From a7ceaa31f2d0d6a37c1b8894fecd8d37c5356d19 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Tue, 18 Mar 2014 09:37:31 +0100 Subject: [PATCH] usb4bsd: FWIW, port usb_template and hook it into the build. --- Makefile_upgrade.inc | 7 +- share/man/man4/Makefile | 1 + share/man/man4/usb_template.4 | 83 +++++++++++++++ sys/bus/u4b/Makefile | 4 +- sys/bus/u4b/template/Makefile | 39 +++++++ sys/bus/u4b/template/usb_template.c | 121 ++++++++++++---------- sys/bus/u4b/template/usb_template.h | 2 +- sys/bus/u4b/template/usb_template_audio.c | 41 +++----- sys/bus/u4b/template/usb_template_cdce.c | 72 ++++--------- sys/bus/u4b/template/usb_template_kbd.c | 35 +++---- sys/bus/u4b/template/usb_template_modem.c | 35 +++---- sys/bus/u4b/template/usb_template_mouse.c | 35 +++---- sys/bus/u4b/template/usb_template_msc.c | 55 +++------- sys/bus/u4b/template/usb_template_mtp.c | 51 +++------ sys/conf/files | 11 ++ sys/config/LINT | 4 + sys/config/LINT64 | 4 + 17 files changed, 328 insertions(+), 272 deletions(-) create mode 100644 share/man/man4/usb_template.4 create mode 100644 sys/bus/u4b/template/Makefile diff --git a/Makefile_upgrade.inc b/Makefile_upgrade.inc index c2b68d72f0..03170ff6d5 100644 --- a/Makefile_upgrade.inc +++ b/Makefile_upgrade.inc @@ -2629,6 +2629,11 @@ TO_REMOVE+=/boot/kernel/umoscom.ko TO_REMOVE+=/usr/share/man/cat4/umoscom.4.gz TO_REMOVE+=/usr/share/man/man4/umoscom.4.gz TO_REMOVE+=/boot/kernel/usb_quirk.ko +TO_REMOVE+=/usr/share/man/cat4/usb_quirk.4.gz +TO_REMOVE+=/usr/share/man/man4/usb_quirk.4.gz +TO_REMOVE+=/boot/kernel/usb_template.ko +TO_REMOVE+=/usr/share/man/cat4/usb_template.4.gz +TO_REMOVE+=/usr/share/man/man4/usb_template.4.gz TO_REMOVE+=/boot/kernel/usfs.ko TO_REMOVE+=/usr/share/man/cat4/usfs.4.gz TO_REMOVE+=/usr/share/man/man4/usfs.4.gz @@ -2664,8 +2669,6 @@ TO_REMOVE+=/usr/share/man/cat4/urtwn.4.gz TO_REMOVE+=/usr/share/man/man4/urtwn.4.gz TO_REMOVE+=/usr/share/man/cat4/urtwnfw.4.gz TO_REMOVE+=/usr/share/man/man4/urtwnfw.4.gz -TO_REMOVE+=/usr/share/man/cat4/usb_quirk.4.gz -TO_REMOVE+=/usr/share/man/man4/usb_quirk.4.gz TO_REMOVE+=/usr/bin/usbhidaction TO_REMOVE+=/usr/share/man/cat1/usbhidaction.1.gz TO_REMOVE+=/usr/share/man/man1/usbhidaction.1.gz diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile index 096d18af7f..4eda2cb13e 100644 --- a/share/man/man4/Makefile +++ b/share/man/man4/Makefile @@ -531,6 +531,7 @@ MAN+= rum.4 \ urtwn.4 \ urtwnfw.4 \ usb_quirk.4 \ + usb_template.4 \ usfs.4 \ u3g.4 \ xhci.4 diff --git a/share/man/man4/usb_template.4 b/share/man/man4/usb_template.4 new file mode 100644 index 0000000000..7c614080fa --- /dev/null +++ b/share/man/man4/usb_template.4 @@ -0,0 +1,83 @@ +.\" $FreeBSD: head/share/man/man4/usb_template.4 263292 2014-03-18 06:43:21Z hselasky $ +.\" +.\" Copyright (c) 2008 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 +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd March 18, 2014 +.Dt USB_TEMPLATE 4 +.Os +. +.Sh NAME +. +. +.Nm usb_template +. +.Nd "USB templates" +. +. +.Sh SYNOPSIS +To compile this module into the kernel, place the following line in +your kernel configuration file: +.Bd -ragged -offset indent +.Cd "device usb_template" +.Ed +.Pp +To load the module at boot time, place the following line in +.Xr loader.conf 5 : +.Bd -literal -offset indent +usb_template_load="YES" +.Ed +. +.Sh DESCRIPTION +The +.Nm +module implements various USB templates that are needed when +programming an USB device side driver. +. +A USB template consists of an USB device descriptor, one or more USB +configuration descriptors, one or more USB interface descriptors, one +or more USB endpoint descriptors, USB strings and additional USB +descriptors. +. +The USB template module currently has templates for USB Mass Storage, +USB CDC Ethernet and Message Transfer Protocol. +. +USB templates are currently selected using the "hw.usb.template" +sysctl. +. +The "hw.usb.template" value can be changed at any time, but will not +have any effect until the USB device has been re-enumerated. +. +. +. +.Sh SEE ALSO +.Xr usb 4 +.Sh STANDARDS +The +.Nm +module complies to the USB 1.0, 2.0 and 3.0 standard. +.Sh HISTORY +The +.Nm +module was written by +.An Hans Petter Selasky Aq Mt hselasky@FreeBSD.org . diff --git a/sys/bus/u4b/Makefile b/sys/bus/u4b/Makefile index 6980e7db2d..0629967b62 100644 --- a/sys/bus/u4b/Makefile +++ b/sys/bus/u4b/Makefile @@ -1,5 +1,3 @@ -#SUBDIR= template - -SUBDIR= usb audio controller input misc net quirk serial storage wlan +SUBDIR= usb audio controller input misc net quirk serial storage template wlan .include diff --git a/sys/bus/u4b/template/Makefile b/sys/bus/u4b/template/Makefile new file mode 100644 index 0000000000..acdcd12792 --- /dev/null +++ b/sys/bus/u4b/template/Makefile @@ -0,0 +1,39 @@ +# +# $FreeBSD: head/sys/modules/usb/template/Makefile 223467 2011-06-23 07:54:03Z hselasky $ +# +# Copyright (c) 2008 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 +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +KMOD= usb_template +SRCS= opt_bus.h opt_usb.h device_if.h bus_if.h usb_if.h usbdevs.h \ + usb_template.c \ + usb_template_audio.c \ + usb_template_cdce.c \ + usb_template_kbd.c \ + usb_template_modem.c \ + usb_template_mouse.c \ + usb_template_msc.c \ + usb_template_mtp.c + +.include diff --git a/sys/bus/u4b/template/usb_template.c b/sys/bus/u4b/template/usb_template.c index b929665ead..50db65afa9 100644 --- a/sys/bus/u4b/template/usb_template.c +++ b/sys/bus/u4b/template/usb_template.c @@ -1,4 +1,4 @@ -/* $FreeBSD$ */ +/* $FreeBSD: head/sys/dev/usb/template/usb_template.c 259218 2013-12-11 13:20:32Z hselasky $ */ /*- * Copyright (c) 2007 Hans Petter Selasky. All rights reserved. * @@ -29,8 +29,10 @@ * USB templates. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -39,34 +41,34 @@ #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "usbdevs.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define USB_DEBUG_VAR usb_debug -#include +#include -#include -#include -#include +#include +#include +#include +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ MODULE_DEPEND(usb_template, usb, 1, 1, 1); MODULE_VERSION(usb_template, 1); @@ -374,7 +376,7 @@ usb_make_config_desc(struct usb_temp_setup *temp, /* Reset some counters */ - temp->bInterfaceNumber = 0 - 1; + temp->bInterfaceNumber = 0xFF; temp->bAlternateSetting = 0; /* Scan all the USB interfaces */ @@ -841,24 +843,24 @@ usb_hw_ep_resolve(struct usb_device *udev, struct usb_hw_ep_scratch *ues; struct usb_hw_ep_scratch_sub *ep; const struct usb_hw_ep_profile *pf; - struct usb_bus_methods *methods; + const struct usb_bus_methods *methods; struct usb_device_descriptor *dd; uint16_t mps; - if (desc == NULL) { + if (desc == NULL) return (USB_ERR_INVAL); - } + /* get bus methods */ methods = udev->bus->methods; - if (methods->get_hw_ep_profile == NULL) { + if (methods->get_hw_ep_profile == NULL) return (USB_ERR_INVAL); - } + if (desc->bDescriptorType == UDESC_DEVICE) { - if (desc->bLength < sizeof(*dd)) { + if (desc->bLength < sizeof(*dd)) return (USB_ERR_INVAL); - } + dd = (void *)desc; /* get HW control endpoint 0 profile */ @@ -905,13 +907,12 @@ usb_hw_ep_resolve(struct usb_device *udev, } return (0); /* success */ } - if (desc->bDescriptorType != UDESC_CONFIG) { + if (desc->bDescriptorType != UDESC_CONFIG) return (USB_ERR_INVAL); - } - if (desc->bLength < sizeof(*(ues->cd))) { + if (desc->bLength < sizeof(*(ues->cd))) return (USB_ERR_INVAL); - } - ues = udev->bus->scratch[0].hw_ep_scratch; + + ues = udev->scratch.hw_ep_scratch; memset(ues, 0, sizeof(*ues)); @@ -1232,13 +1233,18 @@ usb_temp_setup(struct usb_device *udev, { struct usb_temp_setup *uts; void *buf; + usb_error_t error; uint8_t n; + uint8_t do_unlock; - if (tdd == NULL) { - /* be NULL safe */ + /* be NULL safe */ + if (tdd == NULL) return (0); - } - uts = udev->bus->scratch[0].temp_setup; + + /* Protect scratch area */ + do_unlock = usbd_enum_lock(udev); + + uts = udev->scratch.temp_setup; memset(uts, 0, sizeof(*uts)); @@ -1251,17 +1257,24 @@ usb_temp_setup(struct usb_device *udev, if (uts->err) { /* some error happened */ - return (uts->err); + goto done; } /* sanity check */ if (uts->size == 0) { - return (USB_ERR_INVAL); + uts->err = USB_ERR_INVAL; + goto done; } /* allocate zeroed memory */ - uts->buf = malloc(uts->size, M_USB, M_WAITOK | M_ZERO); + uts->buf = usbd_alloc_config_desc(udev, uts->size); + /* + * Allow malloc() to return NULL regardless of M_WAITOK flag. + * This helps when porting the software to non-FreeBSD + * systems. + */ if (uts->buf == NULL) { /* could not allocate memory */ - return (USB_ERR_NOMEM); + uts->err = USB_ERR_NOMEM; + goto done; } /* second pass */ @@ -1276,7 +1289,7 @@ usb_temp_setup(struct usb_device *udev, if (uts->err) { /* some error happened during second pass */ - goto error; + goto done; } /* * Resolve all endpoint addresses ! @@ -1287,7 +1300,7 @@ usb_temp_setup(struct usb_device *udev, DPRINTFN(0, "Could not resolve endpoints for " "Device Descriptor, error = %s\n", usbd_errstr(uts->err)); - goto error; + goto done; } for (n = 0;; n++) { @@ -1300,14 +1313,16 @@ usb_temp_setup(struct usb_device *udev, DPRINTFN(0, "Could not resolve endpoints for " "Config Descriptor %u, error = %s\n", n, usbd_errstr(uts->err)); - goto error; + goto done; } } - return (uts->err); - -error: - usb_temp_unsetup(udev); - return (uts->err); +done: + error = uts->err; + if (error) + usb_temp_unsetup(udev); + if (do_unlock) + usbd_enum_unlock(udev); + return (error); } /*------------------------------------------------------------------------* @@ -1319,12 +1334,8 @@ error: void usb_temp_unsetup(struct usb_device *udev) { - if (udev->usb_template_ptr) { - - free(udev->usb_template_ptr, M_USB); - - udev->usb_template_ptr = NULL; - } + usbd_free_config_desc(udev, udev->usb_template_ptr); + udev->usb_template_ptr = NULL; } static usb_error_t @@ -1370,5 +1381,5 @@ usb_temp_init(void *arg) usb_temp_unsetup_p = &usb_temp_unsetup; } -SYSINIT(usb_temp_init, SI_SUB_LOCK, SI_ORDER_FIRST, usb_temp_init, NULL); -SYSUNINIT(usb_temp_unload, SI_SUB_LOCK, SI_ORDER_ANY, usb_temp_unload, NULL); +SYSINIT(usb_temp_init, SI_SUB_DRIVERS, SI_ORDER_FIRST, usb_temp_init, NULL); +SYSUNINIT(usb_temp_unload, SI_SUB_DRIVERS, SI_ORDER_ANY, usb_temp_unload, NULL); diff --git a/sys/bus/u4b/template/usb_template.h b/sys/bus/u4b/template/usb_template.h index b05272fb2a..6c94e6650e 100644 --- a/sys/bus/u4b/template/usb_template.h +++ b/sys/bus/u4b/template/usb_template.h @@ -1,4 +1,4 @@ -/* $FreeBSD$ */ +/* $FreeBSD: head/sys/dev/usb/template/usb_template.h 223467 2011-06-23 07:54:03Z hselasky $ */ /*- * Copyright (c) 2007 Hans Petter Selasky * All rights reserved. diff --git a/sys/bus/u4b/template/usb_template_audio.c b/sys/bus/u4b/template/usb_template_audio.c index 8e9e7f0664..9fd50f8319 100644 --- a/sys/bus/u4b/template/usb_template_audio.c +++ b/sys/bus/u4b/template/usb_template_audio.c @@ -1,6 +1,4 @@ -#include -__FBSDID("$FreeBSD$"); - +/* $FreeBSD: head/sys/dev/usb/template/usb_template_audio.c 246125 2013-01-30 16:05:54Z hselasky $ */ /*- * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * @@ -30,8 +28,10 @@ __FBSDID("$FreeBSD$"); * This file contains the USB template for an USB Audio Device. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -40,20 +40,20 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include +#include +#include +#include +#include -#include +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ enum { INDEX_AUDIO_LANG, @@ -64,30 +64,21 @@ enum { INDEX_AUDIO_MAX, }; -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - #define STRING_AUDIO_PRODUCT \ - 'A', 0, 'u', 0, 'd', 0, 'i', 0, 'o', 0, ' ', 0, \ - 'T', 0, 'e', 0, 's', 0, 't', 0, ' ', 0, \ - 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, ' ', 0, + "A\0u\0d\0i\0o\0 \0T\0e\0s\0t\0 \0D\0e\0v\0i\0c\0e" #define STRING_AUDIO_MIXER \ - 'M', 0, 'i', 0, 'x', 0, 'e', 0, 'r', 0, ' ', 0, \ - 'i', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, + "M\0i\0x\0e\0r\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e" #define STRING_AUDIO_RECORD \ - 'R', 0, 'e', 0, 'c', 0, 'o', 0, 'r', 0, 'd', 0, ' ', 0, \ - 'i', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, + "R\0e\0c\0o\0r\0d\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e" #define STRING_AUDIO_PLAYBACK \ - 'P', 0, 'l', 0, 'a', 0, 'y', 0, 'b', 0, 'a', 0, 'c', 0, 'k', 0, ' ', 0, \ - 'i', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, + "P\0l\0a\0y\0b\0a\0c\0k\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e" /* make the real string descriptors */ -USB_MAKE_STRING_DESC(STRING_LANG, string_lang); USB_MAKE_STRING_DESC(STRING_AUDIO_MIXER, string_audio_mixer); USB_MAKE_STRING_DESC(STRING_AUDIO_RECORD, string_audio_record); USB_MAKE_STRING_DESC(STRING_AUDIO_PLAYBACK, string_audio_playback); @@ -385,7 +376,7 @@ static const void * audio_get_string_desc(uint16_t lang_id, uint8_t string_index) { static const void *ptr[INDEX_AUDIO_MAX] = { - [INDEX_AUDIO_LANG] = &string_lang, + [INDEX_AUDIO_LANG] = &usb_string_lang_en, [INDEX_AUDIO_MIXER] = &string_audio_mixer, [INDEX_AUDIO_RECORD] = &string_audio_record, [INDEX_AUDIO_PLAYBACK] = &string_audio_playback, @@ -393,7 +384,7 @@ audio_get_string_desc(uint16_t lang_id, uint8_t string_index) }; if (string_index == 0) { - return (&string_lang); + return (&usb_string_lang_en); } if (lang_id != 0x0409) { return (NULL); diff --git a/sys/bus/u4b/template/usb_template_cdce.c b/sys/bus/u4b/template/usb_template_cdce.c index 481a69cb95..dd7de073c7 100644 --- a/sys/bus/u4b/template/usb_template_cdce.c +++ b/sys/bus/u4b/template/usb_template_cdce.c @@ -1,6 +1,4 @@ -#include -__FBSDID("$FreeBSD$"); - +/* $FreeBSD: head/sys/dev/usb/template/usb_template_cdce.c 246125 2013-01-30 16:05:54Z hselasky $ */ /*- * Copyright (c) 2007 Hans Petter Selasky * All rights reserved. @@ -31,8 +29,10 @@ __FBSDID("$FreeBSD$"); * This file contains the USB templates for a CDC USB ethernet device. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -41,20 +41,20 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include +#include +#include +#include +#include -#include +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ enum { STRING_LANG_INDEX, @@ -68,61 +68,31 @@ enum { STRING_ETH_MAX, }; -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - #define STRING_MAC \ - '2', 0, 'A', 0, '2', 0, '3', 0, \ - '4', 0, '5', 0, '6', 0, '7', 0, \ - '8', 0, '9', 0, 'A', 0, 'B', 0, + "2\0A\0002\0003\0004\0005\0006\0007\08\09\0A\0B" #define STRING_ETH_CONTROL \ - 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ - 'E', 0, 't', 0, 'h', 0, 'e', 0, \ - 'r', 0, 'n', 0, 'e', 0, 't', 0, \ - ' ', 0, 'C', 0, 'o', 0, 'm', 0, \ - 'm', 0, ' ', 0, 'i', 0, 'n', 0, \ - 't', 0, 'e', 0, 'r', 0, 'f', 0, \ - 'a', 0, 'c', 0, 'e', 0, + "U\0S\0B\0 \0E\0t\0h\0e\0r\0n\0e\0t\0 " \ + "\0C\0o\0m\0m\0 \0I\0n\0t\0e\0r\0f\0a\0c\0e" #define STRING_ETH_DATA \ - 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ - 'E', 0, 't', 0, 'h', 0, 'e', 0, \ - 'r', 0, 'n', 0, 'e', 0, 't', 0, \ - ' ', 0, 'D', 0, 'a', 0, 't', 0, \ - 'a', 0, ' ', 0, 'i', 0, 'n', 0, \ - 't', 0, 'e', 0, 'r', 0, 'f', 0, \ - 'a', 0, 'c', 0, 'e', 0, + "U\0S\0B\0 \0E\0t\0h\0e\0r\0n\0e\0t\0 \0D\0a\0t\0a\0 " \ + "\0I\0n\0t\0e\0r\0f\0a\0c\0e" #define STRING_ETH_CONFIG \ - 'D', 0, 'e', 0, 'f', 0, 'a', 0, \ - 'u', 0, 'l', 0, 't', 0, ' ', 0, \ - 'c', 0, 'o', 0, 'n', 0, 'f', 0, \ - 'i', 0, 'g', 0, + "D\0e\0f\0a\0u\0l\0t\0 \0c\0o\0n\0f\0i\0g" #define STRING_ETH_VENDOR \ - 'F', 0, 'r', 0, 'e', 0, 'e', 0, \ - 'B', 0, 'S', 0, 'D', 0, ' ', 0, \ - 'f', 0, 'o', 0, 'u', 0, 'n', 0, \ - 'd', 0, 'a', 0, 't', 0, 'i', 0, \ - 'o', 0, 'n', 0, + "F\0r\0e\0e\0B\0S\0D\0 \0f\0o\0u\0n\0d\0a\0t\0i\0o\0n" #define STRING_ETH_PRODUCT \ - 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ - 'E', 0, 't', 0, 'h', 0, 'e', 0, \ - 'r', 0, 'n', 0, 'e', 0, 't', 0, \ - ' ', 0, 'A', 0, 'd', 0, 'a', 0, \ - 'p', 0, 't', 0, 'e', 0, 'r', 0, + "U\0S\0B\0 \0E\0t\0h\0e\0r\0n\0e\0t\0 \0A\0d\0a\0p\0t\0e\0r" #define STRING_ETH_SERIAL \ - 'D', 0, 'e', 0, 'c', 0, 'e', 0, \ - 'm', 0, 'b', 0, 'e', 0, 'r', 0, \ - ' ', 0, '2', 0, '0', 0, '0', 0, \ - '7', 0, + "D\0e\0c\0e\0m\0b\0e\0r\0 \0002\0000\0000\0007" /* make the real string descriptors */ -USB_MAKE_STRING_DESC(STRING_LANG, string_lang); USB_MAKE_STRING_DESC(STRING_MAC, string_mac); USB_MAKE_STRING_DESC(STRING_ETH_CONTROL, string_eth_control); USB_MAKE_STRING_DESC(STRING_ETH_DATA, string_eth_data); @@ -286,7 +256,7 @@ static const void * eth_get_string_desc(uint16_t lang_id, uint8_t string_index) { static const void *ptr[STRING_ETH_MAX] = { - [STRING_LANG_INDEX] = &string_lang, + [STRING_LANG_INDEX] = &usb_string_lang_en, [STRING_MAC_INDEX] = &string_mac, [STRING_ETH_CONTROL_INDEX] = &string_eth_control, [STRING_ETH_DATA_INDEX] = &string_eth_data, @@ -297,7 +267,7 @@ eth_get_string_desc(uint16_t lang_id, uint8_t string_index) }; if (string_index == 0) { - return (&string_lang); + return (&usb_string_lang_en); } if (lang_id != 0x0409) { return (NULL); diff --git a/sys/bus/u4b/template/usb_template_kbd.c b/sys/bus/u4b/template/usb_template_kbd.c index 6295825a73..e81bbd5f4d 100644 --- a/sys/bus/u4b/template/usb_template_kbd.c +++ b/sys/bus/u4b/template/usb_template_kbd.c @@ -1,6 +1,4 @@ -#include -__FBSDID("$FreeBSD$"); - +/* $FreeBSD: head/sys/dev/usb/template/usb_template_kbd.c 246125 2013-01-30 16:05:54Z hselasky $ */ /*- * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * @@ -30,8 +28,10 @@ __FBSDID("$FreeBSD$"); * This file contains the USB template for an USB Keyboard Device. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -40,20 +40,20 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include +#include +#include +#include +#include -#include +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ enum { INDEX_LANG, @@ -62,21 +62,14 @@ enum { INDEX_MAX, }; -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - #define STRING_PRODUCT \ - 'K', 0, 'e', 0, 'y', 0, 'b', 0, 'o', 0, 'a', 0, 'r', 0, 'd', 0, ' ', 0, \ - 'T', 0, 'e', 0, 's', 0, 't', 0, ' ', 0, \ - 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, ' ', 0, + "K\0e\0y\0b\0o\0a\0r\0d\0 \0T\0e\0s\0t\0 \0D\0e\0v\0i\0c\0e" #define STRING_KEYBOARD \ - 'K', 0, 'e', 0, 'y', 0, 'b', 0, 'o', 0, 'a', 0, 'r', 0, 'd', 0, ' ', 0, \ - 'i', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, + "K\0e\0y\0b\0o\0a\0r\0d\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e" /* make the real string descriptors */ -USB_MAKE_STRING_DESC(STRING_LANG, string_lang); USB_MAKE_STRING_DESC(STRING_KEYBOARD, string_keyboard); USB_MAKE_STRING_DESC(STRING_PRODUCT, string_product); @@ -206,13 +199,13 @@ static const void * keyboard_get_string_desc(uint16_t lang_id, uint8_t string_index) { static const void *ptr[INDEX_MAX] = { - [INDEX_LANG] = &string_lang, + [INDEX_LANG] = &usb_string_lang_en, [INDEX_KEYBOARD] = &string_keyboard, [INDEX_PRODUCT] = &string_product, }; if (string_index == 0) { - return (&string_lang); + return (&usb_string_lang_en); } if (lang_id != 0x0409) { return (NULL); diff --git a/sys/bus/u4b/template/usb_template_modem.c b/sys/bus/u4b/template/usb_template_modem.c index abc6f26be7..5b65825b06 100644 --- a/sys/bus/u4b/template/usb_template_modem.c +++ b/sys/bus/u4b/template/usb_template_modem.c @@ -1,6 +1,4 @@ -#include -__FBSDID("$FreeBSD$"); - +/* $FreeBSD: head/sys/dev/usb/template/usb_template_modem.c 246125 2013-01-30 16:05:54Z hselasky $ */ /*- * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * @@ -30,8 +28,10 @@ __FBSDID("$FreeBSD$"); * This file contains the USB template for an USB Modem Device. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -40,20 +40,20 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include +#include +#include +#include +#include -#include +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ enum { INDEX_LANG, @@ -62,21 +62,14 @@ enum { INDEX_MAX, }; -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - #define STRING_PRODUCT \ - 'M', 0, 'o', 0, 'd', 0, 'e', 0, 'm', 0, ' ', 0, \ - 'T', 0, 'e', 0, 's', 0, 't', 0, ' ', 0, \ - 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, ' ', 0, + "M\0o\0d\0e\0m\0 \0T\0e\0s\0t\0 \0D\0e\0v\0i\0c\0e" #define STRING_MODEM \ - 'M', 0, 'o', 0, 'd', 0, 'e', 0, 'm', 0, ' ', 0, \ - 'i', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, + "M\0o\0d\0e\0m\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e" /* make the real string descriptors */ -USB_MAKE_STRING_DESC(STRING_LANG, string_lang); USB_MAKE_STRING_DESC(STRING_MODEM, string_modem); USB_MAKE_STRING_DESC(STRING_PRODUCT, string_product); @@ -234,13 +227,13 @@ static const void * modem_get_string_desc(uint16_t lang_id, uint8_t string_index) { static const void *ptr[INDEX_MAX] = { - [INDEX_LANG] = &string_lang, + [INDEX_LANG] = &usb_string_lang_en, [INDEX_MODEM] = &string_modem, [INDEX_PRODUCT] = &string_product, }; if (string_index == 0) { - return (&string_lang); + return (&usb_string_lang_en); } if (lang_id != 0x0409) { return (NULL); diff --git a/sys/bus/u4b/template/usb_template_mouse.c b/sys/bus/u4b/template/usb_template_mouse.c index 628c9a5e23..b11f4df3d7 100644 --- a/sys/bus/u4b/template/usb_template_mouse.c +++ b/sys/bus/u4b/template/usb_template_mouse.c @@ -1,6 +1,4 @@ -#include -__FBSDID("$FreeBSD$"); - +/* $FreeBSD: head/sys/dev/usb/template/usb_template_mouse.c 246125 2013-01-30 16:05:54Z hselasky $ */ /*- * Copyright (c) 2010 Hans Petter Selasky. All rights reserved. * @@ -30,8 +28,10 @@ __FBSDID("$FreeBSD$"); * This file contains the USB template for an USB Mouse Device. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -40,20 +40,20 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include +#include +#include +#include +#include -#include +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ enum { INDEX_LANG, @@ -62,21 +62,14 @@ enum { INDEX_MAX, }; -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - #define STRING_PRODUCT \ - 'M', 0, 'o', 0, 'u', 0, 's', 0, 'e', 0, ' ', 0, \ - 'T', 0, 'e', 0, 's', 0, 't', 0, ' ', 0, \ - 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, + "M\0o\0u\0s\0e\0 \0T\0e\0s\0t\0 \0D\0e\0v\0i\0c\0e" #define STRING_MOUSE \ - 'M', 0, 'o', 0, 'u', 0, 's', 0, 'e', 0, ' ', 0, \ - 'i', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, + "M\0o\0u\0s\0e\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e" /* make the real string descriptors */ -USB_MAKE_STRING_DESC(STRING_LANG, string_lang); USB_MAKE_STRING_DESC(STRING_MOUSE, string_mouse); USB_MAKE_STRING_DESC(STRING_PRODUCT, string_product); @@ -204,13 +197,13 @@ static const void * mouse_get_string_desc(uint16_t lang_id, uint8_t string_index) { static const void *ptr[INDEX_MAX] = { - [INDEX_LANG] = &string_lang, + [INDEX_LANG] = &usb_string_lang_en, [INDEX_MOUSE] = &string_mouse, [INDEX_PRODUCT] = &string_product, }; if (string_index == 0) { - return (&string_lang); + return (&usb_string_lang_en); } if (lang_id != 0x0409) { return (NULL); diff --git a/sys/bus/u4b/template/usb_template_msc.c b/sys/bus/u4b/template/usb_template_msc.c index 5c05ffe8e2..01ce397699 100644 --- a/sys/bus/u4b/template/usb_template_msc.c +++ b/sys/bus/u4b/template/usb_template_msc.c @@ -1,6 +1,4 @@ -#include -__FBSDID("$FreeBSD$"); - +/* $FreeBSD: head/sys/dev/usb/template/usb_template_msc.c 246125 2013-01-30 16:05:54Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky * All rights reserved. @@ -31,8 +29,10 @@ __FBSDID("$FreeBSD$"); * This file contains the USB templates for an USB Mass Storage Device. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -41,19 +41,19 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include +#include +#include +#include -#include +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ enum { STRING_LANG_INDEX, @@ -65,45 +65,24 @@ enum { STRING_MSC_MAX, }; -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - #define STRING_MSC_DATA \ - 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ - 'M', 0, 'a', 0, 's', 0, 's', 0, \ - ' ', 0, 'S', 0, 't', 0, 'o', 0, \ - 'r', 0, 'a', 0, 'g', 0, 'e', 0, \ - ' ', 0, 'I', 0, 'n', 0, 't', 0, \ - 'e', 0, 'r', 0, 'f', 0, 'a', 0, \ - 'c', 0, 'e', 0, + "U\0S\0B\0 \0M\0a\0s\0s\0 \0S\0t\0o\0r\0a\0g\0e\0 " \ + "\0I\0n\0t\0e\0r\0f\0a\0c\0e" #define STRING_MSC_CONFIG \ - 'D', 0, 'e', 0, 'f', 0, 'a', 0, \ - 'u', 0, 'l', 0, 't', 0, ' ', 0, \ - 'c', 0, 'o', 0, 'n', 0, 'f', 0, \ - 'i', 0, 'g', 0, + "D\0e\0f\0a\0u\0l\0t\0 \0c\0o\0n\0f\0i\0g" #define STRING_MSC_VENDOR \ - 'F', 0, 'r', 0, 'e', 0, 'e', 0, \ - 'B', 0, 'S', 0, 'D', 0, ' ', 0, \ - 'f', 0, 'o', 0, 'u', 0, 'n', 0, \ - 'd', 0, 'a', 0, 't', 0, 'i', 0, \ - 'o', 0, 'n', 0, + "F\0r\0e\0e\0B\0S\0D\0 \0f\0o\0u\0n\0d\0a\0t\0i\0o\0n" #define STRING_MSC_PRODUCT \ - 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ - 'M', 0, 'e', 0, 'm', 0, 'o', 0, \ - 'r', 0, 'y', 0, ' ', 0, 'S', 0, \ - 't', 0, 'i', 0, 'c', 0, 'k', 0 + "U\0S\0B\0 \0M\0e\0m\0o\0r\0y\0 \0S\0t\0i\0c\0k" #define STRING_MSC_SERIAL \ - 'M', 0, 'a', 0, 'r', 0, 'c', 0, \ - 'h', 0, ' ', 0, '2', 0, '0', 0, \ - '0', 0, '8', 0, + "M\0a\0r\0c\0h\0 \0002\0000\0000\08" /* make the real string descriptors */ -USB_MAKE_STRING_DESC(STRING_LANG, string_lang); USB_MAKE_STRING_DESC(STRING_MSC_DATA, string_msc_data); USB_MAKE_STRING_DESC(STRING_MSC_CONFIG, string_msc_config); USB_MAKE_STRING_DESC(STRING_MSC_VENDOR, string_msc_vendor); @@ -195,7 +174,7 @@ static const void * msc_get_string_desc(uint16_t lang_id, uint8_t string_index) { static const void *ptr[STRING_MSC_MAX] = { - [STRING_LANG_INDEX] = &string_lang, + [STRING_LANG_INDEX] = &usb_string_lang_en, [STRING_MSC_DATA_INDEX] = &string_msc_data, [STRING_MSC_CONFIG_INDEX] = &string_msc_config, [STRING_MSC_VENDOR_INDEX] = &string_msc_vendor, @@ -204,7 +183,7 @@ msc_get_string_desc(uint16_t lang_id, uint8_t string_index) }; if (string_index == 0) { - return (&string_lang); + return (&usb_string_lang_en); } if (lang_id != 0x0409) { return (NULL); diff --git a/sys/bus/u4b/template/usb_template_mtp.c b/sys/bus/u4b/template/usb_template_mtp.c index f48fbf422b..768a1e5a48 100644 --- a/sys/bus/u4b/template/usb_template_mtp.c +++ b/sys/bus/u4b/template/usb_template_mtp.c @@ -1,6 +1,4 @@ -#include -__FBSDID("$FreeBSD$"); - +/* $FreeBSD: head/sys/dev/usb/template/usb_template_mtp.c 246125 2013-01-30 16:05:54Z hselasky $ */ /*- * Copyright (c) 2008 Hans Petter Selasky * All rights reserved. @@ -38,8 +36,10 @@ __FBSDID("$FreeBSD$"); * operating system the VID and PID of your device. */ +#ifdef USB_GLOBAL_INCLUDE_FILE +#include USB_GLOBAL_INCLUDE_FILE +#else #include -#include #include #include #include @@ -48,18 +48,19 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include -#include #include #include #include #include -#include -#include -#include +#include +#include +#include + +#include +#endif /* USB_GLOBAL_INCLUDE_FILE */ #define MTP_BREQUEST 0x08 @@ -73,41 +74,23 @@ enum { STRING_MTP_MAX, }; -#define STRING_LANG \ - 0x09, 0x04, /* American English */ - #define STRING_MTP_DATA \ - 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ - 'M', 0, 'T', 0, 'P', 0, \ - ' ', 0, 'I', 0, 'n', 0, 't', 0, \ - 'e', 0, 'r', 0, 'f', 0, 'a', 0, \ - 'c', 0, 'e', 0, + "U\0S\0B\0 \0M\0T\0P\0 \0I\0n\0t\0e\0r\0f\0a\0c\0e" #define STRING_MTP_CONFIG \ - 'D', 0, 'e', 0, 'f', 0, 'a', 0, \ - 'u', 0, 'l', 0, 't', 0, ' ', 0, \ - 'c', 0, 'o', 0, 'n', 0, 'f', 0, \ - 'i', 0, 'g', 0, + "D\0e\0f\0a\0u\0l\0t\0 \0c\0o\0n\0f\0i\0g" #define STRING_MTP_VENDOR \ - 'F', 0, 'r', 0, 'e', 0, 'e', 0, \ - 'B', 0, 'S', 0, 'D', 0, ' ', 0, \ - 'f', 0, 'o', 0, 'u', 0, 'n', 0, \ - 'd', 0, 'a', 0, 't', 0, 'i', 0, \ - 'o', 0, 'n', 0, + "F\0r\0e\0e\0B\0S\0D\0 \0f\0o\0u\0n\0d\0a\0t\0i\0o\0n" #define STRING_MTP_PRODUCT \ - 'U', 0, 'S', 0, 'B', 0, ' ', 0, \ - 'M', 0, 'T', 0, 'P', 0, + "U\0S\0B\0 \0M\0T\0P" #define STRING_MTP_SERIAL \ - 'J', 0, 'u', 0, 'n', 0, 'e', 0, \ - ' ', 0, '2', 0, '0', 0, '0', 0, \ - '8', 0, + "J\0u\0n\0e\0 \0002\0000\0000\08" /* make the real string descriptors */ -USB_MAKE_STRING_DESC(STRING_LANG, string_lang); USB_MAKE_STRING_DESC(STRING_MTP_DATA, string_mtp_data); USB_MAKE_STRING_DESC(STRING_MTP_CONFIG, string_mtp_config); USB_MAKE_STRING_DESC(STRING_MTP_VENDOR, string_mtp_vendor); @@ -244,7 +227,7 @@ static const void * mtp_get_string_desc(uint16_t lang_id, uint8_t string_index) { static const void *ptr[STRING_MTP_MAX] = { - [STRING_LANG_INDEX] = &string_lang, + [STRING_LANG_INDEX] = &usb_string_lang_en, [STRING_MTP_DATA_INDEX] = &string_mtp_data, [STRING_MTP_CONFIG_INDEX] = &string_mtp_config, [STRING_MTP_VENDOR_INDEX] = &string_mtp_vendor, @@ -266,7 +249,7 @@ mtp_get_string_desc(uint16_t lang_id, uint8_t string_index) return (dummy_desc); } if (string_index == 0) { - return (&string_lang); + return (&usb_string_lang_en); } if (lang_id != 0x0409) { return (NULL); diff --git a/sys/conf/files b/sys/conf/files index 2dfb9cd2c1..2e8eadd4d5 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -2551,6 +2551,17 @@ bus/u4b/input/uhid.c optional uhid usb # bus/u4b/quirk/usb_quirk.c optional usb # +# USB templates +# +bus/u4b/template/usb_template.c optional usb_template usb +bus/u4b/template/usb_template_audio.c optional usb_template usb +bus/u4b/template/usb_template_cdce.c optional usb_template usb +bus/u4b/template/usb_template_kbd.c optional usb_template usb +bus/u4b/template/usb_template_modem.c optional usb_template usb +bus/u4b/template/usb_template_mouse.c optional usb_template usb +bus/u4b/template/usb_template_msc.c optional usb_template usb +bus/u4b/template/usb_template_mtp.c optional usb_template usb +# # Other drivers # bus/u4b/audio/uaudio.c optional snd_uaudio usb diff --git a/sys/config/LINT b/sys/config/LINT index b229e5bedd..56e715a0c5 100644 --- a/sys/config/LINT +++ b/sys/config/LINT @@ -2278,6 +2278,10 @@ device urtwnfw # device ufm +# Templates for programming USB device side drivers +# +device usb_template + # debugging options for the USB subsystem # options USB_DEBUG diff --git a/sys/config/LINT64 b/sys/config/LINT64 index 88e0ebd9ce..d56f131b03 100644 --- a/sys/config/LINT64 +++ b/sys/config/LINT64 @@ -2114,6 +2114,10 @@ device urtwnfw # device ufm +# Templates for programming USB device side drivers +# +device usb_template + # debugging options for the USB subsystem # options USB_DEBUG -- 2.41.0