Decodes below BNEP control msg pkt:
1) Commad Not Understood Msg
2) Setup Connection Req Msg
3) Filter NetType Set Msg
4) Filter MultiAddr Set Msg
5) Common Rsp msg for above requests.
And also handles the BNEP extension header packet.
Gowtham Anandha Babu (6):
monitor: Add decoding of Cmd Not Understood pkt
monitor: Add decoding of Setup Conn Req pkt
monitor: Add decoding of Filter NetType Set pkt
monitor: Add decoding of Filter MultAddr Set pkt
monitor: Add decoding of common rsp msg pkt
monitor: Add decoding of BNEP Extension Header pkt
monitor/bnep.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 216 insertions(+), 9 deletions(-)
--
1.9.1
Hi Gowtham,
On Thu, May 7, 2015 at 1:22 PM, Gowtham Anandha Babu
<[email protected]> wrote:
> Decodes below BNEP control msg pkt:
> 1) Commad Not Understood Msg
> 2) Setup Connection Req Msg
> 3) Filter NetType Set Msg
> 4) Filter MultiAddr Set Msg
> 5) Common Rsp msg for above requests.
>
> And also handles the BNEP extension header packet.
>
> Gowtham Anandha Babu (6):
> monitor: Add decoding of Cmd Not Understood pkt
> monitor: Add decoding of Setup Conn Req pkt
> monitor: Add decoding of Filter NetType Set pkt
> monitor: Add decoding of Filter MultAddr Set pkt
> monitor: Add decoding of common rsp msg pkt
> monitor: Add decoding of BNEP Extension Header pkt
>
> monitor/bnep.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 216 insertions(+), 9 deletions(-)
>
> --
> 1.9.1
Applied, thanks.
--
Luiz Augusto von Dentz
BNEP: General Ethernet (0x00|1)
dst 00:00:00:00:00:00 src 00:00:00:00:00:00 [proto 0x0300]
Ext Control(0x00|1) len 0x0f
Filter MultAddr Set (0x05)
Length: 0x000c
03:00:00:20:00:00 - 03:00:00:20:00:00
Ext Unknown(0x7f|0) len 0x0a
ac ac ac ac ac ac ac ac ac 3c
3b 3a 39 38 37 36 35 34 33 32 31 30 2f 2e 2d 2c
---
monitor/bnep.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/monitor/bnep.c b/monitor/bnep.c
index d73a3bc..01392e8 100644
--- a/monitor/bnep.c
+++ b/monitor/bnep.c
@@ -47,6 +47,11 @@
#define GET_PKT_TYPE(type) (type & 0x7f)
#define GET_EXTENSION(type) (type & 0x80)
+/* BNEP Extension Type */
+#define BNEP_EXTENSION_CONTROL 0x00
+
+#define BNEP_CONTROL 0x01
+
uint16_t proto = 0x0000;
struct bnep_frame {
@@ -354,6 +359,43 @@ static bool bnep_dst_only(struct bnep_frame *bnep_frame,
return true;
}
+static bool bnep_eval_extension(struct bnep_frame *bnep_frame, uint8_t indent)
+{
+ struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+ uint8_t type, length;
+ int extension;
+
+ if (!l2cap_frame_get_u8(frame, &type))
+ return false;
+
+ if (!l2cap_frame_get_u8(frame, &length))
+ return false;
+
+ extension = GET_EXTENSION(type);
+ type = GET_PKT_TYPE(type);
+
+ switch (type) {
+ case BNEP_EXTENSION_CONTROL:
+ print_field("%*cExt Control(0x%02x|%s) len 0x%02x", indent,
+ ' ', type, extension ? "1" : "0", length);
+ if (!bnep_control(bnep_frame, indent+2, length))
+ return false;
+ break;
+
+ default:
+ print_field("%*cExt Unknown(0x%02x|%s) len 0x%02x", indent,
+ ' ', type, extension ? "1" : "0", length);
+ packet_hexdump(frame->data, length);
+ l2cap_frame_pull(frame, frame, length);
+ }
+
+ if (extension)
+ if (!bnep_eval_extension(bnep_frame, indent))
+ return false;
+
+ return true;
+}
+
struct bnep_data {
uint8_t type;
const char *str;
@@ -420,7 +462,16 @@ void bnep_packet(const struct l2cap_frame *frame)
if (!bnep_data->func(&bnep_frame, indent, -1))
goto fail;
- /* TODO: Handle BNEP packet with Extension Header */
+ /* Extension info */
+ if (bnep_frame.extension)
+ if (!bnep_eval_extension(&bnep_frame, indent+2))
+ goto fail;
+
+ /* Control packet => No payload info */
+ if (bnep_frame.type == BNEP_CONTROL)
+ return;
+
+ /* TODO: Handle BNEP IP packet */
packet_hexdump(l2cap_frame->data, l2cap_frame->size);
return;
--
1.9.1
BNEP: Control (0x01|0)
Setup Conn Rsp (0x02)
Rsp msg: Operation Successful(0x0000)
BNEP: Control (0x01|0)
Filter NetType Rsp (0x04)
Rsp msg: Operation Successful(0x0000)
BNEP: Control (0x01|0)
Filter MultAddr Rsp (0x06)
Rsp msg: Operation Failed - Invalid Dst Srv UUID(0x0001)
---
monitor/bnep.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/monitor/bnep.c b/monitor/bnep.c
index 15050cb..d73a3bc 100644
--- a/monitor/bnep.c
+++ b/monitor/bnep.c
@@ -158,6 +158,38 @@ static bool setup_conn_req(struct bnep_frame *bnep_frame, uint8_t indent)
return true;
}
+static const char *value2str(uint16_t value)
+{
+ switch (value) {
+ case 0x00:
+ return "Operation Successful";
+ case 0x01:
+ return "Operation Failed - Invalid Dst Srv UUID";
+ case 0x02:
+ return "Operation Failed - Invalid Src Srv UUID";
+ case 0x03:
+ return "Operation Failed - Invalid Srv UUID size";
+ case 0x04:
+ return "Operation Failed - Conn not allowed";
+ default:
+ return "Unknown";
+ }
+}
+
+static bool print_rsp_msg(struct bnep_frame *bnep_frame, uint8_t indent)
+{
+ struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+ uint16_t rsp_msg;
+
+ if (!l2cap_frame_get_be16(frame, &rsp_msg))
+ return false;
+
+ print_field("%*cRsp msg: %s(0x%04x) ", indent, ' ',
+ value2str(rsp_msg), rsp_msg);
+
+ return true;
+}
+
static bool filter_nettype_req(struct bnep_frame *bnep_frame, uint8_t indent)
{
struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
@@ -219,11 +251,11 @@ struct bnep_control_data {
static const struct bnep_control_data bnep_control_table[] = {
{ 0x00, "Command Not Understood", cmd_nt_understood },
{ 0x01, "Setup Conn Req", setup_conn_req },
- { 0x02, "Setup Conn Rsp", },
+ { 0x02, "Setup Conn Rsp", print_rsp_msg },
{ 0x03, "Filter NetType Set", filter_nettype_req },
- { 0x04, "Filter NetType Rsp", },
+ { 0x04, "Filter NetType Rsp", print_rsp_msg },
{ 0x05, "Filter MultAddr Set", filter_multaddr_req },
- { 0x06, "Filter MultAddr Rsp", },
+ { 0x06, "Filter MultAddr Rsp", print_rsp_msg },
{ }
};
--
1.9.1
BNEP: Control (0x01|0)
Command Not Understood (0x00)
Type: 0xff
---
monitor/bnep.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/monitor/bnep.c b/monitor/bnep.c
index 537eeba..2e41d5b 100644
--- a/monitor/bnep.c
+++ b/monitor/bnep.c
@@ -95,13 +95,27 @@ static bool bnep_general(struct bnep_frame *bnep_frame,
}
+static bool cmd_nt_understood(struct bnep_frame *bnep_frame, uint8_t indent)
+{
+ struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+ uint8_t ptype;
+
+ if (!l2cap_frame_get_u8(frame, &ptype))
+ return false;
+
+ print_field("%*cType: 0x%02x ", indent, ' ', ptype);
+
+ return true;
+}
+
struct bnep_control_data {
uint8_t type;
const char *str;
+ bool (*func) (struct bnep_frame *frame, uint8_t indent);
};
static const struct bnep_control_data bnep_control_table[] = {
- { 0x00, "Command Not Understood", },
+ { 0x00, "Command Not Understood", cmd_nt_understood },
{ 0x01, "Setup Conn Req", },
{ 0x02, "Setup Conn Rsp", },
{ 0x03, "Filter NetType Set", },
@@ -137,8 +151,16 @@ static bool bnep_control(struct bnep_frame *bnep_frame,
print_field("%*c%s (0x%02x) ", indent, ' ', type_str, ctype);
- /* TODO: Handle BNEP control types */
+ if (!bnep_control_data || !bnep_control_data->func) {
+ packet_hexdump(frame->data, hdr_len - 1);
+ l2cap_frame_pull(frame, frame, hdr_len - 1);
+ goto done;
+ }
+
+ if (!bnep_control_data->func(bnep_frame, indent+2))
+ return false;
+done:
return true;
}
--
1.9.1
BNEP: Control (0x01|0)
Filter NetType Set (0x03)
Length: 0x0004
0x86dd - 0x86dd
---
monitor/bnep.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/monitor/bnep.c b/monitor/bnep.c
index a5f2432..9bad2d5 100644
--- a/monitor/bnep.c
+++ b/monitor/bnep.c
@@ -158,6 +158,32 @@ static bool setup_conn_req(struct bnep_frame *bnep_frame, uint8_t indent)
return true;
}
+static bool filter_nettype_req(struct bnep_frame *bnep_frame, uint8_t indent)
+{
+ struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+ uint16_t length, start_range, end_range;
+ int i;
+
+ if (!l2cap_frame_get_be16(frame, &length))
+ return false;
+
+ print_field("%*cLength: 0x%04x", indent, ' ', length);
+
+ for (i = 0; i < length / 4; i++) {
+
+ if (!l2cap_frame_get_be16(frame, &start_range))
+ return false;
+
+ if (!l2cap_frame_get_be16(frame, &end_range))
+ return false;
+
+ print_field("%*c0x%04x - 0x%04x", indent, ' ',
+ start_range, end_range);
+ }
+
+ return true;
+}
+
struct bnep_control_data {
uint8_t type;
const char *str;
@@ -168,7 +194,7 @@ static const struct bnep_control_data bnep_control_table[] = {
{ 0x00, "Command Not Understood", cmd_nt_understood },
{ 0x01, "Setup Conn Req", setup_conn_req },
{ 0x02, "Setup Conn Rsp", },
- { 0x03, "Filter NetType Set", },
+ { 0x03, "Filter NetType Set", filter_nettype_req },
{ 0x04, "Filter NetType Rsp", },
{ 0x05, "Filter MultAddr Set", },
{ 0x06, "Filter MultAddr Rsp", },
--
1.9.1
BNEP: Control (0x01|0)
Filter MultAddr Set (0x05)
Length: 0x000c
01:00:00:00:00:00 - ff:ff:ff:ff:ff:ff
---
monitor/bnep.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/monitor/bnep.c b/monitor/bnep.c
index 9bad2d5..15050cb 100644
--- a/monitor/bnep.c
+++ b/monitor/bnep.c
@@ -184,6 +184,32 @@ static bool filter_nettype_req(struct bnep_frame *bnep_frame, uint8_t indent)
return true;
}
+static bool filter_multaddr_req(struct bnep_frame *bnep_frame, uint8_t indent)
+{
+ struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+ uint16_t length;
+ char start_addr[20], end_addr[20];
+ int i;
+
+ if (!l2cap_frame_get_be16(frame, &length))
+ return false;
+
+ print_field("%*cLength: 0x%04x", indent, ' ', length);
+
+ for (i = 0; i < length / 12; i++) {
+
+ if (!get_macaddr(bnep_frame, start_addr))
+ return false;
+
+ if (!get_macaddr(bnep_frame, end_addr))
+ return false;
+
+ print_field("%*c%s - %s", indent, ' ', start_addr, end_addr);
+ }
+
+ return true;
+}
+
struct bnep_control_data {
uint8_t type;
const char *str;
@@ -196,7 +222,7 @@ static const struct bnep_control_data bnep_control_table[] = {
{ 0x02, "Setup Conn Rsp", },
{ 0x03, "Filter NetType Set", filter_nettype_req },
{ 0x04, "Filter NetType Rsp", },
- { 0x05, "Filter MultAddr Set", },
+ { 0x05, "Filter MultAddr Set", filter_multaddr_req },
{ 0x06, "Filter MultAddr Rsp", },
{ }
};
--
1.9.1
BNEP: Control (0x01|0)
Setup Conn Req (0x01)
Size: 0x02
Dst: 0x1116(NAP)
Src: 0x1115(PANU)
---
monitor/bnep.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/monitor/bnep.c b/monitor/bnep.c
index 2e41d5b..a5f2432 100644
--- a/monitor/bnep.c
+++ b/monitor/bnep.c
@@ -108,6 +108,56 @@ static bool cmd_nt_understood(struct bnep_frame *bnep_frame, uint8_t indent)
return true;
}
+static bool setup_conn_req(struct bnep_frame *bnep_frame, uint8_t indent)
+{
+
+ struct l2cap_frame *frame = &bnep_frame->l2cap_frame;
+ uint8_t uuid_size;
+ uint32_t src_uuid = 0, dst_uuid = 0;
+
+ if (!l2cap_frame_get_u8(frame, &uuid_size))
+ return false;
+
+ print_field("%*cSize: 0x%02x ", indent, ' ', uuid_size);
+
+ switch (uuid_size) {
+ case 2:
+ if (!l2cap_frame_get_be16(frame, (uint16_t *) &dst_uuid))
+ return false;
+
+ if (!l2cap_frame_get_be16(frame, (uint16_t *) &src_uuid))
+ return false;
+ break;
+ case 4:
+ if (!l2cap_frame_get_be32(frame, &dst_uuid))
+ return false;
+
+ if (!l2cap_frame_get_be32(frame, &src_uuid))
+ return false;
+ break;
+ case 16:
+ if (!l2cap_frame_get_be32(frame, &dst_uuid))
+ return false;
+
+ l2cap_frame_pull(frame, frame, 12);
+
+ if (!l2cap_frame_get_be32(frame, &src_uuid))
+ return false;
+
+ l2cap_frame_pull(frame, frame, 12);
+ break;
+ default:
+ l2cap_frame_pull(frame, frame, (uuid_size * 2));
+ return true;
+ }
+
+ print_field("%*cDst: 0x%x(%s)", indent, ' ', dst_uuid,
+ uuid32_to_str(dst_uuid));
+ print_field("%*cSrc: 0x%x(%s)", indent, ' ', src_uuid,
+ uuid32_to_str(src_uuid));
+ return true;
+}
+
struct bnep_control_data {
uint8_t type;
const char *str;
@@ -116,7 +166,7 @@ struct bnep_control_data {
static const struct bnep_control_data bnep_control_table[] = {
{ 0x00, "Command Not Understood", cmd_nt_understood },
- { 0x01, "Setup Conn Req", },
+ { 0x01, "Setup Conn Req", setup_conn_req },
{ 0x02, "Setup Conn Rsp", },
{ 0x03, "Filter NetType Set", },
{ 0x04, "Filter NetType Rsp", },
--
1.9.1