From aa499be0dc0ed99b2a59d7c0b6190e8e30a04b4b Mon Sep 17 00:00:00 2001 From: Derek Dai Date: Sat, 1 Apr 2017 10:00:13 +0800 Subject: [PATCH] miracle-wifid: add Link.P2PState for checking P2P supporting status --- src/wifi/wifid-dbus.c | 23 +++++++++++++++++++++++ src/wifi/wifid-link.c | 33 +++++++++++++++++++++++++++++++++ src/wifi/wifid-supplicant.c | 5 ++++- src/wifi/wifid.h | 4 ++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/wifi/wifid-dbus.c b/src/wifi/wifid-dbus.c index 276f2c3..340258c 100644 --- a/src/wifi/wifid-dbus.c +++ b/src/wifi/wifid-dbus.c @@ -631,6 +631,24 @@ static int link_dbus_unmanage(sd_bus_message *msg, return sd_bus_reply_method_return(msg, NULL); } +static int link_dbus_get_p2p_state(sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *data, + sd_bus_error *err) +{ + struct link *l = data; + int r; + + r = sd_bus_message_append(reply, "i", link_get_p2p_state(l)); + if (r < 0) + return r; + + return 1; +} + static int link_dbus_get_p2p_scanning(sd_bus *bus, const char *path, const char *interface, @@ -742,6 +760,11 @@ static const sd_bus_vtable link_dbus_vtable[] = { link_dbus_get_managed, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), + SD_BUS_PROPERTY("P2PState", + "i", + link_dbus_get_p2p_state, + 0, + SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_WRITABLE_PROPERTY("P2PScanning", "b", link_dbus_get_p2p_scanning, diff --git a/src/wifi/wifid-link.c b/src/wifi/wifid-link.c index 0b81def..289e6de 100644 --- a/src/wifi/wifid-link.c +++ b/src/wifi/wifid-link.c @@ -155,6 +155,26 @@ bool link_is_using_dev(struct link *l) return l->use_dev; } +int link_get_p2p_state(struct link *l) +{ + return l->p2p_state; +} + +int link_set_p2p_state(struct link *l, int state) +{ + if (!l) + return log_EINVAL(); + if (l->p2p_state == state) + return 0; + if(-1 > state || 1 < state) + return log_EINVAL(); + + l->p2p_state = state; + link_dbus_properties_changed(l, "P2PState", NULL); + + return 0; +} + bool link_get_managed(struct link *l) { return l->managed; @@ -184,6 +204,19 @@ int link_set_managed(struct link *l, bool set) return 0; } +void link_supplicant_p2p_state_known(struct link *l, int state) +{ + if (!l) + return log_vEINVAL(); + if (l->p2p_state == state) + return; + if(-1 > state || 1 < state) + return log_vEINVAL(); + + l->p2p_state = state; + link_dbus_properties_changed(l, "P2PState", NULL); +} + void link_supplicant_managed(struct link *l) { if(l->managed) { diff --git a/src/wifi/wifid-supplicant.c b/src/wifi/wifid-supplicant.c index a5ab25b..85c76ea 100644 --- a/src/wifi/wifid-supplicant.c +++ b/src/wifi/wifid-supplicant.c @@ -1702,12 +1702,14 @@ static int supplicant_status_fn(struct wpas *w, if (!p2p_state) { log_warning("wpa_supplicant or driver does not support P2P"); + link_supplicant_p2p_state_known(s->l, -1); } else if (!strcmp(p2p_state, "DISABLED")) { log_warning("P2P support disabled on given interface"); + link_supplicant_p2p_state_known(s->l, -1); } else { s->has_p2p = true; - link_supplicant_managed(s->l); + link_supplicant_p2p_state_known(s->l, 1); r = wpas_message_new_request(s->bus_global, "SET", @@ -2579,6 +2581,7 @@ static int supplicant_timer_fn(sd_event_source *source, } else { /* wpas is running smoothly, disable timer */ sd_event_source_set_enabled(source, SD_EVENT_OFF); + link_supplicant_managed(s->l); } } else { /* Who armed this timer? What timer is this? */ diff --git a/src/wifi/wifid.h b/src/wifi/wifid.h index 10a5870..3c27f57 100644 --- a/src/wifi/wifid.h +++ b/src/wifi/wifid.h @@ -130,6 +130,7 @@ struct link { char *friendly_name; char *wfd_subelements; char *mac_addr; + int p2p_state; /* 0: unknown, 1: supported, -1: unsupproted */ size_t peer_cnt; struct shl_htable peers; @@ -170,12 +171,15 @@ int link_set_wfd_subelements(struct link *l, const char *val); const char *link_get_wfd_subelements(struct link *l); int link_set_p2p_scanning(struct link *l, bool set); bool link_get_p2p_scanning(struct link *l); +int link_get_p2p_state(struct link *l); const char *link_get_mac_addr(struct link *l); void link_supplicant_managed(struct link *l); void link_supplicant_started(struct link *l); void link_supplicant_stopped(struct link *l); void link_supplicant_p2p_scan_changed(struct link *l, bool new_value); +/* 0: unknown, -1: unsupported, 1: supported */ +void link_supplicant_p2p_state_known(struct link *l, int state); _shl_sentinel_ void link_dbus_properties_changed(struct link *l, const char *prop, ...);