Bluetooth in Linux

bluetooth_logo

This is a tutorial to enlighten you about how to use Bluetooth in Linux. Bluetooth is a short distance communication standard. The most common bluetooth stack used in Linux is BlueZ. BlueZ was originally developed by Qualcom and later made OpenSource. Since version 2.4.6 it is included in the Linux kernel distribution. So the first thing you have to do is install BlueZ on your Linux box. Just do a google search for bluez and install it on your system. You can get BlueZ from http://bluez.sourceforge.net

Once you are done with this, the next step is to start the bluetooth service. This can be done manually by the following command –

sh /etc/init.d/bluetooth start

The next step is to see if your bluetooth adapter is working properly by scanning for nearby bluetooth devices. This is where we use a tool called hcitool. Enable the bluetooth on your device (mobile) and run the following command –

hcitool scan

The above command will give you output as below –

Scanning …

00:0E:6D:9A:34:21 synapse

The address of your device as well it’s name gets detected in the scan. The next obvious thing to do with our bluetooth enabled linux box is to learn how to transfer and receive files. Files are transferred using a high level protocol called OBEX (Object Exchange). Run the following command and replace my bluetooth address with yours –

sdptool browse 00:0E:6D:9A:34:21

A portion of the output I got is shown below –

Service Name: OBEX Object Push
Service RecHandle: 0x10003
Service Class ID List:
“OBEX Object Push” (0x1105)
Protocol Descriptor List:
“L2CAP” (0x0100)
“RFCOMM” (0x0003)
Channel: 9
“OBEX” (0x0008)
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
“OBEX Object Push” (0x1105)
Version: 0x0100

The ‘Object Push’ service uses RFCOMM channel 9. To upload a file run the following command in the terminal –

obex_push 00:0E:6D:9A:34:21 a.txt

This will transfer the file ‘a.txt’ to the device with the above mentioned address. The same command (obex_push) invoked without any commands can be used to recieve files. For more information type ‘man obex_push’ in the terminal.

This is the end of the basic tutorial on how to use bluetooth in Linux to transfer and receive files. I will be adding more tutorials to perform other functions.

Advertisements

About synapse
Programming, motorcycles and photography. Want to do more, but only have time for so much!

4 Responses to Bluetooth in Linux

  1. Gladney says:

    Nice insights on that. Keep it coming, please. I appreciate your writing and taste on topic.

  2. Munsterman says:

    I?ve been searching looking around for this type of information. Will you publish some more in future? I?ll be grateful if you will.

  3. Steuer says:

    Very nice post!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: