linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: Andre Guedes <andre.guedes@openbossa.org>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH v2 6/9] Bluetooth: Add LE scan functions to hci_core
Date: Mon, 28 Nov 2011 17:28:30 +0100	[thread overview]
Message-ID: <1322497710.29909.40.camel@aeonflux> (raw)
In-Reply-To: <1322265226-6404-7-git-send-email-andre.guedes@openbossa.org>

Hi Andre,

> This patch adds to hci_core functions to init LE scan and cancel
> an ongoing scanning (hci_do_le_scan and hci_cancel_le_scan).
> 
> Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
> ---
>  include/net/bluetooth/hci_core.h |    3 +++
>  net/bluetooth/hci_core.c         |   32 ++++++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+), 0 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index a48c699..db137ca 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -998,5 +998,8 @@ void hci_le_ltk_neg_reply(struct hci_conn *conn);
>  
>  int hci_do_inquiry(struct hci_dev *hdev, u8 length);
>  int hci_cancel_inquiry(struct hci_dev *hdev);
> +int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
> +								int timeout);
> +int hci_cancel_le_scan(struct hci_dev *hdev);
>  
>  #endif /* __HCI_CORE_H */
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index 8e96e3b..1e5d9db 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -2678,5 +2678,37 @@ int hci_cancel_inquiry(struct hci_dev *hdev)
>  	return hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
>  }
>  
> +int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
> +								int timeout)
> +{
> +	struct le_scan_params *params = &hdev->le_scan_params;
> +
> +	if (test_bit(HCI_LE_SCAN, &hdev->dev_flags))
> +		return -EINPROGRESS;
> +
> +	BT_DBG("%s", hdev->name);
> +
> +	params->type = type;
> +	params->interval = interval;
> +	params->window = window;
> +	params->timeout = timeout;
> +
> +	queue_work(hdev->workqueue, &hdev->le_scan);

so you are using the controller workqueue already. That is good. However
if the send command are already processed in a workqueue, we could just
sleep for their results. No need for hci_req_complete handling that we
are using for ioctl based triggers. We could have a lot simpler
hci_request handling from within the workqueue.

> +
> +	return 0;
> +}
> +
> +int hci_cancel_le_scan(struct hci_dev *hdev)
> +{
> +	if (!test_bit(HCI_LE_SCAN, &hdev->dev_flags))
> +		return -EPERM;
> +
> +	BT_DBG("%s", hdev->name);
> +
> +	del_timer(&hdev->le_scan_timer);
> +
> +	return send_le_scan_enable_cmd(hdev, 0);
> +}
> +

Don't you need to clear out the work struct as well? In case that one is
still running? Meaning cancel gets called quickly after starting the
scan. The window might be small, but this is a race condition.

Regards

Marcel



  reply	other threads:[~2011-11-28 16:28 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-25 23:53 [PATCH v2 0/9] LE-Only discovery procedure support Andre Guedes
2011-11-25 23:53 ` [PATCH v2 1/9] Bluetooth: Add dev_flags to struct hci_dev Andre Guedes
2011-11-28 16:17   ` Marcel Holtmann
2011-11-25 23:53 ` [PATCH v2 2/9] Bluetooth: LE Set Scan Parameter Command Andre Guedes
2011-11-28 16:17   ` Marcel Holtmann
2011-12-02 12:19   ` Gustavo Padovan
2011-11-25 23:53 ` [PATCH v2 3/9] Bluetooth: Add helper functions to send LE scan commands Andre Guedes
2011-11-28 16:19   ` Marcel Holtmann
2011-11-25 23:53 ` [PATCH v2 4/9] Bluetooth: Add structs to implement LE scan Andre Guedes
2011-11-25 23:53 ` [PATCH v2 5/9] Bluetooth: LE scan infra-structure Andre Guedes
2011-11-28 16:24   ` Marcel Holtmann
2011-11-30 18:11     ` Andre Guedes
2011-12-02 10:02       ` Query on Media Interface "RegisterPlayer" and Dbus signal "TrackChanged" Jaganath
2011-12-02 11:07         ` Luiz Augusto von Dentz
2011-12-05 13:03           ` sathish
2011-12-06  6:21             ` Chethan T N
2011-11-25 23:53 ` [PATCH v2 6/9] Bluetooth: Add LE scan functions to hci_core Andre Guedes
2011-11-28 16:28   ` Marcel Holtmann [this message]
2011-11-30 18:11     ` Andre Guedes
2011-11-25 23:53 ` [PATCH v2 7/9] Bluetooth: Add 'eir_len' param to mgmt_device_found() Andre Guedes
2011-11-27  6:37   ` Ganir, Chen
2011-11-28 11:08     ` Anderson Lizardo
2011-11-28 14:06       ` Andre Guedes
2011-11-25 23:53 ` [PATCH v2 8/9] Bluetooth: Report LE devices Andre Guedes
2011-11-25 23:53 ` [PATCH v2 9/9] Bluetooth: Support LE-Only discovery procedure Andre Guedes
2011-11-27  6:44   ` Ganir, Chen
2011-11-28 14:51     ` Andre Guedes
2011-11-29  9:14     ` Johan Hedberg
2011-11-30  6:43       ` Ganir, Chen
2011-11-30 11:27         ` Johan Hedberg
2011-11-30 11:38           ` Ganir, Chen
2011-11-30 11:44             ` Johan Hedberg

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=1322497710.29909.40.camel@aeonflux \
    --to=marcel@holtmann.org \
    --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;
as well as URLs for NNTP newsgroup(s).