2006-08-16 18:01:25 +00:00
/* airpcap_loader.c
*
2006-08-21 19:22:33 +00:00
* Giorgio Tino < giorgio . tino @ cacetech . com >
* Copyright ( c ) CACE Technologies , LLC 2006
2006-08-16 18:01:25 +00:00
*
* Wireshark - Network traffic analyzer
* By Gerald Combs < gerald @ wireshark . org >
* Copyright 2000 Gerald Combs
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2012-06-28 22:56:06 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA .
2006-08-16 18:01:25 +00:00
*/
2012-09-20 01:29:52 +00:00
# include "config.h"
2006-08-16 18:01:25 +00:00
# include <glib.h>
2006-12-28 17:22:12 +00:00
# include <epan/crypt/airpdcap_ws.h>
2007-01-11 02:42:34 +00:00
# include <epan/strutil.h>
2010-08-25 20:30:59 +00:00
# include <wsutil/file_util.h>
2015-06-11 22:05:44 +00:00
# include <wsutil/frequency-utils.h>
2006-08-16 18:01:25 +00:00
2014-08-01 00:29:36 +00:00
# include <caputils/airpcap.h>
# include <caputils/airpcap_loader.h>
2006-08-16 18:01:25 +00:00
strcasecmp(), strncasecmp(), g_strcasecmp(), and g_strncasecmp() delenda
est. Use g_ascii_strcasecmp() and g_ascii_strncasecmp(), and supply our
own versions if they're missing from GLib (as is the case with GLib
1.x).
In the code to build the list of named fields for Diameter, don't use
g_strdown(); do our own g_ascii_-style upper-case to lower-case mapping
in the hash function and use g_ascii_strcasecmp() in the compare
function.
We do this because there is no guarantee that toupper(), tolower(), and
functions that use them will, for example, map between "I" and "i" in
all locales; in Turkish locales, for example, there are, in both
upper case and lower case, versions of "i" with and without a dot, and
the upper-case version of "i" is "I"-with-a-dot and the lower-case
version of "I" is "i"-without-a-dot. This causes strings that should
match not to match.
This finishes fixing bug 2010 - an earlier checkin prevented the crash
(as there are other ways to produce the same crash, e.g. a bogus
dictionary.xml file), but didn't fix the case-insensitive string matching.
svn path=/trunk/; revision=23623
2007-11-27 18:52:51 +00:00
2006-10-26 21:53:30 +00:00
/*
* Set to TRUE if the DLL was successfully loaded AND all functions
* are present .
*/
static gboolean AirpcapLoaded = FALSE ;
2009-05-13 10:01:17 +00:00
# ifdef _WIN32
/*
* We load dynamically the dag library in order link it only when
* it ' s present on the system
*/
static void * AirpcapLib = NULL ;
2007-05-18 21:06:20 +00:00
2006-08-16 18:01:25 +00:00
static AirpcapGetLastErrorHandler g_PAirpcapGetLastError ;
static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer ;
static AirpcapSetFilterHandler g_PAirpcapSetFilter ;
static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress ;
static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy ;
static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent ;
static AirpcapReadHandler g_PAirpcapRead ;
static AirpcapGetStatsHandler g_PAirpcapGetStats ;
2009-05-13 10:01:17 +00:00
# endif
static int AirpcapVersion = 3 ;
static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList ;
static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList ;
static AirpcapOpenHandler g_PAirpcapOpen ;
static AirpcapCloseHandler g_PAirpcapClose ;
static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType ;
static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType ;
2006-08-16 18:01:25 +00:00
static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn ;
static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff ;
static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel ;
static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel ;
static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence ;
static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence ;
static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation ;
static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation ;
static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys ;
static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys ;
2006-10-30 06:34:31 +00:00
static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys ;
static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys ;
2006-08-16 18:01:25 +00:00
static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState ;
static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState ;
2006-10-30 06:34:31 +00:00
static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState ;
static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState ;
2006-08-16 18:01:25 +00:00
static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault ;
2006-10-19 22:43:38 +00:00
static AirpcapGetVersionHandler g_PAirpcapGetVersion ;
2007-05-18 21:06:20 +00:00
static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx ;
static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx ;
static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels ;
2006-08-16 18:01:25 +00:00
/* Airpcap interface list */
2015-07-02 10:19:02 +00:00
GList * g_airpcap_if_list = NULL ;
2006-08-16 18:01:25 +00:00
/* Airpcap current selected interface */
airpcap_if_info_t * airpcap_if_selected = NULL ;
/* Airpcap current active interface */
airpcap_if_info_t * airpcap_if_active = NULL ;
2007-05-18 21:06:20 +00:00
Dot11Channel * pSupportedChannels ;
2009-11-12 23:48:11 +00:00
guint numSupportedChannels ;
2007-05-18 21:06:20 +00:00
static AirpcapChannelInfo LegacyChannels [ ] =
{
2012-11-25 21:47:04 +00:00
{ 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 } } ,
2007-05-18 21:06:20 +00:00
} ;
2009-11-12 23:48:11 +00:00
static guint num_legacy_channels = 14 ;
2007-05-18 21:06:20 +00:00
2006-08-16 18:01:25 +00:00
/*
* Get an error message string for a CANT_GET_INTERFACE_LIST error from
* " get_airpcap_interface_list() " .
*/
2007-01-21 23:45:36 +00:00
static gchar *
2006-08-16 18:01:25 +00:00
cant_get_airpcap_if_list_error_message ( const char * err_str )
{
2007-01-24 01:17:48 +00:00
return g_strdup_printf ( " Can't get list of Wireless interfaces: %s " , err_str ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to store the current settings for the selected adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_store_cur_config_as_adapter_default ( PAirpcapHandle ah )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapStoreCurConfigAsAdapterDefault ( ah ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to open an airpcap adapter
*/
PAirpcapHandle
2009-05-13 04:57:45 +00:00
airpcap_if_open ( gchar * name , gchar * err )
2006-08-16 18:01:25 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return NULL ;
if ( name = = NULL ) return NULL ;
return g_PAirpcapOpen ( name , err ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to close an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
void
2006-08-16 18:01:25 +00:00
airpcap_if_close ( PAirpcapHandle handle )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return ;
g_PAirpcapClose ( handle ) ;
2006-08-16 18:01:25 +00:00
}
2007-05-18 21:06:20 +00:00
/*
* Retrieve the state of the Airpcap DLL
*/
int
2009-05-13 17:29:13 +00:00
airpcap_get_dll_state ( void )
2007-05-18 21:06:20 +00:00
{
2012-11-25 21:47:04 +00:00
return AirpcapVersion ;
2007-05-18 21:06:20 +00:00
}
2006-08-16 18:01:25 +00:00
/*
* Airpcap wrapper , used to turn on the led of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_turn_led_on ( PAirpcapHandle AdapterHandle , guint LedNumber )
2006-08-16 18:01:25 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapTurnLedOn ( AdapterHandle , LedNumber ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to turn off the led of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_turn_led_off ( PAirpcapHandle AdapterHandle , guint LedNumber )
2006-08-16 18:01:25 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapTurnLedOff ( AdapterHandle , LedNumber ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to get the channel of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_get_device_channel ( PAirpcapHandle ah , guint * ch )
2006-08-16 18:01:25 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapGetDeviceChannel ( ah , ch ) ;
2006-08-16 18:01:25 +00:00
}
2007-05-18 21:06:20 +00:00
/*
* Airpcap wrapper , used to get the supported channels of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2009-11-12 23:48:11 +00:00
airpcap_if_get_device_supported_channels ( PAirpcapHandle ah , AirpcapChannelInfo * * cInfo , guint * nInfo )
2007-05-18 21:06:20 +00:00
{
if ( ! AirpcapLoaded ) return FALSE ;
2012-11-25 21:47:04 +00:00
if ( airpcap_get_dll_state ( ) = = AIRPCAP_DLL_OLD ) {
* nInfo = num_legacy_channels ;
* cInfo = ( AirpcapChannelInfo * ) & LegacyChannels ;
2007-05-18 21:06:20 +00:00
2012-11-25 21:47:04 +00:00
return TRUE ;
} else if ( airpcap_get_dll_state ( ) = = AIRPCAP_DLL_OK ) {
return g_PAirpcapGetDeviceSupportedChannels ( ah , cInfo , nInfo ) ;
2007-05-18 21:06:20 +00:00
}
return FALSE ;
}
/*
* Airpcap wrapper , used to get the supported channels of an airpcap adapter
*/
Dot11Channel *
2009-11-12 23:48:11 +00:00
airpcap_if_get_device_supported_channels_array ( PAirpcapHandle ah , guint * pNumSupportedChannels )
2007-05-18 21:06:20 +00:00
{
2007-08-17 19:34:14 +00:00
AirpcapChannelInfo * chanInfo ;
2009-11-12 23:48:11 +00:00
guint i = 0 , j = 0 , numInfo = 0 ;
2007-05-18 21:06:20 +00:00
2007-08-17 19:34:14 +00:00
if ( ! AirpcapLoaded )
2008-10-15 23:17:40 +00:00
return NULL ;
2007-08-17 19:34:14 +00:00
if ( airpcap_if_get_device_supported_channels ( ah , & chanInfo , & numInfo ) = = FALSE )
return NULL ;
numSupportedChannels = 0 ;
2007-05-18 21:06:20 +00:00
2007-08-17 19:34:14 +00:00
/*
* allocate a bigger array
*/
if ( numInfo = = 0 )
return NULL ;
2007-05-18 21:06:20 +00:00
2013-03-18 22:38:56 +00:00
pSupportedChannels = ( Dot11Channel * ) g_malloc ( numInfo * ( sizeof * pSupportedChannels ) ) ;
2007-05-18 21:06:20 +00:00
2007-08-17 19:34:14 +00:00
for ( i = 0 ; i < numInfo ; i + + )
{
2009-11-12 23:48:11 +00:00
guint supportedChannel = G_MAXUINT ;
2007-08-17 19:34:14 +00:00
/*
* search if we have it already
*/
for ( j = 0 ; j < numSupportedChannels ; j + + )
{
if ( pSupportedChannels [ j ] . Frequency = = chanInfo [ i ] . Frequency )
{
supportedChannel = j ;
break ;
}
}
2009-11-12 23:48:11 +00:00
if ( supportedChannel = = G_MAXUINT )
2007-08-17 19:34:14 +00:00
{
/*
* not found , create a new item
*/
pSupportedChannels [ numSupportedChannels ] . Frequency = chanInfo [ i ] . Frequency ;
switch ( chanInfo [ i ] . ExtChannel )
{
case - 1 :
2009-05-13 16:14:28 +00:00
pSupportedChannels [ numSupportedChannels ] . Flags = FLAG_CAN_BE_LOW ;
2007-08-17 19:34:14 +00:00
break ;
case + 1 :
2009-05-13 16:14:28 +00:00
pSupportedChannels [ numSupportedChannels ] . Flags = FLAG_CAN_BE_HIGH ;
2007-08-17 19:34:14 +00:00
break ;
case 0 :
default :
pSupportedChannels [ numSupportedChannels ] . Flags = 0 ;
}
/*
* Gather channel information
*/
pSupportedChannels [ numSupportedChannels ] . Flags | =
FREQ_IS_BG ( pSupportedChannels [ numSupportedChannels ] . Frequency ) ?
FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL ;
pSupportedChannels [ numSupportedChannels ] . Channel =
ieee80211_mhz_to_chan ( pSupportedChannels [ numSupportedChannels ] . Frequency ) ;
numSupportedChannels + + ;
}
else
{
/*
* just update the ext channel flags
*/
switch ( chanInfo [ i ] . ExtChannel )
{
case - 1 :
2009-05-13 16:14:28 +00:00
pSupportedChannels [ supportedChannel ] . Flags | = FLAG_CAN_BE_LOW ;
2007-08-17 19:34:14 +00:00
break ;
case + 1 :
2009-05-13 16:14:28 +00:00
pSupportedChannels [ supportedChannel ] . Flags | = FLAG_CAN_BE_HIGH ;
2007-08-17 19:34:14 +00:00
break ;
case 0 :
default :
break ;
}
}
}
2007-05-18 21:06:20 +00:00
2007-08-17 19:34:14 +00:00
if ( numSupportedChannels < 1 )
return NULL ;
/*
* 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 ;
}
}
}
2007-05-18 21:06:20 +00:00
2007-08-17 19:34:14 +00:00
* pNumSupportedChannels = numSupportedChannels ;
return pSupportedChannels ;
2007-05-18 21:06:20 +00:00
}
2006-08-16 18:01:25 +00:00
/*
* Airpcap wrapper , used to set the channel of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_set_device_channel ( PAirpcapHandle ah , guint ch )
2006-08-16 18:01:25 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapSetDeviceChannel ( ah , ch ) ;
2006-08-16 18:01:25 +00:00
}
2007-05-18 21:06:20 +00:00
/*
* Airpcap wrapper , used to set the frequency of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2007-05-18 21:06:20 +00:00
airpcap_if_set_device_channel_ex ( PAirpcapHandle ah , AirpcapChannelInfo ChannelInfo )
{
if ( ! AirpcapLoaded ) return FALSE ;
if ( airpcap_get_dll_state ( ) = = AIRPCAP_DLL_OLD ) {
2012-11-25 21:47:04 +00:00
gint channel = 0 ;
channel = ieee80211_mhz_to_chan ( ChannelInfo . Frequency ) ;
2007-05-18 21:06:20 +00:00
2012-11-25 21:47:04 +00:00
if ( channel < 0 ) {
return FALSE ;
} else {
return airpcap_if_set_device_channel ( ah , channel ) ;
}
2007-05-18 21:06:20 +00:00
} else if ( airpcap_get_dll_state ( ) = = AIRPCAP_DLL_OK ) {
2012-11-25 21:47:04 +00:00
return g_PAirpcapSetDeviceChannelEx ( ah , ChannelInfo ) ;
2007-05-18 21:06:20 +00:00
}
return FALSE ;
}
/*
* Airpcap wrapper , used to get the frequency of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2007-05-18 21:06:20 +00:00
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 ) {
2012-11-25 21:47:04 +00:00
guint channel = 0 ;
guint chan_freq = 0 ;
2007-05-18 21:06:20 +00:00
2012-11-25 21:47:04 +00:00
if ( ! airpcap_if_get_device_channel ( ah , & channel ) ) return FALSE ;
2007-05-18 21:06:20 +00:00
2012-11-25 21:47:04 +00:00
chan_freq = ieee80211_chan_to_mhz ( channel , TRUE ) ;
if ( chan_freq = = 0 ) return FALSE ;
pChannelInfo - > Frequency = chan_freq ;
2007-05-18 21:06:20 +00:00
2012-11-25 21:47:04 +00:00
return TRUE ;
2007-05-18 21:06:20 +00:00
} else if ( airpcap_get_dll_state ( ) = = AIRPCAP_DLL_OK ) {
2012-11-25 21:47:04 +00:00
return g_PAirpcapGetDeviceChannelEx ( ah , pChannelInfo ) ;
2007-05-18 21:06:20 +00:00
}
return FALSE ;
}
2006-08-16 18:01:25 +00:00
/*
* Airpcap wrapper , used to get the link type of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_get_link_type ( PAirpcapHandle ah , PAirpcapLinkType lt )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapGetLinkType ( ah , lt ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to set the link type of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_set_link_type ( PAirpcapHandle ah , AirpcapLinkType lt )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapSetLinkType ( ah , lt ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to get the fcs presence of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_get_fcs_presence ( PAirpcapHandle ah , gboolean * fcs )
2006-08-16 18:01:25 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapGetFcsPresence ( ah , fcs ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to set the fcs presence of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_set_fcs_presence ( PAirpcapHandle ah , gboolean fcs )
2006-08-16 18:01:25 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapSetFcsPresence ( ah , fcs ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to get the decryption enabling of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_get_decryption_state ( PAirpcapHandle ah , PAirpcapDecryptionState PEnable )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapGetDecryptionState ( ah , PEnable ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to set the decryption enabling of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_set_decryption_state ( PAirpcapHandle ah , AirpcapDecryptionState Enable )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapSetDecryptionState ( ah , Enable ) ;
2006-08-16 18:01:25 +00:00
}
2006-10-30 06:34:31 +00:00
/*
* Airpcap wrapper , used to get the decryption enabling of an airpcap driver
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-10-30 06:34:31 +00:00
airpcap_if_get_driver_decryption_state ( PAirpcapHandle ah , PAirpcapDecryptionState PEnable )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded | | ( g_PAirpcapGetDriverDecryptionState = = NULL ) ) return FALSE ;
return g_PAirpcapGetDriverDecryptionState ( ah , PEnable ) ;
2006-10-30 06:34:31 +00:00
}
/*
* Airpcap wrapper , used to set the decryption enabling of an airpcap driver
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-10-30 06:34:31 +00:00
airpcap_if_set_driver_decryption_state ( PAirpcapHandle ah , AirpcapDecryptionState Enable )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded | | ( g_PAirpcapSetDriverDecryptionState = = NULL ) ) return FALSE ;
return g_PAirpcapSetDriverDecryptionState ( ah , Enable ) ;
2006-10-30 06:34:31 +00:00
}
2006-08-16 18:01:25 +00:00
/*
* Airpcap wrapper , used to get the fcs validation of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_get_fcs_validation ( PAirpcapHandle ah , PAirpcapValidationType val )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapGetFcsValidation ( ah , val ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to set the fcs validation of an airpcap adapter
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_set_fcs_validation ( PAirpcapHandle ah , AirpcapValidationType val )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapSetFcsValidation ( ah , val ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to save the settings for the selected_if
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_set_device_keys ( PAirpcapHandle AdapterHandle , PAirpcapKeysCollection KeysCollection )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapSetDeviceKeys ( AdapterHandle , KeysCollection ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Airpcap wrapper , used to save the settings for the selected_if
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_get_device_keys ( PAirpcapHandle AdapterHandle , PAirpcapKeysCollection KeysCollection , guint * PKeysCollectionSize )
2006-10-26 21:53:30 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded ) return FALSE ;
return g_PAirpcapGetDeviceKeys ( AdapterHandle , KeysCollection , PKeysCollectionSize ) ;
2006-08-16 18:01:25 +00:00
}
2006-10-30 06:34:31 +00:00
/*
* Airpcap wrapper , used to save the driver ' s set of keys
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-10-30 06:34:31 +00:00
airpcap_if_set_driver_keys ( PAirpcapHandle AdapterHandle , PAirpcapKeysCollection KeysCollection )
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded | | ( g_PAirpcapSetDriverKeys = = NULL ) ) return FALSE ;
return g_PAirpcapSetDriverKeys ( AdapterHandle , KeysCollection ) ;
2006-10-30 06:34:31 +00:00
}
/*
* Airpcap wrapper , used to load the driver ' s set of keys
*/
2009-05-13 04:57:45 +00:00
gboolean
airpcap_if_get_driver_keys ( PAirpcapHandle AdapterHandle , PAirpcapKeysCollection KeysCollection , guint * PKeysCollectionSize )
2006-10-30 06:34:31 +00:00
{
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded | | ( g_PAirpcapGetDriverKeys = = NULL ) ) return FALSE ;
return g_PAirpcapGetDriverKeys ( AdapterHandle , KeysCollection , PKeysCollectionSize ) ;
2006-10-30 06:34:31 +00:00
}
2006-08-16 18:01:25 +00:00
/*
* This function will create a new airpcap_if_info_t using a name and a description
*/
airpcap_if_info_t *
airpcap_if_info_new ( char * name , char * description )
{
2007-01-24 01:17:48 +00:00
PAirpcapHandle ad ;
gchar ebuf [ AIRPCAP_ERRBUF_SIZE ] ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
airpcap_if_info_t * if_info = NULL ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
/* Probably I have to switch on the leds!!! */
ad = airpcap_if_open ( name , ebuf ) ;
2012-11-25 21:47:04 +00:00
if ( ad )
2007-01-24 01:17:48 +00:00
{
2013-03-18 22:38:56 +00:00
if_info = ( airpcap_if_info_t * ) g_malloc0 ( sizeof ( airpcap_if_info_t ) ) ;
2012-11-25 21:47:04 +00:00
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 ) ;
}
2007-01-24 01:17:48 +00:00
}
return if_info ;
2006-08-16 18:01:25 +00:00
}
2006-10-30 06:34:31 +00:00
/*
* This function will create a new fake drivers ' interface , to load global keys . . .
*/
airpcap_if_info_t *
2009-05-13 17:29:13 +00:00
airpcap_driver_fake_if_info_new ( void )
2006-10-30 06:34:31 +00:00
{
2007-01-24 01:17:48 +00:00
PAirpcapHandle ad ;
gchar ebuf [ AIRPCAP_ERRBUF_SIZE ] ;
2006-10-30 06:34:31 +00:00
2007-01-24 01:17:48 +00:00
airpcap_if_info_t * if_info = NULL ;
airpcap_if_info_t * fake_if_info = NULL ;
2006-10-30 06:34:31 +00:00
2007-01-24 01:17:48 +00:00
/* Maybe for some reason no airpcap adapter is found */
2015-07-02 10:19:02 +00:00
if ( g_airpcap_if_list = = NULL )
2012-11-25 21:47:04 +00:00
return NULL ;
2006-12-05 19:24:25 +00:00
2007-01-24 01:17:48 +00:00
/*
* Retrieve the first AirPcap adapter available . If no interface is found ,
* it is not possible to retrieve the driver ' s settings , so return NULL .
*/
2015-07-02 10:19:02 +00:00
if_info = ( airpcap_if_info_t * ) g_list_nth_data ( g_airpcap_if_list , 0 ) ;
2012-11-25 21:47:04 +00:00
if ( if_info = = NULL )
return NULL ;
2006-10-30 06:34:31 +00:00
2007-01-24 01:17:48 +00:00
/* Open the 'fake' adapter */
ad = airpcap_if_open ( if_info - > name , ebuf ) ;
2012-11-25 21:47:04 +00:00
if ( ad )
2007-01-24 01:17:48 +00:00
{
2013-03-18 22:38:56 +00:00
fake_if_info = ( airpcap_if_info_t * ) g_malloc ( sizeof ( airpcap_if_info_t ) ) ;
2012-11-25 21:47:04 +00:00
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 ) ;
}
2007-01-24 01:17:48 +00:00
}
2006-10-30 06:34:31 +00:00
2007-01-24 01:17:48 +00:00
return fake_if_info ;
2006-10-30 06:34:31 +00:00
}
2015-06-11 22:05:44 +00:00
# ifdef AIRPCAP_DEBUG
2006-10-30 06:34:31 +00:00
/*
* USED FOR DEBUG ONLY . . . PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way .
*/
void
airpcap_if_info_print ( airpcap_if_info_t * if_info )
{
2007-05-18 21:06:20 +00:00
guint i ;
2012-11-25 21:47:04 +00:00
if ( if_info = = NULL )
2007-01-24 01:17:48 +00:00
{
2012-11-25 21:47:04 +00:00
g_print ( " \n WARNING : AirPcap Interface pointer is NULL! \n " ) ;
return ;
2007-01-24 01:17:48 +00:00
}
2006-10-30 06:34:31 +00:00
2007-01-11 02:42:34 +00:00
g_print ( " \n ----------------- AirPcap Interface \n " ) ;
2007-05-18 21:06:20 +00:00
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 ) ;
2009-05-13 10:01:17 +00:00
g_print ( " SUPPORTED CHANNELS POINTER: %p \n " , if_info - > pSupportedChannels ) ;
g_print ( " NUM SUPPORTED CHANNELS: %u \n " , if_info - > numSupportedChannels ) ;
2007-05-18 21:06:20 +00:00
for ( i = 0 ; i < ( if_info - > numSupportedChannels ) ; i + + ) {
2012-11-25 21:47:04 +00:00
g_print ( " \n SUPPORTED CHANNEL #%u \n " , i + 1 ) ;
g_print ( " CHANNEL: %u \n " , if_info - > pSupportedChannels [ i ] . Channel ) ;
g_print ( " FREQUENCY: %u \n " , if_info - > pSupportedChannels [ i ] . Frequency ) ;
g_print ( " FLAGS: %u \n " , if_info - > pSupportedChannels [ i ] . Flags ) ;
2007-05-18 21:06:20 +00:00
}
2007-01-11 02:42:34 +00:00
g_print ( " \n \n " ) ;
2006-10-30 06:34:31 +00:00
}
2015-06-11 22:05:44 +00:00
# endif /* AIRPCAP_DEBUG */
2006-10-30 06:34:31 +00:00
2006-08-16 18:01:25 +00:00
/*
* Function used to load the WEP keys for a selected interface
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-08-16 18:01:25 +00:00
airpcap_if_load_keys ( PAirpcapHandle ad , airpcap_if_info_t * if_info )
{
2012-11-25 21:47:04 +00:00
if ( ! if_info ) return FALSE ;
2006-08-16 18:01:25 +00:00
2007-01-11 02:42:34 +00:00
if_info - > keysCollectionSize = 0 ;
if_info - > keysCollection = NULL ;
2006-08-16 18:01:25 +00:00
2012-11-25 21:47:04 +00:00
if ( ! airpcap_if_get_device_keys ( ad , NULL , & ( if_info - > keysCollectionSize ) ) )
2007-01-24 01:17:48 +00:00
{
2012-11-25 21:47:04 +00:00
if ( if_info - > keysCollectionSize = = 0 )
{
if_info - > keysCollection = NULL ;
airpcap_if_close ( ad ) ;
return FALSE ;
}
if_info - > keysCollection = ( PAirpcapKeysCollection ) g_malloc ( if_info - > keysCollectionSize ) ;
if ( ! if_info - > keysCollection )
{
if_info - > keysCollectionSize = 0 ;
if_info - > keysCollection = NULL ;
airpcap_if_close ( ad ) ;
return FALSE ;
}
airpcap_if_get_device_keys ( ad , if_info - > keysCollection , & ( if_info - > keysCollectionSize ) ) ;
return TRUE ;
2007-01-24 01:17:48 +00:00
}
2006-10-30 06:34:31 +00:00
2007-01-11 02:42:34 +00:00
airpcap_if_close ( ad ) ;
return FALSE ;
2006-10-30 06:34:31 +00:00
}
/*
* Function used to load the WEP keys for a selected interface
*/
2009-05-13 04:57:45 +00:00
gboolean
2006-10-30 06:34:31 +00:00
airpcap_if_load_driver_keys ( PAirpcapHandle ad , airpcap_if_info_t * if_info )
{
2007-01-11 02:42:34 +00:00
if_info - > keysCollectionSize = 0 ;
if_info - > keysCollection = NULL ;
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
if ( ! airpcap_if_get_driver_keys ( ad , NULL , & ( if_info - > keysCollectionSize ) ) )
2007-01-24 01:17:48 +00:00
{
2012-11-25 21:47:04 +00:00
if ( if_info - > keysCollectionSize = = 0 )
{
if_info - > keysCollection = NULL ;
airpcap_if_close ( ad ) ;
return FALSE ;
}
if_info - > keysCollection = ( PAirpcapKeysCollection ) g_malloc ( if_info - > keysCollectionSize ) ;
if ( ! if_info - > keysCollection )
{
if_info - > keysCollectionSize = 0 ;
if_info - > keysCollection = NULL ;
airpcap_if_close ( ad ) ;
return FALSE ;
}
airpcap_if_get_driver_keys ( ad , if_info - > keysCollection , & ( if_info - > keysCollectionSize ) ) ;
return TRUE ;
2007-01-24 01:17:48 +00:00
}
2006-10-30 06:34:31 +00:00
2007-01-11 02:42:34 +00:00
airpcap_if_close ( ad ) ;
return FALSE ;
2006-08-16 18:01:25 +00:00
}
/*
* Function used to save the WEP keys for a selected interface
*/
void
airpcap_if_save_keys ( PAirpcapHandle ad , airpcap_if_info_t * if_info )
{
2012-11-25 21:47:04 +00:00
if ( ! if_info | | ! AirpcapLoaded ) return ;
2006-10-26 21:53:30 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info - > keysCollection ! = NULL )
g_PAirpcapSetDeviceKeys ( ad , if_info - > keysCollection ) ;
2006-08-16 18:01:25 +00:00
}
2006-10-30 06:34:31 +00:00
/*
* Function used to save the WEP keys for a selected interface
*/
void
airpcap_if_save_driver_keys ( PAirpcapHandle ad , airpcap_if_info_t * if_info )
{
2012-11-25 21:47:04 +00:00
if ( if_info - > keysCollection ! = NULL )
airpcap_if_set_driver_keys ( ad , if_info - > keysCollection ) ;
2006-10-30 06:34:31 +00:00
}
2006-08-16 18:01:25 +00:00
/*
* Callback used to free an instance of airpcap_if_info_t
*/
static void
free_airpcap_if_cb ( gpointer data , gpointer user_data _U_ )
{
2013-03-18 22:38:56 +00:00
airpcap_if_info_t * if_info = ( airpcap_if_info_t * ) data ;
2006-08-16 18:01:25 +00:00
2012-04-18 18:17:40 +00:00
if ( NULL = = if_info )
2012-11-25 21:47:04 +00:00
return ;
2012-04-18 18:17:40 +00:00
2007-01-24 01:17:48 +00:00
if ( if_info - > name ! = NULL )
2012-11-25 21:47:04 +00:00
g_free ( if_info - > name ) ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
if ( if_info - > description ! = NULL )
2012-11-25 21:47:04 +00:00
g_free ( if_info - > description ) ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
/* XXX - FREE THE WEP KEY LIST HERE!!!*/
2012-11-25 21:47:04 +00:00
if ( if_info - > keysCollection ! = NULL )
2007-01-24 01:17:48 +00:00
{
2012-11-25 21:47:04 +00:00
g_free ( if_info - > keysCollection ) ;
if_info - > keysCollection = NULL ;
2007-01-24 01:17:48 +00:00
}
2006-08-16 18:01:25 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info - > ip_addr ! = NULL )
g_slist_free ( if_info - > ip_addr ) ;
2006-08-16 18:01:25 +00:00
2012-04-18 18:17:40 +00:00
g_free ( if_info ) ;
2006-08-16 18:01:25 +00:00
}
/*
* Function used to free the airpcap interface list
*/
void
free_airpcap_interface_list ( GList * if_list )
{
2007-01-24 01:17:48 +00:00
g_list_foreach ( if_list , free_airpcap_if_cb , NULL ) ;
g_list_free ( if_list ) ;
2006-08-16 18:01:25 +00:00
}
/*
* This function will use the airpcap . dll to find all the airpcap devices .
* Will return null if no device is found .
*/
GList *
2007-01-21 23:45:36 +00:00
get_airpcap_interface_list ( int * err , char * * err_str )
2006-08-16 18:01:25 +00:00
{
2007-01-11 02:42:34 +00:00
GList * il = NULL ;
airpcap_if_info_t * if_info ;
2009-11-12 23:48:11 +00:00
int n_adapts ;
2006-10-30 06:34:31 +00:00
AirpcapDeviceDescription * devsList , * adListEntry ;
2012-03-27 15:17:42 +00:00
char errbuf [ AIRPCAP_ERRBUF_SIZE ] ;
2006-10-26 21:53:30 +00:00
2009-11-12 23:48:11 +00:00
* err = 0 ;
2007-01-24 01:17:48 +00:00
if ( ! AirpcapLoaded )
2007-04-11 04:57:43 +00:00
{
2012-11-25 21:47:04 +00:00
* err = AIRPCAP_NOT_LOADED ;
return il ;
2007-04-11 04:57:43 +00:00
}
2007-01-24 01:17:48 +00:00
if ( ! g_PAirpcapGetDeviceList ( & devsList , errbuf ) )
2007-01-11 02:42:34 +00:00
{
2012-11-25 21:47:04 +00:00
/* 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 ;
2007-01-11 02:42:34 +00:00
}
2006-08-16 18:01:25 +00:00
2007-01-11 02:42:34 +00:00
/*
* Count the adapters
*/
adListEntry = devsList ;
n_adapts = 0 ;
while ( adListEntry )
{
2012-11-25 21:47:04 +00:00
n_adapts + + ;
adListEntry = adListEntry - > next ;
2007-01-11 02:42:34 +00:00
}
2006-08-16 18:01:25 +00:00
2012-11-25 21:47:04 +00:00
if ( n_adapts = = 0 )
2007-01-11 02:42:34 +00:00
{
2012-11-25 21:47:04 +00:00
/* No interfaces, return il= NULL */
g_PAirpcapFreeDeviceList ( devsList ) ;
* err = NO_AIRPCAP_INTERFACES_FOUND ;
if ( err_str ! = NULL )
* err_str = NULL ;
return il ;
2007-01-11 02:42:34 +00:00
}
2006-08-16 18:01:25 +00:00
2007-01-11 02:42:34 +00:00
/*
* Insert the adapters in our list
*/
adListEntry = devsList ;
2009-11-12 23:48:11 +00:00
while ( adListEntry )
2007-01-11 02:42:34 +00:00
{
2012-11-25 21:47:04 +00:00
if_info = airpcap_if_info_new ( adListEntry - > Name , adListEntry - > Description ) ;
if ( if_info ! = NULL ) {
il = g_list_append ( il , if_info ) ;
}
2006-08-16 18:01:25 +00:00
2012-11-25 21:47:04 +00:00
adListEntry = adListEntry - > next ;
2007-01-11 02:42:34 +00:00
}
2006-08-16 18:01:25 +00:00
2007-01-11 02:42:34 +00:00
g_PAirpcapFreeDeviceList ( devsList ) ;
2006-08-16 18:01:25 +00:00
2007-01-11 02:42:34 +00:00
return il ;
2006-08-16 18:01:25 +00:00
}
/*
* Used to retrieve the interface given the name
* ( the name is used in AirpcapOpen )
*/
2007-05-18 21:06:20 +00:00
airpcap_if_info_t * get_airpcap_if_from_name ( GList * if_list , const gchar * name )
2006-08-16 18:01:25 +00:00
{
2012-11-25 21:47:04 +00:00
GList * curr ;
airpcap_if_info_t * if_info ;
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
for ( curr = g_list_first ( if_list ) ; curr ; curr = g_list_next ( curr ) ) {
if_info = ( airpcap_if_info_t * ) curr - > data ;
if ( if_info & & ( g_ascii_strcasecmp ( if_info - > name , name ) = = 0 ) ) {
return ( if_info ) ;
}
2015-06-11 22:05:44 +00:00
/* Try the name without the "\\.\" prefix. */
if ( strlen ( if_info - > name ) > 4 & & ( g_ascii_strcasecmp ( if_info - > name + 4 , name ) = = 0 ) ) {
return ( if_info ) ;
}
2012-11-25 21:47:04 +00:00
}
return ( NULL ) ;
2006-08-16 18:01:25 +00:00
}
/*
2015-06-11 22:05:44 +00:00
* Clear keys and decryption status for the specified interface
2006-08-16 18:01:25 +00:00
*/
2015-06-11 22:05:44 +00:00
void
airpcap_if_clear_decryption_settings ( airpcap_if_info_t * info_if )
2006-08-16 18:01:25 +00:00
{
2015-06-11 22:05:44 +00:00
if ( info_if ! = NULL )
2007-01-24 01:17:48 +00:00
{
2015-06-11 22:05:44 +00:00
if ( info_if - > keysCollection ! = NULL )
2012-11-25 21:47:04 +00:00
{
2015-06-11 22:05:44 +00:00
g_free ( info_if - > keysCollection ) ;
info_if - > keysCollection = NULL ;
2012-11-25 21:47:04 +00:00
}
2006-10-02 23:44:10 +00:00
2012-11-25 21:47:04 +00:00
info_if - > keysCollectionSize = 0 ;
2006-10-30 06:34:31 +00:00
2013-03-18 22:38:56 +00:00
info_if - > DecryptionOn = AIRPCAP_DECRYPTION_OFF ;
2012-11-25 21:47:04 +00:00
info_if - > saved = FALSE ;
2007-01-11 02:42:34 +00:00
}
2006-08-16 18:01:25 +00:00
}
/*
* Used to retrieve the two chars string from interface
*/
gchar *
airpcap_get_if_string_number ( airpcap_if_info_t * if_info )
{
2007-01-24 01:17:48 +00:00
gchar * number ;
guint n ;
int a ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
a = sscanf ( if_info - > name , AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING , & n ) ;
2006-10-26 21:53:30 +00:00
2006-10-02 23:44:10 +00:00
/* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
* Otherwise , check if it is the " Any " adapter . . .
*/
2012-11-25 21:47:04 +00:00
if ( a = = 0 )
2007-01-24 01:17:48 +00:00
{
2012-11-25 21:47:04 +00:00
if ( g_ascii_strcasecmp ( if_info - > name , AIRPCAP_DEVICE_ANY_EXTRACT_STRING ) ! = 0 )
2016-06-06 02:24:47 +00:00
number = g_strdup ( " ?? " ) ;
2012-11-25 21:47:04 +00:00
else
2016-06-06 02:24:47 +00:00
number = g_strdup ( AIRPCAP_CHANNEL_ANY_NAME ) ;
2007-01-24 01:17:48 +00:00
}
else
{
2012-11-25 21:47:04 +00:00
number = g_strdup_printf ( " %.2u " , n ) ;
2007-01-24 01:17:48 +00:00
}
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
return number ;
2006-08-16 18:01:25 +00:00
}
/*
* Used to retrieve the two chars string from interface
*/
gchar *
airpcap_get_if_string_number_from_description ( gchar * description )
{
2007-01-24 01:17:48 +00:00
gchar * number ;
gchar * pointer ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
number = ( gchar * ) g_malloc ( sizeof ( gchar ) * 3 ) ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
pointer = g_strrstr ( description , " # \0 " ) ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
number [ 0 ] = * ( pointer + 1 ) ;
number [ 1 ] = * ( pointer + 2 ) ;
number [ 2 ] = ' \0 ' ;
2006-08-16 18:01:25 +00:00
2007-01-24 01:17:48 +00:00
return number ;
2006-08-16 18:01:25 +00:00
}
/*
* Load the configuration for the specified interface
*/
void
airpcap_load_selected_if_configuration ( airpcap_if_info_t * if_info )
{
2007-01-11 02:42:34 +00:00
gchar ebuf [ AIRPCAP_ERRBUF_SIZE ] ;
PAirpcapHandle ad ;
2006-08-16 18:01:25 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info ! = NULL )
2007-01-24 01:17:48 +00:00
{
2012-11-25 21:47:04 +00:00
ad = airpcap_if_open ( if_info - > name , ebuf ) ;
2006-08-16 18:01:25 +00:00
2012-11-25 21:47:04 +00:00
if ( ad )
{
/* Stop blinking (if it was blinking!)*/
if ( if_info - > blinking )
{
/* Turn on the light (if it was off) */
if ( ! ( if_info - > led ) ) airpcap_if_turn_led_on ( ad , 0 ) ;
}
2007-01-24 01:17:48 +00:00
2012-11-25 21:47:04 +00:00
/* Apply settings... */
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 ) ) ;
airpcap_if_get_decryption_state ( ad , & ( if_info - > DecryptionOn ) ) ;
/* get the keys, if everything is ok, close the adapter */
if ( airpcap_if_load_keys ( ad , if_info ) )
airpcap_if_close ( ad ) ;
if_info - > saved = TRUE ;
}
2015-06-11 22:05:44 +00:00
#if 0
2012-11-25 21:47:04 +00:00
else
{
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " Error in opening adapter for %s " , if_info - > description ) ;
}
2015-06-11 22:05:44 +00:00
# endif
2007-01-24 01:17:48 +00:00
}
2006-08-16 18:01:25 +00:00
}
/*
* Save the configuration for the specified interface
*/
void
airpcap_save_selected_if_configuration ( airpcap_if_info_t * if_info )
{
2007-01-11 02:42:34 +00:00
gchar ebuf [ AIRPCAP_ERRBUF_SIZE ] ;
PAirpcapHandle ad ;
2006-08-16 18:01:25 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info ! = NULL )
2007-01-11 02:42:34 +00:00
{
2012-11-25 21:47:04 +00:00
ad = airpcap_if_open ( if_info - > name , ebuf ) ;
if ( ad )
{
/* Stop blinking (if it was blinking!)*/
if ( if_info - > blinking )
{
/* Turn on the light (if it was off) */
if ( ! ( if_info - > led ) ) airpcap_if_turn_led_on ( ad , 0 ) ;
}
/* Apply settings... */
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 ) ;
airpcap_if_set_decryption_state ( ad , if_info - > DecryptionOn ) ;
airpcap_if_save_keys ( ad , if_info ) ;
/* ... and save them */
if ( ! airpcap_if_store_cur_config_as_adapter_default ( ad ) )
{
2015-06-11 22:05:44 +00:00
#if 0
2012-11-25 21:47:04 +00:00
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " Cannot save Wireless configuration!!! \n Remember 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. " ) ;
2015-06-11 22:05:44 +00:00
# endif
2012-11-25 21:47:04 +00:00
if_info - > saved = FALSE ;
airpcap_if_close ( ad ) ;
return ;
}
if_info - > saved = TRUE ;
airpcap_if_close ( ad ) ;
}
2015-06-11 22:05:44 +00:00
#if 0
2012-11-25 21:47:04 +00:00
else
{
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " Error in opening adapter for %s " , if_info - > description ) ;
}
2015-06-11 22:05:44 +00:00
# endif
2007-01-11 02:42:34 +00:00
}
2006-10-30 06:34:31 +00:00
}
/*
* Save the configuration for the specified interface
*/
void
airpcap_save_driver_if_configuration ( airpcap_if_info_t * fake_if_info )
{
2007-01-11 02:42:34 +00:00
gchar ebuf [ AIRPCAP_ERRBUF_SIZE ] ;
PAirpcapHandle ad ;
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
if ( fake_if_info ! = NULL )
2007-01-11 02:42:34 +00:00
{
2012-11-25 21:47:04 +00:00
ad = airpcap_if_open ( fake_if_info - > name , ebuf ) ;
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
if ( ad )
{
/* Apply decryption settings... */
airpcap_if_set_driver_decryption_state ( ad , fake_if_info - > DecryptionOn ) ;
airpcap_if_save_driver_keys ( ad , fake_if_info ) ;
airpcap_if_close ( ad ) ;
}
2015-06-11 22:05:44 +00:00
#if 0
2012-11-25 21:47:04 +00:00
else
{
simple_dialog ( ESD_TYPE_ERROR , ESD_BTN_OK , " Error in opening adapter for %s " , fake_if_info - > description ) ;
}
2015-06-11 22:05:44 +00:00
# endif
2007-01-11 02:42:34 +00:00
}
2006-10-30 06:34:31 +00:00
2007-01-11 02:42:34 +00:00
return ;
2006-08-16 18:01:25 +00:00
}
2006-10-30 06:34:31 +00:00
/*
* Free an instance of airpcap_if_info_t
*/
void
airpcap_if_info_free ( airpcap_if_info_t * if_info )
{
2012-11-25 21:47:04 +00:00
if ( if_info ! = NULL )
2007-01-11 02:42:34 +00:00
{
2012-11-25 21:47:04 +00:00
if ( if_info - > name ! = NULL )
g_free ( if_info - > name ) ;
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info - > description ! = NULL )
g_free ( if_info - > description ) ;
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info - > keysCollection ! = NULL )
{
g_free ( if_info - > keysCollection ) ;
if_info - > keysCollection = NULL ;
}
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info - > ip_addr ! = NULL )
{
g_slist_free ( if_info - > ip_addr ) ;
if_info - > ip_addr = NULL ;
}
2006-10-30 06:34:31 +00:00
2012-11-25 21:47:04 +00:00
if ( if_info ! = NULL )
{
g_free ( if_info ) ;
}
2007-01-11 02:42:34 +00:00
}
2006-10-19 00:48:03 +00:00
}
2006-10-26 21:53:30 +00:00
/* DYNAMIC LIBRARY LOADER */
2006-08-16 18:01:25 +00:00
/*
2006-10-26 21:53:30 +00:00
* Used to dynamically load the airpcap library in order link it only when
2006-08-16 18:01:25 +00:00
* it ' s present on the system
*/
2006-10-30 06:34:31 +00:00
int load_airpcap ( void )
2006-08-16 18:01:25 +00:00
{
2009-05-13 10:01:17 +00:00
# ifdef _WIN32
2012-11-25 21:47:04 +00:00
gboolean base_functions = TRUE ;
2009-05-13 04:57:45 +00:00
gboolean eleven_n_functions = TRUE ;
2007-01-24 01:17:48 +00:00
2012-11-25 21:47:04 +00:00
if ( ( AirpcapLib = ws_load_library ( " airpcap.dll " ) ) = = NULL )
2007-01-24 01:17:48 +00:00
{
2012-11-25 21:47:04 +00:00
/* Report the error but go on */
AirpcapVersion = AIRPCAP_DLL_NOT_FOUND ;
return AirpcapVersion ;
2007-01-24 01:17:48 +00:00
}
else
{
2012-11-25 21:47:04 +00:00
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 ;
}
2007-01-24 01:17:48 +00:00
}
2007-05-18 21:06:20 +00:00
return AirpcapVersion ;
2009-05-11 18:46:19 +00:00
# else /* _WIN32 */
return AIRPCAP_DLL_NOT_FOUND ;
# endif /* _WIN32 */
2006-08-16 18:01:25 +00:00
}
2006-10-19 22:43:38 +00:00
/*
* Append the version of AirPcap with which we were compiled to a GString .
*/
void
get_compiled_airpcap_version ( GString * str )
{
2007-01-24 01:17:48 +00:00
g_string_append ( str , " with AirPcap " ) ;
2006-10-19 22:43:38 +00:00
}
/*
* Append the version of AirPcap with which we we ' re running to a GString .
*/
void
get_runtime_airpcap_version ( GString * str )
{
2007-01-24 01:17:48 +00:00
guint vmaj , vmin , vrev , build ;
2006-10-19 22:43:38 +00:00
2007-01-24 01:17:48 +00:00
/* See if the DLL has been loaded successfully. Bail if it hasn't */
if ( AirpcapLoaded = = FALSE ) {
2012-11-25 21:47:04 +00:00
g_string_append ( str , " without AirPcap " ) ;
return ;
2007-01-24 01:17:48 +00:00
}
2006-10-19 22:43:38 +00:00
2007-01-24 01:17:48 +00:00
g_PAirpcapGetVersion ( & vmaj , & vmin , & vrev , & build ) ;
2008-05-07 05:26:40 +00:00
g_string_append_printf ( str , " with AirPcap %d.%d.%d build %d " , vmaj , vmin ,
2012-11-25 21:47:04 +00:00
vrev , build ) ;
2006-10-19 22:43:38 +00:00
}
2013-04-07 15:57:36 +00:00
/*
* Editor modelines - http : //www.wireshark.org/tools/modelines.html
*
* Local variables :
* c - basic - offset : 4
* tab - width : 8
* indent - tabs - mode : nil
* End :
*
* vi : set shiftwidth = 4 tabstop = 8 expandtab :
* : indentSize = 4 : tabSize = 8 : noTabs = true :
*/