--- /dev/null
+/*
+ * Network Configuration Module
+ *
+ * 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 <string.h>
+#include <glib.h>
+
+#include <vconf.h>
+#include <vconf-keys.h>
+
+#include "log.h"
+#include "util.h"
+#include "netdbus.h"
+#include "netsupplicant.h"
+#include "neterror.h"
+#include "wifi-config.h"
+#include "wifi-dpp.h"
+#include "wifi-key-encryption.h"
+
+#define DEFAULT_BOOTSTRAP_TYPE "qrcode"
+#define DEFAULT_DPP_CHANNEL "81/6"
+#define DEFAULT_DPP_FREQ 2437
+
+#define DEFAULT_DPP_CONFIG_PROCESSING_TYPE "0"
+
+#define MACADDR_LEN 6
+#define MACSTR_LEN 18
+#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
+#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
+
+typedef enum {
+ WIFI_DPP_AKM_UNKNOWN,
+ WIFI_DPP_AKM_PSK,
+ WIFI_DPP_AKM_SAE,
+ WIFI_DPP_AKM_DPP,
+} wifi_dpp_akm_e;
+
+typedef enum {
+ WIFI_DPP_STATE_NONE,
+ WIFI_DPP_STATE_AWAITING,
+ WIFI_DPP_STATE_PEER_QR_REQUESTED,
+ WIFI_DPP_STATE_BOOTSTRAPPED,
+ WIFI_DPP_STATE_AUTHENTICATING,
+ WIFI_DPP_STATE_AUTHENTICATED,
+ WIFI_DPP_STATE_CONFIGURED,
+ WIFI_DPP_STATE_CONNECTING,
+ WIFI_DPP_STATE_CONNECTED,
+} wifi_dpp_state_e;
+
+typedef struct {
+ gchar *ssid;
+ gchar *akm;
+ gchar *passphrase;
+ gchar *connector;
+ gchar *c_sign_key;
+ gchar *net_access_key;
+} wifi_dpp_conf_obj;
+
+typedef struct {
+ guint32 peer_id;
+ guint32 own_id;
+ guint32 configurator_id;
+ gboolean is_initiator;
+ wifi_dpp_state_e state;
+} wifi_dpp_s;
+
+gboolean g_in_progress = FALSE;
+static GSList *dpp_info_list = NULL;
+
+static wifi_dpp_s *_get_dpp_info(guint32 peer_id, guint32 own_id)
+{
+ wifi_dpp_s *ret = NULL;
+ GSList *list = NULL;
+
+ for (list = dpp_info_list; list; list = list->next) {
+ ret = list->data;
+ if (ret->own_id == own_id && ret->peer_id == peer_id)
+ break;
+ ret = NULL;
+ }
+ return ret;
+}
+
+static wifi_dpp_s *_get_dpp_in_progress()
+{
+ wifi_dpp_s *ret = NULL;
+ GSList *list = NULL;
+
+ for (list = dpp_info_list; list; list = list->next) {
+ ret = list->data;
+ if (ret->state > WIFI_DPP_STATE_NONE)
+ break;
+ ret = NULL;
+ }
+ return ret;
+}
+
+static wifi_dpp_s *__create_dpp_info(gboolean is_initiator)
+{
+ wifi_dpp_s *ret = g_try_malloc0(sizeof(wifi_dpp_s));
+ if (ret)
+ ret->is_initiator = is_initiator;
+
+ return ret;
+}
+
+static void __add_to_dpp_info_list(wifi_dpp_s * p_dpp)
+{
+ dpp_info_list = g_slist_prepend(dpp_info_list, p_dpp);
+}
+
+static void __remove_from_dpp_info_list(wifi_dpp_s * p_dpp)
+{
+ dpp_info_list = g_slist_remove(dpp_info_list, p_dpp);
+}
+
+static void __destroy_dpp_info(wifi_dpp_s *p_dpp)
+{
+ g_free(p_dpp);
+}
+
+
+static void __free_critical(char *critical)
+{
+ size_t length = 0;
+ if (!critical)
+ return;
+
+ length = strlen(critical);
+ memset((void *)critical, 0x0, length);
+ g_free(critical);
+}
+
+static void __netconfig_wifi_notify_dpp_uri_generated(guint32 own_id, const gchar *own_uri)
+{
+ GVariantBuilder *builder = NULL;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(own_id));
+ g_variant_builder_add(builder, "{sv}", "own_uri", g_variant_new_string(own_uri));
+
+ wifi_emit_dpp_uri_generated((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ return;
+}
+
+static void __netconfig_wifi_notify_dpp_bootstrapped(guint32 peer_id)
+{
+ GVariantBuilder *builder = NULL;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(peer_id));
+
+ wifi_emit_dpp_bootstrapped((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ return;
+}
+
+static void __netconfig_wifi_notify_dpp_awaiting(guint32 own_id)
+{
+ GVariantBuilder *builder = NULL;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(own_id));
+
+ wifi_emit_dpp_awaiting((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ return;
+}
+
+static void __netconfig_wifi_notify_dpp_authenticating(guint32 peer_id, guint32 own_id)
+{
+ GVariantBuilder *builder = NULL;
+
+ 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));
+
+ wifi_emit_dpp_authenticating((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ return;
+}
+
+static void __netconfig_wifi_notify_dpp_failed()
+{
+ wifi_emit_dpp_failed((Wifi *)get_wifi_object());
+
+ return;
+}
+
+static void __netconfig_wifi_notify_dpp_removed(guint32 peer_id, guint32 own_id)
+{
+ GVariantBuilder *builder = NULL;
+
+ 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));
+
+ wifi_emit_dpp_removed((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ return;
+}
+
+static char *__netconfig_dpp_get_supplicant_interface()
+{
+ char *if_path = NULL;
+
+ if_path = netconfig_wifi_get_supplicant_p2p_interface();
+ if (if_path)
+ return if_path;
+
+ if_path = netconfig_wifi_get_supplicant_interface();
+
+ return if_path;
+}
+
+static gboolean __netconfig_wifi_invoke_dpp_set_dpp_config_processing()
+{
+ char *if_path = NULL;
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP Set config processing Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+
+ params = g_variant_new("(ssv)", SUPPLICANT_INTERFACE ".Interface",
+ "DppConfigProcessing", g_variant_new_string(DEFAULT_DPP_CONFIG_PROCESSING_TYPE));
+
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, DBUS_INTERFACE_PROPERTIES, "Set", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to set DPP config processing !!!");
+ return FALSE;
+ }
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_invoke_dpp_qr_code(const char *peer_uri, guint32 *peer_id)
+{
+ char *if_path = NULL;
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP QrCode Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+
+ params = g_variant_new("(s)", peer_uri);
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "QrCode", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to set peer URI !!!");
+ return FALSE;
+ }
+
+ g_variant_get(message, "(u)", peer_id);
+ INFO("DPP reply: [%u]", *peer_id);
+
+ g_variant_unref(message);
+ return TRUE;
+}
+#define DEBUG_G_VARIANT(str, parameters)\
+ do {\
+ gchar *parameters_debug_str = NULL;\
+ if (parameters)\
+ parameters_debug_str = g_variant_print(parameters, TRUE);\
+ DBG("%s[%s]", str, parameters_debug_str ? parameters_debug_str : "NULL");\
+ g_free(parameters_debug_str);\
+ } while (0)
+
+
+static int __ws_unpack_ay(unsigned char *dst, GVariant *src, int size)
+{
+ GVariantIter *iter = NULL;
+ int length = 0;
+
+ if (!dst || !src || size == 0) {
+ DBG("Invalid parameter");
+ return -1;
+ }
+ g_variant_get(src, "ay", &iter);
+ if (iter == NULL) {
+ DBG("failed to get iterator");
+ return -1;
+ }
+
+ while (g_variant_iter_loop(iter, "y", &dst[length])) {
+ length++;
+ if (length >= size)
+ break;
+ }
+ g_variant_iter_free(iter);
+
+ return length;
+}
+
+static gchar *__netconfig_get_p2p_address(const char *if_path)
+{
+ GVariant *params = NULL;
+ GVariant *message = NULL;
+ GVariant *temp = NULL;
+ guchar p2p_addr[MACADDR_LEN] = {0,};
+ gchar address_str[MACSTR_LEN] = {0,};
+
+ params = g_variant_new("(ss)", SUPPLICANT_INTERFACE ".Interface", "P2PAddress");
+
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path,
+ DBUS_INTERFACE_PROPERTIES,
+ "Get",
+ params);
+
+ if (message == NULL) {
+ ERR("netconfig_supplicant_invoke_dbus_method() failed.");
+ return NULL;
+ }
+ DEBUG_G_VARIANT("reply:", message);
+
+ temp = g_variant_get_child_value(message, 0);
+ temp = g_variant_get_child_value(temp, 0);
+ DEBUG_G_VARIANT("temp:", temp);
+ __ws_unpack_ay(p2p_addr, temp, MACADDR_LEN);
+ g_snprintf(address_str, MACSTR_LEN, MACSTR, MAC2STR(p2p_addr));
+
+ DBG("P2P address %s", address_str);
+
+ return g_strdup(address_str);
+}
+
+static gboolean __netconfig_wifi_invoke_dpp_add_bootstrap(const char *key, guint32 *id)
+{
+ char *if_path = NULL;
+ GVariantBuilder *builder = NULL;
+ GVariant *params = NULL;
+ GVariant *message = NULL;
+ gchar *current_mac_addr = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP AddBootstrap Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "type", g_variant_new_string("qrcode"));
+ g_variant_builder_add(builder, "{sv}", "channels", g_variant_new_string(DEFAULT_DPP_CHANNEL));
+ /* TODO: find more comfortable way */
+ current_mac_addr = __netconfig_get_p2p_address(if_path);
+ if (current_mac_addr)
+ g_variant_builder_add(builder, "{sv}", "mac", g_variant_new_string(current_mac_addr));
+ 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 = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "AddBootstrap", params);
+ g_free(if_path);
+ g_free(current_mac_addr);
+ if (message == NULL) {
+ ERR(" DPP : Failed to add bootstrap !!!");
+ return FALSE;
+ }
+
+ g_variant_get(message, "(u)", id);
+ INFO("DPP reply: [%u]", *id);
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_invoke_dpp_get_bootstrap_uri(guint32 id, gchar **uri)
+{
+ char *if_path = NULL;
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+
+ if (id == 0) {
+ DBG("Invalid ID");
+ return FALSE;
+ }
+
+ DBG("[TizenMW-->WPAS]: DPP GetBootstrapUri Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+
+ params = g_variant_new("(u)", id);
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "GetBootstrapUri", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to get URI !!!");
+ return FALSE;
+ }
+
+ g_variant_get(message, "(s)", uri);
+ INFO("DPP reply: [%s]", *uri);
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_invoke_dpp_add_configurator(const char *key, guint32 *id)
+{
+ char *if_path = NULL;
+ GVariantBuilder *builder = NULL;
+ GVariant *params = NULL;
+ GVariant *message = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP AddConfigurator Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ 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 = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "AddConfigurator", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to add configurator !!!");
+ return FALSE;
+ }
+
+ g_variant_get(message, "(u)", id);
+ INFO("DPP reply: [%u]", *id);
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gchar *__generate_configurator_params(guint32 configurator_id, const char *ssid,
+ const char *net_role, const char *akm, const char *pass)
+{
+ gchar ssid_hex[65] = {0,};
+ gchar pass_hex[129] = {0,};
+ gchar *ret = NULL;
+
+ gchar *conf_str = NULL;
+
+ netconfig_convert_bytes_to_hexstr(ssid, strlen(ssid), ssid_hex);
+ conf_str = g_strdup_printf(" ssid=%s conf=%s-%s", ssid_hex, net_role, akm);
+
+ if (pass) {
+ netconfig_convert_bytes_to_hexstr(pass, strlen(pass), pass_hex);
+ ret = g_strdup_printf("%s pass=%s", conf_str, pass_hex);
+ } else {
+ ret = g_strdup_printf(" configurator=%u%s", configurator_id, conf_str);
+ }
+ g_free(conf_str);
+
+ return ret;
+}
+
+static gboolean __netconfig_wifi_invoke_dpp_set_configurator_params(guint configurator_id,
+ const char *ssid, const char *net_role, const char *akm, const char *pass)
+{
+ char *if_path = NULL;
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+ gchar *configurator_param_str = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP Set configurator params Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+
+ configurator_param_str = __generate_configurator_params(
+ configurator_id, ssid, net_role, akm, pass);
+ if (!configurator_param_str) {
+ ERR(" DPP : Failed to gen conf params");
+ g_free(if_path);
+ return FALSE;
+ }
+ params = g_variant_new("(ssv)", SUPPLICANT_INTERFACE ".Interface",
+ "DPPConfiguratorParams", g_variant_new_string(configurator_param_str));
+
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, DBUS_INTERFACE_PROPERTIES, "Set", params);
+ g_free(if_path);
+ g_free(configurator_param_str);
+ if (message == NULL) {
+ ERR(" DPP : Failed to set configurator params !!!");
+ return FALSE;
+ }
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_invoke_dpp_listen(guint32 freq, const gchar *dev_role)
+{
+ char *if_path = NULL;
+ GVariantBuilder *builder = NULL;
+ GVariant *params = NULL;
+ GVariant *message = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP Listen Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "freq", g_variant_new_uint32(freq));
+ g_variant_builder_add(builder, "{sv}", "role", g_variant_new_string(dev_role));
+ params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "Listen", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to start DPP listen !!!");
+ return FALSE;
+ }
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_invoke_auth_init_enrollee(guint32 peer_id)
+{
+ char *if_path = NULL;
+ GVariantBuilder *builder = NULL;
+ GVariant *params = NULL;
+ GVariant *message = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP AuthInit Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer", g_variant_new_uint32(peer_id));
+ g_variant_builder_add(builder, "{sv}", "role", g_variant_new_string("enrollee"));
+ params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "AuthInit", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to start DPP AuthInit !!!");
+ return FALSE;
+ }
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_invoke_auth_init_configurator(guint32 peer_id,
+ guint32 configurator_id, const char *conf, const char *ssid, const char *pass)
+{
+ char *if_path = NULL;
+ GVariantBuilder *builder = NULL;
+ GVariant *params = NULL;
+ GVariant *message = NULL;
+ gchar ssid_hex[65] = {0,};
+ gchar pass_hex[129] = {0,};
+
+ DBG("[TizenMW-->WPAS]: DPP AuthInit Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return FALSE;
+ }
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer", g_variant_new_uint32(peer_id));
+ g_variant_builder_add(builder, "{sv}", "configurator", g_variant_new_uint32(configurator_id));
+ g_variant_builder_add(builder, "{sv}", "role", g_variant_new_string("configurator"));
+ g_variant_builder_add(builder, "{sv}", "conf", g_variant_new_string(conf));
+ if (ssid) {
+ netconfig_convert_bytes_to_hexstr(ssid, strlen(ssid), ssid_hex);
+ g_variant_builder_add(builder, "{sv}", "ssid", g_variant_new_string(ssid_hex));
+ }
+ if (pass) {
+ netconfig_convert_bytes_to_hexstr(pass, strlen(pass), pass_hex);
+ g_variant_builder_add(builder, "{sv}", "passphrase", g_variant_new_string(pass_hex));
+ }
+ params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "AuthInit", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to start DPP AuthInit !!!");
+ return FALSE;
+ }
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static void __netconfig_wifi_invoke_dpp_stop_listen()
+{
+ char *if_path = NULL;
+ GVariant *message = NULL;
+
+ DBG("[TizenMW-->WPAS]: DPP StopListen Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return;
+ }
+
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "StopListen", NULL);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to stop listen !!!");
+ return;
+ }
+
+ g_variant_unref(message);
+ return;
+}
+
+static void __netconfig_wifi_invoke_dpp_remove_bootstrap(guint32 uri_id)
+{
+ char *if_path = NULL;
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+
+ if (uri_id == 0) {
+ DBG("Invalid ID");
+ return;
+ }
+
+ DBG("[TizenMW-->WPAS]: DPP RemoveBootstrap Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return;
+ }
+
+ params = g_variant_new("(u)", uri_id);
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "RemoveBootstrap", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to remove URI !!!");
+ return;
+ }
+
+ g_variant_unref(message);
+ return;
+}
+
+static void __netconfig_wifi_invoke_dpp_remove_configurator(guint32 configurator_id)
+{
+ char *if_path = NULL;
+ GVariant *message = NULL;
+ GVariant *params = NULL;
+
+ if (configurator_id == 0) {
+ DBG("Invalid ID");
+ return;
+ }
+
+ DBG("[TizenMW-->WPAS]: DPP RemoveConfigurator Request: ");
+
+ if_path = __netconfig_dpp_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus interface path");
+ return;
+ }
+
+ params = g_variant_new("(u)", configurator_id);
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface.DPP", "RemoveConfigurator", params);
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" DPP : Failed to remove configurator !!!");
+ return;
+ }
+
+ g_variant_unref(message);
+ return;
+}
+/*
+static void __wifi_dpp_connman_specific_scan_request_reply(GObject *source_object, GAsyncResult *res,
+ gpointer user_data)
+{
+ GDBusConnection *conn = NULL;
+ GError *error = NULL;
+ GVariant *reply;
+
+ conn = G_DBUS_CONNECTION(source_object);
+ reply = g_dbus_connection_call_finish(conn, res, &error);
+ if (error != NULL) {
+ ERR("Scan failed. Error [%s]\n", error->message);
+ g_error_free(error);
+ } else {
+ DBG("Specific Scan Request success\n");
+ }
+
+ if (reply)
+ g_variant_unref(reply);
+}
+
+static gboolean __netconfig_wifi_dpp_invoke_connman_specific_scan(gchar *ssid)
+{
+ GVariant *params = NULL;
+ GVariantBuilder *builder;
+ gboolean ret;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "SSID", g_variant_new_string(ssid));
+
+ params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ ret = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
+ CONNMAN_WIFI_TECHNOLOGY_PREFIX,
+ CONNMAN_TECHNOLOGY_INTERFACE, "SpecificScan", params,
+ __wifi_dpp_connman_specific_scan_request_reply);
+
+ return ret;
+}
+*/
+static void __wifi_dpp_connman_scan_request_reply(GObject *source_object, GAsyncResult *res,
+ gpointer user_data)
+{
+ GDBusConnection *conn = NULL;
+ GError *error = NULL;
+ GVariant *reply;
+
+ conn = G_DBUS_CONNECTION(source_object);
+ reply = g_dbus_connection_call_finish(conn, res, &error);
+ if (error != NULL) {
+ ERR("Scan failed. Error [%s]\n", error->message);
+ g_error_free(error);
+ } else {
+ DBG("Scan Request success\n");
+ }
+
+ if (reply)
+ g_variant_unref(reply);
+}
+
+static gboolean __netconfig_wifi_dpp_invoke_connman_scan()
+{
+ return netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
+ CONNMAN_WIFI_TECHNOLOGY_PREFIX,
+ CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL,
+ __wifi_dpp_connman_scan_request_reply);
+}
+
+
+
+static gboolean __netconfig_wifi_invoke_flush_bss()
+{
+ GVariant *message = NULL;
+ char *if_path = NULL;
+ GVariant *params = NULL;
+
+ DBG("[TizenMW-->WPAS]: Wi-Fi Flush BSS Request: ");
+
+ if_path = netconfig_wifi_get_supplicant_interface();
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus path");
+ return FALSE;
+ }
+
+ params = g_variant_new("(u)", 0);
+ message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
+ if_path, SUPPLICANT_INTERFACE ".Interface", "FlushBSS", params);
+
+ g_free(if_path);
+ if (message == NULL) {
+ ERR(" Failed to flush BSS !!!");
+ return FALSE;
+ }
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_dpp_enter_peer_uri(GDBusMethodInvocation *context,
+ guint32 peer_id, guint32 own_id, gboolean is_initiator, gchar *peer_uri)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ gboolean ret;
+
+ p_dpp_info = _get_dpp_info(peer_id, own_id);
+ if (!p_dpp_info) {
+ ERR("Invalid parameter");
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_qr_code(peer_uri, &(p_dpp_info->peer_id));
+ if (!ret)
+ return FALSE;
+
+ __netconfig_wifi_notify_dpp_bootstrapped(p_dpp_info->peer_id);
+
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_dpp_generate_uri(GDBusMethodInvocation *context,
+ guint32 peer_id, guint32 own_id, gboolean is_initiator, const gchar *key)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ guint32 id = 0;
+ gchar *generated_uri = NULL;
+ gboolean ret;
+
+ p_dpp_info = _get_dpp_info(peer_id, own_id);
+ if (!p_dpp_info) {
+ ERR("Invalid parameter");
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_add_bootstrap(key, &id);
+ if (!ret)
+ return FALSE;
+
+ ret = __netconfig_wifi_invoke_dpp_get_bootstrap_uri(id, &generated_uri);
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ return FALSE;
+ }
+
+ p_dpp_info->own_id = id;
+ __netconfig_wifi_notify_dpp_uri_generated(id, generated_uri);
+ g_free(generated_uri);
+
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_dpp_start_configurator_initiator(GDBusMethodInvocation *context,
+ const char *group_id, const char *ssid, const char *peer_uri, guint32 peer_id,
+ const char *net_role, const char *akm, const char *configurator_key,
+ const char *pass)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ guint32 id = 0;
+ char *conf_str = NULL;
+ gboolean ret = FALSE;
+
+ p_dpp_info = __create_dpp_info(TRUE);
+ if (!p_dpp_info) {
+ INFO("Failed to create DPP info");
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_qr_code(peer_uri, &(id));
+ if (!ret) {
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_add_configurator(configurator_key, &(p_dpp_info->configurator_id));
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+ p_dpp_info->state = WIFI_DPP_STATE_BOOTSTRAPPED;
+ __netconfig_wifi_notify_dpp_bootstrapped(id);
+
+ conf_str = g_strdup_printf("%s-%s", net_role, akm);
+ ret = __netconfig_wifi_invoke_auth_init_configurator(id,
+ p_dpp_info->configurator_id, conf_str, ssid, pass);
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ __destroy_dpp_info(p_dpp_info);
+ g_free(conf_str);
+ return FALSE;
+ }
+
+ p_dpp_info->is_initiator = TRUE;
+ p_dpp_info->peer_id = id;
+ __add_to_dpp_info_list(p_dpp_info);
+ p_dpp_info->state = WIFI_DPP_STATE_AUTHENTICATING;
+ __netconfig_wifi_notify_dpp_authenticating(id, p_dpp_info->own_id);
+
+ g_free(conf_str);
+
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_dpp_start_configurator_responder(GDBusMethodInvocation *context,
+ const char *group_id, const char *ssid, const char *net_role,
+ const char *akm, const char *auth_key, const char *configurator_key,
+ const char *pass)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ gboolean ret = FALSE;
+ guint32 id = 0;
+ gchar *generated_uri = NULL;
+
+ p_dpp_info = __create_dpp_info(FALSE);
+ if (!p_dpp_info) {
+ INFO("Failed to create DPP info");
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_add_configurator(configurator_key, &(p_dpp_info->configurator_id));
+ if (!ret) {
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_set_configurator_params(p_dpp_info->configurator_id, ssid, net_role, akm, pass);
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_configurator(p_dpp_info->configurator_id);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_add_bootstrap(auth_key, &id);
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_configurator(p_dpp_info->configurator_id);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_get_bootstrap_uri(id, &generated_uri);
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_configurator(p_dpp_info->configurator_id);
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ __netconfig_wifi_notify_dpp_uri_generated(id, generated_uri);
+
+ ret = __netconfig_wifi_invoke_dpp_listen(DEFAULT_DPP_FREQ, "configurator");
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_configurator(p_dpp_info->configurator_id);
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ g_free(generated_uri);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ p_dpp_info->is_initiator = FALSE;
+ p_dpp_info->own_id = id;
+ __add_to_dpp_info_list(p_dpp_info);
+ p_dpp_info->state = WIFI_DPP_STATE_AWAITING;
+ __netconfig_wifi_notify_dpp_awaiting(id);
+
+ g_free(generated_uri);
+
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_dpp_start_enrollee_initiator(GDBusMethodInvocation *context,
+ const char *peer_uri, guint32 peer_id)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ guint32 id = 0;
+ gboolean ret = FALSE;
+
+ p_dpp_info = __create_dpp_info(TRUE);
+ if (!p_dpp_info) {
+ INFO("Failed to create DPP info");
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_set_dpp_config_processing();
+ if (!ret) {
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_qr_code(peer_uri, &id);
+ if (!ret) {
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+ p_dpp_info->state = WIFI_DPP_STATE_BOOTSTRAPPED;
+ __netconfig_wifi_notify_dpp_bootstrapped(id);
+
+ ret = __netconfig_wifi_invoke_auth_init_enrollee(id);
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ p_dpp_info->is_initiator = TRUE;
+ p_dpp_info->peer_id = id;
+ __add_to_dpp_info_list(p_dpp_info);
+ p_dpp_info->state = WIFI_DPP_STATE_AUTHENTICATING;
+ __netconfig_wifi_notify_dpp_authenticating(id, p_dpp_info->own_id);
+
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_dpp_start_enrollee_responder(GDBusMethodInvocation *context,
+ const char *auth_key)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ gboolean ret = FALSE;
+ guint32 id = 0;
+ gchar *generated_uri = NULL;
+
+ p_dpp_info = __create_dpp_info(FALSE);
+ if (!p_dpp_info) {
+ INFO("Failed to create DPP info");
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_set_dpp_config_processing();
+ if (!ret) {
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_add_bootstrap(auth_key, &id);
+ if (!ret) {
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ ret = __netconfig_wifi_invoke_dpp_get_bootstrap_uri(id, &generated_uri);
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ __netconfig_wifi_notify_dpp_uri_generated(id, generated_uri);
+
+ ret = __netconfig_wifi_invoke_dpp_listen(DEFAULT_DPP_FREQ, "enrollee");
+ if (!ret) {
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(id);
+ __destroy_dpp_info(p_dpp_info);
+ return FALSE;
+ }
+
+ p_dpp_info->is_initiator = FALSE;
+ p_dpp_info->own_id = id;
+ __add_to_dpp_info_list(p_dpp_info);
+ p_dpp_info->state = WIFI_DPP_STATE_AWAITING;
+ __netconfig_wifi_notify_dpp_awaiting(id);
+
+ g_free(generated_uri);
+
+ return TRUE;
+}
+
+static gboolean __netconfig_wifi_dpp_stop(GDBusMethodInvocation *context,
+ guint32 peer_id, guint32 own_id)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+
+ p_dpp_info = _get_dpp_info(peer_id, own_id);
+ if (!p_dpp_info) {
+ ERR("Invalid parameter");
+ return FALSE;
+ }
+
+ __netconfig_wifi_invoke_dpp_stop_listen();
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(p_dpp_info->peer_id);
+
+ if (p_dpp_info->own_id != 0)
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(p_dpp_info->own_id);
+
+ if (p_dpp_info->configurator_id != 0)
+ __netconfig_wifi_invoke_dpp_remove_configurator(p_dpp_info->configurator_id);
+
+ __remove_from_dpp_info_list(p_dpp_info);
+ __destroy_dpp_info(p_dpp_info);
+ __netconfig_wifi_notify_dpp_removed(peer_id, own_id);
+
+ return TRUE;
+}
+
+
+void netconfig_wifi_dpp_auth_success_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ GVariantBuilder *builder = NULL;
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ p_dpp_info->state = WIFI_DPP_STATE_AUTHENTICATED;
+ wifi_emit_dpp_auth_success((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+
+ return;
+}
+
+static void __clear_dpp_process(wifi_dpp_s *p_dpp_info)
+{
+ g_in_progress = FALSE;
+ __netconfig_wifi_invoke_dpp_stop_listen();
+
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(p_dpp_info->peer_id);
+
+ if (p_dpp_info->own_id != 0)
+ __netconfig_wifi_invoke_dpp_remove_bootstrap(p_dpp_info->own_id);
+
+ if (p_dpp_info->configurator_id != 0)
+ __netconfig_wifi_invoke_dpp_remove_configurator(p_dpp_info->configurator_id);
+
+ __remove_from_dpp_info_list(p_dpp_info);
+ __netconfig_wifi_notify_dpp_removed(p_dpp_info->peer_id, p_dpp_info->own_id);
+ __destroy_dpp_info(p_dpp_info);
+}
+
+static void __resume_dpp_responder(wifi_dpp_s *p_dpp_info)
+{
+ gchar *device_role = NULL;
+ gboolean ret;
+
+ __netconfig_wifi_invoke_dpp_stop_listen();
+
+ if (p_dpp_info->configurator_id)
+ device_role = "configurator";
+ else
+ device_role = "enrollee";
+
+ ret = __netconfig_wifi_invoke_dpp_listen(DEFAULT_DPP_FREQ, device_role);
+ if (!ret) {
+ __clear_dpp_process(p_dpp_info);
+ } else {
+ p_dpp_info->state = WIFI_DPP_STATE_AWAITING;
+ __netconfig_wifi_notify_dpp_awaiting(p_dpp_info->own_id);
+ }
+}
+
+static void __netconfig_wifi_dpp_wrap_up(wifi_dpp_s *p_dpp_info)
+{
+ if (p_dpp_info->is_initiator)
+ __clear_dpp_process(p_dpp_info);
+ else
+ __resume_dpp_responder(p_dpp_info);
+}
+
+static void __netconfig_wifi_dpp_notify_dpp_failed(wifi_dpp_s *p_dpp_info)
+{
+ GVariantBuilder *builder = NULL;
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ wifi_emit_dpp_auth_failed((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ __netconfig_wifi_dpp_wrap_up(p_dpp_info);
+}
+
+void netconfig_wifi_dpp_auth_failed_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ __netconfig_wifi_dpp_notify_dpp_failed(p_dpp_info);
+
+ return;
+}
+
+void netconfig_wifi_dpp_not_compatible_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ GVariantBuilder *builder = NULL;
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ wifi_emit_dpp_not_compatible((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ __netconfig_wifi_dpp_wrap_up(p_dpp_info);
+
+ return;
+}
+
+void netconfig_wifi_dpp_conf_failed_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ GVariantBuilder *builder = NULL;
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ wifi_emit_dpp_conf_failed((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ __netconfig_wifi_dpp_wrap_up(p_dpp_info);
+
+ return;
+}
+
+void netconfig_wifi_dpp_scan_peer_qr_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ GVariantBuilder *builder = NULL;
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ wifi_emit_dpp_scan_peer_qr((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ p_dpp_info->state = WIFI_DPP_STATE_PEER_QR_REQUESTED;
+
+ return;
+}
+
+void netconfig_wifi_dpp_network_id_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ GVariantBuilder *builder = NULL;
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ wifi_emit_dpp_network_id((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ return;
+}
+
+void netconfig_wifi_dpp_conf_sent_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ GVariantBuilder *builder = NULL;
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ wifi_emit_dpp_conf_sent((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ __netconfig_wifi_dpp_wrap_up(p_dpp_info);
+
+ return;
+}
+
+void netconfig_wifi_dpp_conf_received_event(GVariant *message)
+{
+ wifi_dpp_s *p_dpp_info = NULL;
+ GVariantBuilder *builder = NULL;
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+ g_variant_builder_add(builder, "{sv}", "peer_id", g_variant_new_uint32(p_dpp_info->peer_id));
+ g_variant_builder_add(builder, "{sv}", "own_id", g_variant_new_uint32(p_dpp_info->own_id));
+
+ wifi_emit_dpp_conf_received((Wifi *)get_wifi_object(), g_variant_builder_end(builder));
+ g_variant_builder_unref(builder);
+
+ p_dpp_info->state = WIFI_DPP_STATE_CONFIGURED;
+
+ return;
+}
+
+static wifi_dpp_akm_e __get_dpp_akm(const gchar *akm_str)
+{
+ if (g_strcmp0(akm_str, "psk") == 0)
+ return WIFI_DPP_AKM_PSK;
+ else if (g_strcmp0(akm_str, "sae") == 0)
+ return WIFI_DPP_AKM_SAE;
+ else if (g_strcmp0(akm_str, "dpp") == 0)
+ return WIFI_DPP_AKM_DPP;
+
+ return WIFI_DPP_AKM_UNKNOWN;
+}
+
+static gboolean __is_configuration_valid(wifi_dpp_akm_e akm, const gchar *passphrase,
+ const gchar *connector, const gchar *c_sign_key, const gchar *net_access_key)
+{
+ if ((akm == WIFI_DPP_AKM_PSK || akm == WIFI_DPP_AKM_SAE) && passphrase)
+ return TRUE;
+ else if (akm == WIFI_DPP_AKM_DPP && connector && c_sign_key && net_access_key)
+ return TRUE;
+ return FALSE;
+}
+
+gboolean __save_passphrase(GKeyFile *keyfile, gchar *group_name, gchar *key, gchar *value)
+{
+ gchar *enc_data = NULL;
+ gboolean ret = TRUE;
+
+ if (!value)
+ return ret;
+
+ enc_data = _netconfig_encrypt_passphrase(value);
+ if (!enc_data) {
+ ERR("Failed to encrypt the passphrase");
+ ret = FALSE;
+ } else {
+ g_key_file_set_string(keyfile, group_name, key, enc_data);
+ }
+
+ return ret;
+}
+
+gboolean __save_credentials(GKeyFile *keyfile, gchar *group_name, wifi_dpp_conf_obj *conf_obj)
+{
+ gboolean ret;
+
+ ret = __save_passphrase(keyfile, group_name,
+ "Passphrase", conf_obj->passphrase);
+ if (!ret)
+ return FALSE;
+
+ ret = __save_passphrase(keyfile, group_name,
+ "Connector", conf_obj->connector);
+ if (!ret)
+ return FALSE;
+
+ ret = __save_passphrase(keyfile, group_name,
+ "CSignKey", conf_obj->c_sign_key);
+ if (!ret)
+ return FALSE;
+
+ ret = __save_passphrase(keyfile, group_name,
+ "NetAccessKey", conf_obj->net_access_key);
+ if (!ret)
+ return FALSE;
+
+ return TRUE;
+}
+
+
+static gboolean __save_configuration_object(wifi_dpp_conf_obj *conf_obj)
+{
+ gchar ssid_hex[65] = {0,};
+ gchar *config_id = NULL;
+ gchar *group_name = NULL;
+ GKeyFile *keyfile = NULL;
+ gboolean ret;
+
+ if (!conf_obj->ssid) {
+ ERR("DPP :there's no SSID in configuration");
+ return FALSE;
+ }
+
+ if (!__is_configuration_valid(__get_dpp_akm(conf_obj->akm),
+ conf_obj->passphrase,
+ conf_obj->connector,
+ conf_obj->c_sign_key,
+ conf_obj->net_access_key)) {
+ ERR("DPP :Invalid AKM information in configuration");
+ return FALSE;
+ }
+
+ netconfig_convert_bytes_to_hexstr(conf_obj->ssid, strlen(conf_obj->ssid), ssid_hex);
+ config_id = g_strdup_printf("%s_managed_%s", ssid_hex, conf_obj->akm);
+ ret = wifi_config_get_group_name("wifi_", config_id, &group_name);
+ if (!ret) {
+ ERR("Failed to get Wi-Fi config group name");
+ g_free(config_id);
+ return FALSE;
+ }
+
+ keyfile = g_key_file_new();
+ g_key_file_set_string(keyfile, group_name, "Name", conf_obj->ssid);
+ g_key_file_set_string(keyfile, group_name, "SSID", ssid_hex);
+
+ if (!__save_credentials(keyfile, group_name, conf_obj)) {
+ g_key_file_free(keyfile);
+ g_free(config_id);
+ g_free(group_name);
+ return FALSE;
+ }
+
+ g_key_file_set_boolean(keyfile, group_name, "Favorite", TRUE);
+ g_key_file_set_boolean(keyfile, group_name, "AutoConnect", TRUE);
+
+ ret = wifi_config_save_configuration(config_id, keyfile);
+ if (ret == TRUE)
+ INFO("Success to save configuration [%s]", config_id);
+ else
+ INFO("Fail to save configuration [%s]", config_id);
+
+ g_key_file_free(keyfile);
+ g_free(config_id);
+ g_free(group_name);
+
+ return ret;
+
+}
+
+void netconfig_wifi_dpp_conf_obj_event(GVariant *message)
+{
+ GVariantIter *iter = NULL;
+ gchar *key = NULL;
+ GVariant *value = NULL;
+ wifi_dpp_s *p_dpp_info = NULL;
+ wifi_dpp_conf_obj conf_obj = {0,};
+
+ p_dpp_info = _get_dpp_in_progress();
+ if (!p_dpp_info) {
+ ERR("DPP :there's no DPP in progress");
+ return;
+ }
+
+ g_variant_get(message, "(a{sv})", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
+ if (g_strcmp0(key, "ssid") == 0)
+ g_variant_get(value, "&s", &conf_obj.ssid);
+ else if (g_strcmp0(key, "akm") == 0)
+ g_variant_get(value, "&s", &conf_obj.akm);
+ else if (g_strcmp0(key, "passphrase") == 0)
+ g_variant_get(value, "&s", &conf_obj.passphrase);
+ else if (g_strcmp0(key, "connector") == 0)
+ g_variant_get(value, "&s", &conf_obj.connector);
+ else if (g_strcmp0(key, "c_sign_key") == 0)
+ g_variant_get(value, "&s", &conf_obj.c_sign_key);
+ else if (g_strcmp0(key, "net_access_key") == 0)
+ g_variant_get(value, "&s", &conf_obj.net_access_key);
+ }
+
+ if (!__save_configuration_object(&conf_obj) || !__netconfig_wifi_invoke_flush_bss()) {
+ g_variant_iter_free(iter);
+ __netconfig_wifi_dpp_notify_dpp_failed(p_dpp_info);
+ return;
+ }
+
+ g_variant_iter_free(iter);
+ __clear_dpp_process(p_dpp_info);
+ __netconfig_wifi_dpp_invoke_connman_scan();
+ return;
+}
+
+gboolean handle_dpp_enter_peer_uri(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info)
+{
+ gboolean ret = FALSE;
+ GVariantIter *iter;
+ GVariant *value;
+ gchar *field;
+ guint32 peer_id = 0;
+ guint32 own_id = 0;
+ gboolean is_initiator = FALSE;
+ gchar *uri = NULL;
+
+ INFO("Received DPP enter peer uri Request");
+ if ((wifi == NULL) || (dpp_info == NULL)) {
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
+ if (g_strcmp0(field, "peer_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ peer_id = g_variant_get_uint32(value);
+ } else if (g_strcmp0(field, "own_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ own_id = g_variant_get_uint32(value);
+
+ } else if (g_strcmp0(field, "uri") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(uri);
+ uri = g_strdup(g_variant_get_string(value, NULL));
+ }
+ }
+
+ if (!own_id || !uri){
+ g_variant_iter_free(iter);
+ g_free(uri);
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+ wifi_complete_dpp_enter_peer_uri(wifi, context);
+
+ ret = __netconfig_wifi_dpp_enter_peer_uri(context, peer_id, own_id,
+ is_initiator, uri);
+ if (ret == TRUE)
+ INFO("Success to enter peer uri");
+ else
+ __netconfig_wifi_notify_dpp_failed();
+
+ g_variant_iter_free(iter);
+ g_free(uri);
+
+ return TRUE;
+}
+
+gboolean handle_dpp_generate_uri(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info)
+{
+ gboolean ret = FALSE;
+ GVariantIter *iter;
+ GVariant *value;
+ gchar *field;
+ guint32 peer_id = 0;
+ guint32 own_id = 0;
+ gboolean is_initiator = FALSE;
+ gchar *key = NULL;
+
+ INFO("Received DPP gen own uri Request");
+ if ((wifi == NULL) || (dpp_info == NULL)) {
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
+ if (g_strcmp0(field, "peer_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ peer_id = g_variant_get_uint32(value);
+ } else if (g_strcmp0(field, "own_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ own_id = g_variant_get_uint32(value);
+
+ } else if (g_strcmp0(field, "is_initiator") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEAN)) {
+ is_initiator = g_variant_get_boolean(value);
+ } else if (g_strcmp0(field, "key") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ __free_critical(key);
+ key = g_strdup(g_variant_get_string(value, NULL));
+ }
+ }
+
+ if (!peer_id){
+ __free_critical(key);
+ g_variant_iter_free(iter);
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+ wifi_complete_dpp_generate_uri(wifi, context);
+
+ ret = __netconfig_wifi_dpp_generate_uri(context, peer_id, own_id,
+ is_initiator, key);
+ if (ret == TRUE)
+ INFO("Success to generate uri");
+ else
+ __netconfig_wifi_notify_dpp_failed();
+
+ g_variant_iter_free(iter);
+ __free_critical(key);
+
+ return TRUE;
+}
+
+gboolean handle_dpp_start_configurator_initiator(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info)
+{
+ GVariantIter *iter;
+ GVariant *value;
+ gchar *field;
+ gchar *group_id = NULL;
+ gchar *ssid = NULL;
+ gchar *peer_uri = NULL;
+ guint32 peer_id = 0;
+ gchar *net_role = NULL;
+ gchar *akm = NULL;
+ gchar *configurator_key = NULL;
+ gchar *pass = NULL;
+
+ INFO("Received DPP start configurator initiator");
+ if ((wifi == NULL) || (dpp_info == NULL)) {
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+ if (g_in_progress) {
+ ERR("DPP in progress");;
+ netconfig_error_inprogress(context);
+ return TRUE;
+ }
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
+ if (g_strcmp0(field, "group_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(group_id);
+ group_id = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "ssid") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(ssid);
+ ssid = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "peer_uri") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(peer_uri);
+ peer_uri = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "peer_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ peer_id = g_variant_get_uint32(value);
+ } else if (g_strcmp0(field, "net_role") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(net_role);
+ net_role = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "akm") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(akm);
+ akm = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "configurator_key") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ __free_critical(configurator_key);
+ configurator_key = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "pass") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ __free_critical(pass);
+ pass = g_strdup(g_variant_get_string(value, NULL));
+ }
+ }
+
+ if (!ssid || !akm || !net_role || !peer_uri){
+ g_variant_iter_free(iter);
+ g_free(group_id);
+ g_free(ssid);
+ g_free(peer_uri);
+ g_free(net_role);
+ g_free(akm);
+ __free_critical(configurator_key);
+ __free_critical(pass);
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+
+ wifi_complete_dpp_start_configurator_initiator(wifi, context);
+
+ g_in_progress = __netconfig_wifi_dpp_start_configurator_initiator(context, group_id,
+ ssid, peer_uri, peer_id, net_role, akm, configurator_key, pass);
+ if (g_in_progress)
+ INFO("Success to dpp start configurator initiator");
+ else
+ __netconfig_wifi_notify_dpp_failed();
+
+ g_variant_iter_free(iter);
+ g_free(group_id);
+ g_free(ssid);
+ g_free(peer_uri);
+ g_free(net_role);
+ g_free(akm);
+ __free_critical(configurator_key);
+ __free_critical(pass);
+ return TRUE;
+}
+
+gboolean handle_dpp_start_enrollee_initiator(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info)
+{
+ GVariantIter *iter;
+ GVariant *value;
+ gchar *field;
+ gchar *peer_uri = NULL;
+ guint32 peer_id = 0;
+
+ INFO("Received DPP start enrollee initiator");
+ if ((wifi == NULL) || (dpp_info == NULL)) {
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+ if (g_in_progress) {
+ ERR("DPP in progress");;
+ netconfig_error_inprogress(context);
+ return TRUE;
+ }
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
+
+ if (g_strcmp0(field, "peer_uri") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(peer_uri);
+ peer_uri = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "peer_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ peer_id = g_variant_get_uint32(value);
+ }
+ }
+
+ if (!peer_uri){
+ g_variant_iter_free(iter);
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return FALSE;
+ }
+ wifi_complete_dpp_start_enrollee_initiator(wifi, context);
+
+ g_in_progress = __netconfig_wifi_dpp_start_enrollee_initiator(context, peer_uri, peer_id);
+ if (g_in_progress)
+ INFO("Success to dpp start enrollee initiator");
+ else
+ __netconfig_wifi_notify_dpp_failed();
+
+ g_variant_iter_free(iter);
+ g_free(peer_uri);
+
+ return TRUE;
+}
+
+gboolean handle_dpp_start_configurator_responder(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info)
+{
+ GVariantIter *iter;
+ GVariant *value;
+ gchar *field;
+ gchar *group_id = NULL;
+ gchar *ssid = NULL;
+ gchar *net_role = NULL;
+ gchar *akm = NULL;
+ gchar *auth_key = NULL;
+ gchar *configurator_key = NULL;
+ gchar *pass = NULL;
+
+ INFO("Received DPP start configurator responder");
+ if ((wifi == NULL) || (dpp_info == NULL)) {
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+ if (g_in_progress) {
+ ERR("DPP in progress");;
+ netconfig_error_inprogress(context);
+ return TRUE;
+ }
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
+ if (g_strcmp0(field, "group_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(group_id);
+ group_id = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "ssid") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(ssid);
+ ssid = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "net_role") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(net_role);
+ net_role = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "akm") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ g_free(akm);
+ akm = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "auth_key") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ __free_critical(auth_key);
+ auth_key = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "configurator_key") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ __free_critical(configurator_key);
+ configurator_key = g_strdup(g_variant_get_string(value, NULL));
+ } else if (g_strcmp0(field, "pass") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ __free_critical(pass);
+ pass = g_strdup(g_variant_get_string(value, NULL));
+ }
+ }
+
+ if (!ssid || !akm || !net_role){
+ g_variant_iter_free(iter);
+ g_free(group_id);
+ g_free(ssid);
+ g_free(net_role);
+ g_free(akm);
+ __free_critical(auth_key);
+ __free_critical(configurator_key);
+ __free_critical(pass);
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return FALSE;
+ }
+ wifi_complete_dpp_start_configurator_responder(wifi, context);
+
+ g_in_progress = __netconfig_wifi_dpp_start_configurator_responder(context, group_id,
+ ssid, net_role, akm, auth_key, configurator_key, pass);
+ if (g_in_progress)
+ INFO("Success to dpp start configurator responder");
+ else
+ __netconfig_wifi_notify_dpp_failed();
+
+ g_variant_iter_free(iter);
+ g_free(group_id);
+ g_free(ssid);
+ g_free(net_role);
+ g_free(akm);
+ __free_critical(auth_key);
+ __free_critical(configurator_key);
+ __free_critical(pass);
+
+ return TRUE;
+}
+
+gboolean handle_dpp_start_enrollee_responder(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info)
+{
+ GVariantIter *iter;
+ GVariant *value;
+ gchar *field;
+ gchar *auth_key = NULL;
+
+ INFO("Received DPP start enrollee responder");
+ if ((wifi == NULL) || (dpp_info == NULL)) {
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+ if (g_in_progress) {
+ ERR("DPP in progress");;
+ netconfig_error_inprogress(context);
+ return TRUE;
+ }
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
+ if (g_strcmp0(field, "auth_key") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_STRING)) {
+ __free_critical(auth_key);
+ auth_key = g_strdup(g_variant_get_string(value, NULL));
+ }
+ }
+ wifi_complete_dpp_start_enrollee_responder(wifi, context);
+
+ g_in_progress = __netconfig_wifi_dpp_start_enrollee_responder(context, auth_key);
+ if (g_in_progress)
+ INFO("Success to dpp start enrolee responder");
+ else
+ __netconfig_wifi_notify_dpp_failed();
+
+ g_variant_iter_free(iter);
+ __free_critical(auth_key);
+
+ return TRUE;
+}
+
+gboolean handle_dpp_stop(Wifi *wifi, GDBusMethodInvocation *context, GVariant *dpp_info)
+{
+ GVariantIter *iter;
+ GVariant *value;
+ gchar *field;
+ guint32 peer_id = 0;
+ guint32 own_id = 0;
+
+ INFO("Received DPP stop Request");
+ if ((wifi == NULL) || (dpp_info == NULL)) {
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return TRUE;
+ }
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+
+ g_variant_get(dpp_info, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &field, &value)) {
+ if (g_strcmp0(field, "peer_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ peer_id = g_variant_get_uint32(value);
+ } else if (g_strcmp0(field, "own_id") == 0 &&
+ g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
+ own_id = g_variant_get_uint32(value);
+ }
+ }
+ if (!peer_id && !own_id){
+ g_variant_iter_free(iter);
+ ERR("Invalid arguments");
+ netconfig_error_dbus_method_return(context,
+ NETCONFIG_ERROR_INVALID_PARAMETER, "InvalidArguments");
+ return FALSE;
+ }
+ wifi_complete_dpp_stop(wifi, context);
+
+ g_in_progress = !(__netconfig_wifi_dpp_stop(context, peer_id, own_id));
+ if (!g_in_progress)
+ INFO("Success to dpp stop");
+ else
+ __netconfig_wifi_notify_dpp_failed();
+
+ g_variant_iter_free(iter);
+
+ return TRUE;
+}