Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Move three functions into usbdi_util.c, where th...
details: https://anonhg.NetBSD.org/src/rev/9d9edce37166
branches: trunk
changeset: 969118:9d9edce37166
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Feb 08 08:47:27 2020 +0000
description:
Move three functions into usbdi_util.c, where they belong. No functional
change.
diffstat:
sys/dev/usb/usb_subr.c | 97 +-----------------------------------------------
sys/dev/usb/usbdi_util.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++-
sys/dev/usb/usbdi_util.h | 5 +-
sys/dev/usb/usbdivar.h | 4 +-
4 files changed, 100 insertions(+), 101 deletions(-)
diffs (truncated from 306 to 300 lines):
diff -r c30639b5a097 -r 9d9edce37166 sys/dev/usb/usb_subr.c
--- a/sys/dev/usb/usb_subr.c Sat Feb 08 08:23:01 2020 +0000
+++ b/sys/dev/usb/usb_subr.c Sat Feb 08 08:47:27 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usb_subr.c,v 1.241 2019/10/03 05:20:31 maxv Exp $ */
+/* $NetBSD: usb_subr.c,v 1.242 2020/02/08 08:47:27 maxv Exp $ */
/* $FreeBSD: src/sys/dev/usb/usb_subr.c,v 1.18 1999/11/17 22:33:47 n_hibma Exp $ */
/*
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.241 2019/10/03 05:20:31 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_subr.c,v 1.242 2020/02/08 08:47:27 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -66,7 +66,6 @@
#define DPRINTF(FMT,A,B,C,D) USBHIST_LOG(usbdebug,FMT,A,B,C,D)
#define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(usbdebug,N,FMT,A,B,C,D)
-Static usbd_status usbd_set_config(struct usbd_device *, int);
Static void usbd_devinfo(struct usbd_device *, int, char *, size_t);
Static int usbd_getnewaddr(struct usbd_bus *);
Static int usbd_print(void *, const char *);
@@ -113,51 +112,6 @@
}
}
-usbd_status
-usbd_get_string_desc(struct usbd_device *dev, int sindex, int langid,
- usb_string_descriptor_t *sdesc, int *sizep)
-{
- USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
- usb_device_request_t req;
- usbd_status err;
- int actlen;
-
- /*
- * Pass a full-sized buffer to usbd_do_request_len(). At least
- * one device has been seen returning additional data beyond the
- * provided buffers (2-bytes written shortly after the request
- * claims to have completed and returned the 2 byte header,
- * corrupting other memory.)
- */
- req.bmRequestType = UT_READ_DEVICE;
- req.bRequest = UR_GET_DESCRIPTOR;
- USETW2(req.wValue, UDESC_STRING, sindex);
- USETW(req.wIndex, langid);
- USETW(req.wLength, 2); /* only size byte first */
- err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
- USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
- if (err)
- return err;
-
- if (actlen < 2)
- return USBD_SHORT_XFER;
-
- if (sdesc->bLength > sizeof(*sdesc))
- return USBD_INVAL;
- USETW(req.wLength, sdesc->bLength); /* the whole string */
- err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
- USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
- if (err)
- return err;
-
- if (actlen != sdesc->bLength) {
- DPRINTF("expected %jd, got %jd", sdesc->bLength, actlen, 0, 0);
- }
-
- *sizep = actlen;
- return USBD_NORMAL_COMPLETION;
-}
-
static void
usbd_trim_spaces(char *p)
{
@@ -549,23 +503,6 @@
}
}
-Static usbd_status
-usbd_set_config(struct usbd_device *dev, int conf)
-{
- usb_device_request_t req;
-
- USBHIST_FUNC();
- USBHIST_CALLARGS(usbdebug, "dev %#jx conf %jd",
- (uintptr_t)dev, conf, 0, 0);
-
- req.bmRequestType = UT_WRITE_DEVICE;
- req.bRequest = UR_SET_CONFIG;
- USETW(req.wValue, conf);
- USETW(req.wIndex, 0);
- USETW(req.wLength, 0);
- return usbd_do_request(dev, &req, 0);
-}
-
usbd_status
usbd_set_config_no(struct usbd_device *dev, int no, int msg)
{
@@ -1164,36 +1101,6 @@
}
/*
- * Get the first 8 bytes of the device descriptor.
- * Do as Windows does: try to read 64 bytes -- there are devices which
- * recognize the initial descriptor fetch (before the control endpoint's
- * MaxPacketSize is known by the host) by exactly this length.
- */
-usbd_status
-usbd_get_initial_ddesc(struct usbd_device *dev, usb_device_descriptor_t *desc)
-{
- USBHIST_FUNC();
- USBHIST_CALLARGS(usbdebug, "dev %#jx", (uintptr_t)dev, 0, 0, 0);
- usb_device_request_t req;
- char buf[64];
- int res, actlen;
-
- req.bmRequestType = UT_READ_DEVICE;
- req.bRequest = UR_GET_DESCRIPTOR;
- USETW2(req.wValue, UDESC_DEVICE, 0);
- USETW(req.wIndex, 0);
- USETW(req.wLength, 8);
- res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
- &actlen, USBD_DEFAULT_TIMEOUT);
- if (res)
- return res;
- if (actlen < 8)
- return USBD_SHORT_XFER;
- memcpy(desc, buf, 8);
- return USBD_NORMAL_COMPLETION;
-}
-
-/*
* Called when a new device has been put in the powered state,
* but not yet in the addressed state.
* Get initial descriptor, set the address, get full descriptor,
diff -r c30639b5a097 -r 9d9edce37166 sys/dev/usb/usbdi_util.c
--- a/sys/dev/usb/usbdi_util.c Sat Feb 08 08:23:01 2020 +0000
+++ b/sys/dev/usb/usbdi_util.c Sat Feb 08 08:47:27 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdi_util.c,v 1.77 2020/02/08 08:18:06 maxv Exp $ */
+/* $NetBSD: usbdi_util.c,v 1.78 2020/02/08 08:47:27 maxv Exp $ */
/*
* Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.77 2020/02/08 08:18:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usbdi_util.c,v 1.78 2020/02/08 08:47:27 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -154,6 +154,81 @@
0, USB_DEVICE_DESCRIPTOR_SIZE, d);
}
+/*
+ * Get the first 8 bytes of the device descriptor.
+ * Do as Windows does: try to read 64 bytes -- there are devices which
+ * recognize the initial descriptor fetch (before the control endpoint's
+ * MaxPacketSize is known by the host) by exactly this length.
+ */
+usbd_status
+usbd_get_initial_ddesc(struct usbd_device *dev, usb_device_descriptor_t *desc)
+{
+ USBHIST_FUNC();
+ USBHIST_CALLARGS(usbdebug, "dev %#jx", (uintptr_t)dev, 0, 0, 0);
+ usb_device_request_t req;
+ char buf[64];
+ int res, actlen;
+
+ req.bmRequestType = UT_READ_DEVICE;
+ req.bRequest = UR_GET_DESCRIPTOR;
+ USETW2(req.wValue, UDESC_DEVICE, 0);
+ USETW(req.wIndex, 0);
+ USETW(req.wLength, 8);
+ res = usbd_do_request_flags(dev, &req, buf, USBD_SHORT_XFER_OK,
+ &actlen, USBD_DEFAULT_TIMEOUT);
+ if (res)
+ return res;
+ if (actlen < 8)
+ return USBD_SHORT_XFER;
+ memcpy(desc, buf, 8);
+ return USBD_NORMAL_COMPLETION;
+}
+
+usbd_status
+usbd_get_string_desc(struct usbd_device *dev, int sindex, int langid,
+ usb_string_descriptor_t *sdesc, int *sizep)
+{
+ USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
+ usb_device_request_t req;
+ usbd_status err;
+ int actlen;
+
+ /*
+ * Pass a full-sized buffer to usbd_do_request_len(). At least
+ * one device has been seen returning additional data beyond the
+ * provided buffers (2-bytes written shortly after the request
+ * claims to have completed and returned the 2 byte header,
+ * corrupting other memory.)
+ */
+ req.bmRequestType = UT_READ_DEVICE;
+ req.bRequest = UR_GET_DESCRIPTOR;
+ USETW2(req.wValue, UDESC_STRING, sindex);
+ USETW(req.wIndex, langid);
+ USETW(req.wLength, 2); /* only size byte first */
+ err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
+ USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
+ if (err)
+ return err;
+
+ if (actlen < 2)
+ return USBD_SHORT_XFER;
+
+ if (sdesc->bLength > sizeof(*sdesc))
+ return USBD_INVAL;
+ USETW(req.wLength, sdesc->bLength); /* the whole string */
+ err = usbd_do_request_len(dev, &req, sizeof(*sdesc), sdesc,
+ USBD_SHORT_XFER_OK, &actlen, USBD_DEFAULT_TIMEOUT);
+ if (err)
+ return err;
+
+ if (actlen != sdesc->bLength) {
+ DPRINTF("expected %jd, got %jd", sdesc->bLength, actlen, 0, 0);
+ }
+
+ *sizep = actlen;
+ return USBD_NORMAL_COMPLETION;
+}
+
/* -------------------------------------------------------------------------- */
usbd_status
@@ -349,6 +424,22 @@
}
usbd_status
+usbd_set_config(struct usbd_device *dev, int conf)
+{
+ USBHIST_FUNC();
+ USBHIST_CALLARGS(usbdebug, "dev %#jx conf %jd",
+ (uintptr_t)dev, conf, 0, 0);
+ usb_device_request_t req;
+
+ req.bmRequestType = UT_WRITE_DEVICE;
+ req.bRequest = UR_SET_CONFIG;
+ USETW(req.wValue, conf);
+ USETW(req.wIndex, 0);
+ USETW(req.wLength, 0);
+ return usbd_do_request(dev, &req, 0);
+}
+
+usbd_status
usbd_set_address(struct usbd_device *dev, int addr)
{
USBHIST_FUNC();
diff -r c30639b5a097 -r 9d9edce37166 sys/dev/usb/usbdi_util.h
--- a/sys/dev/usb/usbdi_util.h Sat Feb 08 08:23:01 2020 +0000
+++ b/sys/dev/usb/usbdi_util.h Sat Feb 08 08:47:27 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdi_util.h,v 1.51 2020/02/08 08:18:06 maxv Exp $ */
+/* $NetBSD: usbdi_util.h,v 1.52 2020/02/08 08:47:27 maxv Exp $ */
/*
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -45,6 +45,8 @@
usbd_status usbd_get_bos_desc_full(struct usbd_device *, int, void *, int);
usbd_status usbd_get_device_desc(struct usbd_device *,
usb_device_descriptor_t *);
+usbd_status usbd_get_initial_ddesc(struct usbd_device *,
+ usb_device_descriptor_t *);
usbd_status usbd_get_string_desc(struct usbd_device *, int, int,
usb_string_descriptor_t *, int *);
@@ -66,6 +68,7 @@
usbd_status usbd_clear_endpoint_feature(struct usbd_device *, int, int);
usbd_status usbd_get_config(struct usbd_device *, uint8_t *);
+usbd_status usbd_set_config(struct usbd_device *, int);
usbd_status usbd_set_address(struct usbd_device *, int);
usbd_status usbd_set_idle(struct usbd_interface *, int, int);
diff -r c30639b5a097 -r 9d9edce37166 sys/dev/usb/usbdivar.h
--- a/sys/dev/usb/usbdivar.h Sat Feb 08 08:23:01 2020 +0000
+++ b/sys/dev/usb/usbdivar.h Sat Feb 08 08:47:27 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usbdivar.h,v 1.119 2019/09/26 01:35:08 christos Exp $ */
+/* $NetBSD: usbdivar.h,v 1.120 2020/02/08 08:47:27 maxv Exp $ */
/*
* Copyright (c) 1998, 2012 The NetBSD Foundation, Inc.
@@ -334,8 +334,6 @@
void usbd_kill_pipe(struct usbd_pipe *);
usbd_status usbd_attach_roothub(device_t, struct usbd_device *);
Home |
Main Index |
Thread Index |
Old Index