Add tvbuff class.
[obnox/wireshark/wip.git] / packet-ascend.c
1 /* packet-ascend.c
2  * Routines for decoding Lucent/Ascend packet traces
3  *
4  * $Id: packet-ascend.c,v 1.11 2000/05/11 08:14:54 gram Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * 
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
30 #endif
31
32 #include <glib.h>
33 #include <string.h>
34 #include "packet.h"
35 #include "packet-eth.h"
36 #include "packet-ppp.h"
37
38 static int proto_ascend  = -1;
39 static int hf_link_type  = -1;
40 static int hf_session_id = -1;
41 static int hf_called_number = -1;
42 static int hf_chunk      = -1;
43 static int hf_task       = -1;
44 static int hf_user_name  = -1;
45
46 static gint ett_raw = -1;
47
48 static const value_string encaps_vals[] = {
49   {ASCEND_PFX_WDS_X, "PPP Transmit"},
50   {ASCEND_PFX_WDS_R, "PPP Receive" },
51   {ASCEND_PFX_WDD,   "Ethernet"    },
52   {0,                NULL          } };
53
54 void
55 dissect_ascend( const u_char *pd, frame_data *fd, proto_tree *tree ) {
56   proto_tree *fh_tree;
57   proto_item *ti;
58
59   /* load the top pane info. This should be overwritten by
60      the next protocol in the stack */
61   if(check_col(fd, COL_RES_DL_SRC))
62     col_add_str(fd, COL_RES_DL_SRC, "N/A" );
63   if(check_col(fd, COL_RES_DL_DST))
64     col_add_str(fd, COL_RES_DL_DST, "N/A" );
65   if(check_col(fd, COL_PROTOCOL))
66     col_add_str(fd, COL_PROTOCOL, "N/A" );
67   if(check_col(fd, COL_INFO))
68     col_add_str(fd, COL_INFO, "Lucent/Ascend packet trace" );
69
70   /* populate a tree in the second pane with the status of the link
71      layer (ie none) */
72   if(tree) {
73     ti = proto_tree_add_text(tree, NullTVB, 0, 0, "Lucent/Ascend packet trace" );
74     fh_tree = proto_item_add_subtree(ti, ett_raw);
75     proto_tree_add_item(fh_tree, hf_link_type, NullTVB, 0, 0, 
76                         fd->pseudo_header.ascend.type);
77     if (fd->pseudo_header.ascend.type == ASCEND_PFX_WDD) {
78       proto_tree_add_item(fh_tree, hf_called_number, NullTVB, 0, 0, 
79                           fd->pseudo_header.ascend.call_num);
80       proto_tree_add_item(fh_tree, hf_chunk, NullTVB, 0, 0,
81                           fd->pseudo_header.ascend.chunk);
82       proto_tree_add_item_hidden(fh_tree, hf_session_id, NullTVB, 0, 0, 0);
83     } else {  /* It's wandsession data */
84       proto_tree_add_item(fh_tree, hf_user_name, NullTVB, 0, 0, 
85                           fd->pseudo_header.ascend.user);
86       proto_tree_add_item(fh_tree, hf_session_id, NullTVB, 0, 0,
87                           fd->pseudo_header.ascend.sess);
88       proto_tree_add_item_hidden(fh_tree, hf_chunk, NullTVB, 0, 0, 0);
89     }
90     proto_tree_add_item(fh_tree, hf_task, NullTVB, 0, 0, fd->pseudo_header.ascend.task);
91   }
92
93   switch (fd->pseudo_header.ascend.type) {
94     case ASCEND_PFX_WDS_X:
95     case ASCEND_PFX_WDS_R:
96       dissect_ppp(pd, 0, fd, tree);
97       break;
98     case ASCEND_PFX_WDD:
99       dissect_eth(pd, 0, fd, tree);
100       break;
101     default:
102       break;
103   }
104 }
105
106 void
107 proto_register_ascend(void)
108 {
109   static hf_register_info hf[] = {
110     { &hf_link_type,
111     { "Link type",      "ascend.type",  FT_UINT32, BASE_DEC,    VALS(encaps_vals),      0x0,
112       "" }},
113
114     { &hf_session_id,
115     { "Session ID",     "ascend.sess",  FT_UINT32, BASE_DEC,    NULL, 0x0,
116       "" }},
117
118     { &hf_called_number,
119     { "Called number",  "ascend.number", FT_STRING, BASE_NONE,  NULL, 0x0,
120       "" }},
121
122     { &hf_chunk,
123     { "WDD Chunk",      "ascend.chunk", FT_UINT32, BASE_HEX,    NULL, 0x0,
124       "" }},
125
126     { &hf_task,
127     { "Task",           "ascend.task",  FT_UINT32, BASE_HEX,    NULL, 0x0,
128       "" }},
129
130     { &hf_user_name,
131     { "User name",      "ascend.user",  FT_STRING, BASE_NONE,   NULL, 0x0,
132       "" }},
133   };
134   static gint *ett[] = {
135     &ett_raw,
136   };
137
138   proto_ascend = proto_register_protocol("Lucent/Ascend debug output", "ascend");
139   proto_register_field_array(proto_ascend, hf, array_length(hf));
140   proto_register_subtree_array(ett, array_length(ett));
141 }