Add HP Switch Protocol SAP value
[obnox/wireshark/wip.git] / epan / dissectors / packet-snmp.c
1 /* Do not modify this file.                                                   */
2 /* It is created automatically by the ASN.1 to Wireshark dissector compiler   */
3 /* ./packet-snmp.c                                                            */
4 /* ../../tools/asn2wrs.py -b -e -p snmp -c snmp.cnf -s packet-snmp-template snmp.asn */
5
6 /* Input file: packet-snmp-template.c */
7
8 #line 1 "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  *
24  * $Id$
25  *
26  * Wireshark - Network traffic analyzer
27  * By Gerald Combs <gerald@wireshark.org>
28  * Copyright 1998 Gerald Combs
29  *
30  * Some stuff from:
31  *
32  * GXSNMP -- An snmp mangament application
33  * Copyright (C) 1998 Gregory McLean & Jochen Friedrich
34  * Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group
35  *
36  * This program is free software; you can redistribute it and/or
37  * modify it under the terms of the GNU General Public License
38  * as published by the Free Software Foundation; either version 2
39  * of the License, or (at your option) any later version.
40  *
41  * This program is distributed in the hope that it will be useful,
42  * but WITHOUT ANY WARRANTY; without even the implied warranty of
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44  * GNU General Public License for more details.
45  *
46  * You should have received a copy of the GNU General Public License
47  * along with this program; if not, write to the Free Software
48  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
49  */
50
51 #ifdef HAVE_CONFIG_H
52 # include "config.h"
53 #endif
54
55 #include <stdio.h>
56 #include <string.h>
57 #include <ctype.h>
58
59 #include <glib.h>
60
61 #include <epan/packet.h>
62 #include <epan/strutil.h>
63 #include <epan/conversation.h>
64 #include "etypes.h"
65 #include <epan/prefs.h>
66 #include <epan/sminmpec.h>
67 #include <epan/emem.h>
68 #include <epan/next_tvb.h>
69 #include "packet-ipx.h"
70 #include "packet-hpext.h"
71
72
73 #include "packet-ber.h"
74
75 #ifdef HAVE_SOME_SNMP
76
77 #ifdef HAVE_NET_SNMP
78 # include <net-snmp/net-snmp-config.h>
79 # include <net-snmp/mib_api.h>
80 # include <net-snmp/library/default_store.h>
81 # include <net-snmp/config_api.h>
82 #else /* HAVE_NET_SNMP */
83 # include <ucd-snmp/ucd-snmp-config.h>
84 # include <ucd-snmp/asn1.h>
85 # include <ucd-snmp/snmp_api.h>
86 # include <ucd-snmp/snmp_impl.h>
87 # include <ucd-snmp/mib.h>
88 # include <ucd-snmp/default_store.h>
89 # include <ucd-snmp/read_config.h>
90 # include <ucd-snmp/tools.h>
91 #endif /* HAVE_NET_SNMP */
92
93 #ifndef NETSNMP_DS_LIBRARY_ID
94 # define NETSNMP_DS_LIBRARY_ID DS_LIBRARY_ID
95 # define NETSNMP_DS_LIB_NO_TOKEN_WARNINGS DS_LIB_NO_TOKEN_WARNINGS
96 # define NETSNMP_DS_LIB_PRINT_SUFFIX_ONLY DS_LIB_PRINT_SUFFIX_ONLY
97 # define netsnmp_ds_set_boolean ds_set_boolean
98 # define netsnmp_ds_set_int ds_set_int
99 #endif
100
101 #ifdef _WIN32
102 # include <epan/filesystem.h>
103 #endif /* _WIN32 */
104
105    /*
106     * Define values "sprint_realloc_value()" expects.
107     */
108 # define VALTYPE_INTEGER        ASN_INTEGER
109 # define VALTYPE_COUNTER        ASN_COUNTER
110 # define VALTYPE_GAUGE          ASN_GAUGE
111 # define VALTYPE_TIMETICKS      ASN_TIMETICKS
112 # define VALTYPE_STRING         ASN_OCTET_STR
113 # define VALTYPE_IPADDR         ASN_IPADDRESS
114 # define VALTYPE_OPAQUE         ASN_OPAQUE
115 # define VALTYPE_NSAP           ASN_NSAP
116 # define VALTYPE_OBJECTID       ASN_OBJECT_ID
117 # define VALTYPE_BITSTR         ASN_BIT_STR
118 # define VALTYPE_COUNTER64      ASN_COUNTER64
119
120 #endif /* HAVE_SOME_SNMP */
121
122 #include "packet-snmp.h"
123 #include "format-oid.h"
124
125 /* Take a pointer that may be null and return a pointer that's not null
126    by turning null pointers into pointers to the above null string,
127    and, if the argument pointer wasn't null, make sure we handle
128    non-printable characters in the string by escaping them. */
129 #define SAFE_STRING(s, l)       (((s) != NULL) ? format_text((s), (l)) : "")
130
131 #define PNAME  "Simple Network Management Protocol"
132 #define PSNAME "SNMP"
133 #define PFNAME "snmp"
134
135 #define UDP_PORT_SNMP           161
136 #define UDP_PORT_SNMP_TRAP      162
137 #define TCP_PORT_SNMP           161
138 #define TCP_PORT_SNMP_TRAP      162
139 #define TCP_PORT_SMUX           199
140
141 /* Initialize the protocol and registered fields */
142 static int proto_snmp = -1;
143 static int proto_smux = -1;
144
145 /* Default MIB modules to load */
146 /*
147  * XXX - According to Wes Hardaker, we shouldn't do this:
148  *       http://www.ethereal.com/lists/ethereal-dev/200412/msg00222.html
149  */
150 #ifdef _WIN32
151 # define DEF_MIB_MODULES "IP-MIB;IF-MIB;TCP-MIB;UDP-MIB;SNMPv2-MIB;RFC1213-MIB;UCD-SNMP-MIB"
152 # define IMPORT_SEPARATOR ":"
153 #else
154 # define DEF_MIB_MODULES "IP-MIB:IF-MIB:TCP-MIB:UDP-MIB:SNMPv2-MIB:RFC1213-MIB:UCD-SNMP-MIB"
155 # define IMPORT_SEPARATOR ";"
156 #endif /* _WIN32 */
157
158 static const gchar *mib_modules = DEF_MIB_MODULES;
159 static gboolean display_oid = TRUE;
160 static gboolean snmp_var_in_tree = TRUE;
161
162 /* Subdissector tables */
163 static dissector_table_t variable_oid_dissector_table;
164
165 #define TH_AUTH   0x01
166 #define TH_CRYPT  0x02
167 #define TH_REPORT 0x04
168
169 /* desegmentation of SNMP-over-TCP */
170 static gboolean snmp_desegment = TRUE;
171
172 /* Global variables */
173
174 guint32 MsgSecurityModel;
175 tvbuff_t *oid_tvb=NULL;
176 tvbuff_t *value_tvb=NULL;
177
178 static dissector_handle_t snmp_handle;
179 static dissector_handle_t data_handle;
180
181 static next_tvb_list_t var_list;
182
183 static int hf_snmp_v3_flags_auth = -1;
184 static int hf_snmp_v3_flags_crypt = -1;
185 static int hf_snmp_v3_flags_report = -1;
186
187 static int hf_snmp_engineid_conform = -1;
188 static int hf_snmp_engineid_enterprise = -1;
189 static int hf_snmp_engineid_format = -1;
190 static int hf_snmp_engineid_ipv4 = -1;
191 static int hf_snmp_engineid_ipv6 = -1;
192 static int hf_snmp_engineid_mac = -1;
193 static int hf_snmp_engineid_text = -1;
194 static int hf_snmp_engineid_time = -1;
195 static int hf_snmp_engineid_data = -1;
196 static int hf_snmp_counter64 = -1;
197
198
199 /*--- Included file: packet-snmp-hf.c ---*/
200 #line 1 "packet-snmp-hf.c"
201 static int hf_snmp_SMUX_PDUs_PDU = -1;            /* SMUX_PDUs */
202 static int hf_snmp_simple = -1;                   /* SimpleSyntax */
203 static int hf_snmp_application_wide = -1;         /* ApplicationSyntax */
204 static int hf_snmp_integer_value = -1;            /* Integer_value */
205 static int hf_snmp_string_value = -1;             /* String_value */
206 static int hf_snmp_objectID_value = -1;           /* ObjectID_value */
207 static int hf_snmp_empty = -1;                    /* Empty */
208 static int hf_snmp_ipAddress_value = -1;          /* IpAddress */
209 static int hf_snmp_counter_value = -1;            /* Counter32 */
210 static int hf_snmp_timeticks_value = -1;          /* TimeTicks */
211 static int hf_snmp_arbitrary_value = -1;          /* Opaque */
212 static int hf_snmp_big_counter_value = -1;        /* Counter64 */
213 static int hf_snmp_unsigned_integer_value = -1;   /* Unsigned32 */
214 static int hf_snmp_internet = -1;                 /* IpAddress */
215 static int hf_snmp_version = -1;                  /* Version */
216 static int hf_snmp_community = -1;                /* OCTET_STRING */
217 static int hf_snmp_data = -1;                     /* PDUs */
218 static int hf_snmp_parameters = -1;               /* OCTET_STRING */
219 static int hf_snmp_datav2u = -1;                  /* T_datav2u */
220 static int hf_snmp_v2u_plaintext = -1;            /* PDUs */
221 static int hf_snmp_encrypted = -1;                /* OCTET_STRING */
222 static int hf_snmp_msgAuthoritativeEngineID = -1;  /* SnmpEngineID */
223 static int hf_snmp_msgAuthoritativeEngineBoots = -1;  /* INTEGER_0_2147483647 */
224 static int hf_snmp_msgAuthoritativeEngineTime = -1;  /* INTEGER_0_2147483647 */
225 static int hf_snmp_msgUserName = -1;              /* OCTET_STRING_SIZE_1_32 */
226 static int hf_snmp_msgAuthenticationParameters = -1;  /* OCTET_STRING */
227 static int hf_snmp_msgPrivacyParameters = -1;     /* OCTET_STRING */
228 static int hf_snmp_msgVersion = -1;               /* Version */
229 static int hf_snmp_msgGlobalData = -1;            /* HeaderData */
230 static int hf_snmp_msgSecurityParameters = -1;    /* T_msgSecurityParameters */
231 static int hf_snmp_msgData = -1;                  /* ScopedPduData */
232 static int hf_snmp_msgID = -1;                    /* INTEGER_0_2147483647 */
233 static int hf_snmp_msgMaxSize = -1;               /* INTEGER_484_2147483647 */
234 static int hf_snmp_msgFlags = -1;                 /* T_msgFlags */
235 static int hf_snmp_msgSecurityModel = -1;         /* T_msgSecurityModel */
236 static int hf_snmp_plaintext = -1;                /* ScopedPDU */
237 static int hf_snmp_encryptedPDU = -1;             /* OCTET_STRING */
238 static int hf_snmp_contextEngineID = -1;          /* OCTET_STRING */
239 static int hf_snmp_contextName = -1;              /* OCTET_STRING */
240 static int hf_snmp_get_request = -1;              /* T_get_request */
241 static int hf_snmp_get_next_request = -1;         /* T_get_next_request */
242 static int hf_snmp_get_response = -1;             /* T_get_response */
243 static int hf_snmp_set_request = -1;              /* T_set_request */
244 static int hf_snmp_trap = -1;                     /* T_trap */
245 static int hf_snmp_getBulkRequest = -1;           /* T_getBulkRequest */
246 static int hf_snmp_informRequest = -1;            /* T_informRequest */
247 static int hf_snmp_sNMPv2_Trap = -1;              /* T_sNMPv2_Trap */
248 static int hf_snmp_report = -1;                   /* T_report */
249 static int hf_snmp_request_id = -1;               /* INTEGER */
250 static int hf_snmp_error_status = -1;             /* T_error_status */
251 static int hf_snmp_error_index = -1;              /* INTEGER */
252 static int hf_snmp_variable_bindings = -1;        /* VarBindList */
253 static int hf_snmp_bulkPDU_request_id = -1;       /* Integer32 */
254 static int hf_snmp_non_repeaters = -1;            /* INTEGER_0_2147483647 */
255 static int hf_snmp_max_repetitions = -1;          /* INTEGER_0_2147483647 */
256 static int hf_snmp_enterprise = -1;               /* OBJECT_IDENTIFIER */
257 static int hf_snmp_agent_addr = -1;               /* NetworkAddress */
258 static int hf_snmp_generic_trap = -1;             /* T_generic_trap */
259 static int hf_snmp_specific_trap = -1;            /* INTEGER */
260 static int hf_snmp_time_stamp = -1;               /* TimeTicks */
261 static int hf_snmp_name = -1;                     /* ObjectName */
262 static int hf_snmp_valueType = -1;                /* ValueType */
263 static int hf_snmp_value = -1;                    /* ObjectSyntax */
264 static int hf_snmp_unSpecified = -1;              /* NULL */
265 static int hf_snmp_noSuchObject = -1;             /* NULL */
266 static int hf_snmp_noSuchInstance = -1;           /* NULL */
267 static int hf_snmp_endOfMibView = -1;             /* NULL */
268 static int hf_snmp_VarBindList_item = -1;         /* VarBind */
269 static int hf_snmp_open = -1;                     /* OpenPDU */
270 static int hf_snmp_close = -1;                    /* ClosePDU */
271 static int hf_snmp_registerRequest = -1;          /* RReqPDU */
272 static int hf_snmp_registerResponse = -1;         /* RegisterResponse */
273 static int hf_snmp_commitOrRollback = -1;         /* SOutPDU */
274 static int hf_snmp_rRspPDU = -1;                  /* RRspPDU */
275 static int hf_snmp_pDUs = -1;                     /* PDUs */
276 static int hf_snmp_smux_simple = -1;              /* SimpleOpen */
277 static int hf_snmp_smux_version = -1;             /* T_smux_version */
278 static int hf_snmp_identity = -1;                 /* OBJECT_IDENTIFIER */
279 static int hf_snmp_description = -1;              /* DisplayString */
280 static int hf_snmp_password = -1;                 /* OCTET_STRING */
281 static int hf_snmp_subtree = -1;                  /* ObjectName */
282 static int hf_snmp_priority = -1;                 /* INTEGER_M1_2147483647 */
283 static int hf_snmp_operation = -1;                /* T_operation */
284
285 /*--- End of included file: packet-snmp-hf.c ---*/
286 #line 191 "packet-snmp-template.c"
287
288 static int hf_smux_version = -1;
289 static int hf_smux_pdutype = -1;
290
291 /* Initialize the subtree pointers */
292 static gint ett_smux = -1;
293 static gint ett_snmp = -1;
294 static gint ett_engineid = -1;
295 static gint ett_msgFlags = -1;
296
297
298 /*--- Included file: packet-snmp-ett.c ---*/
299 #line 1 "packet-snmp-ett.c"
300 static gint ett_snmp_ObjectSyntax = -1;
301 static gint ett_snmp_SimpleSyntax = -1;
302 static gint ett_snmp_ApplicationSyntax = -1;
303 static gint ett_snmp_NetworkAddress = -1;
304 static gint ett_snmp_Message = -1;
305 static gint ett_snmp_Messagev2u = -1;
306 static gint ett_snmp_T_datav2u = -1;
307 static gint ett_snmp_UsmSecurityParameters = -1;
308 static gint ett_snmp_SNMPv3Message = -1;
309 static gint ett_snmp_HeaderData = -1;
310 static gint ett_snmp_ScopedPduData = -1;
311 static gint ett_snmp_ScopedPDU = -1;
312 static gint ett_snmp_PDUs = -1;
313 static gint ett_snmp_PDU = -1;
314 static gint ett_snmp_BulkPDU = -1;
315 static gint ett_snmp_Trap_PDU = -1;
316 static gint ett_snmp_VarBind = -1;
317 static gint ett_snmp_ValueType = -1;
318 static gint ett_snmp_VarBindList = -1;
319 static gint ett_snmp_SMUX_PDUs = -1;
320 static gint ett_snmp_RegisterResponse = -1;
321 static gint ett_snmp_OpenPDU = -1;
322 static gint ett_snmp_SimpleOpen = -1;
323 static gint ett_snmp_RReqPDU = -1;
324
325 /*--- End of included file: packet-snmp-ett.c ---*/
326 #line 202 "packet-snmp-template.c"
327
328 /* defined in net-SNMP; include/net-snmp/library/snmp.h */
329 #undef SNMP_MSG_GET
330 #undef SNMP_MSG_SET
331 #undef SNMP_MSG_GETNEXT
332 #undef SNMP_MSG_RESPONSE
333 #undef SNMP_MSG_TRAP
334 #undef SNMP_MSG_GETBULK
335 #undef SNMP_MSG_INFORM
336 #undef SNMP_MSG_TRAP2
337 #undef SNMP_MSG_REPORT
338 #undef SNMP_NOSUCHOBJECT
339 #undef SNMP_NOSUCHINSTANCE
340 #undef SNMP_ENDOFMIBVIEW
341
342 /* Security Models */
343
344 #define SNMP_SEC_ANY                    0
345 #define SNMP_SEC_V1                             1
346 #define SNMP_SEC_V2C                    2
347 #define SNMP_SEC_USM                    3
348
349 static const value_string sec_models[] = {
350         { SNMP_SEC_ANY,                 "Any" },
351         { SNMP_SEC_V1,                  "V1" },
352         { SNMP_SEC_V2C,                 "V2C" },
353         { SNMP_SEC_USM,                 "USM" },
354         { 0,                            NULL }
355 };
356
357 /* SMUX PDU types */
358 #define SMUX_MSG_OPEN           0
359 #define SMUX_MSG_CLOSE          1
360 #define SMUX_MSG_RREQ           2
361 #define SMUX_MSG_RRSP           3
362 #define SMUX_MSG_SOUT           4
363
364 static const value_string smux_types[] = {
365         { SMUX_MSG_OPEN,        "Open" },
366         { SMUX_MSG_CLOSE,       "Close" },
367         { SMUX_MSG_RREQ,        "Registration Request" },
368         { SMUX_MSG_RRSP,        "Registration Response" },
369         { SMUX_MSG_SOUT,        "Commit Or Rollback" },
370         { 0,                    NULL }
371 };
372
373 /* SNMP Tags */
374
375 #define SNMP_IPA    0           /* IP Address */
376 #define SNMP_CNT    1           /* Counter (Counter32) */
377 #define SNMP_GGE    2           /* Gauge (Gauge32) */
378 #define SNMP_TIT    3           /* TimeTicks */
379 #define SNMP_OPQ    4           /* Opaque */
380 #define SNMP_NSP    5           /* NsapAddress */
381 #define SNMP_C64    6           /* Counter64 */
382 #define SNMP_U32    7           /* Uinteger32 */
383
384 #define SERR_NSO    0
385 #define SERR_NSI    1
386 #define SERR_EOM    2
387
388 /* SNMPv1 Types */
389
390 #define SNMP_NULL                0
391 #define SNMP_INTEGER             1    /* l  */
392 #define SNMP_OCTETSTR            2    /* c  */
393 #define SNMP_DISPLAYSTR          2    /* c  */
394 #define SNMP_OBJECTID            3    /* ul */
395 #define SNMP_IPADDR              4    /* uc */
396 #define SNMP_COUNTER             5    /* ul */
397 #define SNMP_GAUGE               6    /* ul */
398 #define SNMP_TIMETICKS           7    /* ul */
399 #define SNMP_OPAQUE              8    /* c  */
400
401 /* additional SNMPv2 Types */
402
403 #define SNMP_UINTEGER            5    /* ul */
404 #define SNMP_BITSTR              9    /* uc */
405 #define SNMP_NSAP               10    /* uc */
406 #define SNMP_COUNTER64          11    /* ul */
407 #define SNMP_NOSUCHOBJECT       12
408 #define SNMP_NOSUCHINSTANCE     13
409 #define SNMP_ENDOFMIBVIEW       14
410
411
412 typedef struct _SNMP_CNV SNMP_CNV;
413
414 struct _SNMP_CNV
415 {
416   guint class;
417   guint tag;
418   gint  syntax;
419   const gchar *name;
420 };
421
422 static SNMP_CNV SnmpCnv [] =
423 {
424   {BER_CLASS_UNI, BER_UNI_TAG_NULL,                     SNMP_NULL,      "NULL"},
425   {BER_CLASS_UNI, BER_UNI_TAG_INTEGER,          SNMP_INTEGER,   "INTEGER"},
426   {BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING,      SNMP_OCTETSTR,  "OCTET STRING"},
427   {BER_CLASS_UNI, BER_UNI_TAG_OID,                      SNMP_OBJECTID,  "OBJECTID"},
428   {BER_CLASS_APP, SNMP_IPA,                                     SNMP_IPADDR,    "IPADDR"},
429   {BER_CLASS_APP, SNMP_CNT,                                     SNMP_COUNTER,   "COUNTER"},  /* Counter32 */
430   {BER_CLASS_APP, SNMP_GGE,                                     SNMP_GAUGE,     "GAUGE"},    /* Gauge32 == Unsigned32  */
431   {BER_CLASS_APP, SNMP_TIT,                                     SNMP_TIMETICKS, "TIMETICKS"},
432   {BER_CLASS_APP, SNMP_OPQ,                                     SNMP_OPAQUE,    "OPAQUE"},
433
434 /* SNMPv2 data types and errors */
435
436   {BER_CLASS_UNI, BER_UNI_TAG_BITSTRING,        SNMP_BITSTR,         "BITSTR"},
437   {BER_CLASS_APP, SNMP_C64,                                     SNMP_COUNTER64,      "COUNTER64"},
438   {BER_CLASS_CON, SERR_NSO,                                     SNMP_NOSUCHOBJECT,   "NOSUCHOBJECT"},
439   {BER_CLASS_CON, SERR_NSI,                                     SNMP_NOSUCHINSTANCE, "NOSUCHINSTANCE"},
440   {BER_CLASS_CON, SERR_EOM,                                     SNMP_ENDOFMIBVIEW,   "ENDOFMIBVIEW"},
441   {0,           0,         -1,                  NULL}
442 };
443
444 /*
445  * NAME:        g_snmp_tag_cls2syntax
446  * SYNOPSIS:    gboolean g_snmp_tag_cls2syntax
447  *                  (
448  *                      guint    tag,
449  *                      guint    cls,
450  *                      gushort *syntax
451  *                  )
452  * DESCRIPTION: Converts ASN1 tag and class to Syntax tag and name.
453  *              See SnmpCnv for conversion.
454  * RETURNS:     name on success, NULL on failure
455  */
456
457 static const gchar *
458 snmp_tag_cls2syntax ( guint tag, guint cls, gushort *syntax)
459 {
460     SNMP_CNV *cnv;
461
462     cnv = SnmpCnv;
463     while (cnv->syntax != -1)
464     {
465         if (cnv->tag == tag && cnv->class == cls)
466         {
467             *syntax = cnv->syntax;
468             return cnv->name;
469         }
470         cnv++;
471     }
472     return NULL;
473 }
474
475 int oid_to_subid_buf(const guint8 *oid, gint oid_len, subid_t *buf, int buf_len) {
476   int i, out_len;
477   guint8 byte;
478   guint32 value;
479   gboolean is_first;
480
481   value=0; out_len = 0; byte =0; is_first = TRUE;
482   for (i=0; i<oid_len; i++){
483     if (out_len >= buf_len)
484       break;
485     byte = oid[i];
486     value = (value << 7) | (byte & 0x7F);
487     if (byte & 0x80) {
488       continue;
489     }
490     if (is_first) {
491       if ( value<40 ){
492         buf[0] = 0;
493         buf[1] = value;
494       }else if ( value < 80 ){
495         buf[0] = 1;
496         buf[1] = value - 40;
497       }else {
498         buf[0] = 2;
499         buf[1] = value - 80;
500       }
501       out_len= out_len+2;
502       is_first = FALSE;
503     }else{
504       buf[out_len++] = value;
505     }
506     value = 0;
507   }
508
509   return out_len;
510 }
511
512 gchar *
513 format_oid(subid_t *oid, guint oid_length)
514 {
515         char *result;
516         int result_len;
517         int len;
518         unsigned int i;
519         char *buf;
520 #ifdef HAVE_SOME_SNMP
521         guchar *oid_string;
522         size_t oid_string_len;
523         size_t oid_out_len;
524 #endif
525
526         result_len = oid_length * 22;
527
528 #ifdef HAVE_SOME_SNMP
529         /*
530          * Get the decoded form of the OID, and add its length to the
531          * length of the result string.
532          *
533          * XXX - check for "sprint_realloc_objid()" failure.
534          */
535         oid_string_len = 1024;
536         oid_string = ep_alloc(oid_string_len);
537         *oid_string = '\0';
538         oid_out_len = 0;
539         /* We pass an ep allocated block here, NOT a malloced block
540          * so we MUST NOT allow reallocation, hence the fourth
541          * parameter MUST be 0/FALSE
542          */
543         sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, FALSE,
544             oid, oid_length);
545         result_len += strlen(oid_string) + 3;
546 #endif
547
548         result = ep_alloc(result_len + 1);
549         buf = result;
550         len = g_snprintf(buf, result_len + 1 - (buf-result), "%lu", (unsigned long)oid[0]);
551         buf += len;
552         for (i = 1; i < oid_length;i++) {
553                 len = g_snprintf(buf, result_len + 1 - (buf-result), ".%lu", (unsigned long)oid[i]);
554                 buf += len;
555         }
556
557 #ifdef HAVE_SOME_SNMP
558         /*
559          * Append the decoded form of the OID.
560          */
561         g_snprintf(buf, result_len + 1 -(buf-result), " (%s)", oid_string);
562 #endif
563
564         return result;
565 }
566
567 /* returns the decoded (can be NULL) and non_decoded OID strings */
568 void
569 new_format_oid(subid_t *oid, guint oid_length,
570                gchar **non_decoded, gchar **decoded)
571 {
572         int non_decoded_len;
573         int len;
574         unsigned int i;
575         char *buf;
576 #ifdef HAVE_SOME_SNMP
577         guchar *oid_string;
578         size_t oid_string_len;
579         size_t oid_out_len;
580 #endif
581
582     if (oid == NULL || oid_length < 1) {
583                 *decoded = NULL;
584                 return;
585         }
586
587 #ifdef HAVE_SOME_SNMP
588         /*
589          * Get the decoded form of the OID, and add its length to the
590          * length of the result string.
591          */
592
593         /*
594          * XXX - if we convert this to ep_alloc(), make sure the fourth
595          * argument to sprint_realloc_objid() is FALSE.
596          */
597
598         oid_string_len = 1024;
599         oid_string = ep_alloc(oid_string_len);
600         if (oid_string != NULL) {
601                 *oid_string = '\0';
602                 oid_out_len = 0;
603                 /* We pass an ep allocated block here, NOT a malloced block
604                  * so we MUST NOT allow reallocation, hence the fourth
605                  * parameter MUST be 0/FALSE
606                  */
607                 sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, FALSE,
608                                      oid, oid_length);
609         }
610         *decoded = oid_string;
611 #else
612         *decoded = NULL;
613 #endif
614
615         non_decoded_len = oid_length * 22 + 1;
616         *non_decoded = ep_alloc(non_decoded_len);
617         buf = *non_decoded;
618         len = g_snprintf(buf, non_decoded_len-(buf-*non_decoded), "%lu", (unsigned long)oid[0]);
619         buf += len;
620         for (i = 1; i < oid_length; i++) {
621           len = g_snprintf(buf, non_decoded_len-(buf-*non_decoded), ".%lu", (unsigned long)oid[i]);
622           buf += len;
623         }
624 }
625
626 #ifdef HAVE_SOME_SNMP
627 static gboolean
628 check_var_length(guint vb_length, guint required_length, guchar **errmsg)
629 {
630         gchar *buf;
631         static const char badlen_fmt[] = "Length is %u, should be %u";
632
633         if (vb_length != required_length) {
634                 /* Enough room for the largest "Length is XXX,
635                    should be XXX" message - 10 digits for each
636                    XXX. */
637                 buf = ep_alloc(sizeof badlen_fmt + 10 + 10);
638                 if (buf != NULL) {
639                         g_snprintf(buf, sizeof badlen_fmt + 10 + 10,
640                             badlen_fmt, vb_length, required_length);
641                 }
642                 *errmsg = buf;
643                 return FALSE;
644         }
645         return TRUE;    /* length is OK */
646 }
647
648 static gchar *
649 format_var(struct variable_list *variable, subid_t *variable_oid,
650     guint variable_oid_length, gushort vb_type, guint val_len)
651 {
652         guchar *buf;
653         size_t buf_len;
654         size_t out_len;
655
656         if (variable_oid == NULL || variable_oid_length == 0)
657                 return NULL;
658
659         switch (vb_type) {
660
661         case SNMP_IPADDR:
662                 /* Length has to be 4 bytes. */
663                 if (!check_var_length(val_len, 4, &buf))
664                         return buf;     /* it's not 4 bytes */
665                 break;
666
667 #ifdef REMOVED
668         /* not all counters are encoded as a full 64bit integer */
669         case SNMP_COUNTER64:
670                 /* Length has to be 8 bytes. */
671                 if (!check_var_length(val_len, 8, &buf))
672                         return buf;     /* it's not 8 bytes */
673                 break;
674 #endif
675         default:
676                 break;
677         }
678
679         variable->next_variable = NULL;
680         variable->name = variable_oid;
681         variable->name_length = variable_oid_length;
682         switch (vb_type) {
683
684         case SNMP_INTEGER:
685                 variable->type = VALTYPE_INTEGER;
686                 break;
687
688         case SNMP_COUNTER:
689                 variable->type = VALTYPE_COUNTER;
690                 break;
691
692         case SNMP_GAUGE:
693                 variable->type = VALTYPE_GAUGE;
694                 break;
695
696         case SNMP_TIMETICKS:
697                 variable->type = VALTYPE_TIMETICKS;
698                 break;
699
700         case SNMP_OCTETSTR:
701                 variable->type = VALTYPE_STRING;
702                 break;
703
704         case SNMP_IPADDR:
705                 variable->type = VALTYPE_IPADDR;
706                 break;
707
708         case SNMP_OPAQUE:
709                 variable->type = VALTYPE_OPAQUE;
710                 break;
711
712         case SNMP_NSAP:
713                 variable->type = VALTYPE_NSAP;
714                 break;
715
716         case SNMP_OBJECTID:
717                 variable->type = VALTYPE_OBJECTID;
718                 break;
719
720         case SNMP_BITSTR:
721                 variable->type = VALTYPE_BITSTR;
722                 break;
723
724         case SNMP_COUNTER64:
725                 variable->type = VALTYPE_COUNTER64;
726                 break;
727         }
728         variable->val_len = val_len;
729
730         /*
731          * XXX - check for "sprint_realloc_objid()" failure.
732          */
733
734         buf_len = 1024;
735         buf = ep_alloc(buf_len);
736         if (buf != NULL) {
737                 *buf = '\0';
738                 out_len = 0;
739                 /* We pass an ep allocated block here, NOT a malloced block
740                  * so we MUST NOT allow reallocation, hence the fourth
741                  * parameter MUST be 0/FALSE
742                  */
743                 sprint_realloc_value(&buf, &buf_len, &out_len, FALSE,
744                     variable_oid, variable_oid_length, variable);
745         }
746         return buf;
747 }
748 #endif
749
750
751 #define F_SNMP_ENGINEID_CONFORM 0x80
752 #define SNMP_ENGINEID_RFC1910 0x00
753 #define SNMP_ENGINEID_RFC3411 0x01
754
755 static const true_false_string tfs_snmp_engineid_conform = {
756   "RFC3411 (SNMPv3)",
757   "RFC1910 (Non-SNMPv3)"
758 };
759
760 #define SNMP_ENGINEID_FORMAT_IPV4 0x01
761 #define SNMP_ENGINEID_FORMAT_IPV6 0x02
762 #define SNMP_ENGINEID_FORMAT_MACADDRESS 0x03
763 #define SNMP_ENGINEID_FORMAT_TEXT 0x04
764 #define SNMP_ENGINEID_FORMAT_OCTETS 0x05
765
766 static const value_string snmp_engineid_format_vals[] = {
767         { SNMP_ENGINEID_FORMAT_IPV4,    "IPv4 address" },
768         { SNMP_ENGINEID_FORMAT_IPV6,    "IPv6 address" },
769         { SNMP_ENGINEID_FORMAT_MACADDRESS,      "MAC address" },
770         { SNMP_ENGINEID_FORMAT_TEXT,    "Text, administratively assigned" },
771         { SNMP_ENGINEID_FORMAT_OCTETS,  "Octets, administratively assigned" },
772         { 0,    NULL }
773 };
774
775 /*
776  * SNMP Engine ID dissection according to RFC 3411 (SnmpEngineID TC)
777  * or historic RFC 1910 (AgentID)
778  */
779 int
780 dissect_snmp_engineid(proto_tree *tree, tvbuff_t *tvb, int offset, int len)
781 {
782     proto_item *item = NULL;
783     guint8 conformance, format;
784     guint32 enterpriseid, seconds;
785     nstime_t ts;
786     int len_remain = len;
787
788     /* first bit: engine id conformance */
789     if (len_remain<4) return offset;
790     conformance = ((tvb_get_guint8(tvb, offset)>>7) && 0x01);
791     proto_tree_add_item(tree, hf_snmp_engineid_conform, tvb, offset, 1, FALSE);
792
793     /* 4-byte enterprise number/name */
794     if (len_remain<4) return offset;
795     enterpriseid = tvb_get_ntohl(tvb, offset);
796     if (conformance)
797       enterpriseid -= 0x80000000; /* ignore first bit */
798     proto_tree_add_uint(tree, hf_snmp_engineid_enterprise, tvb, offset, 4, enterpriseid);
799     offset+=4;
800     len_remain-=4;
801
802     switch(conformance) {
803
804     case SNMP_ENGINEID_RFC1910:
805       /* 12-byte AgentID w/ 8-byte trailer */
806       if (len_remain==8) {
807         proto_tree_add_text(tree, tvb, offset, 8, "AgentID Trailer: 0x%s",
808                             tvb_bytes_to_str(tvb, offset, 8));
809         offset+=8;
810         len_remain-=8;
811       } else {
812         proto_tree_add_text(tree, tvb, offset, len_remain, "<Data not conforming to RFC1910>");
813         return offset;
814       }
815       break;
816
817     case SNMP_ENGINEID_RFC3411: /* variable length: 5..32 */
818
819       /* 1-byte format specifier */
820       if (len_remain<1) return offset;
821       format = tvb_get_guint8(tvb, offset);
822       item = proto_tree_add_uint_format(tree, hf_snmp_engineid_format, tvb, offset, 1, format, "Engine ID Format: %s (%d)",
823                           val_to_str(format, snmp_engineid_format_vals, "Reserved/Enterprise-specific"), format);
824       offset+=1;
825       len_remain-=1;
826
827       switch(format) {
828       case SNMP_ENGINEID_FORMAT_IPV4:
829         /* 4-byte IPv4 address */
830         if (len_remain==4) {
831           proto_tree_add_item(tree, hf_snmp_engineid_ipv4, tvb, offset, 4, FALSE);
832           offset+=4;
833           len_remain=0;
834         }
835         break;
836       case SNMP_ENGINEID_FORMAT_IPV6:
837         /* 16-byte IPv6 address */
838         if (len_remain==16) {
839           proto_tree_add_item(tree, hf_snmp_engineid_ipv6, tvb, offset, 16, FALSE);
840           offset+=16;
841           len_remain=0;
842         }
843         break;
844       case SNMP_ENGINEID_FORMAT_MACADDRESS:
845         /* 6-byte MAC address */
846         if (len_remain==6) {
847           proto_tree_add_item(tree, hf_snmp_engineid_mac, tvb, offset, 6, FALSE);
848           offset+=6;
849           len_remain=0;
850         }
851         break;
852       case SNMP_ENGINEID_FORMAT_TEXT:
853         /* max. 27-byte string, administratively assigned */
854         if (len_remain<=27) {
855           proto_tree_add_item(tree, hf_snmp_engineid_text, tvb, offset, len_remain, FALSE);
856           offset+=len_remain;
857           len_remain=0;
858         }
859         break;
860       case 128:
861         /* most common enterprise-specific format: (ucd|net)-snmp random */
862         if ((enterpriseid==2021)||(enterpriseid==8072)) {
863           proto_item_append_text(item, (enterpriseid==2021) ? ": UCD-SNMP Random" : ": Net-SNMP Random");
864           /* demystify: 4B random, 4B epoch seconds */
865           if (len_remain==8) {
866             proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, 4, FALSE);
867             seconds = tvb_get_letohl(tvb, offset+4);
868             ts.secs = seconds;
869             proto_tree_add_time_format(tree, hf_snmp_engineid_time, tvb, offset+4, 4,
870                                   &ts, "Engine ID Data: Creation Time: %s",
871                                   abs_time_secs_to_str(seconds));
872             offset+=8;
873             len_remain=0;
874           }
875         }
876         break;
877       case SNMP_ENGINEID_FORMAT_OCTETS:
878       default:
879         /* max. 27 bytes, administratively assigned or unknown format */
880         if (len_remain<=27) {
881           proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, len_remain, FALSE);
882           offset+=len_remain;
883           len_remain=0;
884         }
885         break;
886       }
887     }
888
889     if (len_remain>0) {
890       proto_tree_add_text(tree, tvb, offset, len_remain, "<Data not conforming to RFC3411>");
891       offset+=len_remain;
892     }
893     return offset;
894 }
895
896 /* This code is copied from the original SNMP dissector with minor changes to adapt it to use packet-ber.c routines
897  * TODO:
898  * - Rewrite it completly as OID as subid_t could be returned from dissect_ber_objectidentifier
899  * - vb_type_name is known when calling this routine(?)
900  * - All branches not needed(?)
901  * ...
902  */
903
904 static void
905 snmp_variable_decode(tvbuff_t *tvb, proto_tree *snmp_tree, packet_info *pinfo,tvbuff_t *oid_tvb,
906                                          int offset, guint *lengthp, tvbuff_t **out_tvb)
907 {
908         int start, vb_value_start;
909         guint length;
910         guint vb_length;
911         gushort vb_type;
912         const gchar *vb_type_name;
913         gint32 vb_integer_value;
914         guint32 vb_uinteger_value;
915         guint8 *vb_octet_string;
916         const guint8 *oid_buf;
917         subid_t *vb_oid;
918         guint vb_oid_length;
919         gchar *vb_display_string = NULL;
920         subid_t *variable_oid = NULL;
921         gint oid_len;
922         guint variable_oid_length = 0;
923         const guint8 *var_oid_buf;
924 #ifdef HAVE_SOME_SNMP
925         struct variable_list variable;
926         long value;
927 #endif
928         unsigned int i;
929         gchar *buf;
930         int len;
931         gint8 class;
932         gboolean pc, ind = 0;
933         gint32 ber_tag;
934
935         start = offset;
936         /* parse the type of the object */
937         offset = dissect_ber_identifier(pinfo, snmp_tree, tvb, start, &class, &pc, &ber_tag);
938         offset = dissect_ber_length(pinfo, snmp_tree, tvb, offset, &vb_length, &ind);
939
940         if(vb_length == 0){
941                 length = offset - start;
942                 *lengthp = length;
943                 return;
944         }
945
946         vb_value_start = offset;
947
948         /* Convert the class, constructed flag, and tag to a type. */
949         vb_type_name = snmp_tag_cls2syntax(ber_tag, class, &vb_type);
950
951         if (vb_type_name == NULL) {
952                 /*
953                  * Unsupported type.
954                  * Dissect the value as an opaque string of octets.
955                  */
956                 vb_type_name = "unsupported type";
957                 vb_type = SNMP_OPAQUE;
958         }
959         /* construct subid_t variable_oid from oid_tvb */
960         if (oid_tvb){
961                 oid_len = tvb_length_remaining(oid_tvb,0);
962                 var_oid_buf = tvb_get_ptr(oid_tvb, 0, oid_len);
963                 variable_oid = ep_alloc((oid_len+1) * sizeof(gulong));
964                 variable_oid_length = oid_to_subid_buf(var_oid_buf, oid_len, variable_oid, ((oid_len+1) * sizeof(gulong)));
965         }
966         /* parse the value */
967         switch (vb_type) {
968
969         case SNMP_INTEGER:
970                 offset = dissect_ber_integer(FALSE, pinfo, NULL, tvb, start, -1, &vb_integer_value);
971                 length = offset - vb_value_start;
972                 if (snmp_tree) {
973 #ifdef HAVE_SOME_SNMP
974                         value = vb_integer_value;
975                         variable.val.integer = &value;
976                         vb_display_string = format_var(&variable,
977                             variable_oid, variable_oid_length, vb_type,
978                             vb_length);
979 #else
980                         vb_display_string = NULL;
981 #endif
982                         if (vb_display_string != NULL) {
983                                 proto_tree_add_text(snmp_tree, tvb,
984                                     vb_value_start, length,
985                                     "Value: %s", vb_display_string);
986                         } else {
987                                 proto_tree_add_text(snmp_tree,tvb,
988                                     vb_value_start, length,
989                                     "Value: %s: %d (%#x)", vb_type_name,
990                                     vb_integer_value, vb_integer_value);
991                         }
992                 }
993                 break;
994
995         case SNMP_COUNTER:
996         case SNMP_GAUGE:
997         case SNMP_TIMETICKS:
998                 offset = dissect_ber_integer(FALSE, pinfo, NULL, tvb, start, -1, &vb_uinteger_value);
999                 length = offset - vb_value_start;
1000                 if (snmp_tree) {
1001 #ifdef HAVE_SOME_SNMP
1002                         value = vb_uinteger_value;
1003                         variable.val.integer = &value;
1004                         vb_display_string = format_var(&variable,
1005                             variable_oid, variable_oid_length, vb_type,
1006                             vb_length);
1007 #else
1008                         vb_display_string = NULL;
1009 #endif
1010                         if (vb_display_string != NULL) {
1011                                 proto_tree_add_text(snmp_tree, tvb,
1012                                     vb_value_start, length,
1013                                     "Value: %s", vb_display_string);
1014                         } else {
1015                                 proto_tree_add_text(snmp_tree, tvb,
1016                                     vb_value_start, length,
1017                                     "Value: %s: %u (%#x)", vb_type_name,
1018                                     vb_uinteger_value, vb_uinteger_value);
1019                         }
1020                 }
1021                 break;
1022         case SNMP_COUNTER64:
1023                 offset=dissect_ber_integer64(TRUE, pinfo, snmp_tree, tvb, offset, hf_snmp_counter64, NULL);
1024                 break;
1025         case SNMP_OCTETSTR:
1026         case SNMP_IPADDR:
1027         case SNMP_OPAQUE:
1028         case SNMP_NSAP:
1029         case SNMP_BITSTR:
1030                 offset = dissect_ber_octet_string(FALSE, pinfo, NULL, tvb, start, -1, out_tvb);
1031                 vb_octet_string = ep_tvb_memdup(tvb, vb_value_start, vb_length);
1032
1033                 length = offset - vb_value_start;
1034                 if (snmp_tree) {
1035 #ifdef HAVE_SOME_SNMP
1036                         variable.val.string = vb_octet_string;
1037                         vb_display_string = format_var(&variable,
1038                             variable_oid, variable_oid_length, vb_type,
1039                             vb_length);
1040 #else
1041                         vb_display_string = NULL;
1042 #endif
1043                         if (vb_display_string != NULL) {
1044                                 proto_tree_add_text(snmp_tree, tvb,
1045                                     vb_value_start, length,
1046                                     "Value: %s", vb_display_string);
1047                         } else {
1048                                 /*
1049                                  * If some characters are not printable,
1050                                  * display the string as bytes.
1051                                  */
1052                                 for (i = 0; i < vb_length; i++) {
1053                                         if (!(isprint(vb_octet_string[i])
1054                                             || isspace(vb_octet_string[i])))
1055                                                 break;
1056                                 }
1057                                 if (i < vb_length) {
1058                                         /*
1059                                          * We stopped, due to a non-printable
1060                                          * character, before we got to the end
1061                                          * of the string.
1062                                          */
1063                                         vb_display_string = ep_alloc(4*vb_length);
1064                                         buf = vb_display_string;
1065                                         len = g_snprintf(buf, 4*vb_length, "%03u", vb_octet_string[0]);
1066                                         buf += len;
1067                                         for (i = 1; i < vb_length; i++) {
1068                                                 len = g_snprintf(buf, 4*vb_length-(buf-vb_display_string), ".%03u",
1069                                                     vb_octet_string[i]);
1070                                                 buf += len;
1071                                         }
1072                                         proto_tree_add_text(snmp_tree, tvb, vb_value_start,
1073                                             length,
1074                                             "Value: %s: %s", vb_type_name,
1075                                             vb_display_string);
1076                                 } else {
1077                                         proto_tree_add_text(snmp_tree, tvb, vb_value_start,
1078                                             length,
1079                                             "Value: %s: %s", vb_type_name,
1080                                             SAFE_STRING(vb_octet_string, vb_length));
1081                                 }
1082                         }
1083                 }
1084                 break;
1085
1086         case SNMP_NULL:
1087                 dissect_ber_null(FALSE, pinfo, NULL, tvb, start, -1);
1088                 length = offset - vb_value_start;
1089                 if (snmp_tree) {
1090                         proto_tree_add_text(snmp_tree, tvb, vb_value_start, length,
1091                             "Value: %s", vb_type_name);
1092                 }
1093                 break;
1094
1095         case SNMP_OBJECTID:
1096                 /* XXX Redo this using dissect_ber_object_identifier when
1097                    it returns tvb or some other binary form of an OID */
1098                 oid_buf = tvb_get_ptr(tvb, vb_value_start, vb_length);
1099                 vb_oid = ep_alloc((vb_length+1) * sizeof(gulong));
1100                 vb_oid_length = oid_to_subid_buf(oid_buf, vb_length, vb_oid, ((vb_length+1) * sizeof(gulong)));
1101
1102                 offset = offset + vb_length;
1103                 length = offset - vb_value_start;
1104                 if (snmp_tree) {
1105 #ifdef HAVE_SOME_SNMP
1106                         variable.val.objid = vb_oid;
1107                         vb_display_string = format_var(&variable,
1108                             variable_oid, variable_oid_length, vb_type,
1109                             vb_oid_length * sizeof (subid_t));
1110                         if (vb_display_string != NULL) {
1111                                 proto_tree_add_text(snmp_tree, tvb,
1112                                     vb_value_start, length,
1113                                     "Value: %s", vb_display_string);
1114                         } else {
1115                                 proto_tree_add_text(snmp_tree, tvb,
1116                                     vb_value_start, length,
1117                                     "Value: %s: [Out of memory]", vb_type_name);
1118                         }
1119 #else /* HAVE_SOME_SNMP */
1120                         vb_display_string = format_oid(vb_oid, vb_oid_length);
1121                         if (vb_display_string != NULL) {
1122                                 proto_tree_add_text(snmp_tree, tvb,
1123                                     vb_value_start, length,
1124                                     "Value: %s: %s", vb_type_name,
1125                                     vb_display_string);
1126                         } else {
1127                                 proto_tree_add_text(snmp_tree, tvb,
1128                                     vb_value_start, length,
1129                                     "Value: %s: [Out of memory]", vb_type_name);
1130                         }
1131 #endif /* HAVE_SOME_SNMP */
1132                 }
1133                 break;
1134
1135         case SNMP_NOSUCHOBJECT:
1136                 length = offset - start;
1137                 if (snmp_tree) {
1138                         proto_tree_add_text(snmp_tree, tvb, offset, length,
1139                             "Value: %s: no such object", vb_type_name);
1140                 }
1141                 break;
1142
1143         case SNMP_NOSUCHINSTANCE:
1144                 length = offset - start;
1145                 if (snmp_tree) {
1146                         proto_tree_add_text(snmp_tree, tvb, offset, length,
1147                             "Value: %s: no such instance", vb_type_name);
1148                 }
1149                 break;
1150
1151         case SNMP_ENDOFMIBVIEW:
1152                 length = offset - start;
1153                 if (snmp_tree) {
1154                         proto_tree_add_text(snmp_tree, tvb, offset, length,
1155                             "Value: %s: end of mib view", vb_type_name);
1156                 }
1157                 break;
1158
1159         default:
1160                 DISSECTOR_ASSERT_NOT_REACHED();
1161                 return;
1162         }
1163         length = offset - start;
1164         *lengthp = length;
1165         return;
1166 }
1167
1168
1169 /*--- Included file: packet-snmp-fn.c ---*/
1170 #line 1 "packet-snmp-fn.c"
1171 /*--- Fields for imported types ---*/
1172
1173
1174
1175
1176 static int
1177 dissect_snmp_ObjectName(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1178   offset = dissect_ber_object_identifier(implicit_tag, pinfo, tree, tvb, offset, hf_index, &oid_tvb);
1179
1180   return offset;
1181 }
1182 static int dissect_name(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1183   return dissect_snmp_ObjectName(FALSE, tvb, offset, pinfo, tree, hf_snmp_name);
1184 }
1185 static int dissect_subtree(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1186   return dissect_snmp_ObjectName(FALSE, tvb, offset, pinfo, tree, hf_snmp_subtree);
1187 }
1188
1189
1190
1191 static int
1192 dissect_snmp_NotificationName(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1193   offset = dissect_ber_object_identifier(implicit_tag, pinfo, tree, tvb, offset, hf_index, NULL);
1194
1195   return offset;
1196 }
1197
1198
1199
1200 static int
1201 dissect_snmp_Integer_value(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1202 #line 233 "snmp.cnf"
1203         guint length;
1204         
1205         snmp_variable_decode(tvb, tree, pinfo, oid_tvb, offset, &length, NULL);
1206         offset = offset + length;
1207
1208
1209
1210   return offset;
1211 }
1212 static int dissect_integer_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1213   return dissect_snmp_Integer_value(FALSE, tvb, offset, pinfo, tree, hf_snmp_integer_value);
1214 }
1215
1216
1217
1218 static int
1219 dissect_snmp_String_value(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1220 #line 227 "snmp.cnf"
1221         guint length;
1222         
1223         snmp_variable_decode(tvb, tree, pinfo, oid_tvb, offset, &length, &value_tvb);
1224         offset = offset + length;
1225
1226
1227
1228   return offset;
1229 }
1230 static int dissect_string_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1231   return dissect_snmp_String_value(FALSE, tvb, offset, pinfo, tree, hf_snmp_string_value);
1232 }
1233
1234
1235
1236 static int
1237 dissect_snmp_ObjectID_value(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1238 #line 239 "snmp.cnf"
1239         guint length;
1240         
1241         snmp_variable_decode(tvb, tree, pinfo, oid_tvb, offset, &length, NULL);
1242         offset = offset + length;
1243
1244
1245
1246   return offset;
1247 }
1248 static int dissect_objectID_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1249   return dissect_snmp_ObjectID_value(FALSE, tvb, offset, pinfo, tree, hf_snmp_objectID_value);
1250 }
1251
1252
1253
1254 static int
1255 dissect_snmp_Empty(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1256 #line 245 "snmp.cnf"
1257         guint length;
1258         
1259         snmp_variable_decode(tvb, tree, pinfo, oid_tvb, offset, &length, NULL);
1260         offset = offset + length;
1261
1262
1263
1264
1265
1266   return offset;
1267 }
1268 static int dissect_empty(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1269   return dissect_snmp_Empty(FALSE, tvb, offset, pinfo, tree, hf_snmp_empty);
1270 }
1271
1272
1273 static const value_string snmp_SimpleSyntax_vals[] = {
1274   {   0, "integer-value" },
1275   {   1, "string-value" },
1276   {   2, "objectID-value" },
1277   {   3, "empty" },
1278   { 0, NULL }
1279 };
1280
1281 static const ber_choice_t SimpleSyntax_choice[] = {
1282   {   0, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_integer_value },
1283   {   1, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_string_value },
1284   {   2, BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_objectID_value },
1285   {   3, BER_CLASS_UNI, BER_UNI_TAG_NULL, BER_FLAGS_NOOWNTAG, dissect_empty },
1286   { 0, 0, 0, 0, NULL }
1287 };
1288
1289 static int
1290 dissect_snmp_SimpleSyntax(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1291   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
1292                                  SimpleSyntax_choice, hf_index, ett_snmp_SimpleSyntax,
1293                                  NULL);
1294
1295   return offset;
1296 }
1297 static int dissect_simple(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1298   return dissect_snmp_SimpleSyntax(FALSE, tvb, offset, pinfo, tree, hf_snmp_simple);
1299 }
1300
1301
1302
1303 static int
1304 dissect_snmp_IpAddress(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1305   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1306                                        NULL);
1307
1308   return offset;
1309 }
1310 static int dissect_ipAddress_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1311   return dissect_snmp_IpAddress(FALSE, tvb, offset, pinfo, tree, hf_snmp_ipAddress_value);
1312 }
1313 static int dissect_internet(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1314   return dissect_snmp_IpAddress(FALSE, tvb, offset, pinfo, tree, hf_snmp_internet);
1315 }
1316
1317
1318
1319 static int
1320 dissect_snmp_Counter32(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1321   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1322                                   NULL);
1323
1324   return offset;
1325 }
1326 static int dissect_counter_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1327   return dissect_snmp_Counter32(FALSE, tvb, offset, pinfo, tree, hf_snmp_counter_value);
1328 }
1329
1330
1331
1332 static int
1333 dissect_snmp_TimeTicks(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1334   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1335                                   NULL);
1336
1337   return offset;
1338 }
1339 static int dissect_timeticks_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1340   return dissect_snmp_TimeTicks(FALSE, tvb, offset, pinfo, tree, hf_snmp_timeticks_value);
1341 }
1342 static int dissect_time_stamp(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1343   return dissect_snmp_TimeTicks(FALSE, tvb, offset, pinfo, tree, hf_snmp_time_stamp);
1344 }
1345
1346
1347
1348 static int
1349 dissect_snmp_Opaque(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1350   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1351                                        NULL);
1352
1353   return offset;
1354 }
1355 static int dissect_arbitrary_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1356   return dissect_snmp_Opaque(FALSE, tvb, offset, pinfo, tree, hf_snmp_arbitrary_value);
1357 }
1358
1359
1360
1361 static int
1362 dissect_snmp_Counter64(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1363   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1364                                   NULL);
1365
1366   return offset;
1367 }
1368 static int dissect_big_counter_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1369   return dissect_snmp_Counter64(FALSE, tvb, offset, pinfo, tree, hf_snmp_big_counter_value);
1370 }
1371
1372
1373
1374 static int
1375 dissect_snmp_Unsigned32(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1376   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1377                                   NULL);
1378
1379   return offset;
1380 }
1381 static int dissect_unsigned_integer_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1382   return dissect_snmp_Unsigned32(FALSE, tvb, offset, pinfo, tree, hf_snmp_unsigned_integer_value);
1383 }
1384
1385
1386 static const value_string snmp_ApplicationSyntax_vals[] = {
1387   {   0, "ipAddress-value" },
1388   {   1, "counter-value" },
1389   {   3, "timeticks-value" },
1390   {   4, "arbitrary-value" },
1391   {   6, "big-counter-value" },
1392   {   2, "unsigned-integer-value" },
1393   { 0, NULL }
1394 };
1395
1396 static const ber_choice_t ApplicationSyntax_choice[] = {
1397   {   0, BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_ipAddress_value },
1398   {   1, BER_CLASS_APP, 1, BER_FLAGS_NOOWNTAG, dissect_counter_value },
1399   {   3, BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_timeticks_value },
1400   {   4, BER_CLASS_APP, 4, BER_FLAGS_NOOWNTAG, dissect_arbitrary_value },
1401   {   6, BER_CLASS_APP, 6, BER_FLAGS_NOOWNTAG, dissect_big_counter_value },
1402   {   2, BER_CLASS_APP, 2, BER_FLAGS_NOOWNTAG, dissect_unsigned_integer_value },
1403   { 0, 0, 0, 0, NULL }
1404 };
1405
1406 static int
1407 dissect_snmp_ApplicationSyntax(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1408   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
1409                                  ApplicationSyntax_choice, hf_index, ett_snmp_ApplicationSyntax,
1410                                  NULL);
1411
1412   return offset;
1413 }
1414 static int dissect_application_wide(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1415   return dissect_snmp_ApplicationSyntax(FALSE, tvb, offset, pinfo, tree, hf_snmp_application_wide);
1416 }
1417
1418
1419 static const value_string snmp_ObjectSyntax_vals[] = {
1420   { -1/*choice*/, "simple" },
1421   { -1/*choice*/, "application-wide" },
1422   { 0, NULL }
1423 };
1424
1425 static const ber_choice_t ObjectSyntax_choice[] = {
1426   { -1/*choice*/, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_simple },
1427   { -1/*choice*/, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_application_wide },
1428   { 0, 0, 0, 0, NULL }
1429 };
1430
1431 static int
1432 dissect_snmp_ObjectSyntax(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1433   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
1434                                  ObjectSyntax_choice, hf_index, ett_snmp_ObjectSyntax,
1435                                  NULL);
1436
1437   return offset;
1438 }
1439 static int dissect_value(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1440   return dissect_snmp_ObjectSyntax(FALSE, tvb, offset, pinfo, tree, hf_snmp_value);
1441 }
1442
1443
1444
1445 static int
1446 dissect_snmp_Integer32(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1447   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1448                                   NULL);
1449
1450   return offset;
1451 }
1452 static int dissect_bulkPDU_request_id(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1453   return dissect_snmp_Integer32(FALSE, tvb, offset, pinfo, tree, hf_snmp_bulkPDU_request_id);
1454 }
1455
1456
1457 static const value_string snmp_NetworkAddress_vals[] = {
1458   {   0, "internet" },
1459   { 0, NULL }
1460 };
1461
1462 static const ber_choice_t NetworkAddress_choice[] = {
1463   {   0, BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_internet },
1464   { 0, 0, 0, 0, NULL }
1465 };
1466
1467 static int
1468 dissect_snmp_NetworkAddress(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1469   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
1470                                  NetworkAddress_choice, hf_index, ett_snmp_NetworkAddress,
1471                                  NULL);
1472
1473   return offset;
1474 }
1475 static int dissect_agent_addr(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1476   return dissect_snmp_NetworkAddress(FALSE, tvb, offset, pinfo, tree, hf_snmp_agent_addr);
1477 }
1478
1479
1480
1481 static int
1482 dissect_snmp_Gauge32(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1483   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1484                                   NULL);
1485
1486   return offset;
1487 }
1488
1489
1490 static const value_string snmp_Version_vals[] = {
1491   {   0, "version-1" },
1492   {   1, "v2c" },
1493   {   2, "v2u" },
1494   {   3, "snmpv3" },
1495   { 0, NULL }
1496 };
1497
1498
1499 static int
1500 dissect_snmp_Version(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1501   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1502                                   NULL);
1503
1504   return offset;
1505 }
1506 static int dissect_version(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1507   return dissect_snmp_Version(FALSE, tvb, offset, pinfo, tree, hf_snmp_version);
1508 }
1509 static int dissect_msgVersion(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1510   return dissect_snmp_Version(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgVersion);
1511 }
1512
1513
1514
1515 static int
1516 dissect_snmp_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1517   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1518                                        NULL);
1519
1520   return offset;
1521 }
1522 static int dissect_community(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1523   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_community);
1524 }
1525 static int dissect_parameters(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1526   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_parameters);
1527 }
1528 static int dissect_encrypted(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1529   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_encrypted);
1530 }
1531 static int dissect_msgAuthenticationParameters(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1532   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgAuthenticationParameters);
1533 }
1534 static int dissect_msgPrivacyParameters(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1535   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgPrivacyParameters);
1536 }
1537 static int dissect_encryptedPDU(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1538   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_encryptedPDU);
1539 }
1540 static int dissect_contextEngineID(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1541   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_contextEngineID);
1542 }
1543 static int dissect_contextName(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1544   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_contextName);
1545 }
1546 static int dissect_password(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1547   return dissect_snmp_OCTET_STRING(FALSE, tvb, offset, pinfo, tree, hf_snmp_password);
1548 }
1549
1550
1551
1552 static int
1553 dissect_snmp_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1554   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1555                                   NULL);
1556
1557   return offset;
1558 }
1559 static int dissect_request_id(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1560   return dissect_snmp_INTEGER(FALSE, tvb, offset, pinfo, tree, hf_snmp_request_id);
1561 }
1562 static int dissect_error_index(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1563   return dissect_snmp_INTEGER(FALSE, tvb, offset, pinfo, tree, hf_snmp_error_index);
1564 }
1565 static int dissect_specific_trap(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1566   return dissect_snmp_INTEGER(FALSE, tvb, offset, pinfo, tree, hf_snmp_specific_trap);
1567 }
1568
1569
1570 static const value_string snmp_T_error_status_vals[] = {
1571   {   0, "noError" },
1572   {   1, "tooBig" },
1573   {   2, "noSuchName" },
1574   {   3, "badValue" },
1575   {   4, "readOnly" },
1576   {   5, "genErr" },
1577   {   6, "noAccess" },
1578   {   7, "wrongType" },
1579   {   8, "wrongLength" },
1580   {   9, "wrongEncoding" },
1581   {  10, "wrongValue" },
1582   {  11, "noCreation" },
1583   {  12, "inconsistentValue" },
1584   {  13, "resourceUnavailable" },
1585   {  14, "commitFailed" },
1586   {  15, "undoFailed" },
1587   {  16, "authorizationError" },
1588   {  17, "notWritable" },
1589   {  18, "inconsistentName" },
1590   { 0, NULL }
1591 };
1592
1593
1594 static int
1595 dissect_snmp_T_error_status(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1596   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1597                                   NULL);
1598
1599   return offset;
1600 }
1601 static int dissect_error_status(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1602   return dissect_snmp_T_error_status(FALSE, tvb, offset, pinfo, tree, hf_snmp_error_status);
1603 }
1604
1605
1606
1607 static int
1608 dissect_snmp_NULL(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1609   offset = dissect_ber_null(implicit_tag, pinfo, tree, tvb, offset, hf_index);
1610
1611   return offset;
1612 }
1613 static int dissect_unSpecified(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1614   return dissect_snmp_NULL(FALSE, tvb, offset, pinfo, tree, hf_snmp_unSpecified);
1615 }
1616 static int dissect_noSuchObject_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1617   return dissect_snmp_NULL(TRUE, tvb, offset, pinfo, tree, hf_snmp_noSuchObject);
1618 }
1619 static int dissect_noSuchInstance_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1620   return dissect_snmp_NULL(TRUE, tvb, offset, pinfo, tree, hf_snmp_noSuchInstance);
1621 }
1622 static int dissect_endOfMibView_impl(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1623   return dissect_snmp_NULL(TRUE, tvb, offset, pinfo, tree, hf_snmp_endOfMibView);
1624 }
1625
1626
1627 static const value_string snmp_ValueType_vals[] = {
1628   {   0, "value" },
1629   {   1, "unSpecified" },
1630   {   2, "noSuchObject" },
1631   {   3, "noSuchInstance" },
1632   {   4, "endOfMibView" },
1633   { 0, NULL }
1634 };
1635
1636 static const ber_choice_t ValueType_choice[] = {
1637   {   0, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_value },
1638   {   1, BER_CLASS_UNI, BER_UNI_TAG_NULL, BER_FLAGS_NOOWNTAG, dissect_unSpecified },
1639   {   2, BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_noSuchObject_impl },
1640   {   3, BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_noSuchInstance_impl },
1641   {   4, BER_CLASS_CON, 2, BER_FLAGS_IMPLTAG, dissect_endOfMibView_impl },
1642   { 0, 0, 0, 0, NULL }
1643 };
1644
1645 static int
1646 dissect_snmp_ValueType(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1647   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
1648                                  ValueType_choice, hf_index, ett_snmp_ValueType,
1649                                  NULL);
1650
1651   return offset;
1652 }
1653 static int dissect_valueType(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1654   return dissect_snmp_ValueType(FALSE, tvb, offset, pinfo, tree, hf_snmp_valueType);
1655 }
1656
1657
1658 static const ber_sequence_t VarBind_sequence[] = {
1659   { BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_name },
1660   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_valueType },
1661   { 0, 0, 0, NULL }
1662 };
1663
1664 static int
1665 dissect_snmp_VarBind(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1666 #line 213 "snmp.cnf"
1667         oid_tvb = NULL;
1668         value_tvb = NULL;
1669    offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1670                                    VarBind_sequence, hf_index, ett_snmp_VarBind);
1671
1672         if (oid_tvb && value_tvb) {
1673                 next_tvb_add_string(&var_list, value_tvb, (snmp_var_in_tree) ? tree : NULL, 
1674                         variable_oid_dissector_table, 
1675                         oid_to_str(tvb_get_ptr(oid_tvb, 0, tvb_length(oid_tvb)), tvb_length(oid_tvb)));
1676         }
1677
1678
1679
1680   return offset;
1681 }
1682 static int dissect_VarBindList_item(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1683   return dissect_snmp_VarBind(FALSE, tvb, offset, pinfo, tree, hf_snmp_VarBindList_item);
1684 }
1685
1686
1687 static const ber_sequence_t VarBindList_sequence_of[1] = {
1688   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_VarBindList_item },
1689 };
1690
1691 static int
1692 dissect_snmp_VarBindList(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1693   offset = dissect_ber_sequence_of(implicit_tag, pinfo, tree, tvb, offset,
1694                                       VarBindList_sequence_of, hf_index, ett_snmp_VarBindList);
1695
1696   return offset;
1697 }
1698 static int dissect_variable_bindings(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1699   return dissect_snmp_VarBindList(FALSE, tvb, offset, pinfo, tree, hf_snmp_variable_bindings);
1700 }
1701
1702
1703 static const ber_sequence_t PDU_sequence[] = {
1704   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_request_id },
1705   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_error_status },
1706   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_error_index },
1707   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_variable_bindings },
1708   { 0, 0, 0, NULL }
1709 };
1710
1711 static int
1712 dissect_snmp_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1713   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1714                                    PDU_sequence, hf_index, ett_snmp_PDU);
1715
1716   return offset;
1717 }
1718
1719
1720
1721 static int
1722 dissect_snmp_GetRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1723   offset = dissect_snmp_PDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1724
1725   return offset;
1726 }
1727
1728
1729
1730 static int
1731 dissect_snmp_T_get_request(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1732 #line 31 "snmp.cnf"
1733  gint8 class;
1734  gboolean pc, ind_field;
1735  gint32 tag;
1736  guint32 len1;
1737
1738  if(!implicit_tag){
1739    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
1740     * XXX is some conformance file magic to work around that bug
1741     */
1742     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
1743     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
1744  }
1745  offset = dissect_snmp_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
1746
1747
1748
1749   return offset;
1750 }
1751 static int dissect_get_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1752   return dissect_snmp_T_get_request(FALSE, tvb, offset, pinfo, tree, hf_snmp_get_request);
1753 }
1754
1755
1756
1757 static int
1758 dissect_snmp_GetNextRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1759   offset = dissect_snmp_PDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1760
1761   return offset;
1762 }
1763
1764
1765
1766 static int
1767 dissect_snmp_T_get_next_request(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1768 #line 46 "snmp.cnf"
1769  gint8 class;
1770  gboolean pc, ind_field;
1771  gint32 tag;
1772  guint32 len1;
1773
1774  if(!implicit_tag){
1775    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
1776     * XXX is some conformance file magic to work around that bug
1777     */
1778     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
1779     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
1780  }
1781  offset = dissect_snmp_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
1782
1783
1784
1785   return offset;
1786 }
1787 static int dissect_get_next_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1788   return dissect_snmp_T_get_next_request(FALSE, tvb, offset, pinfo, tree, hf_snmp_get_next_request);
1789 }
1790
1791
1792
1793 static int
1794 dissect_snmp_GetResponse_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1795   offset = dissect_snmp_PDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1796
1797   return offset;
1798 }
1799
1800
1801
1802 static int
1803 dissect_snmp_T_get_response(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1804 #line 61 "snmp.cnf"
1805  gint8 class;
1806  gboolean pc, ind_field;
1807  gint32 tag;
1808  guint32 len1;
1809
1810  if(!implicit_tag){
1811    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
1812     * XXX is some conformance file magic to work around that bug
1813     */
1814     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
1815     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
1816  }
1817  offset = dissect_snmp_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
1818
1819
1820
1821   return offset;
1822 }
1823 static int dissect_get_response(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1824   return dissect_snmp_T_get_response(FALSE, tvb, offset, pinfo, tree, hf_snmp_get_response);
1825 }
1826
1827
1828
1829 static int
1830 dissect_snmp_SetRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1831   offset = dissect_snmp_PDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1832
1833   return offset;
1834 }
1835
1836
1837
1838 static int
1839 dissect_snmp_T_set_request(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1840 #line 76 "snmp.cnf"
1841  gint8 class;
1842  gboolean pc, ind_field;
1843  gint32 tag;
1844  guint32 len1;
1845
1846  if(!implicit_tag){
1847    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
1848     * XXX is some conformance file magic to work around that bug
1849     */
1850     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
1851     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
1852  }
1853  offset = dissect_snmp_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
1854
1855
1856
1857
1858   return offset;
1859 }
1860 static int dissect_set_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1861   return dissect_snmp_T_set_request(FALSE, tvb, offset, pinfo, tree, hf_snmp_set_request);
1862 }
1863
1864
1865
1866 static int
1867 dissect_snmp_OBJECT_IDENTIFIER(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1868   offset = dissect_ber_object_identifier(implicit_tag, pinfo, tree, tvb, offset, hf_index, NULL);
1869
1870   return offset;
1871 }
1872 static int dissect_enterprise(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1873   return dissect_snmp_OBJECT_IDENTIFIER(FALSE, tvb, offset, pinfo, tree, hf_snmp_enterprise);
1874 }
1875 static int dissect_identity(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1876   return dissect_snmp_OBJECT_IDENTIFIER(FALSE, tvb, offset, pinfo, tree, hf_snmp_identity);
1877 }
1878
1879
1880 static const value_string snmp_T_generic_trap_vals[] = {
1881   {   0, "coldStart" },
1882   {   1, "warmStart" },
1883   {   2, "linkDown" },
1884   {   3, "linkUp" },
1885   {   4, "authenticationFailure" },
1886   {   5, "egpNeighborLoss" },
1887   {   6, "enterpriseSpecific" },
1888   { 0, NULL }
1889 };
1890
1891
1892 static int
1893 dissect_snmp_T_generic_trap(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1894   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1895                                   NULL);
1896
1897   return offset;
1898 }
1899 static int dissect_generic_trap(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1900   return dissect_snmp_T_generic_trap(FALSE, tvb, offset, pinfo, tree, hf_snmp_generic_trap);
1901 }
1902
1903
1904 static const ber_sequence_t Trap_PDU_sequence[] = {
1905   { BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_enterprise },
1906   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_agent_addr },
1907   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_generic_trap },
1908   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_specific_trap },
1909   { BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_time_stamp },
1910   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_variable_bindings },
1911   { 0, 0, 0, NULL }
1912 };
1913
1914 static int
1915 dissect_snmp_Trap_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1916   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1917                                    Trap_PDU_sequence, hf_index, ett_snmp_Trap_PDU);
1918
1919   return offset;
1920 }
1921
1922
1923
1924 static int
1925 dissect_snmp_T_trap(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1926 #line 92 "snmp.cnf"
1927  gint8 class;
1928  gboolean pc, ind_field;
1929  gint32 tag;
1930  guint32 len1;
1931
1932  if(!implicit_tag){
1933    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
1934     * XXX is some conformance file magic to work around that bug
1935     */
1936     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
1937     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
1938  }
1939  offset = dissect_snmp_Trap_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
1940
1941
1942
1943   return offset;
1944 }
1945 static int dissect_trap(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1946   return dissect_snmp_T_trap(FALSE, tvb, offset, pinfo, tree, hf_snmp_trap);
1947 }
1948
1949
1950
1951 static int
1952 dissect_snmp_INTEGER_0_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1953   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
1954                                   NULL);
1955
1956   return offset;
1957 }
1958 static int dissect_msgAuthoritativeEngineBoots(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1959   return dissect_snmp_INTEGER_0_2147483647(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgAuthoritativeEngineBoots);
1960 }
1961 static int dissect_msgAuthoritativeEngineTime(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1962   return dissect_snmp_INTEGER_0_2147483647(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgAuthoritativeEngineTime);
1963 }
1964 static int dissect_msgID(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1965   return dissect_snmp_INTEGER_0_2147483647(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgID);
1966 }
1967 static int dissect_non_repeaters(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1968   return dissect_snmp_INTEGER_0_2147483647(FALSE, tvb, offset, pinfo, tree, hf_snmp_non_repeaters);
1969 }
1970 static int dissect_max_repetitions(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
1971   return dissect_snmp_INTEGER_0_2147483647(FALSE, tvb, offset, pinfo, tree, hf_snmp_max_repetitions);
1972 }
1973
1974
1975 static const ber_sequence_t BulkPDU_sequence[] = {
1976   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_bulkPDU_request_id },
1977   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_non_repeaters },
1978   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_max_repetitions },
1979   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_variable_bindings },
1980   { 0, 0, 0, NULL }
1981 };
1982
1983 static int
1984 dissect_snmp_BulkPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1985   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
1986                                    BulkPDU_sequence, hf_index, ett_snmp_BulkPDU);
1987
1988   return offset;
1989 }
1990
1991
1992
1993 static int
1994 dissect_snmp_GetBulkRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
1995   offset = dissect_snmp_BulkPDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
1996
1997   return offset;
1998 }
1999
2000
2001
2002 static int
2003 dissect_snmp_T_getBulkRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2004 #line 107 "snmp.cnf"
2005  gint8 class;
2006  gboolean pc, ind_field;
2007  gint32 tag;
2008  guint32 len1;
2009
2010  if(!implicit_tag){
2011    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
2012     * XXX is some conformance file magic to work around that bug
2013     */
2014     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
2015     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
2016  }
2017  offset = dissect_snmp_GetBulkRequest_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
2018
2019
2020
2021   return offset;
2022 }
2023 static int dissect_getBulkRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2024   return dissect_snmp_T_getBulkRequest(FALSE, tvb, offset, pinfo, tree, hf_snmp_getBulkRequest);
2025 }
2026
2027
2028
2029 static int
2030 dissect_snmp_InformRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2031   offset = dissect_snmp_PDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
2032
2033   return offset;
2034 }
2035
2036
2037
2038 static int
2039 dissect_snmp_T_informRequest(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2040 #line 122 "snmp.cnf"
2041  gint8 class;
2042  gboolean pc, ind_field;
2043  gint32 tag;
2044  guint32 len1;
2045
2046  if(!implicit_tag){
2047    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
2048     * XXX is some conformance file magic to work around that bug
2049     */
2050     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
2051     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
2052  }
2053  offset = dissect_snmp_InformRequest_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
2054
2055
2056
2057   return offset;
2058 }
2059 static int dissect_informRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2060   return dissect_snmp_T_informRequest(FALSE, tvb, offset, pinfo, tree, hf_snmp_informRequest);
2061 }
2062
2063
2064
2065 static int
2066 dissect_snmp_SNMPv2_Trap_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2067   offset = dissect_snmp_PDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
2068
2069   return offset;
2070 }
2071
2072
2073
2074 static int
2075 dissect_snmp_T_sNMPv2_Trap(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2076 #line 137 "snmp.cnf"
2077  gint8 class;
2078  gboolean pc, ind_field;
2079  gint32 tag;
2080  guint32 len1;
2081
2082  if(!implicit_tag){
2083    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
2084     * XXX is some conformance file magic to work around that bug
2085     */
2086     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
2087     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
2088  }
2089  offset = dissect_snmp_SNMPv2_Trap_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
2090
2091
2092
2093   return offset;
2094 }
2095 static int dissect_sNMPv2_Trap(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2096   return dissect_snmp_T_sNMPv2_Trap(FALSE, tvb, offset, pinfo, tree, hf_snmp_sNMPv2_Trap);
2097 }
2098
2099
2100
2101 static int
2102 dissect_snmp_Report_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2103   offset = dissect_snmp_PDU(implicit_tag, tvb, offset, pinfo, tree, hf_index);
2104
2105   return offset;
2106 }
2107
2108
2109
2110 static int
2111 dissect_snmp_T_report(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2112 #line 152 "snmp.cnf"
2113  gint8 class;
2114  gboolean pc, ind_field;
2115  gint32 tag;
2116  guint32 len1;
2117
2118  if(!implicit_tag){
2119    /* XXX  asn2wrs can not yet handle tagged assignment yes so this
2120     * XXX is some conformance file magic to work around that bug
2121     */
2122     offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
2123     offset = get_ber_length(tree, tvb, offset, &len1, &ind_field);
2124  }
2125  offset = dissect_snmp_Report_PDU(TRUE, tvb, offset, pinfo, tree, hf_index);
2126
2127
2128
2129   return offset;
2130 }
2131 static int dissect_report(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2132   return dissect_snmp_T_report(FALSE, tvb, offset, pinfo, tree, hf_snmp_report);
2133 }
2134
2135
2136 static const value_string snmp_PDUs_vals[] = {
2137   {   0, "get-request" },
2138   {   1, "get-next-request" },
2139   {   2, "get-response" },
2140   {   3, "set-request" },
2141   {   4, "trap" },
2142   {   5, "getBulkRequest" },
2143   {   6, "informRequest" },
2144   {   7, "sNMPv2-Trap" },
2145   {   8, "report" },
2146   { 0, NULL }
2147 };
2148
2149 static const ber_choice_t PDUs_choice[] = {
2150   {   0, BER_CLASS_CON, 0, BER_FLAGS_NOOWNTAG, dissect_get_request },
2151   {   1, BER_CLASS_CON, 1, BER_FLAGS_NOOWNTAG, dissect_get_next_request },
2152   {   2, BER_CLASS_CON, 2, BER_FLAGS_NOOWNTAG, dissect_get_response },
2153   {   3, BER_CLASS_CON, 3, BER_FLAGS_NOOWNTAG, dissect_set_request },
2154   {   4, BER_CLASS_CON, 4, BER_FLAGS_NOOWNTAG, dissect_trap },
2155   {   5, BER_CLASS_CON, 5, BER_FLAGS_NOOWNTAG, dissect_getBulkRequest },
2156   {   6, BER_CLASS_CON, 6, BER_FLAGS_NOOWNTAG, dissect_informRequest },
2157   {   7, BER_CLASS_CON, 7, BER_FLAGS_NOOWNTAG, dissect_sNMPv2_Trap },
2158   {   8, BER_CLASS_CON, 8, BER_FLAGS_NOOWNTAG, dissect_report },
2159   { 0, 0, 0, 0, NULL }
2160 };
2161
2162 static int
2163 dissect_snmp_PDUs(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2164 #line 23 "snmp.cnf"
2165
2166 gint pdu_type;
2167
2168   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
2169                                  PDUs_choice, hf_index, ett_snmp_PDUs,
2170                                  &pdu_type);
2171
2172         if (check_col(pinfo->cinfo, COL_INFO))
2173                 col_add_str(pinfo->cinfo, COL_INFO, val_to_str(pdu_type, snmp_PDUs_vals,"Unknown PDU type (%u)"));
2174
2175
2176
2177   return offset;
2178 }
2179 static int dissect_data(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2180   return dissect_snmp_PDUs(FALSE, tvb, offset, pinfo, tree, hf_snmp_data);
2181 }
2182 static int dissect_v2u_plaintext(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2183   return dissect_snmp_PDUs(FALSE, tvb, offset, pinfo, tree, hf_snmp_v2u_plaintext);
2184 }
2185 static int dissect_pDUs(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2186   return dissect_snmp_PDUs(FALSE, tvb, offset, pinfo, tree, hf_snmp_pDUs);
2187 }
2188
2189
2190 static const ber_sequence_t Message_sequence[] = {
2191   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_version },
2192   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_community },
2193   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_data },
2194   { 0, 0, 0, NULL }
2195 };
2196
2197 static int
2198 dissect_snmp_Message(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2199   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2200                                    Message_sequence, hf_index, ett_snmp_Message);
2201
2202   return offset;
2203 }
2204
2205
2206 static const value_string snmp_T_datav2u_vals[] = {
2207   {   0, "plaintext" },
2208   {   1, "encrypted" },
2209   { 0, NULL }
2210 };
2211
2212 static const ber_choice_t T_datav2u_choice[] = {
2213   {   0, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_v2u_plaintext },
2214   {   1, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_encrypted },
2215   { 0, 0, 0, 0, NULL }
2216 };
2217
2218 static int
2219 dissect_snmp_T_datav2u(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2220   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
2221                                  T_datav2u_choice, hf_index, ett_snmp_T_datav2u,
2222                                  NULL);
2223
2224   return offset;
2225 }
2226 static int dissect_datav2u(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2227   return dissect_snmp_T_datav2u(FALSE, tvb, offset, pinfo, tree, hf_snmp_datav2u);
2228 }
2229
2230
2231 static const ber_sequence_t Messagev2u_sequence[] = {
2232   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_version },
2233   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_parameters },
2234   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_datav2u },
2235   { 0, 0, 0, NULL }
2236 };
2237
2238 static int
2239 dissect_snmp_Messagev2u(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2240   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2241                                    Messagev2u_sequence, hf_index, ett_snmp_Messagev2u);
2242
2243   return offset;
2244 }
2245
2246
2247
2248 static int
2249 dissect_snmp_SnmpEngineID(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2250 #line 189 "snmp.cnf"
2251         tvbuff_t *parameter_tvb = NULL;
2252         proto_tree *engineid_tree = NULL;
2253         proto_item *item = NULL;
2254
2255    offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2256                                        &parameter_tvb);
2257
2258  if (parameter_tvb)
2259         dissect_snmp_engineid(tree, parameter_tvb, 0, tvb_length_remaining(parameter_tvb,0));
2260
2261
2262
2263   return offset;
2264 }
2265 static int dissect_msgAuthoritativeEngineID(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2266   return dissect_snmp_SnmpEngineID(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgAuthoritativeEngineID);
2267 }
2268
2269
2270
2271 static int
2272 dissect_snmp_OCTET_STRING_SIZE_1_32(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2273   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2274                                        NULL);
2275
2276   return offset;
2277 }
2278 static int dissect_msgUserName(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2279   return dissect_snmp_OCTET_STRING_SIZE_1_32(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgUserName);
2280 }
2281
2282
2283 static const ber_sequence_t UsmSecurityParameters_sequence[] = {
2284   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_msgAuthoritativeEngineID },
2285   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_msgAuthoritativeEngineBoots },
2286   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_msgAuthoritativeEngineTime },
2287   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_msgUserName },
2288   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_msgAuthenticationParameters },
2289   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_msgPrivacyParameters },
2290   { 0, 0, 0, NULL }
2291 };
2292
2293 static int
2294 dissect_snmp_UsmSecurityParameters(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2295   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2296                                    UsmSecurityParameters_sequence, hf_index, ett_snmp_UsmSecurityParameters);
2297
2298   return offset;
2299 }
2300
2301
2302
2303 static int
2304 dissect_snmp_INTEGER_484_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2305   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2306                                   NULL);
2307
2308   return offset;
2309 }
2310 static int dissect_msgMaxSize(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2311   return dissect_snmp_INTEGER_484_2147483647(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgMaxSize);
2312 }
2313
2314
2315
2316 static int
2317 dissect_snmp_T_msgFlags(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2318 #line 202 "snmp.cnf"
2319         tvbuff_t *parameter_tvb = NULL;
2320
2321    offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2322                                        &parameter_tvb);
2323
2324  if (parameter_tvb){
2325
2326         proto_tree_add_item(tree, hf_snmp_v3_flags_report, parameter_tvb, 0, 1, FALSE);
2327         proto_tree_add_item(tree, hf_snmp_v3_flags_crypt, parameter_tvb, 0, 1, FALSE);
2328         proto_tree_add_item(tree, hf_snmp_v3_flags_auth, parameter_tvb, 0, 1, FALSE);
2329   }
2330
2331
2332
2333   return offset;
2334 }
2335 static int dissect_msgFlags(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2336   return dissect_snmp_T_msgFlags(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgFlags);
2337 }
2338
2339
2340
2341 static int
2342 dissect_snmp_T_msgSecurityModel(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2343   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2344                                   &MsgSecurityModel);
2345
2346   return offset;
2347 }
2348 static int dissect_msgSecurityModel(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2349   return dissect_snmp_T_msgSecurityModel(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgSecurityModel);
2350 }
2351
2352
2353 static const ber_sequence_t HeaderData_sequence[] = {
2354   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_msgID },
2355   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_msgMaxSize },
2356   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_msgFlags },
2357   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_msgSecurityModel },
2358   { 0, 0, 0, NULL }
2359 };
2360
2361 static int
2362 dissect_snmp_HeaderData(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2363   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2364                                    HeaderData_sequence, hf_index, ett_snmp_HeaderData);
2365
2366   return offset;
2367 }
2368 static int dissect_msgGlobalData(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2369   return dissect_snmp_HeaderData(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgGlobalData);
2370 }
2371
2372
2373
2374 static int
2375 dissect_snmp_T_msgSecurityParameters(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2376 #line 171 "snmp.cnf"
2377
2378         switch(MsgSecurityModel){
2379         case SNMP_SEC_USM:      /* 3 */
2380                 offset = dissect_snmp_UsmSecurityParameters(FALSE, tvb, offset+2, pinfo, tree, -1);
2381                 break;
2382         case SNMP_SEC_ANY:      /* 0 */
2383         case SNMP_SEC_V1:       /* 1 */
2384         case SNMP_SEC_V2C:      /* 2 */
2385         default:
2386                   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2387                                        NULL);
2388
2389                 break;
2390         }
2391
2392
2393
2394   return offset;
2395 }
2396 static int dissect_msgSecurityParameters(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2397   return dissect_snmp_T_msgSecurityParameters(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgSecurityParameters);
2398 }
2399
2400
2401 static const ber_sequence_t ScopedPDU_sequence[] = {
2402   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_contextEngineID },
2403   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_contextName },
2404   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_data },
2405   { 0, 0, 0, NULL }
2406 };
2407
2408 static int
2409 dissect_snmp_ScopedPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2410   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2411                                    ScopedPDU_sequence, hf_index, ett_snmp_ScopedPDU);
2412
2413   return offset;
2414 }
2415 static int dissect_plaintext(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2416   return dissect_snmp_ScopedPDU(FALSE, tvb, offset, pinfo, tree, hf_snmp_plaintext);
2417 }
2418
2419
2420 static const value_string snmp_ScopedPduData_vals[] = {
2421   {   0, "plaintext" },
2422   {   1, "encryptedPDU" },
2423   { 0, NULL }
2424 };
2425
2426 static const ber_choice_t ScopedPduData_choice[] = {
2427   {   0, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_plaintext },
2428   {   1, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_encryptedPDU },
2429   { 0, 0, 0, 0, NULL }
2430 };
2431
2432 static int
2433 dissect_snmp_ScopedPduData(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2434   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
2435                                  ScopedPduData_choice, hf_index, ett_snmp_ScopedPduData,
2436                                  NULL);
2437
2438   return offset;
2439 }
2440 static int dissect_msgData(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2441   return dissect_snmp_ScopedPduData(FALSE, tvb, offset, pinfo, tree, hf_snmp_msgData);
2442 }
2443
2444
2445 static const ber_sequence_t SNMPv3Message_sequence[] = {
2446   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_msgVersion },
2447   { BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_msgGlobalData },
2448   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_msgSecurityParameters },
2449   { BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_msgData },
2450   { 0, 0, 0, NULL }
2451 };
2452
2453 static int
2454 dissect_snmp_SNMPv3Message(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2455   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2456                                    SNMPv3Message_sequence, hf_index, ett_snmp_SNMPv3Message);
2457
2458   return offset;
2459 }
2460
2461
2462 static const value_string snmp_T_smux_version_vals[] = {
2463   {   0, "version-1" },
2464   { 0, NULL }
2465 };
2466
2467
2468 static int
2469 dissect_snmp_T_smux_version(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2470   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2471                                   NULL);
2472
2473   return offset;
2474 }
2475 static int dissect_smux_version(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2476   return dissect_snmp_T_smux_version(FALSE, tvb, offset, pinfo, tree, hf_snmp_smux_version);
2477 }
2478
2479
2480
2481 static int
2482 dissect_snmp_DisplayString(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2483   offset = dissect_ber_octet_string(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2484                                        NULL);
2485
2486   return offset;
2487 }
2488 static int dissect_description(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2489   return dissect_snmp_DisplayString(FALSE, tvb, offset, pinfo, tree, hf_snmp_description);
2490 }
2491
2492
2493 static const ber_sequence_t SimpleOpen_sequence[] = {
2494   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_smux_version },
2495   { BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_identity },
2496   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_description },
2497   { BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_password },
2498   { 0, 0, 0, NULL }
2499 };
2500
2501 static int
2502 dissect_snmp_SimpleOpen(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2503   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2504                                    SimpleOpen_sequence, hf_index, ett_snmp_SimpleOpen);
2505
2506   return offset;
2507 }
2508 static int dissect_smux_simple(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2509   return dissect_snmp_SimpleOpen(FALSE, tvb, offset, pinfo, tree, hf_snmp_smux_simple);
2510 }
2511
2512
2513 static const value_string snmp_OpenPDU_vals[] = {
2514   {   0, "smux-simple" },
2515   { 0, NULL }
2516 };
2517
2518 static const ber_choice_t OpenPDU_choice[] = {
2519   {   0, BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_smux_simple },
2520   { 0, 0, 0, 0, NULL }
2521 };
2522
2523 static int
2524 dissect_snmp_OpenPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2525   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
2526                                  OpenPDU_choice, hf_index, ett_snmp_OpenPDU,
2527                                  NULL);
2528
2529   return offset;
2530 }
2531 static int dissect_open(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2532   return dissect_snmp_OpenPDU(FALSE, tvb, offset, pinfo, tree, hf_snmp_open);
2533 }
2534
2535
2536 static const value_string snmp_ClosePDU_vals[] = {
2537   {   0, "goingDown" },
2538   {   1, "unsupportedVersion" },
2539   {   2, "packetFormat" },
2540   {   3, "protocolError" },
2541   {   4, "internalError" },
2542   {   5, "authenticationFailure" },
2543   { 0, NULL }
2544 };
2545
2546
2547 static int
2548 dissect_snmp_ClosePDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2549   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2550                                   NULL);
2551
2552   return offset;
2553 }
2554 static int dissect_close(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2555   return dissect_snmp_ClosePDU(FALSE, tvb, offset, pinfo, tree, hf_snmp_close);
2556 }
2557
2558
2559
2560 static int
2561 dissect_snmp_INTEGER_M1_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2562   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2563                                   NULL);
2564
2565   return offset;
2566 }
2567 static int dissect_priority(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2568   return dissect_snmp_INTEGER_M1_2147483647(FALSE, tvb, offset, pinfo, tree, hf_snmp_priority);
2569 }
2570
2571
2572 static const value_string snmp_T_operation_vals[] = {
2573   {   0, "delete" },
2574   {   1, "readOnly" },
2575   {   2, "readWrite" },
2576   { 0, NULL }
2577 };
2578
2579
2580 static int
2581 dissect_snmp_T_operation(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2582   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2583                                   NULL);
2584
2585   return offset;
2586 }
2587 static int dissect_operation(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2588   return dissect_snmp_T_operation(FALSE, tvb, offset, pinfo, tree, hf_snmp_operation);
2589 }
2590
2591
2592 static const ber_sequence_t RReqPDU_sequence[] = {
2593   { BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_subtree },
2594   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_priority },
2595   { BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_operation },
2596   { 0, 0, 0, NULL }
2597 };
2598
2599 static int
2600 dissect_snmp_RReqPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2601   offset = dissect_ber_sequence(implicit_tag, pinfo, tree, tvb, offset,
2602                                    RReqPDU_sequence, hf_index, ett_snmp_RReqPDU);
2603
2604   return offset;
2605 }
2606 static int dissect_registerRequest(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2607   return dissect_snmp_RReqPDU(FALSE, tvb, offset, pinfo, tree, hf_snmp_registerRequest);
2608 }
2609
2610
2611 static const value_string snmp_RRspPDU_vals[] = {
2612   {  -1, "failure" },
2613   { 0, NULL }
2614 };
2615
2616
2617 static int
2618 dissect_snmp_RRspPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2619   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2620                                   NULL);
2621
2622   return offset;
2623 }
2624 static int dissect_rRspPDU(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2625   return dissect_snmp_RRspPDU(FALSE, tvb, offset, pinfo, tree, hf_snmp_rRspPDU);
2626 }
2627
2628
2629 static const value_string snmp_RegisterResponse_vals[] = {
2630   {   0, "rRspPDU" },
2631   {   1, "pDUs" },
2632   { 0, NULL }
2633 };
2634
2635 static const ber_choice_t RegisterResponse_choice[] = {
2636   {   0, BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_rRspPDU },
2637   {   1, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_pDUs },
2638   { 0, 0, 0, 0, NULL }
2639 };
2640
2641 static int
2642 dissect_snmp_RegisterResponse(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2643   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
2644                                  RegisterResponse_choice, hf_index, ett_snmp_RegisterResponse,
2645                                  NULL);
2646
2647   return offset;
2648 }
2649 static int dissect_registerResponse(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2650   return dissect_snmp_RegisterResponse(FALSE, tvb, offset, pinfo, tree, hf_snmp_registerResponse);
2651 }
2652
2653
2654 static const value_string snmp_SOutPDU_vals[] = {
2655   {   0, "commit" },
2656   {   1, "rollback" },
2657   { 0, NULL }
2658 };
2659
2660
2661 static int
2662 dissect_snmp_SOutPDU(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2663   offset = dissect_ber_integer(implicit_tag, pinfo, tree, tvb, offset, hf_index,
2664                                   NULL);
2665
2666   return offset;
2667 }
2668 static int dissect_commitOrRollback(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset) {
2669   return dissect_snmp_SOutPDU(FALSE, tvb, offset, pinfo, tree, hf_snmp_commitOrRollback);
2670 }
2671
2672
2673 static const value_string snmp_SMUX_PDUs_vals[] = {
2674   {   0, "open" },
2675   {   1, "close" },
2676   {   2, "registerRequest" },
2677   {   3, "registerResponse" },
2678   {   4, "commitOrRollback" },
2679   { 0, NULL }
2680 };
2681
2682 static const ber_choice_t SMUX_PDUs_choice[] = {
2683   {   0, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_open },
2684   {   1, BER_CLASS_APP, 1, BER_FLAGS_NOOWNTAG, dissect_close },
2685   {   2, BER_CLASS_APP, 2, BER_FLAGS_NOOWNTAG, dissect_registerRequest },
2686   {   3, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_registerResponse },
2687   {   4, BER_CLASS_APP, 4, BER_FLAGS_NOOWNTAG, dissect_commitOrRollback },
2688   { 0, 0, 0, 0, NULL }
2689 };
2690
2691 static int
2692 dissect_snmp_SMUX_PDUs(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_) {
2693   offset = dissect_ber_choice(pinfo, tree, tvb, offset,
2694                                  SMUX_PDUs_choice, hf_index, ett_snmp_SMUX_PDUs,
2695                                  NULL);
2696
2697   return offset;
2698 }
2699
2700 /*--- PDUs ---*/
2701
2702 static void dissect_SMUX_PDUs_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
2703   dissect_snmp_SMUX_PDUs(FALSE, tvb, 0, pinfo, tree, hf_snmp_SMUX_PDUs_PDU);
2704 }
2705
2706
2707 /*--- End of included file: packet-snmp-fn.c ---*/
2708 #line 1044 "packet-snmp-template.c"
2709
2710 guint
2711 dissect_snmp_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
2712     proto_tree *tree, int proto, gint ett, gboolean is_tcp)
2713 {
2714
2715         guint length_remaining;
2716         gint8 class;
2717         gboolean pc, ind = 0;
2718         gint32 tag;
2719         guint32 len;
2720         guint message_length;
2721         int start_offset = offset;
2722         guint32 version = 0;
2723
2724         proto_tree *snmp_tree = NULL;
2725         proto_item *item = NULL;
2726
2727         /*
2728          * This will throw an exception if we don't have any data left.
2729          * That's what we want.  (See "tcp_dissect_pdus()", which is
2730          * similar, but doesn't have to deal with ASN.1.
2731          * XXX - can we make "tcp_dissect_pdus()" provide enough
2732          * information to the "get_pdu_len" routine so that we could
2733          * have that routine deal with ASN.1, and just use
2734          * "tcp_dissect_pdus()"?)
2735          */
2736         length_remaining = tvb_ensure_length_remaining(tvb, offset);
2737
2738         /* NOTE: we have to parse the message piece by piece, since the
2739          * capture length may be less than the message length: a 'global'
2740          * parsing is likely to fail.
2741          */
2742
2743         /*
2744          * If this is SNMP-over-TCP, we might have to do reassembly
2745          * in order to read the "Sequence Of" header.
2746          */
2747         if (is_tcp && snmp_desegment && pinfo->can_desegment) {
2748                 /*
2749                  * This is TCP, and we should, and can, do reassembly.
2750                  *
2751                  * Is the "Sequence Of" header split across segment
2752                  * boundaries?  We requre at least 6 bytes for the
2753                  * header, which allows for a 4-byte length (ASN.1
2754                  * BER).
2755                  */
2756                 if (length_remaining < 6) {
2757                         pinfo->desegment_offset = offset;
2758                         pinfo->desegment_len = 6 - length_remaining;
2759
2760                         /*
2761                          * Return 0, which means "I didn't dissect anything
2762                          * because I don't have enough data - we need
2763                          * to desegment".
2764                          */
2765                         return 0;
2766                 }
2767         }
2768
2769         /*
2770          * OK, try to read the "Sequence Of" header; this gets the total
2771          * length of the SNMP message.
2772          */
2773         /* Set tree to 0 to not display internakl BER fields if option used.*/
2774         offset = dissect_ber_identifier(pinfo, 0, tvb, offset, &class, &pc, &tag);
2775         offset = dissect_ber_length(pinfo, 0, tvb, offset, &len, &ind);
2776
2777         message_length = len + 2;
2778         offset = dissect_ber_integer(FALSE, pinfo, 0, tvb, offset, -1, &version);
2779
2780
2781         /*
2782          * If this is SNMP-over-TCP, we might have to do reassembly
2783          * to get all of this message.
2784          */
2785         if (is_tcp && snmp_desegment && pinfo->can_desegment) {
2786                 /*
2787                  * Yes - is the message split across segment boundaries?
2788                  */
2789                 if (length_remaining < message_length) {
2790                         /*
2791                          * Yes.  Tell the TCP dissector where the data
2792                          * for this message starts in the data it handed
2793                          * us, and how many more bytes we need, and
2794                          * return.
2795                          */
2796                         pinfo->desegment_offset = start_offset;
2797                         pinfo->desegment_len =
2798                             message_length - length_remaining;
2799
2800                         /*
2801                          * Return 0, which means "I didn't dissect anything
2802                          * because I don't have enough data - we need
2803                          * to desegment".
2804                          */
2805                         return 0;
2806                 }
2807         }
2808
2809         next_tvb_init(&var_list);
2810
2811         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
2812                 col_set_str(pinfo->cinfo, COL_PROTOCOL,
2813                     proto_get_protocol_short_name(find_protocol_by_id(proto)));
2814         }
2815
2816         if (tree) {
2817                 item = proto_tree_add_item(tree, proto, tvb, offset,
2818                     message_length, FALSE);
2819                 snmp_tree = proto_item_add_subtree(item, ett);
2820         }
2821
2822         switch (version){
2823         case 0: /* v1 */
2824         case 1: /* v2c */
2825                 offset = dissect_snmp_Message(FALSE , tvb, start_offset, pinfo, snmp_tree, -1);
2826                 break;
2827         case 2: /* v2u */
2828                 offset = dissect_snmp_Messagev2u(FALSE , tvb, start_offset, pinfo, snmp_tree, -1);
2829                 break;
2830                         /* v3 */
2831         case 3:
2832                 offset = dissect_snmp_SNMPv3Message(FALSE , tvb, start_offset, pinfo, snmp_tree, -1);
2833                 break;
2834         default:
2835                 /*
2836                  * Return the length remaining in the tvbuff, so
2837                  * if this is SNMP-over-TCP, our caller thinks there's
2838                  * nothing left to dissect.
2839                  */
2840                 proto_tree_add_text(snmp_tree, tvb, offset, -1,"Unknown version");
2841                 return length_remaining;
2842                 break;
2843         }
2844
2845         next_tvb_call(&var_list, pinfo, tree, NULL, data_handle);
2846
2847         return offset;
2848 }
2849
2850 static gint
2851 dissect_snmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2852 {
2853         conversation_t  *conversation;
2854         int offset;
2855         gint8 tmp_class;
2856         gboolean tmp_pc;
2857         gint32 tmp_tag;
2858         guint32 tmp_length;
2859         gboolean tmp_ind;
2860
2861         /*
2862          * See if this looks like SNMP or not. if not, return 0 so
2863          * wireshark can try som other dissector instead.
2864          */
2865         /* All SNMP packets are BER encoded and consist of a SEQUENCE
2866          * that spans the entire PDU. The first item is an INTEGER that
2867          * has the values 0-2 (version 1-3).
2868          * if not it is not snmp.
2869          */
2870         /* SNMP starts with a SEQUENCE */
2871         offset = get_ber_identifier(tvb, 0, &tmp_class, &tmp_pc, &tmp_tag);
2872         if((tmp_class!=BER_CLASS_UNI)||(tmp_tag!=BER_UNI_TAG_SEQUENCE)){
2873                 return 0;
2874         }
2875         /* then comes a length which spans the rest of the tvb */
2876         offset = get_ber_length(NULL, tvb, offset, &tmp_length, &tmp_ind);
2877         if(tmp_length!=(guint32)tvb_reported_length_remaining(tvb, offset)){
2878                 return 0;
2879         }
2880         /* then comes an INTEGER (version)*/
2881         offset = get_ber_identifier(tvb, offset, &tmp_class, &tmp_pc, &tmp_tag);
2882         if((tmp_class!=BER_CLASS_UNI)||(tmp_tag!=BER_UNI_TAG_INTEGER)){
2883                 return 0;
2884         }
2885         /* do we need to test that version is 0 - 2 (version1-3) ? */
2886
2887
2888         /*
2889          * The first SNMP packet goes to the SNMP port; the second one
2890          * may come from some *other* port, but goes back to the same
2891          * IP address and port as the ones from which the first packet
2892          * came; all subsequent packets presumably go between those two
2893          * IP addresses and ports.
2894          *
2895          * If this packet went to the SNMP port, we check to see if
2896          * there's already a conversation with one address/port pair
2897          * matching the source IP address and port of this packet,
2898          * the other address matching the destination IP address of this
2899          * packet, and any destination port.
2900          *
2901          * If not, we create one, with its address 1/port 1 pair being
2902          * the source address/port of this packet, its address 2 being
2903          * the destination address of this packet, and its port 2 being
2904          * wildcarded, and give it the SNMP dissector as a dissector.
2905          */
2906         if (pinfo->destport == UDP_PORT_SNMP) {
2907           conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
2908                                            pinfo->srcport, 0, NO_PORT_B);
2909           if( (conversation == NULL) || (conversation->dissector_handle!=snmp_handle) ){
2910             conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
2911                                             pinfo->srcport, 0, NO_PORT2);
2912             conversation_set_dissector(conversation, snmp_handle);
2913           }
2914         }
2915
2916         return dissect_snmp_pdu(tvb, 0, pinfo, tree, proto_snmp, ett_snmp, FALSE);
2917 }
2918 static void
2919 dissect_snmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2920 {
2921         int offset = 0;
2922         guint message_len;
2923
2924         while (tvb_reported_length_remaining(tvb, offset) > 0) {
2925                 message_len = dissect_snmp_pdu(tvb, 0, pinfo, tree,
2926                     proto_snmp, ett_snmp, TRUE);
2927                 if (message_len == 0) {
2928                         /*
2929                          * We don't have all the data for that message,
2930                          * so we need to do desegmentation;
2931                          * "dissect_snmp_pdu()" has set that up.
2932                          */
2933                         break;
2934                 }
2935                 offset += message_len;
2936         }
2937 }
2938
2939 static void
2940 dissect_smux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2941 {
2942         proto_tree *smux_tree = NULL;
2943         proto_item *item = NULL;
2944
2945         if (check_col(pinfo->cinfo, COL_PROTOCOL))
2946                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMUX");
2947
2948         if (tree) {
2949                 item = proto_tree_add_item(tree, proto_smux, tvb, 0, -1, FALSE);
2950                 smux_tree = proto_item_add_subtree(item, ett_smux);
2951         }
2952
2953         dissect_SMUX_PDUs_PDU(tvb, pinfo, tree);
2954 }
2955
2956 static void
2957 process_prefs(void)
2958 {
2959 #ifdef HAVE_SOME_SNMP
2960         gchar *tmp_mib_modules;
2961         static gboolean mibs_loaded = FALSE;
2962
2963         if (mibs_loaded) {
2964                 /*
2965                  * Unload the MIBs, as we'll be reloading them based on
2966                  * the current preference setting.
2967                  */
2968                 shutdown_mib(); /* unload MIBs */
2969         }
2970
2971         /*
2972          * Cannot check if MIBS is already set, as it could be set by Wireshark.
2973          *
2974          * If we have a list of modules to load, put that list in MIBS,
2975          * otherwise clear MIBS.
2976          */
2977         if (mib_modules != NULL) {
2978                 tmp_mib_modules = g_strconcat("MIBS=", mib_modules, NULL);
2979                 /*
2980                  * Try to be clever and replace colons for semicolons under
2981                  * Windows.  Do the converse on non-Windows systems.  This
2982                  * handles cases where we've copied a preferences file
2983                  * between a non-Windows box and a Windows box or upgraded
2984                  * from an older version of Wireshark under Windows.
2985                  */
2986                 g_strdelimit(tmp_mib_modules, IMPORT_SEPARATOR, ENV_SEPARATOR_CHAR);
2987
2988 #ifdef _WIN32
2989                 _putenv(tmp_mib_modules);
2990 #else
2991                 putenv(tmp_mib_modules);
2992 #endif /*_WIN32*/
2993         } else {
2994 #ifdef _WIN32
2995                 _putenv("MIBS");
2996 #else
2997                 putenv("MIBS");
2998 #endif  /* _WIN32 */
2999         }
3000
3001         /*
3002          * Load the MIBs.
3003          */
3004         register_mib_handlers();
3005         read_premib_configs();
3006         init_mib();
3007         read_configs();
3008         mibs_loaded = TRUE;
3009 #endif /* HAVE_SOME_SNMP */
3010 }
3011 /*--- proto_register_snmp -------------------------------------------*/
3012 void proto_register_snmp(void) {
3013
3014 #if defined(_WIN32) && defined(HAVE_SOME_SNMP)
3015         char *mib_path;
3016         int mib_path_len;
3017 #define MIB_PATH_APPEND "snmp\\mibs"
3018 #endif
3019         gchar *tmp_mib_modules;
3020
3021   /* List of fields */
3022   static hf_register_info hf[] = {
3023                 { &hf_snmp_v3_flags_auth,
3024                 { "Authenticated", "snmp.v3.flags.auth", FT_BOOLEAN, 8,
3025                     TFS(&flags_set_truth), TH_AUTH, "", HFILL }},
3026                 { &hf_snmp_v3_flags_crypt,
3027                 { "Encrypted", "snmp.v3.flags.crypt", FT_BOOLEAN, 8,
3028                     TFS(&flags_set_truth), TH_CRYPT, "", HFILL }},
3029                 { &hf_snmp_v3_flags_report,
3030                 { "Reportable", "snmp.v3.flags.report", FT_BOOLEAN, 8,
3031                     TFS(&flags_set_truth), TH_REPORT, "", HFILL }},
3032                 { &hf_snmp_engineid_conform, {
3033                     "Engine ID Conformance", "snmp.engineid.conform", FT_BOOLEAN, 8,
3034                     TFS(&tfs_snmp_engineid_conform), F_SNMP_ENGINEID_CONFORM, "Engine ID RFC3411 Conformance", HFILL }},
3035                 { &hf_snmp_engineid_enterprise, {
3036                     "Engine Enterprise ID", "snmp.engineid.enterprise", FT_UINT32, BASE_DEC,
3037                     VALS(sminmpec_values), 0, "Engine Enterprise ID", HFILL }},
3038                 { &hf_snmp_engineid_format, {
3039                     "Engine ID Format", "snmp.engineid.format", FT_UINT8, BASE_DEC,
3040                     VALS(snmp_engineid_format_vals), 0, "Engine ID Format", HFILL }},
3041                 { &hf_snmp_engineid_ipv4, {
3042                     "Engine ID Data: IPv4 address", "snmp.engineid.ipv4", FT_IPv4, BASE_NONE,
3043                     NULL, 0, "Engine ID Data: IPv4 address", HFILL }},
3044                 { &hf_snmp_engineid_ipv6, {
3045                     "Engine ID Data: IPv6 address", "snmp.engineid.ipv6", FT_IPv6, BASE_NONE,
3046                     NULL, 0, "Engine ID Data: IPv6 address", HFILL }},
3047                 { &hf_snmp_engineid_mac, {
3048                     "Engine ID Data: MAC address", "snmp.engineid.mac", FT_ETHER, BASE_NONE,
3049                     NULL, 0, "Engine ID Data: MAC address", HFILL }},
3050                 { &hf_snmp_engineid_text, {
3051                     "Engine ID Data: Text", "snmp.engineid.text", FT_STRING, BASE_NONE,
3052                     NULL, 0, "Engine ID Data: Text", HFILL }},
3053                 { &hf_snmp_engineid_time, {
3054                     "Engine ID Data: Time", "snmp.engineid.time", FT_ABSOLUTE_TIME, BASE_NONE,
3055                     NULL, 0, "Engine ID Data: Time", HFILL }},
3056                 { &hf_snmp_engineid_data, {
3057                     "Engine ID Data", "snmp.engineid.data", FT_BYTES, BASE_HEX,
3058                     NULL, 0, "Engine ID Data", HFILL }},
3059                 { &hf_snmp_counter64, {
3060                     "Value", "snmp.counter64", FT_INT64, BASE_DEC,
3061                     NULL, 0, "A counter64 value", HFILL }},
3062
3063
3064 /*--- Included file: packet-snmp-hfarr.c ---*/
3065 #line 1 "packet-snmp-hfarr.c"
3066     { &hf_snmp_SMUX_PDUs_PDU,
3067       { "SMUX-PDUs", "snmp.SMUX_PDUs",
3068         FT_UINT32, BASE_DEC, VALS(snmp_SMUX_PDUs_vals), 0,
3069         "snmp.SMUX_PDUs", HFILL }},
3070     { &hf_snmp_simple,
3071       { "simple", "snmp.simple",
3072         FT_UINT32, BASE_DEC, VALS(snmp_SimpleSyntax_vals), 0,
3073         "snmp.SimpleSyntax", HFILL }},
3074     { &hf_snmp_application_wide,
3075       { "application-wide", "snmp.application_wide",
3076         FT_UINT32, BASE_DEC, VALS(snmp_ApplicationSyntax_vals), 0,
3077         "snmp.ApplicationSyntax", HFILL }},
3078     { &hf_snmp_integer_value,
3079       { "integer-value", "snmp.integer_value",
3080         FT_INT32, BASE_DEC, NULL, 0,
3081         "snmp.Integer_value", HFILL }},
3082     { &hf_snmp_string_value,
3083       { "string-value", "snmp.string_value",
3084         FT_BYTES, BASE_HEX, NULL, 0,
3085         "snmp.String_value", HFILL }},
3086     { &hf_snmp_objectID_value,
3087       { "objectID-value", "snmp.objectID_value",
3088         FT_OID, BASE_NONE, NULL, 0,
3089         "snmp.ObjectID_value", HFILL }},
3090     { &hf_snmp_empty,
3091       { "empty", "snmp.empty",
3092         FT_NONE, BASE_NONE, NULL, 0,
3093         "snmp.Empty", HFILL }},
3094     { &hf_snmp_ipAddress_value,
3095       { "ipAddress-value", "snmp.ipAddress_value",
3096         FT_IPv4, BASE_NONE, NULL, 0,
3097         "snmp.IpAddress", HFILL }},
3098     { &hf_snmp_counter_value,
3099       { "counter-value", "snmp.counter_value",
3100         FT_UINT32, BASE_DEC, NULL, 0,
3101         "snmp.Counter32", HFILL }},
3102     { &hf_snmp_timeticks_value,
3103       { "timeticks-value", "snmp.timeticks_value",
3104         FT_UINT32, BASE_DEC, NULL, 0,
3105         "snmp.TimeTicks", HFILL }},
3106     { &hf_snmp_arbitrary_value,
3107       { "arbitrary-value", "snmp.arbitrary_value",
3108         FT_BYTES, BASE_HEX, NULL, 0,
3109         "snmp.Opaque", HFILL }},
3110     { &hf_snmp_big_counter_value,
3111       { "big-counter-value", "snmp.big_counter_value",
3112         FT_UINT64, BASE_DEC, NULL, 0,
3113         "snmp.Counter64", HFILL }},
3114     { &hf_snmp_unsigned_integer_value,
3115       { "unsigned-integer-value", "snmp.unsigned_integer_value",
3116         FT_UINT32, BASE_DEC, NULL, 0,
3117         "snmp.Unsigned32", HFILL }},
3118     { &hf_snmp_internet,
3119       { "internet", "snmp.internet",
3120         FT_IPv4, BASE_NONE, NULL, 0,
3121         "snmp.IpAddress", HFILL }},
3122     { &hf_snmp_version,
3123       { "version", "snmp.version",
3124         FT_INT32, BASE_DEC, VALS(snmp_Version_vals), 0,
3125         "snmp.Version", HFILL }},
3126     { &hf_snmp_community,
3127       { "community", "snmp.community",
3128         FT_STRING, BASE_HEX, NULL, 0,
3129         "snmp.OCTET_STRING", HFILL }},
3130     { &hf_snmp_data,
3131       { "data", "snmp.data",
3132         FT_UINT32, BASE_DEC, VALS(snmp_PDUs_vals), 0,
3133         "snmp.PDUs", HFILL }},
3134     { &hf_snmp_parameters,
3135       { "parameters", "snmp.parameters",
3136         FT_BYTES, BASE_HEX, NULL, 0,
3137         "snmp.OCTET_STRING", HFILL }},
3138     { &hf_snmp_datav2u,
3139       { "datav2u", "snmp.datav2u",
3140         FT_UINT32, BASE_DEC, VALS(snmp_T_datav2u_vals), 0,
3141         "snmp.T_datav2u", HFILL }},
3142     { &hf_snmp_v2u_plaintext,
3143       { "plaintext", "snmp.plaintext",
3144         FT_UINT32, BASE_DEC, VALS(snmp_PDUs_vals), 0,
3145         "snmp.PDUs", HFILL }},
3146     { &hf_snmp_encrypted,
3147       { "encrypted", "snmp.encrypted",
3148         FT_BYTES, BASE_HEX, NULL, 0,
3149         "snmp.OCTET_STRING", HFILL }},
3150     { &hf_snmp_msgAuthoritativeEngineID,
3151       { "msgAuthoritativeEngineID", "snmp.msgAuthoritativeEngineID",
3152         FT_BYTES, BASE_HEX, NULL, 0,
3153         "snmp.SnmpEngineID", HFILL }},
3154     { &hf_snmp_msgAuthoritativeEngineBoots,
3155       { "msgAuthoritativeEngineBoots", "snmp.msgAuthoritativeEngineBoots",
3156         FT_UINT32, BASE_DEC, NULL, 0,
3157         "snmp.INTEGER_0_2147483647", HFILL }},
3158     { &hf_snmp_msgAuthoritativeEngineTime,
3159       { "msgAuthoritativeEngineTime", "snmp.msgAuthoritativeEngineTime",
3160         FT_UINT32, BASE_DEC, NULL, 0,
3161         "snmp.INTEGER_0_2147483647", HFILL }},
3162     { &hf_snmp_msgUserName,
3163       { "msgUserName", "snmp.msgUserName",
3164         FT_STRING, BASE_HEX, NULL, 0,
3165         "snmp.OCTET_STRING_SIZE_1_32", HFILL }},
3166     { &hf_snmp_msgAuthenticationParameters,
3167       { "msgAuthenticationParameters", "snmp.msgAuthenticationParameters",
3168         FT_BYTES, BASE_HEX, NULL, 0,
3169         "snmp.OCTET_STRING", HFILL }},
3170     { &hf_snmp_msgPrivacyParameters,
3171       { "msgPrivacyParameters", "snmp.msgPrivacyParameters",
3172         FT_BYTES, BASE_HEX, NULL, 0,
3173         "snmp.OCTET_STRING", HFILL }},
3174     { &hf_snmp_msgVersion,
3175       { "msgVersion", "snmp.msgVersion",
3176         FT_INT32, BASE_DEC, VALS(snmp_Version_vals), 0,
3177         "snmp.Version", HFILL }},
3178     { &hf_snmp_msgGlobalData,
3179       { "msgGlobalData", "snmp.msgGlobalData",
3180         FT_NONE, BASE_NONE, NULL, 0,
3181         "snmp.HeaderData", HFILL }},
3182     { &hf_snmp_msgSecurityParameters,
3183       { "msgSecurityParameters", "snmp.msgSecurityParameters",
3184         FT_BYTES, BASE_HEX, NULL, 0,
3185         "snmp.T_msgSecurityParameters", HFILL }},
3186     { &hf_snmp_msgData,
3187       { "msgData", "snmp.msgData",
3188         FT_UINT32, BASE_DEC, VALS(snmp_ScopedPduData_vals), 0,
3189         "snmp.ScopedPduData", HFILL }},
3190     { &hf_snmp_msgID,
3191       { "msgID", "snmp.msgID",
3192         FT_UINT32, BASE_DEC, NULL, 0,
3193         "snmp.INTEGER_0_2147483647", HFILL }},
3194     { &hf_snmp_msgMaxSize,
3195       { "msgMaxSize", "snmp.msgMaxSize",
3196         FT_UINT32, BASE_DEC, NULL, 0,
3197         "snmp.INTEGER_484_2147483647", HFILL }},
3198     { &hf_snmp_msgFlags,
3199       { "msgFlags", "snmp.msgFlags",
3200         FT_BYTES, BASE_HEX, NULL, 0,
3201         "snmp.T_msgFlags", HFILL }},
3202     { &hf_snmp_msgSecurityModel,
3203       { "msgSecurityModel", "snmp.msgSecurityModel",
3204         FT_UINT32, BASE_DEC, VALS(sec_models), 0,
3205         "snmp.T_msgSecurityModel", HFILL }},
3206     { &hf_snmp_plaintext,
3207       { "plaintext", "snmp.plaintext",
3208         FT_NONE, BASE_NONE, NULL, 0,
3209         "snmp.ScopedPDU", HFILL }},
3210     { &hf_snmp_encryptedPDU,
3211       { "encryptedPDU", "snmp.encryptedPDU",
3212         FT_BYTES, BASE_HEX, NULL, 0,
3213         "snmp.OCTET_STRING", HFILL }},
3214     { &hf_snmp_contextEngineID,
3215       { "contextEngineID", "snmp.contextEngineID",
3216         FT_BYTES, BASE_HEX, NULL, 0,
3217         "snmp.OCTET_STRING", HFILL }},
3218     { &hf_snmp_contextName,
3219       { "contextName", "snmp.contextName",
3220         FT_BYTES, BASE_HEX, NULL, 0,
3221         "snmp.OCTET_STRING", HFILL }},
3222     { &hf_snmp_get_request,
3223       { "get-request", "snmp.get_request",
3224         FT_NONE, BASE_NONE, NULL, 0,
3225         "snmp.T_get_request", HFILL }},
3226     { &hf_snmp_get_next_request,
3227       { "get-next-request", "snmp.get_next_request",
3228         FT_NONE, BASE_NONE, NULL, 0,
3229         "snmp.T_get_next_request", HFILL }},
3230     { &hf_snmp_get_response,
3231       { "get-response", "snmp.get_response",
3232         FT_NONE, BASE_NONE, NULL, 0,
3233         "snmp.T_get_response", HFILL }},
3234     { &hf_snmp_set_request,
3235       { "set-request", "snmp.set_request",
3236         FT_NONE, BASE_NONE, NULL, 0,
3237         "snmp.T_set_request", HFILL }},
3238     { &hf_snmp_trap,
3239       { "trap", "snmp.trap",
3240         FT_NONE, BASE_NONE, NULL, 0,
3241         "snmp.T_trap", HFILL }},
3242     { &hf_snmp_getBulkRequest,
3243       { "getBulkRequest", "snmp.getBulkRequest",
3244         FT_NONE, BASE_NONE, NULL, 0,
3245         "snmp.T_getBulkRequest", HFILL }},
3246     { &hf_snmp_informRequest,
3247       { "informRequest", "snmp.informRequest",
3248         FT_NONE, BASE_NONE, NULL, 0,
3249         "snmp.T_informRequest", HFILL }},
3250     { &hf_snmp_sNMPv2_Trap,
3251       { "sNMPv2-Trap", "snmp.sNMPv2_Trap",
3252         FT_NONE, BASE_NONE, NULL, 0,
3253         "snmp.T_sNMPv2_Trap", HFILL }},
3254     { &hf_snmp_report,
3255       { "report", "snmp.report",
3256         FT_NONE, BASE_NONE, NULL, 0,
3257         "snmp.T_report", HFILL }},
3258     { &hf_snmp_request_id,
3259       { "request-id", "snmp.request_id",
3260         FT_INT32, BASE_DEC, NULL, 0,
3261         "snmp.INTEGER", HFILL }},
3262     { &hf_snmp_error_status,
3263       { "error-status", "snmp.error_status",
3264         FT_INT32, BASE_DEC, VALS(snmp_T_error_status_vals), 0,
3265         "snmp.T_error_status", HFILL }},
3266     { &hf_snmp_error_index,
3267       { "error-index", "snmp.error_index",
3268         FT_INT32, BASE_DEC, NULL, 0,
3269         "snmp.INTEGER", HFILL }},
3270     { &hf_snmp_variable_bindings,
3271       { "variable-bindings", "snmp.variable_bindings",
3272         FT_UINT32, BASE_DEC, NULL, 0,
3273         "snmp.VarBindList", HFILL }},
3274     { &hf_snmp_bulkPDU_request_id,
3275       { "request-id", "snmp.request_id",
3276         FT_INT32, BASE_DEC, NULL, 0,
3277         "snmp.Integer32", HFILL }},
3278     { &hf_snmp_non_repeaters,
3279       { "non-repeaters", "snmp.non_repeaters",
3280         FT_UINT32, BASE_DEC, NULL, 0,
3281         "snmp.INTEGER_0_2147483647", HFILL }},
3282     { &hf_snmp_max_repetitions,
3283       { "max-repetitions", "snmp.max_repetitions",
3284         FT_UINT32, BASE_DEC, NULL, 0,
3285         "snmp.INTEGER_0_2147483647", HFILL }},
3286     { &hf_snmp_enterprise,
3287       { "enterprise", "snmp.enterprise",
3288         FT_OID, BASE_NONE, NULL, 0,
3289         "snmp.OBJECT_IDENTIFIER", HFILL }},
3290     { &hf_snmp_agent_addr,
3291       { "agent-addr", "snmp.agent_addr",
3292         FT_UINT32, BASE_DEC, VALS(snmp_NetworkAddress_vals), 0,
3293         "snmp.NetworkAddress", HFILL }},
3294     { &hf_snmp_generic_trap,
3295       { "generic-trap", "snmp.generic_trap",
3296         FT_INT32, BASE_DEC, VALS(snmp_T_generic_trap_vals), 0,
3297         "snmp.T_generic_trap", HFILL }},
3298     { &hf_snmp_specific_trap,
3299       { "specific-trap", "snmp.specific_trap",
3300         FT_INT32, BASE_DEC, NULL, 0,
3301         "snmp.INTEGER", HFILL }},
3302     { &hf_snmp_time_stamp,
3303       { "time-stamp", "snmp.time_stamp",
3304         FT_UINT32, BASE_DEC, NULL, 0,
3305         "snmp.TimeTicks", HFILL }},
3306     { &hf_snmp_name,
3307       { "name", "snmp.name",
3308         FT_OID, BASE_NONE, NULL, 0,
3309         "snmp.ObjectName", HFILL }},
3310     { &hf_snmp_valueType,
3311       { "valueType", "snmp.valueType",
3312         FT_UINT32, BASE_DEC, VALS(snmp_ValueType_vals), 0,
3313         "snmp.ValueType", HFILL }},
3314     { &hf_snmp_value,
3315       { "value", "snmp.value",
3316         FT_UINT32, BASE_DEC, VALS(snmp_ObjectSyntax_vals), 0,
3317         "snmp.ObjectSyntax", HFILL }},
3318     { &hf_snmp_unSpecified,
3319       { "unSpecified", "snmp.unSpecified",
3320         FT_NONE, BASE_NONE, NULL, 0,
3321         "snmp.NULL", HFILL }},
3322     { &hf_snmp_noSuchObject,
3323       { "noSuchObject", "snmp.noSuchObject",
3324         FT_NONE, BASE_NONE, NULL, 0,
3325         "snmp.NULL", HFILL }},
3326     { &hf_snmp_noSuchInstance,
3327       { "noSuchInstance", "snmp.noSuchInstance",
3328         FT_NONE, BASE_NONE, NULL, 0,
3329         "snmp.NULL", HFILL }},
3330     { &hf_snmp_endOfMibView,
3331       { "endOfMibView", "snmp.endOfMibView",
3332         FT_NONE, BASE_NONE, NULL, 0,
3333         "snmp.NULL", HFILL }},
3334     { &hf_snmp_VarBindList_item,
3335       { "Item", "snmp.VarBindList_item",
3336         FT_NONE, BASE_NONE, NULL, 0,
3337         "snmp.VarBind", HFILL }},
3338     { &hf_snmp_open,
3339       { "open", "snmp.open",
3340         FT_UINT32, BASE_DEC, VALS(snmp_OpenPDU_vals), 0,
3341         "snmp.OpenPDU", HFILL }},
3342     { &hf_snmp_close,
3343       { "close", "snmp.close",
3344         FT_INT32, BASE_DEC, VALS(snmp_ClosePDU_vals), 0,
3345         "snmp.ClosePDU", HFILL }},
3346     { &hf_snmp_registerRequest,
3347       { "registerRequest", "snmp.registerRequest",
3348         FT_NONE, BASE_NONE, NULL, 0,
3349         "snmp.RReqPDU", HFILL }},
3350     { &hf_snmp_registerResponse,
3351       { "registerResponse", "snmp.registerResponse",
3352         FT_UINT32, BASE_DEC, VALS(snmp_RegisterResponse_vals), 0,
3353         "snmp.RegisterResponse", HFILL }},
3354     { &hf_snmp_commitOrRollback,
3355       { "commitOrRollback", "snmp.commitOrRollback",
3356         FT_INT32, BASE_DEC, VALS(snmp_SOutPDU_vals), 0,
3357         "snmp.SOutPDU", HFILL }},
3358     { &hf_snmp_rRspPDU,
3359       { "rRspPDU", "snmp.rRspPDU",
3360         FT_INT32, BASE_DEC, VALS(snmp_RRspPDU_vals), 0,
3361         "snmp.RRspPDU", HFILL }},
3362     { &hf_snmp_pDUs,
3363       { "pDUs", "snmp.pDUs",
3364         FT_UINT32, BASE_DEC, VALS(snmp_PDUs_vals), 0,
3365         "snmp.PDUs", HFILL }},
3366     { &hf_snmp_smux_simple,
3367       { "smux-simple", "snmp.smux_simple",
3368         FT_NONE, BASE_NONE, NULL, 0,
3369         "snmp.SimpleOpen", HFILL }},
3370     { &hf_snmp_smux_version,
3371       { "smux-version", "snmp.smux_version",
3372         FT_INT32, BASE_DEC, VALS(snmp_T_smux_version_vals), 0,
3373         "snmp.T_smux_version", HFILL }},
3374     { &hf_snmp_identity,
3375       { "identity", "snmp.identity",
3376         FT_OID, BASE_NONE, NULL, 0,
3377         "snmp.OBJECT_IDENTIFIER", HFILL }},
3378     { &hf_snmp_description,
3379       { "description", "snmp.description",
3380         FT_BYTES, BASE_HEX, NULL, 0,
3381         "snmp.DisplayString", HFILL }},
3382     { &hf_snmp_password,
3383       { "password", "snmp.password",
3384         FT_BYTES, BASE_HEX, NULL, 0,
3385         "snmp.OCTET_STRING", HFILL }},
3386     { &hf_snmp_subtree,
3387       { "subtree", "snmp.subtree",
3388         FT_OID, BASE_NONE, NULL, 0,
3389         "snmp.ObjectName", HFILL }},
3390     { &hf_snmp_priority,
3391       { "priority", "snmp.priority",
3392         FT_INT32, BASE_DEC, NULL, 0,
3393         "snmp.INTEGER_M1_2147483647", HFILL }},
3394     { &hf_snmp_operation,
3395       { "operation", "snmp.operation",
3396         FT_INT32, BASE_DEC, VALS(snmp_T_operation_vals), 0,
3397         "snmp.T_operation", HFILL }},
3398
3399 /*--- End of included file: packet-snmp-hfarr.c ---*/
3400 #line 1399 "packet-snmp-template.c"
3401   };
3402
3403   /* List of subtrees */
3404   static gint *ett[] = {
3405           &ett_snmp,
3406           &ett_engineid,
3407           &ett_msgFlags,
3408
3409
3410 /*--- Included file: packet-snmp-ettarr.c ---*/
3411 #line 1 "packet-snmp-ettarr.c"
3412     &ett_snmp_ObjectSyntax,
3413     &ett_snmp_SimpleSyntax,
3414     &ett_snmp_ApplicationSyntax,
3415     &ett_snmp_NetworkAddress,
3416     &ett_snmp_Message,
3417     &ett_snmp_Messagev2u,
3418     &ett_snmp_T_datav2u,
3419     &ett_snmp_UsmSecurityParameters,
3420     &ett_snmp_SNMPv3Message,
3421     &ett_snmp_HeaderData,
3422     &ett_snmp_ScopedPduData,
3423     &ett_snmp_ScopedPDU,
3424     &ett_snmp_PDUs,
3425     &ett_snmp_PDU,
3426     &ett_snmp_BulkPDU,
3427     &ett_snmp_Trap_PDU,
3428     &ett_snmp_VarBind,
3429     &ett_snmp_ValueType,
3430     &ett_snmp_VarBindList,
3431     &ett_snmp_SMUX_PDUs,
3432     &ett_snmp_RegisterResponse,
3433     &ett_snmp_OpenPDU,
3434     &ett_snmp_SimpleOpen,
3435     &ett_snmp_RReqPDU,
3436
3437 /*--- End of included file: packet-snmp-ettarr.c ---*/
3438 #line 1408 "packet-snmp-template.c"
3439   };
3440         module_t *snmp_module;
3441
3442   #ifdef HAVE_SOME_SNMP
3443
3444 #ifdef _WIN32
3445         /* Set MIBDIRS so that the SNMP library can find its mibs. */
3446         /* XXX - Should we set MIBS or MIBFILES as well? */
3447         mib_path_len=strlen(get_datafile_dir()) + strlen(MIB_PATH_APPEND) + 20;
3448         mib_path = ep_alloc (mib_path_len);
3449         g_snprintf (mib_path, mib_path_len, "MIBDIRS=%s\\%s", get_datafile_dir(), MIB_PATH_APPEND);
3450         /* Amazingly enough, Windows does not provide setenv(). */
3451         if (getenv("MIBDIRS") == NULL)
3452                 _putenv(mib_path);
3453
3454 #endif  /* _WIN32 */
3455
3456         /*
3457          * Suppress warnings about unknown tokens - we aren't initializing
3458          * UCD SNMP in its entirety, we're just initializing the
3459          * MIB-handling part because that's all we're using, which
3460          * means that entries in the configuration file for other
3461          * pars of the library will not be handled, and we don't want
3462          * the config file reading code to whine about that.
3463          */
3464         netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
3465                                NETSNMP_DS_LIB_NO_TOKEN_WARNINGS, TRUE);
3466         netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
3467                            NETSNMP_DS_LIB_PRINT_SUFFIX_ONLY, 2);
3468 #endif /* HAVE_SOME_SNMP */
3469
3470
3471   /* Register protocol */
3472   proto_snmp = proto_register_protocol(PNAME, PSNAME, PFNAME);
3473   new_register_dissector("snmp", dissect_snmp, proto_snmp);
3474
3475   /* Register fields and subtrees */
3476   proto_register_field_array(proto_snmp, hf, array_length(hf));
3477   proto_register_subtree_array(ett, array_length(ett));
3478
3479
3480         /* Register configuration preferences */
3481         snmp_module = prefs_register_protocol(proto_snmp, process_prefs);
3482         prefs_register_bool_preference(snmp_module, "display_oid",
3483                 "Show SNMP OID in info column",
3484                 "Whether the SNMP OID should be shown in the info column",
3485                 &display_oid);
3486
3487         /*
3488          * Set the default value of "mib_modules".
3489          *
3490          * If the MIBS environment variable is set, make its value
3491          * the value of "mib_modules", otherwise, set "mib_modules"
3492          * to DEF_MIB_MODULES.
3493          */
3494         tmp_mib_modules = getenv("MIBS");
3495         if (tmp_mib_modules != NULL)
3496                 mib_modules = tmp_mib_modules;
3497         prefs_register_string_preference(snmp_module, "mib_modules",
3498             "MIB modules to load",
3499             "List of MIB modules to load (the list is set to environment variable MIBS if the variable is not already set)"
3500             "The list must be separated by colons (:) on non-Windows systems and semicolons (;) on Windows systems",
3501             &mib_modules);
3502         prefs_register_bool_preference(snmp_module, "desegment",
3503             "Reassemble SNMP-over-TCP messages\nspanning multiple TCP segments",
3504             "Whether the SNMP dissector should reassemble messages spanning multiple TCP segments."
3505             " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
3506             &snmp_desegment);
3507
3508   prefs_register_bool_preference(snmp_module, "var_in_tree",
3509                 "Display dissected variables inside SNMP tree",
3510                 "ON - display dissected variables inside SNMP tree, OFF - display dissected variables in root tree after SNMP",
3511                 &snmp_var_in_tree);
3512
3513         variable_oid_dissector_table =
3514             register_dissector_table("snmp.variable_oid",
3515               "SNMP Variable OID", FT_STRING, BASE_NONE);
3516 }
3517
3518
3519 /*--- proto_reg_handoff_snmp ---------------------------------------*/
3520 void proto_reg_handoff_snmp(void) {
3521         dissector_handle_t snmp_tcp_handle;
3522
3523         snmp_handle = find_dissector("snmp");
3524
3525         dissector_add("udp.port", UDP_PORT_SNMP, snmp_handle);
3526         dissector_add("udp.port", UDP_PORT_SNMP_TRAP, snmp_handle);
3527         dissector_add("ethertype", ETHERTYPE_SNMP, snmp_handle);
3528         dissector_add("ipx.socket", IPX_SOCKET_SNMP_AGENT, snmp_handle);
3529         dissector_add("ipx.socket", IPX_SOCKET_SNMP_SINK, snmp_handle);
3530         dissector_add("hpext.dxsap", HPEXT_SNMP, snmp_handle);
3531
3532         snmp_tcp_handle = create_dissector_handle(dissect_snmp_tcp, proto_snmp);
3533         dissector_add("tcp.port", TCP_PORT_SNMP, snmp_tcp_handle);
3534         dissector_add("tcp.port", TCP_PORT_SNMP_TRAP, snmp_tcp_handle);
3535
3536         data_handle = find_dissector("data");
3537
3538         /*
3539          * Process preference settings.
3540          *
3541          * We can't do this in the register routine, as preferences aren't
3542          * read until all dissector register routines have been called (so
3543          * that all dissector preferences have been registered).
3544          */
3545         process_prefs();
3546
3547 }
3548
3549 void
3550 proto_register_smux(void)
3551 {
3552         static hf_register_info hf[] = {
3553                 { &hf_smux_version,
3554                 { "Version", "smux.version", FT_UINT8, BASE_DEC, NULL,
3555                     0x0, "", HFILL }},
3556                 { &hf_smux_pdutype,
3557                 { "PDU type", "smux.pdutype", FT_UINT8, BASE_DEC, VALS(smux_types),
3558                     0x0, "", HFILL }},
3559         };
3560         static gint *ett[] = {
3561                 &ett_smux,
3562         };
3563
3564         proto_smux = proto_register_protocol("SNMP Multiplex Protocol",
3565             "SMUX", "smux");
3566         proto_register_field_array(proto_smux, hf, array_length(hf));
3567         proto_register_subtree_array(ett, array_length(ett));
3568
3569 }
3570
3571 void
3572 proto_reg_handoff_smux(void)
3573 {
3574         dissector_handle_t smux_handle;
3575
3576         smux_handle = create_dissector_handle(dissect_smux, proto_smux);
3577         dissector_add("tcp.port", TCP_PORT_SMUX, smux_handle);
3578 }
3579
3580