Add parsing for AVRCP GetCapabilities
Luiz Augusto von Dentz
maintainerPATCH v2 2/2 Add parsing for AVRCP GetCapabilities
From: Luiz Augusto von Dentz <[email protected]>
--- parser/avrcp.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 123 insertions(+), 1 deletions(-)
parser/avrcp.c +123 -1
@@ -111,6 +111,21 @@#define AVRCP_SEARCH 0x80#define AVRCP_ADD_TO_NOW_PLAYING 0x90 +/* notification events */ +#define AVRCP_EVENT_PLAYBACK_STATUS_CHANGED 0x01 +#define AVRCP_EVENT_TRACK_CHANGED 0x02 +#define AVRCP_EVENT_TRACK_REACHED_END 0x03 +#define AVRCP_EVENT_TRACK_REACHED_START 0x04 +#define AVRCP_EVENT_PLAYBACK_POS_CHANGED 0x05 +#define AVRCP_EVENT_BATT_STATUS_CHANGED 0x06 +#define AVRCP_EVENT_SYSTEM_STATUS_CHANGED 0x07 +#define AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED 0x08 +#define AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED 0x09 +#define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED 0x0a +#define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED 0x0b +#define AVRCP_EVENT_UIDS_CHANGED 0x0c +#define AVRCP_EVENT_VOLUME_CHANGED 0x0d +static const char *ctype2str (uint8_t ctype) {switch (ctype &0x0f ) {
@@ -213,6 +228,105 @@ static const char *pdu2str(uint8_t pduid) } } +static char *cap2str (uint8_t cap) +{ +switch (cap) { +case 0x2 : +return "CompanyID" ; +case 0x3 : +return "EventsID" ; +default : +return "Unknown" ; + } +} + +static char *event2str (uint8_t event) +{ +switch (event) { +case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED : +return "EVENT_PLAYBACK_STATUS_CHANGED" ; +case AVRCP_EVENT_TRACK_CHANGED : +return "EVENT_TRACK_CHANGED" ; +case AVRCP_EVENT_TRACK_REACHED_END : +return "EVENT_TRACK_REACHED_END" ; +case AVRCP_EVENT_TRACK_REACHED_START : +return "EVENT_TRACK_REACHED_START" ; +case AVRCP_EVENT_PLAYBACK_POS_CHANGED : +return "EVENT_PLAYBACK_POS_CHANGED" ; +case AVRCP_EVENT_BATT_STATUS_CHANGED : +return "EVENT_BATT_STATUS_CHANGED" ; +case AVRCP_EVENT_SYSTEM_STATUS_CHANGED : +return "EVENT_SYSTEM_STATUS_CHANGED" ; +case AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED : +return "EVENT_PLAYER_APPLICATION_SETTING_CHANGED" ; +case AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED : +return "EVENT_NOW_PLAYING_CONTENT_CHANGED" ; +case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED : +return "EVENT_AVAILABLE_PLAYERS_CHANGED" ; +case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED : +return "EVENT_ADDRESSED_PLAYER_CHANGED" ; +case AVRCP_EVENT_UIDS_CHANGED : +return "EVENT_UIDS_CHANGED" ; +case AVRCP_EVENT_VOLUME_CHANGED : +return "EVENT_VOLUME_CHANGED" ; +default : +return "Reserved" ; + } +} + +static void avrcp_get_capabilities_dump (int level,struct frame *frm,uint16_t len) +{ +uint8_t cap; +uint8_t count; + +p_indent (level, frm); + +if (len <1 ) { +printf ("PDU Malformed\n" ); +raw_dump (level, frm); +return ; + } + + cap =get_u8 (frm); +printf ("CapabilityID: 0x%02x (%s)\n" , cap,cap2str (cap)); + +if (len ==1 ) +return ; + +p_indent (level, frm); + + count =get_u8 (frm); +printf ("CapabilityCount: 0x%02x\n" , count); + +switch (cap) { +case 0x2 : +for (; count >0 ; count--) { +int i; + +p_indent (level, frm); + +printf ("%s: 0x" ,cap2str (cap)); +for (i =0 ; i <3 ; i++) +printf ("%02x" ,get_u8 (frm)); +printf ("\n" ); + } +break ; +case 0x3 : +for (; count >0 ; count--) { +uint8_t event; + +p_indent (level, frm); + + event =get_u8 (frm); +printf ("%s: 0x%02x (%s)\n" ,cap2str (cap), event, +event2str (event)); + } +break ; +default : +raw_dump (level, frm); + } +} +static void avrcp_pdu_dump (int level,struct frame *frm,uint8_t ctype) {uint8_t pduid, pt;
@@ -229,9 +343,17 @@ static void avrcp_pdu_dump(int level, struct frame *frm, uint8_t ctype)if (len != frm->len) {p_indent (level, frm);printf ("PDU Malformed\n" ); +raw_dump (level, frm); +return ; } -raw_dump (level, frm); +switch (pduid) { +case AVRCP_GET_CAPABILITIES : +avrcp_get_capabilities_dump (level +1 , frm, len); +break ; +default : +raw_dump (level, frm); + } }static char *op2str (uint8_t op)
Signature · 1 line
1.7.6
Quoted 106 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
---
parser/avrcp.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-1 files changed, 123 insertions(+), 1 deletions(-)parser/avrcp.c +85
-0@@ -111,6 +111,21 @@ #define AVRCP_SEARCH 0x80 #define AVRCP_ADD_TO_NOW_PLAYING 0x90 +/* notification events */ +#define AVRCP_EVENT_PLAYBACK_STATUS_CHANGED 0x01 +#define AVRCP_EVENT_TRACK_CHANGED 0x02 +#define AVRCP_EVENT_TRACK_REACHED_END 0x03 +#define AVRCP_EVENT_TRACK_REACHED_START 0x04 +#define AVRCP_EVENT_PLAYBACK_POS_CHANGED 0x05 +#define AVRCP_EVENT_BATT_STATUS_CHANGED 0x06 +#define AVRCP_EVENT_SYSTEM_STATUS_CHANGED 0x07 +#define AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED 0x08 +#define AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED 0x09 +#define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED 0x0a +#define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED 0x0b +#define AVRCP_EVENT_UIDS_CHANGED 0x0c +#define AVRCP_EVENT_VOLUME_CHANGED 0x0d + static const char *ctype2str(uint8_t ctype) { switch (ctype & 0x0f) {@@ -213,6 +228,105 @@ static const char *pdu2str(uint8_t pduid) } } +static char *cap2str (uint8_t cap) +{ + switch (cap) { + case 0x2: + return "CompanyID"; + case 0x3: + return "EventsID"; + default: + return "Unknown"; + } +} + +static char *event2str (uint8_t event) +{ + switch (event) { + case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED: + return "EVENT_PLAYBACK_STATUS_CHANGED"; + case AVRCP_EVENT_TRACK_CHANGED: + return "EVENT_TRACK_CHANGED"; + case AVRCP_EVENT_TRACK_REACHED_END: + return "EVENT_TRACK_REACHED_END"; + case AVRCP_EVENT_TRACK_REACHED_START: + return "EVENT_TRACK_REACHED_START"; + case AVRCP_EVENT_PLAYBACK_POS_CHANGED: + return "EVENT_PLAYBACK_POS_CHANGED"; + case AVRCP_EVENT_BATT_STATUS_CHANGED: + return "EVENT_BATT_STATUS_CHANGED"; + case AVRCP_EVENT_SYSTEM_STATUS_CHANGED: + return "EVENT_SYSTEM_STATUS_CHANGED"; + case AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED: + return "EVENT_PLAYER_APPLICATION_SETTING_CHANGED"; + case AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED: + return "EVENT_NOW_PLAYING_CONTENT_CHANGED"; + case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED: + return "EVENT_AVAILABLE_PLAYERS_CHANGED"; + case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED: + return "EVENT_ADDRESSED_PLAYER_CHANGED"; + case AVRCP_EVENT_UIDS_CHANGED: + return "EVENT_UIDS_CHANGED"; + case AVRCP_EVENT_VOLUME_CHANGED: + return "EVENT_VOLUME_CHANGED"; + default: + return "Reserved"; + } +} + +static void avrcp_get_capabilities_dump (int level,struct frame *frm,uint16_t len) +{ + uint8_t cap; + uint8_t count; + + p_indent(level, frm); + + if (len < 1) { + printf("PDU Malformed\n"); + raw_dump(level, frm); + return; + } + + cap = get_u8(frm); + printf("CapabilityID: 0x%02x (%s)\n", cap, cap2str(cap)); + + if (len == 1) + return; + + p_indent(level, frm); + + count = get_u8(frm); + printf("CapabilityCount: 0x%02x\n", count); +
parser/avrcp.c static const char *pdu2str(uint8_t pduid) · line 310
Quoted 10 lines
parser/avrcp.c +10
-0+ switch (cap) { + case 0x2: + for (; count > 0; count--) { + int i; + + p_indent(level, frm); + + printf("%s: 0x", cap2str(cap)); + for (i = 0; i < 3; i++) + printf("%02x", get_u8(frm));
Humn... I think this is not what you want. Since this information is always in big endian order, you may need to convert it to host architecture in order to see meaningful numbers. E.g.: if you do like you're doing, when receiving a packet with COMPANY_ID == IEEE_BTSIG, the information printed will be 0x581900 instead of the expected 0x001958.
Lucas De Marchi
Luiz Augusto von Dentz
maintainerHi Lucas,
Quoted 117 lines · Lucas De Marchi
Quoted 115 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
---
parser/avrcp.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-1 files changed, 123 insertions(+), 1 deletions(-)parser/avrcp.c +94
-0@@ -111,6 +111,21 @@ #define AVRCP_SEARCH 0x80 #define AVRCP_ADD_TO_NOW_PLAYING 0x90 +/* notification events */ +#define AVRCP_EVENT_PLAYBACK_STATUS_CHANGED 0x01 +#define AVRCP_EVENT_TRACK_CHANGED 0x02 +#define AVRCP_EVENT_TRACK_REACHED_END 0x03 +#define AVRCP_EVENT_TRACK_REACHED_START 0x04 +#define AVRCP_EVENT_PLAYBACK_POS_CHANGED 0x05 +#define AVRCP_EVENT_BATT_STATUS_CHANGED 0x06 +#define AVRCP_EVENT_SYSTEM_STATUS_CHANGED 0x07 +#define AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED 0x08 +#define AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED 0x09 +#define AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED 0x0a +#define AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED 0x0b +#define AVRCP_EVENT_UIDS_CHANGED 0x0c +#define AVRCP_EVENT_VOLUME_CHANGED 0x0d + static const char *ctype2str(uint8_t ctype) { switch (ctype & 0x0f) {@@ -213,6 +228,105 @@ static const char *pdu2str(uint8_t pduid) } } +static char *cap2str (uint8_t cap) +{ + switch (cap) { + case 0x2: + return "CompanyID"; + case 0x3: + return "EventsID"; + default: + return "Unknown"; + } +} + +static char *event2str (uint8_t event) +{ + switch (event) { + case AVRCP_EVENT_PLAYBACK_STATUS_CHANGED: + return "EVENT_PLAYBACK_STATUS_CHANGED"; + case AVRCP_EVENT_TRACK_CHANGED: + return "EVENT_TRACK_CHANGED"; + case AVRCP_EVENT_TRACK_REACHED_END: + return "EVENT_TRACK_REACHED_END"; + case AVRCP_EVENT_TRACK_REACHED_START: + return "EVENT_TRACK_REACHED_START"; + case AVRCP_EVENT_PLAYBACK_POS_CHANGED: + return "EVENT_PLAYBACK_POS_CHANGED"; + case AVRCP_EVENT_BATT_STATUS_CHANGED: + return "EVENT_BATT_STATUS_CHANGED"; + case AVRCP_EVENT_SYSTEM_STATUS_CHANGED: + return "EVENT_SYSTEM_STATUS_CHANGED"; + case AVRCP_EVENT_PLAYER_APPLICATION_SETTING_CHANGED: + return "EVENT_PLAYER_APPLICATION_SETTING_CHANGED"; + case AVRCP_EVENT_NOW_PLAYING_CONTENT_CHANGED: + return "EVENT_NOW_PLAYING_CONTENT_CHANGED"; + case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED: + return "EVENT_AVAILABLE_PLAYERS_CHANGED"; + case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED: + return "EVENT_ADDRESSED_PLAYER_CHANGED"; + case AVRCP_EVENT_UIDS_CHANGED: + return "EVENT_UIDS_CHANGED"; + case AVRCP_EVENT_VOLUME_CHANGED: + return "EVENT_VOLUME_CHANGED"; + default: + return "Reserved"; + } +} + +static void avrcp_get_capabilities_dump (int level,struct frame *frm,uint16_t len) +{ + uint8_t cap; + uint8_t count; + + p_indent(level, frm); + + if (len < 1) { + printf("PDU Malformed\n"); + raw_dump(level, frm); + return; + } + + cap = get_u8(frm); + printf("CapabilityID: 0x%02x (%s)\n", cap, cap2str(cap)); + + if (len == 1) + return; + + p_indent(level, frm); + + count = get_u8(frm); + printf("CapabilityCount: 0x%02x\n", count); + + switch (cap) { + case 0x2: + for (; count > 0; count--) { + int i; + + p_indent(level, frm); + + printf("%s: 0x", cap2str(cap)); + for (i = 0; i < 3; i++)
Quoted 8 lines
parser/avrcp.c static const char *pdu2str(uint8_t pduid) · line 310
Quoted 1 line
parser/avrcp.c +1
-0+ printf("%02x", get_u8(frm));Humn... I think this is not what you want. Since this information is always in big endian order, you may need to convert it to host architecture in order to see meaningful numbers. E.g.: if you do like you're doing, when receiving a packet with
COMPANY_ID==IEEE_BTSIG, the information printed will be0x581900instead of the expected0x001958.
It works just fine, we are printing byte by byte as it comes e.g. sony mw600:
Quoted 1 line
AVCTP: Command : pt
0x00transaction 5 pid0x110e
AV/C: Status: address 0x48 opcode 0x00
Subunit: Panel
Opcode: Vendor Dependent
Company ID: 0x001958
AVRCP: GetCapabilities: pt 0x00 len 0x0001
CapabilityID: 0x02 (CompanyID)Signature · 1 line
Luiz Augusto von Dentz
Hi, Luiz
Quoted 13 lines · Luiz Augusto von Dentz
Quoted 10 lines
Quoted 3 lines
+
printf("%s: 0x", cap2str(cap));
+ for (i = 0; i < 3; i++)
+printf("%02x", get_u8(frm));Humn... I think this is not what you want. Since this information is always in big endian order, you may need to convert it to host architecture in order to see meaningful numbers. E.g.: if you do like you're doing, when receiving a packet with
COMPANY_ID==IEEE_BTSIG, the information printed will be0x581900instead of the expected0x001958.It works just fine, we are printing byte by byte as it comes e.g. sony mw600:
Quoted 7 lines
Quoted 1 line
AVCTP: Command : pt
0x00transaction 5 pid0x110eAV/C: Status: address
0x48opcode0x00
Subunit: Panel
Opcode: Vendor Dependent
Company ID:0x001958
AVRCP: GetCapabilities: pt0x00len0x0001
CapabilityID:0x02(CompanyID)
Right... After all it comes as big endian, so you indeed shouldn't have any issue.
Sorry, for the noise. It looks good now.
Lucas De Marchi
Hi Luiz,
Quoted 3 lines · Luiz Augusto von Dentz
--- parser/avrcp.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 123 insertions(+), 1 deletions(-)
Both of these patches have been pushed upstream. Thanks.
Johan