Add an API for getting VSIE from DHCP Ack packet 69/317169/2 accepted/tizen_7.0_unified tizen_7.0 accepted/tizen/7.0/unified/20240909.160142
authorJaehyun Kim <jeik01.kim@samsung.com>
Thu, 5 Sep 2024 05:51:22 +0000 (14:51 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Thu, 5 Sep 2024 06:03:07 +0000 (15:03 +0900)
Change-Id: I9b51c76f67f55206ad729c89d7c0ad69deaaa470
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
include/wifi-manager-extension.h
src/network_interface.c
src/network_internal.h
src/wifi_internal.c
src/wifi_internal.h
src/wifi_manager.c
tools/manager-test/wman_test_extension.c
tools/manager-test/wman_test_extension.h
tools/manager-test/wman_test_main.c

index f03d57244caedf3244799be3d6c72d9a49f9744b..ab58ff59d4bef8d5f99cc890dfdc0e1d4c98e27c 100644 (file)
@@ -867,6 +867,26 @@ int wifi_manager_set_country_code(wifi_manager_h wifi, const char *country);
  */
 int wifi_manager_get_country_code(wifi_manager_h wifi, char **country_code);
 
+/**
+ * @brief Gets the Wi-Fi Vendor Specific Information Elements (VSIE) from DHCP ack packet of the connected network.
+ * @since_tizen 9.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/network.get
+ * @remarks @a vsie_str must be released with free().
+ *
+ * @param[in]  wifi          The Wi-Fi handle
+ * @param[out] vsie_str      The DHCP VSIE data. If the connection is established but there is no VSIE data, this parameter will be set to NULL.
+ *
+ * @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
+ * @retval #WIFI_MANAGER_ERROR_NO_CONNECTION        Not Connected
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED     Operation Failed
+ * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED    Permission Denied
+ */
+int wifi_manager_get_dhcp_vsie(wifi_manager_h wifi, char **vsie_str);
+
 /**
  * @brief Sets the Wi-Fi band to scan.
  * @since_tizen 9.0
index 77690cf1bcc120d904cec6b08eaad50c83316d60..a8ffffac198d56b0a922f1f9f19fea88e3ea73dd 100644 (file)
@@ -1070,6 +1070,41 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s *Prof
        return Error;
 }
 
+static void _net_extract_dhcp_vsie_from_ipv4(GVariant *variant, char **vsie)
+{
+       GVariant *var = NULL;
+       GVariantIter *iter = NULL;
+       const gchar *value = NULL;
+       const gchar *subKey = NULL;
+
+       g_variant_get(variant, "a{sv}", &iter);
+
+       while (g_variant_iter_loop(iter, "{sv}", &subKey, &var)) {
+               if (g_strcmp0(subKey, "DHCPVsie") == 0) {
+                       value = g_variant_get_string(var, NULL);
+                       *vsie = g_strdup(value);
+               }
+       }
+
+       g_variant_iter_free(iter);
+}
+
+static int __net_extract_dhcp_vsie(GVariantIter *array, char **vsie)
+{
+       GVariant *var = NULL;
+       const gchar *key = NULL;
+
+       __NETWORK_FUNC_ENTER__;
+
+       while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
+               if (g_strcmp0(key, "IPv4") == 0)
+                       _net_extract_dhcp_vsie_from_ipv4(var, vsie);
+       }
+
+       __NETWORK_FUNC_EXIT__;
+       return NET_ERR_NONE;
+}
+
 int _net_extract_service_info(network_info_s *network_info,
                const char* ProfileName, GVariantIter *iter,
                net_profile_info_s* ProfInfo)
@@ -1277,6 +1312,38 @@ static int __net_extract_connected_profile(network_info_s *network_info,
        return err;
 }
 
+static int __net_extract_dhcp_vsie_from_connected_profile(network_info_s *network_info,
+               GVariant *message, char **vsie)
+{
+       int err = NET_ERR_NONE;
+       gchar *obj_path = NULL;
+       GVariantIter *iter = NULL;
+
+       __NETWORK_FUNC_ENTER__;
+
+       if (!g_variant_is_of_type(message, G_VARIANT_TYPE("(oa{sv})"))) {
+               WIFI_LOG(WIFI_ERROR, "There is no connected service");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_NO_PROFILE;
+       }
+
+       g_variant_get(message, "(oa{sv})", &obj_path, &iter);
+
+       if (g_str_has_prefix(obj_path, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) != TRUE) {
+               WIFI_LOG(WIFI_ERROR, "No wifi service");
+               __NETWORK_FUNC_EXIT__;
+               return NET_ERR_NO_PROFILE;
+       }
+
+       err = __net_extract_dhcp_vsie(iter, vsie);
+
+       g_variant_iter_free(iter);
+       g_free(obj_path);
+
+       __NETWORK_FUNC_EXIT__;
+       return err;
+}
+
 static void _net_clear_cb_timers(void)
 {
        if (connection_cb_timer > 0) {
@@ -1495,6 +1562,35 @@ int _net_get_connected_profile(network_info_s *network_info,
        return err;
 }
 
+int _net_get_dhcp_vsie_from_connected_profile(network_info_s *network_info,
+               const char *ifname, char **vsie)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e err = NET_ERR_NO_PROFILE;
+       GVariant *message;
+       GVariant *params = NULL;
+
+       params = g_variant_new("(s)", ifname);
+
+       message = _net_invoke_dbus_method(network_info,
+                       CONNMAN_SERVICE, CONNMAN_MANAGER_PATH,
+                       CONNMAN_MANAGER_INTERFACE, "GetConnectedService",
+                       params, &err);
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get connected service(profile)"); //LCOV_EXCL_LINE
+               __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return err; //LCOV_EXCL_LINE
+       }
+
+       err = __net_extract_dhcp_vsie_from_connected_profile(network_info, message, vsie);
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return err;
+}
+
 int net_init_profile_info(network_info_s *network_info, net_profile_info_s *ProfInfo)
 {
        int i = 0;
index 2da01f292eacc6578cf5f1e9ddeefcfa1741f25e..f1202a4d4a8c01aad7b0db9a419e1a83c95ed8ce 100644 (file)
@@ -156,6 +156,8 @@ int _net_get_interface_list(network_info_s *network_info, GSList **interface_lis
 int _net_get_profile_list(network_info_s *network_info, GSList **profile_list);
 int _net_get_connected_profile(network_info_s *network_info,
                const char *ifname, net_profile_info_s *profile_info);
+int _net_get_dhcp_vsie_from_connected_profile(network_info_s *network_info,
+               const char *ifname, char **vsie);
 net_err_e _net_get_wifi_state(network_info_s *network_info);
 void _net_clear_request_table(network_info_s *network_info);
 
index 2f959acc77b92170112b4e6a8383353e3aa512d4..635a79d29496a67744c3ef36b0c5e9e3094169e8 100644 (file)
@@ -4281,6 +4281,28 @@ int _wifi_get_country_code(wifi_manager_h wifi, char **country)
 }
 
 //LCOV_EXCL_START
+int _wifi_get_dhcp_vsie(wifi_manager_h wifi, char **vsie)
+{
+       int rv;
+       wifi_manager_handle_s *wifi_handle = wifi;
+       const char *ifname = wifi_handle->interface_name;
+
+       rv = _net_get_dhcp_vsie_from_connected_profile(wifi_handle->network_info, ifname, vsie);
+       if (rv != NET_ERR_NONE) {
+               if (rv == NET_ERR_NO_PROFILE)
+                       return WIFI_MANAGER_ERROR_NO_CONNECTION;
+               else if (rv == NET_ERR_ACCESS_DENIED) {
+                       WIFI_LOG(WIFI_ERROR, "Access denied");
+                       return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
+               } else if (rv == NET_ERR_INVALID_PARAM)
+                       return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+               else
+                       return WIFI_MANAGER_ERROR_OPERATION_FAILED;
+       }
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 int _wifi_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band)
 {
        int rv;
index d4bfab94769139cd1f942438c85cdff1d743a427..1925506be5c5ed589f3fd2bd07f0349336f1796d 100644 (file)
@@ -601,6 +601,7 @@ int _wifi_get_random_mac_lifetime(wifi_manager_h wifi, unsigned int *lifetime);
 
 int _wifi_set_country_code(wifi_manager_h wifi, const char *country);
 int _wifi_get_country_code(wifi_manager_h wifi, char **country);
+int _wifi_get_dhcp_vsie(wifi_manager_h wifi, char **vsie);
 int _wifi_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band);
 int _wifi_get_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e *scan_band);
 
index 8b2ccb138b8b4803cb13bee61f6eb38850c08e72..16b803fc4dfd99d3f58b7a6489f88131310acccf 100644 (file)
@@ -2245,6 +2245,35 @@ EXPORT_API int wifi_manager_get_country_code(wifi_manager_h wifi, char **country
        return rv;
 }
 
+EXPORT_API int wifi_manager_get_dhcp_vsie(wifi_manager_h wifi, char **vsie_str)
+{
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       int rv = WIFI_MANAGER_ERROR_NONE;
+       char *vsie = NULL;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       if (vsie_str == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter");
+               __NETWORK_CAPI_FUNC_EXIT__;
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+       }
+
+       RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__);
+
+       rv = _wifi_get_dhcp_vsie(wifi, &vsie);
+       if (vsie) {
+               *vsie_str = strdup(vsie);
+               g_free(vsie);
+       } else {
+               *vsie_str = NULL;
+       }
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+       return rv;
+}
+
 EXPORT_API int wifi_manager_set_scan_band(wifi_manager_h wifi, wifi_manager_band_selection_e scan_band)
 {
        int rv;
index 10d706b2a9f870827f2cdbe7d5d2f09392c27654..95f2f1c5a8cd3aedbf851d0195064ad2bdb0c116 100644 (file)
@@ -1087,3 +1087,20 @@ int wman_test_set_scan_band(wifi_manager_h wifi)
 
        return 1;
 }
+
+int wman_test_get_dhcp_vsie(wifi_manager_h wifi)
+{
+       int rv;
+       char *vsie = NULL;
+
+       rv = wifi_manager_get_dhcp_vsie(wifi, &vsie);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to get DHCP VSIE[%s]\n", wman_test_strerror(rv));
+               return -1;
+       }
+       printf("DHCP VSIE: %s\n", vsie);
+       free(vsie);
+
+       return 1;
+}
+
index 45661f4cb93c316e62ab4f305eaaa369d906598d..0dfbf744bd32c33bc664cfbee8729339ba8435e8 100644 (file)
@@ -51,4 +51,5 @@ int wman_test_get_power_save_mode(wifi_manager_h wifi);
 int wman_test_set_power_save_mode(wifi_manager_h wifi);
 int wman_test_get_scan_band(wifi_manager_h wifi);
 int wman_test_set_scan_band(wifi_manager_h wifi);
+int wman_test_get_dhcp_vsie(wifi_manager_h wifi);
 
index dc308ac26cebbd10bf3888b64baa21f304db29d0..cc3341f91dc603d7b8fe0215f723c28df404e14e 100644 (file)
@@ -333,6 +333,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf(",   - Get Wi-Fi passphrase\n");
                printf(".   - Get Wi-Fi band for scanning\n");
                printf("/   - Set Wi-Fi band for scanning\n");
+               printf("_   - Gets the Wi-Fi VSIE from DHCP ack packet\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
 
                printf("ENTER  - Show options menu.......\n");
@@ -576,6 +577,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case '/':
                rv = wman_test_set_scan_band(wifi);
                break;
+       case '_':
+               rv = wman_test_get_dhcp_vsie(wifi);
+               break;
        default:
                break;
        }