[wifi-manager] Added CAPI to get WiFi VSIE list. 15/142615/8
authorNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 4 Aug 2017 14:29:50 +0000 (19:59 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Wed, 9 Aug 2017 04:33:01 +0000 (10:03 +0530)
Change-Id: I267fc859cdea72d925c58009dd02776016622cd4
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/network_dbus.h
include/network_interface.h
include/wifi_internal.h
include/wifi_manager_extension.h
src/network_dbus.c
src/network_interface.c
src/wifi_internal.c
src/wifi_manager.c

index ecd4ae2..f2cc15b 100755 (executable)
@@ -146,6 +146,7 @@ int _net_dbus_get_autoscan(gboolean *autoscan);
 int _net_dbus_add_vsie(unsigned int frame_id, const char *vsie_str);
 int _net_dbus_get_vsie(unsigned int frame_id, char **vsie_str);
 int _net_dbus_remove_vsie(unsigned int frame_id, const char *vsie_str);
+int _net_dbus_get_vsie_list(GSList **vsie_list);
 
 #ifdef __cplusplus
 }
index 28f248a..0979f1d 100755 (executable)
@@ -218,6 +218,11 @@ typedef struct {
        net_wifi_eap_auth_type_e eap_auth_type;
 } net_eap_config_s;
 
+typedef struct {
+       char *elem;     //vendor element
+       int length;     //size of vendor element
+} net_vsie_data_s;
+
 typedef void (*net_event_cb)(const net_event_info_s* net_event, void* user_data);
 
 int net_register_client_ext(net_event_cb event_cb, void *user_data);
@@ -248,6 +253,7 @@ int net_wifi_get_scan_state(int *scan_state);
 int net_wifi_add_vsie(unsigned int frame_id, const char *vsie_str);
 int net_wifi_get_vsie(unsigned int frame_id, char **vsie_str);
 int net_wifi_remove_vsie(unsigned int frame_id, const char *vsie_str);
+int net_wifi_get_vsie_list(GSList **vsie_list);
 
 int net_wifi_cancel_wps(void);
 
index bb711ed..04cd835 100755 (executable)
@@ -268,6 +268,7 @@ int _wifi_get_vsie(wifi_manager_h wifi,
                wifi_manager_vsie_frames_e frame_id, char **vsie_str);
 int _wifi_remove_vsie(wifi_manager_h wifi,
                wifi_manager_vsie_frames_e frame_id, const char *vsie_str);
+int _wifi_get_vsie_list(wifi_manager_vsie_list_cb callback, void *user_data);
 
 /* WIFI Privilege Check */
 int _wifi_check_get_privilege();
index e0cd41a..75fe71c 100755 (executable)
@@ -92,6 +92,18 @@ typedef enum {
 */
 
 /**
+ * @brief Called when you get the vsie repeatedly.
+ * @since_tizen 4.0
+ * @param[in] vsie The vsie data
+ * @param[in] length The length of vsie data
+ * @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
+ *ยป           otherwise @c false to break out of the loop
+ * @see wifi_manager_get_vsie_list()
+ */
+typedef bool(*wifi_manager_vsie_list_cb)(char* vsie, int length, void* user_data);
+
+/**
  * @brief Enables or disables auto-scanning
  * @details If auto-scanning is disabled, then background scan and wps scan don't work.
  * By default, the auto-scanning is enabled automatically until disabling auto-scanning.
@@ -240,6 +252,25 @@ int wifi_manager_remove_vsie(wifi_manager_h wifi,
                wifi_manager_vsie_frames_e frame_id, const char *vsie_str);
 
 /**
+ * @brief Gets the vsie result of the scan.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege http://tizen.org/privilege/network.get
+ * @param[in] wifi                The wifi handle
+ * @param[in] callback  The callback to be called
+ * @param[in] user_data The user data passed to the callback function
+ * @return 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED     Operation failed
+ * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED    Permission Denied
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Not supported
+ * @post This function invokes wifi_manager_vsie_list_cb().
+ */
+int wifi_manager_get_vsie_list(wifi_manager_h wifi,
+               wifi_manager_vsie_list_cb callback, void *user_data);
+
+/**
 * @}
 */
 
index 8950d3d..673d4b4 100755 (executable)
@@ -1906,6 +1906,91 @@ int _net_dbus_remove_vsie(unsigned int frame_id, const char *vsie_str)
        return Error;
 }
 
+static int _net_get_vsies(GVariant *msg, GSList **vsie_list)
+{
+       WIFI_LOG(WIFI_INFO, "Extract vsie data");
+
+       GVariant *var;
+       GVariantIter *iter, *next;
+       char *obj;
+       gchar *key;
+
+       g_variant_get(msg, "(a(oa{sv}))", &iter);
+       while (g_variant_iter_loop(iter, "(oa{sv})", &obj, &next)) {
+               if (obj == NULL || g_str_has_prefix(obj, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == false)
+                       continue;
+
+               while (g_variant_iter_loop(next, "{sv}", &key, &var)) {
+                       if (g_strcmp0(key, "Vsie") == 0) {
+                               const char *vsie = NULL;
+                               net_vsie_data_s *vendor_data;
+                               gsize vsie_len;
+                               int i;
+
+                               vsie = g_variant_get_fixed_array(var, &vsie_len, sizeof(guchar));
+
+                               if (vsie) {
+                                       vendor_data = (net_vsie_data_s*)g_try_malloc0(sizeof(net_vsie_data_s));
+                                       if (vendor_data) {
+                                               vendor_data->length = vsie_len;
+                                               vendor_data->elem = (char *)g_try_malloc0(vsie_len);
+                                               if (vendor_data->elem)
+                                                       memcpy(vendor_data->elem, vsie, vsie_len);
+                                               else {
+                                                       WIFI_LOG(WIFI_ERROR, "Failed to allocate memory");
+                                                       g_free(vendor_data);
+                                                       g_free(obj);
+                                                       g_free(key);
+                                                       g_free(var);
+                                                       g_variant_iter_free(next);
+                                                       g_variant_iter_free(iter);
+                                                       return -1;
+                                               }
+
+                                               WIFI_LOG(WIFI_INFO, "VSIE Len: %d", vendor_data->length);
+                                               for (i = 0; i < vsie_len; i++)
+                                                       WIFI_LOG(WIFI_INFO, "vendor elem: %02x", vendor_data->elem[i]);
+
+                                               *vsie_list = g_slist_append(*vsie_list, (void *)vendor_data);
+                                       }
+                               }
+                       }
+               }
+       }
+       g_variant_iter_free(iter);
+
+       return NET_ERR_NONE;
+}
+
+int _net_dbus_get_vsie_list(GSList **vsie_list)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+       GVariant *message = NULL;
+
+       message = _net_invoke_dbus_method(
+                       CONNMAN_SERVICE,
+                       CONNMAN_MANAGER_PATH,
+                       CONNMAN_MANAGER_INTERFACE,
+                       "GetVsies",
+                       NULL,
+                       &Error);
+
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get vsie info");
+               __NETWORK_FUNC_EXIT__;
+               return Error;
+       }
+
+       Error = _net_get_vsies(message, vsie_list);
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 static void __net_wps_cancel_reply(GObject *source_object,
                GAsyncResult *res, gpointer user_data)
 {
index 3f672ed..18340b2 100755 (executable)
@@ -1593,7 +1593,7 @@ int net_wifi_get_vsie(unsigned int frame_id, char **vsie_str)
        Error = _net_dbus_get_vsie(frame_id, vsie_str);
        if (Error != NET_ERR_NONE) {
                WIFI_LOG(WIFI_ERROR,
-                               "_net_dbus_add_vsie() failed. Error [%s]",
+                               "_net_dbus_get_vsie() failed. Error [%s]",
                                _net_print_error(Error));
        }
 
@@ -1630,7 +1630,7 @@ int net_wifi_remove_vsie(unsigned int frame_id, const char *vsie_str)
        Error = _net_dbus_remove_vsie(frame_id, vsie_str);
        if (Error != NET_ERR_NONE) {
                WIFI_LOG(WIFI_ERROR,
-                               "_net_dbus_add_vsie() failed. Error [%s]",
+                               "_net_dbus_remove_vsie() failed. Error [%s]",
                                _net_print_error(Error));
        }
 
@@ -1638,6 +1638,43 @@ int net_wifi_remove_vsie(unsigned int frame_id, const char *vsie_str)
        return Error;
 }
 
+int net_wifi_get_vsie_list(GSList **vsie_list)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e Error = NET_ERR_NONE;
+
+       if (NetworkInfo.ref_count < 1) {
+               WIFI_LOG(WIFI_ERROR, "Application is not registered");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_APP_NOT_REGISTERED;
+       }
+
+       if (NetworkInfo.wifi_state == WIFI_OFF) {
+               if ((NetworkInfo.wifi_state = _net_get_wifi_state(&Error)) == WIFI_OFF) {
+                       WIFI_LOG(WIFI_ERROR, "Wi-Fi is powered off!");
+                       __NETWORK_FUNC_EXIT__;
+                       return NET_ERR_INVALID_OPERATION;
+               }
+       }
+
+       if (_net_dbus_is_pending_call_used() == TRUE) {
+               WIFI_LOG(WIFI_ERROR, "pending call in progress");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_INVALID_OPERATION;
+       }
+
+       Error = _net_dbus_get_vsie_list(vsie_list);
+       if (Error != NET_ERR_NONE) {
+               WIFI_LOG(WIFI_ERROR,
+                       "_net_dbus_get_vsie_list failed. Error [%s]",
+                       _net_print_error(Error));
+       }
+
+       __NETWORK_FUNC_EXIT__;
+       return Error;
+}
+
 int net_open_connection_with_wifi_info(const net_wifi_connection_info_s *wifi_info)
 {
        __NETWORK_FUNC_ENTER__;
index 42020c9..171a8f6 100755 (executable)
@@ -1657,6 +1657,40 @@ int _wifi_remove_vsie(wifi_manager_h wifi,
        return WIFI_MANAGER_ERROR_OPERATION_FAILED;
 }
 
+int _wifi_get_vsie_list(wifi_manager_vsie_list_cb callback, void *user_data)
+{
+       int rv;
+       GSList *vsie_list = NULL;
+
+       rv = net_wifi_get_vsie_list(&vsie_list);
+
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               WIFI_LOG(WIFI_ERROR, "Access denied");
+               return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
+       } else if (rv == NET_ERR_INVALID_OPERATION) {
+               WIFI_LOG(WIFI_ERROR, "Invalid Operation");
+               return WIFI_MANAGER_ERROR_INVALID_OPERATION;
+       } else if (rv == NET_ERR_NONE) {
+               WIFI_LOG(WIFI_ERROR, "Error None");
+               GSList *list;
+               int ret;
+               for (list = vsie_list; list; list = list->next) {
+                       ret = callback((char *)((net_vsie_data_s *)list->data)->elem,
+                                       ((net_vsie_data_s *)list->data)->length, user_data);
+                       if (ret == false)
+                               break;
+               }
+
+               g_slist_free_full(vsie_list, g_free);
+               vsie_list = NULL;
+
+               return WIFI_MANAGER_ERROR_NONE;
+       }
+
+       WIFI_LOG(WIFI_ERROR, "Operation Failed");
+       return WIFI_MANAGER_ERROR_OPERATION_FAILED;
+}
+
 int _wifi_get_connected_profile(wifi_manager_ap_h *ap)
 {
        int rv;
index b8fe07b..2f590a2 100755 (executable)
@@ -996,3 +996,17 @@ EXPORT_API int wifi_manager_remove_vsie(wifi_manager_h wifi,
 
        return _wifi_remove_vsie(wifi, frame_id, vsie_str);
 }
+
+EXPORT_API int wifi_manager_get_vsie_list(wifi_manager_h wifi,
+                       wifi_manager_vsie_list_cb callback, void *user_data)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       WIFI_LOG(WIFI_INFO,  "WiFi get vsies\n");
+       if (callback == NULL || !(__wifi_check_handle_validity(wifi))) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter");
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+       }
+
+       return _wifi_get_vsie_list(callback, user_data);
+}