Chapter 7. iWRAP - Bluetooth Interface

The Bluetooth service in Access Server is controlled through the TCP socket interface called iWRAP. The first iWRAP server is listening on port 10101. In the case of Access Server 2293, the second iWRAP server is listening on port 10102, and the third one is listening on port 10103. All commands to an iWRAP server and replies from the server are plain ASCII strings ending in CR+LF ("\r\n"). Commands and replies are not case sensitive.

When connecting to a server, you must first wait for the READY. prompt. Do not send any commands prior to this. Some replies are broadcast to all clients of the server. If you see something that you have not requested or that is not intended for your client (identified by the link identifier), simply ignore the reply.

Normally, the iWRAP is protected with the buffy password. The password can be disabled or changed. For more information, see the SET command. If the password is enabled, it must be sent first, immediately following the READY. prompt, to the iWRAP server. Otherwise, all commands will fail.

For an example of using the iWRAP, please see the asdk/examples/btsend file in the SDK directory.

In the following examples, bold lines are commands sent by the client to the iWRAP server and normal lines are replies received from the iWRAP server by the client.

7.1. Terms

Bluetooth address (bdaddr) consists of six hex digits separated by a colon. For example, "00:07:80:80:bf:01". With commands requiring a Bluetooth address, you can also use the Bluetooth friendly name instead.

Bluetooth channels are numbered from 1 to 30. In Access Server, the Serial Port Profile is assigned to channel number two, the Object Push Profile and File Transfer Profile to channel number three, and the LAN Access Profile is on channel number four. The other channels are free for user applications.

Link Identifier (link_id) is a number from 0 to 99. It is used to identify established Bluetooth connections.

7.2. Starting the iWRAP Servers

Normally, the iWRAP servers are started automatically upon power-up. You can restart the servers manually (for example, to apply the changes made to the iWRAP settings with the setup application without rebooting the system). To restart the servers manually, execute the startup script with option restart:

[root@wrap /] /etc/init.d/bluetooth restart

When the iWRAP servers start up, they use the settings configured with the setup application. You can put additional iWRAP commands to the /etc/bluetooth.conf file. The commands in that file are processed as the last task every time the iWRAP server is started.

7.3. Writing iWRAP Applications

There are two approaches when writing a iWRAP server program (a program accepting incoming calls) for Access Server, both having different pros and cons:

  1. Forklistener

  2. iWRAP Client

Note: When writing a client program (that is, a program making an outgoing call), you have to use iWRAP.

7.3.1. Forklistener

This is a standard program reading data from standard input and writing output to standard output. See the SDK directory examples/forkserver/ for an example of this kind of program.

Pros:

  • Easy to write.

  • Very robust for simple services.

  • You do not have to understand Bluetooth or iWRAP.

Cons:

  • Your program is started and stopped for every incoming connection.

  • If there are multiple connections, it is not possible to communicate to an external program through one socket.

  • You cannot use stdout for debugging; you must use syslog or a log file.

  • iWRAP's advanced features are not available: powermodes, MSC, SDP, inquiry, ...

To setup a forklistener, see the SET command.

7.3.2. iWRAP Client

iWRAP client is a program communicating with the iWRAP server through control and data sockets. See the SDK directory examples/btserver/ for an example of this kind of program.

Pros:

  • The cons with forklistener do not apply.

Cons:

  • More complex than forklistener.

  • You must have basic knowledge about Bluetooth and iWRAP.

For documentation about iWRAP, read this chapter carefully.

7.4. Commands Controlling iWRAP

Table of Contents
INFO -- Get basic info
QUIT -- Close iWRAP connection
SET -- Change parameters
SAVE -- Save iWRAP settings
LOAD -- Run iWRAP command script
PING -- Ask if the connection is alive
PONG -- Connection is alive
ECHO -- Send a message to other iWRAP clients
LOCK -- Lock other iWRAP clients
UNLOCK -- Unlock other iWRAP clients
SHUTDOWN -- Close iWRAP server
SLEEP -- Wait a second

7.5. Finding Bluetooth Devices

Table of Contents
INQUIRY -- Search for other devices
NAME -- Find a friendly name

7.6. Making a Bluetooth Connection

Table of Contents
CALL -- Connect to other device
CONNECT -- Connected to other device
NO CARRIER -- Disconnected from other device
RING -- Another device is calling you
RINGING -- Call in progress
CLOSE -- Disconnect
LIST -- List connections
STATUS -- Status of a connection

7.7. Service Discovery

Table of Contents
SDPSEARCH -- Browse SDP Records
SDPATTR -- Browse SDP Records
SDPQUERY -- Browse SDP Records
SDP bdaddr -- Check devices SDP
SDP ADD -- Add entry to local SDP
SDP DEL -- Delete entry for local SDP
SDP LIST -- List local SDP

This section describes the commands used for Bluetooth service discovery and local SDP record manipulation. The commands and their replies use SDP UUID and attribute values, which are listed in the Bluetooth Assigned Numbers documentation. In the commands below, the most useful UUID and attribute values can, however, be replaced with keywords listed in Table 7-3. The same keywords are used in the command replies instead of numeric values, if the parameter SET BLUETOOTH READABLE is set to 1.

Table 7-3. Supported Keywords for Replacing SDP UUIDs or Attributes

Keyword(s)ValueHex Value
SDPUUID_SDP0001
RFCOMMUUID_RFCOMM0003
OBEXUUID_OBEX0008
BNEPUUID_BNEP000F
L2CAPUUID_L2CAP0100
PUBLICBROWSEGROUP, BROWSE, ROOTUUID_PUBLIC_BROWSE_GROUP1002
SERIALPORT, SPPUUID_SERIALPORT1101
LANACCESS, LANUUID_LANACCESS1102
DIALUPNETWORKING, DUNUUID_DIALUPNETWORKING1103
OBEXOBJECTPUSH, OBJP, OPPUUID_OBEXOBJECTPUSH1105
OBEXFILETRANSFER, FTPUUID_OBEXFILETRANSFER1106
PAN-PANU, PANUUUID_PANU1115
PAN-NAP, NAPUUID_NAP1116
PAN-GN, GNUUID_GN1117
PROTOCOLDESCRIPTORLIST, DESCLIST, DESCATTR_PROTOCOLDESCRIPTORLIST0004
SERVICENAME, NAMEATTR_SERVICENAME + BASE_LANG_OFFSET0000 + 0100
SECURITYDESCRIPTIONATTR_SECURITYDESCRIPTION030A
NETACCESSTYPEATTR_ NETACCESSTYPE030B
MAXNETACCESSRATEATTR_ MAXNETACCESSRATE030C

7.8. Example Sessions

Outgoing RFCOMM Call:


      READY.
      CALL 00:07:80:80:bf:01 1 RFCOMM
      CALL 2
      RINGING 2
      CONNECT 2 RFCOMM 1042
      STATUS 2 MSC 8d
      <Client opens socket connection to port 1042 and transfers data>
      CLOSE 2
      NO CARRIER 2 ERROR 000
    

Incoming RFCOMM Call:


      READY.
      RING 2 00:07:80:80:bf:01 1 RFCOMM 1042
      STATUS 2 MSC 8d
      <Client opens socket connection to port 1042 and transfers data>
      NO CARRIER 2 ERROR 000
    

7.9. Error Codes

Some commands may reply with an error code. The human-readable name of the error is displayed, if the SET BLUETOOTH READABLE setting has value 1. Error code 8 indicates that the iWRAP server is busy executing a number of commands; there can be several client applications using the stack. Just wait a few seconds and try again. Other error codes indicate unexpected, but often only temporary, communication problems.

You can analyze the error from the numeric code. Values bigger than or equal to 900 are iWRAP errors, described in Table 7-5.

Table 7-5. iWRAP Errors

CodeTextual FormReason
900SERVICE_NOT_FOUNDTried to CALL a device whose SDP records do not include the requested service.
901ALREADY_CONNECTEDTried to CALL a device and a service channel that is already connected.
902OUT_OF_HANDLESTried to CALL, but there are too many open connections.
903INVALID_ADDRESS_<addr>Tried to CALL a device with a friendly name that could not be found with the inquiry.
904REJECTEDAn incoming call was rejected by the iWRAP server.
905BUSYTried to issue SDPATTR, but another SDP request was in progress.
906BUSYTried to issue SDPQUERY, but another SDP request was in progress.
907NOT_CONNECTEDTried to CLOSE a connection handle that is not active.
908BUSYTried to issue SDPSEARCH, but another SDP request was in progress.
909INVALID_ADDRESSTried to NAME a device with a friendly name that cannot be found with the inquiry.
90aBUSYTried to issue NAME, but another NAME was in progress.

Other error codes can be analyzed as follows. For example, NO CARRIER ERROR 465: The number 465 is hexadecimal, the sum of 0x400 and 0x65, where 0x400 is a mask, which means that this is an RFCOMM level error. 0x65 (decimal 101) means that the RFCOMM error was a connection timeout.

Table 7-6. Errors Masks

MaskError level
0x100HCI
0x200L2CAP
0x300SDP
0x400RFCOMM

The error codes for each mask are listed in the following tables.

Table 7-7. HCI Error Codes

HCI ErrorCode
HCI_SUCCESS0
HCI_ERR_UNKNOWN_COMMAND1
HCI_ERR_NOCONNECTION2
HCI_ERR_HARDWARE_FAIL3
HCI_ERR_PAGE_TIMEOUT4
HCI_ERR_AUTHENTICATION_FAILED5
HCI_ERR_KEY_MISSING6
HCI_ERR_MEMORY_FULL7
HCI_ERR_CONNECTION_TIMEOUT8
HCI_ERR_MAX_NUM_CONNECTIONS9
HCI_ERR_MAX_NUM_SCO_CONNECTIONS10
HCI_ERR_ACL_CONN_ALREADY_EXISTS11
HCI_ERR_COMMAND_DISALLOWED12
HCI_ERR_HOST_REJECTED_0D13
HCI_ERR_HOST_REJECTED_0E14
HCI_ERR_HOST_REJECTED_0F15
HCI_ERR_HOST_TIMEOUT16
HCI_ERR_UNSUPPORTED_PARAM_VALUE17
HCI_ERR_INVALID_HCI_PARAMETER_VALUE18
HCI_ERR_OTHER_END_TERMINATE_1319
HCI_ERR_OTHER_END_TERMINATE_1420
HCI_ERR_OTHER_END_TERMINATE_1521
HCI_ERR_CONNECTION_TERMINATE_LOCALLY22
HCI_ERR_REPEATED_ATTEMPTS23
HCI_ERR_PARING_NOT_ALLOWED24
HCI_ERR_UNKNOWN_LMP_PDU25
HCI_ERR_UNSUPPORTED_REMOTE_FEATURE26
HCI_ERR_SCO_OFFSET_REJECTED27
HCI_ERR_SCO_INTERVAL_REJECTED28
HCI_ERR_SCO_AIR_MODE_REJECTED29
HCI_ERR_INVALID_LMP_PARAMETERS30
HCI_ERR_UNSPECIFIED_ERROR31
HCI_ERR_UNSUPPORTED_LMP_PARAMETER_VAL32
HCI_ERR_ROLE_CHANGE_NOT_ALLOWED33
HCI_ERR_LMP_RESPONSE_TIMEOUT34
HCI_ERR_LMP_ERROR_TRANSACTION_COLLISION35
HCI_ERR_LMP_PDU_NOT_ALLOWED36
HCI_ERR_ENCRYPTION_MODE_NOT_ACCEPTABLE37
HCI_ERR_UNIT_KEY_USED38
HCI_ERR_QOS_NOT_SUPPORTED39
HCI_ERR_INSTANT_PASSED40
HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPP41
HCI_ERR_ILLEGAL_HANDLE100
HCI_ERR_TIMEOUT101
HCI_ERR_OUTOFSYNC102
HCI_ERR_NO_DESCRIPTOR103

Table 7-8. L2CAP Error Codes

L2CAP ErrorCode
L2CAP_NO_CAUSE0
L2CAP_ERR_PENDING1
L2CAP_ERR_REFUS_INV_PSM2
L2CAP_ERR_REFUS_SEC_BLOCK3
L2CAP_ERR_REFUS_NO_RESOURCE4
L2CAP_ERR_TIMEOUT_EXTERNAL 0xee

Table 7-9. SDP Error Codes

SDP ErrorCode
SDP_ERR_RESERVED0
SDP_ERR_UNSUPPORTED_SDP_VERSION1
SDP_INVALID_SERVICE_RECORD_HANDLE2
SDP_INVALID_REQUEST_SYNTAX3
SDP_INVALID_PDU_SIZE4
SDP_INVALID_CONTINUATION_STATE5
SDP_INSUFFICIENT_RESOURCES6
SDP_ERR_UNHANDLED_CODE100
SDP_ERR_TIMEOUT101
SDP_ERR_NOTFOUND102
SDP_INVALID_RESPONSE_SYNTAX103
SDP_NOT_FOUND (not really an error)200

Table 7-10. RFCOMM Error Codes

RFCOMM ErrorCode
RFCOMM_SUCCESS 0
RFCOMM_ERR_NORESOURCES1
RFCOMM_ERR_ILL_PARAMETER2
RFCOMM_ERR_REJECTED (Connection setup was rejected by remote side)100
RFCOMM_ERR_TIMEOUT (Connection timed out)101
RFCOMM_ERR_NSC (Non supported command received)102
RFCOMM_ERR_ILLPARAMETER103

If the problems persist after restarting the communication parties, please contact Bluegiga Technologies as instructed in Section 1.2.