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"
50 #include <wsutil/file_util.h>
52 #include "ui/simple_dialog.h"
55 #include "airpcap_loader.h"
59 * Set to TRUE if the DLL was successfully loaded AND all functions
62 static gboolean AirpcapLoaded = FALSE;
66 * We load dynamically the dag library in order link it only when
67 * it's present on the system
69 static void * AirpcapLib = NULL;
71 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
72 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
73 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
74 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
75 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
76 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
77 static AirpcapReadHandler g_PAirpcapRead;
78 static AirpcapGetStatsHandler g_PAirpcapGetStats;
81 static int AirpcapVersion = 3;
83 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
84 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
85 static AirpcapOpenHandler g_PAirpcapOpen;
86 static AirpcapCloseHandler g_PAirpcapClose;
87 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
88 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
89 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
90 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
91 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
92 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
93 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
94 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
95 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
96 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
97 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
98 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
99 static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys;
100 static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys;
101 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
102 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
103 static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState;
104 static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState;
105 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
106 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
107 static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx;
108 static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx;
109 static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels;
111 /* Airpcap interface list */
112 GList *airpcap_if_list = NULL;
114 /* Airpcap current selected interface */
115 airpcap_if_info_t *airpcap_if_selected = NULL;
117 /* Airpcap current active interface */
118 airpcap_if_info_t *airpcap_if_active = NULL;
120 /* WLAN preferences pointer */
121 module_t *wlan_prefs = NULL;
123 Dot11Channel *pSupportedChannels;
124 guint numSupportedChannels;
126 static AirpcapChannelInfo LegacyChannels[] =
144 static guint num_legacy_channels = 14;
147 * Callback used by the load_wlan_keys() routine in order to read a WEP decryption key
150 get_wep_key(pref_t *pref, gpointer ud)
152 gchar *key_string = NULL;
153 guint8 key_type = AIRPDCAP_KEY_TYPE_WEP;
154 keys_cb_data_t* user_data;
156 decryption_key_t* new_key;
158 /* Retrieve user data info */
159 user_data = (keys_cb_data_t*)ud;
161 if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
163 /* strip out key type */
164 if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
165 key_string = (gchar*)(*pref->varp.string)+4;
167 else if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WPA_PWD ":", 8) == 0) {
168 key_string = (gchar*)(*pref->varp.string)+8;
169 key_type = AIRPDCAP_KEY_TYPE_WPA_PWD;
171 else if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WPA_PSK ":", 8) == 0) {
172 key_string = (gchar*)(*pref->varp.string)+8;
173 key_type = AIRPDCAP_KEY_TYPE_WPA_PSK;
176 key_type = AIRPDCAP_KEY_TYPE_WEP;
177 key_string = (gchar*)*pref->varp.string;
180 /* Here we have the string describing the key... */
181 new_key = parse_key_string(key_string, key_type);
185 /* Key is added only if not null ... */
186 user_data->list = g_list_append(user_data->list,new_key);
187 user_data->number_of_keys++;
188 user_data->current_index++;
194 /* Returs TRUE if the WEP key is valid, false otherwise */
196 wep_key_is_valid(char* key)
198 GString *new_key_string;
204 new_key_string = g_string_new(key);
206 if( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
208 g_string_free(new_key_string,FALSE);
211 if((new_key_string->len % 2) != 0)
213 g_string_free(new_key_string,FALSE);
216 for(i = 0; i < new_key_string->len; i++)
218 if(!g_ascii_isxdigit(new_key_string->str[i]))
220 g_string_free(new_key_string,FALSE);
225 g_string_free(new_key_string,FALSE);
229 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
231 set_wep_key(pref_t *pref, gpointer ud _U_)
233 gchar *my_string = NULL;
234 keys_cb_data_t* user_data;
235 gint wep_key_number = 0;
237 decryption_key_t* new_key;
239 /* Retrieve user data info */
240 user_data = (keys_cb_data_t*)ud;
242 if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
244 /* Ok, the pref we're gonna set is a wep_key ... but what number? */
245 sscanf(pref->name,"wep_key%d",&wep_key_number);
247 if(user_data->current_index < user_data->number_of_keys)
249 if(wep_key_number == (user_data->current_index+1))
251 /* Retrieve the nth decryption_key_t structure pointer */
252 new_key = (decryption_key_t*)g_list_nth_data(user_data->list,user_data->current_index);
254 /* Free the old key string */
255 g_free((void *)*pref->varp.string);
257 /* Create the new string describing the decryption key */
258 my_string = get_key_string(new_key);
260 /* Duplicate the string, and assign it to the variable pointer */
261 *pref->varp.string = (void *)g_strdup(my_string);
263 /* Free the previously allocated string */
267 else /* If the number of keys has been reduced somehow, we need to delete all the other keys
268 * (remember that the new ones have been probably overwritten)
271 g_free((void *)*pref->varp.string);
272 *pref->varp.string = (void *)g_strdup(""); /* Do not just free memory!!! Put an 'empty' string! */
274 user_data->current_index++;
281 * Function used to read the Decryption Keys from the preferences and store them
282 * properly into the airpcap adapter.
285 load_wlan_driver_wep_keys(void)
287 keys_cb_data_t* user_data;
290 /* Retrieve the wlan preferences */
291 wlan_prefs = prefs_find_module("wlan");
293 /* Allocate a structure used to keep infos between the callbacks */
294 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
296 /* Fill the structure */
297 user_data->list = NULL;
298 user_data->current_index = 0;
299 user_data->number_of_keys= 0; /* Still unknown */
301 /* Run the callback on each 802.11 preference */
302 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
304 /* Now the key list should be filled */
307 * Signal that we've changed things, and run the 802.11 dissector's
310 wlan_prefs->prefs_changed = TRUE;
312 prefs_apply(wlan_prefs);
314 write_wlan_driver_wep_keys_to_registry(user_data->list);
317 /* free the WEP key string */
318 for(i=0;i<g_list_length(user_data->list);i++)
320 g_free(g_list_nth(user_data->list,i)->data);
323 /* free the (empty) list */
324 g_list_free(user_data->list);
326 /* free the user_data structure */
329 /* airpcap_if_info_free(fake_info_if); */
335 * This function will tell the airpcap driver the key list to use
336 * This will be stored into the registry...
339 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
344 PAirpcapKeysCollection KeysCollection;
345 guint KeysCollectionSize;
347 guint keys_in_list = 0;
348 decryption_key_t* key_item = NULL;
350 keys_in_list = g_list_length(key_list);
353 * Calculate the size of the keys collection
355 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
358 * Allocate the collection
360 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
367 * Populate the key collection
369 KeysCollection->nKeys = keys_in_list;
371 for(i = 0; i < keys_in_list; i++)
373 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
375 /* Retrieve the Item corresponding to the i-th key */
376 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
377 new_key = g_string_new(key_item->key->str);
379 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
380 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
382 for(j = 0 ; j < new_key->len; j += 2)
384 s[0] = new_key->str[j];
385 s[1] = new_key->str[j+1];
387 KeyByte = (guint8)strtol(s, NULL, 16);
388 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
391 g_string_free(new_key,TRUE);
395 * Free the old adapter key collection!
397 if(info_if->keysCollection != NULL)
398 g_free(info_if->keysCollection);
401 * Set this collection ad the new one
403 info_if->keysCollection = KeysCollection;
404 info_if->keysCollectionSize = KeysCollectionSize;
407 * Configuration must be saved
409 info_if->saved = FALSE;
412 * Write down the changes to the registry
414 airpcap_save_selected_if_configuration(info_if);
420 * This function will tell the airpcap driver the key list to use
421 * This will be stored into the registry...
424 write_wlan_driver_wep_keys_to_registry(GList* key_list)
429 PAirpcapKeysCollection KeysCollection;
430 guint KeysCollectionSize;
432 guint keys_in_list = 0;
433 decryption_key_t* key_item = NULL;
434 airpcap_if_info_t* fake_info_if = NULL;
436 /* Create the fake_info_if from the first adapter of the list */
437 fake_info_if = airpcap_driver_fake_if_info_new();
439 if(fake_info_if == NULL)
443 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
444 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
446 n = g_list_length(key_list);
447 for(k = 0; k < n; k++ )
448 if(((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
452 * Calculate the size of the keys collection
454 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
457 * Allocate the collection
459 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
466 * Populate the key collection
468 KeysCollection->nKeys = keys_in_list;
471 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
472 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
473 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
476 y = 0; /* Current position in the key list */
478 for(i = 0; i < n; i++)
480 /* Retrieve the Item corresponding to the i-th key */
481 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
484 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supported right now!
485 * We will have to modify the AirpcapKey structure in order to
486 * support the other two types! What happens now, is that simply the
487 * not supported keys will just be discarded (they will be saved in Wireshark though)
489 if(key_item->type == AIRPDCAP_KEY_TYPE_WEP)
491 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
493 new_key = g_string_new(key_item->key->str);
495 KeysCollection->Keys[y].KeyLen = (guint) new_key->len / 2;
496 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
498 for(j = 0 ; j < new_key->len; j += 2)
500 s[0] = new_key->str[j];
501 s[1] = new_key->str[j+1];
503 KeyByte = (guint8)strtol(s, NULL, 16);
504 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
506 /* XXX - Change when WPA will be supported!!! */
508 g_string_free(new_key,TRUE);
510 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
512 /* XXX - The driver cannot deal with this kind of key yet... */
514 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
516 /* XXX - The driver cannot deal with this kind of key yet... */
521 * Free the old adapter key collection!
523 if(fake_info_if->keysCollection != NULL)
524 g_free(fake_info_if->keysCollection);
527 * Set this collection ad the new one
529 fake_info_if->keysCollection = KeysCollection;
530 fake_info_if->keysCollectionSize = KeysCollectionSize;
533 * Configuration must be saved
535 fake_info_if->saved = FALSE;
538 * Write down the changes to the registry
540 airpcap_save_driver_if_configuration(fake_info_if);
542 airpcap_if_info_free(fake_info_if);
548 * Function used to save to the preference file the Decryption Keys.
551 save_wlan_driver_wep_keys(void)
553 GList* key_list = NULL;
554 char* tmp_key = NULL;
555 guint keys_in_list,i;
556 keys_cb_data_t* user_data;
557 airpcap_if_info_t* fake_info_if = NULL;
559 /* Create the fake_info_if from the first adapter of the list */
560 fake_info_if = airpcap_driver_fake_if_info_new();
562 if(fake_info_if == NULL)
565 /* Retrieve the wlan preferences */
566 wlan_prefs = prefs_find_module("wlan");
568 /* Allocate a structure used to keep infos between the callbacks */
569 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
571 /* Number of keys in key list */
572 if(fake_info_if->keysCollectionSize != 0)
573 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
577 for(i=0; i<keys_in_list; i++)
579 /* Only if it is a WEP key... */
580 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
582 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
583 key_list = g_list_append(key_list,g_strdup(tmp_key));
588 /* Now we know the exact number of WEP keys in the list, so store it ... */
589 keys_in_list = g_list_length(key_list);
591 /* Fill the structure */
592 user_data->list = key_list;
593 user_data->current_index = 0;
594 user_data->number_of_keys= keys_in_list;
596 /* Retrieve the wlan preferences */
597 wlan_prefs = prefs_find_module("wlan");
599 /* Run the callback on each 802.11 preference */
600 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
602 /* Signal that we've changed things, and run the 802.11 dissector's
604 wlan_prefs->prefs_changed = TRUE;
606 /* Apply changes for the specified preference */
607 prefs_apply(wlan_prefs);
610 /* free the WEP key string */
611 for(i=0;i<g_list_length(user_data->list);i++)
613 g_free(g_list_nth(user_data->list,i)->data);
616 /* free the (empty) list */
617 g_list_free(user_data->list);
619 /* free the user_data structure */
622 airpcap_if_info_free(fake_info_if);
628 * Function used to save to the preference file the Decryption Keys.
631 save_wlan_wireshark_wep_keys(GList* key_ls)
633 GList* key_list = NULL;
634 guint keys_in_list,i;
635 keys_cb_data_t* user_data;
636 decryption_key_t* tmp_dk;
638 /* Retrieve the wlan preferences */
639 wlan_prefs = prefs_find_module("wlan");
641 /* Allocate a structure used to keep infos between the callbacks */
642 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
644 keys_in_list = g_list_length(key_ls);
648 /* Fill the structure */
649 user_data->list = key_list;
650 user_data->current_index = 0;
651 user_data->number_of_keys= keys_in_list;
653 /* Retrieve the wlan preferences */
654 wlan_prefs = prefs_find_module("wlan");
656 /* Run the callback on each 802.11 preference */
657 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
659 /* Signal that we've changed things, and run the 802.11 dissector's
661 wlan_prefs->prefs_changed = TRUE;
663 /* Apply changes for the specified preference */
664 prefs_apply(wlan_prefs);
667 /* free the WEP key string */
668 for(i=0;i<g_list_length(user_data->list);i++)
670 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
671 g_string_free(tmp_dk->key,TRUE);
672 if(tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
675 /* free the (empty) list */
676 g_list_free(user_data->list);
678 /* free the user_data structure */
685 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
686 * "get_airpcap_interface_list()".
689 cant_get_airpcap_if_list_error_message(const char *err_str)
691 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
695 * Airpcap wrapper, used to store the current settings for the selected adapter
698 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
700 if (!AirpcapLoaded) return FALSE;
701 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
705 * Airpcap wrapper, used to open an airpcap adapter
708 airpcap_if_open(gchar * name, gchar * err)
710 if (!AirpcapLoaded) return NULL;
711 if (name == NULL) return NULL;
712 return g_PAirpcapOpen(name,err);
716 * Airpcap wrapper, used to close an airpcap adapter
719 airpcap_if_close(PAirpcapHandle handle)
721 if (!AirpcapLoaded) return;
722 g_PAirpcapClose(handle);
726 * Retrieve the state of the Airpcap DLL
729 airpcap_get_dll_state(void)
731 return AirpcapVersion;
735 * Airpcap wrapper, used to turn on the led of an airpcap adapter
738 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber)
740 if (!AirpcapLoaded) return FALSE;
741 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
745 * Airpcap wrapper, used to turn off the led of an airpcap adapter
748 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber)
750 if (!AirpcapLoaded) return FALSE;
751 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
755 * Airpcap wrapper, used to get the channel of an airpcap adapter
758 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch)
760 if (!AirpcapLoaded) return FALSE;
761 return g_PAirpcapGetDeviceChannel(ah,ch);
765 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
768 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint * nInfo)
770 if (!AirpcapLoaded) return FALSE;
771 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
772 *nInfo = num_legacy_channels;
773 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
776 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
777 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
783 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
786 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint * pNumSupportedChannels)
788 AirpcapChannelInfo *chanInfo;
789 guint i=0, j=0, numInfo = 0;
793 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
795 numSupportedChannels = 0;
798 * allocate a bigger array
803 pSupportedChannels = g_malloc(numInfo * (sizeof *pSupportedChannels));
805 for (i = 0; i < numInfo; i++)
807 guint supportedChannel = G_MAXUINT;
810 * search if we have it already
812 for (j = 0; j < numSupportedChannels; j++)
814 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
816 supportedChannel = j;
821 if (supportedChannel == G_MAXUINT)
824 * not found, create a new item
826 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
828 switch(chanInfo[i].ExtChannel)
831 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
834 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
838 pSupportedChannels[numSupportedChannels].Flags = 0;
842 * Gather channel information
845 pSupportedChannels[numSupportedChannels].Flags |=
846 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
847 FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
848 pSupportedChannels[numSupportedChannels].Channel =
849 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
850 numSupportedChannels++;
855 * just update the ext channel flags
857 switch(chanInfo[i].ExtChannel)
860 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
863 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
872 if (numSupportedChannels < 1)
875 * Now sort the list by frequency
877 for (i = 0 ; i < numSupportedChannels - 1; i++)
879 for (j = i + 1; j < numSupportedChannels; j++)
881 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
883 Dot11Channel temp = pSupportedChannels[i];
884 pSupportedChannels[i] = pSupportedChannels[j];
885 pSupportedChannels[j] = temp;
890 *pNumSupportedChannels = numSupportedChannels;
891 return pSupportedChannels;
895 * Airpcap wrapper, used to set the channel of an airpcap adapter
898 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch)
900 if (!AirpcapLoaded) return FALSE;
901 return g_PAirpcapSetDeviceChannel(ah,ch);
905 * Airpcap wrapper, used to set the frequency of an airpcap adapter
908 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
910 if (!AirpcapLoaded) return FALSE;
911 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
913 channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
918 return airpcap_if_set_device_channel(ah, channel);
920 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
921 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
928 * Airpcap wrapper, used to get the frequency of an airpcap adapter
931 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
933 if (!AirpcapLoaded) return FALSE;
935 pChannelInfo->Frequency = 0;
936 pChannelInfo->ExtChannel = 0;
937 pChannelInfo->Reserved[0] = 0;
938 pChannelInfo->Reserved[1] = 0;
939 pChannelInfo->Reserved[2] = 0;
941 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
945 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
947 chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
948 if (chan_freq == 0) return FALSE;
949 pChannelInfo->Frequency = chan_freq;
952 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
953 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
959 * Airpcap wrapper, used to get the link type of an airpcap adapter
962 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
964 if (!AirpcapLoaded) return FALSE;
965 return g_PAirpcapGetLinkType(ah,lt);
969 * Airpcap wrapper, used to set the link type of an airpcap adapter
972 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
974 if (!AirpcapLoaded) return FALSE;
975 return g_PAirpcapSetLinkType(ah,lt);
979 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
982 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * fcs)
984 if (!AirpcapLoaded) return FALSE;
985 return g_PAirpcapGetFcsPresence(ah,fcs);
989 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
992 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean fcs)
994 if (!AirpcapLoaded) return FALSE;
995 return g_PAirpcapSetFcsPresence(ah,fcs);
999 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
1002 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1004 if (!AirpcapLoaded) return FALSE;
1005 return g_PAirpcapGetDecryptionState(ah,PEnable);
1009 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1012 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1014 if (!AirpcapLoaded) return FALSE;
1015 return g_PAirpcapSetDecryptionState(ah,Enable);
1019 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1022 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1024 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1025 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1029 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1032 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1034 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1035 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1039 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1042 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1044 if (!AirpcapLoaded) return FALSE;
1045 return g_PAirpcapGetFcsValidation(ah,val);
1049 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1052 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1054 if (!AirpcapLoaded) return FALSE;
1055 return g_PAirpcapSetFcsValidation(ah,val);
1059 * Airpcap wrapper, used to save the settings for the selected_if
1062 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1064 if (!AirpcapLoaded) return FALSE;
1065 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1069 * Airpcap wrapper, used to save the settings for the selected_if
1072 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1074 if (!AirpcapLoaded) return FALSE;
1075 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1079 * Airpcap wrapper, used to save the driver's set of keys
1082 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1084 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1085 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1089 * Airpcap wrapper, used to load the driver's set of keys
1092 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1094 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1095 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1099 * This function will create a new airpcap_if_info_t using a name and a description
1102 airpcap_if_info_new(char *name, char *description)
1105 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1107 airpcap_if_info_t *if_info = NULL;
1109 /* Probably I have to switch on the leds!!! */
1110 ad = airpcap_if_open(name, ebuf);
1113 if_info = g_malloc0(sizeof (airpcap_if_info_t));
1114 if_info->name = g_strdup(name);
1115 if (description == NULL){
1116 if_info->description = NULL;
1118 if_info->description = g_strdup(description);
1121 if_info->ip_addr = NULL;
1122 if_info->loopback = FALSE;
1123 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1124 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1125 airpcap_if_get_link_type(ad,&(if_info->linkType));
1126 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1127 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1128 airpcap_if_turn_led_on(ad, 0);
1129 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1130 if_info->led = TRUE;
1131 if_info->blinking = FALSE;
1132 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1134 /* get the keys, if everything is ok, close the adapter */
1135 if(airpcap_if_load_keys(ad,if_info))
1137 airpcap_if_close(ad);
1144 * This function will create a new fake drivers' interface, to load global keys...
1147 airpcap_driver_fake_if_info_new(void)
1150 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1152 airpcap_if_info_t *if_info = NULL;
1153 airpcap_if_info_t *fake_if_info = NULL;
1155 /* Maybe for some reason no airpcap adapter is found */
1156 if(airpcap_if_list == NULL)
1160 * Retrieve the first AirPcap adapter available. If no interface is found,
1161 * it is not possible to retrieve the driver's settings, so return NULL.
1163 if_info = g_list_nth_data(airpcap_if_list,0);
1167 /* Open the 'fake' adapter */
1168 ad = airpcap_if_open(if_info->name, ebuf);
1171 fake_if_info = g_malloc(sizeof (airpcap_if_info_t));
1172 fake_if_info->name = g_strdup(if_info->name);
1173 fake_if_info->description = g_strdup(if_info->description);
1174 fake_if_info->loopback = FALSE;
1175 fake_if_info->ip_addr = NULL;
1176 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1177 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1178 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1179 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1180 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1181 airpcap_if_turn_led_on(ad, 0);
1182 fake_if_info->led = TRUE;
1183 fake_if_info->blinking = FALSE;
1184 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1186 /* get the keys, if everything is ok, close the adapter */
1187 if(airpcap_if_load_driver_keys(ad,fake_if_info))
1189 airpcap_if_close(ad);
1193 return fake_if_info;
1197 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1200 airpcap_if_info_print(airpcap_if_info_t* if_info)
1205 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1209 g_print("\n----------------- AirPcap Interface \n");
1210 g_print(" NAME: %s\n",if_info->name);
1211 g_print(" DESCRIPTION: %s\n",if_info->description);
1212 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1213 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1214 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1215 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1216 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1217 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1218 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1219 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1220 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1221 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1222 g_print(" LINKTYPE: %d\n",if_info->linkType);
1223 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1224 g_print(" (GTK) TAG: %d\n",if_info->tag);
1225 g_print("SUPPORTED CHANNELS POINTER: %p\n",if_info->pSupportedChannels);
1226 g_print(" NUM SUPPORTED CHANNELS: %u\n",if_info->numSupportedChannels);
1228 for(i=0; i<(if_info->numSupportedChannels); i++){
1229 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1230 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1231 g_print(" FREQUENCY: %u\n",if_info->pSupportedChannels[i].Frequency);
1232 g_print(" FLAGS: %u\n",if_info->pSupportedChannels[i].Flags);
1238 * Function used to load the WEP keys for a selected interface
1241 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1243 if(!if_info) return FALSE;
1245 if_info->keysCollectionSize = 0;
1246 if_info->keysCollection = NULL;
1248 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1250 if(if_info->keysCollectionSize == 0)
1252 if_info->keysCollection = NULL;
1253 airpcap_if_close(ad);
1257 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1258 if(!if_info->keysCollection)
1260 if_info->keysCollectionSize = 0;
1261 if_info->keysCollection = NULL;
1262 airpcap_if_close(ad);
1266 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1270 airpcap_if_close(ad);
1275 * Function used to load the WEP keys for a selected interface
1278 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1280 if_info->keysCollectionSize = 0;
1281 if_info->keysCollection = NULL;
1283 if(!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1285 if(if_info->keysCollectionSize == 0)
1287 if_info->keysCollection = NULL;
1288 airpcap_if_close(ad);
1292 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1293 if(!if_info->keysCollection)
1295 if_info->keysCollectionSize = 0;
1296 if_info->keysCollection = NULL;
1297 airpcap_if_close(ad);
1301 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1305 airpcap_if_close(ad);
1310 * Function used to save the WEP keys for a selected interface
1313 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1315 if(!if_info || !AirpcapLoaded) return;
1317 if(if_info->keysCollection != NULL)
1318 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1322 * Function used to save the WEP keys for a selected interface
1325 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1327 if(if_info->keysCollection != NULL)
1328 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1332 * Callback used to free an instance of airpcap_if_info_t
1335 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1337 airpcap_if_info_t *if_info = data;
1339 if (NULL == if_info)
1342 if (if_info->name != NULL)
1343 g_free(if_info->name);
1345 if (if_info->description != NULL)
1346 g_free(if_info->description);
1348 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1349 if(if_info->keysCollection != NULL)
1351 g_free(if_info->keysCollection);
1352 if_info->keysCollection = NULL;
1355 if(if_info->ip_addr != NULL)
1356 g_slist_free(if_info->ip_addr);
1362 * Function used to free the airpcap interface list
1365 free_airpcap_interface_list(GList *if_list)
1367 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1368 g_list_free(if_list);
1373 * This function will use the airpcap.dll to find all the airpcap devices.
1374 * Will return null if no device is found.
1377 get_airpcap_interface_list(int *err, char **err_str)
1380 airpcap_if_info_t *if_info;
1382 AirpcapDeviceDescription *devsList, *adListEntry;
1383 char errbuf[AIRPCAP_ERRBUF_SIZE];
1389 *err = AIRPCAP_NOT_LOADED;
1393 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1395 /* No interfaces, return il = NULL; */
1396 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1397 if (err_str != NULL)
1398 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1403 * Count the adapters
1405 adListEntry = devsList;
1410 adListEntry = adListEntry->next;
1415 /* No interfaces, return il= NULL */
1416 g_PAirpcapFreeDeviceList(devsList);
1417 *err = NO_AIRPCAP_INTERFACES_FOUND;
1418 if (err_str != NULL)
1424 * Insert the adapters in our list
1426 adListEntry = devsList;
1429 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1430 if (if_info != NULL){
1431 il = g_list_append(il, if_info);
1434 adListEntry = adListEntry->next;
1437 g_PAirpcapFreeDeviceList(devsList);
1443 * Used to retrieve the interface given the name
1444 * (the name is used in AirpcapOpen)
1446 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
1449 airpcap_if_info_t* if_info;
1451 for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
1452 if_info = (airpcap_if_info_t *)curr->data;
1453 if (if_info && (g_ascii_strcasecmp(if_info->name, name) == 0)) {
1461 * Returns the ASCII string of a key given the key bytes
1464 airpcap_get_key_string(AirpcapKey key)
1472 if(key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1476 /* Allocate the string used to store the ASCII representation of the WEP key */
1477 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1478 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1481 for(j = 0; j < key.KeyLen; j++)
1483 src = g_strdup_printf("%.2x", key.KeyData[j]);
1485 * XXX - use g_strconcat() or GStrings instead ???
1487 g_strlcat(dst, src, WEP_KEY_MAX_CHAR_SIZE+1);
1492 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1494 /* XXX - Add code here */
1496 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1498 /* XXX - Add code here */
1502 /* XXX - Add code here */
1509 * Clear keys and decryption status for the specified interface
1512 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1516 if(info_if->keysCollection != NULL)
1518 g_free(info_if->keysCollection);
1519 info_if->keysCollection = NULL;
1522 info_if->keysCollectionSize = 0;
1524 info_if->DecryptionOn = FALSE;
1525 info_if->saved = FALSE;
1530 * Used to retrieve the two chars string from interface
1533 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1539 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1541 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1542 * Otherwise, check if it is the "Any" adapter...
1546 if(g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1547 number = g_strdup_printf("??");
1549 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1553 number = g_strdup_printf("%.2u",n);
1560 * Used to retrieve the two chars string from interface
1563 airpcap_get_if_string_number_from_description(gchar* description)
1568 number = (gchar*)g_malloc(sizeof(gchar)*3);
1570 pointer = g_strrstr(description,"#\0");
1572 number[0] = *(pointer+1);
1573 number[1] = *(pointer+2);
1580 * Returns the default airpcap interface of a list, NULL if list is empty
1583 airpcap_get_default_if(GList* airpcap_if_list)
1586 airpcap_if_info_t* if_info = NULL;
1588 if(prefs.capture_device != NULL)
1590 s = g_strdup(get_if_name(prefs.capture_device));
1591 if_info = get_airpcap_if_from_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
1598 * Load the configuration for the specified interface
1601 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1603 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1608 ad = airpcap_if_open(if_info->name, ebuf);
1612 /* Stop blinking (if it was blinking!)*/
1613 if(if_info->blinking)
1615 /* Turn on the light (if it was off) */
1616 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1619 /* Apply settings... */
1620 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1621 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1622 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1623 airpcap_if_get_link_type(ad,&(if_info->linkType));
1624 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1625 /* get the keys, if everything is ok, close the adapter */
1626 if(airpcap_if_load_keys(ad,if_info))
1627 airpcap_if_close(ad);
1629 if_info->saved = TRUE;
1633 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1639 * Save the configuration for the specified interface
1642 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1644 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1649 ad = airpcap_if_open(if_info->name, ebuf);
1653 /* Stop blinking (if it was blinking!)*/
1654 if(if_info->blinking)
1656 /* Turn on the light (if it was off) */
1657 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1660 /* Apply settings... */
1661 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1662 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1663 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1664 airpcap_if_set_link_type(ad,if_info->linkType);
1665 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1666 airpcap_if_save_keys(ad,if_info);
1668 /* ... and save them */
1669 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1671 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.");
1672 if_info->saved = FALSE;
1673 airpcap_if_close(ad);
1677 if_info->saved = TRUE;
1678 airpcap_if_close(ad);
1682 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1688 * Save the configuration for the specified interface
1691 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1693 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1696 if(fake_if_info != NULL)
1698 ad = airpcap_if_open(fake_if_info->name, ebuf);
1702 /* Apply decryption settings... */
1703 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1704 airpcap_if_save_driver_keys(ad,fake_if_info);
1705 airpcap_if_close(ad);
1709 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1717 * DECRYPTION KEYS FUNCTIONS
1720 * This function is used for DEBUG POURPOSES ONLY!!!
1723 print_key_list(GList* key_list)
1726 decryption_key_t* tmp;
1728 if(key_list == NULL)
1730 g_print("\n\n******* KEY LIST NULL *******\n\n");
1734 n = g_list_length(key_list);
1736 g_print("\n\n********* KEY LIST **********\n\n");
1738 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1740 for(i =0; i < n; i++)
1742 g_print("[%d] :\n",i+1);
1743 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1744 g_print("KEY : %s\n",tmp->key->str);
1746 g_print("BITS: %d\n",tmp->bits);
1748 if(tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1749 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1750 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1751 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1752 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1753 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1755 g_print("TYPE: %s\n","???");
1757 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1758 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1762 g_print("\n*****************************\n\n");
1766 * Retrieves a GList of decryption_key_t structures containing infos about the
1767 * keys for the given adapter... returns NULL if no keys are found.
1770 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1773 char* tmp_key = NULL;
1774 guint i,keys_in_list = 0;
1777 decryption_key_t *new_key = NULL;
1778 GList *key_list = NULL;
1780 /* Number of keys in key list */
1781 if(info_if->keysCollectionSize != 0)
1782 keys_in_list = (guint)(info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1786 for(i=0; i<keys_in_list; i++)
1788 /* Different things to do depending on the key type */
1789 if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1791 /* allocate memory for the new key item */
1792 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1794 /* fill the fields */
1796 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1797 new_key->key = g_string_new(tmp_key);
1801 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1803 /* SSID not used in WEP keys */
1804 new_key->ssid = NULL;
1806 /* TYPE (WEP in this case) */
1807 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1809 /* Append the new element in the list */
1810 key_list = g_list_append(key_list,(gpointer)new_key);
1812 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1814 /* XXX - Not supported yet */
1816 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1818 /* XXX - Not supported yet */
1826 * Retrieves a GList of decryption_key_t structures containing infos about the
1827 * keys for the global AirPcap driver... returns NULL if no keys are found.
1830 get_airpcap_driver_keys(void)
1833 char* tmp_key = NULL;
1834 guint i,keys_in_list = 0;
1837 decryption_key_t *new_key = NULL;
1838 GList *key_list = NULL;
1841 * To read the drivers general settings we need to create and use one airpcap adapter...
1842 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1844 airpcap_if_info_t* fake_info_if = NULL;
1846 /* Create the fake_info_if from the first adapter of the list */
1847 fake_info_if = airpcap_driver_fake_if_info_new();
1849 if(fake_info_if == NULL)
1852 /* Number of keys in key list */
1853 if(fake_info_if->keysCollectionSize != 0)
1854 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1858 for(i=0; i<keys_in_list; i++)
1860 /* Different things to do depending on the key type */
1861 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1863 /* allocate memory for the new key item */
1864 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1866 /* fill the fields */
1868 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1869 new_key->key = g_string_new(tmp_key);
1870 if(tmp_key != NULL) g_free(tmp_key);
1873 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1875 /* SSID not used in WEP keys */
1876 new_key->ssid = NULL;
1878 /* TYPE (WEP in this case) */
1879 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
1881 /* Append the new element in the list */
1882 key_list = g_list_append(key_list,(gpointer)new_key);
1884 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1886 /* XXX - Not supported yet */
1888 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1890 /* XXX - Not supported yet */
1894 airpcap_if_info_free(fake_info_if);
1900 * Returns the list of the decryption keys specified for wireshark, NULL if
1904 get_wireshark_keys(void)
1906 keys_cb_data_t* wep_user_data = NULL;
1908 GList* final_list = NULL;
1909 GList* wep_final_list = NULL;
1911 /* Retrieve the wlan preferences */
1912 wlan_prefs = prefs_find_module("wlan");
1914 /* Allocate a structure used to keep infos between the callbacks */
1915 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1917 /* Fill the structure */
1918 wep_user_data->list = NULL;
1919 wep_user_data->current_index = 0;
1920 wep_user_data->number_of_keys= 0; /* Still unknown */
1922 /* Run the callback on each 802.11 preference */
1923 /* XXX - Right now, only WEP keys will be loaded */
1924 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1926 /* Copy the list field in the user data structure pointer into the final_list */
1927 wep_final_list = wep_user_data->list;
1929 /* XXX - Merge the three lists!!!!! */
1930 final_list = wep_final_list;
1932 /* free the wep_user_data structure */
1933 g_free(wep_user_data);
1939 * Merges two lists of keys and return a newly created GList. If a key is
1940 * found multiple times, it will just appear once!
1941 * list1 and list 2 pointer will have to be freed manually if needed!!!
1942 * If the total number of keys exceeeds the maximum number allowed,
1943 * exceeding keys will be discarded...
1946 merge_key_list(GList* list1, GList* list2)
1950 decryption_key_t *dk1=NULL,
1954 GList* merged_list = NULL;
1956 if( (list1 == NULL) && (list2 == NULL) )
1961 n2 = g_list_length(list2);
1965 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1966 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1968 new_dk->bits = dk2->bits;
1969 new_dk->type = dk2->type;
1970 new_dk->key = g_string_new(dk2->key->str);
1971 new_dk->ssid = byte_array_dup(dk2->ssid);
1973 /* Check the total length of the merged list */
1974 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1975 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1978 else if(list2 == NULL)
1980 n1 = g_list_length(list1);
1984 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1985 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
1987 new_dk->bits = dk1->bits;
1988 new_dk->type = dk1->type;
1989 new_dk->key = g_string_new(dk1->key->str);
1990 new_dk->ssid = byte_array_dup(dk1->ssid);
1992 /* Check the total length of the merged list */
1993 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1994 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1999 n1 = g_list_length(list1);
2000 n2 = g_list_length(list2);
2002 /* Copy the whole list1 into merged_list */
2005 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2006 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2008 new_dk->bits = dk1->bits;
2009 new_dk->type = dk1->type;
2010 new_dk->key = g_string_new(dk1->key->str);
2011 new_dk->ssid = byte_array_dup(dk1->ssid);
2013 /* Check the total length of the merged list */
2014 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2015 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2018 /* Look for keys that are present in list2 but aren't in list1 yet...
2019 * Add them to merged_list
2023 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2025 if(!key_is_in_list(dk2,merged_list))
2027 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2029 new_dk->bits = dk2->bits;
2030 new_dk->type = dk2->type;
2031 new_dk->key = g_string_new(dk2->key->str);
2032 new_dk->ssid = byte_array_dup(dk2->ssid);
2034 /* Check the total length of the merged list */
2035 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2036 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2045 * Use this function to free a key list.
2048 free_key_list(GList *list)
2051 decryption_key_t *curr_key;
2056 n = g_list_length(list);
2058 for(i = 0; i < n; i++)
2060 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2062 /* Free all the strings */
2063 if(curr_key->key != NULL)
2064 g_string_free(curr_key->key, TRUE);
2066 if(curr_key->ssid != NULL)
2067 g_byte_array_free(curr_key->ssid, TRUE);
2069 /* free the decryption_key_t structure*/
2082 * If the given key is contained in the list, returns TRUE.
2083 * Returns FALSE otherwise.
2086 key_is_in_list(decryption_key_t *dk,GList *list)
2089 decryption_key_t* curr_key = NULL;
2090 gboolean found = FALSE;
2092 if( (list == NULL) || (dk == NULL) )
2095 n = g_list_length(list);
2100 for(i = 0; i < n; i++)
2102 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2103 if(keys_are_equals(dk,curr_key))
2111 * Returns TRUE if keys are equals, FALSE otherwise
2114 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2117 if((k1==NULL) || (k2==NULL))
2120 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2121 /** 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) ) **/
2122 /** return TRUE; **/
2124 if( g_string_equal(k1->key,k2->key) &&
2125 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2126 k1->type == k2->type)
2128 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2129 if((k1->ssid == NULL) && (k2->ssid == NULL))
2132 /* If they are not null, they must share the same ssid */
2133 return byte_array_equal(k1->ssid,k2->ssid);
2136 /* Some field is not equal ... */
2141 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2142 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2146 key_lists_are_equal(GList* list1, GList* list2)
2150 guint wep_n1=0,wep_n2=0;
2151 GList *wep_list1=NULL;
2152 GList *wep_list2=NULL;
2155 decryption_key_t *dk1=NULL,*dk2=NULL;
2157 n1 = g_list_length(list1);
2158 n2 = g_list_length(list2);
2161 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2166 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2167 if(dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2169 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2175 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2176 if(dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2178 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2184 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2189 * Commented, because in the new AirPcap version all the keys will be saved
2190 * into the driver, and all the keys for every specific adapter will be
2191 * removed. This means that this check will always fail... and the user will
2192 * always be asked what to do... and it doesn't make much sense.
2194 /* if(n1 != n2) return FALSE; */
2195 if(wep_n1 != wep_n2) return FALSE;
2201 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2202 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2204 if(!g_string_equal(dk1->key,dk2->key)) return FALSE;
2208 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2209 if(!key_is_in_list(dk2,wep_list1)) return FALSE;
2216 test_if_on(pref_t *pref, gpointer ud)
2221 /* Retrieve user data info */
2222 is_on = (gboolean*)ud;
2225 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2227 number = *pref->varp.boolp;
2229 if(number) *is_on = TRUE;
2230 else *is_on = FALSE;
2238 * Returns TRUE if the Wireshark decryption is active, false otherwise
2239 * XXX - Should we just add a routine to packet-ieee80211.c to grab this directly?
2242 wireshark_decryption_on(void)
2246 /* Retrieve the wlan preferences */
2247 wlan_prefs = prefs_find_module("wlan");
2249 /* Run the callback on each 802.11 preference */
2250 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2256 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2259 airpcap_decryption_on(void)
2261 gboolean is_on = FALSE;
2263 airpcap_if_info_t* fake_if_info = NULL;
2265 fake_if_info = airpcap_driver_fake_if_info_new();
2267 if(fake_if_info != NULL)
2269 if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2271 else if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2275 airpcap_if_info_free(fake_if_info);
2281 * Free an instance of airpcap_if_info_t
2284 airpcap_if_info_free(airpcap_if_info_t *if_info)
2288 if (if_info->name != NULL)
2289 g_free(if_info->name);
2291 if (if_info->description != NULL)
2292 g_free(if_info->description);
2294 if(if_info->keysCollection != NULL)
2296 g_free(if_info->keysCollection);
2297 if_info->keysCollection = NULL;
2300 if(if_info->ip_addr != NULL)
2302 g_slist_free(if_info->ip_addr);
2303 if_info->ip_addr = NULL;
2315 set_on_off(pref_t *pref, gpointer ud)
2319 /* Retrieve user data info */
2320 is_on = (gboolean*)ud;
2322 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2326 *pref->varp.boolp = TRUE;
2328 *pref->varp.boolp = FALSE;
2336 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2339 set_wireshark_decryption(gboolean on_off)
2345 /* Retrieve the wlan preferences */
2346 wlan_prefs = prefs_find_module("wlan");
2348 /* Run the callback on each 802.11 preference */
2349 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2352 * Signal that we've changed things, and run the 802.11 dissector's
2355 wlan_prefs->prefs_changed = TRUE;
2357 prefs_apply(wlan_prefs);
2361 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2364 set_airpcap_decryption(gboolean on_off)
2366 /* We need to directly access the .dll functions here... */
2367 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2368 PAirpcapHandle ad,ad_driver;
2370 gboolean success = TRUE;
2374 airpcap_if_info_t* curr_if = NULL;
2375 airpcap_if_info_t* fake_if_info = NULL;
2377 fake_if_info = airpcap_driver_fake_if_info_new();
2379 if(fake_if_info == NULL)
2380 /* We apparently don't have any adapters installed.
2381 * This isn't a failure, so return TRUE
2385 /* Set the driver decryption */
2386 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2390 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2392 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2394 airpcap_if_close(ad_driver);
2397 airpcap_if_info_free(fake_if_info);
2399 n = g_list_length(airpcap_if_list);
2401 /* Set to FALSE the decryption for all the adapters */
2402 /* Apply this change to all the adapters !!! */
2403 for(i = 0; i < n; i++)
2405 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2407 if( curr_if != NULL )
2409 ad = airpcap_if_open(curr_if->name, ebuf);
2412 curr_if->DecryptionOn = (gboolean)AIRPCAP_DECRYPTION_OFF;
2413 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2414 /* Save configuration for the curr_if */
2415 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
2419 airpcap_if_close(ad);
2428 /* DYNAMIC LIBRARY LOADER */
2430 * Used to dynamically load the airpcap library in order link it only when
2431 * it's present on the system
2433 int load_airpcap(void)
2436 gboolean base_functions = TRUE;
2437 gboolean eleven_n_functions = TRUE;
2439 if((AirpcapLib = ws_load_library("airpcap.dll")) == NULL)
2441 /* Report the error but go on */
2442 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2443 return AirpcapVersion;
2447 if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2448 if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2449 if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2450 if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2451 if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2452 if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2453 if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2454 if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2455 if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2456 if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2457 if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2458 if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2459 if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2460 if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2461 if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2462 if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2463 if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2464 if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2465 if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2466 if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2467 if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2468 if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2469 if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2470 if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2471 if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2472 if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2473 if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2474 if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2475 if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2476 if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2477 if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2478 if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2480 /* TEST IF AIRPCAP SUPPORTS 11N */
2481 if((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2482 if((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2483 if((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2485 if(base_functions && eleven_n_functions){
2486 AirpcapLoaded = TRUE;
2487 AirpcapVersion = AIRPCAP_DLL_OK;
2488 }else if(base_functions){
2489 AirpcapLoaded = TRUE;
2490 AirpcapVersion = AIRPCAP_DLL_OLD;
2491 return AIRPCAP_DLL_OK;
2493 AirpcapLoaded = FALSE;
2494 AirpcapVersion = AIRPCAP_DLL_ERROR;
2497 return AirpcapVersion;
2499 return AIRPCAP_DLL_NOT_FOUND;
2504 * Append the version of AirPcap with which we were compiled to a GString.
2507 get_compiled_airpcap_version(GString *str)
2509 g_string_append(str, "with AirPcap");
2513 * Append the version of AirPcap with which we we're running to a GString.
2516 get_runtime_airpcap_version(GString *str)
2518 guint vmaj, vmin, vrev, build;
2520 /* See if the DLL has been loaded successfully. Bail if it hasn't */
2521 if (AirpcapLoaded == FALSE) {
2522 g_string_append(str, "without AirPcap");
2526 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
2527 g_string_append_printf(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2530 #endif /* HAVE_AIRPCAP */