* [PATCH] Bluetooth: Fix advertising address type when toggling connectable
@ 2014-02-25 13:10 johan.hedberg
2014-02-25 13:10 ` johan.hedberg
0 siblings, 1 reply; 4+ messages in thread
From: johan.hedberg @ 2014-02-25 13:10 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
When the connectable setting is toggled using mgmt_set_connectable the
HCI_CONNECTABLE flag will only be set once the related HCI commands
succeed. When determining what kind of advertising to do we need to
therefore also check whether there is a pending Set Connectable command
in addition to the current flag value.
The enable_advertising function was already taking care of this for the
advertising type with the help of the get_adv_type function, but was
failing to do the same for the address type selection. This patch
converts the get_adv_type function to be more generic in that it returns
the expected connectable state and updates the enable_advertising
function to use the return value both for the advertising type as well
as the advertising address type.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/mgmt.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 25b8b278debd..a02828ad4c0e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -817,10 +817,9 @@ static void update_class(struct hci_request *req)
hci_req_add(req, HCI_OP_WRITE_CLASS_OF_DEV, sizeof(cod), cod);
}
-static u8 get_adv_type(struct hci_dev *hdev)
+static bool get_connectable(struct hci_dev *hdev)
{
struct pending_cmd *cmd;
- bool connectable;
/* If there's a pending mgmt command the flag will not yet have
* it's final value, so check for this first.
@@ -828,12 +827,10 @@ static u8 get_adv_type(struct hci_dev *hdev)
cmd = mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev);
if (cmd) {
struct mgmt_mode *cp = cmd->param;
- connectable = !!cp->val;
- } else {
- connectable = test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+ return cp->val;
}
- return connectable ? LE_ADV_IND : LE_ADV_NONCONN_IND;
+ return test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
}
static void enable_advertising(struct hci_request *req)
@@ -841,9 +838,10 @@ static void enable_advertising(struct hci_request *req)
struct hci_dev *hdev = req->hdev;
struct hci_cp_le_set_adv_param cp;
u8 own_addr_type, enable = 0x01;
- bool require_privacy;
+ bool connectable, require_privacy;
- require_privacy = !test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+ connectable = get_connectable(hdev);
+ require_privacy = !connectable;
if (hci_update_random_address(req, require_privacy, &own_addr_type) < 0)
return;
@@ -851,7 +849,7 @@ static void enable_advertising(struct hci_request *req)
memset(&cp, 0, sizeof(cp));
cp.min_interval = __constant_cpu_to_le16(0x0800);
cp.max_interval = __constant_cpu_to_le16(0x0800);
- cp.type = get_adv_type(hdev);
+ cp.type = connectable ? LE_ADV_IND : LE_ADV_NONCONN_IND;
cp.own_address_type = own_addr_type;
cp.channel_map = hdev->le_adv_channel_map;
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] Bluetooth: Fix advertising address type when toggling connectable
2014-02-25 13:10 [PATCH] Bluetooth: Fix advertising address type when toggling connectable johan.hedberg
@ 2014-02-25 13:10 ` johan.hedberg
2014-02-25 17:26 ` Marcel Holtmann
0 siblings, 1 reply; 4+ messages in thread
From: johan.hedberg @ 2014-02-25 13:10 UTC (permalink / raw)
To: linux-bluetooth
From: Johan Hedberg <johan.hedberg@intel.com>
When the connectable setting is toggled using mgmt_set_connectable the
HCI_CONNECTABLE flag will only be set once the related HCI commands
succeed. When determining what kind of advertising to do we need to
therefore also check whether there is a pending Set Connectable command
in addition to the current flag value.
The enable_advertising function was already taking care of this for the
advertising type with the help of the get_adv_type function, but was
failing to do the same for the address type selection. This patch
converts the get_adv_type function to be more generic in that it returns
the expected connectable state and updates the enable_advertising
function to use the return value both for the advertising type as well
as the advertising address type.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
net/bluetooth/mgmt.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 25b8b278debd..a02828ad4c0e 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -817,10 +817,9 @@ static void update_class(struct hci_request *req)
hci_req_add(req, HCI_OP_WRITE_CLASS_OF_DEV, sizeof(cod), cod);
}
-static u8 get_adv_type(struct hci_dev *hdev)
+static bool get_connectable(struct hci_dev *hdev)
{
struct pending_cmd *cmd;
- bool connectable;
/* If there's a pending mgmt command the flag will not yet have
* it's final value, so check for this first.
@@ -828,12 +827,10 @@ static u8 get_adv_type(struct hci_dev *hdev)
cmd = mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev);
if (cmd) {
struct mgmt_mode *cp = cmd->param;
- connectable = !!cp->val;
- } else {
- connectable = test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+ return cp->val;
}
- return connectable ? LE_ADV_IND : LE_ADV_NONCONN_IND;
+ return test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
}
static void enable_advertising(struct hci_request *req)
@@ -841,9 +838,10 @@ static void enable_advertising(struct hci_request *req)
struct hci_dev *hdev = req->hdev;
struct hci_cp_le_set_adv_param cp;
u8 own_addr_type, enable = 0x01;
- bool require_privacy;
+ bool connectable, require_privacy;
- require_privacy = !test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+ connectable = get_connectable(hdev);
+ require_privacy = !connectable;
if (hci_update_random_address(req, require_privacy, &own_addr_type) < 0)
return;
@@ -851,7 +849,7 @@ static void enable_advertising(struct hci_request *req)
memset(&cp, 0, sizeof(cp));
cp.min_interval = __constant_cpu_to_le16(0x0800);
cp.max_interval = __constant_cpu_to_le16(0x0800);
- cp.type = get_adv_type(hdev);
+ cp.type = connectable ? LE_ADV_IND : LE_ADV_NONCONN_IND;
cp.own_address_type = own_addr_type;
cp.channel_map = hdev->le_adv_channel_map;
--
1.8.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Bluetooth: Fix advertising address type when toggling connectable
2014-02-25 13:10 ` johan.hedberg
@ 2014-02-25 17:26 ` Marcel Holtmann
2014-02-25 17:32 ` Johan Hedberg
0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2014-02-25 17:26 UTC (permalink / raw)
To: Johan Hedberg; +Cc: bluez mailin list (linux-bluetooth@vger.kernel.org)
Hi Johan,
> When the connectable setting is toggled using mgmt_set_connectable the
> HCI_CONNECTABLE flag will only be set once the related HCI commands
> succeed. When determining what kind of advertising to do we need to
> therefore also check whether there is a pending Set Connectable command
> in addition to the current flag value.
>
> The enable_advertising function was already taking care of this for the
> advertising type with the help of the get_adv_type function, but was
> failing to do the same for the address type selection. This patch
> converts the get_adv_type function to be more generic in that it returns
> the expected connectable state and updates the enable_advertising
> function to use the return value both for the advertising type as well
> as the advertising address type.
>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/mgmt.c | 16 +++++++---------
> 1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> index 25b8b278debd..a02828ad4c0e 100644
> --- a/net/bluetooth/mgmt.c
> +++ b/net/bluetooth/mgmt.c
> @@ -817,10 +817,9 @@ static void update_class(struct hci_request *req)
> hci_req_add(req, HCI_OP_WRITE_CLASS_OF_DEV, sizeof(cod), cod);
> }
>
> -static u8 get_adv_type(struct hci_dev *hdev)
> +static bool get_connectable(struct hci_dev *hdev)
> {
> struct pending_cmd *cmd;
> - bool connectable;
>
> /* If there's a pending mgmt command the flag will not yet have
> * it's final value, so check for this first.
> @@ -828,12 +827,10 @@ static u8 get_adv_type(struct hci_dev *hdev)
> cmd = mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev);
> if (cmd) {
> struct mgmt_mode *cp = cmd->param;
> - connectable = !!cp->val;
> - } else {
> - connectable = test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
> + return cp->val;
> }
>
> - return connectable ? LE_ADV_IND : LE_ADV_NONCONN_IND;
> + return test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
> }
>
> static void enable_advertising(struct hci_request *req)
> @@ -841,9 +838,10 @@ static void enable_advertising(struct hci_request *req)
> struct hci_dev *hdev = req->hdev;
> struct hci_cp_le_set_adv_param cp;
> u8 own_addr_type, enable = 0x01;
> - bool require_privacy;
> + bool connectable, require_privacy;
>
> - require_privacy = !test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
> + connectable = get_connectable(hdev);
> + require_privacy = !connectable;
>
> if (hci_update_random_address(req, require_privacy, &own_addr_type) < 0)
> return;
can we use a comment here to explain require_privacy like we do with the other time it is used. the two variables are too much. And then call it like this ..address(req, !connectable, &own..).
Regards
Marcel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Bluetooth: Fix advertising address type when toggling connectable
2014-02-25 17:26 ` Marcel Holtmann
@ 2014-02-25 17:32 ` Johan Hedberg
0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2014-02-25 17:32 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: bluez mailin list (linux-bluetooth@vger.kernel.org)
Hi Marcel,
On Tue, Feb 25, 2014, Marcel Holtmann wrote:
> > - bool require_privacy;
> > + bool connectable, require_privacy;
> >
> > - require_privacy = !test_bit(HCI_CONNECTABLE, &hdev->dev_flags);
> > + connectable = get_connectable(hdev);
> > + require_privacy = !connectable;
> >
> > if (hci_update_random_address(req, require_privacy, &own_addr_type) < 0)
> > return;
>
> can we use a comment here to explain require_privacy like we do with
> the other time it is used. the two variables are too much. And then
> call it like this ..address(req, !connectable, &own..).
Sure. v2 coming in a few minutes.
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-25 17:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-25 13:10 [PATCH] Bluetooth: Fix advertising address type when toggling connectable johan.hedberg
2014-02-25 13:10 ` johan.hedberg
2014-02-25 17:26 ` Marcel Holtmann
2014-02-25 17:32 ` Johan Hedberg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.