Local Links

External Links

Contact

Search this site

Creating SDP entries with binary data in OS X


This article documents a problem and a partial work-around with the Bluetooth API in Mac OS 10.4 (Tiger) when creating a new service and describing it in the local SDP database.


When creating certain types of services, long binary (non-ASCII) string have to be stored in the corresponding SDP descriptors.

For example, this is the case for HID devices such as Mice and Keyboards, in the desciptor with the attribute ID 0x0206.

Due to two bugs in Tiger, its Bluetooth API does not non-ASCII text for such descriptors by default. The two bugs are:

  1. Attribute data of type "string" is carried in NSStrings, not NSData. NSStrings are textual containers that do not handle binary data well. E.g, when you use a plist to create a string, it may get modified due to encoding conversion. There is a work-around, though, see below.
  2. When the actual raw SDP dara is created for sending it to inquiring clients over air, data from NSStrings is read using C-style string methods, meaning that data is only read until the first occurance of a zero-byte.

The first bug can be worked around: Instead of providing the string in the plist directly, you need to create it in code, and then use the deprecated Obj-C NSString method

  + (id)stringWithCString:(const char *)bytes length:(unsigned)length;

as this method actually takes the data over in its original form, without an encoding.

The second bug can't be worked around, though, unless you find a way to avoid the use of 00-bytes in your attribute data.

Both bugs have been made known to Apple and there's a good likeliness that the next OS X version might have squashed them.

Refencences


Page last modified on 2012-12-04, 11:21 EST
Powered by PmWiki