Add an API for getting VSIE from DHCP Ack packet 68/317168/2 accepted/tizen_9.0_unified accepted/tizen_unified_dev accepted/tizen_unified_toolchain tizen_9.0 accepted/tizen/9.0/unified/20241030.232958 accepted/tizen/unified/20240909.154247 accepted/tizen/unified/dev/20240910.111432 accepted/tizen/unified/toolchain/20241004.101815 accepted/tizen/unified/x/20240910.014257 accepted/tizen/unified/x/asan/20241014.000152 tizen_9.0_m2_release
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:05:02 +0000 (15:05 +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 5e6c695f4372aa0a548eab9b8958f99a5a57301a..7c04cacbecfa5433f4af789928dbaedb385cb980 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 4078262dea6568efcc92b1100642dc7e0a89c45b..aaf232f3f6308425cba5b8c5b43fb63de9f630cc 100644 (file)
@@ -4286,6 +4286,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 d3cdb4ffb8b5f716973015210db0192ae415483e..4eac66e34da991b64ee33a1d66084105ce1c6df7 100644 (file)
@@ -602,6 +602,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 7b178d344fd59122e98f193048d61c4b281862e3..a44461a6f13031aaa37ccadbbd07f771f90a941b 100644 (file)
@@ -2267,6 +2267,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 8912cb0e8dbc51c400f8b88f94f5c4faf04c8846..8ac2ec8f124dae2e8f54e94675f54a21a4a166ea 100644 (file)
@@ -1097,3 +1097,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 f96b78b411634d3a50028861cf452d9f5f6e8c41..a9a71f943d7a8b6f5d27c975d75ff5a1dcbcf68b 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 534724988d9f649f43b5e651d65d2b29a25ec047..b36a7ad9a6458a9936f98adeaae6aede7d3c09d3 100644 (file)
@@ -368,6 +368,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");
@@ -614,6 +615,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;
        }