Share via


Publishing a Bluetooth Serial Port Profile on a Windows Mobile phone

Some Windows Mobile partners consulted my mobility consulting team lately about publishing Serial Port Profile on a Windows Mobile phone. We know that a Windows Mobile phone usually publishes DUN (Dial-up Networking) service, which is based on SPP. What if you want to publish an additional SPP so your phone and the desktop can have an additional communication channel?

 

In Windows Mobile AKU 6, you can find a sample program (public\common\sdk\samples\bluetooth\bthnscreate) that demonstrates how to use a profile record file (.rec) to generate C code that can be used to publish a service on a device. However, the sample does not provide a rec file for SPP.

 

Well, here is an example of SPP record file you can use. For details of this record file format, you should get a copy of Bluetooth Profile specification and read Part K:5 Serial Port Profile. 

-------------------------------------------------------------------------------------------

1 SEQUENCE

  ; SPP class ID

  UUID16 1101

  END

4 SEQUENCE

    SEQUENCE

      ; L2CAP protocol identifier

      UUID16 100

    END

    SEQUENCE

      ; RFCOMM protocol identifier

      UUID16 3

      ; NOTE: SPP is not guaranteed to run on RFCOMM channel A.

      ; This value may need to change at run time to appropriate channel.

      UINT8 A

    END

  END

6 SEQUENCE

    ; language base ID information

    UINT16 656E

    UINT16 6A

    UINT16 100

  END

100 STRING SPP

-------------------------------------------------------------------------------------------

Using the bthncreate tool with this record file, you can create a C source file. Then if you follow the WSASetService() example at the bottom of the page (https://msdn2.microsoft.com/en-us/library/aa450140.aspx), you can quickly write some code to call WSASetService with the rgbSdpRecord[] array in the created C source file. Of course, before you call WSASetService, you must first initialize winsock by calling WSAStartup, and clean up by calling WSACleanup.

Here the caveat is that once the phone publishes an additional SPP, the Bluetooth stack on the desktop will automatically create an incoming port and an outgoing port once they are paired. This makes legacy applications on the desktop continue to perform virtual com port based communication.

Of course, an easier way to create a channel for communication between a Windows Mobile device and a Windows desktop is to use Bluetooth socket. Please see https://msdn2.microsoft.com/en-us/library/aa362928%28VS.85%29.aspx (desktop BT socket) and https://msdn2.microsoft.com/en-us/library/aa362928%28VS.85%29.aspx (Windows CE BT socket) for details.

Comments