* [PATCHv4 13/14] tools/btgatt-client: Print found include services
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
---
tools/btgatt-client.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 5c692ff..5465d53 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -174,7 +174,9 @@ static void print_uuid(const uint8_t uuid[16])
static void print_service(const bt_gatt_service_t *service)
{
struct bt_gatt_characteristic_iter iter;
+ struct bt_gatt_incl_service_iter include_iter;
const bt_gatt_characteristic_t *chrc;
+ const bt_gatt_included_service_t *incl;
size_t i;
if (!bt_gatt_characteristic_iter_init(&iter, service)) {
@@ -182,12 +184,24 @@ static void print_service(const bt_gatt_service_t *service)
return;
}
+ if (!bt_gatt_include_service_iter_init(&include_iter, service)) {
+ PRLOG("Failed to initialize include service iterator\n");
+ return;
+ }
printf(COLOR_RED "service %s" COLOR_OFF " - start: 0x%04x, "
"end: 0x%04x, uuid: ",
service->primary ? "primary" : "second.",
service->start_handle, service->end_handle);
print_uuid(service->uuid);
+ while (bt_gatt_include_service_iter_next(&include_iter, &incl)) {
+ printf("\t " COLOR_GREEN "include" COLOR_OFF " - handle: "
+ "0x%04x, - start: 0x%04x, end: 0x%04x,"
+ "uuid: ", incl->handle,
+ incl->start_handle, incl->end_handle);
+ print_uuid(incl->uuid);
+ }
+
while (bt_gatt_characteristic_iter_next(&iter, &chrc)) {
printf("\t " COLOR_YELLOW "charac" COLOR_OFF
" - start: 0x%04x, end: 0x%04x, "
--
1.9.3
^ permalink raw reply related
* [PATCHv4 12/14] shared/gatt: Add gatt-client include service iterator
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
It will allow user to take value, handle, start and end handle
of included service.
---
src/shared/gatt-client.c | 30 ++++++++++++++++++++++++++++++
src/shared/gatt-client.h | 10 ++++++++++
2 files changed, 40 insertions(+)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 80d7a1a..679242c 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -1673,6 +1673,36 @@ bool bt_gatt_characteristic_iter_next(struct bt_gatt_characteristic_iter *iter,
return true;
}
+bool bt_gatt_include_service_iter_init(struct bt_gatt_incl_service_iter *iter,
+ const bt_gatt_service_t *service)
+{
+ if (!iter || !service)
+ return false;
+
+ memset(iter, 0, sizeof(*iter));
+ iter->service = (struct service_list *) service;
+
+ return true;
+}
+
+bool bt_gatt_include_service_iter_next(struct bt_gatt_incl_service_iter *iter,
+ const bt_gatt_included_service_t **incl)
+{
+ struct service_list *service;
+
+ if (!iter || !incl)
+ return false;
+
+ service = iter->service;
+
+ if (iter->pos >= service->num_includes)
+ return false;
+
+ *incl = &service->includes[iter->pos++];
+
+ return true;
+}
+
struct read_op {
bt_gatt_client_read_callback_t callback;
void *user_data;
diff --git a/src/shared/gatt-client.h b/src/shared/gatt-client.h
index 05b4838..bf4e7bb 100644
--- a/src/shared/gatt-client.h
+++ b/src/shared/gatt-client.h
@@ -113,6 +113,11 @@ struct bt_gatt_characteristic_iter {
size_t pos;
};
+struct bt_gatt_incl_service_iter {
+ void *service;
+ size_t pos;
+};
+
bool bt_gatt_service_iter_init(struct bt_gatt_service_iter *iter,
struct bt_gatt_client *client);
bool bt_gatt_service_iter_next(struct bt_gatt_service_iter *iter,
@@ -129,6 +134,11 @@ bool bt_gatt_characteristic_iter_init(struct bt_gatt_characteristic_iter *iter,
bool bt_gatt_characteristic_iter_next(struct bt_gatt_characteristic_iter *iter,
const bt_gatt_characteristic_t **chrc);
+bool bt_gatt_include_service_iter_init(struct bt_gatt_incl_service_iter *iter,
+ const bt_gatt_service_t *service);
+bool bt_gatt_include_service_iter_next(struct bt_gatt_incl_service_iter *iter,
+ const bt_gatt_included_service_t **inc);
+
typedef void (*bt_gatt_client_read_callback_t)(bool success, uint8_t att_ecode,
const uint8_t *value, uint16_t length,
void *user_data);
--
1.9.3
^ permalink raw reply related
* [PATCHv4 11/14] shared/gatt: Discover included services
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
---
src/shared/gatt-client.c | 114 +++++++++++++++++++++++++++++++++++++++++++++--
src/shared/gatt-client.h | 7 +++
2 files changed, 117 insertions(+), 4 deletions(-)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 9a0ec35..80d7a1a 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -69,6 +69,8 @@ struct service_list {
bt_gatt_service_t service;
struct chrc_data *chrcs;
size_t num_chrcs;
+ bt_gatt_included_service_t *includes;
+ size_t num_includes;
struct service_list *next;
};
@@ -253,6 +255,14 @@ static void service_destroy_characteristics(struct service_list *service)
free(service->chrcs);
}
+static void service_destroy_includes(struct service_list *service)
+{
+ free(service->includes);
+
+ service->includes = NULL;
+ service->num_includes = 0;
+}
+
static void service_list_clear(struct service_list **head,
struct service_list **tail)
{
@@ -265,6 +275,7 @@ static void service_list_clear(struct service_list **head,
while (l) {
service_destroy_characteristics(l);
+ service_destroy_includes(l);
tmp = l;
l = tmp->next;
free(tmp);
@@ -293,6 +304,7 @@ static void service_list_clear_range(struct service_list **head,
}
service_destroy_characteristics(cur);
+ service_destroy_includes(cur);
if (!prev)
*head = cur->next;
@@ -428,6 +440,99 @@ static int uuid_cmp(const uint8_t uuid128[16], uint16_t uuid16)
return memcmp(uuid128, rhs_uuid, sizeof(rhs_uuid));
}
+static void discover_incl_cb(bool success, uint8_t att_ecode,
+ struct bt_gatt_result *result,
+ void *user_data)
+{
+ struct discovery_op *op = user_data;
+ struct bt_gatt_client *client = op->client;
+ struct bt_gatt_iter iter;
+ char uuid_str[MAX_LEN_UUID_STR];
+ bt_gatt_included_service_t *includes;
+ unsigned int includes_count, i;
+
+ if (!success) {
+ if (att_ecode == BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) {
+ success = true;
+ goto next;
+ }
+
+ goto done;
+ }
+
+ if (!result || !bt_gatt_iter_init(&iter, result)) {
+ success = false;
+ goto done;
+ }
+
+ includes_count = bt_gatt_result_included_count(result);
+ if (includes_count == 0) {
+ success = false;
+ goto done;
+ }
+
+ includes = new0(bt_gatt_included_service_t, includes_count);
+ if (!includes) {
+ success = false;
+ goto done;
+ }
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Included services found: %u",
+ includes_count);
+
+ i = 0;
+ while (bt_gatt_iter_next_included_service(&iter, &includes[i].handle,
+ &includes[i].start_handle,
+ &includes[i].end_handle,
+ includes[i].uuid)) {
+ uuid_to_string(includes[i].uuid, uuid_str);
+ util_debug(client->debug_callback, client->debug_data,
+ "handle: 0x%04x, start: 0x%04x, end: 0x%04x,"
+ "uuid: %s", includes[i].handle,
+ includes[i].start_handle,
+ includes[i].end_handle, uuid_str);
+ i++;
+ }
+
+ op->cur_service->includes = includes;
+ op->cur_service->num_includes = includes_count;
+
+next:
+ if (!op->cur_service->next) {
+ op->cur_service = op->result_head;
+ if (bt_gatt_discover_characteristics(client->att,
+ op->cur_service->service.start_handle,
+ op->cur_service->service.end_handle,
+ discover_chrcs_cb,
+ discovery_op_ref(op),
+ discovery_op_unref))
+ return;
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Failed to start characteristic discovery");
+ discovery_op_unref(op);
+ success = false;
+ goto done;
+ }
+
+ op->cur_service = op->cur_service->next;
+ if (bt_gatt_discover_included_services(client->att,
+ op->cur_service->service.start_handle,
+ op->cur_service->service.end_handle,
+ discover_incl_cb,
+ discovery_op_ref(op),
+ discovery_op_unref))
+ return;
+ util_debug(client->debug_callback, client->debug_data,
+ "Failed to start included discovery");
+ discovery_op_unref(op);
+ success = false;
+
+done:
+ op->complete_func(op, success, att_ecode);
+}
+
static void discover_descs_cb(bool success, uint8_t att_ecode,
struct bt_gatt_result *result,
void *user_data)
@@ -532,6 +637,7 @@ done:
op->complete_func(op, success, att_ecode);
}
+
static void discover_chrcs_cb(bool success, uint8_t att_ecode,
struct bt_gatt_result *result,
void *user_data)
@@ -702,18 +808,18 @@ static void discover_secondary_cb(bool success, uint8_t att_ecode,
}
next:
- /* Sequentially discover the characteristics of all services */
+ /* Sequentially discover included services */
op->cur_service = op->result_head;
- if (bt_gatt_discover_characteristics(client->att,
+ if (bt_gatt_discover_included_services(client->att,
op->cur_service->service.start_handle,
op->cur_service->service.end_handle,
- discover_chrcs_cb,
+ discover_incl_cb,
discovery_op_ref(op),
discovery_op_unref))
return;
util_debug(client->debug_callback, client->debug_data,
- "Failed to start characteristic discovery");
+ "Failed to start included services discovery");
discovery_op_unref(op);
success = false;
diff --git a/src/shared/gatt-client.h b/src/shared/gatt-client.h
index 22d4dc0..05b4838 100644
--- a/src/shared/gatt-client.h
+++ b/src/shared/gatt-client.h
@@ -96,6 +96,13 @@ typedef struct {
size_t num_descs;
} bt_gatt_characteristic_t;
+typedef struct {
+ uint16_t handle;
+ uint16_t start_handle;
+ uint16_t end_handle;
+ uint8_t uuid[BT_GATT_UUID_SIZE];
+} bt_gatt_included_service_t;
+
struct bt_gatt_service_iter {
struct bt_gatt_client *client;
void *ptr;
--
1.9.3
^ permalink raw reply related
* [PATCHv4 10/14] shared/gatt: Discover secondary services
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
Add searching of secondary services in gatt-client.
---
src/shared/gatt-client.c | 116 +++++++++++++++++++++++++++++++++++++++++------
1 file changed, 103 insertions(+), 13 deletions(-)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 724fde2..9a0ec35 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -200,23 +200,36 @@ static void mark_notify_data_invalid_if_in_range(void *data, void *user_data)
notify_data->invalid = true;
}
-static bool service_list_add_service(struct service_list **head,
- struct service_list **tail,
- bool primary, uint16_t start,
- uint16_t end,
+static struct service_list *new_service_list(uint16_t start, uint16_t end,
+ bool primary,
uint8_t uuid[BT_GATT_UUID_SIZE])
{
struct service_list *list;
list = new0(struct service_list, 1);
if (!list)
- return false;
+ return NULL;
list->service.primary = primary;
list->service.start_handle = start;
list->service.end_handle = end;
memcpy(list->service.uuid, uuid, UUID_BYTES);
+ return list;
+}
+
+static bool service_list_add_service(struct service_list **head,
+ struct service_list **tail,
+ bool primary, uint16_t start,
+ uint16_t end,
+ uint8_t uuid[BT_GATT_UUID_SIZE])
+{
+ struct service_list *list;
+
+ list = new_service_list(start, end, primary, uuid);
+ if (!list)
+ return false;
+
if (!(*head))
*head = *tail = list;
else {
@@ -364,6 +377,8 @@ struct discovery_op {
struct bt_gatt_client *client;
struct service_list *result_head, *result_tail, *cur_service;
struct chrc_data *cur_chrc;
+ uint16_t start;
+ uint16_t end;
int cur_chrc_index;
int ref_count;
void (*complete_func)(struct discovery_op *op, bool success,
@@ -634,6 +649,78 @@ done:
op->complete_func(op, success, att_ecode);
}
+static void discover_secondary_cb(bool success, uint8_t att_ecode,
+ struct bt_gatt_result *result,
+ void *user_data)
+{
+ struct discovery_op *op = user_data;
+ struct bt_gatt_client *client = op->client;
+ struct bt_gatt_iter iter;
+ uint16_t start, end;
+ uint8_t uuid[BT_GATT_UUID_SIZE];
+ char uuid_str[MAX_LEN_UUID_STR];
+ struct service_list *service;
+
+ if (!success) {
+ util_debug(client->debug_callback, client->debug_data,
+ "Secondary service discovery failed."
+ " ATT ECODE: 0x%02x", att_ecode);
+ if (att_ecode == BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) {
+ success = true;
+ goto next;
+ }
+
+ goto done;
+ }
+
+ if (!result || !bt_gatt_iter_init(&iter, result)) {
+ success = false;
+ goto done;
+ }
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Secondary services found: %u",
+ bt_gatt_result_service_count(result));
+
+ while (bt_gatt_iter_next_service(&iter, &start, &end, uuid)) {
+ uuid_to_string(uuid, uuid_str);
+ util_debug(client->debug_callback, client->debug_data,
+ "start: 0x%04x, end: 0x%04x, uuid: %s",
+ start, end, uuid_str);
+
+ /* Store the service */
+ service = new_service_list(start, end, false, uuid);
+ if (!service) {
+ util_debug(client->debug_callback, client->debug_data,
+ "Failed to create service");
+ success = false;
+ goto done;
+ }
+
+ service_list_insert_services(&op->result_head, &op->result_tail,
+ service, service);
+ }
+
+next:
+ /* Sequentially discover the characteristics of all services */
+ op->cur_service = op->result_head;
+ if (bt_gatt_discover_characteristics(client->att,
+ op->cur_service->service.start_handle,
+ op->cur_service->service.end_handle,
+ discover_chrcs_cb,
+ discovery_op_ref(op),
+ discovery_op_unref))
+ return;
+
+ util_debug(client->debug_callback, client->debug_data,
+ "Failed to start characteristic discovery");
+ discovery_op_unref(op);
+ success = false;
+
+done:
+ op->complete_func(op, success, att_ecode);
+}
+
static void discover_primary_cb(bool success, uint8_t att_ecode,
struct bt_gatt_result *result,
void *user_data)
@@ -686,18 +773,17 @@ static void discover_primary_cb(bool success, uint8_t att_ecode,
if (!op->result_head)
goto done;
- /* Sequentially discover the characteristics of all services */
+ /* Discover secondary services */
op->cur_service = op->result_head;
- if (bt_gatt_discover_characteristics(client->att,
- op->cur_service->service.start_handle,
- op->cur_service->service.end_handle,
- discover_chrcs_cb,
- discovery_op_ref(op),
- discovery_op_unref))
+ if (bt_gatt_discover_secondary_services(client->att, NULL,
+ op->start, op->end,
+ discover_secondary_cb,
+ discovery_op_ref(op),
+ discovery_op_unref))
return;
util_debug(client->debug_callback, client->debug_data,
- "Failed to start characteristic discovery");
+ "Failed to start secondary service discovery");
discovery_op_unref(op);
success = false;
@@ -870,6 +956,8 @@ static void process_service_changed(struct bt_gatt_client *client,
op->client = client;
op->complete_func = service_changed_complete;
+ op->start = start_handle;
+ op->end = end_handle;
if (!bt_gatt_discover_primary_services(client->att, NULL,
start_handle, end_handle,
@@ -1002,6 +1090,8 @@ static bool gatt_client_init(struct bt_gatt_client *client, uint16_t mtu)
op->client = client;
op->complete_func = init_complete;
+ op->start = 0x0001;
+ op->end = 0xffff;
/* Configure the MTU */
if (!bt_gatt_exchange_mtu(client->att, MAX(BT_ATT_DEFAULT_LE_MTU, mtu),
--
1.9.3
^ permalink raw reply related
* [PATCHv4 09/14] tools/btgatt-client: Print type of service
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
---
tools/btgatt-client.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index d900e08..5c692ff 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -182,8 +182,9 @@ static void print_service(const bt_gatt_service_t *service)
return;
}
- printf(COLOR_RED "service" COLOR_OFF " - start: 0x%04x, "
+ printf(COLOR_RED "service %s" COLOR_OFF " - start: 0x%04x, "
"end: 0x%04x, uuid: ",
+ service->primary ? "primary" : "second.",
service->start_handle, service->end_handle);
print_uuid(service->uuid);
--
1.9.3
^ permalink raw reply related
* [PATCHv4 08/14] shared/gatt: Distinguish Primary from Secondary services
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
Add flag primary to distinguish service as primary or secondary.
---
src/shared/gatt-client.c | 7 +++++--
src/shared/gatt-client.h | 1 +
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 03d722f..724fde2 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -202,7 +202,8 @@ static void mark_notify_data_invalid_if_in_range(void *data, void *user_data)
static bool service_list_add_service(struct service_list **head,
struct service_list **tail,
- uint16_t start, uint16_t end,
+ bool primary, uint16_t start,
+ uint16_t end,
uint8_t uuid[BT_GATT_UUID_SIZE])
{
struct service_list *list;
@@ -211,6 +212,7 @@ static bool service_list_add_service(struct service_list **head,
if (!list)
return false;
+ list->service.primary = primary;
list->service.start_handle = start;
list->service.end_handle = end;
memcpy(list->service.uuid, uuid, UUID_BYTES);
@@ -668,7 +670,8 @@ static void discover_primary_cb(bool success, uint8_t att_ecode,
/* Store the service */
if (!service_list_add_service(&op->result_head,
- &op->result_tail, start, end, uuid)) {
+ &op->result_tail, true, start, end,
+ uuid)) {
util_debug(client->debug_callback, client->debug_data,
"Failed to store service");
success = false;
diff --git a/src/shared/gatt-client.h b/src/shared/gatt-client.h
index 6807f6b..22d4dc0 100644
--- a/src/shared/gatt-client.h
+++ b/src/shared/gatt-client.h
@@ -75,6 +75,7 @@ bool bt_gatt_client_set_debug(struct bt_gatt_client *client,
bt_gatt_client_destroy_func_t destroy);
typedef struct {
+ bool primary;
uint16_t start_handle;
uint16_t end_handle;
uint8_t uuid[BT_GATT_UUID_SIZE];
--
1.9.3
^ permalink raw reply related
* [PATCHv4 07/14] shared/gatt: Add function bt_gatt_result_included_count()
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
It will return number of included services in result.
---
src/shared/gatt-helpers.c | 21 +++++++++++++++++++++
src/shared/gatt-helpers.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index 48e7379..92d0696 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -140,6 +140,27 @@ unsigned int bt_gatt_result_descriptor_count(struct bt_gatt_result *result)
return result_element_count(result);
}
+unsigned int bt_gatt_result_included_count(struct bt_gatt_result *result)
+{
+ struct bt_gatt_result *cur;
+ unsigned int count = 0;
+
+ if (!result)
+ return 0;
+
+ if (result->opcode != BT_ATT_OP_READ_BY_TYPE_RSP)
+ return 0;
+
+ if (result->data_len != 6 && result->data_len != 8)
+ return 0;
+
+ for (cur = result; cur; cur = cur->next)
+ if (cur->opcode == BT_ATT_OP_READ_BY_TYPE_RSP)
+ count += cur->pdu_len / cur->data_len;
+
+ return count;
+}
+
bool bt_gatt_iter_init(struct bt_gatt_iter *iter, struct bt_gatt_result *result)
{
if (!iter || !result)
diff --git a/src/shared/gatt-helpers.h b/src/shared/gatt-helpers.h
index f2c7ec5..07c145d 100644
--- a/src/shared/gatt-helpers.h
+++ b/src/shared/gatt-helpers.h
@@ -38,6 +38,7 @@ struct bt_gatt_iter {
unsigned int bt_gatt_result_service_count(struct bt_gatt_result *result);
unsigned int bt_gatt_result_characteristic_count(struct bt_gatt_result *result);
unsigned int bt_gatt_result_descriptor_count(struct bt_gatt_result *result);
+unsigned int bt_gatt_result_included_count(struct bt_gatt_result *result);
bool bt_gatt_iter_init(struct bt_gatt_iter *iter, struct bt_gatt_result *result);
bool bt_gatt_iter_next_service(struct bt_gatt_iter *iter,
--
1.9.3
^ permalink raw reply related
* [PATCHv4 06/14] shared/gatt: Remove not needed function parameter
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
According to SPEC 4.1 4.5.1 "Find Included Services" there is no need
to pass UUID to discover_included_services() function.
---
src/shared/gatt-helpers.c | 1 -
src/shared/gatt-helpers.h | 1 -
2 files changed, 2 deletions(-)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index fd8d06c..48e7379 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -1002,7 +1002,6 @@ done:
bool bt_gatt_discover_included_services(struct bt_att *att,
uint16_t start, uint16_t end,
- bt_uuid_t *uuid,
bt_gatt_discovery_callback_t callback,
void *user_data,
bt_gatt_destroy_func_t destroy)
diff --git a/src/shared/gatt-helpers.h b/src/shared/gatt-helpers.h
index 8c434c1..f2c7ec5 100644
--- a/src/shared/gatt-helpers.h
+++ b/src/shared/gatt-helpers.h
@@ -82,7 +82,6 @@ bool bt_gatt_discover_secondary_services(struct bt_att *att, bt_uuid_t *uuid,
bt_gatt_destroy_func_t destroy);
bool bt_gatt_discover_included_services(struct bt_att *att,
uint16_t start, uint16_t end,
- bt_uuid_t *uuid,
bt_gatt_discovery_callback_t callback,
void *user_data,
bt_gatt_destroy_func_t destroy);
--
1.9.3
^ permalink raw reply related
* [PATCHv4 05/14] shared/gatt: Add included service iterator
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
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));
+
+ 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);
--
1.9.3
^ permalink raw reply related
* [PATCHv4 04/14] shared/gatt: Add extra check in characteristic iterator
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
Avoid incorrect reading of included service discovery results.
---
src/shared/gatt-helpers.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index c18f738..58104d9 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -123,6 +123,9 @@ unsigned int bt_gatt_result_characteristic_count(struct bt_gatt_result *result)
if (result->opcode != BT_ATT_OP_READ_BY_TYPE_RSP)
return 0;
+ if (result->data_len != 21 && result->data_len != 7)
+ return 0;
+
return result_element_count(result);
}
@@ -239,6 +242,9 @@ bool bt_gatt_iter_next_characteristic(struct bt_gatt_iter *iter,
if (iter->result->opcode != BT_ATT_OP_READ_BY_TYPE_RSP)
return false;
+ if (iter->result->data_len != 21 && iter->result->data_len != 7)
+ return false;
+
op = iter->result->op;
pdu_ptr = iter->result->pdu + iter->pos;
--
1.9.3
^ permalink raw reply related
* [PATCHv4 03/14] shared/gatt: Discover included services 128 bit UUIDS
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
If included services has 128 bit UUID, it won't be returned in
READ_BY_TYPE_RSP. To get UUID READ_REQUEST is used.
This procedure is described in CORE SPEC 4.5.1 "Find Included Services".
---
src/shared/gatt-helpers.c | 170 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 169 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index dcb2a2f..c18f738 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -692,6 +692,160 @@ bool bt_gatt_discover_secondary_services(struct bt_att *att, bt_uuid_t *uuid,
destroy, false);
}
+struct read_incl_data {
+ struct discovery_op *op;
+ struct bt_gatt_result *result;
+ int pos;
+ int ref_count;
+};
+
+static struct read_incl_data *new_read_included(struct bt_gatt_result *res)
+{
+ struct read_incl_data *data;
+
+ data = new0(struct read_incl_data, 1);
+ if (!data)
+ return NULL;
+
+ data->op = discovery_op_ref(res->op);
+ data->result = res;
+
+ return data;
+};
+
+static struct read_incl_data *read_included_ref(struct read_incl_data *data)
+{
+ __sync_fetch_and_add(&data->ref_count, 1);
+
+ return data;
+}
+
+static void read_included_unref(void *data)
+{
+ struct read_incl_data *read_data = data;
+
+ if (__sync_sub_and_fetch(&read_data->ref_count, 1))
+ return;
+
+ discovery_op_unref(read_data->op);
+
+ free(read_data);
+}
+
+static void discover_included_cb(uint8_t opcode, const void *pdu,
+ uint16_t length, void *user_data);
+
+static void read_included_cb(uint8_t opcode, const void *pdu,
+ uint16_t length, void *user_data)
+{
+ struct read_incl_data *data = user_data;
+ struct bt_gatt_result *final_result = NULL;
+ struct discovery_op *op = data->op;
+ struct bt_gatt_result *cur_result;
+ uint8_t att_ecode = 0;
+ uint16_t handle;
+ uint8_t read_pdu[2];
+ bool success;
+
+ if (opcode == BT_ATT_OP_ERROR_RSP) {
+ success = false;
+ att_ecode = process_error(pdu, length);
+ goto done;
+ }
+
+ if (opcode != BT_ATT_OP_READ_RSP || (!pdu && length)) {
+ success = false;
+ goto done;
+ }
+
+ if (length != 16) {
+ success = false;
+ goto done;
+ }
+ cur_result = result_create(opcode, pdu, length, length, op);
+ if (!cur_result) {
+ success = false;
+ goto done;
+ }
+
+ if (!op->result_head)
+ op->result_head = op->result_tail = cur_result;
+ else {
+ op->result_tail->next = cur_result;
+ op->result_tail = cur_result;
+ }
+
+ if (data->pos == data->result->pdu_len) {
+ uint16_t last_handle, data_len;
+ uint8_t pdu[6];
+
+ data_len = data->result->data_len;
+ last_handle = get_le16(data->result->pdu + data->pos -
+ data_len);
+ if (last_handle == op->end_handle) {
+ final_result = op->result_head;
+ success = true;
+ goto done;
+ }
+
+ put_le16(last_handle + 1, pdu);
+ put_le16(op->end_handle, pdu + 2);
+ put_le16(GATT_INCLUDE_UUID, pdu + 4);
+
+ if (bt_att_send(op->att, BT_ATT_OP_READ_BY_TYPE_REQ,
+ pdu, sizeof(pdu),
+ discover_included_cb,
+ discovery_op_ref(op),
+ discovery_op_unref))
+ return;
+
+ discovery_op_unref(op);
+ success = false;
+ goto done;
+ }
+
+ handle = get_le16(data->result->pdu + data->pos + 2);
+ put_le16(handle, read_pdu);
+
+ data->pos += data->result->data_len;
+
+ if (bt_att_send(op->att, BT_ATT_OP_READ_REQ, read_pdu, sizeof(read_pdu),
+ read_included_cb,
+ read_included_ref(data),
+ read_included_unref))
+ return;
+
+ read_included_unref(data);
+ success = false;
+
+done:
+ if (op->callback)
+ op->callback(success, att_ecode, final_result, op->user_data);
+}
+
+static void read_included(struct read_incl_data *data)
+{
+ struct discovery_op *op = data->op;
+ uint16_t handle;
+ uint8_t pdu[2];
+
+ handle = get_le16(data->result->pdu + 2);
+ put_le16(handle, pdu);
+
+ data->pos += data->result->data_len;
+
+ if (bt_att_send(op->att, BT_ATT_OP_READ_REQ, pdu, sizeof(pdu),
+ read_included_cb,
+ read_included_ref(data),
+ read_included_unref))
+ return;
+
+ read_included_unref(data);
+
+ if (op->callback)
+ op->callback(false, 0, NULL, data->op->user_data);
+}
+
static void discover_included_cb(uint8_t opcode, const void *pdu,
uint16_t length, void *user_data)
{
@@ -721,7 +875,8 @@ static void discover_included_cb(uint8_t opcode, const void *pdu,
data_length = ((uint8_t *) pdu)[0];
- if ((length - 1) % data_length || data_length != 8) {
+ if (((length - 1) % data_length) ||
+ (data_length != 8 && data_length != 6)) {
success = false;
goto done;
}
@@ -740,6 +895,19 @@ static void discover_included_cb(uint8_t opcode, const void *pdu,
op->result_tail = cur_result;
}
+ if (data_length == 6) {
+ struct read_incl_data *data;
+
+ data = new_read_included(cur_result);
+ if (!data) {
+ success = false;
+ goto done;
+ }
+
+ read_included(data);
+ return;
+ }
+
last_handle = get_le16(pdu + length - data_length);
if (last_handle != op->end_handle) {
uint8_t pdu[6];
--
1.9.3
^ permalink raw reply related
* [PATCHv4 02/14] shared/gatt: Add initial implementation of discover_included_services
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
Current implementation allow to discover included services with
16 bit UUID only.
---
src/shared/gatt-helpers.c | 108 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 106 insertions(+), 2 deletions(-)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index 4dc787f..dcb2a2f 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -692,6 +692,82 @@ bool bt_gatt_discover_secondary_services(struct bt_att *att, bt_uuid_t *uuid,
destroy, false);
}
+static void discover_included_cb(uint8_t opcode, const void *pdu,
+ uint16_t length, void *user_data)
+{
+ struct bt_gatt_result *final_result = NULL;
+ struct discovery_op *op = user_data;
+ struct bt_gatt_result *cur_result;
+ uint8_t att_ecode = 0;
+ uint16_t last_handle;
+ size_t data_length;
+ bool success;
+
+ if (opcode == BT_ATT_OP_ERROR_RSP) {
+ success = false;
+ att_ecode = process_error(pdu, length);
+
+ if (att_ecode == BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND &&
+ op->result_head)
+ goto success;
+
+ goto done;
+ }
+
+ if (opcode != BT_ATT_OP_READ_BY_TYPE_RSP || !pdu || length < 6) {
+ success = false;
+ goto done;
+ }
+
+ data_length = ((uint8_t *) pdu)[0];
+
+ if ((length - 1) % data_length || data_length != 8) {
+ success = false;
+ goto done;
+ }
+
+ cur_result = result_create(opcode, pdu + 1, length - 1,
+ data_length, op);
+ if (!cur_result) {
+ success = false;
+ goto done;
+ }
+
+ if (!op->result_head)
+ op->result_head = op->result_tail = cur_result;
+ else {
+ op->result_tail->next = cur_result;
+ op->result_tail = cur_result;
+ }
+
+ last_handle = get_le16(pdu + length - data_length);
+ if (last_handle != op->end_handle) {
+ uint8_t pdu[6];
+
+ put_le16(last_handle + 1, pdu);
+ put_le16(op->end_handle, pdu + 2);
+ put_le16(GATT_INCLUDE_UUID, pdu + 4);
+
+ if (bt_att_send(op->att, BT_ATT_OP_READ_BY_TYPE_REQ,
+ pdu, sizeof(pdu),
+ discover_included_cb,
+ discovery_op_ref(op),
+ discovery_op_unref))
+ return;
+
+ discovery_op_unref(op);
+ success = false;
+ }
+
+success:
+ success = true;
+ final_result = op->result_head;
+
+done:
+ if (op->callback)
+ op->callback(success, att_ecode, final_result, op->user_data);
+}
+
bool bt_gatt_discover_included_services(struct bt_att *att,
uint16_t start, uint16_t end,
bt_uuid_t *uuid,
@@ -699,8 +775,36 @@ bool bt_gatt_discover_included_services(struct bt_att *att,
void *user_data,
bt_gatt_destroy_func_t destroy)
{
- /* TODO */
- return false;
+ struct discovery_op *op;
+ uint8_t pdu[6];
+
+ if (!att)
+ return false;
+
+ op = new0(struct discovery_op, 1);
+ if (!op)
+ return false;
+
+ op->att = att;
+ op->callback = callback;
+ op->user_data = user_data;
+ op->destroy = destroy;
+ op->end_handle = end;
+
+ put_le16(start, pdu);
+ put_le16(end, pdu + 2);
+ put_le16(GATT_INCLUDE_UUID, pdu + 4);
+
+ if (!bt_att_send(att, BT_ATT_OP_READ_BY_TYPE_REQ,
+ pdu, sizeof(pdu),
+ discover_included_cb,
+ discovery_op_ref(op),
+ discovery_op_unref)) {
+ free(op);
+ return false;
+ }
+
+ return true;
}
static void discover_chrcs_cb(uint8_t opcode, const void *pdu,
--
1.9.3
^ permalink raw reply related
* [PATCHv4 01/14] shared/gatt: Add discover_secondary_services()
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412932548-28363-1-git-send-email-marcin.kraglak@tieto.com>
This pach implements searching Secondary Services in given range.
---
src/shared/gatt-helpers.c | 56 +++++++++++++++++++++++++++++++++--------------
src/shared/gatt-helpers.h | 5 +++++
2 files changed, 45 insertions(+), 16 deletions(-)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index 55e6992..4dc787f 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -175,6 +175,7 @@ struct discovery_op {
uint16_t end_handle;
int ref_count;
bt_uuid_t uuid;
+ uint16_t service_type;
struct bt_gatt_result *result_head;
struct bt_gatt_result *result_tail;
bt_gatt_discovery_callback_t callback;
@@ -487,7 +488,7 @@ static void read_by_grp_type_cb(uint8_t opcode, const void *pdu,
put_le16(last_end + 1, pdu);
put_le16(op->end_handle, pdu + 2);
- put_le16(GATT_PRIM_SVC_UUID, pdu + 4);
+ put_le16(op->service_type, pdu + 4);
if (bt_att_send(op->att, BT_ATT_OP_READ_BY_GRP_TYPE_REQ,
pdu, sizeof(pdu),
@@ -569,7 +570,7 @@ static void find_by_type_val_cb(uint8_t opcode, const void *pdu,
put_le16(last_end + 1, pdu);
put_le16(op->end_handle, pdu + 2);
- put_le16(GATT_PRIM_SVC_UUID, pdu + 4);
+ put_le16(op->service_type, pdu + 4);
put_uuid_le(&op->uuid, pdu + 6);
if (bt_att_send(op->att, BT_ATT_OP_FIND_BY_TYPE_VAL_REQ,
@@ -594,21 +595,12 @@ done:
op->callback(success, att_ecode, final_result, op->user_data);
}
-bool bt_gatt_discover_all_primary_services(struct bt_att *att, bt_uuid_t *uuid,
- bt_gatt_discovery_callback_t callback,
- void *user_data,
- bt_gatt_destroy_func_t destroy)
-{
- return bt_gatt_discover_primary_services(att, uuid, 0x0001, 0xffff,
- callback, user_data,
- destroy);
-}
-
-bool bt_gatt_discover_primary_services(struct bt_att *att, bt_uuid_t *uuid,
+static bool discover_services(struct bt_att *att, bt_uuid_t *uuid,
uint16_t start, uint16_t end,
bt_gatt_discovery_callback_t callback,
void *user_data,
- bt_gatt_destroy_func_t destroy)
+ bt_gatt_destroy_func_t destroy,
+ bool primary)
{
struct discovery_op *op;
bool result;
@@ -625,6 +617,8 @@ bool bt_gatt_discover_primary_services(struct bt_att *att, bt_uuid_t *uuid,
op->callback = callback;
op->user_data = user_data;
op->destroy = destroy;
+ /* set service uuid to primary or secondary */
+ op->service_type = primary ? GATT_PRIM_SVC_UUID : GATT_SND_SVC_UUID;
/* If UUID is NULL, then discover all primary services */
if (!uuid) {
@@ -632,7 +626,7 @@ bool bt_gatt_discover_primary_services(struct bt_att *att, bt_uuid_t *uuid,
put_le16(start, pdu);
put_le16(end, pdu + 2);
- put_le16(GATT_PRIM_SVC_UUID, pdu + 4);
+ put_le16(op->service_type, pdu + 4);
result = bt_att_send(att, BT_ATT_OP_READ_BY_GRP_TYPE_REQ,
pdu, sizeof(pdu),
@@ -652,7 +646,7 @@ bool bt_gatt_discover_primary_services(struct bt_att *att, bt_uuid_t *uuid,
put_le16(start, pdu);
put_le16(end, pdu + 2);
- put_le16(GATT_PRIM_SVC_UUID, pdu + 4);
+ put_le16(op->service_type, pdu + 4);
put_uuid_le(&op->uuid, pdu + 6);
result = bt_att_send(att, BT_ATT_OP_FIND_BY_TYPE_VAL_REQ,
@@ -668,6 +662,36 @@ bool bt_gatt_discover_primary_services(struct bt_att *att, bt_uuid_t *uuid,
return result;
}
+bool bt_gatt_discover_all_primary_services(struct bt_att *att, bt_uuid_t *uuid,
+ bt_gatt_discovery_callback_t callback,
+ void *user_data,
+ bt_gatt_destroy_func_t destroy)
+{
+ return bt_gatt_discover_primary_services(att, uuid, 0x0001, 0xffff,
+ callback, user_data,
+ destroy);
+}
+
+bool bt_gatt_discover_primary_services(struct bt_att *att, bt_uuid_t *uuid,
+ uint16_t start, uint16_t end,
+ bt_gatt_discovery_callback_t callback,
+ void *user_data,
+ bt_gatt_destroy_func_t destroy)
+{
+ return discover_services(att, uuid, start, end, callback, user_data,
+ destroy, true);
+}
+
+bool bt_gatt_discover_secondary_services(struct bt_att *att, bt_uuid_t *uuid,
+ uint16_t start, uint16_t end,
+ bt_gatt_discovery_callback_t callback,
+ void *user_data,
+ bt_gatt_destroy_func_t destroy)
+{
+ return discover_services(att, uuid, start, end, callback, user_data,
+ destroy, false);
+}
+
bool bt_gatt_discover_included_services(struct bt_att *att,
uint16_t start, uint16_t end,
bt_uuid_t *uuid,
diff --git a/src/shared/gatt-helpers.h b/src/shared/gatt-helpers.h
index f6f4b62..8a25dea 100644
--- a/src/shared/gatt-helpers.h
+++ b/src/shared/gatt-helpers.h
@@ -72,6 +72,11 @@ bool bt_gatt_discover_primary_services(struct bt_att *att, bt_uuid_t *uuid,
bt_gatt_discovery_callback_t callback,
void *user_data,
bt_gatt_destroy_func_t destroy);
+bool bt_gatt_discover_secondary_services(struct bt_att *att, bt_uuid_t *uuid,
+ uint16_t start, uint16_t end,
+ bt_gatt_discovery_callback_t callback,
+ void *user_data,
+ bt_gatt_destroy_func_t destroy);
bool bt_gatt_discover_included_services(struct bt_att *att,
uint16_t start, uint16_t end,
bt_uuid_t *uuid,
--
1.9.3
^ permalink raw reply related
* [PATCHv4 00/14] Included service discovery
From: Marcin Kraglak @ 2014-10-10 9:15 UTC (permalink / raw)
To: linux-bluetooth
Current implementation was tested with PTS GATT test case
TC_GAD_CL_BV_03_C.
v3:
In this version after primary service discovery,
secondary services are discovered. Next included
services are resolved. With this approach we
don't have recursively search for included service,
like it was TODO in previous proposal.
There is also small coding style fix suggested by Arman.
v4:
If no secondary services found, continue include services search (fixed
in gatt-client.c).
Fixed wrong debug logs (primary->secondary).
Fixed searching descriptors
Marcin Kraglak (14):
shared/gatt: Add discover_secondary_services()
shared/gatt: Add initial implementation of discover_included_services
shared/gatt: Discover included services 128 bit UUIDS
shared/gatt: Add extra check in characteristic iterator
shared/gatt: Add included service iterator
shared/gatt: Remove not needed function parameter
shared/gatt: Add function bt_gatt_result_included_count()
shared/gatt: Distinguish Primary from Secondary services
tools/btgatt-client: Print type of service
shared/gatt: Discover secondary services
shared/gatt: Discover included services
shared/gatt: Add gatt-client include service iterator
tools/btgatt-client: Print found include services
shared/gatt: Fix searching descriptors
src/shared/gatt-client.c | 259 ++++++++++++++++++++++++++--
src/shared/gatt-client.h | 18 ++
src/shared/gatt-helpers.c | 418 +++++++++++++++++++++++++++++++++++++++++++---
src/shared/gatt-helpers.h | 10 +-
tools/btgatt-client.c | 17 +-
5 files changed, 686 insertions(+), 36 deletions(-)
--
1.9.3
^ permalink raw reply
* Re: [PATCH 1/3] android/tester: Add GATT server start service test cases
From: Szymon Janc @ 2014-10-10 9:08 UTC (permalink / raw)
To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth
In-Reply-To: <1412605665-13527-1-git-send-email-grzegorz.kolodziejczyk@tieto.com>
Hi Grzegorz,
On Monday 06 of October 2014 16:27:43 Grzegorz Kolodziejczyk wrote:
> This adds start service by server test cases.
> ---
> android/tester-gatt.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++
> android/tester-main.c | 16 +++++++-
> android/tester-main.h | 7 ++++
> 3 files changed, 122 insertions(+), 1 deletion(-)
>
> diff --git a/android/tester-gatt.c b/android/tester-gatt.c
> index e86e929..19ba703 100644
> --- a/android/tester-gatt.c
> +++ b/android/tester-gatt.c
> @@ -37,6 +37,10 @@
> #define CONN1_ID 1
> #define CONN2_ID 2
>
> +#define GATT_SERVER_TRANSPORT_LE 0x00
> +#define GATT_SERVER_TRANSPORT_BREDR 0x01
> +#define GATT_SERVER_TRANSPORT_LE_BREDR 0x02
> +
> static struct queue *list; /* List of gatt test cases */
>
> static int srvc1_handle;
> @@ -138,6 +142,12 @@ struct add_desc_data {
> int permissions;
> };
>
> +struct start_srvc_data {
> + int app_id;
> + int *srvc_handle;
> + int transport;
> +};
> +
> static bt_bdaddr_t emu_remote_bdaddr_val = {
> .address = { 0x00, 0xaa, 0x01, 0x01, 0x00, 0x00 },
> };
> @@ -459,6 +469,30 @@ static struct add_desc_data add_desc_data_1 = {
> .permissions = 0
> };
>
> +static struct start_srvc_data start_srvc_data_1 = {
> + .app_id = APP1_ID,
> + .srvc_handle = &srvc1_handle,
> + .transport = GATT_SERVER_TRANSPORT_LE_BREDR
> +};
> +
> +static struct start_srvc_data start_srvc_data_2 = {
> + .app_id = APP1_ID,
> + .srvc_handle = &srvc1_handle,
> + .transport = GATT_SERVER_TRANSPORT_LE
> +};
> +
> +static struct start_srvc_data start_bad_srvc_data_1 = {
> + .app_id = APP1_ID,
> + .srvc_handle = &srvc_bad_handle,
> + .transport = GATT_SERVER_TRANSPORT_LE
> +};
> +
> +static struct start_srvc_data start_bad_srvc_data_2 = {
> + .app_id = APP1_ID,
> + .srvc_handle = &srvc1_handle,
> + .transport = -1
> +};
> +
> struct set_read_params {
> btgatt_read_params_t *params;
> btgatt_srvc_id_t *srvc_id;
> @@ -1222,6 +1256,21 @@ static void gatt_server_add_desc_action(void)
> schedule_action_verification(step);
> }
>
> +static void gatt_server_start_srvc_action(void)
> +{
> + struct test_data *data = tester_get_data();
> + struct step *current_data_step = queue_peek_head(data->steps);
> + struct start_srvc_data *start_srvc_data = current_data_step->set_data;
> + struct step *step = g_new0(struct step, 1);
> +
> + step->action_status = data->if_gatt->server->start_service(
> + start_srvc_data->app_id,
> + *start_srvc_data->srvc_handle,
> + start_srvc_data->transport);
> +
> + schedule_action_verification(step);
> +}
> +
> static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
> {
> struct test_data *t_data = tester_get_data();
> @@ -2645,6 +2694,57 @@ static struct test_case test_cases[] = {
> CALLBACK_GATTS_DESCRIPTOR_ADDED(GATT_STATUS_FAILURE, APP2_ID,
> &app2_uuid, NULL, NULL, NULL),
> ),
> + TEST_CASE_BREDRLE("Gatt Server - Start Service Successful BREDRLE",
> + ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
> + CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
> + ACTION_SUCCESS(gatt_server_add_service_action,
> + &add_service_data_1),
> + CALLBACK_GATTS_SERVICE_ADDED(GATT_STATUS_SUCCESS, APP1_ID,
> + &service_add_1, NULL,
> + &srvc1_handle),
> + ACTION_SUCCESS(gatt_server_start_srvc_action,
> + &start_srvc_data_1),
> + CALLBACK_GATTS_SERVICE_STARTED(GATT_STATUS_SUCCESS, APP1_ID,
> + &srvc1_handle),
> + ),
> + TEST_CASE_BREDRLE("Gatt Server - Start Service Successful LE",
> + ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
> + CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
> + ACTION_SUCCESS(gatt_server_add_service_action,
> + &add_service_data_1),
> + CALLBACK_GATTS_SERVICE_ADDED(GATT_STATUS_SUCCESS, APP1_ID,
> + &service_add_1, NULL,
> + &srvc1_handle),
> + ACTION_SUCCESS(gatt_server_start_srvc_action,
> + &start_srvc_data_2),
> + CALLBACK_GATTS_SERVICE_STARTED(GATT_STATUS_SUCCESS, APP1_ID,
> + &srvc1_handle),
> + ),
> + TEST_CASE_BREDRLE("Gatt Server - Start Service wrong service handle",
> + ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
> + CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
> + ACTION_SUCCESS(gatt_server_add_service_action,
> + &add_service_data_1),
> + CALLBACK_GATTS_SERVICE_ADDED(GATT_STATUS_SUCCESS, APP1_ID,
> + &service_add_1, NULL, NULL),
> + ACTION_FAIL(gatt_server_start_srvc_action,
> + &start_bad_srvc_data_1),
> + CALLBACK_GATTS_SERVICE_STARTED(GATT_STATUS_FAILURE, APP1_ID,
> + NULL),
> + ),
> + TEST_CASE_BREDRLE("Gatt Server - Start Service wrong server transport",
> + ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
> + CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
> + ACTION_SUCCESS(gatt_server_add_service_action,
> + &add_service_data_1),
> + CALLBACK_GATTS_SERVICE_ADDED(GATT_STATUS_SUCCESS, APP1_ID,
> + &service_add_1, NULL,
> + &srvc1_handle),
> + ACTION_FAIL(gatt_server_start_srvc_action,
> + &start_bad_srvc_data_2),
> + CALLBACK_GATTS_SERVICE_STARTED(GATT_STATUS_FAILURE, APP1_ID,
> + &srvc1_handle),
> + ),
> };
>
> struct queue *get_gatt_tests(void)
> diff --git a/android/tester-main.c b/android/tester-main.c
> index 30e1c59..4ffa3c1 100644
> --- a/android/tester-main.c
> +++ b/android/tester-main.c
> @@ -1608,6 +1608,20 @@ static void gatts_descriptor_added_cb(int status, int server_if,
> schedule_callback_verification(step);
> }
>
> +static void gatts_service_started_cb(int status, int server_if, int srvc_handle)
> +{
> + struct step *step = g_new0(struct step, 1);
> +
> + step->callback = CB_GATTS_SERVICE_STARTED;
> +
> + step->callback_result.status = status;
> + step->callback_result.gatt_app_id = server_if;
> + step->callback_result.srvc_handle = g_memdup(&srvc_handle,
> + sizeof(srvc_handle));
> +
> + schedule_callback_verification(step);
> +}
> +
> static void pan_control_state_cb(btpan_control_state_t state,
> bt_status_t error, int local_role,
> const char *ifname)
> @@ -1735,7 +1749,7 @@ static const btgatt_server_callbacks_t btgatt_server_callbacks = {
> .included_service_added_cb = gatts_included_service_added_cb,
> .characteristic_added_cb = gatts_characteristic_added_cb,
> .descriptor_added_cb = gatts_descriptor_added_cb,
> - .service_started_cb = NULL,
> + .service_started_cb = gatts_service_started_cb,
> .service_stopped_cb = NULL,
> .service_deleted_cb = NULL,
> .request_read_cb = NULL,
> diff --git a/android/tester-main.h b/android/tester-main.h
> index 17a6eb3..1906a8d 100644
> --- a/android/tester-main.h
> +++ b/android/tester-main.h
> @@ -297,6 +297,13 @@ struct pdu_set {
> .store_desc_handle = cb_store_desc_handle, \
> }
>
> +#define CALLBACK_GATTS_SERVICE_STARTED(cb_res, cb_server_id, cb_srvc_handle) { \
> + .callback = CB_GATTS_SERVICE_STARTED, \
> + .callback_result.status = cb_res, \
> + .callback_result.gatt_app_id = cb_server_id, \
> + .callback_result.srvc_handle = cb_srvc_handle, \
> + }
> +
> #define CALLBACK_PAN_CTRL_STATE(cb, cb_res, cb_state, cb_local_role) { \
> .callback = cb, \
> .callback_result.status = cb_res, \
>
All patches applied. Thanks.
--
Best regards,
Szymon Janc
^ permalink raw reply
* Re: [PATCH] android/pts: RFCOMM PTS 5.3 update
From: Szymon Janc @ 2014-10-10 8:36 UTC (permalink / raw)
To: Sebastian Chlad; +Cc: linux-bluetooth
In-Reply-To: <1412867744-11403-1-git-send-email-sebastian.chlad@tieto.com>
Hi Sebastian,
On Thursday 09 of October 2014 17:15:44 Sebastian Chlad wrote:
> PTS tests results for RFCOMM on PTS 5.3.
> PICS' and PIXITs checked against PTS 5.3.
> ---
> android/pics-rfcomm.txt | 2 +-
> android/pixit-rfcomm.txt | 2 +-
> android/pts-rfcomm.txt | 22 ++++++++--------------
> 3 files changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/android/pics-rfcomm.txt b/android/pics-rfcomm.txt
> index 9dfb32e..c970363 100644
> --- a/android/pics-rfcomm.txt
> +++ b/android/pics-rfcomm.txt
> @@ -1,6 +1,6 @@
> RFCOMM PICS for the PTS tool.
>
> -PTS version: 5.2
> +PTS version: 5.3
>
> * - different than PTS defaults
> # - not yet implemented/supported
> diff --git a/android/pixit-rfcomm.txt b/android/pixit-rfcomm.txt
> index 07810d2..187f3b4 100644
> --- a/android/pixit-rfcomm.txt
> +++ b/android/pixit-rfcomm.txt
> @@ -1,6 +1,6 @@
> RFCOMM PIXIT for the PTS tool.
>
> -PTS version: 5.2
> +PTS version: 5.3
>
> * - different than PTS defaults
> & - should be set to IUT Bluetooth address
> diff --git a/android/pts-rfcomm.txt b/android/pts-rfcomm.txt
> index 9bfc7a2..d869ee0 100644
> --- a/android/pts-rfcomm.txt
> +++ b/android/pts-rfcomm.txt
> @@ -1,7 +1,7 @@
> PTS test results for RFCOMM
>
> -PTS version: 5.2
> -Tested: 17-July-2014
> +PTS version: 5.3
> +Tested: 08-October-2014
> Android version: 4.4.4
>
> Results:
> @@ -17,29 +17,23 @@ Test Name Result Notes
> TC_RFC_BV_01_C PASS rctest -n -P 1 <btaddr>
> TC_RFC_BV_02_C PASS rctest -r -P 1
> TC_RFC_BV_03_C PASS rctest -r -P 1
> -TC_RFC_BV_04_C FAIL PTS issue #12421
> - PTS issue #12414
> - NOTE: DISC on DLC is expected; IUT disconnects
> - rfcomm session (close)
> +TC_RFC_BV_04_C PASS NOTE: use ets provided in PTS issue #12414
> TC_RFC_BV_05_C PASS rctest -n -P 4 <btaddr>
> Note: test requires IUT to connect on the given
> channel. sdptool browse <btaddr> to check the
> channel.
> TC_RFC_BV_06_C PASS rctest -r -P 1
> TC_RFC_BV_07_C PASS rctest -r -P 1
> -TC_RFC_BV_08_C INC PTS issue #12397
> - NOTE: Incorrect frame type sent in response to
> - the DISC command
> +TC_RFC_BV_08_C PASS rctest -r -P 1
> + Note: use ets provided in PTS issue #12397
> TC_RFC_BV_11_C PASS rctest -r -P 1
> -TC_RFC_BV_13_C FAIL PTS issue #12397
> - NOTE: IUT sent the correct frame type (UIH)
> - but the parameters did not match the
> - requirements
> +TC_RFC_BV_13_C PASS rctest -r -P 1
> + Note: use ets provided in PTS issue #12397
> TC_RFC_BV_14_C N/A
> TC_RFC_BV_15_C PASS rctest -r -P 1
> TC_RFC_BV_17_C PASS rctest -d -P 1
> TC_RFC_BV_19_C PASS
> TC_RFC_BV_21_C INC PTS issue #12421
> TC_RFC_BV_22_C INC PTS issue #12421
> -TC_RFC_BV_25_C INC PTS issue #12421
> +TC_RFC_BV_25_C INC PTS issue #12621
> -------------------------------------------------------------------------------
>
Applied (after moving PTS issues into same line as affected test name). Thanks.
--
Best regards,
Szymon Janc
^ permalink raw reply
* Re: [PATCH] Bluetooth: Defer connection-parameter removal when unpairing without disconnecting
From: Alfonso Acosta @ 2014-10-10 8:14 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: BlueZ development
In-Reply-To: <B2B9E083-A86D-426A-9E79-5F168A8FA017@holtmann.org>
Hi Marcel,
> don't we also need to clear the flag when the new pairing succeed?
Yep, in fact that's the whole point of the flag .... which I missed.
Thanks for your patience :)
> If we destroy hci_conn anyway, there is pretty much no point in test_and_clear_bit and we could just use test_bit here.
Fair point, I will change them to test_bit.
--
Alfonso Acosta
Embedded Systems Engineer at Spotify
Birger Jarlsgatan 61, Stockholm, Sweden
http://www.spotify.com
^ permalink raw reply
* Re: [PATCH v2 01/12] android/handsfree: Define proper type for device structure
From: Szymon Janc @ 2014-10-10 7:49 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1412763314-12871-1-git-send-email-szymon.janc@tieto.com>
On Wednesday 08 of October 2014 12:15:03 Szymon Janc wrote:
> ---
> android/handsfree.c | 36 +++++++++++++++++++-----------------
> 1 file changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/android/handsfree.c b/android/handsfree.c
> index a815d3b..0b82223 100644
> --- a/android/handsfree.c
> +++ b/android/handsfree.c
> @@ -110,22 +110,7 @@ struct hfp_codec {
> bool remote_supported;
> };
>
> -static const struct indicator inds_defaults[] = {
> - { "service", 0, 1, 0, false, true },
> - { "call", 0, 1, 0, true, true },
> - { "callsetup", 0, 3, 0, true, true },
> - { "callheld", 0, 2, 0, true, true },
> - { "signal", 0, 5, 0, false, true },
> - { "roam", 0, 1, 0, false, true },
> - { "battchg", 0, 5, 0, false, true },
> -};
> -
> -static const struct hfp_codec codecs_defaults[] = {
> - { CODEC_ID_CVSD, true, false},
> - { CODEC_ID_MSBC, false, false},
> -};
> -
> -static struct {
> +struct hf_device {
> bdaddr_t bdaddr;
> uint8_t state;
> uint8_t audio_state;
> @@ -152,7 +137,24 @@ static struct {
>
> GIOChannel *sco;
> guint sco_watch;
> -} device;
> +};
> +
> +static const struct indicator inds_defaults[] = {
> + { "service", 0, 1, 0, false, true },
> + { "call", 0, 1, 0, true, true },
> + { "callsetup", 0, 3, 0, true, true },
> + { "callheld", 0, 2, 0, true, true },
> + { "signal", 0, 5, 0, false, true },
> + { "roam", 0, 1, 0, false, true },
> + { "battchg", 0, 5, 0, false, true },
> +};
> +
> +static const struct hfp_codec codecs_defaults[] = {
> + { CODEC_ID_CVSD, true, false},
> + { CODEC_ID_MSBC, false, false},
> +};
> +
> +static struct hf_device device;
>
> static uint32_t hfp_ag_features = 0;
>
>
Pushed.
--
Best regards,
Szymon Janc
^ permalink raw reply
* Re: [PATCH] Bluetooth: Defer connection-parameter removal when unpairing without disconnecting
From: Marcel Holtmann @ 2014-10-10 7:36 UTC (permalink / raw)
To: Alfonso Acosta; +Cc: BlueZ development
In-Reply-To: <CAHF=Y4pJOC3gA1g-+o1e4HRJraFqpCGOAUuqNiS7b0CvAqEBJg@mail.gmail.com>
Hi Alfonso,
>>> +
>>> + if (test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags))
>>> + hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
>>> }
>>>
>>> /* Enter sniff mode */
>>> @@ -544,6 +547,9 @@ int hci_conn_del(struct hci_conn *conn)
>>>
>>> hci_conn_del_sysfs(conn);
>>>
>>> + if (test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags))
>>> + hci_conn_params_del(conn->hdev, &conn->dst, conn->dst_type);
>> I suppose the above two test_and_clear_bit() calls should be operating
>> on HCI_CONN_PARAM_REMOVAL_PEND and not HCI_CONN_MODE_CHANGE_PEND?
>
> Darn. Yes, my bad.
don't we also need to clear the flag when the new pairing succeed?
If we destroy hci_conn anyway, there is pretty much no point in test_and_clear_bit and we could just use test_bit here.
Regards
Marcel
^ permalink raw reply
* [PATCHv2] bnep: Add extra debug information for bnep_up
From: Andrei Emeltchenko @ 2014-10-10 7:18 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1448347.mpMmb7OWnU@uw000953>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Adding extra debug information helps to investigate failing cases
Return meaningful error code.
---
profiles/network/bnep.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 136709d..070c22e 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -195,7 +195,7 @@ static int bnep_connadd(int sk, uint16_t role, char *dev)
static int bnep_if_up(const char *devname)
{
struct ifreq ifr;
- int sk, err;
+ int sk, err = 0;
sk = socket(AF_INET, SOCK_DGRAM, 0);
@@ -205,16 +205,15 @@ static int bnep_if_up(const char *devname)
ifr.ifr_flags |= IFF_UP;
ifr.ifr_flags |= IFF_MULTICAST;
- err = ioctl(sk, SIOCSIFFLAGS, (void *) &ifr);
+ if (ioctl(sk, SIOCSIFFLAGS, (void *) &ifr) < 0) {
+ err = -errno;
+ error("Could not bring up %s: %s(%d)", devname, strerror(-err),
+ -err);
+ }
close(sk);
- if (err < 0) {
- error("Could not bring up %s", devname);
- return err;
- }
-
- return 0;
+ return err;
}
static int bnep_if_down(const char *devname)
--
1.9.1
^ permalink raw reply related
* Re: [PATCHv3 00/13] Included service discovery
From: Marcin Kraglak @ 2014-10-10 5:20 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org development
In-Reply-To: <1412757110-3509-1-git-send-email-marcin.kraglak@tieto.com>
On 8 October 2014 10:31, Marcin Kraglak <marcin.kraglak@tieto.com> wrote:
> In this version after primary service discovery,
> secondary services are discovered. Next included
> services are resolved. With this approach we
> don't have recursively search for included service,
> like it was TODO in previous proposal.
> There is also small coding style fix suggested by Arman.
> Comments are welcome
>
> BR
> Marcin
>
> Marcin Kraglak (13):
> shared/gatt: Add discover_secondary_services()
> shared/gatt: Add initial implementation of discover_included_services
> shared/gatt: Discover included services 128 bit UUIDS
> shared/gatt: Add extra check in characteristic iterator
> shared/gatt: Add included service iterator
> shared/gatt: Remove not needed function parameter
> shared/gatt: Add function bt_gatt_result_included_count()
> shared/gatt: Distinguish Primary from Secondary services
> tools/btgatt-client: Print type of service
> shared/gatt: Discover secondary services
> shared/gatt: Discover included services
> shared/gatt: Add gatt-client include service iterator
> tools/btgatt-client: Print found include services
>
> src/shared/gatt-client.c | 249 +++++++++++++++++++++++++--
> src/shared/gatt-client.h | 18 ++
> src/shared/gatt-helpers.c | 418 +++++++++++++++++++++++++++++++++++++++++++---
> src/shared/gatt-helpers.h | 10 +-
> tools/btgatt-client.c | 17 +-
> 5 files changed, 678 insertions(+), 34 deletions(-)
>
> --
> 1.9.3
>
ping
^ permalink raw reply
* [PATCH 8/8] unit/hfp: Add test for +CME ERROR: response
From: Lukasz Rymanowski @ 2014-10-09 23:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Lukasz Rymanowski
In-Reply-To: <1412898652-12281-1-git-send-email-lukasz.rymanowski@tieto.com>
---
unit/test-hfp.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index 9c71ee9..ff5532e 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -487,6 +487,19 @@ static void hf_response_with_data(const char *prefix, enum hfp_result res,
hfp_hf_disconnect(context->hfp_hf);
}
+static void hf_cme_error_response_cb(const char *prefix,
+ enum hfp_result res,
+ enum hfp_error cme_err,
+ void *user_data)
+{
+ struct context *context = user_data;
+
+ g_assert_cmpstr(prefix, ==, "AT+CHLD");
+ g_assert_cmpint(res, ==, HFP_RESULT_CME_ERROR);
+ g_assert_cmpint(cme_err, ==, 30);
+
+ hfp_hf_disconnect(context->hfp_hf);
+}
static void hf_brsf_response_cb(const char *prefix, enum hfp_result res,
enum hfp_error cme_err,
void *user_data)
@@ -721,6 +734,14 @@ int main(int argc, char *argv[])
frg_pdu('\r', '\n', 'O', 'k', '\r', '\n'),
data_end());
+ define_hf_test("/hfp/test_send_command_3", test_hf_send_command, NULL,
+ hf_cme_error_response_cb,
+ raw_pdu('A', 'T', '+', 'C', 'H', 'L', 'D', '=',
+ '1', '\0'),
+ frg_pdu('\r', '\n', '+', 'C', 'M', 'E', ' ', 'E'),
+ frg_pdu('R', 'R', 'O', 'R', ':', '3', '0', '\r', '\n'),
+ data_end());
+
define_hf_test("/hfp/test_unsolicited_1", test_hf_unsolicited,
hf_result_handler, NULL,
raw_pdu('+', 'C', 'L', 'C', 'C', '\0'),
--
1.8.4
^ permalink raw reply related
* [PATCH 7/8] unit/hfp: Add unit tests for parsing hfp_context
From: Lukasz Rymanowski @ 2014-10-09 23:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Lukasz Rymanowski
In-Reply-To: <1412898652-12281-1-git-send-email-lukasz.rymanowski@tieto.com>
This patch adds:
/hfp/test_hf_context_parser_1
/hfp/test_hf_context_parser_2
---
unit/test-hfp.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index bc05086..9c71ee9 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -531,6 +531,54 @@ static void test_hf_send_command(gconstpointer data)
execute_context(context);
}
+static void hf_chld_result_handler(struct hfp_context *hf_context,
+ void *user_data)
+{
+ struct context *context = user_data;
+ char str[3];
+
+ g_assert(hf_context);
+ g_assert(hfp_context_get_unquoted_string(hf_context, str,
+ sizeof(str)));
+ g_assert_cmpstr(str, ==, "1");
+ g_assert(hfp_context_get_unquoted_string(hf_context, str,
+ sizeof(str)));
+ g_assert_cmpstr(str, ==, "2x");
+
+ hfp_hf_disconnect(context->hfp_hf);
+}
+
+static void hf_clcc_result_handler(struct hfp_context *hf_context,
+ void *user_data)
+{
+ struct context *context = user_data;
+ char name[10];
+ uint32_t val1, val2;
+
+ g_assert(hf_context);
+ g_assert(hfp_context_open_container(hf_context));
+ g_assert(hfp_context_get_string(hf_context, name, sizeof(name)));
+ g_assert_cmpstr(name, ==, "call");
+ g_assert(hfp_context_open_container(hf_context));
+ g_assert(hfp_context_get_number(hf_context, &val1));
+ g_assert_cmpint(val1, ==, 0);
+ g_assert(hfp_context_get_number(hf_context, &val1));
+ g_assert_cmpint(val1, ==, 1);
+ g_assert(hfp_context_close_container(hf_context));
+ g_assert(hfp_context_close_container(hf_context));
+
+ g_assert(hfp_context_open_container(hf_context));
+ g_assert(hfp_context_get_string(hf_context, name, sizeof(name)));
+ g_assert_cmpstr(name, ==, "callsetup");
+ g_assert(hfp_context_open_container(hf_context));
+ g_assert(hfp_context_get_range(hf_context, &val1, &val2));
+ g_assert_cmpint(val1, ==, 0);
+ g_assert_cmpint(val2, ==, 3);
+ g_assert(hfp_context_close_container(hf_context));
+ g_assert(hfp_context_close_container(hf_context));
+
+ hfp_hf_disconnect(context->hfp_hf);
+}
static void hf_result_handler(struct hfp_context *result,
void *user_data)
@@ -718,5 +766,23 @@ int main(int argc, char *argv[])
raw_pdu('\r', '\n', 'B', 'R', '\r', '\n'),
data_end());
+ define_hf_test("/hfp/test_hf_context_parser_1", test_hf_unsolicited,
+ hf_clcc_result_handler, NULL,
+ raw_pdu('+', 'C', 'L', 'C', 'C', '\0'),
+ frg_pdu('+', 'C', 'L', 'C', 'C', ':'),
+ frg_pdu('(', '\"', 'c', 'a', 'l', 'l', '\"'),
+ frg_pdu('(', '0', ',', '1', ')', ')', ','),
+ frg_pdu('(', '\"', 'c', 'a', 'l', 'l', 's', 'e', 't'),
+ frg_pdu('u', 'p', '\"', ',', '(', '0', '-', '3', ')'),
+ frg_pdu(')', '\r', '\n'),
+ data_end());
+
+ define_hf_test("/hfp/test_hf_context_parser_2", test_hf_unsolicited,
+ hf_chld_result_handler, NULL,
+ raw_pdu('+', 'C', 'H', 'L', 'D', '\0'),
+ frg_pdu('+', 'C', 'H', 'L', 'D', ':'),
+ frg_pdu('1', ',', '2', 'x', '\r', '\n'),
+ data_end());
+
return g_test_run();
}
--
1.8.4
^ permalink raw reply related
* [PATCH 6/8] shared/hfp: Add hfp_context_get_range function
From: Lukasz Rymanowski @ 2014-10-09 23:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Lukasz Rymanowski
In-Reply-To: <1412898652-12281-1-git-send-email-lukasz.rymanowski@tieto.com>
This patch adds hfp_contex_get_range function which is useful in parsing
response like this : +CIND: ("battchr",(1-5))
---
src/shared/hfp.c | 31 +++++++++++++++++++++++++++++++
src/shared/hfp.h | 2 ++
2 files changed, 33 insertions(+)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 1ccbd16..fe9f1c0 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -419,6 +419,37 @@ bool hfp_context_has_next(struct hfp_context *result)
return result->data[result->offset] != '\0';
}
+bool hfp_context_get_range(struct hfp_context *context, uint32_t *min,
+ uint32_t *max)
+{
+ uint32_t l, h;
+ uint32_t start;
+
+ start = context->offset;
+
+ if (!hfp_context_get_number(context, &l))
+ goto failed;
+
+ if (context->data[context->offset] != '-')
+ goto failed;
+
+ context->offset++;
+
+ if (!hfp_context_get_number(context, &h))
+ goto failed;
+
+ *min = l;
+ *max = h;
+
+ next_field(context);
+
+ return true;
+
+failed:
+ context->offset = start;
+ return false;
+}
+
static void process_input(struct hfp_gw *hfp)
{
char *str, *ptr;
diff --git a/src/shared/hfp.h b/src/shared/hfp.h
index e4a70e0..c2153a8 100644
--- a/src/shared/hfp.h
+++ b/src/shared/hfp.h
@@ -137,6 +137,8 @@ bool hfp_context_get_string(struct hfp_context *context, char *buf,
uint8_t len);
bool hfp_context_get_unquoted_string(struct hfp_context *context,
char *buf, uint8_t len);
+bool hfp_context_get_range(struct hfp_context *context, unsigned int *min,
+ unsigned int *max);
bool hfp_context_has_next(struct hfp_context *context);
struct hfp_hf *hfp_hf_new(int fd);
--
1.8.4
^ permalink raw reply related
* [PATCH 5/8] shared/hfp: Minor fix in container close function
From: Lukasz Rymanowski @ 2014-10-09 23:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Lukasz Rymanowski
In-Reply-To: <1412898652-12281-1-git-send-email-lukasz.rymanowski@tieto.com>
When closing container of hfp_context, we should try to move to next
field so offset is set correctly to next data.
Needed in case of parsing for example:
.+CIND: ("call",(0,1)),("callsetup",(0-3))")
---
src/shared/hfp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 6f2d28a..1ccbd16 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -331,6 +331,8 @@ bool hfp_context_close_container(struct hfp_context *context)
context->offset++;
+ next_field(context);
+
return true;
}
--
1.8.4
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox