linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add indication/notification support to interactive gatttool
@ 2011-03-10 19:26 Sheldon Demario
  2011-03-11 10:56 ` Johan Hedberg
  0 siblings, 1 reply; 2+ messages in thread
From: Sheldon Demario @ 2011-03-10 19:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Sheldon Demario

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

diff --git a/attrib/interactive.c b/attrib/interactive.c
index 232cf35..99e99c5 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -98,6 +98,41 @@ static void set_state(enum state st)
 	rl_redisplay();
 }
 
+static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
+{
+	uint8_t opdu[ATT_MAX_MTU];
+	uint16_t handle, i, olen;
+
+	handle = att_get_u16(&pdu[1]);
+
+	printf("\n");
+	switch (pdu[0]) {
+	case ATT_OP_HANDLE_NOTIFY:
+		printf("Notification handle = 0x%04x value: ", handle);
+		break;
+	case ATT_OP_HANDLE_IND:
+		printf("Indication   handle = 0x%04x value: ", handle);
+		break;
+	default:
+		printf("Invalid opcode\n");
+		return;
+	}
+
+	for (i = 3; i < len; i++)
+		printf("%02x ", pdu[i]);
+
+	printf("\n");
+	rl_forced_update_display();
+
+	if (pdu[0] == ATT_OP_HANDLE_NOTIFY)
+		return;
+
+	olen = enc_confirmation(opdu, sizeof(opdu));
+
+	if (olen > 0)
+		g_attrib_send(attrib, 0, opdu[0], opdu, olen, NULL, NULL, NULL);
+}
+
 static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
 {
 	if (err) {
@@ -107,6 +142,10 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
 	}
 
 	attrib = g_attrib_new(iochannel);
+	g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, events_handler,
+							attrib, NULL);
+	g_attrib_register(attrib, ATT_OP_HANDLE_IND, events_handler,
+							attrib, NULL);
 	set_state(STATE_CONNECTED);
 }
 
-- 
1.7.1


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

* Re: [PATCH] Add indication/notification support to interactive gatttool
  2011-03-10 19:26 [PATCH] Add indication/notification support to interactive gatttool Sheldon Demario
@ 2011-03-11 10:56 ` Johan Hedberg
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hedberg @ 2011-03-11 10:56 UTC (permalink / raw)
  To: Sheldon Demario; +Cc: linux-bluetooth

Hi Sheldon,

On Thu, Mar 10, 2011, Sheldon Demario wrote:
> ---
>  attrib/interactive.c |   39 +++++++++++++++++++++++++++++++++++++++
>  1 files changed, 39 insertions(+), 0 deletions(-)

Pushed upstream. Thanks.

Johan

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

end of thread, other threads:[~2011-03-11 10:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-10 19:26 [PATCH] Add indication/notification support to interactive gatttool Sheldon Demario
2011-03-11 10:56 ` Johan Hedberg

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