98e4699b836f4d52342d79711460a82df9c8b7cb
[metze/wireshark/wip.git] / caputils / airpcap_loader.c
1 /* airpcap_loader.c
2  *
3  * Giorgio Tino <giorgio.tino@cacetech.com>
4  * Copyright (c) CACE Technologies, LLC 2006
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 2000 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include "config.h"
26
27 #ifdef HAVE_LIBPCAP
28 #include <glib.h>
29 #include <gmodule.h>
30
31
32 #include <wtap.h>
33 #include <pcap.h>
34 #endif
35
36 #include <epan/crypt/airpdcap_ws.h>
37 #include <epan/strutil.h>
38 #include <wsutil/file_util.h>
39 #include <wsutil/frequency-utils.h>
40
41 #include <caputils/airpcap.h>
42 #include <caputils/airpcap_loader.h>
43
44
45 /*
46  * Set to TRUE if the DLL was successfully loaded AND all functions
47  * are present.
48  */
49 static gboolean AirpcapLoaded = FALSE;
50
51 #ifdef _WIN32
52 /*
53  * We load dynamically the dag library in order link it only when
54  * it's present on the system
55  */
56 static void * AirpcapLib = NULL;
57
58 static AirpcapGetLastErrorHandler g_PAirpcapGetLastError;
59 static AirpcapSetKernelBufferHandler g_PAirpcapSetKernelBuffer;
60 static AirpcapSetFilterHandler g_PAirpcapSetFilter;
61 static AirpcapGetMacAddressHandler g_PAirpcapGetMacAddress;
62 static AirpcapSetMinToCopyHandler g_PAirpcapSetMinToCopy;
63 static AirpcapGetReadEventHandler g_PAirpcapGetReadEvent;
64 static AirpcapReadHandler g_PAirpcapRead;
65 static AirpcapGetStatsHandler g_PAirpcapGetStats;
66 #endif
67
68 static int AirpcapVersion = 3;
69
70 static AirpcapGetDeviceListHandler g_PAirpcapGetDeviceList;
71 static AirpcapFreeDeviceListHandler g_PAirpcapFreeDeviceList;
72 static AirpcapOpenHandler g_PAirpcapOpen;
73 static AirpcapCloseHandler g_PAirpcapClose;
74 static AirpcapGetLinkTypeHandler g_PAirpcapGetLinkType;
75 static AirpcapSetLinkTypeHandler g_PAirpcapSetLinkType;
76 static AirpcapTurnLedOnHandler g_PAirpcapTurnLedOn;
77 static AirpcapTurnLedOffHandler g_PAirpcapTurnLedOff;
78 static AirpcapGetDeviceChannelHandler g_PAirpcapGetDeviceChannel;
79 static AirpcapSetDeviceChannelHandler g_PAirpcapSetDeviceChannel;
80 static AirpcapGetFcsPresenceHandler g_PAirpcapGetFcsPresence;
81 static AirpcapSetFcsPresenceHandler g_PAirpcapSetFcsPresence;
82 static AirpcapGetFcsValidationHandler g_PAirpcapGetFcsValidation;
83 static AirpcapSetFcsValidationHandler g_PAirpcapSetFcsValidation;
84 static AirpcapGetDeviceKeysHandler g_PAirpcapGetDeviceKeys;
85 static AirpcapSetDeviceKeysHandler g_PAirpcapSetDeviceKeys;
86 static AirpcapGetDriverKeysHandler g_PAirpcapGetDriverKeys;
87 static AirpcapSetDriverKeysHandler g_PAirpcapSetDriverKeys;
88 static AirpcapGetDecryptionStateHandler g_PAirpcapGetDecryptionState;
89 static AirpcapSetDecryptionStateHandler g_PAirpcapSetDecryptionState;
90 static AirpcapGetDriverDecryptionStateHandler g_PAirpcapGetDriverDecryptionState;
91 static AirpcapSetDriverDecryptionStateHandler g_PAirpcapSetDriverDecryptionState;
92 static AirpcapStoreCurConfigAsAdapterDefaultHandler g_PAirpcapStoreCurConfigAsAdapterDefault;
93 static AirpcapGetVersionHandler g_PAirpcapGetVersion;
94 static AirpcapSetDeviceChannelExHandler g_PAirpcapSetDeviceChannelEx;
95 static AirpcapGetDeviceChannelExHandler g_PAirpcapGetDeviceChannelEx;
96 static AirpcapGetDeviceSupportedChannelsHandler g_PAirpcapGetDeviceSupportedChannels;
97
98 /* Airpcap interface list */
99 GList *g_airpcap_if_list = NULL;
100
101 /* Airpcap current selected interface */
102 airpcap_if_info_t *airpcap_if_selected = NULL;
103
104 /* Airpcap current active interface */
105 airpcap_if_info_t *airpcap_if_active = NULL;
106
107 Dot11Channel *pSupportedChannels;
108 guint numSupportedChannels;
109
110 static AirpcapChannelInfo LegacyChannels[] =
111 {
112     {2412, 0, {0,0,0}},
113     {2417, 0, {0,0,0}},
114     {2422, 0, {0,0,0}},
115     {2427, 0, {0,0,0}},
116     {2432, 0, {0,0,0}},
117     {2437, 0, {0,0,0}},
118     {2442, 0, {0,0,0}},
119     {2447, 0, {0,0,0}},
120     {2452, 0, {0,0,0}},
121     {2457, 0, {0,0,0}},
122     {2462, 0, {0,0,0}},
123     {2467, 0, {0,0,0}},
124     {2472, 0, {0,0,0}},
125     {2484, 0, {0,0,0}},
126 };
127
128 static guint num_legacy_channels = 14;
129
130 /*
131  * Get an error message string for a CANT_GET_INTERFACE_LIST error from
132  * "get_airpcap_interface_list()".
133  */
134 static gchar *
135 cant_get_airpcap_if_list_error_message(const char *err_str)
136 {
137     return g_strdup_printf("Can't get list of Wireless interfaces: %s", err_str);
138 }
139
140 /*
141  * Airpcap wrapper, used to store the current settings for the selected adapter
142  */
143 gboolean
144 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah)
145 {
146     if (!AirpcapLoaded) return FALSE;
147     return g_PAirpcapStoreCurConfigAsAdapterDefault(ah);
148 }
149
150 /*
151  * Airpcap wrapper, used to open an airpcap adapter
152  */
153 PAirpcapHandle
154 airpcap_if_open(gchar * name, gchar * err)
155 {
156     if (!AirpcapLoaded) return NULL;
157     if (name == NULL) return NULL;
158     return g_PAirpcapOpen(name,err);
159 }
160
161 /*
162  * Airpcap wrapper, used to close an airpcap adapter
163  */
164 void
165 airpcap_if_close(PAirpcapHandle handle)
166 {
167     if (!AirpcapLoaded) return;
168     g_PAirpcapClose(handle);
169 }
170
171 /*
172  * Retrieve the state of the Airpcap DLL
173  */
174 int
175 airpcap_get_dll_state(void)
176 {
177     return AirpcapVersion;
178 }
179
180 /*
181  * Airpcap wrapper, used to turn on the led of an airpcap adapter
182  */
183 gboolean
184 airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber)
185 {
186     if (!AirpcapLoaded) return FALSE;
187     return g_PAirpcapTurnLedOn(AdapterHandle,LedNumber);
188 }
189
190 /*
191  * Airpcap wrapper, used to turn off the led of an airpcap adapter
192  */
193 gboolean
194 airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber)
195 {
196     if (!AirpcapLoaded) return FALSE;
197     return g_PAirpcapTurnLedOff(AdapterHandle,LedNumber);
198 }
199
200 /*
201  * Airpcap wrapper, used to get the channel of an airpcap adapter
202  */
203 gboolean
204 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch)
205 {
206     if (!AirpcapLoaded) return FALSE;
207     return g_PAirpcapGetDeviceChannel(ah,ch);
208 }
209
210 /*
211  * Airpcap wrapper, used to get the supported channels of an airpcap adapter
212  */
213 gboolean
214 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint * nInfo)
215 {
216     if (!AirpcapLoaded) return FALSE;
217     if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD) {
218         *nInfo = num_legacy_channels;
219         *cInfo = (AirpcapChannelInfo*)&LegacyChannels;
220
221         return TRUE;
222     } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK) {
223         return g_PAirpcapGetDeviceSupportedChannels(ah, cInfo, nInfo);
224     }
225     return FALSE;
226 }
227
228 /*
229  * Airpcap wrapper, used to get the supported channels of an airpcap adapter
230  */
231 Dot11Channel*
232 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint * pNumSupportedChannels)
233 {
234     AirpcapChannelInfo *chanInfo;
235     guint i=0, j=0, numInfo = 0;
236
237     if (!AirpcapLoaded)
238         return NULL;
239     if (airpcap_if_get_device_supported_channels(ah, &chanInfo, &numInfo) == FALSE)
240         return NULL;
241     numSupportedChannels = 0;
242
243     /*
244      * allocate a bigger array
245      */
246     if (numInfo == 0)
247         return NULL;
248
249     pSupportedChannels = (Dot11Channel *)g_malloc(numInfo * (sizeof *pSupportedChannels));
250
251     for (i = 0; i < numInfo; i++)
252     {
253         guint supportedChannel = G_MAXUINT;
254
255         /*
256          * search if we have it already
257          */
258         for (j = 0; j < numSupportedChannels; j++)
259         {
260             if (pSupportedChannels[j].Frequency == chanInfo[i].Frequency)
261             {
262                 supportedChannel = j;
263                 break;
264             }
265         }
266
267         if (supportedChannel == G_MAXUINT)
268         {
269             /*
270              * not found, create a new item
271              */
272             pSupportedChannels[numSupportedChannels].Frequency = chanInfo[i].Frequency;
273
274             switch(chanInfo[i].ExtChannel)
275             {
276                 case -1:
277                     pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_LOW;
278                     break;
279                 case +1:
280                     pSupportedChannels[numSupportedChannels].Flags = FLAG_CAN_BE_HIGH;
281                     break;
282                 case 0:
283                 default:
284                     pSupportedChannels[numSupportedChannels].Flags = 0;
285             }
286
287             /*
288              * Gather channel information
289              */
290
291             pSupportedChannels[numSupportedChannels].Flags |=
292                 FREQ_IS_BG(pSupportedChannels[numSupportedChannels].Frequency) ?
293                     FLAG_IS_BG_CHANNEL : FLAG_IS_A_CHANNEL;
294             pSupportedChannels[numSupportedChannels].Channel =
295                 ieee80211_mhz_to_chan(pSupportedChannels[numSupportedChannels].Frequency);
296             numSupportedChannels++;
297         }
298         else
299         {
300             /*
301              * just update the ext channel flags
302              */
303             switch(chanInfo[i].ExtChannel)
304             {
305                 case -1:
306                     pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_LOW;
307                     break;
308                 case +1:
309                     pSupportedChannels[supportedChannel].Flags |= FLAG_CAN_BE_HIGH;
310                     break;
311                 case 0:
312                 default:
313                     break;
314             }
315         }
316     }
317
318     if (numSupportedChannels < 1)
319         return NULL;
320     /*
321      * Now sort the list by frequency
322      */
323     for (i = 0 ; i < numSupportedChannels - 1; i++)
324     {
325         for (j = i + 1; j < numSupportedChannels; j++)
326         {
327             if (pSupportedChannels[i].Frequency > pSupportedChannels[j].Frequency)
328             {
329                 Dot11Channel temp = pSupportedChannels[i];
330                 pSupportedChannels[i] = pSupportedChannels[j];
331                 pSupportedChannels[j] = temp;
332             }
333         }
334     }
335
336     *pNumSupportedChannels = numSupportedChannels;
337     return pSupportedChannels;
338 }
339
340 /*
341  * Airpcap wrapper, used to set the channel of an airpcap adapter
342  */
343 gboolean
344 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch)
345 {
346     if (!AirpcapLoaded) return FALSE;
347     return g_PAirpcapSetDeviceChannel(ah,ch);
348 }
349
350 /*
351  * Airpcap wrapper, used to set the frequency of an airpcap adapter
352  */
353 gboolean
354 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo)
355 {
356     if (!AirpcapLoaded) return FALSE;
357     if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
358         gint channel = 0;
359         channel = ieee80211_mhz_to_chan(ChannelInfo.Frequency);
360
361         if (channel < 0){
362             return FALSE;
363         } else {
364             return airpcap_if_set_device_channel(ah, channel);
365         }
366     } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
367         return g_PAirpcapSetDeviceChannelEx (ah, ChannelInfo);
368     }
369
370     return FALSE;
371 }
372
373 /*
374  * Airpcap wrapper, used to get the frequency of an airpcap adapter
375  */
376 gboolean
377 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo)
378 {
379     if (!AirpcapLoaded) return FALSE;
380
381     pChannelInfo->Frequency = 0;
382     pChannelInfo->ExtChannel = 0;
383     pChannelInfo->Reserved[0] = 0;
384     pChannelInfo->Reserved[1] = 0;
385     pChannelInfo->Reserved[2] = 0;
386
387     if (airpcap_get_dll_state() == AIRPCAP_DLL_OLD){
388         guint channel = 0;
389         guint chan_freq = 0;
390
391         if (!airpcap_if_get_device_channel(ah, &channel)) return FALSE;
392
393         chan_freq = ieee80211_chan_to_mhz(channel, TRUE);
394         if (chan_freq == 0) return FALSE;
395         pChannelInfo->Frequency = chan_freq;
396
397         return TRUE;
398     } else if (airpcap_get_dll_state() == AIRPCAP_DLL_OK){
399         return g_PAirpcapGetDeviceChannelEx (ah, pChannelInfo);
400     }
401     return FALSE;
402 }
403
404 /*
405  * Airpcap wrapper, used to get the link type of an airpcap adapter
406  */
407 gboolean
408 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt)
409 {
410     if (!AirpcapLoaded) return FALSE;
411     return g_PAirpcapGetLinkType(ah,lt);
412 }
413
414 /*
415  * Airpcap wrapper, used to set the link type of an airpcap adapter
416  */
417 gboolean
418 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt)
419 {
420     if (!AirpcapLoaded) return FALSE;
421     return g_PAirpcapSetLinkType(ah,lt);
422 }
423
424 /*
425  * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
426  */
427 gboolean
428 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * fcs)
429 {
430     if (!AirpcapLoaded) return FALSE;
431     return g_PAirpcapGetFcsPresence(ah,fcs);
432 }
433
434 /*
435  * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
436  */
437 gboolean
438 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean fcs)
439 {
440     if (!AirpcapLoaded) return FALSE;
441     return g_PAirpcapSetFcsPresence(ah,fcs);
442 }
443
444 /*
445  * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
446  */
447 gboolean
448 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
449 {
450     if (!AirpcapLoaded) return FALSE;
451     return g_PAirpcapGetDecryptionState(ah,PEnable);
452 }
453
454 /*
455  * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
456  */
457 gboolean
458 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
459 {
460     if (!AirpcapLoaded) return FALSE;
461     return g_PAirpcapSetDecryptionState(ah,Enable);
462 }
463
464 /*
465  * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
466  */
467 gboolean
468 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable)
469 {
470     if (!AirpcapLoaded || (g_PAirpcapGetDriverDecryptionState==NULL)) return FALSE;
471     return g_PAirpcapGetDriverDecryptionState(ah,PEnable);
472 }
473
474 /*
475  * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
476  */
477 gboolean
478 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable)
479 {
480     if (!AirpcapLoaded || (g_PAirpcapSetDriverDecryptionState==NULL)) return FALSE;
481     return g_PAirpcapSetDriverDecryptionState(ah,Enable);
482 }
483
484 /*
485  * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
486  */
487 gboolean
488 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val)
489 {
490     if (!AirpcapLoaded) return FALSE;
491     return g_PAirpcapGetFcsValidation(ah,val);
492 }
493
494 /*
495  * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
496  */
497 gboolean
498 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val)
499 {
500     if (!AirpcapLoaded) return FALSE;
501     return g_PAirpcapSetFcsValidation(ah,val);
502 }
503
504 /*
505  * Airpcap wrapper, used to save the settings for the selected_if
506  */
507 gboolean
508 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
509 {
510     if (!AirpcapLoaded) return FALSE;
511     return g_PAirpcapSetDeviceKeys(AdapterHandle,KeysCollection);
512 }
513
514 /*
515  * Airpcap wrapper, used to save the settings for the selected_if
516  */
517 gboolean
518 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
519 {
520     if (!AirpcapLoaded) return FALSE;
521     return g_PAirpcapGetDeviceKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
522 }
523
524 /*
525  * Airpcap wrapper, used to save the driver's set of keys
526  */
527 gboolean
528 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection)
529 {
530     if (!AirpcapLoaded || (g_PAirpcapSetDriverKeys==NULL)) return FALSE;
531     return g_PAirpcapSetDriverKeys(AdapterHandle,KeysCollection);
532 }
533
534 /*
535  * Airpcap wrapper, used to load the driver's set of keys
536  */
537 gboolean
538 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize)
539 {
540     if (!AirpcapLoaded || (g_PAirpcapGetDriverKeys==NULL)) return FALSE;
541     return g_PAirpcapGetDriverKeys(AdapterHandle,KeysCollection,PKeysCollectionSize);
542 }
543
544 /*
545  * This function will create a new airpcap_if_info_t using a name and a description
546  */
547 airpcap_if_info_t *
548 airpcap_if_info_new(char *name, char *description)
549 {
550     PAirpcapHandle ad;
551     gchar ebuf[AIRPCAP_ERRBUF_SIZE];
552
553     airpcap_if_info_t *if_info = NULL;
554
555     /* Probably I have to switch on the leds!!! */
556     ad = airpcap_if_open(name, ebuf);
557     if (ad)
558     {
559         if_info = (airpcap_if_info_t *)g_malloc0(sizeof (airpcap_if_info_t));
560         if_info->name = g_strdup(name);
561         if (description == NULL){
562             if_info->description = NULL;
563         }else{
564             if_info->description = g_strdup(description);
565         }
566
567         if_info->ip_addr = NULL;
568         if_info->loopback = FALSE;
569         airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
570         airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
571         airpcap_if_get_link_type(ad,&(if_info->linkType));
572         airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
573         if_info->pSupportedChannels = airpcap_if_get_device_supported_channels_array(ad, &(if_info->numSupportedChannels));
574         airpcap_if_turn_led_on(ad, 0);
575         airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
576         if_info->led = TRUE;
577         if_info->blinking = FALSE;
578         if_info->saved = TRUE; /* NO NEED TO BE SAVED */
579
580         /* get the keys, if everything is ok, close the adapter */
581         if (airpcap_if_load_keys(ad,if_info))
582         {
583             airpcap_if_close(ad);
584         }
585     }
586     return if_info;
587 }
588
589 /*
590  * This function will create a new fake drivers' interface, to load global keys...
591  */
592 airpcap_if_info_t*
593 airpcap_driver_fake_if_info_new(void)
594 {
595     PAirpcapHandle ad;
596     gchar ebuf[AIRPCAP_ERRBUF_SIZE];
597
598     airpcap_if_info_t *if_info = NULL;
599     airpcap_if_info_t *fake_if_info = NULL;
600
601     /* Maybe for some reason no airpcap adapter is found */
602     if (g_airpcap_if_list == NULL)
603         return NULL;
604
605     /*
606      * Retrieve the first AirPcap adapter available. If no interface is found,
607      * it is not possible to retrieve the driver's settings, so return NULL.
608      */
609     if_info = (airpcap_if_info_t *)g_list_nth_data(g_airpcap_if_list,0);
610     if (if_info == NULL)
611         return NULL;
612
613     /* Open the 'fake' adapter */
614     ad = airpcap_if_open(if_info->name, ebuf);
615     if (ad)
616     {
617         fake_if_info = (airpcap_if_info_t *)g_malloc(sizeof (airpcap_if_info_t));
618         fake_if_info->name = g_strdup(if_info->name);
619         fake_if_info->description = g_strdup(if_info->description);
620         fake_if_info->loopback = FALSE;
621         fake_if_info->ip_addr = NULL;
622         airpcap_if_get_driver_decryption_state(ad, &(fake_if_info->DecryptionOn));
623         airpcap_if_get_fcs_validation(ad,&(fake_if_info->CrcValidationOn));
624         airpcap_if_get_fcs_presence(ad,&(fake_if_info->IsFcsPresent));
625         airpcap_if_get_link_type(ad,&(fake_if_info->linkType));
626         airpcap_if_get_device_channel_ex(ad,&(fake_if_info->channelInfo));
627         airpcap_if_turn_led_on(ad, 0);
628         fake_if_info->led = TRUE;
629         fake_if_info->blinking = FALSE;
630         fake_if_info->saved = TRUE; /* NO NEED TO BE SAVED */
631
632         /* get the keys, if everything is ok, close the adapter */
633         if (airpcap_if_load_driver_keys(ad,fake_if_info))
634         {
635             airpcap_if_close(ad);
636         }
637     }
638
639     return fake_if_info;
640 }
641
642 #ifdef AIRPCAP_DEBUG
643 /*
644  * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
645  */
646 void
647 airpcap_if_info_print(airpcap_if_info_t* if_info)
648 {
649     guint i;
650     if (if_info == NULL)
651     {
652         g_print("\nWARNING : AirPcap Interface pointer is NULL!\n");
653         return;
654     }
655
656     g_print("\n----------------- AirPcap Interface \n");
657     g_print("                      NAME: %s\n",if_info->name);
658     g_print("               DESCRIPTION: %s\n",if_info->description);
659     g_print("                  BLINKING: %s\n",if_info->blinking ? "TRUE" : "FALSE");
660     g_print("     channelInfo.Frequency: %u\n",if_info->channelInfo.Frequency);
661     g_print("    channelInfo.ExtChannel: %d\n",if_info->channelInfo.ExtChannel);
662     g_print("             CRCVALIDATION: %s\n",if_info->CrcValidationOn ? "ON" : "OFF");
663     g_print("                DECRYPTION: %s\n",if_info->DecryptionOn ? "ON" : "OFF");
664     g_print("                   IP ADDR: %s\n",if_info->ip_addr!=NULL ? "NOT NULL" : "NULL");
665     g_print("                FCSPRESENT: %s\n",if_info->IsFcsPresent ? "TRUE" : "FALSE");
666     g_print("            KEYSCOLLECTION: %s\n",if_info->keysCollection!=NULL ? "NOT NULL" : "NULL");
667     g_print("        KEYSCOLLECTIONSIZE: %u\n",if_info->keysCollectionSize);
668     g_print("                       LED: %s\n",if_info->led ? "ON" : "OFF");
669     g_print("                  LINKTYPE: %d\n",if_info->linkType);
670     g_print("                  LOOPBACK: %s\n",if_info->loopback ? "YES" : "NO");
671     g_print("                 (GTK) TAG: %d\n",if_info->tag);
672     g_print("SUPPORTED CHANNELS POINTER: %p\n",if_info->pSupportedChannels);
673     g_print("    NUM SUPPORTED CHANNELS: %u\n",if_info->numSupportedChannels);
674
675     for(i=0; i<(if_info->numSupportedChannels); i++){
676         g_print("\n        SUPPORTED CHANNEL #%u\n",i+1);
677         g_print("                   CHANNEL: %u\n",if_info->pSupportedChannels[i].Channel);
678         g_print("                 FREQUENCY: %u\n",if_info->pSupportedChannels[i].Frequency);
679         g_print("                     FLAGS: %u\n",if_info->pSupportedChannels[i].Flags);
680     }
681     g_print("\n\n");
682 }
683 #endif /* AIRPCAP_DEBUG */
684
685 /*
686  * Function used to load the WEP keys for a selected interface
687  */
688 gboolean
689 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
690 {
691     if (!if_info) return FALSE;
692
693     if_info->keysCollectionSize = 0;
694     if_info->keysCollection = NULL;
695
696     if (!airpcap_if_get_device_keys(ad, NULL, &(if_info->keysCollectionSize)))
697     {
698         if (if_info->keysCollectionSize == 0)
699         {
700             if_info->keysCollection = NULL;
701             airpcap_if_close(ad);
702             return FALSE;
703         }
704
705         if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
706         if (!if_info->keysCollection)
707         {
708             if_info->keysCollectionSize = 0;
709             if_info->keysCollection = NULL;
710             airpcap_if_close(ad);
711             return FALSE;
712         }
713
714         airpcap_if_get_device_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
715         return TRUE;
716     }
717
718     airpcap_if_close(ad);
719     return FALSE;
720 }
721
722 /*
723  * Function used to load the WEP keys for a selected interface
724  */
725 gboolean
726 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
727 {
728     if_info->keysCollectionSize = 0;
729     if_info->keysCollection = NULL;
730
731     if (!airpcap_if_get_driver_keys(ad, NULL, &(if_info->keysCollectionSize)))
732     {
733         if (if_info->keysCollectionSize == 0)
734         {
735             if_info->keysCollection = NULL;
736             airpcap_if_close(ad);
737             return FALSE;
738         }
739
740         if_info->keysCollection = (PAirpcapKeysCollection)g_malloc(if_info->keysCollectionSize);
741         if (!if_info->keysCollection)
742         {
743             if_info->keysCollectionSize = 0;
744             if_info->keysCollection = NULL;
745             airpcap_if_close(ad);
746             return FALSE;
747         }
748
749         airpcap_if_get_driver_keys(ad, if_info->keysCollection, &(if_info->keysCollectionSize));
750         return TRUE;
751     }
752
753     airpcap_if_close(ad);
754     return FALSE;
755 }
756
757 /*
758  * Function used to save the WEP keys for a selected interface
759  */
760 void
761 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
762 {
763     if (!if_info || !AirpcapLoaded) return;
764
765     if (if_info->keysCollection != NULL)
766         g_PAirpcapSetDeviceKeys(ad,if_info->keysCollection);
767 }
768
769 /*
770  * Function used to save the WEP keys for a selected interface
771  */
772 void
773 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info)
774 {
775     if (if_info->keysCollection != NULL)
776         airpcap_if_set_driver_keys(ad,if_info->keysCollection);
777 }
778
779 /*
780  * Callback used to free an instance of airpcap_if_info_t
781  */
782 static void
783 free_airpcap_if_cb(gpointer data, gpointer user_data _U_)
784 {
785     airpcap_if_info_t *if_info = (airpcap_if_info_t *)data;
786
787     if (NULL == if_info)
788         return;
789
790     if (if_info->name != NULL)
791         g_free(if_info->name);
792
793     if (if_info->description != NULL)
794         g_free(if_info->description);
795
796     /* XXX - FREE THE WEP KEY LIST HERE!!!*/
797     if (if_info->keysCollection != NULL)
798     {
799         g_free(if_info->keysCollection);
800         if_info->keysCollection = NULL;
801     }
802
803     if (if_info->ip_addr != NULL)
804         g_slist_free(if_info->ip_addr);
805
806     g_free(if_info);
807 }
808
809 /*
810  * Function used to free the airpcap interface list
811  */
812 void
813 free_airpcap_interface_list(GList *if_list)
814 {
815     g_list_foreach(if_list, free_airpcap_if_cb, NULL);
816     g_list_free(if_list);
817 }
818
819 /*
820  * This function will use the airpcap.dll to find all the airpcap devices.
821  * Will return null if no device is found.
822  */
823 GList*
824 get_airpcap_interface_list(int *err, char **err_str)
825 {
826     GList  *il = NULL;
827     airpcap_if_info_t *if_info;
828     int n_adapts;
829     AirpcapDeviceDescription *devsList, *adListEntry;
830     char errbuf[AIRPCAP_ERRBUF_SIZE];
831
832     *err = 0;
833
834     if (!AirpcapLoaded)
835     {
836         *err = AIRPCAP_NOT_LOADED;
837         return il;
838     }
839
840     if (!g_PAirpcapGetDeviceList(&devsList, errbuf))
841     {
842         /* No interfaces, return il = NULL; */
843         *err = CANT_GET_AIRPCAP_INTERFACE_LIST;
844         if (err_str != NULL)
845             *err_str = cant_get_airpcap_if_list_error_message(errbuf);
846         return il;
847     }
848
849     /*
850      * Count the adapters
851      */
852     adListEntry = devsList;
853     n_adapts = 0;
854     while(adListEntry)
855     {
856         n_adapts++;
857         adListEntry = adListEntry->next;
858     }
859
860     if (n_adapts == 0)
861     {
862         /* No interfaces, return il= NULL */
863         g_PAirpcapFreeDeviceList(devsList);
864         *err = NO_AIRPCAP_INTERFACES_FOUND;
865         if (err_str != NULL)
866             *err_str = NULL;
867         return il;
868     }
869
870     /*
871      * Insert the adapters in our list
872      */
873     adListEntry = devsList;
874     while(adListEntry)
875     {
876         if_info = airpcap_if_info_new(adListEntry->Name, adListEntry->Description);
877         if (if_info != NULL){
878             il = g_list_append(il, if_info);
879         }
880
881         adListEntry = adListEntry->next;
882     }
883
884     g_PAirpcapFreeDeviceList(devsList);
885
886     return il;
887 }
888
889 /*
890  * Used to retrieve the interface given the name
891  * (the name is used in AirpcapOpen)
892  */
893 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name)
894 {
895     GList* curr;
896     airpcap_if_info_t* if_info;
897
898     for (curr = g_list_first(if_list); curr; curr = g_list_next(curr)) {
899         if_info = (airpcap_if_info_t *)curr->data;
900         if (if_info && (g_ascii_strcasecmp(if_info->name, name) == 0)) {
901             return (if_info);
902         }
903         /* Try the name without the "\\.\" prefix. */
904         if (strlen(if_info->name) > 4 && (g_ascii_strcasecmp(if_info->name + 4, name) == 0)) {
905             return (if_info);
906         }
907     }
908     return (NULL);
909 }
910
911 /*
912  * Clear keys and decryption status for the specified interface
913  */
914 void
915 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if)
916 {
917     if (info_if != NULL)
918     {
919         if (info_if->keysCollection != NULL)
920         {
921             g_free(info_if->keysCollection);
922             info_if->keysCollection = NULL;
923         }
924
925         info_if->keysCollectionSize = 0;
926
927         info_if->DecryptionOn = AIRPCAP_DECRYPTION_OFF;
928         info_if->saved = FALSE;
929     }
930 }
931
932 /*
933  * Used to retrieve the two chars string from interface
934  */
935 gchar*
936 airpcap_get_if_string_number(airpcap_if_info_t* if_info)
937 {
938     gchar* number;
939     guint n;
940     int a;
941
942     a = sscanf(if_info->name,AIRPCAP_DEVICE_NUMBER_EXTRACT_STRING,&n);
943
944     /* If sscanf() returned 1, it means that has read a number, so interface is not "Any"
945      * Otherwise, check if it is the "Any" adapter...
946      */
947     if (a == 0)
948     {
949         if (g_ascii_strcasecmp(if_info->name,AIRPCAP_DEVICE_ANY_EXTRACT_STRING)!=0)
950             number = g_strdup_printf("??");
951         else
952             number = g_strdup_printf(AIRPCAP_CHANNEL_ANY_NAME);
953     }
954     else
955     {
956         number = g_strdup_printf("%.2u",n);
957     }
958
959     return number;
960 }
961
962 /*
963  * Used to retrieve the two chars string from interface
964  */
965 gchar*
966 airpcap_get_if_string_number_from_description(gchar* description)
967 {
968     gchar* number;
969     gchar* pointer;
970
971     number = (gchar*)g_malloc(sizeof(gchar)*3);
972
973     pointer = g_strrstr(description,"#\0");
974
975     number[0] = *(pointer+1);
976     number[1] = *(pointer+2);
977     number[2] = '\0';
978
979     return number;
980 }
981
982 /*
983  * Load the configuration for the specified interface
984  */
985 void
986 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info)
987 {
988     gchar ebuf[AIRPCAP_ERRBUF_SIZE];
989     PAirpcapHandle ad;
990
991     if (if_info != NULL)
992     {
993         ad = airpcap_if_open(if_info->name, ebuf);
994
995         if (ad)
996         {
997             /* Stop blinking (if it was blinking!)*/
998             if (if_info->blinking)
999             {
1000                 /* Turn on the light (if it was off) */
1001                 if (!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1002             }
1003
1004             /* Apply settings... */
1005             airpcap_if_get_device_channel_ex(ad,&(if_info->channelInfo));
1006             airpcap_if_get_fcs_validation(ad,&(if_info->CrcValidationOn));
1007             airpcap_if_get_fcs_presence(ad,&(if_info->IsFcsPresent));
1008             airpcap_if_get_link_type(ad,&(if_info->linkType));
1009             airpcap_if_get_decryption_state(ad, &(if_info->DecryptionOn));
1010             /* get the keys, if everything is ok, close the adapter */
1011             if (airpcap_if_load_keys(ad,if_info))
1012                 airpcap_if_close(ad);
1013
1014             if_info->saved = TRUE;
1015         }
1016 #if 0
1017         else
1018         {
1019             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1020         }
1021 #endif
1022     }
1023 }
1024
1025 /*
1026  * Save the configuration for the specified interface
1027  */
1028 void
1029 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info)
1030 {
1031     gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1032     PAirpcapHandle ad;
1033
1034     if (if_info != NULL)
1035     {
1036         ad = airpcap_if_open(if_info->name, ebuf);
1037
1038         if (ad)
1039         {
1040             /* Stop blinking (if it was blinking!)*/
1041             if (if_info->blinking)
1042             {
1043                 /* Turn on the light (if it was off) */
1044                 if (!(if_info->led)) airpcap_if_turn_led_on(ad, 0);
1045             }
1046
1047             /* Apply settings... */
1048             airpcap_if_set_device_channel_ex(ad,if_info->channelInfo);
1049             airpcap_if_set_fcs_validation(ad,if_info->CrcValidationOn);
1050             airpcap_if_set_fcs_presence(ad,if_info->IsFcsPresent);
1051             airpcap_if_set_link_type(ad,if_info->linkType);
1052             airpcap_if_set_decryption_state(ad, if_info->DecryptionOn);
1053             airpcap_if_save_keys(ad,if_info);
1054
1055             /* ... and save them */
1056             if (!airpcap_if_store_cur_config_as_adapter_default(ad))
1057             {
1058 #if 0
1059                 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.");
1060 #endif
1061                 if_info->saved = FALSE;
1062                 airpcap_if_close(ad);
1063                 return;
1064             }
1065
1066             if_info->saved = TRUE;
1067             airpcap_if_close(ad);
1068         }
1069 #if 0
1070         else
1071         {
1072             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",if_info->description);
1073         }
1074 #endif
1075     }
1076 }
1077
1078 /*
1079  * Save the configuration for the specified interface
1080  */
1081 void
1082 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info)
1083 {
1084     gchar ebuf[AIRPCAP_ERRBUF_SIZE];
1085     PAirpcapHandle ad;
1086
1087     if (fake_if_info != NULL)
1088     {
1089         ad = airpcap_if_open(fake_if_info->name, ebuf);
1090
1091         if (ad)
1092         {
1093             /* Apply decryption settings... */
1094             airpcap_if_set_driver_decryption_state(ad, fake_if_info->DecryptionOn);
1095             airpcap_if_save_driver_keys(ad,fake_if_info);
1096             airpcap_if_close(ad);
1097         }
1098 #if 0
1099         else
1100         {
1101             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, " Error in opening adapter for %s",fake_if_info->description);
1102         }
1103 #endif
1104     }
1105
1106     return;
1107 }
1108
1109 /*
1110  * Free an instance of airpcap_if_info_t
1111  */
1112 void
1113 airpcap_if_info_free(airpcap_if_info_t *if_info)
1114 {
1115     if (if_info != NULL)
1116     {
1117         if (if_info->name != NULL)
1118             g_free(if_info->name);
1119
1120         if (if_info->description != NULL)
1121             g_free(if_info->description);
1122
1123         if (if_info->keysCollection != NULL)
1124         {
1125             g_free(if_info->keysCollection);
1126             if_info->keysCollection = NULL;
1127         }
1128
1129         if (if_info->ip_addr != NULL)
1130         {
1131             g_slist_free(if_info->ip_addr);
1132             if_info->ip_addr = NULL;
1133         }
1134
1135         if (if_info != NULL)
1136         {
1137             g_free(if_info);
1138         }
1139     }
1140 }
1141
1142
1143 /* DYNAMIC LIBRARY LOADER */
1144 /*
1145  *  Used to dynamically load the airpcap library in order link it only when
1146  *  it's present on the system
1147  */
1148 int load_airpcap(void)
1149 {
1150 #ifdef _WIN32
1151     gboolean base_functions     = TRUE;
1152     gboolean eleven_n_functions = TRUE;
1153
1154     if ((AirpcapLib = ws_load_library("airpcap.dll")) == NULL)
1155     {
1156         /* Report the error but go on */
1157         AirpcapVersion = AIRPCAP_DLL_NOT_FOUND;
1158         return AirpcapVersion;
1159     }
1160     else
1161     {
1162         if ((g_PAirpcapGetLastError = (AirpcapGetLastErrorHandler) GetProcAddress(AirpcapLib, "AirpcapGetLastError")) == NULL) base_functions = FALSE;
1163         if ((g_PAirpcapGetDeviceList = (AirpcapGetDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceList")) == NULL) base_functions = FALSE;
1164         if ((g_PAirpcapFreeDeviceList = (AirpcapFreeDeviceListHandler) GetProcAddress(AirpcapLib, "AirpcapFreeDeviceList")) == NULL) base_functions = FALSE;
1165         if ((g_PAirpcapOpen = (AirpcapOpenHandler) GetProcAddress(AirpcapLib, "AirpcapOpen")) == NULL) base_functions = FALSE;
1166         if ((g_PAirpcapClose = (AirpcapCloseHandler) GetProcAddress(AirpcapLib, "AirpcapClose")) == NULL) base_functions = FALSE;
1167         if ((g_PAirpcapGetLinkType = (AirpcapGetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapGetLinkType")) == NULL) base_functions = FALSE;
1168         if ((g_PAirpcapSetLinkType = (AirpcapSetLinkTypeHandler) GetProcAddress(AirpcapLib, "AirpcapSetLinkType")) == NULL) base_functions = FALSE;
1169         if ((g_PAirpcapSetKernelBuffer = (AirpcapSetKernelBufferHandler) GetProcAddress(AirpcapLib, "AirpcapSetKernelBuffer")) == NULL) base_functions = FALSE;
1170         if ((g_PAirpcapSetFilter = (AirpcapSetFilterHandler) GetProcAddress(AirpcapLib, "AirpcapSetFilter")) == NULL) base_functions = FALSE;
1171         if ((g_PAirpcapGetMacAddress = (AirpcapGetMacAddressHandler) GetProcAddress(AirpcapLib, "AirpcapGetMacAddress")) == NULL) base_functions = FALSE;
1172         if ((g_PAirpcapSetMinToCopy = (AirpcapSetMinToCopyHandler) GetProcAddress(AirpcapLib, "AirpcapSetMinToCopy")) == NULL) base_functions = FALSE;
1173         if ((g_PAirpcapGetReadEvent = (AirpcapGetReadEventHandler) GetProcAddress(AirpcapLib, "AirpcapGetReadEvent")) == NULL) base_functions = FALSE;
1174         if ((g_PAirpcapRead = (AirpcapReadHandler) GetProcAddress(AirpcapLib, "AirpcapRead")) == NULL) base_functions = FALSE;
1175         if ((g_PAirpcapGetStats = (AirpcapGetStatsHandler) GetProcAddress(AirpcapLib, "AirpcapGetStats")) == NULL) base_functions = FALSE;
1176         if ((g_PAirpcapTurnLedOn = (AirpcapTurnLedOnHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOn")) == NULL) base_functions = FALSE;
1177         if ((g_PAirpcapTurnLedOff = (AirpcapTurnLedOffHandler) GetProcAddress(AirpcapLib, "AirpcapTurnLedOff")) == NULL) base_functions = FALSE;
1178         if ((g_PAirpcapGetDeviceChannel = (AirpcapGetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannel")) == NULL) base_functions = FALSE;
1179         if ((g_PAirpcapSetDeviceChannel = (AirpcapSetDeviceChannelHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannel")) == NULL) base_functions = FALSE;
1180         if ((g_PAirpcapGetFcsPresence = (AirpcapGetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsPresence")) == NULL) base_functions = FALSE;
1181         if ((g_PAirpcapSetFcsPresence = (AirpcapSetFcsPresenceHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsPresence")) == NULL) base_functions = FALSE;
1182         if ((g_PAirpcapGetFcsValidation = (AirpcapGetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapGetFcsValidation")) == NULL) base_functions = FALSE;
1183         if ((g_PAirpcapSetFcsValidation = (AirpcapSetFcsValidationHandler) GetProcAddress(AirpcapLib, "AirpcapSetFcsValidation")) == NULL) base_functions = FALSE;
1184         if ((g_PAirpcapGetDeviceKeys = (AirpcapGetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceKeys")) == NULL) base_functions = FALSE;
1185         if ((g_PAirpcapSetDeviceKeys = (AirpcapSetDeviceKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceKeys")) == NULL) base_functions = FALSE;
1186         if ((g_PAirpcapGetDecryptionState = (AirpcapGetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDecryptionState")) == NULL) base_functions = FALSE;
1187         if ((g_PAirpcapSetDecryptionState = (AirpcapSetDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDecryptionState")) == NULL) base_functions = FALSE;
1188         if ((g_PAirpcapStoreCurConfigAsAdapterDefault = (AirpcapStoreCurConfigAsAdapterDefaultHandler) GetProcAddress(AirpcapLib, "AirpcapStoreCurConfigAsAdapterDefault")) == NULL) base_functions = FALSE;
1189         if ((g_PAirpcapGetVersion = (AirpcapGetVersionHandler) GetProcAddress(AirpcapLib, "AirpcapGetVersion")) == NULL) base_functions = FALSE;
1190         if ((g_PAirpcapGetDriverDecryptionState = (AirpcapGetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverDecryptionState")) == NULL) base_functions = FALSE;
1191         if ((g_PAirpcapSetDriverDecryptionState = (AirpcapSetDriverDecryptionStateHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverDecryptionState")) == NULL) base_functions = FALSE;
1192         if ((g_PAirpcapGetDriverKeys = (AirpcapGetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapGetDriverKeys")) == NULL) base_functions = FALSE;
1193         if ((g_PAirpcapSetDriverKeys = (AirpcapSetDriverKeysHandler) GetProcAddress(AirpcapLib, "AirpcapSetDriverKeys")) == NULL) base_functions = FALSE;
1194
1195         /* TEST IF AIRPCAP SUPPORTS 11N */
1196         if ((g_PAirpcapSetDeviceChannelEx = (AirpcapSetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapSetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
1197         if ((g_PAirpcapGetDeviceChannelEx = (AirpcapGetDeviceChannelExHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceChannelEx")) == NULL) eleven_n_functions = FALSE;
1198         if ((g_PAirpcapGetDeviceSupportedChannels = (AirpcapGetDeviceSupportedChannelsHandler) GetProcAddress(AirpcapLib, "AirpcapGetDeviceSupportedChannels")) == NULL) eleven_n_functions = FALSE;
1199
1200         if (base_functions && eleven_n_functions){
1201             AirpcapLoaded = TRUE;
1202             AirpcapVersion = AIRPCAP_DLL_OK;
1203         } else if (base_functions){
1204             AirpcapLoaded = TRUE;
1205             AirpcapVersion = AIRPCAP_DLL_OLD;
1206             return AIRPCAP_DLL_OK;
1207         }else{
1208             AirpcapLoaded = FALSE;
1209             AirpcapVersion = AIRPCAP_DLL_ERROR;
1210         }
1211     }
1212     return AirpcapVersion;
1213 #else /* _WIN32 */
1214     return AIRPCAP_DLL_NOT_FOUND;
1215 #endif /* _WIN32 */
1216 }
1217
1218 /*
1219  * Append the version of AirPcap with which we were compiled to a GString.
1220  */
1221 void
1222 get_compiled_airpcap_version(GString *str)
1223 {
1224     g_string_append(str, "with AirPcap");
1225 }
1226
1227 /*
1228  * Append the version of AirPcap with which we we're running to a GString.
1229  */
1230 void
1231 get_runtime_airpcap_version(GString *str)
1232 {
1233     guint vmaj, vmin, vrev, build;
1234
1235     /* See if the DLL has been loaded successfully.  Bail if it hasn't */
1236     if (AirpcapLoaded == FALSE) {
1237         g_string_append(str, "without AirPcap");
1238         return;
1239     }
1240
1241     g_PAirpcapGetVersion(&vmaj, &vmin, &vrev, &build);
1242     g_string_append_printf(str, "with AirPcap %d.%d.%d build %d", vmaj, vmin,
1243         vrev, build);
1244 }
1245
1246 /*
1247  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
1248  *
1249  * Local variables:
1250  * c-basic-offset: 4
1251  * tab-width: 8
1252  * indent-tabs-mode: nil
1253  * End:
1254  *
1255  * vi: set shiftwidth=4 tabstop=8 expandtab:
1256  * :indentSize=4:tabSize=8:noTabs=true:
1257  */