From: Szymon Janc <szymon.janc@gmail.com>
To: Marcin Kraglak <marcin.kraglak@tieto.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCHv5 05/14] shared/gatt: Add included service iterator
Date: Wed, 22 Oct 2014 20:43:50 +0200 [thread overview]
Message-ID: <3761978.EAA0JlRKJm@athlon> (raw)
In-Reply-To: <1413454646-23076-6-git-send-email-marcin.kraglak@tieto.com>
Hi Marcin,
On Thursday 16 October 2014 12:17:17 Marcin Kraglak wrote:
> It will fetch included services from result.
> ---
> src/shared/gatt-helpers.c | 58
> +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/gatt-helpers.h |
> 3 +++
> 2 files changed, 61 insertions(+)
>
> diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
> index 58104d9..fd8d06c 100644
> --- a/src/shared/gatt-helpers.c
> +++ b/src/shared/gatt-helpers.c
> @@ -186,6 +186,64 @@ struct discovery_op {
> bt_gatt_destroy_func_t destroy;
> };
>
> +bool bt_gatt_iter_next_included_service(struct bt_gatt_iter *iter,
> + uint16_t *handle, uint16_t *start_handle,
> + uint16_t *end_handle, uint8_t uuid[16])
> +{
> + struct bt_gatt_result *read_result;
> + const void *pdu_ptr;
> + int i = 0;
> +
> + if (!iter || !iter->result || !handle || !start_handle || !end_handle
> + || !uuid)
> + return false;
> +
> + if (iter->result->opcode != BT_ATT_OP_READ_BY_TYPE_RSP)
> + return false;
> +
> + if (iter->result->data_len != 8 && iter->result->data_len != 6)
> + return false;
> +
> + pdu_ptr = iter->result->pdu + iter->pos;
> +
> + if (iter->result->data_len == 8) {
> + *handle = get_le16(pdu_ptr);
> + *start_handle = get_le16(pdu_ptr + 2);
> + *end_handle = get_le16(pdu_ptr + 4);
> + convert_uuid_le(pdu_ptr + 6, 2, uuid);
> +
> + iter->pos += iter->result->data_len;
> +
> + if (iter->pos == iter->result->pdu_len) {
> + iter->result = iter->result->next;
> + iter->pos = 0;
> + }
> +
> + return true;
> + }
> +
> + *handle = get_le16(pdu_ptr);
> + *start_handle = get_le16(pdu_ptr + 2);
> + *end_handle = get_le16(pdu_ptr + 4);
> + read_result = iter->result;
> +
> + do {
> + read_result = read_result->next;
> + } while (read_result && i++ < (iter->pos / iter->result->data_len));
This loop looks quite unusual. Maybe use for and break inside?
Also please put some comment about those calculations.
> +
> + if (!read_result)
> + return false;
> +
> + convert_uuid_le(read_result->pdu, read_result->data_len, uuid);
> + iter->pos += iter->result->data_len;
> + if (iter->pos == iter->result->pdu_len) {
> + iter->result = read_result->next;
> + iter->pos = 0;
> + }
> +
> + return true;
> +}
> +
> bool bt_gatt_iter_next_service(struct bt_gatt_iter *iter,
> uint16_t *start_handle, uint16_t *end_handle,
> uint8_t uuid[16])
> diff --git a/src/shared/gatt-helpers.h b/src/shared/gatt-helpers.h
> index 8a25dea..8c434c1 100644
> --- a/src/shared/gatt-helpers.h
> +++ b/src/shared/gatt-helpers.h
> @@ -49,6 +49,9 @@ bool bt_gatt_iter_next_characteristic(struct bt_gatt_iter
> *iter, uint8_t uuid[16]);
> bool bt_gatt_iter_next_descriptor(struct bt_gatt_iter *iter, uint16_t
> *handle, uint8_t uuid[16]);
> +bool bt_gatt_iter_next_included_service(struct bt_gatt_iter *iter,
> + uint16_t *handle, uint16_t *start_handle,
> + uint16_t *end_handle, uint8_t uuid[16]);
>
> typedef void (*bt_gatt_destroy_func_t)(void *user_data);
--
Szymon K. Janc
szymon.janc@gmail.com
next prev parent reply other threads:[~2014-10-22 18:43 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-16 10:17 [PATCHv5 00/14] Included service discovery Marcin Kraglak
2014-10-16 10:17 ` [PATCHv5 01/14] shared/gatt: Add discover_secondary_services() Marcin Kraglak
2014-10-22 13:37 ` Szymon Janc
2014-10-16 10:17 ` [PATCHv5 02/14] shared/gatt: Add initial implementation of discover_included_services Marcin Kraglak
2014-10-22 13:37 ` Szymon Janc
2014-10-16 10:17 ` [PATCHv5 03/14] shared/gatt: Discover included services 128 bit UUIDS Marcin Kraglak
2014-10-22 18:43 ` Szymon Janc
2014-10-16 10:17 ` [PATCHv5 04/14] shared/gatt: Add extra check in characteristic iterator Marcin Kraglak
2014-10-22 17:49 ` Szymon Janc
2014-10-16 10:17 ` [PATCHv5 05/14] shared/gatt: Add included service iterator Marcin Kraglak
2014-10-22 18:43 ` Szymon Janc [this message]
2014-10-16 10:17 ` [PATCHv5 06/14] shared/gatt: Remove not needed function parameter Marcin Kraglak
2014-10-16 10:17 ` [PATCHv5 07/14] shared/gatt: Distinguish Primary from Secondary services Marcin Kraglak
2014-10-16 10:17 ` [PATCHv5 08/14] tools/btgatt-client: Print type of service Marcin Kraglak
2014-10-22 18:00 ` Szymon Janc
2014-10-16 10:17 ` [PATCHv5 09/14] shared/gatt: Discover secondary services Marcin Kraglak
2014-10-16 10:17 ` [PATCHv5 10/14] shared/gatt: Discover included services Marcin Kraglak
2014-10-22 18:20 ` Szymon Janc
2014-10-16 10:17 ` [PATCHv5 11/14] shared/gatt: Add gatt-client include service iterator Marcin Kraglak
2014-10-22 18:29 ` Szymon Janc
2014-10-16 10:17 ` [PATCHv5 12/14] tools/btgatt-client: Print found include services Marcin Kraglak
2014-10-16 10:17 ` [PATCHv5 13/14] shared/gatt: Fix searching descriptors Marcin Kraglak
2014-10-16 10:17 ` [PATCHv5 14/14] shared/gatt: Add function bt_gatt_result_included_count() Marcin Kraglak
2014-10-22 6:25 ` [PATCHv5 00/14] Included service discovery Marcin Kraglak
2014-10-22 14:54 ` Luiz Augusto von Dentz
2014-10-22 15:35 ` Arman Uguray
2014-10-22 18:39 ` Szymon Janc
2014-10-23 7:55 ` Luiz Augusto von Dentz
2014-10-24 19:32 ` Arman Uguray
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=3761978.EAA0JlRKJm@athlon \
--to=szymon.janc@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcin.kraglak@tieto.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 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).