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/uat-int.h>
44 #include <epan/dissectors/packet-ieee80211.h>
45 #include <epan/crypt/wep-wpadefs.h>
46 #include <epan/crypt/airpdcap_ws.h>
47 #include <epan/strutil.h>
48 #include <epan/frequency-utils.h>
49 #include "capture_ui_utils.h"
50 #include <wsutil/file_util.h>
52 #include "ui/simple_dialog.h"
55 #include "airpcap_loader.h"
59 * Set to TRUE if the DLL was successfully loaded AND all functions
62 static gboolean AirpcapLoaded = FALSE;
66 * We load dynamically the dag library in order link it only when
67 * it's present on the system
69 static void * AirpcapLib = NULL;
71 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
72 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
73 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
74 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
75 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
76 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
77 static AirpcapReadHandler g_PAirpcapRead;
78 static AirpcapGetStatsHandler g_PAirpcapGetStats;
81 static int AirpcapVersion = 3;
83 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
84 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
85 static AirpcapOpenHandler g_PAirpcapOpen;
86 static AirpcapCloseHandler g_PAirpcapClose;
87 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
88 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
89 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
90 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
91 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
92 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
93 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
94 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
95 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
96 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
97 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
98 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
99 static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys;
100 static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys;
101 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
102 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
103 static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState;
104 static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState;
105 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
106 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
107 static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx;
108 static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx;
109 static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels;
111 /* Airpcap interface list */
112 GList *airpcap_if_list = NULL;
114 /* Airpcap current selected interface */
115 airpcap_if_info_t *airpcap_if_selected = NULL;
117 /* Airpcap current active interface */
118 airpcap_if_info_t *airpcap_if_active = NULL;
120 /* WLAN preferences pointer */
121 module_t *wlan_prefs = NULL;
123 Dot11Channel *pSupportedChannels;
124 guint numSupportedChannels;
126 static AirpcapChannelInfo LegacyChannels[] =
144 static guint num_legacy_channels = 14;
147 * Callback used by the load_wlan_keys() routine in order to read a WEP decryption key
150 get_wep_key(pref_t *pref, gpointer ud)
152 gchar *key_string = NULL;
153 guint8 key_type = AIRPDCAP_KEY_TYPE_WEP;
154 keys_cb_data_t* user_data;
157 const char* err = NULL;
158 uat_wep_key_record_t* wep_keys;
159 decryption_key_t* new_key;
161 /* Retrieve user data info */
162 user_data = (keys_cb_data_t*)ud;
164 if (g_ascii_strcasecmp(pref->name, "wep_key_table") == 0 && pref->type == PREF_UAT)
166 uat = (uat_t *)pref->varp.uat;
167 /* This is just a sanity check. UAT should be loaded */
175 for (i = 0, wep_keys = (uat_wep_key_record_t*)*uat->user_ptr; i < *uat->nrows_p; i++, wep_keys++)
177 /* strip out key type if present */
178 if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WEP ":", 4) == 0) {
179 key_type = AIRPDCAP_KEY_TYPE_WEP;
180 key_string = (gchar*)wep_keys->string+4;
182 else if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WPA_PWD ":", 8) == 0) {
183 key_string = (gchar*)wep_keys->string+8;
184 key_type = AIRPDCAP_KEY_TYPE_WPA_PWD;
186 else if (g_ascii_strncasecmp(wep_keys->string, STRING_KEY_TYPE_WPA_PSK ":", 8) == 0) {
187 key_string = (gchar*)wep_keys->string+8;
188 key_type = AIRPDCAP_KEY_TYPE_WPA_PSK;
191 key_type = wep_keys->key;
192 key_string = (gchar*)wep_keys->string;
195 /* Here we have the string describing the key... */
196 new_key = parse_key_string(key_string, key_type);
200 /* Key is added only if not null ... */
201 user_data->list = g_list_append(user_data->list,new_key);
202 user_data->number_of_keys++;
203 user_data->current_index++;
210 /* Returs TRUE if the WEP key is valid, false otherwise */
212 wep_key_is_valid(char* key)
214 GString *new_key_string;
220 new_key_string = g_string_new(key);
222 if ( ((new_key_string->len) > WEP_KEY_MAX_CHAR_SIZE) || ((new_key_string->len) < 2))
224 g_string_free(new_key_string,FALSE);
227 if ((new_key_string->len % 2) != 0)
229 g_string_free(new_key_string,FALSE);
232 for(i = 0; i < new_key_string->len; i++)
234 if (!g_ascii_isxdigit(new_key_string->str[i]))
236 g_string_free(new_key_string,FALSE);
241 g_string_free(new_key_string,FALSE);
245 /* Callback used by the save_wlan_keys() routine in order to write a decryption key */
247 set_wep_key(pref_t *pref, gpointer ud _U_)
249 keys_cb_data_t* user_data;
253 uat_wep_key_record_t uat_key;
255 decryption_key_t* new_key;
257 /* Retrieve user data info */
258 user_data = (keys_cb_data_t*)ud;
260 if (g_ascii_strcasecmp(pref->name, "wep_key_table") == 0 && pref->type == PREF_UAT)
262 uat = (uat_t *)pref->varp.uat;
263 /* UAT must be loaded */
267 /* Free the old records */
270 for (i = 0; i < user_data->number_of_keys; i++)
272 new_key = (decryption_key_t*)g_list_nth_data(user_data->list,i);
274 uat_key.string = get_key_string(new_key);
275 uat_key.key = new_key->type;
276 uat_add_record(uat, &uat_key);
288 * Function used to read the Decryption Keys from the preferences and store them
289 * properly into the airpcap adapter.
292 load_wlan_driver_wep_keys(void)
294 keys_cb_data_t* user_data;
297 /* Retrieve the wlan preferences */
298 wlan_prefs = prefs_find_module("wlan");
300 /* Allocate a structure used to keep infos between the callbacks */
301 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
303 /* Fill the structure */
304 user_data->list = NULL;
305 user_data->current_index = 0;
306 user_data->number_of_keys= 0; /* Still unknown */
308 /* Run the callback on each 802.11 preference */
309 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)user_data);
311 /* Now the key list should be filled */
314 * Signal that we've changed things, and run the 802.11 dissector's
317 wlan_prefs->prefs_changed = TRUE;
319 prefs_apply(wlan_prefs);
321 write_wlan_driver_wep_keys_to_registry(user_data->list);
324 /* free the WEP key string */
325 for(i=0;i<g_list_length(user_data->list);i++)
327 g_free(g_list_nth(user_data->list,i)->data);
330 /* free the (empty) list */
331 g_list_free(user_data->list);
333 /* free the user_data structure */
336 /* airpcap_if_info_free(fake_info_if); */
342 * This function will tell the airpcap driver the key list to use
343 * This will be stored into the registry...
346 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list)
351 PAirpcapKeysCollection KeysCollection;
352 guint KeysCollectionSize;
354 guint keys_in_list = 0;
355 decryption_key_t* key_item = NULL;
357 keys_in_list = g_list_length(key_list);
360 * Calculate the size of the keys collection
362 KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
365 * Allocate the collection
367 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
374 * Populate the key collection
376 KeysCollection->nKeys = keys_in_list;
378 for(i = 0; i < keys_in_list; i++)
380 KeysCollection->Keys[i].KeyType = AIRPDCAP_KEY_TYPE_WEP;
382 /* Retrieve the Item corresponding to the i-th key */
383 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
384 new_key = g_string_new(key_item->key->str);
386 KeysCollection->Keys[i].KeyLen = (guint) new_key->len / 2;
387 memset(&KeysCollection->Keys[i].KeyData, 0, sizeof(KeysCollection->Keys[i].KeyData));
389 for(j = 0 ; j < new_key->len; j += 2)
391 s[0] = new_key->str[j];
392 s[1] = new_key->str[j+1];
394 KeyByte = (guint8)strtol(s, NULL, 16);
395 KeysCollection->Keys[i].KeyData[j / 2] = KeyByte;
398 g_string_free(new_key,TRUE);
402 * Free the old adapter key collection!
404 if (info_if->keysCollection != NULL)
405 g_free(info_if->keysCollection);
408 * Set this collection ad the new one
410 info_if->keysCollection = KeysCollection;
411 info_if->keysCollectionSize = KeysCollectionSize;
414 * Configuration must be saved
416 info_if->saved = FALSE;
419 * Write down the changes to the registry
421 airpcap_save_selected_if_configuration(info_if);
427 * This function will tell the airpcap driver the key list to use
428 * This will be stored into the registry...
431 write_wlan_driver_wep_keys_to_registry(GList* key_list)
436 PAirpcapKeysCollection KeysCollection;
437 guint KeysCollectionSize;
439 guint keys_in_list = 0;
440 decryption_key_t* key_item = NULL;
441 airpcap_if_info_t* fake_info_if = NULL;
443 /* Create the fake_info_if from the first adapter of the list */
444 fake_info_if = airpcap_driver_fake_if_info_new();
446 if (fake_info_if == NULL)
450 * XXX - When WPA will be supported, change this to: keys_in_list = g_list_length(key_list);
451 * but right now we will have to count only the WEP keys (or we will have a malloc-mess :-) )
453 n = g_list_length(key_list);
454 for(k = 0; k < n; k++ )
455 if (((decryption_key_t*)g_list_nth_data(key_list,k))->type == AIRPDCAP_KEY_TYPE_WEP)
459 * Calculate the size of the keys collection
461 KeysCollectionSize = (guint)AirpcapKeysCollectionSize(keys_in_list);
464 * Allocate the collection
466 KeysCollection = (PAirpcapKeysCollection)g_malloc(KeysCollectionSize);
473 * Populate the key collection
475 KeysCollection->nKeys = keys_in_list;
478 * XXX - If we have, let's say, six keys, the first three are WEP, then two are WPA, and the
479 * last is WEP, we have to scroll the whole list (n) but increment the array counter only
480 * when a WEP key is found (y) .. When WPA will be supported by the driver, I'll have to change
483 y = 0; /* Current position in the key list */
485 for(i = 0; i < n; i++)
487 /* Retrieve the Item corresponding to the i-th key */
488 key_item = (decryption_key_t*)g_list_nth_data(key_list,i);
491 * XXX - The AIRPDCAP_KEY_TYPE_WEP is the only supported right now!
492 * We will have to modify the AirpcapKey structure in order to
493 * support the other two types! What happens now, is that simply the
494 * not supported keys will just be discarded (they will be saved in Wireshark though)
496 if (key_item->type == AIRPDCAP_KEY_TYPE_WEP)
498 KeysCollection->Keys[y].KeyType = AIRPDCAP_KEY_TYPE_WEP;
500 new_key = g_string_new(key_item->key->str);
502 KeysCollection->Keys[y].KeyLen = (guint) new_key->len / 2;
503 memset(&KeysCollection->Keys[y].KeyData, 0, sizeof(KeysCollection->Keys[y].KeyData));
505 for(j = 0 ; j < new_key->len; j += 2)
507 s[0] = new_key->str[j];
508 s[1] = new_key->str[j+1];
510 KeyByte = (guint8)strtol(s, NULL, 16);
511 KeysCollection->Keys[y].KeyData[j / 2] = KeyByte;
513 /* XXX - Change when WPA will be supported!!! */
515 g_string_free(new_key,TRUE);
517 else if (key_item->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
519 /* XXX - The driver cannot deal with this kind of key yet... */
521 else if (key_item->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
523 /* XXX - The driver cannot deal with this kind of key yet... */
528 * Free the old adapter key collection!
530 if (fake_info_if->keysCollection != NULL)
531 g_free(fake_info_if->keysCollection);
534 * Set this collection ad the new one
536 fake_info_if->keysCollection = KeysCollection;
537 fake_info_if->keysCollectionSize = KeysCollectionSize;
540 * Configuration must be saved
542 fake_info_if->saved = FALSE;
545 * Write down the changes to the registry
547 airpcap_save_driver_if_configuration(fake_info_if);
549 airpcap_if_info_free(fake_info_if);
555 * Function used to save to the preference file the Decryption Keys.
558 save_wlan_driver_wep_keys(void)
560 GList* key_list = NULL;
561 char* tmp_key = NULL;
562 guint keys_in_list,i;
563 keys_cb_data_t* user_data;
564 airpcap_if_info_t* fake_info_if = NULL;
566 /* Create the fake_info_if from the first adapter of the list */
567 fake_info_if = airpcap_driver_fake_if_info_new();
569 if (fake_info_if == NULL)
572 /* Retrieve the wlan preferences */
573 wlan_prefs = prefs_find_module("wlan");
575 /* Allocate a structure used to keep infos between the callbacks */
576 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
578 /* Number of keys in key list */
579 if (fake_info_if->keysCollectionSize != 0)
580 keys_in_list = AirpcapKeysCollectionSizeToKeyCount(fake_info_if->keysCollectionSize);
584 for(i=0; i<keys_in_list; i++)
586 /* Only if it is a WEP key... */
587 if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
589 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
590 key_list = g_list_append(key_list,g_strdup(tmp_key));
595 /* Now we know the exact number of WEP keys in the list, so store it ... */
596 keys_in_list = g_list_length(key_list);
598 /* Fill the structure */
599 user_data->list = key_list;
600 user_data->current_index = 0;
601 user_data->number_of_keys= keys_in_list;
603 /* Retrieve the wlan preferences */
604 wlan_prefs = prefs_find_module("wlan");
606 /* Run the callback on each 802.11 preference */
607 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
609 /* Signal that we've changed things, and run the 802.11 dissector's
611 wlan_prefs->prefs_changed = TRUE;
613 /* Apply changes for the specified preference */
614 prefs_apply(wlan_prefs);
617 /* free the WEP key string */
618 for(i=0;i<g_list_length(user_data->list);i++)
620 g_free(g_list_nth(user_data->list,i)->data);
623 /* free the (empty) list */
624 g_list_free(user_data->list);
626 /* free the user_data structure */
629 airpcap_if_info_free(fake_info_if);
635 * Function used to save to the preference file the Decryption Keys.
638 save_wlan_wireshark_wep_keys(GList* key_ls)
640 GList* key_list = NULL;
641 guint keys_in_list,i;
642 keys_cb_data_t* user_data;
643 decryption_key_t* tmp_dk;
645 /* Retrieve the wlan preferences */
646 wlan_prefs = prefs_find_module("wlan");
648 /* Allocate a structure used to keep infos between the callbacks */
649 user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
651 keys_in_list = g_list_length(key_ls);
655 /* Fill the structure */
656 user_data->list = key_list;
657 user_data->current_index = 0;
658 user_data->number_of_keys= keys_in_list;
660 /* Retrieve the wlan preferences */
661 wlan_prefs = prefs_find_module("wlan");
663 /* Run the callback on each 802.11 preference */
664 prefs_pref_foreach(wlan_prefs, set_wep_key, (gpointer)user_data);
666 /* Signal that we've changed things, and run the 802.11 dissector's
668 wlan_prefs->prefs_changed = TRUE;
670 /* Apply changes for the specified preference */
671 prefs_apply(wlan_prefs);
674 /* free the WEP key string */
675 for(i=0;i<g_list_length(user_data->list);i++)
677 tmp_dk = (decryption_key_t*)g_list_nth(user_data->list,i)->data;
678 g_string_free(tmp_dk->key,TRUE);
679 if (tmp_dk->ssid != NULL) g_byte_array_free(tmp_dk->ssid,TRUE);
682 /* free the (empty) list */
683 g_list_free(user_data->list);
685 /* free the user_data structure */
692 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
693 * "get_airpcap_interface_list()".
696 cant_get_airpcap_if_list_error_message(const char *err_str)
698 return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
702 * Airpcap wrapper, used to store the current settings for the selected adapter
705 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
707 if (!AirpcapLoaded) return FALSE;
708 return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
712 * Airpcap wrapper, used to open an airpcap adapter
715 airpcap_if_open(gchar * name, gchar * err)
717 if (!AirpcapLoaded) return NULL;
718 if (name == NULL) return NULL;
719 return g_PAirpcapOpen(name,err);
723 * Airpcap wrapper, used to close an airpcap adapter
726 airpcap_if_close(PAirpcapHandle handle)
728 if (!AirpcapLoaded) return;
729 g_PAirpcapClose(handle);
733 * Retrieve the state of the Airpcap DLL
736 airpcap_get_dll_state(void)
738 return AirpcapVersion;
742 * Airpcap wrapper, used to turn on the led of an airpcap adapter
745 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber)
747 if (!AirpcapLoaded) return FALSE;
748 return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
752 * Airpcap wrapper, used to turn off the led of an airpcap adapter
755 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber)
757 if (!AirpcapLoaded) return FALSE;
758 return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
762 * Airpcap wrapper, used to get the channel of an airpcap adapter
765 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch)
767 if (!AirpcapLoaded) return FALSE;
768 return g_PAirpcapGetDeviceChannel(ah,ch);
772 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
775 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint * nInfo)
777 if (!AirpcapLoaded) return FALSE;
778 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD) {
779 *nInfo = num_legacy_channels;
780 *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
783 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK) {
784 return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
790 * Airpcap wrapper, used to get the supported channels of an airpcap adapter
793 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint * pNumSupportedChannels)
795 AirpcapChannelInfo *chanInfo;
796 guint i=0, j=0, numInfo = 0;
800 if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
802 numSupportedChannels = 0;
805 * allocate a bigger array
810 pSupportedChannels = (Dot11Channel *)g_malloc(numInfo * (sizeof *pSupportedChannels));
812 for (i = 0; i < numInfo; i++)
814 guint supportedChannel = G_MAXUINT;
817 * search if we have it already
819 for (j = 0; j < numSupportedChannels; j++)
821 if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
823 supportedChannel = j;
828 if (supportedChannel == G_MAXUINT)
831 * not found, create a new item
833 pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
835 switch(chanInfo[i].ExtChannel)
838 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
841 pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
845 pSupportedChannels[numSupportedChannels].Flags = 0;
849 * Gather channel information
852 pSupportedChannels[numSupportedChannels].Flags |=
853 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
854 FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
855 pSupportedChannels[numSupportedChannels].Channel =
856 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
857 numSupportedChannels++;
862 * just update the ext channel flags
864 switch(chanInfo[i].ExtChannel)
867 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
870 pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
879 if (numSupportedChannels < 1)
882 * Now sort the list by frequency
884 for (i = 0 ; i < numSupportedChannels - 1; i++)
886 for (j = i + 1; j < numSupportedChannels; j++)
888 if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
890 Dot11Channel temp = pSupportedChannels[i];
891 pSupportedChannels[i] = pSupportedChannels[j];
892 pSupportedChannels[j] = temp;
897 *pNumSupportedChannels = numSupportedChannels;
898 return pSupportedChannels;
902 * Airpcap wrapper, used to set the channel of an airpcap adapter
905 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch)
907 if (!AirpcapLoaded) return FALSE;
908 return g_PAirpcapSetDeviceChannel(ah,ch);
912 * Airpcap wrapper, used to set the frequency of an airpcap adapter
915 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
917 if (!AirpcapLoaded) return FALSE;
918 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
920 channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
925 return airpcap_if_set_device_channel(ah, channel);
927 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
928 return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
935 * Airpcap wrapper, used to get the frequency of an airpcap adapter
938 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
940 if (!AirpcapLoaded) return FALSE;
942 pChannelInfo->Frequency = 0;
943 pChannelInfo->ExtChannel = 0;
944 pChannelInfo->Reserved[0] = 0;
945 pChannelInfo->Reserved[1] = 0;
946 pChannelInfo->Reserved[2] = 0;
948 if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
952 if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
954 chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
955 if (chan_freq == 0) return FALSE;
956 pChannelInfo->Frequency = chan_freq;
959 } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
960 return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
966 * Airpcap wrapper, used to get the link type of an airpcap adapter
969 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
971 if (!AirpcapLoaded) return FALSE;
972 return g_PAirpcapGetLinkType(ah,lt);
976 * Airpcap wrapper, used to set the link type of an airpcap adapter
979 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
981 if (!AirpcapLoaded) return FALSE;
982 return g_PAirpcapSetLinkType(ah,lt);
986 * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
989 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * fcs)
991 if (!AirpcapLoaded) return FALSE;
992 return g_PAirpcapGetFcsPresence(ah,fcs);
996 * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
999 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean fcs)
1001 if (!AirpcapLoaded) return FALSE;
1002 return g_PAirpcapSetFcsPresence(ah,fcs);
1006 * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
1009 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1011 if (!AirpcapLoaded) return FALSE;
1012 return g_PAirpcapGetDecryptionState(ah,PEnable);
1016 * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
1019 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1021 if (!AirpcapLoaded) return FALSE;
1022 return g_PAirpcapSetDecryptionState(ah,Enable);
1026 * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
1029 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
1031 if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
1032 return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
1036 * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
1039 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
1041 if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
1042 return g_PAirpcapSetDriverDecryptionState(ah,Enable);
1046 * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
1049 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
1051 if (!AirpcapLoaded) return FALSE;
1052 return g_PAirpcapGetFcsValidation(ah,val);
1056 * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
1059 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
1061 if (!AirpcapLoaded) return FALSE;
1062 return g_PAirpcapSetFcsValidation(ah,val);
1066 * Airpcap wrapper, used to save the settings for the selected_if
1069 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1071 if (!AirpcapLoaded) return FALSE;
1072 return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
1076 * Airpcap wrapper, used to save the settings for the selected_if
1079 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1081 if (!AirpcapLoaded) return FALSE;
1082 return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1086 * Airpcap wrapper, used to save the driver's set of keys
1089 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
1091 if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
1092 return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
1096 * Airpcap wrapper, used to load the driver's set of keys
1099 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
1101 if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
1102 return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
1106 * This function will create a new airpcap_if_info_t using a name and a description
1109 airpcap_if_info_new(char *name, char *description)
1112 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1114 airpcap_if_info_t *if_info = NULL;
1116 /* Probably I have to switch on the leds!!! */
1117 ad = airpcap_if_open(name, ebuf);
1120 if_info = (airpcap_if_info_t *)g_malloc0(sizeof (airpcap_if_info_t));
1121 if_info->name = g_strdup(name);
1122 if (description == NULL){
1123 if_info->description = NULL;
1125 if_info->description = g_strdup(description);
1128 if_info->ip_addr = NULL;
1129 if_info->loopback = FALSE;
1130 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1131 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1132 airpcap_if_get_link_type(ad,&(if_info->linkType));
1133 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1134 if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
1135 airpcap_if_turn_led_on(ad, 0);
1136 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1137 if_info->led = TRUE;
1138 if_info->blinking = FALSE;
1139 if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1141 /* get the keys, if everything is ok, close the adapter */
1142 if (airpcap_if_load_keys(ad,if_info))
1144 airpcap_if_close(ad);
1151 * This function will create a new fake drivers' interface, to load global keys...
1154 airpcap_driver_fake_if_info_new(void)
1157 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1159 airpcap_if_info_t *if_info = NULL;
1160 airpcap_if_info_t *fake_if_info = NULL;
1162 /* Maybe for some reason no airpcap adapter is found */
1163 if (airpcap_if_list == NULL)
1167 * Retrieve the first AirPcap adapter available. If no interface is found,
1168 * it is not possible to retrieve the driver's settings, so return NULL.
1170 if_info = (airpcap_if_info_t *)g_list_nth_data(airpcap_if_list,0);
1171 if (if_info == NULL)
1174 /* Open the 'fake' adapter */
1175 ad = airpcap_if_open(if_info->name, ebuf);
1178 fake_if_info = (airpcap_if_info_t *)g_malloc(sizeof (airpcap_if_info_t));
1179 fake_if_info->name = g_strdup(if_info->name);
1180 fake_if_info->description = g_strdup(if_info->description);
1181 fake_if_info->loopback = FALSE;
1182 fake_if_info->ip_addr = NULL;
1183 airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
1184 airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
1185 airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
1186 airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
1187 airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
1188 airpcap_if_turn_led_on(ad, 0);
1189 fake_if_info->led = TRUE;
1190 fake_if_info->blinking = FALSE;
1191 fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
1193 /* get the keys, if everything is ok, close the adapter */
1194 if (airpcap_if_load_driver_keys(ad,fake_if_info))
1196 airpcap_if_close(ad);
1200 return fake_if_info;
1204 * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
1207 airpcap_if_info_print(airpcap_if_info_t* if_info)
1210 if (if_info == NULL)
1212 g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
1216 g_print("\n----------------- AirPcap Interface \n");
1217 g_print(" NAME: %s\n",if_info->name);
1218 g_print(" DESCRIPTION: %s\n",if_info->description);
1219 g_print(" BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
1220 g_print(" channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
1221 g_print(" channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
1222 g_print(" CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
1223 g_print(" DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
1224 g_print(" IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
1225 g_print(" FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
1226 g_print(" KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
1227 g_print(" KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
1228 g_print(" LED: %s\n",if_info->led ? "ON" : "OFF");
1229 g_print(" LINKTYPE: %d\n",if_info->linkType);
1230 g_print(" LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
1231 g_print(" (GTK) TAG: %d\n",if_info->tag);
1232 g_print("SUPPORTED CHANNELS POINTER: %p\n",if_info->pSupportedChannels);
1233 g_print(" NUM SUPPORTED CHANNELS: %u\n",if_info->numSupportedChannels);
1235 for(i=0; i<(if_info->numSupportedChannels); i++){
1236 g_print("\n SUPPORTED CHANNEL #%u\n",i+1);
1237 g_print(" CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
1238 g_print(" FREQUENCY: %u\n",if_info->pSupportedChannels[i].Frequency);
1239 g_print(" FLAGS: %u\n",if_info->pSupportedChannels[i].Flags);
1245 * Function used to load the WEP keys for a selected interface
1248 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1250 if (!if_info) return FALSE;
1252 if_info->keysCollectionSize = 0;
1253 if_info->keysCollection = NULL;
1255 if (!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
1257 if (if_info->keysCollectionSize == 0)
1259 if_info->keysCollection = NULL;
1260 airpcap_if_close(ad);
1264 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1265 if (!if_info->keysCollection)
1267 if_info->keysCollectionSize = 0;
1268 if_info->keysCollection = NULL;
1269 airpcap_if_close(ad);
1273 airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1277 airpcap_if_close(ad);
1282 * Function used to load the WEP keys for a selected interface
1285 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1287 if_info->keysCollectionSize = 0;
1288 if_info->keysCollection = NULL;
1290 if (!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
1292 if (if_info->keysCollectionSize == 0)
1294 if_info->keysCollection = NULL;
1295 airpcap_if_close(ad);
1299 if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
1300 if (!if_info->keysCollection)
1302 if_info->keysCollectionSize = 0;
1303 if_info->keysCollection = NULL;
1304 airpcap_if_close(ad);
1308 airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
1312 airpcap_if_close(ad);
1317 * Function used to save the WEP keys for a selected interface
1320 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1322 if (!if_info || !AirpcapLoaded) return;
1324 if (if_info->keysCollection != NULL)
1325 g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
1329 * Function used to save the WEP keys for a selected interface
1332 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
1334 if (if_info->keysCollection != NULL)
1335 airpcap_if_set_driver_keys(ad,if_info->keysCollection);
1339 * Callback used to free an instance of airpcap_if_info_t
1342 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
1344 airpcap_if_info_t *if_info = (airpcap_if_info_t *)data;
1346 if (NULL == if_info)
1349 if (if_info->name != NULL)
1350 g_free(if_info->name);
1352 if (if_info->description != NULL)
1353 g_free(if_info->description);
1355 /* XXX - FREE THE WEP KEY LIST HERE!!!*/
1356 if (if_info->keysCollection != NULL)
1358 g_free(if_info->keysCollection);
1359 if_info->keysCollection = NULL;
1362 if (if_info->ip_addr != NULL)
1363 g_slist_free(if_info->ip_addr);
1369 * Function used to free the airpcap interface list
1372 free_airpcap_interface_list(GList *if_list)
1374 g_list_foreach(if_list, free_airpcap_if_cb, NULL);
1375 g_list_free(if_list);
1380 * This function will use the airpcap.dll to find all the airpcap devices.
1381 * Will return null if no device is found.
1384 get_airpcap_interface_list(int *err, char **err_str)
1387 airpcap_if_info_t *if_info;
1389 AirpcapDeviceDescription *devsList, *adListEntry;
1390 char errbuf[AIRPCAP_ERRBUF_SIZE];
1396 *err = AIRPCAP_NOT_LOADED;
1400 if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
1402 /* No interfaces, return il = NULL; */
1403 *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
1404 if (err_str != NULL)
1405 *err_str = cant_get_airpcap_if_list_error_message(errbuf);
1410 * Count the adapters
1412 adListEntry = devsList;
1417 adListEntry = adListEntry->next;
1422 /* No interfaces, return il= NULL */
1423 g_PAirpcapFreeDeviceList(devsList);
1424 *err = NO_AIRPCAP_INTERFACES_FOUND;
1425 if (err_str != NULL)
1431 * Insert the adapters in our list
1433 adListEntry = devsList;
1436 if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
1437 if (if_info != NULL){
1438 il = g_list_append(il, if_info);
1441 adListEntry = adListEntry->next;
1444 g_PAirpcapFreeDeviceList(devsList);
1450 * Used to retrieve the interface given the name
1451 * (the name is used in AirpcapOpen)
1453 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
1456 airpcap_if_info_t* if_info;
1458 for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
1459 if_info = (airpcap_if_info_t *)curr->data;
1460 if (if_info && (g_ascii_strcasecmp(if_info->name, name) == 0)) {
1468 * Returns the ASCII string of a key given the key bytes
1471 airpcap_get_key_string(AirpcapKey key)
1479 if (key.KeyType == AIRPDCAP_KEY_TYPE_WEP)
1481 if (key.KeyLen != 0)
1483 /* Allocate the string used to store the ASCII representation of the WEP key */
1484 dst = (gchar*)g_malloc(sizeof(gchar)*WEP_KEY_MAX_CHAR_SIZE + 1);
1485 /* Make sure that the first char is '\0' in order to make g_strlcat() work */
1488 for(j = 0; j < key.KeyLen; j++)
1490 src = g_strdup_printf("%.2x", key.KeyData[j]);
1492 * XXX - use g_strconcat() or GStrings instead ???
1494 g_strlcat(dst, src, WEP_KEY_MAX_CHAR_SIZE+1);
1499 else if (key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1501 /* XXX - Add code here */
1503 else if (key.KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1505 /* XXX - Add code here */
1509 /* XXX - Add code here */
1516 * Clear keys and decryption status for the specified interface
1519 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
1521 if (info_if != NULL)
1523 if (info_if->keysCollection != NULL)
1525 g_free(info_if->keysCollection);
1526 info_if->keysCollection = NULL;
1529 info_if->keysCollectionSize = 0;
1531 info_if->DecryptionOn = AIRPCAP_DECRYPTION_OFF;
1532 info_if->saved = FALSE;
1537 * Used to retrieve the two chars string from interface
1540 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
1546 a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
1548 /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
1549 * Otherwise, check if it is the "Any" adapter...
1553 if (g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
1554 number = g_strdup_printf("??");
1556 number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
1560 number = g_strdup_printf("%.2u",n);
1567 * Used to retrieve the two chars string from interface
1570 airpcap_get_if_string_number_from_description(gchar* description)
1575 number = (gchar*)g_malloc(sizeof(gchar)*3);
1577 pointer = g_strrstr(description,"#\0");
1579 number[0] = *(pointer+1);
1580 number[1] = *(pointer+2);
1587 * Returns the default airpcap interface of a list, NULL if list is empty
1590 airpcap_get_default_if(GList* airpcap_if_list_p)
1592 airpcap_if_info_t* if_info = NULL;
1594 if ((prefs.capture_device != NULL) && (*prefs.capture_device != '\0'))
1596 if_info = get_airpcap_if_from_name(airpcap_if_list_p,
1597 get_if_name(prefs.capture_device));
1603 * Load the configuration for the specified interface
1606 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
1608 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1611 if (if_info != NULL)
1613 ad = airpcap_if_open(if_info->name, ebuf);
1617 /* Stop blinking (if it was blinking!)*/
1618 if (if_info->blinking)
1620 /* Turn on the light (if it was off) */
1621 if (!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1624 /* Apply settings... */
1625 airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1626 airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1627 airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1628 airpcap_if_get_link_type(ad,&(if_info->linkType));
1629 airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1630 /* get the keys, if everything is ok, close the adapter */
1631 if (airpcap_if_load_keys(ad,if_info))
1632 airpcap_if_close(ad);
1634 if_info->saved = TRUE;
1638 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1644 * Save the configuration for the specified interface
1647 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1649 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1652 if (if_info != NULL)
1654 ad = airpcap_if_open(if_info->name, ebuf);
1658 /* Stop blinking (if it was blinking!)*/
1659 if (if_info->blinking)
1661 /* Turn on the light (if it was off) */
1662 if (!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1665 /* Apply settings... */
1666 airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1667 airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1668 airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1669 airpcap_if_set_link_type(ad,if_info->linkType);
1670 airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1671 airpcap_if_save_keys(ad,if_info);
1673 /* ... and save them */
1674 if (!airpcap_if_store_cur_config_as_adapter_default(ad))
1676 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.");
1677 if_info->saved = FALSE;
1678 airpcap_if_close(ad);
1682 if_info->saved = TRUE;
1683 airpcap_if_close(ad);
1687 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1693 * Save the configuration for the specified interface
1696 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1698 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1701 if (fake_if_info != NULL)
1703 ad = airpcap_if_open(fake_if_info->name, ebuf);
1707 /* Apply decryption settings... */
1708 airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1709 airpcap_if_save_driver_keys(ad,fake_if_info);
1710 airpcap_if_close(ad);
1714 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1722 * DECRYPTION KEYS FUNCTIONS
1725 * This function is used for DEBUG POURPOSES ONLY!!!
1728 print_key_list(GList* key_list)
1731 decryption_key_t* tmp;
1733 if (key_list == NULL)
1735 g_print("\n\n******* KEY LIST NULL *******\n\n");
1739 n = g_list_length(key_list);
1741 g_print("\n\n********* KEY LIST **********\n\n");
1743 g_print("NUMBER OF KEYS IN LIST : %d\n\n",n);
1745 for(i =0; i < n; i++)
1747 g_print("[%d] :\n",i+1);
1748 tmp = (decryption_key_t*)(g_list_nth_data(key_list,i));
1749 g_print("KEY : %s\n",tmp->key->str);
1751 g_print("BITS: %d\n",tmp->bits);
1753 if (tmp->type == AIRPDCAP_KEY_TYPE_WEP)
1754 g_print("TYPE: %s\n",AIRPCAP_WEP_KEY_STRING);
1755 else if (tmp->type == AIRPDCAP_KEY_TYPE_WPA_PWD)
1756 g_print("TYPE: %s\n",AIRPCAP_WPA_PWD_KEY_STRING);
1757 else if (tmp->type == AIRPDCAP_KEY_TYPE_WPA_PMK)
1758 g_print("TYPE: %s\n",AIRPCAP_WPA_BIN_KEY_STRING);
1760 g_print("TYPE: %s\n","???");
1762 g_print("SSID: %s\n",(tmp->ssid != NULL) ?
1763 format_text((guchar *)tmp->ssid->data, tmp->ssid->len) : "---");
1767 g_print("\n*****************************\n\n");
1771 * Retrieves a GList of decryption_key_t structures containing infos about the
1772 * keys for the given adapter... returns NULL if no keys are found.
1775 get_airpcap_device_keys(airpcap_if_info_t* info_if)
1778 char* tmp_key = NULL;
1779 guint i,keys_in_list = 0;
1782 decryption_key_t *new_key = NULL;
1783 GList *key_list = NULL;
1785 /* Number of keys in key list */
1786 if (info_if->keysCollectionSize != 0)
1787 keys_in_list = AirpcapKeysCollectionSizeToKeyCount(info_if->keysCollectionSize);
1791 for(i=0; i<keys_in_list; i++)
1793 /* Different things to do depending on the key type */
1794 if (info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1796 /* allocate memory for the new key item */
1797 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1799 /* fill the fields */
1801 tmp_key = airpcap_get_key_string(info_if->keysCollection->Keys[i]);
1802 new_key->key = g_string_new(tmp_key);
1806 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1808 /* SSID not used in WEP keys */
1809 new_key->ssid = NULL;
1811 /* TYPE (WEP in this case) */
1812 new_key->type = info_if->keysCollection->Keys[i].KeyType;
1814 /* Append the new element in the list */
1815 key_list = g_list_append(key_list,(gpointer)new_key);
1817 else if (info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1819 /* XXX - Not supported yet */
1821 else if (info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1823 /* XXX - Not supported yet */
1831 * Retrieves a GList of decryption_key_t structures containing infos about the
1832 * keys for the global AirPcap driver... returns NULL if no keys are found.
1835 get_airpcap_driver_keys(void)
1838 char *tmp_key = NULL;
1839 guint i,keys_in_list = 0;
1842 decryption_key_t *new_key = NULL;
1843 GList *key_list = NULL;
1846 * To read the drivers general settings we need to create and use one airpcap adapter...
1847 * The only way to do that is to instantiate a fake adapter, and then close it and delete it.
1849 airpcap_if_info_t* fake_info_if = NULL;
1851 /* Create the fake_info_if from the first adapter of the list */
1852 fake_info_if = airpcap_driver_fake_if_info_new();
1854 if (fake_info_if == NULL)
1857 /* Number of keys in key list */
1858 if (fake_info_if->keysCollectionSize != 0)
1859 keys_in_list = AirpcapKeysCollectionSizeToKeyCount(fake_info_if->keysCollectionSize);
1863 for(i=0; i<keys_in_list; i++)
1865 /* Different things to do depending on the key type */
1866 if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WEP)
1868 /* allocate memory for the new key item */
1869 new_key = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1871 /* fill the fields */
1873 tmp_key = airpcap_get_key_string(fake_info_if->keysCollection->Keys[i]);
1874 new_key->key = g_string_new(tmp_key);
1875 if (tmp_key != NULL) g_free(tmp_key);
1878 new_key->bits = (guint) new_key->key->len *4; /* every char is 4 bits in WEP keys (it is an hexadecimal number) */
1880 /* SSID not used in WEP keys */
1881 new_key->ssid = NULL;
1883 /* TYPE (WEP in this case) */
1884 new_key->type = fake_info_if->keysCollection->Keys[i].KeyType;
1886 /* Append the new element in the list */
1887 key_list = g_list_append(key_list,(gpointer)new_key);
1889 else if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PWD)
1891 /* XXX - Not supported yet */
1893 else if (fake_info_if->keysCollection->Keys[i].KeyType == AIRPDCAP_KEY_TYPE_WPA_PMK)
1895 /* XXX - Not supported yet */
1899 airpcap_if_info_free(fake_info_if);
1905 * Returns the list of the decryption keys specified for wireshark, NULL if
1909 get_wireshark_keys(void)
1911 keys_cb_data_t *wep_user_data = NULL;
1913 GList *final_list = NULL;
1914 GList *wep_final_list = NULL;
1916 /* Retrieve the wlan preferences */
1917 wlan_prefs = prefs_find_module("wlan");
1919 /* Allocate a structure used to keep infos between the callbacks */
1920 wep_user_data = (keys_cb_data_t*)g_malloc(sizeof(keys_cb_data_t));
1922 /* Fill the structure */
1923 wep_user_data->list = NULL;
1924 wep_user_data->current_index = 0;
1925 wep_user_data->number_of_keys= 0; /* Still unknown */
1927 /* Run the callback on each 802.11 preference */
1928 /* XXX - Right now, only WEP keys will be loaded */
1929 prefs_pref_foreach(wlan_prefs, get_wep_key, (gpointer)wep_user_data);
1931 /* Copy the list field in the user data structure pointer into the final_list */
1932 wep_final_list = wep_user_data->list;
1934 /* XXX - Merge the three lists!!!!! */
1935 final_list = wep_final_list;
1937 /* free the wep_user_data structure */
1938 g_free(wep_user_data);
1944 * Merges two lists of keys and return a newly created GList. If a key is
1945 * found multiple times, it will just appear once!
1946 * list1 and list 2 pointer will have to be freed manually if needed!!!
1947 * If the total number of keys exceeeds the maximum number allowed,
1948 * exceeding keys will be discarded...
1951 merge_key_list(GList* list1, GList* list2)
1955 decryption_key_t *dk1=NULL,
1959 GList* merged_list = NULL;
1961 if ( (list1 == NULL) && (list2 == NULL) )
1966 n2 = g_list_length(list2);
1970 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1971 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
1973 new_dk->bits = dk2->bits;
1974 new_dk->type = dk2->type;
1975 new_dk->key = g_string_new(dk2->key->str);
1976 new_dk->ssid = byte_array_dup(dk2->ssid);
1978 /* Check the total length of the merged list */
1979 if (g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1980 merged_list = g_list_append(merged_list,(gpointer)new_dk);
1983 else if (list2 == NULL)
1985 n1 = g_list_length(list1);
1989 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
1990 dk1 = (decryption_key_t*)g_list_nth_data(list1,i);
1992 new_dk->bits = dk1->bits;
1993 new_dk->type = dk1->type;
1994 new_dk->key = g_string_new(dk1->key->str);
1995 new_dk->ssid = byte_array_dup(dk1->ssid);
1997 /* Check the total length of the merged list */
1998 if (g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
1999 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2004 n1 = g_list_length(list1);
2005 n2 = g_list_length(list2);
2007 /* Copy the whole list1 into merged_list */
2010 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2011 dk1 = (decryption_key_t *)g_list_nth_data(list1,i);
2013 new_dk->bits = dk1->bits;
2014 new_dk->type = dk1->type;
2015 new_dk->key = g_string_new(dk1->key->str);
2016 new_dk->ssid = byte_array_dup(dk1->ssid);
2018 /* Check the total length of the merged list */
2019 if (g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2020 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2023 /* Look for keys that are present in list2 but aren't in list1 yet...
2024 * Add them to merged_list
2028 dk2 = (decryption_key_t *)g_list_nth_data(list2,i);
2030 if (!key_is_in_list(dk2,merged_list))
2032 new_dk = (decryption_key_t*)g_malloc(sizeof(decryption_key_t));
2034 new_dk->bits = dk2->bits;
2035 new_dk->type = dk2->type;
2036 new_dk->key = g_string_new(dk2->key->str);
2037 new_dk->ssid = byte_array_dup(dk2->ssid);
2039 /* Check the total length of the merged list */
2040 if (g_list_length(merged_list) < MAX_ENCRYPTION_KEYS)
2041 merged_list = g_list_append(merged_list,(gpointer)new_dk);
2050 * Use this function to free a key list.
2053 free_key_list(GList *list)
2056 decryption_key_t *curr_key;
2061 n = g_list_length(list);
2063 for(i = 0; i < n; i++)
2065 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2067 /* Free all the strings */
2068 if (curr_key->key != NULL)
2069 g_string_free(curr_key->key, TRUE);
2071 if (curr_key->ssid != NULL)
2072 g_byte_array_free(curr_key->ssid, TRUE);
2074 /* free the decryption_key_t structure*/
2087 * If the given key is contained in the list, returns TRUE.
2088 * Returns FALSE otherwise.
2091 key_is_in_list(decryption_key_t *dk,GList *list)
2094 decryption_key_t *curr_key = NULL;
2095 gboolean found = FALSE;
2097 if ( (list == NULL) || (dk == NULL) )
2100 n = g_list_length(list);
2105 for(i = 0; i < n; i++)
2107 curr_key = (decryption_key_t*)g_list_nth_data(list,i);
2108 if (keys_are_equals(dk,curr_key))
2116 * Returns TRUE if keys are equals, FALSE otherwise
2119 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2)
2122 if ((k1==NULL) || (k2==NULL))
2125 /* XXX - Remove this check when we will have the WPA/WPA2 decryption in the Driver! */
2126 /** 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) ) **/
2127 /** return TRUE; **/
2129 if (g_string_equal(k1->key,k2->key) &&
2130 (k1->bits == k2->bits) && /* If the previous is TRUE, this must be TRUE as well */
2131 (k1->type == k2->type))
2133 /* Check the ssid... if the key type is WEP, the two fields should be NULL */
2134 if ((k1->ssid == NULL) && (k2->ssid == NULL))
2137 /* If they are not null, they must share the same ssid */
2138 return byte_array_equal(k1->ssid,k2->ssid);
2141 /* Some field is not equal ... */
2146 * Tests if two collection of keys are equal or not, to be considered equals, they have to
2147 * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
2151 key_lists_are_equal(GList* list1, GList* list2)
2155 guint wep_n1 = 0,wep_n2=0;
2156 GList *wep_list1 = NULL;
2157 GList *wep_list2 = NULL;
2160 decryption_key_t *dk1=NULL,*dk2=NULL;
2162 n1 = g_list_length(list1);
2163 n2 = g_list_length(list2);
2166 * XXX - START : Retrieve the aublists of WEP keys!!! This is needed only 'till Driver WPA decryption
2171 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2172 if (dk1->type == AIRPDCAP_KEY_TYPE_WEP)
2174 wep_list1 = g_list_append(wep_list1,(gpointer)dk1);
2180 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2181 if (dk2->type == AIRPDCAP_KEY_TYPE_WEP)
2183 wep_list2 = g_list_append(wep_list2,(gpointer)dk2);
2189 * XXX - END : Remove from START to END when the WPA/WPA2 decryption will be implemented in
2194 * Commented, because in the new AirPcap version all the keys will be saved
2195 * into the driver, and all the keys for every specific adapter will be
2196 * removed. This means that this check will always fail... and the user will
2197 * always be asked what to do... and it doesn't make much sense.
2199 /* if (n1 != n2) return FALSE; */
2200 if (wep_n1 != wep_n2) return FALSE;
2206 dk1=(decryption_key_t*)g_list_nth_data(list1,i);
2207 dk2=(decryption_key_t*)g_list_nth_data(list2,i);
2209 if (!g_string_equal(dk1->key,dk2->key)) return FALSE;
2213 dk2=(decryption_key_t*)g_list_nth_data(wep_list2,i);
2214 if (!key_is_in_list(dk2,wep_list1)) return FALSE;
2221 test_if_on(pref_t *pref, gpointer ud)
2226 /* Retrieve user data info */
2227 is_on = (gboolean*)ud;
2230 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2232 number = *pref->varp.boolp;
2234 if (number) *is_on = TRUE;
2235 else *is_on = FALSE;
2243 * Returns TRUE if the Wireshark decryption is active, false otherwise
2244 * XXX - Should we just add a routine to packet-ieee80211.c to grab this directly?
2247 wireshark_decryption_on(void)
2251 /* Retrieve the wlan preferences */
2252 wlan_prefs = prefs_find_module("wlan");
2254 /* Run the callback on each 802.11 preference */
2255 prefs_pref_foreach(wlan_prefs, test_if_on, (gpointer)&is_on);
2261 * Returns TRUE if the AirPcap decryption for the current adapter is active, false otherwise
2264 airpcap_decryption_on(void)
2266 gboolean is_on = FALSE;
2268 airpcap_if_info_t* fake_if_info = NULL;
2270 fake_if_info = airpcap_driver_fake_if_info_new();
2272 if (fake_if_info != NULL)
2274 if (fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_ON)
2276 else if (fake_if_info->DecryptionOn == AIRPCAP_DECRYPTION_OFF)
2280 airpcap_if_info_free(fake_if_info);
2286 * Free an instance of airpcap_if_info_t
2289 airpcap_if_info_free(airpcap_if_info_t *if_info)
2291 if (if_info != NULL)
2293 if (if_info->name != NULL)
2294 g_free(if_info->name);
2296 if (if_info->description != NULL)
2297 g_free(if_info->description);
2299 if (if_info->keysCollection != NULL)
2301 g_free(if_info->keysCollection);
2302 if_info->keysCollection = NULL;
2305 if (if_info->ip_addr != NULL)
2307 g_slist_free(if_info->ip_addr);
2308 if_info->ip_addr = NULL;
2311 if (if_info != NULL)
2320 set_on_off(pref_t *pref, gpointer ud)
2324 /* Retrieve user data info */
2325 is_on = (gboolean*)ud;
2327 if (g_ascii_strncasecmp(pref->name, "enable_decryption", 17) == 0 && pref->type == PREF_BOOL)
2331 *pref->varp.boolp = TRUE;
2333 *pref->varp.boolp = FALSE;
2341 * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
2344 set_wireshark_decryption(gboolean on_off)
2350 /* Retrieve the wlan preferences */
2351 wlan_prefs = prefs_find_module("wlan");
2353 /* Run the callback on each 802.11 preference */
2354 prefs_pref_foreach(wlan_prefs, set_on_off, (gpointer)&is_on);
2357 * Signal that we've changed things, and run the 802.11 dissector's
2360 wlan_prefs->prefs_changed = TRUE;
2362 prefs_apply(wlan_prefs);
2366 * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
2369 set_airpcap_decryption(gboolean on_off)
2371 /* We need to directly access the .dll functions here... */
2372 gchar ebuf[AIRPCAP_ERRBUF_SIZE];
2373 PAirpcapHandle ad,ad_driver;
2375 gboolean success = TRUE;
2379 airpcap_if_info_t* curr_if = NULL;
2380 airpcap_if_info_t* fake_if_info = NULL;
2382 fake_if_info = airpcap_driver_fake_if_info_new();
2384 if (fake_if_info == NULL)
2385 /* We apparently don't have any adapters installed.
2386 * This isn't a failure, so return TRUE
2390 /* Set the driver decryption */
2391 ad_driver = airpcap_if_open(fake_if_info->name, ebuf);
2395 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_ON);
2397 airpcap_if_set_driver_decryption_state(ad_driver,AIRPCAP_DECRYPTION_OFF);
2399 airpcap_if_close(ad_driver);
2402 airpcap_if_info_free(fake_if_info);
2404 n = g_list_length(airpcap_if_list);
2406 /* Set to FALSE the decryption for all the adapters */
2407 /* Apply this change to all the adapters !!! */
2408 for(i = 0; i < n; i++)
2410 curr_if = (airpcap_if_info_t*)g_list_nth_data(airpcap_if_list,i);
2412 if (curr_if != NULL)
2414 ad = airpcap_if_open(curr_if->name, ebuf);
2417 curr_if->DecryptionOn = AIRPCAP_DECRYPTION_OFF;
2418 airpcap_if_set_decryption_state(ad,curr_if->DecryptionOn);
2419 /* Save configuration for the curr_if */
2420 if (!airpcap_if_store_cur_config_as_adapter_default(ad))
2424 airpcap_if_close(ad);
2433 /* DYNAMIC LIBRARY LOADER */
2435 * Used to dynamically load the airpcap library in order link it only when
2436 * it's present on the system
2438 int load_airpcap(void)
2441 gboolean base_functions = TRUE;
2442 gboolean eleven_n_functions = TRUE;
2444 if ((AirpcapLib = ws_load_library("airpcap.dll")) == NULL)
2446 /* Report the error but go on */
2447 AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
2448 return AirpcapVersion;
2452 if ((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
2453 if ((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
2454 if ((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
2455 if ((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
2456 if ((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
2457 if ((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
2458 if ((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
2459 if ((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
2460 if ((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
2461 if ((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
2462 if ((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
2463 if ((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
2464 if ((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
2465 if ((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
2466 if ((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
2467 if ((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
2468 if ((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
2469 if ((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
2470 if ((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
2471 if ((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
2472 if ((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
2473 if ((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
2474 if ((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
2475 if ((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
2476 if ((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
2477 if ((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
2478 if ((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
2479 if ((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
2480 if ((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
2481 if ((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
2482 if ((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
2483 if ((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
2485 /* TEST IF AIRPCAP SUPPORTS 11N */
2486 if ((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2487 if ((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
2488 if ((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
2490 if (base_functions && eleven_n_functions){
2491 AirpcapLoaded = TRUE;
2492 AirpcapVersion = AIRPCAP_DLL_OK;
2493 } else if (base_functions){
2494 AirpcapLoaded = TRUE;
2495 AirpcapVersion = AIRPCAP_DLL_OLD;
2496 return AIRPCAP_DLL_OK;
2498 AirpcapLoaded = FALSE;
2499 AirpcapVersion = AIRPCAP_DLL_ERROR;
2502 return AirpcapVersion;
2504 return AIRPCAP_DLL_NOT_FOUND;
2509 * Append the version of AirPcap with which we were compiled to a GString.
2512 get_compiled_airpcap_version(GString *str)
2514 g_string_append(str, "with AirPcap");
2518 * Append the version of AirPcap with which we we're running to a GString.
2521 get_runtime_airpcap_version(GString *str)
2523 guint vmaj, vmin, vrev, build;
2525 /* See if the DLL has been loaded successfully. Bail if it hasn't */
2526 if (AirpcapLoaded == FALSE) {
2527 g_string_append(str, "without AirPcap");
2531 g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
2532 g_string_append_printf(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
2535 #endif /* HAVE_AIRPCAP */