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 <epan/frequency-utils.h>
50 #include "capture_ui_utils.h"
52 #include "simple_dialog.h"
55 #include "airpcap_loader.h"
58 * We load dynamically the dag library in order link it only when
59 * it's present on the system
61 static HMODULE AirpcapLib = NULL;
64 * Set to TRUE if the DLL was successfully loaded AND all functions
67 static gboolean AirpcapLoaded = FALSE;
69 static int AirpcapVersion = 3;
71 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
72 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
73 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
74 static AirpcapOpenHandler g_PAirpcapOpen;
75 static AirpcapCloseHandler g_PAirpcapClose;
76 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
77 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
78 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
79 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
80 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
81 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
82 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
83 static AirpcapReadHandler g_PAirpcapRead;
84 static AirpcapGetStatsHandler g_PAirpcapGetStats;
85 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
86 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
87 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
88 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
89 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
90 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
91 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
92 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
93 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
94 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
95 static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys;
96 static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys;
97 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
98 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
99 static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState;
100 static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState;
101 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
102 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
103 static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx;
104 static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx;
105 static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels;
107 /* Airpcap interface list */
108 GList *airpcap_if_list = NULL;
110 /* Airpcap current selected interface */
111 airpcap_if_info_t *airpcap_if_selected = NULL;
113 /* Airpcap current active interface */
114 airpcap_if_info_t *airpcap_if_active = NULL;
116 /* WLAN preferences pointer */
117 module_t *wlan_prefs = NULL;
119 Dot11Channel *pSupportedChannels;
120 ULONG numSupportedChannels;
122 static AirpcapChannelInfo LegacyChannels[] =
140 static ULONG num_legacy_channels = 14;
143 * Callback used by the load_wlan_keys() routine in order to read a WEP decryption key
146 get_wep_key(pref_t *pref, gpointer ud _U_)
148 gchar *my_string = NULL;
149 keys_cb_data_t* user_data;
151 decryption_key_t* new_key;
153 /* Retrieve user data info */
154 user_data = (keys_cb_data_t*)ud;
156 if (g_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
158 my_string = g_strdup(*pref->varp.string);
160 /* Here we have the string describing the key... */
161 new_key = parse_key_string(my_string);
165 /* Key is added only if not null ... */
166 user_data->list = g_list_append(user_data->list,new_key);
167 user_data->number_of_keys++;
168 user_data->current_index++;
174 /* Returs TRUE if the WEP key is valid, false otherwise */
176 wep_key_is_valid(char* key)
178 GString *new_key_string;
184 new_key_string = g_string_new(key);
186 if( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
188 g_string_free(new_key_string,FALSE);
191 if((new_key_string->len % 2) != 0)
193 g_string_free(new_key_string,FALSE);
196 for(i = 0; i < new_key_string->len; i++)
198 if(!g_ascii_isxdigit(new_key_string->str[i]))
200 g_string_free(new_key_string,FALSE);
205 g_string_free(new_key_string,FALSE);
209 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
211 set_wep_key(pref_t *pref, gpointer ud _U_)
213 gchar *my_string = NULL;
214 keys_cb_data_t* user_data;
215 gint wep_key_number = 0;
217 decryption_key_t* new_key;
219 /* Retrieve user data info */
220 user_data = (keys_cb_data_t*)ud;
222 if (g_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
224 /* Ok, the pref we're gonna set is a wep_key ... but what number? */
225 sscanf(pref->name,"wep_key%d",&wep_key_number);
227 if(user_data->current_index < user_data->number_of_keys)
229 if(wep_key_number == (user_data->current_index+1))
231 /* Retrieve the nth decryption_key_t structure pointer */
232 new_key = (decryption_key_t*)g_list_nth_data(user_data->list,user_data->current_index);
234 /* Free the old key string */
235 g_free((void *)*pref->varp.string);
237 /* Create the new string describing the decryption key */
238 my_string = get_key_string(new_key);
240 /* Duplicate the string, and assign it to the variable pointer */
241 *pref->varp.string = (void *)g_strdup(my_string);
243 /* Free the previously allocated string */
247 else /* If the number of keys has been reduced somehow, we need to delete all the other keys
248 * (remember that the new ones have been probably overwritten)
251 g_free((void *)*pref->varp.string);
252 *pref->varp.string = (void *)g_strdup(""); /* Do not just free memory!!! Put an 'empty' string! */
254 user_data->current_index++;
261 * Function used to read the Decryption Keys from the preferences and store them
262 * properly into the airpcap adapter.
265 load_wlan_driver_wep_keys()
267 keys_cb_data_t* user_data;
271 /* Retrieve the wlan preferences */
272 wlan_prefs = prefs_find_module("wlan");
274 /* Allocate a structure used to keep infos between the callbacks */
275 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
277 /* Fill the structure */
278 user_data->list = NULL;
279 user_data->current_index = 0;
280 user_data->number_of_keys= 0; /* Still unknown */
282 /* Run the callback on each 802.11 preference */
283 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
285 /* Now the key list should be filled */
288 * Signal that we've changed things, and run the 802.11 dissector's
291 wlan_prefs->prefs_changed = TRUE;
293 prefs_apply(wlan_prefs);
295 write_wlan_driver_wep_keys_to_registry(user_data->list);
298 /* free the WEP key string */
299 for(i=0;i<g_list_length(user_data->list);i++)
301 g_free(g_list_nth(user_data->list,i)->data);
304 /* free the (empty) list */
305 g_list_free(user_data->list);
307 /* free the user_data structure */
310 /* airpcap_if_info_free(fake_info_if); */
316 * This function will tell the airpcap driver the key list to use
317 * This will be stored into the registry...
320 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
325 PAirpcapKeysCollection KeysCollection;
326 ULONG KeysCollectionSize;
328 UINT keys_in_list = 0;
329 decryption_key_t* key_item = NULL;
331 keys_in_list = g_list_length(key_list);
334 * Save the encryption keys, if we have any of them
336 KeysCollectionSize = 0;
339 * Calculate the size of the keys collection
341 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
344 * Allocate the collection
346 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
353 * Populate the key collection
355 KeysCollection->nKeys = keys_in_list;
357 for(i = 0; i < keys_in_list; i++)
359 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
361 /* Retrieve the Item corresponding to the i-th key */
362 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
363 new_key = g_string_new(key_item->key->str);
365 KeysCollection->Keys[i].KeyLen = new_key->len / 2;
366 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
368 for(j = 0 ; j < new_key->len; j += 2)
370 s[0] = new_key->str[j];
371 s[1] = new_key->str[j+1];
373 KeyByte = (UCHAR)strtol(s, NULL, 16);
374 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
377 g_string_free(new_key,TRUE);
381 * Free the old adapter key collection!
383 if(info_if->keysCollection != NULL)
384 g_free(info_if->keysCollection);
387 * Set this collection ad the new one
389 info_if->keysCollection = KeysCollection;
390 info_if->keysCollectionSize = KeysCollectionSize;
393 * Configuration must be saved
395 info_if->saved = FALSE;
398 * Write down the changes to the registry
400 airpcap_save_selected_if_configuration(info_if);
406 * This function will tell the airpcap driver the key list to use
407 * This will be stored into the registry...
410 write_wlan_driver_wep_keys_to_registry(GList* key_list)
415 PAirpcapKeysCollection KeysCollection;
416 ULONG KeysCollectionSize;
418 UINT keys_in_list = 0;
419 decryption_key_t* key_item = NULL;
420 airpcap_if_info_t* fake_info_if = NULL;
422 /* Create the fake_info_if from the first adapter of the list */
423 fake_info_if = airpcap_driver_fake_if_info_new();
425 if(fake_info_if == NULL)
429 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
430 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
432 n = g_list_length(key_list);
433 for(k = 0; k < n; k++ )
434 if(((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
438 * Save the encryption keys, if we have any of them
440 KeysCollectionSize = 0;
443 * Calculate the size of the keys collection
445 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
448 * Allocate the collection
450 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
457 * Populate the key collection
459 KeysCollection->nKeys = keys_in_list;
462 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
463 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
464 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
467 y = 0; /* Current position in the key list */
469 for(i = 0; i < n; i++)
471 /* Retrieve the Item corresponding to the i-th key */
472 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
475 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supportd right now!
476 * We will have to modify the AirpcapKey structure in order to
477 * support the other two types! What happens now, is that simply the
478 * not supported keys will just be discarded (they will be saved in wireshark though)
480 if(key_item->type == AIRPDCAP_KEY_TYPE_WEP)
482 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
484 new_key = g_string_new(key_item->key->str);
486 KeysCollection->Keys[y].KeyLen = new_key->len / 2;
487 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
489 for(j = 0 ; j < new_key->len; j += 2)
491 s[0] = new_key->str[j];
492 s[1] = new_key->str[j+1];
494 KeyByte = (UCHAR)strtol(s, NULL, 16);
495 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
497 /* XXX - Change when WPA will be supported!!! */
499 g_string_free(new_key,TRUE);
501 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
503 /* XXX - The driver cannot deal with this kind of key yet... */
505 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
507 /* XXX - The driver cannot deal with this kind of key yet... */
512 * Free the old adapter key collection!
514 if(fake_info_if->keysCollection != NULL)
515 g_free(fake_info_if->keysCollection);
518 * Set this collection ad the new one
520 fake_info_if->keysCollection = KeysCollection;
521 fake_info_if->keysCollectionSize = KeysCollectionSize;
524 * Configuration must be saved
526 fake_info_if->saved = FALSE;
529 * Write down the changes to the registry
531 airpcap_save_driver_if_configuration(fake_info_if);
533 airpcap_if_info_free(fake_info_if);
539 * Function used to save to the preference file the Decryption Keys.
542 save_wlan_driver_wep_keys()
544 GList* key_list = NULL;
545 char* tmp_key = NULL;
546 guint keys_in_list,i;
547 keys_cb_data_t* user_data;
548 airpcap_if_info_t* fake_info_if = NULL;
550 /* Create the fake_info_if from the first adapter of the list */
551 fake_info_if = airpcap_driver_fake_if_info_new();
553 if(fake_info_if == NULL)
556 /* Retrieve the wlan preferences */
557 wlan_prefs = prefs_find_module("wlan");
559 /* Allocate a structure used to keep infos between the callbacks */
560 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
562 /* Number of keys in key list */
563 /* Number of keys in key list */
564 if(fake_info_if->keysCollectionSize != 0)
565 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
569 for(i=0; i<keys_in_list; i++)
571 /* Only if it is a WEP key... */
572 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
574 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
575 key_list = g_list_append(key_list,g_strdup(tmp_key));
580 /* Now we know the exact number of WEP keys in the list, so store it ... */
581 keys_in_list = g_list_length(key_list);
583 /* Fill the structure */
584 user_data->list = key_list;
585 user_data->current_index = 0;
586 user_data->number_of_keys= keys_in_list;
588 /* Retrieve the wlan preferences */
589 wlan_prefs = prefs_find_module("wlan");
591 /* Run the callback on each 802.11 preference */
592 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
594 /* Signal that we've changed things, and run the 802.11 dissector's
596 wlan_prefs->prefs_changed = TRUE;
598 /* Apply changes for the specified preference */
599 prefs_apply(wlan_prefs);
602 /* free the WEP key string */
603 for(i=0;i<g_list_length(user_data->list);i++)
605 g_free(g_list_nth(user_data->list,i)->data);
608 /* free the (empty) list */
609 g_list_free(user_data->list);
611 /* free the user_data structure */
614 airpcap_if_info_free(fake_info_if);
620 * Function used to save to the preference file the Decryption Keys.
623 save_wlan_wireshark_wep_keys(GList* key_ls)
625 GList* key_list = NULL;
626 char* tmp_key = NULL;
627 guint keys_in_list,i;
628 keys_cb_data_t* user_data;
629 airpcap_if_info_t* fake_info_if = NULL;
630 decryption_key_t* tmp_dk;
632 /* Retrieve the wlan preferences */
633 wlan_prefs = prefs_find_module("wlan");
635 /* Allocate a structure used to keep infos between the callbacks */
636 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
638 keys_in_list = g_list_length(key_ls);
642 /* Fill the structure */
643 user_data->list = key_list;
644 user_data->current_index = 0;
645 user_data->number_of_keys= keys_in_list;
647 /* Retrieve the wlan preferences */
648 wlan_prefs = prefs_find_module("wlan");
650 /* Run the callback on each 802.11 preference */
651 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
653 /* Signal that we've changed things, and run the 802.11 dissector's
655 wlan_prefs->prefs_changed = TRUE;
657 /* Apply changes for the specified preference */
658 prefs_apply(wlan_prefs);
661 /* free the WEP key string */
662 for(i=0;i<g_list_length(user_data->list);i++)
664 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
665 g_string_free(tmp_dk->key,TRUE);
666 if(tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
669 /* free the (empty) list */
670 g_list_free(user_data->list);
672 /* free the user_data structure */
679 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
680 * "get_airpcap_interface_list()".
683 cant_get_airpcap_if_list_error_message(const char *err_str)
685 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
689 * Airpcap wrapper, used to store the current settings for the selected adapter
692 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
694 if (!AirpcapLoaded) return FALSE;
695 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
699 * Airpcap wrapper, used to open an airpcap adapter
702 airpcap_if_open(PCHAR name, PCHAR err)
704 if (!AirpcapLoaded) return NULL;
705 if (name == NULL) return NULL;
706 return g_PAirpcapOpen(name,err);
710 * Airpcap wrapper, used to close an airpcap adapter
713 airpcap_if_close(PAirpcapHandle handle)
715 if (!AirpcapLoaded) return;
716 g_PAirpcapClose(handle);
720 * Retrieve the state of the Airpcap DLL
723 airpcap_get_dll_state()
725 return AirpcapVersion;
729 * Airpcap wrapper, used to turn on the led of an airpcap adapter
732 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber)
734 if (!AirpcapLoaded) return FALSE;
735 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
739 * Airpcap wrapper, used to turn off the led of an airpcap adapter
742 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber)
744 if (!AirpcapLoaded) return FALSE;
745 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
749 * Airpcap wrapper, used to get the channel of an airpcap adapter
752 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch)
754 if (!AirpcapLoaded) return FALSE;
755 return g_PAirpcapGetDeviceChannel(ah,ch);
759 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
762 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, PULONG nInfo)
764 if (!AirpcapLoaded) return FALSE;
765 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
766 *nInfo = num_legacy_channels;
767 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
770 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
771 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
777 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
780 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels)
782 AirpcapChannelInfo *chanInfo;
783 ULONG i=0, j=0, numInfo = 0;
787 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
789 numSupportedChannels = 0;
792 * allocate a bigger array
797 pSupportedChannels = malloc(numInfo * (sizeof *pSupportedChannels));
799 for (i = 0; i < numInfo; i++)
801 ULONG supportedChannel = 0xFFFFFFFF;
804 * search if we have it already
806 for (j = 0; j < numSupportedChannels; j++)
808 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
810 supportedChannel = j;
815 if (supportedChannel == 0xFFFFFFFF)
818 * not found, create a new item
820 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
822 switch(chanInfo[i].ExtChannel)
825 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
828 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
832 pSupportedChannels[numSupportedChannels].Flags = 0;
836 * Gather channel information
839 pSupportedChannels[numSupportedChannels].Flags |=
840 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
841 FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
842 pSupportedChannels[numSupportedChannels].Channel =
843 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
844 numSupportedChannels++;
849 * just update the ext channel flags
851 switch(chanInfo[i].ExtChannel)
854 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
857 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
866 if (numSupportedChannels < 1)
869 * Now sort the list by frequency
871 for (i = 0 ; i < numSupportedChannels - 1; i++)
873 for (j = i + 1; j < numSupportedChannels; j++)
875 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
877 Dot11Channel temp = pSupportedChannels[i];
878 pSupportedChannels[i] = pSupportedChannels[j];
879 pSupportedChannels[j] = temp;
884 *pNumSupportedChannels = numSupportedChannels;
885 return pSupportedChannels;
889 * Airpcap wrapper, used to set the channel of an airpcap adapter
892 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch)
894 if (!AirpcapLoaded) return FALSE;
895 return g_PAirpcapSetDeviceChannel(ah,ch);
899 * Airpcap wrapper, used to set the frequency of an airpcap adapter
902 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
904 if (!AirpcapLoaded) return FALSE;
905 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
907 channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
912 return airpcap_if_set_device_channel(ah, channel);
914 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
915 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
922 * Airpcap wrapper, used to get the frequency of an airpcap adapter
925 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
927 if (!AirpcapLoaded) return FALSE;
929 pChannelInfo->Frequency = 0;
930 pChannelInfo->ExtChannel = 0;
931 pChannelInfo->Reserved[0] = 0;
932 pChannelInfo->Reserved[1] = 0;
933 pChannelInfo->Reserved[2] = 0;
935 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
939 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
941 chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
942 if (chan_freq == 0) return FALSE;
943 pChannelInfo->Frequency = chan_freq;
946 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
947 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
953 * Airpcap wrapper, used to get the link type of an airpcap adapter
956 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
958 if (!AirpcapLoaded) return FALSE;
959 return g_PAirpcapGetLinkType(ah,lt);
963 * Airpcap wrapper, used to set the link type of an airpcap adapter
966 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
968 if (!AirpcapLoaded) return FALSE;
969 return g_PAirpcapSetLinkType(ah,lt);
973 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
976 airpcap_if_get_fcs_presence(PAirpcapHandle ah, PBOOL fcs)
978 if (!AirpcapLoaded) return FALSE;
979 return g_PAirpcapGetFcsPresence(ah,fcs);
983 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
986 airpcap_if_set_fcs_presence(PAirpcapHandle ah, BOOL fcs)
988 if (!AirpcapLoaded) return FALSE;
989 return g_PAirpcapSetFcsPresence(ah,fcs);
993 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
996 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
998 if (!AirpcapLoaded) return FALSE;
999 return g_PAirpcapGetDecryptionState(ah,PEnable);
1003 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1006 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1008 if (!AirpcapLoaded) return FALSE;
1009 return g_PAirpcapSetDecryptionState(ah,Enable);
1013 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1016 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1018 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1019 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1023 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1026 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1028 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1029 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1033 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1036 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1038 if (!AirpcapLoaded) return FALSE;
1039 return g_PAirpcapGetFcsValidation(ah,val);
1043 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1046 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1048 if (!AirpcapLoaded) return FALSE;
1049 return g_PAirpcapSetFcsValidation(ah,val);
1053 * Airpcap wrapper, used to save the settings for the selected_if
1056 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1058 if (!AirpcapLoaded) return FALSE;
1059 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1063 * Airpcap wrapper, used to save the settings for the selected_if
1066 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize)
1068 if (!AirpcapLoaded) return FALSE;
1069 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1073 * Airpcap wrapper, used to save the driver's set of keys
1076 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1078 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1079 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1083 * Airpcap wrapper, used to load the driver's set of keys
1086 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize)
1088 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1089 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1093 * This function will create a new airpcap_if_info_t using a name and a description
1096 airpcap_if_info_new(char *name, char *description)
1099 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1101 airpcap_if_info_t *if_info = NULL;
1103 /* Probably I have to switch on the leds!!! */
1104 ad = airpcap_if_open(name, ebuf);
1107 if_info = g_malloc(sizeof (airpcap_if_info_t));
1108 if_info->name = g_strdup(name);
1109 if (description == NULL){
1110 if_info->description = NULL;
1112 if_info->description = g_strdup(description);
1115 if_info->ip_addr = NULL;
1116 if_info->loopback = FALSE;
1117 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1118 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1119 airpcap_if_get_link_type(ad,&(if_info->linkType));
1120 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1121 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1122 airpcap_if_turn_led_on(ad, 0);
1123 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1124 if_info->led = TRUE;
1125 if_info->blinking = FALSE;
1126 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1128 /* get the keys, if everything is ok, close the adapter */
1129 if(airpcap_if_load_keys(ad,if_info))
1131 airpcap_if_close(ad);
1138 * This function will create a new fake drivers' interface, to load global keys...
1141 airpcap_driver_fake_if_info_new()
1144 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1146 airpcap_if_info_t *if_info = NULL;
1147 airpcap_if_info_t *fake_if_info = NULL;
1149 /* Maybe for some reason no airpcap adapter is found */
1150 if(airpcap_if_list == NULL)
1154 * Retrieve the first AirPcap adapter available. If no interface is found,
1155 * it is not possible to retrieve the driver's settings, so return NULL.
1157 if_info = g_list_nth_data(airpcap_if_list,0);
1161 /* Open the 'fake' adapter */
1162 ad = airpcap_if_open(if_info->name, ebuf);
1165 fake_if_info = g_malloc(sizeof (airpcap_if_info_t));
1166 fake_if_info->name = g_strdup(if_info->name);
1167 fake_if_info->description = g_strdup(if_info->description);
1168 fake_if_info->loopback = FALSE;
1169 fake_if_info->ip_addr = NULL;
1170 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1171 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1172 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1173 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1174 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1175 airpcap_if_turn_led_on(ad, 0);
1176 fake_if_info->led = TRUE;
1177 fake_if_info->blinking = FALSE;
1178 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1180 /* get the keys, if everything is ok, close the adapter */
1181 if(airpcap_if_load_driver_keys(ad,fake_if_info))
1183 airpcap_if_close(ad);
1187 return fake_if_info;
1191 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1194 airpcap_if_info_print(airpcap_if_info_t* if_info)
1199 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1203 g_print("\n----------------- AirPcap Interface \n");
1204 g_print(" NAME: %s\n",if_info->name);
1205 g_print(" DESCRIPTION: %s\n",if_info->description);
1206 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1207 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1208 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1209 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1210 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1211 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1212 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1213 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1214 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1215 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1216 g_print(" LINKTYPE: %d\n",if_info->linkType);
1217 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1218 g_print(" (GTK) TAG: %d\n",if_info->tag);
1219 g_print("SUPPORTED CHANNELS POINTER: %lu\n",if_info->pSupportedChannels);
1220 g_print(" NUM SUPPORTED CHANNELS: %lu\n",if_info->numSupportedChannels);
1222 for(i=0; i<(if_info->numSupportedChannels); i++){
1223 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1224 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1225 g_print(" FREQUENCY: %lu\n",if_info->pSupportedChannels[i].Frequency);
1226 g_print(" FLAGS: %lu\n",if_info->pSupportedChannels[i].Flags);
1232 * Function used to load the WEP keys for a selected interface
1235 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1237 if(!if_info) return FALSE;
1239 if_info->keysCollectionSize = 0;
1240 if_info->keysCollection = NULL;
1242 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1244 if(if_info->keysCollectionSize == 0)
1246 if_info->keysCollection = NULL;
1247 airpcap_if_close(ad);
1251 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1252 if(!if_info->keysCollection)
1254 if_info->keysCollectionSize = 0;
1255 if_info->keysCollection = NULL;
1256 airpcap_if_close(ad);
1260 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1264 airpcap_if_close(ad);
1269 * Function used to load the WEP keys for a selected interface
1272 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1274 if_info->keysCollectionSize = 0;
1275 if_info->keysCollection = NULL;
1277 if(!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1279 if(if_info->keysCollectionSize == 0)
1281 if_info->keysCollection = NULL;
1282 airpcap_if_close(ad);
1286 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1287 if(!if_info->keysCollection)
1289 if_info->keysCollectionSize = 0;
1290 if_info->keysCollection = NULL;
1291 airpcap_if_close(ad);
1295 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1299 airpcap_if_close(ad);
1304 * Function used to save the WEP keys for a selected interface
1307 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1309 if(!if_info || !AirpcapLoaded) return;
1311 if(if_info->keysCollection != NULL)
1312 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1316 * Function used to save the WEP keys for a selected interface
1319 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1321 if(if_info->keysCollection != NULL)
1322 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1326 * Callback used to free an instance of airpcap_if_info_t
1329 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1331 airpcap_if_info_t *if_info = data;
1333 if (if_info->name != NULL)
1334 g_free(if_info->name);
1336 if (if_info->description != NULL)
1337 g_free(if_info->description);
1339 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1340 if(if_info->keysCollection != NULL)
1342 g_free(if_info->keysCollection);
1343 if_info->keysCollection = NULL;
1346 if(if_info->ip_addr != NULL)
1347 g_slist_free(if_info->ip_addr);
1354 * Function used to free the airpcap interface list
1357 free_airpcap_interface_list(GList *if_list)
1359 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1360 g_list_free(if_list);
1365 * This function will use the airpcap.dll to find all the airpcap devices.
1366 * Will return null if no device is found.
1369 get_airpcap_interface_list(int *err, char **err_str)
1372 airpcap_if_info_t *if_info;
1374 AirpcapDeviceDescription *devsList, *adListEntry;
1375 char errbuf[PCAP_ERRBUF_SIZE];
1379 *err = AIRPCAP_NOT_LOADED;
1383 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1385 /* No interfaces, return il = NULL; */
1386 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1387 if (err_str != NULL)
1388 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1393 * Count the adapters
1395 adListEntry = devsList;
1400 adListEntry = adListEntry->next;
1405 /* No interfaces, return il= NULL */
1406 g_PAirpcapFreeDeviceList(devsList);
1407 *err = NO_AIRPCAP_INTERFACES_FOUND;
1408 if (err_str != NULL)
1414 * Insert the adapters in our list
1416 adListEntry = devsList;
1417 for(i = 0; i < n_adapts; i++)
1419 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1420 if (if_info != NULL){
1421 il = g_list_append(il, if_info);
1424 adListEntry = adListEntry->next;
1427 g_PAirpcapFreeDeviceList(devsList);
1434 * Used to retrieve the interface given the name
1435 * (the name is used in AirpcapOpen)
1437 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
1441 airpcap_if_info_t* if_info;
1446 while( ifn < g_list_length(if_list) )
1448 curr = g_list_nth(if_list, ifn);
1452 if_info = curr->data;
1455 if ( g_ascii_strcasecmp(if_info->name,name) == 0)
1467 * Returns the ASCII string of a key given the key bytes
1470 airpcap_get_key_string(AirpcapKey key)
1479 if(key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1483 /* Allocate the string used to store the ASCII representation of the WEP key */
1484 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1485 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1488 for(j = 0; j < key.KeyLen; j++)
1490 src = g_strdup_printf("%.2x\0", key.KeyData[j]);
1492 * XXX - use g_strconcat() or GStrings instead ???
1494 l = g_strlcat(dst,src,WEP_KEY_MAX_CHAR_SIZE+1);
1499 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1501 /* XXX - Add code here */
1503 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1505 /* XXX - Add code here */
1509 /* XXX - Add code here */
1516 * Clear keys and decryption status for the specified interface
1519 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1523 if(info_if->keysCollection != NULL)
1525 g_free(info_if->keysCollection);
1526 info_if->keysCollection = NULL;
1529 info_if->keysCollectionSize = 0;
1531 info_if->DecryptionOn = FALSE;
1532 info_if->saved = FALSE;
1537 * Used to retrieve the two chars string from interface
1540 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1546 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1548 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1549 * Otherwise, check if it is the "Any" adapter...
1553 if(g_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1554 number = g_strdup_printf("??");
1556 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1560 number = g_strdup_printf("%.2u\0",n);
1567 * Used to retrieve the two chars string from interface
1570 airpcap_get_if_string_number_from_description(gchar* description)
1575 number = (gchar*)g_malloc(sizeof(gchar)*3);
1577 pointer = g_strrstr(description,"#\0");
1579 number[0] = *(pointer+1);
1580 number[1] = *(pointer+2);
1587 * Returns the default airpcap interface of a list, NULL if list is empty
1590 airpcap_get_default_if(GList* airpcap_if_list)
1593 GList* popdown_if_list = NULL;
1597 airpcap_if_info_t* if_info = NULL;
1599 if(prefs.capture_device != NULL)
1601 s = g_strdup(get_if_name(prefs.capture_device));
1602 if_info = get_airpcap_if_from_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
1609 * Load the configuration for the specified interface
1612 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1614 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1619 ad = airpcap_if_open(if_info->name, ebuf);
1623 /* Stop blinking (if it was blinkig!)*/
1624 if(if_info->blinking)
1626 /* Turn on the light (if it was off) */
1627 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1630 /* Apply settings... */
1631 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1632 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1633 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1634 airpcap_if_get_link_type(ad,&(if_info->linkType));
1635 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1636 /* get the keys, if everything is ok, close the adapter */
1637 if(airpcap_if_load_keys(ad,if_info))
1638 airpcap_if_close(ad);
1640 if_info->saved = TRUE;
1644 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1650 * Save the configuration for the specified interface
1653 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1655 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1660 ad = airpcap_if_open(if_info->name, ebuf);
1664 /* Stop blinking (if it was blinkig!)*/
1665 if(if_info->blinking)
1667 /* Turn on the light (if it was off) */
1668 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1671 /* Apply settings... */
1672 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1673 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1674 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1675 airpcap_if_set_link_type(ad,if_info->linkType);
1676 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1677 airpcap_if_save_keys(ad,if_info);
1679 /* ... and save them */
1680 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1682 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.");
1683 if_info->saved = FALSE;
1684 airpcap_if_close(ad);
1688 if_info->saved = TRUE;
1689 airpcap_if_close(ad);
1693 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1699 * Save the configuration for the specified interface
1702 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1704 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1707 if(fake_if_info != NULL)
1709 ad = airpcap_if_open(fake_if_info->name, ebuf);
1713 /* Apply decryption settings... */
1714 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1715 airpcap_if_save_driver_keys(ad,fake_if_info);
1716 airpcap_if_close(ad);
1720 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1728 * DECRYPTION KEYS FUNCTIONS
1731 * This function is used for DEBUG POURPOSES ONLY!!!
1734 print_key_list(GList* key_list)
1737 decryption_key_t* tmp;
1739 if(key_list == NULL)
1741 g_print("\n\n******* KEY LIST NULL *******\n\n");
1745 n = g_list_length(key_list);
1747 g_print("\n\n********* KEY LIST **********\n\n");
1749 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1751 for(i =0; i < n; i++)
1753 g_print("[%d] :\n",i+1);
1754 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1755 g_print("KEY : %s\n",tmp->key->str);
1757 g_print("BITS: %d\n",tmp->bits);
1759 if(tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1760 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1761 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1762 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1763 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1764 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1766 g_print("TYPE: %s\n","???");
1768 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1769 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1773 g_print("\n*****************************\n\n");
1777 * Retrieves a GList of decryption_key_t structures containing infos about the
1778 * keys for the given adapter... returns NULL if no keys are found.
1781 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1784 char* tmp_key = NULL;
1785 guint i,keys_in_list = 0;
1788 decryption_key_t *new_key = NULL;
1789 GList *key_list = NULL;
1791 /* Number of keys in key list */
1792 if(info_if->keysCollectionSize != 0)
1793 keys_in_list = (guint)(info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1797 for(i=0; i<keys_in_list; i++)
1799 /* Different things to do depending on the key type */
1800 if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1802 /* allocate memory for the new key item */
1803 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1805 /* fill the fields */
1807 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1808 new_key->key = g_string_new(tmp_key);
1812 new_key->bits = new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an exadecimal number) */
1814 /* SSID not used in WEP keys */
1815 new_key->ssid = NULL;
1817 /* TYPE (WEP in this case) */
1818 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1820 /* Append the new element in the list */
1821 key_list = g_list_append(key_list,(gpointer)new_key);
1823 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1825 /* XXX - Not supported yet */
1827 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1829 /* XXX - Not supported yet */
1837 * Retrieves a GList of decryption_key_t structures containing infos about the
1838 * keys for the global AirPcap driver... returns NULL if no keys are found.
1841 get_airpcap_driver_keys()
1844 char* tmp_key = NULL;
1845 guint i,keys_in_list = 0;
1848 decryption_key_t *new_key = NULL;
1849 GList *key_list = NULL;
1852 * To read the drivers general settings we need to create and use one airpcap adapter...
1853 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1855 airpcap_if_info_t* fake_info_if = NULL;
1857 /* Create the fake_info_if from the first adapter of the list */
1858 fake_info_if = airpcap_driver_fake_if_info_new();
1860 if(fake_info_if == NULL)
1863 /* Number of keys in key list */
1864 if(fake_info_if->keysCollectionSize != 0)
1865 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1869 for(i=0; i<keys_in_list; i++)
1871 /* Different things to do depending on the key type */
1872 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1874 /* allocate memory for the new key item */
1875 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1877 /* fill the fields */
1879 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1880 new_key->key = g_string_new(tmp_key);
1881 if(tmp_key != NULL) g_free(tmp_key);
1884 new_key->bits = new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an exadecimal number) */
1886 /* SSID not used in WEP keys */
1887 new_key->ssid = NULL;
1889 /* TYPE (WEP in this case) */
1890 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
1892 /* Append the new element in the list */
1893 key_list = g_list_append(key_list,(gpointer)new_key);
1895 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1897 /* XXX - Not supported yet */
1899 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1901 /* XXX - Not supported yet */
1905 airpcap_if_info_free(fake_info_if);
1911 * Returns the list of the decryption keys specified for wireshark, NULL if
1915 get_wireshark_keys()
1917 keys_cb_data_t* wep_user_data = NULL;
1921 GList* final_list = NULL;
1922 GList* wep_final_list = NULL;
1924 /* Retrieve the wlan preferences */
1925 wlan_prefs = prefs_find_module("wlan");
1927 /* Allocate a structure used to keep infos between the callbacks */
1928 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1930 /* Fill the structure */
1931 wep_user_data->list = NULL;
1932 wep_user_data->current_index = 0;
1933 wep_user_data->number_of_keys= 0; /* Still unknown */
1935 /* Run the callback on each 802.11 preference */
1936 /* XXX - Right now, only WEP keys will be loaded */
1937 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1939 /* Copy the list field in the user data structure pointer into the final_list */
1940 if(wep_user_data != NULL) wep_final_list = wep_user_data->list;
1942 /* XXX - Merge the three lists!!!!! */
1943 final_list = wep_final_list;
1945 /* free the wep_user_data structure */
1946 g_free(wep_user_data);
1952 * Merges two lists of keys and return a newly created GList. If a key is
1953 * found multiple times, it will just appear once!
1954 * list1 and list 2 pointer will have to be freed manually if needed!!!
1955 * If the total number of keys exceeeds the maximum number allowed,
1956 * exceeding keys will be discarded...
1959 merge_key_list(GList* list1, GList* list2)
1963 decryption_key_t *dk1=NULL,
1967 GList* merged_list = NULL;
1969 if( (list1 == NULL) && (list2 == NULL) )
1975 n2 = g_list_length(list2);
1979 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1980 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1982 new_dk->bits = dk2->bits;
1983 new_dk->type = dk2->type;
1984 new_dk->key = g_string_new(dk2->key->str);
1985 new_dk->ssid = byte_array_dup(dk2->ssid);
1987 /* Check the total length of the merged list */
1988 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1989 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1992 else if(list2 == NULL)
1994 n1 = g_list_length(list1);
1999 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2000 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
2002 new_dk->bits = dk1->bits;
2003 new_dk->type = dk1->type;
2004 new_dk->key = g_string_new(dk1->key->str);
2005 new_dk->ssid = byte_array_dup(dk1->ssid);
2007 /* Check the total length of the merged list */
2008 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2009 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2014 n1 = g_list_length(list1);
2015 n2 = g_list_length(list2);
2017 /* Copy the whole list1 into merged_list */
2020 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2021 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2023 new_dk->bits = dk1->bits;
2024 new_dk->type = dk1->type;
2025 new_dk->key = g_string_new(dk1->key->str);
2026 new_dk->ssid = byte_array_dup(dk1->ssid);
2028 /* Check the total length of the merged list */
2029 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2030 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2033 /* Look for keys that are present in list2 but aren't in list1 yet...
2034 * Add them to merged_list
2038 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2040 if(!key_is_in_list(dk2,merged_list))
2042 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2044 new_dk->bits = dk2->bits;
2045 new_dk->type = dk2->type;
2046 new_dk->key = g_string_new(dk2->key->str);
2047 new_dk->ssid = byte_array_dup(dk2->ssid);
2049 /* Check the total length of the merged list */
2050 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2051 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2060 * Use this function to free a key list.
2063 free_key_list(GList *list)
2066 decryption_key_t *curr_key;
2071 n = g_list_length(list);
2073 for(i = 0; i < n; i++)
2075 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2077 /* Free all the strings */
2078 if(curr_key->key != NULL)
2079 g_string_free(curr_key->key, TRUE);
2081 if(curr_key->ssid != NULL)
2082 g_byte_array_free(curr_key->ssid, TRUE);
2084 /* free the decryption_key_t structure*/
2097 * If the given key is contained in the list, returns TRUE.
2098 * Returns FALSE otherwise.
2101 key_is_in_list(decryption_key_t *dk,GList *list)
2104 decryption_key_t* curr_key = NULL;
2105 gboolean found = FALSE;
2107 if( (list == NULL) || (dk == NULL) )
2110 n = g_list_length(list);
2115 for(i = 0; i < n; i++)
2117 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2118 if(keys_are_equals(dk,curr_key))
2126 * Returns TRUE if keys are equals, FALSE otherwise
2129 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2132 if((k1==NULL) || (k2==NULL))
2135 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2136 /** 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) ) **/
2137 /** return TRUE; **/
2139 if( g_string_equal(k1->key,k2->key) &&
2140 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2141 k1->type == k2->type)
2143 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2144 if((k1->ssid == NULL) && (k2->ssid == NULL))
2147 /* If they are not null, they must share the same ssid */
2148 return byte_array_equal(k1->ssid,k2->ssid);
2151 /* Some field is not equal ... */
2156 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2157 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2161 key_lists_are_equal(GList* list1, GList* list2)
2165 guint wep_n1=0,wep_n2=0;
2166 GList *wep_list1=NULL;
2167 GList *wep_list2=NULL;
2170 decryption_key_t *dk1=NULL,*dk2=NULL;
2172 n1 = g_list_length(list1);
2173 n2 = g_list_length(list2);
2176 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2177 * is not implemented.
2181 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2182 if(dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2184 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2190 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2191 if(dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2193 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2199 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2204 * Commented, because in the new AirPcap version all the keys will be saved
2205 * into the driver, and all the keys for every specific adapter will be
2206 * removed. This means that this check will always fail... and the user will
2207 * always be asked what to do... and it doesn't make much sense.
2209 /* if(n1 != n2) return FALSE; */
2210 if(wep_n1 != wep_n2) return FALSE;
2217 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2218 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2220 if(!g_string_equal(dk1->key,dk2->key)) return FALSE;
2224 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2225 if(!key_is_in_list(dk2,wep_list1)) return FALSE;
2232 test_if_on(pref_t *pref, gpointer ud _U_)
2237 /* Retrieve user data info */
2238 is_on = (gboolean*)ud;
2241 if (g_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2243 number = *pref->varp.boolp;
2245 if(number) *is_on = TRUE;
2246 else *is_on = FALSE;
2254 * Returns TRUE if the Wireshark decryption is active, false otherwise
2257 wireshark_decryption_on()
2261 /* Retrieve the wlan preferences */
2262 wlan_prefs = prefs_find_module("wlan");
2264 /* Run the callback on each 802.11 preference */
2265 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2271 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2274 airpcap_decryption_on()
2276 gboolean is_on = FALSE;
2278 airpcap_if_info_t* fake_if_info = NULL;
2280 fake_if_info = airpcap_driver_fake_if_info_new();
2282 if(fake_if_info != NULL)
2284 if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2286 else if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2290 airpcap_if_info_free(fake_if_info);
2296 * Free an instance of airpcap_if_info_t
2299 airpcap_if_info_free(airpcap_if_info_t *if_info)
2303 if (if_info->name != NULL)
2304 g_free(if_info->name);
2306 if (if_info->description != NULL)
2307 g_free(if_info->description);
2309 if(if_info->keysCollection != NULL)
2311 g_free(if_info->keysCollection);
2312 if_info->keysCollection = NULL;
2315 if(if_info->ip_addr != NULL)
2317 g_slist_free(if_info->ip_addr);
2318 if_info->ip_addr = NULL;
2330 set_on_off(pref_t *pref, gpointer ud _U_)
2335 /* Retrieve user data info */
2336 is_on = (gboolean*)ud;
2338 if (g_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2340 number = *pref->varp.boolp;
2342 g_free((void *)*pref->varp.boolp);
2344 *pref->varp.boolp = TRUE;
2346 *pref->varp.boolp = FALSE;
2354 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2357 set_wireshark_decryption(gboolean on_off)
2363 /* Retrieve the wlan preferences */
2364 wlan_prefs = prefs_find_module("wlan");
2366 /* Run the callback on each 802.11 preference */
2367 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2370 * Signal that we've changed things, and run the 802.11 dissector's
2373 wlan_prefs->prefs_changed = TRUE;
2375 prefs_apply(wlan_prefs);
2379 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2382 set_airpcap_decryption(gboolean on_off)
2384 /* We need to directly access the .dll functions here... */
2385 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2386 PAirpcapHandle ad,ad_driver;
2388 gboolean success = TRUE;
2392 airpcap_if_info_t* curr_if = NULL;
2393 airpcap_if_info_t* fake_if_info = NULL;
2395 fake_if_info = airpcap_driver_fake_if_info_new();
2397 if(fake_if_info == NULL)
2398 /* We apparently don't have any adapters installed.
2399 * This isn't a failure, so return TRUE
2403 /* Set the driver decryption */
2404 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2408 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2410 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2412 airpcap_if_close(ad_driver);
2415 airpcap_if_info_free(fake_if_info);
2417 n = g_list_length(airpcap_if_list);
2419 /* Set to FALSE the decryption for all the adapters */
2420 /* Apply this change to all the adapters !!! */
2421 for(i = 0; i < n; i++)
2423 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2425 if( curr_if != NULL )
2427 ad = airpcap_if_open(curr_if->name, ebuf);
2430 curr_if->DecryptionOn = (gboolean)AIRPCAP_DECRYPTION_OFF;
2431 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2432 /* Save configuration for the curr_if */
2433 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
2437 airpcap_if_close(ad);
2446 /* DYNAMIC LIBRARY LOADER */
2448 * Used to dynamically load the airpcap library in order link it only when
2449 * it's present on the system
2451 int load_airpcap(void)
2453 BOOL base_functions = TRUE;
2454 BOOL eleven_n_functions = TRUE;
2456 if((AirpcapLib = LoadLibrary(TEXT("airpcap.dll"))) == NULL)
2458 /* Report the error but go on */
2459 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2460 return AirpcapVersion;
2464 if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2465 if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2466 if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2467 if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2468 if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2469 if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2470 if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2471 if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2472 if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2473 if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2474 if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2475 if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2476 if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2477 if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2478 if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2479 if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2480 if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2481 if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2482 if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2483 if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2484 if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2485 if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2486 if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2487 if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2488 if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2489 if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2490 if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2491 if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2492 if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2493 if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2494 if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2495 if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2497 /* TEST IF AIRPCAP SUPPORTS 11N */
2498 if((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2499 if((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2500 if((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2502 if(base_functions && eleven_n_functions){
2503 AirpcapLoaded = TRUE;
2504 AirpcapVersion = AIRPCAP_DLL_OK;
2505 }else if(base_functions){
2506 AirpcapLoaded = TRUE;
2507 AirpcapVersion = AIRPCAP_DLL_OLD;
2508 return AIRPCAP_DLL_OK;
2510 AirpcapLoaded = FALSE;
2511 AirpcapVersion = AIRPCAP_DLL_ERROR;
2514 return AirpcapVersion;
2518 * Append the version of AirPcap with which we were compiled to a GString.
2521 get_compiled_airpcap_version(GString *str)
2523 g_string_append(str, "with AirPcap");
2527 * Append the version of AirPcap with which we we're running to a GString.
2530 get_runtime_airpcap_version(GString *str)
2532 guint vmaj, vmin, vrev, build;
2534 /* See if the DLL has been loaded successfully. Bail if it hasn't */
2535 if (AirpcapLoaded == FALSE) {
2536 g_string_append(str, "without AirPcap");
2540 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
2541 g_string_sprintfa(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2544 #endif /* HAVE_AIRPCAP */