D-Bus: Make P2P Group Passphrase property getter available for P2P Client
[mech_eap.git] / wpa_supplicant / dbus / dbus_new_handlers_p2p.c
index 1a17e65..9c880a2 100644 (file)
@@ -35,9 +35,9 @@
  * @addr - out param must be of ETH_ALEN size
  * Returns 0 if valid (including MAC), -1 otherwise
  */
-static int parse_peer_object_path(char *peer_path, u8 addr[ETH_ALEN])
+static int parse_peer_object_path(const char *peer_path, u8 addr[ETH_ALEN])
 {
-       char *p;
+       const char *p;
 
        if (!peer_path)
                return -1;
@@ -57,12 +57,12 @@ static int parse_peer_object_path(char *peer_path, u8 addr[ETH_ALEN])
  *
  * Convenience function to create and return an invalid persistent group error.
  */
-static DBusMessage * wpas_dbus_error_persistent_group_unknown(
-       DBusMessage *message)
+static DBusMessage *
+wpas_dbus_error_persistent_group_unknown(DBusMessage *message)
 {
-       return dbus_message_new_error(message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
-                                     "There is no such persistent group in "
-                                     "this P2P device.");
+       return dbus_message_new_error(
+               message, WPAS_DBUS_ERROR_NETWORK_UNKNOWN,
+               "There is no such persistent group in this P2P device.");
 }
 
 
@@ -89,12 +89,12 @@ DBusMessage * wpas_dbus_handler_p2p_find(DBusMessage *message,
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto error;
 
-               if (!os_strcmp(entry.key, "Timeout") &&
-                   (entry.type == DBUS_TYPE_INT32)) {
+               if (os_strcmp(entry.key, "Timeout") == 0 &&
+                   entry.type == DBUS_TYPE_INT32) {
                        timeout = entry.uint32_value;
                } else if (os_strcmp(entry.key, "RequestedDeviceTypes") == 0) {
-                       if ((entry.type != DBUS_TYPE_ARRAY) ||
-                           (entry.array_type != WPAS_DBUS_TYPE_BINARRAY))
+                       if (entry.type != DBUS_TYPE_ARRAY ||
+                           entry.array_type != WPAS_DBUS_TYPE_BINARRAY)
                                goto error_clear;
 
                        os_free(req_dev_types);
@@ -105,20 +105,20 @@ DBusMessage * wpas_dbus_handler_p2p_find(DBusMessage *message,
 
                        for (i = 0; i < entry.array_len; i++) {
                                if (wpabuf_len(entry.binarray_value[i]) !=
-                                                       WPS_DEV_TYPE_LEN)
+                                   WPS_DEV_TYPE_LEN)
                                        goto error_clear;
                                os_memcpy(req_dev_types + i * WPS_DEV_TYPE_LEN,
                                          wpabuf_head(entry.binarray_value[i]),
                                          WPS_DEV_TYPE_LEN);
                        }
                        num_req_dev_types = entry.array_len;
-               } else if (!os_strcmp(entry.key, "DiscoveryType") &&
-                          (entry.type == DBUS_TYPE_STRING)) {
-                       if (!os_strcmp(entry.str_value, "start_with_full"))
+               } else if (os_strcmp(entry.key, "DiscoveryType") == 0 &&
+                          entry.type == DBUS_TYPE_STRING) {
+                       if (os_strcmp(entry.str_value, "start_with_full") == 0)
                                type = P2P_FIND_START_WITH_FULL;
-                       else if (!os_strcmp(entry.str_value, "social"))
+                       else if (os_strcmp(entry.str_value, "social") == 0)
                                type = P2P_FIND_ONLY_SOCIAL;
-                       else if (!os_strcmp(entry.str_value, "progressive"))
+                       else if (os_strcmp(entry.str_value, "progressive") == 0)
                                type = P2P_FIND_PROGRESSIVE;
                        else
                                goto error_clear;
@@ -186,15 +186,16 @@ DBusMessage * wpas_dbus_handler_p2p_listen(DBusMessage *message,
 
        if (!dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &timeout,
                                   DBUS_TYPE_INVALID))
-               return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                             NULL);
+               return wpas_dbus_error_no_memory(message);
 
        if (wpa_s->p2p_dev)
                wpa_s = wpa_s->p2p_dev;
 
-       if (wpas_p2p_listen(wpa_s, (unsigned int)timeout))
-               return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
-                                             NULL);
+       if (wpas_p2p_listen(wpa_s, (unsigned int) timeout)) {
+               return dbus_message_new_error(message,
+                                             WPAS_DBUS_ERROR_UNKNOWN_ERROR,
+                                             "Could not start P2P listen");
+       }
 
        return NULL;
 }
@@ -218,11 +219,11 @@ DBusMessage * wpas_dbus_handler_p2p_extendedlisten(
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto error;
 
-               if (!os_strcmp(entry.key, "period") &&
-                   (entry.type == DBUS_TYPE_INT32))
+               if (os_strcmp(entry.key, "period") == 0 &&
+                   entry.type == DBUS_TYPE_INT32)
                        period = entry.uint32_value;
-               else if (!os_strcmp(entry.key, "interval") &&
-                        (entry.type == DBUS_TYPE_INT32))
+               else if (os_strcmp(entry.key, "interval") == 0 &&
+                        entry.type == DBUS_TYPE_INT32)
                        interval = entry.uint32_value;
                else
                        goto error_clear;
@@ -263,16 +264,16 @@ DBusMessage * wpas_dbus_handler_p2p_presence_request(
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto error;
 
-               if (!os_strcmp(entry.key, "duration1") &&
-                   (entry.type == DBUS_TYPE_INT32))
+               if (os_strcmp(entry.key, "duration1") == 0 &&
+                   entry.type == DBUS_TYPE_INT32)
                        dur1 = entry.uint32_value;
-               else if (!os_strcmp(entry.key, "interval1") &&
+               else if (os_strcmp(entry.key, "interval1") == 0 &&
                         entry.type == DBUS_TYPE_INT32)
                        int1 = entry.uint32_value;
-               else if (!os_strcmp(entry.key, "duration2") &&
+               else if (os_strcmp(entry.key, "duration2") == 0 &&
                         entry.type == DBUS_TYPE_INT32)
                        dur2 = entry.uint32_value;
-               else if (!os_strcmp(entry.key, "interval2") &&
+               else if (os_strcmp(entry.key, "interval2") == 0 &&
                         entry.type == DBUS_TYPE_INT32)
                        int2 = entry.uint32_value;
                else
@@ -308,7 +309,6 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
        int persistent_group = 0;
        int freq = 0;
        char *iface = NULL;
-       char *net_id_str = NULL;
        unsigned int group_id = 0;
        struct wpa_ssid *ssid;
 
@@ -321,15 +321,16 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto inv_args;
 
-               if (!os_strcmp(entry.key, "persistent") &&
-                   (entry.type == DBUS_TYPE_BOOLEAN)) {
-                       persistent_group = (entry.bool_value == TRUE) ? 1 : 0;
-               } else if (!os_strcmp(entry.key, "frequency") &&
-                          (entry.type == DBUS_TYPE_INT32)) {
+               if (os_strcmp(entry.key, "persistent") == 0 &&
+                   entry.type == DBUS_TYPE_BOOLEAN) {
+                       persistent_group = entry.bool_value;
+               } else if (os_strcmp(entry.key, "frequency") == 0 &&
+                          entry.type == DBUS_TYPE_INT32) {
                        freq = entry.int32_value;
                        if (freq <= 0)
                                goto inv_args_clear;
-               } else if (!os_strcmp(entry.key, "persistent_group_object") &&
+               } else if (os_strcmp(entry.key, "persistent_group_object") ==
+                          0 &&
                           entry.type == DBUS_TYPE_OBJECT_PATH)
                        pg_object_path = os_strdup(entry.str_value);
                else
@@ -342,14 +343,17 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
                wpa_s = wpa_s->p2p_dev;
 
        if (pg_object_path != NULL) {
+               char *net_id_str;
+
                /*
                 * A persistent group Object Path is defined meaning we want
                 * to re-invoke a persistent group.
                 */
 
-               iface = wpas_dbus_new_decompose_object_path(pg_object_path, 1,
-                                                           &net_id_str, NULL);
-               if (iface == NULL ||
+               iface = wpas_dbus_new_decompose_object_path(
+                       pg_object_path, WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART,
+                       &net_id_str);
+               if (iface == NULL || net_id_str == NULL ||
                    os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
                        reply =
                            wpas_dbus_error_invalid_args(message,
@@ -381,7 +385,6 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
 
 out:
        os_free(pg_object_path);
-       os_free(net_id_str);
        os_free(iface);
        return reply;
 inv_args_clear:
@@ -416,8 +419,7 @@ static dbus_bool_t wpa_dbus_p2p_check_enabled(struct wpa_supplicant *wpa_s,
                                "P2P is not available for this interface");
                }
                dbus_set_error_const(error, DBUS_ERROR_FAILED,
-                                    "P2P is not available for this "
-                                    "interface");
+                                    "P2P is not available for this interface");
                return FALSE;
        }
        return TRUE;
@@ -475,42 +477,42 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto inv_args;
 
-               if (!os_strcmp(entry.key, "peer") &&
-                   (entry.type == DBUS_TYPE_OBJECT_PATH)) {
+               if (os_strcmp(entry.key, "peer") == 0 &&
+                   entry.type == DBUS_TYPE_OBJECT_PATH) {
                        peer_object_path = os_strdup(entry.str_value);
-               } else if (!os_strcmp(entry.key, "persistent") &&
-                          (entry.type == DBUS_TYPE_BOOLEAN)) {
-                       persistent_group = (entry.bool_value == TRUE) ? 1 : 0;
-               } else if (!os_strcmp(entry.key, "join") &&
-                          (entry.type == DBUS_TYPE_BOOLEAN)) {
-                       join = (entry.bool_value == TRUE) ? 1 : 0;
-               } else if (!os_strcmp(entry.key, "authorize_only") &&
-                          (entry.type == DBUS_TYPE_BOOLEAN)) {
-                       authorize_only = (entry.bool_value == TRUE) ? 1 : 0;
-               } else if (!os_strcmp(entry.key, "frequency") &&
-                          (entry.type == DBUS_TYPE_INT32)) {
+               } else if (os_strcmp(entry.key, "persistent") == 0 &&
+                          entry.type == DBUS_TYPE_BOOLEAN) {
+                       persistent_group = entry.bool_value;
+               } else if (os_strcmp(entry.key, "join") == 0 &&
+                          entry.type == DBUS_TYPE_BOOLEAN) {
+                       join = entry.bool_value;
+               } else if (os_strcmp(entry.key, "authorize_only") == 0 &&
+                          entry.type == DBUS_TYPE_BOOLEAN) {
+                       authorize_only = entry.bool_value;
+               } else if (os_strcmp(entry.key, "frequency") == 0 &&
+                          entry.type == DBUS_TYPE_INT32) {
                        freq = entry.int32_value;
                        if (freq <= 0)
                                goto inv_args_clear;
-               } else if (!os_strcmp(entry.key, "go_intent") &&
-                          (entry.type == DBUS_TYPE_INT32)) {
+               } else if (os_strcmp(entry.key, "go_intent") == 0 &&
+                          entry.type == DBUS_TYPE_INT32) {
                        go_intent = entry.int32_value;
                        if ((go_intent < 0) || (go_intent > 15))
                                goto inv_args_clear;
-               } else if (!os_strcmp(entry.key, "wps_method") &&
-                          (entry.type == DBUS_TYPE_STRING)) {
-                       if (!os_strcmp(entry.str_value, "pbc"))
+               } else if (os_strcmp(entry.key, "wps_method") == 0 &&
+                          entry.type == DBUS_TYPE_STRING) {
+                       if (os_strcmp(entry.str_value, "pbc") == 0)
                                wps_method = WPS_PBC;
-                       else if (!os_strcmp(entry.str_value, "pin"))
+                       else if (os_strcmp(entry.str_value, "pin") == 0)
                                wps_method = WPS_PIN_DISPLAY;
-                       else if (!os_strcmp(entry.str_value, "display"))
+                       else if (os_strcmp(entry.str_value, "display") == 0)
                                wps_method = WPS_PIN_DISPLAY;
-                       else if (!os_strcmp(entry.str_value, "keypad"))
+                       else if (os_strcmp(entry.str_value, "keypad") == 0)
                                wps_method = WPS_PIN_KEYPAD;
                        else
                                goto inv_args_clear;
-               } else if (!os_strcmp(entry.key, "pin") &&
-                          (entry.type == DBUS_TYPE_STRING)) {
+               } else if (os_strcmp(entry.key, "pin") == 0 &&
+                          entry.type == DBUS_TYPE_STRING) {
                        pin = os_strdup(entry.str_value);
                } else
                        goto inv_args_clear;
@@ -518,15 +520,15 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
                wpa_dbus_dict_entry_clear(&entry);
        }
 
-       if (!peer_object_path || (wps_method == WPS_NOT_READY) ||
-           (parse_peer_object_path(peer_object_path, addr) < 0) ||
+       if (wps_method == WPS_NOT_READY ||
+           parse_peer_object_path(peer_object_path, addr) < 0 ||
            !p2p_peer_known(wpa_s->global->p2p, addr))
                goto inv_args;
 
        /*
         * Validate the wps_method specified and the pin value.
         */
-       if ((!pin || !pin[0]) && (wps_method == WPS_PIN_KEYPAD))
+       if ((!pin || !pin[0]) && wps_method == WPS_PIN_KEYPAD)
                goto inv_args;
 
        if (wpa_s->p2p_dev)
@@ -539,6 +541,7 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
        if (new_pin >= 0) {
                char npin[9];
                char *generated_pin;
+
                os_snprintf(npin, sizeof(npin), "%08d", new_pin);
                generated_pin = npin;
                reply = dbus_message_new_method_return(message);
@@ -547,8 +550,8 @@ DBusMessage * wpas_dbus_handler_p2p_connect(DBusMessage *message,
        } else {
                switch (new_pin) {
                case -2:
-                       err_msg = "connect failed due to channel "
-                               "unavailability.";
+                       err_msg =
+                               "connect failed due to channel unavailability.";
                        iface = WPAS_DBUS_ERROR_CONNECT_CHANNEL_UNAVAILABLE;
                        break;
 
@@ -594,7 +597,6 @@ DBusMessage * wpas_dbus_handler_p2p_invite(DBusMessage *message,
        char *peer_object_path = NULL;
        char *pg_object_path = NULL;
        char *iface = NULL;
-       char *net_id_str = NULL;
        u8 peer_addr[ETH_ALEN];
        unsigned int group_id = 0;
        int persistent = 0;
@@ -612,12 +614,13 @@ DBusMessage * wpas_dbus_handler_p2p_invite(DBusMessage *message,
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto err;
 
-               if (!os_strcmp(entry.key, "peer") &&
-                   (entry.type == DBUS_TYPE_OBJECT_PATH)) {
+               if (os_strcmp(entry.key, "peer") == 0 &&
+                   entry.type == DBUS_TYPE_OBJECT_PATH) {
                        peer_object_path = os_strdup(entry.str_value);
                        wpa_dbus_dict_entry_clear(&entry);
-               } else if (!os_strcmp(entry.key, "persistent_group_object") &&
-                          (entry.type == DBUS_TYPE_OBJECT_PATH)) {
+               } else if (os_strcmp(entry.key, "persistent_group_object") ==
+                          0 &&
+                          entry.type == DBUS_TYPE_OBJECT_PATH) {
                        pg_object_path = os_strdup(entry.str_value);
                        persistent = 1;
                        wpa_dbus_dict_entry_clear(&entry);
@@ -627,24 +630,25 @@ DBusMessage * wpas_dbus_handler_p2p_invite(DBusMessage *message,
                }
        }
 
-       if (!peer_object_path ||
-           (parse_peer_object_path(peer_object_path, peer_addr) < 0) ||
-           !p2p_peer_known(wpa_s->global->p2p, peer_addr)) {
+       if (parse_peer_object_path(peer_object_path, peer_addr) < 0 ||
+           !p2p_peer_known(wpa_s->global->p2p, peer_addr))
                goto err;
-       }
 
        if (wpa_s->p2p_dev)
                wpa_s = wpa_s->p2p_dev;
 
        if (persistent) {
+               char *net_id_str;
                /*
                 * A group ID is defined meaning we want to re-invoke a
                 * persistent group
                 */
 
-               iface = wpas_dbus_new_decompose_object_path(pg_object_path, 1,
-                                                           &net_id_str, NULL);
-               if (iface == NULL ||
+               iface = wpas_dbus_new_decompose_object_path(
+                       pg_object_path,
+                       WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART,
+                       &net_id_str);
+               if (iface == NULL || net_id_str == NULL ||
                    os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
                        reply = wpas_dbus_error_invalid_args(message,
                                                             pg_object_path);
@@ -683,6 +687,7 @@ DBusMessage * wpas_dbus_handler_p2p_invite(DBusMessage *message,
        }
 
 out:
+       os_free(iface);
        os_free(pg_object_path);
        os_free(peer_object_path);
        return reply;
@@ -769,8 +774,8 @@ dbus_bool_t wpas_dbus_getter_p2p_device_config(DBusMessageIter *iter,
 
        /* Primary device type */
        if (!wpa_dbus_dict_append_byte_array(&dict_iter, "PrimaryDeviceType",
-                                            (char *)wpa_s->conf->device_type,
-                                            WPS_DEV_TYPE_LEN))
+                                            (char *) wpa_s->conf->device_type,
+                                            WPS_DEV_TYPE_LEN))
                goto err_no_mem;
 
        /* Secondary device types */
@@ -805,75 +810,37 @@ dbus_bool_t wpas_dbus_getter_p2p_device_config(DBusMessageIter *iter,
                        wpa_s->conf->wps_vendor_ext[i];
        }
 
-       if (num_vendor_extensions &&
-           !wpa_dbus_dict_append_wpabuf_array(&dict_iter,
-                                              "VendorExtension",
-                                              vendor_ext,
-                                              num_vendor_extensions))
-               goto err_no_mem;
-
-       /* GO Intent */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "GOIntent",
-                                        wpa_s->conf->p2p_go_intent))
-               goto err_no_mem;
-
-       /* Persistent Reconnect */
-       if (!wpa_dbus_dict_append_bool(&dict_iter, "PersistentReconnect",
-                                      wpa_s->conf->persistent_reconnect))
-               goto err_no_mem;
-
-       /* Listen Reg Class */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "ListenRegClass",
-                                        wpa_s->conf->p2p_listen_reg_class))
-               goto err_no_mem;
-
-       /* Listen Channel */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "ListenChannel",
-                                        wpa_s->conf->p2p_listen_channel))
-               goto err_no_mem;
-
-       /* Oper Reg Class */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "OperRegClass",
-                                        wpa_s->conf->p2p_oper_reg_class))
-               goto err_no_mem;
-
-       /* Oper Channel */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "OperChannel",
-                                        wpa_s->conf->p2p_oper_channel))
-               goto err_no_mem;
-
-       /* SSID Postfix */
-       if (wpa_s->conf->p2p_ssid_postfix &&
-           !wpa_dbus_dict_append_string(&dict_iter, "SsidPostfix",
-                                        wpa_s->conf->p2p_ssid_postfix))
-               goto err_no_mem;
-
-       /* Intra Bss */
-       if (!wpa_dbus_dict_append_bool(&dict_iter, "IntraBss",
-                                      wpa_s->conf->p2p_intra_bss))
-               goto err_no_mem;
-
-       /* Group Idle */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "GroupIdle",
-                                        wpa_s->conf->p2p_group_idle))
-               goto err_no_mem;
-
-       /* Dissasociation low ack */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "disassoc_low_ack",
-                                        wpa_s->conf->disassoc_low_ack))
-               goto err_no_mem;
-
-       /* No Group Iface */
-       if (!wpa_dbus_dict_append_bool(&dict_iter, "NoGroupIface",
-                                      wpa_s->conf->p2p_no_group_iface))
-               goto err_no_mem;
-
-       /* P2P Search Delay */
-       if (!wpa_dbus_dict_append_uint32(&dict_iter, "p2p_search_delay",
-                                        wpa_s->conf->p2p_search_delay))
-               goto err_no_mem;
-
-       if (!wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
+       if ((num_vendor_extensions &&
+            !wpa_dbus_dict_append_wpabuf_array(&dict_iter,
+                                               "VendorExtension",
+                                               vendor_ext,
+                                               num_vendor_extensions)) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "GOIntent",
+                                        wpa_s->conf->p2p_go_intent) ||
+           !wpa_dbus_dict_append_bool(&dict_iter, "PersistentReconnect",
+                                      wpa_s->conf->persistent_reconnect) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "ListenRegClass",
+                                        wpa_s->conf->p2p_listen_reg_class) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "ListenChannel",
+                                        wpa_s->conf->p2p_listen_channel) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "OperRegClass",
+                                        wpa_s->conf->p2p_oper_reg_class) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "OperChannel",
+                                        wpa_s->conf->p2p_oper_channel) ||
+           (wpa_s->conf->p2p_ssid_postfix &&
+            !wpa_dbus_dict_append_string(&dict_iter, "SsidPostfix",
+                                         wpa_s->conf->p2p_ssid_postfix)) ||
+           !wpa_dbus_dict_append_bool(&dict_iter, "IntraBss",
+                                      wpa_s->conf->p2p_intra_bss) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "GroupIdle",
+                                        wpa_s->conf->p2p_group_idle) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "disassoc_low_ack",
+                                        wpa_s->conf->disassoc_low_ack) ||
+           !wpa_dbus_dict_append_bool(&dict_iter, "NoGroupIface",
+                                      wpa_s->conf->p2p_no_group_iface) ||
+           !wpa_dbus_dict_append_uint32(&dict_iter, "p2p_search_delay",
+                                        wpa_s->conf->p2p_search_delay) ||
+           !wpa_dbus_dict_close_write(&variant_iter, &dict_iter) ||
            !dbus_message_iter_close_container(iter, &variant_iter))
                goto err_no_mem;
 
@@ -955,8 +922,8 @@ dbus_bool_t wpas_dbus_setter_p2p_device_config(DBusMessageIter *iter,
                        wpa_s->conf->changed_parameters |=
                                        CFG_CHANGED_SEC_DEVICE_TYPE;
                } else if (os_strcmp(entry.key, "VendorExtension") == 0) {
-                       if ((entry.type != DBUS_TYPE_ARRAY) ||
-                           (entry.array_type != WPAS_DBUS_TYPE_BINARRAY) ||
+                       if (entry.type != DBUS_TYPE_ARRAY ||
+                           entry.array_type != WPAS_DBUS_TYPE_BINARRAY ||
                            (entry.array_len > P2P_MAX_WPS_VENDOR_EXT))
                                goto error;
 
@@ -972,30 +939,30 @@ dbus_bool_t wpas_dbus_setter_p2p_device_config(DBusMessageIter *iter,
                                } else
                                        wpa_s->conf->wps_vendor_ext[i] = NULL;
                        }
-               } else if ((os_strcmp(entry.key, "GOIntent") == 0) &&
-                          (entry.type == DBUS_TYPE_UINT32) &&
+               } else if (os_strcmp(entry.key, "GOIntent") == 0 &&
+                          entry.type == DBUS_TYPE_UINT32 &&
                           (entry.uint32_value <= 15))
                        wpa_s->conf->p2p_go_intent = entry.uint32_value;
-               else if ((os_strcmp(entry.key, "PersistentReconnect") == 0) &&
-                        (entry.type == DBUS_TYPE_BOOLEAN))
+               else if (os_strcmp(entry.key, "PersistentReconnect") == 0 &&
+                        entry.type == DBUS_TYPE_BOOLEAN)
                        wpa_s->conf->persistent_reconnect = entry.bool_value;
-               else if ((os_strcmp(entry.key, "ListenRegClass") == 0) &&
-                        (entry.type == DBUS_TYPE_UINT32)) {
+               else if (os_strcmp(entry.key, "ListenRegClass") == 0 &&
+                        entry.type == DBUS_TYPE_UINT32) {
                        wpa_s->conf->p2p_listen_reg_class = entry.uint32_value;
                        wpa_s->conf->changed_parameters |=
                                CFG_CHANGED_P2P_LISTEN_CHANNEL;
-               } else if ((os_strcmp(entry.key, "ListenChannel") == 0) &&
-                          (entry.type == DBUS_TYPE_UINT32)) {
+               } else if (os_strcmp(entry.key, "ListenChannel") == 0 &&
+                          entry.type == DBUS_TYPE_UINT32) {
                        wpa_s->conf->p2p_listen_channel = entry.uint32_value;
                        wpa_s->conf->changed_parameters |=
                                CFG_CHANGED_P2P_LISTEN_CHANNEL;
-               } else if ((os_strcmp(entry.key, "OperRegClass") == 0) &&
-                          (entry.type == DBUS_TYPE_UINT32)) {
+               } else if (os_strcmp(entry.key, "OperRegClass") == 0 &&
+                          entry.type == DBUS_TYPE_UINT32) {
                        wpa_s->conf->p2p_oper_reg_class = entry.uint32_value;
                        wpa_s->conf->changed_parameters |=
                                CFG_CHANGED_P2P_OPER_CHANNEL;
-               } else if ((os_strcmp(entry.key, "OperChannel") == 0) &&
-                          (entry.type == DBUS_TYPE_UINT32)) {
+               } else if (os_strcmp(entry.key, "OperChannel") == 0 &&
+                          entry.type == DBUS_TYPE_UINT32) {
                        wpa_s->conf->p2p_oper_channel = entry.uint32_value;
                        wpa_s->conf->changed_parameters |=
                                CFG_CHANGED_P2P_OPER_CHANNEL;
@@ -1014,13 +981,13 @@ dbus_bool_t wpas_dbus_setter_p2p_device_config(DBusMessageIter *iter,
 
                        wpa_s->conf->changed_parameters |=
                                        CFG_CHANGED_P2P_SSID_POSTFIX;
-               } else if ((os_strcmp(entry.key, "IntraBss") == 0) &&
-                          (entry.type == DBUS_TYPE_BOOLEAN)) {
+               } else if (os_strcmp(entry.key, "IntraBss") == 0 &&
+                          entry.type == DBUS_TYPE_BOOLEAN) {
                        wpa_s->conf->p2p_intra_bss = entry.bool_value;
                        wpa_s->conf->changed_parameters |=
                                CFG_CHANGED_P2P_INTRA_BSS;
-               } else if ((os_strcmp(entry.key, "GroupIdle") == 0) &&
-                          (entry.type == DBUS_TYPE_UINT32))
+               } else if (os_strcmp(entry.key, "GroupIdle") == 0 &&
+                          entry.type == DBUS_TYPE_UINT32)
                        wpa_s->conf->p2p_group_idle = entry.uint32_value;
                else if (os_strcmp(entry.key, "disassoc_low_ack") == 0 &&
                         entry.type == DBUS_TYPE_UINT32)
@@ -1300,8 +1267,8 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_primary_device_type(
 
 
 dbus_bool_t wpas_dbus_getter_p2p_peer_config_method(DBusMessageIter *iter,
-                                                    DBusError *error,
-                                                    void *user_data)
+                                                   DBusError *error,
+                                                   void *user_data)
 {
        struct peer_handler_args *peer_args = user_data;
        const struct p2p_peer_info *info;
@@ -1325,8 +1292,8 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_config_method(DBusMessageIter *iter,
 
 
 dbus_bool_t wpas_dbus_getter_p2p_peer_level(DBusMessageIter *iter,
-                                            DBusError *error,
-                                            void *user_data)
+                                           DBusError *error,
+                                           void *user_data)
 {
        struct peer_handler_args *peer_args = user_data;
        const struct p2p_peer_info *info;
@@ -1350,8 +1317,8 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_level(DBusMessageIter *iter,
 
 
 dbus_bool_t wpas_dbus_getter_p2p_peer_device_capability(DBusMessageIter *iter,
-                                                        DBusError *error,
-                                                        void *user_data)
+                                                       DBusError *error,
+                                                       void *user_data)
 {
        struct peer_handler_args *peer_args = user_data;
        const struct p2p_peer_info *info;
@@ -1409,8 +1376,7 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
        info = p2p_get_peer_found(peer_args->wpa_s->global->p2p,
                                  peer_args->p2p_device_addr, 0);
        if (info == NULL) {
-               dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "failed to find peer");
+               dbus_set_error(error, DBUS_ERROR_FAILED, "failed to find peer");
                return FALSE;
        }
 
@@ -1418,18 +1384,13 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
                                              DBUS_TYPE_ARRAY_AS_STRING
                                              DBUS_TYPE_ARRAY_AS_STRING
                                              DBUS_TYPE_BYTE_AS_STRING,
-                                             &variant_iter)) {
-               dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "%s: failed to construct message 1", __func__);
-               return FALSE;
-       }
-
-       if (!dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
+                                             &variant_iter) ||
+           !dbus_message_iter_open_container(&variant_iter, DBUS_TYPE_ARRAY,
                                              DBUS_TYPE_ARRAY_AS_STRING
                                              DBUS_TYPE_BYTE_AS_STRING,
                                              &array_iter)) {
                dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "%s: failed to construct message 2", __func__);
+                              "%s: failed to construct message 1", __func__);
                return FALSE;
        }
 
@@ -1444,29 +1405,14 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
                        if (!dbus_message_iter_open_container(
                                    &array_iter, DBUS_TYPE_ARRAY,
                                    DBUS_TYPE_BYTE_AS_STRING,
-                                   &inner_array_iter)) {
-                               dbus_set_error(error, DBUS_ERROR_FAILED,
-                                              "%s: failed to construct "
-                                              "message 3 (%d)",
-                                              __func__, i);
-                               return FALSE;
-                       }
-
-                       if (!dbus_message_iter_append_fixed_array(
+                                   &inner_array_iter) ||
+                           !dbus_message_iter_append_fixed_array(
                                    &inner_array_iter, DBUS_TYPE_BYTE,
-                                   &sec_dev_type_list, WPS_DEV_TYPE_LEN)) {
-                               dbus_set_error(error, DBUS_ERROR_FAILED,
-                                              "%s: failed to construct "
-                                              "message 4 (%d)",
-                                              __func__, i);
-                               return FALSE;
-                       }
-
-                       if (!dbus_message_iter_close_container(
+                                   &sec_dev_type_list, WPS_DEV_TYPE_LEN) ||
+                           !dbus_message_iter_close_container(
                                    &array_iter, &inner_array_iter)) {
                                dbus_set_error(error, DBUS_ERROR_FAILED,
-                                              "%s: failed to construct "
-                                              "message 5 (%d)",
+                                              "%s: failed to construct message 2 (%d)",
                                               __func__, i);
                                return FALSE;
                        }
@@ -1475,15 +1421,10 @@ dbus_bool_t wpas_dbus_getter_p2p_peer_secondary_device_types(
                }
        }
 
-       if (!dbus_message_iter_close_container(&variant_iter, &array_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 6", __func__);
-               return FALSE;
-       }
-
-       if (!dbus_message_iter_close_container(iter, &variant_iter)) {
-               dbus_set_error(error, DBUS_ERROR_FAILED,
-                              "%s: failed to construct message 7", __func__);
+                              "%s: failed to construct message 3", __func__);
                return FALSE;
        }
 
@@ -1695,15 +1636,6 @@ dbus_bool_t wpas_dbus_getter_persistent_groups(DBusMessageIter *iter,
        unsigned int i = 0, num = 0;
        dbus_bool_t success = FALSE;
 
-       if (wpa_s->conf == NULL) {
-               wpa_printf(MSG_ERROR, "dbus: %s: "
-                          "An error occurred getting persistent groups list",
-                          __func__);
-               dbus_set_error_const(error, DBUS_ERROR_FAILED, "an error "
-                                    "occurred getting persistent groups list");
-               return FALSE;
-       }
-
        for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next)
                if (network_is_persistent_group(ssid))
                        num++;
@@ -1816,12 +1748,12 @@ DBusMessage * wpas_dbus_handler_add_persistent_group(
 
        ssid = wpa_config_add_network(wpa_s->conf);
        if (ssid == NULL) {
-               wpa_printf(MSG_ERROR, "dbus: %s: "
-                          "Cannot add new persistent group", __func__);
+               wpa_printf(MSG_ERROR,
+                          "dbus: %s: Cannot add new persistent group",
+                          __func__);
                reply = wpas_dbus_error_unknown_error(
                        message,
-                       "wpa_supplicant could not add "
-                       "a persistent group on this interface.");
+                       "wpa_supplicant could not add a persistent group on this interface.");
                goto err;
        }
 
@@ -1834,13 +1766,12 @@ DBusMessage * wpas_dbus_handler_add_persistent_group(
 
        dbus_error_init(&error);
        if (!set_network_properties(wpa_s, ssid, &iter, &error)) {
-               wpa_printf(MSG_DEBUG, "dbus: %s: "
-                          "Control interface could not set persistent group "
-                          "properties", __func__);
-               reply = wpas_dbus_reply_new_from_error(message, &error,
-                                                      DBUS_ERROR_INVALID_ARGS,
-                                                      "Failed to set network "
-                                                      "properties");
+               wpa_printf(MSG_DEBUG,
+                          "dbus: %s: Control interface could not set persistent group properties",
+                          __func__);
+               reply = wpas_dbus_reply_new_from_error(
+                       message, &error, DBUS_ERROR_INVALID_ARGS,
+                       "Failed to set network properties");
                dbus_error_free(&error);
                goto err;
        }
@@ -1852,15 +1783,13 @@ DBusMessage * wpas_dbus_handler_add_persistent_group(
 
        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;
        }
 
@@ -1890,7 +1819,7 @@ DBusMessage * wpas_dbus_handler_remove_persistent_group(
 {
        DBusMessage *reply = NULL;
        const char *op;
-       char *iface = NULL, *persistent_group_id = NULL;
+       char *iface = NULL, *persistent_group_id;
        int id;
        struct wpa_ssid *ssid;
 
@@ -1901,10 +1830,11 @@ DBusMessage * wpas_dbus_handler_remove_persistent_group(
         * Extract the network ID and ensure the network is actually a child of
         * this interface.
         */
-       iface = wpas_dbus_new_decompose_object_path(op, 1,
-                                                   &persistent_group_id,
-                                                   NULL);
-       if (iface == NULL || os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
+       iface = wpas_dbus_new_decompose_object_path(
+               op, WPAS_DBUS_NEW_PERSISTENT_GROUPS_PART,
+               &persistent_group_id);
+       if (iface == NULL || persistent_group_id == NULL ||
+           os_strcmp(iface, wpa_s->dbus_new_path) != 0) {
                reply = wpas_dbus_error_invalid_args(message, op);
                goto out;
        }
@@ -1924,19 +1854,17 @@ DBusMessage * wpas_dbus_handler_remove_persistent_group(
        wpas_notify_persistent_group_removed(wpa_s, ssid);
 
        if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
-               wpa_printf(MSG_ERROR, "dbus: %s: "
-                          "error occurred when removing persistent group %d",
+               wpa_printf(MSG_ERROR,
+                          "dbus: %s: error occurred when removing persistent group %d",
                           __func__, id);
                reply = wpas_dbus_error_unknown_error(
                        message,
-                       "error removing the specified persistent group on "
-                       "this interface.");
+                       "error removing the specified persistent group on this interface.");
                goto out;
        }
 
 out:
        os_free(iface);
-       os_free(persistent_group_id);
        return reply;
 }
 
@@ -1947,8 +1875,8 @@ static void remove_persistent_group(struct wpa_supplicant *wpa_s,
        wpas_notify_persistent_group_removed(wpa_s, ssid);
 
        if (wpa_config_remove_network(wpa_s->conf, ssid->id) < 0) {
-               wpa_printf(MSG_ERROR, "dbus: %s: "
-                          "error occurred when removing persistent group %d",
+               wpa_printf(MSG_ERROR,
+                          "dbus: %s: error occurred when removing persistent group %d",
                           __func__, ssid->id);
                return;
        }
@@ -2056,6 +1984,7 @@ dbus_bool_t wpas_dbus_getter_p2p_group_ssid(DBusMessageIter *iter,
                                            DBusError *error, void *user_data)
 {
        struct wpa_supplicant *wpa_s = user_data;
+
        if (wpa_s->current_ssid == NULL)
                return FALSE;
        return wpas_dbus_simple_array_property_getter(
@@ -2116,15 +2045,14 @@ dbus_bool_t wpas_dbus_getter_p2p_group_passphrase(DBusMessageIter *iter,
                                                  void *user_data)
 {
        struct wpa_supplicant *wpa_s = user_data;
-       u8 role = wpas_get_p2p_role(wpa_s);
-       char *p_pass = NULL;
+       char *p_pass;
+       struct wpa_ssid *ssid = wpa_s->current_ssid;
 
-       /* Verify correct role for this property */
-       if (role == WPAS_P2P_ROLE_GO) {
-               if (wpa_s->current_ssid == NULL)
-                       return FALSE;
-               p_pass = wpa_s->current_ssid->passphrase;
-       } else
+       if (ssid == NULL)
+               return FALSE;
+
+       p_pass = ssid->passphrase;
+       if (!p_pass)
                p_pass = "";
 
        return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_STRING,
@@ -2137,20 +2065,20 @@ dbus_bool_t wpas_dbus_getter_p2p_group_psk(DBusMessageIter *iter,
                                           DBusError *error, void *user_data)
 {
        struct wpa_supplicant *wpa_s = user_data;
-       u8 role = wpas_get_p2p_role(wpa_s);
        u8 *p_psk = NULL;
        u8 psk_len = 0;
+       struct wpa_ssid *ssid = wpa_s->current_ssid;
 
-       /* Verify correct role for this property */
-       if (role == WPAS_P2P_ROLE_CLIENT) {
-               if (wpa_s->current_ssid == NULL)
-                       return FALSE;
-               p_psk = wpa_s->current_ssid->psk;
-               psk_len = 32;
+       if (ssid == NULL)
+               return FALSE;
+
+       if (ssid->psk_set) {
+               p_psk = ssid->psk;
+               psk_len = sizeof(ssid->psk);
        }
 
        return wpas_dbus_simple_array_property_getter(iter, DBUS_TYPE_BYTE,
-                                                     &p_psk, psk_len, error);
+                                                     p_psk, psk_len, error);
 }
 
 
@@ -2348,31 +2276,31 @@ DBusMessage * wpas_dbus_handler_p2p_add_service(DBusMessage *message,
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto error;
 
-               if (!os_strcmp(entry.key, "service_type") &&
-                   (entry.type == DBUS_TYPE_STRING)) {
-                       if (!os_strcmp(entry.str_value, "upnp"))
+               if (os_strcmp(entry.key, "service_type") == 0 &&
+                   entry.type == DBUS_TYPE_STRING) {
+                       if (os_strcmp(entry.str_value, "upnp") == 0)
                                upnp = 1;
-                       else if (!os_strcmp(entry.str_value, "bonjour"))
+                       else if (os_strcmp(entry.str_value, "bonjour") == 0)
                                bonjour = 1;
                        else
                                goto error_clear;
-               } else if (!os_strcmp(entry.key, "version") &&
-                          entry.type == DBUS_TYPE_INT32) {
+               } else if (os_strcmp(entry.key, "version") == 0 &&
+                          entry.type == DBUS_TYPE_INT32) {
                        version = entry.uint32_value;
-               } else if (!os_strcmp(entry.key, "service") &&
-                            (entry.type == DBUS_TYPE_STRING)) {
+               } else if (os_strcmp(entry.key, "service") == 0 &&
+                          entry.type == DBUS_TYPE_STRING) {
                        os_free(service);
                        service = os_strdup(entry.str_value);
-               } else if (!os_strcmp(entry.key, "query")) {
-                       if ((entry.type != DBUS_TYPE_ARRAY) ||
-                           (entry.array_type != DBUS_TYPE_BYTE))
+               } else if (os_strcmp(entry.key, "query") == 0) {
+                       if (entry.type != DBUS_TYPE_ARRAY ||
+                           entry.array_type != DBUS_TYPE_BYTE)
                                goto error_clear;
                        query = wpabuf_alloc_copy(
                                entry.bytearray_value,
                                entry.array_len);
-               } else if (!os_strcmp(entry.key, "response")) {
-                       if ((entry.type != DBUS_TYPE_ARRAY) ||
-                           (entry.array_type != DBUS_TYPE_BYTE))
+               } else if (os_strcmp(entry.key, "response") == 0) {
+                       if (entry.type != DBUS_TYPE_ARRAY ||
+                           entry.array_type != DBUS_TYPE_BYTE)
                                goto error_clear;
                        resp = wpabuf_alloc_copy(entry.bytearray_value,
                                                 entry.array_len);
@@ -2433,11 +2361,11 @@ DBusMessage * wpas_dbus_handler_p2p_delete_service(
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto error;
 
-               if (!os_strcmp(entry.key, "service_type") &&
-                   (entry.type == DBUS_TYPE_STRING)) {
-                       if (!os_strcmp(entry.str_value, "upnp"))
+               if (os_strcmp(entry.key, "service_type") == 0 &&
+                   entry.type == DBUS_TYPE_STRING) {
+                       if (os_strcmp(entry.str_value, "upnp") == 0)
                                upnp = 1;
-                       else if (!os_strcmp(entry.str_value, "bonjour"))
+                       else if (os_strcmp(entry.str_value, "bonjour") == 0)
                                bonjour = 1;
                        else
                                goto error_clear;
@@ -2448,10 +2376,10 @@ DBusMessage * wpas_dbus_handler_p2p_delete_service(
                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, "version") &&
+                       if (os_strcmp(entry.key, "version") == 0 &&
                            entry.type == DBUS_TYPE_INT32)
                                version = entry.uint32_value;
-                       else if (!os_strcmp(entry.key, "service") &&
+                       else if (os_strcmp(entry.key, "service") == 0 &&
                                 entry.type == DBUS_TYPE_STRING) {
                                os_free(service);
                                service = os_strdup(entry.str_value);
@@ -2472,9 +2400,9 @@ DBusMessage * wpas_dbus_handler_p2p_delete_service(
                        if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                                goto error;
 
-                       if (!os_strcmp(entry.key, "query")) {
-                               if ((entry.type != DBUS_TYPE_ARRAY) ||
-                                   (entry.array_type != DBUS_TYPE_BYTE))
+                       if (os_strcmp(entry.key, "query") == 0) {
+                               if (entry.type != DBUS_TYPE_ARRAY ||
+                                   entry.array_type != DBUS_TYPE_BYTE)
                                        goto error_clear;
                                wpabuf_free(query);
                                query = wpabuf_alloc_copy(
@@ -2538,22 +2466,22 @@ DBusMessage * wpas_dbus_handler_p2p_service_sd_req(
        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, "peer_object") &&
+               if (os_strcmp(entry.key, "peer_object") == 0 &&
                    entry.type == DBUS_TYPE_OBJECT_PATH) {
                        peer_object_path = os_strdup(entry.str_value);
-               } else if (!os_strcmp(entry.key, "service_type") &&
+               } else if (os_strcmp(entry.key, "service_type") == 0 &&
                           entry.type == DBUS_TYPE_STRING) {
-                       if (!os_strcmp(entry.str_value, "upnp"))
+                       if (os_strcmp(entry.str_value, "upnp") == 0)
                                upnp = 1;
                        else
                                goto error_clear;
-               } else if (!os_strcmp(entry.key, "version") &&
+               } else if (os_strcmp(entry.key, "version") == 0 &&
                           entry.type == DBUS_TYPE_INT32) {
                        version = entry.uint32_value;
-               } else if (!os_strcmp(entry.key, "service") &&
+               } else if (os_strcmp(entry.key, "service") == 0 &&
                           entry.type == DBUS_TYPE_STRING) {
                        service = os_strdup(entry.str_value);
-               } else if (!os_strcmp(entry.key, "tlv")) {
+               } else if (os_strcmp(entry.key, "tlv") == 0) {
                        if (entry.type != DBUS_TYPE_ARRAY ||
                            entry.array_type != DBUS_TYPE_BYTE)
                                goto error_clear;
@@ -2631,16 +2559,17 @@ DBusMessage * wpas_dbus_handler_p2p_service_sd_res(
                if (!wpa_dbus_dict_get_entry(&iter_dict, &entry))
                        goto error;
 
-               if (!os_strcmp(entry.key, "peer_object") &&
+               if (os_strcmp(entry.key, "peer_object") == 0 &&
                    entry.type == DBUS_TYPE_OBJECT_PATH) {
                        peer_object_path = os_strdup(entry.str_value);
-               } else if (!os_strcmp(entry.key, "frequency") &&
+               } else if (os_strcmp(entry.key, "frequency") == 0 &&
                           entry.type == DBUS_TYPE_INT32) {
                        freq = entry.uint32_value;
-               } else if (!os_strcmp(entry.key, "dialog_token") &&
-                          entry.type == DBUS_TYPE_UINT32) {
+               } else if (os_strcmp(entry.key, "dialog_token") == 0 &&
+                          (entry.type == DBUS_TYPE_UINT32 ||
+                           entry.type == DBUS_TYPE_INT32)) {
                        dlg_tok = entry.uint32_value;
-               } else if (!os_strcmp(entry.key, "tlvs")) {
+               } else if (os_strcmp(entry.key, "tlvs") == 0) {
                        if (entry.type != DBUS_TYPE_ARRAY ||
                            entry.array_type != DBUS_TYPE_BYTE)
                                goto error_clear;
@@ -2651,12 +2580,9 @@ DBusMessage * wpas_dbus_handler_p2p_service_sd_res(
 
                wpa_dbus_dict_entry_clear(&entry);
        }
-       if (!peer_object_path ||
-           (parse_peer_object_path(peer_object_path, addr) < 0) ||
-           !p2p_peer_known(wpa_s->global->p2p, addr))
-               goto error;
-
-       if (tlv == NULL)
+       if (parse_peer_object_path(peer_object_path, addr) < 0 ||
+           !p2p_peer_known(wpa_s->global->p2p, addr) ||
+           tlv == NULL)
                goto error;
 
        wpas_p2p_sd_response(wpa_s, freq, addr, (u8) dlg_tok, tlv);