aboutsummaryrefslogtreecommitdiff
path: root/attrib
diff options
context:
space:
mode:
authorSheldon Demario <sheldon.demario@openbossa.org>2011-03-10 16:26:46 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2011-03-11 12:55:54 +0200
commitcc2d6b4db85e8128f1d4c2be7c1ee7e21b708ea3 (patch)
tree8d15172914f4f1b707a4e6fb6c3bfef5a865d8f3 /attrib
parentc77263675b971943225ed62adb368727d67d7a4f (diff)
downloadbluez-cc2d6b4db85e8128f1d4c2be7c1ee7e21b708ea3.tar.gz
Add indication/notification support to interactive gatttool
Diffstat (limited to 'attrib')
-rw-r--r--attrib/interactive.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/attrib/interactive.c b/attrib/interactive.c
index d92caa89..1d6f42d5 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -100,6 +100,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) {
@@ -109,6 +144,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);
}