3.8.3 Establishing a Connection
The client MUST transmit one or more CONNECT_PKT_FRAGMENT structures, as specified in section 2.2.11.10, to the server to establish the connection.
The following is a list of constants and variables that hold the state temporarily:
connectReqBufferLen is the length of the connect request buffer connectPktBuff.
reqLen is the actual length of the request in connectPktBuff.
authCookieLen is the length of the Authentication Cookie, which was previously generated by the RDP server and provided to the client, that the client returns to the RDP server.
MAX_DTLS_HDR_TRLR is the maximum length of the DTLS header and trailer bits. It is 96 bytes.
Size of UDP_PACKET_HEADER is 4 bytes.
LAYER_2_OVERHEAD is 100 bytes, which is MAX_DTLS_HDR_TRLR_SIZE + UDP header size.
MAX_CONNECT_REQ_FRAGMENT_SIZE is the maximum size of each connect request fragment. It MUST be set to 1000 bytes.
Before transmitting a CONNECT_PKT_FRAMEMENT, the client MUST do the following:
Set connectReqBufferLen to sizeof(CONNECT_PKT) + authCookieLen + MAX_DTLS_HDR_TRLR.
Allocate a buffer for connectPktBuff of size connectReqBufferLen for the CONNECT_PKT structure and set values for each of its fields.
Set reqLen to the connect request buffer's hdr.pktLen + size of UDP_PACKET_HEADER.
Set MaxUdpPacketSize = (uUpStreamMtu from the connect request's SyncData) - LAYER_2_OVERHEAD
Set fragmentCount = reqLen / MAX_CONNECT_REQ_FRAGMENT_SIZE
If the remainder after the division of reqLen by MAX_CONNECT_REQ_FRAGMENT_SIZE is not zero, increase the fragment count by 1 to completely account for all of the bytes of the request.
Split the CONNECT_PKT buffer into fragmentCount fragments, meaning multiple buffers of type CONNECT_PKT_FRAGMENT.
Each fragment's CONNECT_PKT_FRAGMENT fields MUST be set as follows:
Set UdpPktType to PKT_TYPE_CONNECT_REQ_FRAGMENT.
Set usNoOfFragments to fragmentCount, meaning the total number of fragments calculated.
Set usFragmentID to the Current Fragment number.
Set cbFragmentLength to MAX_CONNECT_REQ_FRAGMENT_SIZE or to the actual number of bytes remaining in the connect request buffer.
Set pktLen to (sizeof(CONNECT_PKT_FRAGMENT) - sizeof(UDP_PACKET_HEADER)) + cbFragmentLength of the Current Fragment.
Set the current fragment's length, fragmentLen, to cbFragmentLength of Current Fragment + sizeof(UDP_PACKET_HEADER).
If the very first fragment's fragmentLen < MaxUdpPacketSize, set fragmentLen to MaxUdpPacketSize.
Finally, DTLS encrypts the fragments and sends them to the RDP server.