Lines Matching +full:no +full:- +full:can +full:- +full:fd
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 #include "pcap-int.h"
40 #include "pcap-usb-linux.h"
41 #include "pcap-usb-linux-common.h"
72 #include "diag-control.h"
77 #define USBMON_DEV_PREFIX_LEN (sizeof USBMON_DEV_PREFIX - 1)
98 size_t data_len; /* Length of data (can be zero) */
127 u_char *mmapbuf; /* memory-mapped region pointer */
150 * XXX - is there any notion of "up" and "running"? in usb_dev_add()
154 * As this refers to all buses, there's no notion of in usb_dev_add()
161 return -1; in usb_dev_add()
164 * XXX - is there a way to determine whether anything's in usb_dev_add()
171 return -1; in usb_dev_add()
187 * We require 2.6.27 or later kernels, so we have binary-mode support. in usb_findalldevs()
194 name = data->d_name; in usb_findalldevs()
201 continue; /* no */ in usb_findalldevs()
229 * 1) a fixed-length header, of size header_size; in usb_set_ring_size()
238 * No more than {buffer size}/5 bytes worth of payload is saved. in usb_set_ring_size()
239 * Therefore, if we subtract the fixed-length size from the in usb_set_ring_size()
241 * don't worry about the descriptors - if we have descriptors, in usb_set_ring_size()
248 if (handle->snapshot < header_size) in usb_set_ring_size()
249 handle->snapshot = header_size; in usb_set_ring_size()
251 ring_size = (handle->snapshot - header_size) * 5; in usb_set_ring_size()
255 * (There's no way to query the minimum or maximum, so we just in usb_set_ring_size()
263 * maximum-size ring. in usb_set_ring_size()
266 handle->snapshot = header_size + (MAX_RING_SIZE/5); in usb_set_ring_size()
271 * callback no more data than specified by the in usb_set_ring_size()
277 if (ioctl(handle->fd, MON_IOCT_RING_SIZE, ring_size) == -1) { in usb_set_ring_size()
278 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_set_ring_size()
279 errno, "Can't set ring size from fd %d", handle->fd); in usb_set_ring_size()
280 return -1; in usb_set_ring_size()
288 struct pcap_usb_linux *handlep = handle->priv; in usb_mmap()
297 if (len == -1) { in usb_mmap()
298 /* Failed. Fall back on non-memory-mapped access. */ in usb_mmap()
302 handlep->mmapbuflen = len; in usb_mmap()
303 handlep->mmapbuf = mmap(0, handlep->mmapbuflen, PROT_READ, in usb_mmap()
304 MAP_SHARED, handle->fd, 0); in usb_mmap()
305 if (handlep->mmapbuf == MAP_FAILED) { in usb_mmap()
308 * just try to fall back on non-memory-mapped access. in usb_mmap()
334 /* without these identifying probes packet data can't be fully decoded */
353 int fd; in probe_devices() local
354 char* name = data->d_name; in probe_devices()
359 snprintf(busdevpath, sizeof(busdevpath), "/dev/bus/usb/%03d/%s", bus, data->d_name); in probe_devices()
361 fd = open(busdevpath, O_RDWR); in probe_devices()
362 if (fd == -1) in probe_devices()
385 ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl); in probe_devices()
396 ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl); in probe_devices()
407 ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl); in probe_devices()
411 close(fd); in probe_devices()
430 if (strncmp(cp, USB_IFACE, sizeof USB_IFACE - 1) != 0) { in usb_create()
435 /* Yes - is USB_IFACE followed by a number? */ in usb_create()
436 cp += sizeof USB_IFACE - 1; in usb_create()
444 /* Followed by a non-valid number. */ in usb_create()
456 p->activate_op = usb_activate; in usb_create()
463 struct pcap_usb_linux *handlep = handle->priv; in usb_activate()
474 if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN) in usb_activate()
475 handle->snapshot = MAXIMUM_SNAPLEN; in usb_activate()
478 handle->bufsize = handle->snapshot; in usb_activate()
479 handle->offset = 0; in usb_activate()
480 handle->linktype = DLT_USB_LINUX; in usb_activate()
482 handle->inject_op = usb_inject_linux; in usb_activate()
483 handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */ in usb_activate()
484 handle->setdirection_op = usb_setdirection_linux; in usb_activate()
485 handle->set_datalink_op = NULL; /* can't change data link type */ in usb_activate()
486 handle->getnonblock_op = pcapint_getnonblock_fd; in usb_activate()
487 handle->setnonblock_op = pcapint_setnonblock_fd; in usb_activate()
490 if (sscanf(handle->opt.device, USB_IFACE"%d", &handlep->bus_index) != 1) in usb_activate()
492 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_activate()
493 "Can't get USB bus index from %s", handle->opt.device); in usb_activate()
498 * We require 2.6.27 or later kernels, so we have binary-mode support. in usb_activate()
502 handlep->bus_index); in usb_activate()
503 handle->fd = open(full_path, O_RDONLY, 0); in usb_activate()
504 if (handle->fd < 0) in usb_activate()
515 * no support for monitoring USB buses in usb_activate()
519 * doesn't exist (no "scan all buses" in usb_activate()
520 * device if the bus index is 0, no in usb_activate()
524 * if we can determine what the particular in usb_activate()
527 handle->errbuf[0] = '\0'; in usb_activate()
535 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_activate()
536 "Attempt to open %s failed with EACCES - root privileges may be required", in usb_activate()
545 pcapint_fmt_errmsg_for_errno(handle->errbuf, in usb_activate()
547 "Can't open USB bus file %s", full_path); in usb_activate()
552 if (handle->opt.rfmon) in usb_activate()
557 close(handle->fd); in usb_activate()
565 handle->linktype = DLT_USB_LINUX_MMAPPED; in usb_activate()
566 handle->stats_op = usb_stats_linux_bin; in usb_activate()
567 handle->read_op = usb_read_linux_mmap; in usb_activate()
568 handle->cleanup_op = usb_cleanup_linux_mmap; in usb_activate()
570 probe_devices(handlep->bus_index); in usb_activate()
574 * "handle->fd" is a real file, so in usb_activate()
577 handle->selectable_fd = handle->fd; in usb_activate()
589 if (usb_set_ring_size(handle, (int)sizeof(pcap_usb_header)) == -1) { in usb_activate()
591 close(handle->fd); in usb_activate()
594 handle->stats_op = usb_stats_linux_bin; in usb_activate()
595 handle->read_op = usb_read_linux_bin; in usb_activate()
597 probe_devices(handlep->bus_index); in usb_activate()
601 * "handle->fd" is a real file, so "select()" and "poll()" in usb_activate()
604 handle->selectable_fd = handle->fd; in usb_activate()
608 handle->buffer = malloc(handle->bufsize); in usb_activate()
609 if (!handle->buffer) { in usb_activate()
610 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_activate()
612 close(handle->fd); in usb_activate()
621 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_inject_linux()
623 return (-1); in usb_inject_linux()
633 p->direction = d; in usb_setdirection_linux()
640 struct pcap_usb_linux *handlep = handle->priv; in usb_stats_linux_bin()
643 ret = ioctl(handle->fd, MON_IOCG_STATS, &st); in usb_stats_linux_bin()
646 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_stats_linux_bin()
647 errno, "Can't read stats from fd %d", handle->fd); in usb_stats_linux_bin()
648 return -1; in usb_stats_linux_bin()
651 stats->ps_recv = handlep->packets_read + st.queued; in usb_stats_linux_bin()
652 stats->ps_drop = st.dropped; in usb_stats_linux_bin()
653 stats->ps_ifdrop = 0; in usb_stats_linux_bin()
658 * see <linux-kernel-source>/Documentation/usb/usbmon.txt and
659 * <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
664 struct pcap_usb_linux *handlep = handle->priv; in usb_read_linux_bin()
668 u_int clen = handle->snapshot - sizeof(pcap_usb_header); in usb_read_linux_bin()
671 info.hdr = (pcap_usb_header*) handle->buffer; in usb_read_linux_bin()
672 info.data = (u_char *)handle->buffer + sizeof(pcap_usb_header); in usb_read_linux_bin()
677 ret = ioctl(handle->fd, MON_IOCX_GET, &info); in usb_read_linux_bin()
678 if (handle->break_loop) in usb_read_linux_bin()
680 handle->break_loop = 0; in usb_read_linux_bin()
681 return -2; in usb_read_linux_bin()
683 } while ((ret == -1) && (errno == EINTR)); in usb_read_linux_bin()
687 return 0; /* no data there */ in usb_read_linux_bin()
689 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_read_linux_bin()
690 errno, "Can't read from fd %d", handle->fd); in usb_read_linux_bin()
691 return -1; in usb_read_linux_bin()
695 * info.hdr->data_len is the number of bytes of isochronous in usb_read_linux_bin()
697 * provided. There are no isochronous descriptors here, in usb_read_linux_bin()
698 * because we're using the old 48-byte header. in usb_read_linux_bin()
700 * If info.hdr->data_flag is non-zero, there's no URB data; in usb_read_linux_bin()
701 * info.hdr->urb_len is the size of the buffer into which in usb_read_linux_bin()
703 * of data transferred. If info.hdr->data_flag is zero, in usb_read_linux_bin()
704 * there is URB data, and info.hdr->urb_len is the number in usb_read_linux_bin()
712 if (info.hdr->data_len < clen) in usb_read_linux_bin()
713 clen = info.hdr->data_len; in usb_read_linux_bin()
714 info.hdr->data_len = clen; in usb_read_linux_bin()
716 if (info.hdr->data_flag) { in usb_read_linux_bin()
718 * No data; just base the original length on in usb_read_linux_bin()
719 * info.hdr->data_len (so that it's >= the captured in usb_read_linux_bin()
722 pkth.len = sizeof(pcap_usb_header) + info.hdr->data_len; in usb_read_linux_bin()
726 * info.hdr->urb_len, so that it includes data in usb_read_linux_bin()
730 pkth.len = sizeof(pcap_usb_header) + info.hdr->urb_len; in usb_read_linux_bin()
732 pkth.ts.tv_sec = (time_t)info.hdr->ts_sec; in usb_read_linux_bin()
733 pkth.ts.tv_usec = info.hdr->ts_usec; in usb_read_linux_bin()
735 if (handle->fcode.bf_insns == NULL || in usb_read_linux_bin()
736 pcapint_filter(handle->fcode.bf_insns, handle->buffer, in usb_read_linux_bin()
738 handlep->packets_read++; in usb_read_linux_bin()
739 callback(user, &pkth, handle->buffer); in usb_read_linux_bin()
747 * see <linux-kernel-source>/Documentation/usb/usbmon.txt and
748 * <linux-kernel-source>/drivers/usb/mon/mon_bin.c binary ABI
754 struct pcap_usb_linux *handlep = handle->priv; in usb_read_linux_mmap()
764 max_clen = handle->snapshot - sizeof(pcap_usb_header_mmapped); in usb_read_linux_mmap()
772 * There's no limit on the number of packets in usb_read_linux_mmap()
790 limit = max_packets - packets; in usb_read_linux_mmap()
798 * earlier (nflush) - MON_IOCX_MFETCH does both in usb_read_linux_mmap()
807 ret = ioctl(handle->fd, MON_IOCX_MFETCH, &fetch); in usb_read_linux_mmap()
808 if (handle->break_loop) in usb_read_linux_mmap()
810 handle->break_loop = 0; in usb_read_linux_mmap()
811 return -2; in usb_read_linux_mmap()
813 } while ((ret == -1) && (errno == EINTR)); in usb_read_linux_mmap()
817 return 0; /* no data there */ in usb_read_linux_mmap()
819 pcapint_fmt_errmsg_for_errno(handle->errbuf, in usb_read_linux_mmap()
820 PCAP_ERRBUF_SIZE, errno, "Can't mfetch fd %d", in usb_read_linux_mmap()
821 handle->fd); in usb_read_linux_mmap()
822 return -1; in usb_read_linux_mmap()
829 * XXX - we can't check break_loop here, as in usb_read_linux_mmap()
833 * not be seen - and won't be flushed, either. in usb_read_linux_mmap()
837 * with the count of packets to flush - or in usb_read_linux_mmap()
838 * would have to flush the already-processed in usb_read_linux_mmap()
843 bp = &handlep->mmapbuf[vec[i]]; in usb_read_linux_mmap()
849 if (hdr->event_type == '@') in usb_read_linux_mmap()
853 * hdr->data_len is the number of bytes of in usb_read_linux_mmap()
857 * If hdr->data_flag is non-zero, there's no in usb_read_linux_mmap()
858 * URB data; hdr->urb_len is the size of the in usb_read_linux_mmap()
861 * If hdr->data_flag is zero, there is URB data, in usb_read_linux_mmap()
862 * and hdr->urb_len is the number of bytes in usb_read_linux_mmap()
873 if (hdr->data_len < clen) in usb_read_linux_mmap()
874 clen = hdr->data_len; in usb_read_linux_mmap()
876 if (hdr->data_flag) { in usb_read_linux_mmap()
878 * No data; just base the original length in usb_read_linux_mmap()
879 * on hdr->data_len (so that it's >= the in usb_read_linux_mmap()
885 hdr->data_len); in usb_read_linux_mmap()
893 * events, hdr->urb_len doesn't take in usb_read_linux_mmap()
907 * the memory-mapped Linux USB header in usb_read_linux_mmap()
908 * plus hdr->urb_len; we use in usb_read_linux_mmap()
909 * hdr->urb_len so that it includes in usb_read_linux_mmap()
917 hdr->urb_len); in usb_read_linux_mmap()
920 pkth.ts.tv_sec = (time_t)hdr->ts_sec; in usb_read_linux_mmap()
921 pkth.ts.tv_usec = hdr->ts_usec; in usb_read_linux_mmap()
923 if (handle->fcode.bf_insns == NULL || in usb_read_linux_mmap()
924 pcapint_filter(handle->fcode.bf_insns, (u_char*) hdr, in usb_read_linux_mmap()
926 handlep->packets_read++; in usb_read_linux_mmap()
942 if (ioctl(handle->fd, MON_IOCH_MFLUSH, nflush) == -1) { in usb_read_linux_mmap()
943 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in usb_read_linux_mmap()
944 errno, "Can't mflush fd %d", handle->fd); in usb_read_linux_mmap()
945 return -1; in usb_read_linux_mmap()
953 struct pcap_usb_linux *handlep = handle->priv; in usb_cleanup_linux_mmap()
955 /* if we have a memory-mapped buffer, unmap it */ in usb_cleanup_linux_mmap()
956 if (handlep->mmapbuf != NULL) { in usb_cleanup_linux_mmap()
957 munmap(handlep->mmapbuf, handlep->mmapbuflen); in usb_cleanup_linux_mmap()
958 handlep->mmapbuf = NULL; in usb_cleanup_linux_mmap()