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