From: Yu Date: Tue, 20 Aug 2019 10:33:32 +0000 (+0900) Subject: Add CAPI implementation for Device Provisioning Protocol X-Git-Tag: accepted/tizen/unified/20191007.234753^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F45%2F212345%2F6;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Add CAPI implementation for Device Provisioning Protocol Change-Id: I2406164f9d2193ac9b2002cebf8598a7becb0ecc Signed-off-by: Yu jiung --- 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__ */