Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jcarlos7121/4138330 to your computer and use it in GitHub Desktop.
Save jcarlos7121/4138330 to your computer and use it in GitHub Desktop.
Driver USB
#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 "[*] Conectado a interfaz (%04K:%04K)\n", id->idVendor,id->idProduct);
return 0;
};
static void pen_disconnect(struct usb_interface *interface){
printk(KERN_INFO "[*] Se desconect interfaz CH");
}
static struct usb_device_id pen_table[] =
{
{USB_DEVICE(0x0930,0x6545)},
{}
};
MODULE_DEVICE_TABLE(usb,pen_table);
static struct usb_driver pen_driver=
{
.name = "CH Driver"
.id_table = pen_table,
.probe = pen_probe,
.disconnect = pen_disconnect,
};
static int __init pen_init(void){
int ret = -1;
printk(KERN_INFO "[*] Constructor del driver CH");
printk(KERN_INFO, "\t Registrando el driver en el kernel");
ret = usb_register(&pen_driver);
printk(KERN_INFO "\t Registro esta completo");
return ret;
}
static void __exit pen_exit(void){
printk(KERN_INFO "[*] Destructor del driver");
usb_deregister(&pen_driver);
printk(KERN_INFO "\t se ha desregistrado exitosamente");
}
module_init(pen_init);
module_exit(pen_exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment