Lines Matching +full:ctrl +full:- +full:len
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)
127 u_char *mmapbuf; /* memory-mapped region pointer */
150 * XXX - is there any notion of "up" and "running"?
161 return -1;
164 * XXX - is there a way to determine whether anything's
171 return -1;
187 * We require 2.6.27 or later kernels, so we have binary-mode support.
194 name = data->d_name;
229 * 1) a fixed-length header, of size header_size;
239 * Therefore, if we subtract the fixed-length size from the
241 * don't worry about the descriptors - if we have descriptors,
248 if (handle->snapshot < header_size)
249 handle->snapshot = header_size;
251 ring_size = (handle->snapshot - header_size) * 5;
263 * maximum-size ring.
266 handle->snapshot = header_size + (MAX_RING_SIZE/5);
277 if (ioctl(handle->fd, MON_IOCT_RING_SIZE, ring_size) == -1) {
278 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
279 errno, "Can't set ring size from fd %d", handle->fd);
280 return -1;
288 struct pcap_usb_linux *handlep = handle->priv;
289 int len;
296 len = usb_set_ring_size(handle, (int)sizeof(pcap_usb_header_mmapped));
297 if (len == -1) {
298 /* Failed. Fall back on non-memory-mapped access. */
302 handlep->mmapbuflen = len;
303 handlep->mmapbuf = mmap(0, handlep->mmapbuflen, PROT_READ,
304 MAP_SHARED, handle->fd, 0);
305 if (handlep->mmapbuf == MAP_FAILED) {
308 * just try to fall back on non-memory-mapped access.
338 struct usbdevfs_ctrltransfer ctrl;
354 char* name = data->d_name;
359 snprintf(busdevpath, sizeof(busdevpath), "/dev/bus/usb/%03d/%s", bus, data->d_name);
362 if (fd == -1)
370 ctrl.bRequestType = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
371 ctrl.bRequest = USB_REQ_GET_DESCRIPTOR;
372 ctrl.wValue = USB_DT_DEVICE << 8;
373 ctrl.wIndex = 0;
374 ctrl.wLength = sizeof(descriptor);
376 ctrl.requesttype = USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
377 ctrl.request = USB_REQ_GET_DESCRIPTOR;
378 ctrl.value = USB_DT_DEVICE << 8;
379 ctrl.index = 0;
380 ctrl.length = sizeof(descriptor);
382 ctrl.data = descriptor;
383 ctrl.timeout = CTRL_TIMEOUT;
385 ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
389 ctrl.wValue = USB_DT_CONFIG << 8;
390 ctrl.wLength = sizeof(configdesc);
392 ctrl.value = USB_DT_CONFIG << 8;
393 ctrl.length = sizeof(configdesc);
395 ctrl.data = configdesc;
396 ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
401 ctrl.wLength = wtotallength;
403 ctrl.length = wtotallength;
405 ctrl.data = malloc(wtotallength);
406 if (ctrl.data) {
407 ret = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
408 free(ctrl.data);
430 if (strncmp(cp, USB_IFACE, sizeof USB_IFACE - 1) != 0) {
435 /* Yes - is USB_IFACE followed by a number? */
436 cp += sizeof USB_IFACE - 1;
444 /* Followed by a non-valid number. */
456 p->activate_op = usb_activate;
463 struct pcap_usb_linux *handlep = handle->priv;
474 if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN)
475 handle->snapshot = MAXIMUM_SNAPLEN;
478 handle->bufsize = handle->snapshot;
479 handle->offset = 0;
480 handle->linktype = DLT_USB_LINUX;
482 handle->inject_op = usb_inject_linux;
483 handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
484 handle->setdirection_op = usb_setdirection_linux;
485 handle->set_datalink_op = NULL; /* can't change data link type */
486 handle->getnonblock_op = pcapint_getnonblock_fd;
487 handle->setnonblock_op = pcapint_setnonblock_fd;
490 if (sscanf(handle->opt.device, USB_IFACE"%d", &handlep->bus_index) != 1)
492 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
493 "Can't get USB bus index from %s", handle->opt.device);
498 * We require 2.6.27 or later kernels, so we have binary-mode support.
502 handlep->bus_index);
503 handle->fd = open(full_path, O_RDONLY, 0);
504 if (handle->fd < 0)
527 handle->errbuf[0] = '\0';
535 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
536 "Attempt to open %s failed with EACCES - root privileges may be required",
545 pcapint_fmt_errmsg_for_errno(handle->errbuf,
552 if (handle->opt.rfmon)
557 close(handle->fd);
565 handle->linktype = DLT_USB_LINUX_MMAPPED;
566 handle->stats_op = usb_stats_linux_bin;
567 handle->read_op = usb_read_linux_mmap;
568 handle->cleanup_op = usb_cleanup_linux_mmap;
570 probe_devices(handlep->bus_index);
574 * "handle->fd" is a real file, so
577 handle->selectable_fd = handle->fd;
589 if (usb_set_ring_size(handle, (int)sizeof(pcap_usb_header)) == -1) {
591 close(handle->fd);
594 handle->stats_op = usb_stats_linux_bin;
595 handle->read_op = usb_read_linux_bin;
597 probe_devices(handlep->bus_index);
601 * "handle->fd" is a real file, so "select()" and "poll()"
604 handle->selectable_fd = handle->fd;
608 handle->buffer = malloc(handle->bufsize);
609 if (!handle->buffer) {
610 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
612 close(handle->fd);
621 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
623 return (-1);
633 p->direction = d;
640 struct pcap_usb_linux *handlep = handle->priv;
643 ret = ioctl(handle->fd, MON_IOCG_STATS, &st);
646 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
647 errno, "Can't read stats from fd %d", handle->fd);
648 return -1;
651 stats->ps_recv = handlep->packets_read + st.queued;
652 stats->ps_drop = st.dropped;
653 stats->ps_ifdrop = 0;
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;
668 u_int clen = handle->snapshot - sizeof(pcap_usb_header);
671 info.hdr = (pcap_usb_header*) handle->buffer;
672 info.data = (u_char *)handle->buffer + sizeof(pcap_usb_header);
677 ret = ioctl(handle->fd, MON_IOCX_GET, &info);
678 if (handle->break_loop)
680 handle->break_loop = 0;
681 return -2;
683 } while ((ret == -1) && (errno == EINTR));
689 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
690 errno, "Can't read from fd %d", handle->fd);
691 return -1;
695 * info.hdr->data_len is the number of bytes of isochronous
698 * because we're using the old 48-byte header.
700 * If info.hdr->data_flag is non-zero, there's no URB data;
701 * info.hdr->urb_len is the size of the buffer into which
703 * of data transferred. If info.hdr->data_flag is zero,
704 * there is URB data, and info.hdr->urb_len is the number
712 if (info.hdr->data_len < clen)
713 clen = info.hdr->data_len;
714 info.hdr->data_len = clen;
716 if (info.hdr->data_flag) {
719 * info.hdr->data_len (so that it's >= the captured
722 pkth.len = sizeof(pcap_usb_header) + info.hdr->data_len;
726 * info.hdr->urb_len, so that it includes data
730 pkth.len = sizeof(pcap_usb_header) + info.hdr->urb_len;
732 pkth.ts.tv_sec = (time_t)info.hdr->ts_sec;
733 pkth.ts.tv_usec = info.hdr->ts_usec;
735 if (handle->fcode.bf_insns == NULL ||
736 pcapint_filter(handle->fcode.bf_insns, handle->buffer,
737 pkth.len, pkth.caplen)) {
738 handlep->packets_read++;
739 callback(user, &pkth, handle->buffer);
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;
764 max_clen = handle->snapshot - sizeof(pcap_usb_header_mmapped);
790 limit = max_packets - packets;
798 * earlier (nflush) - MON_IOCX_MFETCH does both
807 ret = ioctl(handle->fd, MON_IOCX_MFETCH, &fetch);
808 if (handle->break_loop)
810 handle->break_loop = 0;
811 return -2;
813 } while ((ret == -1) && (errno == EINTR));
819 pcapint_fmt_errmsg_for_errno(handle->errbuf,
821 handle->fd);
822 return -1;
829 * XXX - we can't check break_loop here, as
833 * not be seen - and won't be flushed, either.
837 * with the count of packets to flush - or
838 * would have to flush the already-processed
843 bp = &handlep->mmapbuf[vec[i]];
849 if (hdr->event_type == '@')
853 * hdr->data_len is the number of bytes of
857 * If hdr->data_flag is non-zero, there's no
858 * URB data; hdr->urb_len is the size of the
861 * If hdr->data_flag is zero, there is URB data,
862 * and hdr->urb_len is the number of bytes
873 if (hdr->data_len < clen)
874 clen = hdr->data_len;
876 if (hdr->data_flag) {
879 * on hdr->data_len (so that it's >= the
884 pkth.len = u_int_sum(sizeof(pcap_usb_header_mmapped),
885 hdr->data_len);
893 * events, hdr->urb_len doesn't take
902 pkth.len = incoming_isochronous_transfer_completed_len(&pkth, bp);
907 * the memory-mapped Linux USB header
908 * plus hdr->urb_len; we use
909 * hdr->urb_len so that it includes
916 pkth.len = u_int_sum(sizeof(pcap_usb_header_mmapped),
917 hdr->urb_len);
920 pkth.ts.tv_sec = (time_t)hdr->ts_sec;
921 pkth.ts.tv_usec = hdr->ts_usec;
923 if (handle->fcode.bf_insns == NULL ||
924 pcapint_filter(handle->fcode.bf_insns, (u_char*) hdr,
925 pkth.len, pkth.caplen)) {
926 handlep->packets_read++;
942 if (ioctl(handle->fd, MON_IOCH_MFLUSH, nflush) == -1) {
943 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE,
944 errno, "Can't mflush fd %d", handle->fd);
945 return -1;
953 struct pcap_usb_linux *handlep = handle->priv;
955 /* if we have a memory-mapped buffer, unmap it */
956 if (handlep->mmapbuf != NULL) {
957 munmap(handlep->mmapbuf, handlep->mmapbuflen);
958 handlep->mmapbuf = NULL;