#.FN_BODY

Sometimes, like when we have ANY types, we might want to replace whatever function body that Asn2wrs generates with code of our own. This is what this directive allows us to do.

Example : ANY

Asn2wrs can handle the type ANY but we have to help it by adding some small changes to the conformance file.
Assuming you have a construct that looks something like this :

  AlgorithmIdentifier ::= SEQUENCE {
      algorithm OBJECT IDENTIFIER,
      parameters ANY OPTIONAL
  }

To handle this we need to specify our own function bodies to both the algorithm and the parameters fields, which we do using the #.FN_BODY directive.

This particular example also requires us to keep some state between the two field dissectors, namely the OBJECT IDENTIFIER from algorithm which specifis what the content of parameters is. For this one we need a string where we store the oid from AlgorithmIdentifier/algorithm so that we can pick it up and act on later from inside the dissector for AlgorithmIdentifier/parameters. So we have to add :

      static char algorithm_id[64]; /* 64 chars should be enough? */

to the template file as a placeholder to remember which OID we picked up. Then we add to the conformance file:

  #.FN_BODY AlgorithmIdentifier/algorithmId
      offset = dissect_ber_object_identifier(FALSE, pinfo, tree, tvb, offset,
            hf_x509af_algorithm_id, algorithm_id);

  #.FN_BODY AlgorithmIdentifier/parameters
      offset=call_ber_oid_callback(algorithm_id, tvb, offset, pinfo, tree);

The dissector body we specified for AlgorithmIdentifier/algorithmId here stores the retreived OID inside the variable algorithm_id we specified.
When we later come to the dissector for AlgorithmIdentifier/parameters we pick this OID up from the static variable and just pass it on to the ber/oid dissector helper.

This example comes from the X509AF dissector. Please see the code there for more examples on how to do this.

#.FN_BODY (last edited 2008-04-12 17:49:58 by localhost)