Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: Php, Created At: 10/24/2016 8:26:10 PMViews:

HTML view:
Copy Source | Copy HTML
  1. #include <linux/module.h>
  2. //#include <linux/init.h>
  3. #include <linux/kd.h> /*for KDSETLED*/
  4. #include <linux/console_struct.h>
  5. #include <linux/vt_kern.h>/*for fg_console*/
  6. #include <linux/vt.h> /*for MAX_NR_CONSOLES*/
  7.  
  8. struct timer_list my_timer;
  9. struct tty_driver *my_driver;
  10. char kbledstatus =  0;
  11.  
  12. /*
     *    0x07 - 111
     *    0x06 - 110
     *    0x05 - 011
     *    0x04 - 010
     *    0x03 - 101
     *    0x02 - 100
     *    0x01 - 001
    */
  13.  
  14. #define BLINK_DELAY HZ/5
  15. #define ALL_LEDS_ON 0x01
  16. #define RESTORE_LEDS 0xFF
  17.  
  18. static void my_timer_foo(unsigned long ptr)
  19. {
  20.     int *pstatus = (int *)ptr;
  21.     switch (*pstatus) {
  22.     case 0x02: *pstatus = 0x04;
  23.             break;
  24.     case 0x04: *pstatus = 0x01;
  25.             break;
  26.     case 0x01: *pstatus = 0x02;
  27.             break;
  28.     default: *pstatus = 0x02;
  29.             break;
  30.     }
  31.  
  32.     (my_driver->ops->ioctl)(vc_cons[fg_console].d->vc_tty, NULL, KDSETLED,
  33.     *pstatus);
  34.     my_timer.expires = jiffies + BLINK_DELAY;
  35.     add_timer(&my_timer);
  36. }
  37.  
  38.  
  39. static int __init kb_leds_init(void)
  40. {
  41.     int i =  0;
  42.     printk(KERN_INFO "kbleds: fg_console is %x\n", fg_console);
  43.     for (i =  0; i < MAX_NR_CONSOLES; i++) {
  44.     if (!vc_cons[i].d)
  45.         break;
  46.     printk(KERN_INFO "poet_atkm: console[%i/%i] #%i, tty %lx\n", i, MAX_NR_CONSOLES,
  47.             vc_cons[i].d->vc_num, (unsigned long)vc_cons[i].d->vc_tty);
  48.     }
  49.     my_driver = vc_cons[fg_console].d->vc_tty->driver;
  50.     printk(KERN_INFO "tty_driver magic: %x\n", my_driver->magic);
  51.  
  52.     init_timer(&my_timer);
  53.     my_timer.function = my_timer_foo;
  54.     my_timer.data = (unsigned long)&kbledstatus;
  55.     my_timer.expires = jiffies + BLINK_DELAY;
  56.     add_timer(&my_timer);
  57.     return  0;
  58. }
  59.  
  60. static void __exit kb_leds_exit(void)
  61. {
  62.     del_timer(&my_timer);
  63.     (my_driver->ops->ioctl)(vc_cons[fg_console].d->vc_tty, NULL, KDSETLED, RESTORE_LEDS);
  64. }
  65.  
  66. module_init(kb_leds_init);
  67. module_exit(kb_leds_exit);

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2018