USB Notification

Posted by [하늘이]
2014. 9. 11. 11:51 IT/Linux
반응형

출저 : http://www.scribd.com/doc/62568003/34/Linux-USB-Notification


=============================================================

simple_usb_subscriber.c

=============================================================


#include <linux/module.h>

#include <linux/kernel.h>

#include <linux/usb.h>


static int usb_notify_subscriber(struct notifier_block *self, unsigned long action, void *dev)

{

    printk(KERN_INFO "usb_notify_subscriber \n");

    switch (action) 

    {

        case USB_DEVICE_ADD:

            printk(KERN_INFO "usb_notify_subscriber:USBdevice added \n");

            break;

        case USB_DEVICE_REMOVE:

            printk(KERN_INFO "usb_notify_subscriber:USBdevice removed \n");

            break;

        case USB_BUS_ADD:

            printk(KERN_INFO "usb_notify_subscriber:USB Busadded \n");

            break;

        case USB_BUS_REMOVE:

            printk(KERN_INFO "usb_notify_subscriber:USB Busremoved \n");

    }

    return NOTIFY_OK;

}


static struct notifier_block usb_simple_nb = 

{

    .notifier_call = usb_notify_subscriber,

};


int init_module(void)

{

    printk(KERN_INFO "Init USB simple subscriber.\n");/** Register to the USB core to get notification on any addition orremoval of USB devices*/

    usb_register_notify(&usb_simple_nb);

    return 0;

}

     

    

void cleanup_module(void)

{

    /** 

    Remove the notifier

    */

    usb_unregister_notify(&usb_simple_nb);

    printk(KERN_INFO "Remove USB simple subscriber\n");    

}


MODULE_LICENSE ("GPL");



=============================================================

Makefile

=============================================================

obj-m += simple_usb_subscriber.o


all:

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules


clean:

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


[출처] Linux USB Notification (티라노의 홈페이지) |작성자 tyranno1


반응형