From ad827936df8179d2e8ca02bd1fa7c35e4b41221a Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Tue, 14 Jun 2016 22:47:31 +0530 Subject: [SPIN] implement to check blacklist for auto connection. Change-Id: I174b228529374f80b1c4197a310124c028564bb8 Signed-off-by: Niraj Kumar Goit --- src/agent-connman.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/connman.h | 4 ++++ src/service.c | 30 ++++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/src/agent-connman.c b/src/agent-connman.c index 177cbe0a..04f95df3 100755 --- a/src/agent-connman.c +++ b/src/agent-connman.c @@ -595,6 +595,73 @@ int __connman_agent_request_login_input(struct connman_service *service, return -EINPROGRESS; } +#if defined TIZEN_CONNMAN_USE_BLACKLIST +dbus_bool_t __connman_agent_request_blacklist_check( + const char *name, const char *security, const char *eap) +{ + DBusMessage *message; + DBusMessage *reply; + DBusMessageIter iter; + DBusError error; + dbus_bool_t allowed = TRUE; + const char *no_eap = ""; + + if (agent_path == NULL) { + DBG("agent is not registered"); + return FALSE; + } + + if (name == NULL || security == NULL) + return FALSE; + + message = dbus_message_new_method_call(agent_sender, agent_path, + "net.netconfig.wifi", + "CheckBlackList"); + if (message == NULL) { + DBG("dbus_message_new_method_call() failed"); + return TRUE; + } + + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &security); + + if (eap) + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &eap); + else + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &no_eap); + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, 2000, &error); + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + DBG("dbus_connection_send_with_reply_and_block() failed. " + "dbus error [%s: %s]", error.name, error.message); + + dbus_error_free(&error); + } else + DBG("failed to get properties"); + + dbus_message_unref(message); + + return TRUE; + } + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + DBG("failed to request blacklist check"); + return TRUE; + } + + dbus_message_iter_init(reply, &iter); + dbus_message_iter_get_basic(&iter, &allowed); + + dbus_message_unref(message); + + return allowed; +} +#endif + struct request_browser_reply_data { struct connman_service *service; browser_authentication_cb_t callback; diff --git a/src/connman.h b/src/connman.h index 2e9c26f8..6f588bf2 100755 --- a/src/connman.h +++ b/src/connman.h @@ -125,6 +125,10 @@ int __connman_agent_request_peer_authorization(struct connman_peer *peer, bool wps_requested, const char *dbus_sender, void *user_data); +#if defined TIZEN_CONNMAN_USE_BLACKLIST +dbus_bool_t __connman_agent_request_blacklist_check( + const char *name, const char *security, const char *eap); +#endif #include diff --git a/src/service.c b/src/service.c index 9149dd24..ed59930b 100755 --- a/src/service.c +++ b/src/service.c @@ -4198,6 +4198,31 @@ void __connman_service_set_active_session(bool enable, GSList *list) active_count); } +#if defined TIZEN_CONNMAN_USE_BLACKLIST +static connman_bool_t is_allowed(struct connman_service *service) +{ + connman_bool_t allowed; + const char *security = NULL; + + if (!service) + return false; + + security = security2string(service->security); + if (!security) + return false; + + /* check if service is existed in blacklist */ + allowed = __connman_agent_request_blacklist_check(service->name, + security, service->eap); + if (allowed == false) { + DBG("service %p is not allowed", service); + service->autoconnect = false; + } + + return allowed; +} +#endif + struct preferred_tech_data { GList *preferred_list; enum connman_service_type type; @@ -4324,6 +4349,11 @@ static bool auto_connect_service(GList *services, CONNMAN_SERVICE_STATE_IDLE) continue; +#if defined TIZEN_CONNMAN_USE_BLACKLIST + if (is_allowed(service) == false) + continue; +#endif + if (autoconnecting && !active_sessions[service->type]) { DBG("service %p type %s has no users", service, __connman_service_type2string(service->type)); -- cgit v1.2.3