Bluetooth LE L2CAP CID vs. PSM
Asked Answered
B

3

8

I've been teaching myself how to write programs in C for BLE devices using the BlueZ API. However, I seem to be stumped on one particular aspect of the sockaddr_l2 struct. The definition I am using is the following:

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;
};

Now for the part I don't understand: what is the difference between l2_psm and l2_cid? This is what I've gathered so far:

PSM stands for "Protocol Service Multiplexers", and are the L2CAP connection's "port". Source: Bluetooth for Programmers, by Albert Huang

CID stands for "Channel Identifier", and are local names representing a logical channel end-point on the device. Source: http://ecee.colorado.edu/~ecen4242/marko/Bluetooth/Bluetooth/SPECIFICATION/L2CAP.html

Now I'm sure the answer is in those definitions, but I just can't seem to wrap my head around the definition of CID. Can anyone explain to me the differences between PSM and CID in a more comprehensive manner?

Thanks :)

Barsac answered 12/12, 2016 at 18:1 Comment(0)
V
5

Found the following in Syngress' Bluetooth Application Developer Guide from 2002

Q: What is the difference between an L2CAP PSM value and an L2CAP CID?

A: Protocol Service Multiplexor (PSM) values identify the protocol used to communicate over an L2CAP channel. In effect, this defines the higher layer that uses the channel. Multiple instances of the same higher layer may use different L2CAP channels, but they will all be identified by the same PSM value. Each separate channel is uniquely identified by its Channel ID (CID). A higher layer may request an L2CAP connection to a remote RFCOMM entity by specifying a PSM value of 0x0003. The local and remote L2CAP layers then assign CIDs to this link. The CIDs are used to actually identify traffic sent between RFCOMM layers.

Vagal answered 30/4, 2020 at 14:15 Comment(0)
I
3

Check out the Bluetooth Core Specification v4.2 [Vol 3, Part A, Section 4.2] it states:

  • Protocol/Service Multiplexer - PSM (2 octets (minimum)) The PSM field is at least two octets in length. The structure of the PSM field is based on the ISO 3309 extension mechanism for address fields. All PSM values shall be ODD, that is, the least significant bit of the least significant octet must be 1. Also, all PSM values shall have the least significant bit of the most significant octet equal to 0. This allows the PSM field to be extended beyond 16 bits. PSM values are separated into two ranges. Valid values in the first range are assigned by the Bluetooth SIG and indicate protocols. The second range of values are dynamically allocated and used in conjunction with the Service Discovery Protocol (SDP). The dynamically assigned values may be used to support multiple implementations of a particular protocol.

It also provides an outline of an l2cap connection request packet l2cap Connection Request Packet

Basically think of the CID as the port, or general communication endpoint. Connections are received on a specific CID and you can request connections on a specific CID. There are even Bluetooth SIG reserved CIDs which you can see in [Vol 3, Part A, Section 2.1]

The PSM on the other hand can be thought of as an identifier for a specific service or device that is trying to connect to you (or for your own device if you are doing the connecting). For example a device requesting a connection to you may specify in documentation to look for a PSM of 0x80.

Indianapolis answered 27/3, 2019 at 20:37 Comment(0)
A
2

I am no expert in Bluetooth communication, but I am currently working on an L2CAP LE based communication between a mobile app and a linux based server.

During this development work, I came across something called Connection-oriented Channels and Connectionless Data Channel in the bluetooth SIG specification - Core 4.2. Particluarly in this link: https://www.bluetooth.com/specifications/bluetooth-core-specification

As far as what I have understood from reading it partly is that the connection-oriented channels are, as the name suggests, connection oriented. That is, each service is associated with a channel.

In case of a connectionless channel, the psm acts as a multiplexer and facilitates multiple services to use the connectionless channel: 0x0002. Thus, psm(protocol/Service multiplexer) basically is similar to a port number in this channel.

These are just my understanding and observations. I am new to this and maybe wrong. I made an effort to write this since I see no real documentation or forum where people have cared to explain their understanding of this concept. The more the merrier.

Atal answered 24/7, 2017 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.