Logcat: Remove commented code
[metze/wireshark/wip.git] / airpcap_loader.h
1 /* airpcap_loader.h
2  * Declarations of routines for the "About" dialog
3  *
4  * Giorgio Tino <giorgio.tino@cacetech.com>
5  * Copyright (c) CACE Technologies, LLC 2006
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #ifndef __AIRPCAP_LOADER_H__
27 #define __AIRPCAP_LOADER_H__
28
29 #include <epan/crypt/airpdcap_user.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /* Error values from "get_airpcap_interface_list()". */
36 #define CANT_GET_AIRPCAP_INTERFACE_LIST 0    /* error getting list */
37 #define NO_AIRPCAP_INTERFACES_FOUND     1    /* list is empty */
38 #define AIRPCAP_NOT_LOADED              2    /* Airpcap DLL not loaded */
39
40 #define AIRPCAP_CHANNEL_ANY_NAME "ANY"
41
42 #define AIRPCAP_WEP_KEY_STRING  "WEP"
43 /*
44  * XXX - WPA_PWD is the passphrase+ssid and WPA-PSK is the hexadecimal key
45  */
46 #define AIRPCAP_WPA_PWD_KEY_STRING  "WPA-PWD"
47 #define AIRPCAP_WPA_BIN_KEY_STRING  "WPA-PSK"
48
49 #define AIRPCAP_DLL_OK        0
50 #define AIRPCAP_DLL_OLD       1
51 #define AIRPCAP_DLL_ERROR     2
52 #define AIRPCAP_DLL_NOT_FOUND 3
53
54 typedef gchar * (*AirpcapGetLastErrorHandler)(PAirpcapHandle AdapterHandle);
55 typedef gboolean (*AirpcapGetDeviceListHandler)(PAirpcapDeviceDescription *PPAllDevs, gchar * Ebuf);
56 typedef void (*AirpcapFreeDeviceListHandler)(PAirpcapDeviceDescription PAllDevs);
57 typedef PAirpcapHandle (*AirpcapOpenHandler)(gchar * DeviceName, gchar * Ebuf);
58 typedef void (*AirpcapCloseHandler)(PAirpcapHandle AdapterHandle);
59 typedef gboolean (*AirpcapGetLinkTypeHandler)(PAirpcapHandle AdapterHandle, PAirpcapLinkType PLinkType);
60 typedef gboolean (*AirpcapSetLinkTypeHandler)(PAirpcapHandle AdapterHandle, AirpcapLinkType NewLinkType);
61 typedef gboolean (*AirpcapSetKernelBufferHandler)(PAirpcapHandle AdapterHandle, guint BufferSize);
62 typedef gboolean (*AirpcapSetFilterHandler)(PAirpcapHandle AdapterHandle, void * Instructions, guint Len);
63 typedef gboolean (*AirpcapGetMacAddressHandler)(PAirpcapHandle AdapterHandle, PAirpcapMacAddress PMacAddress);
64 typedef gboolean (*AirpcapSetMinToCopyHandler)(PAirpcapHandle AdapterHandle, guint MinToCopy);
65 typedef gboolean (*AirpcapGetReadEventHandler)(PAirpcapHandle AdapterHandle, void *** PReadEvent);
66 typedef gboolean (*AirpcapReadHandler)(PAirpcapHandle AdapterHandle, guint8 * Buffer, guint BufSize, guint * PReceievedBytes);
67 typedef gboolean (*AirpcapGetStatsHandler)(PAirpcapHandle AdapterHandle, PAirpcapStats PStats);
68 typedef gboolean (*AirpcapTurnLedOnHandler)(PAirpcapHandle  AdapterHandle, guint  LedNumber);
69 typedef gboolean (*AirpcapTurnLedOffHandler)(PAirpcapHandle  AdapterHandle, guint  LedNumber);
70 typedef gboolean (*AirpcapSetDeviceChannelHandler)(PAirpcapHandle  AdapterHandle, guint  Channel);
71 typedef gboolean (*AirpcapGetDeviceChannelHandler)(PAirpcapHandle  AdapterHandle, guint * PChannel);
72 typedef gboolean (*AirpcapSetFcsPresenceHandler)(PAirpcapHandle  AdapterHandle, gboolean  IsFcsPresent);
73 typedef gboolean (*AirpcapGetFcsPresenceHandler)(PAirpcapHandle  AdapterHandle, gboolean * PIsFcsPresent);
74 typedef gboolean (*AirpcapSetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, AirpcapValidationType ValidationType);
75 typedef gboolean (*AirpcapGetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, PAirpcapValidationType PValidationType);
76 typedef gboolean (*AirpcapSetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
77 typedef gboolean (*AirpcapGetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
78 typedef gboolean (*AirpcapSetDriverKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
79 typedef gboolean (*AirpcapGetDriverKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
80 typedef gboolean (*AirpcapSetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
81 typedef gboolean (*AirpcapGetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
82 typedef gboolean (*AirpcapSetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
83 typedef gboolean (*AirpcapGetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
84 typedef gboolean (*AirpcapStoreCurConfigAsAdapterDefaultHandler)(PAirpcapHandle AdapterHandle);
85 typedef void (*AirpcapGetVersionHandler)(guint * VersionMajor, guint * VersionMinor, guint * VersionRev, guint * VersionBuild);
86 typedef gboolean (*AirpcapSetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo);
87 typedef gboolean (*AirpcapGetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo);
88 typedef gboolean (*AirpcapGetDeviceSupportedChannelsHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo **ppChannelInfo, guint32 * pNumChannelInfo);
89
90 #define FLAG_CAN_BE_LOW    0x00000001
91 #define FLAG_CAN_BE_HIGH   0x00000002
92 #define FLAG_IS_BG_CHANNEL 0x00000004
93 #define FLAG_IS_A_CHANNEL  0x00000008
94
95 typedef struct _Dot11Channel
96 {
97     guint  Channel;
98     guint32 Frequency;
99     guint32 Flags;
100 } Dot11Channel;
101
102 /*
103  * The list of interfaces returned by "get_airpcap_interface_list()" is
104  * a list of these structures.
105  */
106 typedef struct {
107     char                    *name;              /* e.g. "eth0" */
108     char                    *description;       /* from OS, e.g. "Local Area Connection" or NULL */
109     GSList                  *ip_addr;           /* containing address values of if_addr_t */
110     gboolean                loopback;           /* TRUE if loopback, FALSE otherwise */
111     AirpcapLinkType         linkType;           /* The link layer type */
112     AirpcapChannelInfo      channelInfo;        /* Channel Information */
113     gboolean                IsFcsPresent;       /* Include 802.11 CRC in frames */
114     AirpcapValidationType   CrcValidationOn;    /* Capture Frames with Wrong CRC */
115     AirpcapDecryptionState  DecryptionOn;       /* TRUE if decryption is on, FALSE otherwise */
116     PAirpcapKeysCollection  keysCollection;     /* WEP Key collection for the adapter */
117     guint                   keysCollectionSize; /* Size of the key collection */
118     gboolean                blinking;           /* TRUE if is blinkng, FALSE otherwise */
119     gboolean                led;                /* TRUE if on, FALSE if off */
120     gboolean                saved;              /* TRUE if current configuration has been saved, FALSE otherwise */
121     gint                    tag;                /* int for the gtk blinking callback */
122     Dot11Channel            *pSupportedChannels;
123     guint32                 numSupportedChannels;
124 } airpcap_if_info_t;
125
126 /*
127  * Struct used to store infos to pass to the preferences manager callbacks
128  */
129 typedef struct {
130    GList *list;
131    int current_index;
132    int number_of_keys;
133 } keys_cb_data_t;
134
135 /* Airpcap interface list */
136 extern GList *airpcap_if_list;
137
138 /* Airpcap current selected interface */
139 extern airpcap_if_info_t *airpcap_if_selected;
140
141 /* Airpcap current active interface */
142 extern airpcap_if_info_t *airpcap_if_active;
143
144 /* WLAN preferences pointer */
145 /*extern module_t *wlan_prefs; - TODO: What is this?? */
146
147 /*
148  * Function used to read the Decryption Keys from the preferences and store them
149  * properly into the airpcap adapter.
150  */
151 gboolean
152 load_wlan_driver_wep_keys(void);
153
154 /*
155  *  Function used to save to the prefereces file the Decryption Keys.
156  */
157 gboolean
158 save_wlan_wep_keys(airpcap_if_info_t* info_if);
159
160 /*
161  * This function will tell the airpcap driver the key list to use
162  * This will be stored into the registry...
163  */
164 gboolean
165 write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list);
166
167 /* Returs TRUE if the WEP key is valid, false otherwise */
168 gboolean
169 wep_key_is_valid(char* key);
170
171 /*
172  * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
173  */
174 void
175 airpcap_if_info_print(airpcap_if_info_t* if_info);
176
177 /*
178  * Used to retrieve the two chars string from interface
179  */
180 gchar*
181 airpcap_get_if_string_number_from_description(gchar* description);
182
183 /*
184  * Function used to free the airpcap interface list
185  */
186 void
187 free_airpcap_interface_list(GList *if_list);
188
189 /*
190  * Used to retrieve the interface given the name
191  * (the name is used in AirpcapOpen)
192  */
193 airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name);
194
195 /*
196  * Airpcap wrapper, used to store the current settings for the selected adapter
197  */
198 gboolean
199 airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah);
200
201 /*
202  * Function used to load the WEP keys for a selected interface
203  */
204 gboolean
205 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
206
207 /*
208  * Function used to load the WEP keys from the global driver list
209  */
210 gboolean
211 airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
212
213 /*
214  * Function used to save the WEP keys for a selected interface
215  */
216 void
217 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
218
219 /*
220  * Function used to save the WEP keys for a selected interface
221  */
222 void
223 airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
224
225 /*
226  * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
227  */
228 gboolean
229 airpcap_if_get_fcs_validation(PAirpcapHandle ah, PAirpcapValidationType val);
230
231 /*
232  * Airpcap wrapper, used to set the fcs validation of an airpcap adapter
233  */
234 gboolean
235 airpcap_if_set_fcs_validation(PAirpcapHandle ah, AirpcapValidationType val);
236
237 /*
238  * Airpcap wrapper, used to get the decryption enabling of an airpcap adapter
239  */
240 gboolean
241 airpcap_if_get_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState val);
242
243 /*
244  * Airpcap wrapper, used to set the decryption enabling of an airpcap adapter
245  */
246 gboolean
247 airpcap_if_set_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState val);
248
249 /*
250  * Airpcap wrapper, used to get the fcs presence of an airpcap adapter
251  */
252 gboolean
253 airpcap_if_get_fcs_presence(PAirpcapHandle ah, gboolean * ch);
254
255 /*
256  * Airpcap wrapper, used to set the fcs presence of an airpcap adapter
257  */
258 gboolean
259 airpcap_if_set_fcs_presence(PAirpcapHandle ah, gboolean ch);
260
261 /*
262  * Airpcap wrapper, used to get the link type of an airpcap adapter
263  */
264 gboolean
265 airpcap_if_get_link_type(PAirpcapHandle ah, PAirpcapLinkType lt);
266
267 /*
268  * Airpcap wrapper, used to set the link type of an airpcap adapter
269  */
270 gboolean
271 airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt);
272
273 /*
274  * Airpcap wrapper, used to get the channel of an airpcap adapter
275  */
276 gboolean
277 airpcap_if_get_device_channel(PAirpcapHandle ah, guint * ch);
278
279 /*
280  * Airpcap wrapper, get the channels supported by the adapter
281  */
282 gboolean
283 airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, guint32 * nInfo);
284
285 /*
286  * Airpcap wrapper, get supported channels formatted into an array
287  */
288 Dot11Channel*
289 airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, guint32 * pNumSupportedChannels);
290
291 /*
292  * Airpcap wrapper, used to set the channel of an airpcap adapter
293  */
294 gboolean
295 airpcap_if_set_device_channel(PAirpcapHandle ah, guint ch);
296
297 /*
298  * Airpcap wrapper, used to get the frequency of an airpcap adapter
299  */
300 gboolean
301 airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo);
302
303 /*
304  * Airpcap wrapper, used to set the frequency of an airpcap adapter
305  */
306 gboolean
307 airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo);
308
309 /*
310  * Airpcap wrapper, used to open an airpcap adapter
311  */
312 PAirpcapHandle airpcap_if_open(gchar * name, gchar * err);
313
314 /*
315  * Airpcap wrapper, used to close an airpcap adapter
316  */
317 void airpcap_if_close(PAirpcapHandle handle);
318
319 /*
320  * Retrieve the state of the Airpcap DLL
321  */
322 int
323 airpcap_get_dll_state(void);
324
325 /*
326  * Airpcap wrapper, used to turn on the led of an airpcap adapter
327  */
328 gboolean airpcap_if_turn_led_on(PAirpcapHandle AdapterHandle, guint LedNumber);
329
330 /*
331  * Airpcap wrapper, used to turn off the led of an airpcap adapter
332  */
333 gboolean airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, guint LedNumber);
334
335 /*
336  * This function will create a new airpcap_if_info_t using a name and a description
337  */
338 airpcap_if_info_t* airpcap_if_info_new(char *name, char *description);
339
340 /*
341  * This function will create a new fake drivers' interface, to load global keys...
342  */
343 airpcap_if_info_t* airpcap_driver_fake_if_info_new(void);
344
345 /*
346  *  Used to dinamically load the airpcap library in order link it only when
347  *  it's present on the system.
348  */
349 int load_airpcap(void);
350
351 /*
352  * This function will use the airpcap.dll to find all the airpcap devices.
353  * Will return null if no device is found.
354  */
355 GList*
356 get_airpcap_interface_list(int *err, char **err_str);
357
358 /*
359  * Returns the ASCII string of a key given the key bites
360  */
361 gchar*
362 airpcap_get_key_string(AirpcapKey key);
363
364 /*
365  * Load the configuration for the specified interface
366  */
367 void
368 airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info);
369
370 /*
371  * Save the configuration for the specified interface
372  */
373 void
374 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info);
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 gboolean
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 gboolean
398 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
399
400 /*
401  * Airpcap wrapper, used to save the settings for the selected_if
402  */
403 gboolean
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 gboolean
410 airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, guint * PKeysCollectionSize);
411
412 /*
413  * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
414  */
415 gboolean
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 gboolean
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 gboolean
440 write_wlan_driver_wep_keys_to_registry(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(void);
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(void);
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(void);
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(void);
528
529 /*
530  * Returns TRUE if the AirPcap decryption for the current adapter is active, FALSE otherwise
531  */
532 gboolean
533 airpcap_decryption_on(void);
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 #ifdef __cplusplus
557 }
558 #endif
559
560 #endif /* __AIRPCAP_LOADER_H__ */