Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
asn1.h
1 /* asn1.h
2  * Common data for ASN.1
3  * 2007 Anders Broman
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11 
12 #ifndef __ASN1_H__
13 #define __ASN1_H__
14 
15 #include "ws_symbol_export.h"
16 
17 typedef enum {
18  ASN1_ENC_BER, /* X.690 - BER, CER, DER */
19  ASN1_ENC_PER, /* X.691 - PER */
20  ASN1_ENC_ECN, /* X.692 - ECN */
21  ASN1_ENC_XER /* X.693 - XER */
22 } asn1_enc_e;
23 
24 typedef enum {
25  CB_ASN1_ENC,
26  CB_NEW_DISSECTOR,
27  CB_DISSECTOR_HANDLE
28 } asn1_cb_variant;
29 
30 typedef enum {
31  ASN1_PAR_IRR, /* irrelevant parameter */
32  /* value */
33  ASN1_PAR_BOOLEAN,
34  ASN1_PAR_INTEGER,
35  /* type */
36  ASN1_PAR_TYPE
37 } asn1_par_type;
38 
39 typedef struct _asn1_par_def_t {
40  const gchar *name;
41  asn1_par_type ptype;
43 
44 typedef struct _asn1_par_t {
45  const gchar *name;
46  asn1_par_type ptype;
47  union {
48  gboolean v_boolean;
49  gint32 v_integer;
50  void *v_type;
51  } value;
52  struct _asn1_par_t *next;
53 } asn1_par_t;
54 
55 typedef struct _asn1_stack_frame_t {
56  const gchar *name;
57  struct _asn1_par_t *par;
58  struct _asn1_stack_frame_t *next;
60 
61 #define ASN1_CTX_SIGNATURE 0x41435458 /* "ACTX" */
62 
63 typedef struct _asn1_ctx_t {
64  guint32 signature;
65  asn1_enc_e encoding;
66  gboolean aligned;
67  packet_info *pinfo;
68  proto_item *created_item;
69  struct _asn1_stack_frame_t *stack;
70  void *value_ptr;
71  void *private_data;
72  struct {
73  int hf_index;
74  gboolean data_value_descr_present;
75  gboolean direct_ref_present;
76  gboolean indirect_ref_present;
77  tvbuff_t *data_value_descriptor;
78  const char *direct_reference;
79  gint32 indirect_reference;
80  gint encoding;
81  /*
82  0 : single-ASN1-type,
83  1 : octet-aligned,
84  2 : arbitrary
85  */
86  tvbuff_t *single_asn1_type;
87  tvbuff_t *octet_aligned;
88  tvbuff_t *arbitrary;
89  union {
90  struct {
91  int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index );
92  } ber;
93  struct {
94  int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int);
95  } per;
96  } u;
97  } external;
98  struct {
99  proto_tree *tree;
100  proto_tree *top_tree;
101  void* tree_ctx;
102  } subtree;
103  struct {
104  int hf_index;
105  gboolean data_value_descr_present;
106  tvbuff_t *data_value_descriptor;
107  gint identification;
108  /*
109  0 : syntaxes,
110  1 : syntax,
111  2 : presentation-context-id,
112  3 : context-negotiation,
113  4 : transfer-syntax,
114  5 : fixed
115  */
116  gint32 presentation_context_id;
117  const char *abstract_syntax;
118  const char *transfer_syntax;
119  tvbuff_t *data_value;
120  union {
121  struct {
122  int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index );
123  } ber;
124  struct {
125  int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int);
126  } per;
127  } u;
128  } embedded_pdv;
129  struct _rose_ctx_t *rose_ctx;
130 } asn1_ctx_t;
131 
132 #define ROSE_CTX_SIGNATURE 0x524F5345 /* "ROSE" */
133 
134 typedef struct _rose_ctx_t {
135  guint32 signature;
136  dissector_table_t arg_global_dissector_table;
137  dissector_table_t arg_local_dissector_table;
138  dissector_table_t res_global_dissector_table;
139  dissector_table_t res_local_dissector_table;
140  dissector_table_t err_global_dissector_table;
141  dissector_table_t err_local_dissector_table;
142  /* filling in description into tree, info column, any buffer */
143  int apdu_depth;
144  gboolean fillin_info;
145  gchar *fillin_ptr;
146  gsize fillin_buf_size;
147  struct { /* "dynamic" data */
148  gint pdu;
149  /*
150  1 : invoke,
151  2 : returnResult,
152  3 : returnError,
153  4 : reject
154  */
155  gint code;
156  /*
157  -1 : none (optional in ReturnResult)
158  0 : local,
159  1 : global
160  */
161  gint32 code_local;
162  const char *code_global;
163  proto_item *code_item;
164  } d;
165  void *private_data;
166 } rose_ctx_t;
167 
168 WS_DLL_PUBLIC void asn1_ctx_init(asn1_ctx_t *actx, asn1_enc_e encoding, gboolean aligned, packet_info *pinfo);
169 extern gboolean asn1_ctx_check_signature(asn1_ctx_t *actx);
170 extern void asn1_ctx_clean_external(asn1_ctx_t *actx);
171 extern void asn1_ctx_clean_epdv(asn1_ctx_t *actx);
172 
173 extern void asn1_stack_frame_push(asn1_ctx_t *actx, const gchar *name);
174 extern void asn1_stack_frame_pop(asn1_ctx_t *actx, const gchar *name);
175 extern void asn1_stack_frame_check(asn1_ctx_t *actx, const gchar *name, const asn1_par_def_t *par_def);
176 
177 extern void asn1_param_push_boolean(asn1_ctx_t *actx, gboolean value);
178 extern void asn1_param_push_integer(asn1_ctx_t *actx, gint32 value);
179 extern gboolean asn1_param_get_boolean(asn1_ctx_t *actx, const gchar *name);
180 extern gint32 asn1_param_get_integer(asn1_ctx_t *actx, const gchar *name);
181 
182 WS_DLL_PUBLIC void rose_ctx_init(rose_ctx_t *rctx);
183 extern gboolean rose_ctx_check_signature(rose_ctx_t *rctx);
184 WS_DLL_PUBLIC void rose_ctx_clean_data(rose_ctx_t *rctx);
185 
186 WS_DLL_PUBLIC asn1_ctx_t *get_asn1_ctx(void *ptr);
187 WS_DLL_PUBLIC rose_ctx_t *get_rose_ctx(void *ptr);
188 
189 extern double asn1_get_real(const guint8 *real_ptr, gint len);
190 
191 /* flags */
192 #define ASN1_EXT_ROOT 0x01
193 #define ASN1_EXT_EXT 0x02
194 #define ASN1_OPT 0x04
195 #define ASN1_DFLT 0x08
196 
197 #define ASN1_HAS_EXT(f) ((f)&(ASN1_EXT_ROOT|ASN1_EXT_EXT))
198 
199 
200 #endif /* __ASN1_H__ */
Definition: asn1.h:44
Definition: asn1.h:134
Definition: asn1.h:39
Definition: asn1.h:55
Definition: packet_info.h:44
Definition: tvbuff-int.h:35
Definition: asn1.h:63
Definition: packet.c:83
Definition: proto.h:759