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