5 * Giorgio Tino <giorgio.tino@cacetech.com>
6 * Copyright (c) CACE Technologies, LLC 2006
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 2000 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
43 #include <epan/packet.h>
44 #include <epan/prefs.h>
45 #include <epan/prefs-int.h>
46 #include <epan/crypt/wep-wpadefs.h>
47 #include <epan/crypt/airpdcap_ws.h>
48 #include <epan/strutil.h>
49 #include "capture_ui_utils.h"
51 #include "simple_dialog.h"
54 #include "airpcap_loader.h"
57 * We load dynamically the dag library in order link it only when
58 * it's present on the system
60 static HMODULE AirpcapLib = NULL;
63 * Set to TRUE if the DLL was successfully loaded AND all functions
66 static gboolean AirpcapLoaded = FALSE;
68 static int AirpcapVersion = 3;
70 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
71 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
72 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
73 static AirpcapOpenHandler g_PAirpcapOpen;
74 static AirpcapCloseHandler g_PAirpcapClose;
75 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
76 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
77 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
78 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
79 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
80 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
81 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
82 static AirpcapReadHandler g_PAirpcapRead;
83 static AirpcapGetStatsHandler g_PAirpcapGetStats;
84 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
85 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
86 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
87 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
88 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
89 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
90 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
91 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
92 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
93 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
94 static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys;
95 static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys;
96 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
97 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
98 static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState;
99 static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState;
100 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
101 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
102 static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx;
103 static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx;
104 static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels;
106 /* Airpcap interface list */
107 GList *airpcap_if_list = NULL;
109 /* Airpcap current selected interface */
110 airpcap_if_info_t *airpcap_if_selected = NULL;
112 /* Airpcap current active interface */
113 airpcap_if_info_t *airpcap_if_active = NULL;
115 /* WLAN preferences pointer */
116 module_t *wlan_prefs = NULL;
118 Dot11Channel *pSupportedChannels;
119 ULONG numSupportedChannels;
121 static Dot11Channel Dot11aChannels[] =
141 static Dot11Channel Dot11bChannels[] =
159 static AirpcapChannelInfo LegacyChannels[] =
177 static ULONG num_legacy_channels = 14;
180 * Callback used by the load_wlan_keys() routine in order to read a WEP decryption key
183 get_wep_key(pref_t *pref, gpointer ud _U_)
185 gchar *my_string = NULL;
186 keys_cb_data_t* user_data;
188 decryption_key_t* new_key;
190 /* Retrieve user data info */
191 user_data = (keys_cb_data_t*)ud;
193 if (g_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
195 my_string = g_strdup(*pref->varp.string);
197 /* Here we have the string describing the key... */
198 new_key = parse_key_string(my_string);
202 /* Key is added only if not null ... */
203 user_data->list = g_list_append(user_data->list,new_key);
204 user_data->number_of_keys++;
205 user_data->current_index++;
211 /* Returs TRUE if the WEP key is valid, false otherwise */
213 wep_key_is_valid(char* key)
215 GString *new_key_string;
221 new_key_string = g_string_new(key);
223 if( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
225 g_string_free(new_key_string,FALSE);
228 if((new_key_string->len % 2) != 0)
230 g_string_free(new_key_string,FALSE);
233 for(i = 0; i < new_key_string->len; i++)
235 if(!g_ascii_isxdigit(new_key_string->str[i]))
237 g_string_free(new_key_string,FALSE);
242 g_string_free(new_key_string,FALSE);
246 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
248 set_wep_key(pref_t *pref, gpointer ud _U_)
250 gchar *my_string = NULL;
251 keys_cb_data_t* user_data;
252 gint wep_key_number = 0;
254 decryption_key_t* new_key;
256 /* Retrieve user data info */
257 user_data = (keys_cb_data_t*)ud;
259 if (g_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
261 /* Ok, the pref we're gonna set is a wep_key ... but what number? */
262 sscanf(pref->name,"wep_key%d",&wep_key_number);
264 if(user_data->current_index < user_data->number_of_keys)
266 if(wep_key_number == (user_data->current_index+1))
268 /* Retrieve the nth decryption_key_t structure pointer */
269 new_key = (decryption_key_t*)g_list_nth_data(user_data->list,user_data->current_index);
271 /* Free the old key string */
272 g_free((void *)*pref->varp.string);
274 /* Create the new string describing the decryption key */
275 my_string = get_key_string(new_key);
277 /* Duplicate the string, and assign it to the variable pointer */
278 *pref->varp.string = (void *)g_strdup(my_string);
280 /* Free the previously allocated string */
284 else /* If the number of keys has been reduced somehow, we need to delete all the other keys
285 * (remember that the new ones have been probably overwritten)
288 g_free((void *)*pref->varp.string);
289 *pref->varp.string = (void *)g_strdup(""); /* Do not just free memory!!! Put an 'empty' string! */
291 user_data->current_index++;
298 * Function used to read the Decryption Keys from the preferences and store them
299 * properly into the airpcap adapter.
302 load_wlan_driver_wep_keys()
304 keys_cb_data_t* user_data;
308 /* Retrieve the wlan preferences */
309 wlan_prefs = prefs_find_module("wlan");
311 /* Allocate a structure used to keep infos between the callbacks */
312 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
314 /* Fill the structure */
315 user_data->list = NULL;
316 user_data->current_index = 0;
317 user_data->number_of_keys= 0; /* Still unknown */
319 /* Run the callback on each 802.11 preference */
320 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
322 /* Now the key list should be filled */
325 * Signal that we've changed things, and run the 802.11 dissector's
328 wlan_prefs->prefs_changed = TRUE;
330 prefs_apply(wlan_prefs);
332 write_wlan_driver_wep_keys_to_registry(user_data->list);
335 /* free the WEP key string */
336 for(i=0;i<g_list_length(user_data->list);i++)
338 g_free(g_list_nth(user_data->list,i)->data);
341 /* free the (empty) list */
342 g_list_free(user_data->list);
344 /* free the user_data structure */
347 /* airpcap_if_info_free(fake_info_if); */
353 * This function will tell the airpcap driver the key list to use
354 * This will be stored into the registry...
357 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
362 PAirpcapKeysCollection KeysCollection;
363 ULONG KeysCollectionSize;
365 UINT keys_in_list = 0;
366 decryption_key_t* key_item = NULL;
368 keys_in_list = g_list_length(key_list);
371 * Save the encryption keys, if we have any of them
373 KeysCollectionSize = 0;
376 * Calculate the size of the keys collection
378 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
381 * Allocate the collection
383 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
390 * Populate the key collection
392 KeysCollection->nKeys = keys_in_list;
394 for(i = 0; i < keys_in_list; i++)
396 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
398 /* Retrieve the Item corresponding to the i-th key */
399 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
400 new_key = g_string_new(key_item->key->str);
402 KeysCollection->Keys[i].KeyLen = new_key->len / 2;
403 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
405 for(j = 0 ; j < new_key->len; j += 2)
407 s[0] = new_key->str[j];
408 s[1] = new_key->str[j+1];
410 KeyByte = (UCHAR)strtol(s, NULL, 16);
411 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
414 g_string_free(new_key,TRUE);
418 * Free the old adapter key collection!
420 if(info_if->keysCollection != NULL)
421 g_free(info_if->keysCollection);
424 * Set this collection ad the new one
426 info_if->keysCollection = KeysCollection;
427 info_if->keysCollectionSize = KeysCollectionSize;
430 * Configuration must be saved
432 info_if->saved = FALSE;
435 * Write down the changes to the registry
437 airpcap_save_selected_if_configuration(info_if);
443 * This function will tell the airpcap driver the key list to use
444 * This will be stored into the registry...
447 write_wlan_driver_wep_keys_to_registry(GList* key_list)
452 PAirpcapKeysCollection KeysCollection;
453 ULONG KeysCollectionSize;
455 UINT keys_in_list = 0;
456 decryption_key_t* key_item = NULL;
457 airpcap_if_info_t* fake_info_if = NULL;
459 /* Create the fake_info_if from the first adapter of the list */
460 fake_info_if = airpcap_driver_fake_if_info_new();
462 if(fake_info_if == NULL)
466 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
467 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
469 n = g_list_length(key_list);
470 for(k = 0; k < n; k++ )
471 if(((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
475 * Save the encryption keys, if we have any of them
477 KeysCollectionSize = 0;
480 * Calculate the size of the keys collection
482 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
485 * Allocate the collection
487 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
494 * Populate the key collection
496 KeysCollection->nKeys = keys_in_list;
499 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
500 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
501 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
504 y = 0; /* Current position in the key list */
506 for(i = 0; i < n; i++)
508 /* Retrieve the Item corresponding to the i-th key */
509 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
512 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supportd right now!
513 * We will have to modify the AirpcapKey structure in order to
514 * support the other two types! What happens now, is that simply the
515 * not supported keys will just be discarded (they will be saved in wireshark though)
517 if(key_item->type == AIRPDCAP_KEY_TYPE_WEP)
519 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
521 new_key = g_string_new(key_item->key->str);
523 KeysCollection->Keys[y].KeyLen = new_key->len / 2;
524 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
526 for(j = 0 ; j < new_key->len; j += 2)
528 s[0] = new_key->str[j];
529 s[1] = new_key->str[j+1];
531 KeyByte = (UCHAR)strtol(s, NULL, 16);
532 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
534 /* XXX - Change when WPA will be supported!!! */
536 g_string_free(new_key,TRUE);
538 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
540 /* XXX - The driver cannot deal with this kind of key yet... */
542 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
544 /* XXX - The driver cannot deal with this kind of key yet... */
549 * Free the old adapter key collection!
551 if(fake_info_if->keysCollection != NULL)
552 g_free(fake_info_if->keysCollection);
555 * Set this collection ad the new one
557 fake_info_if->keysCollection = KeysCollection;
558 fake_info_if->keysCollectionSize = KeysCollectionSize;
561 * Configuration must be saved
563 fake_info_if->saved = FALSE;
566 * Write down the changes to the registry
568 airpcap_save_driver_if_configuration(fake_info_if);
570 airpcap_if_info_free(fake_info_if);
576 * Function used to save to the preference file the Decryption Keys.
579 save_wlan_driver_wep_keys()
581 GList* key_list = NULL;
582 char* tmp_key = NULL;
583 guint keys_in_list,i;
584 keys_cb_data_t* user_data;
585 airpcap_if_info_t* fake_info_if = NULL;
587 /* Create the fake_info_if from the first adapter of the list */
588 fake_info_if = airpcap_driver_fake_if_info_new();
590 if(fake_info_if == NULL)
593 /* Retrieve the wlan preferences */
594 wlan_prefs = prefs_find_module("wlan");
596 /* Allocate a structure used to keep infos between the callbacks */
597 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
599 /* Number of keys in key list */
600 /* Number of keys in key list */
601 if(fake_info_if->keysCollectionSize != 0)
602 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
606 for(i=0; i<keys_in_list; i++)
608 /* Only if it is a WEP key... */
609 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
611 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
612 key_list = g_list_append(key_list,g_strdup(tmp_key));
617 /* Now we know the exact number of WEP keys in the list, so store it ... */
618 keys_in_list = g_list_length(key_list);
620 /* Fill the structure */
621 user_data->list = key_list;
622 user_data->current_index = 0;
623 user_data->number_of_keys= keys_in_list;
625 /* Retrieve the wlan preferences */
626 wlan_prefs = prefs_find_module("wlan");
628 /* Run the callback on each 802.11 preference */
629 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
631 /* Signal that we've changed things, and run the 802.11 dissector's
633 wlan_prefs->prefs_changed = TRUE;
635 /* Apply changes for the specified preference */
636 prefs_apply(wlan_prefs);
639 /* free the WEP key string */
640 for(i=0;i<g_list_length(user_data->list);i++)
642 g_free(g_list_nth(user_data->list,i)->data);
645 /* free the (empty) list */
646 g_list_free(user_data->list);
648 /* free the user_data structure */
651 airpcap_if_info_free(fake_info_if);
657 * Function used to save to the preference file the Decryption Keys.
660 save_wlan_wireshark_wep_keys(GList* key_ls)
662 GList* key_list = NULL;
663 char* tmp_key = NULL;
664 guint keys_in_list,i;
665 keys_cb_data_t* user_data;
666 airpcap_if_info_t* fake_info_if = NULL;
667 decryption_key_t* tmp_dk;
669 /* Retrieve the wlan preferences */
670 wlan_prefs = prefs_find_module("wlan");
672 /* Allocate a structure used to keep infos between the callbacks */
673 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
675 keys_in_list = g_list_length(key_ls);
679 /* Fill the structure */
680 user_data->list = key_list;
681 user_data->current_index = 0;
682 user_data->number_of_keys= keys_in_list;
684 /* Retrieve the wlan preferences */
685 wlan_prefs = prefs_find_module("wlan");
687 /* Run the callback on each 802.11 preference */
688 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
690 /* Signal that we've changed things, and run the 802.11 dissector's
692 wlan_prefs->prefs_changed = TRUE;
694 /* Apply changes for the specified preference */
695 prefs_apply(wlan_prefs);
698 /* free the WEP key string */
699 for(i=0;i<g_list_length(user_data->list);i++)
701 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
702 g_string_free(tmp_dk->key,TRUE);
703 if(tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
706 /* free the (empty) list */
707 g_list_free(user_data->list);
709 /* free the user_data structure */
716 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
717 * "get_airpcap_interface_list()".
720 cant_get_airpcap_if_list_error_message(const char *err_str)
722 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
726 * Airpcap wrapper, used to store the current settings for the selected adapter
729 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
731 if (!AirpcapLoaded) return FALSE;
732 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
736 * Airpcap wrapper, used to open an airpcap adapter
739 airpcap_if_open(PCHAR name, PCHAR err)
741 if (!AirpcapLoaded) return NULL;
742 if (name == NULL) return NULL;
743 return g_PAirpcapOpen(name,err);
747 * Airpcap wrapper, used to close an airpcap adapter
750 airpcap_if_close(PAirpcapHandle handle)
752 if (!AirpcapLoaded) return;
753 g_PAirpcapClose(handle);
757 * Retrieve the state of the Airpcap DLL
760 airpcap_get_dll_state()
762 return AirpcapVersion;
766 * Airpcap wrapper, used to turn on the led of an airpcap adapter
769 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber)
771 if (!AirpcapLoaded) return FALSE;
772 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
776 * Airpcap wrapper, used to turn off the led of an airpcap adapter
779 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber)
781 if (!AirpcapLoaded) return FALSE;
782 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
786 * Airpcap wrapper, used to get the channel of an airpcap adapter
789 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch)
791 if (!AirpcapLoaded) return FALSE;
792 return g_PAirpcapGetDeviceChannel(ah,ch);
796 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
799 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, PULONG nInfo)
801 if (!AirpcapLoaded) return FALSE;
802 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
803 *nInfo = num_legacy_channels;
804 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
807 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
808 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
814 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
817 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels)
819 AirpcapChannelInfo *chanInfo;
820 ULONG i=0, j=0, numInfo = 0;
821 if (!AirpcapLoaded) return FALSE;
822 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE) return NULL;
823 numSupportedChannels = 0;
826 * allocate a bigger array
831 pSupportedChannels = malloc(numInfo * (sizeof *pSupportedChannels));
833 for (i = 0; i < numInfo; i++)
835 ULONG supportedChannel = 0xFFFFFFFF;
838 * search if we have it already
840 for (j = 0; j < numSupportedChannels; j++)
842 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
844 supportedChannel = j;
849 if (supportedChannel == 0xFFFFFFFF)
852 * not found, create a new item
854 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
856 switch(chanInfo[i].ExtChannel)
858 case -1: pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH; break;
859 case +1: pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW; break;
861 default: pSupportedChannels[numSupportedChannels].Flags = 0;
865 * match with the ABG channels
868 for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++)
870 if (pSupportedChannels[numSupportedChannels].Frequency == Dot11aChannels[j].Frequency)
872 pSupportedChannels[numSupportedChannels].Flags |= FLAG_IS_A_CHANNEL;
873 pSupportedChannels[numSupportedChannels].Channel = Dot11aChannels[j].Channel;
878 for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++)
880 if (pSupportedChannels[numSupportedChannels].Frequency == Dot11bChannels[j].Frequency)
882 pSupportedChannels[numSupportedChannels].Flags |= FLAG_IS_BG_CHANNEL;
883 pSupportedChannels[numSupportedChannels].Channel = Dot11bChannels[j].Channel;
888 if ((pSupportedChannels[numSupportedChannels].Flags & (FLAG_IS_BG_CHANNEL | FLAG_IS_A_CHANNEL)) == 0){
889 pSupportedChannels[numSupportedChannels].Channel = 0;
892 numSupportedChannels++;
897 * just update the ext channel flags
899 switch(chanInfo[i].ExtChannel)
901 case -1: pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH; break;
902 case +1: pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW; break;
911 * Now sort the list by frequency
913 for (i = 0 ; i < numSupportedChannels - 1; i++)
915 for (j = i + 1; j < numSupportedChannels; j++)
917 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
919 Dot11Channel temp = pSupportedChannels[i];
920 pSupportedChannels[i] = pSupportedChannels[j];
921 pSupportedChannels[j] = temp;
926 *pNumSupportedChannels = numSupportedChannels;
927 return pSupportedChannels;
931 * Get channel representation string given a Frequency
934 airpcap_get_channelstr_from_freq(ULONG chan_freq){
938 channelstr = (gchar*)g_malloc(sizeof(gchar)*20);
939 for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++)
941 if (chan_freq == Dot11aChannels[j].Frequency)
943 sprintf(channelstr, "%u MHz [A %u]", chan_freq, Dot11aChannels[j].Channel);
948 for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++)
950 if (chan_freq == Dot11bChannels[j].Frequency)
952 sprintf(channelstr, "%u MHz [BG %u]", chan_freq, Dot11bChannels[j].Channel);
957 sprintf(channelstr, "%u MHz", chan_freq);
963 * Get channel number given a Frequency
966 airpcap_get_channel_number_from_freq(ULONG chan_freq){
969 for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++){
970 if (chan_freq == Dot11bChannels[j].Frequency){
971 return Dot11bChannels[j].Channel;
975 for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++){
976 if (chan_freq == Dot11aChannels[j].Frequency){
977 return Dot11aChannels[j].Channel;
985 * Get Frequency given a Channel number
988 airpcap_get_freq_from_channel_number(guint chan_number){
991 for (j = 0; j < sizeof(Dot11bChannels)/sizeof(Dot11bChannels[0]); j++){
992 if (chan_number == Dot11bChannels[j].Channel){
993 return Dot11bChannels[j].Frequency;
997 for (j = 0; j < sizeof(Dot11aChannels)/sizeof(Dot11aChannels[0]); j++){
998 if (chan_number == Dot11aChannels[j].Channel){
999 return Dot11aChannels[j].Frequency;
1008 * Airpcap wrapper, used to set the channel of an airpcap adapter
1011 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch)
1013 if (!AirpcapLoaded) return FALSE;
1014 return g_PAirpcapSetDeviceChannel(ah,ch);
1018 * Airpcap wrapper, used to set the frequency of an airpcap adapter
1021 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
1023 if (!AirpcapLoaded) return FALSE;
1024 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
1026 channel = airpcap_get_channel_number_from_freq(ChannelInfo.Frequency);
1031 return airpcap_if_set_device_channel(ah, channel);
1033 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
1034 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
1041 * Airpcap wrapper, used to get the frequency of an airpcap adapter
1044 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
1046 if (!AirpcapLoaded) return FALSE;
1048 pChannelInfo->Frequency = 0;
1049 pChannelInfo->ExtChannel = 0;
1050 pChannelInfo->Reserved[0] = 0;
1051 pChannelInfo->Reserved[1] = 0;
1052 pChannelInfo->Reserved[2] = 0;
1054 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
1056 ULONG chan_freq = 0;
1058 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
1060 chan_freq = airpcap_get_freq_from_channel_number(channel);
1061 if (chan_freq == 0) return FALSE;
1062 pChannelInfo->Frequency = chan_freq;
1065 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
1066 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
1072 * Airpcap wrapper, used to get the link type of an airpcap adapter
1075 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
1077 if (!AirpcapLoaded) return FALSE;
1078 return g_PAirpcapGetLinkType(ah,lt);
1082 * Airpcap wrapper, used to set the link type of an airpcap adapter
1085 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
1087 if (!AirpcapLoaded) return FALSE;
1088 return g_PAirpcapSetLinkType(ah,lt);
1092 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
1095 airpcap_if_get_fcs_presence(PAirpcapHandle ah, PBOOL fcs)
1097 if (!AirpcapLoaded) return FALSE;
1098 return g_PAirpcapGetFcsPresence(ah,fcs);
1102 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
1105 airpcap_if_set_fcs_presence(PAirpcapHandle ah, BOOL fcs)
1107 if (!AirpcapLoaded) return FALSE;
1108 return g_PAirpcapSetFcsPresence(ah,fcs);
1112 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
1115 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1117 if (!AirpcapLoaded) return FALSE;
1118 return g_PAirpcapGetDecryptionState(ah,PEnable);
1122 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1125 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1127 if (!AirpcapLoaded) return FALSE;
1128 return g_PAirpcapSetDecryptionState(ah,Enable);
1132 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1135 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1137 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1138 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1142 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1145 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1147 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1148 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1152 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1155 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1157 if (!AirpcapLoaded) return FALSE;
1158 return g_PAirpcapGetFcsValidation(ah,val);
1162 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1165 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1167 if (!AirpcapLoaded) return FALSE;
1168 return g_PAirpcapSetFcsValidation(ah,val);
1172 * Airpcap wrapper, used to save the settings for the selected_if
1175 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1177 if (!AirpcapLoaded) return FALSE;
1178 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1182 * Airpcap wrapper, used to save the settings for the selected_if
1185 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize)
1187 if (!AirpcapLoaded) return FALSE;
1188 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1192 * Airpcap wrapper, used to save the driver's set of keys
1195 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1197 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1198 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1202 * Airpcap wrapper, used to load the driver's set of keys
1205 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize)
1207 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1208 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1212 * This function will create a new airpcap_if_info_t using a name and a description
1215 airpcap_if_info_new(char *name, char *description)
1218 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1220 airpcap_if_info_t *if_info = NULL;
1222 /* Probably I have to switch on the leds!!! */
1223 ad = airpcap_if_open(name, ebuf);
1226 if_info = g_malloc(sizeof (airpcap_if_info_t));
1227 if_info->name = g_strdup(name);
1228 if (description == NULL){
1229 if_info->description = NULL;
1231 if_info->description = g_strdup(description);
1234 if_info->ip_addr = NULL;
1235 if_info->loopback = FALSE;
1236 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1237 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1238 airpcap_if_get_link_type(ad,&(if_info->linkType));
1239 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1240 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1241 airpcap_if_turn_led_on(ad, 0);
1242 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1243 if_info->led = TRUE;
1244 if_info->blinking = FALSE;
1245 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1247 /* get the keys, if everything is ok, close the adapter */
1248 if(airpcap_if_load_keys(ad,if_info))
1250 airpcap_if_close(ad);
1257 * This function will create a new fake drivers' interface, to load global keys...
1260 airpcap_driver_fake_if_info_new()
1263 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1265 airpcap_if_info_t *if_info = NULL;
1266 airpcap_if_info_t *fake_if_info = NULL;
1268 /* Maybe for some reason no airpcap adapter is found */
1269 if(airpcap_if_list == NULL)
1273 * Retrieve the first AirPcap adapter available. If no interface is found,
1274 * it is not possible to retrieve the driver's settings, so return NULL.
1276 if_info = g_list_nth_data(airpcap_if_list,0);
1280 /* Open the 'fake' adapter */
1281 ad = airpcap_if_open(if_info->name, ebuf);
1284 fake_if_info = g_malloc(sizeof (airpcap_if_info_t));
1285 fake_if_info->name = g_strdup(if_info->name);
1286 fake_if_info->description = g_strdup(if_info->description);
1287 fake_if_info->loopback = FALSE;
1288 fake_if_info->ip_addr = NULL;
1289 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1290 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1291 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1292 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1293 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1294 airpcap_if_turn_led_on(ad, 0);
1295 fake_if_info->led = TRUE;
1296 fake_if_info->blinking = FALSE;
1297 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1299 /* get the keys, if everything is ok, close the adapter */
1300 if(airpcap_if_load_driver_keys(ad,fake_if_info))
1302 airpcap_if_close(ad);
1306 return fake_if_info;
1310 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1313 airpcap_if_info_print(airpcap_if_info_t* if_info)
1318 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1322 g_print("\n----------------- AirPcap Interface \n");
1323 g_print(" NAME: %s\n",if_info->name);
1324 g_print(" DESCRIPTION: %s\n",if_info->description);
1325 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1326 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1327 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1328 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1329 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1330 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1331 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1332 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1333 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1334 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1335 g_print(" LINKTYPE: %d\n",if_info->linkType);
1336 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1337 g_print(" (GTK) TAG: %d\n",if_info->tag);
1338 g_print("SUPPORTED CHANNELS POINTER: %lu\n",if_info->pSupportedChannels);
1339 g_print(" NUM SUPPORTED CHANNELS: %lu\n",if_info->numSupportedChannels);
1341 for(i=0; i<(if_info->numSupportedChannels); i++){
1342 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1343 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1344 g_print(" FREQUENCY: %lu\n",if_info->pSupportedChannels[i].Frequency);
1345 g_print(" FLAGS: %lu\n",if_info->pSupportedChannels[i].Flags);
1351 * Function used to load the WEP keys for a selected interface
1354 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1356 if(!if_info) return FALSE;
1358 if_info->keysCollectionSize = 0;
1359 if_info->keysCollection = NULL;
1361 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1363 if(if_info->keysCollectionSize == 0)
1365 if_info->keysCollection = NULL;
1366 airpcap_if_close(ad);
1370 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1371 if(!if_info->keysCollection)
1373 if_info->keysCollectionSize = 0;
1374 if_info->keysCollection = NULL;
1375 airpcap_if_close(ad);
1379 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1383 airpcap_if_close(ad);
1388 * Function used to load the WEP keys for a selected interface
1391 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1393 if_info->keysCollectionSize = 0;
1394 if_info->keysCollection = NULL;
1396 if(!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1398 if(if_info->keysCollectionSize == 0)
1400 if_info->keysCollection = NULL;
1401 airpcap_if_close(ad);
1405 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1406 if(!if_info->keysCollection)
1408 if_info->keysCollectionSize = 0;
1409 if_info->keysCollection = NULL;
1410 airpcap_if_close(ad);
1414 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1418 airpcap_if_close(ad);
1423 * Function used to save the WEP keys for a selected interface
1426 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1428 if(!if_info || !AirpcapLoaded) return;
1430 if(if_info->keysCollection != NULL)
1431 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1435 * Function used to save the WEP keys for a selected interface
1438 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1440 if(if_info->keysCollection != NULL)
1441 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1445 * Callback used to free an instance of airpcap_if_info_t
1448 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1450 airpcap_if_info_t *if_info = data;
1452 if (if_info->name != NULL)
1453 g_free(if_info->name);
1455 if (if_info->description != NULL)
1456 g_free(if_info->description);
1458 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1459 if(if_info->keysCollection != NULL)
1461 g_free(if_info->keysCollection);
1462 if_info->keysCollection = NULL;
1465 if(if_info->ip_addr != NULL)
1466 g_slist_free(if_info->ip_addr);
1473 * Function used to free the airpcap interface list
1476 free_airpcap_interface_list(GList *if_list)
1478 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1479 g_list_free(if_list);
1484 * This function will use the airpcap.dll to find all the airpcap devices.
1485 * Will return null if no device is found.
1488 get_airpcap_interface_list(int *err, char **err_str)
1491 airpcap_if_info_t *if_info;
1493 AirpcapDeviceDescription *devsList, *adListEntry;
1494 char errbuf[PCAP_ERRBUF_SIZE];
1498 *err = AIRPCAP_NOT_LOADED;
1502 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1504 /* No interfaces, return il = NULL; */
1505 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1506 if (err_str != NULL)
1507 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1512 * Count the adapters
1514 adListEntry = devsList;
1519 adListEntry = adListEntry->next;
1524 /* No interfaces, return il= NULL */
1525 g_PAirpcapFreeDeviceList(devsList);
1526 *err = NO_AIRPCAP_INTERFACES_FOUND;
1527 if (err_str != NULL)
1533 * Insert the adapters in our list
1535 adListEntry = devsList;
1536 for(i = 0; i < n_adapts; i++)
1538 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1539 if (if_info != NULL){
1540 il = g_list_append(il, if_info);
1543 adListEntry = adListEntry->next;
1546 g_PAirpcapFreeDeviceList(devsList);
1553 * Used to retrieve the interface given the name
1554 * (the name is used in AirpcapOpen)
1556 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
1560 airpcap_if_info_t* if_info;
1565 while( ifn < g_list_length(if_list) )
1567 curr = g_list_nth(if_list, ifn);
1571 if_info = curr->data;
1574 if ( g_ascii_strcasecmp(if_info->name,name) == 0)
1586 * Returns the ASCII string of a key given the key bytes
1589 airpcap_get_key_string(AirpcapKey key)
1598 if(key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1602 /* Allocate the string used to store the ASCII representation of the WEP key */
1603 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1604 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1607 for(j = 0; j < key.KeyLen; j++)
1609 src = g_strdup_printf("%.2x\0", key.KeyData[j]);
1611 * XXX - use g_strconcat() or GStrings instead ???
1613 l = g_strlcat(dst,src,WEP_KEY_MAX_CHAR_SIZE+1);
1618 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1620 /* XXX - Add code here */
1622 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1624 /* XXX - Add code here */
1628 /* XXX - Add code here */
1635 * Clear keys and decryption status for the specified interface
1638 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1642 if(info_if->keysCollection != NULL)
1644 g_free(info_if->keysCollection);
1645 info_if->keysCollection = NULL;
1648 info_if->keysCollectionSize = 0;
1650 info_if->DecryptionOn = FALSE;
1651 info_if->saved = FALSE;
1656 * Used to retrieve the two chars string from interface
1659 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1665 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1667 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1668 * Otherwise, check if it is the "Any" adapter...
1672 if(g_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1673 number = g_strdup_printf("??");
1675 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1679 number = g_strdup_printf("%.2u\0",n);
1686 * Used to retrieve the two chars string from interface
1689 airpcap_get_if_string_number_from_description(gchar* description)
1694 number = (gchar*)g_malloc(sizeof(gchar)*3);
1696 pointer = g_strrstr(description,"#\0");
1698 number[0] = *(pointer+1);
1699 number[1] = *(pointer+2);
1706 * Returns the default airpcap interface of a list, NULL if list is empty
1709 airpcap_get_default_if(GList* airpcap_if_list)
1712 GList* popdown_if_list = NULL;
1716 airpcap_if_info_t* if_info = NULL;
1718 if(prefs.capture_device != NULL)
1720 s = g_strdup(get_if_name(prefs.capture_device));
1721 if_info = get_airpcap_if_from_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
1728 * Load the configuration for the specified interface
1731 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1733 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1738 ad = airpcap_if_open(if_info->name, ebuf);
1742 /* Stop blinking (if it was blinkig!)*/
1743 if(if_info->blinking)
1745 /* Turn on the light (if it was off) */
1746 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1749 /* Apply settings... */
1750 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1751 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1752 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1753 airpcap_if_get_link_type(ad,&(if_info->linkType));
1754 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1755 /* get the keys, if everything is ok, close the adapter */
1756 if(airpcap_if_load_keys(ad,if_info))
1757 airpcap_if_close(ad);
1759 if_info->saved = TRUE;
1763 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1769 * Save the configuration for the specified interface
1772 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1774 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1779 ad = airpcap_if_open(if_info->name, ebuf);
1783 /* Stop blinking (if it was blinkig!)*/
1784 if(if_info->blinking)
1786 /* Turn on the light (if it was off) */
1787 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1790 /* Apply settings... */
1791 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1792 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1793 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1794 airpcap_if_set_link_type(ad,if_info->linkType);
1795 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1796 airpcap_if_save_keys(ad,if_info);
1798 /* ... and save them */
1799 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1801 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Cannot save Wireless 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.");
1802 if_info->saved = FALSE;
1803 airpcap_if_close(ad);
1807 if_info->saved = TRUE;
1808 airpcap_if_close(ad);
1812 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1818 * Save the configuration for the specified interface
1821 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1823 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1826 if(fake_if_info != NULL)
1828 ad = airpcap_if_open(fake_if_info->name, ebuf);
1832 /* Apply decryption settings... */
1833 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1834 airpcap_if_save_driver_keys(ad,fake_if_info);
1835 airpcap_if_close(ad);
1839 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1847 * DECRYPTION KEYS FUNCTIONS
1850 * This function is used for DEBUG POURPOSES ONLY!!!
1853 print_key_list(GList* key_list)
1856 decryption_key_t* tmp;
1858 if(key_list == NULL)
1860 g_print("\n\n******* KEY LIST NULL *******\n\n");
1864 n = g_list_length(key_list);
1866 g_print("\n\n********* KEY LIST **********\n\n");
1868 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1870 for(i =0; i < n; i++)
1872 g_print("[%d] :\n",i+1);
1873 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1874 g_print("KEY : %s\n",tmp->key->str);
1876 g_print("BITS: %d\n",tmp->bits);
1878 if(tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1879 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1880 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1881 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1882 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1883 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1885 g_print("TYPE: %s\n","???");
1887 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1888 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1892 g_print("\n*****************************\n\n");
1896 * Retrieves a GList of decryption_key_t structures containing infos about the
1897 * keys for the given adapter... returns NULL if no keys are found.
1900 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1903 char* tmp_key = NULL;
1904 guint i,keys_in_list = 0;
1907 decryption_key_t *new_key = NULL;
1908 GList *key_list = NULL;
1910 /* Number of keys in key list */
1911 if(info_if->keysCollectionSize != 0)
1912 keys_in_list = (guint)(info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1916 for(i=0; i<keys_in_list; i++)
1918 /* Different things to do depending on the key type */
1919 if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1921 /* allocate memory for the new key item */
1922 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1924 /* fill the fields */
1926 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1927 new_key->key = g_string_new(tmp_key);
1931 new_key->bits = new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an exadecimal number) */
1933 /* SSID not used in WEP keys */
1934 new_key->ssid = NULL;
1936 /* TYPE (WEP in this case) */
1937 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1939 /* Append the new element in the list */
1940 key_list = g_list_append(key_list,(gpointer)new_key);
1942 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1944 /* XXX - Not supported yet */
1946 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1948 /* XXX - Not supported yet */
1956 * Retrieves a GList of decryption_key_t structures containing infos about the
1957 * keys for the global AirPcap driver... returns NULL if no keys are found.
1960 get_airpcap_driver_keys()
1963 char* tmp_key = NULL;
1964 guint i,keys_in_list = 0;
1967 decryption_key_t *new_key = NULL;
1968 GList *key_list = NULL;
1971 * To read the drivers general settings we need to create and use one airpcap adapter...
1972 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1974 airpcap_if_info_t* fake_info_if = NULL;
1976 /* Create the fake_info_if from the first adapter of the list */
1977 fake_info_if = airpcap_driver_fake_if_info_new();
1979 if(fake_info_if == NULL)
1982 /* Number of keys in key list */
1983 if(fake_info_if->keysCollectionSize != 0)
1984 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1988 for(i=0; i<keys_in_list; i++)
1990 /* Different things to do depending on the key type */
1991 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1993 /* allocate memory for the new key item */
1994 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1996 /* fill the fields */
1998 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1999 new_key->key = g_string_new(tmp_key);
2000 if(tmp_key != NULL) g_free(tmp_key);
2003 new_key->bits = new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an exadecimal number) */
2005 /* SSID not used in WEP keys */
2006 new_key->ssid = NULL;
2008 /* TYPE (WEP in this case) */
2009 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
2011 /* Append the new element in the list */
2012 key_list = g_list_append(key_list,(gpointer)new_key);
2014 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
2016 /* XXX - Not supported yet */
2018 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
2020 /* XXX - Not supported yet */
2024 airpcap_if_info_free(fake_info_if);
2030 * Returns the list of the decryption keys specified for wireshark, NULL if
2034 get_wireshark_keys()
2036 keys_cb_data_t* wep_user_data = NULL;
2040 GList* final_list = NULL;
2041 GList* wep_final_list = NULL;
2043 /* Retrieve the wlan preferences */
2044 wlan_prefs = prefs_find_module("wlan");
2046 /* Allocate a structure used to keep infos between the callbacks */
2047 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
2049 /* Fill the structure */
2050 wep_user_data->list = NULL;
2051 wep_user_data->current_index = 0;
2052 wep_user_data->number_of_keys= 0; /* Still unknown */
2054 /* Run the callback on each 802.11 preference */
2055 /* XXX - Right now, only WEP keys will be loaded */
2056 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
2058 /* Copy the list field in the user data structure pointer into the final_list */
2059 if(wep_user_data != NULL) wep_final_list = wep_user_data->list;
2061 /* XXX - Merge the three lists!!!!! */
2062 final_list = wep_final_list;
2064 /* free the wep_user_data structure */
2065 g_free(wep_user_data);
2071 * Merges two lists of keys and return a newly created GList. If a key is
2072 * found multiple times, it will just appear once!
2073 * list1 and list 2 pointer will have to be freed manually if needed!!!
2074 * If the total number of keys exceeeds the maximum number allowed,
2075 * exceeding keys will be discarded...
2078 merge_key_list(GList* list1, GList* list2)
2082 decryption_key_t *dk1=NULL,
2086 GList* merged_list = NULL;
2088 if( (list1 == NULL) && (list2 == NULL) )
2094 n2 = g_list_length(list2);
2098 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2099 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2101 new_dk->bits = dk2->bits;
2102 new_dk->type = dk2->type;
2103 new_dk->key = g_string_new(dk2->key->str);
2104 new_dk->ssid = byte_array_dup(dk2->ssid);
2106 /* Check the total length of the merged list */
2107 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2108 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2111 else if(list2 == NULL)
2113 n1 = g_list_length(list1);
2118 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2119 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
2121 new_dk->bits = dk1->bits;
2122 new_dk->type = dk1->type;
2123 new_dk->key = g_string_new(dk1->key->str);
2124 new_dk->ssid = byte_array_dup(dk1->ssid);
2126 /* Check the total length of the merged list */
2127 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2128 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2133 n1 = g_list_length(list1);
2134 n2 = g_list_length(list2);
2136 /* Copy the whole list1 into merged_list */
2139 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2140 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2142 new_dk->bits = dk1->bits;
2143 new_dk->type = dk1->type;
2144 new_dk->key = g_string_new(dk1->key->str);
2145 new_dk->ssid = byte_array_dup(dk1->ssid);
2147 /* Check the total length of the merged list */
2148 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2149 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2152 /* Look for keys that are present in list2 but aren't in list1 yet...
2153 * Add them to merged_list
2157 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2159 if(!key_is_in_list(dk2,merged_list))
2161 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2163 new_dk->bits = dk2->bits;
2164 new_dk->type = dk2->type;
2165 new_dk->key = g_string_new(dk2->key->str);
2166 new_dk->ssid = byte_array_dup(dk2->ssid);
2168 /* Check the total length of the merged list */
2169 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2170 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2179 * Use this function to free a key list.
2182 free_key_list(GList *list)
2185 decryption_key_t *curr_key;
2190 n = g_list_length(list);
2192 for(i = 0; i < n; i++)
2194 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2196 /* Free all the strings */
2197 if(curr_key->key != NULL)
2198 g_string_free(curr_key->key, TRUE);
2200 if(curr_key->ssid != NULL)
2201 g_byte_array_free(curr_key->ssid, TRUE);
2203 /* free the decryption_key_t structure*/
2216 * If the given key is contained in the list, returns TRUE.
2217 * Returns FALSE otherwise.
2220 key_is_in_list(decryption_key_t *dk,GList *list)
2223 decryption_key_t* curr_key = NULL;
2224 gboolean found = FALSE;
2226 if( (list == NULL) || (dk == NULL) )
2229 n = g_list_length(list);
2234 for(i = 0; i < n; i++)
2236 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2237 if(keys_are_equals(dk,curr_key))
2245 * Returns TRUE if keys are equals, FALSE otherwise
2248 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2251 if((k1==NULL) || (k2==NULL))
2254 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2255 /** 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) ) **/
2256 /** return TRUE; **/
2258 if( g_string_equal(k1->key,k2->key) &&
2259 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2260 k1->type == k2->type)
2262 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2263 if((k1->ssid == NULL) && (k2->ssid == NULL))
2266 /* If they are not null, they must share the same ssid */
2267 return byte_array_equal(k1->ssid,k2->ssid);
2270 /* Some field is not equal ... */
2275 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2276 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2280 key_lists_are_equal(GList* list1, GList* list2)
2284 guint wep_n1=0,wep_n2=0;
2285 GList *wep_list1=NULL;
2286 GList *wep_list2=NULL;
2289 decryption_key_t *dk1=NULL,*dk2=NULL;
2291 n1 = g_list_length(list1);
2292 n2 = g_list_length(list2);
2295 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2296 * is not implemented.
2300 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2301 if(dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2303 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2309 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2310 if(dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2312 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2318 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2323 * Commented, because in the new AirPcap version all the keys will be saved
2324 * into the driver, and all the keys for every specific adapter will be
2325 * removed. This means that this check will always fail... and the user will
2326 * always be asked what to do... and it doesn't make much sense.
2328 /* if(n1 != n2) return FALSE; */
2329 if(wep_n1 != wep_n2) return FALSE;
2336 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2337 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2339 if(!g_string_equal(dk1->key,dk2->key)) return FALSE;
2343 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2344 if(!key_is_in_list(dk2,wep_list1)) return FALSE;
2351 test_if_on(pref_t *pref, gpointer ud _U_)
2356 /* Retrieve user data info */
2357 is_on = (gboolean*)ud;
2360 if (g_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2362 number = *pref->varp.boolp;
2364 if(number) *is_on = TRUE;
2365 else *is_on = FALSE;
2373 * Returns TRUE if the Wireshark decryption is active, false otherwise
2376 wireshark_decryption_on()
2380 /* Retrieve the wlan preferences */
2381 wlan_prefs = prefs_find_module("wlan");
2383 /* Run the callback on each 802.11 preference */
2384 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2390 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2393 airpcap_decryption_on()
2395 gboolean is_on = FALSE;
2397 airpcap_if_info_t* fake_if_info = NULL;
2399 fake_if_info = airpcap_driver_fake_if_info_new();
2401 if(fake_if_info != NULL)
2403 if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2405 else if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2409 airpcap_if_info_free(fake_if_info);
2415 * Free an instance of airpcap_if_info_t
2418 airpcap_if_info_free(airpcap_if_info_t *if_info)
2422 if (if_info->name != NULL)
2423 g_free(if_info->name);
2425 if (if_info->description != NULL)
2426 g_free(if_info->description);
2428 if(if_info->keysCollection != NULL)
2430 g_free(if_info->keysCollection);
2431 if_info->keysCollection = NULL;
2434 if(if_info->ip_addr != NULL)
2436 g_slist_free(if_info->ip_addr);
2437 if_info->ip_addr = NULL;
2449 set_on_off(pref_t *pref, gpointer ud _U_)
2454 /* Retrieve user data info */
2455 is_on = (gboolean*)ud;
2457 if (g_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2459 number = *pref->varp.boolp;
2461 g_free((void *)*pref->varp.boolp);
2463 *pref->varp.boolp = TRUE;
2465 *pref->varp.boolp = FALSE;
2473 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2476 set_wireshark_decryption(gboolean on_off)
2482 /* Retrieve the wlan preferences */
2483 wlan_prefs = prefs_find_module("wlan");
2485 /* Run the callback on each 802.11 preference */
2486 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2489 * Signal that we've changed things, and run the 802.11 dissector's
2492 wlan_prefs->prefs_changed = TRUE;
2494 prefs_apply(wlan_prefs);
2498 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2501 set_airpcap_decryption(gboolean on_off)
2503 /* We need to directly access the .dll functions here... */
2504 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2505 PAirpcapHandle ad,ad_driver;
2507 gboolean success = TRUE;
2511 airpcap_if_info_t* curr_if = NULL;
2512 airpcap_if_info_t* fake_if_info = NULL;
2514 fake_if_info = airpcap_driver_fake_if_info_new();
2516 if(fake_if_info == NULL)
2517 /* We apparently don't have any adapters installed.
2518 * This isn't a failure, so return TRUE
2522 /* Set the driver decryption */
2523 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2527 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2529 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2531 airpcap_if_close(ad_driver);
2534 airpcap_if_info_free(fake_if_info);
2536 n = g_list_length(airpcap_if_list);
2538 /* Set to FALSE the decryption for all the adapters */
2539 /* Apply this change to all the adapters !!! */
2540 for(i = 0; i < n; i++)
2542 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2544 if( curr_if != NULL )
2546 ad = airpcap_if_open(curr_if->name, ebuf);
2549 curr_if->DecryptionOn = (gboolean)AIRPCAP_DECRYPTION_OFF;
2550 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2551 /* Save configuration for the curr_if */
2552 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
2556 airpcap_if_close(ad);
2565 /* DYNAMIC LIBRARY LOADER */
2567 * Used to dynamically load the airpcap library in order link it only when
2568 * it's present on the system
2570 int load_airpcap(void)
2572 BOOL base_functions = TRUE;
2573 BOOL eleven_n_functions = TRUE;
2575 if((AirpcapLib = LoadLibrary(TEXT("airpcap.dll"))) == NULL)
2577 /* Report the error but go on */
2578 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2579 return AirpcapVersion;
2583 if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2584 if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2585 if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2586 if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2587 if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2588 if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2589 if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2590 if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2591 if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2592 if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2593 if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2594 if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2595 if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2596 if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2597 if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2598 if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2599 if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2600 if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2601 if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2602 if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2603 if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2604 if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2605 if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2606 if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2607 if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2608 if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2609 if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2610 if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2611 if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2612 if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2613 if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2614 if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2616 /* TEST IF AIRPCAP SUPPORTS 11N */
2617 if((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2618 if((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2619 if((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2621 if(base_functions && eleven_n_functions){
2622 AirpcapLoaded = TRUE;
2623 AirpcapVersion = AIRPCAP_DLL_OK;
2624 }else if(base_functions){
2625 AirpcapLoaded = TRUE;
2626 AirpcapVersion = AIRPCAP_DLL_OLD;
2627 return AIRPCAP_DLL_OK;
2629 AirpcapLoaded = FALSE;
2630 AirpcapVersion = AIRPCAP_DLL_ERROR;
2633 return AirpcapVersion;
2637 * Append the version of AirPcap with which we were compiled to a GString.
2640 get_compiled_airpcap_version(GString *str)
2642 g_string_append(str, "with AirPcap");
2646 * Append the version of AirPcap with which we we're running to a GString.
2649 get_runtime_airpcap_version(GString *str)
2651 guint vmaj, vmin, vrev, build;
2653 /* See if the DLL has been loaded successfully. Bail if it hasn't */
2654 if (AirpcapLoaded == FALSE) {
2655 g_string_append(str, "without AirPcap");
2659 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
2660 g_string_sprintfa(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2663 #endif /* HAVE_AIRPCAP */