Fix bug 1377:
[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
85 /*
86  * The list of interfaces returned by "get_airpcap_interface_list()" is
87  * a list of these structures.
88  */
89 typedef struct {
90         char                                    *name;                          /* e.g. "eth0" */
91         char                                    *description;           /* from OS, e.g. "Local Area Connection" or NULL */
92         GSList                                  *ip_addr;                       /* containing address values of if_addr_t */
93         gboolean                                loopback;                       /* TRUE if loopback, FALSE otherwise */
94         AirpcapLinkType                 linkType;                       /* The link layer type*/
95         UINT                                    channel;                        /* Channel (1-14)*/
96         BOOL                                    IsFcsPresent;           /* Include 802.11 CRC in frames */
97         AirpcapValidationType   CrcValidationOn;        /* Capture Frames with Wrong CRC */
98         AirpcapDecryptionState  DecryptionOn;           /* TRUE if decryption is on, FALSE otherwise*/
99         PAirpcapKeysCollection  keysCollection;         /* WEP Key collection for the adapter */
100         UINT                                    keysCollectionSize;     /* Size of the key collection */
101         gboolean                                blinking;                       /* TRUE if is blinkng, FALSE otherwise*/
102         gboolean                                led;                            /* TRUE if on, FALSE if off*/
103         gboolean                                saved;                          /* TRUE if current configuration has been saved, FALSE otherwise */
104         gint                                    tag;                            /* int for the gtk blinking callback */
105 } airpcap_if_info_t;
106
107 /*
108  * Struct used to store infos to pass to the preferences manager callbacks
109  */
110 typedef struct {
111    GList *list;
112    int current_index;
113    int number_of_keys;
114 } keys_cb_data_t;
115
116 /* Airpcap interface list */
117 extern GList *airpcap_if_list;
118
119 /* Airpcap current selected interface */
120 extern airpcap_if_info_t *airpcap_if_selected;
121
122 /* Airpcap current active interface */
123 extern airpcap_if_info_t *airpcap_if_active;
124
125 /* WLAN preferences pointer */
126 //extern module_t *wlan_prefs;
127
128 /*
129  * Function used to read the Decryption Keys from the preferences and store them
130  * properly into the airpcap adapter.
131  */
132 BOOL
133 load_wlan_driver_wep_keys();
134
135 /*
136  *  Function used to save to the prefereces file the Decryption Keys.
137  */
138 BOOL
139 save_wlan_wep_keys(airpcap_if_info_t* info_if);
140
141 /*
142  * This function will tell the airpcap driver the key list to use
143  * This will be stored into the registry...
144  */
145 gboolean
146 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list);
147
148 /* Returs TRUE if the WEP key is valid, false otherwise */
149 gboolean
150 wep_key_is_valid(char* key);
151
152 /*
153  * Callback used to free an instance of airpcap_if_info_t
154  */
155 static void
156 free_airpcap_if_cb(gpointer data, gpointer user_data _U_);
157
158 /*
159  * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
160  */
161 void
162 airpcap_if_info_print(airpcap_if_info_t* if_info);
163
164 /*
165  * Used to retrieve the two chars string from interface
166  */
167 gchar*
168 airpcap_get_if_string_number_from_description(gchar* description);
169
170 /*
171  * Function used to free the airpcap interface list
172  */
173 void
174 free_airpcap_interface_list(GList *if_list);
175
176 /*
177  * Used to retrieve the interface given the name
178  * (the name is used in AirpcapOpen)
179  */
180 airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name);
181
182 /*
183  * Airpcap wrapper, used to store the current settings for the selected adapter
184  */
185 BOOL
186 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah);
187
188 /*
189  * Function used to load the WEP keys for a selected interface
190  */
191 BOOL
192 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
193
194 /*
195  * Function used to load the WEP keys from the global driver list
196  */
197 BOOL
198 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
199
200 /*
201  * Function used to save the WEP keys for a selected interface
202  */
203 void
204 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
205
206 /*
207  * Function used to save the WEP keys for a selected interface
208  */
209 void
210 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
211
212 /*
213  * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
214  */
215 BOOL
216 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val);
217
218 /*
219  * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
220  */
221 BOOL
222 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val);
223
224 /*
225  * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
226  */
227 BOOL
228 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState val);
229
230 /*
231  * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
232  */
233 BOOL
234 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState val);
235
236 /*
237  * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
238  */
239 BOOL
240 airpcap_if_get_fcs_presence(PAirpcapHandle ah, PBOOL ch);
241
242 /*
243  * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
244  */
245 BOOL
246 airpcap_if_set_fcs_presence(PAirpcapHandle ah, BOOL ch);
247
248 /*
249  * Airpcap wrapper, used to get the link type of an airpcap adapter
250  */
251 BOOL
252 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt);
253
254 /*
255  * Airpcap wrapper, used to set the link type of an airpcap adapter
256  */
257 BOOL
258 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt);
259
260 /*
261  * Airpcap wrapper, used to get the channel of an airpcap adapter
262  */
263 BOOL
264 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch);
265
266 /*
267  * Airpcap wrapper, used to set the channel of an airpcap adapter
268  */
269 BOOL
270 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch);
271
272 /*
273  * Airpcap wrapper, used to open an airpcap adapter
274  */
275 PAirpcapHandle airpcap_if_open(PCHAR name, PCHAR err);
276
277 /*
278  * Airpcap wrapper, used to close an airpcap adapter
279  */
280 VOID airpcap_if_close(PAirpcapHandle handle);
281
282 /*
283  * Airpcap wrapper, used to turn on the led of an airpcap adapter
284  */
285 BOOL airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, UINT LedNumber);
286
287 /*
288  * Airpcap wrapper, used to turn off the led of an airpcap adapter
289  */
290 BOOL airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber);
291
292 /*
293  * This function will create a new airpcap_if_info_t using a name and a description
294  */
295 airpcap_if_info_t* airpcap_if_info_new(char *name, char *description);
296
297 /*
298  * This function will create a new fake drivers' interface, to load global keys...
299  */
300 airpcap_if_info_t* airpcap_driver_fake_if_info_new();
301
302 /*
303  *  Used to dinamically load the airpcap library in order link it only when
304  *  it's present on the system.
305  */
306 int load_airpcap(void);
307
308 /*
309  * This function will use the airpcap.dll to find all the airpcap devices.
310  * Will return null if no device is found.
311  */
312 GList*
313 get_airpcap_interface_list(int *err, char **err_str);
314
315 /*
316  * Returns the ASCII string of a key given the key bites
317  */
318 gchar*
319 airpcap_get_key_string(AirpcapKey key);
320
321 /*
322  * Load the configuration for the specified interface
323  */
324 void
325 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info);
326
327 /*
328  * Save the configuration for the specified interface
329  */
330 void
331 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info);
332
333 /*
334  * Used to retrieve the name of the interface given the description
335  * (the name is used in AirpcapOpen, the description is put in the combo box)
336  */
337 gchar*
338 get_airpcap_name_from_description(GList* if_list, gchar* description);
339
340 /*
341  * Used to retrieve the airpcap_if_info_t of the selected interface given the
342  * description (that is the entry of the combo box).
343  */
344 gpointer
345 get_airpcap_if_from_description(GList* if_list, const gchar* description);
346
347 /*
348  * Used to retrieve the two chars string from interface description
349  */
350 gchar*
351 airpcap_get_if_string_number(airpcap_if_info_t* if_info);
352
353 /*
354  * Returns the default airpcap interface of a list, NULL if list is empty
355  */
356 airpcap_if_info_t*
357 airpcap_get_default_if(GList* airpcap_if_list);
358
359 /*
360  * Airpcap wrapper, used to save the settings for the selected_if
361  */
362 BOOL
363 airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
364
365 /*
366  * Airpcap wrapper, used to save the settings for the selected_if
367  */
368 BOOL
369 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
370
371 /*
372  * Airpcap wrapper, used to save the settings for the selected_if
373  */
374 BOOL
375 airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
376
377 /*
378  * Airpcap wrapper, used to save the settings for the selected_if
379  */
380 BOOL
381 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
382
383 /*
384  * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
385  */
386 BOOL
387 airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable);
388 /*
389  * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
390  */
391 BOOL
392 airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable);
393
394 /*
395  * Save the configuration for the specified interface
396  */
397 void
398 airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info);
399
400 /*
401  * Free an instance of airpcap_if_info_t
402  */
403 void
404 airpcap_if_info_free(airpcap_if_info_t *if_info);
405
406 /*
407  * This function will tell the airpcap driver the key list to use
408  * This will be stored into the registry...
409  */
410 BOOL
411 write_wlan_driver_wep_keys_to_registry(GList* key_list);
412
413 /*
414  * Clear keys and decryption status for the specified interface
415  */
416 void
417 airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if);
418
419 /*
420  *  Function used to save to the preference file the Decryption Keys.
421  */
422 int
423 save_wlan_driver_wep_keys();
424
425 /*
426  *  Function used to save to the preference file the Decryption Keys.
427  */
428 int
429 save_wlan_wireshark_wep_keys(GList* key_ls);
430
431 /*
432  * DECRYPTION KEYS FUNCTIONS
433  */
434 /*
435  * This function is used for DEBUG PURPOSES ONLY!!!
436  */
437 void
438 print_key_list(GList* key_list);
439
440 /*
441  * Retrieves a GList of decryption_key_t structures containing infos about the
442  * keys for the given adapter... returns NULL if no keys are found.
443  */
444 GList*
445 get_airpcap_device_keys(airpcap_if_info_t* if_info);
446
447 /*
448  * Retrieves a GList of decryption_key_t structures containing infos about the
449  * keys for the global AirPcap driver... returns NULL if no keys are found.
450  */
451 GList*
452 get_airpcap_driver_keys();
453
454 /*
455  * Returns the list of the decryption keys specified for wireshark, NULL if
456  * no key is found
457  */
458 GList*
459 get_wireshark_keys();
460
461 /*
462  * Tests if two collection of keys are equal or not, to be considered equals, they have to
463  * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
464  * return TRUE)
465  */
466 gboolean
467 key_lists_are_equal(GList* list1, GList* list2);
468
469 /*
470  * Merges two lists of keys. If a key is found multiple times, it will just appear once!
471  */
472 GList*
473 merge_key_list(GList* list1, GList* list2);
474
475 /*
476  * If the given key is contained in the list, returns TRUE.
477  * Returns FALSE otherwise.
478  */
479 gboolean
480 key_is_in_list(decryption_key_t *dk,GList *list);
481
482 /*
483  * Returns TRUE if keys are equals, FALSE otherwise
484  */
485 gboolean
486 keys_are_equals(decryption_key_t *k1,decryption_key_t *k2);
487
488 /*
489  * Use this function to free a key list.
490  */
491 void
492 free_key_list(GList *list);
493
494 /*
495  * Returns TRUE if the Wireshark decryption is active, FALSE otherwise
496  */
497 gboolean
498 wireshark_decryption_on();
499
500 /*
501  * Returns TRUE if the AirPcap decryption for the current adapter is active, FALSE otherwise
502  */
503 gboolean
504 airpcap_decryption_on();
505
506 /*
507  * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
508  */
509 void
510 set_wireshark_decryption(gboolean on_off);
511
512 /*
513  * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
514  */
515 gboolean
516 set_airpcap_decryption(gboolean on_off);
517
518 /*
519  * Adds compiled version string to str
520  */
521 void
522 get_compiled_airpcap_version(GString *str);
523
524 void
525 get_runtime_airpcap_version(GString *str);
526
527 #endif