Search code examples
cbluetoothbluetooth-lowenergybluezl2cap

Bluetooth LE L2CAP CID vs. PSM


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 :)


Solution

  • 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.