linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gustavo Padovan <padovan@profusion.mobi>
To: johan.hedberg@gmail.com
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 2/3] Bluetooth: Add timeout field to mgmt_set_discoverable
Date: Mon, 7 Nov 2011 14:50:46 -0200	[thread overview]
Message-ID: <20111107165046.GA2651@joana> (raw)
In-Reply-To: <1320358667-21086-2-git-send-email-johan.hedberg@gmail.com>

Hi Johan,

* johan.hedberg@gmail.com <johan.hedberg@gmail.com> [2011-11-04 00:17:46 +0200]:

> From: Johan Hedberg <johan.hedberg@intel.com>
> 
> Based on the revised mgmt API set_discoverable has a timeout parameter
> to specify how long the adapter will remain discoverable. A value of 0
> means "indefinitively".
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  include/net/bluetooth/hci_core.h |    3 +++
>  include/net/bluetooth/mgmt.h     |    4 ++++
>  net/bluetooth/hci_core.c         |   25 +++++++++++++++++++++++++
>  net/bluetooth/hci_event.c        |    5 +++++
>  net/bluetooth/mgmt.c             |    5 ++++-
>  5 files changed, 41 insertions(+), 1 deletions(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index f97792c..5079598 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -196,6 +196,9 @@ struct hci_dev {
>  	struct work_struct	power_off;
>  	struct timer_list	off_timer;
>  
> +	__u16			discov_timeout;
> +	struct delayed_work	discov_off;
> +
>  	struct timer_list	cmd_timer;
>  	struct tasklet_struct	cmd_task;
>  	struct tasklet_struct	rx_task;
> diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
> index 3062fd3..b5320aa 100644
> --- a/include/net/bluetooth/mgmt.h
> +++ b/include/net/bluetooth/mgmt.h
> @@ -69,6 +69,10 @@ struct mgmt_mode {
>  #define MGMT_OP_SET_POWERED		0x0005
>  
>  #define MGMT_OP_SET_DISCOVERABLE	0x0006
> +struct mgmt_cp_set_discoverable {
> +	__u8 val;
> +	__u16 timeout;
> +} __packed;
>  
>  #define MGMT_OP_SET_CONNECTABLE		0x0007
>  
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index b7f6b5b..0c75770 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -595,6 +595,11 @@ static int hci_dev_do_close(struct hci_dev *hdev)
>  	tasklet_kill(&hdev->rx_task);
>  	tasklet_kill(&hdev->tx_task);
>  
> +	if (hdev->discov_timeout > 0) {
> +		cancel_delayed_work_sync(&hdev->discov_off);
> +		hdev->discov_timeout = 0;
> +	}
> +
>  	hci_dev_lock_bh(hdev);
>  	inquiry_cache_flush(hdev);
>  	hci_conn_hash_flush(hdev);
> @@ -968,6 +973,24 @@ void hci_del_off_timer(struct hci_dev *hdev)
>  	del_timer(&hdev->off_timer);
>  }
>  
> +static void hci_discov_off(struct work_struct *work)
> +{
> +	struct hci_dev *hdev;
> +	u8 scan = SCAN_PAGE;
> +
> +	hdev = container_of(work, struct hci_dev, discov_off.work);
> +
> +	BT_DBG("%s", hdev->name);
> +
> +	hci_dev_lock_bh(hdev);
> +
> +	hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, sizeof(scan), &scan);
> +
> +	hdev->discov_timeout = 0;
> +
> +	hci_dev_unlock_bh(hdev);
> +}
> +
>  int hci_uuids_clear(struct hci_dev *hdev)
>  {
>  	struct list_head *p, *n;
> @@ -1485,6 +1508,8 @@ int hci_register_dev(struct hci_dev *hdev)
>  	INIT_WORK(&hdev->power_off, hci_power_off);
>  	setup_timer(&hdev->off_timer, hci_auto_off, (unsigned long) hdev);
>  
> +	INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off);
> +
>  	memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
>  
>  	atomic_set(&hdev->promisc, 0);
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 8c81a75..dd24d6e 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -296,6 +296,11 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
>  		set_bit(HCI_ISCAN, &hdev->flags);
>  		if (!old_iscan)
>  			mgmt_discoverable(hdev->id, 1);
> +		if (hdev->discov_timeout > 0) {
> +			int to = msecs_to_jiffies(hdev->discov_timeout * 1000);
> +			queue_delayed_work(hdev->workqueue, &hdev->discov_off,
> +									to);
> +		}
>  	} else if (old_iscan)
>  		mgmt_discoverable(hdev->id, 0);

If we call set discoverable FALSE after call set discoverable TRUE and
_before_ it timeouts expires we are leaking the delayed work. A
cancel_delayed_work_sync() call seems to be missing in this case.

	Gustavo

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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-03 22:17 [PATCH 1/3] Bluetooth: Clean up logic in hci_cc_write_scan_enable johan.hedberg
2011-11-03 22:17 ` [PATCH 2/3] Bluetooth: Add timeout field to mgmt_set_discoverable johan.hedberg
2011-11-07 16:50   ` Gustavo Padovan [this message]
2011-11-03 22:17 ` [PATCH 3/3] Bluetooth: Fix mgmt response when HCI_Write_Scan_Enable fails johan.hedberg
2011-11-07 16:55   ` Gustavo Padovan
2011-11-07 16:54 ` [PATCH 1/3] Bluetooth: Clean up logic in hci_cc_write_scan_enable Gustavo Padovan

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=20111107165046.GA2651@joana \
    --to=padovan@profusion.mobi \
    --cc=johan.hedberg@gmail.com \
    --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).