Diff between dff482a423242fff54965c0b2bf01326183ff3d8 and cb6dd1222d84e3dd7d9c60afa9e7b5721ed03c02

Changed Files

File Additions Deletions Status
lib/mgmt.h +8 -0 modified
plugins/mgmtops.c +38 -0 modified

Full Patch

diff --git a/lib/mgmt.h b/lib/mgmt.h
index 3d29b24..71c3ba4 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -269,3 +269,11 @@ struct mgmt_ev_auth_failed {
 struct mgmt_ev_local_name_changed {
 	uint8_t name[249];
 } __packed;
+
+#define MGMT_EV_DEVICE_FOUND		0x0012
+struct mgmt_ev_device_found {
+	bdaddr_t bdaddr;
+	uint8_t dev_class[3];
+	int8_t rssi;
+	uint8_t eir[HCI_MAX_EIR_LENGTH];
+} __packed;
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index 65b32e6..e3410e9 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -1257,6 +1257,41 @@ static void mgmt_local_name_changed(int sk, uint16_t index, void *buf, size_t le
 		adapter_update_local_name(adapter, (char *) ev->name);
 }
 
+static void mgmt_device_found(int sk, uint16_t index, void *buf, size_t len)
+{
+	struct mgmt_ev_device_found *ev = buf;
+	struct controller_info *info;
+	char addr[18];
+	uint8_t *eir;
+	uint32_t cls;
+
+	if (len < sizeof(*ev)) {
+		error("Too small mgmt_device_found event packet");
+		return;
+	}
+
+	if (index > max_index) {
+		error("Unexpected index %u in device_found event", index);
+		return;
+	}
+
+	info = &controllers[index];
+
+	cls = ev->dev_class[0] | (ev->dev_class[1] << 8) |
+						(ev->dev_class[2] << 16);
+
+	if (ev->eir[0] == 0)
+		eir = NULL;
+	else
+		eir = ev->eir;
+
+	ba2str(&ev->bdaddr, addr);
+	DBG("hci%u addr %s, class %u rssi %d %s", index, addr, cls,
+						ev->rssi, eir ? "eir" : "");
+
+	btd_event_device_found(&info->bdaddr, &ev->bdaddr, cls, ev->rssi, eir);
+}
+
 static gboolean mgmt_event(GIOChannel *io, GIOCondition cond, gpointer user_data)
 {
 	char buf[MGMT_BUF_SIZE];
@@ -1352,6 +1387,9 @@ static gboolean mgmt_event(GIOChannel *io, GIOCondition cond, gpointer user_data
 	case MGMT_EV_LOCAL_NAME_CHANGED:
 		mgmt_local_name_changed(sk, index, buf + MGMT_HDR_SIZE, len);
 		break;
+	case MGMT_EV_DEVICE_FOUND:
+		mgmt_device_found(sk, index, buf + MGMT_HDR_SIZE, len);
+		break;
 	default:
 		error("Unknown Management opcode %u (index %u)", opcode, index);
 		break;