mirror of
https://github.com/mariusgreuel/avrdude.git
synced 2025-09-28 15:05:27 +00:00
Add support for Visual Studio 2019
This commit is contained in:
572
external/libusb/src/descriptors.c
vendored
Normal file
572
external/libusb/src/descriptors.c
vendored
Normal file
@@ -0,0 +1,572 @@
|
||||
/*
|
||||
* Parses descriptors
|
||||
*
|
||||
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is covered by the LGPL, read LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "usbi.h"
|
||||
|
||||
int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
|
||||
unsigned char type, unsigned char index, void *buf, int size)
|
||||
{
|
||||
memset(buf, 0, size);
|
||||
|
||||
return usb_control_msg(udev, ep | USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
|
||||
(type << 8) + index, 0, buf, size, 1000);
|
||||
}
|
||||
|
||||
int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
|
||||
unsigned char index, void *buf, int size)
|
||||
{
|
||||
memset(buf, 0, size);
|
||||
|
||||
return usb_control_msg(udev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
|
||||
(type << 8) + index, 0, buf, size, 1000);
|
||||
}
|
||||
|
||||
int usb_parse_descriptor(unsigned char *source, char *description, void *dest)
|
||||
{
|
||||
unsigned char *sp = source, *dp = dest;
|
||||
uint16_t w;
|
||||
uint32_t d;
|
||||
char *cp;
|
||||
|
||||
for (cp = description; *cp; cp++)
|
||||
{
|
||||
switch (*cp)
|
||||
{
|
||||
case 'b': /* 8-bit byte */
|
||||
*dp++ = *sp++;
|
||||
break;
|
||||
case 'w': /* 16-bit word, convert from little endian to CPU */
|
||||
w = (sp[1] << 8) | sp[0];
|
||||
sp += 2;
|
||||
//dp += ((unsigned long)dp & 1); /* Align to word boundary */
|
||||
*((uint16_t *)dp) = w;
|
||||
dp += 2;
|
||||
break;
|
||||
case 'd': /* 32-bit dword, convert from little endian to CPU */
|
||||
d = (sp[3] << 24) | (sp[2] << 16) | (sp[1] << 8) | sp[0];
|
||||
sp += 4;
|
||||
//dp += ((unsigned long)dp & 2); /* Align to dword boundary */
|
||||
*((uint32_t *)dp) = d;
|
||||
dp += 4;
|
||||
break;
|
||||
/* These two characters are undocumented and just a hack for Linux */
|
||||
case 'W': /* 16-bit word, keep CPU endianess */
|
||||
//dp += ((unsigned long)dp & 1); /* Align to word boundary */
|
||||
memcpy(dp, sp, 2);
|
||||
sp += 2;
|
||||
dp += 2;
|
||||
break;
|
||||
case 'D': /* 32-bit dword, keep CPU endianess */
|
||||
//dp += ((unsigned long)dp & 2); /* Align to dword boundary */
|
||||
memcpy(dp, sp, 4);
|
||||
sp += 4;
|
||||
dp += 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (int)(sp - source);
|
||||
}
|
||||
|
||||
/*
|
||||
* This code looks surprisingly similar to the code I wrote for the Linux
|
||||
* kernel. It's not a coincidence :)
|
||||
*/
|
||||
|
||||
static int usb_parse_endpoint(struct usb_endpoint_descriptor *endpoint, unsigned char *buffer, int size)
|
||||
{
|
||||
struct usb_descriptor_header header;
|
||||
unsigned char *begin;
|
||||
int parsed = 0, len, numskipped;
|
||||
|
||||
usb_parse_descriptor(buffer, "bb", &header);
|
||||
|
||||
/* Everything should be fine being passed into here, but we sanity */
|
||||
/* check JIC */
|
||||
if (header.bLength > size)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "ran out of descriptors parsing\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (header.bDescriptorType != USB_DT_ENDPOINT)
|
||||
{
|
||||
if (usb_debug >= 2)
|
||||
fprintf(stderr, "unexpected descriptor 0x%X, expecting endpoint descriptor, type 0x%X\n",
|
||||
header.bDescriptorType, USB_DT_ENDPOINT);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
if (header.bLength >= ENDPOINT_AUDIO_DESC_LENGTH)
|
||||
usb_parse_descriptor(buffer, "bbbbwbbb", endpoint);
|
||||
else if (header.bLength >= ENDPOINT_DESC_LENGTH)
|
||||
usb_parse_descriptor(buffer, "bbbbwb", endpoint);
|
||||
|
||||
buffer += header.bLength;
|
||||
size -= header.bLength;
|
||||
parsed += header.bLength;
|
||||
|
||||
/* Skip over the rest of the Class Specific or Vendor Specific */
|
||||
/* descriptors */
|
||||
begin = buffer;
|
||||
numskipped = 0;
|
||||
while (size >= DESC_HEADER_LENGTH)
|
||||
{
|
||||
usb_parse_descriptor(buffer, "bb", &header);
|
||||
|
||||
if (header.bLength < 2)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "invalid descriptor length of %d\n", header.bLength);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If we find another "proper" descriptor then we're done */
|
||||
if ((header.bDescriptorType == USB_DT_ENDPOINT) ||
|
||||
(header.bDescriptorType == USB_DT_INTERFACE) ||
|
||||
(header.bDescriptorType == USB_DT_CONFIG) ||
|
||||
(header.bDescriptorType == USB_DT_DEVICE))
|
||||
break;
|
||||
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "skipping descriptor 0x%X\n", header.bDescriptorType);
|
||||
numskipped++;
|
||||
|
||||
buffer += header.bLength;
|
||||
size -= header.bLength;
|
||||
parsed += header.bLength;
|
||||
}
|
||||
|
||||
if (numskipped && usb_debug >= 2)
|
||||
fprintf(stderr, "skipped %d class/vendor specific endpoint descriptors\n", numskipped);
|
||||
|
||||
/* Copy any unknown descriptors into a storage area for drivers */
|
||||
/* to later parse */
|
||||
len = (int)(buffer - begin);
|
||||
if (!len)
|
||||
{
|
||||
endpoint->extra = NULL;
|
||||
endpoint->extralen = 0;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
endpoint->extra = malloc(len);
|
||||
if (!endpoint->extra)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "couldn't allocate memory for endpoint extra descriptors\n");
|
||||
endpoint->extralen = 0;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
memcpy(endpoint->extra, begin, len);
|
||||
endpoint->extralen = len;
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
static int usb_parse_interface(struct usb_interface *interface,
|
||||
unsigned char *buffer, int size)
|
||||
{
|
||||
int i, len, numskipped, retval, parsed = 0;
|
||||
struct usb_descriptor_header header;
|
||||
struct usb_interface_descriptor *ifp;
|
||||
unsigned char *begin;
|
||||
|
||||
interface->num_altsetting = 0;
|
||||
|
||||
while (size >= INTERFACE_DESC_LENGTH)
|
||||
{
|
||||
interface->altsetting = realloc(interface->altsetting, sizeof(struct usb_interface_descriptor) * (interface->num_altsetting + 1));
|
||||
if (!interface->altsetting)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "couldn't malloc interface->altsetting\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ifp = interface->altsetting + interface->num_altsetting;
|
||||
interface->num_altsetting++;
|
||||
|
||||
usb_parse_descriptor(buffer, "bbbbbbbbb", ifp);
|
||||
|
||||
/* Skip over the interface */
|
||||
buffer += ifp->bLength;
|
||||
parsed += ifp->bLength;
|
||||
size -= ifp->bLength;
|
||||
|
||||
begin = buffer;
|
||||
numskipped = 0;
|
||||
|
||||
/* Skip over any interface, class or vendor descriptors */
|
||||
while (size >= DESC_HEADER_LENGTH)
|
||||
{
|
||||
usb_parse_descriptor(buffer, "bb", &header);
|
||||
|
||||
if (header.bLength < 2)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "invalid descriptor length of %d\n", header.bLength);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If we find another "proper" descriptor then we're done */
|
||||
if ((header.bDescriptorType == USB_DT_INTERFACE) ||
|
||||
(header.bDescriptorType == USB_DT_ENDPOINT) ||
|
||||
(header.bDescriptorType == USB_DT_CONFIG) ||
|
||||
(header.bDescriptorType == USB_DT_DEVICE))
|
||||
break;
|
||||
|
||||
numskipped++;
|
||||
|
||||
buffer += header.bLength;
|
||||
parsed += header.bLength;
|
||||
size -= header.bLength;
|
||||
}
|
||||
|
||||
if (numskipped && usb_debug >= 2)
|
||||
fprintf(stderr, "skipped %d class/vendor specific interface descriptors\n", numskipped);
|
||||
|
||||
/* Copy any unknown descriptors into a storage area for */
|
||||
/* drivers to later parse */
|
||||
len = (int)(buffer - begin);
|
||||
if (!len)
|
||||
{
|
||||
ifp->extra = NULL;
|
||||
ifp->extralen = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ifp->extra = malloc(len);
|
||||
if (!ifp->extra)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "couldn't allocate memory for interface extra descriptors\n");
|
||||
ifp->extralen = 0;
|
||||
return -1;
|
||||
}
|
||||
memcpy(ifp->extra, begin, len);
|
||||
ifp->extralen = len;
|
||||
}
|
||||
|
||||
/* Did we hit an unexpected descriptor? */
|
||||
usb_parse_descriptor(buffer, "bb", &header);
|
||||
if ((size >= DESC_HEADER_LENGTH) &&
|
||||
((header.bDescriptorType == USB_DT_CONFIG) ||
|
||||
(header.bDescriptorType == USB_DT_DEVICE)))
|
||||
return parsed;
|
||||
|
||||
if (ifp->bNumEndpoints > USB_MAXENDPOINTS)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "too many endpoints\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ifp->bNumEndpoints > 0)
|
||||
{
|
||||
ifp->endpoint = (struct usb_endpoint_descriptor *)
|
||||
malloc(ifp->bNumEndpoints *
|
||||
sizeof(struct usb_endpoint_descriptor));
|
||||
if (!ifp->endpoint)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "couldn't allocate memory for ifp->endpoint\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(ifp->endpoint, 0, ifp->bNumEndpoints *
|
||||
sizeof(struct usb_endpoint_descriptor));
|
||||
|
||||
for (i = 0; i < ifp->bNumEndpoints; i++)
|
||||
{
|
||||
usb_parse_descriptor(buffer, "bb", &header);
|
||||
|
||||
if (header.bLength > size)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "ran out of descriptors parsing\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
retval = usb_parse_endpoint(ifp->endpoint + i, buffer, size);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
||||
buffer += retval;
|
||||
parsed += retval;
|
||||
size -= retval;
|
||||
}
|
||||
}
|
||||
else
|
||||
ifp->endpoint = NULL;
|
||||
|
||||
/* We check to see if it's an alternate to this one */
|
||||
ifp = (struct usb_interface_descriptor *)buffer;
|
||||
if (size < USB_DT_INTERFACE_SIZE ||
|
||||
ifp->bDescriptorType != USB_DT_INTERFACE ||
|
||||
!ifp->bAlternateSetting)
|
||||
return parsed;
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
int usb_parse_configuration(struct usb_config_descriptor *config,
|
||||
unsigned char *buffer)
|
||||
{
|
||||
int i, retval, size;
|
||||
struct usb_descriptor_header header;
|
||||
|
||||
usb_parse_descriptor(buffer, "bbwbbbbb", config);
|
||||
size = config->wTotalLength;
|
||||
|
||||
if (config->bNumInterfaces > USB_MAXINTERFACES)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "too many interfaces\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
config->interface = (struct usb_interface *)
|
||||
malloc(config->bNumInterfaces *
|
||||
sizeof(struct usb_interface));
|
||||
if (!config->interface)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "out of memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(config->interface, 0, config->bNumInterfaces * sizeof(struct usb_interface));
|
||||
|
||||
buffer += config->bLength;
|
||||
size -= config->bLength;
|
||||
|
||||
config->extra = NULL;
|
||||
config->extralen = 0;
|
||||
|
||||
for (i = 0; i < config->bNumInterfaces; i++)
|
||||
{
|
||||
int numskipped, len;
|
||||
unsigned char *begin;
|
||||
|
||||
/* Skip over the rest of the Class Specific or Vendor */
|
||||
/* Specific descriptors */
|
||||
begin = buffer;
|
||||
numskipped = 0;
|
||||
while (size >= DESC_HEADER_LENGTH)
|
||||
{
|
||||
usb_parse_descriptor(buffer, "bb", &header);
|
||||
|
||||
if ((header.bLength > size) || (header.bLength < DESC_HEADER_LENGTH))
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "invalid descriptor length of %d\n", header.bLength);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If we find another "proper" descriptor then we're done */
|
||||
if ((header.bDescriptorType == USB_DT_ENDPOINT) ||
|
||||
(header.bDescriptorType == USB_DT_INTERFACE) ||
|
||||
(header.bDescriptorType == USB_DT_CONFIG) ||
|
||||
(header.bDescriptorType == USB_DT_DEVICE))
|
||||
break;
|
||||
|
||||
if (usb_debug >= 2)
|
||||
fprintf(stderr, "skipping descriptor 0x%X\n", header.bDescriptorType);
|
||||
numskipped++;
|
||||
|
||||
buffer += header.bLength;
|
||||
size -= header.bLength;
|
||||
}
|
||||
|
||||
if (numskipped && usb_debug >= 2)
|
||||
fprintf(stderr, "skipped %d class/vendor specific endpoint descriptors\n", numskipped);
|
||||
|
||||
/* Copy any unknown descriptors into a storage area for */
|
||||
/* drivers to later parse */
|
||||
len = (int)(buffer - begin);
|
||||
if (len)
|
||||
{
|
||||
/* FIXME: We should realloc and append here */
|
||||
if (!config->extralen)
|
||||
{
|
||||
config->extra = malloc(len);
|
||||
if (!config->extra)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "couldn't allocate memory for config extra descriptors\n");
|
||||
config->extralen = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(config->extra, begin, len);
|
||||
config->extralen = len;
|
||||
}
|
||||
}
|
||||
|
||||
retval = usb_parse_interface(config->interface + i, buffer, size);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
||||
buffer += retval;
|
||||
size -= retval;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
void usb_destroy_configuration(struct usb_device *dev)
|
||||
{
|
||||
int c, i, j, k;
|
||||
|
||||
if (!dev->config)
|
||||
return;
|
||||
|
||||
for (c = 0; c < dev->descriptor.bNumConfigurations; c++)
|
||||
{
|
||||
struct usb_config_descriptor *cf = &dev->config[c];
|
||||
|
||||
if (!cf->interface)
|
||||
continue;
|
||||
|
||||
for (i = 0; i < cf->bNumInterfaces; i++)
|
||||
{
|
||||
struct usb_interface *ifp = &cf->interface[i];
|
||||
|
||||
if (!ifp->altsetting)
|
||||
continue;
|
||||
|
||||
for (j = 0; j < ifp->num_altsetting; j++)
|
||||
{
|
||||
struct usb_interface_descriptor *as = &ifp->altsetting[j];
|
||||
|
||||
if (as->extra)
|
||||
free(as->extra);
|
||||
|
||||
if (!as->endpoint)
|
||||
continue;
|
||||
|
||||
for (k = 0; k < as->bNumEndpoints; k++)
|
||||
{
|
||||
if (as->endpoint[k].extra)
|
||||
free(as->endpoint[k].extra);
|
||||
}
|
||||
free(as->endpoint);
|
||||
}
|
||||
|
||||
free(ifp->altsetting);
|
||||
}
|
||||
|
||||
free(cf->interface);
|
||||
}
|
||||
|
||||
free(dev->config);
|
||||
}
|
||||
|
||||
void usb_fetch_and_parse_descriptors(usb_dev_handle *udev)
|
||||
{
|
||||
struct usb_device *dev = udev->device;
|
||||
int i;
|
||||
|
||||
if (dev->descriptor.bNumConfigurations > USB_MAXCONFIG)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "Too many configurations (%d > %d)\n", dev->descriptor.bNumConfigurations, USB_MAXCONFIG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dev->descriptor.bNumConfigurations < 1)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "Not enough configurations (%d < %d)\n", dev->descriptor.bNumConfigurations, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
dev->config = (struct usb_config_descriptor *)malloc(dev->descriptor.bNumConfigurations * sizeof(struct usb_config_descriptor));
|
||||
if (!dev->config)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "Unable to allocate memory for config descriptor\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(dev->config, 0, dev->descriptor.bNumConfigurations *
|
||||
sizeof(struct usb_config_descriptor));
|
||||
|
||||
for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
|
||||
{
|
||||
unsigned char buffer[USB_DT_CONFIG_SIZE], *bigbuffer;
|
||||
struct usb_config_descriptor config;
|
||||
int res;
|
||||
|
||||
/* Get the first 8 bytes so we can figure out what the total length is */
|
||||
res = usb_get_descriptor(udev, USB_DT_CONFIG, (unsigned char)i, buffer, USB_DT_CONFIG_SIZE);
|
||||
if (res < USB_DT_CONFIG_SIZE)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
{
|
||||
if (res < 0)
|
||||
fprintf(stderr, "Unable to get descriptor (%d)\n", res);
|
||||
else
|
||||
fprintf(stderr, "Config descriptor too short (expected %d, got %d)\n", USB_DT_CONFIG_SIZE, res);
|
||||
}
|
||||
|
||||
goto err;
|
||||
}
|
||||
|
||||
usb_parse_descriptor(buffer, "bbw", &config);
|
||||
|
||||
bigbuffer = malloc(config.wTotalLength);
|
||||
if (!bigbuffer)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
fprintf(stderr, "Unable to allocate memory for descriptors\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
res = usb_get_descriptor(udev, USB_DT_CONFIG, (unsigned char)i, bigbuffer,
|
||||
config.wTotalLength);
|
||||
if (res < config.wTotalLength)
|
||||
{
|
||||
if (usb_debug >= 1)
|
||||
{
|
||||
if (res < 0)
|
||||
fprintf(stderr, "Unable to get descriptor (%d)\n", res);
|
||||
else
|
||||
fprintf(stderr, "Config descriptor too short (expected %d, got %d)\n", config.wTotalLength, res);
|
||||
}
|
||||
|
||||
free(bigbuffer);
|
||||
goto err;
|
||||
}
|
||||
|
||||
res = usb_parse_configuration(&dev->config[i], bigbuffer);
|
||||
if (usb_debug >= 2)
|
||||
{
|
||||
if (res > 0)
|
||||
fprintf(stderr, "Descriptor data still left\n");
|
||||
else if (res < 0)
|
||||
fprintf(stderr, "Unable to parse descriptors\n");
|
||||
}
|
||||
|
||||
free(bigbuffer);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
err:
|
||||
free(dev->config);
|
||||
|
||||
dev->config = NULL;
|
||||
}
|
||||
|
400
external/libusb/src/driver_api.h
vendored
Normal file
400
external/libusb/src/driver_api.h
vendored
Normal file
@@ -0,0 +1,400 @@
|
||||
/* libusb-win32, Generic Windows USB Library
|
||||
* Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __DRIVER_API_H__
|
||||
#define __DRIVER_API_H__
|
||||
|
||||
enum
|
||||
{
|
||||
LIBUSB_DEBUG_OFF,
|
||||
LIBUSB_DEBUG_ERR,
|
||||
LIBUSB_DEBUG_WRN,
|
||||
LIBUSB_DEBUG_MSG,
|
||||
|
||||
LIBUSB_DEBUG_MAX = 0xff,
|
||||
};
|
||||
|
||||
|
||||
/* 64k */
|
||||
#define LIBUSB_MAX_READ_WRITE 0x10000
|
||||
|
||||
#define LIBUSB_MAX_NUMBER_OF_DEVICES 256
|
||||
#define LIBUSB_MAX_NUMBER_OF_CHILDREN 32
|
||||
|
||||
#define LIBUSB_IOCTL_SET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_SET_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_CLEAR_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x806, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_STATUS CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x807, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_SET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x808, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x809, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x80A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x80B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_VENDOR_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x80C, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_VENDOR_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x80D, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_RESET_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x80E, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_ABORT_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x80F, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_RESET_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x810, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_SET_DEBUG_LEVEL CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x811, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x812, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_ISOCHRONOUS_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x813, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_ISOCHRONOUS_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x814, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x815, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x816, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// supported after 0.1.12.2
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// [trobinso] adds support for querying device properties
|
||||
#define LIBUSB_IOCTL_GET_DEVICE_PROPERTY CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x900, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_CUSTOM_REG_PROPERTY CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x901, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// supported after 1.2.0.0
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#define LIBUSB_IOCTL_GET_CACHED_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x902, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// supported after 1.2.2.0
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#define LIBUSB_IOCTL_GET_OBJECT_NAME CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x8FF, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// supported after 1.2.3.0
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#define LIBUSB_IOCTL_QUERY_DEVICE_INFORMATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x904, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_SET_PIPE_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x906, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_PIPE_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x907, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_SET_POWER_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x908, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_GET_POWER_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x909, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_CONTROL_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x90A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_CONTROL_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x90B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSB_IOCTL_FLUSH_PIPE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x90C, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSBK_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x90D, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSBK_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x90E, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSBK_IOCTL_RELEASE_ALL_INTERFACES CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x90F, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSBK_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x910, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define LIBUSBK_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x911, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// supported after 1.2.4.8 (libusb0.sys only)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#define LIBUSB_IOCTL_RESET_DEVICE_EX CTL_CODE(FILE_DEVICE_UNKNOWN,\
|
||||
0x817, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#include <pshpack1.h>
|
||||
|
||||
enum LIBUSB0_TRANSFER_FLAGS
|
||||
{
|
||||
TRANSFER_FLAGS_SHORT_NOT_OK = 1 << 0,
|
||||
TRANSFER_FLAGS_ISO_SET_START_FRAME = 1 << 30,
|
||||
TRANSFER_FLAGS_ISO_ADD_LATENCY = 1 << 31,
|
||||
};
|
||||
|
||||
/*
|
||||
typedef struct
|
||||
{
|
||||
unsigned int timeout;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned int configuration;
|
||||
} configuration;
|
||||
struct
|
||||
{
|
||||
unsigned int interface;
|
||||
unsigned int altsetting;
|
||||
} interface;
|
||||
struct
|
||||
{
|
||||
unsigned int endpoint;
|
||||
unsigned int packet_size;
|
||||
|
||||
// TODO: max_transfer_size, short transfer not ok, use iso_start_frame
|
||||
unsigned int max_transfer_size;
|
||||
unsigned int transfer_flags;
|
||||
unsigned int iso_start_frame_latency;
|
||||
} endpoint;
|
||||
struct
|
||||
{
|
||||
unsigned int type;
|
||||
unsigned int recipient;
|
||||
unsigned int request;
|
||||
unsigned int value;
|
||||
unsigned int index;
|
||||
} vendor;
|
||||
struct
|
||||
{
|
||||
unsigned int recipient;
|
||||
unsigned int feature;
|
||||
unsigned int index;
|
||||
} feature;
|
||||
struct
|
||||
{
|
||||
unsigned int recipient;
|
||||
unsigned int index;
|
||||
unsigned int status;
|
||||
} status;
|
||||
struct
|
||||
{
|
||||
unsigned int type;
|
||||
unsigned int index;
|
||||
unsigned int language_id;
|
||||
unsigned int recipient;
|
||||
} descriptor;
|
||||
struct
|
||||
{
|
||||
unsigned int level;
|
||||
} debug;
|
||||
struct
|
||||
{
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
unsigned int micro;
|
||||
unsigned int nano;
|
||||
unsigned int mod_value;
|
||||
} version;
|
||||
struct
|
||||
{
|
||||
unsigned int property;
|
||||
} device_property;
|
||||
struct
|
||||
{
|
||||
unsigned int key_type;
|
||||
unsigned int name_offset;
|
||||
unsigned int value_offset;
|
||||
unsigned int value_length;
|
||||
} device_registry_key;
|
||||
struct
|
||||
{
|
||||
// 0 - device plug and play registry key pathname
|
||||
unsigned int objname_index;
|
||||
} objname;
|
||||
};
|
||||
} libusb_request;
|
||||
*/
|
||||
|
||||
#pragma warning(disable:4201)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int interface_number;
|
||||
unsigned int altsetting_number;
|
||||
|
||||
unsigned char intf_use_index:1; // libusbK Only
|
||||
unsigned char altf_use_index:1; // libusbK Only
|
||||
unsigned char:6;
|
||||
|
||||
short interface_index; // libusbK Only
|
||||
short altsetting_index; // libusbK Only
|
||||
}interface_request_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int timeout;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
unsigned int configuration;
|
||||
} configuration;
|
||||
|
||||
interface_request_t intf;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned int endpoint;
|
||||
unsigned int packet_size;
|
||||
|
||||
// TODO: max_transfer_size, short transfer not ok, use iso_start_frame
|
||||
unsigned int max_transfer_size;
|
||||
unsigned int transfer_flags;
|
||||
unsigned int iso_start_frame_latency;
|
||||
} endpoint;
|
||||
struct
|
||||
{
|
||||
unsigned int type;
|
||||
unsigned int recipient;
|
||||
unsigned int request;
|
||||
unsigned int value;
|
||||
unsigned int index;
|
||||
} vendor;
|
||||
struct
|
||||
{
|
||||
unsigned int recipient;
|
||||
unsigned int feature;
|
||||
unsigned int index;
|
||||
} feature;
|
||||
struct
|
||||
{
|
||||
unsigned int recipient;
|
||||
unsigned int index;
|
||||
unsigned int status;
|
||||
} status;
|
||||
struct
|
||||
{
|
||||
unsigned int type;
|
||||
unsigned int index;
|
||||
unsigned int language_id;
|
||||
unsigned int recipient;
|
||||
} descriptor;
|
||||
struct
|
||||
{
|
||||
unsigned int level;
|
||||
} debug;
|
||||
struct
|
||||
{
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
unsigned int micro;
|
||||
unsigned int nano;
|
||||
unsigned int mod_value;
|
||||
} version;
|
||||
struct
|
||||
{
|
||||
unsigned int property;
|
||||
} device_property;
|
||||
struct
|
||||
{
|
||||
unsigned int key_type;
|
||||
unsigned int name_offset;
|
||||
unsigned int value_offset;
|
||||
unsigned int value_length;
|
||||
} device_registry_key;
|
||||
struct
|
||||
{
|
||||
// 0 - device plug and play registry key pathname
|
||||
unsigned int objname_index;
|
||||
} objname;
|
||||
struct
|
||||
{
|
||||
ULONG information_type;
|
||||
} query_device;
|
||||
struct
|
||||
{
|
||||
unsigned int interface_index;
|
||||
unsigned int pipe_id;
|
||||
unsigned int policy_type;
|
||||
} pipe_policy;
|
||||
struct
|
||||
{
|
||||
unsigned int policy_type;
|
||||
} power_policy;
|
||||
struct
|
||||
{
|
||||
unsigned int reset_type;
|
||||
} reset_ex;
|
||||
|
||||
// WDF_USB_CONTROL_SETUP_PACKET control;
|
||||
struct
|
||||
{
|
||||
UCHAR RequestType;
|
||||
UCHAR Request;
|
||||
USHORT Value;
|
||||
USHORT Index;
|
||||
USHORT Length;
|
||||
} control;
|
||||
};
|
||||
} libusb_request;
|
||||
#pragma warning(default:4201)
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
#endif
|
416
external/libusb/src/error.c
vendored
Normal file
416
external/libusb/src/error.c
vendored
Normal file
@@ -0,0 +1,416 @@
|
||||
/* Error & Logging functions
|
||||
|
||||
Copyright (C) 2010 Travis Robinson. <libusbdotnet@gmail.com>
|
||||
website: http://sourceforge.net/projects/libusb-win32
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, please visit www.gnu.org.
|
||||
*/
|
||||
|
||||
#include "error.h"
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if IS_DRIVER
|
||||
#ifdef __GNUC__
|
||||
#define OBJ_KERNEL_HANDLE 0x00000200L
|
||||
#include <ddk/usb100.h>
|
||||
#include <ddk/usbdi.h>
|
||||
#include <ddk/winddk.h>
|
||||
#include "usbdlib_gcc.h"
|
||||
#else
|
||||
#include <ntddk.h>
|
||||
#endif
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define USB_ERROR_BEGIN 500000
|
||||
|
||||
#ifndef LOG_APPNAME
|
||||
#define LOG_APPNAME "LOG_APPNAME define missing"
|
||||
#endif
|
||||
|
||||
#define GetLogLevel(UsbLogLevel) ((UsbLogLevel & LOG_LEVEL_MASK)>LOG_LEVEL_MAX?LOG_LEVEL_MAX:UsbLogLevel & LOG_LEVEL_MASK)
|
||||
#define GetLogOuput(LogOutputType) (LogOutputType>0?(_LOG_OUTPUT_TYPE & LogOutputType):1)
|
||||
|
||||
void usb_err_v (const char* function, const char* format, va_list args);
|
||||
void usb_wrn_v (const char* function, const char* format, va_list args);
|
||||
void usb_msg_v (const char* function, const char* format, va_list args);
|
||||
void usb_dbg_v (const char* function, const char* format, va_list args);
|
||||
|
||||
void usb_log_v (enum USB_LOG_LEVEL level, const char* function, const char* format, va_list args);
|
||||
void _usb_log (enum USB_LOG_LEVEL level, const char* app_name, const char* function, const char* format, ...);
|
||||
void _usb_log_v (enum USB_LOG_LEVEL level, const char* app_name, const char* function, const char* format, va_list args);
|
||||
|
||||
static int usb_log_def_handler(enum USB_LOG_LEVEL level,
|
||||
const char* app_name,
|
||||
const char* prefix,
|
||||
const char* func,
|
||||
int app_prefix_func_end,
|
||||
char* message,
|
||||
int message_length);
|
||||
|
||||
#define STRIP_PREFIX(stringSrc, stringPrefix) \
|
||||
(strstr(stringSrc,stringPrefix)==stringSrc?stringSrc+strlen(stringPrefix):stringSrc)
|
||||
|
||||
static const char *log_level_string[LOG_LEVEL_MAX+1] =
|
||||
{
|
||||
"off",
|
||||
"err",
|
||||
"wrn",
|
||||
"",
|
||||
"dbg",
|
||||
|
||||
"unknown",
|
||||
};
|
||||
|
||||
static const char *skipped_function_prefix_list[] =
|
||||
{
|
||||
"usb_registry_",
|
||||
"usb_",
|
||||
NULL
|
||||
};
|
||||
|
||||
int usb_error_errno = 0;
|
||||
log_hander_t user_log_hander = NULL;
|
||||
|
||||
#if (defined(_DEBUG) || defined(DEBUG) || defined(DBG))
|
||||
int __usb_log_level = LOG_LEVEL_MAX;
|
||||
#else
|
||||
int __usb_log_level = LOG_OFF;
|
||||
#endif
|
||||
|
||||
usb_error_type_t usb_error_type = USB_ERROR_TYPE_NONE;
|
||||
|
||||
const char** skipped_function_prefix = skipped_function_prefix_list;
|
||||
|
||||
#if !IS_DRIVER
|
||||
|
||||
char usb_error_str[LOGBUF_SIZE] = "";
|
||||
|
||||
char *usb_strerror(void)
|
||||
{
|
||||
switch (usb_error_type)
|
||||
{
|
||||
case USB_ERROR_TYPE_NONE:
|
||||
return "No error";
|
||||
case USB_ERROR_TYPE_STRING:
|
||||
return usb_error_str;
|
||||
case USB_ERROR_TYPE_ERRNO:
|
||||
if (usb_error_errno > -USB_ERROR_BEGIN)
|
||||
return strerror(usb_error_errno);
|
||||
else
|
||||
/* Any error we don't know falls under here */
|
||||
return "Unknown error";
|
||||
}
|
||||
|
||||
return "Unknown error";
|
||||
}
|
||||
|
||||
/* returns Windows' last error in a human readable form */
|
||||
const char *usb_win_error_to_string(void)
|
||||
{
|
||||
static char tmp[LOGBUF_SIZE];
|
||||
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
|
||||
LANG_USER_DEFAULT, tmp, sizeof(tmp) - 1, NULL);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
int usb_win_error_to_errno(void)
|
||||
{
|
||||
switch (GetLastError())
|
||||
{
|
||||
case ERROR_SUCCESS:
|
||||
return 0;
|
||||
case ERROR_INVALID_PARAMETER:
|
||||
return EINVAL;
|
||||
case ERROR_SEM_TIMEOUT:
|
||||
case ERROR_OPERATION_ABORTED:
|
||||
return ETRANSFER_TIMEDOUT;
|
||||
case ERROR_NOT_ENOUGH_MEMORY:
|
||||
return ENOMEM;
|
||||
default:
|
||||
return EIO;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void usb_err(const char* function, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
usb_err_v(function, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
void usb_wrn(const char* function, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
usb_wrn_v(function, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void usb_msg(const char* function, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
usb_msg_v(function, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void usb_dbg(const char* function, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
usb_dbg_v(function, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void usb_log(enum USB_LOG_LEVEL level, const char* function, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
usb_log_v(level, function, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void usb_err_v(const char* function, const char* format, va_list args)
|
||||
{
|
||||
usb_log_v(LOG_ERROR, function, format, args);
|
||||
}
|
||||
|
||||
void usb_wrn_v(const char* function, const char* format, va_list args)
|
||||
{
|
||||
usb_log_v(LOG_WARNING, function, format, args);
|
||||
}
|
||||
|
||||
void usb_msg_v(const char* function, const char* format, va_list args)
|
||||
{
|
||||
usb_log_v(LOG_INFO, function, format, args);
|
||||
}
|
||||
|
||||
void usb_dbg_v(const char* function, const char* format, va_list args)
|
||||
{
|
||||
usb_log_v(LOG_DEBUG, function, format, args);
|
||||
}
|
||||
|
||||
void usb_log_v(enum USB_LOG_LEVEL level, const char* function, const char* format, va_list args)
|
||||
{
|
||||
_usb_log_v(level, LOG_APPNAME, function, format, args);
|
||||
}
|
||||
|
||||
void _usb_log(enum USB_LOG_LEVEL level, const char* app_name, const char* function, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
_usb_log_v(level, app_name, function, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void _usb_log_v(enum USB_LOG_LEVEL level,
|
||||
const char* app_name,
|
||||
const char* function,
|
||||
const char* format,
|
||||
va_list args)
|
||||
{
|
||||
|
||||
char local_buffer[LOGBUF_SIZE];
|
||||
int totalCount, count;
|
||||
const char* prefix;
|
||||
const char* func;
|
||||
char* buffer;
|
||||
int masked_level;
|
||||
int app_prefix_func_end;
|
||||
#ifndef LOG_STYLE_SHORT
|
||||
const char** skip_list = NULL;
|
||||
#endif
|
||||
|
||||
masked_level = GetLogLevel(level);
|
||||
|
||||
if (__usb_log_level < masked_level && masked_level != LOG_ERROR) return;
|
||||
buffer = local_buffer;
|
||||
totalCount = 0;
|
||||
count = 0;
|
||||
prefix = log_level_string[masked_level];
|
||||
func = function;
|
||||
app_prefix_func_end = 0;
|
||||
|
||||
if (masked_level > LOG_LEVEL_MAX) masked_level = LOG_LEVEL_MAX;
|
||||
|
||||
if ((level & LOG_RAW) == LOG_RAW)
|
||||
{
|
||||
count = _vsnprintf(buffer, LOGBUF_SIZE-1, format, args);
|
||||
if (count > 0)
|
||||
{
|
||||
buffer += count;
|
||||
totalCount += count;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef LOG_STYLE_SHORT
|
||||
if ((prefix) && strlen(prefix))
|
||||
{
|
||||
count = _snprintf(buffer, (LOGBUF_SIZE-1), "%s: ", prefix);
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
}
|
||||
func = "";
|
||||
#else
|
||||
func = function;
|
||||
|
||||
if (func)
|
||||
{
|
||||
// strip some prefixes to shorten function names
|
||||
skip_list=skipped_function_prefix;
|
||||
while(*skip_list && ((func)) && func[0])
|
||||
{
|
||||
func = STRIP_PREFIX(func,skip_list[0]);
|
||||
skip_list++;
|
||||
}
|
||||
}
|
||||
|
||||
if(!func) func="none";
|
||||
|
||||
// print app name, level string and short function name
|
||||
if ((prefix) && strlen(prefix))
|
||||
{
|
||||
count = _snprintf(buffer, (LOGBUF_SIZE-1), "%s:%s [%s] ", app_name, prefix, func);
|
||||
}
|
||||
else
|
||||
{
|
||||
count = _snprintf(buffer, (LOGBUF_SIZE-1), "%s:[%s] ", app_name, func);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (count >= 0)
|
||||
{
|
||||
app_prefix_func_end = count;
|
||||
buffer += count;
|
||||
totalCount += count;
|
||||
count = _vsnprintf(buffer, (LOGBUF_SIZE-1) - totalCount, format, args);
|
||||
if (count > 0)
|
||||
{
|
||||
buffer += count;
|
||||
totalCount += count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count < 0)
|
||||
totalCount = LOGBUF_SIZE - 1;
|
||||
|
||||
// make sure its null terminated
|
||||
local_buffer[totalCount] = 0;
|
||||
|
||||
#if (!IS_DRIVER)
|
||||
if (masked_level == LOG_ERROR)
|
||||
{
|
||||
// if this is an error message then store it
|
||||
strncpy(usb_error_str, local_buffer, totalCount);
|
||||
usb_error_str[totalCount] = '\0';
|
||||
usb_error_type = USB_ERROR_TYPE_STRING;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (user_log_hander)
|
||||
{
|
||||
if (user_log_hander(level, app_name, prefix, func, app_prefix_func_end, local_buffer, totalCount))
|
||||
return;
|
||||
}
|
||||
if (__usb_log_level >= masked_level)
|
||||
{
|
||||
usb_log_def_handler(level, app_name, prefix, func, app_prefix_func_end, local_buffer, totalCount);
|
||||
}
|
||||
}
|
||||
|
||||
void usb_log_set_level(enum USB_LOG_LEVEL level)
|
||||
{
|
||||
// Debug builds of the driver force all messages on; all the time;
|
||||
// Application can no longer change this.
|
||||
//
|
||||
#if (defined(_DEBUG) || defined(DEBUG) || defined(DBG))
|
||||
__usb_log_level = LOG_LEVEL_MAX;
|
||||
#else
|
||||
__usb_log_level = level > LOG_LEVEL_MAX ? LOG_LEVEL_MAX : level;
|
||||
#endif
|
||||
}
|
||||
|
||||
int usb_log_get_level()
|
||||
{
|
||||
return __usb_log_level;
|
||||
}
|
||||
|
||||
/* Default log handler
|
||||
*/
|
||||
static int usb_log_def_handler(enum USB_LOG_LEVEL level,
|
||||
const char* app_name,
|
||||
const char* prefix,
|
||||
const char* func,
|
||||
int app_prefix_func_end,
|
||||
char* message,
|
||||
int message_length)
|
||||
{
|
||||
#if IS_DRIVER
|
||||
DbgPrint("%s",message);
|
||||
#else
|
||||
#if GetLogOuput(LOG_OUTPUT_TYPE_FILE)
|
||||
FILE* file;
|
||||
file = fopen(LOG_FILE_PATH,"a");
|
||||
if (file)
|
||||
{
|
||||
fwrite(message,1,strlen(message),file);
|
||||
fflush(file);
|
||||
fclose(file);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if GetLogOuput(LOG_OUTPUT_TYPE_STDERR)
|
||||
fprintf(stderr, "%s", message);
|
||||
#endif
|
||||
|
||||
#if GetLogOuput(LOG_OUTPUT_TYPE_DEBUGWINDOW)
|
||||
OutputDebugStringA(message);
|
||||
#endif
|
||||
|
||||
|
||||
#if GetLogOuput(LOG_OUTPUT_TYPE_MSGBOX)
|
||||
if (GetLogLevel(level)==LOG_ERROR)
|
||||
{
|
||||
message[app_prefix_func_end-1]='\0';
|
||||
MessageBoxA(NULL,message+strlen(message),message,MB_OK|MB_ICONERROR);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // IS_DRIVER
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void usb_log_set_handler(log_hander_t log_hander)
|
||||
{
|
||||
user_log_hander = log_hander;
|
||||
}
|
||||
|
||||
log_hander_t usb_log_get_handler(void)
|
||||
{
|
||||
return user_log_hander;
|
||||
}
|
187
external/libusb/src/error.h
vendored
Normal file
187
external/libusb/src/error.h
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
/* Error & Logging functions
|
||||
|
||||
Copyright (C) 2010 Travis Robinson. <libusbdotnet@gmail.com>
|
||||
website: http://sourceforge.net/projects/libusb-win32
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU (LGPL) General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU (LGPL) General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU (LGPL) General Public License
|
||||
along with this program; if not, please visit www.gnu.org.
|
||||
*/
|
||||
|
||||
#ifndef __ERROR_H__
|
||||
#define __ERROR_H__
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
enum USB_LOG_LEVEL
|
||||
{
|
||||
LOG_OFF,
|
||||
LOG_ERROR,
|
||||
LOG_WARNING,
|
||||
LOG_INFO,
|
||||
LOG_DEBUG,
|
||||
|
||||
LOG_LEVEL_MAX,
|
||||
LOG_LEVEL_MASK=0xff,
|
||||
LOG_RAW=0x100
|
||||
|
||||
};
|
||||
|
||||
/* Connection timed out */
|
||||
#define ETRANSFER_TIMEDOUT 116
|
||||
|
||||
#define LOGBUF_SIZE 512
|
||||
|
||||
// TARGETTYPEs
|
||||
#define PROGRAMconsole 0
|
||||
#define PROGRAMwindows 1
|
||||
#define DYNLINK 2
|
||||
#define DRIVER 3
|
||||
|
||||
// default TARGETTYPE
|
||||
#ifndef TARGETTYPE
|
||||
#define TARGETTYPE PROGRAMconsole
|
||||
#endif
|
||||
|
||||
#define IS_DRIVER (TARGETTYPE==DRIVER)
|
||||
#define IS_CONSOLE_APP (TARGETTYPE==PROGRAMconsole)
|
||||
#define IS_WINDOW_APP (TARGETTYPE==PROGRAMwindows)
|
||||
#define IS_APP (IS_CONSOLE_APP || IS_WINDOW_APP)
|
||||
#define IS_DLL (TARGETTYPE==DYNLINK)
|
||||
|
||||
// NOTE: LOG_OUTPUT_TYPEs can be combined
|
||||
// writes log messages to standard error output
|
||||
#define LOG_OUTPUT_TYPE_STDERR 0x001
|
||||
|
||||
// writes log messages to Win32 OutputDebugString (DbgPrint for drivers)
|
||||
#define LOG_OUTPUT_TYPE_DEBUGWINDOW 0x0002
|
||||
#define LOG_OUTPUT_TYPE_DBGPRINT 0x0002
|
||||
|
||||
// displays error log messages to a messagebox (not recommended)
|
||||
#define LOG_OUTPUT_TYPE_MSGBOX 0x0004
|
||||
|
||||
// writes log messages to Kernel-mode DbgPrint
|
||||
|
||||
// writes log messages directly to a file
|
||||
#define LOG_OUTPUT_TYPE_FILE 0x0010
|
||||
|
||||
// strips all log messages except errors
|
||||
#define LOG_OUTPUT_TYPE_REMOVE 0x0020
|
||||
|
||||
#define LOG_OUTPUT_TYPE_DEFAULT 0x0100
|
||||
|
||||
// File logging is never enabled by default.
|
||||
// The LOG_OUTPUT_TYPE define must be manually
|
||||
// set to enable file logging.
|
||||
#if !IS_DRIVER
|
||||
#ifndef LOG_DIRECTORY
|
||||
#define LOG_FILE_PATH LOG_APPNAME ".log"
|
||||
#else
|
||||
#define LOG_FILE_PATH LOG_DIRECTORY LOG_APPNAME ".log"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (IS_DRIVER) || (IS_DLL) || (IS_WINDOW_APP)
|
||||
// default logging for drivers and dlls
|
||||
#define DEF_LOG_OUTPUT_TYPE LOG_OUTPUT_TYPE_DEBUGWINDOW
|
||||
#else
|
||||
// default logging for applications and everything else
|
||||
#define DEF_LOG_OUTPUT_TYPE LOG_OUTPUT_TYPE_STDERR
|
||||
#endif
|
||||
|
||||
#define _usb_log_do_nothing() while(0)
|
||||
// Default logging output
|
||||
#ifdef LOG_OUTPUT_TYPE
|
||||
// all log messages (except errors) are stripped
|
||||
#if (LOG_OUTPUT_TYPE & LOG_OUTPUT_TYPE_REMOVE)
|
||||
#define USBMSG(format,...) _usb_log_do_nothing()
|
||||
#define USBWRN(format,...) _usb_log_do_nothing()
|
||||
#define USBDBG(format,...) _usb_log_do_nothing()
|
||||
#define USBRAWMSG(format,...) _usb_log_do_nothing()
|
||||
|
||||
#define USBMSG0(format) _usb_log_do_nothing()
|
||||
#define USBWRN0(format) _usb_log_do_nothing()
|
||||
#define USBDBG0(format) _usb_log_do_nothing()
|
||||
#define USBRAWMSG0(format) _usb_log_do_nothing()
|
||||
#endif
|
||||
|
||||
#if (LOG_OUTPUT_TYPE & LOG_OUTPUT_TYPE_DEFAULT)
|
||||
#define _LOG_OUTPUT_TYPE ((LOG_OUTPUT_TYPE & 0xff)|DEF_LOG_OUTPUT_TYPE)
|
||||
#else
|
||||
#define _LOG_OUTPUT_TYPE (LOG_OUTPUT_TYPE)
|
||||
#endif
|
||||
|
||||
#else
|
||||
// if the LOG_OUTPUT_TYPE has not been manually set use
|
||||
// the as defaults.
|
||||
#define _LOG_OUTPUT_TYPE DEF_LOG_OUTPUT_TYPE
|
||||
#endif
|
||||
|
||||
// always keep error messages
|
||||
#define USBERR(format,...) usb_err(__FUNCTION__,format,__VA_ARGS__)
|
||||
#define USBERR0(format) usb_err(__FUNCTION__,"%s",format)
|
||||
|
||||
// only keep debug log messages in debug builds
|
||||
#if !(defined(_DEBUG) || defined(DEBUG) || defined(DBG)) && !defined(USBDBG)
|
||||
#define USBDBG(format,...) _usb_log_do_nothing()
|
||||
#define USBDBG0(format) _usb_log_do_nothing()
|
||||
#endif
|
||||
|
||||
// if USBMSG has not been defined as empty (see above)
|
||||
// then keep all the info and warning log messages
|
||||
#ifndef USBMSG
|
||||
#define USBMSG(format,...) usb_msg(__FUNCTION__,format,__VA_ARGS__)
|
||||
#define USBWRN(format,...) usb_wrn(__FUNCTION__,format,__VA_ARGS__)
|
||||
#define USBRAWMSG(format,...) usb_log(LOG_INFO|LOG_RAW,__FUNCTION__,format,__VA_ARGS__)
|
||||
|
||||
#define USBMSG0(format) usb_msg(__FUNCTION__,"%s",format)
|
||||
#define USBWRN0(format) usb_wrn(__FUNCTION__,"%s",format)
|
||||
#define USBRAWMSG0(format) usb_log(LOG_INFO|LOG_RAW,__FUNCTION__,"%s",format)
|
||||
#endif
|
||||
|
||||
// if USBDBG has not been defined as empty (see above)
|
||||
// then keep all the debug log messages
|
||||
#ifndef USBDBG
|
||||
#define USBDBG(format,...) usb_dbg(__FUNCTION__,format,__VA_ARGS__)
|
||||
#define USBDBG0(format) usb_dbg(__FUNCTION__,"%s",format)
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
USB_ERROR_TYPE_NONE = 0,
|
||||
USB_ERROR_TYPE_STRING,
|
||||
USB_ERROR_TYPE_ERRNO,
|
||||
} usb_error_type_t;
|
||||
|
||||
typedef int (*log_hander_t)(enum USB_LOG_LEVEL level, const char*,const char*,const char*, int, char*, int);
|
||||
|
||||
#if (!IS_DRIVER)
|
||||
const char *usb_win_error_to_string(void);
|
||||
int usb_win_error_to_errno(void);
|
||||
#endif
|
||||
|
||||
void usb_log_set_level(enum USB_LOG_LEVEL level);
|
||||
int usb_log_get_level(void);
|
||||
void usb_log_set_handler(log_hander_t log_hander);
|
||||
log_hander_t usb_log_get_handler(void);
|
||||
|
||||
// these are the core logging functions used by the logging macros
|
||||
// (not used directly)
|
||||
void usb_err (const char* function, const char* format, ...);
|
||||
void usb_wrn (const char* function, const char* format, ...);
|
||||
void usb_msg (const char* function, const char* format, ...);
|
||||
void usb_dbg (const char* function, const char* format, ...);
|
||||
void usb_log (enum USB_LOG_LEVEL level, const char* function, const char* format, ...);
|
||||
|
||||
#endif /* _ERROR_H_ */
|
||||
|
18
external/libusb/src/libusb-win32_version.h
vendored
Normal file
18
external/libusb/src/libusb-win32_version.h
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/* libusb-win32_version.h ++ auto-generated
|
||||
*/
|
||||
#ifndef __LIBUSB_WIN32_VERSION_H
|
||||
#define __LIBUSB_WIN32_VERSION_H
|
||||
|
||||
#define __DEFTOSTR(x) #x
|
||||
#define _DEFTOSTR(x) __DEFTOSTR(x)
|
||||
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_MICRO 5
|
||||
#define VERSION_NANO 0
|
||||
#define VERSION_DATE 07/23/2011
|
||||
|
||||
#define VERSION VERSION_MAJOR.VERSION_MINOR.VERSION_MICRO.VERSION_NANO
|
||||
#define RC_VERSION VERSION_MAJOR,VERSION_MINOR,VERSION_MICRO,VERSION_NANO
|
||||
|
||||
#endif
|
1651
external/libusb/src/registry.c
vendored
Normal file
1651
external/libusb/src/registry.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
221
external/libusb/src/registry.h
vendored
Normal file
221
external/libusb/src/registry.h
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
/* libusb-win32, Generic Windows USB Library
|
||||
* Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
|
||||
* Copyright (c) 2010 Travis Robinson <libusbdotnet@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __USB_REGISTRY_H__
|
||||
#define __USB_REGISTRY_H__
|
||||
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
|
||||
|
||||
#define LIBUSB_DRIVER_NAME_NT "libusb0"
|
||||
#define LIBUSB_DRIVER_NAME_9X "libusb0.sys"
|
||||
|
||||
typedef int bool_t;
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE (!(FALSE))
|
||||
#endif
|
||||
|
||||
#define REGISTRY_BUF_SIZE 512
|
||||
|
||||
typedef struct _filter_file_t filter_file_t;
|
||||
struct _filter_file_t
|
||||
{
|
||||
filter_file_t* next;
|
||||
char name[MAX_PATH];
|
||||
};
|
||||
|
||||
typedef int filter_mode_e;
|
||||
enum _filter_mode_e
|
||||
{
|
||||
FM_NONE = 0,
|
||||
FM_LIST = 1 << 0,
|
||||
FM_INSTALL = 1 << 1,
|
||||
FM_REMOVE = 1 << 2,
|
||||
};
|
||||
|
||||
typedef int filter_type_e;
|
||||
enum _filter_type_e
|
||||
{
|
||||
FT_NONE = 0,
|
||||
FT_CLASS_UPPERFILTER = 1 << 0,
|
||||
FT_CLASS_LOWERFILTER = 1 << 1,
|
||||
FT_DEVICE_UPPERFILTER = 1 << 2,
|
||||
FT_DEVICE_LOWERFILTER = 1 << 3,
|
||||
};
|
||||
|
||||
typedef struct _filter_hwid_t filter_hwid_t;
|
||||
struct _filter_hwid_t
|
||||
{
|
||||
int vid;
|
||||
int pid;
|
||||
int mi;
|
||||
int rev;
|
||||
};
|
||||
|
||||
typedef struct _filter_device_t filter_device_t;
|
||||
struct _filter_device_t
|
||||
{
|
||||
filter_device_t* next;
|
||||
|
||||
char device_name[MAX_PATH];
|
||||
char device_hwid[MAX_PATH];
|
||||
char device_mfg[MAX_PATH];
|
||||
char device_uppers[MAX_PATH];
|
||||
char device_lowers[MAX_PATH];
|
||||
char device_id[MAX_PATH];
|
||||
|
||||
filter_type_e action;
|
||||
};
|
||||
|
||||
typedef struct _filter_class_t filter_class_t;
|
||||
struct _filter_class_t
|
||||
{
|
||||
filter_class_t* next;
|
||||
|
||||
char name[MAX_PATH]; // key
|
||||
|
||||
char class_name[MAX_PATH];
|
||||
char class_guid[MAX_PATH];
|
||||
char class_uppers[MAX_PATH];
|
||||
char class_lowers[MAX_PATH];
|
||||
filter_device_t* class_filter_devices;
|
||||
filter_type_e action;
|
||||
};
|
||||
|
||||
typedef struct _filter_context_t filter_context_t;
|
||||
struct _filter_context_t
|
||||
{
|
||||
union
|
||||
{
|
||||
int switches_value;
|
||||
struct
|
||||
{
|
||||
bool_t add_all_classes:1;
|
||||
bool_t add_device_classes:1;
|
||||
bool_t add_default_classes:1;
|
||||
};
|
||||
}switches;
|
||||
|
||||
filter_mode_e filter_mode;
|
||||
filter_class_t* class_filters;
|
||||
filter_device_t* device_filters;
|
||||
filter_file_t* inf_files;
|
||||
bool_t show_help_only;
|
||||
bool_t remove_all_device_filters;
|
||||
bool_t class_filters_modified;
|
||||
char* prompt_string;
|
||||
char* wait_string;
|
||||
};
|
||||
|
||||
bool_t usb_registry_is_nt(void);
|
||||
|
||||
bool_t usb_registry_restart_device(HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data);
|
||||
bool_t usb_registry_stop_device(HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data);
|
||||
bool_t usb_registry_start_device(HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data);
|
||||
|
||||
bool_t usb_registry_get_property(DWORD which, HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data,
|
||||
char *buf, int size);
|
||||
bool_t usb_registry_set_property(DWORD which, HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data,
|
||||
char *buf, int size);
|
||||
|
||||
bool_t usb_registry_restart_all_devices(void);
|
||||
|
||||
|
||||
void usb_registry_stop_libusb_devices(void);
|
||||
void usb_registry_start_libusb_devices(void);
|
||||
|
||||
bool_t usb_registry_get_mz_value(const char *key, const char *value,
|
||||
char *buf, int size);
|
||||
bool_t usb_registry_set_mz_value(const char *key, const char *value,
|
||||
char *buf, int size);
|
||||
int usb_registry_mz_string_size(const char *src);
|
||||
char *usb_registry_mz_string_find(const char *src, const char *str, bool_t no_case);
|
||||
char *usb_registry_mz_string_find_sub(const char *src, const char *str);
|
||||
bool_t usb_registry_mz_string_insert(char *src, const char *str);
|
||||
bool_t usb_registry_mz_string_remove(char *src, const char *str, bool_t no_case);
|
||||
void usb_registry_mz_string_lower(char *src);
|
||||
|
||||
bool_t usb_registry_get_hardware_id(HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data,
|
||||
char* max_path_buffer);
|
||||
bool_t usb_registry_is_service_libusb(HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data,
|
||||
bool_t* is_libusb_service);
|
||||
bool_t usb_registry_is_service_or_filter_libusb(HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data,
|
||||
bool_t* is_libusb_service);
|
||||
|
||||
bool_t usb_registry_insert_class_filter(filter_context_t* filter_context);
|
||||
bool_t usb_registry_remove_class_filter(filter_context_t* filter_context);
|
||||
bool_t usb_registry_remove_device_filter(filter_context_t* filter_context);
|
||||
bool_t usb_registry_free_class_keys(filter_class_t **head);
|
||||
bool_t usb_registry_get_usb_class_keys(filter_context_t* filter_context, bool_t refresh_only);
|
||||
bool_t usb_registry_get_all_class_keys(filter_context_t* filter_context, bool_t refresh_only);
|
||||
bool_t usb_registry_get_device_filter_type(HDEVINFO dev_info,
|
||||
SP_DEVINFO_DATA *dev_info_data,
|
||||
filter_type_e* filter_type);
|
||||
|
||||
bool_t usb_registry_add_usb_class_key(filter_context_t* filter_context, const char* class_guid);
|
||||
bool_t usb_registry_add_filter_device_keys(filter_device_t** head,
|
||||
const char* id,
|
||||
const char* hwid,
|
||||
const char* name,
|
||||
const char* mfg,
|
||||
const char* uppers_mz,
|
||||
const char* lowers_mz,
|
||||
filter_device_t** found);
|
||||
|
||||
bool_t usb_registry_add_filter_file_keys(filter_file_t** head,
|
||||
const char* name,
|
||||
filter_file_t** found);
|
||||
|
||||
bool_t usb_registry_lookup_class_keys_by_name(filter_class_t** head);
|
||||
bool_t usb_registry_add_class_key(filter_class_t **head,
|
||||
const char *key,
|
||||
const char *class_name,
|
||||
const char *class_guid,
|
||||
filter_class_t **found,
|
||||
bool_t update_only);
|
||||
|
||||
bool_t usb_registry_insert_device_filters(filter_context_t* filter_context);
|
||||
bool_t usb_registry_insert_device_filter(filter_context_t* filter_context, char* hwid, bool_t upper,
|
||||
HDEVINFO dev_info, SP_DEVINFO_DATA *dev_info_data);
|
||||
|
||||
bool_t usb_registry_free_filter_devices(filter_device_t **head);
|
||||
bool_t usb_registry_free_filter_files(filter_file_t **head);
|
||||
|
||||
filter_device_t* usb_registry_match_filter_device(filter_device_t** head,
|
||||
HDEVINFO dev_info, PSP_DEVINFO_DATA dev_info_data);
|
||||
|
||||
bool_t usb_registry_mz_to_sz(char* buf_mz, char separator);
|
||||
bool_t usb_registry_fill_filter_hwid(const char* hwid, filter_hwid_t* filter_hwid);
|
||||
|
||||
#endif
|
317
external/libusb/src/usb.c
vendored
Normal file
317
external/libusb/src/usb.c
vendored
Normal file
@@ -0,0 +1,317 @@
|
||||
/*
|
||||
* Main API entry point
|
||||
*
|
||||
* Copyright (c) 2000-2003 Johannes Erdfelt <johannes@erdfelt.com>
|
||||
*
|
||||
* This library is covered by the LGPL, read LICENSE for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h> /* getenv */
|
||||
#include <stdio.h> /* stderr */
|
||||
#include <string.h> /* strcmp */
|
||||
#include <errno.h>
|
||||
|
||||
#include "usbi.h"
|
||||
|
||||
int usb_debug = 0;
|
||||
struct usb_bus *_usb_busses = NULL;
|
||||
|
||||
int usb_find_busses(void)
|
||||
{
|
||||
struct usb_bus *busses, *bus;
|
||||
int ret, changes = 0;
|
||||
|
||||
ret = usb_os_find_busses(&busses);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* Now walk through all of the busses we know about and compare against
|
||||
* this new list. Any duplicates will be removed from the new list.
|
||||
* If we don't find it in the new list, the bus was removed. Any
|
||||
* busses still in the new list, are new to us.
|
||||
*/
|
||||
bus = _usb_busses;
|
||||
while (bus)
|
||||
{
|
||||
int found = 0;
|
||||
struct usb_bus *nbus, *tbus = bus->next;
|
||||
|
||||
nbus = busses;
|
||||
while (nbus)
|
||||
{
|
||||
struct usb_bus *tnbus = nbus->next;
|
||||
|
||||
if (!strcmp(bus->dirname, nbus->dirname))
|
||||
{
|
||||
/* Remove it from the new busses list */
|
||||
LIST_DEL(busses, nbus);
|
||||
|
||||
usb_free_bus(nbus);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
nbus = tnbus;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
/* The bus was removed from the system */
|
||||
LIST_DEL(_usb_busses, bus);
|
||||
usb_free_bus(bus);
|
||||
changes++;
|
||||
}
|
||||
|
||||
bus = tbus;
|
||||
}
|
||||
|
||||
/*
|
||||
* Anything on the *busses list is new. So add them to usb_busses and
|
||||
* process them like the new bus it is.
|
||||
*/
|
||||
bus = busses;
|
||||
while (bus)
|
||||
{
|
||||
struct usb_bus *tbus = bus->next;
|
||||
|
||||
/*
|
||||
* Remove it from the temporary list first and add it to the real
|
||||
* usb_busses list.
|
||||
*/
|
||||
LIST_DEL(busses, bus);
|
||||
|
||||
LIST_ADD(_usb_busses, bus);
|
||||
|
||||
changes++;
|
||||
|
||||
bus = tbus;
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
int usb_find_devices(void)
|
||||
{
|
||||
struct usb_bus *bus;
|
||||
int ret, changes = 0;
|
||||
|
||||
for (bus = usb_busses; bus; bus = bus->next)
|
||||
{
|
||||
struct usb_device *devices, *dev;
|
||||
|
||||
/* Find all of the devices and put them into a temporary list */
|
||||
ret = usb_os_find_devices(bus, &devices);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/*
|
||||
* Now walk through all of the devices we know about and compare
|
||||
* against this new list. Any duplicates will be removed from the new
|
||||
* list. If we don't find it in the new list, the device was removed.
|
||||
* Any devices still in the new list, are new to us.
|
||||
*/
|
||||
dev = bus->devices;
|
||||
while (dev)
|
||||
{
|
||||
int found = 0;
|
||||
struct usb_device *ndev, *tdev = dev->next;
|
||||
|
||||
ndev = devices;
|
||||
while (ndev)
|
||||
{
|
||||
struct usb_device *tndev = ndev->next;
|
||||
|
||||
if (!strcmp(dev->filename, ndev->filename))
|
||||
{
|
||||
/* Remove it from the new devices list */
|
||||
LIST_DEL(devices, ndev);
|
||||
|
||||
usb_free_dev(ndev);
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
ndev = tndev;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
/* The device was removed from the system */
|
||||
LIST_DEL(bus->devices, dev);
|
||||
usb_free_dev(dev);
|
||||
changes++;
|
||||
}
|
||||
|
||||
dev = tdev;
|
||||
}
|
||||
|
||||
/*
|
||||
* Anything on the *devices list is new. So add them to bus->devices and
|
||||
* process them like the new device it is.
|
||||
*/
|
||||
dev = devices;
|
||||
while (dev)
|
||||
{
|
||||
struct usb_device *tdev = dev->next;
|
||||
|
||||
/*
|
||||
* Remove it from the temporary list first and add it to the real
|
||||
* bus->devices list.
|
||||
*/
|
||||
LIST_DEL(devices, dev);
|
||||
|
||||
/*
|
||||
* Some ports fetch the descriptors on scanning (like Linux) so we don't
|
||||
* need to fetch them again.
|
||||
*/
|
||||
if (!dev->config)
|
||||
{
|
||||
usb_dev_handle *udev;
|
||||
|
||||
udev = usb_open(dev);
|
||||
if (udev)
|
||||
{
|
||||
usb_fetch_and_parse_descriptors(udev);
|
||||
|
||||
usb_close(udev);
|
||||
}
|
||||
}
|
||||
|
||||
// [ID:2928293 Tim Green]
|
||||
//
|
||||
if (dev->config)
|
||||
{
|
||||
LIST_ADD(bus->devices, dev);
|
||||
changes++;
|
||||
}
|
||||
|
||||
dev = tdev;
|
||||
}
|
||||
|
||||
usb_os_determine_children(bus);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
void usb_init(void)
|
||||
{
|
||||
if (getenv("USB_DEBUG"))
|
||||
usb_set_debug(atoi(getenv("USB_DEBUG")));
|
||||
|
||||
usb_os_init();
|
||||
}
|
||||
|
||||
usb_dev_handle *usb_open(struct usb_device *dev)
|
||||
{
|
||||
usb_dev_handle *udev;
|
||||
|
||||
udev = malloc(sizeof(*udev));
|
||||
if (!udev)
|
||||
return NULL;
|
||||
|
||||
udev->fd = -1;
|
||||
udev->device = dev;
|
||||
udev->bus = dev->bus;
|
||||
udev->config = udev->interface = udev->altsetting = -1;
|
||||
|
||||
if (usb_os_open(udev) < 0)
|
||||
{
|
||||
free(udev);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return udev;
|
||||
}
|
||||
|
||||
int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
|
||||
size_t buflen)
|
||||
{
|
||||
/*
|
||||
* We can't use usb_get_descriptor() because it's lacking the index
|
||||
* parameter. This will be fixed in libusb 1.0
|
||||
*/
|
||||
return usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
|
||||
(USB_DT_STRING << 8) + index, langid, buf, (int)buflen, 1000);
|
||||
}
|
||||
|
||||
int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf, size_t buflen)
|
||||
{
|
||||
char tbuf[255]; /* Some devices choke on size > 255 */
|
||||
int ret, langid, si, di;
|
||||
|
||||
/*
|
||||
* Asking for the zero'th index is special - it returns a string
|
||||
* descriptor that contains all the language IDs supported by the
|
||||
* device. Typically there aren't many - often only one. The
|
||||
* language IDs are 16 bit numbers, and they start at the third byte
|
||||
* in the descriptor. See USB 2.0 specification, section 9.6.7, for
|
||||
* more information on this. */
|
||||
ret = usb_get_string(dev, 0, 0, tbuf, sizeof(tbuf));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (ret < 4)
|
||||
return -EIO;
|
||||
|
||||
langid = tbuf[2] | (tbuf[3] << 8);
|
||||
|
||||
ret = usb_get_string(dev, index, langid, tbuf, sizeof(tbuf));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (tbuf[1] != USB_DT_STRING)
|
||||
return -EIO;
|
||||
|
||||
if (tbuf[0] > ret)
|
||||
return -EFBIG;
|
||||
|
||||
for (di = 0, si = 2; si < tbuf[0]; si += 2)
|
||||
{
|
||||
if (di >= ((int)buflen - 1))
|
||||
break;
|
||||
|
||||
if (tbuf[si + 1]) /* high byte */
|
||||
buf[di++] = '?';
|
||||
else
|
||||
buf[di++] = tbuf[si];
|
||||
}
|
||||
|
||||
buf[di] = 0;
|
||||
|
||||
return di;
|
||||
}
|
||||
|
||||
int usb_close(usb_dev_handle *dev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = usb_os_close(dev);
|
||||
free(dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct usb_device *usb_device(usb_dev_handle *dev)
|
||||
{
|
||||
return dev->device;
|
||||
}
|
||||
|
||||
void usb_free_dev(struct usb_device *dev)
|
||||
{
|
||||
usb_destroy_configuration(dev);
|
||||
free(dev->children);
|
||||
free(dev);
|
||||
}
|
||||
|
||||
struct usb_bus *usb_get_busses(void)
|
||||
{
|
||||
return _usb_busses;
|
||||
}
|
||||
|
||||
void usb_free_bus(struct usb_bus *bus)
|
||||
{
|
||||
free(bus);
|
||||
}
|
||||
|
75
external/libusb/src/usbi.h
vendored
Normal file
75
external/libusb/src/usbi.h
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef _USBI_H_
|
||||
#define _USBI_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "lusb0_usb.h"
|
||||
#include "error.h"
|
||||
|
||||
extern int usb_debug;
|
||||
|
||||
/* Some quick and generic macros for the simple kind of lists we use */
|
||||
#define LIST_ADD(begin, ent) \
|
||||
do { \
|
||||
if (begin) { \
|
||||
ent->next = begin; \
|
||||
ent->next->prev = ent; \
|
||||
} else \
|
||||
ent->next = NULL; \
|
||||
ent->prev = NULL; \
|
||||
begin = ent; \
|
||||
} while(0)
|
||||
|
||||
#define LIST_DEL(begin, ent) \
|
||||
do { \
|
||||
if (ent->prev) \
|
||||
ent->prev->next = ent->next; \
|
||||
else \
|
||||
begin = ent->next; \
|
||||
if (ent->next) \
|
||||
ent->next->prev = ent->prev; \
|
||||
ent->prev = NULL; \
|
||||
ent->next = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define DESC_HEADER_LENGTH 2
|
||||
#define DEVICE_DESC_LENGTH 18
|
||||
#define CONFIG_DESC_LENGTH 9
|
||||
#define INTERFACE_DESC_LENGTH 9
|
||||
#define ENDPOINT_DESC_LENGTH 7
|
||||
#define ENDPOINT_AUDIO_DESC_LENGTH 9
|
||||
|
||||
struct usb_dev_handle
|
||||
{
|
||||
int fd;
|
||||
|
||||
struct usb_bus *bus;
|
||||
struct usb_device *device;
|
||||
|
||||
int config;
|
||||
int interface;
|
||||
int altsetting;
|
||||
|
||||
/* Added by RMT so implementations can store other per-open-device data */
|
||||
void *impl_info;
|
||||
};
|
||||
|
||||
/* descriptors.c */
|
||||
int usb_parse_descriptor(unsigned char *source, char *description, void *dest);
|
||||
int usb_parse_configuration(struct usb_config_descriptor *config,
|
||||
unsigned char *buffer);
|
||||
void usb_fetch_and_parse_descriptors(usb_dev_handle *udev);
|
||||
void usb_destroy_configuration(struct usb_device *dev);
|
||||
|
||||
/* OS specific routines */
|
||||
int usb_os_find_busses(struct usb_bus **busses);
|
||||
int usb_os_find_devices(struct usb_bus *bus, struct usb_device **devices);
|
||||
int usb_os_determine_children(struct usb_bus *bus);
|
||||
void usb_os_init(void);
|
||||
int usb_os_open(usb_dev_handle *dev);
|
||||
int usb_os_close(usb_dev_handle *dev);
|
||||
|
||||
void usb_free_dev(struct usb_device *dev);
|
||||
void usb_free_bus(struct usb_bus *bus);
|
||||
|
||||
#endif /* _USBI_H_ */
|
||||
|
1281
external/libusb/src/windows.c
vendored
Normal file
1281
external/libusb/src/windows.c
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user