diff options
Diffstat (limited to 'plugins/docsis/packet-ocd.c')
-rw-r--r-- | plugins/docsis/packet-ocd.c | 300 |
1 files changed, 152 insertions, 148 deletions
diff --git a/plugins/docsis/packet-ocd.c b/plugins/docsis/packet-ocd.c index fb16d152f5..cec82e3386 100644 --- a/plugins/docsis/packet-ocd.c +++ b/plugins/docsis/packet-ocd.c @@ -57,17 +57,20 @@ static int hf_docsis_ocd_tlv_ofdm_spec_loc = -1; static int hf_docsis_ocd_tlv_time_int_depth = -1; static int hf_docsis_ocd_tlv_prim_cap_ind = -1; -static int hf_docsis_ocd_tlv_sub_assign_length = -1; static int hf_docsis_ocd_tlv_subc_assign_type = -1; static int hf_docsis_ocd_tlv_subc_assign_value = -1; -static int docsis_ocd_subc_assign_subc_type = -1; -static int docsis_ocd_subc_assign_range = -1; -static int docsis_ocd_subc_assign_index = -1; +static int hf_docsis_ocd_subc_assign_subc_type = -1; +static int hf_docsis_ocd_subc_assign_range = -1; +static int hf_docsis_ocd_subc_assign_index = -1; +static int hf_docsis_ocd_tlv_data = -1; +static int hf_docsis_ocd_type = -1; +static int hf_docsis_ocd_length = -1; + /* Initialize the subtree pointers */ static gint ett_docsis_ocd = -1; static gint ett_docsis_ocd_tlv = -1; -static gint ett_docsis_ocd_tlv_subcarrier_assignment = -1; +static gint ett_docsis_ocd_tlvtlv = -1; static expert_field ei_docsis_ocd_tlvlen_bad = EI_INIT; static expert_field ei_docsis_ocd_value_unknown = EI_INIT; @@ -104,19 +107,20 @@ static const value_string docsis_ocd_prim_cap_ind_str[] = { {0, NULL} }; +static const value_string ocd_tlv_vals[] = { + {DISCRETE_FOURIER_TRANSFORM_SIZE, "Discrete Fourier Transform Size"}, + {CYCLIC_PREFIX, "Cylic Prefix"}, + {ROLL_OFF, "Roll Off"}, + {OFDM_SPECTRUM_LOCATION, "OFDM Spectrum Location"}, + {TIME_INTERLEAVING_DEPTH, "Time Interleaving Depth"}, + {SUBCARRIER_ASSIGNMENT_RANGE_LIST, "Subcarrier Assignment Range/List"}, + {PRIMARY_CAPABILITY_INDICATOR, "Primary Capable Indicator"}, + {0, NULL} +}; + /** BASE_CUSTOM formatter for the OFDM spectrum location */ static void -ofdm_spec_loc( - char *buf, - guint32 value) -{ - g_snprintf(buf, ITEM_LABEL_LENGTH, - "%u Hz", - value); -} - -static void subc_assign_range( char *buf, guint32 value) @@ -147,139 +151,139 @@ static const value_string docsis_ocd_subc_assign_subc_type_str[] = { {0, NULL} }; +static const unit_name_string local_units_hz = { "Hz", NULL }; /* Dissection */ static void -dissect_subcarrier_assignment_range_list(tvbuff_t * tvb, packet_info* pinfo, proto_tree * tree, guint16 start, guint16 len) +dissect_subcarrier_assignment_range_list(tvbuff_t * tvb, packet_info* pinfo, proto_tree * tree, guint16 pos, guint32 len) { - proto_item *it; - proto_tree *subcarrier_assignment_tree; - guint8 subcarrier_assignment_type; - guint16 subcarrier_assignment_index; + proto_item* type_item; + guint32 i, subcarrier_assignment_type; - it = proto_tree_add_protocol_format (tree, proto_docsis_ocd, tvb, start-2, len+2, ".5 Subcarrier Assignment Range/List"); - subcarrier_assignment_tree = proto_item_add_subtree (it, ett_docsis_ocd_tlv_subcarrier_assignment); - - proto_tree_add_item (subcarrier_assignment_tree, hf_docsis_ocd_tlv_sub_assign_length, tvb, start-1, 1, ENC_BIG_ENDIAN); - proto_tree_add_item (subcarrier_assignment_tree, hf_docsis_ocd_tlv_subc_assign_type, tvb, start, 1, ENC_BIG_ENDIAN); - proto_tree_add_item (subcarrier_assignment_tree, hf_docsis_ocd_tlv_subc_assign_value, tvb, start, 1, ENC_BIG_ENDIAN); - proto_tree_add_item (subcarrier_assignment_tree, docsis_ocd_subc_assign_subc_type, tvb, start, 1, ENC_BIG_ENDIAN); - - - subcarrier_assignment_type = (tvb_get_guint8 (tvb, start) >> 6); + type_item = proto_tree_add_item_ret_uint (tree, hf_docsis_ocd_tlv_subc_assign_type, tvb, pos, 1, ENC_BIG_ENDIAN, &subcarrier_assignment_type); + proto_tree_add_item (tree, hf_docsis_ocd_tlv_subc_assign_value, tvb, pos, 1, ENC_BIG_ENDIAN); + proto_tree_add_item (tree, hf_docsis_ocd_subc_assign_subc_type, tvb, pos, 1, ENC_BIG_ENDIAN); + pos++; switch (subcarrier_assignment_type) { case SUBCARRIER_ASSIGNMENT_RANGE_CONT: case SUBCARRIER_ASSIGNMENT_RANGE_SKIPBY1: - proto_tree_add_item (subcarrier_assignment_tree, docsis_ocd_subc_assign_range, tvb, start + 1, 4, ENC_BIG_ENDIAN); + proto_tree_add_item (tree, hf_docsis_ocd_subc_assign_range, tvb, pos, 4, ENC_BIG_ENDIAN); break; case SUBCARRIER_ASSIGNMENT_LIST: - for (subcarrier_assignment_index = 0; subcarrier_assignment_index < len/2; ++subcarrier_assignment_index) { - proto_tree_add_item (subcarrier_assignment_tree, docsis_ocd_subc_assign_index, tvb, start + 1 + 2*subcarrier_assignment_index, 2, ENC_BIG_ENDIAN); + for (i = 0; i < len/2; ++i) { + proto_tree_add_item (tree, hf_docsis_ocd_subc_assign_index, tvb, pos, 2, ENC_BIG_ENDIAN); + pos += 2; } break; default: - expert_add_info_format(pinfo, tree, &ei_docsis_ocd_value_unknown, "Unknown subcarrier assignment type %d", subcarrier_assignment_type); + expert_add_info_format(pinfo, type_item, &ei_docsis_ocd_value_unknown, "Unknown subcarrier assignment type %d", subcarrier_assignment_type); break; } } - static void -dissect_ocd_tlv (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, guint8 start, guint16 len) +dissect_ocd_tlv (tvbuff_t * tvb, packet_info* pinfo, proto_tree * tree) { - proto_item *it; + proto_item *it, *tlv_item, *tlv_len_item; proto_tree *tlv_tree; - guint16 pos = start; - guint8 type, length; + guint16 pos = 0; + guint8 type; + guint32 length; - it = proto_tree_add_protocol_format (tree, proto_docsis_ocd, tvb, start, len, "TLV Data"); + it = proto_tree_add_item(tree, hf_docsis_ocd_tlv_data, tvb, 0, tvb_reported_length(tvb), ENC_NA); tlv_tree = proto_item_add_subtree (it, ett_docsis_ocd_tlv); - while (pos < (len + start)) + while (tvb_reported_length_remaining(tvb, pos) > 0) { - type = tvb_get_guint8 (tvb, pos++); - length = tvb_get_guint8 (tvb, pos++); - if(pos + length > start + len) { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } + type = tvb_get_guint8 (tvb, pos); + tlv_tree = proto_tree_add_subtree(tlv_tree, tvb, pos, -1, + ett_docsis_ocd_tlvtlv, &tlv_item, + val_to_str(type, ocd_tlv_vals, + "Unknown TLV (%u)")); + proto_tree_add_uint (tlv_tree, hf_docsis_ocd_type, tvb, pos, 1, type); + pos++; + tlv_len_item = proto_tree_add_item_ret_uint (tlv_tree, hf_docsis_ocd_length, tvb, pos, 1, ENC_NA, &length); + pos++; + proto_item_set_len(tlv_item, length + 2); + switch (type) { - case DISCRETE_FOURIER_TRANSFORM_SIZE: - if (length == 1) - { - proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_four_trans_size, tvb, pos, 1, ENC_BIG_ENDIAN); - } - else - { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } - break; - case CYCLIC_PREFIX: - if (length == 1) - { - proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_cycl_pref, tvb, pos, 1, ENC_BIG_ENDIAN); - } - else - { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } - break; - case ROLL_OFF: - if (length == 1) - { - proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_roll_off, tvb, pos, 1, ENC_BIG_ENDIAN); - } - else - { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } - break; - case OFDM_SPECTRUM_LOCATION: - if (length == 4) - { - proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_ofdm_spec_loc, tvb, pos, 4, ENC_BIG_ENDIAN); - } - else - { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } - break; - case TIME_INTERLEAVING_DEPTH: - if (length == 1) - { - proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_time_int_depth, tvb, pos, 1, ENC_BIG_ENDIAN); - } - else - { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } - break; - case SUBCARRIER_ASSIGNMENT_RANGE_LIST: - if (length >= 5) - { - dissect_subcarrier_assignment_range_list(tvb, pinfo, tlv_tree, pos, length); - } - else - { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } - break; - case PRIMARY_CAPABILITY_INDICATOR: - if (length == 1) - { - proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_prim_cap_ind, tvb, pos, 1, ENC_BIG_ENDIAN); - } - else - { - expert_add_info_format(pinfo, tlv_tree, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); - } - break; - default: - proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_unknown, tvb, pos - 2, length+2, ENC_NA); - break; + case DISCRETE_FOURIER_TRANSFORM_SIZE: + if (length == 1) + { + proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_four_trans_size, tvb, pos, 1, ENC_BIG_ENDIAN); + } + else + { + expert_add_info_format(pinfo, tlv_len_item, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); + } + break; + case CYCLIC_PREFIX: + if (length == 1) + { + proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_cycl_pref, tvb, pos, 1, ENC_BIG_ENDIAN); + } + else + { + expert_add_info_format(pinfo, tlv_len_item, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); + } + break; + case ROLL_OFF: + if (length == 1) + { + proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_roll_off, tvb, pos, 1, ENC_BIG_ENDIAN); + } + else + { + expert_add_info_format(pinfo, tlv_len_item, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); + } + break; + case OFDM_SPECTRUM_LOCATION: + if (length == 4) + { + proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_ofdm_spec_loc, tvb, pos, 4, ENC_BIG_ENDIAN); + } + else + { + expert_add_info_format(pinfo, tlv_len_item, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); + } + break; + case TIME_INTERLEAVING_DEPTH: + if (length == 1) + { + proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_time_int_depth, tvb, pos, 1, ENC_BIG_ENDIAN); + } + else + { + expert_add_info_format(pinfo, tlv_len_item, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); + } + break; + case SUBCARRIER_ASSIGNMENT_RANGE_LIST: + if (length >= 5) + { + dissect_subcarrier_assignment_range_list(tvb, pinfo, tlv_tree, pos, length); + } + else + { + expert_add_info_format(pinfo, tlv_len_item, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); + } + break; + case PRIMARY_CAPABILITY_INDICATOR: + if (length == 1) + { + proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_prim_cap_ind, tvb, pos, 1, ENC_BIG_ENDIAN); + } + else + { + expert_add_info_format(pinfo, tlv_len_item, &ei_docsis_ocd_tlvlen_bad, "Wrong TLV length: %u", length); + } + break; + default: + proto_tree_add_item (tlv_tree, hf_docsis_ocd_tlv_unknown, tvb, pos - 2, length+2, ENC_NA); + break; } /* switch */ - pos = pos + length; + pos += length; } /* while */ } @@ -287,27 +291,21 @@ static int dissect_ocd (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_) { proto_item *it; - proto_tree *ocd_tree = NULL; + proto_tree *ocd_tree; + tvbuff_t *next_tvb; + guint32 downstream_channel_id, configuration_change_count; - guint8 downstream_channel_id; - guint8 configuration_change_count; - guint16 len; + it = proto_tree_add_item(tree, proto_docsis_ocd, tvb, 0, -1, ENC_NA); + ocd_tree = proto_item_add_subtree (it, ett_docsis_ocd); - downstream_channel_id = tvb_get_guint8 (tvb, 0); - configuration_change_count = tvb_get_guint8 (tvb, 1); - len = tvb_captured_length_remaining (tvb, 2); + proto_tree_add_item_ret_uint (ocd_tree, hf_docsis_ocd_dschid, tvb, 0, 1, ENC_BIG_ENDIAN, &downstream_channel_id); + proto_tree_add_item_ret_uint (ocd_tree, hf_docsis_ocd_ccc, tvb, 1, 1, ENC_BIG_ENDIAN, &configuration_change_count); col_add_fstr (pinfo->cinfo, COL_INFO, "OCD: DS CH ID: %u, CCC: %u", downstream_channel_id, configuration_change_count); - if (tree) - { - it = proto_tree_add_protocol_format (tree, proto_docsis_ocd, tvb, 0, -1, "OFDM Channel Descriptor"); - ocd_tree = proto_item_add_subtree (it, ett_docsis_ocd); - proto_tree_add_item (ocd_tree, hf_docsis_ocd_dschid, tvb, 0, 1, ENC_BIG_ENDIAN); - proto_tree_add_item (ocd_tree, hf_docsis_ocd_ccc, tvb, 1, 1, ENC_BIG_ENDIAN); - } /* Call Dissector TLV's */ - dissect_ocd_tlv(tvb, pinfo, ocd_tree, 2, len); + next_tvb = tvb_new_subset_remaining(tvb, 2); + dissect_ocd_tlv(next_tvb, pinfo, ocd_tree); return tvb_captured_length(tvb); } @@ -327,25 +325,22 @@ proto_register_docsis_ocd(void) {"Configuration Change Count", "docsis_ocd.ccc", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL} }, {&hf_docsis_ocd_tlv_four_trans_size, - {".0 Discrete Fourier Transform Size", "docsis_ocd.tlv.four_trans_size", FT_UINT8, BASE_DEC, VALS (docsis_ocd_four_trans_size), 0x0, NULL, HFILL} + {"Discrete Fourier Transform Size", "docsis_ocd.tlv.four_trans_size", FT_UINT8, BASE_DEC, VALS (docsis_ocd_four_trans_size), 0x0, NULL, HFILL} }, {&hf_docsis_ocd_tlv_cycl_pref, - {".1 Cylic Prefix", "docsis_ocd.tlv.cyc_pref", FT_UINT8, BASE_DEC, VALS (docsis_ocd_cyc_prefix), 0x0, NULL, HFILL} + {"Cylic Prefix", "docsis_ocd.tlv.cyc_pref", FT_UINT8, BASE_DEC, VALS (docsis_ocd_cyc_prefix), 0x0, NULL, HFILL} }, {&hf_docsis_ocd_tlv_roll_off, - {".2 Roll Off", "docsis_ocd.tlv.roll_off", FT_UINT8, BASE_DEC, VALS (docsis_ocd_roll_off), 0x0, NULL, HFILL} + {"Roll Off", "docsis_ocd.tlv.roll_off", FT_UINT8, BASE_DEC, VALS (docsis_ocd_roll_off), 0x0, NULL, HFILL} }, {&hf_docsis_ocd_tlv_ofdm_spec_loc, - {".3 OFDM Spectrum Location", "docsis_ocd.tlv.ofdm_spec_loc", FT_UINT32, BASE_CUSTOM, CF_FUNC(ofdm_spec_loc) , 0x0, NULL, HFILL} + {"OFDM Spectrum Location", "docsis_ocd.tlv.ofdm_spec_loc", FT_UINT32, BASE_DEC|BASE_UNIT_STRING, &local_units_hz, 0x0, NULL, HFILL} }, {&hf_docsis_ocd_tlv_time_int_depth, - {".4 Time Interleaving Depth", "docsis_ocd.tlv.time_int_depth", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL} + {"Time Interleaving Depth", "docsis_ocd.tlv.time_int_depth", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL} }, {&hf_docsis_ocd_tlv_prim_cap_ind, - {".6 Primary Capable Indicator", "docsis_ocd.tlv.prim_cap_ind", FT_UINT8, BASE_DEC, VALS(docsis_ocd_prim_cap_ind_str), 0x0, NULL, HFILL} - }, - {&hf_docsis_ocd_tlv_sub_assign_length, - {"Subcarrier Assignment Length", "docsis_ocd.tlv.subc_assign.length", FT_UINT8, BASE_DEC, NULL, 0x00, NULL, HFILL} + {"Primary Capable Indicator", "docsis_ocd.tlv.prim_cap_ind", FT_UINT8, BASE_DEC, VALS(docsis_ocd_prim_cap_ind_str), 0x0, NULL, HFILL} }, {&hf_docsis_ocd_tlv_subc_assign_type, {"Assignment type", "docsis_ocd.tlv.subc_assign.type", FT_UINT8, BASE_DEC, VALS(docsis_ocd_subc_assign_type_str), 0xC0, NULL, HFILL} @@ -353,15 +348,24 @@ proto_register_docsis_ocd(void) {&hf_docsis_ocd_tlv_subc_assign_value, {"Assignment value", "docsis_ocd.tlv.subc_assign.value", FT_UINT8, BASE_DEC, VALS(docsis_ocd_subc_assign_value_str), 0x20, NULL, HFILL} }, - {&docsis_ocd_subc_assign_subc_type, + {&hf_docsis_ocd_subc_assign_subc_type, {"Subcarrier Type", "docsis_ocd.tlv.subc_assign.subc_type", FT_UINT8, BASE_DEC, VALS(docsis_ocd_subc_assign_subc_type_str), 0x1F, NULL, HFILL} }, - {&docsis_ocd_subc_assign_range, + {&hf_docsis_ocd_subc_assign_range, {"Subcarrier index range", "docsis_ocd.tlv.subc_assign.range", FT_UINT32, BASE_CUSTOM, CF_FUNC(subc_assign_range), 0x00, NULL, HFILL} }, - {&docsis_ocd_subc_assign_index, + {&hf_docsis_ocd_subc_assign_index, {"Subcarrier index", "docsis_ocd.tlv.subc_assign.index", FT_UINT16, BASE_DEC, NULL, 0x00, NULL, HFILL} }, + {&hf_docsis_ocd_tlv_data, + {"TLV Data", "docsis_ocd.tlv_data", FT_BYTES, BASE_NO_DISPLAY_VALUE, NULL, 0x0, NULL, HFILL} + }, + {&hf_docsis_ocd_type, + {"Type", "docsis_ocd.type",FT_UINT8, BASE_DEC, VALS(ocd_tlv_vals), 0x0, NULL, HFILL} + }, + {&hf_docsis_ocd_length, + {"Length", "docsis_ocd.length",FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL} + }, }; static ei_register_info ei[] = { @@ -372,7 +376,7 @@ proto_register_docsis_ocd(void) static gint *ett[] = { &ett_docsis_ocd, &ett_docsis_ocd_tlv, - &ett_docsis_ocd_tlv_subcarrier_assignment + &ett_docsis_ocd_tlvtlv, }; expert_module_t* expert_docsis_ocd; |