Man page - l2cap(7)

Packages contains this manual

Manual

L2CAP

NAME
SYNOPSIS
DESCRIPTION
SOCKET ADDRESS
SOCKET OPTIONS
BT_SECURITY (since Linux 2.6.30)
BT_DEFER_SETUP (since Linux 2.6.30)
BT_FLUSHABLE (since Linux 2.6.39)
BT_POWER (since Linux 3.1)
BT_CHANNEL_POLICY (since Linux 3.10)
BT_PHY (since Linux 5.10)
BT_MODE (since Linux 5.10)
RESOURCES
REPORTING BUGS
SEE ALSO
COPYRIGHT

NAME

l2cap - L2CAP protocol

SYNOPSIS

#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/l2cap.h>

l2cap_socket = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);

DESCRIPTION

L2CAP is a protocol that provides an interface for higher-level protocols to send and receive data over a Bluetooth connection. L2CAP sits on top of the Bluetooth Host Controller Interface (HCI) and provides a set of channels that can be used by higher-level protocols to transmit data.

L2CAP provides a number of services to higher-level protocols, including segmentation and reassembly of large data packets and flow control to prevent overloading of the receiver. L2CAP also supports multiple channels per connection, allowing for concurrent data transmission using different protocols.

SOCKET ADDRESS

struct sockaddr_l2 {
sa_family_t l2_family;
unsigned short l2_psm;
bdaddr_t l2_bdaddr;
unsigned short l2_cid;
uint8_t l2_bdaddr_type;
};

Example:

struct sockaddr_l2 addr;

memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, bdaddr);

if (cid)
addr.l2_cid = htobs(cid);
else
addr.l2_psm = htobs(psm);

addr.l2_bdaddr_type = bdaddr_type;

SOCKET OPTIONS

The socket options listed below can be set by using setsockopt(2) and read with getsockopt(2) with the socket level set to SOL_BLUETOOTH.

BT_SECURITY (since Linux 2.6.30)

Channel security level, possible values:

Image grohtml-3912797-1.png

Example:

int level = BT_SECURITY_HIGH;
int err = setsockopt(l2cap_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 control if the connection procedure needs to be authorized by userspace before responding which allows authorization at profile level, possible values:

Image grohtml-3912797-2.png

Example:

int defer_setup = 1;
int err = setsockopt(l2cap_socket, SOL_BLUETOOTH, BT_DEFER_SETUP,
&defer_setup, sizeof(defer_setup));
if (err == -1) {
perror("setsockopt");
return err;
}

err = listen(l2cap_socket, 5);
if (err) {
perror("listen");
return err;
}

struct sockaddr_l2 remote_addr = {0};
socklen_t addr_len = sizeof(remote_addr);
int new_socket = accept(l2cap_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)

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

Image grohtml-3912797-3.png

BT_POWER (since Linux 3.1)

Channel power policy, this control if the channel shall force exit of sniff mode or not, possible values:

Image grohtml-3912797-4.png

BT_CHANNEL_POLICY (since Linux 3.10)

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

Image grohtml-3912797-5.png

BT_PHY (since Linux 5.10)

Channel supported PHY(s), possible values:

Image grohtml-3912797-6.png

BT_MODE (since Linux 5.10)

Channel Mode, possible values:

Image grohtml-3912797-7.png

RESOURCES

<http://www.bluez.org>

REPORTING BUGS

<linux-bluetooth@vger.kernel.org>

SEE ALSO

socket(7), l2test(1)

COPYRIGHT

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