1. M. S. Ramaiah School of Advanced Studies 1
CSN2503 NP Presentation
IrDA in Linux Kernel
Anshuman Biswal
PT 2012 Batch, Reg. No.: CJB0412001
M. Sc. (Engg.) in Computer Science and Networking
Module Leader: Rinki Sharma
Module Name: Network Programming
Module Code : CSN2503
2. M. S. Ramaiah School of Advanced Studies 2
Presentation Outline
• Introduction
– IrDA
– Security and Operating Range
• Linux architecture with IrDA
• IrDA Stack
• IrDA in the Linux Kernel
• Communicating using IrDA
– SIR mode
– FIR mode
– Transferring of Files
• IrDA sockets
– Hint Bits
– Socket options
– Sample code to discover IrDA devices
– Sample code of simple echo server
• Conclusion
• References
3. M. S. Ramaiah School of Advanced Studies 3
Introduction - Infrared
• Infrared is a legacy technology. It has lousy range
and can be a hassle to set up, but sometimes, it's
the only common communications medium
between your Linux box and something you want
to talk to.
• Infrared is a wireless communication technology
that makes use of the invisible spectrum of light
that is just beyond red in the visible spectrum.
• It's suitable for applications that require short-
range, point-to-point data transfer. Because it uses
light, line of sight is a prerequisite for using
infrared.
• In terms of operating range, infrared devices can
communicate up to one or two meters. Depending
on the implementation, if a device uses a lower
power version, the range can be stepped down to a
mere 20 to 30 cm. This is crucial for low-power
devices.
4. M. S. Ramaiah School of Advanced Studies 4
Introduction- IrDA
• Founded in 1993 as a nonprofit organization, the Infrared Data Association
(IrDA) is an international organization that creates and promotes interoperable,
low-cost infrared data interconnection standards that allow users to transfer
data from one device to another. The term IrDA is typically used to refer to
the protocols for infrared communications, not exclusively to the
nonprofit body.
• There are currently four versions of IrDA; their differences are mainly in the
transfer speed:
Serial Infrared (SIR)- The original standard with a transfer speed of up
to 115 kbps
Medium Infrared (MIR)- Improved transfer speed of 1.152 Mbps; it is
not widely implemented
Fast Infrared (FIR)- Speed of up to 4 Mbps; most new computers
implement this standard
Very Fast Infrared (VFIR)-Speed of up to 16 Mbps; it is not widely
implemented yet
• When two devices with two different IrDA implementations communicate,
one steps down to the lower transfer speed.
5. M. S. Ramaiah School of Advanced Studies 5
Introduction-Security and Operating Range
• A Cyclic Redundancy Check (CRC), which uses a number
derived from the transmitted data to verify its integrity,
protects all exchanged data packets. CRC-16 is used for
speeds up to 1.152 Mbps, and CRC-32 is used for speeds
up to 4 Mbps. The IrDA also defines a bi-directional
communication for infrared communications.
• An infrared connection operates at a range of 0 to 1 meter,
with peak intensity within a 30-degree cone. With more
power, a longer operating range is possible with a
reduction in transfer speed. In addition, an infrared
connection requires a visual line of sight in order to work,
so there cannot be any direct obstruction between the two
communicating devices.
6. M. S. Ramaiah School of Advanced Studies 6
Linux Architecture with IrDA
7. M. S. Ramaiah School of Advanced Studies 7
• Linux supports IR communication on two planes:
• Intelligent data-transfer via protocols specified by the Infrared Data
Association (IrDA). This is implemented by the Linux-IrDA project.
• Controlling applications via a remote control. This is implemented by the Linux
Infrared Remote Control (LIRC) project.
• Device drivers constitute the bottom layer. SIR chipsets that are 16550-compatible uses the
native Linux serial driver after porting it using the IrDA line discipline with IrTTY. An
alternative to this combo is the IrPort driver. FIR chipsets have their own special drivers.
• Next comes the core protocol stack. This consists of the IR Link Access
Protocol (IrLAP), IR Link Management protocol (IrLMP), Tiny Transport
Protocol (TinyTP), and the IrDA socket (IrSock) interface.
• Higher regions of the stack join IrDA to data-transfer applications. IrLAN and IrNET
enable networking, while IrComm allows serial communication.
• openobex which implements the OBject EXchange (OBEX) protocol is used to exchange
objects such as documents and visiting cards.
• To configure Linux-IrDA, you need the irda-utils. This provides tools such
as irattach, irdadump, and irdaping.
Linux Architecture with IrDA
8. M. S. Ramaiah School of Advanced Studies 8
IrDA Stack
The IrDA protocol consist manily of three diffrent layers:
9. M. S. Ramaiah School of Advanced Studies 9
• Physical layer -
• first layer from bottom up in hierarchical stack
• deals directly with
– bit encoding
– error checking and correction
– transmiting and receiving data
• Network Layer: Link Access Protocol (IrLAP)
• second layer on hierarchical stack
• uses services provided by physical layer
• defines services provided by the protocol
• sets vocabulary, encoding and procedures rules
• provides a reliable transport as well as the state machine to discover
neighboring devices
IrDA Stack
10. M. S. Ramaiah School of Advanced Studies 10
• Transport layer: Link Management Protocol (IrLMP)
• support walk-up and point to point connection between IrDA devices
• provides and supports for multiple software applications
• allows entities to operate independently
• IrLMP is a multiplexer over IrLAP
• TinyTP provides segmentation, reassembly, and flow control.
• IrSock offers a socket interface over IrLMP and TinyTP.
IrDA Stack
11. M. S. Ramaiah School of Advanced Studies 11
IrDA in the Kernel
• If your hardware supports SIR mode, this is usually straightforward. FIR configuration
is still somewhat difficult, unless you have a system that's supported right out of the
box.
• Most modern notebooks support FIR by default, but you can often go into the BIOS
setup and change it to SIR. Even if you want FIR to work, be sure to try SIR first,
because it's usually the simplest.
• Most modern kernels have all the support that you need to get infrared to work. If you
build your own kernel, make sure that you've enabled infrared support. Most of the
infrared support is configured under the IrDA (Infrared) Support section that appears in
the kernel configuration.
• To enable IrDA support in your Kernel first get the kernel source from
http://kernel.org/pub/linux/kernel
• To know your current kernel version you can type in the command uname –r . So to
upgrade the kernel download the version above the current version from the above site.
• The kernel tar ball is distributed in both GNU zip (gzip) and bzip2 (better compressed)
format.
• The Linux kernel tar ball in bzip2 format is named linux-x.y.z.tar.bz2, where x.y.z is the
version of that particular release of the kernel source.
12. M. S. Ramaiah School of Advanced Studies 12
• After downloading the source, uncompressing and un tarring it.
• If your tar ball is compressed with bzip2, run
• $ tar xvjf linux-x.y.z.tar.bz2
• If it is compressed with GNU zip, run
• $ tar xvzf linux-x.y.z.tar.gz
• This un tars the source to the directory linux-x.y.z.
• Before we do anything with the sources, we should make sure the source tree
does not contain any old object files or configuration information...That got
there accidentally.
• This is especially true for distribution kernels-they tend to contain various stale
files.
• To do this, go into the source directory and run the command:
$ sudo make mrproper
$sudo make clean
IrDA in the Kernel
13. M. S. Ramaiah School of Advanced Studies 13
• Several configuration programs are supported by the kernel. But best is to use
$ sudo make menuconfig . If you get error while running this command
because of nCurses library then install the library as
– sudo apt-get install libncurses5-dev
before running make menuconfig
IrDA in the Kernel
14. M. S. Ramaiah School of Advanced Studies 14
• IrDA is a network protocol, so it can be found under the networking main
menu in the menuconfig.
IrDA in the Kernel
15. M. S. Ramaiah School of Advanced Studies 15
IrDA in the Kernel
16. M. S. Ramaiah School of Advanced Studies 16
• Save the menuconfig
IrDA in the Kernel
17. M. S. Ramaiah School of Advanced Studies 17
• Once configured, Compiling the kernel is easy.
• To compile the kernel's main part
$ sudo make bzImage
If the make is success you will get the output as
IrDA in the Kernel
18. M. S. Ramaiah School of Advanced Studies 18
• SYSCALL arch/i386/kernel/vsyscall-int80.so gcc: error: elf_i386: No such file
or directory make[1]: if you get this error while doing a make bzImage then go
to arch/x86/vdso/Makefile and search for word VDSO_LDFLAGS there exists
two lines one for x64 and another for x32 bit systems.it should have -m
elf_x86_64 and another one -m elf_x86 replace them like -m64 and -m32
respectively save it and again do the make bzImage
• First, Compile the kernel, only the code which is added statically
$ sudo make
IrDA in the Kernel
19. M. S. Ramaiah School of Advanced Studies 19
• Compile the code of the kernel for the features which are added as modules
$ sudo make modules
• Install the compiled module object code into the compiled kernel. As root simply run
$ sudo make modules_install
• This installs all the compiled modules to their correct home under /lib/modules
• Now install your new kernel!
$ sudo make install
IrDA in the Kernel
20. M. S. Ramaiah School of Advanced Studies 20
• Since initramfs usually needs to be customized for the particular
hardware/device configuration and kernel version, they are not included as a
part of any package, but are generated on the fly at kernel installation time. To
customize the initramfs for particular onfiguration and kernel version,
generated at the installation time use
$ sudo update-initramfs –c –d 2.6.31.5 ( if required)
$ sudo update-initramfs –c –k 2.6.31.5
• Once we installed the new kernel and its new modules, we need to tell the boot
loader about it.
$ sudo update-grub
IrDA in the Kernel
21. M. S. Ramaiah School of Advanced Studies 21
• Once everything is set, reboot your machine.
• At the boot loader's prompt/menu, chose the new kernel.
• Now install the necessary software packages irda-utils and ircp-tray.
$ sudo apt-get install irda-utils ircp-tray
• Install setserial package
$ sudo apt-get install setserial
• Now run the below command to edit the irda-utils file
$ gksu gedit /etc/default/irda-utils
In the configuration file which opens up, change the line
reading DEVICE="/dev/ttyS1" to DEVICE="irda0“ and the line
reading SETSERIAL="" to SETSERIAL="/dev/ttyS1“
IrDA in the Kernel
22. M. S. Ramaiah School of Advanced Studies 22
• Two devices can communicate using IrDA. For this using the above method
build your Linux kernel with IrDA enable for both the devices that you want to
establish communication between using IrDA.
• SIR chips offer a UART interface to the host computer. For communicating in
SIR mode, attach the associated UART port (/dev/ttyS1 for example) of each
laptop to the IrDA stack:
$ sudo irattach /dev/ttyS1 –s
• Verify that IrDA kernel modules (irda.ko, sir_dev.ko, and irtty_sir.ko) are
loaded and that the irda_sir_wq kernel thread is running. The irda0 interface
should also have made an appearance in the ifconfig output. The -s option
to irattach triggers a search for IR activity in the neighborhood. If you slide the
laptops such that their IR transceivers lie within the range cone, they will be
able to spot each other:
$ sudo cat /proc/net/irda/discovery
IrLMP: Discovery log:
nickname: localhost, hint: 0x4400, saddr: 0x55529048, daddr:
0x8fefb350
Communicating using IrDA-SIR mode
23. M. S. Ramaiah School of Advanced Studies 23
• The other laptop makes a similar announcement, but with the source and destination
addresses (saddr and daddr) reversed.
• You may set the desired communication speed using stty on ttyS1. To set the baud rate to
19200, do this:
– $ sudo stty speed 19200 < /dev/ttyS1
• The easiest way to cull IR activity from the air is by using the debug tool, irdadump
$ sudo irdadump -i irda0
• You can also obtain debug information out of the IrDA stack by controlling the verbosity
level in /proc/sys/net/irda/debug
Communicating using IrDA-SIR mode
24. M. S. Ramaiah School of Advanced Studies 24
• To set the laptops in FIR mode, dissociate ttyS1 from the native serial driver
and instead attach it to the NSC FIR driver, nsc-ircc.ko:
$ sudo setserial /dev/ttyS1 uart none
$ sudo modprobe nsc-ircc dongle_id=0x09
$ sudo irattach irda0 -s
dongle_id depends on your IR hardware and can be found from your
hardware documentation. As you did for SIR, take a look
at /proc/net/irda/discovery to see whether things are okay thus far.
• Sometimes, FIR communication hangs at higher speeds. If irdadump shows a
communication freeze, then fix the code, or try lowering the negotiated speed
by tweaking/proc/sys/net/irda/max_baud_rate.
• For device example of IR dongle driver you can see the
file drivers/net/irda/tekram.c and drivers/net/irda/ep7211_ir.c.
Communicating using IrDA-FIR mode
25. M. S. Ramaiah School of Advanced Studies 25
• Transferring The Files
• Install the openobex-apps package.
$ sudo apt-get install openobex-apps
• Then open the terminal and type irxfer
$ irxfer XXXX.mp3
On successful it will say Put Successful
Communicating using IrDA-Transferring of Files
26. M. S. Ramaiah School of Advanced Studies 26
IrDA Sockets
• To develop custom applications over IrDA, use the IrSock interface. To create
a socket over TinyTP, do this:
int fd = socket(AF_IRDA, SOCK_STREAM, 0);
• For a datagram socket over IrLMP, do this:
int fd = socket(AF_IRDA, SOCK_DGRAM, 0);
• To get the list of device discovery and there info IrDA uses a structure to hold
the information in
• struct irda_device_list {
u_int32_t numDevice;
struct irda_device_info Device[1];};
• struct irda_device_info {
u_int32_t saddr; /* Address of local interface */
u_int32_t irdaDeviceID; /* Address of remote device */
char irdaDeviceName[22]; /* Description */
u_int8_t charset; /* Charset used for description */
u_int8_t hints[2]; /* Hint bits */ };
27. M. S. Ramaiah School of Advanced Studies 27
• The irda_device_info struct has a two byte hint array. The hint bits can give
info about that a given IrDA device is and what it supports. Here is a list of the
available bits from /usr/include/linux/irda.h
IrDA Sockets-Hint Bits
Hint bit positions for first hint byte Hint bit positions for second hint byte (first extension byte)
HINT_PNP HINT_TELEPHONY
HINT_PDA HINT_FILE_SERVER
HINT_COMPUTER HINT_COMM
HINT_PRINTER HINT_MESSAGE
HINT_MODEM HINT_HTTP
HINT_FAX HINT_OBEX
HINT_LAN
HINT_EXTENSION: If this is set the next byte is valid
28. M. S. Ramaiah School of Advanced Studies 28
IrDA Sockets- SOL_IRLMP Socket Options
Option Get Set Optval type Description
IRLMP_DISCOVERY_MODE
IRLMP_ENUMDEVICES yes DEVICELIST Returns a list of IrDA device IDs for IR capable
devices within range.
IRLMP_EXCLUSIVE_MODE DWORD (boolean) Sets socket to bypass TinyTP layer to directly
communicate with IrLMP.
IRLMP_IAS_QUERY yes IAS_QUERY Queries IAS on a given service and class name for
its attributes.
IRLMP_IAS_SET yes IAS_SET Sets an attribute value for a given class name and
attribute into IAS.
IRLMP_IRLPT_MODE yes DWORD (boolean) Enables communication with IR capable printers.
IRLMP_PARAMETERS
IRLMP_SEND_PDU_LEN yes DWORD Retrieves the maximum PDU length required to
use IRLMP_9WIRE_MODE.
IRLMP_SHARP_MODE yes
IRLMP_TINYTP_MODE yes
IRLMP_9WIRE_MODE yes yes DWORD (boolean) Puts the IrDA socket into IrCOMM mode.
The following table describes SOL_IRLMP socket options that apply to sockets created for the
Infrared Data Association (IrDA) address family (AF_IRDA) and the InfraRed Link Management
Protocol (IRLMP)
29. M. S. Ramaiah School of Advanced Studies 29
Sample code to discover the device
fd = socket(AF_IRDA, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
exit(-1);
}
printf("sizeof(struct irda_device_list)=%dn",sizeof(struct
irda_device_list));
printf("sizeof(struct irda_device_info)=%dn",
sizeof(struct irda_device_info));
discover_devices(fd);
IrDA Sockets-Sample code to discover the device
30. M. S. Ramaiah School of Advanced Studies 30
struct irda_device_list *list;
len = sizeof(struct irda_device_list) +sizeof(struct irda_device_info) *
MAX_DEVICES;
buf = malloc(len);
list = (struct irda_device_list *) buf;
if (getsockopt(fd, SOL_IRLMP, IRLMP_ENUMDEVICES, buf, &len)) {
perror("getsockopt");
exit(-1);
}
if (len > 0) {
printf("Discovered:n");
for (i=0;i<list->len;i++) {
printf(" name: %sn", list->dev[i].info);
printf(" daddr: %08xn", list->dev[i].daddr);
printf(" saddr: %08xn", list->dev[i].saddr);
printf("n");
}
IrDA Sockets-Sample code to discover the device
32. M. S. Ramaiah School of Advanced Studies 32
for (;;) { addrlen = sizeof(struct sockaddr_irda);
printf("Waiting for connection!n");
conn_fd = accept(fd, (struct sockaddr *) &peer, &addrlen);
if (conn_fd < 0) {
perror("accept");
return -1; }
printf("Connected!n");
do {
actual = recv(conn_fd, &buf, sizeof(buf), 0);
if (actual <= 0) break;
printf("Got %d bytesn", actual);
if (!discard) {
actual = send(conn_fd, &buf, actual, 0);
printf("Sent %d bytesn", actual);
} } while (actual > 0);
close(conn_fd);printf("Disconnected!n");
IrDA Sockets-Sample echo server
33. M. S. Ramaiah School of Advanced Studies 33
Conclusion
• The main reason for using IrDA has been wireless data transfer over the last
one meter using point and shoot principles. Main characteristics of this kind
of wireless optical communication is physically secure data transfer, Line-of-
Sight (LOS) and very low bit error rate (BER) that makes it very efficient.
This has been implemented in portable devices like mobile phones, laptops,
printers, cameras, medical devices and many more.
• Besides the advantages of IrDA, it has certain disadvantages like one device
at a time connection, transfer rate is 4Mbps,have to keep device stable while
transferring data, it is for short range and LOS should be clear.
• Because of the above disadvantages blue tooth came into picture. But still it
cannot overshadow the IrDA uses.
• However more can be done in IrDA for future works like supporting higher
baud rates for faster transmissions,one to many connections etc.
34. M. S. Ramaiah School of Advanced Studies 34
References
[1] Dumbill,E.,Jepson,B.,Weeks,R. (April 2004) “Linux Unwired”, 1st
Edition:O’Reilly
[2] Wikipedia. “Infrared Data Association”. [Online].Available from:
http://en.wikipedia.org/wiki/Infrared_Data_Association (Accessed:31 March
2014)
[3]Linux-IrDA project by Hewlitt Packard. “Linux-IrDA quick tutorial”[Online].
Available from: http://www.hpl.hp.com/personal/Jean_Tourrilhes/IrDA/
(Accesses:31 March 2014)