mgmt: Add support for connected/disconnected events
diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index cb00bd2..f713762 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -310,3 +310,17 @@
 				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 bd4bd96..5176ff3 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -171,3 +171,15 @@
 	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 cf3b15a..4ed83ea 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -427,6 +427,56 @@
 					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 @@
 	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;