From patchwork Thu Mar 12 10:07:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sathish Narasimman X-Patchwork-Id: 11433757 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF1A3913 for ; Thu, 12 Mar 2020 10:06:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A49A72072F for ; Thu, 12 Mar 2020 10:06:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jdQTkCBG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726718AbgCLKGv (ORCPT ); Thu, 12 Mar 2020 06:06:51 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43596 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbgCLKGv (ORCPT ); Thu, 12 Mar 2020 06:06:51 -0400 Received: by mail-pg1-f194.google.com with SMTP id u12so2825019pgb.10 for ; Thu, 12 Mar 2020 03:06:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3YDtsZFvd+LPTd0Sd0anKk1uRn89slB36yxlIFn11go=; b=jdQTkCBGhoVnBa+vbD/hrrTmZNBq1rDe3VTL/ZHKxOrp7gykKpuEvh6XGyY7e4gS6L Umj0OHpaCI6rN7RkOMoe1Boi9I7cTesnDsN7R7OS8orNIvh5dbGo262/4q2U1t46qOJM gLkHyNnu+u4ZoTVN1PVCpJPzMPTrmRFNxC20wEXdpLtELx6JPhe+g/83qgvAH+XzVqM+ nNhGCGKxDoqb81CFWqQpR+dwtTFNc8AU5AVN9AQaCyN6SdwrCVozDSf0RRcboggcZTkM YpDM30x8hMR0CtzRPiEq1cHFuQ0D4vhiVqoMP9Hu/8omS/38GXTPCHmbgyBNzUp0CsI4 0fUw== 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; bh=3YDtsZFvd+LPTd0Sd0anKk1uRn89slB36yxlIFn11go=; b=huHvNJLUAxwPPijEVEfmzvAUyFiR2foQ1EcnQVw37c5lPiJ/8prFn9ioBm3+D/uioN u4PZv8Pghsa0siPo54nrIcBPHuBYojCi0ueyCFgdFZqPn8mnPPiIPTTCe/KWeTTXP9sj IuyR2Yl3fd1aYYIEEAy0rtjwzvg67DrG6ieTVCzML6kODmdQUv7AEzA0hZN5+d9Hwc2T 2SEeTHyq8X8GjRe51Y055DlNGsmroFbBua8ONJ6/JhBmeAQPTe2kgsdxgAGvaP7TT9xX xYLkEICV1bHbrw1TQwcfUAlf71rvaFQK5w5ynE+O9VMfRbdBokP1geAvZzenD2ueVrqt 3eEw== X-Gm-Message-State: ANhLgQ1vT9qQXPilZEGsElMHtxIZpYY4C+wJu76WsvZdZVX3mtVSt44f 0B1JIrFgVoQXbJkRyh/4vFPSfcOuLu8= X-Google-Smtp-Source: ADFU+vvmKGDrp+ae0vMf7DCodYgnQUqJG/NrbYg5fiJZ1d91al3ZYbg1eTuvL04mZVaRmGTSYIr1iw== X-Received: by 2002:a63:4912:: with SMTP id w18mr6865770pga.122.1584007609629; Thu, 12 Mar 2020 03:06:49 -0700 (PDT) Received: from nsathish-Latitude-7480.iind.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id e9sm10578295pfl.179.2020.03.12.03.06.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:06:48 -0700 (PDT) From: Sathish Narsimman X-Google-Original-From: Sathish Narsimman To: linux-bluetooth@vger.kernel.org, nsathish41@gmail.com Cc: chethan.tumkur.narayan@intel.com, Sathish Narsimman Subject: [PATCH 1/7] Bluetooth: LL Privacy Delete Store Resolving list Date: Thu, 12 Mar 2020 15:37:48 +0530 Message-Id: <20200312100754.3445-2-sathish.narasimman@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312100754.3445-1-sathish.narasimman@intel.com> References: <20200312100754.3445-1-sathish.narasimman@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch help to delte the resolving list stored in the BT Controller w.r.t BD_ADDR. Signed-off-by: Sathish Narsimman --- include/net/bluetooth/hci.h | 1 + include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_request.c | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 5f60e135aeb6..352bc43940ff 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -457,6 +457,7 @@ enum { #define HCI_LE_DATA_LEN_EXT 0x20 #define HCI_LE_PHY_2M 0x01 #define HCI_LE_PHY_CODED 0x08 +#define HCI_LE_LL_PRIVACY 0x40 #define HCI_LE_EXT_ADV 0x10 #define HCI_LE_EXT_SCAN_POLICY 0x80 #define HCI_LE_PHY_2M 0x01 diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index d4e28773d378..5f04ef88da35 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand, void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *bdaddr_type); +void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, + bdaddr_t *bdaddr); #define SCO_AIRMODE_MASK 0x0003 #define SCO_AIRMODE_CVSD 0x0000 diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index bf83179ab9d1..f4bbd3b79210 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -885,6 +885,39 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, } } +void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr) +{ + struct hci_cp_le_del_from_resolv_list cp; + struct hci_request req; + struct bdaddr_list_with_irk *irk; + + BT_DBG(""); + + /* Nothing to be done if LL privacy is not supported */ + if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) ) + return; + + if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && + ( hci_dev_test_flag(hdev, HCI_LE_ADV) || + hci_dev_test_flag(hdev, HCI_LE_SCAN) || + hci_lookup_le_connect(hdev) ) ) + return; + + /* If the device is not present in resolving list + * no need to send HCI command. + */ + irk = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, addr_type); + if (!irk) + return; + + hci_req_init(&req, hdev); + cp.bdaddr_type = addr_type; + bacpy(&cp.bdaddr, bdaddr); + + hci_req_add(&req, HCI_OP_LE_DEL_FROM_RESOLV_LIST, sizeof(cp), &cp); + hci_req_run(&req, NULL); +} + void hci_req_add_le_passive_scan(struct hci_request *req) { struct hci_dev *hdev = req->hdev; From patchwork Thu Mar 12 10:07:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sathish Narasimman X-Patchwork-Id: 11433759 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B2A590 for ; Thu, 12 Mar 2020 10:07:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71D6720736 for ; Thu, 12 Mar 2020 10:07:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kYWu85IZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbgCLKHA (ORCPT ); Thu, 12 Mar 2020 06:07:00 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37178 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgCLKG7 (ORCPT ); Thu, 12 Mar 2020 06:06:59 -0400 Received: by mail-pf1-f194.google.com with SMTP id p14so3031851pfn.4 for ; Thu, 12 Mar 2020 03:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LFsJl0Fn403l1TnT4AByOXtpFE82PM3y4xKf+BP4gC4=; b=kYWu85IZ3wezV2aKjpDgATgwJoYU6h7YZi2pHlfyOBVZb4INymOQqbIgSw5d2jiJld ug41k/yz9d06tGhRSaOA+8UPYNVpKCooxbI4BB6HKCdHDm0+3S4gpnECqwAyG1k4NekT ItoU/6jFv4qWFQNpYPDR20X17JBIzIPOp9xUR8QqysDgRB2rEzdbnIk76WZDoJMJRFML lECctTOA3ksG50cfwcELsD0DTgqFWAE819e9r8FwOl8DcgIszWZNrANf0egdx0WgpnFx hOQ53nbEs5/Z2mdlwmkjcIaD2EiyoX5U+aJV0YEslFyDQnoB6eI5eaGMgNqKTDyVWXpc KSmQ== 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; bh=LFsJl0Fn403l1TnT4AByOXtpFE82PM3y4xKf+BP4gC4=; b=pvN121UofxoAeu1IiXXSEfCLJC3N0DOphZ/F8jlen9VjSOX/Z8q3W8u0uBPPqjmjVC MDDqBQL0F2N4wQkzB4QUUjAP3jNWi8E2iy/Hb6/ftoPXd5mcFZ+OLIDl7ng6LgSYbGEC X9pRIjxlgG+Tkp2Mwj6jdKx5KNBzRPbmajetPy/BLG8U8SqWhQGTMvITyEQmEMMm0UXL H5A4NUWo50Gic/2/dl6EPzrxV1Bmki6/psxXOLue3CbT49EjlNEPABMjxLXnAM1d5o0G B1QgKukZuIEMqQVcz2AaARooyxkc2N3aaSsnYHwMUrfxEGVfx2Az0vYEZO0ZsS6dkzQt /Z7g== X-Gm-Message-State: ANhLgQ15J3PMdelj9fSBCZXFKNR76sYJNVAtrVmmxGhPrmzL6UUJThAg SoPaTBZtNbBoBG/fKWc8Isk4dGMm7+BcFA== X-Google-Smtp-Source: ADFU+vusA1Ca7e6IQkcP8kqJslycwEuqLzA3UKVnc3EUViTFXldhQxK013iDjLsxcA9pIUskyt0LTQ== X-Received: by 2002:a62:aa17:: with SMTP id e23mr7527949pff.45.1584007616590; Thu, 12 Mar 2020 03:06:56 -0700 (PDT) Received: from nsathish-Latitude-7480.iind.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id e9sm10578295pfl.179.2020.03.12.03.06.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:06:56 -0700 (PDT) From: Sathish Narsimman X-Google-Original-From: Sathish Narsimman To: linux-bluetooth@vger.kernel.org, nsathish41@gmail.com Cc: chethan.tumkur.narayan@intel.com, Sathish Narsimman , Joy Shermin Subject: [PATCH 2/7] Bluetooth: Add device to Resolving List Date: Thu, 12 Mar 2020 15:37:49 +0530 Message-Id: <20200312100754.3445-3-sathish.narasimman@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312100754.3445-1-sathish.narasimman@intel.com> References: <20200312100754.3445-1-sathish.narasimman@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The Patch is used to add the device to resolving list. The patch will look for the local IRK list and if the device is present in the local resolving list it will be updated and the same updated w.r.t to BT controller by first deleting the existing and adding the new IRK w.r.t bd_addr. Signed-off-by: Sathish Narsimman Signed-off-by: Joy Shermin --- include/net/bluetooth/hci_core.h | 2 + net/bluetooth/hci_request.c | 80 ++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 5f04ef88da35..e5e09d530ce7 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1657,6 +1657,8 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand, void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *bdaddr_type); +int hci_req_update_resolving_list(struct hci_dev *hdev, u8 addr_type, + bdaddr_t *bdaddr, u8 irk[16]); void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr); diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index f4bbd3b79210..88225a9ca1f8 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -885,6 +885,86 @@ static void hci_req_start_scan(struct hci_request *req, u8 type, u16 interval, } } +int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, + u8 irk_val[16]) +{ + struct hci_request req; + struct hci_cp_le_add_to_resolv_list cp; + struct bdaddr_list_with_irk *irk; + u8 entries; + + BT_DBG(""); + + /* Nothing to be done if LL privacy is not supported */ + if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) ) + return -EPROTONOSUPPORT; + + /* Resolving List cannot be updated if address resolution + * in the controller is enabled and advertisement or scanning + * or create connection command is ongoing. + */ + if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && + ( hci_dev_test_flag(hdev, HCI_LE_ADV) || + hci_dev_test_flag(hdev, HCI_LE_SCAN) || + hci_lookup_le_connect(hdev) ) ) + return -EINVAL; + + hci_req_init(&req, hdev); + + irk = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, type); + if (irk) { + /* Device is present in resolving list.*/ + if (memcmp(irk->peer_irk, irk_val, 16) == 0) { + /* Device present in resolving list with same IRK. + * No HCI communication is required.Sort the + * Kernel list. + */ + hci_bdaddr_list_add_with_irk(&irk->list, bdaddr, type, irk_val, NULL); + return 0; + + } + /* IRK has changed for the device in resolving list + * Queue up commands to delete the existing entry and + * add new one. Sorting will be done when command complete + * for add command is receieved. + */ + goto remote; + } + /* Device is not present in resolving list.If resolving list + * is not full add the device to resolving list. + */ + entries = 0; + list_for_each_entry(irk, &hdev->le_resolv_list, list) { + entries++; + } + + if (entries < hdev->le_resolv_list_size) + goto add; + + /* If the resolving list is full, queue up HCI command to delete + * the entry that was used least recently to make space for the + * new device. Kernel list will be updated when command complete + * is received. + */ + irk = list_first_entry_or_null(&hdev->le_resolv_list, struct bdaddr_list_with_irk, list); + + if (!irk) + return -1; + +remote: + hci_req_del_from_resolving_list(hdev, irk->bdaddr_type, &irk->bdaddr); + +add: + cp.bdaddr_type = type; + bacpy(&cp.bdaddr, bdaddr); + memcpy(cp.peer_irk, irk_val, 16); + memcpy(cp.local_irk, hdev->irk, 16); + + hci_req_add(&req, HCI_OP_LE_ADD_TO_RESOLV_LIST, sizeof(cp), &cp); + hci_req_run(&req, NULL); + return 0; +} + void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr) { struct hci_cp_le_del_from_resolv_list cp; From patchwork Thu Mar 12 10:07:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sathish Narasimman X-Patchwork-Id: 11433761 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92C8D90 for ; Thu, 12 Mar 2020 10:07:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7963520736 for ; Thu, 12 Mar 2020 10:07:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rm0JKmK3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbgCLKHC (ORCPT ); Thu, 12 Mar 2020 06:07:02 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:37957 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgCLKHC (ORCPT ); Thu, 12 Mar 2020 06:07:02 -0400 Received: by mail-pf1-f194.google.com with SMTP id z5so3029445pfn.5 for ; Thu, 12 Mar 2020 03:07:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y8MluMm6f37XTe3y61evZ3K/RFwbeZ1K+tfhSmXkmKU=; b=rm0JKmK3M9l2ShN5Rm8hIF7crWT2uzhqAbDpxufwiAgbh1CYUcivvSY/Nceab+uNgK qGWeDnK4GF2/aySFt4k+uJz3BeNhcC9kaMaL4XHUWGlrxwSZc9oF4lk0oPPBD+OMfMeO iFZbZJGPnosn7TiUdSNzabAt9sdCAAME/8NtzlxIiyZJXImW6nap7omgnQWlob0A9XTC qIiPxIr2kImMYbc5OSed3ldtMMiJWiU31DVNGR0canN9M8WiiuFBGbPA/LfVRjaHT0Rm VNIMOTDtNG7692PFC544J4JZpUO++CpYf8MPha7zkt9nuezRYUEbYrPYUp/xOcQUDKiu AJvw== 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; bh=y8MluMm6f37XTe3y61evZ3K/RFwbeZ1K+tfhSmXkmKU=; b=buBzRKicmAYpUz+HE78frQXN9HxxK8houDbSRCv+x8s1A9xK+luW+sMdx/PG3wNNY1 cRSDrW1uRE3OiiiPUq2o/6/SQneYzgURPYZizD2RpHoa4ew1i8VgXxbOukF5O2E0vxna F2aAYp0MfMa36/tNyRo2PUF2ycd6ug48rYi/k7W6iy5+S16NzwjGFhP6+USGW6lAmzne TKXJeRSJXZzkrz/o6v6BgFAH/3q+xwExTdER6UlmFv1Q352F+o58xZJG6xPaobHcfv2G QQfj7m/xKsEswr076apW8v825R800Qj+UOZd5QS7i7z7D6D8lbreC1NWFChikFnxctII dRRg== X-Gm-Message-State: ANhLgQ2UNCTPT0gR5vWSQ9wW9lzx0uQdkwUg6pmLEhHTUhz9ndStKTFX GUVCwuJPyKavgXeUI3Eg/yWDiNi3gDpupQ== X-Google-Smtp-Source: ADFU+vv2v0eV3wXPQmxJO73n9PC05yAbeZKT7Voy9YiXlRwLN+iRvj9kNi0SJjTDuzpepSMsrM2jAw== X-Received: by 2002:aa7:9888:: with SMTP id r8mr5294374pfl.293.1584007620683; Thu, 12 Mar 2020 03:07:00 -0700 (PDT) Received: from nsathish-Latitude-7480.iind.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id e9sm10578295pfl.179.2020.03.12.03.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:07:00 -0700 (PDT) From: Sathish Narsimman X-Google-Original-From: Sathish Narsimman To: linux-bluetooth@vger.kernel.org, nsathish41@gmail.com Cc: chethan.tumkur.narayan@intel.com, Sathish Narsimman , Joy Shermin Subject: [PATCH 3/7] Bluetooth: Update the Resolving list when Local IRK changed Date: Thu, 12 Mar 2020 15:37:50 +0530 Message-Id: <20200312100754.3445-4-sathish.narasimman@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312100754.3445-1-sathish.narasimman@intel.com> References: <20200312100754.3445-1-sathish.narasimman@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Whenever the Local IRK changes. i.e privacy mode is toggled this patch helps to change the IRK list in the bluetooth controller Signed-off-by: Sathish Narsimman Signed-off-by: Joy Shermin --- include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_request.c | 50 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index e5e09d530ce7..43d31a9339a6 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1659,6 +1659,8 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *bdaddr_type); int hci_req_update_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr, u8 irk[16]); +void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev); + void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr); diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 88225a9ca1f8..9ffb62178d24 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -965,6 +965,56 @@ int hci_req_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdadd return 0; } +void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev) +{ + struct bdaddr_list_with_irk *irk; + struct hci_request req; + + BT_DBG(""); + + /* Nothing to be done if LL privacy is not supported. */ + if (!(hdev->le_features[0] & HCI_LE_LL_PRIVACY)) + return; + + /* If resolving list is empty, nothing is to be done.*/ + if (list_empty(&hdev->le_resolv_list)) + return; + + /* Resolving List cannot be updated if address resolution + * in the controller is enabled and advertisement or scanning + * or create connection command is ongoing. + */ + if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && + ( hci_dev_test_flag(hdev, HCI_LE_ADV) || + hci_dev_test_flag(hdev, HCI_LE_SCAN) || + hci_lookup_le_connect(hdev) ) ) + return; + + /* If resolving list is not empty, then clear the resolving list + * and add back each entry with updated local IRK. + */ + hci_req_init(&req, hdev); + + list_for_each_entry(irk, &hdev->le_resolv_list, list) { + struct hci_cp_le_add_to_resolv_list cp; + struct hci_cp_le_del_from_resolv_list cp1; + + cp1.bdaddr_type = irk->bdaddr_type; + bacpy(&cp1.bdaddr, &irk->bdaddr); + hci_req_add(&req, HCI_OP_LE_DEL_FROM_RESOLV_LIST, + sizeof(cp1), &cp1); + + cp.bdaddr_type = irk->bdaddr_type; + bacpy(&cp.bdaddr, &irk->bdaddr); + memcpy(cp.peer_irk, irk->peer_irk, 16); + memcpy(cp.local_irk, hdev->irk, 16); + hci_req_add(&req, HCI_OP_LE_ADD_TO_RESOLV_LIST, + sizeof(cp), &cp); + } + + hci_req_run(&req, NULL); +} + void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr) { struct hci_cp_le_del_from_resolv_list cp; From patchwork Thu Mar 12 10:07:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sathish Narasimman X-Patchwork-Id: 11433763 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C613913 for ; Thu, 12 Mar 2020 10:07:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 831762072F for ; Thu, 12 Mar 2020 10:07:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KTxOM3hq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726784AbgCLKHG (ORCPT ); Thu, 12 Mar 2020 06:07:06 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43494 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgCLKHG (ORCPT ); Thu, 12 Mar 2020 06:07:06 -0400 Received: by mail-pf1-f194.google.com with SMTP id c144so3019450pfb.10 for ; Thu, 12 Mar 2020 03:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4zBwx/dz5Yma+kmqRs4Q3CZ2L+oCkvmiphJfnBmSHoc=; b=KTxOM3hqnqbjZqty/iuu7ACE4GoqjlVc3uOc53AEBD7EC1GP2rqCbVZ4dHRpxfGc+/ 9Pc/zYgwknjSJ+5/q+OsFURpaiJy9B+cI0GrQWvWzZdDQR/WR+VliiG7mLcUIjm5IRZL oHjbxdtHd1DW5SgZNe/B1FkQ64/I+ITonr42rgPJBM6P0/2m1diMSjuP3bsLAW6tA0xo mipBPjN66MMOwuY/oqrlZc2bzLEpThVqpHDYnXZnkOCyhVyTE0lzqMQek2vuIkrzNOsb XXtcB/APSOhj5O7e9v2sVXFYM8ZacwzwqAgbG/9v2c5x5EvMl5fs+PT8OIwUytJUtQ7o YRNg== 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; bh=4zBwx/dz5Yma+kmqRs4Q3CZ2L+oCkvmiphJfnBmSHoc=; b=UL0CkN/EDAECsZEE55Pv/ccJgh4gAEv/o0GfLwT5XuKoTo3Dp0jlSZMbY7QA+HuMSf frJc+ybp1FjMhIUriqwx1VuBmfxIdpF07dqV+cZQkp5ULt3OhZx2Rwy+Dr02TBYNRG4I WAg90ma4KVCw6eHC3BzvEPJFNcraE0bpJprEAS2XegkSWriTUV4uYqriVYD472aZs6qC PRLcLy9mWTXJVKZuZpoBFcnPw3AVyNqbYe9J0jURJu3KRv7sYx7yrtUeWWu4jQBrHtpW TSUBZ6oRanXW4N5pIAtwwHaD4OFouvgu7i8+CobBUXRaqxkvU1hjuOm41uxa+lydmPH1 3wbQ== X-Gm-Message-State: ANhLgQ35JTdYtke3YnLm0Bcx0lAYFMj9Cbw0R8Yr4uZzwx8PQyBHxchy NVKLIGFTTJYxUAjqDANfmcyESee7W+F9mQ== X-Google-Smtp-Source: ADFU+vtzhYpfTnXPkbszd76BTbtMinFozrX27uddzYcByBLxwux/YtJtJJp2fBmoi4Go0vqO7zPsrQ== X-Received: by 2002:aa7:9482:: with SMTP id z2mr2656007pfk.147.1584007624679; Thu, 12 Mar 2020 03:07:04 -0700 (PDT) Received: from nsathish-Latitude-7480.iind.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id e9sm10578295pfl.179.2020.03.12.03.07.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:07:04 -0700 (PDT) From: Sathish Narsimman X-Google-Original-From: Sathish Narsimman To: linux-bluetooth@vger.kernel.org, nsathish41@gmail.com Cc: chethan.tumkur.narayan@intel.com, Sathish Narsimman , Joy Shermin Subject: [PATCH 4/7] Bluetooth: LL_PRIVACY re-load resolving list Date: Thu, 12 Mar 2020 15:37:51 +0530 Message-Id: <20200312100754.3445-5-sathish.narasimman@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312100754.3445-1-sathish.narasimman@intel.com> References: <20200312100754.3445-1-sathish.narasimman@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The patch is used to load the entries in the local IRK to the Bluetooth LE controller resolving list. Signed-off-by: Sathish Narsimman Signed-off-by: Joy Shermin --- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_request.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 43d31a9339a6..46d2d3e10c97 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1659,6 +1659,7 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *bdaddr_type); int hci_req_update_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr, u8 irk[16]); +void hci_load_resolving_list(struct hci_dev *hdev); void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev); void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 9ffb62178d24..e17db3103a3d 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1015,6 +1015,35 @@ void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev) hci_req_run(&req, NULL); } +void hci_load_resolving_list (struct hci_dev *hdev) +{ + struct smp_irk *irk; + u8 num = 0; + + /* Nothing to be done if LL privacy is not supported */ + if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) ) + return; + + if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && + ( hci_dev_test_flag(hdev, HCI_LE_ADV) || + hci_dev_test_flag(hdev, HCI_LE_SCAN) || + hci_lookup_le_connect(hdev) ) ) + return; + + /* Load the first le_resolving_list_size entries from IRK + * list in to resolving list. + */ + rcu_read_lock(); + list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { + if (num++ >= hdev->le_resolv_list_size) + return; + + hci_req_update_resolving_list(hdev, irk->addr_type, &irk->bdaddr, irk->val); + } + + rcu_read_unlock(); +} + void hci_req_del_from_resolving_list(struct hci_dev *hdev, u8 addr_type, bdaddr_t *bdaddr) { struct hci_cp_le_del_from_resolv_list cp; From patchwork Thu Mar 12 10:07:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sathish Narasimman X-Patchwork-Id: 11433765 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5499390 for ; Thu, 12 Mar 2020 10:07:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A96320737 for ; Thu, 12 Mar 2020 10:07:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lGCg1l8E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726785AbgCLKHJ (ORCPT ); Thu, 12 Mar 2020 06:07:09 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42112 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgCLKHJ (ORCPT ); Thu, 12 Mar 2020 06:07:09 -0400 Received: by mail-pf1-f193.google.com with SMTP id x2so2658266pfn.9 for ; Thu, 12 Mar 2020 03:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/zcprjgIRbmIdLFXtpyP+sMyaGODDY39obss3o04Ujs=; b=lGCg1l8EBg3FnK7janYyZR33tAcvBofsxkcmuXPnjXxDAr7eOpaeUavXH42YKF2t7b hyW5q+So302Sr+cM8urfVaBRpey++QaQkNL3J9TmxACHU9g1iYf+CUMUHnWxpIHXkxeS tU39tLklJ3WLBN7y1wxpBSF3Lq70zb1ygBtXOXaGhSXZ72KVixCpErdY5H4MHjoGTCNh pEUA87bSvBILBWdjUvnNQsulNWwBBP42Zxr5YqLsgw2nW7wd3sAGDBP/Ky5AiDwYnyW9 gZ67XmGXQZgg42W8Laq03A/FZMFvwfmetnl7WnnryWqMQ7g6lE1MTVxisWLZcyoIcpn4 x1Ew== 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; bh=/zcprjgIRbmIdLFXtpyP+sMyaGODDY39obss3o04Ujs=; b=iKmuMvo3XypP+rzDtHpLlSH9G2utb9by2KPLdhIhIxq1ppa9tQ9Ebtvaxouag0WGWn GzXhA11JUfPxjkcts+ryNBQ1LAEU4Tvque7+ZA1dGmUn7KOj7zhYuLg6qqtwp7u0NK5c CXzkiROg8q0+U8/rO0IhEQ73uisu6OaLbtUbrCJxk8Xnc3qFGwsajdrYHc1kSBWjqtB6 iF0q/NDF6bHEh3KLuXu/TVyaa1ERmTvSU0YyCh3tzqY1ENASZmukEvFlyrRuky4raKKm O88ZCzcOfI6z1ftQ8blv++wttpunlDTG7OacoUN7WEt/QtOlIlqwiQ6Ot6UuFMdIbDHk DcUw== X-Gm-Message-State: ANhLgQ0TSyu7iX0cA98++v8Pz7mpePwmMKPSof5pf8HW4uWAtGyONOcL +CaaArvNF03bYhHgyxBd+57JuJUgLCjQFw== X-Google-Smtp-Source: ADFU+vvDFfeNTPobROmpH0Buk1XHlAlsGdrlK7bkMhEeZRIiTn1pwGXeJGDk/x/dI1H+3YTM1IHelg== X-Received: by 2002:a63:2cc3:: with SMTP id s186mr6866953pgs.71.1584007628485; Thu, 12 Mar 2020 03:07:08 -0700 (PDT) Received: from nsathish-Latitude-7480.iind.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id e9sm10578295pfl.179.2020.03.12.03.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:07:08 -0700 (PDT) From: Sathish Narsimman X-Google-Original-From: Sathish Narsimman To: linux-bluetooth@vger.kernel.org, nsathish41@gmail.com Cc: chethan.tumkur.narayan@intel.com, Sathish Narsimman , Joy Shermin Subject: [PATCH 5/7] Bluetooth: LL Privacy Check and Update the Resolving List Date: Thu, 12 Mar 2020 15:37:52 +0530 Message-Id: <20200312100754.3445-6-sathish.narasimman@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312100754.3445-1-sathish.narasimman@intel.com> References: <20200312100754.3445-1-sathish.narasimman@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch is an helper function which will be usefull to check the Local Resolving list and update the controller Resolving list during le_create_conn , le_directed_adv. Signed-off-by: Sathish Narsimman Signed-off-by: Joy Shermin --- net/bluetooth/hci_request.c | 21 +++++++++++++++++++++ net/bluetooth/hci_request.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index e17db3103a3d..6b685cdc7de5 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1015,6 +1015,27 @@ void hci_req_update_resolving_list_local_irk(struct hci_dev *hdev) hci_req_run(&req, NULL); } +void hci_req_check_and_update_resolving_list(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr) +{ + struct smp_irk *irk; + + BT_DBG(""); + + /* Nothing to be done if LL privacy is not supported */ + if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY) ) + return; + + if ( !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && + ( hci_dev_test_flag(hdev, HCI_LE_ADV) || + hci_dev_test_flag(hdev, HCI_LE_SCAN) || + hci_lookup_le_connect(hdev) ) ) + return; + + irk = hci_find_irk_by_addr(hdev, bdaddr, type); + if (irk) + hci_req_update_resolving_list(hdev, irk->addr_type, &irk->bdaddr, irk->val); +} + void hci_load_resolving_list (struct hci_dev *hdev) { struct smp_irk *irk; diff --git a/net/bluetooth/hci_request.h b/net/bluetooth/hci_request.h index 0e81614d235e..92a71f35543b 100644 --- a/net/bluetooth/hci_request.h +++ b/net/bluetooth/hci_request.h @@ -90,6 +90,8 @@ void __hci_req_clear_ext_adv_sets(struct hci_request *req); int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, bool use_rpa, struct adv_info *adv_instance, u8 *own_addr_type, bdaddr_t *rand_addr); +void hci_req_check_and_update_resolving_list(struct hci_dev *hdev, u8 addr_type, + bdaddr_t *bdaddr); void __hci_req_update_class(struct hci_request *req); From patchwork Thu Mar 12 10:07:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sathish Narasimman X-Patchwork-Id: 11433767 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6FBDE90 for ; Thu, 12 Mar 2020 10:07:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BABA20724 for ; Thu, 12 Mar 2020 10:07:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rKc2lh46" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726659AbgCLKHQ (ORCPT ); Thu, 12 Mar 2020 06:07:16 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44090 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgCLKHP (ORCPT ); Thu, 12 Mar 2020 06:07:15 -0400 Received: by mail-pl1-f193.google.com with SMTP id d9so2461159plo.11 for ; Thu, 12 Mar 2020 03:07:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rzhdRm2fp7f9hQ3db6A/lbeobDKzou7qkzpbeUmHsp8=; b=rKc2lh46NqRlbqvtCMIy6IZFSjzC/NNtw2DyYUbqNup8mg1mZrotVzwXMND0fqx0cj AkdJReJaXqVAk5s/ZXBW1gaXCWnbQye1VT8pXGAybfoPDQ+zxNBcDqxg64M2ABOFha05 usyOrqJ6NPOAgwuGzLP9Xh25N1lS0sHZxuxdDN9huTb/xdbFhnHKuc0sBiljttxYPUTW TnQ/BURI+eyV253Ea76daE9oCWL3HJ+w85uywI1yIGwp+BlQD136YEvj2YmANXkycw8d wwNBh4zKvUSAOFADKMNcxeFO8lhhDsS63GuQH7kdLNaSwJic+rG2FrbkZi1UnJhphauF HUdg== 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; bh=rzhdRm2fp7f9hQ3db6A/lbeobDKzou7qkzpbeUmHsp8=; b=ml7top9F4dAa5KICNtBfDmLJ6BcRpbGks9z0RNYhoE+jPEwC8yDWfzLhb+kqdSVYPd aBIc1vLPZe/RvvvkhiusMb6NiKEbOeF3WsyVYKyBP1QvUt+vYW3Vpobz4fEL2sePIGxb gODTeHQVvQGHVRcWBeRb6cf37y4SBoQxUOqFna3Hsssy3AsDksQyBNZFpglFwky00/NZ tRmAH/tcQnJ+kXilbfz6Jmx1/lms3LY7bQ4KPql8F1DaUXygy9fg04WgjjFjEVQ6rECF puU618vJ3cXN3Vpbqjbiwl3A9AYEbAFKWrqWUPpaFmoantQoPotWALk9DYPH13LVLSLA O+bQ== X-Gm-Message-State: ANhLgQ1Tr8XZEoq7UVvqUYTnPrtFITS298bxCGok6eEJw5z5DRiXbQEV lOxBgG4+sHn47yI5GgEJOatM5MQs0WT5Rg== X-Google-Smtp-Source: ADFU+vvVv2Q42csXG5ghBQyOGYuMlGi+A+kUhS6/TzRFimpMXRXKt7LWPrncMdRpZaq4tKlm2Z4krQ== X-Received: by 2002:a17:90a:1912:: with SMTP id 18mr3347856pjg.124.1584007631969; Thu, 12 Mar 2020 03:07:11 -0700 (PDT) Received: from nsathish-Latitude-7480.iind.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id e9sm10578295pfl.179.2020.03.12.03.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:07:11 -0700 (PDT) From: Sathish Narsimman X-Google-Original-From: Sathish Narsimman To: linux-bluetooth@vger.kernel.org, nsathish41@gmail.com Cc: chethan.tumkur.narayan@intel.com, Sathish Narsimman Subject: [PATCH 6/7] Bluetooth: Enable LL Privacy Date: Thu, 12 Mar 2020 15:37:53 +0530 Message-Id: <20200312100754.3445-7-sathish.narasimman@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312100754.3445-1-sathish.narasimman@intel.com> References: <20200312100754.3445-1-sathish.narasimman@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This enables Link Layer Privacy and sets RPA timeout to 900sec < HCI Command: LE Set Address Resolution Enable (0x08|0x002d) plen 1 Address resolution: Enabled (0x01) > HCI Event: Command Complete (0x0e) plen 4 LE Set Address Resolution Enable (0x08|0x002d) ncmd 1d Status: Success (0x00) < HCI Command: LE Set Resolvable Private Address Timeout (0x08|0x002e) plen 2 Timeout: 900 seconds > HCI Event: Command Complete (0x0e) plen 4 LE Set Resolvable Private Address Timeout (0x08|0x002e) ncmd 1 Status: Success (0x00) During Successfull pairing adding the information to device Resolving list < HCI Command: LE Add Device To Resolving List (0x08|0x0027) plen 39 Address type: Random (0x01) Address: D1:79:92:B1:83:DF (Static) Peer identity resolving key: ecc317056e5b385cda281b9c24a453e9 Local identity resolving key: 00000000000000000000000000000000 < ACL Data TX: Handle 3585 flags 0x00 dlen 21 SMP: Signing Information (0x0a) len 16 Signature key: 37b6c45656c7e8b3ec8db062c3e0c2b2 > ACL Data RX: Handle 3585 flags 0x02 dlen 9 ATT: Error Response (0x01) len 4 Read By Group Type Request (0x10) Handle: 0x0001 Error: Attribute Not Found (0x0a) > ACL Data RX: Handle 3585 flags 0x02 dlen 11 ATT: Read By Group Type Request (0x10) len 6 Handle range: 0x000a-0xffff Attribute group type: Primary Service (0x2800) > HCI Event: Command Complete (0x0e) plen 4 LE Add Device To Resolving List (0x08|0x0027) ncmd 1 Status: Success (0x00) Signed-off-by: Sathish Narsimman --- include/net/bluetooth/hci.h | 2 ++ net/bluetooth/hci_conn.c | 32 ++++++++++++++++++++++++++++++++ net/bluetooth/hci_core.c | 20 +++++++++++++++++++- net/bluetooth/hci_event.c | 32 +++++++++++++++++++++++++------- net/bluetooth/hci_request.c | 16 +++++++++++++--- net/bluetooth/mgmt.c | 10 +++++++++- net/bluetooth/smp.c | 11 +++++++++++ 7 files changed, 111 insertions(+), 12 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 352bc43940ff..d8431ebb8baa 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1617,6 +1617,8 @@ struct hci_rp_le_read_resolv_list_size { #define HCI_OP_LE_SET_ADDR_RESOLV_ENABLE 0x202d +#define HCI_OP_LE_SET_RPA_TIMEOUT 0x202e + #define HCI_OP_LE_READ_MAX_DATA_LEN 0x202f struct hci_rp_le_read_max_data_len { __u8 status; diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index e245bc155cc2..06067c0852a6 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -830,6 +830,14 @@ static void hci_req_add_le_create_conn(struct hci_request *req, plen = sizeof(*cp); + /* If the own_addr_type is 0x03 or 0x02 and peer is present + * in Kernel IRK list, but not in resolving add the peer to + * the resolving list. + */ + if (own_addr_type == 0x03 || own_addr_type == 0x02) + hci_req_check_and_update_resolving_list(hdev, conn->dst_type, + &conn->dst); + if (scan_1m(hdev)) { cp->phys |= LE_SCAN_PHY_1M; set_ext_conn_params(conn, p); @@ -866,6 +874,14 @@ static void hci_req_add_le_create_conn(struct hci_request *req, cp.scan_interval = cpu_to_le16(hdev->le_scan_interval); cp.scan_window = cp.scan_interval; + /* If the own_addr_type is 0x03 or 0x02 and peer is present + * in Kernel IRK list, but not in resolving add the peer to + * the resolving list. + */ + if (own_addr_type == 0x03 || own_addr_type == 0x02) + hci_req_check_and_update_resolving_list(hdev, conn->dst_type, + &conn->dst); + bacpy(&cp.peer_addr, &conn->dst); cp.peer_addr_type = conn->dst_type; cp.own_address_type = own_addr_type; @@ -901,6 +917,14 @@ static void hci_req_directed_advertising(struct hci_request *req, &own_addr_type, &random_addr) < 0) return; + /* If the own_addr_type is 0x03 or 0x02 and peer is present + * in Kernel IRK list, but not in resolving add the peer to + * the resolving list. + */ + if (own_addr_type == 0x03 || own_addr_type == 0x03) + hci_req_check_and_update_resolving_list(hdev, conn->dst_type, + &conn->dst); + memset(&cp, 0, sizeof(cp)); cp.evt_properties = cpu_to_le16(LE_LEGACY_ADV_DIRECT_IND); @@ -959,6 +983,14 @@ static void hci_req_directed_advertising(struct hci_request *req, &own_addr_type) < 0) return; + /* If the own_addr_type is 0x03 or 0x02 and peer is present + * in Kernel IRK list, but not in resolving add the peer to + * the resolving list. + */ + if (own_addr_type == 0x03 || own_addr_type == 0x02) + hci_req_check_and_update_resolving_list(hdev, conn->dst_type, + &conn->dst); + memset(&cp, 0, sizeof(cp)); /* Some controllers might reject command if intervals are not diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index dbd2ad3a26ed..7727be922084 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -713,7 +713,7 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt) /* If the controller supports the LE Extended Create Connection * command, enable the corresponding event. */ - if (use_ext_conn(hdev)) + if (use_ext_conn(hdev) || hdev->le_features[0] & HCI_LE_LL_PRIVACY) events[1] |= 0x02; /* LE Enhanced Connection * Complete */ @@ -762,6 +762,24 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt) hci_req_add(req, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL); } + if (hdev->commands[35] & 0x02) { + u8 addr_resoln_enable = 0x01; + + /* Enable Address Resolution in controller */ + hci_req_add(req, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, + sizeof(addr_resoln_enable), + &addr_resoln_enable); + } + + if (hdev->commands[35] & 0x40) { + __le16 rpa_timeout = cpu_to_le16(hdev->rpa_timeout); + + /* Set RPA timeout */ + hci_req_add(req, HCI_OP_LE_SET_RPA_TIMEOUT, 2, + &rpa_timeout); + + } + if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) { /* Read LE Maximum Data Length */ hci_req_add(req, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL); diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 20408d386268..d5ce1921fadd 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1684,7 +1684,11 @@ static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) return; hci_dev_lock(hdev); - hdev->adv_addr_type = cp->own_address_type; + + if (cp->own_address_type == ADDR_LE_DEV_PUBLIC) + hdev->adv_addr_type = ADDR_LE_DEV_PUBLIC; + else + hdev->adv_addr_type = ADDR_LE_DEV_RANDOM; hci_dev_unlock(hdev); } @@ -1704,7 +1708,12 @@ static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb) return; hci_dev_lock(hdev); - hdev->adv_addr_type = cp->own_addr_type; + + if (cp->own_addr_type == ADDR_LE_DEV_PUBLIC) + hdev->adv_addr_type = ADDR_LE_DEV_PUBLIC; + else + hdev->adv_addr_type = ADDR_LE_DEV_RANDOM; + if (!hdev->cur_adv_instance) { /* Store in hdev for instance 0 */ hdev->adv_tx_power = rp->tx_power; @@ -2267,11 +2276,13 @@ static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, * is needed for SMP. These values will not change during the * lifetime of the connection. */ - conn->init_addr_type = own_address_type; - if (own_address_type == ADDR_LE_DEV_RANDOM) + if (own_address_type == 0x03 || own_address_type == 0x01) { + conn->init_addr_type = ADDR_LE_DEV_RANDOM; bacpy(&conn->init_addr, &hdev->random_addr); - else + } else { + conn->init_addr_type = ADDR_LE_DEV_PUBLIC; bacpy(&conn->init_addr, &hdev->bdaddr); + } conn->resp_addr_type = peer_addr_type; bacpy(&conn->resp_addr, peer_addr); @@ -5141,6 +5152,8 @@ static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, } } + hci_req_check_and_update_resolving_list(hdev, (conn->dst_type), &conn->dst); + unlock: hci_update_background_scan(hdev); hci_dev_unlock(hdev); @@ -5365,8 +5378,13 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, /* Only resolvable random addresses are valid for these * kind of reports and others can be ignored. */ - if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type)) - return; + if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type)) { + /* Controller with LL Privacy Supported tend to resolve + * the RPA. In that case we should ignore this condition + */ + if ( !(hdev->le_features[0] & HCI_LE_LL_PRIVACY)) + return; + } /* If the controller is not using resolvable random * addresses, then this report can be ignored. diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 6b685cdc7de5..12868caf50ea 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1916,7 +1916,12 @@ int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, if (use_rpa) { int to; - *own_addr_type = ADDR_LE_DEV_RANDOM; + if (hdev->le_features[0] & HCI_LE_LL_PRIVACY) { + /*if there is no resolving list used in the controller + * use the bd_addr from latest Le_set_random_address*/ + *own_addr_type = 0x03; + } else + *own_addr_type = ADDR_LE_DEV_RANDOM; if (adv_instance) { if (!adv_instance->rpa_expired && @@ -2074,7 +2079,7 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance) hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp); - if (own_addr_type == ADDR_LE_DEV_RANDOM && + if (((own_addr_type == ADDR_LE_DEV_RANDOM) || (own_addr_type == 0x03)) && bacmp(&random_addr, BDADDR_ANY)) { struct hci_cp_le_set_adv_set_rand_addr cp; @@ -2341,7 +2346,12 @@ int hci_update_random_address(struct hci_request *req, bool require_privacy, if (use_rpa) { int to; - *own_addr_type = ADDR_LE_DEV_RANDOM; + if (hdev->le_features[0] & HCI_LE_LL_PRIVACY) { + /*if there is no resolving list used in the controller + * use the bd_addr from latest Le_set_random_address*/ + *own_addr_type = 0x03; + } else + *own_addr_type = ADDR_LE_DEV_RANDOM; if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) && !bacmp(&hdev->random_addr, &hdev->rpa)) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 6552003a170e..2b2bc011a130 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -5084,8 +5084,10 @@ static int set_debug_keys(struct sock *sk, struct hci_dev *hdev, if (err < 0) goto unlock; - if (changed) + if (changed) { err = new_settings(hdev, sk); + hci_req_update_resolving_list_local_irk(hdev); + } unlock: hci_dev_unlock(hdev); @@ -5227,6 +5229,8 @@ static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, BDADDR_ANY); } + /* Load the resolving list with entries from IRK list.*/ + hci_load_resolving_list(hdev); hci_dev_set_flag(hdev, HCI_RPA_RESOLVING); err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_LOAD_IRKS, 0, NULL, 0); @@ -7213,6 +7217,10 @@ void mgmt_power_on(struct hci_dev *hdev, int err) if (match.sk) sock_put(match.sk); + /* If load _irk was called when controller was powered down, + * then the resolving list has to be updated now. + */ + hci_load_resolving_list(hdev); hci_dev_unlock(hdev); } diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 1476a91ce935..85be3f5d869a 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -2425,6 +2425,8 @@ int smp_cancel_and_remove_pairing(struct hci_dev *hdev, bdaddr_t *bdaddr, struct smp_chan *smp; int err; + hci_req_del_from_resolving_list(hdev, addr_type, bdaddr); + err = hci_remove_ltk(hdev, bdaddr, addr_type); hci_remove_irk(hdev, bdaddr, addr_type); @@ -2619,6 +2621,15 @@ static int smp_cmd_ident_addr_info(struct l2cap_conn *conn, smp->remote_irk = hci_add_irk(conn->hcon->hdev, &smp->id_addr, smp->id_addr_type, smp->irk, &rpa); + /* Add the device to the resolving list.*/ + hci_req_update_resolving_list(conn->hcon->hdev, + smp->remote_irk->addr_type, + &smp->remote_irk->bdaddr, + smp->remote_irk->val); + + + /*TODO: Check remote device Supports LL Privacy. If not set the device + * with IRK to Device-privacy Mode - Should be discussed - Based on */ distribute: if (!(smp->remote_key_dist & KEY_DIST_MASK)) smp_distribute_keys(smp); From patchwork Thu Mar 12 10:07:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sathish Narasimman X-Patchwork-Id: 11433769 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9955590 for ; Thu, 12 Mar 2020 10:07:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 800A420736 for ; Thu, 12 Mar 2020 10:07:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qpoWLV81" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726795AbgCLKHS (ORCPT ); Thu, 12 Mar 2020 06:07:18 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41737 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgCLKHS (ORCPT ); Thu, 12 Mar 2020 06:07:18 -0400 Received: by mail-pf1-f194.google.com with SMTP id z65so3023146pfz.8 for ; Thu, 12 Mar 2020 03:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WEssHPdmc+CHUX/J9svOx4jP0pCE2+tppJ8olfTleQM=; b=qpoWLV81qW2rMTAtb/JdQk5gDvpAAFkaURhKCNhCgEhSq6rDaf/0BYz5U9PB4XG9Rc TKITRI8R0Yj4w3td0YabE7JrZMSLdyE2S+Sh3dpKTmSWXNuv7IEVkyZeAVY4Qi6cAVKY tStB8dvV5sz2vtdX7QNcPLdnZH7aBrtA/I+nAX91jedSkxv1CWu4M5m1XUpkkDtbNKac K0XsU6zBsDd6MBT7MUiZ2vnCOASH+XLUE87DfFvV6444cZOjMrrYhK1qgEs8ElX4B5hm N5NgEOxBJ++iY1Jdbnq/5mnvMuj97EN/Un+NtPPcS6wJkesJkt4tgzxDgNST/LJnraHR ooXQ== 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; bh=WEssHPdmc+CHUX/J9svOx4jP0pCE2+tppJ8olfTleQM=; b=Nd+ucwx+v4eyD+l7GYV1pGINZKmvEXrgVsohSohluqFDfFfcssXfX8ixa0KQ3G/umS pYeVxC5VNrI3g749p+3Iw0VSlOhHBgDDETQKGN6YOorDAUQfPl7+xT1rDQuG9wZVQmkD W2NHu6fp7ej1Bwn9evkT8XYftzjypjqA7H9lPAWkuANE+rashwsrVBRaxACO6HcgoYyj FDOG3qEOZe3w174LZ53VxB7osI9eEJkA7Q1QyIk3vK4HkTDQg77IEwrU+bGytA0P5HEV 0SbPKXBmV1Lr+F0tWJG7k8BkaelfkL/E++CUnwMywu7rMuHl9AnPNLetJNjO4HGuKXM0 n58g== X-Gm-Message-State: ANhLgQ26foEnmROzn3Y2fSE/Kyaa15vRgmF4pGWxaZYdR/V6Gu671BjW VLgbgComD1AP8gUGv38e3z15oHXu1vL1ZA== X-Google-Smtp-Source: ADFU+vsFeH6BJ/hJhMrE2LaFWr11OZIO66iMMHFEWjUiE9MHIaZ8tqxui9+WBuGrFCLwr1iMaiGPqQ== X-Received: by 2002:a63:e007:: with SMTP id e7mr6982851pgh.414.1584007636397; Thu, 12 Mar 2020 03:07:16 -0700 (PDT) Received: from nsathish-Latitude-7480.iind.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id e9sm10578295pfl.179.2020.03.12.03.07.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2020 03:07:15 -0700 (PDT) From: Sathish Narsimman X-Google-Original-From: Sathish Narsimman To: linux-bluetooth@vger.kernel.org, nsathish41@gmail.com Cc: chethan.tumkur.narayan@intel.com, Sathish Narsimman Subject: [PATCH 7/7] Bluetooth LL Privacy update White list Date: Thu, 12 Mar 2020 15:37:54 +0530 Message-Id: <20200312100754.3445-8-sathish.narasimman@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200312100754.3445-1-sathish.narasimman@intel.com> References: <20200312100754.3445-1-sathish.narasimman@intel.com> Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Update white list filter policy of if LL Privacy is enabled When Address Resolution is enabled and device is already in the white list then follow the filter policy Signed-off-by: Sathish Narsimman --- net/bluetooth/hci_request.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 12868caf50ea..47cb2602713a 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -711,7 +711,16 @@ static int add_to_white_list(struct hci_request *req, /* White list can not be used with RPAs */ if (!allow_rpa && hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) { - return -1; + /* White list can not be used with RPAs if address + * resolution is disabled in the controller + */ + if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) + return -1; + + /* if the peer device is not present in the resolving list */ + if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr, + b->bdaddr_type)) + return -1; } /* During suspend, only wakeable devices can be in whitelist */ @@ -768,7 +777,16 @@ static u8 update_white_list(struct hci_request *req) /* White list can not be used with RPAs */ if (!allow_rpa && hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) { - return 0x00; + /* White list can not be used with RPAs if address + * resolution is disabled in the controller + */ + if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) + return 0x00; + + /* if the peer device is not present in the resolving list */ + if (!hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, &b->bdaddr, + b->bdaddr_type)) + return 0x00; } num_entries++;