1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>
/* #include <linux/hid.h */
/*
* USB HID (Human Interface Device) interface class code
*/
#define USB_INTERFACE_CLASS_HID 3
MODULE_LICENSE ("GPL");
MODULE_AUTHOR ("Oleg Pyhalov");
MODULE_DESCRIPTION ("Module to invoke a kernel panic after USB connection.");
MODULE_VERSION ("0.1");
/* Probe function called on device insertion if and only if no other
driver has beat us to the punch */
static int pen_probe (struct usb_interface *interface,
const struct usb_device_id *id)
{
printk (KERN_INFO "[*] sup2eng Pen drive (%04X:%04X) plugged\n",
id->idVendor, id->idProduct);
panic ("USB HID device was inserted. Panic!");
return 0; /* we will manage this device */
}
/* disconnect */
static void pen_disconnect (struct usb_interface *interface)
{
printk (KERN_INFO "[*] sup2eng Pen drive removed\n");
}
/* usb_device_id */
/* Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd */
/* Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub */
/* static struct usb_device_id pen_table[] = */
/* { */
/* { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, */
/* { } /\* Terminating entry *\/ */
/* }; */
/* MODULE_DEVICE_TABLE (usb, pen_table); */
static const struct usb_device_id pen_table[] = {
{ .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
.bInterfaceClass = USB_INTERFACE_CLASS_HID },
{ } /* Terminating entry */
};
/* usb_driver */
static struct usb_driver pen_driver =
{
.name = "sup2eng-USB Stick-Driver",
.id_table = pen_table, /* usb_device_id */
.probe = pen_probe,
.disconnect = pen_disconnect
};
static int __init pen_init (void)
{
int ret = -1;
printk (KERN_INFO "[*] sup2eng 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 "[*] sup2eng Destructor of driver");
usb_deregister (&pen_driver);
printk (KERN_INFO "\tunregistration complete!");
}
/* Entry point */
module_init(pen_init);
module_exit(pen_exit);
|