[PATCH] Fix for USB ugen panics

Jay Cornwall jay at evilrealms.net
Wed Jan 7 18:32:14 PST 2004


Martin wrote:

> Good news: the panic is gone.

:D

But I managed to test this with my Speedtouch USB modem, so no surprises there. ;)

> I'm _trying_ to write a small capture program for my webcam
> (Creative Videoblaster Webcam Go). I'm not very successful.
> I managed to get a stream of black(?) pixels from my webcam,
> using the so-called isochronous transfer mode. The program is
> called "camtest".
> 
> I was doing some experiments with ugen to check out why only
> black pixels are coming from the interface and so I tried out
> a sysctl "USB_SET_CONFIG". That caused a panic instantly.
> I removed all unnecessary code around the sysctl-call to
> submit a PR and called the program "camtest-panic".

Yep, the panic was caused by ugen not expecting to be asked to USB_SET_CONFIG 
a value of zero.

> - you can start "camtest" as many times as you want after
> fresh reboot and the isochronous transfer can be established
> successfully

Correct.

> - after starting "camtest-panic", first time there is no error

At this point, you've called USB_SET_CONFIG with a value of 0. This value is 
reserved as a way to put the device into the "unconfigured" state. From here 
(as I was discussing with Bernd on freebsd-hackers@), the only way to leave 
the state is to either reset the USB hub or detach/reattach the device.

> - after starting "camtest-panic" only one time, you will not
> get past the sysctl-call "USB_SET_ALTINTERFACE" in "camtest",
> it stops with the message (from perror): "Invalid argument"

Correct, according to the USB spec interfaces are unavailable when the device 
is in the "unconfigured" state.

> - after starting "camtest-panic" first time, you get an error
> when starting it (e.a. "camtest-panic") more times after the 
> sysctl-call "USB_SET_CONFIG", it stops with the message
> (perror): "Input/output error"

The device is in configuration zero at this point. No further configuration 
changes can be made now, until the device has been put back into the 
"configured" state.

As discussed in the post to freebsd-hackers@, both I and Bernd think that 
USB_SET_CONFIG probably shouldn't let the user set configuration zero in case 
it happens accidentally. But I haven't disallowed this in the patch until I've 
got in touch with the USB stack developer, and confirmed that would be 
sensible behaviour.

> I hope you can see from my description that there is still
> something weird going on with ugen. I wish I could help, but
> I don't know much about USB and just started my first program.
> It just looks for me like there is something not being
> cleaned up correctly after the USB_SET_CONFIG-sysctl in 
> "camtest-panic".

I think you're on the right lines, but all that's going wrong is setting the 
device configuration to zero. You need to look up the technical specs for your 
USB webcam to see which configurations are available, and what interfaces and 
endpoints are available in each configuration.

If it says that configuration zero is an acceptable configuration, then I'm 
confused. :)

Certainly my USB modem lets you set configuration 1, and operates correctly in 
that configuration. As it only has one configuration, I can only presume USB 
devices generally start from configuration 1 onwards.

> Thanks for the patch,

Thanks for testing it. :)

-- 
Cheers,
Jay

http://www.evilrealms.net/ - Systems Administrator & Developer
http://www.imperial.ac.uk/ - 3rd year CS student


More information about the freebsd-current mailing list