Microsoft KB Archive/328900

= HOW TO: Debug Bluetooth Wireless Technologies in Windows CE By Using the BTDC Tool =

Article ID: 328900

Article Last Modified on 12/27/2003

-

APPLIES TO


 * Microsoft Windows CE 5.0

-



This article was previously published under Q328900



IN THIS ARTICLE
SUMMARY Bluetooth Debug Console (BTDC) Debugging Tool Use the Debugging Tool
 * Read a Bluetooth address
 * Inquire
 * Ping
 * Set and Revoke PINs
 * Establish an L2CAP Connection, Write Data, and Disconnect
 * Establish a RFCOMM Connection, Write Data, and Disconnect
 * Add and Delete SDP Records
 * Search SDP Services or Attributes
 * SDP Service Attribute Search



SUMMARY
This article describes how to use Bluetooth debug zones and the Bluetooth Debug Console (Btdc.exe) sample tool.

The Bluetooth debug zones can be turned on or off by using the Btloader.exe tool. This tool requires shell support. Use the following command line to set debug zones:

btloader debug 

is a DWORD bit mask of debug zones you may want to turn on or off. The meaning of each debug zone is defined in the following file:

\public\common\oak\inc\bt_debug.h

For example, the following command turns on all debug zones:

btloader debug 0xffffffff

back to the top

Bluetooth Debug Console (BTDC) Debugging Tool
BTDC is a console tool that helps to debug the Bluetooth driver. The tool requires shell support. You can find Help by typing help at the BTDC prompt. The output of commands is generally in the following format:

[API called] returns [return code in hex] [return code in decimal] [result]

The return codes are standard error codes as defined in Winerror.h.

Before you do any L2CAP operation, run the l2cap load command one time in the beginning.

back to the top

Read a Bluetooth Address
You can use the readbd command to decide whether Bluetooth hardware was recognized and initialized correctly. This command reads the Bluetooth hardware address of the local Bluetooth device.

Usage: At the BTDC prompt, type readbd.   Example (successful): >readbd BthReadLocalAddr returns 0x00000000 0, address = 008037141e1c   Example (unsuccessful): >readbd BthReadLocalAddr returns 0x00000426 1062, address = 000000000000 

back to the top

Inquire
Use the inquiry command to do Bluetooth inquiry.

Usage: inquiry

Parameters:

LAP: LAP used to build inquiry packet. If 0 is supplied, the General Inquiry Access Code (0x9e8b33) will be used.

Length: Duration of the inquiry in seconds.

Number of responses: Maximum number of responses that inquiry returns.   Example (found one Bluetooth device, whose address is 08004621efbd): >inquiry 0x0 30 5 BthPerformInquiry returns 0x00000000 0 08004621efbd cod = 0x00420210 clock = 0x38a7 page = 0 period = 0 repetition = 1 

back to the top

Ping
Use the ping command to do an L2CAP ping. Before you use any L2CAP commands, you must first call 12cap load.

Usage: ping   Example: >l2cap load L2CAPLoad : 0 >ping 08004621efbd L2CAPPing returns 0x00000000 (0) Ping data> 0000 42 00 54 00 20 00 57 00 |  B.T. .W.    Ping data> 0008 69 00 6e 00 43 00 45 00  |  i.n.C.E.    Ping data> 0010 20 00 76 00 30 00 30 00  |   .v.0.0. Ping data> 0018 30 00 31 00 2e 00 30 00 |  0.1...0. Ping data> 0020 30 00 30 00 31 00 20 00 |  0.0.1. .   Ping data> 0028 65 00 63 00 68 00 6f  00  |  e.c.h.o.    Ping data> 0030 20 00 72 00 65 00 71 00  |   .r.e.q.    Ping data> 0038 20 00 69 00 64 00 20 00  |   .i.d.. Ping data> 0040 30 00 32 00 39 00 20 00 |  0.2.9. .   Ping data> 0048 72 00 65 00 73 00 70 00  |  r.e.s.p.    Ping data> 0050 6f  00 6e 00 73 00 70 00  |  o.n.s.e.    Ping data> 0058 20 00 31 00 00 00           |   .l </li></ul>

back to the top

Set and Revoke PIN Numbers
To set a PIN, use the setpin command; to revoke a PIN, use revpin.   Setting a PIN

Usage: setpin

Parameters:

Bluetooth address: the address with which the PIN is associated.

Byte Sequence: PIN number in byte sequence (ASCII code).

Example (set PIN number for device08004621efbd to 1234 (ASCII 31323334)): >setpin 08004621efbd 31323334 BthSetPIN returns 0x00000000 0 </li>  Revoking a PIN

Usage: revpin

Parameters:

Bluetooth address: the address with which the PIN is associated.

Example (revoke PIN number for device08004621efbd): >revpin 08004621efbd BthRevokePIN returns 0x00000000 0 </li></ul>

back to the top

Establish an L2CAP Connection, Write Data, and Disconnect
To establish an L2CAP connection between two Bluetooth devices, to write, and to disconnect, use the following commands: accept, connect, write, disconnect, and unaccept.

You must use the 12cap load command before you run any L2CAP commands; you have to run 12cap load only one time.

The following samples of code show how to establish a L2CAP connection, write the &quot;Hello&quot; string from the device that initiates the connection, and then disconnect:   On the device that is meant to accept the incoming connection, run the following code: >l2cap load L2CAPLoad : 0 >accept 0x1231 0x0 L2CAPAccept returns 0x00000000 (0) >Listen thread created for psm = 0x1231 </li>  On the device that will initiate the connection, run the following code: >l2cap load L2CAPLoad : 0 >connect 008037141e1c 0x1231 0x0 Attempting to connect to BT_ADDR 008037141e1c psm = 0x1231 L2CAPConnect returns 0x00000000 (0) >Read thread created for connection 0x0041 >write 0x0041 hello L2CAPWrite returns 0x00000000 (0) >disconnect 0x0041 L2CAPCloseCID returns 0x00000000 (0) Error 0x000004b1 (1201) </li>  To quit the listening thread, on the device that accepts the incoming connection, run the following code: >unaccept 0x1231 L2CAPClosePSM returns 0x00000000 (0) </li></ul>

NOTE: The connect command returns the connection handle (0x0041 in the previous example), which is used by other L2CAP connection-related commands. After write succeeds, &quot;Hello&quot; appears on the receiving device.

back to the top

Establish an RFCOMM Connection, Write Data, and Disconnect
To establish an RFCOMM connection between two Bluetooth devices, to write data, and to disconnect, use the following commands: rfcomm create, rfcomm open, rfcomm write, and rfcomm destroy.

The following example shows how to establish a RFCOMM connection, to write &quot;Hello&quot; from the device that initiates the connection, and then disconnect.   On the device that is meant to accept the incoming connection, run the following code: >rfcomm create 9 server 1 handle = 0x00436f50 >rfcomm open 9 Opened COM9:, handle 0x21cf23da </li>  On the device that initiates the connection, run the following code: >rfcomm create 9 client 008037141e1c 1 handle = 0x0042f320 >rfcomm open 9 Opened COM9:, handle 0x21d1a062 >rfcomm write 9 hello Result = 0x00000001 Bytes written 12 >rfcomm destroy 9 Exiting thread for port COM9: </li>  To quit the listening thread, on the device that accepts the incoming connection, run the following code: >rfcomm destroy 9 Exiting thread for port COM9: </li></ul>

NOTE: After write succeeds, &quot;Hello&quot; appears on the receiving device.

back to the top

Add and Delete SDP Records
To add an SDP record, use the sdpAddRecord command; to delete a record, use sdpDelRecord.

The following data types are supported: SEQUENCE, UUID16, UUID32, UUID128, UINT8, UINT16, INT32, UINT64, UINT128, INT8, INT16, INT32, INT128, BOOLEAN, STRING, URL, and Nil.

Before you add a service record, you have to first write the content of the record in a file. The general format of the file is:

[Attribute Id] [Data Type] [Data]

See the example of a service record file later under this point.   Adding a service record:

Usage: sdpAddRecord

Parameters: filename: Name of the file that contains the SDP record to be added.

Example: >sdpAddRecord ftp.record BthNsSetService returns 0x00000000, record handle = 0x00427010,GLE=0x00000000 NOTE: GLE is the error code that is returned by GetLastError. For a list of SDP error codes, see \public\common\sdk\inc\bt_sdp.h. </li>  Deleting a service record

Usage: sdpDelRecord

Parameters: Handle: handle of the SDP record that you want to delete.

Example: >sdpDelRecord 0x00427010<BR/> BthNsSetService returns 0x00000000,GLE=0x00000000 </li> Example of a service record file

The following code is an example of a service record file (lines beginning with ; are comments).</li></ul>

<pre class="fixed_text">;; This file is provided as a sample to show how to create an SDP record. To


 * add an SDP record into the SDP database, run btdc.exe and then &quot;sdpAddRecord [fileName]&quot;

1 SEQUENCE ; FTP service class UUID UUID16 1106 END

4 SEQUENCE SEQUENCE ; L2CAP protocol identifier UUID16 100 END

SEQUENCE ; RFCOMM protocol identifier UUID16 3 ; NOTE: FTP is not guaranteed to run on RFCOMM channel 10. ; This value may have to change at run time to appropriate channel. UINT8 A   END SEQUENCE ; OBEX protocol. UUID16 8 END

END

6 SEQUENCE ; language base ID information UINT16 656E UINT16 6A UINT16 100 END

9 SEQUENCE SEQUENCE ; profile descriptor list. ; Protocol 1106 UUID16 1106 ; profile version for 1106 UINT16 100 END END 100 STRING FTP back to the top

Search SDP Services or Attributes
To search the SDP service, use the sdpServiceSearch command; to search an SDP attribute, use sdpAttribSearch.

Similar to adding an SDP record, you have to first write the content of the search to a file.  <li> Search a service by using sdpServiceSearch

The following shows the format of the file for sdpServiceSearch. must be UUID16, UUID32, or UUID128. There must be at least 1 entry but no more than 12 entries in the file.

[Data Type] [Guid]

An example file would be:

UUID128 00000001-0000-1000-8000-00805F9B34FB

Usage: sdpServiceSearch

Parameters:

Bluetooth device: Bluetooth device address of the device to be queried.

filename: Name of the file that contains the SDP record to be added.

Example: >sdpServiceSearch 08004621efbd servicesearch.txt BthNsLookupServiceBegin returned 0x00000000,GLE=0x00000000 BthNsLookupServiceNext returned 0x00000000,GLE=0x00000000 BthNsLookupServiceNext returned 1 handles Rec[0] = 0x00000000 BthNsLookupServiceEnd returned 0x00000000,GLE=0x00000000 </li> <li> Searching an attribute using sdpAttribSearch

The following is the format of the file for sdpAttribSearch:

[(Attribute ranges, 2 16-bit numbers, ordered from the smallest number to the largest number]

An example file would be: 00000000  0001 0005   0008 0008 Usage: sdpAttribSearch

Parameters:

Bluetooth device: Bluetooth device address of the device to be queried.

filename: Name of the file that contains the SDP record to be added.

Example: >sdpAttribSearch 08004621efbd attribsearch.txt BthNsLookupServiceBegin returned 0x00000000,GLE=0x00000000 BthNsLookupServiceNext returned 0x00000000,GLE=0x00000000 BthNsLookupServiceNext return buf size = 36 bytes 35, 22, 09, 00, 01, 35, 03, 19, 10, 00, 09, 00, 04, 35, 0d, 35, 06, 19, 01, 00, 09, 00, 01, 35, 03, 19, 00, 01, 09, 00, 05, 35, 03, 19, 10, 02,

BthNsLookupServiceEnd returned 0x00000000,GLE=0x00000000 </li></ul>

back to the top

SDP Service Attribute Search
To search an SDP service attribute, use the sdpServAttribSearch command.

Similar to adding an SDP record, you have to first write the content of the search to a file. The following is the format of the file:

[Data Type] [Guid] END [(Attribute ranges, 2 16-bit numbers, ordered from the smallest number to the largest number]

The data type must be one of the following: UUID16, UUID32, or UUID128. There must be at least 1 entry but no more than 12 entries in the file.

Usage: sdpServAttribSearch

Parameters:

Bluetooth device: Bluetooth device address of the device to be queried.

filename: Name of the file that contains the SDP record to be added. <ul> <li> An example file would be: UUID128 00000001-0000-1000-8000-00805F9B34FB END

0001 0005  0008 0008                    </li> <li> Example: >sdpServAttribSearch 08004621efbd servattribsearch.txt BthNsLookupServiceBegin returned 0x00000000,GLE=0x00000000 BthNsLookupServiceNext returned 0x00000000,GLE=0x00000000 BthNsLookupServiceNext returned return buf size = 38 bytes 35, 24, 35, 22, 09, 00, 01, 35, 03, 19, 10, 00, 09, 00, 04, 35, 0d, 35, 06, 19, 01, 00, 09, 00, 01, 35, 03, 19, 00, 01, 09, 00, 05, 35, 03, 19, 10, 02,

BthNsLookupServiceEnd returned 0x00000000,GLE=0x00000000 </li></ul>

back to the top

Keywords: kbhowto kbhowtomaster KB328900

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.