From owner-p4-projects@FreeBSD.ORG Fri Feb 20 11:20:55 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4A63D10656D1; Fri, 20 Feb 2009 11:20:55 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F01BA10656CC for ; Fri, 20 Feb 2009 11:20:54 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id DC3298FC14 for ; Fri, 20 Feb 2009 11:20:54 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n1KBKsSQ042515 for ; Fri, 20 Feb 2009 11:20:54 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n1KBKsp3042513 for perforce@freebsd.org; Fri, 20 Feb 2009 11:20:54 GMT (envelope-from hselasky@FreeBSD.org) Date: Fri, 20 Feb 2009 11:20:54 GMT Message-Id: <200902201120.n1KBKsp3042513@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky To: Perforce Change Reviews Cc: Subject: PERFORCE change 157974 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Feb 2009 11:20:56 -0000 http://perforce.freebsd.org/chv.cgi?CH=157974 Change 157974 by hselasky@hselasky_laptop001 on 2009/02/20 11:20:39 USB TEMPLATE: Add support for setting and getting the USB template value through libusb20 and usbconfig. Affected files ... .. //depot/projects/usb/src/lib/libusb20/libusb20.3#7 edit .. //depot/projects/usb/src/lib/libusb20/libusb20.c#15 edit .. //depot/projects/usb/src/lib/libusb20/libusb20_int.h#8 edit .. //depot/projects/usb/src/lib/libusb20/libusb20_ugen20.c#14 edit .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#46 edit .. //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.h#14 edit .. //depot/projects/usb/src/sys/dev/usb2/include/usb2_ioctl.h#31 edit .. //depot/projects/usb/src/usr.sbin/usbconfig/usbconfig.c#13 edit Differences ... ==== //depot/projects/usb/src/lib/libusb20/libusb20.3#7 (text+ko) ==== @@ -698,6 +698,30 @@ . .Sh USB BACKEND OPERATIONS . +.Fn libusb20_be_get_template pbackend ptemp +This function will return the currently selected global USB device +side mode template into the integer pointer +.Fa ptemp . +This function returns zero on success else a LIBUSB20_ERROR value is +returned. +. +.Pp +. +.Fn libusb20_be_set_template pbackend temp +This function will set the global USB device side mode template to +.Fa temp . +The new template is not activated until after the next USB +enumeration. +The template number decides how the USB device will present itself to +the USB Host, like Mass Storage Device, USB Ethernet Device. Also see +the +.Xr usb2_template 4 +module. +This function returns zero on success else a LIBUSB20_ERROR value is +returned. +. +.Pp +. .Fn libusb20_be_get_dev_quirk pbackend index pquirk This function will return the device quirk according to .Fa index ==== //depot/projects/usb/src/lib/libusb20/libusb20.c#15 (text+ko) ==== @@ -1165,6 +1165,23 @@ return (pbe->methods->root_get_perm(pbe, mode)); } +int +libusb20_be_set_template(struct libusb20_backend *pbe, int temp) +{ + return (pbe->methods->root_set_template(pbe, temp)); +} + +int +libusb20_be_get_template(struct libusb20_backend *pbe, int *ptemp) +{ + int temp; + + if (ptemp == NULL) + ptemp = &temp; + + return (pbe->methods->root_get_template(pbe, ptemp)); +} + struct libusb20_device * libusb20_be_device_foreach(struct libusb20_backend *pbe, struct libusb20_device *pdev) { ==== //depot/projects/usb/src/lib/libusb20/libusb20_int.h#8 (text+ko) ==== @@ -70,6 +70,8 @@ typedef int (libusb20_root_set_owner_t)(struct libusb20_backend *pbe, uid_t user, gid_t group); typedef int (libusb20_root_set_perm_t)(struct libusb20_backend *pbe, mode_t mode); typedef void (libusb20_exit_backend_t)(struct libusb20_backend *pbe); +typedef int (libusb20_root_set_template_t)(struct libusb20_backend *pbe, int temp); +typedef int (libusb20_root_get_template_t)(struct libusb20_backend *pbe, int *ptemp); #define LIBUSB20_DEFINE(n,field) \ libusb20_##field##_t *field; @@ -105,6 +107,8 @@ m(n, root_get_owner) \ m(n, root_set_perm) \ m(n, root_get_perm) \ + m(n, root_set_template) \ + m(n, root_get_template) \ /* mandatory device methods */ \ m(n, open_device) \ m(n, close_device) \ ==== //depot/projects/usb/src/lib/libusb20/libusb20_ugen20.c#14 (text+ko) ==== @@ -72,6 +72,8 @@ static libusb20_root_get_owner_t ugen20_root_get_owner; static libusb20_root_set_perm_t ugen20_root_set_perm; static libusb20_root_get_perm_t ugen20_root_get_perm; +static libusb20_root_set_template_t ugen20_root_set_template; +static libusb20_root_get_template_t ugen20_root_get_template; const struct libusb20_backend_methods libusb20_ugen20_backend = { LIBUSB20_BACKEND(LIBUSB20_DECLARE, ugen20) @@ -1179,3 +1181,15 @@ return (ugen20_be_do_perm(USB_GET_ROOT_PERM, 0, 0, 0, 0, NULL, NULL, mode)); } + +static int +ugen20_root_set_template(struct libusb20_backend *pbe, int temp) +{ + return (ugen20_be_ioctl(USB_SET_TEMPLATE, &temp)); +} + +static int +ugen20_root_get_template(struct libusb20_backend *pbe, int *ptemp) +{ + return (ugen20_be_ioctl(USB_GET_TEMPLATE, ptemp)); +} ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#46 (text+ko) ==== @@ -1377,6 +1377,15 @@ case USB_DEV_QUIRK_REMOVE: err = usb2_quirk_ioctl_p(cmd, data, fflag, td); break; + case USB_GET_TEMPLATE: + *(int *)data = usb2_template; + break; + case USB_SET_TEMPLATE: + err = priv_check(curthread, PRIV_ROOT); + if (err) + break; + usb2_template = *(int *)data; + break; default: err = ENOTTY; break; ==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.h#14 (text+ko) ==== @@ -155,6 +155,10 @@ char product[64]; /* product string */ }; +/* globals */ + +extern int usb2_template; + /* function prototypes */ struct usb2_device *usb2_alloc_device(device_t parent_dev, struct usb2_bus *bus, ==== //depot/projects/usb/src/sys/dev/usb2/include/usb2_ioctl.h#31 (text+ko) ==== @@ -267,6 +267,8 @@ #define USB_SET_PORT_DISABLE _IOW ('U', 144, int) #define USB_SET_POWER_MODE _IOW ('U', 145, int) #define USB_GET_POWER_MODE _IOR ('U', 146, int) +#define USB_SET_TEMPLATE _IOW ('U', 147, int) +#define USB_GET_TEMPLATE _IOR ('U', 148, int) /* Modem device */ #define USB_GET_CM_OVER_DATA _IOR ('U', 180, int) ==== //depot/projects/usb/src/usr.sbin/usbconfig/usbconfig.c#13 (text+ko) ==== @@ -42,6 +42,7 @@ struct options { const char *quirkname; void *buffer; + int template; gid_t gid; uid_t uid; mode_t mode; @@ -65,6 +66,8 @@ uint8_t got_set_alt:1; uint8_t got_set_owner:1; uint8_t got_set_perm:1; + uint8_t got_set_template:1; + uint8_t got_get_template:1; uint8_t got_suspend:1; uint8_t got_resume:1; uint8_t got_reset:1; @@ -99,6 +102,8 @@ T_SET_ALT, T_SET_OWNER, T_SET_PERM, + T_SET_TEMPLATE, + T_GET_TEMPLATE, T_ADD_DEVICE_QUIRK, T_REMOVE_DEVICE_QUIRK, T_SHOW_IFACE_DRIVER, @@ -130,6 +135,8 @@ {"set_alt", T_SET_ALT, 1}, {"set_owner", T_SET_OWNER, 1}, {"set_perm", T_SET_PERM, 1}, + {"set_template", T_SET_TEMPLATE, 1}, + {"get_template", T_GET_TEMPLATE, 0}, {"add_dev_quirk_vplh", T_ADD_DEVICE_QUIRK, 5}, {"remove_dev_quirk_vplh", T_REMOVE_DEVICE_QUIRK, 5}, {"dump_quirk_names", T_DUMP_QUIRK_NAMES, 0}, @@ -283,6 +290,8 @@ " set_alt " "\n" " set_owner " "\n" " set_perm " "\n" + " set_template