Re: Failing controls transfers in VMware

2009-07-17 Thread Juergen Lock
In article 200907012107.48635.hsela...@c2i.net you write:
On Wednesday 01 July 2009 20:31:41 Markus Dolze wrote:
 Hans Petter Selasky wrote:
  On Tuesday 30 June 2009 22:11:47 Markus Dolze wrote:
  Markus Dolze wrote:
  To repeat run the attached program:
 
 1. Fill in some vendor / product ID of a device detected as ugen
  device 2. Compile and run the code (devel/libusb must be installed).
 
  You should use this function when reading strings:
 
  int usb_get_string_simple(usb_dev_handle * dev, int index, char *buf,
  size_t buflen);

 Yes, this is more easy, but I crafted the control transfers myself to
 show that actually the control transfer is failing.

Sometimes you have to pass the exact length of the string, and not the maximum 
length when doing the control request.

Just though I'd mention...  hplip (ports/print/hplip, actually I am testing
the port for the new version that was posted on -ports) works around a
similar issue (string fetching failing on first try) by simply retrying
the same transfer after a 2s delay.  (And I just got that working here on
7-stable by checking for a return value of -EIO in addition to 0 that was
in the original code and made my printer not work.)

 Here is that code (with the patch), see also:
http://lists.freebsd.org/pipermail/freebsd-ports/2009-July/055840.html

..
/* This function is similar to usb_get_string_simple, but it handles zero 
returns. */
static int get_string_descriptor(usb_dev_handle *dev, int index, char *buf, 
size_t buflen)
{
   char tbuf[255];   /* Some devices choke on size  255 */
   int ret, si, di, cnt=5;

   while (cnt--)
   {
  ret = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, 
(USB_DT_STRING  8) + index, 
   0x409, tbuf, sizeof(tbuf), LIBUSB_CONTROL_REQ_TIMEOUT);
  if (ret==0 || ret == -EIO)
  {
 /* This retry is necessary for lj1000 and lj1005. des 12/12/07
 Also HP Photosmart 42xx seems to suffer transient errors with serial 
id */
 BUG(get_string_descriptor error result %d, retrying in 2 secs..., 
ret);
 sleep(2);
 continue;
  }
  break;
   }

   if (ret  0)
   {
  BUG(unable get_string_descriptor %d: %m\n, ret); 
  return ret;
   }

   if (tbuf[1] != USB_DT_STRING)
   {
  BUG(invalid get_string_descriptor tag act=%d exp=%d\n, tbuf[1], 
USB_DT_STRING); 
  return -EIO;
   }

   if (tbuf[0]  ret)
   {
  BUG(invalid get_string_descriptor size act=%d exp=%d\n, tbuf[0], ret); 
  return -EFBIG;
   }

   for (di = 0, si = 2; si  tbuf[0]; si += 2)
   {
  if (di = (buflen - 1))
 break;

  if (tbuf[si + 1])   /* high byte */
 buf[di++] = '0';
  else
 buf[di++] = tbuf[si];
   }

   buf[di] = 0;

   return di;
}
..

 Btw, something else since that question also came up on -ports, does the
new stack support accessing e.g. ulpt devices as ugen too?  I know the old
one didn't, which is why you have to take out ulpt (and umass depending
on the particular printer) out of the kernel when you want to use hplip,
which you don't have to do e.g. on (sorry :) Linux...  (As mentioned in
that other post testing head here is difficult since it has ata issues
on this box. ):

 Thanx,
Juergen
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-07-13 Thread Markus Dolze

Hans Petter Selasky wrote:
 On Wednesday 01 July 2009 20:26:35 Markus Dolze wrote:
 Hans Petter Selasky wrote:
 On Tuesday 30 June 2009 22:04:34 Markus Dolze 
 freebsd8# usbconfig -u 0 -a 3 dump_string 1
 STRING_0x01 = www.fischl.de
 freebsd8# usbconfig -u 0 -a 3 dump_string 2
 STRING_0x02 = USBasp

 I already took a problem with the usb stack into account. The stack used
 is V-USB formerly known as AVR-USB
 (http://www.obdev.at/products/vusb/index.html). As written previously I
 tried several different devices including GPS and smartcard terminals
 with the same bad result.

 It may also be a problem with VMware's virtual devices or host drivers.

 
 Try without VM-ware, and see if the result is the same.
 
 --HPS
 

I had the time to set up -current (2009-06) on real hardware. Here are
the results:

Running on real hardware (I used do_request directly):

r...@mireille:~# usbconfig -u 2 -a 2
ugen2.2: USBasp www.fischl.de at usbus2, cfg=0 md=HOST spd=LOW
(1.5Mbps) pwr=ON
r...@mireille:~# usbconfig -u 2 -a 2 do_request 0x80 0x06 0x0301 0x0409 256
REQUEST = 0x1c 0x03 0x77 0x00 0x77 0x00 0x77 0x00 0x2e 0x00 0x66 0x00
0x69 0x00 0x73 0x00 0x63 0x00 0x68 0x00 0x6c 0x00 0x2e 0x00 0x64 0x00
0x65 0x00www.fischl.de

Compare this to the results from VMware:

freebsd8# usbconfig -u 0 -a 3
ugen0.3: USBasp www.fischl.de at usbus0, cfg=0 md=HOST spd=FULL
(12Mbps) pwr=ON
freebsd8# usbconfig -u 0 -a 3 do_request 0x80 0x06 0x0301 0x0409 256
REQUEST = 0x2e 0x00 0x66 0x00 0x69 0x00 0x73 0x00 0x63 0x00 0x68 0x00
0x6c 0x00 0x2e 0x00 0x64 0x00 0x65 0x00.fischl.de


Within VMware the first bytes from the response are missing! The only
difference I can see is the speed being LOW vs FULL (where LOW is correct).

I give up on this. And remember that VMware and FreeBSD don't play well
with USB devices.

Thanks so far!

Markus
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-07-01 Thread Hans Petter Selasky
On Tuesday 30 June 2009 22:04:34 Markus Dolze wrote:
 Hans Petter Selasky wrote:
  On Tuesday 30 June 2009 20:46:22 Markus Dolze wrote:
  Hello,
 
  for several days I ways trying to get devel/avrdude to work with an
  USBasp compatibel device (www.ullihome.de) on FreeBSD 7.2 running as a
  guest in VMware Workstation 6.5.2.
 
 ...
 
  FYI: Not a solution maybe, but 8-current has a new USB stack.
 
  Works with AVRDUDE.
 
  --HPS

 Hi,

 yes, I know. Therefore I already tried and the result is even worse.
 Output from the test program:

 freebsd8# ./main
 ./main: Command not found.
 freebsd8# ./test
 Found AVR-USB device
 USB_control_msg result: 20
 2e 00
 Found device from vendor: (null)
 USB_control_msg result: 6
 61 00
 Found device: (null)

 freebsd8# uname -v
 FreeBSD 8.0-CURRENT-200906 #0: Mon Jun 29 23:38:52 CEST 2009
 r...@freebsd8.intra.mdolze.de:/usr/obj/usr/src/sys/CUSTOM

 It does not even get string descriptors back (second byte of buffer is
 0x00).


 Avrdude doesn't work either:

 freebsd8# avrdude -c usbasp -p atmega8 -U eeprom:r:-:h
 avrdude: error: usbasp_transmit: Unknown error


That's maybe a bug in the firmware in your USB device! Can you try reading the 
strings using usbconfig -u XXX -a YYY dump_string ZZZ

What does usbconfig output?

--HPS

___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-07-01 Thread Hans Petter Selasky
On Tuesday 30 June 2009 22:11:47 Markus Dolze wrote:
 Markus Dolze wrote:
  To repeat run the attached program:
 
 1. Fill in some vendor / product ID of a device detected as ugen
  device 2. Compile and run the code (devel/libusb must be installed).
 

You should use this function when reading strings:

int usb_get_string_simple(usb_dev_handle * dev, int index, char *buf, 
size_t buflen);

--HPS


___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-07-01 Thread Markus Dolze


Hans Petter Selasky wrote:
 On Tuesday 30 June 2009 22:04:34 Markus Dolze wrote:
 Hans Petter Selasky wrote:
 On Tuesday 30 June 2009 20:46:22 Markus Dolze wrote:
 Hello,

 for several days I ways trying to get devel/avrdude to work with an
 USBasp compatibel device (www.ullihome.de) on FreeBSD 7.2 running as a
 guest in VMware Workstation 6.5.2.

 ...
 FYI: Not a solution maybe, but 8-current has a new USB stack.

 Works with AVRDUDE.

 --HPS
 Hi,

 yes, I know. Therefore I already tried and the result is even worse.
 Output from the test program:

 freebsd8# ./main
 ./main: Command not found.
 freebsd8# ./test
 Found AVR-USB device
 USB_control_msg result: 20
 2e 00
 Found device from vendor: (null)
 USB_control_msg result: 6
 61 00
 Found device: (null)

 freebsd8# uname -v
 FreeBSD 8.0-CURRENT-200906 #0: Mon Jun 29 23:38:52 CEST 2009
 r...@freebsd8.intra.mdolze.de:/usr/obj/usr/src/sys/CUSTOM

 It does not even get string descriptors back (second byte of buffer is
 0x00).


 Avrdude doesn't work either:

 freebsd8# avrdude -c usbasp -p atmega8 -U eeprom:r:-:h
 avrdude: error: usbasp_transmit: Unknown error

 
 That's maybe a bug in the firmware in your USB device! Can you try reading 
 the 
 strings using usbconfig -u XXX -a YYY dump_string ZZZ
 
 What does usbconfig output?
 
 --HPS
 

Here's the output:

freebsd8# usbconfig -u 0 -a 3 dump_string 1
STRING_0x01 = www.fischl.de
freebsd8# usbconfig -u 0 -a 3 dump_string 2
STRING_0x02 = USBasp

I already took a problem with the usb stack into account. The stack used
is V-USB formerly known as AVR-USB
(http://www.obdev.at/products/vusb/index.html). As written previously I
tried several different devices including GPS and smartcard terminals
with the same bad result.

It may also be a problem with VMware's virtual devices or host drivers.

Thanks,
Markus


___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-07-01 Thread Markus Dolze
Hans Petter Selasky wrote:
 On Tuesday 30 June 2009 22:11:47 Markus Dolze wrote:
 Markus Dolze wrote:
 To repeat run the attached program:

1. Fill in some vendor / product ID of a device detected as ugen
 device 2. Compile and run the code (devel/libusb must be installed).

 
 You should use this function when reading strings:
 
 int usb_get_string_simple(usb_dev_handle * dev, int index, char *buf, 
 size_t buflen);
 

Yes, this is more easy, but I crafted the control transfers myself to
show that actually the control transfer is failing.

Libusb's usb_get_string_simple internally uses to control transfers to
read a string. The first one to get a list of supported languages and
the second one to actually retrieve the string. I found that the second
control transfer always errors out.

If I replace the usb_control_msg() in my test program with
usb_get_string_simple() I get:

r...@freebsd7:./test
Found AVR-USB device
USB_control_msg result: -5
Warning: cannot query manufacturer for device: error sending control
message: Input/output error
USB_control_msg result: -5
Warning: cannot query product: error sending control message:
Input/output error

Thanks,
Markus
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-07-01 Thread Hans Petter Selasky
On Wednesday 01 July 2009 20:31:41 Markus Dolze wrote:
 Hans Petter Selasky wrote:
  On Tuesday 30 June 2009 22:11:47 Markus Dolze wrote:
  Markus Dolze wrote:
  To repeat run the attached program:
 
 1. Fill in some vendor / product ID of a device detected as ugen
  device 2. Compile and run the code (devel/libusb must be installed).
 
  You should use this function when reading strings:
 
  int usb_get_string_simple(usb_dev_handle * dev, int index, char *buf,
  size_t buflen);

 Yes, this is more easy, but I crafted the control transfers myself to
 show that actually the control transfer is failing.

Sometimes you have to pass the exact length of the string, and not the maximum 
length when doing the control request.


 Libusb's usb_get_string_simple internally uses to control transfers to
 read a string. The first one to get a list of supported languages and
 the second one to actually retrieve the string. I found that the second
 control transfer always errors out.

 If I replace the usb_control_msg() in my test program with
 usb_get_string_simple() I get:

 r...@freebsd7:./test
 Found AVR-USB device
 USB_control_msg result: -5
 Warning: cannot query manufacturer for device: error sending control
 message: Input/output error
 USB_control_msg result: -5
 Warning: cannot query product: error sending control message:
 Input/output error

usbconfig is using the same function to dump the device string. Strange you 
get different results.

--HPS

___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-07-01 Thread Hans Petter Selasky
On Wednesday 01 July 2009 20:26:35 Markus Dolze wrote:
 Hans Petter Selasky wrote:
  On Tuesday 30 June 2009 22:04:34 Markus Dolze 
 freebsd8# usbconfig -u 0 -a 3 dump_string 1
 STRING_0x01 = www.fischl.de
 freebsd8# usbconfig -u 0 -a 3 dump_string 2
 STRING_0x02 = USBasp

 I already took a problem with the usb stack into account. The stack used
 is V-USB formerly known as AVR-USB
 (http://www.obdev.at/products/vusb/index.html). As written previously I
 tried several different devices including GPS and smartcard terminals
 with the same bad result.

 It may also be a problem with VMware's virtual devices or host drivers.


Try without VM-ware, and see if the result is the same.

--HPS

___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-06-30 Thread Markus Dolze
Hans Petter Selasky wrote:
 On Tuesday 30 June 2009 20:46:22 Markus Dolze wrote:
 Hello,

 for several days I ways trying to get devel/avrdude to work with an
 USBasp compatibel device (www.ullihome.de) on FreeBSD 7.2 running as a
 guest in VMware Workstation 6.5.2.

...
 
 FYI: Not a solution maybe, but 8-current has a new USB stack.
 
 Works with AVRDUDE.
 
 --HPS
 

Hi,

yes, I know. Therefore I already tried and the result is even worse.
Output from the test program:

freebsd8# ./main
./main: Command not found.
freebsd8# ./test
Found AVR-USB device
USB_control_msg result: 20
2e 00
Found device from vendor: (null)
USB_control_msg result: 6
61 00
Found device: (null)

freebsd8# uname -v
FreeBSD 8.0-CURRENT-200906 #0: Mon Jun 29 23:38:52 CEST 2009
r...@freebsd8.intra.mdolze.de:/usr/obj/usr/src/sys/CUSTOM

It does not even get string descriptors back (second byte of buffer is
0x00).


Avrdude doesn't work either:

freebsd8# avrdude -c usbasp -p atmega8 -U eeprom:r:-:h
avrdude: error: usbasp_transmit: Unknown error



Regards,
Markus
___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org


Re: Failing controls transfers in VMware

2009-06-30 Thread Markus Dolze
Markus Dolze wrote:
 To repeat run the attached program:

1. Fill in some vendor / product ID of a device detected as ugen device
2. Compile and run the code (devel/libusb must be installed).

 The result will look like this:

   
The mailing list didn't send the attachment. Here is the code, put
together from different example programs:

/*
 * A program to test USB control messages
 */

#include stdio.h
#include string.h
#include usb.h

#define USBASP_SHARED_VID   0x16C0
#define USBASP_SHARED_PID   0x05DC

#define TIMEOUT 5000
#define LANGID  0x0409  /* english */

char* usbStringToAscii(char *buffer, int len)
{
charbuf[256];
int i;

printf(%02x %02x\n, buffer[0], buffer[1]);

if(buffer[1] != USB_DT_STRING){
*buf = 0;
return 0;
}
if((unsigned char)buffer[0]  len)
len = (unsigned char)buffer[0];
len /= 2;
/* lossy conversion to ISO Latin1: */
for(i=1;ilen;i++){
if(i  sizeof(buf))  /* destination buffer overflow */
break;
buf[i-1] = buffer[2 * i];
if(buffer[2 * i + 1] != 0)  /* outside of ISO Latin1 range */
buf[i-1] = '?';
}
buf[i-1] = 0;
return strdup(buf);
}


int main(int argc, char *argv[])
{
struct usb_bus  *bus;
struct usb_device   *dev;
usb_dev_handle  *handle = NULL;
charstring[255];
int len;

usb_init();
usb_find_busses();
usb_find_devices();
for(bus = usb_get_busses(); bus; bus = bus-next) {
for(dev = bus-devices; dev; dev = dev-next) {
if((dev-descriptor.idVendor == USBASP_SHARED_VID 
   dev-descriptor.idProduct == USBASP_SHARED_PID) {
printf(Found AVR-USB device\n);
   
handle = usb_open(dev);
if(!handle) {
printf(Warning: cannot open USB device: %s\n,
usb_strerror());
continue;
}

memset(string, 0, sizeof(string));
len = usb_control_msg(handle, USB_ENDPOINT_IN,
USB_REQ_GET_DESCRIPTOR,
(USB_DT_STRING  8) +
dev-descriptor.iManufacturer, LANGID, string,
sizeof(string), TIMEOUT);
printf(USB_control_msg result: %d\n, len);
if(len  0)
printf(Warning: cannot query manufacturer for
device: %s\n,
usb_strerror());
else
printf(Found device from vendor: %s\n,
usbStringToAscii(string, len));
   
memset(string, 0, sizeof(string));
len = usb_control_msg(handle, USB_ENDPOINT_IN,
USB_REQ_GET_DESCRIPTOR,
(USB_DT_STRING  8) + dev-descriptor.iProduct,
LANGID, string,
sizeof(string), TIMEOUT);
printf(USB_control_msg result: %d\n, len);
if(len  0)
printf(Warning: cannot query product: %s\n,
usb_strerror());
else
printf(Found device: %s\n,
usbStringToAscii(string, len));
   
usb_close(handle);
handle = NULL;
}
}
}

return 0;
}

___
freebsd-usb@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-usb
To unsubscribe, send any mail to freebsd-usb-unsubscr...@freebsd.org