Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1177850pxx; Tue, 27 Oct 2020 10:01:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEiyEue+Bn0qruqSNoAehrq8SRpMqJ9pR6v/lb8LpBvKnSBa8nQZS38odf7PK2gkqk+cmi X-Received: by 2002:a17:906:b293:: with SMTP id q19mr3279323ejz.13.1603818079860; Tue, 27 Oct 2020 10:01:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603818079; cv=none; d=google.com; s=arc-20160816; b=LpPfs3UR9BzkBF+mEpuv7TyhLw4enT0uWx+ACKCzFbdoHGkdKEHGYthFhZtYAVQe8A bl+/TxNxjWqwc/LvUW4Af7CmRlKV5ySUeuY/8FzAZMkmTGQQLtRI1UiR9WggatTrXyWE HUBnE3si4xqe74O7ul6scbEAU4XLC/F53BV4HmHi9QlvnaX35XWmQrcyPHCe2hMEaPwu hty2t13q/phoWhcQ6+lVj9EZIHdTaJ9L5h17F+wt//PWz0Y4kYrq0yEkMKbH5OTaaQhL h49Dgqs5dI1dbcW9YDQruYm52LHuObL9lS2N33LnZ8no8rgErxHsmV9gQbn5mhP62C05 yk3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=1ke5nGbA4clAxIjt0JUhDX3ZTydTBVBs4rEWy4zdTpU=; b=Oc9UNzixpqlL9+N06omXAr/H22ePmM+VWEGc2Jh8bS4844w74USNZWlIY41m/kHoXe TnFL4rHgv+BlNn/Y2FL38Nh0fAhCsloohfAF5epBiQD4jYxulbAJ2TxXqbX9Y45kjABC PowCYklgyn3um899Jp0liVy5tz4Y/bOzfCVGWFtWYpDfvQuNUwvwDox52gUfxg+eYOel cbYDRbI6Vth5lLW3+vg7L4zMwhd3Ou7nVbUHqfHmgWjtNDHjInazQEy3UvqTy4NxDWMm kFm7gY8h8yWzWiWHmYbDdZ4AJQZHq7HiguVXvEt/JuUI85yDybBEjUEeqsz5ZkhvpI7b dfug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=K5xdihYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q18si1244487edb.466.2020.10.27.10.00.57; Tue, 27 Oct 2020 10:01:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=K5xdihYB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1806378AbgJ0QGI (ORCPT + 99 others); Tue, 27 Oct 2020 12:06:08 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:35314 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1802508AbgJ0Ptv (ORCPT ); Tue, 27 Oct 2020 11:49:51 -0400 Received: by mail-lj1-f195.google.com with SMTP id x16so2349271ljh.2 for ; Tue, 27 Oct 2020 08:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1ke5nGbA4clAxIjt0JUhDX3ZTydTBVBs4rEWy4zdTpU=; b=K5xdihYBzdmUdNJQ2LLnUYlVrlt+QfwqeoklnM2hogn92aLb8d3vyflsafRufchaeZ CA7MOtlZBygfC8YYTcXvdHyg3H4Uc9aYpFEVh+8Gj/tAroF4BtXrBxUvz4AM/8XZlHHA Zmb9DdL4GELqH5gfrCkRyujlf/GGo8woHmmRa9QWuuIUUJbP+wQZyR9yMlFiys4T0i8A 4hN2ipTGzA2WV6CzmbUbf/8AhBTplnO3NMNTMqFlNqilp4nIaexXKzqov+8pb8EnVwqb 9imjsPRhep6QFj4/KoNQX9Y8gqUEJUh+gRwDUdG+SKp336qZzHh2M2GTo/x8mSQca1p+ KX+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1ke5nGbA4clAxIjt0JUhDX3ZTydTBVBs4rEWy4zdTpU=; b=W72kq8irBP05oaGJ4gqivvFBGQnxlQAIyfePFChsKdXKYlGD65AXTVgovZDQ/QeF8y rVTr2KaY2U6terMUvcsKQ8gvxwwYKqcIrDDftvXoBpl2oJVJaryg/HdIzQdr0WFduV8N A3R3AH0mXdyVr4vLErC6Xa5XMlgAn7oqw/Fm2wFnd8hZ6PYgX/1H0VGIayx+notxiM2S yt1DBpNKSak/dyvE0J1rIRCk8YSpLzhJ6ef3G7iR6fi7bL+k/Vl8qsNCDruCLtOgaf+Q HAFgb6fmR6TBI4yWQS6YHzVKOogGZRUOzOVFFSnuqyhJ+jNOXrTZO9elz4F6tKjNK3j7 oaOw== X-Gm-Message-State: AOAM533dMzb7+PvPCTljPWt7yd6OGdO2Y/dIBLp/ejmDybUh+ZQgI8L/ rqhBSa+0INTt70TIbxhVpi0Ie2vrNXkpapiZXrwczw== X-Received: by 2002:a2e:351a:: with SMTP id z26mr1407846ljz.3.1603813786899; Tue, 27 Oct 2020 08:49:46 -0700 (PDT) MIME-Version: 1.0 References: <20200929080324.632523-1-tientzu@chromium.org> In-Reply-To: From: Alain Michaud Date: Tue, 27 Oct 2020 11:49:35 -0400 Message-ID: Subject: Re: [PATCH v2] Bluetooth: Move force_bredr_smp debugfs into hci_debugfs_create_bredr To: Claire Chang Cc: Marcel Holtmann , Johan Hedberg , "David S. Miller" , Jakub Kicinski , netdev , BlueZ , lkml Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Friendly ping and adding my review-by tag. On Wed, Oct 7, 2020 at 12:38 AM Claire Chang wrote: > > Hi, > > This patch is to fix the kernel error > [ 46.271811] debugfs: File 'force_bredr_smp' in directory 'hci0' > already present! > > When powering off and on the bluetooth, the smp_register will try to create the > force_bredr_smp entry again. > Move the creation to hci_debugfs_create_bredr so the force_bredr_smp entry will > only be created when HCI_SETUP and HCI_CONFIG are not set. > > Thanks, > Claire > > On Tue, Sep 29, 2020 at 4:03 PM Claire Chang wrote: > > > > Avoid multiple attempts to create the debugfs entry, force_bredr_smp, > > by moving it from the SMP registration to the BR/EDR controller init > > section. hci_debugfs_create_bredr is only called when HCI_SETUP and > > HCI_CONFIG is not set. > > > > Signed-off-by: Claire Chang Reviewed-by: Alain Michaud > > --- > > v2: correct a typo in commit message > > > > net/bluetooth/hci_debugfs.c | 50 +++++++++++++++++++++++++++++++++++++ > > net/bluetooth/smp.c | 44 ++------------------------------ > > net/bluetooth/smp.h | 2 ++ > > 3 files changed, 54 insertions(+), 42 deletions(-) > > > > diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c > > index 5e8af2658e44..4626e0289a97 100644 > > --- a/net/bluetooth/hci_debugfs.c > > +++ b/net/bluetooth/hci_debugfs.c > > @@ -494,6 +494,45 @@ static int auto_accept_delay_get(void *data, u64 *val) > > DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get, > > auto_accept_delay_set, "%llu\n"); > > > > +static ssize_t force_bredr_smp_read(struct file *file, > > + char __user *user_buf, > > + size_t count, loff_t *ppos) > > +{ > > + struct hci_dev *hdev = file->private_data; > > + char buf[3]; > > + > > + buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP) ? 'Y' : 'N'; > > + buf[1] = '\n'; > > + buf[2] = '\0'; > > + return simple_read_from_buffer(user_buf, count, ppos, buf, 2); > > +} > > + > > +static ssize_t force_bredr_smp_write(struct file *file, > > + const char __user *user_buf, > > + size_t count, loff_t *ppos) > > +{ > > + struct hci_dev *hdev = file->private_data; > > + bool enable; > > + int err; > > + > > + err = kstrtobool_from_user(user_buf, count, &enable); > > + if (err) > > + return err; > > + > > + err = smp_force_bredr(hdev, enable); > > + if (err) > > + return err; > > + > > + return count; > > +} > > + > > +static const struct file_operations force_bredr_smp_fops = { > > + .open = simple_open, > > + .read = force_bredr_smp_read, > > + .write = force_bredr_smp_write, > > + .llseek = default_llseek, > > +}; > > + > > static int idle_timeout_set(void *data, u64 val) > > { > > struct hci_dev *hdev = data; > > @@ -589,6 +628,17 @@ void hci_debugfs_create_bredr(struct hci_dev *hdev) > > debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev, > > &voice_setting_fops); > > > > + /* If the controller does not support BR/EDR Secure Connections > > + * feature, then the BR/EDR SMP channel shall not be present. > > + * > > + * To test this with Bluetooth 4.0 controllers, create a debugfs > > + * switch that allows forcing BR/EDR SMP support and accepting > > + * cross-transport pairing on non-AES encrypted connections. > > + */ > > + if (!lmp_sc_capable(hdev)) > > + debugfs_create_file("force_bredr_smp", 0644, hdev->debugfs, > > + hdev, &force_bredr_smp_fops); > > + > > if (lmp_ssp_capable(hdev)) { > > debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs, > > hdev, &ssp_debug_mode_fops); > > diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c > > index 433227f96c73..8b817e4358fd 100644 > > --- a/net/bluetooth/smp.c > > +++ b/net/bluetooth/smp.c > > @@ -3353,31 +3353,8 @@ static void smp_del_chan(struct l2cap_chan *chan) > > l2cap_chan_put(chan); > > } > > > > -static ssize_t force_bredr_smp_read(struct file *file, > > - char __user *user_buf, > > - size_t count, loff_t *ppos) > > +int smp_force_bredr(struct hci_dev *hdev, bool enable) > > { > > - struct hci_dev *hdev = file->private_data; > > - char buf[3]; > > - > > - buf[0] = hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP) ? 'Y': 'N'; > > - buf[1] = '\n'; > > - buf[2] = '\0'; > > - return simple_read_from_buffer(user_buf, count, ppos, buf, 2); > > -} > > - > > -static ssize_t force_bredr_smp_write(struct file *file, > > - const char __user *user_buf, > > - size_t count, loff_t *ppos) > > -{ > > - struct hci_dev *hdev = file->private_data; > > - bool enable; > > - int err; > > - > > - err = kstrtobool_from_user(user_buf, count, &enable); > > - if (err) > > - return err; > > - > > if (enable == hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP)) > > return -EALREADY; > > > > @@ -3399,16 +3376,9 @@ static ssize_t force_bredr_smp_write(struct file *file, > > > > hci_dev_change_flag(hdev, HCI_FORCE_BREDR_SMP); > > > > - return count; > > + return 0; > > } > > > > -static const struct file_operations force_bredr_smp_fops = { > > - .open = simple_open, > > - .read = force_bredr_smp_read, > > - .write = force_bredr_smp_write, > > - .llseek = default_llseek, > > -}; > > - > > int smp_register(struct hci_dev *hdev) > > { > > struct l2cap_chan *chan; > > @@ -3433,17 +3403,7 @@ int smp_register(struct hci_dev *hdev) > > > > hdev->smp_data = chan; > > > > - /* If the controller does not support BR/EDR Secure Connections > > - * feature, then the BR/EDR SMP channel shall not be present. > > - * > > - * To test this with Bluetooth 4.0 controllers, create a debugfs > > - * switch that allows forcing BR/EDR SMP support and accepting > > - * cross-transport pairing on non-AES encrypted connections. > > - */ > > if (!lmp_sc_capable(hdev)) { > > - debugfs_create_file("force_bredr_smp", 0644, hdev->debugfs, > > - hdev, &force_bredr_smp_fops); > > - > > /* Flag can be already set here (due to power toggle) */ > > if (!hci_dev_test_flag(hdev, HCI_FORCE_BREDR_SMP)) > > return 0; > > diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h > > index 121edadd5f8d..fc35a8bf358e 100644 > > --- a/net/bluetooth/smp.h > > +++ b/net/bluetooth/smp.h > > @@ -193,6 +193,8 @@ bool smp_irk_matches(struct hci_dev *hdev, const u8 irk[16], > > int smp_generate_rpa(struct hci_dev *hdev, const u8 irk[16], bdaddr_t *rpa); > > int smp_generate_oob(struct hci_dev *hdev, u8 hash[16], u8 rand[16]); > > > > +int smp_force_bredr(struct hci_dev *hdev, bool enable); > > + > > int smp_register(struct hci_dev *hdev); > > void smp_unregister(struct hci_dev *hdev); > > > > -- > > 2.28.0.618.gf4bc123cb7-goog > >