Obscure more email addresses.
[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.32 2002/08/28 21:00:07 jmayer Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
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 #include <glib.h>
29 #include <string.h>
30 #include <epan/packet.h>
31
32 static int proto_ascend  = -1;
33 static int hf_link_type  = -1;
34 static int hf_session_id = -1;
35 static int hf_called_number = -1;
36 static int hf_chunk      = -1;
37 static int hf_task       = -1;
38 static int hf_user_name  = -1;
39
40 static gint ett_raw = -1;
41
42 static const value_string encaps_vals[] = {
43   {ASCEND_PFX_WDS_X, "PPP Transmit"},
44   {ASCEND_PFX_WDS_R, "PPP Receive" },
45   {ASCEND_PFX_WDD,   "Ethernet"    },
46   {0,                NULL          } };
47
48 static dissector_handle_t eth_handle;
49 static dissector_handle_t ppp_hdlc_handle;
50
51 static void
52 dissect_ascend(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
53 {
54   proto_tree                    *fh_tree;
55   proto_item                    *ti;
56   union wtap_pseudo_header      *pseudo_header = pinfo->pseudo_header;
57
58   /* load the top pane info. This should be overwritten by
59      the next protocol in the stack */
60   if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
61     col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "N/A" );
62   if(check_col(pinfo->cinfo, COL_RES_DL_DST))
63     col_set_str(pinfo->cinfo, COL_RES_DL_DST, "N/A" );
64   if(check_col(pinfo->cinfo, COL_PROTOCOL))
65     col_set_str(pinfo->cinfo, COL_PROTOCOL, "N/A" );
66   if(check_col(pinfo->cinfo, COL_INFO))
67     col_set_str(pinfo->cinfo, COL_INFO, "Lucent/Ascend packet trace" );
68
69   /* If this is a transmitted or received PPP frame, set the PPP direction. */
70   switch (pseudo_header->ascend.type) {
71
72   case ASCEND_PFX_WDS_X:
73     pinfo->p2p_dir = P2P_DIR_SENT;
74     break;
75
76   case ASCEND_PFX_WDS_R:
77     pinfo->p2p_dir = P2P_DIR_RECV;
78     break;
79   }
80
81   /* populate a tree in the second pane with the status of the link
82      layer (ie none) */
83   if(tree) {
84     ti = proto_tree_add_protocol_format(tree, proto_ascend, tvb, 0, 0,
85                                         "Lucent/Ascend packet trace");
86     fh_tree = proto_item_add_subtree(ti, ett_raw);
87     proto_tree_add_uint(fh_tree, hf_link_type, tvb, 0, 0,
88                         pseudo_header->ascend.type);
89     if (pseudo_header->ascend.type == ASCEND_PFX_WDD) {
90       proto_tree_add_string(fh_tree, hf_called_number, tvb, 0, 0,
91                           pseudo_header->ascend.call_num);
92       proto_tree_add_uint(fh_tree, hf_chunk, tvb, 0, 0,
93                           pseudo_header->ascend.chunk);
94       proto_tree_add_uint_hidden(fh_tree, hf_session_id, tvb, 0, 0, 0);
95     } else {  /* It's wandsession data */
96       proto_tree_add_string(fh_tree, hf_user_name, tvb, 0, 0,
97                           pseudo_header->ascend.user);
98       proto_tree_add_uint(fh_tree, hf_session_id, tvb, 0, 0,
99                           pseudo_header->ascend.sess);
100       proto_tree_add_uint_hidden(fh_tree, hf_chunk, tvb, 0, 0, 0);
101     }
102     proto_tree_add_uint(fh_tree, hf_task, tvb, 0, 0, pseudo_header->ascend.task);
103   }
104
105   switch (pseudo_header->ascend.type) {
106     case ASCEND_PFX_WDS_X:
107     case ASCEND_PFX_WDS_R:
108       call_dissector(ppp_hdlc_handle, tvb, pinfo, tree);
109       break;
110     case ASCEND_PFX_WDD:
111       call_dissector(eth_handle, tvb, pinfo, tree);
112       break;
113     default:
114       break;
115   }
116 }
117
118 void
119 proto_register_ascend(void)
120 {
121   static hf_register_info hf[] = {
122     { &hf_link_type,
123     { "Link type",      "ascend.type",  FT_UINT32, BASE_DEC,    VALS(encaps_vals),      0x0,
124       "", HFILL }},
125
126     { &hf_session_id,
127     { "Session ID",     "ascend.sess",  FT_UINT32, BASE_DEC,    NULL, 0x0,
128       "", HFILL }},
129
130     { &hf_called_number,
131     { "Called number",  "ascend.number", FT_STRING, BASE_NONE,  NULL, 0x0,
132       "", HFILL }},
133
134     { &hf_chunk,
135     { "WDD Chunk",      "ascend.chunk", FT_UINT32, BASE_HEX,    NULL, 0x0,
136       "", HFILL }},
137
138     { &hf_task,
139     { "Task",           "ascend.task",  FT_UINT32, BASE_HEX,    NULL, 0x0,
140       "", HFILL }},
141
142     { &hf_user_name,
143     { "User name",      "ascend.user",  FT_STRING, BASE_NONE,   NULL, 0x0,
144       "", HFILL }},
145   };
146   static gint *ett[] = {
147     &ett_raw,
148   };
149
150   proto_ascend = proto_register_protocol("Lucent/Ascend debug output",
151                                          "Lucent/Ascend", "ascend");
152   proto_register_field_array(proto_ascend, hf, array_length(hf));
153   proto_register_subtree_array(ett, array_length(ett));
154 }
155
156 void
157 proto_reg_handoff_ascend(void)
158 {
159   dissector_handle_t ascend_handle;
160
161   /*
162    * Get handles for the Ethernet and PPP-in-HDLC-like-framing dissectors.
163    */
164   eth_handle = find_dissector("eth");
165   ppp_hdlc_handle = find_dissector("ppp_hdlc");
166
167   ascend_handle = create_dissector_handle(dissect_ascend, proto_ascend);
168   dissector_add("wtap_encap", WTAP_ENCAP_ASCEND, ascend_handle);
169 }