Deleted Added
full compact
libusb10_io.c (195957) libusb10_io.c (199055)
1/* $FreeBSD: head/lib/libusb/libusb10_io.c 195957 2009-07-30 00:11:41Z alfred $ */
1/* $FreeBSD: head/lib/libusb/libusb10_io.c 199055 2009-11-08 20:03:52Z thompsa $ */
2/*-
3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

27#include <stdlib.h>
28#include <unistd.h>
29#include <stdio.h>
30#include <poll.h>
31#include <pthread.h>
32#include <time.h>
33#include <errno.h>
34#include <sys/queue.h>
2/*-
3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

27#include <stdlib.h>
28#include <unistd.h>
29#include <stdio.h>
30#include <poll.h>
31#include <pthread.h>
32#include <time.h>
33#include <errno.h>
34#include <sys/queue.h>
35#include <sys/endian.h>
35
36#include "libusb20.h"
37#include "libusb20_desc.h"
38#include "libusb20_int.h"
39#include "libusb.h"
40#include "libusb10.h"
41
42UNEXPORTED void

--- 100 unchanged lines hidden (view full) ---

143 CTX_UNLOCK(ctx);
144 libusb_unref_device(libusb_get_device(ppdev[i]));
145 CTX_LOCK(ctx);
146 }
147 }
148 goto do_done;
149 }
150 for (i = 0; i != nfds; i++) {
36
37#include "libusb20.h"
38#include "libusb20_desc.h"
39#include "libusb20_int.h"
40#include "libusb.h"
41#include "libusb10.h"
42
43UNEXPORTED void

--- 100 unchanged lines hidden (view full) ---

144 CTX_UNLOCK(ctx);
145 libusb_unref_device(libusb_get_device(ppdev[i]));
146 CTX_LOCK(ctx);
147 }
148 }
149 goto do_done;
150 }
151 for (i = 0; i != nfds; i++) {
151 if (fds[i].revents == 0)
152 continue;
153 if (ppdev[i] != NULL) {
154 dev = libusb_get_device(ppdev[i]);
155
152 if (ppdev[i] != NULL) {
153 dev = libusb_get_device(ppdev[i]);
154
156 err = libusb20_dev_process(ppdev[i]);
155 if (fds[i].revents == 0)
156 err = 0; /* nothing to do */
157 else
158 err = libusb20_dev_process(ppdev[i]);
159
157 if (err) {
158 /* cancel all transfers - device is gone */
159 libusb10_cancel_all_transfer(dev);
160 if (err) {
161 /* cancel all transfers - device is gone */
162 libusb10_cancel_all_transfer(dev);
160 /*
161 * make sure we don't go into an infinite
162 * loop
163 */
163
164 /* remove USB device from polling loop */
164 libusb10_remove_pollfd(dev->ctx, &dev->dev_poll);
165 }
166 CTX_UNLOCK(ctx);
167 libusb_unref_device(dev);
168 CTX_LOCK(ctx);
169
170 } else {
171 uint8_t dummy;

--- 396 unchanged lines hidden (view full) ---

568 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_interrupt_transfer enter");
569
570 ret = libusb10_do_transfer(devh, endpoint, data, length, transferred,
571 timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);
572
573 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_interrupt_transfer leave");
574 return (ret);
575}
165 libusb10_remove_pollfd(dev->ctx, &dev->dev_poll);
166 }
167 CTX_UNLOCK(ctx);
168 libusb_unref_device(dev);
169 CTX_LOCK(ctx);
170
171 } else {
172 uint8_t dummy;

--- 396 unchanged lines hidden (view full) ---

569 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_interrupt_transfer enter");
570
571 ret = libusb10_do_transfer(devh, endpoint, data, length, transferred,
572 timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);
573
574 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_interrupt_transfer leave");
575 return (ret);
576}
577
578uint8_t *
579libusb_get_iso_packet_buffer(struct libusb_transfer *transfer, uint32_t index)
580{
581 uint8_t *ptr;
582 uint32_t n;
583
584 if (transfer->num_iso_packets < 0)
585 return (NULL);
586
587 if (index >= (uint32_t)transfer->num_iso_packets)
588 return (NULL);
589
590 ptr = transfer->buffer;
591 if (ptr == NULL)
592 return (NULL);
593
594 for (n = 0; n != index; n++) {
595 ptr += transfer->iso_packet_desc[n].length;
596 }
597 return (ptr);
598}
599
600uint8_t *
601libusb_get_iso_packet_buffer_simple(struct libusb_transfer *transfer, uint32_t index)
602{
603 uint8_t *ptr;
604
605 if (transfer->num_iso_packets < 0)
606 return (NULL);
607
608 if (index >= (uint32_t)transfer->num_iso_packets)
609 return (NULL);
610
611 ptr = transfer->buffer;
612 if (ptr == NULL)
613 return (NULL);
614
615 ptr += transfer->iso_packet_desc[0].length * index;
616
617 return (ptr);
618}
619
620void
621libusb_set_iso_packet_lengths(struct libusb_transfer *transfer, uint32_t length)
622{
623 int n;
624
625 if (transfer->num_iso_packets < 0)
626 return;
627
628 for (n = 0; n != transfer->num_iso_packets; n++)
629 transfer->iso_packet_desc[n].length = length;
630}
631
632uint8_t *
633libusb_control_transfer_get_data(struct libusb_transfer *transfer)
634{
635 if (transfer->buffer == NULL)
636 return (NULL);
637
638 return (transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE);
639}
640
641struct libusb_control_setup *
642libusb_control_transfer_get_setup(struct libusb_transfer *transfer)
643{
644 return ((struct libusb_control_setup *)transfer->buffer);
645}
646
647void
648libusb_fill_control_setup(uint8_t *buf, uint8_t bmRequestType,
649 uint8_t bRequest, uint16_t wValue,
650 uint16_t wIndex, uint16_t wLength)
651{
652 struct libusb_control_setup *req = (struct libusb_control_setup *)buf;
653
654 /* The alignment is OK for all fields below. */
655 req->bmRequestType = bmRequestType;
656 req->bRequest = bRequest;
657 req->wValue = htole16(wValue);
658 req->wIndex = htole16(wIndex);
659 req->wLength = htole16(wLength);
660}
661
662void
663libusb_fill_control_transfer(struct libusb_transfer *transfer,
664 libusb_device_handle *devh, uint8_t *buf,
665 libusb_transfer_cb_fn callback, void *user_data,
666 uint32_t timeout)
667{
668 struct libusb_control_setup *setup = (struct libusb_control_setup *)buf;
669
670 transfer->dev_handle = devh;
671 transfer->endpoint = 0;
672 transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
673 transfer->timeout = timeout;
674 transfer->buffer = buf;
675 if (setup != NULL)
676 transfer->length = LIBUSB_CONTROL_SETUP_SIZE
677 + le16toh(setup->wLength);
678 else
679 transfer->length = 0;
680 transfer->user_data = user_data;
681 transfer->callback = callback;
682
683}
684
685void
686libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
687 libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf,
688 int length, libusb_transfer_cb_fn callback, void *user_data,
689 uint32_t timeout)
690{
691 transfer->dev_handle = devh;
692 transfer->endpoint = endpoint;
693 transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
694 transfer->timeout = timeout;
695 transfer->buffer = buf;
696 transfer->length = length;
697 transfer->user_data = user_data;
698 transfer->callback = callback;
699}
700
701void
702libusb_fill_interrupt_transfer(struct libusb_transfer *transfer,
703 libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf,
704 int length, libusb_transfer_cb_fn callback, void *user_data,
705 uint32_t timeout)
706{
707 transfer->dev_handle = devh;
708 transfer->endpoint = endpoint;
709 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
710 transfer->timeout = timeout;
711 transfer->buffer = buf;
712 transfer->length = length;
713 transfer->user_data = user_data;
714 transfer->callback = callback;
715}
716
717void
718libusb_fill_iso_transfer(struct libusb_transfer *transfer,
719 libusb_device_handle *devh, uint8_t endpoint, uint8_t *buf,
720 int length, int npacket, libusb_transfer_cb_fn callback,
721 void *user_data, uint32_t timeout)
722{
723 transfer->dev_handle = devh;
724 transfer->endpoint = endpoint;
725 transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
726 transfer->timeout = timeout;
727 transfer->buffer = buf;
728 transfer->length = length;
729 transfer->num_iso_packets = npacket;
730 transfer->user_data = user_data;
731 transfer->callback = callback;
732}
733