USB Notification
출저 : 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
'IT > Linux' 카테고리의 다른 글
[리눅스 공부 2] 정적라이브러리 사용하기 (0) | 2015.06.28 |
---|---|
[리눅스 공부 1] C 컴파일러 - Hello world (0) | 2015.06.28 |
우분투 커널 컴파일 (0) | 2014.08.09 |
ubuntu 빌드 환경 설정 [설치 필요 패키지 정보] (0) | 2014.04.27 |
ubuntu root password 변경 (0) | 2014.04.14 |