All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Cc: "Felipe F. Tonello" <eu@felipetonello.com>,
	"linux-bluetooth@vger.kernel.org"
	<linux-bluetooth@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>
Subject: Re: [PATCH v5 BlueZ 4/4] Bluetooth: Handle Slave Connection Interval Range AD
Date: Thu, 13 Apr 2017 21:40:05 +0300	[thread overview]
Message-ID: <CABBYNZJDziDgofxfTqGPU+LZN0LE31VSCKHCG_SWH=VSC7bPUg@mail.gmail.com> (raw)
In-Reply-To: <877f2o6u8p.fsf@intel.com>

Hi,

On Thu, Apr 13, 2017 at 9:24 PM, Vinicius Costa Gomes
<vinicius.gomes@intel.com> wrote:
> Hi Felipe,
>
> "Felipe F. Tonello" <eu@felipetonello.com> writes:
>
>> The Slave Connection Interval Range data type contains the Peripheral's
>> preferred connection interval range, for all logical connections.
>>
>> It is useful to parse it in the Kernel so there is no multiple calls to
>> MGMT interface to update the device connection parameters and subsequent
>> connection command call to this device will use proper connection
>> parameters. This saves context-switches and eliminates user-space to
>> update the connection parameters each time a device is found or
>> bluetoothd is restarted and so on. Also, there is no need for the
>> user-space to know care about it because if the slave device wishes to
>> persist with these parameters, it should use the L2CAP connection
>> parameters upade request upon a completed connection.
>
> nitpick: upade -> update
>
>>
>> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
>> ---
>>  net/bluetooth/mgmt.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 53 insertions(+)
>>
>> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
>> index 1fba2a03f8ae..ea5d6c85f173 100644
>> --- a/net/bluetooth/mgmt.c
>> +++ b/net/bluetooth/mgmt.c
>> @@ -7442,6 +7442,46 @@ static bool is_filter_match(struct hci_dev *hdev, s8 rssi, u8 *eir,
>>       return true;
>>  }
>>
>> +static bool has_eir_slave_conn_int(const u8 *eir_data, u8 eir_len,
>> +                                u16 *min_conn, u16 *max_conn)
>> +{
>> +     u16 len = 0;
>> +     const u8 EIR_SLAVE_CONN_INT = 0x12; /* Slave Connection Interval Range */
>> +
>> +     while (len < eir_len - 1) {
>> +             u8 field_len = eir_data[0];
>> +             const u8 *data;
>> +             u8 data_len;
>> +
>> +             /* Check for the end of EIR */
>> +             if (field_len == 0)
>> +                     break;
>> +
>> +             len += field_len + 1;
>> +
>> +             /* Do not continue EIR Data parsing if got
>> +              * incorrect length
>> +              */
>> +             if (len > eir_len)
>> +                     break;
>> +
>> +             data = &eir_data[2];
>> +             data_len = field_len - 1;
>> +
>> +             if (eir_data[1] == EIR_SLAVE_CONN_INT) {
>> +                     if (data_len < 4)
>> +                             break;
>> +                     *min_conn = le16_to_cpu(&data[0]);
>> +                     *max_conn = le16_to_cpu(&data[2]);
>> +                     return true;
>> +             }
>> +
>> +             eir_data += field_len + 1;
>> +     }
>> +
>> +     return false;
>> +}
>> +
>>  void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
>>                      u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
>>                      u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len)
>> @@ -7449,6 +7489,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
>>       char buf[512];
>>       struct mgmt_ev_device_found *ev = (void *)buf;
>>       size_t ev_size;
>> +     struct hci_conn *hcon;
>>
>>       /* Don't send events for a non-kernel initiated discovery. With
>>        * LE one exception is if we have pend_le_reports > 0 in which
>> @@ -7521,6 +7562,18 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
>>       ev->eir_len = cpu_to_le16(eir_len + scan_rsp_len);
>>       ev_size = sizeof(*ev) + eir_len + scan_rsp_len;
>>
>> +     /* Search for Slave Connection Interval AD */
>> +     hcon = hci_conn_hash_lookup_le(hdev, bdaddr, addr_type);
>> +     if (hcon) {
>> +             u16 min_conn_int, max_conn_int;
>> +
>> +             if (has_eir_slave_conn_int(ev->eir, ev->eir_len,
>> +                                        &min_conn_int, &max_conn_int)) {
>> +                     hcon->le_conn_min_interval = min_conn_int;
>> +                     hcon->le_conn_max_interval = max_conn_int;
>> +             }
>> +     }
>> +
>
> It's been some time that I looked at this code, so I could be missing
> something, but I got the feeling that this part would make more sense if
> it was at process_adv_report(), there's even the check for a pending
> connection, so no need to redo that here.

Actually I would use the AD only in case the device is marked for
auto-connect or there is a connection pending, so the parameters are
only used for the connection alone and are not persisted.

> Apart from this, the series looks good.
>
>
>>       mgmt_event(MGMT_EV_DEVICE_FOUND, hdev, ev, ev_size, NULL);
>>  }
>>
>> --
>> 2.12.2
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
> Cheers,
> --
> Vinicius



-- 
Luiz Augusto von Dentz

  reply	other threads:[~2017-04-13 18:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13 12:21 [PATCH v5 BlueZ 0/4] Connection Update improvements Felipe F. Tonello
2017-04-13 12:22 ` [PATCH v5 BlueZ 1/4] Bluetooth: L2CAP: Refactor L2CAP_CONN_PARAM_UPDATE_REQ into a function Felipe F. Tonello
2017-04-13 12:22 ` [PATCH v5 BlueZ 2/4] Bluetooth: L2CAP: Add handler for Connection Parameter Update Response Felipe F. Tonello
2017-04-13 12:22 ` [PATCH v5 BlueZ 3/4] Bluetooth: L2CAP: Add BT_LE_CONN_PARAM socket option Felipe F. Tonello
2017-04-13 12:22 ` [PATCH v5 BlueZ 4/4] Bluetooth: Handle Slave Connection Interval Range AD Felipe F. Tonello
2017-04-13 18:24   ` Vinicius Costa Gomes
2017-04-13 18:40     ` Luiz Augusto von Dentz [this message]
2017-04-13 20:01   ` kbuild test robot
2017-04-13 22:04   ` kbuild test robot

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='CABBYNZJDziDgofxfTqGPU+LZN0LE31VSCKHCG_SWH=VSC7bPUg@mail.gmail.com' \
    --to=luiz.dentz@gmail.com \
    --cc=eu@felipetonello.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=vinicius.gomes@intel.com \
    /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 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.