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:
mask 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
Use the Debugging Tool
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
LAPlengthnumber of responsesParameters:
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.
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
Bluetooth address
back to the top
Set and Revoke PIN Numbers
To set a PIN, use the
setpin command; to revoke a PIN, use
revpin.
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 "Hello" 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
- 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)
- To quit the listening thread, on the device that accepts the incoming connection, run the following code:
>unaccept 0x1231
L2CAPClosePSM returns 0x00000000 (0)
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, "Hello" 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 "Hello" 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
- 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:
- 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:
NOTE: After
write succeeds, "Hello" 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 filename
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. - Deleting a service record
Usage: sdpDelRecord handle
Parameters: Handle: handle of the SDP record that you want to delete.
Example:
>sdpDelRecord 0x00427010<BR/>
BthNsSetService returns 0x00000000,GLE=0x00000000
- Example of a service record file
The following code is an example of a service record file (lines beginning with ; are comments).
;; 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 "sdpAddRecord [fileName]"
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.
- Search a service by using sdpServiceSearch
The following shows the format of the file for sdpServiceSearch. Data Type must be UUID16, UUID32, or UUID128. There must be at least 1 entry but no more than 12 entries in the file.
An example file would be:
UUID128 00000001-0000-1000-8000-00805F9B34FB
Usage: sdpServiceSearch Bluetooth devicefilename
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
- Searching an attribute using sdpAttribSearch
The following is the format of the file for sdpAttribSearch:
Service Record Handle (9 Hex digits)
[(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 Bluetooth devicefilename
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
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
Bluetooth devicefilenameParameters:
Bluetooth device: Bluetooth device address of the device to be queried.
filename: Name of the file that contains the SDP record to be added.
- An example file would be:
UUID128 00000001-0000-1000-8000-00805F9B34FB
END
0001 0005
0008 0008
- 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
back to the top