From 0deab087cdb0f9314ef8b528b4aa8768a0b58c5f Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 15 Feb 2013 17:07:28 +0200 Subject: [PATCH] P2P NFC: Allow separate WPS/P2P IES to be parsed This will be needed for processing the NFC connection handover messages for P2P. Signed-hostap: Jouni Malinen --- src/p2p/p2p_i.h | 2 ++ src/p2p/p2p_parse.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/p2p/p2p_i.h b/src/p2p/p2p_i.h index 9e41f26a6..0fa4b70a1 100644 --- a/src/p2p/p2p_i.h +++ b/src/p2p/p2p_i.h @@ -585,6 +585,8 @@ int p2p_channel_select(struct p2p_channels *chans, const int *classes, int p2p_parse_p2p_ie(const struct wpabuf *buf, struct p2p_message *msg); int p2p_parse_ies(const u8 *data, size_t len, struct p2p_message *msg); int p2p_parse(const u8 *data, size_t len, struct p2p_message *msg); +int p2p_parse_ies_separate(const u8 *wsc, size_t wsc_len, const u8 *p2p, + size_t p2p_len, struct p2p_message *msg); void p2p_parse_free(struct p2p_message *msg); int p2p_attr_text(struct wpabuf *data, char *buf, char *end); int p2p_group_info_parse(const u8 *gi, size_t gi_len, diff --git a/src/p2p/p2p_parse.c b/src/p2p/p2p_parse.c index cdf8b40d5..bc548e8d4 100644 --- a/src/p2p/p2p_parse.c +++ b/src/p2p/p2p_parse.c @@ -466,6 +466,33 @@ int p2p_parse(const u8 *data, size_t len, struct p2p_message *msg) } +int p2p_parse_ies_separate(const u8 *wsc, size_t wsc_len, const u8 *p2p, + size_t p2p_len, struct p2p_message *msg) +{ + os_memset(msg, 0, sizeof(*msg)); + + msg->wps_attributes = wpabuf_alloc_copy(wsc, wsc_len); + if (msg->wps_attributes && + p2p_parse_wps_ie(msg->wps_attributes, msg)) { + p2p_parse_free(msg); + return -1; + } + + msg->p2p_attributes = wpabuf_alloc_copy(p2p, p2p_len); + if (msg->p2p_attributes && + p2p_parse_p2p_ie(msg->p2p_attributes, msg)) { + wpa_printf(MSG_DEBUG, "P2P: Failed to parse P2P IE data"); + if (msg->p2p_attributes) + wpa_hexdump_buf(MSG_MSGDUMP, "P2P: P2P IE data", + msg->p2p_attributes); + p2p_parse_free(msg); + return -1; + } + + return 0; +} + + /** * p2p_parse_free - Free temporary data from P2P parsing * @msg: Parsed attributes