* [RFC 1/2] Bluetooth: Use controller sets when available
@ 2019-06-03 10:48 Luiz Augusto von Dentz
2019-06-03 10:48 ` [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr Luiz Augusto von Dentz
2019-07-06 13:39 ` [RFC 1/2] Bluetooth: Use controller sets when available Marcel Holtmann
0 siblings, 2 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2019-06-03 10:48 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes use of controller sets when using Extended Advertising
feature thus offloading the scheduling to the controller.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/hci_conn.c | 2 +-
net/bluetooth/hci_core.c | 3 ++-
net/bluetooth/hci_request.c | 40 ++++++++++++++++++++++++++++++-------
net/bluetooth/hci_request.h | 2 +-
4 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index bd4978ce8c45..1d2fa24d752f 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -912,7 +912,7 @@ static void hci_req_directed_advertising(struct hci_request *req,
sizeof(cp), &cp);
}
- __hci_req_enable_ext_advertising(req);
+ __hci_req_enable_ext_advertising(req, 0x00);
} else {
struct hci_cp_le_set_adv_param cp;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d6b2540ba7f8..9547354a9773 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2829,7 +2829,7 @@ int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags,
memset(adv_instance->scan_rsp_data, 0,
sizeof(adv_instance->scan_rsp_data));
} else {
- if (hdev->adv_instance_cnt >= HCI_MAX_ADV_INSTANCES ||
+ if (hdev->adv_instance_cnt >= hdev->le_num_of_adv_sets ||
instance < 1 || instance > HCI_MAX_ADV_INSTANCES)
return -EOVERFLOW;
@@ -3197,6 +3197,7 @@ struct hci_dev *hci_alloc_dev(void)
hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE;
hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M;
hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M;
+ hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES;
hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT;
hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT;
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index ca73d36cc149..5970d77f9911 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -1596,7 +1596,7 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)
cp.own_addr_type = own_addr_type;
cp.channel_map = hdev->le_adv_channel_map;
cp.tx_power = 127;
- cp.handle = 0;
+ cp.handle = instance;
if (flags & MGMT_ADV_FLAG_SEC_2M) {
cp.primary_phy = HCI_ADV_PHY_1M;
@@ -1638,11 +1638,21 @@ int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance)
return 0;
}
-void __hci_req_enable_ext_advertising(struct hci_request *req)
+int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance)
{
+ struct hci_dev *hdev = req->hdev;
struct hci_cp_le_set_ext_adv_enable *cp;
struct hci_cp_ext_adv_set *adv_set;
u8 data[sizeof(*cp) + sizeof(*adv_set) * 1];
+ struct adv_info *adv_instance;
+
+ if (instance > 0) {
+ adv_instance = hci_find_adv_instance(hdev, instance);
+ if (!adv_instance)
+ return -EINVAL;
+ } else {
+ adv_instance = NULL;
+ }
cp = (void *) data;
adv_set = (void *) cp->data;
@@ -1654,11 +1664,23 @@ void __hci_req_enable_ext_advertising(struct hci_request *req)
memset(adv_set, 0, sizeof(*adv_set));
- adv_set->handle = 0;
+ adv_set->handle = instance;
+
+ /* Set duration per instance since controller is responsible for
+ * scheduling it.
+ */
+ if (adv_instance && adv_instance->duration) {
+ u16 duration = adv_instance->duration * MSEC_PER_SEC;
+
+ /* Time = N * 10 ms */
+ adv_set->duration = cpu_to_le16(duration / 10);
+ }
hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_ENABLE,
sizeof(*cp) + sizeof(*adv_set) * cp->num_of_sets,
data);
+
+ return 0;
}
int __hci_req_start_ext_adv(struct hci_request *req, u8 instance)
@@ -1674,7 +1696,7 @@ int __hci_req_start_ext_adv(struct hci_request *req, u8 instance)
return err;
__hci_req_update_scan_rsp_data(req, instance);
- __hci_req_enable_ext_advertising(req);
+ __hci_req_enable_ext_advertising(req, instance);
return 0;
}
@@ -1718,10 +1740,13 @@ int __hci_req_schedule_adv_instance(struct hci_request *req, u8 instance,
adv_instance->remaining_time =
adv_instance->remaining_time - timeout;
- hdev->adv_instance_timeout = timeout;
- queue_delayed_work(hdev->req_workqueue,
+ /* Only use work for scheduling instaces with legacy advertising */
+ if (!ext_adv_capable(hdev)) {
+ hdev->adv_instance_timeout = timeout;
+ queue_delayed_work(hdev->req_workqueue,
&hdev->adv_instance_expire,
msecs_to_jiffies(timeout * 1000));
+ }
/* If we're just re-scheduling the same instance again then do not
* execute any HCI commands. This happens when a single instance is
@@ -2739,7 +2764,8 @@ static int powered_update_hci(struct hci_request *req, unsigned long opt)
if (!ext_adv_capable(hdev))
__hci_req_enable_advertising(req);
else if (!err)
- __hci_req_enable_ext_advertising(req);
+ __hci_req_enable_ext_advertising(req,
+ 0x00);
}
} else if (!list_empty(&hdev->adv_instances)) {
struct adv_info *adv_instance;
diff --git a/net/bluetooth/hci_request.h b/net/bluetooth/hci_request.h
index 692cc8b13368..ea4191c76fb3 100644
--- a/net/bluetooth/hci_request.h
+++ b/net/bluetooth/hci_request.h
@@ -82,7 +82,7 @@ void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk,
int __hci_req_setup_ext_adv_instance(struct hci_request *req, u8 instance);
int __hci_req_start_ext_adv(struct hci_request *req, u8 instance);
-void __hci_req_enable_ext_advertising(struct hci_request *req);
+int __hci_req_enable_ext_advertising(struct hci_request *req, u8 instance);
void __hci_req_clear_ext_adv_sets(struct hci_request *req);
int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
bool use_rpa, struct adv_info *adv_instance,
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr
2019-06-03 10:48 [RFC 1/2] Bluetooth: Use controller sets when available Luiz Augusto von Dentz
@ 2019-06-03 10:48 ` Luiz Augusto von Dentz
2019-07-03 13:57 ` Luiz Augusto von Dentz
2019-07-06 13:39 ` Marcel Holtmann
2019-07-06 13:39 ` [RFC 1/2] Bluetooth: Use controller sets when available Marcel Holtmann
1 sibling, 2 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2019-06-03 10:48 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The spec defines PSM and LE_PSM as different domains so a listen on the
same PSM is valid if the address type points to a different bearer.
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/l2cap_core.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index b53acd6c9a3d..8da73ca8c111 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -168,11 +168,18 @@ static struct l2cap_chan *l2cap_get_chan_by_ident(struct l2cap_conn *conn,
return c;
}
-static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src)
+static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src,
+ u8 src_type)
{
struct l2cap_chan *c;
list_for_each_entry(c, &chan_list, global_l) {
+ if (src_type == BDADDR_BREDR && c->src_type != BDADDR_BREDR)
+ continue;
+
+ if (src_type != BDADDR_BREDR && c->src_type == BDADDR_BREDR)
+ continue;
+
if (c->sport == psm && !bacmp(&c->src, src))
return c;
}
@@ -185,7 +192,7 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
write_lock(&chan_list_lock);
- if (psm && __l2cap_global_chan_by_addr(psm, src)) {
+ if (psm && __l2cap_global_chan_by_addr(psm, src, chan->src_type)) {
err = -EADDRINUSE;
goto done;
}
@@ -209,7 +216,8 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
err = -EINVAL;
for (p = start; p <= end; p += incr)
- if (!__l2cap_global_chan_by_addr(cpu_to_le16(p), src)) {
+ if (!__l2cap_global_chan_by_addr(cpu_to_le16(p), src,
+ chan->src_type)) {
chan->psm = cpu_to_le16(p);
chan->sport = cpu_to_le16(p);
err = 0;
--
2.21.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr
2019-06-03 10:48 ` [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr Luiz Augusto von Dentz
@ 2019-07-03 13:57 ` Luiz Augusto von Dentz
2019-07-06 13:39 ` Marcel Holtmann
1 sibling, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2019-07-03 13:57 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Johan Hedberg, Marcel Holtmann
Hi Marcel, Johan,
On Mon, Jun 3, 2019 at 1:48 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> The spec defines PSM and LE_PSM as different domains so a listen on the
> same PSM is valid if the address type points to a different bearer.
>
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index b53acd6c9a3d..8da73ca8c111 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -168,11 +168,18 @@ static struct l2cap_chan *l2cap_get_chan_by_ident(struct l2cap_conn *conn,
> return c;
> }
>
> -static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src)
> +static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src,
> + u8 src_type)
> {
> struct l2cap_chan *c;
>
> list_for_each_entry(c, &chan_list, global_l) {
> + if (src_type == BDADDR_BREDR && c->src_type != BDADDR_BREDR)
> + continue;
> +
> + if (src_type != BDADDR_BREDR && c->src_type == BDADDR_BREDR)
> + continue;
> +
> if (c->sport == psm && !bacmp(&c->src, src))
> return c;
> }
> @@ -185,7 +192,7 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
>
> write_lock(&chan_list_lock);
>
> - if (psm && __l2cap_global_chan_by_addr(psm, src)) {
> + if (psm && __l2cap_global_chan_by_addr(psm, src, chan->src_type)) {
> err = -EADDRINUSE;
> goto done;
> }
> @@ -209,7 +216,8 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
>
> err = -EINVAL;
> for (p = start; p <= end; p += incr)
> - if (!__l2cap_global_chan_by_addr(cpu_to_le16(p), src)) {
> + if (!__l2cap_global_chan_by_addr(cpu_to_le16(p), src,
> + chan->src_type)) {
> chan->psm = cpu_to_le16(p);
> chan->sport = cpu_to_le16(p);
> err = 0;
> --
> 2.21.0
Any chance to review this one.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr
2019-06-03 10:48 ` [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr Luiz Augusto von Dentz
2019-07-03 13:57 ` Luiz Augusto von Dentz
@ 2019-07-06 13:39 ` Marcel Holtmann
1 sibling, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2019-07-06 13:39 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
> The spec defines PSM and LE_PSM as different domains so a listen on the
> same PSM is valid if the address type points to a different bearer.
>
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC 1/2] Bluetooth: Use controller sets when available
2019-06-03 10:48 [RFC 1/2] Bluetooth: Use controller sets when available Luiz Augusto von Dentz
2019-06-03 10:48 ` [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr Luiz Augusto von Dentz
@ 2019-07-06 13:39 ` Marcel Holtmann
1 sibling, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2019-07-06 13:39 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
> This makes use of controller sets when using Extended Advertising
> feature thus offloading the scheduling to the controller.
>
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> net/bluetooth/hci_conn.c | 2 +-
> net/bluetooth/hci_core.c | 3 ++-
> net/bluetooth/hci_request.c | 40 ++++++++++++++++++++++++++++++-------
> net/bluetooth/hci_request.h | 2 +-
> 4 files changed, 37 insertions(+), 10 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-07-06 13:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-03 10:48 [RFC 1/2] Bluetooth: Use controller sets when available Luiz Augusto von Dentz
2019-06-03 10:48 ` [RFC 2/2] Bluetooth: L2CAP: Check bearer type on __l2cap_global_chan_by_addr Luiz Augusto von Dentz
2019-07-03 13:57 ` Luiz Augusto von Dentz
2019-07-06 13:39 ` Marcel Holtmann
2019-07-06 13:39 ` [RFC 1/2] Bluetooth: Use controller sets when available Marcel Holtmann
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).