1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. |
---|
5 | * Authors: Daniel Lawson |
---|
6 | * Perry Lorier |
---|
7 | * |
---|
8 | * All rights reserved. |
---|
9 | * |
---|
10 | * This code has been developed by the University of Waikato WAND |
---|
11 | * research group. For further information please see http://www.wand.net.nz/ |
---|
12 | * |
---|
13 | * libtrace is free software; you can redistribute it and/or modify |
---|
14 | * it under the terms of the GNU General Public License as published by |
---|
15 | * the Free Software Foundation; either version 2 of the License, or |
---|
16 | * (at your option) any later version. |
---|
17 | * |
---|
18 | * libtrace is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with libtrace; if not, write to the Free Software |
---|
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
26 | * |
---|
27 | * $Id$ |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | #define _GNU_SOURCE |
---|
32 | #include "config.h" |
---|
33 | #include "common.h" |
---|
34 | #include "libtrace.h" |
---|
35 | #include "libtrace_int.h" |
---|
36 | #include "format_helper.h" |
---|
37 | #include "wag.h" |
---|
38 | |
---|
39 | #include <sys/stat.h> |
---|
40 | #include <fcntl.h> |
---|
41 | #include <assert.h> |
---|
42 | #include <errno.h> |
---|
43 | #include <stdio.h> |
---|
44 | #include <string.h> |
---|
45 | #include <stdlib.h> |
---|
46 | |
---|
47 | #ifdef HAVE_LIMITS_H |
---|
48 | # include <limits.h> |
---|
49 | #endif |
---|
50 | |
---|
51 | #ifdef HAVE_SYS_LIMITS_H |
---|
52 | # include <sys/limits.h> |
---|
53 | #endif |
---|
54 | |
---|
55 | #ifdef WIN32 |
---|
56 | # include <io.h> |
---|
57 | # include <share.h> |
---|
58 | #else |
---|
59 | # include <sys/ioctl.h> |
---|
60 | #endif |
---|
61 | |
---|
62 | static struct libtrace_format_t wag; |
---|
63 | static struct libtrace_format_t wag_trace; |
---|
64 | |
---|
65 | #define DATA(x) ((struct wag_format_data_t *)x->format_data) |
---|
66 | #define DATAOUT(x) ((struct wag_format_data_out_t *)x->format_data) |
---|
67 | |
---|
68 | #define INPUT DATA(libtrace)->input |
---|
69 | #define OUTPUT DATAOUT(libtrace)->output |
---|
70 | #define OPTIONS DATAOUT(libtrace)->options |
---|
71 | |
---|
72 | struct wag_format_data_t { |
---|
73 | /** Information about the current state of the input device */ |
---|
74 | union { |
---|
75 | int fd; |
---|
76 | libtrace_io_t *file; |
---|
77 | } input; |
---|
78 | }; |
---|
79 | |
---|
80 | struct wag_format_data_out_t { |
---|
81 | union { |
---|
82 | struct { |
---|
83 | int level; |
---|
84 | int filemode; |
---|
85 | } zlib; |
---|
86 | } options; |
---|
87 | union { |
---|
88 | int fd; |
---|
89 | libtrace_io_t *file; |
---|
90 | } output; |
---|
91 | }; |
---|
92 | |
---|
93 | static int wag_init_input(libtrace_t *libtrace) { |
---|
94 | libtrace->format_data = calloc((size_t)1, |
---|
95 | sizeof(struct wag_format_data_t)); |
---|
96 | return 0; |
---|
97 | } |
---|
98 | |
---|
99 | static int wag_start_input(libtrace_t *libtrace) |
---|
100 | { |
---|
101 | struct stat buf; |
---|
102 | if (stat(libtrace->uridata,&buf) == -1 ) { |
---|
103 | trace_set_err(libtrace,errno,"stat(%s)",libtrace->uridata); |
---|
104 | return -1; |
---|
105 | } |
---|
106 | #ifndef WIN32 |
---|
107 | if (S_ISCHR(buf.st_mode)) { |
---|
108 | INPUT.fd = open(libtrace->uridata, O_RDONLY); |
---|
109 | if (ioctl (INPUT.fd, CAPTURE_RADIOON, 0) == -1) { |
---|
110 | trace_set_err(libtrace, errno, |
---|
111 | "Could not turn WAG radio on"); |
---|
112 | return -1; |
---|
113 | } |
---|
114 | return 0; |
---|
115 | } |
---|
116 | trace_set_err(libtrace,TRACE_ERR_INIT_FAILED, |
---|
117 | "%s is not a valid char device", |
---|
118 | libtrace->uridata); |
---|
119 | #else |
---|
120 | trace_set_err(libtrace, TRACE_ERR_UNSUPPORTED, |
---|
121 | "WAG cards are not supported in Windows"); |
---|
122 | #endif |
---|
123 | return -1; |
---|
124 | } |
---|
125 | |
---|
126 | static int wtf_init_input(libtrace_t *libtrace) |
---|
127 | { |
---|
128 | libtrace->format_data = calloc((size_t)1, |
---|
129 | sizeof(struct wag_format_data_t)); |
---|
130 | return 0; |
---|
131 | } |
---|
132 | |
---|
133 | static int wtf_start_input(libtrace_t *libtrace) |
---|
134 | { |
---|
135 | if (DATA(libtrace)->input.file) |
---|
136 | return 0; /* success */ |
---|
137 | DATA(libtrace)->input.file = trace_open_file(libtrace); |
---|
138 | |
---|
139 | if (!DATA(libtrace)->input.file) |
---|
140 | return -1; |
---|
141 | |
---|
142 | return 0; /* success */ |
---|
143 | } |
---|
144 | |
---|
145 | static int wtf_init_output(libtrace_out_t *libtrace) { |
---|
146 | libtrace->format_data = malloc(sizeof(struct wag_format_data_out_t)); |
---|
147 | |
---|
148 | OUTPUT.file = 0; |
---|
149 | OPTIONS.zlib.level = 0; |
---|
150 | OPTIONS.zlib.filemode = O_CREAT | O_WRONLY; |
---|
151 | |
---|
152 | return 0; |
---|
153 | } |
---|
154 | |
---|
155 | static int wtf_start_output(libtrace_out_t *libtrace) { |
---|
156 | OUTPUT.file = trace_open_file_out(libtrace, |
---|
157 | OPTIONS.zlib.level, |
---|
158 | OPTIONS.zlib.filemode); |
---|
159 | if (!OUTPUT.file) { |
---|
160 | return -1; |
---|
161 | } |
---|
162 | return 0; |
---|
163 | } |
---|
164 | |
---|
165 | static int wtf_config_output(libtrace_out_t *libtrace, |
---|
166 | trace_option_output_t option, |
---|
167 | void *value) { |
---|
168 | switch(option) { |
---|
169 | #ifdef HAVE_LIBZ |
---|
170 | case TRACE_OPTION_OUTPUT_COMPRESS: |
---|
171 | OPTIONS.zlib.level = *(int*)value; |
---|
172 | assert(OPTIONS.zlib.level>=0 |
---|
173 | && OPTIONS.zlib.level<=9); |
---|
174 | return 0; |
---|
175 | #else |
---|
176 | case TRACE_OPTION_OUTPUT_COMPRESS: |
---|
177 | /* E feature unavailable */ |
---|
178 | trace_set_err_out(libtrace,TRACE_ERR_OPTION_UNAVAIL, |
---|
179 | "zlib not supported"); |
---|
180 | return -1; |
---|
181 | #endif |
---|
182 | default: |
---|
183 | /* E unknown feature */ |
---|
184 | trace_set_err_out(libtrace,TRACE_ERR_UNKNOWN_OPTION, |
---|
185 | "Unknown option"); |
---|
186 | return -1; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | static int wag_pause_input(libtrace_t *libtrace) |
---|
191 | { |
---|
192 | #ifndef WIN32 |
---|
193 | if (ioctl (INPUT.fd, CAPTURE_RADIOON, 0) == -1) { |
---|
194 | trace_set_err(libtrace, errno, |
---|
195 | "Could not turn WAG radio off"); |
---|
196 | } |
---|
197 | close(INPUT.fd); |
---|
198 | return 0; |
---|
199 | #endif |
---|
200 | trace_set_err(libtrace, TRACE_ERR_UNSUPPORTED, |
---|
201 | "WAG cards are not supported in Windows"); |
---|
202 | return -1; |
---|
203 | } |
---|
204 | |
---|
205 | static int wag_fin_input(libtrace_t *libtrace) { |
---|
206 | #ifndef WIN32 |
---|
207 | ioctl (INPUT.fd, CAPTURE_RADIOON, 0); |
---|
208 | #endif |
---|
209 | free(libtrace->format_data); |
---|
210 | return 0; |
---|
211 | } |
---|
212 | |
---|
213 | static int wtf_fin_input(libtrace_t *libtrace) { |
---|
214 | libtrace_io_close(INPUT.file); |
---|
215 | free(libtrace->format_data); |
---|
216 | return 0; |
---|
217 | } |
---|
218 | |
---|
219 | static int wtf_fin_output(libtrace_out_t *libtrace) { |
---|
220 | libtrace_io_close(OUTPUT.file); |
---|
221 | free(libtrace->format_data); |
---|
222 | return 0; |
---|
223 | } |
---|
224 | |
---|
225 | static int wag_read(libtrace_t *libtrace, void *buffer, size_t len, |
---|
226 | int block) { |
---|
227 | size_t framesize; |
---|
228 | char *buf_ptr = (char *)buffer; |
---|
229 | size_t to_read = 0; |
---|
230 | uint16_t magic = 0; |
---|
231 | long fd_flags; |
---|
232 | |
---|
233 | assert(libtrace); |
---|
234 | |
---|
235 | to_read = sizeof(struct frame_t); |
---|
236 | |
---|
237 | #ifndef WIN32 |
---|
238 | fd_flags = fcntl(INPUT.fd, F_GETFL); |
---|
239 | if (fd_flags == -1) { |
---|
240 | /* TODO: Replace with better libtrace-style |
---|
241 | * error handling later */ |
---|
242 | perror("Could not get fd flags"); |
---|
243 | return 0; |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | if (!block) { |
---|
249 | if (fcntl(INPUT.fd, F_SETFL, fd_flags | O_NONBLOCK) == -1) { |
---|
250 | perror("Could not set fd flags"); |
---|
251 | return 0; |
---|
252 | } |
---|
253 | } |
---|
254 | else { |
---|
255 | if (fd_flags & O_NONBLOCK) { |
---|
256 | fd_flags &= ~O_NONBLOCK; |
---|
257 | if (fcntl(INPUT.fd, F_SETFL, fd_flags) == -1) { |
---|
258 | perror("Could not set fd flags"); |
---|
259 | return 0; |
---|
260 | } |
---|
261 | } |
---|
262 | } |
---|
263 | #endif |
---|
264 | |
---|
265 | /* I'm not sure if wag has a memory hole which we can use for |
---|
266 | * zero-copy - something to add in later, I guess */ |
---|
267 | |
---|
268 | while (to_read>0) { |
---|
269 | int ret=read(INPUT.fd,buf_ptr,to_read); |
---|
270 | |
---|
271 | if (ret == -1) { |
---|
272 | if (errno == EINTR) |
---|
273 | continue; |
---|
274 | |
---|
275 | if (errno == EAGAIN) { |
---|
276 | trace_set_err(libtrace, EAGAIN, "EAGAIN"); |
---|
277 | return -1; |
---|
278 | } |
---|
279 | |
---|
280 | trace_set_err(libtrace,errno, |
---|
281 | "read(%s)",libtrace->uridata); |
---|
282 | return -1; |
---|
283 | } |
---|
284 | |
---|
285 | assert(ret>0); |
---|
286 | |
---|
287 | to_read = to_read - ret; |
---|
288 | buf_ptr = buf_ptr + ret; |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | framesize = ntohs(((struct frame_t *)buffer)->size); |
---|
293 | magic = ntohs(((struct frame_t *)buffer)->magic); |
---|
294 | |
---|
295 | if (magic != 0xdaa1) { |
---|
296 | trace_set_err(libtrace, |
---|
297 | TRACE_ERR_BAD_PACKET,"magic number bad or missing"); |
---|
298 | return -1; |
---|
299 | } |
---|
300 | |
---|
301 | /* We should deal. this is called "snapping", but we don't yet */ |
---|
302 | assert(framesize<=len); |
---|
303 | |
---|
304 | buf_ptr = ((char*)buffer + sizeof (struct frame_t)); |
---|
305 | to_read = framesize - sizeof(struct frame_t); |
---|
306 | |
---|
307 | while (to_read>0) { |
---|
308 | int ret=read(INPUT.fd,buf_ptr,(size_t)to_read); |
---|
309 | |
---|
310 | if (ret == -1) { |
---|
311 | if (errno == EINTR) |
---|
312 | continue; |
---|
313 | if (errno == EAGAIN) { |
---|
314 | /* What happens to the frame header?! */ |
---|
315 | trace_set_err(libtrace, EAGAIN, "EAGAIN"); |
---|
316 | return -1; |
---|
317 | } |
---|
318 | trace_set_err(libtrace,errno,"read(%s)", |
---|
319 | libtrace->uridata); |
---|
320 | return -1; |
---|
321 | } |
---|
322 | |
---|
323 | to_read = to_read - ret; |
---|
324 | buf_ptr = buf_ptr + ret; |
---|
325 | } |
---|
326 | return framesize; |
---|
327 | } |
---|
328 | |
---|
329 | |
---|
330 | static int wag_read_packet_versatile(libtrace_t *libtrace, libtrace_packet_t *packet, int block_flag) { |
---|
331 | int numbytes; |
---|
332 | |
---|
333 | if (packet->buf_control == TRACE_CTRL_EXTERNAL || !packet->buffer) { |
---|
334 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
335 | packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); |
---|
336 | } |
---|
337 | |
---|
338 | |
---|
339 | packet->trace = libtrace; |
---|
340 | packet->type = TRACE_RT_DATA_WAG; |
---|
341 | |
---|
342 | if ((numbytes = wag_read(libtrace, (void *)packet->buffer, |
---|
343 | (size_t)RP_BUFSIZE, block_flag)) <= 0) { |
---|
344 | |
---|
345 | return numbytes; |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | packet->header = packet->buffer; |
---|
350 | packet->payload=(char*)packet->buffer+trace_get_framing_length(packet); |
---|
351 | return numbytes; |
---|
352 | } |
---|
353 | |
---|
354 | static int wag_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { |
---|
355 | return wag_read_packet_versatile(libtrace, packet, 1); |
---|
356 | } |
---|
357 | |
---|
358 | static int wtf_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { |
---|
359 | int numbytes; |
---|
360 | void *buffer; |
---|
361 | void *buffer2; |
---|
362 | int framesize; |
---|
363 | int size; |
---|
364 | |
---|
365 | if (packet->buf_control == TRACE_CTRL_EXTERNAL || !packet->buffer) { |
---|
366 | packet->buf_control = TRACE_CTRL_PACKET; |
---|
367 | packet->buffer = malloc((size_t)LIBTRACE_PACKET_BUFSIZE); |
---|
368 | } |
---|
369 | packet->type = TRACE_RT_DATA_WAG; |
---|
370 | buffer2 = buffer = packet->buffer; |
---|
371 | |
---|
372 | numbytes = libtrace_io_read(INPUT.file, buffer, sizeof(struct frame_t)); |
---|
373 | |
---|
374 | if (numbytes == 0) { |
---|
375 | return 0; |
---|
376 | } |
---|
377 | |
---|
378 | if (numbytes != sizeof(struct frame_t)) { |
---|
379 | int err=errno; |
---|
380 | trace_set_err(libtrace,err, |
---|
381 | "read(%s,frame_t)",packet->trace->uridata); |
---|
382 | printf("failed to read header=%i\n",err); |
---|
383 | return -1; |
---|
384 | } |
---|
385 | |
---|
386 | if (htons(((struct frame_t *)buffer)->magic) != 0xdaa1) { |
---|
387 | trace_set_err(libtrace, |
---|
388 | TRACE_ERR_BAD_PACKET,"Insufficient magic (%04x)",htons(((struct frame_t *)buffer)->magic)); |
---|
389 | return -1; |
---|
390 | } |
---|
391 | |
---|
392 | framesize = ntohs(((struct frame_t *)buffer)->size); |
---|
393 | buffer2 = (char*)buffer + sizeof(struct frame_t); |
---|
394 | size = framesize - sizeof(struct frame_t); |
---|
395 | assert(size < LIBTRACE_PACKET_BUFSIZE); |
---|
396 | assert(size > 0); |
---|
397 | |
---|
398 | if ((numbytes=libtrace_io_read(INPUT.file, buffer2, (size_t)size)) |
---|
399 | != size) { |
---|
400 | trace_set_err(libtrace, |
---|
401 | errno,"read(%s,buffer)",packet->trace->uridata); |
---|
402 | return -1; |
---|
403 | } |
---|
404 | |
---|
405 | packet->header = packet->buffer; |
---|
406 | packet->payload=(char*)packet->buffer+trace_get_framing_length(packet); |
---|
407 | return framesize; |
---|
408 | |
---|
409 | } |
---|
410 | |
---|
411 | static int wtf_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) |
---|
412 | { |
---|
413 | int numbytes =0 ; |
---|
414 | if (packet->trace->format != &wag_trace) { |
---|
415 | trace_set_err_out(libtrace,TRACE_ERR_NO_CONVERSION, |
---|
416 | "Cannot convert to wag trace format from %s format yet", |
---|
417 | packet->trace->format->name); |
---|
418 | return -1; |
---|
419 | } |
---|
420 | |
---|
421 | /* We could just read from packet->buffer, but I feel it is more |
---|
422 | * technically correct to read from the header and payload pointers |
---|
423 | */ |
---|
424 | if ((numbytes = libtrace_io_write(OUTPUT.file, packet->header, |
---|
425 | trace_get_framing_length(packet))) |
---|
426 | !=(int)trace_get_framing_length(packet)) { |
---|
427 | trace_set_err_out(libtrace,errno, |
---|
428 | "write(%s)",packet->trace->uridata); |
---|
429 | return -1; |
---|
430 | } |
---|
431 | if ((numbytes = libtrace_io_write(OUTPUT.file, packet->payload, |
---|
432 | trace_get_capture_length(packet)) |
---|
433 | != (int)trace_get_capture_length(packet))) { |
---|
434 | trace_set_err_out(libtrace, |
---|
435 | errno,"write(%s)",packet->trace->uridata); |
---|
436 | return -1; |
---|
437 | } |
---|
438 | return numbytes; |
---|
439 | } |
---|
440 | |
---|
441 | static libtrace_linktype_t wag_get_link_type(const libtrace_packet_t *packet UNUSED) { |
---|
442 | return TRACE_TYPE_80211; |
---|
443 | } |
---|
444 | |
---|
445 | static libtrace_direction_t wag_get_direction(const libtrace_packet_t *packet) { |
---|
446 | struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer; |
---|
447 | if (wagptr->hdr.type == 0) { |
---|
448 | return wagptr->hdr.subtype; |
---|
449 | } |
---|
450 | return -1; |
---|
451 | } |
---|
452 | |
---|
453 | static uint64_t wag_get_erf_timestamp(const libtrace_packet_t *packet) { |
---|
454 | struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer; |
---|
455 | uint64_t timestamp = 0; |
---|
456 | timestamp = ((uint64_t)(ntohl(wagptr->ts.secs)) << 32) | (uint64_t)(ntohl(wagptr->ts.subsecs)); |
---|
457 | return timestamp; |
---|
458 | } |
---|
459 | |
---|
460 | static int wag_get_capture_length(const libtrace_packet_t *packet) { |
---|
461 | |
---|
462 | struct frame_t * wag_frame_data = (struct frame_t *)packet->header; |
---|
463 | |
---|
464 | if (wag_frame_data->subtype == FRAME_SUBTYPE_DATA_RX) { |
---|
465 | struct frame_data_rx_t *wag_hdr = |
---|
466 | (struct frame_data_rx_t *)packet->header; |
---|
467 | return ntohs(wag_hdr->rxinfo.length); |
---|
468 | } |
---|
469 | |
---|
470 | if (wag_frame_data->subtype == FRAME_SUBTYPE_DATA_TX) { |
---|
471 | struct frame_data_tx_t *wag_hdr = |
---|
472 | (struct frame_data_tx_t *)packet->header; |
---|
473 | return ntohs(wag_hdr->txinfo.length); |
---|
474 | } |
---|
475 | |
---|
476 | /* default option - not optimal as there tends to be an |
---|
477 | * extra 2 bytes floating around somewhere */ |
---|
478 | return ntohs(((struct frame_t *)packet->header)->size) |
---|
479 | -sizeof(struct frame_data_rx_t); |
---|
480 | } |
---|
481 | |
---|
482 | static int wag_get_wire_length(const libtrace_packet_t *packet) { |
---|
483 | struct frame_t * wag_frame_data = (struct frame_t *)packet->header; |
---|
484 | |
---|
485 | |
---|
486 | if (wag_frame_data->subtype == FRAME_SUBTYPE_DATA_RX) { |
---|
487 | struct frame_data_rx_t *wag_hdr = |
---|
488 | (struct frame_data_rx_t *)packet->header; |
---|
489 | return ntohs(wag_hdr->rxinfo.length); |
---|
490 | } |
---|
491 | |
---|
492 | if (wag_frame_data->subtype == FRAME_SUBTYPE_DATA_TX) { |
---|
493 | struct frame_data_tx_t *wag_hdr = |
---|
494 | (struct frame_data_tx_t *)packet->header; |
---|
495 | return ntohs(wag_hdr->txinfo.length); |
---|
496 | } |
---|
497 | |
---|
498 | /* default option - not optimal as there tends to be an |
---|
499 | * extra 2 bytes floating around somewhere */ |
---|
500 | return ntohs(((struct frame_t *)packet->header)->size) |
---|
501 | -sizeof(struct frame_data_rx_t); |
---|
502 | } |
---|
503 | |
---|
504 | static int wag_get_framing_length(UNUSED const libtrace_packet_t *packet) { |
---|
505 | /* There's an extra two bytes floating around somewhere that |
---|
506 | * we can't account for! */ |
---|
507 | return sizeof(struct frame_data_rx_t); |
---|
508 | } |
---|
509 | |
---|
510 | static int wag_get_fd(const libtrace_t *trace) { |
---|
511 | return DATA(trace)->input.fd; |
---|
512 | } |
---|
513 | |
---|
514 | static struct libtrace_eventobj_t trace_event_wag(libtrace_t *trace, libtrace_packet_t *packet) |
---|
515 | { |
---|
516 | struct libtrace_eventobj_t event = {0,0,0.0,0}; |
---|
517 | libtrace_err_t read_err; |
---|
518 | |
---|
519 | assert(trace); |
---|
520 | assert(packet); |
---|
521 | |
---|
522 | /* We could probably just call get_fd here */ |
---|
523 | if (trace->format->get_fd) { |
---|
524 | event.fd = trace->format->get_fd(trace); |
---|
525 | } else { |
---|
526 | event.fd = 0; |
---|
527 | } |
---|
528 | |
---|
529 | event.size = wag_read_packet_versatile(trace, packet, 0); |
---|
530 | if (event.size == -1) { |
---|
531 | read_err = trace_get_err(trace); |
---|
532 | if (read_err.err_num == EAGAIN) { |
---|
533 | event.type = TRACE_EVENT_IOWAIT; |
---|
534 | } |
---|
535 | else { |
---|
536 | printf("Packet error\n"); |
---|
537 | event.type = TRACE_EVENT_PACKET; |
---|
538 | } |
---|
539 | } else if (event.size == 0) { |
---|
540 | event.type = TRACE_EVENT_TERMINATE; |
---|
541 | } else { |
---|
542 | event.type = TRACE_EVENT_PACKET; |
---|
543 | } |
---|
544 | |
---|
545 | return event; |
---|
546 | } |
---|
547 | |
---|
548 | static void wag_help(void) { |
---|
549 | printf("wag format module: $Revision$\n"); |
---|
550 | printf("Supported input URIs:\n"); |
---|
551 | printf("\twag:/dev/wagn\n"); |
---|
552 | printf("\n"); |
---|
553 | printf("\te.g.: wag:/dev/wag0\n"); |
---|
554 | printf("\n"); |
---|
555 | printf("Supported output URIs:\n"); |
---|
556 | printf("\tNone\n"); |
---|
557 | printf("\n"); |
---|
558 | } |
---|
559 | |
---|
560 | static void wtf_help(void) { |
---|
561 | printf("wag trace format module: $Revision$\n"); |
---|
562 | printf("Supported input URIs:\n"); |
---|
563 | printf("\twtf:/path/to/trace.wag\n"); |
---|
564 | printf("\twtf:/path/to/trace.wag.gz\n"); |
---|
565 | printf("\n"); |
---|
566 | printf("\te.g.: wtf:/tmp/trace.wag.gz\n"); |
---|
567 | printf("\n"); |
---|
568 | printf("Supported output URIs:\n"); |
---|
569 | printf("\twtf:/path/to/trace.wag\n"); |
---|
570 | printf("\twtf:/path/to/trace.wag.gz\n"); |
---|
571 | printf("\n"); |
---|
572 | printf("\te.g.: wtf:/tmp/trace.wag.gz\n"); |
---|
573 | printf("\n"); |
---|
574 | } |
---|
575 | |
---|
576 | static struct libtrace_format_t wag = { |
---|
577 | "wag", |
---|
578 | "$Id$", |
---|
579 | TRACE_FORMAT_WAG, |
---|
580 | wag_init_input, /* init_input */ |
---|
581 | NULL, /* config_input */ |
---|
582 | wag_start_input, /* start_input */ |
---|
583 | wag_pause_input, /* pause_input */ |
---|
584 | NULL, /* init_output */ |
---|
585 | NULL, /* config_output */ |
---|
586 | NULL, /* start_output */ |
---|
587 | wag_fin_input, /* fin_input */ |
---|
588 | NULL, /* fin_output */ |
---|
589 | wag_read_packet, /* read_packet */ |
---|
590 | NULL, /* fin_packet */ |
---|
591 | NULL, /* write_packet */ |
---|
592 | wag_get_link_type, /* get_link_type */ |
---|
593 | wag_get_direction, /* get_direction */ |
---|
594 | NULL, /* set_direction */ |
---|
595 | wag_get_erf_timestamp, /* get_erf_timestamp */ |
---|
596 | NULL, /* get_timeval */ |
---|
597 | NULL, /* get_seconds */ |
---|
598 | NULL, /* seek_erf */ |
---|
599 | NULL, /* seek_timeval */ |
---|
600 | NULL, /* seek_seconds */ |
---|
601 | wag_get_capture_length, /* get_capture_length */ |
---|
602 | wag_get_wire_length, /* get_wire_length */ |
---|
603 | wag_get_framing_length, /* get_framing_length */ |
---|
604 | NULL, /* set_capture_length */ |
---|
605 | wag_get_fd, /* get_fd */ |
---|
606 | trace_event_wag, /* trace_event */ |
---|
607 | wag_help, /* help */ |
---|
608 | NULL /* next pointer */ |
---|
609 | }; |
---|
610 | |
---|
611 | /* wtf stands for Wag Trace Format */ |
---|
612 | |
---|
613 | static struct libtrace_format_t wag_trace = { |
---|
614 | "wtf", |
---|
615 | "$Id$", |
---|
616 | TRACE_FORMAT_WAG, |
---|
617 | wtf_init_input, /* init_input */ |
---|
618 | NULL, /* config input */ |
---|
619 | wtf_start_input, /* start input */ |
---|
620 | NULL, /* pause_input */ |
---|
621 | wtf_init_output, /* init_output */ |
---|
622 | wtf_config_output, /* config_output */ |
---|
623 | wtf_start_output, /* start output */ |
---|
624 | wtf_fin_input, /* fin_input */ |
---|
625 | wtf_fin_output, /* fin_output */ |
---|
626 | wtf_read_packet, /* read_packet */ |
---|
627 | NULL, /* fin_packet */ |
---|
628 | wtf_write_packet, /* write_packet */ |
---|
629 | wag_get_link_type, /* get_link_type */ |
---|
630 | wag_get_direction, /* get_direction */ |
---|
631 | NULL, /* set_direction */ |
---|
632 | wag_get_erf_timestamp, /* get_erf_timestamp */ |
---|
633 | NULL, /* get_timeval */ |
---|
634 | NULL, /* get_seconds */ |
---|
635 | NULL, /* seek_erf */ |
---|
636 | NULL, /* seek_timeval */ |
---|
637 | NULL, /* seek_seconds */ |
---|
638 | wag_get_capture_length, /* get_capture_length */ |
---|
639 | wag_get_wire_length, /* get_wire_length */ |
---|
640 | wag_get_framing_length, /* get_framing_length */ |
---|
641 | NULL, /* set_capture_length */ |
---|
642 | NULL, /* get_fd */ |
---|
643 | trace_event_trace, /* trace_event */ |
---|
644 | wtf_help, /* help */ |
---|
645 | NULL /* next pointer */ |
---|
646 | }; |
---|
647 | |
---|
648 | |
---|
649 | void wag_constructor(void) { |
---|
650 | register_format(&wag); |
---|
651 | register_format(&wag_trace); |
---|
652 | } |
---|