Added CAPI to get vsie information of each AP. 59/158859/3
authorNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 3 Nov 2017 12:13:27 +0000 (17:43 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 7 Nov 2017 09:58:14 +0000 (15:28 +0530)
Change-Id: I937be29ea3bbdbc799ea74eb3107cd42b83e5144
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/network_interface.h
include/network_wlan.h
include/wifi_manager_extension.h
src/network_interface.c
src/wifi_ap.c
test/wifi_manager_test.c

index d2f7680..8e823f3 100755 (executable)
@@ -166,6 +166,8 @@ typedef struct {
        int disconnect_reason;                                                  /** Supplicant Disconnect Reason Code */
        unsigned char raw_ssid[NET_WLAN_RAW_SSID_LEN+1];/** Raw SSID bytes */
        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 */
 } net_profile_info_s;
 
 typedef struct {
index 6ac0b49..3252f96 100755 (executable)
@@ -94,6 +94,9 @@ extern "C" {
  */
 #define NET_WLAN_PRIVATE_KEY_PASSWD_LEN                50
 
+/** Length of VSIE(vendor specific information element) */
+#define NET_WLAN_MAX_VSIE_LEN                  255
+
 /**
  * Below security modes are used in infrastructure and ad-hoc mode
  * For now all EAP security mechanisms are provided only in infrastructure mode
index 9a89cd8..16a5cc9 100755 (executable)
@@ -269,6 +269,24 @@ int wifi_manager_get_vsie_list(wifi_manager_h wifi,
                wifi_manager_vsie_list_cb callback, void *user_data);
 
 /**
+ * @brief Gets the vsie result of the AP.
+ * @since_tizen 5.0
+ * @remarks @a vsie must be released with free().
+ *
+ * @param[in] ap               The access point handle
+ * @param[out] vsie            The vendor specific information element
+ * @param[out] length          The VSIE length
+ *
+ * @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_OUT_OF_MEMORY       Out of memory
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Not supported
+ */
+int wifi_manager_ap_get_vsie(wifi_manager_ap_h ap,
+                       char **vsie, int *length);
+
+/**
  * @brief Flush BSS
  * @since_tizen 4.0
  *
index 5765f3b..e656b1e 100755 (executable)
@@ -810,6 +810,34 @@ 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;
@@ -932,6 +960,23 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof
                } else if (g_strcmp0(key, "Frequency") == 0) {
                        ProfInfo->frequency = (unsigned int)g_variant_get_uint16(var);
 
+               } else if (g_strcmp0(key, "Vsie") == 0) {
+                       const unsigned char *vsie_bytes = NULL;
+                       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);
+                       }
                } else if (g_strcmp0(key, "DisconnectReason") == 0) {
                        ProfInfo->disconnect_reason = g_variant_get_int32(var);
 
index 8ccba5b..397677a 100755 (executable)
@@ -555,6 +555,34 @@ EXPORT_API int wifi_manager_ap_get_frequency(wifi_manager_ap_h ap, int *frequenc
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+EXPORT_API int wifi_manager_ap_get_vsie(wifi_manager_ap_h ap,
+                       char **vsie, int *length)
+{
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       WIFI_LOG(WIFI_INFO,  "WiFi get vsie\n");
+       if (_wifi_check_ap_validity(ap) == false || vsie == NULL || length == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter");
+               __NETWORK_CAPI_FUNC_EXIT__;
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_s *profile_info = ap;
+
+       *length = (int)profile_info->vsie_len;
+       *vsie = strdup(profile_info->vsie);
+       if (*vsie == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to allocate memory");
+               __NETWORK_CAPI_FUNC_EXIT__;
+               return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+       }
+
+       __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 4cf1f61..79d5421 100755 (executable)
@@ -976,6 +976,8 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user
        char *ap_name_part = (char*)user_data;
        wifi_manager_disconnect_reason_e disconnect_reason;
        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) {
@@ -1009,6 +1011,12 @@ 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_get_max_speed(ap, &int_value) == WIFI_MANAGER_ERROR_NONE)
                        printf("Max speed : %d\n", int_value);
                else