Bluetooth technology has been around for sometime now and although a lot has been developed on and around this fantastic technology the best is yet to come…………………………..I started looking into this technology as my work required me to do so but was amazed by the potential it had and so decided to dive further and will continue to do so for sometime now till i have something concrete at hand…….The basics are nearly available everywhere…..but yet it is the best place to start. Since i basically deal with j2me mobile platforms, so JSR-82 became my point of start,

Most of the java enabled cell phones(the cldc, midp soup)……have a bluetooth device. This bluetooth device can very easily be controlled through either vendor applications supplied or one can simply write some little java code of his own to tame this little beast. I would be playing with this bt device at a very higher level(java), but libraries like bluez(more at http://www.bluez.org/) facilitate development at much lower level…………But thats a different story altogether……..lets begin by discussing what the oem vendor has allowed us to do……….I usually begin by switching the bluetooth in my n86 on and discovering the devices around me and some weird names popping up on the little screen. But wait, with java at your disposal you can have even more. Let’s try to make a similar application where one can discover a bit more about devices around him and a little more info about his own bt device.

Java refers to the bluetooth device present on your phone or user’s phone as LocalDevice and the devices that u r detecting via u r LocalDevice as RemoteDevice(s). As our PC’s have MAC addresses as unique identification,  these bluetooth devices also have some unique identifier. Java allows you to have a look at this 48 bit unique identifier of your LocalDevice by using the the api,

LocalDevice.getLocalDevice().getBluetoothAddress()—> the value returned will be an integer which will look something like—>0025cff962b9, If you are not interested please skip this part but for those who would like to delve further there’s some little information here. 0025cff962b9, can be divided into 6 segments of 8 bits each–> 00:25:cf:f9:62:b9 .

The first 3 bytes(00:25:cf) are assigned by IEEE to a specific manufacturer,and the last 3 bytes are freely allocated by the manufacturer,

i.e.,if 00:25:cf represents nokia n86 then all nokia n86 will hv same 3 bytes as their bt starting address.
But if you are looking into a commercial application then a bluetooth address is of  little use to the naive user, so for the user Java supplies you with the api,

LocalDevice.getLocalDevice().getFriendlyName()–>which will give you the user defined name of the bluetooth device, which the user can instantly recognize and connect with.

Similar simple apis exist to discover and extract valuable information about devices detected(did u say hacking??),

LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC,DiscoveryListener);

will start inquiring about devices in visibility range of the bluetooth. As devices a discovered a callback will be called, which is,

public void deviceDiscovered(RemoteDevice arg0, DeviceClass arg1),

Using the arg0 you can discover normal stupid things like the,

  1. Bluetooth Address of the remote device.
  2. Friendly name.
  3. Authentication info.
  4. Encryption info.

It is the arg1 that is pretty interesting, arg1 is the class of device(cod). Lets leave java aside for a second, and jump to pure binary. COD is a combination of 24 bits,

23   22   21   20   19   18   17   16   15   14   13   12   11   10   9    8    7    6    5    4    3    2    1    0

z       z       z      z       z      z      z      z      z      z      y     y      y      y   y    y    x     x    x    x    x    x    0   0

x->6 bits–>minor device class

y->6 bits–>major device class

z->10 bits–>Service class

if z(14) is set–>

if z(15) is set–>

if z(16) is set–>positioning

if z(17) is set–>rendering

if z(18) is set–>networking

if z(19) is set–>capturing

if z(20) is set–>object transfer

if z(21) is set–>audio

if z(22) is set–>telephony

if z(23) is set–>information

According to bt assigned numbers doc–>

13  12  11  10  9   8

for imaging device–> 0    0    0    1    1    0–>0x600 in hex

to convert this to decimal–> fill the remaining 0 to 7 bits with 0’s,

0 0 0 1 1 0 0 0 0 0 0 0 0 0–>2^9+2^10=512+1024=1536—>this integer is returned by java api(arg1.getMajorDeviceClass()) to indicate an imaging device.

Now let’s talk about minor device class—>

7  6  5  4  3  2

for a laptop we have–> 0  0  0  0  1  1

to convert this to decimal–>fill remaining 0 and 1 spaces by 0.

start calculating–>0 0 0 0 1 1 0 0–>2^2+2^3=12—>this integer is returned by java api(arg1.getMinorDeviceClass())  for a laptop device.

Now lets go the reverse way for the service classes,let’s say java api(arg1.getServiceClasses()) returns us something like 5898240(nokia n95 w’out simcard in offline mode)

Convert this to binary—>

23 22 21 20 19 18 17 16 15 14 13 12 11 10 9  8  7  6  5  4  3  2  1  0

0    1    0   1    1    0    1   0   0   0   0    0  0  0   0  0  0  0  0  0  0  0  0  0

For a dell laptop:

0    1    1    1    1    1    1   0   0   0   0    0   0   0  0  0  0  0  0  0  0  0  0  0

Interpret yourself.

Advertisements