Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1233083pxu; Fri, 16 Oct 2020 07:13:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQViDbKir11EUrEkhYK4MxVVWhLFqwQLfA5wTuaOXRIPVb/raWDjYQTD4Fm9/gnIPtY4T5 X-Received: by 2002:a05:6402:2292:: with SMTP id cw18mr4335851edb.112.1602857597679; Fri, 16 Oct 2020 07:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602857597; cv=none; d=google.com; s=arc-20160816; b=jQE4cIOUihI2rQUvUNhOZi4+XlSHVVWzxmIPcGBdQ1xOQZIgbuDdJ6jG7fzVjVtDPi 2ON4Iih8P0yaR2TcSKF1R8EHH92ndog42ymvtw5kSteG+FtV2i0wzGD4q695IPgQ74xZ FryEGEz7ee0X6vG9XqsGasMtUtWR8F57FpdToRVbrgQKY6e3u6+qN+31u0b4epwYx0h9 CcyrDfcHEAt6XAD6bd4jNN5+eIzGG+AcVy6Vgx4keUrUChpf/4LGZCYNU+RFEGh5mPJE y6pS/MbSBqvH3vbMA8m80ot0zPfSbkUqyEDEfXDYNRLLBMgUXG1M16i3Nwmvs4AXXcJP CaIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fhdj5DewE9w1CIXh191Jm29445zjxcphQarOzQ1J9p4=; b=Xrvfjg0LOOVOi3zOHr2R0fU/fguraWbL62SFxtTuQgBLaGQc8ao4m5v7oOqdOEW8r4 EJHU9/5NLaaijbFrC2loaU5l3GsVGfwZMmbtyrB1OFMKMNaA1nhUjhbwSgA1R/z+VjBH wK/kEpdHeoxBN+cHmb++E/nUf6KradBlT7VBx6LChNd21esnL/1/qI53VR7VwiE2u49p cHt5hMQt0c0/OICprI7yXOeylDpGa2eX4ekyQRJx5+qKTSRZroBr/uV17fEbq6Pbuscg iTSZAyXuknELtK43y2ET2M96oRlEKSsIrs0KiFMhFIRrqXG5chZ4SU3lTzMaC9/UvYhG 11/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pTwfXxzo; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q30si1847483edb.278.2020.10.16.07.12.54; Fri, 16 Oct 2020 07:13:17 -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=@kernel.org header.s=default header.b=pTwfXxzo; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406138AbgJPJPP (ORCPT + 99 others); Fri, 16 Oct 2020 05:15:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:38146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405087AbgJPJJ1 (ORCPT ); Fri, 16 Oct 2020 05:09:27 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BCABC20848; Fri, 16 Oct 2020 09:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839366; bh=60IszBw0AHzpThHVxQE6yYPaMEkQ7WNMgWk/4ICWN3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pTwfXxzo/5pdrQgD5fb3R3SxSXRuWJQZl0b85Q97TXZJ0SrdLxnOwzrfaeXuoG2iZ Vn/qcg5S63YRl8/gW4fyWy9kdjjB3IUHSyGSy/qk6ceXRMsR5ubuAqUFkqahw3vTvG gHLduIPmu9Kq+si3ykwqPZ6Q+g0AzBhb85wq/Jk0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luiz Augusto von Dentz , Marcel Holtmann , Hans-Christian Noren Egtvedt Subject: [PATCH 4.19 08/21] Bluetooth: Consolidate encryption handling in hci_encrypt_cfm Date: Fri, 16 Oct 2020 11:07:27 +0200 Message-Id: <20201016090437.716750153@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201016090437.301376476@linuxfoundation.org> References: <20201016090437.301376476@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Luiz Augusto von Dentz commit 3ca44c16b0dcc764b641ee4ac226909f5c421aa3 upstream. This makes hci_encrypt_cfm calls hci_connect_cfm in case the connection state is BT_CONFIG so callers don't have to check the state. Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Marcel Holtmann Cc: Hans-Christian Noren Egtvedt Signed-off-by: Greg Kroah-Hartman --- include/net/bluetooth/hci_core.h | 20 ++++++++++++++++++-- net/bluetooth/hci_event.c | 28 +++------------------------- 2 files changed, 21 insertions(+), 27 deletions(-) --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1287,10 +1287,26 @@ static inline void hci_auth_cfm(struct h conn->security_cfm_cb(conn, status); } -static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, - __u8 encrypt) +static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) { struct hci_cb *cb; + __u8 encrypt; + + if (conn->state == BT_CONFIG) { + if (status) + conn->state = BT_CONNECTED; + + hci_connect_cfm(conn, status); + hci_conn_drop(conn); + return; + } + + if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) + encrypt = 0x00; + else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) + encrypt = 0x02; + else + encrypt = 0x01; if (conn->sec_level == BT_SECURITY_SDP) conn->sec_level = BT_SECURITY_LOW; --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2756,7 +2756,7 @@ static void hci_auth_complete_evt(struct &cp); } else { clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); - hci_encrypt_cfm(conn, ev->status, 0x00); + hci_encrypt_cfm(conn, ev->status); } } @@ -2841,22 +2841,7 @@ static void read_enc_key_size_complete(s conn->enc_key_size = rp->key_size; } - if (conn->state == BT_CONFIG) { - conn->state = BT_CONNECTED; - hci_connect_cfm(conn, 0); - hci_conn_drop(conn); - } else { - u8 encrypt; - - if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) - encrypt = 0x00; - else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) - encrypt = 0x02; - else - encrypt = 0x01; - - hci_encrypt_cfm(conn, 0, encrypt); - } + hci_encrypt_cfm(conn, 0); unlock: hci_dev_unlock(hdev); @@ -2955,14 +2940,7 @@ static void hci_encrypt_change_evt(struc } notify: - if (conn->state == BT_CONFIG) { - if (!ev->status) - conn->state = BT_CONNECTED; - - hci_connect_cfm(conn, ev->status); - hci_conn_drop(conn); - } else - hci_encrypt_cfm(conn, ev->status, ev->encrypt); + hci_encrypt_cfm(conn, ev->status); unlock: hci_dev_unlock(hdev);