Re: how to write kernel modules



Nikos Chantziaras wrote:
Of course googling helps, but the usual suspect is LinuxHQ, where I
found this: http://www.linuxhq.com/lkprogram.html

For the 2.6 kernel, this seems like a nice introduction:
http://www.tldp.org/LDP/lkmpg/2.6/html

Thanks for the reply. After speaking with someone in on ##c at Freenode, I
decided to abandon the kernel module in favor of a user space driver.

I've made a small amount of progress; however, now that I'm to the point
that I'm ready to speak with the device, the usb_get_string_simple function
returns -1. Any ideas what I'm doing wrong?

#include <stdio.h>
#include <usb.h>

#define VENDOR_ID 0x05e3
#define PRODUCT_ID 0x0502

usb_dev_handle *find_device() {
struct usb_bus *bus;
struct usb_device *dev;

for (bus = usb_busses; bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if (dev->descriptor.idVendor == VENDOR_ID &&
dev->descriptor.idProduct == PRODUCT_ID ) {
struct usb_dev_handle *handle;
printf("Device with Vendor Id: %x and Product Id: %x found.\n",
VENDOR_ID, PRODUCT_ID);
if (!(handle = usb_open(dev))) {
fprintf(stderr, "Could not open USB device\n");
return NULL;
}
return handle;
}
}
}
return NULL;
}

main(int argc, char *argv[]) {
usb_dev_handle *device;
struct usb_bus *bus;
struct usb_device *dev;
usb_init();
usb_find_busses();
usb_find_devices();
usb_dev_handle *udev;

if (!(device = find_device())) {
fprintf(stderr, "Couldn't find the device, Exiting\n");
}

char *buf;
int len;
len = usb_get_string_simple(device,0,buf,1024);
if (len < 0) {
// Here's where my code quits
fprintf(stderr, "Couldn't read from device, Exiting (%i)\n",len);
return -1;
}
printf(buf);

FILE *bindat;
bindat = fopen("usbdump","w");
fwrite(buf,1,1024,bindat);
fclose(bindat);

usb_close(device);
}

--
Joshua David Williams

(QDOS == "Quick & Dirty Operating System) --> (DOS == "Dirty Operating
System")
.



Relevant Pages