Skip to contentSkip to conversation

Add decoding for BNEP packet types

PATCH Applied Gowtham Anandha Babu 2 participants 7 messages Apr 21, 2015 – Apr 23, 2015 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

cover Add decoding for BNEP packet types

Gowtham Anandha Babu (5):
monitor: Add support for decoding bnep General pkt
monitor: Add support for decoding bnep Control pkt
monitor: Add support for decoding bnep Compressed pkt
monitor: Add support for decoding bnep SrcOnly pkt
monitor: Add support for decoding bnep DestOnly pkt

 monitor/bnep.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 169 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/5 monitor: Add support for decoding bnep General pkt

      BNEP: General Ethernet (0x00|0)
         dst 00:00:00:00:00:00 src 00:00:00:00:00:00 [proto 0x0300]
        3c 3b 3a 39 38 37 36 35 34 33 32 31 30 2f 2e 2d
        2c 2b 2a 29 28 27 26 25 24 23 22 21 20 1f 1e 1d
---
 monitor/bnep.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 66 insertions(+), 10 deletions(-)
monitor/bnep.c +66 -10
index 1450f85..61b5d71 100644
@@ -47,29 +47,72 @@
 #define GET_PKT_TYPE(type) (type & 0x7f)
 #define GET_EXTENSION(type) (type & 0x80)
 
+uint16_t proto = 0x0000;
+
 struct bnep_frame {
 	uint8_t type;
 	int extension;
 	struct l2cap_frame l2cap_frame;
 };
 
+static bool get_macaddr(struct bnep_frame *bnep_frame, char *str)
+{
+	uint8_t addr[6];
+	struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+	int i;
+
+	for (i = 0; i < 6; i++)
+		if (!l2cap_frame_get_u8(frame, &addr[i]))
+			return false;
+
+	sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
+		addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
+
+	return true;
+}
+
+static bool bnep_general(struct bnep_frame *bnep_frame,
+					uint8_t indent,	int hdr_len)
+{
+	struct l2cap_frame *frame;
+	char src_addr[20], dest_addr[20];
+
+	if (!get_macaddr(bnep_frame, dest_addr))
+		return false;
+
+	if (!get_macaddr(bnep_frame, src_addr))
+		return false;
+
+	frame = &bnep_frame->l2cap_frame;
+
+	if (!l2cap_frame_get_be16(frame, &proto))
+		return false;
+
+	print_field("%*cdst %s src %s [proto 0x%04x] ", indent,
+					' ', dest_addr, src_addr, proto);
+
+	return true;
+
+}
+
 struct bnep_data {
 	uint8_t type;
 	const char *str;
+	bool (*func) (struct bnep_frame *frame, uint8_t indent, int hdr_len);
 };
 
 static const struct bnep_data bnep_table[] = {
-	{ 0x00, "General Ethernet"},
-	{ 0x01, "Control"},
-	{ 0x02, "Compressed Ethernet"},
-	{ 0x03, "Compressed Ethernet Src Only"},
-	{ 0x04, "Compressed Ethernet Dest Only"},
+	{ 0x00, "General Ethernet",		bnep_general	},
+	{ 0x01, "Control",					},
+	{ 0x02, "Compressed Ethernet",				},
+	{ 0x03, "Compressed Ethernet SrcOnly",			},
+	{ 0x04, "Compressed Ethernet DestOnly",			},
 	{ }
 };
 
 void bnep_packet(const struct l2cap_frame *frame)
 {
-	uint8_t type;
+	uint8_t type, indent = 1;
 	struct bnep_frame bnep_frame;
 	struct l2cap_frame *l2cap_frame;
 	const struct bnep_data *bnep_data = NULL;
@@ -93,10 +136,13 @@ void bnep_packet(const struct l2cap_frame *frame)
 	}
 
 	if (bnep_data) {
-		if (frame->in)
-			pdu_color = COLOR_MAGENTA;
-		else
-			pdu_color = COLOR_BLUE;
+		if (bnep_data->func) {
+			if (frame->in)
+				pdu_color = COLOR_MAGENTA;
+			else
+				pdu_color = COLOR_BLUE;
+		} else
+			pdu_color = COLOR_WHITE_BG;
 		pdu_str = bnep_data->str;
 	} else {
 		pdu_color = COLOR_WHITE_BG;
@@ -107,7 +153,17 @@ void bnep_packet(const struct l2cap_frame *frame)
 				" (0x%02x|%s)", bnep_frame.type,
 				bnep_frame.extension ? "1" : "0");
 
+	if (!bnep_data || !bnep_data->func) {
+		packet_hexdump(l2cap_frame->data, l2cap_frame->size);
+		return;
+	}
+
+	if (!bnep_data->func(&bnep_frame, indent, -1))
+		goto fail;
+
+	/* TODO: Handle BNEP packet with Extension Header */
 	packet_hexdump(l2cap_frame->data, l2cap_frame->size);
+
 	return;
 
 fail:
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/5 monitor: Add support for decoding bnep Control pkt

In reply to Gowtham Anandha Babu
      BNEP: Control (0x01|0)
         Filter MultAddr Set (0x05)
        00 30 ff ff ff ff ff ff ff ff ff ff ff ff 33 33
        00 00 00 01 33 33 00 00 00 01 01 00 5e 00 00 01
---
 monitor/bnep.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
monitor/bnep.c +48 -1
index 61b5d71..d417e2f 100644
@@ -95,6 +95,53 @@ static bool bnep_general(struct bnep_frame *bnep_frame,
 
 }
 
+struct bnep_control_data {
+	uint8_t type;
+	const char *str;
+};
+
+static const struct bnep_control_data bnep_control_table[] = {
+	{ 0x00, "Command Not Understood",	},
+	{ 0x01, "Setup Conn Req",		},
+	{ 0x02, "Setup Conn Rsp",		},
+	{ 0x03, "Filter NetType Set",		},
+	{ 0x04, "Filter NetType Rsp",		},
+	{ 0x05, "Filter MultAddr Set",		},
+	{ 0x06, "Filter MultAddr Rsp",		},
+	{ }
+};
+
+static bool bnep_control(struct bnep_frame *bnep_frame,
+					uint8_t indent,	int hdr_len)
+{
+	uint8_t ctype;
+	struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+	const struct bnep_control_data *bnep_control_data = NULL;
+	const char *type_str;
+	int i;
+
+	if (!l2cap_frame_get_u8(frame, &ctype))
+		return false;
+
+	for (i = 0; bnep_control_table[i].str; i++) {
+		if (bnep_control_table[i].type == ctype) {
+			bnep_control_data = &bnep_control_table[i];
+			break;
+		}
+	}
+
+	if (bnep_control_data)
+		type_str = bnep_control_data->str;
+	else
+		type_str = "Unknown control type";
+
+	print_field("%*c%s (0x%02x) ", indent, ' ', type_str, ctype);
+
+	/* TODO: Handle BNEP control types */
+
+	return true;
+}
+
 struct bnep_data {
 	uint8_t type;
 	const char *str;
@@ -103,7 +150,7 @@ struct bnep_data {
 
 static const struct bnep_data bnep_table[] = {
 	{ 0x00, "General Ethernet",		bnep_general	},
-	{ 0x01, "Control",					},
+	{ 0x01, "Control",			bnep_control	},
 	{ 0x02, "Compressed Ethernet",				},
 	{ 0x03, "Compressed Ethernet SrcOnly",			},
 	{ 0x04, "Compressed Ethernet DestOnly",			},
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/5 monitor: Add support for decoding bnep Compressed pkt

In reply to Gowtham Anandha Babu
      BNEP: Compressed Ethernet (0x02|0)
         [proto 0x0300]
        3c 3b 3a 39 38 37 36 35 34 33 32 31 30 2f 2e 2d
        2c 2b 2a 29 28 27 26 25 24 23 22 21 20 1f 1e 1d
---
 monitor/bnep.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
monitor/bnep.c +15 -1
index d417e2f..1735a7a 100644
@@ -142,6 +142,20 @@ static bool bnep_control(struct bnep_frame *bnep_frame,
 	return true;
 }
 
+static bool bnep_compressed(struct bnep_frame *bnep_frame,
+					uint8_t indent,	int hdr_len)
+{
+
+	struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+
+	if (!l2cap_frame_get_be16(frame, &proto))
+		return false;
+
+	print_field("%*c[proto 0x%04x] ", indent, ' ', proto);
+
+	return true;
+}
+
 struct bnep_data {
 	uint8_t type;
 	const char *str;
@@ -151,7 +165,7 @@ struct bnep_data {
 static const struct bnep_data bnep_table[] = {
 	{ 0x00, "General Ethernet",		bnep_general	},
 	{ 0x01, "Control",			bnep_control	},
-	{ 0x02, "Compressed Ethernet",				},
+	{ 0x02, "Compressed Ethernet",		bnep_compressed	},
 	{ 0x03, "Compressed Ethernet SrcOnly",			},
 	{ 0x04, "Compressed Ethernet DestOnly",			},
 	{ }
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/5 monitor: Add support for decoding bnep SrcOnly pkt

In reply to Gowtham Anandha Babu
      BNEP: Compressed Ethernet SrcOnly (0x03|0)
         src 00:00:00:00:00:00 [proto 0x0300]
        3c 3b 3a 39 38 37 36 35 34 33 32 31 30 2f 2e 2d
        2c 2b 2a 29 28 27 26 25 24 23 22 21 20 1f 1e 1d
---
 monitor/bnep.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
monitor/bnep.c +22 -1
index 1735a7a..5904367 100644
@@ -156,6 +156,27 @@ static bool bnep_compressed(struct bnep_frame *bnep_frame,
 	return true;
 }
 
+static bool bnep_src_only(struct bnep_frame *bnep_frame,
+					uint8_t indent,	int hdr_len)
+{
+
+	struct l2cap_frame *frame;
+	char src_addr[20];
+
+	if (!get_macaddr(bnep_frame, src_addr))
+		return false;
+
+	frame = &bnep_frame->l2cap_frame;
+
+	if (!l2cap_frame_get_be16(frame, &proto))
+		return false;
+
+	print_field("%*csrc %s [proto 0x%04x] ", indent,
+					' ', src_addr, proto);
+
+	return true;
+}
+
 struct bnep_data {
 	uint8_t type;
 	const char *str;
@@ -166,7 +187,7 @@ static const struct bnep_data bnep_table[] = {
 	{ 0x00, "General Ethernet",		bnep_general	},
 	{ 0x01, "Control",			bnep_control	},
 	{ 0x02, "Compressed Ethernet",		bnep_compressed	},
-	{ 0x03, "Compressed Ethernet SrcOnly",			},
+	{ 0x03, "Compressed Ethernet SrcOnly",	bnep_src_only	},
 	{ 0x04, "Compressed Ethernet DestOnly",			},
 	{ }
 };
Signature · 1 line
1.9.1
#5 lore raw

PATCH 5/5 monitor: Add support for decoding bnep DestOnly pkt

In reply to Gowtham Anandha Babu
      BNEP: Compressed Ethernet DestOnly (0x04|0)
         dst 00:00:00:00:00:00 [proto 0x0000]
        00 00 00 00 00 00 61 62 63 64 65 66 30 31 32 33
        34 35 36 37 38 39 5f 62 6e 65 70 5f 74 65 73 74
---
 monitor/bnep.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
monitor/bnep.c +22 -1
index 5904367..537eeba 100644
@@ -177,6 +177,27 @@ static bool bnep_src_only(struct bnep_frame *bnep_frame,
 	return true;
 }
 
+static bool bnep_dst_only(struct bnep_frame *bnep_frame,
+					uint8_t indent,	int hdr_len)
+{
+
+	struct l2cap_frame *frame;
+	char dest_addr[20];
+
+	if (!get_macaddr(bnep_frame, dest_addr))
+		return false;
+
+	frame = &bnep_frame->l2cap_frame;
+
+	if (!l2cap_frame_get_be16(frame, &proto))
+		return false;
+
+	print_field("%*cdst %s [proto 0x%04x] ", indent,
+					' ', dest_addr, proto);
+
+	return true;
+}
+
 struct bnep_data {
 	uint8_t type;
 	const char *str;
@@ -188,7 +209,7 @@ static const struct bnep_data bnep_table[] = {
 	{ 0x01, "Control",			bnep_control	},
 	{ 0x02, "Compressed Ethernet",		bnep_compressed	},
 	{ 0x03, "Compressed Ethernet SrcOnly",	bnep_src_only	},
-	{ 0x04, "Compressed Ethernet DestOnly",			},
+	{ 0x04, "Compressed Ethernet DestOnly",	bnep_dst_only	},
 	{ }
 };
 
Signature · 1 line
1.9.1
maintainer Applied
#6 lore raw
In reply to Gowtham Anandha Babu

Hi Gowtham,

Quoted 7 lines · Gowtham Anandha Babu

Gowtham Anandha Babu (5):
monitor: Add support for decoding bnep General pkt
monitor: Add support for decoding bnep Control pkt
monitor: Add support for decoding bnep Compressed pkt
monitor: Add support for decoding bnep SrcOnly pkt
monitor: Add support for decoding bnep DestOnly pkt

Quoted 5 lines
 monitor/bnep.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 169 insertions(+), 10 deletions(-)

--
1.9.1

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz