From Robert Hogan via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4257 :
authormorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 13 May 2010 15:19:40 +0000 (15:19 +0000)
committermorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 13 May 2010 15:19:40 +0000 (15:19 +0000)
Correctly decode and display the buffer address in SBA orders.

Note: This includes a macro with a new license which is added to COPYING.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@32785 f5534014-38df-0310-8fa8-9805f1628bb7

COPYING
epan/dissectors/packet-telnet.c
epan/dissectors/packet-tn3270.c
epan/dissectors/packet-tn3270.h

diff --git a/COPYING b/COPYING
index e836c8dca8df6831feba14edd0b8ca971ecb035a..1e2cc2fcf1426dce10d37c343c7b7df2b2ec1627 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -28,7 +28,7 @@ Parts of Wireshark can be built and distributed as libraries. These
 parts are still covered by the GPL, and NOT by the Lesser General Public
 License or any other license.
 
-If you integrate all or part of Wireshark into your own application, then 
+If you integrate all or part of Wireshark into your own application, then
 that application must be released under a license compatible with the GPL.
 
 The full text of the GNU GPL and the other applicable licenses follows.
@@ -383,7 +383,7 @@ Parts of this software are licensed as follows
 
    Copyright (c) 1988, 1992, 1993
         The Regents of the University of California.  All rights reserved.
-  
+
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
@@ -395,7 +395,7 @@ Parts of this software are licensed as follows
    3. Neither the name of the University nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.
-  
+
    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -410,7 +410,7 @@ Parts of this software are licensed as follows
 
 
    Copyright (c) 2003 Markus Friedl.  All rights reserved.
-  
+
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
@@ -419,7 +419,7 @@ Parts of this software are licensed as follows
    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
-  
+
    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
@@ -434,25 +434,25 @@ Parts of this software are licensed as follows
 
    Copyright (c) 2003 Endace Technology Ltd, Hamilton, New Zealand.
    All rights reserved.
-  
+
    This software and documentation has been developed by Endace Technology Ltd.
    along with the DAG PCI network capture cards. For further information please
    visit http://www.endace.com/.
-  
+
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
-  
+
     1. Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
-  
+
     2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.
-  
+
     3. The name of Endace Technology Ltd may not be used to endorse or promote
     products derived from this software without specific prior written
     permission.
-  
+
    THIS SOFTWARE IS PROVIDED BY ENDACE TECHNOLOGY LTD ``AS IS'' AND ANY EXPRESS
    OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
@@ -467,7 +467,7 @@ Parts of this software are licensed as follows
 
    Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
    All rights reserved.
-  
+
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
@@ -479,7 +479,7 @@ Parts of this software are licensed as follows
    3. Neither the name of the project nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.
-  
+
    THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -494,7 +494,7 @@ Parts of this software are licensed as follows
 
 
    Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
-  
+
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
@@ -503,7 +503,7 @@ Parts of this software are licensed as follows
    2. Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
-  
+
    THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -515,3 +515,32 @@ Parts of this software are licensed as follows
    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    SUCH DAMAGE.
+
+   Copyright (c) 1993-2009, Paul Mattes.
+   Copyright (c) 1990, Jeff Sparkes.
+   Copyright (c) 1989, Georgia Tech Research Corporation (GTRC), Atlanta, GA
+     30332.
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+       * Redistributions of source code must retain the above copyright
+         notice, this list of conditions and the following disclaimer.
+       * Redistributions in binary form must reproduce the above copyright
+         notice, this list of conditions and the following disclaimer in the
+         documentation and/or other materials provided with the distribution.
+       * Neither the names of Paul Mattes, Jeff Sparkes, GTRC nor the names of
+         their contributors may be used to endorse or promote products derived
+         from this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY PAUL MATTES, JEFF SPARKES AND GTRC "AS IS" AND
+   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+   ARE DISCLAIMED. IN NO EVENT SHALL PAUL MATTES, JEFF SPARKES OR GTRC BE
+   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+   POSSIBILITY OF SUCH DAMAGE.
index e1963b5f03cdd2ecc577952830516e0e39365355..add9185d22245cb0de9ef2fa126cc33da2f8d11f 100644 (file)
@@ -138,21 +138,30 @@ typedef struct tn_opt {
 } tn_opt;
 
 static void
-check_for_tn3270(packet_info *pinfo _U_, const char *optname, const char *terminaltype)
+check_tn3270_model(packet_info *pinfo _U_, const char *terminaltype)
 {
-
-  if (strcmp(optname,"Terminal Type") != 0) {
-      return;
-  }
-
+  int model;
+  char str_model[2];
   if ((strcmp(terminaltype,"IBM-3278-2-E") == 0) || (strcmp(terminaltype,"IBM-3278-2") == 0) ||
       (strcmp(terminaltype,"IBM-3278-3") == 0) || (strcmp(terminaltype,"IBM-3278-4") == 0) ||
       (strcmp(terminaltype,"IBM-3278-5") == 0) || (strcmp(terminaltype,"IBM-3277-2") == 0) ||
       (strcmp(terminaltype,"IBM-3279-3") == 0) || (strcmp(terminaltype,"IBM-3279-4") == 0) ||
       (strcmp(terminaltype,"IBM-3279-2-E") == 0) || (strcmp(terminaltype,"IBM-3279-2") == 0) ||
-      (strcmp(terminaltype,"IBM-3279-4-E") == 0))
-      add_tn3270_conversation(pinfo, 0);
+      (strcmp(terminaltype,"IBM-3279-4-E") == 0)) {
+      str_model[0] = terminaltype[9];
+      str_model[1] = '\0';
+      model = atoi(str_model);
+      add_tn3270_conversation(pinfo, 0, model);
+  }
+}
 
+static void
+check_for_tn3270(packet_info *pinfo _U_, const char *optname, const char *terminaltype)
+{
+  if (strcmp(optname,"Terminal Type") != 0) {
+      return;
+  }
+  check_tn3270_model(pinfo, terminaltype);
 }
 
 static void
@@ -210,7 +219,7 @@ dissect_tn3270_regime_subopt(packet_info *pinfo _U_, const char *optname _U_, tv
       case TN3270_REGIME_IS:
         if (cmd == TN3270_REGIME_ARE) {
             proto_tree_add_text(tree, tvb, offset, 1, "ARE");
-            add_tn3270_conversation(pinfo, 0);
+            add_tn3270_conversation(pinfo, 0, 0);
         } else {
             proto_tree_add_text(tree, tvb, offset, 1, "IS");
         }
@@ -294,6 +303,7 @@ dissect_tn3270e_subopt(packet_info *pinfo _U_, const char *optname _U_, tvbuff_t
                   if (datalen > 0) {
                     proto_tree_add_text(tree, tvb, offset + 1, datalen, "%s",
                                         tvb_format_text(tvb, offset + 1, datalen));
+                    check_tn3270_model(pinfo, tvb_format_text(tvb, offset + 1, datalen));
                     offset += datalen;
                     len -= datalen;
                   }
@@ -339,7 +349,7 @@ dissect_tn3270e_subopt(packet_info *pinfo _U_, const char *optname _U_, tvbuff_t
             proto_tree_add_text(tree, tvb, offset, 1, "REJECT");
             break;
       case TN3270_REQUEST:
-            add_tn3270_conversation(pinfo, 1);
+            add_tn3270_conversation(pinfo, 1, 0);
             proto_tree_add_text(tree, tvb, offset, 1, "REQUEST");
             device_type = tvb_get_guint8(tvb, offset-1);
             if (device_type == TN3270_DEVICE_TYPE) {
index 4290b9136d9ec3b782f683a193f66ec159aa8e94..a9ebbb19925643bea7573487827de8bd83e6bf2e 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
  */
+/*
+ * The DECODE_BADDR macro comes from ctlr.c in X3270 and has the following licence:
+ *
+ * Copyright (c) 1993-2009, Paul Mattes.
+ * Copyright (c) 1990, Jeff Sparkes.
+ * Copyright (c) 1989, Georgia Tech Research Corporation (GTRC), Atlanta, GA
+ *  30332.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the names of Paul Mattes, Jeff Sparkes, GTRC nor the names of
+ *       their contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY PAUL MATTES, JEFF SPARKES AND GTRC "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL PAUL MATTES, JEFF SPARKES OR GTRC BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define DECODE_BADDR(c1, c2) \
+    ((((c1) & 0xC0) == 0x00) ? \
+    (((c1) & 0x3F) << 8) | (c2) : \
+    (((c1) & 0x3F) << 6) | ((c2) & 0x3F))
 
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -60,8 +97,7 @@ static int hf_tn3270_attribute_type=-1;
 static int hf_tn3270_begin_end_flags1=-1;
 static int hf_tn3270_begin_end_flags2=-1;
 static int hf_tn3270_bsc=-1;
-static int hf_tn3270_buffer_x=-1;
-static int hf_tn3270_buffer_y=-1;
+static int hf_tn3270_buffer_address=-1;
 static int hf_tn3270_c_cav=-1;
 static int hf_tn3270_cc=-1;
 static int hf_tn3270_character_code=-1;
@@ -417,6 +453,8 @@ static gint ett_tn3270_msr_state_mask=-1;
 
 tn3270_conv_info_t *tn3270_info_items;
 
+guint8 ROWS, COLS, MAXROWS, MAXCOLS;
+
 gint dissect_orders_and_data(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset);
 
 typedef struct hf_items {
@@ -842,7 +880,7 @@ static gint
 dissect_outbound_3270ds(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
                              gint sf_length)
 {
-  int start=offset; 
+  int start=offset;
   int cmd;
 
   proto_tree_add_item(tn3270_tree,
@@ -1050,7 +1088,7 @@ dissect_restart(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset,
                           (sf_length - 9),
                           FALSE);
   offset+=(sf_length - 9);
-  
+
   return (offset - start);
 }
 
@@ -3450,18 +3488,22 @@ static gint
 dissect_sba(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
 {
   int start = offset;
-  proto_tree_add_item(tn3270_tree,
-                          hf_tn3270_buffer_x,
-                          tvb, offset,
-                          1,
-                          FALSE);
-  offset++;
-  proto_tree_add_item(tn3270_tree,
-                          hf_tn3270_buffer_y,
+  guint8 x, y;
+  int buffer_addr=0;
+  proto_item *ti;
+
+  x = tvb_get_guint8(tvb, offset);
+  y = tvb_get_guint8(tvb, offset+1);
+  buffer_addr = DECODE_BADDR(x,y);
+
+  ti = proto_tree_add_item(tn3270_tree,
+                          hf_tn3270_buffer_address,
                           tvb, offset,
-                          1,
+                          2,
                           FALSE);
-  offset++;
+  proto_item_append_text(ti, " (Row %u, Column %u for %ux%u Display)",
+                         (buffer_addr / COLS) + 1, (buffer_addr % COLS) + 1, ROWS, COLS);
+  offset+=2;
 
   return (offset - start);
 }
@@ -3605,10 +3647,15 @@ dissect_orders_and_data(proto_tree *tn3270_tree, tvbuff_t *tvb, gint offset)
             break;
 /*          case PT:*/
           case IC:
+            break;
           case EW:
+            ROWS=24;
+            COLS=80;
+            break;
           case EWA:
+            ROWS=MAXROWS;
+            COLS=MAXCOLS;
             break;
-/*            return (offset - start);*/
           default:
             proto_tree_add_text(tn3270_tree, tvb, offset, 1, "Bogus value: %u", order_code);
             offset ++;
@@ -3838,7 +3885,7 @@ dissect_tn3270(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 }
 
 void
-add_tn3270_conversation(packet_info *pinfo, int tn3270e)
+add_tn3270_conversation(packet_info *pinfo, int tn3270e, int model)
 {
   conversation_t *conversation;
   tn3270_conv_info_t *tn3270_info = NULL;
@@ -3874,6 +3921,24 @@ add_tn3270_conversation(packet_info *pinfo, int tn3270e)
       tn3270_info_items = tn3270_info;
     }
 
+    /* The maximum rows/cols is tied to the 3270 model number */
+    switch (model) {
+        case 4:
+          MAXROWS = 32;
+          MAXCOLS = 80;
+          break;
+        case 5:
+          MAXROWS = 27;
+          MAXCOLS = 132;
+          break;
+        case 2:
+        default:
+          MAXROWS = 24;
+          MAXCOLS = 80;
+      }
+    ROWS = 24;
+    COLS = 80;
+
     tn3270_info->extended = tn3270e;
 
 }
@@ -4048,13 +4113,9 @@ proto_register_tn3270(void)
         FT_UINT8, BASE_HEX, VALS(vals_attention_identification_bytes), 0x0,
         NULL, HFILL }},
 
-    { &hf_tn3270_buffer_x,
-      { "Buffer X", "tn3270.buffer_x",
-        FT_UINT8, BASE_HEX, NULL, 0x0,
-        NULL, HFILL }},
-    { &hf_tn3270_buffer_y,
-      { "Buffer Y", "tn3270.buffer_y",
-        FT_UINT8, BASE_HEX, NULL, 0x0,
+    { &hf_tn3270_buffer_address,
+      { "Buffer Address", "tn3270.buffer_address",
+        FT_UINT16, BASE_HEX, NULL, 0x0,
         NULL, HFILL }},
 
     /* Self Defining Parameters */
@@ -4193,7 +4254,7 @@ proto_register_tn3270(void)
     /* END - 5.11 - Load Format Storage */
 
     /* 5.12 - Load Line Type */
-    { &hf_tn3270_load_line_type_command, 
+    { &hf_tn3270_load_line_type_command,
         {  "Line Type Command", "tn3270.load_line_type_command",
             FT_UINT8, BASE_HEX, NULL, 0x0,
             NULL, HFILL }},
index fe07b26e7e7e2826fb7af3b15eddd59321270030..df2415f8e18da11cb71dc0abc6039d27c841357b 100644 (file)
@@ -1143,7 +1143,7 @@ typedef struct tn3270_conv_info_t {
   gint extended;
 } tn3270_conv_info_t;
 
-void add_tn3270_conversation(packet_info *pinfo, int tn3270e);
+void add_tn3270_conversation(packet_info *pinfo, int tn3270e, int model);
 int find_tn3270_conversation(packet_info *pinfo);
 
 #endif