Fix a couple (value) mistakes in value_strings. Found by Martin's patch on the ...
[obnox/wireshark/wip.git] / wiretap / atm.c
1 /* atm.c
2  *
3  * $Id$
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          
78         if (len >= 3) {
79                 if (pd[0] == 0xaa && pd[1] == 0xaa && pd[2] == 0x03) {
80                         /*
81                          * Looks like a SNAP header; assume it's LLC
82                          * multiplexed RFC 1483 traffic.
83                          */
84                         pseudo_header->atm.type = TRAF_LLCMX;
85                 } else if ((pseudo_header->atm.aal5t_len &&
86                         pseudo_header->atm.aal5t_len < 16) || len<16) {
87                         /*
88                          * As this cannot be a LANE Ethernet frame (less
89                          * than 2 bytes of LANE header + 14 bytes of
90                          * Ethernet header) we can try it as a SSCOP frame.
91                          */
92                         pseudo_header->atm.aal = AAL_SIGNALLING;
93                 } else if (pd[0] == 0x83 || pd[0] == 0x81) {
94                         /*
95                          * MTP3b headers often encapsulate
96                          * a SCCP or MTN in the 3G network.
97                          * This should cause 0x83 or 0x81
98                          * in the first byte.
99                          */
100                         pseudo_header->atm.aal = AAL_SIGNALLING;
101                 } else {
102                         /*
103                          * Assume it's LANE.
104                          */
105                         pseudo_header->atm.type = TRAF_LANE;
106                         atm_guess_lane_type(pd, len, pseudo_header);
107                 }
108         } else {
109                /*
110                 * Not only VCI 5 is used for signaling. It might be
111                 * one of these VCIs.
112                 */
113                pseudo_header->atm.aal = AAL_SIGNALLING;
114         }
115 }
116
117 void
118 atm_guess_lane_type(const guint8 *pd, guint32 len,
119     union wtap_pseudo_header *pseudo_header)
120 {
121         if (len >= 2) {
122                 if (pd[0] == 0xff && pd[1] == 0x00) {
123                         /*
124                          * Looks like LE Control traffic.
125                          */
126                         pseudo_header->atm.subtype = TRAF_ST_LANE_LE_CTRL;
127                 } else {
128                         /*
129                          * XXX - Ethernet, or Token Ring?
130                          * Assume Ethernet for now; if we see earlier
131                          * LANE traffic, we may be able to figure out
132                          * the traffic type from that, but there may
133                          * still be situations where the user has to
134                          * tell us.
135                          */
136                         pseudo_header->atm.subtype = TRAF_ST_LANE_802_3;
137                 }
138         }
139 }