From 6054a08da1a365c8c2b12cd5856731a6ca7380b8 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Thu, 4 Apr 2019 22:41:59 +0900 Subject: [PATCH 01/16] Update comments as per guideline Change-Id: I75c05778611ca8c652bbb78157c456f8f6e53825 Signed-off-by: Jaehyun Kim --- include/wifi-manager.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 2560b41..245aa72 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -780,7 +780,7 @@ typedef void *wifi_manager_ap_h; */ /** - * @brief The Wi-Fi access point configuration handle + * @brief The Wi-Fi access point configuration handle. * @since_tizen 3.0 */ typedef void *wifi_manager_config_h; @@ -832,7 +832,7 @@ typedef enum { /** * @brief Called for each found access point. * @since_tizen 3.0 - * @remarks @a AP is valid only in this function. In order to use @a AP outside this function, you must copy the AP with wifi_manager_ap_clone(). + * @remarks @a ap is valid only in this function. In order to use @a AP outside this function, you must copy the AP with wifi_manager_ap_clone(). * @param[in] ap The access point * @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 @@ -857,6 +857,9 @@ typedef void(*wifi_manager_scan_finished_cb)(wifi_manager_error_e error_code, vo /** * @brief Called when the scanning state is changed. + * @details The following error codes can be received: \n + * #WIFI_MANAGER_ERROR_NONE Successful \n + * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed * @since_tizen 4.0 * @param[in] state The wifi scanning state * @param[in] user_data The user data passed from the callback registration function @@ -867,6 +870,10 @@ typedef void(*wifi_manager_scan_state_changed_cb)(wifi_manager_scan_state_e stat /** * @brief Called after wifi_manager_activate() or wifi_manager_activate_with_wifi_picker_tested() is completed. + * @details The following error codes can be received: \n + * #WIFI_MANAGER_ERROR_NONE Successful \n + * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed \n + * #WIFI_MANAGER_ERROR_SECURITY_RESTRICTED Restricted by security system policy * @since_tizen 3.0 * @param[in] result The result * @param[in] user_data The user data passed from wifi_manager_activate() and wifi_manager_activate_with_wifi_picker_tested() @@ -878,6 +885,10 @@ typedef void(*wifi_manager_activated_cb)(wifi_manager_error_e result, void *user /** * @brief Called after wifi_manager_deactivate() is completed. + * @details The following error codes can be received: \n + * #WIFI_MANAGER_ERROR_NONE Successful \n + * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed \n + * #WIFI_MANAGER_ERROR_SECURITY_RESTRICTED Restricted by security system policy * @since_tizen 3.0 * @param[in] result The result * @param[in] user_data The user data passed from wifi_manager_deactivate() @@ -895,7 +906,22 @@ typedef void(*wifi_manager_deactivated_cb)(wifi_manager_error_e result, void *us * - wifi_manager_connect_by_wps_pin() * - wifi_manager_connect_by_wps_pbc_without_ssid() * - wifi_manager_connect_by_wps_pin_without_ssid() - * - wifi_manager_connect_hidden_ap() + * - wifi_manager_connect_hidden_ap() \n\n + * The following error codes can be received: \n + * #WIFI_MANAGER_ERROR_NONE Successful \n + * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed \n + * #WIFI_MANAGER_ERROR_OPERATION_ABORTED Operation aborted \n + * #WIFI_MANAGER_ERROR_ALREADY_EXISTS Connection already exists \n + * #WIFI_MANAGER_ERROR_OUT_OF_RANGE Out of range \n + * #WIFI_MANAGER_ERROR_DHCP_FAILED DHCP failed \n + * #WIFI_MANAGER_ERROR_CONNECT_FAILED Connect failed \n + * #WIFI_MANAGER_ERROR_LOGIN_FAILED Login failed \n + * #WIFI_MANAGER_ERROR_AUTHENTICATION_FAILED Authentication failed \n + * #WIFI_MANAGER_ERROR_INVALID_KEY Invalid key \n + * #WIFI_MANAGER_ERROR_PIN_MISSING PIN missing \n + * #WIFI_MANAGER_ERROR_WPS_OVERLAP WPS Overlap \n + * #WIFI_MANAGER_ERROR_WPS_TIMEOUT WPS Timeout \n + * #WIFI_MANAGER_ERROR_WPS_WEP_PROHIBITED WPS WEP Prohibited * @since_tizen 3.0 * @param[in] result The result * @param[in] user_data The user data passed from the connection function. @@ -911,6 +937,9 @@ typedef void(*wifi_manager_connected_cb)(wifi_manager_error_e result, void *user /** * @brief Called after wifi_manager_disconnect() is completed. + * @details The following error codes can be received: \n + * #WIFI_MANAGER_ERROR_NONE Successful \n + * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed * @since_tizen 3.0 * @param[in] result The result * @param[in] user_data The user data passed from wifi_manager_disconnect() @@ -934,6 +963,9 @@ typedef void(*wifi_manager_forget_ap_finished_cb)(wifi_manager_error_e result, v /** * @brief Called when the BSSID scan is finished. + * @details The following error codes can be received: \n + * #WIFI_MANAGER_ERROR_NONE Successful \n + * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed * @since_tizen 4.0 * @param[in] error_code The error code * @param[in] user_data The user data passed from the callback registration function @@ -1056,6 +1088,7 @@ typedef void(*wifi_manager_tdls_state_changed_cb)(wifi_manager_tdls_state_e stat /** * @brief Called when the Wi-Fi TDLS is discovered. + * @since_tizen 4.0 * @remarks @a peer_mac_addr is usable only in the callback. To use outside the callback, make a copy. * @param[in] state The TDLS state * @param[in] peer_mac_addr The MAC address of the TDLS peer -- 2.7.4 From 4cc25830568913d05acf15f224c805c2ba1aaf28 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Mon, 29 Apr 2019 17:37:41 +0900 Subject: [PATCH 02/16] Fix API reference in header Change-Id: I72046f489139a30a1a76997564b6c65d739fb2c0 Signed-off-by: hyunuktak --- include/wifi-manager.h | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 245aa72..5a06901 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -832,7 +832,7 @@ typedef enum { /** * @brief Called for each found access point. * @since_tizen 3.0 - * @remarks @a ap is valid only in this function. In order to use @a AP outside this function, you must copy the AP with wifi_manager_ap_clone(). + * @remarks @a ap is valid only in this function. In order to use @a ap outside this function, you must copy the @a ap with wifi_manager_ap_clone(). * @param[in] ap The access point * @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 @@ -846,6 +846,9 @@ typedef bool(*wifi_manager_found_ap_cb)(wifi_manager_ap_h ap, void *user_data); /** * @brief Called when the scan is finished. + * @details The following error codes can be received: \n + * #WIFI_MANAGER_ERROR_NONE Successful \n + * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed \n * @since_tizen 3.0 * @param[in] error_code The error code * @param[in] user_data The user data passed from the callback registration function @@ -857,9 +860,6 @@ typedef void(*wifi_manager_scan_finished_cb)(wifi_manager_error_e error_code, vo /** * @brief Called when the scanning state is changed. - * @details The following error codes can be received: \n - * #WIFI_MANAGER_ERROR_NONE Successful \n - * #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed * @since_tizen 4.0 * @param[in] state The wifi scanning state * @param[in] user_data The user data passed from the callback registration function @@ -1347,8 +1347,8 @@ int wifi_manager_scan_specific_ap(wifi_manager_h wifi, * @brief Creates a Wi-Fi specific AP scan handle. * @since_tizen 4.0 * @remarks You must release @a specific_scan using wifi_manager_specific_scan_destroy(). - * @param[in] wifi The Wi-Fi handle - * @param[out] specific_scan The Wi-Fi specific AP scan handle + * @param[in] wifi The Wi-Fi handle + * @param[out] specific_scan The Wi-Fi specific AP scan handle * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful @@ -1364,8 +1364,8 @@ int wifi_manager_specific_scan_create(wifi_manager_h wifi, wifi_manager_specific /** * @brief Destroys a Wi-Fi specific AP scan handle. * @since_tizen 4.0 - * @param[in] wifi The Wi-Fi handle - * @param[in] specific_scan The Wi-Fi specific AP scan handle + * @param[in] wifi The Wi-Fi handle + * @param[in] specific_scan The Wi-Fi specific AP scan handle * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful @@ -1382,7 +1382,7 @@ int wifi_manager_specific_scan_destroy(wifi_manager_h wifi, wifi_manager_specifi * @brief Sets the SSID of a specific AP scan. * @since_tizen 4.0 * @param[in] specific_scan The Wi-Fi specific AP scan handle - * @param[in] essid The SSID of specific AP scan + * @param[in] essid The SSID of specific AP scan * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful @@ -1398,7 +1398,7 @@ int wifi_manager_specific_scan_set_ssid(wifi_manager_specific_scan_h specific_sc * @brief Sets the channel frequency of a specific AP scan. * @since_tizen 4.0 * @param[in] specific_scan The Wi-Fi specific AP scan handle - * @param[in] freq The channel frequency of specific AP scan + * @param[in] freq The channel frequency of specific AP scan * * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful @@ -3164,7 +3164,7 @@ int wifi_manager_ap_set_eap_ca_cert_file(wifi_manager_ap_h ap, const char *file) int wifi_manager_ap_get_eap_client_cert_file(wifi_manager_ap_h ap, char **file); /** - * @brief Sets the CA Certificate of EAP. + * @brief Sets the Client Certificate of EAP. * @since_tizen 3.0 * @remarks This function is valid only if the EAP type is #WIFI_MANAGER_EAP_TYPE_TLS. * @param[in] ap The access point handle @@ -4063,7 +4063,6 @@ int wifi_manager_config_get_eap_subject_match(wifi_manager_config_h config, * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied * @see wifi_manager_config_save() */ int wifi_manager_config_set_eap_subject_match(wifi_manager_config_h config, @@ -4106,7 +4105,6 @@ int wifi_manager_tdls_set_discovered_cb(wifi_manager_h wifi, * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation - * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported */ int wifi_manager_tdls_unset_discovered_cb(wifi_manager_h wifi); @@ -4126,7 +4124,6 @@ int wifi_manager_tdls_unset_discovered_cb(wifi_manager_h wifi); * @retval #WIFI_MANAGER_ERROR_INVALID_OPERATION Invalid operation * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed * @retval #WIFI_MANAGER_ERROR_PERMISSION_DENIED Permission Denied - * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported */ int wifi_manager_tdls_start_discovery(wifi_manager_h wifi, const char *peer_mac_addr); -- 2.7.4 From 3145f151a08a66e5cb7d26e64adb52961a30dea1 Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Wed, 26 Dec 2018 08:53:18 +0530 Subject: [PATCH 03/16] Added prototype of CAPI to get maximum scan SSIDs. Added prototype of CAPI to get the maximum number of SSIDs supported by wlan chipset for scan operation. Change-Id: I88f6d9922fc38487a8bcbd1942b8f508a1649d7f Signed-off-by: Niraj Kumar Goit --- include/wifi-manager.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 245aa72..53efa29 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -1379,6 +1379,25 @@ int wifi_manager_specific_scan_create(wifi_manager_h wifi, wifi_manager_specific int wifi_manager_specific_scan_destroy(wifi_manager_h wifi, wifi_manager_specific_scan_h specific_scan); /** + * @brief Gets the maximum number of SSIDs supported by wlan chipset for scan operation. + * @since_tizen 5.5 + * @privlevel public + * @privilege %http://tizen.org/privilege/network.get + * @param[in] wifi The Wi-Fi handle + * @param[out] max_scan_ssids The maximum number of SSIDs supported by wlan \n + * chipset for scan operation. + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized + * @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 + * @see wifi_manager_specific_scan_set_ssid() + */ +int wifi_manager_specific_scan_get_max_ssid(wifi_manager_h wifi, int *max_scan_ssids); + +/** * @brief Sets the SSID of a specific AP scan. * @since_tizen 4.0 * @param[in] specific_scan The Wi-Fi specific AP scan handle -- 2.7.4 From 3ed4d7f915e60647ca86258b573332225cbbc967 Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Wed, 26 Dec 2018 08:57:59 +0530 Subject: [PATCH 04/16] Added CAPI to get the maximum scan SSIDs. Added CAPI to get the maximum number of scan SSIDs supported by wlan chipset. Change-Id: I44991b5bde6d6ce1bd8d5f44150fff9957616f7b Signed-off-by: Niraj Kumar Goit --- include/network_dbus.h | 1 + include/network_interface.h | 1 + include/wifi_internal.h | 1 + src/network_dbus.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/network_interface.c | 25 +++++++++++++++++++++++++ src/wifi_internal.c | 17 +++++++++++++++++ src/wifi_manager.c | 21 +++++++++++++++++++++ 7 files changed, 106 insertions(+) diff --git a/include/network_dbus.h b/include/network_dbus.h index b7b5cb1..2aac720 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -115,6 +115,7 @@ int _net_dbus_netlink_scan_request(GSList *nl_scan_list, const char *vsie); int _net_dbus_get_passpoint(int *enabled); int _net_dbus_set_passpoint(int enable); int _net_dbus_multi_scan_request(GSList *multi_scan_list); +int _net_dbus_get_max_scan_ssids(int *max_scan_ssids); int _net_dbus_cancel_wps(void); int _net_dbus_open_connection_without_ssid(); diff --git a/include/network_interface.h b/include/network_interface.h index 125d4a2..d758b8a 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -301,6 +301,7 @@ int net_wifi_get_passpoint(int *enable); int net_wifi_set_passpoint(int enable); int net_wifi_get_scan_state(int *scan_state); int net_multi_scan_wifi(GSList *specific_scan_list, gboolean multi_scan_type[]); +int net_wifi_get_max_scan_ssids(int *max_scan_ssids); 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); diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 4fb99e2..03d5486 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -335,6 +335,7 @@ int _wifi_specific_scan_set_freq(wifi_manager_specific_scan_h specific_scan, int _wifi_start_multi_scan(wifi_manager_h wifi, wifi_manager_specific_scan_h specific_scan, wifi_manager_scan_finished_cb callback, void *user_data); +int _wifi_get_max_scan_ssids(int *max_scan_ssids); /* WIFI Configuration */ bool _wifi_check_config_validity(wifi_manager_config_h config_h); diff --git a/src/network_dbus.c b/src/network_dbus.c index 1631840..0868308 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -3524,4 +3524,44 @@ int _net_dbus_multi_scan_request(GSList *multi_scan_list) __NETWORK_FUNC_EXIT__; return Error; } + +int _net_dbus_get_max_scan_ssids(int *max_scan_ssids) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + GVariant *message = NULL; + GVariant *value = NULL; + GVariantIter *iter = NULL; + gchar *key = NULL; + + message = _net_invoke_dbus_method( + CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX, + CONNMAN_TECHNOLOGY_INTERFACE, "GetMaxScanSsid", NULL, &Error); + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to get Max scan SSIDs."); + *max_scan_ssids = 0; + + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_get(message, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "MaxScanSSID") == 0) { + *max_scan_ssids = g_variant_get_int32(value); + WIFI_LOG(WIFI_INFO, "Successfully get Max scan SSIDs: %d", *max_scan_ssids); + g_variant_unref(value); + g_free(key); + break; + } + } + + g_variant_iter_free(iter); + g_variant_unref(message); + + __NETWORK_FUNC_EXIT__; + return Error; +} //LCOV_EXCL_STOP diff --git a/src/network_interface.c b/src/network_interface.c index 35df3ae..4b63a18 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -3850,4 +3850,29 @@ int net_get_service_state() return _net_get_service_state(); } +int net_wifi_get_max_scan_ssids(int *max_scan_ssids) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + if (NetworkInfo.ref_count < 1) { + WIFI_LOG(WIFI_ERROR, "Application is not registered"); + __NETWORK_CAPI_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + Error = _net_dbus_get_max_scan_ssids(max_scan_ssids); + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "Failed to get Max scan SSIDs. Error [%s]", + _net_print_error(Error)); + + __NETWORK_CAPI_FUNC_EXIT__; + return Error; + } + + __NETWORK_CAPI_FUNC_EXIT__; + return NET_ERR_NONE; +} //LCOV_EXCL_STOP diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 224d75b..efa1c57 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -3530,3 +3530,20 @@ int _wifi_get_service_state() return ret; } + +int _wifi_get_max_scan_ssids(int *max_scan_ssids) +{ + int rv; + + rv = net_wifi_get_max_scan_ssids(max_scan_ssids); + + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE + } else if (rv != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed to get driver_max_scan_ssids"); //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + return WIFI_MANAGER_ERROR_NONE; +} diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 5e7b40f..29a8c24 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -1731,6 +1731,27 @@ EXPORT_API int wifi_manager_specific_scan_destroy(wifi_manager_h wifi, return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_specific_scan_get_max_ssid(wifi_manager_h wifi, int *max_scan_ssids) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + int rv; + + RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__); + + if (max_scan_ssids == 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 + } + + rv = _wifi_get_max_scan_ssids(max_scan_ssids); + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} + EXPORT_API int wifi_manager_specific_scan_set_ssid(wifi_manager_specific_scan_h specific_scan, const char *essid) { -- 2.7.4 From 032ddf14f20fc3edb3017c391dc574de6141434f Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Fri, 14 Jun 2019 17:20:13 +0530 Subject: [PATCH 05/16] Added support of WPA3-SAE security mode. Change-Id: I44114045b9716defe4e467007a1d32d2df38b1ef Signed-off-by: Niraj Kumar Goit Signed-off-by: Nishant Chaprana --- include/network_wlan.h | 15 +++++++++++++++ include/wifi-manager.h | 1 + src/network_interface.c | 3 +++ src/network_internal.c | 8 +++++++- src/network_signal.c | 4 ++++ src/wifi_ap.c | 20 +++++++++++++++++--- src/wifi_internal.c | 14 ++++++++++++++ test/wifi_manager_test.c | 1 + tool/wifi_mgr_tool.c | 2 ++ 9 files changed, 64 insertions(+), 4 deletions(-) diff --git a/include/network_wlan.h b/include/network_wlan.h index cd133d0..58264aa 100755 --- a/include/network_wlan.h +++ b/include/network_wlan.h @@ -54,6 +54,11 @@ extern "C" { #define NET_WLAN_MAX_PSK_PASSPHRASE_LEN 65 /** + * Length of SAE Key + */ +#define NET_WLAN_MAX_SAE_PASSPHRASE_LEN 65 + +/** * Length of WEP Key * Max of 10 Hex digits allowed in case of 64 bit encryption * Max of 26 Hex digits allowed in case of 128 bit encryption @@ -114,6 +119,7 @@ typedef enum { WLAN_SEC_MODE_WPA_PSK, /** WPA-PSK */ WLAN_SEC_MODE_WPA2_PSK, /** WPA2-PSK */ WLAN_SEC_MODE_WPA_FT_PSK, + WLAN_SEC_MODE_SAE, /** SAE */ } wlan_security_mode_type_e; /** @@ -182,6 +188,14 @@ typedef struct { } wlan_psk_info_s; /** + * Below structure is used by WPA3-SAE + * To see the maximum length of SAE passphrase key. + */ +typedef struct { + char saeKey[NET_WLAN_MAX_SAE_PASSPHRASE_LEN + 1]; /** key value for WPA3-SAE */ +} wlan_sae_info_s; + +/** * Below structure is used by WEP * To see the maximum length of WEP key. */ @@ -220,6 +234,7 @@ typedef union { wlan_wep_info_s wep; /** Wep Authentication */ wlan_psk_info_s psk; /** psk Authentication */ wlan_eap_info_s eap; /** eap Authentication */ + wlan_sae_info_s sae; /** sae Authentication */ } wlan_auth_info_u; /** diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 60ae2ab..7042845 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -374,6 +374,7 @@ typedef enum { WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK = 3, /**< WPA2-PSK */ WIFI_MANAGER_SECURITY_TYPE_EAP = 4, /**< EAP */ WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK = 5, /**< FT-PSK (Since 5.0) */ + WIFI_MANAGER_SECURITY_TYPE_SAE = 6, /**< SAE (Since 5.5) */ } wifi_manager_security_type_e; /** diff --git a/src/network_interface.c b/src/network_interface.c index 4b63a18..b6c5f0f 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -858,6 +858,9 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof else if (g_strcmp0(value, "rsn") == 0 && ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK) ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK; + else if (g_strcmp0(value, "sae") == 0 && + ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE) + ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_SAE; else if (g_strcmp0(value, "wps") == 0) ProfInfo->security_info.wps_support = TRUE; else if (ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_NONE) diff --git a/src/network_internal.c b/src/network_internal.c index 6ecc61b..15f65f2 100755 --- a/src/network_internal.c +++ b/src/network_internal.c @@ -274,13 +274,19 @@ int _net_open_connection_with_wifi_info(const net_wifi_connection_info_s* wifi_i wifi_connection_info.passphrase = (char *)wifi_info->security_info.authentication.psk.pskKey; break; + case WLAN_SEC_MODE_WPA_FT_PSK: wifi_connection_info.security = "ft_psk"; wifi_connection_info.passphrase = (char *)wifi_info->security_info.authentication.psk.pskKey; break; - + /** SAE supported */ + case WLAN_SEC_MODE_SAE: + wifi_connection_info.security = "sae"; + wifi_connection_info.passphrase = + (char *)wifi_info->security_info.authentication.sae.saeKey; + break; case WLAN_SEC_MODE_IEEE8021X: wifi_connection_info.security = "ieee8021x"; diff --git a/src/network_signal.c b/src/network_signal.c index ffd5593..3b88ffd 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -175,6 +175,10 @@ static wlan_security_mode_type_e __net_get_wlan_sec_mode(int security) return WLAN_SEC_MODE_WPA2_PSK; case 5: return WLAN_SEC_MODE_IEEE8021X; + case 6: + return WLAN_SEC_MODE_WPA_FT_PSK; + case 7: + return WLAN_SEC_MODE_SAE; default: return WLAN_SEC_MODE_NONE; } diff --git a/src/wifi_ap.c b/src/wifi_ap.c index c4f3b85..c8f0d45 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -87,16 +87,19 @@ static char *__wifi_create_profile_name(const char *ssid, case WLAN_SEC_MODE_WEP: g_sec = "wep"; break; + case WLAN_SEC_MODE_IEEE8021X: + g_sec = "ieee8021x"; + break; case WLAN_SEC_MODE_WPA_PSK: case WLAN_SEC_MODE_WPA2_PSK: g_sec = "psk"; break; - case WLAN_SEC_MODE_IEEE8021X: - g_sec = "ieee8021x"; - break; case WLAN_SEC_MODE_WPA_FT_PSK: g_sec = "ft_psk"; break; + case WLAN_SEC_MODE_SAE: + g_sec = "sae"; + break; default: WIFI_LOG(WIFI_ERROR, "Invalid security type"); return NULL; @@ -1678,6 +1681,9 @@ EXPORT_API int wifi_manager_ap_get_security_type(wifi_manager_ap_h ap, case WLAN_SEC_MODE_WPA_FT_PSK: *type = WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK; break; + case WLAN_SEC_MODE_SAE: + *type = WIFI_MANAGER_SECURITY_TYPE_SAE; + break; default: /* __NETWORK_CAPI_FUNC_EXIT__; */ return WIFI_MANAGER_ERROR_OPERATION_FAILED; @@ -1724,6 +1730,9 @@ EXPORT_API int wifi_manager_ap_set_security_type(wifi_manager_ap_h ap, case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK: profile_info->security_info.sec_mode = WLAN_SEC_MODE_WPA_FT_PSK; break; + case WIFI_MANAGER_SECURITY_TYPE_SAE: + profile_info->security_info.sec_mode = WLAN_SEC_MODE_SAE; + break; default: __NETWORK_CAPI_FUNC_EXIT__; return WIFI_MANAGER_ERROR_INVALID_PARAMETER; @@ -1854,6 +1863,7 @@ EXPORT_API int wifi_manager_ap_is_passphrase_required(wifi_manager_ap_h ap, case WLAN_SEC_MODE_WPA_PSK: case WLAN_SEC_MODE_WPA2_PSK: case WLAN_SEC_MODE_WPA_FT_PSK: + case WLAN_SEC_MODE_SAE: *required = true; break; default: @@ -1893,6 +1903,10 @@ EXPORT_API int wifi_manager_ap_set_passphrase(wifi_manager_ap_h ap, const char * g_strlcpy(profile_info->security_info.authentication.psk.pskKey, passphrase, NET_WLAN_MAX_PSK_PASSPHRASE_LEN+1); break; + case WLAN_SEC_MODE_SAE: + g_strlcpy(profile_info->security_info.authentication.sae.saeKey, + passphrase, NET_WLAN_MAX_SAE_PASSPHRASE_LEN+1); + break; case WLAN_SEC_MODE_NONE: case WLAN_SEC_MODE_IEEE8021X: default: diff --git a/src/wifi_internal.c b/src/wifi_internal.c index efa1c57..47a1776 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -31,6 +31,7 @@ static gboolean multi_scan_type[WIFI_MULTI_SCAN_MAX] = {0, }; #define WIFI_SECURITY_WEP "wep" #define WIFI_SECURITY_WPA_PSK "psk" #define WIFI_SECURITY_WPA_FT_PSK "ft_psk" +#define WIFI_SECURITY_SAE "sae" #define WIFI_SECURITY_EAP "ieee8021x" static __thread GSList *wifi_manager_handle_list = NULL; @@ -213,6 +214,9 @@ static gchar *__wifi_security_type_to_string(wifi_manager_security_type_e securi case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK: return WIFI_SECURITY_WPA_PSK; + case WIFI_MANAGER_SECURITY_TYPE_SAE: + return WIFI_SECURITY_SAE; + case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK: return WIFI_SECURITY_WPA_FT_PSK; @@ -471,6 +475,9 @@ static void __update_netlink_scan_profile_iterator(GSList *bss_list) profile->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK; break; case 4: + profile->security_info.sec_mode = WLAN_SEC_MODE_SAE; + break; + case 5: profile->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X; break; default: @@ -1893,6 +1900,9 @@ int _wifi_get_hidden_aps(wifi_manager_h wifi, const char *essid, case WLAN_SEC_MODE_WPA_FT_PSK: type = WIFI_MANAGER_SECURITY_TYPE_WPA_PSK; break; + case WLAN_SEC_MODE_SAE: + type = WIFI_MANAGER_SECURITY_TYPE_SAE; + break; } if (prof_info->is_hidden == TRUE) { if (type == sec_type) { @@ -1928,6 +1938,10 @@ int _wifi_get_hidden_aps(wifi_manager_h wifi, const char *essid, g_strlcpy(profile_info->security_info.authentication.psk.pskKey, passphrase, NET_WLAN_MAX_PSK_PASSPHRASE_LEN+1); break; + case WLAN_SEC_MODE_SAE: + g_strlcpy(profile_info->security_info.authentication.sae.saeKey, + passphrase, NET_WLAN_MAX_SAE_PASSPHRASE_LEN+1); + break; case WLAN_SEC_MODE_NONE: break; case WLAN_SEC_MODE_IEEE8021X: diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index baae119..1beba73 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -1459,6 +1459,7 @@ static bool __test_found_specific_ap_callback(wifi_manager_ap_h ap, void *user_d case WIFI_MANAGER_SECURITY_TYPE_WEP: case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK: case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK: + case WIFI_MANAGER_SECURITY_TYPE_SAE: { char passphrase[100]; printf("Input passphrase for %s : ", ap_name); diff --git a/tool/wifi_mgr_tool.c b/tool/wifi_mgr_tool.c index 0b33a92..cfcc767 100755 --- a/tool/wifi_mgr_tool.c +++ b/tool/wifi_mgr_tool.c @@ -496,6 +496,8 @@ const char *test_wifi_mgr_sec_type_to_string(wifi_manager_security_type_e type) return "EAP"; case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK: return "FT_PSK"; + case WIFI_MANAGER_SECURITY_TYPE_SAE: + return "WPA3"; } return "Unknown"; -- 2.7.4 From 4930093dd90d8bb7d1e00a8b7c90c1dfeec534bf Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Mon, 24 Jun 2019 10:38:12 +0900 Subject: [PATCH 06/16] Add to get passphrase internally from config Change-Id: I46766950cdd8a6d45dd06d8055e978042073699e Signed-off-by: hyunuktak --- include/network_dbus.h | 6 +++--- include/network_interface.h | 6 +++--- include/wifi_internal.h | 6 ++++-- packaging/capi-network-wifi-manager.spec | 2 +- src/network_dbus.c | 10 +++++++--- src/network_interface.c | 16 ++++++++-------- src/wifi_config.c | 8 +++++--- src/wifi_internal.c | 16 ++++++++-------- 8 files changed, 39 insertions(+), 31 deletions(-) diff --git a/include/network_dbus.h b/include/network_dbus.h index 2aac720..f966e9a 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -133,13 +133,13 @@ int _net_dbus_config_set_field(const gchar *config_id, const gchar *key, const g int _net_dbus_config_get_passphrase(const gchar *config_id, gchar **passphrase); int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, - net_ip_info_config_s *ip_info, gboolean is_hidden); + net_ip_info_config_s *ip_info, gboolean is_hidden, gboolean is_created); int _net_dbus_config_save_eap_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, - const gchar *proxy_address, net_eap_config_s *eap_config, gboolean is_hidden); + const gchar *proxy_address, net_eap_config_s *eap_config, gboolean is_hidden, gboolean is_created); int _net_dbus_config_remove_configurations(const gchar *config_id); int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name, - net_wifi_security_type_e *security_type, gchar **proxy_address, + gchar **passphrase, net_wifi_security_type_e *security_type, gchar **proxy_address, gboolean *is_hidden, net_ip_info_config_s **ip_info, void *last_error); int _net_dbus_config_load_eap_configurations(const gchar *config_id, gchar **name, net_wifi_security_type_e *security_type, gchar **proxy_address, diff --git a/include/network_interface.h b/include/network_interface.h index d758b8a..e800102 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -347,13 +347,13 @@ int net_config_get_passphrase(const gchar *config_id, gchar **passphrase); int net_config_save_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, net_ip_info_config_s *ip_info, - gboolean is_hidden); + gboolean is_hidden, gboolean is_created); int net_config_save_eap_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, - const gchar *proxy_address, void *eap_config, gboolean is_hidden); + const gchar *proxy_address, void *eap_config, gboolean is_hidden, gboolean is_created); int net_config_remove_configurations(const gchar *config_id); int net_config_load_configurations(const gchar *config_id, gchar **name, - void *security_type, gchar **proxy_address, gboolean *is_hidden, + gchar **passphrase, void *security_type, gchar **proxy_address, gboolean *is_hidden, net_ip_info_config_s **ip_info, void *last_error); int net_config_load_eap_configurations(const gchar *config_id, gchar **name, void *security_type, gchar **proxy_address, diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 03d5486..1a62db6 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -46,6 +46,7 @@ extern "C" { #define WIFI_CONFIG_SECURITY_TYPE "Security" #define WIFI_CONFIG_PROXYADDRESS "ProxyAddress" #define WIFI_CONFIG_HIDDEN "Hidden" +#define WIFI_CONFIG_CREATED "Created" #define WIFI_CONFIG_IPV4_METHOD "IPv4.method" #define WIFI_CONFIG_IPV6_METHOD "IPv6.method" #define WIFI_CONFIG_IPV4_ADDRESS "IPv4.local_address" @@ -181,6 +182,7 @@ typedef struct { gchar *name; gchar *passphrase; wifi_manager_security_type_e security_type; + gboolean is_created; gboolean is_saved; gboolean is_hidden; @@ -346,7 +348,7 @@ int _wifi_config_get_config_id_list(GSList **list); int _wifi_save_configuration(const gchar *name, const gchar *passphrase, wifi_manager_security_type_e security_type, const gchar *proxy_address, - wifi_config_ip_info_s *ip_info, gboolean is_hidden); + wifi_config_ip_info_s *ip_info, gboolean is_hidden, gboolean is_created); int _wifi_load_configurations(void); int _wifi_foreach_configuration(wifi_manager_config_list_cb callback, void *user_data); int _wifi_remove_configuration(const gchar *config_id); @@ -354,7 +356,7 @@ int _wifi_configuration_set_field(const gchar *config_id, const gchar *key, cons int _wifi_configuration_get_passphrase(const gchar *config_id, gchar **passphrase); int _wifi_save_eap_configurations(const gchar *name, const gchar *passphrase, wifi_manager_security_type_e security_type, const gchar *proxy_address, - wifi_eap_config_s *eap_config, gboolean is_hidden); + wifi_eap_config_s *eap_config, gboolean is_hidden, gboolean is_created); gchar *_wifi_eap_type_to_string(wifi_manager_eap_type_e eap_type); gchar *_wifi_eap_auth_type_to_string(wifi_manager_eap_auth_type_e eap_auth_type); int _wifi_set_autoscan(bool autoscan); diff --git a/packaging/capi-network-wifi-manager.spec b/packaging/capi-network-wifi-manager.spec index 7437aeb..ffd2027 100755 --- a/packaging/capi-network-wifi-manager.spec +++ b/packaging/capi-network-wifi-manager.spec @@ -1,6 +1,6 @@ Name: capi-network-wifi-manager Summary: Network Wi-Fi library in TIZEN C API -Version: 1.0.44 +Version: 1.0.45 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/network_dbus.c b/src/network_dbus.c index 0868308..4f2377e 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -2864,7 +2864,7 @@ int _net_dbus_config_get_passphrase(const gchar *config_id, gchar **passphrase) int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, - net_ip_info_config_s *ip_info, gboolean is_hidden) + net_ip_info_config_s *ip_info, gboolean is_hidden, gboolean is_created) { __NETWORK_FUNC_ENTER__; @@ -2886,6 +2886,7 @@ int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *na g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(proxy_address)); if (is_hidden == TRUE) g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string("TRUE")); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_CREATED, g_variant_new_boolean(is_created)); switch (ip_info->ip_type) { case NET_IP_CONFIG_TYPE_STATIC: @@ -2988,7 +2989,7 @@ int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *na int _net_dbus_config_save_eap_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, - const gchar *proxy_address, net_eap_config_s *eap_config, gboolean is_hidden) + const gchar *proxy_address, net_eap_config_s *eap_config, gboolean is_hidden, gboolean is_created) { __NETWORK_FUNC_ENTER__; @@ -3006,6 +3007,7 @@ int _net_dbus_config_save_eap_configurations(const gchar *config_id, g_variant_builder_add(b, "{sv}", WIFI_CONFIG_PROXYADDRESS, g_variant_new_string(proxy_address)); if (is_hidden == TRUE) g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string("TRUE")); + g_variant_builder_add(b, "{sv}", WIFI_CONFIG_CREATED, g_variant_new_boolean(is_created)); if (eap_config != NULL) { gchar* auth_type = NULL; @@ -3084,7 +3086,7 @@ int _net_dbus_config_remove_configurations(const gchar *config_id) } int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name, - net_wifi_security_type_e *security_type, gchar **proxy_address, + gchar **passphrase, net_wifi_security_type_e *security_type, gchar **proxy_address, gboolean *is_hidden, net_ip_info_config_s **ip_info, void *last_error) { __NETWORK_FUNC_ENTER__; @@ -3113,6 +3115,8 @@ int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name, if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) { if (g_strcmp0(field, WIFI_CONFIG_NAME) == 0) { *name = g_strdup(g_variant_get_string(value, NULL)); + } else if (g_strcmp0(field, WIFI_CONFIG_PASSPHRASE) == 0) { + *passphrase = g_strdup(g_variant_get_string(value, NULL)); } else if (g_strcmp0(field, WIFI_CONFIG_SECURITY_TYPE) == 0) { *security_type = __net_wifi_security_type_to_int(g_variant_get_string(value, NULL)); } else if (g_strcmp0(field, WIFI_CONFIG_HIDDEN) == 0) { diff --git a/src/network_interface.c b/src/network_interface.c index b6c5f0f..0b6ff12 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -3456,7 +3456,7 @@ int net_config_get_passphrase(const gchar *config_id, gchar **passphrase) int net_config_save_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, - net_ip_info_config_s *ip_info, gboolean is_hidden) + net_ip_info_config_s *ip_info, gboolean is_hidden, gboolean is_created) { __NETWORK_FUNC_ENTER__; @@ -3469,7 +3469,7 @@ int net_config_save_configurations(const gchar *config_id, const gchar *name, } Error = _net_dbus_config_save_configurations(config_id, name, ssid, - passphrase, proxy_address, ip_info, is_hidden); + passphrase, proxy_address, ip_info, is_hidden, is_created); if (Error != NET_ERR_NONE) WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE "Failed to save configurations. Error [%s]", @@ -3482,7 +3482,7 @@ int net_config_save_configurations(const gchar *config_id, const gchar *name, //LCOV_EXCL_START int net_config_save_eap_configurations(const gchar *config_id, const gchar *name, const gchar *ssid, const gchar *passphrase, - const gchar *proxy_address, void *eap_config, gboolean is_hidden) + const gchar *proxy_address, void *eap_config, gboolean is_hidden, gboolean is_created) { __NETWORK_FUNC_ENTER__; @@ -3495,8 +3495,8 @@ int net_config_save_eap_configurations(const gchar *config_id, return NET_ERR_APP_NOT_REGISTERED; } - Error = _net_dbus_config_save_eap_configurations(config_id, - name, ssid, passphrase, proxy_address, net_eap_config, is_hidden); + Error = _net_dbus_config_save_eap_configurations(config_id, name, ssid, passphrase, + proxy_address, net_eap_config, is_hidden, is_created); if (Error != NET_ERR_NONE) WIFI_LOG(WIFI_ERROR, "Failed to save configurations. Error [%s]", @@ -3530,7 +3530,7 @@ int net_config_remove_configurations(const gchar *config_id) } int net_config_load_configurations(const gchar *config_id, gchar **name, - void *security_type, gchar **proxy_address, gboolean *is_hidden, + gchar **passphrase, void *security_type, gchar **proxy_address, gboolean *is_hidden, net_ip_info_config_s **ip_info, void *last_error) { __NETWORK_FUNC_ENTER__; @@ -3544,8 +3544,8 @@ int net_config_load_configurations(const gchar *config_id, gchar **name, return NET_ERR_APP_NOT_REGISTERED; //LCOV_EXCL_LINE } - Error = _net_dbus_config_load_configurations(config_id, name, sec_type, - proxy_address, is_hidden, ip_info, last_error); + Error = _net_dbus_config_load_configurations(config_id, name, passphrase, + sec_type, proxy_address, is_hidden, ip_info, last_error); if (Error != NET_ERR_NONE) WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE "Failed to load configurations. Error [%s]", diff --git a/src/wifi_config.c b/src/wifi_config.c index 4f2868d..c0f0908 100755 --- a/src/wifi_config.c +++ b/src/wifi_config.c @@ -46,6 +46,7 @@ EXPORT_API int wifi_manager_config_create(wifi_manager_h wifi, const char *name, h->name = g_strdup(name); h->passphrase = g_strdup(passphrase); h->security_type = security_type; + h->is_created = TRUE; h->is_saved = FALSE; h->is_hidden = FALSE; h->proxy_address = NULL; @@ -125,6 +126,7 @@ EXPORT_API int wifi_manager_config_clone(wifi_manager_config_h origin, wifi_mana h->name = g_strdup(config->name); h->passphrase = g_strdup(config->passphrase); h->security_type = config->security_type; + h->is_created = FALSE; h->is_saved = config->is_saved; h->is_hidden = config->is_hidden; h->proxy_address = g_strdup(config->proxy_address); @@ -251,13 +253,13 @@ EXPORT_API int wifi_manager_config_save(wifi_manager_h wifi, } if (h->security_type == WIFI_MANAGER_SECURITY_TYPE_EAP) { - ret = _wifi_save_eap_configurations(h->name, h->passphrase, - h->security_type, h->proxy_address, h->eap_config, h->is_hidden); + ret = _wifi_save_eap_configurations(h->name, h->passphrase, h->security_type, + h->proxy_address, h->eap_config, h->is_hidden, h->is_created); if (ret != WIFI_MANAGER_ERROR_NONE) WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_eap_configurations"); //LCOV_EXCL_LINE } else { ret = _wifi_save_configuration(h->name, h->passphrase, h->security_type, - h->proxy_address, h->ip_info, h->is_hidden); + h->proxy_address, h->ip_info, h->is_hidden, h->is_created); if (ret != WIFI_MANAGER_ERROR_NONE) WIFI_LOG(WIFI_ERROR, "Fail to save configurations [%d]", ret); //LCOV_EXCL_LINE } diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 47a1776..75ead15 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -537,13 +537,13 @@ static int __connect_with_wifi_info(net_profile_info_s *ap_info) } static int __load_configurations(const gchar *config_id, gchar **name, - wifi_manager_security_type_e *security_type, gchar **proxy_address, + gchar **passphrase, wifi_manager_security_type_e *security_type, gchar **proxy_address, gboolean *is_hidden, wifi_config_ip_info_s **ip_info, wifi_manager_error_e *last_error) { int rv; - rv = net_config_load_configurations(config_id, name, security_type, + rv = net_config_load_configurations(config_id, name, passphrase, security_type, proxy_address, is_hidden, (net_ip_info_config_s **)ip_info, last_error); if (rv == NET_ERR_ACCESS_DENIED) { @@ -2812,7 +2812,7 @@ int _wifi_config_get_config_id_list(GSList **list) int _wifi_save_configuration(const gchar *name, const gchar *passphrase, wifi_manager_security_type_e security_type, const gchar *proxy_address, - wifi_config_ip_info_s *ip_info, gboolean is_hidden) + wifi_config_ip_info_s *ip_info, gboolean is_hidden, gboolean is_created) { int rv; gchar *config_id = NULL; @@ -2836,7 +2836,7 @@ int _wifi_save_configuration(const gchar *name, const gchar *passphrase, ssid = __wifi_change_name_to_hexadecimal(name); rv = net_config_save_configurations(config_id, name, ssid, passphrase, - proxy_address, (void *)ip_info, is_hidden); + proxy_address, (void *)ip_info, is_hidden, is_created); if (rv == NET_ERR_ACCESS_DENIED) { WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE @@ -2889,7 +2889,7 @@ int _wifi_load_configurations(void) g_free(h);//LCOV_EXCL_LINE break;//LCOV_EXCL_LINE } - rv = __load_configurations(id, &h->name, &h->security_type, + rv = __load_configurations(id, &h->name, &h->passphrase, &h->security_type, &h->proxy_address, &h->is_hidden, &h->ip_info, &h->last_error); } @@ -2997,7 +2997,7 @@ int _wifi_remove_configuration(const gchar *config_id) //LCOV_EXCL_START int _wifi_save_eap_configurations(const gchar *name, const gchar *passphrase, wifi_manager_security_type_e security_type, const gchar *proxy_address, - wifi_eap_config_s *eap_config, gboolean is_hidden) + wifi_eap_config_s *eap_config, gboolean is_hidden, gboolean is_created) { int rv; gchar *config_id = NULL; @@ -3024,8 +3024,8 @@ int _wifi_save_eap_configurations(const gchar *name, const gchar *passphrase, ssid = __wifi_change_name_to_hexadecimal(name); - rv = net_config_save_eap_configurations(config_id, name, - ssid, passphrase, proxy_address, (void *)eap_config, is_hidden); + rv = net_config_save_eap_configurations(config_id, name, ssid, passphrase, + proxy_address, (void *)eap_config, is_hidden, is_created); if (rv == NET_ERR_ACCESS_DENIED) { WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE -- 2.7.4 From 030a8f2138459f022fc79d55e7df6f33d61e0dab Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Wed, 26 Jun 2019 19:14:31 +0900 Subject: [PATCH 07/16] Check flight mode when bssid scan called Change-Id: I353760c0ff80604c74353b80c5aeec47ee4d8b3e Signed-off-by: hyunuktak --- packaging/capi-network-wifi-manager.spec | 2 +- src/wifi_internal.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packaging/capi-network-wifi-manager.spec b/packaging/capi-network-wifi-manager.spec index ffd2027..aa45ca9 100755 --- a/packaging/capi-network-wifi-manager.spec +++ b/packaging/capi-network-wifi-manager.spec @@ -1,6 +1,6 @@ Name: capi-network-wifi-manager Summary: Network Wi-Fi library in TIZEN C API -Version: 1.0.45 +Version: 1.0.46 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 75ead15..d688769 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -1961,6 +1961,12 @@ int _wifi_bssid_scan_request(wifi_manager_h wifi, int rv; wifi_manager_device_state_e device_state; int activated = -1; + int flight_mode = -1; + + if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode) != 0) { + WIFI_LOG(WIFI_ERROR, "Failed to get vconf key of flight mode"); + return WIFI_MANAGER_ERROR_OPERATION_FAILED; + } rv = _wifi_get_wifi_device_state(&device_state); if (rv == WIFI_MANAGER_ERROR_NONE) { @@ -1970,7 +1976,13 @@ int _wifi_bssid_scan_request(wifi_manager_h wifi, activated = 1; } - WIFI_LOG(WIFI_INFO, "Activated: %d", activated); + WIFI_LOG(WIFI_INFO, "Activated: %d, flight mode: %d", activated, flight_mode); + + if (activated == 0 && flight_mode > 0) { + WIFI_LOG(WIFI_INFO, "Invalid operation"); //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_INVALID_OPERATION; //LCOV_EXCL_LINE + } + rv = net_bssid_scan_wifi(activated); if (rv == NET_ERR_ACCESS_DENIED) { -- 2.7.4 From c52de7db746037604907d0910416e0b45a0550b5 Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Mon, 1 Jul 2019 15:39:30 +0900 Subject: [PATCH 08/16] Make a gcov package for coverage Change-Id: Ibb7a353efd8d93f38e90c55547ce74e329cfc75c Signed-off-by: Cheoleun Moon --- packaging/capi-network-wifi-manager.spec | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packaging/capi-network-wifi-manager.spec b/packaging/capi-network-wifi-manager.spec index 7437aeb..54a4b89 100755 --- a/packaging/capi-network-wifi-manager.spec +++ b/packaging/capi-network-wifi-manager.spec @@ -14,6 +14,9 @@ BuildRequires: pkgconfig(gthread-2.0) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-appfw-application) +%if 0%{?gcov:1} +BuildRequires: lcov +%endif Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -34,11 +37,26 @@ Summary: Test Application for Wi-Fi Manager %description tool Test Application for Wi-Fi Manager +%if 0%{?gcov:1} +%package gcov +Summary: Network Wi-Fi manager library(gcov) +Group: Network/Testing +%description gcov +gcov objects for coverage test +%endif + %prep %setup -q %build +%if 0%{?gcov:1} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" +export FFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov" +%endif + export CFLAGS+=' -Wno-unused-local-typedefs' #export CFLAGS+=' -Wno-unused-local-typedefs -fprofile-arcs -ftest-coverage' MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` @@ -51,9 +69,19 @@ cmake -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \ make %{?_smp_mflags} +%if 0%{?gcov:1} +mkdir -p gcov-obj +find . -name '*.gcno' -exec cp '{}' gcov-obj ';' +%endif + %install %make_install +%if 0%{?gcov:1} +mkdir -p %{buildroot}%{_datadir}/gcov/obj +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +%endif + %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -72,3 +100,8 @@ make %{?_smp_mflags} %files tool %{_bindir}/wifi_manager_test %{_bindir}/wifi_mgr_tool + +%if 0%{?gcov:1} +%files gcov +%{_datadir}/gcov/obj/* +%endif -- 2.7.4 From d14e1ea70e9212cb7a5f7fb4c8e95af1e5f0189f Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Mon, 1 Jul 2019 21:20:16 +0900 Subject: [PATCH 09/16] Corrected CAPI name and some doxygen comments Change-Id: I3e1450b287292e4229cca7437deb2c389687ac93 Signed-off-by: Jaehyun Kim --- include/wifi-manager.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 7042845..235dfb6 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -1380,13 +1380,13 @@ int wifi_manager_specific_scan_create(wifi_manager_h wifi, wifi_manager_specific int wifi_manager_specific_scan_destroy(wifi_manager_h wifi, wifi_manager_specific_scan_h specific_scan); /** - * @brief Gets the maximum number of SSIDs supported by wlan chipset for scan operation. + * @brief Gets the maximum number of SSIDs supported by the Wi-Fi chipset for the scan operation. * @since_tizen 5.5 * @privlevel public * @privilege %http://tizen.org/privilege/network.get * @param[in] wifi The Wi-Fi handle - * @param[out] max_scan_ssids The maximum number of SSIDs supported by wlan \n - * chipset for scan operation. + * @param[out] max_scan_ssids The maximum number of SSIDs supported by the Wi-Fi \n + * chipset for the scan operation. * @return 0 on success, otherwise negative error value * @retval #WIFI_MANAGER_ERROR_NONE Successful * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized @@ -1396,7 +1396,7 @@ int wifi_manager_specific_scan_destroy(wifi_manager_h wifi, wifi_manager_specifi * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported * @see wifi_manager_specific_scan_set_ssid() */ -int wifi_manager_specific_scan_get_max_ssid(wifi_manager_h wifi, int *max_scan_ssids); +int wifi_manager_specific_scan_get_max_ssids(wifi_manager_h wifi, int *max_scan_ssids); /** * @brief Sets the SSID of a specific AP scan. -- 2.7.4 From d6514d8cd056c75396de811dc5eea34b463f0324 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Thu, 4 Jul 2019 20:05:20 +0900 Subject: [PATCH 10/16] Corrected incorrectly checking of state value WIFI_MANAGER_CONNECTION_STATE_FAILURE is defined as -1 but it is considered to be an CAPI error in wifi_manager_ap_get_connection_state(). Change-Id: I28ddd2f0e1d2409a668a78166fcdc75674f76753 Signed-off-by: Jaehyun Kim --- src/wifi_ap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wifi_ap.c b/src/wifi_ap.c index c8f0d45..b21402f 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -706,7 +706,7 @@ EXPORT_API int wifi_manager_ap_get_connection_state(wifi_manager_ap_h ap, *state = _wifi_convert_to_ap_state(profile_info->ProfileState); - if (*state < 0) { + if (*state < -1) { /* __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE */ return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } -- 2.7.4 From 5cdac2e3ec108d04cc07fccc6785a96b16b0c4e3 Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Fri, 5 Jul 2019 18:34:05 +0530 Subject: [PATCH 11/16] Correct wifi_manager_specific_scan_get_max_ssids() API name as per wifi-manager.h header file Change-Id: I16330e3ecc402a56a37afb7953852d402fe032cc Signed-off-by: Nishant Chaprana --- packaging/capi-network-wifi-manager.spec | 2 +- src/wifi_manager.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/capi-network-wifi-manager.spec b/packaging/capi-network-wifi-manager.spec index 8e99a24..7c65fb5 100755 --- a/packaging/capi-network-wifi-manager.spec +++ b/packaging/capi-network-wifi-manager.spec @@ -1,6 +1,6 @@ Name: capi-network-wifi-manager Summary: Network Wi-Fi library in TIZEN C API -Version: 1.0.46 +Version: 1.0.47 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 29a8c24..1531af0 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -1731,7 +1731,7 @@ EXPORT_API int wifi_manager_specific_scan_destroy(wifi_manager_h wifi, return WIFI_MANAGER_ERROR_NONE; } -EXPORT_API int wifi_manager_specific_scan_get_max_ssid(wifi_manager_h wifi, int *max_scan_ssids) +EXPORT_API int wifi_manager_specific_scan_get_max_ssids(wifi_manager_h wifi, int *max_scan_ssids) { __NETWORK_CAPI_FUNC_ENTER__; -- 2.7.4 From aecb246ea4b3142d0c25672fb9f05c933414d582 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Mon, 8 Jul 2019 18:11:28 +0900 Subject: [PATCH 12/16] Corrected doxygen comments for specific scan APIs Change-Id: I1a06c4972b5515504cc07adcbdc4779c6318f41d Signed-off-by: Jaehyun Kim --- include/wifi-manager.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 235dfb6..ebf995a 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -1358,7 +1358,7 @@ int wifi_manager_scan_specific_ap(wifi_manager_h wifi, * @retval #WIFI_MANAGER_ERROR_OUT_OF_MEMORY Out of memory * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported * @pre This function needs a wifi_manager_initialize() call before use. - * @see wifi_manager_specific_scan_create() + * @see wifi_manager_specific_scan_destroy() */ int wifi_manager_specific_scan_create(wifi_manager_h wifi, wifi_manager_specific_scan_h *specific_scan); @@ -1375,7 +1375,7 @@ int wifi_manager_specific_scan_create(wifi_manager_h wifi, wifi_manager_specific * @retval #WIFI_MANAGER_ERROR_OUT_OF_MEMORY Out of memory * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported * @pre This function needs a wifi_manager_initialize() call before use. - * @see wifi_manager_specific_scan_destroy() + * @see wifi_manager_specific_scan_create() */ int wifi_manager_specific_scan_destroy(wifi_manager_h wifi, wifi_manager_specific_scan_h specific_scan); @@ -1410,7 +1410,7 @@ int wifi_manager_specific_scan_get_max_ssids(wifi_manager_h wifi, int *max_scan_ * @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 - * @see wifi_manager_specific_scan_set_ssid() + * @see wifi_manager_specific_scan_get_max_ssids() */ int wifi_manager_specific_scan_set_ssid(wifi_manager_specific_scan_h specific_scan, const char *essid); @@ -1426,7 +1426,6 @@ int wifi_manager_specific_scan_set_ssid(wifi_manager_specific_scan_h specific_sc * @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 - * @see wifi_manager_specific_scan_set_freq() */ int wifi_manager_specific_scan_set_freq(wifi_manager_specific_scan_h specific_scan, int freq); @@ -4389,6 +4388,7 @@ int wifi_manager_get_ip_conflict_state(wifi_manager_h wifi, * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported */ int wifi_manager_is_5ghz_band_supported(wifi_manager_h wifi, bool *supported); + /** * @} */ -- 2.7.4 From 6a920c20656609490fbcd34c1ef3a578729316ce Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Thu, 25 Apr 2019 21:13:49 +0900 Subject: [PATCH 13/16] Added CAPI to get the hidden property of access point Change-Id: If3e80eb3bf7b3d8a14577201c67be2f6923035d2 Signed-off-by: Jaehyun Kim --- include/wifi-manager.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 245aa72..a766914 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -2391,6 +2391,21 @@ int wifi_manager_ap_is_favorite(wifi_manager_ap_h ap, bool *favorite); int wifi_manager_ap_is_passpoint(wifi_manager_ap_h ap, bool *passpoint); /** + * @brief Checks whether the access point is hidden or not. + * @since_tizen 5.5 + * @param[in] ap The access point handle + * @param[out] is_hidden @c true if the access point is hidden, + * @c false if the access point is not hidden. + * @return 0 on success, otherwise negative error value + * @retval #WIFI_MANAGER_ERROR_NONE Successful + * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED Not supported + */ +int wifi_manager_ap_is_hidden(wifi_manager_ap_h ap, bool *is_hidden); + +/** * @brief Gets the connection state. * @since_tizen 3.0 * @param[in] ap The access point handle -- 2.7.4 From d0dfaa7c29446984f982454287e73bcf907bed22 Mon Sep 17 00:00:00 2001 From: Yu Date: Thu, 25 Jul 2019 14:49:24 +0900 Subject: [PATCH 14/16] Add support for OWE security mode Change-Id: I65fe3abe254a985e13e4977268218148f44d43fc --- include/network_interface.h | 2 ++ include/network_wlan.h | 3 ++- include/wifi-manager.h | 3 ++- src/network_dbus.c | 10 ++++++++-- src/network_interface.c | 3 +++ src/network_internal.c | 4 ++++ src/wifi_ap.c | 11 +++++++++++ src/wifi_internal.c | 8 ++++++++ test/wifi_manager_test.c | 1 + tool/wifi_mgr_tool.c | 2 ++ 10 files changed, 43 insertions(+), 4 deletions(-) diff --git a/include/network_interface.h b/include/network_interface.h index e800102..a07b01d 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -125,6 +125,8 @@ typedef enum { WIFI_SEC_WPA_PSK, WIFI_SEC_WPA2_PSK, WIFI_SEC_EAP, + WIFI_SEC_SAE, + WIFI_SEC_OWE, } net_wifi_security_type_e; typedef enum { diff --git a/include/network_wlan.h b/include/network_wlan.h index 58264aa..58b33c1 100755 --- a/include/network_wlan.h +++ b/include/network_wlan.h @@ -119,7 +119,8 @@ typedef enum { WLAN_SEC_MODE_WPA_PSK, /** WPA-PSK */ WLAN_SEC_MODE_WPA2_PSK, /** WPA2-PSK */ WLAN_SEC_MODE_WPA_FT_PSK, - WLAN_SEC_MODE_SAE, /** SAE */ + WLAN_SEC_MODE_SAE, /** SAE */ + WLAN_SEC_MODE_OWE, /** OWE */ } wlan_security_mode_type_e; /** diff --git a/include/wifi-manager.h b/include/wifi-manager.h index ebf995a..acf585b 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -374,7 +374,8 @@ typedef enum { WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK = 3, /**< WPA2-PSK */ WIFI_MANAGER_SECURITY_TYPE_EAP = 4, /**< EAP */ WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK = 5, /**< FT-PSK (Since 5.0) */ - WIFI_MANAGER_SECURITY_TYPE_SAE = 6, /**< SAE (Since 5.5) */ + WIFI_MANAGER_SECURITY_TYPE_SAE = 6, /**< SAE (Since 5.5) */ + WIFI_MANAGER_SECURITY_TYPE_OWE = 7, /**< OWE (Since 5.5) */ } wifi_manager_security_type_e; /** diff --git a/src/network_dbus.c b/src/network_dbus.c index 4f2377e..907aefb 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -27,6 +27,8 @@ #define WIFI_SECURITY_WEP "wep" #define WIFI_SECURITY_WPA_PSK "psk" #define WIFI_SECURITY_EAP "ieee8021x" +#define WIFI_SECURITY_SAE "sae" +#define WIFI_SECURITY_OWE "owe" extern __thread network_info_s NetworkInfo; extern __thread network_request_table_s request_table[NETWORK_REQUEST_TYPE_MAX]; @@ -128,6 +130,10 @@ static net_wifi_security_type_e __net_wifi_security_type_to_int(const gchar *typ ret = WIFI_SEC_WPA_PSK; else if (g_strcmp0(type, WIFI_SECURITY_EAP) == 0) ret = WIFI_SEC_EAP; + else if (g_strcmp0(type, WIFI_SECURITY_SAE) == 0) + ret = WIFI_SEC_SAE; + else if (g_strcmp0(type, WIFI_SECURITY_OWE) == 0) + ret = WIFI_SEC_OWE; else WIFI_LOG(WIFI_ERROR, "Not supported type (%s)", type); @@ -1335,7 +1341,6 @@ int _net_dbus_connect_service(const net_wifi_connect_service_info_t *wifi_connec goto error; //LCOV_EXCL_LINE } - if (wifi_connection_info->is_hidden == TRUE) { //LCOV_EXCL_START char *target_name = __net_make_group_name(wifi_connection_info->ssid, @@ -1368,7 +1373,8 @@ int _net_dbus_connect_service(const net_wifi_connect_service_info_t *wifi_connec wifi_connection_info->ssid, wifi_connection_info->passphrase, prof_info->ProfileName); - } else if (g_strcmp0(wifi_connection_info->security, "none") != 0) { + } else if (g_strcmp0(wifi_connection_info->security, "none") != 0 && + g_strcmp0(wifi_connection_info->security, "owe") != 0) { Error = _net_dbus_set_agent_passphrase_and_connect( wifi_connection_info->passphrase, prof_info->ProfileName); if (NET_ERR_NONE != Error) { diff --git a/src/network_interface.c b/src/network_interface.c index 0b6ff12..d058b7a 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -861,6 +861,9 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof else if (g_strcmp0(value, "sae") == 0 && ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE) ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_SAE; + else if (g_strcmp0(value, "owe") == 0 && + ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE) + ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_OWE; else if (g_strcmp0(value, "wps") == 0) ProfInfo->security_info.wps_support = TRUE; else if (ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_NONE) diff --git a/src/network_internal.c b/src/network_internal.c index 15f65f2..1e0bd17 100755 --- a/src/network_internal.c +++ b/src/network_internal.c @@ -288,6 +288,10 @@ int _net_open_connection_with_wifi_info(const net_wifi_connection_info_s* wifi_i (char *)wifi_info->security_info.authentication.sae.saeKey; break; + case WLAN_SEC_MODE_OWE: + wifi_connection_info.security = "owe"; + break; + case WLAN_SEC_MODE_IEEE8021X: wifi_connection_info.security = "ieee8021x"; diff --git a/src/wifi_ap.c b/src/wifi_ap.c index b21402f..08b1bc2 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -100,6 +100,9 @@ static char *__wifi_create_profile_name(const char *ssid, case WLAN_SEC_MODE_SAE: g_sec = "sae"; break; + case WLAN_SEC_MODE_OWE: + g_sec = "owe"; + break; default: WIFI_LOG(WIFI_ERROR, "Invalid security type"); return NULL; @@ -1684,6 +1687,9 @@ EXPORT_API int wifi_manager_ap_get_security_type(wifi_manager_ap_h ap, case WLAN_SEC_MODE_SAE: *type = WIFI_MANAGER_SECURITY_TYPE_SAE; break; + case WLAN_SEC_MODE_OWE: + *type = WIFI_MANAGER_SECURITY_TYPE_OWE; + break; default: /* __NETWORK_CAPI_FUNC_EXIT__; */ return WIFI_MANAGER_ERROR_OPERATION_FAILED; @@ -1733,6 +1739,9 @@ EXPORT_API int wifi_manager_ap_set_security_type(wifi_manager_ap_h ap, case WIFI_MANAGER_SECURITY_TYPE_SAE: profile_info->security_info.sec_mode = WLAN_SEC_MODE_SAE; break; + case WIFI_MANAGER_SECURITY_TYPE_OWE: + profile_info->security_info.sec_mode = WLAN_SEC_MODE_OWE; + break; default: __NETWORK_CAPI_FUNC_EXIT__; return WIFI_MANAGER_ERROR_INVALID_PARAMETER; @@ -1856,6 +1865,7 @@ EXPORT_API int wifi_manager_ap_is_passphrase_required(wifi_manager_ap_h ap, //LCOV_EXCL_START switch (profile_info->security_info.sec_mode) { case WLAN_SEC_MODE_NONE: + case WLAN_SEC_MODE_OWE: *required = false; break; case WLAN_SEC_MODE_WEP: @@ -1909,6 +1919,7 @@ EXPORT_API int wifi_manager_ap_set_passphrase(wifi_manager_ap_h ap, const char * break; case WLAN_SEC_MODE_NONE: case WLAN_SEC_MODE_IEEE8021X: + case WLAN_SEC_MODE_OWE: default: __NETWORK_CAPI_FUNC_EXIT__; return WIFI_MANAGER_ERROR_OPERATION_FAILED; diff --git a/src/wifi_internal.c b/src/wifi_internal.c index d688769..7b0a31e 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -32,6 +32,7 @@ static gboolean multi_scan_type[WIFI_MULTI_SCAN_MAX] = {0, }; #define WIFI_SECURITY_WPA_PSK "psk" #define WIFI_SECURITY_WPA_FT_PSK "ft_psk" #define WIFI_SECURITY_SAE "sae" +#define WIFI_SECURITY_OWE "owe" #define WIFI_SECURITY_EAP "ieee8021x" static __thread GSList *wifi_manager_handle_list = NULL; @@ -217,6 +218,9 @@ static gchar *__wifi_security_type_to_string(wifi_manager_security_type_e securi case WIFI_MANAGER_SECURITY_TYPE_SAE: return WIFI_SECURITY_SAE; + case WIFI_MANAGER_SECURITY_TYPE_OWE: + return WIFI_SECURITY_OWE; + case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK: return WIFI_SECURITY_WPA_FT_PSK; @@ -1903,6 +1907,9 @@ int _wifi_get_hidden_aps(wifi_manager_h wifi, const char *essid, case WLAN_SEC_MODE_SAE: type = WIFI_MANAGER_SECURITY_TYPE_SAE; break; + case WLAN_SEC_MODE_OWE: + type = WIFI_MANAGER_SECURITY_TYPE_OWE; + break; } if (prof_info->is_hidden == TRUE) { if (type == sec_type) { @@ -1943,6 +1950,7 @@ int _wifi_get_hidden_aps(wifi_manager_h wifi, const char *essid, passphrase, NET_WLAN_MAX_SAE_PASSPHRASE_LEN+1); break; case WLAN_SEC_MODE_NONE: + case WLAN_SEC_MODE_OWE: break; case WLAN_SEC_MODE_IEEE8021X: default: diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index 1beba73..b2dc850 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -1504,6 +1504,7 @@ static bool __test_found_specific_ap_callback(wifi_manager_ap_h ap, void *user_d } break; case WIFI_MANAGER_SECURITY_TYPE_NONE: + case WIFI_MANAGER_SECURITY_TYPE_OWE: default: break; } diff --git a/tool/wifi_mgr_tool.c b/tool/wifi_mgr_tool.c index cfcc767..eb77cda 100755 --- a/tool/wifi_mgr_tool.c +++ b/tool/wifi_mgr_tool.c @@ -498,6 +498,8 @@ const char *test_wifi_mgr_sec_type_to_string(wifi_manager_security_type_e type) return "FT_PSK"; case WIFI_MANAGER_SECURITY_TYPE_SAE: return "WPA3"; + case WIFI_MANAGER_SECURITY_TYPE_OWE: + return "OWE"; } return "Unknown"; -- 2.7.4 From bc390257aea1b71436e0580ceef2beb82f6f361d Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Wed, 17 Jul 2019 10:54:43 +0530 Subject: [PATCH 15/16] Added CAPI to get AP hidden status. Change-Id: I35b56a260a9e4d19e21a9b48691f22c15f50174d Signed-off-by: Niraj Kumar Goit --- include/network_interface.h | 1 + src/network_interface.c | 2 ++ src/wifi_ap.c | 23 +++++++++++++++++++++++ test/wifi_manager_test.c | 7 +++++++ 4 files changed, 33 insertions(+) diff --git a/include/network_interface.h b/include/network_interface.h index e800102..cdcd2d9 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -189,6 +189,7 @@ typedef struct { char country_code[NET_WLAN_COUNTRY_CODE_LEN]; /** Country code received from AP */ unsigned int connection_mode; /** Connection mode (IEEE 802.11b/g/n/a/ac) */ GSList *bssid_list; /** List if BSSID, strength and frequency of AP **/ + gboolean ap_hidden_status; /** Hidden Status of connected AP */ } net_profile_info_s; typedef struct { diff --git a/src/network_interface.c b/src/network_interface.c index 0b6ff12..6d35669 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -1057,6 +1057,8 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof } } g_variant_iter_free(iter_sub); + } else if (g_strcmp0(key, "Hidden") == 0) { + ProfInfo->ap_hidden_status = g_variant_get_boolean(var); } else Error = __net_extract_common_info(key, var, ProfInfo); } diff --git a/src/wifi_ap.c b/src/wifi_ap.c index b21402f..dd078f2 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -1943,6 +1943,29 @@ EXPORT_API int wifi_manager_ap_is_wps_supported(wifi_manager_ap_h ap, bool *supp return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_ap_is_hidden(wifi_manager_ap_h ap, bool *is_hidden) +{ + /* __NETWORK_CAPI_FUNC_ENTER__; */ + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (_wifi_check_ap_validity(ap) == false || is_hidden == 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; + + if (profile_info->ap_hidden_status) + *is_hidden = true; + else + *is_hidden = false; + + /* __NETWORK_CAPI_FUNC_EXIT__; */ + return WIFI_MANAGER_ERROR_NONE; +} + /* Wi-Fi EAP *****************************************************************/ EXPORT_API int wifi_manager_ap_set_eap_passphrase(wifi_manager_ap_h ap, const char *user_name, const char *password) diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index 1beba73..034bf58 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -1129,6 +1129,7 @@ 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; + bool is_hidden; rv = wifi_manager_ap_get_essid(ap, &ap_name); if (rv != WIFI_MANAGER_ERROR_NONE) { @@ -1178,6 +1179,12 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user printf("Favorite : %s\n", bool_value ? "TRUE" : "FALSE"); else printf("Fail to get Favorite\n"); + + if (wifi_manager_ap_is_hidden(ap, &is_hidden) == WIFI_MANAGER_ERROR_NONE) + printf("Hidden Status : %s\n", is_hidden ? "TRUE" : "FALSE"); + else + printf("Fail to get hidden status\n"); + if (wifi_manager_ap_get_disconnect_reason(ap, &disconnect_reason) == WIFI_MANAGER_ERROR_NONE) printf("Disconnect reason : %d\n", disconnect_reason); -- 2.7.4 From 2ca41ef0bee71ce8aec8403fd1480f53888b10c3 Mon Sep 17 00:00:00 2001 From: Yu Date: Tue, 20 Aug 2019 19:33:32 +0900 Subject: [PATCH 16/16] Add CAPI implementation for Device Provisioning Protocol Change-Id: I2406164f9d2193ac9b2002cebf8598a7becb0ecc Signed-off-by: Yu jiung --- doc/wifi_manager_doc.h | 25 ++ include/network_dbus.h | 14 + include/network_interface.h | 28 ++ include/network_internal.h | 16 ++ include/network_wlan.h | 1 + include/wifi-manager.h | 3 +- include/wifi_internal.h | 127 +++++++++ src/network_dbus.c | 266 +++++++++++++++++- src/network_interface.c | 152 +++++++++++ src/network_signal.c | 207 ++++++++++++++ src/wifi_ap.c | 10 + src/wifi_dpp.c | 508 ++++++++++++++++++++++++++++++++++ src/wifi_internal.c | 458 +++++++++++++++++++++++++++++++ tool/CMakeLists.txt | 1 + tool/wifi_mgr_public.c | 2 + tool/wifi_mgr_public_dpp.c | 650 ++++++++++++++++++++++++++++++++++++++++++++ tool/wifi_mgr_public_dpp.h | 20 ++ tool/wifi_mgr_tool.c | 108 ++++++++ tool/wifi_mgr_tool.h | 6 + 19 files changed, 2600 insertions(+), 2 deletions(-) create mode 100644 src/wifi_dpp.c create mode 100644 tool/wifi_mgr_public_dpp.c create mode 100644 tool/wifi_mgr_public_dpp.h diff --git a/doc/wifi_manager_doc.h b/doc/wifi_manager_doc.h index d26a8d9..721eab0 100755 --- a/doc/wifi_manager_doc.h +++ b/doc/wifi_manager_doc.h @@ -252,4 +252,29 @@ */ +/** + * @defgroup CAPI_NETWORK_WIFI_MANAGER_DPP_MODULE Wi-Fi Device Provisioning Protocol + * @brief The DPP API provides functions for managing the DPP of Wi-Fi. + * @ingroup CAPI_NETWORK_WIFI_MANAGER_MODULE + * + * @section CAPI_NETWORK_WIFI_MANAGER_DPP_MODULE Required Header + * \#include + * + * @section CAPI_NETWORK_WIFI_MANAGER_DPP_MODULE Overview + * The Configuration API provides functions for managing the DPP of Wi-Fi. You can manage the DPP process using the functions. + * @section CAPI_NETWORK_WIFI_MANAGER_DPP_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.wifi\n + * + * It is recommended to design applications with regard to features, for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, and control your application's actions accordingly.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature Element. + * + */ + + #endif /* __TIZEN_NETWORK_WIFI_MANAGER_DOC_H__ */ diff --git a/include/network_dbus.h b/include/network_dbus.h index f966e9a..96d5072 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -165,6 +165,20 @@ int _net_dbus_wifi_get_autoconnect(const char *profile_name, gboolean *autoconne int _net_dbus_get_5ghz_support(gboolean *supported); int _net_dbus_set_ip_conflict_period(unsigned int initial_time); +int _net_dbus_dpp_enter_peer_uri(guint32 peer_id, guint32 own_id, const char *uri); +int _net_dbus_dpp_generate_uri(guint32 peer_id, guint32 own_id, gboolean is_initiator, const char *key); + +int _net_dbus_dpp_start_configurator_initiator(const gchar *group_id, const gchar *ssid, + const gchar *peer_uri, guint32 peer_id, const gchar *net_role, + const gchar *akm, const gchar *configurator_key, const gchar *pass); +int _net_dbus_dpp_start_enrollee_initiator(const gchar *peer_uri, guint32 peer_id); +int _net_dbus_dpp_start_configurator_responder(const gchar *group_id, + const gchar *ssid, const gchar *net_role, const gchar *akm, + const gchar *auth_key, const gchar *configurator_key, const gchar *pass); +int _net_dbus_dpp_start_enrollee_responder(const gchar *auth_key); + +int _net_dbus_dpp_stop(guint32 peer_id, guint32 own_id, gboolean is_initiator); + #ifdef __cplusplus } diff --git a/include/network_interface.h b/include/network_interface.h index 624454a..42965c8 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -31,6 +31,7 @@ extern "C" { #define WIFI_INFO 1 #define WIFI_ERROR 2 #define WIFI_WARN 3 +#define MAX_DPP_URI_LEN 256 #define WIFI_LOG(log_level, format, args...) \ do { \ @@ -71,6 +72,21 @@ typedef enum { NET_EVENT_WIFI_TDLS_CONNECTED_IND, NET_EVENT_WIFI_TDLS_DISCONNECTED_IND, NET_EVENT_WIFI_FORGET_AP_IND, + NET_EVENT_WIFI_DPP_URI_GENERATED, + NET_EVENT_WIFI_DPP_BOOTSTRAPPED, + NET_EVENT_WIFI_DPP_AWAITING, + NET_EVENT_WIFI_DPP_AUTHENTICATING, + NET_EVENT_WIFI_DPP_AUTH_SUCCESS, + NET_EVENT_WIFI_DPP_AUTH_FAILED, + NET_EVENT_WIFI_DPP_NOT_COMPATIBLE, + NET_EVENT_WIFI_DPP_CONF_FAILED, + NET_EVENT_WIFI_DPP_SCAN_PEER_QR, + NET_EVENT_WIFI_DPP_NETWORK_ID, + NET_EVENT_WIFI_DPP_CONF_SENT, + NET_EVENT_WIFI_DPP_CONF_RECEIVED, + NET_EVENT_WIFI_DPP_FAILED, + NET_EVENT_WIFI_DPP_REMOVED, + NET_EVENT_WIFI_DPP_EVENT_IND, /* TODO: Make this in detail */ } net_event_e; typedef enum { @@ -127,6 +143,7 @@ typedef enum { WIFI_SEC_EAP, WIFI_SEC_SAE, WIFI_SEC_OWE, + WIFI_SEC_DPP, } net_wifi_security_type_e; typedef enum { @@ -273,6 +290,12 @@ typedef struct { gchar *dns_address[NET_DNS_ADDR_MAX]; } net_ip_info_config_s; +typedef struct { + guint32 peer_id; + guint32 own_id; + char own_uri[MAX_DPP_URI_LEN]; +} net_dpp_event_info_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); @@ -370,6 +393,11 @@ wifi_tech_state_e wifi_state_get_technology_state(void); int net_get_service_state(); int net_wifi_get_5ghz_support(gboolean *supported); +int net_dpp_enter_peer_uri(guint32 peer_id, guint32 own_id, const char *uri); +int net_dpp_generate_own_uri(guint32 peer_id, guint32 own_id, gboolean is_initiator, const char *key); +int net_dpp_start(void *dpp_data, const char *auth_key, + const char *configurator_key, const char *pass); +int net_dpp_stop(guint32 peer_id, guint32 own_id, gboolean is_initiator); /** * \} */ diff --git a/include/network_internal.h b/include/network_internal.h index e6cd880..9a81e97 100755 --- a/include/network_internal.h +++ b/include/network_internal.h @@ -102,6 +102,22 @@ extern "C" { #define NETCONFIG_SIGNAL_WIFI_CONNECT_FAIL "WiFiConnectFail" #define NETCONFIG_SIGNAL_WPS_FAIL_EVENT "WpsFailEvent" #define NETCONFIG_SIGNAL_IP_CONFLICT_EVENT "IpConflictEvent" +#define NETCONFIG_SIGNAL_DPP_URI_GENERATED "DppUriGenerated" +#define NETCONFIG_SIGNAL_DPP_BOOTSTRAPPED "DppBootstrapped" +#define NETCONFIG_SIGNAL_DPP_AWAITING "DppAwaiting" +#define NETCONFIG_SIGNAL_DPP_AUTHENTICATING "DppAuthenticating" +#define NETCONFIG_SIGNAL_DPP_AUTH_SUCCESS "DppAuthSuccess" +#define NETCONFIG_SIGNAL_DPP_AUTH_FAILED "DppAuthFailed" +#define NETCONFIG_SIGNAL_DPP_NOT_COMPATIBLE "DppNotCompatible" +#define NETCONFIG_SIGNAL_DPP_CONF_FAILED "DppConfFailed" +#define NETCONFIG_SIGNAL_DPP_SCAN_PEER_QR "DppScanPeerQr" +#define NETCONFIG_SIGNAL_DPP_NETWORK_ID "DppNetworkID" +#define NETCONFIG_SIGNAL_DPP_CONF_SENT "DppConfSent" +#define NETCONFIG_SIGNAL_DPP_CONF_RECEIVED "DppConfReceived" +#define NETCONFIG_SIGNAL_DPP_FAILED "DppFailed" +#define NETCONFIG_SIGNAL_DPP_REMOVED "DppRemoved" + + #define __NETWORK_FUNC_ENTER__ /*WIFI_LOG(WIFI_INFO, "Enter (%s)", __func__);*/ #define __NETWORK_FUNC_EXIT__ /*WIFI_LOG(WIFI_INFO, "Quit (%s)", __func__);*/ diff --git a/include/network_wlan.h b/include/network_wlan.h index 58b33c1..5f8df63 100755 --- a/include/network_wlan.h +++ b/include/network_wlan.h @@ -121,6 +121,7 @@ typedef enum { WLAN_SEC_MODE_WPA_FT_PSK, WLAN_SEC_MODE_SAE, /** SAE */ WLAN_SEC_MODE_OWE, /** OWE */ + WLAN_SEC_MODE_DPP, /** DPP */ } wlan_security_mode_type_e; /** diff --git a/include/wifi-manager.h b/include/wifi-manager.h index 5763929..fe12d7f 100755 --- a/include/wifi-manager.h +++ b/include/wifi-manager.h @@ -190,7 +190,6 @@ typedef enum { * @} */ - /** * @addtogroup CAPI_NETWORK_WIFI_MANAGER_MONITOR_MODULE * @{ @@ -376,6 +375,7 @@ typedef enum { WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK = 5, /**< FT-PSK (Since 5.0) */ WIFI_MANAGER_SECURITY_TYPE_SAE = 6, /**< SAE (Since 5.5) */ WIFI_MANAGER_SECURITY_TYPE_OWE = 7, /**< OWE (Since 5.5) */ + WIFI_MANAGER_SECURITY_TYPE_DPP = 8, /**< DPP (Since 5.5) */ } wifi_manager_security_type_e; /** @@ -4409,6 +4409,7 @@ int wifi_manager_is_5ghz_band_supported(wifi_manager_h wifi, bool *supported); * @} */ + #ifdef __cplusplus } #endif diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 1a62db6..7db289d 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -129,8 +129,54 @@ typedef enum { WIFI_MANAGER_TDLS_STATE_CHANGED_CB, WIFI_MANAGER_TDLS_DISCOVERED_CB, WIFI_MANAGER_FORGET_AP_CB, + WIFI_MANAGER_DPP_EVENT_CB, } wifi_manager_handle_cb_e; +typedef void *wifi_manager_dpp_h; + +typedef enum { + WIFI_MANAGER_DPP_ROLE_CONFIGURATOR, + WIFI_MANAGER_DPP_ROLE_ENROLLEE +} wifi_manager_dpp_role_e; + +typedef enum { + WIFI_MANAGER_DPP_NETWORK_ROLE_AP, + WIFI_MANAGER_DPP_NETWORK_ROLE_STA +} wifi_manager_dpp_network_role_e; + +typedef enum { + WIFI_MANAGER_DPP_AKM_PSK, + WIFI_MANAGER_DPP_AKM_SAE, + WIFI_MANAGER_DPP_AKM_DPP +} wifi_manager_dpp_akm_e; + +typedef enum { + WIFI_MANAGER_DPP_STATE_NONE, + WIFI_MANAGER_DPP_STATE_URI_REQUESTED, + WIFI_MANAGER_DPP_STATE_AWAITING, + WIFI_MANAGER_DPP_STATE_BOOTSTRAPPED, + WIFI_MANAGER_DPP_STATE_AUTHENTICATING, + WIFI_MANAGER_DPP_STATE_AUTHENTICATED, + WIFI_MANAGER_DPP_STATE_CONFIGURING, + WIFI_MANAGER_DPP_STATE_CONFIGURED, +} wifi_manager_dpp_state_e; + +typedef enum { + WIFI_MANAGER_DPP_EVENT_NONE, + WIFI_MANAGER_DPP_EVENT_REQUEST_FAILED, + WIFI_MANAGER_DPP_EVENT_URI_GENERATED, + WIFI_MANAGER_DPP_EVENT_SCAN_PEER_QR, + WIFI_MANAGER_DPP_EVENT_BUSY, + WIFI_MANAGER_DPP_EVENT_AUTH_FAILED, + WIFI_MANAGER_DPP_EVENT_NOT_COMPATIBLE, + WIFI_MANAGER_DPP_EVENT_CONF_FAILED, + WIFI_MANAGER_DPP_EVENT_TIMEOUT, + WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, +} wifi_manager_dpp_event_e; + +typedef void(*wifi_manager_dpp_event_cb)(wifi_manager_dpp_event_e event, + wifi_manager_dpp_state_e state, wifi_manager_dpp_h handle, void *user_data); + typedef enum { WIFI_MULTI_SCAN_SSID = 0x01, WIFI_MULTI_SCAN_FREQ, @@ -194,6 +240,20 @@ typedef struct { } wifi_config_s; typedef struct { + gchar *group_id; + gchar *ssid; + gchar *peer_uri; + guint32 peer_id; + gchar *own_uri; + guint32 own_id; + gboolean is_initiator; + wifi_manager_dpp_role_e role; + wifi_manager_dpp_network_role_e net_role; + wifi_manager_dpp_akm_e akm; + wifi_manager_dpp_state_e state; +} wifi_dpp_s; + +typedef struct { wifi_manager_device_state_changed_cb device_state_cb; void *device_state_user_data; wifi_manager_scan_finished_cb bg_scan_cb; @@ -232,6 +292,8 @@ typedef struct { void *netlink_scan_user_data; wifi_manager_forget_ap_finished_cb forget_ap_cb; void *forget_ap_user_data; + wifi_manager_dpp_event_cb dpp_event_cb; + void *dpp_event_user_data; } wifi_manager_handle_s; @@ -423,6 +485,71 @@ typedef enum { extern tizen_profile_t _get_tizen_profile(); int _wifi_get_service_state(); int _wifi_get_5ghz_support(bool *supported); + +/* WIFI DPP */ + +int wifi_manager_dpp_create(wifi_manager_h wifi, + bool is_initiator, wifi_manager_dpp_h *handle); + +int wifi_manager_dpp_destroy(wifi_manager_dpp_h handle); + +int wifi_manager_dpp_set_event_cb(wifi_manager_dpp_h handle, + wifi_manager_dpp_event_cb cb, void *user_data); + +int wifi_manager_dpp_unset_event_cb(wifi_manager_dpp_h handle); + +int wifi_manager_dpp_is_initiator(wifi_manager_dpp_h handle, + bool *is_initiator); + +int wifi_manager_dpp_get_state(wifi_manager_dpp_h handle, + wifi_manager_dpp_state_e *state); + +int wifi_manager_dpp_set_role(wifi_manager_dpp_h handle, + wifi_manager_dpp_role_e role); + +int wifi_manager_dpp_get_role(wifi_manager_dpp_h handle, + wifi_manager_dpp_role_e *role); + +int wifi_manager_dpp_set_group_id(wifi_manager_dpp_h handle, const char *group_id); + +int wifi_manager_dpp_get_group_id(wifi_manager_dpp_h handle, char **group_id); + +int wifi_manager_dpp_set_ssid(wifi_manager_dpp_h handle, const char *ssid); + +int wifi_manager_dpp_get_ssid(wifi_manager_dpp_h handle, char **ssid); + +int wifi_manager_dpp_set_network_role(wifi_manager_dpp_h handle, + const wifi_manager_dpp_network_role_e role); + +int wifi_manager_dpp_get_network_role(wifi_manager_dpp_h handle, + wifi_manager_dpp_network_role_e *role); + +int wifi_manager_dpp_set_akm(wifi_manager_dpp_h handle, + const wifi_manager_dpp_akm_e akm); + +int wifi_manager_dpp_get_akm(wifi_manager_dpp_h handle, + wifi_manager_dpp_akm_e *akm); + +int wifi_manager_dpp_enter_peer_uri(wifi_manager_dpp_h handle, const char *uri); + +int wifi_manager_dpp_request_own_uri_generation(wifi_manager_dpp_h handle, const char *key); + +int wifi_manager_dpp_get_own_uri(wifi_manager_dpp_h handle, char **uri); + +int wifi_manager_dpp_start(wifi_manager_dpp_h handle, + const char *auth_key, const char *configurator_key, const char *pass); + +int wifi_manager_dpp_stop(wifi_manager_dpp_h handle); + +bool _wifi_check_dpp_validity(wifi_manager_dpp_h dpp_h); +void _wifi_add_to_dpp_list(wifi_manager_dpp_h dpp_h); +void _wifi_remove_from_dpp_list(wifi_manager_dpp_h dpp_h); +int _wifi_dpp_enter_peer_uri(wifi_dpp_s *p_dpp, + const char *uri); +int _wifi_dpp_request_own_uri_gen(wifi_dpp_s *p_dpp, const char *key); +int _wifi_dpp_start(wifi_dpp_s *p_dpp, const char *auth_key, + const char *configurator_key, const char *pass); +int _wifi_dpp_stop(wifi_dpp_s *p_dpp); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/network_dbus.c b/src/network_dbus.c index 907aefb..5738bff 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -29,6 +29,7 @@ #define WIFI_SECURITY_EAP "ieee8021x" #define WIFI_SECURITY_SAE "sae" #define WIFI_SECURITY_OWE "owe" +#define WIFI_SECURITY_DPP "dpp" extern __thread network_info_s NetworkInfo; extern __thread network_request_table_s request_table[NETWORK_REQUEST_TYPE_MAX]; @@ -134,6 +135,8 @@ static net_wifi_security_type_e __net_wifi_security_type_to_int(const gchar *typ ret = WIFI_SEC_SAE; else if (g_strcmp0(type, WIFI_SECURITY_OWE) == 0) ret = WIFI_SEC_OWE; + else if (g_strcmp0(type, WIFI_SECURITY_DPP) == 0) + ret = WIFI_SEC_DPP; else WIFI_LOG(WIFI_ERROR, "Not supported type (%s)", type); @@ -2532,7 +2535,6 @@ int _net_dbus_open_connection_without_ssid() return Error; } - int _net_dbus_open_pin_connection_without_ssid(const char *pin) { __NETWORK_FUNC_ENTER__; @@ -2552,6 +2554,268 @@ int _net_dbus_open_pin_connection_without_ssid(const char *pin) return Error; } +int _net_dbus_dpp_enter_peer_uri(guint32 peer_id, guint32 own_id, const char *uri) +{ + __NETWORK_FUNC_ENTER__; + + GVariant *params = NULL; + GVariantBuilder *builder; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + /* TODO: send & handle dbus */ + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(peer_id)); + g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(own_id)); + g_variant_builder_add(builder, "{sv}", "uri", g_variant_new_string(uri)); + + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, + "DppEnterPeerUri", params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to DppEnterPeerUri"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully DppEnterPeerUri\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_dpp_generate_uri(guint32 peer_id, guint32 own_id, gboolean is_initiator, const char *key) +{ + __NETWORK_FUNC_ENTER__; + + GVariant *params = NULL; + GVariantBuilder *builder; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + /* TODO: send & handle dbus */ + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(peer_id)); + g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(own_id)); + g_variant_builder_add(builder, "{sv}", "is_initiator", g_variant_new_boolean (is_initiator)); + if (key) + g_variant_builder_add(builder, "{sv}", "key", g_variant_new_string(key)); + + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, + "DppGenerateUri", params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to DppGenerateUri"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully DppGenerateUri\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_dpp_start_configurator_initiator(const gchar *group_id, const gchar *ssid, + const gchar *peer_uri, guint32 peer_id, const gchar *net_role, + const gchar *akm, const gchar *configurator_key, const gchar *pass) +{ + __NETWORK_FUNC_ENTER__; + GVariant *params = NULL; + GVariantBuilder *builder; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + if (group_id) + g_variant_builder_add(builder, "{sv}", "group_id", g_variant_new_string(group_id)); + if (ssid) + g_variant_builder_add(builder, "{sv}", "ssid", g_variant_new_string(ssid)); + if (peer_uri) + g_variant_builder_add(builder, "{sv}", "peer_uri", g_variant_new_string(peer_uri)); + g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(peer_id)); + if (net_role) + g_variant_builder_add(builder, "{sv}", "net_role", g_variant_new_string(net_role)); + if (akm) + g_variant_builder_add(builder, "{sv}", "akm", g_variant_new_string(akm)); + if (configurator_key) + g_variant_builder_add(builder, "{sv}", "configurator_key", g_variant_new_string(configurator_key)); + if (pass) + g_variant_builder_add(builder, "{sv}", "pass", g_variant_new_string(pass)); + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, + "DppStartConfiguratorInitiator", params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to DppStartConfiguratorInitiator"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully DppStartConfiguratorInitiator\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_dpp_start_enrollee_initiator(const gchar *peer_uri, guint32 peer_id) +{ + __NETWORK_FUNC_ENTER__; + GVariant *params = NULL; + GVariantBuilder *builder; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + if (peer_uri) + g_variant_builder_add(builder, "{sv}", "peer_uri", g_variant_new_string(peer_uri)); + g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(peer_id)); + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, + "DppStartEnrolleeInitiator", params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to DppStartEnrolleeInitiator"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully DppStartEnrolleeInitiator\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_dpp_start_configurator_responder(const gchar *group_id, + const gchar *ssid, const gchar *net_role, const gchar *akm, + const gchar *auth_key, const gchar *configurator_key, const gchar *pass) +{ + __NETWORK_FUNC_ENTER__; + GVariant *params = NULL; + GVariantBuilder *builder; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + if (group_id) + g_variant_builder_add(builder, "{sv}", "group_id", g_variant_new_string(group_id)); + if (ssid) + g_variant_builder_add(builder, "{sv}", "ssid", g_variant_new_string(ssid)); + if (net_role) + g_variant_builder_add(builder, "{sv}", "net_role", g_variant_new_string(net_role)); + if (akm) + g_variant_builder_add(builder, "{sv}", "akm", g_variant_new_string(akm)); + if (auth_key) + g_variant_builder_add(builder, "{sv}", "auth_key", g_variant_new_string(auth_key)); + if (configurator_key) + g_variant_builder_add(builder, "{sv}", "configurator_key", g_variant_new_string(configurator_key)); + if (pass) + g_variant_builder_add(builder, "{sv}", "pass", g_variant_new_string(pass)); + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, + "DppStartConfiguratorResponder", params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to DppStartConfiguratorResponder"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully DppStartConfiguratorResponder\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_dpp_start_enrollee_responder(const gchar *auth_key) +{ + __NETWORK_FUNC_ENTER__; + GVariant *params = NULL; + GVariantBuilder *builder; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + if (auth_key) + g_variant_builder_add(builder, "{sv}", "auth_key", g_variant_new_string(auth_key)); + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, + "DppStartEnrolleeResponder", params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to DppStartEnrolleeResponder"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully DppStartEnrolleeResponder\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_dpp_stop(guint32 peer_id, guint32 own_id, gboolean is_initiator) +{ + __NETWORK_FUNC_ENTER__; + GVariant *params = NULL; + GVariantBuilder *builder; + GVariant *message = NULL; + net_err_e Error = NET_ERR_NONE; + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(peer_id)); + g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(own_id)); + g_variant_builder_add(builder, "{sv}", "is_initiator", g_variant_new_boolean (is_initiator)); + + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, + "DppStop", params, &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to stop DPP"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully stop DPP\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + int _net_dbus_tdls_disconnect(const char* peer_mac_addr) { __NETWORK_FUNC_ENTER__; diff --git a/src/network_interface.c b/src/network_interface.c index f579dec..1b8a49e 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -864,6 +864,9 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof else if (g_strcmp0(value, "owe") == 0 && ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE) ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_OWE; + else if (g_strcmp0(value, "dpp") == 0 && + ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_SAE) + ProfInfo->security_info.sec_mode = WLAN_SEC_MODE_DPP; else if (g_strcmp0(value, "wps") == 0) ProfInfo->security_info.wps_support = TRUE; else if (ProfInfo->security_info.sec_mode < WLAN_SEC_MODE_NONE) @@ -3883,4 +3886,153 @@ int net_wifi_get_max_scan_ssids(int *max_scan_ssids) __NETWORK_CAPI_FUNC_EXIT__; return NET_ERR_NONE; } + +static net_err_e __check_preconditions() +{ + net_err_e rv = NET_ERR_NONE; + + if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) { + WIFI_LOG(WIFI_ERROR, "Application is not registered\n"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + if (NetworkInfo.wifi_state == WIFI_OFF) { + if ((NetworkInfo.wifi_state = _net_get_wifi_state(&rv)) == WIFI_OFF) { + WIFI_LOG(WIFI_ERROR, "Wi-Fi is powered off!"); //LCOV_EXCL_LINE + __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE + return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE + } + } + + return rv; +} + +int net_dpp_enter_peer_uri(guint32 peer_id, guint32 own_id, const char *uri) +{ + net_err_e Error = NET_ERR_NONE; + + Error = __check_preconditions(); + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to enter peer uri : %d", Error); + /* TODO generate args, set request table value, handle return values*/ + + Error = _net_dbus_dpp_enter_peer_uri(peer_id, own_id, uri); + + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "Set Peer Uri dbus request failed. Error [%s]", + _net_print_error(Error)); + } + + return Error; +} + +int net_dpp_generate_own_uri(guint32 peer_id, guint32 own_id, gboolean is_initiator, const char *key) +{ + net_err_e Error = NET_ERR_NONE; + + Error = __check_preconditions(); + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to generate uri : %d", Error); + /* TODO generate args, set request table value, handle return values*/ + + Error = _net_dbus_dpp_generate_uri(peer_id, own_id, is_initiator, key); + + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "Generate URI dbus request failed. Error [%s]", + _net_print_error(Error)); + } + + return Error; +} + +static gchar *__dpp_network_role_to_string(wifi_manager_dpp_network_role_e role) +{ + if (role == WIFI_MANAGER_DPP_NETWORK_ROLE_AP) + return "ap"; + else if (role == WIFI_MANAGER_DPP_NETWORK_ROLE_STA) + return "sta"; + else + return NULL; +} + +static gchar *__dpp_akm_to_string(wifi_manager_dpp_akm_e akm) +{ + if (akm == WIFI_MANAGER_DPP_AKM_PSK) + return "psk"; + else if (akm == WIFI_MANAGER_DPP_AKM_SAE) + return "sae"; + else if (akm == WIFI_MANAGER_DPP_AKM_DPP) + return "dpp"; + else + return NULL; +} + +static net_err_e __net_dpp_start_each(wifi_dpp_s *p_dpp, const char *auth_key, + const char *configurator_key, const char *pass) +{ + int rv; + gboolean is_configurator = (p_dpp->role == WIFI_MANAGER_DPP_ROLE_CONFIGURATOR); + + if (p_dpp->is_initiator && is_configurator) + rv = _net_dbus_dpp_start_configurator_initiator(p_dpp->group_id, p_dpp->ssid, + p_dpp->peer_uri, p_dpp->peer_id, + __dpp_network_role_to_string(p_dpp->net_role), + __dpp_akm_to_string(p_dpp->akm), + configurator_key, pass); + else if (p_dpp->is_initiator && !is_configurator) + rv = _net_dbus_dpp_start_enrollee_initiator(p_dpp->peer_uri, p_dpp->peer_id); + else if (!p_dpp->is_initiator && is_configurator) + rv = _net_dbus_dpp_start_configurator_responder(p_dpp->group_id, p_dpp->ssid, + __dpp_network_role_to_string(p_dpp->net_role), + __dpp_akm_to_string(p_dpp->akm), + auth_key, configurator_key, pass); + else + rv = _net_dbus_dpp_start_enrollee_responder(auth_key); + + return rv; +} + +int net_dpp_start(void *dpp_data, const char *auth_key, + const char *configurator_key, const char *pass) +{ + net_err_e Error = NET_ERR_NONE; + + Error = __check_preconditions(); + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to start dpp uri : %d", Error); + /* TODO generate args, set request table value, handle return values*/ + + Error = __net_dpp_start_each((wifi_dpp_s *)dpp_data, auth_key, configurator_key, pass); + + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "DppStart dbus request failed. Error [%s]", + _net_print_error(Error)); + } + + return Error; +} + +int net_dpp_stop(guint32 peer_id, guint32 own_id, gboolean is_initiator) +{ + net_err_e Error = NET_ERR_NONE; + + Error = __check_preconditions(); + if (Error != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to stop dpp : %d", Error); + /* TODO generate args, set request table value, handle return values*/ + + Error = _net_dbus_dpp_stop(peer_id, own_id, is_initiator); + + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "DppStop dbus request failed. Error [%s]", + _net_print_error(Error)); + } + + return Error; +} //LCOV_EXCL_STOP diff --git a/src/network_signal.c b/src/network_signal.c index 3b88ffd..be3639e 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -1293,6 +1293,185 @@ static int __net_handle_ip_conflict_rsp(GVariant *param) return NET_ERR_NONE; } +static int __net_handle_dpp_uri_generated(GVariant *param) +{ + GVariantIter *iter = NULL; + GVariant *value = NULL; + gchar *key = NULL; + const gchar *uri_str = NULL; + net_dpp_event_info_s dpp_event_info = {0,}; + net_event_info_s event_data; + memset(&event_data, 0, sizeof(event_data)); + + g_variant_get(param, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "own_id") == 0) { + dpp_event_info.own_id = g_variant_get_uint32(value); + } else if (g_strcmp0(key, "own_uri") == 0) { + uri_str = g_variant_get_string(value, NULL); + if (uri_str && strlen(uri_str) > 0) + g_strlcpy(dpp_event_info.own_uri, uri_str, strlen(uri_str) + 1); + } + } + g_variant_iter_free(iter); + + WIFI_LOG(WIFI_INFO, + "Received the signal: %s", + NETCONFIG_SIGNAL_DPP_URI_GENERATED); + + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_WIFI_DPP_URI_GENERATED; + event_data.Datalength = sizeof(net_dpp_event_info_s); + event_data.Data = &dpp_event_info; + _net_client_callback(&event_data); + + return NET_ERR_NONE; +} + +static int __net_handle_dpp_bootstrapped(GVariant *param) +{ + GVariantIter *iter = NULL; + GVariant *value = NULL; + gchar *key = NULL; + net_dpp_event_info_s dpp_event_info; + dpp_event_info.peer_id = 0; + net_event_info_s event_data; + memset(&event_data, 0, sizeof(event_data)); + + g_variant_get(param, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "peer_id") == 0) + dpp_event_info.peer_id = g_variant_get_uint32(value); + } + g_variant_iter_free(iter); + + WIFI_LOG(WIFI_INFO, + "Received the signal: %s", + NETCONFIG_SIGNAL_DPP_BOOTSTRAPPED); + + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_WIFI_DPP_BOOTSTRAPPED; + event_data.Datalength = sizeof(net_dpp_event_info_s); + event_data.Data = &dpp_event_info; + _net_client_callback(&event_data); + + return NET_ERR_NONE; +} + +static int __net_handle_dpp_awaiting(GVariant *param) +{ + GVariantIter *iter = NULL; + GVariant *value = NULL; + gchar *key = NULL; + net_dpp_event_info_s dpp_event_info; + dpp_event_info.own_id = 0; + net_event_info_s event_data; + memset(&event_data, 0, sizeof(event_data)); + + g_variant_get(param, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "own_id") == 0) + dpp_event_info.own_id = g_variant_get_uint32(value); + } + g_variant_iter_free(iter); + + WIFI_LOG(WIFI_INFO, + "Received the signal: %s", + NETCONFIG_SIGNAL_DPP_AWAITING); + + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_WIFI_DPP_AWAITING; + event_data.Datalength = sizeof(net_dpp_event_info_s); + event_data.Data = &dpp_event_info; + _net_client_callback(&event_data); + + return NET_ERR_NONE; +} + + +static int __net_handle_dpp_events(GVariant *param, net_event_e event) +{ + GVariantIter *iter = NULL; + GVariant *value = NULL; + gchar *key = NULL; + net_dpp_event_info_s dpp_event_info; + dpp_event_info.peer_id = 0; + net_event_info_s event_data; + memset(&event_data, 0, sizeof(event_data)); + + g_variant_get(param, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "peer_id") == 0) + dpp_event_info.peer_id = g_variant_get_uint32(value); + else if (g_strcmp0(key, "own_id") == 0) + dpp_event_info.own_id = g_variant_get_uint32(value); + } + g_variant_iter_free(iter); + + event_data.Error = NET_ERR_NONE; + event_data.Event = event; + event_data.Datalength = sizeof(net_dpp_event_info_s); + event_data.Data = &dpp_event_info; + _net_client_callback(&event_data); + + return NET_ERR_NONE; +} + +static int __net_handle_dpp_failed(GVariant *param) +{ + net_event_info_s event_data; + memset(&event_data, 0, sizeof(event_data)); + + WIFI_LOG(WIFI_INFO, + "Received the signal: %s", + NETCONFIG_SIGNAL_DPP_FAILED); + + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_WIFI_DPP_FAILED; + _net_client_callback(&event_data); + + return NET_ERR_NONE; +} + +static int __net_handle_dpp_removed(GVariant *param) +{ + GVariantIter *iter = NULL; + GVariant *value = NULL; + gchar *key = NULL; + net_dpp_event_info_s dpp_event_info; + dpp_event_info.peer_id = 0; + dpp_event_info.own_id = 0; + net_event_info_s event_data; + memset(&event_data, 0, sizeof(event_data)); + + g_variant_get(param, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "peer_id") == 0) + dpp_event_info.peer_id = g_variant_get_uint32(value); + else if (g_strcmp0(key, "own_id") == 0) + dpp_event_info.own_id = g_variant_get_uint32(value); + } + g_variant_iter_free(iter); + + WIFI_LOG(WIFI_INFO, + "Received the signal: %s", + NETCONFIG_SIGNAL_DPP_REMOVED); + + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_WIFI_DPP_REMOVED; + event_data.Datalength = sizeof(net_dpp_event_info_s); + event_data.Data = &dpp_event_info; + _net_client_callback(&event_data); + + return NET_ERR_NONE; +} + + static void __net_connman_manager_signal_filter(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data) @@ -1329,6 +1508,34 @@ static void __net_netconfig_signal_filter(GDBusConnection *conn, __net_handle_wifi_wps_fail_event_rsp(param); else if (g_strcmp0(sig, NETCONFIG_SIGNAL_IP_CONFLICT_EVENT) == 0) __net_handle_ip_conflict_rsp(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_URI_GENERATED) == 0) + __net_handle_dpp_uri_generated(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_BOOTSTRAPPED) == 0) + __net_handle_dpp_bootstrapped(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_AWAITING) == 0) + __net_handle_dpp_awaiting(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_AUTHENTICATING) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_AUTHENTICATING); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_AUTH_SUCCESS) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_AUTH_SUCCESS); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_AUTH_FAILED) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_AUTH_FAILED); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_NOT_COMPATIBLE) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_NOT_COMPATIBLE); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_CONF_FAILED) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_CONF_FAILED); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_SCAN_PEER_QR) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_SCAN_PEER_QR); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_NETWORK_ID) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_NETWORK_ID); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_CONF_SENT) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_CONF_SENT); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_CONF_RECEIVED) == 0) + __net_handle_dpp_events(param, NET_EVENT_WIFI_DPP_CONF_RECEIVED); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_FAILED) == 0) + __net_handle_dpp_failed(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_DPP_REMOVED) == 0) + __net_handle_dpp_removed(param); } static void __net_netconfig_network_signal_filter(GDBusConnection *conn, diff --git a/src/wifi_ap.c b/src/wifi_ap.c index 30a9391..5e848bc 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -103,6 +103,9 @@ static char *__wifi_create_profile_name(const char *ssid, case WLAN_SEC_MODE_OWE: g_sec = "owe"; break; + case WLAN_SEC_MODE_DPP: + g_sec = "dpp"; + break; default: WIFI_LOG(WIFI_ERROR, "Invalid security type"); return NULL; @@ -1690,6 +1693,9 @@ EXPORT_API int wifi_manager_ap_get_security_type(wifi_manager_ap_h ap, case WLAN_SEC_MODE_OWE: *type = WIFI_MANAGER_SECURITY_TYPE_OWE; break; + case WLAN_SEC_MODE_DPP: + *type = WIFI_MANAGER_SECURITY_TYPE_DPP; + break; default: /* __NETWORK_CAPI_FUNC_EXIT__; */ return WIFI_MANAGER_ERROR_OPERATION_FAILED; @@ -1742,6 +1748,9 @@ EXPORT_API int wifi_manager_ap_set_security_type(wifi_manager_ap_h ap, case WIFI_MANAGER_SECURITY_TYPE_OWE: profile_info->security_info.sec_mode = WLAN_SEC_MODE_OWE; break; + case WIFI_MANAGER_SECURITY_TYPE_DPP: + profile_info->security_info.sec_mode = WLAN_SEC_MODE_DPP; + break; default: __NETWORK_CAPI_FUNC_EXIT__; return WIFI_MANAGER_ERROR_INVALID_PARAMETER; @@ -1866,6 +1875,7 @@ EXPORT_API int wifi_manager_ap_is_passphrase_required(wifi_manager_ap_h ap, switch (profile_info->security_info.sec_mode) { case WLAN_SEC_MODE_NONE: case WLAN_SEC_MODE_OWE: + case WLAN_SEC_MODE_DPP: *required = false; break; case WLAN_SEC_MODE_WEP: diff --git a/src/wifi_dpp.c b/src/wifi_dpp.c new file mode 100644 index 0000000..ba9b230 --- /dev/null +++ b/src/wifi_dpp.c @@ -0,0 +1,508 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "network_internal.h" +#include "wifi-manager.h" +#include "wifi_internal.h" + +/** + * Wifi DPP CAPI + */ +EXPORT_API int wifi_manager_dpp_create(wifi_manager_h wifi, + bool is_initiator, wifi_manager_dpp_h *handle) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = NULL; + + RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__); + + p_dpp = g_new0(wifi_dpp_s, 1); + if (p_dpp == NULL) { + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE + } + + p_dpp->is_initiator = is_initiator; + + _wifi_add_to_dpp_list((wifi_manager_dpp_h)p_dpp); + *handle = (wifi_manager_dpp_h)p_dpp; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_destroy(wifi_manager_dpp_h handle) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + g_free(p_dpp->group_id); + g_free(p_dpp->ssid); + g_free(p_dpp->peer_uri); + g_free(p_dpp->own_uri); + + _wifi_remove_from_dpp_list(handle); + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +static int __wifi_set_dpp_event_cb(wifi_manager_h wifi, + void *callback, void *user_data) +{ + wifi_manager_handle_s *local_handle = (wifi_manager_handle_s *)wifi; + + local_handle->dpp_event_cb = callback; + local_handle->dpp_event_user_data = user_data; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_set_event_cb(wifi_manager_h wifi, + wifi_manager_dpp_event_cb callback, void *user_data) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__); + + if (callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + __NETWORK_CAPI_FUNC_EXIT__; + return __wifi_set_dpp_event_cb(wifi, callback, user_data); +} + +EXPORT_API int wifi_manager_dpp_unset_event_cb(wifi_manager_h wifi) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__); + + __NETWORK_CAPI_FUNC_EXIT__; + return __wifi_set_dpp_event_cb(wifi, NULL, NULL); +} + +EXPORT_API int wifi_manager_dpp_is_initiator(wifi_manager_dpp_h handle, + bool *is_initiator) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || is_initiator == 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 + } + + *is_initiator = p_dpp->is_initiator; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_get_state(wifi_manager_dpp_h handle, + wifi_manager_dpp_state_e *state) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || state == 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 + } + + *state = p_dpp->state; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_set_role(wifi_manager_dpp_h handle, + wifi_manager_dpp_role_e role) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + p_dpp->role = role; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_get_role(wifi_manager_dpp_h handle, + wifi_manager_dpp_role_e *role) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || role == 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 + } + + *role = p_dpp->role; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_set_group_id(wifi_manager_dpp_h handle, const char *group_id) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || group_id == 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 + } + g_free(p_dpp->group_id); + p_dpp->group_id = g_strdup(group_id); + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_get_group_id(wifi_manager_dpp_h handle, char **group_id) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || group_id == 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 + } + + if (p_dpp->group_id != NULL) + *group_id = strdup(p_dpp->group_id); + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_set_ssid(wifi_manager_dpp_h handle, const char *ssid) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (!_wifi_check_essid_validity(ssid)) { + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE + } + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + g_free(p_dpp->ssid); + p_dpp->ssid = g_strdup(ssid); + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_get_ssid(wifi_manager_dpp_h handle, char **ssid) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || ssid == 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 + } + + if (p_dpp->ssid != NULL) + *ssid = strdup(p_dpp->ssid); + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_set_network_role(wifi_manager_dpp_h handle, + const wifi_manager_dpp_network_role_e role) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + p_dpp->net_role = role; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_get_network_role(wifi_manager_dpp_h handle, + wifi_manager_dpp_network_role_e *role) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || role == 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 + } + + *role = p_dpp->net_role; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_set_akm(wifi_manager_dpp_h handle, + const wifi_manager_dpp_akm_e akm) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + p_dpp->akm = akm; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_get_akm(wifi_manager_dpp_h handle, + wifi_manager_dpp_akm_e *akm) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || akm == 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 + } + + *akm = p_dpp->akm; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_enter_peer_uri(wifi_manager_dpp_h handle, const char *uri) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + int rv; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false || uri == 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 + } + + rv = _wifi_dpp_enter_peer_uri(p_dpp, uri); + if (rv != WIFI_MANAGER_ERROR_NONE) { + WIFI_LOG(WIFI_ERROR, "Failed entor peer URI[%d]", rv); //LCOV_EXCL_LINE + } else { + g_free(p_dpp->peer_uri); + p_dpp->peer_uri = NULL; + p_dpp->peer_uri = g_strdup(uri); + } + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} + +EXPORT_API int wifi_manager_dpp_request_own_uri_generation(wifi_manager_dpp_h handle, const char *key) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + int rv = WIFI_MANAGER_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + rv = _wifi_dpp_request_own_uri_gen(p_dpp, key); + if (rv != WIFI_MANAGER_ERROR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed generate own URI[%d]", rv); //LCOV_EXCL_LINE + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} + +EXPORT_API int wifi_manager_dpp_get_own_uri(wifi_manager_dpp_h handle, char **uri) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + if (p_dpp->own_uri != NULL) + *uri = strdup(p_dpp->own_uri); + + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_NONE; +} + +EXPORT_API int wifi_manager_dpp_start(wifi_manager_dpp_h handle, + const char *auth_key, const char *configurator_key, const char *pass) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + int rv; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + rv = _wifi_dpp_start(p_dpp, auth_key, configurator_key, pass); + if (rv != WIFI_MANAGER_ERROR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to start DPP[%d]", rv); //LCOV_EXCL_LINE + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} + +EXPORT_API int wifi_manager_dpp_stop(wifi_manager_dpp_h handle) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + int rv; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_dpp_s *p_dpp = (wifi_dpp_s *)handle; + + if (_wifi_check_dpp_validity(handle) == false) { + 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 + } + + rv = _wifi_dpp_stop(p_dpp); + if (rv != WIFI_MANAGER_ERROR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to stop DPP[%d]", rv); //LCOV_EXCL_LINE + + __NETWORK_CAPI_FUNC_EXIT__; + return rv; +} diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 7b0a31e..f89dd18 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -33,13 +33,22 @@ static gboolean multi_scan_type[WIFI_MULTI_SCAN_MAX] = {0, }; #define WIFI_SECURITY_WPA_FT_PSK "ft_psk" #define WIFI_SECURITY_SAE "sae" #define WIFI_SECURITY_OWE "owe" +#define WIFI_SECURITY_DPP "dpp" #define WIFI_SECURITY_EAP "ieee8021x" + +/* DPP related DBus calls are sync method. + * If DPP is not allowed to start from net-config, there's no g_p_dpp_current for lib. + * So, we should take care about changing DPP DBus call mechanism + */ +static __thread wifi_dpp_s *g_p_dpp_current = NULL; + static __thread GSList *wifi_manager_handle_list = NULL; static __thread GSList *ap_handle_list = NULL; static __thread GSList *config_handle_list = NULL; static __thread GSList *multi_scan_handle_list = NULL; static __thread GSList *netlink_scan_handle_list = NULL; +static __thread GSList *dpp_handle_list = NULL; static __thread GSList *profile_iterator = NULL; static __thread GSList *specific_profile_iterator = NULL; @@ -221,6 +230,9 @@ static gchar *__wifi_security_type_to_string(wifi_manager_security_type_e securi case WIFI_MANAGER_SECURITY_TYPE_OWE: return WIFI_SECURITY_OWE; + case WIFI_MANAGER_SECURITY_TYPE_DPP: + return WIFI_SECURITY_DPP; + case WIFI_MANAGER_SECURITY_TYPE_WPA_FT_PSK: return WIFI_SECURITY_WPA_FT_PSK; @@ -1151,6 +1163,240 @@ static void __forget_ap_cb(wifi_manager_error_e result) } } +static void __raise_dpp_event_callback(wifi_manager_dpp_event_e event, + wifi_manager_dpp_state_e state) +{ + GSList *list; + for (list = wifi_manager_handle_list; list; list = list->next) { + wifi_manager_handle_s *local_handle = (wifi_manager_handle_s *)list->data; + if (!local_handle->dpp_event_cb) + continue; + local_handle->dpp_event_cb(event, + state, + g_p_dpp_current, + local_handle->dpp_event_user_data); + } +} + +static void __dpp_uri_generated_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) { + g_p_dpp_current->own_uri = g_strdup(dpp_event_info->own_uri); + g_p_dpp_current->own_id = dpp_event_info->own_id; + } + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_URI_GENERATED, + WIFI_MANAGER_DPP_STATE_NONE); +} + +static void __dpp_bootstrapped_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) { + g_p_dpp_current->peer_id = dpp_event_info->peer_id; + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_BOOTSTRAPPED; + } + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_BOOTSTRAPPED); +} + +static void __dpp_awaiting_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AWAITING; + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_AWAITING); +} + +static void __dpp_authenticating_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AUTHENTICATING; + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_AUTHENTICATING); +} + +static void __dpp_auth_success_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_AUTHENTICATED; + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_AUTHENTICATED); +} + +static void __dpp_auth_failed_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_AUTH_FAILED, + WIFI_MANAGER_DPP_STATE_NONE); +} + +static void __dpp_not_compatible_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_NOT_COMPATIBLE, + WIFI_MANAGER_DPP_STATE_NONE); +} + +static void __dpp_conf_failed_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_CONF_FAILED, + WIFI_MANAGER_DPP_STATE_NONE); +} + +static void __dpp_scan_peer_qr_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_URI_REQUESTED; + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_URI_REQUESTED); +} + +static void __dpp_network_id_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURED; + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_CONFIGURED); +} + +static void __dpp_conf_sent_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURING; + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_CONFIGURING); +} + +static void __dpp_conf_received_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_CONFIGURED; + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_CONFIGURED); +} + +static void __dpp_failed_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) { + g_p_dpp_current->peer_id = 0; + g_p_dpp_current->own_id = 0; + g_free(g_p_dpp_current->own_uri); + g_p_dpp_current->own_uri = NULL; + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_NONE; + } + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_REQUEST_FAILED, + WIFI_MANAGER_DPP_STATE_NONE); + + g_p_dpp_current = NULL; +} + +static void __dpp_removed_cb(net_dpp_event_info_s *dpp_event_info) +{ + if (net_check_ref_count() != true) { + WIFI_LOG(WIFI_ERROR, "Application is not registered" + "If multi-threaded, thread integrity be broken."); + return; + } + + if (g_p_dpp_current) { + g_p_dpp_current->peer_id = 0; + g_p_dpp_current->own_id = 0; + g_free(g_p_dpp_current->own_uri); + g_p_dpp_current->own_uri = NULL; + g_p_dpp_current->state = WIFI_MANAGER_DPP_STATE_NONE; + } + + __raise_dpp_event_callback(WIFI_MANAGER_DPP_EVENT_STATE_CHANGED, + WIFI_MANAGER_DPP_STATE_NONE); + + g_p_dpp_current = NULL; +} + static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data) { bool is_requested = false; @@ -1384,6 +1630,48 @@ static void _wifi_evt_cb(net_event_info_s *event_cb, void *user_data) WIFI_LOG(WIFI_INFO, "Got Wi-Fi forget AP IND\n"); //LCOV_EXCL_LINE __forget_ap_cb(event_cb->Error); //LCOV_EXCL_LINE break; + case NET_EVENT_WIFI_DPP_URI_GENERATED: + __dpp_uri_generated_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_BOOTSTRAPPED: + __dpp_bootstrapped_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_AWAITING: + __dpp_awaiting_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_AUTHENTICATING: + __dpp_authenticating_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_AUTH_SUCCESS: + __dpp_auth_success_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_AUTH_FAILED: + __dpp_auth_failed_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_NOT_COMPATIBLE: + __dpp_not_compatible_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_CONF_FAILED: + __dpp_conf_failed_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_SCAN_PEER_QR: + __dpp_scan_peer_qr_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_NETWORK_ID: + __dpp_network_id_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_CONF_SENT: + __dpp_conf_sent_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_CONF_RECEIVED: + __dpp_conf_received_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_FAILED: + __dpp_failed_cb((net_dpp_event_info_s *)event_cb->Data); + break; + case NET_EVENT_WIFI_DPP_REMOVED: + __dpp_removed_cb((net_dpp_event_info_s *)event_cb->Data); + break; default: break; } @@ -1523,6 +1811,10 @@ int _wifi_get_callback_count_from_handle_list(wifi_manager_handle_cb_e e) if (local_handle->forget_ap_cb) ++count; break; + case WIFI_MANAGER_DPP_EVENT_CB: + if (local_handle->dpp_event_cb) + ++count; + break; default: break; } @@ -1557,6 +1849,16 @@ void __clear_config_list(GSList **iterator) } } +static void __free_dpp(gpointer data) +{ + wifi_dpp_s *p_dpp = (wifi_dpp_s *)data; + g_free(p_dpp->group_id); + g_free(p_dpp->own_uri); + g_free(p_dpp->peer_uri); + g_free(p_dpp->ssid); + g_free(p_dpp); +} + bool _wifi_deinit(void) { int rv = net_deregister_client_ext(); @@ -1575,6 +1877,9 @@ bool _wifi_deinit(void) __clear_config_list(&config_iterator); + g_slist_free_full(dpp_handle_list, __free_dpp); + g_p_dpp_current = NULL; + return true; } @@ -1910,6 +2215,9 @@ int _wifi_get_hidden_aps(wifi_manager_h wifi, const char *essid, case WLAN_SEC_MODE_OWE: type = WIFI_MANAGER_SECURITY_TYPE_OWE; break; + case WLAN_SEC_MODE_DPP: + type = WIFI_MANAGER_SECURITY_TYPE_DPP; + break; } if (prof_info->is_hidden == TRUE) { if (type == sec_type) { @@ -3581,3 +3889,153 @@ int _wifi_get_max_scan_ssids(int *max_scan_ssids) return WIFI_MANAGER_ERROR_NONE; } + +bool _wifi_check_dpp_validity(wifi_manager_dpp_h dpp_h) +{ + GSList *list = NULL; + + if (dpp_h == NULL) + return false; + + for (list = dpp_handle_list; list; list = list->next) + if (dpp_h == list->data) return true; + + return false; +} + +void _wifi_add_to_dpp_list(wifi_manager_dpp_h dpp_h) +{ + dpp_handle_list = g_slist_prepend(dpp_handle_list, dpp_h); +} + +void _wifi_remove_from_dpp_list(wifi_manager_dpp_h dpp_h) +{ + if (dpp_h == g_p_dpp_current) + g_p_dpp_current = NULL; + dpp_handle_list = g_slist_remove(dpp_handle_list, dpp_h); + g_free(dpp_h); +} + +static gboolean __is_new_initiator(wifi_dpp_s *p_dpp) +{ + return (p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_NONE); +} + +static gboolean __is_response_pending_initiator(wifi_dpp_s *p_dpp) +{ + return (p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_URI_REQUESTED); +} + +static gboolean __is_new_responder(wifi_dpp_s *p_dpp) +{ + return (!p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_NONE); +} + +static gboolean __is_peer_scan_requested_responder(wifi_dpp_s *p_dpp) +{ + return (!p_dpp->is_initiator) && (p_dpp->state == WIFI_MANAGER_DPP_STATE_URI_REQUESTED); +} + +static wifi_manager_error_e __convert_net_err_to_wifi_dpp_error(net_err_e err_type) +{ + switch (err_type) { + case NET_ERR_NONE: + return WIFI_MANAGER_ERROR_NONE; + case NET_ERR_IN_PROGRESS: + return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS; + case NET_ERR_ACCESS_DENIED: + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + case NET_ERR_INVALID_PARAM: + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + default: + return WIFI_MANAGER_ERROR_OPERATION_FAILED; + } +} + + +int _wifi_dpp_enter_peer_uri(wifi_dpp_s *p_dpp, + const char *uri) +{ + int rv = WIFI_MANAGER_ERROR_NONE; + + /* Just saving Peer URI for not bootstrapped initiator */ + if (__is_new_initiator(p_dpp)) + return rv; + + if (!__is_peer_scan_requested_responder(p_dpp)) + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + + if(g_p_dpp_current != p_dpp) + return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS; + + rv = net_dpp_enter_peer_uri(p_dpp->peer_id, p_dpp->own_id, uri); + + if (rv != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to enter peer URI"); + else + g_p_dpp_current = p_dpp; + + return __convert_net_err_to_wifi_dpp_error(rv); +} + +int _wifi_dpp_request_own_uri_gen(wifi_dpp_s *p_dpp, const char *key) +{ + int rv = WIFI_MANAGER_ERROR_NONE; + + if (!__is_response_pending_initiator(p_dpp)) + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + + if(g_p_dpp_current != p_dpp) + return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS; + + rv = net_dpp_generate_own_uri(p_dpp->peer_id, p_dpp->own_id, p_dpp->is_initiator, key); + + if (rv != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to generate own URI"); + + return __convert_net_err_to_wifi_dpp_error(rv); +} + +int _wifi_dpp_start(wifi_dpp_s *p_dpp, const char *auth_key, + const char *configurator_key, const char *pass) +{ + int rv = WIFI_MANAGER_ERROR_NONE; + + if (!__is_new_initiator(p_dpp) && + !__is_new_responder(p_dpp)) + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + + if(g_p_dpp_current) + return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS; + + rv = net_dpp_start((void *)p_dpp, auth_key, configurator_key, pass); + + if (rv != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to start"); + else + g_p_dpp_current = p_dpp; + + return __convert_net_err_to_wifi_dpp_error(rv); +} + +int _wifi_dpp_stop(wifi_dpp_s *p_dpp) +{ + int rv = WIFI_MANAGER_ERROR_NONE; + + if (__is_new_initiator(p_dpp) || + __is_new_responder(p_dpp)) + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + + if (!g_p_dpp_current) + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + + if(g_p_dpp_current != p_dpp) + return WIFI_MANAGER_ERROR_NOW_IN_PROGRESS; + + rv = net_dpp_stop(p_dpp->peer_id, p_dpp->own_id, p_dpp->is_initiator); + + if (rv != NET_ERR_NONE) + WIFI_LOG(WIFI_ERROR, "Failed to stop"); + + return __convert_net_err_to_wifi_dpp_error(rv); +} diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt index a2d657a..34f8c86 100755 --- a/tool/CMakeLists.txt +++ b/tool/CMakeLists.txt @@ -28,6 +28,7 @@ SET(wifi_mgr_tool_src wifi_mgr_public_tdls.c wifi_mgr_public_vsie.c wifi_mgr_public_ipconflict.c + wifi_mgr_public_dpp.c wifi_mgr_extension.c wifi_mgr_extension_autoscan.c wifi_mgr_extension_autoconnect.c diff --git a/tool/wifi_mgr_public.c b/tool/wifi_mgr_public.c index 76c4f80..a7fb4f8 100755 --- a/tool/wifi_mgr_public.c +++ b/tool/wifi_mgr_public.c @@ -41,6 +41,7 @@ extern struct menu_data menu_public_config[]; extern struct menu_data menu_public_tdls[]; extern struct menu_data menu_public_vsie[]; extern struct menu_data menu_public_ipconflict[]; +extern struct menu_data menu_public_dpp[]; static void __test_public_activated_cb(wifi_manager_error_e result, void* user_data) { @@ -329,5 +330,6 @@ struct menu_data menu_public[] = { { "t", "[TDLS]", menu_public_tdls, NULL, NULL}, { "v", "[VSIE]", menu_public_vsie, NULL, NULL}, { "i", "[IP Conflict]", menu_public_ipconflict, NULL, NULL}, + { "d", "[DPP]", menu_public_dpp, NULL, NULL}, { NULL, NULL, }, }; diff --git a/tool/wifi_mgr_public_dpp.c b/tool/wifi_mgr_public_dpp.c new file mode 100644 index 0000000..820ac24 --- /dev/null +++ b/tool/wifi_mgr_public_dpp.c @@ -0,0 +1,650 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "wifi_mgr_tool.h" +#include "wifi_mgr_menu.h" +#include "wifi_mgr_public_dpp.h" + + +#define WIFI_DPP_ENROLLEE_RESPONDER_AUTH_KEY "30770201010420965343A2843698032E2035BE5FEAC74249EBA2AC368467634B15D55E103C20CEA00A06082A8648CE3D030107A14403420004018EF2B0C34B9065D27E74DD4E34F1911CB20D1C3FC4A443A3C642D78389A91EAF3F9B3975BFFE53AC03EBA12752B2BBC7C8F771ECE124AD1A4E185F722F22A9" +#define WIFI_DPP_CONFIGURATOR_KEY "3077020101042041FBDC3730C1359E9CA33624BD8386FA15657EDE3345FC467F66031CA1238385A00A06082A8648CE3D030107A14403420004147A92156330B9FD2BC8997D4F02DFA38E72323BCE85468DEB2569D60247B4CE793C00A2FE90960D9E18E084712C0D900A1F3F499E616EEF5FFF56A0F416F54B" +#define WIFI_DPP_CONFIGURATOR_RESPONDER_AUTH_KEY "30770201010420FECD32BF73910579485CCF4E478149F691886B03BC8840B275F50814ACBF8BE6A00A06082A8648CE3D030107A144034200045C8242DEED3E60F9C8AC44A3A672F6302097C0853BD24C4A3093B5BFB2108CD1343963308D10A6021602FB3F5B4BCE8E778FAA23F53A30B667745DF16E0A1991" + +/* DPP Configurator SSID */ +static char g_ssid[MENU_DATA_SIZE] = "DPP-Network"; + +/* DPP Configurator Network Role */ +static char g_net_role[MENU_DATA_SIZE] = "1"; + +/* DPP Configurator AKM PSK */ +static char g_akm[MENU_DATA_SIZE] = "0"; + +/* DPP Configurator AKM PSK key*/ +static char g_psk_key[MENU_DATA_SIZE] = "wpapassword"; + +/* DPP Configurator AKM SAE key */ +static char g_sae_key[MENU_DATA_SIZE] = "saepassword"; + +/* DPP Enrollee Peer URI */ +static char g_enrollee_peer_uri[MENU_DATA_SIZE] = "DPP:C:81/6;M:f8:d1:11:62:c7:28;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADAY7ysMNLkGXSfnTdTjTxkRyyDRw/xKRDo8ZC14OJqR4=;;"; + +/* DPP Configurator Peer URI */ +static char g_configurator_peer_uri[MENU_DATA_SIZE] = "DPP:C:81/6;M:f8:d1:11:62:ba:d4;K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADXIJC3u0+YPnIrESjpnL2MCCXwIU70kxKMJO1v7IQjNE=;;"; + +static char g_pending_peer_uri[MENU_DATA_SIZE] = "Not yet determined"; + +static char g_pending_auth_key[MENU_DATA_SIZE] = "Not yet determined"; + +extern wifi_manager_h g_wifi_h; + +static wifi_manager_dpp_h g_wifi_dpp_h = NULL; + +static int _test_public_dpp_get_state(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + wifi_manager_dpp_state_e dpp_state = WIFI_MANAGER_DPP_STATE_NONE; + + ret = wifi_manager_dpp_get_state(g_wifi_dpp_h, &dpp_state); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) + msg("Succeeded to get DPP state " LOG_CYAN "[%s]" LOG_END, + test_wifi_mgr_dpp_state_to_string(dpp_state)); + else + msg("Fail to get DPP state " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_is_initiator(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + bool is_initiator = FALSE; + + ret = wifi_manager_dpp_is_initiator(g_wifi_dpp_h, &is_initiator); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) + msg("Succeeded to get is initiator " LOG_CYAN "[%s]" LOG_END, + is_initiator ? "Initiator" : "Responder"); + else + msg("Fail to get DPP is initiator " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_get_device_role(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + wifi_manager_dpp_role_e role = WIFI_MANAGER_DPP_ROLE_CONFIGURATOR; + + ret = wifi_manager_dpp_get_role(g_wifi_dpp_h, &role); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) + msg("Succeeded to get DPP device role " LOG_CYAN "[%s]" LOG_END, + test_wifi_mgr_dpp_device_role_to_string(role)); + else + msg("Fail to get DPP role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_get_ssid(MManager *mm, struct menu_data *menu) +{ + char *p_ssid = NULL; + int ret = WIFI_MANAGER_ERROR_NONE; + + + ret = wifi_manager_dpp_get_ssid(g_wifi_dpp_h, &p_ssid); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE && p_ssid) + msg("Succeeded to get DPP configurator SSID " LOG_CYAN "[%s]" LOG_END, + p_ssid); + else + msg("Fail to get DPP configurator SSID " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + if (p_ssid) + free(p_ssid); + + return ret; +} + +static int _test_public_dpp_get_network_role(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + wifi_manager_dpp_network_role_e role = WIFI_MANAGER_DPP_NETWORK_ROLE_STA; + + ret = wifi_manager_dpp_get_network_role(g_wifi_dpp_h, &role); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) + msg("Succeeded to get DPP configurator network role " LOG_CYAN "[%s]" LOG_END, + test_wifi_mgr_dpp_network_role_to_string(role)); + else + msg("Fail to get DPP network role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_get_akm(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + wifi_manager_dpp_akm_e akm = WIFI_MANAGER_DPP_AKM_DPP; + + ret = wifi_manager_dpp_get_akm(g_wifi_dpp_h, &akm); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) + msg("Succeeded to get DPP configurator AKM " LOG_CYAN "[%s]" LOG_END, + test_wifi_mgr_dpp_akm_to_string(akm)); + else + msg("Fail to get DPP network role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_get_own_uri(MManager *mm, struct menu_data *menu) +{ + char *p_own_uri = NULL; + int ret = WIFI_MANAGER_ERROR_NONE; + + + ret = wifi_manager_dpp_get_own_uri(g_wifi_dpp_h, &p_own_uri); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE && p_own_uri) + msg("Succeeded to get DPP own URI" LOG_CYAN "[%s]" LOG_END, + p_own_uri); + else + msg("Fail to get DPP own URI " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + if (p_own_uri) + free(p_own_uri); + + return ret; +} + +static const char *__get_akm_key(wifi_manager_dpp_akm_e akm) +{ + if (akm == WIFI_MANAGER_DPP_AKM_PSK) + return g_psk_key; + else if (akm == WIFI_MANAGER_DPP_AKM_SAE) + return g_sae_key; + + return NULL; +} + +static int _test_public_dpp_start_configurator_initiator(MManager *mm, struct menu_data *menu) +{ + wifi_manager_dpp_network_role_e net_role = (int)strtol(g_net_role, NULL, 10); + wifi_manager_dpp_akm_e akm = (int)strtol(g_akm, NULL, 10); + int ret = WIFI_MANAGER_ERROR_NONE; + + if (g_wifi_dpp_h) { + msg("Previous DPP process is in progress"); + return 0; + } + + ret = wifi_manager_dpp_create(g_wifi_h, TRUE, &g_wifi_dpp_h); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END); + } else { + msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_CONFIGURATOR); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP role " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_enter_peer_uri(g_wifi_dpp_h, g_enrollee_peer_uri); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set peer URI " LOG_CYAN LOG_END); + } else { + msg("Failed to set peer URI " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_ssid(g_wifi_dpp_h, g_ssid); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set configuration object SSID " LOG_CYAN "[%s]" LOG_END, g_ssid); + } else { + msg("Failed to set configuration object SSID " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_akm(g_wifi_dpp_h, akm); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP AKM " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP AKM " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_network_role(g_wifi_dpp_h, net_role); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP network role " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP network role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_start(g_wifi_dpp_h, NULL, WIFI_DPP_CONFIGURATOR_KEY, __get_akm_key(akm)); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to start DPP Configurator initiator " LOG_CYAN LOG_END); + } else { + msg("Failed to start DPP Configurator initiator " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + } + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_start_configurator_responder(MManager *mm, struct menu_data *menu) +{ + wifi_manager_dpp_network_role_e net_role = (int)strtol(g_net_role, NULL, 10); + wifi_manager_dpp_akm_e akm = (int)strtol(g_akm, NULL, 10); + int ret = WIFI_MANAGER_ERROR_NONE; + + if (g_wifi_dpp_h) { + msg("Previous DPP process is in progress"); + return 0; + } + + ret = wifi_manager_dpp_create(g_wifi_h, FALSE, &g_wifi_dpp_h); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END); + } else { + msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_CONFIGURATOR); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP role " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_ssid(g_wifi_dpp_h, g_ssid); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set configuration object SSID " LOG_CYAN "[%s]" LOG_END, g_ssid); + } else { + msg("Failed to set configuration object SSID " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_akm(g_wifi_dpp_h, akm); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP AKM " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP AKM " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_network_role(g_wifi_dpp_h, net_role); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP network role " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP network role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_start(g_wifi_dpp_h, + WIFI_DPP_CONFIGURATOR_RESPONDER_AUTH_KEY, + WIFI_DPP_CONFIGURATOR_KEY, + __get_akm_key(akm)); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to start DPP Configurator responder " LOG_CYAN LOG_END); + } else { + msg("Failed to start DPP Configurator responder " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + } + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_start_enrollee_initiator(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + + if (g_wifi_dpp_h) { + msg("Previous DPP process is in progress"); + return 0; + } + + ret = wifi_manager_dpp_create(g_wifi_h, TRUE, &g_wifi_dpp_h); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END); + } else { + msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_ENROLLEE); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP role " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_enter_peer_uri(g_wifi_dpp_h, g_configurator_peer_uri); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set peer URI " LOG_CYAN LOG_END); + } else { + msg("Failed to set peer URI " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_start(g_wifi_dpp_h, NULL, NULL, NULL); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to start DPP Enrollee initiator " LOG_CYAN LOG_END); + } else { + msg("Failed to start DPP Enrollee initiator " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + } + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_start_enrollee_responder(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + + if (g_wifi_dpp_h) { + msg("Previous DPP process is in progress"); + return 0; + } + + ret = wifi_manager_dpp_create(g_wifi_h, FALSE, &g_wifi_dpp_h); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg(LOG_GREEN "Succeeded to create DPP handle" LOG_END); + } else { + msg("Failed to create DPP handle " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + g_wifi_dpp_h = NULL; + return ret; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_set_role(g_wifi_dpp_h, WIFI_MANAGER_DPP_ROLE_ENROLLEE); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to set DPP role " LOG_CYAN LOG_END); + } else { + msg("Failed to set DPP role " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_start(g_wifi_dpp_h, + WIFI_DPP_ENROLLEE_RESPONDER_AUTH_KEY, NULL, NULL); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to start DPP Enrollee responder " LOG_CYAN LOG_END); + } else { + msg("Failed to start DPP Enrollee responder " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + wifi_manager_dpp_destroy(g_wifi_dpp_h); + g_wifi_dpp_h = NULL; + } + + msg(HR_SINGLE); + + return ret; +} + + +static int _test_public_dpp_enter_peer_uri(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + + ret = wifi_manager_dpp_enter_peer_uri(g_wifi_dpp_h, g_pending_peer_uri); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) + msg("Succeeded to set peer URI " LOG_CYAN LOG_END); + else + msg("Fail to set peer URI " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + + return ret; +} + +static int _test_dpp_generate_own_uri(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + + ret = wifi_manager_dpp_request_own_uri_generation(g_wifi_dpp_h, g_pending_peer_uri); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) + msg("Succeeded to generate own URI " LOG_CYAN LOG_END); + else + msg("Fail to generate own URI " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + + msg(HR_SINGLE); + + return ret; +} + +static int _test_public_dpp_stop(MManager *mm, struct menu_data *menu) +{ + int ret = WIFI_MANAGER_ERROR_NONE; + + if (!g_wifi_dpp_h) { + msg("There's no started DPP process"); + return 0; + } + + ret = wifi_manager_dpp_stop(g_wifi_dpp_h); + + msg(HR_SINGLE); + + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to stop DPP " LOG_CYAN LOG_END); + } else { + msg("Failed to stop DPP " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + } + + msg(HR_SINGLE); + + ret = wifi_manager_dpp_destroy(g_wifi_dpp_h); + if (ret == WIFI_MANAGER_ERROR_NONE) { + msg("Succeeded to destroy DPP " LOG_CYAN LOG_END); + } else { + msg("Failed to destroy DPP " LOG_RED "[%s]" LOG_END, + test_wifi_mgr_convert_error_to_string(ret)); + } + g_wifi_dpp_h = NULL; + + msg(HR_SINGLE); + + return ret; +} + + +struct menu_data menu_public_dpp_get[] = { + { "0", "state", NULL, _test_public_dpp_get_state, NULL}, + { "1", "is Initiator", NULL, _test_public_dpp_is_initiator, NULL}, + { "2", "device role", NULL, _test_public_dpp_get_device_role, NULL}, + { "3", "ssid", NULL, _test_public_dpp_get_ssid, NULL}, + { "4", "network role", NULL, _test_public_dpp_get_network_role, NULL}, + { "5", "AKM", NULL, _test_public_dpp_get_akm, NULL}, + { "6", "own URI", NULL, _test_public_dpp_get_own_uri, NULL}, + { NULL, NULL, }, +}; + +struct menu_data menu_public_dpp_start[] = { + { "0", "[Start] configurator initiator", NULL, _test_public_dpp_start_configurator_initiator, NULL}, + { "1", "[Start] configurator responder", NULL, _test_public_dpp_start_configurator_responder, NULL}, + { "2", "[Start] enrollee initiator", NULL, _test_public_dpp_start_enrollee_initiator, NULL}, + { "3", "[Start] enrollee responder", NULL, _test_public_dpp_start_enrollee_responder, NULL}, + { NULL, NULL, }, +}; + +struct menu_data menu_public_dpp[] = { + { "0", LOG_LIGHTGREEN "[Configuration SSID]" LOG_END, NULL, NULL, g_ssid}, + { "1", LOG_LIGHTGREEN "[Configuration Network Role 0:AP 1:STA]" LOG_END, NULL, NULL, g_net_role}, + { "2", LOG_LIGHTGREEN "[Configuration AKM 0:PSK 1:SAE 2:DPP]" LOG_END, NULL, NULL, g_akm}, + { "3", LOG_LIGHTGREEN "[Configuration PSK key]" LOG_END, NULL, NULL, g_psk_key}, + { "4", LOG_LIGHTGREEN "[Configuration SAE key]" LOG_END, NULL, NULL, g_sae_key}, + { "5", LOG_LIGHTGREEN "[Enrollee Peer URI]" LOG_END, NULL, NULL, g_enrollee_peer_uri}, + { "6", LOG_LIGHTGREEN "[Configurator Peer URI]" LOG_END, NULL, NULL, g_configurator_peer_uri}, + { "7", LOG_LIGHTGREEN "[Pending Peer URI]" LOG_END, NULL, NULL, g_pending_peer_uri}, + { "8", LOG_LIGHTGREEN "[Pending Auth Key]" LOG_END, NULL, NULL, g_pending_auth_key}, + { "p", "[Enter] peer URI" LOG_END, NULL, _test_public_dpp_enter_peer_uri, NULL}, + { "o", "[GENERATE] own URI" LOG_END, NULL, _test_dpp_generate_own_uri, NULL}, + { "s", LOG_LIGHTBLUE "[Start]" LOG_END, menu_public_dpp_start, NULL, NULL}, + { "t", LOG_LIGHTMAGENTA "[Stop]" LOG_END, NULL, _test_public_dpp_stop, NULL}, + { "g", LOG_LIGHTBLUE "[GET]" LOG_END, menu_public_dpp_get, NULL, NULL}, + { NULL, NULL, }, +}; diff --git a/tool/wifi_mgr_public_dpp.h b/tool/wifi_mgr_public_dpp.h new file mode 100644 index 0000000..86ea167 --- /dev/null +++ b/tool/wifi_mgr_public_dpp.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WIFI_MGR_PUBLIC_DPP_H__ +#define __WIFI_MGR_PUBLIC_DPP_H__ + +#endif /** __WIFI_MGR_PUBLIC_DPP_H__ */ diff --git a/tool/wifi_mgr_tool.c b/tool/wifi_mgr_tool.c index eb77cda..b6c9e5e 100755 --- a/tool/wifi_mgr_tool.c +++ b/tool/wifi_mgr_tool.c @@ -126,6 +126,16 @@ static void __test_tdls_discover_cb(wifi_manager_tdls_discovery_state_e state, msg(", Discovery is finished"); } +static void __test_dpp_event_cb(wifi_manager_dpp_event_e event, + wifi_manager_dpp_state_e state, wifi_manager_dpp_h handle, void *user_data) +{ + msgn("[%s] DPP event callback", (char *)user_data); + + msg(", event [%s]", test_wifi_mgr_dpp_event_to_string(event)); + if (event == WIFI_MANAGER_DPP_EVENT_STATE_CHANGED) + msg("state [%s]", test_wifi_mgr_dpp_state_to_string(state)); +} + static int _test_wifi_mgr_initialize(MManager *mm, struct menu_data *menu) { int ret = WIFI_MANAGER_ERROR_NONE; @@ -145,6 +155,8 @@ static int _test_wifi_mgr_initialize(MManager *mm, struct menu_data *menu) wifi_manager_tdls_set_state_changed_cb(g_wifi_h, __test_tdls_state_cb, "1"); wifi_manager_tdls_set_discovered_cb(g_wifi_h, __test_tdls_discover_cb, "1"); + wifi_manager_dpp_set_event_cb(g_wifi_h, __test_dpp_event_cb, "1"); + msg(LOG_GREEN "Success to initialize wifi [1] handle [%p]" LOG_END, g_wifi_h); } else { msg("Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END, @@ -166,6 +178,8 @@ static int _test_wifi_mgr_initialize(MManager *mm, struct menu_data *menu) wifi_manager_tdls_set_state_changed_cb(g_wifi2_h, __test_tdls_state_cb, "2"); wifi_manager_tdls_set_discovered_cb(g_wifi2_h, __test_tdls_discover_cb, "2"); + wifi_manager_dpp_set_event_cb(g_wifi2_h, __test_dpp_event_cb, "2"); + msg(LOG_GREEN "Success to initialize wifi [2] handle [%p]" LOG_END, g_wifi2_h); } else { msg("Failed to initialize wifi [2] handle " LOG_RED "[%s]" LOG_END, @@ -207,6 +221,8 @@ static int _test_wifi_mgr_initialize_cs(MManager *mm, struct menu_data *menu) wifi_manager_tdls_set_state_changed_cb(g_wifi_h, __test_tdls_state_cb, "1"); wifi_manager_tdls_set_discovered_cb(g_wifi_h, __test_tdls_discover_cb, "1"); + wifi_manager_dpp_set_event_cb(g_wifi_h, __test_dpp_event_cb, "1"); + msg(LOG_GREEN "Success to initialize wifi [1] handle [%p]" LOG_END, g_wifi_h); } else { msg("Failed to initialize wifi handle " LOG_RED "[%s]" LOG_END, @@ -228,6 +244,8 @@ static int _test_wifi_mgr_initialize_cs(MManager *mm, struct menu_data *menu) wifi_manager_tdls_set_state_changed_cb(g_wifi2_h, __test_tdls_state_cb, "2"); wifi_manager_tdls_set_discovered_cb(g_wifi2_h, __test_tdls_discover_cb, "2"); + wifi_manager_dpp_set_event_cb(g_wifi2_h, __test_dpp_event_cb, "2"); + msg(LOG_GREEN "Success to initialize wifi [2] handle [%p]" LOG_END, g_wifi2_h); } else { msg("Failed to initialize wifi [2] handle " LOG_RED "[%s]" LOG_END, @@ -500,6 +518,8 @@ const char *test_wifi_mgr_sec_type_to_string(wifi_manager_security_type_e type) return "WPA3"; case WIFI_MANAGER_SECURITY_TYPE_OWE: return "OWE"; + case WIFI_MANAGER_SECURITY_TYPE_DPP: + return "DPP"; } return "Unknown"; @@ -587,6 +607,94 @@ const char *test_wifi_mgr_convert_error_to_string(wifi_manager_error_e err_type) } } +const char *test_wifi_mgr_dpp_state_to_string(wifi_manager_dpp_state_e state) +{ + switch (state) { + case WIFI_MANAGER_DPP_STATE_NONE: + return "NONE"; + case WIFI_MANAGER_DPP_STATE_URI_REQUESTED: + return "URI_REQUESTED"; + case WIFI_MANAGER_DPP_STATE_AWAITING: + return "AWAITING"; + case WIFI_MANAGER_DPP_STATE_BOOTSTRAPPED: + return "BOOTSTRAPPED"; + case WIFI_MANAGER_DPP_STATE_AUTHENTICATING: + return "AUTHENTICATING"; + case WIFI_MANAGER_DPP_STATE_AUTHENTICATED: + return "AUTHENTICATED"; + case WIFI_MANAGER_DPP_STATE_CONFIGURING: + return "CONFIGURING"; + case WIFI_MANAGER_DPP_STATE_CONFIGURED: + return "CONFIGURED"; + default: + return "UNKNOWN"; + } +} + +const char *test_wifi_mgr_dpp_event_to_string(wifi_manager_dpp_event_e event) +{ + switch (event) { + case WIFI_MANAGER_DPP_EVENT_REQUEST_FAILED: + return "REQUEST_FAILED"; + case WIFI_MANAGER_DPP_EVENT_URI_GENERATED: + return "URI_GENERATED"; + case WIFI_MANAGER_DPP_EVENT_SCAN_PEER_QR: + return "SCAN_PEER_QR"; + case WIFI_MANAGER_DPP_EVENT_BUSY: + return "BUSY"; + case WIFI_MANAGER_DPP_EVENT_AUTH_FAILED: + return "AUTH_FAILED"; + case WIFI_MANAGER_DPP_EVENT_NOT_COMPATIBLE: + return "NOT_COMPATIBLE"; + case WIFI_MANAGER_DPP_EVENT_CONF_FAILED: + return "CONF FAILED"; + case WIFI_MANAGER_DPP_EVENT_TIMEOUT: + return "TIMEOUT"; + case WIFI_MANAGER_DPP_EVENT_STATE_CHANGED: + return "STATE_CHANGED"; + default: + return "UNKNOWN"; + } +} + +const char *test_wifi_mgr_dpp_device_role_to_string(wifi_manager_dpp_role_e role) +{ + switch (role) { + case WIFI_MANAGER_DPP_ROLE_CONFIGURATOR: + return "CONFIGURATOR"; + case WIFI_MANAGER_DPP_ROLE_ENROLLEE: + return "ENROLLEE"; + default: + return "UNKNOWN"; + } +} + +const char *test_wifi_mgr_dpp_network_role_to_string(wifi_manager_dpp_network_role_e role) +{ + switch (role) { + case WIFI_MANAGER_DPP_NETWORK_ROLE_AP: + return "AP"; + case WIFI_MANAGER_DPP_NETWORK_ROLE_STA: + return "STA"; + default: + return "UNKNOWN"; + } +} + +const char *test_wifi_mgr_dpp_akm_to_string(wifi_manager_dpp_akm_e akm) +{ + switch (akm) { + case WIFI_MANAGER_DPP_AKM_PSK: + return "PSK"; + case WIFI_MANAGER_DPP_AKM_SAE: + return "SAE"; + case WIFI_MANAGER_DPP_AKM_DPP: + return "DPP"; + default: + return "UNKNOWN"; + } +} + int main(int arg, char **argv) { GMainLoop *mainloop = NULL; diff --git a/tool/wifi_mgr_tool.h b/tool/wifi_mgr_tool.h index 35cf118..b0f62ac 100755 --- a/tool/wifi_mgr_tool.h +++ b/tool/wifi_mgr_tool.h @@ -20,6 +20,7 @@ #include #include #include +#include #define MALLOC0(t, n) ((t*) g_try_malloc0((n) * sizeof(t))) #define FREE(p) do { \ @@ -44,5 +45,10 @@ const char *test_wifi_mgr_ip_config_type_to_string(wifi_manager_ip_config_type_e const char *test_wifi_mgr_sec_type_to_string(wifi_manager_security_type_e type); const char *test_wifi_mgr_conn_state_to_string(wifi_manager_connection_state_e state); const char *test_wifi_mgr_convert_error_to_string(wifi_manager_error_e err_type); +const char *test_wifi_mgr_dpp_state_to_string(wifi_manager_dpp_state_e state); +const char *test_wifi_mgr_dpp_event_to_string(wifi_manager_dpp_event_e event); +const char *test_wifi_mgr_dpp_akm_to_string(wifi_manager_dpp_akm_e akm); +const char *test_wifi_mgr_dpp_network_role_to_string(wifi_manager_dpp_network_role_e role); +const char *test_wifi_mgr_dpp_device_role_to_string(wifi_manager_dpp_role_e role); #endif /* __WIFI_MGR_TOOL_H__ */ -- 2.7.4