GTPv2: fix dissection of APN IE
[metze/wireshark/wip.git] / epan / dissectors / packet-srp.c
index 7054a286014b4b315dae2652d5732292e3d7ca91..f9cdf7d00281f76a98e9907ab41ec6aeb4f3d5df 100644 (file)
@@ -2,38 +2,22 @@
  * Routines for H.324/SRP dissection
  * 2004 Richard van der Hoff <richardv@mxtelecom.com>
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
 
-#include <glib.h>
 #include <epan/packet.h>
-#include <epan/bitswap.h>
-#include <epan/circuit.h>
-#include <epan/stream.h>
 #include <epan/crc16-tvb.h>
 
+void proto_register_srp(void);
+void proto_register_ccsrl(void);
+void proto_reg_handoff_srp(void);
+
 /* Wireshark ID of the protocols */
 static int proto_srp = -1;
 static int proto_ccsrl = -1;
@@ -60,22 +44,28 @@ static dissector_handle_t h245dg_handle;
 #define SRP_SRP_RESPONSE 251
 #define SRP_NSRP_RESPONSE 247
 
+/* WNSRP definitions */
+#define WNSRP_COMMAND_HEADER 241
+#define WNSRP_RESPONSE_HEADER 243
+
 static const value_string srp_frame_types[] = {
-  {SRP_SRP_COMMAND, "SRP command"},
-  {SRP_SRP_RESPONSE, "SRP response"},
-  {SRP_NSRP_RESPONSE, "NSRP response"},
-  {0,NULL}
+    {SRP_SRP_COMMAND, "SRP command"},
+    {SRP_SRP_RESPONSE, "SRP response"},
+    {SRP_NSRP_RESPONSE, "NSRP response"},
+    {WNSRP_COMMAND_HEADER, "WNSRP command"},
+    {WNSRP_RESPONSE_HEADER, "WNSRP response"},
+    {0,NULL}
 };
 
 static const value_string ccsrl_ls_vals[] = {
-  {0xFF, "Yes"},
-  {0x00, "No"},
-  {0,NULL}
+    {0xFF, "Yes"},
+    {0x00, "No"},
+    {0,NULL}
 };
 
 /*****************************************************************************/
 
-static void dissect_ccsrl(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
+static int dissect_ccsrl(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_)
 {
     proto_item *ccsrl_item;
     proto_tree *ccsrl_tree=NULL;
@@ -84,18 +74,19 @@ static void dissect_ccsrl(tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree
 
     /* add the 'ccsrl' tree to the main tree */
     if (tree) {
-       ccsrl_item = proto_tree_add_item (tree, proto_ccsrl, tvb, 0, -1, FALSE);
-       ccsrl_tree = proto_item_add_subtree (ccsrl_item, ett_ccsrl);
-       proto_tree_add_uint(ccsrl_tree,hf_ccsrl_ls,tvb,0,1,lastseg);
+        ccsrl_item = proto_tree_add_item (tree, proto_ccsrl, tvb, 0, -1, ENC_NA);
+        ccsrl_tree = proto_item_add_subtree (ccsrl_item, ett_ccsrl);
+        proto_tree_add_uint(ccsrl_tree,hf_ccsrl_ls,tvb,0,1,lastseg);
     }
 
     /* XXX add support for reassembly of fragments */
-    
+
     /* XXX currently, we always dissect as H245. It's not necessarily
         that though.
     */
     next_tvb = tvb_new_subset_remaining(tvb, 1);
     call_dissector( h245dg_handle, next_tvb, pinfo, ccsrl_tree );
+    return tvb_captured_length(tvb);
 }
 
 static void dissect_srp_command(tvbuff_t * tvb, packet_info * pinfo, proto_tree * srp_tree)
@@ -104,10 +95,10 @@ static void dissect_srp_command(tvbuff_t * tvb, packet_info * pinfo, proto_tree
     guint payload_len;
 
     if( srp_tree )
-       proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,FALSE);
+        proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,ENC_BIG_ENDIAN);
 
     payload_len = tvb_reported_length_remaining(tvb,4);
-    next_tvb = tvb_new_subset(tvb, 2, payload_len, payload_len );
+    next_tvb = tvb_new_subset_length(tvb, 2, payload_len);
 
     /* XXX currently, we always dissect as CCSRL. It's only that in
      * H324/Annex C though.
@@ -115,74 +106,77 @@ static void dissect_srp_command(tvbuff_t * tvb, packet_info * pinfo, proto_tree
     call_dissector(ccsrl_handle, next_tvb, pinfo, srp_tree );
 }
 
-static void dissect_srp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree)
+static int dissect_srp (tvbuff_t * tvb, packet_info * pinfo, proto_tree * tree, void* data _U_)
 {
     proto_item *srp_item = NULL;
     proto_tree *srp_tree = NULL;
     proto_item *hidden_item;
 
     guint8 header = tvb_get_guint8(tvb,0);
-    
+
     /* add the 'srp' tree to the main tree */
     if (tree) {
-       srp_item = proto_tree_add_item (tree, proto_srp, tvb, 0, -1, FALSE);
-       srp_tree = proto_item_add_subtree (srp_item, ett_srp);
-       proto_tree_add_uint(srp_tree,hf_srp_header,tvb,0,1,header);
+        srp_item = proto_tree_add_item (tree, proto_srp, tvb, 0, -1, ENC_NA);
+        srp_tree = proto_item_add_subtree (srp_item, ett_srp);
+        proto_tree_add_uint(srp_tree,hf_srp_header,tvb,0,1,header);
     }
 
     switch( header ) {
-       case SRP_SRP_COMMAND:
-           dissect_srp_command(tvb,pinfo,srp_tree);
-           break;
-
-       case SRP_SRP_RESPONSE:
-           break;
-
-       case SRP_NSRP_RESPONSE:
-           if( srp_tree )
-               proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,FALSE);
-           break;
-
-       default:
-           break;
+        case SRP_SRP_COMMAND:
+        case WNSRP_COMMAND_HEADER:
+            dissect_srp_command(tvb,pinfo,srp_tree);
+            break;
+
+        case SRP_SRP_RESPONSE:
+            break;
+
+        case SRP_NSRP_RESPONSE:
+        case WNSRP_RESPONSE_HEADER:
+            if( srp_tree )
+                proto_tree_add_item(srp_tree,hf_srp_seqno,tvb,1,1,ENC_BIG_ENDIAN);
+            break;
+
+        default:
+            break;
     }
 
     if( srp_tree ) {
-       guint16 crc, calc_crc;
-       guint crc_offset = tvb_reported_length(tvb)-2;
-       crc = tvb_get_letohs(tvb,-2);
-
-       /* crc includes the header */
-       calc_crc = crc16_ccitt_tvb(tvb,crc_offset);
-       
-       if( crc == calc_crc ) {
-           proto_tree_add_uint_format(srp_tree, hf_srp_crc, tvb,
-                                      crc_offset, 2, crc,
-                                      "CRC: 0x%04x (correct)", crc);
-       } else {
-           hidden_item = proto_tree_add_boolean(srp_tree, hf_srp_crc_bad, tvb,
-                                         crc_offset, 2, TRUE);
-           PROTO_ITEM_SET_HIDDEN(hidden_item);
-           proto_tree_add_uint_format(srp_tree, hf_srp_crc, tvb,
-                                      crc_offset, 2, crc,
-                                      "CRC: 0x%04x (incorrect, should be 0x%04x)",
-                                      crc,
-                                      calc_crc);
-       }
+        guint16 crc, calc_crc;
+        guint crc_offset = tvb_reported_length(tvb)-2;
+        crc = tvb_get_letohs(tvb,-2);
+
+        /* crc includes the header */
+        calc_crc = crc16_ccitt_tvb(tvb,crc_offset);
+
+        if( crc == calc_crc ) {
+            proto_tree_add_uint_format_value(srp_tree, hf_srp_crc, tvb,
+                                       crc_offset, 2, crc,
+                                       "0x%04x (correct)", crc);
+        } else {
+            hidden_item = proto_tree_add_boolean(srp_tree, hf_srp_crc_bad, tvb,
+                                          crc_offset, 2, TRUE);
+            PROTO_ITEM_SET_HIDDEN(hidden_item);
+            proto_tree_add_uint_format_value(srp_tree, hf_srp_crc, tvb,
+                                       crc_offset, 2, crc,
+                                       "0x%04x (incorrect, should be 0x%04x)",
+                                       crc,
+                                       calc_crc);
+        }
     }
 
+    return tvb_captured_length(tvb);
 }
 
 void proto_register_ccsrl (void)
 {
     static hf_register_info hf[] = {
-       { &hf_ccsrl_ls,
-         { "Last Segment","ccsrl.ls",FT_UINT8, BASE_HEX, ccsrl_ls_vals, 0x0,
-           "Last segment indicator", HFILL}},
+        { &hf_ccsrl_ls,
+          { "Last Segment","ccsrl.ls",FT_UINT8, BASE_HEX, VALS(ccsrl_ls_vals), 0x0,
+            "Last segment indicator", HFILL}},
     };
 
     static gint *ett[] = {
-       &ett_ccsrl,
+        &ett_ccsrl,
     };
 
     proto_ccsrl = proto_register_protocol ("H.324/CCSRL", "CCSRL", "ccsrl");
@@ -194,22 +188,22 @@ void proto_register_ccsrl (void)
 void proto_register_srp (void)
 {
     static hf_register_info hf[] = {
-       {&hf_srp_header,
-        { "Header", "srp.header", FT_UINT8, BASE_DEC, srp_frame_types, 0x0,
-          "SRP header octet", HFILL }},
-       {&hf_srp_seqno,
-        { "Sequence Number", "srp.seqno", FT_UINT8, BASE_DEC, NULL, 0x0,
-          NULL, HFILL }},
-       {&hf_srp_crc,
-        { "CRC", "srp.crc", FT_UINT16, BASE_HEX, NULL, 0x0,
-          NULL, HFILL }},
-       { &hf_srp_crc_bad,
-         { "Bad CRC","srp.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
-           NULL, HFILL }},
+        {&hf_srp_header,
+         { "Header", "srp.header", FT_UINT8, BASE_DEC, VALS(srp_frame_types), 0x0,
+           "SRP header octet", HFILL }},
+        {&hf_srp_seqno,
+         { "Sequence Number", "srp.seqno", FT_UINT8, BASE_DEC, NULL, 0x0,
+           NULL, HFILL }},
+        {&hf_srp_crc,
+         { "CRC", "srp.crc", FT_UINT16, BASE_HEX, NULL, 0x0,
+           NULL, HFILL }},
+        { &hf_srp_crc_bad,
+          { "Bad CRC","srp.crc_bad", FT_BOOLEAN, BASE_NONE, NULL, 0x0,
+            NULL, HFILL }},
     };
 
     static gint *ett[] = {
-       &ett_srp,
+        &ett_srp,
     };
 
     proto_srp = proto_register_protocol ("H.324/SRP", "SRP", "srp");
@@ -225,6 +219,19 @@ void proto_register_srp (void)
 
 
 void proto_reg_handoff_srp(void) {
-    ccsrl_handle = find_dissector("ccsrl");
-    h245dg_handle = find_dissector("h245dg");
+    ccsrl_handle = find_dissector_add_dependency("ccsrl", proto_srp);
+    h245dg_handle = find_dissector_add_dependency("h245dg", proto_srp);
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 4
+ * tab-width: 8
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
+ */