Programming interface

User space API

API provides interface to the Bluetooth driver for the user space programs and includes:

  • HCI functions which are used to manage Bluetooth devices.

  • RFCOMM functions. Used to create and destroy RFCOMM connections.

  • SDP functions to access local and remote SDP databases.

API is implemented as a set of shared libraries (e.g. libaffix.so) which are used by client programs.

For more details about implemented functions look at the include/affix/btcore.h.

For more details how to use interfaces look at implementation of tctl.c, btsrv-main.c.

Socket interface

Programming interface includes Berkeley socket interface for the user space programs. This software introduce new protocol family - PF_AFFIX, consisting of protocols used in the Bluetooth stack. To create the bluetooth socket the standard socket function is used:

fd = socket(PF_AFFIX, type, protocol);

Parameter type can be SOCK_RAW or SOCK_STREAM, protocol defines which protocol to use with the socket.

Protocol family uses new socket address structure:

struct sockaddr_affix {
        sa_family_t family;
        BD_ADDR     bda;
        uint16_t    port;
        BD_ADDR     local;
};

where family is PF_AFFIX, bda is Bluetooth device address (6 bytes) and port is PSM or server_channel value of the destination protocol/service, depending on the protocol.

Currently two protocols are used in the PF_AFFIX family:

BTPROTO_L2CAP

Socket with this protocol is used to create L2CAP connection to another device. Socket type is SOCK_STREAM here. This socket is used for example by the SDP server.

Before socket can be used it should be connected to the particular device, using connect system call:

err = connect(fd, sockaddr, addrlen);

send() and recv() syscalls is used to send and receive packets form the devices.

BTPROTO_RFCOMM

Socket with this protocol is used to create RFCOMM connection to another device. Socket type is SOCK_STREAM here. This socket can be used by SDP protocol.

Before socket can be used it should be connected to the particular device, using connect system call:

err = connect(fd, sockaddr, addrlen);

For more details how to use interfaces look at implementation of btctl.c, btsrv-main.c.

Assigned numbers

These numbers assigned for testing purpose and should be registered to prevent conflicts. Those numbers have been selected as if they were not used in the kernel.

  1. Line discipline for the Bluetooth card (with serial interface).

    #define N_NCC 14
  2. Type of the Bluetooth network device interface and BLUETOOTH packet type

    #define ARPHRD_BLUETOOTH 0x8000
    #define ETH_P_BLUETOOTH  0x0027
  3. Socket protocol family.

    #define PF_AFFIX  27
    #define AF_AFFIX  PF_AFFIX
    #define SOL_AFFIX 277
  4. Virtual terminal major number.

    #define BTY_MAJOR 60