Deleted Added
sdiff udiff text old ( 195957 ) new ( 199055 )
full compact
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>
38#include <sys/endian.h>
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))) {
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
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 */
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;
1203 uint32_t endpoint;
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;
1260 uint32_t endpoint;
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