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.
42 #include <epan/packet.h>
43 #include <epan/prefs.h>
44 #include <epan/prefs-int.h>
45 #include <epan/crypt/wep-wpadefs.h>
46 #include <epan/crypt/airpdcap_ws.h>
47 #include <epan/strutil.h>
48 #include <epan/frequency-utils.h>
49 #include "capture_ui_utils.h"
51 #include "simple_dialog.h"
54 #include "airpcap_loader.h"
58 * Set to TRUE if the DLL was successfully loaded AND all functions
61 static gboolean AirpcapLoaded = FALSE;
65 * We load dynamically the dag library in order link it only when
66 * it's present on the system
68 static void * AirpcapLib = NULL;
70 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
71 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
72 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
73 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
74 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
75 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
76 static AirpcapReadHandler g_PAirpcapRead;
77 static AirpcapGetStatsHandler g_PAirpcapGetStats;
80 static int AirpcapVersion = 3;
82 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
83 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
84 static AirpcapOpenHandler g_PAirpcapOpen;
85 static AirpcapCloseHandler g_PAirpcapClose;
86 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
87 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
88 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
89 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
90 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
91 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
92 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
93 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
94 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
95 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
96 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
97 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
98 static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys;
99 static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys;
100 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
101 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
102 static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState;
103 static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState;
104 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
105 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
106 static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx;
107 static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx;
108 static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels;
110 /* Airpcap interface list */
111 GList *airpcap_if_list = NULL;
113 /* Airpcap current selected interface */
114 airpcap_if_info_t *airpcap_if_selected = NULL;
116 /* Airpcap current active interface */
117 airpcap_if_info_t *airpcap_if_active = NULL;
119 /* WLAN preferences pointer */
120 module_t *wlan_prefs = NULL;
122 Dot11Channel *pSupportedChannels;
123 guint numSupportedChannels;
125 static AirpcapChannelInfo LegacyChannels[] =
143 static guint num_legacy_channels = 14;
146 * Callback used by the load_wlan_keys() routine in order to read a WEP decryption key
149 get_wep_key(pref_t *pref, gpointer ud)
151 gchar *my_string = NULL;
152 keys_cb_data_t* user_data;
154 decryption_key_t* new_key;
156 /* Retrieve user data info */
157 user_data = (keys_cb_data_t*)ud;
159 if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
161 my_string = g_strdup(*pref->varp.string);
163 /* Here we have the string describing the key... */
164 new_key = parse_key_string(my_string);
168 /* Key is added only if not null ... */
169 user_data->list = g_list_append(user_data->list,new_key);
170 user_data->number_of_keys++;
171 user_data->current_index++;
177 /* Returs TRUE if the WEP key is valid, false otherwise */
179 wep_key_is_valid(char* key)
181 GString *new_key_string;
187 new_key_string = g_string_new(key);
189 if( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
191 g_string_free(new_key_string,FALSE);
194 if((new_key_string->len % 2) != 0)
196 g_string_free(new_key_string,FALSE);
199 for(i = 0; i < new_key_string->len; i++)
201 if(!g_ascii_isxdigit(new_key_string->str[i]))
203 g_string_free(new_key_string,FALSE);
208 g_string_free(new_key_string,FALSE);
212 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
214 set_wep_key(pref_t *pref, gpointer ud _U_)
216 gchar *my_string = NULL;
217 keys_cb_data_t* user_data;
218 gint wep_key_number = 0;
220 decryption_key_t* new_key;
222 /* Retrieve user data info */
223 user_data = (keys_cb_data_t*)ud;
225 if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
227 /* Ok, the pref we're gonna set is a wep_key ... but what number? */
228 sscanf(pref->name,"wep_key%d",&wep_key_number);
230 if(user_data->current_index < user_data->number_of_keys)
232 if(wep_key_number == (user_data->current_index+1))
234 /* Retrieve the nth decryption_key_t structure pointer */
235 new_key = (decryption_key_t*)g_list_nth_data(user_data->list,user_data->current_index);
237 /* Free the old key string */
238 g_free((void *)*pref->varp.string);
240 /* Create the new string describing the decryption key */
241 my_string = get_key_string(new_key);
243 /* Duplicate the string, and assign it to the variable pointer */
244 *pref->varp.string = (void *)g_strdup(my_string);
246 /* Free the previously allocated string */
250 else /* If the number of keys has been reduced somehow, we need to delete all the other keys
251 * (remember that the new ones have been probably overwritten)
254 g_free((void *)*pref->varp.string);
255 *pref->varp.string = (void *)g_strdup(""); /* Do not just free memory!!! Put an 'empty' string! */
257 user_data->current_index++;
264 * Function used to read the Decryption Keys from the preferences and store them
265 * properly into the airpcap adapter.
268 load_wlan_driver_wep_keys(void)
270 keys_cb_data_t* user_data;
273 /* Retrieve the wlan preferences */
274 wlan_prefs = prefs_find_module("wlan");
276 /* Allocate a structure used to keep infos between the callbacks */
277 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
279 /* Fill the structure */
280 user_data->list = NULL;
281 user_data->current_index = 0;
282 user_data->number_of_keys= 0; /* Still unknown */
284 /* Run the callback on each 802.11 preference */
285 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
287 /* Now the key list should be filled */
290 * Signal that we've changed things, and run the 802.11 dissector's
293 wlan_prefs->prefs_changed = TRUE;
295 prefs_apply(wlan_prefs);
297 write_wlan_driver_wep_keys_to_registry(user_data->list);
300 /* free the WEP key string */
301 for(i=0;i<g_list_length(user_data->list);i++)
303 g_free(g_list_nth(user_data->list,i)->data);
306 /* free the (empty) list */
307 g_list_free(user_data->list);
309 /* free the user_data structure */
312 /* airpcap_if_info_free(fake_info_if); */
318 * This function will tell the airpcap driver the key list to use
319 * This will be stored into the registry...
322 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
327 PAirpcapKeysCollection KeysCollection;
328 guint KeysCollectionSize;
330 guint keys_in_list = 0;
331 decryption_key_t* key_item = NULL;
333 keys_in_list = g_list_length(key_list);
336 * Save the encryption keys, if we have any of them
338 KeysCollectionSize = 0;
341 * Calculate the size of the keys collection
343 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
346 * Allocate the collection
348 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
355 * Populate the key collection
357 KeysCollection->nKeys = keys_in_list;
359 for(i = 0; i < keys_in_list; i++)
361 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
363 /* Retrieve the Item corresponding to the i-th key */
364 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
365 new_key = g_string_new(key_item->key->str);
367 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
368 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
370 for(j = 0 ; j < new_key->len; j += 2)
372 s[0] = new_key->str[j];
373 s[1] = new_key->str[j+1];
375 KeyByte = (guint8)strtol(s, NULL, 16);
376 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
379 g_string_free(new_key,TRUE);
383 * Free the old adapter key collection!
385 if(info_if->keysCollection != NULL)
386 g_free(info_if->keysCollection);
389 * Set this collection ad the new one
391 info_if->keysCollection = KeysCollection;
392 info_if->keysCollectionSize = KeysCollectionSize;
395 * Configuration must be saved
397 info_if->saved = FALSE;
400 * Write down the changes to the registry
402 airpcap_save_selected_if_configuration(info_if);
408 * This function will tell the airpcap driver the key list to use
409 * This will be stored into the registry...
412 write_wlan_driver_wep_keys_to_registry(GList* key_list)
417 PAirpcapKeysCollection KeysCollection;
418 guint KeysCollectionSize;
420 guint keys_in_list = 0;
421 decryption_key_t* key_item = NULL;
422 airpcap_if_info_t* fake_info_if = NULL;
424 /* Create the fake_info_if from the first adapter of the list */
425 fake_info_if = airpcap_driver_fake_if_info_new();
427 if(fake_info_if == NULL)
431 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
432 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
434 n = g_list_length(key_list);
435 for(k = 0; k < n; k++ )
436 if(((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
440 * Save the encryption keys, if we have any of them
442 KeysCollectionSize = 0;
445 * Calculate the size of the keys collection
447 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
450 * Allocate the collection
452 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
459 * Populate the key collection
461 KeysCollection->nKeys = keys_in_list;
464 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
465 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
466 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
469 y = 0; /* Current position in the key list */
471 for(i = 0; i < n; i++)
473 /* Retrieve the Item corresponding to the i-th key */
474 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
477 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supported right now!
478 * We will have to modify the AirpcapKey structure in order to
479 * support the other two types! What happens now, is that simply the
480 * not supported keys will just be discarded (they will be saved in Wireshark though)
482 if(key_item->type == AIRPDCAP_KEY_TYPE_WEP)
484 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
486 new_key = g_string_new(key_item->key->str);
488 KeysCollection->Keys[y].KeyLen = (guint) new_key->len / 2;
489 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
491 for(j = 0 ; j < new_key->len; j += 2)
493 s[0] = new_key->str[j];
494 s[1] = new_key->str[j+1];
496 KeyByte = (guint8)strtol(s, NULL, 16);
497 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
499 /* XXX - Change when WPA will be supported!!! */
501 g_string_free(new_key,TRUE);
503 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
505 /* XXX - The driver cannot deal with this kind of key yet... */
507 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
509 /* XXX - The driver cannot deal with this kind of key yet... */
514 * Free the old adapter key collection!
516 if(fake_info_if->keysCollection != NULL)
517 g_free(fake_info_if->keysCollection);
520 * Set this collection ad the new one
522 fake_info_if->keysCollection = KeysCollection;
523 fake_info_if->keysCollectionSize = KeysCollectionSize;
526 * Configuration must be saved
528 fake_info_if->saved = FALSE;
531 * Write down the changes to the registry
533 airpcap_save_driver_if_configuration(fake_info_if);
535 airpcap_if_info_free(fake_info_if);
541 * Function used to save to the preference file the Decryption Keys.
544 save_wlan_driver_wep_keys(void)
546 GList* key_list = NULL;
547 char* tmp_key = NULL;
548 guint keys_in_list,i;
549 keys_cb_data_t* user_data;
550 airpcap_if_info_t* fake_info_if = NULL;
552 /* Create the fake_info_if from the first adapter of the list */
553 fake_info_if = airpcap_driver_fake_if_info_new();
555 if(fake_info_if == NULL)
558 /* Retrieve the wlan preferences */
559 wlan_prefs = prefs_find_module("wlan");
561 /* Allocate a structure used to keep infos between the callbacks */
562 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
564 /* Number of keys in key list */
565 if(fake_info_if->keysCollectionSize != 0)
566 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
570 for(i=0; i<keys_in_list; i++)
572 /* Only if it is a WEP key... */
573 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
575 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
576 key_list = g_list_append(key_list,g_strdup(tmp_key));
581 /* Now we know the exact number of WEP keys in the list, so store it ... */
582 keys_in_list = g_list_length(key_list);
584 /* Fill the structure */
585 user_data->list = key_list;
586 user_data->current_index = 0;
587 user_data->number_of_keys= keys_in_list;
589 /* Retrieve the wlan preferences */
590 wlan_prefs = prefs_find_module("wlan");
592 /* Run the callback on each 802.11 preference */
593 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
595 /* Signal that we've changed things, and run the 802.11 dissector's
597 wlan_prefs->prefs_changed = TRUE;
599 /* Apply changes for the specified preference */
600 prefs_apply(wlan_prefs);
603 /* free the WEP key string */
604 for(i=0;i<g_list_length(user_data->list);i++)
606 g_free(g_list_nth(user_data->list,i)->data);
609 /* free the (empty) list */
610 g_list_free(user_data->list);
612 /* free the user_data structure */
615 airpcap_if_info_free(fake_info_if);
621 * Function used to save to the preference file the Decryption Keys.
624 save_wlan_wireshark_wep_keys(GList* key_ls)
626 GList* key_list = NULL;
627 guint keys_in_list,i;
628 keys_cb_data_t* user_data;
629 decryption_key_t* tmp_dk;
631 /* Retrieve the wlan preferences */
632 wlan_prefs = prefs_find_module("wlan");
634 /* Allocate a structure used to keep infos between the callbacks */
635 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
637 keys_in_list = g_list_length(key_ls);
641 /* Fill the structure */
642 user_data->list = key_list;
643 user_data->current_index = 0;
644 user_data->number_of_keys= keys_in_list;
646 /* Retrieve the wlan preferences */
647 wlan_prefs = prefs_find_module("wlan");
649 /* Run the callback on each 802.11 preference */
650 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
652 /* Signal that we've changed things, and run the 802.11 dissector's
654 wlan_prefs->prefs_changed = TRUE;
656 /* Apply changes for the specified preference */
657 prefs_apply(wlan_prefs);
660 /* free the WEP key string */
661 for(i=0;i<g_list_length(user_data->list);i++)
663 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
664 g_string_free(tmp_dk->key,TRUE);
665 if(tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
668 /* free the (empty) list */
669 g_list_free(user_data->list);
671 /* free the user_data structure */
678 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
679 * "get_airpcap_interface_list()".
682 cant_get_airpcap_if_list_error_message(const char *err_str)
684 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
688 * Airpcap wrapper, used to store the current settings for the selected adapter
691 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
693 if (!AirpcapLoaded) return FALSE;
694 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
698 * Airpcap wrapper, used to open an airpcap adapter
701 airpcap_if_open(gchar * name, gchar * err)
703 if (!AirpcapLoaded) return NULL;
704 if (name == NULL) return NULL;
705 return g_PAirpcapOpen(name,err);
709 * Airpcap wrapper, used to close an airpcap adapter
712 airpcap_if_close(PAirpcapHandle handle)
714 if (!AirpcapLoaded) return;
715 g_PAirpcapClose(handle);
719 * Retrieve the state of the Airpcap DLL
722 airpcap_get_dll_state(void)
724 return AirpcapVersion;
728 * Airpcap wrapper, used to turn on the led of an airpcap adapter
731 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber)
733 if (!AirpcapLoaded) return FALSE;
734 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
738 * Airpcap wrapper, used to turn off the led of an airpcap adapter
741 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber)
743 if (!AirpcapLoaded) return FALSE;
744 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
748 * Airpcap wrapper, used to get the channel of an airpcap adapter
751 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch)
753 if (!AirpcapLoaded) return FALSE;
754 return g_PAirpcapGetDeviceChannel(ah,ch);
758 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
761 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint * nInfo)
763 if (!AirpcapLoaded) return FALSE;
764 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
765 *nInfo = num_legacy_channels;
766 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
769 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
770 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
776 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
779 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint * pNumSupportedChannels)
781 AirpcapChannelInfo *chanInfo;
782 guint i=0, j=0, numInfo = 0;
786 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
788 numSupportedChannels = 0;
791 * allocate a bigger array
796 pSupportedChannels = g_malloc(numInfo * (sizeof *pSupportedChannels));
798 for (i = 0; i < numInfo; i++)
800 guint supportedChannel = G_MAXUINT;
803 * search if we have it already
805 for (j = 0; j < numSupportedChannels; j++)
807 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
809 supportedChannel = j;
814 if (supportedChannel == G_MAXUINT)
817 * not found, create a new item
819 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
821 switch(chanInfo[i].ExtChannel)
824 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
827 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
831 pSupportedChannels[numSupportedChannels].Flags = 0;
835 * Gather channel information
838 pSupportedChannels[numSupportedChannels].Flags |=
839 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
840 FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
841 pSupportedChannels[numSupportedChannels].Channel =
842 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
843 numSupportedChannels++;
848 * just update the ext channel flags
850 switch(chanInfo[i].ExtChannel)
853 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
856 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
865 if (numSupportedChannels < 1)
868 * Now sort the list by frequency
870 for (i = 0 ; i < numSupportedChannels - 1; i++)
872 for (j = i + 1; j < numSupportedChannels; j++)
874 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
876 Dot11Channel temp = pSupportedChannels[i];
877 pSupportedChannels[i] = pSupportedChannels[j];
878 pSupportedChannels[j] = temp;
883 *pNumSupportedChannels = numSupportedChannels;
884 return pSupportedChannels;
888 * Airpcap wrapper, used to set the channel of an airpcap adapter
891 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch)
893 if (!AirpcapLoaded) return FALSE;
894 return g_PAirpcapSetDeviceChannel(ah,ch);
898 * Airpcap wrapper, used to set the frequency of an airpcap adapter
901 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
903 if (!AirpcapLoaded) return FALSE;
904 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
906 channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
911 return airpcap_if_set_device_channel(ah, channel);
913 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
914 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
921 * Airpcap wrapper, used to get the frequency of an airpcap adapter
924 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
926 if (!AirpcapLoaded) return FALSE;
928 pChannelInfo->Frequency = 0;
929 pChannelInfo->ExtChannel = 0;
930 pChannelInfo->Reserved[0] = 0;
931 pChannelInfo->Reserved[1] = 0;
932 pChannelInfo->Reserved[2] = 0;
934 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
938 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
940 chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
941 if (chan_freq == 0) return FALSE;
942 pChannelInfo->Frequency = chan_freq;
945 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
946 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
952 * Airpcap wrapper, used to get the link type of an airpcap adapter
955 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
957 if (!AirpcapLoaded) return FALSE;
958 return g_PAirpcapGetLinkType(ah,lt);
962 * Airpcap wrapper, used to set the link type of an airpcap adapter
965 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
967 if (!AirpcapLoaded) return FALSE;
968 return g_PAirpcapSetLinkType(ah,lt);
972 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
975 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * fcs)
977 if (!AirpcapLoaded) return FALSE;
978 return g_PAirpcapGetFcsPresence(ah,fcs);
982 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
985 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean fcs)
987 if (!AirpcapLoaded) return FALSE;
988 return g_PAirpcapSetFcsPresence(ah,fcs);
992 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
995 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
997 if (!AirpcapLoaded) return FALSE;
998 return g_PAirpcapGetDecryptionState(ah,PEnable);
1002 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1005 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1007 if (!AirpcapLoaded) return FALSE;
1008 return g_PAirpcapSetDecryptionState(ah,Enable);
1012 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1015 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1017 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1018 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1022 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1025 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1027 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1028 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1032 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1035 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1037 if (!AirpcapLoaded) return FALSE;
1038 return g_PAirpcapGetFcsValidation(ah,val);
1042 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1045 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1047 if (!AirpcapLoaded) return FALSE;
1048 return g_PAirpcapSetFcsValidation(ah,val);
1052 * Airpcap wrapper, used to save the settings for the selected_if
1055 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1057 if (!AirpcapLoaded) return FALSE;
1058 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1062 * Airpcap wrapper, used to save the settings for the selected_if
1065 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1067 if (!AirpcapLoaded) return FALSE;
1068 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1072 * Airpcap wrapper, used to save the driver's set of keys
1075 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1077 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1078 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1082 * Airpcap wrapper, used to load the driver's set of keys
1085 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1087 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1088 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1092 * This function will create a new airpcap_if_info_t using a name and a description
1095 airpcap_if_info_new(char *name, char *description)
1098 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1100 airpcap_if_info_t *if_info = NULL;
1102 /* Probably I have to switch on the leds!!! */
1103 ad = airpcap_if_open(name, ebuf);
1106 if_info = g_malloc0(sizeof (airpcap_if_info_t));
1107 if_info->name = g_strdup(name);
1108 if (description == NULL){
1109 if_info->description = NULL;
1111 if_info->description = g_strdup(description);
1114 if_info->ip_addr = NULL;
1115 if_info->loopback = FALSE;
1116 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1117 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1118 airpcap_if_get_link_type(ad,&(if_info->linkType));
1119 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1120 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1121 airpcap_if_turn_led_on(ad, 0);
1122 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1123 if_info->led = TRUE;
1124 if_info->blinking = FALSE;
1125 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1127 /* get the keys, if everything is ok, close the adapter */
1128 if(airpcap_if_load_keys(ad,if_info))
1130 airpcap_if_close(ad);
1137 * This function will create a new fake drivers' interface, to load global keys...
1140 airpcap_driver_fake_if_info_new(void)
1143 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1145 airpcap_if_info_t *if_info = NULL;
1146 airpcap_if_info_t *fake_if_info = NULL;
1148 /* Maybe for some reason no airpcap adapter is found */
1149 if(airpcap_if_list == NULL)
1153 * Retrieve the first AirPcap adapter available. If no interface is found,
1154 * it is not possible to retrieve the driver's settings, so return NULL.
1156 if_info = g_list_nth_data(airpcap_if_list,0);
1160 /* Open the 'fake' adapter */
1161 ad = airpcap_if_open(if_info->name, ebuf);
1164 fake_if_info = g_malloc(sizeof (airpcap_if_info_t));
1165 fake_if_info->name = g_strdup(if_info->name);
1166 fake_if_info->description = g_strdup(if_info->description);
1167 fake_if_info->loopback = FALSE;
1168 fake_if_info->ip_addr = NULL;
1169 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1170 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1171 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1172 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1173 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1174 airpcap_if_turn_led_on(ad, 0);
1175 fake_if_info->led = TRUE;
1176 fake_if_info->blinking = FALSE;
1177 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1179 /* get the keys, if everything is ok, close the adapter */
1180 if(airpcap_if_load_driver_keys(ad,fake_if_info))
1182 airpcap_if_close(ad);
1186 return fake_if_info;
1190 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1193 airpcap_if_info_print(airpcap_if_info_t* if_info)
1198 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1202 g_print("\n----------------- AirPcap Interface \n");
1203 g_print(" NAME: %s\n",if_info->name);
1204 g_print(" DESCRIPTION: %s\n",if_info->description);
1205 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1206 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1207 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1208 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1209 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1210 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1211 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1212 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1213 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1214 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1215 g_print(" LINKTYPE: %d\n",if_info->linkType);
1216 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1217 g_print(" (GTK) TAG: %d\n",if_info->tag);
1218 g_print("SUPPORTED CHANNELS POINTER: %p\n",if_info->pSupportedChannels);
1219 g_print(" NUM SUPPORTED CHANNELS: %u\n",if_info->numSupportedChannels);
1221 for(i=0; i<(if_info->numSupportedChannels); i++){
1222 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1223 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1224 g_print(" FREQUENCY: %u\n",if_info->pSupportedChannels[i].Frequency);
1225 g_print(" FLAGS: %u\n",if_info->pSupportedChannels[i].Flags);
1231 * Function used to load the WEP keys for a selected interface
1234 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1236 if(!if_info) return FALSE;
1238 if_info->keysCollectionSize = 0;
1239 if_info->keysCollection = NULL;
1241 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1243 if(if_info->keysCollectionSize == 0)
1245 if_info->keysCollection = NULL;
1246 airpcap_if_close(ad);
1250 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1251 if(!if_info->keysCollection)
1253 if_info->keysCollectionSize = 0;
1254 if_info->keysCollection = NULL;
1255 airpcap_if_close(ad);
1259 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1263 airpcap_if_close(ad);
1268 * Function used to load the WEP keys for a selected interface
1271 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1273 if_info->keysCollectionSize = 0;
1274 if_info->keysCollection = NULL;
1276 if(!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1278 if(if_info->keysCollectionSize == 0)
1280 if_info->keysCollection = NULL;
1281 airpcap_if_close(ad);
1285 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1286 if(!if_info->keysCollection)
1288 if_info->keysCollectionSize = 0;
1289 if_info->keysCollection = NULL;
1290 airpcap_if_close(ad);
1294 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1298 airpcap_if_close(ad);
1303 * Function used to save the WEP keys for a selected interface
1306 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1308 if(!if_info || !AirpcapLoaded) return;
1310 if(if_info->keysCollection != NULL)
1311 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1315 * Function used to save the WEP keys for a selected interface
1318 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1320 if(if_info->keysCollection != NULL)
1321 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1325 * Callback used to free an instance of airpcap_if_info_t
1328 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1330 airpcap_if_info_t *if_info = data;
1332 if (if_info->name != NULL)
1333 g_free(if_info->name);
1335 if (if_info->description != NULL)
1336 g_free(if_info->description);
1338 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1339 if(if_info->keysCollection != NULL)
1341 g_free(if_info->keysCollection);
1342 if_info->keysCollection = NULL;
1345 if(if_info->ip_addr != NULL)
1346 g_slist_free(if_info->ip_addr);
1353 * Function used to free the airpcap interface list
1356 free_airpcap_interface_list(GList *if_list)
1358 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1359 g_list_free(if_list);
1364 * This function will use the airpcap.dll to find all the airpcap devices.
1365 * Will return null if no device is found.
1368 get_airpcap_interface_list(int *err, char **err_str)
1371 airpcap_if_info_t *if_info;
1373 AirpcapDeviceDescription *devsList, *adListEntry;
1374 char errbuf[PCAP_ERRBUF_SIZE];
1380 *err = AIRPCAP_NOT_LOADED;
1384 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1386 /* No interfaces, return il = NULL; */
1387 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1388 if (err_str != NULL)
1389 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1394 * Count the adapters
1396 adListEntry = devsList;
1401 adListEntry = adListEntry->next;
1406 /* No interfaces, return il= NULL */
1407 g_PAirpcapFreeDeviceList(devsList);
1408 *err = NO_AIRPCAP_INTERFACES_FOUND;
1409 if (err_str != NULL)
1415 * Insert the adapters in our list
1417 adListEntry = devsList;
1420 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1421 if (if_info != NULL){
1422 il = g_list_append(il, if_info);
1425 adListEntry = adListEntry->next;
1428 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
1456 #ifdef HAVE_PCAP_REMOTE /* The interface will be prepended with "rpcap://" */
1457 || g_str_has_suffix(name, if_info->name)
1471 * Returns the ASCII string of a key given the key bytes
1474 airpcap_get_key_string(AirpcapKey key)
1482 if(key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1486 /* Allocate the string used to store the ASCII representation of the WEP key */
1487 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1488 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1491 for(j = 0; j < key.KeyLen; j++)
1493 src = g_strdup_printf("%.2x", key.KeyData[j]);
1495 * XXX - use g_strconcat() or GStrings instead ???
1497 g_strlcat(dst, src, WEP_KEY_MAX_CHAR_SIZE+1);
1502 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1504 /* XXX - Add code here */
1506 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1508 /* XXX - Add code here */
1512 /* XXX - Add code here */
1519 * Clear keys and decryption status for the specified interface
1522 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1526 if(info_if->keysCollection != NULL)
1528 g_free(info_if->keysCollection);
1529 info_if->keysCollection = NULL;
1532 info_if->keysCollectionSize = 0;
1534 info_if->DecryptionOn = FALSE;
1535 info_if->saved = FALSE;
1540 * Used to retrieve the two chars string from interface
1543 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1549 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1551 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1552 * Otherwise, check if it is the "Any" adapter...
1556 if(g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1557 number = g_strdup_printf("??");
1559 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1563 number = g_strdup_printf("%.2u",n);
1570 * Used to retrieve the two chars string from interface
1573 airpcap_get_if_string_number_from_description(gchar* description)
1578 number = (gchar*)g_malloc(sizeof(gchar)*3);
1580 pointer = g_strrstr(description,"#\0");
1582 number[0] = *(pointer+1);
1583 number[1] = *(pointer+2);
1590 * Returns the default airpcap interface of a list, NULL if list is empty
1593 airpcap_get_default_if(GList* airpcap_if_list)
1596 airpcap_if_info_t* if_info = NULL;
1598 if(prefs.capture_device != NULL)
1600 s = g_strdup(get_if_name(prefs.capture_device));
1601 if_info = get_airpcap_if_from_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
1608 * Load the configuration for the specified interface
1611 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1613 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1618 ad = airpcap_if_open(if_info->name, ebuf);
1622 /* Stop blinking (if it was blinking!)*/
1623 if(if_info->blinking)
1625 /* Turn on the light (if it was off) */
1626 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1629 /* Apply settings... */
1630 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1631 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1632 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1633 airpcap_if_get_link_type(ad,&(if_info->linkType));
1634 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1635 /* get the keys, if everything is ok, close the adapter */
1636 if(airpcap_if_load_keys(ad,if_info))
1637 airpcap_if_close(ad);
1639 if_info->saved = TRUE;
1643 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1649 * Save the configuration for the specified interface
1652 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1654 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1659 ad = airpcap_if_open(if_info->name, ebuf);
1663 /* Stop blinking (if it was blinking!)*/
1664 if(if_info->blinking)
1666 /* Turn on the light (if it was off) */
1667 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1670 /* Apply settings... */
1671 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1672 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1673 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1674 airpcap_if_set_link_type(ad,if_info->linkType);
1675 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1676 airpcap_if_save_keys(ad,if_info);
1678 /* ... and save them */
1679 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1681 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.");
1682 if_info->saved = FALSE;
1683 airpcap_if_close(ad);
1687 if_info->saved = TRUE;
1688 airpcap_if_close(ad);
1692 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1698 * Save the configuration for the specified interface
1701 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1703 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1706 if(fake_if_info != NULL)
1708 ad = airpcap_if_open(fake_if_info->name, ebuf);
1712 /* Apply decryption settings... */
1713 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1714 airpcap_if_save_driver_keys(ad,fake_if_info);
1715 airpcap_if_close(ad);
1719 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1727 * DECRYPTION KEYS FUNCTIONS
1730 * This function is used for DEBUG POURPOSES ONLY!!!
1733 print_key_list(GList* key_list)
1736 decryption_key_t* tmp;
1738 if(key_list == NULL)
1740 g_print("\n\n******* KEY LIST NULL *******\n\n");
1744 n = g_list_length(key_list);
1746 g_print("\n\n********* KEY LIST **********\n\n");
1748 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1750 for(i =0; i < n; i++)
1752 g_print("[%d] :\n",i+1);
1753 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1754 g_print("KEY : %s\n",tmp->key->str);
1756 g_print("BITS: %d\n",tmp->bits);
1758 if(tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1759 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1760 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1761 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1762 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1763 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1765 g_print("TYPE: %s\n","???");
1767 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1768 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1772 g_print("\n*****************************\n\n");
1776 * Retrieves a GList of decryption_key_t structures containing infos about the
1777 * keys for the given adapter... returns NULL if no keys are found.
1780 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1783 char* tmp_key = NULL;
1784 guint i,keys_in_list = 0;
1787 decryption_key_t *new_key = NULL;
1788 GList *key_list = NULL;
1790 /* Number of keys in key list */
1791 if(info_if->keysCollectionSize != 0)
1792 keys_in_list = (guint)(info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1796 for(i=0; i<keys_in_list; i++)
1798 /* Different things to do depending on the key type */
1799 if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1801 /* allocate memory for the new key item */
1802 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1804 /* fill the fields */
1806 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1807 new_key->key = g_string_new(tmp_key);
1811 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1813 /* SSID not used in WEP keys */
1814 new_key->ssid = NULL;
1816 /* TYPE (WEP in this case) */
1817 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1819 /* Append the new element in the list */
1820 key_list = g_list_append(key_list,(gpointer)new_key);
1822 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1824 /* XXX - Not supported yet */
1826 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1828 /* XXX - Not supported yet */
1836 * Retrieves a GList of decryption_key_t structures containing infos about the
1837 * keys for the global AirPcap driver... returns NULL if no keys are found.
1840 get_airpcap_driver_keys(void)
1843 char* tmp_key = NULL;
1844 guint i,keys_in_list = 0;
1847 decryption_key_t *new_key = NULL;
1848 GList *key_list = NULL;
1851 * To read the drivers general settings we need to create and use one airpcap adapter...
1852 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1854 airpcap_if_info_t* fake_info_if = NULL;
1856 /* Create the fake_info_if from the first adapter of the list */
1857 fake_info_if = airpcap_driver_fake_if_info_new();
1859 if(fake_info_if == NULL)
1862 /* Number of keys in key list */
1863 if(fake_info_if->keysCollectionSize != 0)
1864 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1868 for(i=0; i<keys_in_list; i++)
1870 /* Different things to do depending on the key type */
1871 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1873 /* allocate memory for the new key item */
1874 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1876 /* fill the fields */
1878 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1879 new_key->key = g_string_new(tmp_key);
1880 if(tmp_key != NULL) g_free(tmp_key);
1883 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1885 /* SSID not used in WEP keys */
1886 new_key->ssid = NULL;
1888 /* TYPE (WEP in this case) */
1889 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
1891 /* Append the new element in the list */
1892 key_list = g_list_append(key_list,(gpointer)new_key);
1894 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1896 /* XXX - Not supported yet */
1898 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1900 /* XXX - Not supported yet */
1904 airpcap_if_info_free(fake_info_if);
1910 * Returns the list of the decryption keys specified for wireshark, NULL if
1914 get_wireshark_keys(void)
1916 keys_cb_data_t* wep_user_data = NULL;
1918 GList* final_list = NULL;
1919 GList* wep_final_list = NULL;
1921 /* Retrieve the wlan preferences */
1922 wlan_prefs = prefs_find_module("wlan");
1924 /* Allocate a structure used to keep infos between the callbacks */
1925 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1927 /* Fill the structure */
1928 wep_user_data->list = NULL;
1929 wep_user_data->current_index = 0;
1930 wep_user_data->number_of_keys= 0; /* Still unknown */
1932 /* Run the callback on each 802.11 preference */
1933 /* XXX - Right now, only WEP keys will be loaded */
1934 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1936 /* Copy the list field in the user data structure pointer into the final_list */
1937 if(wep_user_data != NULL) wep_final_list = wep_user_data->list;
1939 /* XXX - Merge the three lists!!!!! */
1940 final_list = wep_final_list;
1942 /* free the wep_user_data structure */
1943 g_free(wep_user_data);
1949 * Merges two lists of keys and return a newly created GList. If a key is
1950 * found multiple times, it will just appear once!
1951 * list1 and list 2 pointer will have to be freed manually if needed!!!
1952 * If the total number of keys exceeeds the maximum number allowed,
1953 * exceeding keys will be discarded...
1956 merge_key_list(GList* list1, GList* list2)
1960 decryption_key_t *dk1=NULL,
1964 GList* merged_list = NULL;
1966 if( (list1 == NULL) && (list2 == NULL) )
1972 n2 = g_list_length(list2);
1976 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1977 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1979 new_dk->bits = dk2->bits;
1980 new_dk->type = dk2->type;
1981 new_dk->key = g_string_new(dk2->key->str);
1982 new_dk->ssid = byte_array_dup(dk2->ssid);
1984 /* Check the total length of the merged list */
1985 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1986 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1989 else if(list2 == NULL)
1991 n1 = g_list_length(list1);
1996 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1997 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
1999 new_dk->bits = dk1->bits;
2000 new_dk->type = dk1->type;
2001 new_dk->key = g_string_new(dk1->key->str);
2002 new_dk->ssid = byte_array_dup(dk1->ssid);
2004 /* Check the total length of the merged list */
2005 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2006 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2011 n1 = g_list_length(list1);
2012 n2 = g_list_length(list2);
2014 /* Copy the whole list1 into merged_list */
2017 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2018 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2020 new_dk->bits = dk1->bits;
2021 new_dk->type = dk1->type;
2022 new_dk->key = g_string_new(dk1->key->str);
2023 new_dk->ssid = byte_array_dup(dk1->ssid);
2025 /* Check the total length of the merged list */
2026 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2027 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2030 /* Look for keys that are present in list2 but aren't in list1 yet...
2031 * Add them to merged_list
2035 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2037 if(!key_is_in_list(dk2,merged_list))
2039 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2041 new_dk->bits = dk2->bits;
2042 new_dk->type = dk2->type;
2043 new_dk->key = g_string_new(dk2->key->str);
2044 new_dk->ssid = byte_array_dup(dk2->ssid);
2046 /* Check the total length of the merged list */
2047 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2048 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2057 * Use this function to free a key list.
2060 free_key_list(GList *list)
2063 decryption_key_t *curr_key;
2068 n = g_list_length(list);
2070 for(i = 0; i < n; i++)
2072 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2074 /* Free all the strings */
2075 if(curr_key->key != NULL)
2076 g_string_free(curr_key->key, TRUE);
2078 if(curr_key->ssid != NULL)
2079 g_byte_array_free(curr_key->ssid, TRUE);
2081 /* free the decryption_key_t structure*/
2094 * If the given key is contained in the list, returns TRUE.
2095 * Returns FALSE otherwise.
2098 key_is_in_list(decryption_key_t *dk,GList *list)
2101 decryption_key_t* curr_key = NULL;
2102 gboolean found = FALSE;
2104 if( (list == NULL) || (dk == NULL) )
2107 n = g_list_length(list);
2112 for(i = 0; i < n; i++)
2114 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2115 if(keys_are_equals(dk,curr_key))
2123 * Returns TRUE if keys are equals, FALSE otherwise
2126 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2129 if((k1==NULL) || (k2==NULL))
2132 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2133 /** 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) ) **/
2134 /** return TRUE; **/
2136 if( g_string_equal(k1->key,k2->key) &&
2137 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2138 k1->type == k2->type)
2140 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2141 if((k1->ssid == NULL) && (k2->ssid == NULL))
2144 /* If they are not null, they must share the same ssid */
2145 return byte_array_equal(k1->ssid,k2->ssid);
2148 /* Some field is not equal ... */
2153 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2154 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2158 key_lists_are_equal(GList* list1, GList* list2)
2162 guint wep_n1=0,wep_n2=0;
2163 GList *wep_list1=NULL;
2164 GList *wep_list2=NULL;
2167 decryption_key_t *dk1=NULL,*dk2=NULL;
2169 n1 = g_list_length(list1);
2170 n2 = g_list_length(list2);
2173 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2178 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2179 if(dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2181 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2187 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2188 if(dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2190 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2196 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2201 * Commented, because in the new AirPcap version all the keys will be saved
2202 * into the driver, and all the keys for every specific adapter will be
2203 * removed. This means that this check will always fail... and the user will
2204 * always be asked what to do... and it doesn't make much sense.
2206 /* if(n1 != n2) return FALSE; */
2207 if(wep_n1 != wep_n2) return FALSE;
2214 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2215 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2217 if(!g_string_equal(dk1->key,dk2->key)) return FALSE;
2221 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2222 if(!key_is_in_list(dk2,wep_list1)) return FALSE;
2229 test_if_on(pref_t *pref, gpointer ud)
2234 /* Retrieve user data info */
2235 is_on = (gboolean*)ud;
2238 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2240 number = *pref->varp.boolp;
2242 if(number) *is_on = TRUE;
2243 else *is_on = FALSE;
2251 * Returns TRUE if the Wireshark decryption is active, false otherwise
2254 wireshark_decryption_on(void)
2258 /* Retrieve the wlan preferences */
2259 wlan_prefs = prefs_find_module("wlan");
2261 /* Run the callback on each 802.11 preference */
2262 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2268 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2271 airpcap_decryption_on(void)
2273 gboolean is_on = FALSE;
2275 airpcap_if_info_t* fake_if_info = NULL;
2277 fake_if_info = airpcap_driver_fake_if_info_new();
2279 if(fake_if_info != NULL)
2281 if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2283 else if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2287 airpcap_if_info_free(fake_if_info);
2293 * Free an instance of airpcap_if_info_t
2296 airpcap_if_info_free(airpcap_if_info_t *if_info)
2300 if (if_info->name != NULL)
2301 g_free(if_info->name);
2303 if (if_info->description != NULL)
2304 g_free(if_info->description);
2306 if(if_info->keysCollection != NULL)
2308 g_free(if_info->keysCollection);
2309 if_info->keysCollection = NULL;
2312 if(if_info->ip_addr != NULL)
2314 g_slist_free(if_info->ip_addr);
2315 if_info->ip_addr = NULL;
2327 set_on_off(pref_t *pref, gpointer ud)
2332 /* Retrieve user data info */
2333 is_on = (gboolean*)ud;
2335 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2337 number = *pref->varp.boolp;
2340 *pref->varp.boolp = TRUE;
2342 *pref->varp.boolp = FALSE;
2350 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2353 set_wireshark_decryption(gboolean on_off)
2359 /* Retrieve the wlan preferences */
2360 wlan_prefs = prefs_find_module("wlan");
2362 /* Run the callback on each 802.11 preference */
2363 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2366 * Signal that we've changed things, and run the 802.11 dissector's
2369 wlan_prefs->prefs_changed = TRUE;
2371 prefs_apply(wlan_prefs);
2375 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2378 set_airpcap_decryption(gboolean on_off)
2380 /* We need to directly access the .dll functions here... */
2381 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2382 PAirpcapHandle ad,ad_driver;
2384 gboolean success = TRUE;
2388 airpcap_if_info_t* curr_if = NULL;
2389 airpcap_if_info_t* fake_if_info = NULL;
2391 fake_if_info = airpcap_driver_fake_if_info_new();
2393 if(fake_if_info == NULL)
2394 /* We apparently don't have any adapters installed.
2395 * This isn't a failure, so return TRUE
2399 /* Set the driver decryption */
2400 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2404 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2406 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2408 airpcap_if_close(ad_driver);
2411 airpcap_if_info_free(fake_if_info);
2413 n = g_list_length(airpcap_if_list);
2415 /* Set to FALSE the decryption for all the adapters */
2416 /* Apply this change to all the adapters !!! */
2417 for(i = 0; i < n; i++)
2419 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2421 if( curr_if != NULL )
2423 ad = airpcap_if_open(curr_if->name, ebuf);
2426 curr_if->DecryptionOn = (gboolean)AIRPCAP_DECRYPTION_OFF;
2427 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2428 /* Save configuration for the curr_if */
2429 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
2433 airpcap_if_close(ad);
2442 /* DYNAMIC LIBRARY LOADER */
2444 * Used to dynamically load the airpcap library in order link it only when
2445 * it's present on the system
2447 int load_airpcap(void)
2450 gboolean base_functions = TRUE;
2451 gboolean eleven_n_functions = TRUE;
2453 if((AirpcapLib = LoadLibrary(TEXT("airpcap.dll"))) == NULL)
2455 /* Report the error but go on */
2456 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2457 return AirpcapVersion;
2461 if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2462 if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2463 if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2464 if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2465 if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2466 if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2467 if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2468 if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2469 if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2470 if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2471 if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2472 if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2473 if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2474 if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2475 if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2476 if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2477 if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2478 if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2479 if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2480 if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2481 if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2482 if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2483 if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2484 if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2485 if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2486 if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2487 if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2488 if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2489 if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2490 if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2491 if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2492 if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2494 /* TEST IF AIRPCAP SUPPORTS 11N */
2495 if((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2496 if((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2497 if((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2499 if(base_functions && eleven_n_functions){
2500 AirpcapLoaded = TRUE;
2501 AirpcapVersion = AIRPCAP_DLL_OK;
2502 }else if(base_functions){
2503 AirpcapLoaded = TRUE;
2504 AirpcapVersion = AIRPCAP_DLL_OLD;
2505 return AIRPCAP_DLL_OK;
2507 AirpcapLoaded = FALSE;
2508 AirpcapVersion = AIRPCAP_DLL_ERROR;
2511 return AirpcapVersion;
2513 return AIRPCAP_DLL_NOT_FOUND;
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_append_printf(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2544 #endif /* HAVE_AIRPCAP */