Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp288058ybl; Wed, 4 Dec 2019 02:50:08 -0800 (PST) X-Google-Smtp-Source: APXvYqyrr+WJqc/xP2FkPKDV/e5QEEwifl0PUBv1YiLpuJ+IMh5/MlY8tKF6qe7sDtNvVEu/vkKh X-Received: by 2002:aca:90f:: with SMTP id 15mr2031960oij.85.1575456608639; Wed, 04 Dec 2019 02:50:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575456608; cv=none; d=google.com; s=arc-20160816; b=XFy0eBCM+RdmzLYogRR+TS/3MfjThHzhmukSRGp2CPGd2uHlrzufceTy2QMAgrghfM iMbj2jtQvTOh2YpWatbqvoU6G9irzoBmbJazasm85iafk48K53pT8twOuXj2nLoaRRw3 X6pWqPAWl5YAVW1m6Udn2IDrmOW/wa7oWAOrvOigJXm90vAnFC+FLR3Ismeo/V9PNQRq Rm4yfoOAzF6T/stPETlGzp1WqCFKuf17WlTbvWx+ylNwXPFRrHEjK3wcnmQAmawF358Y RIs186ky79Czvon9gnLzpSXHOfRH6uEiY7fQ7wl9wHyISRyaSEjnsdlnIIPwgHBJGdyj eO5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=DSUhe3uM4ajH6geL+x6rO4p7U/zu6BU0FQtPTmiAO/w=; b=nfc/axOMIymQzC+ZE2QSkieaANPtA0Rca3ncibEGpwC4i9/A8wACPabnv44ZTMtt3d UjtMGMTynDojAb6t+iNNni9V6fGw4sAMOVgAKQkTfUosqu5bfACLRYsm8wmTDrOaVjdz StPZX96BZlVWya8KvzP8CmLZ3Apt/4fRQjrCb4h16OOWp5vxq8TVQg6owvQjoAUeewwF 5tfDJ5yNZJyHoJT2MhbKRpj3YN82lLJmaVnDshJ2BkZnUfEGZJNmlWchA0/seLin9l4v v5YLcWkTEJGF2SabvOVzgBtzbVVLh7zutytSRFWnDkjSmSdYoKHTuJ0nJQRDTKqCjfAz IiDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i15si2835456otk.120.2019.12.04.02.49.43; Wed, 04 Dec 2019 02:50:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727445AbfLDKta (ORCPT + 99 others); Wed, 4 Dec 2019 05:49:30 -0500 Received: from mga07.intel.com ([134.134.136.100]:11533 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727268AbfLDKt3 (ORCPT ); Wed, 4 Dec 2019 05:49:29 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 02:49:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,277,1571727600"; d="scan'208";a="205350840" Received: from unknown (HELO spoorthi-H97M-D3H.iind.intel.com) ([10.223.96.107]) by orsmga008.jf.intel.com with ESMTP; 04 Dec 2019 02:49:27 -0800 From: spoorthix.k@intel.com To: linux-bluetooth@vger.kernel.org Cc: bharat.b.panda@intel.com Subject: [PATCH] Add support to update Resolving list Date: Wed, 4 Dec 2019 16:33:11 +0530 Message-Id: <1575457391-3974-1-git-send-email-spoorthix.k@intel.com> X-Mailer: git-send-email 1.9.1 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Spoorthi Ravishankar Koppad Code changes to add or delete the BD address to/from existing resolving list referred from Bluetooth Core Specification v5.0 Vol6 Part B Section 6.3, If the link layer privacy feature is supported by the controller, Link layer may scan devices using RPA during background scan,the host can add newly scanned devices to the Resolving list. ` Signed-off-by: Spoorthi Ravishankar Koppad --- include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_request.c | 85 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 5bc1e30..1574dc1 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -433,6 +433,7 @@ enum { #define HCI_LE_SLAVE_FEATURES 0x08 #define HCI_LE_PING 0x10 #define HCI_LE_DATA_LEN_EXT 0x20 +#define HCI_LE_LL_PRIVACY 0x40 #define HCI_LE_PHY_2M 0x01 #define HCI_LE_PHY_CODED 0x08 #define HCI_LE_EXT_ADV 0x10 diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index 621f1a9..5c59cce 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -670,6 +670,85 @@ void hci_req_add_le_scan_disable(struct hci_request *req) } } +static void add_to_resolve_list(struct hci_request *req, + struct hci_conn_params *params, + struct list_head *list) +{ + struct hci_cp_le_add_to_resolv_list cp; + struct bdaddr_list_with_irk *entry; + + entry = kzalloc(sizeof(*entry), GFP_KERNEL); + if (!entry) + return; + + memset(&cp, 0, sizeof(cp)); + + cp.bdaddr_type = params->addr_type; + bacpy(&cp.bdaddr, ¶ms->addr); + memcpy(entry->peer_irk, cp.peer_irk, 16); + memcpy(entry->local_irk, cp.local_irk, 16); + + list_add(&entry->list, list); + + hci_req_add(req, HCI_OP_LE_ADD_TO_RESOLV_LIST, sizeof(cp), &cp); +} + +static void update_resolve_list(struct hci_request *req) +{ + struct hci_dev *hdev = req->hdev; + struct bdaddr_list *b; + struct hci_conn_params *params; + int err; + u8 resolve_list_entries = 0; + + list_for_each_entry(b, &hdev->le_resolv_list, list) { + /* Cannot Remove or add the device to the Resolving list + * whenever there is an outstanding connection. + */ + if (!hci_pend_le_action_lookup(&hdev->pend_le_conns, + &b->bdaddr, + b->bdaddr_type) && + !hci_pend_le_action_lookup(&hdev->pend_le_reports, + &b->bdaddr, + b->bdaddr_type)) { + struct hci_cp_le_del_from_resolv_list cp; + + cp.bdaddr_type = b->bdaddr_type; + bacpy(&cp.bdaddr, &b->bdaddr); + + hci_req_add(req, HCI_OP_LE_DEL_FROM_RESOLV_LIST, + sizeof(cp), &cp); + } + } + /* During background scanning/active scanning the + * device BD address is populated in LE pending + * connections list. So, track the list and add to Resolving + * list if found by IRK. + */ + list_for_each_entry(params, &hdev->pend_le_conns, action) { + if (hci_bdaddr_list_lookup(&hdev->le_resolv_list, + ¶ms->addr, params->addr_type)) + resolve_list_entries++; + + if (hci_find_irk_by_addr(hdev, ¶ms->addr, + params->addr_type)) { + /* Add device to resolving list */ + resolve_list_entries++; + add_to_resolve_list(req, params, &hdev->le_resolv_list); + } + } + + /* Device can be resolved in the Host if size of resolving + * list is greater than defined in the controller. + */ + if (resolve_list_entries >= hdev->le_resolv_list_size) { + err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); + if (err < 0) + BT_ERR("%s failed to generate new RPA", + hdev->name); + } +} + static void add_to_white_list(struct hci_request *req, struct hci_conn_params *params) { @@ -896,6 +975,12 @@ void hci_req_add_le_passive_scan(struct hci_request *req) (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) filter_policy |= 0x02; + /* If LE Privacy is supported in controller + * add the device to resolving list. + */ + if (hci_dev_test_flag(hdev, HCI_LE_LL_PRIVACY)) + update_resolve_list(req); + hci_req_start_scan(req, LE_SCAN_PASSIVE, hdev->le_scan_interval, hdev->le_scan_window, own_addr_type, filter_policy); } -- 1.9.1