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