1999-11-11 05:36:16 +00:00
|
|
|
/* packet-lapd.c
|
|
|
|
* Routines for LAPD frame disassembly
|
2001-11-13 23:55:44 +00:00
|
|
|
* Gilbert Ramirez <gram@alumni.rice.edu>
|
1999-11-11 05:36:16 +00:00
|
|
|
*
|
2002-01-21 07:37:49 +00:00
|
|
|
* $Id: packet-lapd.c,v 1.28 2002/01/21 07:36:36 guy Exp $
|
1999-11-11 05:36:16 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-05-27 07:27:21 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
1999-11-11 05:36:16 +00:00
|
|
|
* Copyright 1998
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
1999-11-11 05:36:16 +00:00
|
|
|
#include "xdlc.h"
|
|
|
|
|
|
|
|
/* ISDN/LAPD references:
|
|
|
|
*
|
|
|
|
* http://www.cisco.com/univercd/cc/td/doc/cisintwk/ito_doc/isdn.htm
|
|
|
|
* http://www.ece.wpi.edu/courses/ee535/hwk11cd95/agrebe/agrebe.html
|
|
|
|
* http://www.acacia-net.com/Clarinet/Protocol/q9213o84.htm
|
|
|
|
*/
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static int proto_lapd = -1;
|
|
|
|
static int hf_lapd_address = -1;
|
|
|
|
static int hf_lapd_sapi = -1;
|
|
|
|
static int hf_lapd_cr = -1;
|
|
|
|
static int hf_lapd_ea1 = -1;
|
|
|
|
static int hf_lapd_tei = -1;
|
|
|
|
static int hf_lapd_ea2 = -1;
|
|
|
|
static int hf_lapd_control = -1;
|
|
|
|
|
|
|
|
static gint ett_lapd = -1;
|
|
|
|
static gint ett_lapd_address = -1;
|
|
|
|
static gint ett_lapd_control = -1;
|
1999-11-11 05:36:16 +00:00
|
|
|
|
2001-05-27 07:27:21 +00:00
|
|
|
static dissector_handle_t q931_handle;
|
2001-11-25 22:51:14 +00:00
|
|
|
static dissector_handle_t data_handle;
|
2001-05-27 07:27:21 +00:00
|
|
|
|
1999-11-11 08:35:11 +00:00
|
|
|
/*
|
|
|
|
* Bits in the address field.
|
|
|
|
*/
|
|
|
|
#define LAPD_SAPI 0xfc00 /* Service Access Point Identifier */
|
|
|
|
#define LAPD_SAPI_SHIFT 10
|
|
|
|
#define LAPD_CR 0x0200 /* Command/Response bit */
|
|
|
|
#define LAPD_EA1 0x0100 /* First Address Extension bit */
|
|
|
|
#define LAPD_TEI 0x00fe /* Terminal Endpoint Identifier */
|
|
|
|
#define LAPD_EA2 0x0001 /* Second Address Extension bit */
|
|
|
|
|
|
|
|
#define LAPD_SAPI_Q931 0 /* Q.931 call control procedure */
|
|
|
|
#define LAPD_SAPI_PM_Q931 1 /* Packet mode Q.931 call control procedure */
|
|
|
|
#define LAPD_SAPI_X25 16 /* X.25 Level 3 procedures */
|
|
|
|
#define LAPD_SAPI_L2 63 /* Layer 2 management procedures */
|
|
|
|
|
1999-11-11 05:36:16 +00:00
|
|
|
static const value_string lapd_sapi_vals[] = {
|
1999-11-11 08:35:11 +00:00
|
|
|
{ LAPD_SAPI_Q931, "Q.931 Call control procedure" },
|
|
|
|
{ LAPD_SAPI_PM_Q931, "Packet mode Q.931 Call control procedure" },
|
|
|
|
{ LAPD_SAPI_X25, "X.25 Level 3 procedures" },
|
|
|
|
{ LAPD_SAPI_L2, "Layer 2 management procedures" },
|
|
|
|
{ 0, NULL }
|
1999-11-11 05:36:16 +00:00
|
|
|
};
|
|
|
|
|
2000-11-29 05:16:15 +00:00
|
|
|
static void
|
2000-05-31 03:58:56 +00:00
|
|
|
dissect_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
1999-11-11 05:36:16 +00:00
|
|
|
{
|
|
|
|
proto_tree *lapd_tree, *addr_tree;
|
|
|
|
proto_item *ti;
|
1999-11-11 08:35:11 +00:00
|
|
|
guint16 control;
|
|
|
|
int lapd_header_len;
|
2000-05-31 03:58:56 +00:00
|
|
|
guint16 address, cr, sapi;
|
|
|
|
gboolean is_response;
|
|
|
|
tvbuff_t *next_tvb;
|
1999-11-11 05:36:16 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "LAPD");
|
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
1999-11-11 05:36:16 +00:00
|
|
|
|
2000-05-31 03:58:56 +00:00
|
|
|
address = tvb_get_ntohs(tvb, 0);
|
1999-11-11 08:35:11 +00:00
|
|
|
cr = address & LAPD_CR;
|
|
|
|
sapi = (address & LAPD_SAPI) >> LAPD_SAPI_SHIFT;
|
|
|
|
lapd_header_len = 2; /* address */
|
1999-11-11 05:36:16 +00:00
|
|
|
|
2000-09-21 04:41:37 +00:00
|
|
|
if (pinfo->pseudo_header->p2p.sent) {
|
|
|
|
is_response = cr ? TRUE : FALSE;
|
2001-12-10 00:26:21 +00:00
|
|
|
if(check_col(pinfo->cinfo, COL_RES_DL_DST))
|
|
|
|
col_set_str(pinfo->cinfo, COL_RES_DL_DST, "Network");
|
|
|
|
if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
|
|
|
|
col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "User");
|
1999-11-11 05:36:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-09-21 04:41:37 +00:00
|
|
|
is_response = cr ? FALSE : TRUE;
|
2001-12-10 00:26:21 +00:00
|
|
|
if(check_col(pinfo->cinfo, COL_RES_DL_DST))
|
|
|
|
col_set_str(pinfo->cinfo, COL_RES_DL_DST, "User");
|
|
|
|
if(check_col(pinfo->cinfo, COL_RES_DL_SRC))
|
|
|
|
col_set_str(pinfo->cinfo, COL_RES_DL_SRC, "Network");
|
1999-11-11 05:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
2000-05-31 05:09:07 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_lapd, tvb, 0, 3, FALSE);
|
1999-11-16 11:44:20 +00:00
|
|
|
lapd_tree = proto_item_add_subtree(ti, ett_lapd);
|
1999-11-11 05:36:16 +00:00
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
ti = proto_tree_add_uint(lapd_tree, hf_lapd_address, tvb, 0, 2, address);
|
1999-11-16 11:44:20 +00:00
|
|
|
addr_tree = proto_item_add_subtree(ti, ett_lapd_address);
|
1999-11-11 05:36:16 +00:00
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
proto_tree_add_uint(addr_tree, hf_lapd_sapi,tvb, 0, 1, address);
|
|
|
|
proto_tree_add_uint(addr_tree, hf_lapd_cr, tvb, 0, 1, address);
|
|
|
|
proto_tree_add_uint(addr_tree, hf_lapd_ea1, tvb, 0, 1, address);
|
|
|
|
proto_tree_add_uint(addr_tree, hf_lapd_tei, tvb, 1, 1, address);
|
|
|
|
proto_tree_add_uint(addr_tree, hf_lapd_ea2, tvb, 1, 1, address);
|
1999-11-11 05:36:16 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lapd_tree = NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-31 03:58:56 +00:00
|
|
|
control = dissect_xdlc_control(tvb, 2, pinfo, lapd_tree, hf_lapd_control,
|
1999-11-16 11:44:20 +00:00
|
|
|
ett_lapd_control, is_response, TRUE);
|
1999-11-11 08:35:11 +00:00
|
|
|
lapd_header_len += XDLC_CONTROL_LEN(control, TRUE);
|
|
|
|
|
2000-05-31 03:58:56 +00:00
|
|
|
next_tvb = tvb_new_subset(tvb, lapd_header_len, -1, -1);
|
2000-01-24 02:05:39 +00:00
|
|
|
if (XDLC_IS_INFORMATION(control)) {
|
1999-11-11 08:35:11 +00:00
|
|
|
/* call next protocol */
|
|
|
|
switch (sapi) {
|
1999-11-11 05:36:16 +00:00
|
|
|
|
1999-11-11 08:35:11 +00:00
|
|
|
case LAPD_SAPI_Q931:
|
2001-05-27 07:27:21 +00:00
|
|
|
call_dissector(q931_handle, next_tvb, pinfo, tree);
|
1999-11-11 08:35:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-11-25 22:51:14 +00:00
|
|
|
call_dissector(data_handle,next_tvb, pinfo, tree);
|
1999-11-11 08:35:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-01-24 02:05:39 +00:00
|
|
|
} else
|
2001-11-25 22:51:14 +00:00
|
|
|
call_dissector(data_handle,next_tvb, pinfo, tree);
|
1999-11-11 05:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_lapd(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_lapd_address,
|
|
|
|
{ "Address Field", "lapd.address", FT_UINT16, BASE_HEX, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Address", HFILL }},
|
1999-11-11 05:36:16 +00:00
|
|
|
|
|
|
|
{ &hf_lapd_sapi,
|
1999-11-11 08:35:11 +00:00
|
|
|
{ "SAPI", "lapd.sapi", FT_UINT16, BASE_DEC, VALS(lapd_sapi_vals), LAPD_SAPI,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Service Access Point Identifier", HFILL }},
|
1999-11-11 05:36:16 +00:00
|
|
|
|
|
|
|
{ &hf_lapd_cr,
|
1999-11-11 08:35:11 +00:00
|
|
|
{ "C/R", "lapd.cr", FT_UINT16, BASE_DEC, NULL, LAPD_CR,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Command/Response bit", HFILL }},
|
1999-11-11 05:36:16 +00:00
|
|
|
|
|
|
|
{ &hf_lapd_ea1,
|
1999-11-11 08:35:11 +00:00
|
|
|
{ "EA1", "lapd.ea1", FT_UINT16, BASE_DEC, NULL, LAPD_EA1,
|
2001-06-18 02:18:27 +00:00
|
|
|
"First Address Extension bit", HFILL }},
|
1999-11-11 05:36:16 +00:00
|
|
|
|
|
|
|
{ &hf_lapd_tei,
|
1999-11-11 08:35:11 +00:00
|
|
|
{ "TEI", "lapd.tei", FT_UINT16, BASE_DEC, NULL, LAPD_TEI,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Terminal Endpoint Identifier", HFILL }},
|
1999-11-11 05:36:16 +00:00
|
|
|
|
|
|
|
{ &hf_lapd_ea2,
|
1999-11-11 08:35:11 +00:00
|
|
|
{ "EA2", "lapd.ea2", FT_UINT16, BASE_DEC, NULL, LAPD_EA2,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Second Address Extension bit", HFILL }},
|
1999-11-11 05:36:16 +00:00
|
|
|
|
|
|
|
{ &hf_lapd_control,
|
|
|
|
{ "Control Field", "lapd.control", FT_UINT16, BASE_HEX, NULL, 0x0,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Control field", HFILL }},
|
1999-11-11 05:36:16 +00:00
|
|
|
};
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_lapd,
|
|
|
|
&ett_lapd_address,
|
|
|
|
&ett_lapd_control,
|
|
|
|
};
|
1999-11-11 05:36:16 +00:00
|
|
|
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_lapd = proto_register_protocol("Link Access Procedure, Channel D (LAPD)",
|
|
|
|
"LAPD", "lapd");
|
1999-11-11 05:36:16 +00:00
|
|
|
proto_register_field_array (proto_lapd, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
1999-11-11 05:36:16 +00:00
|
|
|
}
|
2000-11-29 05:16:15 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_lapd(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t lapd_handle;
|
|
|
|
|
2001-05-27 07:27:21 +00:00
|
|
|
/*
|
|
|
|
* Get handle for the Q.931 dissector.
|
|
|
|
*/
|
|
|
|
q931_handle = find_dissector("q931");
|
2001-11-25 22:51:14 +00:00
|
|
|
data_handle = find_dissector("data");
|
2001-05-27 07:27:21 +00:00
|
|
|
|
2001-12-03 04:00:26 +00:00
|
|
|
lapd_handle = create_dissector_handle(dissect_lapd, proto_lapd);
|
|
|
|
dissector_add("wtap_encap", WTAP_ENCAP_LAPD, lapd_handle);
|
2000-11-29 05:16:15 +00:00
|
|
|
}
|