P2P: Copy config from p2pdev when not using dedicated group interface
[mech_eap.git] / wpa_supplicant / p2p_supplicant.c
index 38e3418..b1f3344 100644 (file)
@@ -1951,7 +1951,12 @@ static void wpas_p2p_clone_config(struct wpa_supplicant *dst,
        d = dst->conf;
        s = src->conf;
 
-#define C(n) if (s->n) d->n = os_strdup(s->n)
+#define C(n)                            \
+do {                                    \
+       if (s->n && !d->n)              \
+               d->n = os_strdup(s->n); \
+} while (0)
+
        C(device_name);
        C(manufacturer);
        C(model_name);
@@ -1979,28 +1984,14 @@ static void wpas_p2p_clone_config(struct wpa_supplicant *dst,
        d->disable_scan_offload = s->disable_scan_offload;
        d->passive_scan = s->passive_scan;
 
-       if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey) {
-               d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey);
-               d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey);
-       }
-       d->p2p_cli_probe = s->p2p_cli_probe;
-}
-
-
-static void wpas_p2p_clone_config_dh(struct wpa_supplicant *dst,
-                                    const struct wpa_supplicant *src)
-{
-       struct wpa_config *d;
-       const struct wpa_config *s;
-
-       d = dst->conf;
-       s = src->conf;
-
        if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey &&
-           !d->wps_nfc_dh_privkey && !d->wps_nfc_dh_pubkey) {
+           !d->wps_nfc_pw_from_config) {
+               wpabuf_free(d->wps_nfc_dh_privkey);
+               wpabuf_free(d->wps_nfc_dh_pubkey);
                d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey);
                d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey);
        }
+       d->p2p_cli_probe = s->p2p_cli_probe;
 }
 
 
@@ -2255,7 +2246,7 @@ static void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
                group_wpa_s = wpa_s->parent;
                wpa_s->global->p2p_group_formation = group_wpa_s;
                if (group_wpa_s != wpa_s)
-                       wpas_p2p_clone_config_dh(group_wpa_s, wpa_s);
+                       wpas_p2p_clone_config(group_wpa_s, wpa_s);
        }
 
        group_wpa_s->p2p_in_provisioning = 1;
@@ -6013,7 +6004,7 @@ wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
                        "P2P: Use primary interface for group operations");
                wpa_s->p2p_first_connection_timeout = 0;
                if (wpa_s != wpa_s->p2pdev)
-                       wpas_p2p_clone_config_dh(wpa_s, wpa_s->p2pdev);
+                       wpas_p2p_clone_config(wpa_s, wpa_s->p2pdev);
                return wpa_s;
        }
 
@@ -8390,17 +8381,17 @@ static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s,
                return -1;
        }
 
-       if (wpa_s->parent->p2p_oob_dev_pw_id !=
+       if (wpa_s->p2pdev->p2p_oob_dev_pw_id !=
            DEV_PW_NFC_CONNECTION_HANDOVER &&
-           !wpa_s->parent->p2p_oob_dev_pw) {
+           !wpa_s->p2pdev->p2p_oob_dev_pw) {
                wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known");
                return -1;
        }
        res = wpas_ap_wps_add_nfc_pw(
-               wpa_s, wpa_s->parent->p2p_oob_dev_pw_id,
-               wpa_s->parent->p2p_oob_dev_pw,
-               wpa_s->parent->p2p_peer_oob_pk_hash_known ?
-               wpa_s->parent->p2p_peer_oob_pubkey_hash : NULL);
+               wpa_s, wpa_s->p2pdev->p2p_oob_dev_pw_id,
+               wpa_s->p2pdev->p2p_oob_dev_pw,
+               wpa_s->p2pdev->p2p_peer_oob_pk_hash_known ?
+               wpa_s->p2pdev->p2p_peer_oob_pubkey_hash : NULL);
        if (res)
                return res;
 
@@ -8418,16 +8409,16 @@ static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s,
 
        wpa_s->global->p2p_invite_group = wpa_s;
        persistent = ssid->p2p_persistent_group &&
-               wpas_p2p_get_persistent(wpa_s->parent,
+               wpas_p2p_get_persistent(wpa_s->p2pdev,
                                        params->peer->p2p_device_addr,
                                        ssid->ssid, ssid->ssid_len);
-       wpa_s->parent->pending_invite_ssid_id = -1;
+       wpa_s->p2pdev->pending_invite_ssid_id = -1;
 
        return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr,
                          P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr,
                          ssid->ssid, ssid->ssid_len, ssid->frequency,
                          wpa_s->global->p2p_dev_addr, persistent, 0,
-                         wpa_s->parent->p2p_oob_dev_pw_id);
+                         wpa_s->p2pdev->p2p_oob_dev_pw_id);
 }