Initialize var_list in dissect_smux(), so that we don't use previously
[obnox/wireshark/wip.git] / airpcap_loader.h
index 831e5519b1b66fb8b97b4d880821271c465abcbd..f974800dcdef27b856061aab8e0eda4d04577bf2 100644 (file)
 #ifndef __AIRPCAP_LOADER_H__
 #define __AIRPCAP_LOADER_H__
 
+#include <epan/crypt/airpdcap_user.h>
+
 /* Error values from "get_airpcap_interface_list()". */
 #define        CANT_GET_AIRPCAP_INTERFACE_LIST 0       /* error getting list */
 #define        NO_AIRPCAP_INTERFACES_FOUND     1       /* list is empty */
-
-#define MAX_ENCRYPTION_KEYS 64
+#define AIRPCAP_NOT_LOADED             2       /* Airpcap DLL not loaded */
 
 #define AIRPCAP_CHANNEL_ANY_NAME "ANY"
 
+#define AIRPCAP_WEP_KEY_STRING  "WEP"
 /*
- * WEP_KEY_MAX_SIZE is in bytes. but each byte is rapresented in strings with an ascii char
- * 4 bit are needed to store an exadecimal number, 8 bit to store a char...
+ * XXX - WPA_PWD is the passphrase+ssid and WPA-PSK is the hexadecimal key
  */
-#define WEP_KEY_MAX_CHAR_SIZE (WEP_KEY_MAX_SIZE*2)
+#define AIRPCAP_WPA_PWD_KEY_STRING  "WPA-PWD"
+#define AIRPCAP_WPA_BIN_KEY_STRING  "WPA-PSK"
+
+#define AIRPCAP_DLL_OK                 0
+#define AIRPCAP_DLL_OLD                        1
+#define AIRPCAP_DLL_ERROR              2
+#define AIRPCAP_DLL_NOT_FOUND  3
 
 typedef PCHAR (*AirpcapGetLastErrorHandler)(PAirpcapHandle AdapterHandle);
 typedef BOOL (*AirpcapGetDeviceListHandler)(PAirpcapDeviceDescription *PPAllDevs, PCHAR Ebuf);
@@ -66,9 +73,30 @@ typedef BOOL (*AirpcapSetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, Ai
 typedef BOOL (*AirpcapGetFcsValidationHandler)(PAirpcapHandle  AdapterHandle, PAirpcapValidationType PValidationType);
 typedef BOOL (*AirpcapSetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
 typedef BOOL (*AirpcapGetDeviceKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
+typedef BOOL (*AirpcapSetDriverKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
+typedef BOOL (*AirpcapGetDriverKeysHandler)(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
 typedef BOOL (*AirpcapSetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
 typedef BOOL (*AirpcapGetDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
+typedef BOOL (*AirpcapSetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHandle, AirpcapDecryptionState Enable);
+typedef BOOL (*AirpcapGetDriverDecryptionStateHandler)(PAirpcapHandle AdapterHandle, PAirpcapDecryptionState PEnable);
 typedef BOOL (*AirpcapStoreCurConfigAsAdapterDefaultHandler)(PAirpcapHandle AdapterHandle);
+typedef VOID (*AirpcapGetVersionHandler)(PUINT VersionMajor, PUINT VersionMinor, PUINT VersionRev, PUINT VersionBuild);
+typedef BOOL (*AirpcapSetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo ChannelInfo);
+typedef BOOL (*AirpcapGetDeviceChannelExHandler)(PAirpcapHandle AdapterHandle, PAirpcapChannelInfo PChannelInfo);
+typedef BOOL (*AirpcapGetDeviceSupportedChannelsHandler)(PAirpcapHandle AdapterHandle, AirpcapChannelInfo **ppChannelInfo, PULONG pNumChannelInfo);
+
+#define FLAG_CAN_BE_LOW                0x00000001
+#define FLAG_CAN_BE_HIGH       0x00000002
+#define FLAG_IS_BG_CHANNEL     0x00000004
+#define FLAG_IS_A_CHANNEL      0x00000008
+
+typedef struct _Dot11Channel
+{
+       UINT  Channel;
+       ULONG Frequency;
+       ULONG Flags;
+} Dot11Channel;
+
 /*
  * The list of interfaces returned by "get_airpcap_interface_list()" is
  * a list of these structures.
@@ -78,19 +106,30 @@ typedef struct {
        char                                    *description;           /* from OS, e.g. "Local Area Connection" or NULL */
        GSList                                  *ip_addr;                       /* containing address values of if_addr_t */
        gboolean                                loopback;                       /* TRUE if loopback, FALSE otherwise */
-       AirpcapLinkType                 linkType;                       /* The link layer type*/
-       UINT                                    channel;                        /* Channel (1-14)*/
+       AirpcapLinkType                 linkType;                       /* The link layer type */
+       AirpcapChannelInfo              channelInfo;            /* Channel Information */
        BOOL                                    IsFcsPresent;           /* Include 802.11 CRC in frames */
        AirpcapValidationType   CrcValidationOn;        /* Capture Frames with Wrong CRC */
-       AirpcapDecryptionState  DecryptionOn;           /* TRUE if decryption is on, FALSE otherwise*/
+       AirpcapDecryptionState  DecryptionOn;           /* TRUE if decryption is on, FALSE otherwise */
        PAirpcapKeysCollection  keysCollection;         /* WEP Key collection for the adapter */
        UINT                                    keysCollectionSize;     /* Size of the key collection */
-       gboolean                                blinking;                       /* TRUE if is blinkng, FALSE otherwise*/
-       gboolean                                led;                            /* TRUE if on, FALSE if off*/
+       gboolean                                blinking;                       /* TRUE if is blinkng, FALSE otherwise */
+       gboolean                                led;                            /* TRUE if on, FALSE if off */
        gboolean                                saved;                          /* TRUE if current configuration has been saved, FALSE otherwise */
        gint                                    tag;                            /* int for the gtk blinking callback */
+       Dot11Channel                    *pSupportedChannels;
+       ULONG                                   numSupportedChannels;
 } airpcap_if_info_t;
 
+/*
+ * Struct used to store infos to pass to the preferences manager callbacks
+ */
+typedef struct {
+   GList *list;
+   int current_index;
+   int number_of_keys;
+} keys_cb_data_t;
+
 /* Airpcap interface list */
 extern GList *airpcap_if_list;
 
@@ -100,12 +139,45 @@ extern airpcap_if_info_t *airpcap_if_selected;
 /* Airpcap current active interface */
 extern airpcap_if_info_t *airpcap_if_active;
 
+/* WLAN preferences pointer */
+/*extern module_t *wlan_prefs; - TODO: What is this?? */
+
+/*
+ * Function used to read the Decryption Keys from the preferences and store them
+ * properly into the airpcap adapter.
+ */
+BOOL
+load_wlan_driver_wep_keys();
+
+/*
+ *  Function used to save to the prefereces file the Decryption Keys.
+ */
+BOOL
+save_wlan_wep_keys(airpcap_if_info_t* info_if);
+
+/*
+ * This function will tell the airpcap driver the key list to use
+ * This will be stored into the registry...
+ */
+gboolean
+write_wlan_wep_keys_to_registry(airpcap_if_info_t* info_if, GList* key_list);
+
+/* Returs TRUE if the WEP key is valid, false otherwise */
+gboolean
+wep_key_is_valid(char* key);
+
 /*
  * Callback used to free an instance of airpcap_if_info_t
  */
 static void
 free_airpcap_if_cb(gpointer data, gpointer user_data _U_);
 
+/*
+ * USED FOR DEBUG ONLY... PRINTS AN AirPcap ADAPTER STRUCTURE in a fancy way.
+ */
+void
+airpcap_if_info_print(airpcap_if_info_t* if_info);
+
 /*
  * Used to retrieve the two chars string from interface
  */
@@ -122,7 +194,7 @@ free_airpcap_interface_list(GList *if_list);
  * Used to retrieve the interface given the name
  * (the name is used in AirpcapOpen)
  */
-airpcap_if_info_t* get_airpcap_if_by_name(GList* if_list, const gchar* name);
+airpcap_if_info_t* get_airpcap_if_from_name(GList* if_list, const gchar* name);
 
 /*
  * Airpcap wrapper, used to store the current settings for the selected adapter
@@ -136,12 +208,24 @@ airpcap_if_store_cur_config_as_adapter_default(PAirpcapHandle ah);
 BOOL
 airpcap_if_load_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
 
+/*
+ * Function used to load the WEP keys from the global driver list
+ */
+BOOL
+airpcap_if_load_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
+
 /*
  * Function used to save the WEP keys for a selected interface
  */
 void
 airpcap_if_save_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
 
+/*
+ * Function used to save the WEP keys for a selected interface
+ */
+void
+airpcap_if_save_driver_keys(PAirpcapHandle ad, airpcap_if_info_t *if_info);
+
 /*
  * Airpcap wrapper, used to get the fcs validation of an airpcap adapter
  */
@@ -196,12 +280,36 @@ airpcap_if_set_link_type(PAirpcapHandle ah, AirpcapLinkType lt);
 BOOL
 airpcap_if_get_device_channel(PAirpcapHandle ah, PUINT ch);
 
+/*
+ * Airpcap wrapper, get the channels supported by the adapter
+ */
+BOOL
+airpcap_if_get_device_supported_channels(PAirpcapHandle ah, AirpcapChannelInfo **cInfo, PULONG nInfo);
+
+/*
+ * Airpcap wrapper, get supported channels formatted into an array
+ */
+Dot11Channel*
+airpcap_if_get_device_supported_channels_array(PAirpcapHandle ah, PULONG pNumSupportedChannels);
+
 /*
  * Airpcap wrapper, used to set the channel of an airpcap adapter
  */
 BOOL
 airpcap_if_set_device_channel(PAirpcapHandle ah, UINT ch);
 
+/*
+ * Airpcap wrapper, used to get the frequency of an airpcap adapter
+ */
+BOOL
+airpcap_if_get_device_channel_ex(PAirpcapHandle ah, PAirpcapChannelInfo pChannelInfo);
+
+/*
+ * Airpcap wrapper, used to set the frequency of an airpcap adapter
+ */
+BOOL
+airpcap_if_set_device_channel_ex(PAirpcapHandle ah, AirpcapChannelInfo ChannelInfo);
+
 /*
  * Airpcap wrapper, used to open an airpcap adapter
  */
@@ -212,6 +320,12 @@ PAirpcapHandle airpcap_if_open(PCHAR name, PCHAR err);
  */
 VOID airpcap_if_close(PAirpcapHandle handle);
 
+/*
+ * Retrieve the state of the Airpcap DLL
+ */
+int
+airpcap_get_dll_state();
+
 /*
  * Airpcap wrapper, used to turn on the led of an airpcap adapter
  */
@@ -228,24 +342,22 @@ BOOL airpcap_if_turn_led_off(PAirpcapHandle AdapterHandle, UINT LedNumber);
 airpcap_if_info_t* airpcap_if_info_new(char *name, char *description);
 
 /*
- *  Used to dinamically load the airpcap library in order link it only when
- *  it's present on the system.
+ * This function will create a new fake drivers' interface, to load global keys...
  */
-BOOL load_airpcap(void);
+airpcap_if_info_t* airpcap_driver_fake_if_info_new();
 
 /*
- * Get an error message string for a CANT_GET_INTERFACE_LIST error from
- * "get_airpcap_interface_list()".
+ *  Used to dinamically load the airpcap library in order link it only when
+ *  it's present on the system.
  */
-gchar*
-cant_get_airpcap_if_list_error_message(const char *err_str);
+int load_airpcap(void);
 
 /*
  * This function will use the airpcap.dll to find all the airpcap devices.
  * Will return null if no device is found.
  */
 GList*
-get_airpcap_interface_list(int *err, char *err_str);
+get_airpcap_interface_list(int *err, char **err_str);
 
 /*
  * Returns the ASCII string of a key given the key bites
@@ -265,20 +377,6 @@ airpcap_load_selected_if_configuration(airpcap_if_info_t* if_info);
 void
 airpcap_save_selected_if_configuration(airpcap_if_info_t* if_info);
 
-/*
- * Used to retrieve the name of the interface given the description
- * (the name is used in AirpcapOpen, the description is put in the combo box)
- */
-gchar*
-get_airpcap_name_from_description(GList* if_list, gchar* description);
-
-/*
- * Used to retrieve the airpcap_if_info_t of the selected interface given the
- * description (that is the entry of the combo box).
- */
-gpointer
-get_airpcap_if_from_description(GList* if_list, const gchar* description);
-
 /*
  * Used to retrieve the two chars string from interface description
  */
@@ -302,4 +400,161 @@ airpcap_if_set_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection
  */
 BOOL
 airpcap_if_get_device_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
+
+/*
+ * Airpcap wrapper, used to save the settings for the selected_if
+ */
+BOOL
+airpcap_if_set_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection);
+
+/*
+ * Airpcap wrapper, used to save the settings for the selected_if
+ */
+BOOL
+airpcap_if_get_driver_keys(PAirpcapHandle AdapterHandle, PAirpcapKeysCollection KeysCollection, PUINT PKeysCollectionSize);
+
+/*
+ * Airpcap wrapper, used to get the decryption enabling of an airpcap driver
+ */
+BOOL
+airpcap_if_get_driver_decryption_state(PAirpcapHandle ah, PAirpcapDecryptionState PEnable);
+/*
+ * Airpcap wrapper, used to set the decryption enabling of an airpcap driver
+ */
+BOOL
+airpcap_if_set_driver_decryption_state(PAirpcapHandle ah, AirpcapDecryptionState Enable);
+
+/*
+ * Save the configuration for the specified interface
+ */
+void
+airpcap_save_driver_if_configuration(airpcap_if_info_t* fake_if_info);
+
+/*
+ * Free an instance of airpcap_if_info_t
+ */
+void
+airpcap_if_info_free(airpcap_if_info_t *if_info);
+
+/*
+ * This function will tell the airpcap driver the key list to use
+ * This will be stored into the registry...
+ */
+BOOL
+write_wlan_driver_wep_keys_to_registry(GList* key_list);
+
+/*
+ * Clear keys and decryption status for the specified interface
+ */
+void
+airpcap_if_clear_decryption_settings(airpcap_if_info_t* info_if);
+
+/*
+ *  Function used to save to the preference file the Decryption Keys.
+ */
+int
+save_wlan_driver_wep_keys();
+
+/*
+ *  Function used to save to the preference file the Decryption Keys.
+ */
+int
+save_wlan_wireshark_wep_keys(GList* key_ls);
+
+/*
+ * DECRYPTION KEYS FUNCTIONS
+ */
+/*
+ * This function is used for DEBUG PURPOSES ONLY!!!
+ */
+void
+print_key_list(GList* key_list);
+
+/*
+ * Retrieves a GList of decryption_key_t structures containing infos about the
+ * keys for the given adapter... returns NULL if no keys are found.
+ */
+GList*
+get_airpcap_device_keys(airpcap_if_info_t* if_info);
+
+/*
+ * Retrieves a GList of decryption_key_t structures containing infos about the
+ * keys for the global AirPcap driver... returns NULL if no keys are found.
+ */
+GList*
+get_airpcap_driver_keys();
+
+/*
+ * Returns the list of the decryption keys specified for wireshark, NULL if
+ * no key is found
+ */
+GList*
+get_wireshark_keys();
+
+/*
+ * Tests if two collection of keys are equal or not, to be considered equals, they have to
+ * contain the same keys in the SAME ORDER! (If both lists are NULL, which means empty will
+ * return TRUE)
+ */
+gboolean
+key_lists_are_equal(GList* list1, GList* list2);
+
+/*
+ * Merges two lists of keys. If a key is found multiple times, it will just appear once!
+ */
+GList*
+merge_key_list(GList* list1, GList* list2);
+
+/*
+ * If the given key is contained in the list, returns TRUE.
+ * Returns FALSE otherwise.
+ */
+gboolean
+key_is_in_list(decryption_key_t *dk,GList *list);
+
+/*
+ * Returns TRUE if keys are equals, FALSE otherwise
+ */
+gboolean
+keys_are_equals(decryption_key_t *k1,decryption_key_t *k2);
+
+/*
+ * Use this function to free a key list.
+ */
+void
+free_key_list(GList *list);
+
+/*
+ * Returns TRUE if the Wireshark decryption is active, FALSE otherwise
+ */
+gboolean
+wireshark_decryption_on();
+
+/*
+ * Returns TRUE if the AirPcap decryption for the current adapter is active, FALSE otherwise
+ */
+gboolean
+airpcap_decryption_on();
+
+/*
+ * Enables decryption for Wireshark if on_off is TRUE, disables it otherwise.
+ */
+void
+set_wireshark_decryption(gboolean on_off);
+
+/*
+ * Enables decryption for all the adapters if on_off is TRUE, disables it otherwise.
+ */
+gboolean
+set_airpcap_decryption(gboolean on_off);
+
+/*
+ * Adds compiled version string to str
+ */
+void
+get_compiled_airpcap_version(GString *str);
+
+void
+get_runtime_airpcap_version(GString *str);
+
 #endif