From 1cc667a00caa830b90e71d2f5c4e3a321cf2e73e Mon Sep 17 00:00:00 2001 From: Derek Dai Date: Wed, 14 Sep 2016 10:57:46 +0800 Subject: [PATCH 1/3] don't modify raw message --- src/shared/wpas.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/shared/wpas.c b/src/shared/wpas.c index 4b2adea..171a472 100644 --- a/src/shared/wpas.c +++ b/src/shared/wpas.c @@ -742,6 +742,7 @@ static int wpas__parse_message(struct wpas *w, const char *ifname = NULL; unsigned int level; char *pos; + char *orig_raw = raw; int r, num; bool is_event = false; @@ -751,7 +752,7 @@ static int wpas__parse_message(struct wpas *w, ifname = pos; pos = strchrnul(pos, ' '); if (*pos) - *pos++ = 0; + pos++; len -= pos - raw; raw = pos; @@ -811,15 +812,12 @@ static int wpas__parse_message(struct wpas *w, m->sealed = true; m->rawlen = len; - m->raw = malloc(len + 1); + m->raw = strdup(orig_raw); if (!m->raw) return -ENOMEM; - /* copy with 0-terminator */ - memcpy(m->raw, raw, len + 1); - if (ifname) { - m->ifname = strdup(ifname); + m->ifname = strndup(ifname, strchrnul(ifname, ' ') - ifname); if (!m->ifname) return -ENOMEM; } From a9266e5055d2c332080785e24bbaa82b101b1d11 Mon Sep 17 00:00:00 2001 From: Derek Dai Date: Wed, 14 Sep 2016 11:29:55 +0800 Subject: [PATCH 2/3] re-dispatch wpa_message with ifname!=NULL from supplicant_global_fn() to supplicant_dev_fn() --- src/wifi/wifid-supplicant.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wifi/wifid-supplicant.c b/src/wifi/wifid-supplicant.c index 6a49fa4..26d981c 100644 --- a/src/wifi/wifid-supplicant.c +++ b/src/wifi/wifid-supplicant.c @@ -2147,6 +2147,9 @@ static int supplicant_global_fn(struct wpas *w, } /* ignore events on the global-iface, we only listen on dev-iface */ + if(wpas_message_get_ifname(m)) { + supplicant_event(s, m); + } return 0; From 3886dcb7c791442a2012c8d0678a1c828403a8b5 Mon Sep 17 00:00:00 2001 From: Derek Dai Date: Wed, 14 Sep 2016 16:01:54 +0800 Subject: [PATCH 3/3] add option --use-dev to miracle-wifid to workaround the 'no ifname' issue --- src/wifi/wifid-link.c | 10 ++++++++++ src/wifi/wifid-supplicant.c | 2 +- src/wifi/wifid.c | 11 +++++++++++ src/wifi/wifid.h | 5 +++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/wifi/wifid-link.c b/src/wifi/wifid-link.c index ff9eb62..b2de058 100644 --- a/src/wifi/wifid-link.c +++ b/src/wifi/wifid-link.c @@ -132,6 +132,16 @@ void link_free(struct link *l) free(l); } +void link_use_dev(struct link *l) +{ + l->use_dev = true; +} + +bool link_is_using_dev(struct link *l) +{ + return l->use_dev; +} + void link_set_managed(struct link *l, bool set) { int r; diff --git a/src/wifi/wifid-supplicant.c b/src/wifi/wifid-supplicant.c index 26d981c..d3e4dbe 100644 --- a/src/wifi/wifid-supplicant.c +++ b/src/wifi/wifid-supplicant.c @@ -2147,7 +2147,7 @@ static int supplicant_global_fn(struct wpas *w, } /* ignore events on the global-iface, we only listen on dev-iface */ - if(wpas_message_get_ifname(m)) { + if(link_is_using_dev(s->l) && wpas_message_get_ifname(m)) { supplicant_event(s, m); } diff --git a/src/wifi/wifid.c b/src/wifi/wifid.c index 9533206..d2e8108 100644 --- a/src/wifi/wifid.c +++ b/src/wifi/wifid.c @@ -42,6 +42,7 @@ const char *interface_name = NULL; unsigned int arg_wpa_loglevel = LOG_NOTICE; +bool use_dev = false; /* * Manager Handling @@ -102,6 +103,9 @@ static void manager_add_udev_link(struct manager *m, link_set_friendly_name(l, m->friendly_name); + if(use_dev) + link_use_dev(l); + #ifdef RELY_UDEV if (udev_device_has_tag(d, "miracle")) { #else @@ -457,6 +461,7 @@ static int help(void) " -i --interface Choose the interface to use\n" "\n" " --wpa-loglevel