C Programming - Accessing USB Data / Driver Specifics - c

I am writing some simple test automation to access the USB port in Ubuntu, and determine driver specific details, devices that are connected, and operating mode (USB 2 , 3 , etc ...).
I have not done any development in this area, and was looking for advice on libraries / recommendations to accomplish this.
Thank you for you help!
Dan.

I've done this using libusb. You can get get started here. http://libusb.sourceforge.net/api-1.0/ If you're just looking at seeing various usb devices, it's pretty easy. Here are some examples that you can get up and running pretty quickly: http://www.dreamincode.net/forums/topic/148707-introduction-to-using-libusb-10/

I found the sourceforge info useful, but could not get the install to work in Ubuntu.
After some searching, I found Libusb and how to use its packages in Ubuntu
This appears to resolve my issue; plus interesting point about using usb.h instead of libusb.h to compile.
Thanks for all the input!
Dan

Related

libipq not supported in Ubuntu 12.04

I have the requirement of altering packets as a part of my University's research project and came across two libraries. which are libnetfilter_queue and libipq which is the deprecated version. libnetfilter_queue documentation is next to zero on packet alteration and the only good documentation I came across is done via libipq.
Thus, when I run my code I get the error passer: Unable to create netlink socket: Protocol not supported which I found out that is due to the fact that libipq is not supported in the new linux kernels.
My query is, is there a work around to make libipq work with Ubuntu 12.04 LTS or any reference to documentation or tutorials that would help implement packet alteration via libnetfilter_queue.
I was at this for some days and could not find solution. you help will be very much appreciated. :)
Thank you very much :)
P.S: the question is also posted over here ( https://askubuntu.com/questions/430234/libipq-not-supported-in-ubuntu-12-04-lts )
Once the ip_queue module is gone, then you can't use libipq, as it leverages that module directly; so no, there's no workaround unless you install an older kernel that still has the ip_queue module.
That said, you've mentioned absolutely nothing about what you've actually tried. If you start from a basic libnetfilter_queue example, when you're setting the verdict, you should be using nfq_set_verdict, passing in the data_len and buf parameters containing the swizzled packet data.

C or C++ programming with contikiOS on Arduino Due

What I need to do is to compile and run a program written in C/C++ on Arduino.
I'm ok with every open source RTOS if it supports C especially struct.
So I have found contikiOS does that, and tried to get started.
But I guess contikiOS doesn't support Arduino port anymore and Due is quite recent model so that I couldn't find proper information.
If you know any information on it or want me to help, please give me an advice.
Ah, do you have any other recommendation for RTOS?
Thanks.
If what you need is to run a simple c/c++ software, you have to know that the arduino environment support c/c++ code, as explained in the arduino homepage http://code.google.com/p/arduino/
If for your requirements, you need to use a real time operating system, there is a contikiOS version for Arduino (Contiki-Arduino).
Last but not least, if you are a beginner, i would advice you to use a popular RTOS, to find support on internet easily if you need it. Sadly, i am not an expert on that field. But when i google it, i find Duinos, maybe you could have a look on it.

libudev advice needed

I am embarking on a programming project that will need to confirm device identity of removable media (e.g. usb thumb drives) before it will go on to do a bunch of other cool stuff.
Some friends of mine pointed me towards using the Serial Number, and preliminary testing using the udevadm command indicates that this should work. I did some additional checking and it appears that if I can get the software working with libudev then it should (minimally) compile on ubuntu, slackware and gentoo, which would be a really nice benefit.
So I used bing to find a tutorial and got the Signal 11 site (http://www.signal11.us/oss/udev/) it's a very well-written tutorial. It actually seems to have everything I need. I download the code. Fix a couple of platform-specific bugs and then compile. BOOM! Gcc compiles without errors. So far so good.
But when I try to run it, it kicks up a couple of bugs, and I realize that I need to read some more tutorials so that I can understand libudev well enough to fix the bugs, and to turn out working software. Problem is that there really ISN'T any other tutorials (that I can find) and the kernel.org site that is the (only known?) site of the library documentation is down after a recent server compromise.
I considered just issuing udevadm directives to system() and then parsing results, but that's a really hackish way to put software together, and I am planning on releasing this to the community when I'm finished writing.
So how best for me to learn libudev??
libudev is quite simple library. After reading library you've mentioned and using API documentation (site should be soon up) I was able to get what I wanted. udevadm is great help, after issuing # udevadm info --query=all --name=/path/to/dev you'll get all information that udev has about this device and what's more important, these are parameters used in property functions (e.g. udev_device_get_property_value(device, "ID_VENDOR")). So best way to learn libudev is to start using it with help of signal11 tutorial, API documentation and udevadm informations.
EDIT: libudev is currently part of systemd - documentation is available as manual pages - https://www.freedesktop.org/software/systemd/man/libudev.html#
For those looking in 2023...
As Maciej pointed out, libudev is now a part of systemd.
According to:
https://www.freedesktop.org/software/systemd/man/libudev.html#
...this library is supported, but should not be used in new projects.
Please see sd-device(3) for an equivalent replacement with a more
modern API.
Documentation for sd-device:
https://www.freedesktop.org/software/systemd/man/sd-device.html#

how to code drivers?

I want to code drivers in C in linux os, though I think its very tough. Can I get some hints as to how to start or books to follow? Drivers can be from my USB port to graphics card!!
I know as to where I can search for books, I would like to know as to what the basic knowledge I should start with. Do I need to have hardware knowledge and which specific books are good for novice like me?
Start with Linux Device Drivers by Rubini and Corbet, published by O'Reilly.
It's also available as a free PDF download.
"Linux Device Drivers" (the O'Reilley book) by Rubini and Corbet is the definitive book for Linux Device Drivers.
Cool! see the free pdf version in Roddy's answer & kristina's comment!
try amazon !! there is many books there for drivers . some have samples 2 !!
Several texts:
Essential Linux Device Drivers (I really enjoyed this one. It has a strong introductory section on Linux and how device drivers generally work.)
Linux Device Drivers (The "standard" with a free pdf link as mentioned by others)
Understanding the Linux Kernel (The longer you spend here, the better you need to really understand the kernel. This will help.)
Before you jump into designing drivers you should first get exceptional C skills and probably some Linux Kernel know-how. Desigining drivers is not trivial and might scare you off if you are not used to programming on a low-level.
I might recommend The C programming Language if you are not accustomed to C as it is, in my opinion, the primer on C if you have some programming background.
Drivers differ greatly in complexity depending on the device. USB drivers are on the simple side of the spectrum; GPU drivers are massively complex and even the authors of those drivers usually don't know everything that they do. My recommendation would be focusing on drivers for hardware you personally care about, rather than trying to be a jack-of-all-hardware; it'll be easier in the long run.
Everybody else's answers about documentation sources and various things to read are spot-on and you should really accept one of them.
Many of the more complex driver communities have their own domain-specific information as well. If you want to write a GPU driver, the DRI/DRM and Mesa communities have their own wikis and mailing lists which will help you out greatly, as well as their own documentation. http://dri.freedesktop.org/ is a decent starting place, as is http://wiki.x.org/.
Hope this helps!
you have here a really good example
http://www.linuxjournal.com/article/7353
Just look at the source codes of current drivers. I wrote my usb rndis driver by only reading the comments put above the codes.
Get the kernel source and look at /drivers directory. Usb drivers are in usb directory, however usb drivers about networking are resided in /net/usb.
You can learn lots by reading the comments.

FastCGI on Windows and Lighttpd

I'm looking to make my CGI forum software FastCGI compatible.
The forum software consists of a few dlls and .exe (.cgi) files written in C and x86 assembly language. I also have a SQlite3 database.
Lighttpd runs all these cgi scripts as child processes and I much say that the whole thing works pretty damn well.
But I want to experiment with FastCGI. However, the examples are poor, the documentation is poor, and it really looks like it's made for Linux in mind. Did someone get FastCGI working on Windows? If someone has a code example around, and the lighttpd configuration lines, I would be really grateful.
i've done some work with fastcgi on windows. bottom line is its not a lot of fun - you are 100% correct that there aren't a lot of sample and it the documentation is poor. but, the developer who i was helping on this was in contact with the guys who write iis and the fastcgi spec and was able to get his software to work. some changes are in the works to help. here is a link to some information:
http://blogs.iis.net/ksingla/archive/2009/04/20/fastcgi-isapi-1-5-beta-for-winxp-and-win2k3.aspx
i should add that the guy i was working with had so many problems with libfcgi.dll that he ended up rewriting it (see the reference to libfcgi2.dll in the article linked above.)
best regards,
don

Resources