1 /* -*- mode: c; c-basic-offset: 2 -*- */
4 * nosy-dump - Interface to snoop mode driver for TI PCILynx 1394 controllers
5 * Copyright (C) 2002-2006 Kristian Høgsberg
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <sys/ioctl.h>
38 #include "nosy-user.h"
39 #include "nosy-dump.h"
42 PACKET_FIELD_DETAIL
= 0x01,
43 PACKET_FIELD_DATA_LENGTH
= 0x02,
44 /* Marks the fields we print in transaction view. */
45 PACKET_FIELD_TRANSACTION
= 0x04
49 print_packet(unsigned long *data
, size_t length
);
51 decode_link_packet(struct link_packet
*packet
, size_t length
,
52 int include_flags
, int exclude_flags
);
55 sig_t sys_sigint_handler
;
57 static char *option_nosy_device
= "/dev/nosy";
58 static char *option_view
= "packet";
59 static char *option_output
= NULL
;
60 static char *option_input
= NULL
;
61 static int option_hex
;
62 static int option_iso
;
63 static int option_cycle_start
;
64 static int option_version
;
65 static int option_verbose
;
73 static const struct poptOption options
[] = {
77 argInfo
: POPT_ARG_STRING
,
78 arg
: &option_nosy_device
,
79 descrip
: "Path to nosy device.",
84 argInfo
: POPT_ARG_STRING
,
86 descrip
: "Specify view of bus traffic: packet, transaction or stats.",
92 argInfo
: POPT_ARG_NONE
,
94 descrip
: "Print each packet in hex.",
98 argInfo
: POPT_ARG_NONE
,
100 descrip
: "Print iso packets.",
103 longName
: "cycle-start",
104 argInfo
: POPT_ARG_NONE
,
105 arg
: &option_cycle_start
,
106 descrip
: "Print cycle start packets.",
111 argInfo
: POPT_ARG_NONE
,
112 arg
: &option_verbose
,
113 descrip
: "Verbose packet view.",
118 argInfo
: POPT_ARG_STRING
,
120 descrip
: "Log to output file.",
121 argDescrip
: "FILENAME"
126 argInfo
: POPT_ARG_STRING
,
128 descrip
: "Decode log from file.",
129 argDescrip
: "FILENAME"
133 argInfo
: POPT_ARG_NONE
,
134 arg
: &option_version
,
135 descrip
: "Specify print version info.",
142 sigint_handler(int signal_num
)
146 /* Allow all Ctrl-C's except the first to interrupt the program in
149 signal(SIGINT
, SIG_DFL
);
154 subaction_create(unsigned long *data
, size_t length
)
156 struct subaction
*sa
;
158 /* we put the ack in the subaction struct for easy access. */
159 sa
= malloc(sizeof *sa
- sizeof sa
->packet
+ length
);
160 sa
->ack
= data
[length
/ 4 - 1];
162 memcpy (&sa
->packet
, data
, length
);
168 subaction_destroy(struct subaction
*sa
)
173 struct list pending_transaction_list
=
174 { &pending_transaction_list
, &pending_transaction_list
};
176 struct link_transaction
*
177 link_transaction_lookup(int request_node
, int response_node
, int tlabel
)
179 struct link_transaction
*t
;
181 list_for_each_entry(t
, &pending_transaction_list
, link
) {
182 if (t
->request_node
== request_node
&&
183 t
->response_node
== response_node
&&
188 t
= malloc(sizeof *t
);
189 t
->request_node
= request_node
;
190 t
->response_node
= response_node
;
192 list_init(&t
->request_list
);
193 list_init(&t
->response_list
);
195 list_append(&pending_transaction_list
, &t
->link
);
201 link_transaction_destroy(struct link_transaction
*t
)
203 while (!list_empty(&t
->request_list
)) {
204 struct subaction
*sa
= list_head(&t
->request_list
, struct subaction
, link
);
205 list_remove(&sa
->link
);
206 subaction_destroy(sa
);
209 while (!list_empty(&t
->response_list
)) {
210 struct subaction
*sa
= list_head(&t
->response_list
, struct subaction
, link
);
211 list_remove(&sa
->link
);
212 subaction_destroy(sa
);
218 struct protocol_decoder
{
220 int (*decode
)(struct link_transaction
*t
);
223 static struct protocol_decoder protocol_decoders
[] = {
224 { "FCP", decode_fcp
}
228 handle_transaction(struct link_transaction
*t
)
230 struct subaction
*sa
;
233 for (i
= 0; i
< array_length(protocol_decoders
); i
++)
234 if (protocol_decoders
[i
].decode(t
))
237 /* HACK: decode only fcp right now. */
240 decode_link_packet(&t
->request
->packet
, t
->request
->length
,
241 PACKET_FIELD_TRANSACTION
, 0);
243 decode_link_packet(&t
->response
->packet
, t
->request
->length
,
244 PACKET_FIELD_TRANSACTION
, 0);
246 printf("[no response]");
248 if (option_verbose
) {
249 list_for_each_entry(sa
, &t
->request_list
, link
)
250 print_packet((unsigned long *) &sa
->packet
, sa
->length
);
251 list_for_each_entry(sa
, &t
->response_list
, link
)
252 print_packet((unsigned long *) &sa
->packet
, sa
->length
);
256 link_transaction_destroy(t
);
260 clear_pending_transaction_list(void)
262 struct link_transaction
*t
;
264 while (!list_empty(&pending_transaction_list
)) {
265 t
= list_head(&pending_transaction_list
, struct link_transaction
, link
);
266 list_remove(&t
->link
);
267 link_transaction_destroy(t
);
268 /* print unfinished transactions */
272 static const char * const tcode_names
[] = {
273 "write_quadlet_request",
274 "write_block_request",
277 "read_quadlet_request",
278 "read_block_request",
279 "read_quadlet_response",
280 "read_block_response",
287 static const char * const ack_names
[] = {
306 static const char * const rcode_names
[] = {
317 static const char * const retry_names
[] = {
335 struct packet_field
*fields
;
339 struct packet_field
{
340 const char *name
; /* Short name for field. */
341 int offset
; /* Location of field, specified in bits.
342 * Negative means from end of packet */
343 int width
; /* Width of field, 0 means use data_length. */
344 int flags
; /* Show options. */
345 const char * const *value_names
;
348 #define COMMON_REQUEST_FIELDS \
349 { "dest", 0, 16, PACKET_FIELD_TRANSACTION }, \
351 { "rt", 22, 2, PACKET_FIELD_DETAIL, retry_names }, \
352 { "tcode", 24, 4, PACKET_FIELD_TRANSACTION, tcode_names }, \
353 { "pri", 28, 4, PACKET_FIELD_DETAIL }, \
354 { "src", 32, 16, PACKET_FIELD_TRANSACTION }, \
355 { "offs", 48, 48, PACKET_FIELD_TRANSACTION }
357 #define COMMON_RESPONSE_FIELDS \
360 { "rt", 22, 2, PACKET_FIELD_DETAIL, retry_names }, \
361 { "tcode", 24, 4, 0, tcode_names }, \
362 { "pri", 28, 4, PACKET_FIELD_DETAIL }, \
364 { "rcode", 48, 4, PACKET_FIELD_TRANSACTION, rcode_names }
366 struct packet_field read_quadlet_request_fields
[] = {
367 COMMON_REQUEST_FIELDS
,
368 { "crc", 96, 32, PACKET_FIELD_DETAIL
},
369 { "ack", 156, 4, 0, ack_names
}
372 struct packet_field read_quadlet_response_fields
[] = {
373 COMMON_RESPONSE_FIELDS
,
374 { "data", 96, 32, PACKET_FIELD_TRANSACTION
},
375 { "crc", 128, 32, PACKET_FIELD_DETAIL
},
376 { "ack", 188, 4, 0, ack_names
}
379 struct packet_field read_block_request_fields
[] = {
380 COMMON_REQUEST_FIELDS
,
381 { "data_length", 96, 16, PACKET_FIELD_TRANSACTION
},
382 { "extended_tcode", 112, 16 },
383 { "crc", 128, 32, PACKET_FIELD_DETAIL
},
384 { "ack", 188, 4, 0, ack_names
},
387 struct packet_field block_response_fields
[] = {
388 COMMON_RESPONSE_FIELDS
,
389 { "data_length", 96, 16, PACKET_FIELD_DATA_LENGTH
},
390 { "extended_tcode", 112, 16 },
391 { "crc", 128, 32, PACKET_FIELD_DETAIL
},
392 { "data", 160, 0, PACKET_FIELD_TRANSACTION
},
393 { "crc", -64, 32, PACKET_FIELD_DETAIL
},
394 { "ack", -4, 4, 0, ack_names
}
397 struct packet_field write_quadlet_request_fields
[] = {
398 COMMON_REQUEST_FIELDS
,
399 { "data", 96, 32, PACKET_FIELD_TRANSACTION
},
400 { "ack", -4, 4, 0, ack_names
}
403 struct packet_field block_request_fields
[] = {
404 COMMON_REQUEST_FIELDS
,
405 { "data_length", 96, 16, PACKET_FIELD_DATA_LENGTH
| PACKET_FIELD_TRANSACTION
},
406 { "extended_tcode", 112, 16, PACKET_FIELD_TRANSACTION
},
407 { "crc", 128, 32, PACKET_FIELD_DETAIL
},
408 { "data", 160, 0, PACKET_FIELD_TRANSACTION
},
409 { "crc", -64, 32, PACKET_FIELD_DETAIL
},
410 { "ack", -4, 4, 0, ack_names
}
413 struct packet_field write_response_fields
[] = {
414 COMMON_RESPONSE_FIELDS
,
415 { "reserved", 64, 32, PACKET_FIELD_DETAIL
},
416 { "ack", -4, 4, 0, ack_names
}
419 struct packet_field iso_data_fields
[] = {
420 { "data_length", 0, 16, PACKET_FIELD_DATA_LENGTH
},
422 { "channel", 18, 6 },
423 { "tcode", 24, 4, 0, tcode_names
},
425 { "crc", 32, 32, PACKET_FIELD_DETAIL
},
427 { "crc", -64, 32, PACKET_FIELD_DETAIL
},
428 { "ack", -4, 4, 0, ack_names
}
431 static struct packet_info packet_info
[] = {
433 .name
= "write_quadlet_request",
434 .type
= PACKET_REQUEST
,
435 .response_tcode
= TCODE_WRITE_RESPONSE
,
436 .fields
= write_quadlet_request_fields
,
437 .field_count
= array_length(write_quadlet_request_fields
)
440 .name
= "write_block_request",
441 .type
= PACKET_REQUEST
,
442 .response_tcode
= TCODE_WRITE_RESPONSE
,
443 .fields
= block_request_fields
,
444 .field_count
= array_length(block_request_fields
)
447 .name
= "write_response",
448 .type
= PACKET_RESPONSE
,
449 .fields
= write_response_fields
,
450 .field_count
= array_length(write_response_fields
)
454 .type
= PACKET_RESERVED
,
457 .name
= "read_quadlet_request",
458 .type
= PACKET_REQUEST
,
459 .response_tcode
= TCODE_READ_QUADLET_RESPONSE
,
460 .fields
= read_quadlet_request_fields
,
461 .field_count
= array_length(read_quadlet_request_fields
)
464 .name
= "read_block_request",
465 .type
= PACKET_REQUEST
,
466 .response_tcode
= TCODE_READ_BLOCK_RESPONSE
,
467 .fields
= read_block_request_fields
,
468 .field_count
= array_length(read_block_request_fields
)
471 .name
= "read_quadlet_response",
472 .type
= PACKET_RESPONSE
,
473 .fields
= read_quadlet_response_fields
,
474 .field_count
= array_length(read_quadlet_response_fields
)
477 .name
= "read_block_response",
478 .type
= PACKET_RESPONSE
,
479 .fields
= block_response_fields
,
480 .field_count
= array_length(block_response_fields
)
483 .name
= "cycle_start",
484 .type
= PACKET_OTHER
,
485 .fields
= write_quadlet_request_fields
,
486 .field_count
= array_length(write_quadlet_request_fields
)
489 .name
= "lock_request",
490 .type
= PACKET_REQUEST
,
491 .fields
= block_request_fields
,
492 .field_count
= array_length(block_request_fields
)
496 .type
= PACKET_OTHER
,
497 .fields
= iso_data_fields
,
498 .field_count
= array_length(iso_data_fields
)
501 .name
= "lock_response",
502 .type
= PACKET_RESPONSE
,
503 .fields
= block_response_fields
,
504 .field_count
= array_length(block_response_fields
)
509 handle_packet(unsigned long *data
, size_t length
)
512 printf("bus reset\r\n");
513 clear_pending_transaction_list();
515 else if (length
> sizeof(struct phy_packet
)) {
516 struct link_packet
*p
= (struct link_packet
*) data
;
517 struct subaction
*sa
, *prev
;
518 struct link_transaction
*t
;
520 switch (packet_info
[p
->common
.tcode
].type
) {
522 t
= link_transaction_lookup(p
->common
.source
, p
->common
.destination
,
524 sa
= subaction_create(data
, length
);
527 if (!list_empty(&t
->request_list
)) {
528 prev
= list_tail(&t
->request_list
, struct subaction
, link
);
530 if (!ACK_BUSY(prev
->ack
)) {
531 /* error, we should only see ack_busy_* before the
532 * ack_pending/ack_complete -- this is an ack_pending
533 * instead (ack_complete would have finished the
537 if (prev
->packet
.common
.tcode
!= sa
->packet
.common
.tcode
||
538 prev
->packet
.common
.tlabel
!= sa
->packet
.common
.tlabel
)
540 /* error, these should match for retries. */;
543 list_append(&t
->request_list
, &sa
->link
);
547 if (p
->common
.tcode
!= TCODE_WRITE_QUADLET
&&
548 p
->common
.tcode
!= TCODE_WRITE_BLOCK
)
549 /* error, unified transactions only allowed for write */;
550 list_remove(&t
->link
);
551 handle_transaction(t
);
557 list_remove(&t
->link
);
558 handle_transaction(t
);
562 /* request subaction phase over, wait for response. */
568 /* ok, wait for retry. */
569 /* check that retry protocol is respected. */
574 case PACKET_RESPONSE
:
575 t
= link_transaction_lookup(p
->common
.destination
, p
->common
.source
,
577 if (list_empty(&t
->request_list
)) {
578 /* unsolicited response */
581 sa
= subaction_create(data
, length
);
584 if (!list_empty(&t
->response_list
)) {
585 prev
= list_tail(&t
->response_list
, struct subaction
, link
);
587 if (!ACK_BUSY(prev
->ack
))
588 /* error, we should only see ack_busy_* before the
589 * ack_pending/ack_complete */;
591 if (prev
->packet
.common
.tcode
!= sa
->packet
.common
.tcode
||
592 prev
->packet
.common
.tlabel
!= sa
->packet
.common
.tlabel
)
593 /* use memcmp() instead? */
594 /* error, these should match for retries. */;
597 prev
= list_tail(&t
->request_list
, struct subaction
, link
);
598 if (prev
->ack
!= ACK_PENDING
) {
599 /* error, should not get response unless last request got
603 if (packet_info
[prev
->packet
.common
.tcode
].response_tcode
!=
604 sa
->packet
.common
.tcode
) {
605 /* error, tcode mismatch */
609 list_append(&t
->response_list
, &sa
->link
);
616 list_remove(&t
->link
);
617 handle_transaction(t
);
618 /* transaction complete, remove t from pending list. */
622 /* error for responses. */
628 /* no problem, wait for next retry */
635 case PACKET_RESERVED
:
643 unsigned int get_bits(struct link_packet
*packet
, int offset
, int width
)
645 unsigned long *data
= (unsigned long *) packet
;
646 unsigned long index
, shift
, mask
;
648 index
= offset
/ 32 + 1;
649 shift
= 32 - (offset
& 31) - width
;
650 mask
= width
== 32 ? ~0 : (1 << width
) - 1;
652 return (data
[index
] >> shift
) & mask
;
655 #if __BYTE_ORDER == __LITTLE_ENDIAN
656 #define byte_index(i) ((i) ^ 3)
657 #elif __BYTE_ORDER == __BIG_ENDIAN
658 #define byte_index(i) (i)
660 #error unsupported byte order.
663 void dump_data(unsigned char *data
, int length
)
670 print_length
= length
;
672 for (i
= 0; i
< print_length
; i
++)
674 (i
% 4 == 0 && i
!= 0) ? " " : "",
675 data
[byte_index(i
)]);
677 if (print_length
< length
)
678 printf(" (%d more bytes)", length
- print_length
);
682 decode_link_packet(struct link_packet
*packet
, size_t length
,
683 int include_flags
, int exclude_flags
)
685 struct packet_info
*pi
;
689 pi
= &packet_info
[packet
->common
.tcode
];
691 for (i
= 0; i
< pi
->field_count
; i
++) {
692 struct packet_field
*f
= &pi
->fields
[i
];
695 if (f
->flags
& exclude_flags
)
697 if (include_flags
&& !(f
->flags
& include_flags
))
701 offset
= length
* 8 + f
->offset
- 32;
705 if (f
->value_names
!= NULL
) {
708 bits
= get_bits(packet
, offset
, f
->width
);
709 printf("%s", f
->value_names
[bits
]);
711 else if (f
->width
== 0) {
712 printf("%s=[", f
->name
);
713 dump_data((unsigned char *) packet
+ (offset
/ 8 + 4), data_length
);
717 unsigned long long bits
;
718 int high_width
, low_width
;
720 if ((offset
& ~31) != ((offset
+ f
->width
- 1) & ~31)) {
721 /* Bit field spans quadlet boundary. */
722 high_width
= ((offset
+ 31) & ~31) - offset
;
723 low_width
= f
->width
- high_width
;
725 bits
= get_bits(packet
, offset
, high_width
);
726 bits
= (bits
<< low_width
) |
727 get_bits(packet
, offset
+ high_width
, low_width
);
730 bits
= get_bits(packet
, offset
, f
->width
);
732 printf("%s=0x%0*llx", f
->name
, (f
->width
+ 3) / 4, bits
);
734 if (f
->flags
& PACKET_FIELD_DATA_LENGTH
)
738 if (i
< pi
->field_count
- 1)
744 print_packet(unsigned long *data
, size_t length
)
748 printf("%6lu ", data
[0]);
752 else if (length
< sizeof(struct phy_packet
)) {
753 printf("short packet: ");
754 for (i
= 1; i
< length
/ 4; i
++)
755 printf("%s%08lx", i
== 0 ? "[" : " ", data
[i
]);
759 else if (length
== sizeof(struct phy_packet
) && data
[1] == ~data
[2]) {
760 struct phy_packet
*pp
= (struct phy_packet
*) data
;
762 /* phy packet are 3 quadlets: the 1 quadlet payload,
763 * the bitwise inverse of the payload and the snoop
766 switch (pp
->common
.identifier
) {
767 case PHY_PACKET_CONFIGURATION
:
768 if (!pp
->phy_config
.set_root
&& !pp
->phy_config
.set_gap_count
) {
769 printf("ext phy config: phy_id=%02x", pp
->phy_config
.root_id
);
772 printf("phy config:");
773 if (pp
->phy_config
.set_root
)
774 printf(" set_root_id=%02x", pp
->phy_config
.root_id
);
775 if (pp
->phy_config
.set_gap_count
)
776 printf(" set_gap_count=%d", pp
->phy_config
.gap_count
);
780 case PHY_PACKET_LINK_ON
:
781 printf("link-on packet, phy_id=%02x", pp
->link_on
.phy_id
);
784 case PHY_PACKET_SELF_ID
:
785 if (pp
->self_id
.extended
) {
786 printf("extended self id: phy_id=%02x, seq=%d",
787 pp
->ext_self_id
.phy_id
, pp
->ext_self_id
.sequence
);
790 static const char * const speed_names
[] = {
791 "S100", "S200", "S400", "BETA"
793 printf("self id: phy_id=%02x, link %s, gap_count=%d, speed=%s%s%s",
795 (pp
->self_id
.link_active
? "active" : "not active"),
796 pp
->self_id
.gap_count
,
797 speed_names
[pp
->self_id
.phy_speed
],
798 (pp
->self_id
.contender
? ", irm contender" : ""),
799 (pp
->self_id
.initiated_reset
? ", initiator" : ""));
804 printf("unknown phy packet: ");
805 for (i
= 1; i
< length
/ 4; i
++)
806 printf("%s%08lx", i
== 0 ? "[" : " ", data
[i
]);
812 struct link_packet
*packet
= (struct link_packet
*) data
;
814 decode_link_packet(packet
, length
, 0,
815 option_verbose
? 0 : PACKET_FIELD_DETAIL
);
820 dump_data((unsigned char *) data
+ 4, length
- 4);
827 #define HIDE_CURSOR "\033[?25l"
828 #define SHOW_CURSOR "\033[?25h"
829 #define CLEAR "\033[H\033[2J"
832 print_stats(unsigned long *data
, size_t length
)
834 static int bus_reset_count
, short_packet_count
, phy_packet_count
;
835 static int tcode_count
[16];
836 static struct timeval last_update
;
842 else if (length
< sizeof(struct phy_packet
))
843 short_packet_count
++;
844 else if (length
== sizeof(struct phy_packet
) && data
[1] == ~data
[2])
847 struct link_packet
*packet
= (struct link_packet
*) data
;
848 tcode_count
[packet
->common
.tcode
]++;
851 gettimeofday(&now
, NULL
);
852 if (now
.tv_sec
<= last_update
.tv_sec
&&
853 now
.tv_usec
< last_update
.tv_usec
+ 500000)
857 printf(CLEAR HIDE_CURSOR
858 " bus resets : %8d\n"
859 " short packets : %8d\n"
860 " phy packets : %8d\n",
861 bus_reset_count
, short_packet_count
, phy_packet_count
);
863 for (i
= 0; i
< array_length(packet_info
); i
++)
864 if (packet_info
[i
].type
!= PACKET_RESERVED
)
865 printf(" %-24s: %8d\n", packet_info
[i
].name
, tcode_count
[i
]);
866 printf(SHOW_CURSOR
"\n");
869 struct termios saved_attributes
;
872 reset_input_mode (void)
874 tcsetattr (STDIN_FILENO
, TCSANOW
, &saved_attributes
);
878 set_input_mode (void)
880 struct termios tattr
;
882 /* Make sure stdin is a terminal. */
883 if (!isatty(STDIN_FILENO
)) {
884 fprintf(stderr
, "Not a terminal.\n");
888 /* Save the terminal attributes so we can restore them later. */
889 tcgetattr(STDIN_FILENO
, &saved_attributes
);
890 atexit(reset_input_mode
);
892 /* Set the funny terminal modes. */
893 tcgetattr(STDIN_FILENO
, &tattr
);
894 tattr
.c_lflag
&= ~(ICANON
|ECHO
); /* Clear ICANON and ECHO. */
895 tattr
.c_cc
[VMIN
] = 1;
896 tattr
.c_cc
[VTIME
] = 0;
897 tcsetattr(STDIN_FILENO
, TCSAFLUSH
, &tattr
);
900 int main(int argc
, const char *argv
[])
903 FILE *output
= NULL
, *input
= NULL
;
908 struct pollfd pollfds
[2];
910 sys_sigint_handler
= signal(SIGINT
, sigint_handler
);
912 con
= poptGetContext(NULL
, argc
, argv
, options
, 0);
913 retval
= poptGetNextOpt(con
);
915 poptPrintUsage(con
, stdout
, 0);
919 if (option_version
) {
920 printf("dump tool for nosy sniffer, version %s\n", VERSION
);
924 if (__BYTE_ORDER
!= __LITTLE_ENDIAN
)
925 fprintf(stderr
, "warning: nosy has only been tested on little "
926 "endian machines\n");
928 if (option_input
!= NULL
) {
929 input
= fopen(option_input
, "r");
931 fprintf(stderr
, "Could not open %s, %m\n", option_input
);
936 fd
= open(option_nosy_device
, O_RDWR
);
938 fprintf(stderr
, "Could not open %s, %m\n", option_nosy_device
);
944 if (strcmp(option_view
, "transaction") == 0)
945 view
= VIEW_TRANSACTION
;
946 else if (strcmp(option_view
, "stats") == 0)
952 output
= fopen(option_output
, "w");
953 if (output
== NULL
) {
954 fprintf(stderr
, "Could not open %s, %m\n", option_output
);
959 setvbuf(stdout
, NULL
, _IOLBF
, BUFSIZ
);
962 unsigned long buf
[128 * 1024];
968 filter
&= ~(1 <<TCODE_ISO_DATA
);
969 if (!option_cycle_start
)
970 filter
&= ~(1 << TCODE_CYCLE_START
);
972 if (view
== VIEW_STATS
)
973 ioctl(fd
, NOSY_IOC_FILTER
, ~(1 << TCODE_CYCLE_START
));
975 ioctl(fd
, NOSY_IOC_FILTER
, filter
);
977 ioctl(fd
, NOSY_IOC_START
);
980 pollfds
[0].events
= POLLIN
;
981 pollfds
[1].fd
= STDIN_FILENO
;
982 pollfds
[1].events
= POLLIN
;
986 if (fread(&length
, sizeof length
, 1, input
) != 1)
988 fread(buf
, 1, length
, input
);
991 poll(pollfds
, 2, -1);
992 if (pollfds
[1].revents
) {
993 read(STDIN_FILENO
, &c
, sizeof c
);
1002 if (pollfds
[0].revents
)
1003 length
= read(fd
, buf
, sizeof buf
);
1008 if (output
!= NULL
) {
1009 fwrite(&length
, sizeof length
, 1, output
);
1010 fwrite(buf
, 1, length
, output
);
1014 case VIEW_TRANSACTION
:
1015 handle_packet(buf
, length
);
1018 print_packet(buf
, length
);
1021 print_stats(buf
, length
);
1027 poptPrintUsage(con
, stdout
, 0);
1034 poptFreeContext(con
);