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 * Save the encryption keys, if we have any of them
355 KeysCollectionSize = 0;
358 * Calculate the size of the keys collection
360 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
363 * Allocate the collection
365 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
372 * Populate the key collection
374 KeysCollection->nKeys = keys_in_list;
376 for(i = 0; i < keys_in_list; i++)
378 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
380 /* Retrieve the Item corresponding to the i-th key */
381 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
382 new_key = g_string_new(key_item->key->str);
384 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
385 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
387 for(j = 0 ; j < new_key->len; j += 2)
389 s[0] = new_key->str[j];
390 s[1] = new_key->str[j+1];
392 KeyByte = (guint8)strtol(s, NULL, 16);
393 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
396 g_string_free(new_key,TRUE);
400 * Free the old adapter key collection!
402 if(info_if->keysCollection != NULL)
403 g_free(info_if->keysCollection);
406 * Set this collection ad the new one
408 info_if->keysCollection = KeysCollection;
409 info_if->keysCollectionSize = KeysCollectionSize;
412 * Configuration must be saved
414 info_if->saved = FALSE;
417 * Write down the changes to the registry
419 airpcap_save_selected_if_configuration(info_if);
425 * This function will tell the airpcap driver the key list to use
426 * This will be stored into the registry...
429 write_wlan_driver_wep_keys_to_registry(GList* key_list)
434 PAirpcapKeysCollection KeysCollection;
435 guint KeysCollectionSize;
437 guint keys_in_list = 0;
438 decryption_key_t* key_item = NULL;
439 airpcap_if_info_t* fake_info_if = NULL;
441 /* Create the fake_info_if from the first adapter of the list */
442 fake_info_if = airpcap_driver_fake_if_info_new();
444 if(fake_info_if == NULL)
448 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
449 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
451 n = g_list_length(key_list);
452 for(k = 0; k < n; k++ )
453 if(((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
457 * Save the encryption keys, if we have any of them
459 KeysCollectionSize = 0;
462 * Calculate the size of the keys collection
464 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
467 * Allocate the collection
469 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
476 * Populate the key collection
478 KeysCollection->nKeys = keys_in_list;
481 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
482 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
483 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
486 y = 0; /* Current position in the key list */
488 for(i = 0; i < n; i++)
490 /* Retrieve the Item corresponding to the i-th key */
491 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
494 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supported right now!
495 * We will have to modify the AirpcapKey structure in order to
496 * support the other two types! What happens now, is that simply the
497 * not supported keys will just be discarded (they will be saved in Wireshark though)
499 if(key_item->type == AIRPDCAP_KEY_TYPE_WEP)
501 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
503 new_key = g_string_new(key_item->key->str);
505 KeysCollection->Keys[y].KeyLen = (guint) new_key->len / 2;
506 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
508 for(j = 0 ; j < new_key->len; j += 2)
510 s[0] = new_key->str[j];
511 s[1] = new_key->str[j+1];
513 KeyByte = (guint8)strtol(s, NULL, 16);
514 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
516 /* XXX - Change when WPA will be supported!!! */
518 g_string_free(new_key,TRUE);
520 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
522 /* XXX - The driver cannot deal with this kind of key yet... */
524 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
526 /* XXX - The driver cannot deal with this kind of key yet... */
531 * Free the old adapter key collection!
533 if(fake_info_if->keysCollection != NULL)
534 g_free(fake_info_if->keysCollection);
537 * Set this collection ad the new one
539 fake_info_if->keysCollection = KeysCollection;
540 fake_info_if->keysCollectionSize = KeysCollectionSize;
543 * Configuration must be saved
545 fake_info_if->saved = FALSE;
548 * Write down the changes to the registry
550 airpcap_save_driver_if_configuration(fake_info_if);
552 airpcap_if_info_free(fake_info_if);
558 * Function used to save to the preference file the Decryption Keys.
561 save_wlan_driver_wep_keys(void)
563 GList* key_list = NULL;
564 char* tmp_key = NULL;
565 guint keys_in_list,i;
566 keys_cb_data_t* user_data;
567 airpcap_if_info_t* fake_info_if = NULL;
569 /* Create the fake_info_if from the first adapter of the list */
570 fake_info_if = airpcap_driver_fake_if_info_new();
572 if(fake_info_if == NULL)
575 /* Retrieve the wlan preferences */
576 wlan_prefs = prefs_find_module("wlan");
578 /* Allocate a structure used to keep infos between the callbacks */
579 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
581 /* Number of keys in key list */
582 if(fake_info_if->keysCollectionSize != 0)
583 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
587 for(i=0; i<keys_in_list; i++)
589 /* Only if it is a WEP key... */
590 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
592 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
593 key_list = g_list_append(key_list,g_strdup(tmp_key));
598 /* Now we know the exact number of WEP keys in the list, so store it ... */
599 keys_in_list = g_list_length(key_list);
601 /* Fill the structure */
602 user_data->list = key_list;
603 user_data->current_index = 0;
604 user_data->number_of_keys= keys_in_list;
606 /* Retrieve the wlan preferences */
607 wlan_prefs = prefs_find_module("wlan");
609 /* Run the callback on each 802.11 preference */
610 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
612 /* Signal that we've changed things, and run the 802.11 dissector's
614 wlan_prefs->prefs_changed = TRUE;
616 /* Apply changes for the specified preference */
617 prefs_apply(wlan_prefs);
620 /* free the WEP key string */
621 for(i=0;i<g_list_length(user_data->list);i++)
623 g_free(g_list_nth(user_data->list,i)->data);
626 /* free the (empty) list */
627 g_list_free(user_data->list);
629 /* free the user_data structure */
632 airpcap_if_info_free(fake_info_if);
638 * Function used to save to the preference file the Decryption Keys.
641 save_wlan_wireshark_wep_keys(GList* key_ls)
643 GList* key_list = NULL;
644 guint keys_in_list,i;
645 keys_cb_data_t* user_data;
646 decryption_key_t* tmp_dk;
648 /* Retrieve the wlan preferences */
649 wlan_prefs = prefs_find_module("wlan");
651 /* Allocate a structure used to keep infos between the callbacks */
652 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
654 keys_in_list = g_list_length(key_ls);
658 /* Fill the structure */
659 user_data->list = key_list;
660 user_data->current_index = 0;
661 user_data->number_of_keys= keys_in_list;
663 /* Retrieve the wlan preferences */
664 wlan_prefs = prefs_find_module("wlan");
666 /* Run the callback on each 802.11 preference */
667 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
669 /* Signal that we've changed things, and run the 802.11 dissector's
671 wlan_prefs->prefs_changed = TRUE;
673 /* Apply changes for the specified preference */
674 prefs_apply(wlan_prefs);
677 /* free the WEP key string */
678 for(i=0;i<g_list_length(user_data->list);i++)
680 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
681 g_string_free(tmp_dk->key,TRUE);
682 if(tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
685 /* free the (empty) list */
686 g_list_free(user_data->list);
688 /* free the user_data structure */
695 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
696 * "get_airpcap_interface_list()".
699 cant_get_airpcap_if_list_error_message(const char *err_str)
701 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
705 * Airpcap wrapper, used to store the current settings for the selected adapter
708 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
710 if (!AirpcapLoaded) return FALSE;
711 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
715 * Airpcap wrapper, used to open an airpcap adapter
718 airpcap_if_open(gchar * name, gchar * err)
720 if (!AirpcapLoaded) return NULL;
721 if (name == NULL) return NULL;
722 return g_PAirpcapOpen(name,err);
726 * Airpcap wrapper, used to close an airpcap adapter
729 airpcap_if_close(PAirpcapHandle handle)
731 if (!AirpcapLoaded) return;
732 g_PAirpcapClose(handle);
736 * Retrieve the state of the Airpcap DLL
739 airpcap_get_dll_state(void)
741 return AirpcapVersion;
745 * Airpcap wrapper, used to turn on the led of an airpcap adapter
748 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber)
750 if (!AirpcapLoaded) return FALSE;
751 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
755 * Airpcap wrapper, used to turn off the led of an airpcap adapter
758 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber)
760 if (!AirpcapLoaded) return FALSE;
761 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
765 * Airpcap wrapper, used to get the channel of an airpcap adapter
768 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch)
770 if (!AirpcapLoaded) return FALSE;
771 return g_PAirpcapGetDeviceChannel(ah,ch);
775 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
778 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint * nInfo)
780 if (!AirpcapLoaded) return FALSE;
781 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
782 *nInfo = num_legacy_channels;
783 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
786 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
787 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
793 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
796 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint * pNumSupportedChannels)
798 AirpcapChannelInfo *chanInfo;
799 guint i=0, j=0, numInfo = 0;
803 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
805 numSupportedChannels = 0;
808 * allocate a bigger array
813 pSupportedChannels = g_malloc(numInfo * (sizeof *pSupportedChannels));
815 for (i = 0; i < numInfo; i++)
817 guint supportedChannel = G_MAXUINT;
820 * search if we have it already
822 for (j = 0; j < numSupportedChannels; j++)
824 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
826 supportedChannel = j;
831 if (supportedChannel == G_MAXUINT)
834 * not found, create a new item
836 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
838 switch(chanInfo[i].ExtChannel)
841 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
844 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
848 pSupportedChannels[numSupportedChannels].Flags = 0;
852 * Gather channel information
855 pSupportedChannels[numSupportedChannels].Flags |=
856 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
857 FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
858 pSupportedChannels[numSupportedChannels].Channel =
859 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
860 numSupportedChannels++;
865 * just update the ext channel flags
867 switch(chanInfo[i].ExtChannel)
870 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
873 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
882 if (numSupportedChannels < 1)
885 * Now sort the list by frequency
887 for (i = 0 ; i < numSupportedChannels - 1; i++)
889 for (j = i + 1; j < numSupportedChannels; j++)
891 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
893 Dot11Channel temp = pSupportedChannels[i];
894 pSupportedChannels[i] = pSupportedChannels[j];
895 pSupportedChannels[j] = temp;
900 *pNumSupportedChannels = numSupportedChannels;
901 return pSupportedChannels;
905 * Airpcap wrapper, used to set the channel of an airpcap adapter
908 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch)
910 if (!AirpcapLoaded) return FALSE;
911 return g_PAirpcapSetDeviceChannel(ah,ch);
915 * Airpcap wrapper, used to set the frequency of an airpcap adapter
918 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
920 if (!AirpcapLoaded) return FALSE;
921 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
923 channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
928 return airpcap_if_set_device_channel(ah, channel);
930 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
931 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
938 * Airpcap wrapper, used to get the frequency of an airpcap adapter
941 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
943 if (!AirpcapLoaded) return FALSE;
945 pChannelInfo->Frequency = 0;
946 pChannelInfo->ExtChannel = 0;
947 pChannelInfo->Reserved[0] = 0;
948 pChannelInfo->Reserved[1] = 0;
949 pChannelInfo->Reserved[2] = 0;
951 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
955 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
957 chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
958 if (chan_freq == 0) return FALSE;
959 pChannelInfo->Frequency = chan_freq;
962 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
963 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
969 * Airpcap wrapper, used to get the link type of an airpcap adapter
972 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
974 if (!AirpcapLoaded) return FALSE;
975 return g_PAirpcapGetLinkType(ah,lt);
979 * Airpcap wrapper, used to set the link type of an airpcap adapter
982 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
984 if (!AirpcapLoaded) return FALSE;
985 return g_PAirpcapSetLinkType(ah,lt);
989 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
992 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * fcs)
994 if (!AirpcapLoaded) return FALSE;
995 return g_PAirpcapGetFcsPresence(ah,fcs);
999 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
1002 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean fcs)
1004 if (!AirpcapLoaded) return FALSE;
1005 return g_PAirpcapSetFcsPresence(ah,fcs);
1009 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
1012 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1014 if (!AirpcapLoaded) return FALSE;
1015 return g_PAirpcapGetDecryptionState(ah,PEnable);
1019 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1022 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1024 if (!AirpcapLoaded) return FALSE;
1025 return g_PAirpcapSetDecryptionState(ah,Enable);
1029 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1032 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1034 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1035 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1039 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1042 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1044 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1045 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1049 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1052 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1054 if (!AirpcapLoaded) return FALSE;
1055 return g_PAirpcapGetFcsValidation(ah,val);
1059 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1062 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1064 if (!AirpcapLoaded) return FALSE;
1065 return g_PAirpcapSetFcsValidation(ah,val);
1069 * Airpcap wrapper, used to save the settings for the selected_if
1072 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1074 if (!AirpcapLoaded) return FALSE;
1075 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1079 * Airpcap wrapper, used to save the settings for the selected_if
1082 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1084 if (!AirpcapLoaded) return FALSE;
1085 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1089 * Airpcap wrapper, used to save the driver's set of keys
1092 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1094 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1095 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1099 * Airpcap wrapper, used to load the driver's set of keys
1102 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1104 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1105 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1109 * This function will create a new airpcap_if_info_t using a name and a description
1112 airpcap_if_info_new(char *name, char *description)
1115 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1117 airpcap_if_info_t *if_info = NULL;
1119 /* Probably I have to switch on the leds!!! */
1120 ad = airpcap_if_open(name, ebuf);
1123 if_info = g_malloc0(sizeof (airpcap_if_info_t));
1124 if_info->name = g_strdup(name);
1125 if (description == NULL){
1126 if_info->description = NULL;
1128 if_info->description = g_strdup(description);
1131 if_info->ip_addr = NULL;
1132 if_info->loopback = FALSE;
1133 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1134 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1135 airpcap_if_get_link_type(ad,&(if_info->linkType));
1136 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1137 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1138 airpcap_if_turn_led_on(ad, 0);
1139 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1140 if_info->led = TRUE;
1141 if_info->blinking = FALSE;
1142 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1144 /* get the keys, if everything is ok, close the adapter */
1145 if(airpcap_if_load_keys(ad,if_info))
1147 airpcap_if_close(ad);
1154 * This function will create a new fake drivers' interface, to load global keys...
1157 airpcap_driver_fake_if_info_new(void)
1160 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1162 airpcap_if_info_t *if_info = NULL;
1163 airpcap_if_info_t *fake_if_info = NULL;
1165 /* Maybe for some reason no airpcap adapter is found */
1166 if(airpcap_if_list == NULL)
1170 * Retrieve the first AirPcap adapter available. If no interface is found,
1171 * it is not possible to retrieve the driver's settings, so return NULL.
1173 if_info = g_list_nth_data(airpcap_if_list,0);
1177 /* Open the 'fake' adapter */
1178 ad = airpcap_if_open(if_info->name, ebuf);
1181 fake_if_info = g_malloc(sizeof (airpcap_if_info_t));
1182 fake_if_info->name = g_strdup(if_info->name);
1183 fake_if_info->description = g_strdup(if_info->description);
1184 fake_if_info->loopback = FALSE;
1185 fake_if_info->ip_addr = NULL;
1186 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1187 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1188 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1189 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1190 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1191 airpcap_if_turn_led_on(ad, 0);
1192 fake_if_info->led = TRUE;
1193 fake_if_info->blinking = FALSE;
1194 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1196 /* get the keys, if everything is ok, close the adapter */
1197 if(airpcap_if_load_driver_keys(ad,fake_if_info))
1199 airpcap_if_close(ad);
1203 return fake_if_info;
1207 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1210 airpcap_if_info_print(airpcap_if_info_t* if_info)
1215 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1219 g_print("\n----------------- AirPcap Interface \n");
1220 g_print(" NAME: %s\n",if_info->name);
1221 g_print(" DESCRIPTION: %s\n",if_info->description);
1222 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1223 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1224 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1225 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1226 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1227 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1228 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1229 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1230 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1231 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1232 g_print(" LINKTYPE: %d\n",if_info->linkType);
1233 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1234 g_print(" (GTK) TAG: %d\n",if_info->tag);
1235 g_print("SUPPORTED CHANNELS POINTER: %p\n",if_info->pSupportedChannels);
1236 g_print(" NUM SUPPORTED CHANNELS: %u\n",if_info->numSupportedChannels);
1238 for(i=0; i<(if_info->numSupportedChannels); i++){
1239 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1240 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1241 g_print(" FREQUENCY: %u\n",if_info->pSupportedChannels[i].Frequency);
1242 g_print(" FLAGS: %u\n",if_info->pSupportedChannels[i].Flags);
1248 * Function used to load the WEP keys for a selected interface
1251 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1253 if(!if_info) return FALSE;
1255 if_info->keysCollectionSize = 0;
1256 if_info->keysCollection = NULL;
1258 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1260 if(if_info->keysCollectionSize == 0)
1262 if_info->keysCollection = NULL;
1263 airpcap_if_close(ad);
1267 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1268 if(!if_info->keysCollection)
1270 if_info->keysCollectionSize = 0;
1271 if_info->keysCollection = NULL;
1272 airpcap_if_close(ad);
1276 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1280 airpcap_if_close(ad);
1285 * Function used to load the WEP keys for a selected interface
1288 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1290 if_info->keysCollectionSize = 0;
1291 if_info->keysCollection = NULL;
1293 if(!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1295 if(if_info->keysCollectionSize == 0)
1297 if_info->keysCollection = NULL;
1298 airpcap_if_close(ad);
1302 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1303 if(!if_info->keysCollection)
1305 if_info->keysCollectionSize = 0;
1306 if_info->keysCollection = NULL;
1307 airpcap_if_close(ad);
1311 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1315 airpcap_if_close(ad);
1320 * Function used to save the WEP keys for a selected interface
1323 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1325 if(!if_info || !AirpcapLoaded) return;
1327 if(if_info->keysCollection != NULL)
1328 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1332 * Function used to save the WEP keys for a selected interface
1335 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1337 if(if_info->keysCollection != NULL)
1338 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1342 * Callback used to free an instance of airpcap_if_info_t
1345 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1347 airpcap_if_info_t *if_info = data;
1349 if (if_info->name != NULL)
1350 g_free(if_info->name);
1352 if (if_info->description != NULL)
1353 g_free(if_info->description);
1355 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1356 if(if_info->keysCollection != NULL)
1358 g_free(if_info->keysCollection);
1359 if_info->keysCollection = NULL;
1362 if(if_info->ip_addr != NULL)
1363 g_slist_free(if_info->ip_addr);
1370 * Function used to free the airpcap interface list
1373 free_airpcap_interface_list(GList *if_list)
1375 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1376 g_list_free(if_list);
1381 * This function will use the airpcap.dll to find all the airpcap devices.
1382 * Will return null if no device is found.
1385 get_airpcap_interface_list(int *err, char **err_str)
1388 airpcap_if_info_t *if_info;
1390 AirpcapDeviceDescription *devsList, *adListEntry;
1391 char errbuf[PCAP_ERRBUF_SIZE];
1397 *err = AIRPCAP_NOT_LOADED;
1401 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1403 /* No interfaces, return il = NULL; */
1404 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1405 if (err_str != NULL)
1406 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1411 * Count the adapters
1413 adListEntry = devsList;
1418 adListEntry = adListEntry->next;
1423 /* No interfaces, return il= NULL */
1424 g_PAirpcapFreeDeviceList(devsList);
1425 *err = NO_AIRPCAP_INTERFACES_FOUND;
1426 if (err_str != NULL)
1432 * Insert the adapters in our list
1434 adListEntry = devsList;
1437 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1438 if (if_info != NULL){
1439 il = g_list_append(il, if_info);
1442 adListEntry = adListEntry->next;
1445 g_PAirpcapFreeDeviceList(devsList);
1451 * Used to retrieve the interface given the name
1452 * (the name is used in AirpcapOpen)
1454 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
1457 airpcap_if_info_t* if_info;
1459 for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
1460 if_info = (airpcap_if_info_t *)curr->data;
1461 if (if_info && (g_ascii_strcasecmp(if_info->name, name) == 0)) {
1469 * Returns the ASCII string of a key given the key bytes
1472 airpcap_get_key_string(AirpcapKey key)
1480 if(key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1484 /* Allocate the string used to store the ASCII representation of the WEP key */
1485 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1486 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1489 for(j = 0; j < key.KeyLen; j++)
1491 src = g_strdup_printf("%.2x", key.KeyData[j]);
1493 * XXX - use g_strconcat() or GStrings instead ???
1495 g_strlcat(dst, src, WEP_KEY_MAX_CHAR_SIZE+1);
1500 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1502 /* XXX - Add code here */
1504 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1506 /* XXX - Add code here */
1510 /* XXX - Add code here */
1517 * Clear keys and decryption status for the specified interface
1520 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1524 if(info_if->keysCollection != NULL)
1526 g_free(info_if->keysCollection);
1527 info_if->keysCollection = NULL;
1530 info_if->keysCollectionSize = 0;
1532 info_if->DecryptionOn = FALSE;
1533 info_if->saved = FALSE;
1538 * Used to retrieve the two chars string from interface
1541 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1547 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1549 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1550 * Otherwise, check if it is the "Any" adapter...
1554 if(g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1555 number = g_strdup_printf("??");
1557 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1561 number = g_strdup_printf("%.2u",n);
1568 * Used to retrieve the two chars string from interface
1571 airpcap_get_if_string_number_from_description(gchar* description)
1576 number = (gchar*)g_malloc(sizeof(gchar)*3);
1578 pointer = g_strrstr(description,"#\0");
1580 number[0] = *(pointer+1);
1581 number[1] = *(pointer+2);
1588 * Returns the default airpcap interface of a list, NULL if list is empty
1591 airpcap_get_default_if(GList* airpcap_if_list)
1594 airpcap_if_info_t* if_info = NULL;
1596 if(prefs.capture_device != NULL)
1598 s = g_strdup(get_if_name(prefs.capture_device));
1599 if_info = get_airpcap_if_from_name(airpcap_if_list,g_strdup(get_if_name(prefs.capture_device)));
1606 * Load the configuration for the specified interface
1609 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1611 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1616 ad = airpcap_if_open(if_info->name, ebuf);
1620 /* Stop blinking (if it was blinking!)*/
1621 if(if_info->blinking)
1623 /* Turn on the light (if it was off) */
1624 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1627 /* Apply settings... */
1628 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1629 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1630 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1631 airpcap_if_get_link_type(ad,&(if_info->linkType));
1632 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1633 /* get the keys, if everything is ok, close the adapter */
1634 if(airpcap_if_load_keys(ad,if_info))
1635 airpcap_if_close(ad);
1637 if_info->saved = TRUE;
1641 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1647 * Save the configuration for the specified interface
1650 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1652 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1657 ad = airpcap_if_open(if_info->name, ebuf);
1661 /* Stop blinking (if it was blinking!)*/
1662 if(if_info->blinking)
1664 /* Turn on the light (if it was off) */
1665 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1668 /* Apply settings... */
1669 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1670 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1671 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1672 airpcap_if_set_link_type(ad,if_info->linkType);
1673 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1674 airpcap_if_save_keys(ad,if_info);
1676 /* ... and save them */
1677 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1679 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.");
1680 if_info->saved = FALSE;
1681 airpcap_if_close(ad);
1685 if_info->saved = TRUE;
1686 airpcap_if_close(ad);
1690 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1696 * Save the configuration for the specified interface
1699 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1701 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1704 if(fake_if_info != NULL)
1706 ad = airpcap_if_open(fake_if_info->name, ebuf);
1710 /* Apply decryption settings... */
1711 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1712 airpcap_if_save_driver_keys(ad,fake_if_info);
1713 airpcap_if_close(ad);
1717 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1725 * DECRYPTION KEYS FUNCTIONS
1728 * This function is used for DEBUG POURPOSES ONLY!!!
1731 print_key_list(GList* key_list)
1734 decryption_key_t* tmp;
1736 if(key_list == NULL)
1738 g_print("\n\n******* KEY LIST NULL *******\n\n");
1742 n = g_list_length(key_list);
1744 g_print("\n\n********* KEY LIST **********\n\n");
1746 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1748 for(i =0; i < n; i++)
1750 g_print("[%d] :\n",i+1);
1751 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1752 g_print("KEY : %s\n",tmp->key->str);
1754 g_print("BITS: %d\n",tmp->bits);
1756 if(tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1757 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1758 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1759 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1760 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1761 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1763 g_print("TYPE: %s\n","???");
1765 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1766 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1770 g_print("\n*****************************\n\n");
1774 * Retrieves a GList of decryption_key_t structures containing infos about the
1775 * keys for the given adapter... returns NULL if no keys are found.
1778 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1781 char* tmp_key = NULL;
1782 guint i,keys_in_list = 0;
1785 decryption_key_t *new_key = NULL;
1786 GList *key_list = NULL;
1788 /* Number of keys in key list */
1789 if(info_if->keysCollectionSize != 0)
1790 keys_in_list = (guint)(info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1794 for(i=0; i<keys_in_list; i++)
1796 /* Different things to do depending on the key type */
1797 if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1799 /* allocate memory for the new key item */
1800 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1802 /* fill the fields */
1804 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1805 new_key->key = g_string_new(tmp_key);
1809 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1811 /* SSID not used in WEP keys */
1812 new_key->ssid = NULL;
1814 /* TYPE (WEP in this case) */
1815 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1817 /* Append the new element in the list */
1818 key_list = g_list_append(key_list,(gpointer)new_key);
1820 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1822 /* XXX - Not supported yet */
1824 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1826 /* XXX - Not supported yet */
1834 * Retrieves a GList of decryption_key_t structures containing infos about the
1835 * keys for the global AirPcap driver... returns NULL if no keys are found.
1838 get_airpcap_driver_keys(void)
1841 char* tmp_key = NULL;
1842 guint i,keys_in_list = 0;
1845 decryption_key_t *new_key = NULL;
1846 GList *key_list = NULL;
1849 * To read the drivers general settings we need to create and use one airpcap adapter...
1850 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1852 airpcap_if_info_t* fake_info_if = NULL;
1854 /* Create the fake_info_if from the first adapter of the list */
1855 fake_info_if = airpcap_driver_fake_if_info_new();
1857 if(fake_info_if == NULL)
1860 /* Number of keys in key list */
1861 if(fake_info_if->keysCollectionSize != 0)
1862 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1866 for(i=0; i<keys_in_list; i++)
1868 /* Different things to do depending on the key type */
1869 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1871 /* allocate memory for the new key item */
1872 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1874 /* fill the fields */
1876 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1877 new_key->key = g_string_new(tmp_key);
1878 if(tmp_key != NULL) g_free(tmp_key);
1881 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1883 /* SSID not used in WEP keys */
1884 new_key->ssid = NULL;
1886 /* TYPE (WEP in this case) */
1887 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
1889 /* Append the new element in the list */
1890 key_list = g_list_append(key_list,(gpointer)new_key);
1892 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1894 /* XXX - Not supported yet */
1896 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1898 /* XXX - Not supported yet */
1902 airpcap_if_info_free(fake_info_if);
1908 * Returns the list of the decryption keys specified for wireshark, NULL if
1912 get_wireshark_keys(void)
1914 keys_cb_data_t* wep_user_data = NULL;
1916 GList* final_list = NULL;
1917 GList* wep_final_list = NULL;
1919 /* Retrieve the wlan preferences */
1920 wlan_prefs = prefs_find_module("wlan");
1922 /* Allocate a structure used to keep infos between the callbacks */
1923 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1925 /* Fill the structure */
1926 wep_user_data->list = NULL;
1927 wep_user_data->current_index = 0;
1928 wep_user_data->number_of_keys= 0; /* Still unknown */
1930 /* Run the callback on each 802.11 preference */
1931 /* XXX - Right now, only WEP keys will be loaded */
1932 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1934 /* Copy the list field in the user data structure pointer into the final_list */
1935 if(wep_user_data != NULL) wep_final_list = wep_user_data->list;
1937 /* XXX - Merge the three lists!!!!! */
1938 final_list = wep_final_list;
1940 /* free the wep_user_data structure */
1941 g_free(wep_user_data);
1947 * Merges two lists of keys and return a newly created GList. If a key is
1948 * found multiple times, it will just appear once!
1949 * list1 and list 2 pointer will have to be freed manually if needed!!!
1950 * If the total number of keys exceeeds the maximum number allowed,
1951 * exceeding keys will be discarded...
1954 merge_key_list(GList* list1, GList* list2)
1958 decryption_key_t *dk1=NULL,
1962 GList* merged_list = NULL;
1964 if( (list1 == NULL) && (list2 == NULL) )
1970 n2 = g_list_length(list2);
1974 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1975 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1977 new_dk->bits = dk2->bits;
1978 new_dk->type = dk2->type;
1979 new_dk->key = g_string_new(dk2->key->str);
1980 new_dk->ssid = byte_array_dup(dk2->ssid);
1982 /* Check the total length of the merged list */
1983 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1984 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1987 else if(list2 == NULL)
1989 n1 = g_list_length(list1);
1994 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1995 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
1997 new_dk->bits = dk1->bits;
1998 new_dk->type = dk1->type;
1999 new_dk->key = g_string_new(dk1->key->str);
2000 new_dk->ssid = byte_array_dup(dk1->ssid);
2002 /* Check the total length of the merged list */
2003 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2004 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2009 n1 = g_list_length(list1);
2010 n2 = g_list_length(list2);
2012 /* Copy the whole list1 into merged_list */
2015 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2016 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2018 new_dk->bits = dk1->bits;
2019 new_dk->type = dk1->type;
2020 new_dk->key = g_string_new(dk1->key->str);
2021 new_dk->ssid = byte_array_dup(dk1->ssid);
2023 /* Check the total length of the merged list */
2024 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2025 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2028 /* Look for keys that are present in list2 but aren't in list1 yet...
2029 * Add them to merged_list
2033 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2035 if(!key_is_in_list(dk2,merged_list))
2037 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2039 new_dk->bits = dk2->bits;
2040 new_dk->type = dk2->type;
2041 new_dk->key = g_string_new(dk2->key->str);
2042 new_dk->ssid = byte_array_dup(dk2->ssid);
2044 /* Check the total length of the merged list */
2045 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2046 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2055 * Use this function to free a key list.
2058 free_key_list(GList *list)
2061 decryption_key_t *curr_key;
2066 n = g_list_length(list);
2068 for(i = 0; i < n; i++)
2070 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2072 /* Free all the strings */
2073 if(curr_key->key != NULL)
2074 g_string_free(curr_key->key, TRUE);
2076 if(curr_key->ssid != NULL)
2077 g_byte_array_free(curr_key->ssid, TRUE);
2079 /* free the decryption_key_t structure*/
2092 * If the given key is contained in the list, returns TRUE.
2093 * Returns FALSE otherwise.
2096 key_is_in_list(decryption_key_t *dk,GList *list)
2099 decryption_key_t* curr_key = NULL;
2100 gboolean found = FALSE;
2102 if( (list == NULL) || (dk == NULL) )
2105 n = g_list_length(list);
2110 for(i = 0; i < n; i++)
2112 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2113 if(keys_are_equals(dk,curr_key))
2121 * Returns TRUE if keys are equals, FALSE otherwise
2124 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2127 if((k1==NULL) || (k2==NULL))
2130 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2131 /** 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) ) **/
2132 /** return TRUE; **/
2134 if( g_string_equal(k1->key,k2->key) &&
2135 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2136 k1->type == k2->type)
2138 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2139 if((k1->ssid == NULL) && (k2->ssid == NULL))
2142 /* If they are not null, they must share the same ssid */
2143 return byte_array_equal(k1->ssid,k2->ssid);
2146 /* Some field is not equal ... */
2151 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2152 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2156 key_lists_are_equal(GList* list1, GList* list2)
2160 guint wep_n1=0,wep_n2=0;
2161 GList *wep_list1=NULL;
2162 GList *wep_list2=NULL;
2165 decryption_key_t *dk1=NULL,*dk2=NULL;
2167 n1 = g_list_length(list1);
2168 n2 = g_list_length(list2);
2171 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2176 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2177 if(dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2179 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2185 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2186 if(dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2188 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2194 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2199 * Commented, because in the new AirPcap version all the keys will be saved
2200 * into the driver, and all the keys for every specific adapter will be
2201 * removed. This means that this check will always fail... and the user will
2202 * always be asked what to do... and it doesn't make much sense.
2204 /* if(n1 != n2) return FALSE; */
2205 if(wep_n1 != wep_n2) return FALSE;
2212 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2213 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2215 if(!g_string_equal(dk1->key,dk2->key)) return FALSE;
2219 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2220 if(!key_is_in_list(dk2,wep_list1)) return FALSE;
2227 test_if_on(pref_t *pref, gpointer ud)
2232 /* Retrieve user data info */
2233 is_on = (gboolean*)ud;
2236 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2238 number = *pref->varp.boolp;
2240 if(number) *is_on = TRUE;
2241 else *is_on = FALSE;
2249 * Returns TRUE if the Wireshark decryption is active, false otherwise
2250 * XXX - Should we just add a routine to packet-ieee80211.c to grab this directly?
2253 wireshark_decryption_on(void)
2257 /* Retrieve the wlan preferences */
2258 wlan_prefs = prefs_find_module("wlan");
2260 /* Run the callback on each 802.11 preference */
2261 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2267 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2270 airpcap_decryption_on(void)
2272 gboolean is_on = FALSE;
2274 airpcap_if_info_t* fake_if_info = NULL;
2276 fake_if_info = airpcap_driver_fake_if_info_new();
2278 if(fake_if_info != NULL)
2280 if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2282 else if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2286 airpcap_if_info_free(fake_if_info);
2292 * Free an instance of airpcap_if_info_t
2295 airpcap_if_info_free(airpcap_if_info_t *if_info)
2299 if (if_info->name != NULL)
2300 g_free(if_info->name);
2302 if (if_info->description != NULL)
2303 g_free(if_info->description);
2305 if(if_info->keysCollection != NULL)
2307 g_free(if_info->keysCollection);
2308 if_info->keysCollection = NULL;
2311 if(if_info->ip_addr != NULL)
2313 g_slist_free(if_info->ip_addr);
2314 if_info->ip_addr = NULL;
2326 set_on_off(pref_t *pref, gpointer ud)
2331 /* Retrieve user data info */
2332 is_on = (gboolean*)ud;
2334 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2336 number = *pref->varp.boolp;
2339 *pref->varp.boolp = TRUE;
2341 *pref->varp.boolp = FALSE;
2349 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2352 set_wireshark_decryption(gboolean on_off)
2358 /* Retrieve the wlan preferences */
2359 wlan_prefs = prefs_find_module("wlan");
2361 /* Run the callback on each 802.11 preference */
2362 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2365 * Signal that we've changed things, and run the 802.11 dissector's
2368 wlan_prefs->prefs_changed = TRUE;
2370 prefs_apply(wlan_prefs);
2374 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2377 set_airpcap_decryption(gboolean on_off)
2379 /* We need to directly access the .dll functions here... */
2380 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2381 PAirpcapHandle ad,ad_driver;
2383 gboolean success = TRUE;
2387 airpcap_if_info_t* curr_if = NULL;
2388 airpcap_if_info_t* fake_if_info = NULL;
2390 fake_if_info = airpcap_driver_fake_if_info_new();
2392 if(fake_if_info == NULL)
2393 /* We apparently don't have any adapters installed.
2394 * This isn't a failure, so return TRUE
2398 /* Set the driver decryption */
2399 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2403 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2405 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2407 airpcap_if_close(ad_driver);
2410 airpcap_if_info_free(fake_if_info);
2412 n = g_list_length(airpcap_if_list);
2414 /* Set to FALSE the decryption for all the adapters */
2415 /* Apply this change to all the adapters !!! */
2416 for(i = 0; i < n; i++)
2418 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2420 if( curr_if != NULL )
2422 ad = airpcap_if_open(curr_if->name, ebuf);
2425 curr_if->DecryptionOn = (gboolean)AIRPCAP_DECRYPTION_OFF;
2426 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2427 /* Save configuration for the curr_if */
2428 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
2432 airpcap_if_close(ad);
2441 /* DYNAMIC LIBRARY LOADER */
2443 * Used to dynamically load the airpcap library in order link it only when
2444 * it's present on the system
2446 int load_airpcap(void)
2449 gboolean base_functions = TRUE;
2450 gboolean eleven_n_functions = TRUE;
2452 if((AirpcapLib = ws_load_library("airpcap.dll")) == NULL)
2454 /* Report the error but go on */
2455 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2456 return AirpcapVersion;
2460 if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2461 if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2462 if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2463 if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2464 if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2465 if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2466 if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2467 if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2468 if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2469 if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2470 if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2471 if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2472 if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2473 if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2474 if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2475 if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2476 if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2477 if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2478 if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2479 if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2480 if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2481 if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2482 if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2483 if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2484 if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2485 if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2486 if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2487 if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2488 if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2489 if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2490 if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2491 if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2493 /* TEST IF AIRPCAP SUPPORTS 11N */
2494 if((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2495 if((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2496 if((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2498 if(base_functions && eleven_n_functions){
2499 AirpcapLoaded = TRUE;
2500 AirpcapVersion = AIRPCAP_DLL_OK;
2501 }else if(base_functions){
2502 AirpcapLoaded = TRUE;
2503 AirpcapVersion = AIRPCAP_DLL_OLD;
2504 return AIRPCAP_DLL_OK;
2506 AirpcapLoaded = FALSE;
2507 AirpcapVersion = AIRPCAP_DLL_ERROR;
2510 return AirpcapVersion;
2512 return AIRPCAP_DLL_NOT_FOUND;
2517 * Append the version of AirPcap with which we were compiled to a GString.
2520 get_compiled_airpcap_version(GString *str)
2522 g_string_append(str, "with AirPcap");
2526 * Append the version of AirPcap with which we we're running to a GString.
2529 get_runtime_airpcap_version(GString *str)
2531 guint vmaj, vmin, vrev, build;
2533 /* See if the DLL has been loaded successfully. Bail if it hasn't */
2534 if (AirpcapLoaded == FALSE) {
2535 g_string_append(str, "without AirPcap");
2539 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
2540 g_string_append_printf(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2543 #endif /* HAVE_AIRPCAP */