How to send a bit to the parallel port on Linux (2nd part)

In this second part of how to send bits to the parallel port on Linux, i describe here basics on how to do the same on kernel space.
Here is a simple linux kernel module, that create a char device named parlport, and you can communicate directly with device using the /dev/parlport

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/unistd.h>
#include <asm/uaccess.h>
#include <linux/file.h>
#include <asm/io.h>

#define NAME “parlp”
#define VERSION “0.1”
#define LICENSE “GPL”
#define DESCPT “Simple Parallel Port LED driver”
#define AUTHOR “Mezgani Ali\n”\
“mail: mezgani [AT] nativelabs [.] org\n”\

#define SUCCESS 0
#define DEVICE_NAME “parlport”
#define BASEPORT 0x0378

static int major = 61; /* major number assigned to our device driver */

static int __init start_module(void);
static void __exit clean_module(void);

static int device_open(struct inode *, struct file *);
static int device_release(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t, loff_t *);
static ssize_t device_write(struct file *, char *, size_t, loff_t *);

static struct file_operations fops = {
.open = device_open,
.release = device_release,
.read = device_read,
.write = device_write

static int
__init start_module(void)
int result;

result = register_chrdev(major, DEVICE_NAME, &fops);

if (result < 0) {
printk(KERN_ALERT “Registering device failed with %d\n”, major);
return result;

if (!(request_region(BASEPORT, 1, DEVICE_NAME))){
printk(KERN_WARNING “Winbond error request region: %X\n”, BASEPORT);
release_region(BASEPORT, 1);

return result;

printk(KERN_INFO “I was assigned major number %d. To talk to\n”, major);
printk(KERN_INFO “the driver, create a dev file with\n”);
printk(KERN_INFO “‘mknod /dev/%s c %d 0’.\n”, DEVICE_NAME, major);

return SUCCESS;

static void
__exit clean_module(void)
release_region(BASEPORT, 1);

unregister_chrdev(major, DEVICE_NAME);
printk(KERN_ALERT “unregister_chrdev && cleaning module\n”);


static int
device_open(struct inode *inode, struct file *file)
return SUCCESS;

static int
device_release(struct inode *inode, struct file *file)
return 0;

static ssize_t
device_read(struct file *filp, char *buffer, size_t length, loff_t * offset)
unsigned char pbuffer;
int len;

/* input a byte (8 bits) from a port, call inb(port), it returns the byte it got */
pbuffer = inb(BASEPORT);

len = copy_to_user(buffer, &pbuffer, 1);
if (len) return -EFAULT;

if (*offset == 0) {
*offset += 1;
return 1;
} else {
return 0;

static ssize_t
device_write(struct file *filp, char *buffer, size_t length, loff_t * offset)

char pbuffer, *ptr;
int len;

ptr = buffer + length – 1;
len = copy_from_user(&pbuffer, ptr, 1);
if (len) return -EFAULT;

/* output the data to parallel port */
outb(pbuffer, BASEPORT);
return 1;



Example of use after compilation ;

# insmod parlport.ko
# mknod /dev/parlport c 61 0
# chown 666 /dev/parlport
# echo F > /dev/parlport


Future of hacking

Many secret of nano technology are reveled, i think that the nano science become more and more interesting.

Germans and Americans scientist worked on it 20 years old, so this technology become more and more exploited and deployed in many domains, medicine, military, mechanic, pharmacy …
Dr. Altmann  has published a book about some dangerous military uses if you want read more please check here

More than that many researcher ask for dead code, to prove their reel visibility of the world and hiding the GOD existence, i’m really sorry to know about these
thoughts of this kind of intellectuals.

Anyway, a simple use can affect political people even to write and read event from their mind.

In computer science :
i think that if we can not hack brains, no links are needed to hack into boxes, only nano metals and could be set by materials constructor into some referred data bus or in NIC’s, to deserve attacker remotely using signals in some dedicated channel, well every bit sent are mirrored on the attacker simulator.

finally it sound like telegram methods, very exciting and awesome what human can drive.

How to send a bit to the parallel port on Linux

It will be nice idea To do a network monitoring  project with LEDs, the fastest way is to use a Perl module called Device::ParallelPort, this module provides an API to all parallel ports. Device::ParallelPort has a number of drivers for multiple operating systems that includes a direct access module for Linux and the Linux ParPort driver. Work almost on  windows and FresBSD.

In python, there are a  module named pyparallel, and in c in userspace we may use Unix Standard and System Input/Output routines.

Here a simple example that make all LEDS connected to parallel port blinking 5 times.

  #include <stdio.h>
  #include <unistd.h>     /* For sleep(), ioperm(), inb() and outb(). */
  #include <sys/io.h>     /* Perhaps asm/io.h on other systems. */

  /* Address of the first parallel port. found in BIOS settings. */
  #define kDATA_REG (0x0378)          /* Base address = data register. */
  #define kSTAT_REG (DATA_REG + 1)    /* Status register. */
  #define kCONT_REG (DATA_REG + 2)    /* Control register. */

  int main()
      int i;

      if (ioperm(kDATA_REG, 1, 1))    /* Get permission to access this port. */
          printf("ioperm(%x) failed.\nYou must be root to execute!\n", kDATA_REG);
          return 1;

      /* Assume port is already in output mode (bit 5 in control register). */
      for (i = 0; i < 5; i++)        /* Let the LED(s) blink. */
          outb(255, kDATA_REG);       /* All 8 datalines high. */
          outb(0, kDATA_REG);         /* All 8 datalines low.  */

      return 0;