Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
asn1.h
Go to the documentation of this file.
1
12#pragma once
13#include <epan/packet.h>
14#include "ws_symbol_export.h"
15
16typedef enum {
17 ASN1_ENC_BER, /* X.690 - BER, CER, DER */
18 ASN1_ENC_PER, /* X.691 - PER */
19 ASN1_ENC_ECN, /* X.692 - ECN */
20 ASN1_ENC_XER, /* X.693 - XER */
21 ASN1_ENC_OER /* X.696 - OER */
22} asn1_enc_e;
23
24typedef enum {
25 CB_ASN1_ENC,
26 CB_NEW_DISSECTOR,
27 CB_DISSECTOR_HANDLE
28} asn1_cb_variant;
29
30typedef 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
39typedef struct _asn1_par_def_t {
40 const char *name;
41 asn1_par_type ptype;
43
44typedef struct _asn1_par_t {
45 const char *name;
46 asn1_par_type ptype;
47 union {
48 bool v_boolean;
49 int32_t v_integer;
50 void *v_type;
51 } value;
52 struct _asn1_par_t *next;
54
55typedef struct _asn1_stack_frame_t {
56 const char *name;
57 struct _asn1_par_t *par;
58 struct _asn1_stack_frame_t *next;
60
61#define ASN1_CTX_SIGNATURE 0x41435458 /* "ACTX" */
62
63typedef struct _asn1_ctx_t {
64 uint32_t signature;
65 asn1_enc_e encoding;
66 bool 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 bool data_value_descr_present;
75 bool direct_ref_present;
76 bool indirect_ref_present;
77 tvbuff_t *data_value_descriptor;
78 const char *direct_reference;
79 int32_t indirect_reference;
80 int 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 unsigned (*ber_callback)(bool imp_tag, tvbuff_t *tvb, unsigned offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index );
92 } ber;
93 struct {
94 unsigned (*type_cb)(tvbuff_t*, uint32_t, 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 bool data_value_descr_present;
106 tvbuff_t *data_value_descriptor;
107 int 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 int32_t 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)(bool 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
134typedef struct _rose_ctx_t {
135 uint32_t 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 bool fillin_info;
145 char *fillin_ptr;
146 size_t fillin_buf_size;
147 struct { /* "dynamic" data */
148 int pdu;
149 /*
150 1 : invoke,
151 2 : returnResult,
152 3 : returnError,
153 4 : reject
154 */
155 int code;
156 /*
157 -1 : none (optional in ReturnResult)
158 0 : local,
159 1 : global
160 */
161 int32_t code_local;
162 const char *code_global;
163 proto_item *code_item;
164 } d;
165 void *private_data;
166} rose_ctx_t;
167
168WS_DLL_PUBLIC void asn1_ctx_init(asn1_ctx_t *actx, asn1_enc_e encoding, bool aligned, packet_info *pinfo);
169WS_DLL_PUBLIC bool asn1_ctx_check_signature(asn1_ctx_t *actx);
170WS_DLL_PUBLIC void asn1_ctx_clean_external(asn1_ctx_t *actx);
171extern void asn1_ctx_clean_epdv(asn1_ctx_t *actx);
172
173WS_DLL_PUBLIC void asn1_stack_frame_push(asn1_ctx_t *actx, const char *name);
174WS_DLL_PUBLIC void asn1_stack_frame_pop(asn1_ctx_t *actx, const char *name);
175WS_DLL_PUBLIC void asn1_stack_frame_check(asn1_ctx_t *actx, const char *name, const asn1_par_def_t *par_def);
176
177WS_DLL_PUBLIC void asn1_param_push_boolean(asn1_ctx_t *actx, bool value);
178WS_DLL_PUBLIC void asn1_param_push_integer(asn1_ctx_t *actx, int32_t value);
179extern bool asn1_param_get_boolean(asn1_ctx_t *actx, const char *name);
180WS_DLL_PUBLIC int32_t asn1_param_get_integer(asn1_ctx_t *actx, const char *name);
181
182WS_DLL_PUBLIC void rose_ctx_init(rose_ctx_t *rctx);
183extern bool rose_ctx_check_signature(rose_ctx_t *rctx);
184WS_DLL_PUBLIC void rose_ctx_clean_data(rose_ctx_t *rctx);
185
186WS_DLL_PUBLIC asn1_ctx_t *get_asn1_ctx(void *ptr);
187WS_DLL_PUBLIC rose_ctx_t *get_rose_ctx(void *ptr);
188
189/* Sets err to EINVAL for an invalid encoding (returning 0) to ERANGE if
190 * overflow or underflow occurs (rounding, possibly to +/-HUGE_VAL, +/-0.0),
191 * and 0 if conversion is successful. */
192WS_DLL_PUBLIC double asn1_get_real(const uint8_t *real_ptr, int len, int *err);
193
194/* flags */
195#define ASN1_EXT_ROOT 0x01
196#define ASN1_EXT_EXT 0x02
197#define ASN1_OPT 0x04
198#define ASN1_DFLT 0x08
199
200#define ASN1_HAS_EXT(f) ((f)&(ASN1_EXT_ROOT|ASN1_EXT_EXT))
Definition asn1.h:63
Definition asn1.h:39
Definition asn1.h:44
Definition asn1.h:55
Definition packet_info.h:40
Definition proto.h:902
Definition asn1.h:134
Definition packet.c:97
Definition tvbuff-int.h:33