From 71750b28609cd08c046d2bbcafa74e2380da2091 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 21 Apr 2016 15:26:32 +0200 Subject: USB Audio: Add dissection of Format Type Descriptor Only support Type 1 and 2 Change-Id: I0d2f5b9bc59063cb77d81667fe68c37133985568 Ping-Bug:11858 Reviewed-on: https://code.wireshark.org/review/15039 Reviewed-by: Anders Broman --- epan/dissectors/packet-usb-audio.c | 123 +++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) (limited to 'epan/dissectors/packet-usb-audio.c') diff --git a/epan/dissectors/packet-usb-audio.c b/epan/dissectors/packet-usb-audio.c index bce611f889..242d6c0290 100644 --- a/epan/dissectors/packet-usb-audio.c +++ b/epan/dissectors/packet-usb-audio.c @@ -50,6 +50,16 @@ static int hf_as_if_desc_subtype = -1; static int hf_as_if_gen_term_id = -1; static int hf_as_if_gen_delay = -1; static int hf_as_if_gen_format = -1; +static int hf_as_if_ft_formattype = -1; +static int hf_as_if_ft_maxbitrate = -1; +static int hf_as_if_ft_nrchannels = -1; +static int hf_as_if_ft_subframesize = -1; +static int hf_as_if_ft_bitresolution = -1; +static int hf_as_if_ft_samplesperframe = -1; +static int hf_as_if_ft_samfreqtype = -1; +static int hf_as_if_ft_lowersamfreq = -1; +static int hf_as_if_ft_uppersamfreq = -1; +static int hf_as_if_ft_samfreq = -1; static int hf_as_ep_desc_subtype = -1; static reassembly_table midi_data_reassembly_table; @@ -380,6 +390,85 @@ dissect_as_if_general_body(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, return offset-offset_start; } +static gint +dissect_as_if_format_type_body(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_, + proto_tree *tree, usb_conv_info_t *usb_conv_info) +{ + audio_conv_info_t *audio_conv_info; + gint offset_start; + guint8 SamFreqType; + guint8 format_type; + + /* the caller has already checked that usb_conv_info!=NULL */ + audio_conv_info = (audio_conv_info_t *)usb_conv_info->class_data; + if (!audio_conv_info) + return 0; + + offset_start = offset; + + proto_tree_add_item(tree, hf_as_if_ft_formattype, tvb, offset, 1, ENC_LITTLE_ENDIAN); + format_type = tvb_get_guint8(tvb, offset); + offset++; + + + switch(format_type){ + case 1: + proto_tree_add_item(tree, hf_as_if_ft_nrchannels, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; + + proto_tree_add_item(tree, hf_as_if_ft_subframesize, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; + + proto_tree_add_item(tree, hf_as_if_ft_bitresolution, tvb, offset, 1, ENC_LITTLE_ENDIAN); + offset += 1; + + proto_tree_add_item(tree, hf_as_if_ft_samfreqtype, tvb, offset, 1, ENC_LITTLE_ENDIAN); + SamFreqType = tvb_get_guint8(tvb, offset); + offset++; + + if(SamFreqType == 0){ + proto_tree_add_item(tree, hf_as_if_ft_lowersamfreq, tvb, offset, 3, ENC_LITTLE_ENDIAN); + offset += 3; + proto_tree_add_item(tree, hf_as_if_ft_uppersamfreq, tvb, offset, 3, ENC_LITTLE_ENDIAN); + offset += 3; + }else { + while(SamFreqType){ + proto_tree_add_item(tree, hf_as_if_ft_samfreq, tvb, offset, 3, ENC_LITTLE_ENDIAN); + offset += 3; + SamFreqType--; + } + } + break; + case 2: + proto_tree_add_item(tree, hf_as_if_ft_maxbitrate, tvb, offset, 2, ENC_LITTLE_ENDIAN); + offset += 2; + + proto_tree_add_item(tree, hf_as_if_ft_samplesperframe, tvb, offset, 2, ENC_LITTLE_ENDIAN); + offset += 2; + + proto_tree_add_item(tree, hf_as_if_ft_samfreqtype, tvb, offset, 1, ENC_LITTLE_ENDIAN); + SamFreqType = tvb_get_guint8(tvb, offset); + offset++; + + if(SamFreqType == 0){ + proto_tree_add_item(tree, hf_as_if_ft_lowersamfreq, tvb, offset, 3, ENC_LITTLE_ENDIAN); + offset += 3; + proto_tree_add_item(tree, hf_as_if_ft_uppersamfreq, tvb, offset, 3, ENC_LITTLE_ENDIAN); + offset += 3; + }else { + while(SamFreqType){ + proto_tree_add_item(tree, hf_as_if_ft_samfreq, tvb, offset, 3, ENC_LITTLE_ENDIAN); + offset += 3; + SamFreqType--; + } + } + break; + default: + break; + } + + return offset-offset_start; +} static gint dissect_usb_audio_descriptor(tvbuff_t *tvb, packet_info *pinfo, @@ -458,6 +547,10 @@ dissect_usb_audio_descriptor(tvbuff_t *tvb, packet_info *pinfo, dissect_as_if_general_body(tvb, offset, pinfo, desc_tree, usb_conv_info); break; + case AS_SUBTYPE_FORMAT_TYPE: + dissect_as_if_format_type_body(tvb, offset, pinfo, + desc_tree, usb_conv_info); + break; default: proto_tree_add_expert(desc_tree, pinfo, &ei_usb_audio_undecoded, tvb, offset-3, desc_len); break; @@ -580,6 +673,36 @@ proto_register_usb_audio(void) { &hf_as_if_gen_format, { "Format", "usbaudio.as_if_gen.wFormatTag", FT_UINT16, BASE_HEX, NULL, 0x00, "wFormatTag", HFILL }}, + { &hf_as_if_ft_formattype, + { "FormatType", "usbaudio.as_if_ft.bFormatType", + FT_UINT8, BASE_DEC, NULL, 0x00, "wFormatType", HFILL }}, + { &hf_as_if_ft_maxbitrate, + { "Max Bit Rate", "usbaudio.as_if_ft.wMaxBitRate", + FT_UINT16, BASE_DEC, NULL, 0x00, "wMaxBitRate", HFILL }}, + { &hf_as_if_ft_nrchannels, + { "Number Channels", "usbaudio.as_if_ft.bNrChannels", + FT_UINT8, BASE_DEC, NULL, 0x00, "bNrChannels", HFILL }}, + { &hf_as_if_ft_subframesize, + { "Subframe Size", "usbaudio.as_if_ft.bSubframeSize", + FT_UINT8, BASE_DEC, NULL, 0x00, "bSubframeSize", HFILL }}, + { &hf_as_if_ft_bitresolution, + { "Bit Resolution", "usbaudio.as_if_ft.bBitResolution", + FT_UINT8, BASE_DEC, NULL, 0x00, "bBitResolution", HFILL }}, + { &hf_as_if_ft_samplesperframe, + { "Samples Per Frame", "usbaudio.as_if_ft.wSamplesPerFrame", + FT_UINT16, BASE_DEC, NULL, 0x00, "wSamplesPerFrame", HFILL }}, + { &hf_as_if_ft_samfreqtype, + { "Samples Frequence Type", "usbaudio.as_if_ft.bSamFreqType", + FT_UINT8, BASE_DEC, NULL, 0x00, "bSamFreqType", HFILL }}, + { &hf_as_if_ft_lowersamfreq, + { "Lower Samples Frequence", "usbaudio.as_if_ft.tLowerSamFreq", + FT_UINT24, BASE_DEC, NULL, 0x00, "tLowerSamFreq", HFILL }}, + { &hf_as_if_ft_uppersamfreq, + { "Upper Samples Frequence", "usbaudio.as_if_ft.tUpperSamFreq", + FT_UINT24, BASE_DEC, NULL, 0x00, "tUpperSamFreq", HFILL }}, + { &hf_as_if_ft_samfreq, + { "Samples Frequence", "usbaudio.as_if_ft.tSamFreq", + FT_UINT24, BASE_DEC, NULL, 0x00, "tSamFreq", HFILL }}, { &hf_as_ep_desc_subtype, { "Subtype", "usbaudio.as_ep_subtype", FT_UINT8, BASE_HEX, NULL, 0x00, "bDescriptorSubtype", HFILL }}, -- cgit v1.2.3