rfcomm(7) Linux System Administration rfcomm(7)

# [Name](#Name)

rfcomm - RFCOMM protocol

# [SYNOPSIS](#SYNOPSIS)

```
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
rfcomm_socket = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
```

# [DESCRIPTION](#DESCRIPTION)

The RFCOMM protocol provides emulation of serial ports over the [L2CAP(7)](/man/os/bluez/L2CAP.7) protocol. The protocol is based on the ETSI standard TS 07.10.

RFCOMM is a simple transport protocol, with additional provisions for emulating the 9 circuits of RS-232 (EIATIA-232-E) serial ports.

# [SOCKET ADDRESS](#SOCKET_ADDRESS)

```
struct sockaddr_rc {


    sa_family_t rc_family;


    unsigned short rc_bdaddr;


    unsigned char rc_channel;
};
```

Example:

```
struct sockaddr_rc addr;
memset(&addr, 0, sizeof(addr));
addr.rc_family = AF_BLUETOOTH;
bacpy(&addr.rc_bdaddr, bdaddr);
addr.rc_channel = channel;
```

# [SOCKET OPTIONS](#SOCKET_OPTIONS)

The socket options listed below can be set by using [**setsockopt(2)**](/man/os/bluez/setsockopt.2) and read with [**getsockopt(2)**](/man/os/bluez/getsockopt.2) with the socket level set to SOL\_BLUETOOTH.

## [BT\_SECURITY (since Linux 2.6.30)](#BT_SECURITY_%28since_Linux_2.6.30%29)

Channel security level, possible values:

Value Security Level Link Key Type Encryption **BT\_SECURITY\_SDP** 0 (SDP Only) None Not required **BT\_SECURITY\_LOW** 1 (Low) Unauthenticated Not required **BT\_SECURITY\_MEDIUM** 2 (Medium - default) Unauthenticated Desired **BT\_SECURITY\_HIGH** 3 (High) Authenticated Required **BT\_SECURITY\_FIPS** (since Linux 3.15) 4 (Secure Only) Authenticated (P-256 based Secure Simple Pairing and Secure Authentication) Required

Example:

```
int level = BT_SECURITY_HIGH;
int err = setsockopt(rfcomm_socket, SOL_BLUETOOTH, BT_SECURITY, &level,


                     sizeof(level));
if (err == -1) {


    perror("setsockopt");


    return 1;
}
```

## [BT\_DEFER\_SETUP (since Linux 2.6.30)](#BT_DEFER_SETUP_%28since_Linux_2.6.30%29)

Channel defer connection setup, this control if the connection procedure needs to be authorized by userspace before responding which allows authorization at profile level, possible values:

Value Description Authorization **0** Disable (default) Not required **1** Enable Required

Example:

```
int defer_setup = 1;
int err = setsockopt(rfcomm_socket, SOL_BLUETOOTH, BT_DEFER_SETUP,


                     &defer_setup, sizeof(defer_setup));
if (err == -1) {


    perror("setsockopt");


    return err;
}
err = listen(rfcomm_socket, 5);
if (err) {


    perror("listen");


    return err;
}
struct sockaddr_rc remote_addr = {0};
socklen_t addr_len = sizeof(remote_addr);
int new_socket = accept(rfcomm_socket, (struct sockaddr*)&remote_addr,


                        &addr_len);
if (new_socket < 0) {


    perror("accept");


    return new_socket;
}
/* To complete the connection setup of new_socket read 1 byte */
char c;
struct pollfd pfd;
memset(&pfd, 0, sizeof(pfd));
pfd.fd = new_socket;
pfd.events = POLLOUT;
err = poll(&pfd, 1, 0);
if (err) {


    perror("poll");


    return err;
}
if (!(pfd.revents & POLLOUT)) {


    err = read(sk, &c, 1);


    if (err < 0) {


        perror("read");


        return err;


    }
}
```

## [BT\_FLUSHABLE (since Linux 2.6.39)](#BT_FLUSHABLE_%28since_Linux_2.6.39%29)

Channel flushable flag, this control if the channel data can be flushed or not, possible values:

Define Value Description **BT\_FLUSHABLE\_OFF** 0x00 (default) Do not flush data **BT\_FLUSHABLE\_ON** 0x01 Flush data

## [BT\_CHANNEL\_POLICY (since Linux 3.10)](#BT_CHANNEL_POLICY_%28since_Linux_3.10%29)

High-speed (AMP) channel policy, possible values:

Define Value Description **BT\_CHANNEL\_POLICY\_BREDR\_ONLY** 0 (default) BR/EDR only **BT\_CHANNEL\_POLICY\_BREDR\_PREFERRED** 1 BR/EDR Preferred **BT\_CHANNEL\_POLICY\_BREDR\_PREFERRED** 2 AMP Preferred

## [BT\_PHY (since Linux 5.10)](#BT_PHY_%28since_Linux_5.10%29)

Channel supported PHY(s), possible values:

Define Value Description **BT\_PHY\_BR\_1M\_1SLOT** BIT 0 BR 1Mbps 1SLOT **BT\_PHY\_BR\_1M\_3SLOT** BIT 1 BR 1Mbps 3SLOT **BT\_PHY\_BR\_1M\_5SLOT** BIT 2 BR 1Mbps 5SLOT **BT\_PHY\_BR\_2M\_1SLOT** BIT 3 EDR 2Mbps 1SLOT **BT\_PHY\_BR\_2M\_3SLOT** BIT 4 EDR 2Mbps 3SLOT **BT\_PHY\_BR\_2M\_5SLOT** BIT 5 EDR 2Mbps 5SLOT **BT\_PHY\_BR\_3M\_1SLOT** BIT 6 EDR 3Mbps 1SLOT **BT\_PHY\_BR\_3M\_3SLOT** BIT 7 EDR 3Mbps 3SLOT **BT\_PHY\_BR\_3M\_5SLOT** BIT 8 EDR 3Mbps 5SLOT

# [RESOURCES](#RESOURCES)

&lt;http://www.bluez.org&gt;

# [REPORTING BUGS](#REPORTING_BUGS)

&lt;linux-bluetooth@vger.kernel.org&gt;

# [SEE ALSO](#SEE_ALSO)

[socket(7)](/man/os/bluez/socket.7), [rctest(1)](/man/os/bluez/rctest.1)

# [Copyright](#Copyright)

Free use of this software is granted under the terms of the GNU Lesser General Public Licenses (LGPL).

May 2024 BlueZ

---

Document: rfcomm(7) from bluez 5.87-r3 (Chainguard OS)
Source: https://github.com/bluez/bluez
