Added CAPI to receive each vsie in callback. 98/165798/4 accepted/tizen/unified/20180123.061052 submit/tizen/20180122.055424
authorNiraj Kumar Goit <niraj.g@samsung.com>
Thu, 4 Jan 2018 05:18:57 +0000 (10:48 +0530)
committertaesub kim <taesub.kim@samsung.com>
Mon, 22 Jan 2018 05:27:41 +0000 (14:27 +0900)
Added CAPI "wifi_manager_ap_foreach_vsie()" to receive each vsie of AP
in callback.

Change-Id: I6290038ea5a75755a13e395238306fa167638ba9
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/network_interface.h
include/wifi-manager.h
src/network_interface.c
src/wifi_ap.c
test/wifi_manager_test.c

index 22d5cf99449d95f8e4304d11d3f0d62a6ce98b80..c89bb1a7db7cf802f12f2e145cabc381d9ca6381 100755 (executable)
@@ -170,6 +170,7 @@ typedef struct {
        int raw_ssid_len;                                                               /** Raw SSID length */
        char vsie[NET_WLAN_MAX_VSIE_LEN+1];     /** Vendor Specific Information Element of AP*/
        gsize vsie_len; /** VSIE length */
+       GSList *vsie_list;                      /** List of Vendor Specific Information Element of AP*/
        int assoc_status_code;                                                  /** Supplicant WiFi Association Status Code */
 } net_profile_info_s;
 
index 5e2c67f159a3ab14ba22b69f5e0ca21cb1b920ac..4fc87cc440303d8cc9f6cea69034dadbbdbb6f77 100755 (executable)
@@ -2966,6 +2966,35 @@ int wifi_manager_ap_get_assoc_status_code(wifi_manager_ap_h ap,
 int wifi_manager_ap_get_vsie(wifi_manager_ap_h ap,
                char **vsie, int *length);
 
+/**
+ * @brief Called with VSIE data and length of VSIE.
+ * @since_tizen 5.0
+ * @remarks  If @a vsie is needed outside the callback, a copy should be
+ *           made. @a vsie will be freed automatically after the execution
+ *           of this callback.
+ * @param[in] vsie             The vendor specific data
+ * @param[in] length         The length of vendor specific data
+ * @param[in] user_data        The user data passed from the foreach function
+ * @return  @c true to continue with the next iteration of the loop, \n
+ *          @c false to break out of the loop
+ * @pre  wifi_manager_ap_foreach_vsie() will invoke this callback.
+ * @see  wifi_manager_ap_foreach_vsie().
+ */
+typedef bool(*wifi_manager_ap_vsie_cb)(unsigned char *vsie, int length, void *user_data);
+
+/**
+ * @brief Gets all VSIE of AP.
+ * @since_tizen 5.0
+ * @param[in] ap               The access point handle
+ * @param[in] callback         The callback to be called for each VSIE of AP
+ * @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_NOT_SUPPORTED      Not supported
+ */
+int wifi_manager_ap_foreach_vsie(wifi_manager_ap_h ap,
+               wifi_manager_ap_vsie_cb callback, void *user_data);
 
 /**
 * @}
index c98b60a9774d5a3044c3b49ff7341f3a03232b7e..3605843b306df879a62acf97d63eb893f6222617 100755 (executable)
@@ -856,34 +856,6 @@ done:
        return Error;
 }
 
-static int __net_convert_byte_to_txt(const unsigned char *src, char **dst, int src_len)
-{
-       int dst_length = 0;
-       int i = 0;
-       char *buf = NULL;
-
-       if (src_len <= 0) {
-               WIFI_LOG(WIFI_ERROR, "Invalid source length");
-               return -1;
-       }
-
-       *dst = (char *) g_try_malloc0((2*src_len)+1);
-       if (!(*dst)) {
-               WIFI_LOG(WIFI_ERROR, "failed to allocate memory to buffer");
-               return -1;
-       }
-
-       buf = (*dst);
-
-       for (i = 0; i < src_len; i++) {
-               snprintf(buf, 3, "%02x", src[i]);
-               buf += 2;
-               dst_length += 2;
-       }
-
-       return dst_length;
-}
-
 static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* ProfInfo)
 {
        net_err_e Error = NET_ERR_NONE;
@@ -1008,20 +980,18 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof
 
                } else if (g_strcmp0(key, "Vsie") == 0) {
                        const unsigned char *vsie_bytes = NULL;
-                       char *vsie = NULL;
+                       unsigned char *vsie = NULL;
                        gsize size;
-                       int buf_len = 0;
 
                        vsie_bytes = g_variant_get_fixed_array(var, &size, sizeof(guchar));
 
                        if (vsie_bytes) {
-                               ProfInfo->vsie_len = size;
-
-                               buf_len = __net_convert_byte_to_txt(vsie_bytes, &vsie, size);
-                               if (buf_len > 0)
-                                       g_strlcpy(ProfInfo->vsie, vsie, buf_len+1);
-
-                               g_free(vsie);
+                               vsie = (unsigned char *)g_try_malloc0(size);
+                               if (vsie) {
+                                       memcpy(vsie, vsie_bytes, size);
+                                       ProfInfo->vsie_list = g_slist_append(ProfInfo->vsie_list, vsie);
+                               } else
+                                       WIFI_LOG(WIFI_ERROR, "Failed to allocate memory.");
                        }
                } else if (g_strcmp0(key, "DisconnectReason") == 0) {
                        ProfInfo->disconnect_reason = g_variant_get_int32(var);
index 1713bf8cb60b52ad057ac18e4675ef544718c5ce..59f584051016edb8f623c05cbee75721e8033167 100755 (executable)
@@ -583,6 +583,38 @@ EXPORT_API int wifi_manager_ap_get_vsie(wifi_manager_ap_h ap,
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+EXPORT_API int wifi_manager_ap_foreach_vsie(wifi_manager_ap_h ap,
+               wifi_manager_ap_vsie_cb callback, void *user_data)
+{
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       if (_wifi_check_ap_validity(ap) == false || callback == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net_profile_info_s *profile_info = ap;
+
+       bool rv;
+       GSList *list;
+       for (list = profile_info->vsie_list; list; list = list->next) {
+               unsigned char *vsie = (unsigned char *)list->data;
+               int length = vsie[1] + 2;
+
+               rv = callback(vsie, length, user_data);
+               if (rv == false)
+                       break;
+       }
+       g_slist_free_full(profile_info->vsie_list, g_free);
+       profile_info->vsie_list = NULL;
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 EXPORT_API int wifi_manager_ap_get_max_speed(wifi_manager_ap_h ap, int *max_speed)
 {
        __NETWORK_CAPI_FUNC_ENTER__;
index d38e5bd17ec72022281ef9abd6131c2857fc7416..e4c701e64e20647b190ef2075c682dd672d0c2a3 100755 (executable)
@@ -978,6 +978,50 @@ static bool __test_ipv6_address_callback(char *ipv6_address, void *user_data)
        return true;
 }
 
+static int __test_convert_byte_to_txt(const unsigned char *src, char **dst, int src_len)
+{
+       int dst_length = 0;
+       int i = 0;
+       char *buf = NULL;
+
+       if (src_len <= 0) {
+               printf("Invalid source length\n");
+               return -1;
+       }
+
+       *dst = (char *)malloc((2*src_len)+1);
+       if (!(*dst)) {
+               printf("failed to allocate memory to buffer\n");
+               return -1;
+       }
+
+       buf = (*dst);
+
+       for (i = 0; i < src_len; i++) {
+               snprintf(buf, 3, "%02x", src[i]);
+               buf += 2;
+               dst_length += 2;
+       }
+
+       return dst_length;
+}
+
+static bool __test_vendor_specific_callback(unsigned char *vsie_bytes, int vsie_len, void *user_data)
+{
+       if (!vsie_bytes)
+               return false;
+
+       char *vsie = NULL;
+       int buf_len = __test_convert_byte_to_txt(vsie_bytes, &vsie, vsie_len);
+       if (buf_len > 0)
+               printf("vsie_len: %d, vsie: %s\n", vsie_len, vsie);
+
+       if (vsie)
+               free(vsie);
+
+       return true;
+}
+
 static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user_data)
 {
        int rv, address_type = 0;
@@ -997,8 +1041,6 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user
        wifi_manager_disconnect_reason_e disconnect_reason;
        wifi_manager_assoc_status_code_e status_code;
        wifi_manager_rssi_level_e rssi_level;
-       char *vsie;
-       int length;
 
        rv = wifi_manager_ap_get_essid(ap, &ap_name);
        if (rv != WIFI_MANAGER_ERROR_NONE) {
@@ -1032,11 +1074,9 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user
                else
                        printf("Fail to get Frequency\n");
 
-               if (wifi_manager_ap_get_vsie(ap, &vsie, &length) == WIFI_MANAGER_ERROR_NONE) {
-                       printf("VSIE Len: %d vendor element: %s\n", length, vsie);
-                       free(vsie);
-               } else
-                       printf("Fail to get VSIE\n");
+               if (wifi_manager_ap_foreach_vsie(ap, __test_vendor_specific_callback, NULL)
+                               != WIFI_MANAGER_ERROR_NONE)
+                       printf("Fail to get vsie\n");
 
                if (wifi_manager_ap_get_max_speed(ap, &int_value) == WIFI_MANAGER_ERROR_NONE)
                        printf("Max speed : %d\n", int_value);