From patchwork Thu Jan 2 10:30:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Bilal_Hatipo=C4=9Flu?= X-Patchwork-Id: 1217048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FyALTUaK"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="R6gBYd96"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47pPT84bK4z9sPn for ; Thu, 2 Jan 2020 21:31:08 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=DIAKuXxRYKfGKGec17RP7jItoxSKe0KWuuhizCThWmk=; b=FyALTUaKVu7qOL kTPGN+/llNlB8A4gPUpn6XeKjnlJGjSgBSCmthin8gIZMZfQJPe4Ytgnxr7G0JJq18tTWMwXZc59o 3R8tw1RHafW9MaDOixK4NsHDTsP4eEcYWvUXPA7NNczM1vXi4v/E6I0Wmuz80sVxCakH0+rG9eB2n OAfywKUE8XEavOo4Y2IEBck/3MzEHEF8ecVgDR1hmtaVTJ7lt/LfftpG4LHK01ZAhrew3w2GLuT29 lZMtkNSDxnZJw36ZJS9Ei89YJEtHBPVF8RqUrjEprYE8aBc38q+aXsp1+lc3QrHTdYXQvjdQK2oUE 1TCnXebOmJ0wWc1AEj9w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1imxkt-0001yz-CU; Thu, 02 Jan 2020 10:31:03 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1imxkq-0001xw-2N for hostap@lists.infradead.org; Thu, 02 Jan 2020 10:31:01 +0000 Received: by mail-lj1-x244.google.com with SMTP id y6so32221584lji.0 for ; Thu, 02 Jan 2020 02:30:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=2kcQN+HP6pD+Z7OtkKvrp7zZX9yKG1Mu15QWUxb9nfQ=; b=R6gBYd963+mk0XfyJRRsoq6I+adx5NDNPSKcimZb6MlMIymk3/Jlr8BJWPpTfE3aFf xcap762HdiDH7XoYxWstKxZsf55CNmJLfiwNVM/7JRc35r2EjG9uLJs6iYBLtbbMo9FN jcFxiDN9C6AwVYgV2znao5bsWFy9LQxUev9VxUZzg2LOFN8TPJ/XDNUxqO0feriRcinJ I96TPO1WXjXEYNKg8XQHjJgRmOnPxdpUF+NpGmGAFEpaVgF++F9JOvdnyCtmVCZDbzxn Q9UdBB8n5Fy6RRuUw6QekfiGHOAzHuT1YH/DT8p/GqeLppioCrVwUZMKDoDtzsuh72Qj vahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=2kcQN+HP6pD+Z7OtkKvrp7zZX9yKG1Mu15QWUxb9nfQ=; b=HS14pwye78eeP/QG+r0dJ6Oa97I3e+oPR9lXSKDMhZ7R1xbDQ3AJBWL+n1eHU/kUId AGpTk0HQVmevE+PO+46bFvzlxXl0uWaV1nVRIkmEHAeoZAdNcNRtCdFgW6kCG51iSL8Z c+yHxcqR+xbzhwzEIxjJ8/3rDaiGEdumE/aj10Vy8dOLulyGS/lEHXR6ks6uliL4Opkr i5BCEKpjg8v/T/vUk3DkfRyQRBtKu5V74xQzgXv8uYzWLidM7TOWS9jqdRImwDCCBWca 4LhcNxE+enq4IVQ8PGWE2MdGHJ8rTsnyzqkdHOrlkkWPWt5P3A34OVN0wj4/tD1otX1B 2rlg== X-Gm-Message-State: APjAAAUMqgGzagFVV6snhwUT1VlMM3g0ZrU0QV3FCFxCEtVh8UChZc7h C8dV0igK1f3xS11bvtPU5RDu6SiY X-Google-Smtp-Source: APXvYqwBHcKCWlP7NoTg8MENUP4/NsFs79mYv8cKybhESw0Yg6M+f9IPSlXD3TsupqFITKST72i8Gg== X-Received: by 2002:a2e:9687:: with SMTP id q7mr40390799lji.232.1577961057289; Thu, 02 Jan 2020 02:30:57 -0800 (PST) Received: from bilal-kubuntu-new.corp.airties.com ([91.220.65.3]) by smtp.gmail.com with ESMTPSA id d9sm22438677lja.73.2020.01.02.02.30.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jan 2020 02:30:56 -0800 (PST) From: bilalhp@gmail.com To: hostap@lists.infradead.org Subject: [PATCH v4] Add application extension data to WPS IE Date: Thu, 2 Jan 2020 13:30:50 +0300 Message-Id: <1577961050-8756-1-git-send-email-bilalhp@gmail.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200102_023100_137304_877234DC X-CRM114-Status: GOOD ( 16.91 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:244 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (bilalhp[at]gmail.com) 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bilal Hatipoglu 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. Added a new optional entry called "wps_application_ext[]" to hostapd config file to configure this. Signed-off-by: Veli Demirel Signed-off-by: Bilal Hatipoglu --- hostapd/config_file.c | 12 ++++++++++++ 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_dev_attr.h | 1 + src/wps/wps_registrar.c | 6 ++++-- 8 files changed, 73 insertions(+), 2 deletions(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index 21c9ab2..cb03440 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -3616,6 +3616,18 @@ static int hostapd_config_fill(struct hostapd_config *conf, } os_free(bss->device_name); bss->device_name = os_strdup(pos); + } else if (os_strncmp(buf, "wps_application_ext[", 20) == 0) { + char *endp = NULL; + long int i = strtol(buf + 20, &endp, 10); + + if ((*endp != ']') || + (i < 0) || + (i >= MAX_WPS_APPLICATION_EXTENSIONS)) { + wpa_printf(MSG_ERROR, "Line %d: Invalid index", line); + return 1; + } + wpabuf_free(bss->wps_application_ext[i]); + bss->wps_application_ext[i] = wpabuf_parse_bin(pos); } else if (os_strcmp(buf, "manufacturer") == 0) { if (os_strlen(pos) > 64) { wpa_printf(MSG_ERROR, "Line %d: Too long manufacturer", diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c index 68af3c1..684450f 100644 --- a/src/ap/ap_config.c +++ b/src/ap/ap_config.c @@ -813,6 +813,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 7e4b926..e8f033a 100644 --- a/src/ap/ap_config.h +++ b/src/ap/ap_config.h @@ -498,6 +498,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 175b9fc..dc4e0b5 100644 --- a/src/ap/wps_hostapd.c +++ b/src/ap/wps_hostapd.c @@ -985,6 +985,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; @@ -1077,6 +1102,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) { @@ -1311,6 +1339,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_dev_attr.h b/src/wps/wps_dev_attr.h index a4b4173..81fdd5f 100644 --- a/src/wps/wps_dev_attr.h +++ b/src/wps/wps_dev_attr.h @@ -33,6 +33,7 @@ void wps_process_vendor_ext_m1(struct wps_device_data *dev, const u8 ext); int wps_process_rf_bands(struct wps_device_data *dev, const u8 *bands); void wps_device_data_free(struct wps_device_data *dev); 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 wps_build_req_dev_type(struct wps_device_data *dev, struct wpabuf *msg, unsigned int num_req_dev_types, const u8 *req_dev_types); diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c index 671f5fe..da81d1a 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(®->wps->dev, beacon, 0)) || wps_build_wfa_ext(beacon, 0, auth_macs, count, 0) || - wps_build_vendor_ext(®->wps->dev, beacon)) { + wps_build_vendor_ext(®->wps->dev, beacon) || + wps_build_application_ext(®->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(®->wps->dev, probe, 0)) || wps_build_wfa_ext(probe, 0, auth_macs, count, 0) || - wps_build_vendor_ext(®->wps->dev, probe)) { + wps_build_vendor_ext(®->wps->dev, probe) || + wps_build_application_ext(®->wps->dev, probe)) { wpabuf_free(beacon); wpabuf_free(probe); return -1;