From 9a0edc0d16da172b45efda98a49ca042c08c7284 Mon Sep 17 00:00:00 2001
From: Ola Olsson <ola1olsson@gmail.com>
Date: Sat, 28 Mar 2015 01:36:44 +0100
Subject: [PATCH] Persist wpa_debug_level (log_level)
Every time the supplicant is started, it uses the log level
that was used the last time the config file was saved.
Before this patch, there were two options to change debug level
1) Statically at start up using args "-d" or "-q". Particularly
in Android, this is cumbersome since I need to change the boot
image to alter this variable.
2) Runtime via wpa_cli. This is a good way but hard to get right
timing if I need to log during the startup of the wpa_supplicant
itself. Also, when people file me bugs, they often tell me that
they ran "wpa_cli log_level debug" and thought it was persistent
throughout reboot.
---
src/utils/wpa_debug.c | 38 ++++++++++++++++++++++++++++++++++++++
src/utils/wpa_debug.h | 5 +++++
wpa_supplicant/config.c | 13 +++++++++++++
wpa_supplicant/config.h | 7 +++++++
wpa_supplicant/config_file.c | 1 +
wpa_supplicant/ctrl_iface.c | 40 ----------------------------------------
wpa_supplicant/main.c | 4 +++-
7 files changed, 67 insertions(+), 41 deletions(-)
@@ -33,6 +33,44 @@ int wpa_debug_level = MSG_INFO;
int wpa_debug_show_keys = 0;
int wpa_debug_timestamp = 0;
+const char * debug_level_str(int level)
+{
+ switch (level) {
+ case MSG_EXCESSIVE:
+ return "EXCESSIVE";
+ case MSG_MSGDUMP:
+ return "MSGDUMP";
+ case MSG_DEBUG:
+ return "DEBUG";
+ case MSG_INFO:
+ return "INFO";
+ case MSG_WARNING:
+ return "WARNING";
+ case MSG_ERROR:
+ return "ERROR";
+ default:
+ return "?";
+ }
+}
+
+
+int str_to_debug_level(const char *s)
+{
+ if (os_strcasecmp(s, "EXCESSIVE") == 0)
+ return MSG_EXCESSIVE;
+ if (os_strcasecmp(s, "MSGDUMP") == 0)
+ return MSG_MSGDUMP;
+ if (os_strcasecmp(s, "DEBUG") == 0)
+ return MSG_DEBUG;
+ if (os_strcasecmp(s, "INFO") == 0)
+ return MSG_INFO;
+ if (os_strcasecmp(s, "WARNING") == 0)
+ return MSG_WARNING;
+ if (os_strcasecmp(s, "ERROR") == 0)
+ return MSG_ERROR;
+ return -1;
+}
+
#ifdef CONFIG_ANDROID_LOG
@@ -22,6 +22,11 @@ enum {
MSG_EXCESSIVE, MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR
};
+const char * debug_level_str(int level);
+
+int str_to_debug_level(const char *s);
+
+
#ifdef CONFIG_NO_STDOUT_DEBUG
#define wpa_debug_print_timestamp() do { } while (0)
@@ -3729,6 +3729,18 @@ static int wpa_global_config_parse_ipv4(const struct global_parse_data *data,
}
#endif /* CONFIG_P2P */
+static int wpa_config_process_log_level(const struct global_parse_data *data,
+ struct wpa_config *config, int line,
+ const char *pos)
+{
+ int level = str_to_debug_level(pos);
+ if (level != -1) {
+ wpa_debug_level = level;
+ return 0;
+ }
+ wpa_printf(MSG_ERROR, "Message level:%d not in range\n", level);
+ return -1;
+}
static int wpa_config_process_country(const struct global_parse_data *data,
struct wpa_config *config, int line,
@@ -4215,6 +4227,7 @@ static const struct global_parse_data global_fields[] = {
{ INT(key_mgmt_offload), 0},
{ INT(passive_scan), 0 },
{ INT(reassoc_same_bss_optim), 0 },
+ { FUNC(log_level), 0},
};
#undef FUNC
@@ -1163,6 +1163,13 @@ struct wpa_config {
* reassoc_same_bss_optim - Whether to optimize reassoc-to-same-BSS
*/
int reassoc_same_bss_optim;
+
+ /**
+ * Never use or trust this variable. This is just used
+ * to get the wpa_config_process_log_level callback so we can set
+ * the global wpa_debug_level variable.
+ */
+ int log_level;
};
@@ -1280,6 +1280,7 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config)
if (config->reassoc_same_bss_optim)
fprintf(f, "reassoc_same_bss_optim=%d\n",
config->reassoc_same_bss_optim);
+ fprintf(f, "log_level=%s\n", debug_level_str(wpa_debug_level));
}
#endif /* CONFIG_NO_CONFIG_WRITE */
@@ -2088,46 +2088,6 @@ static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
return 3;
}
-
-static const char * debug_level_str(int level)
-{
- switch (level) {
- case MSG_EXCESSIVE:
- return "EXCESSIVE";
- case MSG_MSGDUMP:
- return "MSGDUMP";
- case MSG_DEBUG:
- return "DEBUG";
- case MSG_INFO:
- return "INFO";
- case MSG_WARNING:
- return "WARNING";
- case MSG_ERROR:
- return "ERROR";
- default:
- return "?";
- }
-}
-
-
-static int str_to_debug_level(const char *s)
-{
- if (os_strcasecmp(s, "EXCESSIVE") == 0)
- return MSG_EXCESSIVE;
- if (os_strcasecmp(s, "MSGDUMP") == 0)
- return MSG_MSGDUMP;
- if (os_strcasecmp(s, "DEBUG") == 0)
- return MSG_DEBUG;
- if (os_strcasecmp(s, "INFO") == 0)
- return MSG_INFO;
- if (os_strcasecmp(s, "WARNING") == 0)
- return MSG_WARNING;
- if (os_strcasecmp(s, "ERROR") == 0)
- return MSG_ERROR;
- return -1;
-}
-
-
static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
char *cmd, char *buf,
size_t buflen)
@@ -67,6 +67,7 @@ static void usage(void)
" -i = interface name\n"
" -I = additional configuration file\n"
" -d = increase debugging verbosity (-dd even more)\n"
+ " Note that the config file variable has precedence\n"
" -D = driver name (can be multiple drivers: nl80211,wext)\n"
" -e = entropy file\n");
#ifdef CONFIG_DEBUG_FILE
@@ -89,7 +90,8 @@ static void usage(void)
" -O = override ctrl_interface parameter for new interfaces\n"
" -p = driver parameters\n"
" -P = PID file\n"
- " -q = decrease debugging verbosity (-qq even less)\n");
+ " -q = decrease debugging verbosity (-qq even less)\n"
+ " Note that the config file variable has precedence\n");
#ifdef CONFIG_DBUS
printf(" -u = enable DBus control interface\n");
#endif /* CONFIG_DBUS */
--
1.7.9.5