proto_item *add_tlv_subtree(tlv_info_t *self, proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, const guint encoding) { header_field_info *hf; proto_tree *tlv_tree; proto_item *tlv_item; gint tlv_value_length, tlv_val_offset; guint8 size_of_tlv_length_field; guint8 tlv_type; /* Make sure we're dealing with a valid TLV here */ if (get_tlv_type(self) < 0) return tree; /* Retrieve the necessary TLV information */ tlv_val_offset = get_tlv_value_offset(self); tlv_value_length = get_tlv_length(self); size_of_tlv_length_field = get_tlv_size_of_length(self); tlv_type = get_tlv_type(self); hf = proto_registrar_get_nth(hfindex); tlv_item = proto_tree_add_text(tree, tvb, start, tlv_value_length+tlv_val_offset, "%s", hf->name); tlv_tree = proto_item_add_subtree(tlv_item, ett_tlv[tlv_type]); proto_tree_add_uint(tlv_tree, hf_tlv_type, tvb, start, 1, tlv_type); if (size_of_tlv_length_field > 0) /* It is */ { /* display the length of the length field TLV */ proto_tree_add_uint(tlv_tree, hf_tlv_length_size, tvb, start+1, 1, size_of_tlv_length_field); /* display the TLV length */ proto_tree_add_uint(tlv_tree, hf_tlv_length, tvb, start+2, size_of_tlv_length_field, tlv_value_length); } else { /* It is not */ /* display the TLV length */ proto_tree_add_uint(tlv_tree, hf_tlv_length, tvb, start+1, 1, tlv_value_length); } tlv_item = proto_tree_add_item(tlv_tree, hfindex, tvb, start+tlv_val_offset, tlv_value_length, encoding); /* Return a pointer to the value level */ return tlv_item; }
proto_tree *add_protocol_subtree(tlv_info_t *self, gint idx, proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start, gint length _U_, const char *label) { /* Declare local variables */ proto_tree *tlv_tree; proto_item *tlv_item; gint tlv_value_length, tlv_val_offset; guint8 size_of_tlv_length_field; guint8 tlv_type; guint32 tlv_value; const gchar *hex_fmt; /* Make sure we're dealing with a valid TLV here */ if (get_tlv_type(self) < 0) return tree; /* Retrieve the necessary TLV information */ tlv_val_offset = get_tlv_value_offset(self); tlv_value_length = get_tlv_length(self); size_of_tlv_length_field = get_tlv_size_of_length(self); tlv_type = get_tlv_type(self); /* display the TLV name and display the value in hex. Highlight type, length, and value. */ tlv_item = proto_tree_add_protocol_format(tree, hfindex, tvb, start, tlv_value_length+tlv_val_offset, "%s (%u byte(s))", label, tlv_value_length); tlv_tree = proto_item_add_subtree(tlv_item, ett_tlv[tlv_type]); proto_tree_add_uint(tlv_tree, hf_tlv_type, tvb, start, 1, tlv_type); if (size_of_tlv_length_field > 0) /* It is */ { /* display the length of the length field TLV */ proto_tree_add_uint(tlv_tree, hf_tlv_length_size, tvb, start+1, 1, size_of_tlv_length_field); /* display the TLV length */ proto_tree_add_uint(tlv_tree, hf_tlv_length, tvb, start+2, size_of_tlv_length_field, tlv_value_length); } else { /* It is not */ /* display the TLV length */ proto_tree_add_uint(tlv_tree, hf_tlv_length, tvb, start+1, 1, tlv_value_length); } /* display the TLV value and make it a subtree */ switch (tlv_value_length) { case 1: tlv_value = tvb_get_guint8(tvb, start+tlv_val_offset); hex_fmt = tlv_val_1byte; break; case 2: tlv_value = tvb_get_ntohs(tvb, start+tlv_val_offset); hex_fmt = tlv_val_2byte; break; case 3: tlv_value = tvb_get_ntoh24(tvb, start+tlv_val_offset); hex_fmt = tlv_val_3byte; break; case 4: tlv_value = tvb_get_ntohl(tvb, start+tlv_val_offset); hex_fmt = tlv_val_4byte; break; default: tlv_value = tvb_get_ntohl(tvb, start+tlv_val_offset); hex_fmt = tlv_val_5byte; break; } /* Show "TLV value: " */ tlv_tree = proto_tree_add_subtree_format(tlv_tree, tvb, start+tlv_val_offset, tlv_value_length, idx, NULL, hex_fmt, label, tlv_value); /* Return a pointer to the value level */ return tlv_tree; }
{ /* Declare local variables */ proto_tree *tlv_tree; proto_item *tlv_item; guint start_of_tlv; gint tlv_value_length, tlv_val_offset; guint8 size_of_tlv_length_field; guint8 tlv_type; guint32 tlv_value; gchar *hex_fmt; /* Retrieve the necessary TLV information */ tlv_val_offset = get_tlv_value_offset(this); start_of_tlv = start - tlv_val_offset; tlv_value_length = get_tlv_length(this); size_of_tlv_length_field = get_tlv_size_of_length(this); tlv_type = get_tlv_type(this); /* display the TLV name and display the value in hex. Highlight type, length, and value. */ tlv_item = proto_tree_add_item(tree, hfindex, tvb, start, tlv_value_length, little_endian); if (!PITEM_FINFO(tlv_item)) return tree; /* Correct the highlighting. */ PITEM_FINFO(tlv_item)->start -= tlv_val_offset; PITEM_FINFO(tlv_item)->length += tlv_val_offset; /* add TLV subtree to contain the type, length, and value */ tlv_tree = proto_item_add_subtree(tlv_item, *ett_tlv[tlv_type]); /* display the TLV type */ proto_tree_add_text(tlv_tree, tvb, start_of_tlv, 1, "TLV type: %u", tlv_type);