]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - wpa_supplicant/ap.c
P2P: Add support for IP address assignment in 4-way handshake
[thirdparty/hostap.git] / wpa_supplicant / ap.c
index 412db23bcb09252848f8c35f8c87d46d1f600fea..ce3efcbad815a5555c90954aeae0191dd1d924ef 100644 (file)
@@ -15,6 +15,7 @@
 #include "common/ieee802_11_defs.h"
 #include "common/wpa_ctrl.h"
 #include "eapol_supp/eapol_supp_sm.h"
+#include "crypto/dh_group5.h"
 #include "ap/hostapd.h"
 #include "ap/ap_config.h"
 #include "ap/ap_drv_ops.h"
@@ -181,6 +182,16 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
 
        bss->isolate = !wpa_s->conf->p2p_intra_bss;
        bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
+
+       if (ssid->p2p_group) {
+               os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
+               os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
+                         4);
+               os_memcpy(bss->ip_addr_start,
+                         wpa_s->parent->conf->ip_addr_start, 4);
+               os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
+                         4);
+       }
 #endif /* CONFIG_P2P */
 
        if (ssid->ssid_len == 0) {
@@ -360,6 +371,8 @@ static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
        hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
        if (hdr_len > len)
                return;
+       if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
+               return;
        wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
                           mgmt->u.action.category,
                           &mgmt->u.action.u.vs_public_action.action,
@@ -680,6 +693,8 @@ void ap_eapol_tx_status(void *ctx, const u8 *dst,
 {
 #ifdef NEED_AP_MLME
        struct wpa_supplicant *wpa_s = ctx;
+       if (!wpa_s->ap_iface)
+               return;
        hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
 #endif /* NEED_AP_MLME */
 }
@@ -942,6 +957,19 @@ struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
        return hostapd_wps_nfc_hs_cr(hapd, ndef);
 }
 
+
+int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
+                                   const struct wpabuf *req,
+                                   const struct wpabuf *sel)
+{
+       struct hostapd_data *hapd;
+
+       if (wpa_s->ap_iface == NULL)
+               return -1;
+       hapd = wpa_s->ap_iface->bss[0];
+       return hostapd_wps_nfc_report_handover(hapd, req, sel);
+}
+
 #endif /* CONFIG_WPS_NFC */
 
 #endif /* CONFIG_WPS */
@@ -1135,3 +1163,48 @@ int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
 
        return 0;
 }
+
+
+#ifdef CONFIG_WPS_NFC
+int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
+                          const struct wpabuf *pw, const u8 *pubkey_hash)
+{
+       struct hostapd_data *hapd;
+       struct wps_context *wps;
+
+       if (!wpa_s->ap_iface)
+               return -1;
+       hapd = wpa_s->ap_iface->bss[0];
+       wps = hapd->wps;
+
+       if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
+           wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
+               wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
+               return -1;
+       }
+
+       dh5_free(wps->dh_ctx);
+       wpabuf_free(wps->dh_pubkey);
+       wpabuf_free(wps->dh_privkey);
+       wps->dh_privkey = wpabuf_dup(
+               wpa_s->parent->conf->wps_nfc_dh_privkey);
+       wps->dh_pubkey = wpabuf_dup(
+               wpa_s->parent->conf->wps_nfc_dh_pubkey);
+       if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
+               wps->dh_ctx = NULL;
+               wpabuf_free(wps->dh_pubkey);
+               wps->dh_pubkey = NULL;
+               wpabuf_free(wps->dh_privkey);
+               wps->dh_privkey = NULL;
+               return -1;
+       }
+       wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
+       if (wps->dh_ctx == NULL)
+               return -1;
+
+       return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
+                                             pw_id,
+                                             pw ? wpabuf_head(pw) : NULL,
+                                             pw ? wpabuf_len(pw) : 0, 1);
+}
+#endif /* CONFIG_WPS_NFC */