From: Vinay Gannevaram Date: Thu, 3 Nov 2022 07:29:16 +0000 (+0530) Subject: PASN: Allow extra elements to be added into PASN Authentication frames X-Git-Tag: hostap_2_11~1587 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1ed44b6a699e416f5991752c31af855e08e6e8a;p=thirdparty%2Fhostap.git PASN: Allow extra elements to be added into PASN Authentication frames Wi-Fi Aware defines protocol specific elements in PASN Authentication frames for pairing setup. Add an option to add this type of custom elements into PASN frames. This is mainly for the libpasn.so use cases. Signed-off-by: Jouni Malinen --- diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c index 38bca41a0..bedc14233 100644 --- a/src/common/wpa_common.c +++ b/src/common/wpa_common.c @@ -4102,4 +4102,27 @@ void wpa_pasn_add_rsnxe(struct wpabuf *buf, u16 capab) wpabuf_put_u8(buf, capab); } + +/* + * wpa_pasn_add_extra_ies - Add protocol specific IEs in Authentication + * frame for PASN. + * + * @buf: Buffer in which the elements will be added + * @extra_ies: Protocol specific elements to add + * @len: Length of the elements + * Returns: 0 on success, -1 on failure + */ + +int wpa_pasn_add_extra_ies(struct wpabuf *buf, const u8 *extra_ies, size_t len) +{ + if (!len || !extra_ies || !buf) + return 0; + + if (wpabuf_tailroom(buf) < sizeof(len)) + return -1; + + wpabuf_put_data(buf, extra_ies, len); + return 0; +} + #endif /* CONFIG_PASN */ diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h index 7374d8b7b..2c6fe05ac 100644 --- a/src/common/wpa_common.h +++ b/src/common/wpa_common.h @@ -749,5 +749,6 @@ int wpa_pasn_parse_parameter_ie(const u8 *data, u8 len, bool from_ap, struct wpa_pasn_params_data *pasn_params); void wpa_pasn_add_rsnxe(struct wpabuf *buf, u16 capab); +int wpa_pasn_add_extra_ies(struct wpabuf *buf, const u8 *extra_ies, size_t len); #endif /* WPA_COMMON_H */ diff --git a/src/pasn/pasn_common.h b/src/pasn/pasn_common.h index d34bde302..e091b8eb4 100644 --- a/src/pasn/pasn_common.h +++ b/src/pasn/pasn_common.h @@ -115,6 +115,13 @@ struct wpas_pasn { bool custom_pmkid_valid; u8 custom_pmkid[PMKID_LEN]; + /** + * Extra elements to add into Authentication frames. These can be used, + * e.g., for Wi-Fi Aware use cases. + */ + const u8 *extra_ies; + size_t extra_ies_len; + /** * send_mgmt - Function handler to transmit a Management frame * @ctx: Callback context from cb_ctx diff --git a/src/pasn/pasn_initiator.c b/src/pasn/pasn_initiator.c index f123afb1b..4afe7859a 100644 --- a/src/pasn/pasn_initiator.c +++ b/src/pasn/pasn_initiator.c @@ -579,6 +579,8 @@ static struct wpabuf * wpas_pasn_build_auth_1(struct wpas_pasn *pasn, wpa_pasn_add_rsnxe(buf, pasn->rsnxe_capab); + wpa_pasn_add_extra_ies(buf, pasn->extra_ies, pasn->extra_ies_len); + ret = pasn_auth_frame_hash(pasn->akmp, pasn->cipher, wpabuf_head_u8(buf) + IEEE80211_HDRLEN, wpabuf_len(buf) - IEEE80211_HDRLEN, diff --git a/src/pasn/pasn_responder.c b/src/pasn/pasn_responder.c index 30fc51204..02a1088bf 100644 --- a/src/pasn/pasn_responder.c +++ b/src/pasn/pasn_responder.c @@ -491,6 +491,8 @@ int handle_auth_pasn_resp(struct wpas_pasn *pasn, const u8 *own_addr, if (rsnxe_ie) wpabuf_put_data(buf, rsnxe_ie, 2 + rsnxe_ie[1]); + wpa_pasn_add_extra_ies(buf, pasn->extra_ies, pasn->extra_ies_len); + /* Add the mic */ mic_len = pasn_mic_len(pasn->akmp, pasn->cipher); wpabuf_put_u8(buf, WLAN_EID_MIC);