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