libusb10.c (005044bdc0feb74a0fe1366b8cc8a8f8986cd294) | libusb10.c (f1b5fa6e496ae0eb2a3a60ecd613ff92d432e5b9) |
---|---|
1/* $FreeBSD$ */ 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 11 unchanged lines hidden (view full) --- 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 | 1/* $FreeBSD$ */ 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 11 unchanged lines hidden (view full) --- 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 |
28#include <stdlib.h> 29#include <unistd.h> 30#include <stdio.h> 31#include <poll.h> 32#include <pthread.h> 33#include <time.h> 34#include <errno.h> | 28#include <sys/fcntl.h> |
35#include <sys/ioctl.h> | 29#include <sys/ioctl.h> |
36#include <sys/filio.h> | |
37#include <sys/queue.h> | 30#include <sys/queue.h> |
38#include <sys/endian.h> | |
39 | 31 |
32#include <assert.h> 33#include <errno.h> 34#include <poll.h> 35#include <pthread.h> 36#include <stdio.h> 37#include <stdlib.h> 38#include <unistd.h> 39 |
|
40#define libusb_device_handle libusb20_device 41 42#include "libusb20.h" 43#include "libusb20_desc.h" 44#include "libusb20_int.h" 45#include "libusb.h" 46#include "libusb10.h" 47 --- 22 unchanged lines hidden (view full) --- 70 ctx->debug = level; 71} 72 73int 74libusb_init(libusb_context **context) 75{ 76 struct libusb_context *ctx; 77 char *debug; | 40#define libusb_device_handle libusb20_device 41 42#include "libusb20.h" 43#include "libusb20_desc.h" 44#include "libusb20_int.h" 45#include "libusb.h" 46#include "libusb10.h" 47 --- 22 unchanged lines hidden (view full) --- 70 ctx->debug = level; 71} 72 73int 74libusb_init(libusb_context **context) 75{ 76 struct libusb_context *ctx; 77 char *debug; |
78 int flag; |
|
78 int ret; 79 80 ctx = malloc(sizeof(*ctx)); 81 if (!ctx) 82 return (LIBUSB_ERROR_INVALID_PARAM); 83 84 memset(ctx, 0, sizeof(*ctx)); 85 --- 14 unchanged lines hidden (view full) --- 100 ret = pipe(ctx->ctrl_pipe); 101 if (ret < 0) { 102 pthread_mutex_destroy(&ctx->ctx_lock); 103 pthread_cond_destroy(&ctx->ctx_cond); 104 free(ctx); 105 return (LIBUSB_ERROR_OTHER); 106 } 107 /* set non-blocking mode on the control pipe to avoid deadlock */ | 79 int ret; 80 81 ctx = malloc(sizeof(*ctx)); 82 if (!ctx) 83 return (LIBUSB_ERROR_INVALID_PARAM); 84 85 memset(ctx, 0, sizeof(*ctx)); 86 --- 14 unchanged lines hidden (view full) --- 101 ret = pipe(ctx->ctrl_pipe); 102 if (ret < 0) { 103 pthread_mutex_destroy(&ctx->ctx_lock); 104 pthread_cond_destroy(&ctx->ctx_cond); 105 free(ctx); 106 return (LIBUSB_ERROR_OTHER); 107 } 108 /* set non-blocking mode on the control pipe to avoid deadlock */ |
108 ret = 1; 109 ioctl(ctx->ctrl_pipe[0], FIONBIO, &ret); 110 ret = 1; 111 ioctl(ctx->ctrl_pipe[1], FIONBIO, &ret); | 109 flag = 1; 110 ret = fcntl(ctx->ctrl_pipe[0], O_NONBLOCK, &flag); 111 assert(ret != -1 && "Couldn't set O_NONBLOCK for ctx->ctrl_pipe[0]"); 112 flag = 1; 113 ret = fcntl(ctx->ctrl_pipe[1], O_NONBLOCK, &flag); 114 assert(ret != -1 && "Couldn't set O_NONBLOCK for ctx->ctrl_pipe[1]"); |
112 113 libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->ctrl_pipe[0], POLLIN); 114 115 pthread_mutex_lock(&default_context_lock); 116 if (usbi_default_context == NULL) { 117 usbi_default_context = ctx; 118 } 119 pthread_mutex_unlock(&default_context_lock); --- 535 unchanged lines hidden (view full) --- 655 libusb10_add_pollfd(dev->ctx, &dev->dev_poll, 656 pdev, libusb20_dev_get_fd(pdev), 657 POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM); 658 659 return (err ? LIBUSB_ERROR_OTHER : 0); 660} 661 662int | 115 116 libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->ctrl_pipe[0], POLLIN); 117 118 pthread_mutex_lock(&default_context_lock); 119 if (usbi_default_context == NULL) { 120 usbi_default_context = ctx; 121 } 122 pthread_mutex_unlock(&default_context_lock); --- 535 unchanged lines hidden (view full) --- 658 libusb10_add_pollfd(dev->ctx, &dev->dev_poll, 659 pdev, libusb20_dev_get_fd(pdev), 660 POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM); 661 662 return (err ? LIBUSB_ERROR_OTHER : 0); 663} 664 665int |
666libusb_check_connected(struct libusb20_device *pdev) 667{ 668 libusb_device *dev; 669 int err; 670 671 dev = libusb_get_device(pdev); 672 if (dev == NULL) 673 return (LIBUSB_ERROR_INVALID_PARAM); 674 675 err = libusb20_dev_check_connected(pdev); 676 677 return (err ? LIBUSB_ERROR_NO_DEVICE : 0); 678} 679 680int |
|
663libusb_kernel_driver_active(struct libusb20_device *pdev, int interface) 664{ 665 if (pdev == NULL) 666 return (LIBUSB_ERROR_INVALID_PARAM); 667 668 return (libusb20_dev_kernel_driver_active( 669 pdev, interface)); 670} --- 691 unchanged lines hidden --- | 681libusb_kernel_driver_active(struct libusb20_device *pdev, int interface) 682{ 683 if (pdev == NULL) 684 return (LIBUSB_ERROR_INVALID_PARAM); 685 686 return (libusb20_dev_kernel_driver_active( 687 pdev, interface)); 688} --- 691 unchanged lines hidden --- |