Minor spelling etc updates.
[metze/wireshark/wip.git] / packet-ncp.c
index 50c7eafc972940578307dd5aaff489156971e0c8..3bad2c7af799bc2689d8adc19cfefc9eb3bbfb5f 100644 (file)
@@ -5,7 +5,7 @@
  * Modified to decode server op-lock
  * & NDS packets by Greg Morris <gmorris@novell.com>
  *
- * $Id: packet-ncp.c,v 1.68 2002/08/28 21:00:23 jmayer Exp $
+ * $Id: packet-ncp.c,v 1.72 2002/10/11 19:36:13 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -82,13 +82,15 @@ static int hf_ncp_slot = -1;
 static int hf_ncp_control_code = -1;
 static int hf_ncp_fragment_handle = -1;
 static int hf_lip_echo = -1;
-
+/*static int hf_ping_version = -1;*/
 
 gint ett_ncp = -1;
+gint ett_nds = -1;
 static gint ett_ncp_system_flags = -1;
 
 /* desegmentation of NCP over TCP */
 static gboolean ncp_desegment = TRUE;
+/*static int ncp_nds_true = FALSE;*/
 
 static dissector_handle_t data_handle;
 
@@ -98,6 +100,7 @@ static dissector_handle_t data_handle;
 #define NCP_RQST_HDR_LENGTH    7
 #define NCP_RPLY_HDR_LENGTH    8
 
+
 /* Hash functions */
 gint  ncp_equal (gconstpointer v, gconstpointer v2);
 guint ncp_hash  (gconstpointer v);
@@ -138,6 +141,10 @@ static const value_string ncp_ip_signature[] = {
        (c) 1996 by Steve Conner & Diane Conner
        Published by Annabooks, San Diego, California
         ISBN: 0-929392-31-0
+        
+ And:
+    http:developer.novell.com
+    NCP documentation        
 
 */
 
@@ -159,10 +166,10 @@ static value_string ncp_type_vals[] = {
        { NCP_SERVICE_REPLY,    "Service reply" },
        { NCP_WATCHDOG,         "Watchdog" },
        { NCP_DEALLOCATE_SLOT,  "Destroy service connection" },
-       { NCP_BROADCAST_SLOT,   "Server Broadcast" },
+    { NCP_BROADCAST_SLOT,   "Server Broadcast" },
        { NCP_BURST_MODE_XFER,  "Burst mode transfer" },
        { NCP_POSITIVE_ACK,     "Request being processed" },
-       { NCP_LIP_ECHO, "Large Internet Packet Echo" },
+    { NCP_LIP_ECHO, "Large Internet Packet Echo" },
        { 0,                    NULL }
 };
 
@@ -191,12 +198,13 @@ dissect_ncp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
        proto_tree                      *flags_tree = NULL;
        guint16                         data_len = 0;
        guint16                         missing_fraglist_count = 0;
-       guint16                         ncp_nds_verb;
        int                             hdr_offset = 0;
        int                             commhdr;
        int                             offset;
        gint                            length_remaining;
        tvbuff_t                        *next_tvb;
+       guint32                         testvar = 0;
+       guint8                          subfunction;
 
        if (check_col(pinfo->cinfo, COL_PROTOCOL))
                col_set_str(pinfo->cinfo, COL_PROTOCOL, "NCP");
@@ -236,15 +244,16 @@ dissect_ncp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
        /* Record the offset where the NCP common header starts */
        commhdr = hdr_offset;
 
-       header.type             = tvb_get_ntohs(tvb, commhdr);
+       header.type                 = tvb_get_ntohs(tvb, commhdr);
        header.sequence         = tvb_get_guint8(tvb, commhdr+2);
        header.conn_low         = tvb_get_guint8(tvb, commhdr+3);
        header.conn_high        = tvb_get_guint8(tvb, commhdr+5);
 
        if (check_col(pinfo->cinfo, COL_INFO)) {
-               col_add_fstr(pinfo->cinfo, COL_INFO,
+           col_add_fstr(pinfo->cinfo, COL_INFO,
                    "%s",
                    val_to_str(header.type, ncp_type_vals, "Unknown type (0x%04x)"));
+
        }
 
        nw_connection = (header.conn_high << 16) + header.conn_low;
@@ -272,7 +281,7 @@ dissect_ncp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
         */
        switch (header.type) {
 
-       case NCP_BROADCAST_SLOT:        /* Server Broadcast */
+       case NCP_BROADCAST_SLOT:    /* Server Broadcast */
                proto_tree_add_uint(ncp_tree, hf_ncp_seq,       tvb, commhdr + 2, 1, header.sequence);
                proto_tree_add_uint(ncp_tree, hf_ncp_connection,tvb, commhdr + 3, 3, nw_connection);
                proto_tree_add_item(ncp_tree, hf_ncp_task,      tvb, commhdr + 4, 1, FALSE);
@@ -280,8 +289,8 @@ dissect_ncp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                proto_tree_add_item(ncp_tree, hf_ncp_oplock_handle, tvb, commhdr + 10, 4, FALSE);
                break;
 
-       case NCP_LIP_ECHO:              /* Lip Echo Packet */
-               proto_tree_add_item(ncp_tree, hf_lip_echo, tvb, commhdr, 13, FALSE);
+       case NCP_LIP_ECHO:    /* Lip Echo Packet */
+               proto_tree_add_item(ncp_tree, hf_lip_echo, tvb, commhdr, 2, FALSE);
                break;
 
        case NCP_BURST_MODE_XFER:       /* Packet Burst Packet */
@@ -379,12 +388,22 @@ dissect_ncp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                    tvb, commhdr + 34, 2, FALSE);
                break;
 
+       case NCP_ALLOCATE_SLOT:         /* Allocate Slot Request */
+               length_remaining = tvb_length_remaining(tvb, commhdr + 4);
+               if (length_remaining > 4) { 
+                       testvar = tvb_get_ntohl(tvb, commhdr+4);
+                       if (testvar == 0x4c495020) {
+                               proto_tree_add_item(ncp_tree, hf_lip_echo, tvb, commhdr+4, 13, FALSE);
+                               break;
+                       }
+               }
+               /* otherwise fall through */
+    
+       case NCP_POSITIVE_ACK:          /* Positive Acknowledgement */
        case NCP_SERVICE_REQUEST:       /* Server NCP Request */
        case NCP_SERVICE_REPLY:         /* Server NCP Reply */
-       case NCP_ALLOCATE_SLOT:         /* Allocate Slot Request */
        case NCP_WATCHDOG:              /* Watchdog Packet */
        case NCP_DEALLOCATE_SLOT:       /* Deallocate Slot Request */
-       case NCP_POSITIVE_ACK:          /* Positive Acknowledgement */
        default:
                proto_tree_add_uint(ncp_tree, hf_ncp_seq,       tvb, commhdr + 2, 1, header.sequence);
                proto_tree_add_uint(ncp_tree, hf_ncp_connection,tvb, commhdr + 3, 3, nw_connection);
@@ -398,19 +417,42 @@ dissect_ncp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
        switch (header.type) {
 
        case NCP_ALLOCATE_SLOT:         /* Allocate Slot Request */
+               length_remaining = tvb_length_remaining(tvb, commhdr + 4);
+               if (length_remaining > 4) {
+                       testvar = tvb_get_ntohl(tvb, commhdr+4);
+                       if (testvar == 0x4c495020) {
+                               proto_tree_add_text(ncp_tree, tvb, commhdr, -1,
+                                   "Lip Echo Packet");
+                               /*break;*/
+                       }
+               }
+
        case NCP_SERVICE_REQUEST:       /* Server NCP Request */
        case NCP_DEALLOCATE_SLOT:       /* Deallocate Slot Request */
        case NCP_BROADCAST_SLOT:        /* Server Broadcast Packet */
                next_tvb = tvb_new_subset(tvb, hdr_offset, -1, -1);
                if (tvb_get_guint8(tvb, commhdr+6) == 0x68) {
-                       ncp_nds_verb = tvb_get_ntohl(tvb, commhdr+4);
-                       if (tvb_get_guint8(tvb, commhdr+7) == 0x02) {  /* NDS Packet to decode */
-                               dissect_nds_request(next_tvb, pinfo, nw_connection,
-                                   header.sequence, header.type, ncp_tree);
-                       } else {
-                               dissect_ncp_request(next_tvb, pinfo, nw_connection,
-                                   header.sequence, header.type, ncp_tree);
-                       }
+                       subfunction = tvb_get_guint8(tvb, commhdr+7);
+                       switch (subfunction) {
+
+                       case 0x02:      /* NDS Frag Packet to decode */
+                               dissect_nds_request(next_tvb, pinfo,
+                                   nw_connection, header.sequence,
+                                   header.type, ncp_tree);
+                               break;
+
+                       case 0x01:      /* NDS Ping */
+                               dissect_ping_req(next_tvb, pinfo,
+                                   nw_connection, header.sequence,
+                                   header.type, ncp_tree);
+                               break;
+
+                       default:
+                               dissect_ncp_request(next_tvb, pinfo,
+                                   nw_connection, header.sequence,
+                                   header.type, ncp_tree);
+                               break;
+                        }
                } else {
                        dissect_ncp_request(next_tvb, pinfo, nw_connection,
                            header.sequence, header.type, ncp_tree);
@@ -490,7 +532,7 @@ dissect_ncp_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
 
        default:
                if (tree) {
-                       proto_tree_add_text(ncp_tree, tvb, commhdr + 6, -1,
+                   proto_tree_add_text(ncp_tree, tvb, commhdr + 6, -1,
                            "%s packets not supported yet",
                            val_to_str(header.type, ncp_type_vals,
                                "Unknown type (0x%04x)"));
@@ -524,6 +566,7 @@ get_ncp_pdu_len(tvbuff_t *tvb, int offset)
    * Get the length of the NCP-over-TCP packet.  Strip off the "has
    * signature" flag.
    */
+
   return tvb_get_ntohl(tvb, offset + 4) & 0x7fffffff;
 }
 
@@ -681,10 +724,12 @@ proto_register_ncp(void)
       { "Large Internet Packet Echo",    "ncp.lip_echo",
     FT_STRING, BASE_NONE, NULL, 0x0,
     "", HFILL }},
+  
   };
   static gint *ett[] = {
     &ett_ncp,
     &ett_ncp_system_flags,
+    &ett_nds,
   };
   module_t *ncp_module;
 
@@ -715,3 +760,5 @@ proto_reg_handoff_ncp(void)
 
   data_handle = find_dissector("data");
 }
+
+