[SPIN] implement to check blacklist for auto connection.
[platform/upstream/connman.git] / src / service.c
index ca32698..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;
@@ -1906,8 +1907,10 @@ static void state_changed(struct connman_service *service)
        if (!str)
                return;
 
+#if !defined TIZEN_EXT
        if (!allow_property_changed(service))
                return;
+#endif
 
        connman_dbus_property_changed_basic(service->path,
                                CONNMAN_SERVICE_INTERFACE, "State",
@@ -2726,11 +2729,13 @@ static void append_wifi_ext_info(DBusMessageIter *dict,
        unsigned int maxrate;
        uint16_t frequency;
        const char *enc_mode;
+       gboolean passpoint;
 
        bssid = connman_network_get_bssid(network);
        maxrate = connman_network_get_maxrate(network);
        frequency = connman_network_get_frequency(network);
        enc_mode = connman_network_get_enc_mode(network);
+       passpoint = connman_network_get_is_hs20AP(network);
 
        snprintf(bssid_str, WIFI_BSSID_STR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x",
                                bssid[0], bssid[1], bssid[2],
@@ -2744,6 +2749,8 @@ static void append_wifi_ext_info(DBusMessageIter *dict,
                                        DBUS_TYPE_UINT16, &frequency);
        connman_dbus_dict_append_basic(dict, "EncryptionMode",
                                        DBUS_TYPE_STRING, &enc_mode);
+       connman_dbus_dict_append_basic(dict, "Passpoint",
+                                       DBUS_TYPE_BOOLEAN, &passpoint);
 }
 #endif
 
@@ -4191,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;
@@ -4317,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));
@@ -4715,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 ||
@@ -4759,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);
@@ -5159,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);
@@ -5338,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.
         */
@@ -5729,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
 
 /**
@@ -6281,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)
@@ -6424,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:
@@ -6475,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),
@@ -6538,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);
@@ -7760,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;
 }
@@ -7973,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);