From patchwork Tue Dec 25 18:47:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jouni Malinen X-Patchwork-Id: 208115 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9BC5E2C00A8 for ; Wed, 26 Dec 2012 05:48:12 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C6BEE9C129; Tue, 25 Dec 2012 13:48:09 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bzrWTc--7ZCA; Tue, 25 Dec 2012 13:48:09 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id A09929C0CF; Tue, 25 Dec 2012 13:48:05 -0500 (EST) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id E76E09C127 for ; Tue, 25 Dec 2012 13:48:03 -0500 (EST) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oUS+wyKzjD8B for ; Tue, 25 Dec 2012 13:47:59 -0500 (EST) Received: from jmaline2.user.openhosting.com (kvm.w1.fi [128.177.28.162]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 34B649C125 for ; Tue, 25 Dec 2012 13:47:59 -0500 (EST) Received: from jm (91-157-45-116.elisa-laajakaista.fi [91.157.45.116]) (authenticated bits=0) by jmaline2.user.openhosting.com (8.13.8/8.13.8) with ESMTP id qBPIgOAC029114 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 25 Dec 2012 13:42:25 -0500 Received: by jm (sSMTP sendmail emulation); Tue, 25 Dec 2012 20:47:55 +0200 Date: Tue, 25 Dec 2012 20:47:55 +0200 From: Jouni Malinen To: hostap@lists.shmoo.com Subject: Re: [PATCHv2] bgscan_learn: Load BSS entries from current SSID only Message-ID: <20121225184755.GA14841@w1.fi> Mail-Followup-To: hostap@lists.shmoo.com References: <20120630135858.GA19284@w1.fi> <4FF17480.90006@tieto.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com On Mon, Jul 09, 2012 at 03:04:03PM +0300, Piotr.Nakraszewicz@tieto.com wrote: > bgscan_learn wrongly loads BSS entries from data file even if > we changed ESS we are connected to. To prevent that add SSID > parameter (stored as a hexdump) to data file and compare it with > current SSID before loading the entries. The patch itself was relatively okay (needed to check data->ssid->ssid != NULL and a small typo in a comment) and I was about to apply this. However, I was trying to figure out the case where there would be a case where this is needed and couldn't come up with any.. The bgscan learn data file is supposed to be pointing to a different file for each ssid block and as such, this type of per-SSID filtering is implicitly handled by wpa_supplicant restarting the bgscan module for each network. Why would this need to be handled with an explicit SSID information with the data file? Even though I did not apply this, the following patch shows the somewhat cleaned up version I was testing with. diff --git a/wpa_supplicant/bgscan_learn.c b/wpa_supplicant/bgscan_learn.c index 07d31e4..c9e6f57 100644 --- a/wpa_supplicant/bgscan_learn.c +++ b/wpa_supplicant/bgscan_learn.c @@ -151,6 +151,29 @@ static int bgscan_learn_load(struct bgscan_learn_data *data) bgscan_learn_add_neighbor(bss, addr); } + + if (os_strncmp(buf, "SSID ", 5) == 0) { + /* + * Check if current SSID is the same as the one stored + * in the data file. + */ + u8 ssid[MAX_SSID_LEN]; + char *start = buf + 5; + char *end = os_strstr(start, "\n"); + + if (data->ssid->ssid && + (!end || + end - start != (int) data->ssid->ssid_len * 2 || + hexstr2bin(start, ssid, data->ssid->ssid_len) || + os_memcmp(ssid, data->ssid->ssid, + data->ssid->ssid_len) != 0)) { + wpa_printf(MSG_INFO, "bgscan learn: " + "Different SSID in data file, " + "omitting BSS entries"); + fclose(f); + return 0; + } + } } fclose(f); @@ -162,6 +185,8 @@ static void bgscan_learn_save(struct bgscan_learn_data *data) { FILE *f; struct bgscan_learn_bss *bss; + char buf[2 * MAX_SSID_LEN + 5 + 2]; + char *pos; if (data->fname == NULL) return; @@ -174,6 +199,17 @@ static void bgscan_learn_save(struct bgscan_learn_data *data) return; fprintf(f, "wpa_supplicant-bgscan-learn\n"); + if (data->ssid->ssid) { + /* Store SSID as a hexdump */ + pos = buf; + os_memcpy(pos, "SSID ", 5); + pos += 5; + pos += wpa_snprintf_hex(pos, 2 * MAX_SSID_LEN + 1, + data->ssid->ssid, data->ssid->ssid_len); + os_memcpy(pos, "\n", 2); + fprintf(f, "%s", buf); + } + dl_list_for_each(bss, &data->bss, struct bgscan_learn_bss, list) { fprintf(f, "BSS " MACSTR " %d\n", MAC2STR(bss->bssid), bss->freq);