* [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state
@ 2012-02-21 17:43 johan.hedberg
2012-02-21 17:43 ` [PATCH 2/6] Bluetooth: mgmt: Fix Removing discoverable timeout in set_connectable johan.hedberg
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: johan.hedberg @ 2012-02-21 17:43 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
This patch makes it possible to toggle the connectable & discoverable
settings when powered off. Two new hdev->dev_flags flags are added to
track what the scan mode should be when the device is finally powered
on.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
include/net/bluetooth/hci.h | 2 +
net/bluetooth/hci_core.c | 1 +
net/bluetooth/mgmt.c | 91 ++++++++++++++++++++++++++++++++++--------
3 files changed, 76 insertions(+), 18 deletions(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ec37049..169d2f8 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -96,6 +96,8 @@ enum {
HCI_LE_SCAN,
HCI_SSP_ENABLED,
HCI_HS_ENABLED,
+ HCI_CONNECTABLE,
+ HCI_DISCOVERABLE,
};
/* HCI ioctl defines */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index a787c9c..9d19949 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -737,6 +737,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
if (hdev->discov_timeout > 0) {
cancel_delayed_work(&hdev->discov_off);
hdev->discov_timeout = 0;
+ clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
}
if (test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->dev_flags))
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 0f87030..6311be7 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -398,10 +398,10 @@ static u32 get_current_settings(struct hci_dev *hdev)
if (!test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
settings |= MGMT_SETTING_POWERED;
- if (test_bit(HCI_PSCAN, &hdev->flags))
+ if (test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
settings |= MGMT_SETTING_CONNECTABLE;
- if (test_bit(HCI_ISCAN, &hdev->flags))
+ if (test_bit(HCI_DISCOVERABLE, &hdev->dev_flags))
settings |= MGMT_SETTING_DISCOVERABLE;
if (test_bit(HCI_PAIRABLE, &hdev->dev_flags))
@@ -804,6 +804,7 @@ static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
struct mgmt_cp_set_discoverable *cp = data;
struct hci_dev *hdev;
struct pending_cmd *cmd;
+ u16 timeout;
u8 scan;
int err;
@@ -818,9 +819,11 @@ static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
return cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
MGMT_STATUS_INVALID_PARAMS);
+ timeout = get_unaligned_le16(&cp->timeout);
+
hci_dev_lock(hdev);
- if (!hdev_is_powered(hdev)) {
+ if (!hdev_is_powered(hdev) && timeout > 0) {
err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
MGMT_STATUS_NOT_POWERED);
goto failed;
@@ -833,8 +836,22 @@ static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
goto failed;
}
- if (cp->val == test_bit(HCI_ISCAN, &hdev->flags) &&
- test_bit(HCI_PSCAN, &hdev->flags)) {
+ if (!test_bit(HCI_CONNECTABLE, &hdev->dev_flags)) {
+ err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
+ MGMT_STATUS_REJECTED);
+ goto failed;
+ }
+
+ if (!hdev_is_powered(hdev)) {
+ if (cp->val)
+ set_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
+ else
+ clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
+ err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev);
+ goto failed;
+ }
+
+ if (!!cp->val == test_bit(HCI_DISCOVERABLE, &hdev->dev_flags)) {
err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev);
goto failed;
}
@@ -857,7 +874,7 @@ static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
mgmt_pending_remove(cmd);
if (cp->val)
- hdev->discov_timeout = get_unaligned_le16(&cp->timeout);
+ hdev->discov_timeout = timeout;
failed:
hci_dev_unlock(hdev);
@@ -888,8 +905,13 @@ static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
hci_dev_lock(hdev);
if (!hdev_is_powered(hdev)) {
- err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
- MGMT_STATUS_NOT_POWERED);
+ if (cp->val)
+ set_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+ else {
+ clear_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+ clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
+ }
+ err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev);
goto failed;
}
@@ -900,7 +922,7 @@ static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
goto failed;
}
- if (cp->val == test_bit(HCI_PSCAN, &hdev->flags)) {
+ if (!!cp->val == test_bit(HCI_PSCAN, &hdev->flags)) {
err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev);
goto failed;
}
@@ -2881,9 +2903,22 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
__le32 ev;
int err;
+ if (!test_bit(HCI_MGMT, &hdev->dev_flags))
+ return 0;
+
mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match);
- if (!powered) {
+ if (powered) {
+ u8 scan = 0;
+
+ if (test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
+ scan |= SCAN_PAGE;
+ if (test_bit(HCI_DISCOVERABLE, &hdev->dev_flags))
+ scan |= SCAN_INQUIRY;
+
+ if (scan)
+ hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
+ } else {
u8 status = ENETDOWN;
mgmt_pending_foreach(0, hdev, cmd_status_rsp, &status);
}
@@ -2902,15 +2937,25 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable)
{
struct cmd_lookup match = { NULL, hdev };
- __le32 ev;
- int err;
+ bool changed = false;
+ int err = 0;
mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, hdev, settings_rsp, &match);
- ev = cpu_to_le32(get_current_settings(hdev));
+ if (discoverable) {
+ if (!test_and_set_bit(HCI_DISCOVERABLE, &hdev->dev_flags))
+ changed = true;
+ } else {
+ if (test_and_clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags))
+ changed = true;
+ }
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev),
+ if (changed) {
+ __le32 ev = cpu_to_le32(get_current_settings(hdev));
+ err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev),
match.sk);
+ }
+
if (match.sk)
sock_put(match.sk);
@@ -2919,16 +2964,26 @@ int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable)
int mgmt_connectable(struct hci_dev *hdev, u8 connectable)
{
- __le32 ev;
struct cmd_lookup match = { NULL, hdev };
- int err;
+ bool changed = false;
+ int err = 0;
mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, hdev, settings_rsp,
&match);
- ev = cpu_to_le32(get_current_settings(hdev));
+ if (connectable) {
+ if (!test_and_set_bit(HCI_CONNECTABLE, &hdev->dev_flags))
+ changed = true;
+ } else {
+ if (test_and_clear_bit(HCI_CONNECTABLE, &hdev->dev_flags))
+ changed = true;
+ }
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), match.sk);
+ if (changed) {
+ __le32 ev = cpu_to_le32(get_current_settings(hdev));
+ err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev),
+ match.sk);
+ }
if (match.sk)
sock_put(match.sk);
--
1.7.9
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/6] Bluetooth: mgmt: Fix Removing discoverable timeout in set_connectable
2012-02-21 17:43 [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
@ 2012-02-21 17:43 ` johan.hedberg
2012-02-22 8:09 ` Andrei Emeltchenko
2012-02-21 17:43 ` [PATCH 3/6] Bluetooth: mgmt: Fix current settings values when powered off johan.hedberg
` (4 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: johan.hedberg @ 2012-02-21 17:43 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
When switching connectable mode off any pending discoverable timeout
must also be disabled to avoid duplicate write_scan_enable commands.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/mgmt.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 6311be7..eec70a4 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -935,9 +935,14 @@ static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
if (cp->val)
scan = SCAN_PAGE;
- else
+ else {
scan = 0;
+ if (test_bit(HCI_ISCAN, &hdev->flags) &&
+ hdev->discov_timeout > 0)
+ cancel_delayed_work(&hdev->discov_off);
+ }
+
err = hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
if (err < 0)
mgmt_pending_remove(cmd);
--
1.7.9
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/6] Bluetooth: mgmt: Fix Removing discoverable timeout in set_connectable
2012-02-21 17:43 ` [PATCH 2/6] Bluetooth: mgmt: Fix Removing discoverable timeout in set_connectable johan.hedberg
@ 2012-02-22 8:09 ` Andrei Emeltchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andrei Emeltchenko @ 2012-02-22 8:09 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
On Tue, Feb 21, 2012 at 07:43:45PM +0200, johan.hedberg@gmail.com wrote:
> From: Johan Hedberg <johan.hedberg@intel.com>
>
> When switching connectable mode off any pending discoverable timeout
> must also be disabled to avoid duplicate write_scan_enable commands.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/mgmt.c | 7 ++++++-
> 1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index 6311be7..eec70a4 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -935,9 +935,14 @@ static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
>
> if (cp->val)
> scan = SCAN_PAGE;
> - else
> + else {
I think here you have to use braces in both branches.
Best regards
Andrei Emeltchenko
> scan = 0;
>
> + if (test_bit(HCI_ISCAN, &hdev->flags) &&
> + hdev->discov_timeout > 0)
> + cancel_delayed_work(&hdev->discov_off);
> + }
> +
> err = hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
> if (err < 0)
> mgmt_pending_remove(cmd);
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/6] Bluetooth: mgmt: Fix current settings values when powered off
2012-02-21 17:43 [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
2012-02-21 17:43 ` [PATCH 2/6] Bluetooth: mgmt: Fix Removing discoverable timeout in set_connectable johan.hedberg
@ 2012-02-21 17:43 ` johan.hedberg
2012-02-21 17:43 ` [PATCH 4/6] Bluetooth: mgmt: Add convenience function for sending New Settings johan.hedberg
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2012-02-21 17:43 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
We should not stop iterating through the various settings if powered off
since most may still be set even then.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/mgmt.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index eec70a4..86e63a7 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -392,10 +392,7 @@ static u32 get_current_settings(struct hci_dev *hdev)
{
u32 settings = 0;
- if (!test_bit(HCI_UP, &hdev->flags))
- return settings;
-
- if (!test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
+ if (hdev_is_powered(hdev))
settings |= MGMT_SETTING_POWERED;
if (test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
--
1.7.9
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/6] Bluetooth: mgmt: Add convenience function for sending New Settings
2012-02-21 17:43 [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
2012-02-21 17:43 ` [PATCH 2/6] Bluetooth: mgmt: Fix Removing discoverable timeout in set_connectable johan.hedberg
2012-02-21 17:43 ` [PATCH 3/6] Bluetooth: mgmt: Fix current settings values when powered off johan.hedberg
@ 2012-02-21 17:43 ` johan.hedberg
2012-02-21 17:43 ` [PATCH 5/6] Bluetooth: mgmt: Fix New Settings event for connectable/discoverable johan.hedberg
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2012-02-21 17:43 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
The New Settings event needs to be sent from quite many places so it
makes sense to have a convenience function for it to simplify the code.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/mgmt.c | 96 +++++++++++++++++++++++---------------------------
1 files changed, 44 insertions(+), 52 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 86e63a7..439ec78 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -796,6 +796,42 @@ failed:
return err;
}
+static int mgmt_event(u16 event, struct hci_dev *hdev, void *data,
+ u16 data_len, struct sock *skip_sk)
+{
+ struct sk_buff *skb;
+ struct mgmt_hdr *hdr;
+
+ skb = alloc_skb(sizeof(*hdr) + data_len, GFP_ATOMIC);
+ if (!skb)
+ return -ENOMEM;
+
+ hdr = (void *) skb_put(skb, sizeof(*hdr));
+ hdr->opcode = cpu_to_le16(event);
+ if (hdev)
+ hdr->index = cpu_to_le16(hdev->id);
+ else
+ hdr->index = cpu_to_le16(MGMT_INDEX_NONE);
+ hdr->len = cpu_to_le16(data_len);
+
+ if (data)
+ memcpy(skb_put(skb, data_len), data, data_len);
+
+ hci_send_to_control(skb, skip_sk);
+ kfree_skb(skb);
+
+ return 0;
+}
+
+static int new_settings(struct hci_dev *hdev, struct sock *skip)
+{
+ __le32 ev;
+
+ ev = cpu_to_le32(get_current_settings(hdev));
+
+ return mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), skip);
+}
+
static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
{
struct mgmt_cp_set_discoverable *cp = data;
@@ -951,38 +987,10 @@ failed:
return err;
}
-static int mgmt_event(u16 event, struct hci_dev *hdev, void *data,
- u16 data_len, struct sock *skip_sk)
-{
- struct sk_buff *skb;
- struct mgmt_hdr *hdr;
-
- skb = alloc_skb(sizeof(*hdr) + data_len, GFP_ATOMIC);
- if (!skb)
- return -ENOMEM;
-
- hdr = (void *) skb_put(skb, sizeof(*hdr));
- hdr->opcode = cpu_to_le16(event);
- if (hdev)
- hdr->index = cpu_to_le16(hdev->id);
- else
- hdr->index = cpu_to_le16(MGMT_INDEX_NONE);
- hdr->len = cpu_to_le16(data_len);
-
- if (data)
- memcpy(skb_put(skb, data_len), data, data_len);
-
- hci_send_to_control(skb, skip_sk);
- kfree_skb(skb);
-
- return 0;
-}
-
static int set_pairable(struct sock *sk, u16 index, void *data, u16 len)
{
struct mgmt_mode *cp = data;
struct hci_dev *hdev;
- __le32 ev;
int err;
BT_DBG("request for hci%u", index);
@@ -1007,9 +1015,7 @@ static int set_pairable(struct sock *sk, u16 index, void *data, u16 len)
if (err < 0)
goto failed;
- ev = cpu_to_le32(get_current_settings(hdev));
-
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), sk);
+ err = new_settings(hdev, sk);
failed:
hci_dev_unlock(hdev);
@@ -2902,7 +2908,6 @@ static void settings_rsp(struct pending_cmd *cmd, void *data)
int mgmt_powered(struct hci_dev *hdev, u8 powered)
{
struct cmd_lookup match = { NULL, hdev };
- __le32 ev;
int err;
if (!test_bit(HCI_MGMT, &hdev->dev_flags))
@@ -2925,10 +2930,7 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
mgmt_pending_foreach(0, hdev, cmd_status_rsp, &status);
}
- ev = cpu_to_le32(get_current_settings(hdev));
-
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev),
- match.sk);
+ err = new_settings(hdev, match.sk);
if (match.sk)
sock_put(match.sk);
@@ -2952,11 +2954,8 @@ int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable)
changed = true;
}
- if (changed) {
- __le32 ev = cpu_to_le32(get_current_settings(hdev));
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev),
- match.sk);
- }
+ if (changed)
+ err = new_settings(hdev, match.sk);
if (match.sk)
sock_put(match.sk);
@@ -2981,11 +2980,8 @@ int mgmt_connectable(struct hci_dev *hdev, u8 connectable)
changed = true;
}
- if (changed) {
- __le32 ev = cpu_to_le32(get_current_settings(hdev));
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev),
- match.sk);
- }
+ if (changed)
+ err = new_settings(hdev, match.sk);
if (match.sk)
sock_put(match.sk);
@@ -3320,7 +3316,6 @@ int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status)
{
struct cmd_lookup match = { NULL, hdev };
- __le32 ev;
int err;
if (status) {
@@ -3333,8 +3328,7 @@ int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status)
mgmt_pending_foreach(MGMT_OP_SET_LINK_SECURITY, hdev, settings_rsp,
&match);
- ev = cpu_to_le32(get_current_settings(hdev));
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), match.sk);
+ err = new_settings(hdev, match.sk);
if (match.sk)
sock_put(match.sk);
@@ -3357,7 +3351,6 @@ static int clear_eir(struct hci_dev *hdev)
int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 status)
{
struct cmd_lookup match = { NULL, hdev };
- __le32 ev;
int err;
if (status) {
@@ -3369,8 +3362,7 @@ int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 status)
mgmt_pending_foreach(MGMT_OP_SET_SSP, hdev, settings_rsp, &match);
- ev = cpu_to_le32(get_current_settings(hdev));
- err = mgmt_event(MGMT_EV_NEW_SETTINGS, hdev, &ev, sizeof(ev), match.sk);
+ err = new_settings(hdev, match.sk);
if (match.sk) {
sock_put(match.sk);
--
1.7.9
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 5/6] Bluetooth: mgmt: Fix New Settings event for connectable/discoverable
2012-02-21 17:43 [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
` (2 preceding siblings ...)
2012-02-21 17:43 ` [PATCH 4/6] Bluetooth: mgmt: Add convenience function for sending New Settings johan.hedberg
@ 2012-02-21 17:43 ` johan.hedberg
2012-02-21 17:43 ` [PATCH 6/6] Bluetooth: Fix clearing of persistent dev_flags johan.hedberg
2012-02-22 8:05 ` [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state Andrei Emeltchenko
5 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2012-02-21 17:43 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
When powered off and doing changes to the Connectable or Discoverable
setting we should also send an appropriate New Settings event in
addition to the command response.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/mgmt.c | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 439ec78..08b867a 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -876,11 +876,20 @@ static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
}
if (!hdev_is_powered(hdev)) {
- if (cp->val)
- set_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
- else
- clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
+ bool changed = false;
+
+ if (!!cp->val != test_bit(HCI_DISCOVERABLE, &hdev->dev_flags)) {
+ change_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
+ changed = true;
+ }
+
err = send_settings_rsp(sk, MGMT_OP_SET_DISCOVERABLE, hdev);
+ if (err < 0)
+ goto failed;
+
+ if (changed)
+ err = new_settings(hdev, sk);
+
goto failed;
}
@@ -938,13 +947,25 @@ static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
hci_dev_lock(hdev);
if (!hdev_is_powered(hdev)) {
+ bool changed = false;
+
+ if (!!cp->val != test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
+ changed = true;
+
if (cp->val)
set_bit(HCI_CONNECTABLE, &hdev->dev_flags);
else {
clear_bit(HCI_CONNECTABLE, &hdev->dev_flags);
clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
}
+
err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev);
+ if (err < 0)
+ goto failed;
+
+ if (changed)
+ err = new_settings(hdev, sk);
+
goto failed;
}
--
1.7.9
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 6/6] Bluetooth: Fix clearing of persistent dev_flags
2012-02-21 17:43 [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
` (3 preceding siblings ...)
2012-02-21 17:43 ` [PATCH 5/6] Bluetooth: mgmt: Fix New Settings event for connectable/discoverable johan.hedberg
@ 2012-02-21 17:43 ` johan.hedberg
2012-02-22 8:05 ` [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state Andrei Emeltchenko
5 siblings, 0 replies; 8+ messages in thread
From: johan.hedberg @ 2012-02-21 17:43 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
Now that most flags are persistent, only the LE_SCAN flag should be
cleared after a reset.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/hci_event.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 5d0f92a..2a5d05c 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -192,9 +192,8 @@ static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
hci_req_complete(hdev, HCI_OP_RESET, status);
- /* Reset all flags, except persistent ones */
- hdev->dev_flags &= BIT(HCI_MGMT) | BIT(HCI_SETUP) | BIT(HCI_AUTO_OFF) |
- BIT(HCI_LINK_KEYS) | BIT(HCI_DEBUG_KEYS);
+ /* Reset all non-persistent flags */
+ hdev->dev_flags &= ~(BIT(HCI_LE_SCAN));
}
static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
--
1.7.9
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state
2012-02-21 17:43 [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
` (4 preceding siblings ...)
2012-02-21 17:43 ` [PATCH 6/6] Bluetooth: Fix clearing of persistent dev_flags johan.hedberg
@ 2012-02-22 8:05 ` Andrei Emeltchenko
5 siblings, 0 replies; 8+ messages in thread
From: Andrei Emeltchenko @ 2012-02-22 8:05 UTC (permalink / raw)
To: johan.hedberg; +Cc: linux-bluetooth
Hi Johan,
On Tue, Feb 21, 2012 at 07:43:44PM +0200, johan.hedberg@gmail.com wrote:
> From: Johan Hedberg <johan.hedberg@intel.com>
>
> This patch makes it possible to toggle the connectable & discoverable
> settings when powered off. Two new hdev->dev_flags flags are added to
> track what the scan mode should be when the device is finally powered
> on.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
...
> +
> + if (!!cp->val == test_bit(HCI_DISCOVERABLE, &hdev->dev_flags)) {
Is this really the best we can do? Also applies to other similar code.
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-02-22 8:09 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-21 17:43 [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
2012-02-21 17:43 ` [PATCH 2/6] Bluetooth: mgmt: Fix Removing discoverable timeout in set_connectable johan.hedberg
2012-02-22 8:09 ` Andrei Emeltchenko
2012-02-21 17:43 ` [PATCH 3/6] Bluetooth: mgmt: Fix current settings values when powered off johan.hedberg
2012-02-21 17:43 ` [PATCH 4/6] Bluetooth: mgmt: Add convenience function for sending New Settings johan.hedberg
2012-02-21 17:43 ` [PATCH 5/6] Bluetooth: mgmt: Fix New Settings event for connectable/discoverable johan.hedberg
2012-02-21 17:43 ` [PATCH 6/6] Bluetooth: Fix clearing of persistent dev_flags johan.hedberg
2012-02-22 8:05 ` [PATCH 1/6] Bluetooth: mgmt: Allow connectable/discoverable changes in off state Andrei Emeltchenko
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).