From 48908574c4853023dfe402a120b58a7a7d1f56de Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 21 Jan 2011 07:03:02 +0200 Subject: [PATCH] mgmt: Add support for connected/disconnected events --- doc/mgmt-api.txt | 14 ++++++++++++ lib/mgmt.h | 12 ++++++++++ plugins/mgmtops.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt index cb00bd2d9..f71376240 100644 --- a/doc/mgmt-api.txt +++ b/doc/mgmt-api.txt @@ -310,3 +310,17 @@ Event Parameters Controller_Index (2 Octets) PIN_Length (1 Octet) } Old_Key_Type (1 Octet) + +Device Connected Event +====================== + +Event Code 0x000B +Event Parameters Controller_Index (2 Octets) + Address (6 Octets) + +Device Disconnected Event +========================= + +Event Code 0x000C +Event Parameters Controller_Index (2 Octets) + Address (6 Octets) diff --git a/lib/mgmt.h b/lib/mgmt.h index bd4bd96b0..5176ff33f 100644 --- a/lib/mgmt.h +++ b/lib/mgmt.h @@ -171,3 +171,15 @@ struct mgmt_ev_new_key { struct mgmt_key_info key; uint8_t old_key_type; } __packed; + +#define MGMT_EV_DEVICE_CONNECTED 0x000B +struct mgmt_ev_device_connected { + uint16_t index; + bdaddr_t bdaddr; +} __packed; + +#define MGMT_EV_DEVICE_DISCONNECTED 0x000C +struct mgmt_ev_device_disconnected { + uint16_t index; + bdaddr_t bdaddr; +} __packed; diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c index cf3b15a2b..4ed83ea4d 100644 --- a/plugins/mgmtops.c +++ b/plugins/mgmtops.c @@ -427,6 +427,56 @@ static void mgmt_new_key(int sk, void *buf, size_t len) ev->key.pin_len, ev->old_key_type); } +static void mgmt_device_connected(int sk, void *buf, size_t len) +{ + struct mgmt_ev_device_connected *ev = buf; + struct controller_info *info; + uint16_t index; + char addr[18]; + + if (len < sizeof(*ev)) { + error("Too small device_connected event"); + return; + } + + index = btohs(bt_get_unaligned(&ev->index)); + ba2str(&ev->bdaddr, addr); + + DBG("hci%u device %s connected", index, addr); + + if (index > max_index) { + error("Unexpected index %u in device_connected event", index); + return; + } + + info = &controllers[index]; +} + +static void mgmt_device_disconnected(int sk, void *buf, size_t len) +{ + struct mgmt_ev_device_disconnected *ev = buf; + struct controller_info *info; + uint16_t index; + char addr[18]; + + if (len < sizeof(*ev)) { + error("Too small device_disconnected event"); + return; + } + + index = btohs(bt_get_unaligned(&ev->index)); + ba2str(&ev->bdaddr, addr); + + DBG("hci%u device %s disconnected", index, addr); + + if (index > max_index) { + error("Unexpected index %u in device_disconnected event", index); + return; + } + + info = &controllers[index]; +} + static void uuid_to_uuid128(uuid_t *uuid128, const uuid_t *uuid) { if (uuid->type == SDP_UUID16) @@ -878,6 +928,12 @@ static gboolean mgmt_event(GIOChannel *io, GIOCondition cond, gpointer user_data case MGMT_EV_NEW_KEY: mgmt_new_key(sk, buf + MGMT_HDR_SIZE, len); break; + case MGMT_EV_DEVICE_CONNECTED: + mgmt_device_connected(sk, buf + MGMT_HDR_SIZE, len); + break; + case MGMT_EV_DEVICE_DISCONNECTED: + mgmt_device_disconnected(sk, buf + MGMT_HDR_SIZE, len); + break; default: error("Unknown Management opcode %u", opcode); break;