wsgcrypt.h checks internally if we HAVE_LIBGCRYPT
[metze/wireshark/wip.git] / epan / dissectors / packet-snmp.c
1 /* Do not modify this file. Changes will be overwritten.                      */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler       */
3 /* packet-snmp.c                                                              */
4 /* ../../tools/asn2wrs.py -b -p snmp -c ./snmp.cnf -s ./packet-snmp-template -D . -O ../../epan/dissectors snmp.asn */
5
6 /* Input file: packet-snmp-template.c */
7
8 #line 1 "../../asn1/snmp/packet-snmp-template.c"
9 /* packet-snmp.c
10  * Routines for SNMP (simple network management protocol)
11  * Copyright (C) 1998 Didier Jorand
12  *
13  * See RFC 1157 for SNMPv1.
14  *
15  * See RFCs 1901, 1905, and 1906 for SNMPv2c.
16  *
17  * See RFCs 1905, 1906, 1909, and 1910 for SNMPv2u [historic].
18  *
19  * See RFCs 2570-2576 for SNMPv3
20  * Updated to use the asn2wrs compiler made by Tomas Kukosa
21  * Copyright (C) 2005 - 2006 Anders Broman [AT] ericsson.com
22  *
23  * See RFC 3414 for User-based Security Model for SNMPv3
24  * See RFC 3826 for  (AES) Cipher Algorithm in the SNMP USM
25  * See RFC 2578 for Structure of Management Information Version 2 (SMIv2)
26  * Copyright (C) 2007 Luis E. Garcia Ontanon <luis@ontanon.org>
27  *
28  * Wireshark - Network traffic analyzer
29  * By Gerald Combs <gerald@wireshark.org>
30  * Copyright 1998 Gerald Combs
31  *
32  * Some stuff from:
33  *
34  * GXSNMP -- An snmp mangament application
35  * Copyright (C) 1998 Gregory McLean & Jochen Friedrich
36  * Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group
37  *
38  * This program is free software; you can redistribute it and/or
39  * modify it under the terms of the GNU General Public License
40  * as published by the Free Software Foundation; either version 2
41  * of the License, or (at your option) any later version.
42  *
43  * This program is distributed in the hope that it will be useful,
44  * but WITHOUT ANY WARRANTY; without even the implied warranty of
45  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46  * GNU General Public License for more details.
47  *
48  * You should have received a copy of the GNU General Public License
49  * along with this program; if not, write to the Free Software
50  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
51  */
52
53 #if 0
54 #include <stdio.h>
55 #define D(args) do {printf args; fflush(stdout); } while(0)
56 #endif
57
58 #include "config.h"
59
60 #include <epan/packet.h>
61 #include <epan/strutil.h>
62 #include <epan/conversation.h>
63 #include <epan/etypes.h>
64 #include <epan/prefs.h>
65 #include <epan/sminmpec.h>
66 #include <epan/next_tvb.h>
67 #include <epan/uat.h>
68 #include <epan/asn1.h>
69 #include <epan/expert.h>
70 #include <epan/oids.h>
71 #include <wsutil/sha1.h>
72 #include <wsutil/md5.h>
73 #include "packet-ipx.h"
74 #include "packet-hpext.h"
75 #include "packet-ber.h"
76 #include "packet-snmp.h"
77
78 #include <wsutil/wsgcrypt.h>
79
80 /* Take a pointer that may be null and return a pointer that's not null
81    by turning null pointers into pointers to the above null string,
82    and, if the argument pointer wasn't null, make sure we handle
83    non-printable characters in the string by escaping them. */
84 #define SAFE_STRING(s, l)       (((s) != NULL) ? format_text((s), (l)) : "")
85
86 #define PNAME  "Simple Network Management Protocol"
87 #define PSNAME "SNMP"
88 #define PFNAME "snmp"
89
90 #define UDP_PORT_SNMP           161
91 #define UDP_PORT_SNMP_TRAP      162
92 #define TCP_PORT_SNMP           161
93 #define TCP_PORT_SNMP_TRAP      162
94 #define TCP_PORT_SMUX           199
95 #define UDP_PORT_SNMP_PATROL 8161
96
97 /* Initialize the protocol and registered fields */
98 static int proto_snmp = -1;
99 static int proto_smux = -1;
100
101 static gboolean display_oid = TRUE;
102 static gboolean snmp_var_in_tree = TRUE;
103
104 void proto_register_snmp(void);
105 void proto_reg_handoff_snmp(void);
106 void proto_register_smux(void);
107 void proto_reg_handoff_smux(void);
108
109 static gboolean snmp_usm_auth_md5(snmp_usm_params_t* p, guint8**, guint*, gchar const**);
110 static gboolean snmp_usm_auth_sha1(snmp_usm_params_t* p, guint8**, guint*, gchar const**);
111
112 static tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t*, tvbuff_t*, gchar const**);
113 static tvbuff_t* snmp_usm_priv_aes128(snmp_usm_params_t*, tvbuff_t*, gchar const**);
114 static tvbuff_t* snmp_usm_priv_aes192(snmp_usm_params_t*, tvbuff_t*, gchar const**);
115 static tvbuff_t* snmp_usm_priv_aes256(snmp_usm_params_t*, tvbuff_t*, gchar const**);
116
117
118 static void snmp_usm_password_to_key_md5(const guint8 *password, guint passwordlen, const guint8 *engineID, guint engineLength, guint8 *key);
119 static void snmp_usm_password_to_key_sha1(const guint8 *password, guint passwordlen, const guint8 *engineID, guint engineLength, guint8 *key);
120
121
122 static snmp_usm_auth_model_t model_md5 = {snmp_usm_password_to_key_md5, snmp_usm_auth_md5, 16};
123 static snmp_usm_auth_model_t model_sha1 = {snmp_usm_password_to_key_sha1, snmp_usm_auth_sha1, SHA1_DIGEST_LEN};
124
125 static const value_string auth_types[] = {
126         {0,"MD5"},
127         {1,"SHA1"},
128         {0,NULL}
129 };
130 static snmp_usm_auth_model_t* auth_models[] = {&model_md5,&model_sha1};
131
132 #define PRIV_DES        0
133 #define PRIV_AES128     1
134 #define PRIV_AES192     2
135 #define PRIV_AES256     3
136
137 static const value_string priv_types[] = {
138         { PRIV_DES,    "DES" },
139         { PRIV_AES128, "AES" },
140         { PRIV_AES192, "AES192" },
141         { PRIV_AES256, "AES256" },
142         { 0, NULL}
143 };
144 static snmp_usm_decoder_t priv_protos[] = {
145         snmp_usm_priv_des,
146         snmp_usm_priv_aes128,
147         snmp_usm_priv_aes192,
148         snmp_usm_priv_aes256
149 };
150
151 static snmp_ue_assoc_t* ueas = NULL;
152 static guint num_ueas = 0;
153 static snmp_ue_assoc_t* localized_ues = NULL;
154 static snmp_ue_assoc_t* unlocalized_ues = NULL;
155 /****/
156
157 /* Variabled used for handling enterprise spesific trap types */
158 typedef struct _snmp_st_assoc_t {
159         char *enterprise;
160         guint trap;
161         char *desc;
162 } snmp_st_assoc_t;
163 static guint num_specific_traps = 0;
164 static snmp_st_assoc_t *specific_traps = NULL;
165 static const char *enterprise_oid = NULL;
166 static guint generic_trap = 0;
167 static guint32 snmp_version = 0;
168
169 static snmp_usm_params_t usm_p = {FALSE,FALSE,0,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,FALSE};
170
171 #define TH_AUTH   0x01
172 #define TH_CRYPT  0x02
173 #define TH_REPORT 0x04
174
175 /* desegmentation of SNMP-over-TCP */
176 static gboolean snmp_desegment = TRUE;
177
178 /* Global variables */
179
180 guint32 MsgSecurityModel;
181 tvbuff_t *oid_tvb=NULL;
182 tvbuff_t *value_tvb=NULL;
183
184 static dissector_handle_t snmp_handle;
185 static dissector_handle_t data_handle;
186
187 static next_tvb_list_t var_list;
188
189 static int hf_snmp_v3_flags_auth = -1;
190 static int hf_snmp_v3_flags_crypt = -1;
191 static int hf_snmp_v3_flags_report = -1;
192
193 static int hf_snmp_engineid_conform = -1;
194 static int hf_snmp_engineid_enterprise = -1;
195 static int hf_snmp_engineid_format = -1;
196 static int hf_snmp_engineid_ipv4 = -1;
197 static int hf_snmp_engineid_ipv6 = -1;
198 static int hf_snmp_engineid_cisco_type = -1;
199 static int hf_snmp_engineid_mac = -1;
200 static int hf_snmp_engineid_text = -1;
201 static int hf_snmp_engineid_time = -1;
202 static int hf_snmp_engineid_data = -1;
203 static int hf_snmp_decryptedPDU = -1;
204 static int hf_snmp_msgAuthentication = -1;
205
206 static int hf_snmp_noSuchObject = -1;
207 static int hf_snmp_noSuchInstance = -1;
208 static int hf_snmp_endOfMibView = -1;
209 static int hf_snmp_unSpecified = -1;
210
211 static int hf_snmp_integer32_value = -1;
212 static int hf_snmp_octetstring_value = -1;
213 static int hf_snmp_oid_value = -1;
214 static int hf_snmp_null_value = -1;
215 static int hf_snmp_ipv4_value = -1;
216 static int hf_snmp_ipv6_value = -1;
217 static int hf_snmp_anyaddress_value = -1;
218 static int hf_snmp_unsigned32_value = -1;
219 static int hf_snmp_unknown_value = -1;
220 static int hf_snmp_opaque_value = -1;
221 static int hf_snmp_nsap_value = -1;
222 static int hf_snmp_counter_value = -1;
223 static int hf_snmp_timeticks_value = -1;
224 static int hf_snmp_big_counter_value = -1;
225 static int hf_snmp_gauge32_value = -1;
226
227 static int hf_snmp_objectname = -1;
228 static int hf_snmp_scalar_instance_index = -1;
229
230 static int hf_snmp_var_bind_str = -1;
231 static int hf_snmp_agentid_trailer = -1;
232
233
234 /*--- Included file: packet-snmp-hf.c ---*/
235 #line 1 "../../asn1/snmp/packet-snmp-hf.c"
236 static int hf_snmp_SMUX_PDUs_PDU = -1;            /* SMUX_PDUs */
237 static int hf_snmp_version = -1;                  /* Version */
238 static int hf_snmp_community = -1;                /* Community */
239 static int hf_snmp_data = -1;                     /* PDUs */
240 static int hf_snmp_parameters = -1;               /* OCTET_STRING */
241 static int hf_snmp_datav2u = -1;                  /* T_datav2u */
242 static int hf_snmp_v2u_plaintext = -1;            /* PDUs */
243 static int hf_snmp_encrypted = -1;                /* OCTET_STRING */
244 static int hf_snmp_msgAuthoritativeEngineID = -1;  /* T_msgAuthoritativeEngineID */
245 static int hf_snmp_msgAuthoritativeEngineBoots = -1;  /* T_msgAuthoritativeEngineBoots */
246 static int hf_snmp_msgAuthoritativeEngineTime = -1;  /* T_msgAuthoritativeEngineTime */
247 static int hf_snmp_msgUserName = -1;              /* T_msgUserName */
248 static int hf_snmp_msgAuthenticationParameters = -1;  /* T_msgAuthenticationParameters */
249 static int hf_snmp_msgPrivacyParameters = -1;     /* T_msgPrivacyParameters */
250 static int hf_snmp_msgVersion = -1;               /* Version */
251 static int hf_snmp_msgGlobalData = -1;            /* HeaderData */
252 static int hf_snmp_msgSecurityParameters = -1;    /* T_msgSecurityParameters */
253 static int hf_snmp_msgData = -1;                  /* ScopedPduData */
254 static int hf_snmp_msgID = -1;                    /* INTEGER_0_2147483647 */
255 static int hf_snmp_msgMaxSize = -1;               /* INTEGER_484_2147483647 */
256 static int hf_snmp_msgFlags = -1;                 /* T_msgFlags */
257 static int hf_snmp_msgSecurityModel = -1;         /* T_msgSecurityModel */
258 static int hf_snmp_plaintext = -1;                /* ScopedPDU */
259 static int hf_snmp_encryptedPDU = -1;             /* T_encryptedPDU */
260 static int hf_snmp_contextEngineID = -1;          /* SnmpEngineID */
261 static int hf_snmp_contextName = -1;              /* OCTET_STRING */
262 static int hf_snmp_get_request = -1;              /* GetRequest_PDU */
263 static int hf_snmp_get_next_request = -1;         /* GetNextRequest_PDU */
264 static int hf_snmp_get_response = -1;             /* GetResponse_PDU */
265 static int hf_snmp_set_request = -1;              /* SetRequest_PDU */
266 static int hf_snmp_trap = -1;                     /* Trap_PDU */
267 static int hf_snmp_getBulkRequest = -1;           /* GetBulkRequest_PDU */
268 static int hf_snmp_informRequest = -1;            /* InformRequest_PDU */
269 static int hf_snmp_snmpV2_trap = -1;              /* SNMPv2_Trap_PDU */
270 static int hf_snmp_report = -1;                   /* Report_PDU */
271 static int hf_snmp_request_id = -1;               /* INTEGER */
272 static int hf_snmp_error_status = -1;             /* T_error_status */
273 static int hf_snmp_error_index = -1;              /* INTEGER */
274 static int hf_snmp_variable_bindings = -1;        /* VarBindList */
275 static int hf_snmp_bulkPDU_request_id = -1;       /* Integer32 */
276 static int hf_snmp_non_repeaters = -1;            /* INTEGER_0_2147483647 */
277 static int hf_snmp_max_repetitions = -1;          /* INTEGER_0_2147483647 */
278 static int hf_snmp_enterprise = -1;               /* EnterpriseOID */
279 static int hf_snmp_agent_addr = -1;               /* NetworkAddress */
280 static int hf_snmp_generic_trap = -1;             /* GenericTrap */
281 static int hf_snmp_specific_trap = -1;            /* SpecificTrap */
282 static int hf_snmp_time_stamp = -1;               /* TimeTicks */
283 static int hf_snmp_name = -1;                     /* ObjectName */
284 static int hf_snmp_valueType = -1;                /* NULL */
285 static int hf_snmp_VarBindList_item = -1;         /* VarBind */
286 static int hf_snmp_open = -1;                     /* OpenPDU */
287 static int hf_snmp_close = -1;                    /* ClosePDU */
288 static int hf_snmp_registerRequest = -1;          /* RReqPDU */
289 static int hf_snmp_registerResponse = -1;         /* RegisterResponse */
290 static int hf_snmp_commitOrRollback = -1;         /* SOutPDU */
291 static int hf_snmp_rRspPDU = -1;                  /* RRspPDU */
292 static int hf_snmp_pDUs = -1;                     /* PDUs */
293 static int hf_snmp_smux_simple = -1;              /* SimpleOpen */
294 static int hf_snmp_smux_version = -1;             /* T_smux_version */
295 static int hf_snmp_identity = -1;                 /* OBJECT_IDENTIFIER */
296 static int hf_snmp_description = -1;              /* DisplayString */
297 static int hf_snmp_password = -1;                 /* OCTET_STRING */
298 static int hf_snmp_subtree = -1;                  /* ObjectName */
299 static int hf_snmp_priority = -1;                 /* INTEGER_M1_2147483647 */
300 static int hf_snmp_operation = -1;                /* T_operation */
301
302 /*--- End of included file: packet-snmp-hf.c ---*/
303 #line 226 "../../asn1/snmp/packet-snmp-template.c"
304
305 /* Initialize the subtree pointers */
306 static gint ett_smux = -1;
307 static gint ett_snmp = -1;
308 static gint ett_engineid = -1;
309 static gint ett_msgFlags = -1;
310 static gint ett_encryptedPDU = -1;
311 static gint ett_decrypted = -1;
312 static gint ett_authParameters = -1;
313 static gint ett_internet = -1;
314 static gint ett_varbind = -1;
315 static gint ett_name = -1;
316 static gint ett_value = -1;
317 static gint ett_decoding_error = -1;
318
319
320 /*--- Included file: packet-snmp-ett.c ---*/
321 #line 1 "../../asn1/snmp/packet-snmp-ett.c"
322 static gint ett_snmp_Message = -1;
323 static gint ett_snmp_Messagev2u = -1;
324 static gint ett_snmp_T_datav2u = -1;
325 static gint ett_snmp_UsmSecurityParameters = -1;
326 static gint ett_snmp_SNMPv3Message = -1;
327 static gint ett_snmp_HeaderData = -1;
328 static gint ett_snmp_ScopedPduData = -1;
329 static gint ett_snmp_ScopedPDU = -1;
330 static gint ett_snmp_PDUs = -1;
331 static gint ett_snmp_PDU = -1;
332 static gint ett_snmp_BulkPDU = -1;
333 static gint ett_snmp_Trap_PDU_U = -1;
334 static gint ett_snmp_VarBind = -1;
335 static gint ett_snmp_VarBindList = -1;
336 static gint ett_snmp_SMUX_PDUs = -1;
337 static gint ett_snmp_RegisterResponse = -1;
338 static gint ett_snmp_OpenPDU = -1;
339 static gint ett_snmp_SimpleOpen_U = -1;
340 static gint ett_snmp_RReqPDU_U = -1;
341
342 /*--- End of included file: packet-snmp-ett.c ---*/
343 #line 242 "../../asn1/snmp/packet-snmp-template.c"
344
345 static expert_field ei_snmp_failed_decrypted_data_pdu = EI_INIT;
346 static expert_field ei_snmp_decrypted_data_bad_formatted = EI_INIT;
347 static expert_field ei_snmp_verify_authentication_error = EI_INIT;
348 static expert_field ei_snmp_authentication_ok = EI_INIT;
349 static expert_field ei_snmp_authentication_error = EI_INIT;
350 static expert_field ei_snmp_varbind_not_uni_class_seq = EI_INIT;
351 static expert_field ei_snmp_varbind_has_indicator = EI_INIT;
352 static expert_field ei_snmp_objectname_not_oid = EI_INIT;
353 static expert_field ei_snmp_objectname_has_indicator = EI_INIT;
354 static expert_field ei_snmp_value_not_primitive_encoding = EI_INIT;
355 static expert_field ei_snmp_invalid_oid = EI_INIT;
356 static expert_field ei_snmp_varbind_wrong_tag = EI_INIT;
357 static expert_field ei_snmp_varbind_response = EI_INIT;
358 static expert_field ei_snmp_no_instance_subid = EI_INIT;
359 static expert_field ei_snmp_wrong_num_of_subids = EI_INIT;
360 static expert_field ei_snmp_index_suboid_too_short = EI_INIT;
361 static expert_field ei_snmp_unimplemented_instance_index = EI_INIT;
362 static expert_field ei_snmp_index_suboid_len0 = EI_INIT;
363 static expert_field ei_snmp_index_suboid_too_long = EI_INIT;
364 static expert_field ei_snmp_index_string_too_long = EI_INIT;
365 static expert_field ei_snmp_column_parent_not_row = EI_INIT;
366 static expert_field ei_snmp_uint_too_large = EI_INIT;
367 static expert_field ei_snmp_int_too_large = EI_INIT;
368 static expert_field ei_snmp_integral_value0 = EI_INIT;
369 static expert_field ei_snmp_missing_mib = EI_INIT;
370 static expert_field ei_snmp_varbind_wrong_length_value = EI_INIT;
371 static expert_field ei_snmp_varbind_wrong_class_tag = EI_INIT;
372 static expert_field ei_snmp_rfc1910_non_conformant = EI_INIT;
373 static expert_field ei_snmp_rfc3411_non_conformant = EI_INIT;
374 static expert_field ei_snmp_version_unknown = EI_INIT;
375 static expert_field ei_snmp_trap_pdu_obsolete = EI_INIT;
376
377 static const true_false_string auth_flags = {
378         "OK",
379         "Failed"
380 };
381
382 /* Security Models */
383
384 #define SNMP_SEC_ANY                    0
385 #define SNMP_SEC_V1                     1
386 #define SNMP_SEC_V2C                    2
387 #define SNMP_SEC_USM                    3
388
389 static const value_string sec_models[] = {
390         { SNMP_SEC_ANY,                 "Any" },
391         { SNMP_SEC_V1,                  "V1" },
392         { SNMP_SEC_V2C,                 "V2C" },
393         { SNMP_SEC_USM,                 "USM" },
394         { 0,                            NULL }
395 };
396
397 #if 0
398 /* SMUX PDU types */
399 #define SMUX_MSG_OPEN           0
400 #define SMUX_MSG_CLOSE          1
401 #define SMUX_MSG_RREQ           2
402 #define SMUX_MSG_RRSP           3
403 #define SMUX_MSG_SOUT           4
404
405 static const value_string smux_types[] = {
406         { SMUX_MSG_OPEN,        "Open" },
407         { SMUX_MSG_CLOSE,       "Close" },
408         { SMUX_MSG_RREQ,        "Registration Request" },
409         { SMUX_MSG_RRSP,        "Registration Response" },
410         { SMUX_MSG_SOUT,        "Commit Or Rollback" },
411         { 0,                    NULL }
412 };
413 #endif
414
415
416 #define SNMP_IPA    0           /* IP Address */
417 #define SNMP_CNT    1           /* Counter (Counter32) */
418 #define SNMP_GGE    2           /* Gauge (Gauge32) */
419 #define SNMP_TIT    3           /* TimeTicks */
420 #define SNMP_OPQ    4           /* Opaque */
421 #define SNMP_NSP    5           /* NsapAddress */
422 #define SNMP_C64    6           /* Counter64 */
423 #define SNMP_U32    7           /* Uinteger32 */
424
425 #define SERR_NSO    0
426 #define SERR_NSI    1
427 #define SERR_EOM    2
428
429
430 dissector_table_t value_sub_dissectors_table;
431
432
433 static const gchar *
434 snmp_lookup_specific_trap (guint specific_trap)
435 {
436         guint i;
437
438         for (i = 0; i < num_specific_traps; i++) {
439                 snmp_st_assoc_t *u = &(specific_traps[i]);
440
441                 if ((u->trap == specific_trap) &&
442                     (strcmp (u->enterprise, enterprise_oid) == 0))
443                 {
444                         return u->desc;
445                 }
446         }
447
448         return NULL;
449 }
450
451 static int
452 dissect_snmp_variable_string(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void *data _U_)
453 {
454
455         proto_tree_add_item(tree, hf_snmp_var_bind_str, tvb, 0, -1, ENC_ASCII|ENC_NA);
456
457         return tvb_captured_length(tvb);
458 }
459
460 /*
461 DateAndTime ::= TEXTUAL-CONVENTION
462     DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"
463     STATUS       current
464     DESCRIPTION
465             "A date-time specification.
466
467             field  octets  contents                  range
468             -----  ------  --------                  -----
469               1      1-2   year*                     0..65536
470               2       3    month                     1..12
471               3       4    day                       1..31
472               4       5    hour                      0..23
473               5       6    minutes                   0..59
474               6       7    seconds                   0..60
475                            (use 60 for leap-second)
476               7       8    deci-seconds              0..9
477               8       9    direction from UTC        '+' / '-'
478               9      10    hours from UTC*           0..13
479              10      11    minutes from UTC          0..59
480
481             * Notes:
482             - the value of year is in network-byte order
483             - daylight saving time in New Zealand is +13
484
485             For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be
486             displayed as:
487
488                              1992-5-26,13:30:15.0,-4:0
489
490             Note that if only local time is known, then timezone
491             information (fields 8-10) is not present."
492     SYNTAX       OCTET STRING (SIZE (8 | 11))
493 */
494 static proto_item *
495 dissect_snmp_variable_date_and_time(proto_tree *tree,int hfid, tvbuff_t *tvb, int offset, int length)
496 {
497         guint16 year;
498         guint8 month;
499         guint8 day;
500         guint8 hour;
501         guint8 minutes;
502         guint8 seconds;
503         guint8 deci_seconds;
504         guint8 hour_from_utc;
505         guint8 min_from_utc;
506         gchar *str;
507
508         year                    = tvb_get_ntohs(tvb,offset);
509         month                   = tvb_get_guint8(tvb,offset+2);
510         day                     = tvb_get_guint8(tvb,offset+3);
511         hour                    = tvb_get_guint8(tvb,offset+4);
512         minutes                 = tvb_get_guint8(tvb,offset+5);
513         seconds                 = tvb_get_guint8(tvb,offset+6);
514         deci_seconds            = tvb_get_guint8(tvb,offset+7);
515         if(length > 8){
516                 hour_from_utc   = tvb_get_guint8(tvb,offset+9);
517                 min_from_utc    = tvb_get_guint8(tvb,offset+10);
518
519                 str = wmem_strdup_printf(wmem_packet_scope(),
520                          "%u-%u-%u, %u:%u:%u.%u UTC %s%u:%u",
521                          year,
522                          month,
523                          day,
524                          hour,
525                          minutes,
526                          seconds,
527                          deci_seconds,
528                          tvb_get_string_enc(wmem_packet_scope(),tvb,offset+8,1,ENC_ASCII|ENC_NA),
529                          hour_from_utc,
530                          min_from_utc);
531         }else{
532                  str = wmem_strdup_printf(wmem_packet_scope(),
533                          "%u-%u-%u, %u:%u:%u.%u",
534                          year,
535                          month,
536                          day,
537                          hour,
538                          minutes,
539                          seconds,
540                          deci_seconds);
541         }
542
543         return proto_tree_add_string(tree, hfid, tvb, offset, length, str);
544
545 }
546
547 /*
548  *  dissect_snmp_VarBind
549  *  this routine dissects variable bindings, looking for the oid information in our oid reporsitory
550  *  to format and add the value adequatelly.
551  *
552  * The choice to handwrite this code instead of using the asn compiler is to avoid having tons
553  * of uses of global variables distributed in very different parts of the code.
554  * Other than that there's a cosmetic thing: the tree from ASN generated code would be so
555  * convoluted due to the nesting of CHOICEs in the definition of VarBind/value.
556  *
557  * XXX: the length of this function (~400 lines) is an aberration!
558  *  oid_key_t:key_type could become a series of callbacks instead of an enum
559  *  the (! oid_info_is_ok) switch could be made into an array (would be slower)
560  *
561
562         NetworkAddress ::=  CHOICE { internet IpAddress }
563         IpAddress ::= [APPLICATION 0] IMPLICIT OCTET STRING (SIZE (4))
564         TimeTicks ::= [APPLICATION 3] IMPLICIT INTEGER (0..4294967295)
565         Integer32 ::= INTEGER (-2147483648..2147483647)
566         ObjectName ::= OBJECT IDENTIFIER
567         Counter32 ::= [APPLICATION 1] IMPLICIT INTEGER (0..4294967295)
568         Gauge32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)
569         Unsigned32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)
570         Integer-value ::=  INTEGER (-2147483648..2147483647)
571         Integer32 ::= INTEGER (-2147483648..2147483647)
572         ObjectID-value ::= OBJECT IDENTIFIER
573         Empty ::= NULL
574         TimeTicks ::= [APPLICATION 3] IMPLICIT INTEGER (0..4294967295)
575         Opaque ::= [APPLICATION 4] IMPLICIT OCTET STRING
576         Counter64 ::= [APPLICATION 6] IMPLICIT INTEGER (0..18446744073709551615)
577
578         ObjectSyntax ::= CHOICE {
579                  simple SimpleSyntax,
580                  application-wide ApplicationSyntax
581         }
582
583         SimpleSyntax ::= CHOICE {
584            integer-value Integer-value,
585            string-value String-value,
586            objectID-value ObjectID-value,
587            empty  Empty
588         }
589
590         ApplicationSyntax ::= CHOICE {
591            ipAddress-value IpAddress,
592            counter-value Counter32,
593            timeticks-value TimeTicks,
594            arbitrary-value Opaque,
595            big-counter-value Counter64,
596            unsigned-integer-value Unsigned32
597         }
598
599         ValueType ::=  CHOICE {
600            value ObjectSyntax,
601            unSpecified NULL,
602            noSuchObject[0] IMPLICIT NULL,
603            noSuchInstance[1] IMPLICIT NULL,
604            endOfMibView[2] IMPLICIT NULL
605         }
606
607         VarBind ::= SEQUENCE {
608            name ObjectName,
609            valueType ValueType
610         }
611
612  */
613
614 static int
615 dissect_snmp_VarBind(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,
616                      asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_)
617 {
618         int seq_offset, name_offset, value_offset, value_start;
619         guint32 seq_len, name_len, value_len;
620         gint8 ber_class;
621         gboolean pc;
622         gint32 tag;
623         gboolean ind;
624         guint32* subids;
625         guint8* oid_bytes;
626         oid_info_t* oid_info = NULL;
627         guint oid_matched, oid_left;
628         proto_item *pi_name, *pi_varbind, *pi_value = NULL;
629         proto_tree *pt, *pt_varbind, *pt_name, *pt_value;
630         char label[ITEM_LABEL_LENGTH];
631         const char* repr = NULL;
632         const char* info_oid = NULL;
633         char* valstr;
634         int hfid = -1;
635         int min_len = 0, max_len = 0;
636         gboolean oid_info_is_ok;
637         const char* oid_string = NULL;
638         enum {BER_NO_ERROR, BER_WRONG_LENGTH, BER_WRONG_TAG} format_error = BER_NO_ERROR;
639
640         seq_offset = offset;
641
642         /* first have the VarBind's sequence header */
643         offset = dissect_ber_identifier(actx->pinfo, tree, tvb, offset, &ber_class, &pc, &tag);
644         offset = dissect_ber_length(actx->pinfo, tree, tvb, offset, &seq_len, &ind);
645
646         if (!pc && ber_class==BER_CLASS_UNI && tag==BER_UNI_TAG_SEQUENCE) {
647                 proto_item* pi;
648                 pt = proto_tree_add_subtree(tree, tvb, seq_offset, seq_len + (offset - seq_offset),
649                                 ett_decoding_error, &pi, "VarBind must be an universal class sequence");
650                 expert_add_info(actx->pinfo, pi, &ei_snmp_varbind_not_uni_class_seq);
651                 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
652         }
653
654         if (ind) {
655                 proto_item* pi;
656                 pt = proto_tree_add_subtree(tree, tvb, seq_offset, seq_len + (offset - seq_offset),
657                                         ett_decoding_error, &pi, "Indicator must be clear in VarBind");
658                 expert_add_info(actx->pinfo, pi, &ei_snmp_varbind_has_indicator);
659                 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
660         }
661
662         /* we add the varbind tree root with a dummy label we'll fill later on */
663         pt_varbind = proto_tree_add_subtree(tree,tvb,offset,seq_len,ett_varbind,&pi_varbind,"VarBind");
664         *label = '\0';
665
666         seq_len += offset - seq_offset;
667
668         /* then we have the ObjectName's header */
669
670         offset = dissect_ber_identifier(actx->pinfo, pt_varbind, tvb, offset, &ber_class, &pc, &tag);
671         name_offset = offset = dissect_ber_length(actx->pinfo, pt_varbind, tvb, offset, &name_len, &ind);
672
673         if (! ( !pc && ber_class==BER_CLASS_UNI && tag==BER_UNI_TAG_OID) ) {
674                 proto_item* pi;
675                 pt = proto_tree_add_subtree(tree, tvb, seq_offset, seq_len,
676                                 ett_decoding_error, &pi, "ObjectName must be an OID in primitive encoding");
677                 expert_add_info(actx->pinfo, pi, &ei_snmp_objectname_not_oid);
678                 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
679         }
680
681         if (ind) {
682                 proto_item* pi;
683                 pt = proto_tree_add_subtree(tree, tvb, seq_offset, seq_len,
684                                 ett_decoding_error, &pi, "Indicator must be clear in ObjectName");
685                 expert_add_info(actx->pinfo, pi, &ei_snmp_objectname_has_indicator);
686                 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
687         }
688
689         pi_name = proto_tree_add_item(pt_varbind,hf_snmp_objectname,tvb,name_offset,name_len,ENC_NA);
690         pt_name = proto_item_add_subtree(pi_name,ett_name);
691
692         offset += name_len;
693         value_start = offset;
694         /* then we have the value's header */
695         offset = dissect_ber_identifier(actx->pinfo, pt_varbind, tvb, offset, &ber_class, &pc, &tag);
696         value_offset = dissect_ber_length(actx->pinfo, pt_varbind, tvb, offset, &value_len, &ind);
697
698         if (! (!pc) ) {
699                 proto_item* pi;
700                 pt = proto_tree_add_subtree(pt_varbind, tvb, value_start, value_len,
701                                 ett_decoding_error, &pi, "the value must be in primitive encoding");
702                 expert_add_info(actx->pinfo, pi, &ei_snmp_value_not_primitive_encoding);
703                 return dissect_unknown_ber(actx->pinfo, tvb, value_start, pt);
704         }
705
706         /* Now, we know where everithing is */
707
708         /* fetch ObjectName and its relative oid_info */
709         oid_bytes = (guint8*)tvb_memdup(wmem_packet_scope(), tvb, name_offset, name_len);
710         oid_info = oid_get_from_encoded(wmem_packet_scope(), oid_bytes, name_len, &subids, &oid_matched, &oid_left);
711
712         add_oid_debug_subtree(oid_info,pt_name);
713
714         if (!subids) {
715                 proto_item* pi;
716
717                 repr = oid_encoded2string(wmem_packet_scope(), oid_bytes, name_len);
718                 pt = proto_tree_add_subtree_format(pt_name,tvb, 0, 0, ett_decoding_error, &pi, "invalid oid: %s", repr);
719                 expert_add_info_format(actx->pinfo, pi, &ei_snmp_invalid_oid, "invalid oid: %s", repr);
720                 return dissect_unknown_ber(actx->pinfo, tvb, name_offset, pt);
721         }
722
723         if (oid_matched+oid_left) {
724                 oid_string = oid_subid2string(wmem_packet_scope(), subids,oid_matched+oid_left);
725         }
726
727         if (ber_class == BER_CLASS_CON) {
728                 /* if we have an error value just add it and get out the way ASAP */
729                 proto_item* pi;
730                 const char* note;
731
732                 if (value_len != 0) {
733                         min_len = max_len = 0;
734                         format_error = BER_WRONG_LENGTH;
735                 }
736
737                 switch (tag) {
738                         case SERR_NSO:
739                                 hfid = hf_snmp_noSuchObject;
740                                 note = "noSuchObject";
741                                 break;
742                         case SERR_NSI:
743                                 hfid = hf_snmp_noSuchInstance;
744                                 note = "noSuchInstance";
745                                 break;
746                         case SERR_EOM:
747                                 hfid = hf_snmp_endOfMibView;
748                                 note = "endOfMibView";
749                                 break;
750                         default: {
751                                 pt = proto_tree_add_subtree_format(pt_varbind,tvb,0,0,ett_decoding_error,&pi,
752                                                                 "Wrong tag for Error Value: expected 0, 1, or 2 but got: %d",tag);
753                                 expert_add_info(actx->pinfo, pi, &ei_snmp_varbind_wrong_tag);
754                                 return dissect_unknown_ber(actx->pinfo, tvb, value_start, pt);
755                         }
756                 }
757
758                 pi = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,ENC_BIG_ENDIAN);
759                 expert_add_info_format(actx->pinfo, pi, &ei_snmp_varbind_response, "%s",note);
760                 g_strlcpy (label, note, ITEM_LABEL_LENGTH);
761                 goto set_label;
762         }
763
764         /* now we'll try to figure out which are the indexing sub-oids and whether the oid we know about is the one oid we have to use */
765         switch (oid_info->kind) {
766                 case OID_KIND_SCALAR:
767                         if (oid_left == 1) {
768                                 /* OK: we got the instance sub-id */
769                                 proto_tree_add_uint64(pt_name,hf_snmp_scalar_instance_index,tvb,name_offset,name_len,subids[oid_matched]);
770                                 oid_info_is_ok = TRUE;
771                                 goto indexing_done;
772                         } else if (oid_left == 0) {
773                                 if (ber_class == BER_CLASS_UNI && tag == BER_UNI_TAG_NULL) {
774                                         /* unSpecified  does not require an instance sub-id add the new value and get off the way! */
775                                         pi_value = proto_tree_add_item(pt_varbind,hf_snmp_unSpecified,tvb,value_offset,value_len,ENC_NA);
776                                         goto set_label;
777                                 } else {
778                                         proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_no_instance_subid,tvb,0,0);
779                                         oid_info_is_ok = FALSE;
780                                         goto indexing_done;
781                                 }
782                         } else {
783                                 proto_tree_add_expert_format(pt_name,actx->pinfo,&ei_snmp_wrong_num_of_subids,tvb,0,0,"A scalar should have only one instance sub-id this has: %d",oid_left);
784                                 oid_info_is_ok = FALSE;
785                                 goto indexing_done;
786                         }
787                 break;
788                 case OID_KIND_COLUMN:
789                         if ( oid_info->parent->kind == OID_KIND_ROW) {
790                                 oid_key_t* k = oid_info->parent->key;
791                                 guint key_start = oid_matched;
792                                 guint key_len = oid_left;
793                                 oid_info_is_ok = TRUE;
794
795                                 if ( key_len == 0 && ber_class == BER_CLASS_UNI && tag == BER_UNI_TAG_NULL) {
796                                         /* unSpecified  does not require an instance sub-id add the new value and get off the way! */
797                                         pi_value = proto_tree_add_item(pt_varbind,hf_snmp_unSpecified,tvb,value_offset,value_len,ENC_NA);
798                                         goto set_label;
799                                 }
800
801                                 if (k) {
802                                         for (;k;k = k->next) {
803                                                 guint suboid_len;
804
805                                                 if (key_start >= oid_matched+oid_left) {
806                                                         proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_index_suboid_too_short,tvb,0,0);
807                                                         oid_info_is_ok = FALSE;
808                                                         goto indexing_done;
809                                                 }
810
811                                                 switch(k->key_type) {
812                                                         case OID_KEY_TYPE_WRONG: {
813                                                                 proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_unimplemented_instance_index,tvb,0,0);
814                                                                 oid_info_is_ok = FALSE;
815                                                                 goto indexing_done;
816                                                         }
817                                                         case OID_KEY_TYPE_INTEGER: {
818                                                                 if (IS_FT_INT(k->ft_type)) {
819                                                                         proto_tree_add_int(pt_name,k->hfid,tvb,name_offset,name_len,(guint)subids[key_start]);
820                                                                 } else { /* if it's not an unsigned int let proto_tree_add_uint throw a warning */
821                                                                         proto_tree_add_uint64(pt_name,k->hfid,tvb,name_offset,name_len,(guint)subids[key_start]);
822                                                                 }
823                                                                 key_start++;
824                                                                 key_len--;
825                                                                 continue; /* k->next */
826                                                         }
827                                                         case OID_KEY_TYPE_IMPLIED_OID:
828                                                                 suboid_len = key_len;
829
830                                                                 goto show_oid_index;
831
832                                                         case OID_KEY_TYPE_OID: {
833                                                                 guint8* suboid_buf;
834                                                                 guint suboid_buf_len;
835                                                                 guint32* suboid;
836
837                                                                 suboid_len = subids[key_start++];
838                                                                 key_len--;
839
840 show_oid_index:
841                                                                 suboid = &(subids[key_start]);
842
843                                                                 if( suboid_len == 0 ) {
844                                                                         proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_index_suboid_len0,tvb,0,0);
845                                                                         oid_info_is_ok = FALSE;
846                                                                         goto indexing_done;
847                                                                 }
848
849                                                                 if( key_len < suboid_len ) {
850                                                                         proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_index_suboid_too_long,tvb,0,0);
851                                                                         oid_info_is_ok = FALSE;
852                                                                         goto indexing_done;
853                                                                 }
854
855                                                                 suboid_buf_len = oid_subid2encoded(wmem_packet_scope(), suboid_len, suboid, &suboid_buf);
856
857                                                                 DISSECTOR_ASSERT(suboid_buf_len);
858
859                                                                 proto_tree_add_oid(pt_name,k->hfid,tvb,name_offset, suboid_buf_len, suboid_buf);
860
861                                                                 key_start += suboid_len;
862                                                                 key_len -= suboid_len + 1;
863                                                                 continue; /* k->next */
864                                                         }
865                                                         default: {
866                                                                 guint8* buf;
867                                                                 guint buf_len;
868                                                                 guint32* suboid;
869                                                                 guint i;
870
871
872                                                                 switch (k->key_type) {
873                                                                         case OID_KEY_TYPE_IPADDR:
874                                                                                 suboid = &(subids[key_start]);
875                                                                                 buf_len = 4;
876                                                                                 break;
877                                                                         case OID_KEY_TYPE_IMPLIED_STRING:
878                                                                         case OID_KEY_TYPE_IMPLIED_BYTES:
879                                                                         case OID_KEY_TYPE_ETHER:
880                                                                                 suboid = &(subids[key_start]);
881                                                                                 buf_len = key_len;
882                                                                                 break;
883                                                                         default:
884                                                                                 buf_len = k->num_subids;
885                                                                                 suboid = &(subids[key_start]);
886
887                                                                                 if(!buf_len) {
888                                                                                         buf_len = *suboid++;
889                                                                                         key_len--;
890                                                                                         key_start++;
891                                                                                 }
892                                                                                 break;
893                                                                 }
894
895                                                                 if( key_len < buf_len ) {
896                                                                         proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_index_string_too_long,tvb,0,0);
897                                                                         oid_info_is_ok = FALSE;
898                                                                         goto indexing_done;
899                                                                 }
900
901                                                                 buf = (guint8*)wmem_alloc(wmem_packet_scope(), buf_len+1);
902                                                                 for (i = 0; i < buf_len; i++)
903                                                                         buf[i] = (guint8)suboid[i];
904                                                                 buf[i] = '\0';
905
906                                                                 switch(k->key_type) {
907                                                                         case OID_KEY_TYPE_STRING:
908                                                                         case OID_KEY_TYPE_IMPLIED_STRING:
909                                                                                 proto_tree_add_string(pt_name,k->hfid,tvb,name_offset,buf_len, buf);
910                                                                                 break;
911                                                                         case OID_KEY_TYPE_BYTES:
912                                                                         case OID_KEY_TYPE_NSAP:
913                                                                         case OID_KEY_TYPE_IMPLIED_BYTES:
914                                                                                 proto_tree_add_bytes(pt_name,k->hfid,tvb,name_offset,buf_len, buf);
915                                                                                 break;
916                                                                         case OID_KEY_TYPE_ETHER:
917                                                                                 proto_tree_add_ether(pt_name,k->hfid,tvb,name_offset,buf_len, buf);
918                                                                                 break;
919                                                                         case OID_KEY_TYPE_IPADDR: {
920                                                                                 guint32* ipv4_p = (guint32*)buf;
921                                                                                 proto_tree_add_ipv4(pt_name,k->hfid,tvb,name_offset,buf_len, *ipv4_p);
922                                                                                 }
923                                                                                 break;
924                                                                         default:
925                                                                                 DISSECTOR_ASSERT_NOT_REACHED();
926                                                                                 break;
927                                                                 }
928
929                                                                 key_start += buf_len;
930                                                                 key_len -= buf_len;
931                                                                 continue; /* k->next*/
932                                                         }
933                                                 }
934                                         }
935                                         goto indexing_done;
936                                 } else {
937                                         proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_unimplemented_instance_index,tvb,0,0);
938                                         oid_info_is_ok = FALSE;
939                                         goto indexing_done;
940                                 }
941                         } else {
942                                 proto_tree_add_expert(pt_name,actx->pinfo,&ei_snmp_column_parent_not_row,tvb,0,0);
943                                 oid_info_is_ok = FALSE;
944                                 goto indexing_done;
945                         }
946                 default: {
947 /*                      proto_tree_add_expert (pt_name,actx->pinfo,PI_MALFORMED, PI_WARN,tvb,0,0,"This kind OID should have no value"); */
948                         oid_info_is_ok = FALSE;
949                         goto indexing_done;
950                 }
951         }
952 indexing_done:
953
954         if (oid_info_is_ok && oid_info->value_type) {
955                 if (ber_class == BER_CLASS_UNI && tag == BER_UNI_TAG_NULL) {
956                         pi_value = proto_tree_add_item(pt_varbind,hf_snmp_unSpecified,tvb,value_offset,value_len,ENC_NA);
957                 } else {
958                         /* Provide a tree_item to attach errors to, if needed. */
959                         pi_value = pi_name;
960
961                         if ((oid_info->value_type->ber_class != BER_CLASS_ANY) &&
962                                 (ber_class != oid_info->value_type->ber_class))
963                                 format_error = BER_WRONG_TAG;
964                         else if ((oid_info->value_type->ber_tag != BER_TAG_ANY) &&
965                                 (tag != oid_info->value_type->ber_tag))
966                                 format_error = BER_WRONG_TAG;
967                         else {
968                                 max_len = oid_info->value_type->max_len == -1 ? 0xffffff : oid_info->value_type->max_len;
969                                 min_len = oid_info->value_type->min_len;
970
971                                 if ((int)value_len < min_len || (int)value_len > max_len)
972                                         format_error = BER_WRONG_LENGTH;
973                         }
974
975                         if (format_error == BER_NO_ERROR)
976                                 pi_value = proto_tree_add_item(pt_varbind,oid_info->value_hfid,tvb,value_offset,value_len,ENC_BIG_ENDIAN);
977                 }
978         } else {
979                 switch(ber_class|(tag<<4)) {
980                         case BER_CLASS_UNI|(BER_UNI_TAG_INTEGER<<4):
981                         {
982                                 gint64 val=0;
983                                 unsigned int int_val_offset = value_offset;
984                                 unsigned int i;
985
986                                 max_len = 4; min_len = 1;
987                                 if (value_len > (guint)max_len || value_len < (guint)min_len) {
988                                         hfid = hf_snmp_integer32_value;
989                                         format_error = BER_WRONG_LENGTH;
990                                         break;
991                                 }
992
993                                 if(value_len > 0) {
994                                         /* extend sign bit */
995                                         if(tvb_get_guint8(tvb, int_val_offset)&0x80) {
996                                                 val=-1;
997                                         }
998                                         for(i=0;i<value_len;i++) {
999                                                 val=(val<<8)|tvb_get_guint8(tvb, int_val_offset);
1000                                                 int_val_offset++;
1001                                         }
1002                                 }
1003                                 proto_tree_add_int64(pt_varbind, hf_snmp_integer32_value, tvb,value_offset,value_len, val);
1004
1005                                 goto already_added;
1006                         }
1007                         case BER_CLASS_UNI|(BER_UNI_TAG_OCTETSTRING<<4):
1008                                 if(oid_info->value_hfid> -1){
1009                                         hfid = oid_info->value_hfid;
1010                                 }else{
1011                                         hfid = hf_snmp_octetstring_value;
1012                                 }
1013                                 break;
1014                         case BER_CLASS_UNI|(BER_UNI_TAG_OID<<4):
1015                                 max_len = -1; min_len = 1;
1016                                 if (value_len < (guint)min_len) format_error = BER_WRONG_LENGTH;
1017                                 hfid = hf_snmp_oid_value;
1018                                 break;
1019                         case BER_CLASS_UNI|(BER_UNI_TAG_NULL<<4):
1020                                 max_len = 0; min_len = 0;
1021                                 if (value_len != 0) format_error = BER_WRONG_LENGTH;
1022                                 hfid = hf_snmp_null_value;
1023                                 break;
1024                         case BER_CLASS_APP: /* | (SNMP_IPA<<4)*/
1025                                 switch(value_len) {
1026                                         case 4: hfid = hf_snmp_ipv4_value; break;
1027                                         case 16: hfid = hf_snmp_ipv6_value; break;
1028                                         default: hfid = hf_snmp_anyaddress_value; break;
1029                                 }
1030                                 break;
1031                         case BER_CLASS_APP|(SNMP_U32<<4):
1032                                 hfid = hf_snmp_unsigned32_value;
1033                                 break;
1034                         case BER_CLASS_APP|(SNMP_GGE<<4):
1035                                 hfid = hf_snmp_gauge32_value;
1036                                 break;
1037                         case BER_CLASS_APP|(SNMP_CNT<<4):
1038                                 hfid = hf_snmp_counter_value;
1039                                 break;
1040                         case BER_CLASS_APP|(SNMP_TIT<<4):
1041                                 hfid = hf_snmp_timeticks_value;
1042                                 break;
1043                         case BER_CLASS_APP|(SNMP_OPQ<<4):
1044                                 hfid = hf_snmp_opaque_value;
1045                                 break;
1046                         case BER_CLASS_APP|(SNMP_NSP<<4):
1047                                 hfid = hf_snmp_nsap_value;
1048                                 break;
1049                         case BER_CLASS_APP|(SNMP_C64<<4):
1050                                 hfid = hf_snmp_big_counter_value;
1051                                 break;
1052                         default:
1053                                 hfid = hf_snmp_unknown_value;
1054                                 break;
1055                 }
1056                 if (value_len > 8) {
1057                         /*
1058                          * Too long for an FT_UINT64 or an FT_INT64.
1059                          */
1060                         header_field_info *hfinfo = proto_registrar_get_nth(hfid);
1061                         if (hfinfo->type == FT_UINT64) {
1062                                 /*
1063                                  * Check if this is an unsigned int64 with
1064                                  * a big value.
1065                                  */
1066                                 if (value_len > 9 || tvb_get_guint8(tvb, value_offset) != 0) {
1067                                         /* It is.  Fail. */
1068                                         proto_tree_add_expert_format(pt_varbind,actx->pinfo,&ei_snmp_uint_too_large,tvb,value_offset,value_len,"Integral value too large");
1069                                         goto already_added;
1070                                 }
1071                                 /* Cheat and skip the leading 0 byte */
1072                                 value_len--;
1073                                 value_offset++;
1074                         } else if (hfinfo->type == FT_INT64) {
1075                                 /*
1076                                  * For now, just reject these.
1077                                  */
1078                                 proto_tree_add_expert_format(pt_varbind,actx->pinfo,&ei_snmp_int_too_large,tvb,value_offset,value_len,"Integral value too large or too small");
1079                                 goto already_added;
1080                         }
1081                 } else if (value_len == 0) {
1082                         /*
1083                          * X.690 section 8.3.1 "Encoding of an integer value":
1084                          * "The encoding of an integer value shall be
1085                          * primitive. The contents octets shall consist of
1086                          * one or more octets."
1087                          *
1088                          * Zero is not "one or more".
1089                          */
1090                         header_field_info *hfinfo = proto_registrar_get_nth(hfid);
1091                         if (hfinfo->type == FT_UINT64 || hfinfo->type == FT_INT64) {
1092                                 proto_tree_add_expert_format(pt_varbind,actx->pinfo,&ei_snmp_integral_value0,tvb,value_offset,value_len,"Integral value is zero-length");
1093                                 goto already_added;
1094                         }
1095                 }
1096                 /* Special case DATE AND TIME */
1097                 if((oid_info->value_type)&&(oid_info->value_type->keytype == OID_KEY_TYPE_DATE_AND_TIME)&&(value_len > 7)){
1098                         pi_value = dissect_snmp_variable_date_and_time(pt_varbind, hfid, tvb, value_offset, value_len);
1099                 }else{
1100                         pi_value = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,ENC_BIG_ENDIAN);
1101                 }
1102                 if (format_error != BER_NO_ERROR) {
1103                         expert_add_info(actx->pinfo, pi_value, &ei_snmp_missing_mib);
1104                 }
1105
1106         }
1107 already_added:
1108         pt_value = proto_item_add_subtree(pi_value,ett_value);
1109
1110         if (value_len > 0 && oid_string) {
1111                 tvbuff_t* sub_tvb = tvb_new_subset_length(tvb, value_offset, value_len);
1112
1113                 next_tvb_add_string(&var_list, sub_tvb, (snmp_var_in_tree) ? pt_value : NULL, value_sub_dissectors_table, oid_string);
1114         }
1115
1116
1117 set_label:
1118         if (pi_value) proto_item_fill_label(PITEM_FINFO(pi_value), label);
1119
1120         if (oid_info && oid_info->name) {
1121                 if (oid_left >= 1) {
1122                         repr = wmem_strdup_printf(wmem_packet_scope(), "%s.%s (%s)", oid_info->name,
1123                                                 oid_subid2string(wmem_packet_scope(), &(subids[oid_matched]),oid_left),
1124                                                 oid_subid2string(wmem_packet_scope(), subids,oid_matched+oid_left));
1125                         info_oid = wmem_strdup_printf(wmem_packet_scope(), "%s.%s", oid_info->name,
1126                                                 oid_subid2string(wmem_packet_scope(), &(subids[oid_matched]),oid_left));
1127                 } else {
1128                         repr = wmem_strdup_printf(wmem_packet_scope(), "%s (%s)", oid_info->name,
1129                                                 oid_subid2string(wmem_packet_scope(), subids,oid_matched));
1130                         info_oid = oid_info->name;
1131                 }
1132         } else if (oid_string) {
1133                 repr = wmem_strdup(wmem_packet_scope(), oid_string);
1134                 info_oid = oid_string;
1135         } else {
1136                 repr = wmem_strdup(wmem_packet_scope(), "[Bad OID]");
1137         }
1138
1139         valstr = strstr(label,": ");
1140         valstr = valstr ? valstr+2 : label;
1141
1142         proto_item_set_text(pi_varbind,"%s: %s",repr,valstr);
1143
1144         if (display_oid && info_oid) {
1145                 col_append_fstr (actx->pinfo->cinfo, COL_INFO, " %s", info_oid);
1146         }
1147
1148         switch (format_error) {
1149                 case BER_WRONG_LENGTH: {
1150                         proto_item* pi;
1151                         proto_tree* p_tree = proto_item_add_subtree(pi_value,ett_decoding_error);
1152                         pt = proto_tree_add_subtree_format(p_tree,tvb,0,0,ett_decoding_error,&pi,
1153                                                              "Wrong value length: %u  expecting: %u <= len <= %u",
1154                                                              value_len, min_len, max_len == -1 ? 0xFFFFFF : max_len);
1155                         expert_add_info(actx->pinfo, pi, &ei_snmp_varbind_wrong_length_value);
1156                         return dissect_unknown_ber(actx->pinfo, tvb, value_start, pt);
1157                 }
1158                 case BER_WRONG_TAG: {
1159                         proto_item* pi;
1160                         proto_tree* p_tree = proto_item_add_subtree(pi_value,ett_decoding_error);
1161                         pt = proto_tree_add_subtree_format(p_tree,tvb,0,0,ett_decoding_error,&pi,
1162                                                              "Wrong class/tag for Value expected: %d,%d got: %d,%d",
1163                                                              oid_info->value_type->ber_class, oid_info->value_type->ber_tag,
1164                                                              ber_class, tag);
1165                         expert_add_info(actx->pinfo, pi, &ei_snmp_varbind_wrong_class_tag);
1166                         return dissect_unknown_ber(actx->pinfo, tvb, value_start, pt);
1167                 }
1168                 default:
1169                         break;
1170         }
1171
1172         return seq_offset + seq_len;
1173 }
1174
1175
1176 #define F_SNMP_ENGINEID_CONFORM 0x80
1177 #define SNMP_ENGINEID_RFC1910 0x00
1178 #define SNMP_ENGINEID_RFC3411 0x01
1179
1180 static const true_false_string tfs_snmp_engineid_conform = {
1181         "RFC3411 (SNMPv3)",
1182         "RFC1910 (Non-SNMPv3)"
1183 };
1184
1185 #define SNMP_ENGINEID_FORMAT_IPV4 0x01
1186 #define SNMP_ENGINEID_FORMAT_IPV6 0x02
1187 #define SNMP_ENGINEID_FORMAT_MACADDRESS 0x03
1188 #define SNMP_ENGINEID_FORMAT_TEXT 0x04
1189 #define SNMP_ENGINEID_FORMAT_OCTETS 0x05
1190
1191 static const value_string snmp_engineid_format_vals[] = {
1192         { SNMP_ENGINEID_FORMAT_IPV4,    "IPv4 address" },
1193         { SNMP_ENGINEID_FORMAT_IPV6,    "IPv6 address" },
1194         { SNMP_ENGINEID_FORMAT_MACADDRESS,      "MAC address" },
1195         { SNMP_ENGINEID_FORMAT_TEXT,    "Text, administratively assigned" },
1196         { SNMP_ENGINEID_FORMAT_OCTETS,  "Octets, administratively assigned" },
1197         { 0,    NULL }
1198 };
1199
1200 #define SNMP_ENGINEID_CISCO_AGENT 0x00
1201 #define SNMP_ENGINEID_CISCO_MANAGER 0x01
1202
1203 static const value_string snmp_engineid_cisco_type_vals[] = {
1204         { SNMP_ENGINEID_CISCO_AGENT,    "Agent" },
1205         { SNMP_ENGINEID_CISCO_MANAGER,  "Manager" },
1206         { 0,    NULL }
1207 };
1208
1209 /*
1210  * SNMP Engine ID dissection according to RFC 3411 (SnmpEngineID TC)
1211  * or historic RFC 1910 (AgentID)
1212  */
1213 int
1214 dissect_snmp_engineid(proto_tree *tree, packet_info *pinfo, tvbuff_t *tvb, int offset, int len)
1215 {
1216         proto_item *item = NULL;
1217         guint8 conformance, format;
1218         guint32 enterpriseid, seconds;
1219         nstime_t ts;
1220         int len_remain = len;
1221
1222         /* first bit: engine id conformance */
1223         if (len_remain<1) return offset;
1224         conformance = ((tvb_get_guint8(tvb, offset)>>7) & 0x01);
1225         proto_tree_add_item(tree, hf_snmp_engineid_conform, tvb, offset, 1, ENC_BIG_ENDIAN);
1226
1227         /* 4-byte enterprise number/name */
1228         if (len_remain<4) return offset;
1229         enterpriseid = tvb_get_ntohl(tvb, offset);
1230         if (conformance)
1231                 enterpriseid -= 0x80000000; /* ignore first bit */
1232         proto_tree_add_uint(tree, hf_snmp_engineid_enterprise, tvb, offset, 4, enterpriseid);
1233         offset+=4;
1234         len_remain-=4;
1235
1236         switch(conformance) {
1237
1238         case SNMP_ENGINEID_RFC1910:
1239                 /* 12-byte AgentID w/ 8-byte trailer */
1240                 if (len_remain==8) {
1241                         proto_tree_add_item(tree, hf_snmp_agentid_trailer, tvb, offset, 8, ENC_NA);
1242                         offset+=8;
1243                         len_remain-=8;
1244                 } else {
1245                         proto_tree_add_expert(tree, pinfo, &ei_snmp_rfc1910_non_conformant, tvb, offset, len_remain);
1246                         return offset;
1247                 }
1248                 break;
1249
1250         case SNMP_ENGINEID_RFC3411: /* variable length: 5..32 */
1251
1252                 /* 1-byte format specifier */
1253                 if (len_remain<1) return offset;
1254                 format = tvb_get_guint8(tvb, offset);
1255                 item = proto_tree_add_uint_format(tree, hf_snmp_engineid_format, tvb, offset, 1, format, "Engine ID Format: %s (%d)",
1256                                                   val_to_str(format, snmp_engineid_format_vals, "Reserved/Enterprise-specific"), format);
1257                 offset+=1;
1258                 len_remain-=1;
1259
1260                 switch(format) {
1261                 case SNMP_ENGINEID_FORMAT_IPV4:
1262                         /* 4-byte IPv4 address */
1263                         if (len_remain==4) {
1264                                 proto_tree_add_item(tree, hf_snmp_engineid_ipv4, tvb, offset, 4, ENC_BIG_ENDIAN);
1265                                 offset+=4;
1266                                 len_remain=0;
1267                         }
1268                         break;
1269                 case SNMP_ENGINEID_FORMAT_IPV6:
1270                         /* 16-byte IPv6 address */
1271                         if (len_remain==16) {
1272                                 proto_tree_add_item(tree, hf_snmp_engineid_ipv6, tvb, offset, 16, ENC_NA);
1273                                 offset+=16;
1274                                 len_remain=0;
1275                         }
1276                         break;
1277                 case SNMP_ENGINEID_FORMAT_MACADDRESS:
1278                         /* See: https://supportforums.cisco.com/message/3010617#3010617 for details. */
1279                         if ((enterpriseid==9)&&(len_remain==7)) {
1280                                 proto_tree_add_item(tree, hf_snmp_engineid_cisco_type, tvb, offset, 1, ENC_BIG_ENDIAN);
1281                                 offset++;
1282                                 len_remain--;
1283                         }
1284                         /* 6-byte MAC address */
1285                         if (len_remain==6) {
1286                                 proto_tree_add_item(tree, hf_snmp_engineid_mac, tvb, offset, 6, ENC_NA);
1287                                 offset+=6;
1288                                 len_remain=0;
1289                         }
1290                         break;
1291                 case SNMP_ENGINEID_FORMAT_TEXT:
1292                         /* max. 27-byte string, administratively assigned */
1293                         if (len_remain<=27) {
1294                                 proto_tree_add_item(tree, hf_snmp_engineid_text, tvb, offset, len_remain, ENC_ASCII|ENC_NA);
1295                                 offset+=len_remain;
1296                                 len_remain=0;
1297                         }
1298                         break;
1299                 case 128:
1300                         /* most common enterprise-specific format: (ucd|net)-snmp random */
1301                         if ((enterpriseid==2021)||(enterpriseid==8072)) {
1302                                 proto_item_append_text(item, (enterpriseid==2021) ? ": UCD-SNMP Random" : ": Net-SNMP Random");
1303                                 /* demystify: 4B random, 4B epoch seconds */
1304                                 if (len_remain==8) {
1305                                         proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, 4, ENC_NA);
1306                                         seconds = tvb_get_letohl(tvb, offset+4);
1307                                         ts.secs = seconds;
1308                                         ts.nsecs = 0;
1309                                         proto_tree_add_time_format_value(tree, hf_snmp_engineid_time, tvb, offset+4, 4,
1310                                                                          &ts, "%s",
1311                                                                          abs_time_secs_to_str(wmem_packet_scope(), seconds, ABSOLUTE_TIME_LOCAL, TRUE));
1312                                         offset+=8;
1313                                         len_remain=0;
1314                                 }
1315                         break;
1316                         }
1317                 /* fall through */
1318                 case SNMP_ENGINEID_FORMAT_OCTETS:
1319                 default:
1320                         /* max. 27 bytes, administratively assigned or unknown format */
1321                         if (len_remain<=27) {
1322                                 proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, len_remain, ENC_NA);
1323                                 offset+=len_remain;
1324                                 len_remain=0;
1325                         }
1326                 break;
1327                 }
1328         }
1329
1330         if (len_remain>0) {
1331                 proto_tree_add_expert(tree, pinfo, &ei_snmp_rfc3411_non_conformant, tvb, offset, len_remain);
1332                 offset+=len_remain;
1333         }
1334         return offset;
1335 }
1336
1337
1338 static void set_ue_keys(snmp_ue_assoc_t* n ) {
1339         guint key_size = n->user.authModel->key_size;
1340
1341         n->user.authKey.data = (guint8 *)g_malloc(key_size);
1342         n->user.authKey.len = key_size;
1343         n->user.authModel->pass2key(n->user.authPassword.data,
1344                                     n->user.authPassword.len,
1345                                     n->engine.data,
1346                                     n->engine.len,
1347                                     n->user.authKey.data);
1348
1349         if (n->priv_proto == PRIV_AES128 || n->priv_proto == PRIV_AES192 || n->priv_proto == PRIV_AES256) {
1350                 guint need_key_len =
1351                         (n->priv_proto == PRIV_AES128) ? 16 :
1352                         (n->priv_proto == PRIV_AES192) ? 24 :
1353                         (n->priv_proto == PRIV_AES256) ? 32 :
1354                         0;
1355
1356                 guint key_len = key_size;
1357
1358                 while (key_len < need_key_len)
1359                         key_len += key_size;
1360
1361                 n->user.privKey.data = (guint8 *)g_malloc(key_len);
1362                 n->user.privKey.len  = need_key_len;
1363
1364                 n->user.authModel->pass2key(n->user.privPassword.data,
1365                                             n->user.privPassword.len,
1366                                             n->engine.data,
1367                                             n->engine.len,
1368                                             n->user.privKey.data);
1369
1370                 key_len = key_size;
1371
1372                 /* extend key if needed */
1373                 while (key_len < need_key_len) {
1374                         n->user.authModel->pass2key(
1375                                 n->user.privKey.data,
1376                                 key_len,
1377                                 n->engine.data,
1378                                 n->engine.len,
1379                                 n->user.privKey.data + key_len);
1380
1381                         key_len += key_size;
1382                 }
1383
1384         } else {
1385                 n->user.privKey.data = (guint8 *)g_malloc(key_size);
1386                 n->user.privKey.len = key_size;
1387                 n->user.authModel->pass2key(n->user.privPassword.data,
1388                                             n->user.privPassword.len,
1389                                             n->engine.data,
1390                                             n->engine.len,
1391                                             n->user.privKey.data);
1392         }
1393 }
1394
1395 static snmp_ue_assoc_t*
1396 ue_dup(snmp_ue_assoc_t* o)
1397 {
1398         snmp_ue_assoc_t* d = (snmp_ue_assoc_t*)g_memdup(o,sizeof(snmp_ue_assoc_t));
1399
1400         d->user.authModel = o->user.authModel;
1401
1402         d->user.privProtocol = o->user.privProtocol;
1403
1404         d->user.userName.data = (guint8 *)g_memdup(o->user.userName.data,o->user.userName.len);
1405         d->user.userName.len = o->user.userName.len;
1406
1407         d->user.authPassword.data = o->user.authPassword.data ? (guint8 *)g_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL;
1408         d->user.authPassword.len = o->user.authPassword.len;
1409
1410         d->user.privPassword.data = o->user.privPassword.data ? (guint8 *)g_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL;
1411         d->user.privPassword.len = o->user.privPassword.len;
1412
1413         d->engine.len = o->engine.len;
1414
1415         if (d->engine.len) {
1416                 d->engine.data = (guint8 *)g_memdup(o->engine.data,o->engine.len);
1417                 set_ue_keys(d);
1418         }
1419
1420         return d;
1421
1422 }
1423
1424 static void*
1425 snmp_users_copy_cb(void* dest, const void* orig, size_t len _U_)
1426 {
1427         const snmp_ue_assoc_t* o = (const snmp_ue_assoc_t*)orig;
1428         snmp_ue_assoc_t* d = (snmp_ue_assoc_t*)dest;
1429
1430         d->auth_model = o->auth_model;
1431         d->user.authModel = auth_models[o->auth_model];
1432
1433         d->priv_proto = o->priv_proto;
1434         d->user.privProtocol = priv_protos[o->priv_proto];
1435
1436         d->user.userName.data = (guint8*)g_memdup(o->user.userName.data,o->user.userName.len);
1437         d->user.userName.len = o->user.userName.len;
1438
1439         d->user.authPassword.data = o->user.authPassword.data ? (guint8*)g_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL;
1440         d->user.authPassword.len = o->user.authPassword.len;
1441
1442         d->user.privPassword.data = o->user.privPassword.data ? (guint8*)g_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL;
1443         d->user.privPassword.len = o->user.privPassword.len;
1444
1445         d->engine.len = o->engine.len;
1446         if (o->engine.data) {
1447                 d->engine.data = (guint8*)g_memdup(o->engine.data,o->engine.len);
1448         }
1449
1450         d->user.authKey.data = o->user.authKey.data ? (guint8*)g_memdup(o->user.authKey.data,o->user.authKey.len) : NULL;
1451         d->user.authKey.len = o->user.authKey.len;
1452
1453         d->user.privKey.data = o->user.privKey.data ? (guint8*)g_memdup(o->user.privKey.data,o->user.privKey.len) : NULL;
1454         d->user.privKey.len = o->user.privKey.len;
1455
1456         return d;
1457 }
1458
1459 static void
1460 snmp_users_free_cb(void* p)
1461 {
1462         snmp_ue_assoc_t* ue = (snmp_ue_assoc_t*)p;
1463         g_free(ue->user.userName.data);
1464         g_free(ue->user.authPassword.data);
1465         g_free(ue->user.privPassword.data);
1466         g_free(ue->user.authKey.data);
1467         g_free(ue->user.privKey.data);
1468         g_free(ue->engine.data);
1469 }
1470
1471 static gboolean
1472 snmp_users_update_cb(void* p _U_, char** err)
1473 {
1474         snmp_ue_assoc_t* ue = (snmp_ue_assoc_t*)p;
1475         GString* es = g_string_new("");
1476         unsigned int i;
1477
1478         *err = NULL;
1479
1480         if (num_ueas == 0)
1481                 /* Nothing to update */
1482                 return FALSE;
1483
1484         if (! ue->user.userName.len)
1485                 g_string_append_printf(es,"no userName\n");
1486
1487         for (i=0; i<num_ueas-1; i++) {
1488                 snmp_ue_assoc_t* u = &(ueas[i]);
1489
1490                 /* RFC 3411 section 5 */
1491                 if ((u->engine.len > 0) && (u->engine.len < 5 || u->engine.len > 32)) {
1492                         g_string_append_printf(es, "Invalid engineId length (%u). Must be between 5 and 32 (10 and 64 hex digits)\n", u->engine.len);
1493                 }
1494
1495
1496                 if ( u->user.userName.len == ue->user.userName.len
1497                         && u->engine.len == ue->engine.len && (u != ue)) {
1498
1499                         if (u->engine.len > 0 && memcmp( u->engine.data, ue->engine.data, u->engine.len ) == 0) {
1500                                 if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
1501                                         /* XXX: make a string for the engineId */
1502                                         g_string_append_printf(es,"Duplicate key (userName='%s')\n",ue->user.userName.data);
1503                                 }
1504                         }
1505
1506                         if (u->engine.len == 0) {
1507                                 if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
1508                                         g_string_append_printf(es,"Duplicate key (userName='%s' engineId=NONE)\n",ue->user.userName.data);
1509                                 }
1510                         }
1511                 }
1512         }
1513
1514         if (es->len) {
1515                 es = g_string_truncate(es,es->len-1);
1516                 *err = g_string_free(es, FALSE);
1517                 return FALSE;
1518         }
1519
1520         return TRUE;
1521 }
1522
1523 static void
1524 free_ue_cache(snmp_ue_assoc_t **cache)
1525 {
1526         static snmp_ue_assoc_t *a, *nxt;
1527
1528         for (a = *cache; a; a = nxt) {
1529                 nxt = a->next;
1530                 snmp_users_free_cb(a);
1531                 g_free(a);
1532         }
1533
1534         *cache = NULL;
1535 }
1536
1537 #define CACHE_INSERT(c,a) if (c) { snmp_ue_assoc_t* t = c; c = a; c->next = t; } else { c = a; a->next = NULL; }
1538
1539 static void
1540 init_ue_cache(void)
1541 {
1542         guint i;
1543
1544         for (i = 0; i < num_ueas; i++) {
1545                 snmp_ue_assoc_t* a = ue_dup(&(ueas[i]));
1546
1547                 if (a->engine.len) {
1548                         CACHE_INSERT(localized_ues,a);
1549
1550                 } else {
1551                         CACHE_INSERT(unlocalized_ues,a);
1552                 }
1553
1554         }
1555 }
1556
1557 static void
1558 cleanup_ue_cache(void)
1559 {
1560         free_ue_cache(&localized_ues);
1561         free_ue_cache(&unlocalized_ues);
1562 }
1563
1564 /* Called when the user applies changes to UAT preferences. */
1565 static void
1566 renew_ue_cache(void)
1567 {
1568         cleanup_ue_cache();
1569         init_ue_cache();
1570 }
1571
1572
1573 static snmp_ue_assoc_t*
1574 localize_ue( snmp_ue_assoc_t* o, const guint8* engine, guint engine_len )
1575 {
1576         snmp_ue_assoc_t* n = (snmp_ue_assoc_t*)g_memdup(o,sizeof(snmp_ue_assoc_t));
1577
1578         n->engine.data = (guint8*)g_memdup(engine,engine_len);
1579         n->engine.len = engine_len;
1580
1581         set_ue_keys(n);
1582
1583         return n;
1584 }
1585
1586
1587 #define localized_match(a,u,ul,e,el) \
1588         ( a->user.userName.len == ul \
1589         && a->engine.len == el \
1590         && memcmp( a->user.userName.data, u, ul ) == 0 \
1591         && memcmp( a->engine.data,   e,  el ) == 0 )
1592
1593 #define unlocalized_match(a,u,l) \
1594         ( a->user.userName.len == l && memcmp( a->user.userName.data, u, l) == 0 )
1595
1596 static snmp_ue_assoc_t*
1597 get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb)
1598 {
1599         static snmp_ue_assoc_t* a;
1600         guint given_username_len;
1601         guint8* given_username;
1602         guint given_engine_len;
1603         guint8* given_engine;
1604
1605         if ( ! (localized_ues || unlocalized_ues ) ) return NULL;
1606
1607         if (! ( user_tvb && engine_tvb ) ) return NULL;
1608
1609         given_username_len = tvb_captured_length(user_tvb);
1610         given_engine_len = tvb_captured_length(engine_tvb);
1611         if (! ( given_engine_len && given_username_len ) ) return NULL;
1612         given_username = (guint8*)tvb_memdup(wmem_packet_scope(),user_tvb,0,-1);
1613         given_engine = (guint8*)tvb_memdup(wmem_packet_scope(),engine_tvb,0,-1);
1614
1615         for (a = localized_ues; a; a = a->next) {
1616                 if ( localized_match(a, given_username, given_username_len, given_engine, given_engine_len) ) {
1617                         return a;
1618                 }
1619         }
1620
1621         for (a = unlocalized_ues; a; a = a->next) {
1622                 if ( unlocalized_match(a, given_username, given_username_len) ) {
1623                         snmp_ue_assoc_t* n = localize_ue( a, given_engine, given_engine_len );
1624                         CACHE_INSERT(localized_ues,n);
1625                         return n;
1626                 }
1627         }
1628
1629         return NULL;
1630 }
1631
1632 static gboolean
1633 snmp_usm_auth_md5(snmp_usm_params_t* p, guint8** calc_auth_p, guint* calc_auth_len_p, gchar const** error)
1634 {
1635         gint msg_len;
1636         guint8* msg;
1637         guint auth_len;
1638         guint8* auth;
1639         guint8* key;
1640         guint key_len;
1641         guint8 *calc_auth;
1642         guint start;
1643         guint end;
1644         guint i;
1645
1646         if (!p->auth_tvb) {
1647                 *error = "No Authenticator";
1648                 return FALSE;
1649         }
1650
1651         key = p->user_assoc->user.authKey.data;
1652         key_len = p->user_assoc->user.authKey.len;
1653
1654         if (! key ) {
1655                 *error = "User has no authKey";
1656                 return FALSE;
1657         }
1658
1659
1660         auth_len = tvb_captured_length(p->auth_tvb);
1661
1662         if (auth_len != 12) {
1663                 *error = "Authenticator length wrong";
1664                 return FALSE;
1665         }
1666
1667         msg_len = tvb_captured_length(p->msg_tvb);
1668         if (msg_len <= 0) {
1669                 *error = "Not enough data remaining";
1670                 return FALSE;
1671         }
1672         msg = (guint8*)tvb_memdup(wmem_packet_scope(),p->msg_tvb,0,msg_len);
1673
1674
1675         auth = (guint8*)tvb_memdup(wmem_packet_scope(),p->auth_tvb,0,auth_len);
1676
1677         start = p->auth_offset - p->start_offset;
1678         end =   start + auth_len;
1679
1680         /* fill the authenticator with zeros */
1681         for ( i = start ; i < end ; i++ ) {
1682                 msg[i] = '\0';
1683         }
1684
1685         calc_auth = (guint8*)wmem_alloc(wmem_packet_scope(), 16);
1686
1687         md5_hmac(msg, msg_len, key, key_len, calc_auth);
1688
1689         if (calc_auth_p) *calc_auth_p = calc_auth;
1690         if (calc_auth_len_p) *calc_auth_len_p = 12;
1691
1692         return ( memcmp(auth,calc_auth,12) != 0 ) ? FALSE : TRUE;
1693 }
1694
1695
1696 static gboolean
1697 snmp_usm_auth_sha1(snmp_usm_params_t* p _U_, guint8** calc_auth_p, guint* calc_auth_len_p, gchar const** error _U_)
1698 {
1699         gint msg_len;
1700         guint8* msg;
1701         guint auth_len;
1702         guint8* auth;
1703         guint8* key;
1704         guint key_len;
1705         guint8 *calc_auth;
1706         guint start;
1707         guint end;
1708         guint i;
1709
1710         if (!p->auth_tvb) {
1711                 *error = "No Authenticator";
1712                 return FALSE;
1713         }
1714
1715         key = p->user_assoc->user.authKey.data;
1716         key_len = p->user_assoc->user.authKey.len;
1717
1718         if (! key ) {
1719                 *error = "User has no authKey";
1720                 return FALSE;
1721         }
1722
1723
1724         auth_len = tvb_captured_length(p->auth_tvb);
1725
1726
1727         if (auth_len != 12) {
1728                 *error = "Authenticator length wrong";
1729                 return FALSE;
1730         }
1731
1732         msg_len = tvb_captured_length(p->msg_tvb);
1733         if (msg_len <= 0) {
1734                 *error = "Not enough data remaining";
1735                 return FALSE;
1736         }
1737         msg = (guint8*)tvb_memdup(wmem_packet_scope(),p->msg_tvb,0,msg_len);
1738
1739         auth = (guint8*)tvb_memdup(wmem_packet_scope(),p->auth_tvb,0,auth_len);
1740
1741         start = p->auth_offset - p->start_offset;
1742         end =   start + auth_len;
1743
1744         /* fill the authenticator with zeros */
1745         for ( i = start ; i < end ; i++ ) {
1746                 msg[i] = '\0';
1747         }
1748
1749         calc_auth = (guint8*)wmem_alloc(wmem_packet_scope(), SHA1_DIGEST_LEN);
1750
1751         sha1_hmac(key, key_len, msg, msg_len, calc_auth);
1752
1753         if (calc_auth_p) *calc_auth_p = calc_auth;
1754         if (calc_auth_len_p) *calc_auth_len_p = 12;
1755
1756         return ( memcmp(auth,calc_auth,12) != 0 ) ? FALSE : TRUE;
1757 }
1758
1759 static tvbuff_t*
1760 snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U_, gchar const** error _U_)
1761 {
1762 #ifdef HAVE_LIBGCRYPT
1763         gcry_error_t err;
1764         gcry_cipher_hd_t hd = NULL;
1765
1766         guint8* cleartext;
1767         guint8* des_key = p->user_assoc->user.privKey.data; /* first 8 bytes */
1768         guint8* pre_iv = &(p->user_assoc->user.privKey.data[8]); /* last 8 bytes */
1769         guint8* salt;
1770         gint salt_len;
1771         gint cryptgrm_len;
1772         guint8* cryptgrm;
1773         tvbuff_t* clear_tvb;
1774         guint8 iv[8];
1775         guint i;
1776
1777
1778         salt_len = tvb_captured_length(p->priv_tvb);
1779
1780         if (salt_len != 8) {
1781                 *error = "decryptionError: msgPrivacyParameters length != 8";
1782                 return NULL;
1783         }
1784
1785         salt = (guint8*)tvb_memdup(wmem_packet_scope(),p->priv_tvb,0,salt_len);
1786
1787         /*
1788          The resulting "salt" is XOR-ed with the pre-IV to obtain the IV.
1789          */
1790         for (i=0; i<8; i++) {
1791                 iv[i] = pre_iv[i] ^ salt[i];
1792         }
1793
1794         cryptgrm_len = tvb_captured_length(encryptedData);
1795
1796         if ((cryptgrm_len <= 0) || (cryptgrm_len % 8)) {
1797                 *error = "decryptionError: the length of the encrypted data is not a mutiple of 8 octets";
1798                 return NULL;
1799         }
1800
1801         cryptgrm = (guint8*)tvb_memdup(wmem_packet_scope(),encryptedData,0,-1);
1802
1803         cleartext = (guint8*)g_malloc(cryptgrm_len);
1804
1805         err = gcry_cipher_open(&hd, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_CBC, 0);
1806         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1807
1808         err = gcry_cipher_setiv(hd, iv, 8);
1809         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1810
1811         err = gcry_cipher_setkey(hd,des_key,8);
1812         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1813
1814         err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len);
1815         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1816
1817         gcry_cipher_close(hd);
1818
1819         clear_tvb = tvb_new_child_real_data(encryptedData, cleartext, cryptgrm_len, cryptgrm_len);
1820         tvb_set_free_cb(clear_tvb, g_free);
1821
1822         return clear_tvb;
1823
1824 on_gcry_error:
1825         g_free(cleartext);
1826         *error = (const gchar *)gpg_strerror(err);
1827         if (hd) gcry_cipher_close(hd);
1828         return NULL;
1829 #else
1830         *error = "libgcrypt not present, cannot decrypt";
1831         return NULL;
1832 #endif
1833 }
1834
1835 #ifdef HAVE_LIBGCRYPT
1836 static tvbuff_t*
1837 snmp_usm_priv_aes_common(snmp_usm_params_t* p, tvbuff_t* encryptedData, gchar const** error, int algo)
1838 {
1839         gcry_error_t err;
1840         gcry_cipher_hd_t hd = NULL;
1841
1842         guint8* cleartext;
1843         guint8* aes_key = p->user_assoc->user.privKey.data;
1844         int aes_key_len = p->user_assoc->user.privKey.len;
1845         guint8 iv[16];
1846         gint priv_len;
1847         gint cryptgrm_len;
1848         guint8* cryptgrm;
1849         tvbuff_t* clear_tvb;
1850
1851         priv_len = tvb_captured_length(p->priv_tvb);
1852
1853         if (priv_len != 8) {
1854                 *error = "decryptionError: msgPrivacyParameters length != 8";
1855                 return NULL;
1856         }
1857
1858         iv[0] = (p->boots & 0xff000000) >> 24;
1859         iv[1] = (p->boots & 0x00ff0000) >> 16;
1860         iv[2] = (p->boots & 0x0000ff00) >> 8;
1861         iv[3] = (p->boots & 0x000000ff);
1862         iv[4] = (p->snmp_time & 0xff000000) >> 24;
1863         iv[5] = (p->snmp_time & 0x00ff0000) >> 16;
1864         iv[6] = (p->snmp_time & 0x0000ff00) >> 8;
1865         iv[7] = (p->snmp_time & 0x000000ff);
1866         tvb_memcpy(p->priv_tvb,&(iv[8]),0,8);
1867
1868         cryptgrm_len = tvb_captured_length(encryptedData);
1869         if (cryptgrm_len <= 0) {
1870                 *error = "Not enough data remaining";
1871                 return NULL;
1872         }
1873         cryptgrm = (guint8*)tvb_memdup(wmem_packet_scope(),encryptedData,0,-1);
1874
1875         cleartext = (guint8*)g_malloc(cryptgrm_len);
1876
1877         err = gcry_cipher_open(&hd, algo, GCRY_CIPHER_MODE_CFB, 0);
1878         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1879
1880         err = gcry_cipher_setiv(hd, iv, 16);
1881         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1882
1883         err = gcry_cipher_setkey(hd,aes_key,aes_key_len);
1884         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1885
1886         err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len);
1887         if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1888
1889         gcry_cipher_close(hd);
1890
1891         clear_tvb = tvb_new_child_real_data(encryptedData, cleartext, cryptgrm_len, cryptgrm_len);
1892         tvb_set_free_cb(clear_tvb, g_free);
1893
1894         return clear_tvb;
1895
1896 on_gcry_error:
1897         g_free(cleartext);
1898         *error = (const gchar *)gpg_strerror(err);
1899         if (hd) gcry_cipher_close(hd);
1900         return NULL;
1901 }
1902 #endif
1903
1904 static tvbuff_t*
1905 snmp_usm_priv_aes128(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U_, gchar const** error)
1906 {
1907 #ifdef HAVE_LIBGCRYPT
1908         return snmp_usm_priv_aes_common(p, encryptedData, error, GCRY_CIPHER_AES);
1909 #else
1910         *error = "libgcrypt not present, cannot decrypt";
1911         return NULL;
1912 #endif
1913 }
1914
1915 static tvbuff_t*
1916 snmp_usm_priv_aes192(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U_, gchar const** error)
1917 {
1918 #ifdef HAVE_LIBGCRYPT
1919         return snmp_usm_priv_aes_common(p, encryptedData, error, GCRY_CIPHER_AES192);
1920 #else
1921         *error = "libgcrypt not present, cannot decrypt";
1922         return NULL;
1923 #endif
1924 }
1925
1926 static tvbuff_t*
1927 snmp_usm_priv_aes256(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U_, gchar const** error)
1928 {
1929 #ifdef HAVE_LIBGCRYPT
1930         return snmp_usm_priv_aes_common(p, encryptedData, error, GCRY_CIPHER_AES256);
1931 #else
1932         *error = "libgcrypt not present, cannot decrypt";
1933         return NULL;
1934 #endif
1935 }
1936
1937 static gboolean
1938 check_ScopedPdu(tvbuff_t* tvb)
1939 {
1940         int offset;
1941         gint8 ber_class;
1942         gboolean pc;
1943         gint32 tag;
1944         int hoffset, eoffset;
1945         guint32 len;
1946
1947         offset = get_ber_identifier(tvb, 0, &ber_class, &pc, &tag);
1948         offset = get_ber_length(tvb, offset, NULL, NULL);
1949
1950         if ( ! (((ber_class!=BER_CLASS_APP) && (ber_class!=BER_CLASS_PRI) )
1951                         && ( (!pc) || (ber_class!=BER_CLASS_UNI) || (tag!=BER_UNI_TAG_ENUMERATED) )
1952                         )) return FALSE;
1953
1954         if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0))
1955                 return TRUE;
1956
1957         hoffset = offset;
1958
1959         offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
1960         offset = get_ber_length(tvb, offset, &len, NULL);
1961         eoffset = offset + len;
1962
1963         if (eoffset <= hoffset) return FALSE;
1964
1965         if ((ber_class!=BER_CLASS_APP)&&(ber_class!=BER_CLASS_PRI))
1966                 if( (ber_class!=BER_CLASS_UNI)
1967                         ||((tag<BER_UNI_TAG_NumericString)&&(tag!=BER_UNI_TAG_OCTETSTRING)&&(tag!=BER_UNI_TAG_UTF8String)) )
1968                         return FALSE;
1969
1970         return TRUE;
1971
1972 }
1973
1974
1975 /*--- Included file: packet-snmp-fn.c ---*/
1976 #line 1 "../../asn1/snmp/packet-snmp-fn.c"
1977
1978
1979
1980 static int
1981 dissect_snmp_EnterpriseOID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1982 #line 68 "../../asn1/snmp/snmp.cnf"
1983         const gchar* name;
1984
1985   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &enterprise_oid);
1986
1987
1988         if (display_oid && enterprise_oid) {
1989                 name = oid_resolved_from_string(wmem_packet_scope(), enterprise_oid);
1990                 if (name) {
1991                 col_append_fstr (actx->pinfo->cinfo, COL_INFO, " %s", name);
1992                 }
1993         }
1994
1995
1996
1997   return offset;
1998 }
1999
2000
2001
2002 static int
2003 dissect_snmp_OCTET_STRING_SIZE_4(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2004   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2005                                        NULL);
2006
2007   return offset;
2008 }
2009
2010
2011
2012 static int
2013 dissect_snmp_NetworkAddress(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2014   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2015                                       hf_index, BER_CLASS_APP, 0, TRUE, dissect_snmp_OCTET_STRING_SIZE_4);
2016
2017   return offset;
2018 }
2019
2020
2021
2022 static int
2023 dissect_snmp_INTEGER_0_4294967295(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2024   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2025                                                 NULL);
2026
2027   return offset;
2028 }
2029
2030
2031
2032 static int
2033 dissect_snmp_TimeTicks(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2034   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2035                                       hf_index, BER_CLASS_APP, 3, TRUE, dissect_snmp_INTEGER_0_4294967295);
2036
2037   return offset;
2038 }
2039
2040
2041
2042 static int
2043 dissect_snmp_Integer32(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2044   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2045                                                 NULL);
2046
2047   return offset;
2048 }
2049
2050
2051
2052 static int
2053 dissect_snmp_ObjectName(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2054   offset = dissect_ber_object_identifier(implicit_tag, actx, tree, tvb, offset, hf_index, NULL);
2055
2056   return offset;
2057 }
2058
2059
2060 static const value_string snmp_Version_vals[] = {
2061   {   0, "version-1" },
2062   {   1, "v2c" },
2063   {   2, "v2u" },
2064   {   3, "snmpv3" },
2065   { 0, NULL }
2066 };
2067
2068
2069 static int
2070 dissect_snmp_Version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2071   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2072                                                 &snmp_version);
2073
2074   return offset;
2075 }
2076
2077
2078
2079 static int
2080 dissect_snmp_Community(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2081   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2082                                        NULL);
2083
2084   return offset;
2085 }
2086
2087
2088
2089 static int
2090 dissect_snmp_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2091   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2092                                                 NULL);
2093
2094   return offset;
2095 }
2096
2097
2098 static const value_string snmp_T_error_status_vals[] = {
2099   {   0, "noError" },
2100   {   1, "tooBig" },
2101   {   2, "noSuchName" },
2102   {   3, "badValue" },
2103   {   4, "readOnly" },
2104   {   5, "genErr" },
2105   {   6, "noAccess" },
2106   {   7, "wrongType" },
2107   {   8, "wrongLength" },
2108   {   9, "wrongEncoding" },
2109   {  10, "wrongValue" },
2110   {  11, "noCreation" },
2111   {  12, "inconsistentValue" },
2112   {  13, "resourceUnavailable" },
2113   {  14, "commitFailed" },
2114   {  15, "undoFailed" },
2115   {  16, "authorizationError" },
2116   {  17, "notWritable" },
2117   {  18, "inconsistentName" },
2118   { 0, NULL }
2119 };
2120
2121
2122 static int
2123 dissect_snmp_T_error_status(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2124   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2125                                                 NULL);
2126
2127   return offset;
2128 }
2129
2130
2131
2132 static int
2133 dissect_snmp_NULL(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2134   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
2135
2136   return offset;
2137 }
2138
2139
2140
2141 static const ber_sequence_t VarBindList_sequence_of[1] = {
2142   { &hf_snmp_VarBindList_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBind },
2143 };
2144
2145 static int
2146 dissect_snmp_VarBindList(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2147   offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
2148                                       VarBindList_sequence_of, hf_index, ett_snmp_VarBindList);
2149
2150   return offset;
2151 }
2152
2153
2154 static const ber_sequence_t PDU_sequence[] = {
2155   { &hf_snmp_request_id     , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER },
2156   { &hf_snmp_error_status   , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_error_status },
2157   { &hf_snmp_error_index    , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER },
2158   { &hf_snmp_variable_bindings, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBindList },
2159   { NULL, 0, 0, 0, NULL }
2160 };
2161
2162 static int
2163 dissect_snmp_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2164   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2165                                    PDU_sequence, hf_index, ett_snmp_PDU);
2166
2167   return offset;
2168 }
2169
2170
2171
2172 static int
2173 dissect_snmp_GetRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2174   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2175                                       hf_index, BER_CLASS_CON, 0, TRUE, dissect_snmp_PDU);
2176
2177   return offset;
2178 }
2179
2180
2181
2182 static int
2183 dissect_snmp_GetNextRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2184   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2185                                       hf_index, BER_CLASS_CON, 1, TRUE, dissect_snmp_PDU);
2186
2187   return offset;
2188 }
2189
2190
2191
2192 static int
2193 dissect_snmp_GetResponse_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2194   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2195                                       hf_index, BER_CLASS_CON, 2, TRUE, dissect_snmp_PDU);
2196
2197   return offset;
2198 }
2199
2200
2201
2202 static int
2203 dissect_snmp_SetRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2204   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2205                                       hf_index, BER_CLASS_CON, 3, TRUE, dissect_snmp_PDU);
2206
2207   return offset;
2208 }
2209
2210
2211 static const value_string snmp_GenericTrap_vals[] = {
2212   {   0, "coldStart" },
2213   {   1, "warmStart" },
2214   {   2, "linkDown" },
2215   {   3, "linkUp" },
2216   {   4, "authenticationFailure" },
2217   {   5, "egpNeighborLoss" },
2218   {   6, "enterpriseSpecific" },
2219   { 0, NULL }
2220 };
2221
2222
2223 static int
2224 dissect_snmp_GenericTrap(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2225   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2226                                                 &generic_trap);
2227
2228   return offset;
2229 }
2230
2231
2232
2233 static int
2234 dissect_snmp_SpecificTrap(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2235 #line 52 "../../asn1/snmp/snmp.cnf"
2236   guint specific_trap;
2237
2238   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2239                                                 &specific_trap);
2240
2241
2242         if (generic_trap == 6) { /* enterprise specific */
2243                 const gchar *specific_str = snmp_lookup_specific_trap (specific_trap);
2244                 if (specific_str) {
2245                 proto_item_append_text(actx->created_item, " (%s)", specific_str);
2246                 }
2247         }
2248
2249
2250   return offset;
2251 }
2252
2253
2254 static const ber_sequence_t Trap_PDU_U_sequence[] = {
2255   { &hf_snmp_enterprise     , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_snmp_EnterpriseOID },
2256   { &hf_snmp_agent_addr     , BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_snmp_NetworkAddress },
2257   { &hf_snmp_generic_trap   , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_GenericTrap },
2258   { &hf_snmp_specific_trap  , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_SpecificTrap },
2259   { &hf_snmp_time_stamp     , BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_snmp_TimeTicks },
2260   { &hf_snmp_variable_bindings, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBindList },
2261   { NULL, 0, 0, 0, NULL }
2262 };
2263
2264 static int
2265 dissect_snmp_Trap_PDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2266 #line 40 "../../asn1/snmp/snmp.cnf"
2267         generic_trap = 0;
2268         enterprise_oid = NULL;
2269
2270   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2271                                    Trap_PDU_U_sequence, hf_index, ett_snmp_Trap_PDU_U);
2272
2273
2274   if (snmp_version != 0) {
2275     expert_add_info(actx->pinfo, tree, &ei_snmp_trap_pdu_obsolete);
2276   }
2277
2278
2279
2280   return offset;
2281 }
2282
2283
2284
2285 static int
2286 dissect_snmp_Trap_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2287   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2288                                       hf_index, BER_CLASS_CON, 4, TRUE, dissect_snmp_Trap_PDU_U);
2289
2290   return offset;
2291 }
2292
2293
2294
2295 static int
2296 dissect_snmp_INTEGER_0_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2297   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2298                                                 NULL);
2299
2300   return offset;
2301 }
2302
2303
2304 static const ber_sequence_t BulkPDU_sequence[] = {
2305   { &hf_snmp_bulkPDU_request_id, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Integer32 },
2306   { &hf_snmp_non_repeaters  , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_0_2147483647 },
2307   { &hf_snmp_max_repetitions, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_0_2147483647 },
2308   { &hf_snmp_variable_bindings, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBindList },
2309   { NULL, 0, 0, 0, NULL }
2310 };
2311
2312 static int
2313 dissect_snmp_BulkPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2314   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2315                                    BulkPDU_sequence, hf_index, ett_snmp_BulkPDU);
2316
2317   return offset;
2318 }
2319
2320
2321
2322 static int
2323 dissect_snmp_GetBulkRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2324   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2325                                       hf_index, BER_CLASS_CON, 5, TRUE, dissect_snmp_BulkPDU);
2326
2327   return offset;
2328 }
2329
2330
2331
2332 static int
2333 dissect_snmp_InformRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2334   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2335                                       hf_index, BER_CLASS_CON, 6, TRUE, dissect_snmp_PDU);
2336
2337   return offset;
2338 }
2339
2340
2341
2342 static int
2343 dissect_snmp_SNMPv2_Trap_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2344   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2345                                       hf_index, BER_CLASS_CON, 7, TRUE, dissect_snmp_PDU);
2346
2347   return offset;
2348 }
2349
2350
2351
2352 static int
2353 dissect_snmp_Report_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2354   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2355                                       hf_index, BER_CLASS_CON, 8, TRUE, dissect_snmp_PDU);
2356
2357   return offset;
2358 }
2359
2360
2361 static const value_string snmp_PDUs_vals[] = {
2362   {   0, "get-request" },
2363   {   1, "get-next-request" },
2364   {   2, "get-response" },
2365   {   3, "set-request" },
2366   {   4, "trap" },
2367   {   5, "getBulkRequest" },
2368   {   6, "informRequest" },
2369   {   7, "snmpV2-trap" },
2370   {   8, "report" },
2371   { 0, NULL }
2372 };
2373
2374 static const ber_choice_t PDUs_choice[] = {
2375   {   0, &hf_snmp_get_request    , BER_CLASS_CON, 0, BER_FLAGS_NOOWNTAG, dissect_snmp_GetRequest_PDU },
2376   {   1, &hf_snmp_get_next_request, BER_CLASS_CON, 1, BER_FLAGS_NOOWNTAG, dissect_snmp_GetNextRequest_PDU },
2377   {   2, &hf_snmp_get_response   , BER_CLASS_CON, 2, BER_FLAGS_NOOWNTAG, dissect_snmp_GetResponse_PDU },
2378   {   3, &hf_snmp_set_request    , BER_CLASS_CON, 3, BER_FLAGS_NOOWNTAG, dissect_snmp_SetRequest_PDU },
2379   {   4, &hf_snmp_trap           , BER_CLASS_CON, 4, BER_FLAGS_NOOWNTAG, dissect_snmp_Trap_PDU },
2380   {   5, &hf_snmp_getBulkRequest , BER_CLASS_CON, 5, BER_FLAGS_NOOWNTAG, dissect_snmp_GetBulkRequest_PDU },
2381   {   6, &hf_snmp_informRequest  , BER_CLASS_CON, 6, BER_FLAGS_NOOWNTAG, dissect_snmp_InformRequest_PDU },
2382   {   7, &hf_snmp_snmpV2_trap    , BER_CLASS_CON, 7, BER_FLAGS_NOOWNTAG, dissect_snmp_SNMPv2_Trap_PDU },
2383   {   8, &hf_snmp_report         , BER_CLASS_CON, 8, BER_FLAGS_NOOWNTAG, dissect_snmp_Report_PDU },
2384   { 0, NULL, 0, 0, 0, NULL }
2385 };
2386
2387 static int
2388 dissect_snmp_PDUs(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2389 #line 28 "../../asn1/snmp/snmp.cnf"
2390 gint pdu_type=-1;
2391
2392   col_clear(actx->pinfo->cinfo, COL_INFO);
2393
2394   offset = dissect_ber_choice(actx, tree, tvb, offset,
2395                                  PDUs_choice, hf_index, ett_snmp_PDUs,
2396                                  &pdu_type);
2397
2398         if( (pdu_type!=-1) && snmp_PDUs_vals[pdu_type].strptr ){
2399                 col_prepend_fstr(actx->pinfo->cinfo, COL_INFO, "%s", snmp_PDUs_vals[pdu_type].strptr);
2400         }
2401
2402
2403
2404   return offset;
2405 }
2406
2407
2408 static const ber_sequence_t Message_sequence[] = {
2409   { &hf_snmp_version        , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Version },
2410   { &hf_snmp_community      , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_Community },
2411   { &hf_snmp_data           , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_PDUs },
2412   { NULL, 0, 0, 0, NULL }
2413 };
2414
2415 static int
2416 dissect_snmp_Message(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2417   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2418                                    Message_sequence, hf_index, ett_snmp_Message);
2419
2420   return offset;
2421 }
2422
2423
2424
2425 static int
2426 dissect_snmp_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2427   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2428                                        NULL);
2429
2430   return offset;
2431 }
2432
2433
2434 static const value_string snmp_T_datav2u_vals[] = {
2435   {   0, "plaintext" },
2436   {   1, "encrypted" },
2437   { 0, NULL }
2438 };
2439
2440 static const ber_choice_t T_datav2u_choice[] = {
2441   {   0, &hf_snmp_v2u_plaintext  , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_PDUs },
2442   {   1, &hf_snmp_encrypted      , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2443   { 0, NULL, 0, 0, 0, NULL }
2444 };
2445
2446 static int
2447 dissect_snmp_T_datav2u(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2448   offset = dissect_ber_choice(actx, tree, tvb, offset,
2449                                  T_datav2u_choice, hf_index, ett_snmp_T_datav2u,
2450                                  NULL);
2451
2452   return offset;
2453 }
2454
2455
2456 static const ber_sequence_t Messagev2u_sequence[] = {
2457   { &hf_snmp_version        , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Version },
2458   { &hf_snmp_parameters     , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2459   { &hf_snmp_datav2u        , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_T_datav2u },
2460   { NULL, 0, 0, 0, NULL }
2461 };
2462
2463 static int
2464 dissect_snmp_Messagev2u(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2465   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2466                                    Messagev2u_sequence, hf_index, ett_snmp_Messagev2u);
2467
2468   return offset;
2469 }
2470
2471
2472
2473 static int
2474 dissect_snmp_SnmpEngineID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2475 #line 102 "../../asn1/snmp/snmp.cnf"
2476         tvbuff_t* param_tvb = NULL;
2477
2478         offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index, &param_tvb);
2479          if (param_tvb) {
2480                 proto_tree* engine_tree = proto_item_add_subtree(actx->created_item,ett_engineid);
2481                 dissect_snmp_engineid(engine_tree, actx->pinfo, param_tvb, 0, tvb_reported_length_remaining(param_tvb,0));
2482         }
2483
2484
2485
2486   return offset;
2487 }
2488
2489
2490
2491 static int
2492 dissect_snmp_T_msgAuthoritativeEngineID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2493 #line 94 "../../asn1/snmp/snmp.cnf"
2494
2495         offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index, &usm_p.engine_tvb);
2496          if (usm_p.engine_tvb) {
2497                 proto_tree* engine_tree = proto_item_add_subtree(actx->created_item,ett_engineid);
2498                 dissect_snmp_engineid(engine_tree, actx->pinfo, usm_p.engine_tvb, 0, tvb_reported_length_remaining(usm_p.engine_tvb,0));
2499         }
2500
2501
2502
2503   return offset;
2504 }
2505
2506
2507
2508 static int
2509 dissect_snmp_T_msgAuthoritativeEngineBoots(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2510   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2511                                                 &usm_p.boots);
2512
2513   return offset;
2514 }
2515
2516
2517
2518 static int
2519 dissect_snmp_T_msgAuthoritativeEngineTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2520   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2521                                                 &usm_p.snmp_time);
2522
2523   return offset;
2524 }
2525
2526
2527
2528 static int
2529 dissect_snmp_T_msgUserName(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2530   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2531                                        &usm_p.user_tvb);
2532
2533   return offset;
2534 }
2535
2536
2537
2538 static int
2539 dissect_snmp_T_msgAuthenticationParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2540 #line 114 "../../asn1/snmp/snmp.cnf"
2541         offset = dissect_ber_octet_string(FALSE, actx, tree, tvb, offset, hf_index, &usm_p.auth_tvb);
2542         if (usm_p.auth_tvb) {
2543                 usm_p.auth_item = actx->created_item;
2544                 usm_p.auth_offset = tvb_offset_from_real_beginning(usm_p.auth_tvb);
2545         }
2546
2547
2548   return offset;
2549 }
2550
2551
2552
2553 static int
2554 dissect_snmp_T_msgPrivacyParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2555   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2556                                        &usm_p.priv_tvb);
2557
2558   return offset;
2559 }
2560
2561
2562 static const ber_sequence_t UsmSecurityParameters_sequence[] = {
2563   { &hf_snmp_msgAuthoritativeEngineID, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthoritativeEngineID },
2564   { &hf_snmp_msgAuthoritativeEngineBoots, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthoritativeEngineBoots },
2565   { &hf_snmp_msgAuthoritativeEngineTime, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthoritativeEngineTime },
2566   { &hf_snmp_msgUserName    , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgUserName },
2567   { &hf_snmp_msgAuthenticationParameters, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthenticationParameters },
2568   { &hf_snmp_msgPrivacyParameters, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgPrivacyParameters },
2569   { NULL, 0, 0, 0, NULL }
2570 };
2571
2572 static int
2573 dissect_snmp_UsmSecurityParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2574   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2575                                    UsmSecurityParameters_sequence, hf_index, ett_snmp_UsmSecurityParameters);
2576
2577   return offset;
2578 }
2579
2580
2581
2582 static int
2583 dissect_snmp_INTEGER_484_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2584   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2585                                                 NULL);
2586
2587   return offset;
2588 }
2589
2590
2591
2592 static int
2593 dissect_snmp_T_msgFlags(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2594 #line 217 "../../asn1/snmp/snmp.cnf"
2595         tvbuff_t *parameter_tvb = NULL;
2596
2597    offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2598                                        &parameter_tvb);
2599
2600         if (parameter_tvb){
2601                 guint8 v3_flags = tvb_get_guint8(parameter_tvb, 0);
2602                 proto_tree* flags_tree = proto_item_add_subtree(actx->created_item,ett_msgFlags);
2603
2604                 proto_tree_add_item(flags_tree, hf_snmp_v3_flags_report, parameter_tvb, 0, 1, ENC_BIG_ENDIAN);
2605                 proto_tree_add_item(flags_tree, hf_snmp_v3_flags_crypt, parameter_tvb, 0, 1, ENC_BIG_ENDIAN);
2606                 proto_tree_add_item(flags_tree, hf_snmp_v3_flags_auth, parameter_tvb, 0, 1, ENC_BIG_ENDIAN);
2607
2608                 usm_p.encrypted = v3_flags & TH_CRYPT ? TRUE : FALSE;
2609                 usm_p.authenticated = v3_flags & TH_AUTH ? TRUE : FALSE;
2610         }
2611
2612
2613
2614
2615   return offset;
2616 }
2617
2618
2619
2620 static int
2621 dissect_snmp_T_msgSecurityModel(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2622   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2623                                                 &MsgSecurityModel);
2624
2625   return offset;
2626 }
2627
2628
2629 static const ber_sequence_t HeaderData_sequence[] = {
2630   { &hf_snmp_msgID          , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_0_2147483647 },
2631   { &hf_snmp_msgMaxSize     , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_484_2147483647 },
2632   { &hf_snmp_msgFlags       , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgFlags },
2633   { &hf_snmp_msgSecurityModel, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgSecurityModel },
2634   { NULL, 0, 0, 0, NULL }
2635 };
2636
2637 static int
2638 dissect_snmp_HeaderData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2639   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2640                                    HeaderData_sequence, hf_index, ett_snmp_HeaderData);
2641
2642   return offset;
2643 }
2644
2645
2646
2647 static int
2648 dissect_snmp_T_msgSecurityParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2649 #line 165 "../../asn1/snmp/snmp.cnf"
2650
2651         switch(MsgSecurityModel){
2652                 case SNMP_SEC_USM:      /* 3 */
2653                         offset = dissect_snmp_UsmSecurityParameters(FALSE, tvb, offset+2, actx, tree, -1);
2654                         usm_p.user_assoc = get_user_assoc(usm_p.engine_tvb, usm_p.user_tvb);
2655                         break;
2656                 case SNMP_SEC_ANY:      /* 0 */
2657                 case SNMP_SEC_V1:       /* 1 */
2658                 case SNMP_SEC_V2C:      /* 2 */
2659                 default:
2660                           offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2661                                        NULL);
2662
2663                         break;
2664         }
2665
2666
2667
2668   return offset;
2669 }
2670
2671
2672 static const ber_sequence_t ScopedPDU_sequence[] = {
2673   { &hf_snmp_contextEngineID, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_SnmpEngineID },
2674   { &hf_snmp_contextName    , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2675   { &hf_snmp_data           , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_PDUs },
2676   { NULL, 0, 0, 0, NULL }
2677 };
2678
2679 static int
2680 dissect_snmp_ScopedPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2681   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2682                                    ScopedPDU_sequence, hf_index, ett_snmp_ScopedPDU);
2683
2684   return offset;
2685 }
2686
2687
2688
2689 static int
2690 dissect_snmp_T_encryptedPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2691 #line 123 "../../asn1/snmp/snmp.cnf"
2692         tvbuff_t* crypt_tvb;
2693         offset = dissect_ber_octet_string(FALSE, actx, tree, tvb, offset, hf_snmp_encryptedPDU, &crypt_tvb);
2694
2695         if( usm_p.encrypted && crypt_tvb
2696                 && usm_p.user_assoc
2697                 && usm_p.user_assoc->user.privProtocol ) {
2698
2699                 const gchar* error = NULL;
2700                 proto_tree* encryptedpdu_tree = proto_item_add_subtree(actx->created_item,ett_encryptedPDU);
2701                 tvbuff_t* cleartext_tvb = usm_p.user_assoc->user.privProtocol(&usm_p, crypt_tvb, &error );
2702
2703                 if (! cleartext_tvb) {
2704                         proto_tree_add_expert_format(encryptedpdu_tree, actx->pinfo, &ei_snmp_failed_decrypted_data_pdu,
2705                                 crypt_tvb, 0, -1, "Failed to decrypt encryptedPDU: %s", error);
2706
2707                         col_set_str(actx->pinfo->cinfo, COL_INFO, "encryptedPDU: Failed to decrypt");
2708
2709                         return offset;
2710                 } else {
2711                         proto_item* decrypted_item;
2712                         proto_tree* decrypted_tree;
2713
2714                         if (! check_ScopedPdu(cleartext_tvb)) {
2715                                 proto_tree_add_expert(encryptedpdu_tree, actx->pinfo, &ei_snmp_decrypted_data_bad_formatted, cleartext_tvb, 0, -1);
2716
2717                                 col_set_str(actx->pinfo->cinfo, COL_INFO, "encryptedPDU: Decrypted data not formatted as expected");
2718
2719                                 return offset;
2720                         }
2721
2722
2723                         add_new_data_source(actx->pinfo, cleartext_tvb, "Decrypted ScopedPDU");
2724
2725                         decrypted_item = proto_tree_add_item(encryptedpdu_tree, hf_snmp_decryptedPDU,cleartext_tvb,0,-1,ENC_NA);
2726                         decrypted_tree = proto_item_add_subtree(decrypted_item,ett_decrypted);
2727                         dissect_snmp_ScopedPDU(FALSE, cleartext_tvb, 0, actx, decrypted_tree, -1);
2728                         }
2729         } else {
2730                         col_set_str(actx->pinfo->cinfo, COL_INFO, "encryptedPDU: privKey Unknown");
2731         }
2732
2733
2734
2735   return offset;
2736 }
2737
2738
2739 static const value_string snmp_ScopedPduData_vals[] = {
2740   {   0, "plaintext" },
2741   {   1, "encryptedPDU" },
2742   { 0, NULL }
2743 };
2744
2745 static const ber_choice_t ScopedPduData_choice[] = {
2746   {   0, &hf_snmp_plaintext      , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_ScopedPDU },
2747   {   1, &hf_snmp_encryptedPDU   , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_encryptedPDU },
2748   { 0, NULL, 0, 0, 0, NULL }
2749 };
2750
2751 static int
2752 dissect_snmp_ScopedPduData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2753   offset = dissect_ber_choice(actx, tree, tvb, offset,
2754                                  ScopedPduData_choice, hf_index, ett_snmp_ScopedPduData,
2755                                  NULL);
2756
2757   return offset;
2758 }
2759
2760
2761 static const ber_sequence_t SNMPv3Message_sequence[] = {
2762   { &hf_snmp_msgVersion     , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Version },
2763   { &hf_snmp_msgGlobalData  , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_HeaderData },
2764   { &hf_snmp_msgSecurityParameters, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgSecurityParameters },
2765   { &hf_snmp_msgData        , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_ScopedPduData },
2766   { NULL, 0, 0, 0, NULL }
2767 };
2768
2769 static int
2770 dissect_snmp_SNMPv3Message(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2771   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2772                                    SNMPv3Message_sequence, hf_index, ett_snmp_SNMPv3Message);
2773
2774 #line 180 "../../asn1/snmp/snmp.cnf"
2775
2776         if( usm_p.authenticated
2777                 && usm_p.user_assoc
2778                 && usm_p.user_assoc->user.authModel ) {
2779                 const gchar* error = NULL;
2780                 proto_item* authen_item;
2781                 proto_tree* authen_tree = proto_item_add_subtree(usm_p.auth_item,ett_authParameters);
2782                 guint8* calc_auth;
2783                 guint calc_auth_len;
2784
2785                 usm_p.authOK = usm_p.user_assoc->user.authModel->authenticate( &usm_p, &calc_auth, &calc_auth_len, &error );
2786
2787                 if (error) {
2788                         expert_add_info_format( actx->pinfo, usm_p.auth_item, &ei_snmp_verify_authentication_error, "Error while verifying Message authenticity: %s", error );
2789                 } else {
2790                         expert_field* expert;
2791
2792                         authen_item = proto_tree_add_boolean(authen_tree, hf_snmp_msgAuthentication, tvb, 0, 0, usm_p.authOK);
2793                         PROTO_ITEM_SET_GENERATED(authen_item);
2794
2795                         if (usm_p.authOK) {
2796                                 expert = &ei_snmp_authentication_ok;
2797                         } else {
2798                                 const gchar* calc_auth_str = bytestring_to_str(wmem_packet_scope(), calc_auth,calc_auth_len,' ');
2799                                 proto_item_append_text(authen_item, " calculated = %s", calc_auth_str);
2800                                 expert = &ei_snmp_authentication_error;
2801                         }
2802
2803                         expert_add_info( actx->pinfo, authen_item, expert);
2804                 }
2805         }
2806
2807
2808   return offset;
2809 }
2810
2811
2812 static const value_string snmp_T_smux_version_vals[] = {
2813   {   0, "version-1" },
2814   { 0, NULL }
2815 };
2816
2817
2818 static int
2819 dissect_snmp_T_smux_version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2820   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2821                                                 NULL);
2822
2823   return offset;
2824 }
2825
2826
2827
2828 static int
2829 dissect_snmp_OBJECT_IDENTIFIER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2830   offset = dissect_ber_object_identifier(implicit_tag, actx, tree, tvb, offset, hf_index, NULL);
2831
2832   return offset;
2833 }
2834
2835
2836
2837 static int
2838 dissect_snmp_DisplayString(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2839   offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2840                                        NULL);
2841
2842   return offset;
2843 }
2844
2845
2846 static const ber_sequence_t SimpleOpen_U_sequence[] = {
2847   { &hf_snmp_smux_version   , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_smux_version },
2848   { &hf_snmp_identity       , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_snmp_OBJECT_IDENTIFIER },
2849   { &hf_snmp_description    , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_DisplayString },
2850   { &hf_snmp_password       , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2851   { NULL, 0, 0, 0, NULL }
2852 };
2853
2854 static int
2855 dissect_snmp_SimpleOpen_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2856   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2857                                    SimpleOpen_U_sequence, hf_index, ett_snmp_SimpleOpen_U);
2858
2859   return offset;
2860 }
2861
2862
2863
2864 static int
2865 dissect_snmp_SimpleOpen(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2866   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2867                                       hf_index, BER_CLASS_APP, 0, TRUE, dissect_snmp_SimpleOpen_U);
2868
2869   return offset;
2870 }
2871
2872
2873 static const value_string snmp_OpenPDU_vals[] = {
2874   {   0, "smux-simple" },
2875   { 0, NULL }
2876 };
2877
2878 static const ber_choice_t OpenPDU_choice[] = {
2879   {   0, &hf_snmp_smux_simple    , BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_snmp_SimpleOpen },
2880   { 0, NULL, 0, 0, 0, NULL }
2881 };
2882
2883 static int
2884 dissect_snmp_OpenPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2885   offset = dissect_ber_choice(actx, tree, tvb, offset,
2886                                  OpenPDU_choice, hf_index, ett_snmp_OpenPDU,
2887                                  NULL);
2888
2889   return offset;
2890 }
2891
2892
2893 static const value_string snmp_ClosePDU_U_vals[] = {
2894   {   0, "goingDown" },
2895   {   1, "unsupportedVersion" },
2896   {   2, "packetFormat" },
2897   {   3, "protocolError" },
2898   {   4, "internalError" },
2899   {   5, "authenticationFailure" },
2900   { 0, NULL }
2901 };
2902
2903
2904 static int
2905 dissect_snmp_ClosePDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2906   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2907                                                 NULL);
2908
2909   return offset;
2910 }
2911
2912
2913
2914 static int
2915 dissect_snmp_ClosePDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2916   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2917                                       hf_index, BER_CLASS_APP, 1, TRUE, dissect_snmp_ClosePDU_U);
2918
2919   return offset;
2920 }
2921
2922
2923
2924 static int
2925 dissect_snmp_INTEGER_M1_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2926   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2927                                                 NULL);
2928
2929   return offset;
2930 }
2931
2932
2933 static const value_string snmp_T_operation_vals[] = {
2934   {   0, "delete" },
2935   {   1, "readOnly" },
2936   {   2, "readWrite" },
2937   { 0, NULL }
2938 };
2939
2940
2941 static int
2942 dissect_snmp_T_operation(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2943   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2944                                                 NULL);
2945
2946   return offset;
2947 }
2948
2949
2950 static const ber_sequence_t RReqPDU_U_sequence[] = {
2951   { &hf_snmp_subtree        , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_snmp_ObjectName },
2952   { &hf_snmp_priority       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_M1_2147483647 },
2953   { &hf_snmp_operation      , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_operation },
2954   { NULL, 0, 0, 0, NULL }
2955 };
2956
2957 static int
2958 dissect_snmp_RReqPDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2959   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2960                                    RReqPDU_U_sequence, hf_index, ett_snmp_RReqPDU_U);
2961
2962   return offset;
2963 }
2964
2965
2966
2967 static int
2968 dissect_snmp_RReqPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2969   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2970                                       hf_index, BER_CLASS_APP, 2, TRUE, dissect_snmp_RReqPDU_U);
2971
2972   return offset;
2973 }
2974
2975
2976 static const value_string snmp_RRspPDU_U_vals[] = {
2977   {  -1, "failure" },
2978   { 0, NULL }
2979 };
2980
2981
2982 static int
2983 dissect_snmp_RRspPDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2984   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2985                                                 NULL);
2986
2987   return offset;
2988 }
2989
2990
2991
2992 static int
2993 dissect_snmp_RRspPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2994   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2995                                       hf_index, BER_CLASS_APP, 3, TRUE, dissect_snmp_RRspPDU_U);
2996
2997   return offset;
2998 }
2999
3000
3001 static const value_string snmp_RegisterResponse_vals[] = {
3002   {   0, "rRspPDU" },
3003   {   1, "pDUs" },
3004   { 0, NULL }
3005 };
3006
3007 static const ber_choice_t RegisterResponse_choice[] = {
3008   {   0, &hf_snmp_rRspPDU        , BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_snmp_RRspPDU },
3009   {   1, &hf_snmp_pDUs           , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_PDUs },
3010   { 0, NULL, 0, 0, 0, NULL }
3011 };
3012
3013 static int
3014 dissect_snmp_RegisterResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3015   offset = dissect_ber_choice(actx, tree, tvb, offset,
3016                                  RegisterResponse_choice, hf_index, ett_snmp_RegisterResponse,
3017                                  NULL);
3018
3019   return offset;
3020 }
3021
3022
3023 static const value_string snmp_SOutPDU_U_vals[] = {
3024   {   0, "commit" },
3025   {   1, "rollback" },
3026   { 0, NULL }
3027 };
3028
3029
3030 static int
3031 dissect_snmp_SOutPDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3032   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
3033                                                 NULL);
3034
3035   return offset;
3036 }
3037
3038
3039
3040 static int
3041 dissect_snmp_SOutPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3042   offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
3043                                       hf_index, BER_CLASS_APP, 4, TRUE, dissect_snmp_SOutPDU_U);
3044
3045   return offset;
3046 }
3047
3048
3049 static const value_string snmp_SMUX_PDUs_vals[] = {
3050   {   0, "open" },
3051   {   1, "close" },
3052   {   2, "registerRequest" },
3053   {   3, "registerResponse" },
3054   {   4, "commitOrRollback" },
3055   { 0, NULL }
3056 };
3057
3058 static const ber_choice_t SMUX_PDUs_choice[] = {
3059   {   0, &hf_snmp_open           , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_OpenPDU },
3060   {   1, &hf_snmp_close          , BER_CLASS_APP, 1, BER_FLAGS_NOOWNTAG, dissect_snmp_ClosePDU },
3061   {   2, &hf_snmp_registerRequest, BER_CLASS_APP, 2, BER_FLAGS_NOOWNTAG, dissect_snmp_RReqPDU },
3062   {   3, &hf_snmp_registerResponse, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_RegisterResponse },
3063   {   4, &hf_snmp_commitOrRollback, BER_CLASS_APP, 4, BER_FLAGS_NOOWNTAG, dissect_snmp_SOutPDU },
3064   { 0, NULL, 0, 0, 0, NULL }
3065 };
3066
3067 static int
3068 dissect_snmp_SMUX_PDUs(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
3069   offset = dissect_ber_choice(actx, tree, tvb, offset,
3070                                  SMUX_PDUs_choice, hf_index, ett_snmp_SMUX_PDUs,
3071                                  NULL);
3072
3073   return offset;
3074 }
3075
3076 /*--- PDUs ---*/
3077
3078 static int dissect_SMUX_PDUs_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
3079   int offset = 0;
3080   asn1_ctx_t asn1_ctx;
3081   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
3082   offset = dissect_snmp_SMUX_PDUs(FALSE, tvb, offset, &asn1_ctx, tree, hf_snmp_SMUX_PDUs_PDU);
3083   return offset;
3084 }
3085
3086
3087 /*--- End of included file: packet-snmp-fn.c ---*/
3088 #line 1873 "../../asn1/snmp/packet-snmp-template.c"
3089
3090
3091 guint
3092 dissect_snmp_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
3093                  proto_tree *tree, int proto, gint ett, gboolean is_tcp)
3094 {
3095
3096         guint length_remaining;
3097         gint8 ber_class;
3098         gboolean pc, ind = 0;
3099         gint32 tag;
3100         guint32 len;
3101         guint message_length;