Wireshark-dev: [Wireshark-dev] asn2wrs problem when value needed from tagged type
From: "Anders Broman" <a.broman@xxxxxxxxx>
Date: Mon, 30 Apr 2007 12:36:24 +0200
Hi,
There is a problem with the tagged type if a value needs to be returned from
it.

As the following example from TCAP:

#.FN_BODY OrigTransactionID VAL_PTR = parameter_tvb
tvbuff_t *parameter_tvb;
guint8 len, i;
proto_item *tid_item;
proto_tree *subtree;
tid_item = proto_tree_add_text(tree, tvb, offset, -1, "Source Transaction
ID");
subtree = proto_item_add_subtree(tid_item, ett_otid);

%(DEFAULT_BODY)s

The generated code will be:
static int
dissect_tcap_OCTET_STRING_SIZE_1_4(gboolean implicit_tag _U_, tvbuff_t *tvb
_U_, int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int
hf_index _U_) {
  offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset,
hf_index,
                                       NULL);

  return offset;
}



static int
dissect_tcap_OrigTransactionID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_,
int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int hf_index
_U_) {
#line 159 "tcap.cnf"
tvbuff_t *parameter_tvb;
guint8 len, i;
proto_item *tid_item;
proto_tree *subtree;
tid_item = proto_tree_add_text(tree, tvb, offset, -1, "Source Transaction
ID");
subtree = proto_item_add_subtree(tid_item, ett_otid);

  offset = dissect_ber_tagged_type(implicit_tag, pinfo, tree, tvb, offset,
                                      hf_index, BER_CLASS_APP, 8, TRUE,
dissect_tcap_OCTET_STRING_SIZE_1_4);

I think this can be solved by using
typedef struct _asn1_ber_ctx_t {
  proto_item *created_item;
  void *value_ptr;
  void *private_data;
} asn1_ber_ctx_t;

In packet-ber.c similar to packet-per.c if the code above could be changed
to something like the code
Below only for the tagged type as a start as there is a lot of changes
needed otherwise.
Regards
Anders

static int
dissect_tcap_OCTET_STRING_SIZE_1_4(gboolean implicit_tag _U_, tvbuff_t *tvb
_U_, int offset _U_, asn1_ber_ctx_t *actx, packet_info *pinfo _U_,
proto_tree *tree _U_, int hf_index _U_) {
  offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset,
hf_index,
                                       actx->value_ptr);

  return offset;
}



static int
dissect_tcap_OrigTransactionID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_,
int offset _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int hf_index
_U_) {
#line 159 "tcap.cnf"
tvbuff_t *parameter_tvb;
guint8 len, i;
proto_item *tid_item;
proto_tree *subtree;
tid_item = proto_tree_add_text(tree, tvb, offset, -1, "Source Transaction
ID");
subtree = proto_item_add_subtree(tid_item, ett_otid);

  offset = dissect_ber_tagged_type(implicit_tag, pinfo, tree, tvb, offset,
actx
                                      hf_index, BER_CLASS_APP, 8, TRUE,
dissect_tcap_OCTET_STRING_SIZE_1_4);