RFCOMM(7)
π RFCOMM(7) π
okay so this is the rfcomm page from Linux System Administration β RFCOMM protocol edition, and yes bestie, weβre getting into the Bluetooth serial-port emulation lore. π¦
πΈ NAME πΈ
rfcomm β RFCOMM protocol
β¨ SYNOPSIS β¨
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
rfcomm_socket = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
π« DESCRIPTION π«
The RFCOMM protocol gives you serial port emulation over the L2CAP(7) protocol. Itβs based on the ETSI standard TS 07.10. No cap, thatβs literally the foundation. π
RFCOMM is a simple transport protocol, but it also has extra provisions for emulating the 9 circuits of RS-232 (EIATIA-232-E) serial ports. Itβs giving βserial ports but make it Bluetooth.β π
π¬ 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 π οΈ
The socket options listed below can be set with setsockopt(2) and read with getsockopt(2), with the socket level set to SOL_BLUETOOTH. Slay. π₯
π BT_SECURITY (since Linux 2.6.30) π
Channel security level β possible values, bestie:
BT_SECURITY_SDPβ Security Level:0 (SDP Only); Link Key Type:None; Encryption:Not required.BT_SECURITY_LOWβ Security Level:1 (Low); Link Key Type:Unauthenticated; Encryption:Not required.BT_SECURITY_MEDIUMβ Security Level:2 (Medium - default); Link Key Type:Unauthenticated; Encryption:Desired.BT_SECURITY_HIGHβ Security Level:3 (High); Link Key Type:Authenticated; Encryption:Required.BT_SECURITY_FIPS(since Linux 3.15) β Security Level:4 (Secure Only); Link Key Type:Authenticated (P-256 based Secure Simple Pairing and Secure Authentication); Encryption: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) π‘οΈ
Channel defer connection setup β this controls whether the connection procedure needs to be authorized by userspace before responding, which allows authorization at profile level. Possible values:
- Value
0β Description:Disable (default); Authorization:Not required. - Value
1β Description:Enable; Authorization: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)
Okay so this one's the channel flushable flag β it literally just controls whether the channel's data can be flushed or not. That's it, that's the whole vibe. Possible values:
BT_FLUSHABLE_OFFβ value0x00, and it's the default. Do not flush data.BT_FLUSHABLE_ONβ value0x01. Flush data. πΏ
β‘ BT_CHANNEL_POLICY (since Linux 3.10)
This is the high-speed (AMP) channel policy bestie, possible values:
BT_CHANNEL_POLICY_BREDR_ONLYβ value0(the default). BR/EDR only.BT_CHANNEL_POLICY_BREDR_PREFERREDβ value1. BR/EDR Preferred.BT_CHANNEL_POLICY_BREDR_PREFERREDβ value2. AMP Preferred.
π«Ά ngl, values1and2both shipping with the same define name is exactly what the page says, so I'm not touching it β I'm just the messenger π
π¦ BT_PHY (since Linux 5.10)
Channel supported PHY(s), possible values β and yes, these are bit flags, so you can stack them:
BT_PHY_BR_1M_1SLOTβBIT 0β BR 1Mbps 1SLOTBT_PHY_BR_1M_3SLOTβBIT 1β BR 1Mbps 3SLOTBT_PHY_BR_1M_5SLOTβBIT 2β BR 1Mbps 5SLOTBT_PHY_BR_2M_1SLOTβBIT 3β EDR 2Mbps 1SLOTBT_PHY_BR_2M_3SLOTβBIT 4β EDR 2Mbps 3SLOTBT_PHY_BR_2M_5SLOTβBIT 5β EDR 2Mbps 5SLOTBT_PHY_BR_3M_1SLOTβBIT 6β EDR 3Mbps 1SLOTBT_PHY_BR_3M_3SLOTβBIT 7β EDR 3Mbps 3SLOTBT_PHY_BR_3M_5SLOTβBIT 8β EDR 3Mbps 5SLOT
Nine PHYs, all iconic in their own way π
π RESOURCES
http://www.bluez.org
That's the mothership, go say hi β¨
π REPORTING BUGS
linux-bluetooth@vger.kernel.org
Found something cursed? Email the list. They're chill, fr fr π
π SEE ALSO
π COPYRIGHT
Free use of this software is granted under the terms of the GNU Lesser General Public Licenses (LGPL).
That's the whole page bestie, you ate that π β¨ This little masterpiece is brought to you by BlueZ β dated May 2024 β and answers to the name RFCOMM(7) ππ¦ Go forth and bind those sockets, mwah π
π¦ where this page comes from
- centos-stream 9: bluez-libs-devel 5.87+2.git8750129efca8-1.el9 Β· GPLv2+
- centos-stream 9: bluez-libs-devel 5.87+2.git8750129efca8-1.el9 Β· GPLv2+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms