Bluetooth L2CAP protocol

Source: Internet
Author: User
Tags bit set

1. Overview

L2CAP can provide connection-oriented or connectionless data services to the upper layer, with multiplexing capability and segmentation and reassembly operation. Data of upper-layer protocols or applications can be accepted. The maximum value is 64 K Bytes. Flow Control and retransmission can be performed on each channel. The structure is as follows:

Several main features: (1) Protocol/channel multiplexing (2) segmentation and reassembly (3) Error Control and retransmissions (4) Support for streaming (5) fragmentation and recombination (6) quality of Service 2. Common terms and concepts L2CAP Channel: The logical connection between two endpoints in peer devices, characterizedby their channel Identifiers (CID). (The logical connection between two devices identifies the channel with the CID at both ends) SDU, or L2CAP SDU: The data unit exchanged between L2CAP and upper layer. It does not contain any L2CAP protocol information. Segment, or SDU segment: Segmentation procedure generation, part of the SDU. Note: It is not used in basic L2CAP mode. It is only used in enhanced retransmission mode, streaming mode, retransmission mode and flow control mode. [This is obvious. Basic L2CAP does not have control field] PDU, or L2CAP PDU: Protocol Data Unit, which contains L2CAP protocol information. Control Information and upper-layer data information. Generally, it starts with a basic L2CAP header and consists of the following PDU: B-frames, I-frames, S-frames, C-frames and G-Frames. B-frame is used in basic L2CAP mode; I-frame and S-frame are used in enhanced retransmission mode, streaming mode, retransmission mode, and flow control mode; c-frame is dedicated to L2CAP signaling channel; G-frame is used in connectionless L2CAP channel and can also be used for broadcasting.   3. CIDCID (Channel identifiers), the identifier of the two endpoints of an L2CAP connection. Yes Fixed ChannelAnd Dynamically allocated channel. As shown in:
It should be noted that after the ALC-U or the LE-U logical link is established, the fixed channel is already in effect. If several remote devices have the same CID, the local device can still identify the device. Is an example of CID creation:
The Cid rules for establishing different types of L2CAP connections are as follows: 4. data packet format first, L2CAP has five operation modes: In addition, L2CAP has the following connection types: A: connection-oriented channels in basic L2CAP mode (connection oriented, using the basic L2CAP Mode) b: connectionless Data Channel in basic L2CAP mode (connectionless, using basic L2CAP mode) connection types of C: connection-oriented channels are divided: basic L2CAP mode and retransmission/flowcontrol/streaming modes (connection-oriented, retransmission/Traffic Control/stream mode) CaseBasic Information Frame (B-frame) is used. The format is as follows: length refers to the number of bytes of information field, and information payload is 0 to 65535 bytes. Case BThe Group frame (G-frame) is used. The length parameter is set to the number of bytes of the SMS plus the number of bytes of information. The CID is 0x0002 because it is a connectionless data channel. The MNS is protocol/service multiplexer, And the MNS must be at least 16 bits. In addition, it must be in the following format: | xxxxxxxxxx0 | xxxxxxxx1 |. We can see that there is a connected range. The first range is the protocol representing the SIG allocation value, and the second range is dynamically allocated for communication with SDP, it can also be used to support special protocols. The information part ranges from 0 to 65533 bytes. Case CInformation Frame (I-frame) and supervisory frame (S-frame) are used in combination as follows:
This situation is complicated. First, we should talk about S-frame and S-frame to respond to I-frame. The length parameter is the total number of bytes except the basic L2CAP header. Control Three Control Modes:( 1) Standard Control Field (2) the enhanced control field, and the (3) extended control fieldstandard control field: used for retransmission mode and flow control mode; enhanced control field: used for enhanced retransmission mode and streaming mode; extended control field: used for enhanced retransmission mode and streaming mode. The parameters of the three control modes are described as follows: SAR: segmentation and reassembly, indicating whether the L2CAP is segmented. The format is as follows:
Txseq: Send Sequence Number, which counts the sent I-frame and is used for segmentation and reorganization. Reqseq: receive sequence number, accept sequence number, used for re-transmission and other R: retransmission disable bit, used to implement Flow Control. S: supervisory function, which indicates the type of S-frame. The definition is as follows:
P: poll, the P-bit is set to 1 to solicit a response from the receiver. the aggreger shallrespond immediately with a frame with the F-bit set to 1.f: final (1 bit ), the F-bit is set to 1 in response to an S-frame with the p bit set to 1. l2CAP SDU length (2 byte) if the SDU of L2CAP is large and spans several I-frames, SDU Length indicates the total length of SDU. This field is not required if the SDU does not have segments. Note that SDU length only appears in start I-frame, and SAR of I-frame is 0x01. That is to say, in all the segments of the I-frame, only the first one needs to specify the SDU length, and other I-frames do not need. Information payload field can be filled with this field based on the configured MPs (max pus) size. FCS (2 byte) is used to check this frame. The calculation is complicated and not detailed. 5. Signaling packet formats I mentioned several types of PDUS and a C-frame. C-frame is dedicated to signaling channel (0x0001 or 0x0005), and signaling commands is transmitted on it. Note that a C-frame in the 0x0001 channel can transmit multiple commands at the same time, and only one command can be transmitted at 0x0005. The payload length cannot exceed mtusig. For the defined minimum signaling MTU:
The L2CAP PDU format defined on the signaling channel is as follows: the structure is the same as that of B-frame. The root type of signaling commands is as follows:
The parameter description is as follows: Code (1 octet): specifies the type of the command, which generally includes the following types:


Parameter identifier (1 octet): identifies a req and res, matching. Parameter length (2 octets): specifies the number of data field bytes. Parameter Data (0 or more octets): command data. 6. The command section describes the command on the signaling channel. There are 19 types of type. Command reject (code 0x01 ):


Connection Request (code 0x02): Used to establish an L2CAP connection between devices.
Source CID is the CID of the device that initiates this req. Connection response (code 0x03): corresponding to connection request
Note: The destination CID parameter is the CID of the device that sends this res, and the source CID is the CID of the device that accepts this res. [This may be to match the definition of Connection Request] result (2 octets ):
Status (2 octets): valid when result is pending.

Configuration request (code 0x04): the configuration required to establish an L2CAP connection.
Here, DCID is the CID of the device that accepts the req. Flags does not explain all configuration information provided by configuration options. If it is an empty configuration, the length is set to 0x0004. the format of configuration option is defined as follows:
Type (1 octet): set to 0: the receiver cannot recognize option, then reject this req to 1: The receiver cannot be set to option, then the reqlength (1 octet) of SKIP ): define the number of bytes in option Data configuration response (code 0x05): Response configuration requst
SCID is the recipient of this res device's cidflags (2 octets) does not explain the structure of the remaining command and the above is similar, not described one by one, refer to the Spec1425-1438. 7. some configuration options (1) Maximum Transmission Unit (MTU): All L2CAP implementations need to support up to 48 bytes (on ACL-U) and 23 bytes (on LE-U ).
MTU: The maximum SDU size (number of bytes) (2) flush timeout option; this option is not used for extended flow specification.
Flush timeout is calculated in milliseconds. The rest are Quality of Service (QoS) option, retransmission and flow control option, frame check sequence (FCS) option, extended flow Specification option, etc. For details, refer to spec 4.0. 8. Fragmentation and recombination
Not complete...

 

Bluetooth L2CAP protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.