[SPIN] implement to check blacklist for auto connection.
[platform/upstream/connman.git] / src / service.c
index db8953c..ed59930 100755 (executable)
@@ -156,6 +156,7 @@ struct connman_service {
         *              manage open/close connection requests by each application.
         */
        int user_pdn_connection_refcount;
+       bool storage_reload;
 #endif
 #if defined TIZEN_TV_EXT
        enum connman_dnsconfig_method dns_config_method;
@@ -327,6 +328,10 @@ enum connman_service_security __connman_service_string2security(const char *str)
                return CONNMAN_SERVICE_SECURITY_NONE;
        if (!strcmp(str, "wep"))
                return CONNMAN_SERVICE_SECURITY_WEP;
+#if defined TIZEN_EXT
+       if (!strcmp(str, "rsn"))
+               return CONNMAN_SERVICE_SECURITY_RSN;
+#endif
 
        return CONNMAN_SERVICE_SECURITY_UNKNOWN;
 }
@@ -342,8 +347,14 @@ static const char *security2string(enum connman_service_security security)
                return "wep";
        case CONNMAN_SERVICE_SECURITY_PSK:
        case CONNMAN_SERVICE_SECURITY_WPA:
+#if defined TIZEN_EXT
+               return "psk";
+       case CONNMAN_SERVICE_SECURITY_RSN:
+               return "rsn";
+#else
        case CONNMAN_SERVICE_SECURITY_RSN:
                return "psk";
+#endif
        case CONNMAN_SERVICE_SECURITY_8021X:
                return "ieee8021x";
        }
@@ -3377,7 +3388,9 @@ static int check_passphrase(enum connman_service_security security,
        case CONNMAN_SERVICE_SECURITY_UNKNOWN:
        case CONNMAN_SERVICE_SECURITY_NONE:
        case CONNMAN_SERVICE_SECURITY_WPA:
+#if !defined TIZEN_EXT
        case CONNMAN_SERVICE_SECURITY_RSN:
+#endif
 
                DBG("service security '%s' (%d) not handled",
                                security2string(security), security);
@@ -3385,6 +3398,9 @@ static int check_passphrase(enum connman_service_security security,
                return -EOPNOTSUPP;
 
        case CONNMAN_SERVICE_SECURITY_PSK:
+#if defined TIZEN_EXT
+       case CONNMAN_SERVICE_SECURITY_RSN:
+#endif
                /* A raw key is always 64 bytes length,
                 * its content is in hex representation.
                 * A PSK key must be between [8..63].
@@ -4182,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;
@@ -4308,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));
@@ -4706,6 +4752,24 @@ static DBusMessage *disconnect_service(DBusConnection *conn,
        return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
 }
 
+#if defined TIZEN_EXT
+static void __connman_service_cleanup_network_8021x(struct connman_service *service)
+{
+       if (service == NULL)
+               return;
+
+       DBG("service %p ", service);
+
+       connman_network_set_string(service->network, "WiFi.EAP", NULL);
+       connman_network_set_string(service->network, "WiFi.Identity", NULL);
+       connman_network_set_string(service->network, "WiFi.CACertFile", NULL);
+       connman_network_set_string(service->network, "WiFi.ClientCertFile", NULL);
+       connman_network_set_string(service->network, "WiFi.PrivateKeyFile", NULL);
+       connman_network_set_string(service->network, "WiFi.PrivateKeyPassphrase", NULL);
+       connman_network_set_string(service->network, "WiFi.Phase2", NULL);
+}
+#endif
+
 bool __connman_service_remove(struct connman_service *service)
 {
        if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET ||
@@ -4750,6 +4814,8 @@ bool __connman_service_remove(struct connman_service *service)
        g_free(service->phase2);
        service->phase2 = NULL;
 
+       __connman_service_cleanup_network_8021x(service);
+
        __connman_ipconfig_set_method(service->ipconfig_ipv4, CONNMAN_IPCONFIG_METHOD_DHCP);
        __connman_ipconfig_set_method(service->ipconfig_ipv6, CONNMAN_IPCONFIG_METHOD_AUTO);
        connman_service_set_proxy(service, NULL, false);
@@ -5150,6 +5216,10 @@ static void service_schedule_removed(struct connman_service *service)
 
 static bool allow_property_changed(struct connman_service *service)
 {
+#if defined TIZEN_EXT
+       if (service->path == NULL)
+               return FALSE;
+#endif
        if (g_hash_table_lookup_extended(services_notify->add, service->path,
                                        NULL, NULL)) {
                DBG("no property updates for service %p", service);
@@ -5329,6 +5399,7 @@ static void service_initialize(struct connman_service *service)
 
        service->wps = false;
 #if defined TIZEN_EXT
+       service->storage_reload = false;
        /*
         * Description: TIZEN implements system global connection management.
         */
@@ -5720,6 +5791,13 @@ int __connman_service_get_connected_count_of_iface(
 
        return count;
 }
+
+void __connman_service_set_storage_reload(struct connman_service *service,
+                                       bool storage_reload)
+{
+       if (service != NULL)
+               service->storage_reload = storage_reload;
+}
 #endif
 
 /**
@@ -6272,6 +6350,23 @@ static void single_connected_tech(struct connman_service *allowed)
        g_slist_free(services);
 }
 
+#if defined TIZEN_EXT
+static void set_priority_connected_service(void)
+{
+       struct connman_service *service;
+       GList *list;
+
+       for (list = service_list; list; list = list->next) {
+               service = list->data;
+
+               if (is_connected(service) == FALSE)
+                       service->order = 5;
+               else
+                       service->order = 6;
+       }
+}
+#endif
+
 static const char *get_dbus_sender(struct connman_service *service)
 {
        if (!service->pending)
@@ -6415,6 +6510,11 @@ static int service_indicate_state(struct connman_service *service)
                else if (service->type != CONNMAN_SERVICE_TYPE_VPN)
                        vpn_auto_connect();
 
+#if defined TIZEN_EXT
+               if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+                       set_priority_connected_service();
+#endif
+
                break;
 
        case CONNMAN_SERVICE_STATE_ONLINE:
@@ -6466,7 +6566,10 @@ static int service_indicate_state(struct connman_service *service)
                break;
 
        case CONNMAN_SERVICE_STATE_FAILURE:
-
+#if defined TIZEN_EXT
+               if (service->type == CONNMAN_SERVICE_TYPE_WIFI)
+                       service->order = 5;
+#endif
                if (service->connect_reason == CONNMAN_SERVICE_CONNECT_REASON_USER &&
                        connman_agent_report_error(service, service->path,
                                        error2string(service->error),
@@ -6529,6 +6632,18 @@ int __connman_service_indicate_error(struct connman_service *service,
 
        set_error(service, error);
 
+/* default internet service: fix not cleared if pdp activation*/
+#if defined TIZEN_EXT
+               /*
+                * If connection failed for default service(DefaultInternet),
+                * default_connecting_device should be cleared.
+                */
+               if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR &&
+                               service->error == CONNMAN_SERVICE_ERROR_CONNECT_FAILED)
+                       __connman_service_disconnect_default(service);
+
+#endif
+
        __connman_service_ipconfig_indicate_state(service,
                                                CONNMAN_SERVICE_STATE_FAILURE,
                                                CONNMAN_IPCONFIG_TYPE_IPV4);
@@ -7751,6 +7866,12 @@ static enum connman_service_security convert_wifi_security(const char *security)
                return CONNMAN_SERVICE_SECURITY_WPA;
        else if (g_str_equal(security, "rsn"))
                return CONNMAN_SERVICE_SECURITY_RSN;
+#if defined TIZEN_EXT
+       else if (g_str_equal(security, "ft_psk") == TRUE)
+               return CONNMAN_SERVICE_SECURITY_PSK;
+       else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
+               return CONNMAN_SERVICE_SECURITY_8021X;
+#endif
        else
                return CONNMAN_SERVICE_SECURITY_UNKNOWN;
 }
@@ -7964,6 +8085,13 @@ void __connman_service_update_from_network(struct connman_network *network)
        if (!service->network)
                return;
 
+#if defined TIZEN_EXT
+       if (service->storage_reload) {
+               service_load(service);
+               __connman_service_set_storage_reload(service, false);
+       }
+#endif
+
        name = connman_network_get_string(service->network, "Name");
        if (g_strcmp0(service->name, name) != 0) {
                g_free(service->name);