linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] android/gatt: Fix service changed indication
@ 2014-12-11 16:53 Mariusz Skamra
  2014-12-11 16:53 ` [PATCH 2/2] android/gatt: Fix find_info_handle function Mariusz Skamra
  2014-12-11 17:55 ` [PATCH 1/2] android/gatt: Fix service changed indication Szymon Janc
  0 siblings, 2 replies; 3+ messages in thread
From: Mariusz Skamra @ 2014-12-11 16:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mariusz Skamra

This patch fixes the service changed indication issue.
Without confirmation callback indications were not sent.
Dummy ignore_confirmation_cb is used for this purpose.
---
 android/gatt.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 58bc22d..c4e3497 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1017,6 +1017,12 @@ static void send_exchange_mtu_request(struct gatt_device *device)
 		device_unref(device);
 }
 
+static void ignore_confirmation_cb(guint8 status, const guint8 *pdu,
+					guint16 len, gpointer user_data)
+{
+	/* Ignored. */
+}
+
 static void notify_att_range_change(struct gatt_device *dev,
 							struct att_range *range)
 {
@@ -1025,6 +1031,7 @@ static void notify_att_range_change(struct gatt_device *dev,
 	uint16_t ccc;
 	uint8_t *pdu;
 	size_t mtu;
+	GAttribResultFunc confirmation_cb = NULL;
 
 	handle = gatt_db_attribute_get_handle(service_changed_attrib);
 	if (!handle)
@@ -1044,6 +1051,7 @@ static void notify_att_range_change(struct gatt_device *dev,
 	case 0x0002:
 		length = enc_indication(handle, (uint8_t *) range,
 						sizeof(*range), pdu, mtu);
+		confirmation_cb = ignore_confirmation_cb;
 		break;
 	default:
 		/* 0xfff4 reserved for future use */
@@ -1051,7 +1059,8 @@ static void notify_att_range_change(struct gatt_device *dev,
 	}
 
 	if (length)
-		g_attrib_send(dev->attrib, 0, pdu, length, NULL, NULL, NULL);
+		g_attrib_send(dev->attrib, 0, pdu, length,
+						confirmation_cb, NULL, NULL);
 }
 
 static struct app_connection *create_connection(struct gatt_device *device,
@@ -5432,12 +5441,6 @@ failed:
 				HAL_OP_GATT_SERVER_DELETE_SERVICE, status);
 }
 
-static void ignore_confirmation_cb(guint8 status, const guint8 *pdu,
-						guint16 len, gpointer user_data)
-{
-	/* Ignored. */
-}
-
 static void handle_server_send_indication(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_server_send_indication *cmd = buf;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] android/gatt: Fix find_info_handle function
  2014-12-11 16:53 [PATCH 1/2] android/gatt: Fix service changed indication Mariusz Skamra
@ 2014-12-11 16:53 ` Mariusz Skamra
  2014-12-11 17:55 ` [PATCH 1/2] android/gatt: Fix service changed indication Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Mariusz Skamra @ 2014-12-11 16:53 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Mariusz Skamra

Server can contain attributes with 128-bit attribute types
---
 android/gatt.c | 50 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index c4e3497..4237813 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -6104,11 +6104,12 @@ static uint8_t find_info_handle(const uint8_t *cmd, uint16_t cmd_len,
 						uint8_t *rsp, size_t rsp_size,
 						uint16_t *length)
 {
-	struct queue *q;
+	struct gatt_db_attribute *attrib;
+	struct queue *q, *temp;
 	struct att_data_list *adl;
 	int iterator = 0;
 	uint16_t start, end;
-	uint16_t len;
+	uint16_t len, queue_len;
 
 	DBG("");
 
@@ -6130,17 +6131,45 @@ static uint8_t find_info_handle(const uint8_t *cmd, uint16_t cmd_len,
 		return ATT_ECODE_ATTR_NOT_FOUND;
 	}
 
-	len = queue_length(q);
-	adl = att_data_list_alloc(len, 2 * sizeof(uint16_t));
-	if (!adl) {
+	temp = queue_new();
+	if (!temp) {
+		queue_destroy(q, NULL);
+		return ATT_ECODE_UNLIKELY;
+	}
+
+	attrib = queue_peek_head(q);
+	/* UUIDS can be only 128 bit and 16 bit */
+	len = bt_uuid_len(gatt_db_attribute_get_type(attrib));
+	if (len != 2 && len != 16) {
 		queue_destroy(q, NULL);
+		queue_destroy(temp, NULL);
+		return ATT_ECODE_UNLIKELY;
+	}
+
+	while (attrib) {
+		const bt_uuid_t *type;
+		type = gatt_db_attribute_get_type(attrib);
+
+		if (bt_uuid_len(type) != len)
+			break;
+
+		queue_push_tail(temp, queue_pop_head(q));
+		attrib = queue_peek_head(q);
+	}
+
+	queue_destroy(q, NULL);
+
+	queue_len = queue_length(temp);
+	adl = att_data_list_alloc(queue_len, len + sizeof(uint16_t));
+	if (!adl) {
+		queue_destroy(temp, NULL);
 		return ATT_ECODE_INSUFF_RESOURCES;
 	}
 
-	while (queue_peek_head(q)) {
+	while (queue_peek_head(temp)) {
 		uint8_t *value;
 		const bt_uuid_t *type;
-		struct gatt_db_attribute *attrib = queue_pop_head(q);
+		struct gatt_db_attribute *attrib = queue_pop_head(temp);
 		uint16_t handle;
 
 		type = gatt_db_attribute_get_type(attrib);
@@ -6151,17 +6180,18 @@ static uint8_t find_info_handle(const uint8_t *cmd, uint16_t cmd_len,
 
 		handle = gatt_db_attribute_get_handle(attrib);
 		put_le16(handle, value);
-		memcpy(&value[2], &type->value.u16, bt_uuid_len(type));
+		memcpy(&value[2], &type->value, len);
 	}
 
-	len = enc_find_info_resp(ATT_FIND_INFO_RESP_FMT_16BIT, adl, rsp,
+	len = enc_find_info_resp(len == 2 ? ATT_FIND_INFO_RESP_FMT_16BIT :
+					ATT_FIND_INFO_RESP_FMT_128BIT, adl, rsp,
 								rsp_size);
 	if (!len)
 		return ATT_ECODE_UNLIKELY;
 
 	*length = len;
 	att_data_list_free(adl);
-	queue_destroy(q, free);
+	queue_destroy(temp, NULL);
 
 	return 0;
 }
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] android/gatt: Fix service changed indication
  2014-12-11 16:53 [PATCH 1/2] android/gatt: Fix service changed indication Mariusz Skamra
  2014-12-11 16:53 ` [PATCH 2/2] android/gatt: Fix find_info_handle function Mariusz Skamra
@ 2014-12-11 17:55 ` Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-12-11 17:55 UTC (permalink / raw)
  To: Mariusz Skamra; +Cc: linux-bluetooth

Hi Mariusz,

On Thursday 11 of December 2014 17:53:53 Mariusz Skamra wrote:
> This patch fixes the service changed indication issue.
> Without confirmation callback indications were not sent.
> Dummy ignore_confirmation_cb is used for this purpose.
> ---
>  android/gatt.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/android/gatt.c b/android/gatt.c
> index 58bc22d..c4e3497 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -1017,6 +1017,12 @@ static void send_exchange_mtu_request(struct
> gatt_device *device) device_unref(device);
>  }
> 
> +static void ignore_confirmation_cb(guint8 status, const guint8 *pdu,
> +					guint16 len, gpointer user_data)
> +{
> +	/* Ignored. */
> +}
> +
>  static void notify_att_range_change(struct gatt_device *dev,
>  							struct att_range *range)
>  {
> @@ -1025,6 +1031,7 @@ static void notify_att_range_change(struct gatt_device
> *dev, uint16_t ccc;
>  	uint8_t *pdu;
>  	size_t mtu;
> +	GAttribResultFunc confirmation_cb = NULL;
> 
>  	handle = gatt_db_attribute_get_handle(service_changed_attrib);
>  	if (!handle)
> @@ -1044,6 +1051,7 @@ static void notify_att_range_change(struct gatt_device
> *dev, case 0x0002:
>  		length = enc_indication(handle, (uint8_t *) range,
>  						sizeof(*range), pdu, mtu);
> +		confirmation_cb = ignore_confirmation_cb;
>  		break;
>  	default:
>  		/* 0xfff4 reserved for future use */
> @@ -1051,7 +1059,8 @@ static void notify_att_range_change(struct gatt_device
> *dev, }
> 
>  	if (length)
> -		g_attrib_send(dev->attrib, 0, pdu, length, NULL, NULL, NULL);
> +		g_attrib_send(dev->attrib, 0, pdu, length,
> +						confirmation_cb, NULL, NULL);
>  }
> 
>  static struct app_connection *create_connection(struct gatt_device *device,
> @@ -5432,12 +5441,6 @@ failed:
>  				HAL_OP_GATT_SERVER_DELETE_SERVICE, status);
>  }
> 
> -static void ignore_confirmation_cb(guint8 status, const guint8 *pdu,
> -						guint16 len, gpointer user_data)
> -{
> -	/* Ignored. */
> -}
> -
>  static void handle_server_send_indication(const void *buf, uint16_t len)
>  {
>  	const struct hal_cmd_gatt_server_send_indication *cmd = buf;

Both patches applied, thanks.

-- 
BR
Szymon Janc

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-11 17:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-11 16:53 [PATCH 1/2] android/gatt: Fix service changed indication Mariusz Skamra
2014-12-11 16:53 ` [PATCH 2/2] android/gatt: Fix find_info_handle function Mariusz Skamra
2014-12-11 17:55 ` [PATCH 1/2] android/gatt: Fix service changed indication Szymon Janc

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).