2 * Routines for Agent Extensibility (AgentX) Protocol disassembly
7 * Copyright (c) 2005 by Oleg Terletsky <oleg.terletsky@comverse.com>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1999 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 #include <epan/packet.h>
39 #include <epan/prefs.h>
41 #include <epan/dissectors/packet-tcp.h>
43 static guint global_agentx_tcp_port = 705;
45 void proto_reg_handoff_agentx(void);
48 /* Define the agentx proto */
49 static int proto_agentx = -1;
52 static int hf_version = -1;
53 static int hf_type = -1;
54 static int hf_flags = -1;
55 static int hf_session_id = -1;
56 static int hf_trans_id = -1;
57 static int hf_packet_id = -1;
58 static int hf_payload_len = -1;
59 static int hf_ostring_len = -1;
60 static int hf_ostring = -1;
61 static int hf_oid_sub = -1;
62 static int hf_oid_prefix = -1;
63 static int hf_oid_include = -1;
64 static int hf_oid_str = -1;
65 static int hf_resp_uptime = -1;
66 static int hf_resp_error = -1;
67 static int hf_resp_index = -1;
68 static int hf_vtag = -1;
69 static int hf_val32 = -1;
70 static int hf_val64 = -1;
71 static int hf_open_timeout = -1;
72 static int hf_close_reason = -1;
73 static int hf_reg_timeout = -1;
74 static int hf_reg_prio = -1;
75 static int hf_reg_rsid = -1;
76 static int hf_reg_ubound = -1;
77 static int hf_unreg_timeout = -1;
78 static int hf_unreg_prio = -1;
79 static int hf_unreg_rsid = -1;
80 static int hf_unreg_ubound = -1;
81 static int hf_gbulk_nrepeat = -1;
82 static int hf_gbulk_mrepeat = -1;
85 static gint ett_agentx = -1;
86 static gint ett_pdu_hdr = -1;
87 static gint ett_get = -1;
88 static gint ett_getnext = -1;
89 static gint ett_search_range = -1;
90 static gint ett_obj_ident = -1;
91 static gint ett_response = -1;
92 static gint ett_valrep = -1;
93 static gint ett_open = -1;
94 static gint ett_close = -1;
95 static gint ett_register = -1;
96 static gint ett_unregister = -1;
97 static gint ett_getbulk = -1;
98 static gint ett_testset = -1;
99 static gint ett_commitset = -1;
100 static gint ett_undoset = -1;
101 static gint ett_cleanupset = -1;
102 static gint ett_notify = -1;
103 static gint ett_ping = -1;
104 static gint ett_idxalloc = -1;
105 static gint ett_idxdalloc = -1;
106 static gint ett_addcap = -1;
107 static gint ett_remcap = -1;
110 #define AGENTX_OPEN_PDU 1
111 #define AGENTX_CLOSE_PDU 2
112 #define AGENTX_REGISTER_PDU 3
113 #define AGENTX_UNREGISTER_PDU 4
114 #define AGENTX_GET_PDU 5
115 #define AGENTX_GETNEXT_PDU 6
116 #define AGENTX_GETBULK_PDU 7
117 #define AGENTX_TESTSET_PDU 8
118 #define AGENTX_COMMITSET_PDU 9
119 #define AGENTX_UNDOSET_PDU 10
120 #define AGENTX_CLEANUPSET_PDU 11
121 #define AGENTX_NOTIFY_PDU 12
122 #define AGENTX_PING_PDU 13
123 #define AGENTX_INDEX_ALLOC_PDU 14
124 #define AGENTX_INDEX_DEALLOC_PDU 15
125 #define AGENTX_ADD_AGENT_CAPS_PDU 16
126 #define AGENTX_REM_AGENT_CAPS_PDU 17
127 #define AGENTX_RESPONSE_PDU 18
130 static const value_string type_values [] = {
131 { AGENTX_OPEN_PDU, "Open-PDU" },
132 { AGENTX_CLOSE_PDU, "Close-PDU" },
133 { AGENTX_REGISTER_PDU, "Register-PDU" },
134 { AGENTX_UNREGISTER_PDU, "Unregister-PDU" },
135 { AGENTX_GET_PDU, "Get-PDU" },
136 { AGENTX_GETNEXT_PDU, "GetNext-PDU" },
137 { AGENTX_GETBULK_PDU, "GetBulk-PDU" },
138 { AGENTX_TESTSET_PDU, "TestSet-PDU" },
139 { AGENTX_COMMITSET_PDU, "CommitSet-PDU" },
140 { AGENTX_UNDOSET_PDU, "UndoSet-PDU" },
141 { AGENTX_CLEANUPSET_PDU, "CleanupSet-PDU" },
142 { AGENTX_NOTIFY_PDU, "Notify-PDU" },
143 { AGENTX_PING_PDU, "Ping-PDU" },
144 { AGENTX_INDEX_ALLOC_PDU, "IndexAllocate-PDU" },
145 { AGENTX_INDEX_DEALLOC_PDU, "IndexDeallocate-PDU" },
146 { AGENTX_ADD_AGENT_CAPS_PDU, "AddAgentCaps-PDU" },
147 { AGENTX_REM_AGENT_CAPS_PDU, "RemoveAgentCaps-PDU" },
148 { AGENTX_RESPONSE_PDU, "Response-PDU" },
160 #define VB_COUNTER32 65
161 #define VB_GAUGE32 66
162 #define VB_TIMETICK 67
164 #define VB_COUNTER64 70
165 #define VB_NOSUCHOBJ 128
166 #define VB_NOSUCHINST 129
167 #define VB_ENDOFMIB 130
170 static const value_string vtag_values [] = {
171 { VB_INT, "Integer" },
172 { VB_OSTR, "Octet String" },
174 { VB_OID, "Object Identifier" },
175 { VB_IPADDR, "IpAddress" },
176 { VB_COUNTER32, "Counter32" },
177 { VB_GAUGE32, "Gauge32" },
178 { VB_TIMETICK, "TimeTicks" },
179 { VB_OPAQUE, "Opaque" },
180 { VB_COUNTER64, "Counter64" },
181 { VB_NOSUCHOBJ, "noSuchObject" },
182 { VB_NOSUCHINST, "noSuchInstance" },
183 { VB_ENDOFMIB, "endOfMibView" },
189 #define CREASON_OTHER 1
190 #define CREASON_PARSE_ERROR 2
191 #define CREASON_PROTOCOL_ERROR 3
192 #define CREASON_TIMEOUTS 4
193 #define CREASON_SHUTDOWN 5
194 #define CREASON_BY_MANAGER 6
197 static const value_string close_reasons[] = {
198 { CREASON_OTHER, "reasonOther" },
199 { CREASON_PARSE_ERROR, "reasonParseError" },
200 { CREASON_PROTOCOL_ERROR, "reasonProtocolError" },
201 { CREASON_TIMEOUTS, "reasonTimeouts" },
202 { CREASON_SHUTDOWN , "reasonShutdown" },
203 { CREASON_BY_MANAGER, "reasonByManager" },
208 /* Response errors */
209 #define AGENTX_NO_ERROR 0
210 #define AGENTX_TOO_BIG 1
211 #define AGENTX_NO_SUCH_NAME 2
212 #define AGENTX_BAD_VALUE 3
213 #define AGENTX_READ_ONLY 4
214 #define AGENTX_GEN_ERROR 5
215 #define AGENTX_NO_ACCESS 6
216 #define AGENTX_WRONG_TYPE 7
217 #define AGENTX_WRONG_LEN 8
218 #define AGENTX_WRONG_ENCODE 9
219 #define AGENTX_WRONG_VALUE 10
220 #define AGENTX_NO_CREATION 11
221 #define AGENTX_INCONSIST_VALUE 12
222 #define AGENTX_RES_UNAVAIL 13
223 #define AGENTX_COMMIT_FAILED 14
224 #define AGENTX_UNDO_FAILED 15
225 #define AGENTX_AUTH_ERROR 16
226 #define AGENTX_NOTWRITABLE 17
227 #define AGENTX_INCONSIS_NAME 18
228 #define AGENTX_OPEN_FAILED 256
229 #define AGENTX_NOT_OPEN 257
230 #define AGENTX_IDX_WRONT_TYPE 258
231 #define AGENTX_IDX_ALREAY_ALLOC 259
232 #define AGENTX_IDX_NONEAVAIL 260
233 #define AGENTX_IDX_NOTALLOC 261
234 #define AGENTX_UNSUPP_CONTEXT 262
235 #define AGENTX_DUP_REGISTR 263
236 #define AGENTX_UNKNOWN_REG 264
237 #define AGENTX_UNKNOWN_CAPS 265
240 static const value_string resp_errors[] = {
241 { AGENTX_NO_ERROR, "noError" },
242 { AGENTX_TOO_BIG, "tooBig" },
243 { AGENTX_NO_SUCH_NAME, "noSuchName" },
244 { AGENTX_BAD_VALUE, "badValue" },
245 { AGENTX_READ_ONLY, "readOnly" },
246 { AGENTX_GEN_ERROR, "genErr" },
247 { AGENTX_NO_ACCESS, "noAccess" },
248 { AGENTX_WRONG_TYPE, "wrongType" },
249 { AGENTX_WRONG_LEN, "wrongLength" },
250 { AGENTX_WRONG_ENCODE, "wrongEncoding" },
251 { AGENTX_WRONG_VALUE, "wrongValue" },
252 { AGENTX_NO_CREATION, "noCreation" },
253 { AGENTX_INCONSIST_VALUE, "inconsistentValue" },
254 { AGENTX_RES_UNAVAIL, "resourceUnavailable" },
255 { AGENTX_COMMIT_FAILED, "commitFailed" },
256 { AGENTX_UNDO_FAILED , "undoFailed" },
257 { AGENTX_AUTH_ERROR, "authorizationError" },
258 { AGENTX_NOTWRITABLE, "notWritable" },
259 { AGENTX_INCONSIS_NAME, "inconsistentName" },
260 { AGENTX_OPEN_FAILED, "openFailed" },
261 { AGENTX_NOT_OPEN, "notOpen" },
262 { AGENTX_IDX_WRONT_TYPE, "indexWrongType" },
263 { AGENTX_IDX_ALREAY_ALLOC, "indexAlreadyAllocated" },
264 { AGENTX_IDX_NONEAVAIL, "indexNoneAvailable" },
265 { AGENTX_IDX_NOTALLOC, "indexNotAllocated" },
266 { AGENTX_UNSUPP_CONTEXT, "unsupportedContext" },
267 { AGENTX_DUP_REGISTR, "duplicateRegistration" },
268 { AGENTX_UNKNOWN_REG, "unknownRegistration" },
269 { AGENTX_UNKNOWN_CAPS, "unknownAgentCaps" },
276 /* PDU Header flags */
278 #define INSTANCE_REGISTRATION 0
279 #define NEW_INDEX 0x1
280 #define ANY_INDEX 0x2
281 #define NON_DEFAULT_CONTEXT 0x4
282 #define NETWORK_BYTE_ORDER 0x8
284 #define PDU_HDR_LEN 20
285 #define PADDING(x) ((((x) + 3) >> 2) << 2)
287 #define NORLEL(flags,var,tvb,offset) \
288 var = (flags & NETWORK_BYTE_ORDER) ? \
289 tvb_get_ntohl(tvb, offset) : \
290 tvb_get_letohl(tvb, offset)
291 #define NORLES(flags,var,tvb,offset) \
292 var = (flags & NETWORK_BYTE_ORDER) ? \
293 tvb_get_ntohs(tvb, offset) : \
294 tvb_get_letohs(tvb, offset)
296 static int dissect_octet_string(tvbuff_t *tvb, proto_tree *tree, int offset, char flags)
298 guint32 n_oct, p_noct;
301 NORLEL(flags, n_oct, tvb, offset);
303 p_noct = PADDING(n_oct);
305 THROW(ReportedBoundsError);
306 tvb_get_nstringz(tvb, offset + 4, n_oct, context);
309 proto_tree_add_uint(tree,hf_ostring_len,tvb,offset,4,n_oct);
310 proto_tree_add_string(tree, hf_ostring, tvb, offset + 4, n_oct, context);
315 /* XXX - Is there a particular reason we're not using oid_encoded2string() here? */
316 static int convert_oid_to_str(guint32 *oid, int len, char* str, int slen, char prefix)
323 if(slen < len) return 0;
326 tlen += g_snprintf(str,slen,".1.3.6.1.%d",prefix);
329 for(i=0; i < len && tlen < slen; i++) {
330 tlen += g_snprintf(str+tlen,slen-tlen,".%d",oid[i]);
335 static int dissect_object_id(tvbuff_t *tvb, proto_tree *tree, int offset, char flags)
346 memset(oid, '\0', sizeof(oid));
347 memset(str_oid, '\0', sizeof(str_oid));
349 n_subid = tvb_get_guint8(tvb, offset);
350 prefix = tvb_get_guint8(tvb, offset + 1);
351 include = tvb_get_guint8(tvb,offset + 2);
352 tvb_get_guint8(tvb, offset + 3);
354 for(i=0; i<n_subid; i++) {
355 NORLEL(flags, oid[i], tvb, (offset+4) + (i*4));
358 if(!(slen = convert_oid_to_str(&oid[0], n_subid, &str_oid[0], 2048, prefix)))
363 item = proto_tree_add_text(tree,tvb,offset,n_subid + 4 ,
364 "Object Identifier: (%s) %s",(include) ? "Start" : "End" , str_oid);
365 subtree = proto_item_add_subtree(item, ett_obj_ident);
366 } else return offset;
368 proto_tree_add_uint(subtree, hf_oid_sub, tvb, offset, 1, n_subid);
369 proto_tree_add_uint(subtree, hf_oid_prefix, tvb, offset + 1, 1, prefix);
370 proto_tree_add_uint(subtree, hf_oid_include, tvb, offset + 2, 1, include);
371 proto_tree_add_string(subtree,hf_oid_str, tvb, offset + 4, slen, str_oid);
373 return 4 + (n_subid * 4);
376 static int dissect_search_range(tvbuff_t *tvb, proto_tree *tree, int offset, char flags)
379 offset += dissect_object_id(tvb, tree, offset, flags);
380 offset += dissect_object_id(tvb, tree, offset, flags);
385 static int dissect_val64(tvbuff_t *tvb, proto_tree *tree, int offset, char flags)
387 gboolean little_endian = !(flags & NETWORK_BYTE_ORDER);
389 proto_tree_add_item(tree, hf_val64, tvb, offset, 8, little_endian);
394 static int dissect_val32(tvbuff_t *tvb, proto_tree *tree, int offset, char flags)
396 gboolean little_endian = !(flags & NETWORK_BYTE_ORDER);
398 proto_tree_add_item(tree, hf_val32, tvb, offset, 4, little_endian);
403 static int dissect_varbind(tvbuff_t *tvb, proto_tree *tree, int offset, int len, char flags)
410 NORLES(flags, vtag, tvb, offset);
411 /* 2 reserved bytes after this */
414 item = proto_tree_add_text(tree,tvb, offset, len, "Value Representation");
415 subtree = proto_item_add_subtree(item, ett_valrep);
418 proto_tree_add_uint(subtree, hf_vtag, tvb, offset, 2, vtag);
419 tlen = dissect_object_id(tvb, subtree, offset + 4, flags);
424 tlen += dissect_object_id(tvb, subtree, offset + tlen + 4, flags);
430 tlen += dissect_octet_string(tvb, subtree,offset + tlen + 4,flags);
437 tlen += dissect_val32(tvb, subtree,offset + tlen + 4, flags);
441 tlen += dissect_val64(tvb, subtree,offset + tlen + 4, flags);
453 static void dissect_response_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
457 gboolean little_endian = !(flags & NETWORK_BYTE_ORDER);
460 item = proto_tree_add_text(tree, tvb, offset, len, "Response-PDU");
461 subtree = proto_item_add_subtree(item, ett_response);
463 r_uptime = little_endian ? \
464 tvb_get_letohl(tvb, offset) : tvb_get_ntohl(tvb, offset);
466 proto_tree_add_uint_format(subtree, hf_resp_uptime, tvb, offset, 4, r_uptime,
467 "sysUptime: %s", time_msecs_to_str(r_uptime));
468 proto_tree_add_item(subtree, hf_resp_error, tvb, offset + 4, 2, little_endian);
469 proto_tree_add_item(subtree, hf_resp_index, tvb, offset + 6, 2, little_endian);
472 while(len > offset) {
473 offset += dissect_varbind(tvb, subtree, offset, len, flags);
477 static void dissect_getnext_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
482 item = proto_tree_add_text(tree, tvb, offset, len, "GetNext-PDU");
483 subtree = proto_item_add_subtree(item, ett_getnext);
485 if(flags & NON_DEFAULT_CONTEXT) {
487 offset += dissect_octet_string(tvb, subtree, offset, flags);
490 while(len > offset) {
491 offset += dissect_search_range(tvb, subtree, offset, flags);
495 static void dissect_get_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
500 item = proto_tree_add_text(tree, tvb, offset, len, "Get-PDU");
501 subtree = proto_item_add_subtree(item, ett_get);
503 if(flags & NON_DEFAULT_CONTEXT) {
505 offset += dissect_octet_string(tvb, subtree, offset, flags);
508 while(len >= offset) {
509 offset += dissect_search_range(tvb, subtree, offset, flags);
510 offset += 4; /* skip 0 end dword */
514 static void dissect_getbulk_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
518 gboolean little_endian = !(flags & NETWORK_BYTE_ORDER);
520 item = proto_tree_add_text(tree, tvb, offset, len, "GetBulk-PDU");
521 subtree = proto_item_add_subtree(item, ett_getbulk);
523 if(flags & NON_DEFAULT_CONTEXT) {
525 offset += dissect_octet_string(tvb, subtree, offset, flags);
528 proto_tree_add_item(subtree, hf_gbulk_nrepeat, tvb, offset, 2, little_endian);
529 proto_tree_add_item(subtree, hf_gbulk_mrepeat, tvb, offset + 2, 2, little_endian);
532 while(len >= offset) {
533 offset += dissect_search_range(tvb, subtree, offset, flags);
537 static void dissect_open_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
543 item = proto_tree_add_text(tree, tvb, offset, len, "Open-PDU");
544 subtree = proto_item_add_subtree(item, ett_open);
546 timeout = tvb_get_guint8(tvb, offset);
547 tvb_get_ntoh24(tvb, offset + 1);
549 proto_tree_add_uint(subtree, hf_open_timeout, tvb, offset, 1, timeout);
553 offset += dissect_object_id(tvb, subtree, offset, flags);
556 offset += dissect_octet_string(tvb, subtree, offset, flags);
559 static void dissect_close_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len)
565 item = proto_tree_add_text(tree, tvb, offset, len, "Close-PDU");
566 subtree = proto_item_add_subtree(item, ett_close);
568 reason = tvb_get_guint8(tvb, offset);
569 tvb_get_ntoh24(tvb, offset + 1);
571 proto_tree_add_uint(subtree, hf_close_reason, tvb, offset, 1, reason);
576 static void dissect_register_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
581 gboolean little_endian = !(flags & NETWORK_BYTE_ORDER);
583 item = proto_tree_add_text(tree, tvb, offset, len, "Register-PDU");
584 subtree = proto_item_add_subtree(item, ett_register);
586 if(flags & NON_DEFAULT_CONTEXT) {
588 offset += dissect_octet_string(tvb, subtree, offset, flags);
591 proto_tree_add_item(subtree, hf_reg_timeout, tvb, offset, 1, FALSE);
592 proto_tree_add_item(subtree, hf_reg_prio, tvb, offset+1, 1, FALSE);
593 proto_tree_add_item(subtree, hf_reg_rsid, tvb, offset+2, 1, FALSE);
598 offset += dissect_object_id(tvb, subtree, offset, flags);
601 /* Upper bound (opt) */
602 proto_tree_add_item(subtree, hf_reg_ubound, tvb, offset, 4, little_endian);
608 static void dissect_unregister_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
612 gboolean little_endian = !(flags & NETWORK_BYTE_ORDER);
614 item = proto_tree_add_text(tree, tvb, offset, len, "Unregister-PDU");
615 subtree = proto_item_add_subtree(item, ett_unregister);
617 if(flags & NON_DEFAULT_CONTEXT) {
619 offset += dissect_octet_string(tvb, subtree, offset, flags);
622 proto_tree_add_item(subtree, hf_unreg_timeout, tvb, offset, 1, FALSE);
623 proto_tree_add_item(subtree, hf_unreg_prio, tvb, offset+1, 1, FALSE);
624 proto_tree_add_item(subtree, hf_unreg_rsid, tvb, offset+2, 1, FALSE);
628 offset += dissect_object_id(tvb, subtree, offset, flags);
631 /* Upper bound (opt) */
632 proto_tree_add_item(subtree, hf_unreg_ubound, tvb, offset, 4, little_endian);
637 static void dissect_testset_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
642 item = proto_tree_add_text(tree, tvb, offset, len, "Testset-PDU");
643 subtree = proto_item_add_subtree(item, ett_testset);
645 if(flags & NON_DEFAULT_CONTEXT) {
647 offset += dissect_octet_string(tvb, subtree, offset, flags);
650 while(len > offset) {
651 offset += dissect_varbind(tvb, subtree, offset, len, flags);
655 static void dissect_notify_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
660 item = proto_tree_add_text(tree, tvb, offset, len, "Notify-PDU");
661 subtree = proto_item_add_subtree(item, ett_notify);
663 if(flags & NON_DEFAULT_CONTEXT) {
665 offset += dissect_octet_string(tvb, subtree, offset, flags);
668 while(len > offset) {
669 offset += dissect_varbind(tvb, subtree, offset, len, flags);
673 static void dissect_ping_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
678 item = proto_tree_add_text(tree, tvb, offset, len, "Ping-PDU");
679 subtree = proto_item_add_subtree(item, ett_ping);
681 if(flags & NON_DEFAULT_CONTEXT) {
683 offset += dissect_octet_string(tvb, subtree, offset, flags);
687 static void dissect_idx_alloc_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
692 item = proto_tree_add_text(tree, tvb, offset, len, "IndexAllocate-PDU");
693 subtree = proto_item_add_subtree(item, ett_idxalloc);
695 if(flags & NON_DEFAULT_CONTEXT) {
697 offset += dissect_octet_string(tvb, subtree, offset, flags);
700 while(len > offset) {
701 offset += dissect_varbind(tvb, subtree, offset, len, flags);
706 static void dissect_idx_dealloc_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
711 item = proto_tree_add_text(tree, tvb, offset, len, "IndexDeallocate-PDU");
712 subtree = proto_item_add_subtree(item, ett_idxdalloc);
714 if(flags & NON_DEFAULT_CONTEXT) {
716 offset += dissect_octet_string(tvb, subtree, offset, flags);
719 while(len > offset) {
720 offset += dissect_varbind(tvb, subtree, offset, len, flags);
724 static void dissect_add_caps_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
729 item = proto_tree_add_text(tree, tvb, offset, len, "AddAgentCaps-PDU");
730 subtree = proto_item_add_subtree(item, ett_addcap);
732 if(flags & NON_DEFAULT_CONTEXT) {
734 offset += dissect_octet_string(tvb, subtree, offset, flags);
737 offset += dissect_object_id(tvb, subtree, offset, flags);
739 offset += dissect_octet_string(tvb, subtree, offset, flags);
742 static void dissect_rem_caps_pdu(tvbuff_t *tvb, proto_tree *tree,int offset,int len, char flags)
747 item = proto_tree_add_text(tree, tvb, offset, len, "RemoveAgentCaps-PDU");
748 subtree = proto_item_add_subtree(item, ett_remcap);
750 if(flags & NON_DEFAULT_CONTEXT) {
752 offset += dissect_octet_string(tvb, subtree, offset, flags);
755 offset += dissect_object_id(tvb, subtree, offset, flags);
759 static guint get_agentx_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
765 * Get the payload length.
767 flags = tvb_get_guint8(tvb, offset + 2);
768 NORLEL(flags, plen, tvb, offset + 16);
771 * Arbitrarily limit it to 2^24, so we don't have to worry about
778 * That length doesn't include the header; add that in.
783 static void dissect_agentx_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
786 proto_tree* agentx_tree ,*pdu_hdr_tree;
787 proto_item* pdu_item , *t_item;
796 version = tvb_get_guint8(tvb,0); offset+=1;
797 type = tvb_get_guint8(tvb,1); offset+=1;
798 flags = tvb_get_guint8(tvb,2); offset+=1;
799 /* skip reserved byte */
802 NORLEL(flags, session_id, tvb, 4); offset+=4;
803 NORLEL(flags, trans_id, tvb, 8); offset+=4;
804 NORLEL(flags, packet_id, tvb, 12); offset+=4;
805 NORLEL(flags, payload_len, tvb, 16); offset+=4;
807 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AgentX");
809 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: sid=%d, tid=%d, packid=%d, plen=%d",
810 val_to_str(type,type_values,"unknown"),
811 session_id,trans_id,packet_id,payload_len);
817 /*t_item = proto_tree_add_item(tree, proto_agentx, tvb, 0, -1, FALSE);*/
818 t_item = proto_tree_add_protocol_format(tree, proto_agentx, tvb, 0, -1,
819 "Agent Extensibility (AgentX) Protocol: %s, sid=%d, tid=%d, packid=%d, plen=%d",
820 val_to_str(type,type_values,"unknown"),
821 session_id,trans_id,packet_id,payload_len);
822 agentx_tree = proto_item_add_subtree(t_item, ett_agentx);
824 pdu_item = proto_tree_add_text(agentx_tree, tvb, 0, 5, "PDU Header: Type[%u], len=%d, sid=%d, tid=%d, packid=%d",
825 (char)type,payload_len,session_id,trans_id,packet_id);
827 pdu_hdr_tree = proto_item_add_subtree(pdu_item, ett_pdu_hdr);
829 proto_tree_add_uint(pdu_hdr_tree,hf_version,tvb,0,1,version);
830 proto_tree_add_uint(pdu_hdr_tree,hf_type,tvb,1,1,type);
831 proto_tree_add_uint(pdu_hdr_tree,hf_flags,tvb,2,1,flags);
832 proto_tree_add_uint(pdu_hdr_tree,hf_session_id,tvb,4,4,session_id);
833 proto_tree_add_uint(pdu_hdr_tree,hf_trans_id,tvb,8,4,trans_id);
834 proto_tree_add_uint(pdu_hdr_tree,hf_packet_id,tvb,12,4,packet_id);
835 proto_tree_add_uint(pdu_hdr_tree,hf_payload_len,tvb,16,4,payload_len);
838 case AGENTX_OPEN_PDU:
839 dissect_open_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
842 case AGENTX_CLOSE_PDU:
843 dissect_close_pdu(tvb, pdu_hdr_tree, offset,payload_len);
846 case AGENTX_REGISTER_PDU:
847 dissect_register_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
850 case AGENTX_UNREGISTER_PDU:
851 dissect_unregister_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
855 dissect_get_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
858 case AGENTX_GETNEXT_PDU:
859 dissect_getnext_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
862 case AGENTX_GETBULK_PDU:
863 dissect_getbulk_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
866 case AGENTX_TESTSET_PDU:
867 dissect_testset_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
870 case AGENTX_COMMITSET_PDU:
871 case AGENTX_UNDOSET_PDU:
872 case AGENTX_CLEANUPSET_PDU:
873 /* there is no parameters */
876 case AGENTX_NOTIFY_PDU:
877 dissect_notify_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
880 case AGENTX_PING_PDU:
881 dissect_ping_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
884 case AGENTX_INDEX_ALLOC_PDU:
885 dissect_idx_alloc_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
888 case AGENTX_INDEX_DEALLOC_PDU:
889 dissect_idx_dealloc_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
892 case AGENTX_ADD_AGENT_CAPS_PDU:
893 dissect_add_caps_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
896 case AGENTX_REM_AGENT_CAPS_PDU:
897 dissect_rem_caps_pdu(tvb, pdu_hdr_tree, offset,payload_len,flags);
900 case AGENTX_RESPONSE_PDU:
901 dissect_response_pdu(tvb, pdu_hdr_tree, offset, payload_len, flags);
906 static void dissect_agentx(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
908 tcp_dissect_pdus(tvb, pinfo, tree, TRUE, 20, get_agentx_pdu_len,
913 proto_register_agentx(void)
915 static hf_register_info hf[] = {
918 { "Version", "agentx.version", FT_UINT8, BASE_DEC, NULL, 0x0,
919 "header version", HFILL }},
922 { "Type", "agentx.type", FT_UINT8, BASE_DEC, VALS(type_values), 0x0,
923 "header type", HFILL }},
926 { "Flags", "agentx.flags", FT_UINT8, BASE_DEC, NULL, 0x0,
927 "header type", HFILL }},
930 { "sessionID", "agentx.session_id", FT_UINT32, BASE_DEC, NULL, 0x0,
931 "Session ID", HFILL }},
934 { "TransactionID", "agentx.transaction_id", FT_UINT32, BASE_DEC, NULL, 0x0,
935 "Transaction ID", HFILL }},
938 { "PacketID", "agentx.packet_id", FT_UINT32, BASE_DEC, NULL, 0x0,
939 "Packet ID", HFILL }},
942 { "Payload length", "agentx.payload_len", FT_UINT32, BASE_DEC, NULL, 0x0,
946 { "Octet String", "agentx.ostring", FT_STRING, BASE_NONE, NULL, 0x0,
950 { "OString len", "agentx.ostring_len", FT_UINT32, BASE_DEC, NULL, 0x0,
951 "Octet String Length", HFILL }},
954 { "Number subids", "agentx.n_subid", FT_UINT8, BASE_DEC, NULL, 0x0,
958 { "OID prefix", "agentx.oid_prefix", FT_UINT8, BASE_DEC, NULL, 0x0,
962 { "OID include", "agentx.oid_include", FT_UINT8, BASE_DEC, NULL, 0x0,
966 { "OID", "agentx.oid", FT_STRING, BASE_NONE, NULL, 0x0,
970 { "sysUpTime", "agentx.r.uptime", FT_UINT32, BASE_DEC, NULL, 0x0,
974 { "Resp. error", "agentx.r.error", FT_UINT16, BASE_DEC, VALS(resp_errors), 0x0,
975 "response error", HFILL }},
978 { "Resp. index", "agentx.r.index", FT_UINT16, BASE_DEC, NULL, 0x0,
979 "response index", HFILL }},
982 { "Variable type", "agentx.v.tag", FT_UINT16, BASE_DEC, VALS(vtag_values), 0x0,
986 { "Value(32)", "agentx.v.val32", FT_UINT32, BASE_DEC, NULL, 0x0,
990 { "Value(64)", "agentx.v.val64", FT_UINT64, BASE_DEC, NULL, 0x0,
994 { "Timeout", "agentx.o.timeout", FT_UINT8, BASE_DEC, NULL, 0x0,
995 "open timeout", HFILL }},
998 { "Reason", "agentx.c.reason", FT_UINT8, BASE_DEC, VALS(close_reasons), 0x0,
999 "close reason", HFILL }},
1002 { "Timeout", "agentx.r.timeout", FT_UINT8, BASE_DEC, NULL, 0x0,
1003 "Register timeout", HFILL }},
1006 { "Priority", "agentx.r.priority", FT_UINT8, BASE_DEC, NULL, 0x0,
1007 "Register Priority", HFILL }},
1010 { "Range_subid", "agentx.r.range_subid", FT_UINT8, BASE_DEC, NULL, 0x0,
1011 "Register range_subid", HFILL }},
1014 { "Upper bound", "agentx.r.upper_bound", FT_UINT32, BASE_DEC, NULL, 0x0,
1015 "Register upper bound", HFILL }},
1017 { &hf_unreg_timeout,
1018 { "Timeout", "agentx.u.timeout", FT_UINT8, BASE_DEC, NULL, 0x0,
1019 "Unregister timeout", HFILL }},
1022 { "Priority", "agentx.u.priority", FT_UINT8, BASE_DEC, NULL, 0x0,
1023 "Unregister Priority", HFILL }},
1026 { "Range_subid", "agentx.u.range_subid", FT_UINT8, BASE_DEC, NULL, 0x0,
1027 "Unregister range_subid", HFILL }},
1030 { "Upper bound", "agentx.u.upper_bound", FT_UINT32, BASE_DEC, NULL, 0x0,
1031 "Register upper bound", HFILL }},
1033 { &hf_gbulk_nrepeat,
1034 { "Repeaters", "agentx.gb.nrepeat", FT_UINT16, BASE_DEC, NULL, 0x0,
1035 "getBulk Num. repeaters", HFILL }},
1037 { &hf_gbulk_mrepeat,
1038 { "Max Repetition", "agentx.gb.mrepeat", FT_UINT16, BASE_DEC, NULL, 0x0,
1039 "getBulk Max repetition", HFILL }},
1042 /* Add more fields here */
1046 static gint *ett[] = {
1073 module_t *agentx_module;
1075 proto_agentx = proto_register_protocol("AgentX",
1076 "AgentX", "agentx");
1078 proto_register_field_array(proto_agentx, hf, array_length(hf));
1079 proto_register_subtree_array(ett, array_length(ett));
1081 agentx_module = prefs_register_protocol(proto_agentx, proto_reg_handoff_agentx);
1083 prefs_register_uint_preference(agentx_module, "tcp.agentx_port",
1084 "AgentX listener TCP Port",
1085 "Set the TCP port for AgentX"
1086 "(if other than the default of 705)",
1087 10, &global_agentx_tcp_port);
1090 /* The registration hand-off routine */
1092 proto_reg_handoff_agentx(void)
1094 static gboolean agentx_prefs_initialized = FALSE;
1095 static dissector_handle_t agentx_handle;
1096 static guint agentx_tcp_port;
1098 if(!agentx_prefs_initialized) {
1099 agentx_handle = create_dissector_handle(dissect_agentx, proto_agentx);
1100 agentx_prefs_initialized = TRUE;
1103 dissector_delete("tcp.port", agentx_tcp_port, agentx_handle);
1106 agentx_tcp_port = global_agentx_tcp_port;
1107 dissector_add("tcp.port", agentx_tcp_port, agentx_handle);