smb-direct fragmentation
[metze/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24 #include "wtap-int.h"
25 #include "atm.h"
26
27 /*
28  * Routines to use with ATM capture file types that don't include information
29  * about the *type* of ATM traffic (or, at least, where we haven't found
30  * that information).
31  *
32  * We assume the traffic is AAL5, unless it's VPI 0/VCI 5, in which case
33  * we assume it's the signalling AAL.
34  */
35
36 void
37 atm_guess_traffic_type(const guint8 *pd, guint32 len,
38     union wtap_pseudo_header *pseudo_header)
39 {
40         /*
41          * Start out assuming nothing other than that it's AAL5.
42          */
43         pseudo_header->atm.aal = AAL_5;
44         pseudo_header->atm.type = TRAF_UNKNOWN;
45         pseudo_header->atm.subtype = TRAF_ST_UNKNOWN;
46
47         if (pseudo_header->atm.vpi == 0) {
48                 /*
49                  * Traffic on some PVCs with a VPI of 0 and certain
50                  * VCIs is of particular types.
51                  */
52                 switch (pseudo_header->atm.vci) {
53
54                 case 5:
55                         /*
56                          * Signalling AAL.
57                          */
58                         pseudo_header->atm.aal = AAL_SIGNALLING;
59                         return;
60
61                 case 16:
62                         /*
63                          * ILMI.
64                          */
65                         pseudo_header->atm.type = TRAF_ILMI;
66                         return;
67                 }
68         }
69
70         /*
71          * OK, we can't tell what it is based on the VPI/VCI; try
72          * guessing based on the contents, if we have enough data
73          * to guess.
74          */
75
76         if (len >= 3) {
77                 if (pd[0] == 0xaa && pd[1] == 0xaa && pd[2] == 0x03) {
78                         /*
79                          * Looks like a SNAP header; assume it's LLC
80                          * multiplexed RFC 1483 traffic.
81                          */
82                         pseudo_header->atm.type = TRAF_LLCMX;
83                 } else if ((pseudo_header->atm.aal5t_len &&
84                         pseudo_header->atm.aal5t_len < 16) || len<16) {
85                         /*
86                          * As this cannot be a LANE Ethernet frame (less
87                          * than 2 bytes of LANE header + 14 bytes of
88                          * Ethernet header) we can try it as a SSCOP frame.
89                          */
90                         pseudo_header->atm.aal = AAL_SIGNALLING;
91                 } else if (pd[0] == 0x83 || pd[0] == 0x81) {
92                         /*
93                          * MTP3b headers often encapsulate
94                          * a SCCP or MTN in the 3G network.
95                          * This should cause 0x83 or 0x81
96                          * in the first byte.
97                          */
98                         pseudo_header->atm.aal = AAL_SIGNALLING;
99                 } else {
100                         /*
101                          * Assume it's LANE.
102                          */
103                         pseudo_header->atm.type = TRAF_LANE;
104                         atm_guess_lane_type(pd, len, pseudo_header);
105                 }
106         } else {
107                /*
108                 * Not only VCI 5 is used for signaling. It might be
109                 * one of these VCIs.
110                 */
111                pseudo_header->atm.aal = AAL_SIGNALLING;
112         }
113 }
114
115 void
116 atm_guess_lane_type(const guint8 *pd, guint32 len,
117     union wtap_pseudo_header *pseudo_header)
118 {
119         if (len >= 2) {
120                 if (pd[0] == 0xff && pd[1] == 0x00) {
121                         /*
122                          * Looks like LE Control traffic.
123                          */
124                         pseudo_header->atm.subtype = TRAF_ST_LANE_LE_CTRL;
125                 } else {
126                         /*
127                          * XXX - Ethernet, or Token Ring?
128                          * Assume Ethernet for now; if we see earlier
129                          * LANE traffic, we may be able to figure out
130                          * the traffic type from that, but there may
131                          * still be situations where the user has to
132                          * tell us.
133                          */
134                         pseudo_header->atm.subtype = TRAF_ST_LANE_802_3;
135                 }
136         }
137 }