From patchwork Fri Jun 26 22:57:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wang X-Patchwork-Id: 1318162 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=2001:8b0:10b:1231::1; helo=merlin.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=chromium.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=jBSSeYOW; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HuK+9ZoK; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 49tskY0K38z9sRk for ; Sat, 27 Jun 2020 08:58:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=m0tOproSk3BHt8NQPj8VKff3Uj8ILRAUIVtvf+dg4/M=; b=jBSSeYOWiqNc3RxTY7qDdnZm3T CKQY4Qua67af8ZKlRTtdQoCsdzjMYOyNRwY1vJMjXGwTs6e3CnMjEls3EXCXzMwr14P9N9/VNVet4 MYMt56gE02rOzxBCc/3jy7sNdU+9IjWFY9H88PWM+MTVl8NL/NV64e6ni7SluJMUokE4TYTx16YC9 Ufsz7UzW/aA8I5tjExqNbgqjTnVkN6DKO85EKN5NfoSzuLG1aRMi8vxYyltrACyNYNFGgSGnjSYrp 4n8HseheNQbnzebXIHwYBLGqA8gI6n5r7YqOI3mrJqMPPtnykmwC/USULFo8AFt3fkEgOO711ribP z+rnAVvQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joxHh-0004X0-Nz; Fri, 26 Jun 2020 22:57:25 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joxHa-0004Wb-V6 for hostap@lists.infradead.org; Fri, 26 Jun 2020 22:57:19 +0000 Received: by mail-pl1-x644.google.com with SMTP id y18so4820573plr.4 for ; Fri, 26 Jun 2020 15:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LbewRfxj+or94yTNILKRrSJGCdDb71D+UASFVyoT3iQ=; b=HuK+9ZoKLGrRQFe9SwWSjIPFarSy4SzJrwle2aBgI4mWLdvgBUbhE9l2VS+eJKd4xX l5ZtkDjaRBFkXej9r8ne11nvd/wiswbxUOJlXRPRh6VEvFWmjt7Q3fGx8hRwlNrSCCzE mIo4dvX5gH2oLoMFrIcyVYgnb+z6jlXWddRiQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LbewRfxj+or94yTNILKRrSJGCdDb71D+UASFVyoT3iQ=; b=Kk+xhibXAiAJX44fQUL67Nuco45HDOtqZobe7/McOni/ogQlIN96aD24Wu3/0KLbaf 7pIagATt9D7XEQuYFqNENIsTyfbXtp3JcuccEmVJ9CDYeJ/U37XZJhbkfsF5dIc+3ITQ 0gvC9h3WL4hub1IqrYREVoHNfZCcKpIrKXwg7QReYs20gy0ccpDGeU2yRFYp1amlpMWC 1sxBR0e0TyaYaptaI68hnif/TVXs7T5lifIUqIhGjIfj/QbC/3Wm9DUPGkf+N4EQz/HM s0uvcduzf6zEZUyCgb9A0aBFPQ9fnBDxVBs/pjO6IVcL53ztETFUWdlP7yMCj2ZAnN4d J9gQ== X-Gm-Message-State: AOAM5306E99IoXifwLYZ6Boa5Sq3B/tdJKoPa+t6HJq6YGwN7eT9Dp7Y kPsyGOvQR55+SVqXDIZ63BlxLw== X-Google-Smtp-Source: ABdhPJy9wJlS1ATG3w+Pk7UXPC3FpEDSTkW3gSKlCJFH8vwe7Sl2qysdBB5KsHTemKZ8/HoyQAbUxA== X-Received: by 2002:a17:902:b698:: with SMTP id c24mr4381888pls.223.1593212235013; Fri, 26 Jun 2020 15:57:15 -0700 (PDT) Received: from localhost ([2620:15c:202:201:2b10:8627:31e7:c5ec]) by smtp.gmail.com with ESMTPSA id 25sm26421689pfi.7.2020.06.26.15.57.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jun 2020 15:57:14 -0700 (PDT) From: Matthew Wang To: j@w1.fi Subject: [PATCH 1/3] skip property update actions when wpa_config_set returns 1 Date: Fri, 26 Jun 2020 15:57:06 -0700 Message-Id: <20200626225708.429239-1-matthewmwang@chromium.org> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [2607:f8b0:4864:20:0:0:0:644 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender 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: , Cc: hostap@lists.infradead.org, Matthew Wang Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When network properties are updated via dbus, wpa_config_set is used to update the property in the wpa_ssid struct. If it returns 1, the property was not changed and there's no need to perform any of the update actions. Signed-off-by: Matthew Wang --- wpa_supplicant/dbus/dbus_new_handlers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index d1f9607c6..93eeb30e1 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -267,8 +267,15 @@ dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s, } else goto error; - if (wpa_config_set(ssid, entry.key, value, 0) < 0) + ret = wpa_config_set(ssid, entry.key, value, 0); + if (ret < 0) goto error; + if (ret == 1) { + os_free(value); + value = NULL; + wpa_dbus_dict_entry_clear(&entry); + continue; + } if (os_strcmp(entry.key, "bssid") != 0 && os_strcmp(entry.key, "priority") != 0) From patchwork Fri Jun 26 22:57:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wang X-Patchwork-Id: 1318163 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=2001:8b0:10b:1231::1; helo=merlin.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=chromium.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=J91bhfnb; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=jfwJ7+nz; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 49tskY1K2jz9sSS for ; Sat, 27 Jun 2020 08:58:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8emflAqjqLZl16sflmXYM3y3oYSeN/y2ist+RTikRxM=; b=J91bhfnbYqhN06BpKJxK79H42 1T520PHwJ83oaxLdgPohVC3jkxPigIKJ0jJwC1eprHS8WBcbepVZA6URpm761yqIZrGgLTYpRvrnV AOqL2nWiILntaB7hblsP4oUAqi80H/pV7HzjTuQbO7FETruxB8CrQQBAH4EmtaQeLG1rP2yP/G2BM /kPKbF1AKiFWn6Rw3GicP+GMkmwHTQ3xPGP/ZXSL82AS+mxKt7MJbiPfrC7ida3UyiRhGXU6k8bNG 9zdQSjCMar/wLvOvBVOA50FffHw+rcu+fdsuU+aQS7ZS43aKQ8gr4bMy2LvPptWWlW7EYDCmoGA9Q bVRfkAXQQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joxHl-0004Xa-9Y; Fri, 26 Jun 2020 22:57:29 +0000 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joxHc-0004Wh-L3 for hostap@lists.infradead.org; Fri, 26 Jun 2020 22:57:25 +0000 Received: by mail-pj1-x1044.google.com with SMTP id i4so5558473pjd.0 for ; Fri, 26 Jun 2020 15:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J8u3hUUnhrwvtKWuB8Vq92VQvcQi71mYvmiPUx8FijQ=; b=jfwJ7+nz3mZC4jBv9TEkIZVu5mYu+ktBdVHUfPUOb245wGj+wTapWrFvxMHDsxNWQ7 NtIPuQ2Z7gywM8Dg9FoDlmUSgbR8Oe2ZWhvza2e6ohzQDMvX7b4SY5OOOetQvVJxZF90 BhAlEWJq7ZbVAsHkROzCqEOetZ5nJyZKApbow= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J8u3hUUnhrwvtKWuB8Vq92VQvcQi71mYvmiPUx8FijQ=; b=NTfg3E5dMdg0GA/YanH9AQHwx2TQDpIvDTObj23LanVCiFkcGsHWuLE1Z8G7UadVrX sATgbtbsZ7a5jESA5UNeLZuY8F3VfHjcCET+gvv7mSpWqXJfldv6ITD8mV2UAvVOZY/U wyoyAmiTryTrMt2tqNhbEGMnjQJNI2GnwAw/1EbN7oSVPTRyEZ6nCG1rJgyfiaJxCJ4d 54F3aKyaU2LXc8ygKkcR9Oy5jpbKzNX+4kcZgVrGN/V1c6HBaIhfEWIqZE3AMqyPzYl4 arLJ0OPE7njYVQ3aJCHRaHfnlgIdW8CTQUIxdpUV0QQVy2Co5RlUspZcgGb4ce5MizXy KhNA== X-Gm-Message-State: AOAM531Zha2bm7aFVo3KL/q2I2KfuRO4wJabHidoFa4j4dTiv422hH/6 Y/05Nvd0h1ujfWUZgsxQy+gkcdvfOLA= X-Google-Smtp-Source: ABdhPJy1scnzIrG12aPWmVwDwyU7PWgaN4pKMuXAUM8+xsTEPXYyw/nOZCqzLMSMUVKU3RJEMp7Prg== X-Received: by 2002:a17:90a:b781:: with SMTP id m1mr5402378pjr.14.1593212238290; Fri, 26 Jun 2020 15:57:18 -0700 (PDT) Received: from localhost ([2620:15c:202:201:2b10:8627:31e7:c5ec]) by smtp.gmail.com with ESMTPSA id u19sm28557979pfk.98.2020.06.26.15.57.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jun 2020 15:57:17 -0700 (PDT) From: Matthew Wang To: j@w1.fi Subject: [PATCH 2/3] global parser functions return 1 when property unchanged Date: Fri, 26 Jun 2020 15:57:07 -0700 Message-Id: <20200626225708.429239-2-matthewmwang@chromium.org> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog In-Reply-To: <20200626225708.429239-1-matthewmwang@chromium.org> References: <20200626225708.429239-1-matthewmwang@chromium.org> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [2607:f8b0:4864:20:0:0:0:1044 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender 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: , Cc: hostap@lists.infradead.org, Matthew Wang Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, wpa_config_set, the function that sets per-network properties, returns 1 when a property it attempts to set is unchanged. Its global parallel, wpa_config_process_global, doesn't do this even though much of the code is very similar. Change this, and several of the parser functions, to resemble the per-network parser and setter functions. Signed-off-by: Matthew Wang --- src/utils/wpabuf.h | 15 ++++++ wpa_supplicant/config.c | 63 +++++++++++++++++++++++-- wpa_supplicant/ctrl_iface.c | 2 + wpa_supplicant/dbus/dbus_new_handlers.c | 8 ++-- 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/utils/wpabuf.h b/src/utils/wpabuf.h index 01da41b32..ecdc08f84 100644 --- a/src/utils/wpabuf.h +++ b/src/utils/wpabuf.h @@ -70,6 +70,21 @@ static inline size_t wpabuf_tailroom(const struct wpabuf *buf) return buf->size - buf->used; } +/** + * wpabuf_cmp - Check if two buffers contain the same data + * @a: wpabuf buffer + * @b: wpabuf buffer + * Returns: 0 if the two buffers contain the same data and non-zero otherwise + */ +static inline int wpabuf_cmp(const struct wpabuf *a, const struct wpabuf *b) +{ + if (a == NULL && b == NULL) + return 0; + if (a && b && wpabuf_size(a) == wpabuf_size(b)) + return os_memcmp(a->buf, b->buf, wpabuf_size(a)); + return -1; +} + /** * wpabuf_head - Get pointer to the head of the buffer data * @buf: wpabuf buffer diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 0b4a66ad7..e4fa43ec7 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -4360,13 +4360,31 @@ void wpa_config_debug_dump_networks(struct wpa_config *config) #endif /* CONFIG_NO_STDOUT_DEBUG */ +/** + * Structure for global configuration parsing. This data is used to implement a + * generic parser for the global interface configuration. The table of variables + * is defined below in this file (global_fields[]). + */ struct global_parse_data { + /* Configuration variable name */ char *name; + + /* Parser function for this variable. The parser functions return 0 or 1 + * to indicate success. Value 0 indicates that the parameter value may + * have change while value 1 means that the value did not change. + * Error cases (failure to parse the string) are indicated by returning + * -1. */ int (*parser)(const struct global_parse_data *data, struct wpa_config *config, int line, const char *value); + + /* Getter function to print the variable in text format to buf. */ int (*get)(const char *name, struct wpa_config *config, long offset, char *buf, size_t buflen, int pretty_print); + + /* Variable specific parameters for the parser. */ void *param1, *param2, *param3; + + /* Indicates which configuration variable has changed. */ unsigned int changed_flag; }; @@ -4385,8 +4403,10 @@ static int wpa_global_config_parse_int(const struct global_parse_data *data, line, pos); return -1; } - *dst = val; + if (*dst == val) + return 1; + *dst = val; wpa_printf(MSG_DEBUG, "%s=%d", data->name, *dst); if (data->param2 && *dst < (long) data->param2) { @@ -4413,7 +4433,7 @@ static int wpa_global_config_parse_str(const struct global_parse_data *data, struct wpa_config *config, int line, const char *pos) { - size_t len; + size_t len, prev_len; char **dst, *tmp; len = os_strlen(pos); @@ -4437,11 +4457,22 @@ static int wpa_global_config_parse_str(const struct global_parse_data *data, return -1; } + dst = (char **) (((u8 *) config) + (long) data->param1); + if (*dst) + prev_len = os_strlen(*dst); + else + prev_len = 0; + + /* No change to the previously configured value */ + if ((*dst == NULL && pos == NULL) || + (*dst && pos && prev_len == len && + os_memcmp(*dst, pos, len) == 0)) + return 1; + tmp = os_strdup(pos); if (tmp == NULL) return -1; - dst = (char **) (((u8 *) config) + (long) data->param1); os_free(*dst); *dst = tmp; wpa_printf(MSG_DEBUG, "%s='%s'", data->name, *dst); @@ -4482,6 +4513,10 @@ static int wpa_global_config_parse_bin(const struct global_parse_data *data, return -1; dst = (struct wpabuf **) (((u8 *) config) + (long) data->param1); + if (wpabuf_cmp(*dst, tmp) == 0) { + wpabuf_free(tmp); + return 1; + } wpabuf_free(*dst); *dst = tmp; wpa_printf(MSG_DEBUG, "%s", data->name); @@ -4523,6 +4558,8 @@ static int wpa_global_config_parse_ipv4(const struct global_parse_data *data, return -1; dst = (u32 *) (((u8 *) config) + (long) data->param1); + if (os_memcmp(dst, &addr.u.v4.s_addr, 4) == 0) + return 1; os_memcpy(dst, &addr.u.v4.s_addr, 4); wpa_printf(MSG_DEBUG, "%s = 0x%x", data->name, WPA_GET_BE32((u8 *) dst)); @@ -4540,6 +4577,8 @@ static int wpa_config_process_country(const struct global_parse_data *data, wpa_printf(MSG_DEBUG, "Invalid country set"); return -1; } + if (pos[0] == config->country[0] && pos[1] == config->country[1]) + return 1; config->country[0] = pos[0]; config->country[1] = pos[1]; wpa_printf(MSG_DEBUG, "country='%c%c'", @@ -5158,6 +5197,19 @@ const char * wpa_config_get_global_field_name(unsigned int i, int *no_var) } +/** + * wpa_config_process_global - Set a variable in global configuration + * @config: Pointer to global configuration data + * @pos: Name and value in the format "{name}={value}" + * @line: Line number in configuration file or 0 if not used + * Returns: 0 on success with possible change in value, 1 on success with no + * change to previously configured value, or -1 on failure + * + * This function can be used to set global configuration variables based on + * both the configuration file and management interface input. The value + * parameter must be in the same format as the text-based configuration file is + * using. For example, strings are using double quotation marks. + */ int wpa_config_process_global(struct wpa_config *config, char *pos, int line) { size_t i; @@ -5170,11 +5222,14 @@ int wpa_config_process_global(struct wpa_config *config, char *pos, int line) pos[flen] != '=') continue; - if (field->parser(field, config, line, pos + flen + 1)) { + ret = field->parser(field, config, line, pos + flen + 1); + if (ret < 0) { wpa_printf(MSG_ERROR, "Line %d: failed to " "parse '%s'.", line, pos); ret = -1; } + if (ret == 1) + break; if (field->changed_flag == CFG_CHANGED_NFC_PASSWORD_TOKEN) config->wps_nfc_pw_from_config = 1; config->changed_parameters |= field->changed_flag; diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 8d2ccbae5..eea8b40f4 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -884,6 +884,8 @@ static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s, ret = wpa_config_process_global(wpa_s->conf, cmd, -1); if (ret == 0) wpa_supplicant_update_config(wpa_s); + else if (ret == 1) + ret = 0; } return ret; diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index 93eeb30e1..18b66e303 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -3948,14 +3948,14 @@ dbus_bool_t wpas_dbus_setter_iface_global( return FALSE; } - if (wpa_config_process_global(wpa_s->conf, buf, -1)) { + ret = wpa_config_process_global(wpa_s->conf, buf, -1); + if (ret < 0) { dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "Failed to set interface property %s", property_desc->dbus_property); return FALSE; - } - - wpa_supplicant_update_config(wpa_s); + } else if (ret == 0) + wpa_supplicant_update_config(wpa_s); return TRUE; } From patchwork Fri Jun 26 22:57:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wang X-Patchwork-Id: 1318161 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=2001:8b0:10b:1231::1; helo=merlin.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=chromium.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=VS3AoZPx; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Y51EQ6FL; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 49tskY0Hvjz9sQx for ; Sat, 27 Jun 2020 08:58:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1b4b4ktt1jo6qp6gShCXtCfnt+LpTLI2ixpiGxXZvoQ=; b=VS3AoZPxLqDil/Y+Q4t4hw0dH bPJoS3tNay7zQ2nLsVvSXbwAjqbeygTTNemcweeBgCtR0bxMNvbYm1E2aw9ldN3mW/gTTV7Jw+PZg 3cNJ2NXTa7csNjyZoWEaM5DIRL6fwQEochqhCPPCggFprfsvd6LMAx3Y6HHbfzeoFANNiZMDoQ6OS pvSDO8zjRdckJhh1SdSgSmgggPQ7ui6WGPD/RPl7JbE8T/ZUJvhLWwgHdw9ScnkNElGr+j/DatQ4C HZ9Tr2bX3QSauHSgahWGjuK6sNPoYz3WYmZ1I9v0JEivqSDXF8d6Rkta9ijuSUg+62OkMDfillx4Y AebtMFEuQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joxHj-0004XM-Um; Fri, 26 Jun 2020 22:57:28 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1joxHg-0004Wt-30 for hostap@lists.infradead.org; Fri, 26 Jun 2020 22:57:25 +0000 Received: by mail-pf1-x444.google.com with SMTP id a127so5244713pfa.12 for ; Fri, 26 Jun 2020 15:57:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fH494sWmiPwpWejBe5vn3WQPh02pbgE9GgNwRSfuBiw=; b=Y51EQ6FLwpMuqpnleou67BN/mcoqs1LqWCr/r4GKcZYDKmWmgtIBMhq7COtB2GDq8T K4x56qebI1jW1etMsIoykkbqPvBqcJozhIMqx3OwKk2db90Ax5qAnexwKv4btU07YN7G +RUpb9r+ufTz+6e4l4EKX5FQpwI6Wdl+vgbXU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fH494sWmiPwpWejBe5vn3WQPh02pbgE9GgNwRSfuBiw=; b=WUqhwx8LqHtkX4IEg29VRqdz7SyvPn4ybaNeHsC/fxEFEPIvQCnjrQAp2JfugzsmIK ZYFcw9O8pIj3GiKsFfhtExqtBbZ3qAYBIlWC9BFmVtI/61rc15pY1wrI0E4P/nzPmSkI 36RIS+z7Yj3Rl7Er3IuVkaL9LVexwCBJasK1zJGXuSgpAmxF36T40mjFL5QoK6SN1eRo pPmJpX70baI7//6zaoTrQTnINDbTqui1cEZpym/LsCM0m+5xkHeSTBhd3GGoFZSMlSUj hx1Lhc9X3AokE6lgORzqFeI93UseMF6xxG22oumIFAeJHGC9VMM0LJkDiGSoBjM2Fiko kyKQ== X-Gm-Message-State: AOAM5322Rc6BsTB2ZOh/lnZeIQ1wY80i+ojs8isMN6EiJWl1ArD+hc5w ikapkNsFKh6EIfpmuKHILgJsTg== X-Google-Smtp-Source: ABdhPJyUDUAYr7mcBx9911NIcMGRWYcYHbAp871bSv8mkh0rpuaqhi0NL4qQ35REZeIVG/a+XQxCIQ== X-Received: by 2002:a65:620e:: with SMTP id d14mr902510pgv.360.1593212241911; Fri, 26 Jun 2020 15:57:21 -0700 (PDT) Received: from localhost ([2620:15c:202:201:2b10:8627:31e7:c5ec]) by smtp.gmail.com with ESMTPSA id w17sm28189874pff.27.2020.06.26.15.57.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jun 2020 15:57:21 -0700 (PDT) From: Matthew Wang To: j@w1.fi Subject: [PATCH 3/3] reconfigure bgscan parameters Date: Fri, 26 Jun 2020 15:57:08 -0700 Message-Id: <20200626225708.429239-3-matthewmwang@chromium.org> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog In-Reply-To: <20200626225708.429239-1-matthewmwang@chromium.org> References: <20200626225708.429239-1-matthewmwang@chromium.org> MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.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 [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 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_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 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender 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: , Cc: hostap@lists.infradead.org, Matthew Wang Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Teach wpa_supplicant to {de,}initialize bgscans when bgscan parameters are set after initial connection. Signed-off-by: Matthew Wang --- wpa_supplicant/config.c | 2 +- wpa_supplicant/config.h | 1 + wpa_supplicant/ctrl_iface.c | 7 ++++ wpa_supplicant/dbus/dbus_new_handlers.c | 7 ++++ wpa_supplicant/wpa_supplicant.c | 48 +++++++++++++++++-------- wpa_supplicant/wpa_supplicant_i.h | 3 ++ 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index e4fa43ec7..11baee54b 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -4963,7 +4963,7 @@ static const struct global_parse_data global_fields[] = { { INT_RANGE(eapol_version, 1, 2), 0 }, #endif /* CONFIG_MACSEC */ { INT(ap_scan), 0 }, - { FUNC(bgscan), 0 }, + { FUNC(bgscan), CFG_CHANGED_BGSCAN }, #ifdef CONFIG_MESH { INT(user_mpm), 0 }, { INT_RANGE(max_peer_links, 0, 255), 0 }, diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index a385da528..59c8e7bbd 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -376,6 +376,7 @@ struct wpa_cred { #define CFG_CHANGED_SCHED_SCAN_PLANS BIT(17) #define CFG_CHANGED_WOWLAN_TRIGGERS BIT(18) #define CFG_CHANGED_DISABLE_BTM BIT(19) +#define CFG_CHANGED_BGSCAN BIT(20) /** * struct wpa_config - wpa_supplicant configuration data diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index eea8b40f4..fdbbfa463 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -3555,6 +3555,13 @@ static int wpa_supplicant_ctrl_iface_update_network( else if (os_strcmp(name, "priority") == 0) wpa_config_update_prio_list(wpa_s->conf); +#ifdef CONFIG_BGSCAN + if (os_strcmp(name, "bgscan") == 0 && + wpa_s->current_ssid == ssid && + wpa_s->wpa_state == WPA_COMPLETED) + wpa_supplicant_reset_bgscan(wpa_s); +#endif /* CONFIG_BGSCAN */ + return 0; } diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c index 18b66e303..79a3799eb 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers.c +++ b/wpa_supplicant/dbus/dbus_new_handlers.c @@ -297,6 +297,13 @@ dbus_bool_t set_network_properties(struct wpa_supplicant *wpa_s, else if (os_strcmp(entry.key, "priority") == 0) wpa_config_update_prio_list(wpa_s->conf); +#ifdef CONFIG_BGSCAN + if (os_strcmp(entry.key, "bgscan") == 0 && + wpa_s->current_ssid == ssid && + wpa_s->wpa_state == WPA_COMPLETED) + wpa_supplicant_reset_bgscan(wpa_s); +#endif /* CONFIG_BGSCAN */ + os_free(value); value = NULL; wpa_dbus_dict_entry_clear(&entry); diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index e7989baef..62a6538b2 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -803,7 +803,22 @@ const char * wpa_supplicant_state_txt(enum wpa_states state) #ifdef CONFIG_BGSCAN -static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s) +static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s) +{ + if (wpa_s->bgscan_ssid != NULL) { + bgscan_deinit(wpa_s); + wpa_s->bgscan_ssid = NULL; + } +} + + +/** + * wpa_supplicant_reset_bgscan - Reset the bgscan for the current SSID. + * @wpa_s: Pointer to the wpa_supplicant data + * + * Stop, start, or reconfigure the scan parameters depending on the method. + */ +void wpa_supplicant_reset_bgscan(struct wpa_supplicant *wpa_s) { const char *name; @@ -811,12 +826,12 @@ static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s) name = wpa_s->current_ssid->bgscan; else name = wpa_s->conf->bgscan; - if (name == NULL || name[0] == '\0') + if (name == NULL || name[0] == '\0') { + wpa_supplicant_stop_bgscan(wpa_s); return; + } if (wpas_driver_bss_selection(wpa_s)) return; - if (wpa_s->current_ssid == wpa_s->bgscan_ssid) - return; #ifdef CONFIG_P2P if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) return; @@ -846,15 +861,6 @@ static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s) wpa_s->bgscan_ssid = NULL; } - -static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s) -{ - if (wpa_s->bgscan_ssid != NULL) { - bgscan_deinit(wpa_s); - wpa_s->bgscan_ssid = NULL; - } -} - #endif /* CONFIG_BGSCAN */ @@ -1011,8 +1017,8 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_s->wpa_state = state; #ifdef CONFIG_BGSCAN - if (state == WPA_COMPLETED) - wpa_supplicant_start_bgscan(wpa_s); + if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid) + wpa_supplicant_reset_bgscan(wpa_s); else if (state < WPA_ASSOCIATED) wpa_supplicant_stop_bgscan(wpa_s); #endif /* CONFIG_BGSCAN */ @@ -7151,6 +7157,18 @@ void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s) if (wpa_s->conf->changed_parameters & CFG_CHANGED_DISABLE_BTM) wpa_supplicant_set_default_scan_ies(wpa_s); +#ifdef CONFIG_BGSCAN + /* + * We default to global bgscan parameters only when per-network bgscan + * parameters aren't set. Only bother resetting bgscan parameters if + * this is the case. + */ + if (wpa_s->conf->changed_parameters & CFG_CHANGED_BGSCAN && + wpa_s->current_ssid && !wpa_s->current_ssid->bgscan && + wpa_s->wpa_state == WPA_COMPLETED) + wpa_supplicant_reset_bgscan(wpa_s); +#endif /* CONFIG_BGSCAN */ + #ifdef CONFIG_WPS wpas_wps_update_config(wpa_s); #endif /* CONFIG_WPS */ diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 341d84156..f88120a8d 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -1445,6 +1445,9 @@ int wpas_beacon_rep_scan_process(struct wpa_supplicant *wpa_s, void wpas_clear_beacon_rep_data(struct wpa_supplicant *wpa_s); void wpas_flush_fils_hlp_req(struct wpa_supplicant *wpa_s); void wpas_clear_disabled_interface(void *eloop_ctx, void *timeout_ctx); +#ifdef CONFIG_BGSCAN +void wpa_supplicant_reset_bgscan(struct wpa_supplicant *wpa_s); +#endif /* CONFIG_BGSCAN */ /* MBO functions */