2 * Routines for Agent Extensibility (AgentX) Protocol disassembly
5 * Copyright (c) 2005 by Oleg Terletsky <oleg.terletsky@comverse.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1999 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/packet.h>
29 #include <epan/prefs.h>
30 #include <epan/to_str.h>
32 #include "packet-tcp.h"
34 static guint global_agentx_tcp_port = 705;
36 void proto_register_agentx(void);
37 void proto_reg_handoff_agentx(void);
40 /* Define the agentx proto */
41 static int proto_agentx = -1;
44 static int hf_version = -1;
45 static int hf_type = -1;
46 static int hf_flags = -1;
47 static int hf_flags_register = -1;
48 static int hf_flags_newindex = -1;
49 static int hf_flags_anyindex = -1;
50 static int hf_flags_context = -1;
51 static int hf_flags_byteorder = -1;
52 static int hf_session_id = -1;
53 static int hf_trans_id = -1;
54 static int hf_packet_id = -1;
55 static int hf_payload_len = -1;
56 static int hf_ostring_len = -1;
57 static int hf_ostring = -1;
58 static int hf_oid_sub = -1;
59 static int hf_oid_prefix = -1;
60 static int hf_oid_include = -1;
61 static int hf_oid_str = -1;
62 static int hf_resp_uptime = -1;
63 static int hf_resp_error = -1;
64 static int hf_resp_index = -1;
65 static int hf_vtag = -1;
66 static int hf_val32 = -1;
67 static int hf_val64 = -1;
68 static int hf_open_timeout = -1;
69 static int hf_close_reason = -1;
70 static int hf_reg_timeout = -1;
71 static int hf_reg_prio = -1;
72 static int hf_reg_rsid = -1;
73 static int hf_reg_ubound = -1;
74 static int hf_unreg_timeout = -1;
75 static int hf_unreg_prio = -1;
76 static int hf_unreg_rsid = -1;
77 static int hf_unreg_ubound = -1;
78 static int hf_gbulk_nrepeat = -1;
79 static int hf_gbulk_mrepeat = -1;
82 static gint ett_flags = -1;
83 static gint ett_agentx = -1;
84 static gint ett_pdu_hdr = -1;
85 static gint ett_get = -1;
86 static gint ett_getnext = -1;
87 static gint ett_search_range = -1;
88 static gint ett_obj_ident = -1;
89 static gint ett_response = -1;
90 static gint ett_valrep = -1;
91 static gint ett_open = -1;
92 static gint ett_close = -1;
93 static gint ett_register = -1;
94 static gint ett_unregister = -1;
95 static gint ett_getbulk = -1;
96 static gint ett_testset = -1;
97 static gint ett_commitset = -1;
98 static gint ett_undoset = -1;
99 static gint ett_cleanupset = -1;
100 static gint ett_notify = -1;
101 static gint ett_ping = -1;
102 static gint ett_idxalloc = -1;
103 static gint ett_idxdalloc = -1;
104 static gint ett_addcap = -1;
105 static gint ett_remcap = -1;
108 #define AGENTX_OPEN_PDU 1
109 #define AGENTX_CLOSE_PDU 2
110 #define AGENTX_REGISTER_PDU 3
111 #define AGENTX_UNREGISTER_PDU 4
112 #define AGENTX_GET_PDU 5
113 #define AGENTX_GETNEXT_PDU 6
114 #define AGENTX_GETBULK_PDU 7
115 #define AGENTX_TESTSET_PDU 8
116 #define AGENTX_COMMITSET_PDU 9
117 #define AGENTX_UNDOSET_PDU 10
118 #define AGENTX_CLEANUPSET_PDU 11
119 #define AGENTX_NOTIFY_PDU 12
120 #define AGENTX_PING_PDU 13
121 #define AGENTX_INDEX_ALLOC_PDU 14
122 #define AGENTX_INDEX_DEALLOC_PDU 15
123 #define AGENTX_ADD_AGENT_CAPS_PDU 16
124 #define AGENTX_REM_AGENT_CAPS_PDU 17
125 #define AGENTX_RESPONSE_PDU 18
128 static const value_string type_values [] = {
129 { AGENTX_OPEN_PDU, "Open-PDU" },
130 { AGENTX_CLOSE_PDU, "Close-PDU" },
131 { AGENTX_REGISTER_PDU, "Register-PDU" },
132 { AGENTX_UNREGISTER_PDU, "Unregister-PDU" },
133 { AGENTX_GET_PDU, "Get-PDU" },
134 { AGENTX_GETNEXT_PDU, "GetNext-PDU" },
135 { AGENTX_GETBULK_PDU, "GetBulk-PDU" },
136 { AGENTX_TESTSET_PDU, "TestSet-PDU" },
137 { AGENTX_COMMITSET_PDU, "CommitSet-PDU" },
138 { AGENTX_UNDOSET_PDU, "UndoSet-PDU" },
139 { AGENTX_CLEANUPSET_PDU, "CleanupSet-PDU" },
140 { AGENTX_NOTIFY_PDU, "Notify-PDU" },
141 { AGENTX_PING_PDU, "Ping-PDU" },
142 { AGENTX_INDEX_ALLOC_PDU, "IndexAllocate-PDU" },
143 { AGENTX_INDEX_DEALLOC_PDU, "IndexDeallocate-PDU" },
144 { AGENTX_ADD_AGENT_CAPS_PDU, "AddAgentCaps-PDU" },
145 { AGENTX_REM_AGENT_CAPS_PDU, "RemoveAgentCaps-PDU" },
146 { AGENTX_RESPONSE_PDU, "Response-PDU" },
149 static value_string_ext type_values_ext = VALUE_STRING_EXT_INIT(type_values);
158 #define VB_COUNTER32 65
159 #define VB_GAUGE32 66
160 #define VB_TIMETICK 67
162 #define VB_COUNTER64 70
163 #define VB_NOSUCHOBJ 128
164 #define VB_NOSUCHINST 129
165 #define VB_ENDOFMIB 130
168 static const value_string vtag_values [] = {
169 { VB_INT, "Integer" },
170 { VB_OSTR, "Octet String" },
172 { VB_OID, "Object Identifier" },
173 { VB_IPADDR, "IpAddress" },
174 { VB_COUNTER32, "Counter32" },
175 { VB_GAUGE32, "Gauge32" },
176 { VB_TIMETICK, "TimeTicks" },
177 { VB_OPAQUE, "Opaque" },
178 { VB_COUNTER64, "Counter64" },
179 { VB_NOSUCHOBJ, "noSuchObject" },
180 { VB_NOSUCHINST, "noSuchInstance" },
181 { VB_ENDOFMIB, "endOfMibView" },
184 static value_string_ext vtag_values_ext = VALUE_STRING_EXT_INIT(vtag_values);
187 #define CREASON_OTHER 1
188 #define CREASON_PARSE_ERROR 2
189 #define CREASON_PROTOCOL_ERROR 3
190 #define CREASON_TIMEOUTS 4
191 #define CREASON_SHUTDOWN 5
192 #define CREASON_BY_MANAGER 6
195 static const value_string close_reasons[] = {
196 { CREASON_OTHER, "reasonOther" },
197 { CREASON_PARSE_ERROR, "reasonParseError" },
198 { CREASON_PROTOCOL_ERROR, "reasonProtocolError" },
199 { CREASON_TIMEOUTS, "reasonTimeouts" },
200 { CREASON_SHUTDOWN , "reasonShutdown" },
201 { CREASON_BY_MANAGER, "reasonByManager" },
206 /* Response errors */
207 #define AGENTX_NO_ERROR 0
208 #define AGENTX_TOO_BIG 1
209 #define AGENTX_NO_SUCH_NAME 2
210 #define AGENTX_BAD_VALUE 3
211 #define AGENTX_READ_ONLY 4
212 #define AGENTX_GEN_ERROR 5
213 #define AGENTX_NO_ACCESS 6
214 #define AGENTX_WRONG_TYPE 7
215 #define AGENTX_WRONG_LEN 8
216 #define AGENTX_WRONG_ENCODE 9
217 #define AGENTX_WRONG_VALUE 10
218 #define AGENTX_NO_CREATION 11
219 #define AGENTX_INCONSIST_VALUE 12
220 #define AGENTX_RES_UNAVAIL 13
221 #define AGENTX_COMMIT_FAILED 14
222 #define AGENTX_UNDO_FAILED 15
223 #define AGENTX_AUTH_ERROR 16
224 #define AGENTX_NOTWRITABLE 17
225 #define AGENTX_INCONSIS_NAME 18
226 #define AGENTX_OPEN_FAILED 256
227 #define AGENTX_NOT_OPEN 257
228 #define AGENTX_IDX_WRONT_TYPE 258
229 #define AGENTX_IDX_ALREAY_ALLOC 259
230 #define AGENTX_IDX_NONEAVAIL 260
231 #define AGENTX_IDX_NOTALLOC 261
232 #define AGENTX_UNSUPP_CONTEXT 262
233 #define AGENTX_DUP_REGISTR 263
234 #define AGENTX_UNKNOWN_REG 264
235 #define AGENTX_UNKNOWN_CAPS 265
238 static const value_string resp_errors[] = {
239 { AGENTX_NO_ERROR, "noError" },
240 { AGENTX_TOO_BIG, "tooBig" },
241 { AGENTX_NO_SUCH_NAME, "noSuchName" },
242 { AGENTX_BAD_VALUE, "badValue" },
243 { AGENTX_READ_ONLY, "readOnly" },
244 { AGENTX_GEN_ERROR, "genErr" },
245 { AGENTX_NO_ACCESS, "noAccess" },
246 { AGENTX_WRONG_TYPE, "wrongType" },
247 { AGENTX_WRONG_LEN, "wrongLength" },
248 { AGENTX_WRONG_ENCODE, "wrongEncoding" },
249 { AGENTX_WRONG_VALUE, "wrongValue" },
250 { AGENTX_NO_CREATION, "noCreation" },
251 { AGENTX_INCONSIST_VALUE, "inconsistentValue" },
252 { AGENTX_RES_UNAVAIL, "resourceUnavailable" },
253 { AGENTX_COMMIT_FAILED, "commitFailed" },
254 { AGENTX_UNDO_FAILED , "undoFailed" },
255 { AGENTX_AUTH_ERROR, "authorizationError" },
256 { AGENTX_NOTWRITABLE, "notWritable" },
257 { AGENTX_INCONSIS_NAME, "inconsistentName" },
258 { AGENTX_OPEN_FAILED, "openFailed" },
259 { AGENTX_NOT_OPEN, "notOpen" },
260 { AGENTX_IDX_WRONT_TYPE, "indexWrongType" },
261 { AGENTX_IDX_ALREAY_ALLOC, "indexAlreadyAllocated" },
262 { AGENTX_IDX_NONEAVAIL, "indexNoneAvailable" },
263 { AGENTX_IDX_NOTALLOC, "indexNotAllocated" },
264 { AGENTX_UNSUPP_CONTEXT, "unsupportedContext" },
265 { AGENTX_DUP_REGISTR, "duplicateRegistration" },
266 { AGENTX_UNKNOWN_REG, "unknownRegistration" },
267 { AGENTX_UNKNOWN_CAPS, "unknownAgentCaps" },
270 static value_string_ext resp_errors_ext = VALUE_STRING_EXT_INIT(resp_errors);
272 /* OID usage indicators */
274 enum OID_USAGE { OID_START_RANGE, OID_END_RANGE, OID_EXACT };
276 /* PDU Header flags */
278 #define INSTANCE_REGISTRATION 0x01
279 #define NEW_INDEX 0x02
280 #define ANY_INDEX 0x04
281 #define NON_DEFAULT_CONTEXT 0x08
282 #define NETWORK_BYTE_ORDER 0x10
284 #define OID_IS_INCLUSIVE 0x01
286 #define PDU_HDR_LEN 20
287 #define PADDING(x) ((((x) + 3) >> 2) << 2)
289 #define NORLEL(flags,var,tvb,offset) \
290 var = (flags & NETWORK_BYTE_ORDER) ? \
291 tvb_get_ntohl(tvb, offset) : \
292 tvb_get_letohl(tvb, offset)
293 #define NORLES(flags,var,tvb,offset) \
294 var = (flags & NETWORK_BYTE_ORDER) ? \
295 tvb_get_ntohs(tvb, offset) : \
296 tvb_get_letohs(tvb, offset)
299 dissect_octet_string(tvbuff_t *tvb, proto_tree *tree, int offset, guint8 flags)
301 guint32 n_oct, p_noct;
303 NORLEL(flags, n_oct, tvb, offset);
305 p_noct = PADDING(n_oct);
307 proto_tree_add_uint(tree, hf_ostring_len, tvb, offset, 4, n_oct);
309 * XXX - an "octet string" is not necessarily a text string, so
310 * having hf_ostring be FT_STRING is not necessarily appropriate.
312 proto_tree_add_item(tree, hf_ostring, tvb, offset + 4, n_oct, ENC_ASCII|ENC_NA);
317 /* XXX - Is there a particular reason we're not using oid_encoded2string() here? */
319 convert_oid_to_str(guint32 *oid, int len, char* str, int slen, char prefix)
326 if(slen < len) return 0;
329 tlen += g_snprintf(str, slen, ".1.3.6.1.%d", prefix);
332 for(i=0; i < len && tlen < slen; i++) {
333 tlen += g_snprintf(str+tlen, slen-tlen, ".%d", oid[i]);
339 dissect_object_id(tvbuff_t *tvb, proto_tree *tree, int offset, guint8 flags, enum OID_USAGE oid_usage)
349 memset(oid, '\0', sizeof(oid));
350 memset(str_oid, '\0', sizeof(str_oid));
352 n_subid = tvb_get_guint8(tvb, offset);
353 prefix = tvb_get_guint8(tvb, offset + 1);
354 include = tvb_get_guint8(tvb, offset + 2);
355 tvb_get_guint8(tvb, offset + 3);
357 for(i=0; i<n_subid; i++) {
358 NORLEL(flags, oid[i], tvb, (offset+4) + (i*4));
361 if(!convert_oid_to_str(&oid[0], n_subid, &str_oid[0], 2048, prefix))
362 g_snprintf(&str_oid[0], 2048, "(null)");
365 const char *range = "";
366 const char *inclusion = (include) ? " (Inclusive)" : " (Exclusive)";
368 case OID_START_RANGE: range = "(Range Start) "; break;
369 case OID_END_RANGE: range = " (Range End) "; break;
370 default: inclusion = ""; break;
372 subtree = proto_tree_add_subtree_format(tree, tvb, offset, 4 + (n_subid * 4) ,
373 ett_obj_ident, NULL, "Object Identifier: %s%s%s", range, str_oid, inclusion);
377 proto_tree_add_uint(subtree, hf_oid_sub, tvb, offset, 1, n_subid);
378 proto_tree_add_uint(subtree, hf_oid_prefix, tvb, offset + 1, 1, prefix);
379 proto_tree_add_boolean(subtree, hf_oid_include, tvb, offset + 2, 1, include);
380 proto_tree_add_string(subtree, hf_oid_str, tvb, offset + 4, (n_subid * 4), str_oid);
382 return 4 + (n_subid * 4);
386 dissect_search_range(tvbuff_t *tvb, proto_tree *tree, int start_offset, guint8 flags, guint8 pdu_type)
388 int offset = start_offset;
389 offset += dissect_object_id(tvb, tree, offset, flags, (pdu_type == AGENTX_GET_PDU) ? OID_EXACT : OID_START_RANGE);
390 offset += dissect_object_id(tvb, tree, offset, flags, (pdu_type == AGENTX_GET_PDU) ? OID_EXACT : OID_END_RANGE);
392 return (offset - start_offset);
396 dissect_val64(tvbuff_t *tvb, proto_tree *tree, int offset, guint8 flags)
398 guint encoding = (flags & NETWORK_BYTE_ORDER) ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN;
400 proto_tree_add_item(tree, hf_val64, tvb, offset, 8, encoding);
406 dissect_val32(tvbuff_t *tvb, proto_tree *tree, int offset, guint8 flags)
408 guint encoding = (flags & NETWORK_BYTE_ORDER) ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN;
410 proto_tree_add_item(tree, hf_val32, tvb, offset, 4, encoding);
416 dissect_varbind(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
422 NORLES(flags, vtag, tvb, offset);
423 /* 2 reserved bytes after this */
426 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_valrep, NULL, "Value Representation");
429 proto_tree_add_uint(subtree, hf_vtag, tvb, offset, 2, vtag);
430 tlen = dissect_object_id(tvb, subtree, offset + 4, flags, OID_EXACT);
435 tlen += dissect_object_id(tvb, subtree, offset + tlen + 4, flags, OID_EXACT);
441 tlen += dissect_octet_string(tvb, subtree, offset + tlen + 4, flags);
448 tlen += dissect_val32(tvb, subtree, offset + tlen + 4, flags);
452 tlen += dissect_val64(tvb, subtree, offset + tlen + 4, flags);
465 dissect_response_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
468 guint encoding = (flags & NETWORK_BYTE_ORDER) ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN;
471 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_response, NULL, "Response-PDU");
473 NORLEL(flags, r_uptime, tvb, offset);
474 proto_tree_add_uint_format(subtree, hf_resp_uptime, tvb, offset, 4, r_uptime,
475 "sysUptime: %s", time_msecs_to_str(wmem_packet_scope(), r_uptime));
476 proto_tree_add_item(subtree, hf_resp_error, tvb, offset + 4, 2, encoding);
477 proto_tree_add_item(subtree, hf_resp_index, tvb, offset + 6, 2, encoding);
481 while(len > offset) {
482 offset += dissect_varbind(tvb, subtree, offset, len, flags);
487 dissect_getnext_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
491 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_getnext, NULL, "GetNext-PDU");
493 if(flags & NON_DEFAULT_CONTEXT) {
495 offset += dissect_octet_string(tvb, subtree, offset, flags);
499 while(len > offset) {
500 offset += dissect_search_range(tvb, subtree, offset, flags, 0);
505 dissect_get_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
509 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_get, NULL, "Get-PDU");
511 if(flags & NON_DEFAULT_CONTEXT) {
513 offset += dissect_octet_string(tvb, subtree, offset, flags);
517 while(len > offset) {
518 offset += dissect_search_range(tvb, subtree, offset, flags, AGENTX_GET_PDU);
523 dissect_getbulk_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
526 guint encoding = (flags & NETWORK_BYTE_ORDER) ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN;
528 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_getbulk, NULL, "GetBulk-PDU");
530 if(flags & NON_DEFAULT_CONTEXT) {
532 offset += dissect_octet_string(tvb, subtree, offset, flags);
535 proto_tree_add_item(subtree, hf_gbulk_nrepeat, tvb, offset, 2, encoding);
536 proto_tree_add_item(subtree, hf_gbulk_mrepeat, tvb, offset + 2, 2, encoding);
539 while(len >= offset) {
540 offset += dissect_search_range(tvb, subtree, offset, flags, 0);
545 dissect_open_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
550 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_open, NULL, "Open-PDU");
552 timeout = tvb_get_guint8(tvb, offset);
553 tvb_get_ntoh24(tvb, offset + 1);
555 proto_tree_add_uint(subtree, hf_open_timeout, tvb, offset, 1, timeout);
559 offset += dissect_object_id(tvb, subtree, offset, flags, OID_EXACT);
562 offset += dissect_octet_string(tvb, subtree, offset, flags);
567 dissect_close_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len)
571 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_close, NULL, "Close-PDU");
573 proto_tree_add_item(subtree, hf_close_reason, tvb, offset, 1, ENC_NA);
574 tvb_get_ntoh24(tvb, offset + 1);
581 dissect_register_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
584 guint encoding = (flags & NETWORK_BYTE_ORDER) ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN;
586 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_register, NULL, "Register-PDU");
588 if(flags & NON_DEFAULT_CONTEXT) {
590 offset += dissect_octet_string(tvb, subtree, offset, flags);
593 proto_tree_add_item(subtree, hf_reg_timeout, tvb, offset, 1, encoding);
594 proto_tree_add_item(subtree, hf_reg_prio, tvb, offset+1, 1, encoding);
595 proto_tree_add_item(subtree, hf_reg_rsid, tvb, offset+2, 1, encoding);
600 offset += dissect_object_id(tvb, subtree, offset, flags, OID_EXACT);
604 /* Upper bound (opt) */
605 proto_tree_add_item(subtree, hf_reg_ubound, tvb, offset, 4, encoding);
613 dissect_unregister_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
616 guint encoding = (flags & NETWORK_BYTE_ORDER) ? ENC_BIG_ENDIAN : ENC_LITTLE_ENDIAN;
618 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_unregister, NULL, "Unregister-PDU");
620 if(flags & NON_DEFAULT_CONTEXT) {
622 offset += dissect_octet_string(tvb, subtree, offset, flags);
625 proto_tree_add_item(subtree, hf_unreg_timeout, tvb, offset, 1, encoding);
626 proto_tree_add_item(subtree, hf_unreg_prio, tvb, offset+1, 1, encoding);
627 proto_tree_add_item(subtree, hf_unreg_rsid, tvb, offset+2, 1, encoding);
631 offset += dissect_object_id(tvb, subtree, offset, flags, OID_EXACT);
635 /* Upper bound (opt) */
636 proto_tree_add_item(subtree, hf_unreg_ubound, tvb, offset, 4, encoding);
644 dissect_testset_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
648 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_testset, NULL, "Testset-PDU");
650 if(flags & NON_DEFAULT_CONTEXT) {
652 offset += dissect_octet_string(tvb, subtree, offset, flags);
655 while(len > offset) {
656 offset += dissect_varbind(tvb, subtree, offset, len, flags);
661 dissect_notify_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
665 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_notify, NULL, "Notify-PDU");
667 if(flags & NON_DEFAULT_CONTEXT) {
669 offset += dissect_octet_string(tvb, subtree, offset, flags);
672 while(len > offset) {
673 offset += dissect_varbind(tvb, subtree, offset, len, flags);
678 dissect_ping_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
682 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_ping, NULL, "Ping-PDU");
684 if(flags & NON_DEFAULT_CONTEXT) {
686 offset += dissect_octet_string(tvb, subtree, offset, flags);
692 dissect_idx_alloc_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
696 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_idxalloc, NULL, "IndexAllocate-PDU");
698 if(flags & NON_DEFAULT_CONTEXT) {
700 offset += dissect_octet_string(tvb, subtree, offset, flags);
703 while(len > offset) {
704 offset += dissect_varbind(tvb, subtree, offset, len, flags);
710 dissect_idx_dealloc_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
714 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_idxdalloc, NULL, "IndexDeallocate-PDU");
716 if(flags & NON_DEFAULT_CONTEXT) {
718 offset += dissect_octet_string(tvb, subtree, offset, flags);
721 while(len > offset) {
722 offset += dissect_varbind(tvb, subtree, offset, len, flags);
727 dissect_add_caps_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
731 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_addcap, NULL, "AddAgentCaps-PDU");
733 if(flags & NON_DEFAULT_CONTEXT) {
735 offset += dissect_octet_string(tvb, subtree, offset, flags);
738 offset += dissect_object_id(tvb, subtree, offset, flags, OID_EXACT);
740 offset += dissect_octet_string(tvb, subtree, offset, flags);
746 dissect_rem_caps_pdu(tvbuff_t *tvb, proto_tree *tree, int offset, int len, guint8 flags)
750 subtree = proto_tree_add_subtree(tree, tvb, offset, len, ett_remcap, NULL, "RemoveAgentCaps-PDU");
752 if(flags & NON_DEFAULT_CONTEXT) {
754 offset += dissect_octet_string(tvb, subtree, offset, flags);
757 offset += dissect_object_id(tvb, subtree, offset, flags, OID_EXACT);
764 get_agentx_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
770 * Get the payload length.
772 flags = tvb_get_guint8(tvb, offset + 2);
773 NORLEL(flags, plen, tvb, offset + 16);
776 * Arbitrarily limit it to 2^24, so we don't have to worry about
783 * That length doesn't include the header; add that in.
789 dissect_agentx_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
792 proto_tree* agentx_tree, *pdu_hdr_tree;
801 static const int * pdu_flags[] = {
810 version = tvb_get_guint8(tvb, 0); offset+=1;
811 type = tvb_get_guint8(tvb, 1); offset+=1;
812 flags = tvb_get_guint8(tvb, 2); offset+=1;
813 /* skip reserved byte */
816 NORLEL(flags, session_id, tvb, 4); offset+=4;
817 NORLEL(flags, trans_id, tvb, 8); offset+=4;
818 NORLEL(flags, packet_id, tvb, 12); offset+=4;
819 NORLEL(flags, payload_len, tvb, 16); offset+=4;
821 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AgentX");
823 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: sid=%d, tid=%d, packid=%d, plen=%d",
824 val_to_str_ext_const(type, &type_values_ext, "unknown"),
825 session_id, trans_id, packet_id, payload_len);
829 return tvb_captured_length(tvb);
831 /*t_item = proto_tree_add_item(tree, proto_agentx, tvb, 0, -1, ENC_NA);*/
832 t_item = proto_tree_add_protocol_format(tree, proto_agentx, tvb, 0, -1,
833 "Agent Extensibility (AgentX) Protocol: %s, sid=%d, tid=%d, packid=%d, plen=%d",
834 val_to_str_ext_const(type, &type_values_ext, "unknown"),
835 session_id, trans_id, packet_id, payload_len);
836 agentx_tree = proto_item_add_subtree(t_item, ett_agentx);
838 pdu_hdr_tree = proto_tree_add_subtree_format(agentx_tree, tvb, 0, PDU_HDR_LEN,
839 ett_pdu_hdr, NULL, "PDU Header: Type[%u], len=%d, sid=%d, tid=%d, packid=%d",
840 (char)type, payload_len, session_id, trans_id, packet_id);
842 proto_tree_add_uint(pdu_hdr_tree, hf_version, tvb, 0, 1, version);
843 proto_tree_add_uint(pdu_hdr_tree, hf_type, tvb, 1, 1, type);
844 proto_tree_add_bitmask(pdu_hdr_tree, tvb, 2, hf_flags, ett_flags, pdu_flags, ENC_NA);
846 proto_tree_add_uint(pdu_hdr_tree, hf_session_id, tvb, 4, 4, session_id);
847 proto_tree_add_uint(pdu_hdr_tree, hf_trans_id, tvb, 8, 4, trans_id);
848 proto_tree_add_uint(pdu_hdr_tree, hf_packet_id, tvb, 12, 4, packet_id);
849 proto_tree_add_uint(pdu_hdr_tree, hf_payload_len, tvb, 16, 4, payload_len);
852 case AGENTX_OPEN_PDU:
853 dissect_open_pdu(tvb, agentx_tree, offset, payload_len, flags);
856 case AGENTX_CLOSE_PDU:
857 dissect_close_pdu(tvb, agentx_tree, offset, payload_len);
860 case AGENTX_REGISTER_PDU:
861 dissect_register_pdu(tvb, agentx_tree, offset, payload_len, flags);
864 case AGENTX_UNREGISTER_PDU:
865 dissect_unregister_pdu(tvb, agentx_tree, offset, payload_len, flags);
869 dissect_get_pdu(tvb, agentx_tree, offset, payload_len, flags);
872 case AGENTX_GETNEXT_PDU:
873 dissect_getnext_pdu(tvb, agentx_tree, offset, payload_len, flags);
876 case AGENTX_GETBULK_PDU:
877 dissect_getbulk_pdu(tvb, agentx_tree, offset, payload_len, flags);
880 case AGENTX_TESTSET_PDU:
881 dissect_testset_pdu(tvb, agentx_tree, offset, payload_len, flags);
884 case AGENTX_COMMITSET_PDU:
885 case AGENTX_UNDOSET_PDU:
886 case AGENTX_CLEANUPSET_PDU:
887 /* there is no parameters */
890 case AGENTX_NOTIFY_PDU:
891 dissect_notify_pdu(tvb, agentx_tree, offset, payload_len, flags);
894 case AGENTX_PING_PDU:
895 dissect_ping_pdu(tvb, agentx_tree, offset, payload_len, flags);
898 case AGENTX_INDEX_ALLOC_PDU:
899 dissect_idx_alloc_pdu(tvb, agentx_tree, offset, payload_len, flags);
902 case AGENTX_INDEX_DEALLOC_PDU:
903 dissect_idx_dealloc_pdu(tvb, agentx_tree, offset, payload_len, flags);
906 case AGENTX_ADD_AGENT_CAPS_PDU:
907 dissect_add_caps_pdu(tvb, agentx_tree, offset, payload_len, flags);
910 case AGENTX_REM_AGENT_CAPS_PDU:
911 dissect_rem_caps_pdu(tvb, agentx_tree, offset, payload_len, flags);
914 case AGENTX_RESPONSE_PDU:
915 dissect_response_pdu(tvb, agentx_tree, offset, payload_len, flags);
919 return tvb_captured_length(tvb);
923 dissect_agentx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
925 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 20, get_agentx_pdu_len,
926 dissect_agentx_pdu, data);
927 return tvb_captured_length(tvb);
930 static const true_false_string tfs_agentx_context = { "Provided", "None" };
931 static const true_false_string tfs_agentx_byteorder = { "MSB (network order)", "LSB" };
934 proto_register_agentx(void)
936 static hf_register_info hf[] = {
939 { "Version", "agentx.version", FT_UINT8, BASE_DEC, NULL, 0x0,
940 "header version", HFILL }},
943 { "Type", "agentx.type", FT_UINT8, BASE_DEC | BASE_EXT_STRING, &type_values_ext, 0x0,
944 "header type", HFILL }},
947 { "Flags", "agentx.flags", FT_UINT8, BASE_DEC, NULL, 0x0,
948 "header type", HFILL }},
950 { &hf_flags_register,
951 { "Register", "agentx.flags.register", FT_BOOLEAN, 8, TFS(&tfs_yes_no),
952 INSTANCE_REGISTRATION, "Instance Registration", HFILL }},
954 { &hf_flags_newindex,
955 { "New Index", "agentx.flags.newindex", FT_BOOLEAN, 8, TFS(&tfs_yes_no),
956 NEW_INDEX, "New Index Requested", HFILL }},
958 { &hf_flags_anyindex,
959 { "Any Index", "agentx.flags.anyindex", FT_BOOLEAN, 8, TFS(&tfs_yes_no),
960 ANY_INDEX, "Any Index Requested", HFILL }},
963 { "Non-default Context", "agentx.flags.context", FT_BOOLEAN, 8, TFS(&tfs_agentx_context),
964 NON_DEFAULT_CONTEXT, NULL, HFILL }},
966 { &hf_flags_byteorder,
967 { "Byte Order", "agentx.flags.byteorder", FT_BOOLEAN, 8, TFS(&tfs_agentx_byteorder),
968 NETWORK_BYTE_ORDER, NULL, HFILL }},
971 { "sessionID", "agentx.session_id", FT_UINT32, BASE_DEC, NULL, 0x0,
972 "Session ID", HFILL }},
975 { "TransactionID", "agentx.transaction_id", FT_UINT32, BASE_DEC, NULL, 0x0,
976 "Transaction ID", HFILL }},
979 { "PacketID", "agentx.packet_id", FT_UINT32, BASE_DEC, NULL, 0x0,
980 "Packet ID", HFILL }},
983 { "Payload length", "agentx.payload_len", FT_UINT32, BASE_DEC, NULL, 0x0,
987 { "Octet String", "agentx.ostring", FT_STRING, BASE_NONE, NULL, 0x0,
991 { "OString len", "agentx.ostring_len", FT_UINT32, BASE_DEC, NULL, 0x0,
992 "Octet String Length", HFILL }},
995 { "Number subids", "agentx.n_subid", FT_UINT8, BASE_DEC, NULL, 0x0,
999 { "OID prefix", "agentx.oid_prefix", FT_UINT8, BASE_DEC, NULL, 0x0,
1003 { "OID include", "agentx.oid_include", FT_BOOLEAN, 8, TFS(&tfs_yes_no),
1004 OID_IS_INCLUSIVE, NULL, HFILL }},
1007 { "OID", "agentx.oid", FT_STRING, BASE_NONE, NULL, 0x0,
1011 { "sysUpTime", "agentx.r.uptime", FT_UINT32, BASE_DEC, NULL, 0x0,
1015 { "Resp. error", "agentx.r.error", FT_UINT16, BASE_DEC | BASE_EXT_STRING, &resp_errors_ext, 0x0,
1016 "response error", HFILL }},
1019 { "Resp. index", "agentx.r.index", FT_UINT16, BASE_DEC, NULL, 0x0,
1020 "response index", HFILL }},
1023 { "Variable type", "agentx.v.tag", FT_UINT16, BASE_DEC | BASE_EXT_STRING, &vtag_values_ext, 0x0,
1027 { "Value(32)", "agentx.v.val32", FT_UINT32, BASE_DEC, NULL, 0x0,
1031 { "Value(64)", "agentx.v.val64", FT_UINT64, BASE_DEC, NULL, 0x0,
1035 { "Timeout", "agentx.o.timeout", FT_UINT8, BASE_DEC, NULL, 0x0,
1036 "open timeout", HFILL }},
1039 { "Reason", "agentx.c.reason", FT_UINT8, BASE_DEC, VALS(close_reasons), 0x0,
1040 "close reason", HFILL }},
1043 { "Timeout", "agentx.r.timeout", FT_UINT8, BASE_DEC, NULL, 0x0,
1044 "Register timeout", HFILL }},
1047 { "Priority", "agentx.r.priority", FT_UINT8, BASE_DEC, NULL, 0x0,
1048 "Register Priority", HFILL }},
1051 { "Range_subid", "agentx.r.range_subid", FT_UINT8, BASE_DEC, NULL, 0x0,
1052 "Register range_subid", HFILL }},
1055 { "Upper bound", "agentx.r.upper_bound", FT_UINT32, BASE_DEC, NULL, 0x0,
1056 "Register upper bound", HFILL }},
1058 { &hf_unreg_timeout,
1059 { "Timeout", "agentx.u.timeout", FT_UINT8, BASE_DEC, NULL, 0x0,
1060 "Unregister timeout", HFILL }},
1063 { "Priority", "agentx.u.priority", FT_UINT8, BASE_DEC, NULL, 0x0,
1064 "Unregister Priority", HFILL }},
1067 { "Range_subid", "agentx.u.range_subid", FT_UINT8, BASE_DEC, NULL, 0x0,
1068 "Unregister range_subid", HFILL }},
1071 { "Upper bound", "agentx.u.upper_bound", FT_UINT32, BASE_DEC, NULL, 0x0,
1072 "Register upper bound", HFILL }},
1074 { &hf_gbulk_nrepeat,
1075 { "Repeaters", "agentx.gb.nrepeat", FT_UINT16, BASE_DEC, NULL, 0x0,
1076 "getBulk Num. repeaters", HFILL }},
1078 { &hf_gbulk_mrepeat,
1079 { "Max Repetition", "agentx.gb.mrepeat", FT_UINT16, BASE_DEC, NULL, 0x0,
1080 "getBulk Max repetition", HFILL }},
1083 /* Add more fields here */
1087 static gint *ett[] = {
1115 module_t *agentx_module;
1117 proto_agentx = proto_register_protocol("AgentX",
1118 "AgentX", "agentx");
1120 proto_register_field_array(proto_agentx, hf, array_length(hf));
1121 proto_register_subtree_array(ett, array_length(ett));
1123 agentx_module = prefs_register_protocol(proto_agentx, proto_reg_handoff_agentx);
1125 prefs_register_uint_preference(agentx_module, "tcp.agentx_port",
1126 "AgentX listener TCP Port",
1127 "Set the TCP port for AgentX"
1128 "(if other than the default of 705)",
1129 10, &global_agentx_tcp_port);
1132 /* The registration hand-off routine */
1134 proto_reg_handoff_agentx(void)
1136 static gboolean agentx_prefs_initialized = FALSE;
1137 static dissector_handle_t agentx_handle;
1138 static guint agentx_tcp_port;
1140 if(!agentx_prefs_initialized) {
1141 agentx_handle = new_create_dissector_handle(dissect_agentx, proto_agentx);
1142 agentx_prefs_initialized = TRUE;
1145 dissector_delete_uint("tcp.port", agentx_tcp_port, agentx_handle);
1148 agentx_tcp_port = global_agentx_tcp_port;
1149 dissector_add_uint("tcp.port", agentx_tcp_port, agentx_handle);
1153 * Editor modelines - http://www.wireshark.org/tools/modelines.html
1158 * indent-tabs-mode: t
1161 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1162 * :indentSize=8:tabSize=8:noTabs=false: