OBject EXchange
OBEX 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. One of OBEX's earliest popular applications was in the Palm III. This PDA and its many successors use OBEX to exchange business cards, data, even applications.
Although OBEX was initially designed for infrared, it has now been adopted by Bluetooth, and is also used over RS-232, USB, WAP and in devices such as Livescribe smartpens.
Comparison to HTTP
OBEX is similar in design and function to HTTP in providing the client with a reliable transport for connecting to a server and may then request or provide objects. But OBEX differs in many important respects:- HTTP is normally layered above a TCP/IP link. OBEX can also be, but is commonly implemented on an IrLAP/IrLMP/Tiny TP stack on an IrDA device. In Bluetooth, OBEX is implemented on a Baseband/ACL/L2CAP stack. Other such "bindings" of OBEX are possible, such as over USB.
- HTTP uses human-readable text, but OBEX uses binary-formatted type-length-value triplets named "Headers" to exchange information about a request or an object. These are much easier to parse by resource-limited devices.
- HTTP transactions are inherently stateless; generally an HTTP client opens a connection, makes a single request, receives its response, and either closes the connection or makes other unrelated requests. In OBEX, a single transport connection may bear many related operations. In fact, recent additions to the OBEX specification allow an abruptly closed transaction to be resumed with all state information intact.
Objects
Objects are fields and headers. As an example, the following may be the object used for requesting the phonebook from a mobile:
Object | Fields | Command | GET, Final | 0x83 |
Object | Fields | Length | total length of object | |
Object | Headers | Connection ID | 1 | |
Object | Headers | Name | "telecom/pb.vcf" |
This object contains two fields and two headers. The first field specifies that is a request for data. The second field is the total size of the object, including the two fields.
This object also contains two headers, specifically a "Connection ID" and a "Name". The first byte of each header is the header's name and its content type. In this case:
- 0xCB means that this header is a "Connection ID", a number obtained previously; the two highest-order bits of 0xCB are 11, and this pair specifies that this as a 4-byte quantity;
- the first byte of the second header is 0x01; this byte identifies this header as a "Name" one; the first two bits of 0x01 are 00, meaning that the content of this header is a null-terminated unicode string, prefixed by the number of bytes it is made of.
Response | Fields | Response code | OK, Final | |
Response | Fields | Length | total length of object | |
Response | Headers | End-of-Body |
In this example, the phonebook is assumed short enough to be contained in a single response object. The only header has 0x49 as its identifier, meaning that it is an "End of Body", the last chunk of information. The first two bits of 0x49 are 01, meaning that the content of this header is length-prefixed data: the two next bytes 0x00 0x2F tells the length of this data, the succeeding ones are the data, in this case a phonebook comprising only an empty vCard of 47 bytes.
This example shows a single GET command and its response, the only headers involved being connection id, name and end-of-body. Before issuing it, a CONNECT command should have been sent for establishing some parameters of the connection, including the connection id. Other commands are: put, setpath, action, abort, disconnect. Some other notable headers include: type, time, description, target.
Session
After the client connects to the server, a typical session consists in the client sending a number of objects and getting their responses from the server. As an example:- CONNECT: one of the fields specifies the largest size of packets the client can receive; a TARGET header specifies the kind of service the client is expecting ; the server answer with its maximal packet length, the connection id, and other data
- GET: the client requests a file, specifying the connection id, the file name and/or its type; the server answer with the file content, or just a part of it; in the latter case, the client has to send other GET objects to obtain the rest of the file
- SETPATH: the client tells the server to switch to a different file folder, specifying the connection id and the folder name in two headers
- GET: the client request a listing of the folder content by sending an object with the connection id and an appropriate TYPE header
- PUT: the client sends a file to the server; if it is too large to fit into a single packet, the server will request the next part with a CONTINUE response
- DISCONNECT: the client informs the server that is closing the session
Protocols
The following protocols runs over OBEX, or have bindings to do so:; OBEX Push
; OBEX File Transfer Protocol
; Phonebook Access
; IrMC
; SyncML
Implementations
javax.obex
Optional package javax.obex in Java APIs for Bluetooth provides an implementation of OBEX in Java.OpenObex
OpenObex is an open-source implementation of OBEX in C. It provides functions for connecting over IrDA, Bluetooth, USB and TCP/IP, building objects and handling received data. An example schema of a client application is:void callback_function
int main
Objects are sent by
OBEX_Request
. After calling OBEX_HandleInput
, received data is processed in the callback function. The callback function can determine whether the response has been completely received, and therefore whether the main program can exit from the while
loop it is executing.PyOBEX and nOBEX
PyOBEX provides partial support for OBEX in Python. nOBEX is a fork of PyOBEX with more complete OBEX support, and support for the Bluetooth Hands Free Profile to facilitate OBEX testing on automotive infotainment systems.Profiles
OBEX is the foundation for many higher-layer "profiles":Classification | Profile |
IrDA | Point and Shoot profile |
IrDA | Infrared Financial Messaging profile |
Bluetooth SIG | Generic Object Exchange Profile |
Bluetooth SIG | Object Push Profile |
Bluetooth SIG | File Transfer Profile |
Bluetooth SIG | Synchronization Profile |
Bluetooth SIG | Basic Imaging Profile |
Bluetooth SIG | Basic Printing Profile |
OMA | SyncML binding |
Supported devices
- All Palms since Palm III, except the Palm Pre, Palm Pre Plus, Palm Pixi and Palm Pixi Plus.
- Most Sharp, Motorola, Samsung, Sony Ericsson, HTC and Nokia phones with infrared or Bluetooth port
- LG EnV Touch
- Many other PDAs since 2003
- Many other phones with infrared or Bluetooth port
- Android devices in version 2.1 and above
- Windows Phone 7.8 and 8 devices.