PERFORCE change 172665 for review

Hans Petter Selasky hselasky at FreeBSD.org
Wed Jan 6 17:41:52 UTC 2010


http://p4web.freebsd.org/chv.cgi?CH=172665

Change 172665 by hselasky at hselasky_laptop001 on 2010/01/06 17:41:26

	usbconfig: 
		- Allow specifying unit and address like a 
		  coordinate, optionally prefixed by "ugen".
		- Refactor string dumping code.
		- Idea by "Warren Block".
		- Patch by HPS.

Affected files ...

.. //depot/projects/usb/src/usr.sbin/usbconfig/dump.c#17 edit
.. //depot/projects/usb/src/usr.sbin/usbconfig/dump.h#9 edit
.. //depot/projects/usb/src/usr.sbin/usbconfig/usbconfig.8#8 edit
.. //depot/projects/usb/src/usr.sbin/usbconfig/usbconfig.c#19 edit

Differences ...

==== //depot/projects/usb/src/usr.sbin/usbconfig/dump.c#17 (text+ko) ====

@@ -365,3 +365,40 @@
 	}
 	return;
 }
+
+void
+dump_string_by_index(struct libusb20_device *pdev, uint8_t str_index)
+{
+	char *pbuf;
+	uint8_t n;
+	uint8_t len;
+
+	pbuf = malloc(256);
+	if (pbuf == NULL)
+		err(1, "out of memory");
+
+	if (str_index == 0) {
+		/* language table */
+		if (libusb20_dev_req_string_sync(pdev,
+		    str_index, 0, pbuf, 256)) {
+			printf("STRING_0x%02x = <read error>\n", str_index);
+		} else {
+			printf("STRING_0x%02x = ", str_index);
+			len = (uint8_t)pbuf[0];
+			for (n = 0; n != len; n++) {
+				printf("0x%02x%s", (uint8_t)pbuf[n], 
+				    (n != (len-1)) ? ", " : "");
+			}
+			printf("\n");
+		}
+	} else {
+		/* ordinary string */
+		if (libusb20_dev_req_string_simple_sync(pdev,
+		    str_index, pbuf, 256)) {
+			printf("STRING_0x%02x = <read error>\n", str_index);
+		} else {
+			printf("STRING_0x%02x = <%s>\n", str_index, pbuf);
+		}
+	}
+	free(pbuf);
+}

==== //depot/projects/usb/src/usr.sbin/usbconfig/dump.h#9 (text+ko) ====

@@ -24,11 +24,17 @@
  * SUCH DAMAGE.
  */
 
+#ifndef _DUMP_H_
+#define	_DUMP_H_
+
 const char *dump_mode(uint8_t value);
 const char *dump_speed(uint8_t value);
 const char *dump_power_mode(uint8_t value);
+void	dump_string_by_index(struct libusb20_device *pdev, uint8_t index);
 void	dump_device_info(struct libusb20_device *pdev, uint8_t show_drv);
 void	dump_be_quirk_names(struct libusb20_backend *pbe);
 void	dump_be_dev_quirks(struct libusb20_backend *pbe);
 void	dump_device_desc(struct libusb20_device *pdev);
 void	dump_config(struct libusb20_device *pdev, uint8_t all_cfg);
+
+#endif	/* _DUMP_H_ */

==== //depot/projects/usb/src/usr.sbin/usbconfig/usbconfig.8#8 (text+ko) ====

@@ -1,6 +1,6 @@
 .\" $FreeBSD: src/usr.sbin/usbconfig/usbconfig.8,v 1.3 2009/11/01 11:39:07 brueffer Exp $
 .\"
-.\" Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
+.\" Copyright (c) 2008-2010 Hans Petter Selasky. All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
 .\" modification, are permitted provided that the following conditions
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd November 1, 2009
+.Dd January 6, 2010
 .Dt USBCONFIG 8
 .Os
 .Sh NAME
@@ -34,6 +34,9 @@
 .Op Fl u Ar unit
 .Op Fl a Ar addr
 .Op cmds...
+.Nm
+.Op Fl d Ar [ugen]<unit>.<addr>
+.Op cmds...
 .Sh DESCRIPTION
 The
 .Nm
@@ -46,6 +49,9 @@
 .It Fl a Ar addr
 Limit device range to the given USB device index.
 Should only be used in conjunction with the unit argument.
+.It Fl d Ar [ugen]<unit>.<addr>
+Limit device range to USB devices connected to the given unit and address.
+The unit and address coordinates may be prefixed by the lowercased word "ugen".
 .It Fl h
 Show help and available commands.
 .El
@@ -57,5 +63,34 @@
 Show information about the device on USB bus 1 at address 2:
 .Pp
 .Dl usbconfig -u 1 -a 2 dump_info
+.Pp
+Dump HID descriptor for device on USB bus 1 at address 2:
+.Pp
+.Dl usbconfig -u 1 -a 2 do_request 0x81 0x06 0x2200 0 0x100
+.Pp
+Dump string descriptor at index Z for device on USB bus 1 at address 2:
+.Pp
+.Dl usbconfig -u 1 -a 2 dump_string Z
+.Pp
+Dump current configuration descriptor for device on USB bus 1 at address 2:
+.Pp
+.Dl usbconfig -u 1 -a 2 dump_curr_config_desc
+.Pp
+Dump device descriptor for device on USB bus 1 at address 2:
+.Pp
+.Dl usbconfig -u 1 -a 2 dump_device_desc
+.Pp
+Program the device on USB bus 1 at address 2 to suspend, resume, power off, go into power save, or power on:
+.Pp
+.Dl usbconfig -u 1 -a 2 suspend
+.Dl usbconfig -u 1 -a 2 resume
+.Dl usbconfig -u 1 -a 2 power_off
+.Dl usbconfig -u 1 -a 2 power_save
+.Dl usbconfig -u 1 -a 2 power_on
+.Pp
+Display a list of available quirk names:
+.Pp
+.Dl usbconfig dump_quirk_names
+.Pp
 .Sh SEE ALSO
 .Xr usb 4

==== //depot/projects/usb/src/usr.sbin/usbconfig/usbconfig.c#19 (text+ko) ====

@@ -96,6 +96,7 @@
 enum {
 	T_UNIT,
 	T_ADDR,
+	T_UGEN,
 	T_IFACE,
 	T_SET_CONFIG,
 	T_SET_ALT,
@@ -128,6 +129,7 @@
 static const struct token token[] = {
 	{"-u", T_UNIT, 1},
 	{"-a", T_ADDR, 1},
+	{"-d", T_UGEN, 1},
 	{"-i", T_IFACE, 1},
 	{"set_config", T_SET_CONFIG, 1},
 	{"set_alt", T_SET_ALT, 1},
@@ -266,6 +268,7 @@
 	printf(""
 	    "usbconfig - configure the USB subsystem" "\n"
 	    "usage: usbconfig -u <busnum> -a <devaddr> -i <ifaceindex> [cmds...]" "\n"
+	    "usage: usbconfig -d [ugen]<busnum>.<devaddr> -i <ifaceindex> [cmds...]" "\n"
 	    "commands:" "\n"
 	    "  set_config <cfg_index>" "\n"
 	    "  set_alt <alt_index>" "\n"
@@ -402,21 +405,7 @@
 			err(1, "could not open device");
 		}
 		if (opt->got_dump_string) {
-			char *pbuf;
-
-			pbuf = malloc(256);
-			if (pbuf == NULL) {
-				err(1, "out of memory");
-			}
-			if (libusb20_dev_req_string_simple_sync(pdev,
-			    opt->string_index, pbuf, 256)) {
-				printf("STRING_0x%02x = <read error>\n",
-				    opt->string_index);
-			} else {
-				printf("STRING_0x%02x = <%s>\n",
-				    opt->string_index, pbuf);
-			}
-			free(pbuf);
+			dump_string_by_index(pdev, opt->string_index);
 		}
 		if (opt->got_do_request) {
 			uint16_t actlen;
@@ -539,6 +528,9 @@
 {
 	struct libusb20_backend *pbe;
 	struct options *opt = &options;
+	const char *ptr;
+	int unit;
+	int addr;
 	int n;
 	int t;
 
@@ -625,6 +617,33 @@
 			opt->got_show_iface_driver = 1;
 			break;
 
+		case T_UGEN:
+			if (opt->got_any) {
+				/* allow multiple commands on the same line */
+				flush_command(pbe, opt);
+			}
+			ptr = argv[n + 1];
+
+			if ((ptr[0] == 'u') &&
+			    (ptr[1] == 'g') &&
+			    (ptr[2] == 'e') &&
+			    (ptr[3] == 'n'))
+				ptr += 4;
+
+			if ((sscanf(ptr, "%d.%d",
+			    &unit, &addr) != 2) ||
+			    (unit < 0) || (unit > 65535) ||
+			    (addr < 0) || (addr > 65535)) {
+				errx(1, "cannot "
+				    "parse '%s'", argv[n + 1]);
+			}
+			opt->bus = unit;
+			opt->addr = addr;
+			opt->got_bus = 1;
+;			opt->got_addr = 1;
+			n++;
+			break;
+
 		case T_UNIT:
 			if (opt->got_any) {
 				/* allow multiple commands on the same line */
@@ -699,9 +718,8 @@
 			opt->got_any++;
 			break;
 		case T_DUMP_STRING:
-			if (opt->got_dump_string) {
-				flush_command(pbe, opt);
-			}
+			if (opt->got_dump_string)
+				duplicate_option(argv[n]);
 			opt->string_index = num_id(argv[n + 1], "str_index");
 			opt->got_dump_string = 1;
 			opt->got_any++;
@@ -750,9 +768,8 @@
 			opt->got_any++;
 			break;
 		case T_DO_REQUEST:
-			if (opt->got_do_request) {
-				flush_command(pbe, opt);
-			}
+			if (opt->got_do_request)
+				duplicate_option(argv[n]);
 			LIBUSB20_INIT(LIBUSB20_CONTROL_SETUP, &opt->setup);
 			opt->setup.bmRequestType = num_id(argv[n + 1], "bmReqTyp");
 			opt->setup.bRequest = num_id(argv[n + 2], "bReq");


More information about the p4-projects mailing list