PERFORCE change 151807 for review
Hans Petter Selasky
hselasky at FreeBSD.org
Thu Oct 23 15:03:33 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=151807
Change 151807 by hselasky at hselasky_laptop001 on 2008/10/23 15:03:22
Add full support for LibUSB v0.1.12 through the FreeBSD
specific USB library. LibUSB applications should link
with libusb20 on FreeBSD in the future.
Affected files ...
.. //depot/projects/usb/src/lib/libusb20/Makefile#2 edit
.. //depot/projects/usb/src/lib/libusb20/libusb20.c#3 edit
.. //depot/projects/usb/src/lib/libusb20/libusb20.h#4 edit
.. //depot/projects/usb/src/lib/libusb20/libusb20_compat01.c#1 add
.. //depot/projects/usb/src/lib/libusb20/libusb20_compat01.h#1 add
.. //depot/projects/usb/src/lib/libusb20/libusb20_compat10.c#1 add
.. //depot/projects/usb/src/lib/libusb20/libusb20_compat10.h#1 add
.. //depot/projects/usb/src/lib/libusb20/libusb20_int.h#3 edit
Differences ...
==== //depot/projects/usb/src/lib/libusb20/Makefile#2 (text+ko) ====
@@ -7,8 +7,15 @@
LIB= usb20
SHLIB_MAJOR= 1
SHLIB_MINOR= 0
-SRCS= libusb20.c libusb20_desc.c libusb20_ugen20.c
-INCS= libusb20.h libusb20_desc.h
+SRCS= libusb20.c
+SRCS+= libusb20_desc.c
+SRCS+= libusb20_ugen20.c
+SRCS+= libusb20_compat01.c
+SRCS+= libusb20_compat10.c
+INCS+= libusb20.h
+INCS+= libusb20_desc.h
+INCS+= libusb20_compat01.h
+INCS+= libusb20_compat10.h
MAN= libusb20.3
MKLINT= no
NOGCCERROR=
==== //depot/projects/usb/src/lib/libusb20/libusb20.c#3 (text+ko) ====
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <poll.h>
+#include <ctype.h>
#include <sys/queue.h>
#include "libusb20.h"
@@ -632,9 +633,9 @@
}
int
-libusb20_dev_request_sync(struct libusb20_device *pdev, struct LIBUSB20_CONTROL_SETUP_DECODED *setup,
- void *data, uint16_t *pactlen, uint32_t timeout,
- uint8_t flags)
+libusb20_dev_request_sync(struct libusb20_device *pdev,
+ struct LIBUSB20_CONTROL_SETUP_DECODED *setup, void *data,
+ uint16_t *pactlen, uint32_t timeout, uint8_t flags)
{
int error;
@@ -643,6 +644,128 @@
return (error);
}
+int
+libusb20_dev_req_string_sync(struct libusb20_device *pdev,
+ uint8_t index, uint16_t langid, void *ptr, uint16_t len)
+{
+ struct LIBUSB20_CONTROL_SETUP_DECODED req;
+ int error;
+
+ if (len < 4) {
+ /* invalid length */
+ return (LIBUSB20_ERROR_INVALID_PARAM);
+ }
+ LIBUSB20_INIT(LIBUSB20_CONTROL_SETUP, &req);
+
+ /*
+ * We need to read the USB string in two steps else some USB
+ * devices will complain.
+ */
+ req.wValue = (256 * LIBUSB20_DT_STRING) | index;
+ req.wIndex = langid;
+ req.wLength = 4; /* bytes */
+
+ error = libusb20_dev_request_sync(pdev, &req,
+ ptr, NULL, 1000, LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK);
+ if (error) {
+ return (error);
+ }
+ req.wLength = *(uint8_t *)ptr; /* bytes */
+ if (req.wLength > len) {
+ /* partial string read */
+ req.wLength = len;
+ }
+ error = libusb20_dev_request_sync(pdev, &req,
+ ptr, NULL, 1000, LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK);
+
+ if (error) {
+ return (error);
+ }
+ if (((uint8_t *)ptr)[1] != LIBUSB20_DT_STRING) {
+ return (LIBUSB20_ERROR_OTHER);
+ }
+ return (0); /* success */
+}
+
+int
+libusb20_dev_req_string_simple_sync(struct libusb20_device *pdev,
+ uint8_t index, void *ptr, uint16_t len)
+{
+ char *buf;
+ int error;
+ uint16_t langid;
+ uint16_t n;
+ uint16_t i;
+ uint16_t c;
+ uint8_t temp[255];
+ uint8_t swap;
+
+ /* the following code derives from the FreeBSD USB kernel */
+
+ if (len < 1) {
+ /* too short buffer */
+ return (LIBUSB20_ERROR_INVALID_PARAM);
+ }
+ error = libusb20_dev_req_string_sync(pdev,
+ 0, 0, temp, sizeof(temp));
+ if (error < 0)
+ return (error);
+
+ langid = temp[2] | (temp[3] << 8);
+
+ error = libusb20_dev_req_string_sync(pdev, index,
+ langid, temp, sizeof(temp));
+ if (error < 0)
+ return (error);
+
+ if (temp[0] < 2) {
+ /* string length is too short */
+ return (LIBUSB20_ERROR_OTHER);
+ }
+ /* reserve one byte for terminating zero */
+ len--;
+
+ /* find maximum length */
+ n = (temp[0] / 2) - 1;
+ if (n > len) {
+ n = len;
+ }
+ /* reset swap state */
+ swap = 3;
+
+ /* setup output buffer pointer */
+ buf = ptr;
+
+ /* convert and filter */
+ for (i = 0; (i != n); i++) {
+ c = temp[(2 * i) + 2] | (temp[(2 * i) + 3] << 8);
+
+ /* convert from Unicode, handle buggy strings */
+ if (((c & 0xff00) == 0) && (swap & 1)) {
+ /* Little Endian, default */
+ *buf = c;
+ swap = 1;
+ } else if (((c & 0x00ff) == 0) && (swap & 2)) {
+ /* Big Endian */
+ *buf = c >> 8;
+ swap = 2;
+ } else {
+ *buf = '.';
+ }
+ /*
+ * Filter by default - we don't allow greater and less than
+ * signs because they might confuse the dmesg printouts!
+ */
+ if ((*buf == '<') || (*buf == '>') || (!isprint(*buf))) {
+ *buf = '.';
+ }
+ buf++;
+ }
+ *buf = 0; /* zero terminate string */
+
+ return (0);
+}
+
struct libusb20_config *
libusb20_dev_alloc_config(struct libusb20_device *pdev, uint8_t configIndex)
{
==== //depot/projects/usb/src/lib/libusb20/libusb20.h#4 (text+ko) ====
@@ -31,6 +31,7 @@
#include <stdint.h>
#include <time.h>
+#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -235,6 +236,8 @@
int libusb20_dev_process(struct libusb20_device *pdev);
int libusb20_dev_release_interface(struct libusb20_device *pdev, uint8_t iface_index);
int libusb20_dev_request_sync(struct libusb20_device *pdev, struct LIBUSB20_CONTROL_SETUP_DECODED *setup, void *data, uint16_t *pactlen, uint32_t timeout, uint8_t flags);
+int libusb20_dev_req_string_sync(struct libusb20_device *pdev, uint8_t index, uint16_t langid, void *ptr, uint16_t len);
+int libusb20_dev_req_string_simple_sync(struct libusb20_device *pdev, uint8_t index, void *ptr, uint16_t len);
int libusb20_dev_reset(struct libusb20_device *pdev);
int libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode);
uint8_t libusb20_dev_get_power_mode(struct libusb20_device *pdev);
==== //depot/projects/usb/src/lib/libusb20/libusb20_int.h#3 (text+ko) ====
@@ -210,6 +210,9 @@
/* private backend data */
void *privBeData;
+ /* libUSB v0.1 compat data */
+ void *priv01Data;
+
/* claimed interfaces */
uint32_t claimed_interfaces;
More information about the p4-projects
mailing list