Add sample strace output to illustrate the timeout problem.
[obnox/wireshark/wip.git] / packet-lapd.c
1 /* packet-lapd.c
2  * Routines for LAPD frame disassembly
3  * Gilbert Ramirez <gram@xiexie.org>
4  *
5  * $Id: packet-lapd.c,v 1.3 1999/11/16 11:42:37 guy Exp $
6  *
7  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@zing.org>
9  * Copyright 1998
10  *
11  * 
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  * 
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  * 
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34
35 #include <stdio.h>
36 #include <glib.h>
37 #include <string.h>
38 #include "packet.h"
39 #include "xdlc.h"
40
41 /* ISDN/LAPD references:
42  *
43  * http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/isdn.htm
44  * http://www.ece.wpi.edu/courses/ee535/hwk11cd95/agrebe/agrebe.html
45  * http://www.acacia-net.com/Clarinet/Protocol/q9213o84.htm
46  */
47
48 static int proto_lapd = -1;
49 static int hf_lapd_address = -1;
50 static int hf_lapd_sapi = -1;
51 static int hf_lapd_cr = -1;
52 static int hf_lapd_ea1 = -1;
53 static int hf_lapd_tei = -1;
54 static int hf_lapd_ea2 = -1;
55 static int hf_lapd_control = -1;
56
57 static gint ett_lapd = -1;
58 static gint ett_lapd_address = -1;
59 static gint ett_lapd_control = -1;
60
61 /*
62  * Bits in the address field.
63  */
64 #define LAPD_SAPI       0xfc00  /* Service Access Point Identifier */
65 #define LAPD_SAPI_SHIFT 10
66 #define LAPD_CR         0x0200  /* Command/Response bit */
67 #define LAPD_EA1        0x0100  /* First Address Extension bit */
68 #define LAPD_TEI        0x00fe  /* Terminal Endpoint Identifier */
69 #define LAPD_EA2        0x0001  /* Second Address Extension bit */
70
71 #define LAPD_SAPI_Q931          0       /* Q.931 call control procedure */
72 #define LAPD_SAPI_PM_Q931       1       /* Packet mode Q.931 call control procedure */
73 #define LAPD_SAPI_X25           16      /* X.25 Level 3 procedures */
74 #define LAPD_SAPI_L2            63      /* Layer 2 management procedures */
75
76 static const value_string lapd_sapi_vals[] = {
77         { LAPD_SAPI_Q931,       "Q.931 Call control procedure" },
78         { LAPD_SAPI_PM_Q931,    "Packet mode Q.931 Call control procedure" },
79         { LAPD_SAPI_X25,        "X.25 Level 3 procedures" },
80         { LAPD_SAPI_L2,         "Layer 2 management procedures" },
81         { 0,                    NULL }
82 };
83
84 void
85 dissect_lapd(const u_char *pd, frame_data *fd, proto_tree *tree)
86 {
87         proto_tree      *lapd_tree, *addr_tree;
88         proto_item      *ti;
89         guint16         control;
90         int             lapd_header_len;
91
92         guint16 address, cr, sapi;
93
94         gboolean is_response;
95
96         if (check_col(fd, COL_PROTOCOL))
97                 col_add_str(fd, COL_PROTOCOL, "LAPD");
98
99         address = pntohs(&pd[0]);
100         cr = address & LAPD_CR;
101         sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT;
102         lapd_header_len = 2;    /* address */
103
104         if (fd->pseudo_header.lapd.from_network_to_user) {
105                 is_response = cr ? FALSE : TRUE;
106                 if(check_col(fd, COL_RES_DL_DST))
107                     col_add_str(fd, COL_RES_DL_DST, "User");
108                 if(check_col(fd, COL_RES_DL_SRC))
109                     col_add_str(fd, COL_RES_DL_SRC, "Network");
110         }
111         else {
112                 is_response = cr ? TRUE : FALSE;
113                 if(check_col(fd, COL_RES_DL_DST))
114                         col_add_str(fd, COL_RES_DL_DST, "Network");
115                 if(check_col(fd, COL_RES_DL_SRC))
116                         col_add_str(fd, COL_RES_DL_SRC, "User");
117         }
118
119
120         if (tree) {
121                 ti = proto_tree_add_item(tree, proto_lapd, 0, 3, NULL);
122                 lapd_tree = proto_item_add_subtree(ti, ett_lapd);
123
124                 ti = proto_tree_add_item(lapd_tree, hf_lapd_address, 0, 2, address);
125                 addr_tree = proto_item_add_subtree(ti, ett_lapd_address);
126
127                 proto_tree_add_item(addr_tree, hf_lapd_sapi,    0, 1, address);
128                 proto_tree_add_item(addr_tree, hf_lapd_cr,      0, 1, address);
129                 proto_tree_add_item(addr_tree, hf_lapd_ea1,     0, 1, address);
130                 proto_tree_add_item(addr_tree, hf_lapd_tei,     1, 1, address);
131                 proto_tree_add_item(addr_tree, hf_lapd_ea2,     1, 1, address);
132         }
133         else {
134                 lapd_tree = NULL;
135         }
136
137         control = dissect_xdlc_control(pd, 2, fd, lapd_tree, hf_lapd_control,
138             ett_lapd_control, is_response, TRUE);
139         lapd_header_len += XDLC_CONTROL_LEN(control, TRUE);
140
141         if (XDLC_HAS_PAYLOAD(control)) {
142                 /* call next protocol */
143                 switch (sapi) {
144
145                 case LAPD_SAPI_Q931:
146                         dissect_q931(pd, lapd_header_len, fd, tree);
147                         break;
148
149                 default:
150                         dissect_data(pd, lapd_header_len, fd, tree);
151                         break;
152                 }
153         }
154 }
155
156 void
157 proto_register_lapd(void)
158 {
159     static hf_register_info hf[] = {
160         { &hf_lapd_address,
161           { "Address Field", "lapd.address", FT_UINT16, BASE_HEX, NULL, 0x0, 
162                 "" }},
163
164         { &hf_lapd_sapi,
165           { "SAPI", "lapd.sapi", FT_UINT16, BASE_DEC, VALS(lapd_sapi_vals), LAPD_SAPI,
166                 "Service Access Point Identifier" }},
167
168         { &hf_lapd_cr,
169           { "C/R", "lapd.cr", FT_UINT16, BASE_DEC, NULL, LAPD_CR,
170                 "Command/Response bit" }},
171
172         { &hf_lapd_ea1,
173           { "EA1", "lapd.ea1", FT_UINT16, BASE_DEC, NULL, LAPD_EA1,
174                 "First Address Extension bit" }},
175
176         { &hf_lapd_tei,
177           { "TEI", "lapd.tei", FT_UINT16, BASE_DEC, NULL, LAPD_TEI,
178                 "Terminal Endpoint Identifier" }},
179
180         { &hf_lapd_ea2,
181           { "EA2", "lapd.ea2", FT_UINT16, BASE_DEC, NULL, LAPD_EA2,
182                 "Second Address Extension bit" }},
183
184         { &hf_lapd_control,
185           { "Control Field", "lapd.control", FT_UINT16, BASE_HEX, NULL, 0x0,
186                 "" }},
187     };
188     static gint *ett[] = {
189         &ett_lapd,
190         &ett_lapd_address,
191         &ett_lapd_control,
192     };
193
194     proto_lapd = proto_register_protocol ("Link Access Procedure, Channel D (LAPD)", "lapd");
195     proto_register_field_array (proto_lapd, hf, array_length(hf));
196     proto_register_subtree_array(ett, array_length(ett));
197 }