Investigating OBEX over USB
I’ve had a number of requests for USB support in gnome-vfs-obexftp. At first I didn’t have much luck talking to my phone via USB. Running the obex_test utility from OpenOBEX gave the following results:
$ obex_test -u Using USB transport, querying available interfaces Interface 0: (null) Interface 1: (null) Interface 2: (null) Use 'obex_test -u interface_number' to run interactive OBEX test client
Trying to talk via any of these interface numbers failed. After reading up a bit, it turned out that I needed to add a udev rule to give permissions on my phone. After doing so, I got a better result:
$ obex_test -u Using USB transport, querying available interfaces Interface 0: Nokia Nokia 6230 (null) Interface 1: Nokia Nokia 6230 (null) Interface 2: Nokia Nokia 6230 (null) Use 'obex_test -u interface_number' to run interactive OBEX test client
With the change, I was also able to access the phone using the obexftp command line client. This seemed enough to start investigating a bit further. The OpenOBEX API for setting up USB connections goes something like this:
- The app calls OBEX_FindInterfaces(), which returns a list of obex_interface_t structures that represent the different discovered interfaces.
- The app picks one of the discovered interfaces (based on the manufacturer, product and serial number strings), then connects to it using OBEX_InterfaceConnect().
There are a number of issues with this interface though.
- If the phone doesn’t provide a serial number via its USB interface (like my 6230 doesn’t), the obex_interface_t structure is not enough to identify a particular phone.
- If the phone exposes multiple OBEX USB interfaces for some reason, OpenOBEX lists it multiple times. In the obex_test output shown above, there was a single phone attached – not three.
- There is no way to tell when phones are connected or disconnected. While HAL can do that job for us, there is no way to map from the device information provided by HAL to one of the discovered interfaces provided by OpenOBEX.
To sum up, it shouldn’t be difficult to hack support for USB connections into gnome-vfs-obexftp with URLs like obex://usb-N/ (where N is the number of the discovered interface), but there are a number of features I’d need to provide a good user experience:
- The ability to ask OpenOBEX to connect to a particular USB device, rather than having to deal with its discovery interface.
- A good set of udev rules to grant the needed permissions on common phones so they don’t need to find out why things only work as root.