linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Adds definitions for AMP Assoc data
@ 2012-05-08  9:44 Andrei Emeltchenko
  2012-05-08  9:44 ` [PATCH 2/2] Decode A2MP Get AMP Assoc rsp Andrei Emeltchenko
  2012-05-08 20:22 ` [PATCH 1/2] Adds definitions for AMP Assoc data Johan Hedberg
  0 siblings, 2 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2012-05-08  9:44 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Definitions are needed for decoding A2MP Assoc Rsp.
---
 lib/a2mp.h |   38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lib/a2mp.h b/lib/a2mp.h
index da937d1..ac308e7 100644
--- a/lib/a2mp.h
+++ b/lib/a2mp.h
@@ -142,6 +142,44 @@ struct a2mp_disconn_rsp {
 #define A2MP_STATUS_PHYS_LINK_EXISTS			0x05
 #define A2MP_STATUS_SECURITY_VIOLATION			0x06
 
+#define MAC_ADDR_TYPE		1
+#define PREF_CHANLIST_TYPE	2
+#define CONNECTED_CHAN		3
+#define PAL_CAP_TYPE		4
+#define PAL_VER_INFO		5
+
+struct tlv {
+	uint8_t type;
+	uint16_t len;
+	uint8_t val[0];
+} __attribute__ ((packed));
+
+struct pal_ver {
+	uint8_t ver;
+	uint16_t company_id;
+	uint16_t sub_ver;
+} __attribute__ ((packed));
+
+struct country_triplet {
+	union {
+		struct {
+			uint8_t first_channel;
+			uint8_t num_channels;
+			int8_t max_power;
+		} __attribute__ ((packed)) chans;
+		struct {
+			uint8_t reg_extension_id;
+			uint8_t reg_class;
+			uint8_t coverage_class;
+		} __attribute__ ((packed)) ext;
+	};
+} __attribute__ ((packed));
+
+struct chan_list {
+	uint8_t country_code[3];
+	struct country_triplet triplets[0];
+} __attribute__ ((packed));
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] Decode A2MP Get AMP Assoc rsp
  2012-05-08  9:44 [PATCH 1/2] Adds definitions for AMP Assoc data Andrei Emeltchenko
@ 2012-05-08  9:44 ` Andrei Emeltchenko
  2012-05-08 20:22 ` [PATCH 1/2] Adds definitions for AMP Assoc data Johan Hedberg
  1 sibling, 0 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2012-05-08  9:44 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Adds decoding Assoc data:

...
> ACL data: handle 11 flags 0x02 dlen 53
    A2MP: Get AMP Assoc rsp: id 1 status (0) Success
      Assoc data [len 39]:
        MAC: <address>
        Preferred Chan List number of triplets 4
          Country code: XXX
          Reg ext id 201 reg class 254 coverage class 0
          Channel 1 max power 20
          Channels 2 - 12 max power 20
          Channels 4 - 8 max power 0
        PAL CAP: 00 00 00 00
        PAL VER: 01 Comp ID: <id> SubVer: 0001
...
---
 parser/l2cap.c |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 91 insertions(+), 8 deletions(-)

diff --git a/parser/l2cap.c b/parser/l2cap.c
index 69383e6..8a1469b 100644
--- a/parser/l2cap.c
+++ b/parser/l2cap.c
@@ -1162,20 +1162,103 @@ static inline void a2mp_assoc_req(int level, struct frame *frm)
 	printf("Get AMP Assoc req: id %d\n", h->id);
 }
 
+static void a2mp_dump_chanlist(int level, struct tlv *tlv, char *prefix)
+{
+	struct chan_list *chan_list = (struct chan_list *) tlv->val;
+	struct country_triplet *triplet;
+	int i, num;
+
+	num = tlv->len / sizeof(*triplet);
+
+	printf("%s number of triplets %d\n", prefix, num);
+
+	p_indent(level+2, 0);
+
+	printf("Country code: %c%c%c\n", chan_list->country_code[0],
+	       chan_list->country_code[1], chan_list->country_code[2]);
+
+	for (i = 0; i < num; i++) {
+		triplet = &chan_list->triplets[i];
+
+		p_indent(level+2, 0);
+
+		if (triplet->chans.first_channel >= 201) {
+			printf("Reg ext id %d reg class %d coverage class %d\n",
+			       triplet->ext.reg_extension_id,
+			       triplet->ext.reg_class,
+			       triplet->ext.coverage_class);
+		} else {
+			if (triplet->chans.num_channels == 1)
+				printf("Channel %d max power %d\n",
+						triplet->chans.first_channel,
+						triplet->chans.max_power);
+			else
+				printf("Channels %d - %d max power %d\n",
+						triplet->chans.first_channel,
+						triplet->chans.first_channel +
+						triplet->chans.num_channels,
+						triplet->chans.max_power);
+		}
+	}
+}
+
 static inline void a2mp_assoc_dump(int level, uint8_t *assoc, uint16_t len)
 {
-	int i;
+	struct tlv *tlv;
 
 	p_indent(level, 0);
-	printf("Assoc data:");
-	for (i = 0; i < len; i++) {
-		if (!(i%16)) {
-			printf("\n");
-			p_indent(level+1, 0);
+	printf("Assoc data [len %d]:\n", len);
+
+	tlv = (struct tlv *) assoc;
+	while (len > sizeof(*tlv)) {
+		uint16_t tlvlen = btohs(tlv->len);
+		struct pal_ver *ver;
+
+		p_indent(level+1, 0);
+
+		switch (tlv->type) {
+		case MAC_ADDR_TYPE:
+			if (tlvlen != 6)
+				break;
+			printf("MAC: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
+			       tlv->val[0], tlv->val[1], tlv->val[2],
+			       tlv->val[3], tlv->val[4], tlv->val[5]);
+			break;
+
+		case PREF_CHANLIST_TYPE:
+			a2mp_dump_chanlist(level, tlv, "Preferred Chan List");
+			break;
+
+		case CONNECTED_CHAN:
+			a2mp_dump_chanlist(level, tlv, "Connected Chan List");
+			break;
+
+		case PAL_CAP_TYPE:
+			if (tlvlen != 4)
+				break;
+			printf("PAL CAP: %2.2x %2.2x %2.2x %2.2x\n",
+			       tlv->val[0], tlv->val[1], tlv->val[2],
+			       tlv->val[3]);
+			break;
+
+		case PAL_VER_INFO:
+			if (tlvlen != 5)
+				break;
+			ver = (struct pal_ver *) tlv->val;
+			printf("PAL VER: %2.2x Comp ID: %4.4x SubVer: %4.4x\n",
+			       ver->ver, btohs(ver->company_id),
+			       btohs(ver->sub_ver));
+			break;
+
+		default:
+			printf("Unrecognized type %d\n", tlv->type);
+			break;
 		}
-		printf("%2.2x ",*assoc++);
+
+		len -= tlvlen + sizeof(*tlv);
+		assoc += tlvlen + sizeof(*tlv);
+		tlv = (struct tlv *) assoc;
 	}
-	printf("\n");
 }
 
 static inline void a2mp_assoc_rsp(int level, struct frame *frm, uint16_t len)
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/2] Adds definitions for AMP Assoc data
  2012-05-08  9:44 [PATCH 1/2] Adds definitions for AMP Assoc data Andrei Emeltchenko
  2012-05-08  9:44 ` [PATCH 2/2] Decode A2MP Get AMP Assoc rsp Andrei Emeltchenko
@ 2012-05-08 20:22 ` Johan Hedberg
  2012-05-10  8:08   ` [hcidump PATCHv2 " Andrei Emeltchenko
  1 sibling, 1 reply; 9+ messages in thread
From: Johan Hedberg @ 2012-05-08 20:22 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

On Tue, May 08, 2012, Andrei Emeltchenko wrote:
>  #define A2MP_STATUS_PHYS_LINK_EXISTS			0x05
>  #define A2MP_STATUS_SECURITY_VIOLATION			0x06
>  
> +#define MAC_ADDR_TYPE		1
> +#define PREF_CHANLIST_TYPE	2
> +#define CONNECTED_CHAN		3
> +#define PAL_CAP_TYPE		4
> +#define PAL_VER_INFO		5
> +
> +struct tlv {
> +	uint8_t type;
> +	uint16_t len;
> +	uint8_t val[0];
> +} __attribute__ ((packed));
> +
> +struct pal_ver {
> +	uint8_t ver;
> +	uint16_t company_id;
> +	uint16_t sub_ver;
> +} __attribute__ ((packed));
> +
> +struct country_triplet {
> +	union {
> +		struct {
> +			uint8_t first_channel;
> +			uint8_t num_channels;
> +			int8_t max_power;
> +		} __attribute__ ((packed)) chans;
> +		struct {
> +			uint8_t reg_extension_id;
> +			uint8_t reg_class;
> +			uint8_t coverage_class;
> +		} __attribute__ ((packed)) ext;
> +	};
> +} __attribute__ ((packed));
> +
> +struct chan_list {
> +	uint8_t country_code[3];
> +	struct country_triplet triplets[0];
> +} __attribute__ ((packed));

Everything in this file is name-spaced with A2MP_ or a2mp_. Please
follow that convention.

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [hcidump PATCHv2 1/2] Adds definitions for AMP Assoc data
  2012-05-08 20:22 ` [PATCH 1/2] Adds definitions for AMP Assoc data Johan Hedberg
@ 2012-05-10  8:08   ` Andrei Emeltchenko
  2012-05-10  8:08     ` [hcidump PATCHv2 2/2] Decode A2MP Get AMP Assoc rsp Andrei Emeltchenko
  2012-05-16  8:10     ` [hcidump PATCHv2 1/2] Adds definitions for AMP Assoc data Johan Hedberg
  0 siblings, 2 replies; 9+ messages in thread
From: Andrei Emeltchenko @ 2012-05-10  8:08 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Definitions are needed for decoding A2MP Assoc Rsp.
---
 lib/a2mp.h |   38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lib/a2mp.h b/lib/a2mp.h
index da937d1..61f1c1e 100644
--- a/lib/a2mp.h
+++ b/lib/a2mp.h
@@ -142,6 +142,44 @@ struct a2mp_disconn_rsp {
 #define A2MP_STATUS_PHYS_LINK_EXISTS			0x05
 #define A2MP_STATUS_SECURITY_VIOLATION			0x06
 
+#define A2MP_MAC_ADDR_TYPE		1
+#define A2MP_PREF_CHANLIST_TYPE		2
+#define A2MP_CONNECTED_CHAN		3
+#define A2MP_PAL_CAP_TYPE		4
+#define A2MP_PAL_VER_INFO		5
+
+struct a2mp_tlv {
+	uint8_t type;
+	uint16_t len;
+	uint8_t val[0];
+} __attribute__ ((packed));
+
+struct a2mp_pal_ver {
+	uint8_t ver;
+	uint16_t company_id;
+	uint16_t sub_ver;
+} __attribute__ ((packed));
+
+struct a2mp_country_triplet {
+	union {
+		struct {
+			uint8_t first_channel;
+			uint8_t num_channels;
+			int8_t max_power;
+		} __attribute__ ((packed)) chans;
+		struct {
+			uint8_t reg_extension_id;
+			uint8_t reg_class;
+			uint8_t coverage_class;
+		} __attribute__ ((packed)) ext;
+	};
+} __attribute__ ((packed));
+
+struct a2mp_chan_list {
+	uint8_t country_code[3];
+	struct a2mp_country_triplet triplets[0];
+} __attribute__ ((packed));
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [hcidump PATCHv2 2/2] Decode A2MP Get AMP Assoc rsp
  2012-05-10  8:08   ` [hcidump PATCHv2 " Andrei Emeltchenko
@ 2012-05-10  8:08     ` Andrei Emeltchenko
  2012-05-16  8:12       ` Johan Hedberg
  2012-05-16  8:10     ` [hcidump PATCHv2 1/2] Adds definitions for AMP Assoc data Johan Hedberg
  1 sibling, 1 reply; 9+ messages in thread
From: Andrei Emeltchenko @ 2012-05-10  8:08 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Adds decoding Assoc data:

...
> ACL data: handle 11 flags 0x02 dlen 53
    A2MP: Get AMP Assoc rsp: id 1 status (0) Success
      Assoc data [len 39]:
        MAC: <address>
        Preferred Chan List number of triplets 4
          Country code: XXX
          Reg ext id 201 reg class 254 coverage class 0
          Channel 1 max power 20
          Channels 2 - 12 max power 20
          Channels 4 - 8 max power 0
        PAL CAP: 00 00 00 00
        PAL VER: 01 Comp ID: <id> SubVer: 0001
...
---
 parser/l2cap.c |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 91 insertions(+), 8 deletions(-)

diff --git a/parser/l2cap.c b/parser/l2cap.c
index 69383e6..b6a7c57 100644
--- a/parser/l2cap.c
+++ b/parser/l2cap.c
@@ -1162,20 +1162,103 @@ static inline void a2mp_assoc_req(int level, struct frame *frm)
 	printf("Get AMP Assoc req: id %d\n", h->id);
 }
 
+static void a2mp_dump_chanlist(int level, struct a2mp_tlv *tlv, char *prefix)
+{
+	struct a2mp_chan_list *chan_list = (struct a2mp_chan_list *) tlv->val;
+	struct a2mp_country_triplet *triplet;
+	int i, num;
+
+	num = tlv->len / sizeof(*triplet);
+
+	printf("%s number of triplets %d\n", prefix, num);
+
+	p_indent(level+2, 0);
+
+	printf("Country code: %c%c%c\n", chan_list->country_code[0],
+	       chan_list->country_code[1], chan_list->country_code[2]);
+
+	for (i = 0; i < num; i++) {
+		triplet = &chan_list->triplets[i];
+
+		p_indent(level+2, 0);
+
+		if (triplet->chans.first_channel >= 201) {
+			printf("Reg ext id %d reg class %d coverage class %d\n",
+			       triplet->ext.reg_extension_id,
+			       triplet->ext.reg_class,
+			       triplet->ext.coverage_class);
+		} else {
+			if (triplet->chans.num_channels == 1)
+				printf("Channel %d max power %d\n",
+						triplet->chans.first_channel,
+						triplet->chans.max_power);
+			else
+				printf("Channels %d - %d max power %d\n",
+						triplet->chans.first_channel,
+						triplet->chans.first_channel +
+						triplet->chans.num_channels,
+						triplet->chans.max_power);
+		}
+	}
+}
+
 static inline void a2mp_assoc_dump(int level, uint8_t *assoc, uint16_t len)
 {
-	int i;
+	struct a2mp_tlv *tlv;
 
 	p_indent(level, 0);
-	printf("Assoc data:");
-	for (i = 0; i < len; i++) {
-		if (!(i%16)) {
-			printf("\n");
-			p_indent(level+1, 0);
+	printf("Assoc data [len %d]:\n", len);
+
+	tlv = (struct a2mp_tlv *) assoc;
+	while (len > sizeof(*tlv)) {
+		uint16_t tlvlen = btohs(tlv->len);
+		struct a2mp_pal_ver *ver;
+
+		p_indent(level+1, 0);
+
+		switch (tlv->type) {
+		case A2MP_MAC_ADDR_TYPE:
+			if (tlvlen != 6)
+				break;
+			printf("MAC: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
+			       tlv->val[0], tlv->val[1], tlv->val[2],
+			       tlv->val[3], tlv->val[4], tlv->val[5]);
+			break;
+
+		case A2MP_PREF_CHANLIST_TYPE:
+			a2mp_dump_chanlist(level, tlv, "Preferred Chan List");
+			break;
+
+		case A2MP_CONNECTED_CHAN:
+			a2mp_dump_chanlist(level, tlv, "Connected Chan List");
+			break;
+
+		case A2MP_PAL_CAP_TYPE:
+			if (tlvlen != 4)
+				break;
+			printf("PAL CAP: %2.2x %2.2x %2.2x %2.2x\n",
+			       tlv->val[0], tlv->val[1], tlv->val[2],
+			       tlv->val[3]);
+			break;
+
+		case A2MP_PAL_VER_INFO:
+			if (tlvlen != 5)
+				break;
+			ver = (struct a2mp_pal_ver *) tlv->val;
+			printf("PAL VER: %2.2x Comp ID: %4.4x SubVer: %4.4x\n",
+			       ver->ver, btohs(ver->company_id),
+			       btohs(ver->sub_ver));
+			break;
+
+		default:
+			printf("Unrecognized type %d\n", tlv->type);
+			break;
 		}
-		printf("%2.2x ",*assoc++);
+
+		len -= tlvlen + sizeof(*tlv);
+		assoc += tlvlen + sizeof(*tlv);
+		tlv = (struct a2mp_tlv *) assoc;
 	}
-	printf("\n");
 }
 
 static inline void a2mp_assoc_rsp(int level, struct frame *frm, uint16_t len)
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [hcidump PATCHv2 1/2] Adds definitions for AMP Assoc data
  2012-05-10  8:08   ` [hcidump PATCHv2 " Andrei Emeltchenko
  2012-05-10  8:08     ` [hcidump PATCHv2 2/2] Decode A2MP Get AMP Assoc rsp Andrei Emeltchenko
@ 2012-05-16  8:10     ` Johan Hedberg
  1 sibling, 0 replies; 9+ messages in thread
From: Johan Hedberg @ 2012-05-16  8:10 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

On Thu, May 10, 2012, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Definitions are needed for decoding A2MP Assoc Rsp.
> ---
>  lib/a2mp.h |   38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)

I've applied this to both bluez.git and bluez-hcidump.git, but the
second patch had some issues (replying to it in a minute).

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [hcidump PATCHv2 2/2] Decode A2MP Get AMP Assoc rsp
  2012-05-10  8:08     ` [hcidump PATCHv2 2/2] Decode A2MP Get AMP Assoc rsp Andrei Emeltchenko
@ 2012-05-16  8:12       ` Johan Hedberg
  2012-05-16  8:26         ` [PATCH] " Andrei Emeltchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Johan Hedberg @ 2012-05-16  8:12 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

On Thu, May 10, 2012, Andrei Emeltchenko wrote:
> +	printf("Country code: %c%c%c\n", chan_list->country_code[0],
> +	       chan_list->country_code[1], chan_list->country_code[2]);

We still use tabs-only indentation in user space. The above line is
violating this.

> +			printf("Reg ext id %d reg class %d coverage class %d\n",
> +			       triplet->ext.reg_extension_id,
> +			       triplet->ext.reg_class,
> +			       triplet->ext.coverage_class);

Same here.

> +			if (triplet->chans.num_channels == 1)
> +			printf("MAC: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
> +			       tlv->val[0], tlv->val[1], tlv->val[2],
> +			       tlv->val[3], tlv->val[4], tlv->val[5]);

And here. Btw, it also looks like the printf is incorrectly indented
(same indentation as the if).

> +			printf("PAL CAP: %2.2x %2.2x %2.2x %2.2x\n",
> +			       tlv->val[0], tlv->val[1], tlv->val[2],
> +			       tlv->val[3]);

Tabs + spaces here again.

> +			printf("PAL VER: %2.2x Comp ID: %4.4x SubVer: %4.4x\n",
> +			       ver->ver, btohs(ver->company_id),
> +			       btohs(ver->sub_ver));

And here.

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] Decode A2MP Get AMP Assoc rsp
  2012-05-16  8:12       ` Johan Hedberg
@ 2012-05-16  8:26         ` Andrei Emeltchenko
  2012-05-16  8:30           ` Johan Hedberg
  0 siblings, 1 reply; 9+ messages in thread
From: Andrei Emeltchenko @ 2012-05-16  8:26 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Adds decoding Assoc data:

...
> ACL data: handle 11 flags 0x02 dlen 53
    A2MP: Get AMP Assoc rsp: id 1 status (0) Success
      Assoc data [len 39]:
        MAC: <address>
        Preferred Chan List number of triplets 4
          Country code: XXX
          Reg ext id 201 reg class 254 coverage class 0
          Channel 1 max power 20
          Channels 2 - 12 max power 20
          Channels 4 - 8 max power 0
        PAL CAP: 00 00 00 00
        PAL VER: 01 Comp ID: <id> SubVer: 0001
...
---
 parser/l2cap.c |  101 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 92 insertions(+), 9 deletions(-)

diff --git a/parser/l2cap.c b/parser/l2cap.c
index 69383e6..c6bc7ff 100644
--- a/parser/l2cap.c
+++ b/parser/l2cap.c
@@ -1162,20 +1162,103 @@ static inline void a2mp_assoc_req(int level, struct frame *frm)
 	printf("Get AMP Assoc req: id %d\n", h->id);
 }
 
+static void a2mp_dump_chanlist(int level, struct a2mp_tlv *tlv, char *prefix)
+{
+	struct a2mp_chan_list *chan_list = (struct a2mp_chan_list *) tlv->val;
+	struct a2mp_country_triplet *triplet;
+	int i, num;
+
+	num = tlv->len / sizeof(*triplet);
+
+	printf("%s number of triplets %d\n", prefix, num);
+
+	p_indent(level+2, 0);
+
+	printf("Country code: %c%c%c\n", chan_list->country_code[0],
+			chan_list->country_code[1], chan_list->country_code[2]);
+
+	for (i = 0; i < num; i++) {
+		triplet = &chan_list->triplets[i];
+
+		p_indent(level+2, 0);
+
+		if (triplet->chans.first_channel >= 201) {
+			printf("Reg ext id %d reg class %d coverage class %d\n",
+						triplet->ext.reg_extension_id,
+						triplet->ext.reg_class,
+						triplet->ext.coverage_class);
+		} else {
+			if (triplet->chans.num_channels == 1)
+				printf("Channel %d max power %d\n",
+						triplet->chans.first_channel,
+						triplet->chans.max_power);
+			else
+				printf("Channels %d - %d max power %d\n",
+						triplet->chans.first_channel,
+						triplet->chans.first_channel +
+						triplet->chans.num_channels,
+						triplet->chans.max_power);
+		}
+	}
+}
+
 static inline void a2mp_assoc_dump(int level, uint8_t *assoc, uint16_t len)
 {
-	int i;
+	struct a2mp_tlv *tlv;
 
 	p_indent(level, 0);
-	printf("Assoc data:");
-	for (i = 0; i < len; i++) {
-		if (!(i%16)) {
-			printf("\n");
-			p_indent(level+1, 0);
+	printf("Assoc data [len %d]:\n", len);
+
+	tlv = (struct a2mp_tlv *) assoc;
+	while (len > sizeof(*tlv)) {
+		uint16_t tlvlen = btohs(tlv->len);
+		struct a2mp_pal_ver *ver;
+
+		p_indent(level+1, 0);
+
+		switch (tlv->type) {
+		case A2MP_MAC_ADDR_TYPE:
+			if (tlvlen != 6)
+				break;
+			printf("MAC: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
+					tlv->val[0], tlv->val[1], tlv->val[2],
+					tlv->val[3], tlv->val[4], tlv->val[5]);
+			break;
+
+		case A2MP_PREF_CHANLIST_TYPE:
+			a2mp_dump_chanlist(level, tlv, "Preferred Chan List");
+			break;
+
+		case A2MP_CONNECTED_CHAN:
+			a2mp_dump_chanlist(level, tlv, "Connected Chan List");
+			break;
+
+		case A2MP_PAL_CAP_TYPE:
+			if (tlvlen != 4)
+				break;
+			printf("PAL CAP: %2.2x %2.2x %2.2x %2.2x\n",
+					tlv->val[0], tlv->val[1], tlv->val[2],
+					tlv->val[3]);
+			break;
+
+		case A2MP_PAL_VER_INFO:
+			if (tlvlen != 5)
+				break;
+			ver = (struct a2mp_pal_ver *) tlv->val;
+			printf("PAL VER: %2.2x Comp ID: %4.4x SubVer: %4.4x\n",
+					ver->ver, btohs(ver->company_id),
+					btohs(ver->sub_ver));
+			break;
+
+		default:
+			printf("Unrecognized type %d\n", tlv->type);
+			break;
 		}
-		printf("%2.2x ",*assoc++);
+
+		len -= tlvlen + sizeof(*tlv);
+		assoc += tlvlen + sizeof(*tlv);
+		tlv = (struct a2mp_tlv *) assoc;
 	}
-	printf("\n");
 }
 
 static inline void a2mp_assoc_rsp(int level, struct frame *frm, uint16_t len)
@@ -1183,7 +1266,7 @@ static inline void a2mp_assoc_rsp(int level, struct frame *frm, uint16_t len)
 	struct a2mp_assoc_rsp *h = frm->ptr;
 
 	printf("Get AMP Assoc rsp: id %d status (%d) %s \n",
-		   h->id, h->status, a2mpstatus2str(h->status));
+			h->id, h->status, a2mpstatus2str(h->status));
 	a2mp_assoc_dump(level + 1, (uint8_t *) &h->assoc_data, len - 2);
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Decode A2MP Get AMP Assoc rsp
  2012-05-16  8:26         ` [PATCH] " Andrei Emeltchenko
@ 2012-05-16  8:30           ` Johan Hedberg
  0 siblings, 0 replies; 9+ messages in thread
From: Johan Hedberg @ 2012-05-16  8:30 UTC (permalink / raw)
  To: Andrei Emeltchenko; +Cc: linux-bluetooth

Hi Andrei,

On Wed, May 16, 2012, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> 
> Adds decoding Assoc data:
> 
> ...
> > ACL data: handle 11 flags 0x02 dlen 53
>     A2MP: Get AMP Assoc rsp: id 1 status (0) Success
>       Assoc data [len 39]:
>         MAC: <address>
>         Preferred Chan List number of triplets 4
>           Country code: XXX
>           Reg ext id 201 reg class 254 coverage class 0
>           Channel 1 max power 20
>           Channels 2 - 12 max power 20
>           Channels 4 - 8 max power 0
>         PAL CAP: 00 00 00 00
>         PAL VER: 01 Comp ID: <id> SubVer: 0001
> ...
> ---
>  parser/l2cap.c |  101 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 92 insertions(+), 9 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-05-16  8:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-08  9:44 [PATCH 1/2] Adds definitions for AMP Assoc data Andrei Emeltchenko
2012-05-08  9:44 ` [PATCH 2/2] Decode A2MP Get AMP Assoc rsp Andrei Emeltchenko
2012-05-08 20:22 ` [PATCH 1/2] Adds definitions for AMP Assoc data Johan Hedberg
2012-05-10  8:08   ` [hcidump PATCHv2 " Andrei Emeltchenko
2012-05-10  8:08     ` [hcidump PATCHv2 2/2] Decode A2MP Get AMP Assoc rsp Andrei Emeltchenko
2012-05-16  8:12       ` Johan Hedberg
2012-05-16  8:26         ` [PATCH] " Andrei Emeltchenko
2012-05-16  8:30           ` Johan Hedberg
2012-05-16  8:10     ` [hcidump PATCHv2 1/2] Adds definitions for AMP Assoc data Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).