Fix typo
[platform/core/api/tethering.git] / src / tethering.c
index cd44ae7..701cd73 100755 (executable)
 #define FILTERING_MULTIPORT_RULE_STR    "-t %s -A %s -p %s -m multiport --dport %d,%d -j %s"
 #define FILTERING_RULE_STR  "-t %s -A %s -p %s --dport %d -j %s"
 
+typedef enum {
+       DUAL_BAND_NONE = 0,                     //0
+       DUAL_BAND_2G = 1 << 0,                  //1
+       DUAL_BAND_5G = 1 << 1,                  //2
+       DUAL_BAND_MIN_INTERFACE = 1 << 2,       //4
+       DUAL_BAND_ALL = 7,                      //7
+} supported_band_e;
+
 static GSList *allowed_list = NULL;
 static GSList *blocked_list = NULL;
 static GSList *port_forwarding = NULL;
@@ -135,8 +143,24 @@ static __tethering_sig_t sigs[] = {
        {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp} };
 
 static int retry = 0;
+static int is_dualband_support = DUAL_BAND_NONE;
 static __thread tethering_request_table_t request_table[TETHERING_TYPE_MAX];
 
+static void  __reset_dualband_support(void)
+{
+       is_dualband_support = DUAL_BAND_NONE;
+}
+
+static void  __set_dualband_support(int band)
+{
+       is_dualband_support |= band;
+       return;
+}
+
+static gboolean  __is_dualband_support(void)
+{
+       return (is_dualband_support ==  DUAL_BAND_ALL) ? TRUE : FALSE;
+}
 static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
 {
        if (conn == NULL || signal_name == NULL)
@@ -1800,7 +1824,7 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type)
                        request_table[TETHERING_TYPE_WIFI_SHARING].flag = true;
                } else {
                        g_strlcpy(key, "wifi_tether", TETHERING_WIFI_KEY_MAX_LEN);
-                       request_table[TETHERING_TYPE_WIFI_SHARING].flag = true;
+                       request_table[TETHERING_TYPE_WIFI].flag = true;
                }
 
                g_dbus_proxy_call(proxy, "enable_wifi_tethering",
@@ -1946,7 +1970,7 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type)
                SINFO("Disable Wi-Fi Tethering !");
 
                g_dbus_proxy_call(proxy, "disable_wifi_tethering",
-                               g_variant_new("(i)", TETHERING_ADDRESS_FAMILY_IPV4),
+                               g_variant_new("(ii)", TETHERING_ADDRESS_FAMILY_IPV4, th->mode_type),
                                G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable,
                                (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering);
                break;
@@ -2378,6 +2402,73 @@ API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb
  * @see  tethering_is_enabled()
  * @see  tethering_enable()
  */
+
+API int tethering_is_dualband_supported(tethering_h tethering, tethering_type_e type, bool *supported)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+       if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING)
+               CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+
+       __tethering_h *th = (__tethering_h *)tethering;
+       gchar *if_name = NULL;
+       gboolean Is2GBandSupported = FALSE;
+       gboolean Is5GBandSupported = FALSE;
+       GError *error = NULL;
+       GVariant *result = NULL;
+       GVariantIter *outer_iter = NULL;
+       GVariantIter *inner_iter = NULL;
+       GVariant *station = NULL;
+       GVariant *value = NULL;
+       gchar *key = NULL;
+       int count = 0;
+
+       DBG("+");
+       __reset_dualband_support();
+       result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_wifi_interfaces",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+               g_error_free(error);
+               return TETHERING_ERROR_OPERATION_FAILED;
+       }
+       g_variant_get(result, "(a(a{sv}))", &outer_iter);
+       while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
+               g_variant_get(station, "a{sv}", &inner_iter);
+               while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
+                       if (g_strcmp0(key, "IfName") == 0) {
+                               g_variant_get(value, "s", &if_name);
+                               SDBG("Interface Name is %s\n", if_name);
+                       } else if (g_strcmp0(key, "Is2GBandSupported") == 0) {
+                               Is2GBandSupported = g_variant_get_boolean(value);
+                               SDBG("Is2GBandSupported  is %d\n", Is2GBandSupported);
+                               if (Is2GBandSupported)
+                                       __set_dualband_support(DUAL_BAND_2G);
+                       } else if (g_strcmp0(key, "Is5GBandSupported") == 0) {
+                               Is5GBandSupported = g_variant_get_boolean(value);
+                               SDBG("Is5GBandSupported  is %d\n", Is5GBandSupported);
+                               if (Is5GBandSupported)
+                                       __set_dualband_support(DUAL_BAND_5G);
+                       } else {
+                               ERR("Key %s not required\n", key);
+                       }
+               }
+               count++;
+
+               g_variant_iter_free(inner_iter);
+       }
+       if (count >= 2)
+               __set_dualband_support(DUAL_BAND_MIN_INTERFACE);
+       *supported =  __is_dualband_support();
+       DBG("count:%d is dualband suppport: %d", count, *supported);
+       g_variant_iter_free(outer_iter);
+       g_variant_unref(result);
+       DBG("-\n");
+       return TETHERING_ERROR_NONE;
+}
 API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data)
 {
        CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
@@ -2395,6 +2486,7 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                        "tethering is not enabled\n");
 
        mobile_ap_type_e interface;
+       tethering_band_e band;
        __tethering_h *th = (__tethering_h *)tethering;
        __tethering_client_h client = {0, };
        gchar *ip = NULL;
@@ -2466,6 +2558,10 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                                timestamp = g_variant_get_int32(value);
                                DBG("timestamp is %d\n", timestamp);
                                client.tm = (time_t)timestamp;
+                       } else if (g_strcmp0(key, "Band") == 0) {
+                               band = g_variant_get_int32(value);
+                               client.band = (!band) ? TETHERING_WIFI_BAND_2G : TETHERING_WIFI_BAND_5G;
+                               SDBG("band type %d\n", band);
                        } else {
                                ERR("Key %s not required\n", key);
                        }
@@ -2479,6 +2575,11 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ
                mac = NULL;
 
                g_variant_iter_free(inner_iter);
+               if ((th->mode_type == 0 || th->mode_type == 1) && client.band != TETHERING_WIFI_BAND_2G) //if band is not for 2g continue
+                       continue;
+               if ((th->mode_type == 2 || th->mode_type == 3) && client.band != TETHERING_WIFI_BAND_5G) //if band is not for 5g continue
+                       continue;
+               SDBG("mode_type: %d and client.band: %d ", th->mode_type, client.band);
                if (callback((tethering_client_h)&client, user_data) == false) {
                        DBG("iteration is stopped\n");
                        g_free(client.hostname);