建筑笔驱动器

时间:2015-03-15 04:12:06

标签: c linux-kernel linux-device-driver

我正在尝试构建功能齐全的笔式驱动器。以下是我到目前为止所做的事情:

#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/usb.h>

static int pen_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
    printk(KERN_INFO "[*] Anubhav-usb pen drive (%04X:%04X) plugged\n", id->idVendor, id->idProduct);
    return 0;
}

static void pen_disconnect(struct usb_interface *interface)
{
    printk(KERN_INFO "[*] Anubhav-usb pen drive removed\n");
}

static struct usb_device_id pen_table[] =
{
    //0951:1643
    { USB_DEVICE(0x0951, 0x1643) },
    {}
};
MODULE_DEVICE_TABLE (usb, pen_table);


//usb driver
static struct usb_driver pen_driver =
{
    .name = "Anubhav-usb stick-driver",
    .id_table = pen_table,
    .probe = pen_probe,
    .disconnect = pen_disconnect,
};

static int __init pen_init(void)
{
    int ret = -1;
    printk(KERN_INFO "[*]Anubhav-usb constructor of driver");
    printk(KERN_INFO "\tRegistering Driver with Kernel");
    ret = usb_register(&pen_driver);
    printk(KERN_INFO "\tRegistration is complete");
    return ret;
}

static void __exit pen_exit(void)
{
    printk(KERN_INFO "[*] Aubhav-usb destructor of driver");
    usb_deregister(&pen_driver);
    printk(KERN_INFO "\tUnregistration complete");
}



module_init(pen_init);
module_exit(pen_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("ANUBHAV");
MODULE_DESCRIPTION("USB registration driver");

我在内核中插入了这个模块,探针功能正常工作。我现在想进一步移动,并希望在笔式驱动器中读取(然后再写入)数据。

例如。接下来我想要的是弹出文件浏览器窗口显示笔式驱动器的内容,就像插入笔式驱动器时通常的工作一样。

我检查了这本书&#34; LINUX DEVICE DRIVERS 2 edition&#34;但找不到USB驱动程序的任何章节。

我还检查了链接: http://www.opensourceforu.com/2011/11/usb-drivers-in-linux-2/ 但我不确定它是否正在指导我正确的方向。

链接到一些有用的资源和/或电子书会很有帮助。

0 个答案:

没有答案
相关问题