From: Johan Hedberg <johan.hedberg@gmail.com>
To: Andre Guedes <andre.guedes@openbossa.org>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 09/17] Bluetooth: Update le_scan_disable_work to use HCI request
Date: Wed, 17 Apr 2013 12:18:35 +0300 [thread overview]
Message-ID: <20130417091835.GF6637@x220> (raw)
In-Reply-To: <1365117675-2202-10-git-send-email-andre.guedes@openbossa.org>
Hi Andre,
On Thu, Apr 04, 2013, Andre Guedes wrote:
> +static void le_scan_disable_work_complete(struct hci_dev *hdev, u8 status)
> +{
> + struct hci_command_hdr *last_cmd;
> + u16 opcode;
> +
> + BT_DBG("status %d", status);
> +
> + /* Get opcode from the last command sent */
> + last_cmd = (void *) hdev->sent_cmd->data;
> + opcode = __le16_to_cpu(last_cmd->opcode);
> +
> + switch (opcode) {
> + case HCI_OP_LE_SET_SCAN_ENABLE:
> + if (status) {
> + BT_ERR("Failed to disable LE scanning: status %d",
> + status);
> + return;
> + }
> +
> + hci_dev_lock(hdev);
> + hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
> + hci_dev_unlock(hdev);
> + break;
> +
> + case HCI_OP_INQUIRY:
> + if (status) {
> + hci_dev_lock(hdev);
> + hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
> + hci_dev_unlock(hdev);
> + return;
> + }
> +
> + break;
> + }
> +}
> +
> static void le_scan_disable_work(struct work_struct *work)
> {
> struct hci_dev *hdev = container_of(work, struct hci_dev,
> le_scan_disable.work);
> struct hci_cp_le_set_scan_enable cp;
> + struct hci_request req;
> + int err;
>
> BT_DBG("%s", hdev->name);
>
> + if (hdev->discovery.state != DISCOVERY_FINDING)
> + return;
> +
> + hci_req_init(&req, hdev);
> +
> memset(&cp, 0, sizeof(cp));
> + cp.enable = LE_SCAN_DISABLE;
> + hci_req_add(&req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
> +
> + /* If we are running the interleaved discovery, also add the inquiry
> + * HCI command to the HCI request.
> + */
> + if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED) {
> + struct hci_cp_inquiry inq_cp;
> + /* General inquiry access code (GIAC) */
> + u8 lap[3] = { 0x33, 0x8b, 0x9e };
> +
> + hci_dev_lock(hdev);
> + inquiry_cache_flush(hdev);
> + hci_dev_unlock(hdev);
> +
> + memset(&inq_cp, 0, sizeof(inq_cp));
> + memcpy(&inq_cp.lap, lap, sizeof(inq_cp.lap));
> + inq_cp.length = DISCOV_INTERLEAVED_INQUIRY_LEN;
> + hci_req_add(&req, HCI_OP_INQUIRY, sizeof(inq_cp), &inq_cp);
> + }
>
> - hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
> + err = hci_req_run(&req, le_scan_disable_work_complete);
> + if (err)
> + BT_ERR("Failed to disable LE scanning: err %d", err);
> }
I don't really like the complexity of the logic here with having to peek
at hdev->sent_cmd to figure out what's going on in the callback. Maybe
instead do this in two separate steps, i.e. send the HCI_OP_INQUIRY only
in the callback for the HCI_OP_LE_SET_SCAN_ENABLE. Alternatively look
into the possibility of using our recently introduced _sync API, though
you'll first need to have a patch to add a hci_cmd_sync() which
internally acquires the request lock.
Johan
next prev parent reply other threads:[~2013-04-17 9:18 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-04 23:20 [PATCH 00/17] Update Discovery to use HCI request framework Andre Guedes
2013-04-04 23:20 ` [PATCH 01/17] Bluetooth: Change LE scanning timeout macros Andre Guedes
2013-04-17 8:28 ` Johan Hedberg
2013-04-04 23:21 ` [PATCH 02/17] Bluetooth: Add LE scan type macros Andre Guedes
2013-04-17 8:28 ` Johan Hedberg
2013-04-04 23:21 ` [PATCH 03/17] Bluetooth: Add macros for filter duplicates values Andre Guedes
2013-04-17 8:29 ` Johan Hedberg
2013-04-04 23:21 ` [PATCH 04/17] Bluetooth: Rename LE_SCANNING_* macros Andre Guedes
2013-04-17 8:29 ` Johan Hedberg
2013-04-18 4:20 ` Gustavo Padovan
2013-04-04 23:21 ` [PATCH 05/17] Bluetooth: Make inquiry_cache_flush non-static Andre Guedes
2013-04-17 8:30 ` Johan Hedberg
2013-04-17 22:17 ` Andre Guedes
2013-04-04 23:21 ` [PATCH 06/17] Bluetooth: Update start_discovery to use HCI request Andre Guedes
2013-04-04 23:21 ` [PATCH 07/17] Bluetooth: Remove start discovery handling from hci_event.c Andre Guedes
2013-04-04 23:21 ` [PATCH 08/17] Bluetooth: Move discovery macros to hci_core.h Andre Guedes
2013-04-04 23:21 ` [PATCH 09/17] Bluetooth: Update le_scan_disable_work to use HCI request Andre Guedes
2013-04-17 9:18 ` Johan Hedberg [this message]
2013-04-17 22:18 ` Andre Guedes
2013-04-04 23:21 ` [PATCH 10/17] Bluetooth: Update stop_discovery " Andre Guedes
2013-04-04 23:21 ` [PATCH 11/17] Bluetooth: Remove stop discovery handling from hci_event.c Andre Guedes
2013-04-04 23:21 ` [PATCH 12/17] Bluetooth: Refactor hci_cc_le_set_scan_enable Andre Guedes
2013-04-04 23:21 ` [PATCH 13/17] Bluetooth: Remove LE scan helpers Andre Guedes
2013-04-04 23:21 ` [PATCH 14/17] Bluetooth: Remove inquiry helpers Andre Guedes
2013-04-04 23:21 ` [PATCH 15/17] Bluetooth: Remove empty event handler Andre Guedes
2013-04-04 23:21 ` [PATCH 16/17] Bluetooth: Rename le_scan_disable delayed work Andre Guedes
2013-04-04 23:21 ` [PATCH 17/17] Bluetooth: Mgmt Device Found Event Andre Guedes
2013-04-15 16:50 ` [PATCH 00/17] Update Discovery to use HCI request framework Andre Guedes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130417091835.GF6637@x220 \
--to=johan.hedberg@gmail.com \
--cc=andre.guedes@openbossa.org \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox