First step in integrating the AirPcap WEP preferences with those

from the 802.11 dissector.  Use a #define for the maximum number of
WEP keys.  Use AirPcap's if we have it (64).  Rename find_module()
prefs_find_module() and make it public.

svn path=/trunk/; revision=19467
This commit is contained in:
Gerald Combs 2006-10-10 00:28:53 +00:00
parent c43a1dffed
commit 993305a75f
5 changed files with 56 additions and 31 deletions

View File

@ -83,6 +83,8 @@ typedef struct _AirpcapDeviceDescription
PCHAR Description; /* Device description */
} AirpcapDeviceDescription, *PAirpcapDeviceDescription;
#define MAX_ENCRYPTION_KEYS 64
#define WEP_KEY_MAX_SIZE 32 /* Maximum size of a WEP key, in bytes. This is the size of an entry in the */
/* AirpcapWepKeysCollection structure */

View File

@ -32,8 +32,6 @@
#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_CHANNEL_ANY_NAME "ANY"
/*

View File

@ -71,6 +71,13 @@
#include <ctype.h>
#include "isprint.h"
#ifdef HAVE_AIRPCAP
#include <airpcap.h>
#else
/* XXX - This is probably a bit much */
#define MAX_ENCRYPTION_KEYS 64
#endif
#ifndef roundup2
#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
#endif
@ -112,7 +119,7 @@ static int weak_iv(guchar *iv);
*/
#ifndef USE_ENV
static const char *wep_keystr[] = {NULL, NULL, NULL, NULL};
static char *wep_keystr[MAX_ENCRYPTION_KEYS];
#endif
/* ************************************************************************* */
@ -3302,6 +3309,9 @@ wlan_defragment_init(void)
void
proto_register_ieee80211 (void)
{
int i;
GString *key_name, *key_title, *key_desc;
static const value_string frame_type[] = {
{MGT_FRAME, "Management frame"},
{CONTROL_FRAME, "Control frame"},
@ -4163,22 +4173,28 @@ proto_register_ieee80211 (void)
"How many WEP keys do we have to choose from? (0 to disable, up to 4)",
&num_wepkeys, wep_keys_options, FALSE);
prefs_register_string_preference(wlan_module, "wep_key1",
"WEP key #1",
"First WEP key (A:B:C:D:E) [40bit], (A:B:C:D:E:F:G:H:I:J:K:L:M) [104bit], or whatever key length you're using",
&wep_keystr[0]);
prefs_register_string_preference(wlan_module, "wep_key2",
"WEP key #2",
"Second WEP key (A:B:C:D:E) [40bit], (A:B:C:D:E:F:G:H:I:J:K:L:M) [104bit], or whatever key length you're using",
&wep_keystr[1]);
prefs_register_string_preference(wlan_module, "wep_key3",
"WEP key #3",
"Third WEP key (A:B:C:D:E) [40bit], (A:B:C:D:E:F:G:H:I:J:K:L:M) [104bit], or whatever key length you're using",
&wep_keystr[2]);
prefs_register_string_preference(wlan_module, "wep_key4",
"WEP key #4",
"Fourth WEP key (A:B:C:D:E) [40bit] (A:B:C:D:E:F:G:H:I:J:K:L:M) [104bit], or whatever key length you're using",
&wep_keystr[3]);
for (i = 0; i < MAX_ENCRYPTION_KEYS; i++) {
key_name = g_string_new("");
key_title = g_string_new("");
key_desc = g_string_new("");
wep_keystr[i] = NULL;
/* prefs_register_*_preference() expects unique strings, so
* we build them using g_string_sprintf and just leave them
* allocated. */
g_string_sprintf(key_name, "wep_key%d", i + 1);
fprintf(stderr, "%s\n", key_name->str);
g_string_sprintf(key_title, "WEP key #%d", i + 1);
g_string_sprintf(key_desc, "WEP key #%d bytes in hexadecimal (A:B:C:D:E) "
"[40bit], (A:B:C:D:E:F:G:H:I:J:K:L:M) [104bit], or whatever key "
"length you're using", i + 1);
prefs_register_string_preference(wlan_module, key_name->str,
key_title->str, key_desc->str, &wep_keystr[i]);
g_string_free(key_name, FALSE);
g_string_free(key_title, FALSE);
g_string_free(key_desc, FALSE);
}
#endif
}

View File

@ -50,7 +50,6 @@
#include <epan/prefs-int.h>
/* Internal functions */
static module_t *find_module(const char *name);
static module_t *prefs_register_module_or_subtree(module_t *parent,
const char *name, const char *title, const char *description, gboolean is_subtree,
void (*apply_cb)(void));
@ -209,7 +208,7 @@ prefs_register_module_or_subtree(module_t *parent, const char *name,
* protocol preferences to have a bogus "protocol.", or
* something such as that, to be added to all their names).
*/
g_assert(find_module(name) == NULL);
g_assert(prefs_find_module(name) == NULL);
/*
* Insert this module in the list of all modules.
@ -311,8 +310,8 @@ module_match(gconstpointer a, gconstpointer b)
return strcmp(name, module->name);
}
static module_t *
find_module(const char *name)
module_t *
prefs_find_module(const char *name)
{
GList *list_entry;
@ -494,7 +493,7 @@ find_preference(module_t *module, const char *name)
gboolean
prefs_is_registered_protocol(const char *name)
{
module_t *m = find_module(name);
module_t *m = prefs_find_module(name);
return (m != NULL && !m->obsolete);
}
@ -505,7 +504,7 @@ prefs_is_registered_protocol(const char *name)
const char *
prefs_get_title_by_name(const char *name)
{
module_t *m = find_module(name);
module_t *m = prefs_find_module(name);
return (m != NULL && !m->obsolete) ? m->title : NULL;
}
@ -1823,7 +1822,7 @@ set_pref(gchar *pref_name, gchar *value)
had_a_dot = TRUE;
}
*dotp = '\0'; /* separate module and preference name */
module = find_module(pref_name);
module = prefs_find_module(pref_name);
/*
* XXX - "Diameter" rather than "diameter" was used in earlier
@ -1842,14 +1841,14 @@ set_pref(gchar *pref_name, gchar *value)
*/
if (module == NULL) {
if (strcmp(pref_name, "Diameter") == 0)
module = find_module("diameter");
module = prefs_find_module("diameter");
else if (strcmp(pref_name, "bxxp") == 0)
module = find_module("beep");
module = prefs_find_module("beep");
else if (strcmp(pref_name, "gtpv0") == 0 ||
strcmp(pref_name, "gtpv1") == 0)
module = find_module("gtp");
module = prefs_find_module("gtp");
else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
module = find_module("gsm-sms-ud");
module = prefs_find_module("gsm-sms-ud");
}
*dotp = '.'; /* put the preference string back */
dotp++; /* skip past separator to preference name */
@ -2016,7 +2015,7 @@ set_pref(gchar *pref_name, gchar *value)
pref = find_preference(module, "desegment_body");
} else if (strcmp(module->name, "smpp") == 0) {
/* Handle preferences that moved from SMPP. */
module_t *new_module = find_module("gsm-sms-ud");
module_t *new_module = prefs_find_module("gsm-sms-ud");
if(new_module){
if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
pref = find_preference(new_module, "port_number_udh_means_wsp");

View File

@ -351,6 +351,16 @@ extern void free_prefs(e_prefs *pr);
#define PREFS_SET_NO_SUCH_PREF 2 /* no such preference */
#define PREFS_SET_OBSOLETE 3 /* preference used to exist but no longer does */
/** Given a module name, return a pointer to its pref_module struct,
* or NULL if it's not found.
*
* @param name The preference module name. Usually the same as the protocol
* name, e.g. "tcp".
* @return A pointer to the corresponding preference module, or NULL if it
* wasn't found.
*/
module_t *prefs_find_module(const char *name);
extern int prefs_set_pref(char *prefarg);
#endif /* prefs.h */