From owner-p4-projects@FreeBSD.ORG Tue Jul 1 17:38:46 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A8437106567C; Tue, 1 Jul 2008 17:38:46 +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 68D1A106567A for ; Tue, 1 Jul 2008 17:38:46 +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 5822D8FC2F for ; Tue, 1 Jul 2008 17:38:46 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m61Hckb3051143 for ; Tue, 1 Jul 2008 17:38:46 GMT (envelope-from hselasky@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m61HckWA051141 for perforce@freebsd.org; Tue, 1 Jul 2008 17:38:46 GMT (envelope-from hselasky@FreeBSD.org) Date: Tue, 1 Jul 2008 17:38:46 GMT Message-Id: <200807011738.m61HckWA051141@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 144435 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: Tue, 01 Jul 2008 17:38:47 -0000 http://perforce.freebsd.org/chv.cgi?CH=144435 Change 144435 by hselasky@hselasky_laptop001 on 2008/07/01 17:38:36 New USB template modules is finished. Affected files ... .. //depot/projects/usb/src/sys/dev/usb2/template/usb2_template.c#2 edit .. //depot/projects/usb/src/sys/dev/usb2/template/usb2_template.h#2 edit .. //depot/projects/usb/src/sys/dev/usb2/template/usb2_template_cdce.c#2 edit .. //depot/projects/usb/src/sys/dev/usb2/template/usb2_template_msc.c#2 edit .. //depot/projects/usb/src/sys/dev/usb2/template/usb2_template_mtp.c#2 edit .. //depot/projects/usb/src/sys/modules/usb2/template/Makefile#2 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb2/template/usb2_template.c#2 (text+ko) ==== @@ -1,9 +1,5 @@ -#include -__FBSDID("$FreeBSD: src/sys/dev/usb/usb_template.c $"); - /*- - * Copyright (c) 2007 Hans Petter Selasky - * All rights reserved. + * Copyright (c) 2007 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 @@ -32,28 +28,62 @@ * USB templates. */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include + +#define USB_DEBUG_VAR usb2_debug + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +MODULE_DEPEND(usb2_template, usb2_core, 1, 1, 1); +MODULE_VERSION(usb2_template, 1); + +/* function prototypes */ -#include -#include -#include -#include -#include +static void usb2_make_raw_desc(struct usb2_temp_setup *temp, const uint8_t *raw); +static void usb2_make_endpoint_desc(struct usb2_temp_setup *temp, const struct usb2_temp_endpoint_desc *ted); +static void usb2_make_interface_desc(struct usb2_temp_setup *temp, const struct usb2_temp_interface_desc *tid); +static void usb2_make_config_desc(struct usb2_temp_setup *temp, const struct usb2_temp_config_desc *tcd); +static void usb2_make_device_desc(struct usb2_temp_setup *temp, const struct usb2_temp_device_desc *tdd); +static uint8_t usb2_hw_ep_match(const struct usb2_hw_ep_profile *pf, uint8_t ep_type, uint8_t ep_dir_in); +static uint8_t usb2_hw_ep_find_match(struct usb2_hw_ep_scratch *ues, struct usb2_hw_ep_scratch_sub *ep, uint8_t is_simplex); +static uint8_t usb2_hw_ep_get_needs(struct usb2_hw_ep_scratch *ues, uint8_t ep_type, uint8_t is_complete); +static usb2_error_t usb2_hw_ep_resolve(struct usb2_device *udev, struct usb2_descriptor *desc); +static const struct usb2_temp_device_desc *usb2_temp_get_tdd(struct usb2_device *udev); +static void *usb2_temp_get_device_desc(struct usb2_device *udev); +static void *usb2_temp_get_qualifier_desc(struct usb2_device *udev); +static void *usb2_temp_get_config_desc(struct usb2_device *udev, uint16_t *pLength, uint8_t index); +static const void *usb2_temp_get_string_desc(struct usb2_device *udev, uint16_t lang_id, uint8_t string_index); +static const void *usb2_temp_get_hub_desc(struct usb2_device *udev); +static void usb2_temp_get_desc(struct usb2_device *udev, struct usb2_device_request *req, const void **pPtr, uint16_t *pLength); +static usb2_error_t usb2_temp_setup(struct usb2_device *udev, const struct usb2_temp_device_desc *tdd); +static void usb2_temp_unsetup(struct usb2_device *udev); +static usb2_error_t usb2_temp_setup_by_index(struct usb2_device *udev, uint16_t index); +static void usb2_temp_init(void *arg); /*------------------------------------------------------------------------* - * usbd_make_raw_desc + * usb2_make_raw_desc * * This function will insert a raw USB descriptor into the generated * USB configuration. *------------------------------------------------------------------------*/ static void -usbd_make_raw_desc(struct usbd_temp_setup *temp, +usb2_make_raw_desc(struct usb2_temp_setup *temp, const uint8_t *raw) { void *dst; @@ -65,15 +95,15 @@ if (raw) { len = raw[0]; if (temp->buf) { - dst = USBD_ADD_BYTES(temp->buf, temp->size); + dst = USB_ADD_BYTES(temp->buf, temp->size); bcopy(raw, dst, len); /* check if we have got a CDC union descriptor */ - if ((raw[0] >= sizeof(usb_cdc_union_descriptor_t)) && + if ((raw[0] >= sizeof(struct usb2_cdc_union_descriptor)) && (raw[1] == UDESC_CS_INTERFACE) && (raw[2] == UDESCSUB_CDC_UNION)) { - usb_cdc_union_descriptor_t *ud = (void *)dst; + struct usb2_cdc_union_descriptor *ud = (void *)dst; /* update the interface numbers */ @@ -89,17 +119,17 @@ } /*------------------------------------------------------------------------* - * usbd_make_endpoint_desc + * usb2_make_endpoint_desc * * This function will generate an USB endpoint descriptor from the * given USB template endpoint descriptor, which will be inserted into * the USB configuration. *------------------------------------------------------------------------*/ static void -usbd_make_endpoint_desc(struct usbd_temp_setup *temp, - const struct usb_temp_endpoint_desc *ted) +usb2_make_endpoint_desc(struct usb2_temp_setup *temp, + const struct usb2_temp_endpoint_desc *ted) { - usb_endpoint_descriptor_t *ed; + struct usb2_endpoint_descriptor *ed; const void **rd; uint16_t old_size; uint16_t mps; @@ -115,19 +145,19 @@ rd = ted->ppRawDesc; if (rd) { while (*rd) { - usbd_make_raw_desc(temp, *rd); + usb2_make_raw_desc(temp, *rd); rd++; } } if (ted->pPacketSize == NULL) { /* not initialized */ - temp->err = USBD_ERR_INVAL; + temp->err = USB_ERR_INVAL; return; } - mps = ted->pPacketSize->mps[temp->usb_speed]; + mps = ted->pPacketSize->mps[temp->usb2_speed]; if (mps == 0) { /* not initialized */ - temp->err = USBD_ERR_INVAL; + temp->err = USB_ERR_INVAL; return; } else if (mps == UE_ZERO_MPS) { /* escape for Zero Max Packet Size */ @@ -141,7 +171,7 @@ * in case there is a buffer present: */ if (temp->buf) { - ed = USBD_ADD_BYTES(temp->buf, old_size); + ed = USB_ADD_BYTES(temp->buf, old_size); ed->bLength = sizeof(*ed); ed->bDescriptorType = UDESC_ENDPOINT; ed->bEndpointAddress = ea; @@ -151,9 +181,9 @@ /* setup bInterval parameter */ if (ted->pIntervals && - ted->pIntervals->bInterval[temp->usb_speed]) { + ted->pIntervals->bInterval[temp->usb2_speed]) { ed->bInterval = - ted->pIntervals->bInterval[temp->usb_speed]; + ted->pIntervals->bInterval[temp->usb2_speed]; } else { switch (et) { case UE_BULK: @@ -161,7 +191,7 @@ ed->bInterval = 0; /* not used */ break; case UE_INTERRUPT: - switch (temp->usb_speed) { + switch (temp->usb2_speed) { case USB_SPEED_LOW: case USB_SPEED_FULL: ed->bInterval = 1; /* 1 ms */ @@ -172,7 +202,7 @@ } break; default: /* UE_ISOCHRONOUS */ - switch (temp->usb_speed) { + switch (temp->usb2_speed) { case USB_SPEED_LOW: case USB_SPEED_FULL: ed->bInterval = 1; /* 1 ms */ @@ -190,18 +220,18 @@ } /*------------------------------------------------------------------------* - * usbd_make_interface_desc + * usb2_make_interface_desc * * This function will generate an USB interface descriptor from the * given USB template interface descriptor, which will be inserted * into the USB configuration. *------------------------------------------------------------------------*/ static void -usbd_make_interface_desc(struct usbd_temp_setup *temp, - const struct usb_temp_interface_desc *tid) +usb2_make_interface_desc(struct usb2_temp_setup *temp, + const struct usb2_temp_interface_desc *tid) { - usb_interface_descriptor_t *id; - const struct usb_temp_endpoint_desc **ted; + struct usb2_interface_descriptor *id; + const struct usb2_temp_endpoint_desc **ted; const void **rd; uint16_t old_size; @@ -225,7 +255,7 @@ if (rd) { while (*rd) { - usbd_make_raw_desc(temp, *rd); + usb2_make_raw_desc(temp, *rd); rd++; } } @@ -238,7 +268,7 @@ ted = tid->ppEndpoints; if (ted) { while (*ted) { - usbd_make_endpoint_desc(temp, *ted); + usb2_make_endpoint_desc(temp, *ted); ted++; } } @@ -247,7 +277,7 @@ * in case there is a buffer present: */ if (temp->buf) { - id = USBD_ADD_BYTES(temp->buf, old_size); + id = USB_ADD_BYTES(temp->buf, old_size); id->bLength = sizeof(*id); id->bDescriptorType = UDESC_INTERFACE; id->bInterfaceNumber = temp->bInterfaceNumber; @@ -262,18 +292,18 @@ } /*------------------------------------------------------------------------* - * usbd_make_config_desc + * usb2_make_config_desc * * This function will generate an USB config descriptor from the given * USB template config descriptor, which will be inserted into the USB * configuration. *------------------------------------------------------------------------*/ static void -usbd_make_config_desc(struct usbd_temp_setup *temp, - const struct usb_temp_config_desc *tcd) +usb2_make_config_desc(struct usb2_temp_setup *temp, + const struct usb2_temp_config_desc *tcd) { - usb_config_descriptor_t *cd; - const struct usb_temp_interface_desc **tid; + struct usb2_config_descriptor *cd; + const struct usb2_temp_interface_desc **tid; uint16_t old_size; /* Reserve memory */ @@ -291,7 +321,7 @@ tid = tcd->ppIfaceDesc; if (tid) { while (*tid) { - usbd_make_interface_desc(temp, *tid); + usb2_make_interface_desc(temp, *tid); tid++; } } @@ -300,7 +330,7 @@ * in case there is a buffer present: */ if (temp->buf) { - cd = USBD_ADD_BYTES(temp->buf, old_size); + cd = USB_ADD_BYTES(temp->buf, old_size); /* compute total size */ old_size = temp->size - old_size; @@ -325,17 +355,17 @@ } /*------------------------------------------------------------------------* - * usbd_make_device_desc + * usb2_make_device_desc * * This function will generate an USB device descriptor from the * given USB template device descriptor. *------------------------------------------------------------------------*/ static void -usbd_make_device_desc(struct usbd_temp_setup *temp, - const struct usb_temp_device_desc *tdd) +usb2_make_device_desc(struct usb2_temp_setup *temp, + const struct usb2_temp_device_desc *tdd) { - struct usb_temp_data *utd; - const struct usb_temp_config_desc **tcd; + struct usb2_temp_data *utd; + const struct usb2_temp_config_desc **tcd; uint16_t old_size; /* Reserve memory */ @@ -349,7 +379,7 @@ tcd = tdd->ppConfigDesc; if (tcd) { while (*tcd) { - usbd_make_config_desc(temp, *tcd); + usb2_make_config_desc(temp, *tcd); temp->bConfigurationValue++; tcd++; } @@ -360,7 +390,7 @@ */ if (temp->buf) { - utd = USBD_ADD_BYTES(temp->buf, old_size); + utd = USB_ADD_BYTES(temp->buf, old_size); /* Store a pointer to our template device descriptor */ utd->tdd = tdd; @@ -395,7 +425,7 @@ USETW(utd->udq.bcdUSB, 0x0200); utd->udq.bMaxPacketSize0 = 0; - switch (temp->usb_speed) { + switch (temp->usb2_speed) { case USB_SPEED_LOW: USETW(utd->udd.bcdUSB, 0x0110); utd->udd.bMaxPacketSize = 8; @@ -413,7 +443,7 @@ utd->udd.bMaxPacketSize = 255; /* 512 bytes */ break; default: - temp->err = USBD_ERR_INVAL; + temp->err = USB_ERR_INVAL; break; } } @@ -421,14 +451,14 @@ } /*------------------------------------------------------------------------* - * usbd_hw_ep_match + * usb2_hw_ep_match * * Return values: * 0: The endpoint profile does not match the criterias * Else: The endpoint profile matches the criterias *------------------------------------------------------------------------*/ static uint8_t -usbd_hw_ep_match(const struct usbd_hw_ep_profile *pf, +usb2_hw_ep_match(const struct usb2_hw_ep_profile *pf, uint8_t ep_type, uint8_t ep_dir_in) { if (ep_type == UE_CONTROL) { @@ -447,7 +477,7 @@ } /*------------------------------------------------------------------------* - * usbd_hw_ep_find_match + * usb2_hw_ep_find_match * * This function is used to find the best matching endpoint profile * for and endpoint belonging to an USB descriptor. @@ -457,10 +487,10 @@ * Else: Failure. No match. *------------------------------------------------------------------------*/ static uint8_t -usbd_hw_ep_find_match(struct usbd_hw_ep_scratch *ues, - struct usbd_sw_ep_scratch *ep, uint8_t is_simplex) +usb2_hw_ep_find_match(struct usb2_hw_ep_scratch *ues, + struct usb2_hw_ep_scratch_sub *ep, uint8_t is_simplex) { - const struct usbd_hw_ep_profile *pf; + const struct usb2_hw_ep_profile *pf; uint16_t distance; uint16_t temp; uint8_t n; @@ -486,7 +516,7 @@ } } - for (n = 1; n != (USB_MAX_ENDPOINTS / 2); n++) { + for (n = 1; n != (USB_EP_MAX / 2); n++) { /* check if IN-endpoint is reserved */ if (dir_in) { @@ -514,7 +544,7 @@ continue; } /* check if HW endpoint matches */ - if (!usbd_hw_ep_match(pf, ep->needs_ep_type, dir_in)) { + if (!usb2_hw_ep_match(pf, ep->needs_ep_type, dir_in)) { /* mismatch */ continue; } @@ -568,7 +598,7 @@ } /*------------------------------------------------------------------------* - * usbd_hw_ep_get_needs + * usb2_hw_ep_get_needs * * This function will figure out the type and number of endpoints * which are needed for an USB configuration. @@ -578,16 +608,16 @@ * Else: Failure. *------------------------------------------------------------------------*/ static uint8_t -usbd_hw_ep_get_needs(struct usbd_hw_ep_scratch *ues, +usb2_hw_ep_get_needs(struct usb2_hw_ep_scratch *ues, uint8_t ep_type, uint8_t is_complete) { - struct usbd_sw_ep_scratch *ep_iface; - struct usbd_sw_ep_scratch *ep_curr; - struct usbd_sw_ep_scratch *ep_max; - struct usbd_sw_ep_scratch *ep_end; - usb_descriptor_t *desc; - usb_interface_descriptor_t *id; - usb_endpoint_descriptor_t *ed; + struct usb2_hw_ep_scratch_sub *ep_iface; + struct usb2_hw_ep_scratch_sub *ep_curr; + struct usb2_hw_ep_scratch_sub *ep_max; + struct usb2_hw_ep_scratch_sub *ep_end; + struct usb2_descriptor *desc; + struct usb2_interface_descriptor *id; + struct usb2_endpoint_descriptor *ed; uint16_t wMaxPacketSize; uint16_t temp; uint8_t allow_override; @@ -595,14 +625,14 @@ ep_iface = ues->ep_max; ep_curr = ues->ep_max; - ep_end = ues->ep + USB_MAX_ENDPOINTS; + ep_end = ues->ep + USB_EP_MAX; ep_max = ues->ep_max; desc = NULL; - speed = ues->udev->speed; + speed = usb2_get_speed(ues->udev); repeat: - while ((desc = usbd_desc_foreach(ues->cd, desc))) { + while ((desc = usb2_desc_foreach(ues->cd, desc))) { if ((desc->bDescriptorType == UDESC_INTERFACE) && (desc->bLength >= sizeof(*id))) { @@ -726,7 +756,7 @@ } /*------------------------------------------------------------------------* - * usbd_hw_ep_resolve + * usb2_hw_ep_resolve * * This function will try to resolve endpoint requirements by the * given endpoint profiles that the USB hardware reports. @@ -735,42 +765,42 @@ * 0: Success * Else: Failure *------------------------------------------------------------------------*/ -static usbd_status_t -usbd_hw_ep_resolve(struct usbd_device *udev, - usb_descriptor_t *desc) +static usb2_error_t +usb2_hw_ep_resolve(struct usb2_device *udev, + struct usb2_descriptor *desc) { - struct usbd_hw_ep_scratch *ues; - struct usbd_sw_ep_scratch *ep; - const struct usbd_hw_ep_profile *pf; - struct usbd_bus_methods *methods; - usb_device_descriptor_t *dd; + struct usb2_hw_ep_scratch *ues; + struct usb2_hw_ep_scratch_sub *ep; + const struct usb2_hw_ep_profile *pf; + struct usb2_bus_methods *methods; + struct usb2_device_descriptor *dd; uint16_t mps; if (desc == NULL) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } /* get bus methods */ methods = udev->bus->methods; if (methods->get_hw_ep_profile == NULL) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } if (desc->bDescriptorType == UDESC_DEVICE) { if (desc->bLength < sizeof(*dd)) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } dd = (void *)desc; /* get HW control endpoint 0 profile */ (methods->get_hw_ep_profile) (udev, &pf, 0); if (pf == NULL) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } - if (!usbd_hw_ep_match(pf, UE_CONTROL, 0)) { - PRINTFN(-1, ("Endpoint 0 does not " - "support control\n")); - return (USBD_ERR_INVAL); + if (!usb2_hw_ep_match(pf, UE_CONTROL, 0)) { + DPRINTF(-1, "Endpoint 0 does not " + "support control\n"); + return (USB_ERR_INVAL); } mps = dd->bMaxPacketSize; @@ -788,7 +818,7 @@ /* check if "mps" is too small */ if (mps < 8) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } } @@ -801,18 +831,18 @@ } /* Check if we support the specified wMaxPacketSize */ if (pf->max_frame_size < mps) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } } return (0); /* success */ } if (desc->bDescriptorType != UDESC_CONFIG) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } if (desc->bLength < sizeof(*(ues->cd))) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } - ues = udev->scratch[0].hw_ep_scratch; + ues = udev->bus->scratch[0].hw_ep_scratch; bzero(ues, sizeof(*ues)); @@ -823,12 +853,12 @@ /* Get all the endpoints we need */ - if (usbd_hw_ep_get_needs(ues, UE_ISOCHRONOUS, 0) || - usbd_hw_ep_get_needs(ues, UE_INTERRUPT, 0) || - usbd_hw_ep_get_needs(ues, UE_CONTROL, 0) || - usbd_hw_ep_get_needs(ues, UE_BULK, 0)) { - PRINTFN(-1, ("Could not get needs\n")); - return (USBD_ERR_INVAL); + if (usb2_hw_ep_get_needs(ues, UE_ISOCHRONOUS, 0) || + usb2_hw_ep_get_needs(ues, UE_INTERRUPT, 0) || + usb2_hw_ep_get_needs(ues, UE_CONTROL, 0) || + usb2_hw_ep_get_needs(ues, UE_BULK, 0)) { + DPRINTF(-1, "Could not get needs\n"); + return (USB_ERR_INVAL); } for (ep = ues->ep; ep != ues->ep_max; ep++) { @@ -838,10 +868,10 @@ * First try to use a simplex endpoint. * Then try to use a duplex endpoint. */ - if (usbd_hw_ep_find_match(ues, ep, 1) && - usbd_hw_ep_find_match(ues, ep, 0)) { - PRINTFN(-1, ("Could not find match\n")); - return (USBD_ERR_INVAL); + if (usb2_hw_ep_find_match(ues, ep, 1) && + usb2_hw_ep_find_match(ues, ep, 0)) { + DPRINTF(-1, "Could not find match\n"); + return (USB_ERR_INVAL); } } } @@ -850,48 +880,48 @@ /* Update all endpoint addresses */ - if (usbd_hw_ep_get_needs(ues, UE_ISOCHRONOUS, 1) || - usbd_hw_ep_get_needs(ues, UE_INTERRUPT, 1) || - usbd_hw_ep_get_needs(ues, UE_CONTROL, 1) || - usbd_hw_ep_get_needs(ues, UE_BULK, 1)) { - PRINTFN(-1, ("Could not update endpoint address\n")); - return (USBD_ERR_INVAL); + if (usb2_hw_ep_get_needs(ues, UE_ISOCHRONOUS, 1) || + usb2_hw_ep_get_needs(ues, UE_INTERRUPT, 1) || + usb2_hw_ep_get_needs(ues, UE_CONTROL, 1) || + usb2_hw_ep_get_needs(ues, UE_BULK, 1)) { + DPRINTF(-1, "Could not update endpoint address\n"); + return (USB_ERR_INVAL); } return (0); /* success */ } /*------------------------------------------------------------------------* - * usbd_temp_get_tdd + * usb2_temp_get_tdd * * Returns: * NULL: No USB template device descriptor found. * Else: Pointer to the USB template device descriptor. *------------------------------------------------------------------------*/ -static const struct usb_temp_device_desc * -usbd_temp_get_tdd(struct usbd_device *udev) +static const struct usb2_temp_device_desc * +usb2_temp_get_tdd(struct usb2_device *udev) { - if (udev->usb_template_ptr == NULL) { + if (udev->usb2_template_ptr == NULL) { return (NULL); } - return (udev->usb_template_ptr->tdd); + return (udev->usb2_template_ptr->tdd); } /*------------------------------------------------------------------------* - * usbd_temp_get_device_desc + * usb2_temp_get_device_desc * * Returns: * NULL: No USB device descriptor found. * Else: Pointer to USB device descriptor. *------------------------------------------------------------------------*/ static void * -usbd_temp_get_device_desc(struct usbd_device *udev) +usb2_temp_get_device_desc(struct usb2_device *udev) { - usb_device_descriptor_t *dd; + struct usb2_device_descriptor *dd; - if (udev->usb_template_ptr == NULL) { + if (udev->usb2_template_ptr == NULL) { return (NULL); } - dd = &(udev->usb_template_ptr->udd); + dd = &(udev->usb2_template_ptr->udd); if (dd->bDescriptorType != UDESC_DEVICE) { /* sanity check failed */ return (NULL); @@ -900,21 +930,21 @@ } /*------------------------------------------------------------------------* - * usbd_temp_get_qualifier_desc + * usb2_temp_get_qualifier_desc * * Returns: * NULL: No USB device_qualifier descriptor found. * Else: Pointer to USB device_qualifier descriptor. *------------------------------------------------------------------------*/ static void * -usbd_temp_get_qualifier_desc(struct usbd_device *udev) +usb2_temp_get_qualifier_desc(struct usb2_device *udev) { - usb_device_qualifier_t *dq; + struct usb2_device_qualifier *dq; - if (udev->usb_template_ptr == NULL) { + if (udev->usb2_template_ptr == NULL) { return (NULL); } - dq = &(udev->usb_template_ptr->udq); + dq = &(udev->usb2_template_ptr->udq); if (dq->bDescriptorType != UDESC_DEVICE_QUALIFIER) { /* sanity check failed */ return (NULL); @@ -923,25 +953,25 @@ } /*------------------------------------------------------------------------* - * usbd_temp_get_config_desc + * usb2_temp_get_config_desc * * Returns: * NULL: No USB config descriptor found. * Else: Pointer to USB config descriptor having index "index". *------------------------------------------------------------------------*/ static void * -usbd_temp_get_config_desc(struct usbd_device *udev, +usb2_temp_get_config_desc(struct usb2_device *udev, uint16_t *pLength, uint8_t index) { - usb_device_descriptor_t *dd; - usb_config_descriptor_t *cd; + struct usb2_device_descriptor *dd; + struct usb2_config_descriptor *cd; uint16_t temp; - if (udev->usb_template_ptr == NULL) { + if (udev->usb2_template_ptr == NULL) { return (NULL); } - dd = &(udev->usb_template_ptr->udd); - cd = (void *)(udev->usb_template_ptr + 1); + dd = &(udev->usb2_template_ptr->udd); + cd = (void *)(udev->usb2_template_ptr + 1); if (index >= dd->bNumConfigurations) { /* out of range */ @@ -953,7 +983,7 @@ return (NULL); } temp = UGETW(cd->wTotalLength); - cd = USBD_ADD_BYTES(cd, temp); + cd = USB_ADD_BYTES(cd, temp); } if (pLength) { @@ -963,19 +993,19 @@ } /*------------------------------------------------------------------------* - * usbd_temp_get_string_desc + * usb2_temp_get_string_desc * * Returns: * NULL: No string descriptor found. * Else: Pointer to a string descriptor. *------------------------------------------------------------------------*/ static const void * -usbd_temp_get_string_desc(struct usbd_device *udev, +usb2_temp_get_string_desc(struct usb2_device *udev, uint16_t lang_id, uint8_t string_index) { - const struct usb_temp_device_desc *tdd; + const struct usb2_temp_device_desc *tdd; - tdd = usbd_temp_get_tdd(udev); + tdd = usb2_temp_get_tdd(udev); if (tdd == NULL) { return (NULL); } @@ -986,26 +1016,26 @@ } /*------------------------------------------------------------------------* - * usbd_temp_get_hub_desc + * usb2_temp_get_hub_desc * * Returns: * NULL: No USB HUB descriptor found. * Else: Pointer to a USB HUB descriptor. *------------------------------------------------------------------------*/ static const void * -usbd_temp_get_hub_desc(struct usbd_device *udev) +usb2_temp_get_hub_desc(struct usb2_device *udev) { return (NULL); /* needs to be implemented */ } /*------------------------------------------------------------------------* - * usbd_temp_get_desc + * usb2_temp_get_desc * * This function is a demultiplexer for local USB device side control * endpoint requests. *------------------------------------------------------------------------*/ -void -usbd_temp_get_desc(struct usbd_device *udev, usb_device_request_t *req, +static void +usb2_temp_get_desc(struct usb2_device *udev, struct usb2_device_request *req, const void **pPtr, uint16_t *pLength) { const uint8_t *buf; @@ -1041,7 +1071,7 @@ if (req->wValue[0]) { goto tr_stalled; } - buf = usbd_temp_get_device_desc(udev); + buf = usb2_temp_get_device_desc(udev); goto tr_valid; case UDESC_DEVICE_QUALIFIER: if (udev->speed != USB_SPEED_HIGH) { @@ -1050,18 +1080,18 @@ if (req->wValue[0]) { goto tr_stalled; } - buf = usbd_temp_get_qualifier_desc(udev); + buf = usb2_temp_get_qualifier_desc(udev); goto tr_valid; case UDESC_OTHER_SPEED_CONFIGURATION: if (udev->speed != USB_SPEED_HIGH) { goto tr_stalled; } case UDESC_CONFIG: - buf = usbd_temp_get_config_desc(udev, + buf = usb2_temp_get_config_desc(udev, &len, req->wValue[0]); goto tr_valid; case UDESC_STRING: - buf = usbd_temp_get_string_desc(udev, + buf = usb2_temp_get_string_desc(udev, UGETW(req->wIndex), req->wValue[0]); goto tr_valid; default: @@ -1073,7 +1103,7 @@ if (req->wValue[0]) { goto tr_stalled; } - buf = usbd_temp_get_hub_desc(udev); + buf = usb2_temp_get_hub_desc(udev); goto tr_valid; tr_valid: @@ -1094,7 +1124,7 @@ } /*------------------------------------------------------------------------* - * usbd_temp_setup + * usb2_temp_setup * * This function generates USB descriptors according to the given USB * template device descriptor. It will also try to figure out the best @@ -1104,11 +1134,11 @@ * 0: Success * Else: Failure *------------------------------------------------------------------------*/ -usbd_status_t -usbd_temp_setup(struct usbd_device *udev, - const struct usb_temp_device_desc *tdd) +static usb2_error_t +usb2_temp_setup(struct usb2_device *udev, + const struct usb2_temp_device_desc *tdd) { - struct usbd_temp_setup *uts; + struct usb2_temp_setup *uts; void *buf; uint8_t n; @@ -1116,16 +1146,16 @@ /* be NULL safe */ return (0); } - uts = udev->scratch[0].temp_setup; + uts = udev->bus->scratch[0].temp_setup; bzero(uts, sizeof(*uts)); - uts->usb_speed = udev->speed; + uts->usb2_speed = udev->speed; uts->self_powered = udev->flags.self_powered; /* first pass */ - usbd_make_device_desc(uts, tdd); + usb2_make_device_desc(uts, tdd); if (uts->err) { /* some error happened */ @@ -1133,24 +1163,24 @@ } /* sanity check */ if (uts->size == 0) { - return (USBD_ERR_INVAL); + return (USB_ERR_INVAL); } /* allocate zeroed memory */ uts->buf = malloc(uts->size, M_USB, M_WAITOK | M_ZERO); if (uts->buf == NULL) { /* could not allocate memory */ - return (USBD_ERR_NOMEM); + return (USB_ERR_NOMEM); } /* second pass */ uts->size = 0; - usbd_make_device_desc(uts, tdd); + usb2_make_device_desc(uts, tdd); /* * Store a pointer to our descriptors: */ - udev->usb_template_ptr = uts->buf; + udev->usb2_template_ptr = uts->buf; if (uts->err) { /* some error happened during second pass */ @@ -1159,49 +1189,84 @@ /* * Resolve all endpoint addresses ! */ - buf = usbd_temp_get_device_desc(udev); - uts->err = usbd_hw_ep_resolve(udev, buf); + buf = usb2_temp_get_device_desc(udev); + uts->err = usb2_hw_ep_resolve(udev, buf); if (uts->err) { - PRINTFN(-1, ("Could not resolve endpoints for " + DPRINTF(-1, "Could not resolve endpoints for " "Device Descriptor, error = %s\n", - usbd_errstr(uts->err))); + usb2_errstr(uts->err)); goto error; } for (n = 0;; n++) { - buf = usbd_temp_get_config_desc(udev, NULL, n); + buf = usb2_temp_get_config_desc(udev, NULL, n); if (buf == NULL) { break; } - uts->err = usbd_hw_ep_resolve(udev, buf); + uts->err = usb2_hw_ep_resolve(udev, buf); if (uts->err) { - PRINTFN(-1, ("Could not resolve endpoints for " + DPRINTF(-1, "Could not resolve endpoints for " "Config Descriptor %u, error = %s\n", n, - usbd_errstr(uts->err))); + usb2_errstr(uts->err)); goto error; } } return (uts->err); error: - usbd_temp_unsetup(udev); + usb2_temp_unsetup(udev); return (uts->err); } /*------------------------------------------------------------------------* - * usbd_temp_unsetup + * usb2_temp_unsetup * * This function frees any memory associated with the currently * setup template, if any. *------------------------------------------------------------------------*/ -void -usbd_temp_unsetup(struct usbd_device *udev) +static void +usb2_temp_unsetup(struct usb2_device *udev) { - if (udev->usb_template_ptr) { + if (udev->usb2_template_ptr) { + + free(udev->usb2_template_ptr, M_USB); + + udev->usb2_template_ptr = NULL; + } + return; +} - free(udev->usb_template_ptr, M_USB); +static usb2_error_t +usb2_temp_setup_by_index(struct usb2_device *udev, uint16_t index) +{ + usb2_error_t err; - udev->usb_template_ptr = NULL; + switch (index) { + case 0: + err = usb2_temp_setup(udev, &usb2_template_msc); + break; + case 1: + err = usb2_temp_setup(udev, &usb2_template_cdce); + break; + case 2: + err = usb2_temp_setup(udev, &usb2_template_mtp); + break; + default: + return (USB_ERR_INVAL); } + + return (err); +} + +static void +usb2_temp_init(void *arg) >>> TRUNCATED FOR MAIL (1000 lines) <<<