Fix dist.
[obnox/wireshark/wip.git] / airpcap_loader.h
1 /* airpcap_loader.h
2  * Declarations of routines for the "About" dialog
3  *
4  * $Id$
5  *
6  * Giorgio Tino <giorgio.tino@cacetech.com>
7  * Copyright (c) CACE Technologies, LLC 2006
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifndef __AIRPCAP_LOADER_H__
29 #define __AIRPCAP_LOADER_H__
30
31 #include <epan/crypt/airpdcap_user.h>
32
33 /* Error values from "get_airpcap_interface_list()". */
34 #define CANT_GET_AIRPCAP_INTERFACE_LIST 0       /* error getting list */
35 #define NO_AIRPCAP_INTERFACES_FOUND     1       /* list is empty */
36 #define AIRPCAP_NOT_LOADED              2       /* Airpcap DLL not loaded */
37
38 #define AIRPCAP_CHANNEL_ANY_NAME "ANY"
39
40 #define AIRPCAP_WEP_KEY_STRING  "WEP"
41 /*
42  * XXX - WPA_PWD is the passphrase+ssid and WPA-PSK is the hexadecimal key
43  */
44 #define AIRPCAP_WPA_PWD_KEY_STRING  "WPA-PWD"
45 #define AIRPCAP_WPA_BIN_KEY_STRING  "WPA-PSK"
46
47 #define AIRPCAP_DLL_OK                  0
48 #define AIRPCAP_DLL_OLD                 1
49 #define AIRPCAP_DLL_ERROR               2
50 #define AIRPCAP_DLL_NOT_FOUND   3
51
52 typedef PCHAR (*AirpcapGetLastErrorHandler)(PAirpcapHandle AdapterHandle);
53 typedef BOOL (*AirpcapGetDeviceListHandler)(PAirpcapDeviceDescription *PPAllDevs, PCHAR Ebuf);
54 typedef VOID (*AirpcapFreeDeviceListHandler)(PAirpcapDeviceDescription PAllDevs);
55 typedef PAirpcapHandle (*AirpcapOpenHandler)(PCHAR DeviceName, PCHAR Ebuf);
56 typedef VOID (*AirpcapCloseHandler)(PAirpcapHandle AdapterHandle);
57 typedef BOOL (*AirpcapGetLinkTypeHandler)(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
58 typedef BOOL (*AirpcapSetLinkTypeHandler)(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
59 typedef BOOL (*AirpcapSetKernelBufferHandler)(PAirpcapHandle AdapterHandle, UINT BufferSize);
60 typedef BOOL (*AirpcapSetFilterHandler)(PAirpcapHandle AdapterHandle, PVOID Instructions, UINT Len);
61 typedef BOOL (*AirpcapGetMacAddressHandler)(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
62 typedef BOOL (*AirpcapSetMinToCopyHandler)(PAirpcapHandle AdapterHandle, UINT MinToCopy);
63 typedef BOOL (*AirpcapGetReadEventHandler)(PAirpcapHandle AdapterHandle, HANDLE* PReadEvent);
64 typedef BOOL (*AirpcapReadHandler)(PAirpcapHandle AdapterHandle, PBYTE Buffer, UINT BufSize, PUINT PReceievedBytes);
65 typedef BOOL (*AirpcapGetStatsHandler)(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
66 typedef BOOL (*AirpcapTurnLedOnHandler)(PAirpcapHandle  AdapterHandle, UINT  LedNumber);
67 typedef BOOL (*AirpcapTurnLedOffHandler)(PAirpcapHandle  AdapterHandle, UINT  LedNumber);
68 typedef BOOL (*AirpcapSetDeviceChannelHandler)(PAirpcapHandle  AdapterHandle, UINT  Channel);
69 typedef BOOL (*AirpcapGetDeviceChannelHandler)(PAirpcapHandle  AdapterHandle, PUINT PChannel);
70 typedef BOOL (*AirpcapSetFcsPresenceHandler)(PAirpcapHandle  AdapterHandle, BOOL  IsFcsPresent);
71 typedef BOOL (*AirpcapGetFcsPresenceHandler)(PAirpcapHandle  AdapterHandle, PBOOL PIsFcsPresent);
72 typedef BOOL (*AirpcapSetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, AirpcapValidationType ValidationType);
73 typedef BOOL (*AirpcapGetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, PAirpcapValidationType PValidationType);
74 typedef BOOL (*AirpcapSetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
75 typedef BOOL (*AirpcapGetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
76 typedef BOOL (*AirpcapSetDriverKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
77 typedef BOOL (*AirpcapGetDriverKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
78 typedef BOOL (*AirpcapSetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
79 typedef BOOL (*AirpcapGetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
80 typedef BOOL (*AirpcapSetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
81 typedef BOOL (*AirpcapGetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
82 typedef BOOL (*AirpcapStoreCurConfigAsAdapterDefaultHandler)(PAirpcapHandle AdapterHandle);
83 typedef VOID (*AirpcapGetVersionHandler)(PUINT VersionMajor, PUINT VersionMinor, PUINT VersionRev, PUINT VersionBuild);
84 typedef BOOL (*AirpcapSetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo);
85 typedef BOOL (*AirpcapGetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo);
86 typedef BOOL (*AirpcapGetDeviceSupportedChannelsHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo **ppChannelInfo, PULONG pNumChannelInfo);
87
88 #define FLAG_CAN_BE_LOW         0x00000001
89 #define FLAG_CAN_BE_HIGH        0x00000002
90 #define FLAG_IS_BG_CHANNEL      0x00000004
91 #define FLAG_IS_A_CHANNEL       0x00000008
92
93 typedef struct _Dot11Channel
94 {
95         UINT  Channel;
96         ULONG Frequency;
97         ULONG Flags;
98 } Dot11Channel;
99
100 /*
101  * The list of interfaces returned by "get_airpcap_interface_list()" is
102  * a list of these structures.
103  */
104 typedef struct {
105         char                                    *name;                          /* e.g. "eth0" */
106         char                                    *description;           /* from OS, e.g. "Local Area Connection" or NULL */
107         GSList                                  *ip_addr;                       /* containing address values of if_addr_t */
108         gboolean                                loopback;                       /* TRUE if loopback, FALSE otherwise */
109         AirpcapLinkType                 linkType;                       /* The link layer type */
110         AirpcapChannelInfo              channelInfo;            /* Channel Information */
111         BOOL                                    IsFcsPresent;           /* Include 802.11 CRC in frames */
112         AirpcapValidationType   CrcValidationOn;        /* Capture Frames with Wrong CRC */
113         AirpcapDecryptionState  DecryptionOn;           /* TRUE if decryption is on, FALSE otherwise */
114         PAirpcapKeysCollection  keysCollection;         /* WEP Key collection for the adapter */
115         UINT                                    keysCollectionSize;     /* Size of the key collection */
116         gboolean                                blinking;                       /* TRUE if is blinkng, FALSE otherwise */
117         gboolean                                led;                            /* TRUE if on, FALSE if off */
118         gboolean                                saved;                          /* TRUE if current configuration has been saved, FALSE otherwise */
119         gint                                    tag;                            /* int for the gtk blinking callback */
120         Dot11Channel                    *pSupportedChannels;
121         ULONG                                   numSupportedChannels;
122 } airpcap_if_info_t;
123
124 /*
125  * Struct used to store infos to pass to the preferences manager callbacks
126  */
127 typedef struct {
128    GList *list;
129    int current_index;
130    int number_of_keys;
131 } keys_cb_data_t;
132
133 /* Airpcap interface list */
134 extern GList *airpcap_if_list;
135
136 /* Airpcap current selected interface */
137 extern airpcap_if_info_t *airpcap_if_selected;
138
139 /* Airpcap current active interface */
140 extern airpcap_if_info_t *airpcap_if_active;
141
142 /* WLAN preferences pointer */
143 /*extern module_t *wlan_prefs; - TODO: What is this?? */
144
145 /*
146  * Function used to read the Decryption Keys from the preferences and store them
147  * properly into the airpcap adapter.
148  */
149 BOOL
150 load_wlan_driver_wep_keys();
151
152 /*
153  *  Function used to save to the prefereces file the Decryption Keys.
154  */
155 BOOL
156 save_wlan_wep_keys(airpcap_if_info_t* info_if);
157
158 /*
159  * This function will tell the airpcap driver the key list to use
160  * This will be stored into the registry...
161  */
162 gboolean
163 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list);
164
165 /* Returs TRUE if the WEP key is valid, false otherwise */
166 gboolean
167 wep_key_is_valid(char* key);
168
169 /*
170  * Callback used to free an instance of airpcap_if_info_t
171  */
172 static void
173 free_airpcap_if_cb(gpointer data, gpointer user_data _U_);
174
175 /*
176  * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
177  */
178 void
179 airpcap_if_info_print(airpcap_if_info_t* if_info);
180
181 /*
182  * Used to retrieve the two chars string from interface
183  */
184 gchar*
185 airpcap_get_if_string_number_from_description(gchar* description);
186
187 /*
188  * Function used to free the airpcap interface list
189  */
190 void
191 free_airpcap_interface_list(GList *if_list);
192
193 /*
194  * Used to retrieve the interface given the name
195  * (the name is used in AirpcapOpen)
196  */
197 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name);
198
199 /*
200  * Airpcap wrapper, used to store the current settings for the selected adapter
201  */
202 BOOL
203 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah);
204
205 /*
206  * Function used to load the WEP keys for a selected interface
207  */
208 BOOL
209 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
210
211 /*
212  * Function used to load the WEP keys from the global driver list
213  */
214 BOOL
215 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
216
217 /*
218  * Function used to save the WEP keys for a selected interface
219  */
220 void
221 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
222
223 /*
224  * Function used to save the WEP keys for a selected interface
225  */
226 void
227 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
228
229 /*
230  * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
231  */
232 BOOL
233 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val);
234
235 /*
236  * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
237  */
238 BOOL
239 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val);
240
241 /*
242  * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
243  */
244 BOOL
245 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState val);
246
247 /*
248  * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
249  */
250 BOOL
251 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState val);
252
253 /*
254  * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
255  */
256 BOOL
257 airpcap_if_get_fcs_presence(PAirpcapHandle ah, PBOOL ch);
258
259 /*
260  * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
261  */
262 BOOL
263 airpcap_if_set_fcs_presence(PAirpcapHandle ah, BOOL ch);
264
265 /*
266  * Airpcap wrapper, used to get the link type of an airpcap adapter
267  */
268 BOOL
269 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt);
270
271 /*
272  * Airpcap wrapper, used to set the link type of an airpcap adapter
273  */
274 BOOL
275 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt);
276
277 /*
278  * Airpcap wrapper, used to get the channel of an airpcap adapter
279  */
280 BOOL
281 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch);
282
283 /*
284  * Airpcap wrapper, get the channels supported by the adapter
285  */
286 BOOL
287 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, PULONG nInfo);
288
289 /*
290  * Airpcap wrapper, get supported channels formatted into an array
291  */
292 Dot11Channel*
293 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels);
294
295 /*
296  * Get channel representation string given a Frequency
297  */
298 gchar*
299 airpcap_get_channelstr_from_freq(ULONG chan_freq);
300
301 /*
302  * Get channel number given a Frequency
303  */
304 guint
305 airpcap_get_channel_number_from_freq(ULONG chan_freq);
306
307 /*
308  * Get Frequency given a Channel number
309  */
310 ULONG
311 airpcap_get_freq_from_channel_number(guint chan_number);
312
313 /*
314  * Airpcap wrapper, used to set the channel of an airpcap adapter
315  */
316 BOOL
317 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch);
318
319 /*
320  * Airpcap wrapper, used to get the frequency of an airpcap adapter
321  */
322 BOOL
323 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo);
324
325 /*
326  * Airpcap wrapper, used to set the frequency of an airpcap adapter
327  */
328 BOOL
329 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo);
330
331 /*
332  * Airpcap wrapper, used to open an airpcap adapter
333  */
334 PAirpcapHandle airpcap_if_open(PCHAR name, PCHAR err);
335
336 /*
337  * Airpcap wrapper, used to close an airpcap adapter
338  */
339 VOID airpcap_if_close(PAirpcapHandle handle);
340
341 /*
342  * Retrieve the state of the Airpcap DLL
343  */
344 int
345 airpcap_get_dll_state();
346
347 /*
348  * Airpcap wrapper, used to turn on the led of an airpcap adapter
349  */
350 BOOL airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber);
351
352 /*
353  * Airpcap wrapper, used to turn off the led of an airpcap adapter
354  */
355 BOOL airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber);
356
357 /*
358  * This function will create a new airpcap_if_info_t using a name and a description
359  */
360 airpcap_if_info_t* airpcap_if_info_new(char *name, char *description);
361
362 /*
363  * This function will create a new fake drivers' interface, to load global keys...
364  */
365 airpcap_if_info_t* airpcap_driver_fake_if_info_new();
366
367 /*
368  *  Used to dinamically load the airpcap library in order link it only when
369  *  it's present on the system.
370  */
371 int load_airpcap(void);
372
373 /*
374  * This function will use the airpcap.dll to find all the airpcap devices.
375  * Will return null if no device is found.
376  */
377 GList*
378 get_airpcap_interface_list(int *err, char **err_str);
379
380 /*
381  * Returns the ASCII string of a key given the key bites
382  */
383 gchar*
384 airpcap_get_key_string(AirpcapKey key);
385
386 /*
387  * Load the configuration for the specified interface
388  */
389 void
390 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info);
391
392 /*
393  * Save the configuration for the specified interface
394  */
395 void
396 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info);
397
398 /*
399  * Used to retrieve the two chars string from interface description
400  */
401 gchar*
402 airpcap_get_if_string_number(airpcap_if_info_t* if_info);
403
404 /*
405  * Returns the default airpcap interface of a list, NULL if list is empty
406  */
407 airpcap_if_info_t*
408 airpcap_get_default_if(GList* airpcap_if_list);
409
410 /*
411  * Airpcap wrapper, used to save the settings for the selected_if
412  */
413 BOOL
414 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
415
416 /*
417  * Airpcap wrapper, used to save the settings for the selected_if
418  */
419 BOOL
420 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
421
422 /*
423  * Airpcap wrapper, used to save the settings for the selected_if
424  */
425 BOOL
426 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
427
428 /*
429  * Airpcap wrapper, used to save the settings for the selected_if
430  */
431 BOOL
432 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
433
434 /*
435  * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
436  */
437 BOOL
438 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable);
439 /*
440  * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
441  */
442 BOOL
443 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable);
444
445 /*
446  * Save the configuration for the specified interface
447  */
448 void
449 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info);
450
451 /*
452  * Free an instance of airpcap_if_info_t
453  */
454 void
455 airpcap_if_info_free(airpcap_if_info_t *if_info);
456
457 /*
458  * This function will tell the airpcap driver the key list to use
459  * This will be stored into the registry...
460  */
461 BOOL
462 write_wlan_driver_wep_keys_to_registry(GList* key_list);
463
464 /*
465  * Clear keys and decryption status for the specified interface
466  */
467 void
468 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if);
469
470 /*
471  *  Function used to save to the preference file the Decryption Keys.
472  */
473 int
474 save_wlan_driver_wep_keys();
475
476 /*
477  *  Function used to save to the preference file the Decryption Keys.
478  */
479 int
480 save_wlan_wireshark_wep_keys(GList* key_ls);
481
482 /*
483  * DECRYPTION KEYS FUNCTIONS
484  */
485 /*
486  * This function is used for DEBUG PURPOSES ONLY!!!
487  */
488 void
489 print_key_list(GList* key_list);
490
491 /*
492  * Retrieves a GList of decryption_key_t structures containing infos about the
493  * keys for the given adapter... returns NULL if no keys are found.
494  */
495 GList*
496 get_airpcap_device_keys(airpcap_if_info_t* if_info);
497
498 /*
499  * Retrieves a GList of decryption_key_t structures containing infos about the
500  * keys for the global AirPcap driver... returns NULL if no keys are found.
501  */
502 GList*
503 get_airpcap_driver_keys();
504
505 /*
506  * Returns the list of the decryption keys specified for wireshark, NULL if
507  * no key is found
508  */
509 GList*
510 get_wireshark_keys();
511
512 /*
513  * Tests if two collection of keys are equal or not, to be considered equals, they have to
514  * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
515  * return TRUE)
516  */
517 gboolean
518 key_lists_are_equal(GList* list1, GList* list2);
519
520 /*
521  * Merges two lists of keys. If a key is found multiple times, it will just appear once!
522  */
523 GList*
524 merge_key_list(GList* list1, GList* list2);
525
526 /*
527  * If the given key is contained in the list, returns TRUE.
528  * Returns FALSE otherwise.
529  */
530 gboolean
531 key_is_in_list(decryption_key_t *dk,GList *list);
532
533 /*
534  * Returns TRUE if keys are equals, FALSE otherwise
535  */
536 gboolean
537 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2);
538
539 /*
540  * Use this function to free a key list.
541  */
542 void
543 free_key_list(GList *list);
544
545 /*
546  * Returns TRUE if the Wireshark decryption is active, FALSE otherwise
547  */
548 gboolean
549 wireshark_decryption_on();
550
551 /*
552  * Returns TRUE if the AirPcap decryption for the current adapter is active, FALSE otherwise
553  */
554 gboolean
555 airpcap_decryption_on();
556
557 /*
558  * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
559  */
560 void
561 set_wireshark_decryption(gboolean on_off);
562
563 /*
564  * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
565  */
566 gboolean
567 set_airpcap_decryption(gboolean on_off);
568
569 /*
570  * Adds compiled version string to str
571  */
572 void
573 get_compiled_airpcap_version(GString *str);
574
575 void
576 get_runtime_airpcap_version(GString *str);
577
578 #endif