-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkbleds.c~
96 lines (53 loc) · 1.82 KB
/
kbleds.c~
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/init.h>
#include <linux/tty.h> /* for fg_console, MAX_NR_CONSOLES */
#include <linux/kd.h>
#include <linux/vt.h>
#include <linux/console_struct.h> /* for vc_cons */
MODULE_DESCRIPTION("using the keyboard LEDs ");
MODULE_AUTHOR("Amr Mohamed Awd ");
MODULE_LICENSE("GPL");
struct timer_list mytimer_list;
struct tty_driver *my_driver;
char kbledstatus = 0 ;
#define BLINK_DELAY HZ/5
#define ALL_LEDS_ON 0x07
#define RESTORE_LEDS 0xff
static void my_timer_func(unsigned long ptr){
int *pstatus =(int *) ptr;
if(*pstatus==ALL_LEDS_ON)
*pstatus=RESTORE_LEDS;
else
*pstatus=ALL_LEDS_ON;
(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty,NULL,KDSETLED, *pstatus);
mytimer_list.expires=jiffers+BLINK_DELAY;
add_timer(&mytimer_list);
}
static int __init kbleds_init(void){
int i=0;
printk(KERN_INFO "kbleds: loading");
printk(KERN_INFO "kbleds: fg_condole is %x ",fg_console);
for(i=0; i<MAX_NR_CONSOLES;i++){
if(!vc_cons[i].d)
break;
printk(KERN_INFO "LEDS: console[%i/%i] #%i,tty %lx ",i,MAX_NR_CONSOLES,vc_cons[i].d->vc_num,(unsigned long)vc_cons[i].d->vc_tty);
}
printk(KERN_INFO "LEDS: finished scanning consoles ");
my_driver=vc_cons[fg_console].d->vc_tty->driver;
printk(KERN_INFO "LEDS:tty driver magic %x ",my_driver->magic);
init_timer(&mytimer_list);
mytimer_list.function=my_timer_func;
mytimer_list.data=(unsigned long)&kbledstatus;
mytimer_list.expires=jiffers+BLINK_DELAY;
add_timer(&mytimer_list);
return 0;
}
static void __exit kbleds__exit(void){
printk(KERN_INFO "LEDS: unloaaaading");
del_timer(&mytimer_list);
(my_driver->ioctl) (vc_cons[fg_console].d->vc_tty,NULL,KDSETLED,RESTORE_LEDS);
}
module_init(kbleds_init);
module_exit(kbleds_exit);