/src/wireshark/wiretap/netxray.c
Line | Count | Source |
1 | | /* netxray.c |
2 | | * |
3 | | * Wiretap Library |
4 | | * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu> |
5 | | * |
6 | | * SPDX-License-Identifier: GPL-2.0-or-later |
7 | | */ |
8 | | |
9 | | #include "config.h" |
10 | | #include "netxray.h" |
11 | | |
12 | | #include <string.h> |
13 | | |
14 | | #include <wsutil/array.h> |
15 | | #include <wsutil/pint.h> |
16 | | |
17 | | #include "wtap_module.h" |
18 | | #include "file_wrappers.h" |
19 | | #include "atm.h" |
20 | | |
21 | | /* |
22 | | * Sniffer Basic (NetXRay)/Windows Sniffer Pro |
23 | | * |
24 | | * Network Associates' Sniffer Basic (formerly NetXRay from Cinco Networks) |
25 | | * file format is now supported, at least for Ethernet and token-ring. |
26 | | * Network Associates' Windows Sniffer Pro appears to use a variant of that |
27 | | * format; it's supported to the same extent. |
28 | | */ |
29 | | |
30 | | /* Capture file header, *including* magic number, is padded to 128 bytes. */ |
31 | 0 | #define CAPTUREFILE_HEADER_SIZE 128 |
32 | | |
33 | | /* Magic number size, in both 1.x and later files. */ |
34 | 0 | #define MAGIC_SIZE 4 |
35 | | |
36 | | /* Magic number in NetXRay 1.x files. */ |
37 | | static const char old_netxray_magic[MAGIC_SIZE] = { |
38 | | 'V', 'L', '\0', '\0' |
39 | | }; |
40 | | |
41 | | /* Magic number in NetXRay 2.0 and later, and Windows Sniffer, files. */ |
42 | | static const char netxray_magic[MAGIC_SIZE] = { |
43 | | 'X', 'C', 'P', '\0' |
44 | | }; |
45 | | |
46 | | /* NetXRay file header (minus magic number). */ |
47 | | /* */ |
48 | | /* As field usages are identified, please revise as needed */ |
49 | | /* Please do *not* use netxray_hdr xxx... names in the code */ |
50 | | /* (Placeholder names for all 'unknown' fields are */ |
51 | | /* of form xxx_x<hex_hdr_offset> */ |
52 | | /* where <hex_hdr_offset> *includes* the magic number) */ |
53 | | |
54 | | struct netxray_hdr { |
55 | | char version[8]; /* version number */ |
56 | | uint32_t start_time; /* UNIX [UTC] time when capture started */ |
57 | | |
58 | | uint32_t nframes; /* number of packets */ |
59 | | uint32_t xxx_x14; /* unknown [some kind of file offset] */ |
60 | | uint32_t start_offset; /* offset of first packet in capture */ |
61 | | uint32_t end_offset; /* offset after last packet in capture */ |
62 | | |
63 | | uint32_t xxx_x20; /* unknown [some kind of file offset] */ |
64 | | uint32_t xxx_x24; /* unknown [unused ?] */ |
65 | | uint32_t xxx_x28; /* unknown [some kind of file offset] */ |
66 | | uint8_t network; /* datalink type */ |
67 | | uint8_t network_plus; /* [See code] */ |
68 | | uint8_t xxx_x2E[2]; /* unknown */ |
69 | | |
70 | | uint8_t timeunit; /* encodes length of a tick */ |
71 | | uint8_t xxx_x31[3]; /* XXX - upper 3 bytes of timeunit ? */ |
72 | | uint32_t timelo; /* lower 32 bits of capture start time stamp */ |
73 | | uint32_t timehi; /* upper 32 bits of capture start time stamp */ |
74 | | uint32_t linespeed; /* speed of network, in bits/second */ |
75 | | |
76 | | uint8_t xxx_x40[12]; /* unknown [other stuff] */ |
77 | | uint8_t realtick[4]; /* (ticks/sec for Ethernet/Ndis/Timeunit=2 ?) */ |
78 | | /* (realtick[1], realtick[2] also currently */ |
79 | | /* used as flag for 'FCS presence') */ |
80 | | |
81 | | uint8_t xxx_x50[4]; /* unknown [other stuff] */ |
82 | | uint8_t captype; /* capture type */ |
83 | | uint8_t xxx_x55[3]; /* unknown [other stuff] */ |
84 | | uint8_t xxx_x58[4]; /* unknown [other stuff] */ |
85 | | uint8_t wan_hdlc_subsub_captype; /* WAN HDLC subsub_captype */ |
86 | | uint8_t xxx_x5D[3]; /* unknown [other stuff] */ |
87 | | |
88 | | uint8_t xxx_x60[16]; /* unknown [other stuff] */ |
89 | | |
90 | | uint8_t xxx_x70[14]; /* unknown [other stuff] */ |
91 | | int16_t timezone_hrs; /* timezone hours [at least for version 2.2..]; */ |
92 | | /* positive values = west of UTC: */ |
93 | | /* negative values = east of UTC: */ |
94 | | /* e.g. +5 is American Eastern */ |
95 | | /* [Does not appear to be adjusted for DST ] */ |
96 | | }; |
97 | | |
98 | | /* |
99 | | * Capture type, in hdr.captype. |
100 | | * |
101 | | * Values other than 0 are dependent on the network type. |
102 | | * For Ethernet captures, it indicates the type of capture pod. |
103 | | * For WAN captures (all of which are done with a pod), it indicates |
104 | | * the link-layer type. |
105 | | */ |
106 | 0 | #define CAPTYPE_NDIS 0 /* Capture on network interface using NDIS */ |
107 | | |
108 | | /* |
109 | | * Ethernet capture types. |
110 | | */ |
111 | 0 | #define ETH_CAPTYPE_GIGPOD 2 /* gigabit Ethernet captured with pod */ |
112 | 0 | #define ETH_CAPTYPE_OTHERPOD 3 /* non-gigabit Ethernet captured with pod */ |
113 | 0 | #define ETH_CAPTYPE_OTHERPOD2 5 /* gigabit Ethernet via pod ?? */ |
114 | | /* Captype 5 seen in capture from Distributed Sniffer with: */ |
115 | | /* Version 4.50.211 software */ |
116 | | /* SysKonnect SK-9843 Gigabit Ethernet Server Adapter */ |
117 | 0 | #define ETH_CAPTYPE_GIGPOD2 6 /* gigabit Ethernet, captured with blade on S6040-model Sniffer */ |
118 | | |
119 | | /* |
120 | | * WAN capture types. |
121 | | */ |
122 | | #define WAN_CAPTYPE_BROUTER 1 /* Bridge/router captured with pod */ |
123 | 0 | #define WAN_CAPTYPE_PPP 3 /* PPP captured with pod */ |
124 | 0 | #define WAN_CAPTYPE_FRELAY 4 /* Frame Relay captured with pod */ |
125 | | #define WAN_CAPTYPE_BROUTER2 5 /* Bridge/router captured with pod */ |
126 | 0 | #define WAN_CAPTYPE_HDLC 6 /* HDLC (X.25, ISDN) captured with pod */ |
127 | 0 | #define WAN_CAPTYPE_SDLC 7 /* SDLC captured with pod */ |
128 | 0 | #define WAN_CAPTYPE_HDLC2 8 /* HDLC captured with pod */ |
129 | | #define WAN_CAPTYPE_BROUTER3 9 /* Bridge/router captured with pod */ |
130 | | #define WAN_CAPTYPE_SMDS 10 /* SMDS DXI */ |
131 | | #define WAN_CAPTYPE_BROUTER4 11 /* Bridge/router captured with pod */ |
132 | | #define WAN_CAPTYPE_BROUTER5 12 /* Bridge/router captured with pod */ |
133 | 0 | #define WAN_CAPTYPE_CHDLC 19 /* Cisco router (CHDLC) captured with pod */ |
134 | | |
135 | | #define CAPTYPE_ATM 15 /* ATM captured with pod */ |
136 | | |
137 | | /* |
138 | | * # of ticks that equal 1 second, in version 002.xxx files other |
139 | | * than Ethernet captures with a captype other than CAPTYPE_NDIS; |
140 | | * the index into this array is hdr.timeunit. |
141 | | * |
142 | | * DO NOT SEND IN PATCHES THAT CHANGE ANY OF THE NON-ZERO VALUES IN |
143 | | * ANY OF THE TpS TABLES. THOSE VALUES ARE CORRECT FOR AT LEAST ONE |
144 | | * CAPTURE, SO CHANGING THEM WILL BREAK AT LEAST SOME CAPTURES. WE |
145 | | * WILL NOT CHECK IN PATCHES THAT CHANGE THESE VALUES. |
146 | | * |
147 | | * Instead, if a value in a TpS table is wrong, check whether captype |
148 | | * has a non-zero value; if so, perhaps we need a new TpS table for the |
149 | | * corresponding network type and captype, or perhaps the 'realtick' |
150 | | * field contains the correct ticks-per-second value. |
151 | | * |
152 | | * TpS...[] entries of 0.0 mean that no capture file for the |
153 | | * corresponding captype/timeunit values has yet been seen, or that |
154 | | * we're using the 'realtick' value. |
155 | | * |
156 | | * XXX - 05/29/07: For Ethernet captype = 0 (NDIS) and timeunit = 2: |
157 | | * Perusal of a number of Sniffer captures |
158 | | * (including those from Wireshark bug reports |
159 | | * and those from the Wireshark 'menagerie') |
160 | | * suggests that 'realtick' for this case |
161 | | * contains the correct ticks/second to be used. |
162 | | * So: we'll use realtick for Ethernet captype=0 and timeunit=2. |
163 | | * (It might be that realtick should be used for Ethernet captype = 0 |
164 | | * and timeunit = 1 but I've not yet enough captures to be sure). |
165 | | * Based upon the captures reviewed to date, realtick cannot be used for |
166 | | * any of the other Ethernet captype/timeunit combinations for which there |
167 | | * are non-zero values in the TpS tables. |
168 | | * |
169 | | * In at least one capture where "realtick" doesn't correspond |
170 | | * to the value from the appropriate TpS table, the per-packet header's |
171 | | * "xxx" field is all zero, so it's not as if a 2.x header includes |
172 | | * a "compatibility" time stamp corresponding to the value from the |
173 | | * TpS table and a "real" time stamp corresponding to "realtick". |
174 | | * |
175 | | * XXX - the item corresponding to timeunit = 2 is 1193180.0, presumably |
176 | | * because somebody found it gave the right answer for some captures, but |
177 | | * 3 times that, i.e. 3579540.0, appears to give the right answer for some |
178 | | * other captures. |
179 | | * |
180 | | * Some captures have realtick of 1193182, some have 3579545, and some |
181 | | * have 1193000. Most of those, in one set of captures somebody has, |
182 | | * are wrong. (Did that mean "wrong for some capture files, but not |
183 | | * for the files in which they occurred", or "wrong for the files in |
184 | | * which they occurred? If it's "wrong for some capture files, but |
185 | | * not for the files in which they occurred", perhaps those were Ethernet |
186 | | * captures with a captype of 0 and timeunit = 2, so that we now use |
187 | | * realtick, and perhaps that fixes the problems.) |
188 | | * |
189 | | * XXX - in at least one ATM capture, hdr.realtick is 1193180.0 |
190 | | * and hdr.timeunit is 0. Does that capture have a captype of |
191 | | * CAPTYPE_ATM? If so, what should the table for ATM captures with |
192 | | * that captype be? |
193 | | */ |
194 | | static const double TpS[] = { 1e6, 1193000.0, 1193182.0 }; |
195 | 0 | #define NUM_NETXRAY_TIMEUNITS array_length(TpS) |
196 | | |
197 | | /* |
198 | | * Table of time units for Ethernet captures with captype ETH_CAPTYPE_GIGPOD. |
199 | | * 0.0 means "unknown". |
200 | | * |
201 | | * It appears that, at least for Ethernet captures, if captype is |
202 | | * ETH_CAPTYPE_GIGPOD, that indicates that it's a gigabit Ethernet |
203 | | * capture, possibly from a special whizzo gigabit pod, and also |
204 | | * indicates that the time stamps have some higher resolution than |
205 | | * in other captures, possibly thanks to a high-resolution timer |
206 | | * on the pod. |
207 | | * |
208 | | * It also appears that the time units might differ for gigabit pod |
209 | | * captures between version 002.001 and 002.002. For 002.001, |
210 | | * the values below are correct; for 002.002, it's claimed that |
211 | | * the right value for TpS_gigpod[2] is 1250000.0, but at least one |
212 | | * 002.002 gigabit pod capture has 31250000.0 as the right value. |
213 | | * XXX: Note that the TpS_otherpod[2] value is 1250000.0; It seems |
214 | | * reasonable to suspect that the original claim might actually |
215 | | * have been for a capture with a captype of 'otherpod'. |
216 | | * (Based upon captures reviewed realtick does not contain the |
217 | | * correct TpS values for the 'gigpod' captype). |
218 | | */ |
219 | | static const double TpS_gigpod[] = { 1e9, 0.0, 31250000.0 }; |
220 | 0 | #define NUM_NETXRAY_TIMEUNITS_GIGPOD array_length(TpS_gigpod) |
221 | | |
222 | | /* |
223 | | * Table of time units for Ethernet captures with captype ETH_CAPTYPE_OTHERPOD. |
224 | | * (Based upon captures reviewed realtick does not contain the |
225 | | * correct TpS values for the 'otherpod' captype). |
226 | | */ |
227 | | static const double TpS_otherpod[] = { 1e6, 0.0, 1250000.0 }; |
228 | 0 | #define NUM_NETXRAY_TIMEUNITS_OTHERPOD array_length(TpS_otherpod) |
229 | | |
230 | | /* |
231 | | * Table of time units for Ethernet captures with captype ETH_CAPTYPE_OTHERPOD2. |
232 | | * (Based upon captures reviewed realtick does not contain the |
233 | | * correct TpS values for the 'otherpod2' captype). |
234 | | */ |
235 | | static const double TpS_otherpod2[] = { 1e6, 0.0, 0.0 }; |
236 | 0 | #define NUM_NETXRAY_TIMEUNITS_OTHERPOD2 array_length(TpS_otherpod2) |
237 | | |
238 | | /* |
239 | | * Table of time units for Ethernet captures with captype ETH_CAPTYPE_GIGPOD2. |
240 | | * (Based upon captures reviewed realtick does not contain the |
241 | | * correct TpS values for the 'gigpod2' captype). |
242 | | */ |
243 | | static const double TpS_gigpod2[] = { 1e9, 0.0, 20000000.0 }; |
244 | 0 | #define NUM_NETXRAY_TIMEUNITS_GIGPOD2 array_length(TpS_gigpod2) |
245 | | |
246 | | /* Version number strings. */ |
247 | | static const char vers_1_0[] = { |
248 | | '0', '0', '1', '.', '0', '0', '0', '\0' |
249 | | }; |
250 | | |
251 | | static const char vers_1_1[] = { |
252 | | '0', '0', '1', '.', '1', '0', '0', '\0' |
253 | | }; |
254 | | |
255 | | static const char vers_2_000[] = { |
256 | | '0', '0', '2', '.', '0', '0', '0', '\0' |
257 | | }; |
258 | | |
259 | | static const char vers_2_001[] = { |
260 | | '0', '0', '2', '.', '0', '0', '1', '\0' |
261 | | }; |
262 | | |
263 | | static const char vers_2_002[] = { |
264 | | '0', '0', '2', '.', '0', '0', '2', '\0' |
265 | | }; |
266 | | |
267 | | static const char vers_2_003[] = { |
268 | | '0', '0', '2', '.', '0', '0', '3', '\0' |
269 | | }; |
270 | | |
271 | | /* Old NetXRay data record format - followed by frame data. */ |
272 | | struct old_netxrayrec_hdr { |
273 | | uint32_t timelo; /* lower 32 bits of time stamp */ |
274 | | uint32_t timehi; /* upper 32 bits of time stamp */ |
275 | | uint16_t len; /* packet length */ |
276 | | uint8_t xxx[6]; /* unknown */ |
277 | | }; |
278 | | |
279 | | /* NetXRay format version 1.x data record format - followed by frame data. */ |
280 | | struct netxrayrec_1_x_hdr { |
281 | | uint32_t timelo; /* lower 32 bits of time stamp */ |
282 | | uint32_t timehi; /* upper 32 bits of time stamp */ |
283 | | uint16_t orig_len; /* packet length */ |
284 | | uint16_t incl_len; /* capture length */ |
285 | | uint8_t xxx[16]; /* unknown */ |
286 | | }; |
287 | | |
288 | | /* |
289 | | * NetXRay format version 2.x data record format - followed by frame data. |
290 | | * |
291 | | * The xxx fields appear to be: |
292 | | * |
293 | | * xxx[0]: ATM traffic type and subtype in the low 3 bits of |
294 | | * each nibble, and flags(?) in the upper bit of each nibble. |
295 | | * Always 0 for 802.11? |
296 | | * |
297 | | * xxx[1]: Always 0 for 802.11? |
298 | | * |
299 | | * xxx[2], xxx[3]: for Ethernet, 802.11, ISDN LAPD, LAPB, |
300 | | * Frame Relay, if both are 0xff, there are 4 bytes of stuff |
301 | | * at the end of the packet data, which might be an FCS or |
302 | | * which might be junk to discard. |
303 | | * |
304 | | * xxx[4-7]: Always 0 for 802.11? |
305 | | * |
306 | | * xxx[8], xxx[9]: 2 bytes of a flag word? If treated as |
307 | | * a 2-byte little-endian flag word: |
308 | | * |
309 | | * 0x0001: Error of some sort, including bad CRC, although |
310 | | * in one ISDN capture it's set in some B2 channel |
311 | | * packets of unknown content (as opposed to the B1 |
312 | | * traffic in the capture, which is PPP) |
313 | | * 0x0002: Seen in 802.11 - short preamble? Bad CRC? |
314 | | * 0x0004: Some particular type of error? |
315 | | * 0x0008: For (Gigabit?) Ethernet (with special probe?), |
316 | | * 4 bytes at end are junk rather than CRC? |
317 | | * 0x0100: CRC error on ATM? Protected and Not decrypted |
318 | | * for 802.11? Bad CRC? Short preamble? |
319 | | * 0x0200: Something for ATM? Something else for 802.11? |
320 | | * 0x0400: raw ATM cell |
321 | | * 0x0800: OAM cell? |
322 | | * 0x2000: port on which the packet was captured? |
323 | | * |
324 | | * The Sniffer Portable 4.8 User's Guide lists a set of packet status |
325 | | * flags including: |
326 | | * |
327 | | * packet is marked; |
328 | | * packet was captured from Port A on the pod or adapter card; |
329 | | * packet was captured from Port B on the pod or adapter card; |
330 | | * packet has a symptom or diagnosis associated with it; |
331 | | * packet is an event filter trigger; |
332 | | * CRC error packet with normal packet size; |
333 | | * CRC error packet with oversize error; |
334 | | * packet size < 64 bytes (including CRC) but with valid CRC; |
335 | | * packet size < 64 bytes (including CRC) with CRC error; |
336 | | * packet size > 1518 bytes (including CRC) but with valid CRC; |
337 | | * packet damaged by a collision; |
338 | | * packet length not a multiple of 8 bits; |
339 | | * address conflict in the ring on Token Ring; |
340 | | * packet is not copied (received) by the destination host on |
341 | | * Token Ring; |
342 | | * AAL5 length error; |
343 | | * AAL5 maximum segments error; |
344 | | * ATM timeout error; |
345 | | * ATM buffer error; |
346 | | * ATM unknown error; |
347 | | * and a ton of AAL2 errors. |
348 | | * |
349 | | * Not all those bits necessarily correspond to flag bits in the file, |
350 | | * but some might. |
351 | | * |
352 | | * In one ATM capture, the 0x2000 bit was set for all frames; in another, |
353 | | * it's unset for all frames. This, plus the ATMbook having two ports, |
354 | | * suggests that it *might* be a "port A vs. port B" flag. |
355 | | * |
356 | | * The 0x0001 bit appears to be set for CRC errors on Ethernet and 802.11. |
357 | | * It also appears to be set on ATM for AAL5 PDUs that appear to be |
358 | | * completely reassembled and that have a CRC error and for frames that |
359 | | * appear to be part of a full AAL5 PDU. In at least two files with |
360 | | * frames of the former type, the 0x0100 and 0x0200 flags are set; |
361 | | * in at least one file with frames of the latter type, neither of |
362 | | * those flags are set. |
363 | | * |
364 | | * The field appears to be somewhat random in some captures, |
365 | | * however. |
366 | | * |
367 | | * xxx[10]: for 802.11, always 0? |
368 | | * |
369 | | * xxx[11]: for 802.11, 0x05 if the packet is WEP-encrypted(?). |
370 | | * |
371 | | * xxx[12]: for 802.11, channel number. |
372 | | * |
373 | | * xxx[13]: for 802.11, data rate, in 500 Kb/s units. |
374 | | * |
375 | | * xxx[14]: for 802.11, signal strength. |
376 | | * |
377 | | * xxx[15]: for 802.11, noise level; 0xFF means none reported, |
378 | | * 0x7F means 100%. |
379 | | * |
380 | | * xxx[16-19]: for 802.11, PHY header, at least for {HR/}DSSS, |
381 | | * in at least one capture. |
382 | | * In another capture, xxx[16] appears to be the |
383 | | * data rate in 500 Kb/s units |
384 | | * Chip-dependent stuff? |
385 | | * |
386 | | * xxx[20-25]: for 802.11, MAC address of sending machine(?). |
387 | | * |
388 | | * xxx[26]: for 802.11, one of 0x00, 0x01, 0x03, or 0x0b? |
389 | | * |
390 | | * xxx[27]: for 802.11, one of 0x00 or 0x30? |
391 | | */ |
392 | | struct netxrayrec_2_x_hdr { |
393 | | uint32_t timelo; /* lower 32 bits of time stamp */ |
394 | | uint32_t timehi; /* upper 32 bits of time stamp */ |
395 | | uint16_t orig_len; /* packet length */ |
396 | | uint16_t incl_len; /* capture length */ |
397 | | uint8_t xxx[28]; /* various data */ |
398 | | }; |
399 | | |
400 | | /* |
401 | | * Union of the data record headers. |
402 | | */ |
403 | | union netxrayrec_hdr { |
404 | | struct old_netxrayrec_hdr old_hdr; |
405 | | struct netxrayrec_1_x_hdr hdr_1_x; |
406 | | struct netxrayrec_2_x_hdr hdr_2_x; |
407 | | }; |
408 | | |
409 | | typedef struct { |
410 | | time_t start_time; |
411 | | double ticks_per_sec; |
412 | | double start_timestamp; |
413 | | bool wrapped; |
414 | | uint32_t nframes; |
415 | | int64_t start_offset; |
416 | | int64_t end_offset; |
417 | | int version_major; |
418 | | bool fcs_valid; /* if packets have valid FCS at the end */ |
419 | | unsigned isdn_type; /* 1 = E1 PRI, 2 = T1 PRI, 3 = BRI */ |
420 | | } netxray_t; |
421 | | |
422 | | static bool netxray_read(wtap *wth, wtap_rec *rec, |
423 | | int *err, char **err_info, int64_t *data_offset); |
424 | | static bool netxray_seek_read(wtap *wth, int64_t seek_off, |
425 | | wtap_rec *rec, int *err, char **err_info); |
426 | | static int netxray_process_rec_header(wtap *wth, FILE_T fh, |
427 | | wtap_rec *rec, int *err, char **err_info); |
428 | | static void netxray_guess_atm_type(wtap *wth, wtap_rec *rec); |
429 | | static bool netxray_dump_1_1(wtap_dumper *wdh, const wtap_rec *rec, |
430 | | int *err, char **err_info); |
431 | | static bool netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, |
432 | | char **err_info); |
433 | | static bool netxray_dump_2_0(wtap_dumper *wdh, const wtap_rec *rec, |
434 | | int *err, char **err_info); |
435 | | static bool netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, |
436 | | char **err_info); |
437 | | |
438 | | static int netxray_old_file_type_subtype = -1; |
439 | | static int netxray_1_0_file_type_subtype = -1; |
440 | | static int netxray_1_1_file_type_subtype = -1; |
441 | | static int netxray_2_00x_file_type_subtype = -1; |
442 | | |
443 | | void register_netxray(void); |
444 | | |
445 | | wtap_open_return_val |
446 | | netxray_open(wtap *wth, int *err, char **err_info) |
447 | 0 | { |
448 | 0 | char magic[MAGIC_SIZE]; |
449 | 0 | bool is_old; |
450 | 0 | struct netxray_hdr hdr; |
451 | 0 | unsigned network_type; |
452 | 0 | double ticks_per_sec; |
453 | 0 | int version_major, version_minor; |
454 | 0 | int file_type; |
455 | 0 | double start_timestamp; |
456 | 0 | static const int netxray_encap[] = { |
457 | 0 | WTAP_ENCAP_UNKNOWN, |
458 | 0 | WTAP_ENCAP_ETHERNET, |
459 | 0 | WTAP_ENCAP_TOKEN_RING, |
460 | 0 | WTAP_ENCAP_FDDI_BITSWAPPED, |
461 | | /* |
462 | | * XXX - some PPP captures may look like Ethernet, |
463 | | * perhaps because they're using NDIS to capture on the |
464 | | * same machine and it provides simulated-Ethernet |
465 | | * packets, but captures taken with various serial |
466 | | * pods use the same network type value but aren't |
467 | | * shaped like Ethernet. We handle that below. |
468 | | */ |
469 | 0 | WTAP_ENCAP_ETHERNET, /* WAN(PPP), but shaped like Ethernet */ |
470 | 0 | WTAP_ENCAP_UNKNOWN, /* LocalTalk */ |
471 | 0 | WTAP_ENCAP_UNKNOWN, /* "DIX" - should not occur */ |
472 | 0 | WTAP_ENCAP_UNKNOWN, /* ARCNET raw */ |
473 | 0 | WTAP_ENCAP_UNKNOWN, /* ARCNET 878.2 */ |
474 | 0 | WTAP_ENCAP_ATM_PDUS_UNTRUNCATED,/* ATM */ |
475 | 0 | WTAP_ENCAP_IEEE_802_11_WITH_RADIO, |
476 | | /* Wireless WAN with radio information */ |
477 | 0 | WTAP_ENCAP_UNKNOWN /* IrDA */ |
478 | 0 | }; |
479 | 0 | #define NUM_NETXRAY_ENCAPS array_length(netxray_encap) |
480 | 0 | int file_encap; |
481 | 0 | unsigned isdn_type = 0; |
482 | 0 | netxray_t *netxray; |
483 | | |
484 | | /* Read in the string that should be at the start of a NetXRay |
485 | | * file */ |
486 | 0 | if (!wtap_read_bytes(wth->fh, magic, MAGIC_SIZE, err, err_info)) { |
487 | 0 | if (*err != WTAP_ERR_SHORT_READ) |
488 | 0 | return WTAP_OPEN_ERROR; |
489 | 0 | return WTAP_OPEN_NOT_MINE; |
490 | 0 | } |
491 | | |
492 | 0 | if (memcmp(magic, netxray_magic, MAGIC_SIZE) == 0) { |
493 | 0 | is_old = false; |
494 | 0 | } else if (memcmp(magic, old_netxray_magic, MAGIC_SIZE) == 0) { |
495 | 0 | is_old = true; |
496 | 0 | } else { |
497 | 0 | return WTAP_OPEN_NOT_MINE; |
498 | 0 | } |
499 | | |
500 | | /* Read the rest of the header. */ |
501 | 0 | if (!wtap_read_bytes(wth->fh, &hdr, sizeof hdr, err, err_info)) |
502 | 0 | return WTAP_OPEN_ERROR; |
503 | | |
504 | 0 | if (is_old) { |
505 | 0 | version_major = 0; |
506 | 0 | version_minor = 0; |
507 | 0 | file_type = netxray_old_file_type_subtype; |
508 | 0 | } else { |
509 | | /* It appears that version 1.1 files (as produced by Windows |
510 | | * Sniffer Pro 2.0.01) have the time stamp in microseconds, |
511 | | * rather than the milliseconds version 1.0 files appear to |
512 | | * have. |
513 | | * |
514 | | * It also appears that version 2.00x files have per-packet |
515 | | * headers with some extra fields. */ |
516 | 0 | if (memcmp(hdr.version, vers_1_0, sizeof vers_1_0) == 0) { |
517 | 0 | version_major = 1; |
518 | 0 | version_minor = 0; |
519 | 0 | file_type = netxray_1_0_file_type_subtype; |
520 | 0 | } else if (memcmp(hdr.version, vers_1_1, sizeof vers_1_1) == 0) { |
521 | 0 | version_major = 1; |
522 | 0 | version_minor = 1; |
523 | 0 | file_type = netxray_1_1_file_type_subtype; |
524 | 0 | } else if (memcmp(hdr.version, vers_2_000, sizeof vers_2_000) == 0) { |
525 | 0 | version_major = 2; |
526 | 0 | version_minor = 0; |
527 | 0 | file_type = netxray_2_00x_file_type_subtype; |
528 | 0 | } else if (memcmp(hdr.version, vers_2_001, sizeof vers_2_001) == 0) { |
529 | 0 | version_major = 2; |
530 | 0 | version_minor = 1; |
531 | 0 | file_type = netxray_2_00x_file_type_subtype; |
532 | 0 | } else if (memcmp(hdr.version, vers_2_002, sizeof vers_2_002) == 0) { |
533 | 0 | version_major = 2; |
534 | 0 | version_minor = 2; |
535 | 0 | file_type = netxray_2_00x_file_type_subtype; |
536 | 0 | } else if (memcmp(hdr.version, vers_2_003, sizeof vers_2_003) == 0) { |
537 | 0 | version_major = 2; |
538 | 0 | version_minor = 3; |
539 | 0 | file_type = netxray_2_00x_file_type_subtype; |
540 | 0 | } else { |
541 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
542 | 0 | *err_info = ws_strdup_printf("netxray: version \"%.8s\" unsupported", hdr.version); |
543 | 0 | return WTAP_OPEN_ERROR; |
544 | 0 | } |
545 | 0 | } |
546 | | |
547 | 0 | switch (hdr.network_plus) { |
548 | | |
549 | 0 | case 0: |
550 | | /* |
551 | | * The byte after hdr.network is usually 0, in which case |
552 | | * the hdr.network byte is an NDIS network type value - 1. |
553 | | */ |
554 | 0 | network_type = hdr.network + 1; |
555 | 0 | break; |
556 | | |
557 | 0 | case 2: |
558 | | /* |
559 | | * However, in some Ethernet captures, it's 2, and the |
560 | | * hdr.network byte is 1 rather than 0. We assume |
561 | | * that if there's a byte after hdr.network with the value |
562 | | * 2, the hdr.network byte is an NDIS network type, rather |
563 | | * than an NDIS network type - 1. |
564 | | */ |
565 | 0 | network_type = hdr.network; |
566 | 0 | break; |
567 | | |
568 | 0 | default: |
569 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
570 | 0 | *err_info = ws_strdup_printf("netxray: the byte after the network type has the value %u, which I don't understand", |
571 | 0 | hdr.network_plus); |
572 | 0 | return WTAP_OPEN_ERROR; |
573 | 0 | } |
574 | | |
575 | 0 | if (network_type >= NUM_NETXRAY_ENCAPS |
576 | 0 | || netxray_encap[network_type] == WTAP_ENCAP_UNKNOWN) { |
577 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
578 | 0 | *err_info = ws_strdup_printf("netxray: network type %u (%u) unknown or unsupported", |
579 | 0 | network_type, hdr.network_plus); |
580 | 0 | return WTAP_OPEN_ERROR; |
581 | 0 | } |
582 | | |
583 | | /* |
584 | | * Figure out the time stamp units and start time stamp. |
585 | | */ |
586 | 0 | start_timestamp = (double)pletohu32(&hdr.timelo) |
587 | 0 | + (double)pletohu32(&hdr.timehi)*4294967296.0; |
588 | 0 | if (is_old) { |
589 | 0 | ticks_per_sec = 1000.0; |
590 | 0 | wth->file_tsprec = WTAP_TSPREC_MSEC; |
591 | 0 | } else if (version_major == 1) { |
592 | 0 | switch (version_minor) { |
593 | | |
594 | 0 | case 0: |
595 | 0 | ticks_per_sec = 1000.0; |
596 | 0 | wth->file_tsprec = WTAP_TSPREC_MSEC; |
597 | 0 | break; |
598 | | |
599 | 0 | case 1: |
600 | | /* |
601 | | * In version 1.1 files (as produced by Windows |
602 | | * Sniffer Pro 2.0.01), the time stamp is in |
603 | | * microseconds, rather than the milliseconds |
604 | | * time stamps in NetXRay and older versions |
605 | | * of Windows Sniffer. |
606 | | */ |
607 | 0 | ticks_per_sec = 1000000.0; |
608 | 0 | wth->file_tsprec = WTAP_TSPREC_USEC; |
609 | 0 | break; |
610 | | |
611 | 0 | default: |
612 | | /* "Can't happen" - we rejected that above */ |
613 | 0 | *err = WTAP_ERR_INTERNAL; |
614 | 0 | *err_info = ws_strdup_printf("netxray: version %d.%d somehow didn't get rejected", |
615 | 0 | version_major, version_minor); |
616 | 0 | return WTAP_OPEN_ERROR; |
617 | 0 | } |
618 | 0 | } else if (version_major == 2) { |
619 | | /* |
620 | | * Get the time stamp units from the appropriate TpS |
621 | | * table or from the file header. |
622 | | */ |
623 | 0 | switch (network_type) { |
624 | | |
625 | 0 | case 1: |
626 | | /* |
627 | | * Ethernet - the table to use depends on whether |
628 | | * this is an NDIS or pod capture. |
629 | | */ |
630 | 0 | switch (hdr.captype) { |
631 | | |
632 | 0 | case CAPTYPE_NDIS: |
633 | 0 | if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS) { |
634 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
635 | 0 | *err_info = ws_strdup_printf( |
636 | 0 | "netxray: Unknown timeunit %u for Ethernet/CAPTYPE_NDIS version %.8s capture", |
637 | 0 | hdr.timeunit, hdr.version); |
638 | 0 | return WTAP_OPEN_ERROR; |
639 | 0 | } |
640 | | /* |
641 | | XXX: 05/29/07: Use 'realtick' instead of TpS table if timeunit=2; |
642 | | Using 'realtick' in this case results |
643 | | in the correct 'ticks per second' for all the captures that |
644 | | I have of this type (including captures from a number of Wireshark |
645 | | bug reports). |
646 | | */ |
647 | 0 | if (hdr.timeunit == 2) { |
648 | 0 | ticks_per_sec = pletohu32(hdr.realtick); |
649 | 0 | } |
650 | 0 | else { |
651 | 0 | ticks_per_sec = TpS[hdr.timeunit]; |
652 | 0 | } |
653 | 0 | break; |
654 | | |
655 | 0 | case ETH_CAPTYPE_GIGPOD: |
656 | 0 | if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_GIGPOD |
657 | 0 | || TpS_gigpod[hdr.timeunit] == 0.0) { |
658 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
659 | 0 | *err_info = ws_strdup_printf( |
660 | 0 | "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_GIGPOD version %.8s capture", |
661 | 0 | hdr.timeunit, hdr.version); |
662 | 0 | return WTAP_OPEN_ERROR; |
663 | 0 | } |
664 | 0 | ticks_per_sec = TpS_gigpod[hdr.timeunit]; |
665 | | |
666 | | /* |
667 | | * At least for 002.002 and 002.003 |
668 | | * captures, the start time stamp is 0, |
669 | | * not the value in the file. |
670 | | */ |
671 | 0 | if (version_minor == 2 || version_minor == 3) |
672 | 0 | start_timestamp = 0.0; |
673 | 0 | break; |
674 | | |
675 | 0 | case ETH_CAPTYPE_OTHERPOD: |
676 | 0 | if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_OTHERPOD |
677 | 0 | || TpS_otherpod[hdr.timeunit] == 0.0) { |
678 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
679 | 0 | *err_info = ws_strdup_printf( |
680 | 0 | "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_OTHERPOD version %.8s capture", |
681 | 0 | hdr.timeunit, hdr.version); |
682 | 0 | return WTAP_OPEN_ERROR; |
683 | 0 | } |
684 | 0 | ticks_per_sec = TpS_otherpod[hdr.timeunit]; |
685 | | |
686 | | /* |
687 | | * At least for 002.002 and 002.003 |
688 | | * captures, the start time stamp is 0, |
689 | | * not the value in the file. |
690 | | */ |
691 | 0 | if (version_minor == 2 || version_minor == 3) |
692 | 0 | start_timestamp = 0.0; |
693 | 0 | break; |
694 | | |
695 | 0 | case ETH_CAPTYPE_OTHERPOD2: |
696 | 0 | if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_OTHERPOD2 |
697 | 0 | || TpS_otherpod2[hdr.timeunit] == 0.0) { |
698 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
699 | 0 | *err_info = ws_strdup_printf( |
700 | 0 | "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_OTHERPOD2 version %.8s capture", |
701 | 0 | hdr.timeunit, hdr.version); |
702 | 0 | return WTAP_OPEN_ERROR; |
703 | 0 | } |
704 | 0 | ticks_per_sec = TpS_otherpod2[hdr.timeunit]; |
705 | | /* |
706 | | * XXX: start time stamp in the one capture file examined of this type was 0; |
707 | | * We'll assume the start time handling is the same as for other pods. |
708 | | * |
709 | | * At least for 002.002 and 002.003 |
710 | | * captures, the start time stamp is 0, |
711 | | * not the value in the file. |
712 | | */ |
713 | 0 | if (version_minor == 2 || version_minor == 3) |
714 | 0 | start_timestamp = 0.0; |
715 | 0 | break; |
716 | | |
717 | 0 | case ETH_CAPTYPE_GIGPOD2: |
718 | 0 | if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS_GIGPOD2 |
719 | 0 | || TpS_gigpod2[hdr.timeunit] == 0.0) { |
720 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
721 | 0 | *err_info = ws_strdup_printf( |
722 | 0 | "netxray: Unknown timeunit %u for Ethernet/ETH_CAPTYPE_GIGPOD2 version %.8s capture", |
723 | 0 | hdr.timeunit, hdr.version); |
724 | 0 | return WTAP_OPEN_ERROR; |
725 | 0 | } |
726 | 0 | ticks_per_sec = TpS_gigpod2[hdr.timeunit]; |
727 | | /* |
728 | | * XXX: start time stamp in the one capture file examined of this type was 0; |
729 | | * We'll assume the start time handling is the same as for other pods. |
730 | | * |
731 | | * At least for 002.002 and 002.003 |
732 | | * captures, the start time stamp is 0, |
733 | | * not the value in the file. |
734 | | */ |
735 | 0 | if (version_minor == 2 || version_minor == 3) |
736 | 0 | start_timestamp = 0.0; |
737 | 0 | break; |
738 | | |
739 | 0 | default: |
740 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
741 | 0 | *err_info = ws_strdup_printf( |
742 | 0 | "netxray: Unknown capture type %u for Ethernet version %.8s capture", |
743 | 0 | hdr.captype, hdr.version); |
744 | 0 | return WTAP_OPEN_ERROR; |
745 | 0 | } |
746 | 0 | break; |
747 | | |
748 | 0 | default: |
749 | 0 | if (hdr.timeunit >= NUM_NETXRAY_TIMEUNITS) { |
750 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
751 | 0 | *err_info = ws_strdup_printf( |
752 | 0 | "netxray: Unknown timeunit %u for %u/%u version %.8s capture", |
753 | 0 | hdr.timeunit, network_type, hdr.captype, |
754 | 0 | hdr.version); |
755 | 0 | return WTAP_OPEN_ERROR; |
756 | 0 | } |
757 | 0 | ticks_per_sec = TpS[hdr.timeunit]; |
758 | 0 | break; |
759 | 0 | } |
760 | | |
761 | | /* |
762 | | * If the number of ticks per second is greater than |
763 | | * 1 million, make the precision be nanoseconds rather |
764 | | * than microseconds. |
765 | | * |
766 | | * XXX - do values only slightly greater than one million |
767 | | * correspond to a resolution sufficiently better than |
768 | | * 1 microsecond to display more digits of precision? |
769 | | * XXX - Seems reasonable to use nanosecs only if TPS >= 10M |
770 | | */ |
771 | 0 | if (ticks_per_sec >= 1e7) |
772 | 0 | wth->file_tsprec = WTAP_TSPREC_NSEC; |
773 | 0 | else |
774 | 0 | wth->file_tsprec = WTAP_TSPREC_USEC; |
775 | 0 | } else { |
776 | | /* "Can't happen" - we rejected that above */ |
777 | 0 | *err = WTAP_ERR_INTERNAL; |
778 | 0 | *err_info = ws_strdup_printf("netxray: version %d.%d somehow didn't get rejected", |
779 | 0 | version_major, version_minor); |
780 | 0 | return WTAP_OPEN_ERROR; |
781 | 0 | } |
782 | 0 | start_timestamp = start_timestamp/ticks_per_sec; |
783 | |
|
784 | 0 | if (network_type == 4) { |
785 | | /* |
786 | | * In version 0 and 1, we assume, for now, that all |
787 | | * WAN captures have frames that look like Ethernet |
788 | | * frames (as a result, presumably, of having passed |
789 | | * through NDISWAN). |
790 | | * |
791 | | * In version 2, it looks as if there's stuff in the |
792 | | * file header to specify what particular type of WAN |
793 | | * capture we have. |
794 | | */ |
795 | 0 | if (version_major == 2) { |
796 | 0 | switch (hdr.captype) { |
797 | | |
798 | 0 | case WAN_CAPTYPE_PPP: |
799 | | /* |
800 | | * PPP. |
801 | | */ |
802 | 0 | file_encap = WTAP_ENCAP_PPP_WITH_PHDR; |
803 | 0 | break; |
804 | | |
805 | 0 | case WAN_CAPTYPE_FRELAY: |
806 | | /* |
807 | | * Frame Relay. |
808 | | * |
809 | | * XXX - in at least one capture, this |
810 | | * is Cisco HDLC, not Frame Relay, but |
811 | | * in another capture, it's Frame Relay. |
812 | | * |
813 | | * [Bytes in each capture: |
814 | | * Cisco HDLC: hdr.xxx_x60[06:10]: 0x02 0x00 0x01 0x00 0x06 |
815 | | * Frame Relay: hdr.xxx_x60[06:10] 0x00 0x00 0x00 0x00 0x00 |
816 | | |
817 | | * Cisco HDLC: hdr.xxx_x60[14:15]: 0xff 0xff |
818 | | * Frame Relay: hdr.xxx_x60[14:15]: 0x00 0x00 |
819 | | * ] |
820 | | */ |
821 | 0 | file_encap = WTAP_ENCAP_FRELAY_WITH_PHDR; |
822 | 0 | break; |
823 | | |
824 | 0 | case WAN_CAPTYPE_HDLC: |
825 | 0 | case WAN_CAPTYPE_HDLC2: |
826 | | /* |
827 | | * Various HDLC flavors? |
828 | | */ |
829 | 0 | switch (hdr.wan_hdlc_subsub_captype) { |
830 | | |
831 | 0 | case 0: /* LAPB/X.25 */ |
832 | | /* |
833 | | * XXX - at least one capture of |
834 | | * this type appears to be PPP. |
835 | | */ |
836 | 0 | file_encap = WTAP_ENCAP_LAPB; |
837 | 0 | break; |
838 | | |
839 | 0 | case 1: /* E1 PRI */ |
840 | 0 | case 2: /* T1 PRI */ |
841 | 0 | case 3: /* BRI */ |
842 | 0 | file_encap = WTAP_ENCAP_ISDN; |
843 | 0 | isdn_type = hdr.wan_hdlc_subsub_captype; |
844 | 0 | break; |
845 | | |
846 | 0 | default: |
847 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
848 | 0 | *err_info = ws_strdup_printf("netxray: WAN HDLC capture subsubtype 0x%02x unknown or unsupported", |
849 | 0 | hdr.wan_hdlc_subsub_captype); |
850 | 0 | return WTAP_OPEN_ERROR; |
851 | 0 | } |
852 | 0 | break; |
853 | | |
854 | 0 | case WAN_CAPTYPE_SDLC: |
855 | | /* |
856 | | * SDLC. |
857 | | */ |
858 | 0 | file_encap = WTAP_ENCAP_SDLC; |
859 | 0 | break; |
860 | | |
861 | 0 | case WAN_CAPTYPE_CHDLC: |
862 | | /* |
863 | | * Cisco router (CHDLC) captured with pod |
864 | | */ |
865 | 0 | file_encap = WTAP_ENCAP_CHDLC_WITH_PHDR; |
866 | 0 | break; |
867 | | |
868 | 0 | default: |
869 | 0 | *err = WTAP_ERR_UNSUPPORTED; |
870 | 0 | *err_info = ws_strdup_printf("netxray: WAN capture subtype 0x%02x unknown or unsupported", |
871 | 0 | hdr.captype); |
872 | 0 | return WTAP_OPEN_ERROR; |
873 | 0 | } |
874 | 0 | } else |
875 | 0 | file_encap = WTAP_ENCAP_ETHERNET; |
876 | 0 | } else |
877 | 0 | file_encap = netxray_encap[network_type]; |
878 | | |
879 | | /* This is a netxray file */ |
880 | 0 | wth->file_type_subtype = file_type; |
881 | 0 | netxray = g_new(netxray_t, 1); |
882 | 0 | wth->priv = (void *)netxray; |
883 | 0 | wth->subtype_read = netxray_read; |
884 | 0 | wth->subtype_seek_read = netxray_seek_read; |
885 | 0 | wth->file_encap = file_encap; |
886 | 0 | wth->snapshot_length = 0; /* not available in header */ |
887 | 0 | netxray->start_time = pletohu32(&hdr.start_time); |
888 | 0 | netxray->ticks_per_sec = ticks_per_sec; |
889 | 0 | netxray->start_timestamp = start_timestamp; |
890 | 0 | netxray->version_major = version_major; |
891 | | |
892 | | /* |
893 | | * If frames have an extra 4 bytes of stuff at the end, is |
894 | | * it an FCS, or just junk? |
895 | | */ |
896 | 0 | netxray->fcs_valid = false; |
897 | 0 | switch (file_encap) { |
898 | | |
899 | 0 | case WTAP_ENCAP_ETHERNET: |
900 | 0 | case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: |
901 | 0 | case WTAP_ENCAP_ISDN: |
902 | 0 | case WTAP_ENCAP_LAPB: |
903 | | /* |
904 | | * It appears that, in at least some version 2 Ethernet |
905 | | * captures, for frames that have 0xff in hdr_2_x.xxx[2] |
906 | | * and hdr_2_x.xxx[3] in the per-packet header: |
907 | | * |
908 | | * if, in the file header, hdr.realtick[1] is 0x34 |
909 | | * and hdr.realtick[2] is 0x12, the frames have an |
910 | | * FCS at the end; |
911 | | * |
912 | | * otherwise, they have 4 bytes of junk at the end. |
913 | | * |
914 | | * Yes, it's strange that you have to check the *middle* |
915 | | * of the time stamp field; you can't check for any |
916 | | * particular value of the time stamp field. |
917 | | * |
918 | | * For now, we assume that to be true for 802.11 captures |
919 | | * as well; it appears to be the case for at least one |
920 | | * such capture - the file doesn't have 0x34 and 0x12, |
921 | | * and the 4 bytes at the end of the frames with 0xff |
922 | | * are junk, not an FCS. |
923 | | * |
924 | | * For ISDN captures, it appears, at least in some |
925 | | * captures, to be similar, although I haven't yet |
926 | | * checked whether it's a valid FCS. |
927 | | * |
928 | | * XXX - should we do this for all encapsulation types? |
929 | | * |
930 | | * XXX - is there some other field that *really* indicates |
931 | | * whether we have an FCS or not? The check of the time |
932 | | * stamp is bizarre, as we're checking the middle. |
933 | | * Perhaps hdr.realtick[0] is 0x00, in which case time |
934 | | * stamp units in the range 1192960 through 1193215 |
935 | | * correspond to captures with an FCS, but that's still |
936 | | * a bit bizarre. |
937 | | * |
938 | | * Note that there are captures with a network type of 0 |
939 | | * (Ethernet) and capture type of 0 (NDIS) that do, and |
940 | | * that don't, have 0x34 0x12 in them, and at least one |
941 | | * of the NDIS captures with 0x34 0x12 in it has FCSes, |
942 | | * so it's not as if no NDIS captures have an FCS. |
943 | | * |
944 | | * There are also captures with a network type of 4 (WAN), |
945 | | * capture type of 6 (HDLC), and subtype of 2 (T1 PRI) that |
946 | | * do, and that don't, have 0x34 0x12, so there are at least |
947 | | * some captures taken with a WAN pod that might lack an FCS. |
948 | | * (We haven't yet tried dissecting the 4 bytes at the |
949 | | * end of packets with hdr_2_x.xxx[2] and hdr_2_x.xxx[3] |
950 | | * equal to 0xff as an FCS.) |
951 | | * |
952 | | * All captures I've seen that have 0x34 and 0x12 *and* |
953 | | * have at least one frame with an FCS have a value of |
954 | | * 0x01 in xxx_x40[4]. No captures I've seen with a network |
955 | | * type of 0 (Ethernet) missing 0x34 0x12 have 0x01 there, |
956 | | * however. However, there's at least one capture |
957 | | * without 0x34 and 0x12, with a network type of 0, |
958 | | * and with 0x01 in xxx_x40[4], *without* FCSes in the |
959 | | * frames - the 4 bytes at the end are all zero - so it's |
960 | | * not as simple as "xxx_x40[4] = 0x01 means the 4 bytes at |
961 | | * the end are FCSes". Also, there's also at least one |
962 | | * 802.11 capture with an xxx_x40[4] value of 0x01 with junk |
963 | | * rather than an FCS at the end of the frame, so xxx_x40[4] |
964 | | * isn't an obvious flag to determine whether the |
965 | | * capture has FCSes. |
966 | | * |
967 | | * There don't seem to be any other values in any of the |
968 | | * xxx_x5..., xxx_x6...., xxx_x7.... fields |
969 | | * that obviously correspond to frames having an FCS. |
970 | | * |
971 | | * 05/29/07: Examination of numerous sniffer captures suggests |
972 | | * that the apparent correlation of certain realtick |
973 | | * bytes to 'FCS presence' may actually be |
974 | | * a 'false positive'. |
975 | | * ToDo: Review analysis and update code. |
976 | | * It might be that the ticks-per-second value |
977 | | * is hardware-dependent, and that hardware with |
978 | | * a particular realtick value puts an FCS there |
979 | | * and other hardware doesn't. |
980 | | */ |
981 | 0 | if (version_major == 2) { |
982 | 0 | if (hdr.realtick[1] == 0x34 && hdr.realtick[2] == 0x12) |
983 | 0 | netxray->fcs_valid = true; |
984 | 0 | } |
985 | 0 | break; |
986 | 0 | } |
987 | | |
988 | | /* |
989 | | * Remember the ISDN type, as we need it to interpret the |
990 | | * channel number in ISDN captures. |
991 | | */ |
992 | 0 | netxray->isdn_type = isdn_type; |
993 | | |
994 | | /* Remember the offset after the last packet in the capture (which |
995 | | * isn't necessarily the last packet in the file), as it appears |
996 | | * there's sometimes crud after it. |
997 | | * XXX: Remember 'start_offset' to help testing for 'short file' at EOF |
998 | | */ |
999 | 0 | netxray->wrapped = false; |
1000 | 0 | netxray->nframes = pletohu32(&hdr.nframes); |
1001 | 0 | netxray->start_offset = pletohu32(&hdr.start_offset); |
1002 | 0 | netxray->end_offset = pletohu32(&hdr.end_offset); |
1003 | | |
1004 | | /* Seek to the beginning of the data records. */ |
1005 | 0 | if (file_seek(wth->fh, netxray->start_offset, SEEK_SET, err) == -1) { |
1006 | 0 | return WTAP_OPEN_ERROR; |
1007 | 0 | } |
1008 | | |
1009 | | /* |
1010 | | * Add an IDB; we don't know how many interfaces were |
1011 | | * involved, so we just say one interface, about which |
1012 | | * we only know the link-layer type, snapshot length, |
1013 | | * and time stamp resolution. |
1014 | | */ |
1015 | 0 | wtap_add_generated_idb(wth); |
1016 | |
|
1017 | 0 | return WTAP_OPEN_MINE; |
1018 | 0 | } |
1019 | | |
1020 | | /* Read the next packet */ |
1021 | | static bool |
1022 | | netxray_read(wtap *wth, wtap_rec *rec, int *err, char **err_info, |
1023 | | int64_t *data_offset) |
1024 | 0 | { |
1025 | 0 | netxray_t *netxray = (netxray_t *)wth->priv; |
1026 | 0 | int padding; |
1027 | |
|
1028 | 0 | reread: |
1029 | | /* |
1030 | | * Return the offset of the record header, so we can reread it |
1031 | | * if we go back to this frame. |
1032 | | */ |
1033 | 0 | *data_offset = file_tell(wth->fh); |
1034 | | |
1035 | | /* Have we reached the end of the packet data? */ |
1036 | 0 | if (*data_offset == netxray->end_offset) { |
1037 | | /* Yes. */ |
1038 | 0 | *err = 0; /* it's just an EOF, not an error */ |
1039 | 0 | return false; |
1040 | 0 | } |
1041 | | |
1042 | | /* Read and process record header. */ |
1043 | 0 | padding = netxray_process_rec_header(wth, wth->fh, rec, err, err_info); |
1044 | 0 | if (padding < 0) { |
1045 | | /* |
1046 | | * Error or EOF. |
1047 | | */ |
1048 | 0 | if (*err != 0) { |
1049 | | /* |
1050 | | * Error of some sort; give up. |
1051 | | */ |
1052 | 0 | return false; |
1053 | 0 | } |
1054 | | |
1055 | | /* We're at EOF. Wrap? |
1056 | | * XXX: Need to handle 'short file' cases |
1057 | | * (Distributed Sniffer seems to have a |
1058 | | * certain small propensity to generate 'short' files |
1059 | | * i.e. [many] bytes are missing from the end of the file) |
1060 | | * case 1: start_offset < end_offset |
1061 | | * wrap will read already read packets again; |
1062 | | * so: error with "short file" |
1063 | | * case 2: start_offset > end_offset ("circular" file) |
1064 | | * wrap will mean there's a gap (missing packets). |
1065 | | * However, I don't see a good way to identify this |
1066 | | * case so we'll just have to allow the wrap. |
1067 | | * (Maybe there can be an error message after all |
1068 | | * packets are read since there'll be less packets than |
1069 | | * specified in the file header). |
1070 | | * Note that these cases occur *only* if a 'short' eof occurs exactly |
1071 | | * at the expected beginning of a frame header record; If there is a |
1072 | | * partial frame header (or partial frame data) record, then the |
1073 | | * netxray_read... functions will detect the short record. |
1074 | | */ |
1075 | 0 | if (netxray->start_offset < netxray->end_offset) { |
1076 | 0 | *err = WTAP_ERR_SHORT_READ; |
1077 | 0 | return false; |
1078 | 0 | } |
1079 | | |
1080 | 0 | if (!netxray->wrapped) { |
1081 | | /* Yes. Remember that we did. */ |
1082 | 0 | netxray->wrapped = true; |
1083 | 0 | if (file_seek(wth->fh, CAPTUREFILE_HEADER_SIZE, |
1084 | 0 | SEEK_SET, err) == -1) |
1085 | 0 | return false; |
1086 | 0 | goto reread; |
1087 | 0 | } |
1088 | | |
1089 | | /* We've already wrapped - don't wrap again. */ |
1090 | 0 | return false; |
1091 | 0 | } |
1092 | | |
1093 | | /* |
1094 | | * Read the packet data. |
1095 | | */ |
1096 | 0 | if (!wtap_read_bytes_buffer(wth->fh, &rec->data, |
1097 | 0 | rec->rec_header.packet_header.caplen, err, err_info)) |
1098 | 0 | return false; |
1099 | | |
1100 | | /* |
1101 | | * If there's extra stuff at the end of the record, skip it. |
1102 | | */ |
1103 | 0 | if (!wtap_read_bytes(wth->fh, NULL, padding, err, err_info)) |
1104 | 0 | return false; |
1105 | | |
1106 | | /* |
1107 | | * If it's an ATM packet, and we don't have enough information |
1108 | | * from the packet header to determine its type or subtype, |
1109 | | * attempt to guess them from the packet data. |
1110 | | */ |
1111 | 0 | netxray_guess_atm_type(wth, rec); |
1112 | 0 | return true; |
1113 | 0 | } |
1114 | | |
1115 | | static bool |
1116 | | netxray_seek_read(wtap *wth, int64_t seek_off, wtap_rec *rec, |
1117 | | int *err, char **err_info) |
1118 | 0 | { |
1119 | 0 | if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1) |
1120 | 0 | return false; |
1121 | | |
1122 | 0 | if (netxray_process_rec_header(wth, wth->random_fh, rec, err, |
1123 | 0 | err_info) == -1) { |
1124 | 0 | if (*err == 0) { |
1125 | | /* |
1126 | | * EOF - we report that as a short read, as |
1127 | | * we've read this once and know that it |
1128 | | * should be there. |
1129 | | */ |
1130 | 0 | *err = WTAP_ERR_SHORT_READ; |
1131 | 0 | } |
1132 | 0 | return false; |
1133 | 0 | } |
1134 | | |
1135 | | /* |
1136 | | * Read the packet data. |
1137 | | */ |
1138 | 0 | if (!wtap_read_bytes_buffer(wth->random_fh, &rec->data, |
1139 | 0 | rec->rec_header.packet_header.caplen, err, err_info)) |
1140 | 0 | return false; |
1141 | | |
1142 | | /* |
1143 | | * If it's an ATM packet, and we don't have enough information |
1144 | | * from the packet header to determine its type or subtype, |
1145 | | * attempt to guess them from the packet data. |
1146 | | */ |
1147 | 0 | netxray_guess_atm_type(wth, rec); |
1148 | 0 | return true; |
1149 | 0 | } |
1150 | | |
1151 | | static int |
1152 | | netxray_process_rec_header(wtap *wth, FILE_T fh, wtap_rec *rec, |
1153 | | int *err, char **err_info) |
1154 | 0 | { |
1155 | 0 | netxray_t *netxray = (netxray_t *)wth->priv; |
1156 | 0 | union netxrayrec_hdr hdr; |
1157 | 0 | int hdr_size = 0; |
1158 | 0 | double t; |
1159 | 0 | int packet_size; |
1160 | 0 | int padding = 0; |
1161 | | |
1162 | | /* Read record header. */ |
1163 | 0 | switch (netxray->version_major) { |
1164 | | |
1165 | 0 | case 0: |
1166 | 0 | hdr_size = sizeof (struct old_netxrayrec_hdr); |
1167 | 0 | break; |
1168 | | |
1169 | 0 | case 1: |
1170 | 0 | hdr_size = sizeof (struct netxrayrec_1_x_hdr); |
1171 | 0 | break; |
1172 | | |
1173 | 0 | case 2: |
1174 | 0 | hdr_size = sizeof (struct netxrayrec_2_x_hdr); |
1175 | 0 | break; |
1176 | 0 | } |
1177 | 0 | if (!wtap_read_bytes_or_eof(fh, (void *)&hdr, hdr_size, err, err_info)) { |
1178 | | /* |
1179 | | * If *err is 0, we're at EOF. *err being 0 and a return |
1180 | | * value of -1 tells our caller we're at EOF. |
1181 | | * |
1182 | | * Otherwise, we got an error, and *err *not* being 0 |
1183 | | * and a return value tells our caller we have an error. |
1184 | | */ |
1185 | 0 | return -1; |
1186 | 0 | } |
1187 | | |
1188 | | /* |
1189 | | * If this is Ethernet, 802.11, ISDN, X.25, or ATM, set the |
1190 | | * pseudo-header. |
1191 | | */ |
1192 | 0 | switch (netxray->version_major) { |
1193 | | |
1194 | 0 | case 1: |
1195 | 0 | switch (wth->file_encap) { |
1196 | | |
1197 | 0 | case WTAP_ENCAP_ETHERNET: |
1198 | | /* |
1199 | | * XXX - if hdr_1_x.xxx[15] is 1 |
1200 | | * the frame appears not to have any extra |
1201 | | * stuff at the end, but if it's 0, |
1202 | | * there appears to be 4 bytes of stuff |
1203 | | * at the end, but it's not an FCS. |
1204 | | * |
1205 | | * Or is that just the low-order bit? |
1206 | | * |
1207 | | * For now, we just say "no FCS". |
1208 | | */ |
1209 | 0 | rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; |
1210 | 0 | break; |
1211 | 0 | } |
1212 | 0 | break; |
1213 | | |
1214 | 0 | case 2: |
1215 | 0 | switch (wth->file_encap) { |
1216 | | |
1217 | 0 | case WTAP_ENCAP_ETHERNET: |
1218 | | /* |
1219 | | * It appears, at least with version 2 captures, |
1220 | | * that we have 4 bytes of stuff (which might be |
1221 | | * a valid FCS or might be junk) at the end of |
1222 | | * the packet if hdr_2_x.xxx[2] and |
1223 | | * hdr_2_x.xxx[3] are 0xff, and we don't if |
1224 | | * they don't. |
1225 | | * |
1226 | | * It also appears that if the low-order bit of |
1227 | | * hdr_2_x.xxx[8] is set, the packet has a |
1228 | | * bad FCS. |
1229 | | */ |
1230 | 0 | if (hdr.hdr_2_x.xxx[2] == 0xff && |
1231 | 0 | hdr.hdr_2_x.xxx[3] == 0xff) { |
1232 | | /* |
1233 | | * We have 4 bytes of stuff at the |
1234 | | * end of the frame - FCS, or junk? |
1235 | | */ |
1236 | 0 | if (netxray->fcs_valid) { |
1237 | | /* |
1238 | | * FCS. |
1239 | | */ |
1240 | 0 | rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 4; |
1241 | 0 | } else { |
1242 | | /* |
1243 | | * Junk. |
1244 | | */ |
1245 | 0 | padding = 4; |
1246 | 0 | } |
1247 | 0 | } else |
1248 | 0 | rec->rec_header.packet_header.pseudo_header.eth.fcs_len = 0; |
1249 | 0 | break; |
1250 | | |
1251 | 0 | case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: |
1252 | | /* |
1253 | | * It appears, in one 802.11 capture, that |
1254 | | * we have 4 bytes of junk at the ends of |
1255 | | * frames in which hdr_2_x.xxx[2] and |
1256 | | * hdr_2_x.xxx[3] are 0xff; I haven't |
1257 | | * seen any frames where it's an FCS, but, |
1258 | | * for now, we still check the fcs_valid |
1259 | | * flag - I also haven't seen any capture |
1260 | | * where we'd set it based on the realtick |
1261 | | * value. |
1262 | | * |
1263 | | * It also appears that if the low-order bit of |
1264 | | * hdr_2_x.xxx[8] is set, the packet has a |
1265 | | * bad FCS. According to Ken Mann, the 0x4 bit |
1266 | | * is sometimes also set for errors. |
1267 | | * |
1268 | | * Ken also says that xxx[11] is 0x5 when the |
1269 | | * packet is WEP-encrypted. |
1270 | | */ |
1271 | 0 | memset(&rec->rec_header.packet_header.pseudo_header.ieee_802_11, 0, sizeof(rec->rec_header.packet_header.pseudo_header.ieee_802_11)); |
1272 | 0 | if (hdr.hdr_2_x.xxx[2] == 0xff && |
1273 | 0 | hdr.hdr_2_x.xxx[3] == 0xff) { |
1274 | | /* |
1275 | | * We have 4 bytes of stuff at the |
1276 | | * end of the frame - FCS, or junk? |
1277 | | */ |
1278 | 0 | if (netxray->fcs_valid) { |
1279 | | /* |
1280 | | * FCS. |
1281 | | */ |
1282 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 4; |
1283 | 0 | } else { |
1284 | | /* |
1285 | | * Junk. |
1286 | | */ |
1287 | 0 | padding = 4; |
1288 | 0 | } |
1289 | 0 | } else |
1290 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.fcs_len = 0; |
1291 | |
|
1292 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.decrypted = false; |
1293 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.datapad = false; |
1294 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.phy = PHDR_802_11_PHY_UNKNOWN; |
1295 | | |
1296 | | /* |
1297 | | * XXX - any other information, such as PHY |
1298 | | * type, frequency, 11n/11ac information, |
1299 | | * etc.? |
1300 | | */ |
1301 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_channel = true; |
1302 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.channel = |
1303 | 0 | hdr.hdr_2_x.xxx[12]; |
1304 | |
|
1305 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_data_rate = true; |
1306 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.data_rate = |
1307 | 0 | hdr.hdr_2_x.xxx[13]; |
1308 | |
|
1309 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_signal_percent = true; |
1310 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.signal_percent = |
1311 | 0 | hdr.hdr_2_x.xxx[14]; |
1312 | | |
1313 | | /* |
1314 | | * According to Ken Mann, at least in the captures |
1315 | | * he's seen, xxx[15] is the noise level, which |
1316 | | * is either 0xFF meaning "none reported" or a value |
1317 | | * from 0x00 to 0x7F for 0 to 100%. |
1318 | | */ |
1319 | 0 | if (hdr.hdr_2_x.xxx[15] != 0xFF) { |
1320 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.has_noise_percent = true; |
1321 | 0 | rec->rec_header.packet_header.pseudo_header.ieee_802_11.noise_percent = |
1322 | 0 | hdr.hdr_2_x.xxx[15]*100/127; |
1323 | 0 | } |
1324 | 0 | break; |
1325 | | |
1326 | 0 | case WTAP_ENCAP_ISDN: |
1327 | | /* |
1328 | | * ISDN. |
1329 | | * |
1330 | | * The bottommost bit of byte 12 of hdr_2_x.xxx |
1331 | | * is the direction flag. |
1332 | | * |
1333 | | * The bottom 5 bits of byte 13 of hdr_2_x.xxx |
1334 | | * are the channel number, but some mapping is |
1335 | | * required for PRI. (Is it really just the time |
1336 | | * slot?) |
1337 | | */ |
1338 | 0 | rec->rec_header.packet_header.pseudo_header.isdn.uton = |
1339 | 0 | (hdr.hdr_2_x.xxx[12] & 0x01); |
1340 | 0 | rec->rec_header.packet_header.pseudo_header.isdn.channel = |
1341 | 0 | hdr.hdr_2_x.xxx[13] & 0x1F; |
1342 | 0 | switch (netxray->isdn_type) { |
1343 | | |
1344 | 0 | case 1: |
1345 | | /* |
1346 | | * E1 PRI. Channel numbers 0 and 16 |
1347 | | * are the D channel; channel numbers 1 |
1348 | | * through 15 are B1 through B15; channel |
1349 | | * numbers 17 through 31 are B16 through |
1350 | | * B31. |
1351 | | */ |
1352 | 0 | if (rec->rec_header.packet_header.pseudo_header.isdn.channel == 16) |
1353 | 0 | rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; |
1354 | 0 | else if (rec->rec_header.packet_header.pseudo_header.isdn.channel > 16) |
1355 | 0 | rec->rec_header.packet_header.pseudo_header.isdn.channel -= 1; |
1356 | 0 | break; |
1357 | | |
1358 | 0 | case 2: |
1359 | | /* |
1360 | | * T1 PRI. Channel numbers 0 and 24 |
1361 | | * are the D channel; channel numbers 1 |
1362 | | * through 23 are B1 through B23. |
1363 | | */ |
1364 | 0 | if (rec->rec_header.packet_header.pseudo_header.isdn.channel == 24) |
1365 | 0 | rec->rec_header.packet_header.pseudo_header.isdn.channel = 0; |
1366 | 0 | else if (rec->rec_header.packet_header.pseudo_header.isdn.channel > 24) |
1367 | 0 | rec->rec_header.packet_header.pseudo_header.isdn.channel -= 1; |
1368 | 0 | break; |
1369 | 0 | } |
1370 | | |
1371 | | /* |
1372 | | * It appears, at least with version 2 captures, |
1373 | | * that we have 4 bytes of stuff (which might be |
1374 | | * a valid FCS or might be junk) at the end of |
1375 | | * the packet if hdr_2_x.xxx[2] and |
1376 | | * hdr_2_x.xxx[3] are 0xff, and we don't if |
1377 | | * they don't. |
1378 | | * |
1379 | | * XXX - does the low-order bit of hdr_2_x.xxx[8] |
1380 | | * indicate a bad FCS, as is the case with |
1381 | | * Ethernet? |
1382 | | */ |
1383 | 0 | if (hdr.hdr_2_x.xxx[2] == 0xff && |
1384 | 0 | hdr.hdr_2_x.xxx[3] == 0xff) { |
1385 | | /* |
1386 | | * FCS, or junk, at the end. |
1387 | | * XXX - is it an FCS if "fcs_valid" is |
1388 | | * true? |
1389 | | */ |
1390 | 0 | padding = 4; |
1391 | 0 | } |
1392 | 0 | break; |
1393 | | |
1394 | 0 | case WTAP_ENCAP_LAPB: |
1395 | 0 | case WTAP_ENCAP_FRELAY_WITH_PHDR: |
1396 | | /* |
1397 | | * LAPB/X.25 and Frame Relay. |
1398 | | * |
1399 | | * The bottommost bit of byte 12 of hdr_2_x.xxx |
1400 | | * is the direction flag. (Probably true for other |
1401 | | * HDLC encapsulations as well.) |
1402 | | */ |
1403 | 0 | rec->rec_header.packet_header.pseudo_header.dte_dce.flags = |
1404 | 0 | (hdr.hdr_2_x.xxx[12] & 0x01) ? 0x00 : FROM_DCE; |
1405 | | |
1406 | | /* |
1407 | | * It appears, at least with version 2 captures, |
1408 | | * that we have 4 bytes of stuff (which might be |
1409 | | * a valid FCS or might be junk) at the end of |
1410 | | * the packet if hdr_2_x.xxx[2] and |
1411 | | * hdr_2_x.xxx[3] are 0xff, and we don't if |
1412 | | * they don't. |
1413 | | * |
1414 | | * XXX - does the low-order bit of hdr_2_x.xxx[8] |
1415 | | * indicate a bad FCS, as is the case with |
1416 | | * Ethernet? |
1417 | | */ |
1418 | 0 | if (hdr.hdr_2_x.xxx[2] == 0xff && |
1419 | 0 | hdr.hdr_2_x.xxx[3] == 0xff) { |
1420 | | /* |
1421 | | * FCS, or junk, at the end. |
1422 | | * XXX - is it an FCS if "fcs_valid" is |
1423 | | * true? |
1424 | | */ |
1425 | 0 | padding = 4; |
1426 | 0 | } |
1427 | 0 | break; |
1428 | | |
1429 | 0 | case WTAP_ENCAP_PPP_WITH_PHDR: |
1430 | 0 | case WTAP_ENCAP_SDLC: |
1431 | 0 | case WTAP_ENCAP_CHDLC_WITH_PHDR: |
1432 | 0 | rec->rec_header.packet_header.pseudo_header.p2p.sent = |
1433 | 0 | (hdr.hdr_2_x.xxx[12] & 0x01) ? true : false; |
1434 | 0 | break; |
1435 | | |
1436 | 0 | case WTAP_ENCAP_ATM_PDUS_UNTRUNCATED: |
1437 | | /* |
1438 | | * XXX - the low-order bit of hdr_2_x.xxx[8] |
1439 | | * seems to indicate some sort of error. In |
1440 | | * at least one capture, a number of packets |
1441 | | * have that flag set, and they appear either |
1442 | | * to be the beginning part of an incompletely |
1443 | | * reassembled AAL5 PDU, with either checksum |
1444 | | * errors at higher levels (possibly due to |
1445 | | * the packet being reported as shorter than |
1446 | | * it actually is, and checksumming failing |
1447 | | * because it doesn't include all the data) |
1448 | | * or "Malformed frame" errors from being |
1449 | | * too short, or appear to be later parts |
1450 | | * of an incompletely reassembled AAL5 PDU |
1451 | | * with the last one in a sequence of errors |
1452 | | * having what looks like an AAL5 trailer, |
1453 | | * with a length and checksum. |
1454 | | * |
1455 | | * Does it just mean "reassembly failed", |
1456 | | * as appears to be the case in those |
1457 | | * packets, or does it mean "CRC error" |
1458 | | * at the AAL5 layer (which would be the |
1459 | | * case if you were treating an incompletely |
1460 | | * reassembled PDU as a completely reassembled |
1461 | | * PDU, although you'd also expect a length |
1462 | | * error in that case), or does it mean |
1463 | | * "generic error", with some other flag |
1464 | | * or flags indicating what particular |
1465 | | * error occurred? The documentation |
1466 | | * for Sniffer Pro 4.7 indicates a bunch |
1467 | | * of different error types, both in general |
1468 | | * and for ATM in particular. |
1469 | | * |
1470 | | * No obvious bits in hdr_2_x.xxx appear |
1471 | | * to be additional flags of that sort. |
1472 | | * |
1473 | | * XXX - in that capture, I see several |
1474 | | * reassembly errors in a row; should those |
1475 | | * packets be reassembled in the ATM dissector? |
1476 | | * What happens if a reassembly fails because |
1477 | | * a cell is bad? |
1478 | | */ |
1479 | 0 | rec->rec_header.packet_header.pseudo_header.atm.flags = 0; |
1480 | 0 | if (hdr.hdr_2_x.xxx[8] & 0x01) |
1481 | 0 | rec->rec_header.packet_header.pseudo_header.atm.flags |= ATM_REASSEMBLY_ERROR; |
1482 | | /* |
1483 | | * XXX - is 0x08 an "OAM cell" flag? |
1484 | | * Are the 0x01 and 0x02 bits error indications? |
1485 | | * Some packets in one capture that have the |
1486 | | * 0x01 bit set in hdr_2_x.xxx[8] and that |
1487 | | * appear to have been reassembled completely |
1488 | | * but have a bad CRC have 0x03 in hdr_2_x.xxx[9] |
1489 | | * (and don't have the 0x20 bit set). |
1490 | | * |
1491 | | * In the capture with incomplete reassemblies, |
1492 | | * all packets have the 0x20 bit set. In at |
1493 | | * least some of the captures with complete |
1494 | | * reassemblies with CRC errors, no packets |
1495 | | * have the 0x20 bit set. |
1496 | | * |
1497 | | * Are hdr_2_x.xxx[8] and hdr_2_x.xxx[9] a 16-bit |
1498 | | * flag field? |
1499 | | */ |
1500 | 0 | if (hdr.hdr_2_x.xxx[9] & 0x04) |
1501 | 0 | rec->rec_header.packet_header.pseudo_header.atm.flags |= ATM_RAW_CELL; |
1502 | 0 | rec->rec_header.packet_header.pseudo_header.atm.vpi = hdr.hdr_2_x.xxx[11]; |
1503 | 0 | rec->rec_header.packet_header.pseudo_header.atm.vci = pletohu16(&hdr.hdr_2_x.xxx[12]); |
1504 | 0 | rec->rec_header.packet_header.pseudo_header.atm.channel = |
1505 | 0 | (hdr.hdr_2_x.xxx[15] & 0x10)? 1 : 0; |
1506 | 0 | rec->rec_header.packet_header.pseudo_header.atm.cells = 0; |
1507 | | |
1508 | | /* |
1509 | | * XXX - the uppermost bit of hdr_2_xxx[0] |
1510 | | * looks as if it might be a flag of some sort. |
1511 | | * The remaining 3 bits appear to be an AAL |
1512 | | * type - 5 is, surprise surprise, AAL5. |
1513 | | */ |
1514 | 0 | switch (hdr.hdr_2_x.xxx[0] & 0x70) { |
1515 | | |
1516 | 0 | case 0x00: /* Unknown */ |
1517 | 0 | rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; |
1518 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; |
1519 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1520 | 0 | break; |
1521 | | |
1522 | 0 | case 0x10: /* XXX - AAL1? */ |
1523 | 0 | rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; |
1524 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; |
1525 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1526 | 0 | break; |
1527 | | |
1528 | 0 | case 0x20: /* XXX - AAL2? */ |
1529 | 0 | rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; |
1530 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; |
1531 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1532 | 0 | break; |
1533 | | |
1534 | 0 | case 0x40: /* XXX - AAL3/4? */ |
1535 | 0 | rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_UNKNOWN; |
1536 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; |
1537 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1538 | 0 | break; |
1539 | | |
1540 | 0 | case 0x30: /* XXX - AAL5 cells seen with this */ |
1541 | 0 | case 0x50: /* AAL5 (including signalling) */ |
1542 | 0 | case 0x60: /* XXX - AAL5 cells seen with this */ |
1543 | 0 | case 0x70: /* XXX - AAL5 cells seen with this */ |
1544 | 0 | rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_5; |
1545 | | /* |
1546 | | * XXX - is the 0x08 bit of hdr_2_x.xxx[0] |
1547 | | * a flag? I've not yet seen a case where |
1548 | | * it matters. |
1549 | | */ |
1550 | 0 | switch (hdr.hdr_2_x.xxx[0] & 0x07) { |
1551 | | |
1552 | 0 | case 0x01: |
1553 | 0 | case 0x02: /* Signalling traffic */ |
1554 | 0 | rec->rec_header.packet_header.pseudo_header.atm.aal = AAL_SIGNALLING; |
1555 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; |
1556 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1557 | 0 | break; |
1558 | | |
1559 | 0 | case 0x03: /* ILMI */ |
1560 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_ILMI; |
1561 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1562 | 0 | break; |
1563 | | |
1564 | 0 | case 0x00: |
1565 | 0 | case 0x04: |
1566 | 0 | case 0x05: |
1567 | | /* |
1568 | | * I've seen a frame with type |
1569 | | * 0x30 and subtype 0x08 that |
1570 | | * was LANE 802.3, a frame |
1571 | | * with type 0x30 and subtype |
1572 | | * 0x04 that was LANE 802.3, |
1573 | | * and another frame with type |
1574 | | * 0x30 and subtype 0x08 that |
1575 | | * was junk with a string in |
1576 | | * it that had also appeared |
1577 | | * in some CDP and LE Control |
1578 | | * frames, and that was preceded |
1579 | | * by a malformed LE Control |
1580 | | * frame - was that a reassembly |
1581 | | * failure? |
1582 | | * |
1583 | | * I've seen frames with type |
1584 | | * 0x50 and subtype 0x0c, some |
1585 | | * of which were LE Control |
1586 | | * frames, and at least one |
1587 | | * of which was neither an LE |
1588 | | * Control frame nor a LANE |
1589 | | * 802.3 frame, and contained |
1590 | | * the string "ForeThought_6.2.1 |
1591 | | * Alpha" - does that imply |
1592 | | * FORE's own encapsulation, |
1593 | | * or was this a reassembly failure? |
1594 | | * The latter frame was preceded |
1595 | | * by a malformed LE Control |
1596 | | * frame. |
1597 | | * |
1598 | | * I've seen a couple of frames |
1599 | | * with type 0x60 and subtype 0x00, |
1600 | | * one of which was LANE 802.3 and |
1601 | | * one of which was LE Control. |
1602 | | * I've seen one frame with type |
1603 | | * 0x60 and subtype 0x0c, which |
1604 | | * was LANE 802.3. |
1605 | | * |
1606 | | * I've seen a couple of frames |
1607 | | * with type 0x70 and subtype 0x00, |
1608 | | * both of which were LANE 802.3. |
1609 | | */ |
1610 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_LANE; |
1611 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1612 | 0 | break; |
1613 | | |
1614 | 0 | case 0x06: /* XXX - not seen yet */ |
1615 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_UNKNOWN; |
1616 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; |
1617 | 0 | break; |
1618 | | |
1619 | 0 | case 0x07: /* LLC multiplexed */ |
1620 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type = TRAF_LLCMX; /* XXX */ |
1621 | 0 | rec->rec_header.packet_header.pseudo_header.atm.subtype = TRAF_ST_UNKNOWN; /* XXX */ |
1622 | 0 | break; |
1623 | 0 | } |
1624 | 0 | break; |
1625 | 0 | } |
1626 | 0 | break; |
1627 | 0 | } |
1628 | 0 | break; |
1629 | 0 | } |
1630 | | |
1631 | 0 | wtap_setup_packet_rec(rec, wth->file_encap); |
1632 | 0 | rec->block = wtap_block_create(WTAP_BLOCK_PACKET); |
1633 | 0 | if (netxray->version_major == 0) { |
1634 | 0 | rec->presence_flags = WTAP_HAS_TS; |
1635 | 0 | t = (double)pletohu32(&hdr.old_hdr.timelo) |
1636 | 0 | + (double)pletohu32(&hdr.old_hdr.timehi)*4294967296.0; |
1637 | 0 | t /= netxray->ticks_per_sec; |
1638 | 0 | t -= netxray->start_timestamp; |
1639 | 0 | rec->ts.secs = netxray->start_time + (long)t; |
1640 | 0 | rec->ts.nsecs = (int)((t-(double)(unsigned long)(t)) |
1641 | 0 | *1.0e9); |
1642 | | /* |
1643 | | * We subtract the padding from the packet size, so our caller |
1644 | | * doesn't see it. |
1645 | | */ |
1646 | 0 | packet_size = pletohu16(&hdr.old_hdr.len); |
1647 | 0 | rec->rec_header.packet_header.caplen = packet_size - padding; |
1648 | 0 | rec->rec_header.packet_header.len = rec->rec_header.packet_header.caplen; |
1649 | 0 | } else { |
1650 | 0 | rec->presence_flags = WTAP_HAS_TS|WTAP_HAS_CAP_LEN; |
1651 | 0 | t = (double)pletohu32(&hdr.hdr_1_x.timelo) |
1652 | 0 | + (double)pletohu32(&hdr.hdr_1_x.timehi)*4294967296.0; |
1653 | 0 | t /= netxray->ticks_per_sec; |
1654 | 0 | t -= netxray->start_timestamp; |
1655 | 0 | rec->ts.secs = netxray->start_time + (time_t)t; |
1656 | 0 | rec->ts.nsecs = (int)((t-(double)(unsigned long)(t)) |
1657 | 0 | *1.0e9); |
1658 | | /* |
1659 | | * We subtract the padding from the packet size, so our caller |
1660 | | * doesn't see it. |
1661 | | */ |
1662 | 0 | packet_size = pletohu16(&hdr.hdr_1_x.incl_len); |
1663 | 0 | rec->rec_header.packet_header.caplen = packet_size - padding; |
1664 | 0 | rec->rec_header.packet_header.len = pletohu16(&hdr.hdr_1_x.orig_len) - padding; |
1665 | 0 | } |
1666 | |
|
1667 | 0 | return padding; |
1668 | 0 | } |
1669 | | |
1670 | | static void |
1671 | | netxray_guess_atm_type(wtap *wth, wtap_rec *rec) |
1672 | 0 | { |
1673 | 0 | if (wth->file_encap == WTAP_ENCAP_ATM_PDUS_UNTRUNCATED && |
1674 | 0 | !(rec->rec_header.packet_header.pseudo_header.atm.flags & ATM_REASSEMBLY_ERROR)) { |
1675 | 0 | if (rec->rec_header.packet_header.pseudo_header.atm.aal == AAL_UNKNOWN) { |
1676 | | /* |
1677 | | * Try to guess the type and subtype based |
1678 | | * on the VPI/VCI and packet contents. |
1679 | | */ |
1680 | 0 | atm_guess_traffic_type(rec); |
1681 | 0 | } else if (rec->rec_header.packet_header.pseudo_header.atm.aal == AAL_5 && |
1682 | 0 | rec->rec_header.packet_header.pseudo_header.atm.type == TRAF_LANE) { |
1683 | | /* |
1684 | | * Try to guess the subtype based on the |
1685 | | * packet contents. |
1686 | | */ |
1687 | 0 | atm_guess_lane_type(rec); |
1688 | 0 | } |
1689 | 0 | } |
1690 | 0 | } |
1691 | | |
1692 | | typedef struct { |
1693 | | bool first_frame; |
1694 | | uint32_t start_secs; |
1695 | | uint32_t nframes; |
1696 | | } netxray_dump_t; |
1697 | | |
1698 | | static const struct { |
1699 | | int wtap_encap_value; |
1700 | | int ndis_value; |
1701 | | } wtap_encap_1_1[] = { |
1702 | | { WTAP_ENCAP_ETHERNET, 0 }, /* -> NDIS Ethernet */ |
1703 | | { WTAP_ENCAP_TOKEN_RING, 1 }, /* -> NDIS Token Ring */ |
1704 | | { WTAP_ENCAP_FDDI, 2 }, /* -> NDIS FDDI */ |
1705 | | { WTAP_ENCAP_FDDI_BITSWAPPED, 2 }, /* -> NDIS FDDI */ |
1706 | | }; |
1707 | 0 | #define NUM_WTAP_ENCAPS_1_1 array_length(wtap_encap_1_1) |
1708 | | |
1709 | | static int |
1710 | | wtap_encap_to_netxray_1_1_encap(int encap) |
1711 | 0 | { |
1712 | 0 | unsigned int i; |
1713 | |
|
1714 | 0 | for (i = 0; i < NUM_WTAP_ENCAPS_1_1; i++) { |
1715 | 0 | if (encap == wtap_encap_1_1[i].wtap_encap_value) |
1716 | 0 | return wtap_encap_1_1[i].ndis_value; |
1717 | 0 | } |
1718 | | |
1719 | 0 | return -1; |
1720 | 0 | } |
1721 | | |
1722 | | /* Returns 0 if we could write the specified encapsulation type, |
1723 | | an error indication otherwise. */ |
1724 | | static int |
1725 | | netxray_dump_can_write_encap_1_1(int encap) |
1726 | 0 | { |
1727 | | /* Per-packet encapsulations aren't supported. */ |
1728 | 0 | if (encap == WTAP_ENCAP_PER_PACKET) |
1729 | 0 | return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; |
1730 | | |
1731 | 0 | if (wtap_encap_to_netxray_1_1_encap(encap) == -1) |
1732 | 0 | return WTAP_ERR_UNWRITABLE_ENCAP; |
1733 | | |
1734 | 0 | return 0; |
1735 | 0 | } |
1736 | | |
1737 | | /* Returns true on success, false on failure; sets "*err" to an error code on |
1738 | | failure */ |
1739 | | static bool |
1740 | | netxray_dump_open_1_1(wtap_dumper *wdh, int *err, char **err_info _U_) |
1741 | 0 | { |
1742 | 0 | netxray_dump_t *netxray; |
1743 | |
|
1744 | 0 | wdh->subtype_write = netxray_dump_1_1; |
1745 | 0 | wdh->subtype_finish = netxray_dump_finish_1_1; |
1746 | | |
1747 | | /* We can't fill in all the fields in the file header, as we |
1748 | | haven't yet written any packets. As we'll have to rewrite |
1749 | | the header when we've written out all the packets, we just |
1750 | | skip over the header for now. */ |
1751 | 0 | if (wtap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) |
1752 | 0 | return false; |
1753 | 0 | wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE; |
1754 | |
|
1755 | 0 | netxray = g_new(netxray_dump_t, 1); |
1756 | 0 | wdh->priv = (void *)netxray; |
1757 | 0 | netxray->first_frame = true; |
1758 | 0 | netxray->start_secs = 0; |
1759 | 0 | netxray->nframes = 0; |
1760 | |
|
1761 | 0 | return true; |
1762 | 0 | } |
1763 | | |
1764 | | /* Write a record for a packet to a dump file. |
1765 | | Returns true on success, false on failure. */ |
1766 | | static bool |
1767 | | netxray_dump_1_1(wtap_dumper *wdh, const wtap_rec *rec, |
1768 | | int *err, char **err_info _U_) |
1769 | 0 | { |
1770 | 0 | netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; |
1771 | 0 | uint64_t timestamp; |
1772 | 0 | uint32_t t32; |
1773 | 0 | struct netxrayrec_1_x_hdr rec_hdr; |
1774 | | |
1775 | | /* We can only write packet records. */ |
1776 | 0 | if (rec->rec_type != REC_TYPE_PACKET) { |
1777 | 0 | *err = WTAP_ERR_UNWRITABLE_REC_TYPE; |
1778 | 0 | *err_info = wtap_unwritable_rec_type_err_string(rec); |
1779 | 0 | return false; |
1780 | 0 | } |
1781 | | |
1782 | | /* |
1783 | | * Make sure this packet doesn't have a link-layer type that |
1784 | | * differs from the one for the file. |
1785 | | */ |
1786 | 0 | if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { |
1787 | 0 | *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; |
1788 | 0 | return false; |
1789 | 0 | } |
1790 | | |
1791 | | /* The captured length field is 16 bits, so there's a hard |
1792 | | limit of 65535. */ |
1793 | 0 | if (rec->rec_header.packet_header.caplen > 65535) { |
1794 | 0 | *err = WTAP_ERR_PACKET_TOO_LARGE; |
1795 | 0 | return false; |
1796 | 0 | } |
1797 | | |
1798 | | /* NetXRay/Windows Sniffer files have a capture start date/time |
1799 | | in the header, in a UNIX-style format, with one-second resolution, |
1800 | | and a start time stamp with microsecond resolution that's just |
1801 | | an arbitrary time stamp relative to some unknown time (boot |
1802 | | time?), and have times relative to the start time stamp in |
1803 | | the packet headers; pick the seconds value of the time stamp |
1804 | | of the first packet as the UNIX-style start date/time, and make |
1805 | | the high-resolution start time stamp 0, with the time stamp of |
1806 | | packets being the delta between the stamp of the packet and |
1807 | | the stamp of the first packet with the microseconds part 0. */ |
1808 | 0 | if (netxray->first_frame) { |
1809 | 0 | netxray->first_frame = false; |
1810 | | /* |
1811 | | * XXX - NetXRay ran on Windows, where MSVC's localtime() |
1812 | | * can't handle time_t < 0, so *maybe* it makes sense |
1813 | | * to allow time stamps up to 2^32-1 "seconds since the |
1814 | | * Epoch", but maybe the start time in those files is |
1815 | | * signed, in which case we should check against |
1816 | | * INT32_MIN and INT32_MAX and make start_secs a |
1817 | | * int32_t. |
1818 | | */ |
1819 | 0 | if (rec->ts.secs < 0 || rec->ts.secs > WTAP_NSTIME_32BIT_SECS_MAX) { |
1820 | 0 | *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; |
1821 | 0 | return false; |
1822 | 0 | } |
1823 | 0 | netxray->start_secs = (uint32_t)rec->ts.secs; |
1824 | 0 | } |
1825 | | |
1826 | | /* build the header for each packet */ |
1827 | 0 | memset(&rec_hdr, '\0', sizeof(rec_hdr)); |
1828 | 0 | timestamp = ((uint64_t)rec->ts.secs - (uint64_t)netxray->start_secs)*1000000 |
1829 | 0 | + ((uint64_t)rec->ts.nsecs)/1000; |
1830 | 0 | t32 = (uint32_t)(timestamp%INT64_C(4294967296)); |
1831 | 0 | rec_hdr.timelo = GUINT32_TO_LE(t32); |
1832 | 0 | t32 = (uint32_t)(timestamp/INT64_C(4294967296)); |
1833 | 0 | rec_hdr.timehi = GUINT32_TO_LE(t32); |
1834 | 0 | rec_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len); |
1835 | 0 | rec_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); |
1836 | |
|
1837 | 0 | if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof(rec_hdr), err)) |
1838 | 0 | return false; |
1839 | | |
1840 | | /* write the packet data */ |
1841 | 0 | if (!wtap_dump_file_write(wdh, ws_buffer_start_ptr(&rec->data), |
1842 | 0 | rec->rec_header.packet_header.caplen, err)) |
1843 | 0 | return false; |
1844 | | |
1845 | 0 | netxray->nframes++; |
1846 | |
|
1847 | 0 | return true; |
1848 | 0 | } |
1849 | | |
1850 | | /* Finish writing to a dump file. |
1851 | | Returns true on success, false on failure. */ |
1852 | | static bool |
1853 | | netxray_dump_finish_1_1(wtap_dumper *wdh, int *err, char **err_info _U_) |
1854 | 0 | { |
1855 | 0 | char hdr_buf[CAPTUREFILE_HEADER_SIZE - sizeof(netxray_magic)]; |
1856 | 0 | netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; |
1857 | 0 | int64_t filelen; |
1858 | 0 | struct netxray_hdr file_hdr; |
1859 | |
|
1860 | 0 | if (-1 == (filelen = wtap_dump_file_tell(wdh, err))) |
1861 | 0 | return false; |
1862 | | |
1863 | | /* Go back to beginning */ |
1864 | 0 | if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) |
1865 | 0 | return false; |
1866 | | |
1867 | | /* Rewrite the file header. */ |
1868 | 0 | if (!wtap_dump_file_write(wdh, netxray_magic, sizeof netxray_magic, err)) |
1869 | 0 | return false; |
1870 | | |
1871 | | /* "sniffer" version ? */ |
1872 | 0 | memset(&file_hdr, '\0', sizeof file_hdr); |
1873 | 0 | memcpy(file_hdr.version, vers_1_1, sizeof vers_1_1); |
1874 | 0 | file_hdr.start_time = GUINT32_TO_LE(netxray->start_secs); |
1875 | 0 | file_hdr.nframes = GUINT32_TO_LE(netxray->nframes); |
1876 | 0 | file_hdr.start_offset = GUINT32_TO_LE(CAPTUREFILE_HEADER_SIZE); |
1877 | | /* XXX - large files? */ |
1878 | 0 | file_hdr.end_offset = GUINT32_TO_LE((uint32_t)filelen); |
1879 | 0 | file_hdr.network = wtap_encap_to_netxray_1_1_encap(wdh->file_encap); |
1880 | 0 | file_hdr.timelo = GUINT32_TO_LE(0); |
1881 | 0 | file_hdr.timehi = GUINT32_TO_LE(0); |
1882 | |
|
1883 | 0 | memset(hdr_buf, '\0', sizeof hdr_buf); |
1884 | 0 | memcpy(hdr_buf, &file_hdr, sizeof(file_hdr)); |
1885 | 0 | if (!wtap_dump_file_write(wdh, hdr_buf, sizeof hdr_buf, err)) |
1886 | 0 | return false; |
1887 | | |
1888 | | /* Don't double-count the size of the file header */ |
1889 | 0 | wdh->bytes_dumped = filelen; |
1890 | 0 | return true; |
1891 | 0 | } |
1892 | | |
1893 | | static const struct { |
1894 | | int wtap_encap_value; |
1895 | | int ndis_value; |
1896 | | } wtap_encap_2_0[] = { |
1897 | | { WTAP_ENCAP_ETHERNET, 0 }, /* -> NDIS Ethernet */ |
1898 | | { WTAP_ENCAP_TOKEN_RING, 1 }, /* -> NDIS Token Ring */ |
1899 | | { WTAP_ENCAP_FDDI, 2 }, /* -> NDIS FDDI */ |
1900 | | { WTAP_ENCAP_FDDI_BITSWAPPED, 2 }, /* -> NDIS FDDI */ |
1901 | | { WTAP_ENCAP_PPP_WITH_PHDR, 3 }, /* -> NDIS WAN */ |
1902 | | { WTAP_ENCAP_FRELAY_WITH_PHDR, 3 }, /* -> NDIS WAN */ |
1903 | | { WTAP_ENCAP_LAPB, 3 }, /* -> NDIS WAN */ |
1904 | | { WTAP_ENCAP_SDLC, 3 }, /* -> NDIS WAN */ |
1905 | | }; |
1906 | 0 | #define NUM_WTAP_ENCAPS_2_0 array_length(wtap_encap_2_0) |
1907 | | |
1908 | | static int |
1909 | | wtap_encap_to_netxray_2_0_encap(int encap) |
1910 | 0 | { |
1911 | 0 | unsigned int i; |
1912 | |
|
1913 | 0 | for (i = 0; i < NUM_WTAP_ENCAPS_2_0; i++) { |
1914 | 0 | if (encap == wtap_encap_2_0[i].wtap_encap_value) |
1915 | 0 | return wtap_encap_2_0[i].ndis_value; |
1916 | 0 | } |
1917 | | |
1918 | 0 | return -1; |
1919 | 0 | } |
1920 | | |
1921 | | /* Returns 0 if we could write the specified encapsulation type, |
1922 | | an error indication otherwise. */ |
1923 | | static int |
1924 | | netxray_dump_can_write_encap_2_0(int encap) |
1925 | 0 | { |
1926 | | /* Per-packet encapsulations aren't supported. */ |
1927 | 0 | if (encap == WTAP_ENCAP_PER_PACKET) |
1928 | 0 | return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; |
1929 | | |
1930 | 0 | if (wtap_encap_to_netxray_2_0_encap(encap) == -1) |
1931 | 0 | return WTAP_ERR_UNWRITABLE_ENCAP; |
1932 | | |
1933 | 0 | return 0; |
1934 | 0 | } |
1935 | | |
1936 | | /* Returns true on success, false on failure; sets "*err" to an error code on |
1937 | | failure */ |
1938 | | static bool |
1939 | | netxray_dump_open_2_0(wtap_dumper *wdh, int *err, char **err_info _U_) |
1940 | 0 | { |
1941 | 0 | netxray_dump_t *netxray; |
1942 | |
|
1943 | 0 | wdh->subtype_write = netxray_dump_2_0; |
1944 | 0 | wdh->subtype_finish = netxray_dump_finish_2_0; |
1945 | | |
1946 | | /* We can't fill in all the fields in the file header, as we |
1947 | | haven't yet written any packets. As we'll have to rewrite |
1948 | | the header when we've written out all the packets, we just |
1949 | | skip over the header for now. */ |
1950 | 0 | if (wtap_dump_file_seek(wdh, CAPTUREFILE_HEADER_SIZE, SEEK_SET, err) == -1) |
1951 | 0 | return false; |
1952 | 0 | wdh->bytes_dumped += CAPTUREFILE_HEADER_SIZE; |
1953 | |
|
1954 | 0 | netxray = g_new(netxray_dump_t, 1); |
1955 | 0 | wdh->priv = (void *)netxray; |
1956 | 0 | netxray->first_frame = true; |
1957 | 0 | netxray->start_secs = 0; |
1958 | 0 | netxray->nframes = 0; |
1959 | |
|
1960 | 0 | return true; |
1961 | 0 | } |
1962 | | |
1963 | | /* Write a record for a packet to a dump file. |
1964 | | Returns true on success, false on failure. */ |
1965 | | static bool |
1966 | | netxray_dump_2_0(wtap_dumper *wdh, const wtap_rec *rec, |
1967 | | int *err, char **err_info _U_) |
1968 | 0 | { |
1969 | 0 | const union wtap_pseudo_header *pseudo_header = &rec->rec_header.packet_header.pseudo_header; |
1970 | 0 | netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; |
1971 | 0 | uint64_t timestamp; |
1972 | 0 | uint32_t t32; |
1973 | 0 | struct netxrayrec_2_x_hdr rec_hdr; |
1974 | | |
1975 | | /* We can only write packet records. */ |
1976 | 0 | if (rec->rec_type != REC_TYPE_PACKET) { |
1977 | 0 | *err = WTAP_ERR_UNWRITABLE_REC_TYPE; |
1978 | 0 | *err_info = wtap_unwritable_rec_type_err_string(rec); |
1979 | 0 | return false; |
1980 | 0 | } |
1981 | | |
1982 | | /* |
1983 | | * Make sure this packet doesn't have a link-layer type that |
1984 | | * differs from the one for the file. |
1985 | | */ |
1986 | 0 | if (wdh->file_encap != rec->rec_header.packet_header.pkt_encap) { |
1987 | 0 | *err = WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED; |
1988 | 0 | return false; |
1989 | 0 | } |
1990 | | |
1991 | | /* Don't write anything we're not willing to read. */ |
1992 | 0 | if (rec->rec_header.packet_header.caplen > WTAP_MAX_PACKET_SIZE_STANDARD) { |
1993 | 0 | *err = WTAP_ERR_PACKET_TOO_LARGE; |
1994 | 0 | return false; |
1995 | 0 | } |
1996 | | |
1997 | | /* NetXRay/Windows Sniffer files have a capture start date/time |
1998 | | in the header, in a UNIX-style format, with one-second resolution, |
1999 | | and a start time stamp with microsecond resolution that's just |
2000 | | an arbitrary time stamp relative to some unknown time (boot |
2001 | | time?), and have times relative to the start time stamp in |
2002 | | the packet headers; pick the seconds value of the time stamp |
2003 | | of the first packet as the UNIX-style start date/time, and make |
2004 | | the high-resolution start time stamp 0, with the time stamp of |
2005 | | packets being the delta between the stamp of the packet and |
2006 | | the stamp of the first packet with the microseconds part 0. */ |
2007 | 0 | if (netxray->first_frame) { |
2008 | 0 | netxray->first_frame = false; |
2009 | | /* |
2010 | | * XXX - NetXRay ran on Windows, where MSVC's localtime() |
2011 | | * can't handle time_t < 0, so *maybe* it makes sense |
2012 | | * to allow time stamps up to 2^32-1 "seconds since the |
2013 | | * Epoch", but maybe the start time in those files is |
2014 | | * signed, in which case we should check against |
2015 | | * INT32_MIN and INT32_MAX and make start_secs a |
2016 | | * int32_t. |
2017 | | */ |
2018 | 0 | if (rec->ts.secs < 0 || rec->ts.secs > WTAP_NSTIME_32BIT_SECS_MAX) { |
2019 | 0 | *err = WTAP_ERR_TIME_STAMP_NOT_SUPPORTED; |
2020 | 0 | return false; |
2021 | 0 | } |
2022 | 0 | netxray->start_secs = (uint32_t)rec->ts.secs; |
2023 | 0 | } |
2024 | | |
2025 | | /* build the header for each packet */ |
2026 | 0 | memset(&rec_hdr, '\0', sizeof(rec_hdr)); |
2027 | 0 | timestamp = ((uint64_t)rec->ts.secs - (uint64_t)netxray->start_secs)*1000000 |
2028 | 0 | + ((uint64_t)rec->ts.nsecs)/1000; |
2029 | 0 | t32 = (uint32_t)(timestamp%INT64_C(4294967296)); |
2030 | 0 | rec_hdr.timelo = GUINT32_TO_LE(t32); |
2031 | 0 | t32 = (uint32_t)(timestamp/INT64_C(4294967296)); |
2032 | 0 | rec_hdr.timehi = GUINT32_TO_LE(t32); |
2033 | 0 | rec_hdr.orig_len = GUINT16_TO_LE(rec->rec_header.packet_header.len); |
2034 | 0 | rec_hdr.incl_len = GUINT16_TO_LE(rec->rec_header.packet_header.caplen); |
2035 | |
|
2036 | 0 | switch (rec->rec_header.packet_header.pkt_encap) { |
2037 | | |
2038 | 0 | case WTAP_ENCAP_IEEE_802_11_WITH_RADIO: |
2039 | 0 | rec_hdr.xxx[12] = |
2040 | 0 | pseudo_header->ieee_802_11.has_channel ? |
2041 | 0 | pseudo_header->ieee_802_11.channel : |
2042 | 0 | 0; |
2043 | 0 | rec_hdr.xxx[13] = |
2044 | 0 | pseudo_header->ieee_802_11.has_data_rate ? |
2045 | 0 | (uint8_t)pseudo_header->ieee_802_11.data_rate : |
2046 | 0 | 0; |
2047 | 0 | rec_hdr.xxx[14] = |
2048 | 0 | pseudo_header->ieee_802_11.has_signal_percent ? |
2049 | 0 | pseudo_header->ieee_802_11.signal_percent : |
2050 | 0 | 0; |
2051 | 0 | rec_hdr.xxx[15] = |
2052 | 0 | pseudo_header->ieee_802_11.has_noise_percent ? |
2053 | 0 | pseudo_header->ieee_802_11.noise_percent*127/100 : |
2054 | 0 | 0xFF; |
2055 | 0 | break; |
2056 | | |
2057 | 0 | case WTAP_ENCAP_PPP_WITH_PHDR: |
2058 | 0 | case WTAP_ENCAP_SDLC: |
2059 | 0 | rec_hdr.xxx[12] |= pseudo_header->p2p.sent ? 0x01 : 0x00; |
2060 | 0 | break; |
2061 | | |
2062 | 0 | case WTAP_ENCAP_FRELAY_WITH_PHDR: |
2063 | 0 | rec_hdr.xxx[12] |= (pseudo_header->dte_dce.flags & FROM_DCE) ? 0x00 : 0x01; |
2064 | 0 | break; |
2065 | 0 | } |
2066 | | |
2067 | 0 | if (!wtap_dump_file_write(wdh, &rec_hdr, sizeof(rec_hdr), err)) |
2068 | 0 | return false; |
2069 | | |
2070 | | /* write the packet data */ |
2071 | 0 | if (!wtap_dump_file_write(wdh, ws_buffer_start_ptr(&rec->data), |
2072 | 0 | rec->rec_header.packet_header.caplen, err)) |
2073 | 0 | return false; |
2074 | | |
2075 | 0 | netxray->nframes++; |
2076 | |
|
2077 | 0 | return true; |
2078 | 0 | } |
2079 | | |
2080 | | /* Finish writing to a dump file. |
2081 | | Returns true on success, false on failure. */ |
2082 | | static bool |
2083 | | netxray_dump_finish_2_0(wtap_dumper *wdh, int *err, char **err_info _U_) |
2084 | 0 | { |
2085 | 0 | char hdr_buf[CAPTUREFILE_HEADER_SIZE - sizeof(netxray_magic)]; |
2086 | 0 | netxray_dump_t *netxray = (netxray_dump_t *)wdh->priv; |
2087 | 0 | int64_t filelen; |
2088 | 0 | struct netxray_hdr file_hdr; |
2089 | |
|
2090 | 0 | if (-1 == (filelen = wtap_dump_file_tell(wdh, err))) |
2091 | 0 | return false; |
2092 | | |
2093 | | /* Go back to beginning */ |
2094 | 0 | if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1) |
2095 | 0 | return false; |
2096 | | |
2097 | | /* Rewrite the file header. */ |
2098 | 0 | if (!wtap_dump_file_write(wdh, netxray_magic, sizeof netxray_magic, err)) |
2099 | 0 | return false; |
2100 | | |
2101 | | /* "sniffer" version ? */ |
2102 | 0 | memset(&file_hdr, '\0', sizeof file_hdr); |
2103 | 0 | memcpy(file_hdr.version, vers_2_001, sizeof vers_2_001); |
2104 | 0 | file_hdr.start_time = GUINT32_TO_LE(netxray->start_secs); |
2105 | 0 | file_hdr.nframes = GUINT32_TO_LE(netxray->nframes); |
2106 | 0 | file_hdr.start_offset = GUINT32_TO_LE(CAPTUREFILE_HEADER_SIZE); |
2107 | | /* XXX - large files? */ |
2108 | 0 | file_hdr.end_offset = GUINT32_TO_LE((uint32_t)filelen); |
2109 | 0 | file_hdr.network = wtap_encap_to_netxray_2_0_encap(wdh->file_encap); |
2110 | 0 | file_hdr.timelo = GUINT32_TO_LE(0); |
2111 | 0 | file_hdr.timehi = GUINT32_TO_LE(0); |
2112 | 0 | switch (wdh->file_encap) { |
2113 | | |
2114 | 0 | case WTAP_ENCAP_PPP_WITH_PHDR: |
2115 | 0 | file_hdr.captype = WAN_CAPTYPE_PPP; |
2116 | 0 | break; |
2117 | | |
2118 | 0 | case WTAP_ENCAP_FRELAY_WITH_PHDR: |
2119 | 0 | file_hdr.captype = WAN_CAPTYPE_FRELAY; |
2120 | 0 | break; |
2121 | | |
2122 | 0 | case WTAP_ENCAP_LAPB: |
2123 | 0 | file_hdr.captype = WAN_CAPTYPE_HDLC; |
2124 | 0 | file_hdr.wan_hdlc_subsub_captype = 0; |
2125 | 0 | break; |
2126 | | |
2127 | 0 | case WTAP_ENCAP_SDLC: |
2128 | 0 | file_hdr.captype = WAN_CAPTYPE_SDLC; |
2129 | 0 | break; |
2130 | | |
2131 | 0 | default: |
2132 | 0 | file_hdr.captype = CAPTYPE_NDIS; |
2133 | 0 | break; |
2134 | 0 | } |
2135 | | |
2136 | 0 | memset(hdr_buf, '\0', sizeof hdr_buf); |
2137 | 0 | memcpy(hdr_buf, &file_hdr, sizeof(file_hdr)); |
2138 | 0 | if (!wtap_dump_file_write(wdh, hdr_buf, sizeof hdr_buf, err)) |
2139 | 0 | return false; |
2140 | | |
2141 | | /* Don't double-count the size of the file header */ |
2142 | 0 | wdh->bytes_dumped = filelen; |
2143 | 0 | return true; |
2144 | 0 | } |
2145 | | |
2146 | | static const struct supported_block_type netxray_old_blocks_supported[] = { |
2147 | | /* |
2148 | | * We support packet blocks, with no comments or other options. |
2149 | | */ |
2150 | | { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED } |
2151 | | }; |
2152 | | |
2153 | | static const struct file_type_subtype_info netxray_old_info = { |
2154 | | "Cinco Networks NetXRay 1.x", "netxray1", "cap", NULL, |
2155 | | true, BLOCKS_SUPPORTED(netxray_old_blocks_supported), |
2156 | | NULL, NULL, NULL |
2157 | | }; |
2158 | | |
2159 | | static const struct supported_block_type netxray_1_0_blocks_supported[] = { |
2160 | | /* |
2161 | | * We support packet blocks, with no comments or other options. |
2162 | | */ |
2163 | | { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED } |
2164 | | }; |
2165 | | |
2166 | | static const struct file_type_subtype_info netxray_1_0_info = { |
2167 | | "Cinco Networks NetXRay 2.0 or later", "netxray2", "cap", NULL, |
2168 | | true, BLOCKS_SUPPORTED(netxray_1_0_blocks_supported), |
2169 | | NULL, NULL, NULL |
2170 | | }; |
2171 | | |
2172 | | static const struct supported_block_type netxray_1_1_blocks_supported[] = { |
2173 | | /* |
2174 | | * We support packet blocks, with no comments or other options. |
2175 | | */ |
2176 | | { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED } |
2177 | | }; |
2178 | | |
2179 | | static const struct file_type_subtype_info netxray_1_1_info = { |
2180 | | "NetXray, Sniffer (Windows) 1.1", "ngwsniffer_1_1", "cap", NULL, |
2181 | | true, BLOCKS_SUPPORTED(netxray_1_1_blocks_supported), |
2182 | | netxray_dump_can_write_encap_1_1, netxray_dump_open_1_1, NULL |
2183 | | }; |
2184 | | |
2185 | | static const struct supported_block_type netxray_2_00x_blocks_supported[] = { |
2186 | | /* |
2187 | | * We support packet blocks, with no comments or other options. |
2188 | | */ |
2189 | | { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED } |
2190 | | }; |
2191 | | |
2192 | | static const struct file_type_subtype_info netxray_2_00x_info = { |
2193 | | "Sniffer (Windows) 2.00x", "ngwsniffer_2_0", "cap", "caz", |
2194 | | true, BLOCKS_SUPPORTED(netxray_2_00x_blocks_supported), |
2195 | | netxray_dump_can_write_encap_2_0, netxray_dump_open_2_0, NULL |
2196 | | }; |
2197 | | |
2198 | | void register_netxray(void) |
2199 | 14 | { |
2200 | 14 | netxray_old_file_type_subtype = wtap_register_file_type_subtype(&netxray_old_info); |
2201 | 14 | netxray_1_0_file_type_subtype = wtap_register_file_type_subtype(&netxray_1_0_info); |
2202 | 14 | netxray_1_1_file_type_subtype = wtap_register_file_type_subtype(&netxray_1_1_info); |
2203 | 14 | netxray_2_00x_file_type_subtype = wtap_register_file_type_subtype(&netxray_2_00x_info); |
2204 | | |
2205 | | /* |
2206 | | * Register names for backwards compatibility with the |
2207 | | * wtap_filetypes table in Lua. |
2208 | | */ |
2209 | 14 | wtap_register_backwards_compatibility_lua_name("NETXRAY_OLD", |
2210 | 14 | netxray_old_file_type_subtype); |
2211 | 14 | wtap_register_backwards_compatibility_lua_name("NETXRAY_1_0", |
2212 | 14 | netxray_1_0_file_type_subtype); |
2213 | 14 | wtap_register_backwards_compatibility_lua_name("NETXRAY_1_1", |
2214 | 14 | netxray_1_1_file_type_subtype); |
2215 | 14 | wtap_register_backwards_compatibility_lua_name("NETXRAY_2_00x", |
2216 | 14 | netxray_2_00x_file_type_subtype); |
2217 | 14 | } |
2218 | | |
2219 | | /* |
2220 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
2221 | | * |
2222 | | * Local variables: |
2223 | | * c-basic-offset: 8 |
2224 | | * tab-width: 8 |
2225 | | * indent-tabs-mode: t |
2226 | | * End: |
2227 | | * |
2228 | | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
2229 | | * :indentSize=8:tabSize=8:noTabs=false: |
2230 | | */ |