Add support for getting the controller index list
diff --git a/lib/mgmt.h b/lib/mgmt.h
index 46fc527..25e15e7 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -40,7 +40,14 @@
#define MGMT_READ_VERSION_RP_SIZE 4
#define MGMT_OP_READ_FEATURES 0x0002
+
#define MGMT_OP_READ_INDEX_LIST 0x0003
+struct mgmt_read_index_list_rp {
+ uint16_t num_controllers;
+ uint16_t index[0];
+} __packed;
+#define MGMT_READ_INDEX_LIST_RP_SIZE 2
+
#define MGMT_OP_READ_INFO 0x0004
#define MGMT_OP_READ_STATISTICS 0x0005
#define MGMT_OP_READ_MODE 0x0006
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index d60b77f..c6ceb5f 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -53,6 +53,7 @@
static void read_version_complete(int sk, void *buf, size_t len)
{
+ struct mgmt_hdr hdr;
struct mgmt_read_version_rp *rp = buf;
uint16_t revision;
@@ -65,6 +66,39 @@
DBG("status %u version %u revision %u", rp->status, rp->version,
revision);
+
+ memset(&hdr, 0, sizeof(hdr));
+ hdr.opcode = MGMT_OP_READ_INDEX_LIST;
+ if (write(sk, &hdr, sizeof(hdr)) < 0)
+ error("Unable to read controller index list: %s (%d)",
+ strerror(errno), errno);
+}
+
+static void read_index_list_complete(int sk, void *buf, size_t len)
+{
+ struct mgmt_read_index_list_rp *rp = buf;
+ uint16_t num;
+ int i;
+
+ if (len < MGMT_READ_INDEX_LIST_RP_SIZE) {
+ error("Too small read index list complete event");
+ return;
+ }
+
+ num = btohs(bt_get_unaligned(&rp->num_controllers));
+
+ if (num * sizeof(uint16_t) + MGMT_READ_INDEX_LIST_RP_SIZE != len) {
+ error("Incorrect packet size for index list event");
+ return;
+ }
+
+ for (i = 0; i < num; i++) {
+ uint16_t index;
+
+ index = btohs(bt_get_unaligned(&rp->index[i]));
+
+ DBG("Found controller %u", index);
+ }
}
static void mgmt_cmd_complete(int sk, void *buf, size_t len)
@@ -85,6 +119,9 @@
case MGMT_OP_READ_VERSION:
read_version_complete(sk, ev->data, len - sizeof(*ev));
break;
+ case MGMT_OP_READ_INDEX_LIST:
+ read_index_list_complete(sk, ev->data, len - sizeof(*ev));
+ break;
default:
error("Unknown command complete for opcode %u", opcode);
break;