diff mbox series

Add application extension data to WPS IE

Message ID 1567676080-20016-1-git-send-email-bilalhp@gmail.com
State Changes Requested
Headers show
Series Add application extension data to WPS IE | expand

Commit Message

Bilal Hatipoğlu Sept. 5, 2019, 9:34 a.m. UTC
From: Bilal Hatipoglu <bilal.hatipoglu@airties.com>

Application Extension attribute is defined in WPS Spec v2.06 page 105.
This patch makes hostapd add this application extension data to WPS IE
if configured. The implementation is very similar to vendor extension.

Signed-off-by: Veli Demirel <veli.demirel@airties.com>
Signed-off-by: Bilal Hatipoglu <bilal.hatipoglu@airties.com>
---
 src/ap/ap_config.c      |  2 ++
 src/ap/ap_config.h      |  1 +
 src/ap/wps_hostapd.c    | 29 +++++++++++++++++++++++++++++
 src/wps/wps.h           |  5 +++++
 src/wps/wps_dev_attr.c  | 19 +++++++++++++++++++
 src/wps/wps_registrar.c |  6 ++++--
 6 files changed, 60 insertions(+), 2 deletions(-)

Comments

Bilal Hatipoglu Sept. 30, 2019, 12:02 p.m. UTC | #1
Hello,

Can anyone help reviewing and merging this change?

Regards.






Bilal Hatipoglu

Principal Software Architect

AirTies Wireless Networks















From: Hostap <hostap-bounces@lists.infradead.org> on behalf of bilalhp@gmail.com <bilalhp@gmail.com>

Sent: Thursday, September 5, 2019 12:34 PM

To: hostap@lists.infradead.org <hostap@lists.infradead.org>

Subject: [PATCH] Add application extension data to WPS IE

 


From: Bilal Hatipoglu <bilal.hatipoglu@airties.com>



Application Extension attribute is defined in WPS Spec v2.06 page 105.

This patch makes hostapd add this application extension data to WPS IE

if configured. The implementation is very similar to vendor extension.



Signed-off-by: Veli Demirel <veli.demirel@airties.com>

Signed-off-by: Bilal Hatipoglu <bilal.hatipoglu@airties.com>

---

 src/ap/ap_config.c      |  2 ++

 src/ap/ap_config.h      |  1 +

 src/ap/wps_hostapd.c    | 29 +++++++++++++++++++++++++++++

 src/wps/wps.h           |  5 +++++

 src/wps/wps_dev_attr.c  | 19 +++++++++++++++++++

 src/wps/wps_registrar.c |  6 ++++--

 6 files changed, 60 insertions(+), 2 deletions(-)



diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c

index 80a73d6..6fac2cf 100644

--- a/src/ap/ap_config.c

+++ b/src/ap/ap_config.c

@@ -768,6 +768,8 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)

         os_free(conf->upc);

         for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)

                 wpabuf_free(conf->wps_vendor_ext[i]);

+       for (i = 0; i < MAX_WPS_APPLICATION_EXTENSIONS; i++)

+               wpabuf_free(conf->wps_application_ext[i]);

         wpabuf_free(conf->wps_nfc_dh_pubkey);

         wpabuf_free(conf->wps_nfc_dh_privkey);

         wpabuf_free(conf->wps_nfc_dev_pw);

diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h

index c49b48f..3719f94 100644

--- a/src/ap/ap_config.h

+++ b/src/ap/ap_config.h

@@ -501,6 +501,7 @@ struct hostapd_bss_config {

         char *model_url;

         char *upc;

         struct wpabuf *wps_vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];

+       struct wpabuf *wps_application_ext[MAX_WPS_APPLICATION_EXTENSIONS];

         int wps_nfc_pw_from_config;

         int wps_nfc_dev_pw_id;

         struct wpabuf *wps_nfc_dh_pubkey;

diff --git a/src/ap/wps_hostapd.c b/src/ap/wps_hostapd.c

index 2f1af11..5aaf33a 100644

--- a/src/ap/wps_hostapd.c

+++ b/src/ap/wps_hostapd.c

@@ -993,6 +993,31 @@ static int hostapd_wps_set_vendor_ext(struct hostapd_data *hapd,

 }

 

 

+static int hostapd_wps_set_application_ext(struct hostapd_data *hapd,

+                                     struct wps_context *wps)

+{

+       int i;

+

+       for (i = 0; i < MAX_WPS_APPLICATION_EXTENSIONS; i++) {

+               wpabuf_free(wps->dev.application_ext[i]);

+               wps->dev.application_ext[i] = NULL;

+

+               if (hapd->conf->wps_application_ext[i] == NULL)

+                       continue;

+

+               wps->dev.application_ext[i] =

+                       wpabuf_dup(hapd->conf->wps_application_ext[i]);

+               if (wps->dev.application_ext[i] == NULL) {

+                       while (--i >= 0)

+                               wpabuf_free(wps->dev.application_ext[i]);

+                       return -1;

+               }

+       }

+

+       return 0;

+}

+

+

 static void hostapd_free_wps(struct wps_context *wps)

 {

         int i;

@@ -1085,6 +1110,9 @@ int hostapd_init_wps(struct hostapd_data *hapd,

         if (hostapd_wps_set_vendor_ext(hapd, wps) < 0)

                 goto fail;

 

+       if (hostapd_wps_set_application_ext(hapd, wps) < 0)

+               goto fail;

+

         wps->dev.os_version = WPA_GET_BE32(hapd->conf->os_version);

 

         if (conf->wps_rf_bands) {

@@ -1319,6 +1347,7 @@ void hostapd_update_wps(struct hostapd_data *hapd)

 #endif /* CONFIG_WPS_UPNP */

 

         hostapd_wps_set_vendor_ext(hapd, hapd->wps);

+       hostapd_wps_set_application_ext(hapd, hapd->wps);

 

         if (hapd->conf->wps_state)

                 wps_registrar_update_ie(hapd->wps->registrar);

diff --git a/src/wps/wps.h b/src/wps/wps.h

index 9963c46..8605490 100644

--- a/src/wps/wps.h

+++ b/src/wps/wps.h

@@ -66,6 +66,10 @@ struct wps_credential {

 #define WPS_MAX_VENDOR_EXT_LEN 1024

 /* maximum number of parsed WPS vendor extension attributes */

 #define MAX_WPS_PARSE_VENDOR_EXT 10

+/* maximum number of advertised WPS application extension attributes */

+#define MAX_WPS_APPLICATION_EXTENSIONS 10

+/* maximum size of WPS application extension attribute */

+#define WPS_MAX_APPLICATION_EXT_LEN 1024

 

 /**

  * struct wps_device_data - WPS Device Data

@@ -98,6 +102,7 @@ struct wps_device_data {

         u16 config_methods;

         struct wpabuf *vendor_ext_m1;

         struct wpabuf *vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];

+       struct wpabuf *application_ext[MAX_WPS_APPLICATION_EXTENSIONS];

 

         int p2p;

         u8 multi_ap_ext;

diff --git a/src/wps/wps_dev_attr.c b/src/wps/wps_dev_attr.c

index b209fea..0cc312e 100644

--- a/src/wps/wps_dev_attr.c

+++ b/src/wps/wps_dev_attr.c

@@ -242,6 +242,25 @@ int wps_build_vendor_ext(struct wps_device_data *dev, struct wpabuf *msg)

 }

 

 

+int wps_build_application_ext(struct wps_device_data *dev, struct wpabuf *msg)

+{

+       int i;

+

+       for (i = 0; i < MAX_WPS_APPLICATION_EXTENSIONS; i++) {

+               if (dev->application_ext[i] == NULL)

+                       continue;

+               wpa_hexdump(MSG_DEBUG, "WPS:  * Application Extension",

+                           wpabuf_head_u8(dev->application_ext[i]),

+                           wpabuf_len(dev->application_ext[i]));

+               wpabuf_put_be16(msg, ATTR_APPLICATION_EXT);

+               wpabuf_put_be16(msg, wpabuf_len(dev->application_ext[i]));

+               wpabuf_put_buf(msg, dev->application_ext[i]);

+       }

+

+       return 0;

+}

+

+

 static int wps_process_manufacturer(struct wps_device_data *dev, const u8 *str,

                                     size_t str_len)

 {

diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c

index 0ac5b28..3de7736 100644

--- a/src/wps/wps_registrar.c

+++ b/src/wps/wps_registrar.c

@@ -1331,7 +1331,8 @@ static int wps_set_ie(struct wps_registrar *reg)

             wps_build_sel_pbc_reg_uuid_e(reg, beacon) ||

             (reg->dualband && wps_build_rf_bands(&reg->wps->dev, beacon, 0)) ||

             wps_build_wfa_ext(beacon, 0, auth_macs, count, 0) ||

-           wps_build_vendor_ext(&reg->wps->dev, beacon)) {

+           wps_build_vendor_ext(&reg->wps->dev, beacon) ||

+           wps_build_application_ext(&reg->wps->dev, beacon)) {

                 wpabuf_free(beacon);

                 wpabuf_free(probe);

                 return -1;

@@ -1361,7 +1362,8 @@ static int wps_set_ie(struct wps_registrar *reg)

             wps_build_probe_config_methods(reg, probe) ||

             (reg->dualband && wps_build_rf_bands(&reg->wps->dev, probe, 0)) ||

             wps_build_wfa_ext(probe, 0, auth_macs, count, 0) ||

-           wps_build_vendor_ext(&reg->wps->dev, probe)) {

+           wps_build_vendor_ext(&reg->wps->dev, probe) ||

+           wps_build_application_ext(&reg->wps->dev, probe)) {

                 wpabuf_free(beacon);

                 wpabuf_free(probe);

                 return -1;
Jouni Malinen Dec. 25, 2019, 7:07 p.m. UTC | #2
On Thu, Sep 05, 2019 at 12:34:40PM +0300, bilalhp@gmail.com wrote:
> From: Bilal Hatipoglu <bilal.hatipoglu@airties.com>
> 
> Application Extension attribute is defined in WPS Spec v2.06 page 105.
> This patch makes hostapd add this application extension data to WPS IE
> if configured. The implementation is very similar to vendor extension.
> 
> Signed-off-by: Veli Demirel <veli.demirel@airties.com>
> Signed-off-by: Bilal Hatipoglu <bilal.hatipoglu@airties.com>
> ---
>  src/ap/ap_config.c      |  2 ++
>  src/ap/ap_config.h      |  1 +
>  src/ap/wps_hostapd.c    | 29 +++++++++++++++++++++++++++++
>  src/wps/wps.h           |  5 +++++
>  src/wps/wps_dev_attr.c  | 19 +++++++++++++++++++
>  src/wps/wps_registrar.c |  6 ++++--
>  6 files changed, 60 insertions(+), 2 deletions(-)

How is one supposed to be able to configure these application
extensions? There is no changes here to modify hostapd/config_file.c to
parse anything new nor any documentation in hostapd/hostapd.conf for any
new configuration parameter. There's only definition of the new
configuration parameter in ap_config.h and code to free that in
ap_config.c if one were somehow able to add it.

> diff --git a/src/wps/wps_dev_attr.c b/src/wps/wps_dev_attr.c
> @@ -242,6 +242,25 @@ int wps_build_vendor_ext(struct wps_device_data *dev, struct wpabuf *msg)
> +int wps_build_application_ext(struct wps_device_data *dev, struct wpabuf *msg)

A prototype for these new function needs to be added into
src/wps/wps_dev_attr.h to avoid compilation warnings/errors in
wps_registrar.c that calls this function.
Bilal Hatipoğlu Dec. 30, 2019, 9:27 a.m. UTC | #3
On Wed, 25 Dec 2019 at 22:07, Jouni Malinen <j@w1.fi> wrote:
>
> On Thu, Sep 05, 2019 at 12:34:40PM +0300, bilalhp@gmail.com wrote:
> > From: Bilal Hatipoglu <bilal.hatipoglu@airties.com>
> >
> > Application Extension attribute is defined in WPS Spec v2.06 page 105.
> > This patch makes hostapd add this application extension data to WPS IE
> > if configured. The implementation is very similar to vendor extension.
> >
> > Signed-off-by: Veli Demirel <veli.demirel@airties.com>
> > Signed-off-by: Bilal Hatipoglu <bilal.hatipoglu@airties.com>
> > ---
> >  src/ap/ap_config.c      |  2 ++
> >  src/ap/ap_config.h      |  1 +
> >  src/ap/wps_hostapd.c    | 29 +++++++++++++++++++++++++++++
> >  src/wps/wps.h           |  5 +++++
> >  src/wps/wps_dev_attr.c  | 19 +++++++++++++++++++
> >  src/wps/wps_registrar.c |  6 ++++--
> >  6 files changed, 60 insertions(+), 2 deletions(-)
>
> How is one supposed to be able to configure these application
> extensions? There is no changes here to modify hostapd/config_file.c to
> parse anything new nor any documentation in hostapd/hostapd.conf for any
> new configuration parameter. There's only definition of the new
> configuration parameter in ap_config.h and code to free that in
> ap_config.c if one were somehow able to add it.
BH: This is currently left open as this is also the case for
wpa_vendor_ext today. Additionally, I don't know what is the preferred
method to enter this kind of multiple array entries for a config value
as there is no current example of it. Please let me know if you have
any recommendations. We currently maintain another patch for this
purpose which is not generic, so I did not publish that part.
>
> > diff --git a/src/wps/wps_dev_attr.c b/src/wps/wps_dev_attr.c
> > @@ -242,6 +242,25 @@ int wps_build_vendor_ext(struct wps_device_data *dev, struct wpabuf *msg)
> > +int wps_build_application_ext(struct wps_device_data *dev, struct wpabuf *msg)
>
> A prototype for these new function needs to be added into
> src/wps/wps_dev_attr.h to avoid compilation warnings/errors in
> wps_registrar.c that calls this function.
BH: Good catch. Will fix with v2 right away! Thanks for your time.
>
> --
> Jouni Malinen                                            PGP id EFC895FA
diff mbox series

Patch

diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
index 80a73d6..6fac2cf 100644
--- a/src/ap/ap_config.c
+++ b/src/ap/ap_config.c
@@ -768,6 +768,8 @@  void hostapd_config_free_bss(struct hostapd_bss_config *conf)
 	os_free(conf->upc);
 	for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
 		wpabuf_free(conf->wps_vendor_ext[i]);
+	for (i = 0; i < MAX_WPS_APPLICATION_EXTENSIONS; i++)
+		wpabuf_free(conf->wps_application_ext[i]);
 	wpabuf_free(conf->wps_nfc_dh_pubkey);
 	wpabuf_free(conf->wps_nfc_dh_privkey);
 	wpabuf_free(conf->wps_nfc_dev_pw);
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index c49b48f..3719f94 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -501,6 +501,7 @@  struct hostapd_bss_config {
 	char *model_url;
 	char *upc;
 	struct wpabuf *wps_vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];
+	struct wpabuf *wps_application_ext[MAX_WPS_APPLICATION_EXTENSIONS];
 	int wps_nfc_pw_from_config;
 	int wps_nfc_dev_pw_id;
 	struct wpabuf *wps_nfc_dh_pubkey;
diff --git a/src/ap/wps_hostapd.c b/src/ap/wps_hostapd.c
index 2f1af11..5aaf33a 100644
--- a/src/ap/wps_hostapd.c
+++ b/src/ap/wps_hostapd.c
@@ -993,6 +993,31 @@  static int hostapd_wps_set_vendor_ext(struct hostapd_data *hapd,
 }
 
 
+static int hostapd_wps_set_application_ext(struct hostapd_data *hapd,
+				      struct wps_context *wps)
+{
+	int i;
+
+	for (i = 0; i < MAX_WPS_APPLICATION_EXTENSIONS; i++) {
+		wpabuf_free(wps->dev.application_ext[i]);
+		wps->dev.application_ext[i] = NULL;
+
+		if (hapd->conf->wps_application_ext[i] == NULL)
+			continue;
+
+		wps->dev.application_ext[i] =
+			wpabuf_dup(hapd->conf->wps_application_ext[i]);
+		if (wps->dev.application_ext[i] == NULL) {
+			while (--i >= 0)
+				wpabuf_free(wps->dev.application_ext[i]);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+
 static void hostapd_free_wps(struct wps_context *wps)
 {
 	int i;
@@ -1085,6 +1110,9 @@  int hostapd_init_wps(struct hostapd_data *hapd,
 	if (hostapd_wps_set_vendor_ext(hapd, wps) < 0)
 		goto fail;
 
+	if (hostapd_wps_set_application_ext(hapd, wps) < 0)
+		goto fail;
+
 	wps->dev.os_version = WPA_GET_BE32(hapd->conf->os_version);
 
 	if (conf->wps_rf_bands) {
@@ -1319,6 +1347,7 @@  void hostapd_update_wps(struct hostapd_data *hapd)
 #endif /* CONFIG_WPS_UPNP */
 
 	hostapd_wps_set_vendor_ext(hapd, hapd->wps);
+	hostapd_wps_set_application_ext(hapd, hapd->wps);
 
 	if (hapd->conf->wps_state)
 		wps_registrar_update_ie(hapd->wps->registrar);
diff --git a/src/wps/wps.h b/src/wps/wps.h
index 9963c46..8605490 100644
--- a/src/wps/wps.h
+++ b/src/wps/wps.h
@@ -66,6 +66,10 @@  struct wps_credential {
 #define WPS_MAX_VENDOR_EXT_LEN 1024
 /* maximum number of parsed WPS vendor extension attributes */
 #define MAX_WPS_PARSE_VENDOR_EXT 10
+/* maximum number of advertised WPS application extension attributes */
+#define MAX_WPS_APPLICATION_EXTENSIONS 10
+/* maximum size of WPS application extension attribute */
+#define WPS_MAX_APPLICATION_EXT_LEN 1024
 
 /**
  * struct wps_device_data - WPS Device Data
@@ -98,6 +102,7 @@  struct wps_device_data {
 	u16 config_methods;
 	struct wpabuf *vendor_ext_m1;
 	struct wpabuf *vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];
+	struct wpabuf *application_ext[MAX_WPS_APPLICATION_EXTENSIONS];
 
 	int p2p;
 	u8 multi_ap_ext;
diff --git a/src/wps/wps_dev_attr.c b/src/wps/wps_dev_attr.c
index b209fea..0cc312e 100644
--- a/src/wps/wps_dev_attr.c
+++ b/src/wps/wps_dev_attr.c
@@ -242,6 +242,25 @@  int wps_build_vendor_ext(struct wps_device_data *dev, struct wpabuf *msg)
 }
 
 
+int wps_build_application_ext(struct wps_device_data *dev, struct wpabuf *msg)
+{
+	int i;
+
+	for (i = 0; i < MAX_WPS_APPLICATION_EXTENSIONS; i++) {
+		if (dev->application_ext[i] == NULL)
+			continue;
+		wpa_hexdump(MSG_DEBUG, "WPS:  * Application Extension",
+			    wpabuf_head_u8(dev->application_ext[i]),
+			    wpabuf_len(dev->application_ext[i]));
+		wpabuf_put_be16(msg, ATTR_APPLICATION_EXT);
+		wpabuf_put_be16(msg, wpabuf_len(dev->application_ext[i]));
+		wpabuf_put_buf(msg, dev->application_ext[i]);
+	}
+
+	return 0;
+}
+
+
 static int wps_process_manufacturer(struct wps_device_data *dev, const u8 *str,
 				    size_t str_len)
 {
diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c
index 0ac5b28..3de7736 100644
--- a/src/wps/wps_registrar.c
+++ b/src/wps/wps_registrar.c
@@ -1331,7 +1331,8 @@  static int wps_set_ie(struct wps_registrar *reg)
 	    wps_build_sel_pbc_reg_uuid_e(reg, beacon) ||
 	    (reg->dualband && wps_build_rf_bands(&reg->wps->dev, beacon, 0)) ||
 	    wps_build_wfa_ext(beacon, 0, auth_macs, count, 0) ||
-	    wps_build_vendor_ext(&reg->wps->dev, beacon)) {
+	    wps_build_vendor_ext(&reg->wps->dev, beacon) ||
+	    wps_build_application_ext(&reg->wps->dev, beacon)) {
 		wpabuf_free(beacon);
 		wpabuf_free(probe);
 		return -1;
@@ -1361,7 +1362,8 @@  static int wps_set_ie(struct wps_registrar *reg)
 	    wps_build_probe_config_methods(reg, probe) ||
 	    (reg->dualband && wps_build_rf_bands(&reg->wps->dev, probe, 0)) ||
 	    wps_build_wfa_ext(probe, 0, auth_macs, count, 0) ||
-	    wps_build_vendor_ext(&reg->wps->dev, probe)) {
+	    wps_build_vendor_ext(&reg->wps->dev, probe) ||
+	    wps_build_application_ext(&reg->wps->dev, probe)) {
 		wpabuf_free(beacon);
 		wpabuf_free(probe);
 		return -1;