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:

  1. Set connectReqBufferLen to sizeof(CONNECT_PKT) + authCookieLen + MAX_DTLS_HDR_TRLR.

  2. Allocate a buffer for connectPktBuff of size connectReqBufferLen for the CONNECT_PKT structure and set values for each of its fields. 

  3. Set reqLen to the connect request buffer's hdr.pktLen + size of UDP_PACKET_HEADER.

  4. Set MaxUdpPacketSize = (uUpStreamMtu from the connect request's SyncData) - LAYER_2_OVERHEAD

  5. Set fragmentCount = reqLen / MAX_CONNECT_REQ_FRAGMENT_SIZE

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

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

  1. Set UdpPktType to PKT_TYPE_CONNECT_REQ_FRAGMENT.

  2. Set usNoOfFragments to fragmentCount, meaning the total number of fragments calculated.

  3. Set usFragmentID to the Current Fragment number.

  4. Set cbFragmentLength to MAX_CONNECT_REQ_FRAGMENT_SIZE or to the actual number of bytes remaining in the connect request buffer.

  5. Set pktLen to (sizeof(CONNECT_PKT_FRAGMENT) - sizeof(UDP_PACKET_HEADER)) + cbFragmentLength of the Current Fragment.

  6. Set the current fragment's length, fragmentLen, to cbFragmentLength of Current Fragment + sizeof(UDP_PACKET_HEADER).

  7. If the very first fragment's fragmentLen < MaxUdpPacketSize, set fragmentLen to MaxUdpPacketSize.

Finally, DTLS encrypts the fragments and sends them to the RDP server.