Deleted Added
full compact
libusb10.c (195957) libusb10.c (199055)
1/* $FreeBSD: head/lib/libusb/libusb10.c 195957 2009-07-30 00:11:41Z alfred $ */
1/* $FreeBSD: head/lib/libusb/libusb10.c 199055 2009-11-08 20:03:52Z thompsa $ */
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:
9 * 1. Redistributions of source code must retain the above copyright

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

30#include <stdio.h>
31#include <poll.h>
32#include <pthread.h>
33#include <time.h>
34#include <errno.h>
35#include <sys/ioctl.h>
36#include <sys/filio.h>
37#include <sys/queue.h>
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:
9 * 1. Redistributions of source code must retain the above copyright

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

30#include <stdio.h>
31#include <poll.h>
32#include <pthread.h>
33#include <time.h>
34#include <errno.h>
35#include <sys/ioctl.h>
36#include <sys/filio.h>
37#include <sys/queue.h>
38#include <sys/endian.h>
38
39#include "libusb20.h"
40#include "libusb20_desc.h"
41#include "libusb20_int.h"
42#include "libusb.h"
43#include "libusb10.h"
44
45static pthread_mutex_t default_context_lock = PTHREAD_MUTEX_INITIALIZER;

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

180 *list = malloc((i + 1) * sizeof(void *));
181 if (*list == NULL) {
182 libusb20_be_free(usb_backend);
183 return (LIBUSB_ERROR_NO_MEM);
184 }
185 /* create libusb v1.0 compliant devices */
186 i = 0;
187 while ((pdev = libusb20_be_device_foreach(usb_backend, NULL))) {
39
40#include "libusb20.h"
41#include "libusb20_desc.h"
42#include "libusb20_int.h"
43#include "libusb.h"
44#include "libusb10.h"
45
46static pthread_mutex_t default_context_lock = PTHREAD_MUTEX_INITIALIZER;

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

181 *list = malloc((i + 1) * sizeof(void *));
182 if (*list == NULL) {
183 libusb20_be_free(usb_backend);
184 return (LIBUSB_ERROR_NO_MEM);
185 }
186 /* create libusb v1.0 compliant devices */
187 i = 0;
188 while ((pdev = libusb20_be_device_foreach(usb_backend, NULL))) {
188 /* get device into libUSB v1.0 list */
189 libusb20_be_dequeue_device(usb_backend, pdev);
190
191 dev = malloc(sizeof(*dev));
192 if (dev == NULL) {
193 while (i != 0) {
194 libusb_unref_device((*list)[i - 1]);
195 i--;
196 }
197 free(*list);
198 *list = NULL;
199 libusb20_be_free(usb_backend);
200 return (LIBUSB_ERROR_NO_MEM);
201 }
189
190 dev = malloc(sizeof(*dev));
191 if (dev == NULL) {
192 while (i != 0) {
193 libusb_unref_device((*list)[i - 1]);
194 i--;
195 }
196 free(*list);
197 *list = NULL;
198 libusb20_be_free(usb_backend);
199 return (LIBUSB_ERROR_NO_MEM);
200 }
201
202 /* get device into libUSB v1.0 list */
203 libusb20_be_dequeue_device(usb_backend, pdev);
204
202 memset(dev, 0, sizeof(*dev));
203
204 /* init transfer queues */
205 TAILQ_INIT(&dev->tr_head);
206
207 /* set context we belong to */
208 dev->ctx = ctx;
209

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

411 return; /* be NULL safe */
412
413 dev = libusb_get_device(pdev);
414 ctx = dev->ctx;
415
416 libusb10_remove_pollfd(ctx, &dev->dev_poll);
417
418 libusb20_dev_close(pdev);
205 memset(dev, 0, sizeof(*dev));
206
207 /* init transfer queues */
208 TAILQ_INIT(&dev->tr_head);
209
210 /* set context we belong to */
211 dev->ctx = ctx;
212

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

414 return; /* be NULL safe */
415
416 dev = libusb_get_device(pdev);
417 ctx = dev->ctx;
418
419 libusb10_remove_pollfd(ctx, &dev->dev_poll);
420
421 libusb20_dev_close(pdev);
422
423 /* unref will free the "pdev" when the refcount reaches zero */
419 libusb_unref_device(dev);
420
421 /* make sure our event loop detects the closed device */
422 dummy = 0;
423 err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
424 if (err < sizeof(dummy)) {
425 /* ignore error, if any */
426 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_close write failed!");

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

1190
1191int
1192libusb_submit_transfer(struct libusb_transfer *uxfer)
1193{
1194 struct libusb20_transfer *pxfer0;
1195 struct libusb20_transfer *pxfer1;
1196 struct libusb_super_transfer *sxfer;
1197 struct libusb_device *dev;
424 libusb_unref_device(dev);
425
426 /* make sure our event loop detects the closed device */
427 dummy = 0;
428 err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
429 if (err < sizeof(dummy)) {
430 /* ignore error, if any */
431 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_close write failed!");

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

1195
1196int
1197libusb_submit_transfer(struct libusb_transfer *uxfer)
1198{
1199 struct libusb20_transfer *pxfer0;
1200 struct libusb20_transfer *pxfer1;
1201 struct libusb_super_transfer *sxfer;
1202 struct libusb_device *dev;
1198 unsigned int endpoint;
1203 uint32_t endpoint;
1199 int err;
1200
1201 if (uxfer == NULL)
1202 return (LIBUSB_ERROR_INVALID_PARAM);
1203
1204 if (uxfer->dev_handle == NULL)
1205 return (LIBUSB_ERROR_INVALID_PARAM);
1206

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

1247
1248int
1249libusb_cancel_transfer(struct libusb_transfer *uxfer)
1250{
1251 struct libusb20_transfer *pxfer0;
1252 struct libusb20_transfer *pxfer1;
1253 struct libusb_super_transfer *sxfer;
1254 struct libusb_device *dev;
1204 int err;
1205
1206 if (uxfer == NULL)
1207 return (LIBUSB_ERROR_INVALID_PARAM);
1208
1209 if (uxfer->dev_handle == NULL)
1210 return (LIBUSB_ERROR_INVALID_PARAM);
1211

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

1252
1253int
1254libusb_cancel_transfer(struct libusb_transfer *uxfer)
1255{
1256 struct libusb20_transfer *pxfer0;
1257 struct libusb20_transfer *pxfer1;
1258 struct libusb_super_transfer *sxfer;
1259 struct libusb_device *dev;
1255 unsigned int endpoint;
1260 uint32_t endpoint;
1256
1257 if (uxfer == NULL)
1258 return (LIBUSB_ERROR_INVALID_PARAM);
1259
1260 if (uxfer->dev_handle == NULL)
1261 return (LIBUSB_ERROR_INVALID_PARAM);
1262
1263 endpoint = uxfer->endpoint;

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

1307 return (0);
1308}
1309
1310UNEXPORTED void
1311libusb10_cancel_all_transfer(libusb_device *dev)
1312{
1313 /* TODO */
1314}
1261
1262 if (uxfer == NULL)
1263 return (LIBUSB_ERROR_INVALID_PARAM);
1264
1265 if (uxfer->dev_handle == NULL)
1266 return (LIBUSB_ERROR_INVALID_PARAM);
1267
1268 endpoint = uxfer->endpoint;

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

1312 return (0);
1313}
1314
1315UNEXPORTED void
1316libusb10_cancel_all_transfer(libusb_device *dev)
1317{
1318 /* TODO */
1319}
1320
1321uint16_t
1322libusb_cpu_to_le16(uint16_t x)
1323{
1324 return (htole16(x));
1325}
1326
1327uint16_t
1328libusb_le16_to_cpu(uint16_t x)
1329{
1330 return (le16toh(x));
1331}
1332