Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1040073pxu; Fri, 16 Oct 2020 02:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGJYj671QzatYbc7Xw5uuXnV5Wr9rObsZ2cAQWj+K8jjzfCYYsrHW+O+m0vL+SjdpapWCh X-Received: by 2002:a17:906:ad8a:: with SMTP id la10mr2687827ejb.176.1602839497025; Fri, 16 Oct 2020 02:11:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602839497; cv=none; d=google.com; s=arc-20160816; b=bNVRBM7e8CZpWPnf23aINORaC1jYVW/q8natkWN1NvcSI1e/kocD5+4lRljvTpVla2 bfLWJXPUXIFGcHAyGZ9VnVI7QOyzu3la9K0l9NuBoxes3o5Nv+/CAjJIximXrIZB1PIr YgHA3xU4KdyFdugCNyhZBtoVoa/EZMMzkrHmIsCld9aLbTtY/pDbiDMjp2vb1vGzwTw/ 2QI4OlHWhGsv1TYUDrhqj6CugQ8LBPiyIm1CR65hmaIEGLPi5AFEvXojxsNXY6CzSiDe J2XzLNcq84krrQz5/2mQMJpV4c0ySJJMa5K1pzJ7meFAAPvjgVZE4JH4mx570uu7z1c7 EkVg== 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=6DnhJ0YdX8++g5eCbOPJIqhbk1xy3iOlS9rcJo+zSaQ=; b=ZMjW//3Z3lV9XhQ9+CSHKi0tjweustj/572zgRw64eWmJIqGijcV89BEJKV6+wadyS cfjssOWiC60ydWKDn62+X0K1EY7y3E7OYlelwKDuOFPY/aqmfU6v1J64uG2zaNnGsXBz 6d2GBkKCRXjohues0z668QuKOMu2znj5WBuYLlDEZr2CwNRRgECMJRQBjMEY+FdfV1qc G6bjhKLwE6kYZpcU9aFknqHllACMaP60LfMiOVRjGv3NVs0H9KtjoXuBtxuVvSzYW/9S Zyo8CbTVpjJ+pFsHt1Z/5raYLS57WfE2hGoJlfl9cA//h0GPVnCsBrKbGxyM2calK0Or 00MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KdidQVfy; 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 o14si1237657edq.11.2020.10.16.02.11.14; Fri, 16 Oct 2020 02:11:37 -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=KdidQVfy; 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 S2405509AbgJPJId (ORCPT + 99 others); Fri, 16 Oct 2020 05:08:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:36388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405432AbgJPJH7 (ORCPT ); Fri, 16 Oct 2020 05:07:59 -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 BBEF020878; Fri, 16 Oct 2020 09:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602839278; bh=l9/SGTMiQugaQ5fuHul/OLB4H+3idCzaNqgv/U1nTlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KdidQVfyIMMc7zuBdrlJq40KjAJSFw9E6Sp2IKQ7Sw8+ws+SBW1jSqXzjZoDDNf8x py43rkqedB24svypiWMILi+gn53V/Iwi4ACt/gOKbLa/wkZXj7CUpuJZj8KCxA9rgj fXs6SQ+rOAV+OJLqK/JX9CS05thP7k9g7ljHxtvk= 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.9 05/16] Bluetooth: Consolidate encryption handling in hci_encrypt_cfm Date: Fri, 16 Oct 2020 11:07:09 +0200 Message-Id: <20201016090437.484876100@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201016090437.205626543@linuxfoundation.org> References: <20201016090437.205626543@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 @@ -1250,10 +1250,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 @@ -2493,7 +2493,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); } } @@ -2579,22 +2579,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); @@ -2691,14 +2676,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);