diff options
author | gerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-05-18 21:06:20 +0000 |
---|---|---|
committer | gerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-05-18 21:06:20 +0000 |
commit | f854c711a17f3548cbbd8bf6a6dff7dfcac86992 (patch) | |
tree | 73fd0bdd4133b7c7f3ad9e8aa1bb51c59f2cc0a6 | |
parent | 6f423cc4ce804d3355c786ebb6593828d6a90301 (diff) |
From Dustin Johnson:
- Update the wireless/AirPcap GUI code to support 802.11n as well as
some related upcoming code changes.
- Remove airpcap.h from the repository, since it exists in the AirPcap
devpack (and will be superseded Real Soon Now).
- Show the individual channel flag bits in radiotap.
Fix the 802.11n MCS set display.
This is a partial checkin, so hopefully nothing is broken.
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@21831 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | Makefile.common | 1 | ||||
-rw-r--r-- | Makefile.nmake | 2 | ||||
-rw-r--r-- | airpcap.h | 677 | ||||
-rw-r--r-- | airpcap_loader.c | 701 | ||||
-rw-r--r-- | airpcap_loader.h | 93 | ||||
-rw-r--r-- | config.nmake | 1 | ||||
-rw-r--r-- | epan/dissectors/Makefile.nmake | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-ieee80211.c | 16 | ||||
-rw-r--r-- | epan/dissectors/packet-ieee80211.h | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-radiotap.c | 64 | ||||
-rw-r--r-- | gtk/Makefile.nmake | 2 | ||||
-rw-r--r-- | gtk/airpcap_dlg.c | 374 | ||||
-rw-r--r-- | gtk/airpcap_dlg.h | 29 | ||||
-rw-r--r-- | gtk/airpcap_gui_utils.c | 454 | ||||
-rw-r--r-- | gtk/airpcap_gui_utils.h | 34 | ||||
-rw-r--r-- | gtk/capture_dlg.c | 8 | ||||
-rw-r--r-- | gtk/capture_if_dlg.c | 20 | ||||
-rw-r--r-- | gtk/keys.h | 2 | ||||
-rw-r--r-- | gtk/main.c | 222 |
19 files changed, 1271 insertions, 1432 deletions
diff --git a/Makefile.common b/Makefile.common index b043cd1b1c..5090d80538 100644 --- a/Makefile.common +++ b/Makefile.common @@ -158,7 +158,6 @@ wireshark_SOURCES = \ # corresponding headers wireshark_INCLUDES = \ - airpcap.h \ airpcap_loader.h \ alert_box.h \ capture.h \ diff --git a/Makefile.nmake b/Makefile.nmake index 61e24e805d..74be16308e 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -15,7 +15,7 @@ LDFLAGS = /NOLOGO /INCREMENTAL:no /MACHINE:I386 $(LOCAL_LDFLAGS) CFLAGS=-WX -DHAVE_CONFIG_H $(LOCAL_CFLAGS) $(GLIB_CFLAGS) /I. /Iwiretap \ $(ZLIB_CFLAGS) /I$(PCAP_DIR)\include \ - $(NET_SNMP_CFLAGS) \ + $(NET_SNMP_CFLAGS) $(AIRPCAP_CFLAGS) \ $(ADNS_CFLAGS) $(PCRE_CFLAGS) $(GNUTLS_CFLAGS) $(LUA_CFLAGS) \ -D_U_="" -D_NEED_VAR_IMPORT_ diff --git a/airpcap.h b/airpcap.h deleted file mode 100644 index 8afe8d938f..0000000000 --- a/airpcap.h +++ /dev/null @@ -1,677 +0,0 @@ -/* - * Copyright (c) 2006 CACE Technologies, Davis (California) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#if !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_) -#define AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_ - -#include <epan/crypt/wep-wpadefs.h> /* WEP_KEY_MAX_SIZE */ - -#ifdef _MSC_VER -/* This disables a VS warning for zero-sized arrays. All the compilers we support have that feature */ -#pragma warning( disable : 4200) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/*! - \mainpage AirPcap interface documentation - - \section Introduction - - This document describes the data structures and the functions exported by the CACE Technologies AirPcap library. - The AirPcap library provides low-level access to the AirPcap driver including advanced capabilities such as channel setting, - link type control and WEP configuration.<br> - This manual includes the following sections: - - \note throughout this documentation, \i device refers to a physical USB AirPcap device, wile \i adapter is an open API - instance. Most of the AirPcap API operations are adapter-specific but some of them, like setting the channel, are - per-device and will be reflected on all the open adapters. These functions will have "Device" in their name, e.g. - AirpcapSetDeviceChannel(). - - \b Sections: - - - \ref airpcapfuncs - - \ref airpcapdefs - - \ref radiotap -*/ - -/** @defgroup airpcapdefs AirPcap definitions and data structures - * @{ - */ - -/*! - \brief This string is the fixed prefix in the airpcap adapter name. - It can be used to parse the name field in an AirpcapDeviceDescription structure. -*/ -#define AIRPCAP_DEVICE_NAME_PREFIX "\\\\.\\airpcap" - -/*! - \brief This string is the scanf modifier to extract the adapter number from an adapter name. - It can be used to parse the name field in an AirpcapDeviceDescription structure with scanf. -*/ -#define AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING "\\\\.\\airpcap%u" - -/*! - \brief This string is the scanf modifier to extract the adapter "Any" string from an adapter name. - It can be used to parse the name field in an AirpcapDeviceDescription structure with scanf. -*/ -#define AIRPCAP_DEVICE_ANY_EXTRACT_STRING "\\\\.\\airpcap_any" - -/*! - \brief Entry in the list returned by \ref AirpcapGetDeviceList(); -*/ -typedef struct _AirpcapDeviceDescription -{ - struct _AirpcapDeviceDescription *next; /* Next element in the list */ - PCHAR Name; /* Device name */ - PCHAR Description; /* Device description */ -} AirpcapDeviceDescription, *PAirpcapDeviceDescription; - - -#ifndef __MINGW32__ -#pragma pack(push) -#pragma pack(1) -#endif /* __MINGW32__ */ - - -#define AIRPCAP_KEYTYPE_WEP 0 /* Key type: WEP. The key can have an arbitrary length smaller than 32 bytes. */ -#define AIRPCAP_KEYTYPE_TKIP 1 /* Key type: TKIP (WPA_PWD). NOT SUPPORTED YET. */ -#define AIRPCAP_KEYTYPE_CCMP 2 /* Key type: CCMP (WPA_BIN). NOT SUPPORTED YET. */ - -/*! - \brief WEP key container -*/ -typedef struct _AirpcapKey -{ - UINT KeyType; /* Type of key, can be on of: \ref AIRPCAP_KEYTYPE_WEP, \ref AIRPCAP_KEYTYPE_TKIP, \ref AIRPCAP_KEYTYPE_CCMP. Only AIRPCAP_KEYTYPE_WEP is supported by the driver at the moment. */ - UINT KeyLen; /* Length of the key, in bytes */ - BYTE KeyData[WEP_KEY_MAX_SIZE]; /* Key Data */ -} -#ifdef __MINGW32__ -__attribute__((__packed__)) -#endif /* __MINGW32__ */ -AirpcapKey, *PAirpcapKey; - -/*! - \brief Type of frame validation the adapter performs. - An adapter can be instructed to accept different kind of frames: correct frames only, frames with wrong Frame Check Sequence (FCS) only, all frames. -*/ -typedef enum _AirpcapValidationType -{ - AIRPCAP_VT_ACCEPT_EVERYTHING = 1, /* Accept all the frames the device captures */ - AIRPCAP_VT_ACCEPT_CORRECT_FRAMES = 2, /* Accept correct frames only, i.e. frames with correct Frame Check Sequence (FCS). */ - AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES = 3, /* Accept corrupt frames only, i.e. frames with worng Frame Check Sequence (FCS). */ - AIRPCAP_VT_UNKNOWN = 4 /* Unknown validation type. You should see it only in case of error. */ -}AirpcapValidationType, *PAirpcapValidationType; - -/*! - \brief Type of decryption the adapter performs. - An adapter can be instructed to turn decryption (based on the device-configured keys configured - with \ref AirpcapSetDeviceKeys()) on or off. -*/ -typedef enum _AirpcapDecryptionState -{ - AIRPCAP_DECRYPTION_ON = 1, /* This adapter performs decryption */ - AIRPCAP_DECRYPTION_OFF = 2 /* This adapter does not perform decryption */ -}AirpcapDecryptionState, *PAirpcapDecryptionState; - - -/*! - \brief Storage for a MAC address -*/ -typedef struct _AirpcapMacAddress -{ - BYTE Address[6]; /* MAC address bytes */ -} -#ifdef __MINGW32__ -__attribute__((__packed__)) -#endif /* __MINGW32__ */ -AirpcapMacAddress, *PAirpcapMacAddress; - -/*! - \brief This structure is used to store a collection of WEP keys. - Note that the definition of the structure doesn't contain any key, so be careful to allocate a buffer - with the size of the key, like in the following example: - - \code - PAirpcapKeysCollection KeysCollection; - UINT KeysCollectionSize; - - KeysCollectionSize = sizeof(AirpcapKeysCollection) + NumKeys * sizeof(AirpcapKey); - - KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize); - if(!KeysCollection) - { - // Error - } - \endcode -*/ -typedef struct _AirpcapKeysCollection -{ - UINT nKeys; /* Number of keys in the collection */ - AirpcapKey Keys[0]; /* Array of nKeys keys. */ -} AirpcapKeysCollection, *PAirpcapKeysCollection; - -/*! - \brief Packet header. - - This structure defines the BPF that preceeds every packet delivered to the application. -*/ -typedef struct _AirpcapBpfHeader -{ - UINT TsSec; /* Timestamp associated with the captured packet. SECONDS. */ - UINT TsUsec; /* Timestamp associated with the captured packet. MICROSECONDS. */ - UINT Caplen; /* Length of captured portion. The captured portion <b>can be different</b> from the original packet, because it is possible (with a proper filter) to instruct the driver to capture only a portion of the packets. */ - UINT Originallen; /* Original length of packet */ - USHORT Hdrlen; /* Length of bpf header (this struct plus alignment padding). In some cases, a padding could be added between the end of this structure and the packet data for performance reasons. This field can be used to retrieve the actual data of the packet. */ -} -#ifdef __MINGW32__ -__attribute__((__packed__)) -#endif /* __MINGW32__ */ -AirpcapBpfHeader, *PAirpcapBpfHeader; - -/* Helper macros to extract packets coming from the driver. Rounds up to the next even multiple of AIRPCAP_ALIGNMENT. */ -#define AIRPCAP_ALIGNMENT sizeof(int) -#define AIRPCAP_WORDALIGN(x) (((x)+(AIRPCAP_ALIGNMENT-1))&~(AIRPCAP_ALIGNMENT-1)) - -#ifndef __MINGW32__ -#pragma pack(pop) -#endif /* __MINGW32__ */ - -#define AIRPCAP_ERRBUF_SIZE 512 /* Size of the error buffer, in bytes */ - -#ifndef __AIRPCAP_DRIVER__ - -/*! - \brief Link type. - AirPcap supports two kind of 802.11 linktypes: plain 802.11 and radiotap. -*/ -typedef enum _AirpcapLinkType -{ - AIRPCAP_LT_802_11 = 1, /* plain 802.11 linktype. Every packet in the buffer contains the raw 802.11 frame, including MAC FCS. */ - 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. */ - AIRPCAP_LT_UNKNOWN = 3 /* Unknown linktype. You should see it only in case of error. */ -}AirpcapLinkType, *PAirpcapLinkType; - -#if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_) -#define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ -/*! - \brief Adapter handle. -*/ -typedef struct _AirpcapHandle AirpcapHandle, *PAirpcapHandle; -#endif - -/*! - \brief Capture statistics. - Returned by \ref AirpcapGetStats(); -*/ -typedef struct _AirpcapStats -{ - UINT Recvs; /* Number of packets that the driver received by the adapter */ - /* from the beginning of the current capture. This value includes the packets */ - /* dropped because of buffer full. */ - UINT Drops; /* number of packets that the driver dropped from the beginning of a capture. */ - /* A packet is lost when the the buffer of the driver is full. */ - UINT IfDrops; /* Packets dropped by the card before going to the USB bus. */ - /* Not supported at the moment. */ - UINT Capt; /* number of packets that pass the BPF filter, find place in the kernel buffer and */ - /* therefore reach the application. */ -}AirpcapStats, *PAirpcapStats; - -/*@}*/ - -/** @defgroup airpcapfuncs AirPcap functions - * @{ - */ - -/*! - \brief Return a string with the API version - \param VersionMajor Pointer to a variable that will be filled with the major version number. - \param VersionMinor Pointer to a variable that will be filled with the minor version number. - \param VersionRev Pointer to a variable that will be filled with the revision number. - \param VersionBuild Pointer to a variable that will be filled with the build number. -*/ -void AirpcapGetVersion(PUINT VersionMajor, PUINT VersionMinor, PUINT VersionRev, PUINT VersionBuild); - -/*! - \brief Return the last error related to the specified handle - \param AdapterHandle Handle to an open adapter. - \return The string with the last error. -*/ -PCHAR AirpcapGetLastError(PAirpcapHandle AdapterHandle); - -/*! - \brief Return the list of available devices - \param PPAllDevs Address to a caller allocated pointer. On success this pointer will receive the head of a list of available devices. - \param Ebuf String that will contain error information if FALSE is returned. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes. - \return TRUE on success. FALSE is returned on failure, in which case Ebuf is filled in with an appropriate error message. - - Here's a snppet of code that shows how to use AirpcapGetDeviceList(): - - \code - CHAR Ebuf[AIRPCAP_ERRBUF_SIZE]; - AirpcapDeviceDescription *Desc, *tDesc; - - if(AirpcapGetDeviceList(&Desc, Ebuf) == -1) - { - printf("Unable to get the list of devices: %s\n", Ebuf); - return -1; - } - - for(tDesc = Desc; tDesc; tDesc = tDesc->next) - { - printf("%u) %s (%s)\n", - ++i, - tDesc->Name, - tDesc->Description); - } - \endcode -*/ -BOOL AirpcapGetDeviceList(PAirpcapDeviceDescription *PPAllDevs, PCHAR Ebuf); - -/*! - \brief Free a list of devices returned by AirpcapGetDeviceList() - \param PAllDevs Head of the list of devices returned by \ref AirpcapGetDeviceList(). -*/ -VOID AirpcapFreeDeviceList(PAirpcapDeviceDescription PAllDevs); - -/*! - \brief Open an adapter - \param DeviceName Name of the device to open. Use \ref AirpcapGetDeviceList() to get the list of devices. - \param Ebuf String that will contain error information in case of failure. The size of the string must be AIRPCAP_ERRBUF_SIZE bytes. - \return A PAirpcapHandle handle on success. NULL is returned on failure, in which case Ebuf is filled in with an appropriate error message. -*/ -PAirpcapHandle AirpcapOpen(PCHAR DeviceName, PCHAR Ebuf); - -/*! - \brief Close an adapter - \param AdapterHandle Handle to the adapter to close. -*/ -VOID AirpcapClose(PAirpcapHandle AdapterHandle); - -/*! - \brief Set the link type of an adapter - \param AdapterHandle Handle to the adapter. - \param NewLinkType the "link type", i.e. the format of the frames that will be received from the adapter. - \return TRUE on success. - - the "link type" determines how the driver will encode the packets captured from the network. - Aircap supports two link types: - - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any - power information. Look at the Capture_no_radio example application in the developer's pack - for a reference on how to decode 802.11 frames with this link type. - - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header - that contains power and channel information. More information about the radiotap header can be found int the - \ref radiotap section. Moreover, the "Capture_radio" example application in - the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers. -*/ -BOOL AirpcapSetLinkType(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType); - -/*! - \brief Get the link type of the specified adapter - \param AdapterHandle Handle to the adapter. - \param PLinkType Pointer to a caller allocated AirpcapLinkType variable that will contain the link type of the adapter. - \return TRUE on success. - - the "link type" determines how the driver will encode the packets captured from the network. - Aircap supports two link types: - - AIRPCAP_LT_802_11, to capture 802.11 frames (including control frames) without any - power information. Look at the Capture_no_radio example application in the developer's pack - for a reference on how to decode 802.11 frames with this link type. - - AIRPCAP_LT_802_11_PLUS_RADIO, to capture 802.11 frames (including control frames) with a radiotap header - that contains power and channel information. More information about the radiotap header can be found int the - \ref radiotap section. Moreover, the "Capture_radio" example application in - the developer's pack can be used as a reference on how to decode 802.11 frames with radiotap headers. -*/ -BOOL AirpcapGetLinkType(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType); - -/*! - \brief Configures the adapter on whether to include the MAC Frame Check Sequence in the captured packets. - \param AdapterHandle Handle to the adapter. - \param IsFcsPresent TRUE if the packets should include the FCS. FALSE otherwise - \return TRUE on success. - - In the default configuration, the adapter includes the FCS in the captured packets. The MAC Frame Check Sequence - 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 - link types. - When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header - that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present - when FCS inclusion is off. -*/ -BOOL AirpcapSetFcsPresence(PAirpcapHandle AdapterHandle, BOOL IsFcsPresent); - -/*! - \brief Returns TRUE if the specified adapter includes the MAC Frame Check Sequence in the captured packets - \param AdapterHandle Handle to the adapter. - \param PIsFcsPresent User-provided variable that will be set to true if the adapter is including the FCS. - \return TRUE if the operation is successful. FALSE otherwise. - - In the default configuration, the adatper has FCS inclusion turned on. The MAC Frame Check Sequence 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 - link types. - When the FCS inclusion is turned on, and if the link type is AIRPCAP_LT_802_11_PLUS_RADIO, the radiotap header - that precedes each frame has two additional fields at the end: Padding and FCS. These two fields are not present - when FCS inclusion is off. -*/ -BOOL AirpcapGetFcsPresence(PAirpcapHandle AdapterHandle, PBOOL PIsFcsPresent); - -/*! - \brief Configures the adapter to accept or drop frames with an incorrect Frame Check sequence (FCS). - \param AdapterHandle Handle to the adapter. - \param ValidationType The type of validation the driver will perform. See the documentation of \ref AirpcapValidationType for details. - \return TRUE on success. - - \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode. -*/ -BOOL AirpcapSetFcsValidation(PAirpcapHandle AdapterHandle, AirpcapValidationType ValidationType); - -/*! - \brief Checks if the specified adapter is configured to capture frames with incorrect an incorrect Frame Check Sequence (FCS). - \param AdapterHandle Handle to the adapter. - \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. - \return TRUE if the operation is succesful. FALSE otherwise. - - \note By default, the driver is configured in \ref AIRPCAP_VT_ACCEPT_EVERYTHING mode. -*/ -BOOL AirpcapGetFcsValidation(PAirpcapHandle AdapterHandle, PAirpcapValidationType ValidationType); - -/*! - \brief Set the list of decryption keys that the driver is going to use with the specified device. - \param AdapterHandle Handle an open adapter instance. - \param KeysCollection Pointer to a \ref PAirpcapKeysCollection structure that contains the keys to be set in the driver. - \return TRUE if the operation is successful. FALSE otherwise. - - 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 - keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames - to the application. - The driver supports, for every device, multiple keys at the same time. - - At this time, the only supported decryption method is WEP. - - The configured decryption keys are device-specific: they will not be used by other airpcap devices besides the specified one. - - The keys are applied to the packets in the same order they appear in the KeysCollection structure until the packet is - correctly decrypted, therefore putting frequently used keys at the beginning of the structure improves performance. - - \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be - immediately reflected on all the other capture instances. -*/ -BOOL AirpcapSetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection); - -/*! - \brief Returns the list of decryption keys in the driver that are currently associated with the specified device - \param AdapterHandle Handle to an open adapter instance. - \param KeysCollection User-allocated PAirpcapKeysCollection structure that will be filled with the keys. - \param PKeysCollectionSize \b IN: pointer to a user-allocated variable that contains the length of the KeysCollection structure, in bytes. - \b OUT: amount of data moved by the driver in the buffer pointed by KeysBuffer, in bytes. - \return TRUE if the operation is succesful. If an error occurs, the return value is FALSE and KeysCollectionSize is zero. - If the provided buffer is too small to contain the keys, the return value is FALSE and KeysCollectionSize contains the - needed KeysCollection length, in bytes. If the device doesn't have any decryption key configured, the return value is TRUE, and - KeysCollectionSize will be zero. - - This function returns the list of decryption keys in the driver that are associated with the specified device. - 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 - keys corresponds to the one the frame has been encrypted with, the driver will perform decryption and return the cleartext frames - to the application. - The driver supports, for every device, multiple keys at the same time. - - The configured decryption keys are device-specific, therefore AirpcapGetDeviceKeys() will return a different set of keys - when called on different devices. - - At this time, the only supported decryption method is WEP. - - \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be - immediately reflected on all the other capture instances. -*/ -BOOL AirpcapGetDeviceKeys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize); - -/*! - \brief Turns on or off the decryption of the incoming frames - \param AdapterHandle Handle to the adapter. - \param ValidationType Either \ref AIRPCAP_DECRYPTION_ON or \ref AIRPCAP_DECRYPTION_OFF - \return TRUE on success. - - The decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function. - \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON. -*/ -BOOL AirpcapSetDecryptionState(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable); - -/*! - \brief Tells if this open instance is configured to perform the decryption of the incoming frames - \param AdapterHandle Handle to the adapter. - \param ValidationType Pointer to a user supplied variable that will contain the decryption configuration. See \ref PAirpcapDecryptionState for details. - \return TRUE if the operation is succesful. FALSE otherwise. - - The decryption keys can be configured with the \ref AirpcapSetDeviceKeys() function. - \note By default, the driver is configured with \ref AIRPCAP_DECRYPTION_ON. -*/ -BOOL AirpcapGetDecryptionState(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable); - -/*! - \brief Set the radio channel of a device - \param AdapterHandle Handle to the adapter. - \param Channel the new channel to set. - \return TRUE on success. - - Valid channels are in the range 1-14. The default channel setting is 6. - - \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be - immediately reflected on all the other capture instances. -*/ -BOOL AirpcapSetDeviceChannel(PAirpcapHandle AdapterHandle, UINT Channel); - -/*! - \brief Get the radio channel of a device - \param AdapterHandle Handle to the adapter. - \param PChannel Pointer to a user-supplied variable into which the function will copy the currently configured radio channel. - \return TRUE on success. - - Valid channels are in the range 1-14. The default channel setting is 6. - - \note: this is a Device-related function: when you change the channel from an open capture instance, the change will be - immediately reflected on all the other capture instances. -*/ -BOOL AirpcapGetDeviceChannel(PAirpcapHandle AdapterHandle, PUINT PChannel); - -/*! - \brief Set the size of the kernel packet buffer for this adapter - \param AdapterHandle Handle to the adapter. - \param BufferSize New size, in bytes. - \return TRUE on success. - - Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte. - This function can be used to change the size of this buffer, and can be called at any time. - A bigger kernel buffer size decreases the risk of dropping packets during network bursts or when the - application is busy, at the cost of higher kernel memory usage. - - \note: don't use this function unless you know what you are doing. Due to chaching issues and bigger non-paged - memory consumption, Bigger buffer sizes can decrease the capture performace instead of improving it. -*/ -BOOL AirpcapSetKernelBuffer(PAirpcapHandle AdapterHandle, UINT BufferSize); - -/*! - \brief Get the size of the kernel packet buffer for this adapter - \param AdapterHandle Handle to the adapter. - \param PSizeBytes User-allocated variable that will be filled with the size of the kernel buffer. - \return TRUE on success. - - Every AirPcap open instance has an associated kernel buffer, whose default size is 1 Mbyte. - This function can be used to get the size of this buffer. -*/ -BOOL AirpcapGetKernelBufferSize(PAirpcapHandle AdapterHandle, PUINT PSizeBytes); - -/*! - \brief Saves the configuration of the specified adapter in the registry, so that it becomes the default for this adapter. - \param AdapterHandle Handle to the adapter. - \return TRUE on success. FALSE on failure. - - Almost all the AirPcap calls that modify the configuration (\ref AirpcapSetLinkType(), \ref AirpcapSetFcsPresence(), - \ref AirpcapSetFcsValidation(), \ref AirpcapSetKernelBuffer(), \ref AirpcapSetMinToCopy()) - affect only the referenced AirPcap open instance. This means that if you do another \ref AirpcapOpen() on the same - adapter, the configuration changes will not be remembered, and the new adapter handle will have default configuration - settings. - - Exceptions to this rule are the \ref AirpcapSetDeviceChannel() and \ref AirpcapSetDeviceKeys() functions: a channel change is - reflected on all the open instances, and remembered until the next call to \ref AirpcapSetDeviceChannel(), until the adapter - is unplugged, or until the machine is powered off. Same thing for the configuration of the WEP keys. - - AirpcapStoreCurConfigAsAdapterDefault() stores the configuration of the give open instance as the default for the adapter: - all the instances opened in the future will have the same configuration that this adapter currently has. - The configuration is stored in the registry, therefore it is remembered even when the adapter is unplugged or the - machine is turned off. However, an adapter doesn't bring its configuration with it from machine to machine. - - the configuration information saved in the registry includes the following parameters: - - channel - - kernel buffer size - - mintocopy - - link type - - CRC presence - - Encryption keys - - Encryption Enabled/Disabled state - - The configuration is adapter-specific. This means that changing the configuration of an adapter - doesn't modify the one of the other adapters that are currently used or that will be used in the future. - - \note AirpcapStoreCurConfigAsAdapterDefault() must have exclusive access to the adapter -- it - will fail if more than one AirPcap handle is opened at the same time for this adapter. - AirpcapStoreCurConfigAsAdapterDefault() needs administrator privileges. It will fail if the calling user - is not a local machine administrator. -*/ -BOOL AirpcapStoreCurConfigAsAdapterDefault(PAirpcapHandle AdapterHandle); - -/*! - \brief Set the BPF kernel filter for an adapter - \param AdapterHandle Handle to the adapter. - \param Instructions pointer to the first BPF instruction in the array. Corresponds to the bf_insns - in a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm). - \param Len Number of instructions in the array pointed by the previous field. Corresponds to the bf_len in - a a bpf_program structure (see the WinPcap documentation at http://www.winpcap.org/devel.htm). - \return TRUE on success. - - The AirPcap driver is able to perform kernel-level filtering using the standard BPF pseudo-machine format. You can read - the WinPcap documentation at http://www.winpcap.org/devel.htm for more details on the BPF filtering mechaism. - - A filter can be automatically created by using the pcap_compile() function of the WinPcap API. This function - converts a human readable text expression with the tcpdump/libpcap syntax into a BPF program. - If your program doesn't link wpcap, but you need to generate the code for a particular filter, you can run WinDump - with the -d or -dd or -ddd flags to obtain the pseudocode. - -*/ -BOOL AirpcapSetFilter(PAirpcapHandle AdapterHandle, PVOID Instructions, UINT Len); - -/*! - \brief Return the MAC address of an adapter. - \param AdapterHandle Handle to the adapter. - \param PMacAddress Pointer to a user allocated MAC address. - The size of this buffer needs to be at least 6 bytes. - \return TRUE on success. -*/ -BOOL AirpcapGetMacAddress(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress); - -/*! - \brief Set the mintocopy parameter for an open adapter - \param AdapterHandle Handle to the adapter. - \param MinToCopy is the mintocopy size in bytes. - \return TRUE on success. - - When the number of bytes in the kernel buffer changes from less than mintocopy bytes to greater than or equal to mintocopy bytes, - the read event is signalled (see \ref AirpcapGetReadEvent()). A high value for mintocopy results in poor responsiveness since the - driver may signal the application "long" after the arrival of the packet. And a high value results in low CPU loading - by minimizing the number of user/kernel context switches. - A low MinToCopy results in good responsiveness since the driver will signal the application close to the arrival time of - the packet. This has higher CPU loading over the first approach. -*/ -BOOL AirpcapSetMinToCopy(PAirpcapHandle AdapterHandle, UINT MinToCopy); - -/*! - \brief Gets an event that is signaled when that is signalled when packets are available in the kernel buffer (see \ref AirpcapSetMinToCopy()). - \param AdapterHandle Handle to the adapter. - \param PReadEvent Pointer to a user-supplied handle that in which the read event will be copied. - \return TRUE on success. - - \note the event is signalled when at least mintocopy bytes are present in the kernel buffer (see \ref AirpcapSetMinToCopy()). - This event can be used by WaitForSingleObject() and WaitForMultipleObjects() to create blocking behavior when reading - packets from one or more adapters (see \ref AirpcapRead()). -*/ -BOOL AirpcapGetReadEvent(PAirpcapHandle AdapterHandle, HANDLE* PReadEvent); - -/*! - \brief Fills a user-provided buffer with zero or more packets that have been captured on the referenced adapter. - \param AdapterHandle Handle to the adapter. - \param Buffer pointer to the buffer that will be filled with captured packets. - \param BufSize size of the input buffer that will contain the packets, in bytes. - \param PReceievedBytes Pointer to a user supplied variable that will receive the number of bytes copied by AirpcapRead. - Can be smaller than BufSize. - \return TRUE on success. - - 802.11 frames are returned by the driver in buffers. Every 802.11 frame in the buffer is preceded by a \ref AirpcapBpfHeader structure. - The suggested way to use an AirPcap adapter is through the pcap API exported by wpcap.dll. If this is not - possible, the Capture_radio and Capture_no_radio examples in the AirPcap developer's pack show how to properly decode the - packets in the read buffer returned by AirpcapRead(). - - \note this function is NOT blocking. Blocking behavior can be obtained using the event returned - by \ref AirpcapGetReadEvent(). See also \ref AirpcapSetMinToCopy(). -*/ -BOOL AirpcapRead(PAirpcapHandle AdapterHandle, PBYTE Buffer, UINT BufSize, PUINT PReceievedBytes); - -/*! - \brief Get per-adapter WinPcap-compatible capture statistics. - \param AdapterHandle Handle to the adapter. - \param PStats pointer to a user-allocated AirpcapStats structure that will be filled with statistical information. - \return TRUE on success. -*/ -BOOL AirpcapGetStats(PAirpcapHandle AdapterHandle, PAirpcapStats PStats); - -/*! - \brief Get the number of LEDs the referenced adapter has available. - \param AdapterHandle Handle to the adapter. - \param NumberOfLeds Number of LEDs available on this adapter. - \return TRUE on success. -*/ -BOOL AirpcapGetLedsNumber(PAirpcapHandle AdapterHandle, PUINT NumberOfLeds); - -/*! - \brief Turn on one of the adapter's LEDs. - \param AdapterHandle Handle to the adapter. - \param LedNumber zero-based identifier of the LED to turn on. - \return TRUE on success. -*/ -BOOL AirpcapTurnLedOn(PAirpcapHandle AdapterHandle, UINT LedNumber); - -/*! - \brief Turn off one of the adapter's LEDs. - \param AdapterHandle Handle to the adapter. - \param LedNumber zero-based identifier of the LED to turn off. - \return TRUE on success. -*/ -BOOL AirpcapTurnLedOff(PAirpcapHandle AdapterHandle, UINT LedNumber); - -/*@}*/ - -#endif /* __AIRPCAP_DRIVER__ */ - -#ifdef __cplusplus -} -#endif - -#endif /* !defined(AIRPCAP_H__EAE405F5_0171_9592_B3C2_C19EC426AD34__INCLUDED_) */ diff --git a/airpcap_loader.c b/airpcap_loader.c index e01b6bc792..f7ef397c16 100644 --- a/airpcap_loader.c +++ b/airpcap_loader.c @@ -64,6 +64,8 @@ static HMODULE AirpcapLib = NULL; */ static gboolean AirpcapLoaded = FALSE; +static int AirpcapVersion = 3; + static AirpcapGetLastErrorHandler g_PAirpcapGetLastError; static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList; static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList; @@ -96,6 +98,9 @@ static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState; static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault; static AirpcapGetVersionHandler g_PAirpcapGetVersion; +static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx; +static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx; +static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels; /* Airpcap interface list */ GList *airpcap_if_list = NULL; @@ -109,6 +114,67 @@ airpcap_if_info_t *airpcap_if_active = NULL; /* WLAN preferences pointer */ module_t *wlan_prefs = NULL; +Dot11Channel *pSupportedChannels; +ULONG numSupportedChannels; + +static Dot11Channel Dot11aChannels[] = +{ + {34, 5170, 0}, + {36, 5180, 0}, + {38, 5190, 0}, + {40, 5200, 0}, + {42, 5210, 0}, + {44, 5220, 0}, + {46, 5230, 0}, + {48, 5240, 0}, + {52, 5260, 0}, + {56, 5280, 0}, + {60, 5300, 0}, + {64, 5320, 0}, + {149, 5745, 0}, + {153, 5765, 0}, + {157, 5785, 0}, + {161, 5805, 0}, +}; + +static Dot11Channel Dot11bChannels[] = +{ + {1, 2412, 0}, + {2, 2417, 0}, + {3, 2422, 0}, + {4, 2427, 0}, + {5, 2432, 0}, + {6, 2437, 0}, + {7, 2442, 0}, + {8, 2447, 0}, + {9, 2452, 0}, + {10, 2457, 0}, + {11, 2462, 0}, + {12, 2467, 0}, + {13, 2472, 0}, + {14, 2484, 0}, +}; + +static AirpcapChannelInfo LegacyChannels[] = +{ + {2412, 0, {0,0,0}}, + {2417, 0, {0,0,0}}, + {2422, 0, {0,0,0}}, + {2427, 0, {0,0,0}}, + {2432, 0, {0,0,0}}, + {2437, 0, {0,0,0}}, + {2442, 0, {0,0,0}}, + {2447, 0, {0,0,0}}, + {2452, 0, {0,0,0}}, + {2457, 0, {0,0,0}}, + {2462, 0, {0,0,0}}, + {2467, 0, {0,0,0}}, + {2472, 0, {0,0,0}}, + {2484, 0, {0,0,0}}, +}; + +static ULONG num_legacy_channels = 14; + /* * Callback used by the load_wlan_keys() routine in order to read a WEP decryption key */ @@ -687,6 +753,15 @@ airpcap_if_close(PAirpcapHandle handle) } /* + * Retrieve the state of the Airpcap DLL + */ +int +airpcap_get_dll_state() +{ + return AirpcapVersion; +} + +/* * Airpcap wrapper, used to turn on the led of an airpcap adapter */ BOOL @@ -717,6 +792,218 @@ airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch) } /* + * Airpcap wrapper, used to get the supported channels of an airpcap adapter + */ +BOOL +airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, PULONG nInfo) +{ + if (!AirpcapLoaded) return FALSE; + if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){ + *nInfo = num_legacy_channels; + *cInfo = (AirpcapChannelInfo*)&LegacyChannels; + + return TRUE; + } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){ + return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo); + } + return FALSE; +} + +/* + * Airpcap wrapper, used to get the supported channels of an airpcap adapter + */ +Dot11Channel* +airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels) +{ + AirpcapChannelInfo *chanInfo; + ULONG i=0, j=0, numInfo = 0; + if (!AirpcapLoaded) return FALSE; + if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE) return NULL; + numSupportedChannels = 0; + + /* + * allocate a bigger array + */ + if (numInfo == 0) + return FALSE; + + pSupportedChannels = malloc(numInfo * (sizeof *pSupportedChannels)); + + for (i = 0; i < numInfo; i++) + { + ULONG supportedChannel = 0xFFFFFFFF; + + /* + * search if we have it already + */ + for (j = 0; j < numSupportedChannels; j++) + { + if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency) + { + supportedChannel = j; + break; + } + } + + if (supportedChannel == 0xFFFFFFFF) + { + /* + * not found, create a new item + */ + pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency; + + switch(chanInfo[i].ExtChannel) + { + case -1: pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH; break; + case +1: pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW; break; + case 0: + default: pSupportedChannels[numSupportedChannels].Flags = 0; + } + + /* + * match with the ABG channels + */ + + for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++) + { + if (pSupportedChannels[numSupportedChannels].Frequency == Dot11aChannels[j].Frequency) + { + pSupportedChannels[numSupportedChannels].Flags |= FLAG_IS_A_CHANNEL; + pSupportedChannels[numSupportedChannels].Channel = Dot11aChannels[j].Channel; + break; + } + } + + for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++) + { + if (pSupportedChannels[numSupportedChannels].Frequency == Dot11bChannels[j].Frequency) + { + pSupportedChannels[numSupportedChannels].Flags |= FLAG_IS_BG_CHANNEL; + pSupportedChannels[numSupportedChannels].Channel = Dot11bChannels[j].Channel; + break; + } + } + + if ((pSupportedChannels[numSupportedChannels].Flags & (FLAG_IS_BG_CHANNEL | FLAG_IS_A_CHANNEL)) == 0){ + pSupportedChannels[numSupportedChannels].Channel = 0; + } + + numSupportedChannels++; + } + else + { + /* + * just update the ext channel flags + */ + switch(chanInfo[i].ExtChannel) + { + case -1: pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH; break; + case +1: pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW; break; + case 0: + default: + break; + } + } + } + + /* + * Now sort the list by frequency + */ + for (i = 0 ; i < numSupportedChannels - 1; i++) + { + for (j = i + 1; j < numSupportedChannels; j++) + { + if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency) + { + Dot11Channel temp = pSupportedChannels[i]; + pSupportedChannels[i] = pSupportedChannels[j]; + pSupportedChannels[j] = temp; + } + } + } + + *pNumSupportedChannels = numSupportedChannels; + return pSupportedChannels; +} + +/* + * Get channel representation string given a Frequency + */ +gchar* +airpcap_get_channelstr_from_freq(ULONG chan_freq){ + gchar *channelstr; + guint j; + + channelstr = (gchar*)g_malloc(sizeof(gchar)*20); + for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++) + { + if (chan_freq == Dot11aChannels[j].Frequency) + { + sprintf(channelstr, "%u MHz [A %u]", chan_freq, Dot11aChannels[j].Channel); + return channelstr; + } + } + + for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++) + { + if (chan_freq == Dot11bChannels[j].Frequency) + { + sprintf(channelstr, "%u MHz [BG %u]", chan_freq, Dot11bChannels[j].Channel); + return channelstr; + } + } + + sprintf(channelstr, "%u MHz", chan_freq); + + return channelstr; +} + +/* + * Get channel number given a Frequency + */ +guint +airpcap_get_channel_number_from_freq(ULONG chan_freq){ + guint j; + + for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++){ + if (chan_freq == Dot11bChannels[j].Frequency){ + return Dot11bChannels[j].Channel; + } + } + + for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++){ + if (chan_freq == Dot11aChannels[j].Frequency){ + return Dot11aChannels[j].Channel; + } + } + + return 0; +} + +/* + * Get Frequency given a Channel number + */ +ULONG +airpcap_get_freq_from_channel_number(guint chan_number){ + guint j; + + for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++){ + if (chan_number == Dot11bChannels[j].Channel){ + return Dot11bChannels[j].Frequency; + } + } + + for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++){ + if (chan_number == Dot11aChannels[j].Channel){ + return Dot11aChannels[j].Frequency; + } + } + + return 0; +} + + +/* * Airpcap wrapper, used to set the channel of an airpcap adapter */ BOOL @@ -727,6 +1014,60 @@ airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch) } /* + * Airpcap wrapper, used to set the frequency of an airpcap adapter + */ +BOOL +airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo) +{ + if (!AirpcapLoaded) return FALSE; + if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){ + guint channel = 0; + channel = airpcap_get_channel_number_from_freq(ChannelInfo.Frequency); + + if (channel == 0){ + return FALSE; + } else { + return airpcap_if_set_device_channel(ah, channel); + } + } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){ + return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo); + } + + return FALSE; +} + +/* + * Airpcap wrapper, used to get the frequency of an airpcap adapter + */ +BOOL +airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo) +{ + if (!AirpcapLoaded) return FALSE; + + pChannelInfo->Frequency = 0; + pChannelInfo->ExtChannel = 0; + pChannelInfo->Reserved[0] = 0; + pChannelInfo->Reserved[1] = 0; + pChannelInfo->Reserved[2] = 0; + + if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){ + guint channel = 0; + ULONG chan_freq = 0; + + if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE; + + chan_freq = airpcap_get_freq_from_channel_number(channel); + if (chan_freq == 0) return FALSE; + pChannelInfo->Frequency = chan_freq; + + return TRUE; + } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){ + return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo); + } + return FALSE; +} + +/* * Airpcap wrapper, used to get the link type of an airpcap adapter */ BOOL @@ -881,29 +1222,32 @@ airpcap_if_info_new(char *name, char *description) ad = airpcap_if_open(name, ebuf); if(ad) { - if_info = g_malloc(sizeof (airpcap_if_info_t)); - if_info->name = g_strdup(name); - if (description == NULL) - if_info->description = NULL; - else - if_info->description = g_strdup(description); - if_info->ip_addr = NULL; - if_info->loopback = FALSE; - airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn)); - airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent)); - airpcap_if_get_link_type(ad,&(if_info->linkType)); - airpcap_if_get_device_channel(ad,&(if_info->channel)); - airpcap_if_turn_led_on(ad, 0); - airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn)); - if_info->led = TRUE; - if_info->blinking = FALSE; - if_info->saved = TRUE; /* NO NEED TO BE SAVED */ - - /* get the keys, if everything is ok, close the adapter */ - if(airpcap_if_load_keys(ad,if_info)) - { - airpcap_if_close(ad); - } + if_info = g_malloc(sizeof (airpcap_if_info_t)); + if_info->name = g_strdup(name); + if (description == NULL){ + if_info->description = NULL; + }else{ + if_info->description = g_strdup(description); + } + + if_info->ip_addr = NULL; + if_info->loopback = FALSE; + airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn)); + airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent)); + airpcap_if_get_link_type(ad,&(if_info->linkType)); + airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo)); + if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels)); + airpcap_if_turn_led_on(ad, 0); + airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn)); + if_info->led = TRUE; + if_info->blinking = FALSE; + if_info->saved = TRUE; /* NO NEED TO BE SAVED */ + + /* get the keys, if everything is ok, close the adapter */ + if(airpcap_if_load_keys(ad,if_info)) + { + airpcap_if_close(ad); + } } return if_info; } @@ -936,26 +1280,26 @@ airpcap_driver_fake_if_info_new() ad = airpcap_if_open(if_info->name, ebuf); if(ad) { - fake_if_info = g_malloc(sizeof (airpcap_if_info_t)); - fake_if_info->name = g_strdup(if_info->name); - fake_if_info->description = g_strdup(if_info->description); - fake_if_info->loopback = FALSE; - fake_if_info->ip_addr = NULL; - airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn)); - airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn)); - airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent)); - airpcap_if_get_link_type(ad,&(fake_if_info->linkType)); - airpcap_if_get_device_channel(ad,&(fake_if_info->channel)); - airpcap_if_turn_led_on(ad, 0); - fake_if_info->led = TRUE; - fake_if_info->blinking = FALSE; - fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */ - - /* get the keys, if everything is ok, close the adapter */ - if(airpcap_if_load_driver_keys(ad,fake_if_info)) - { - airpcap_if_close(ad); - } + fake_if_info = g_malloc(sizeof (airpcap_if_info_t)); + fake_if_info->name = g_strdup(if_info->name); + fake_if_info->description = g_strdup(if_info->description); + fake_if_info->loopback = FALSE; + fake_if_info->ip_addr = NULL; + airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn)); + airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn)); + airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent)); + airpcap_if_get_link_type(ad,&(fake_if_info->linkType)); + airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo)); + airpcap_if_turn_led_on(ad, 0); + fake_if_info->led = TRUE; + fake_if_info->blinking = FALSE; + fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */ + + /* get the keys, if everything is ok, close the adapter */ + if(airpcap_if_load_driver_keys(ad,fake_if_info)) + { + airpcap_if_close(ad); + } } return fake_if_info; @@ -967,27 +1311,38 @@ airpcap_driver_fake_if_info_new() void airpcap_if_info_print(airpcap_if_info_t* if_info) { + guint i; if(if_info == NULL) { - g_print("\nWARNING : AirPcap Interface pointer is NULL!\n"); - return; + g_print("\nWARNING : AirPcap Interface pointer is NULL!\n"); + return; } g_print("\n----------------- AirPcap Interface \n"); - g_print(" NAME: %s\n",if_info->name); - g_print(" DESCRIPTION: %s\n",if_info->description); - g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE"); - g_print(" CHANNEL: %2u\n",if_info->channel); - g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF"); - g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF"); - g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL"); - g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE"); - g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL"); - g_print("KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize); - g_print(" LED: %s\n",if_info->led ? "ON" : "OFF"); - g_print(" LINKTYPE: %d\n",if_info->linkType); - g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO"); - g_print(" (GTK) TAG: %d\n",if_info->tag); + g_print(" NAME: %s\n",if_info->name); + g_print(" DESCRIPTION: %s\n",if_info->description); + g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE"); + g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency); + g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel); + g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF"); + g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF"); + g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL"); + g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE"); + g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL"); + g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize); + g_print(" LED: %s\n",if_info->led ? "ON" : "OFF"); + g_print(" LINKTYPE: %d\n",if_info->linkType); + g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO"); + g_print(" (GTK) TAG: %d\n",if_info->tag); + g_print("SUPPORTED CHANNELS POINTER: %lu\n",if_info->pSupportedChannels); + g_print(" NUM SUPPORTED CHANNELS: %lu\n",if_info->numSupportedChannels); + + for(i=0; i<(if_info->numSupportedChannels); i++){ + g_print("\n SUPPORTED CHANNEL #%u\n",i+1); + g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel); + g_print(" FREQUENCY: %lu\n",if_info->pSupportedChannels[i].Frequency); + g_print(" FLAGS: %lu\n",if_info->pSupportedChannels[i].Flags); + } g_print("\n\n"); } @@ -1139,17 +1494,17 @@ get_airpcap_interface_list(int *err, char **err_str) if (!AirpcapLoaded) { - *err = AIRPCAP_NOT_LOADED; - return il; + *err = AIRPCAP_NOT_LOADED; + return il; } if (!g_PAirpcapGetDeviceList(&devsList, errbuf)) { - /* No interfaces, return il = NULL; */ - *err = CANT_GET_AIRPCAP_INTERFACE_LIST; - if (err_str != NULL) - *err_str = cant_get_airpcap_if_list_error_message(errbuf); - return il; + /* No interfaces, return il = NULL; */ + *err = CANT_GET_AIRPCAP_INTERFACE_LIST; + if (err_str != NULL) + *err_str = cant_get_airpcap_if_list_error_message(errbuf); + return il; } /* @@ -1165,12 +1520,12 @@ get_airpcap_interface_list(int *err, char **err_str) if(n_adapts == 0) { - /* No interfaces, return il= NULL */ - g_PAirpcapFreeDeviceList(devsList); - *err = NO_AIRPCAP_INTERFACES_FOUND; - if (err_str != NULL) - *err_str = NULL; - return il; + /* No interfaces, return il= NULL */ + g_PAirpcapFreeDeviceList(devsList); + *err = NO_AIRPCAP_INTERFACES_FOUND; + if (err_str != NULL) + *err_str = NULL; + return il; } /* @@ -1179,10 +1534,12 @@ get_airpcap_interface_list(int *err, char **err_str) adListEntry = devsList; for(i = 0; i < n_adapts; i++) { - if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description); - il = g_list_append(il, if_info); + if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description); + if (if_info != NULL){ + il = g_list_append(il, if_info); + } - adListEntry = adListEntry->next; + adListEntry = adListEntry->next; } g_PAirpcapFreeDeviceList(devsList); @@ -1192,43 +1549,10 @@ get_airpcap_interface_list(int *err, char **err_str) } /* - * Used to retrieve the name of the interface given the description - * (the name is used in AirpcapOpen, the description is put in the combo box) - */ -gchar* get_airpcap_name_from_description(GList* if_list, gchar* description) -{ - unsigned int ifn; - GList* curr; - airpcap_if_info_t* if_info; - - ifn = 0; - if(if_list != NULL) - { - while( ifn < g_list_length(if_list) ) - { - curr = g_list_nth(if_list, ifn); - - if_info = NULL; - if(curr != NULL) - if_info = curr->data; - if(if_info != NULL) - { - if ( g_ascii_strcasecmp(if_info->description,description) == 0) - { - return if_info->name; - } - } - ifn++; - } - } - return NULL; -} - -/* * Used to retrieve the interface given the name * (the name is used in AirpcapOpen) */ -airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name) +airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name) { unsigned int ifn; GList* curr; @@ -1328,39 +1652,6 @@ airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if) } /* - * Used to retrieve the airpcap_if_info_t of the selected interface given the - * description (that is the entry of the combo box). - */ -gpointer get_airpcap_if_from_description(GList* if_list, const gchar* description) -{ - unsigned int ifn; - GList* curr; - airpcap_if_info_t* if_info; - - ifn = 0; - if(if_list != NULL) - { - while( ifn < g_list_length(if_list) ) - { - curr = g_list_nth(if_list, ifn); - - if_info = NULL; - if(curr != NULL) - if_info = curr->data; - if(if_info != NULL) - { - if ( g_ascii_strcasecmp(if_info->description,description) == 0) - { - return if_info; - } - } - ifn++; - } - } - return NULL; -} - -/* * Used to retrieve the two chars string from interface */ gchar* @@ -1426,7 +1717,7 @@ airpcap_get_default_if(GList* airpcap_if_list) if(prefs.capture_device != NULL) { s = g_strdup(get_if_name(prefs.capture_device)); - if_info = get_airpcap_if_by_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device))); + if_info = get_airpcap_if_from_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device))); g_free(s); } return if_info; @@ -1443,7 +1734,7 @@ airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info) if(if_info != NULL) { - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf); + ad = airpcap_if_open(if_info->name, ebuf); if(ad) { @@ -1455,7 +1746,7 @@ airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info) } /* Apply settings... */ - airpcap_if_get_device_channel(ad,&(if_info->channel)); + airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo)); airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn)); airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent)); airpcap_if_get_link_type(ad,&(if_info->linkType)); @@ -1484,7 +1775,7 @@ airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info) if(if_info != NULL) { - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, if_info->description), ebuf); + ad = airpcap_if_open(if_info->name, ebuf); if(ad) { @@ -1496,7 +1787,7 @@ airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info) } /* Apply settings... */ - airpcap_if_set_device_channel(ad,if_info->channel); + airpcap_if_set_device_channel_ex(ad,if_info->channelInfo); airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn); airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent); airpcap_if_set_link_type(ad,if_info->linkType); @@ -1960,8 +2251,8 @@ keys_are_equals(decryption_key_t *k1,decryption_key_t *k2) return FALSE; /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */ - /** //if( (k1->type == AIRPDCAP_KEY_TYPE_WPA_PWD) || (k2->type == AIRPDCAP_KEY_TYPE_WPA_PWD) || (k1->type == AIRPDCAP_KEY_TYPE_WPA_PMK) || (k2->type == AIRPDCAP_KEY_TYPE_WPA_PMK) ) **/ - /** // return TRUE; **/ + /** if( (k1->type == AIRPDCAP_KEY_TYPE_WPA_PWD) || (k2->type == AIRPDCAP_KEY_TYPE_WPA_PWD) || (k1->type == AIRPDCAP_KEY_TYPE_WPA_PMK) || (k2->type == AIRPDCAP_KEY_TYPE_WPA_PMK) ) **/ + /** return TRUE; **/ if( g_string_equal(k1->key,k2->key) && (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */ @@ -2251,7 +2542,7 @@ set_airpcap_decryption(gboolean on_off) if( curr_if != NULL ) { - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list,curr_if->description), ebuf); + ad = airpcap_if_open(curr_if->name, ebuf); if(ad) { curr_if->DecryptionOn = (gboolean)AIRPCAP_DECRYPTION_OFF; @@ -2278,69 +2569,67 @@ set_airpcap_decryption(gboolean on_off) int load_airpcap(void) { BOOL base_functions = TRUE; - BOOL new_functions = TRUE; + BOOL eleven_n_functions = TRUE; if((AirpcapLib = LoadLibrary(TEXT("airpcap.dll"))) == NULL) { - /* Report the error but go on */ - return AIRPCAP_DLL_NOT_FOUND; + /* Report the error but go on */ + AirpcapVersion = AIRPCAP_DLL_NOT_FOUND; + return AirpcapVersion; } else { - if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE; - if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE; - if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE; - if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE; - if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE; - if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE; - if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE; - if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE; - if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE; - if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE; - - /* TEST IF WE CAN FIND AIRPCAP NEW DRIVER FEATURES */ - if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) new_functions = FALSE; - if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) new_functions = FALSE; - if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) new_functions = FALSE; - if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) new_functions = FALSE; - - if(base_functions) - { - if(new_functions) - { - AirpcapLoaded = TRUE; - return AIRPCAP_DLL_OK; - } - else - { - AirpcapLoaded = TRUE; - return AIRPCAP_DLL_OLD; - } - } - else - { - AirpcapLoaded = FALSE; - return AIRPCAP_DLL_ERROR; - } + if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE; + if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE; + if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE; + if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE; + if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE; + if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE; + if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE; + if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE; + if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE; + if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE; + + /* TEST IF AIRPCAP SUPPORTS 11N */ + if((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE; + if((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE; + if((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE; + + if(base_functions && eleven_n_functions){ + AirpcapLoaded = TRUE; + AirpcapVersion = AIRPCAP_DLL_OK; + }else if(base_functions){ + AirpcapLoaded = TRUE; + AirpcapVersion = AIRPCAP_DLL_OLD; + return AIRPCAP_DLL_OK; + }else{ + AirpcapLoaded = FALSE; + AirpcapVersion = AIRPCAP_DLL_ERROR; + } } + return AirpcapVersion; } /* diff --git a/airpcap_loader.h b/airpcap_loader.h index da345e247a..98de26a5f2 100644 --- a/airpcap_loader.h +++ b/airpcap_loader.h @@ -81,6 +81,21 @@ typedef BOOL (*AirpcapSetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHan typedef BOOL (*AirpcapGetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable); typedef BOOL (*AirpcapStoreCurConfigAsAdapterDefaultHandler)(PAirpcapHandle AdapterHandle); typedef VOID (*AirpcapGetVersionHandler)(PUINT VersionMajor, PUINT VersionMinor, PUINT VersionRev, PUINT VersionBuild); +typedef BOOL (*AirpcapSetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo); +typedef BOOL (*AirpcapGetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo); +typedef BOOL (*AirpcapGetDeviceSupportedChannelsHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo **ppChannelInfo, PULONG pNumChannelInfo); + +#define FLAG_CAN_BE_LOW 0x00000001 +#define FLAG_CAN_BE_HIGH 0x00000002 +#define FLAG_IS_BG_CHANNEL 0x00000004 +#define FLAG_IS_A_CHANNEL 0x00000008 + +typedef struct _Dot11Channel +{ + UINT Channel; + ULONG Frequency; + ULONG Flags; +} Dot11Channel; /* * The list of interfaces returned by "get_airpcap_interface_list()" is @@ -91,17 +106,19 @@ typedef struct { char *description; /* from OS, e.g. "Local Area Connection" or NULL */ GSList *ip_addr; /* containing address values of if_addr_t */ gboolean loopback; /* TRUE if loopback, FALSE otherwise */ - AirpcapLinkType linkType; /* The link layer type*/ - UINT channel; /* Channel (1-14)*/ + AirpcapLinkType linkType; /* The link layer type */ + AirpcapChannelInfo channelInfo; /* Channel Information */ BOOL IsFcsPresent; /* Include 802.11 CRC in frames */ AirpcapValidationType CrcValidationOn; /* Capture Frames with Wrong CRC */ - AirpcapDecryptionState DecryptionOn; /* TRUE if decryption is on, FALSE otherwise*/ + AirpcapDecryptionState DecryptionOn; /* TRUE if decryption is on, FALSE otherwise */ PAirpcapKeysCollection keysCollection; /* WEP Key collection for the adapter */ UINT keysCollectionSize; /* Size of the key collection */ - gboolean blinking; /* TRUE if is blinkng, FALSE otherwise*/ - gboolean led; /* TRUE if on, FALSE if off*/ + gboolean blinking; /* TRUE if is blinkng, FALSE otherwise */ + gboolean led; /* TRUE if on, FALSE if off */ gboolean saved; /* TRUE if current configuration has been saved, FALSE otherwise */ gint tag; /* int for the gtk blinking callback */ + Dot11Channel *pSupportedChannels; + ULONG numSupportedChannels; } airpcap_if_info_t; /* @@ -123,7 +140,7 @@ extern airpcap_if_info_t *airpcap_if_selected; extern airpcap_if_info_t *airpcap_if_active; /* WLAN preferences pointer */ -//extern module_t *wlan_prefs; +/*extern module_t *wlan_prefs; - TODO: What is this?? */ /* * Function used to read the Decryption Keys from the preferences and store them @@ -177,7 +194,7 @@ free_airpcap_interface_list(GList *if_list); * Used to retrieve the interface given the name * (the name is used in AirpcapOpen) */ -airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name); +airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name); /* * Airpcap wrapper, used to store the current settings for the selected adapter @@ -264,12 +281,54 @@ BOOL airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch); /* + * Airpcap wrapper, get the channels supported by the adapter + */ +BOOL +airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, PULONG nInfo); + +/* + * Airpcap wrapper, get supported channels formatted into an array + */ +Dot11Channel* +airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels); + +/* + * Get channel representation string given a Frequency + */ +gchar* +airpcap_get_channelstr_from_freq(ULONG chan_freq); + +/* + * Get channel number given a Frequency + */ +guint +airpcap_get_channel_number_from_freq(ULONG chan_freq); + +/* + * Get Frequency given a Channel number + */ +ULONG +airpcap_get_freq_from_channel_number(guint chan_number); + +/* * Airpcap wrapper, used to set the channel of an airpcap adapter */ BOOL airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch); /* + * Airpcap wrapper, used to get the frequency of an airpcap adapter + */ +BOOL +airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo); + +/* + * Airpcap wrapper, used to set the frequency of an airpcap adapter + */ +BOOL +airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo); + +/* * Airpcap wrapper, used to open an airpcap adapter */ PAirpcapHandle airpcap_if_open(PCHAR name, PCHAR err); @@ -280,6 +339,12 @@ PAirpcapHandle airpcap_if_open(PCHAR name, PCHAR err); VOID airpcap_if_close(PAirpcapHandle handle); /* + * Retrieve the state of the Airpcap DLL + */ +int +airpcap_get_dll_state(); + +/* * Airpcap wrapper, used to turn on the led of an airpcap adapter */ BOOL airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber); @@ -331,20 +396,6 @@ void airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info); /* - * Used to retrieve the name of the interface given the description - * (the name is used in AirpcapOpen, the description is put in the combo box) - */ -gchar* -get_airpcap_name_from_description(GList* if_list, gchar* description); - -/* - * Used to retrieve the airpcap_if_info_t of the selected interface given the - * description (that is the entry of the combo box). - */ -gpointer -get_airpcap_if_from_description(GList* if_list, const gchar* description); - -/* * Used to retrieve the two chars string from interface description */ gchar* diff --git a/config.nmake b/config.nmake index 754a764635..74603cc852 100644 --- a/config.nmake +++ b/config.nmake @@ -629,6 +629,7 @@ PANGO_LIB_DIR=1.2.0 !IFDEF AIRPCAP_DIR AIRPCAP_CONFIG=^#define HAVE_AIRPCAP 1 AIRPDCAP_CONFIG=^#define HAVE_AIRPDCAP 1 +AIRPCAP_CFLAGS=/I$(AIRPCAP_DIR)\include !ELSE AIRPCAP_CONFIG= AIRPDCAP_CONFIG= diff --git a/epan/dissectors/Makefile.nmake b/epan/dissectors/Makefile.nmake index c382ba2780..9c0d30f930 100644 --- a/epan/dissectors/Makefile.nmake +++ b/epan/dissectors/Makefile.nmake @@ -12,7 +12,7 @@ include Makefile.common CFLAGS=-WX -DHAVE_CONFIG_H /I. /I.. /I../.. $(GLIB_CFLAGS) \ $(NET_SNMP_CFLAGS) $(ZLIB_CFLAGS) \ $(PCRE_CFLAGS) $(GNUTLS_CFLAGS) $(NETTLE_CFLAGS) \ - $(KFW_CFLAGS) \ + $(KFW_CFLAGS) $(AIRPCAP_CFLAGS) \ /I$(PCAP_DIR)\include -D_U_="" $(LOCAL_CFLAGS) CVARSDLL=-DWIN32 -DNULL=0 -D_MT -D_DLL diff --git a/epan/dissectors/packet-ieee80211.c b/epan/dissectors/packet-ieee80211.c index b0757b4420..610c52cea8 100644 --- a/epan/dissectors/packet-ieee80211.c +++ b/epan/dissectors/packet-ieee80211.c @@ -3224,18 +3224,18 @@ dissect_mcs_set(proto_tree *tree, tvbuff_t *tvb, int offset, gboolean basic, gbo bit_tree = proto_item_add_subtree(ti, ett_mcsbit_tree); /* Bits 0 - 31 */ - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_0to7, tvb, offset, 1, TRUE); - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_8to15, tvb, offset + 1, 1, TRUE); - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_16to23, tvb, offset + 2, 1, TRUE); - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_24to31, tvb, offset + 3, 1, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_0to7, tvb, offset, 4, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_8to15, tvb, offset, 4, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_16to23, tvb, offset, 4, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_24to31, tvb, offset, 4, TRUE); /* Bits 32 - 52 */ - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_32, tvb, offset + 4, 1, TRUE); - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_33to38, tvb, offset + 4, 1, TRUE); - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_39to52, tvb, offset + 4, 3, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_32, tvb, offset + 4, 4, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_33to38, tvb, offset + 4, 4, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_39to52, tvb, offset + 4, 4, TRUE); /* Bits 53 - 76 */ - proto_tree_add_item(bit_tree, mcsset_rx_bitmask_53to76, tvb, offset + 6, 3, TRUE); + proto_tree_add_item(bit_tree, mcsset_rx_bitmask_53to76, tvb, offset + 6, 4, TRUE); capability = tvb_get_letohs (tvb, offset+10); proto_tree_add_uint_format(mcs_tree, mcsset_highest_data_rate, tvb, offset + 10, 2, diff --git a/epan/dissectors/packet-ieee80211.h b/epan/dissectors/packet-ieee80211.h index f7f99974df..6e34cd45c2 100644 --- a/epan/dissectors/packet-ieee80211.h +++ b/epan/dissectors/packet-ieee80211.h @@ -30,6 +30,7 @@ void capture_ieee80211 (const guchar *, int, int, packet_counts *); void capture_ieee80211_datapad (const guchar *, int, int, packet_counts *); void capture_ieee80211_fixed (const guchar *, int, int, packet_counts *); +void capture_ieee80211_ht (const guchar *, int, int, packet_counts *); void ieee_80211_add_tagged_parameters (tvbuff_t * tvb, int offset, packet_info * pinfo, proto_tree * tree, int tagged_parameters_len); diff --git a/epan/dissectors/packet-radiotap.c b/epan/dissectors/packet-radiotap.c index 673d12eee6..4ec28940f4 100644 --- a/epan/dissectors/packet-radiotap.c +++ b/epan/dissectors/packet-radiotap.c @@ -152,6 +152,14 @@ static int hf_radiotap_mactime = -1; static int hf_radiotap_channel = -1; static int hf_radiotap_channel_frequency = -1; static int hf_radiotap_channel_flags = -1; +static int hf_radiotap_channel_flags_turbo = -1; +static int hf_radiotap_channel_flags_cck = -1; +static int hf_radiotap_channel_flags_ofdm = -1; +static int hf_radiotap_channel_flags_2ghz = -1; +static int hf_radiotap_channel_flags_5ghz = -1; +static int hf_radiotap_channel_flags_passive = -1; +static int hf_radiotap_channel_flags_dynamic = -1; +static int hf_radiotap_channel_flags_gfsk = -1; static int hf_radiotap_fhss_hopset = -1; static int hf_radiotap_fhss_pattern = -1; static int hf_radiotap_datarate = -1; @@ -198,6 +206,7 @@ static int hf_radiotap_fcs_bad = -1; static gint ett_radiotap = -1; static gint ett_radiotap_present = -1; static gint ett_radiotap_flags = -1; +static gint ett_radiotap_channel_flags = -1; static dissector_handle_t ieee80211_handle; static dissector_handle_t ieee80211_datapad_handle; @@ -503,9 +512,34 @@ proto_register_radiotap(void) "Channel frequency in megahertz that this frame was sent/received on", HFILL } }, { &hf_radiotap_channel_flags, - { "Channel type", "radiotap.channel.flags", + { "Channel type", "radiotap.channel.type", FT_UINT16, BASE_HEX, VALS(phy_type), 0x0, - "", HFILL } }, + "Channel type", HFILL } }, + + { &hf_radiotap_channel_flags_turbo, + { "Turbo", "radiotap.channel.type.turbo", + FT_BOOLEAN, 16, NULL, 0x0010, "Channel Type Turbo", HFILL } }, + { &hf_radiotap_channel_flags_cck, + { "Complementary Code Keying (CCK)", "radiotap.channel.type.cck", + FT_BOOLEAN, 16, NULL, 0x0020, "Channel Type Complementary Code Keying (CCK) Modulation", HFILL } }, + { &hf_radiotap_channel_flags_ofdm, + { "Orthogonal Frequency-Division Multiplexing (OFDM)", "radiotap.channel.type.ofdm", + FT_BOOLEAN, 16, NULL, 0x0040, "Channel Type Orthogonal Frequency-Division Multiplexing (OFDM)", HFILL } }, + { &hf_radiotap_channel_flags_2ghz, + { "2 GHz spectrum", "radiotap.channel.type.2ghz", + FT_BOOLEAN, 16, NULL, 0x0080, "Channel Type 2 GHz spectrum", HFILL } }, + { &hf_radiotap_channel_flags_5ghz, + { "5 GHz spectrum", "radiotap.channel.type.5ghz", + FT_BOOLEAN, 16, NULL, 0x0100, "Channel Type 5 GHz spectrum", HFILL } }, + { &hf_radiotap_channel_flags_passive, + { "Passive", "radiotap.channel.type.passive", + FT_BOOLEAN, 16, NULL, 0x0200, "Channel Type Passive", HFILL } }, + { &hf_radiotap_channel_flags_dynamic, + { "Dynamic CCK-OFDM", "radiotap.channel.type.dynamic", + FT_BOOLEAN, 16, NULL, 0x0400, "Channel Type Dynamic CCK-OFDM Channel", HFILL } }, + { &hf_radiotap_channel_flags_gfsk, + { "Gaussian Frequency Shift Keying (GFSK)", "radiotap.channel.type.gfsk", + FT_BOOLEAN, 16, NULL, 0x0800, "Channel Type Gaussian Frequency Shift Keying (GFSK) Modulation", HFILL } }, { &hf_radiotap_fhss_hopset, { "FHSS Hop Set", "radiotap.fhss.hopset", @@ -572,7 +606,8 @@ proto_register_radiotap(void) static gint *ett[] = { &ett_radiotap, &ett_radiotap_present, - &ett_radiotap_flags + &ett_radiotap_flags, + &ett_radiotap_channel_flags }; proto_radiotap = proto_register_protocol("IEEE 802.11 Radiotap Capture header", "802.11 Radiotap", "radiotap"); @@ -855,6 +890,9 @@ dissect_radiotap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) length_remaining--; break; case IEEE80211_RADIOTAP_CHANNEL: + { + proto_item *it; + proto_tree *flags_tree; align_offset = ALIGN_OFFSET(offset, 2); offset += align_offset; length_remaining -= align_offset; @@ -875,12 +913,30 @@ dissect_radiotap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) tvb, offset, 2, freq); } /* We're already 2-byte aligned. */ - proto_tree_add_uint(radiotap_tree, hf_radiotap_channel_flags, + it = proto_tree_add_uint(radiotap_tree, hf_radiotap_channel_flags, tvb, offset+2, 2, flags); + flags_tree = proto_item_add_subtree(it, ett_radiotap_channel_flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_turbo, + tvb, offset+2, 1, flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_cck, + tvb, offset+2, 1, flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_ofdm, + tvb, offset+2, 1, flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_2ghz, + tvb, offset+2, 1, flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_5ghz, + tvb, offset+3, 1, flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_passive, + tvb, offset+3, 1, flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_dynamic, + tvb, offset+3, 1, flags); + proto_tree_add_boolean(flags_tree, hf_radiotap_channel_flags_gfsk, + tvb, offset+3, 1, flags); } offset+=4 /* Channel + flags */; length_remaining-=4; break; + } case IEEE80211_RADIOTAP_FHSS: align_offset = ALIGN_OFFSET(offset, 2); offset += align_offset; diff --git a/gtk/Makefile.nmake b/gtk/Makefile.nmake index 9ab577f026..96c18a365b 100644 --- a/gtk/Makefile.nmake +++ b/gtk/Makefile.nmake @@ -10,7 +10,7 @@ include ..\config.nmake CFLAGS=-WX -DHAVE_CONFIG_H /I.. /I../wiretap $(GTK_CFLAGS) $(GNUTLS_CFLAGS) \ /I$(PCAP_DIR)\WPCAP\LIBPCAP /I$(PCAP_DIR)\WPCAP\LIBPCAP\bpf \ /I$(PCAP_DIR)\WPCAP\LIBPCAP\lbl \ - /I$(PCAP_DIR)\include $(NET_SNMP_CFLAGS) \ + /I$(PCAP_DIR)\include $(NET_SNMP_CFLAGS) $(AIRPCAP_CFLAGS) \ /Zm800 -D_U_="" -D_NEED_VAR_IMPORT_ $(LOCAL_CFLAGS) \ $(PORTAUDIO_CFLAGS) \ $(HHC_CFLAGS) diff --git a/gtk/airpcap_dlg.c b/gtk/airpcap_dlg.c index ab92fa39fc..dd4881efa6 100644 --- a/gtk/airpcap_dlg.c +++ b/gtk/airpcap_dlg.c @@ -24,6 +24,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -39,6 +40,7 @@ #include <epan/filesystem.h> #include <epan/prefs.h> #include <epan/prefs-int.h> +#include <epan/crypt/wep-wpadefs.h> #include <pcap.h> @@ -375,8 +377,7 @@ static void on_channel_en_changed(GtkWidget *w _U_, gpointer data) { const gchar *s; - - s = gtk_entry_get_text(GTK_ENTRY(w)); + ULONG ch_freq; if ( !block_advanced_signals && (data != NULL) && (w != NULL) ) { @@ -385,244 +386,65 @@ on_channel_en_changed(GtkWidget *w _U_, gpointer data) { if (airpcap_if_selected != NULL) { - airpcap_if_selected->channel = airpcap_get_channel_number(s); + ch_freq = airpcap_get_frequency_from_str(s); + airpcap_if_active->channelInfo.Frequency = ch_freq; airpcap_if_selected->saved = FALSE; + airpcap_update_channel_offset_cb(airpcap_if_selected, ch_freq, GTK_WIDGET(data)); } } } } /* - * Changed callback for the capture type combobox + * Changed callback for the channel offset combobox */ static void -on_capture_type_en_changed(GtkWidget *w _U_, gpointer data) +on_channel_offset_cb_changed(GtkWidget *w _U_, gpointer data) { const gchar *s; - - s = gtk_entry_get_text(GTK_ENTRY(w)); + gchar offset; if ( !block_advanced_signals && (data != NULL) && (w != NULL) ) { + s = gtk_entry_get_text(GTK_ENTRY(w)); if ((g_strcasecmp("",s))) { - airpcap_if_selected->linkType = airpcap_get_link_type(s); - airpcap_if_selected->saved = FALSE; + if (airpcap_if_selected != NULL) + { + sscanf(s,"%d",&offset); + airpcap_if_selected->channelInfo.ExtChannel = offset; + airpcap_if_selected->saved = FALSE; + } } } } /* - * Activate callback for the adapter combobox + * Changed callback for the capture type combobox */ static void -combo_if_activate_cb(GtkWidget *entry _U_, gpointer data) -{ -} - -/* - * Pop-up window, used to ask the user if he wants to save the selected interface settings - * when closing the window. - */ -void -airpcap_ask_for_save_before_closing(GtkWidget *w _U_, gpointer data) -{ - GtkWidget* dialog; - - dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, - PRIMARY_TEXT_START "Save settings before closing?" PRIMARY_TEXT_END "\n\n" - "If you close the window without saving, changes you made will\nbe discarded."); - simple_dialog_set_cb(dialog, airpcap_dialog_save_before_closing_cb, data); -} - -/* user confirmed the "Save settings..." dialog */ -void -airpcap_dialog_save_before_closing_cb(gpointer dialog _U_, gint btn, gpointer data) +on_capture_type_en_changed(GtkWidget *w _U_, gpointer data) { - GtkWidget* interface_combo; - GtkWidget* key_ls; + const gchar *s; - /* I need the combo box entry */ - interface_combo = GTK_WIDGET(OBJECT_GET_DATA(GTK_WIDGET(data),AIRPCAP_ADVANCED_INTERFACE_KEY)); - key_ls = GTK_WIDGET(OBJECT_GET_DATA(data,AIRPCAP_ADVANCED_KEYLIST_KEY)); + s = gtk_entry_get_text(GTK_ENTRY(w)); - switch (btn) + if ( !block_advanced_signals && (data != NULL) && (w != NULL) ) { - case(ESD_BTN_SAVE): - /* save interface and exit */ - airpcap_add_keys_from_list(key_ls,airpcap_if_selected); - airpcap_save_selected_if_configuration(airpcap_if_selected); - /* Remove gtk timeout */ - gtk_timeout_remove(airpcap_if_selected->tag); - break; - case(ESD_BTN_DONT_SAVE): - /* exit without saving */ - break; - - default: - break; + if ((g_strcasecmp("",s))) + { + airpcap_if_selected->linkType = airpcap_get_link_type(s); + airpcap_if_selected->saved = FALSE; + } } } /* - * Pop-up window, used to ask the user if he wants to save the selected interface settings - * when changing the interface in the advanced dialog box + * Activate callback for the adapter combobox */ -void -airpcap_ask_for_save(GtkWidget *entry _U_, gpointer data) -{ - GtkWidget* dialog; - - dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE_CANCEL, - PRIMARY_TEXT_START "Save settings before changing interface?" PRIMARY_TEXT_END "\n\n" - "If you change interface without saving, changes you made will\nbe discarded."); - simple_dialog_set_cb(dialog, airpcap_dialog_save_cb, data); - -} - -/* user confirmed the "Save settings..." dialog */ -void -airpcap_dialog_save_cb(GtkWidget* dialog _U_, gint btn, gpointer data) +static void +combo_if_activate_cb(GtkWidget *entry _U_, gpointer data) { - GtkWidget* interface_combo; - GtkWidget* key_ls; - - /* I need the combo box entry */ - interface_combo = GTK_WIDGET(OBJECT_GET_DATA(GTK_WIDGET(data),AIRPCAP_ADVANCED_INTERFACE_KEY)); - key_ls = GTK_WIDGET(OBJECT_GET_DATA(data,AIRPCAP_ADVANCED_KEYLIST_KEY)); - - switch (btn) - { - case(ESD_BTN_SAVE): - /* save interface and change */ - airpcap_add_keys_from_list(key_ls,airpcap_if_selected); - airpcap_save_selected_if_configuration(airpcap_if_selected); - /* Remove gtk timeout */ - gtk_timeout_remove(airpcap_if_selected->tag); - airpcap_change_if(GTK_COMBO(interface_combo)->entry,data); - break; - case(ESD_BTN_DONT_SAVE): - /* change interface without saving */ - airpcap_change_if(GTK_COMBO(interface_combo)->entry,data); - break; - case(ESD_BTN_CANCEL): - /* don't change interface and don't save */ - break; - default: - break; - } -} - -/* - * Function used to change the selected interface and advanced dialog box - */ -void -airpcap_change_if(GtkWidget *entry _U_, gpointer data) -{ - const gchar *s; - gchar *channel_s; - gchar *capture_s; - GtkWidget *main_w; - - GtkWidget *interface_combo; - GtkWidget *channel_combo; - GtkWidget *capture_combo; - GtkWidget *crc_check; - GtkWidget *wrong_crc_combo; - GtkWidget *blink_bt; - GtkWidget *key_ls; - - airpcap_if_info_t *new_if; - - /* Retrieve the GUI object pointers */ - main_w = GTK_WIDGET(data); - interface_combo = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_ADVANCED_INTERFACE_KEY)); - channel_combo = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_ADVANCED_CHANNEL_KEY)); - capture_combo = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_ADVANCED_LINK_TYPE_KEY)); - crc_check = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_ADVANCED_FCS_CHECK_KEY)); - wrong_crc_combo = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_ADVANCED_FCS_FILTER_KEY)); - blink_bt = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_ADVANCED_BLINK_KEY)); - key_ls = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_ADVANCED_KEYLIST_KEY)); - - s = gtk_entry_get_text(GTK_ENTRY(entry)); - - /* Select actual interface*/ - new_if = get_airpcap_if_from_description(airpcap_if_list, s); - - /* And change the GUI according to it... */ - /* This should always happen, but it seems that the callback is - * called twice, the first time with an 'empty' text... so it - * will return NULL! - */ - if (new_if != NULL) - { - airpcap_if_selected = new_if; - - new_if = NULL; - /* I need to 'block' signals to widgets or they will receive a signal now - and will change twice */ - block_advanced_signals = TRUE; - - /* Blink button */ - if (airpcap_if_selected->blinking) - { -#if GTK_MAJOR_VERSION >= 2 - gtk_button_set_label(GTK_BUTTON(blink_bt),"Stop Blinking"); -#else - gtk_label_set_text(GTK_LABEL(GTK_BIN(blink_bt)->child),"Stop Blinking"); -#endif - } - else - { -#if GTK_MAJOR_VERSION >= 2 - gtk_button_set_label(GTK_BUTTON(blink_bt)," Blink Led "); -#else - gtk_label_set_text(GTK_LABEL(GTK_BIN(blink_bt)->child)," Blink Led "); -#endif - } - - /* Channel combo */ - channel_s = g_strdup_printf("%d",airpcap_if_selected->channel); - if (channel_combo != NULL) /* this event seems to happen when combo is still NULL */ - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_combo)->entry), channel_s); - - /* Link Layer combo */ - capture_s = NULL; - if (airpcap_if_selected->linkType == AIRPCAP_LT_802_11) - { - capture_s = g_strdup_printf(AIRPCAP_LINK_TYPE_NAME_802_11_ONLY); - if (capture_combo != NULL) /* this event seems to happen when combo is still NULL */ - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(capture_combo)->entry), capture_s); - } - else if (airpcap_if_selected->linkType == AIRPCAP_LT_802_11_PLUS_RADIO) - { - capture_s = g_strdup_printf(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO); - if (capture_combo != NULL) /* this event seems to happen when combo is still NULL */ - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(capture_combo)->entry), capture_s); - } - - /* Fcs Presence check box */ - if (airpcap_if_selected->IsFcsPresent) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(crc_check),TRUE); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(crc_check),FALSE); - - /* Wrong Crc combo box */ - if (airpcap_if_selected->CrcValidationOn == AIRPCAP_VT_ACCEPT_EVERYTHING) - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wrong_crc_combo)->entry),AIRPCAP_VALIDATION_TYPE_NAME_ALL); - else if (airpcap_if_selected->CrcValidationOn == AIRPCAP_VT_ACCEPT_CORRECT_FRAMES) - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wrong_crc_combo)->entry),AIRPCAP_VALIDATION_TYPE_NAME_CORRECT); - else if (airpcap_if_selected->CrcValidationOn == AIRPCAP_VT_ACCEPT_CORRUPT_FRAMES) - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(wrong_crc_combo)->entry),AIRPCAP_VALIDATION_TYPE_NAME_CORRUPT); - - /* Remove old keys */ - gtk_list_remove_items(GTK_LIST(key_ls),GTK_LIST(key_ls)->children); - /* Add new keys */ - airpcap_fill_key_list(key_ls); - - /* Enable the signals again */ - block_advanced_signals = FALSE; - } } /* @@ -636,7 +458,7 @@ void update_blink(gpointer data _U_) sel = (airpcap_if_info_t*)data; - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, sel->description), ebuf); + ad = airpcap_if_open(sel->name, ebuf); if (ad) { if (sel->led) @@ -834,7 +656,7 @@ on_key_management_apply_bt_clicked(GtkWidget *button, gpointer data _U_) update_decryption_mode_cm(toolbar_cm); /* Redissect all the packets, and re-evaluate the display filter. */ -/** //cf_redissect_packets(&cfile); **/ +/** cf_redissect_packets(&cfile); **/ } /* * Callback for the Wireless Advanced Settings 'Apply' button. @@ -849,6 +671,7 @@ on_advanced_apply_bt_clicked(GtkWidget *button, gpointer data _U_) GtkWidget *toolbar, *toolbar_if_lb, *toolbar_channel_cm, + *toolbar_channel_offset_cb, *toolbar_wrong_crc_cm; /* retrieve main window */ @@ -857,9 +680,10 @@ on_advanced_apply_bt_clicked(GtkWidget *button, gpointer data _U_) toolbar = GTK_WIDGET(OBJECT_GET_DATA(main_w,AIRPCAP_TOOLBAR_KEY)); /* retrieve toolbar info */ - toolbar_if_lb = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_INTERFACE_KEY)); - toolbar_channel_cm = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_CHANNEL_KEY)); - toolbar_wrong_crc_cm = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_FCS_FILTER_KEY)); + toolbar_if_lb = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_INTERFACE_KEY)); + toolbar_channel_cm = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_CHANNEL_KEY)); + toolbar_channel_offset_cb = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY)); + toolbar_wrong_crc_cm = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_FCS_FILTER_KEY)); /* Save the configuration (for all ) */ airpcap_save_selected_if_configuration(airpcap_if_selected); @@ -868,8 +692,9 @@ on_advanced_apply_bt_clicked(GtkWidget *button, gpointer data _U_) if ( g_strcasecmp(airpcap_if_selected->description,airpcap_if_active->description) == 0) { gtk_label_set_text(GTK_LABEL(toolbar_if_lb), g_strdup_printf("%s %s\t","Current Wireless Interface: #",airpcap_get_if_string_number(airpcap_if_selected))); - airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cm),airpcap_if_selected); - airpcap_validation_type_combo_set_by_type(toolbar_wrong_crc_cm,airpcap_if_selected->CrcValidationOn); + airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cm),airpcap_if_selected); + airpcap_update_channel_offset_combo_entry(GTK_WIDGET(toolbar_channel_offset_cb),airpcap_if_selected->channelInfo.ExtChannel); + airpcap_validation_type_combo_set_by_type(toolbar_wrong_crc_cm,airpcap_if_selected->CrcValidationOn); } } @@ -2101,7 +1926,7 @@ update_decryption_mode_list(GtkWidget *w) enable_decryption_cb_items = g_list_append (enable_decryption_cb_items, AIRPCAP_DECRYPTION_TYPE_STRING_NONE); enable_decryption_cb_items = g_list_append (enable_decryption_cb_items, AIRPCAP_DECRYPTION_TYPE_STRING_WIRESHARK); - if (airpcap_if_list != NULL) + if (airpcap_if_list != NULL && g_list_length(airpcap_if_list) > 0) { enable_decryption_cb_items = g_list_append (enable_decryption_cb_items, AIRPCAP_DECRYPTION_TYPE_STRING_AIRPCAP); } @@ -2144,11 +1969,13 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) GtkWidget *basic_parameters_al; GtkWidget *basic_parameters_tb; GtkWidget *channel_lb; + GtkWidget *channel_offset_lb; GtkWidget *capture_type_lb; GtkWidget *channel_cm; GList *channel_cm_items = NULL; GtkWidget *channel_en; GtkWidget *capture_type_cm; + GtkWidget *channel_offset_cb; GList *capture_type_cm_items = NULL; GtkWidget *capture_type_en; GtkWidget *fcs_ck; @@ -2166,6 +1993,9 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) GtkWidget *apply_bt; GtkWidget *cancel_bt; + /* for loop counter */ + guint i; + /* widgets in the toolbar */ GtkWidget *toolbar, *toolbar_if_lb, @@ -2324,32 +2154,49 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) capture_type_lb = gtk_label_new ("Capture Type:"); gtk_widget_set_name (capture_type_lb, "capture_type_lb"); gtk_widget_show (capture_type_lb); - gtk_table_attach (GTK_TABLE (basic_parameters_tb), capture_type_lb, 0, 1, 1, - 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), + gtk_table_attach (GTK_TABLE (basic_parameters_tb), capture_type_lb, 0, 1, 2, + 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (capture_type_lb), 0, 0.5); + /* Start: Channel offset label */ + channel_offset_lb = gtk_label_new ("Channel Offset:"); + gtk_widget_set_name (channel_offset_lb, "channel_offset_lb"); + gtk_widget_show (channel_offset_lb); + gtk_table_attach (GTK_TABLE (basic_parameters_tb), channel_offset_lb, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (channel_offset_lb), 0, 0.5); + /* End: Channel offset label */ + + /* Start: Channel offset combo box */ + channel_offset_cb = gtk_combo_new(); + gtk_widget_set_name (channel_offset_cb, "channel_offset_cb"); + gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(channel_offset_cb)->entry),FALSE); + + airpcap_update_channel_offset_cb(airpcap_if_selected, airpcap_if_selected->channelInfo.Frequency, channel_offset_cb); + airpcap_update_channel_offset_combo_entry(channel_offset_cb, airpcap_if_selected->channelInfo.ExtChannel); + + gtk_widget_show(channel_offset_cb); + + gtk_table_attach (GTK_TABLE (basic_parameters_tb), channel_offset_cb, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + /* End: Channel offset combo box */ + channel_cm = gtk_combo_new (); gtk_widget_set_name (channel_cm, "channel_cm"); gtk_widget_show (channel_cm); gtk_table_attach (GTK_TABLE (basic_parameters_tb), channel_cm, 1, 2, 0, 1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "1"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "2"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "3"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "4"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "5"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "6"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "7"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "8"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "9"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "10"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "11"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "12"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "13"); - channel_cm_items = g_list_append (channel_cm_items, (gpointer) "14"); - gtk_combo_set_popdown_strings (GTK_COMBO (channel_cm), channel_cm_items); + + if (airpcap_if_selected != NULL && airpcap_if_selected->pSupportedChannels != NULL && airpcap_if_selected->numSupportedChannels > 0){ + for (i = 0; i<(airpcap_if_selected->numSupportedChannels); i++){ + channel_cm_items = g_list_append(channel_cm_items, airpcap_get_channelstr_from_freq(airpcap_if_selected->pSupportedChannels[i].Frequency)); + } + gtk_combo_set_popdown_strings( GTK_COMBO(channel_cm), channel_cm_items) ; + } /* Select the first entry */ if (airpcap_if_selected != NULL) @@ -2367,13 +2214,18 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) capture_type_cm = gtk_combo_new (); gtk_widget_set_name (capture_type_cm, "capture_type_cm"); gtk_widget_show (capture_type_cm); - gtk_table_attach (GTK_TABLE (basic_parameters_tb), capture_type_cm, 1, 2, 1, - 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + gtk_table_attach (GTK_TABLE (basic_parameters_tb), capture_type_cm, 1, 2, 2, + 3, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); capture_type_cm_items = g_list_append (capture_type_cm_items, (gpointer) AIRPCAP_LINK_TYPE_NAME_802_11_ONLY); capture_type_cm_items = g_list_append (capture_type_cm_items, (gpointer) AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO); + + if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){ + capture_type_cm_items = + g_list_append (capture_type_cm_items, (gpointer) AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI); + } gtk_combo_set_popdown_strings (GTK_COMBO (capture_type_cm), capture_type_cm_items); @@ -2381,10 +2233,14 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) capture_s = NULL; if (airpcap_if_selected != NULL) { - if (airpcap_if_selected->linkType == AIRPCAP_LT_802_11) - capture_s = g_strdup_printf("%s",AIRPCAP_LINK_TYPE_NAME_802_11_ONLY); - else if (airpcap_if_selected->linkType == AIRPCAP_LT_802_11_PLUS_RADIO) - capture_s = g_strdup_printf("%s",AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO); + if (airpcap_if_selected->linkType == AIRPCAP_LT_802_11){ + capture_s = g_strdup_printf("%s",AIRPCAP_LINK_TYPE_NAME_802_11_ONLY); + }else if (airpcap_if_selected->linkType == AIRPCAP_LT_802_11_PLUS_RADIO){ + capture_s = g_strdup_printf("%s",AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO); + }else if (airpcap_if_selected->linkType == AIRPCAP_LT_802_11_PLUS_PPI){ + capture_s = g_strdup_printf("%s",AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI); + } + if (capture_s != NULL) gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(capture_type_cm)->entry), capture_s); } g_free(capture_s); @@ -2421,7 +2277,7 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) "basic_parameters_fcs_h_box"); gtk_widget_show (basic_parameters_fcs_h_box); gtk_table_attach (GTK_TABLE (basic_parameters_tb), - basic_parameters_fcs_h_box, 2, 3, 1, 2, + basic_parameters_fcs_h_box, 2, 3, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 3, 0); @@ -2492,7 +2348,7 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) #endif gtk_widget_set_name (reset_configuration_bt, "reset_configuration_bt"); /* gtk_widget_show (reset_configuration_bt); */ - gtk_container_add (GTK_CONTAINER (left_h_button_box), + gtk_container_add (GTK_CONTAINER (low_buttons_h_box), reset_configuration_bt); GTK_WIDGET_SET_FLAGS (reset_configuration_bt, GTK_CAN_DEFAULT); @@ -2520,7 +2376,8 @@ display_airpcap_advanced_cb(GtkWidget *w, gpointer data) SIGNAL_CONNECT (blink_bt, "clicked", on_what_s_this_bt_clicked, airpcap_advanced_w); } - SIGNAL_CONNECT (channel_en, "changed",on_channel_en_changed, airpcap_advanced_w); + SIGNAL_CONNECT (channel_en, "changed",on_channel_en_changed, channel_offset_cb); + SIGNAL_CONNECT (GTK_COMBO(channel_offset_cb)->entry, "changed",on_channel_offset_cb_changed, airpcap_advanced_w); SIGNAL_CONNECT (capture_type_en, "changed",on_capture_type_en_changed, airpcap_advanced_w); SIGNAL_CONNECT (fcs_ck, "toggled",on_fcs_ck_toggled, airpcap_advanced_w); SIGNAL_CONNECT (fcs_filter_en, "changed",on_fcs_filter_en_changed, airpcap_advanced_w); @@ -2577,26 +2434,28 @@ on_advanced_ok_bt_clicked(GtkWidget *button, gpointer data _U_) GtkWidget *toolbar, *toolbar_if_lb, *toolbar_channel_cm, + *toolbar_channel_offset_cb, *toolbar_wrong_crc_cm, *advanced_bt; /* Retrieve the GUI object pointers */ - airpcap_advanced_w = GTK_WIDGET(data); - interface_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_INTERFACE_KEY)); - channel_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_CHANNEL_KEY)); - capture_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_LINK_TYPE_KEY)); - crc_check = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_FCS_CHECK_KEY)); - wrong_crc_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_FCS_FILTER_KEY)); - blink_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_BLINK_KEY)); - cancel_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_CANCEL_KEY)); - ok_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_OK_KEY)); - advanced_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_KEY)); - - toolbar = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_TOOLBAR_KEY)); + airpcap_advanced_w = GTK_WIDGET(data); + interface_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_INTERFACE_KEY)); + channel_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_CHANNEL_KEY)); + capture_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_LINK_TYPE_KEY)); + crc_check = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_FCS_CHECK_KEY)); + wrong_crc_combo = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_FCS_FILTER_KEY)); + blink_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_BLINK_KEY)); + cancel_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_CANCEL_KEY)); + ok_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_OK_KEY)); + advanced_bt = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_ADVANCED_KEY)); + + toolbar = GTK_WIDGET(OBJECT_GET_DATA(airpcap_advanced_w,AIRPCAP_TOOLBAR_KEY)); /* retrieve toolbar info */ toolbar_if_lb = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_INTERFACE_KEY)); toolbar_channel_cm = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_CHANNEL_KEY)); + toolbar_channel_offset_cb = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY)); toolbar_wrong_crc_cm = GTK_WIDGET(OBJECT_GET_DATA(toolbar,AIRPCAP_TOOLBAR_FCS_FILTER_KEY)); /* Stop blinking ALL leds (go through the airpcap_if_list) */ @@ -2624,14 +2483,13 @@ on_advanced_ok_bt_clicked(GtkWidget *button, gpointer data _U_) if ( g_strcasecmp(airpcap_if_selected->description,airpcap_if_active->description) == 0) { gtk_label_set_text(GTK_LABEL(toolbar_if_lb), g_strdup_printf("%s %s\t","Current Wireless Interface: #",airpcap_get_if_string_number(airpcap_if_selected))); - airpcap_update_channel_combo(GTK_WIDGET(toolbar_channel_cm),airpcap_if_selected); - + airpcap_update_channel_offset_combo_entry(GTK_WIDGET(toolbar_channel_offset_cb),airpcap_if_selected->channelInfo.ExtChannel); airpcap_validation_type_combo_set_by_type(toolbar_wrong_crc_cm,airpcap_if_selected->CrcValidationOn); } /* If interface active is airpcap, set sensitive TRUE for airpcap toolbar */ - if ( get_airpcap_if_by_name(airpcap_if_list,airpcap_if_active->description) != NULL) + if ( get_airpcap_if_from_name(airpcap_if_list,airpcap_if_active->description) != NULL) { airpcap_set_toolbar_start_capture(airpcap_if_active); } @@ -3102,11 +2960,11 @@ on_key_management_ok_bt_clicked(GtkWidget *button, gpointer data _U_) write_prefs_to_file(); /* If interface active is airpcap, set sensitive TRUE for airpcap toolbar */ - if (airpcap_if_list != NULL) + if (airpcap_if_list != NULL && g_list_length(airpcap_if_list) > 0) { if (airpcap_if_active != NULL) { - if ( get_airpcap_if_by_name(airpcap_if_list,airpcap_if_active->description) != NULL) + if ( get_airpcap_if_from_name(airpcap_if_list,airpcap_if_active->description) != NULL) { airpcap_set_toolbar_start_capture(airpcap_if_active); } diff --git a/gtk/airpcap_dlg.h b/gtk/airpcap_dlg.h index e5fbcc904d..82cc3373c9 100644 --- a/gtk/airpcap_dlg.h +++ b/gtk/airpcap_dlg.h @@ -51,29 +51,6 @@ void on_add_key_w_destroy(GtkWidget *button, gpointer data _U_); /* - * Pop-up window, used to ask the user if he wants to save the selected interface settings - * when closing the window. - */ -void -airpcap_ask_for_save_before_closing(GtkWidget *w _U_, gpointer data); - -/* user confirmed the "Save settings..." dialog */ -void -airpcap_dialog_save_before_closing_cb(gpointer dialog _U_, gint btn, gpointer data); - -/* - * Pop-up window, used to ask the user if he wants to save the selected interface settings - */ -void -airpcap_ask_for_save(GtkWidget *entry _U_, gpointer data); - -/* - * Function used to change the selected interface and advanced dialog box - */ -void -airpcap_change_if(GtkWidget *entry _U_, gpointer data); - -/* * Fill the interface combo box specified */ void @@ -262,12 +239,6 @@ static void combo_if_activate_cb(GtkWidget *w _U_, gpointer data); /* - * Pop-up window that appears when user confirms the "Save settings..." dialog - */ -static void -airpcap_dialog_save_cb(GtkWidget* dialog _U_, gint btn, gpointer data); - -/* * Thread function used to blink the led */ void update_blink(gpointer data _U_); diff --git a/gtk/airpcap_gui_utils.c b/gtk/airpcap_gui_utils.c index f5d2abce59..fc413fd1bb 100644 --- a/gtk/airpcap_gui_utils.c +++ b/gtk/airpcap_gui_utils.c @@ -54,6 +54,9 @@ #include "keys.h" +/* Controls the releay of settings back to the adapter. */ +gboolean change_airpcap_settings = FALSE; + /* * Used to retrieve a string containing a list of all the channels * on which at least one adapter is capturing. This is true @@ -63,37 +66,37 @@ gchar* airpcap_get_all_channels_list(airpcap_if_info_t* if_info) { - gchar *channels; + gchar *frequencies; gchar *tmp; guint n,i; GList *current_item; airpcap_if_info_t* current_adapter; /* Allocate the string used to store the ASCII representation of the WEP key */ - channels = (gchar*)g_malloc(sizeof(gchar)*128); + frequencies = (gchar*)g_malloc(sizeof(gchar)*128); /* Make sure that the first char is '\0' in order to make g_strlcat() work */ - channels[0]='\0'; + frequencies[0]='\0'; if(airpcap_if_is_any(if_info)) { - n = g_list_length(airpcap_if_list); - - for(i = 0; i < n; i++) - { - current_item = g_list_nth(airpcap_if_list,i); - current_adapter = (airpcap_if_info_t*)current_item->data; - if(current_adapter != if_info) - { - tmp = g_strdup_printf("%d",current_adapter->channel); - g_strlcat(channels,tmp,128); - g_free(tmp); - - if(i<(n-1)) g_strlcat(channels,",",128); - } - } + n = g_list_length(airpcap_if_list); + + for(i = 0; i < n; i++) + { + current_item = g_list_nth(airpcap_if_list,i); + current_adapter = (airpcap_if_info_t*)current_item->data; + if(current_adapter != if_info && g_strncasecmp("AirPcap USB wireless capture adapter nr.", current_adapter->description, 40) == 0) + { + tmp = g_strdup_printf("%d",current_adapter->channelInfo.Frequency); + g_strlcat(frequencies,tmp,128); + g_free(tmp); + + if(i<(n-1)) g_strlcat(frequencies,",",128); + } + } } - return channels; + return frequencies; } /* @@ -105,6 +108,8 @@ airpcap_set_toolbar_start_capture(airpcap_if_info_t* if_info) GtkWidget *airpcap_toolbar_label; GtkWidget *airpcap_toolbar_channel; GtkWidget *airpcap_toolbar_channel_lb; + GtkWidget *airpcap_toolbar_channel_offset; + GtkWidget *airpcap_toolbar_channel_offset_lb; GtkWidget *airpcap_toolbar_button; GtkWidget *airpcap_toolbar_fcs; GtkWidget *airpcap_toolbar_fcs_lb; @@ -117,6 +122,8 @@ airpcap_set_toolbar_start_capture(airpcap_if_info_t* if_info) airpcap_toolbar_label = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_INTERFACE_KEY); airpcap_toolbar_channel = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_KEY); airpcap_toolbar_channel_lb = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY); + airpcap_toolbar_channel_offset = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY); + airpcap_toolbar_channel_offset_lb = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY); airpcap_toolbar_fcs = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_FCS_FILTER_KEY); airpcap_toolbar_fcs_lb = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY); airpcap_toolbar_button = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_ADVANCED_KEY); @@ -127,45 +134,65 @@ airpcap_set_toolbar_start_capture(airpcap_if_info_t* if_info) /* The current interface is an airpcap interface */ if(if_info != NULL) { - gtk_widget_set_sensitive(airpcap_tb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_channel,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE); - airpcap_update_channel_combo(GTK_WIDGET(airpcap_toolbar_channel),if_info); - - /*decription check box*/ - gtk_signal_handler_block_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); - if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE); - gtk_signal_handler_unblock_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); - - if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info)); - gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text); - g_free(if_label_text); + gtk_widget_set_sensitive(airpcap_tb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE); + + /*decription check box*/ + gtk_signal_handler_block_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); + if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE); + gtk_signal_handler_unblock_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); + + if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info)); + gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text); + g_free(if_label_text); + + change_airpcap_settings = FALSE; + if (if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){ + guint i = 0; + GList *channel_list = NULL; + + for (; i<if_info->numSupportedChannels; i++){ + channel_list = g_list_append(channel_list, airpcap_get_channelstr_from_freq(if_info->pSupportedChannels[i].Frequency)); + } + gtk_combo_set_popdown_strings( GTK_COMBO(airpcap_toolbar_channel), channel_list); + g_list_free(channel_list); + } + + airpcap_update_channel_combo(GTK_WIDGET(airpcap_toolbar_channel),if_info); + airpcap_update_channel_offset_cb(if_info, if_info->channelInfo.Frequency, airpcap_toolbar_channel_offset); + airpcap_update_channel_offset_combo_entry(airpcap_toolbar_channel_offset, if_info->channelInfo.ExtChannel); + change_airpcap_settings = TRUE; } else /* Current interface is NOT an AirPcap one... */ { - gtk_widget_set_sensitive(airpcap_tb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_channel,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE); - airpcap_set_toolbar_no_if(airpcap_tb); + gtk_widget_set_sensitive(airpcap_tb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_keys_button,FALSE); + airpcap_set_toolbar_no_if(airpcap_tb); } } @@ -179,6 +206,8 @@ airpcap_set_toolbar_stop_capture(airpcap_if_info_t* if_info) GtkWidget *airpcap_toolbar_label; GtkWidget *airpcap_toolbar_channel; GtkWidget *airpcap_toolbar_channel_lb; + GtkWidget *airpcap_toolbar_channel_offset; + GtkWidget *airpcap_toolbar_channel_offset_lb; GtkWidget *airpcap_toolbar_button; GtkWidget *airpcap_toolbar_fcs; GtkWidget *airpcap_toolbar_fcs_lb; @@ -192,6 +221,8 @@ airpcap_set_toolbar_stop_capture(airpcap_if_info_t* if_info) airpcap_toolbar_label = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_INTERFACE_KEY); airpcap_toolbar_channel = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_KEY); airpcap_toolbar_channel_lb = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY); + airpcap_toolbar_channel_offset = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY); + airpcap_toolbar_channel_offset_lb = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY); airpcap_toolbar_fcs = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_FCS_FILTER_KEY); airpcap_toolbar_fcs_lb = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY); airpcap_toolbar_button = OBJECT_GET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_ADVANCED_KEY); @@ -202,47 +233,67 @@ airpcap_set_toolbar_stop_capture(airpcap_if_info_t* if_info) /* The current interface is an airpcap interface */ if(if_info != NULL) { - gtk_widget_set_sensitive(airpcap_tb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_channel,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_button,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE); - airpcap_validation_type_combo_set_by_type(GTK_WIDGET(airpcap_toolbar_crc_filter_combo),if_info->CrcValidationOn); - airpcap_update_channel_combo(GTK_WIDGET(airpcap_toolbar_channel),if_info); - - /*decription check box*/ - gtk_signal_handler_block_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); - if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE); - else - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE); - gtk_signal_handler_unblock_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); - - - if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info)); - gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text); - g_free(if_label_text); - } + gtk_widget_set_sensitive(airpcap_tb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_label,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_button,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE); + airpcap_validation_type_combo_set_by_type(GTK_WIDGET(airpcap_toolbar_crc_filter_combo),if_info->CrcValidationOn); + + /*decription check box*/ + gtk_signal_handler_block_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); + if(if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),TRUE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(airpcap_toolbar_decryption),FALSE); + gtk_signal_handler_unblock_by_func (GTK_OBJECT(airpcap_toolbar_decryption),GTK_SIGNAL_FUNC(airpcap_toolbar_encryption_cb), airpcap_tb); + + if_label_text = g_strdup_printf("Current Wireless Interface: #%s", airpcap_get_if_string_number(if_info)); + gtk_label_set_text(GTK_LABEL(airpcap_toolbar_label),if_label_text); + g_free(if_label_text); + + change_airpcap_settings = FALSE; + if (if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){ + guint i = 0; + GList *channel_list = NULL; + + for (; i<if_info->numSupportedChannels; i++){ + channel_list = g_list_append(channel_list, airpcap_get_channelstr_from_freq(if_info->pSupportedChannels[i].Frequency)); + } + gtk_combo_set_popdown_strings( GTK_COMBO(airpcap_toolbar_channel), channel_list); + g_list_free(channel_list); + } + + airpcap_update_channel_combo(GTK_WIDGET(airpcap_toolbar_channel),if_info); + airpcap_update_channel_offset_cb(if_info, if_info->channelInfo.Frequency, airpcap_toolbar_channel_offset); + airpcap_update_channel_offset_combo_entry(airpcap_toolbar_channel_offset, if_info->channelInfo.ExtChannel); + change_airpcap_settings = TRUE; + } else { - gtk_widget_set_sensitive(airpcap_tb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_channel,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,FALSE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE); - gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE); - airpcap_set_toolbar_no_if(airpcap_tb); + gtk_widget_set_sensitive(airpcap_tb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_label,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_channel_offset_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_fcs_lb,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_button,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_crc_filter_combo,FALSE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_decryption_lb,TRUE); + gtk_widget_set_sensitive(airpcap_toolbar_keys_button,TRUE); + airpcap_set_toolbar_no_if(airpcap_tb); + change_airpcap_settings = FALSE; } } @@ -435,17 +486,14 @@ airpcap_get_validation_name(AirpcapValidationType vt) AirpcapLinkType airpcap_get_link_type(const gchar* name) { - if(!(g_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_ONLY,name))) - { - return AIRPCAP_LT_802_11; - } - else if(!(g_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO,name))) - { - return AIRPCAP_LT_802_11_PLUS_RADIO; - } - else - { - return AIRPCAP_LT_UNKNOWN; + if(!(g_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_ONLY,name))){ + return AIRPCAP_LT_802_11; + }else if(!(g_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO,name))){ + return AIRPCAP_LT_802_11_PLUS_RADIO; + }else if(!(g_strcasecmp(AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI,name))){ + return AIRPCAP_LT_802_11_PLUS_PPI; + }else{ + return AIRPCAP_LT_UNKNOWN; } } @@ -456,17 +504,14 @@ airpcap_get_link_type(const gchar* name) gchar* airpcap_get_link_name(AirpcapLinkType lt) { - if(lt == AIRPCAP_LT_802_11) - { - return AIRPCAP_LINK_TYPE_NAME_802_11_ONLY; - } - else if(lt == AIRPCAP_LT_802_11_PLUS_RADIO) - { - return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO; - } - else if(lt == AIRPCAP_LT_UNKNOWN) - { - return AIRPCAP_LINK_TYPE_NAME_UNKNOWN; + if(lt == AIRPCAP_LT_802_11){ + return AIRPCAP_LINK_TYPE_NAME_802_11_ONLY; + }else if(lt == AIRPCAP_LT_802_11_PLUS_RADIO){ + return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO; + }else if(lt == AIRPCAP_LT_802_11_PLUS_PPI){ + return AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI; + }else if(lt == AIRPCAP_LT_UNKNOWN){ + return AIRPCAP_LINK_TYPE_NAME_UNKNOWN; } return NULL; } @@ -524,16 +569,16 @@ airpcap_validation_type_combo_get_type(GtkWidget* c) /* * Retrieve the UINT corresponding to the given string (channel only, handle with care!) */ -UINT -airpcap_get_channel_number(const gchar* s) +ULONG +airpcap_get_frequency_from_str(const gchar* s) { - int ch_num; + ULONG ch_freq; - sscanf(s,"%d",&ch_num); + sscanf(s,"%ld",&ch_freq); /* XXX - check for ch_num btween 1-14, and return -1 otherwise??? */ - return ch_num; + return ch_freq; } /* @@ -549,9 +594,85 @@ airpcap_get_channel_name(UINT n) * Set the combo box entry string given an UINT channel number */ void -airpcap_channel_combo_set_by_number(GtkWidget* w,UINT channel) +airpcap_channel_combo_set_by_number(GtkWidget* w,UINT chan_freq) +{ + gchar *entry_text; + + entry_text = airpcap_get_channelstr_from_freq(chan_freq); + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),airpcap_get_channelstr_from_freq(chan_freq)); + g_free(entry_text); +} + +/* + * Change channel of Airpcap Adapter + */ +gboolean +airpcap_update_frequency_and_offset(airpcap_if_info_t* if_info) { - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),airpcap_get_channel_name(channel)); + gchar ebuf[AIRPCAP_ERRBUF_SIZE]; + PAirpcapHandle ad; + gboolean return_value = FALSE; + + if (if_info != NULL){ + ad = airpcap_if_open(if_info->name, ebuf); + + if(ad != NULL) { + return_value = airpcap_if_set_device_channel_ex(ad,if_info->channelInfo); + airpcap_if_close(ad); + } + } + + return return_value; +} + +/* + * Update the channel offset of the given combobox + */ +void +airpcap_update_channel_offset_cb(airpcap_if_info_t* if_info, ULONG ch_freq, GtkWidget *channel_offset_cb) +{ + const gchar *current_offset; + gchar current_offset_copy[10]; + gchar *new_offset_str; + ULONG chan_flags; + + if (airpcap_if_is_any(if_info)){ + gtk_widget_set_sensitive(GTK_WIDGET(channel_offset_cb),FALSE); + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_offset_cb)->entry), "0"); + return; + } + + current_offset = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(channel_offset_cb)->entry)); + strcpy (current_offset_copy, current_offset); + chan_flags = airpcap_load_channel_offset_cb(if_info, channel_offset_cb, ch_freq); + + new_offset_str = current_offset_copy; + + /* If current_offset == -1 && new_offset cannot be -1 */ + if (strcmp(current_offset_copy, "-1") == 0 && !(chan_flags & FLAG_CAN_BE_HIGH)){ + if ((chan_flags & FLAG_CAN_BE_LOW)){ + new_offset_str = "+1"; + }else{ + new_offset_str = "0"; + } + }else if (strcmp(current_offset_copy, "+1") == 0 && !(chan_flags & FLAG_CAN_BE_LOW)){ + if ((chan_flags & FLAG_CAN_BE_HIGH)){ + new_offset_str = "-1"; + }else{ + new_offset_str = "0"; + } + } + + change_airpcap_settings = FALSE; + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_offset_cb)->entry), new_offset_str); + change_airpcap_settings = TRUE; + + sscanf(new_offset_str,"%d",&(if_info->channelInfo.ExtChannel)); + if (!airpcap_update_frequency_and_offset(if_info)){ + simple_dialog(ESD_TYPE_ERROR,ESD_BTN_OK,"Adapter failed to be set with the following settings: Frequency - %ld Extension Channel - %d", if_info->channelInfo.Frequency, if_info->channelInfo.ExtChannel); + } + + g_free(new_offset_str); } /* @@ -572,23 +693,73 @@ airpcap_if_is_any(airpcap_if_info_t* if_info) void airpcap_update_channel_combo(GtkWidget* w, airpcap_if_info_t* if_info) { -gchar* channels_list; + gchar* frequency_list; if(airpcap_if_is_any(if_info)) { - channels_list = airpcap_get_all_channels_list(if_info); - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),channels_list); - g_free(channels_list); - gtk_widget_set_sensitive(GTK_WIDGET(w),FALSE); + frequency_list = airpcap_get_all_channels_list(if_info); + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry),frequency_list); + g_free(frequency_list); + change_airpcap_settings = FALSE; + gtk_widget_set_sensitive(GTK_WIDGET(w),FALSE); } else { - airpcap_channel_combo_set_by_number(w,if_info->channel); - gtk_widget_set_sensitive(GTK_WIDGET(w),TRUE); + airpcap_channel_combo_set_by_number(w,if_info->channelInfo.Frequency); + change_airpcap_settings = TRUE; + gtk_widget_set_sensitive(GTK_WIDGET(w),TRUE); } } /* + * Update channel offset combo box to 'offset'. + */ +void +airpcap_update_channel_offset_combo_entry(GtkWidget* w, gchar extChannel) +{ + gchar channel_offset_value[3]; + + if (extChannel > 0){ + sprintf(channel_offset_value, "+%d", extChannel); + }else{ + sprintf(channel_offset_value, "%d", extChannel); + } + + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(w)->entry), channel_offset_value); +} + +/* + * Update channel offset combo box given the selected frequency. Return the flags from the given frequency. + */ +ULONG +airpcap_load_channel_offset_cb(airpcap_if_info_t* if_info, GtkWidget* channel_offset_cb, ULONG chan_freq) +{ + GList *channel_offset_list = NULL; + + if (if_info != NULL && if_info->pSupportedChannels != NULL && if_info->numSupportedChannels > 0){ + guint i = 0; + + for (; i<if_info->numSupportedChannels; i++){ + if (if_info->pSupportedChannels[i].Frequency == chan_freq){ + if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_HIGH)){ + channel_offset_list = g_list_append(channel_offset_list, "-1"); + } + channel_offset_list = g_list_append(channel_offset_list, "0"); + if ((if_info->pSupportedChannels[i].Flags & FLAG_CAN_BE_LOW)){ + channel_offset_list = g_list_append(channel_offset_list, "+1"); + } + gtk_combo_set_popdown_strings( GTK_COMBO(channel_offset_cb), channel_offset_list) ; + gtk_widget_set_sensitive(channel_offset_cb, g_list_length(channel_offset_list) > 1); + g_list_free(channel_offset_list); + return if_info->pSupportedChannels[i].Flags; + } + } + } + + return NULL; +} + +/* * Takes the keys from the GtkList widget, and add them to the interface list */ void @@ -1026,6 +1197,8 @@ airpcap_enable_toolbar_widgets(GtkWidget* w, gboolean en) *if_description_lb, *channel_cb, *channel_lb, + *channel_offset_cb, + *channel_offset_lb, *fcs_cb, *fcs_lb, *advanced_bt; @@ -1038,6 +1211,8 @@ airpcap_enable_toolbar_widgets(GtkWidget* w, gboolean en) if_description_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_INTERFACE_KEY); channel_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY); channel_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_KEY); + channel_offset_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY); + channel_offset_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY); fcs_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY); fcs_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_FCS_FILTER_KEY); advanced_bt = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_ADVANCED_KEY); @@ -1046,6 +1221,8 @@ airpcap_enable_toolbar_widgets(GtkWidget* w, gboolean en) if(if_description_lb != NULL) gtk_widget_set_sensitive(if_description_lb,en); if(channel_lb != NULL) gtk_widget_set_sensitive(channel_lb,en); if(channel_cb != NULL) gtk_widget_set_sensitive(channel_cb,en); + if(channel_offset_cb != NULL) gtk_widget_set_sensitive(channel_offset_cb,en); + if(channel_offset_lb != NULL) gtk_widget_set_sensitive(channel_offset_lb,en); if(fcs_lb != NULL) gtk_widget_set_sensitive(fcs_lb,en); if(fcs_cb != NULL) gtk_widget_set_sensitive(fcs_cb,en); if(advanced_bt != NULL) gtk_widget_set_sensitive(advanced_bt,en); @@ -1064,6 +1241,8 @@ airpcap_set_toolbar_no_if(GtkWidget* w) *if_description_lb, *channel_cb, *channel_lb, + *channel_offset_cb, + *channel_offset_lb, *fcs_cb, *fcs_lb, *advanced_bt; @@ -1073,15 +1252,18 @@ airpcap_set_toolbar_no_if(GtkWidget* w) toolbar_tb = w; - if_description_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_INTERFACE_KEY); - channel_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY); - channel_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_KEY); - fcs_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY); - fcs_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_FCS_FILTER_KEY); - advanced_bt = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_ADVANCED_KEY); + if_description_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_INTERFACE_KEY); + channel_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY); + channel_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_KEY); + channel_offset_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY); + channel_offset_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY); + fcs_lb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY); + fcs_cb = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_FCS_FILTER_KEY); + advanced_bt = OBJECT_GET_DATA(toolbar_tb,AIRPCAP_TOOLBAR_ADVANCED_KEY); if(fcs_cb != NULL) gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(fcs_cb)->entry),""); if(channel_cb != NULL) gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cb)->entry),""); + if(channel_offset_cb != NULL) gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_offset_cb)->entry),""); if(if_description_lb != NULL) gtk_label_set_text(GTK_LABEL(if_description_lb),"Current Wireless Interface: None"); /*if(if_description_lb != NULL) gtk_widget_set_sensitive(if_description_lb,FALSE); diff --git a/gtk/airpcap_gui_utils.h b/gtk/airpcap_gui_utils.h index d4e4e7c604..5139de8941 100644 --- a/gtk/airpcap_gui_utils.h +++ b/gtk/airpcap_gui_utils.h @@ -35,7 +35,8 @@ #define AIRPCAP_LINK_TYPE_NAME_802_11_ONLY "802.11 Only" #define AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_RADIO "802.11 + Radio" -#define AIRPCAP_LINK_TYPE_NAME_UNKNOWN "Unknown" +#define AIRPCAP_LINK_TYPE_NAME_UNKNOWN "Unknown" +#define AIRPCAP_LINK_TYPE_NAME_802_11_PLUS_PPI "802.11 + PPI" #define AIRPCAP_DECRYPTION_TYPE_STRING_WIRESHARK "Wireshark" #define AIRPCAP_DECRYPTION_TYPE_STRING_AIRPCAP "Driver" @@ -44,6 +45,9 @@ #define NO_ROW_SELECTED -1 #define NO_COLUMN_SELECTED -1 +/* Controls the releay of settings back to the adapter. */ +extern gboolean change_airpcap_settings; + /* * This structure is used because we need to store infos about the currently selected * row in the key list. @@ -147,10 +151,16 @@ AirpcapValidationType airpcap_validation_type_combo_get_type(GtkWidget* c); /* + * Update channel offset combo box to 'offset'. + */ +void +airpcap_update_channel_offset_combo_entry(GtkWidget* w, gchar extChannel); + +/* * Returns the string corresponding to the given UINT (1-14, for channel only) */ -UINT -airpcap_get_channel_number(const gchar* s); +ULONG +airpcap_get_frequency_from_str(const gchar* s); /* * Retrieve the UINT corresponding to the given string (channel only, handle with care!) @@ -171,6 +181,12 @@ int airpcap_if_is_any(airpcap_if_info_t* if_info); /* + * Change channel of Airpcap Adapter + */ +gboolean +airpcap_update_frequency_and_offset(airpcap_if_info_t* if_info); + +/* * Takes the keys from the GtkList widget, and add them to the interface list */ void @@ -183,6 +199,18 @@ void airpcap_update_channel_combo(GtkWidget* w, airpcap_if_info_t* if_info); /* + * Update the channel offset of the given combobox + */ +void +airpcap_update_channel_offset_cb(airpcap_if_info_t* if_info, ULONG ch_freq, GtkWidget *channel_offset_cb); + +/* + * Update channel offset combo box given the selected frequency. Return the flags from the given frequency. + */ +ULONG +airpcap_load_channel_offset_cb(airpcap_if_info_t* if_info, GtkWidget* channel_offset_cb, ULONG chan_freq); + +/* * This function will take the current keys (widget list), specified for the * current adapter, and save them as default for ALL the others. */ diff --git a/gtk/capture_dlg.c b/gtk/capture_dlg.c index 656340866d..4420dbeab2 100644 --- a/gtk/capture_dlg.c +++ b/gtk/capture_dlg.c @@ -207,7 +207,7 @@ set_link_type_list(GtkWidget *linktype_om, GtkWidget *entry) /* is it an airpcap interface??? */ /* retrieve the advanced button pointer */ advanced_bt = OBJECT_GET_DATA(entry,AIRPCAP_OPTIONS_ADVANCED_KEY); - airpcap_if_selected = get_airpcap_if_by_name(airpcap_if_list,if_name); + airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,if_name); airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); if( airpcap_if_selected != NULL) { @@ -582,9 +582,11 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) *m_resolv_cb, *n_resolv_cb, *t_resolv_cb, *bbox, *ok_bt, *cancel_bt, *help_bt; +#if GTK_MAJOR_VERSION >= 2 /* For some reason this button's action crashes under GTK 1. */ #ifdef HAVE_AIRPCAP GtkWidget *advanced_hb, *advanced_bt; #endif +#endif #if GTK_MAJOR_VERSION < 2 GtkAccelGroup *accel_group; #endif @@ -700,7 +702,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) #ifdef HAVE_AIRPCAP /* get the airpcap interface (if it IS an airpcap interface, and update the toolbar... and of course enable the advanced button...)*/ - airpcap_if_selected = get_airpcap_if_by_name(airpcap_if_list,capture_opts->iface); + airpcap_if_selected = get_airpcap_if_from_name(airpcap_if_list,capture_opts->iface); #endif if (capture_opts->iface != NULL) { @@ -872,6 +874,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) OBJECT_SET_DATA(filter_bt, E_FILT_TE_PTR_KEY, filter_te); /* advanced row */ +#if GTK_MAJOR_VERSION >= 2 /* For some reason this button's action crashes under GTK 1. */ #ifdef HAVE_AIRPCAP advanced_hb = gtk_hbox_new(FALSE,5); gtk_box_pack_start(GTK_BOX(capture_vb), advanced_hb, FALSE, FALSE, 0); @@ -905,6 +908,7 @@ capture_prep_cb(GtkWidget *w _U_, gpointer d _U_) gtk_widget_show(advanced_bt); gtk_widget_show(advanced_hb); #endif +#endif /* Capture file-related options frame */ file_fr = gtk_frame_new("Capture File(s)"); diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c index ef5483ac8f..35c59d5a19 100644 --- a/gtk/capture_if_dlg.c +++ b/gtk/capture_if_dlg.c @@ -120,6 +120,7 @@ typedef struct if_dlg_data_s { #endif guint32 last_packets; gchar *device; + if_info_t if_info; } if_dlg_data_t; void update_if(if_dlg_data_t *if_dlg_data); @@ -132,7 +133,7 @@ capture_do_cb(GtkWidget *capture_bt _U_, gpointer if_data) if_dlg_data_t *if_dlg_data = if_data; #ifdef HAVE_AIRPCAP - airpcap_if_active = get_airpcap_if_from_description(airpcap_if_list, GTK_LABEL(if_dlg_data->descr_lb)->label); + airpcap_if_active = get_airpcap_if_from_name(airpcap_if_list, if_dlg_data->if_info.name); airpcap_if_selected = airpcap_if_active; #endif @@ -390,6 +391,17 @@ combo_channel_new(void) return channel_cb; } +/* + * Sorts the Interface List in alphabetical order + */ +int if_list_comparator_alph (const if_info_t *first, const if_info_t *second){ + if(first != NULL && first->description != NULL && second != NULL && second->description != NULL){ + return g_strcasecmp(first->description, second->description); + } else { + return 0; + } +} + /* start getting capture stats from all interfaces */ void capture_if_cb(GtkWidget *w _U_, gpointer d _U_) @@ -444,6 +456,7 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_) /* LOAD THE INTERFACES */ if_list = get_interface_list(&err, &err_str); + if_list = g_list_sort (if_list, if_list_comparator_alph); if (if_list == NULL && err == CANT_GET_INTERFACE_LIST) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); g_free(err_str); @@ -460,7 +473,7 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_) update_decryption_mode_list(decryption_cm); if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); + /* simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); /* XXX - Do we need to show an error here? */ g_free(err_str); } @@ -552,10 +565,11 @@ capture_if_cb(GtkWidget *w _U_, gpointer d _U_) g_string_assign(if_tool_str, ""); if_info = curr->data; if_dlg_data = g_malloc0(sizeof(if_dlg_data_t)); + if_dlg_data->if_info = *if_info; /* Kind of adaptor (icon) */ #ifdef HAVE_AIRPCAP - if(get_airpcap_if_from_description(airpcap_if_list,if_info->description) != NULL) + if(get_airpcap_if_from_name(airpcap_if_list,if_info->name) != NULL) icon = xpm_to_widget(capture_airpcap_16_xpm); else icon = xpm_to_widget(capture_ethernet_16_xpm); diff --git a/gtk/keys.h b/gtk/keys.h index 23dfd554ff..ebc25bb663 100644 --- a/gtk/keys.h +++ b/gtk/keys.h @@ -53,6 +53,8 @@ #define AIRPCAP_TOOLBAR_LINK_TYPE_KEY "airpcap_toolbar_lt_key" #define AIRPCAP_TOOLBAR_CHANNEL_KEY "airpcap_toolbar_ch_key" #define AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY "airpcap_toolbar_ch_lb_key" +#define AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY "airpcap_toolbar_ch_offset_key" +#define AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY "airpcap_toolbar_ch_offset_lb_key" #define AIRPCAP_TOOLBAR_FCS_CHECK_KEY "airpcap_toolbar_fcs_check_key" #define AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY "airpcap_toolbar_fcs_filter_lb_key" #define AIRPCAP_TOOLBAR_FCS_FILTER_KEY "airpcap_toolbar_fcs_filter_key" diff --git a/gtk/main.c b/gtk/main.c index c395ce6f90..ff1bfdec17 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -2184,14 +2184,19 @@ main(int argc, char *argv[]) /* load the airpcap interfaces */ airpcap_if_list = get_airpcap_interface_list(&err, &err_str); - if (airpcap_if_list == NULL && err == CANT_GET_AIRPCAP_INTERFACE_LIST) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err_str); - g_free(err_str); - } - /* select the first ad default (THIS SHOULD BE CHANGED) */ - airpcap_if_active = airpcap_get_default_if(airpcap_if_list); - break; + if (airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0){ + if (err == CANT_GET_AIRPCAP_INTERFACE_LIST && err_str != NULL) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", "Failed to open Airpcap Adapters!"); + g_free(err_str); + } + airpcap_if_active = NULL; + + } else { + /* select the first ad default (THIS SHOULD BE CHANGED) */ + airpcap_if_active = airpcap_get_default_if(airpcap_if_list); + } + break; #if 0 /* * XXX - Maybe we need to warn the user if one of the following happens??? @@ -4106,31 +4111,49 @@ window_state_event_cb (GtkWidget *widget _U_, static void airpcap_toolbar_channel_changed_cb(GtkWidget *w _U_, gpointer data) { - gchar ebuf[AIRPCAP_ERRBUF_SIZE]; - PAirpcapHandle ad; const gchar *s; - int ch_num; - - s = gtk_entry_get_text(GTK_ENTRY(data)); + ULONG ch_freq; - if ((data != NULL) && (w != NULL) ) { - s = gtk_entry_get_text(GTK_ENTRY(data)); + if ((data != NULL) && (w != NULL) && change_airpcap_settings) { + s = gtk_entry_get_text(GTK_ENTRY(w)); if ((g_strcasecmp("",s))) { - sscanf(s,"%d",&ch_num); + ch_freq = airpcap_get_frequency_from_str(s); if (airpcap_if_active != NULL) { - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list, airpcap_if_active->description), ebuf); - - if(ad) { - airpcap_if_set_device_channel(ad,ch_num); - airpcap_if_active->channel = ch_num; - airpcap_if_close(ad); - } + airpcap_if_active->channelInfo.Frequency = ch_freq; + airpcap_update_channel_offset_cb(airpcap_if_active, ch_freq, GTK_WIDGET(data)); } } } } /* + * Changed callback for the channel offset combobox + */ +static void +on_channel_offset_cb_changed(GtkWidget *w _U_, gpointer data) +{ + const gchar *s; + gchar offset; + + if ((data != NULL) && (w != NULL) && change_airpcap_settings) + { + s = gtk_entry_get_text(GTK_ENTRY(w)); + if ((g_strcasecmp("",s))) + { + if (airpcap_if_active != NULL) + { + sscanf(s,"%d",&offset); + airpcap_if_active->channelInfo.ExtChannel = offset; + if (change_airpcap_settings != NULL) + { + airpcap_update_frequency_and_offset(airpcap_if_active); + } + } + } + } +} + +/* * Callback for the wrong crc combo */ static void @@ -4140,15 +4163,13 @@ airpcap_toolbar_wrong_crc_combo_cb(GtkWidget *entry, gpointer user_data) PAirpcapHandle ad; if( !block_toolbar_signals && (airpcap_if_active != NULL)) { - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list,airpcap_if_active->description), ebuf); + ad = airpcap_if_open(airpcap_if_active->name, ebuf); if (ad) { airpcap_if_active->CrcValidationOn = airpcap_get_validation_type(gtk_entry_get_text(GTK_ENTRY(entry))); airpcap_if_set_fcs_validation(ad,airpcap_if_active->CrcValidationOn); /* Save configuration */ - if(!airpcap_if_store_cur_config_as_adapter_default(ad)) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Cannot save configuration!!!\nRemember that in order to store the configuration in the registry you have to:\n\n- Close all the airpcap-based applications.\n- Be sure to have administrative privileges."); - } + airpcap_if_store_cur_config_as_adapter_default(ad); airpcap_if_close(ad); } } @@ -4167,7 +4188,7 @@ airpcap_toolbar_encryption_cb(GtkWidget *entry, gpointer user_data) /* Apply changes to the current adapter */ if( (airpcap_if_active != NULL)) { - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list,airpcap_if_active->description), ebuf); + ad = airpcap_if_open(airpcap_if_active->name, ebuf); if(ad) { if(airpcap_if_active->DecryptionOn == AIRPCAP_DECRYPTION_ON) { @@ -4193,6 +4214,7 @@ airpcap_toolbar_encryption_cb(GtkWidget *entry, gpointer user_data) return; } + if (!(airpcap_if_list == NULL)){ n = g_list_length(airpcap_if_list); /* The same kind of settings should be propagated to all the adapters */ @@ -4201,18 +4223,22 @@ airpcap_toolbar_encryption_cb(GtkWidget *entry, gpointer user_data) curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i); if( (curr_if != NULL) && (curr_if != airpcap_if_selected) ) { - ad = airpcap_if_open(get_airpcap_name_from_description(airpcap_if_list,curr_if->description), ebuf); + ad = airpcap_if_open(curr_if->name, ebuf); if(ad) { curr_if->DecryptionOn = airpcap_if_selected->DecryptionOn; airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn); /* Save configuration for the curr_if */ if(!airpcap_if_store_cur_config_as_adapter_default(ad)) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Cannot save configuration!!!\nRemember that in order to store the configuration in the registry you have to:\n\n- Close all the airpcap-based applications.\n- Be sure to have administrative privileges."); - } + } airpcap_if_close(ad); } } } + } else { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "AirPcap Adapter Error!"); + return; + } } /* @@ -4289,13 +4315,16 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) gchar *title; #ifdef HAVE_AIRPCAP - GtkWidget *advanced_bt, - *key_management_bt, - *interface_lb, - *channel_lb, - *channel_cm, - *wrong_crc_lb, - *wrong_crc_cm; + GtkWidget *key_management_bt = NULL, +#if GTK_MAJOR_VERSION >= 2 /* For some reason this button's action crashes under GTK 1. */ + *advanced_bt = NULL, +#endif + *channel_lb = NULL, + *channel_cm = NULL, + *channel_offset_lb = NULL, + *channel_offset_cb = NULL, + *wrong_crc_lb = NULL, + *wrong_crc_cm = NULL; GtkWidget *enable_decryption_lb; GtkWidget *enable_decryption_cb; @@ -4306,7 +4335,7 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) GList *linktype_list = NULL; GList *link_list = NULL; GtkTooltips *airpcap_tooltips; - gchar *if_label_text; + /* gchar *if_label_text; */ gint *from_widget = NULL; #endif @@ -4421,72 +4450,100 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) gtk_widget_show(airpcap_tb); /* Interface Label */ - if(airpcap_if_active != NULL) { + /*if(airpcap_if_active != NULL) { if_label_text = g_strdup_printf("%s %s\t","Current Wireless Interface: #",airpcap_get_if_string_number(airpcap_if_active)); interface_lb = gtk_label_new(if_label_text); g_free(if_label_text); } else { interface_lb = gtk_label_new("No Wireless Interface Found "); - } + }*/ /* Add the label to the toolbar */ - gtk_toolbar_append_widget(GTK_TOOLBAR(airpcap_tb), interface_lb, + /*gtk_toolbar_append_widget(GTK_TOOLBAR(airpcap_tb), interface_lb, "Current Wireless Interface", "Private"); OBJECT_SET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_INTERFACE_KEY,interface_lb); gtk_widget_show(interface_lb); - gtk_toolbar_insert_space(GTK_TOOLBAR(airpcap_tb),1); + gtk_toolbar_insert_space(GTK_TOOLBAR(airpcap_tb),1);*/ /* Create the "802.11 Channel:" label */ - channel_lb = gtk_label_new(" 802.11 Channel: "); + channel_lb = gtk_label_new("802.11 Channel: "); OBJECT_SET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_LABEL_KEY,channel_lb); gtk_toolbar_append_widget(GTK_TOOLBAR(airpcap_tb), channel_lb, "Current 802.11 Channel", "Private"); gtk_widget_show(channel_lb); - WIDGET_SET_SIZE(channel_lb, 100, 28); + WIDGET_SET_SIZE(channel_lb, 85, 28); /* Create the channel combo box */ channel_cm = gtk_combo_new(); gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(channel_cm)->entry),FALSE); OBJECT_SET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_KEY,channel_cm); - channel_list = g_list_append(channel_list, "1 (2412MHz)"); - channel_list = g_list_append(channel_list, "2 (2417MHz)"); - channel_list = g_list_append(channel_list, "3 (2422MHz)"); - channel_list = g_list_append(channel_list, "4 (2427MHz)"); - channel_list = g_list_append(channel_list, "5 (2432MHz)"); - channel_list = g_list_append(channel_list, "6 (2437MHz)"); - channel_list = g_list_append(channel_list, "7 (2442MHz)"); - channel_list = g_list_append(channel_list, "8 (2447MHz)"); - channel_list = g_list_append(channel_list, "9 (2452MHz)"); - channel_list = g_list_append(channel_list, "10 (2457MHz)"); - channel_list = g_list_append(channel_list, "11 (2462MHz)"); - channel_list = g_list_append(channel_list, "12 (2467MHz)"); - channel_list = g_list_append(channel_list, "13 (2472MHz)"); - channel_list = g_list_append(channel_list, "14 (2484MHz)"); - - gtk_combo_set_popdown_strings( GTK_COMBO(channel_cm), channel_list) ; + if (airpcap_if_active != NULL && airpcap_if_active->pSupportedChannels != NULL && airpcap_if_active->numSupportedChannels > 0){ + guint i = 0; + for (; i<airpcap_if_active->numSupportedChannels; i++){ + channel_list = g_list_append(channel_list, airpcap_get_channelstr_from_freq(airpcap_if_active->pSupportedChannels[i].Frequency)); + } + gtk_combo_set_popdown_strings( GTK_COMBO(channel_cm), channel_list) ; + } gtk_tooltips_set_tip(airpcap_tooltips, GTK_WIDGET(GTK_COMBO(channel_cm)->entry), "Change the 802.11 RF channel", NULL); - WIDGET_SET_SIZE(channel_cm, 100, 28); + WIDGET_SET_SIZE(channel_cm, 120, 28); - if(airpcap_if_active != NULL) - gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cm)->entry), airpcap_get_channel_name(airpcap_if_active->channel)); - else + if(airpcap_if_active != NULL) + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cm)->entry), airpcap_get_channelstr_from_freq(airpcap_if_active->channelInfo.Frequency)); + else gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_cm)->entry),""); - /* callback for channel combo box */ - SIGNAL_CONNECT(GTK_COMBO(channel_cm)->entry,"changed",airpcap_toolbar_channel_changed_cb,GTK_COMBO(channel_cm)->entry); gtk_widget_show(channel_cm); gtk_toolbar_append_widget(GTK_TOOLBAR(airpcap_tb), channel_cm, "802.11 Channel", "Private"); + /* gtk_toolbar_append_space(GTK_TOOLBAR(airpcap_tb)); */ + + /* Create the "Channel Offset:" label */ + channel_offset_lb = gtk_label_new("Channel Offset: "); + OBJECT_SET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_CHANNEL_OFFSET_LABEL_KEY,channel_offset_lb); + gtk_toolbar_append_widget(GTK_TOOLBAR(airpcap_tb), channel_offset_lb, + "Current 802.11 Channel Offset", "Private"); + gtk_widget_show(channel_offset_lb); + + WIDGET_SET_SIZE(channel_offset_lb, 80, 28); + + /* Start: Channel offset combo box */ + channel_offset_cb = gtk_combo_new(); + gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(channel_offset_cb)->entry),FALSE); + OBJECT_SET_DATA(airpcap_tb, AIRPCAP_TOOLBAR_CHANNEL_OFFSET_KEY, channel_offset_cb); + + if(airpcap_if_active != NULL){ + airpcap_update_channel_offset_cb(airpcap_if_active, airpcap_if_active->channelInfo.Frequency, channel_offset_cb); + airpcap_update_channel_offset_combo_entry(channel_offset_cb, airpcap_if_active->channelInfo.ExtChannel); + } else { + gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(channel_offset_cb)->entry),""); + } + + gtk_tooltips_set_tip(airpcap_tooltips, GTK_WIDGET(GTK_COMBO(channel_offset_cb)->entry), + "Change channel offset", NULL); + + WIDGET_SET_SIZE(channel_offset_cb, 50, 28); + + gtk_widget_show(channel_offset_cb); + + gtk_toolbar_append_widget(GTK_TOOLBAR(airpcap_tb), channel_offset_cb, + "802.11 Channel Offset", "Private"); + gtk_toolbar_append_space(GTK_TOOLBAR(airpcap_tb)); + /* callback for channel combo box */ + SIGNAL_CONNECT(GTK_COMBO(channel_cm)->entry,"changed", airpcap_toolbar_channel_changed_cb, channel_offset_cb); + /* callback for channel offset combo box */ + SIGNAL_CONNECT(GTK_COMBO(channel_offset_cb)->entry,"changed", on_channel_offset_cb_changed, channel_offset_cb); + /* End: Channel offset combo box */ + /* Wrong CRC Label */ wrong_crc_lb = gtk_label_new(" FCS Filter: "); OBJECT_SET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_FCS_FILTER_LABEL_KEY,wrong_crc_lb); @@ -4552,6 +4609,7 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) gtk_toolbar_append_space(GTK_TOOLBAR(airpcap_tb)); +#if GTK_MAJOR_VERSION >= 2 /* For some reason this button's action crashes under GTK 1. */ /* Advanced button */ advanced_bt = gtk_button_new_with_label("Wireless Settings..."); OBJECT_SET_DATA(airpcap_tb,AIRPCAP_TOOLBAR_ADVANCED_KEY,advanced_bt); @@ -4559,7 +4617,10 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) SIGNAL_CONNECT(advanced_bt, "clicked", toolbar_display_airpcap_advanced_cb, airpcap_tb); gtk_toolbar_append_widget(GTK_TOOLBAR(airpcap_tb), advanced_bt, "Set Advanced Wireless Settings", "Private"); + + gtk_widget_show(advanced_bt); +#endif /* GTK_MAJOR_VERSION */ /* Key Management button */ key_management_bt = gtk_button_new_with_label("Decryption Keys..."); @@ -4570,21 +4631,18 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) "Manage Decryption Keys", "Private"); gtk_widget_show(key_management_bt); - /* select the default interface */ - airpcap_if_active = airpcap_get_default_if(airpcap_if_list); - /* If no airpcap interface is present, gray everything */ if(airpcap_if_active == NULL) { - if(airpcap_if_list == NULL) { + if(airpcap_if_list == NULL || g_list_length(airpcap_if_list) == 0) { /*No airpcap device found */ airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); /* recent.airpcap_toolbar_show = TRUE; */ - } else { - /* default adapter is not airpcap... or is airpcap but is not found*/ - airpcap_set_toolbar_stop_capture(airpcap_if_active); - airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); - /* recent.airpcap_toolbar_show = TRUE; */ - } + } else { + /* default adapter is not airpcap... or is airpcap but is not found*/ + airpcap_set_toolbar_stop_capture(airpcap_if_active); + airpcap_enable_toolbar_widgets(airpcap_tb,FALSE); + /* recent.airpcap_toolbar_show = TRUE; */ + } } else { airpcap_set_toolbar_stop_capture(airpcap_if_active); /* recent.airpcap_toolbar_show = TRUE; */ @@ -4764,12 +4822,14 @@ show_main_window(gboolean doing_work) * This will read the decryption keys from the preferences file, and will * store them into the registry... */ - if(!airpcap_check_decryption_keys(airpcap_if_list)) { - /* Ask the user what to do ...*/ - airpcap_keys_check_w(NULL,NULL); - } else { - /* Keys from lists are equals, or wireshark has got no keys */ - airpcap_load_decryption_keys(airpcap_if_list); + if(airpcap_if_list != NULL && g_list_length(airpcap_if_list) > 0){ + if (!airpcap_check_decryption_keys(airpcap_if_list)) { + /* Ask the user what to do ...*/ + airpcap_keys_check_w(NULL,NULL); + } else { + /* Keys from lists are equals, or wireshark has got no keys */ + airpcap_load_decryption_keys(airpcap_if_list); + } } switch (airpcap_dll_ret_val) { |