D-Bus: Set last_scan_req to MANUAL_SCAN_REQ on Scan() trigger paths
[mech_eap.git] / wpa_supplicant / dbus / dbus_new_handlers.c
index e10b9fa..67562a5 100644 (file)
@@ -2,7 +2,7 @@
  * WPA Supplicant / dbus-based control interface
  * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
  * Copyright (c) 2009-2010, Witold Sowa <witold.sowa@gmail.com>
- * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2009-2015, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
 #include "dbus_common_i.h"
 #include "drivers/driver.h"
 
-static const char *debug_strings[] = {
+static const char * const debug_strings[] = {
        "excessive", "msgdump", "debug", "info", "warning", "error", NULL
 };
 
 
 /**
- * wpas_dbus_error_unknown_error - Return a new InvalidArgs error message
+ * wpas_dbus_error_unknown_error - Return a new UnknownError error message
  * @message: Pointer to incoming dbus message this error refers to
  * @arg: Optional string appended to error message
  * Returns: a dbus error message
@@ -45,20 +45,6 @@ static const char *debug_strings[] = {
 DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
                                            const char *arg)
 {
-       /*
-        * This function can be called as a result of a failure
-        * within internal getter calls, which will call this function
-        * with a NULL message parameter.  However, dbus_message_new_error
-        * looks very unkindly (i.e, abort()) on a NULL message, so
-        * in this case, we should not call it.
-        */
-       if (message == NULL) {
-               wpa_printf(MSG_INFO, "dbus: wpas_dbus_error_unknown_error "
-                          "called with NULL message (arg=%s)",
-                          arg ? arg : "N/A");
-               return NULL;
-       }
-
        return dbus_message_new_error(message, WPAS_DBUS_ERROR_UNKNOWN_ERROR,
                                      arg);
 }
@@ -73,9 +59,9 @@ DBusMessage * wpas_dbus_error_unknown_error(DBusMessage *message,
  */
 static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
 {
-       return dbus_message_new_error(message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
-                                     "wpa_supplicant knows nothing about "
-                                     "this interface.");
+       return dbus_message_new_error(
+               message, WPAS_DBUS_ERROR_IFACE_UNKNOWN,
+               "wpa_supplicant knows nothing about this interface.");
 }
 
 
@@ -88,9 +74,9 @@ static DBusMessage * wpas_dbus_error_iface_unknown(DBusMessage *message)
  */
 static DBusMessage * wpas_dbus_error_network_unknown(DBusMessage *message)
 {
-       return dbus_message_new_error(message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
-                                     "There is no such a network in this "
-                                     "interface.");
+       return dbus_message_new_error(
+               message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
+               "There is no such a network in this interface.");
 }
 
 
@@ -106,9 +92,9 @@ DBusMessage * wpas_dbus_error_invalid_args(DBusMessage *message,
 {
        DBusMessage *reply;
 
-       reply = dbus_message_new_error(message, WPAS_DBUS_ERROR_INVALID_ARGS,
-                                      "Did not receive correct message "
-                                      "arguments.");
+       reply = dbus_message_new_error(
+               message, WPAS_DBUS_ERROR_INVALID_ARGS,
+               "Did not receive correct message arguments.");
        if (arg != NULL)
                dbus_message_append_args(reply, DBUS_TYPE_STRING, &arg,
                                         DBUS_TYPE_INVALID);
@@ -134,7 +120,14 @@ static DBusMessage * wpas_dbus_error_scan_error(DBusMessage *message,
 }
 
 
-static const char *dont_quote[] = {
+DBusMessage * wpas_dbus_error_no_memory(DBusMessage *message)
+{
+       wpa_printf(MSG_DEBUG, "dbus: Failed to allocate memory");
+       return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
+}
+
+
+static const char * const dont_quote[] = {
        "key_mgmt", "proto", "pairwise", "auth_alg", "group", "eap",
        "opensc_engine_path", "pkcs11_engine_path", "pkcs11_module_path",
        "bssid", "scan_freq", "freq_list", NULL
@@ -143,6 +136,7 @@ static const char *dont_quote[] = {
 static dbus_bool_t should_quote_opt(const char *key)
 {
        int i = 0;
+
        while (dont_quote[i] != NULL) {
                if (os_strcmp(key, dont_quote[i]) == 0)
                        return FALSE;
@@ -163,7 +157,8 @@ static struct wpa_supplicant * get_iface_by_dbus_path(
        struct wpa_supplicant *wpa_s;
 
        for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
-               if (os_strcmp(wpa_s->dbus_new_path, path) == 0)
+               if (wpa_s->dbus_new_path &&
+                   os_strcmp(wpa_s->dbus_new_path, path) == 0)
                        return wpa_s;
        }
        return NULL;
@@ -219,7 +214,7 @@ dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s,
                } else if (entry.type == DBUS_TYPE_STRING) {
                        if (should_quote_opt(entry.key)) {
                                size = os_strlen(entry.str_value);
-                               if (size <= 0)
+                               if (size == 0)
                                        goto error;
 
                                size += 3;
@@ -260,6 +255,19 @@ dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s,
                if (wpa_config_set(ssid, entry.key, value, 0) < 0)
                        goto error;
 
+               if (os_strcmp(entry.key, "bssid") != 0 &&
+                   os_strcmp(entry.key, "priority") != 0)
+                       wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
+
+               if (wpa_s->current_ssid == ssid ||
+                   wpa_s->current_ssid == NULL) {
+                       /*
+                        * Invalidate the EAP session cache if anything in the
+                        * current or previously used configuration changes.
+                        */
+                       eapol_sm_invalidate_cached_session(wpa_s->eapol);
+               }
+
                if ((os_strcmp(entry.key, "psk") == 0 &&
                     value[0] == '"' && ssid->ssid_len) ||
                    (os_strcmp(entry.key, "ssid") == 0 && ssid->passphrase))
@@ -302,13 +310,13 @@ dbus_bool_t wpas_dbus_simple_property_getter(DBusMessageIter *iter,
 
        if (!dbus_type_is_basic(type)) {
                dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "%s: given type is not basic", __func__);
+                              "%s: given type is not basic", __func__);
                return FALSE;
        }
 
        if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
-                                             wpa_dbus_type_as_string(type),
-                                             &variant_iter) ||
+                                             wpa_dbus_type_as_string(type),
+                                             &variant_iter) ||
            !dbus_message_iter_append_basic(&variant_iter, type, val) ||
            !dbus_message_iter_close_container(iter, &variant_iter)) {
                dbus_set_error(error, DBUS_ERROR_FAILED,
@@ -379,7 +387,7 @@ dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
 
        if (!dbus_type_is_basic(type)) {
                dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "%s: given type is not basic", __func__);
+                              "%s: given type is not basic", __func__);
                return FALSE;
        }
 
@@ -395,7 +403,7 @@ dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
                return FALSE;
        }
 
-       switch(type) {
+       switch (type) {
        case DBUS_TYPE_BYTE:
        case DBUS_TYPE_BOOLEAN:
                element_size = 1;
@@ -421,7 +429,7 @@ dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
                break;
        default:
                dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "%s: unknown element type %d", __func__, type);
+                              "%s: unknown element type %d", __func__, type);
                return FALSE;
        }
 
@@ -438,7 +446,7 @@ dbus_bool_t wpas_dbus_simple_array_property_getter(DBusMessageIter *iter,
        if (!dbus_message_iter_close_container(&variant_iter, &array_iter) ||
            !dbus_message_iter_close_container(iter, &variant_iter)) {
                dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "%s: failed to construct message 3", __func__);
+                              "%s: failed to construct message 3", __func__);
                return FALSE;
        }
 
@@ -537,34 +545,34 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
        while (wpa_dbus_dict_has_dict_entry(&iter_dict)) {
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto error;
-               if (!os_strcmp(entry.key, "Driver") &&
-                   (entry.type == DBUS_TYPE_STRING)) {
+               if (os_strcmp(entry.key, "Driver") == 0 &&
+                   entry.type == DBUS_TYPE_STRING) {
                        os_free(driver);
                        driver = os_strdup(entry.str_value);
                        wpa_dbus_dict_entry_clear(&entry);
                        if (driver == NULL)
-                               goto error;
-               } else if (!os_strcmp(entry.key, "Ifname") &&
-                          (entry.type == DBUS_TYPE_STRING)) {
+                               goto oom;
+               } else if (os_strcmp(entry.key, "Ifname") == 0 &&
+                          entry.type == DBUS_TYPE_STRING) {
                        os_free(ifname);
                        ifname = os_strdup(entry.str_value);
                        wpa_dbus_dict_entry_clear(&entry);
                        if (ifname == NULL)
-                               goto error;
-               } else if (!os_strcmp(entry.key, "ConfigFile") &&
-                          (entry.type == DBUS_TYPE_STRING)) {
+                               goto oom;
+               } else if (os_strcmp(entry.key, "ConfigFile") == 0 &&
+                          entry.type == DBUS_TYPE_STRING) {
                        os_free(confname);
                        confname = os_strdup(entry.str_value);
                        wpa_dbus_dict_entry_clear(&entry);
                        if (confname == NULL)
-                               goto error;
-               } else if (!os_strcmp(entry.key, "BridgeIfname") &&
-                          (entry.type == DBUS_TYPE_STRING)) {
+                               goto oom;
+               } else if (os_strcmp(entry.key, "BridgeIfname") == 0 &&
+                          entry.type == DBUS_TYPE_STRING) {
                        os_free(bridge_ifname);
                        bridge_ifname = os_strdup(entry.str_value);
                        wpa_dbus_dict_entry_clear(&entry);
                        if (bridge_ifname == NULL)
-                               goto error;
+                               goto oom;
                } else {
                        wpa_dbus_dict_entry_clear(&entry);
                        goto error;
@@ -579,28 +587,30 @@ DBusMessage * wpas_dbus_handler_create_interface(DBusMessage *message,
         * an error if we already control it.
         */
        if (wpa_supplicant_get_iface(global, ifname) != NULL) {
-               reply = dbus_message_new_error(message,
-                                              WPAS_DBUS_ERROR_IFACE_EXISTS,
-                                              "wpa_supplicant already "
-                                              "controls this interface.");
+               reply = dbus_message_new_error(
+                       message, WPAS_DBUS_ERROR_IFACE_EXISTS,
+                       "wpa_supplicant already controls this interface.");
        } else {
                struct wpa_supplicant *wpa_s;
                struct wpa_interface iface;
+
                os_memset(&iface, 0, sizeof(iface));
                iface.driver = driver;
                iface.ifname = ifname;
                iface.confname = confname;
                iface.bridge_ifname = bridge_ifname;
                /* Otherwise, have wpa_supplicant attach to it. */
-               if ((wpa_s = wpa_supplicant_add_iface(global, &iface))) {
+               wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
+               if (wpa_s && wpa_s->dbus_new_path) {
                        const char *path = wpa_s->dbus_new_path;
+
                        reply = dbus_message_new_method_return(message);
                        dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH,
-                                                &path, DBUS_TYPE_INVALID);
+                                                &path, DBUS_TYPE_INVALID);
                } else {
                        reply = wpas_dbus_error_unknown_error(
-                               message, "wpa_supplicant couldn't grab this "
-                               "interface.");
+                               message,
+                               "wpa_supplicant couldn't grab this interface.");
                }
        }
 
@@ -614,6 +624,9 @@ out:
 error:
        reply = wpas_dbus_error_invalid_args(message, NULL);
        goto out;
+oom:
+       reply = wpas_dbus_error_no_memory(message);
+       goto out;
 }
 
 
@@ -643,8 +656,8 @@ DBusMessage * wpas_dbus_handler_remove_interface(DBusMessage *message,
                reply = wpas_dbus_error_iface_unknown(message);
        else if (wpa_supplicant_remove_iface(global, wpa_s, 0)) {
                reply = wpas_dbus_error_unknown_error(
-                       message, "wpa_supplicant couldn't remove this "
-                       "interface.");
+                       message,
+                       "wpa_supplicant couldn't remove this interface.");
        }
 
        return reply;
@@ -672,19 +685,17 @@ DBusMessage * wpas_dbus_handler_get_interface(DBusMessage *message,
                              DBUS_TYPE_INVALID);
 
        wpa_s = wpa_supplicant_get_iface(global, ifname);
-       if (wpa_s == NULL)
+       if (wpa_s == NULL || wpa_s->dbus_new_path == NULL)
                return wpas_dbus_error_iface_unknown(message);
 
        path = wpa_s->dbus_new_path;
        reply = dbus_message_new_method_return(message);
        if (reply == NULL)
-               return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                             NULL);
+               return wpas_dbus_error_no_memory(message);
        if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
                                      DBUS_TYPE_INVALID)) {
                dbus_message_unref(reply);
-               return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                             NULL);
+               return wpas_dbus_error_no_memory(message);
        }
 
        return reply;
@@ -727,8 +738,8 @@ dbus_bool_t wpas_dbus_getter_debug_level(DBusMessageIter *iter,
  * Getter for "DebugTimestamp" property.
  */
 dbus_bool_t wpas_dbus_getter_debug_timestamp(DBusMessageIter *iter,
-                                             DBusError *error,
-                                             void *user_data)
+                                            DBusError *error,
+                                            void *user_data)
 {
        return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN,
                                                &wpa_debug_timestamp, error);
@@ -783,8 +794,8 @@ dbus_bool_t wpas_dbus_setter_debug_level(DBusMessageIter *iter,
        if (val < 0 ||
            wpa_supplicant_set_debug_params(global, val, wpa_debug_timestamp,
                                            wpa_debug_show_keys)) {
-               dbus_set_error_const(error, DBUS_ERROR_FAILED, "wrong debug "
-                                    "level value");
+               dbus_set_error_const(error, DBUS_ERROR_FAILED,
+                                    "wrong debug level value");
                return FALSE;
        }
 
@@ -866,8 +877,10 @@ dbus_bool_t wpas_dbus_getter_interfaces(DBusMessageIter *iter,
        unsigned int i = 0, num = 0;
        dbus_bool_t success;
 
-       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
-               num++;
+       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               if (wpa_s->dbus_new_path)
+                       num++;
+       }
 
        paths = os_calloc(num, sizeof(char *));
        if (!paths) {
@@ -875,8 +888,10 @@ dbus_bool_t wpas_dbus_getter_interfaces(DBusMessageIter *iter,
                return FALSE;
        }
 
-       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next)
-               paths[i++] = wpa_s->dbus_new_path;
+       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               if (wpa_s->dbus_new_path)
+                       paths[i++] = wpa_s->dbus_new_path;
+       }
 
        success = wpas_dbus_simple_array_property_getter(iter,
                                                         DBUS_TYPE_OBJECT_PATH,
@@ -934,8 +949,8 @@ dbus_bool_t wpas_dbus_getter_eap_methods(DBusMessageIter *iter,
  * and P2P that are determined at compile time.
  */
 dbus_bool_t wpas_dbus_getter_global_capabilities(DBusMessageIter *iter,
-                                                DBusError *error,
-                                                void *user_data)
+                                                DBusError *error,
+                                                void *user_data)
 {
        const char *capabilities[5] = { NULL, NULL, NULL, NULL, NULL };
        size_t num_items = 0;
@@ -964,8 +979,8 @@ static int wpas_dbus_get_scan_type(DBusMessage *message, DBusMessageIter *var,
                                   char **type, DBusMessage **reply)
 {
        if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_STRING) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                          "Type must be a string");
+               wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a string",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
                        message, "Wrong Type value type. String required");
                return -1;
@@ -987,36 +1002,36 @@ static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
        int len;
 
        if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
-                          "must be an array of arrays of bytes");
+               wpa_printf(MSG_DEBUG,
+                          "%s[dbus]: ssids must be an array of arrays of bytes",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
-                       message, "Wrong SSIDs value type. Array of arrays of "
-                       "bytes required");
+                       message,
+                       "Wrong SSIDs value type. Array of arrays of bytes required");
                return -1;
        }
 
        dbus_message_iter_recurse(var, &array_iter);
 
        if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
-           dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
-       {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ssids "
-                          "must be an array of arrays of bytes");
+           dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE) {
+               wpa_printf(MSG_DEBUG,
+                          "%s[dbus]: ssids must be an array of arrays of bytes",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
-                       message, "Wrong SSIDs value type. Array of arrays of "
-                       "bytes required");
+                       message,
+                       "Wrong SSIDs value type. Array of arrays of bytes required");
                return -1;
        }
 
-       while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
-       {
+       while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) {
                if (ssids_num >= WPAS_MAX_SCAN_SSIDS) {
-                       wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                                  "Too many ssids specified on scan dbus "
-                                  "call");
+                       wpa_printf(MSG_DEBUG,
+                                  "%s[dbus]: Too many ssids specified on scan dbus call",
+                                  __func__);
                        *reply = wpas_dbus_error_invalid_args(
-                               message, "Too many ssids specified. Specify "
-                               "at most four");
+                               message,
+                               "Too many ssids specified. Specify at most four");
                        return -1;
                }
 
@@ -1024,11 +1039,10 @@ static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
 
                dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
 
-               if (len > MAX_SSID_LEN) {
+               if (len > SSID_MAX_LEN) {
                        wpa_printf(MSG_DEBUG,
-                                  "wpas_dbus_handler_scan[dbus]: "
-                                  "SSID too long (len=%d max_len=%d)",
-                                  len, MAX_SSID_LEN);
+                                  "%s[dbus]: SSID too long (len=%d max_len=%d)",
+                                  __func__, len, SSID_MAX_LEN);
                        *reply = wpas_dbus_error_invalid_args(
                                message, "Invalid SSID: too long");
                        return -1;
@@ -1037,12 +1051,7 @@ static int wpas_dbus_get_scan_ssids(DBusMessage *message, DBusMessageIter *var,
                if (len != 0) {
                        ssid = os_malloc(len);
                        if (ssid == NULL) {
-                               wpa_printf(MSG_DEBUG,
-                                          "wpas_dbus_handler_scan[dbus]: "
-                                          "out of memory. Cannot allocate "
-                                          "memory for SSID");
-                               *reply = dbus_message_new_error(
-                                       message, DBUS_ERROR_NO_MEMORY, NULL);
+                               *reply = wpas_dbus_error_no_memory(message);
                                return -1;
                        }
                        os_memcpy(ssid, val, len);
@@ -1074,28 +1083,28 @@ static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
        int len;
 
        if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
-                          "be an array of arrays of bytes");
+               wpa_printf(MSG_DEBUG,
+                          "%s[dbus]: ies must be an array of arrays of bytes",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
-                       message, "Wrong IEs value type. Array of arrays of "
-                       "bytes required");
+                       message,
+                       "Wrong IEs value type. Array of arrays of bytes required");
                return -1;
        }
 
        dbus_message_iter_recurse(var, &array_iter);
 
        if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_ARRAY ||
-           dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE)
-       {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: ies must "
-                          "be an array of arrays of bytes");
+           dbus_message_iter_get_element_type(&array_iter) != DBUS_TYPE_BYTE) {
+               wpa_printf(MSG_DEBUG,
+                          "%s[dbus]: ies must be an array of arrays of bytes",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
                        message, "Wrong IEs value type. Array required");
                return -1;
        }
 
-       while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY)
-       {
+       while (dbus_message_iter_get_arg_type(&array_iter) == DBUS_TYPE_ARRAY) {
                dbus_message_iter_recurse(&array_iter, &sub_array_iter);
 
                dbus_message_iter_get_fixed_array(&sub_array_iter, &val, &len);
@@ -1106,12 +1115,8 @@ static int wpas_dbus_get_scan_ies(DBusMessage *message, DBusMessageIter *var,
 
                nies = os_realloc(ies, ies_len + len);
                if (nies == NULL) {
-                       wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                                  "out of memory. Cannot allocate memory for "
-                                  "IE");
                        os_free(ies);
-                       *reply = dbus_message_new_error(
-                               message, DBUS_ERROR_NO_MEMORY, NULL);
+                       *reply = wpas_dbus_error_no_memory(message);
                        return -1;
                }
                ies = nies;
@@ -1137,11 +1142,12 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
        int freqs_num = 0;
 
        if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_ARRAY) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                          "Channels must be an array of structs");
+               wpa_printf(MSG_DEBUG,
+                          "%s[dbus]: Channels must be an array of structs",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
-                       message, "Wrong Channels value type. Array of structs "
-                       "required");
+                       message,
+                       "Wrong Channels value type. Array of structs required");
                return -1;
        }
 
@@ -1149,11 +1155,11 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
 
        if (dbus_message_iter_get_arg_type(&array_iter) != DBUS_TYPE_STRUCT) {
                wpa_printf(MSG_DEBUG,
-                          "wpas_dbus_handler_scan[dbus]: Channels must be an "
-                          "array of structs");
+                          "%s[dbus]: Channels must be an array of structs",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
-                       message, "Wrong Channels value type. Array of structs "
-                       "required");
+                       message,
+                       "Wrong Channels value type. Array of structs required");
                return -1;
        }
 
@@ -1165,14 +1171,14 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
 
                if (dbus_message_iter_get_arg_type(&sub_array_iter) !=
                    DBUS_TYPE_UINT32) {
-                       wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                                  "Channel must by specified by struct of "
-                                  "two UINT32s %c",
+                       wpa_printf(MSG_DEBUG,
+                                  "%s[dbus]: Channel must by specified by struct of two UINT32s %c",
+                                  __func__,
                                   dbus_message_iter_get_arg_type(
                                           &sub_array_iter));
                        *reply = wpas_dbus_error_invalid_args(
-                               message, "Wrong Channel struct. Two UINT32s "
-                               "required");
+                               message,
+                               "Wrong Channel struct. Two UINT32s required");
                        os_free(freqs);
                        return -1;
                }
@@ -1181,9 +1187,9 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
                if (!dbus_message_iter_next(&sub_array_iter) ||
                    dbus_message_iter_get_arg_type(&sub_array_iter) !=
                    DBUS_TYPE_UINT32) {
-                       wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                                  "Channel must by specified by struct of "
-                                  "two UINT32s");
+                       wpa_printf(MSG_DEBUG,
+                                  "%s[dbus]: Channel must by specified by struct of two UINT32s",
+                                  __func__);
                        *reply = wpas_dbus_error_invalid_args(
                                message,
                                "Wrong Channel struct. Two UINT32s required");
@@ -1203,11 +1209,7 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
                        freqs = nfreqs;
                }
                if (freqs == NULL) {
-                       wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                                  "out of memory. can't allocate memory for "
-                                  "freqs");
-                       *reply = dbus_message_new_error(
-                               message, DBUS_ERROR_NO_MEMORY, NULL);
+                       *reply = wpas_dbus_error_no_memory(message);
                        return -1;
                }
 
@@ -1222,10 +1224,7 @@ static int wpas_dbus_get_scan_channels(DBusMessage *message,
                os_free(freqs);
        freqs = nfreqs;
        if (freqs == NULL) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                          "out of memory. Can't allocate memory for freqs");
-               *reply = dbus_message_new_error(
-                       message, DBUS_ERROR_NO_MEMORY, NULL);
+               *reply = wpas_dbus_error_no_memory(message);
                return -1;
        }
        freqs[freqs_num] = 0;
@@ -1241,8 +1240,8 @@ static int wpas_dbus_get_scan_allow_roam(DBusMessage *message,
                                         DBusMessage **reply)
 {
        if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                          "Type must be a boolean");
+               wpa_printf(MSG_DEBUG, "%s[dbus]: Type must be a boolean",
+                          __func__);
                *reply = wpas_dbus_error_invalid_args(
                        message, "Wrong Type value type. Boolean required");
                return -1;
@@ -1279,7 +1278,7 @@ DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
        dbus_message_iter_recurse(&iter, &dict_iter);
 
        while (dbus_message_iter_get_arg_type(&dict_iter) ==
-                       DBUS_TYPE_DICT_ENTRY) {
+              DBUS_TYPE_DICT_ENTRY) {
                dbus_message_iter_recurse(&dict_iter, &entry_iter);
                dbus_message_iter_get_basic(&entry_iter, &key);
                dbus_message_iter_next(&entry_iter);
@@ -1308,8 +1307,8 @@ DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
                                                          &reply) < 0)
                                goto out;
                } else {
-                       wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                                  "Unknown argument %s", key);
+                       wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown argument %s",
+                                  __func__, key);
                        reply = wpas_dbus_error_invalid_args(message, key);
                        goto out;
                }
@@ -1318,30 +1317,43 @@ DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
        }
 
        if (!type) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                          "Scan type not specified");
+               wpa_printf(MSG_DEBUG, "%s[dbus]: Scan type not specified",
+                          __func__);
                reply = wpas_dbus_error_invalid_args(message, key);
                goto out;
        }
 
-       if (!os_strcmp(type, "passive")) {
+       if (os_strcmp(type, "passive") == 0) {
                if (params.num_ssids || params.extra_ies_len) {
-                       wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                                  "SSIDs or IEs specified for passive scan.");
+                       wpa_printf(MSG_DEBUG,
+                                  "%s[dbus]: SSIDs or IEs specified for passive scan.",
+                                  __func__);
                        reply = wpas_dbus_error_invalid_args(
-                               message, "You can specify only Channels in "
-                               "passive scan");
+                               message,
+                               "You can specify only Channels in passive scan");
                        goto out;
-               } else if (params.freqs && params.freqs[0]) {
-                       if (wpa_supplicant_trigger_scan(wpa_s, &params)) {
-                               reply = wpas_dbus_error_scan_error(
-                                       message, "Scan request rejected");
-                       }
                } else {
-                       wpa_s->scan_req = MANUAL_SCAN_REQ;
-                       wpa_supplicant_req_scan(wpa_s, 0, 0);
+                       if (wpa_s->sched_scanning) {
+                               wpa_printf(MSG_DEBUG,
+                                          "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed",
+                                          __func__);
+                               wpa_supplicant_cancel_sched_scan(wpa_s);
+                       }
+
+                       if (params.freqs && params.freqs[0]) {
+                               wpa_s->last_scan_req = MANUAL_SCAN_REQ;
+                               if (wpa_supplicant_trigger_scan(wpa_s,
+                                                               &params)) {
+                                       reply = wpas_dbus_error_scan_error(
+                                               message,
+                                               "Scan request rejected");
+                               }
+                       } else {
+                               wpa_s->scan_req = MANUAL_SCAN_REQ;
+                               wpa_supplicant_req_scan(wpa_s, 0, 0);
+                       }
                }
-       } else if (!os_strcmp(type, "active")) {
+       } else if (os_strcmp(type, "active") == 0) {
                if (!params.num_ssids) {
                        /* Add wildcard ssid */
                        params.num_ssids++;
@@ -1349,13 +1361,21 @@ DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
 #ifdef CONFIG_AUTOSCAN
                autoscan_deinit(wpa_s);
 #endif /* CONFIG_AUTOSCAN */
+               if (wpa_s->sched_scanning) {
+                       wpa_printf(MSG_DEBUG,
+                                  "%s[dbus]: Stop ongoing sched_scan to allow requested scan to proceed",
+                                  __func__);
+                       wpa_supplicant_cancel_sched_scan(wpa_s);
+               }
+
+               wpa_s->last_scan_req = MANUAL_SCAN_REQ;
                if (wpa_supplicant_trigger_scan(wpa_s, &params)) {
                        reply = wpas_dbus_error_scan_error(
                                message, "Scan request rejected");
                }
        } else {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
-                          "Unknown scan type: %s", type);
+               wpa_printf(MSG_DEBUG, "%s[dbus]: Unknown scan type: %s",
+                          __func__, type);
                reply = wpas_dbus_error_invalid_args(message,
                                                     "Wrong scan type");
                goto out;
@@ -1435,8 +1455,7 @@ DBusMessage * wpas_dbus_handler_signal_poll(DBusMessage *message,
 nomem:
        if (reply)
                dbus_message_unref(reply);
-       reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY, NULL);
-       return reply;
+       return wpas_dbus_error_no_memory(message);
 }
 
 
@@ -1484,14 +1503,14 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
 
        dbus_message_iter_init(message, &iter);
 
-       ssid = wpa_config_add_network(wpa_s->conf);
+       if (wpa_s->dbus_new_path)
+               ssid = wpa_config_add_network(wpa_s->conf);
        if (ssid == NULL) {
-               wpa_printf(MSG_ERROR, "wpas_dbus_handler_add_network[dbus]: "
-                          "can't add new interface.");
+               wpa_printf(MSG_ERROR, "%s[dbus]: can't add new interface.",
+                          __func__);
                reply = wpas_dbus_error_unknown_error(
                        message,
-                       "wpa_supplicant could not add "
-                       "a network on this interface.");
+                       "wpa_supplicant could not add a network on this interface.");
                goto err;
        }
        wpas_notify_network_added(wpa_s, ssid);
@@ -1500,9 +1519,9 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
 
        dbus_error_init(&error);
        if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_handler_add_network[dbus]:"
-                          "control interface couldn't set network "
-                          "properties");
+               wpa_printf(MSG_DEBUG,
+                          "%s[dbus]: control interface couldn't set network properties",
+                          __func__);
                reply = wpas_dbus_reply_new_from_error(message, &error,
                                                       DBUS_ERROR_INVALID_ARGS,
                                                       "Failed to add network");
@@ -1517,15 +1536,13 @@ DBusMessage * wpas_dbus_handler_add_network(DBusMessage *message,
 
        reply = dbus_message_new_method_return(message);
        if (reply == NULL) {
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
+               reply = wpas_dbus_error_no_memory(message);
                goto err;
        }
        if (!dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
                                      DBUS_TYPE_INVALID)) {
                dbus_message_unref(reply);
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
+               reply = wpas_dbus_error_no_memory(message);
                goto err;
        }
 
@@ -1586,6 +1603,30 @@ DBusMessage * wpas_dbus_handler_reattach(DBusMessage *message,
 
 
 /**
+ * wpas_dbus_handler_reconnect - Reconnect if disconnected
+ * @message: Pointer to incoming dbus message
+ * @wpa_s: wpa_supplicant structure for a network interface
+ * Returns: InterfaceDisabled DBus error message if disabled
+ * or NULL otherwise.
+ *
+ * Handler function for "Reconnect" method call of network interface.
+ */
+DBusMessage * wpas_dbus_handler_reconnect(DBusMessage *message,
+               struct wpa_supplicant *wpa_s)
+{
+       if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
+               return dbus_message_new_error(message,
+                                             WPAS_DBUS_ERROR_IFACE_DISABLED,
+                                             "This interface is disabled");
+       }
+
+       if (wpa_s->disconnected)
+               wpas_request_connection(wpa_s);
+       return NULL;
+}
+
+
+/**
  * wpas_dbus_handler_remove_network - Remove a configured network
  * @message: Pointer to incoming dbus message
  * @wpa_s: wpa_supplicant structure for a network interface
@@ -1611,7 +1652,7 @@ DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
        iface = wpas_dbus_new_decompose_object_path(op,
                                                    WPAS_DBUS_NEW_NETWORKS_PART,
                                                    &net_id);
-       if (iface == NULL || net_id == NULL ||
+       if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
            os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
                reply = wpas_dbus_error_invalid_args(message, op);
                goto out;
@@ -1638,19 +1679,19 @@ DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
                wpa_supplicant_deauthenticate(wpa_s,
                                              WLAN_REASON_DEAUTH_LEAVING);
        else if (!was_disabled && wpa_s->sched_scanning) {
-               wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
-                          "network from filters");
+               wpa_printf(MSG_DEBUG,
+                          "Stop ongoing sched_scan to remove network from filters");
                wpa_supplicant_cancel_sched_scan(wpa_s);
                wpa_supplicant_req_scan(wpa_s, 0, 0);
        }
 
        if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
                wpa_printf(MSG_ERROR,
-                          "wpas_dbus_handler_remove_network[dbus]: "
-                          "error occurred when removing network %d", id);
+                          "%s[dbus]: error occurred when removing network %d",
+                          __func__, id);
                reply = wpas_dbus_error_unknown_error(
-                       message, "error removing the specified network on "
-                       "this interface.");
+                       message,
+                       "error removing the specified network on is interface.");
                goto out;
        }
 
@@ -1668,9 +1709,8 @@ static void remove_network(void *arg, struct wpa_ssid *ssid)
 
        if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) {
                wpa_printf(MSG_ERROR,
-                          "wpas_dbus_handler_remove_all_networks[dbus]: "
-                          "error occurred when removing network %d",
-                          ssid->id);
+                          "%s[dbus]: error occurred when removing network %d",
+                          __func__, ssid->id);
                return;
        }
 
@@ -1725,7 +1765,7 @@ DBusMessage * wpas_dbus_handler_select_network(DBusMessage *message,
        iface = wpas_dbus_new_decompose_object_path(op,
                                                    WPAS_DBUS_NEW_NETWORKS_PART,
                                                    &net_id);
-       if (iface == NULL || net_id == NULL ||
+       if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
            os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
                reply = wpas_dbus_error_invalid_args(message, op);
                goto out;
@@ -1772,10 +1812,10 @@ DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message,
        struct wpa_ssid *ssid;
 
        if (!dbus_message_get_args(message, NULL,
-                                  DBUS_TYPE_OBJECT_PATH, &op,
-                                  DBUS_TYPE_STRING, &field,
-                                  DBUS_TYPE_STRING, &value,
-                                  DBUS_TYPE_INVALID))
+                                  DBUS_TYPE_OBJECT_PATH, &op,
+                                  DBUS_TYPE_STRING, &field,
+                                  DBUS_TYPE_STRING, &value,
+                                  DBUS_TYPE_INVALID))
                return wpas_dbus_error_invalid_args(message, NULL);
 
        /* Extract the network ID and ensure the network */
@@ -1783,7 +1823,7 @@ DBusMessage * wpas_dbus_handler_network_reply(DBusMessage *message,
        iface = wpas_dbus_new_decompose_object_path(op,
                                                    WPAS_DBUS_NEW_NETWORKS_PART,
                                                    &net_id);
-       if (iface == NULL || net_id == NULL ||
+       if (iface == NULL || net_id == NULL || !wpa_s->dbus_new_path ||
            os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
                reply = wpas_dbus_error_invalid_args(message, op);
                goto out;
@@ -1857,26 +1897,18 @@ DBusMessage * wpas_dbus_handler_add_blob(DBusMessage *message,
 
        blob = os_zalloc(sizeof(*blob));
        if (!blob) {
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
+               reply = wpas_dbus_error_no_memory(message);
                goto err;
        }
 
        blob->data = os_malloc(blob_len);
-       if (!blob->data) {
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
+       blob->name = os_strdup(blob_name);
+       if (!blob->data || !blob->name) {
+               reply = wpas_dbus_error_no_memory(message);
                goto err;
        }
        os_memcpy(blob->data, blob_data, blob_len);
-
        blob->len = blob_len;
-       blob->name = os_strdup(blob_name);
-       if (!blob->name) {
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
-               goto err;
-       }
 
        wpa_config_set_blob(wpa_s->conf, blob);
        wpas_notify_blob_added(wpa_s, blob->name);
@@ -1921,39 +1953,21 @@ DBusMessage * wpas_dbus_handler_get_blob(DBusMessage *message,
        }
 
        reply = dbus_message_new_method_return(message);
-       if (!reply) {
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
-               goto out;
-       }
+       if (!reply)
+               return wpas_dbus_error_no_memory(message);
 
        dbus_message_iter_init_append(reply, &iter);
 
        if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
                                              DBUS_TYPE_BYTE_AS_STRING,
-                                             &array_iter)) {
+                                             &array_iter) ||
+           !dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
+                                                 &(blob->data), blob->len) ||
+           !dbus_message_iter_close_container(&iter, &array_iter)) {
                dbus_message_unref(reply);
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
-               goto out;
-       }
-
-       if (!dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE,
-                                                 &(blob->data), blob->len)) {
-               dbus_message_unref(reply);
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
-               goto out;
+               reply = wpas_dbus_error_no_memory(message);
        }
 
-       if (!dbus_message_iter_close_container(&iter, &array_iter)) {
-               dbus_message_unref(reply);
-               reply = dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                              NULL);
-               goto out;
-       }
-
-out:
        return reply;
 }
 
@@ -2035,11 +2049,10 @@ DBusMessage * wpas_dbus_handler_autoscan(DBusMessage *message,
 
        if (arg != NULL && os_strlen(arg) > 0) {
                char *tmp;
+
                tmp = os_strdup(arg);
                if (tmp == NULL) {
-                       reply = dbus_message_new_error(message,
-                                                      DBUS_ERROR_NO_MEMORY,
-                                                      NULL);
+                       reply = wpas_dbus_error_no_memory(message);
                } else {
                        os_free(wpa_s->conf->autoscan);
                        wpa_s->conf->autoscan = tmp;
@@ -2301,15 +2314,16 @@ DBusMessage * wpas_dbus_handler_set_pkcs11_engine_and_module_path(
                                                   pkcs11_module_path))
                return dbus_message_new_error(
                        message, DBUS_ERROR_FAILED,
-                       "Reinit of the EAPOL state machine with the new PKCS "
-                       "#11 engine and module path failed.");
-
-       wpa_dbus_mark_property_changed(
-               wpa_s->global->dbus, wpa_s->dbus_new_path,
-               WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11EnginePath");
-       wpa_dbus_mark_property_changed(
-               wpa_s->global->dbus, wpa_s->dbus_new_path,
-               WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11ModulePath");
+                       "Reinit of the EAPOL state machine with the new PKCS #11 engine and module path failed.");
+
+       if (wpa_s->dbus_new_path) {
+               wpa_dbus_mark_property_changed(
+                       wpa_s->global->dbus, wpa_s->dbus_new_path,
+                       WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11EnginePath");
+               wpa_dbus_mark_property_changed(
+                       wpa_s->global->dbus, wpa_s->dbus_new_path,
+                       WPAS_DBUS_NEW_IFACE_INTERFACE, "PKCS11ModulePath");
+       }
 
        return NULL;
 }
@@ -2344,6 +2358,7 @@ dbus_bool_t wpas_dbus_getter_capabilities(DBusMessageIter *iter,
        /***** pairwise cipher */
        if (res < 0) {
                const char *args[] = {"ccmp", "tkip", "none"};
+
                if (!wpa_dbus_dict_append_string_array(
                            &iter_dict, "Pairwise", args,
                            ARRAY_SIZE(args)))
@@ -2383,6 +2398,7 @@ dbus_bool_t wpas_dbus_getter_capabilities(DBusMessageIter *iter,
                const char *args[] = {
                        "ccmp", "tkip", "wep104", "wep40"
                };
+
                if (!wpa_dbus_dict_append_string_array(
                            &iter_dict, "Group", args,
                            ARRAY_SIZE(args)))
@@ -2501,6 +2517,7 @@ dbus_bool_t wpas_dbus_getter_capabilities(DBusMessageIter *iter,
        /***** WPA protocol */
        if (res < 0) {
                const char *args[] = { "rsn", "wpa" };
+
                if (!wpa_dbus_dict_append_string_array(
                            &iter_dict, "Protocol", args,
                            ARRAY_SIZE(args)))
@@ -2528,6 +2545,7 @@ dbus_bool_t wpas_dbus_getter_capabilities(DBusMessageIter *iter,
        /***** auth alg */
        if (res < 0) {
                const char *args[] = { "open", "shared", "leap" };
+
                if (!wpa_dbus_dict_append_string_array(
                            &iter_dict, "AuthAlg", args,
                            ARRAY_SIZE(args)))
@@ -2652,7 +2670,7 @@ dbus_bool_t wpas_dbus_getter_state(DBusMessageIter *iter, DBusError *error,
  * Getter for "scanning" property.
  */
 dbus_bool_t wpas_dbus_getter_scanning(DBusMessageIter *iter, DBusError *error,
-                                      void *user_data)
+                                     void *user_data)
 {
        struct wpa_supplicant *wpa_s = user_data;
        dbus_bool_t scanning = wpa_s->scanning ? TRUE : FALSE;
@@ -2774,6 +2792,7 @@ dbus_bool_t wpas_dbus_getter_disconnect_reason(DBusMessageIter *iter,
 {
        struct wpa_supplicant *wpa_s = user_data;
        dbus_int32_t reason = wpa_s->disconnect_reason;
+
        return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_INT32,
                                                &reason, error);
 }
@@ -3028,8 +3047,8 @@ dbus_bool_t wpas_dbus_getter_driver(DBusMessageIter *iter, DBusError *error,
        const char *driver;
 
        if (wpa_s->driver == NULL || wpa_s->driver->name == NULL) {
-               wpa_printf(MSG_DEBUG, "wpas_dbus_getter_driver[dbus]: "
-                          "wpa_s has no driver set");
+               wpa_printf(MSG_DEBUG, "%s[dbus]: wpa_s has no driver set",
+                          __func__);
                dbus_set_error(error, DBUS_ERROR_FAILED, "%s: no driver set",
                               __func__);
                return FALSE;
@@ -3057,7 +3076,7 @@ dbus_bool_t wpas_dbus_getter_current_bss(DBusMessageIter *iter,
        struct wpa_supplicant *wpa_s = user_data;
        char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *bss_obj_path = path_buf;
 
-       if (wpa_s->current_bss)
+       if (wpa_s->current_bss && wpa_s->dbus_new_path)
                os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
                            "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
                            wpa_s->dbus_new_path, wpa_s->current_bss->id);
@@ -3085,7 +3104,7 @@ dbus_bool_t wpas_dbus_getter_current_network(DBusMessageIter *iter,
        struct wpa_supplicant *wpa_s = user_data;
        char path_buf[WPAS_DBUS_OBJECT_PATH_MAX], *net_obj_path = path_buf;
 
-       if (wpa_s->current_ssid)
+       if (wpa_s->current_ssid && wpa_s->dbus_new_path)
                os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
                            "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
                            wpa_s->dbus_new_path, wpa_s->current_ssid->id);
@@ -3149,6 +3168,7 @@ dbus_bool_t wpas_dbus_getter_bridge_ifname(DBusMessageIter *iter,
 {
        struct wpa_supplicant *wpa_s = user_data;
        const char *bridge_ifname = wpa_s->bridge_ifname;
+
        return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
                                                &bridge_ifname, error);
 }
@@ -3172,6 +3192,12 @@ dbus_bool_t wpas_dbus_getter_bsss(DBusMessageIter *iter, DBusError *error,
        unsigned int i = 0;
        dbus_bool_t success = FALSE;
 
+       if (!wpa_s->dbus_new_path) {
+               dbus_set_error(error, DBUS_ERROR_FAILED,
+                              "%s: no D-Bus interface", __func__);
+               return FALSE;
+       }
+
        paths = os_calloc(wpa_s->num_bss, sizeof(char *));
        if (!paths) {
                dbus_set_error_const(error, DBUS_ERROR_NO_MEMORY, "no memory");
@@ -3223,6 +3249,12 @@ dbus_bool_t wpas_dbus_getter_networks(DBusMessageIter *iter, DBusError *error,
        unsigned int i = 0, num = 0;
        dbus_bool_t success = FALSE;
 
+       if (!wpa_s->dbus_new_path) {
+               dbus_set_error(error, DBUS_ERROR_FAILED,
+                              "%s: no D-Bus interface", __func__);
+               return FALSE;
+       }
+
        for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
                if (!network_is_persistent_group(ssid))
                        num++;
@@ -3239,7 +3271,8 @@ dbus_bool_t wpas_dbus_getter_networks(DBusMessageIter *iter, DBusError *error,
                        continue;
                paths[i] = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
                if (paths[i] == NULL) {
-                       dbus_set_error(error, DBUS_ERROR_NO_MEMORY, "no memory");
+                       dbus_set_error(error, DBUS_ERROR_NO_MEMORY,
+                                      "no memory");
                        goto out;
                }
 
@@ -3380,7 +3413,7 @@ static struct wpa_bss * get_bss_helper(struct bss_handler_args *args,
 
        if (!res) {
                wpa_printf(MSG_ERROR, "%s[dbus]: no bss with id %d found",
-                          func_name, args->id);
+                          func_name, args->id);
                dbus_set_error(error, DBUS_ERROR_FAILED,
                               "%s: BSS %d not found",
                               func_name, args->id);
@@ -3621,7 +3654,7 @@ static dbus_bool_t wpas_dbus_get_bss_security_prop(DBusMessageIter *iter,
        DBusMessageIter iter_dict, variant_iter;
        const char *group;
        const char *pairwise[5]; /* max 5 pairwise ciphers is supported */
-       const char *key_mgmt[8]; /* max 8 key managements may be supported */
+       const char *key_mgmt[9]; /* max 9 key managements may be supported */
        int n;
 
        if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
@@ -3645,8 +3678,14 @@ static dbus_bool_t wpas_dbus_get_bss_security_prop(DBusMessageIter *iter,
                key_mgmt[n++] = "wpa-ft-eap";
        if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256)
                key_mgmt[n++] = "wpa-eap-sha256";
+#ifdef CONFIG_SUITEB
        if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B)
                key_mgmt[n++] = "wpa-eap-suite-b";
+#endif /* CONFIG_SUITEB */
+#ifdef CONFIG_SUITEB192
+       if (ie_data->key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192)
+               key_mgmt[n++] = "wpa-eap-suite-b-192";
+#endif /* CONFIG_SUITEB192 */
        if (ie_data->key_mgmt & WPA_KEY_MGMT_NONE)
                key_mgmt[n++] = "wpa-none";
 
@@ -3816,6 +3855,7 @@ dbus_bool_t wpas_dbus_getter_bss_wps(DBusMessageIter *iter, DBusError *error,
        struct wpabuf *wps_ie;
 #endif /* CONFIG_WPS */
        DBusMessageIter iter_dict, variant_iter;
+       int wps_support = 0;
        const char *type = "";
 
        res = get_bss_helper(args, error, __func__);
@@ -3830,6 +3870,7 @@ dbus_bool_t wpas_dbus_getter_bss_wps(DBusMessageIter *iter, DBusError *error,
 #ifdef CONFIG_WPS
        wps_ie = wpa_bss_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
        if (wps_ie) {
+               wps_support = 1;
                if (wps_is_selected_pbc_registrar(wps_ie))
                        type = "pbc";
                else if (wps_is_selected_pin_registrar(wps_ie))
@@ -3839,7 +3880,7 @@ dbus_bool_t wpas_dbus_getter_bss_wps(DBusMessageIter *iter, DBusError *error,
        }
 #endif /* CONFIG_WPS */
 
-       if (!wpa_dbus_dict_append_string(&iter_dict, "Type", type) ||
+       if ((wps_support && !wpa_dbus_dict_append_string(&iter_dict, "Type", type)) ||
            !wpa_dbus_dict_close_write(&variant_iter, &iter_dict) ||
            !dbus_message_iter_close_container(iter, &variant_iter))
                goto nomem;
@@ -4063,8 +4104,7 @@ DBusMessage * wpas_dbus_handler_subscribe_preq(
 
        name = os_strdup(dbus_message_get_sender(message));
        if (!name)
-               return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                             "out of memory");
+               return wpas_dbus_error_no_memory(message);
 
        wpa_s->preq_notify_peer = name;
 
@@ -4128,7 +4168,7 @@ void wpas_dbus_signal_preq(struct wpa_supplicant *wpa_s,
        struct wpas_dbus_priv *priv = wpa_s->global->dbus;
 
        /* Do nothing if the control interface is not turned on */
-       if (priv == NULL)
+       if (priv == NULL || !wpa_s->dbus_new_path)
                return;
 
        if (wpa_s->preq_notify_peer == NULL)