few formal changes in PER dissector (rename asn_* types to asn1_* ones)
[obnox/wireshark/wip.git] / epan / dissectors / packet-per.h
1 /* packet-per.h
2  * Routines for dissection of ASN.1 Aligned PER
3  * 2003  Ronnie Sahlberg
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef __PACKET_PER_H__
27 #define __PACKET_PER_H__
28
29 /*--- ASN.1 Context, will be moved to common ASN.1 header when created --- */
30
31 typedef enum {
32   ASN1_ENC_BER,  /* X.690 - BER, CER, DER */
33   ASN1_ENC_PER,  /* X.691 - PER */
34   ASN1_ENC_ECN,  /* X.692 - ECN */
35   ASN1_ENC_XER   /* X.693 - XER */
36 } asn1_enc_e;
37
38 typedef struct _asn1_ctx_t {
39   asn1_enc_e encoding;
40   gboolean aligned;
41   packet_info *pinfo;
42   proto_item *created_item;
43   void *private_data;
44 } asn1_ctx_t;
45
46 void asn1_ctx_init(asn1_ctx_t *actx, asn1_enc_e encoding, gboolean aligned, packet_info *pinfo);
47
48 /* flags */
49 #define ASN1_EXT_ROOT 0x01
50 #define ASN1_EXT_EXT  0x02
51 #define ASN1_OPT      0x04
52 #define ASN1_DFLT     0x08
53
54 #define ASN1_HAS_EXT(f) ((f)&(ASN1_EXT_ROOT|ASN1_EXT_EXT))
55
56
57 /*----------------------------------*/
58
59
60 #define PER_NOT_DECODED_YET(x) \
61 proto_tree_add_text(tree, tvb, 0, 0, "something unknown here [%s]",x); \
62 fprintf(stderr,"[%s %u] Not decoded yet in packet : %d  [%s]\n", __FILE__, __LINE__, actx->pinfo->fd->num,x); \
63 if (check_col(actx->pinfo->cinfo, COL_INFO)){ \
64         col_append_fstr(actx->pinfo->cinfo, COL_INFO, "[UNKNOWN PER: %s]", x); \
65 } \
66 tvb_get_guint8(tvb, 9999);
67
68 typedef int (*per_type_fn)(tvbuff_t*, int, asn1_ctx_t*, proto_tree*, int);
69
70 /* in all functions here, offset is guint32 and is
71    byteposition<<3 + bitposition
72 */
73
74 /* value for value and size constraints */
75 #define NO_BOUND -1
76
77
78 /* values for extensions */
79 #define ASN1_NO_EXTENSIONS      0
80 #define ASN1_EXTENSION_ROOT         ASN1_EXT_ROOT
81 #define ASN1_NOT_EXTENSION_ROOT ASN1_EXT_EXT
82
83 /* value for optional */
84 #define ASN1_NOT_OPTIONAL       0
85 #define ASN1_OPTIONAL           ASN1_OPT
86
87 typedef struct _per_choice_t {
88         int value;
89         const int *p_id;
90         int extension;
91         per_type_fn func;
92 } per_choice_t;
93
94 typedef struct _per_sequence_t {
95         const int *p_id;
96         int extension;
97         int optional;
98         per_type_fn func;
99 } per_sequence_t;
100
101 extern guint32 dissect_per_length_determinant(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, guint32 *length);
102
103 extern guint32 dissect_per_null(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
104
105 extern guint32 dissect_per_GeneralString(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
106
107 extern guint32 dissect_per_sequence_of(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *parent_tree, int hf_index, gint ett_index, const per_sequence_t *seq);
108
109 extern guint32 dissect_per_IA5String(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len);
110
111 extern guint32 dissect_per_NumericString(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len);
112
113 extern guint32 dissect_per_PrintableString(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len);
114
115 extern guint32 dissect_per_VisibleString(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len);
116
117 extern guint32 dissect_per_BMPString(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len);
118
119 extern guint32 dissect_per_constrained_sequence_of(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *parent_tree, int hf_index, gint ett_index, const per_sequence_t *seq, int min_len, int max_len);
120
121 extern guint32 dissect_per_constrained_set_of(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *parent_tree, int hf_index, gint ett_index, const per_sequence_t *seq, int min_len, int max_len);
122
123 extern guint32 dissect_per_set_of(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *parent_tree, int hf_index, gint ett_index, const per_sequence_t *seq);
124
125 extern guint32 dissect_per_object_identifier(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, tvbuff_t **value_tvb);
126 extern guint32 dissect_per_object_identifier_str(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, const char **value_string);
127
128 extern guint32 dissect_per_boolean(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, gboolean *bool);
129
130 extern guint32 dissect_per_integer(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, gint32 *value);
131
132 extern guint32 dissect_per_constrained_integer(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, guint32 min, guint32 max, guint32 *value, gboolean has_extension);
133
134 extern guint32 dissect_per_choice(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, gint ett_index, const per_choice_t *choice, guint32 *value);
135
136 extern guint32 dissect_per_sequence(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *parent_tree, int hf_index, gint ett_index, const per_sequence_t *sequence);
137
138 extern guint32 dissect_per_octet_string(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len, tvbuff_t **value_tvb);
139
140 extern guint32 dissect_per_bit_string(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len, gboolean has_extension, tvbuff_t **value_tvb);
141
142 extern guint32 dissect_per_restricted_character_string(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, int min_len, int max_len, const char *alphabet, int alphabet_length, tvbuff_t **value_tvb);
143
144 extern guint32 dissect_per_enumerated(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, guint32 root_num, guint32 *value, gboolean has_extension, guint32 ext_num, guint32 *value_map);
145
146 extern guint32 dissect_per_open_type(tvbuff_t *tvb, guint32 offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index, per_type_fn type);
147
148 #endif  /* __PACKET_PER_H__ */