Add wifi_direct_foreach_supported_channel() API 36/238936/3 submit/tizen/20200804.230001
authorNishant Chaprana <n.chaprana@samsung.com>
Tue, 4 Aug 2020 04:57:17 +0000 (10:27 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Tue, 4 Aug 2020 04:57:17 +0000 (10:27 +0530)
This API is used to get channels which are supported by chipset.

Change-Id: I1efbd6aaca0d14801be543177889df031808cfa9
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
include/wifi-direct-internal.h
packaging/capi-network-wifi-direct.spec
src/wifi-direct-client-proxy.c

index 65ffb21..53c4174 100644 (file)
@@ -29,6 +29,18 @@ extern "C" {
 #endif
 
 /**
+ * @brief Called when you get the supported channels repeatedly.
+ * @since_tizen 6.0
+ * @param[in] channel       The supported channel
+ * @param[in] user_data  The user data passed from the request function
+ * @return @c true to continue with the next iteration of the loop, \n
+ *         @c false to break out of the loop
+ * @pre wifi_direct_foreach_supported_channel() will invoke this callback.
+ * @see wifi_direct_foreach_supported_channel()
+ */
+typedef bool(*wifi_direct_supported_channel_cb)(unsigned int channel, void *user_data);
+
+/**
  * @brief Rejects the connection request from other device now in progress.
  * @since_tizen 2.3
  * @privlevel public
@@ -69,6 +81,72 @@ int wifi_direct_reject_connection(char *mac_address);
  */
 int wifi_direct_accept_connection(char *mac_address);
 
+/**
+ * @brief Gets the list of supported channels
+ * @since_tizen 6.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/wifidirect
+ * @param[in] callback   The callback function which is invoked at success
+ * @param[in] user_data  The user data to be passed to the callback function
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #WIFI_DIRECT_ERROR_NONE                  Successful
+ * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED      Operation failed
+ * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED  Communication failed
+ * @retval #WIFI_DIRECT_ERROR_PERMISSION_DENIED     Permission denied
+ * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED         Operation not permitted
+ * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED         Not supported
+ * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED       Not initialized
+ * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY         Device or resource busy
+ * @pre Wi-Fi Direct service must be activated by wifi_direct_activate().
+ * @see wifi_direct_activate()
+ * @see wifi_direct_supported_channel_cb()
+ *
+ *
+ * Here is an example of the usage:
+ * @code
+ * #include <stdio.h>
+ * #include <wifi-direct.h>
+ * #include <wifi-direct-internal.h>
+ *
+ *
+ * bool callback(unsigned int channel, void *user_data)
+ * {
+ *     printf("Channel [%u] is supported\n", channel);
+ *     return true;
+ * }
+ *
+ * int function(void)
+ * {
+ *     int ret;
+ *
+ *     ret = wifi_direct_foreach_supported_channel(callback, NULL);
+ *
+ *     if (ret != WIFI_DIRECT_ERROR_NONE) {
+ *             printf("Failed to get supported channels\n");
+ *             return -1;
+ *     }
+ *
+ *     return 0;
+ * }
+ *
+ * int main()
+ * {
+ *     // Initialize Wi-Fi Direct.
+ *     // Activate Wi-Fi Direct.
+ *
+ *     function();
+ *
+ *     // App must clean up Wi-Fi Direct before exiting
+ *
+ *     // Deactivate Wi-Fi Direct
+ *     // Deinitialize Wi-Fi Direct
+ *     return 0;
+ * }
+ * @endcode
+ */
+int wifi_direct_foreach_supported_channel(wifi_direct_supported_channel_cb callback, void *user_data);
 
 #ifdef __cplusplus
 }
index 4f00068..723cda5 100755 (executable)
@@ -3,7 +3,7 @@
 
 Name:       capi-network-wifi-direct
 Summary:    Network WiFi-Direct Library
-Version:    1.3.1
+Version:    1.3.2
 Release:    1
 Group:      Network & Connectivity/API
 License:    Apache-2.0
index 475c0a4..dbe636c 100755 (executable)
@@ -2357,6 +2357,59 @@ EXPORT_API int wifi_direct_get_operating_channel(int *channel)
        return WIFI_DIRECT_ERROR_NONE;
 }
 
+int wifi_direct_foreach_supported_channel(wifi_direct_supported_channel_cb cb, void* user_data)
+{
+       __WDC_LOG_FUNC_START__;
+
+       CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
+
+       GError* error = NULL;
+       GVariant *reply = NULL;
+       GVariantIter *iter = NULL;
+       int ret = WIFI_DIRECT_ERROR_NONE;
+       unsigned int channel;
+
+       if (g_client_info.is_registered == false) {
+               WDC_LOGE("Client is NOT registered");
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
+       }
+
+       if (!cb) {
+               WDC_LOGE("NULL Param [callback]!");
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
+       }
+
+       reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
+                                         "GetSupportedChannels",
+                                         NULL,
+                                         &error);
+
+       ret = __net_wifidirect_gerror_to_enum(error);
+       if (ret != WIFI_DIRECT_ERROR_NONE)
+               return ret;
+
+       g_variant_get(reply, "(iau)", &ret, &iter);
+       if (ret != WIFI_DIRECT_ERROR_NONE) {
+               __WDC_LOG_FUNC_END__;
+               return WIFI_DIRECT_ERROR_OPERATION_FAILED;
+       }
+
+       WDC_LOGD("wifi_direct_foreach_supported_channel() SUCCESS");
+
+       while (g_variant_iter_loop(iter, "u", &channel)) {
+               if (!cb(channel, user_data))
+                       break;
+       }
+       g_variant_iter_free(iter);
+       g_variant_unref(reply);
+
+       WDC_LOGD("%s() return : [%d]", __func__, ret);
+       __WDC_LOG_FUNC_END__;
+       return ret;
+}
+
 EXPORT_API int wifi_direct_activate_pushbutton(void)
 {
        __WDC_LOG_FUNC_START__;