Diff between d7e8d3cbf08c01830878eaf9b2a4c4c80168857c and 7ee8ea022d568ab5d6df7dd6d82841ffa7696fa9

Changed Files

File Additions Deletions Status
lib/mgmt.h +13 -9 modified
mgmt/main.c +40 -16 modified
plugins/mgmtops.c +10 -9 modified

Full Patch

diff --git a/lib/mgmt.h b/lib/mgmt.h
index e8080e5..6e39596 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -138,10 +138,20 @@ struct mgmt_rp_disconnect {
 	bdaddr_t bdaddr;
 } __packed;
 
+#define MGMT_ADDR_BREDR			0x00
+#define MGMT_ADDR_LE			0x01
+#define MGMT_ADDR_BREDR_LE		0x02
+#define MGMT_ADDR_INVALID		0xff
+
+struct mgmt_addr_info {
+	bdaddr_t bdaddr;
+	uint8_t type;
+} __packed;
+
 #define MGMT_OP_GET_CONNECTIONS		0x0010
 struct mgmt_rp_get_connections {
 	uint16_t conn_count;
-	bdaddr_t conn[0];
+	struct mgmt_addr_info addr[0];
 } __packed;
 
 #define MGMT_OP_PIN_CODE_REPLY		0x0011
@@ -260,18 +270,12 @@ struct mgmt_ev_new_key {
 } __packed;
 
 #define MGMT_EV_DEVICE_CONNECTED	0x000B
-struct mgmt_ev_device_connected {
-	bdaddr_t bdaddr;
-} __packed;
 
 #define MGMT_EV_DEVICE_DISCONNECTED	0x000C
-struct mgmt_ev_device_disconnected {
-	bdaddr_t bdaddr;
-} __packed;
 
 #define MGMT_EV_CONNECT_FAILED		0x000D
 struct mgmt_ev_connect_failed {
-	bdaddr_t bdaddr;
+	struct mgmt_addr_info addr;
 	uint8_t status;
 } __packed;
 
@@ -301,7 +305,7 @@ struct mgmt_ev_local_name_changed {
 
 #define MGMT_EV_DEVICE_FOUND		0x0012
 struct mgmt_ev_device_found {
-	bdaddr_t bdaddr;
+	struct mgmt_addr_info addr;
 	uint8_t dev_class[3];
 	int8_t rssi;
 	uint8_t eir[HCI_MAX_EIR_LENGTH];
diff --git a/mgmt/main.c b/mgmt/main.c
index 8160f45..ac0e96e 100644
--- a/mgmt/main.c
+++ b/mgmt/main.c
@@ -333,9 +333,26 @@ static int mgmt_new_key(int mgmt_sk, uint16_t index,
 	return 0;
 }
 
+static void type2str(uint8_t type, char *str, size_t len)
+{
+	switch (type) {
+	case MGMT_ADDR_BREDR:
+		strncpy(str, "BR/EDR", len);
+		break;
+	case MGMT_ADDR_LE:
+		strncpy(str, "LE", len);
+		break;
+	case MGMT_ADDR_BREDR_LE:
+		strncpy(str, "BR/EDR/LE", len);
+		break;
+	default:
+		strncpy(str, "(unknown)", len);
+		break;
+	}
+}
+
 static int mgmt_connected(int mgmt_sk, uint16_t index, bool connected,
-				struct mgmt_ev_device_connected *ev,
-				uint16_t len)
+				struct mgmt_addr_info *ev, uint16_t len)
 {
 	const char *ev_name = connected ? "connected" : "disconnected";
 
@@ -346,9 +363,11 @@ static int mgmt_connected(int mgmt_sk, uint16_t index, bool connected,
 	}
 
 	if (monitor) {
-		char addr[18];
+		char addr[18], type[10];
+
 		ba2str(&ev->bdaddr, addr);
-		printf("hci%u %s %s\n", index, addr, ev_name);
+		type2str(ev->type, type, sizeof(type));
+		printf("hci%u %s type %s %s\n", index, addr, type, ev_name);
 	}
 
 	return 0;
@@ -365,10 +384,12 @@ static int mgmt_conn_failed(int mgmt_sk, uint16_t index,
 	}
 
 	if (monitor) {
-		char addr[18];
-		ba2str(&ev->bdaddr, addr);
-		printf("hci%u %s connect failed with status 0x%02x\n",
-						index, addr, ev->status);
+		char addr[18], type[10];
+
+		ba2str(&ev->addr.bdaddr, addr);
+		type2str(ev->addr.type, type, sizeof(type));
+		printf("hci%u %s type %s connect failed (status 0x%02x)\n",
+						index, addr, type, ev->status);
 	}
 
 	return 0;
@@ -420,10 +441,11 @@ static int mgmt_device_found(int mgmt_sk, uint16_t index,
 	}
 
 	if (monitor || discovery) {
-		char addr[18];
-		ba2str(&ev->bdaddr, addr);
-		printf("hci%u dev_found: %s class 0x%02x%02x%02x rssi %d "
-			"eir (%s)\n", index, addr,
+		char addr[18], type[10];
+		ba2str(&ev->addr.bdaddr, addr);
+		type2str(ev->addr.type, type, sizeof(type));
+		printf("hci%u dev_found: %s type %s class 0x%02x%02x%02x "
+			"rssi %d eir (%s)\n", index, addr, type,
 			ev->dev_class[2], ev->dev_class[1], ev->dev_class[0],
 			ev->rssi, ev->eir[0] == 0 ? "no" : "yes");
 	}
@@ -836,17 +858,19 @@ static void con_rsp(int mgmt_sk, uint16_t op, uint16_t id, uint8_t status,
 	}
 
 	count = bt_get_le16(&rp->conn_count);
-	if (len != sizeof(*rp) + count * sizeof(bdaddr_t)) {
+	if (len != sizeof(*rp) + count * sizeof(struct mgmt_addr_info)) {
 		fprintf(stderr, "Invalid get_connections length "
 					" (count=%u, len=%u)\n", count, len);
 		exit(EXIT_FAILURE);
 	}
 
 	for (i = 0; i < count; i++) {
-		char addr[18];
+		char addr[18], type[18];
+
+		ba2str(&rp->addr[i].bdaddr, addr);
+		type2str(rp->addr[i].type, type, sizeof(type));
 
-		ba2str(&rp->conn[i], addr);
-		printf("%s\n", addr);
+		printf("%s type %s\n", addr, type);
 	}
 
 	exit(EXIT_SUCCESS);
diff --git a/plugins/mgmtops.c b/plugins/mgmtops.c
index d4221b8..68d13ef 100644
--- a/plugins/mgmtops.c
+++ b/plugins/mgmtops.c
@@ -430,7 +430,7 @@ static void mgmt_new_key(int sk, uint16_t index, void *buf, size_t len)
 
 static void mgmt_device_connected(int sk, uint16_t index, void *buf, size_t len)
 {
-	struct mgmt_ev_device_connected *ev = buf;
+	struct mgmt_addr_info *ev = buf;
 	struct controller_info *info;
 	char addr[18];
 
@@ -456,7 +456,7 @@ static void mgmt_device_connected(int sk, uint16_t index, void *buf, size_t len)
 static void mgmt_device_disconnected(int sk, uint16_t index, void *buf,
 								size_t len)
 {
-	struct mgmt_ev_device_disconnected *ev = buf;
+	struct mgmt_addr_info *ev = buf;
 	struct controller_info *info;
 	char addr[18];
 
@@ -490,7 +490,7 @@ static void mgmt_connect_failed(int sk, uint16_t index, void *buf, size_t len)
 		return;
 	}
 
-	ba2str(&ev->bdaddr, addr);
+	ba2str(&ev->addr.bdaddr, addr);
 
 	DBG("hci%u %s status %u", index, addr, ev->status);
 
@@ -501,10 +501,11 @@ static void mgmt_connect_failed(int sk, uint16_t index, void *buf, size_t len)
 
 	info = &controllers[index];
 
-	btd_event_conn_failed(&info->bdaddr, &ev->bdaddr, ev->status);
+	btd_event_conn_failed(&info->bdaddr, &ev->addr.bdaddr, ev->status);
 
 	/* In the case of security mode 3 devices */
-	btd_event_bonding_complete(&info->bdaddr, &ev->bdaddr, ev->status);
+	btd_event_bonding_complete(&info->bdaddr, &ev->addr.bdaddr,
+								ev->status);
 }
 
 static int mgmt_pincode_reply(int index, bdaddr_t *bdaddr, const char *pin,
@@ -1043,7 +1044,7 @@ static void get_connections_complete(int sk, uint16_t index, void *buf,
 	info = &controllers[index];
 
 	for (i = 0; i < rp->conn_count; i++) {
-		bdaddr_t *bdaddr = g_memdup(&rp->conn[i], sizeof(bdaddr_t));
+		bdaddr_t *bdaddr = g_memdup(&rp->addr[i], sizeof(bdaddr_t));
 		info->connections = g_slist_append(info->connections, bdaddr);
 	}
 
@@ -1345,12 +1346,12 @@ static void mgmt_device_found(int sk, uint16_t index, void *buf, size_t len)
 	else
 		eir = ev->eir;
 
-	ba2str(&ev->bdaddr, addr);
+	ba2str(&ev->addr.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,
-							HCI_MAX_EIR_LENGTH);
+	btd_event_device_found(&info->bdaddr, &ev->addr.bdaddr, cls,
+					ev->rssi, eir, HCI_MAX_EIR_LENGTH);
 }
 
 static void mgmt_remote_name(int sk, uint16_t index, void *buf, size_t len)