cf95f14d1d0e280f251d496c280b939c40168708
[obnox/wireshark/wip.git] / wiretap / atm.c
1 /* atm.c
2  *
3  * $Id: atm.c,v 1.2 2002/08/13 03:32:56 guy Exp $
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
7  * 
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include "wtap-int.h"
27 #include "atm.h"
28
29 /*
30  * Routines to use with ATM capture file types that don't include information
31  * about the *type* of ATM traffic (or, at least, where we haven't found
32  * that information).
33  *
34  * We assume the traffic is AAL5, unless it's VPI 0/VCI 5, in which case
35  * we assume it's the signalling AAL.
36  */
37
38 void
39 atm_guess_traffic_type(const guint8 *pd, guint32 len,
40     union wtap_pseudo_header *pseudo_header)
41 {
42         /*
43          * Start out assuming nothing other than that it's AAL5.
44          */
45         pseudo_header->atm.aal = AAL_5;
46         pseudo_header->atm.type = TRAF_UNKNOWN;
47         pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
48
49         if (pseudo_header->atm.vpi == 0) {
50                 /*
51                  * Traffic on some PVCs with a VPI of 0 and certain
52                  * VCIs is of particular types.
53                  */
54                 switch (pseudo_header->atm.vci) {
55
56                 case 5:
57                         /*
58                          * Signalling AAL.
59                          */
60                         pseudo_header->atm.aal = AAL_SIGNALLING;
61                         return;
62
63                 case 16:
64                         /*
65                          * ILMI.
66                          */
67                         pseudo_header->atm.type = TRAF_ILMI;
68                         return;
69                 }
70         }
71
72         /*
73          * OK, we can't tell what it is based on the VPI/VCI; try
74          * guessing based on the contents, if we have enough data
75          * to guess.
76          */
77         if (len >= 3) {
78                 if (pd[0] == 0xaa && pd[1] == 0xaa && pd[2] == 0x03) {
79                         /*
80                          * Looks like a SNAP header; assume it's LLC
81                          * multiplexed RFC 1483 traffic.
82                          */
83                         pseudo_header->atm.type = TRAF_LLCMX;
84                 } else {
85                         /*
86                          * Assume it's LANE.
87                          */
88                         pseudo_header->atm.type = TRAF_LANE;
89                         atm_guess_lane_type(pd, len, pseudo_header);
90                 }
91         }
92 }
93
94 void
95 atm_guess_lane_type(const guint8 *pd, guint32 len,
96     union wtap_pseudo_header *pseudo_header)
97 {
98         if (len >= 2) {
99                 if (pd[0] == 0xff && pd[1] == 0x00) {
100                         /*
101                          * Looks like LE Control traffic.
102                          */
103                         pseudo_header->atm.subtype = TRAF_ST_LANE_LE_CTRL;
104                 } else {
105                         /*
106                          * XXX - Ethernet, or Token Ring?
107                          * Assume Ethernet for now; if we see earlier
108                          * LANE traffic, we may be able to figure out
109                          * the traffic type from that, but there may
110                          * still be situations where the user has to
111                          * tell us.
112                          */
113                         pseudo_header->atm.subtype = TRAF_ST_LANE_802_3;
114                 }
115         }
116 }