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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
40 #include <epan/packet.h>
41 #include <epan/prefs.h>
42 #include <epan/prefs-int.h>
43 #include <epan/crypt/wep-wpadefs.h>
44 #include <epan/crypt/airpdcap_ws.h>
45 #include <epan/strutil.h>
46 #include <epan/frequency-utils.h>
47 #include "capture_ui_utils.h"
48 #include <wsutil/file_util.h>
50 #include "ui/simple_dialog.h"
53 #include "airpcap_loader.h"
57 * Set to TRUE if the DLL was successfully loaded AND all functions
60 static gboolean AirpcapLoaded = FALSE;
64 * We load dynamically the dag library in order link it only when
65 * it's present on the system
67 static void * AirpcapLib = NULL;
69 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
70 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
71 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
72 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
73 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
74 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
75 static AirpcapReadHandler g_PAirpcapRead;
76 static AirpcapGetStatsHandler g_PAirpcapGetStats;
79 static int AirpcapVersion = 3;
81 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
82 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
83 static AirpcapOpenHandler g_PAirpcapOpen;
84 static AirpcapCloseHandler g_PAirpcapClose;
85 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
86 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
87 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
88 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
89 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
90 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
91 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
92 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
93 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
94 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
95 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
96 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
97 static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys;
98 static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys;
99 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
100 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
101 static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState;
102 static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState;
103 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
104 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
105 static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx;
106 static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx;
107 static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels;
109 /* Airpcap interface list */
110 GList *airpcap_if_list = NULL;
112 /* Airpcap current selected interface */
113 airpcap_if_info_t *airpcap_if_selected = NULL;
115 /* Airpcap current active interface */
116 airpcap_if_info_t *airpcap_if_active = NULL;
118 /* WLAN preferences pointer */
119 module_t *wlan_prefs = NULL;
121 Dot11Channel *pSupportedChannels;
122 guint numSupportedChannels;
124 static AirpcapChannelInfo LegacyChannels[] =
142 static guint num_legacy_channels = 14;
145 * Callback used by the load_wlan_keys() routine in order to read a WEP decryption key
148 get_wep_key(pref_t *pref, gpointer ud)
150 gchar *key_string = NULL;
151 guint8 key_type = AIRPDCAP_KEY_TYPE_WEP;
152 keys_cb_data_t* user_data;
154 decryption_key_t* new_key;
156 /* Retrieve user data info */
157 user_data = (keys_cb_data_t*)ud;
159 if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
161 /* strip out key type */
162 if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
163 key_string = (gchar*)(*pref->varp.string)+4;
165 else if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WPA_PWD ":", 8) == 0) {
166 key_string = (gchar*)(*pref->varp.string)+8;
167 key_type = AIRPDCAP_KEY_TYPE_WPA_PWD;
169 else if (g_ascii_strncasecmp(*pref->varp.string, STRING_KEY_TYPE_WPA_PSK ":", 8) == 0) {
170 key_string = (gchar*)(*pref->varp.string)+8;
171 key_type = AIRPDCAP_KEY_TYPE_WPA_PSK;
174 key_type = AIRPDCAP_KEY_TYPE_WEP;
175 key_string = (gchar*)*pref->varp.string;
178 /* Here we have the string describing the key... */
179 new_key = parse_key_string(key_string, key_type);
183 /* Key is added only if not null ... */
184 user_data->list = g_list_append(user_data->list,new_key);
185 user_data->number_of_keys++;
186 user_data->current_index++;
192 /* Returs TRUE if the WEP key is valid, false otherwise */
194 wep_key_is_valid(char* key)
196 GString *new_key_string;
202 new_key_string = g_string_new(key);
204 if( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
206 g_string_free(new_key_string,FALSE);
209 if((new_key_string->len % 2) != 0)
211 g_string_free(new_key_string,FALSE);
214 for(i = 0; i < new_key_string->len; i++)
216 if(!g_ascii_isxdigit(new_key_string->str[i]))
218 g_string_free(new_key_string,FALSE);
223 g_string_free(new_key_string,FALSE);
227 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
229 set_wep_key(pref_t *pref, gpointer ud _U_)
231 gchar *my_string = NULL;
232 keys_cb_data_t* user_data;
233 gint wep_key_number = 0;
235 decryption_key_t* new_key;
237 /* Retrieve user data info */
238 user_data = (keys_cb_data_t*)ud;
240 if (g_ascii_strncasecmp(pref->name, "wep_key", 7) == 0 && pref->type == PREF_STRING)
242 /* Ok, the pref we're gonna set is a wep_key ... but what number? */
243 sscanf(pref->name,"wep_key%d",&wep_key_number);
245 if(user_data->current_index < user_data->number_of_keys)
247 if(wep_key_number == (user_data->current_index+1))
249 /* Retrieve the nth decryption_key_t structure pointer */
250 new_key = (decryption_key_t*)g_list_nth_data(user_data->list,user_data->current_index);
252 /* Free the old key string */
253 g_free((void *)*pref->varp.string);
255 /* Create the new string describing the decryption key */
256 my_string = get_key_string(new_key);
258 /* Duplicate the string, and assign it to the variable pointer */
259 *pref->varp.string = (void *)g_strdup(my_string);
261 /* Free the previously allocated string */
265 else /* If the number of keys has been reduced somehow, we need to delete all the other keys
266 * (remember that the new ones have been probably overwritten)
269 g_free((void *)*pref->varp.string);
270 *pref->varp.string = (void *)g_strdup(""); /* Do not just free memory!!! Put an 'empty' string! */
272 user_data->current_index++;
279 * Function used to read the Decryption Keys from the preferences and store them
280 * properly into the airpcap adapter.
283 load_wlan_driver_wep_keys(void)
285 keys_cb_data_t* user_data;
288 /* Retrieve the wlan preferences */
289 wlan_prefs = prefs_find_module("wlan");
291 /* Allocate a structure used to keep infos between the callbacks */
292 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
294 /* Fill the structure */
295 user_data->list = NULL;
296 user_data->current_index = 0;
297 user_data->number_of_keys= 0; /* Still unknown */
299 /* Run the callback on each 802.11 preference */
300 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
302 /* Now the key list should be filled */
305 * Signal that we've changed things, and run the 802.11 dissector's
308 wlan_prefs->prefs_changed = TRUE;
310 prefs_apply(wlan_prefs);
312 write_wlan_driver_wep_keys_to_registry(user_data->list);
315 /* free the WEP key string */
316 for(i=0;i<g_list_length(user_data->list);i++)
318 g_free(g_list_nth(user_data->list,i)->data);
321 /* free the (empty) list */
322 g_list_free(user_data->list);
324 /* free the user_data structure */
327 /* airpcap_if_info_free(fake_info_if); */
333 * This function will tell the airpcap driver the key list to use
334 * This will be stored into the registry...
337 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
342 PAirpcapKeysCollection KeysCollection;
343 guint KeysCollectionSize;
345 guint keys_in_list = 0;
346 decryption_key_t* key_item = NULL;
348 keys_in_list = g_list_length(key_list);
351 * Calculate the size of the keys collection
353 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
356 * Allocate the collection
358 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
365 * Populate the key collection
367 KeysCollection->nKeys = keys_in_list;
369 for(i = 0; i < keys_in_list; i++)
371 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
373 /* Retrieve the Item corresponding to the i-th key */
374 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
375 new_key = g_string_new(key_item->key->str);
377 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
378 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
380 for(j = 0 ; j < new_key->len; j += 2)
382 s[0] = new_key->str[j];
383 s[1] = new_key->str[j+1];
385 KeyByte = (guint8)strtol(s, NULL, 16);
386 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
389 g_string_free(new_key,TRUE);
393 * Free the old adapter key collection!
395 if(info_if->keysCollection != NULL)
396 g_free(info_if->keysCollection);
399 * Set this collection ad the new one
401 info_if->keysCollection = KeysCollection;
402 info_if->keysCollectionSize = KeysCollectionSize;
405 * Configuration must be saved
407 info_if->saved = FALSE;
410 * Write down the changes to the registry
412 airpcap_save_selected_if_configuration(info_if);
418 * This function will tell the airpcap driver the key list to use
419 * This will be stored into the registry...
422 write_wlan_driver_wep_keys_to_registry(GList* key_list)
427 PAirpcapKeysCollection KeysCollection;
428 guint KeysCollectionSize;
430 guint keys_in_list = 0;
431 decryption_key_t* key_item = NULL;
432 airpcap_if_info_t* fake_info_if = NULL;
434 /* Create the fake_info_if from the first adapter of the list */
435 fake_info_if = airpcap_driver_fake_if_info_new();
437 if(fake_info_if == NULL)
441 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
442 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
444 n = g_list_length(key_list);
445 for(k = 0; k < n; k++ )
446 if(((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
450 * Calculate the size of the keys collection
452 KeysCollectionSize = sizeof(AirpcapKeysCollection) + keys_in_list * sizeof(AirpcapKey);
455 * Allocate the collection
457 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
464 * Populate the key collection
466 KeysCollection->nKeys = keys_in_list;
469 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
470 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
471 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
474 y = 0; /* Current position in the key list */
476 for(i = 0; i < n; i++)
478 /* Retrieve the Item corresponding to the i-th key */
479 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
482 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supported right now!
483 * We will have to modify the AirpcapKey structure in order to
484 * support the other two types! What happens now, is that simply the
485 * not supported keys will just be discarded (they will be saved in Wireshark though)
487 if(key_item->type == AIRPDCAP_KEY_TYPE_WEP)
489 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
491 new_key = g_string_new(key_item->key->str);
493 KeysCollection->Keys[y].KeyLen = (guint) new_key->len / 2;
494 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
496 for(j = 0 ; j < new_key->len; j += 2)
498 s[0] = new_key->str[j];
499 s[1] = new_key->str[j+1];
501 KeyByte = (guint8)strtol(s, NULL, 16);
502 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
504 /* XXX - Change when WPA will be supported!!! */
506 g_string_free(new_key,TRUE);
508 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
510 /* XXX - The driver cannot deal with this kind of key yet... */
512 else if(key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
514 /* XXX - The driver cannot deal with this kind of key yet... */
519 * Free the old adapter key collection!
521 if(fake_info_if->keysCollection != NULL)
522 g_free(fake_info_if->keysCollection);
525 * Set this collection ad the new one
527 fake_info_if->keysCollection = KeysCollection;
528 fake_info_if->keysCollectionSize = KeysCollectionSize;
531 * Configuration must be saved
533 fake_info_if->saved = FALSE;
536 * Write down the changes to the registry
538 airpcap_save_driver_if_configuration(fake_info_if);
540 airpcap_if_info_free(fake_info_if);
546 * Function used to save to the preference file the Decryption Keys.
549 save_wlan_driver_wep_keys(void)
551 GList* key_list = NULL;
552 char* tmp_key = NULL;
553 guint keys_in_list,i;
554 keys_cb_data_t* user_data;
555 airpcap_if_info_t* fake_info_if = NULL;
557 /* Create the fake_info_if from the first adapter of the list */
558 fake_info_if = airpcap_driver_fake_if_info_new();
560 if(fake_info_if == NULL)
563 /* Retrieve the wlan preferences */
564 wlan_prefs = prefs_find_module("wlan");
566 /* Allocate a structure used to keep infos between the callbacks */
567 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
569 /* Number of keys in key list */
570 if(fake_info_if->keysCollectionSize != 0)
571 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
575 for(i=0; i<keys_in_list; i++)
577 /* Only if it is a WEP key... */
578 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
580 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
581 key_list = g_list_append(key_list,g_strdup(tmp_key));
586 /* Now we know the exact number of WEP keys in the list, so store it ... */
587 keys_in_list = g_list_length(key_list);
589 /* Fill the structure */
590 user_data->list = key_list;
591 user_data->current_index = 0;
592 user_data->number_of_keys= keys_in_list;
594 /* Retrieve the wlan preferences */
595 wlan_prefs = prefs_find_module("wlan");
597 /* Run the callback on each 802.11 preference */
598 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
600 /* Signal that we've changed things, and run the 802.11 dissector's
602 wlan_prefs->prefs_changed = TRUE;
604 /* Apply changes for the specified preference */
605 prefs_apply(wlan_prefs);
608 /* free the WEP key string */
609 for(i=0;i<g_list_length(user_data->list);i++)
611 g_free(g_list_nth(user_data->list,i)->data);
614 /* free the (empty) list */
615 g_list_free(user_data->list);
617 /* free the user_data structure */
620 airpcap_if_info_free(fake_info_if);
626 * Function used to save to the preference file the Decryption Keys.
629 save_wlan_wireshark_wep_keys(GList* key_ls)
631 GList* key_list = NULL;
632 guint keys_in_list,i;
633 keys_cb_data_t* user_data;
634 decryption_key_t* tmp_dk;
636 /* Retrieve the wlan preferences */
637 wlan_prefs = prefs_find_module("wlan");
639 /* Allocate a structure used to keep infos between the callbacks */
640 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
642 keys_in_list = g_list_length(key_ls);
646 /* Fill the structure */
647 user_data->list = key_list;
648 user_data->current_index = 0;
649 user_data->number_of_keys= keys_in_list;
651 /* Retrieve the wlan preferences */
652 wlan_prefs = prefs_find_module("wlan");
654 /* Run the callback on each 802.11 preference */
655 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
657 /* Signal that we've changed things, and run the 802.11 dissector's
659 wlan_prefs->prefs_changed = TRUE;
661 /* Apply changes for the specified preference */
662 prefs_apply(wlan_prefs);
665 /* free the WEP key string */
666 for(i=0;i<g_list_length(user_data->list);i++)
668 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
669 g_string_free(tmp_dk->key,TRUE);
670 if(tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
673 /* free the (empty) list */
674 g_list_free(user_data->list);
676 /* free the user_data structure */
683 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
684 * "get_airpcap_interface_list()".
687 cant_get_airpcap_if_list_error_message(const char *err_str)
689 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
693 * Airpcap wrapper, used to store the current settings for the selected adapter
696 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
698 if (!AirpcapLoaded) return FALSE;
699 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
703 * Airpcap wrapper, used to open an airpcap adapter
706 airpcap_if_open(gchar * name, gchar * err)
708 if (!AirpcapLoaded) return NULL;
709 if (name == NULL) return NULL;
710 return g_PAirpcapOpen(name,err);
714 * Airpcap wrapper, used to close an airpcap adapter
717 airpcap_if_close(PAirpcapHandle handle)
719 if (!AirpcapLoaded) return;
720 g_PAirpcapClose(handle);
724 * Retrieve the state of the Airpcap DLL
727 airpcap_get_dll_state(void)
729 return AirpcapVersion;
733 * Airpcap wrapper, used to turn on the led of an airpcap adapter
736 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber)
738 if (!AirpcapLoaded) return FALSE;
739 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
743 * Airpcap wrapper, used to turn off the led of an airpcap adapter
746 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber)
748 if (!AirpcapLoaded) return FALSE;
749 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
753 * Airpcap wrapper, used to get the channel of an airpcap adapter
756 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch)
758 if (!AirpcapLoaded) return FALSE;
759 return g_PAirpcapGetDeviceChannel(ah,ch);
763 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
766 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint * nInfo)
768 if (!AirpcapLoaded) return FALSE;
769 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
770 *nInfo = num_legacy_channels;
771 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
774 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
775 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
781 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
784 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint * pNumSupportedChannels)
786 AirpcapChannelInfo *chanInfo;
787 guint i=0, j=0, numInfo = 0;
791 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
793 numSupportedChannels = 0;
796 * allocate a bigger array
801 pSupportedChannels = g_malloc(numInfo * (sizeof *pSupportedChannels));
803 for (i = 0; i < numInfo; i++)
805 guint supportedChannel = G_MAXUINT;
808 * search if we have it already
810 for (j = 0; j < numSupportedChannels; j++)
812 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
814 supportedChannel = j;
819 if (supportedChannel == G_MAXUINT)
822 * not found, create a new item
824 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
826 switch(chanInfo[i].ExtChannel)
829 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
832 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
836 pSupportedChannels[numSupportedChannels].Flags = 0;
840 * Gather channel information
843 pSupportedChannels[numSupportedChannels].Flags |=
844 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
845 FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
846 pSupportedChannels[numSupportedChannels].Channel =
847 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
848 numSupportedChannels++;
853 * just update the ext channel flags
855 switch(chanInfo[i].ExtChannel)
858 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
861 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
870 if (numSupportedChannels < 1)
873 * Now sort the list by frequency
875 for (i = 0 ; i < numSupportedChannels - 1; i++)
877 for (j = i + 1; j < numSupportedChannels; j++)
879 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
881 Dot11Channel temp = pSupportedChannels[i];
882 pSupportedChannels[i] = pSupportedChannels[j];
883 pSupportedChannels[j] = temp;
888 *pNumSupportedChannels = numSupportedChannels;
889 return pSupportedChannels;
893 * Airpcap wrapper, used to set the channel of an airpcap adapter
896 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch)
898 if (!AirpcapLoaded) return FALSE;
899 return g_PAirpcapSetDeviceChannel(ah,ch);
903 * Airpcap wrapper, used to set the frequency of an airpcap adapter
906 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
908 if (!AirpcapLoaded) return FALSE;
909 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
911 channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
916 return airpcap_if_set_device_channel(ah, channel);
918 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
919 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
926 * Airpcap wrapper, used to get the frequency of an airpcap adapter
929 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
931 if (!AirpcapLoaded) return FALSE;
933 pChannelInfo->Frequency = 0;
934 pChannelInfo->ExtChannel = 0;
935 pChannelInfo->Reserved[0] = 0;
936 pChannelInfo->Reserved[1] = 0;
937 pChannelInfo->Reserved[2] = 0;
939 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
943 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
945 chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
946 if (chan_freq == 0) return FALSE;
947 pChannelInfo->Frequency = chan_freq;
950 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
951 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
957 * Airpcap wrapper, used to get the link type of an airpcap adapter
960 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
962 if (!AirpcapLoaded) return FALSE;
963 return g_PAirpcapGetLinkType(ah,lt);
967 * Airpcap wrapper, used to set the link type of an airpcap adapter
970 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
972 if (!AirpcapLoaded) return FALSE;
973 return g_PAirpcapSetLinkType(ah,lt);
977 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
980 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * fcs)
982 if (!AirpcapLoaded) return FALSE;
983 return g_PAirpcapGetFcsPresence(ah,fcs);
987 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
990 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean fcs)
992 if (!AirpcapLoaded) return FALSE;
993 return g_PAirpcapSetFcsPresence(ah,fcs);
997 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
1000 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1002 if (!AirpcapLoaded) return FALSE;
1003 return g_PAirpcapGetDecryptionState(ah,PEnable);
1007 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1010 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1012 if (!AirpcapLoaded) return FALSE;
1013 return g_PAirpcapSetDecryptionState(ah,Enable);
1017 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1020 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1022 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1023 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1027 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1030 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1032 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1033 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1037 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1040 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1042 if (!AirpcapLoaded) return FALSE;
1043 return g_PAirpcapGetFcsValidation(ah,val);
1047 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1050 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1052 if (!AirpcapLoaded) return FALSE;
1053 return g_PAirpcapSetFcsValidation(ah,val);
1057 * Airpcap wrapper, used to save the settings for the selected_if
1060 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1062 if (!AirpcapLoaded) return FALSE;
1063 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1067 * Airpcap wrapper, used to save the settings for the selected_if
1070 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1072 if (!AirpcapLoaded) return FALSE;
1073 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1077 * Airpcap wrapper, used to save the driver's set of keys
1080 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1082 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1083 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1087 * Airpcap wrapper, used to load the driver's set of keys
1090 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1092 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1093 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1097 * This function will create a new airpcap_if_info_t using a name and a description
1100 airpcap_if_info_new(char *name, char *description)
1103 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1105 airpcap_if_info_t *if_info = NULL;
1107 /* Probably I have to switch on the leds!!! */
1108 ad = airpcap_if_open(name, ebuf);
1111 if_info = g_malloc0(sizeof (airpcap_if_info_t));
1112 if_info->name = g_strdup(name);
1113 if (description == NULL){
1114 if_info->description = NULL;
1116 if_info->description = g_strdup(description);
1119 if_info->ip_addr = NULL;
1120 if_info->loopback = FALSE;
1121 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1122 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1123 airpcap_if_get_link_type(ad,&(if_info->linkType));
1124 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1125 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1126 airpcap_if_turn_led_on(ad, 0);
1127 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1128 if_info->led = TRUE;
1129 if_info->blinking = FALSE;
1130 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1132 /* get the keys, if everything is ok, close the adapter */
1133 if(airpcap_if_load_keys(ad,if_info))
1135 airpcap_if_close(ad);
1142 * This function will create a new fake drivers' interface, to load global keys...
1145 airpcap_driver_fake_if_info_new(void)
1148 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1150 airpcap_if_info_t *if_info = NULL;
1151 airpcap_if_info_t *fake_if_info = NULL;
1153 /* Maybe for some reason no airpcap adapter is found */
1154 if(airpcap_if_list == NULL)
1158 * Retrieve the first AirPcap adapter available. If no interface is found,
1159 * it is not possible to retrieve the driver's settings, so return NULL.
1161 if_info = g_list_nth_data(airpcap_if_list,0);
1165 /* Open the 'fake' adapter */
1166 ad = airpcap_if_open(if_info->name, ebuf);
1169 fake_if_info = g_malloc(sizeof (airpcap_if_info_t));
1170 fake_if_info->name = g_strdup(if_info->name);
1171 fake_if_info->description = g_strdup(if_info->description);
1172 fake_if_info->loopback = FALSE;
1173 fake_if_info->ip_addr = NULL;
1174 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1175 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1176 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1177 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1178 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1179 airpcap_if_turn_led_on(ad, 0);
1180 fake_if_info->led = TRUE;
1181 fake_if_info->blinking = FALSE;
1182 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1184 /* get the keys, if everything is ok, close the adapter */
1185 if(airpcap_if_load_driver_keys(ad,fake_if_info))
1187 airpcap_if_close(ad);
1191 return fake_if_info;
1195 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1198 airpcap_if_info_print(airpcap_if_info_t* if_info)
1203 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1207 g_print("\n----------------- AirPcap Interface \n");
1208 g_print(" NAME: %s\n",if_info->name);
1209 g_print(" DESCRIPTION: %s\n",if_info->description);
1210 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1211 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1212 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1213 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1214 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1215 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1216 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1217 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1218 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1219 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1220 g_print(" LINKTYPE: %d\n",if_info->linkType);
1221 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1222 g_print(" (GTK) TAG: %d\n",if_info->tag);
1223 g_print("SUPPORTED CHANNELS POINTER: %p\n",if_info->pSupportedChannels);
1224 g_print(" NUM SUPPORTED CHANNELS: %u\n",if_info->numSupportedChannels);
1226 for(i=0; i<(if_info->numSupportedChannels); i++){
1227 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1228 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1229 g_print(" FREQUENCY: %u\n",if_info->pSupportedChannels[i].Frequency);
1230 g_print(" FLAGS: %u\n",if_info->pSupportedChannels[i].Flags);
1236 * Function used to load the WEP keys for a selected interface
1239 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1241 if(!if_info) return FALSE;
1243 if_info->keysCollectionSize = 0;
1244 if_info->keysCollection = NULL;
1246 if(!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1248 if(if_info->keysCollectionSize == 0)
1250 if_info->keysCollection = NULL;
1251 airpcap_if_close(ad);
1255 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1256 if(!if_info->keysCollection)
1258 if_info->keysCollectionSize = 0;
1259 if_info->keysCollection = NULL;
1260 airpcap_if_close(ad);
1264 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1268 airpcap_if_close(ad);
1273 * Function used to load the WEP keys for a selected interface
1276 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1278 if_info->keysCollectionSize = 0;
1279 if_info->keysCollection = NULL;
1281 if(!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1283 if(if_info->keysCollectionSize == 0)
1285 if_info->keysCollection = NULL;
1286 airpcap_if_close(ad);
1290 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1291 if(!if_info->keysCollection)
1293 if_info->keysCollectionSize = 0;
1294 if_info->keysCollection = NULL;
1295 airpcap_if_close(ad);
1299 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1303 airpcap_if_close(ad);
1308 * Function used to save the WEP keys for a selected interface
1311 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1313 if(!if_info || !AirpcapLoaded) return;
1315 if(if_info->keysCollection != NULL)
1316 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1320 * Function used to save the WEP keys for a selected interface
1323 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1325 if(if_info->keysCollection != NULL)
1326 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1330 * Callback used to free an instance of airpcap_if_info_t
1333 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1335 airpcap_if_info_t *if_info = data;
1337 if (NULL == if_info)
1340 if (if_info->name != NULL)
1341 g_free(if_info->name);
1343 if (if_info->description != NULL)
1344 g_free(if_info->description);
1346 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1347 if(if_info->keysCollection != NULL)
1349 g_free(if_info->keysCollection);
1350 if_info->keysCollection = NULL;
1353 if(if_info->ip_addr != NULL)
1354 g_slist_free(if_info->ip_addr);
1360 * Function used to free the airpcap interface list
1363 free_airpcap_interface_list(GList *if_list)
1365 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1366 g_list_free(if_list);
1371 * This function will use the airpcap.dll to find all the airpcap devices.
1372 * Will return null if no device is found.
1375 get_airpcap_interface_list(int *err, char **err_str)
1378 airpcap_if_info_t *if_info;
1380 AirpcapDeviceDescription *devsList, *adListEntry;
1381 char errbuf[AIRPCAP_ERRBUF_SIZE];
1387 *err = AIRPCAP_NOT_LOADED;
1391 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1393 /* No interfaces, return il = NULL; */
1394 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1395 if (err_str != NULL)
1396 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1401 * Count the adapters
1403 adListEntry = devsList;
1408 adListEntry = adListEntry->next;
1413 /* No interfaces, return il= NULL */
1414 g_PAirpcapFreeDeviceList(devsList);
1415 *err = NO_AIRPCAP_INTERFACES_FOUND;
1416 if (err_str != NULL)
1422 * Insert the adapters in our list
1424 adListEntry = devsList;
1427 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1428 if (if_info != NULL){
1429 il = g_list_append(il, if_info);
1432 adListEntry = adListEntry->next;
1435 g_PAirpcapFreeDeviceList(devsList);
1441 * Used to retrieve the interface given the name
1442 * (the name is used in AirpcapOpen)
1444 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
1447 airpcap_if_info_t* if_info;
1449 for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
1450 if_info = (airpcap_if_info_t *)curr->data;
1451 if (if_info && (g_ascii_strcasecmp(if_info->name, name) == 0)) {
1459 * Returns the ASCII string of a key given the key bytes
1462 airpcap_get_key_string(AirpcapKey key)
1470 if(key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1474 /* Allocate the string used to store the ASCII representation of the WEP key */
1475 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1476 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1479 for(j = 0; j < key.KeyLen; j++)
1481 src = g_strdup_printf("%.2x", key.KeyData[j]);
1483 * XXX - use g_strconcat() or GStrings instead ???
1485 g_strlcat(dst, src, WEP_KEY_MAX_CHAR_SIZE+1);
1490 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1492 /* XXX - Add code here */
1494 else if(key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1496 /* XXX - Add code here */
1500 /* XXX - Add code here */
1507 * Clear keys and decryption status for the specified interface
1510 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1514 if(info_if->keysCollection != NULL)
1516 g_free(info_if->keysCollection);
1517 info_if->keysCollection = NULL;
1520 info_if->keysCollectionSize = 0;
1522 info_if->DecryptionOn = FALSE;
1523 info_if->saved = FALSE;
1528 * Used to retrieve the two chars string from interface
1531 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1537 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1539 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1540 * Otherwise, check if it is the "Any" adapter...
1544 if(g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1545 number = g_strdup_printf("??");
1547 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1551 number = g_strdup_printf("%.2u",n);
1558 * Used to retrieve the two chars string from interface
1561 airpcap_get_if_string_number_from_description(gchar* description)
1566 number = (gchar*)g_malloc(sizeof(gchar)*3);
1568 pointer = g_strrstr(description,"#\0");
1570 number[0] = *(pointer+1);
1571 number[1] = *(pointer+2);
1578 * Returns the default airpcap interface of a list, NULL if list is empty
1581 airpcap_get_default_if(GList* airpcap_if_list)
1583 airpcap_if_info_t* if_info = NULL;
1585 if ((prefs.capture_device != NULL) && (*prefs.capture_device != '\0'))
1587 if_info = get_airpcap_if_from_name(airpcap_if_list,
1588 get_if_name(prefs.capture_device));
1594 * Load the configuration for the specified interface
1597 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1599 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1604 ad = airpcap_if_open(if_info->name, ebuf);
1608 /* Stop blinking (if it was blinking!)*/
1609 if(if_info->blinking)
1611 /* Turn on the light (if it was off) */
1612 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1615 /* Apply settings... */
1616 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1617 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1618 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1619 airpcap_if_get_link_type(ad,&(if_info->linkType));
1620 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1621 /* get the keys, if everything is ok, close the adapter */
1622 if(airpcap_if_load_keys(ad,if_info))
1623 airpcap_if_close(ad);
1625 if_info->saved = TRUE;
1629 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1635 * Save the configuration for the specified interface
1638 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1640 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1645 ad = airpcap_if_open(if_info->name, ebuf);
1649 /* Stop blinking (if it was blinking!)*/
1650 if(if_info->blinking)
1652 /* Turn on the light (if it was off) */
1653 if(!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1656 /* Apply settings... */
1657 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1658 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1659 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1660 airpcap_if_set_link_type(ad,if_info->linkType);
1661 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1662 airpcap_if_save_keys(ad,if_info);
1664 /* ... and save them */
1665 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
1667 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.");
1668 if_info->saved = FALSE;
1669 airpcap_if_close(ad);
1673 if_info->saved = TRUE;
1674 airpcap_if_close(ad);
1678 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1684 * Save the configuration for the specified interface
1687 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1689 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1692 if(fake_if_info != NULL)
1694 ad = airpcap_if_open(fake_if_info->name, ebuf);
1698 /* Apply decryption settings... */
1699 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1700 airpcap_if_save_driver_keys(ad,fake_if_info);
1701 airpcap_if_close(ad);
1705 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1713 * DECRYPTION KEYS FUNCTIONS
1716 * This function is used for DEBUG POURPOSES ONLY!!!
1719 print_key_list(GList* key_list)
1722 decryption_key_t* tmp;
1724 if(key_list == NULL)
1726 g_print("\n\n******* KEY LIST NULL *******\n\n");
1730 n = g_list_length(key_list);
1732 g_print("\n\n********* KEY LIST **********\n\n");
1734 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1736 for(i =0; i < n; i++)
1738 g_print("[%d] :\n",i+1);
1739 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1740 g_print("KEY : %s\n",tmp->key->str);
1742 g_print("BITS: %d\n",tmp->bits);
1744 if(tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1745 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1746 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1747 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1748 else if(tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1749 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1751 g_print("TYPE: %s\n","???");
1753 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1754 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1758 g_print("\n*****************************\n\n");
1762 * Retrieves a GList of decryption_key_t structures containing infos about the
1763 * keys for the given adapter... returns NULL if no keys are found.
1766 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1769 char* tmp_key = NULL;
1770 guint i,keys_in_list = 0;
1773 decryption_key_t *new_key = NULL;
1774 GList *key_list = NULL;
1776 /* Number of keys in key list */
1777 if(info_if->keysCollectionSize != 0)
1778 keys_in_list = (guint)(info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1782 for(i=0; i<keys_in_list; i++)
1784 /* Different things to do depending on the key type */
1785 if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1787 /* allocate memory for the new key item */
1788 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1790 /* fill the fields */
1792 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1793 new_key->key = g_string_new(tmp_key);
1797 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1799 /* SSID not used in WEP keys */
1800 new_key->ssid = NULL;
1802 /* TYPE (WEP in this case) */
1803 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1805 /* Append the new element in the list */
1806 key_list = g_list_append(key_list,(gpointer)new_key);
1808 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1810 /* XXX - Not supported yet */
1812 else if(info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1814 /* XXX - Not supported yet */
1822 * Retrieves a GList of decryption_key_t structures containing infos about the
1823 * keys for the global AirPcap driver... returns NULL if no keys are found.
1826 get_airpcap_driver_keys(void)
1829 char* tmp_key = NULL;
1830 guint i,keys_in_list = 0;
1833 decryption_key_t *new_key = NULL;
1834 GList *key_list = NULL;
1837 * To read the drivers general settings we need to create and use one airpcap adapter...
1838 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1840 airpcap_if_info_t* fake_info_if = NULL;
1842 /* Create the fake_info_if from the first adapter of the list */
1843 fake_info_if = airpcap_driver_fake_if_info_new();
1845 if(fake_info_if == NULL)
1848 /* Number of keys in key list */
1849 if(fake_info_if->keysCollectionSize != 0)
1850 keys_in_list = (guint)(fake_info_if->keysCollectionSize - sizeof(AirpcapKeysCollection))/sizeof(AirpcapKey);
1854 for(i=0; i<keys_in_list; i++)
1856 /* Different things to do depending on the key type */
1857 if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1859 /* allocate memory for the new key item */
1860 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1862 /* fill the fields */
1864 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1865 new_key->key = g_string_new(tmp_key);
1866 if(tmp_key != NULL) g_free(tmp_key);
1869 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1871 /* SSID not used in WEP keys */
1872 new_key->ssid = NULL;
1874 /* TYPE (WEP in this case) */
1875 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
1877 /* Append the new element in the list */
1878 key_list = g_list_append(key_list,(gpointer)new_key);
1880 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1882 /* XXX - Not supported yet */
1884 else if(fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1886 /* XXX - Not supported yet */
1890 airpcap_if_info_free(fake_info_if);
1896 * Returns the list of the decryption keys specified for wireshark, NULL if
1900 get_wireshark_keys(void)
1902 keys_cb_data_t* wep_user_data = NULL;
1904 GList* final_list = NULL;
1905 GList* wep_final_list = NULL;
1907 /* Retrieve the wlan preferences */
1908 wlan_prefs = prefs_find_module("wlan");
1910 /* Allocate a structure used to keep infos between the callbacks */
1911 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1913 /* Fill the structure */
1914 wep_user_data->list = NULL;
1915 wep_user_data->current_index = 0;
1916 wep_user_data->number_of_keys= 0; /* Still unknown */
1918 /* Run the callback on each 802.11 preference */
1919 /* XXX - Right now, only WEP keys will be loaded */
1920 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1922 /* Copy the list field in the user data structure pointer into the final_list */
1923 wep_final_list = wep_user_data->list;
1925 /* XXX - Merge the three lists!!!!! */
1926 final_list = wep_final_list;
1928 /* free the wep_user_data structure */
1929 g_free(wep_user_data);
1935 * Merges two lists of keys and return a newly created GList. If a key is
1936 * found multiple times, it will just appear once!
1937 * list1 and list 2 pointer will have to be freed manually if needed!!!
1938 * If the total number of keys exceeeds the maximum number allowed,
1939 * exceeding keys will be discarded...
1942 merge_key_list(GList* list1, GList* list2)
1946 decryption_key_t *dk1=NULL,
1950 GList* merged_list = NULL;
1952 if( (list1 == NULL) && (list2 == NULL) )
1957 n2 = g_list_length(list2);
1961 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1962 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1964 new_dk->bits = dk2->bits;
1965 new_dk->type = dk2->type;
1966 new_dk->key = g_string_new(dk2->key->str);
1967 new_dk->ssid = byte_array_dup(dk2->ssid);
1969 /* Check the total length of the merged list */
1970 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1971 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1974 else if(list2 == NULL)
1976 n1 = g_list_length(list1);
1980 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1981 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
1983 new_dk->bits = dk1->bits;
1984 new_dk->type = dk1->type;
1985 new_dk->key = g_string_new(dk1->key->str);
1986 new_dk->ssid = byte_array_dup(dk1->ssid);
1988 /* Check the total length of the merged list */
1989 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1990 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1995 n1 = g_list_length(list1);
1996 n2 = g_list_length(list2);
1998 /* Copy the whole list1 into merged_list */
2001 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2002 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2004 new_dk->bits = dk1->bits;
2005 new_dk->type = dk1->type;
2006 new_dk->key = g_string_new(dk1->key->str);
2007 new_dk->ssid = byte_array_dup(dk1->ssid);
2009 /* Check the total length of the merged list */
2010 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2011 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2014 /* Look for keys that are present in list2 but aren't in list1 yet...
2015 * Add them to merged_list
2019 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2021 if(!key_is_in_list(dk2,merged_list))
2023 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2025 new_dk->bits = dk2->bits;
2026 new_dk->type = dk2->type;
2027 new_dk->key = g_string_new(dk2->key->str);
2028 new_dk->ssid = byte_array_dup(dk2->ssid);
2030 /* Check the total length of the merged list */
2031 if(g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2032 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2041 * Use this function to free a key list.
2044 free_key_list(GList *list)
2047 decryption_key_t *curr_key;
2052 n = g_list_length(list);
2054 for(i = 0; i < n; i++)
2056 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2058 /* Free all the strings */
2059 if(curr_key->key != NULL)
2060 g_string_free(curr_key->key, TRUE);
2062 if(curr_key->ssid != NULL)
2063 g_byte_array_free(curr_key->ssid, TRUE);
2065 /* free the decryption_key_t structure*/
2078 * If the given key is contained in the list, returns TRUE.
2079 * Returns FALSE otherwise.
2082 key_is_in_list(decryption_key_t *dk,GList *list)
2085 decryption_key_t* curr_key = NULL;
2086 gboolean found = FALSE;
2088 if( (list == NULL) || (dk == NULL) )
2091 n = g_list_length(list);
2096 for(i = 0; i < n; i++)
2098 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2099 if(keys_are_equals(dk,curr_key))
2107 * Returns TRUE if keys are equals, FALSE otherwise
2110 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2113 if((k1==NULL) || (k2==NULL))
2116 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2117 /** 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) ) **/
2118 /** return TRUE; **/
2120 if( g_string_equal(k1->key,k2->key) &&
2121 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2122 k1->type == k2->type)
2124 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2125 if((k1->ssid == NULL) && (k2->ssid == NULL))
2128 /* If they are not null, they must share the same ssid */
2129 return byte_array_equal(k1->ssid,k2->ssid);
2132 /* Some field is not equal ... */
2137 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2138 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2142 key_lists_are_equal(GList* list1, GList* list2)
2146 guint wep_n1=0,wep_n2=0;
2147 GList *wep_list1=NULL;
2148 GList *wep_list2=NULL;
2151 decryption_key_t *dk1=NULL,*dk2=NULL;
2153 n1 = g_list_length(list1);
2154 n2 = g_list_length(list2);
2157 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2162 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2163 if(dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2165 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2171 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2172 if(dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2174 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2180 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2185 * Commented, because in the new AirPcap version all the keys will be saved
2186 * into the driver, and all the keys for every specific adapter will be
2187 * removed. This means that this check will always fail... and the user will
2188 * always be asked what to do... and it doesn't make much sense.
2190 /* if(n1 != n2) return FALSE; */
2191 if(wep_n1 != wep_n2) return FALSE;
2197 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2198 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2200 if(!g_string_equal(dk1->key,dk2->key)) return FALSE;
2204 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2205 if(!key_is_in_list(dk2,wep_list1)) return FALSE;
2212 test_if_on(pref_t *pref, gpointer ud)
2217 /* Retrieve user data info */
2218 is_on = (gboolean*)ud;
2221 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2223 number = *pref->varp.boolp;
2225 if(number) *is_on = TRUE;
2226 else *is_on = FALSE;
2234 * Returns TRUE if the Wireshark decryption is active, false otherwise
2235 * XXX - Should we just add a routine to packet-ieee80211.c to grab this directly?
2238 wireshark_decryption_on(void)
2242 /* Retrieve the wlan preferences */
2243 wlan_prefs = prefs_find_module("wlan");
2245 /* Run the callback on each 802.11 preference */
2246 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2252 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2255 airpcap_decryption_on(void)
2257 gboolean is_on = FALSE;
2259 airpcap_if_info_t* fake_if_info = NULL;
2261 fake_if_info = airpcap_driver_fake_if_info_new();
2263 if(fake_if_info != NULL)
2265 if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2267 else if(fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2271 airpcap_if_info_free(fake_if_info);
2277 * Free an instance of airpcap_if_info_t
2280 airpcap_if_info_free(airpcap_if_info_t *if_info)
2284 if (if_info->name != NULL)
2285 g_free(if_info->name);
2287 if (if_info->description != NULL)
2288 g_free(if_info->description);
2290 if(if_info->keysCollection != NULL)
2292 g_free(if_info->keysCollection);
2293 if_info->keysCollection = NULL;
2296 if(if_info->ip_addr != NULL)
2298 g_slist_free(if_info->ip_addr);
2299 if_info->ip_addr = NULL;
2311 set_on_off(pref_t *pref, gpointer ud)
2315 /* Retrieve user data info */
2316 is_on = (gboolean*)ud;
2318 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2322 *pref->varp.boolp = TRUE;
2324 *pref->varp.boolp = FALSE;
2332 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2335 set_wireshark_decryption(gboolean on_off)
2341 /* Retrieve the wlan preferences */
2342 wlan_prefs = prefs_find_module("wlan");
2344 /* Run the callback on each 802.11 preference */
2345 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2348 * Signal that we've changed things, and run the 802.11 dissector's
2351 wlan_prefs->prefs_changed = TRUE;
2353 prefs_apply(wlan_prefs);
2357 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2360 set_airpcap_decryption(gboolean on_off)
2362 /* We need to directly access the .dll functions here... */
2363 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2364 PAirpcapHandle ad,ad_driver;
2366 gboolean success = TRUE;
2370 airpcap_if_info_t* curr_if = NULL;
2371 airpcap_if_info_t* fake_if_info = NULL;
2373 fake_if_info = airpcap_driver_fake_if_info_new();
2375 if(fake_if_info == NULL)
2376 /* We apparently don't have any adapters installed.
2377 * This isn't a failure, so return TRUE
2381 /* Set the driver decryption */
2382 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2386 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2388 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2390 airpcap_if_close(ad_driver);
2393 airpcap_if_info_free(fake_if_info);
2395 n = g_list_length(airpcap_if_list);
2397 /* Set to FALSE the decryption for all the adapters */
2398 /* Apply this change to all the adapters !!! */
2399 for(i = 0; i < n; i++)
2401 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2403 if( curr_if != NULL )
2405 ad = airpcap_if_open(curr_if->name, ebuf);
2408 curr_if->DecryptionOn = (gboolean)AIRPCAP_DECRYPTION_OFF;
2409 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2410 /* Save configuration for the curr_if */
2411 if(!airpcap_if_store_cur_config_as_adapter_default(ad))
2415 airpcap_if_close(ad);
2424 /* DYNAMIC LIBRARY LOADER */
2426 * Used to dynamically load the airpcap library in order link it only when
2427 * it's present on the system
2429 int load_airpcap(void)
2432 gboolean base_functions = TRUE;
2433 gboolean eleven_n_functions = TRUE;
2435 if((AirpcapLib = ws_load_library("airpcap.dll")) == NULL)
2437 /* Report the error but go on */
2438 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2439 return AirpcapVersion;
2443 if((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2444 if((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2445 if((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2446 if((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2447 if((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2448 if((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2449 if((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2450 if((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2451 if((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2452 if((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2453 if((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2454 if((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2455 if((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2456 if((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2457 if((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2458 if((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2459 if((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2460 if((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2461 if((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2462 if((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2463 if((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2464 if((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2465 if((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2466 if((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2467 if((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2468 if((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2469 if((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2470 if((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2471 if((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2472 if((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2473 if((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2474 if((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2476 /* TEST IF AIRPCAP SUPPORTS 11N */
2477 if((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2478 if((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2479 if((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2481 if(base_functions && eleven_n_functions){
2482 AirpcapLoaded = TRUE;
2483 AirpcapVersion = AIRPCAP_DLL_OK;
2484 }else if(base_functions){
2485 AirpcapLoaded = TRUE;
2486 AirpcapVersion = AIRPCAP_DLL_OLD;
2487 return AIRPCAP_DLL_OK;
2489 AirpcapLoaded = FALSE;
2490 AirpcapVersion = AIRPCAP_DLL_ERROR;
2493 return AirpcapVersion;
2495 return AIRPCAP_DLL_NOT_FOUND;
2500 * Append the version of AirPcap with which we were compiled to a GString.
2503 get_compiled_airpcap_version(GString *str)
2505 g_string_append(str, "with AirPcap");
2509 * Append the version of AirPcap with which we we're running to a GString.
2512 get_runtime_airpcap_version(GString *str)
2514 guint vmaj, vmin, vrev, build;
2516 /* See if the DLL has been loaded successfully. Bail if it hasn't */
2517 if (AirpcapLoaded == FALSE) {
2518 g_string_append(str, "without AirPcap");
2522 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
2523 g_string_append_printf(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2526 #endif /* HAVE_AIRPCAP */