Diff between 988a2bb6ac8743e65f262e2a4368f0cf01e9722c and 0de52f95ec9b9512165174c7f4b2c5fe84c33dc0

Changed Files

File Additions Deletions Status
monitor/btsnoop.c +16 -1 modified
monitor/packet.c +25 -7 modified
monitor/packet.h +1 -1 modified

Full Patch

diff --git a/monitor/btsnoop.c b/monitor/btsnoop.c
index c07eb2d..0b3e412 100644
--- a/monitor/btsnoop.c
+++ b/monitor/btsnoop.c
@@ -207,6 +207,7 @@ int btsnoop_read(struct timeval *tv, uint16_t *index, uint16_t *opcode,
 	struct btsnoop_pkt pkt;
 	uint32_t toread, flags;
 	uint64_t ts;
+	uint8_t pkt_type;
 	ssize_t len;
 
 	if (btsnoop_fd < 0)
@@ -233,7 +234,21 @@ int btsnoop_read(struct timeval *tv, uint16_t *index, uint16_t *opcode,
 	switch (btsnoop_type) {
 	case 1001:
 		*index = 0;
-		*opcode = packet_get_opcode(flags);
+		*opcode = packet_get_opcode(0xff, flags);
+		break;
+
+	case 1002:
+		len = read(btsnoop_fd, &pkt_type, 1);
+		if (len < 0) {
+			perror("Failed to read packet type");
+			close(btsnoop_fd);
+			btsnoop_fd = -1;
+			return -1;
+		}
+		toread--;
+
+		*index = 0;
+		*opcode = packet_get_opcode(pkt_type, flags);
 		break;
 
 	case 2001:
diff --git a/monitor/packet.c b/monitor/packet.c
index eb1387e..0c4d360 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -867,18 +867,36 @@ uint32_t packet_get_flags(uint16_t opcode)
 	return 0xff;
 }
 
-uint16_t packet_get_opcode(uint32_t flags)
+uint16_t packet_get_opcode(uint8_t type, uint32_t flags)
 {
-	if (flags & 0x02) {
-		if (flags & 0x01)
-			return MONITOR_EVENT_PKT;
-		else
-			return MONITOR_COMMAND_PKT;
-	} else {
+	switch (type) {
+	case HCI_COMMAND_PKT:
+		return MONITOR_COMMAND_PKT;
+	case HCI_ACLDATA_PKT:
 		if (flags & 0x01)
 			return MONITOR_ACL_RX_PKT;
 		else
 			return MONITOR_ACL_TX_PKT;
+	case HCI_SCODATA_PKT:
+		if (flags & 0x01)
+			return MONITOR_SCO_RX_PKT;
+		else
+			return MONITOR_SCO_TX_PKT;
+	case HCI_EVENT_PKT:
+		return MONITOR_EVENT_PKT;
+	case 0xff:
+		if (flags & 0x02) {
+			if (flags & 0x01)
+				return MONITOR_EVENT_PKT;
+			else
+				return MONITOR_COMMAND_PKT;
+		} else {
+			if (flags & 0x01)
+				return MONITOR_ACL_RX_PKT;
+			else
+				return MONITOR_ACL_TX_PKT;
+		}
+		break;
 	}
 
 	return 0xff;
diff --git a/monitor/packet.h b/monitor/packet.h
index dd2f5e3..ea21bd7 100644
--- a/monitor/packet.h
+++ b/monitor/packet.h
@@ -42,7 +42,7 @@ void packet_monitor(struct timeval *tv, uint16_t index, uint16_t opcode,
 					const void *data, uint16_t size);
 
 uint32_t packet_get_flags(uint16_t opcode);
-uint16_t packet_get_opcode(uint32_t flags);
+uint16_t packet_get_opcode(uint8_t type, uint32_t flags);
 
 void packet_new_index(struct timeval *tv, uint16_t index, const char *label,
 				uint8_t type, uint8_t bus, const char *name);