| 
      
      
      From: Stephan M. <ste...@we...> - 2006-07-20 18:04:50
       | 
| 
I applied your patch, but in driver_api.h I moved the 'recipient' member 
to the end of the structure so that the new dll remains downward 
compatible and works with older driver versions.
Thanks,
Stephan
> This patch adds recipient (device, interface, endpoint) support to
> LIBUSB_IOCTL_{GET,SET}_DESCRIPTOR and makes use of it from
> usb_control_message(). The implementation mimics 
> LIBUSB_IOCTL_GET_STATUS, etc.
> 
> This change is necessary for certain HID devices that require report
> descriptor accesses to follow the letter of the spec. Such requests are
> supposed to be addressed as standard (not class or vendor) but with an
> interface recipient (not device). Previously, usb_control_message()
> addressed all standard descriptor requests to the device. This works for
> the vast majority of devices, but I have one (APC BackUPS ES 350) that
> chokes.
> 
> My particular application only needs support for GET, but I changed SET
> accordingly for the sake of completeness.
> 
> --Adam
> 
> 
> diff -u -r1.46 windows.c
> --- src/windows.c	17 Jul 2006 19:31:23 -0000	1.46
> +++ src/windows.c	19 Jul 2006 02:00:40 -0000
> @@ -688,14 +688,16 @@
>            code = LIBUSB_IOCTL_SET_FEATURE;
>            break;
>  
> -        case USB_REQ_GET_DESCRIPTOR:     	  
> +        case USB_REQ_GET_DESCRIPTOR:
> +          req.descriptor.recipient = requesttype & 0x1F;
>            req.descriptor.type = (value >> 8) & 0xFF;
>            req.descriptor.index = value & 0xFF;
>            req.descriptor.language_id = index;
>            code = LIBUSB_IOCTL_GET_DESCRIPTOR;
>            break;
> -	  
> +
>          case USB_REQ_SET_DESCRIPTOR:
> +          req.descriptor.recipient = requesttype & 0x1F;
>            req.descriptor.type = (value >> 8) & 0xFF;
>            req.descriptor.index = value & 0xFF;
>            req.descriptor.language_id = index;
> @@ -843,6 +845,7 @@
>  
>        /* retrieve device descriptor */
>        req.descriptor.type = USB_DT_DEVICE;
> +      req.descriptor.recipient = USB_RECIP_DEVICE;
>        req.descriptor.index = 0;
>        req.descriptor.language_id = 0;
>        req.timeout = LIBUSB_DEFAULT_TIMEOUT;
> diff -u -r1.5 driver_api.h
> --- src/driver/driver_api.h	6 Apr 2006 17:17:31 -0000	1.5
> +++ src/driver/driver_api.h	19 Jul 2006 02:00:40 -0000
> @@ -146,6 +146,7 @@
>      } status;
>      struct
>      {
> +      unsigned int recipient;
>        unsigned int type;
>        unsigned int index;
>        unsigned int language_id;
> diff -u -r1.7 get_descriptor.c
> --- src/driver/get_descriptor.c	4 Jul 2006 18:11:17 -0000	1.7
> +++ src/driver/get_descriptor.c	19 Jul 2006 02:00:41 -0000
> @@ -22,7 +22,7 @@
>  
>  
>  NTSTATUS get_descriptor(libusb_device_t *dev,
> -                        void *buffer, int size, int type, 
> +                        void *buffer, int size, int type, int recipient,
>                          int index, int language_id, int *received, int timeout)
>  {
>    NTSTATUS status = STATUS_SUCCESS;
> @@ -31,6 +31,7 @@
>    DEBUG_PRINT_NL();
>    DEBUG_MESSAGE("get_descriptor(): buffer size %d", size);
>    DEBUG_MESSAGE("get_descriptor(): type %04d", type);
> +  DEBUG_MESSAGE("get_descriptor(): recipient %04d", recipient);
>    DEBUG_MESSAGE("get_descriptor(): index %04d", index);
>    DEBUG_MESSAGE("get_descriptor(): language id %04d", language_id);
>    DEBUG_MESSAGE("get_descriptor(): timeout %d", timeout);
> @@ -38,7 +39,22 @@
>  
>    memset(&urb, 0, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
>  
> -  urb.UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE;
> +  switch(recipient)
> +    {
> +    case USB_RECIP_DEVICE:
> +      urb.UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE;
> +      break;
> +    case USB_RECIP_INTERFACE:
> +      urb.UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE;
> +      break;
> +    case USB_RECIP_ENDPOINT:
> +      urb.UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT;
> +      break;
> +    default:
> +      DEBUG_ERROR("get_descriptor(): invalid recipient");
> +      return STATUS_INVALID_PARAMETER;
> +    }
> +  
>    urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
>    urb.UrbControlDescriptorRequest.TransferBufferLength = size;
>    urb.UrbControlDescriptorRequest.TransferBuffer = buffer;
> @@ -46,7 +62,6 @@
>    urb.UrbControlDescriptorRequest.Index = (UCHAR)index;
>    urb.UrbControlDescriptorRequest.LanguageId = (USHORT)language_id;
>    
> -
>    status = call_usbd(dev, &urb, IOCTL_INTERNAL_USB_SUBMIT_URB, timeout);
>  
>        
> @@ -78,6 +93,7 @@
>  
>    if(!NT_SUCCESS(get_descriptor(dev, desc, desc_size, 
>                            USB_CONFIGURATION_DESCRIPTOR_TYPE,
> +                          USB_RECIP_DEVICE,
>                            configuration - 1,
>                            0, size, LIBUSB_DEFAULT_TIMEOUT)))
>      {
> @@ -95,6 +111,7 @@
>  
>    if(!NT_SUCCESS(get_descriptor(dev, desc, desc_size,
>                            USB_CONFIGURATION_DESCRIPTOR_TYPE,
> +                          USB_RECIP_DEVICE,
>                            configuration - 1,
>                            0, size, LIBUSB_DEFAULT_TIMEOUT)))
>      {
> diff -u -r1.13 ioctl.c
> --- src/driver/ioctl.c	9 Mar 2006 18:47:47 -0000	1.13
> +++ src/driver/ioctl.c	19 Jul 2006 02:00:41 -0000
> @@ -150,6 +150,7 @@
>                                input_buffer + sizeof(libusb_request), 
>                                input_buffer_length - sizeof(libusb_request), 
>                                request->descriptor.type,
> +                              request->descriptor.recipient,
>                                request->descriptor.index,
>                                request->descriptor.language_id, 
>                                &ret, request->timeout);
> @@ -169,6 +170,7 @@
>        status = get_descriptor(dev, output_buffer, 
>                                output_buffer_length,
>                                request->descriptor.type,
> +                              request->descriptor.recipient,
>                                request->descriptor.index,
>                                request->descriptor.language_id, 
>                                &ret, request->timeout);
> diff -u -r1.28 libusb_driver.h
> --- src/driver/libusb_driver.h	17 Jul 2006 19:31:22 -0000	1.28
> +++ src/driver/libusb_driver.h	19 Jul 2006 02:00:41 -0000
> @@ -190,11 +190,11 @@
>                      int index, char *status, int *ret, int timeout);
>  NTSTATUS set_descriptor(libusb_device_t *dev,
>                          void *buffer, int size, 
> -                        int type, int index, int language_id, 
> +                        int type, int recipient, int index, int language_id, 
>                          int *sent, int timeout);
>  NTSTATUS get_descriptor(libusb_device_t *dev, void *buffer, int size, 
> -                        int type, int index, int language_id, int *received, 
> -                        int timeout);
> +                        int type, int recipient, int index, int language_id,
> +                        int *received, int timeout);
>  USB_CONFIGURATION_DESCRIPTOR *
>  get_config_descriptor(libusb_device_t *dev, int configuration, int *size);
>  
> diff -u -r1.13 set_configuration.c
> --- src/driver/set_configuration.c	4 Jul 2006 18:11:17 -0000	1.13
> +++ src/driver/set_configuration.c	19 Jul 2006 02:00:41 -0000
> @@ -71,6 +71,7 @@
>    status = get_descriptor(dev, &device_descriptor,
>                            sizeof(USB_DEVICE_DESCRIPTOR), 
>                            USB_DEVICE_DESCRIPTOR_TYPE,
> +                          USB_RECIP_DEVICE,
>                            0, 0, &desc_size, LIBUSB_DEFAULT_TIMEOUT);  
>  
>    if(!NT_SUCCESS(status))
> diff -u -r1.6 set_descriptor.c
> --- src/driver/set_descriptor.c	9 Apr 2006 09:12:21 -0000	1.6
> +++ src/driver/set_descriptor.c	19 Jul 2006 02:00:41 -0000
> @@ -22,7 +22,7 @@
>  
>  
>  NTSTATUS set_descriptor(libusb_device_t *dev,
> -                        void *buffer, int size, int type, 
> +                        void *buffer, int size, int type, int recipient,
>                          int index, int language_id, int *sent, int timeout)
>  {
>    NTSTATUS status = STATUS_SUCCESS;
> @@ -31,13 +31,29 @@
>    DEBUG_PRINT_NL();
>    DEBUG_MESSAGE("set_descriptor(): buffer size %d", size);
>    DEBUG_MESSAGE("set_descriptor(): type %04d", type);
> +  DEBUG_MESSAGE("set_descriptor(): recipient %04d", recipient);
>    DEBUG_MESSAGE("set_descriptor(): index %04d", index);
>    DEBUG_MESSAGE("set_descriptor(): language id %04d", language_id);
>    DEBUG_MESSAGE("set_descriptor(): timeout %d", timeout);
>  
>    memset(&urb, 0, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
>  
> -  urb.UrbHeader.Function =  URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE;
> +  switch(recipient)
> +    {
> +    case USB_RECIP_DEVICE:
> +      urb.UrbHeader.Function = URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE;
> +      break;
> +    case USB_RECIP_INTERFACE:
> +      urb.UrbHeader.Function = URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE;
> +      break;
> +    case USB_RECIP_ENDPOINT:
> +      urb.UrbHeader.Function = URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT;
> +      break;
> +    default:
> +      DEBUG_ERROR("set_descriptor(): invalid recipient");
> +      return STATUS_INVALID_PARAMETER;
> +    }
> +  
>    urb.UrbHeader.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
>    urb.UrbControlDescriptorRequest.TransferBufferLength = size;
>    urb.UrbControlDescriptorRequest.TransferBuffer = buffer;
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Libusb-win32-devel mailing list
> Lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
_____________________________________________________________________
Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
http://smartsurfer.web.de/?mc=100071&distributionid=000000000071
 | 
| 
      
      
      From: Stephan M. <ste...@we...> - 2006-07-21 16:54:58
       | 
| 
The first change was intended, but not the second one!
I'll reverse it.
Thanks for the hint,
Stephan
> On Thu, Jul 20, 2006 at 08:04:41PM +0200, Stephan Meyer wrote:
> >=20
> > I applied your patch, but in driver=5Fapi.h I moved the 'recipient' memb=
er=20
> > to the end of the structure so that the new dll remains downward=20
> > compatible and works with older driver versions.
>=20
> It looks like a couple unintentional changes might have crept into your
> commit of windows.c. Just in case, I've highlighted them here...
>=20
> Thanks!
> --Adam
>=20
> > diff -u -r1.47 -r1.48
> > --- windows.c	18 Jul 2006 20:13:40 -0000	1.47
> > +++ windows.c	20 Jul 2006 17:58:57 -0000	1.48
> > @@ -161,18 +161,18 @@
> >      }
> >   =20
> >    /* now, retrieve the device's current configuration, except from hu=
bs */
> > -  if(dev->device->config && dev->device->config->interface
> > -     && dev->device->config->interface[0].altsetting
> > -     && dev->device->config->interface[0].altsetting[0].bInterfaceCla=
ss=20
> > -     !=3D USB=5FCLASS=5FHUB)
> > -    {
> > -      config =3D usb=5Fget=5Fconfiguration(dev);
> > +/*   if(dev->device->config && dev->device->config->interface */
> > +/*      && dev->device->config->interface[0].altsetting */
> > +/*      && dev->device->config->interface[0].altsetting[0].bInterface=
Class  */
> > +/*      !=3D USB=5FCLASS=5FHUB) */
> > +/*     { */
> > +/*       config =3D usb=5Fget=5Fconfiguration(dev); */
> >       =20
> > -      if(config > 0)
> > -        {
> > -          dev->config =3D config;
> > -        }
> > -    }
> > +/*       if(config > 0) */
> > +/*         { */
> > +/*           dev->config =3D config; */
> > +/*         } */
> > +/*     } */
> > =20
> >    return 0;
> >  }
> > @@ -768,7 +770,7 @@
> >      {
> >        usb=5Ferror("usb=5Fcontrol=5Fmsg: sending control message failed, "
> >                  "win error: %s", usb=5Fwin=5Ferror=5Fto=5Fstring());
> > -      return -usb=5Fwin=5Ferror=5Fto=5Ferrno();
> > +      ret =3D -usb=5Fwin=5Ferror=5Fto=5Ferrno();
> >      }
> > =20
> >    /* out request=3F */
>=20
> ------------------------------------------------------------------------=
-
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share =
your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php=3Fpage=3Djoin.php&p=3Dsourceforge&CID=3DDEVDE=
V
> =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F
> Libusb-win32-devel mailing list
> Lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel
=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=
Erweitern Sie FreeMail zu einem noch leistungsst=E4rkeren E-Mail-Postfach!	=09
Mehr Infos unter http://freemail.web.de/home/landingpad/=3Fmc=3D021131
 | 
| 
      
      
      From: Adam K. <akr...@ro...> - 2006-07-20 18:49:48
       | 
| On Thu, Jul 20, 2006 at 08:04:41PM +0200, Stephan Meyer wrote: > > I applied your patch, but in driver_api.h I moved the 'recipient' member > to the end of the structure so that the new dll remains downward > compatible and works with older driver versions. Good point. Thanks! --Adam | 
| 
      
      
      From: Adam K. <akr...@ro...> - 2006-07-20 23:24:43
       | 
| On Thu, Jul 20, 2006 at 08:04:41PM +0200, Stephan Meyer wrote:
> 
> I applied your patch, but in driver_api.h I moved the 'recipient' member 
> to the end of the structure so that the new dll remains downward 
> compatible and works with older driver versions.
It looks like a couple unintentional changes might have crept into your
commit of windows.c. Just in case, I've highlighted them here...
Thanks!
--Adam
> diff -u -r1.47 -r1.48
> --- windows.c	18 Jul 2006 20:13:40 -0000	1.47
> +++ windows.c	20 Jul 2006 17:58:57 -0000	1.48
> @@ -161,18 +161,18 @@
>      }
>    
>    /* now, retrieve the device's current configuration, except from hubs */
> -  if(dev->device->config && dev->device->config->interface
> -     && dev->device->config->interface[0].altsetting
> -     && dev->device->config->interface[0].altsetting[0].bInterfaceClass 
> -     != USB_CLASS_HUB)
> -    {
> -      config = usb_get_configuration(dev);
> +/*   if(dev->device->config && dev->device->config->interface */
> +/*      && dev->device->config->interface[0].altsetting */
> +/*      && dev->device->config->interface[0].altsetting[0].bInterfaceClass  */
> +/*      != USB_CLASS_HUB) */
> +/*     { */
> +/*       config = usb_get_configuration(dev); */
>        
> -      if(config > 0)
> -        {
> -          dev->config = config;
> -        }
> -    }
> +/*       if(config > 0) */
> +/*         { */
> +/*           dev->config = config; */
> +/*         } */
> +/*     } */
>  
>    return 0;
>  }
> @@ -768,7 +770,7 @@
>      {
>        usb_error("usb_control_msg: sending control message failed, "
>                  "win error: %s", usb_win_error_to_string());
> -      return -usb_win_error_to_errno();
> +      ret = -usb_win_error_to_errno();
>      }
>  
>    /* out request? */
 |