CID (Channel ID) 在L2CAP层的很重要。
其中有一些固定的CID,比如在ACL_U逻辑链路上,
0x0001 代表Signaling channel0x0002 代表无连接的信道0x0040~0xFFFF 用于动态分配(主要用于connection-orientation 面向连接)
如下图所示,基本的信道主要是三种:
Connection-orientedConnectionless DataL2CAP Signaling 其中面向连接的Connection-oriented是动态分配的CID,其他的两种面向连接和Signaling都有固定的信道。 其中LE_U逻辑链路的上的Signaling CID 是0x0005待补充
Length: 2 bytes Channel ID : 2 bytes Information payload: 65535 bytes (由长度的决定)
Length: 2 bytes CID: 2 bytes,固定是0x0002 PSM(Protocol/Service Multiplexer) : >= 2bytes 最小是两个字节 eg:SDP, Refcommon Information payload: 65535 bytes
The Control Field identifies whether the frame is an S-frame or I-frame and contains various information about the frame.
1 Standard Control Field The Standard Control Field shall be used for Retransmission mode and Flow Control mode2 Enhanced Control Field3 Extended Control Field The Enhanced and Extended Control Fields shall be used for Enhanced Retransmission mode and Streaming mode.用来控制数据帧是否重传。 S-frames are used to acknowledge I-frames and request retransmission of Iframes.
Each S-frame has an ReqSeq sequence number which may acknowledge additional I-frames received by the data Link Layer entity.
Each S-frame with a Standard Control Field has a retransmission bit (R bit) that affects whether I-frames are retransmitted.
Each S-frame with an Enhanced Control field or an Extended Control Field has a Poll bit (P-bit) and a Final bit (F-bit) and does not have an R-bit.
Defined types of S-frames are RR (Receiver Ready), REJ (Reject), RNR(Receiver Not Ready) and SREJ (Selective Reject).
主要用来传输L2CAP的数据。 The I-frames are used to transfer information between L2CAP entities.
Each I-frame has a TxSeq(Send sequence number), ReqSeq(Receive sequence number) which can acknowledge additional I-frames received by the dataLink Layer entity.
Each I-frame with a Standard Control field has a retransmission bit (R bit) that affects whether I-frames are retransmitted.
Each I-frame with an Enhanced Control Field or an Extended Control Field has an F-bit that is used in Poll/Final bit functions.
//(SAR segmentation and reassembly) The SAR field in the I-frame is used for segmentation and reassembly control. The L2CAP SDU Length field specifies the length of an SDU, including the aggregate length across all segments if segmented.
是S-Frame还是I-Frame 由 Control 字段中最低位决定的。 Information and Supervisory frames types are distinguished by the least significant bit in the Control Field.
Type The type bit shall be 0 for an I-frame and 1 for an S-frame.
Send Sequence Number - TxSeq The send sequence number is used to number each I-frame, to enable sequencing and retransmission.
Receive Sequence Number - ReqSeq The receive sequence number is used by the receiver side to acknowledge I-frames, and in the REJ and SREJ frames to request the retransmission of an I-frame with a specific send sequence number.
Retransmission Disable Bit - R R=0: Normal operation. Sender uses the RetransmissionTimer to control retransmission of I-frames. Sender does not use the MonitorTimer. R=1: Receiver side requests sender to postpone retransmission of I-frames. Sender monitors signaling with the MonitorTimer. Sender does not use the RetransmissionTimer.
Segmentation and Reassembly - SAR The SAR bits define whether an L2CAP SDU is segmented。
Supervisory function - S The S-bits mark the type of S-frame
Poll - P The P-bit is set to 1 to solicit a response from the receiver. The receiver shall respond immediately with a frame with the F-bit set to 1.
Final - F The F-bit is set to 1 in response to an S-frame with the P bit set to 1.
0x0001 information payload 可以包含多条指令。 0x0005只能包含一条指令 Multiple commands may be sent in a single C-frame over fixed channel CID 0x0001 while only one command per C-frame shall be sent over fixed channel CID 0x0005.
C-Frame不能超过MTU中定义的长度。如果超过,接受端会立即发L2CAP_COMMAND_REJECT_RSP包含支持的最大的长度。同时C-Frame 最小长度如下表。 Note: The name of a signalling packet has a suffix indicating its type: _REQ for requests, _RSP for responses, and _IND for indications.
Code (1 byte) 如果接受端收到未知或者不允许的Code,会立即发送L2CAP_COMMAND_-REJECT_RSP,其中包含拒绝码。参见下表: Identifier (1 byte) 确认码,在Request和Response之间保持统一, Response 会使用Request的identifier进行回复。 The requesting device sets this field and the responding device uses the same value in its response.连续的命令,需要使用不同的Identifier。 Within each signaling channel a different Identifier shall be used for each successive command.
同时0x00不可以使用,会被当做无效signaling抛弃。 Signaling identifier 0x00 is an illegal identifier and shall never be used in any command.