You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2019/06/04 11:15:51 UTC

[mynewt-nimble] branch master updated: apps/bttester: Add support for reliable write

This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new 4f189e0  apps/bttester: Add support for reliable write
4f189e0 is described below

commit 4f189e077899b907a3c151fe729f46a53898b846
Author: MichaƂ Narajowski <mi...@codecoup.pl>
AuthorDate: Mon Jun 3 17:53:11 2019 +0200

    apps/bttester: Add support for reliable write
---
 apps/bttester/src/bttester.h | 10 ++++++++
 apps/bttester/src/gatt.c     | 60 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)

diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index 04f4501..34fe9b6 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -576,6 +576,16 @@ struct gatt_write_long_cmd {
 	u8_t data[0];
 } __packed;
 
+#define GATT_RELIABLE_WRITE		0x19
+struct gatt_reliable_write_cmd {
+    u8_t address_type;
+    u8_t address[6];
+    u16_t handle;
+    u16_t offset;
+    u16_t data_length;
+    u8_t data[0];
+} __packed;
+
 #define GATT_CFG_NOTIFY			0x1a
 #define GATT_CFG_INDICATE		0x1b
 struct gatt_cfg_notify_cmd {
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index b162ce5..a03f61a 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1654,6 +1654,63 @@ fail:
 		   BTP_STATUS_FAILED);
 }
 
+static int reliable_write_rsp(uint16_t conn_handle,
+			      const struct ble_gatt_error *error,
+			      struct ble_gatt_attr *attrs,
+			      uint8_t num_attrs,
+			      void *arg)
+{
+	uint8_t err = (uint8_t) error->status;
+
+	SYS_LOG_DBG("");
+
+	tester_send(BTP_SERVICE_ID_GATT, GATT_RELIABLE_WRITE,
+		    CONTROLLER_INDEX, &err,
+		    sizeof(err));
+	return 0;
+}
+
+static void reliable_write(u8_t *data, u16_t len)
+{
+	const struct gatt_reliable_write_cmd *cmd = (void *) data;
+	struct ble_gap_conn_desc conn;
+	struct ble_gatt_attr attr;
+	struct os_mbuf *om = NULL;
+	int rc;
+
+	SYS_LOG_DBG("");
+
+	rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
+	if (rc) {
+		goto fail;
+	}
+
+	om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
+	/* This is required, because Nimble checks if
+	 * the data is longer than offset
+	 */
+	if (os_mbuf_extend(om, sys_le16_to_cpu(cmd->offset) + 1) == NULL) {
+		goto fail;
+	}
+
+	attr.handle = sys_le16_to_cpu(cmd->handle);
+	attr.offset = sys_le16_to_cpu(cmd->offset);
+	attr.om = om;
+
+	if (ble_gattc_write_reliable(conn.conn_handle, &attr, 1,
+				     reliable_write_rsp, NULL)) {
+		goto fail;
+	}
+
+	return;
+
+	fail:
+	os_mbuf_free_chain(om);
+
+	tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE_LONG, CONTROLLER_INDEX,
+		   BTP_STATUS_FAILED);
+}
+
 static struct bt_gatt_subscribe_params {
 	u16_t ccc_handle;
 	u16_t value;
@@ -2235,6 +2292,9 @@ void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
 	case GATT_WRITE_LONG:
 		write_long(data, len);
 		return;
+	case GATT_RELIABLE_WRITE:
+		reliable_write(data, len);
+		return;
 	case GATT_CFG_NOTIFY:
 	case GATT_CFG_INDICATE:
 		config_subscription(data, len, opcode);