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