2 * Routines for the COPS (Common Open Policy Service) protocol dissection
3 * RFC2748 & COPS-PR extension RFC3084
5 * Copyright 2000, Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-cops.c,v 1.32 2002/08/28 21:00:08 jmayer Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 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 "packet-ipv6.h"
40 #include "packet-tcp.h"
43 #include "format-oid.h"
46 #define TCP_PORT_COPS 3288
48 /* Variable to hold the tcp port preference */
49 static guint global_cops_tcp_port = TCP_PORT_COPS;
51 /* desegmentation of COPS */
52 static gboolean cops_desegment = TRUE;
54 /* Variable to allow for proper deletion of dissector registration
55 * when the user changes port from the gui
58 static guint cops_tcp_port = 0;
60 static gchar *last_decoded_prid=NULL;
62 #define COPS_OBJECT_HDR_SIZE 4
64 /* Null string of type "guchar[]". */
65 static const guchar nullstring[] = "";
67 #define SAFE_STRING(s) (((s) != NULL) ? (s) : nullstring)
71 #define COPS_IPA 0 /* IP Address */
72 #define COPS_U32 2 /* Unsigned 32*/
73 #define COPS_TIT 3 /* TimeTicks */
74 #define COPS_OPQ 4 /* Opaque */
75 #define COPS_I64 10 /* Integer64 */
76 #define COPS_U64 11 /* Uinteger64 */
81 #define COPS_INTEGER 1 /* l */
82 #define COPS_OCTETSTR 2 /* c */
83 #define COPS_OBJECTID 3 /* ul */
84 #define COPS_IPADDR 4 /* uc */
85 #define COPS_UNSIGNED32 5 /* ul */
86 #define COPS_TIMETICKS 7 /* ul */
87 #define COPS_OPAQUE 8 /* c */
88 #define COPS_INTEGER64 10 /* ll */
89 #define COPS_UNSIGNED64 11 /* ull */
92 typedef struct _COPS_CNV COPS_CNV;
102 static COPS_CNV CopsCnv [] =
104 {ASN1_UNI, ASN1_NUL, COPS_NULL, "NULL"},
105 {ASN1_UNI, ASN1_INT, COPS_INTEGER, "INTEGER"},
106 {ASN1_UNI, ASN1_OTS, COPS_OCTETSTR, "OCTET STRING"},
107 {ASN1_UNI, ASN1_OJI, COPS_OBJECTID, "OBJECTID"},
108 {ASN1_APL, COPS_IPA, COPS_IPADDR, "IPADDR"},
109 {ASN1_APL, COPS_U32, COPS_UNSIGNED32,"UNSIGNED32"},
110 {ASN1_APL, COPS_TIT, COPS_TIMETICKS, "TIMETICKS"},
111 {ASN1_APL, COPS_OPQ, COPS_OPAQUE, "OPAQUE"},
112 {ASN1_APL, COPS_I64, COPS_INTEGER64, "INTEGER64"},
113 {ASN1_APL, COPS_U64, COPS_UNSIGNED64, "UNSIGNED64"},
118 cops_tag_cls2syntax ( guint tag, guint cls, gushort *syntax)
123 while (cnv->syntax != -1)
125 if (cnv->tag == tag && cnv->class == cls)
127 *syntax = cnv->syntax;
135 static const value_string cops_flags_vals[] = {
137 { 0x01, "Solicited Message Flag Bit" },
141 /* The different COPS message types */
143 COPS_NO_MSG, /* Not a COPS Message type */
145 COPS_MSG_REQ, /* Request (REQ) */
146 COPS_MSG_DEC, /* Decision (DEC) */
147 COPS_MSG_RPT, /* Report State (RPT) */
148 COPS_MSG_DRQ, /* Delete Request State (DRQ) */
149 COPS_MSG_SSQ, /* Synchronize State Req (SSQ) */
150 COPS_MSG_OPN, /* Client-Open (OPN) */
151 COPS_MSG_CAT, /* Client-Accept (CAT) */
152 COPS_MSG_CC, /* Client-Close (CC) */
153 COPS_MSG_KA, /* Keep-Alive (KA) */
154 COPS_MSG_SSC, /* Synchronize Complete (SSC) */
156 COPS_LAST_OP_CODE /* For error checking */
159 static const value_string cops_op_code_vals[] = {
160 { COPS_MSG_REQ, "Request (REQ)" },
161 { COPS_MSG_DEC, "Decision (DEC)" },
162 { COPS_MSG_RPT, "Report State (RPT)" },
163 { COPS_MSG_DRQ, "Delete Request State (DRQ)" },
164 { COPS_MSG_SSQ, "Synchronize State Req (SSQ)" },
165 { COPS_MSG_OPN, "Client-Open (OPN)" },
166 { COPS_MSG_CAT, "Client-Accept (CAT)" },
167 { COPS_MSG_CC, "Client-Close (CC)" },
168 { COPS_MSG_KA, "Keep-Alive (KA)" },
169 { COPS_MSG_SSC, "Synchronize Complete (SSC)" },
174 /* The different objects in COPS messages */
176 COPS_NO_OBJECT, /* Not a COPS Object type */
178 COPS_OBJ_HANDLE, /* Handle Object (Handle) */
179 COPS_OBJ_CONTEXT, /* Context Object (Context) */
180 COPS_OBJ_IN_INT, /* In-Interface Object (IN-Int) */
181 COPS_OBJ_OUT_INT, /* Out-Interface Object (OUT-Int) */
182 COPS_OBJ_REASON, /* Reason Object (Reason) */
183 COPS_OBJ_DECISION, /* Decision Object (Decision) */
184 COPS_OBJ_LPDPDECISION, /* LPDP Decision Object (LPDPDecision) */
185 COPS_OBJ_ERROR, /* Error Object (Error) */
186 COPS_OBJ_CLIENTSI, /* Client Specific Information Object (ClientSI) */
187 COPS_OBJ_KATIMER, /* Keep-Alive Timer Object (KATimer) */
188 COPS_OBJ_PEPID, /* PEP Identification Object (PEPID) */
189 COPS_OBJ_REPORT_TYPE, /* Report-Type Object (Report-Type) */
190 COPS_OBJ_PDPREDIRADDR, /* PDP Redirect Address Object (PDPRedirAddr) */
191 COPS_OBJ_LASTPDPADDR, /* Last PDP Address (LastPDPaddr) */
192 COPS_OBJ_ACCTTIMER, /* Accounting Timer Object (AcctTimer) */
193 COPS_OBJ_INTEGRITY, /* Message Integrity Object (Integrity) */
194 COPS_LAST_C_NUM /* For error checking */
197 static const value_string cops_c_num_vals[] = {
198 { COPS_OBJ_HANDLE, "Handle Object (Handle)" },
199 { COPS_OBJ_CONTEXT, "Context Object (Context)" },
200 { COPS_OBJ_IN_INT, "In-Interface Object (IN-Int)" },
201 { COPS_OBJ_OUT_INT, "Out-Interface Object (OUT-Int)" },
202 { COPS_OBJ_REASON, "Reason Object (Reason)" },
203 { COPS_OBJ_DECISION, "Decision Object (Decision)" },
204 { COPS_OBJ_LPDPDECISION, "LPDP Decision Object (LPDPDecision)" },
205 { COPS_OBJ_ERROR, "Error Object (Error)" },
206 { COPS_OBJ_CLIENTSI, "Client Specific Information Object (ClientSI)" },
207 { COPS_OBJ_KATIMER, "Keep-Alive Timer Object (KATimer)" },
208 { COPS_OBJ_PEPID, "PEP Identification Object (PEPID)" },
209 { COPS_OBJ_REPORT_TYPE, "Report-Type Object (Report-Type)" },
210 { COPS_OBJ_PDPREDIRADDR, "PDP Redirect Address Object (PDPRedirAddr)" },
211 { COPS_OBJ_LASTPDPADDR, "Last PDP Address (LastPDPaddr)" },
212 { COPS_OBJ_ACCTTIMER, "Accounting Timer Object (AcctTimer)" },
213 { COPS_OBJ_INTEGRITY, "Message Integrity Object (Integrity)" },
218 /* The different objects in COPS-PR messages */
220 COPS_NO_PR_OBJECT, /* Not a COPS-PR Object type */
221 COPS_OBJ_PRID, /* Provisioning Instance Identifier (PRID) */
222 COPS_OBJ_PPRID, /* Prefix Provisioning Instance Identifier (PPRID) */
223 COPS_OBJ_EPD, /* Encoded Provisioning Instance Data (EPD) */
224 COPS_OBJ_GPERR, /* Global Provisioning Error Object (GPERR) */
225 COPS_OBJ_CPERR, /* PRC Class Provisioning Error Object (CPERR) */
226 COPS_OBJ_ERRPRID, /* Error Provisioning Instance Identifier (ErrorPRID)*/
228 COPS_LAST_S_NUM /* For error checking */
232 static const value_string cops_s_num_vals[] = {
233 { COPS_OBJ_PRID, "Provisioning Instance Identifier (PRID)" },
234 { COPS_OBJ_PPRID, "Prefix Provisioning Instance Identifier (PPRID)" },
235 { COPS_OBJ_EPD, "Encoded Provisioning Instance Data (EPD)" },
236 { COPS_OBJ_GPERR, "Global Provisioning Error Object (GPERR)" },
237 { COPS_OBJ_CPERR, "PRC Class Provisioning Error Object (CPERR)" },
238 { COPS_OBJ_ERRPRID, "Error Provisioning Instance Identifier (ErrorPRID)" },
243 /* R-Type is carried within the Context Object */
244 static const value_string cops_r_type_vals[] = {
245 { 0x01, "Incoming-Message/Admission Control request" },
246 { 0x02, "Resource-Allocation request" },
247 { 0x04, "Outgoing-Message request" },
248 { 0x08, "Configuration request" },
251 /* S-Type is carried within the ClientSI Object for COPS-PR*/
252 static const value_string cops_s_type_vals[] = {
257 /* Reason-Code is carried within the Reason object */
258 static const value_string cops_reason_vals[] = {
259 { 1, "Unspecified" },
261 { 3, "Preempted (Another request state takes precedence)" },
262 { 4, "Tear (Used to communicate a signaled state removal)" },
263 { 5, "Timeout (Local state has timed-out)" },
264 { 6, "Route Change (Change invalidates request state)" },
265 { 7, "Insufficient Resources (No local resource available)" },
266 { 8, "PDP's Directive (PDP decision caused the delete)" },
267 { 9, "Unsupported decision (PDP decision not supported)" },
268 { 10, "Synchronize Handle Unknown" },
269 { 11, "Transient Handle (stateless event)" },
270 { 12, "Malformed Decision (could not recover)" },
271 { 13, "Unknown COPS Object from PDP" },
275 /* Command-Code is carried within the Decision object if C-Type is 1 */
276 static const value_string cops_dec_cmd_code_vals[] = {
277 { 0, "NULL Decision (No configuration data available)" },
278 { 1, "Install (Admit request/Install configuration)" },
279 { 2, "Remove (Remove request/Remove configuration)" },
283 /* Decision flags are also carried with the Decision object if C-Type is 1 */
284 static const value_string cops_dec_cmd_flag_vals[] = {
285 { 0x00, "<None set>" },
286 { 0x01, "Trigger Error (Trigger error message if set)" },
290 /* Error-Code from Error object */
291 static const value_string cops_error_vals[] = {
293 {2, "Invalid handle reference" },
294 {3, "Bad message format (Malformed Message)" },
295 {4, "Unable to process (server gives up on query)" },
296 {5, "Mandatory client-specific info missing" },
297 {6, "Unsupported client" },
298 {7, "Mandatory COPS object missing" },
299 {8, "Client Failure" },
300 {9, "Communication Failure" },
301 {10, "Unspecified" },
302 {11, "Shutting down" },
303 {12, "Redirect to Preferred Server" },
304 {13, "Unknown COPS Object" },
305 {14, "Authentication Failure" },
306 {15, "Authentication Required" },
309 /* Error-Code from GPERR object */
310 static const value_string cops_gperror_vals[] = {
312 {2, "AvailMemExhausted" },
313 {3, "unknownASN.1Tag" },
314 {4, "maxMsgSizeExceeded" },
315 {5, "unknownError" },
316 {6, "maxRequestStatesOpen" },
317 {7, "invalidASN.1Length" },
318 {8, "invalidObjectPad" },
319 {9, "unknownPIBData" },
320 {10, "unknownCOPSPRObject" },
321 {11, "malformedDecision" },
325 /* Error-Code from CPERR object */
326 static const value_string cops_cperror_vals[] = {
327 {1, "priSpaceExhausted" },
328 {2, "priInstanceInvalid" },
329 {3, "attrValueInvalid" },
330 {4, "attrValueSupLimited" },
331 {5, "attrEnumSupLimited" },
332 {6, "attrMaxLengthExceeded" },
333 {7, "attrReferenceUnknown" },
334 {8, "priNotifyOnly" },
336 {10, "tooFewAttrs" },
337 {11, "invalidAttrType" },
338 {12, "deletedInRef" },
339 {13, "priSpecificError" },
344 /* Report-Type from Report-Type object */
345 static const value_string cops_report_type_vals[] = {
346 {1, " Success : Decision was successful at the PEP" },
347 {2, " Failure : Decision could not be completed by PEP" },
348 {3, " Accounting: Accounting update for an installed state" },
352 /* Initialize the protocol and registered fields */
353 static gint proto_cops = -1;
354 static gint hf_cops_ver_flags = -1;
355 static gint hf_cops_version = -1;
356 static gint hf_cops_flags = -1;
358 static gint hf_cops_op_code = -1;
359 static gint hf_cops_client_type = -1;
360 static gint hf_cops_msg_len = -1;
362 static gint hf_cops_obj_len = -1;
363 static gint hf_cops_obj_c_num = -1;
364 static gint hf_cops_obj_c_type = -1;
366 static gint hf_cops_obj_s_num = -1;
367 static gint hf_cops_obj_s_type = -1;
369 static gint hf_cops_r_type_flags = -1;
370 static gint hf_cops_m_type_flags = -1;
372 static gint hf_cops_in_int_ipv4 = -1;
373 static gint hf_cops_in_int_ipv6 = -1;
374 static gint hf_cops_out_int_ipv4 = -1;
375 static gint hf_cops_out_int_ipv6 = -1;
376 static gint hf_cops_int_ifindex = -1;
378 static gint hf_cops_reason = -1;
379 static gint hf_cops_reason_sub = -1;
381 static gint hf_cops_dec_cmd_code = -1;
382 static gint hf_cops_dec_flags = -1;
384 static gint hf_cops_error = -1;
385 static gint hf_cops_error_sub = -1;
387 static gint hf_cops_gperror = -1;
388 static gint hf_cops_gperror_sub = -1;
390 static gint hf_cops_cperror = -1;
391 static gint hf_cops_cperror_sub = -1;
393 static gint hf_cops_katimer = -1;
395 static gint hf_cops_pepid = -1;
397 static gint hf_cops_report_type = -1;
399 static gint hf_cops_pdprediraddr_ipv4 = -1;
400 static gint hf_cops_pdprediraddr_ipv6 = -1;
401 static gint hf_cops_lastpdpaddr_ipv4 = -1;
402 static gint hf_cops_lastpdpaddr_ipv6 = -1;
403 static gint hf_cops_pdp_tcp_port = -1;
405 static gint hf_cops_accttimer = -1;
407 static gint hf_cops_key_id = -1;
408 static gint hf_cops_seq_num = -1;
410 /* Initialize the subtree pointers */
411 static gint ett_cops = -1;
412 static gint ett_cops_ver_flags = -1;
413 static gint ett_cops_obj = -1;
414 static gint ett_cops_pr_obj = -1;
415 static gint ett_cops_obj_data = -1;
416 static gint ett_cops_r_type_flags = -1;
417 static gint ett_cops_itf = -1;
418 static gint ett_cops_reason = -1;
419 static gint ett_cops_decision = -1;
420 static gint ett_cops_error = -1;
421 static gint ett_cops_clientsi = -1;
422 static gint ett_cops_asn1 = -1;
423 static gint ett_cops_gperror = -1;
424 static gint ett_cops_cperror = -1;
425 static gint ett_cops_pdp = -1;
427 void proto_reg_handoff_cops(void);
429 static guint get_cops_pdu_len(tvbuff_t *tvb, int offset);
430 static void dissect_cops_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
432 static int dissect_cops_object(tvbuff_t *tvb, guint32 offset, proto_tree *tree);
433 static int dissect_cops_object_data(tvbuff_t *tvb, guint32 offset, proto_tree *tree,
434 guint8 c_num, guint8 c_type, guint16 len);
436 static int dissect_cops_pr_objects(tvbuff_t *tvb, guint32 offset, proto_tree *tree, guint16 pr_len);
437 static int dissect_cops_pr_object_data(tvbuff_t *tvb, guint32 offset, proto_tree *tree,
438 guint8 s_num, guint8 s_type, guint16 len);
440 /* Code to actually dissect the packets */
442 dissect_cops(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
444 tcp_dissect_pdus(tvb, pinfo, tree, cops_desegment, 8,
445 get_cops_pdu_len, dissect_cops_pdu);
449 get_cops_pdu_len(tvbuff_t *tvb, int offset)
452 * Get the length of the COPS message.
454 return tvb_get_ntohl(tvb, offset + 4);
458 dissect_cops_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
462 if (check_col(pinfo->cinfo, COL_PROTOCOL))
463 col_set_str(pinfo->cinfo, COL_PROTOCOL, "COPS");
464 if (check_col(pinfo->cinfo, COL_INFO))
465 col_clear(pinfo->cinfo, COL_INFO);
467 op_code = tvb_get_guint8(tvb, 1);
468 if (check_col(pinfo->cinfo, COL_INFO))
469 col_add_fstr(pinfo->cinfo, COL_INFO, "COPS %s",
470 val_to_str(op_code, cops_op_code_vals, "Unknown Op Code"));
474 proto_tree *cops_tree, *ver_flags_tree;
480 ti = proto_tree_add_item(tree, proto_cops, tvb, offset, -1, FALSE);
481 cops_tree = proto_item_add_subtree(ti, ett_cops);
483 /* Version and flags share the same byte, put them in a subtree */
484 ver_flags = tvb_get_guint8(tvb, offset);
485 tv = proto_tree_add_uint_format(cops_tree, hf_cops_ver_flags, tvb, offset, 1,
486 ver_flags, "Version: %u, Flags: %s",
487 hi_nibble(ver_flags),
488 val_to_str(lo_nibble(ver_flags), cops_flags_vals, "Unknown"));
489 ver_flags_tree = proto_item_add_subtree(tv, ett_cops_ver_flags);
490 proto_tree_add_uint(ver_flags_tree, hf_cops_version, tvb, offset, 1, ver_flags);
491 proto_tree_add_uint(ver_flags_tree, hf_cops_flags, tvb, offset, 1, ver_flags);
494 proto_tree_add_uint(cops_tree, hf_cops_op_code, tvb, offset, 1, tvb_get_guint8(tvb, offset));
496 proto_tree_add_uint(cops_tree, hf_cops_client_type, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
499 msg_len = tvb_get_ntohl(tvb, offset);
500 proto_tree_add_uint(cops_tree, hf_cops_msg_len, tvb, offset, 4, tvb_get_ntohl(tvb, offset));
503 while (tvb_reported_length_remaining(tvb, offset) >= COPS_OBJECT_HDR_SIZE)
504 offset += dissect_cops_object(tvb, offset, cops_tree);
506 garbage = tvb_length_remaining(tvb, offset);
508 proto_tree_add_text(cops_tree, tvb, offset, garbage,
509 "Trailing garbage: %d byte%s", garbage,
510 plurality(garbage, "", "s"));
516 static char *cops_c_type_to_str(guint8 c_num, guint8 c_type)
519 case COPS_OBJ_HANDLE:
521 return "Client Handle";
523 case COPS_OBJ_IN_INT:
524 case COPS_OBJ_OUT_INT:
526 return "IPv4 Address + Interface";
527 else if (c_type == 2)
528 return "IPv6 Address + Interface";
530 case COPS_OBJ_DECISION:
531 case COPS_OBJ_LPDPDECISION:
533 return "Decision Flags (Mandatory)";
534 else if (c_type == 2)
535 return "Stateless Data";
536 else if (c_type == 3)
537 return "Replacement Data";
538 else if (c_type == 4)
539 return "Client Specific Decision Data";
540 else if (c_type == 5)
541 return "Named Decision Data";
543 case COPS_OBJ_CLIENTSI:
545 return "Signaled ClientSI";
546 else if (c_type == 2)
547 return "Named ClientSI";
549 case COPS_OBJ_KATIMER:
551 return "Keep-alive timer value";
553 case COPS_OBJ_PDPREDIRADDR:
554 case COPS_OBJ_LASTPDPADDR:
556 return "IPv4 Address + TCP Port";
557 else if (c_type == 2)
558 return "IPv6 Address + TCP Port";
560 case COPS_OBJ_ACCTTIMER:
562 return "Accounting timer value";
564 case COPS_OBJ_INTEGRITY:
566 return "HMAC digest";
573 static int dissect_cops_object(tvbuff_t *tvb, guint32 offset, proto_tree *tree)
575 guint16 object_len, contents_len;
576 guint8 c_num, c_type;
578 proto_tree *obj_tree;
582 object_len = tvb_get_ntohs(tvb, offset);
583 c_num = tvb_get_guint8(tvb, offset + 2);
584 c_type = tvb_get_guint8(tvb, offset + 3);
586 ti = proto_tree_add_uint_format(tree, hf_cops_obj_c_num, tvb, offset, object_len, c_num,
587 "%s: %s", val_to_str(c_num, cops_c_num_vals, "Unknown"),
588 cops_c_type_to_str(c_num, c_type));
589 obj_tree = proto_item_add_subtree(ti, ett_cops_obj);
591 proto_tree_add_uint(obj_tree, hf_cops_obj_len, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
594 proto_tree_add_uint(obj_tree, hf_cops_obj_c_num, tvb, offset, 1, c_num);
597 type_str = cops_c_type_to_str(c_num, c_type);
598 proto_tree_add_text(obj_tree, tvb, offset, 1, "C-Type: %s%s%u%s",
600 strlen(type_str) ? " (" : "",
602 strlen(type_str) ? ")" : "");
605 contents_len = object_len - COPS_OBJECT_HDR_SIZE;
606 ret = dissect_cops_object_data(tvb, offset, obj_tree, c_num, c_type, contents_len);
607 if (ret < 0) return 0;
609 /* Pad to 32bit boundary */
610 if (object_len % sizeof (guint32))
611 object_len += (sizeof (guint32) - object_len % sizeof (guint32));
616 static int dissect_cops_pr_objects(tvbuff_t *tvb, guint32 offset, proto_tree *tree, guint16 pr_len)
618 guint16 object_len, contents_len;
619 guint8 s_num, s_type;
622 proto_tree *cops_pr_tree, *obj_tree;
625 cops_pr_tree = proto_item_add_subtree(tree, ett_cops_pr_obj);
627 while (pr_len >= COPS_OBJECT_HDR_SIZE) {
628 object_len = tvb_get_ntohs(tvb, offset);
629 s_num = tvb_get_guint8(tvb, offset + 2);
631 ti = proto_tree_add_uint_format(cops_pr_tree, hf_cops_obj_s_num, tvb, offset, object_len, s_num,
632 "%s", val_to_str(s_num, cops_s_num_vals, "Unknown"));
633 obj_tree = proto_item_add_subtree(cops_pr_tree, ett_cops_pr_obj);
635 proto_tree_add_uint(obj_tree, hf_cops_obj_len, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
639 proto_tree_add_uint(obj_tree, hf_cops_obj_s_num, tvb, offset, 1, s_num);
643 s_type = tvb_get_guint8(tvb, offset);
644 type_str = val_to_str(s_type, cops_s_type_vals, "Unknown");
645 proto_tree_add_text(obj_tree, tvb, offset, 1, "S-Type: %s%s%u%s",
647 strlen(type_str) ? " (" : "",
649 strlen(type_str) ? ")" : "");
653 contents_len = object_len - COPS_OBJECT_HDR_SIZE;
654 ret = dissect_cops_pr_object_data(tvb, offset, obj_tree, s_num, s_type, contents_len);
658 /*Pad to 32bit boundary */
659 if (object_len % sizeof (guint32))
660 object_len += (sizeof (guint32) - object_len % sizeof (guint32));
662 pr_len -= object_len - COPS_OBJECT_HDR_SIZE;
663 offset += object_len - COPS_OBJECT_HDR_SIZE;
669 static int dissect_cops_object_data(tvbuff_t *tvb, guint32 offset, proto_tree *tree,
670 guint8 c_num, guint8 c_type, guint16 len)
673 proto_tree *r_type_tree, *itf_tree, *reason_tree, *dec_tree, *error_tree, *clientsi_tree, *pdp_tree;
674 guint16 r_type, m_type, reason, reason_sub, cmd_code, cmd_flags, error, error_sub, tcp_port;
675 guint32 ipv4addr, ifindex;
676 struct e_in6_addr ipv6addr;
679 case COPS_OBJ_CONTEXT:
680 r_type = tvb_get_ntohs(tvb, offset);
681 m_type = tvb_get_ntohs(tvb, offset + 2);
682 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: R-Type: %s, M-Type: %u",
683 val_to_str(r_type, cops_r_type_vals, "Unknown"),
686 r_type_tree = proto_item_add_subtree(ti, ett_cops_r_type_flags);
687 proto_tree_add_uint(r_type_tree, hf_cops_r_type_flags, tvb, offset, 2, r_type);
689 proto_tree_add_uint(r_type_tree, hf_cops_m_type_flags, tvb, offset, 2, m_type);
692 case COPS_OBJ_IN_INT:
693 case COPS_OBJ_OUT_INT:
694 if (c_type == 1) { /* IPv4 */
695 tvb_memcpy(tvb, (guint8 *)&ipv4addr, offset, 4);
696 ifindex = tvb_get_ntohl(tvb, offset + 4);
697 ti = proto_tree_add_text(tree, tvb, offset, 8, "Contents: IPv4 address %s, ifIndex: %u",
698 ip_to_str((guint8 *)&ipv4addr), ifindex);
699 itf_tree = proto_item_add_subtree(ti, ett_cops_itf);
700 proto_tree_add_ipv4(itf_tree,
701 (c_num == COPS_OBJ_IN_INT) ? hf_cops_in_int_ipv4 : hf_cops_out_int_ipv4,
702 tvb, offset, 4, ipv4addr);
704 } else if (c_type == 2) { /* IPv6 */
705 tvb_memcpy(tvb, (guint8 *)&ipv6addr, offset, sizeof ipv6addr);
706 ifindex = tvb_get_ntohl(tvb, offset + sizeof ipv6addr);
707 ti = proto_tree_add_text(tree, tvb, offset, 20, "Contents: IPv6 address %s, ifIndex: %u",
708 ip6_to_str(&ipv6addr), ifindex);
709 itf_tree = proto_item_add_subtree(ti, ett_cops_itf);
710 proto_tree_add_ipv6(itf_tree,
711 (c_num == COPS_OBJ_IN_INT) ? hf_cops_in_int_ipv6 : hf_cops_out_int_ipv6,
712 tvb, offset, 16, (guint8 *)&ipv6addr);
717 proto_tree_add_uint(itf_tree, hf_cops_int_ifindex, tvb, offset, 4, ifindex);
720 case COPS_OBJ_REASON:
721 reason = tvb_get_ntohs(tvb, offset);
722 reason_sub = tvb_get_ntohs(tvb, offset + 2);
723 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: Reason-Code: %s, Reason Sub-code: 0x%04x",
724 val_to_str(reason, cops_reason_vals, "<Unknown value>"), reason_sub);
725 reason_tree = proto_item_add_subtree(ti, ett_cops_reason);
726 proto_tree_add_uint(reason_tree, hf_cops_reason, tvb, offset, 2, reason);
729 proto_tree_add_text(reason_tree, tvb, offset, 2, "Reason Sub-code: "
730 "Unknown object's C-Num %u, C-Type %u",
731 tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset + 1));
733 proto_tree_add_uint(reason_tree, hf_cops_reason_sub, tvb, offset, 2, reason_sub);
736 case COPS_OBJ_DECISION:
737 case COPS_OBJ_LPDPDECISION:
739 cmd_code = tvb_get_ntohs(tvb, offset);
740 cmd_flags = tvb_get_ntohs(tvb, offset + 2);
741 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: Command-Code: %s, Flags: %s",
742 val_to_str(cmd_code, cops_dec_cmd_code_vals, "<Unknown value>"),
743 val_to_str(cmd_flags, cops_dec_cmd_flag_vals, "<Unknown flag>"));
744 dec_tree = proto_item_add_subtree(ti, ett_cops_decision);
745 proto_tree_add_uint(dec_tree, hf_cops_dec_cmd_code, tvb, offset, 2, cmd_code);
747 proto_tree_add_uint(dec_tree, hf_cops_dec_flags, tvb, offset, 2, cmd_flags);
748 } else if (c_type == 5) { /*COPS-PR Data*/
749 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: %u bytes", len);
750 dec_tree = proto_item_add_subtree(ti, ett_cops_decision);
751 dissect_cops_pr_objects(tvb, offset, dec_tree, len);
759 error = tvb_get_ntohs(tvb, offset);
760 error_sub = tvb_get_ntohs(tvb, offset + 2);
761 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: Error-Code: %s, Error Sub-code: 0x%04x",
762 val_to_str(error, cops_error_vals, "<Unknown value>"), error_sub);
763 error_tree = proto_item_add_subtree(ti, ett_cops_error);
764 proto_tree_add_uint(error_tree, hf_cops_error, tvb, offset, 2, error);
767 proto_tree_add_text(error_tree, tvb, offset, 2, "Error Sub-code: "
768 "Unknown object's C-Num %u, C-Type %u",
769 tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset + 1));
771 proto_tree_add_uint(error_tree, hf_cops_error_sub, tvb, offset, 2, error_sub);
774 case COPS_OBJ_CLIENTSI:
776 if (c_type != 2) /*Not COPS-PR data*/
779 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: %u bytes", len);
780 clientsi_tree = proto_item_add_subtree(ti, ett_cops_clientsi);
782 dissect_cops_pr_objects(tvb, offset, clientsi_tree, len);
785 case COPS_OBJ_KATIMER:
789 proto_tree_add_item(tree, hf_cops_katimer, tvb, offset + 2, 2, FALSE);
790 if (tvb_get_ntohs(tvb, offset + 2) == 0)
791 proto_tree_add_text(tree, tvb, offset, 0, "Value of zero implies infinity.");
798 if (tvb_strnlen(tvb, offset, len) == -1)
799 proto_tree_add_text(tree, tvb, offset, len, "<PEP Id is not a NUL terminated ASCII string>");
801 proto_tree_add_item(tree, hf_cops_pepid, tvb, offset,
802 tvb_strnlen(tvb, offset, len) + 1, FALSE);
805 case COPS_OBJ_REPORT_TYPE:
809 proto_tree_add_item(tree, hf_cops_report_type, tvb, offset, 2, FALSE);
812 case COPS_OBJ_PDPREDIRADDR:
813 case COPS_OBJ_LASTPDPADDR:
814 if (c_type == 1) { /* IPv4 */
815 tvb_memcpy(tvb, (guint8 *)&ipv4addr, offset, 4);
816 tcp_port = tvb_get_ntohs(tvb, offset + 4 + 2);
817 ti = proto_tree_add_text(tree, tvb, offset, 8, "Contents: IPv4 address %s, TCP Port Number: %u",
818 ip_to_str((guint8 *)&ipv4addr), tcp_port);
819 pdp_tree = proto_item_add_subtree(ti, ett_cops_pdp);
820 proto_tree_add_ipv4(pdp_tree,
821 (c_num == COPS_OBJ_PDPREDIRADDR) ? hf_cops_pdprediraddr_ipv4 : hf_cops_lastpdpaddr_ipv4,
822 tvb, offset, 4, ipv4addr);
824 } else if (c_type == 2) { /* IPv6 */
825 tvb_memcpy(tvb, (guint8 *)&ipv6addr, offset, sizeof ipv6addr);
826 tcp_port = tvb_get_ntohs(tvb, offset + sizeof ipv6addr + 2);
827 ti = proto_tree_add_text(tree, tvb, offset, 20, "Contents: IPv6 address %s, TCP Port Number: %u",
828 ip6_to_str(&ipv6addr), tcp_port);
829 pdp_tree = proto_item_add_subtree(ti, ett_cops_pdp);
830 proto_tree_add_ipv6(pdp_tree,
831 (c_num == COPS_OBJ_PDPREDIRADDR) ? hf_cops_pdprediraddr_ipv6 : hf_cops_lastpdpaddr_ipv6,
832 tvb, offset, 16, (guint8 *)&ipv6addr);
838 proto_tree_add_uint(pdp_tree, hf_cops_pdp_tcp_port, tvb, offset, 2, tcp_port);
841 case COPS_OBJ_ACCTTIMER:
845 proto_tree_add_item(tree, hf_cops_accttimer, tvb, offset + 2, 2, FALSE);
846 if (tvb_get_ntohs(tvb, offset + 2) == 0)
847 proto_tree_add_text(tree, tvb, offset, 0, "Value of zero means "
848 "there SHOULD be no unsolicited accounting updates.");
851 case COPS_OBJ_INTEGRITY:
853 break; /* Not HMAC digest */
855 proto_tree_add_item(tree, hf_cops_key_id, tvb, offset, 4, FALSE);
856 proto_tree_add_item(tree, hf_cops_seq_num, tvb, offset + 4, 4, FALSE);
857 proto_tree_add_text(tree, tvb, offset + 8 , len - 8, "Contents: Keyed Message Digest");
861 proto_tree_add_text(tree, tvb, offset, len, "Contents: %u bytes", len);
870 /*convert hex to binary string (1010....)*/
871 static gchar* xtobstr(guint8 *hex, guint len) {
873 guint i=0,j=0,k=0, bit=0;
877 binstr = g_malloc(8*sizeof(gchar)*len);
879 for (i=0; i < len; i++) {
880 for ( j=0; j<8; j++ ) { /* for each bit */
881 bit = (mask & hex[i]) ? 1 : 0; /* bit is 1 or 0 */
882 sprintf(&binstr[k++],"%d",bit); /*put it in string */
883 mask >>= 1; /* shift mask right */
891 * XXX - we should perhaps support reading PIBs, as we support reading
892 * MIBs, and use the PIBs we read to understand how to display COPS data
893 * just as we use the MIBs we read to understand how to display SNMP
896 static int decode_cops_pr_asn1_data(tvbuff_t *tvb, guint32 offset,
897 proto_tree *tree, guint epdlen, gboolean inepd)
911 gint32 vb_integer_value;
912 guint32 vb_uinteger_value;
914 guint8 *vb_octet_string;
919 gchar *vb_display_string;
925 while (epdlen > 0) { /*while there is stuff to be decoded*/
926 asn1_open(&asn1, tvb, offset);
928 /* parse the type of the object */
932 ret = asn1_header_decode (&asn1, &cls, &con, &tag, &def,
934 if (ret != ASN1_ERR_NOERROR)
937 return ASN1_ERR_LENGTH_NOT_DEFINITE;
939 /* Convert the class, constructed flag, and tag to a type. */
940 vb_type_name = cops_tag_cls2syntax(tag, cls, &vb_type);
941 if (vb_type_name == NULL) {
944 * Dissect the value as an opaque string of octets.
946 vb_type_name = "unsupported type";
947 vb_type = COPS_OPAQUE;
950 /* parse the value */
955 ret = asn1_int32_value_decode(&asn1, vb_length,
957 if (ret != ASN1_ERR_NOERROR)
959 length = asn1.offset - start;
961 proto_tree_add_text(tree, asn1.tvb, offset, length,
962 "Value: %s: %d (%#x)", vb_type_name,
963 vb_integer_value, vb_integer_value);
967 case COPS_UNSIGNED32:
969 ret = asn1_uint32_value_decode(&asn1, vb_length,
971 if (ret != ASN1_ERR_NOERROR)
973 length = asn1.offset - start;
975 proto_tree_add_text(tree, asn1.tvb, offset, length,
976 "Value: %s: %u (%#x)", vb_type_name,
977 vb_uinteger_value, vb_uinteger_value);
984 case COPS_UNSIGNED64:
986 ret = asn1_string_value_decode (&asn1, vb_length,
988 if (ret != ASN1_ERR_NOERROR)
990 length = asn1.offset - start;
992 /* if this EPD belongs to ipFilter or
993 frwkPrcSupport Entries print it correctly) */
994 if ((strncmp(last_decoded_prid,"1.3.6.1.2.2.2.3.2.1",19)==0) || (strncmp(last_decoded_prid,"1.3.6.1.2.2.2.1.1.1",19)==0)) {
995 if(strncmp(last_decoded_prid,"1.3.6.1.2.2.2.3.2.1",19)==0) {
996 i=0;/* EPD belongs to
998 bytes (IPv6 not printed
1002 frwkPrcSupportEntry,
1003 convert hex byte(s) to
1006 xtobstr(vb_octet_string,
1009 proto_tree_add_text(tree, asn1.tvb,
1011 "Value: %s: %s", vb_type_name,
1014 g_free(vb_octet_string);
1015 g_free(vb_display_string);
1020 /* EPD doesn't belong to ipFilter or
1021 frwkPrcSupport Entries;
1022 check for unprintable characters*/
1024 for (i = 0; i < vb_length; i++) {
1025 if (!(isprint(vb_octet_string[i])
1026 ||isspace(vb_octet_string[i])))
1032 * If some characters are not printable,
1033 * display the string as bytes.
1035 if (i < vb_length) {
1037 * We stopped, due to a non-printable
1038 * character, before we got to the end
1042 g_malloc(4*vb_length);
1043 buf = &vb_display_string[0];
1044 len = sprintf(buf, "%03u",
1045 vb_octet_string[0]);
1047 for (i = 1; i < vb_length; i++) {
1048 len = sprintf(buf, ".%03u",
1049 vb_octet_string[i]);
1052 proto_tree_add_text(tree,
1053 asn1.tvb, offset, length,
1054 "Value: %s: %s", vb_type_name,
1056 g_free(vb_display_string);
1058 proto_tree_add_text(tree,
1059 asn1.tvb, offset, length,
1060 "Value: %s: %.*s", vb_type_name,
1062 SAFE_STRING(vb_octet_string));
1065 g_free(vb_octet_string);
1069 ret = asn1_null_decode (&asn1, vb_length);
1070 if (ret != ASN1_ERR_NOERROR)
1072 length = asn1.offset - start;
1074 proto_tree_add_text(tree, asn1.tvb, offset, length,
1075 "Value: %s", vb_type_name);
1080 ret = asn1_oid_value_decode (&asn1, vb_length, &vb_oid,
1082 if (ret != ASN1_ERR_NOERROR)
1084 length = asn1.offset - start;
1087 vb_display_string = format_oid(vb_oid,
1089 proto_tree_add_text(tree, asn1.tvb, offset, length,
1090 "Value: %s: %s", vb_type_name,
1094 /* we're decoding EPD */
1095 g_free(vb_display_string);
1097 /* we're decoding PRID, so let's store
1098 the OID of the PRID so that later
1099 when we're decoding this PRID's EPD
1100 we can finetune the output. */
1101 if (last_decoded_prid)
1102 g_free(last_decoded_prid);
1103 last_decoded_prid = vb_display_string;
1110 g_assert_not_reached();
1111 return ASN1_ERR_WRONG_TYPE;
1114 asn1_close(&asn1,&offset);
1121 static int dissect_cops_pr_object_data(tvbuff_t *tvb, guint32 offset, proto_tree *tree,
1122 guint8 s_num, guint8 s_type, guint16 len)
1125 proto_tree *asn1_object_tree, *gperror_tree, *cperror_tree;
1126 guint16 gperror=0, gperror_sub=0, cperror=0, cperror_sub=0;
1130 if (s_type != 1) /* Not Provisioning Instance Identifier (PRID) */
1133 ti=proto_tree_add_text(tree, tvb, offset, len, "Contents:");
1134 asn1_object_tree = proto_item_add_subtree(ti, ett_cops_asn1);
1136 decode_cops_pr_asn1_data(tvb, offset, asn1_object_tree, len, FALSE);
1139 case COPS_OBJ_PPRID:
1140 if (s_type != 1) /* Not Prefix Provisioning Instance Identifier (PPRID) */
1143 ti = proto_tree_add_text(tree, tvb, offset, len, "Contents:");
1144 asn1_object_tree = proto_item_add_subtree(ti, ett_cops_asn1);
1146 decode_cops_pr_asn1_data(tvb, offset, asn1_object_tree, len, FALSE);
1150 if (s_type != 1) /* Not Encoded Provisioning Instance Data (EPD) */
1153 ti = proto_tree_add_text(tree, tvb, offset, len, "Contents:");
1154 asn1_object_tree = proto_item_add_subtree(ti, ett_cops_asn1);
1156 decode_cops_pr_asn1_data(tvb, offset, asn1_object_tree, len, TRUE);
1159 case COPS_OBJ_GPERR:
1160 if (s_type != 1) /* Not Global Provisioning Error Object (GPERR) */
1163 gperror = tvb_get_ntohs(tvb, offset);
1164 gperror_sub = tvb_get_ntohs(tvb, offset + 2);
1165 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: Error-Code: %s, Error Sub-code: 0x%04x",
1166 val_to_str(gperror, cops_gperror_vals, "<Unknown value>"), gperror_sub);
1167 gperror_tree = proto_item_add_subtree(ti, ett_cops_gperror);
1168 proto_tree_add_uint(gperror_tree, hf_cops_gperror, tvb, offset, 2, gperror);
1170 if (cperror == 13) {
1171 proto_tree_add_text(gperror_tree, tvb, offset, 2, "Error Sub-code: "
1172 "Unknown object's C-Num %u, C-Type %u",
1173 tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset + 1));
1175 proto_tree_add_uint(gperror_tree, hf_cops_gperror_sub, tvb, offset, 2, gperror_sub);
1178 case COPS_OBJ_CPERR:
1179 if (s_type != 1) /*Not PRC Class Provisioning Error Object (CPERR) */
1184 cperror = tvb_get_ntohs(tvb, offset);
1185 cperror_sub = tvb_get_ntohs(tvb, offset + 2);
1186 ti = proto_tree_add_text(tree, tvb, offset, 4, "Contents: Error-Code: %s, Error Sub-code: 0x%04x",
1187 val_to_str(cperror, cops_cperror_vals, "<Unknown value>"), cperror_sub);
1188 cperror_tree = proto_item_add_subtree(ti, ett_cops_cperror);
1189 proto_tree_add_uint(cperror_tree, hf_cops_cperror, tvb, offset, 2, cperror);
1191 if (cperror == 13) {
1192 proto_tree_add_text(cperror_tree, tvb, offset, 2, "Error Sub-code: "
1193 "Unknown object's S-Num %u, C-Type %u",
1194 tvb_get_guint8(tvb, offset), tvb_get_guint8(tvb, offset + 1));
1196 proto_tree_add_uint(cperror_tree, hf_cops_cperror_sub, tvb, offset, 2, cperror_sub);
1199 case COPS_OBJ_ERRPRID:
1200 if (s_type != 1) /*Not Error Provisioning Instance Identifier (ErrorPRID)*/
1203 ti = proto_tree_add_text(tree, tvb, offset, len, "Contents:");
1204 asn1_object_tree = proto_item_add_subtree(ti, ett_cops_asn1);
1206 decode_cops_pr_asn1_data(tvb, offset, asn1_object_tree, len, FALSE);
1210 proto_tree_add_text(tree, tvb, offset, len, "Contents: %u bytes", len);
1218 /* Register the protocol with Ethereal */
1219 void proto_register_cops(void)
1221 /* Setup list of header fields */
1222 static hf_register_info hf[] = {
1223 { &hf_cops_ver_flags,
1224 { "Version and Flags", "cops.ver_flags",
1225 FT_UINT8, BASE_HEX, NULL, 0x0,
1226 "Version and Flags in COPS Common Header", HFILL }
1229 { "Version", "cops.version",
1230 FT_UINT8, BASE_DEC, NULL, 0xF0,
1231 "Version in COPS Common Header", HFILL }
1234 { "Flags", "cops.flags",
1235 FT_UINT8, BASE_HEX, VALS(cops_flags_vals), 0x0F,
1236 "Flags in COPS Common Header", HFILL }
1239 { "Op Code", "cops.op_code",
1240 FT_UINT8, BASE_DEC, VALS(cops_op_code_vals), 0x0,
1241 "Op Code in COPS Common Header", HFILL }
1243 { &hf_cops_client_type,
1244 { "Client Type", "cops.client_type",
1245 FT_UINT16, BASE_DEC, NULL, 0x0,
1246 "Client Type in COPS Common Header", HFILL }
1249 { "Message Length", "cops.msg_len",
1250 FT_UINT32, BASE_DEC, NULL, 0x0,
1251 "Message Length in COPS Common Header", HFILL }
1254 { "Object Length", "cops.obj.len",
1255 FT_UINT32, BASE_DEC, NULL, 0x0,
1256 "Object Length in COPS Object Header", HFILL }
1258 { &hf_cops_obj_c_num,
1259 { "C-Num", "cops.c_num",
1260 FT_UINT8, BASE_DEC, VALS(cops_c_num_vals), 0x0,
1261 "C-Num in COPS Object Header", HFILL }
1263 { &hf_cops_obj_c_type,
1264 { "C-Type", "cops.c_type",
1265 FT_UINT8, BASE_DEC, NULL, 0x0,
1266 "C-Type in COPS Object Header", HFILL }
1269 { &hf_cops_obj_s_num,
1270 { "S-Num", "cops.s_num",
1271 FT_UINT8, BASE_DEC, VALS(cops_s_num_vals), 0x0,
1272 "S-Num in COPS-PR Object Header", HFILL }
1274 { &hf_cops_obj_s_type,
1275 { "S-Type", "cops.s_type",
1276 FT_UINT8, BASE_DEC, NULL, 0x0,
1277 "S-Type in COPS-PR Object Header", HFILL }
1280 { &hf_cops_r_type_flags,
1281 { "R-Type", "cops.context.r_type",
1282 FT_UINT16, BASE_HEX, VALS(cops_r_type_vals), 0xFFFF,
1283 "R-Type in COPS Context Object", HFILL }
1285 { &hf_cops_m_type_flags,
1286 { "M-Type", "cops.context.m_type",
1287 FT_UINT16, BASE_HEX, NULL, 0xFFFF,
1288 "M-Type in COPS Context Object", HFILL }
1290 { &hf_cops_in_int_ipv4,
1291 { "IPv4 address", "cops.in-int.ipv4",
1292 FT_IPv4, 0, NULL, 0xFFFF,
1293 "IPv4 address in COPS IN-Int object", HFILL }
1295 { &hf_cops_in_int_ipv6,
1296 { "IPv6 address", "cops.in-int.ipv6",
1297 FT_IPv6, 0, NULL, 0xFFFF,
1298 "IPv6 address in COPS IN-Int object", HFILL }
1300 { &hf_cops_out_int_ipv4,
1301 { "IPv4 address", "cops.out-int.ipv4",
1302 FT_IPv4, 0, NULL, 0xFFFF,
1303 "IPv4 address in COPS OUT-Int object", HFILL }
1305 { &hf_cops_out_int_ipv6,
1306 { "IPv6 address", "cops.out-int.ipv6",
1307 FT_IPv6, 0, NULL, 0xFFFF,
1308 "IPv6 address in COPS OUT-Int", HFILL }
1310 { &hf_cops_int_ifindex,
1311 { "ifIndex", "cops.in-out-int.ifindex",
1312 FT_UINT32, BASE_DEC, NULL, 0x0,
1313 "If SNMP is supported, corresponds to MIB-II ifIndex", HFILL }
1316 { "Reason", "cops.reason",
1317 FT_UINT16, BASE_DEC, VALS(cops_reason_vals), 0,
1318 "Reason in Reason object", HFILL }
1320 { &hf_cops_reason_sub,
1321 { "Reason Sub-code", "cops.reason_sub",
1322 FT_UINT16, BASE_HEX, NULL, 0,
1323 "Reason Sub-code in Reason object", HFILL }
1325 { &hf_cops_dec_cmd_code,
1326 { "Command-Code", "cops.decision.cmd",
1327 FT_UINT16, BASE_DEC, VALS(cops_dec_cmd_code_vals), 0,
1328 "Command-Code in Decision/LPDP Decision object", HFILL }
1330 { &hf_cops_dec_flags,
1331 { "Flags", "cops.decision.flags",
1332 FT_UINT16, BASE_HEX, VALS(cops_dec_cmd_flag_vals), 0xffff,
1333 "Flags in Decision/LPDP Decision object", HFILL }
1336 { "Error", "cops.error",
1337 FT_UINT16, BASE_DEC, VALS(cops_error_vals), 0,
1338 "Error in Error object", HFILL }
1340 { &hf_cops_error_sub,
1341 { "Error Sub-code", "cops.error_sub",
1342 FT_UINT16, BASE_HEX, NULL, 0,
1343 "Error Sub-code in Error object", HFILL }
1346 { "Contents: KA Timer Value", "cops.katimer.value",
1347 FT_UINT16, BASE_DEC, NULL, 0,
1348 "Keep-Alive Timer Value in KATimer object", HFILL }
1351 { "Contents: PEP Id", "cops.pepid.id",
1352 FT_STRING, BASE_NONE, NULL, 0,
1353 "PEP Id in PEPID object", HFILL }
1355 { &hf_cops_report_type,
1356 { "Contents: Report-Type", "cops.report_type",
1357 FT_UINT16, BASE_DEC, VALS(cops_report_type_vals), 0,
1358 "Report-Type in Report-Type object", HFILL }
1360 { &hf_cops_pdprediraddr_ipv4,
1361 { "IPv4 address", "cops.pdprediraddr.ipv4",
1362 FT_IPv4, 0, NULL, 0xFFFF,
1363 "IPv4 address in COPS PDPRedirAddr object", HFILL }
1365 { &hf_cops_pdprediraddr_ipv6,
1366 { "IPv6 address", "cops.pdprediraddr.ipv6",
1367 FT_IPv6, 0, NULL, 0xFFFF,
1368 "IPv6 address in COPS PDPRedirAddr object", HFILL }
1370 { &hf_cops_lastpdpaddr_ipv4,
1371 { "IPv4 address", "cops.lastpdpaddr.ipv4",
1372 FT_IPv4, 0, NULL, 0xFFFF,
1373 "IPv4 address in COPS LastPDPAddr object", HFILL }
1375 { &hf_cops_lastpdpaddr_ipv6,
1376 { "IPv6 address", "cops.lastpdpaddr.ipv6",
1377 FT_IPv6, 0, NULL, 0xFFFF,
1378 "IPv6 address in COPS LastPDPAddr object", HFILL }
1380 { &hf_cops_pdp_tcp_port,
1381 { "TCP Port Number", "cops.pdp.tcp_port",
1382 FT_UINT32, BASE_DEC, NULL, 0x0,
1383 "TCP Port Number of PDP in PDPRedirAddr/LastPDPAddr object", HFILL }
1385 { &hf_cops_accttimer,
1386 { "Contents: ACCT Timer Value", "cops.accttimer.value",
1387 FT_UINT16, BASE_DEC, NULL, 0,
1388 "Accounting Timer Value in AcctTimer object", HFILL }
1391 { "Contents: Key ID", "cops.integrity.key_id",
1392 FT_UINT32, BASE_DEC, NULL, 0,
1393 "Key ID in Integrity object", HFILL }
1396 { "Contents: Sequence Number", "cops.integrity.seq_num",
1397 FT_UINT32, BASE_DEC, NULL, 0,
1398 "Sequence Number in Integrity object", HFILL }
1401 { "Error", "cops.gperror",
1402 FT_UINT16, BASE_DEC, VALS(cops_gperror_vals), 0,
1403 "Error in Error object", HFILL }
1405 { &hf_cops_gperror_sub,
1406 { "Error Sub-code", "cops.gperror_sub",
1407 FT_UINT16, BASE_HEX, NULL, 0,
1408 "Error Sub-code in Error object", HFILL }
1411 { "Error", "cops.cperror",
1412 FT_UINT16, BASE_DEC, VALS(cops_cperror_vals), 0,
1413 "Error in Error object", HFILL }
1415 { &hf_cops_cperror_sub,
1416 { "Error Sub-code", "cops.cperror_sub",
1417 FT_UINT16, BASE_HEX, NULL, 0,
1418 "Error Sub-code in Error object", HFILL }
1423 /* Setup protocol subtree array */
1424 static gint *ett[] = {
1426 &ett_cops_ver_flags,
1430 &ett_cops_r_type_flags,
1442 module_t* cops_module;
1444 /* Register the protocol name and description */
1445 proto_cops = proto_register_protocol("Common Open Policy Service",
1448 /* Required function calls to register the header fields and subtrees used */
1449 proto_register_field_array(proto_cops, hf, array_length(hf));
1450 proto_register_subtree_array(ett, array_length(ett));
1452 /* Register our configuration options for cops,
1453 * particularly our ports
1455 cops_module = prefs_register_protocol(proto_cops,
1456 proto_reg_handoff_cops);
1457 prefs_register_uint_preference(cops_module,"tcp.cops_port",
1459 "Set the TCP port for COPS messages",
1460 10,&global_cops_tcp_port);
1461 prefs_register_bool_preference(cops_module, "desegment",
1462 "Desegment all COPS messages spanning multiple TCP segments",
1463 "Whether the COPS dissector should desegment all messages spanning multiple TCP segments",
1468 proto_reg_handoff_cops(void)
1470 static int cops_prefs_initialized = FALSE;
1471 static dissector_handle_t cops_handle;
1473 if (!cops_prefs_initialized) {
1474 cops_handle = create_dissector_handle(dissect_cops, proto_cops);
1475 cops_prefs_initialized = TRUE;
1477 dissector_delete("tcp.port",cops_tcp_port,cops_handle);
1479 /* Set our port numbers for future use */
1480 cops_tcp_port = global_cops_tcp_port;
1482 dissector_add("tcp.port", cops_tcp_port, cops_handle);