From 367dcbbeb392ee4071395f87e6d4eac53f09ff0d Mon Sep 17 00:00:00 2001 From: Saurav Babu Date: Fri, 31 Aug 2018 15:10:24 +0530 Subject: Online Check: Change default connection policy 1. Modified the priority of default connection 2. Disconnect the cellular when wifi state is online 3. Added a dbus-api for downgrading the wifi state to ready 4. Modified the connman_service_get_default_connection() Change-Id: Ie062d86479a9bc80919ba7d0c168028f61a9c7be Signed-off-by: Saurav Babu --- configure.ac | 7 ++++ packaging/connman.spec | 1 + src/service.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ src/wispr.c | 19 ++++++++++ 4 files changed, 127 insertions(+) diff --git a/configure.ac b/configure.ac index 3a569d4a..d1b76538 100644 --- a/configure.ac +++ b/configure.ac @@ -84,6 +84,13 @@ AC_ARG_ENABLE(tizen-ext-wifi-mesh, [CFLAGS="$CFLAGS -DTIZEN_EXT_WIFI_MESH"], [enable_tizen_ext_wifi_mesh="no"]) AM_CONDITIONAL(TIZEN_EXT_WIFI_MESH, test "${enable_tizen_ext_wifi_mesh}" != "no") +AC_ARG_ENABLE(tizen-maintain-online, + AC_HELP_STRING([--enable-tizen-maintain-online], [enable TIZEN extensions]), + [if (test "${enableval}" = "yes"); then + CFLAGS="$CFLAGS -DTIZEN_MAINTAIN_ONLINE" + LIBS="$LIBS -lsmack" + fi]) + AC_ARG_WITH(openconnect, AC_HELP_STRING([--with-openconnect=PROGRAM], [specify location of openconnect binary]), [path_openconnect=${withval}]) diff --git a/packaging/connman.spec b/packaging/connman.spec index fd69829f..609059e8 100644 --- a/packaging/connman.spec +++ b/packaging/connman.spec @@ -152,6 +152,7 @@ chmod +x bootstrap --sysconfdir=/etc \ --enable-client \ --enable-tizen-ext \ + --enable-tizen-maintain-online \ --enable-pacrunner \ --enable-wifi=builtin \ %if %{with connman_openconnect} diff --git a/src/service.c b/src/service.c index d13aafb6..bc081575 100644 --- a/src/service.c +++ b/src/service.c @@ -2175,8 +2175,13 @@ struct connman_service *connman_service_get_default_connection(void) state2string(service->state), __connman_service_type2string(service->type)); +#if defined TIZEN_MAINTAIN_ONLINE + if (service->type == CONNMAN_SERVICE_TYPE_WIFI && + service->state == CONNMAN_SERVICE_STATE_ONLINE) { +#else if (service->type == CONNMAN_SERVICE_TYPE_WIFI && is_connected(service->state) == TRUE) { +#endif return service; } else if (service->type == CONNMAN_SERVICE_TYPE_CELLULAR && __connman_service_is_internet_profile(service) == TRUE) { @@ -2202,6 +2207,9 @@ struct connman_service *connman_service_get_default_connection(void) struct connman_service *__connman_service_get_default(void) { +#if defined TIZEN_MAINTAIN_ONLINE + return connman_service_get_default_connection(); +#else struct connman_service *service; if (!service_list) @@ -2213,6 +2221,7 @@ struct connman_service *__connman_service_get_default(void) return NULL; return service; +#endif } bool __connman_service_index_is_default(int index) @@ -6053,6 +6062,19 @@ static DBusMessage *get_user_favorite(DBusConnection *conn, return reply; } +#if defined TIZEN_MAINTAIN_ONLINE +static DBusMessage *downgrade_service(DBusConnection *conn, + DBusMessage *msg, void *user_data) +{ + struct connman_service *service = user_data; + + downgrade_state(service); + __connman_connection_update_gateway(); + + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); +} +#endif + static struct _services_notify { int id; GHashTable *add; @@ -6205,6 +6227,9 @@ static const GDBusMethodTable service_methods[] = { { GDBUS_METHOD("GetUserFavorite", NULL, GDBUS_ARGS({ "value", "v" }), get_user_favorite) }, +#if defined TIZEN_MAINTAIN_ONLINE + { GDBUS_METHOD("Downgrade", NULL, NULL, downgrade_service) }, +#endif { }, }; @@ -7162,7 +7187,12 @@ static void __connman_service_disconnect_default(struct connman_service *service default_connecting_device = NULL; } +#if defined TIZEN_MAINTAIN_ONLINE +static void __connman_service_connect_default(struct connman_service *current, + enum connman_service_state old_state) +#else static void __connman_service_connect_default(struct connman_service *current) +#endif { int err; GList *list; @@ -7199,6 +7229,11 @@ static void __connman_service_connect_default(struct connman_service *current) } return; +#if defined TIZEN_MAINTAIN_ONLINE + } else if (current->state == CONNMAN_SERVICE_STATE_READY && + old_state == CONNMAN_SERVICE_STATE_ONLINE) { + DBG("Device is downgraded: online --> ready"); +#endif } else if (is_connected(current->state) == TRUE || is_connecting(current->state) == TRUE) return; @@ -7302,7 +7337,19 @@ static void set_priority_connected_service(void) if (is_connected(service->state) == FALSE) service->order = 5; else +#if defined TIZEN_MAINTAIN_ONLINE + { + if (service->type == CONNMAN_SERVICE_TYPE_WIFI && + service->state == CONNMAN_SERVICE_STATE_ONLINE) + service->order = 6; + else if (service->type != CONNMAN_SERVICE_TYPE_WIFI) + service->order = 6; + else + service->order = 5; + } +#else service->order = 6; +#endif } } #endif @@ -7445,10 +7492,15 @@ static int service_indicate_state(struct connman_service *service) __connman_ipconfig_disable_ipv6( service->ipconfig_ipv6); +#if !defined TIZEN_MAINTAIN_ONLINE if (connman_setting_get_bool("SingleConnectedTechnology")) single_connected_tech(service); else if (service->type != CONNMAN_SERVICE_TYPE_VPN) vpn_auto_connect(); +#else + if (service->type != CONNMAN_SERVICE_TYPE_VPN) + vpn_auto_connect(); +#endif #if defined TIZEN_EXT if (service->type == CONNMAN_SERVICE_TYPE_WIFI) @@ -7458,6 +7510,15 @@ static int service_indicate_state(struct connman_service *service) break; case CONNMAN_SERVICE_STATE_ONLINE: +#if defined TIZEN_MAINTAIN_ONLINE +#if defined TIZEN_EXT + if (service->type == CONNMAN_SERVICE_TYPE_WIFI) + set_priority_connected_service(); +#endif + + if (connman_setting_get_bool("SingleConnectedTechnology")) + single_connected_tech(service); +#endif break; @@ -7527,7 +7588,11 @@ static int service_indicate_state(struct connman_service *service) service_list_sort(); #if defined TIZEN_EXT +#if defined TIZEN_MAINTAIN_ONLINE + __connman_service_connect_default(service, old_state); +#else __connman_service_connect_default(service); +#endif #endif __connman_connection_update_gateway(); @@ -7771,12 +7836,35 @@ static gboolean redo_wispr(gpointer user_data) return FALSE; } +#if defined TIZEN_MAINTAIN_ONLINE +static gboolean redo_wispr_ipv4(gpointer user_data) +{ + struct connman_service *service = user_data; + + DBG(""); + + __connman_wispr_start(service, CONNMAN_IPCONFIG_TYPE_IPV4); + + return FALSE; +} +#endif + int __connman_service_online_check_failed(struct connman_service *service, enum connman_ipconfig_type type) { DBG("service %p type %d count %d", service, type, service->online_check_count); +#if defined TIZEN_MAINTAIN_ONLINE + /* Retry IPv4 stuff also */ + if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { + connman_warn("Online check failed for %p %s", service, + service->name); + + g_timeout_add_seconds(1, redo_wispr_ipv4, service); + return 0; + } +#else /* currently we only retry IPv6 stuff */ if (type == CONNMAN_IPCONFIG_TYPE_IPV4 || service->online_check_count != 1) { @@ -7784,6 +7872,7 @@ int __connman_service_online_check_failed(struct connman_service *service, service->name); return 0; } +#endif service->online_check_count = 0; @@ -7891,6 +7980,10 @@ int __connman_service_ipconfig_indicate_state(struct connman_service *service, if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { #if !defined TIZEN_EXT check_proxy_setup(service); +#endif +#if defined TIZEN_MAINTAIN_ONLINE +/* if (old_state == CONNMAN_SERVICE_STATE_ONLINE) */ + check_proxy_setup(service); #endif } else { service->online_check_count = 1; @@ -8838,8 +8931,15 @@ unsigned int __connman_service_get_order(struct connman_service *service) service->do_split_routing == FALSE) order = 10; else if (service->type == CONNMAN_SERVICE_TYPE_WIFI) { +#if defined TIZEN_MAINTAIN_ONLINE + if (service->state != CONNMAN_SERVICE_STATE_ONLINE) + service->order = 0; + else if (service->order < 5) + service->order = 5; +#else if (service->order < 5) order = 5; +#endif } else if (service->type == CONNMAN_SERVICE_TYPE_ETHERNET) order = 4; else if (service->type == CONNMAN_SERVICE_TYPE_BLUETOOTH) diff --git a/src/wispr.c b/src/wispr.c index a2df55a0..f5fe36b4 100644 --- a/src/wispr.c +++ b/src/wispr.c @@ -688,6 +688,9 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data) const char *str = NULL; guint16 status; gsize length; +#if defined TIZEN_MAINTAIN_ONLINE + static int retried = 0; +#endif DBG(""); @@ -719,6 +722,9 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data) wp_context->status_url, wp_context); break; case 200: +#if defined TIZEN_MAINTAIN_ONLINE + retried = 0; +#endif if (wp_context->wispr_msg.message_type >= 0) break; @@ -756,6 +762,19 @@ static bool wispr_portal_web_result(GWebResult *result, gpointer user_data) case 404: if (__connman_service_online_check_failed(wp_context->service, wp_context->type) == 0) { +#if defined TIZEN_MAINTAIN_ONLINE + if (wp_context->type == CONNMAN_IPCONFIG_TYPE_IPV4) { + if (retried == 0) { + connman_agent_report_error(wp_context->service, + __connman_service_get_path(wp_context->service), + "internet-unreachable", + NULL, NULL, NULL); + + retried = 1; + } + break; + } +#endif wispr_portal_error(wp_context); free_connman_wispr_portal_context(wp_context); return false; -- cgit v1.2.3