# Writing userland driver for /dev/ugen UVC cam



## randomep (Jun 22, 2016)

Hi all,

For my purposes I need to write my own driver for a UVC webcam. The webcam is recognized as /dev/ugen.  What I want to know is simply can I control and stream with the webcam using just the read/write, open/close, and ioctl functions?  I do not want to use anyone else's driver, for my purpose I need to write my driver in userland. Is there some really beginner examples of how to do this? If it is possible?

thanks in advance!


----------



## SirDice (Jun 22, 2016)

FreeBSD Architecture Handbook: Part II. Device Drivers


----------



## tobik@ (Jun 22, 2016)

randomep said:


> For my purposes I need to write my own driver for a UVC webcam. The webcam is recognized as /dev/ugen. What I want to know is simply can I control and stream with the webcam using just the read/write, open/close, and ioctl functions? I do not want to use anyone else's driver, for my purpose I need to write my driver in userland. Is there some really beginner examples of how to do this? If it is possible?


It's possible. multimedia/webcamd does this.  It's a port of Linux' USB webcam drivers running in userspace using libusb(3) and cuse4bsd(3) by hselasky@.


----------



## randomep (Jun 22, 2016)

tobik said:


> It's possible. multimedia/webcamd does this.  It's a port of Linux' USB webcam drivers running in userspace using libusb(3) and cuse4bsd(3) by hselasky@.



Thanks for the reply. Yes I have seen the webcamd link.  I have several questions about it.  My first goal is to see what is required so I can do something similar, not to use webcamd.

1. I am a Linux user I don't have a FreeBSD and I cannot make sense of how to actually see the source code, followed the instructions on Linux and it didn't work well.
2. For my requirement I will not have access to libusb or cuse4bsd.  Do those functions in turn just use open/close, read/write, ioctls()? Or do they use some of their own kernel module code?  I just know that on the target system the device is /dev/ugen, and I need to know is open/close, read/write, ioctls() sufficient to get to the webcam?

thanks!


----------



## hselasky@ (Jul 9, 2016)

1) You can download all source code from the distfiles section.
2) You'll find the cuse manual page here.

Use libusb to access USB devices instead of /dev/ugenX.Y directly via IOCTLs. If your device is very simple you can read/write endpoint data using /dev/usb/X.Y.Z .


----------

