2 * FreeRDP: A Remote Desktop Protocol Client
3 * T.124 Generic Conference Control (GCC)
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
23 * T.124 GCC is defined in:
25 * http://www.itu.int/rec/T-REC-T.124-199802-S/en
26 * ITU-T T.124 (02/98): Generic Conference Control
30 * ConnectData ::= SEQUENCE
33 * connectPDU OCTET_STRING
38 * object OBJECT_IDENTIFIER,
39 * h221NonStandard H221NonStandardIdentifier
42 * ConnectGCCPDU ::= CHOICE
44 * conferenceCreateRequest ConferenceCreateRequest,
45 * conferenceCreateResponse ConferenceCreateResponse,
46 * conferenceQueryRequest ConferenceQueryRequest,
47 * conferenceQueryResponse ConferenceQueryResponse,
48 * conferenceJoinRequest ConferenceJoinRequest,
49 * conferenceJoinResponse ConferenceJoinResponse,
50 * conferenceInviteRequest ConferenceInviteRequest,
51 * conferenceInviteResponse ConferenceInviteResponse,
55 * ConferenceCreateRequest ::= SEQUENCE
57 * conferenceName ConferenceName,
58 * convenerPassword Password OPTIONAL,
59 * password Password OPTIONAL,
60 * lockedConference BOOLEAN,
61 * listedConference BOOLEAN,
62 * conductibleConference BOOLEAN,
63 * terminationMethod TerminationMethod,
64 * conductorPrivileges SET OF Privilege OPTIONAL,
65 * conductedPrivileges SET OF Privilege OPTIONAL,
66 * nonConductedPrivileges SET OF Privilege OPTIONAL,
67 * conferenceDescription TextString OPTIONAL,
68 * callerIdentifier TextString OPTIONAL,
69 * userData UserData OPTIONAL,
71 * conferencePriority ConferencePriority OPTIONAL,
72 * conferenceMode ConferenceMode OPTIONAL
75 * ConferenceCreateResponse ::= SEQUENCE
83 * resourcesNotAvailable (2),
84 * rejectedForSymmetryBreaking (3),
85 * lockedConferenceNotSupported (4)
87 * userData UserData OPTIONAL,
91 * ConferenceName ::= SEQUENCE
93 * numeric SimpleNumericString
94 * text SimpleTextString OPTIONAL,
98 * SimpleNumericString ::= NumericString (SIZE (1..255)) (FROM ("0123456789"))
100 * UserData ::= SET OF SEQUENCE
103 * value OCTET_STRING OPTIONAL
106 * H221NonStandardIdentifier ::= OCTET STRING (SIZE (4..255))
108 * UserID ::= DynamicChannelID
110 * ChannelID ::= INTEGER (1..65535)
111 * StaticChannelID ::= INTEGER (1..1000)
112 * DynamicChannelID ::= INTEGER (1001..65535)
117 * OID = 0.0.20.124.0.1
118 * { itu-t(0) recommendation(0) t(20) t124(124) version(0) 1 }
119 * v.1 of ITU-T Recommendation T.124 (Feb 1998): "Generic Conference Control"
121 uint8 t124_02_98_oid[6] = { 0, 0, 20, 124, 0, 1 };
123 uint8 h221_cs_key[4] = "Duca";
124 uint8 h221_sc_key[4] = "McDn";
127 * Read a GCC Conference Create Request.\n
130 * @param settings rdp settings
133 boolean gcc_read_conference_create_request(STREAM* s, rdpSettings* settings)
141 if (!per_read_choice(s, &choice))
143 if (!per_read_object_identifier(s, t124_02_98_oid))
146 /* ConnectData::connectPDU (OCTET_STRING) */
147 if (!per_read_length(s, &length))
151 if (!per_read_choice(s, &choice))
153 if (!per_read_selection(s, &selection))
156 /* ConferenceCreateRequest::conferenceName */
157 if (!per_read_numeric_string(s, 1)) /* ConferenceName::numeric */
159 if (!per_read_padding(s, 1)) /* padding */
162 /* UserData (SET OF SEQUENCE) */
163 if (!per_read_number_of_sets(s, &number) || number != 1) /* one set of UserData */
165 if (!per_read_choice(s, &choice) || choice != 0xC0) /* UserData::value present + select h221NonStandard (1) */
168 /* h221NonStandard */
169 if (!per_read_octet_string(s, h221_cs_key, 4, 4)) /* h221NonStandard, client-to-server H.221 key, "Duca" */
172 /* userData::value (OCTET_STRING) */
173 if (!per_read_length(s, &length))
175 if (stream_get_left(s) < length)
177 if (!gcc_read_client_data_blocks(s, settings, length))
184 * Write a GCC Conference Create Request.\n
187 * @param user_data client data blocks
190 void gcc_write_conference_create_request(STREAM* s, STREAM* user_data)
193 per_write_choice(s, 0); /* From Key select object (0) of type OBJECT_IDENTIFIER */
194 per_write_object_identifier(s, t124_02_98_oid); /* ITU-T T.124 (02/98) OBJECT_IDENTIFIER */
196 /* ConnectData::connectPDU (OCTET_STRING) */
197 per_write_length(s, stream_get_length(user_data) + 14); /* connectPDU length */
200 per_write_choice(s, 0); /* From ConnectGCCPDU select conferenceCreateRequest (0) of type ConferenceCreateRequest */
201 per_write_selection(s, 0x08); /* select optional userData from ConferenceCreateRequest */
203 /* ConferenceCreateRequest::conferenceName */
204 per_write_numeric_string(s, (uint8*)"1", 1, 1); /* ConferenceName::numeric */
205 per_write_padding(s, 1); /* padding */
207 /* UserData (SET OF SEQUENCE) */
208 per_write_number_of_sets(s, 1); /* one set of UserData */
209 per_write_choice(s, 0xC0); /* UserData::value present + select h221NonStandard (1) */
211 /* h221NonStandard */
212 per_write_octet_string(s, h221_cs_key, 4, 4); /* h221NonStandard, client-to-server H.221 key, "Duca" */
214 /* userData::value (OCTET_STRING) */
215 per_write_octet_string(s, user_data->data, stream_get_length(user_data), 0); /* array of client data blocks */
218 void gcc_read_conference_create_response(STREAM* s, rdpSettings* settings)
228 per_read_choice(s, &choice);
229 per_read_object_identifier(s, t124_02_98_oid);
231 /* ConnectData::connectPDU (OCTET_STRING) */
232 per_read_length(s, &length);
235 per_read_choice(s, &choice);
237 /* ConferenceCreateResponse::nodeID (UserID) */
238 per_read_integer16(s, &nodeID, 1001);
240 /* ConferenceCreateResponse::tag (INTEGER) */
241 per_read_integer(s, &tag);
243 /* ConferenceCreateResponse::result (ENUMERATED) */
244 per_read_enumerated(s, &result, MCS_Result_enum_length);
246 /* number of UserData sets */
247 per_read_number_of_sets(s, &number);
249 /* UserData::value present + select h221NonStandard (1) */
250 per_read_choice(s, &choice);
252 /* h221NonStandard */
253 per_read_octet_string(s, h221_sc_key, 4, 4); /* h221NonStandard, server-to-client H.221 key, "McDn" */
255 /* userData (OCTET_STRING) */
256 per_read_length(s, &length);
257 gcc_read_server_data_blocks(s, settings, length);
260 boolean gcc_read_client_data_blocks(STREAM* s, rdpSettings *settings, int length)
268 pos = stream_get_pos(s);
269 gcc_read_user_data_header(s, &type, &blockLength);
274 if (!gcc_read_client_core_data(s, settings, blockLength - 4))
279 if (!gcc_read_client_security_data(s, settings))
284 if (!gcc_read_client_network_data(s, settings))
289 if (!gcc_read_client_cluster_data(s, settings))
294 if (!gcc_read_client_monitor_data(s, settings))
302 length -= blockLength;
303 stream_set_pos(s, pos + blockLength);
309 void gcc_write_client_data_blocks(STREAM* s, rdpSettings *settings)
311 gcc_write_client_core_data(s, settings);
312 gcc_write_client_cluster_data(s, settings);
313 gcc_write_client_security_data(s, settings);
314 gcc_write_client_network_data(s, settings);
315 gcc_write_client_monitor_data(s, settings);
318 void gcc_read_server_data_blocks(STREAM* s, rdpSettings *settings, int length)
324 while (offset < length)
326 gcc_read_user_data_header(s, &type, &blockLength);
331 gcc_read_server_core_data(s, settings);
335 gcc_read_server_security_data(s, settings);
339 gcc_read_server_network_data(s, settings);
346 offset += blockLength;
350 void gcc_read_user_data_header(STREAM* s, uint16* type, uint16* length)
352 stream_read_uint16(s, *type); /* type */
353 stream_read_uint16(s, *length); /* length */
357 * Write a user data header (TS_UD_HEADER).\n
360 * @param type data block type
361 * @param length data block length
364 void gcc_write_user_data_header(STREAM* s, uint16 type, uint16 length)
366 stream_write_uint16(s, type); /* type */
367 stream_write_uint16(s, length); /* length */
371 * Read a client core data block (TS_UD_CS_CORE).\n
374 * @param settings rdp settings
377 boolean gcc_read_client_core_data(STREAM* s, rdpSettings *settings, uint16 blockLength)
380 uint16 colorDepth = 0;
381 uint16 postBeta2ColorDepth = 0;
382 uint16 highColorDepth = 0;
383 uint16 supportedColorDepths = 0;
384 uint16 earlyCapabilityFlags = 0;
385 uint32 serverSelectedProtocol = 0;
388 /* Length of all required fields, until imeFileName */
389 if (blockLength < 128)
392 stream_read_uint32(s, version); /* version */
393 settings->rdp_version = (version == RDP_VERSION_4 ? 5 : 4);
395 stream_read_uint16(s, settings->width); /* desktopWidth */
396 stream_read_uint16(s, settings->height); /* desktopHeight */
397 stream_read_uint16(s, colorDepth); /* colorDepth */
398 stream_seek_uint16(s); /* SASSequence (Secure Access Sequence) */
399 stream_read_uint32(s, settings->kbd_layout); /* keyboardLayout */
400 stream_read_uint32(s, settings->client_build); /* clientBuild */
402 /* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
403 str = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), 32);
405 snprintf(settings->client_hostname, sizeof(settings->client_hostname), "%s", str);
408 stream_read_uint32(s, settings->kbd_type); /* keyboardType */
409 stream_read_uint32(s, settings->kbd_subtype); /* keyboardSubType */
410 stream_read_uint32(s, settings->kbd_fn_keys); /* keyboardFunctionKey */
412 stream_seek(s, 64); /* imeFileName */
417 * The following fields are all optional. If one field is present, all of the preceding
418 * fields MUST also be present. If one field is not present, all of the subsequent fields
419 * MUST NOT be present.
420 * We must check the bytes left before reading each field.
427 stream_read_uint16(s, postBeta2ColorDepth); /* postBeta2ColorDepth */
432 stream_seek_uint16(s); /* clientProductID */
437 stream_seek_uint32(s); /* serialNumber */
442 stream_read_uint16(s, highColorDepth); /* highColorDepth */
447 stream_read_uint16(s, supportedColorDepths); /* supportedColorDepths */
452 stream_read_uint16(s, earlyCapabilityFlags); /* earlyCapabilityFlags */
455 if (blockLength < 64)
457 str = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), 64);
459 snprintf(settings->client_product_id, sizeof(settings->client_product_id), "%s", str);
465 stream_read_uint8(s, settings->performance_flags); /* connectionType */
470 stream_seek_uint8(s); /* pad1octet */
475 stream_read_uint32(s, serverSelectedProtocol); /* serverSelectedProtocol */
478 if (settings->selected_protocol != serverSelectedProtocol)
486 * Write a client core data block (TS_UD_CS_CORE).\n
489 * @param settings rdp settings
492 void gcc_write_client_core_data(STREAM* s, rdpSettings *settings)
496 size_t clientNameLength;
497 uint8 connectionType;
498 uint16 highColorDepth;
499 uint16 supportedColorDepths;
500 uint16 earlyCapabilityFlags;
501 char* clientDigProductId;
502 size_t clientDigProductIdLength;
504 gcc_write_user_data_header(s, CS_CORE, 216);
506 version = settings->rdp_version >= 5 ? RDP_VERSION_5_PLUS : RDP_VERSION_4;
507 clientName = freerdp_uniconv_out(settings->uniconv, settings->client_hostname, &clientNameLength);
508 clientDigProductId = freerdp_uniconv_out(settings->uniconv, settings->client_product_id, &clientDigProductIdLength);
510 stream_write_uint32(s, version); /* version */
511 stream_write_uint16(s, settings->width); /* desktopWidth */
512 stream_write_uint16(s, settings->height); /* desktopHeight */
513 stream_write_uint16(s, RNS_UD_COLOR_8BPP); /* colorDepth, ignored because of postBeta2ColorDepth */
514 stream_write_uint16(s, RNS_UD_SAS_DEL); /* SASSequence (Secure Access Sequence) */
515 stream_write_uint32(s, settings->kbd_layout); /* keyboardLayout */
516 stream_write_uint32(s, settings->client_build); /* clientBuild */
518 /* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
519 if (clientNameLength > 30)
521 clientNameLength = 30;
522 clientName[clientNameLength] = 0;
523 clientName[clientNameLength + 1] = 0;
525 stream_write(s, clientName, clientNameLength + 2);
526 stream_write_zero(s, 32 - clientNameLength - 2);
529 stream_write_uint32(s, settings->kbd_type); /* keyboardType */
530 stream_write_uint32(s, settings->kbd_subtype); /* keyboardSubType */
531 stream_write_uint32(s, settings->kbd_fn_keys); /* keyboardFunctionKey */
533 stream_write_zero(s, 64); /* imeFileName */
535 stream_write_uint16(s, RNS_UD_COLOR_8BPP); /* postBeta2ColorDepth */
536 stream_write_uint16(s, 1); /* clientProductID */
537 stream_write_uint32(s, 0); /* serialNumber (should be initialized to 0) */
539 highColorDepth = MIN(settings->color_depth, 24);
541 supportedColorDepths =
542 RNS_UD_24BPP_SUPPORT |
543 RNS_UD_16BPP_SUPPORT |
544 RNS_UD_15BPP_SUPPORT;
547 earlyCapabilityFlags = RNS_UD_CS_SUPPORT_ERRINFO_PDU;
549 if (settings->performance_flags == PERF_FLAG_NONE)
551 earlyCapabilityFlags |= RNS_UD_CS_VALID_CONNECTION_TYPE;
552 connectionType = CONNECTION_TYPE_LAN;
555 if (settings->color_depth == 32)
557 supportedColorDepths |= RNS_UD_32BPP_SUPPORT;
558 earlyCapabilityFlags |= RNS_UD_CS_WANT_32BPP_SESSION;
561 stream_write_uint16(s, highColorDepth); /* highColorDepth */
562 stream_write_uint16(s, supportedColorDepths); /* supportedColorDepths */
564 stream_write_uint16(s, earlyCapabilityFlags); /* earlyCapabilityFlags */
566 /* clientDigProductId (64 bytes, null-terminated unicode, truncated to 30 characters) */
567 if (clientDigProductIdLength > 62)
569 clientDigProductIdLength = 62;
570 clientDigProductId[clientDigProductIdLength] = 0;
571 clientDigProductId[clientDigProductIdLength + 1] = 0;
573 stream_write(s, clientDigProductId, clientDigProductIdLength + 2);
574 stream_write_zero(s, 64 - clientDigProductIdLength - 2);
575 xfree(clientDigProductId);
577 stream_write_uint8(s, connectionType); /* connectionType */
578 stream_write_uint8(s, 0); /* pad1octet */
580 stream_write_uint32(s, settings->selected_protocol); /* serverSelectedProtocol */
583 void gcc_read_server_core_data(STREAM* s, rdpSettings *settings)
586 uint32 clientRequestedProtocols;
588 stream_read_uint32(s, version); /* version */
589 stream_read_uint32(s, clientRequestedProtocols); /* clientRequestedProtocols */
591 if (version == RDP_VERSION_4 && settings->rdp_version > 4)
592 settings->rdp_version = 4;
593 else if (version == RDP_VERSION_5_PLUS && settings->rdp_version < 5)
594 settings->rdp_version = 7;
598 * Read a client security data block (TS_UD_CS_SEC).\n
601 * @param settings rdp settings
604 boolean gcc_read_client_security_data(STREAM* s, rdpSettings *settings)
606 printf("CS_SECURITY\n");
611 * Write a client security data block (TS_UD_CS_SEC).\n
614 * @param settings rdp settings
617 void gcc_write_client_security_data(STREAM* s, rdpSettings *settings)
619 gcc_write_user_data_header(s, CS_SECURITY, 12);
621 if (settings->encryption > 0)
623 stream_write_uint32(s, settings->encryption_method); /* encryptionMethods */
624 stream_write_uint32(s, 0); /* extEncryptionMethods */
628 /* French locale, disable encryption */
629 stream_write_uint32(s, 0); /* encryptionMethods */
630 stream_write_uint32(s, settings->encryption_method); /* extEncryptionMethods */
634 void gcc_read_server_security_data(STREAM* s, rdpSettings *settings)
636 uint32 encryptionMethod;
637 uint32 encryptionLevel;
638 uint32 serverRandomLen;
639 uint32 serverCertLen;
641 stream_read_uint32(s, encryptionMethod); /* encryptionMethod */
642 stream_read_uint32(s, encryptionLevel); /* encryptionLevel */
643 stream_read_uint32(s, serverRandomLen); /* serverRandomLen */
644 stream_read_uint32(s, serverCertLen); /* serverCertLen */
646 if (encryptionMethod == 0 && encryptionLevel == 0)
648 /* serverRandom and serverRandom must not be present */
652 if (serverRandomLen > 0)
655 freerdp_blob_alloc(&settings->server_random, serverRandomLen);
656 memcpy(settings->server_random.data, s->p, serverRandomLen);
657 stream_seek(s, serverRandomLen);
660 if (serverCertLen > 0)
662 /* serverCertificate */
663 freerdp_blob_alloc(&settings->server_certificate, serverCertLen);
664 memcpy(settings->server_certificate.data, s->p, serverCertLen);
665 stream_seek(s, serverCertLen);
670 * Read a client network data block (TS_UD_CS_NET).\n
673 * @param settings rdp settings
676 boolean gcc_read_client_network_data(STREAM* s, rdpSettings *settings)
678 printf("CS_NETWORK\n");
683 * Write a client network data block (TS_UD_CS_NET).\n
686 * @param settings rdp settings
689 void gcc_write_client_network_data(STREAM* s, rdpSettings *settings)
694 if (settings->num_channels > 0)
696 length = settings->num_channels * 12 + 8;
697 gcc_write_user_data_header(s, CS_NET, length);
699 stream_write_uint32(s, settings->num_channels); /* channelCount */
701 /* channelDefArray */
702 for (i = 0; i < settings->num_channels; i++)
705 stream_write(s, settings->channels[i].name, 8); /* name (8 bytes) */
706 stream_write_uint32(s, settings->channels[i].options); /* options (4 bytes) */
711 void gcc_read_server_network_data(STREAM* s, rdpSettings *settings)
718 stream_read_uint16(s, MCSChannelId); /* MCSChannelId */
719 stream_read_uint16(s, channelCount); /* channelCount */
721 if (channelCount != settings->num_channels)
723 printf("requested %d channels, got %d instead\n",
724 settings->num_channels, channelCount);
727 for (i = 0; i < channelCount; i++)
729 stream_read_uint16(s, channelId); /* channelId */
730 settings->channels[i].chan_id = channelId;
733 if (channelCount % 2 == 1)
734 stream_seek(s, 2); /* padding */
738 * Read a client cluster data block (TS_UD_CS_CLUSTER).\n
741 * @param settings rdp settings
744 boolean gcc_read_client_cluster_data(STREAM* s, rdpSettings *settings)
746 printf("CS_CLUSTER\n");
751 * Write a client cluster data block (TS_UD_CS_CLUSTER).\n
754 * @param settings rdp settings
757 void gcc_write_client_cluster_data(STREAM* s, rdpSettings *settings)
761 gcc_write_user_data_header(s, CS_CLUSTER, 12);
763 flags = REDIRECTION_SUPPORTED | (REDIRECTION_VERSION4 << 2);
765 if (settings->console_session || settings->redirected_session_id)
766 flags |= REDIRECTED_SESSIONID_FIELD_VALID;
768 stream_write_uint32(s, flags); /* flags */
769 stream_write_uint32(s, settings->redirected_session_id); /* redirectedSessionID */
773 * Read a client monitor data block (TS_UD_CS_MONITOR).\n
776 * @param settings rdp settings
779 boolean gcc_read_client_monitor_data(STREAM* s, rdpSettings *settings)
781 printf("CS_MONITOR\n");
786 * Write a client monitor data block (TS_UD_CS_MONITOR).\n
789 * @param settings rdp settings
792 void gcc_write_client_monitor_data(STREAM* s, rdpSettings *settings)
796 uint32 left, top, right, bottom, flags;
798 if (settings->num_monitors > 1)
800 length = (20 * settings->num_monitors) + 12;
801 gcc_write_user_data_header(s, CS_MONITOR, length);
803 stream_write_uint32(s, 0); /* flags */
804 stream_write_uint32(s, settings->num_monitors); /* monitorCount */
806 for (i = 0; i < settings->num_monitors; i++)
808 left = settings->monitors[i].x;
809 top = settings->monitors[i].y;
810 right = settings->monitors[i].x + settings->monitors[i].width - 1;
811 bottom = settings->monitors[i].y + settings->monitors[i].height - 1;
812 flags = settings->monitors[i].is_primary ? MONITOR_PRIMARY : 0;
814 stream_write_uint32(s, left); /* left */
815 stream_write_uint32(s, top); /* top */
816 stream_write_uint32(s, right); /* right */
817 stream_write_uint32(s, bottom); /* bottom */
818 stream_write_uint32(s, flags); /* flags */