Changeset 49babe0
- Timestamp:
- 02/15/06 15:18:38 (15 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- 643105b
- Parents:
- 6eb91ff
- Location:
- lib
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/Makefile.am
r7068467 r49babe0 1 1 lib_LTLIBRARIES = libtrace.la 2 include_HEADERS = libtrace.h dagformat.h wag.h lt_inttypes.h daglegacy.h 2 include_HEADERS = libtrace.h dagformat.h wag.h lt_inttypes.h daglegacy.h rt_protocol.h 3 3 4 4 extra_DIST = format_template.c 5 5 libtrace_la_SOURCES = trace.c fifo.c fifo.h common.h \ 6 format_erf.c format_pcap.c format_wag.c format_legacy.c \6 format_erf.c format_pcap.c format_wag.c format_legacy.c format_rt.c\ 7 7 format_helper.c format_helper.h \ 8 8 parse_cmd.c parse_cmd.h libtrace_int.h lt_inttypes.h \ -
lib/format_wag.c
r6eb91ff r49babe0 267 267 static int wag_read(struct libtrace_t *libtrace, void *buffer, size_t len) { 268 268 int numbytes; 269 size_t framesize; 270 assert(libtrace); 271 272 if (buffer == 0) 273 buffer = malloc(len); 274 275 /* read in wag_frame_hdr */ 276 if ((numbytes = read(INPUT.fd, 277 buffer, 278 sizeof(struct wag_frame_hdr))) != sizeof(struct wag_frame_hdr)) { 279 return -1; 280 } 281 282 framesize = ntohs(((struct wag_frame_hdr *)buffer)->size); 283 284 if (framesize > len) { 285 return -1; 286 } 287 288 /* read in remainder of packet */ 289 if((numbytes = read(INPUT.fd, 290 (char*)buffer + sizeof(struct wag_frame_hdr), 291 framesize - sizeof(struct wag_frame_hdr))) != 292 (framesize - sizeof(struct wag_frame_hdr))) { 293 294 return -1; 295 296 } 297 269 int framesize; 270 char *buf_ptr = (char *)buffer; 271 int to_read = 0; 272 uint16_t magic = 0; 273 uint16_t lctr = 0; 274 275 assert(libtrace); 276 277 to_read = sizeof(struct frame_t); 278 279 while (to_read>0) { 280 int ret=read(INPUT.fd,buf_ptr,to_read); 281 282 if (ret == -1) { 283 if (errno == EINTR || errno==EAGAIN) 284 continue; 285 perror("read(frame)"); 286 return -1; 287 } 288 289 assert(ret>0); 290 291 to_read = to_read - ret; 292 buf_ptr = buf_ptr + ret; 293 } 294 295 framesize = ntohs(((struct frame_t *)buffer)->size); 296 magic = ntohs(((struct frame_t *)buffer)->magic); 297 298 if (magic != 0xdaa1) { 299 printf("Magic number is BAD!\n"); 300 return -1; 301 } 302 303 if (framesize > len) { 304 printf("Framesize > len\n"); 305 return -1; 306 } 307 308 buf_ptr = buffer + sizeof (struct frame_t); 309 to_read = framesize - sizeof(struct frame_t); 310 311 while (to_read>0) { 312 int ret=read(INPUT.fd,buf_ptr,to_read); 313 314 if (ret == -1) { 315 if (errno == EINTR || errno==EAGAIN) 316 continue; 317 perror("read(frame)"); 318 return -1; 319 } 320 321 // assert(ret>0); 322 323 to_read = to_read - ret; 324 buf_ptr = buf_ptr + ret; 325 } 298 326 return framesize; 299 327 } … … 336 364 337 365 338 if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct wag_frame_hdr))) == -1) {366 if ((numbytes = LIBTRACE_READ(INPUT.file, buffer, sizeof(struct frame_t))) == -1) { 339 367 perror("libtrace_read"); 340 368 return -1; … … 345 373 } 346 374 347 framesize = ntohs(((struct wag_frame_hdr*)buffer)->size);348 buffer2 = (char*)buffer + sizeof(struct wag_frame_hdr);349 size = framesize - sizeof(struct wag_frame_hdr);375 framesize = ntohs(((struct frame_t *)buffer)->size); 376 buffer2 = (char*)buffer + sizeof(struct frame_t); 377 size = framesize - sizeof(struct frame_t); 350 378 assert(size < LIBTRACE_PACKET_BUFSIZE); 351 379 … … 391 419 392 420 static int8_t wag_get_direction(const struct libtrace_packet_t *packet) { 393 struct wag_data_frame *wagptr = (struct wag_data_frame*)packet->buffer;421 struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer; 394 422 if (wagptr->hdr.type == 0) { 395 423 return wagptr->hdr.subtype; … … 399 427 400 428 static uint64_t wag_get_erf_timestamp(const struct libtrace_packet_t *packet) { 401 struct wag_data_frame *wagptr = (struct wag_data_frame*)packet->buffer;429 struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer; 402 430 uint64_t timestamp = 0; 403 431 timestamp = ((uint64_t)(ntohl(wagptr->ts.secs)) << 32) | (uint64_t)(ntohl(wagptr->ts.subsecs)); … … 406 434 407 435 static int wag_get_capture_length(const struct libtrace_packet_t *packet) { 408 struct wag_data_frame *wagptr = (struct wag_data_frame*)packet->buffer;436 struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer; 409 437 return ntohs(wagptr->hdr.size); 410 438 } 411 439 412 440 static int wag_get_wire_length(const struct libtrace_packet_t *packet) { 413 struct wag_data_frame *wagptr = (struct wag_data_frame*)packet->buffer;441 struct frame_data_rx_t *wagptr = (struct frame_data_rx_t *)packet->buffer; 414 442 return ntohs(wagptr->hdr.size); 415 443 } 416 444 417 445 static int wag_get_framing_length(const struct libtrace_packet_t *packet) { 418 return sizeof(struct wag_data_frame);446 return sizeof(struct frame_data_rx_t); 419 447 } 420 448 -
lib/libtrace.h
r7068467 r49babe0 95 95 void *buffer; 96 96 size_t size; 97 uint8_t type; // rt protocol type for the packet 97 98 buf_control_t buf_control; 98 99 } libtrace_packet_t; … … 680 681 /** Get the length of the capture framing headers. 681 682 * @param packet the packet opaque pointer 682 * @return the size of the packet as it was on the wire.683 * @return the size of the framing header. 683 684 * @author Perry Lorier 684 685 * @author Daniel Lawson -
lib/trace.c
r7068467 r49babe0 437 437 if (libtrace->format->start_input) { 438 438 int ret=libtrace->format->start_input(libtrace); 439 if ( !ret) {439 if (ret < 0) { 440 440 return ret; 441 441 } -
lib/wag.h
r7068467 r49babe0 3 3 * 4 4 * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand. 5 * Authors: Daniel Lawson 6 * Perry Lorier 7 * 5 * Authors: Daniel Lawson 6 * Perry Lorier 7 * 8 8 * All rights reserved. 9 9 * 10 * This code has been developed by the University of Waikato WAND 10 * This code has been developed by the University of Waikato WAND 11 11 * research group. For further information please see http://www.wand.net.nz/ 12 12 * … … 28 28 * 29 29 */ 30 #ifndef _WAG_H_31 #define _WAG_H_32 30 33 /* Generic field breakdowns */ 34 struct wag_frame_hdr { 35 uint16_t magic; 36 uint16_t size; 37 uint16_t type; 38 uint16_t subtype; 31 #ifndef _WAG_H 32 #define _WAG_H 33 34 // This is the WAG magic number - used to delimit frames 35 #define WAG_MAGIC (0xdaa1) 36 37 // Define frame types 38 #define FRAME_TYPE_DATA (0x0000) 39 #define FRAME_TYPE_UNDEFINED (0xffff) 40 41 // Define frame subtypes 42 #define FRAME_SUBTYPE_DATA_RX (0x0000) 43 #define FRAME_SUBTYPE_DATA_TX (0x0001) 44 45 // This is the common part of the frame header. 46 // We synchronise by scanning a stream to look for the magic number (WAG_MAGIC). 47 // We can then tell the size and type of this frame, and pass over it if necessary. 48 struct frame_t { 49 uint16_t magic; // magic number (0xdaa1) 50 uint16_t size; // total frame size in bytes 51 uint16_t type; // frame type 52 uint16_t subtype; // frame subtype 39 53 }; 40 54 41 struct wag_timestamp { 42 uint32_t secs; 43 uint32_t subsecs; 55 /////////////////////////////////////////////////////////////////////////////////// 56 // 57 // Frames that the radio part of the WAG framework understands 58 // 59 /////////////////////////////////////////////////////////////////////////////////// 60 // Common subfields... 61 62 // timestamp 63 struct timestamp_t { 64 uint32_t secs; // seconds since start of 01-01-1970 65 uint32_t subsecs; // (1/(2^32))ths of a second 44 66 }; 45 67 46 / * Received packet frame fields */47 struct wag_stream_info{68 // frame stream information 69 struct strinfo_t { 48 70 uint16_t unused_1; 49 71 uint16_t unused_2; … … 52 74 }; 53 75 54 struct wag_plcp_hdr { 55 uint8_t signal; 56 uint8_t service; 57 uint16_t length; 76 // Type: DATA, Subtype: RX 77 struct frame_data_rx_t { 78 struct frame_t hdr; // common frame header 79 struct strinfo_t strinfo; // stream status 80 struct timestamp_t ts; // timestamp of reception of this frame 81 struct { 82 uint8_t rssi; // receive signal strength of this frame 83 uint8_t rxstatus; // rx status bits from the modem 84 uint16_t length; // length in bytes of the frame payload 85 struct { 86 uint8_t signal; // 802.11PLCP signal field 87 uint8_t service; // 802.11PLCP service field 88 uint16_t length; } plcp; } rxinfo; // 802.11PLCP length field (uS) 89 char data[0]; // placeholder to allow payload access 58 90 }; 59 91 60 struct wag_rxparams { 61 uint8_t rssi; 62 uint8_t rxstatus; 63 uint16_t length; 64 struct wag_plcp_hdr plcp; 65 }; 66 67 struct wag_data_frame { 68 struct wag_frame_hdr hdr; 69 struct wag_stream_info strinfo; 70 struct wag_timestamp ts; 71 struct wag_rxparams rxinfo; 72 char data[1]; 73 }; 74 75 /* Transmit packet frame fields */ 76 struct wag_txparams { 77 uint8_t gain; 78 uint8_t mode; 79 uint16_t length; 80 uint32_t unused_1; 81 }; 82 83 struct wag_tx_data_frame { 84 struct wag_frame_hdr hdr; 85 uint32_t unused_1; 86 uint32_t unused_2; 87 struct wag_txparams txinfo; 88 char data[1]; 92 // Type: DATA, Subtype: TX 93 struct frame_data_tx_t { 94 struct frame_t hdr; // common frame header 95 uint64_t unused_1; // 96 uint64_t unused_2; // 97 struct { 98 uint8_t gain; // tx gain with which to send this packet 99 uint8_t mode; // tx mode with which to send this packet 100 uint16_t length; // length in bytes of the frame payload 101 uint32_t unused_1; } txinfo; // 102 char data[0]; // placeholder to allow payload access 89 103 }; 90 104 91 105 struct ieee_802_11_header { 92 unsigned intprotocol:2;93 unsigned inttype:2;94 unsigned intsubtype:4;95 unsigned intto_ds:1;96 unsigned intfrom_ds:1;97 unsigned intmore_frag:1;98 unsigned intretry:1;99 unsigned intpower:1;100 unsigned intmore_data:1;101 unsigned intwep:1;102 unsigned intorder:1;103 104 105 106 107 108 109 uint8_tdata[1];106 uint8_t protocol:2; 107 uint8_t type:2; 108 uint8_t subtype:4; 109 uint8_t to_ds:1; 110 uint8_t from_ds:1; 111 uint8_t more_frag:1; 112 uint8_t retry:1; 113 uint8_t power:1; 114 uint8_t more_data:1; 115 uint8_t wep:1; 116 uint8_t order:1; 117 uint16_t duration; 118 uint8_t mac1[6]; 119 uint8_t mac2[6]; 120 uint8_t mac3[6]; 121 uint16_t SeqCtl; 122 uint8_t mac4[6]; 123 uint8_t data[1]; 110 124 }; 111 125 112 126 struct ieee_802_11_payload { 113 114 uint8_tdata[1];127 uint16_t type; 128 uint8_t data[1]; 115 129 }; 116 130 131 117 132 #endif
Note: See TracChangeset
for help on using the changeset viewer.