Skip to main content


List/Identify Your USB Devices With "libusb20"

If you write a program that handles a USB device, you better let your program identify that device, and find it’s logical file name first.
If your USB version is 2.0, don’t use the functions in “usb.h” - they are obsolete. From the function and structures found in there, you’ll see that the function that get the device info loads all the USB hierarchy into the memory. Besides, it doesn’t work.Use “libusb20” instead.
Following is a little program that lists USB devices:#include <stdio.h> #include <libusb20.h> #include <libusb20_desc.h> int main(int argc, char *argv[]){ struct libusb20_backend *backend = libusb20_be_alloc_default(); struct libusb20_device *cur_dev=NULL, *next_dev; struct LIBUSB20_DEVICE_DESC_DECODED *desc; while(1) { next_dev = libusb20_be_device_foreach(backend, cur_dev); cur_dev=next_dev; if (cur_dev == NULL) break; desc = libusb20_dev_get_device_desc(cur_dev); printf("Vendo…
Recent posts

The FreeBSD Sources

I haven’t finished the first challenge, yet. The camera does not send pictures, though I see that URB’s (USB Request Buffers) are sent to the device. The function that submits the URB is called usb_submit_urb; it is found in ‘linux_usb.c’, it calls a function named usb_submit_urb_sub, which in turn calls libusb20_tr_start. The last function is not provided within the sources of webcamd. It belongs to the libusb20 library.
I’d asked on the IRC channel ‘’ where I can find the sources of that library, and received in response the link
I still don’t find there assembly commands like in and out used for communications with hardware devices. The source file is a part of a big project named FreeBSD. It is on GitHub, and I can use the search box on the top of the page to run recursive greps.
I guess that the first thing I search will be the string ‘USB_FS_START’ because in the function 'ugen20_tr_su…

The Web Camera Challenge - Debug Info

I now have a binary file named ‘webcamd’ in ~/myPorts/webcamd-, the directory to which I’ve extracted the tarball. When I run ./webcamd, I get a list of available devices, including the line:webcamd [-d ugen4.4] -N Vimicro-Vimicro-USB-2-0-PC-Camera-Venus -S unknown -M 0Now, I switch to the root account using su -m, to pass the current environment variable - including the current working directory - to ‘root’.
Before I start the daemon from the command line I should stop the daemon that is already running by typing the command:service webcamd stopSo I run the command :./webcamd -N Vimicro-Vimicro-USB-2-0-PC-Camera-Venus-S unknown -M0and see the output:Hello!11 Linux video capture interface: v2.00 b2c2-flexcop: B2C2 FlexcopII/II(b)/III digital TV receiver chip loaded successfully USB Video Class driver (1.1.1) cpia2: V4L-Driver for Vision CPiA2 based cameras v3.0.1 pvrusb2: V4L in-tree version:Hauppauge WinTV-PVR-USB2 MPEG2 Encoder/Tuner pvrusb2: Debug mask is31 (0x1f) USBVisi…

The Web Camera Challenge - Patches

The compilation and link discussed in the previous post succeeded after I’d edited a bash script, but only once. The second time, I got the errormedia_tree/drivers/media/i2c/tvp5150.c:1358:2: error: #endif without #if#endif ^This happened because of patches(diff files) had been applied twice.
So, in my work directory, named ~/myPorts/webcamd-‘, I’ve created a script file to get the original ones.
The script looks as follows:#!/usr/bin/env bashif [ ! -e /tmp/webcamd- ] then (cd /tmp && tar -xzf ~/Downloads/webcamd-\(1\).tar.bz2) fifor file in patches/*.diff do base=`basename $file .diff` targ_arr=`find . -name $base` for targ in$targ_arrdo src=/tmp/webcamd-$targ cp $src$targdonedoneThen I ran my script that invokes the make command.
Now, having commented out the commands that patch files, I can create the binary webcamd time and time again.
BTW, the tarball also exists in /usr/ports/distfiles at least after you install the …

The Web Camera Challenge - Compile & Link

So, I’ve decided that I want to debug the daemon ‘webcamd’,. To do this, I have to get the source code.
If you wanted to install software from the ports, you would usually go to the port directory and runmake install cleanThis is not enough if you want to debug. There are 2 targets to be made first:
1. fetch - to check if the lates tarball is in ‘/usr/ports/distfiles’
2. extract - to extract the tarball to <port-dir>/work
So, to be sure I know how to compile, I had made the targets and added some ‘printf’ command before running make reinstall
Then I stopped the running daemon, using:service webcamd stopandwebcamd ...This only worked once, so I consulted the porter’s guide, and read there about patching. Well, according to section 4.3 I should extract the compressed tar(tape archive) file to a private directory, but I thought working directly from the port’s sub-tree would be more convenient, because the port directory has a Makefile.
Since it has not worked, I tried patchi…

The Web Camera Challenge - Ports And Tarballs

I have a little ֵMicrosoft LifeCam VX-800 web camera attached to my computer. It works well on Linux, but I’ve switched to FreeBSD where it does not. To make it work I need a driver. In this case the driver is a daemon named ‘webcamd’, and event-driven process that runs in the background. The Web Camera Daemon is supposed to communicate with a kernel object named ‘cuse’ or ‘cuse4bsd’ to create a socket named ‘/dev/video0’ so other application (the web-browser, VLC, etc) can grab a photo or a video.
I want to check why this socket is not created.
To debug a software product, you better refer to the port from which the product can be installed because installing from ports often requires downloading of the source code from which the product is built and installed.
If you read the Porter’s Guide , you can learn that sites from which the source code(tar ball) is to be fetch are held by the environment variable ‘MASTER_SITES’, and that the name of the tarball to download is a combinat…