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