Added API to get client connect info. 75/242175/10 accepted/tizen/unified/20200903.151717 submit/tizen/20200828.142119 submit/tizen/20200901.053326 submit/tizen/20200902.111409 submit/tizen/20200903.044940
authorPrasadam Prashath Kumar <prasadam.p@samsung.com>
Mon, 24 Aug 2020 17:36:38 +0000 (23:06 +0530)
committerPrasadam Prashath Kumar <prasadam.p@samsung.com>
Fri, 28 Aug 2020 11:48:25 +0000 (17:18 +0530)
Change-Id: Iacffe2ea51d1f2f9f02817be2a2bab4421123f9f
Signed-off-by: Prasadam Prashath Kumar <prasadam.p@samsung.com>
include/tethering.h
include/tethering_private.h
src/tethering.c
src/tethering_client.c
tools/tethering_test.c

index 102a90593592338763fb5226c94380cde3022493..a8cf64e84060ff3be592b01efa1d57248b9d9ca1 100644 (file)
@@ -70,6 +70,10 @@ typedef enum {
     TETHERING_TYPE_MAX,  /**< Maximum */
 } tethering_type_e;
 
+typedef enum {
+    TETHERING_WIFI_BAND_2G = 0,
+    TETHERING_WIFI_BAND_5G,
+} tethering_band_e;
 /**
  * @brief Enumeration for the cause of disabling the tethering.
  * @since_tizen 2.3
@@ -510,6 +514,19 @@ int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb call
  */
 int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data);
 
+/**
+ * @brief Gets the clients which are connected.
+ * @since_tizen 6.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/tethering.admin
+ * @param[in]  tethering  The tethering handle
+ * @param[in]  type  The tethering type
+ * @retval  #TETHERING_ERROR_NONE  Successful
+ * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #TETHERING_ERROR_OPERATION_FAILED  Operation failed
+ */
+int tethering_is_dualband_supported(tethering_h tethering, tethering_type_e type, bool *supported);
+
 /**
  * @brief Registers the callback function, which is called when tethering is enabled.
  * @since_tizen 2.3
@@ -1458,6 +1475,22 @@ int tethering_client_destroy(tethering_client_h client);
  */
 int tethering_client_get_tethering_type(tethering_client_h client, tethering_type_e *type);
 
+/**
+ * @brief  Gets the tethering band of client.
+ * @since_tizen 6.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/tethering.admin
+ * @param[in]  client  The handle of client
+ * @param[out]  band  The band of tethering
+ * @return  0 on success, otherwise a negative error value.
+ * @retval  #TETHERING_ERROR_NONE  Successful
+ * @retval  #TETHERING_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @see  tethering_usb_get_connected_client()
+ * @see  tethering_connection_state_changed_cb()
+ */
+int tethering_client_get_tethering_band(tethering_client_h client, tethering_band_e *band);
+
+
 /**
  * @brief Gets the name of a client.
  * @since_tizen 2.3
index 6e685deb3f7035b8b87ddd9e6df2637bf9d11e1d..d7bca369f20d8c80cc4deff4a9350ea6f2b2d987 100644 (file)
@@ -311,6 +311,7 @@ typedef struct {
        char mac[TETHERING_STR_INFO_LEN];               /**< MAC Address */
        char *hostname;
        time_t tm;      /**< connection time */
+       tethering_band_e band;                  /**< wifi band type */
 } __tethering_client_h;
 
 typedef struct {
index 4ef8036199d1bcad470100ab196f3ca4654cede7..84a18e759bfb41a0284cfce695c9e57958e0b997 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)
@@ -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);
index efde31e27ac846c0bcf6e9eba33e9b70e41d908d..ffbd8824e759d59bca3a87eb0b828bf0158ea8f2 100755 (executable)
@@ -85,6 +85,22 @@ API int tethering_client_get_tethering_type(tethering_client_h client, tethering
        return TETHERING_ERROR_NONE;
 }
 
+API int tethering_client_get_tethering_band(tethering_client_h client, tethering_band_e *band)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+
+       _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "Parameter(client) is NULL\n");
+       _retvm_if(band == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "Parameter(band) is NULL\n");
+
+       __tethering_client_h *si = (__tethering_client_h *)client;
+
+       *band = si->band;
+
+       return TETHERING_ERROR_NONE;
+}
+
 API int tethering_client_get_name(tethering_client_h client, char **name)
 {
        CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
index 66ae65e77b49e52f5d59e18759633dbefb58b80c..8c4b16b62063934b2850a43dee55b29e2a526f3d 100755 (executable)
@@ -110,6 +110,18 @@ static bool test_get_user_string(const char *msg, char *buf, int buf_size)
        return true;
 }
 
+static const char *__convert_tethering_band_to_str(const tethering_band_e band)
+{
+       static char str_buf[COMMON_STR_BUF_LEN] = {0, };
+
+       if (band == TETHERING_WIFI_BAND_2G)
+               g_strlcpy(str_buf, "2.4GHz Band", sizeof(str_buf));
+       else
+               g_strlcpy(str_buf, "5.0GHz Band", sizeof(str_buf));
+
+       return str_buf;
+}
+
 static const char *__convert_tethering_type_to_str(const tethering_type_e type)
 {
        static char str_buf[COMMON_STR_BUF_LEN] = {0, };
@@ -380,6 +392,7 @@ static bool __clients_foreach_cb(tethering_client_h client, void *data)
        char *ip_address = NULL;
        char *mac_address = NULL;
        char *hostname = NULL;
+       tethering_band_e band;
 
        /* Clone internal information */
        if (tethering_client_clone(&clone, client) != TETHERING_ERROR_NONE) {
@@ -400,6 +413,9 @@ static bool __clients_foreach_cb(tethering_client_h client, void *data)
        if (tethering_client_get_name(clone, &hostname) != TETHERING_ERROR_NONE)
                g_print("tethering_client_get_hostname is failed\n");
 
+       if (tethering_client_get_tethering_band(clone, &band) != TETHERING_ERROR_NONE)
+               g_print("tethering_client_get_type is failed\n");
+
        /* End of getting information */
 
        g_print("\n< Client Info. >\n");
@@ -407,6 +423,7 @@ static bool __clients_foreach_cb(tethering_client_h client, void *data)
        g_print("\tIP Address %s\n", ip_address);
        g_print("\tMAC Address : %s\n", mac_address);
        g_print("\tHostname : %s\n", hostname);
+       g_print("\tBand : %s\n",  __convert_tethering_band_to_str(band));
 
        /* Destroy cloned objects */
        if (ip_address)
@@ -776,6 +793,31 @@ static int test_tethering_disable(void)
        return 1;
 }
 
+static int test_tethering_is_dualband_supported(void)
+{
+       int ret;
+       tethering_type_e type;
+       tethering_h handle = th;
+       bool band_supported = FALSE;
+
+       if (!__get_tethering_type(&type))
+               return -1;
+
+       if (type != TETHERING_TYPE_WIFI)
+               return -1;
+
+       ret = tethering_is_dualband_supported(handle, type, &band_supported);
+
+       if (__is_err(ret) == true) {
+               printf("Fail to get is dubalband supported\n");
+               return -1;
+       } else {
+               printf("DualBand is %s\n", band_supported ? "Supported" : "Not Supported");
+       }
+
+       return 1;
+
+}
 static int test_tethering_get_client_info(void)
 {
        int ret;
@@ -1435,11 +1477,6 @@ static int test_tethering_wifi_set_wps_pin(void)
        return 1;
 }
 
-static int test_tethering_wifi_is_dualband_supported(void)
-{
-       return 1;
-}
-
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -1511,7 +1548,6 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("G       - Push WPS button\n");
                printf("H       - Set WPS PIN\n");
                printf("I       - Is Wi-Fi dualband supported \n");
-               printf("J       - Set Wi-Fi dualband  \n");
                printf("0       - \n");
                printf("ENTER  - Show options menu.......\n");
        }
@@ -1632,7 +1668,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                rv = test_tethering_wifi_set_wps_pin();
                break;
        case 'I':
-               rv = test_tethering_wifi_is_dualband_supported();
+               rv = test_tethering_is_dualband_supported();
                break;
        }