diff options
author | kukosa <kukosa@f5534014-38df-0310-8fa8-9805f1628bb7> | 2006-06-05 06:49:52 +0000 |
---|---|---|
committer | kukosa <kukosa@f5534014-38df-0310-8fa8-9805f1628bb7> | 2006-06-05 06:49:52 +0000 |
commit | 6726a08ee5aa2082ced0f51b1eea2dd4864c7a3c (patch) | |
tree | 6f16b2e9095f9e0c2bb540437053a6ae4487b7be | |
parent | 361e5a33f1796683e95c98a06f15b0dd2bb0b6ac (diff) |
- packet-per.[ch]: Open Type support
- asn2wrs.py: TYPE-IDENTIFIER and ABSTRACT-SYNTAX information object classes support
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@18338 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | epan/dissectors/packet-per.c | 21 | ||||
-rw-r--r-- | epan/dissectors/packet-per.h | 3 | ||||
-rwxr-xr-x | tools/asn2wrs.py | 141 |
3 files changed, 151 insertions, 14 deletions
diff --git a/epan/dissectors/packet-per.c b/epan/dissectors/packet-per.c index e9ddfdce94..e695b6b6c1 100644 --- a/epan/dissectors/packet-per.c +++ b/epan/dissectors/packet-per.c @@ -112,6 +112,27 @@ void asn_ctx_init(asn_ctx_t *actx, asn_enc_e encoding, gboolean aligned, packet_ offset=(offset&0xfffffff8)+8; \ } +/* 10 Encoding procedures -------------------------------------------------- */ + +/* 10.2 Open type fields --------------------------------------------------- */ +guint32 +dissect_per_open_type(tvbuff_t *tvb, guint32 offset, asn_ctx_t *actx, proto_tree *tree, int hf_index, per_type_fn type) +{ + guint32 type_length, end_offset; + + offset = dissect_per_length_determinant(tvb, offset, actx, tree, hf_per_open_type_length, &type_length); + if (actx->aligned) BYTE_ALIGN_OFFSET(offset); + end_offset = offset + type_length * 8; + + if (type) { + type(tvb, offset, actx, tree, hf_index); + } else { + actx->created_item = proto_tree_add_text(tree, tvb, offset>>3, BLEN(offset, end_offset), "Unknown Open Type"); + } + + return end_offset; +} + /* 10.9 General rules for encoding a length determinant -------------------- */ guint32 dissect_per_length_determinant(tvbuff_t *tvb, guint32 offset, asn_ctx_t *actx _U_, proto_tree *tree, int hf_index, guint32 *length) diff --git a/epan/dissectors/packet-per.h b/epan/dissectors/packet-per.h index bc3fe2a463..ea1c953685 100644 --- a/epan/dissectors/packet-per.h +++ b/epan/dissectors/packet-per.h @@ -56,6 +56,7 @@ if (check_col(actx->pinfo->cinfo, COL_INFO)){ \ tvb_get_guint8(tvb, 9999); typedef int (*per_callback)(tvbuff_t *, int, asn_ctx_t *, proto_tree *); +typedef int (*per_type_fn)(tvbuff_t*, int, asn_ctx_t*, proto_tree*, int); /* in all functions here, offset is guint32 and is byteposition<<3 + bitposition @@ -133,4 +134,6 @@ extern guint32 dissect_per_restricted_character_string(tvbuff_t *tvb, guint32 of extern guint32 dissect_per_enumerated(tvbuff_t *tvb, guint32 offset, asn_ctx_t *actx, proto_tree *tree, int hf_index, guint32 root_num, guint32 *value, gboolean has_extension, guint32 ext_num, guint32 *value_map); +extern guint32 dissect_per_open_type(tvbuff_t *tvb, guint32 offset, asn_ctx_t *actx, proto_tree *tree, int hf_index, per_type_fn type); + #endif /* __PACKET_PER_H__ */ diff --git a/tools/asn2wrs.py b/tools/asn2wrs.py index 82a82381ba..2cc3e9eb53 100755 --- a/tools/asn2wrs.py +++ b/tools/asn2wrs.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# competh.py +# asn2wrs.py # ASN.1 to Wireshark dissector compiler # 2004 Tomas Kukosa # @@ -24,6 +24,9 @@ # ITU-T Recommendation X.680 (07/2002), # Information technology - Abstract Syntax Notation One (ASN.1): Specification of basic notation # +# ITU-T Recommendation X.681 (07/2002), +# Information technology - Abstract Syntax Notation One (ASN.1): Information object specification +# # ITU-T Recommendation X.682 (07/2002), # Information technology - Abstract Syntax Notation One (ASN.1): Constraint specification # @@ -169,7 +172,8 @@ static_tokens = { r';' : 'SEMICOLON', #r'@' : 'AT', #r'\!' : 'EXCLAMATION', - r'\^' : 'CIRCUMFLEX' + r'\^' : 'CIRCUMFLEX', + r'\&' : 'AMPERSAND' } # 11.27 Reserved words @@ -230,6 +234,8 @@ reserved_words = { 'AUTOMATIC': 'AUTOMATIC', 'OBJECT': 'OBJECT', 'IDENTIFIER': 'IDENTIFIER', + 'TYPE-IDENTIFIER' : 'TYPE_IDENTIFIER', + 'ABSTRACT-SYNTAX' : 'ABSTRACT_SYNTAX', # 'OPERATION' : 'OPERATION', # 'ARGUMENT' : 'ARGUMENT', # 'RESULT' : 'RESULT', @@ -2942,6 +2948,56 @@ class EnumeratedType (Type): body = '#error Can not decode %s' % (tname) return body +#--- OpenType ----------------------------------------------------------- +class OpenType (Type): + def to_python (self, ctx): + return "asn1.ANY" + + def single_type(self): + if (self.HasConstraint() and + self.constr.type == 'Type' and + self.constr.subtype.type == 'Type_Ref'): + return self.constr.subtype.val + return None + + def eth_reg_sub(self, ident, ectx): + t = self.single_type() + if t: + ectx.eth_dep_add(ident, t) + + def eth_tname(self): + t = self.single_type() + if t: + return 'OpenType_' + t + else: + return Type.eth_tname(self) + + def eth_ftype(self, ectx): + return ('FT_NONE', 'BASE_NONE') + + def GetTTag(self, ectx): + return ('BER_CLASS_ANY', '0') + + def eth_type_default_pars(self, ectx, tname): + pars = Type.eth_type_default_pars(self, ectx, tname) + t = self.single_type() + if t: + t = ectx.type[t]['ethname'] + pars['TYPE_REF_PROTO'] = ectx.eth_type[t]['proto'] + pars['TYPE_REF_TNAME'] = t + pars['TYPE_REF_FN'] = 'dissect_%(TYPE_REF_PROTO)s_%(TYPE_REF_TNAME)s' + else: + pars['TYPE_REF_FN'] = 'NULL' + return pars + + def eth_type_default_body(self, ectx, tname): + if (ectx.Per()): + body = ectx.eth_fn_call('dissect_%(ER)s_open_type', ret='offset', + par=(('%(TVB)s', '%(OFFSET)s', '%(ACTX)s', '%(TREE)s', '%(HF_INDEX)s', '%(TYPE_REF_FN)s',),)) + else: + body = '#error Can not decode %s' % (tname) + return body + #--- AnyType ----------------------------------------------------------- class AnyType (Type): def to_python (self, ctx): @@ -3635,8 +3691,8 @@ def p_ValueAssignment (t): # 16.1 def p_Type (t): '''Type : BuiltinType - | ReferencedType - | ConstrainedType''' + | ReferencedType + | ConstrainedType''' t[0] = t[1] # 16.2 @@ -3649,6 +3705,7 @@ def p_BuiltinType (t): | EnumeratedType | IntegerType | NullType + | ObjectClassFieldType | ObjectIdentifierType | OctetStringType | RealType @@ -4084,7 +4141,7 @@ def p_AnyType (t): # 31.1 def p_ObjectIdentifierType (t): 'ObjectIdentifierType : OBJECT IDENTIFIER' - t[0] = ObjectIdentifierType () + t[0] = ObjectIdentifierType() # 31.3 def p_ObjectIdentifierValue (t): @@ -4274,6 +4331,7 @@ def p_SubtypeElements (t): | ValueRange | PermittedAlphabet | SizeConstraint + | TypeConstraint | InnerTypeConstraints | PatternConstraint''' t[0] = t[1] @@ -4335,9 +4393,9 @@ def p_SizeConstraint (t): # 47.6 Type constraint # 47.6.1 -#def p_TypeConstraint (t): -# 'TypeConstraint : Type' -# t[0] = Constraint (type = 'Type', subtype = t[2]) +def p_TypeConstraint (t): + 'TypeConstraint : Type' + t[0] = Constraint (type = 'Type', subtype = t[1]) # 47.7 Permitted alphabet # 47.7.1 @@ -4477,9 +4535,64 @@ def p_char_string (t): t[0] = t[1] def p_number (t): - 'number : NUMBER' - t[0] = t[1] + 'number : NUMBER' + t[0] = t[1] + + +#--- ITU-T Recommendation X.681 ----------------------------------------------- + +# 7 ASN.1 lexical items ------------------------------------------------------- + +# 7.4 Type field references +def p_typefieldreference (t): + 'typefieldreference : AMPERSAND UCASE_IDENT' + t[0] = t[2] + +# 7.5 Value field references + +def p_valuefieldreference (t): + 'valuefieldreference : AMPERSAND LCASE_IDENT' + t[0] = t[2] + +# 8 Referencing definitions + +# 8.1 +def p_DefinedObjectClass (t): + 'DefinedObjectClass : UsefulObjectClassReference' + t[0] = t[1] + +# 8.4 +def p_UsefulObjectClassReference (t): + '''UsefulObjectClassReference : TYPE_IDENTIFIER + | ABSTRACT_SYNTAX''' + t[0] = t[1] + +# 9 Information object class definition and assignment + +# 9.14 +def p_FieldName (t): + '''FieldName : typefieldreference + | valuefieldreference''' + t[0] = t[1] + +# 14 Notation for the object class field type --------------------------------- + +# 14.1 +def p_ObjectClassFieldType (t): + 'ObjectClassFieldType : DefinedObjectClass DOT FieldName''' + t[0] = get_type_from_class(t[1], t[3]) + +object_class_types = { + 'TYPE-IDENTIFIER/id' : lambda : ObjectIdentifierType(), + 'TYPE-IDENTIFIER/Type' : lambda : OpenType(), + 'ABSTRACT-SYNTAX/id' : lambda : ObjectIdentifierType(), + 'ABSTRACT-SYNTAX/Type' : lambda : OpenType(), + 'ABSTRACT-SYNTAX/property' : lambda : BitStringType(), +} + +def get_type_from_class(cls, fld): + return object_class_types.get(cls + '/' + fld, lambda : AnyType())() #--- ITU-T Recommendation X.682 ----------------------------------------------- @@ -4487,17 +4600,17 @@ def p_number (t): # 8.1 def p_GeneralConstraint (t): - '''GeneralConstraint : UserDefinedConstraint''' + '''GeneralConstraint : UserDefinedConstraint''' # | TableConstraint # | ContentsConstraint'' - t[0] = t[1] + t[0] = t[1] # 9 User-defined constraints -------------------------------------------------- # 9.1 def p_UserDefinedConstraint (t): - 'UserDefinedConstraint : CONSTRAINED BY LBRACE UserDefinedConstraintParameterList RBRACE' - t[0] = Constraint(type = 'UserDefined', subtype = t[4]) + 'UserDefinedConstraint : CONSTRAINED BY LBRACE UserDefinedConstraintParameterList RBRACE' + t[0] = Constraint(type = 'UserDefined', subtype = t[4]) def p_UserDefinedConstraintParameterList_1 (t): 'UserDefinedConstraintParameterList : ' |