Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/5] android/gatt: Implement MTU exchange HAL API
@ 2015-03-11 14:41 Szymon Janc
  2015-03-11 14:41 ` [PATCH 2/5] android: Update Android system headers to 5.1 API Szymon Janc
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Szymon Janc @ 2015-03-11 14:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allow application to query for current MTU. MTU is always
exchanged on connection and notifications are sent to framework.

When client requests MTU exchange we just report current value but
don't trigger another exchange procedure (since this is against spec).
---
 android/gatt.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 60 insertions(+), 3 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 9c2a280..1a264ba 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -941,6 +941,39 @@ static bool get_local_mtu(struct gatt_device *dev, uint16_t *mtu)
 	return true;
 }
 
+static void notify_client_mtu_change(struct app_connection *conn, bool success)
+{
+	struct hal_ev_gatt_client_configure_mtu ev;
+	size_t mtu;
+
+	g_attrib_get_buffer(conn->device->attrib, &mtu);
+
+	ev.conn_id = conn->id;
+	ev.status = success ? GATT_SUCCESS : GATT_FAILURE;
+	ev.mtu = mtu;
+
+	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
+			HAL_EV_GATT_CLIENT_CONFIGURE_MTU, sizeof(ev), &ev);
+}
+
+static void notify_mtu_change(void *data, void *user_data)
+{
+	struct gatt_device *device = user_data;
+	struct app_connection *conn = data;
+
+	if (conn->device != device)
+		return;
+
+	switch (conn->app->type) {
+	case GATT_CLIENT:
+		notify_client_mtu_change(conn, true);
+		break;
+	case GATT_SERVER:
+	default:
+		break;
+	}
+}
+
 static bool update_mtu(struct gatt_device *device, uint16_t rmtu)
 {
 	uint16_t mtu, lmtu;
@@ -965,6 +998,8 @@ static bool update_mtu(struct gatt_device *device, uint16_t rmtu)
 		return false;
 	}
 
+	queue_foreach(app_connections, notify_mtu_change, device);
+
 	return true;
 }
 
@@ -1600,6 +1635,11 @@ reply:
 	data.status = status;
 	queue_foreach(app_connections, notify_app_connect_status_by_device,
 									&data);
+
+	/* For BR/EDR notify about MTU since it is not negotiable*/
+	if (cid != ATT_CID)
+		queue_foreach(app_connections, notify_mtu_change, dev);
+
 	device_unref(dev);
 
 	/* Check if we should restart scan */
@@ -5676,14 +5716,31 @@ static void handle_client_scan_filter_enable(const void *buf, uint16_t len)
 static void handle_client_configure_mtu(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_client_configure_mtu *cmd = buf;
+	static struct app_connection *conn;
+	uint8_t status;
 
-	DBG("conn_id %u", cmd->conn_id);
+	DBG("conn_id %u mtu %d", cmd->conn_id, cmd->mtu);
 
-	/* TODO */
+	conn = find_connection_by_id(cmd->conn_id);
+	if (!conn) {
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
 
+	/*
+	 * currently MTU is always exchanged on connection, just report current
+	 * value
+	 *
+	 * TODO figure out when send failed status
+	 * TODO should we fail for BR/EDR?
+	 */
+	notify_client_mtu_change(conn, false);
+	status = HAL_STATUS_SUCCESS;
+
+failed:
 	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
 					HAL_OP_GATT_CLIENT_CONFIGURE_MTU,
-					HAL_STATUS_UNSUPPORTED);
+					status);
 }
 
 static void handle_client_conn_param_update(const void *buf, uint16_t len)
-- 
1.9.3


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

* [PATCH 2/5] android: Update Android system headers to 5.1 API
  2015-03-11 14:41 [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
@ 2015-03-11 14:41 ` Szymon Janc
  2015-03-11 14:41 ` [PATCH 3/5] android/hal-ipc-api: Add GATT Server MTU Changed notification Szymon Janc
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2015-03-11 14:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Android headers are used for Linux host build.
---
 android/Makefile.am               | 2 +-
 android/hardware/bt_gatt_server.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/android/Makefile.am b/android/Makefile.am
index 676daab..7eb6440 100644
--- a/android/Makefile.am
+++ b/android/Makefile.am
@@ -1,6 +1,6 @@
 if ANDROID
 
-AM_CFLAGS += -DANDROID_VERSION=0x050000
+AM_CFLAGS += -DANDROID_VERSION=0x050100
 
 android_plugindir = $(abs_top_srcdir)/android/.libs
 
diff --git a/android/hardware/bt_gatt_server.h b/android/hardware/bt_gatt_server.h
index 2b1de27..0d6cc1e 100644
--- a/android/hardware/bt_gatt_server.h
+++ b/android/hardware/bt_gatt_server.h
@@ -117,6 +117,9 @@ typedef void (*indication_sent_callback)(int conn_id, int status);
  */
 typedef void (*congestion_callback)(int conn_id, bool congested);
 
+/** Callback invoked when the MTU for a given connection changes */
+typedef void (*mtu_changed_callback)(int conn_id, int mtu);
+
 typedef struct {
     register_server_callback        register_server_cb;
     connection_callback             connection_cb;
@@ -133,6 +136,7 @@ typedef struct {
     response_confirmation_callback  response_confirmation_cb;
     indication_sent_callback        indication_sent_cb;
     congestion_callback             congestion_cb;
+    mtu_changed_callback            mtu_changed_cb;
 } btgatt_server_callbacks_t;
 
 /** Represents the standard BT-GATT server interface. */
-- 
1.9.3


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

* [PATCH 3/5] android/hal-ipc-api: Add GATT Server MTU Changed notification
  2015-03-11 14:41 [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
  2015-03-11 14:41 ` [PATCH 2/5] android: Update Android system headers to 5.1 API Szymon Janc
@ 2015-03-11 14:41 ` Szymon Janc
  2015-03-11 14:41 ` [PATCH 4/5] android/hal-gatt: Add support for server MTU changed callback Szymon Janc
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2015-03-11 14:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Add definition of GATT server MTU changed notification.
---
 android/hal-ipc-api.txt | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/android/hal-ipc-api.txt b/android/hal-ipc-api.txt
index 77f2f57..503b47a 100644
--- a/android/hal-ipc-api.txt
+++ b/android/hal-ipc-api.txt
@@ -2329,6 +2329,11 @@ Notifications:
 		Notification parameters: Connection ID (4 octets)
 		                         Congested (1 octet)
 
+	Opcode 0xb0 - Server MTU Changed notification
+
+		Notification parameters: Connection ID (4 octets)
+		                         MTU (4 octets)
+
 
 Bluetooth Handsfree Client HAL (ID 10)
 ======================================
-- 
1.9.3


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

* [PATCH 4/5] android/hal-gatt: Add support for server MTU changed callback
  2015-03-11 14:41 [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
  2015-03-11 14:41 ` [PATCH 2/5] android: Update Android system headers to 5.1 API Szymon Janc
  2015-03-11 14:41 ` [PATCH 3/5] android/hal-ipc-api: Add GATT Server MTU Changed notification Szymon Janc
@ 2015-03-11 14:41 ` Szymon Janc
  2015-03-11 14:41 ` [PATCH 5/5] android/gatt: Add suport " Szymon Janc
  2015-03-12 15:03 ` [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
  4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2015-03-11 14:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

---
 android/hal-gatt.c | 13 +++++++++++++
 android/hal-msg.h  |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/android/hal-gatt.c b/android/hal-gatt.c
index 438ad61..f7217c7 100644
--- a/android/hal-gatt.c
+++ b/android/hal-gatt.c
@@ -641,6 +641,16 @@ static void handle_server_congestion(void *buf, uint16_t len, int fd)
 #endif
 }
 
+static void handle_server_mtu_changed(void *buf, uint16_t len, int fd)
+{
+#if ANDROID_VERSION >= PLATFORM_VER(5, 1, 0)
+	struct hal_ev_gatt_server_mtu_changed *ev = buf;
+
+	if (cbs->server->mtu_changed_cb)
+		cbs->server->mtu_changed_cb(ev->conn_id, ev->mtu);
+#endif
+}
+
 /*
  * handlers will be called from notification thread context,
  * index in table equals to 'opcode - HAL_MINIMUM_EVENT'
@@ -784,6 +794,9 @@ static const struct hal_ipc_handler ev_handlers[] = {
 	/* HAL_EV_GATT_SERVER_CONGESTION */
 	{ handle_server_congestion, false,
 		sizeof(struct hal_ev_gatt_server_congestion) },
+	/* HAL_EV_GATT_SERVER_MTU_CHANGED */
+	{ handle_server_mtu_changed, false,
+		sizeof(struct hal_ev_gatt_server_mtu_changed) },
 	};
 
 /* Client API */
diff --git a/android/hal-msg.h b/android/hal-msg.h
index 0ec07c7..698f45a 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -2092,6 +2092,12 @@ struct hal_ev_gatt_server_congestion {
 	uint8_t congested;
 } __attribute__((packed));
 
+#define HAL_EV_GATT_SERVER_MTU_CHANGED		0xb0
+struct hal_ev_gatt_server_mtu_changed {
+	int32_t conn_id;
+	int32_t mtu;
+} __attribute__((packed));
+
 #define HAL_GATT_PERMISSION_READ			0x0001
 #define HAL_GATT_PERMISSION_READ_ENCRYPTED		0x0002
 #define HAL_GATT_PERMISSION_READ_ENCRYPTED_MITM		0x0004
-- 
1.9.3


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

* [PATCH 5/5] android/gatt: Add suport for server MTU changed callback
  2015-03-11 14:41 [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
                   ` (2 preceding siblings ...)
  2015-03-11 14:41 ` [PATCH 4/5] android/hal-gatt: Add support for server MTU changed callback Szymon Janc
@ 2015-03-11 14:41 ` Szymon Janc
  2015-03-12 15:03 ` [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
  4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2015-03-11 14:41 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

When MTU is exchange notification is send with updated MTU.
For BR/EDR notification is always send after connection.
---
 android/gatt.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 1a264ba..bf1741e 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -956,6 +956,20 @@ static void notify_client_mtu_change(struct app_connection *conn, bool success)
 			HAL_EV_GATT_CLIENT_CONFIGURE_MTU, sizeof(ev), &ev);
 }
 
+static void notify_server_mtu(struct app_connection *conn)
+{
+	struct hal_ev_gatt_server_mtu_changed ev;
+	size_t mtu;
+
+	g_attrib_get_buffer(conn->device->attrib, &mtu);
+
+	ev.conn_id = conn->id;
+	ev.mtu = mtu;
+
+	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
+			HAL_EV_GATT_SERVER_MTU_CHANGED, sizeof(ev), &ev);
+}
+
 static void notify_mtu_change(void *data, void *user_data)
 {
 	struct gatt_device *device = user_data;
@@ -969,6 +983,8 @@ static void notify_mtu_change(void *data, void *user_data)
 		notify_client_mtu_change(conn, true);
 		break;
 	case GATT_SERVER:
+		notify_server_mtu(conn);
+		break;
 	default:
 		break;
 	}
-- 
1.9.3


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

* Re: [PATCH 1/5] android/gatt: Implement MTU exchange HAL API
  2015-03-11 14:41 [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
                   ` (3 preceding siblings ...)
  2015-03-11 14:41 ` [PATCH 5/5] android/gatt: Add suport " Szymon Janc
@ 2015-03-12 15:03 ` Szymon Janc
  4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2015-03-12 15:03 UTC (permalink / raw)
  To: linux-bluetooth

On Wednesday 11 of March 2015 15:41:19 Szymon Janc wrote:
> This allow application to query for current MTU. MTU is always
> exchanged on connection and notifications are sent to framework.
> 
> When client requests MTU exchange we just report current value but
> don't trigger another exchange procedure (since this is against spec).
> ---
>  android/gatt.c | 63
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed,
> 60 insertions(+), 3 deletions(-)
> 
> diff --git a/android/gatt.c b/android/gatt.c
> index 9c2a280..1a264ba 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -941,6 +941,39 @@ static bool get_local_mtu(struct gatt_device *dev,
> uint16_t *mtu) return true;
>  }
> 
> +static void notify_client_mtu_change(struct app_connection *conn, bool
> success) +{
> +	struct hal_ev_gatt_client_configure_mtu ev;
> +	size_t mtu;
> +
> +	g_attrib_get_buffer(conn->device->attrib, &mtu);
> +
> +	ev.conn_id = conn->id;
> +	ev.status = success ? GATT_SUCCESS : GATT_FAILURE;
> +	ev.mtu = mtu;
> +
> +	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
> +			HAL_EV_GATT_CLIENT_CONFIGURE_MTU, sizeof(ev), &ev);
> +}
> +
> +static void notify_mtu_change(void *data, void *user_data)
> +{
> +	struct gatt_device *device = user_data;
> +	struct app_connection *conn = data;
> +
> +	if (conn->device != device)
> +		return;
> +
> +	switch (conn->app->type) {
> +	case GATT_CLIENT:
> +		notify_client_mtu_change(conn, true);
> +		break;
> +	case GATT_SERVER:
> +	default:
> +		break;
> +	}
> +}
> +
>  static bool update_mtu(struct gatt_device *device, uint16_t rmtu)
>  {
>  	uint16_t mtu, lmtu;
> @@ -965,6 +998,8 @@ static bool update_mtu(struct gatt_device *device,
> uint16_t rmtu) return false;
>  	}
> 
> +	queue_foreach(app_connections, notify_mtu_change, device);
> +
>  	return true;
>  }
> 
> @@ -1600,6 +1635,11 @@ reply:
>  	data.status = status;
>  	queue_foreach(app_connections, notify_app_connect_status_by_device,
>  									&data);
> +
> +	/* For BR/EDR notify about MTU since it is not negotiable*/
> +	if (cid != ATT_CID)
> +		queue_foreach(app_connections, notify_mtu_change, dev);
> +
>  	device_unref(dev);
> 
>  	/* Check if we should restart scan */
> @@ -5676,14 +5716,31 @@ static void handle_client_scan_filter_enable(const
> void *buf, uint16_t len) static void handle_client_configure_mtu(const void
> *buf, uint16_t len) {
>  	const struct hal_cmd_gatt_client_configure_mtu *cmd = buf;
> +	static struct app_connection *conn;
> +	uint8_t status;
> 
> -	DBG("conn_id %u", cmd->conn_id);
> +	DBG("conn_id %u mtu %d", cmd->conn_id, cmd->mtu);
> 
> -	/* TODO */
> +	conn = find_connection_by_id(cmd->conn_id);
> +	if (!conn) {
> +		status = HAL_STATUS_FAILED;
> +		goto failed;
> +	}
> 
> +	/*
> +	 * currently MTU is always exchanged on connection, just report current
> +	 * value
> +	 *
> +	 * TODO figure out when send failed status
> +	 * TODO should we fail for BR/EDR?
> +	 */
> +	notify_client_mtu_change(conn, false);
> +	status = HAL_STATUS_SUCCESS;
> +
> +failed:
>  	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
>  					HAL_OP_GATT_CLIENT_CONFIGURE_MTU,
> -					HAL_STATUS_UNSUPPORTED);
> +					status);
>  }
> 
>  static void handle_client_conn_param_update(const void *buf, uint16_t len)

Applied.

-- 
BR
Szymon Janc

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

end of thread, other threads:[~2015-03-12 15:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-11 14:41 [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc
2015-03-11 14:41 ` [PATCH 2/5] android: Update Android system headers to 5.1 API Szymon Janc
2015-03-11 14:41 ` [PATCH 3/5] android/hal-ipc-api: Add GATT Server MTU Changed notification Szymon Janc
2015-03-11 14:41 ` [PATCH 4/5] android/hal-gatt: Add support for server MTU changed callback Szymon Janc
2015-03-11 14:41 ` [PATCH 5/5] android/gatt: Add suport " Szymon Janc
2015-03-12 15:03 ` [PATCH 1/5] android/gatt: Implement MTU exchange HAL API Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox