Create a Serial Port Profile (SPP) connection to a service on a remote Bluetooth
device (server)
Synopsis:
#include <btapi/btspp.h>
int bt_spp_open(char *addr, char *service_uuid, bool nonblock)
Arguments:
- addr
-
The remote Bluetooth device (server) address. The address is in the following format:
2:2:2:2:2:2, where each digit indicates the number of hexadecimal digits. For example:
00:11:22:33:AA:BB.
- service_uuid
-
The Universally Unique Identifier (UUID) or the name of the service to connect to. If
this parameter represents the UUID, it must be the service ID defined by the
developer, not the Service Class ID assigned by the Bluetooth organization. For
example, the SPP profile has a 4-digit Service Class ID of
0x1101. A
developer can create multiple services for this service class, and must define a
unique service ID for each of the services. This function searches for the intended
service using the input UUID when the input matches a supported service ID format. If
service_uuid does not match any supported UUID format, this
argument is considered to contain the service name, which has a maximal length of 50
including the terminating NULL character. Then the search for the service is done by
service name and generic SPP attributes. If this argument represents the service ID,
it must be in one of the following formats:
- "0x1101": search by generic SPP attributes
- "0x1101:<uuid>": search by UUID <uuid>
- "<uuid>": search by UUID <uuid> where <uuid> is in
<8-4-4-4-12> format, in which each digit indicates the number of hexadecimal
digits.
For example, a valid service ID can be:
- "00001101-1111-2222-3333-444444444444": search by service UUID
"00001101-1111-2222-3333-444444444444"
- "0x1101:00001101-1111-2222-3333-444444444444": search by
service UUID "00001101-1111-2222-3333-444444444444"
- "0x1101": search by generic SPP attributes
- "0x1102": search by service name "0x1102" and
generic SPP attributes
- "3rd party SPP service": search by service name "3rd
party SPP service" and generic SPP attributes
- nonblock
-
A flag that specifies whether to open a mount point of the connection in non-blocking
mode. A value of true means opening the connection in non-blocking
mode.
Library:
libbtapi (For the qcc command, use the -l btapi
option to link against this library)
Description:
The connection can be opened in non-blocking or blocking
mode. After you successfully call this function, and when your application is finished with
the file descriptor that is returned from this function, call the bt_spp_close() function to clean up
resources.
Returns:
The mount point file descriptor if a connection has been
successfully created,
-1 with the
errno set otherwise. The
errno can be set to one of the following values when
-1
is returned. If the
errno is set to any other value than the following, a
system error has occurred.
- EINVAL: Invalid arguments were specified.
- EPERM: The bt_spp_init() function has not been called or has failed.
- ENONMEM: There is insufficient memory to allocate to complete the
function.
- ESRVRFAULT: The operation was aborted by the user.
- EBADMSG: There was an error parsing the incoming message.
- EMLINK: A connection to the same service on the same device has
already been established.
- ENODATA: A failure occurred because an error occurred on the stack.