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