Commit 812abb13 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Johan Hedberg

Bluetooth: Refactor BR/EDR inquiry and LE scan triggering.

This patch refactor BR/EDR inquiry and LE scan triggering logic into
separate methods.
Signed-off-by: default avatarJakub Pawlowski <jpawlowski@google.com>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 695c4cb6
...@@ -3921,93 +3921,113 @@ static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, ...@@ -3921,93 +3921,113 @@ static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
return err; return err;
} }
static bool trigger_discovery(struct hci_request *req, u8 *status) static bool trigger_bredr_inquiry(struct hci_request *req, u8 *status)
{ {
struct hci_dev *hdev = req->hdev; struct hci_dev *hdev = req->hdev;
struct hci_cp_le_set_scan_param param_cp; struct hci_cp_inquiry cp;
struct hci_cp_le_set_scan_enable enable_cp;
struct hci_cp_inquiry inq_cp;
/* General inquiry access code (GIAC) */ /* General inquiry access code (GIAC) */
u8 lap[3] = { 0x33, 0x8b, 0x9e }; u8 lap[3] = { 0x33, 0x8b, 0x9e };
*status = mgmt_bredr_support(hdev);
if (*status)
return false;
if (hci_dev_test_flag(hdev, HCI_INQUIRY)) {
*status = MGMT_STATUS_BUSY;
return false;
}
hci_inquiry_cache_flush(hdev);
memset(&cp, 0, sizeof(cp));
memcpy(&cp.lap, lap, sizeof(cp.lap));
cp.length = DISCOV_BREDR_INQUIRY_LEN;
hci_req_add(req, HCI_OP_INQUIRY, sizeof(cp), &cp);
return true;
}
static bool trigger_le_scan(struct hci_request *req, u16 interval, u8 *status)
{
struct hci_dev *hdev = req->hdev;
struct hci_cp_le_set_scan_param param_cp;
struct hci_cp_le_set_scan_enable enable_cp;
u8 own_addr_type; u8 own_addr_type;
int err; int err;
switch (hdev->discovery.type) { *status = mgmt_le_support(hdev);
case DISCOV_TYPE_BREDR: if (*status)
*status = mgmt_bredr_support(hdev); return false;
if (*status)
return false;
if (test_bit(HCI_INQUIRY, &hdev->flags)) { if (hci_dev_test_flag(hdev, HCI_LE_ADV)) {
*status = MGMT_STATUS_BUSY; /* Don't let discovery abort an outgoing connection attempt
* that's using directed advertising.
*/
if (hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT)) {
*status = MGMT_STATUS_REJECTED;
return false; return false;
} }
hci_inquiry_cache_flush(hdev); disable_advertising(req);
}
memset(&inq_cp, 0, sizeof(inq_cp)); /* If controller is scanning, it means the background scanning is
memcpy(&inq_cp.lap, lap, sizeof(inq_cp.lap)); * running. Thus, we should temporarily stop it in order to set the
inq_cp.length = DISCOV_BREDR_INQUIRY_LEN; * discovery scanning parameters.
hci_req_add(req, HCI_OP_INQUIRY, sizeof(inq_cp), &inq_cp); */
break; if (hci_dev_test_flag(hdev, HCI_LE_SCAN))
hci_req_add_le_scan_disable(req);
case DISCOV_TYPE_LE: /* All active scans will be done with either a resolvable private
case DISCOV_TYPE_INTERLEAVED: * address (when privacy feature has been enabled) or non-resolvable
*status = mgmt_le_support(hdev); * private address.
if (*status) */
return false; err = hci_update_random_address(req, true, &own_addr_type);
if (err < 0) {
*status = MGMT_STATUS_FAILED;
return false;
}
if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED && memset(&param_cp, 0, sizeof(param_cp));
!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { param_cp.type = LE_SCAN_ACTIVE;
*status = MGMT_STATUS_NOT_SUPPORTED; param_cp.interval = cpu_to_le16(interval);
return false; param_cp.window = cpu_to_le16(DISCOV_LE_SCAN_WIN);
} param_cp.own_address_type = own_addr_type;
if (hci_dev_test_flag(hdev, HCI_LE_ADV)) { hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
/* Don't let discovery abort an outgoing &param_cp);
* connection attempt that's using directed
* advertising.
*/
if (hci_conn_hash_lookup_state(hdev, LE_LINK,
BT_CONNECT)) {
*status = MGMT_STATUS_REJECTED;
return false;
}
disable_advertising(req); memset(&enable_cp, 0, sizeof(enable_cp));
} enable_cp.enable = LE_SCAN_ENABLE;
enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
/* If controller is scanning, it means the background scanning hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
* is running. Thus, we should temporarily stop it in order to &enable_cp);
* set the discovery scanning parameters.
*/ return true;
if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) }
hci_req_add_le_scan_disable(req);
memset(&param_cp, 0, sizeof(param_cp)); static bool trigger_discovery(struct hci_request *req, u8 *status)
{
struct hci_dev *hdev = req->hdev;
/* All active scans will be done with either a resolvable switch (hdev->discovery.type) {
* private address (when privacy feature has been enabled) case DISCOV_TYPE_BREDR:
* or non-resolvable private address. if (!trigger_bredr_inquiry(req, status))
*/ return false;
err = hci_update_random_address(req, true, &own_addr_type); break;
if (err < 0) {
*status = MGMT_STATUS_FAILED; case DISCOV_TYPE_INTERLEAVED:
if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
*status = MGMT_STATUS_NOT_SUPPORTED;
return false; return false;
} }
/* fall through */
param_cp.type = LE_SCAN_ACTIVE; case DISCOV_TYPE_LE:
param_cp.interval = cpu_to_le16(DISCOV_LE_SCAN_INT); if (!trigger_le_scan(req, DISCOV_LE_SCAN_INT, status))
param_cp.window = cpu_to_le16(DISCOV_LE_SCAN_WIN); return false;
param_cp.own_address_type = own_addr_type;
hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
&param_cp);
memset(&enable_cp, 0, sizeof(enable_cp));
enable_cp.enable = LE_SCAN_ENABLE;
enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
&enable_cp);
break; break;
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment