Sunday, June 21, 2009

OBEX introduction


What is OBEX?
OBEX (abbreviation of OBject EXchange, also termed IrOBEX) is a communications protocol that facilitates the exchange of binary objects between devices. It is maintained by the Infrared Data Association but has also been adopted by the Bluetooth Special Interest Group and the SyncML wing of the Open Mobile Alliance (OMA). OBEX is very similar in design and function to HTTP. It's a client-server type. One device is a server and it waits for any connections. The other device is a client and it requests to send a file to the server.

How to use OBEX via bluetooth in Android?
There are some popular open source projects and they have implemented OBEX protocol. I choose openobex, obexpushd, obexftp applications, and I made some changes to allow them to run in Android.

* build
  1. download the original source
  2. write related Android.mk files
  3. fix undeclared problems or modify to use glib functions....etc
  4. upload the source code to gitorious site (http://gitorious.org/android-obex)
* install
adb push obexpushd /system/xbin/obexpushd
adb push obexftp /system/bin/obexftp
adb push obex_test /system/bin/obex_test

Examples:
A. Run an OBEX data server in Android, use 'adb shell' to Android Dev phone terminal

> su (use root account)
# cd /sdcard (change dir to sdcard and launch obex data server here)
# obexpushd (it will store incoming files to /sdcard dir and run in backgournd)
or
# obexpushd -n -d (it will store incoming file to /sdcard dir and not run in backgound, display debug message)

When it launchs an OBEX data server in Android, it would broadcast "OBEX Object Push" service from SDP server. If you use other BT devices to search OBEX service, it can discover Android Dev phone. Once you make a paired connection, you can send files to Android Dev phone via bluetooth. It will automatically store files to sdcard.

B. Make Android Dev phone as a client, use 'adb shell' to Android Dev phone terminal

This is an example, I send a mp3 file from Android phone to my NOKIA N73 mobile phone.

> su (use root account)
# hcitool scan (scan all near by bluetooth device)
Scanning ...
00:18:C5:42:18:78 Erin-Nokia N73
# sdptool search FTP (search near by BT device with FTP service)
Inquiring ...
Searching for FTP on 00:18:C5:42:18:78 ...
Service Name: OBEX File Transfer
Service RecHandle: 0x1000e
Service Class ID List:
"OBEX File Transfer" (0x1106)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 11
"OBEX" (0x0008)
Language Base Attr List:
code_ISO639: 0x454e
encoding: 0x6a
base_offset: 0x100
Profile Descriptor List:
"OBEX File Transfer" (0x1106)
Version: 0x0100

# cd /sdcard
# obexftp -b 00:18:C5:42:18:78 -B 11 --list (list folder information)
Browsing 00:18:C5:42:18:78 ...
Channel: 11
Connecting..\done
Receiving "(null)"...|

]>



done
Disconnecting../done

# obexftp -b 00:18:C5:42:18:78 -B 11 -cE: -p 01.Breakaway.mp3 (send a MP3 song to NOKIA phone)
Browsing 00:18:C5:42:18:78 ...
Channel: 11
Connecting..\done
Sending "E:"...|done
Sending "01.Breakaway.mp3".../done
Disconnecting..-done

# obex_test -b 00:18:C5:42:18:78 11 (send obex text file to NOKIA phone)
Using Bluetooth RFCOMM transport
OBEX Interactive test client/server.
> c (create connection)
Made some progress...
Server request finished!
server_done() Command (00) has now finished
Timeout waiting for data. Aborting
> p (push a file)
PUT file (local, remote)> /sdcard/obex
test (write a subject name)
name=/sdcard/obex, size=3423
Going to send 3423 bytes
Made some progress...
Made some progress...
Made some progress...
Made some progress...
Server request finished!
server_done() Command (02) has now finished
Timeout waiting for data. Aborting
> q (leave it)

PS. all related source code is here.

3 comments:

  1. Hi,

    Great work on this, but please could you post your compiled binaries as well? I can't get the source to compile (Ubuntu 9.04, using make?)

    I think the problem may be that the user needs to be called erin (have the directory /home/erin/mydroid)

    Thanks,

    Will S

    ReplyDelete
  2. Hi,
    Did you get the whole source from Android git server? It need to compile in Android build system.

    The binary files are here.
    http://code.google.com/p/androidobex/downloads/list

    ReplyDelete
  3. also, i write another more detailed notes about building. http://i-miss-erin.blogspot.com/2009/07/how-to-build-obex-in-android.html

    ReplyDelete

Note: Only a member of this blog may post a comment.