[PATCH 5/6] Add Write Request in interactive gatttool

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Bruna Moreira <bruna.moreira@xxxxxxxxxxxxx>

---
 attrib/interactive.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/attrib/interactive.c b/attrib/interactive.c
index c5dd2b7..e5817ab 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -501,6 +501,56 @@ static void cmd_read_uuid(int argcp, char **argvp)
 					char_read_by_uuid_cb, char_data);
 }
 
+static void char_write_req_cb(guint8 status, const guint8 *pdu, guint16 plen,
+							gpointer user_data)
+{
+	if (status != 0) {
+		printf("Characteristic Write Request failed: "
+						"%s\n", att_ecode2str(status));
+		return;
+	}
+
+	if (!dec_write_resp(pdu, plen)) {
+		printf("Protocol error\n");
+		return;
+	}
+
+	printf("Characteristic value was written successfully\n");
+}
+
+static void cmd_char_write_req(int argcp, char **argvp)
+{
+	uint8_t *value;
+	size_t plen;
+	int handle;
+
+	if (conn_state != STATE_CONNECTED) {
+		printf("Command failed: disconnected\n");
+		return;
+	}
+
+	if (argcp < 3) {
+		printf("Usage: char-write-req <handle> <new value>\n");
+		return;
+	}
+
+	handle = strtoll(argvp[1], NULL, 16);
+	if (errno != 0 || handle <= 0) {
+		printf("A valid handle is required\n");
+		return;
+	}
+
+	plen = gatt_attr_data_from_string(argvp[2], &value);
+	if (plen == 0) {
+		g_printerr("Invalid value\n");
+		return;
+	}
+
+	gatt_write_char(attrib, handle, value, plen, char_write_req_cb, NULL);
+
+	g_free(value);
+}
+
 static struct {
 	const char *cmd;
 	void (*func)(int argcp, char **argvp);
@@ -525,6 +575,8 @@ static struct {
 		"Characteristics Value/Descriptor Read by handle" },
 	{ "char-read-uuid",	cmd_read_uuid,	"<UUID> [start hnd] [end hnd]",
 		"Characteristics Value/Descriptor Read by UUID" },
+	{ "char-write-req",	cmd_char_write_req,	"<handle> <new value>",
+		"Characteristic Value Write (Write Request)" },
 	{ NULL, NULL, NULL}
 };
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux