3 * Giorgio Tino <giorgio.tino@cacetech.com>
4 * Copyright (c) CACE Technologies, LLC 2006
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2000 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 #include <epan/packet.h>
39 #include <epan/prefs.h>
40 #include <epan/prefs-int.h>
41 #include <epan/uat-int.h>
42 #include <epan/dissectors/packet-ieee80211.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;
155 const char* err = NULL;
156 uat_wep_key_record_t* wep_keys;
157 decryption_key_t* new_key;
159 /* Retrieve user data info */
160 user_data = (keys_cb_data_t*)ud;
162 if (g_ascii_strcasecmp(pref->name, "wep_key_table") == 0 && pref->type == PREF_UAT)
164 uat = pref->varp.uat;
165 /* This is just a sanity check. UAT should be loaded */
173 for (i = 0, wep_keys = (uat_wep_key_record_t*)*uat->user_ptr; i < *uat->nrows_p; i++, wep_keys++)
175 /* strip out key type if present */
176 if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
177 key_type = AIRPDCAP_KEY_TYPE_WEP;
178 key_string = (gchar*)wep_keys->string+4;
180 else if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WPA_PWD ":", 8) == 0) {
181 key_string = (gchar*)wep_keys->string+8;
182 key_type = AIRPDCAP_KEY_TYPE_WPA_PWD;
184 else if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WPA_PSK ":", 8) == 0) {
185 key_string = (gchar*)wep_keys->string+8;
186 key_type = AIRPDCAP_KEY_TYPE_WPA_PSK;
189 key_type = wep_keys->key;
190 key_string = (gchar*)wep_keys->string;
193 /* Here we have the string describing the key... */
194 new_key = parse_key_string(key_string, key_type);
198 /* Key is added only if not null ... */
199 user_data->list = g_list_append(user_data->list,new_key);
200 user_data->number_of_keys++;
201 user_data->current_index++;
208 /* Returs TRUE if the WEP key is valid, false otherwise */
210 wep_key_is_valid(char* key)
212 GString *new_key_string;
218 new_key_string = g_string_new(key);
220 if ( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
222 g_string_free(new_key_string,FALSE);
225 if ((new_key_string->len % 2) != 0)
227 g_string_free(new_key_string,FALSE);
230 for(i = 0; i < new_key_string->len; i++)
232 if (!g_ascii_isxdigit(new_key_string->str[i]))
234 g_string_free(new_key_string,FALSE);
239 g_string_free(new_key_string,FALSE);
243 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
245 set_wep_key(pref_t *pref, gpointer ud _U_)
247 keys_cb_data_t* user_data;
250 const char* err = NULL;
251 uat_wep_key_record_t uat_key;
253 decryption_key_t* new_key;
255 /* Retrieve user data info */
256 user_data = (keys_cb_data_t*)ud;
258 if (g_ascii_strcasecmp(pref->name, "wep_key_table") == 0 && pref->type == PREF_UAT)
260 uat = pref->varp.uat;
263 /* UAT will only be loaded if previous keys exist, so it may need
271 /* Free the old records */
274 for (i = 0; i < user_data->number_of_keys; i++)
276 new_key = (decryption_key_t*)g_list_nth_data(user_data->list,i);
278 uat_key.string = get_key_string(new_key);
279 uat_key.key = new_key->type;
280 uat_add_record(uat, &uat_key, TRUE);
292 * Function used to read the Decryption Keys from the preferences and store them
293 * properly into the airpcap adapter.
296 load_wlan_driver_wep_keys(void)
298 keys_cb_data_t* user_data;
301 /* Retrieve the wlan preferences */
302 wlan_prefs = prefs_find_module("wlan");
304 /* Allocate a structure used to keep infos between the callbacks */
305 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
307 /* Fill the structure */
308 user_data->list = NULL;
309 user_data->current_index = 0;
310 user_data->number_of_keys= 0; /* Still unknown */
312 /* Run the callback on each 802.11 preference */
313 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
315 /* Now the key list should be filled */
318 * Signal that we've changed things, and run the 802.11 dissector's
321 wlan_prefs->prefs_changed = TRUE;
323 prefs_apply(wlan_prefs);
325 write_wlan_driver_wep_keys_to_registry(user_data->list);
328 /* free the WEP key string */
329 for(i=0;i<g_list_length(user_data->list);i++)
331 g_free(g_list_nth(user_data->list,i)->data);
334 /* free the (empty) list */
335 g_list_free(user_data->list);
337 /* free the user_data structure */
340 /* airpcap_if_info_free(fake_info_if); */
346 * This function will tell the airpcap driver the key list to use
347 * This will be stored into the registry...
350 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
355 PAirpcapKeysCollection KeysCollection;
356 guint KeysCollectionSize;
358 guint keys_in_list = 0;
359 decryption_key_t* key_item = NULL;
361 keys_in_list = g_list_length(key_list);
364 * Calculate the size of the keys collection
366 KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
369 * Allocate the collection
371 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
378 * Populate the key collection
380 KeysCollection->nKeys = keys_in_list;
382 for(i = 0; i < keys_in_list; i++)
384 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
386 /* Retrieve the Item corresponding to the i-th key */
387 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
388 new_key = g_string_new(key_item->key->str);
390 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
391 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
393 for(j = 0 ; j < new_key->len; j += 2)
395 s[0] = new_key->str[j];
396 s[1] = new_key->str[j+1];
398 KeyByte = (guint8)strtol(s, NULL, 16);
399 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
402 g_string_free(new_key,TRUE);
406 * Free the old adapter key collection!
408 if (info_if->keysCollection != NULL)
409 g_free(info_if->keysCollection);
412 * Set this collection ad the new one
414 info_if->keysCollection = KeysCollection;
415 info_if->keysCollectionSize = KeysCollectionSize;
418 * Configuration must be saved
420 info_if->saved = FALSE;
423 * Write down the changes to the registry
425 airpcap_save_selected_if_configuration(info_if);
431 * This function will tell the airpcap driver the key list to use
432 * This will be stored into the registry...
435 write_wlan_driver_wep_keys_to_registry(GList* key_list)
440 PAirpcapKeysCollection KeysCollection;
441 guint KeysCollectionSize;
443 guint keys_in_list = 0;
444 decryption_key_t* key_item = NULL;
445 airpcap_if_info_t* fake_info_if = NULL;
447 /* Create the fake_info_if from the first adapter of the list */
448 fake_info_if = airpcap_driver_fake_if_info_new();
450 if (fake_info_if == NULL)
454 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
455 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
457 n = g_list_length(key_list);
458 for(k = 0; k < n; k++ )
459 if (((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
463 * Calculate the size of the keys collection
465 KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
468 * Allocate the collection
470 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
477 * Populate the key collection
479 KeysCollection->nKeys = keys_in_list;
482 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
483 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
484 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
487 y = 0; /* Current position in the key list */
489 for(i = 0; i < n; i++)
491 /* Retrieve the Item corresponding to the i-th key */
492 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
495 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supported right now!
496 * We will have to modify the AirpcapKey structure in order to
497 * support the other two types! What happens now, is that simply the
498 * not supported keys will just be discarded (they will be saved in Wireshark though)
500 if (key_item->type == AIRPDCAP_KEY_TYPE_WEP)
502 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
504 new_key = g_string_new(key_item->key->str);
506 KeysCollection->Keys[y].KeyLen = (guint) new_key->len / 2;
507 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
509 for(j = 0 ; j < new_key->len; j += 2)
511 s[0] = new_key->str[j];
512 s[1] = new_key->str[j+1];
514 KeyByte = (guint8)strtol(s, NULL, 16);
515 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
517 /* XXX - Change when WPA will be supported!!! */
519 g_string_free(new_key,TRUE);
521 else if (key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
523 /* XXX - The driver cannot deal with this kind of key yet... */
525 else if (key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
527 /* XXX - The driver cannot deal with this kind of key yet... */
532 * Free the old adapter key collection!
534 if (fake_info_if->keysCollection != NULL)
535 g_free(fake_info_if->keysCollection);
538 * Set this collection ad the new one
540 fake_info_if->keysCollection = KeysCollection;
541 fake_info_if->keysCollectionSize = KeysCollectionSize;
544 * Configuration must be saved
546 fake_info_if->saved = FALSE;
549 * Write down the changes to the registry
551 airpcap_save_driver_if_configuration(fake_info_if);
553 airpcap_if_info_free(fake_info_if);
559 * Function used to save to the preference file the Decryption Keys.
562 save_wlan_driver_wep_keys(void)
564 GList* key_list = NULL;
565 char* tmp_key = NULL;
566 guint keys_in_list,i;
567 keys_cb_data_t* user_data;
568 airpcap_if_info_t* fake_info_if = NULL;
570 /* Create the fake_info_if from the first adapter of the list */
571 fake_info_if = airpcap_driver_fake_if_info_new();
573 if (fake_info_if == NULL)
576 /* Retrieve the wlan preferences */
577 wlan_prefs = prefs_find_module("wlan");
579 /* Allocate a structure used to keep infos between the callbacks */
580 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
582 /* Number of keys in key list */
583 if (fake_info_if->keysCollectionSize != 0)
584 keys_in_list = AirpcapKeysCollectionSizeToKeyCount(fake_info_if->keysCollectionSize);
588 for(i=0; i<keys_in_list; i++)
590 /* Only if it is a WEP key... */
591 if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
593 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
594 key_list = g_list_append(key_list,g_strdup(tmp_key));
599 /* Now we know the exact number of WEP keys in the list, so store it ... */
600 keys_in_list = g_list_length(key_list);
602 /* Fill the structure */
603 user_data->list = key_list;
604 user_data->current_index = 0;
605 user_data->number_of_keys= keys_in_list;
607 /* Retrieve the wlan preferences */
608 wlan_prefs = prefs_find_module("wlan");
610 /* Run the callback on each 802.11 preference */
611 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
613 /* Signal that we've changed things, and run the 802.11 dissector's
615 wlan_prefs->prefs_changed = TRUE;
617 /* Apply changes for the specified preference */
618 prefs_apply(wlan_prefs);
621 /* free the WEP key string */
622 for(i=0;i<g_list_length(user_data->list);i++)
624 g_free(g_list_nth(user_data->list,i)->data);
627 /* free the (empty) list */
628 g_list_free(user_data->list);
630 /* free the user_data structure */
633 airpcap_if_info_free(fake_info_if);
639 * Function used to save to the preference file the Decryption Keys.
642 save_wlan_wireshark_wep_keys(GList* key_ls)
644 GList* key_list = NULL;
645 guint keys_in_list,i;
646 keys_cb_data_t* user_data;
647 decryption_key_t* tmp_dk;
649 /* Retrieve the wlan preferences */
650 wlan_prefs = prefs_find_module("wlan");
652 /* Allocate a structure used to keep infos between the callbacks */
653 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
655 keys_in_list = g_list_length(key_ls);
659 /* Fill the structure */
660 user_data->list = key_list;
661 user_data->current_index = 0;
662 user_data->number_of_keys= keys_in_list;
664 /* Retrieve the wlan preferences */
665 wlan_prefs = prefs_find_module("wlan");
667 /* Run the callback on each 802.11 preference */
668 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
670 /* Signal that we've changed things, and run the 802.11 dissector's
672 wlan_prefs->prefs_changed = TRUE;
674 /* Apply changes for the specified preference */
675 prefs_apply(wlan_prefs);
678 /* free the WEP key string */
679 for(i=0;i<g_list_length(user_data->list);i++)
681 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
682 g_string_free(tmp_dk->key,TRUE);
683 if (tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
686 /* free the (empty) list */
687 g_list_free(user_data->list);
689 /* free the user_data structure */
696 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
697 * "get_airpcap_interface_list()".
700 cant_get_airpcap_if_list_error_message(const char *err_str)
702 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
706 * Airpcap wrapper, used to store the current settings for the selected adapter
709 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
711 if (!AirpcapLoaded) return FALSE;
712 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
716 * Airpcap wrapper, used to open an airpcap adapter
719 airpcap_if_open(gchar * name, gchar * err)
721 if (!AirpcapLoaded) return NULL;
722 if (name == NULL) return NULL;
723 return g_PAirpcapOpen(name,err);
727 * Airpcap wrapper, used to close an airpcap adapter
730 airpcap_if_close(PAirpcapHandle handle)
732 if (!AirpcapLoaded) return;
733 g_PAirpcapClose(handle);
737 * Retrieve the state of the Airpcap DLL
740 airpcap_get_dll_state(void)
742 return AirpcapVersion;
746 * Airpcap wrapper, used to turn on the led of an airpcap adapter
749 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber)
751 if (!AirpcapLoaded) return FALSE;
752 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
756 * Airpcap wrapper, used to turn off the led of an airpcap adapter
759 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber)
761 if (!AirpcapLoaded) return FALSE;
762 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
766 * Airpcap wrapper, used to get the channel of an airpcap adapter
769 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch)
771 if (!AirpcapLoaded) return FALSE;
772 return g_PAirpcapGetDeviceChannel(ah,ch);
776 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
779 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint * nInfo)
781 if (!AirpcapLoaded) return FALSE;
782 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD) {
783 *nInfo = num_legacy_channels;
784 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
787 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK) {
788 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
794 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
797 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint * pNumSupportedChannels)
799 AirpcapChannelInfo *chanInfo;
800 guint i=0, j=0, numInfo = 0;
804 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
806 numSupportedChannels = 0;
809 * allocate a bigger array
814 pSupportedChannels = (Dot11Channel *)g_malloc(numInfo * (sizeof *pSupportedChannels));
816 for (i = 0; i < numInfo; i++)
818 guint supportedChannel = G_MAXUINT;
821 * search if we have it already
823 for (j = 0; j < numSupportedChannels; j++)
825 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
827 supportedChannel = j;
832 if (supportedChannel == G_MAXUINT)
835 * not found, create a new item
837 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
839 switch(chanInfo[i].ExtChannel)
842 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
845 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
849 pSupportedChannels[numSupportedChannels].Flags = 0;
853 * Gather channel information
856 pSupportedChannels[numSupportedChannels].Flags |=
857 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
858 FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
859 pSupportedChannels[numSupportedChannels].Channel =
860 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
861 numSupportedChannels++;
866 * just update the ext channel flags
868 switch(chanInfo[i].ExtChannel)
871 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
874 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
883 if (numSupportedChannels < 1)
886 * Now sort the list by frequency
888 for (i = 0 ; i < numSupportedChannels - 1; i++)
890 for (j = i + 1; j < numSupportedChannels; j++)
892 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
894 Dot11Channel temp = pSupportedChannels[i];
895 pSupportedChannels[i] = pSupportedChannels[j];
896 pSupportedChannels[j] = temp;
901 *pNumSupportedChannels = numSupportedChannels;
902 return pSupportedChannels;
906 * Airpcap wrapper, used to set the channel of an airpcap adapter
909 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch)
911 if (!AirpcapLoaded) return FALSE;
912 return g_PAirpcapSetDeviceChannel(ah,ch);
916 * Airpcap wrapper, used to set the frequency of an airpcap adapter
919 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
921 if (!AirpcapLoaded) return FALSE;
922 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
924 channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
929 return airpcap_if_set_device_channel(ah, channel);
931 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
932 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
939 * Airpcap wrapper, used to get the frequency of an airpcap adapter
942 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
944 if (!AirpcapLoaded) return FALSE;
946 pChannelInfo->Frequency = 0;
947 pChannelInfo->ExtChannel = 0;
948 pChannelInfo->Reserved[0] = 0;
949 pChannelInfo->Reserved[1] = 0;
950 pChannelInfo->Reserved[2] = 0;
952 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
956 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
958 chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
959 if (chan_freq == 0) return FALSE;
960 pChannelInfo->Frequency = chan_freq;
963 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
964 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
970 * Airpcap wrapper, used to get the link type of an airpcap adapter
973 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
975 if (!AirpcapLoaded) return FALSE;
976 return g_PAirpcapGetLinkType(ah,lt);
980 * Airpcap wrapper, used to set the link type of an airpcap adapter
983 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
985 if (!AirpcapLoaded) return FALSE;
986 return g_PAirpcapSetLinkType(ah,lt);
990 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
993 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * fcs)
995 if (!AirpcapLoaded) return FALSE;
996 return g_PAirpcapGetFcsPresence(ah,fcs);
1000 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
1003 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean fcs)
1005 if (!AirpcapLoaded) return FALSE;
1006 return g_PAirpcapSetFcsPresence(ah,fcs);
1010 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
1013 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1015 if (!AirpcapLoaded) return FALSE;
1016 return g_PAirpcapGetDecryptionState(ah,PEnable);
1020 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1023 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1025 if (!AirpcapLoaded) return FALSE;
1026 return g_PAirpcapSetDecryptionState(ah,Enable);
1030 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1033 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1035 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1036 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1040 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1043 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1045 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1046 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1050 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1053 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1055 if (!AirpcapLoaded) return FALSE;
1056 return g_PAirpcapGetFcsValidation(ah,val);
1060 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1063 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1065 if (!AirpcapLoaded) return FALSE;
1066 return g_PAirpcapSetFcsValidation(ah,val);
1070 * Airpcap wrapper, used to save the settings for the selected_if
1073 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1075 if (!AirpcapLoaded) return FALSE;
1076 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1080 * Airpcap wrapper, used to save the settings for the selected_if
1083 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1085 if (!AirpcapLoaded) return FALSE;
1086 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1090 * Airpcap wrapper, used to save the driver's set of keys
1093 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1095 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1096 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1100 * Airpcap wrapper, used to load the driver's set of keys
1103 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1105 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1106 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1110 * This function will create a new airpcap_if_info_t using a name and a description
1113 airpcap_if_info_new(char *name, char *description)
1116 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1118 airpcap_if_info_t *if_info = NULL;
1120 /* Probably I have to switch on the leds!!! */
1121 ad = airpcap_if_open(name, ebuf);
1124 if_info = (airpcap_if_info_t *)g_malloc0(sizeof (airpcap_if_info_t));
1125 if_info->name = g_strdup(name);
1126 if (description == NULL){
1127 if_info->description = NULL;
1129 if_info->description = g_strdup(description);
1132 if_info->ip_addr = NULL;
1133 if_info->loopback = FALSE;
1134 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1135 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1136 airpcap_if_get_link_type(ad,&(if_info->linkType));
1137 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1138 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1139 airpcap_if_turn_led_on(ad, 0);
1140 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1141 if_info->led = TRUE;
1142 if_info->blinking = FALSE;
1143 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1145 /* get the keys, if everything is ok, close the adapter */
1146 if (airpcap_if_load_keys(ad,if_info))
1148 airpcap_if_close(ad);
1155 * This function will create a new fake drivers' interface, to load global keys...
1158 airpcap_driver_fake_if_info_new(void)
1161 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1163 airpcap_if_info_t *if_info = NULL;
1164 airpcap_if_info_t *fake_if_info = NULL;
1166 /* Maybe for some reason no airpcap adapter is found */
1167 if (airpcap_if_list == NULL)
1171 * Retrieve the first AirPcap adapter available. If no interface is found,
1172 * it is not possible to retrieve the driver's settings, so return NULL.
1174 if_info = (airpcap_if_info_t *)g_list_nth_data(airpcap_if_list,0);
1175 if (if_info == NULL)
1178 /* Open the 'fake' adapter */
1179 ad = airpcap_if_open(if_info->name, ebuf);
1182 fake_if_info = (airpcap_if_info_t *)g_malloc(sizeof (airpcap_if_info_t));
1183 fake_if_info->name = g_strdup(if_info->name);
1184 fake_if_info->description = g_strdup(if_info->description);
1185 fake_if_info->loopback = FALSE;
1186 fake_if_info->ip_addr = NULL;
1187 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1188 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1189 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1190 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1191 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1192 airpcap_if_turn_led_on(ad, 0);
1193 fake_if_info->led = TRUE;
1194 fake_if_info->blinking = FALSE;
1195 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1197 /* get the keys, if everything is ok, close the adapter */
1198 if (airpcap_if_load_driver_keys(ad,fake_if_info))
1200 airpcap_if_close(ad);
1204 return fake_if_info;
1208 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1211 airpcap_if_info_print(airpcap_if_info_t* if_info)
1214 if (if_info == NULL)
1216 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1220 g_print("\n----------------- AirPcap Interface \n");
1221 g_print(" NAME: %s\n",if_info->name);
1222 g_print(" DESCRIPTION: %s\n",if_info->description);
1223 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1224 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1225 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1226 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1227 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1228 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1229 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1230 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1231 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1232 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1233 g_print(" LINKTYPE: %d\n",if_info->linkType);
1234 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1235 g_print(" (GTK) TAG: %d\n",if_info->tag);
1236 g_print("SUPPORTED CHANNELS POINTER: %p\n",if_info->pSupportedChannels);
1237 g_print(" NUM SUPPORTED CHANNELS: %u\n",if_info->numSupportedChannels);
1239 for(i=0; i<(if_info->numSupportedChannels); i++){
1240 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1241 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1242 g_print(" FREQUENCY: %u\n",if_info->pSupportedChannels[i].Frequency);
1243 g_print(" FLAGS: %u\n",if_info->pSupportedChannels[i].Flags);
1249 * Function used to load the WEP keys for a selected interface
1252 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1254 if (!if_info) return FALSE;
1256 if_info->keysCollectionSize = 0;
1257 if_info->keysCollection = NULL;
1259 if (!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1261 if (if_info->keysCollectionSize == 0)
1263 if_info->keysCollection = NULL;
1264 airpcap_if_close(ad);
1268 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1269 if (!if_info->keysCollection)
1271 if_info->keysCollectionSize = 0;
1272 if_info->keysCollection = NULL;
1273 airpcap_if_close(ad);
1277 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1281 airpcap_if_close(ad);
1286 * Function used to load the WEP keys for a selected interface
1289 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1291 if_info->keysCollectionSize = 0;
1292 if_info->keysCollection = NULL;
1294 if (!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1296 if (if_info->keysCollectionSize == 0)
1298 if_info->keysCollection = NULL;
1299 airpcap_if_close(ad);
1303 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1304 if (!if_info->keysCollection)
1306 if_info->keysCollectionSize = 0;
1307 if_info->keysCollection = NULL;
1308 airpcap_if_close(ad);
1312 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1316 airpcap_if_close(ad);
1321 * Function used to save the WEP keys for a selected interface
1324 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1326 if (!if_info || !AirpcapLoaded) return;
1328 if (if_info->keysCollection != NULL)
1329 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1333 * Function used to save the WEP keys for a selected interface
1336 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1338 if (if_info->keysCollection != NULL)
1339 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1343 * Callback used to free an instance of airpcap_if_info_t
1346 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1348 airpcap_if_info_t *if_info = (airpcap_if_info_t *)data;
1350 if (NULL == if_info)
1353 if (if_info->name != NULL)
1354 g_free(if_info->name);
1356 if (if_info->description != NULL)
1357 g_free(if_info->description);
1359 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1360 if (if_info->keysCollection != NULL)
1362 g_free(if_info->keysCollection);
1363 if_info->keysCollection = NULL;
1366 if (if_info->ip_addr != NULL)
1367 g_slist_free(if_info->ip_addr);
1373 * Function used to free the airpcap interface list
1376 free_airpcap_interface_list(GList *if_list)
1378 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1379 g_list_free(if_list);
1384 * This function will use the airpcap.dll to find all the airpcap devices.
1385 * Will return null if no device is found.
1388 get_airpcap_interface_list(int *err, char **err_str)
1391 airpcap_if_info_t *if_info;
1393 AirpcapDeviceDescription *devsList, *adListEntry;
1394 char errbuf[AIRPCAP_ERRBUF_SIZE];
1400 *err = AIRPCAP_NOT_LOADED;
1404 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1406 /* No interfaces, return il = NULL; */
1407 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1408 if (err_str != NULL)
1409 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1414 * Count the adapters
1416 adListEntry = devsList;
1421 adListEntry = adListEntry->next;
1426 /* No interfaces, return il= NULL */
1427 g_PAirpcapFreeDeviceList(devsList);
1428 *err = NO_AIRPCAP_INTERFACES_FOUND;
1429 if (err_str != NULL)
1435 * Insert the adapters in our list
1437 adListEntry = devsList;
1440 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1441 if (if_info != NULL){
1442 il = g_list_append(il, if_info);
1445 adListEntry = adListEntry->next;
1448 g_PAirpcapFreeDeviceList(devsList);
1454 * Used to retrieve the interface given the name
1455 * (the name is used in AirpcapOpen)
1457 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
1460 airpcap_if_info_t* if_info;
1462 for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
1463 if_info = (airpcap_if_info_t *)curr->data;
1464 if (if_info && (g_ascii_strcasecmp(if_info->name, name) == 0)) {
1472 * Returns the ASCII string of a key given the key bytes
1475 airpcap_get_key_string(AirpcapKey key)
1483 if (key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1485 if (key.KeyLen != 0)
1487 /* Allocate the string used to store the ASCII representation of the WEP key */
1488 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1489 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1492 for(j = 0; j < key.KeyLen; j++)
1494 src = g_strdup_printf("%.2x", key.KeyData[j]);
1496 * XXX - use g_strconcat() or GStrings instead ???
1498 g_strlcat(dst, src, WEP_KEY_MAX_CHAR_SIZE+1);
1503 else if (key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1505 /* XXX - Add code here */
1507 else if (key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1509 /* XXX - Add code here */
1513 /* XXX - Add code here */
1520 * Clear keys and decryption status for the specified interface
1523 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1525 if (info_if != NULL)
1527 if (info_if->keysCollection != NULL)
1529 g_free(info_if->keysCollection);
1530 info_if->keysCollection = NULL;
1533 info_if->keysCollectionSize = 0;
1535 info_if->DecryptionOn = AIRPCAP_DECRYPTION_OFF;
1536 info_if->saved = FALSE;
1541 * Used to retrieve the two chars string from interface
1544 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1550 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1552 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1553 * Otherwise, check if it is the "Any" adapter...
1557 if (g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1558 number = g_strdup_printf("??");
1560 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1564 number = g_strdup_printf("%.2u",n);
1571 * Used to retrieve the two chars string from interface
1574 airpcap_get_if_string_number_from_description(gchar* description)
1579 number = (gchar*)g_malloc(sizeof(gchar)*3);
1581 pointer = g_strrstr(description,"#\0");
1583 number[0] = *(pointer+1);
1584 number[1] = *(pointer+2);
1591 * Returns the default airpcap interface of a list, NULL if list is empty
1594 airpcap_get_default_if(GList* airpcap_if_list_p)
1596 airpcap_if_info_t* if_info = NULL;
1598 if ((prefs.capture_device != NULL) && (*prefs.capture_device != '\0'))
1600 if_info = get_airpcap_if_from_name(airpcap_if_list_p,
1601 get_if_name(prefs.capture_device));
1607 * Load the configuration for the specified interface
1610 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1612 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1615 if (if_info != NULL)
1617 ad = airpcap_if_open(if_info->name, ebuf);
1621 /* Stop blinking (if it was blinking!)*/
1622 if (if_info->blinking)
1624 /* Turn on the light (if it was off) */
1625 if (!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1628 /* Apply settings... */
1629 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1630 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1631 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1632 airpcap_if_get_link_type(ad,&(if_info->linkType));
1633 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1634 /* get the keys, if everything is ok, close the adapter */
1635 if (airpcap_if_load_keys(ad,if_info))
1636 airpcap_if_close(ad);
1638 if_info->saved = TRUE;
1642 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1648 * Save the configuration for the specified interface
1651 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1653 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1656 if (if_info != NULL)
1658 ad = airpcap_if_open(if_info->name, ebuf);
1662 /* Stop blinking (if it was blinking!)*/
1663 if (if_info->blinking)
1665 /* Turn on the light (if it was off) */
1666 if (!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1669 /* Apply settings... */
1670 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1671 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1672 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1673 airpcap_if_set_link_type(ad,if_info->linkType);
1674 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1675 airpcap_if_save_keys(ad,if_info);
1677 /* ... and save them */
1678 if (!airpcap_if_store_cur_config_as_adapter_default(ad))
1680 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.");
1681 if_info->saved = FALSE;
1682 airpcap_if_close(ad);
1686 if_info->saved = TRUE;
1687 airpcap_if_close(ad);
1691 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1697 * Save the configuration for the specified interface
1700 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1702 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1705 if (fake_if_info != NULL)
1707 ad = airpcap_if_open(fake_if_info->name, ebuf);
1711 /* Apply decryption settings... */
1712 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1713 airpcap_if_save_driver_keys(ad,fake_if_info);
1714 airpcap_if_close(ad);
1718 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1726 * DECRYPTION KEYS FUNCTIONS
1729 * This function is used for DEBUG POURPOSES ONLY!!!
1732 print_key_list(GList* key_list)
1735 decryption_key_t* tmp;
1737 if (key_list == NULL)
1739 g_print("\n\n******* KEY LIST NULL *******\n\n");
1743 n = g_list_length(key_list);
1745 g_print("\n\n********* KEY LIST **********\n\n");
1747 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1749 for(i =0; i < n; i++)
1751 g_print("[%d] :\n",i+1);
1752 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1753 g_print("KEY : %s\n",tmp->key->str);
1755 g_print("BITS: %d\n",tmp->bits);
1757 if (tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1758 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1759 else if (tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1760 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1761 else if (tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1762 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1764 g_print("TYPE: %s\n","???");
1766 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1767 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1771 g_print("\n*****************************\n\n");
1775 * Retrieves a GList of decryption_key_t structures containing infos about the
1776 * keys for the given adapter... returns NULL if no keys are found.
1779 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1782 char* tmp_key = NULL;
1783 guint i,keys_in_list = 0;
1786 decryption_key_t *new_key = NULL;
1787 GList *key_list = NULL;
1789 /* Number of keys in key list */
1790 if (info_if->keysCollectionSize != 0)
1791 keys_in_list = AirpcapKeysCollectionSizeToKeyCount(info_if->keysCollectionSize);
1795 for(i=0; i<keys_in_list; i++)
1797 /* Different things to do depending on the key type */
1798 if (info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1800 /* allocate memory for the new key item */
1801 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1803 /* fill the fields */
1805 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1806 new_key->key = g_string_new(tmp_key);
1810 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1812 /* SSID not used in WEP keys */
1813 new_key->ssid = NULL;
1815 /* TYPE (WEP in this case) */
1816 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1818 /* Append the new element in the list */
1819 key_list = g_list_append(key_list,(gpointer)new_key);
1821 else if (info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1823 /* XXX - Not supported yet */
1825 else if (info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1827 /* XXX - Not supported yet */
1835 * Retrieves a GList of decryption_key_t structures containing infos about the
1836 * keys for the global AirPcap driver... returns NULL if no keys are found.
1839 get_airpcap_driver_keys(void)
1842 char *tmp_key = NULL;
1843 guint i,keys_in_list = 0;
1846 decryption_key_t *new_key = NULL;
1847 GList *key_list = NULL;
1850 * To read the drivers general settings we need to create and use one airpcap adapter...
1851 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1853 airpcap_if_info_t* fake_info_if = NULL;
1855 /* Create the fake_info_if from the first adapter of the list */
1856 fake_info_if = airpcap_driver_fake_if_info_new();
1858 if (fake_info_if == NULL)
1861 /* Number of keys in key list */
1862 if (fake_info_if->keysCollectionSize != 0)
1863 keys_in_list = AirpcapKeysCollectionSizeToKeyCount(fake_info_if->keysCollectionSize);
1867 for(i=0; i<keys_in_list; i++)
1869 /* Different things to do depending on the key type */
1870 if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1872 /* allocate memory for the new key item */
1873 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1875 /* fill the fields */
1877 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1878 new_key->key = g_string_new(tmp_key);
1879 if (tmp_key != NULL) g_free(tmp_key);
1882 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1884 /* SSID not used in WEP keys */
1885 new_key->ssid = NULL;
1887 /* TYPE (WEP in this case) */
1888 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
1890 /* Append the new element in the list */
1891 key_list = g_list_append(key_list,(gpointer)new_key);
1893 else if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1895 /* XXX - Not supported yet */
1897 else if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1899 /* XXX - Not supported yet */
1903 airpcap_if_info_free(fake_info_if);
1909 * Returns the list of the decryption keys specified for wireshark, NULL if
1913 get_wireshark_keys(void)
1915 keys_cb_data_t *wep_user_data = NULL;
1917 GList *final_list = NULL;
1918 GList *wep_final_list = NULL;
1920 /* Retrieve the wlan preferences */
1921 wlan_prefs = prefs_find_module("wlan");
1923 /* Allocate a structure used to keep infos between the callbacks */
1924 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1926 /* Fill the structure */
1927 wep_user_data->list = NULL;
1928 wep_user_data->current_index = 0;
1929 wep_user_data->number_of_keys= 0; /* Still unknown */
1931 /* Run the callback on each 802.11 preference */
1932 /* XXX - Right now, only WEP keys will be loaded */
1933 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1935 /* Copy the list field in the user data structure pointer into the final_list */
1936 wep_final_list = wep_user_data->list;
1938 /* XXX - Merge the three lists!!!!! */
1939 final_list = wep_final_list;
1941 /* free the wep_user_data structure */
1942 g_free(wep_user_data);
1948 * Merges two lists of keys and return a newly created GList. If a key is
1949 * found multiple times, it will just appear once!
1950 * list1 and list 2 pointer will have to be freed manually if needed!!!
1951 * If the total number of keys exceeeds the maximum number allowed,
1952 * exceeding keys will be discarded...
1955 merge_key_list(GList* list1, GList* list2)
1959 decryption_key_t *dk1=NULL,
1963 GList* merged_list = NULL;
1965 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);
1993 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1994 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
1996 new_dk->bits = dk1->bits;
1997 new_dk->type = dk1->type;
1998 new_dk->key = g_string_new(dk1->key->str);
1999 new_dk->ssid = byte_array_dup(dk1->ssid);
2001 /* Check the total length of the merged list */
2002 if (g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2003 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2008 n1 = g_list_length(list1);
2009 n2 = g_list_length(list2);
2011 /* Copy the whole list1 into merged_list */
2014 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2015 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2017 new_dk->bits = dk1->bits;
2018 new_dk->type = dk1->type;
2019 new_dk->key = g_string_new(dk1->key->str);
2020 new_dk->ssid = byte_array_dup(dk1->ssid);
2022 /* Check the total length of the merged list */
2023 if (g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2024 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2027 /* Look for keys that are present in list2 but aren't in list1 yet...
2028 * Add them to merged_list
2032 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2034 if (!key_is_in_list(dk2,merged_list))
2036 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2038 new_dk->bits = dk2->bits;
2039 new_dk->type = dk2->type;
2040 new_dk->key = g_string_new(dk2->key->str);
2041 new_dk->ssid = byte_array_dup(dk2->ssid);
2043 /* Check the total length of the merged list */
2044 if (g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2045 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2054 * Use this function to free a key list.
2057 free_key_list(GList *list)
2060 decryption_key_t *curr_key;
2065 n = g_list_length(list);
2067 for(i = 0; i < n; i++)
2069 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2071 /* Free all the strings */
2072 if (curr_key->key != NULL)
2073 g_string_free(curr_key->key, TRUE);
2075 if (curr_key->ssid != NULL)
2076 g_byte_array_free(curr_key->ssid, TRUE);
2078 /* free the decryption_key_t structure*/
2091 * If the given key is contained in the list, returns TRUE.
2092 * Returns FALSE otherwise.
2095 key_is_in_list(decryption_key_t *dk,GList *list)
2098 decryption_key_t *curr_key = NULL;
2099 gboolean found = FALSE;
2101 if ( (list == NULL) || (dk == NULL) )
2104 n = g_list_length(list);
2109 for(i = 0; i < n; i++)
2111 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2112 if (keys_are_equals(dk,curr_key))
2120 * Returns TRUE if keys are equals, FALSE otherwise
2123 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2126 if ((k1==NULL) || (k2==NULL))
2129 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2130 /** 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) ) **/
2131 /** return TRUE; **/
2133 if (g_string_equal(k1->key,k2->key) &&
2134 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2135 (k1->type == k2->type))
2137 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2138 if ((k1->ssid == NULL) && (k2->ssid == NULL))
2141 /* If they are not null, they must share the same ssid */
2142 return byte_array_equal(k1->ssid,k2->ssid);
2145 /* Some field is not equal ... */
2150 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2151 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2155 key_lists_are_equal(GList* list1, GList* list2)
2159 guint wep_n1 = 0,wep_n2=0;
2160 GList *wep_list1 = NULL;
2161 GList *wep_list2 = NULL;
2164 decryption_key_t *dk1=NULL,*dk2=NULL;
2166 n1 = g_list_length(list1);
2167 n2 = g_list_length(list2);
2170 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2175 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2176 if (dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2178 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2184 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2185 if (dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2187 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2193 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2198 * Commented, because in the new AirPcap version all the keys will be saved
2199 * into the driver, and all the keys for every specific adapter will be
2200 * removed. This means that this check will always fail... and the user will
2201 * always be asked what to do... and it doesn't make much sense.
2203 /* if (n1 != n2) return FALSE; */
2204 if (wep_n1 != wep_n2) return FALSE;
2210 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2211 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2213 if (!g_string_equal(dk1->key,dk2->key)) return FALSE;
2217 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2218 if (!key_is_in_list(dk2,wep_list1)) return FALSE;
2225 test_if_on(pref_t *pref, gpointer ud)
2230 /* Retrieve user data info */
2231 is_on = (gboolean*)ud;
2234 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2236 number = *pref->varp.boolp;
2238 if (number) *is_on = TRUE;
2239 else *is_on = FALSE;
2247 * Returns TRUE if the Wireshark decryption is active, false otherwise
2248 * XXX - Should we just add a routine to packet-ieee80211.c to grab this directly?
2251 wireshark_decryption_on(void)
2255 /* Retrieve the wlan preferences */
2256 wlan_prefs = prefs_find_module("wlan");
2258 /* Run the callback on each 802.11 preference */
2259 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2265 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2268 airpcap_decryption_on(void)
2270 gboolean is_on = FALSE;
2272 airpcap_if_info_t* fake_if_info = NULL;
2274 fake_if_info = airpcap_driver_fake_if_info_new();
2276 if (fake_if_info != NULL)
2278 if (fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2280 else if (fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2284 airpcap_if_info_free(fake_if_info);
2290 * Free an instance of airpcap_if_info_t
2293 airpcap_if_info_free(airpcap_if_info_t *if_info)
2295 if (if_info != NULL)
2297 if (if_info->name != NULL)
2298 g_free(if_info->name);
2300 if (if_info->description != NULL)
2301 g_free(if_info->description);
2303 if (if_info->keysCollection != NULL)
2305 g_free(if_info->keysCollection);
2306 if_info->keysCollection = NULL;
2309 if (if_info->ip_addr != NULL)
2311 g_slist_free(if_info->ip_addr);
2312 if_info->ip_addr = NULL;
2315 if (if_info != NULL)
2324 set_on_off(pref_t *pref, gpointer ud)
2328 /* Retrieve user data info */
2329 is_on = (gboolean*)ud;
2331 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2335 *pref->varp.boolp = TRUE;
2337 *pref->varp.boolp = FALSE;
2345 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2348 set_wireshark_decryption(gboolean on_off)
2354 /* Retrieve the wlan preferences */
2355 wlan_prefs = prefs_find_module("wlan");
2357 /* Run the callback on each 802.11 preference */
2358 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2361 * Signal that we've changed things, and run the 802.11 dissector's
2364 wlan_prefs->prefs_changed = TRUE;
2366 prefs_apply(wlan_prefs);
2370 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2373 set_airpcap_decryption(gboolean on_off)
2375 /* We need to directly access the .dll functions here... */
2376 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2377 PAirpcapHandle ad,ad_driver;
2379 gboolean success = TRUE;
2383 airpcap_if_info_t* curr_if = NULL;
2384 airpcap_if_info_t* fake_if_info = NULL;
2386 fake_if_info = airpcap_driver_fake_if_info_new();
2388 if (fake_if_info == NULL)
2389 /* We apparently don't have any adapters installed.
2390 * This isn't a failure, so return TRUE
2394 /* Set the driver decryption */
2395 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2399 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2401 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2403 airpcap_if_close(ad_driver);
2406 airpcap_if_info_free(fake_if_info);
2408 n = g_list_length(airpcap_if_list);
2410 /* Set to FALSE the decryption for all the adapters */
2411 /* Apply this change to all the adapters !!! */
2412 for(i = 0; i < n; i++)
2414 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2416 if (curr_if != NULL)
2418 ad = airpcap_if_open(curr_if->name, ebuf);
2421 curr_if->DecryptionOn = AIRPCAP_DECRYPTION_OFF;
2422 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2423 /* Save configuration for the curr_if */
2424 if (!airpcap_if_store_cur_config_as_adapter_default(ad))
2428 airpcap_if_close(ad);
2437 /* DYNAMIC LIBRARY LOADER */
2439 * Used to dynamically load the airpcap library in order link it only when
2440 * it's present on the system
2442 int load_airpcap(void)
2445 gboolean base_functions = TRUE;
2446 gboolean eleven_n_functions = TRUE;
2448 if ((AirpcapLib = ws_load_library("airpcap.dll")) == NULL)
2450 /* Report the error but go on */
2451 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2452 return AirpcapVersion;
2456 if ((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2457 if ((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2458 if ((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2459 if ((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2460 if ((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2461 if ((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2462 if ((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2463 if ((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2464 if ((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2465 if ((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2466 if ((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2467 if ((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2468 if ((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2469 if ((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2470 if ((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2471 if ((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2472 if ((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2473 if ((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2474 if ((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2475 if ((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2476 if ((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2477 if ((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2478 if ((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2479 if ((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2480 if ((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2481 if ((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2482 if ((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2483 if ((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2484 if ((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2485 if ((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2486 if ((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2487 if ((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2489 /* TEST IF AIRPCAP SUPPORTS 11N */
2490 if ((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2491 if ((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2492 if ((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2494 if (base_functions && eleven_n_functions){
2495 AirpcapLoaded = TRUE;
2496 AirpcapVersion = AIRPCAP_DLL_OK;
2497 } else if (base_functions){
2498 AirpcapLoaded = TRUE;
2499 AirpcapVersion = AIRPCAP_DLL_OLD;
2500 return AIRPCAP_DLL_OK;
2502 AirpcapLoaded = FALSE;
2503 AirpcapVersion = AIRPCAP_DLL_ERROR;
2506 return AirpcapVersion;
2508 return AIRPCAP_DLL_NOT_FOUND;
2513 * Append the version of AirPcap with which we were compiled to a GString.
2516 get_compiled_airpcap_version(GString *str)
2518 g_string_append(str, "with AirPcap");
2522 * Append the version of AirPcap with which we we're running to a GString.
2525 get_runtime_airpcap_version(GString *str)
2527 guint vmaj, vmin, vrev, build;
2529 /* See if the DLL has been loaded successfully. Bail if it hasn't */
2530 if (AirpcapLoaded == FALSE) {
2531 g_string_append(str, "without AirPcap");
2535 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
2536 g_string_append_printf(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2539 #endif /* HAVE_AIRPCAP */
2542 * Editor modelines - http://www.wireshark.org/tools/modelines.html
2547 * indent-tabs-mode: nil
2550 * vi: set shiftwidth=4 tabstop=8 expandtab:
2551 * :indentSize=4:tabSize=8:noTabs=true: