diff --git a/.gitattributes b/.gitattributes index 66adacda92055fd6b8c27566590b470e4ee714e5..9136fc5392ab3a2b592cadc278339b9f8c168c5c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -59,3 +59,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.webm filter=lfs diff=lfs merge=lfs -text fuzz-tooling/infra/cifuzz/test_data/timeout_fuzzer filter=lfs diff=lfs merge=lfs -text fuzz-tooling/projects/curl/pkgs/curl_fuzzer/corpora/curl_fuzzer_rtsp/oss-fuzz-issue-6937 filter=lfs diff=lfs merge=lfs -text +local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-VariableFont_wdth,wght.ttf filter=lfs diff=lfs merge=lfs -text +local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-Italic-VariableFont_wdth,wght.ttf filter=lfs diff=lfs merge=lfs -text +local-test-freerdp-full-01/afc-freerdp/server/Sample/rfx_test.pcap filter=lfs diff=lfs merge=lfs -text diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e332eb7d5e7221beb1b19e84a2761db88f5435f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2022 Armin Novak +# Copyright 2022 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("ainput") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..5bab1c8d8a7f14aa2defe7fe89a74a229d74da20 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "ainput" + TYPE + "dynamic" + DESCRIPTION + "Advanced Input Virtual Channel Extension" + SPECIFICATIONS + "[XXXXX]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0bd9abf99fcb3b1ff2e1ce5407626dc15abe95e6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2022 Armin Novak +# Copyright 2022 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("ainput") + +set(${MODULE_PREFIX}_SRCS ainput_main.c ainput_main.h) + +set(${MODULE_PREFIX}_LIBS winpr) + +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.c new file mode 100644 index 0000000000000000000000000000000000000000..51d912ad3694a3683773023e587084b26e67a265 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.c @@ -0,0 +1,183 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Advanced Input Virtual Channel Extension + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include +#include +#include + +#include "ainput_main.h" +#include +#include +#include +#include + +#include "../common/ainput_common.h" + +#define TAG CHANNELS_TAG("ainput.client") + +typedef struct AINPUT_PLUGIN_ AINPUT_PLUGIN; +struct AINPUT_PLUGIN_ +{ + GENERIC_DYNVC_PLUGIN base; + AInputClientContext* context; + UINT32 MajorVersion; + UINT32 MinorVersion; +}; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT ainput_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + UINT16 type = 0; + AINPUT_PLUGIN* ainput = NULL; + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + + WINPR_ASSERT(callback); + WINPR_ASSERT(data); + + ainput = (AINPUT_PLUGIN*)callback->plugin; + WINPR_ASSERT(ainput); + + if (!Stream_CheckAndLogRequiredLength(TAG, data, 2)) + return ERROR_NO_DATA; + Stream_Read_UINT16(data, type); + switch (type) + { + case MSG_AINPUT_VERSION: + if (!Stream_CheckAndLogRequiredLength(TAG, data, 8)) + return ERROR_NO_DATA; + Stream_Read_UINT32(data, ainput->MajorVersion); + Stream_Read_UINT32(data, ainput->MinorVersion); + break; + default: + WLog_WARN(TAG, "Received unsupported message type 0x%04" PRIx16, type); + break; + } + + return CHANNEL_RC_OK; +} + +static UINT ainput_send_input_event(AInputClientContext* context, UINT64 flags, INT32 x, INT32 y) +{ + AINPUT_PLUGIN* ainput = NULL; + GENERIC_CHANNEL_CALLBACK* callback = NULL; + BYTE buffer[32] = { 0 }; + UINT64 time = 0; + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); + + WINPR_ASSERT(s); + WINPR_ASSERT(context); + + time = GetTickCount64(); + ainput = (AINPUT_PLUGIN*)context->handle; + WINPR_ASSERT(ainput); + + if (ainput->MajorVersion != AINPUT_VERSION_MAJOR) + { + WLog_WARN(TAG, "Unsupported channel version %" PRIu32 ".%" PRIu32 ", aborting.", + ainput->MajorVersion, ainput->MinorVersion); + return CHANNEL_RC_UNSUPPORTED_VERSION; + } + callback = ainput->base.listener_callback->channel_callback; + WINPR_ASSERT(callback); + + { + char ebuffer[128] = { 0 }; + WLog_VRB(TAG, "sending timestamp=0x%08" PRIx64 ", flags=%s, %" PRId32 "x%" PRId32, time, + ainput_flags_to_string(flags, ebuffer, sizeof(ebuffer)), x, y); + } + + /* Message type */ + Stream_Write_UINT16(s, MSG_AINPUT_MOUSE); + + /* Event data */ + Stream_Write_UINT64(s, time); + Stream_Write_UINT64(s, flags); + Stream_Write_INT32(s, x); + Stream_Write_INT32(s, y); + Stream_SealLength(s); + + /* ainput back what we have received. AINPUT does not have any message IDs. */ + WINPR_ASSERT(callback->channel); + WINPR_ASSERT(callback->channel->Write); + return callback->channel->Write(callback->channel, (ULONG)Stream_Length(s), Stream_Buffer(s), + NULL); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT ainput_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + + free(callback); + + return CHANNEL_RC_OK; +} + +static UINT init_plugin_cb(GENERIC_DYNVC_PLUGIN* base, rdpContext* rcontext, rdpSettings* settings) +{ + AINPUT_PLUGIN* ainput = (AINPUT_PLUGIN*)base; + AInputClientContext* context = (AInputClientContext*)calloc(1, sizeof(AInputClientContext)); + if (!context) + return CHANNEL_RC_NO_MEMORY; + + context->handle = (void*)base; + context->AInputSendInputEvent = ainput_send_input_event; + + ainput->context = context; + ainput->base.iface.pInterface = context; + return CHANNEL_RC_OK; +} + +static void terminate_plugin_cb(GENERIC_DYNVC_PLUGIN* base) +{ + AINPUT_PLUGIN* ainput = (AINPUT_PLUGIN*)base; + free(ainput->context); +} + +static const IWTSVirtualChannelCallback ainput_functions = { ainput_on_data_received, + NULL, /* Open */ + ainput_on_close, NULL }; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE ainput_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, AINPUT_DVC_CHANNEL_NAME, + sizeof(AINPUT_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK), + &ainput_functions, init_plugin_cb, terminate_plugin_cb); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.h new file mode 100644 index 0000000000000000000000000000000000000000..5e1d5b1fd8ddeadc599911682e2a2a46431b4250 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/client/ainput_main.h @@ -0,0 +1,40 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Advanced Input Virtual Channel Extension + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AINPUT_CLIENT_MAIN_H +#define FREERDP_CHANNEL_AINPUT_CLIENT_MAIN_H + +#include +#include +#include +#include +#include + +#define DVC_TAG CHANNELS_TAG("ainput.client") +#ifdef WITH_DEBUG_DVC +#define DEBUG_DVC(...) WLog_DBG(DVC_TAG, __VA_ARGS__) +#else +#define DEBUG_DVC(...) \ + do \ + { \ + } while (0) +#endif + +#endif /* FREERDP_CHANNEL_AINPUT_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/common/ainput_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/common/ainput_common.h new file mode 100644 index 0000000000000000000000000000000000000000..34442f7d956185a54a912e3c16048f84bf06745b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/common/ainput_common.h @@ -0,0 +1,59 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_INT_AINPUT_COMMON_H +#define FREERDP_INT_AINPUT_COMMON_H + +#include + +#include + +static INLINE const char* ainput_flags_to_string(UINT64 flags, char* buffer, size_t size) +{ + char number[32] = { 0 }; + + if (flags & AINPUT_FLAGS_HAVE_REL) + winpr_str_append("AINPUT_FLAGS_HAVE_REL", buffer, size, "|"); + if (flags & AINPUT_FLAGS_WHEEL) + winpr_str_append("AINPUT_FLAGS_WHEEL", buffer, size, "|"); + if (flags & AINPUT_FLAGS_MOVE) + winpr_str_append("AINPUT_FLAGS_MOVE", buffer, size, "|"); + if (flags & AINPUT_FLAGS_DOWN) + winpr_str_append("AINPUT_FLAGS_DOWN", buffer, size, "|"); + if (flags & AINPUT_FLAGS_REL) + winpr_str_append("AINPUT_FLAGS_REL", buffer, size, "|"); + if (flags & AINPUT_FLAGS_BUTTON1) + winpr_str_append("AINPUT_FLAGS_BUTTON1", buffer, size, "|"); + if (flags & AINPUT_FLAGS_BUTTON2) + winpr_str_append("AINPUT_FLAGS_BUTTON2", buffer, size, "|"); + if (flags & AINPUT_FLAGS_BUTTON3) + winpr_str_append("AINPUT_FLAGS_BUTTON3", buffer, size, "|"); + if (flags & AINPUT_XFLAGS_BUTTON1) + winpr_str_append("AINPUT_XFLAGS_BUTTON1", buffer, size, "|"); + if (flags & AINPUT_XFLAGS_BUTTON2) + winpr_str_append("AINPUT_XFLAGS_BUTTON2", buffer, size, "|"); + + _snprintf(number, sizeof(number), "[0x%08" PRIx64 "]", flags); + winpr_str_append(number, buffer, size, " "); + + return buffer; +} + +#endif /* FREERDP_INT_AINPUT_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b5becfb16a25abbab3ccc01f8a4aa699513c3806 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2022 Armin Novak +# Copyright 2022 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("ainput") + +set(${MODULE_PREFIX}_SRCS ainput_main.c) + +set(${MODULE_PREFIX}_LIBS freerdp) +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/ainput_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/ainput_main.c new file mode 100644 index 0000000000000000000000000000000000000000..9dca2f72a0249ecb0a0a426bfd9e1f8218a26b7f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/ainput/server/ainput_main.c @@ -0,0 +1,597 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Advanced Input Virtual Channel Extension + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "../common/ainput_common.h" + +#define TAG CHANNELS_TAG("ainput.server") + +typedef enum +{ + AINPUT_INITIAL, + AINPUT_OPENED, + AINPUT_VERSION_SENT, +} eAInputChannelState; + +typedef struct +{ + ainput_server_context context; + + BOOL opened; + + HANDLE stopEvent; + + HANDLE thread; + void* ainput_channel; + + DWORD SessionId; + + BOOL isOpened; + BOOL externalThread; + + /* Channel state */ + eAInputChannelState state; + + wStream* buffer; +} ainput_server; + +static UINT ainput_server_context_poll(ainput_server_context* context); +static BOOL ainput_server_context_handle(ainput_server_context* context, HANDLE* handle); +static UINT ainput_server_context_poll_int(ainput_server_context* context); + +static BOOL ainput_server_is_open(ainput_server_context* context) +{ + ainput_server* ainput = (ainput_server*)context; + + WINPR_ASSERT(ainput); + return ainput->isOpened; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT ainput_server_open_channel(ainput_server* ainput) +{ + DWORD Error = 0; + HANDLE hEvent = NULL; + DWORD StartTick = 0; + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + + WINPR_ASSERT(ainput); + + if (WTSQuerySessionInformationA(ainput->context.vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + return ERROR_INTERNAL_ERROR; + } + + ainput->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + hEvent = WTSVirtualChannelManagerGetEventHandle(ainput->context.vcm); + StartTick = GetTickCount(); + + while (ainput->ainput_channel == NULL) + { + if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED) + { + Error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", Error); + return Error; + } + + ainput->ainput_channel = WTSVirtualChannelOpenEx(ainput->SessionId, AINPUT_DVC_CHANNEL_NAME, + WTS_CHANNEL_OPTION_DYNAMIC); + + Error = GetLastError(); + + if (Error == ERROR_NOT_FOUND) + { + WLog_DBG(TAG, "Channel %s not found", AINPUT_DVC_CHANNEL_NAME); + break; + } + + if (ainput->ainput_channel) + { + UINT32 channelId = 0; + BOOL status = TRUE; + + channelId = WTSChannelGetIdByHandle(ainput->ainput_channel); + + IFCALLRET(ainput->context.ChannelIdAssigned, status, &ainput->context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + + break; + } + + if (GetTickCount() - StartTick > 5000) + { + WLog_WARN(TAG, "Timeout opening channel %s", AINPUT_DVC_CHANNEL_NAME); + break; + } + } + + return ainput->ainput_channel ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; +} + +static UINT ainput_server_send_version(ainput_server* ainput) +{ + ULONG written = 0; + wStream* s = NULL; + + WINPR_ASSERT(ainput); + + s = ainput->buffer; + WINPR_ASSERT(s); + + Stream_SetPosition(s, 0); + if (!Stream_EnsureCapacity(s, 10)) + { + WLog_WARN(TAG, "[%s] out of memory", AINPUT_DVC_CHANNEL_NAME); + return ERROR_OUTOFMEMORY; + } + + Stream_Write_UINT16(s, MSG_AINPUT_VERSION); + Stream_Write_UINT32(s, AINPUT_VERSION_MAJOR); /* Version (4 bytes) */ + Stream_Write_UINT32(s, AINPUT_VERSION_MINOR); /* Version (4 bytes) */ + + WINPR_ASSERT(Stream_GetPosition(s) <= UINT32_MAX); + if (!WTSVirtualChannelWrite(ainput->ainput_channel, Stream_BufferAs(s, char), + (ULONG)Stream_GetPosition(s), &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +static UINT ainput_server_recv_mouse_event(ainput_server* ainput, wStream* s) +{ + UINT error = CHANNEL_RC_OK; + UINT64 flags = 0; + UINT64 time = 0; + INT32 x = 0; + INT32 y = 0; + char buffer[128] = { 0 }; + + WINPR_ASSERT(ainput); + WINPR_ASSERT(s); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 24)) + return ERROR_NO_DATA; + + Stream_Read_UINT64(s, time); + Stream_Read_UINT64(s, flags); + Stream_Read_INT32(s, x); + Stream_Read_INT32(s, y); + + WLog_VRB(TAG, "received: time=0x%08" PRIx64 ", flags=%s, %" PRId32 "x%" PRId32, time, + ainput_flags_to_string(flags, buffer, sizeof(buffer)), x, y); + IFCALLRET(ainput->context.MouseEvent, error, &ainput->context, time, flags, x, y); + + return error; +} + +static HANDLE ainput_server_get_channel_handle(ainput_server* ainput) +{ + void* buffer = NULL; + DWORD BytesReturned = 0; + HANDLE ChannelEvent = NULL; + + WINPR_ASSERT(ainput); + + if (WTSVirtualChannelQuery(ainput->ainput_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) == TRUE) + { + if (BytesReturned == sizeof(HANDLE)) + ChannelEvent = *(HANDLE*)buffer; + + WTSFreeMemory(buffer); + } + + return ChannelEvent; +} + +static DWORD WINAPI ainput_server_thread_func(LPVOID arg) +{ + DWORD nCount = 0; + HANDLE events[2] = { 0 }; + ainput_server* ainput = (ainput_server*)arg; + UINT error = CHANNEL_RC_OK; + DWORD status = 0; + + WINPR_ASSERT(ainput); + + nCount = 0; + events[nCount++] = ainput->stopEvent; + + while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0)) + { + switch (ainput->state) + { + case AINPUT_OPENED: + events[1] = ainput_server_get_channel_handle(ainput); + nCount = 2; + status = WaitForMultipleObjects(nCount, events, FALSE, 100); + switch (status) + { + case WAIT_TIMEOUT: + case WAIT_OBJECT_0 + 1: + case WAIT_OBJECT_0: + error = ainput_server_context_poll_int(&ainput->context); + break; + case WAIT_FAILED: + default: + WLog_WARN(TAG, "[%s] Wait for open failed", AINPUT_DVC_CHANNEL_NAME); + error = ERROR_INTERNAL_ERROR; + break; + } + break; + case AINPUT_VERSION_SENT: + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + switch (status) + { + case WAIT_TIMEOUT: + case WAIT_OBJECT_0 + 1: + case WAIT_OBJECT_0: + error = ainput_server_context_poll_int(&ainput->context); + break; + + case WAIT_FAILED: + default: + WLog_WARN(TAG, "[%s] Wait for version failed", AINPUT_DVC_CHANNEL_NAME); + error = ERROR_INTERNAL_ERROR; + break; + } + break; + default: + error = ainput_server_context_poll_int(&ainput->context); + break; + } + } + + (void)WTSVirtualChannelClose(ainput->ainput_channel); + ainput->ainput_channel = NULL; + + if (error && ainput->context.rdpcontext) + setChannelError(ainput->context.rdpcontext, error, + "ainput_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT ainput_server_open(ainput_server_context* context) +{ + ainput_server* ainput = (ainput_server*)context; + + WINPR_ASSERT(ainput); + + if (!ainput->externalThread && (ainput->thread == NULL)) + { + ainput->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!ainput->stopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + ainput->thread = CreateThread(NULL, 0, ainput_server_thread_func, ainput, 0, NULL); + if (!ainput->thread) + { + WLog_ERR(TAG, "CreateEvent failed!"); + (void)CloseHandle(ainput->stopEvent); + ainput->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + } + ainput->isOpened = TRUE; + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT ainput_server_close(ainput_server_context* context) +{ + UINT error = CHANNEL_RC_OK; + ainput_server* ainput = (ainput_server*)context; + + WINPR_ASSERT(ainput); + + if (!ainput->externalThread && ainput->thread) + { + (void)SetEvent(ainput->stopEvent); + + if (WaitForSingleObject(ainput->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(ainput->thread); + (void)CloseHandle(ainput->stopEvent); + ainput->thread = NULL; + ainput->stopEvent = NULL; + } + if (ainput->externalThread) + { + if (ainput->state != AINPUT_INITIAL) + { + (void)WTSVirtualChannelClose(ainput->ainput_channel); + ainput->ainput_channel = NULL; + ainput->state = AINPUT_INITIAL; + } + } + ainput->isOpened = FALSE; + + return error; +} + +static UINT ainput_server_initialize(ainput_server_context* context, BOOL externalThread) +{ + UINT error = CHANNEL_RC_OK; + ainput_server* ainput = (ainput_server*)context; + + WINPR_ASSERT(ainput); + + if (ainput->isOpened) + { + WLog_WARN(TAG, "Application error: AINPUT channel already initialized, calling in this " + "state is not possible!"); + return ERROR_INVALID_STATE; + } + ainput->externalThread = externalThread; + return error; +} + +ainput_server_context* ainput_server_context_new(HANDLE vcm) +{ + ainput_server* ainput = (ainput_server*)calloc(1, sizeof(ainput_server)); + + if (!ainput) + return NULL; + + ainput->context.vcm = vcm; + ainput->context.Open = ainput_server_open; + ainput->context.IsOpen = ainput_server_is_open; + ainput->context.Close = ainput_server_close; + ainput->context.Initialize = ainput_server_initialize; + ainput->context.Poll = ainput_server_context_poll; + ainput->context.ChannelHandle = ainput_server_context_handle; + + ainput->buffer = Stream_New(NULL, 4096); + if (!ainput->buffer) + goto fail; + return &ainput->context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + ainput_server_context_free(&ainput->context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void ainput_server_context_free(ainput_server_context* context) +{ + ainput_server* ainput = (ainput_server*)context; + if (ainput) + { + ainput_server_close(context); + Stream_Free(ainput->buffer, TRUE); + } + free(ainput); +} + +static UINT ainput_process_message(ainput_server* ainput) +{ + BOOL rc = 0; + UINT error = ERROR_INTERNAL_ERROR; + ULONG BytesReturned = 0; + ULONG ActualBytesReturned = 0; + UINT16 MessageId = 0; + wStream* s = NULL; + + WINPR_ASSERT(ainput); + WINPR_ASSERT(ainput->ainput_channel); + + s = ainput->buffer; + WINPR_ASSERT(s); + + Stream_SetPosition(s, 0); + rc = WTSVirtualChannelRead(ainput->ainput_channel, 0, NULL, 0, &BytesReturned); + if (!rc) + goto out; + + if (BytesReturned < 2) + { + error = CHANNEL_RC_OK; + goto out; + } + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + if (WTSVirtualChannelRead(ainput->ainput_channel, 0, Stream_BufferAs(s, char), + (ULONG)Stream_Capacity(s), &ActualBytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + goto out; + } + + if (BytesReturned != ActualBytesReturned) + { + WLog_ERR(TAG, "WTSVirtualChannelRead size mismatch %" PRId32 ", expected %" PRId32, + ActualBytesReturned, BytesReturned); + goto out; + } + + Stream_SetLength(s, ActualBytesReturned); + Stream_Read_UINT16(s, MessageId); + + switch (MessageId) + { + case MSG_AINPUT_MOUSE: + error = ainput_server_recv_mouse_event(ainput, s); + break; + + default: + WLog_ERR(TAG, "audin_server_thread_func: unknown MessageId %" PRIu8 "", MessageId); + break; + } + +out: + if (error) + WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error); + + return error; +} + +BOOL ainput_server_context_handle(ainput_server_context* context, HANDLE* handle) +{ + ainput_server* ainput = (ainput_server*)context; + WINPR_ASSERT(ainput); + WINPR_ASSERT(handle); + + if (!ainput->externalThread) + { + WLog_WARN(TAG, "[%s] externalThread fail!", AINPUT_DVC_CHANNEL_NAME); + return FALSE; + } + if (ainput->state == AINPUT_INITIAL) + { + WLog_WARN(TAG, "[%s] state fail!", AINPUT_DVC_CHANNEL_NAME); + return FALSE; + } + *handle = ainput_server_get_channel_handle(ainput); + return TRUE; +} + +UINT ainput_server_context_poll_int(ainput_server_context* context) +{ + ainput_server* ainput = (ainput_server*)context; + UINT error = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(ainput); + + switch (ainput->state) + { + case AINPUT_INITIAL: + error = ainput_server_open_channel(ainput); + if (error) + WLog_ERR(TAG, "ainput_server_open_channel failed with error %" PRIu32 "!", error); + else + ainput->state = AINPUT_OPENED; + break; + case AINPUT_OPENED: + { + union + { + BYTE* pb; + void* pv; + } buffer; + DWORD BytesReturned = 0; + + buffer.pv = NULL; + + if (WTSVirtualChannelQuery(ainput->ainput_channel, WTSVirtualChannelReady, &buffer.pv, + &BytesReturned) != TRUE) + { + WLog_ERR(TAG, "WTSVirtualChannelReady failed,"); + } + else + { + if (*buffer.pb != 0) + { + error = ainput_server_send_version(ainput); + if (error) + WLog_ERR(TAG, "audin_server_send_version failed with error %" PRIu32 "!", + error); + else + ainput->state = AINPUT_VERSION_SENT; + } + else + error = CHANNEL_RC_OK; + } + WTSFreeMemory(buffer.pv); + } + break; + case AINPUT_VERSION_SENT: + error = ainput_process_message(ainput); + break; + + default: + WLog_ERR(TAG, "AINPUT channel is in invalid state %d", ainput->state); + break; + } + + return error; +} + +UINT ainput_server_context_poll(ainput_server_context* context) +{ + ainput_server* ainput = (ainput_server*)context; + + WINPR_ASSERT(ainput); + if (!ainput->externalThread) + { + WLog_WARN(TAG, "[%s] externalThread fail!", AINPUT_DVC_CHANNEL_NAME); + return ERROR_INTERNAL_ERROR; + } + return ainput_server_context_poll_int(context); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2c92a64aa89e5a9ea0f238da4df7abca1e48e502 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("audin") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..9956bf954fa27b7ce2340e467bce6a0de6b22fbb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/ChannelOptions.cmake @@ -0,0 +1,24 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +if(ANDROID) + set(OPTION_SERVER_DEFAULT OFF) +endif() + +define_channel_options( + NAME + "audin" + TYPE + "dynamic" + DESCRIPTION + "Audio Input Redirection Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEAI]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ce4015bc106a2b418a8d084025ae65d83b83872 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/CMakeLists.txt @@ -0,0 +1,58 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("audin") + +set(${MODULE_PREFIX}_SRCS audin_main.c audin_main.h) + +set(${MODULE_PREFIX}_LIBS freerdp winpr) + +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") + +if(WITH_OSS) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "oss" "") +endif() + +if(WITH_ALSA) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "alsa" "") +endif() + +if(WITH_PULSE) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "pulse" "") +endif() + +if(WITH_OPENSLES) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "opensles" "") +endif() + +if(WITH_WINMM) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "winmm" "") +endif() + +if(WITH_MACAUDIO) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "mac" "") +endif() + +if(WITH_SNDIO) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "sndio" "") +endif() + +if(WITH_IOSAUDIO) + add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "ios" "") +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..432ff1b4f8564681eed0fa1085a33c207c810c4e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "alsa" "") + +find_package(ALSA REQUIRED) + +set(${MODULE_PREFIX}_SRCS audin_alsa.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${ALSA_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${ALSA_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/audin_alsa.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/audin_alsa.c new file mode 100644 index 0000000000000000000000000000000000000000..82ce66e64b5a8f57623c24805627ca2740e4d08d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/alsa/audin_alsa.c @@ -0,0 +1,463 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - ALSA implementation + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "audin_main.h" + +typedef struct +{ + IAudinDevice iface; + + char* device_name; + UINT32 frames_per_packet; + AUDIO_FORMAT aformat; + + HANDLE thread; + HANDLE stopEvent; + + AudinReceive receive; + void* user_data; + + rdpContext* rdpcontext; + wLog* log; + size_t bytes_per_frame; +} AudinALSADevice; + +static snd_pcm_format_t audin_alsa_format(UINT32 wFormatTag, UINT32 bitPerChannel) +{ + switch (wFormatTag) + { + case WAVE_FORMAT_PCM: + switch (bitPerChannel) + { + case 16: + return SND_PCM_FORMAT_S16_LE; + + case 8: + return SND_PCM_FORMAT_S8; + + default: + return SND_PCM_FORMAT_UNKNOWN; + } + + default: + return SND_PCM_FORMAT_UNKNOWN; + } +} + +static BOOL audin_alsa_set_params(AudinALSADevice* alsa, snd_pcm_t* capture_handle) +{ + int error = 0; + SSIZE_T s = 0; + UINT32 channels = alsa->aformat.nChannels; + snd_pcm_hw_params_t* hw_params = NULL; + snd_pcm_format_t format = + audin_alsa_format(alsa->aformat.wFormatTag, alsa->aformat.wBitsPerSample); + + if ((error = snd_pcm_hw_params_malloc(&hw_params)) < 0) + { + WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_hw_params_malloc (%s)", snd_strerror(error)); + return FALSE; + } + + snd_pcm_hw_params_any(capture_handle, hw_params); + snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); + snd_pcm_hw_params_set_format(capture_handle, hw_params, format); + snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &alsa->aformat.nSamplesPerSec, NULL); + snd_pcm_hw_params_set_channels_near(capture_handle, hw_params, &channels); + snd_pcm_hw_params(capture_handle, hw_params); + snd_pcm_hw_params_free(hw_params); + snd_pcm_prepare(capture_handle); + if (channels > UINT16_MAX) + return FALSE; + s = snd_pcm_format_size(format, 1); + if ((s < 0) || (s > UINT16_MAX)) + return FALSE; + alsa->aformat.nChannels = (UINT16)channels; + alsa->bytes_per_frame = (size_t)s * channels; + return TRUE; +} + +static DWORD WINAPI audin_alsa_thread_func(LPVOID arg) +{ + DWORD error = CHANNEL_RC_OK; + BYTE* buffer = NULL; + AudinALSADevice* alsa = (AudinALSADevice*)arg; + + WINPR_ASSERT(alsa); + + WLog_Print(alsa->log, WLOG_DEBUG, "in"); + + snd_pcm_t* capture_handle = NULL; + const int rc = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0); + if (rc < 0) + { + WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_open (%s)", snd_strerror(rc)); + error = CHANNEL_RC_INITIALIZATION_ERROR; + goto out; + } + + if (!audin_alsa_set_params(alsa, capture_handle)) + { + WLog_Print(alsa->log, WLOG_ERROR, "audin_alsa_set_params failed"); + goto out; + } + + buffer = + (BYTE*)calloc(alsa->frames_per_packet + alsa->aformat.nBlockAlign, alsa->bytes_per_frame); + + if (!buffer) + { + WLog_Print(alsa->log, WLOG_ERROR, "calloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + while (1) + { + size_t frames = alsa->frames_per_packet; + const DWORD status = WaitForSingleObject(alsa->stopEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_Print(alsa->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "!", + error); + break; + } + + if (status == WAIT_OBJECT_0) + { + WLog_Print(alsa->log, WLOG_DEBUG, "alsa->stopEvent requests termination"); + break; + } + + snd_pcm_sframes_t framesRead = snd_pcm_readi(capture_handle, buffer, frames); + + if (framesRead == 0) + continue; + + if (framesRead == -EPIPE) + { + const int res = snd_pcm_recover(capture_handle, (int)framesRead, 0); + if (res < 0) + WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_recover (%s)", snd_strerror(res)); + + continue; + } + else if (framesRead < 0) + { + WLog_Print(alsa->log, WLOG_ERROR, "snd_pcm_readi (%s)", snd_strerror((int)framesRead)); + error = ERROR_INTERNAL_ERROR; + break; + } + + error = alsa->receive(&alsa->aformat, buffer, + WINPR_ASSERTING_INT_CAST(size_t, framesRead) * alsa->bytes_per_frame, + alsa->user_data); + + if (error) + { + WLog_Print(alsa->log, WLOG_ERROR, "audin_alsa_thread_receive failed with error %ld", + error); + break; + } + } + + free(buffer); + + if (capture_handle) + { + const int res = snd_pcm_close(capture_handle); + if (res < 0) + WLog_Print(alsa->log, WLOG_WARN, "snd_pcm_close (%s)", snd_strerror(res)); + } + +out: + WLog_Print(alsa->log, WLOG_DEBUG, "out"); + + if (error && alsa->rdpcontext) + setChannelError(alsa->rdpcontext, error, "audin_alsa_thread_func reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_alsa_free(IAudinDevice* device) +{ + AudinALSADevice* alsa = (AudinALSADevice*)device; + + if (alsa) + free(alsa->device_name); + + free(alsa); + return CHANNEL_RC_OK; +} + +static BOOL audin_alsa_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format) +{ + if (!device || !format) + return FALSE; + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->cbSize == 0 && (format->nSamplesPerSec <= 48000) && + (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) && + (format->nChannels == 1 || format->nChannels == 2)) + { + return TRUE; + } + + break; + + default: + return FALSE; + } + + return FALSE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_alsa_set_format(IAudinDevice* device, const AUDIO_FORMAT* format, + UINT32 FramesPerPacket) +{ + AudinALSADevice* alsa = (AudinALSADevice*)device; + + if (!alsa || !format) + return ERROR_INVALID_PARAMETER; + + alsa->aformat = *format; + alsa->frames_per_packet = FramesPerPacket; + + if (audin_alsa_format(format->wFormatTag, format->wBitsPerSample) == SND_PCM_FORMAT_UNKNOWN) + return ERROR_INTERNAL_ERROR; + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive, void* user_data) +{ + AudinALSADevice* alsa = (AudinALSADevice*)device; + + if (!device || !receive || !user_data) + return ERROR_INVALID_PARAMETER; + + alsa->receive = receive; + alsa->user_data = user_data; + + if (!(alsa->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_Print(alsa->log, WLOG_ERROR, "CreateEvent failed!"); + goto error_out; + } + + if (!(alsa->thread = CreateThread(NULL, 0, audin_alsa_thread_func, alsa, 0, NULL))) + { + WLog_Print(alsa->log, WLOG_ERROR, "CreateThread failed!"); + goto error_out; + } + + return CHANNEL_RC_OK; +error_out: + (void)CloseHandle(alsa->stopEvent); + alsa->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_alsa_close(IAudinDevice* device) +{ + UINT error = CHANNEL_RC_OK; + AudinALSADevice* alsa = (AudinALSADevice*)device; + + if (!alsa) + return ERROR_INVALID_PARAMETER; + + if (alsa->stopEvent) + { + (void)SetEvent(alsa->stopEvent); + + if (WaitForSingleObject(alsa->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_Print(alsa->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "", + error); + return error; + } + + (void)CloseHandle(alsa->stopEvent); + alsa->stopEvent = NULL; + (void)CloseHandle(alsa->thread); + alsa->thread = NULL; + } + + alsa->receive = NULL; + alsa->user_data = NULL; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_alsa_parse_addin_args(AudinALSADevice* device, const ADDIN_ARGV* args) +{ + int status = 0; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + AudinALSADevice* alsa = device; + COMMAND_LINE_ARGUMENT_A audin_alsa_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "audio device name" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, args->argv, audin_alsa_args, flags, alsa, NULL, + NULL); + + if (status < 0) + return ERROR_INVALID_PARAMETER; + + arg = audin_alsa_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + alsa->device_name = _strdup(arg->Value); + + if (!alsa->device_name) + { + WLog_Print(alsa->log, WLOG_ERROR, "_strdup failed!"); + return CHANNEL_RC_NO_MEMORY; + } + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE alsa_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args = NULL; + AudinALSADevice* alsa = NULL; + UINT error = 0; + alsa = (AudinALSADevice*)calloc(1, sizeof(AudinALSADevice)); + + if (!alsa) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + alsa->log = WLog_Get(TAG); + alsa->iface.Open = audin_alsa_open; + alsa->iface.FormatSupported = audin_alsa_format_supported; + alsa->iface.SetFormat = audin_alsa_set_format; + alsa->iface.Close = audin_alsa_close; + alsa->iface.Free = audin_alsa_free; + alsa->rdpcontext = pEntryPoints->rdpcontext; + args = pEntryPoints->args; + + if ((error = audin_alsa_parse_addin_args(alsa, args))) + { + WLog_Print(alsa->log, WLOG_ERROR, + "audin_alsa_parse_addin_args failed with errorcode %" PRIu32 "!", error); + goto error_out; + } + + if (!alsa->device_name) + { + alsa->device_name = _strdup("default"); + + if (!alsa->device_name) + { + WLog_Print(alsa->log, WLOG_ERROR, "_strdup failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + } + + alsa->frames_per_packet = 128; + alsa->aformat.nChannels = 2; + alsa->aformat.wBitsPerSample = 16; + alsa->aformat.wFormatTag = WAVE_FORMAT_PCM; + alsa->aformat.nSamplesPerSec = 44100; + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)alsa))) + { + WLog_Print(alsa->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!", + error); + goto error_out; + } + + return CHANNEL_RC_OK; +error_out: + free(alsa->device_name); + free(alsa); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.c new file mode 100644 index 0000000000000000000000000000000000000000..35d4d89fd94b586251e2855ca36713970d5d8dde --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.c @@ -0,0 +1,1110 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2015 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "audin_main.h" + +#define SNDIN_VERSION 0x02 + +typedef enum +{ + MSG_SNDIN_VERSION = 0x01, + MSG_SNDIN_FORMATS = 0x02, + MSG_SNDIN_OPEN = 0x03, + MSG_SNDIN_OPEN_REPLY = 0x04, + MSG_SNDIN_DATA_INCOMING = 0x05, + MSG_SNDIN_DATA = 0x06, + MSG_SNDIN_FORMATCHANGE = 0x07, +} MSG_SNDIN; + +typedef struct +{ + IWTSVirtualChannelCallback iface; + + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; + IWTSVirtualChannel* channel; + + /** + * The supported format list sent back to the server, which needs to + * be stored as reference when the server sends the format index in + * Open PDU and Format Change PDU + */ + AUDIO_FORMAT* formats; + UINT32 formats_count; +} AUDIN_CHANNEL_CALLBACK; + +typedef struct +{ + IWTSPlugin iface; + + GENERIC_LISTENER_CALLBACK* listener_callback; + + /* Parsed plugin data */ + AUDIO_FORMAT* fixed_format; + char* subsystem; + char* device_name; + + /* Device interface */ + IAudinDevice* device; + + rdpContext* rdpcontext; + BOOL attached; + wStream* data; + AUDIO_FORMAT* format; + UINT32 FramesPerPacket; + + FREERDP_DSP_CONTEXT* dsp_context; + wLog* log; + + IWTSListener* listener; + + BOOL initialized; + UINT32 version; +} AUDIN_PLUGIN; + +static BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args); + +static UINT audin_channel_write_and_free(AUDIN_CHANNEL_CALLBACK* callback, wStream* out, + BOOL freeStream) +{ + if (!callback || !out) + return ERROR_INVALID_PARAMETER; + + if (!callback->channel || !callback->channel->Write) + return ERROR_INTERNAL_ERROR; + + Stream_SealLength(out); + WINPR_ASSERT(Stream_Length(out) <= UINT32_MAX); + const UINT error = callback->channel->Write(callback->channel, (ULONG)Stream_Length(out), + Stream_Buffer(out), NULL); + + if (freeStream) + Stream_Free(out, TRUE); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_process_version(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s) +{ + const UINT32 ClientVersion = SNDIN_VERSION; + UINT32 ServerVersion = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, ServerVersion); + WLog_Print(audin->log, WLOG_DEBUG, "ServerVersion=%" PRIu32 ", ClientVersion=%" PRIu32, + ServerVersion, ClientVersion); + + /* Do not answer server packet, we do not support the channel version. */ + if (ServerVersion > ClientVersion) + { + WLog_Print(audin->log, WLOG_WARN, + "Incompatible channel version server=%" PRIu32 + ", client supports version=%" PRIu32, + ServerVersion, ClientVersion); + return CHANNEL_RC_OK; + } + audin->version = ServerVersion; + + wStream* out = Stream_New(NULL, 5); + + if (!out) + { + WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!"); + return ERROR_OUTOFMEMORY; + } + + Stream_Write_UINT8(out, MSG_SNDIN_VERSION); + Stream_Write_UINT32(out, ClientVersion); + return audin_channel_write_and_free(callback, out, TRUE); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_send_incoming_data_pdu(AUDIN_CHANNEL_CALLBACK* callback) +{ + BYTE out_data[1] = { MSG_SNDIN_DATA_INCOMING }; + + if (!callback || !callback->channel || !callback->channel->Write) + return ERROR_INTERNAL_ERROR; + + return callback->channel->Write(callback->channel, 1, out_data, NULL); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s) +{ + UINT error = ERROR_INTERNAL_ERROR; + UINT32 NumFormats = 0; + UINT32 cbSizeFormatsPacket = 0; + + WINPR_ASSERT(audin); + WINPR_ASSERT(callback); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, NumFormats); + WLog_Print(audin->log, WLOG_DEBUG, "NumFormats %" PRIu32 "", NumFormats); + + if ((NumFormats < 1) || (NumFormats > 1000)) + { + WLog_Print(audin->log, WLOG_ERROR, "bad NumFormats %" PRIu32 "", NumFormats); + return ERROR_INVALID_DATA; + } + + Stream_Seek_UINT32(s); /* cbSizeFormatsPacket */ + callback->formats = audio_formats_new(NumFormats); + + if (!callback->formats) + { + WLog_Print(audin->log, WLOG_ERROR, "calloc failed!"); + return ERROR_INVALID_DATA; + } + + wStream* out = Stream_New(NULL, 9); + + if (!out) + { + error = CHANNEL_RC_NO_MEMORY; + WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!"); + goto out; + } + + Stream_Seek(out, 9); + + /* SoundFormats (variable) */ + for (UINT32 i = 0; i < NumFormats; i++) + { + AUDIO_FORMAT format = { 0 }; + + if (!audio_format_read(s, &format)) + { + error = ERROR_INVALID_DATA; + goto out; + } + + audio_format_print(audin->log, WLOG_DEBUG, &format); + + if (!audio_format_compatible(audin->fixed_format, &format)) + { + audio_format_free(&format); + continue; + } + + if (freerdp_dsp_supports_format(&format, TRUE) || + audin->device->FormatSupported(audin->device, &format)) + { + /* Store the agreed format in the corresponding index */ + callback->formats[callback->formats_count++] = format; + + if (!audio_format_write(out, &format)) + { + error = CHANNEL_RC_NO_MEMORY; + WLog_Print(audin->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!"); + goto out; + } + } + else + { + audio_format_free(&format); + } + } + + if ((error = audin_send_incoming_data_pdu(callback))) + { + WLog_Print(audin->log, WLOG_ERROR, "audin_send_incoming_data_pdu failed!"); + goto out; + } + + cbSizeFormatsPacket = (UINT32)Stream_GetPosition(out); + Stream_SetPosition(out, 0); + Stream_Write_UINT8(out, MSG_SNDIN_FORMATS); /* Header (1 byte) */ + Stream_Write_UINT32(out, callback->formats_count); /* NumFormats (4 bytes) */ + Stream_Write_UINT32(out, cbSizeFormatsPacket); /* cbSizeFormatsPacket (4 bytes) */ + Stream_SetPosition(out, cbSizeFormatsPacket); + error = audin_channel_write_and_free(callback, out, FALSE); +out: + + if (error != CHANNEL_RC_OK) + { + audio_formats_free(callback->formats, NumFormats); + callback->formats = NULL; + } + + Stream_Free(out, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_send_format_change_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, + UINT32 NewFormat) +{ + WINPR_ASSERT(audin); + WINPR_ASSERT(callback); + + wStream* out = Stream_New(NULL, 5); + + if (!out) + { + WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!"); + return CHANNEL_RC_OK; + } + + Stream_Write_UINT8(out, MSG_SNDIN_FORMATCHANGE); + Stream_Write_UINT32(out, NewFormat); + return audin_channel_write_and_free(callback, out, TRUE); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_send_open_reply_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, + UINT32 Result) +{ + WINPR_ASSERT(audin); + WINPR_ASSERT(callback); + + wStream* out = Stream_New(NULL, 5); + + if (!out) + { + WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT8(out, MSG_SNDIN_OPEN_REPLY); + Stream_Write_UINT32(out, Result); + return audin_channel_write_and_free(callback, out, TRUE); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_receive_wave_data(const AUDIO_FORMAT* format, const BYTE* data, size_t size, + void* user_data) +{ + WINPR_ASSERT(format); + + UINT error = ERROR_INTERNAL_ERROR; + AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)user_data; + + if (!callback) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin; + + if (!audin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + if (!audin->attached) + return CHANNEL_RC_OK; + + Stream_SetPosition(audin->data, 0); + + if (!Stream_EnsureRemainingCapacity(audin->data, 1)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write_UINT8(audin->data, MSG_SNDIN_DATA); + + const BOOL compatible = audio_format_compatible(format, audin->format); + if (compatible && audin->device->FormatSupported(audin->device, audin->format)) + { + if (!Stream_EnsureRemainingCapacity(audin->data, size)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write(audin->data, data, size); + } + else + { + if (!freerdp_dsp_encode(audin->dsp_context, format, data, size, audin->data)) + return ERROR_INTERNAL_ERROR; + } + + /* Did not encode anything, skip this, the codec is not ready for output. */ + if (Stream_GetPosition(audin->data) <= 1) + return CHANNEL_RC_OK; + + audio_format_print(audin->log, WLOG_TRACE, audin->format); + WLog_Print(audin->log, WLOG_TRACE, "[%" PRIdz "/%" PRIdz "]", size, + Stream_GetPosition(audin->data) - 1); + + if ((error = audin_send_incoming_data_pdu(callback))) + { + WLog_Print(audin->log, WLOG_ERROR, "audin_send_incoming_data_pdu failed!"); + return error; + } + + return audin_channel_write_and_free(callback, audin->data, FALSE); +} + +static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback) +{ + UINT error = ERROR_INTERNAL_ERROR; + AUDIO_FORMAT format = { 0 }; + + if (!audin || !audin->device) + return FALSE; + + format = *audin->format; + const BOOL supported = + IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format); + WLog_Print(audin->log, WLOG_DEBUG, "microphone uses %s codec", + audio_format_get_tag_string(format.wFormatTag)); + + if (!supported) + { + /* Default sample rates supported by most backends. */ + const UINT32 samplerates[] = { format.nSamplesPerSec, 96000, 48000, 44100, 22050 }; + BOOL test = FALSE; + + format.wFormatTag = WAVE_FORMAT_PCM; + format.wBitsPerSample = 16; + format.cbSize = 0; + for (size_t x = 0; x < ARRAYSIZE(samplerates); x++) + { + format.nSamplesPerSec = samplerates[x]; + for (UINT16 y = audin->format->nChannels; y > 0; y--) + { + format.nChannels = y; + format.nBlockAlign = 2 * format.nChannels; + test = IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format); + if (test) + break; + } + if (test) + break; + } + if (!test) + return FALSE; + } + + IFCALLRET(audin->device->SetFormat, error, audin->device, &format, audin->FramesPerPacket); + + if (error != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "SetFormat failed with errorcode %" PRIu32 "", error); + return FALSE; + } + + if (!freerdp_dsp_context_reset(audin->dsp_context, audin->format, audin->FramesPerPacket)) + return FALSE; + + IFCALLRET(audin->device->Open, error, audin->device, audin_receive_wave_data, callback); + + if (error != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "Open failed with errorcode %" PRIu32 "", error); + return FALSE; + } + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_process_open(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, wStream* s) +{ + UINT32 initialFormat = 0; + UINT32 FramesPerPacket = 0; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, FramesPerPacket); + Stream_Read_UINT32(s, initialFormat); + WLog_Print(audin->log, WLOG_DEBUG, "FramesPerPacket=%" PRIu32 " initialFormat=%" PRIu32 "", + FramesPerPacket, initialFormat); + audin->FramesPerPacket = FramesPerPacket; + + if (initialFormat >= callback->formats_count) + { + WLog_Print(audin->log, WLOG_ERROR, "invalid format index %" PRIu32 " (total %" PRIu32 ")", + initialFormat, callback->formats_count); + return ERROR_INVALID_DATA; + } + + audin->format = &callback->formats[initialFormat]; + + if (!audin_open_device(audin, callback)) + return ERROR_INTERNAL_ERROR; + + if ((error = audin_send_format_change_pdu(audin, callback, initialFormat))) + { + WLog_Print(audin->log, WLOG_ERROR, "audin_send_format_change_pdu failed!"); + return error; + } + + if ((error = audin_send_open_reply_pdu(audin, callback, 0))) + WLog_Print(audin->log, WLOG_ERROR, "audin_send_open_reply_pdu failed!"); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_process_format_change(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback, + wStream* s) +{ + UINT32 NewFormat = 0; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, NewFormat); + WLog_Print(audin->log, WLOG_DEBUG, "NewFormat=%" PRIu32 "", NewFormat); + + if (NewFormat >= callback->formats_count) + { + WLog_Print(audin->log, WLOG_ERROR, "invalid format index %" PRIu32 " (total %" PRIu32 ")", + NewFormat, callback->formats_count); + return ERROR_INVALID_DATA; + } + + audin->format = &callback->formats[NewFormat]; + + if (audin->device) + { + IFCALLRET(audin->device->Close, error, audin->device); + + if (error != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "Close failed with errorcode %" PRIu32 "", error); + return error; + } + } + + if (!audin_open_device(audin, callback)) + return ERROR_INTERNAL_ERROR; + + if ((error = audin_send_format_change_pdu(audin, callback, NewFormat))) + WLog_ERR(TAG, "audin_send_format_change_pdu failed!"); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + UINT error = 0; + BYTE MessageId = 0; + AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback; + + if (!callback || !data) + return ERROR_INVALID_PARAMETER; + + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin; + + if (!audin) + return ERROR_INTERNAL_ERROR; + + if (!Stream_CheckAndLogRequiredCapacity(TAG, data, 1)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(data, MessageId); + WLog_Print(audin->log, WLOG_DEBUG, "MessageId=0x%02" PRIx8 "", MessageId); + + switch (MessageId) + { + case MSG_SNDIN_VERSION: + error = audin_process_version(audin, callback, data); + break; + + case MSG_SNDIN_FORMATS: + error = audin_process_formats(audin, callback, data); + break; + + case MSG_SNDIN_OPEN: + error = audin_process_open(audin, callback, data); + break; + + case MSG_SNDIN_FORMATCHANGE: + error = audin_process_format_change(audin, callback, data); + break; + + default: + WLog_Print(audin->log, WLOG_ERROR, "unknown MessageId=0x%02" PRIx8 "", MessageId); + error = ERROR_INVALID_DATA; + break; + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback; + WINPR_ASSERT(callback); + + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin; + WINPR_ASSERT(audin); + + UINT error = CHANNEL_RC_OK; + WLog_Print(audin->log, WLOG_TRACE, "..."); + + if (audin->device) + { + IFCALLRET(audin->device->Close, error, audin->device); + + if (error != CHANNEL_RC_OK) + WLog_Print(audin->log, WLOG_ERROR, "Close failed with errorcode %" PRIu32 "", error); + } + + audin->format = NULL; + audio_formats_free(callback->formats, callback->formats_count); + free(callback); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, + IWTSVirtualChannel* pChannel, BYTE* Data, + BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback) +{ + GENERIC_LISTENER_CALLBACK* listener_callback = (GENERIC_LISTENER_CALLBACK*)pListenerCallback; + + if (!listener_callback || !listener_callback->plugin) + return ERROR_INTERNAL_ERROR; + + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)listener_callback->plugin; + WLog_Print(audin->log, WLOG_TRACE, "..."); + AUDIN_CHANNEL_CALLBACK* callback = + (AUDIN_CHANNEL_CALLBACK*)calloc(1, sizeof(AUDIN_CHANNEL_CALLBACK)); + + if (!callback) + { + WLog_Print(audin->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + callback->iface.OnDataReceived = audin_on_data_received; + callback->iface.OnClose = audin_on_close; + callback->plugin = listener_callback->plugin; + callback->channel_mgr = listener_callback->channel_mgr; + callback->channel = pChannel; + *ppCallback = (IWTSVirtualChannelCallback*)callback; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr) +{ + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin; + + if (!audin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + if (!pChannelMgr) + return ERROR_INVALID_PARAMETER; + + if (audin->initialized) + { + WLog_ERR(TAG, "[%s] channel initialized twice, aborting", AUDIN_DVC_CHANNEL_NAME); + return ERROR_INVALID_DATA; + } + + WLog_Print(audin->log, WLOG_TRACE, "..."); + audin->listener_callback = + (GENERIC_LISTENER_CALLBACK*)calloc(1, sizeof(GENERIC_LISTENER_CALLBACK)); + + if (!audin->listener_callback) + { + WLog_Print(audin->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + audin->listener_callback->iface.OnNewChannelConnection = audin_on_new_channel_connection; + audin->listener_callback->plugin = pPlugin; + audin->listener_callback->channel_mgr = pChannelMgr; + const UINT rc = pChannelMgr->CreateListener(pChannelMgr, AUDIN_DVC_CHANNEL_NAME, 0, + &audin->listener_callback->iface, &audin->listener); + + audin->initialized = rc == CHANNEL_RC_OK; + return rc; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_plugin_terminated(IWTSPlugin* pPlugin) +{ + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin; + UINT error = CHANNEL_RC_OK; + + if (!audin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + WLog_Print(audin->log, WLOG_TRACE, "..."); + + if (audin->listener_callback) + { + IWTSVirtualChannelManager* mgr = audin->listener_callback->channel_mgr; + if (mgr) + IFCALL(mgr->DestroyListener, mgr, audin->listener); + } + audio_formats_free(audin->fixed_format, 1); + + if (audin->device) + { + IFCALLRET(audin->device->Free, error, audin->device); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(audin->log, WLOG_ERROR, "Free failed with errorcode %" PRIu32 "", error); + // dont stop on error + } + + audin->device = NULL; + } + + freerdp_dsp_context_free(audin->dsp_context); + Stream_Free(audin->data, TRUE); + free(audin->subsystem); + free(audin->device_name); + free(audin->listener_callback); + free(audin); + return CHANNEL_RC_OK; +} + +static UINT audin_plugin_attached(IWTSPlugin* pPlugin) +{ + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin; + UINT error = CHANNEL_RC_OK; + + if (!audin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + audin->attached = TRUE; + return error; +} + +static UINT audin_plugin_detached(IWTSPlugin* pPlugin) +{ + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin; + UINT error = CHANNEL_RC_OK; + + if (!audin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + audin->attached = FALSE; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* device) +{ + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin; + + WINPR_ASSERT(audin); + + if (audin->device) + { + WLog_Print(audin->log, WLOG_ERROR, "existing device, abort."); + return ERROR_ALREADY_EXISTS; + } + + WLog_Print(audin->log, WLOG_DEBUG, "device registered."); + audin->device = device; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin, const char* name, const ADDIN_ARGV* args) +{ + WINPR_ASSERT(audin); + + FREERDP_AUDIN_DEVICE_ENTRY_POINTS entryPoints = { 0 }; + UINT error = ERROR_INTERNAL_ERROR; + + PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0); + PFREERDP_AUDIN_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_AUDIN_DEVICE_ENTRY); + + if (entry == NULL) + { + WLog_Print(audin->log, WLOG_ERROR, + "freerdp_load_channel_addin_entry did not return any function pointers for %s ", + name); + return ERROR_INVALID_FUNCTION; + } + + entryPoints.plugin = &audin->iface; + entryPoints.pRegisterAudinDevice = audin_register_device_plugin; + entryPoints.args = args; + entryPoints.rdpcontext = audin->rdpcontext; + + error = entry(&entryPoints); + if (error) + { + WLog_Print(audin->log, WLOG_ERROR, "%s entry returned error %" PRIu32 ".", name, error); + return error; + } + + WLog_Print(audin->log, WLOG_INFO, "Loaded %s backend for audin", name); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_set_subsystem(AUDIN_PLUGIN* audin, const char* subsystem) +{ + WINPR_ASSERT(audin); + + free(audin->subsystem); + audin->subsystem = _strdup(subsystem); + + if (!audin->subsystem) + { + WLog_Print(audin->log, WLOG_ERROR, "_strdup failed!"); + return ERROR_NOT_ENOUGH_MEMORY; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_set_device_name(AUDIN_PLUGIN* audin, const char* device_name) +{ + WINPR_ASSERT(audin); + + free(audin->device_name); + audin->device_name = _strdup(device_name); + + if (!audin->device_name) + { + WLog_Print(audin->log, WLOG_ERROR, "_strdup failed!"); + return ERROR_NOT_ENOUGH_MEMORY; + } + + return CHANNEL_RC_OK; +} + +BOOL audin_process_addin_args(AUDIN_PLUGIN* audin, const ADDIN_ARGV* args) +{ + COMMAND_LINE_ARGUMENT_A audin_args[] = { + { "sys", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "subsystem" }, + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "device" }, + { "format", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "format" }, + { "rate", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "rate" }, + { "channel", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "channel" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } + }; + + if (!args || args->argc == 1) + return TRUE; + + const DWORD flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + const int status = + CommandLineParseArgumentsA(args->argc, args->argv, audin_args, flags, audin, NULL, NULL); + + if (status != 0) + return FALSE; + + const COMMAND_LINE_ARGUMENT_A* arg = audin_args; + errno = 0; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "sys") + { + const UINT error = audin_set_subsystem(audin, arg->Value); + if (error != CHANNEL_RC_OK) + { + WLog_Print(audin->log, WLOG_ERROR, + "audin_set_subsystem failed with error %" PRIu32 "!", error); + return FALSE; + } + } + CommandLineSwitchCase(arg, "dev") + { + const UINT error = audin_set_device_name(audin, arg->Value); + if (error != CHANNEL_RC_OK) + { + WLog_Print(audin->log, WLOG_ERROR, + "audin_set_device_name failed with error %" PRIu32 "!", error); + return FALSE; + } + } + CommandLineSwitchCase(arg, "format") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val > UINT16_MAX)) + return FALSE; + + audin->fixed_format->wFormatTag = (UINT16)val; + } + CommandLineSwitchCase(arg, "rate") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val == 0) || (val > UINT32_MAX)) + return FALSE; + + audin->fixed_format->nSamplesPerSec = (UINT32)val; + } + CommandLineSwitchCase(arg, "channel") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val <= UINT16_MAX)) + audin->fixed_format->nChannels = (UINT16)val; + } + CommandLineSwitchDefault(arg) + { + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + struct SubsystemEntry + { + char* subsystem; + char* device; + }; + UINT error = CHANNEL_RC_INITIALIZATION_ERROR; + struct SubsystemEntry entries[] = + { +#if defined(WITH_PULSE) + { "pulse", "" }, +#endif +#if defined(WITH_OSS) + { "oss", "default" }, +#endif +#if defined(WITH_ALSA) + { "alsa", "default" }, +#endif +#if defined(WITH_OPENSLES) + { "opensles", "default" }, +#endif +#if defined(WITH_WINMM) + { "winmm", "default" }, +#endif +#if defined(WITH_MACAUDIO) + { "mac", "default" }, +#endif +#if defined(WITH_IOSAUDIO) + { "ios", "default" }, +#endif +#if defined(WITH_SNDIO) + { "sndio", "default" }, +#endif + { NULL, NULL } + }; + struct SubsystemEntry* entry = &entries[0]; + WINPR_ASSERT(pEntryPoints); + WINPR_ASSERT(pEntryPoints->GetPlugin); + AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, AUDIN_CHANNEL_NAME); + + if (audin != NULL) + return CHANNEL_RC_ALREADY_INITIALIZED; + + audin = (AUDIN_PLUGIN*)calloc(1, sizeof(AUDIN_PLUGIN)); + + if (!audin) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + audin->log = WLog_Get(TAG); + audin->data = Stream_New(NULL, 4096); + audin->fixed_format = audio_format_new(); + + if (!audin->fixed_format) + goto out; + + if (!audin->data) + goto out; + + audin->dsp_context = freerdp_dsp_context_new(TRUE); + + if (!audin->dsp_context) + goto out; + + audin->attached = TRUE; + audin->iface.Initialize = audin_plugin_initialize; + audin->iface.Connected = NULL; + audin->iface.Disconnected = NULL; + audin->iface.Terminated = audin_plugin_terminated; + audin->iface.Attached = audin_plugin_attached; + audin->iface.Detached = audin_plugin_detached; + + const ADDIN_ARGV* args = pEntryPoints->GetPluginData(pEntryPoints); + audin->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); + + if (args) + { + if (!audin_process_addin_args(audin, args)) + goto out; + } + + if (audin->subsystem) + { + if ((error = audin_load_device_plugin(audin, audin->subsystem, args))) + { + WLog_Print( + audin->log, WLOG_ERROR, + "Unable to load microphone redirection subsystem %s because of error %" PRIu32 "", + audin->subsystem, error); + goto out; + } + } + else + { + while (entry && entry->subsystem && !audin->device) + { + if ((error = audin_set_subsystem(audin, entry->subsystem))) + { + WLog_Print(audin->log, WLOG_ERROR, + "audin_set_subsystem for %s failed with error %" PRIu32 "!", + entry->subsystem, error); + } + else if ((error = audin_set_device_name(audin, entry->device))) + { + WLog_Print(audin->log, WLOG_ERROR, + "audin_set_device_name for %s failed with error %" PRIu32 "!", + entry->subsystem, error); + } + else if ((error = audin_load_device_plugin(audin, audin->subsystem, args))) + { + WLog_Print(audin->log, WLOG_ERROR, + "audin_load_device_plugin %s failed with error %" PRIu32 "!", + entry->subsystem, error); + } + + entry++; + } + } + + if (audin->device == NULL) + { + /* If we have no audin device do not register plugin but still return OK or the client will + * just disconnect due to a missing microphone. */ + WLog_Print(audin->log, WLOG_ERROR, "No microphone device could be found."); + error = CHANNEL_RC_OK; + goto out; + } + + error = pEntryPoints->RegisterPlugin(pEntryPoints, AUDIN_CHANNEL_NAME, &audin->iface); + if (error == CHANNEL_RC_OK) + return error; + +out: + audin_plugin_terminated(&audin->iface); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.h new file mode 100644 index 0000000000000000000000000000000000000000..1e6a49849d908b2a8164eed359b697109982b39c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/audin_main.h @@ -0,0 +1,33 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AUDIN_CLIENT_MAIN_H +#define FREERDP_CHANNEL_AUDIN_CLIENT_MAIN_H + +#include + +#include +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("audin.client") + +#endif /* FREERDP_CHANNEL_AUDIN_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..51228759a000566bbd0b6e38d436bec80d568ff1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/CMakeLists.txt @@ -0,0 +1,31 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Armin Novak +# Copyright (c) 2015 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "ios" "") +find_library(CORE_AUDIO CoreAudio) +find_library(AVFOUNDATION AVFoundation) +find_library(AUDIO_TOOL AudioToolbox) + +set(${MODULE_PREFIX}_SRCS audin_ios.m) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${AVFOUNDATION} ${CORE_AUDIO} ${AUDIO_TOOL}) + +include_directories(..) +include_directories(SYSTEM ${MAC_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/audin_ios.m b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/audin_ios.m new file mode 100644 index 0000000000000000000000000000000000000000..30819858e8cfd787f175df62d9d8a6288bb583a1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/ios/audin_ios.m @@ -0,0 +1,335 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - iOS implementation + * + * Copyright (c) 2015 Armin Novak + * Copyright 2015 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#import + +#define __COREFOUNDATION_CFPLUGINCOM__ 1 +#define IUNKNOWN_C_GUTS \ + void *_reserved; \ + void *QueryInterface; \ + void *AddRef; \ + void *Release + +#include +#include +#include + +#include +#include + +#include "audin_main.h" + +#define IOS_AUDIO_QUEUE_NUM_BUFFERS 100 + +typedef struct +{ + IAudinDevice iface; + + AUDIO_FORMAT format; + UINT32 FramesPerPacket; + int dev_unit; + + AudinReceive receive; + void *user_data; + + rdpContext *rdpcontext; + + bool isOpen; + AudioQueueRef audioQueue; + AudioStreamBasicDescription audioFormat; + AudioQueueBufferRef audioBuffers[IOS_AUDIO_QUEUE_NUM_BUFFERS]; +} AudinIosDevice; + +static AudioFormatID audin_ios_get_format(const AUDIO_FORMAT *format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + return kAudioFormatLinearPCM; + + default: + return 0; + } +} + +static AudioFormatFlags audin_ios_get_flags_for_format(const AUDIO_FORMAT *format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + return kAudioFormatFlagIsSignedInteger; + + default: + return 0; + } +} + +static BOOL audin_ios_format_supported(IAudinDevice *device, const AUDIO_FORMAT *format) +{ + AudinIosDevice *ios = (AudinIosDevice *)device; + AudioFormatID req_fmt = 0; + + if (device == NULL || format == NULL) + return FALSE; + + req_fmt = audin_ios_get_format(format); + + if (req_fmt == 0) + return FALSE; + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_ios_set_format(IAudinDevice *device, const AUDIO_FORMAT *format, + UINT32 FramesPerPacket) +{ + AudinIosDevice *ios = (AudinIosDevice *)device; + + if (device == NULL || format == NULL) + return ERROR_INVALID_PARAMETER; + + ios->FramesPerPacket = FramesPerPacket; + ios->format = *format; + WLog_INFO(TAG, "Audio Format %s [channels=%d, samples=%d, bits=%d]", + audio_format_get_tag_string(format->wFormatTag), format->nChannels, + format->nSamplesPerSec, format->wBitsPerSample); + ios->audioFormat.mBitsPerChannel = format->wBitsPerSample; + + if (format->wBitsPerSample == 0) + ios->audioFormat.mBitsPerChannel = 16; + + ios->audioFormat.mChannelsPerFrame = ios->format.nChannels; + ios->audioFormat.mFramesPerPacket = 1; + + ios->audioFormat.mBytesPerFrame = + ios->audioFormat.mChannelsPerFrame * (ios->audioFormat.mBitsPerChannel / 8); + ios->audioFormat.mBytesPerPacket = + ios->audioFormat.mBytesPerFrame * ios->audioFormat.mFramesPerPacket; + + ios->audioFormat.mFormatFlags = audin_ios_get_flags_for_format(format); + ios->audioFormat.mFormatID = audin_ios_get_format(format); + ios->audioFormat.mReserved = 0; + ios->audioFormat.mSampleRate = ios->format.nSamplesPerSec; + return CHANNEL_RC_OK; +} + +static void ios_audio_queue_input_cb(void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, + const AudioTimeStamp *inStartTime, UInt32 inNumPackets, + const AudioStreamPacketDescription *inPacketDesc) +{ + AudinIosDevice *ios = (AudinIosDevice *)aqData; + UINT error = CHANNEL_RC_OK; + const BYTE *buffer = inBuffer->mAudioData; + int buffer_size = inBuffer->mAudioDataByteSize; + (void)inAQ; + (void)inStartTime; + (void)inNumPackets; + (void)inPacketDesc; + + if (buffer_size > 0) + error = ios->receive(&ios->format, buffer, buffer_size, ios->user_data); + + AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL); + + if (error) + { + WLog_ERR(TAG, "ios->receive failed with error %" PRIu32 "", error); + SetLastError(ERROR_INTERNAL_ERROR); + } +} + +static UINT audin_ios_close(IAudinDevice *device) +{ + UINT errCode = CHANNEL_RC_OK; + char errString[1024]; + OSStatus devStat; + AudinIosDevice *ios = (AudinIosDevice *)device; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if (ios->isOpen) + { + devStat = AudioQueueStop(ios->audioQueue, true); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueStop failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + } + + ios->isOpen = false; + } + + if (ios->audioQueue) + { + devStat = AudioQueueDispose(ios->audioQueue, true); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueDispose failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + } + + ios->audioQueue = NULL; + } + + ios->receive = NULL; + ios->user_data = NULL; + return errCode; +} + +static UINT audin_ios_open(IAudinDevice *device, AudinReceive receive, void *user_data) +{ + AudinIosDevice *ios = (AudinIosDevice *)device; + DWORD errCode; + char errString[1024]; + OSStatus devStat; + + ios->receive = receive; + ios->user_data = user_data; + devStat = AudioQueueNewInput(&(ios->audioFormat), ios_audio_queue_input_cb, ios, NULL, + kCFRunLoopCommonModes, 0, &(ios->audioQueue)); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueNewInput failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + for (size_t index = 0; index < IOS_AUDIO_QUEUE_NUM_BUFFERS; index++) + { + devStat = AudioQueueAllocateBuffer(ios->audioQueue, + ios->FramesPerPacket * 2 * ios->format.nChannels, + &ios->audioBuffers[index]); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueAllocateBuffer failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + devStat = AudioQueueEnqueueBuffer(ios->audioQueue, ios->audioBuffers[index], 0, NULL); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueEnqueueBuffer failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + } + + devStat = AudioQueueStart(ios->audioQueue, NULL); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueStart failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + ios->isOpen = true; + return CHANNEL_RC_OK; +err_out: + audin_ios_close(device); + return CHANNEL_RC_INITIALIZATION_ERROR; +} + +static UINT audin_ios_free(IAudinDevice *device) +{ + AudinIosDevice *ios = (AudinIosDevice *)device; + int error; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if ((error = audin_ios_close(device))) + { + WLog_ERR(TAG, "audin_oss_close failed with error code %d!", error); + } + + free(ios); + return CHANNEL_RC_OK; +} + +FREERDP_ENTRY_POINT(UINT VCAPITYPE ios_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + DWORD errCode; + char errString[1024]; + const ADDIN_ARGV *args; + AudinIosDevice *ios; + UINT error; + ios = (AudinIosDevice *)calloc(1, sizeof(AudinIosDevice)); + + if (!ios) + { + errCode = GetLastError(); + WLog_ERR(TAG, "calloc failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + return CHANNEL_RC_NO_MEMORY; + } + + ios->iface.Open = audin_ios_open; + ios->iface.FormatSupported = audin_ios_format_supported; + ios->iface.SetFormat = audin_ios_set_format; + ios->iface.Close = audin_ios_close; + ios->iface.Free = audin_ios_free; + ios->rdpcontext = pEntryPoints->rdpcontext; + ios->dev_unit = -1; + args = pEntryPoints->args; + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice *)ios))) + { + WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "!", error); + goto error_out; + } + + return CHANNEL_RC_OK; +error_out: + free(ios); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a496f80de76e9eb1af421554839e0119e0fdbf3e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/CMakeLists.txt @@ -0,0 +1,32 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Armin Novak +# Copyright (c) 2015 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "mac" "") +find_library(CORE_AUDIO CoreAudio) +find_library(AVFOUNDATION AVFoundation) +find_library(AUDIO_TOOL AudioToolbox) +find_library(APP_SERVICES ApplicationServices) + +set(${MODULE_PREFIX}_SRCS audin_mac.m) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${AVFOUNDATION} ${CORE_AUDIO} ${AUDIO_TOOL} ${APP_SERVICES}) + +include_directories(..) +include_directories(SYSTEM ${MAC_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/audin_mac.m b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/audin_mac.m new file mode 100644 index 0000000000000000000000000000000000000000..346d8594524c9a585b978020d7acc6956379214e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/mac/audin_mac.m @@ -0,0 +1,463 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - Mac OS X implementation + * + * Copyright (c) 2015 Armin Novak + * Copyright 2015 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#import + +#define __COREFOUNDATION_CFPLUGINCOM__ 1 +#define IUNKNOWN_C_GUTS \ + void *_reserved; \ + void *QueryInterface; \ + void *AddRef; \ + void *Release + +#include +#include +#include +#include + +#include +#include + +#include "audin_main.h" + +#define MAC_AUDIO_QUEUE_NUM_BUFFERS 100 + +/* Fix for #4462: Provide type alias if not declared (Mac OS < 10.10) + * https://developer.apple.com/documentation/coreaudio/audioformatid + */ +#ifndef AudioFormatID +typedef UInt32 AudioFormatID; +#endif + +#ifndef AudioFormatFlags +typedef UInt32 AudioFormatFlags; +#endif + +typedef struct +{ + IAudinDevice iface; + + AUDIO_FORMAT format; + UINT32 FramesPerPacket; + int dev_unit; + + AudinReceive receive; + void *user_data; + + rdpContext *rdpcontext; + + bool isAuthorized; + bool isOpen; + AudioQueueRef audioQueue; + AudioStreamBasicDescription audioFormat; + AudioQueueBufferRef audioBuffers[MAC_AUDIO_QUEUE_NUM_BUFFERS]; +} AudinMacDevice; + +static AudioFormatID audin_mac_get_format(const AUDIO_FORMAT *format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + return kAudioFormatLinearPCM; + + default: + return 0; + } +} + +static AudioFormatFlags audin_mac_get_flags_for_format(const AUDIO_FORMAT *format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + return kAudioFormatFlagIsSignedInteger; + + default: + return 0; + } +} + +static BOOL audin_mac_format_supported(IAudinDevice *device, const AUDIO_FORMAT *format) +{ + AudinMacDevice *mac = (AudinMacDevice *)device; + AudioFormatID req_fmt = 0; + + if (!mac->isAuthorized) + return FALSE; + + if (device == NULL || format == NULL) + return FALSE; + + if (format->nChannels != 2) + return FALSE; + + req_fmt = audin_mac_get_format(format); + + if (req_fmt == 0) + return FALSE; + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_mac_set_format(IAudinDevice *device, const AUDIO_FORMAT *format, + UINT32 FramesPerPacket) +{ + AudinMacDevice *mac = (AudinMacDevice *)device; + + if (!mac->isAuthorized) + return ERROR_INTERNAL_ERROR; + + if (device == NULL || format == NULL) + return ERROR_INVALID_PARAMETER; + + mac->FramesPerPacket = FramesPerPacket; + mac->format = *format; + WLog_INFO(TAG, "Audio Format %s [channels=%d, samples=%d, bits=%d]", + audio_format_get_tag_string(format->wFormatTag), format->nChannels, + format->nSamplesPerSec, format->wBitsPerSample); + mac->audioFormat.mBitsPerChannel = format->wBitsPerSample; + + if (format->wBitsPerSample == 0) + mac->audioFormat.mBitsPerChannel = 16; + + mac->audioFormat.mChannelsPerFrame = mac->format.nChannels; + mac->audioFormat.mFramesPerPacket = 1; + + mac->audioFormat.mBytesPerFrame = + mac->audioFormat.mChannelsPerFrame * (mac->audioFormat.mBitsPerChannel / 8); + mac->audioFormat.mBytesPerPacket = + mac->audioFormat.mBytesPerFrame * mac->audioFormat.mFramesPerPacket; + + mac->audioFormat.mFormatFlags = audin_mac_get_flags_for_format(format); + mac->audioFormat.mFormatID = audin_mac_get_format(format); + mac->audioFormat.mReserved = 0; + mac->audioFormat.mSampleRate = mac->format.nSamplesPerSec; + return CHANNEL_RC_OK; +} + +static void mac_audio_queue_input_cb(void *aqData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, + const AudioTimeStamp *inStartTime, UInt32 inNumPackets, + const AudioStreamPacketDescription *inPacketDesc) +{ + AudinMacDevice *mac = (AudinMacDevice *)aqData; + UINT error = CHANNEL_RC_OK; + const BYTE *buffer = inBuffer->mAudioData; + int buffer_size = inBuffer->mAudioDataByteSize; + (void)inAQ; + (void)inStartTime; + (void)inNumPackets; + (void)inPacketDesc; + + if (buffer_size > 0) + error = mac->receive(&mac->format, buffer, buffer_size, mac->user_data); + + AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL); + + if (error) + { + WLog_ERR(TAG, "mac->receive failed with error %" PRIu32 "", error); + SetLastError(ERROR_INTERNAL_ERROR); + } +} + +static UINT audin_mac_close(IAudinDevice *device) +{ + UINT errCode = CHANNEL_RC_OK; + char errString[1024]; + OSStatus devStat; + AudinMacDevice *mac = (AudinMacDevice *)device; + + if (!mac->isAuthorized) + return ERROR_INTERNAL_ERROR; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if (mac->isOpen) + { + devStat = AudioQueueStop(mac->audioQueue, true); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueStop failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + } + + mac->isOpen = false; + } + + if (mac->audioQueue) + { + devStat = AudioQueueDispose(mac->audioQueue, true); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueDispose failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + } + + mac->audioQueue = NULL; + } + + mac->receive = NULL; + mac->user_data = NULL; + return errCode; +} + +static UINT audin_mac_open(IAudinDevice *device, AudinReceive receive, void *user_data) +{ + AudinMacDevice *mac = (AudinMacDevice *)device; + DWORD errCode; + char errString[1024]; + OSStatus devStat; + + if (!mac->isAuthorized) + return ERROR_INTERNAL_ERROR; + + mac->receive = receive; + mac->user_data = user_data; + devStat = AudioQueueNewInput(&(mac->audioFormat), mac_audio_queue_input_cb, mac, NULL, + kCFRunLoopCommonModes, 0, &(mac->audioQueue)); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueNewInput failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + for (size_t index = 0; index < MAC_AUDIO_QUEUE_NUM_BUFFERS; index++) + { + devStat = AudioQueueAllocateBuffer(mac->audioQueue, + mac->FramesPerPacket * 2 * mac->format.nChannels, + &mac->audioBuffers[index]); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueAllocateBuffer failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + devStat = AudioQueueEnqueueBuffer(mac->audioQueue, mac->audioBuffers[index], 0, NULL); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueEnqueueBuffer failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + } + + devStat = AudioQueueStart(mac->audioQueue, NULL); + + if (devStat != 0) + { + errCode = GetLastError(); + WLog_ERR(TAG, "AudioQueueStart failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + goto err_out; + } + + mac->isOpen = true; + return CHANNEL_RC_OK; +err_out: + audin_mac_close(device); + return CHANNEL_RC_INITIALIZATION_ERROR; +} + +static UINT audin_mac_free(IAudinDevice *device) +{ + AudinMacDevice *mac = (AudinMacDevice *)device; + int error; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if ((error = audin_mac_close(device))) + { + WLog_ERR(TAG, "audin_oss_close failed with error code %d!", error); + } + + free(mac); + return CHANNEL_RC_OK; +} + +static UINT audin_mac_parse_addin_args(AudinMacDevice *device, const ADDIN_ARGV *args) +{ + DWORD errCode; + char errString[1024]; + int status; + char *str_num, *eptr; + DWORD flags; + const COMMAND_LINE_ARGUMENT_A *arg; + COMMAND_LINE_ARGUMENT_A audin_mac_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "audio device name" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + + AudinMacDevice *mac = (AudinMacDevice *)device; + + if (args->argc == 1) + return CHANNEL_RC_OK; + + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = + CommandLineParseArgumentsA(args->argc, args->argv, audin_mac_args, flags, mac, NULL, NULL); + + if (status < 0) + return ERROR_INVALID_PARAMETER; + + arg = audin_mac_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + str_num = _strdup(arg->Value); + + if (!str_num) + { + errCode = GetLastError(); + WLog_ERR(TAG, "_strdup failed with %s [%d]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + return CHANNEL_RC_NO_MEMORY; + } + + mac->dev_unit = strtol(str_num, &eptr, 10); + + if (mac->dev_unit < 0 || *eptr != '\0') + mac->dev_unit = -1; + + free(str_num); + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +FREERDP_ENTRY_POINT(UINT VCAPITYPE mac_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + DWORD errCode; + char errString[1024]; + const ADDIN_ARGV *args; + AudinMacDevice *mac; + UINT error; + mac = (AudinMacDevice *)calloc(1, sizeof(AudinMacDevice)); + + if (!mac) + { + errCode = GetLastError(); + WLog_ERR(TAG, "calloc failed with %s [%" PRIu32 "]", + winpr_strerror(errCode, errString, sizeof(errString)), errCode); + return CHANNEL_RC_NO_MEMORY; + } + + mac->iface.Open = audin_mac_open; + mac->iface.FormatSupported = audin_mac_format_supported; + mac->iface.SetFormat = audin_mac_set_format; + mac->iface.Close = audin_mac_close; + mac->iface.Free = audin_mac_free; + mac->rdpcontext = pEntryPoints->rdpcontext; + mac->dev_unit = -1; + args = pEntryPoints->args; + + if ((error = audin_mac_parse_addin_args(mac, args))) + { + WLog_ERR(TAG, "audin_mac_parse_addin_args failed with %" PRIu32 "!", error); + goto error_out; + } + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice *)mac))) + { + WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "!", error); + goto error_out; + } + +#if defined(MAC_OS_X_VERSION_10_14) + if (@available(macOS 10.14, *)) + { + @autoreleasepool + { + AVAuthorizationStatus status = + [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]; + switch (status) + { + case AVAuthorizationStatusAuthorized: + mac->isAuthorized = TRUE; + break; + case AVAuthorizationStatusNotDetermined: + [AVCaptureDevice + requestAccessForMediaType:AVMediaTypeAudio + completionHandler:^(BOOL granted) { + if (granted == YES) + { + mac->isAuthorized = TRUE; + } + else + WLog_WARN(TAG, "Microphone access denied by user"); + }]; + break; + case AVAuthorizationStatusRestricted: + WLog_WARN(TAG, "Microphone access restricted by policy"); + break; + case AVAuthorizationStatusDenied: + WLog_WARN(TAG, "Microphone access denied by policy"); + break; + default: + break; + } + } + } +#endif + + return CHANNEL_RC_OK; +error_out: + free(mac); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2174996fd718427562f7bbbce10973a1cc603ca6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2013 Armin Novak +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "opensles" "") + +find_package(OpenSLES REQUIRED) + +set(${MODULE_PREFIX}_SRCS opensl_io.c audin_opensl_es.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${OpenSLES_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${OpenSLES_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/audin_opensl_es.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/audin_opensl_es.c new file mode 100644 index 0000000000000000000000000000000000000000..9885b033a80b6990102aa47cb6e3e2195e0ccddb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/audin_opensl_es.c @@ -0,0 +1,336 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - OpenSL ES implementation + * + * Copyright 2013 Armin Novak + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include "audin_main.h" +#include "opensl_io.h" + +typedef struct +{ + IAudinDevice iface; + + char* device_name; + OPENSL_STREAM* stream; + + AUDIO_FORMAT format; + UINT32 frames_per_packet; + + UINT32 bytes_per_channel; + + AudinReceive receive; + + void* user_data; + + rdpContext* rdpcontext; + wLog* log; +} AudinOpenSLESDevice; + +static UINT audin_opensles_close(IAudinDevice* device); + +static void audin_receive(void* context, const void* data, size_t size) +{ + UINT error; + AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)context; + + if (!opensles || !data) + { + WLog_ERR(TAG, "Invalid arguments context=%p, data=%p", opensles, data); + return; + } + + error = opensles->receive(&opensles->format, data, size, opensles->user_data); + + if (error && opensles->rdpcontext) + setChannelError(opensles->rdpcontext, error, "audin_receive reported an error"); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_opensles_free(IAudinDevice* device) +{ + AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device; + + if (!opensles) + return ERROR_INVALID_PARAMETER; + + WLog_Print(opensles->log, WLOG_DEBUG, "device=%p", (void*)device); + + free(opensles->device_name); + free(opensles); + return CHANNEL_RC_OK; +} + +static BOOL audin_opensles_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format) +{ + AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device; + + if (!opensles || !format) + return FALSE; + + WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p", (void*)opensles, (void*)format); + WINPR_ASSERT(format); + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: /* PCM */ + if (format->cbSize == 0 && (format->nSamplesPerSec <= 48000) && + (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) && + (format->nChannels >= 1 && format->nChannels <= 2)) + { + return TRUE; + } + + break; + + default: + WLog_Print(opensles->log, WLOG_DEBUG, "Encoding '%s' [0x%04" PRIX16 "] not supported", + audio_format_get_tag_string(format->wFormatTag), format->wFormatTag); + break; + } + + return FALSE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_opensles_set_format(IAudinDevice* device, const AUDIO_FORMAT* format, + UINT32 FramesPerPacket) +{ + AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device; + + if (!opensles || !format) + return ERROR_INVALID_PARAMETER; + + WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, format=%p, FramesPerPacket=%" PRIu32 "", + (void*)device, (void*)format, FramesPerPacket); + WINPR_ASSERT(format); + + opensles->format = *format; + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + opensles->frames_per_packet = FramesPerPacket; + + switch (format->wBitsPerSample) + { + case 4: + opensles->bytes_per_channel = 1; + break; + + case 8: + opensles->bytes_per_channel = 1; + break; + + case 16: + opensles->bytes_per_channel = 2; + break; + + default: + return ERROR_UNSUPPORTED_TYPE; + } + + break; + + default: + WLog_Print(opensles->log, WLOG_ERROR, + "Encoding '%" PRIu16 "' [%04" PRIX16 "] not supported", format->wFormatTag, + format->wFormatTag); + return ERROR_UNSUPPORTED_TYPE; + } + + WLog_Print(opensles->log, WLOG_DEBUG, "frames_per_packet=%" PRIu32, + opensles->frames_per_packet); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_opensles_open(IAudinDevice* device, AudinReceive receive, void* user_data) +{ + AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device; + + if (!opensles || !receive || !user_data) + return ERROR_INVALID_PARAMETER; + + WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, receive=%p, user_data=%p", (void*)device, + (void*)receive, (void*)user_data); + + if (opensles->stream) + goto error_out; + + if (!(opensles->stream = android_OpenRecDevice( + opensles, audin_receive, opensles->format.nSamplesPerSec, opensles->format.nChannels, + opensles->frames_per_packet, opensles->format.wBitsPerSample))) + { + WLog_Print(opensles->log, WLOG_ERROR, "android_OpenRecDevice failed!"); + goto error_out; + } + + opensles->receive = receive; + opensles->user_data = user_data; + return CHANNEL_RC_OK; +error_out: + audin_opensles_close(device); + return ERROR_INTERNAL_ERROR; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT audin_opensles_close(IAudinDevice* device) +{ + AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device; + + if (!opensles) + return ERROR_INVALID_PARAMETER; + + WLog_Print(opensles->log, WLOG_DEBUG, "device=%p", (void*)device); + android_CloseRecDevice(opensles->stream); + opensles->receive = NULL; + opensles->user_data = NULL; + opensles->stream = NULL; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_opensles_parse_addin_args(AudinOpenSLESDevice* device, const ADDIN_ARGV* args) +{ + UINT status; + DWORD flags; + const COMMAND_LINE_ARGUMENT_A* arg; + AudinOpenSLESDevice* opensles = (AudinOpenSLESDevice*)device; + COMMAND_LINE_ARGUMENT_A audin_opensles_args[] = { + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, + "audio device name" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } + }; + + WLog_Print(opensles->log, WLOG_DEBUG, "device=%p, args=%p", (void*)device, (void*)args); + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, args->argv, audin_opensles_args, flags, + opensles, NULL, NULL); + + if (status < 0) + return status; + + arg = audin_opensles_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + opensles->device_name = _strdup(arg->Value); + + if (!opensles->device_name) + { + WLog_Print(opensles->log, WLOG_ERROR, "_strdup failed!"); + return CHANNEL_RC_NO_MEMORY; + } + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE opensles_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args; + AudinOpenSLESDevice* opensles; + UINT error; + opensles = (AudinOpenSLESDevice*)calloc(1, sizeof(AudinOpenSLESDevice)); + + if (!opensles) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + opensles->log = WLog_Get(TAG); + opensles->iface.Open = audin_opensles_open; + opensles->iface.FormatSupported = audin_opensles_format_supported; + opensles->iface.SetFormat = audin_opensles_set_format; + opensles->iface.Close = audin_opensles_close; + opensles->iface.Free = audin_opensles_free; + opensles->rdpcontext = pEntryPoints->rdpcontext; + args = pEntryPoints->args; + + if ((error = audin_opensles_parse_addin_args(opensles, args))) + { + WLog_Print(opensles->log, WLOG_ERROR, + "audin_opensles_parse_addin_args failed with errorcode %" PRIu32 "!", error); + goto error_out; + } + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)opensles))) + { + WLog_Print(opensles->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!", + error); + goto error_out; + } + + return CHANNEL_RC_OK; +error_out: + free(opensles); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.c new file mode 100644 index 0000000000000000000000000000000000000000..39b3dc848330d7926664a4f2a00a077dc42e621e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.c @@ -0,0 +1,388 @@ +/* +opensl_io.c: +Android OpenSL input/output module +Copyright (c) 2012, Victor Lazzarini +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#include "audin_main.h" +#include "opensl_io.h" +#define CONV16BIT 32768 +#define CONVMYFLT (1. / 32768.) + +typedef struct +{ + size_t size; + void* data; +} queue_element; + +struct opensl_stream +{ + // engine interfaces + SLObjectItf engineObject; + SLEngineItf engineEngine; + + // device interfaces + SLDeviceVolumeItf deviceVolume; + + // recorder interfaces + SLObjectItf recorderObject; + SLRecordItf recorderRecord; + SLAndroidSimpleBufferQueueItf recorderBufferQueue; + + unsigned int inchannels; + unsigned int sr; + unsigned int buffersize; + unsigned int bits_per_sample; + + queue_element* prep; + queue_element* next; + + void* context; + opensl_receive_t receive; +}; + +static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context); + +// creates the OpenSL ES audio engine +static SLresult openSLCreateEngine(OPENSL_STREAM* p) +{ + SLresult result; + // create engine + result = slCreateEngine(&(p->engineObject), 0, NULL, 0, NULL, NULL); + + if (result != SL_RESULT_SUCCESS) + goto engine_end; + + // realize the engine + result = (*p->engineObject)->Realize(p->engineObject, SL_BOOLEAN_FALSE); + + if (result != SL_RESULT_SUCCESS) + goto engine_end; + + // get the engine interface, which is needed in order to create other objects + result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE, &(p->engineEngine)); + + if (result != SL_RESULT_SUCCESS) + goto engine_end; + + // get the volume interface - important, this is optional! + result = + (*p->engineObject)->GetInterface(p->engineObject, SL_IID_DEVICEVOLUME, &(p->deviceVolume)); + + if (result != SL_RESULT_SUCCESS) + { + p->deviceVolume = NULL; + result = SL_RESULT_SUCCESS; + } + +engine_end: + WINPR_ASSERT(SL_RESULT_SUCCESS == result); + return result; +} + +// Open the OpenSL ES device for input +static SLresult openSLRecOpen(OPENSL_STREAM* p) +{ + SLresult result; + SLuint32 sr = p->sr; + SLuint32 channels = p->inchannels; + WINPR_ASSERT(!p->recorderObject); + + if (channels) + { + switch (sr) + { + case 8000: + sr = SL_SAMPLINGRATE_8; + break; + + case 11025: + sr = SL_SAMPLINGRATE_11_025; + break; + + case 16000: + sr = SL_SAMPLINGRATE_16; + break; + + case 22050: + sr = SL_SAMPLINGRATE_22_05; + break; + + case 24000: + sr = SL_SAMPLINGRATE_24; + break; + + case 32000: + sr = SL_SAMPLINGRATE_32; + break; + + case 44100: + sr = SL_SAMPLINGRATE_44_1; + break; + + case 48000: + sr = SL_SAMPLINGRATE_48; + break; + + case 64000: + sr = SL_SAMPLINGRATE_64; + break; + + case 88200: + sr = SL_SAMPLINGRATE_88_2; + break; + + case 96000: + sr = SL_SAMPLINGRATE_96; + break; + + case 192000: + sr = SL_SAMPLINGRATE_192; + break; + + default: + return -1; + } + + // configure audio source + SLDataLocator_IODevice loc_dev = { SL_DATALOCATOR_IODEVICE, SL_IODEVICE_AUDIOINPUT, + SL_DEFAULTDEVICEID_AUDIOINPUT, NULL }; + SLDataSource audioSrc = { &loc_dev, NULL }; + // configure audio sink + int speakers; + + if (channels > 1) + speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; + else + speakers = SL_SPEAKER_FRONT_CENTER; + + SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, + 2 }; + SLDataFormat_PCM format_pcm; + format_pcm.formatType = SL_DATAFORMAT_PCM; + format_pcm.numChannels = channels; + format_pcm.samplesPerSec = sr; + format_pcm.channelMask = speakers; + format_pcm.endianness = SL_BYTEORDER_LITTLEENDIAN; + + if (16 == p->bits_per_sample) + { + format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; + format_pcm.containerSize = 16; + } + else if (8 == p->bits_per_sample) + { + format_pcm.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_8; + format_pcm.containerSize = 8; + } + else + WINPR_ASSERT(0); + + SLDataSink audioSnk = { &loc_bq, &format_pcm }; + // create audio recorder + // (requires the RECORD_AUDIO permission) + const SLInterfaceID id[] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE }; + const SLboolean req[] = { SL_BOOLEAN_TRUE }; + result = (*p->engineEngine) + ->CreateAudioRecorder(p->engineEngine, &(p->recorderObject), &audioSrc, + &audioSnk, 1, id, req); + WINPR_ASSERT(!result); + + if (SL_RESULT_SUCCESS != result) + goto end_recopen; + + // realize the audio recorder + result = (*p->recorderObject)->Realize(p->recorderObject, SL_BOOLEAN_FALSE); + WINPR_ASSERT(!result); + + if (SL_RESULT_SUCCESS != result) + goto end_recopen; + + // get the record interface + result = (*p->recorderObject) + ->GetInterface(p->recorderObject, SL_IID_RECORD, &(p->recorderRecord)); + WINPR_ASSERT(!result); + + if (SL_RESULT_SUCCESS != result) + goto end_recopen; + + // get the buffer queue interface + result = (*p->recorderObject) + ->GetInterface(p->recorderObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, + &(p->recorderBufferQueue)); + WINPR_ASSERT(!result); + + if (SL_RESULT_SUCCESS != result) + goto end_recopen; + + // register callback on the buffer queue + result = (*p->recorderBufferQueue) + ->RegisterCallback(p->recorderBufferQueue, bqRecorderCallback, p); + WINPR_ASSERT(!result); + + if (SL_RESULT_SUCCESS != result) + goto end_recopen; + + end_recopen: + return result; + } + else + return SL_RESULT_SUCCESS; +} + +// close the OpenSL IO and destroy the audio engine +static void openSLDestroyEngine(OPENSL_STREAM* p) +{ + // destroy audio recorder object, and invalidate all associated interfaces + if (p->recorderObject != NULL) + { + (*p->recorderObject)->Destroy(p->recorderObject); + p->recorderObject = NULL; + p->recorderRecord = NULL; + p->recorderBufferQueue = NULL; + } + + // destroy engine object, and invalidate all associated interfaces + if (p->engineObject != NULL) + { + (*p->engineObject)->Destroy(p->engineObject); + p->engineObject = NULL; + p->engineEngine = NULL; + } +} + +static queue_element* opensles_queue_element_new(size_t size) +{ + queue_element* q = calloc(1, sizeof(queue_element)); + + if (!q) + goto fail; + + q->size = size; + q->data = malloc(size); + + if (!q->data) + goto fail; + + return q; +fail: + free(q); + return NULL; +} + +static void opensles_queue_element_free(void* obj) +{ + queue_element* e = (queue_element*)obj; + + if (e) + free(e->data); + + free(e); +} + +// open the android audio device for input +OPENSL_STREAM* android_OpenRecDevice(void* context, opensl_receive_t receive, int sr, + int inchannels, int bufferframes, int bits_per_sample) +{ + OPENSL_STREAM* p; + + if (!context || !receive) + return NULL; + + p = (OPENSL_STREAM*)calloc(1, sizeof(OPENSL_STREAM)); + + if (!p) + return NULL; + + p->context = context; + p->receive = receive; + p->inchannels = inchannels; + p->sr = sr; + p->buffersize = bufferframes; + p->bits_per_sample = bits_per_sample; + + if ((p->bits_per_sample != 8) && (p->bits_per_sample != 16)) + goto fail; + + if (openSLCreateEngine(p) != SL_RESULT_SUCCESS) + goto fail; + + if (openSLRecOpen(p) != SL_RESULT_SUCCESS) + goto fail; + + /* Create receive buffers, prepare them and start recording */ + p->prep = opensles_queue_element_new(p->buffersize * p->bits_per_sample / 8); + p->next = opensles_queue_element_new(p->buffersize * p->bits_per_sample / 8); + + if (!p->prep || !p->next) + goto fail; + + (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, p->next->data, p->next->size); + (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, p->prep->data, p->prep->size); + (*p->recorderRecord)->SetRecordState(p->recorderRecord, SL_RECORDSTATE_RECORDING); + return p; +fail: + android_CloseRecDevice(p); + return NULL; +} + +// close the android audio device +void android_CloseRecDevice(OPENSL_STREAM* p) +{ + if (p == NULL) + return; + + opensles_queue_element_free(p->next); + opensles_queue_element_free(p->prep); + openSLDestroyEngine(p); + free(p); +} + +// this callback handler is called every time a buffer finishes recording +static void bqRecorderCallback(SLAndroidSimpleBufferQueueItf bq, void* context) +{ + OPENSL_STREAM* p = (OPENSL_STREAM*)context; + queue_element* e; + + if (!p) + return; + + e = p->next; + + if (!e) + return; + + if (!p->context || !p->receive) + WLog_WARN(TAG, "Missing receive callback=%p, context=%p", p->receive, p->context); + else + p->receive(p->context, e->data, e->size); + + p->next = p->prep; + p->prep = e; + (*p->recorderBufferQueue)->Enqueue(p->recorderBufferQueue, e->data, e->size); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.h b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.h new file mode 100644 index 0000000000000000000000000000000000000000..e99522cfe96e05ebaececffc5517119a42045e8d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/opensles/opensl_io.h @@ -0,0 +1,65 @@ +/* +opensl_io.c: +Android OpenSL input/output module header +Copyright (c) 2012, Victor Lazzarini +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef FREERDP_CHANNEL_AUDIN_CLIENT_OPENSL_IO_H +#define FREERDP_CHANNEL_AUDIN_CLIENT_OPENSL_IO_H + +#include +#include + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct opensl_stream OPENSL_STREAM; + + typedef void (*opensl_receive_t)(void* context, const void* data, size_t size); + + /* + Open the audio device with a given sampling rate (sr), input and output channels and IO buffer + size in frames. Returns a handle to the OpenSL stream + */ + FREERDP_LOCAL OPENSL_STREAM* android_OpenRecDevice(void* context, opensl_receive_t receive, + int sr, int inchannels, int bufferframes, + int bits_per_sample); + /* + Close the audio device + */ + FREERDP_LOCAL void android_CloseRecDevice(OPENSL_STREAM* p); + +#ifdef __cplusplus +}; +#endif + +#endif /* FREERDP_CHANNEL_AUDIN_CLIENT_OPENSL_IO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3532c6312c08c4b7d89eb32f84ecdf3275cdea77 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/CMakeLists.txt @@ -0,0 +1,31 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Rozhuk Ivan +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "oss" "") + +find_package(OSS REQUIRED) + +set(${MODULE_PREFIX}_SRCS audin_oss.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${OSS_LIBRARIES}) + +include_directories(..) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(SYSTEM ${OSS_INCLUDE_DIRS}) +cleaning_configure_file(${CMAKE_SOURCE_DIR}/cmake/oss-includes.h.in ${CMAKE_CURRENT_BINARY_DIR}/oss-includes.h @ONLY) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/audin_oss.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/audin_oss.c new file mode 100644 index 0000000000000000000000000000000000000000..8b6ad6cc5109268cd1cddd4684b20c0dba200455 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/oss/audin_oss.c @@ -0,0 +1,486 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - OSS implementation + * + * Copyright (c) 2015 Rozhuk Ivan + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "audin_main.h" + +typedef struct +{ + IAudinDevice iface; + + HANDLE thread; + HANDLE stopEvent; + + AUDIO_FORMAT format; + UINT32 FramesPerPacket; + int dev_unit; + + AudinReceive receive; + void* user_data; + + rdpContext* rdpcontext; +} AudinOSSDevice; + +static void OSS_LOG_ERR(const char* _text, int _error) +{ + if ((_error) != 0) + { + char buffer[256] = { 0 }; + WLog_ERR(TAG, "%s: %i - %s\n", (_text), (_error), + winpr_strerror((_error), buffer, sizeof(buffer))); + } +} + +static UINT32 audin_oss_get_format(const AUDIO_FORMAT* format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + switch (format->wBitsPerSample) + { + case 8: + return AFMT_S8; + + case 16: + return AFMT_S16_LE; + + default: + break; + } + + break; + default: + break; + } + + return 0; +} + +static BOOL audin_oss_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format) +{ + if (device == NULL || format == NULL) + return FALSE; + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->cbSize != 0 || format->nSamplesPerSec > 48000 || + (format->wBitsPerSample != 8 && format->wBitsPerSample != 16) || + (format->nChannels != 1 && format->nChannels != 2)) + return FALSE; + + break; + + default: + return FALSE; + } + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_oss_set_format(IAudinDevice* device, const AUDIO_FORMAT* format, + UINT32 FramesPerPacket) +{ + AudinOSSDevice* oss = (AudinOSSDevice*)device; + + if (device == NULL || format == NULL) + return ERROR_INVALID_PARAMETER; + + oss->FramesPerPacket = FramesPerPacket; + oss->format = *format; + return CHANNEL_RC_OK; +} + +static DWORD WINAPI audin_oss_thread_func(LPVOID arg) +{ + char dev_name[PATH_MAX] = "/dev/dsp"; + char mixer_name[PATH_MAX] = "/dev/mixer"; + int pcm_handle = -1; + int mixer_handle = 0; + BYTE* buffer = NULL; + unsigned long tmp = 0; + size_t buffer_size = 0; + AudinOSSDevice* oss = (AudinOSSDevice*)arg; + UINT error = 0; + DWORD status = 0; + + if (oss == NULL) + { + error = ERROR_INVALID_PARAMETER; + goto err_out; + } + + if (oss->dev_unit != -1) + { + (void)sprintf_s(dev_name, (PATH_MAX - 1), "/dev/dsp%i", oss->dev_unit); + (void)sprintf_s(mixer_name, PATH_MAX - 1, "/dev/mixer%i", oss->dev_unit); + } + + WLog_INFO(TAG, "open: %s", dev_name); + + if ((pcm_handle = open(dev_name, O_RDONLY)) < 0) + { + OSS_LOG_ERR("sound dev open failed", errno); + error = ERROR_INTERNAL_ERROR; + goto err_out; + } + + /* Set rec volume to 100%. */ + if ((mixer_handle = open(mixer_name, O_RDWR)) < 0) + { + OSS_LOG_ERR("mixer open failed, not critical", errno); + } + else + { + tmp = (100 | (100 << 8)); + + if (ioctl(mixer_handle, MIXER_WRITE(SOUND_MIXER_MIC), &tmp) == -1) + OSS_LOG_ERR("WRITE_MIXER - SOUND_MIXER_MIC, not critical", errno); + + tmp = (100 | (100 << 8)); + + if (ioctl(mixer_handle, MIXER_WRITE(SOUND_MIXER_RECLEV), &tmp) == -1) + OSS_LOG_ERR("WRITE_MIXER - SOUND_MIXER_RECLEV, not critical", errno); + + close(mixer_handle); + } + +#if 0 /* FreeBSD OSS implementation at this moment (2015.03) does not set PCM_CAP_INPUT flag. */ + tmp = 0; + + if (ioctl(pcm_handle, SNDCTL_DSP_GETCAPS, &tmp) == -1) + { + OSS_LOG_ERR("SNDCTL_DSP_GETCAPS failed, try ignored", errno); + } + else if ((tmp & PCM_CAP_INPUT) == 0) + { + OSS_LOG_ERR("Device does not supports playback", EOPNOTSUPP); + goto err_out; + } + +#endif + /* Set format. */ + tmp = audin_oss_get_format(&oss->format); + + if (ioctl(pcm_handle, SNDCTL_DSP_SETFMT, &tmp) == -1) + OSS_LOG_ERR("SNDCTL_DSP_SETFMT failed", errno); + + tmp = oss->format.nChannels; + + if (ioctl(pcm_handle, SNDCTL_DSP_CHANNELS, &tmp) == -1) + OSS_LOG_ERR("SNDCTL_DSP_CHANNELS failed", errno); + + tmp = oss->format.nSamplesPerSec; + + if (ioctl(pcm_handle, SNDCTL_DSP_SPEED, &tmp) == -1) + OSS_LOG_ERR("SNDCTL_DSP_SPEED failed", errno); + + tmp = oss->format.nBlockAlign; + + if (ioctl(pcm_handle, SNDCTL_DSP_SETFRAGMENT, &tmp) == -1) + OSS_LOG_ERR("SNDCTL_DSP_SETFRAGMENT failed", errno); + + buffer_size = + (1ull * oss->FramesPerPacket * oss->format.nChannels * (oss->format.wBitsPerSample / 8ull)); + buffer = (BYTE*)calloc((buffer_size + sizeof(void*)), sizeof(BYTE)); + + if (NULL == buffer) + { + OSS_LOG_ERR("malloc() fail", errno); + error = ERROR_NOT_ENOUGH_MEMORY; + goto err_out; + } + + while (1) + { + SSIZE_T stmp = -1; + status = WaitForSingleObject(oss->stopEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + goto err_out; + } + + if (status == WAIT_OBJECT_0) + break; + + stmp = read(pcm_handle, buffer, buffer_size); + + /* Error happen. */ + if (stmp < 0) + { + OSS_LOG_ERR("read() error", errno); + continue; + } + + if ((size_t)stmp < buffer_size) /* Not enough data. */ + continue; + + if ((error = oss->receive(&oss->format, buffer, buffer_size, oss->user_data))) + { + WLog_ERR(TAG, "oss->receive failed with error %" PRIu32 "", error); + break; + } + } + +err_out: + + if (error && oss && oss->rdpcontext) + setChannelError(oss->rdpcontext, error, "audin_oss_thread_func reported an error"); + + if (pcm_handle != -1) + { + WLog_INFO(TAG, "close: %s", dev_name); + close(pcm_handle); + } + + free(buffer); + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_oss_open(IAudinDevice* device, AudinReceive receive, void* user_data) +{ + AudinOSSDevice* oss = (AudinOSSDevice*)device; + oss->receive = receive; + oss->user_data = user_data; + + if (!(oss->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (!(oss->thread = CreateThread(NULL, 0, audin_oss_thread_func, oss, 0, NULL))) + { + WLog_ERR(TAG, "CreateThread failed!"); + (void)CloseHandle(oss->stopEvent); + oss->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_oss_close(IAudinDevice* device) +{ + UINT error = 0; + AudinOSSDevice* oss = (AudinOSSDevice*)device; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if (oss->stopEvent != NULL) + { + (void)SetEvent(oss->stopEvent); + + if (WaitForSingleObject(oss->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(oss->stopEvent); + oss->stopEvent = NULL; + (void)CloseHandle(oss->thread); + oss->thread = NULL; + } + + oss->receive = NULL; + oss->user_data = NULL; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_oss_free(IAudinDevice* device) +{ + AudinOSSDevice* oss = (AudinOSSDevice*)device; + UINT error = 0; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if ((error = audin_oss_close(device))) + { + WLog_ERR(TAG, "audin_oss_close failed with error code %" PRIu32 "!", error); + } + + free(oss); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_oss_parse_addin_args(AudinOSSDevice* device, const ADDIN_ARGV* args) +{ + int status = 0; + char* str_num = NULL; + char* eptr = NULL; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + AudinOSSDevice* oss = device; + COMMAND_LINE_ARGUMENT_A audin_oss_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "audio device name" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = + CommandLineParseArgumentsA(args->argc, args->argv, audin_oss_args, flags, oss, NULL, NULL); + + if (status < 0) + return ERROR_INVALID_PARAMETER; + + arg = audin_oss_args; + errno = 0; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + str_num = _strdup(arg->Value); + + if (!str_num) + { + WLog_ERR(TAG, "_strdup failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + { + long val = strtol(str_num, &eptr, 10); + + if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX)) + { + free(str_num); + return CHANNEL_RC_NULL_DATA; + } + + oss->dev_unit = (INT32)val; + } + + if (oss->dev_unit < 0 || *eptr != '\0') + oss->dev_unit = -1; + + free(str_num); + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE oss_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args = NULL; + AudinOSSDevice* oss = NULL; + UINT error = 0; + oss = (AudinOSSDevice*)calloc(1, sizeof(AudinOSSDevice)); + + if (!oss) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + oss->iface.Open = audin_oss_open; + oss->iface.FormatSupported = audin_oss_format_supported; + oss->iface.SetFormat = audin_oss_set_format; + oss->iface.Close = audin_oss_close; + oss->iface.Free = audin_oss_free; + oss->rdpcontext = pEntryPoints->rdpcontext; + oss->dev_unit = -1; + args = pEntryPoints->args; + + if ((error = audin_oss_parse_addin_args(oss, args))) + { + WLog_ERR(TAG, "audin_oss_parse_addin_args failed with errorcode %" PRIu32 "!", error); + goto error_out; + } + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)oss))) + { + WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "!", error); + goto error_out; + } + + return CHANNEL_RC_OK; +error_out: + free(oss); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1cec9fab96332506976cb459504cd3b999374bf8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "pulse" "") + +find_package(PulseAudio REQUIRED) + +set(${MODULE_PREFIX}_SRCS audin_pulse.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_MAINLOOP_LIBRARY}) + +include_directories(..) +include_directories(SYSTEM ${PULSEAUDIO_INCLUDE_DIR}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/audin_pulse.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/audin_pulse.c new file mode 100644 index 0000000000000000000000000000000000000000..826960bd7472edfd891e0a3f65f8016f7dce43de --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/pulse/audin_pulse.c @@ -0,0 +1,561 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - PulseAudio implementation + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "audin_main.h" + +typedef struct +{ + IAudinDevice iface; + + char* device_name; + UINT32 frames_per_packet; + pa_threaded_mainloop* mainloop; + pa_context* context; + pa_sample_spec sample_spec; + pa_stream* stream; + AUDIO_FORMAT format; + + size_t bytes_per_frame; + size_t buffer_frames; + + AudinReceive receive; + void* user_data; + + rdpContext* rdpcontext; + wLog* log; +} AudinPulseDevice; + +static const char* pulse_context_state_string(pa_context_state_t state) +{ + switch (state) + { + case PA_CONTEXT_UNCONNECTED: + return "PA_CONTEXT_UNCONNECTED"; + case PA_CONTEXT_CONNECTING: + return "PA_CONTEXT_CONNECTING"; + case PA_CONTEXT_AUTHORIZING: + return "PA_CONTEXT_AUTHORIZING"; + case PA_CONTEXT_SETTING_NAME: + return "PA_CONTEXT_SETTING_NAME"; + case PA_CONTEXT_READY: + return "PA_CONTEXT_READY"; + case PA_CONTEXT_FAILED: + return "PA_CONTEXT_FAILED"; + case PA_CONTEXT_TERMINATED: + return "PA_CONTEXT_TERMINATED"; + default: + return "UNKNOWN"; + } +} + +static const char* pulse_stream_state_string(pa_stream_state_t state) +{ + switch (state) + { + case PA_STREAM_UNCONNECTED: + return "PA_STREAM_UNCONNECTED"; + case PA_STREAM_CREATING: + return "PA_STREAM_CREATING"; + case PA_STREAM_READY: + return "PA_STREAM_READY"; + case PA_STREAM_FAILED: + return "PA_STREAM_FAILED"; + case PA_STREAM_TERMINATED: + return "PA_STREAM_TERMINATED"; + default: + return "UNKNOWN"; + } +} + +static void audin_pulse_context_state_callback(pa_context* context, void* userdata) +{ + AudinPulseDevice* pulse = (AudinPulseDevice*)userdata; + pa_context_state_t state = pa_context_get_state(context); + + WLog_Print(pulse->log, WLOG_DEBUG, "context state %s", pulse_context_state_string(state)); + switch (state) + { + case PA_CONTEXT_READY: + case PA_CONTEXT_FAILED: + case PA_CONTEXT_TERMINATED: + pa_threaded_mainloop_signal(pulse->mainloop, 0); + break; + + default: + break; + } +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_pulse_connect(IAudinDevice* device) +{ + pa_context_state_t state = PA_CONTEXT_FAILED; + AudinPulseDevice* pulse = (AudinPulseDevice*)device; + + if (!pulse->context) + return ERROR_INVALID_PARAMETER; + + if (pa_context_connect(pulse->context, NULL, 0, NULL)) + { + WLog_Print(pulse->log, WLOG_ERROR, "pa_context_connect failed (%d)", + pa_context_errno(pulse->context)); + return ERROR_INTERNAL_ERROR; + } + + pa_threaded_mainloop_lock(pulse->mainloop); + + if (pa_threaded_mainloop_start(pulse->mainloop) < 0) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + WLog_Print(pulse->log, WLOG_ERROR, "pa_threaded_mainloop_start failed (%d)", + pa_context_errno(pulse->context)); + return ERROR_INTERNAL_ERROR; + } + + for (;;) + { + state = pa_context_get_state(pulse->context); + + if (state == PA_CONTEXT_READY) + break; + + if (!PA_CONTEXT_IS_GOOD(state)) + { + WLog_Print(pulse->log, WLOG_ERROR, "bad context state (%s: %d)", + pulse_context_state_string(state), pa_context_errno(pulse->context)); + pa_context_disconnect(pulse->context); + return ERROR_INVALID_STATE; + } + + pa_threaded_mainloop_wait(pulse->mainloop); + } + + pa_threaded_mainloop_unlock(pulse->mainloop); + WLog_Print(pulse->log, WLOG_DEBUG, "connected"); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_pulse_free(IAudinDevice* device) +{ + AudinPulseDevice* pulse = (AudinPulseDevice*)device; + + if (!pulse) + return ERROR_INVALID_PARAMETER; + + if (pulse->mainloop) + { + pa_threaded_mainloop_stop(pulse->mainloop); + } + + if (pulse->context) + { + pa_context_disconnect(pulse->context); + pa_context_unref(pulse->context); + pulse->context = NULL; + } + + if (pulse->mainloop) + { + pa_threaded_mainloop_free(pulse->mainloop); + pulse->mainloop = NULL; + } + + free(pulse); + return CHANNEL_RC_OK; +} + +static BOOL audin_pulse_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format) +{ + AudinPulseDevice* pulse = (AudinPulseDevice*)device; + + if (!pulse || !format) + return FALSE; + + if (!pulse->context) + return 0; + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->cbSize == 0 && (format->nSamplesPerSec <= PA_RATE_MAX) && + (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) && + (format->nChannels >= 1 && format->nChannels <= PA_CHANNELS_MAX)) + { + return TRUE; + } + + break; + + default: + return FALSE; + } + + return FALSE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_pulse_set_format(IAudinDevice* device, const AUDIO_FORMAT* format, + UINT32 FramesPerPacket) +{ + pa_sample_spec sample_spec = { 0 }; + AudinPulseDevice* pulse = (AudinPulseDevice*)device; + + if (!pulse || !format) + return ERROR_INVALID_PARAMETER; + + if (!pulse->context) + return ERROR_INVALID_PARAMETER; + + if (FramesPerPacket > 0) + pulse->frames_per_packet = FramesPerPacket; + + sample_spec.rate = format->nSamplesPerSec; + + sample_spec.channels = WINPR_ASSERTING_INT_CAST(uint8_t, format->nChannels); + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: /* PCM */ + switch (format->wBitsPerSample) + { + case 8: + sample_spec.format = PA_SAMPLE_U8; + break; + + case 16: + sample_spec.format = PA_SAMPLE_S16LE; + break; + + default: + return ERROR_INTERNAL_ERROR; + } + + break; + + default: + return ERROR_INTERNAL_ERROR; + } + + pulse->sample_spec = sample_spec; + pulse->format = *format; + return CHANNEL_RC_OK; +} + +static void audin_pulse_stream_state_callback(pa_stream* stream, void* userdata) +{ + AudinPulseDevice* pulse = (AudinPulseDevice*)userdata; + WINPR_ASSERT(pulse); + + pa_stream_state_t state = pa_stream_get_state(stream); + + WLog_Print(pulse->log, WLOG_DEBUG, "stream state %s", pulse_stream_state_string(state)); + switch (state) + { + case PA_STREAM_READY: + case PA_STREAM_FAILED: + case PA_STREAM_TERMINATED: + pa_threaded_mainloop_signal(pulse->mainloop, 0); + break; + + case PA_STREAM_UNCONNECTED: + case PA_STREAM_CREATING: + default: + break; + } +} + +static void audin_pulse_stream_request_callback(pa_stream* stream, size_t length, void* userdata) +{ + const void* data = NULL; + AudinPulseDevice* pulse = (AudinPulseDevice*)userdata; + UINT error = CHANNEL_RC_OK; + pa_stream_peek(stream, &data, &length); + error = + IFCALLRESULT(CHANNEL_RC_OK, pulse->receive, &pulse->format, data, length, pulse->user_data); + pa_stream_drop(stream); + + if (error && pulse->rdpcontext) + setChannelError(pulse->rdpcontext, error, "audin_pulse_thread_func reported an error"); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_pulse_close(IAudinDevice* device) +{ + AudinPulseDevice* pulse = (AudinPulseDevice*)device; + + if (!pulse) + return ERROR_INVALID_PARAMETER; + + if (pulse->stream) + { + pa_threaded_mainloop_lock(pulse->mainloop); + pa_stream_disconnect(pulse->stream); + pa_stream_unref(pulse->stream); + pulse->stream = NULL; + pa_threaded_mainloop_unlock(pulse->mainloop); + } + + pulse->receive = NULL; + pulse->user_data = NULL; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* user_data) +{ + pa_stream_state_t state = PA_STREAM_FAILED; + pa_buffer_attr buffer_attr = { 0 }; + AudinPulseDevice* pulse = (AudinPulseDevice*)device; + + if (!pulse || !receive || !user_data) + return ERROR_INVALID_PARAMETER; + + if (!pulse->context) + return ERROR_INVALID_PARAMETER; + + if (!pulse->sample_spec.rate || pulse->stream) + return ERROR_INVALID_PARAMETER; + + pulse->receive = receive; + pulse->user_data = user_data; + pa_threaded_mainloop_lock(pulse->mainloop); + pulse->stream = pa_stream_new(pulse->context, "freerdp_audin", &pulse->sample_spec, NULL); + + if (!pulse->stream) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + WLog_Print(pulse->log, WLOG_DEBUG, "pa_stream_new failed (%d)", + pa_context_errno(pulse->context)); + const int rc = pa_context_errno(pulse->context); + return (UINT)rc; + } + + pulse->bytes_per_frame = pa_frame_size(&pulse->sample_spec); + pa_stream_set_state_callback(pulse->stream, audin_pulse_stream_state_callback, pulse); + pa_stream_set_read_callback(pulse->stream, audin_pulse_stream_request_callback, pulse); + buffer_attr.maxlength = (UINT32)-1; + buffer_attr.tlength = (UINT32)-1; + buffer_attr.prebuf = (UINT32)-1; + buffer_attr.minreq = (UINT32)-1; + /* 500ms latency */ + const size_t frag = pulse->bytes_per_frame * pulse->frames_per_packet; + WINPR_ASSERT(frag <= UINT32_MAX); + buffer_attr.fragsize = (uint32_t)frag; + + if (buffer_attr.fragsize % pulse->format.nBlockAlign) + buffer_attr.fragsize += + pulse->format.nBlockAlign - buffer_attr.fragsize % pulse->format.nBlockAlign; + + if (pa_stream_connect_record(pulse->stream, pulse->device_name, &buffer_attr, + PA_STREAM_ADJUST_LATENCY) < 0) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + WLog_Print(pulse->log, WLOG_ERROR, "pa_stream_connect_playback failed (%d)", + pa_context_errno(pulse->context)); + const int rc = pa_context_errno(pulse->context); + return (UINT)rc; + } + + while (pulse->stream) + { + state = pa_stream_get_state(pulse->stream); + + if (state == PA_STREAM_READY) + break; + + if (!PA_STREAM_IS_GOOD(state)) + { + audin_pulse_close(device); + WLog_Print(pulse->log, WLOG_ERROR, "bad stream state (%s: %d)", + pulse_stream_state_string(state), pa_context_errno(pulse->context)); + pa_threaded_mainloop_unlock(pulse->mainloop); + const int rc = pa_context_errno(pulse->context); + return (UINT)rc; + } + + pa_threaded_mainloop_wait(pulse->mainloop); + } + + pa_threaded_mainloop_unlock(pulse->mainloop); + pulse->buffer_frames = 0; + WLog_Print(pulse->log, WLOG_DEBUG, "connected"); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_pulse_parse_addin_args(AudinPulseDevice* device, const ADDIN_ARGV* args) +{ + int status = 0; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + AudinPulseDevice* pulse = device; + COMMAND_LINE_ARGUMENT_A audin_pulse_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "audio device name" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, args->argv, audin_pulse_args, flags, pulse, + NULL, NULL); + + if (status < 0) + return ERROR_INVALID_PARAMETER; + + arg = audin_pulse_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + pulse->device_name = _strdup(arg->Value); + + if (!pulse->device_name) + { + WLog_Print(pulse->log, WLOG_ERROR, "_strdup failed!"); + return CHANNEL_RC_NO_MEMORY; + } + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE pulse_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args = NULL; + AudinPulseDevice* pulse = NULL; + UINT error = 0; + pulse = (AudinPulseDevice*)calloc(1, sizeof(AudinPulseDevice)); + + if (!pulse) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + pulse->log = WLog_Get(TAG); + pulse->iface.Open = audin_pulse_open; + pulse->iface.FormatSupported = audin_pulse_format_supported; + pulse->iface.SetFormat = audin_pulse_set_format; + pulse->iface.Close = audin_pulse_close; + pulse->iface.Free = audin_pulse_free; + pulse->rdpcontext = pEntryPoints->rdpcontext; + args = pEntryPoints->args; + + if ((error = audin_pulse_parse_addin_args(pulse, args))) + { + WLog_Print(pulse->log, WLOG_ERROR, + "audin_pulse_parse_addin_args failed with error %" PRIu32 "!", error); + goto error_out; + } + + pulse->mainloop = pa_threaded_mainloop_new(); + + if (!pulse->mainloop) + { + WLog_Print(pulse->log, WLOG_ERROR, "pa_threaded_mainloop_new failed"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp"); + + if (!pulse->context) + { + WLog_Print(pulse->log, WLOG_ERROR, "pa_context_new failed"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + pa_context_set_state_callback(pulse->context, audin_pulse_context_state_callback, pulse); + + if ((error = audin_pulse_connect(&pulse->iface))) + { + WLog_Print(pulse->log, WLOG_ERROR, "audin_pulse_connect failed"); + goto error_out; + } + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, &pulse->iface))) + { + WLog_Print(pulse->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!", + error); + goto error_out; + } + + return CHANNEL_RC_OK; +error_out: + audin_pulse_free(&pulse->iface); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..93e595be0f82b10449a9f1cae441798021fce00e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/CMakeLists.txt @@ -0,0 +1,30 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Rozhuk Ivan +# Copyright (c) 2020 Ingo Feinerer +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "sndio" "") + +find_package(SNDIO REQUIRED) + +set(${MODULE_PREFIX}_SRCS audin_sndio.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${SNDIO_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${SNDIO_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/audin_sndio.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/audin_sndio.c new file mode 100644 index 0000000000000000000000000000000000000000..af5426e72f46f9b859ef107754f0613516a2e3ba --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/sndio/audin_sndio.c @@ -0,0 +1,352 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - sndio implementation + * + * Copyright (c) 2015 Rozhuk Ivan + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2020 Ingo Feinerer + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include + +#include +#include + +#include "audin_main.h" + +typedef struct +{ + IAudinDevice device; + + HANDLE thread; + HANDLE stopEvent; + + AUDIO_FORMAT format; + UINT32 FramesPerPacket; + + AudinReceive receive; + void* user_data; + + rdpContext* rdpcontext; +} AudinSndioDevice; + +static BOOL audin_sndio_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format) +{ + if (device == NULL || format == NULL) + return FALSE; + + return (format->wFormatTag == WAVE_FORMAT_PCM); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_sndio_set_format(IAudinDevice* device, AUDIO_FORMAT* format, + UINT32 FramesPerPacket) +{ + AudinSndioDevice* sndio = (AudinSndioDevice*)device; + + if (device == NULL || format == NULL) + return ERROR_INVALID_PARAMETER; + + if (format->wFormatTag != WAVE_FORMAT_PCM) + return ERROR_INTERNAL_ERROR; + + sndio->format = *format; + sndio->FramesPerPacket = FramesPerPacket; + + return CHANNEL_RC_OK; +} + +static void* audin_sndio_thread_func(void* arg) +{ + struct sio_hdl* hdl; + struct sio_par par; + BYTE* buffer = NULL; + size_t n, nbytes; + AudinSndioDevice* sndio = (AudinSndioDevice*)arg; + UINT error = 0; + DWORD status; + + if (arg == NULL) + { + error = ERROR_INVALID_PARAMETER; + goto err_out; + } + + hdl = sio_open(SIO_DEVANY, SIO_REC, 0); + if (hdl == NULL) + { + WLog_ERR(TAG, "could not open audio device"); + error = ERROR_INTERNAL_ERROR; + goto err_out; + } + + sio_initpar(&par); + par.bits = sndio->format.wBitsPerSample; + par.rchan = sndio->format.nChannels; + par.rate = sndio->format.nSamplesPerSec; + if (!sio_setpar(hdl, &par)) + { + WLog_ERR(TAG, "could not set audio parameters"); + error = ERROR_INTERNAL_ERROR; + goto err_out; + } + if (!sio_getpar(hdl, &par)) + { + WLog_ERR(TAG, "could not get audio parameters"); + error = ERROR_INTERNAL_ERROR; + goto err_out; + } + + if (!sio_start(hdl)) + { + WLog_ERR(TAG, "could not start audio device"); + error = ERROR_INTERNAL_ERROR; + goto err_out; + } + + nbytes = + (sndio->FramesPerPacket * sndio->format.nChannels * (sndio->format.wBitsPerSample / 8)); + buffer = (BYTE*)calloc((nbytes + sizeof(void*)), sizeof(BYTE)); + + if (buffer == NULL) + { + error = ERROR_NOT_ENOUGH_MEMORY; + goto err_out; + } + + while (1) + { + status = WaitForSingleObject(sndio->stopEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + goto err_out; + } + + if (status == WAIT_OBJECT_0) + break; + + n = sio_read(hdl, buffer, nbytes); + + if (n == 0) + { + WLog_ERR(TAG, "could not read"); + continue; + } + + if (n < nbytes) + continue; + + if ((error = sndio->receive(&sndio->format, buffer, nbytes, sndio->user_data))) + { + WLog_ERR(TAG, "sndio->receive failed with error %" PRIu32 "", error); + break; + } + } + +err_out: + if (error && sndio->rdpcontext) + setChannelError(sndio->rdpcontext, error, "audin_sndio_thread_func reported an error"); + + if (hdl != NULL) + { + WLog_INFO(TAG, "sio_close"); + sio_stop(hdl); + sio_close(hdl); + } + + free(buffer); + ExitThread(0); + return NULL; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_sndio_open(IAudinDevice* device, AudinReceive receive, void* user_data) +{ + AudinSndioDevice* sndio = (AudinSndioDevice*)device; + sndio->receive = receive; + sndio->user_data = user_data; + + if (!(sndio->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed"); + return ERROR_INTERNAL_ERROR; + } + + if (!(sndio->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)audin_sndio_thread_func, + sndio, 0, NULL))) + { + WLog_ERR(TAG, "CreateThread failed"); + (void)CloseHandle(sndio->stopEvent); + sndio->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_sndio_close(IAudinDevice* device) +{ + UINT error; + AudinSndioDevice* sndio = (AudinSndioDevice*)device; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if (sndio->stopEvent != NULL) + { + (void)SetEvent(sndio->stopEvent); + + if (WaitForSingleObject(sndio->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(sndio->stopEvent); + sndio->stopEvent = NULL; + (void)CloseHandle(sndio->thread); + sndio->thread = NULL; + } + + sndio->receive = NULL; + sndio->user_data = NULL; + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_sndio_free(IAudinDevice* device) +{ + AudinSndioDevice* sndio = (AudinSndioDevice*)device; + int error; + + if (device == NULL) + return ERROR_INVALID_PARAMETER; + + if ((error = audin_sndio_close(device))) + { + WLog_ERR(TAG, "audin_sndio_close failed with error code %d", error); + } + + free(sndio); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_sndio_parse_addin_args(AudinSndioDevice* device, ADDIN_ARGV* args) +{ + int status; + DWORD flags; + COMMAND_LINE_ARGUMENT_A* arg; + AudinSndioDevice* sndio = (AudinSndioDevice*)device; + COMMAND_LINE_ARGUMENT_A audin_sndio_args[] = { { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, audin_sndio_args, + flags, sndio, NULL, NULL); + + if (status < 0) + return ERROR_INVALID_PARAMETER; + + arg = audin_sndio_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE sndio_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + ADDIN_ARGV* args; + AudinSndioDevice* sndio; + UINT ret = CHANNEL_RC_OK; + sndio = (AudinSndioDevice*)calloc(1, sizeof(AudinSndioDevice)); + + if (sndio == NULL) + return CHANNEL_RC_NO_MEMORY; + + sndio->device.Open = audin_sndio_open; + sndio->device.FormatSupported = audin_sndio_format_supported; + sndio->device.SetFormat = audin_sndio_set_format; + sndio->device.Close = audin_sndio_close; + sndio->device.Free = audin_sndio_free; + sndio->rdpcontext = pEntryPoints->rdpcontext; + args = pEntryPoints->args; + + if (args->argc > 1) + { + ret = audin_sndio_parse_addin_args(sndio, args); + + if (ret != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "error parsing arguments"); + goto error; + } + } + + if ((ret = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*)sndio))) + { + WLog_ERR(TAG, "RegisterAudinDevice failed with error %" PRIu32 "", ret); + goto error; + } + + return ret; +error: + audin_sndio_free(&sndio->device); + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..903d8499d6e2bba45437ad23abc66f5ee88c253e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("audin" "winmm" "") + +set(${MODULE_PREFIX}_SRCS audin_winmm.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp winmm.lib) + +include_directories(..) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/audin_winmm.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/audin_winmm.c new file mode 100644 index 0000000000000000000000000000000000000000..daa59254f814b883cff2e4584e3a9e58cb856596 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/client/winmm/audin_winmm.c @@ -0,0 +1,566 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel - WinMM implementation + * + * Copyright 2013 Zhang Zhaolong + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "audin_main.h" + +/* fix missing definitions in mingw */ +#ifndef WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE +#define WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE 0x0010 +#endif + +typedef struct +{ + IAudinDevice iface; + + char* device_name; + AudinReceive receive; + void* user_data; + HANDLE thread; + HANDLE stopEvent; + HWAVEIN hWaveIn; + PWAVEFORMATEX* ppwfx; + PWAVEFORMATEX pwfx_cur; + UINT32 ppwfx_size; + UINT32 cFormats; + UINT32 frames_per_packet; + rdpContext* rdpcontext; + wLog* log; +} AudinWinmmDevice; + +static void CALLBACK waveInProc(HWAVEIN hWaveIn, UINT uMsg, DWORD_PTR dwInstance, + DWORD_PTR dwParam1, DWORD_PTR dwParam2) +{ + AudinWinmmDevice* winmm = (AudinWinmmDevice*)dwInstance; + PWAVEHDR pWaveHdr; + UINT error = CHANNEL_RC_OK; + MMRESULT mmResult; + + switch (uMsg) + { + case WIM_CLOSE: + break; + + case WIM_DATA: + pWaveHdr = (WAVEHDR*)dwParam1; + + if (WHDR_DONE == (WHDR_DONE & pWaveHdr->dwFlags)) + { + if (pWaveHdr->dwBytesRecorded && + !(WaitForSingleObject(winmm->stopEvent, 0) == WAIT_OBJECT_0)) + { + AUDIO_FORMAT format; + format.cbSize = winmm->pwfx_cur->cbSize; + format.nBlockAlign = winmm->pwfx_cur->nBlockAlign; + format.nAvgBytesPerSec = winmm->pwfx_cur->nAvgBytesPerSec; + format.nChannels = winmm->pwfx_cur->nChannels; + format.nSamplesPerSec = winmm->pwfx_cur->nSamplesPerSec; + format.wBitsPerSample = winmm->pwfx_cur->wBitsPerSample; + format.wFormatTag = winmm->pwfx_cur->wFormatTag; + + if ((error = winmm->receive(&format, pWaveHdr->lpData, + pWaveHdr->dwBytesRecorded, winmm->user_data))) + break; + + mmResult = waveInAddBuffer(hWaveIn, pWaveHdr, sizeof(WAVEHDR)); + + if (mmResult != MMSYSERR_NOERROR) + error = ERROR_INTERNAL_ERROR; + } + } + + break; + + case WIM_OPEN: + break; + + default: + break; + } + + if (error && winmm->rdpcontext) + setChannelError(winmm->rdpcontext, error, "waveInProc reported an error"); +} + +static BOOL log_mmresult(AudinWinmmDevice* winmm, const char* what, MMRESULT result) +{ + if (result != MMSYSERR_NOERROR) + { + CHAR buffer[8192] = { 0 }; + CHAR msg[8192] = { 0 }; + CHAR cmsg[8192] = { 0 }; + waveInGetErrorTextA(result, buffer, sizeof(buffer)); + + _snprintf(msg, sizeof(msg) - 1, "%s failed. %" PRIu32 " [%s]", what, result, buffer); + _snprintf(cmsg, sizeof(cmsg) - 1, "audin_winmm_thread_func reported an error '%s'", msg); + WLog_Print(winmm->log, WLOG_DEBUG, "%s", msg); + if (winmm->rdpcontext) + setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, cmsg); + return FALSE; + } + return TRUE; +} + +static BOOL test_format_supported(const PWAVEFORMATEX pwfx) +{ + MMRESULT rc; + WAVEINCAPSA caps = { 0 }; + + rc = waveInGetDevCapsA(WAVE_MAPPER, &caps, sizeof(caps)); + if (rc != MMSYSERR_NOERROR) + return FALSE; + + switch (pwfx->nChannels) + { + case 1: + if ((caps.dwFormats & + (WAVE_FORMAT_1M08 | WAVE_FORMAT_2M08 | WAVE_FORMAT_4M08 | WAVE_FORMAT_96M08 | + WAVE_FORMAT_1M16 | WAVE_FORMAT_2M16 | WAVE_FORMAT_4M16 | WAVE_FORMAT_96M16)) == 0) + return FALSE; + break; + case 2: + if ((caps.dwFormats & + (WAVE_FORMAT_1S08 | WAVE_FORMAT_2S08 | WAVE_FORMAT_4S08 | WAVE_FORMAT_96S08 | + WAVE_FORMAT_1S16 | WAVE_FORMAT_2S16 | WAVE_FORMAT_4S16 | WAVE_FORMAT_96S16)) == 0) + return FALSE; + break; + default: + return FALSE; + } + + rc = waveInOpen(NULL, WAVE_MAPPER, pwfx, 0, 0, + WAVE_FORMAT_QUERY | WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE); + return (rc == MMSYSERR_NOERROR); +} + +static DWORD WINAPI audin_winmm_thread_func(LPVOID arg) +{ + AudinWinmmDevice* winmm = (AudinWinmmDevice*)arg; + char* buffer = NULL; + int size = 0; + WAVEHDR waveHdr[4] = { 0 }; + DWORD status = 0; + MMRESULT rc = 0; + + if (!winmm->hWaveIn) + { + rc = waveInOpen(&winmm->hWaveIn, WAVE_MAPPER, winmm->pwfx_cur, (DWORD_PTR)waveInProc, + (DWORD_PTR)winmm, + CALLBACK_FUNCTION | WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE); + if (!log_mmresult(winmm, "waveInOpen", rc)) + return ERROR_INTERNAL_ERROR; + } + + size = + (winmm->pwfx_cur->wBitsPerSample * winmm->pwfx_cur->nChannels * winmm->frames_per_packet + + 7) / + 8; + + for (int i = 0; i < 4; i++) + { + buffer = (char*)malloc(size); + + if (!buffer) + return CHANNEL_RC_NO_MEMORY; + + waveHdr[i].dwBufferLength = size; + waveHdr[i].dwFlags = 0; + waveHdr[i].lpData = buffer; + rc = waveInPrepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i])); + + if (!log_mmresult(winmm, "waveInPrepareHeader", rc)) + { + } + + rc = waveInAddBuffer(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i])); + + if (!log_mmresult(winmm, "waveInAddBuffer", rc)) + { + } + } + + rc = waveInStart(winmm->hWaveIn); + + if (!log_mmresult(winmm, "waveInStart", rc)) + { + } + + status = WaitForSingleObject(winmm->stopEvent, INFINITE); + + if (status == WAIT_FAILED) + { + WLog_Print(winmm->log, WLOG_DEBUG, "WaitForSingleObject failed."); + + if (winmm->rdpcontext) + setChannelError(winmm->rdpcontext, ERROR_INTERNAL_ERROR, + "audin_winmm_thread_func reported an error"); + } + + rc = waveInReset(winmm->hWaveIn); + + if (!log_mmresult(winmm, "waveInReset", rc)) + { + } + + for (int i = 0; i < 4; i++) + { + rc = waveInUnprepareHeader(winmm->hWaveIn, &waveHdr[i], sizeof(waveHdr[i])); + + if (!log_mmresult(winmm, "waveInUnprepareHeader", rc)) + { + } + + free(waveHdr[i].lpData); + } + + rc = waveInClose(winmm->hWaveIn); + + if (!log_mmresult(winmm, "waveInClose", rc)) + { + } + + winmm->hWaveIn = NULL; + return 0; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_winmm_free(IAudinDevice* device) +{ + AudinWinmmDevice* winmm = (AudinWinmmDevice*)device; + + if (!winmm) + return ERROR_INVALID_PARAMETER; + + for (UINT32 i = 0; i < winmm->cFormats; i++) + { + free(winmm->ppwfx[i]); + } + + free(winmm->ppwfx); + free(winmm->device_name); + free(winmm); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_winmm_close(IAudinDevice* device) +{ + DWORD status; + UINT error = CHANNEL_RC_OK; + AudinWinmmDevice* winmm = (AudinWinmmDevice*)device; + + if (!winmm) + return ERROR_INVALID_PARAMETER; + + (void)SetEvent(winmm->stopEvent); + status = WaitForSingleObject(winmm->thread, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_Print(winmm->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "!", + error); + return error; + } + + (void)CloseHandle(winmm->thread); + (void)CloseHandle(winmm->stopEvent); + winmm->thread = NULL; + winmm->stopEvent = NULL; + winmm->receive = NULL; + winmm->user_data = NULL; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_winmm_set_format(IAudinDevice* device, const AUDIO_FORMAT* format, + UINT32 FramesPerPacket) +{ + AudinWinmmDevice* winmm = (AudinWinmmDevice*)device; + + if (!winmm || !format) + return ERROR_INVALID_PARAMETER; + + winmm->frames_per_packet = FramesPerPacket; + + for (UINT32 i = 0; i < winmm->cFormats; i++) + { + const PWAVEFORMATEX ppwfx = winmm->ppwfx[i]; + if ((ppwfx->wFormatTag == format->wFormatTag) && (ppwfx->nChannels == format->nChannels) && + (ppwfx->wBitsPerSample == format->wBitsPerSample) && + (ppwfx->nSamplesPerSec == format->nSamplesPerSec)) + { + /* BUG: Many devices report to support stereo recording but fail here. + * Ensure we always use mono. */ + if (ppwfx->nChannels > 1) + { + ppwfx->nChannels = 1; + } + + if (ppwfx->nBlockAlign != 2) + { + ppwfx->nBlockAlign = 2; + ppwfx->nAvgBytesPerSec = ppwfx->nSamplesPerSec * ppwfx->nBlockAlign; + } + + if (!test_format_supported(ppwfx)) + return ERROR_INVALID_PARAMETER; + winmm->pwfx_cur = ppwfx; + return CHANNEL_RC_OK; + } + } + + return ERROR_INVALID_PARAMETER; +} + +static BOOL audin_winmm_format_supported(IAudinDevice* device, const AUDIO_FORMAT* format) +{ + AudinWinmmDevice* winmm = (AudinWinmmDevice*)device; + PWAVEFORMATEX pwfx; + BYTE* data; + + if (!winmm || !format) + return FALSE; + + if (format->wFormatTag != WAVE_FORMAT_PCM) + return FALSE; + + if (format->nChannels != 1) + return FALSE; + + pwfx = (PWAVEFORMATEX)malloc(sizeof(WAVEFORMATEX) + format->cbSize); + + if (!pwfx) + return FALSE; + + pwfx->cbSize = format->cbSize; + pwfx->wFormatTag = format->wFormatTag; + pwfx->nChannels = format->nChannels; + pwfx->nSamplesPerSec = format->nSamplesPerSec; + pwfx->nBlockAlign = format->nBlockAlign; + pwfx->wBitsPerSample = format->wBitsPerSample; + data = (BYTE*)pwfx + sizeof(WAVEFORMATEX); + memcpy(data, format->data, format->cbSize); + + pwfx->nAvgBytesPerSec = pwfx->nSamplesPerSec * pwfx->nBlockAlign; + + if (!test_format_supported(pwfx)) + goto fail; + + if (winmm->cFormats >= winmm->ppwfx_size) + { + PWAVEFORMATEX* tmp_ppwfx; + tmp_ppwfx = realloc(winmm->ppwfx, sizeof(PWAVEFORMATEX) * winmm->ppwfx_size * 2); + + if (!tmp_ppwfx) + goto fail; + + winmm->ppwfx_size *= 2; + winmm->ppwfx = tmp_ppwfx; + } + + winmm->ppwfx[winmm->cFormats++] = pwfx; + return TRUE; + +fail: + free(pwfx); + return FALSE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_winmm_open(IAudinDevice* device, AudinReceive receive, void* user_data) +{ + AudinWinmmDevice* winmm = (AudinWinmmDevice*)device; + + if (!winmm || !receive || !user_data) + return ERROR_INVALID_PARAMETER; + + winmm->receive = receive; + winmm->user_data = user_data; + + if (!(winmm->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_Print(winmm->log, WLOG_ERROR, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (!(winmm->thread = CreateThread(NULL, 0, audin_winmm_thread_func, winmm, 0, NULL))) + { + WLog_Print(winmm->log, WLOG_ERROR, "CreateThread failed!"); + (void)CloseHandle(winmm->stopEvent); + winmm->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT audin_winmm_parse_addin_args(AudinWinmmDevice* device, const ADDIN_ARGV* args) +{ + int status; + DWORD flags; + const COMMAND_LINE_ARGUMENT_A* arg; + AudinWinmmDevice* winmm = (AudinWinmmDevice*)device; + COMMAND_LINE_ARGUMENT_A audin_winmm_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "audio device name" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, args->argv, audin_winmm_args, flags, winmm, + NULL, NULL); + arg = audin_winmm_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + winmm->device_name = _strdup(arg->Value); + + if (!winmm->device_name) + { + WLog_Print(winmm->log, WLOG_ERROR, "_strdup failed!"); + return CHANNEL_RC_NO_MEMORY; + } + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE winmm_freerdp_audin_client_subsystem_entry( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args; + AudinWinmmDevice* winmm; + UINT error; + + if (waveInGetNumDevs() == 0) + { + WLog_Print(WLog_Get(TAG), WLOG_ERROR, "No microphone available!"); + return ERROR_DEVICE_NOT_AVAILABLE; + } + + winmm = (AudinWinmmDevice*)calloc(1, sizeof(AudinWinmmDevice)); + + if (!winmm) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + winmm->log = WLog_Get(TAG); + winmm->iface.Open = audin_winmm_open; + winmm->iface.FormatSupported = audin_winmm_format_supported; + winmm->iface.SetFormat = audin_winmm_set_format; + winmm->iface.Close = audin_winmm_close; + winmm->iface.Free = audin_winmm_free; + winmm->rdpcontext = pEntryPoints->rdpcontext; + args = pEntryPoints->args; + + if ((error = audin_winmm_parse_addin_args(winmm, args))) + { + WLog_Print(winmm->log, WLOG_ERROR, + "audin_winmm_parse_addin_args failed with error %" PRIu32 "!", error); + goto error_out; + } + + if (!winmm->device_name) + { + winmm->device_name = _strdup("default"); + + if (!winmm->device_name) + { + WLog_Print(winmm->log, WLOG_ERROR, "_strdup failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + } + + winmm->ppwfx_size = 10; + winmm->ppwfx = calloc(winmm->ppwfx_size, sizeof(PWAVEFORMATEX)); + + if (!winmm->ppwfx) + { + WLog_Print(winmm->log, WLOG_ERROR, "malloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, &winmm->iface))) + { + WLog_Print(winmm->log, WLOG_ERROR, "RegisterAudinDevice failed with error %" PRIu32 "!", + error); + goto error_out; + } + + return CHANNEL_RC_OK; +error_out: + free(winmm->ppwfx); + free(winmm->device_name); + free(winmm); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d081e2389dbb23f7ba54d913470ebb0a779e65e4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/CMakeLists.txt @@ -0,0 +1,23 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("audin") + +set(${MODULE_PREFIX}_SRCS audin.c) + +set(${MODULE_PREFIX}_LIBS freerdp) +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/audin.c b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/audin.c new file mode 100644 index 0000000000000000000000000000000000000000..142e198fd3489f4011bf7bcd86d511966702fdbf --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/audin/server/audin.c @@ -0,0 +1,913 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Audio Input Virtual Channel + * + * Copyright 2012 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define AUDIN_TAG CHANNELS_TAG("audin.server") + +#define SNDIN_HEADER_SIZE 1 + +typedef enum +{ + MSG_SNDIN_VERSION = 0x01, + MSG_SNDIN_FORMATS = 0x02, + MSG_SNDIN_OPEN = 0x03, + MSG_SNDIN_OPEN_REPLY = 0x04, + MSG_SNDIN_DATA_INCOMING = 0x05, + MSG_SNDIN_DATA = 0x06, + MSG_SNDIN_FORMATCHANGE = 0x07, +} MSG_SNDIN; + +typedef struct +{ + audin_server_context context; + + HANDLE stopEvent; + + HANDLE thread; + void* audin_channel; + + DWORD SessionId; + + AUDIO_FORMAT* audin_server_formats; + UINT32 audin_n_server_formats; + AUDIO_FORMAT* audin_negotiated_format; + UINT32 audin_client_format_idx; + wLog* log; +} audin_server; + +static UINT audin_server_recv_version(audin_server_context* context, wStream* s, + const SNDIN_PDU* header) +{ + audin_server* audin = (audin_server*)context; + SNDIN_VERSION pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4)) + return ERROR_NO_DATA; + + Stream_Read_UINT32(s, pdu.Version); + + IFCALLRET(context->ReceiveVersion, error, context, &pdu); + if (error) + WLog_Print(audin->log, WLOG_ERROR, "context->ReceiveVersion failed with error %" PRIu32 "", + error); + + return error; +} + +static UINT audin_server_recv_formats(audin_server_context* context, wStream* s, + const SNDIN_PDU* header) +{ + audin_server* audin = (audin_server*)context; + SNDIN_FORMATS pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + /* Implementations MUST, at a minimum, support WAVE_FORMAT_PCM (0x0001) */ + if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4 + 4 + 18)) + return ERROR_NO_DATA; + + Stream_Read_UINT32(s, pdu.NumFormats); + Stream_Read_UINT32(s, pdu.cbSizeFormatsPacket); + + if (pdu.NumFormats == 0) + { + WLog_Print(audin->log, WLOG_ERROR, "Sound Formats PDU contains no formats"); + return ERROR_INVALID_DATA; + } + + pdu.SoundFormats = audio_formats_new(pdu.NumFormats); + if (!pdu.SoundFormats) + { + WLog_Print(audin->log, WLOG_ERROR, "Failed to allocate %u SoundFormats", pdu.NumFormats); + return ERROR_NOT_ENOUGH_MEMORY; + } + + for (UINT32 i = 0; i < pdu.NumFormats; ++i) + { + AUDIO_FORMAT* format = &pdu.SoundFormats[i]; + + if (!audio_format_read(s, format)) + { + WLog_Print(audin->log, WLOG_ERROR, "Failed to read audio format"); + audio_formats_free(pdu.SoundFormats, i + i); + return ERROR_INVALID_DATA; + } + + audio_format_print(audin->log, WLOG_DEBUG, format); + } + + if (pdu.cbSizeFormatsPacket != Stream_GetPosition(s)) + { + WLog_Print(audin->log, WLOG_WARN, + "cbSizeFormatsPacket is invalid! Expected: %u Got: %zu. Fixing size", + pdu.cbSizeFormatsPacket, Stream_GetPosition(s)); + const size_t pos = Stream_GetPosition(s); + if (pos > UINT32_MAX) + { + WLog_Print(audin->log, WLOG_ERROR, "Stream too long, %" PRIuz " exceeds UINT32_MAX", + pos); + error = ERROR_INVALID_PARAMETER; + goto fail; + } + pdu.cbSizeFormatsPacket = (UINT32)pos; + } + + pdu.ExtraDataSize = Stream_GetRemainingLength(s); + + IFCALLRET(context->ReceiveFormats, error, context, &pdu); + if (error) + WLog_Print(audin->log, WLOG_ERROR, "context->ReceiveFormats failed with error %" PRIu32 "", + error); + +fail: + audio_formats_free(pdu.SoundFormats, pdu.NumFormats); + + return error; +} + +static UINT audin_server_recv_open_reply(audin_server_context* context, wStream* s, + const SNDIN_PDU* header) +{ + audin_server* audin = (audin_server*)context; + SNDIN_OPEN_REPLY pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4)) + return ERROR_NO_DATA; + + Stream_Read_UINT32(s, pdu.Result); + + IFCALLRET(context->OpenReply, error, context, &pdu); + if (error) + WLog_Print(audin->log, WLOG_ERROR, "context->OpenReply failed with error %" PRIu32 "", + error); + + return error; +} + +static UINT audin_server_recv_data_incoming(audin_server_context* context, wStream* s, + const SNDIN_PDU* header) +{ + audin_server* audin = (audin_server*)context; + SNDIN_DATA_INCOMING pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + IFCALLRET(context->IncomingData, error, context, &pdu); + if (error) + WLog_Print(audin->log, WLOG_ERROR, "context->IncomingData failed with error %" PRIu32 "", + error); + + return error; +} + +static UINT audin_server_recv_data(audin_server_context* context, wStream* s, + const SNDIN_PDU* header) +{ + audin_server* audin = (audin_server*)context; + SNDIN_DATA pdu = { 0 }; + wStream dataBuffer = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + pdu.Data = Stream_StaticInit(&dataBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s)); + + IFCALLRET(context->Data, error, context, &pdu); + if (error) + WLog_Print(audin->log, WLOG_ERROR, "context->Data failed with error %" PRIu32 "", error); + + return error; +} + +static UINT audin_server_recv_format_change(audin_server_context* context, wStream* s, + const SNDIN_PDU* header) +{ + audin_server* audin = (audin_server*)context; + SNDIN_FORMATCHANGE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4)) + return ERROR_NO_DATA; + + Stream_Read_UINT32(s, pdu.NewFormat); + + IFCALLRET(context->ReceiveFormatChange, error, context, &pdu); + if (error) + WLog_Print(audin->log, WLOG_ERROR, + "context->ReceiveFormatChange failed with error %" PRIu32 "", error); + + return error; +} + +static DWORD WINAPI audin_server_thread_func(LPVOID arg) +{ + wStream* s = NULL; + void* buffer = NULL; + DWORD nCount = 0; + HANDLE events[8] = { 0 }; + BOOL ready = FALSE; + HANDLE ChannelEvent = NULL; + DWORD BytesReturned = 0; + audin_server* audin = (audin_server*)arg; + UINT error = CHANNEL_RC_OK; + DWORD status = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(audin); + + if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) == TRUE) + { + if (BytesReturned == sizeof(HANDLE)) + ChannelEvent = *(HANDLE*)buffer; + + WTSFreeMemory(buffer); + } + else + { + WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelQuery failed"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + nCount = 0; + events[nCount++] = audin->stopEvent; + events[nCount++] = ChannelEvent; + + /* Wait for the client to confirm that the Audio Input dynamic channel is ready */ + + while (1) + { + if ((status = WaitForMultipleObjects(nCount, events, FALSE, 100)) == WAIT_OBJECT_0) + goto out; + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_Print(audin->log, WLOG_ERROR, + "WaitForMultipleObjects failed with error %" PRIu32 "", error); + goto out; + } + if (status == WAIT_OBJECT_0) + goto out; + + if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer, + &BytesReturned) == FALSE) + { + WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelQuery failed"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + ready = *((BOOL*)buffer); + WTSFreeMemory(buffer); + + if (ready) + break; + } + + s = Stream_New(NULL, 4096); + + if (!s) + { + WLog_Print(audin->log, WLOG_ERROR, "Stream_New failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + if (ready) + { + SNDIN_VERSION version = { 0 }; + + version.Version = audin->context.serverVersion; + + if ((error = audin->context.SendVersion(&audin->context, &version))) + { + WLog_Print(audin->log, WLOG_ERROR, "SendVersion failed with error %" PRIu32 "!", error); + goto out_capacity; + } + } + + while (ready) + { + SNDIN_PDU header = { 0 }; + + if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0) + break; + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_Print(audin->log, WLOG_ERROR, + "WaitForMultipleObjects failed with error %" PRIu32 "", error); + break; + } + if (status == WAIT_OBJECT_0) + break; + + Stream_SetPosition(s, 0); + + if (!WTSVirtualChannelRead(audin->audin_channel, 0, NULL, 0, &BytesReturned)) + { + WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelRead failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (BytesReturned < 1) + continue; + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + break; + + WINPR_ASSERT(Stream_Capacity(s) <= UINT32_MAX); + if (WTSVirtualChannelRead(audin->audin_channel, 0, Stream_BufferAs(s, char), + (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE) + { + WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelRead failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + Stream_SetLength(s, BytesReturned); + if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, SNDIN_HEADER_SIZE)) + { + error = ERROR_INTERNAL_ERROR; + break; + } + + Stream_Read_UINT8(s, header.MessageId); + + switch (header.MessageId) + { + case MSG_SNDIN_VERSION: + error = audin_server_recv_version(&audin->context, s, &header); + break; + case MSG_SNDIN_FORMATS: + error = audin_server_recv_formats(&audin->context, s, &header); + break; + case MSG_SNDIN_OPEN_REPLY: + error = audin_server_recv_open_reply(&audin->context, s, &header); + break; + case MSG_SNDIN_DATA_INCOMING: + error = audin_server_recv_data_incoming(&audin->context, s, &header); + break; + case MSG_SNDIN_DATA: + error = audin_server_recv_data(&audin->context, s, &header); + break; + case MSG_SNDIN_FORMATCHANGE: + error = audin_server_recv_format_change(&audin->context, s, &header); + break; + default: + WLog_Print(audin->log, WLOG_ERROR, + "audin_server_thread_func: unknown or invalid MessageId %" PRIu8 "", + header.MessageId); + error = ERROR_INVALID_DATA; + break; + } + if (error) + break; + } + +out_capacity: + Stream_Free(s, TRUE); +out: + (void)WTSVirtualChannelClose(audin->audin_channel); + audin->audin_channel = NULL; + + if (error && audin->context.rdpcontext) + setChannelError(audin->context.rdpcontext, error, + "audin_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +static BOOL audin_server_open(audin_server_context* context) +{ + audin_server* audin = (audin_server*)context; + + WINPR_ASSERT(audin); + if (!audin->thread) + { + PULONG pSessionId = NULL; + DWORD BytesReturned = 0; + audin->SessionId = WTS_CURRENT_SESSION; + UINT32 channelId = 0; + BOOL status = TRUE; + + if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned)) + { + audin->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + } + + audin->audin_channel = WTSVirtualChannelOpenEx(audin->SessionId, AUDIN_DVC_CHANNEL_NAME, + WTS_CHANNEL_OPTION_DYNAMIC); + + if (!audin->audin_channel) + { + WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelOpenEx failed!"); + return FALSE; + } + + channelId = WTSChannelGetIdByHandle(audin->audin_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_Print(audin->log, WLOG_ERROR, "context->ChannelIdAssigned failed!"); + return FALSE; + } + + if (!(audin->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_Print(audin->log, WLOG_ERROR, "CreateEvent failed!"); + return FALSE; + } + + if (!(audin->thread = + CreateThread(NULL, 0, audin_server_thread_func, (void*)audin, 0, NULL))) + { + WLog_Print(audin->log, WLOG_ERROR, "CreateThread failed!"); + (void)CloseHandle(audin->stopEvent); + audin->stopEvent = NULL; + return FALSE; + } + + return TRUE; + } + + WLog_Print(audin->log, WLOG_ERROR, "thread already running!"); + return FALSE; +} + +static BOOL audin_server_is_open(audin_server_context* context) +{ + audin_server* audin = (audin_server*)context; + + WINPR_ASSERT(audin); + return audin->thread != NULL; +} + +static BOOL audin_server_close(audin_server_context* context) +{ + audin_server* audin = (audin_server*)context; + WINPR_ASSERT(audin); + + if (audin->thread) + { + (void)SetEvent(audin->stopEvent); + + if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED) + { + WLog_Print(audin->log, WLOG_ERROR, "WaitForSingleObject failed with error %" PRIu32 "", + GetLastError()); + return FALSE; + } + + (void)CloseHandle(audin->thread); + (void)CloseHandle(audin->stopEvent); + audin->thread = NULL; + audin->stopEvent = NULL; + } + + if (audin->audin_channel) + { + (void)WTSVirtualChannelClose(audin->audin_channel); + audin->audin_channel = NULL; + } + + audin->audin_negotiated_format = NULL; + + return TRUE; +} + +static wStream* audin_server_packet_new(wLog* log, size_t size, BYTE MessageId) +{ + WINPR_ASSERT(log); + + /* Allocate what we need plus header bytes */ + wStream* s = Stream_New(NULL, size + SNDIN_HEADER_SIZE); + if (!s) + { + WLog_Print(log, WLOG_ERROR, "Stream_New failed!"); + return NULL; + } + + Stream_Write_UINT8(s, MessageId); + + return s; +} + +static UINT audin_server_packet_send(audin_server_context* context, wStream* s) +{ + audin_server* audin = (audin_server*)context; + UINT error = CHANNEL_RC_OK; + ULONG written = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(s); + + const size_t pos = Stream_GetPosition(s); + WINPR_ASSERT(pos <= UINT32_MAX); + if (!WTSVirtualChannelWrite(audin->audin_channel, Stream_BufferAs(s, char), (UINT32)pos, + &written)) + { + WLog_Print(audin->log, WLOG_ERROR, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + if (written < Stream_GetPosition(s)) + { + WLog_Print(audin->log, WLOG_WARN, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", + written, Stream_GetPosition(s)); + } + +out: + Stream_Free(s, TRUE); + return error; +} + +static UINT audin_server_send_version(audin_server_context* context, const SNDIN_VERSION* version) +{ + audin_server* audin = (audin_server*)context; + + WINPR_ASSERT(context); + WINPR_ASSERT(version); + + wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_VERSION); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT32(s, version->Version); + + return audin_server_packet_send(context, s); +} + +static UINT audin_server_send_formats(audin_server_context* context, const SNDIN_FORMATS* formats) +{ + audin_server* audin = (audin_server*)context; + + WINPR_ASSERT(audin); + WINPR_ASSERT(formats); + + wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18, MSG_SNDIN_FORMATS); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT32(s, formats->NumFormats); + Stream_Write_UINT32(s, formats->cbSizeFormatsPacket); + + for (UINT32 i = 0; i < formats->NumFormats; ++i) + { + AUDIO_FORMAT* format = &formats->SoundFormats[i]; + + if (!audio_format_write(s, format)) + { + WLog_Print(audin->log, WLOG_ERROR, "Failed to write audio format"); + Stream_Free(s, TRUE); + return CHANNEL_RC_NO_MEMORY; + } + } + + return audin_server_packet_send(context, s); +} + +static UINT audin_server_send_open(audin_server_context* context, const SNDIN_OPEN* open) +{ + audin_server* audin = (audin_server*)context; + WINPR_ASSERT(audin); + WINPR_ASSERT(open); + + wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18 + 22, MSG_SNDIN_OPEN); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT32(s, open->FramesPerPacket); + Stream_Write_UINT32(s, open->initialFormat); + + Stream_Write_UINT16(s, open->captureFormat.wFormatTag); + Stream_Write_UINT16(s, open->captureFormat.nChannels); + Stream_Write_UINT32(s, open->captureFormat.nSamplesPerSec); + Stream_Write_UINT32(s, open->captureFormat.nAvgBytesPerSec); + Stream_Write_UINT16(s, open->captureFormat.nBlockAlign); + Stream_Write_UINT16(s, open->captureFormat.wBitsPerSample); + + if (open->ExtraFormatData) + { + Stream_Write_UINT16(s, 22); /* cbSize */ + + Stream_Write_UINT16(s, open->ExtraFormatData->Samples.wReserved); + Stream_Write_UINT32(s, open->ExtraFormatData->dwChannelMask); + + Stream_Write_UINT32(s, open->ExtraFormatData->SubFormat.Data1); + Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data2); + Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data3); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[0]); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[1]); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[2]); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[3]); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[4]); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[5]); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[6]); + Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[7]); + } + else + { + WINPR_ASSERT(open->captureFormat.wFormatTag != WAVE_FORMAT_EXTENSIBLE); + + Stream_Write_UINT16(s, 0); /* cbSize */ + } + + return audin_server_packet_send(context, s); +} + +static UINT audin_server_send_format_change(audin_server_context* context, + const SNDIN_FORMATCHANGE* format_change) +{ + audin_server* audin = (audin_server*)context; + + WINPR_ASSERT(context); + WINPR_ASSERT(format_change); + + wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_FORMATCHANGE); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT32(s, format_change->NewFormat); + + return audin_server_packet_send(context, s); +} + +static UINT audin_server_receive_version_default(audin_server_context* audin_ctx, + const SNDIN_VERSION* version) +{ + audin_server* audin = (audin_server*)audin_ctx; + SNDIN_FORMATS formats = { 0 }; + + WINPR_ASSERT(audin); + WINPR_ASSERT(version); + + if (version->Version == 0) + { + WLog_Print(audin->log, WLOG_ERROR, "Received invalid AUDIO_INPUT version from client"); + return ERROR_INVALID_DATA; + } + + WLog_Print(audin->log, WLOG_DEBUG, "AUDIO_INPUT version of client: %u", version->Version); + + formats.NumFormats = audin->audin_n_server_formats; + formats.SoundFormats = audin->audin_server_formats; + + return audin->context.SendFormats(&audin->context, &formats); +} + +static UINT send_open(audin_server* audin) +{ + SNDIN_OPEN open = { 0 }; + + WINPR_ASSERT(audin); + + open.FramesPerPacket = 441; + open.initialFormat = audin->audin_client_format_idx; + open.captureFormat.wFormatTag = WAVE_FORMAT_PCM; + open.captureFormat.nChannels = 2; + open.captureFormat.nSamplesPerSec = 44100; + open.captureFormat.nAvgBytesPerSec = 44100 * 2 * 2; + open.captureFormat.nBlockAlign = 4; + open.captureFormat.wBitsPerSample = 16; + + WINPR_ASSERT(audin->context.SendOpen); + return audin->context.SendOpen(&audin->context, &open); +} + +static UINT audin_server_receive_formats_default(audin_server_context* context, + const SNDIN_FORMATS* formats) +{ + audin_server* audin = (audin_server*)context; + WINPR_ASSERT(audin); + WINPR_ASSERT(formats); + + if (audin->audin_negotiated_format) + { + WLog_Print(audin->log, WLOG_ERROR, + "Received client formats, but negotiation was already done"); + return ERROR_INVALID_DATA; + } + + for (UINT32 i = 0; i < audin->audin_n_server_formats; ++i) + { + for (UINT32 j = 0; j < formats->NumFormats; ++j) + { + if (audio_format_compatible(&audin->audin_server_formats[i], &formats->SoundFormats[j])) + { + audin->audin_negotiated_format = &audin->audin_server_formats[i]; + audin->audin_client_format_idx = i; + return send_open(audin); + } + } + } + + WLog_Print(audin->log, WLOG_ERROR, "Could not agree on a audio format with the server"); + + return ERROR_INVALID_DATA; +} + +static UINT audin_server_receive_format_change_default(audin_server_context* context, + const SNDIN_FORMATCHANGE* format_change) +{ + audin_server* audin = (audin_server*)context; + + WINPR_ASSERT(audin); + WINPR_ASSERT(format_change); + + if (format_change->NewFormat != audin->audin_client_format_idx) + { + WLog_Print(audin->log, WLOG_ERROR, + "NewFormat in FormatChange differs from requested format"); + return ERROR_INVALID_DATA; + } + + WLog_Print(audin->log, WLOG_DEBUG, "Received Format Change PDU: %u", format_change->NewFormat); + + return CHANNEL_RC_OK; +} + +static UINT audin_server_incoming_data_default(audin_server_context* context, + const SNDIN_DATA_INCOMING* data_incoming) +{ + audin_server* audin = (audin_server*)context; + WINPR_ASSERT(audin); + WINPR_ASSERT(data_incoming); + + /* TODO: Implement bandwidth measure of clients uplink */ + WLog_Print(audin->log, WLOG_DEBUG, "Received Incoming Data PDU"); + return CHANNEL_RC_OK; +} + +static UINT audin_server_open_reply_default(audin_server_context* context, + const SNDIN_OPEN_REPLY* open_reply) +{ + audin_server* audin = (audin_server*)context; + WINPR_ASSERT(audin); + WINPR_ASSERT(open_reply); + + /* TODO: Implement failure handling */ + WLog_Print(audin->log, WLOG_DEBUG, "Open Reply PDU: Result: %i", open_reply->Result); + return CHANNEL_RC_OK; +} + +audin_server_context* audin_server_context_new(HANDLE vcm) +{ + audin_server* audin = (audin_server*)calloc(1, sizeof(audin_server)); + + if (!audin) + { + WLog_ERR(AUDIN_TAG, "calloc failed!"); + return NULL; + } + audin->log = WLog_Get(AUDIN_TAG); + audin->context.vcm = vcm; + audin->context.Open = audin_server_open; + audin->context.IsOpen = audin_server_is_open; + audin->context.Close = audin_server_close; + + audin->context.SendVersion = audin_server_send_version; + audin->context.SendFormats = audin_server_send_formats; + audin->context.SendOpen = audin_server_send_open; + audin->context.SendFormatChange = audin_server_send_format_change; + + /* Default values */ + audin->context.serverVersion = SNDIN_VERSION_Version_2; + audin->context.ReceiveVersion = audin_server_receive_version_default; + audin->context.ReceiveFormats = audin_server_receive_formats_default; + audin->context.ReceiveFormatChange = audin_server_receive_format_change_default; + audin->context.IncomingData = audin_server_incoming_data_default; + audin->context.OpenReply = audin_server_open_reply_default; + + return &audin->context; +} + +void audin_server_context_free(audin_server_context* context) +{ + audin_server* audin = (audin_server*)context; + + if (!audin) + return; + + audin_server_close(context); + audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats); + audin->audin_server_formats = NULL; + free(audin); +} + +BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count, + const AUDIO_FORMAT* formats) +{ + audin_server* audin = (audin_server*)context; + WINPR_ASSERT(audin); + + audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats); + audin->audin_n_server_formats = 0; + audin->audin_server_formats = NULL; + audin->audin_negotiated_format = NULL; + + if (count < 0) + { + const size_t audin_n_server_formats = + server_audin_get_formats(&audin->audin_server_formats); + WINPR_ASSERT(audin_n_server_formats <= UINT32_MAX); + + audin->audin_n_server_formats = (UINT32)audin_n_server_formats; + } + else + { + const size_t scount = (size_t)count; + AUDIO_FORMAT* audin_server_formats = audio_formats_new(scount); + if (!audin_server_formats) + return count == 0; + + for (SSIZE_T x = 0; x < count; x++) + { + if (!audio_format_copy(&formats[x], &audin_server_formats[x])) + { + audio_formats_free(audin_server_formats, scount); + return FALSE; + } + } + + WINPR_ASSERT(count <= UINT32_MAX); + audin->audin_server_formats = audin_server_formats; + audin->audin_n_server_formats = (UINT32)count; + } + return audin->audin_n_server_formats > 0; +} + +const AUDIO_FORMAT* audin_server_get_negotiated_format(const audin_server_context* context) +{ + const audin_server* audin = (const audin_server*)context; + WINPR_ASSERT(audin); + + return audin->audin_negotiated_format; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a5d596211b1c37efbb8f03063217d8a77df88029 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/client/CMakeLists.txt @@ -0,0 +1,165 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# Copyright 2024 Armin Novak +# Copyright 2024 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(MODULE_NAME "freerdp-channels-client") +set(MODULE_PREFIX "FREERDP_CHANNELS_CLIENT") + +set(${MODULE_PREFIX}_SRCS + ${CMAKE_CURRENT_BINARY_DIR}/tables.c ${CMAKE_CURRENT_SOURCE_DIR}/tables.h ${CMAKE_CURRENT_SOURCE_DIR}/addin.c + ${CMAKE_CURRENT_SOURCE_DIR}/addin.h ${CMAKE_CURRENT_SOURCE_DIR}/generic_dynvc.c +) + +if(CHANNEL_STATIC_CLIENT_ENTRIES) + list(REMOVE_DUPLICATES CHANNEL_STATIC_CLIENT_ENTRIES) +endif() + +foreach(STATIC_ENTRY ${CHANNEL_STATIC_CLIENT_ENTRIES}) + foreach(STATIC_MODULE ${CHANNEL_STATIC_CLIENT_MODULES}) + foreach(ENTRY ${${STATIC_MODULE}_CLIENT_ENTRY}) + if(${ENTRY} STREQUAL ${STATIC_ENTRY}) + set(STATIC_MODULE_NAME ${${STATIC_MODULE}_CLIENT_NAME}) + set(STATIC_MODULE_CHANNEL ${${STATIC_MODULE}_CLIENT_CHANNEL}) + list(APPEND ${MODULE_PREFIX}_LIBS ${STATIC_MODULE_NAME}) + + set(ENTRY_POINT_NAME "${STATIC_MODULE_CHANNEL}_${ENTRY}") + if(${ENTRY} STREQUAL "VirtualChannelEntry") + set(ENTRY_POINT_IMPORT "extern BOOL VCAPITYPE ${ENTRY_POINT_NAME}(PCHANNEL_ENTRY_POINTS);") + elseif(${ENTRY} STREQUAL "VirtualChannelEntryEx") + set(ENTRY_POINT_IMPORT "extern BOOL VCAPITYPE ${ENTRY_POINT_NAME}(PCHANNEL_ENTRY_POINTS,PVOID);") + elseif(${ENTRY} MATCHES "DVCPluginEntry$") + set(ENTRY_POINT_IMPORT "extern UINT VCAPITYPE ${ENTRY_POINT_NAME}(IDRDYNVC_ENTRY_POINTS* pEntryPoints);") + elseif(${ENTRY} MATCHES "DeviceServiceEntry$") + set(ENTRY_POINT_IMPORT + "extern UINT VCAPITYPE ${ENTRY_POINT_NAME}(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints);" + ) + else() + set(ENTRY_POINT_IMPORT "extern UINT VCAPITYPE ${ENTRY_POINT_NAME}(void);") + endif() + + string(APPEND ${STATIC_ENTRY}_IMPORTS "\n${ENTRY_POINT_IMPORT}") + string(APPEND ${STATIC_ENTRY}_TABLE "\n\t{ \"${STATIC_MODULE_CHANNEL}\", ${ENTRY_POINT_NAME} },") + endif() + endforeach() + endforeach() +endforeach() + +string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "\nextern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[];\n") +string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[] =\n{") + +foreach(STATIC_ENTRY ${CHANNEL_STATIC_CLIENT_ENTRIES}) + set(CLIENT_STATIC_ENTRY_IMPORTS "${CLIENT_STATIC_ENTRY_IMPORTS}\n${${STATIC_ENTRY}_IMPORTS}") + if(${STATIC_ENTRY} STREQUAL "VirtualChannelEntry") + set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_VC") + set(CLIENT_STATIC_ENTRY_INITIALIZER ".csevc") + elseif(${STATIC_ENTRY} STREQUAL "VirtualChannelEntryEx") + set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_VCEX") + set(CLIENT_STATIC_ENTRY_INITIALIZER ".csevcex") + elseif(${STATIC_ENTRY} MATCHES "DVCPluginEntry$") + set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_DVC") + set(CLIENT_STATIC_ENTRY_INITIALIZER ".csedvc") + elseif(${STATIC_ENTRY} MATCHES "DeviceServiceEntry$") + set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY_DSE") + set(CLIENT_STATIC_ENTRY_INITIALIZER ".csedse") + else() + set(CLIENT_STATIC_ENTRY_TYPE "STATIC_ENTRY") + set(CLIENT_STATIC_ENTRY_INITIALIZER ".cse") + endif() + + string(APPEND CLIENT_STATIC_ENTRY_TABLES + "\nextern const ${CLIENT_STATIC_ENTRY_TYPE} CLIENT_${STATIC_ENTRY}_TABLE[];\n" + ) + string(APPEND CLIENT_STATIC_ENTRY_TABLES "const ${CLIENT_STATIC_ENTRY_TYPE} CLIENT_${STATIC_ENTRY}_TABLE[] =\n{") + string(APPEND CLIENT_STATIC_ENTRY_TABLES "\n${${STATIC_ENTRY}_TABLE}") + string(APPEND CLIENT_STATIC_ENTRY_TABLES "\n\t{ NULL, NULL }\n};") + string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST + "\n\t{ \"${STATIC_ENTRY}\", { ${CLIENT_STATIC_ENTRY_INITIALIZER} = CLIENT_${STATIC_ENTRY}_TABLE } }," + ) +endforeach() + +string(APPEND CLIENT_STATIC_ENTRY_TABLES_LIST "\n\t{ NULL, { .cse = NULL } }\n};") + +set(CLIENT_STATIC_ADDIN_TABLE "extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[];\n") +string(APPEND CLIENT_STATIC_ADDIN_TABLE "const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[] =\n{") + +foreach(STATIC_MODULE ${CHANNEL_STATIC_CLIENT_MODULES}) + set(STATIC_MODULE_NAME ${${STATIC_MODULE}_CLIENT_NAME}) + set(STATIC_MODULE_CHANNEL ${${STATIC_MODULE}_CLIENT_CHANNEL}) + string(TOUPPER "CLIENT_${STATIC_MODULE_CHANNEL}_SUBSYSTEM_TABLE" SUBSYSTEM_TABLE_NAME) + set(SUBSYSTEM_TABLE + "extern const STATIC_SUBSYSTEM_ENTRY ${SUBSYSTEM_TABLE_NAME}[];\nconst STATIC_SUBSYSTEM_ENTRY ${SUBSYSTEM_TABLE_NAME}[] =\n{" + ) + get_target_property(CHANNEL_SUBSYSTEMS ${STATIC_MODULE_NAME} SUBSYSTEMS) + if(CHANNEL_SUBSYSTEMS MATCHES "NOTFOUND") + set(CHANNEL_SUBSYSTEMS "") + endif() + foreach(STATIC_SUBSYSTEM ${CHANNEL_SUBSYSTEMS}) + if(${STATIC_SUBSYSTEM} MATCHES "^([^-]*)-(.*)") + string(REGEX REPLACE "^([^-]*)-(.*)" "\\1" STATIC_SUBSYSTEM_NAME ${STATIC_SUBSYSTEM}) + string(REGEX REPLACE "^([^-]*)-(.*)" "\\2" STATIC_SUBSYSTEM_TYPE ${STATIC_SUBSYSTEM}) + else() + set(STATIC_SUBSYSTEM_NAME "${STATIC_SUBSYSTEM}") + set(STATIC_SUBSYSTEM_TYPE "") + endif() + string(LENGTH "${STATIC_SUBSYSTEM_TYPE}" _type_length) + set(SUBSYSTEM_MODULE_NAME "${STATIC_MODULE_NAME}-${STATIC_SUBSYSTEM}") + list(APPEND ${MODULE_PREFIX}_LIBS ${SUBSYSTEM_MODULE_NAME}) + if(_type_length GREATER 0) + set(STATIC_SUBSYSTEM_ENTRY + "${STATIC_SUBSYSTEM_NAME}_freerdp_${STATIC_MODULE_CHANNEL}_client_${STATIC_SUBSYSTEM_TYPE}_subsystem_entry" + ) + else() + set(STATIC_SUBSYSTEM_ENTRY "${STATIC_SUBSYSTEM_NAME}_freerdp_${STATIC_MODULE_CHANNEL}_client_subsystem_entry") + endif() + string(APPEND SUBSYSTEM_TABLE + "\n\t{ \"${STATIC_SUBSYSTEM_NAME}\", \"${STATIC_SUBSYSTEM_TYPE}\", ${STATIC_SUBSYSTEM_ENTRY} }," + ) + set(SUBSYSTEM_IMPORT "extern UINT VCAPITYPE ${STATIC_SUBSYSTEM_ENTRY}(void*);") + string(APPEND CLIENT_STATIC_SUBSYSTEM_IMPORTS "\n${SUBSYSTEM_IMPORT}") + endforeach() + string(APPEND SUBSYSTEM_TABLE "\n\t{ NULL, NULL, NULL }\n};") + string(APPEND CLIENT_STATIC_SUBSYSTEM_TABLES "\n${SUBSYSTEM_TABLE}") + + foreach(ENTRY ${${STATIC_MODULE}_CLIENT_ENTRY}) + set(ENTRY_POINT_NAME ${STATIC_MODULE_CHANNEL}_${ENTRY}) + if(${ENTRY} STREQUAL "VirtualChannelEntry") + set(ENTRY_INITIALIZER ".csevc") + elseif(${ENTRY} STREQUAL "VirtualChannelEntryEx") + set(ENTRY_INITIALIZER ".csevcex") + elseif(${ENTRY} MATCHES "DVCPluginEntry$") + set(ENTRY_INITIALIZER ".csedvc") + elseif(${ENTRY} MATCHES "DeviceServiceEntry$") + set(ENTRY_INITIALIZER ".csedse") + else() + set(ENTRY_INITIALIZER ".cse") + endif() + string( + APPEND + CLIENT_STATIC_ADDIN_TABLE + "\n\t{ \"${STATIC_MODULE_CHANNEL}\", \"${ENTRY}\", { ${ENTRY_INITIALIZER} = ${ENTRY_POINT_NAME} }, ${SUBSYSTEM_TABLE_NAME} }," + ) + endforeach() +endforeach() +string(APPEND CLIENT_STATIC_ADDIN_TABLE "\n\t{ NULL, NULL, { .cse = NULL }, NULL }\n};") + +cleaning_configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tables.c.in ${CMAKE_CURRENT_BINARY_DIR}/tables.c) + +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp winpr) + +set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} PARENT_SCOPE) +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.c b/local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.c new file mode 100644 index 0000000000000000000000000000000000000000..ee354d61f4e7e62da8e29d1ef1ff712deebb3e55 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.c @@ -0,0 +1,761 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Channel Addins + * + * Copyright 2012 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tables.h" + +#include "addin.h" + +#include +#define TAG CHANNELS_TAG("addin") + +extern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[]; + +static void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABLE* table, + const char* identifier) +{ + size_t index = 0; + const STATIC_ENTRY* pEntry = &table->table.cse[index++]; + + while (pEntry->entry != NULL) + { + static_entry_fn_t fkt = pEntry->entry; + if (strcmp(pEntry->name, identifier) == 0) + return WINPR_FUNC_PTR_CAST(fkt, void*); + + pEntry = &table->table.cse[index++]; + } + + return NULL; +} + +void* freerdp_channels_client_find_static_entry(const char* name, const char* identifier) +{ + size_t index = 0; + const STATIC_ENTRY_TABLE* pEntry = &CLIENT_STATIC_ENTRY_TABLES[index++]; + + while (pEntry->table.cse != NULL) + { + if (strcmp(pEntry->name, name) == 0) + { + return freerdp_channels_find_static_entry_in_table(pEntry, identifier); + } + + pEntry = &CLIENT_STATIC_ENTRY_TABLES[index++]; + } + + return NULL; +} + +extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[]; + +static FREERDP_ADDIN** freerdp_channels_list_client_static_addins(LPCSTR pszName, + LPCSTR pszSubsystem, + LPCSTR pszType, DWORD dwFlags) +{ + DWORD nAddins = 0; + FREERDP_ADDIN** ppAddins = NULL; + const STATIC_SUBSYSTEM_ENTRY* subsystems = NULL; + nAddins = 0; + ppAddins = (FREERDP_ADDIN**)calloc(128, sizeof(FREERDP_ADDIN*)); + + if (!ppAddins) + { + WLog_ERR(TAG, "calloc failed!"); + return NULL; + } + + ppAddins[nAddins] = NULL; + + for (size_t i = 0; CLIENT_STATIC_ADDIN_TABLE[i].name != NULL; i++) + { + FREERDP_ADDIN* pAddin = (FREERDP_ADDIN*)calloc(1, sizeof(FREERDP_ADDIN)); + const STATIC_ADDIN_TABLE* table = &CLIENT_STATIC_ADDIN_TABLE[i]; + if (!pAddin) + { + WLog_ERR(TAG, "calloc failed!"); + goto error_out; + } + + (void)sprintf_s(pAddin->cName, ARRAYSIZE(pAddin->cName), "%s", table->name); + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_STATIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + ppAddins[nAddins++] = pAddin; + subsystems = table->table; + + for (size_t j = 0; subsystems[j].name != NULL; j++) + { + pAddin = (FREERDP_ADDIN*)calloc(1, sizeof(FREERDP_ADDIN)); + + if (!pAddin) + { + WLog_ERR(TAG, "calloc failed!"); + goto error_out; + } + + (void)sprintf_s(pAddin->cName, ARRAYSIZE(pAddin->cName), "%s", table->name); + (void)sprintf_s(pAddin->cSubsystem, ARRAYSIZE(pAddin->cSubsystem), "%s", + subsystems[j].name); + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_STATIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; + ppAddins[nAddins++] = pAddin; + } + } + + return ppAddins; +error_out: + freerdp_channels_addin_list_free(ppAddins); + return NULL; +} + +static HANDLE FindFirstFileUTF8(LPCSTR pszSearchPath, WIN32_FIND_DATAW* FindData) +{ + HANDLE hdl = INVALID_HANDLE_VALUE; + if (!pszSearchPath) + return hdl; + WCHAR* wpath = ConvertUtf8ToWCharAlloc(pszSearchPath, NULL); + if (!wpath) + return hdl; + + hdl = FindFirstFileW(wpath, FindData); + free(wpath); + + return hdl; +} + +static FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPCSTR pszName, LPCSTR pszSubsystem, + LPCSTR pszType, DWORD dwFlags) +{ + int nDashes = 0; + HANDLE hFind = NULL; + DWORD nAddins = 0; + LPSTR pszPattern = NULL; + size_t cchPattern = 0; + LPCSTR pszAddinPath = FREERDP_ADDIN_PATH; + LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX; + LPCSTR pszExtension = NULL; + LPSTR pszSearchPath = NULL; + size_t cchSearchPath = 0; + size_t cchAddinPath = 0; + size_t cchInstallPrefix = 0; + FREERDP_ADDIN** ppAddins = NULL; + WIN32_FIND_DATAW FindData = { 0 }; + cchAddinPath = strnlen(pszAddinPath, sizeof(FREERDP_ADDIN_PATH)); + cchInstallPrefix = strnlen(pszInstallPrefix, sizeof(FREERDP_INSTALL_PREFIX)); + pszExtension = PathGetSharedLibraryExtensionA(0); + cchPattern = 128 + strnlen(pszExtension, MAX_PATH) + 2; + pszPattern = (LPSTR)malloc(cchPattern + 1); + + if (!pszPattern) + { + WLog_ERR(TAG, "malloc failed!"); + return NULL; + } + + if (pszName && pszSubsystem && pszType) + { + (void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "%s-client-%s-%s.%s", + pszName, pszSubsystem, pszType, pszExtension); + } + else if (pszName && pszType) + { + (void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "%s-client-?-%s.%s", + pszName, pszType, pszExtension); + } + else if (pszName) + { + (void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "%s-client*.%s", + pszName, pszExtension); + } + else + { + (void)sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX "?-client*.%s", + pszExtension); + } + + cchPattern = strnlen(pszPattern, cchPattern); + cchSearchPath = cchInstallPrefix + cchAddinPath + cchPattern + 3; + pszSearchPath = (LPSTR)calloc(cchSearchPath + 1, sizeof(char)); + + if (!pszSearchPath) + { + WLog_ERR(TAG, "malloc failed!"); + free(pszPattern); + return NULL; + } + + CopyMemory(pszSearchPath, pszInstallPrefix, cchInstallPrefix); + pszSearchPath[cchInstallPrefix] = '\0'; + const HRESULT hr1 = NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszAddinPath); + const HRESULT hr2 = NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszPattern); + free(pszPattern); + + if (FAILED(hr1) || FAILED(hr2)) + { + free(pszSearchPath); + return NULL; + } + + hFind = FindFirstFileUTF8(pszSearchPath, &FindData); + + free(pszSearchPath); + nAddins = 0; + ppAddins = (FREERDP_ADDIN**)calloc(128, sizeof(FREERDP_ADDIN*)); + + if (!ppAddins) + { + FindClose(hFind); + WLog_ERR(TAG, "calloc failed!"); + return NULL; + } + + if (hFind == INVALID_HANDLE_VALUE) + return ppAddins; + + do + { + char* cFileName = NULL; + BOOL used = FALSE; + FREERDP_ADDIN* pAddin = (FREERDP_ADDIN*)calloc(1, sizeof(FREERDP_ADDIN)); + + if (!pAddin) + { + WLog_ERR(TAG, "calloc failed!"); + goto error_out; + } + + cFileName = + ConvertWCharNToUtf8Alloc(FindData.cFileName, ARRAYSIZE(FindData.cFileName), NULL); + if (!cFileName) + goto skip; + + nDashes = 0; + for (size_t index = 0; cFileName[index]; index++) + nDashes += (cFileName[index] == '-') ? 1 : 0; + + if (nDashes == 1) + { + size_t len = 0; + char* p[2] = { 0 }; + /* -client. */ + p[0] = cFileName; + p[1] = strchr(p[0], '-'); + if (!p[1]) + goto skip; + p[1] += 1; + + len = (size_t)(p[1] - p[0]); + if (len < 1) + { + WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName); + goto skip; + } + strncpy(pAddin->cName, p[0], MIN(ARRAYSIZE(pAddin->cName), len - 1)); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + ppAddins[nAddins++] = pAddin; + + used = TRUE; + } + else if (nDashes == 2) + { + size_t len = 0; + char* p[4] = { 0 }; + /* -client-. */ + p[0] = cFileName; + p[1] = strchr(p[0], '-'); + if (!p[1]) + goto skip; + p[1] += 1; + p[2] = strchr(p[1], '-'); + if (!p[2]) + goto skip; + p[2] += 1; + p[3] = strchr(p[2], '.'); + if (!p[3]) + goto skip; + p[3] += 1; + + len = (size_t)(p[1] - p[0]); + if (len < 1) + { + WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName); + goto skip; + } + strncpy(pAddin->cName, p[0], MIN(ARRAYSIZE(pAddin->cName), len - 1)); + + len = (size_t)(p[3] - p[2]); + if (len < 1) + { + WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName); + goto skip; + } + strncpy(pAddin->cSubsystem, p[2], MIN(ARRAYSIZE(pAddin->cSubsystem), len - 1)); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; + ppAddins[nAddins++] = pAddin; + + used = TRUE; + } + else if (nDashes == 3) + { + size_t len = 0; + char* p[5] = { 0 }; + /* -client--. */ + p[0] = cFileName; + p[1] = strchr(p[0], '-'); + if (!p[1]) + goto skip; + p[1] += 1; + p[2] = strchr(p[1], '-'); + if (!p[2]) + goto skip; + p[2] += 1; + p[3] = strchr(p[2], '-'); + if (!p[3]) + goto skip; + p[3] += 1; + p[4] = strchr(p[3], '.'); + if (!p[4]) + goto skip; + p[4] += 1; + + len = (size_t)(p[1] - p[0]); + if (len < 1) + { + WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName); + goto skip; + } + strncpy(pAddin->cName, p[0], MIN(ARRAYSIZE(pAddin->cName), len - 1)); + + len = (size_t)(p[3] - p[2]); + if (len < 1) + { + WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName); + goto skip; + } + strncpy(pAddin->cSubsystem, p[2], MIN(ARRAYSIZE(pAddin->cSubsystem), len - 1)); + + len = (size_t)(p[4] - p[3]); + if (len < 1) + { + WLog_WARN(TAG, "Skipping file '%s', invalid format", cFileName); + goto skip; + } + strncpy(pAddin->cType, p[3], MIN(ARRAYSIZE(pAddin->cType), len - 1)); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; + pAddin->dwFlags |= FREERDP_ADDIN_TYPE; + ppAddins[nAddins++] = pAddin; + + used = TRUE; + } + + skip: + free(cFileName); + if (!used) + free(pAddin); + + } while (FindNextFileW(hFind, &FindData)); + + FindClose(hFind); + ppAddins[nAddins] = NULL; + return ppAddins; +error_out: + FindClose(hFind); + freerdp_channels_addin_list_free(ppAddins); + return NULL; +} + +FREERDP_ADDIN** freerdp_channels_list_addins(LPCSTR pszName, LPCSTR pszSubsystem, LPCSTR pszType, + DWORD dwFlags) +{ + if (dwFlags & FREERDP_ADDIN_STATIC) + return freerdp_channels_list_client_static_addins(pszName, pszSubsystem, pszType, dwFlags); + else if (dwFlags & FREERDP_ADDIN_DYNAMIC) + return freerdp_channels_list_dynamic_addins(pszName, pszSubsystem, pszType, dwFlags); + + return NULL; +} + +void freerdp_channels_addin_list_free(FREERDP_ADDIN** ppAddins) +{ + if (!ppAddins) + return; + + for (size_t index = 0; ppAddins[index] != NULL; index++) + free(ppAddins[index]); + + free((void*)ppAddins); +} + +extern const STATIC_ENTRY CLIENT_VirtualChannelEntryEx_TABLE[]; + +static BOOL freerdp_channels_is_virtual_channel_entry_ex(LPCSTR pszName) +{ + for (size_t i = 0; CLIENT_VirtualChannelEntryEx_TABLE[i].name != NULL; i++) + { + const STATIC_ENTRY* entry = &CLIENT_VirtualChannelEntryEx_TABLE[i]; + + if (!strncmp(entry->name, pszName, MAX_PATH)) + return TRUE; + } + + return FALSE; +} + +PVIRTUALCHANNELENTRY freerdp_channels_load_static_addin_entry(LPCSTR pszName, LPCSTR pszSubsystem, + LPCSTR pszType, DWORD dwFlags) +{ + const STATIC_ADDIN_TABLE* table = CLIENT_STATIC_ADDIN_TABLE; + const char* type = NULL; + + if (!pszName) + return NULL; + + if (dwFlags & FREERDP_ADDIN_CHANNEL_DYNAMIC) + type = "DVCPluginEntry"; + else if (dwFlags & FREERDP_ADDIN_CHANNEL_DEVICE) + type = "DeviceServiceEntry"; + else if (dwFlags & FREERDP_ADDIN_CHANNEL_STATIC) + { + if (dwFlags & FREERDP_ADDIN_CHANNEL_ENTRYEX) + type = "VirtualChannelEntryEx"; + else + type = "VirtualChannelEntry"; + } + + for (; table->name != NULL; table++) + { + if (strncmp(table->name, pszName, MAX_PATH) == 0) + { + if (type && (strncmp(table->type, type, MAX_PATH) != 0)) + continue; + + if (pszSubsystem != NULL) + { + const STATIC_SUBSYSTEM_ENTRY* subsystems = table->table; + + for (; subsystems->name != NULL; subsystems++) + { + /* If the pszSubsystem is an empty string use the default backend. */ + if ((strnlen(pszSubsystem, 1) == + 0) || /* we only want to know if strnlen is > 0 */ + (strncmp(subsystems->name, pszSubsystem, MAX_PATH) == 0)) + { + static_subsystem_entry_fn_t fkt = subsystems->entry; + + if (pszType) + { + if (strncmp(subsystems->type, pszType, MAX_PATH) == 0) + return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY); + } + else + return WINPR_FUNC_PTR_CAST(fkt, PVIRTUALCHANNELENTRY); + } + } + } + else + { + if (dwFlags & FREERDP_ADDIN_CHANNEL_ENTRYEX) + { + if (!freerdp_channels_is_virtual_channel_entry_ex(pszName)) + return NULL; + } + + return table->entry.csevc; + } + } + } + + return NULL; +} + +typedef struct +{ + wMessageQueue* queue; + wStream* data_in; + HANDLE thread; + char* channel_name; + rdpContext* ctx; + LPVOID userdata; + MsgHandler msg_handler; +} msg_proc_internals; + +static DWORD WINAPI channel_client_thread_proc(LPVOID userdata) +{ + UINT error = CHANNEL_RC_OK; + wStream* data = NULL; + wMessage message = { 0 }; + msg_proc_internals* internals = userdata; + + WINPR_ASSERT(internals); + + while (1) + { + if (!MessageQueue_Wait(internals->queue)) + { + WLog_ERR(TAG, "MessageQueue_Wait failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + if (!MessageQueue_Peek(internals->queue, &message, TRUE)) + { + WLog_ERR(TAG, "MessageQueue_Peek failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (message.id == WMQ_QUIT) + break; + + if (message.id == 0) + { + data = (wStream*)message.wParam; + + if ((error = internals->msg_handler(internals->userdata, data))) + { + WLog_ERR(TAG, "msg_handler failed with error %" PRIu32 "!", error); + break; + } + } + } + if (error && internals->ctx) + { + char msg[128]; + (void)_snprintf(msg, 127, + "%s_virtual_channel_client_thread reported an" + " error", + internals->channel_name); + setChannelError(internals->ctx, error, msg); + } + ExitThread(error); + return error; +} + +static void free_msg(void* obj) +{ + wMessage* msg = (wMessage*)obj; + + if (msg && (msg->id == 0)) + { + wStream* s = (wStream*)msg->wParam; + Stream_Free(s, TRUE); + } +} + +static void channel_client_handler_free(msg_proc_internals* internals) +{ + if (!internals) + return; + + if (internals->thread) + (void)CloseHandle(internals->thread); + MessageQueue_Free(internals->queue); + Stream_Free(internals->data_in, TRUE); + free(internals->channel_name); + free(internals); +} + +/* Create message queue and thread or not, depending on settings */ +void* channel_client_create_handler(rdpContext* ctx, LPVOID userdata, MsgHandler msg_handler, + const char* channel_name) +{ + msg_proc_internals* internals = calloc(1, sizeof(msg_proc_internals)); + if (!internals) + { + WLog_ERR(TAG, "calloc failed!"); + return NULL; + } + internals->msg_handler = msg_handler; + internals->userdata = userdata; + if (channel_name) + { + internals->channel_name = _strdup(channel_name); + if (!internals->channel_name) + goto fail; + } + WINPR_ASSERT(ctx); + WINPR_ASSERT(ctx->settings); + internals->ctx = ctx; + if ((freerdp_settings_get_uint32(ctx->settings, FreeRDP_ThreadingFlags) & + THREADING_FLAGS_DISABLE_THREADS) == 0) + { + wObject obj = { 0 }; + obj.fnObjectFree = free_msg; + internals->queue = MessageQueue_New(&obj); + if (!internals->queue) + { + WLog_ERR(TAG, "MessageQueue_New failed!"); + goto fail; + } + + if (!(internals->thread = + CreateThread(NULL, 0, channel_client_thread_proc, (void*)internals, 0, NULL))) + { + WLog_ERR(TAG, "CreateThread failed!"); + goto fail; + } + } + return internals; + +fail: + channel_client_handler_free(internals); + return NULL; +} +/* post a message in the queue or directly call the processing handler */ +UINT channel_client_post_message(void* MsgsHandle, LPVOID pData, UINT32 dataLength, + UINT32 totalLength, UINT32 dataFlags) +{ + msg_proc_internals* internals = MsgsHandle; + wStream* data_in = NULL; + + if (!internals) + { + /* TODO: return some error here */ + return CHANNEL_RC_OK; + } + + if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) + { + return CHANNEL_RC_OK; + } + + if (dataFlags & CHANNEL_FLAG_FIRST) + { + if (internals->data_in) + { + if (!Stream_EnsureCapacity(internals->data_in, totalLength)) + return CHANNEL_RC_NO_MEMORY; + } + else + internals->data_in = Stream_New(NULL, totalLength); + } + + if (!(data_in = internals->data_in)) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if (!Stream_EnsureRemainingCapacity(data_in, dataLength)) + { + Stream_Free(internals->data_in, TRUE); + internals->data_in = NULL; + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write(data_in, pData, dataLength); + + if (dataFlags & CHANNEL_FLAG_LAST) + { + if (Stream_Capacity(data_in) != Stream_GetPosition(data_in)) + { + char msg[128]; + (void)_snprintf(msg, 127, "%s_plugin_process_received: read error", + internals->channel_name); + WLog_ERR(TAG, msg); + return ERROR_INTERNAL_ERROR; + } + + internals->data_in = NULL; + Stream_SealLength(data_in); + Stream_SetPosition(data_in, 0); + + if ((freerdp_settings_get_uint32(internals->ctx->settings, FreeRDP_ThreadingFlags) & + THREADING_FLAGS_DISABLE_THREADS) != 0) + { + UINT error = CHANNEL_RC_OK; + if ((error = internals->msg_handler(internals->userdata, data_in))) + { + WLog_ERR(TAG, + "msg_handler failed with error" + " %" PRIu32 "!", + error); + return ERROR_INTERNAL_ERROR; + } + } + else if (!MessageQueue_Post(internals->queue, NULL, 0, (void*)data_in, NULL)) + { + WLog_ERR(TAG, "MessageQueue_Post failed!"); + return ERROR_INTERNAL_ERROR; + } + } + return CHANNEL_RC_OK; +} +/* Tear down queue and thread */ +UINT channel_client_quit_handler(void* MsgsHandle) +{ + msg_proc_internals* internals = MsgsHandle; + UINT rc = 0; + if (!internals) + { + /* TODO: return some error here */ + return CHANNEL_RC_OK; + } + + WINPR_ASSERT(internals->ctx); + WINPR_ASSERT(internals->ctx->settings); + + if ((freerdp_settings_get_uint32(internals->ctx->settings, FreeRDP_ThreadingFlags) & + THREADING_FLAGS_DISABLE_THREADS) == 0) + { + if (internals->queue && internals->thread) + { + if (MessageQueue_PostQuit(internals->queue, 0) && + (WaitForSingleObject(internals->thread, INFINITE) == WAIT_FAILED)) + { + rc = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", rc); + return rc; + } + } + } + + channel_client_handler_free(internals); + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.h b/local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.h new file mode 100644 index 0000000000000000000000000000000000000000..1b794e737878b31419618acd76215db3c8ddc421 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/client/addin.h @@ -0,0 +1,28 @@ +/* + * FreeRDP: A Remote Desktop Protocol Implementation + * Channel Addins + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +typedef UINT (*MsgHandler)(LPVOID userdata, wStream* data); + +FREERDP_API void* channel_client_create_handler(rdpContext* ctx, LPVOID userdata, + MsgHandler handler, const char* channel_name); + +UINT channel_client_post_message(void* MsgsHandle, LPVOID pData, UINT32 dataLength, + UINT32 totalLength, UINT32 dataFlags); + +UINT channel_client_quit_handler(void* MsgsHandle); diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/client/generic_dynvc.c b/local-test-freerdp-delta-01/afc-freerdp/channels/client/generic_dynvc.c new file mode 100644 index 0000000000000000000000000000000000000000..6221470c413167fe0cdaf69a87ea65c2f30cb953 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/client/generic_dynvc.c @@ -0,0 +1,214 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic channel + * + * Copyright 2022 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#define TAG FREERDP_TAG("genericdynvc") + +static UINT generic_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, + IWTSVirtualChannel* pChannel, BYTE* Data, + BOOL* pbAccept, + IWTSVirtualChannelCallback** ppCallback) +{ + GENERIC_CHANNEL_CALLBACK* callback = NULL; + GENERIC_DYNVC_PLUGIN* plugin = NULL; + GENERIC_LISTENER_CALLBACK* listener_callback = (GENERIC_LISTENER_CALLBACK*)pListenerCallback; + + if (!listener_callback || !listener_callback->plugin) + return ERROR_INTERNAL_ERROR; + + plugin = (GENERIC_DYNVC_PLUGIN*)listener_callback->plugin; + WLog_Print(plugin->log, WLOG_TRACE, "..."); + + callback = (GENERIC_CHANNEL_CALLBACK*)calloc(1, plugin->channelCallbackSize); + if (!callback) + { + WLog_Print(plugin->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + /* implant configured channel callbacks */ + callback->iface = *plugin->channel_callbacks; + + callback->plugin = listener_callback->plugin; + callback->channel_mgr = listener_callback->channel_mgr; + callback->channel = pChannel; + + listener_callback->channel_callback = callback; + listener_callback->channel = pChannel; + + *ppCallback = (IWTSVirtualChannelCallback*)callback; + return CHANNEL_RC_OK; +} + +static UINT generic_dynvc_plugin_initialize(IWTSPlugin* pPlugin, + IWTSVirtualChannelManager* pChannelMgr) +{ + UINT rc = 0; + GENERIC_LISTENER_CALLBACK* listener_callback = NULL; + GENERIC_DYNVC_PLUGIN* plugin = (GENERIC_DYNVC_PLUGIN*)pPlugin; + + if (!plugin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + if (!pChannelMgr) + return ERROR_INVALID_PARAMETER; + + if (plugin->initialized) + { + WLog_ERR(TAG, "[%s] channel initialized twice, aborting", plugin->dynvc_name); + return ERROR_INVALID_DATA; + } + + WLog_Print(plugin->log, WLOG_TRACE, "..."); + listener_callback = (GENERIC_LISTENER_CALLBACK*)calloc(1, sizeof(GENERIC_LISTENER_CALLBACK)); + if (!listener_callback) + { + WLog_Print(plugin->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + plugin->listener_callback = listener_callback; + listener_callback->iface.OnNewChannelConnection = generic_on_new_channel_connection; + listener_callback->plugin = pPlugin; + listener_callback->channel_mgr = pChannelMgr; + rc = pChannelMgr->CreateListener(pChannelMgr, plugin->dynvc_name, 0, &listener_callback->iface, + &plugin->listener); + + plugin->listener->pInterface = plugin->iface.pInterface; + plugin->initialized = (rc == CHANNEL_RC_OK); + return rc; +} + +static UINT generic_plugin_terminated(IWTSPlugin* pPlugin) +{ + GENERIC_DYNVC_PLUGIN* plugin = (GENERIC_DYNVC_PLUGIN*)pPlugin; + UINT error = CHANNEL_RC_OK; + + if (!plugin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + WLog_Print(plugin->log, WLOG_TRACE, "..."); + + /* some channels (namely rdpei), look at initialized to see if they should continue to run */ + plugin->initialized = FALSE; + + if (plugin->terminatePluginFn) + plugin->terminatePluginFn(plugin); + + if (plugin->listener_callback) + { + IWTSVirtualChannelManager* mgr = plugin->listener_callback->channel_mgr; + if (mgr) + IFCALL(mgr->DestroyListener, mgr, plugin->listener); + } + + free(plugin->listener_callback); + free(plugin->dynvc_name); + free(plugin); + return error; +} + +static UINT generic_dynvc_plugin_attached(IWTSPlugin* pPlugin) +{ + GENERIC_DYNVC_PLUGIN* pluginn = (GENERIC_DYNVC_PLUGIN*)pPlugin; + UINT error = CHANNEL_RC_OK; + + if (!pluginn) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + pluginn->attached = TRUE; + return error; +} + +static UINT generic_dynvc_plugin_detached(IWTSPlugin* pPlugin) +{ + GENERIC_DYNVC_PLUGIN* plugin = (GENERIC_DYNVC_PLUGIN*)pPlugin; + UINT error = CHANNEL_RC_OK; + + if (!plugin) + return CHANNEL_RC_BAD_CHANNEL_HANDLE; + + plugin->attached = FALSE; + return error; +} + +UINT freerdp_generic_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* logTag, + const char* name, size_t pluginSize, size_t channelCallbackSize, + const IWTSVirtualChannelCallback* channel_callbacks, + DYNVC_PLUGIN_INIT_FN initPluginFn, + DYNVC_PLUGIN_TERMINATE_FN terminatePluginFn) +{ + GENERIC_DYNVC_PLUGIN* plugin = NULL; + UINT error = CHANNEL_RC_INITIALIZATION_ERROR; + + WINPR_ASSERT(pEntryPoints); + WINPR_ASSERT(pEntryPoints->GetPlugin); + WINPR_ASSERT(logTag); + WINPR_ASSERT(name); + WINPR_ASSERT(pluginSize >= sizeof(*plugin)); + WINPR_ASSERT(channelCallbackSize >= sizeof(GENERIC_CHANNEL_CALLBACK)); + + plugin = (GENERIC_DYNVC_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, name); + if (plugin != NULL) + return CHANNEL_RC_ALREADY_INITIALIZED; + + plugin = (GENERIC_DYNVC_PLUGIN*)calloc(1, pluginSize); + if (!plugin) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + plugin->log = WLog_Get(logTag); + plugin->attached = TRUE; + plugin->channel_callbacks = channel_callbacks; + plugin->channelCallbackSize = channelCallbackSize; + plugin->iface.Initialize = generic_dynvc_plugin_initialize; + plugin->iface.Connected = NULL; + plugin->iface.Disconnected = NULL; + plugin->iface.Terminated = generic_plugin_terminated; + plugin->iface.Attached = generic_dynvc_plugin_attached; + plugin->iface.Detached = generic_dynvc_plugin_detached; + plugin->terminatePluginFn = terminatePluginFn; + + if (initPluginFn) + { + rdpSettings* settings = pEntryPoints->GetRdpSettings(pEntryPoints); + rdpContext* context = pEntryPoints->GetRdpContext(pEntryPoints); + + error = initPluginFn(plugin, context, settings); + if (error != CHANNEL_RC_OK) + goto error; + } + + plugin->dynvc_name = _strdup(name); + if (!plugin->dynvc_name) + goto error; + + error = pEntryPoints->RegisterPlugin(pEntryPoints, name, &plugin->iface); + if (error == CHANNEL_RC_OK) + return error; + +error: + generic_plugin_terminated(&plugin->iface); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.c.in b/local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.c.in new file mode 100644 index 0000000000000000000000000000000000000000..2c34a30eebc8bb3f01a133a7230d73f19393ae74 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.c.in @@ -0,0 +1,33 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Static Entry Point Tables + * + * Copyright 2012 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include "tables.h" + +${CLIENT_STATIC_TYPEDEFS} +${CLIENT_STATIC_ENTRY_IMPORTS} +${CLIENT_STATIC_SUBSYSTEM_IMPORTS} +${CLIENT_STATIC_ENTRY_TABLES} +${CLIENT_STATIC_ENTRY_TABLES_LIST} +${CLIENT_STATIC_SUBSYSTEM_TABLES} +${CLIENT_STATIC_ADDIN_TABLE} + diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.h b/local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.h new file mode 100644 index 0000000000000000000000000000000000000000..bbb16a76373f1efbaad647c319699119575f47b2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/client/tables.h @@ -0,0 +1,105 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Static Entry Point Tables + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +/* The 'entry' function pointers have variable arguments. */ +WINPR_PRAGMA_DIAG_PUSH +WINPR_PRAGMA_DIAG_IGNORED_STRICT_PROTOTYPES + +typedef UINT(VCAPITYPE* static_entry_fn_t)(); +typedef struct +{ + const char* name; + static_entry_fn_t entry; +} STATIC_ENTRY; + +typedef BOOL(VCAPITYPE* static_entry_vc_fn_t)(PCHANNEL_ENTRY_POINTS); +typedef struct +{ + const char* name; + static_entry_vc_fn_t entry; +} STATIC_ENTRY_VC; + +typedef BOOL(VCAPITYPE* static_entry_vcex_fn_t)(PCHANNEL_ENTRY_POINTS, PVOID); +typedef struct +{ + const char* name; + static_entry_vcex_fn_t entry; +} STATIC_ENTRY_VCEX; + +typedef UINT(VCAPITYPE* static_entry_dvc_fn_t)(IDRDYNVC_ENTRY_POINTS*); +typedef struct +{ + const char* name; + static_entry_dvc_fn_t entry; +} STATIC_ENTRY_DVC; + +typedef UINT(VCAPITYPE* static_entry_dse_fn_t)(PDEVICE_SERVICE_ENTRY_POINTS); +typedef struct +{ + const char* name; + static_entry_dse_fn_t entry; +} STATIC_ENTRY_DSE; + +typedef union +{ + const STATIC_ENTRY* cse; + const STATIC_ENTRY_VC* csevc; + const STATIC_ENTRY_VCEX* csevcex; + const STATIC_ENTRY_DVC* csedvc; + const STATIC_ENTRY_DSE* csedse; +} static_entry_u; + +typedef union +{ + static_entry_fn_t cse; + static_entry_vc_fn_t csevc; + static_entry_vcex_fn_t csevcex; + static_entry_dvc_fn_t csedvc; + static_entry_dse_fn_t csedse; +} static_entry_fn_u; + +typedef struct +{ + const char* name; + static_entry_u table; +} STATIC_ENTRY_TABLE; + +typedef UINT(VCAPITYPE* static_subsystem_entry_fn_t)(void*); +typedef struct +{ + const char* name; + const char* type; + static_subsystem_entry_fn_t entry; +} STATIC_SUBSYSTEM_ENTRY; + +typedef struct +{ + const char* name; + const char* type; + static_entry_fn_u entry; + const STATIC_SUBSYSTEM_ENTRY* table; +} STATIC_ADDIN_TABLE; + +WINPR_PRAGMA_DIAG_POP diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb9addd524ad3b031f7f031c816fd910a477c5b6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("cliprdr") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..0787c08eb5b4914b480daa9cb6b5dbef4bc05ec3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "cliprdr" + TYPE + "static" + DESCRIPTION + "Clipboard Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPECLIP]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..956620d413d9c0a53dfbae4f23e41d96c507dfc7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/CMakeLists.txt @@ -0,0 +1,25 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("cliprdr") + +set(${MODULE_PREFIX}_SRCS cliprdr_format.c cliprdr_format.h cliprdr_main.c cliprdr_main.h ../cliprdr_common.h + ../cliprdr_common.c +) + +set(${MODULE_PREFIX}_LIBS winpr freerdp) +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntryEx") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.c b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.c new file mode 100644 index 0000000000000000000000000000000000000000..41978d988783b1a45cdd768e050831593a46ac81 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.c @@ -0,0 +1,244 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "cliprdr_main.h" +#include "cliprdr_format.h" +#include "../cliprdr_common.h" + +CLIPRDR_FORMAT_LIST cliprdr_filter_format_list(const CLIPRDR_FORMAT_LIST* list, const UINT32 mask, + const UINT32 checkMask) +{ + const UINT32 maskData = + checkMask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_REMOTE_TO_LOCAL); + const UINT32 maskFiles = + checkMask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES); + WINPR_ASSERT(list); + + CLIPRDR_FORMAT_LIST filtered = { 0 }; + filtered.common.msgType = CB_FORMAT_LIST; + filtered.numFormats = list->numFormats; + filtered.formats = calloc(filtered.numFormats, sizeof(CLIPRDR_FORMAT)); + + size_t wpos = 0; + if ((mask & checkMask) == checkMask) + { + for (size_t x = 0; x < list->numFormats; x++) + { + const CLIPRDR_FORMAT* format = &list->formats[x]; + CLIPRDR_FORMAT* cur = &filtered.formats[x]; + cur->formatId = format->formatId; + if (format->formatName) + cur->formatName = _strdup(format->formatName); + wpos++; + } + } + else if ((mask & maskFiles) != 0) + { + for (size_t x = 0; x < list->numFormats; x++) + { + const CLIPRDR_FORMAT* format = &list->formats[x]; + CLIPRDR_FORMAT* cur = &filtered.formats[wpos]; + + if (!format->formatName) + continue; + if (strcmp(format->formatName, type_FileGroupDescriptorW) == 0 || + strcmp(format->formatName, type_FileContents) == 0) + { + cur->formatId = format->formatId; + cur->formatName = _strdup(format->formatName); + wpos++; + } + } + } + else if ((mask & maskData) != 0) + { + for (size_t x = 0; x < list->numFormats; x++) + { + const CLIPRDR_FORMAT* format = &list->formats[x]; + CLIPRDR_FORMAT* cur = &filtered.formats[wpos]; + + if (!format->formatName || + (strcmp(format->formatName, type_FileGroupDescriptorW) != 0 && + strcmp(format->formatName, type_FileContents) != 0)) + { + cur->formatId = format->formatId; + if (format->formatName) + cur->formatName = _strdup(format->formatName); + wpos++; + } + } + } + WINPR_ASSERT(wpos <= UINT32_MAX); + filtered.numFormats = (UINT32)wpos; + return filtered; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT cliprdr_process_format_list(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags) +{ + CLIPRDR_FORMAT_LIST formatList = { 0 }; + CLIPRDR_FORMAT_LIST filteredFormatList = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + formatList.common.msgType = CB_FORMAT_LIST; + formatList.common.msgFlags = msgFlags; + formatList.common.dataLen = dataLen; + + if ((error = cliprdr_read_format_list(s, &formatList, cliprdr->useLongFormatNames))) + goto error_out; + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + filteredFormatList = cliprdr_filter_format_list( + &formatList, mask, CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES); + if (filteredFormatList.numFormats == 0) + goto error_out; + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatList: numFormats: %" PRIu32 "", + filteredFormatList.numFormats); + + if (context->ServerFormatList) + { + if ((error = context->ServerFormatList(context, &filteredFormatList))) + WLog_ERR(TAG, "ServerFormatList failed with error %" PRIu32 "", error); + } + +error_out: + cliprdr_free_format_list(&filteredFormatList); + cliprdr_free_format_list(&formatList); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags) +{ + CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatListResponse"); + + formatListResponse.common.msgType = CB_FORMAT_LIST_RESPONSE; + formatListResponse.common.msgFlags = msgFlags; + formatListResponse.common.dataLen = dataLen; + + IFCALLRET(context->ServerFormatListResponse, error, context, &formatListResponse); + if (error) + WLog_ERR(TAG, "ServerFormatListResponse failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags) +{ + CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatDataRequest"); + + formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST; + formatDataRequest.common.msgFlags = msgFlags; + formatDataRequest.common.dataLen = dataLen; + + if ((error = cliprdr_read_format_data_request(s, &formatDataRequest))) + return error; + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + if ((mask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) == 0) + { + return cliprdr_send_error_response(cliprdr, CB_FORMAT_DATA_RESPONSE); + } + + context->lastRequestedFormatId = formatDataRequest.requestedFormatId; + IFCALLRET(context->ServerFormatDataRequest, error, context, &formatDataRequest); + if (error) + WLog_ERR(TAG, "ServerFormatDataRequest failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags) +{ + CLIPRDR_FORMAT_DATA_RESPONSE formatDataResponse = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerFormatDataResponse"); + + formatDataResponse.common.msgType = CB_FORMAT_DATA_RESPONSE; + formatDataResponse.common.msgFlags = msgFlags; + formatDataResponse.common.dataLen = dataLen; + + if ((error = cliprdr_read_format_data_response(s, &formatDataResponse))) + return error; + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0) + { + WLog_WARN(TAG, + "Received ServerFormatDataResponse but remote -> local clipboard is disabled"); + return CHANNEL_RC_OK; + } + + IFCALLRET(context->ServerFormatDataResponse, error, context, &formatDataResponse); + if (error) + WLog_ERR(TAG, "ServerFormatDataResponse failed with error %" PRIu32 "!", error); + + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.h b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.h new file mode 100644 index 0000000000000000000000000000000000000000..a3ba1ed1bb755f3a4a76a182282047a6e30125d8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_format.h @@ -0,0 +1,37 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CLIPRDR_CLIENT_FORMAT_H +#define FREERDP_CHANNEL_CLIPRDR_CLIENT_FORMAT_H + +UINT cliprdr_process_format_list(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags); +UINT cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags); +UINT cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags); +UINT cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, + UINT16 msgFlags); +CLIPRDR_FORMAT_LIST cliprdr_filter_format_list(const CLIPRDR_FORMAT_LIST* list, const UINT32 mask, + const UINT32 checkMask); + +#endif /* FREERDP_CHANNEL_CLIPRDR_CLIENT_FORMAT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.c new file mode 100644 index 0000000000000000000000000000000000000000..f0476fc9994f0f6bcf34c55008a394a71ce5be17 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.c @@ -0,0 +1,1174 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "../../../channels/client/addin.h" + +#include "cliprdr_main.h" +#include "cliprdr_format.h" +#include "../cliprdr_common.h" + +const char type_FileGroupDescriptorW[] = "FileGroupDescriptorW"; +const char type_FileContents[] = "FileContents"; + +CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr) +{ + CliprdrClientContext* pInterface = NULL; + + if (!cliprdr) + return NULL; + + pInterface = (CliprdrClientContext*)cliprdr->channelEntryPoints.pInterface; + return pInterface; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s) +{ + UINT status = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + const size_t pos = Stream_GetPosition(s); + const size_t dataLen = pos - 8; + WINPR_ASSERT(dataLen <= UINT32_MAX); + + Stream_SetPosition(s, 4); + Stream_Write_UINT32(s, (UINT32)dataLen); + Stream_SetPosition(s, pos); + + WLog_DBG(TAG, "Cliprdr Sending (%" PRIu32 " bytes)", dataLen + 8); + + if (!cliprdr) + { + status = CHANNEL_RC_BAD_INIT_HANDLE; + } + else + { + WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelWriteEx); + status = cliprdr->channelEntryPoints.pVirtualChannelWriteEx( + cliprdr->InitHandle, cliprdr->OpenHandle, Stream_Buffer(s), + (UINT32)Stream_GetPosition(s), s); + } + + if (status != CHANNEL_RC_OK) + { + Stream_Free(s, TRUE); + WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08" PRIX32 "]", + WTSErrorToString(status), status); + } + + return status; +} + +UINT cliprdr_send_error_response(cliprdrPlugin* cliprdr, UINT16 type) +{ + wStream* s = cliprdr_packet_new(type, CB_RESPONSE_FAIL, 0); + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_OUTOFMEMORY; + } + + return cliprdr_packet_send(cliprdr, s); +} + +static void cliprdr_print_general_capability_flags(UINT32 flags) +{ + WLog_DBG(TAG, "generalFlags (0x%08" PRIX32 ") {", flags); + + if (flags & CB_USE_LONG_FORMAT_NAMES) + WLog_DBG(TAG, "\tCB_USE_LONG_FORMAT_NAMES"); + + if (flags & CB_STREAM_FILECLIP_ENABLED) + WLog_DBG(TAG, "\tCB_STREAM_FILECLIP_ENABLED"); + + if (flags & CB_FILECLIP_NO_FILE_PATHS) + WLog_DBG(TAG, "\tCB_FILECLIP_NO_FILE_PATHS"); + + if (flags & CB_CAN_LOCK_CLIPDATA) + WLog_DBG(TAG, "\tCB_CAN_LOCK_CLIPDATA"); + + if (flags & CB_HUGE_FILE_SUPPORT_ENABLED) + WLog_DBG(TAG, "\tCB_HUGE_FILE_SUPPORT_ENABLED"); + + WLog_DBG(TAG, "}"); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_process_general_capability(cliprdrPlugin* cliprdr, wStream* s) +{ + UINT32 version = 0; + UINT32 generalFlags = 0; + CLIPRDR_CAPABILITIES capabilities = { 0 }; + CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + if (!context) + { + WLog_ERR(TAG, "cliprdr_get_client_interface failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, version); /* version (4 bytes) */ + Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */ + WLog_DBG(TAG, "Version: %" PRIu32 "", version); + + cliprdr_print_general_capability_flags(generalFlags); + + cliprdr->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE; + cliprdr->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE; + cliprdr->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE; + cliprdr->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE; + cliprdr->hasHugeFileSupport = (generalFlags & CB_HUGE_FILE_SUPPORT_ENABLED) ? TRUE : FALSE; + cliprdr->capabilitiesReceived = TRUE; + + capabilities.common.msgType = CB_CLIP_CAPS; + capabilities.cCapabilitiesSets = 1; + capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*)&(generalCapabilitySet); + generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL; + generalCapabilitySet.capabilitySetLength = 12; + generalCapabilitySet.version = version; + generalCapabilitySet.generalFlags = generalFlags; + IFCALLRET(context->ServerCapabilities, error, context, &capabilities); + + if (error) + WLog_ERR(TAG, "ServerCapabilities failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, + UINT16 flags) +{ + UINT16 lengthCapability = 0; + UINT16 cCapabilitiesSets = 0; + UINT16 capabilitySetType = 0; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */ + Stream_Seek_UINT16(s); /* pad1 (2 bytes) */ + WLog_Print(cliprdr->log, WLOG_DEBUG, "ServerCapabilities"); + + for (UINT16 index = 0; index < cCapabilitiesSets; index++) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, capabilitySetType); /* capabilitySetType (2 bytes) */ + Stream_Read_UINT16(s, lengthCapability); /* lengthCapability (2 bytes) */ + + if ((lengthCapability < 4) || + (!Stream_CheckAndLogRequiredLength(TAG, s, lengthCapability - 4U))) + return ERROR_INVALID_DATA; + + switch (capabilitySetType) + { + case CB_CAPSTYPE_GENERAL: + if ((error = cliprdr_process_general_capability(cliprdr, s))) + { + WLog_ERR(TAG, + "cliprdr_process_general_capability failed with error %" PRIu32 "!", + error); + return error; + } + + break; + + default: + WLog_ERR(TAG, "unknown cliprdr capability set: %" PRIu16 "", capabilitySetType); + return CHANNEL_RC_BAD_PROC; + } + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, + UINT16 flags) +{ + CLIPRDR_MONITOR_READY monitorReady = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + WLog_Print(cliprdr->log, WLOG_DEBUG, "MonitorReady"); + + if (!cliprdr->capabilitiesReceived) + { + /** + * The clipboard capabilities pdu from server to client is optional, + * but a server using it must send it before sending the monitor ready pdu. + * When the server capabilities pdu is not used, default capabilities + * corresponding to a generalFlags field set to zero are assumed. + */ + cliprdr->useLongFormatNames = FALSE; + cliprdr->streamFileClipEnabled = FALSE; + cliprdr->fileClipNoFilePaths = TRUE; + cliprdr->canLockClipData = FALSE; + } + + monitorReady.common.msgType = CB_MONITOR_READY; + monitorReady.common.msgFlags = flags; + monitorReady.common.dataLen = length; + IFCALLRET(context->MonitorReady, error, context, &monitorReady); + + if (error) + WLog_ERR(TAG, "MonitorReady failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_process_filecontents_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, + UINT16 flags) +{ + CLIPRDR_FILE_CONTENTS_REQUEST request = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsRequest"); + + request.common.msgType = CB_FILECONTENTS_REQUEST; + request.common.msgFlags = flags; + request.common.dataLen = length; + + if ((error = cliprdr_read_file_contents_request(s, &request))) + return error; + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + if ((mask & (CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) == 0) + { + WLog_WARN(TAG, "local -> remote file copy disabled, ignoring request"); + return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE); + } + IFCALLRET(context->ServerFileContentsRequest, error, context, &request); + + if (error) + WLog_ERR(TAG, "ServerFileContentsRequest failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_process_filecontents_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, + UINT16 flags) +{ + CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + WLog_Print(cliprdr->log, WLOG_DEBUG, "FileContentsResponse"); + + response.common.msgType = CB_FILECONTENTS_RESPONSE; + response.common.msgFlags = flags; + response.common.dataLen = length; + + if ((error = cliprdr_read_file_contents_response(s, &response))) + return error; + + IFCALLRET(context->ServerFileContentsResponse, error, context, &response); + + if (error) + WLog_ERR(TAG, "ServerFileContentsResponse failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_process_lock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, + UINT16 flags) +{ + CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + WLog_Print(cliprdr->log, WLOG_DEBUG, "LockClipData"); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + lockClipboardData.common.msgType = CB_LOCK_CLIPDATA; + lockClipboardData.common.msgFlags = flags; + lockClipboardData.common.dataLen = length; + Stream_Read_UINT32(s, lockClipboardData.clipDataId); /* clipDataId (4 bytes) */ + IFCALLRET(context->ServerLockClipboardData, error, context, &lockClipboardData); + + if (error) + WLog_ERR(TAG, "ServerLockClipboardData failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_process_unlock_clipdata(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, + UINT16 flags) +{ + CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData = { 0 }; + CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr); + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + WLog_Print(cliprdr->log, WLOG_DEBUG, "UnlockClipData"); + + if ((error = cliprdr_read_unlock_clipdata(s, &unlockClipboardData))) + return error; + + unlockClipboardData.common.msgType = CB_UNLOCK_CLIPDATA; + unlockClipboardData.common.msgFlags = flags; + unlockClipboardData.common.dataLen = length; + + IFCALLRET(context->ServerUnlockClipboardData, error, context, &unlockClipboardData); + + if (error) + WLog_ERR(TAG, "ServerUnlockClipboardData failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_order_recv(LPVOID userdata, wStream* s) +{ + cliprdrPlugin* cliprdr = userdata; + UINT16 msgType = 0; + UINT16 msgFlags = 0; + UINT32 dataLen = 0; + UINT error = 0; + + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(s); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, msgType); /* msgType (2 bytes) */ + Stream_Read_UINT16(s, msgFlags); /* msgFlags (2 bytes) */ + Stream_Read_UINT32(s, dataLen); /* dataLen (4 bytes) */ + + if (!Stream_CheckAndLogRequiredLength(TAG, s, dataLen)) + return ERROR_INVALID_DATA; + + char buffer1[64] = { 0 }; + char buffer2[64] = { 0 }; + WLog_DBG(TAG, "msgType: %s (%" PRIu16 "), msgFlags: %s dataLen: %" PRIu32 "", + CB_MSG_TYPE_STRING(msgType, buffer1, sizeof(buffer1)), msgType, + CB_MSG_FLAGS_STRING(msgFlags, buffer2, sizeof(buffer2)), dataLen); + + switch (msgType) + { + case CB_CLIP_CAPS: + if ((error = cliprdr_process_clip_caps(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_clip_caps failed with error %" PRIu32 "!", error); + + break; + + case CB_MONITOR_READY: + if ((error = cliprdr_process_monitor_ready(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_monitor_ready failed with error %" PRIu32 "!", + error); + + break; + + case CB_FORMAT_LIST: + if ((error = cliprdr_process_format_list(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_format_list failed with error %" PRIu32 "!", error); + + break; + + case CB_FORMAT_LIST_RESPONSE: + if ((error = cliprdr_process_format_list_response(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_format_list_response failed with error %" PRIu32 "!", + error); + + break; + + case CB_FORMAT_DATA_REQUEST: + if ((error = cliprdr_process_format_data_request(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_format_data_request failed with error %" PRIu32 "!", + error); + + break; + + case CB_FORMAT_DATA_RESPONSE: + if ((error = cliprdr_process_format_data_response(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_format_data_response failed with error %" PRIu32 "!", + error); + + break; + + case CB_FILECONTENTS_REQUEST: + if ((error = cliprdr_process_filecontents_request(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_filecontents_request failed with error %" PRIu32 "!", + error); + + break; + + case CB_FILECONTENTS_RESPONSE: + if ((error = cliprdr_process_filecontents_response(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, + "cliprdr_process_filecontents_response failed with error %" PRIu32 "!", + error); + + break; + + case CB_LOCK_CLIPDATA: + if ((error = cliprdr_process_lock_clipdata(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_lock_clipdata failed with error %" PRIu32 "!", + error); + + break; + + case CB_UNLOCK_CLIPDATA: + if ((error = cliprdr_process_unlock_clipdata(cliprdr, s, dataLen, msgFlags))) + WLog_ERR(TAG, "cliprdr_process_unlock_clipdata failed with error %" PRIu32 "!", + error); + + break; + + default: + error = CHANNEL_RC_BAD_PROC; + WLog_ERR(TAG, "unknown msgType %" PRIu16 "", msgType); + break; + } + + Stream_Free(s, TRUE); + return error; +} + +/** + * Callback Interface + */ + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_client_capabilities(CliprdrClientContext* context, + const CLIPRDR_CAPABILITIES* capabilities) +{ + wStream* s = NULL; + UINT32 flags = 0; + const CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + + cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Write_UINT16(s, 1); /* cCapabilitiesSets */ + Stream_Write_UINT16(s, 0); /* pad1 */ + generalCapabilitySet = (const CLIPRDR_GENERAL_CAPABILITY_SET*)capabilities->capabilitySets; + Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType); /* capabilitySetType */ + Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength); /* lengthCapability */ + Stream_Write_UINT32(s, generalCapabilitySet->version); /* version */ + flags = generalCapabilitySet->generalFlags; + + /* Client capabilities are sent in response to server capabilities. + * -> Do not request features the server does not support. + * -> Update clipboard context feature state to what was agreed upon. + */ + if (!cliprdr->useLongFormatNames) + flags &= (uint32_t)~CB_USE_LONG_FORMAT_NAMES; + if (!cliprdr->streamFileClipEnabled) + flags &= (uint32_t)~CB_STREAM_FILECLIP_ENABLED; + if (!cliprdr->fileClipNoFilePaths) + flags &= (uint32_t)~CB_FILECLIP_NO_FILE_PATHS; + if (!cliprdr->canLockClipData) + flags &= (uint32_t)~CB_CAN_LOCK_CLIPDATA; + if (!cliprdr->hasHugeFileSupport) + flags &= (uint32_t)~CB_HUGE_FILE_SUPPORT_ENABLED; + + cliprdr->useLongFormatNames = (flags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE; + cliprdr->streamFileClipEnabled = (flags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE; + cliprdr->fileClipNoFilePaths = (flags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE; + cliprdr->canLockClipData = (flags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE; + cliprdr->hasHugeFileSupport = (flags & CB_HUGE_FILE_SUPPORT_ENABLED) ? TRUE : FALSE; + + Stream_Write_UINT32(s, flags); /* generalFlags */ + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientCapabilities"); + + cliprdr->initialFormatListSent = FALSE; + + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_temp_directory(CliprdrClientContext* context, + const CLIPRDR_TEMP_DIRECTORY* tempDirectory) +{ + wStream* s = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(tempDirectory); + + cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + const size_t tmpDirCharLen = sizeof(tempDirectory->szTempDir) / sizeof(WCHAR); + s = cliprdr_packet_new(CB_TEMP_DIRECTORY, 0, tmpDirCharLen * sizeof(WCHAR)); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (Stream_Write_UTF16_String_From_UTF8(s, tmpDirCharLen - 1, tempDirectory->szTempDir, + ARRAYSIZE(tempDirectory->szTempDir), TRUE) < 0) + { + Stream_Free(s, TRUE); + return ERROR_INTERNAL_ERROR; + } + /* Path must be 260 UTF16 characters with '\0' termination. + * ensure this here */ + Stream_Write_UINT16(s, 0); + + WLog_Print(cliprdr->log, WLOG_DEBUG, "TempDirectory: %s", tempDirectory->szTempDir); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_client_format_list(CliprdrClientContext* context, + const CLIPRDR_FORMAT_LIST* formatList) +{ + wStream* s = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(formatList); + + cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + { + const UINT32 mask = CB_RESPONSE_OK | CB_RESPONSE_FAIL; + if ((formatList->common.msgFlags & mask) != 0) + WLog_WARN(TAG, + "Sending clipboard request with invalid flags msgFlags = 0x%08" PRIx32 + ". Correct in your client!", + formatList->common.msgFlags & mask); + } + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + CLIPRDR_FORMAT_LIST filterList = cliprdr_filter_format_list( + formatList, mask, CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES); + + /* Allow initial format list from monitor ready, but ignore later attempts */ + if ((filterList.numFormats == 0) && cliprdr->initialFormatListSent) + { + cliprdr_free_format_list(&filterList); + return CHANNEL_RC_OK; + } + cliprdr->initialFormatListSent = TRUE; + + s = cliprdr_packet_format_list_new(&filterList, cliprdr->useLongFormatNames, FALSE); + cliprdr_free_format_list(&filterList); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_format_list_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatList: numFormats: %" PRIu32 "", + formatList->numFormats); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_client_format_list_response(CliprdrClientContext* context, + const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse) +{ + wStream* s = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(formatListResponse); + + cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->common.msgFlags, 0); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatListResponse"); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context, + const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData) +{ + wStream* s = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(lockClipboardData); + + cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + s = cliprdr_packet_lock_clipdata_new(lockClipboardData); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_lock_clipdata_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientLockClipboardData: clipDataId: 0x%08" PRIX32 "", + lockClipboardData->clipDataId); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context, + const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) +{ + wStream* s = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(unlockClipboardData); + + cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_unlock_clipdata_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientUnlockClipboardData: clipDataId: 0x%08" PRIX32 "", + unlockClipboardData->clipDataId); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_client_format_data_request(CliprdrClientContext* context, + const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(formatDataRequest); + + cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + if ((mask & (CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES)) == 0) + { + WLog_WARN(TAG, "remote -> local copy disabled, ignoring request"); + return CHANNEL_RC_OK; + } + + wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, 0, 4); + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */ + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataRequest(0x%08" PRIx32 ")", + formatDataRequest->requestedFormatId); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_client_format_data_response(CliprdrClientContext* context, + const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(formatDataResponse); + + cliprdrPlugin* cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + WINPR_ASSERT( + (freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask) & + (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES)) != 0); + + wStream* s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->common.msgFlags, + formatDataResponse->common.dataLen); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen); + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataResponse"); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_client_file_contents_request(CliprdrClientContext* context, + const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest) +{ + wStream* s = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(fileContentsRequest); + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + if ((mask & CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES) == 0) + { + WLog_WARN(TAG, "remote -> local file copy disabled, ignoring request"); + return CHANNEL_RC_OK; + } + + cliprdr = (cliprdrPlugin*)context->handle; + if (!cliprdr) + return ERROR_INTERNAL_ERROR; + + if (!cliprdr->hasHugeFileSupport) + { + if (((UINT64)fileContentsRequest->cbRequested + fileContentsRequest->nPositionLow) > + UINT32_MAX) + return ERROR_INVALID_PARAMETER; + if (fileContentsRequest->nPositionHigh != 0) + return ERROR_INVALID_PARAMETER; + } + + s = cliprdr_packet_file_contents_request_new(fileContentsRequest); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_file_contents_request_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsRequest: streamId: 0x%08" PRIX32 "", + fileContentsRequest->streamId); + return cliprdr_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_client_file_contents_response(CliprdrClientContext* context, + const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse) +{ + wStream* s = NULL; + cliprdrPlugin* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(fileContentsResponse); + + cliprdr = (cliprdrPlugin*)context->handle; + WINPR_ASSERT(cliprdr); + + const UINT32 mask = + freerdp_settings_get_uint32(context->rdpcontext->settings, FreeRDP_ClipboardFeatureMask); + if ((mask & CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES) == 0) + return cliprdr_send_error_response(cliprdr, CB_FILECONTENTS_RESPONSE); + + s = cliprdr_packet_file_contents_response_new(fileContentsResponse); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_file_contents_response_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFileContentsResponse: streamId: 0x%08" PRIX32 "", + fileContentsResponse->streamId); + return cliprdr_packet_send(cliprdr, s); +} + +static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle, + UINT event, LPVOID pData, + UINT32 dataLength, UINT32 totalLength, + UINT32 dataFlags) +{ + UINT error = CHANNEL_RC_OK; + cliprdrPlugin* cliprdr = (cliprdrPlugin*)lpUserParam; + + switch (event) + { + case CHANNEL_EVENT_DATA_RECEIVED: + if (!cliprdr || (cliprdr->OpenHandle != openHandle)) + { + WLog_ERR(TAG, "error no match"); + return; + } + if ((error = channel_client_post_message(cliprdr->MsgsHandle, pData, dataLength, + totalLength, dataFlags))) + WLog_ERR(TAG, "failed with error %" PRIu32 "", error); + + break; + + case CHANNEL_EVENT_WRITE_CANCELLED: + case CHANNEL_EVENT_WRITE_COMPLETE: + { + wStream* s = (wStream*)pData; + Stream_Free(s, TRUE); + } + break; + + case CHANNEL_EVENT_USER: + break; + default: + break; + } + + if (error && cliprdr && cliprdr->context->rdpcontext) + setChannelError(cliprdr->context->rdpcontext, error, + "cliprdr_virtual_channel_open_event_ex reported an error"); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVOID pData, + UINT32 dataLength) +{ + DWORD status = 0; + WINPR_ASSERT(cliprdr); + WINPR_ASSERT(cliprdr->context); + + WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelOpenEx); + status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx( + cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name, + cliprdr_virtual_channel_open_event_ex); + if (status != CHANNEL_RC_OK) + return status; + + cliprdr->MsgsHandle = channel_client_create_handler( + cliprdr->context->rdpcontext, cliprdr, cliprdr_order_recv, CLIPRDR_SVC_CHANNEL_NAME); + if (!cliprdr->MsgsHandle) + return ERROR_INTERNAL_ERROR; + + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr) +{ + UINT rc = 0; + + WINPR_ASSERT(cliprdr); + + channel_client_quit_handler(cliprdr->MsgsHandle); + cliprdr->MsgsHandle = NULL; + + if (cliprdr->OpenHandle == 0) + return CHANNEL_RC_OK; + + WINPR_ASSERT(cliprdr->channelEntryPoints.pVirtualChannelCloseEx); + rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle, + cliprdr->OpenHandle); + + if (CHANNEL_RC_OK != rc) + { + WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08" PRIX32 "]", WTSErrorToString(rc), + rc); + return rc; + } + + cliprdr->OpenHandle = 0; + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_virtual_channel_event_terminated(cliprdrPlugin* cliprdr) +{ + WINPR_ASSERT(cliprdr); + + cliprdr->InitHandle = 0; + free(cliprdr->context); + free(cliprdr); + return CHANNEL_RC_OK; +} + +static VOID VCAPITYPE cliprdr_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle, + UINT event, LPVOID pData, + UINT dataLength) +{ + UINT error = CHANNEL_RC_OK; + cliprdrPlugin* cliprdr = (cliprdrPlugin*)lpUserParam; + + if (!cliprdr || (cliprdr->InitHandle != pInitHandle)) + { + WLog_ERR(TAG, "error no match"); + return; + } + + switch (event) + { + case CHANNEL_EVENT_CONNECTED: + if ((error = cliprdr_virtual_channel_event_connected(cliprdr, pData, dataLength))) + WLog_ERR(TAG, + "cliprdr_virtual_channel_event_connected failed with error %" PRIu32 "!", + error); + + break; + + case CHANNEL_EVENT_DISCONNECTED: + if ((error = cliprdr_virtual_channel_event_disconnected(cliprdr))) + WLog_ERR(TAG, + "cliprdr_virtual_channel_event_disconnected failed with error %" PRIu32 + "!", + error); + + break; + + case CHANNEL_EVENT_TERMINATED: + if ((error = cliprdr_virtual_channel_event_terminated(cliprdr))) + WLog_ERR(TAG, + "cliprdr_virtual_channel_event_terminated failed with error %" PRIu32 "!", + error); + break; + default: + break; + } + + if (error && cliprdr->context->rdpcontext) + setChannelError(cliprdr->context->rdpcontext, error, + "cliprdr_virtual_channel_init_event reported an error"); +} + +/* cliprdr is always built-in */ +#define VirtualChannelEntryEx cliprdr_VirtualChannelEntryEx + +FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, + PVOID pInitHandle)) +{ + UINT rc = 0; + cliprdrPlugin* cliprdr = NULL; + CliprdrClientContext* context = NULL; + CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx = NULL; + cliprdr = (cliprdrPlugin*)calloc(1, sizeof(cliprdrPlugin)); + + if (!cliprdr) + { + WLog_ERR(TAG, "calloc failed!"); + return FALSE; + } + + cliprdr->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | + CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL; + (void)sprintf_s(cliprdr->channelDef.name, ARRAYSIZE(cliprdr->channelDef.name), + CLIPRDR_SVC_CHANNEL_NAME); + pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints; + WINPR_ASSERT(pEntryPointsEx); + + if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) && + (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER)) + { + context = (CliprdrClientContext*)calloc(1, sizeof(CliprdrClientContext)); + + if (!context) + { + free(cliprdr); + WLog_ERR(TAG, "calloc failed!"); + return FALSE; + } + + context->handle = (void*)cliprdr; + context->custom = NULL; + context->ClientCapabilities = cliprdr_client_capabilities; + context->TempDirectory = cliprdr_temp_directory; + context->ClientFormatList = cliprdr_client_format_list; + context->ClientFormatListResponse = cliprdr_client_format_list_response; + context->ClientLockClipboardData = cliprdr_client_lock_clipboard_data; + context->ClientUnlockClipboardData = cliprdr_client_unlock_clipboard_data; + context->ClientFormatDataRequest = cliprdr_client_format_data_request; + context->ClientFormatDataResponse = cliprdr_client_format_data_response; + context->ClientFileContentsRequest = cliprdr_client_file_contents_request; + context->ClientFileContentsResponse = cliprdr_client_file_contents_response; + cliprdr->context = context; + context->rdpcontext = pEntryPointsEx->context; + } + + cliprdr->log = WLog_Get(CHANNELS_TAG("channels.cliprdr.client")); + WLog_Print(cliprdr->log, WLOG_DEBUG, "VirtualChannelEntryEx"); + CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints, + sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)); + cliprdr->InitHandle = pInitHandle; + rc = cliprdr->channelEntryPoints.pVirtualChannelInitEx( + cliprdr, context, pInitHandle, &cliprdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, + cliprdr_virtual_channel_init_event_ex); + + if (CHANNEL_RC_OK != rc) + { + WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08" PRIX32 "]", WTSErrorToString(rc), + rc); + free(cliprdr->context); + free(cliprdr); + return FALSE; + } + + cliprdr->channelEntryPoints.pInterface = context; + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.h new file mode 100644 index 0000000000000000000000000000000000000000..94cffdd0442928e16846f1db16fa04c07fcf1950 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/client/cliprdr_main.h @@ -0,0 +1,61 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2011 Vic Lee + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CLIPRDR_CLIENT_MAIN_H +#define FREERDP_CHANNEL_CLIPRDR_CLIENT_MAIN_H + +#include + +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("cliprdr.client") + +typedef struct +{ + CHANNEL_DEF channelDef; + CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints; + + CliprdrClientContext* context; + + wLog* log; + void* InitHandle; + DWORD OpenHandle; + void* MsgsHandle; + + BOOL capabilitiesReceived; + BOOL useLongFormatNames; + BOOL streamFileClipEnabled; + BOOL fileClipNoFilePaths; + BOOL canLockClipData; + BOOL hasHugeFileSupport; + BOOL initialFormatListSent; +} cliprdrPlugin; + +CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr); +UINT cliprdr_send_error_response(cliprdrPlugin* cliprdr, UINT16 type); + +extern const char type_FileGroupDescriptorW[]; +extern const char type_FileContents[]; + +#endif /* FREERDP_CHANNEL_CLIPRDR_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.c b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.c new file mode 100644 index 0000000000000000000000000000000000000000..6ac7dfddd4afae6a52829a97c5a6ea45f9659615 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.c @@ -0,0 +1,558 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Cliprdr common + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#define TAG CHANNELS_TAG("cliprdr.common") + +#include "cliprdr_common.h" + +static const char* CB_MSG_TYPE_STR(UINT32 type) +{ + switch (type) + { + case CB_TYPE_NONE: + return "CB_TYPE_NONE"; + case CB_MONITOR_READY: + return "CB_MONITOR_READY"; + case CB_FORMAT_LIST: + return "CB_FORMAT_LIST"; + case CB_FORMAT_LIST_RESPONSE: + return "CB_FORMAT_LIST_RESPONSE"; + case CB_FORMAT_DATA_REQUEST: + return "CB_FORMAT_DATA_REQUEST"; + case CB_FORMAT_DATA_RESPONSE: + return "CB_FORMAT_DATA_RESPONSE"; + case CB_TEMP_DIRECTORY: + return "CB_TEMP_DIRECTORY"; + case CB_CLIP_CAPS: + return "CB_CLIP_CAPS"; + case CB_FILECONTENTS_REQUEST: + return "CB_FILECONTENTS_REQUEST"; + case CB_FILECONTENTS_RESPONSE: + return "CB_FILECONTENTS_RESPONSE"; + case CB_LOCK_CLIPDATA: + return "CB_LOCK_CLIPDATA"; + case CB_UNLOCK_CLIPDATA: + return "CB_UNLOCK_CLIPDATA"; + default: + return "UNKNOWN"; + } +} + +const char* CB_MSG_TYPE_STRING(UINT16 type, char* buffer, size_t size) +{ + (void)_snprintf(buffer, size, "%s [0x%04" PRIx16 "]", CB_MSG_TYPE_STR(type), type); + return buffer; +} + +const char* CB_MSG_FLAGS_STRING(UINT16 msgFlags, char* buffer, size_t size) +{ + if ((msgFlags & CB_RESPONSE_OK) != 0) + winpr_str_append("CB_RESPONSE_OK", buffer, size, "|"); + if ((msgFlags & CB_RESPONSE_FAIL) != 0) + winpr_str_append("CB_RESPONSE_FAIL", buffer, size, "|"); + if ((msgFlags & CB_ASCII_NAMES) != 0) + winpr_str_append("CB_ASCII_NAMES", buffer, size, "|"); + + const size_t len = strnlen(buffer, size); + if (!len) + winpr_str_append("NONE", buffer, size, ""); + + char val[32] = { 0 }; + (void)_snprintf(val, sizeof(val), "[0x%04" PRIx16 "]", msgFlags); + winpr_str_append(val, buffer, size, "|"); + return buffer; +} + +static BOOL cliprdr_validate_file_contents_request(const CLIPRDR_FILE_CONTENTS_REQUEST* request) +{ + /* + * [MS-RDPECLIP] 2.2.5.3 File Contents Request PDU (CLIPRDR_FILECONTENTS_REQUEST). + * + * A request for the size of the file identified by the lindex field. The size MUST be + * returned as a 64-bit, unsigned integer. The cbRequested field MUST be set to + * 0x00000008 and both the nPositionLow and nPositionHigh fields MUST be + * set to 0x00000000. + */ + + if (request->dwFlags & FILECONTENTS_SIZE) + { + if (request->cbRequested != sizeof(UINT64)) + { + WLog_ERR(TAG, "cbRequested must be %" PRIu32 ", got %" PRIu32 "", sizeof(UINT64), + request->cbRequested); + return FALSE; + } + + if (request->nPositionHigh != 0 || request->nPositionLow != 0) + { + WLog_ERR(TAG, "nPositionHigh and nPositionLow must be set to 0"); + return FALSE; + } + } + + return TRUE; +} + +wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen) +{ + wStream* s = NULL; + s = Stream_New(NULL, dataLen + 8); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return NULL; + } + + Stream_Write_UINT16(s, msgType); + Stream_Write_UINT16(s, msgFlags); + /* Write actual length after the entire packet has been constructed. */ + Stream_Write_UINT32(s, 0); + return s; +} + +static void cliprdr_write_file_contents_request(wStream* s, + const CLIPRDR_FILE_CONTENTS_REQUEST* request) +{ + Stream_Write_UINT32(s, request->streamId); /* streamId (4 bytes) */ + Stream_Write_UINT32(s, request->listIndex); /* listIndex (4 bytes) */ + Stream_Write_UINT32(s, request->dwFlags); /* dwFlags (4 bytes) */ + Stream_Write_UINT32(s, request->nPositionLow); /* nPositionLow (4 bytes) */ + Stream_Write_UINT32(s, request->nPositionHigh); /* nPositionHigh (4 bytes) */ + Stream_Write_UINT32(s, request->cbRequested); /* cbRequested (4 bytes) */ + + if (request->haveClipDataId) + Stream_Write_UINT32(s, request->clipDataId); /* clipDataId (4 bytes) */ +} + +static INLINE void cliprdr_write_lock_unlock_clipdata(wStream* s, UINT32 clipDataId) +{ + Stream_Write_UINT32(s, clipDataId); +} + +static void cliprdr_write_lock_clipdata(wStream* s, + const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData) +{ + cliprdr_write_lock_unlock_clipdata(s, lockClipboardData->clipDataId); +} + +static void cliprdr_write_unlock_clipdata(wStream* s, + const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) +{ + cliprdr_write_lock_unlock_clipdata(s, unlockClipboardData->clipDataId); +} + +static void cliprdr_write_file_contents_response(wStream* s, + const CLIPRDR_FILE_CONTENTS_RESPONSE* response) +{ + Stream_Write_UINT32(s, response->streamId); /* streamId (4 bytes) */ + Stream_Write(s, response->requestedData, response->cbRequested); +} + +wStream* cliprdr_packet_lock_clipdata_new(const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData) +{ + wStream* s = NULL; + + if (!lockClipboardData) + return NULL; + + s = cliprdr_packet_new(CB_LOCK_CLIPDATA, 0, 4); + + if (!s) + return NULL; + + cliprdr_write_lock_clipdata(s, lockClipboardData); + return s; +} + +wStream* +cliprdr_packet_unlock_clipdata_new(const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) +{ + wStream* s = NULL; + + if (!unlockClipboardData) + return NULL; + + s = cliprdr_packet_new(CB_UNLOCK_CLIPDATA, 0, 4); + + if (!s) + return NULL; + + cliprdr_write_unlock_clipdata(s, unlockClipboardData); + return s; +} + +wStream* cliprdr_packet_file_contents_request_new(const CLIPRDR_FILE_CONTENTS_REQUEST* request) +{ + wStream* s = NULL; + + if (!request) + return NULL; + + s = cliprdr_packet_new(CB_FILECONTENTS_REQUEST, 0, 28); + + if (!s) + return NULL; + + cliprdr_write_file_contents_request(s, request); + return s; +} + +wStream* cliprdr_packet_file_contents_response_new(const CLIPRDR_FILE_CONTENTS_RESPONSE* response) +{ + wStream* s = NULL; + + if (!response) + return NULL; + + s = cliprdr_packet_new(CB_FILECONTENTS_RESPONSE, response->common.msgFlags, + 4 + response->cbRequested); + + if (!s) + return NULL; + + cliprdr_write_file_contents_response(s, response); + return s; +} + +wStream* cliprdr_packet_format_list_new(const CLIPRDR_FORMAT_LIST* formatList, + BOOL useLongFormatNames, BOOL useAsciiNames) +{ + WINPR_ASSERT(formatList); + + if (formatList->common.msgType != CB_FORMAT_LIST) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, formatList->common.msgType); + + if (useLongFormatNames && useAsciiNames) + WLog_WARN(TAG, "called with invalid arguments useLongFormatNames=true && " + "useAsciiNames=true. useAsciiNames requires " + "useLongFormatNames=false, ignoring argument."); + + const UINT32 length = formatList->numFormats * 36; + const size_t formatNameCharSize = + (useLongFormatNames || !useAsciiNames) ? sizeof(WCHAR) : sizeof(CHAR); + + wStream* s = cliprdr_packet_new(CB_FORMAT_LIST, 0, length); + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return NULL; + } + + for (UINT32 index = 0; index < formatList->numFormats; index++) + { + const CLIPRDR_FORMAT* format = &(formatList->formats[index]); + + const char* szFormatName = format->formatName; + size_t formatNameLength = 0; + if (szFormatName) + formatNameLength = strlen(szFormatName); + + size_t formatNameMaxLength = formatNameLength + 1; /* Ensure '\0' termination in output */ + if (!Stream_EnsureRemainingCapacity(s, + 4 + MAX(32, formatNameMaxLength * formatNameCharSize))) + goto fail; + + Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */ + + if (!useLongFormatNames) + { + formatNameMaxLength = useAsciiNames ? 32 : 16; + formatNameLength = MIN(formatNameMaxLength - 1, formatNameLength); + } + + if (szFormatName && (formatNameLength > 0)) + { + if (useAsciiNames) + { + Stream_Write(s, szFormatName, formatNameLength); + Stream_Zero(s, formatNameMaxLength - formatNameLength); + } + else + { + if (Stream_Write_UTF16_String_From_UTF8(s, formatNameMaxLength, szFormatName, + formatNameLength, TRUE) < 0) + goto fail; + } + } + else + Stream_Zero(s, formatNameMaxLength * formatNameCharSize); + } + + return s; + +fail: + Stream_Free(s, TRUE); + return NULL; +} + +UINT cliprdr_read_unlock_clipdata(wStream* s, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */ + return CHANNEL_RC_OK; +} + +UINT cliprdr_read_format_data_request(wStream* s, CLIPRDR_FORMAT_DATA_REQUEST* request) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, request->requestedFormatId); /* requestedFormatId (4 bytes) */ + return CHANNEL_RC_OK; +} + +UINT cliprdr_read_format_data_response(wStream* s, CLIPRDR_FORMAT_DATA_RESPONSE* response) +{ + response->requestedFormatData = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, response->common.dataLen)) + return ERROR_INVALID_DATA; + + if (response->common.dataLen) + response->requestedFormatData = Stream_ConstPointer(s); + + return CHANNEL_RC_OK; +} + +UINT cliprdr_read_file_contents_request(wStream* s, CLIPRDR_FILE_CONTENTS_REQUEST* request) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 24)) + return ERROR_INVALID_DATA; + + request->haveClipDataId = FALSE; + Stream_Read_UINT32(s, request->streamId); /* streamId (4 bytes) */ + Stream_Read_UINT32(s, request->listIndex); /* listIndex (4 bytes) */ + Stream_Read_UINT32(s, request->dwFlags); /* dwFlags (4 bytes) */ + Stream_Read_UINT32(s, request->nPositionLow); /* nPositionLow (4 bytes) */ + Stream_Read_UINT32(s, request->nPositionHigh); /* nPositionHigh (4 bytes) */ + Stream_Read_UINT32(s, request->cbRequested); /* cbRequested (4 bytes) */ + + if (Stream_GetRemainingLength(s) >= 4) + { + Stream_Read_UINT32(s, request->clipDataId); /* clipDataId (4 bytes) */ + request->haveClipDataId = TRUE; + } + + if (!cliprdr_validate_file_contents_request(request)) + return ERROR_BAD_ARGUMENTS; + + return CHANNEL_RC_OK; +} + +UINT cliprdr_read_file_contents_response(wStream* s, CLIPRDR_FILE_CONTENTS_RESPONSE* response) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, response->streamId); /* streamId (4 bytes) */ + response->requestedData = Stream_ConstPointer(s); /* requestedFileContentsData */ + + WINPR_ASSERT(response->common.dataLen >= 4); + response->cbRequested = response->common.dataLen - 4; + return CHANNEL_RC_OK; +} + +UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, BOOL useLongFormatNames) +{ + UINT32 index = 0; + size_t formatNameLength = 0; + const char* szFormatName = NULL; + const WCHAR* wszFormatName = NULL; + wStream sub1buffer = { 0 }; + CLIPRDR_FORMAT* formats = NULL; + UINT error = ERROR_INTERNAL_ERROR; + + const BOOL asciiNames = (formatList->common.msgFlags & CB_ASCII_NAMES) ? TRUE : FALSE; + + index = 0; + /* empty format list */ + formatList->formats = NULL; + formatList->numFormats = 0; + + wStream* sub1 = + Stream_StaticConstInit(&sub1buffer, Stream_ConstPointer(s), formatList->common.dataLen); + if (!Stream_SafeSeek(s, formatList->common.dataLen)) + return ERROR_INVALID_DATA; + + if (!formatList->common.dataLen) + { + } + else if (!useLongFormatNames) + { + const size_t cap = Stream_Capacity(sub1) / 36ULL; + if (cap > UINT32_MAX) + { + WLog_ERR(TAG, "Invalid short format list length: %" PRIuz "", cap); + return ERROR_INTERNAL_ERROR; + } + formatList->numFormats = (UINT32)cap; + + if (formatList->numFormats) + formats = (CLIPRDR_FORMAT*)calloc(formatList->numFormats, sizeof(CLIPRDR_FORMAT)); + + if (!formats) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + formatList->formats = formats; + + while (Stream_GetRemainingLength(sub1) >= 4) + { + CLIPRDR_FORMAT* format = &formats[index]; + + Stream_Read_UINT32(sub1, format->formatId); /* formatId (4 bytes) */ + + /* According to MS-RDPECLIP 2.2.3.1.1.1 formatName is "a 32-byte block containing + * the *null-terminated* name assigned to the Clipboard Format: (32 ASCII 8 characters + * or 16 Unicode characters)" + * However, both Windows RDSH and mstsc violate this specs as seen in the following + * example of a transferred short format name string: [R.i.c.h. .T.e.x.t. .F.o.r.m.a.t.] + * These are 16 unicode characters - *without* terminating null ! + */ + + szFormatName = Stream_ConstPointer(sub1); + wszFormatName = Stream_ConstPointer(sub1); + if (!Stream_SafeSeek(sub1, 32)) + goto error_out; + + free(format->formatName); + format->formatName = NULL; + + if (asciiNames) + { + if (szFormatName[0]) + { + /* ensure null termination */ + format->formatName = strndup(szFormatName, 31); + if (!format->formatName) + { + WLog_ERR(TAG, "malloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + } + } + else + { + if (wszFormatName[0]) + { + format->formatName = ConvertWCharNToUtf8Alloc(wszFormatName, 16, NULL); + if (!format->formatName) + goto error_out; + } + } + + index++; + } + } + else + { + wStream sub2buffer = sub1buffer; + wStream* sub2 = &sub2buffer; + + while (Stream_GetRemainingLength(sub1) > 0) + { + size_t rest = 0; + if (!Stream_SafeSeek(sub1, 4)) /* formatId (4 bytes) */ + goto error_out; + + wszFormatName = Stream_ConstPointer(sub1); + rest = Stream_GetRemainingLength(sub1); + formatNameLength = _wcsnlen(wszFormatName, rest / sizeof(WCHAR)); + + if (!Stream_SafeSeek(sub1, (formatNameLength + 1) * sizeof(WCHAR))) + goto error_out; + formatList->numFormats++; + } + + if (formatList->numFormats) + formats = (CLIPRDR_FORMAT*)calloc(formatList->numFormats, sizeof(CLIPRDR_FORMAT)); + + if (!formats) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + formatList->formats = formats; + + while (Stream_GetRemainingLength(sub2) >= 4) + { + size_t rest = 0; + CLIPRDR_FORMAT* format = &formats[index]; + + Stream_Read_UINT32(sub2, format->formatId); /* formatId (4 bytes) */ + + free(format->formatName); + format->formatName = NULL; + + wszFormatName = Stream_ConstPointer(sub2); + rest = Stream_GetRemainingLength(sub2); + formatNameLength = _wcsnlen(wszFormatName, rest / sizeof(WCHAR)); + if (!Stream_SafeSeek(sub2, (formatNameLength + 1) * sizeof(WCHAR))) + goto error_out; + + if (formatNameLength) + { + format->formatName = + ConvertWCharNToUtf8Alloc(wszFormatName, formatNameLength, NULL); + if (!format->formatName) + goto error_out; + } + + index++; + } + } + + return CHANNEL_RC_OK; + +error_out: + cliprdr_free_format_list(formatList); + return error; +} + +void cliprdr_free_format_list(CLIPRDR_FORMAT_LIST* formatList) +{ + if (formatList == NULL) + return; + + if (formatList->formats) + { + for (UINT32 index = 0; index < formatList->numFormats; index++) + { + free(formatList->formats[index].formatName); + } + + free(formatList->formats); + formatList->formats = NULL; + formatList->numFormats = 0; + } +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.h new file mode 100644 index 0000000000000000000000000000000000000000..1a78ab388e4e30808f06c4a6dabb461ea8ebdd73 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/cliprdr_common.h @@ -0,0 +1,64 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Cliprdr common + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPECLIP_COMMON_H +#define FREERDP_CHANNEL_RDPECLIP_COMMON_H + +#include +#include + +#include +#include + +FREERDP_LOCAL const char* CB_MSG_TYPE_STRING(UINT16 type, char* buffer, size_t size); +FREERDP_LOCAL const char* CB_MSG_FLAGS_STRING(UINT16 msgFlags, char* buffer, size_t size); + +FREERDP_LOCAL wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen); +FREERDP_LOCAL wStream* +cliprdr_packet_lock_clipdata_new(const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData); +FREERDP_LOCAL wStream* +cliprdr_packet_unlock_clipdata_new(const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData); +FREERDP_LOCAL wStream* +cliprdr_packet_file_contents_request_new(const CLIPRDR_FILE_CONTENTS_REQUEST* request); +FREERDP_LOCAL wStream* +cliprdr_packet_file_contents_response_new(const CLIPRDR_FILE_CONTENTS_RESPONSE* response); +FREERDP_LOCAL wStream* cliprdr_packet_format_list_new(const CLIPRDR_FORMAT_LIST* formatList, + BOOL useLongFormatNames, BOOL useAsciiNames); + +FREERDP_LOCAL UINT cliprdr_read_lock_clipdata(wStream* s, + CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData); +FREERDP_LOCAL UINT cliprdr_read_unlock_clipdata(wStream* s, + CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData); +FREERDP_LOCAL UINT cliprdr_read_format_data_request(wStream* s, + CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest); +FREERDP_LOCAL UINT cliprdr_read_format_data_response(wStream* s, + CLIPRDR_FORMAT_DATA_RESPONSE* response); +FREERDP_LOCAL UINT +cliprdr_read_file_contents_request(wStream* s, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest); +FREERDP_LOCAL UINT cliprdr_read_file_contents_response(wStream* s, + CLIPRDR_FILE_CONTENTS_RESPONSE* response); +FREERDP_LOCAL UINT cliprdr_read_format_list(wStream* s, CLIPRDR_FORMAT_LIST* formatList, + BOOL useLongFormatNames); + +FREERDP_LOCAL void cliprdr_free_format_list(CLIPRDR_FORMAT_LIST* formatList); + +#endif /* FREERDP_CHANNEL_RDPECLIP_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b20b9dc8ee8e406dbaa4558922c7cecbb3cc017 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/CMakeLists.txt @@ -0,0 +1,23 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("cliprdr") + +set(${MODULE_PREFIX}_SRCS cliprdr_main.c cliprdr_main.h ../cliprdr_common.h ../cliprdr_common.c) + +set(${MODULE_PREFIX}_LIBS freerdp) +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/cliprdr_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/cliprdr_main.c new file mode 100644 index 0000000000000000000000000000000000000000..d0e81f3423de5a67910d040f3b722f15e9d3ac75 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/cliprdr_main.c @@ -0,0 +1,1525 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include "cliprdr_main.h" +#include "../cliprdr_common.h" + +/** + * Initialization Sequence\n + * Client Server\n + * | |\n + * |<----------------------Server Clipboard Capabilities PDU-----------------|\n + * |<-----------------------------Monitor Ready PDU--------------------------|\n + * |-----------------------Client Clipboard Capabilities PDU---------------->|\n + * |---------------------------Temporary Directory PDU---------------------->|\n + * |-------------------------------Format List PDU-------------------------->|\n + * |<--------------------------Format List Response PDU----------------------|\n + * + */ + +/** + * Data Transfer Sequences\n + * Shared Local\n + * Clipboard Owner Clipboard Owner\n + * | |\n + * |-------------------------------------------------------------------------|\n _ + * |-------------------------------Format List PDU-------------------------->|\n | + * |<--------------------------Format List Response PDU----------------------|\n _| Copy + * Sequence + * |<---------------------Lock Clipboard Data PDU (Optional)-----------------|\n + * |-------------------------------------------------------------------------|\n + * |-------------------------------------------------------------------------|\n _ + * |<--------------------------Format Data Request PDU-----------------------|\n | Paste + * Sequence Palette, + * |---------------------------Format Data Response PDU--------------------->|\n _| Metafile, + * File List Data + * |-------------------------------------------------------------------------|\n + * |-------------------------------------------------------------------------|\n _ + * |<------------------------Format Contents Request PDU---------------------|\n | Paste + * Sequence + * |-------------------------Format Contents Response PDU------------------->|\n _| File + * Stream Data + * |<---------------------Lock Clipboard Data PDU (Optional)-----------------|\n + * |-------------------------------------------------------------------------|\n + * + */ + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_packet_send(CliprdrServerPrivate* cliprdr, wStream* s) +{ + UINT rc = 0; + size_t pos = 0; + BOOL status = 0; + UINT32 dataLen = 0; + ULONG written = 0; + + WINPR_ASSERT(cliprdr); + + pos = Stream_GetPosition(s); + if ((pos < 8) || (pos > UINT32_MAX)) + { + rc = ERROR_NO_DATA; + goto fail; + } + + dataLen = (UINT32)(pos - 8); + Stream_SetPosition(s, 4); + Stream_Write_UINT32(s, dataLen); + + WINPR_ASSERT(pos <= UINT32_MAX); + status = WTSVirtualChannelWrite(cliprdr->ChannelHandle, Stream_BufferAs(s, char), (UINT32)pos, + &written); + rc = status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; +fail: + Stream_Free(s, TRUE); + return rc; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_capabilities(CliprdrServerContext* context, + const CLIPRDR_CAPABILITIES* capabilities) +{ + size_t offset = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(capabilities); + + CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*)context->handle; + + if (capabilities->common.msgType != CB_CLIP_CAPS) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, capabilities->common.msgType); + + if (capabilities->cCapabilitiesSets > UINT16_MAX) + { + WLog_ERR(TAG, "Invalid number of capability sets in clipboard caps"); + return ERROR_INVALID_PARAMETER; + } + + wStream* s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Write_UINT16(s, + (UINT16)capabilities->cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */ + Stream_Write_UINT16(s, 0); /* pad1 (2 bytes) */ + for (UINT32 x = 0; x < capabilities->cCapabilitiesSets; x++) + { + const CLIPRDR_CAPABILITY_SET* cap = + (const CLIPRDR_CAPABILITY_SET*)(((const BYTE*)capabilities->capabilitySets) + offset); + offset += cap->capabilitySetLength; + + switch (cap->capabilitySetType) + { + case CB_CAPSTYPE_GENERAL: + { + const CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet = + (const CLIPRDR_GENERAL_CAPABILITY_SET*)cap; + Stream_Write_UINT16( + s, generalCapabilitySet->capabilitySetType); /* capabilitySetType (2 bytes) */ + Stream_Write_UINT16( + s, generalCapabilitySet->capabilitySetLength); /* lengthCapability (2 bytes) */ + Stream_Write_UINT32(s, generalCapabilitySet->version); /* version (4 bytes) */ + Stream_Write_UINT32( + s, generalCapabilitySet->generalFlags); /* generalFlags (4 bytes) */ + } + break; + + default: + WLog_WARN(TAG, "Unknown capability set type %08" PRIx16, cap->capabilitySetType); + if (!Stream_SafeSeek(s, cap->capabilitySetLength)) + { + WLog_ERR(TAG, "short stream"); + Stream_Free(s, TRUE); + return ERROR_NO_DATA; + } + break; + } + } + WLog_DBG(TAG, "ServerCapabilities"); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_monitor_ready(CliprdrServerContext* context, + const CLIPRDR_MONITOR_READY* monitorReady) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(monitorReady); + + cliprdr = (CliprdrServerPrivate*)context->handle; + + if (monitorReady->common.msgType != CB_MONITOR_READY) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, monitorReady->common.msgType); + + s = cliprdr_packet_new(CB_MONITOR_READY, monitorReady->common.msgFlags, + monitorReady->common.dataLen); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "ServerMonitorReady"); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_format_list(CliprdrServerContext* context, + const CLIPRDR_FORMAT_LIST* formatList) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(formatList); + + cliprdr = (CliprdrServerPrivate*)context->handle; + + s = cliprdr_packet_format_list_new(formatList, context->useLongFormatNames, FALSE); + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_format_list_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "ServerFormatList: numFormats: %" PRIu32 "", formatList->numFormats); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_server_format_list_response(CliprdrServerContext* context, + const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(formatListResponse); + + cliprdr = (CliprdrServerPrivate*)context->handle; + if (formatListResponse->common.msgType != CB_FORMAT_LIST_RESPONSE) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, formatListResponse->common.msgType); + + s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, formatListResponse->common.msgFlags, + formatListResponse->common.dataLen); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "ServerFormatListResponse"); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_lock_clipboard_data(CliprdrServerContext* context, + const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(lockClipboardData); + + cliprdr = (CliprdrServerPrivate*)context->handle; + if (lockClipboardData->common.msgType != CB_LOCK_CLIPDATA) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, lockClipboardData->common.msgType); + + s = cliprdr_packet_lock_clipdata_new(lockClipboardData); + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_lock_clipdata_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "ServerLockClipboardData: clipDataId: 0x%08" PRIX32 "", + lockClipboardData->clipDataId); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_server_unlock_clipboard_data(CliprdrServerContext* context, + const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(unlockClipboardData); + + cliprdr = (CliprdrServerPrivate*)context->handle; + if (unlockClipboardData->common.msgType != CB_UNLOCK_CLIPDATA) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, unlockClipboardData->common.msgType); + + s = cliprdr_packet_unlock_clipdata_new(unlockClipboardData); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_unlock_clipdata_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "ServerUnlockClipboardData: clipDataId: 0x%08" PRIX32 "", + unlockClipboardData->clipDataId); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_format_data_request(CliprdrServerContext* context, + const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(formatDataRequest); + + cliprdr = (CliprdrServerPrivate*)context->handle; + if (formatDataRequest->common.msgType != CB_FORMAT_DATA_REQUEST) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, formatDataRequest->common.msgType); + + s = cliprdr_packet_new(CB_FORMAT_DATA_REQUEST, formatDataRequest->common.msgFlags, + formatDataRequest->common.dataLen); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */ + WLog_DBG(TAG, "ClientFormatDataRequest"); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_server_format_data_response(CliprdrServerContext* context, + const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(formatDataResponse); + + cliprdr = (CliprdrServerPrivate*)context->handle; + + if (formatDataResponse->common.msgType != CB_FORMAT_DATA_RESPONSE) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, formatDataResponse->common.msgType); + + s = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, formatDataResponse->common.msgFlags, + formatDataResponse->common.dataLen); + + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->common.dataLen); + WLog_DBG(TAG, "ServerFormatDataResponse"); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_server_file_contents_request(CliprdrServerContext* context, + const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(fileContentsRequest); + + cliprdr = (CliprdrServerPrivate*)context->handle; + + if (fileContentsRequest->common.msgType != CB_FILECONTENTS_REQUEST) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, fileContentsRequest->common.msgType); + + s = cliprdr_packet_file_contents_request_new(fileContentsRequest); + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_file_contents_request_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "ServerFileContentsRequest: streamId: 0x%08" PRIX32 "", + fileContentsRequest->streamId); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +cliprdr_server_file_contents_response(CliprdrServerContext* context, + const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse) +{ + wStream* s = NULL; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(fileContentsResponse); + + cliprdr = (CliprdrServerPrivate*)context->handle; + + if (fileContentsResponse->common.msgType != CB_FILECONTENTS_RESPONSE) + WLog_WARN(TAG, "called with invalid type %08" PRIx32, fileContentsResponse->common.msgType); + + s = cliprdr_packet_file_contents_response_new(fileContentsResponse); + if (!s) + { + WLog_ERR(TAG, "cliprdr_packet_file_contents_response_new failed!"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "ServerFileContentsResponse: streamId: 0x%08" PRIX32 "", + fileContentsResponse->streamId); + return cliprdr_server_packet_send(cliprdr, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_general_capability(CliprdrServerContext* context, wStream* s, + CLIPRDR_GENERAL_CAPABILITY_SET* cap_set) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(cap_set); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, cap_set->version); /* version (4 bytes) */ + Stream_Read_UINT32(s, cap_set->generalFlags); /* generalFlags (4 bytes) */ + + if (context->useLongFormatNames) + context->useLongFormatNames = + (cap_set->generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE; + + if (context->streamFileClipEnabled) + context->streamFileClipEnabled = + (cap_set->generalFlags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE; + + if (context->fileClipNoFilePaths) + context->fileClipNoFilePaths = + (cap_set->generalFlags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE; + + if (context->canLockClipData) + context->canLockClipData = (cap_set->generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE; + + if (context->hasHugeFileSupport) + context->hasHugeFileSupport = + (cap_set->generalFlags & CB_HUGE_FILE_SUPPORT_ENABLED) ? TRUE : FALSE; + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_capabilities(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + UINT16 capabilitySetType = 0; + UINT16 capabilitySetLength = 0; + UINT error = ERROR_INVALID_DATA; + size_t cap_sets_size = 0; + CLIPRDR_CAPABILITIES capabilities = { 0 }; + CLIPRDR_CAPABILITY_SET* capSet = NULL; + + WINPR_ASSERT(context); + WINPR_UNUSED(header); + + WLog_DBG(TAG, "CliprdrClientCapabilities"); + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, capabilities.cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */ + Stream_Seek_UINT16(s); /* pad1 (2 bytes) */ + + for (size_t index = 0; index < capabilities.cCapabilitiesSets; index++) + { + void* tmp = NULL; + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + goto out; + Stream_Read_UINT16(s, capabilitySetType); /* capabilitySetType (2 bytes) */ + Stream_Read_UINT16(s, capabilitySetLength); /* capabilitySetLength (2 bytes) */ + + cap_sets_size += capabilitySetLength; + + if (cap_sets_size > 0) + tmp = realloc(capabilities.capabilitySets, cap_sets_size); + if (tmp == NULL) + { + WLog_ERR(TAG, "capabilities.capabilitySets realloc failed!"); + free(capabilities.capabilitySets); + return CHANNEL_RC_NO_MEMORY; + } + + capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*)tmp; + + capSet = &(capabilities.capabilitySets[index]); + + capSet->capabilitySetType = capabilitySetType; + capSet->capabilitySetLength = capabilitySetLength; + + switch (capSet->capabilitySetType) + { + case CB_CAPSTYPE_GENERAL: + error = cliprdr_server_receive_general_capability( + context, s, (CLIPRDR_GENERAL_CAPABILITY_SET*)capSet); + if (error) + { + WLog_ERR(TAG, + "cliprdr_server_receive_general_capability failed with error %" PRIu32 + "", + error); + goto out; + } + break; + + default: + WLog_ERR(TAG, "unknown cliprdr capability set: %" PRIu16 "", + capSet->capabilitySetType); + goto out; + } + } + + error = CHANNEL_RC_OK; + IFCALLRET(context->ClientCapabilities, error, context, &capabilities); +out: + free(capabilities.capabilitySets); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_temporary_directory(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + size_t length = 0; + CLIPRDR_TEMP_DIRECTORY tempDirectory = { 0 }; + CliprdrServerPrivate* cliprdr = NULL; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_UNUSED(header); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, + ARRAYSIZE(cliprdr->temporaryDirectory) * sizeof(WCHAR))) + return CHANNEL_RC_NO_MEMORY; + + const WCHAR* wszTempDir = Stream_ConstPointer(s); + + if (wszTempDir[ARRAYSIZE(cliprdr->temporaryDirectory) - 1] != 0) + { + WLog_ERR(TAG, "wszTempDir[259] was not 0"); + return ERROR_INVALID_DATA; + } + + if (ConvertWCharNToUtf8(wszTempDir, ARRAYSIZE(cliprdr->temporaryDirectory), + cliprdr->temporaryDirectory, + ARRAYSIZE(cliprdr->temporaryDirectory)) < 0) + { + WLog_ERR(TAG, "failed to convert temporary directory name"); + return ERROR_INVALID_DATA; + } + + length = strnlen(cliprdr->temporaryDirectory, ARRAYSIZE(cliprdr->temporaryDirectory)); + + if (length >= ARRAYSIZE(cliprdr->temporaryDirectory)) + length = ARRAYSIZE(cliprdr->temporaryDirectory) - 1; + + CopyMemory(tempDirectory.szTempDir, cliprdr->temporaryDirectory, length); + tempDirectory.szTempDir[length] = '\0'; + WLog_DBG(TAG, "CliprdrTemporaryDirectory: %s", cliprdr->temporaryDirectory); + IFCALLRET(context->TempDirectory, error, context, &tempDirectory); + + if (error) + WLog_ERR(TAG, "TempDirectory failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_format_list(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_FORMAT_LIST formatList = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + formatList.common.msgType = CB_FORMAT_LIST; + formatList.common.msgFlags = header->msgFlags; + formatList.common.dataLen = header->dataLen; + + if ((error = cliprdr_read_format_list(s, &formatList, context->useLongFormatNames))) + goto out; + + WLog_DBG(TAG, "ClientFormatList: numFormats: %" PRIu32 "", formatList.numFormats); + IFCALLRET(context->ClientFormatList, error, context, &formatList); + + if (error) + WLog_ERR(TAG, "ClientFormatList failed with error %" PRIu32 "!", error); + +out: + cliprdr_free_format_list(&formatList); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_format_list_response(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + WINPR_UNUSED(s); + WLog_DBG(TAG, "CliprdrClientFormatListResponse"); + formatListResponse.common.msgType = CB_FORMAT_LIST_RESPONSE; + formatListResponse.common.msgFlags = header->msgFlags; + formatListResponse.common.dataLen = header->dataLen; + IFCALLRET(context->ClientFormatListResponse, error, context, &formatListResponse); + + if (error) + WLog_ERR(TAG, "ClientFormatListResponse failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_lock_clipdata(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + WLog_DBG(TAG, "CliprdrClientLockClipData"); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + lockClipboardData.common.msgType = CB_LOCK_CLIPDATA; + lockClipboardData.common.msgFlags = header->msgFlags; + lockClipboardData.common.dataLen = header->dataLen; + Stream_Read_UINT32(s, lockClipboardData.clipDataId); /* clipDataId (4 bytes) */ + IFCALLRET(context->ClientLockClipboardData, error, context, &lockClipboardData); + + if (error) + WLog_ERR(TAG, "ClientLockClipboardData failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_unlock_clipdata(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + WLog_DBG(TAG, "CliprdrClientUnlockClipData"); + + unlockClipboardData.common.msgType = CB_UNLOCK_CLIPDATA; + unlockClipboardData.common.msgFlags = header->msgFlags; + unlockClipboardData.common.dataLen = header->dataLen; + + if ((error = cliprdr_read_unlock_clipdata(s, &unlockClipboardData))) + return error; + + IFCALLRET(context->ClientUnlockClipboardData, error, context, &unlockClipboardData); + + if (error) + WLog_ERR(TAG, "ClientUnlockClipboardData failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_format_data_request(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + WLog_DBG(TAG, "CliprdrClientFormatDataRequest"); + formatDataRequest.common.msgType = CB_FORMAT_DATA_REQUEST; + formatDataRequest.common.msgFlags = header->msgFlags; + formatDataRequest.common.dataLen = header->dataLen; + + if ((error = cliprdr_read_format_data_request(s, &formatDataRequest))) + return error; + + context->lastRequestedFormatId = formatDataRequest.requestedFormatId; + IFCALLRET(context->ClientFormatDataRequest, error, context, &formatDataRequest); + + if (error) + WLog_ERR(TAG, "ClientFormatDataRequest failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_format_data_response(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_FORMAT_DATA_RESPONSE formatDataResponse = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + WLog_DBG(TAG, "CliprdrClientFormatDataResponse"); + formatDataResponse.common.msgType = CB_FORMAT_DATA_RESPONSE; + formatDataResponse.common.msgFlags = header->msgFlags; + formatDataResponse.common.dataLen = header->dataLen; + + if ((error = cliprdr_read_format_data_response(s, &formatDataResponse))) + return error; + + IFCALLRET(context->ClientFormatDataResponse, error, context, &formatDataResponse); + + if (error) + WLog_ERR(TAG, "ClientFormatDataResponse failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_filecontents_request(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_FILE_CONTENTS_REQUEST request = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + WLog_DBG(TAG, "CliprdrClientFileContentsRequest"); + request.common.msgType = CB_FILECONTENTS_REQUEST; + request.common.msgFlags = header->msgFlags; + request.common.dataLen = header->dataLen; + + if ((error = cliprdr_read_file_contents_request(s, &request))) + return error; + + if (!context->hasHugeFileSupport) + { + if (request.nPositionHigh > 0) + return ERROR_INVALID_DATA; + if ((UINT64)request.nPositionLow + request.cbRequested > UINT32_MAX) + return ERROR_INVALID_DATA; + } + IFCALLRET(context->ClientFileContentsRequest, error, context, &request); + + if (error) + WLog_ERR(TAG, "ClientFileContentsRequest failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_filecontents_response(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + CLIPRDR_FILE_CONTENTS_RESPONSE response = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + WLog_DBG(TAG, "CliprdrClientFileContentsResponse"); + + response.common.msgType = CB_FILECONTENTS_RESPONSE; + response.common.msgFlags = header->msgFlags; + response.common.dataLen = header->dataLen; + + if ((error = cliprdr_read_file_contents_response(s, &response))) + return error; + + IFCALLRET(context->ClientFileContentsResponse, error, context, &response); + + if (error) + WLog_ERR(TAG, "ClientFileContentsResponse failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_receive_pdu(CliprdrServerContext* context, wStream* s, + const CLIPRDR_HEADER* header) +{ + UINT error = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + char buffer1[64] = { 0 }; + char buffer2[64] = { 0 }; + WLog_DBG(TAG, "CliprdrServerReceivePdu: msgType: %s, msgFlags: %s dataLen: %" PRIu32 "", + CB_MSG_TYPE_STRING(header->msgType, buffer1, sizeof(buffer1)), + CB_MSG_FLAGS_STRING(header->msgFlags, buffer2, sizeof(buffer2)), header->dataLen); + + switch (header->msgType) + { + case CB_CLIP_CAPS: + if ((error = cliprdr_server_receive_capabilities(context, s, header))) + WLog_ERR(TAG, "cliprdr_server_receive_capabilities failed with error %" PRIu32 "!", + error); + + break; + + case CB_TEMP_DIRECTORY: + if ((error = cliprdr_server_receive_temporary_directory(context, s, header))) + WLog_ERR(TAG, + "cliprdr_server_receive_temporary_directory failed with error %" PRIu32 + "!", + error); + + break; + + case CB_FORMAT_LIST: + if ((error = cliprdr_server_receive_format_list(context, s, header))) + WLog_ERR(TAG, "cliprdr_server_receive_format_list failed with error %" PRIu32 "!", + error); + + break; + + case CB_FORMAT_LIST_RESPONSE: + if ((error = cliprdr_server_receive_format_list_response(context, s, header))) + WLog_ERR(TAG, + "cliprdr_server_receive_format_list_response failed with error %" PRIu32 + "!", + error); + + break; + + case CB_LOCK_CLIPDATA: + if ((error = cliprdr_server_receive_lock_clipdata(context, s, header))) + WLog_ERR(TAG, "cliprdr_server_receive_lock_clipdata failed with error %" PRIu32 "!", + error); + + break; + + case CB_UNLOCK_CLIPDATA: + if ((error = cliprdr_server_receive_unlock_clipdata(context, s, header))) + WLog_ERR(TAG, + "cliprdr_server_receive_unlock_clipdata failed with error %" PRIu32 "!", + error); + + break; + + case CB_FORMAT_DATA_REQUEST: + if ((error = cliprdr_server_receive_format_data_request(context, s, header))) + WLog_ERR(TAG, + "cliprdr_server_receive_format_data_request failed with error %" PRIu32 + "!", + error); + + break; + + case CB_FORMAT_DATA_RESPONSE: + if ((error = cliprdr_server_receive_format_data_response(context, s, header))) + WLog_ERR(TAG, + "cliprdr_server_receive_format_data_response failed with error %" PRIu32 + "!", + error); + + break; + + case CB_FILECONTENTS_REQUEST: + if ((error = cliprdr_server_receive_filecontents_request(context, s, header))) + WLog_ERR(TAG, + "cliprdr_server_receive_filecontents_request failed with error %" PRIu32 + "!", + error); + + break; + + case CB_FILECONTENTS_RESPONSE: + if ((error = cliprdr_server_receive_filecontents_response(context, s, header))) + WLog_ERR(TAG, + "cliprdr_server_receive_filecontents_response failed with error %" PRIu32 + "!", + error); + + break; + + default: + error = ERROR_INVALID_DATA; + WLog_ERR(TAG, "Unexpected clipboard PDU type: %" PRIu16 "", header->msgType); + break; + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_init(CliprdrServerContext* context) +{ + UINT32 generalFlags = 0; + CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet = { 0 }; + UINT error = 0; + CLIPRDR_MONITOR_READY monitorReady = { 0 }; + CLIPRDR_CAPABILITIES capabilities = { 0 }; + + WINPR_ASSERT(context); + + monitorReady.common.msgType = CB_MONITOR_READY; + capabilities.common.msgType = CB_CLIP_CAPS; + + if (context->useLongFormatNames) + generalFlags |= CB_USE_LONG_FORMAT_NAMES; + + if (context->streamFileClipEnabled) + generalFlags |= CB_STREAM_FILECLIP_ENABLED; + + if (context->fileClipNoFilePaths) + generalFlags |= CB_FILECLIP_NO_FILE_PATHS; + + if (context->canLockClipData) + generalFlags |= CB_CAN_LOCK_CLIPDATA; + + if (context->hasHugeFileSupport) + generalFlags |= CB_HUGE_FILE_SUPPORT_ENABLED; + + capabilities.common.msgType = CB_CLIP_CAPS; + capabilities.common.msgFlags = 0; + capabilities.common.dataLen = 4 + CB_CAPSTYPE_GENERAL_LEN; + capabilities.cCapabilitiesSets = 1; + capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*)&generalCapabilitySet; + generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL; + generalCapabilitySet.capabilitySetLength = CB_CAPSTYPE_GENERAL_LEN; + generalCapabilitySet.version = CB_CAPS_VERSION_2; + generalCapabilitySet.generalFlags = generalFlags; + + if ((error = context->ServerCapabilities(context, &capabilities))) + { + WLog_ERR(TAG, "ServerCapabilities failed with error %" PRIu32 "!", error); + return error; + } + + if ((error = context->MonitorReady(context, &monitorReady))) + { + WLog_ERR(TAG, "MonitorReady failed with error %" PRIu32 "!", error); + return error; + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_read(CliprdrServerContext* context) +{ + wStream* s = NULL; + size_t position = 0; + DWORD BytesToRead = 0; + DWORD BytesReturned = 0; + CLIPRDR_HEADER header = { 0 }; + CliprdrServerPrivate* cliprdr = NULL; + UINT error = 0; + DWORD status = 0; + + WINPR_ASSERT(context); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + + s = cliprdr->s; + + if (Stream_GetPosition(s) < CLIPRDR_HEADER_LENGTH) + { + BytesReturned = 0; + BytesToRead = (UINT32)(CLIPRDR_HEADER_LENGTH - Stream_GetPosition(s)); + status = WaitForSingleObject(cliprdr->ChannelEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + if (status == WAIT_TIMEOUT) + return CHANNEL_RC_OK; + + if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0, Stream_Pointer(s), BytesToRead, + &BytesReturned)) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Seek(s, BytesReturned); + } + + if (Stream_GetPosition(s) >= CLIPRDR_HEADER_LENGTH) + { + position = Stream_GetPosition(s); + Stream_SetPosition(s, 0); + Stream_Read_UINT16(s, header.msgType); /* msgType (2 bytes) */ + Stream_Read_UINT16(s, header.msgFlags); /* msgFlags (2 bytes) */ + Stream_Read_UINT32(s, header.dataLen); /* dataLen (4 bytes) */ + + if (!Stream_EnsureRemainingCapacity(s, header.dataLen)) + { + WLog_ERR(TAG, "Stream_EnsureCapacity failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_SetPosition(s, position); + + if (Stream_GetPosition(s) < (header.dataLen + CLIPRDR_HEADER_LENGTH)) + { + BytesReturned = 0; + BytesToRead = + (UINT32)((header.dataLen + CLIPRDR_HEADER_LENGTH) - Stream_GetPosition(s)); + status = WaitForSingleObject(cliprdr->ChannelEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + if (status == WAIT_TIMEOUT) + return CHANNEL_RC_OK; + + if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0, Stream_Pointer(s), BytesToRead, + &BytesReturned)) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_Seek(s, BytesReturned); + } + + if (Stream_GetPosition(s) >= (header.dataLen + CLIPRDR_HEADER_LENGTH)) + { + Stream_SetPosition(s, (header.dataLen + CLIPRDR_HEADER_LENGTH)); + Stream_SealLength(s); + Stream_SetPosition(s, CLIPRDR_HEADER_LENGTH); + + if ((error = cliprdr_server_receive_pdu(context, s, &header))) + { + WLog_ERR(TAG, "cliprdr_server_receive_pdu failed with error code %" PRIu32 "!", + error); + return error; + } + + Stream_SetPosition(s, 0); + /* check for trailing zero bytes */ + status = WaitForSingleObject(cliprdr->ChannelEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + if (status == WAIT_TIMEOUT) + return CHANNEL_RC_OK; + + BytesReturned = 0; + BytesToRead = 4; + + if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0, Stream_Pointer(s), BytesToRead, + &BytesReturned)) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (BytesReturned == 4) + { + Stream_Read_UINT16(s, header.msgType); /* msgType (2 bytes) */ + Stream_Read_UINT16(s, header.msgFlags); /* msgFlags (2 bytes) */ + + if (!header.msgType) + { + /* ignore trailing bytes */ + Stream_SetPosition(s, 0); + } + } + else + { + Stream_Seek(s, BytesReturned); + } + } + } + + return CHANNEL_RC_OK; +} + +static DWORD WINAPI cliprdr_server_thread(LPVOID arg) +{ + DWORD status = 0; + DWORD nCount = 0; + HANDLE events[MAXIMUM_WAIT_OBJECTS] = { 0 }; + HANDLE ChannelEvent = NULL; + CliprdrServerContext* context = (CliprdrServerContext*)arg; + CliprdrServerPrivate* cliprdr = NULL; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + + ChannelEvent = context->GetEventHandle(context); + + events[nCount++] = cliprdr->StopEvent; + events[nCount++] = ChannelEvent; + + if (context->autoInitializationSequence) + { + if ((error = cliprdr_server_init(context))) + { + WLog_ERR(TAG, "cliprdr_server_init failed with error %" PRIu32 "!", error); + goto out; + } + } + + while (1) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error); + goto out; + } + + status = WaitForSingleObject(cliprdr->StopEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + goto out; + } + + if (status == WAIT_OBJECT_0) + break; + + status = WaitForSingleObject(ChannelEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + goto out; + } + + if (status == WAIT_OBJECT_0) + { + if ((error = context->CheckEventHandle(context))) + { + WLog_ERR(TAG, "CheckEventHandle failed with error %" PRIu32 "!", error); + break; + } + } + } + +out: + + if (error && context->rdpcontext) + setChannelError(context->rdpcontext, error, "cliprdr_server_thread reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_open(CliprdrServerContext* context) +{ + void* buffer = NULL; + DWORD BytesReturned = 0; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + + cliprdr->ChannelHandle = + WTSVirtualChannelOpen(cliprdr->vcm, WTS_CURRENT_SESSION, CLIPRDR_SVC_CHANNEL_NAME); + + if (!cliprdr->ChannelHandle) + { + WLog_ERR(TAG, "WTSVirtualChannelOpen for cliprdr failed!"); + return ERROR_INTERNAL_ERROR; + } + + cliprdr->ChannelEvent = NULL; + + if (WTSVirtualChannelQuery(cliprdr->ChannelHandle, WTSVirtualEventHandle, &buffer, + &BytesReturned)) + { + if (BytesReturned != sizeof(HANDLE)) + { + WLog_ERR(TAG, "BytesReturned has not size of HANDLE!"); + return ERROR_INTERNAL_ERROR; + } + + cliprdr->ChannelEvent = *(HANDLE*)buffer; + WTSFreeMemory(buffer); + } + + if (!cliprdr->ChannelEvent) + { + WLog_ERR(TAG, "WTSVirtualChannelQuery for cliprdr failed!"); + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_close(CliprdrServerContext* context) +{ + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + + if (cliprdr->ChannelHandle) + { + (void)WTSVirtualChannelClose(cliprdr->ChannelHandle); + cliprdr->ChannelHandle = NULL; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_start(CliprdrServerContext* context) +{ + UINT error = 0; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + + if (!cliprdr->ChannelHandle) + { + if ((error = context->Open(context))) + { + WLog_ERR(TAG, "Open failed!"); + return error; + } + } + + if (!(cliprdr->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (!(cliprdr->Thread = CreateThread(NULL, 0, cliprdr_server_thread, (void*)context, 0, NULL))) + { + WLog_ERR(TAG, "CreateThread failed!"); + (void)CloseHandle(cliprdr->StopEvent); + cliprdr->StopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_stop(CliprdrServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + + if (cliprdr->StopEvent) + { + (void)SetEvent(cliprdr->StopEvent); + + if (WaitForSingleObject(cliprdr->Thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(cliprdr->Thread); + (void)CloseHandle(cliprdr->StopEvent); + } + + if (cliprdr->ChannelHandle) + return context->Close(context); + + return error; +} + +static HANDLE cliprdr_server_get_event_handle(CliprdrServerContext* context) +{ + CliprdrServerPrivate* cliprdr = NULL; + + WINPR_ASSERT(context); + + cliprdr = (CliprdrServerPrivate*)context->handle; + WINPR_ASSERT(cliprdr); + return cliprdr->ChannelEvent; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cliprdr_server_check_event_handle(CliprdrServerContext* context) +{ + return cliprdr_server_read(context); +} + +CliprdrServerContext* cliprdr_server_context_new(HANDLE vcm) +{ + CliprdrServerPrivate* cliprdr = NULL; + CliprdrServerContext* context = (CliprdrServerContext*)calloc(1, sizeof(CliprdrServerContext)); + + if (context) + { + context->autoInitializationSequence = TRUE; + context->Open = cliprdr_server_open; + context->Close = cliprdr_server_close; + context->Start = cliprdr_server_start; + context->Stop = cliprdr_server_stop; + context->GetEventHandle = cliprdr_server_get_event_handle; + context->CheckEventHandle = cliprdr_server_check_event_handle; + context->ServerCapabilities = cliprdr_server_capabilities; + context->MonitorReady = cliprdr_server_monitor_ready; + context->ServerFormatList = cliprdr_server_format_list; + context->ServerFormatListResponse = cliprdr_server_format_list_response; + context->ServerLockClipboardData = cliprdr_server_lock_clipboard_data; + context->ServerUnlockClipboardData = cliprdr_server_unlock_clipboard_data; + context->ServerFormatDataRequest = cliprdr_server_format_data_request; + context->ServerFormatDataResponse = cliprdr_server_format_data_response; + context->ServerFileContentsRequest = cliprdr_server_file_contents_request; + context->ServerFileContentsResponse = cliprdr_server_file_contents_response; + cliprdr = context->handle = (CliprdrServerPrivate*)calloc(1, sizeof(CliprdrServerPrivate)); + + if (cliprdr) + { + cliprdr->vcm = vcm; + cliprdr->s = Stream_New(NULL, 4096); + + if (!cliprdr->s) + { + WLog_ERR(TAG, "Stream_New failed!"); + free(context->handle); + free(context); + return NULL; + } + } + else + { + WLog_ERR(TAG, "calloc failed!"); + free(context); + return NULL; + } + } + + return context; +} + +void cliprdr_server_context_free(CliprdrServerContext* context) +{ + CliprdrServerPrivate* cliprdr = NULL; + + if (!context) + return; + + cliprdr = (CliprdrServerPrivate*)context->handle; + + if (cliprdr) + { + Stream_Free(cliprdr->s, TRUE); + } + + free(context->handle); + free(context); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/cliprdr_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/cliprdr_main.h new file mode 100644 index 0000000000000000000000000000000000000000..f2e71624c8b7a9fc34d8c57eb7be5767675a912a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/cliprdr/server/cliprdr_main.h @@ -0,0 +1,47 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CLIPRDR_SERVER_MAIN_H +#define FREERDP_CHANNEL_CLIPRDR_SERVER_MAIN_H + +#include +#include +#include +#include + +#include +#include + +#define TAG CHANNELS_TAG("cliprdr.server") + +#define CLIPRDR_HEADER_LENGTH 8 + +typedef struct +{ + HANDLE vcm; + HANDLE Thread; + HANDLE StopEvent; + void* ChannelHandle; + HANDLE ChannelEvent; + + wStream* s; + char temporaryDirectory[260]; +} CliprdrServerPrivate; + +#endif /* FREERDP_CHANNEL_CLIPRDR_SERVER_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/disp/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..04281c0f3a098499499f4bc159934156093e6a1c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("disp") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/disp/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..416ec17684cb5ea0c3a9c146fab770f4f930cb8c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "disp" + TYPE + "dynamic" + DESCRIPTION + "Display Update Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEDISP]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/disp/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6287e09b11a098df49072384fb009d120525b126 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/client/CMakeLists.txt @@ -0,0 +1,25 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2013 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("disp") + +set(${MODULE_PREFIX}_SRCS disp_main.c disp_main.h ../disp_common.c ../disp_common.h) + +set(${MODULE_PREFIX}_LIBS winpr) +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/disp/disp_common.c b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/disp_common.c new file mode 100644 index 0000000000000000000000000000000000000000..9387691ead501db92970f336c4cd09f165003aad --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/disp_common.c @@ -0,0 +1,55 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPEDISP Virtual Channel Extension + * + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#define TAG CHANNELS_TAG("disp.common") + +#include "disp_common.h" + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT disp_read_header(wStream* s, DISPLAY_CONTROL_HEADER* header) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, header->type); + Stream_Read_UINT32(s, header->length); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT disp_write_header(wStream* s, const DISPLAY_CONTROL_HEADER* header) +{ + Stream_Write_UINT32(s, header->type); + Stream_Write_UINT32(s, header->length); + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/disp/disp_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/disp_common.h new file mode 100644 index 0000000000000000000000000000000000000000..386b8b39dde88405d447f5cb3659a6f82a46aafd --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/disp_common.h @@ -0,0 +1,32 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPEDISP Virtual Channel Extension + * + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DISP_COMMON_H +#define FREERDP_CHANNEL_DISP_COMMON_H + +#include +#include + +#include +#include + +FREERDP_LOCAL UINT disp_read_header(wStream* s, DISPLAY_CONTROL_HEADER* header); +FREERDP_LOCAL UINT disp_write_header(wStream* s, const DISPLAY_CONTROL_HEADER* header); + +#endif /* FREERDP_CHANNEL_DISP_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/disp/server/disp_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/server/disp_main.c new file mode 100644 index 0000000000000000000000000000000000000000..45cd82359012f783d53bdd2a4e800f14c66b9732 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/disp/server/disp_main.c @@ -0,0 +1,639 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPEDISP Virtual Channel Extension + * + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "disp_main.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "../disp_common.h" + +#define TAG CHANNELS_TAG("rdpedisp.server") + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ + +static wStream* disp_server_single_packet_new(UINT32 type, UINT32 length) +{ + UINT error = 0; + DISPLAY_CONTROL_HEADER header; + wStream* s = Stream_New(NULL, DISPLAY_CONTROL_HEADER_LENGTH + length); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + goto error; + } + + header.type = type; + header.length = DISPLAY_CONTROL_HEADER_LENGTH + length; + + if ((error = disp_write_header(s, &header))) + { + WLog_ERR(TAG, "Failed to write header with error %" PRIu32 "!", error); + goto error; + } + + return s; +error: + Stream_Free(s, TRUE); + return NULL; +} + +static void disp_server_sanitize_monitor_layout(DISPLAY_CONTROL_MONITOR_LAYOUT* monitor) +{ + if (monitor->PhysicalWidth < DISPLAY_CONTROL_MIN_PHYSICAL_MONITOR_WIDTH || + monitor->PhysicalWidth > DISPLAY_CONTROL_MAX_PHYSICAL_MONITOR_WIDTH || + monitor->PhysicalHeight < DISPLAY_CONTROL_MIN_PHYSICAL_MONITOR_HEIGHT || + monitor->PhysicalHeight > DISPLAY_CONTROL_MAX_PHYSICAL_MONITOR_HEIGHT) + { + if (monitor->PhysicalWidth != 0 || monitor->PhysicalHeight != 0) + WLog_DBG( + TAG, + "Sanitizing invalid physical monitor size. Old physical monitor size: [%" PRIu32 + ", %" PRIu32 "]", + monitor->PhysicalWidth, monitor->PhysicalHeight); + + monitor->PhysicalWidth = monitor->PhysicalHeight = 0; + } +} + +static BOOL disp_server_is_monitor_layout_valid(const DISPLAY_CONTROL_MONITOR_LAYOUT* monitor) +{ + WINPR_ASSERT(monitor); + + if (monitor->Width < DISPLAY_CONTROL_MIN_MONITOR_WIDTH || + monitor->Width > DISPLAY_CONTROL_MAX_MONITOR_WIDTH) + { + WLog_WARN(TAG, "Received invalid value for monitor->Width: %" PRIu32 "", monitor->Width); + return FALSE; + } + + if (monitor->Height < DISPLAY_CONTROL_MIN_MONITOR_HEIGHT || + monitor->Height > DISPLAY_CONTROL_MAX_MONITOR_HEIGHT) + { + WLog_WARN(TAG, "Received invalid value for monitor->Height: %" PRIu32 "", monitor->Height); + return FALSE; + } + + switch (monitor->Orientation) + { + case ORIENTATION_LANDSCAPE: + case ORIENTATION_PORTRAIT: + case ORIENTATION_LANDSCAPE_FLIPPED: + case ORIENTATION_PORTRAIT_FLIPPED: + break; + + default: + WLog_WARN(TAG, "Received incorrect value for monitor->Orientation: %" PRIu32 "", + monitor->Orientation); + return FALSE; + } + + return TRUE; +} + +static UINT disp_recv_display_control_monitor_layout_pdu(wStream* s, DispServerContext* context) +{ + UINT32 error = CHANNEL_RC_OK; + DISPLAY_CONTROL_MONITOR_LAYOUT_PDU pdu = { 0 }; + + WINPR_ASSERT(s); + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, pdu.MonitorLayoutSize); /* MonitorLayoutSize (4 bytes) */ + + if (pdu.MonitorLayoutSize != DISPLAY_CONTROL_MONITOR_LAYOUT_SIZE) + { + WLog_ERR(TAG, "MonitorLayoutSize is set to %" PRIu32 ". expected %" PRIu32 "", + pdu.MonitorLayoutSize, DISPLAY_CONTROL_MONITOR_LAYOUT_SIZE); + return ERROR_INVALID_DATA; + } + + Stream_Read_UINT32(s, pdu.NumMonitors); /* NumMonitors (4 bytes) */ + + if (pdu.NumMonitors > context->MaxNumMonitors) + { + WLog_ERR(TAG, "NumMonitors (%" PRIu32 ")> server MaxNumMonitors (%" PRIu32 ")", + pdu.NumMonitors, context->MaxNumMonitors); + return ERROR_INVALID_DATA; + } + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, pdu.NumMonitors, + DISPLAY_CONTROL_MONITOR_LAYOUT_SIZE)) + return ERROR_INVALID_DATA; + + pdu.Monitors = (DISPLAY_CONTROL_MONITOR_LAYOUT*)calloc(pdu.NumMonitors, + sizeof(DISPLAY_CONTROL_MONITOR_LAYOUT)); + + if (!pdu.Monitors) + { + WLog_ERR(TAG, "disp_recv_display_control_monitor_layout_pdu(): calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + WLog_DBG(TAG, "disp_recv_display_control_monitor_layout_pdu: NumMonitors=%" PRIu32 "", + pdu.NumMonitors); + + for (UINT32 index = 0; index < pdu.NumMonitors; index++) + { + DISPLAY_CONTROL_MONITOR_LAYOUT* monitor = &(pdu.Monitors[index]); + + Stream_Read_UINT32(s, monitor->Flags); /* Flags (4 bytes) */ + Stream_Read_INT32(s, monitor->Left); /* Left (4 bytes) */ + Stream_Read_INT32(s, monitor->Top); /* Top (4 bytes) */ + Stream_Read_UINT32(s, monitor->Width); /* Width (4 bytes) */ + Stream_Read_UINT32(s, monitor->Height); /* Height (4 bytes) */ + Stream_Read_UINT32(s, monitor->PhysicalWidth); /* PhysicalWidth (4 bytes) */ + Stream_Read_UINT32(s, monitor->PhysicalHeight); /* PhysicalHeight (4 bytes) */ + Stream_Read_UINT32(s, monitor->Orientation); /* Orientation (4 bytes) */ + Stream_Read_UINT32(s, monitor->DesktopScaleFactor); /* DesktopScaleFactor (4 bytes) */ + Stream_Read_UINT32(s, monitor->DeviceScaleFactor); /* DeviceScaleFactor (4 bytes) */ + + disp_server_sanitize_monitor_layout(monitor); + WLog_DBG(TAG, + "\t%" PRIu32 " : Flags: 0x%08" PRIX32 " Left/Top: (%" PRId32 ",%" PRId32 + ") W/H=%" PRIu32 "x%" PRIu32 ")", + index, monitor->Flags, monitor->Left, monitor->Top, monitor->Width, + monitor->Height); + WLog_DBG(TAG, + "\t PhysicalWidth: %" PRIu32 " PhysicalHeight: %" PRIu32 " Orientation: %" PRIu32 + "", + monitor->PhysicalWidth, monitor->PhysicalHeight, monitor->Orientation); + + if (!disp_server_is_monitor_layout_valid(monitor)) + { + error = ERROR_INVALID_DATA; + goto out; + } + } + + if (context) + IFCALLRET(context->DispMonitorLayout, error, context, &pdu); + +out: + free(pdu.Monitors); + return error; +} + +static UINT disp_server_receive_pdu(DispServerContext* context, wStream* s) +{ + UINT error = CHANNEL_RC_OK; + size_t beg = 0; + size_t end = 0; + DISPLAY_CONTROL_HEADER header = { 0 }; + + WINPR_ASSERT(s); + WINPR_ASSERT(context); + + beg = Stream_GetPosition(s); + + if ((error = disp_read_header(s, &header))) + { + WLog_ERR(TAG, "disp_read_header failed with error %" PRIu32 "!", error); + return error; + } + + switch (header.type) + { + case DISPLAY_CONTROL_PDU_TYPE_MONITOR_LAYOUT: + if ((error = disp_recv_display_control_monitor_layout_pdu(s, context))) + WLog_ERR(TAG, + "disp_recv_display_control_monitor_layout_pdu " + "failed with error %" PRIu32 "!", + error); + + break; + + default: + error = CHANNEL_RC_BAD_PROC; + WLog_WARN(TAG, "Received unknown PDU type: %" PRIu32 "", header.type); + break; + } + + end = Stream_GetPosition(s); + + if (end != (beg + header.length)) + { + WLog_ERR(TAG, "Unexpected DISP pdu end: Actual: %" PRIuz ", Expected: %" PRIuz "", end, + (beg + header.length)); + Stream_SetPosition(s, (beg + header.length)); + } + + return error; +} + +static UINT disp_server_handle_messages(DispServerContext* context) +{ + DWORD BytesReturned = 0; + void* buffer = NULL; + UINT ret = CHANNEL_RC_OK; + DispServerPrivate* priv = NULL; + wStream* s = NULL; + + WINPR_ASSERT(context); + + priv = context->priv; + WINPR_ASSERT(priv); + + s = priv->input_stream; + WINPR_ASSERT(s); + + /* Check whether the dynamic channel is ready */ + if (!priv->isReady) + { + if (WTSVirtualChannelQuery(priv->disp_channel, WTSVirtualChannelReady, &buffer, + &BytesReturned) == FALSE) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_ERR(TAG, "WTSVirtualChannelQuery failed"); + return ERROR_INTERNAL_ERROR; + } + + priv->isReady = *((BOOL*)buffer); + WTSFreeMemory(buffer); + } + + /* Consume channel event only after the disp dynamic channel is ready */ + Stream_SetPosition(s, 0); + + if (!WTSVirtualChannelRead(priv->disp_channel, 0, NULL, 0, &BytesReturned)) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (BytesReturned < 1) + return CHANNEL_RC_OK; + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + const size_t cap = Stream_Capacity(s); + if (cap > UINT32_MAX) + return CHANNEL_RC_NO_BUFFER; + + if (WTSVirtualChannelRead(priv->disp_channel, 0, Stream_BufferAs(s, char), (ULONG)cap, + &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_SetLength(s, BytesReturned); + Stream_SetPosition(s, 0); + + while (Stream_GetPosition(s) < Stream_Length(s)) + { + if ((ret = disp_server_receive_pdu(context, s))) + { + WLog_ERR(TAG, + "disp_server_receive_pdu " + "failed with error %" PRIu32 "!", + ret); + return ret; + } + } + + return ret; +} + +static DWORD WINAPI disp_server_thread_func(LPVOID arg) +{ + DispServerContext* context = (DispServerContext*)arg; + DispServerPrivate* priv = NULL; + DWORD status = 0; + DWORD nCount = 0; + HANDLE events[8] = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + + priv = context->priv; + WINPR_ASSERT(priv); + + events[nCount++] = priv->stopEvent; + events[nCount++] = priv->channelEvent; + + /* Main virtual channel loop. RDPEDISP do not need version negotiation */ + while (TRUE) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error); + break; + } + + /* Stop Event */ + if (status == WAIT_OBJECT_0) + break; + + if ((error = disp_server_handle_messages(context))) + { + WLog_ERR(TAG, "disp_server_handle_messages failed with error %" PRIu32 "", error); + break; + } + } + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT disp_server_open(DispServerContext* context) +{ + UINT rc = ERROR_INTERNAL_ERROR; + DispServerPrivate* priv = NULL; + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + void* buffer = NULL; + UINT32 channelId = 0; + BOOL status = TRUE; + + WINPR_ASSERT(context); + + priv = context->priv; + WINPR_ASSERT(priv); + + priv->SessionId = WTS_CURRENT_SESSION; + + if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + + priv->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + priv->disp_channel = + WTSVirtualChannelOpenEx(priv->SessionId, DISP_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC); + + if (!priv->disp_channel) + { + WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed!"); + rc = GetLastError(); + goto out_close; + } + + channelId = WTSChannelGetIdByHandle(priv->disp_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + + /* Query for channel event handle */ + if (!WTSVirtualChannelQuery(priv->disp_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) || + (BytesReturned != sizeof(HANDLE))) + { + WLog_ERR(TAG, + "WTSVirtualChannelQuery failed " + "or invalid returned size(%" PRIu32 ")", + BytesReturned); + + if (buffer) + WTSFreeMemory(buffer); + + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + + priv->channelEvent = *(HANDLE*)buffer; + WTSFreeMemory(buffer); + + if (priv->thread == NULL) + { + if (!(priv->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + + if (!(priv->thread = + CreateThread(NULL, 0, disp_server_thread_func, (void*)context, 0, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + (void)CloseHandle(priv->stopEvent); + priv->stopEvent = NULL; + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + } + + return CHANNEL_RC_OK; +out_close: + (void)WTSVirtualChannelClose(priv->disp_channel); + priv->disp_channel = NULL; + priv->channelEvent = NULL; + return rc; +} + +static UINT disp_server_packet_send(DispServerContext* context, wStream* s) +{ + UINT ret = 0; + ULONG written = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(s); + + const size_t pos = Stream_GetPosition(s); + + WINPR_ASSERT(pos <= UINT32_MAX); + if (!WTSVirtualChannelWrite(context->priv->disp_channel, Stream_BufferAs(s, char), (UINT32)pos, + &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + ret = ERROR_INTERNAL_ERROR; + goto out; + } + + if (written < Stream_GetPosition(s)) + { + WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written, + Stream_GetPosition(s)); + } + + ret = CHANNEL_RC_OK; +out: + Stream_Free(s, TRUE); + return ret; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT disp_server_send_caps_pdu(DispServerContext* context) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + + s = disp_server_single_packet_new(DISPLAY_CONTROL_PDU_TYPE_CAPS, 12); + + if (!s) + { + WLog_ERR(TAG, "disp_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, context->MaxNumMonitors); /* MaxNumMonitors (4 bytes) */ + Stream_Write_UINT32(s, context->MaxMonitorAreaFactorA); /* MaxMonitorAreaFactorA (4 bytes) */ + Stream_Write_UINT32(s, context->MaxMonitorAreaFactorB); /* MaxMonitorAreaFactorB (4 bytes) */ + return disp_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT disp_server_close(DispServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + DispServerPrivate* priv = NULL; + + WINPR_ASSERT(context); + + priv = context->priv; + WINPR_ASSERT(priv); + + if (priv->thread) + { + (void)SetEvent(priv->stopEvent); + + if (WaitForSingleObject(priv->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(priv->thread); + (void)CloseHandle(priv->stopEvent); + priv->thread = NULL; + priv->stopEvent = NULL; + } + + if (priv->disp_channel) + { + (void)WTSVirtualChannelClose(priv->disp_channel); + priv->disp_channel = NULL; + } + + return error; +} + +DispServerContext* disp_server_context_new(HANDLE vcm) +{ + DispServerContext* context = NULL; + DispServerPrivate* priv = NULL; + context = (DispServerContext*)calloc(1, sizeof(DispServerContext)); + + if (!context) + { + WLog_ERR(TAG, "disp_server_context_new(): calloc DispServerContext failed!"); + goto fail; + } + + priv = context->priv = (DispServerPrivate*)calloc(1, sizeof(DispServerPrivate)); + + if (!context->priv) + { + WLog_ERR(TAG, "disp_server_context_new(): calloc DispServerPrivate failed!"); + goto fail; + } + + priv->input_stream = Stream_New(NULL, 4); + + if (!priv->input_stream) + { + WLog_ERR(TAG, "Stream_New failed!"); + goto fail; + } + + context->vcm = vcm; + context->Open = disp_server_open; + context->Close = disp_server_close; + context->DisplayControlCaps = disp_server_send_caps_pdu; + priv->isReady = FALSE; + return context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + disp_server_context_free(context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void disp_server_context_free(DispServerContext* context) +{ + if (!context) + return; + + if (context->priv) + { + disp_server_close(context); + Stream_Free(context->priv->input_stream, TRUE); + free(context->priv); + } + + free(context); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..eca79c772dc86016ab3786b749fe3ebae6ada5dc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("drdynvc") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..22652bbc29bfb93ac706b4d39bb854ecd0d463eb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "drdynvc" + TYPE + "static" + DESCRIPTION + "Dynamic Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEDYC]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b9cc206c4a71832173a0bdecf12f05f19457e2f5 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/client/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("drdynvc") + +set(${MODULE_PREFIX}_SRCS drdynvc_main.c drdynvc_main.h) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntryEx") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/client/drdynvc_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/client/drdynvc_main.h new file mode 100644 index 0000000000000000000000000000000000000000..c282cdd61b99f04830df87a07dca55dde40c2cd3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/client/drdynvc_main.h @@ -0,0 +1,133 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DRDYNVC_CLIENT_MAIN_H +#define FREERDP_CHANNEL_DRDYNVC_CLIENT_MAIN_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +typedef struct drdynvc_plugin drdynvcPlugin; + +typedef struct +{ + IWTSVirtualChannelManager iface; + + drdynvcPlugin* drdynvc; + + wArrayList* plugin_names; + wArrayList* plugins; + + wHashTable* listeners; + wHashTable* channelsById; + wStreamPool* pool; +} DVCMAN; + +typedef struct +{ + IWTSListener iface; + + DVCMAN* dvcman; + char* channel_name; + UINT32 flags; + IWTSListenerCallback* listener_callback; +} DVCMAN_LISTENER; + +typedef struct +{ + IDRDYNVC_ENTRY_POINTS iface; + + DVCMAN* dvcman; + const ADDIN_ARGV* args; + rdpContext* context; +} DVCMAN_ENTRY_POINTS; + +typedef enum +{ + DVC_CHANNEL_INIT, + DVC_CHANNEL_RUNNING, + DVC_CHANNEL_CLOSED +} DVC_CHANNEL_STATE; + +typedef struct +{ + IWTSVirtualChannel iface; + + volatile LONG refCounter; + DVC_CHANNEL_STATE state; + DVCMAN* dvcman; + void* pInterface; + UINT32 channel_id; + char* channel_name; + IWTSVirtualChannelCallback* channel_callback; + + wStream* dvc_data; + UINT32 dvc_data_length; + CRITICAL_SECTION lock; +} DVCMAN_CHANNEL; + +typedef enum +{ + DRDYNVC_STATE_INITIAL, + DRDYNVC_STATE_CAPABILITIES, + DRDYNVC_STATE_READY, + DRDYNVC_STATE_OPENING_CHANNEL, + DRDYNVC_STATE_SEND_RECEIVE, + DRDYNVC_STATE_FINAL +} DRDYNVC_STATE; + +struct drdynvc_plugin +{ + CHANNEL_DEF channelDef; + CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints; + + wLog* log; + HANDLE thread; + BOOL async; + wStream* data_in; + void* InitHandle; + DWORD OpenHandle; + wMessageQueue* queue; + + DRDYNVC_STATE state; + DrdynvcClientContext* context; + + UINT16 version; + int PriorityCharge0; + int PriorityCharge1; + int PriorityCharge2; + int PriorityCharge3; + rdpContext* rdpcontext; + + IWTSVirtualChannelManager* channel_mgr; +}; + +#endif /* FREERDP_CHANNEL_DRDYNVC_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/server/drdynvc_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/server/drdynvc_main.h new file mode 100644 index 0000000000000000000000000000000000000000..4456d95bcfb0655df159c4b3dc1893fb040ef8bb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/drdynvc/server/drdynvc_main.h @@ -0,0 +1,37 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DRDYNVC_SERVER_MAIN_H +#define FREERDP_CHANNEL_DRDYNVC_SERVER_MAIN_H + +#include +#include +#include + +#include +#include + +struct s_drdynvc_server_private +{ + HANDLE Thread; + HANDLE StopEvent; + void* ChannelHandle; +}; + +#endif /* FREERDP_CHANNEL_DRDYNVC_SERVER_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/drive/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/drive/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b6af794ff707c0e812757fba632871083311c0a3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/drive/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("drive") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/drive/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/drive/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..3d11f1fe7205003660d0722b363182a5fa602497 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/drive/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options( + NAME + "drive" + TYPE + "device" + DESCRIPTION + "Drive Redirection Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEFS]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/echo/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..35b45a7885a9466b8ab99cccb1bcf5d474903d6d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("echo") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/echo/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..d805b58a1b907a1a96f228fe366b8966fce614e0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "echo" + TYPE + "dynamic" + DESCRIPTION + "Echo Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEECO]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..777beaf230e32ba3aa5fbcdcfc7e7975960842d2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/CMakeLists.txt @@ -0,0 +1,25 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("echo") + +set(${MODULE_PREFIX}_SRCS echo_main.c echo_main.h) + +set(${MODULE_PREFIX}_LIBS winpr) +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/echo_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/echo_main.c new file mode 100644 index 0000000000000000000000000000000000000000..af6baafb52980a4b3d1c76a51330b2104ee9e4af --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/echo_main.c @@ -0,0 +1,92 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Echo Virtual Channel Extension + * + * Copyright 2013 Christian Hofstaedtler + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include +#include + +#include "echo_main.h" +#include +#include +#include + +#define TAG CHANNELS_TAG("echo.client") + +typedef struct +{ + GENERIC_DYNVC_PLUGIN baseDynPlugin; +} ECHO_PLUGIN; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT echo_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + const BYTE* pBuffer = Stream_ConstPointer(data); + const size_t cbSize = Stream_GetRemainingLength(data); + + WINPR_ASSERT(callback); + WINPR_ASSERT(callback->channel); + WINPR_ASSERT(callback->channel->Write); + + if (cbSize > UINT32_MAX) + return ERROR_INVALID_PARAMETER; + + /* echo back what we have received. ECHO does not have any message IDs. */ + return callback->channel->Write(callback->channel, (ULONG)cbSize, pBuffer, NULL); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT echo_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + + free(callback); + + return CHANNEL_RC_OK; +} + +static const IWTSVirtualChannelCallback echo_callbacks = { echo_on_data_received, NULL, /* Open */ + echo_on_close, NULL }; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE echo_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, ECHO_DVC_CHANNEL_NAME, + sizeof(ECHO_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK), + &echo_callbacks, NULL, NULL); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/echo_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/echo_main.h new file mode 100644 index 0000000000000000000000000000000000000000..1286371f8ba0cf451bfd5fdc4af94b7c615fef15 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/client/echo_main.h @@ -0,0 +1,40 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Echo Virtual Channel Extension + * + * Copyright 2013 Christian Hofstaedtler + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_ECHO_CLIENT_MAIN_H +#define FREERDP_CHANNEL_ECHO_CLIENT_MAIN_H + +#include + +#include +#include +#include +#include + +#define DVC_TAG CHANNELS_TAG("echo.client") +#ifdef WITH_DEBUG_DVC +#define DEBUG_DVC(...) WLog_DBG(DVC_TAG, __VA_ARGS__) +#else +#define DEBUG_DVC(...) \ + do \ + { \ + } while (0) +#endif + +#endif /* FREERDP_CHANNEL_ECHO_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/echo/server/echo_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/server/echo_main.c new file mode 100644 index 0000000000000000000000000000000000000000..7a00e31703ff63b27d5fb816274daf52697dd98c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/echo/server/echo_main.c @@ -0,0 +1,385 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Echo Virtual Channel Extension + * + * Copyright 2014 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("echo.server") + +typedef struct +{ + echo_server_context context; + + BOOL opened; + + HANDLE stopEvent; + + HANDLE thread; + void* echo_channel; + + DWORD SessionId; + +} echo_server; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT echo_server_open_channel(echo_server* echo) +{ + DWORD Error = 0; + HANDLE hEvent = NULL; + DWORD StartTick = 0; + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + + if (WTSQuerySessionInformationA(echo->context.vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + return ERROR_INTERNAL_ERROR; + } + + echo->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + hEvent = WTSVirtualChannelManagerGetEventHandle(echo->context.vcm); + StartTick = GetTickCount(); + + while (echo->echo_channel == NULL) + { + if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED) + { + Error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", Error); + return Error; + } + + echo->echo_channel = WTSVirtualChannelOpenEx(echo->SessionId, ECHO_DVC_CHANNEL_NAME, + WTS_CHANNEL_OPTION_DYNAMIC); + + if (echo->echo_channel) + { + UINT32 channelId = 0; + BOOL status = TRUE; + + channelId = WTSChannelGetIdByHandle(echo->echo_channel); + + IFCALLRET(echo->context.ChannelIdAssigned, status, &echo->context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + + break; + } + + Error = GetLastError(); + + if (Error == ERROR_NOT_FOUND) + break; + + if (GetTickCount() - StartTick > 5000) + break; + } + + return echo->echo_channel ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; +} + +static DWORD WINAPI echo_server_thread_func(LPVOID arg) +{ + wStream* s = NULL; + void* buffer = NULL; + DWORD nCount = 0; + HANDLE events[8]; + BOOL ready = FALSE; + HANDLE ChannelEvent = NULL; + DWORD BytesReturned = 0; + echo_server* echo = (echo_server*)arg; + UINT error = 0; + DWORD status = 0; + + if ((error = echo_server_open_channel(echo))) + { + UINT error2 = 0; + WLog_ERR(TAG, "echo_server_open_channel failed with error %" PRIu32 "!", error); + IFCALLRET(echo->context.OpenResult, error2, &echo->context, + ECHO_SERVER_OPEN_RESULT_NOTSUPPORTED); + + if (error2) + WLog_ERR(TAG, "echo server's OpenResult callback failed with error %" PRIu32 "", + error2); + + goto out; + } + + buffer = NULL; + BytesReturned = 0; + ChannelEvent = NULL; + + if (WTSVirtualChannelQuery(echo->echo_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) == TRUE) + { + if (BytesReturned == sizeof(HANDLE)) + ChannelEvent = *(HANDLE*)buffer; + + WTSFreeMemory(buffer); + } + + nCount = 0; + events[nCount++] = echo->stopEvent; + events[nCount++] = ChannelEvent; + + /* Wait for the client to confirm that the Graphics Pipeline dynamic channel is ready */ + + while (1) + { + status = WaitForMultipleObjects(nCount, events, FALSE, 100); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error); + break; + } + + if (status == WAIT_OBJECT_0) + { + IFCALLRET(echo->context.OpenResult, error, &echo->context, + ECHO_SERVER_OPEN_RESULT_CLOSED); + + if (error) + WLog_ERR(TAG, "OpenResult failed with error %" PRIu32 "!", error); + + break; + } + + if (WTSVirtualChannelQuery(echo->echo_channel, WTSVirtualChannelReady, &buffer, + &BytesReturned) == FALSE) + { + IFCALLRET(echo->context.OpenResult, error, &echo->context, + ECHO_SERVER_OPEN_RESULT_ERROR); + + if (error) + WLog_ERR(TAG, "OpenResult failed with error %" PRIu32 "!", error); + + break; + } + + ready = *((BOOL*)buffer); + WTSFreeMemory(buffer); + + if (ready) + { + IFCALLRET(echo->context.OpenResult, error, &echo->context, ECHO_SERVER_OPEN_RESULT_OK); + + if (error) + WLog_ERR(TAG, "OpenResult failed with error %" PRIu32 "!", error); + + break; + } + } + + s = Stream_New(NULL, 4096); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + (void)WTSVirtualChannelClose(echo->echo_channel); + ExitThread(ERROR_NOT_ENOUGH_MEMORY); + return ERROR_NOT_ENOUGH_MEMORY; + } + + while (ready) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error); + break; + } + + if (status == WAIT_OBJECT_0) + break; + + Stream_SetPosition(s, 0); + if (!WTSVirtualChannelRead(echo->echo_channel, 0, NULL, 0, &BytesReturned)) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (BytesReturned < 1) + continue; + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + error = CHANNEL_RC_NO_MEMORY; + break; + } + + if (WTSVirtualChannelRead(echo->echo_channel, 0, Stream_BufferAs(s, char), + (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + IFCALLRET(echo->context.Response, error, &echo->context, Stream_Buffer(s), BytesReturned); + + if (error) + { + WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error); + break; + } + } + + Stream_Free(s, TRUE); + (void)WTSVirtualChannelClose(echo->echo_channel); + echo->echo_channel = NULL; +out: + + if (error && echo->context.rdpcontext) + setChannelError(echo->context.rdpcontext, error, + "echo_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT echo_server_open(echo_server_context* context) +{ + echo_server* echo = (echo_server*)context; + + if (echo->thread == NULL) + { + if (!(echo->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (!(echo->thread = CreateThread(NULL, 0, echo_server_thread_func, (void*)echo, 0, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + (void)CloseHandle(echo->stopEvent); + echo->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT echo_server_close(echo_server_context* context) +{ + UINT error = CHANNEL_RC_OK; + echo_server* echo = (echo_server*)context; + + if (echo->thread) + { + (void)SetEvent(echo->stopEvent); + + if (WaitForSingleObject(echo->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(echo->thread); + (void)CloseHandle(echo->stopEvent); + echo->thread = NULL; + echo->stopEvent = NULL; + } + + return error; +} + +static BOOL echo_server_request(echo_server_context* context, const BYTE* buffer, UINT32 length) +{ + union + { + const BYTE* cpv; + CHAR* pv; + } cnv; + cnv.cpv = buffer; + echo_server* echo = (echo_server*)context; + WINPR_ASSERT(echo); + + return WTSVirtualChannelWrite(echo->echo_channel, cnv.pv, length, NULL); +} + +echo_server_context* echo_server_context_new(HANDLE vcm) +{ + echo_server* echo = NULL; + echo = (echo_server*)calloc(1, sizeof(echo_server)); + + if (echo) + { + echo->context.vcm = vcm; + echo->context.Open = echo_server_open; + echo->context.Close = echo_server_close; + echo->context.Request = echo_server_request; + } + else + WLog_ERR(TAG, "calloc failed!"); + + return (echo_server_context*)echo; +} + +void echo_server_context_free(echo_server_context* context) +{ + echo_server* echo = (echo_server*)context; + echo_server_close(context); + free(echo); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/encomsp/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/encomsp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f6463049efd8e99e147efd465c18ff5edc506846 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/encomsp/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("encomsp") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/encomsp/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/encomsp/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..974df5bb4fd20609e33f54957221dfa508b2f1fc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/encomsp/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "encomsp" + TYPE + "static" + DESCRIPTION + "Multiparty Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEMC]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/geometry/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/geometry/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf1e76262b18812422a8753354d14a21132e349f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/geometry/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2017 David Fort +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("geometry") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/geometry/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/geometry/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..994d4542addd705c22a949dd8f54d32f5a296e09 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/geometry/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options( + NAME + "geometry" + TYPE + "dynamic" + DESCRIPTION + "Geometry tracking Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEGT]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..edf396af98a37cfa1c2d50015051285fe771c0f0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2020 Microsoft +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("gfxredir") + +if(WITH_SERVER_CHANNELS OR WITH_CLIENT_CHANNELS) + include_directories(common) + add_subdirectory(common) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e8bd4c734f373384edf08be4ea64c9ec8d3f9e45 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT OFF) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "gfxredir" + TYPE + "dynamic" + DESCRIPTION + "Graphics Redirection Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPXXXX]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..77761928843ce9c3061827a4f5b258d4758f36af --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2024 Armin Novak +# Copyright 2024 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(SRCS gfxredir_common.h gfxredir_common.c) + +# Library currently header only +add_library(gfxredir-common STATIC ${SRCS}) + +channel_install(gfxredir-common ${FREERDP_ADDIN_PATH} "FreeRDPTargets") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/gfxredir_common.c b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/gfxredir_common.c new file mode 100644 index 0000000000000000000000000000000000000000..88ee88bbc53175118514ab4057c89865997593cc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/gfxredir_common.c @@ -0,0 +1,58 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPXXXX Remote App Graphics Redirection Virtual Channel Extension + * + * Copyright 2020 Microsoft + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("gfxredir.common") + +#include "gfxredir_common.h" + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT gfxredir_read_header(wStream* s, GFXREDIR_HEADER* header) +{ + WINPR_ASSERT(header); + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, header->cmdId); + Stream_Read_UINT32(s, header->length); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT gfxredir_write_header(wStream* s, const GFXREDIR_HEADER* header) +{ + WINPR_ASSERT(header); + Stream_Write_UINT32(s, header->cmdId); + Stream_Write_UINT32(s, header->length); + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/gfxredir_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/gfxredir_common.h new file mode 100644 index 0000000000000000000000000000000000000000..18710a9ab2bde7ec5f8cf272b1c541ec17ace89d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/common/gfxredir_common.h @@ -0,0 +1,32 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPXXXX Remote App Graphics Redirection Virtual Channel Extension + * + * Copyright 2020 Microsoft + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_GFXREDIR_COMMON_H +#define FREERDP_CHANNEL_GFXREDIR_COMMON_H + +#include +#include + +#include +#include + +FREERDP_LOCAL UINT gfxredir_read_header(wStream* s, GFXREDIR_HEADER* header); +FREERDP_LOCAL UINT gfxredir_write_header(wStream* s, const GFXREDIR_HEADER* header); + +#endif /* FREERDP_CHANNEL_GFXREDIR_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5f88a2fc5004548675c90abe0adcd5b57fb8fd35 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2020 Microsoft +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("gfxredir") + +set(${MODULE_PREFIX}_SRCS gfxredir_main.c gfxredir_main.h) + +set(${MODULE_PREFIX}_LIBS freerdp gfxredir-common) + +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/gfxredir_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/gfxredir_main.c new file mode 100644 index 0000000000000000000000000000000000000000..bb02b01bd30776669fe5514860400f2fbae84848 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/gfxredir_main.c @@ -0,0 +1,829 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPXXXX Remote App Graphics Redirection Virtual Channel Extension + * + * Copyright 2020 Microsoft + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "gfxredir_main.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define TAG CHANNELS_TAG("gfxredir.server") + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_recv_legacy_caps_pdu(wStream* s, GfxRedirServerContext* context) +{ + UINT32 error = CHANNEL_RC_OK; + GFXREDIR_LEGACY_CAPS_PDU pdu = { 0 }; + + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.version); /* version (2 bytes) */ + + if (context) + IFCALLRET(context->GraphicsRedirectionLegacyCaps, error, context, &pdu); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_recv_caps_advertise_pdu(wStream* s, UINT32 length, + GfxRedirServerContext* context) +{ + UINT32 error = CHANNEL_RC_OK; + GFXREDIR_CAPS_ADVERTISE_PDU pdu = { 0 }; + + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, length)) + return ERROR_INVALID_DATA; + + pdu.length = length; + Stream_GetPointer(s, pdu.caps); + Stream_Seek(s, length); + + if (!context->GraphicsRedirectionCapsAdvertise) + { + WLog_ERR(TAG, "server does not support CapsAdvertise PDU!"); + return ERROR_NOT_SUPPORTED; + } + else if (context) + { + IFCALLRET(context->GraphicsRedirectionCapsAdvertise, error, context, &pdu); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_recv_present_buffer_ack_pdu(wStream* s, GfxRedirServerContext* context) +{ + UINT32 error = CHANNEL_RC_OK; + GFXREDIR_PRESENT_BUFFER_ACK_PDU pdu = { 0 }; + + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 16)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT64(s, pdu.windowId); /* windowId (8 bytes) */ + Stream_Read_UINT64(s, pdu.presentId); /* presentId (8 bytes) */ + + if (context) + { + IFCALLRET(context->PresentBufferAck, error, context, &pdu); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_server_receive_pdu(GfxRedirServerContext* context, wStream* s) +{ + UINT error = CHANNEL_RC_OK; + GFXREDIR_HEADER header = { 0 }; + + WINPR_ASSERT(context); + + const size_t beg = Stream_GetPosition(s); + + if ((error = gfxredir_read_header(s, &header))) + { + WLog_ERR(TAG, "gfxredir_read_header failed with error %" PRIu32 "!", error); + return error; + } + + switch (header.cmdId) + { + case GFXREDIR_CMDID_LEGACY_CAPS: + if ((error = gfxredir_recv_legacy_caps_pdu(s, context))) + WLog_ERR(TAG, + "gfxredir_recv_legacy_caps_pdu " + "failed with error %" PRIu32 "!", + error); + + break; + + case GFXREDIR_CMDID_CAPS_ADVERTISE: + if ((error = gfxredir_recv_caps_advertise_pdu(s, header.length - 8, context))) + WLog_ERR(TAG, + "gfxredir_recv_caps_advertise " + "failed with error %" PRIu32 "!", + error); + break; + + case GFXREDIR_CMDID_PRESENT_BUFFER_ACK: + if ((error = gfxredir_recv_present_buffer_ack_pdu(s, context))) + WLog_ERR(TAG, + "gfxredir_recv_present_buffer_ask_pdu " + "failed with error %" PRIu32 "!", + error); + break; + + default: + error = CHANNEL_RC_BAD_PROC; + WLog_WARN(TAG, "Received unknown PDU type: %" PRIu32 "", header.cmdId); + break; + } + + const size_t end = Stream_GetPosition(s); + + if (end != (beg + header.length)) + { + WLog_ERR(TAG, "Unexpected GFXREDIR pdu end: Actual: %d, Expected: %" PRIu32 "", end, + (beg + header.length)); + Stream_SetPosition(s, (beg + header.length)); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_server_handle_messages(GfxRedirServerContext* context) +{ + UINT ret = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + + GfxRedirServerPrivate* priv = context->priv; + WINPR_ASSERT(priv); + + wStream* s = priv->input_stream; + + /* Check whether the dynamic channel is ready */ + if (!priv->isReady) + { + void* buffer = NULL; + DWORD BytesReturned = 0; + if (WTSVirtualChannelQuery(priv->gfxredir_channel, WTSVirtualChannelReady, &buffer, + &BytesReturned) == FALSE) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_ERR(TAG, "WTSVirtualChannelQuery failed"); + return ERROR_INTERNAL_ERROR; + } + + priv->isReady = *((BOOL*)buffer); + WTSFreeMemory(buffer); + } + + /* Consume channel event only after the dynamic channel is ready */ + if (priv->isReady) + { + Stream_SetPosition(s, 0); + + DWORD BytesReturned = 0; + if (!WTSVirtualChannelRead(priv->gfxredir_channel, 0, NULL, 0, &BytesReturned)) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (BytesReturned < 1) + return CHANNEL_RC_OK; + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + const ULONG cap = WINPR_ASSERTING_INT_CAST(ULONG, Stream_Capacity(s)); + if (WTSVirtualChannelRead(priv->gfxredir_channel, 0, (PCHAR)Stream_Buffer(s), cap, + &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_SetLength(s, BytesReturned); + Stream_SetPosition(s, 0); + + while (Stream_GetPosition(s) < Stream_Length(s)) + { + if ((ret = gfxredir_server_receive_pdu(context, s))) + { + WLog_ERR(TAG, + "gfxredir_server_receive_pdu " + "failed with error %" PRIu32 "!", + ret); + return ret; + } + } + } + + return ret; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static DWORD WINAPI gfxredir_server_thread_func(LPVOID arg) +{ + GfxRedirServerContext* context = (GfxRedirServerContext*)arg; + WINPR_ASSERT(context); + + GfxRedirServerPrivate* priv = context->priv; + WINPR_ASSERT(priv); + + HANDLE events[8] = { 0 }; + UINT error = CHANNEL_RC_OK; + DWORD nCount = 0; + events[nCount++] = priv->stopEvent; + events[nCount++] = priv->channelEvent; + + while (TRUE) + { + const DWORD status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "", error); + break; + } + + /* Stop Event */ + if (status == WAIT_OBJECT_0) + break; + + if ((error = gfxredir_server_handle_messages(context))) + { + WLog_ERR(TAG, "gfxredir_server_handle_messages failed with error %" PRIu32 "", error); + break; + } + } + + ExitThread(error); + return error; +} + +/** + * Function description + * Create new stream for single gfxredir packet. The new stream length + * would be required data length + header. The header will be written + * to the stream before return. + * + * @param cmdId the command identifier + * @param length data length without header + * + * @return new stream + */ +static wStream* gfxredir_server_single_packet_new(UINT32 cmdId, size_t length) +{ + GFXREDIR_HEADER header = { 0 }; + wStream* s = Stream_New(NULL, GFXREDIR_HEADER_SIZE + length); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + goto error; + } + + header.cmdId = cmdId; + header.length = WINPR_ASSERTING_INT_CAST(UINT32, GFXREDIR_HEADER_SIZE + length); + + const UINT error = gfxredir_write_header(s, &header); + if (error) + { + WLog_ERR(TAG, "Failed to write header with error %" PRIu32 "!", error); + goto error; + } + + return s; +error: + Stream_Free(s, TRUE); + return NULL; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_server_packet_send(GfxRedirServerContext* context, wStream* s) +{ + UINT ret = ERROR_INTERNAL_ERROR; + ULONG written = 0; + + WINPR_ASSERT(context); + + const ULONG cap = WINPR_ASSERTING_INT_CAST(ULONG, Stream_GetPosition(s)); + if (!WTSVirtualChannelWrite(context->priv->gfxredir_channel, (PCHAR)Stream_Buffer(s), cap, + &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + ret = ERROR_INTERNAL_ERROR; + goto out; + } + + if (written < Stream_GetPosition(s)) + { + WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written, + Stream_GetPosition(s)); + } + + ret = CHANNEL_RC_OK; +out: + Stream_Free(s, TRUE); + return ret; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_send_error(GfxRedirServerContext* context, const GFXREDIR_ERROR_PDU* error) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(error); + + wStream* s = gfxredir_server_single_packet_new(GFXREDIR_CMDID_ERROR, 4); + + if (!s) + { + WLog_ERR(TAG, "gfxredir_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, error->errorCode); + return gfxredir_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_send_caps_confirm(GfxRedirServerContext* context, + const GFXREDIR_CAPS_CONFIRM_PDU* graphicsCapsConfirm) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(graphicsCapsConfirm); + + if (graphicsCapsConfirm->length < GFXREDIR_CAPS_HEADER_SIZE) + { + WLog_ERR(TAG, "length must be greater than header size, failed!"); + return ERROR_INVALID_DATA; + } + + wStream* s = + gfxredir_server_single_packet_new(GFXREDIR_CMDID_CAPS_CONFIRM, graphicsCapsConfirm->length); + + if (!s) + { + WLog_ERR(TAG, "gfxredir_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, GFXREDIR_CAPS_SIGNATURE); + Stream_Write_UINT32(s, graphicsCapsConfirm->version); + Stream_Write_UINT32(s, graphicsCapsConfirm->length); + if (graphicsCapsConfirm->length > GFXREDIR_CAPS_HEADER_SIZE) + Stream_Write(s, graphicsCapsConfirm->capsData, + graphicsCapsConfirm->length - GFXREDIR_CAPS_HEADER_SIZE); + const UINT ret = gfxredir_server_packet_send(context, s); + if (ret == CHANNEL_RC_OK) + context->confirmedCapsVersion = graphicsCapsConfirm->version; + return ret; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_send_open_pool(GfxRedirServerContext* context, + const GFXREDIR_OPEN_POOL_PDU* openPool) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(openPool); + + if (context->confirmedCapsVersion != GFXREDIR_CAPS_VERSION2_0) + { + WLog_ERR(TAG, "open_pool is called with invalid version!"); + return ERROR_INTERNAL_ERROR; + } + + if (openPool->sectionNameLength == 0 || openPool->sectionName == NULL) + { + WLog_ERR(TAG, "section name must be provided!"); + return ERROR_INVALID_DATA; + } + + /* make sure null-terminate */ + if (openPool->sectionName[openPool->sectionNameLength - 1] != 0) + { + WLog_ERR(TAG, "section name must be terminated with NULL!"); + return ERROR_INVALID_DATA; + } + + wStream* s = gfxredir_server_single_packet_new(GFXREDIR_CMDID_OPEN_POOL, + 20 + (openPool->sectionNameLength * 2)); + + if (!s) + { + WLog_ERR(TAG, "gfxredir_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT64(s, openPool->poolId); + Stream_Write_UINT64(s, openPool->poolSize); + Stream_Write_UINT32(s, openPool->sectionNameLength); + Stream_Write(s, openPool->sectionName, (2ULL * openPool->sectionNameLength)); + return gfxredir_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_send_close_pool(GfxRedirServerContext* context, + const GFXREDIR_CLOSE_POOL_PDU* closePool) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(closePool); + + if (context->confirmedCapsVersion != GFXREDIR_CAPS_VERSION2_0) + { + WLog_ERR(TAG, "close_pool is called with invalid version!"); + return ERROR_INTERNAL_ERROR; + } + + wStream* s = gfxredir_server_single_packet_new(GFXREDIR_CMDID_CLOSE_POOL, 8); + + if (!s) + { + WLog_ERR(TAG, "gfxredir_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT64(s, closePool->poolId); + return gfxredir_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_send_create_buffer(GfxRedirServerContext* context, + const GFXREDIR_CREATE_BUFFER_PDU* createBuffer) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(createBuffer); + + if (context->confirmedCapsVersion != GFXREDIR_CAPS_VERSION2_0) + { + WLog_ERR(TAG, "create_buffer is called with invalid version!"); + return ERROR_INTERNAL_ERROR; + } + + wStream* s = gfxredir_server_single_packet_new(GFXREDIR_CMDID_CREATE_BUFFER, 40); + + if (!s) + { + WLog_ERR(TAG, "gfxredir_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT64(s, createBuffer->poolId); + Stream_Write_UINT64(s, createBuffer->bufferId); + Stream_Write_UINT64(s, createBuffer->offset); + Stream_Write_UINT32(s, createBuffer->stride); + Stream_Write_UINT32(s, createBuffer->width); + Stream_Write_UINT32(s, createBuffer->height); + Stream_Write_UINT32(s, createBuffer->format); + return gfxredir_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_send_destroy_buffer(GfxRedirServerContext* context, + const GFXREDIR_DESTROY_BUFFER_PDU* destroyBuffer) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(destroyBuffer); + + if (context->confirmedCapsVersion != GFXREDIR_CAPS_VERSION2_0) + { + WLog_ERR(TAG, "destroy_buffer is called with invalid version!"); + return ERROR_INTERNAL_ERROR; + } + + wStream* s = gfxredir_server_single_packet_new(GFXREDIR_CMDID_DESTROY_BUFFER, 8); + + if (!s) + { + WLog_ERR(TAG, "gfxredir_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT64(s, destroyBuffer->bufferId); + return gfxredir_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_send_present_buffer(GfxRedirServerContext* context, + const GFXREDIR_PRESENT_BUFFER_PDU* presentBuffer) +{ + RECTANGLE_32 dummyRect = { 0, 0, 0, 0 }; + + WINPR_ASSERT(context); + WINPR_ASSERT(presentBuffer); + + if (context->confirmedCapsVersion != GFXREDIR_CAPS_VERSION2_0) + { + WLog_ERR(TAG, "present_buffer is called with invalid version!"); + return ERROR_INTERNAL_ERROR; + } + + if (presentBuffer->numOpaqueRects > GFXREDIR_MAX_OPAQUE_RECTS) + { + WLog_ERR(TAG, "numOpaqueRects is larger than its limit!"); + return ERROR_INVALID_DATA; + } + + const size_t length = + 64ULL + ((presentBuffer->numOpaqueRects ? presentBuffer->numOpaqueRects : 1) * + sizeof(RECTANGLE_32)); + + wStream* s = gfxredir_server_single_packet_new(GFXREDIR_CMDID_PRESENT_BUFFER, length); + + if (!s) + { + WLog_ERR(TAG, "gfxredir_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT64(s, presentBuffer->timestamp); + Stream_Write_UINT64(s, presentBuffer->presentId); + Stream_Write_UINT64(s, presentBuffer->windowId); + Stream_Write_UINT64(s, presentBuffer->bufferId); + Stream_Write_UINT32(s, presentBuffer->orientation); + Stream_Write_UINT32(s, presentBuffer->targetWidth); + Stream_Write_UINT32(s, presentBuffer->targetHeight); + Stream_Write_UINT32(s, presentBuffer->dirtyRect.left); + Stream_Write_UINT32(s, presentBuffer->dirtyRect.top); + Stream_Write_UINT32(s, presentBuffer->dirtyRect.width); + Stream_Write_UINT32(s, presentBuffer->dirtyRect.height); + Stream_Write_UINT32(s, presentBuffer->numOpaqueRects); + if (presentBuffer->numOpaqueRects) + Stream_Write(s, presentBuffer->opaqueRects, + (presentBuffer->numOpaqueRects * sizeof(RECTANGLE_32))); + else + Stream_Write(s, &dummyRect, sizeof(RECTANGLE_32)); + return gfxredir_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_server_open(GfxRedirServerContext* context) +{ + UINT rc = ERROR_INTERNAL_ERROR; + WINPR_ASSERT(context); + + GfxRedirServerPrivate* priv = context->priv; + WINPR_ASSERT(priv); + + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + void* buffer = NULL; + priv->SessionId = WTS_CURRENT_SESSION; + + if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + + priv->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + priv->gfxredir_channel = WTSVirtualChannelOpenEx(priv->SessionId, GFXREDIR_DVC_CHANNEL_NAME, + WTS_CHANNEL_OPTION_DYNAMIC); + + if (!priv->gfxredir_channel) + { + WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed!"); + rc = GetLastError(); + goto out_close; + } + + /* Query for channel event handle */ + if (!WTSVirtualChannelQuery(priv->gfxredir_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) || + (BytesReturned != sizeof(HANDLE))) + { + WLog_ERR(TAG, + "WTSVirtualChannelQuery failed " + "or invalid returned size(%" PRIu32 ")", + BytesReturned); + + if (buffer) + WTSFreeMemory(buffer); + + rc = ERROR_INTERNAL_ERROR; + goto out_close; + } + + priv->channelEvent = *(HANDLE*)buffer; + WTSFreeMemory(buffer); + + if (priv->thread == NULL) + { + if (!(priv->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + goto out_close; + } + + if (!(priv->thread = + CreateThread(NULL, 0, gfxredir_server_thread_func, (void*)context, 0, NULL))) + { + WLog_ERR(TAG, "CreateEvent failed!"); + (void)CloseHandle(priv->stopEvent); + priv->stopEvent = NULL; + goto out_close; + } + } + + return CHANNEL_RC_OK; +out_close: + WTSVirtualChannelClose(priv->gfxredir_channel); + priv->gfxredir_channel = NULL; + priv->channelEvent = NULL; + return rc; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT gfxredir_server_close(GfxRedirServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + WINPR_ASSERT(context); + + GfxRedirServerPrivate* priv = context->priv; + WINPR_ASSERT(priv); + + if (priv->thread) + { + (void)SetEvent(priv->stopEvent); + + if (WaitForSingleObject(priv->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(priv->thread); + (void)CloseHandle(priv->stopEvent); + priv->thread = NULL; + priv->stopEvent = NULL; + } + + if (priv->gfxredir_channel) + { + WTSVirtualChannelClose(priv->gfxredir_channel); + priv->gfxredir_channel = NULL; + } + + return error; +} + +GfxRedirServerContext* gfxredir_server_context_new(HANDLE vcm) +{ + GfxRedirServerContext* context = + (GfxRedirServerContext*)calloc(1, sizeof(GfxRedirServerContext)); + + if (!context) + { + WLog_ERR(TAG, "gfxredir_server_context_new(): calloc GfxRedirServerContext failed!"); + return NULL; + } + + GfxRedirServerPrivate* priv = context->priv = + (GfxRedirServerPrivate*)calloc(1, sizeof(GfxRedirServerPrivate)); + + if (!context->priv) + { + WLog_ERR(TAG, "gfxredir_server_context_new(): calloc GfxRedirServerPrivate failed!"); + goto fail; + } + + priv->input_stream = Stream_New(NULL, 4); + + if (!priv->input_stream) + { + WLog_ERR(TAG, "Stream_New failed!"); + goto fail; + } + + context->vcm = vcm; + context->Open = gfxredir_server_open; + context->Close = gfxredir_server_close; + context->Error = gfxredir_send_error; + context->GraphicsRedirectionCapsConfirm = gfxredir_send_caps_confirm; + context->OpenPool = gfxredir_send_open_pool; + context->ClosePool = gfxredir_send_close_pool; + context->CreateBuffer = gfxredir_send_create_buffer; + context->DestroyBuffer = gfxredir_send_destroy_buffer; + context->PresentBuffer = gfxredir_send_present_buffer; + context->confirmedCapsVersion = GFXREDIR_CAPS_VERSION1; + priv->isReady = FALSE; + return context; +fail: + gfxredir_server_context_free(context); + return NULL; +} + +void gfxredir_server_context_free(GfxRedirServerContext* context) +{ + if (!context) + return; + + gfxredir_server_close(context); + + if (context->priv) + { + Stream_Free(context->priv->input_stream, TRUE); + free(context->priv); + } + + free(context); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/gfxredir_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/gfxredir_main.h new file mode 100644 index 0000000000000000000000000000000000000000..45424fd970a5c98287c7f2c8f1cc7258a76aac03 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/gfxredir/server/gfxredir_main.h @@ -0,0 +1,37 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPXXXX Remote App Graphics Redirection Virtual Channel Extension + * + * Copyright 2020 Microsoft + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_GFXREDIR_SERVER_MAIN_H +#define FREERDP_CHANNEL_GFXREDIR_SERVER_MAIN_H + +#include + +struct s_gfxredir_server_private +{ + BOOL isReady; + wStream* input_stream; + HANDLE channelEvent; + HANDLE thread; + HANDLE stopEvent; + DWORD SessionId; + + void* gfxredir_channel; +}; + +#endif /* FREERDP_CHANNEL_GFXREDIR_SERVER_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/location/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/location/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bdeceafa2d6476010af66092bf5d47ee7b80f558 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/location/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2023 Pascal Nowack +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("location") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/location/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/location/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..465173a66101663523e64c1faf1414c77a49b923 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/location/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "location" + TYPE + "dynamic" + DESCRIPTION + "Location Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEL]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/location/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/location/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..57fbd5aa3e5d847a6452afa5c343294dbd37e04c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/location/client/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2024 Armin Novak +# Copyright 2024 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("location") + +set(${MODULE_PREFIX}_SRCS location_main.c) + +set(${MODULE_PREFIX}_LIBS winpr) +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9475c56af13770249e02e304174748489ce97e14 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("parallel") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..1bac3ae03f13aadbc21905e38664fffb49a0fec8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/ChannelOptions.cmake @@ -0,0 +1,38 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +if(WIN32) + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) + message("Serial redirection not supported on windows") +endif() + +if(APPLE) + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) + message("Serial redirection not supported on apple") +endif() + +if(ANDROID) + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) + message("Serial redirection not supported on android") +endif() + +define_channel_options( + NAME + "parallel" + TYPE + "device" + DESCRIPTION + "Parallel Port Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPESP]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..35da0e6d19c081665558c1e603e4c8b5e6c23277 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/client/CMakeLists.txt @@ -0,0 +1,23 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("parallel") + +set(${MODULE_PREFIX}_SRCS parallel_main.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp) +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DeviceServiceEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/client/parallel_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/client/parallel_main.c new file mode 100644 index 0000000000000000000000000000000000000000..f449f88b1884134fd0e7c919c5bd89a3af075663 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/parallel/client/parallel_main.c @@ -0,0 +1,521 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Redirected Parallel Port Device Service + * + * Copyright 2010 O.S. Systems Software Ltda. + * Copyright 2010 Eduardo Fiss Beloni + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include + +#ifndef _WIN32 +#include +#include +#include +#endif + +#ifdef __LINUX__ +#include +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("drive.client") + +typedef struct +{ + DEVICE device; + + int file; + char* path; + UINT32 id; + + HANDLE thread; + wMessageQueue* queue; + rdpContext* rdpcontext; + wLog* log; +} PARALLEL_DEVICE; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_process_irp_create(PARALLEL_DEVICE* parallel, IRP* irp) +{ + char* path = NULL; + UINT32 PathLength = 0; + + WINPR_ASSERT(parallel); + WINPR_ASSERT(irp); + + if (!Stream_SafeSeek(irp->input, 28)) + return ERROR_INVALID_DATA; + /* DesiredAccess(4) AllocationSize(8), FileAttributes(4) */ + /* SharedAccess(4) CreateDisposition(4), CreateOptions(4) */ + if (!Stream_CheckAndLogRequiredLength(TAG, irp->input, 4)) + return ERROR_INVALID_DATA; + Stream_Read_UINT32(irp->input, PathLength); + if (PathLength < sizeof(WCHAR)) + return ERROR_INVALID_DATA; + const WCHAR* ptr = Stream_ConstPointer(irp->input); + if (!Stream_SafeSeek(irp->input, PathLength)) + return ERROR_INVALID_DATA; + path = ConvertWCharNToUtf8Alloc(ptr, PathLength / sizeof(WCHAR), NULL); + if (!path) + return CHANNEL_RC_NO_MEMORY; + + parallel->id = irp->devman->id_sequence++; + parallel->file = open(parallel->path, O_RDWR); + + if (parallel->file < 0) + { + irp->IoStatus = STATUS_ACCESS_DENIED; + parallel->id = 0; + } + else + { + /* all read and write operations should be non-blocking */ + if (fcntl(parallel->file, F_SETFL, O_NONBLOCK) == -1) + { + } + } + + Stream_Write_UINT32(irp->output, parallel->id); + Stream_Write_UINT8(irp->output, 0); + free(path); + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_process_irp_close(PARALLEL_DEVICE* parallel, IRP* irp) +{ + WINPR_ASSERT(parallel); + WINPR_ASSERT(irp); + + (void)close(parallel->file); + + Stream_Zero(irp->output, 5); /* Padding(5) */ + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) +{ + UINT32 Length = 0; + UINT64 Offset = 0; + ssize_t status = 0; + BYTE* buffer = NULL; + + WINPR_ASSERT(parallel); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLength(TAG, irp->input, 12)) + return ERROR_INVALID_DATA; + Stream_Read_UINT32(irp->input, Length); + Stream_Read_UINT64(irp->input, Offset); + (void)Offset; /* [MS-RDPESP] 3.2.5.1.4 Processing a Server Read Request Message + * ignored */ + buffer = (BYTE*)calloc(Length, sizeof(BYTE)); + + if (!buffer) + { + WLog_Print(parallel->log, WLOG_ERROR, "malloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + status = read(parallel->file, buffer, Length); + + if ((status < 0) || (status > UINT32_MAX)) + { + irp->IoStatus = STATUS_UNSUCCESSFUL; + free(buffer); + buffer = NULL; + Length = 0; + } + else + { + Length = (UINT32)status; + } + + Stream_Write_UINT32(irp->output, Length); + + if (Length > 0) + { + if (!Stream_EnsureRemainingCapacity(irp->output, Length)) + { + WLog_Print(parallel->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!"); + free(buffer); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write(irp->output, buffer, Length); + } + + free(buffer); + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_process_irp_write(PARALLEL_DEVICE* parallel, IRP* irp) +{ + UINT32 len = 0; + UINT32 Length = 0; + UINT64 Offset = 0; + + WINPR_ASSERT(parallel); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLength(TAG, irp->input, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(irp->input, Length); + Stream_Read_UINT64(irp->input, Offset); + (void)Offset; /* [MS-RDPESP] 3.2.5.1.5 Processing a Server Write Request Message + * ignore offset */ + if (!Stream_SafeSeek(irp->input, 20)) /* Padding */ + return ERROR_INVALID_DATA; + const void* ptr = Stream_ConstPointer(irp->input); + if (!Stream_SafeSeek(irp->input, Length)) + return ERROR_INVALID_DATA; + len = Length; + + while (len > 0) + { + const ssize_t status = write(parallel->file, ptr, len); + + if ((status < 0) || (status > len)) + { + irp->IoStatus = STATUS_UNSUCCESSFUL; + Length = 0; + break; + } + + Stream_Seek(irp->input, WINPR_ASSERTING_INT_CAST(size_t, status)); + len -= status; + } + + Stream_Write_UINT32(irp->output, Length); + Stream_Write_UINT8(irp->output, 0); /* Padding */ + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_process_irp_device_control(PARALLEL_DEVICE* parallel, IRP* irp) +{ + WINPR_ASSERT(parallel); + WINPR_ASSERT(irp); + + Stream_Write_UINT32(irp->output, 0); /* OutputBufferLength */ + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_process_irp(PARALLEL_DEVICE* parallel, IRP* irp) +{ + UINT error = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(parallel); + WINPR_ASSERT(irp); + + switch (irp->MajorFunction) + { + case IRP_MJ_CREATE: + error = parallel_process_irp_create(parallel, irp); + break; + + case IRP_MJ_CLOSE: + error = parallel_process_irp_close(parallel, irp); + break; + + case IRP_MJ_READ: + error = parallel_process_irp_read(parallel, irp); + break; + + case IRP_MJ_WRITE: + error = parallel_process_irp_write(parallel, irp); + break; + + case IRP_MJ_DEVICE_CONTROL: + error = parallel_process_irp_device_control(parallel, irp); + break; + + default: + irp->IoStatus = STATUS_NOT_SUPPORTED; + error = irp->Complete(irp); + break; + } + + DWORD level = WLOG_TRACE; + if (error) + level = WLOG_WARN; + + WLog_Print(parallel->log, level, + "[%s|0x%08" PRIx32 "] completed with %s [0x%08" PRIx32 "] (IoStatus %s [0x%08" PRIx32 + "])", + rdpdr_irp_string(irp->MajorFunction), irp->MajorFunction, WTSErrorToString(error), + error, NtStatus2Tag(irp->IoStatus), irp->IoStatus); + + return error; +} + +static DWORD WINAPI parallel_thread_func(LPVOID arg) +{ + PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*)arg; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(parallel); + while (1) + { + if (!MessageQueue_Wait(parallel->queue)) + { + WLog_Print(parallel->log, WLOG_ERROR, "MessageQueue_Wait failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + wMessage message = { 0 }; + if (!MessageQueue_Peek(parallel->queue, &message, TRUE)) + { + WLog_Print(parallel->log, WLOG_ERROR, "MessageQueue_Peek failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (message.id == WMQ_QUIT) + break; + + IRP* irp = (IRP*)message.wParam; + + error = parallel_process_irp(parallel, irp); + if (error) + { + WLog_Print(parallel->log, WLOG_ERROR, + "parallel_process_irp failed with error %" PRIu32 "!", error); + break; + } + } + + if (error && parallel->rdpcontext) + setChannelError(parallel->rdpcontext, error, "parallel_thread_func reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_irp_request(DEVICE* device, IRP* irp) +{ + PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*)device; + + WINPR_ASSERT(parallel); + + if (!MessageQueue_Post(parallel->queue, NULL, 0, (void*)irp, NULL)) + { + WLog_Print(parallel->log, WLOG_ERROR, "MessageQueue_Post failed!"); + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT parallel_free_int(PARALLEL_DEVICE* parallel) +{ + if (parallel) + { + if (!MessageQueue_PostQuit(parallel->queue, 0) || + (WaitForSingleObject(parallel->thread, INFINITE) == WAIT_FAILED)) + { + const UINT error = GetLastError(); + WLog_Print(parallel->log, WLOG_ERROR, + "WaitForSingleObject failed with error %" PRIu32 "!", error); + } + + (void)CloseHandle(parallel->thread); + Stream_Free(parallel->device.data, TRUE); + MessageQueue_Free(parallel->queue); + } + free(parallel); + return CHANNEL_RC_OK; +} + +static UINT parallel_free(DEVICE* device) +{ + if (device) + return parallel_free_int((PARALLEL_DEVICE*)device); + return CHANNEL_RC_OK; +} + +static void parallel_message_free(void* obj) +{ + wMessage* msg = obj; + if (!msg) + return; + if (msg->id != 0) + return; + + IRP* irp = (IRP*)msg->wParam; + if (!irp) + return; + WINPR_ASSERT(irp->Discard); + irp->Discard(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT( + UINT VCAPITYPE parallel_DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)) +{ + PARALLEL_DEVICE* parallel = NULL; + UINT error = 0; + + WINPR_ASSERT(pEntryPoints); + + RDPDR_PARALLEL* device = (RDPDR_PARALLEL*)pEntryPoints->device; + WINPR_ASSERT(device); + + wLog* log = WLog_Get(TAG); + WINPR_ASSERT(log); + + char* name = device->device.Name; + char* path = device->Path; + + if (!name || (name[0] == '*') || !path) + { + /* TODO: implement auto detection of parallel ports */ + WLog_Print(log, WLOG_WARN, "Autodetection not implemented, no ports will be redirected"); + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + if (name[0] && path[0]) + { + parallel = (PARALLEL_DEVICE*)calloc(1, sizeof(PARALLEL_DEVICE)); + + if (!parallel) + { + WLog_Print(log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + parallel->log = log; + parallel->device.type = RDPDR_DTYP_PARALLEL; + parallel->device.name = name; + parallel->device.IRPRequest = parallel_irp_request; + parallel->device.Free = parallel_free; + parallel->rdpcontext = pEntryPoints->rdpcontext; + const size_t length = strlen(name); + parallel->device.data = Stream_New(NULL, length + 1); + + if (!parallel->device.data) + { + WLog_Print(parallel->log, WLOG_ERROR, "Stream_New failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + for (size_t i = 0; i <= length; i++) + Stream_Write_INT8(parallel->device.data, name[i] < 0 ? '_' : name[i]); + + parallel->path = path; + parallel->queue = MessageQueue_New(NULL); + + if (!parallel->queue) + { + WLog_Print(parallel->log, WLOG_ERROR, "MessageQueue_New failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + wObject* obj = MessageQueue_Object(parallel->queue); + WINPR_ASSERT(obj); + obj->fnObjectFree = parallel_message_free; + + error = pEntryPoints->RegisterDevice(pEntryPoints->devman, ¶llel->device); + if (error) + { + WLog_Print(parallel->log, WLOG_ERROR, "RegisterDevice failed with error %" PRIu32 "!", + error); + goto error_out; + } + + parallel->thread = CreateThread(NULL, 0, parallel_thread_func, parallel, 0, NULL); + if (!parallel->thread) + { + WLog_Print(parallel->log, WLOG_ERROR, "CreateThread failed!"); + error = ERROR_INTERNAL_ERROR; + goto error_out; + } + } + + return CHANNEL_RC_OK; +error_out: + parallel_free_int(parallel); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/printer/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..39a20992e1725880903907efb99de0ae682fa255 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("printer") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/printer/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..5f315f9982e39f4643e395eb84a18cacb2d73f31 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/ChannelOptions.cmake @@ -0,0 +1,40 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +if(WIN32) + set(OPTION_CLIENT_DEFAULT ON) + set(OPTION_SERVER_DEFAULT OFF) +else() + # cups is available on mac os and linux by default, on android it is optional. + if(NOT IOS AND NOT ANDROID) + set(CUPS_DEFAULT ON) + else() + set(CUPS_DEFAULT OFF) + endif() + option(WITH_CUPS "CUPS printer support" ${CUPS_DEFAULT}) + if(WITH_CUPS) + set(OPTION_CLIENT_DEFAULT ON) + set(OPTION_SERVER_DEFAULT OFF) + else() + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) + endif() +endif() + +define_channel_options( + NAME + "printer" + TYPE + "device" + DESCRIPTION + "Print Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEPC]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/cups/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/cups/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cde1ce4a6ba80fec7d8e82e5e02eaaf227961dd3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/cups/CMakeLists.txt @@ -0,0 +1,28 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2019 Armin Novak +# Copyright 2019 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +define_channel_client_subsystem("printer" "cups" "") + +find_package(Cups 2.0 REQUIRED) +set(${MODULE_PREFIX}_SRCS printer_cups.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${CUPS_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${CUPS_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/cups/printer_cups.c b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/cups/printer_cups.c new file mode 100644 index 0000000000000000000000000000000000000000..fb28065f86312121af3630b032f6ba1a34bf41ac --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/cups/printer_cups.c @@ -0,0 +1,461 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Print Virtual Channel - CUPS driver + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#define TAG CHANNELS_TAG("printer.client.cups") + +#if defined(__APPLE__) +#include +#include + +static bool is_mac_os_sonoma_or_later(void) +{ + char str[256] = { 0 }; + size_t size = sizeof(str); + + errno = 0; + int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0); + if (ret != 0) + { + char buffer[256] = { 0 }; + WLog_WARN(TAG, "sysctlbyname('kern.osrelease') failed with %s [%d]", + winpr_strerror(errno, buffer, sizeof(buffer)), errno); + return false; + } + + int major = 0; + int minor = 0; + int patch = 0; + + // NOLINTNEXTLINE(cert-err34-c) + const int rc = sscanf(str, "%d.%d.%d", &major, &minor, &patch); + if (rc != 3) + { + WLog_WARN(TAG, "could not match '%s' to format '%d.%d.%d'"); + return false; + } + + if (major < 23) + return false; + return true; +} +#endif + +typedef struct +{ + rdpPrinterDriver driver; + + size_t id_sequence; + size_t references; +} rdpCupsPrinterDriver; + +typedef struct +{ + rdpPrintJob printjob; + + http_t* printjob_object; + int printjob_id; +} rdpCupsPrintJob; + +typedef struct +{ + rdpPrinter printer; + + rdpCupsPrintJob* printjob; +} rdpCupsPrinter; + +static void printer_cups_get_printjob_name(char* buf, size_t size, size_t id) +{ + struct tm tres = { 0 }; + const time_t tt = time(NULL); + const struct tm* t = localtime_r(&tt, &tres); + + WINPR_ASSERT(buf); + WINPR_ASSERT(size > 0); + + (void)sprintf_s(buf, size - 1, "FreeRDP Print %04d-%02d-%02d %02d-%02d-%02d - Job %" PRIuz, + t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, + id); +} + +static bool http_status_ok(http_status_t status) +{ + switch (status) + { + case HTTP_OK: + case HTTP_CONTINUE: + return true; + default: + return false; + } +} + +static UINT write_printjob(rdpPrintJob* printjob, const BYTE* data, size_t size) +{ + rdpCupsPrintJob* cups_printjob = (rdpCupsPrintJob*)printjob; + + WINPR_ASSERT(cups_printjob); + + http_status_t rc = + cupsWriteRequestData(cups_printjob->printjob_object, (const char*)data, size); + if (!http_status_ok(rc)) + WLog_WARN(TAG, "cupsWriteRequestData returned %s", httpStatus(rc)); + + return CHANNEL_RC_OK; +} +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_cups_write_printjob(rdpPrintJob* printjob, const BYTE* data, size_t size) +{ + return write_printjob(printjob, data, size); +} + +static void printer_cups_close_printjob(rdpPrintJob* printjob) +{ + rdpCupsPrintJob* cups_printjob = (rdpCupsPrintJob*)printjob; + rdpCupsPrinter* cups_printer = NULL; + + WINPR_ASSERT(cups_printjob); + + ipp_status_t rc = cupsFinishDocument(cups_printjob->printjob_object, printjob->printer->name); + if (rc != IPP_OK) + WLog_WARN(TAG, "cupsFinishDocument returned %s", ippErrorString(rc)); + + cups_printjob->printjob_id = 0; + httpClose(cups_printjob->printjob_object); + + cups_printer = (rdpCupsPrinter*)printjob->printer; + WINPR_ASSERT(cups_printer); + + cups_printer->printjob = NULL; + free(cups_printjob); +} + +static rdpPrintJob* printer_cups_create_printjob(rdpPrinter* printer, UINT32 id) +{ + rdpCupsPrinter* cups_printer = (rdpCupsPrinter*)printer; + rdpCupsPrintJob* cups_printjob = NULL; + + WINPR_ASSERT(cups_printer); + + if (cups_printer->printjob != NULL) + { + WLog_WARN(TAG, "printjob [printer '%s'] already existing, abort!", printer->name); + return NULL; + } + + cups_printjob = (rdpCupsPrintJob*)calloc(1, sizeof(rdpCupsPrintJob)); + if (!cups_printjob) + return NULL; + + cups_printjob->printjob.id = id; + cups_printjob->printjob.printer = printer; + + cups_printjob->printjob.Write = printer_cups_write_printjob; + cups_printjob->printjob.Close = printer_cups_close_printjob; + + { + char buf[100] = { 0 }; + + cups_printjob->printjob_object = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, + HTTP_ENCRYPT_IF_REQUESTED, 1, 10000, NULL); + + if (!cups_printjob->printjob_object) + { + WLog_WARN(TAG, "httpConnect2 failed for '%s:%d", cupsServer(), ippPort()); + free(cups_printjob); + return NULL; + } + + printer_cups_get_printjob_name(buf, sizeof(buf), cups_printjob->printjob.id); + + cups_printjob->printjob_id = + cupsCreateJob(cups_printjob->printjob_object, printer->name, buf, 0, NULL); + + if (!cups_printjob->printjob_id) + { + WLog_WARN(TAG, "cupsCreateJob failed for printer '%s', driver '%s'", printer->name, + printer->driver); + httpClose(cups_printjob->printjob_object); + free(cups_printjob); + return NULL; + } + + http_status_t rc = cupsStartDocument(cups_printjob->printjob_object, printer->name, + cups_printjob->printjob_id, buf, CUPS_FORMAT_AUTO, 1); + if (!http_status_ok(rc)) + WLog_WARN(TAG, "cupsStartDocument [printer '%s', driver '%s'] returned %s", + printer->name, printer->driver, httpStatus(rc)); + } + + cups_printer->printjob = cups_printjob; + + return &cups_printjob->printjob; +} + +static rdpPrintJob* printer_cups_find_printjob(rdpPrinter* printer, UINT32 id) +{ + rdpCupsPrinter* cups_printer = (rdpCupsPrinter*)printer; + + WINPR_ASSERT(cups_printer); + + if (cups_printer->printjob == NULL) + return NULL; + if (cups_printer->printjob->printjob.id != id) + return NULL; + + return &cups_printer->printjob->printjob; +} + +static void printer_cups_free_printer(rdpPrinter* printer) +{ + rdpCupsPrinter* cups_printer = (rdpCupsPrinter*)printer; + + WINPR_ASSERT(cups_printer); + + if (cups_printer->printjob) + { + WINPR_ASSERT(cups_printer->printjob->printjob.Close); + cups_printer->printjob->printjob.Close(&cups_printer->printjob->printjob); + } + + if (printer->backend) + { + WINPR_ASSERT(printer->backend->ReleaseRef); + printer->backend->ReleaseRef(printer->backend); + } + free(printer->name); + free(printer->driver); + free(printer); +} + +static void printer_cups_add_ref_printer(rdpPrinter* printer) +{ + if (printer) + printer->references++; +} + +static void printer_cups_release_ref_printer(rdpPrinter* printer) +{ + if (!printer) + return; + if (printer->references <= 1) + printer_cups_free_printer(printer); + else + printer->references--; +} + +static rdpPrinter* printer_cups_new_printer(rdpCupsPrinterDriver* cups_driver, const char* name, + const char* driverName, BOOL is_default) +{ + rdpCupsPrinter* cups_printer = NULL; + + cups_printer = (rdpCupsPrinter*)calloc(1, sizeof(rdpCupsPrinter)); + if (!cups_printer) + return NULL; + + cups_printer->printer.backend = &cups_driver->driver; + + cups_printer->printer.id = cups_driver->id_sequence++; + cups_printer->printer.name = _strdup(name); + if (!cups_printer->printer.name) + goto fail; + + if (driverName) + cups_printer->printer.driver = _strdup(driverName); + else + { + const char* dname = "MS Publisher Imagesetter"; +#if defined(__APPLE__) + if (is_mac_os_sonoma_or_later()) + dname = "Microsoft Print to PDF"; +#endif + cups_printer->printer.driver = _strdup(dname); + } + if (!cups_printer->printer.driver) + goto fail; + + cups_printer->printer.is_default = is_default; + + cups_printer->printer.CreatePrintJob = printer_cups_create_printjob; + cups_printer->printer.FindPrintJob = printer_cups_find_printjob; + cups_printer->printer.AddRef = printer_cups_add_ref_printer; + cups_printer->printer.ReleaseRef = printer_cups_release_ref_printer; + + WINPR_ASSERT(cups_printer->printer.AddRef); + cups_printer->printer.AddRef(&cups_printer->printer); + + WINPR_ASSERT(cups_printer->printer.backend->AddRef); + cups_printer->printer.backend->AddRef(cups_printer->printer.backend); + + return &cups_printer->printer; + +fail: + printer_cups_free_printer(&cups_printer->printer); + return NULL; +} + +static void printer_cups_release_enum_printers(rdpPrinter** printers) +{ + rdpPrinter** cur = printers; + + while ((cur != NULL) && ((*cur) != NULL)) + { + if ((*cur)->ReleaseRef) + (*cur)->ReleaseRef(*cur); + cur++; + } + free((void*)printers); +} + +static rdpPrinter** printer_cups_enum_printers(rdpPrinterDriver* driver) +{ + rdpPrinter** printers = NULL; + int num_printers = 0; + cups_dest_t* dests = NULL; + BOOL haveDefault = FALSE; + const int num_dests = cupsGetDests(&dests); + + WINPR_ASSERT(driver); + if (num_dests >= 0) + printers = (rdpPrinter**)calloc((size_t)num_dests + 1, sizeof(rdpPrinter*)); + if (!printers) + return NULL; + + for (size_t i = 0; i < (size_t)num_dests; i++) + { + const cups_dest_t* dest = &dests[i]; + if (dest->instance == NULL) + { + rdpPrinter* current = printer_cups_new_printer((rdpCupsPrinterDriver*)driver, + dest->name, NULL, dest->is_default); + if (!current) + { + printer_cups_release_enum_printers(printers); + printers = NULL; + break; + } + + if (current->is_default) + haveDefault = TRUE; + + printers[num_printers++] = current; + } + } + cupsFreeDests(num_dests, dests); + + if (!haveDefault && (num_dests > 0) && printers) + { + if (printers[0]) + printers[0]->is_default = TRUE; + } + + return printers; +} + +static rdpPrinter* printer_cups_get_printer(rdpPrinterDriver* driver, const char* name, + const char* driverName, BOOL isDefault) +{ + rdpCupsPrinterDriver* cups_driver = (rdpCupsPrinterDriver*)driver; + + WINPR_ASSERT(cups_driver); + return printer_cups_new_printer(cups_driver, name, driverName, isDefault); +} + +static void printer_cups_add_ref_driver(rdpPrinterDriver* driver) +{ + rdpCupsPrinterDriver* cups_driver = (rdpCupsPrinterDriver*)driver; + if (cups_driver) + cups_driver->references++; +} + +/* Singleton */ +static rdpCupsPrinterDriver* uniq_cups_driver = NULL; + +static void printer_cups_release_ref_driver(rdpPrinterDriver* driver) +{ + rdpCupsPrinterDriver* cups_driver = (rdpCupsPrinterDriver*)driver; + + WINPR_ASSERT(cups_driver); + + if (cups_driver->references <= 1) + { + if (uniq_cups_driver == cups_driver) + uniq_cups_driver = NULL; + free(cups_driver); + } + else + cups_driver->references--; +} + +FREERDP_ENTRY_POINT(UINT VCAPITYPE cups_freerdp_printer_client_subsystem_entry(void* arg)) +{ + rdpPrinterDriver** ppPrinter = (rdpPrinterDriver**)arg; + if (!ppPrinter) + return ERROR_INVALID_PARAMETER; + + if (!uniq_cups_driver) + { + uniq_cups_driver = (rdpCupsPrinterDriver*)calloc(1, sizeof(rdpCupsPrinterDriver)); + + if (!uniq_cups_driver) + return ERROR_OUTOFMEMORY; + + uniq_cups_driver->driver.EnumPrinters = printer_cups_enum_printers; + uniq_cups_driver->driver.ReleaseEnumPrinters = printer_cups_release_enum_printers; + uniq_cups_driver->driver.GetPrinter = printer_cups_get_printer; + + uniq_cups_driver->driver.AddRef = printer_cups_add_ref_driver; + uniq_cups_driver->driver.ReleaseRef = printer_cups_release_ref_driver; + + uniq_cups_driver->id_sequence = 1; + } + + WINPR_ASSERT(uniq_cups_driver->driver.AddRef); + uniq_cups_driver->driver.AddRef(&uniq_cups_driver->driver); + + *ppPrinter = &uniq_cups_driver->driver; + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/printer_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/printer_main.c new file mode 100644 index 0000000000000000000000000000000000000000..01c572ee1cd66c6548cde35c2025a62f50216ac6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/printer_main.c @@ -0,0 +1,1196 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Print Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak + * Copyright 2016 David PHAM-VAN + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "../printer.h" + +#include + +#include + +#define TAG CHANNELS_TAG("printer.client") + +typedef struct +{ + DEVICE device; + + rdpPrinter* printer; + + WINPR_PSLIST_HEADER pIrpList; + + HANDLE event; + HANDLE stopEvent; + + HANDLE thread; + rdpContext* rdpcontext; + char port[64]; + BOOL async; +} PRINTER_DEVICE; + +typedef enum +{ + PRN_CONF_PORT = 0, + PRN_CONF_PNP = 1, + PRN_CONF_DRIVER = 2, + PRN_CONF_DATA = 3 +} prn_conf_t; + +static const char* filemap[] = { "PortDosName", "PnPName", "DriverName", + "CachedPrinterConfigData" }; + +static char* get_printer_config_path(const rdpSettings* settings, const WCHAR* name, size_t length) +{ + const char* path = freerdp_settings_get_string(settings, FreeRDP_ConfigPath); + char* dir = GetCombinedPath(path, "printers"); + char* bname = crypto_base64_encode((const BYTE*)name, length); + char* config = GetCombinedPath(dir, bname); + + if (config && !winpr_PathFileExists(config)) + { + if (!winpr_PathMakePath(config, NULL)) + { + free(config); + config = NULL; + } + } + + free(dir); + free(bname); + return config; +} + +static BOOL printer_write_setting(const char* path, prn_conf_t type, const void* data, + size_t length) +{ + DWORD written = 0; + BOOL rc = FALSE; + HANDLE file = NULL; + char* base64 = NULL; + const char* name = filemap[type]; + char* abs = GetCombinedPath(path, name); + + if (!abs || (length > INT32_MAX)) + { + free(abs); + return FALSE; + } + + file = CreateFileA(abs, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + free(abs); + + if (file == INVALID_HANDLE_VALUE) + return FALSE; + + if (length > 0) + { + base64 = crypto_base64_encode(data, length); + + if (!base64) + goto fail; + + /* base64 char represents 6bit -> 4*(n/3) is the length which is + * always smaller than 2*n */ + const size_t b64len = strnlen(base64, 2 * length); + rc = WriteFile(file, base64, (UINT32)b64len, &written, NULL); + + if (b64len != written) + rc = FALSE; + } + else + rc = TRUE; + +fail: + (void)CloseHandle(file); + free(base64); + return rc; +} + +static BOOL printer_config_valid(const char* path) +{ + if (!path) + return FALSE; + + if (!winpr_PathFileExists(path)) + return FALSE; + + return TRUE; +} + +static BOOL printer_read_setting(const char* path, prn_conf_t type, void** data, UINT32* length) +{ + DWORD lowSize = 0; + DWORD highSize = 0; + DWORD read = 0; + BOOL rc = FALSE; + HANDLE file = NULL; + char* fdata = NULL; + const char* name = filemap[type]; + char* abs = GetCombinedPath(path, name); + + if (!abs) + return FALSE; + + file = CreateFileA(abs, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + free(abs); + + if (file == INVALID_HANDLE_VALUE) + return FALSE; + + lowSize = GetFileSize(file, &highSize); + + if ((lowSize == INVALID_FILE_SIZE) || (highSize != 0)) + goto fail; + + if (lowSize != 0) + { + fdata = malloc(lowSize); + + if (!fdata) + goto fail; + + rc = ReadFile(file, fdata, lowSize, &read, NULL); + + if (lowSize != read) + rc = FALSE; + } + +fail: + (void)CloseHandle(file); + + if (rc && (lowSize <= INT_MAX)) + { + size_t blen = 0; + crypto_base64_decode(fdata, lowSize, (BYTE**)data, &blen); + + if (*data && (blen > 0)) + *length = (UINT32)blen; + else + { + rc = FALSE; + *length = 0; + } + } + else + { + *length = 0; + *data = NULL; + } + + free(fdata); + return rc; +} + +static BOOL printer_save_to_config(const rdpSettings* settings, const char* PortDosName, + size_t PortDosNameLen, const WCHAR* PnPName, size_t PnPNameLen, + const WCHAR* DriverName, size_t DriverNameLen, + const WCHAR* PrinterName, size_t PrintNameLen, + const BYTE* CachedPrinterConfigData, size_t CacheFieldsLen) +{ + BOOL rc = FALSE; + char* path = get_printer_config_path(settings, PrinterName, PrintNameLen); + + if (!path) + goto fail; + + if (!printer_write_setting(path, PRN_CONF_PORT, PortDosName, PortDosNameLen)) + goto fail; + + if (!printer_write_setting(path, PRN_CONF_PNP, PnPName, PnPNameLen)) + goto fail; + + if (!printer_write_setting(path, PRN_CONF_DRIVER, DriverName, DriverNameLen)) + goto fail; + + if (!printer_write_setting(path, PRN_CONF_DATA, CachedPrinterConfigData, CacheFieldsLen)) + goto fail; + +fail: + free(path); + return rc; +} + +static BOOL printer_update_to_config(const rdpSettings* settings, const WCHAR* name, size_t length, + const BYTE* data, size_t datalen) +{ + BOOL rc = FALSE; + char* path = get_printer_config_path(settings, name, length); + rc = printer_write_setting(path, PRN_CONF_DATA, data, datalen); + free(path); + return rc; +} + +static BOOL printer_remove_config(const rdpSettings* settings, const WCHAR* name, size_t length) +{ + BOOL rc = FALSE; + char* path = get_printer_config_path(settings, name, length); + + if (!printer_config_valid(path)) + goto fail; + + rc = winpr_RemoveDirectory(path); +fail: + free(path); + return rc; +} + +static BOOL printer_move_config(const rdpSettings* settings, const WCHAR* oldName, size_t oldLength, + const WCHAR* newName, size_t newLength) +{ + BOOL rc = FALSE; + char* oldPath = get_printer_config_path(settings, oldName, oldLength); + char* newPath = get_printer_config_path(settings, newName, newLength); + + if (printer_config_valid(oldPath)) + rc = winpr_MoveFile(oldPath, newPath); + + free(oldPath); + free(newPath); + return rc; +} + +static BOOL printer_load_from_config(const rdpSettings* settings, rdpPrinter* printer, + PRINTER_DEVICE* printer_dev) +{ + BOOL res = FALSE; + WCHAR* wname = NULL; + size_t wlen = 0; + char* path = NULL; + UINT32 flags = 0; + void* DriverName = NULL; + UINT32 DriverNameLen = 0; + void* PnPName = NULL; + UINT32 PnPNameLen = 0; + void* CachedPrinterConfigData = NULL; + UINT32 CachedFieldsLen = 0; + UINT32 PrinterNameLen = 0; + + if (!settings || !printer || !printer->name) + return FALSE; + + wname = ConvertUtf8ToWCharAlloc(printer->name, &wlen); + + if (!wname) + goto fail; + + wlen++; + path = get_printer_config_path(settings, wname, wlen * sizeof(WCHAR)); + { + const size_t plen = wlen * sizeof(WCHAR); + if (plen > UINT32_MAX) + goto fail; + PrinterNameLen = (UINT32)plen; + } + + if (!path) + goto fail; + + if (printer->is_default) + flags |= RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER; + + if (!printer_read_setting(path, PRN_CONF_PNP, &PnPName, &PnPNameLen)) + { + } + + if (!printer_read_setting(path, PRN_CONF_DRIVER, &DriverName, &DriverNameLen)) + { + size_t len = 0; + DriverName = ConvertUtf8ToWCharAlloc(printer->driver, &len); + if (!DriverName) + goto fail; + const size_t dlen = (len + 1) * sizeof(WCHAR); + if (dlen > UINT32_MAX) + goto fail; + DriverNameLen = (UINT32)dlen; + } + + if (!printer_read_setting(path, PRN_CONF_DATA, &CachedPrinterConfigData, &CachedFieldsLen)) + { + } + + Stream_SetPosition(printer_dev->device.data, 0); + + if (!Stream_EnsureRemainingCapacity(printer_dev->device.data, 24)) + goto fail; + + Stream_Write_UINT32(printer_dev->device.data, flags); + Stream_Write_UINT32(printer_dev->device.data, 0); /* CodePage, reserved */ + Stream_Write_UINT32(printer_dev->device.data, PnPNameLen); /* PnPNameLen */ + Stream_Write_UINT32(printer_dev->device.data, DriverNameLen); + Stream_Write_UINT32(printer_dev->device.data, PrinterNameLen); + Stream_Write_UINT32(printer_dev->device.data, CachedFieldsLen); + + if (!Stream_EnsureRemainingCapacity(printer_dev->device.data, PnPNameLen)) + goto fail; + + if (PnPNameLen > 0) + Stream_Write(printer_dev->device.data, PnPName, PnPNameLen); + + if (!Stream_EnsureRemainingCapacity(printer_dev->device.data, DriverNameLen)) + goto fail; + + Stream_Write(printer_dev->device.data, DriverName, DriverNameLen); + + if (!Stream_EnsureRemainingCapacity(printer_dev->device.data, PrinterNameLen)) + goto fail; + + union + { + char c[2]; + WCHAR w; + } backslash; + backslash.c[0] = '\\'; + backslash.c[1] = '\0'; + + for (WCHAR* wptr = wname; (wptr = _wcschr(wptr, backslash.w));) + *wptr = L'_'; + Stream_Write(printer_dev->device.data, wname, PrinterNameLen); + + if (!Stream_EnsureRemainingCapacity(printer_dev->device.data, CachedFieldsLen)) + goto fail; + + Stream_Write(printer_dev->device.data, CachedPrinterConfigData, CachedFieldsLen); + res = TRUE; +fail: + free(path); + free(wname); + free(PnPName); + free(DriverName); + free(CachedPrinterConfigData); + return res; +} + +static BOOL printer_save_default_config(const rdpSettings* settings, rdpPrinter* printer) +{ + BOOL res = FALSE; + WCHAR* wname = NULL; + WCHAR* driver = NULL; + size_t wlen = 0; + size_t dlen = 0; + char* path = NULL; + + if (!settings || !printer || !printer->name || !printer->driver) + return FALSE; + + wname = ConvertUtf8ToWCharAlloc(printer->name, NULL); + + if (!wname) + goto fail; + + driver = ConvertUtf8ToWCharAlloc(printer->driver, NULL); + + if (!driver) + goto fail; + + wlen = _wcslen(wname) + 1; + dlen = _wcslen(driver) + 1; + path = get_printer_config_path(settings, wname, wlen * sizeof(WCHAR)); + + if (!path) + goto fail; + + if (dlen > 1) + { + if (!printer_write_setting(path, PRN_CONF_DRIVER, driver, dlen * sizeof(WCHAR))) + goto fail; + } + + res = TRUE; +fail: + free(path); + free(wname); + free(driver); + return res; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_process_irp_create(PRINTER_DEVICE* printer_dev, IRP* irp) +{ + rdpPrintJob* printjob = NULL; + + WINPR_ASSERT(printer_dev); + WINPR_ASSERT(irp); + + if (printer_dev->printer) + { + WINPR_ASSERT(printer_dev->printer->CreatePrintJob); + printjob = + printer_dev->printer->CreatePrintJob(printer_dev->printer, irp->devman->id_sequence++); + } + + if (printjob) + { + Stream_Write_UINT32(irp->output, printjob->id); /* FileId */ + } + else + { + Stream_Write_UINT32(irp->output, 0); /* FileId */ + irp->IoStatus = STATUS_PRINT_QUEUE_FULL; + } + + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_process_irp_close(PRINTER_DEVICE* printer_dev, IRP* irp) +{ + rdpPrintJob* printjob = NULL; + + WINPR_ASSERT(printer_dev); + WINPR_ASSERT(irp); + + if (printer_dev->printer) + { + WINPR_ASSERT(printer_dev->printer->FindPrintJob); + printjob = printer_dev->printer->FindPrintJob(printer_dev->printer, irp->FileId); + } + + if (!printjob) + { + irp->IoStatus = STATUS_UNSUCCESSFUL; + } + else + { + printjob->Close(printjob); + } + + Stream_Zero(irp->output, 4); /* Padding(4) */ + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_process_irp_write(PRINTER_DEVICE* printer_dev, IRP* irp) +{ + UINT32 Length = 0; + UINT64 Offset = 0; + rdpPrintJob* printjob = NULL; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(printer_dev); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLength(TAG, irp->input, 32)) + return ERROR_INVALID_DATA; + Stream_Read_UINT32(irp->input, Length); + Stream_Read_UINT64(irp->input, Offset); + (void)Offset; /* [MS-RDPEPC] 2.2.2.9 Server Printer Write Request (DR_PRN_WRITE_REQ) + * reserved for future use, ignore */ + Stream_Seek(irp->input, 20); /* Padding */ + const void* ptr = Stream_ConstPointer(irp->input); + if (!Stream_SafeSeek(irp->input, Length)) + return ERROR_INVALID_DATA; + if (printer_dev->printer) + { + WINPR_ASSERT(printer_dev->printer->FindPrintJob); + printjob = printer_dev->printer->FindPrintJob(printer_dev->printer, irp->FileId); + } + + if (!printjob) + { + irp->IoStatus = STATUS_UNSUCCESSFUL; + Length = 0; + } + else + { + error = printjob->Write(printjob, ptr, Length); + } + + if (error) + { + WLog_ERR(TAG, "printjob->Write failed with error %" PRIu32 "!", error); + return error; + } + + Stream_Write_UINT32(irp->output, Length); + Stream_Write_UINT8(irp->output, 0); /* Padding */ + + WINPR_ASSERT(irp->Complete); + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_process_irp_device_control(PRINTER_DEVICE* printer_dev, IRP* irp) +{ + WINPR_ASSERT(printer_dev); + WINPR_ASSERT(irp); + + Stream_Write_UINT32(irp->output, 0); /* OutputBufferLength */ + + WINPR_ASSERT(irp->Complete); + return irp->Complete(irp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_process_irp(PRINTER_DEVICE* printer_dev, IRP* irp) +{ + UINT error = 0; + + WINPR_ASSERT(printer_dev); + WINPR_ASSERT(irp); + + switch (irp->MajorFunction) + { + case IRP_MJ_CREATE: + if ((error = printer_process_irp_create(printer_dev, irp))) + { + WLog_ERR(TAG, "printer_process_irp_create failed with error %" PRIu32 "!", error); + return error; + } + + break; + + case IRP_MJ_CLOSE: + if ((error = printer_process_irp_close(printer_dev, irp))) + { + WLog_ERR(TAG, "printer_process_irp_close failed with error %" PRIu32 "!", error); + return error; + } + + break; + + case IRP_MJ_WRITE: + if ((error = printer_process_irp_write(printer_dev, irp))) + { + WLog_ERR(TAG, "printer_process_irp_write failed with error %" PRIu32 "!", error); + return error; + } + + break; + + case IRP_MJ_DEVICE_CONTROL: + if ((error = printer_process_irp_device_control(printer_dev, irp))) + { + WLog_ERR(TAG, "printer_process_irp_device_control failed with error %" PRIu32 "!", + error); + return error; + } + + break; + + default: + irp->IoStatus = STATUS_NOT_SUPPORTED; + WINPR_ASSERT(irp->Complete); + return irp->Complete(irp); + } + + return CHANNEL_RC_OK; +} + +static DWORD WINAPI printer_thread_func(LPVOID arg) +{ + IRP* irp = NULL; + PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*)arg; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(printer_dev); + + while (1) + { + HANDLE obj[] = { printer_dev->event, printer_dev->stopEvent }; + DWORD rc = WaitForMultipleObjects(ARRAYSIZE(obj), obj, FALSE, INFINITE); + + if (rc == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "!", error); + break; + } + + if (rc == WAIT_OBJECT_0 + 1) + break; + else if (rc != WAIT_OBJECT_0) + continue; + + (void)ResetEvent(printer_dev->event); + irp = (IRP*)InterlockedPopEntrySList(printer_dev->pIrpList); + + if (irp == NULL) + { + WLog_ERR(TAG, "InterlockedPopEntrySList failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if ((error = printer_process_irp(printer_dev, irp))) + { + WLog_ERR(TAG, "printer_process_irp failed with error %" PRIu32 "!", error); + break; + } + } + + if (error && printer_dev->rdpcontext) + setChannelError(printer_dev->rdpcontext, error, "printer_thread_func reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_irp_request(DEVICE* device, IRP* irp) +{ + PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*)device; + + WINPR_ASSERT(printer_dev); + WINPR_ASSERT(irp); + + if (printer_dev->async) + { + InterlockedPushEntrySList(printer_dev->pIrpList, &(irp->ItemEntry)); + (void)SetEvent(printer_dev->event); + } + else + { + UINT error = printer_process_irp(printer_dev, irp); + if (error) + { + WLog_ERR(TAG, "printer_process_irp failed with error %" PRIu32 "!", error); + return error; + } + } + + return CHANNEL_RC_OK; +} + +static UINT printer_custom_component(DEVICE* device, UINT16 component, UINT16 packetId, wStream* s) +{ + UINT32 eventID = 0; + PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*)device; + + WINPR_ASSERT(printer_dev); + WINPR_ASSERT(printer_dev->rdpcontext); + + const rdpSettings* settings = printer_dev->rdpcontext->settings; + WINPR_ASSERT(settings); + + if (component != RDPDR_CTYP_PRN) + return ERROR_INVALID_DATA; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, eventID); + + switch (packetId) + { + case PAKID_PRN_CACHE_DATA: + switch (eventID) + { + case RDPDR_ADD_PRINTER_EVENT: + { + char PortDosName[8]; + UINT32 PnPNameLen = 0; + UINT32 DriverNameLen = 0; + UINT32 PrintNameLen = 0; + UINT32 CacheFieldsLen = 0; + const WCHAR* PnPName = NULL; + const WCHAR* DriverName = NULL; + const WCHAR* PrinterName = NULL; + const BYTE* CachedPrinterConfigData = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 24)) + return ERROR_INVALID_DATA; + + Stream_Read(s, PortDosName, sizeof(PortDosName)); + Stream_Read_UINT32(s, PnPNameLen); + Stream_Read_UINT32(s, DriverNameLen); + Stream_Read_UINT32(s, PrintNameLen); + Stream_Read_UINT32(s, CacheFieldsLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, PnPNameLen)) + return ERROR_INVALID_DATA; + + PnPName = Stream_ConstPointer(s); + Stream_Seek(s, PnPNameLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, DriverNameLen)) + return ERROR_INVALID_DATA; + + DriverName = Stream_ConstPointer(s); + Stream_Seek(s, DriverNameLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, PrintNameLen)) + return ERROR_INVALID_DATA; + + PrinterName = Stream_ConstPointer(s); + Stream_Seek(s, PrintNameLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, CacheFieldsLen)) + return ERROR_INVALID_DATA; + + CachedPrinterConfigData = Stream_ConstPointer(s); + Stream_Seek(s, CacheFieldsLen); + + if (!printer_save_to_config(settings, PortDosName, sizeof(PortDosName), PnPName, + PnPNameLen, DriverName, DriverNameLen, PrinterName, + PrintNameLen, CachedPrinterConfigData, + CacheFieldsLen)) + return ERROR_INTERNAL_ERROR; + } + break; + + case RDPDR_UPDATE_PRINTER_EVENT: + { + UINT32 PrinterNameLen = 0; + UINT32 ConfigDataLen = 0; + const WCHAR* PrinterName = NULL; + const BYTE* ConfigData = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, PrinterNameLen); + Stream_Read_UINT32(s, ConfigDataLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, PrinterNameLen)) + return ERROR_INVALID_DATA; + + PrinterName = Stream_ConstPointer(s); + Stream_Seek(s, PrinterNameLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, ConfigDataLen)) + return ERROR_INVALID_DATA; + + ConfigData = Stream_ConstPointer(s); + Stream_Seek(s, ConfigDataLen); + + if (!printer_update_to_config(settings, PrinterName, PrinterNameLen, ConfigData, + ConfigDataLen)) + return ERROR_INTERNAL_ERROR; + } + break; + + case RDPDR_DELETE_PRINTER_EVENT: + { + UINT32 PrinterNameLen = 0; + const WCHAR* PrinterName = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, PrinterNameLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, PrinterNameLen)) + return ERROR_INVALID_DATA; + + PrinterName = Stream_ConstPointer(s); + Stream_Seek(s, PrinterNameLen); + printer_remove_config(settings, PrinterName, PrinterNameLen); + } + break; + + case RDPDR_RENAME_PRINTER_EVENT: + { + UINT32 OldPrinterNameLen = 0; + UINT32 NewPrinterNameLen = 0; + const WCHAR* OldPrinterName = NULL; + const WCHAR* NewPrinterName = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, OldPrinterNameLen); + Stream_Read_UINT32(s, NewPrinterNameLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, OldPrinterNameLen)) + return ERROR_INVALID_DATA; + + OldPrinterName = Stream_ConstPointer(s); + Stream_Seek(s, OldPrinterNameLen); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, NewPrinterNameLen)) + return ERROR_INVALID_DATA; + + NewPrinterName = Stream_ConstPointer(s); + Stream_Seek(s, NewPrinterNameLen); + + if (!printer_move_config(settings, OldPrinterName, OldPrinterNameLen, + NewPrinterName, NewPrinterNameLen)) + return ERROR_INTERNAL_ERROR; + } + break; + + default: + WLog_ERR(TAG, "Unknown cache data eventID: 0x%08" PRIX32 "", eventID); + return ERROR_INVALID_DATA; + } + + break; + + case PAKID_PRN_USING_XPS: + { + UINT32 flags = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, flags); + WLog_ERR(TAG, + "Ignoring unhandled message PAKID_PRN_USING_XPS [printerID=%08" PRIx32 + ", flags=%08" PRIx32 "]", + eventID, flags); + } + break; + + default: + WLog_ERR(TAG, "Unknown printing component packetID: 0x%04" PRIX16 "", packetId); + return ERROR_INVALID_DATA; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_free(DEVICE* device) +{ + IRP* irp = NULL; + PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*)device; + UINT error = 0; + + WINPR_ASSERT(printer_dev); + + if (printer_dev->async) + { + (void)SetEvent(printer_dev->stopEvent); + + if (WaitForSingleObject(printer_dev->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + + /* The analyzer is confused by this premature return value. + * Since this case can not be handled gracefully silence the + * analyzer here. */ +#ifndef __clang_analyzer__ + return error; +#endif + } + + while ((irp = (IRP*)InterlockedPopEntrySList(printer_dev->pIrpList)) != NULL) + { + WINPR_ASSERT(irp->Discard); + irp->Discard(irp); + } + + (void)CloseHandle(printer_dev->thread); + (void)CloseHandle(printer_dev->stopEvent); + (void)CloseHandle(printer_dev->event); + winpr_aligned_free(printer_dev->pIrpList); + } + + if (printer_dev->printer) + { + WINPR_ASSERT(printer_dev->printer->ReleaseRef); + printer_dev->printer->ReleaseRef(printer_dev->printer); + } + + Stream_Free(printer_dev->device.data, TRUE); + free(printer_dev); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrinter* printer) +{ + PRINTER_DEVICE* printer_dev = NULL; + UINT error = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(pEntryPoints); + WINPR_ASSERT(printer); + + printer_dev = (PRINTER_DEVICE*)calloc(1, sizeof(PRINTER_DEVICE)); + + if (!printer_dev) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + printer_dev->device.data = Stream_New(NULL, 1024); + + if (!printer_dev->device.data) + goto error_out; + + (void)sprintf_s(printer_dev->port, sizeof(printer_dev->port), "PRN%" PRIuz, printer->id); + printer_dev->device.type = RDPDR_DTYP_PRINT; + printer_dev->device.name = printer_dev->port; + printer_dev->device.IRPRequest = printer_irp_request; + printer_dev->device.CustomComponentRequest = printer_custom_component; + printer_dev->device.Free = printer_free; + printer_dev->rdpcontext = pEntryPoints->rdpcontext; + printer_dev->printer = printer; + + if (!freerdp_settings_get_bool(pEntryPoints->rdpcontext->settings, + FreeRDP_SynchronousStaticChannels)) + printer_dev->async = TRUE; + + if (!printer_load_from_config(pEntryPoints->rdpcontext->settings, printer, printer_dev)) + goto error_out; + + if (printer_dev->async) + { + printer_dev->pIrpList = (WINPR_PSLIST_HEADER)winpr_aligned_malloc( + sizeof(WINPR_SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); + + if (!printer_dev->pIrpList) + { + WLog_ERR(TAG, "_aligned_malloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + InitializeSListHead(printer_dev->pIrpList); + + printer_dev->event = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!printer_dev->event) + { + WLog_ERR(TAG, "CreateEvent failed!"); + error = ERROR_INTERNAL_ERROR; + goto error_out; + } + + printer_dev->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!printer_dev->stopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + error = ERROR_INTERNAL_ERROR; + goto error_out; + } + } + + error = pEntryPoints->RegisterDevice(pEntryPoints->devman, &printer_dev->device); + if (error) + { + WLog_ERR(TAG, "RegisterDevice failed with error %" PRIu32 "!", error); + goto error_out; + } + + if (printer_dev->async) + { + printer_dev->thread = + CreateThread(NULL, 0, printer_thread_func, (void*)printer_dev, 0, NULL); + if (!printer_dev->thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + error = ERROR_INTERNAL_ERROR; + goto error_out; + } + } + + WINPR_ASSERT(printer->AddRef); + printer->AddRef(printer); + return CHANNEL_RC_OK; +error_out: + printer_free(&printer_dev->device); + return error; +} + +static rdpPrinterDriver* printer_load_backend(const char* backend) +{ + typedef UINT(VCAPITYPE * backend_load_t)(rdpPrinterDriver**); + PVIRTUALCHANNELENTRY entry = freerdp_load_channel_addin_entry("printer", backend, NULL, 0); + backend_load_t func = WINPR_FUNC_PTR_CAST(entry, backend_load_t); + if (!func) + return NULL; + + rdpPrinterDriver* printer = NULL; + const UINT rc = func(&printer); + if (rc != CHANNEL_RC_OK) + return NULL; + + return printer; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT( + UINT VCAPITYPE printer_DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)) +{ + char* name = NULL; + char* driver_name = NULL; + BOOL default_backend = TRUE; + RDPDR_PRINTER* device = NULL; + rdpPrinterDriver* driver = NULL; + UINT error = CHANNEL_RC_OK; + + if (!pEntryPoints || !pEntryPoints->device) + return ERROR_INVALID_PARAMETER; + + device = (RDPDR_PRINTER*)pEntryPoints->device; + name = device->device.Name; + driver_name = _strdup(device->DriverName); + + /* Secondary argument is one of the following: + * + * ... name of a printer driver + * : ... name of a printer driver and local printer backend to use + */ + if (driver_name) + { + char* sep = strstr(driver_name, ":"); + if (sep) + { + const char* backend = sep + 1; + *sep = '\0'; + driver = printer_load_backend(backend); + default_backend = FALSE; + } + } + + if (!driver && default_backend) + { + const char* backend = +#if defined(WITH_CUPS) + "cups" +#elif defined(_WIN32) + "win" +#else + "" +#endif + ; + + driver = printer_load_backend(backend); + } + + if (!driver) + { + WLog_ERR(TAG, "Could not get a printer driver!"); + error = CHANNEL_RC_INITIALIZATION_ERROR; + goto fail; + } + + if (name && name[0]) + { + WINPR_ASSERT(driver->GetPrinter); + rdpPrinter* printer = driver->GetPrinter(driver, name, driver_name, device->IsDefault); + + if (!printer) + { + WLog_ERR(TAG, "Could not get printer %s!", name); + error = CHANNEL_RC_INITIALIZATION_ERROR; + goto fail; + } + + WINPR_ASSERT(printer->ReleaseRef); + if (!printer_save_default_config(pEntryPoints->rdpcontext->settings, printer)) + { + error = CHANNEL_RC_INITIALIZATION_ERROR; + printer->ReleaseRef(printer); + goto fail; + } + + error = printer_register(pEntryPoints, printer); + printer->ReleaseRef(printer); + if (error) + { + WLog_ERR(TAG, "printer_register failed with error %" PRIu32 "!", error); + goto fail; + } + } + else + { + WINPR_ASSERT(driver->EnumPrinters); + rdpPrinter** printers = driver->EnumPrinters(driver); + if (printers) + { + for (rdpPrinter** current = printers; *current; ++current) + { + error = printer_register(pEntryPoints, *current); + if (error) + { + WLog_ERR(TAG, "printer_register failed with error %" PRIu32 "!", error); + break; + } + } + } + else + { + WLog_ERR(TAG, "Failed to enumerate printers!"); + error = CHANNEL_RC_INITIALIZATION_ERROR; + } + + WINPR_ASSERT(driver->ReleaseEnumPrinters); + driver->ReleaseEnumPrinters(printers); + } + +fail: + free(driver_name); + if (driver) + { + WINPR_ASSERT(driver->ReleaseRef); + driver->ReleaseRef(driver); + } + + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/win/printer_win.c b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/win/printer_win.c new file mode 100644 index 0000000000000000000000000000000000000000..c92b60249a4d9d7582cd39c10ef12417057ab7d1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/client/win/printer_win.c @@ -0,0 +1,467 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Print Virtual Channel - WIN driver + * + * Copyright 2012 Gerald Richter + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#define WIDEN_INT(x) L##x +#define WIDEN(x) WIDEN_INT(x) +#define PRINTER_TAG CHANNELS_TAG("printer.client") +#ifdef WITH_DEBUG_WINPR +#define DEBUG_WINPR(...) WLog_DBG(PRINTER_TAG, __VA_ARGS__) +#else +#define DEBUG_WINPR(...) \ + do \ + { \ + } while (0) +#endif + +typedef struct +{ + rdpPrinterDriver driver; + + size_t id_sequence; + size_t references; +} rdpWinPrinterDriver; + +typedef struct +{ + rdpPrintJob printjob; + DOC_INFO_1 di; + DWORD handle; + + void* printjob_object; + int printjob_id; +} rdpWinPrintJob; + +typedef struct +{ + rdpPrinter printer; + HANDLE hPrinter; + rdpWinPrintJob* printjob; +} rdpWinPrinter; + +static WCHAR* printer_win_get_printjob_name(size_t id) +{ + time_t tt; + struct tm tres; + errno_t err; + WCHAR* str; + size_t len = 1024; + int rc; + + tt = time(NULL); + err = localtime_s(&tres, &tt); + + str = calloc(len, sizeof(WCHAR)); + if (!str) + return NULL; + + rc = swprintf_s(str, len, + WIDEN("FreeRDP Print %04d-%02d-%02d% 02d-%02d-%02d - Job %") WIDEN(PRIuz) + WIDEN("\0"), + tres.tm_year + 1900, tres.tm_mon + 1, tres.tm_mday, tres.tm_hour, tres.tm_min, + tres.tm_sec, id); + + return str; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT printer_win_write_printjob(rdpPrintJob* printjob, const BYTE* data, size_t size) +{ + rdpWinPrinter* printer; + LPCVOID pBuf = data; + DWORD cbBuf = size; + DWORD pcWritten; + + if (!printjob || !data) + return ERROR_BAD_ARGUMENTS; + + printer = (rdpWinPrinter*)printjob->printer; + if (!printer) + return ERROR_BAD_ARGUMENTS; + + if (!WritePrinter(printer->hPrinter, pBuf, cbBuf, &pcWritten)) + return ERROR_INTERNAL_ERROR; + return CHANNEL_RC_OK; +} + +static void printer_win_close_printjob(rdpPrintJob* printjob) +{ + rdpWinPrintJob* win_printjob = (rdpWinPrintJob*)printjob; + rdpWinPrinter* win_printer; + + if (!printjob) + return; + + win_printer = (rdpWinPrinter*)printjob->printer; + if (!win_printer) + return; + + if (!EndPagePrinter(win_printer->hPrinter)) + { + } + + if (!EndDocPrinter(win_printer->hPrinter)) + { + } + + win_printer->printjob = NULL; + + free(win_printjob->di.pDocName); + free(win_printjob); +} + +static rdpPrintJob* printer_win_create_printjob(rdpPrinter* printer, UINT32 id) +{ + rdpWinPrinter* win_printer = (rdpWinPrinter*)printer; + rdpWinPrintJob* win_printjob; + + if (win_printer->printjob != NULL) + return NULL; + + win_printjob = (rdpWinPrintJob*)calloc(1, sizeof(rdpWinPrintJob)); + if (!win_printjob) + return NULL; + + win_printjob->printjob.id = id; + win_printjob->printjob.printer = printer; + win_printjob->di.pDocName = printer_win_get_printjob_name(id); + win_printjob->di.pDatatype = NULL; + win_printjob->di.pOutputFile = NULL; + + win_printjob->handle = StartDocPrinter(win_printer->hPrinter, 1, (LPBYTE) & (win_printjob->di)); + + if (!win_printjob->handle) + { + free(win_printjob->di.pDocName); + free(win_printjob); + return NULL; + } + + if (!StartPagePrinter(win_printer->hPrinter)) + { + free(win_printjob->di.pDocName); + free(win_printjob); + return NULL; + } + + win_printjob->printjob.Write = printer_win_write_printjob; + win_printjob->printjob.Close = printer_win_close_printjob; + + win_printer->printjob = win_printjob; + + return &win_printjob->printjob; +} + +static rdpPrintJob* printer_win_find_printjob(rdpPrinter* printer, UINT32 id) +{ + rdpWinPrinter* win_printer = (rdpWinPrinter*)printer; + + if (!win_printer->printjob) + return NULL; + + if (win_printer->printjob->printjob.id != id) + return NULL; + + return (rdpPrintJob*)win_printer->printjob; +} + +static void printer_win_free_printer(rdpPrinter* printer) +{ + rdpWinPrinter* win_printer = (rdpWinPrinter*)printer; + + if (win_printer->printjob) + win_printer->printjob->printjob.Close((rdpPrintJob*)win_printer->printjob); + + if (win_printer->hPrinter) + ClosePrinter(win_printer->hPrinter); + + if (printer->backend) + printer->backend->ReleaseRef(printer->backend); + + free(printer->name); + free(printer->driver); + free(printer); +} + +static void printer_win_add_ref_printer(rdpPrinter* printer) +{ + if (printer) + printer->references++; +} + +static void printer_win_release_ref_printer(rdpPrinter* printer) +{ + if (!printer) + return; + if (printer->references <= 1) + printer_win_free_printer(printer); + else + printer->references--; +} + +static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver, const WCHAR* name, + const WCHAR* drivername, BOOL is_default) +{ + rdpWinPrinter* win_printer; + DWORD needed = 0; + PRINTER_INFO_2* prninfo = NULL; + + if (!name) + return NULL; + + win_printer = (rdpWinPrinter*)calloc(1, sizeof(rdpWinPrinter)); + if (!win_printer) + return NULL; + + win_printer->printer.backend = &win_driver->driver; + win_printer->printer.id = win_driver->id_sequence++; + win_printer->printer.name = ConvertWCharToUtf8Alloc(name, NULL); + if (!win_printer->printer.name) + goto fail; + + if (!win_printer->printer.name) + goto fail; + win_printer->printer.is_default = is_default; + + win_printer->printer.CreatePrintJob = printer_win_create_printjob; + win_printer->printer.FindPrintJob = printer_win_find_printjob; + win_printer->printer.AddRef = printer_win_add_ref_printer; + win_printer->printer.ReleaseRef = printer_win_release_ref_printer; + + if (!OpenPrinter(name, &(win_printer->hPrinter), NULL)) + goto fail; + + /* How many memory should be allocated for printer data */ + GetPrinter(win_printer->hPrinter, 2, (LPBYTE)prninfo, 0, &needed); + if (needed == 0) + goto fail; + + prninfo = (PRINTER_INFO_2*)GlobalAlloc(GPTR, needed); + if (!prninfo) + goto fail; + + if (!GetPrinter(win_printer->hPrinter, 2, (LPBYTE)prninfo, needed, &needed)) + { + GlobalFree(prninfo); + goto fail; + } + + if (drivername) + win_printer->printer.driver = ConvertWCharToUtf8Alloc(drivername, NULL); + else + win_printer->printer.driver = ConvertWCharToUtf8Alloc(prninfo->pDriverName, NULL); + GlobalFree(prninfo); + if (!win_printer->printer.driver) + goto fail; + + win_printer->printer.AddRef(&win_printer->printer); + win_printer->printer.backend->AddRef(win_printer->printer.backend); + return &win_printer->printer; + +fail: + printer_win_free_printer(&win_printer->printer); + return NULL; +} + +static void printer_win_release_enum_printers(rdpPrinter** printers) +{ + rdpPrinter** cur = printers; + + while ((cur != NULL) && ((*cur) != NULL)) + { + if ((*cur)->ReleaseRef) + (*cur)->ReleaseRef(*cur); + cur++; + } + free(printers); +} + +static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver) +{ + rdpPrinter** printers; + int num_printers; + PRINTER_INFO_2* prninfo = NULL; + DWORD needed, returned; + BOOL haveDefault = FALSE; + LPWSTR defaultPrinter = NULL; + + GetDefaultPrinter(NULL, &needed); + if (needed) + { + defaultPrinter = (LPWSTR)calloc(needed, sizeof(WCHAR)); + + if (!defaultPrinter) + return NULL; + + if (!GetDefaultPrinter(defaultPrinter, &needed)) + defaultPrinter[0] = '\0'; + } + + /* find required size for the buffer */ + EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, + &returned); + + /* allocate array of PRINTER_INFO structures */ + prninfo = (PRINTER_INFO_2*)GlobalAlloc(GPTR, needed); + if (!prninfo) + { + free(defaultPrinter); + return NULL; + } + + /* call again */ + if (!EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 2, (LPBYTE)prninfo, + needed, &needed, &returned)) + { + } + + printers = (rdpPrinter**)calloc((returned + 1), sizeof(rdpPrinter*)); + if (!printers) + { + GlobalFree(prninfo); + free(defaultPrinter); + return NULL; + } + + num_printers = 0; + + for (int i = 0; i < (int)returned; i++) + { + rdpPrinter* current = printers[num_printers]; + current = printer_win_new_printer((rdpWinPrinterDriver*)driver, prninfo[i].pPrinterName, + prninfo[i].pDriverName, + _wcscmp(prninfo[i].pPrinterName, defaultPrinter) == 0); + if (!current) + { + printer_win_release_enum_printers(printers); + printers = NULL; + break; + } + if (current->is_default) + haveDefault = TRUE; + printers[num_printers++] = current; + } + + if (!haveDefault && (returned > 0)) + printers[0]->is_default = TRUE; + + GlobalFree(prninfo); + free(defaultPrinter); + return printers; +} + +static rdpPrinter* printer_win_get_printer(rdpPrinterDriver* driver, const char* name, + const char* driverName, BOOL isDefault) +{ + WCHAR* driverNameW = NULL; + WCHAR* nameW = NULL; + rdpWinPrinterDriver* win_driver = (rdpWinPrinterDriver*)driver; + rdpPrinter* myPrinter = NULL; + + if (name) + { + nameW = ConvertUtf8ToWCharAlloc(name, NULL); + if (!nameW) + return NULL; + } + if (driverName) + { + driverNameW = ConvertUtf8ToWCharAlloc(driverName, NULL); + if (!driverNameW) + return NULL; + } + + myPrinter = printer_win_new_printer(win_driver, nameW, driverNameW, isDefault); + free(driverNameW); + free(nameW); + + return myPrinter; +} + +static void printer_win_add_ref_driver(rdpPrinterDriver* driver) +{ + rdpWinPrinterDriver* win = (rdpWinPrinterDriver*)driver; + if (win) + win->references++; +} + +/* Singleton */ +static rdpWinPrinterDriver* win_driver = NULL; + +static void printer_win_release_ref_driver(rdpPrinterDriver* driver) +{ + rdpWinPrinterDriver* win = (rdpWinPrinterDriver*)driver; + if (win->references <= 1) + { + free(win); + win_driver = NULL; + } + else + win->references--; +} + +FREERDP_ENTRY_POINT(UINT VCAPITYPE win_freerdp_printer_client_subsystem_entry(void* arg)) +{ + rdpPrinterDriver** ppPrinter = (rdpPrinterDriver**)arg; + if (!ppPrinter) + return ERROR_INVALID_PARAMETER; + + if (!win_driver) + { + win_driver = (rdpWinPrinterDriver*)calloc(1, sizeof(rdpWinPrinterDriver)); + + if (!win_driver) + return ERROR_OUTOFMEMORY; + + win_driver->driver.EnumPrinters = printer_win_enum_printers; + win_driver->driver.ReleaseEnumPrinters = printer_win_release_enum_printers; + win_driver->driver.GetPrinter = printer_win_get_printer; + + win_driver->driver.AddRef = printer_win_add_ref_driver; + win_driver->driver.ReleaseRef = printer_win_release_ref_driver; + + win_driver->id_sequence = 1; + } + + win_driver->driver.AddRef(&win_driver->driver); + + *ppPrinter = &win_driver->driver; + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/printer/printer.h b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/printer.h new file mode 100644 index 0000000000000000000000000000000000000000..ae0902dff76cf1d9b1011a8910d354fb9d5a065a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/printer/printer.h @@ -0,0 +1,36 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Definition for the printer channel + * + * Copyright 2016 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_PRINTER_PRINTER_H +#define FREERDP_CHANNEL_PRINTER_PRINTER_H + +/* SERVER_PRINTER_CACHE_EVENT.cachedata */ +#define RDPDR_ADD_PRINTER_EVENT 0x00000001 +#define RDPDR_UPDATE_PRINTER_EVENT 0x00000002 +#define RDPDR_DELETE_PRINTER_EVENT 0x00000003 +#define RDPDR_RENAME_PRINTER_EVENT 0x00000004 + +/* DR_PRN_DEVICE_ANNOUNCE.Flags */ +#define RDPDR_PRINTER_ANNOUNCE_FLAG_ASCII 0x00000001 +#define RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER 0x00000002 +#define RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER 0x00000004 +#define RDPDR_PRINTER_ANNOUNCE_FLAG_TSPRINTER 0x00000008 +#define RDPDR_PRINTER_ANNOUNCE_FLAG_XPSFORMAT 0x00000010 + +#endif /* FREERDP_CHANNEL_PRINTER_PRINTER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2d0c0732026bb878417f0c2811054f019b01fef6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rail") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..8cff6368480713a61608d4271d61b73ed443a256 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "rail" + TYPE + "static" + DESCRIPTION + "Remote Programs Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPERP]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5227766fa676eefad9ba5024b088f16f28e43d57 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/CMakeLists.txt @@ -0,0 +1,31 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("rail") + +set(${MODULE_PREFIX}_SRCS + ../rail_common.h + ../rail_common.c + client_rails.c + rail_main.c + rail_main.h + rail_orders.c + rail_orders.h +) + +set(${MODULE_PREFIX}_LIBS freerdp) +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntryEx") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/client_rails.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/client_rails.c new file mode 100644 index 0000000000000000000000000000000000000000..e2108a4e6137a2399c3d6f9ff30a0b510a77df69 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/client_rails.c @@ -0,0 +1,104 @@ + +#include + +#include +#include + +#include "rail_main.h" + +UINT client_rail_server_start_cmd(RailClientContext* context) +{ + UINT status = 0; + char argsAndFile[520] = { 0 }; + RAIL_EXEC_ORDER exec = { 0 }; + RAIL_SYSPARAM_ORDER sysparam = { 0 }; + RAIL_CLIENT_STATUS_ORDER clientStatus = { 0 }; + + WINPR_ASSERT(context); + railPlugin* rail = context->handle; + WINPR_ASSERT(rail); + WINPR_ASSERT(rail->rdpcontext); + + const rdpSettings* settings = rail->rdpcontext->settings; + WINPR_ASSERT(settings); + + clientStatus.flags = TS_RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE; + + if (freerdp_settings_get_bool(settings, FreeRDP_AutoReconnectionEnabled)) + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_AUTORECONNECT; + + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_ZORDER_SYNC; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_WINDOW_RESIZE_MARGIN_SUPPORTED; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_APPBAR_REMOTING_SUPPORTED; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED; + clientStatus.flags |= TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED; + status = context->ClientInformation(context, &clientStatus); + + if (status != CHANNEL_RC_OK) + return status; + + if (freerdp_settings_get_bool(settings, FreeRDP_RemoteAppLanguageBarSupported)) + { + RAIL_LANGBAR_INFO_ORDER langBarInfo; + langBarInfo.languageBarStatus = 0x00000008; /* TF_SFT_HIDDEN */ + status = context->ClientLanguageBarInfo(context, &langBarInfo); + + /* We want the language bar, but the server might not support it. */ + switch (status) + { + case CHANNEL_RC_OK: + case ERROR_BAD_CONFIGURATION: + break; + default: + return status; + } + } + + sysparam.params = 0; + sysparam.params |= SPI_MASK_SET_HIGH_CONTRAST; + sysparam.highContrast.colorScheme.string = NULL; + sysparam.highContrast.colorScheme.length = 0; + sysparam.highContrast.flags = 0x7E; + sysparam.params |= SPI_MASK_SET_MOUSE_BUTTON_SWAP; + sysparam.mouseButtonSwap = FALSE; + sysparam.params |= SPI_MASK_SET_KEYBOARD_PREF; + sysparam.keyboardPref = FALSE; + sysparam.params |= SPI_MASK_SET_DRAG_FULL_WINDOWS; + sysparam.dragFullWindows = FALSE; + sysparam.params |= SPI_MASK_SET_KEYBOARD_CUES; + sysparam.keyboardCues = FALSE; + sysparam.params |= SPI_MASK_SET_WORK_AREA; + sysparam.workArea.left = 0; + sysparam.workArea.top = 0; + + const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth); + const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight); + + sysparam.workArea.right = WINPR_ASSERTING_INT_CAST(UINT16, w); + sysparam.workArea.bottom = WINPR_ASSERTING_INT_CAST(UINT16, h); + sysparam.dragFullWindows = FALSE; + status = context->ClientSystemParam(context, &sysparam); + + if (status != CHANNEL_RC_OK) + return status; + + const char* RemoteApplicationFile = + freerdp_settings_get_string(settings, FreeRDP_RemoteApplicationFile); + const char* RemoteApplicationCmdLine = + freerdp_settings_get_string(settings, FreeRDP_RemoteApplicationCmdLine); + if (RemoteApplicationFile && RemoteApplicationCmdLine) + { + (void)_snprintf(argsAndFile, ARRAYSIZE(argsAndFile), "%s %s", RemoteApplicationCmdLine, + RemoteApplicationFile); + exec.RemoteApplicationArguments = argsAndFile; + } + else if (RemoteApplicationFile) + exec.RemoteApplicationArguments = RemoteApplicationFile; + else + exec.RemoteApplicationArguments = RemoteApplicationCmdLine; + exec.RemoteApplicationProgram = + freerdp_settings_get_string(settings, FreeRDP_RemoteApplicationProgram); + exec.RemoteApplicationWorkingDir = + freerdp_settings_get_string(settings, FreeRDP_ShellWorkingDirectory); + return context->ClientExecute(context, &exec); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_main.c new file mode 100644 index 0000000000000000000000000000000000000000..abca0005ffd038a542ad2fc2e813452dec217390 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_main.c @@ -0,0 +1,760 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RAIL Virtual Channel Plugin + * + * Copyright 2011 Marc-Andre Moreau + * Copyright 2011 Roman Barabanov + * Copyright 2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2017 Armin Novak + * Copyright 2017 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include +#include + +#include "rail_orders.h" +#include "rail_main.h" + +#include "../../../channels/client/addin.h" + +RailClientContext* rail_get_client_interface(railPlugin* rail) +{ + RailClientContext* pInterface = NULL; + + if (!rail) + return NULL; + + pInterface = (RailClientContext*)rail->channelEntryPoints.pInterface; + return pInterface; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send(railPlugin* rail, wStream* s) +{ + UINT status = 0; + + if (!rail) + { + Stream_Free(s, TRUE); + return CHANNEL_RC_BAD_INIT_HANDLE; + } + + status = rail->channelEntryPoints.pVirtualChannelWriteEx( + rail->InitHandle, rail->OpenHandle, Stream_Buffer(s), (UINT32)Stream_GetPosition(s), s); + + if (status != CHANNEL_RC_OK) + { + Stream_Free(s, TRUE); + WLog_ERR(TAG, "pVirtualChannelWriteEx failed with %s [%08" PRIX32 "]", + WTSErrorToString(status), status); + } + + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_channel_data(railPlugin* rail, wStream* src) +{ + if (!rail || !src) + { + Stream_Free(src, TRUE); + return ERROR_INVALID_PARAMETER; + } + + return rail_send(rail, src); +} + +/** + * Callback Interface + */ + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_execute(RailClientContext* context, const RAIL_EXEC_ORDER* exec) +{ + const char* exeOrFile = NULL; + UINT error = 0; + railPlugin* rail = NULL; + UINT16 flags = 0; + RAIL_UNICODE_STRING ruExeOrFile = { 0 }; + RAIL_UNICODE_STRING ruWorkingDir = { 0 }; + RAIL_UNICODE_STRING ruArguments = { 0 }; + + if (!context || !exec) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + exeOrFile = exec->RemoteApplicationProgram; + flags = exec->flags; + + if (!exeOrFile) + return ERROR_INVALID_PARAMETER; + + if (!utf8_string_to_rail_string(exec->RemoteApplicationProgram, + &ruExeOrFile) || /* RemoteApplicationProgram */ + !utf8_string_to_rail_string(exec->RemoteApplicationWorkingDir, + &ruWorkingDir) || /* ShellWorkingDirectory */ + !utf8_string_to_rail_string(exec->RemoteApplicationArguments, + &ruArguments)) /* RemoteApplicationCmdLine */ + error = ERROR_INTERNAL_ERROR; + else + error = rail_send_client_exec_order(rail, flags, &ruExeOrFile, &ruWorkingDir, &ruArguments); + + free(ruExeOrFile.string); + free(ruWorkingDir.string); + free(ruArguments.string); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_activate(RailClientContext* context, const RAIL_ACTIVATE_ORDER* activate) +{ + railPlugin* rail = NULL; + + if (!context || !activate) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_activate_order(rail, activate); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_client_sysparam(RailClientContext* context, RAIL_SYSPARAM_ORDER* sysparam) +{ + wStream* s = NULL; + size_t length = RAIL_SYSPARAM_ORDER_LENGTH; + railPlugin* rail = NULL; + UINT error = 0; + BOOL extendedSpiSupported = 0; + + if (!context || !sysparam) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + + switch (sysparam->param) + { + case SPI_SET_DRAG_FULL_WINDOWS: + case SPI_SET_KEYBOARD_CUES: + case SPI_SET_KEYBOARD_PREF: + case SPI_SET_MOUSE_BUTTON_SWAP: + length += 1; + break; + + case SPI_SET_WORK_AREA: + case SPI_DISPLAY_CHANGE: + case SPI_TASKBAR_POS: + length += 8; + break; + + case SPI_SET_HIGH_CONTRAST: + length += sysparam->highContrast.colorSchemeLength + 10; + break; + + case SPI_SETFILTERKEYS: + length += 20; + break; + + case SPI_SETSTICKYKEYS: + case SPI_SETCARETWIDTH: + case SPI_SETTOGGLEKEYS: + length += 4; + break; + + default: + return ERROR_BAD_ARGUMENTS; + } + + s = rail_pdu_init(length); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + extendedSpiSupported = rail_is_extended_spi_supported(rail->channelFlags); + if ((error = rail_write_sysparam_order(s, sysparam, extendedSpiSupported))) + { + WLog_ERR(TAG, "rail_write_client_sysparam_order failed with error %" PRIu32 "!", error); + Stream_Free(s, TRUE); + return error; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSPARAM); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_system_param(RailClientContext* context, + const RAIL_SYSPARAM_ORDER* sysInParam) +{ + UINT error = CHANNEL_RC_OK; + RAIL_SYSPARAM_ORDER sysparam; + + if (!context || !sysInParam) + return ERROR_INVALID_PARAMETER; + + sysparam = *sysInParam; + + if (sysparam.params & SPI_MASK_SET_HIGH_CONTRAST) + { + sysparam.param = SPI_SET_HIGH_CONTRAST; + + if ((error = rail_send_client_sysparam(context, &sysparam))) + { + WLog_ERR(TAG, "rail_send_client_sysparam failed with error %" PRIu32 "!", error); + return error; + } + } + + if (sysparam.params & SPI_MASK_TASKBAR_POS) + { + sysparam.param = SPI_TASKBAR_POS; + + if ((error = rail_send_client_sysparam(context, &sysparam))) + { + WLog_ERR(TAG, "rail_send_client_sysparam failed with error %" PRIu32 "!", error); + return error; + } + } + + if (sysparam.params & SPI_MASK_SET_MOUSE_BUTTON_SWAP) + { + sysparam.param = SPI_SET_MOUSE_BUTTON_SWAP; + + if ((error = rail_send_client_sysparam(context, &sysparam))) + { + WLog_ERR(TAG, "rail_send_client_sysparam failed with error %" PRIu32 "!", error); + return error; + } + } + + if (sysparam.params & SPI_MASK_SET_KEYBOARD_PREF) + { + sysparam.param = SPI_SET_KEYBOARD_PREF; + + if ((error = rail_send_client_sysparam(context, &sysparam))) + { + WLog_ERR(TAG, "rail_send_client_sysparam failed with error %" PRIu32 "!", error); + return error; + } + } + + if (sysparam.params & SPI_MASK_SET_DRAG_FULL_WINDOWS) + { + sysparam.param = SPI_SET_DRAG_FULL_WINDOWS; + + if ((error = rail_send_client_sysparam(context, &sysparam))) + { + WLog_ERR(TAG, "rail_send_client_sysparam failed with error %" PRIu32 "!", error); + return error; + } + } + + if (sysparam.params & SPI_MASK_SET_KEYBOARD_CUES) + { + sysparam.param = SPI_SET_KEYBOARD_CUES; + + if ((error = rail_send_client_sysparam(context, &sysparam))) + { + WLog_ERR(TAG, "rail_send_client_sysparam failed with error %" PRIu32 "!", error); + return error; + } + } + + if (sysparam.params & SPI_MASK_SET_WORK_AREA) + { + sysparam.param = SPI_SET_WORK_AREA; + + if ((error = rail_send_client_sysparam(context, &sysparam))) + { + WLog_ERR(TAG, "rail_send_client_sysparam failed with error %" PRIu32 "!", error); + return error; + } + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_system_command(RailClientContext* context, + const RAIL_SYSCOMMAND_ORDER* syscommand) +{ + railPlugin* rail = NULL; + + if (!context || !syscommand) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_syscommand_order(rail, syscommand); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_handshake(RailClientContext* context, const RAIL_HANDSHAKE_ORDER* handshake) +{ + railPlugin* rail = NULL; + + if (!context || !handshake) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_handshake_order(rail, handshake); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_notify_event(RailClientContext* context, + const RAIL_NOTIFY_EVENT_ORDER* notifyEvent) +{ + railPlugin* rail = NULL; + + if (!context || !notifyEvent) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_notify_event_order(rail, notifyEvent); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_window_move(RailClientContext* context, + const RAIL_WINDOW_MOVE_ORDER* windowMove) +{ + railPlugin* rail = NULL; + + if (!context || !windowMove) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_window_move_order(rail, windowMove); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_information(RailClientContext* context, + const RAIL_CLIENT_STATUS_ORDER* clientStatus) +{ + railPlugin* rail = NULL; + + if (!context || !clientStatus) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_status_order(rail, clientStatus); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_system_menu(RailClientContext* context, const RAIL_SYSMENU_ORDER* sysmenu) +{ + railPlugin* rail = NULL; + + if (!context || !sysmenu) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_sysmenu_order(rail, sysmenu); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_language_bar_info(RailClientContext* context, + const RAIL_LANGBAR_INFO_ORDER* langBarInfo) +{ + railPlugin* rail = NULL; + + if (!context || !langBarInfo) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_langbar_info_order(rail, langBarInfo); +} + +static UINT rail_client_language_ime_info(RailClientContext* context, + const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo) +{ + railPlugin* rail = NULL; + + if (!context || !langImeInfo) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_languageime_info_order(rail, langImeInfo); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_client_get_appid_request(RailClientContext* context, + const RAIL_GET_APPID_REQ_ORDER* getAppIdReq) +{ + railPlugin* rail = NULL; + + if (!context || !getAppIdReq || !context->handle) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_get_appid_req_order(rail, getAppIdReq); +} + +static UINT rail_client_compartment_info(RailClientContext* context, + const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo) +{ + railPlugin* rail = NULL; + + if (!context || !compartmentInfo || !context->handle) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_compartment_info_order(rail, compartmentInfo); +} + +static UINT rail_client_cloak(RailClientContext* context, const RAIL_CLOAK* cloak) +{ + railPlugin* rail = NULL; + + if (!context || !cloak || !context->handle) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_cloak_order(rail, cloak); +} + +static UINT rail_client_snap_arrange(RailClientContext* context, const RAIL_SNAP_ARRANGE* snap) +{ + railPlugin* rail = NULL; + + if (!context || !snap || !context->handle) + return ERROR_INVALID_PARAMETER; + + rail = (railPlugin*)context->handle; + return rail_send_client_snap_arrange_order(rail, snap); +} + +static UINT rail_client_text_scale(RailClientContext* context, UINT32 textScale) +{ + if (!context || !context->handle) + return ERROR_INVALID_PARAMETER; + + railPlugin* rail = (railPlugin*)context->handle; + return rail_send_client_text_scale_order(rail, textScale); +} + +static UINT rail_client_caret_blink_rate(RailClientContext* context, UINT32 rate) +{ + if (!context || !context->handle) + return ERROR_INVALID_PARAMETER; + + railPlugin* rail = (railPlugin*)context->handle; + return rail_send_client_caret_blink_rate_order(rail, rate); +} + +static VOID VCAPITYPE rail_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle, + UINT event, LPVOID pData, + UINT32 dataLength, UINT32 totalLength, + UINT32 dataFlags) +{ + UINT error = CHANNEL_RC_OK; + railPlugin* rail = (railPlugin*)lpUserParam; + + switch (event) + { + case CHANNEL_EVENT_DATA_RECEIVED: + if (!rail || (rail->OpenHandle != openHandle)) + { + WLog_ERR(TAG, "error no match"); + return; + } + + if ((error = channel_client_post_message(rail->MsgsHandle, pData, dataLength, + totalLength, dataFlags))) + { + WLog_ERR(TAG, + "rail_virtual_channel_event_data_received" + " failed with error %" PRIu32 "!", + error); + } + + break; + + case CHANNEL_EVENT_WRITE_CANCELLED: + case CHANNEL_EVENT_WRITE_COMPLETE: + { + wStream* s = (wStream*)pData; + Stream_Free(s, TRUE); + } + break; + + case CHANNEL_EVENT_USER: + break; + default: + break; + } + + if (error && rail && rail->rdpcontext) + setChannelError(rail->rdpcontext, error, + "rail_virtual_channel_open_event reported an error"); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData, UINT32 dataLength) +{ + RailClientContext* context = rail_get_client_interface(rail); + UINT status = CHANNEL_RC_OK; + + WINPR_ASSERT(rail); + + if (context) + { + IFCALLRET(context->OnOpen, status, context, &rail->sendHandshake); + + if (status != CHANNEL_RC_OK) + WLog_ERR(TAG, "context->OnOpen failed with %s [%08" PRIX32 "]", + WTSErrorToString(status), status); + } + rail->MsgsHandle = channel_client_create_handler(rail->rdpcontext, rail, rail_order_recv, + RAIL_SVC_CHANNEL_NAME); + if (!rail->MsgsHandle) + return ERROR_INTERNAL_ERROR; + + return rail->channelEntryPoints.pVirtualChannelOpenEx(rail->InitHandle, &rail->OpenHandle, + rail->channelDef.name, + rail_virtual_channel_open_event_ex); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_virtual_channel_event_disconnected(railPlugin* rail) +{ + UINT rc = 0; + + channel_client_quit_handler(rail->MsgsHandle); + if (rail->OpenHandle == 0) + return CHANNEL_RC_OK; + + WINPR_ASSERT(rail->channelEntryPoints.pVirtualChannelCloseEx); + rc = rail->channelEntryPoints.pVirtualChannelCloseEx(rail->InitHandle, rail->OpenHandle); + + if (CHANNEL_RC_OK != rc) + { + WLog_ERR(TAG, "pVirtualChannelCloseEx failed with %s [%08" PRIX32 "]", WTSErrorToString(rc), + rc); + return rc; + } + + rail->OpenHandle = 0; + + return CHANNEL_RC_OK; +} + +static void rail_virtual_channel_event_terminated(railPlugin* rail) +{ + rail->InitHandle = 0; + free(rail->context); + free(rail); +} + +static VOID VCAPITYPE rail_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle, + UINT event, LPVOID pData, UINT dataLength) +{ + UINT error = CHANNEL_RC_OK; + railPlugin* rail = (railPlugin*)lpUserParam; + + if (!rail || (rail->InitHandle != pInitHandle)) + { + WLog_ERR(TAG, "error no match"); + return; + } + + switch (event) + { + case CHANNEL_EVENT_CONNECTED: + if ((error = rail_virtual_channel_event_connected(rail, pData, dataLength))) + WLog_ERR(TAG, "rail_virtual_channel_event_connected failed with error %" PRIu32 "!", + error); + + break; + + case CHANNEL_EVENT_DISCONNECTED: + if ((error = rail_virtual_channel_event_disconnected(rail))) + WLog_ERR(TAG, + "rail_virtual_channel_event_disconnected failed with error %" PRIu32 "!", + error); + + break; + + case CHANNEL_EVENT_TERMINATED: + rail_virtual_channel_event_terminated(rail); + break; + + case CHANNEL_EVENT_ATTACHED: + case CHANNEL_EVENT_DETACHED: + default: + break; + } + + if (error && rail->rdpcontext) + setChannelError(rail->rdpcontext, error, + "rail_virtual_channel_init_event_ex reported an error"); +} + +/* rail is always built-in */ +#define VirtualChannelEntryEx rail_VirtualChannelEntryEx + +FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, + PVOID pInitHandle)) +{ + UINT rc = 0; + railPlugin* rail = NULL; + RailClientContext* context = NULL; + CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx = NULL; + BOOL isFreerdp = FALSE; + rail = (railPlugin*)calloc(1, sizeof(railPlugin)); + + if (!rail) + { + WLog_ERR(TAG, "calloc failed!"); + return FALSE; + } + + /* Default to automatically replying to server handshakes */ + rail->sendHandshake = TRUE; + rail->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | + CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL; + (void)sprintf_s(rail->channelDef.name, ARRAYSIZE(rail->channelDef.name), RAIL_SVC_CHANNEL_NAME); + pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints; + + if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) && + (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER)) + { + context = (RailClientContext*)calloc(1, sizeof(RailClientContext)); + + if (!context) + { + WLog_ERR(TAG, "calloc failed!"); + free(rail); + return FALSE; + } + + context->handle = (void*)rail; + context->custom = NULL; + context->ClientExecute = rail_client_execute; + context->ClientActivate = rail_client_activate; + context->ClientSystemParam = rail_client_system_param; + context->ClientSystemCommand = rail_client_system_command; + context->ClientHandshake = rail_client_handshake; + context->ClientNotifyEvent = rail_client_notify_event; + context->ClientWindowMove = rail_client_window_move; + context->ClientInformation = rail_client_information; + context->ClientSystemMenu = rail_client_system_menu; + context->ClientLanguageBarInfo = rail_client_language_bar_info; + context->ClientLanguageIMEInfo = rail_client_language_ime_info; + context->ClientGetAppIdRequest = rail_client_get_appid_request; + context->ClientSnapArrange = rail_client_snap_arrange; + context->ClientCloak = rail_client_cloak; + context->ClientCompartmentInfo = rail_client_compartment_info; + context->ClientTextScale = rail_client_text_scale; + context->ClientCaretBlinkRate = rail_client_caret_blink_rate; + rail->rdpcontext = pEntryPointsEx->context; + rail->context = context; + isFreerdp = TRUE; + } + + rail->log = WLog_Get("com.freerdp.channels.rail.client"); + WLog_Print(rail->log, WLOG_DEBUG, "VirtualChannelEntryEx"); + CopyMemory(&(rail->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)); + rail->InitHandle = pInitHandle; + rc = rail->channelEntryPoints.pVirtualChannelInitEx( + rail, context, pInitHandle, &rail->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, + rail_virtual_channel_init_event_ex); + + if (CHANNEL_RC_OK != rc) + { + WLog_ERR(TAG, "failed with %s [%08" PRIX32 "]", WTSErrorToString(rc), rc); + goto error_out; + } + + rail->channelEntryPoints.pInterface = context; + return TRUE; +error_out: + + if (isFreerdp) + free(rail->context); + + free(rail); + return FALSE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_main.h new file mode 100644 index 0000000000000000000000000000000000000000..2cbc6c1559218a3ea8764c17ec6fc397247733f0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_main.h @@ -0,0 +1,60 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RAIL Virtual Channel Plugin + * + * Copyright 2011 Marc-Andre Moreau + * Copyright 2011 Roman Barabanov + * Copyright 2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RAIL_CLIENT_MAIN_H +#define FREERDP_CHANNEL_RAIL_CLIENT_MAIN_H + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "../rail_common.h" + +typedef struct +{ + CHANNEL_DEF channelDef; + CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints; + + RailClientContext* context; + + wLog* log; + void* InitHandle; + DWORD OpenHandle; + void* MsgsHandle; + rdpContext* rdpcontext; + DWORD channelBuildNumber; + DWORD channelFlags; + RAIL_CLIENT_STATUS_ORDER clientStatus; + BOOL sendHandshake; +} railPlugin; + +RailClientContext* rail_get_client_interface(railPlugin* rail); +UINT rail_send_channel_data(railPlugin* rail, wStream* s); + +#endif /* FREERDP_CHANNEL_RAIL_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_orders.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_orders.c new file mode 100644 index 0000000000000000000000000000000000000000..a11623d7fc1eaba6e8af9f3f1661350e7910b536 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_orders.c @@ -0,0 +1,1610 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Applications Integrated Locally (RAIL) Orders + * + * Copyright 2009 Marc-Andre Moreau + * Copyright 2011 Roman Barabanov + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2017 Armin Novak + * Copyright 2017 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include + +#include "rail_orders.h" + +static BOOL rail_is_feature_supported(const rdpContext* context, UINT32 featureMask); + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType) +{ + char buffer[128] = { 0 }; + UINT16 orderLength = 0; + + if (!rail || !s) + { + Stream_Free(s, TRUE); + return ERROR_INVALID_PARAMETER; + } + + orderLength = (UINT16)Stream_GetPosition(s); + Stream_SetPosition(s, 0); + rail_write_pdu_header(s, orderType, orderLength); + Stream_SetPosition(s, orderLength); + WLog_Print(rail->log, WLOG_DEBUG, "Sending %s PDU, length: %" PRIu16 "", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); + return rail_send_channel_data(rail, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* execResult) +{ + if (!s || !execResult) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_EXEC_RESULT_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, execResult->flags); /* flags (2 bytes) */ + Stream_Read_UINT16(s, execResult->execResult); /* execResult (2 bytes) */ + Stream_Read_UINT32(s, execResult->rawResult); /* rawResult (4 bytes) */ + Stream_Seek_UINT16(s); /* padding (2 bytes) */ + return rail_read_unicode_string(s, &execResult->exeOrFile) + ? CHANNEL_RC_OK + : ERROR_INTERNAL_ERROR; /* exeOrFile */ +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo) +{ + if (!s || !minmaxinfo) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_MINMAXINFO_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, minmaxinfo->windowId); /* windowId (4 bytes) */ + Stream_Read_INT16(s, minmaxinfo->maxWidth); /* maxWidth (2 bytes) */ + Stream_Read_INT16(s, minmaxinfo->maxHeight); /* maxHeight (2 bytes) */ + Stream_Read_INT16(s, minmaxinfo->maxPosX); /* maxPosX (2 bytes) */ + Stream_Read_INT16(s, minmaxinfo->maxPosY); /* maxPosY (2 bytes) */ + Stream_Read_INT16(s, minmaxinfo->minTrackWidth); /* minTrackWidth (2 bytes) */ + Stream_Read_INT16(s, minmaxinfo->minTrackHeight); /* minTrackHeight (2 bytes) */ + Stream_Read_INT16(s, minmaxinfo->maxTrackWidth); /* maxTrackWidth (2 bytes) */ + Stream_Read_INT16(s, minmaxinfo->maxTrackHeight); /* maxTrackHeight (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_server_localmovesize_order(wStream* s, + RAIL_LOCALMOVESIZE_ORDER* localMoveSize) +{ + UINT16 isMoveSizeStart = 0; + + if (!s || !localMoveSize) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LOCALMOVESIZE_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, localMoveSize->windowId); /* windowId (4 bytes) */ + Stream_Read_UINT16(s, isMoveSizeStart); /* isMoveSizeStart (2 bytes) */ + localMoveSize->isMoveSizeStart = (isMoveSizeStart != 0) ? TRUE : FALSE; + Stream_Read_UINT16(s, localMoveSize->moveSizeType); /* moveSizeType (2 bytes) */ + Stream_Read_INT16(s, localMoveSize->posX); /* posX (2 bytes) */ + Stream_Read_INT16(s, localMoveSize->posY); /* posY (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_server_get_appid_resp_order(wStream* s, + RAIL_GET_APPID_RESP_ORDER* getAppidResp) +{ + if (!s || !getAppidResp) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_GET_APPID_RESP_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, getAppidResp->windowId); /* windowId (4 bytes) */ + Stream_Read_UTF16_String( + s, getAppidResp->applicationId, + ARRAYSIZE(getAppidResp->applicationId)); /* applicationId (260 UNICODE chars) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo) +{ + if (!s || !langbarInfo) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LANGBAR_INFO_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, langbarInfo->languageBarStatus); /* languageBarStatus (4 bytes) */ + return CHANNEL_RC_OK; +} + +static UINT rail_write_client_status_order(wStream* s, const RAIL_CLIENT_STATUS_ORDER* clientStatus) +{ + if (!s || !clientStatus) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, clientStatus->flags); /* flags (4 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_client_exec_order(wStream* s, UINT16 flags, + const RAIL_UNICODE_STRING* exeOrFile, + const RAIL_UNICODE_STRING* workingDir, + const RAIL_UNICODE_STRING* arguments) +{ + UINT error = 0; + + if (!s || !exeOrFile || !workingDir || !arguments) + return ERROR_INVALID_PARAMETER; + + /* [MS-RDPERP] 2.2.2.3.1 Client Execute PDU (TS_RAIL_ORDER_EXEC) + * Check argument limits */ + if ((exeOrFile->length > 520) || (workingDir->length > 520) || (arguments->length > 16000)) + { + WLog_ERR(TAG, + "TS_RAIL_ORDER_EXEC argument limits exceeded: ExeOrFile=%" PRIu16 + " [max=520], WorkingDir=%" PRIu16 " [max=520], Arguments=%" PRIu16 " [max=16000]", + exeOrFile->length, workingDir->length, arguments->length); + return ERROR_BAD_ARGUMENTS; + } + + Stream_Write_UINT16(s, flags); /* flags (2 bytes) */ + Stream_Write_UINT16(s, exeOrFile->length); /* exeOrFileLength (2 bytes) */ + Stream_Write_UINT16(s, workingDir->length); /* workingDirLength (2 bytes) */ + Stream_Write_UINT16(s, arguments->length); /* argumentsLength (2 bytes) */ + + if ((error = rail_write_unicode_string_value(s, exeOrFile))) + { + WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error); + return error; + } + + if ((error = rail_write_unicode_string_value(s, workingDir))) + { + WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error); + return error; + } + + if ((error = rail_write_unicode_string_value(s, arguments))) + { + WLog_ERR(TAG, "rail_write_unicode_string_value failed with error %" PRIu32 "", error); + return error; + } + + return error; +} + +static UINT rail_write_client_activate_order(wStream* s, const RAIL_ACTIVATE_ORDER* activate) +{ + BYTE enabled = 0; + + if (!s || !activate) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, activate->windowId); /* windowId (4 bytes) */ + enabled = activate->enabled ? 1 : 0; + Stream_Write_UINT8(s, enabled); /* enabled (1 byte) */ + return ERROR_SUCCESS; +} + +static UINT rail_write_client_sysmenu_order(wStream* s, const RAIL_SYSMENU_ORDER* sysmenu) +{ + if (!s || !sysmenu) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, sysmenu->windowId); /* windowId (4 bytes) */ + Stream_Write_INT16(s, sysmenu->left); /* left (2 bytes) */ + Stream_Write_INT16(s, sysmenu->top); /* top (2 bytes) */ + return ERROR_SUCCESS; +} + +static UINT rail_write_client_syscommand_order(wStream* s, const RAIL_SYSCOMMAND_ORDER* syscommand) +{ + if (!s || !syscommand) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, syscommand->windowId); /* windowId (4 bytes) */ + Stream_Write_UINT16(s, syscommand->command); /* command (2 bytes) */ + return ERROR_SUCCESS; +} + +static UINT rail_write_client_notify_event_order(wStream* s, + const RAIL_NOTIFY_EVENT_ORDER* notifyEvent) +{ + if (!s || !notifyEvent) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, notifyEvent->windowId); /* windowId (4 bytes) */ + Stream_Write_UINT32(s, notifyEvent->notifyIconId); /* notifyIconId (4 bytes) */ + Stream_Write_UINT32(s, notifyEvent->message); /* notifyIconId (4 bytes) */ + return ERROR_SUCCESS; +} + +static UINT rail_write_client_window_move_order(wStream* s, + const RAIL_WINDOW_MOVE_ORDER* windowMove) +{ + if (!s || !windowMove) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, windowMove->windowId); /* windowId (4 bytes) */ + Stream_Write_INT16(s, windowMove->left); /* left (2 bytes) */ + Stream_Write_INT16(s, windowMove->top); /* top (2 bytes) */ + Stream_Write_INT16(s, windowMove->right); /* right (2 bytes) */ + Stream_Write_INT16(s, windowMove->bottom); /* bottom (2 bytes) */ + return ERROR_SUCCESS; +} + +static UINT rail_write_client_get_appid_req_order(wStream* s, + const RAIL_GET_APPID_REQ_ORDER* getAppidReq) +{ + if (!s || !getAppidReq) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, getAppidReq->windowId); /* windowId (4 bytes) */ + return ERROR_SUCCESS; +} + +static UINT rail_write_langbar_info_order(wStream* s, const RAIL_LANGBAR_INFO_ORDER* langbarInfo) +{ + if (!s || !langbarInfo) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, langbarInfo->languageBarStatus); /* languageBarStatus (4 bytes) */ + return ERROR_SUCCESS; +} + +static UINT rail_write_languageime_info_order(wStream* s, + const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo) +{ + if (!s || !langImeInfo) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, langImeInfo->ProfileType); + Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(UINT16, langImeInfo->LanguageID)); + Stream_Write(s, &langImeInfo->LanguageProfileCLSID, sizeof(langImeInfo->LanguageProfileCLSID)); + Stream_Write(s, &langImeInfo->ProfileGUID, sizeof(langImeInfo->ProfileGUID)); + Stream_Write_UINT32(s, langImeInfo->KeyboardLayout); + return ERROR_SUCCESS; +} + +static UINT rail_write_compartment_info_order(wStream* s, + const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo) +{ + if (!s || !compartmentInfo) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, compartmentInfo->ImeState); + Stream_Write_UINT32(s, compartmentInfo->ImeConvMode); + Stream_Write_UINT32(s, compartmentInfo->ImeSentenceMode); + Stream_Write_UINT32(s, compartmentInfo->KanaMode); + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_handshake_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_HANDSHAKE_ORDER serverHandshake = { 0 }; + UINT error = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_handshake_order(s, &serverHandshake))) + { + WLog_ERR(TAG, "rail_read_handshake_order failed with error %" PRIu32 "!", error); + return error; + } + + rail->channelBuildNumber = serverHandshake.buildNumber; + + if (rail->sendHandshake) + { + RAIL_HANDSHAKE_ORDER clientHandshake = { 0 }; + clientHandshake.buildNumber = 0x00001DB0; + error = context->ClientHandshake(context, &clientHandshake); + } + + if (error != CHANNEL_RC_OK) + return error; + + if (context->custom) + { + IFCALLRET(context->ServerHandshake, error, context, &serverHandshake); + + if (error) + WLog_ERR(TAG, "context.ServerHandshake failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rail_read_compartment_info_order(wStream* s, + RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_COMPARTMENT_INFO_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, compartmentInfo->ImeState); /* ImeState (4 bytes) */ + Stream_Read_UINT32(s, compartmentInfo->ImeConvMode); /* ImeConvMode (4 bytes) */ + Stream_Read_UINT32(s, compartmentInfo->ImeSentenceMode); /* ImeSentenceMode (4 bytes) */ + Stream_Read_UINT32(s, compartmentInfo->KanaMode); /* KANAMode (4 bytes) */ + return CHANNEL_RC_OK; +} + +static UINT rail_recv_compartmentinfo_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_COMPARTMENT_INFO_ORDER pdu = { 0 }; + UINT error = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED)) + return ERROR_BAD_CONFIGURATION; + + if ((error = rail_read_compartment_info_order(s, &pdu))) + return error; + + if (context->custom) + { + IFCALLRET(context->ClientCompartmentInfo, error, context, &pdu); + + if (error) + WLog_ERR(TAG, "context.ClientCompartmentInfo failed with error %" PRIu32 "", error); + } + + return error; +} + +BOOL rail_is_feature_supported(const rdpContext* context, UINT32 featureMask) +{ + UINT32 supported = 0; + UINT32 masked = 0; + + if (!context || !context->settings) + return FALSE; + + const UINT32 level = + freerdp_settings_get_uint32(context->settings, FreeRDP_RemoteApplicationSupportLevel); + const UINT32 mask = + freerdp_settings_get_uint32(context->settings, FreeRDP_RemoteApplicationSupportMask); + supported = level & mask; + masked = (supported & featureMask); + + if (masked != featureMask) + { + char maskstr[256] = { 0 }; + char actualstr[256] = { 0 }; + + WLog_WARN(TAG, "have %s, require %s", + freerdp_rail_support_flags_to_string(supported, actualstr, sizeof(actualstr)), + freerdp_rail_support_flags_to_string(featureMask, maskstr, sizeof(maskstr))); + return FALSE; + } + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_handshake_ex_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_HANDSHAKE_EX_ORDER serverHandshake = { 0 }; + UINT error = 0; + + if (!rail || !context || !s) + return ERROR_INVALID_PARAMETER; + + if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED)) + return ERROR_BAD_CONFIGURATION; + + if ((error = rail_read_handshake_ex_order(s, &serverHandshake))) + { + WLog_ERR(TAG, "rail_read_handshake_ex_order failed with error %" PRIu32 "!", error); + return error; + } + + rail->channelBuildNumber = serverHandshake.buildNumber; + rail->channelFlags = serverHandshake.railHandshakeFlags; + + { + char buffer[192] = { 0 }; + WLog_DBG(TAG, "HandshakeFlags=%s [buildNumber=0x%08" PRIx32 "]", + rail_handshake_ex_flags_to_string(rail->channelFlags, buffer, sizeof(buffer)), + rail->channelBuildNumber); + } + + if (rail->sendHandshake) + { + RAIL_HANDSHAKE_ORDER clientHandshake = { 0 }; + clientHandshake.buildNumber = 0x00001DB0; + /* 2.2.2.2.3 HandshakeEx PDU (TS_RAIL_ORDER_HANDSHAKE_EX) + * Client response is really a Handshake PDU */ + error = context->ClientHandshake(context, &clientHandshake); + } + + if (error != CHANNEL_RC_OK) + return error; + + if (context->custom) + { + IFCALLRET(context->ServerHandshakeEx, error, context, &serverHandshake); + + if (error) + WLog_ERR(TAG, "context.ServerHandshakeEx failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_exec_result_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_EXEC_RESULT_ORDER execResult = { 0 }; + UINT error = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_server_exec_result_order(s, &execResult))) + { + WLog_ERR(TAG, "rail_read_server_exec_result_order failed with error %" PRIu32 "!", error); + goto fail; + } + + if (context->custom) + { + IFCALLRET(context->ServerExecuteResult, error, context, &execResult); + + if (error) + WLog_ERR(TAG, "context.ServerExecuteResult failed with error %" PRIu32 "", error); + } + +fail: + free(execResult.exeOrFile.string); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_server_sysparam_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_SYSPARAM_ORDER sysparam; + UINT error = 0; + BOOL extendedSpiSupported = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + extendedSpiSupported = rail_is_extended_spi_supported(rail->channelFlags); + if ((error = rail_read_sysparam_order(s, &sysparam, extendedSpiSupported))) + { + WLog_ERR(TAG, "rail_read_sysparam_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerSystemParam, error, context, &sysparam); + + if (error) + WLog_ERR(TAG, "context.ServerSystemParam failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_server_minmaxinfo_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_MINMAXINFO_ORDER minMaxInfo = { 0 }; + UINT error = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_server_minmaxinfo_order(s, &minMaxInfo))) + { + WLog_ERR(TAG, "rail_read_server_minmaxinfo_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerMinMaxInfo, error, context, &minMaxInfo); + + if (error) + WLog_ERR(TAG, "context.ServerMinMaxInfo failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_server_localmovesize_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_LOCALMOVESIZE_ORDER localMoveSize = { 0 }; + UINT error = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_server_localmovesize_order(s, &localMoveSize))) + { + WLog_ERR(TAG, "rail_read_server_localmovesize_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerLocalMoveSize, error, context, &localMoveSize); + + if (error) + WLog_ERR(TAG, "context.ServerLocalMoveSize failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_server_get_appid_resp_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_GET_APPID_RESP_ORDER getAppIdResp = { 0 }; + UINT error = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_server_get_appid_resp_order(s, &getAppIdResp))) + { + WLog_ERR(TAG, "rail_read_server_get_appid_resp_order failed with error %" PRIu32 "!", + error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerGetAppIdResponse, error, context, &getAppIdResp); + + if (error) + WLog_ERR(TAG, "context.ServerGetAppIdResponse failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_langbar_info_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_LANGBAR_INFO_ORDER langBarInfo = { 0 }; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + + if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED)) + return ERROR_BAD_CONFIGURATION; + + if ((error = rail_read_langbar_info_order(s, &langBarInfo))) + { + WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerLanguageBarInfo, error, context, &langBarInfo); + + if (error) + WLog_ERR(TAG, "context.ServerLanguageBarInfo failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rail_read_taskbar_info_order(wStream* s, RAIL_TASKBAR_INFO_ORDER* taskbarInfo) +{ + if (!s || !taskbarInfo) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_TASKBAR_INFO_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, taskbarInfo->TaskbarMessage); + Stream_Read_UINT32(s, taskbarInfo->WindowIdTab); + Stream_Read_UINT32(s, taskbarInfo->Body); + return CHANNEL_RC_OK; +} + +static UINT rail_recv_taskbar_info_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_TASKBAR_INFO_ORDER taskBarInfo = { 0 }; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + + /* 2.2.2.14.1 Taskbar Tab Info PDU (TS_RAIL_ORDER_TASKBARINFO) + * server -> client message only supported if announced. */ + if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED)) + return ERROR_BAD_CONFIGURATION; + + if ((error = rail_read_taskbar_info_order(s, &taskBarInfo))) + { + WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerTaskBarInfo, error, context, &taskBarInfo); + + if (error) + WLog_ERR(TAG, "context.ServerTaskBarInfo failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rail_read_zorder_sync_order(wStream* s, RAIL_ZORDER_SYNC* zorder) +{ + if (!s || !zorder) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_Z_ORDER_SYNC_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, zorder->windowIdMarker); + return CHANNEL_RC_OK; +} + +static UINT rail_recv_zorder_sync_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_ZORDER_SYNC zorder = { 0 }; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + + if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_ZORDER_SYNC) == 0) + return ERROR_INVALID_DATA; + + if ((error = rail_read_zorder_sync_order(s, &zorder))) + { + WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerZOrderSync, error, context, &zorder); + + if (error) + WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rail_read_cloak_order(wStream* s, RAIL_CLOAK* cloak) +{ + BYTE cloaked = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_CLOAK_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, cloak->windowId); /* WindowId (4 bytes) */ + Stream_Read_UINT8(s, cloaked); /* Cloaked (1 byte) */ + cloak->cloak = (cloaked != 0) ? TRUE : FALSE; + return CHANNEL_RC_OK; +} + +static UINT rail_recv_cloak_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_CLOAK cloak = { 0 }; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + + /* 2.2.2.12.1 Window Cloak State Change PDU (TS_RAIL_ORDER_CLOAK) + * server -> client message only supported if announced. */ + if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED) == 0) + return ERROR_INVALID_DATA; + + if ((error = rail_read_cloak_order(s, &cloak))) + { + WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerCloak, error, context, &cloak); + + if (error) + WLog_ERR(TAG, "context.ServerZOrderSync failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rail_read_power_display_request_order(wStream* s, RAIL_POWER_DISPLAY_REQUEST* power) +{ + UINT32 active = 0; + + if (!s || !power) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_POWER_DISPLAY_REQUEST_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, active); + power->active = active != 0; + return CHANNEL_RC_OK; +} + +static UINT rail_recv_power_display_request_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_POWER_DISPLAY_REQUEST power = { 0 }; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + + /* 2.2.2.13.1 Power Display Request PDU(TS_RAIL_ORDER_POWER_DISPLAY_REQUEST) + */ + if ((rail->clientStatus.flags & TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED) == 0) + return ERROR_INVALID_DATA; + + if ((error = rail_read_power_display_request_order(s, &power))) + { + WLog_ERR(TAG, "rail_read_zorder_sync_order failed with error %" PRIu32 "!", error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerPowerDisplayRequest, error, context, &power); + + if (error) + WLog_ERR(TAG, "context.ServerPowerDisplayRequest failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rail_read_get_application_id_extended_response_order(wStream* s, + RAIL_GET_APPID_RESP_EX* id) +{ + if (!s || !id) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, id->windowID); + + if (!Stream_Read_UTF16_String(s, id->applicationID, ARRAYSIZE(id->applicationID))) + return ERROR_INVALID_DATA; + + if (_wcsnlen(id->applicationID, ARRAYSIZE(id->applicationID)) >= ARRAYSIZE(id->applicationID)) + return ERROR_INVALID_DATA; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, id->processId); + + if (!Stream_Read_UTF16_String(s, id->processImageName, ARRAYSIZE(id->processImageName))) + return ERROR_INVALID_DATA; + + if (_wcsnlen(id->applicationID, ARRAYSIZE(id->processImageName)) >= + ARRAYSIZE(id->processImageName)) + return ERROR_INVALID_DATA; + + return CHANNEL_RC_OK; +} + +static UINT rail_recv_get_application_id_extended_response_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + RAIL_GET_APPID_RESP_EX id = { 0 }; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_get_application_id_extended_response_order(s, &id))) + { + WLog_ERR(TAG, + "rail_read_get_application_id_extended_response_order failed with error %" PRIu32 + "!", + error); + return error; + } + + if (context->custom) + { + IFCALLRET(context->ServerGetAppidResponseExtended, error, context, &id); + + if (error) + WLog_ERR(TAG, "context.ServerGetAppidResponseExtended failed with error %" PRIu32 "", + error); + } + + return error; +} + +static UINT rail_read_textscaleinfo_order(wStream* s, UINT32* pTextScaleFactor) +{ + WINPR_ASSERT(pTextScaleFactor); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, *pTextScaleFactor); + return CHANNEL_RC_OK; +} + +static UINT rail_recv_textscaleinfo_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + UINT32 TextScaleFactor = 0; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_textscaleinfo_order(s, &TextScaleFactor))) + return error; + + if (context->custom) + { + IFCALLRET(context->ClientTextScale, error, context, TextScaleFactor); + + if (error) + WLog_ERR(TAG, "context.ClientTextScale failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rail_read_caretblinkinfo_order(wStream* s, UINT32* pCaretBlinkRate) +{ + WINPR_ASSERT(pCaretBlinkRate); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, *pCaretBlinkRate); + return CHANNEL_RC_OK; +} + +static UINT rail_recv_caretblinkinfo_order(railPlugin* rail, wStream* s) +{ + RailClientContext* context = rail_get_client_interface(rail); + UINT32 CaretBlinkRate = 0; + UINT error = 0; + + if (!context) + return ERROR_INVALID_PARAMETER; + if ((error = rail_read_caretblinkinfo_order(s, &CaretBlinkRate))) + return error; + + if (context->custom) + { + IFCALLRET(context->ClientCaretBlinkRate, error, context, CaretBlinkRate); + + if (error) + WLog_ERR(TAG, "context.ClientCaretBlinkRate failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_order_recv(LPVOID userdata, wStream* s) +{ + char buffer[128] = { 0 }; + railPlugin* rail = userdata; + UINT16 orderType = 0; + UINT16 orderLength = 0; + UINT error = CHANNEL_RC_OK; + + if (!rail || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_pdu_header(s, &orderType, &orderLength))) + { + WLog_ERR(TAG, "rail_read_pdu_header failed with error %" PRIu32 "!", error); + return error; + } + + WLog_Print(rail->log, WLOG_DEBUG, "Received %s PDU, length:%" PRIu16 "", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); + + switch (orderType) + { + case TS_RAIL_ORDER_HANDSHAKE: + error = rail_recv_handshake_order(rail, s); + break; + + case TS_RAIL_ORDER_COMPARTMENTINFO: + error = rail_recv_compartmentinfo_order(rail, s); + break; + + case TS_RAIL_ORDER_HANDSHAKE_EX: + error = rail_recv_handshake_ex_order(rail, s); + break; + + case TS_RAIL_ORDER_EXEC_RESULT: + error = rail_recv_exec_result_order(rail, s); + break; + + case TS_RAIL_ORDER_SYSPARAM: + error = rail_recv_server_sysparam_order(rail, s); + break; + + case TS_RAIL_ORDER_MINMAXINFO: + error = rail_recv_server_minmaxinfo_order(rail, s); + break; + + case TS_RAIL_ORDER_LOCALMOVESIZE: + error = rail_recv_server_localmovesize_order(rail, s); + break; + + case TS_RAIL_ORDER_GET_APPID_RESP: + error = rail_recv_server_get_appid_resp_order(rail, s); + break; + + case TS_RAIL_ORDER_LANGBARINFO: + error = rail_recv_langbar_info_order(rail, s); + break; + + case TS_RAIL_ORDER_TASKBARINFO: + error = rail_recv_taskbar_info_order(rail, s); + break; + + case TS_RAIL_ORDER_ZORDER_SYNC: + error = rail_recv_zorder_sync_order(rail, s); + break; + + case TS_RAIL_ORDER_CLOAK: + error = rail_recv_cloak_order(rail, s); + break; + + case TS_RAIL_ORDER_POWER_DISPLAY_REQUEST: + error = rail_recv_power_display_request_order(rail, s); + break; + + case TS_RAIL_ORDER_GET_APPID_RESP_EX: + error = rail_recv_get_application_id_extended_response_order(rail, s); + break; + + case TS_RAIL_ORDER_TEXTSCALEINFO: + error = rail_recv_textscaleinfo_order(rail, s); + break; + + case TS_RAIL_ORDER_CARETBLINKINFO: + error = rail_recv_caretblinkinfo_order(rail, s); + break; + + default: + WLog_ERR(TAG, "Unknown RAIL PDU %s received.", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer))); + return ERROR_INVALID_DATA; + } + + if (error != CHANNEL_RC_OK) + { + char ebuffer[128] = { 0 }; + WLog_Print(rail->log, WLOG_ERROR, "Failed to process rail %s PDU, length:%" PRIu16 "", + rail_get_order_type_string_full(orderType, ebuffer, sizeof(ebuffer)), + orderLength); + } + + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_handshake_order(railPlugin* rail, const RAIL_HANDSHAKE_ORDER* handshake) +{ + if (!rail || !handshake) + return ERROR_INVALID_PARAMETER; + + wStream* s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_handshake_order(s, handshake); + return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_handshake_ex_order(railPlugin* rail, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx) +{ + if (!rail || !handshakeEx) + return ERROR_INVALID_PARAMETER; + + wStream* s = rail_pdu_init(RAIL_HANDSHAKE_EX_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_handshake_ex_order(s, handshakeEx); + return rail_send_pdu(rail, s, TS_RAIL_ORDER_HANDSHAKE_EX); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_status_order(railPlugin* rail, const RAIL_CLIENT_STATUS_ORDER* clientStatus) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !clientStatus) + return ERROR_INVALID_PARAMETER; + + rail->clientStatus = *clientStatus; + s = rail_pdu_init(RAIL_CLIENT_STATUS_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_client_status_order(s, clientStatus); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLIENTSTATUS); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_exec_order(railPlugin* rail, UINT16 flags, + const RAIL_UNICODE_STRING* exeOrFile, + const RAIL_UNICODE_STRING* workingDir, + const RAIL_UNICODE_STRING* arguments) +{ + wStream* s = NULL; + UINT error = 0; + size_t length = 0; + + if (!rail || !exeOrFile || !workingDir || !arguments) + return ERROR_INVALID_PARAMETER; + + length = RAIL_EXEC_ORDER_LENGTH + exeOrFile->length + workingDir->length + arguments->length; + s = rail_pdu_init(length); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if ((error = rail_write_client_exec_order(s, flags, exeOrFile, workingDir, arguments))) + { + WLog_ERR(TAG, "rail_write_client_exec_order failed with error %" PRIu32 "!", error); + goto out; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_EXEC); + +out: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_activate_order(railPlugin* rail, const RAIL_ACTIVATE_ORDER* activate) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !activate) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_ACTIVATE_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_client_activate_order(s, activate); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_ACTIVATE); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_sysmenu_order(railPlugin* rail, const RAIL_SYSMENU_ORDER* sysmenu) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !sysmenu) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_SYSMENU_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_client_sysmenu_order(s, sysmenu); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSMENU); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_syscommand_order(railPlugin* rail, const RAIL_SYSCOMMAND_ORDER* syscommand) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !syscommand) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_SYSCOMMAND_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_client_syscommand_order(s, syscommand); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_SYSCOMMAND); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_notify_event_order(railPlugin* rail, + const RAIL_NOTIFY_EVENT_ORDER* notifyEvent) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !notifyEvent) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_NOTIFY_EVENT_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_client_notify_event_order(s, notifyEvent); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_NOTIFY_EVENT); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_window_move_order(railPlugin* rail, const RAIL_WINDOW_MOVE_ORDER* windowMove) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !windowMove) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_WINDOW_MOVE_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_client_window_move_order(s, windowMove); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + + return rail_send_pdu(rail, s, TS_RAIL_ORDER_WINDOWMOVE); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_get_appid_req_order(railPlugin* rail, + const RAIL_GET_APPID_REQ_ORDER* getAppIdReq) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !getAppIdReq) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_GET_APPID_REQ_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_client_get_appid_req_order(s, getAppIdReq); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + return rail_send_pdu(rail, s, TS_RAIL_ORDER_GET_APPID_REQ); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_send_client_langbar_info_order(railPlugin* rail, + const RAIL_LANGBAR_INFO_ORDER* langBarInfo) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !langBarInfo) + return ERROR_INVALID_PARAMETER; + + if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED)) + return ERROR_BAD_CONFIGURATION; + + s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_langbar_info_order(s, langBarInfo); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGBARINFO); +} + +UINT rail_send_client_languageime_info_order(railPlugin* rail, + const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !langImeInfo) + return ERROR_INVALID_PARAMETER; + + if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED)) + return ERROR_BAD_CONFIGURATION; + + s = rail_pdu_init(RAIL_LANGUAGEIME_INFO_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_languageime_info_order(s, langImeInfo); + + if (ERROR_SUCCESS != error) + { + + Stream_Free(s, TRUE); + return error; + } + return rail_send_pdu(rail, s, TS_RAIL_ORDER_LANGUAGEIMEINFO); +} + +UINT rail_send_client_compartment_info_order(railPlugin* rail, + const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo) +{ + wStream* s = NULL; + UINT error = 0; + + if (!rail || !compartmentInfo) + return ERROR_INVALID_PARAMETER; + + if (!rail_is_feature_supported(rail->rdpcontext, RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED)) + return ERROR_BAD_CONFIGURATION; + + s = rail_pdu_init(RAIL_COMPARTMENT_INFO_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rail_write_compartment_info_order(s, compartmentInfo); + + if (ERROR_SUCCESS != error) + { + Stream_Free(s, TRUE); + return error; + } + return rail_send_pdu(rail, s, TS_RAIL_ORDER_COMPARTMENTINFO); +} + +UINT rail_send_client_cloak_order(railPlugin* rail, const RAIL_CLOAK* cloak) +{ + if (!rail || !cloak) + return ERROR_INVALID_PARAMETER; + + wStream* s = rail_pdu_init(5); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, cloak->windowId); + Stream_Write_UINT8(s, cloak->cloak ? 1 : 0); + return rail_send_pdu(rail, s, TS_RAIL_ORDER_CLOAK); +} + +UINT rail_send_client_snap_arrange_order(railPlugin* rail, const RAIL_SNAP_ARRANGE* snap) +{ + if (!rail) + return ERROR_INVALID_PARAMETER; + + /* 2.2.2.7.5 Client Window Snap PDU (TS_RAIL_ORDER_SNAP_ARRANGE) */ + if ((rail->channelFlags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_SNAP_ARRANGE_SUPPORTED) == 0) + { + RAIL_WINDOW_MOVE_ORDER move = { 0 }; + move.top = snap->top; + move.left = snap->left; + move.right = snap->right; + move.bottom = snap->bottom; + move.windowId = snap->windowId; + return rail_send_client_window_move_order(rail, &move); + } + + wStream* s = rail_pdu_init(12); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, snap->windowId); + Stream_Write_INT16(s, snap->left); + Stream_Write_INT16(s, snap->top); + Stream_Write_INT16(s, snap->right); + Stream_Write_INT16(s, snap->bottom); + return rail_send_pdu(rail, s, TS_RAIL_ORDER_SNAP_ARRANGE); +} + +UINT rail_send_client_text_scale_order(railPlugin* rail, UINT32 textScale) +{ + if (!rail) + return ERROR_INVALID_PARAMETER; + + wStream* s = rail_pdu_init(4); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, textScale); + return rail_send_pdu(rail, s, TS_RAIL_ORDER_TEXTSCALEINFO); +} + +UINT rail_send_client_caret_blink_rate_order(railPlugin* rail, UINT32 rate) +{ + if (!rail) + return ERROR_INVALID_PARAMETER; + + wStream* s = rail_pdu_init(4); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, rate); + return rail_send_pdu(rail, s, TS_RAIL_ORDER_CARETBLINKINFO); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_orders.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_orders.h new file mode 100644 index 0000000000000000000000000000000000000000..6817fa1d5dadd6034107e9e33e2531a2d33b14c7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/client/rail_orders.h @@ -0,0 +1,62 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Applications Integrated Locally (RAIL) + * + * Copyright 2009 Marc-Andre Moreau + * Copyright 2011 Roman Barabanov + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RAIL_CLIENT_ORDERS_H +#define FREERDP_CHANNEL_RAIL_CLIENT_ORDERS_H + +#include + +#include "rail_main.h" + +#define TAG CHANNELS_TAG("rail.client") + +UINT rail_order_recv(LPVOID userdata, wStream* s); +UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType); + +UINT rail_send_handshake_order(railPlugin* rail, const RAIL_HANDSHAKE_ORDER* handshake); +UINT rail_send_handshake_ex_order(railPlugin* rail, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx); +UINT rail_send_client_status_order(railPlugin* rail, const RAIL_CLIENT_STATUS_ORDER* clientStatus); +UINT rail_send_client_exec_order(railPlugin* rail, UINT16 flags, + const RAIL_UNICODE_STRING* exeOrFile, + const RAIL_UNICODE_STRING* workingDir, + const RAIL_UNICODE_STRING* arguments); +UINT rail_send_client_activate_order(railPlugin* rail, const RAIL_ACTIVATE_ORDER* activate); +UINT rail_send_client_sysmenu_order(railPlugin* rail, const RAIL_SYSMENU_ORDER* sysmenu); +UINT rail_send_client_syscommand_order(railPlugin* rail, const RAIL_SYSCOMMAND_ORDER* syscommand); + +UINT rail_send_client_notify_event_order(railPlugin* rail, + const RAIL_NOTIFY_EVENT_ORDER* notifyEvent); +UINT rail_send_client_window_move_order(railPlugin* rail, const RAIL_WINDOW_MOVE_ORDER* windowMove); +UINT rail_send_client_get_appid_req_order(railPlugin* rail, + const RAIL_GET_APPID_REQ_ORDER* getAppIdReq); +UINT rail_send_client_langbar_info_order(railPlugin* rail, + const RAIL_LANGBAR_INFO_ORDER* langBarInfo); +UINT rail_send_client_languageime_info_order(railPlugin* rail, + const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo); +UINT rail_send_client_cloak_order(railPlugin* rail, const RAIL_CLOAK* cloak); +UINT rail_send_client_snap_arrange_order(railPlugin* rail, const RAIL_SNAP_ARRANGE* snap); +UINT rail_send_client_compartment_info_order(railPlugin* rail, + const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo); +UINT rail_send_client_text_scale_order(railPlugin* rail, UINT32 textScale); +UINT rail_send_client_caret_blink_rate_order(railPlugin* rail, UINT32 rate); + +#endif /* FREERDP_CHANNEL_RAIL_CLIENT_ORDERS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/rail_common.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/rail_common.c new file mode 100644 index 0000000000000000000000000000000000000000..f80b6ed70900c54118ffa415e0ec6cff0e96aa66 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/rail_common.c @@ -0,0 +1,618 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RAIL common functions + * + * Copyright 2011 Marc-Andre Moreau + * Copyright 2011 Roman Barabanov + * Copyright 2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "rail_common.h" + +#include +#include + +#define TAG CHANNELS_TAG("rail.common") + +const char* rail_get_order_type_string(UINT16 orderType) +{ + switch (orderType) + { + case TS_RAIL_ORDER_EXEC: + return "TS_RAIL_ORDER_EXEC"; + case TS_RAIL_ORDER_ACTIVATE: + return "TS_RAIL_ORDER_ACTIVATE"; + case TS_RAIL_ORDER_SYSPARAM: + return "TS_RAIL_ORDER_SYSPARAM"; + case TS_RAIL_ORDER_SYSCOMMAND: + return "TS_RAIL_ORDER_SYSCOMMAND"; + case TS_RAIL_ORDER_HANDSHAKE: + return "TS_RAIL_ORDER_HANDSHAKE"; + case TS_RAIL_ORDER_NOTIFY_EVENT: + return "TS_RAIL_ORDER_NOTIFY_EVENT"; + case TS_RAIL_ORDER_WINDOWMOVE: + return "TS_RAIL_ORDER_WINDOWMOVE"; + case TS_RAIL_ORDER_LOCALMOVESIZE: + return "TS_RAIL_ORDER_LOCALMOVESIZE"; + case TS_RAIL_ORDER_MINMAXINFO: + return "TS_RAIL_ORDER_MINMAXINFO"; + case TS_RAIL_ORDER_CLIENTSTATUS: + return "TS_RAIL_ORDER_CLIENTSTATUS"; + case TS_RAIL_ORDER_SYSMENU: + return "TS_RAIL_ORDER_SYSMENU"; + case TS_RAIL_ORDER_LANGBARINFO: + return "TS_RAIL_ORDER_LANGBARINFO"; + case TS_RAIL_ORDER_GET_APPID_REQ: + return "TS_RAIL_ORDER_GET_APPID_REQ"; + case TS_RAIL_ORDER_GET_APPID_RESP: + return "TS_RAIL_ORDER_GET_APPID_RESP"; + case TS_RAIL_ORDER_TASKBARINFO: + return "TS_RAIL_ORDER_TASKBARINFO"; + case TS_RAIL_ORDER_LANGUAGEIMEINFO: + return "TS_RAIL_ORDER_LANGUAGEIMEINFO"; + case TS_RAIL_ORDER_COMPARTMENTINFO: + return "TS_RAIL_ORDER_COMPARTMENTINFO"; + case TS_RAIL_ORDER_HANDSHAKE_EX: + return "TS_RAIL_ORDER_HANDSHAKE_EX"; + case TS_RAIL_ORDER_ZORDER_SYNC: + return "TS_RAIL_ORDER_ZORDER_SYNC"; + case TS_RAIL_ORDER_CLOAK: + return "TS_RAIL_ORDER_CLOAK"; + case TS_RAIL_ORDER_POWER_DISPLAY_REQUEST: + return "TS_RAIL_ORDER_POWER_DISPLAY_REQUEST"; + case TS_RAIL_ORDER_SNAP_ARRANGE: + return "TS_RAIL_ORDER_SNAP_ARRANGE"; + case TS_RAIL_ORDER_GET_APPID_RESP_EX: + return "TS_RAIL_ORDER_GET_APPID_RESP_EX"; + case TS_RAIL_ORDER_EXEC_RESULT: + return "TS_RAIL_ORDER_EXEC_RESULT"; + case TS_RAIL_ORDER_TEXTSCALEINFO: + return "TS_RAIL_ORDER_TEXTSCALEINFO"; + case TS_RAIL_ORDER_CARETBLINKINFO: + return "TS_RAIL_ORDER_CARETBLINKINFO"; + default: + return "TS_RAIL_ORDER_UNKNOWN"; + } +} + +const char* rail_get_order_type_string_full(UINT16 orderType, char* buffer, size_t length) +{ + (void)_snprintf(buffer, length, "%s[0x%04" PRIx16 "]", rail_get_order_type_string(orderType), + orderType); + return buffer; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_read_pdu_header(wStream* s, UINT16* orderType, UINT16* orderLength) +{ + if (!s || !orderType || !orderLength) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, *orderType); /* orderType (2 bytes) */ + Stream_Read_UINT16(s, *orderLength); /* orderLength (2 bytes) */ + return CHANNEL_RC_OK; +} + +void rail_write_pdu_header(wStream* s, UINT16 orderType, UINT16 orderLength) +{ + Stream_Write_UINT16(s, orderType); /* orderType (2 bytes) */ + Stream_Write_UINT16(s, orderLength); /* orderLength (2 bytes) */ +} + +wStream* rail_pdu_init(size_t length) +{ + wStream* s = Stream_New(NULL, length + RAIL_PDU_HEADER_LENGTH); + + if (!s) + return NULL; + + Stream_Seek(s, RAIL_PDU_HEADER_LENGTH); + return s; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_read_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, handshake->buildNumber); /* buildNumber (4 bytes) */ + return CHANNEL_RC_OK; +} + +void rail_write_handshake_order(wStream* s, const RAIL_HANDSHAKE_ORDER* handshake) +{ + Stream_Write_UINT32(s, handshake->buildNumber); /* buildNumber (4 bytes) */ +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_read_handshake_ex_order(wStream* s, RAIL_HANDSHAKE_EX_ORDER* handshakeEx) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, handshakeEx->buildNumber); /* buildNumber (4 bytes) */ + Stream_Read_UINT32(s, handshakeEx->railHandshakeFlags); /* railHandshakeFlags (4 bytes) */ + return CHANNEL_RC_OK; +} + +void rail_write_handshake_ex_order(wStream* s, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx) +{ + Stream_Write_UINT32(s, handshakeEx->buildNumber); /* buildNumber (4 bytes) */ + Stream_Write_UINT32(s, handshakeEx->railHandshakeFlags); /* railHandshakeFlags (4 bytes) */ +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_write_unicode_string(wStream* s, const RAIL_UNICODE_STRING* unicode_string) +{ + if (!s || !unicode_string) + return ERROR_INVALID_PARAMETER; + + if (!Stream_EnsureRemainingCapacity(s, 2 + unicode_string->length)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, unicode_string->length); /* cbString (2 bytes) */ + Stream_Write(s, unicode_string->string, unicode_string->length); /* string */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_write_unicode_string_value(wStream* s, const RAIL_UNICODE_STRING* unicode_string) +{ + size_t length = 0; + + if (!s || !unicode_string) + return ERROR_INVALID_PARAMETER; + + length = unicode_string->length; + + if (length > 0) + { + if (!Stream_EnsureRemainingCapacity(s, length)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write(s, unicode_string->string, length); /* string */ + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_high_contrast(wStream* s, RAIL_HIGH_CONTRAST* highContrast) +{ + if (!s || !highContrast) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, highContrast->flags); /* flags (4 bytes) */ + Stream_Read_UINT32(s, highContrast->colorSchemeLength); /* colorSchemeLength (4 bytes) */ + + if (!rail_read_unicode_string(s, &highContrast->colorScheme)) /* colorScheme */ + return ERROR_INTERNAL_ERROR; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_high_contrast(wStream* s, const RAIL_HIGH_CONTRAST* highContrast) +{ + UINT32 colorSchemeLength = 0; + + if (!s || !highContrast) + return ERROR_INVALID_PARAMETER; + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return CHANNEL_RC_NO_MEMORY; + + colorSchemeLength = highContrast->colorScheme.length + 2; + Stream_Write_UINT32(s, highContrast->flags); /* flags (4 bytes) */ + Stream_Write_UINT32(s, colorSchemeLength); /* colorSchemeLength (4 bytes) */ + return rail_write_unicode_string(s, &highContrast->colorScheme); /* colorScheme */ +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_filterkeys(wStream* s, TS_FILTERKEYS* filterKeys) +{ + if (!s || !filterKeys) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 20)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, filterKeys->Flags); + Stream_Read_UINT32(s, filterKeys->WaitTime); + Stream_Read_UINT32(s, filterKeys->DelayTime); + Stream_Read_UINT32(s, filterKeys->RepeatTime); + Stream_Read_UINT32(s, filterKeys->BounceTime); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_filterkeys(wStream* s, const TS_FILTERKEYS* filterKeys) +{ + if (!s || !filterKeys) + return ERROR_INVALID_PARAMETER; + + if (!Stream_EnsureRemainingCapacity(s, 20)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write_UINT32(s, filterKeys->Flags); + Stream_Write_UINT32(s, filterKeys->WaitTime); + Stream_Write_UINT32(s, filterKeys->DelayTime); + Stream_Write_UINT32(s, filterKeys->RepeatTime); + Stream_Write_UINT32(s, filterKeys->BounceTime); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rail_read_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam, BOOL extendedSpiSupported) +{ + BYTE body = 0; + UINT error = CHANNEL_RC_OK; + + if (!s || !sysparam) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 5)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, sysparam->param); /* systemParam (4 bytes) */ + + sysparam->params = 0; /* bitflags of received params */ + + switch (sysparam->param) + { + /* Client sysparams */ + case SPI_SET_DRAG_FULL_WINDOWS: + sysparam->params |= SPI_MASK_SET_DRAG_FULL_WINDOWS; + Stream_Read_UINT8(s, body); /* body (1 byte) */ + sysparam->dragFullWindows = body != 0; + break; + + case SPI_SET_KEYBOARD_CUES: + sysparam->params |= SPI_MASK_SET_KEYBOARD_CUES; + Stream_Read_UINT8(s, body); /* body (1 byte) */ + sysparam->keyboardCues = body != 0; + break; + + case SPI_SET_KEYBOARD_PREF: + sysparam->params |= SPI_MASK_SET_KEYBOARD_PREF; + Stream_Read_UINT8(s, body); /* body (1 byte) */ + sysparam->keyboardPref = body != 0; + break; + + case SPI_SET_MOUSE_BUTTON_SWAP: + sysparam->params |= SPI_MASK_SET_MOUSE_BUTTON_SWAP; + Stream_Read_UINT8(s, body); /* body (1 byte) */ + sysparam->mouseButtonSwap = body != 0; + break; + + case SPI_SET_WORK_AREA: + sysparam->params |= SPI_MASK_SET_WORK_AREA; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, sysparam->workArea.left); /* left (2 bytes) */ + Stream_Read_UINT16(s, sysparam->workArea.top); /* top (2 bytes) */ + Stream_Read_UINT16(s, sysparam->workArea.right); /* right (2 bytes) */ + Stream_Read_UINT16(s, sysparam->workArea.bottom); /* bottom (2 bytes) */ + break; + + case SPI_DISPLAY_CHANGE: + sysparam->params |= SPI_MASK_DISPLAY_CHANGE; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, sysparam->displayChange.left); /* left (2 bytes) */ + Stream_Read_UINT16(s, sysparam->displayChange.top); /* top (2 bytes) */ + Stream_Read_UINT16(s, sysparam->displayChange.right); /* right (2 bytes) */ + Stream_Read_UINT16(s, sysparam->displayChange.bottom); /* bottom (2 bytes) */ + break; + + case SPI_TASKBAR_POS: + sysparam->params |= SPI_MASK_TASKBAR_POS; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, sysparam->taskbarPos.left); /* left (2 bytes) */ + Stream_Read_UINT16(s, sysparam->taskbarPos.top); /* top (2 bytes) */ + Stream_Read_UINT16(s, sysparam->taskbarPos.right); /* right (2 bytes) */ + Stream_Read_UINT16(s, sysparam->taskbarPos.bottom); /* bottom (2 bytes) */ + break; + + case SPI_SET_HIGH_CONTRAST: + sysparam->params |= SPI_MASK_SET_HIGH_CONTRAST; + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + error = rail_read_high_contrast(s, &sysparam->highContrast); + break; + + case SPI_SETCARETWIDTH: + sysparam->params |= SPI_MASK_SET_CARET_WIDTH; + + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, sysparam->caretWidth); + + if (sysparam->caretWidth < 0x0001) + return ERROR_INVALID_DATA; + + break; + + case SPI_SETSTICKYKEYS: + sysparam->params |= SPI_MASK_SET_STICKY_KEYS; + + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, sysparam->stickyKeys); + break; + + case SPI_SETTOGGLEKEYS: + sysparam->params |= SPI_MASK_SET_TOGGLE_KEYS; + + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, sysparam->toggleKeys); + break; + + case SPI_SETFILTERKEYS: + sysparam->params |= SPI_MASK_SET_FILTER_KEYS; + + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 20)) + return ERROR_INVALID_DATA; + + error = rail_read_filterkeys(s, &sysparam->filterKeys); + break; + + /* Server sysparams */ + case SPI_SETSCREENSAVEACTIVE: + sysparam->params |= SPI_MASK_SET_SCREEN_SAVE_ACTIVE; + + Stream_Read_UINT8(s, body); /* body (1 byte) */ + sysparam->setScreenSaveActive = body != 0; + break; + + case SPI_SETSCREENSAVESECURE: + sysparam->params |= SPI_MASK_SET_SET_SCREEN_SAVE_SECURE; + + Stream_Read_UINT8(s, body); /* body (1 byte) */ + sysparam->setScreenSaveSecure = body != 0; + break; + + default: + break; + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 err2or code + */ +UINT rail_write_sysparam_order(wStream* s, const RAIL_SYSPARAM_ORDER* sysparam, + BOOL extendedSpiSupported) +{ + BYTE body = 0; + UINT error = CHANNEL_RC_OK; + + if (!s || !sysparam) + return ERROR_INVALID_PARAMETER; + + if (!Stream_EnsureRemainingCapacity(s, 12)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write_UINT32(s, sysparam->param); /* systemParam (4 bytes) */ + + switch (sysparam->param) + { + /* Client sysparams */ + case SPI_SET_DRAG_FULL_WINDOWS: + body = sysparam->dragFullWindows ? 1 : 0; + Stream_Write_UINT8(s, body); + break; + + case SPI_SET_KEYBOARD_CUES: + body = sysparam->keyboardCues ? 1 : 0; + Stream_Write_UINT8(s, body); + break; + + case SPI_SET_KEYBOARD_PREF: + body = sysparam->keyboardPref ? 1 : 0; + Stream_Write_UINT8(s, body); + break; + + case SPI_SET_MOUSE_BUTTON_SWAP: + body = sysparam->mouseButtonSwap ? 1 : 0; + Stream_Write_UINT8(s, body); + break; + + case SPI_SET_WORK_AREA: + Stream_Write_UINT16(s, sysparam->workArea.left); /* left (2 bytes) */ + Stream_Write_UINT16(s, sysparam->workArea.top); /* top (2 bytes) */ + Stream_Write_UINT16(s, sysparam->workArea.right); /* right (2 bytes) */ + Stream_Write_UINT16(s, sysparam->workArea.bottom); /* bottom (2 bytes) */ + break; + + case SPI_DISPLAY_CHANGE: + Stream_Write_UINT16(s, sysparam->displayChange.left); /* left (2 bytes) */ + Stream_Write_UINT16(s, sysparam->displayChange.top); /* top (2 bytes) */ + Stream_Write_UINT16(s, sysparam->displayChange.right); /* right (2 bytes) */ + Stream_Write_UINT16(s, sysparam->displayChange.bottom); /* bottom (2 bytes) */ + break; + + case SPI_TASKBAR_POS: + Stream_Write_UINT16(s, sysparam->taskbarPos.left); /* left (2 bytes) */ + Stream_Write_UINT16(s, sysparam->taskbarPos.top); /* top (2 bytes) */ + Stream_Write_UINT16(s, sysparam->taskbarPos.right); /* right (2 bytes) */ + Stream_Write_UINT16(s, sysparam->taskbarPos.bottom); /* bottom (2 bytes) */ + break; + + case SPI_SET_HIGH_CONTRAST: + error = rail_write_high_contrast(s, &sysparam->highContrast); + break; + + case SPI_SETCARETWIDTH: + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + if (sysparam->caretWidth < 0x0001) + return ERROR_INVALID_DATA; + + Stream_Write_UINT32(s, sysparam->caretWidth); + break; + + case SPI_SETSTICKYKEYS: + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + Stream_Write_UINT32(s, sysparam->stickyKeys); + break; + + case SPI_SETTOGGLEKEYS: + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + Stream_Write_UINT32(s, sysparam->toggleKeys); + break; + + case SPI_SETFILTERKEYS: + if (!extendedSpiSupported) + return ERROR_INVALID_DATA; + + error = rail_write_filterkeys(s, &sysparam->filterKeys); + break; + + /* Server sysparams */ + case SPI_SETSCREENSAVEACTIVE: + body = sysparam->setScreenSaveActive ? 1 : 0; + Stream_Write_UINT8(s, body); + break; + + case SPI_SETSCREENSAVESECURE: + body = sysparam->setScreenSaveSecure ? 1 : 0; + Stream_Write_UINT8(s, body); + break; + + default: + return ERROR_INVALID_PARAMETER; + } + + return error; +} + +BOOL rail_is_extended_spi_supported(UINT32 channelFlags) +{ + return (channelFlags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_EXTENDED_SPI_SUPPORTED) ? TRUE : FALSE; +} + +const char* rail_handshake_ex_flags_to_string(UINT32 flags, char* buffer, size_t len) +{ + if (len < 1) + return NULL; + + (void)_snprintf(buffer, len, "{"); + char* fbuffer = &buffer[1]; + len--; + + if (flags & TS_RAIL_ORDER_HANDSHAKEEX_FLAGS_HIDEF) + winpr_str_append("HIDEF", fbuffer, len, "|"); + if (flags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_EXTENDED_SPI_SUPPORTED) + winpr_str_append("EXTENDED_SPI_SUPPORTED", fbuffer, len, "|"); + if (flags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_SNAP_ARRANGE_SUPPORTED) + winpr_str_append("SNAP_ARRANGE_SUPPORTED", fbuffer, len, "|"); + if (flags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_TEXT_SCALE_SUPPORTED) + winpr_str_append("TEXT_SCALE_SUPPORTED", fbuffer, len, "|"); + if (flags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_CARET_BLINK_SUPPORTED) + winpr_str_append("CARET_BLINK_SUPPORTED", fbuffer, len, "|"); + if (flags & TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_EXTENDED_SPI_2_SUPPORTED) + winpr_str_append("EXTENDED_SPI_2_SUPPORTED", fbuffer, len, "|"); + + char number[16] = { 0 }; + (void)_snprintf(number, sizeof(number), "[0x%08" PRIx32 "]", flags); + winpr_str_append(number, buffer, len, "}"); + return buffer; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/rail_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/rail_common.h new file mode 100644 index 0000000000000000000000000000000000000000..4233a8985b74a8c0224b146a19ad5368d8159f79 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/rail_common.h @@ -0,0 +1,76 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RAIL Virtual Channel Plugin + * + * Copyright 2011 Marc-Andre Moreau + * Copyright 2011 Roman Barabanov + * Copyright 2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RAIL_COMMON_H +#define FREERDP_CHANNEL_RAIL_COMMON_H + +#include + +#define RAIL_PDU_HEADER_LENGTH 4 + +/* Fixed length of PDUs, excluding variable lengths */ +#define RAIL_HANDSHAKE_ORDER_LENGTH 4 /* fixed */ +#define RAIL_HANDSHAKE_EX_ORDER_LENGTH 8 /* fixed */ +#define RAIL_CLIENT_STATUS_ORDER_LENGTH 4 /* fixed */ +#define RAIL_EXEC_ORDER_LENGTH 8 /* variable */ +#define RAIL_EXEC_RESULT_ORDER_LENGTH 12 /* variable */ +#define RAIL_SYSPARAM_ORDER_LENGTH 4 /* variable */ +#define RAIL_MINMAXINFO_ORDER_LENGTH 20 /* fixed */ +#define RAIL_LOCALMOVESIZE_ORDER_LENGTH 12 /* fixed */ +#define RAIL_ACTIVATE_ORDER_LENGTH 5 /* fixed */ +#define RAIL_SYSMENU_ORDER_LENGTH 8 /* fixed */ +#define RAIL_SYSCOMMAND_ORDER_LENGTH 6 /* fixed */ +#define RAIL_NOTIFY_EVENT_ORDER_LENGTH 12 /* fixed */ +#define RAIL_WINDOW_MOVE_ORDER_LENGTH 12 /* fixed */ +#define RAIL_SNAP_ARRANGE_ORDER_LENGTH 12 /* fixed */ +#define RAIL_GET_APPID_REQ_ORDER_LENGTH 4 /* fixed */ +#define RAIL_LANGBAR_INFO_ORDER_LENGTH 4 /* fixed */ +#define RAIL_LANGUAGEIME_INFO_ORDER_LENGTH 42 /* fixed */ +#define RAIL_COMPARTMENT_INFO_ORDER_LENGTH 16 /* fixed */ +#define RAIL_CLOAK_ORDER_LENGTH 5 /* fixed */ +#define RAIL_TASKBAR_INFO_ORDER_LENGTH 12 /* fixed */ +#define RAIL_Z_ORDER_SYNC_ORDER_LENGTH 4 /* fixed */ +#define RAIL_POWER_DISPLAY_REQUEST_ORDER_LENGTH 4 /* fixed */ +#define RAIL_GET_APPID_RESP_ORDER_LENGTH 524 /* fixed */ +#define RAIL_GET_APPID_RESP_EX_ORDER_LENGTH 1048 /* fixed */ + +UINT rail_read_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake); +void rail_write_handshake_order(wStream* s, const RAIL_HANDSHAKE_ORDER* handshake); +UINT rail_read_handshake_ex_order(wStream* s, RAIL_HANDSHAKE_EX_ORDER* handshakeEx); +void rail_write_handshake_ex_order(wStream* s, const RAIL_HANDSHAKE_EX_ORDER* handshakeEx); + +wStream* rail_pdu_init(size_t length); +UINT rail_read_pdu_header(wStream* s, UINT16* orderType, UINT16* orderLength); +void rail_write_pdu_header(wStream* s, UINT16 orderType, UINT16 orderLength); + +UINT rail_write_unicode_string(wStream* s, const RAIL_UNICODE_STRING* unicode_string); +UINT rail_write_unicode_string_value(wStream* s, const RAIL_UNICODE_STRING* unicode_string); + +UINT rail_read_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam, BOOL extendedSpiSupported); +UINT rail_write_sysparam_order(wStream* s, const RAIL_SYSPARAM_ORDER* sysparam, + BOOL extendedSpiSupported); +BOOL rail_is_extended_spi_supported(UINT32 channelFlags); +const char* rail_get_order_type_string(UINT16 orderType); +const char* rail_get_order_type_string_full(UINT16 orderType, char* buffer, size_t length); + +#endif /* FREERDP_CHANNEL_RAIL_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..76734b05f410cf068ecb4c4434803589fa909582 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2019 Mati Shabtay +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("rail") + +set(${MODULE_PREFIX}_SRCS ../rail_common.c ../rail_common.h rail_main.c rail_main.h) + +set(${MODULE_PREFIX}_LIBS freerdp) + +include_directories(..) + +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "VirtualChannelEntryEx") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/rail_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/rail_main.c new file mode 100644 index 0000000000000000000000000000000000000000..fb336a1228ecae2c08c597b4431b463f268da2f3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/rail_main.c @@ -0,0 +1,1731 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RAIL Virtual Channel Plugin + * + * Copyright 2019 Mati Shabtay + * + + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "rail_main.h" + +#define TAG CHANNELS_TAG("rail.server") + +/** + * Sends a single rail PDU on the channel + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send(RailServerContext* context, wStream* s, ULONG length) +{ + UINT status = CHANNEL_RC_OK; + ULONG written = 0; + + if (!context) + return CHANNEL_RC_BAD_INIT_HANDLE; + + if (!WTSVirtualChannelWrite(context->priv->rail_channel, Stream_BufferAs(s, char), length, + &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + status = ERROR_INTERNAL_ERROR; + } + + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_server_send_pdu(RailServerContext* context, wStream* s, UINT16 orderType) +{ + char buffer[128] = { 0 }; + UINT16 orderLength = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + orderLength = (UINT16)Stream_GetPosition(s); + Stream_SetPosition(s, 0); + rail_write_pdu_header(s, orderType, orderLength); + Stream_SetPosition(s, orderLength); + WLog_DBG(TAG, "Sending %s PDU, length: %" PRIu16 "", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); + return rail_send(context, s, orderLength); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_local_move_size_order(wStream* s, + const RAIL_LOCALMOVESIZE_ORDER* localMoveSize) +{ + if (!s || !localMoveSize) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, localMoveSize->windowId); /* WindowId (4 bytes) */ + Stream_Write_UINT16(s, localMoveSize->isMoveSizeStart ? 1 : 0); /* IsMoveSizeStart (2 bytes) */ + Stream_Write_UINT16(s, localMoveSize->moveSizeType); /* MoveSizeType (2 bytes) */ + Stream_Write_INT16(s, localMoveSize->posX); /* PosX (2 bytes) */ + Stream_Write_INT16(s, localMoveSize->posY); /* PosY (2 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_min_max_info_order(wStream* s, const RAIL_MINMAXINFO_ORDER* minMaxInfo) +{ + if (!s || !minMaxInfo) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, minMaxInfo->windowId); /* WindowId (4 bytes) */ + Stream_Write_INT16(s, minMaxInfo->maxWidth); /* MaxWidth (2 bytes) */ + Stream_Write_INT16(s, minMaxInfo->maxHeight); /* MaxHeight (2 bytes) */ + Stream_Write_INT16(s, minMaxInfo->maxPosX); /* MaxPosX (2 bytes) */ + Stream_Write_INT16(s, minMaxInfo->maxPosY); /* MaxPosY (2 bytes) */ + Stream_Write_INT16(s, minMaxInfo->minTrackWidth); /* MinTrackWidth (2 bytes) */ + Stream_Write_INT16(s, minMaxInfo->minTrackHeight); /* MinTrackHeight (2 bytes) */ + Stream_Write_INT16(s, minMaxInfo->maxTrackWidth); /* MaxTrackWidth (2 bytes) */ + Stream_Write_INT16(s, minMaxInfo->maxTrackHeight); /* MaxTrackHeight (2 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_taskbar_info_order(wStream* s, const RAIL_TASKBAR_INFO_ORDER* taskbarInfo) +{ + if (!s || !taskbarInfo) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, taskbarInfo->TaskbarMessage); /* TaskbarMessage (4 bytes) */ + Stream_Write_UINT32(s, taskbarInfo->WindowIdTab); /* WindowIdTab (4 bytes) */ + Stream_Write_UINT32(s, taskbarInfo->Body); /* Body (4 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_langbar_info_order(wStream* s, const RAIL_LANGBAR_INFO_ORDER* langbarInfo) +{ + if (!s || !langbarInfo) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, langbarInfo->languageBarStatus); /* LanguageBarStatus (4 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_exec_result_order(wStream* s, const RAIL_EXEC_RESULT_ORDER* execResult) +{ + if (!s || !execResult) + return ERROR_INVALID_PARAMETER; + + if (execResult->exeOrFile.length > 520 || execResult->exeOrFile.length < 1) + return ERROR_INVALID_DATA; + + Stream_Write_UINT16(s, execResult->flags); /* Flags (2 bytes) */ + Stream_Write_UINT16(s, execResult->execResult); /* ExecResult (2 bytes) */ + Stream_Write_UINT32(s, execResult->rawResult); /* RawResult (4 bytes) */ + Stream_Write_UINT16(s, 0); /* Padding (2 bytes) */ + Stream_Write_UINT16(s, execResult->exeOrFile.length); /* ExeOrFileLength (2 bytes) */ + Stream_Write(s, execResult->exeOrFile.string, + execResult->exeOrFile.length); /* ExeOrFile (variable) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_z_order_sync_order(wStream* s, const RAIL_ZORDER_SYNC* zOrderSync) +{ + if (!s || !zOrderSync) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, zOrderSync->windowIdMarker); /* WindowIdMarker (4 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_cloak_order(wStream* s, const RAIL_CLOAK* cloak) +{ + if (!s || !cloak) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, cloak->windowId); /* WindowId (4 bytes) */ + Stream_Write_UINT8(s, cloak->cloak ? 1 : 0); /* Cloaked (1 byte) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +rail_write_power_display_request_order(wStream* s, + const RAIL_POWER_DISPLAY_REQUEST* powerDisplayRequest) +{ + if (!s || !powerDisplayRequest) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, powerDisplayRequest->active ? 1 : 0); /* Active (4 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_get_app_id_resp_order(wStream* s, + const RAIL_GET_APPID_RESP_ORDER* getAppidResp) +{ + if (!s || !getAppidResp) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, getAppidResp->windowId); /* WindowId (4 bytes) */ + Stream_Write_UTF16_String( + s, getAppidResp->applicationId, + ARRAYSIZE(getAppidResp->applicationId)); /* ApplicationId (512 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_write_get_appid_resp_ex_order(wStream* s, + const RAIL_GET_APPID_RESP_EX* getAppidRespEx) +{ + if (!s || !getAppidRespEx) + return ERROR_INVALID_PARAMETER; + + Stream_Write_UINT32(s, getAppidRespEx->windowID); /* WindowId (4 bytes) */ + Stream_Write_UTF16_String( + s, getAppidRespEx->applicationID, + ARRAYSIZE(getAppidRespEx->applicationID)); /* ApplicationId (520 bytes) */ + Stream_Write_UINT32(s, getAppidRespEx->processId); /* ProcessId (4 bytes) */ + Stream_Write_UTF16_String( + s, getAppidRespEx->processImageName, + ARRAYSIZE(getAppidRespEx->processImageName)); /* ProcessImageName (520 bytes) */ + return ERROR_SUCCESS; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_handshake(RailServerContext* context, + const RAIL_HANDSHAKE_ORDER* handshake) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !handshake) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_handshake_order(s, handshake); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_HANDSHAKE); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_handshake_ex(RailServerContext* context, + const RAIL_HANDSHAKE_EX_ORDER* handshakeEx) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !handshakeEx || !context->priv) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_HANDSHAKE_EX_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_server_set_handshake_ex_flags(context, handshakeEx->railHandshakeFlags); + + rail_write_handshake_ex_order(s, handshakeEx); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_HANDSHAKE_EX); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_sysparam(RailServerContext* context, + const RAIL_SYSPARAM_ORDER* sysparam) +{ + wStream* s = NULL; + UINT error = 0; + RailServerPrivate* priv = NULL; + BOOL extendedSpiSupported = 0; + + if (!context || !sysparam) + return ERROR_INVALID_PARAMETER; + + priv = context->priv; + + if (!priv) + return ERROR_INVALID_PARAMETER; + + extendedSpiSupported = rail_is_extended_spi_supported(context->priv->channelFlags); + s = rail_pdu_init(RAIL_SYSPARAM_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_sysparam_order(s, sysparam, extendedSpiSupported); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_SYSPARAM); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_local_move_size(RailServerContext* context, + const RAIL_LOCALMOVESIZE_ORDER* localMoveSize) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !localMoveSize) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_LOCALMOVESIZE_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_local_move_size_order(s, localMoveSize); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_LOCALMOVESIZE); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_min_max_info(RailServerContext* context, + const RAIL_MINMAXINFO_ORDER* minMaxInfo) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !minMaxInfo) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_MINMAXINFO_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_min_max_info_order(s, minMaxInfo); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_MINMAXINFO); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_taskbar_info(RailServerContext* context, + const RAIL_TASKBAR_INFO_ORDER* taskbarInfo) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !taskbarInfo) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_TASKBAR_INFO_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_taskbar_info_order(s, taskbarInfo); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_TASKBARINFO); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_langbar_info(RailServerContext* context, + const RAIL_LANGBAR_INFO_ORDER* langbarInfo) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !langbarInfo) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_langbar_info_order(s, langbarInfo); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_LANGBARINFO); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_exec_result(RailServerContext* context, + const RAIL_EXEC_RESULT_ORDER* execResult) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !execResult) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_EXEC_RESULT_ORDER_LENGTH + execResult->exeOrFile.length); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_exec_result_order(s, execResult); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_EXEC_RESULT); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_z_order_sync(RailServerContext* context, + const RAIL_ZORDER_SYNC* zOrderSync) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !zOrderSync) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_Z_ORDER_SYNC_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_z_order_sync_order(s, zOrderSync); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_ZORDER_SYNC); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_cloak(RailServerContext* context, const RAIL_CLOAK* cloak) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !cloak) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_CLOAK_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_cloak_order(s, cloak); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_CLOAK); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT +rail_send_server_power_display_request(RailServerContext* context, + const RAIL_POWER_DISPLAY_REQUEST* powerDisplayRequest) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !powerDisplayRequest) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_POWER_DISPLAY_REQUEST_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_power_display_request_order(s, powerDisplayRequest); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_POWER_DISPLAY_REQUEST); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error coie + */ +static UINT rail_send_server_get_app_id_resp(RailServerContext* context, + const RAIL_GET_APPID_RESP_ORDER* getAppidResp) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !getAppidResp) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_GET_APPID_RESP_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_get_app_id_resp_order(s, getAppidResp); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_GET_APPID_RESP); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_send_server_get_appid_resp_ex(RailServerContext* context, + const RAIL_GET_APPID_RESP_EX* getAppidRespEx) +{ + wStream* s = NULL; + UINT error = 0; + + if (!context || !getAppidRespEx) + return ERROR_INVALID_PARAMETER; + + s = rail_pdu_init(RAIL_GET_APPID_RESP_EX_ORDER_LENGTH); + + if (!s) + { + WLog_ERR(TAG, "rail_pdu_init failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rail_write_get_appid_resp_ex_order(s, getAppidRespEx); + error = rail_server_send_pdu(context, s, TS_RAIL_ORDER_GET_APPID_RESP_EX); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* clientStatus) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_CLIENT_STATUS_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, clientStatus->flags); /* Flags (4 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_exec_order(wStream* s, RAIL_EXEC_ORDER* exec, char* args[]) +{ + RAIL_EXEC_ORDER order = { 0 }; + UINT16 exeLen = 0; + UINT16 workLen = 0; + UINT16 argLen = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_EXEC_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, exec->flags); /* Flags (2 bytes) */ + Stream_Read_UINT16(s, exeLen); /* ExeOrFileLength (2 bytes) */ + Stream_Read_UINT16(s, workLen); /* WorkingDirLength (2 bytes) */ + Stream_Read_UINT16(s, argLen); /* ArgumentsLength (2 bytes) */ + + if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)exeLen + workLen + argLen)) + return ERROR_INVALID_DATA; + + if (exeLen > 0) + { + const size_t len = exeLen / sizeof(WCHAR); + exec->RemoteApplicationProgram = args[0] = Stream_Read_UTF16_String_As_UTF8(s, len, NULL); + if (!exec->RemoteApplicationProgram) + goto fail; + } + if (workLen > 0) + { + const size_t len = workLen / sizeof(WCHAR); + exec->RemoteApplicationWorkingDir = args[1] = + Stream_Read_UTF16_String_As_UTF8(s, len, NULL); + if (!exec->RemoteApplicationWorkingDir) + goto fail; + } + if (argLen > 0) + { + const size_t len = argLen / sizeof(WCHAR); + exec->RemoteApplicationArguments = args[2] = Stream_Read_UTF16_String_As_UTF8(s, len, NULL); + if (!exec->RemoteApplicationArguments) + goto fail; + } + + return CHANNEL_RC_OK; +fail: + free(args[0]); + free(args[1]); + free(args[2]); + *exec = order; + return ERROR_INTERNAL_ERROR; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate) +{ + BYTE enabled = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_ACTIVATE_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, activate->windowId); /* WindowId (4 bytes) */ + Stream_Read_UINT8(s, enabled); /* Enabled (1 byte) */ + activate->enabled = (enabled != 0) ? TRUE : FALSE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_SYSMENU_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, sysmenu->windowId); /* WindowId (4 bytes) */ + Stream_Read_INT16(s, sysmenu->left); /* Left (2 bytes) */ + Stream_Read_INT16(s, sysmenu->top); /* Top (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_SYSCOMMAND_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, syscommand->windowId); /* WindowId (4 bytes) */ + Stream_Read_UINT16(s, syscommand->command); /* Command (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notifyEvent) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_NOTIFY_EVENT_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, notifyEvent->windowId); /* WindowId (4 bytes) */ + Stream_Read_UINT32(s, notifyEvent->notifyIconId); /* NotifyIconId (4 bytes) */ + Stream_Read_UINT32(s, notifyEvent->message); /* Message (4 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_get_appid_req_order(wStream* s, RAIL_GET_APPID_REQ_ORDER* getAppidReq) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_GET_APPID_REQ_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, getAppidReq->windowId); /* WindowId (4 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* windowMove) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_WINDOW_MOVE_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, windowMove->windowId); /* WindowId (4 bytes) */ + Stream_Read_INT16(s, windowMove->left); /* Left (2 bytes) */ + Stream_Read_INT16(s, windowMove->top); /* Top (2 bytes) */ + Stream_Read_INT16(s, windowMove->right); /* Right (2 bytes) */ + Stream_Read_INT16(s, windowMove->bottom); /* Bottom (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_snap_arange_order(wStream* s, RAIL_SNAP_ARRANGE* snapArrange) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_SNAP_ARRANGE_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, snapArrange->windowId); /* WindowId (4 bytes) */ + Stream_Read_INT16(s, snapArrange->left); /* Left (2 bytes) */ + Stream_Read_INT16(s, snapArrange->top); /* Top (2 bytes) */ + Stream_Read_INT16(s, snapArrange->right); /* Right (2 bytes) */ + Stream_Read_INT16(s, snapArrange->bottom); /* Bottom (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbarInfo) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LANGBAR_INFO_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, langbarInfo->languageBarStatus); /* LanguageBarStatus (4 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_language_ime_info_order(wStream* s, + RAIL_LANGUAGEIME_INFO_ORDER* languageImeInfo) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_LANGUAGEIME_INFO_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, languageImeInfo->ProfileType); /* ProfileType (4 bytes) */ + Stream_Read_UINT16(s, languageImeInfo->LanguageID); /* LanguageID (2 bytes) */ + Stream_Read( + s, &languageImeInfo->LanguageProfileCLSID, + sizeof(languageImeInfo->LanguageProfileCLSID)); /* LanguageProfileCLSID (16 bytes) */ + Stream_Read(s, &languageImeInfo->ProfileGUID, + sizeof(languageImeInfo->ProfileGUID)); /* ProfileGUID (16 bytes) */ + Stream_Read_UINT32(s, languageImeInfo->KeyboardLayout); /* KeyboardLayout (4 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_compartment_info_order(wStream* s, + RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_COMPARTMENT_INFO_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, compartmentInfo->ImeState); /* ImeState (4 bytes) */ + Stream_Read_UINT32(s, compartmentInfo->ImeConvMode); /* ImeConvMode (4 bytes) */ + Stream_Read_UINT32(s, compartmentInfo->ImeSentenceMode); /* ImeSentenceMode (4 bytes) */ + Stream_Read_UINT32(s, compartmentInfo->KanaMode); /* KANAMode (4 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_read_cloak_order(wStream* s, RAIL_CLOAK* cloak) +{ + BYTE cloaked = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RAIL_CLOAK_ORDER_LENGTH)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, cloak->windowId); /* WindowId (4 bytes) */ + Stream_Read_UINT8(s, cloaked); /* Cloaked (1 byte) */ + cloak->cloak = (cloaked != 0) ? TRUE : FALSE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_handshake_order(RailServerContext* context, + RAIL_HANDSHAKE_ORDER* handshake, wStream* s) +{ + UINT error = 0; + + if (!context || !handshake || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_handshake_order(s, handshake))) + { + WLog_ERR(TAG, "rail_read_handshake_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientHandshake, error, context, handshake); + + if (error) + WLog_ERR(TAG, "context.ClientHandshake failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_client_status_order(RailServerContext* context, + RAIL_CLIENT_STATUS_ORDER* clientStatus, wStream* s) +{ + UINT error = 0; + + if (!context || !clientStatus || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_client_status_order(s, clientStatus))) + { + WLog_ERR(TAG, "rail_read_client_status_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientClientStatus, error, context, clientStatus); + + if (error) + WLog_ERR(TAG, "context.ClientClientStatus failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_exec_order(RailServerContext* context, wStream* s) +{ + UINT error = 0; + char* args[3] = { 0 }; + RAIL_EXEC_ORDER exec = { 0 }; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + error = rail_read_exec_order(s, &exec, args); + if (error) + { + WLog_ERR(TAG, "rail_read_client_status_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientExec, error, context, &exec); + + if (error) + WLog_ERR(TAG, "context.Exec failed with error %" PRIu32 "", error); + + free(args[0]); + free(args[1]); + free(args[2]); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_sysparam_order(RailServerContext* context, + RAIL_SYSPARAM_ORDER* sysparam, wStream* s) +{ + UINT error = 0; + BOOL extendedSpiSupported = 0; + + if (!context || !sysparam || !s) + return ERROR_INVALID_PARAMETER; + + extendedSpiSupported = rail_is_extended_spi_supported(context->priv->channelFlags); + if ((error = rail_read_sysparam_order(s, sysparam, extendedSpiSupported))) + { + WLog_ERR(TAG, "rail_read_sysparam_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientSysparam, error, context, sysparam); + + if (error) + WLog_ERR(TAG, "context.ClientSysparam failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_activate_order(RailServerContext* context, + RAIL_ACTIVATE_ORDER* activate, wStream* s) +{ + UINT error = 0; + + if (!context || !activate || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_activate_order(s, activate))) + { + WLog_ERR(TAG, "rail_read_activate_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientActivate, error, context, activate); + + if (error) + WLog_ERR(TAG, "context.ClientActivate failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_sysmenu_order(RailServerContext* context, RAIL_SYSMENU_ORDER* sysmenu, + wStream* s) +{ + UINT error = 0; + + if (!context || !sysmenu || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_sysmenu_order(s, sysmenu))) + { + WLog_ERR(TAG, "rail_read_sysmenu_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientSysmenu, error, context, sysmenu); + + if (error) + WLog_ERR(TAG, "context.ClientSysmenu failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_syscommand_order(RailServerContext* context, + RAIL_SYSCOMMAND_ORDER* syscommand, wStream* s) +{ + UINT error = 0; + + if (!context || !syscommand || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_syscommand_order(s, syscommand))) + { + WLog_ERR(TAG, "rail_read_syscommand_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientSyscommand, error, context, syscommand); + + if (error) + WLog_ERR(TAG, "context.ClientSyscommand failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_notify_event_order(RailServerContext* context, + RAIL_NOTIFY_EVENT_ORDER* notifyEvent, wStream* s) +{ + UINT error = 0; + + if (!context || !notifyEvent || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_notify_event_order(s, notifyEvent))) + { + WLog_ERR(TAG, "rail_read_notify_event_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientNotifyEvent, error, context, notifyEvent); + + if (error) + WLog_ERR(TAG, "context.ClientNotifyEvent failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_window_move_order(RailServerContext* context, + RAIL_WINDOW_MOVE_ORDER* windowMove, wStream* s) +{ + UINT error = 0; + + if (!context || !windowMove || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_window_move_order(s, windowMove))) + { + WLog_ERR(TAG, "rail_read_window_move_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientWindowMove, error, context, windowMove); + + if (error) + WLog_ERR(TAG, "context.ClientWindowMove failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_snap_arrange_order(RailServerContext* context, + RAIL_SNAP_ARRANGE* snapArrange, wStream* s) +{ + UINT error = 0; + + if (!context || !snapArrange || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_snap_arange_order(s, snapArrange))) + { + WLog_ERR(TAG, "rail_read_snap_arange_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientSnapArrange, error, context, snapArrange); + + if (error) + WLog_ERR(TAG, "context.ClientSnapArrange failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_get_appid_req_order(RailServerContext* context, + RAIL_GET_APPID_REQ_ORDER* getAppidReq, wStream* s) +{ + UINT error = 0; + + if (!context || !getAppidReq || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_get_appid_req_order(s, getAppidReq))) + { + WLog_ERR(TAG, "rail_read_get_appid_req_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientGetAppidReq, error, context, getAppidReq); + + if (error) + WLog_ERR(TAG, "context.ClientGetAppidReq failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_langbar_info_order(RailServerContext* context, + RAIL_LANGBAR_INFO_ORDER* langbarInfo, wStream* s) +{ + UINT error = 0; + + if (!context || !langbarInfo || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_langbar_info_order(s, langbarInfo))) + { + WLog_ERR(TAG, "rail_read_langbar_info_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientLangbarInfo, error, context, langbarInfo); + + if (error) + WLog_ERR(TAG, "context.ClientLangbarInfo failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_language_ime_info_order(RailServerContext* context, + RAIL_LANGUAGEIME_INFO_ORDER* languageImeInfo, + wStream* s) +{ + UINT error = 0; + + if (!context || !languageImeInfo || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_language_ime_info_order(s, languageImeInfo))) + { + WLog_ERR(TAG, "rail_read_language_ime_info_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientLanguageImeInfo, error, context, languageImeInfo); + + if (error) + WLog_ERR(TAG, "context.ClientLanguageImeInfo failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_compartment_info(RailServerContext* context, + RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo, + wStream* s) +{ + UINT error = 0; + + if (!context || !compartmentInfo || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_compartment_info_order(s, compartmentInfo))) + { + WLog_ERR(TAG, "rail_read_compartment_info_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientCompartmentInfo, error, context, compartmentInfo); + + if (error) + WLog_ERR(TAG, "context.ClientCompartmentInfo failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_recv_client_cloak_order(RailServerContext* context, RAIL_CLOAK* cloak, wStream* s) +{ + UINT error = 0; + + if (!context || !cloak || !s) + return ERROR_INVALID_PARAMETER; + + if ((error = rail_read_cloak_order(s, cloak))) + { + WLog_ERR(TAG, "rail_read_cloak_order failed with error %" PRIu32 "!", error); + return error; + } + + IFCALLRET(context->ClientCloak, error, context, cloak); + + if (error) + WLog_ERR(TAG, "context.Cloak failed with error %" PRIu32 "", error); + + return error; +} + +static UINT rail_recv_client_text_scale_order(RailServerContext* context, wStream* s) +{ + UINT error = CHANNEL_RC_OK; + UINT32 TextScaleFactor = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, TextScaleFactor); + IFCALLRET(context->ClientTextScale, error, context, TextScaleFactor); + + if (error) + WLog_ERR(TAG, "context.TextScale failed with error %" PRIu32 "", error); + + return error; +} + +static UINT rail_recv_client_caret_blink(RailServerContext* context, wStream* s) +{ + UINT error = CHANNEL_RC_OK; + UINT32 CaretBlinkRate = 0; + + if (!context || !s) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, CaretBlinkRate); + IFCALLRET(context->ClientCaretBlinkRate, error, context, CaretBlinkRate); + + if (error) + WLog_ERR(TAG, "context.CaretBlinkRate failed with error %" PRIu32 "", error); + + return error; +} + +static DWORD WINAPI rail_server_thread(LPVOID arg) +{ + RailServerContext* context = (RailServerContext*)arg; + RailServerPrivate* priv = context->priv; + DWORD status = 0; + DWORD nCount = 0; + HANDLE events[8]; + UINT error = CHANNEL_RC_OK; + events[nCount++] = priv->channelEvent; + events[nCount++] = priv->stopEvent; + + while (TRUE) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "!", error); + break; + } + + status = WaitForSingleObject(context->priv->stopEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error); + break; + } + + if (status == WAIT_OBJECT_0) + break; + + status = WaitForSingleObject(context->priv->channelEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR( + TAG, + "WaitForSingleObject(context->priv->channelEvent, 0) failed with error %" PRIu32 + "!", + error); + break; + } + + if (status == WAIT_OBJECT_0) + { + if ((error = rail_server_handle_messages(context))) + { + WLog_ERR(TAG, "rail_server_handle_messages failed with error %" PRIu32 "", error); + break; + } + } + } + + if (error && context->rdpcontext) + setChannelError(context->rdpcontext, error, "rail_server_thread reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rail_server_start(RailServerContext* context) +{ + void* buffer = NULL; + DWORD bytesReturned = 0; + RailServerPrivate* priv = context->priv; + UINT error = ERROR_INTERNAL_ERROR; + priv->rail_channel = + WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, RAIL_SVC_CHANNEL_NAME); + + if (!priv->rail_channel) + { + WLog_ERR(TAG, "WTSVirtualChannelOpen failed!"); + return error; + } + + if (!WTSVirtualChannelQuery(priv->rail_channel, WTSVirtualEventHandle, &buffer, + &bytesReturned) || + (bytesReturned != sizeof(HANDLE))) + { + WLog_ERR(TAG, + "error during WTSVirtualChannelQuery(WTSVirtualEventHandle) or invalid returned " + "size(%" PRIu32 ")", + bytesReturned); + + if (buffer) + WTSFreeMemory(buffer); + + goto out_close; + } + + priv->channelEvent = *(HANDLE*)buffer; + WTSFreeMemory(buffer); + context->priv->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (!context->priv->stopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + goto out_close; + } + + context->priv->thread = CreateThread(NULL, 0, rail_server_thread, (void*)context, 0, NULL); + + if (!context->priv->thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + goto out_stop_event; + } + + return CHANNEL_RC_OK; +out_stop_event: + (void)CloseHandle(context->priv->stopEvent); + context->priv->stopEvent = NULL; +out_close: + (void)WTSVirtualChannelClose(context->priv->rail_channel); + context->priv->rail_channel = NULL; + return error; +} + +static BOOL rail_server_stop(RailServerContext* context) +{ + RailServerPrivate* priv = context->priv; + + if (priv->thread) + { + (void)SetEvent(priv->stopEvent); + + if (WaitForSingleObject(priv->thread, INFINITE) == WAIT_FAILED) + { + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", GetLastError()); + return FALSE; + } + + (void)CloseHandle(priv->thread); + (void)CloseHandle(priv->stopEvent); + priv->thread = NULL; + priv->stopEvent = NULL; + } + + if (priv->rail_channel) + { + (void)WTSVirtualChannelClose(priv->rail_channel); + priv->rail_channel = NULL; + } + + priv->channelEvent = NULL; + return TRUE; +} + +RailServerContext* rail_server_context_new(HANDLE vcm) +{ + RailServerContext* context = NULL; + RailServerPrivate* priv = NULL; + context = (RailServerContext*)calloc(1, sizeof(RailServerContext)); + + if (!context) + { + WLog_ERR(TAG, "calloc failed!"); + return NULL; + } + + context->vcm = vcm; + context->Start = rail_server_start; + context->Stop = rail_server_stop; + context->ServerHandshake = rail_send_server_handshake; + context->ServerHandshakeEx = rail_send_server_handshake_ex; + context->ServerSysparam = rail_send_server_sysparam; + context->ServerLocalMoveSize = rail_send_server_local_move_size; + context->ServerMinMaxInfo = rail_send_server_min_max_info; + context->ServerTaskbarInfo = rail_send_server_taskbar_info; + context->ServerLangbarInfo = rail_send_server_langbar_info; + context->ServerExecResult = rail_send_server_exec_result; + context->ServerGetAppidResp = rail_send_server_get_app_id_resp; + context->ServerZOrderSync = rail_send_server_z_order_sync; + context->ServerCloak = rail_send_server_cloak; + context->ServerPowerDisplayRequest = rail_send_server_power_display_request; + context->ServerGetAppidRespEx = rail_send_server_get_appid_resp_ex; + context->priv = priv = (RailServerPrivate*)calloc(1, sizeof(RailServerPrivate)); + + if (!priv) + { + WLog_ERR(TAG, "calloc failed!"); + goto out_free; + } + + /* Create shared input stream */ + priv->input_stream = Stream_New(NULL, 4096); + + if (!priv->input_stream) + { + WLog_ERR(TAG, "Stream_New failed!"); + goto out_free_priv; + } + + return context; +out_free_priv: + free(context->priv); +out_free: + free(context); + return NULL; +} + +void rail_server_context_free(RailServerContext* context) +{ + if (context->priv) + Stream_Free(context->priv->input_stream, TRUE); + + free(context->priv); + free(context); +} + +void rail_server_set_handshake_ex_flags(RailServerContext* context, DWORD flags) +{ + RailServerPrivate* priv = NULL; + + if (!context || !context->priv) + return; + + priv = context->priv; + priv->channelFlags = flags; +} + +UINT rail_server_handle_messages(RailServerContext* context) +{ + char buffer[128] = { 0 }; + UINT status = CHANNEL_RC_OK; + DWORD bytesReturned = 0; + UINT16 orderType = 0; + UINT16 orderLength = 0; + RailServerPrivate* priv = context->priv; + wStream* s = priv->input_stream; + + /* Read header */ + if (!Stream_EnsureRemainingCapacity(s, RAIL_PDU_HEADER_LENGTH)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed, RAIL_PDU_HEADER_LENGTH"); + return CHANNEL_RC_NO_MEMORY; + } + + if (!WTSVirtualChannelRead(priv->rail_channel, 0, Stream_Pointer(s), RAIL_PDU_HEADER_LENGTH, + &bytesReturned)) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_ERR(TAG, "channel connection closed"); + return ERROR_INTERNAL_ERROR; + } + + /* Parse header */ + if ((status = rail_read_pdu_header(s, &orderType, &orderLength)) != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "rail_read_pdu_header failed with error %" PRIu32 "!", status); + return status; + } + + if (!Stream_EnsureRemainingCapacity(s, orderLength - RAIL_PDU_HEADER_LENGTH)) + { + WLog_ERR(TAG, + "Stream_EnsureRemainingCapacity failed, orderLength - RAIL_PDU_HEADER_LENGTH"); + return CHANNEL_RC_NO_MEMORY; + } + + /* Read body */ + if (!WTSVirtualChannelRead(priv->rail_channel, 0, Stream_Pointer(s), + orderLength - RAIL_PDU_HEADER_LENGTH, &bytesReturned)) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_ERR(TAG, "channel connection closed"); + return ERROR_INTERNAL_ERROR; + } + + WLog_DBG(TAG, "Received %s PDU, length:%" PRIu16 "", + rail_get_order_type_string_full(orderType, buffer, sizeof(buffer)), orderLength); + + switch (orderType) + { + case TS_RAIL_ORDER_HANDSHAKE: + { + RAIL_HANDSHAKE_ORDER handshake; + return rail_recv_client_handshake_order(context, &handshake, s); + } + + case TS_RAIL_ORDER_CLIENTSTATUS: + { + RAIL_CLIENT_STATUS_ORDER clientStatus; + return rail_recv_client_client_status_order(context, &clientStatus, s); + } + + case TS_RAIL_ORDER_EXEC: + return rail_recv_client_exec_order(context, s); + + case TS_RAIL_ORDER_SYSPARAM: + { + RAIL_SYSPARAM_ORDER sysparam = { 0 }; + return rail_recv_client_sysparam_order(context, &sysparam, s); + } + + case TS_RAIL_ORDER_ACTIVATE: + { + RAIL_ACTIVATE_ORDER activate; + return rail_recv_client_activate_order(context, &activate, s); + } + + case TS_RAIL_ORDER_SYSMENU: + { + RAIL_SYSMENU_ORDER sysmenu; + return rail_recv_client_sysmenu_order(context, &sysmenu, s); + } + + case TS_RAIL_ORDER_SYSCOMMAND: + { + RAIL_SYSCOMMAND_ORDER syscommand; + return rail_recv_client_syscommand_order(context, &syscommand, s); + } + + case TS_RAIL_ORDER_NOTIFY_EVENT: + { + RAIL_NOTIFY_EVENT_ORDER notifyEvent; + return rail_recv_client_notify_event_order(context, ¬ifyEvent, s); + } + + case TS_RAIL_ORDER_WINDOWMOVE: + { + RAIL_WINDOW_MOVE_ORDER windowMove; + return rail_recv_client_window_move_order(context, &windowMove, s); + } + + case TS_RAIL_ORDER_SNAP_ARRANGE: + { + RAIL_SNAP_ARRANGE snapArrange; + return rail_recv_client_snap_arrange_order(context, &snapArrange, s); + } + + case TS_RAIL_ORDER_GET_APPID_REQ: + { + RAIL_GET_APPID_REQ_ORDER getAppidReq; + return rail_recv_client_get_appid_req_order(context, &getAppidReq, s); + } + + case TS_RAIL_ORDER_LANGBARINFO: + { + RAIL_LANGBAR_INFO_ORDER langbarInfo; + return rail_recv_client_langbar_info_order(context, &langbarInfo, s); + } + + case TS_RAIL_ORDER_LANGUAGEIMEINFO: + { + RAIL_LANGUAGEIME_INFO_ORDER languageImeInfo; + return rail_recv_client_language_ime_info_order(context, &languageImeInfo, s); + } + + case TS_RAIL_ORDER_COMPARTMENTINFO: + { + RAIL_COMPARTMENT_INFO_ORDER compartmentInfo; + return rail_recv_client_compartment_info(context, &compartmentInfo, s); + } + + case TS_RAIL_ORDER_CLOAK: + { + RAIL_CLOAK cloak; + return rail_recv_client_cloak_order(context, &cloak, s); + } + + case TS_RAIL_ORDER_TEXTSCALEINFO: + { + return rail_recv_client_text_scale_order(context, s); + } + + case TS_RAIL_ORDER_CARETBLINKINFO: + { + return rail_recv_client_caret_blink(context, s); + } + + default: + WLog_ERR(TAG, "Unknown RAIL PDU order received."); + return ERROR_INVALID_DATA; + } +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/rail_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/rail_main.h new file mode 100644 index 0000000000000000000000000000000000000000..f15cf19346a2979086ae85c453bb94e27faeabcb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rail/server/rail_main.h @@ -0,0 +1,44 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RAIL Virtual Channel Plugin + * + * Copyright 2019 Mati Shabtay + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RAIL_SERVER_MAIN_H +#define FREERDP_CHANNEL_RAIL_SERVER_MAIN_H + +#include +#include + +#include +#include +#include + +#include "../rail_common.h" + +struct s_rail_server_private +{ + HANDLE thread; + HANDLE stopEvent; + HANDLE channelEvent; + void* rail_channel; + + wStream* input_stream; + + DWORD channelFlags; +}; + +#endif /* FREERDP_CHANNEL_RAIL_SERVER_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3d0bf4667ae0d1eeee4e5d86926ac5942e2179b8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdp2tcp") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..ca21887511dbef6ba1763be67d715b8ecdde0a39 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/ChannelOptions.cmake @@ -0,0 +1,18 @@ +set(OPTION_DEFAULT OFF) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options( + NAME + "rdp2tcp" + TYPE + "static" + DESCRIPTION + "Tunneling TCP over RDP" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1c9c03bdae7848778fa12df3dc4102c618719f2b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/client/CMakeLists.txt @@ -0,0 +1,23 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("rdp2tcp") + +set(${MODULE_PREFIX}_SRCS rdp2tcp_main.c) + +set(${MODULE_PREFIX}_LIBS freerdp) +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "VirtualChannelEntryEx") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/client/rdp2tcp_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/client/rdp2tcp_main.c new file mode 100644 index 0000000000000000000000000000000000000000..17238c6bb26ea5ea2e08640cc8ace5495a7459a3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdp2tcp/client/rdp2tcp_main.c @@ -0,0 +1,311 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * rdp2tcp Virtual Channel Extension + * + * Copyright 2017 Artur Zaprzala + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#define TAG CLIENT_TAG(RDP2TCP_DVC_CHANNEL_NAME) + +typedef struct +{ + HANDLE hStdOutputRead; + HANDLE hStdInputWrite; + HANDLE hProcess; + HANDLE copyThread; + HANDLE writeComplete; + DWORD openHandle; + void* initHandle; + CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints; + char buffer[16 * 1024]; + char* commandline; +} Plugin; + +static int init_external_addin(Plugin* plugin) +{ + SECURITY_ATTRIBUTES saAttr = { 0 }; + STARTUPINFOA siStartInfo = { 0 }; /* Using ANSI type to match CreateProcessA */ + PROCESS_INFORMATION procInfo = { 0 }; + + WINPR_ASSERT(plugin); + + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = TRUE; + saAttr.lpSecurityDescriptor = NULL; + siStartInfo.cb = sizeof(STARTUPINFO); + siStartInfo.hStdError = GetStdHandle(STD_ERROR_HANDLE); + siStartInfo.dwFlags = STARTF_USESTDHANDLES; + + // Create pipes + if (!CreatePipe(&plugin->hStdOutputRead, &siStartInfo.hStdOutput, &saAttr, 0)) + { + WLog_ERR(TAG, "stdout CreatePipe"); + return -1; + } + + if (!SetHandleInformation(plugin->hStdOutputRead, HANDLE_FLAG_INHERIT, 0)) + { + WLog_ERR(TAG, "stdout SetHandleInformation"); + return -1; + } + + if (!CreatePipe(&siStartInfo.hStdInput, &plugin->hStdInputWrite, &saAttr, 0)) + { + WLog_ERR(TAG, "stdin CreatePipe"); + return -1; + } + + if (!SetHandleInformation(plugin->hStdInputWrite, HANDLE_FLAG_INHERIT, 0)) + { + WLog_ERR(TAG, "stdin SetHandleInformation"); + return -1; + } + + // Execute plugin + plugin->commandline = _strdup(plugin->channelEntryPoints.pExtendedData); + if (!CreateProcessA(NULL, + plugin->commandline, // command line + NULL, // process security attributes + NULL, // primary thread security attributes + TRUE, // handles are inherited + 0, // creation flags + NULL, // use parent's environment + NULL, // use parent's current directory + &siStartInfo, // STARTUPINFO pointer + &procInfo // receives PROCESS_INFORMATION + )) + { + WLog_ERR(TAG, "fork for addin"); + return -1; + } + + plugin->hProcess = procInfo.hProcess; + (void)CloseHandle(procInfo.hThread); + (void)CloseHandle(siStartInfo.hStdOutput); + (void)CloseHandle(siStartInfo.hStdInput); + return 0; +} + +static DWORD WINAPI copyThread(void* data) +{ + DWORD status = WAIT_OBJECT_0; + Plugin* plugin = (Plugin*)data; + size_t const bufsize = 16ULL * 1024ULL; + + WINPR_ASSERT(plugin); + + while (status == WAIT_OBJECT_0) + { + + HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 }; + DWORD dwRead = 0; + char* buffer = calloc(bufsize, sizeof(char)); + + if (!buffer) + { + (void)fprintf(stderr, "rdp2tcp copyThread: malloc failed\n"); + goto fail; + } + + // if (!ReadFile(plugin->hStdOutputRead, plugin->buffer, sizeof plugin->buffer, &dwRead, + // NULL)) + if (!ReadFile(plugin->hStdOutputRead, buffer, bufsize, &dwRead, NULL)) + { + free(buffer); + goto fail; + } + + if (plugin->channelEntryPoints.pVirtualChannelWriteEx( + plugin->initHandle, plugin->openHandle, buffer, dwRead, buffer) != CHANNEL_RC_OK) + { + free(buffer); + (void)fprintf(stderr, "rdp2tcp copyThread failed %i\n", (int)dwRead); + goto fail; + } + + handles[0] = plugin->writeComplete; + handles[1] = freerdp_abort_event(plugin->channelEntryPoints.context); + status = WaitForMultipleObjects(2, handles, FALSE, INFINITE); + if (status == WAIT_OBJECT_0) + (void)ResetEvent(plugin->writeComplete); + } + +fail: + ExitThread(0); + return 0; +} + +static void closeChannel(Plugin* plugin) +{ + WINPR_ASSERT(plugin); + WINPR_ASSERT(plugin->channelEntryPoints.pVirtualChannelCloseEx); + plugin->channelEntryPoints.pVirtualChannelCloseEx(plugin->initHandle, plugin->openHandle); +} + +static void dataReceived(Plugin* plugin, void* pData, UINT32 dataLength, UINT32 totalLength, + UINT32 dataFlags) +{ + DWORD dwWritten = 0; + + WINPR_ASSERT(plugin); + + if (dataFlags & CHANNEL_FLAG_SUSPEND) + return; + + if (dataFlags & CHANNEL_FLAG_RESUME) + return; + + if (dataFlags & CHANNEL_FLAG_FIRST) + { + if (!WriteFile(plugin->hStdInputWrite, &totalLength, sizeof(totalLength), &dwWritten, NULL)) + closeChannel(plugin); + } + + if (!WriteFile(plugin->hStdInputWrite, pData, dataLength, &dwWritten, NULL)) + closeChannel(plugin); +} + +static void VCAPITYPE VirtualChannelOpenEventEx(LPVOID lpUserParam, DWORD openHandle, UINT event, + LPVOID pData, UINT32 dataLength, UINT32 totalLength, + UINT32 dataFlags) +{ + Plugin* plugin = (Plugin*)lpUserParam; + + WINPR_ASSERT(plugin); + switch (event) + { + case CHANNEL_EVENT_DATA_RECEIVED: + dataReceived(plugin, pData, dataLength, totalLength, dataFlags); + break; + + case CHANNEL_EVENT_WRITE_CANCELLED: + free(pData); + break; + case CHANNEL_EVENT_WRITE_COMPLETE: + (void)SetEvent(plugin->writeComplete); + free(pData); + break; + default: + break; + } +} + +static void channel_terminated(Plugin* plugin) +{ + if (!plugin) + return; + + if (plugin->copyThread) + (void)TerminateThread(plugin->copyThread, 0); + if (plugin->writeComplete) + (void)CloseHandle(plugin->writeComplete); + + (void)CloseHandle(plugin->hStdInputWrite); + (void)CloseHandle(plugin->hStdOutputRead); + TerminateProcess(plugin->hProcess, 0); + (void)CloseHandle(plugin->hProcess); + free(plugin->commandline); + free(plugin); +} + +static void channel_initialized(Plugin* plugin) +{ + WINPR_ASSERT(plugin); + plugin->writeComplete = CreateEvent(NULL, TRUE, FALSE, NULL); + plugin->copyThread = CreateThread(NULL, 0, copyThread, plugin, 0, NULL); +} + +static VOID VCAPITYPE VirtualChannelInitEventEx(LPVOID lpUserParam, LPVOID pInitHandle, UINT event, + LPVOID pData, UINT dataLength) +{ + Plugin* plugin = (Plugin*)lpUserParam; + + WINPR_ASSERT(plugin); + + switch (event) + { + case CHANNEL_EVENT_INITIALIZED: + channel_initialized(plugin); + break; + + case CHANNEL_EVENT_CONNECTED: + WINPR_ASSERT(plugin); + WINPR_ASSERT(plugin->channelEntryPoints.pVirtualChannelOpenEx); + if (plugin->channelEntryPoints.pVirtualChannelOpenEx( + pInitHandle, &plugin->openHandle, RDP2TCP_DVC_CHANNEL_NAME, + VirtualChannelOpenEventEx) != CHANNEL_RC_OK) + return; + + break; + + case CHANNEL_EVENT_DISCONNECTED: + break; + + case CHANNEL_EVENT_TERMINATED: + channel_terminated(plugin); + break; + default: + break; + } +} + +#define VirtualChannelEntryEx rdp2tcp_VirtualChannelEntryEx +FREERDP_ENTRY_POINT(BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, + PVOID pInitHandle)) +{ + CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx = + (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints; + WINPR_ASSERT(pEntryPointsEx); + WINPR_ASSERT(pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX) && + pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER); + + Plugin* plugin = (Plugin*)calloc(1, sizeof(Plugin)); + + if (!plugin) + return FALSE; + + plugin->initHandle = pInitHandle; + plugin->channelEntryPoints = *pEntryPointsEx; + + if (init_external_addin(plugin) < 0) + { + free(plugin); + return FALSE; + } + + CHANNEL_DEF channelDef = { 0 }; + strncpy(channelDef.name, RDP2TCP_DVC_CHANNEL_NAME, sizeof(channelDef.name)); + channelDef.options = + CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP; + + if (pEntryPointsEx->pVirtualChannelInitEx(plugin, NULL, pInitHandle, &channelDef, 1, + VIRTUAL_CHANNEL_VERSION_WIN2000, + VirtualChannelInitEventEx) != CHANNEL_RC_OK) + return FALSE; + + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpdr/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpdr/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..76326be05f783b189797bd30921177f49dabe442 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpdr/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdpdr") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpdr/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpdr/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6bc5fc2444b03d7648d18029ba8d83f16e40a0ef --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpdr/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "rdpdr" + TYPE + "static" + DESCRIPTION + "Device Redirection Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEFS] [MS-RDPEPC] [MS-RDPESC] [MS-RDPESP]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7de40d6c17bf23a6be803482a2bd7ff904634457 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/CMakeLists.txt @@ -0,0 +1,38 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2023 David Fort +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if(NOT IOS AND NOT WIN32 AND NOT ANDROID) + find_package(KRB5) + + if(KRB5_FOUND) + define_channel("rdpear") + + include_directories(common) + + if(WITH_CLIENT_CHANNELS OR WITH_SERVER_CHANNELS) + add_subdirectory(common) + endif() + + if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) + endif() + + #if(WITH_SERVER_CHANNELS) + # add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) + #endif() + endif() +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..636701d3ec757a639950c87e23ee07cb46bd0329 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT OFF) +set(OPTION_CLIENT_DEFAULT OFF) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options( + NAME + "rdpear" + TYPE + "dynamic" + DESCRIPTION + "Authentication redirection Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEAR]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6f5d1bb8fa25943917e941d10ab83cb96cb11097 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/client/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2023 David Fort +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("rdpear") + +set(${MODULE_PREFIX}_SRCS rdpear_main.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp rdpear-common) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/client/rdpear_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/client/rdpear_main.c new file mode 100644 index 0000000000000000000000000000000000000000..32f07e4e6565a060c05e8881c8fa545aa10034f0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/client/rdpear_main.c @@ -0,0 +1,989 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Authentication redirection virtual channel + * + * Copyright 2023 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("rdpear.client") + +/* defined in libkrb5 */ +krb5_error_code encode_krb5_authenticator(const krb5_authenticator* rep, krb5_data** code_out); +krb5_error_code encode_krb5_ap_rep(const krb5_ap_rep* rep, krb5_data** code_out); + +typedef struct +{ + GENERIC_DYNVC_PLUGIN base; + rdpContext* rdp_context; + krb5_context krbContext; +} RDPEAR_PLUGIN; + +static const BYTE payloadHeader[16] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + +static krb5_error_code RPC_ENCRYPTION_KEY_to_keyblock(krb5_context ctx, + const KERB_RPC_ENCRYPTION_KEY* key, + krb5_keyblock** pkeyblock) +{ + WINPR_ASSERT(ctx); + WINPR_ASSERT(key); + WINPR_ASSERT(pkeyblock); + + if (!key->reserved3.length) + return KRB5KDC_ERR_NULL_KEY; + + krb5_error_code rv = + krb5_init_keyblock(ctx, (krb5_enctype)key->reserved2, key->reserved3.length, pkeyblock); + if (rv) + return rv; + + krb5_keyblock* keyblock = *pkeyblock; + memcpy(keyblock->contents, key->reserved3.value, key->reserved3.length); + return rv; +} + +static krb5_error_code kerb_do_checksum(krb5_context ctx, const KERB_RPC_ENCRYPTION_KEY* key, + krb5_keyusage kusage, krb5_cksumtype cksumtype, + const KERB_ASN1_DATA* plain, krb5_checksum* out) +{ + WINPR_ASSERT(ctx); + WINPR_ASSERT(key); + WINPR_ASSERT(plain); + WINPR_ASSERT(out); + + krb5_keyblock* keyblock = NULL; + krb5_data data = { 0 }; + + krb5_error_code rv = RPC_ENCRYPTION_KEY_to_keyblock(ctx, key, &keyblock); + if (rv) + return rv; + + data.data = (char*)plain->Asn1Buffer; + data.length = plain->Asn1BufferHints.count; + + rv = krb5_c_make_checksum(ctx, cksumtype, keyblock, kusage, &data, out); + + krb5_free_keyblock(ctx, keyblock); + return rv; +} + +static krb5_error_code kerb_do_encrypt(krb5_context ctx, const KERB_RPC_ENCRYPTION_KEY* key, + krb5_keyusage kusage, const KERB_ASN1_DATA* plain, + krb5_data* out) +{ + WINPR_ASSERT(ctx); + WINPR_ASSERT(key); + WINPR_ASSERT(plain); + WINPR_ASSERT(out); + + krb5_keyblock* keyblock = NULL; + krb5_data data = { 0 }; + krb5_enc_data enc = { 0 }; + size_t elen = 0; + + krb5_error_code rv = RPC_ENCRYPTION_KEY_to_keyblock(ctx, key, &keyblock); + if (rv) + return rv; + + data.data = (char*)plain->Asn1Buffer; + data.length = plain->Asn1BufferHints.count; + + rv = krb5_c_encrypt_length(ctx, keyblock->enctype, data.length, &elen); + if (rv) + goto out; + if (!elen || (elen > UINT32_MAX)) + { + rv = KRB5_PARSE_MALFORMED; + goto out; + } + enc.ciphertext.length = (unsigned int)elen; + enc.ciphertext.data = malloc(elen); + if (!enc.ciphertext.data) + { + rv = ENOMEM; + goto out; + } + + rv = krb5_c_encrypt(ctx, keyblock, kusage, NULL, &data, &enc); + + out->data = enc.ciphertext.data; + out->length = enc.ciphertext.length; +out: + krb5_free_keyblock(ctx, keyblock); + return rv; +} + +static krb5_error_code kerb_do_decrypt(krb5_context ctx, const KERB_RPC_ENCRYPTION_KEY* key, + krb5_keyusage kusage, const krb5_data* cipher, + KERB_ASN1_DATA* plain) +{ + WINPR_ASSERT(ctx); + WINPR_ASSERT(key); + WINPR_ASSERT(cipher); + WINPR_ASSERT(cipher->length); + WINPR_ASSERT(plain); + + krb5_keyblock* keyblock = NULL; + krb5_data data = { 0 }; + krb5_enc_data enc = { 0 }; + + krb5_error_code rv = RPC_ENCRYPTION_KEY_to_keyblock(ctx, key, &keyblock); + if (rv) + return rv; + + enc.kvno = KRB5_PVNO; + enc.enctype = (krb5_enctype)key->reserved2; + enc.ciphertext.length = cipher->length; + enc.ciphertext.data = cipher->data; + + data.length = cipher->length; + data.data = (char*)malloc(cipher->length); + if (!data.data) + { + rv = ENOMEM; + goto out; + } + + rv = krb5_c_decrypt(ctx, keyblock, kusage, NULL, &enc, &data); + + plain->Asn1Buffer = (BYTE*)data.data; + plain->Asn1BufferHints.count = data.length; +out: + krb5_free_keyblock(ctx, keyblock); + return rv; +} + +static BOOL rdpear_send_payload(RDPEAR_PLUGIN* rdpear, IWTSVirtualChannelCallback* pChannelCallback, + RdpEarPackageType packageType, wStream* payload) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + BOOL ret = FALSE; + wStream* finalStream = NULL; + SecBuffer cryptedBuffer = { 0 }; + wStream* unencodedContent = rdpear_encodePayload(packageType, payload); + if (!unencodedContent) + goto out; + + const size_t unencodedLen = Stream_GetPosition(unencodedContent); + +#if UINT32_MAX < SIZE_MAX + if (unencodedLen > UINT32_MAX) + goto out; +#endif + + SecBuffer inBuffer = { (ULONG)unencodedLen, SECBUFFER_DATA, Stream_Buffer(unencodedContent) }; + + if (!freerdp_nla_encrypt(rdpear->rdp_context, &inBuffer, &cryptedBuffer)) + goto out; + + finalStream = Stream_New(NULL, 200); + if (!finalStream) + goto out; + Stream_Write_UINT32(finalStream, 0x4EACC3C8); /* ProtocolMagic (4 bytes) */ + Stream_Write_UINT32(finalStream, cryptedBuffer.cbBuffer); /* Length (4 bytes) */ + Stream_Write_UINT32(finalStream, 0x00000000); /* Version (4 bytes) */ + Stream_Write_UINT32(finalStream, 0x00000000); /* Reserved (4 bytes) */ + Stream_Write_UINT64(finalStream, 0); /* TsPkgContext (8 bytes) */ + + /* payload */ + if (!Stream_EnsureRemainingCapacity(finalStream, cryptedBuffer.cbBuffer)) + goto out; + + Stream_Write(finalStream, cryptedBuffer.pvBuffer, cryptedBuffer.cbBuffer); + + const size_t pos = Stream_GetPosition(finalStream); +#if UINT32_MAX < SIZE_MAX + if (pos > UINT32_MAX) + goto out; +#endif + + UINT status = + callback->channel->Write(callback->channel, (ULONG)pos, Stream_Buffer(finalStream), NULL); + ret = (status == CHANNEL_RC_OK); + if (!ret) + WLog_DBG(TAG, "rdpear_send_payload=0x%x", status); +out: + sspi_SecBufferFree(&cryptedBuffer); + Stream_Free(unencodedContent, TRUE); + Stream_Free(finalStream, TRUE); + return ret; +} + +static BOOL rdpear_prepare_response(NdrContext* rcontext, UINT16 callId, UINT32 status, + NdrContext** pwcontext, wStream* retStream) +{ + WINPR_ASSERT(rcontext); + WINPR_ASSERT(pwcontext); + + BOOL ret = FALSE; + *pwcontext = NULL; + NdrContext* wcontext = ndr_context_copy(rcontext); + if (!wcontext) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(retStream, sizeof(payloadHeader))) + goto out; + + Stream_Write(retStream, payloadHeader, sizeof(payloadHeader)); + + if (!ndr_write_header(wcontext, retStream) || !ndr_start_constructed(wcontext, retStream) || + !ndr_write_pickle(wcontext, retStream) || /* pickle header */ + !ndr_write_uint16(wcontext, retStream, callId) || /* callId */ + !ndr_write_uint16(wcontext, retStream, 0x0000) || /* align padding */ + !ndr_write_uint32(wcontext, retStream, status) || /* status */ + !ndr_write_uint16(wcontext, retStream, callId) || /* callId */ + !ndr_write_uint16(wcontext, retStream, 0x0000)) /* align padding */ + goto out; + + *pwcontext = wcontext; + ret = TRUE; +out: + if (!ret) + ndr_context_destroy(&wcontext); + return ret; +} + +static BOOL rdpear_kerb_version(NdrContext* rcontext, wStream* s, UINT32* pstatus, UINT32* pversion) +{ + *pstatus = ERROR_INVALID_DATA; + + if (!ndr_read_uint32(rcontext, s, pversion)) + return TRUE; + + WLog_DBG(TAG, "-> KerbNegotiateVersion(v=0x%x)", *pversion); + *pstatus = 0; + + return TRUE; +} + +static BOOL rdpear_kerb_ComputeTgsChecksum(RDPEAR_PLUGIN* rdpear, NdrContext* rcontext, wStream* s, + UINT32* pstatus, KERB_ASN1_DATA* resp) +{ + ComputeTgsChecksumReq req = { 0 }; + krb5_checksum checksum = { 0 }; + wStream* asn1Payload = NULL; + + *pstatus = ERROR_INVALID_DATA; + WLog_DBG(TAG, "-> ComputeTgsChecksum"); + + if (!ndr_read_ComputeTgsChecksumReq(rcontext, s, NULL, &req) || + !ndr_treat_deferred_read(rcontext, s)) + goto out; + // ComputeTgsChecksumReq_dump(WLog_Get(""), WLOG_DEBUG, &req); + + krb5_error_code rv = + kerb_do_checksum(rdpear->krbContext, req.Key, KRB5_KEYUSAGE_TGS_REQ_AUTH_CKSUM, + (krb5_cksumtype)req.ChecksumType, req.requestBody, &checksum); + if (rv) + goto out; + + asn1Payload = rdpear_enc_Checksum(req.ChecksumType, &checksum); + if (!asn1Payload) + goto out; + + resp->Pdu = 8; + resp->Asn1Buffer = Stream_Buffer(asn1Payload); + const size_t pos = Stream_GetPosition(asn1Payload); + if (pos > UINT32_MAX) + goto out; + resp->Asn1BufferHints.count = (UINT32)pos; + *pstatus = 0; + +out: + ndr_destroy_ComputeTgsChecksumReq(rcontext, NULL, &req); + krb5_free_checksum_contents(rdpear->krbContext, &checksum); + Stream_Free(asn1Payload, FALSE); + return TRUE; +} + +static BOOL rdpear_kerb_BuildEncryptedAuthData(RDPEAR_PLUGIN* rdpear, NdrContext* rcontext, + wStream* s, UINT32* pstatus, KERB_ASN1_DATA* asn1) +{ + BuildEncryptedAuthDataReq req = { 0 }; + krb5_data encrypted = { 0 }; + wStream* asn1Payload = NULL; + krb5_error_code rv = 0; + + *pstatus = ERROR_INVALID_DATA; + WLog_DBG(TAG, "-> BuildEncryptedAuthData"); + + if (!ndr_read_BuildEncryptedAuthDataReq(rcontext, s, NULL, &req) || + !ndr_treat_deferred_read(rcontext, s)) + goto out; + + rv = kerb_do_encrypt(rdpear->krbContext, req.Key, (krb5_keyusage)req.KeyUsage, + req.PlainAuthData, &encrypted); + if (rv) + goto out; + + /* do the encoding */ + asn1Payload = rdpear_enc_EncryptedData(req.Key->reserved2, &encrypted); + if (!asn1Payload) + goto out; + + // WLog_DBG(TAG, "rdpear_kerb_BuildEncryptedAuthData resp="); + // winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(asn1Payload), Stream_GetPosition(asn1Payload)); + asn1->Pdu = 6; + asn1->Asn1Buffer = Stream_Buffer(asn1Payload); + const size_t pos = Stream_GetPosition(asn1Payload); + if (pos > UINT32_MAX) + goto out; + asn1->Asn1BufferHints.count = (UINT32)pos; + *pstatus = 0; + +out: + krb5_free_data_contents(rdpear->krbContext, &encrypted); + ndr_destroy_BuildEncryptedAuthDataReq(rcontext, NULL, &req); + Stream_Free(asn1Payload, FALSE); + return TRUE; +} + +static char* KERB_RPC_UNICODESTR_to_charptr(const RPC_UNICODE_STRING* src) +{ + WINPR_ASSERT(src); + return ConvertWCharNToUtf8Alloc(src->Buffer, src->strLength, NULL); +} + +static BOOL extractAuthData(const KERB_ASN1_DATA* src, krb5_authdata* authData, BOOL* haveData) +{ + WinPrAsn1Decoder dec = { 0 }; + WinPrAsn1Decoder dec2 = { 0 }; + WinPrAsn1Decoder dec3 = { 0 }; + WinPrAsn1Decoder_InitMem(&dec, WINPR_ASN1_DER, src->Asn1Buffer, src->Asn1BufferHints.count); + BOOL error = FALSE; + WinPrAsn1_INTEGER adType = 0; + WinPrAsn1_OctetString os = { 0 }; + + *haveData = FALSE; + if (!WinPrAsn1DecReadSequence(&dec, &dec2)) + return FALSE; + + wStream subStream = WinPrAsn1DecGetStream(&dec2); + if (!Stream_GetRemainingLength(&subStream)) + return TRUE; + + if (!WinPrAsn1DecReadSequence(&dec2, &dec3)) + return FALSE; + + if (!WinPrAsn1DecReadContextualInteger(&dec3, 0, &error, &adType) || + !WinPrAsn1DecReadContextualOctetString(&dec3, 1, &error, &os, FALSE)) + return FALSE; + + if (os.len > UINT32_MAX) + return FALSE; + + authData->ad_type = adType; + authData->length = (unsigned int)os.len; + authData->contents = os.data; + *haveData = TRUE; + return TRUE; +} + +static BOOL extractChecksum(const KERB_ASN1_DATA* src, krb5_checksum* dst) +{ + WinPrAsn1Decoder dec = { 0 }; + WinPrAsn1Decoder dec2 = { 0 }; + WinPrAsn1Decoder_InitMem(&dec, WINPR_ASN1_DER, src->Asn1Buffer, src->Asn1BufferHints.count); + BOOL error = FALSE; + WinPrAsn1_OctetString os; + + if (!WinPrAsn1DecReadSequence(&dec, &dec2)) + return FALSE; + + WinPrAsn1_INTEGER cksumtype = 0; + if (!WinPrAsn1DecReadContextualInteger(&dec2, 0, &error, &cksumtype) || + !WinPrAsn1DecReadContextualOctetString(&dec2, 1, &error, &os, FALSE)) + return FALSE; + + if (os.len > UINT32_MAX) + return FALSE; + dst->checksum_type = cksumtype; + dst->length = (unsigned int)os.len; + dst->contents = os.data; + return TRUE; +} + +#define FILETIME_TO_UNIX_OFFSET_S 11644473600LL + +static LONGLONG krb5_time_to_FILETIME(const krb5_timestamp* ts, krb5_int32 usec) +{ + WINPR_ASSERT(ts); + return (((*ts + FILETIME_TO_UNIX_OFFSET_S) * (1000LL * 1000LL) + usec) * 10LL); +} + +static void krb5_free_principal_contents(krb5_context ctx, krb5_principal principal) +{ + WINPR_ASSERT(principal); + krb5_free_data_contents(ctx, &principal->realm); + krb5_free_data(ctx, principal->data); +} + +static BOOL rdpear_kerb_CreateApReqAuthenticator(RDPEAR_PLUGIN* rdpear, NdrContext* rcontext, + wStream* s, UINT32* pstatus, + CreateApReqAuthenticatorResp* resp) +{ + krb5_error_code rv = 0; + wStream* asn1EncodedAuth = NULL; + CreateApReqAuthenticatorReq req = { 0 }; + krb5_data authenticator = { 0 }; + krb5_data* der = NULL; + krb5_keyblock* subkey = NULL; + krb5_principal_data client = { 0 }; + + *pstatus = ERROR_INVALID_DATA; + WLog_DBG(TAG, "-> CreateApReqAuthenticator"); + + if (!ndr_read_CreateApReqAuthenticatorReq(rcontext, s, NULL, &req) || + !ndr_treat_deferred_read(rcontext, s)) + goto out; + + krb5_authdata authdata = { 0 }; + krb5_authdata* authDataPtr[2] = { &authdata, NULL }; + BOOL haveData = 0; + + if (!extractAuthData(req.AuthData, &authdata, &haveData)) + { + WLog_ERR(TAG, "error retrieving auth data"); + winpr_HexDump(TAG, WLOG_DEBUG, req.AuthData->Asn1Buffer, + req.AuthData->Asn1BufferHints.count); + goto out; + } + + if (req.SkewTime->QuadPart) + { + WLog_ERR(TAG, "!!!!! should handle SkewTime !!!!!"); + } + + if (req.SubKey) + { + rv = RPC_ENCRYPTION_KEY_to_keyblock(rdpear->krbContext, req.SubKey, &subkey); + if (rv) + { + WLog_ERR(TAG, "error importing subkey"); + goto out; + } + } + + krb5_authenticator authent = { .checksum = NULL, + .subkey = NULL, + .seq_number = req.SequenceNumber, + .authorization_data = haveData ? authDataPtr : NULL }; + + client.type = req.ClientName->NameType; + if (req.ClientName->nameHints.count > INT32_MAX) + goto out; + + client.length = (krb5_int32)req.ClientName->nameHints.count; + client.data = calloc(req.ClientName->nameHints.count, sizeof(krb5_data)); + if (!client.data) + goto out; + + for (int i = 0; i < client.length; i++) + { + client.data[i].data = KERB_RPC_UNICODESTR_to_charptr(&req.ClientName->Names[i]); + if (!client.data[i].data) + goto out; + client.data[i].length = (unsigned int)strnlen(client.data[i].data, UINT32_MAX); + } + client.realm.data = KERB_RPC_UNICODESTR_to_charptr(req.ClientRealm); + if (!client.realm.data) + goto out; + client.realm.length = (unsigned int)strnlen(client.realm.data, UINT32_MAX); + authent.client = &client; + + krb5_checksum checksum; + krb5_checksum* pchecksum = NULL; + if (req.GssChecksum) + { + if (!extractChecksum(req.GssChecksum, &checksum)) + { + WLog_ERR(TAG, "Error getting the checksum"); + goto out; + } + pchecksum = &checksum; + } + authent.checksum = pchecksum; + + krb5_us_timeofday(rdpear->krbContext, &authent.ctime, &authent.cusec); + + rv = encode_krb5_authenticator(&authent, &der); + if (rv) + { + WLog_ERR(TAG, "error encoding authenticator"); + goto out; + } + + KERB_ASN1_DATA plain_authent = { .Pdu = 0, + .Asn1Buffer = (BYTE*)der->data, + .Asn1BufferHints = { .count = der->length } }; + + rv = kerb_do_encrypt(rdpear->krbContext, req.EncryptionKey, (krb5_keyusage)req.KeyUsage, + &plain_authent, &authenticator); + if (rv) + { + WLog_ERR(TAG, "error encrypting authenticator"); + goto out; + } + + asn1EncodedAuth = rdpear_enc_EncryptedData(req.EncryptionKey->reserved2, &authenticator); + if (!asn1EncodedAuth) + { + WLog_ERR(TAG, "error encoding to ASN1"); + rv = ENOMEM; + goto out; + } + + // WLog_DBG(TAG, "authenticator="); + // winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(asn1EncodedAuth), + // Stream_GetPosition(asn1EncodedAuth)); + + const size_t size = Stream_GetPosition(asn1EncodedAuth); + if (size > UINT32_MAX) + goto out; + resp->Authenticator.Asn1BufferHints.count = (UINT32)size; + resp->Authenticator.Asn1Buffer = Stream_Buffer(asn1EncodedAuth); + resp->AuthenticatorTime.QuadPart = krb5_time_to_FILETIME(&authent.ctime, authent.cusec); + *pstatus = 0; + +out: + resp->Authenticator.Pdu = 6; + resp->KerbProtocolError = rv; + krb5_free_principal_contents(rdpear->krbContext, &client); + krb5_free_data(rdpear->krbContext, der); + krb5_free_data_contents(rdpear->krbContext, &authenticator); + if (subkey) + krb5_free_keyblock(rdpear->krbContext, subkey); + ndr_destroy_CreateApReqAuthenticatorReq(rcontext, NULL, &req); + Stream_Free(asn1EncodedAuth, FALSE); + return TRUE; +} + +static BOOL rdpear_findEncryptedData(const KERB_ASN1_DATA* src, int* penctype, krb5_data* data) +{ + WinPrAsn1Decoder dec = { 0 }; + WinPrAsn1Decoder dec2 = { 0 }; + WinPrAsn1Decoder_InitMem(&dec, WINPR_ASN1_DER, src->Asn1Buffer, src->Asn1BufferHints.count); + BOOL error = FALSE; + WinPrAsn1_INTEGER encType = 0; + WinPrAsn1_OctetString os = { 0 }; + + if (!WinPrAsn1DecReadSequence(&dec, &dec2) || + !WinPrAsn1DecReadContextualInteger(&dec2, 0, &error, &encType) || + !WinPrAsn1DecReadContextualOctetString(&dec2, 2, &error, &os, FALSE)) + return FALSE; + + if (os.len > UINT32_MAX) + return FALSE; + data->data = (char*)os.data; + data->length = (unsigned int)os.len; + *penctype = encType; + return TRUE; +} + +static BOOL rdpear_kerb_UnpackKdcReplyBody(RDPEAR_PLUGIN* rdpear, NdrContext* rcontext, wStream* s, + UINT32* pstatus, UnpackKdcReplyBodyResp* resp) +{ + UnpackKdcReplyBodyReq req = { 0 }; + + *pstatus = ERROR_INVALID_DATA; + + if (!ndr_read_UnpackKdcReplyBodyReq(rcontext, s, NULL, &req) || + !ndr_treat_deferred_read(rcontext, s)) + goto out; + + if (req.StrengthenKey) + { + WLog_ERR(TAG, "StrengthenKey not supported yet"); + goto out; + } + + WLog_DBG(TAG, "-> UnpackKdcReplyBody: KeyUsage=0x%x PDU=0x%x", req.KeyUsage, req.Pdu); + // WLog_DBG(TAG, "encryptedPayload="); + // winpr_HexDump(TAG, WLOG_DEBUG, req.EncryptedData->Asn1Buffer, + // req.EncryptedData->Asn1BufferHints.count); + + krb5_data asn1Data = { 0 }; + int encType = 0; + if (!rdpear_findEncryptedData(req.EncryptedData, &encType, &asn1Data) || !asn1Data.length) + goto out; + + resp->KerbProtocolError = kerb_do_decrypt( + rdpear->krbContext, req.Key, (krb5_keyusage)req.KeyUsage, &asn1Data, &resp->ReplyBody); + resp->ReplyBody.Pdu = req.Pdu; + + *pstatus = 0; + +out: + ndr_destroy_UnpackKdcReplyBodyReq(rcontext, NULL, &req); + return TRUE; +} + +static BOOL rdpear_kerb_DecryptApReply(RDPEAR_PLUGIN* rdpear, NdrContext* rcontext, wStream* s, + UINT32* pstatus, KERB_ASN1_DATA* resp) +{ + DecryptApReplyReq req = { 0 }; + + *pstatus = ERROR_INVALID_DATA; + if (!ndr_read_DecryptApReplyReq(rcontext, s, NULL, &req) || + !ndr_treat_deferred_read(rcontext, s)) + goto out; + + WLog_DBG(TAG, "-> DecryptApReply"); + // winpr_HexDump(TAG, WLOG_DEBUG, req.EncryptedReply->Asn1Buffer, + // req.EncryptedReply->Asn1BufferHints.count); + + krb5_data asn1Data = { 0 }; + int encType = 0; + if (!rdpear_findEncryptedData(req.EncryptedReply, &encType, &asn1Data) || !asn1Data.length) + goto out; + + resp->Pdu = 0x31; + krb5_error_code rv = + kerb_do_decrypt(rdpear->krbContext, req.Key, KRB5_KEYUSAGE_AP_REP_ENCPART, &asn1Data, resp); + if (rv != 0) + { + WLog_ERR(TAG, "error decrypting"); + goto out; + } + + // WLog_DBG(TAG, "response="); + // winpr_HexDump(TAG, WLOG_DEBUG, resp->Asn1Buffer, resp->Asn1BufferHints.count); + *pstatus = 0; +out: + ndr_destroy_DecryptApReplyReq(rcontext, NULL, &req); + return TRUE; +} + +static BOOL rdpear_kerb_PackApReply(RDPEAR_PLUGIN* rdpear, NdrContext* rcontext, wStream* s, + UINT32* pstatus, PackApReplyResp* resp) +{ + PackApReplyReq req = { 0 }; + krb5_data asn1Data = { 0 }; + krb5_data* out = NULL; + + WLog_DBG(TAG, "-> PackApReply"); + *pstatus = ERROR_INVALID_DATA; + if (!ndr_read_PackApReplyReq(rcontext, s, NULL, &req) || !ndr_treat_deferred_read(rcontext, s)) + goto out; + + krb5_error_code rv = kerb_do_encrypt(rdpear->krbContext, req.SessionKey, + KRB5_KEYUSAGE_AP_REP_ENCPART, req.ReplyBody, &asn1Data); + if (rv) + goto out; + + krb5_ap_rep reply; + reply.enc_part.kvno = KRB5_PVNO; + reply.enc_part.enctype = (krb5_enctype)req.SessionKey->reserved2; + reply.enc_part.ciphertext.length = asn1Data.length; + reply.enc_part.ciphertext.data = asn1Data.data; + + rv = encode_krb5_ap_rep(&reply, &out); + if (rv) + goto out; + + resp->PackedReply = (BYTE*)out->data; + resp->PackedReplyHints.count = out->length; + *pstatus = 0; +out: + free(out); + krb5_free_data_contents(rdpear->krbContext, &asn1Data); + ndr_destroy_PackApReplyReq(rcontext, NULL, &req); + return TRUE; +} + +static UINT rdpear_decode_payload(RDPEAR_PLUGIN* rdpear, + IWTSVirtualChannelCallback* pChannelCallback, wStream* s) +{ + UINT ret = ERROR_INVALID_DATA; + NdrContext* context = NULL; + NdrContext* wcontext = NULL; + UINT32 status = 0; + + UINT32 uint32Resp = 0; + KERB_ASN1_DATA asn1Data = { 0 }; + CreateApReqAuthenticatorResp createApReqAuthenticatorResp = { 0 }; + UnpackKdcReplyBodyResp unpackKdcReplyBodyResp = { 0 }; + PackApReplyResp packApReplyResp = { 0 }; + + void* resp = NULL; + NdrMessageType respDescr = NULL; + + wStream* respStream = Stream_New(NULL, 500); + if (!respStream) + goto out; + + Stream_Seek(s, 16); /* skip first 16 bytes */ + + wStream commandStream = { 0 }; + UINT16 callId = 0; + UINT16 callId2 = 0; + + context = ndr_read_header(s); + if (!context || !ndr_read_constructed(context, s, &commandStream) || + !ndr_read_pickle(context, &commandStream) || + !ndr_read_uint16(context, &commandStream, &callId) || + !ndr_read_uint16(context, &commandStream, &callId2) || (callId != callId2)) + goto out; + + ret = CHANNEL_RC_NOT_OPEN; + switch (callId) + { + case RemoteCallKerbNegotiateVersion: + resp = &uint32Resp; + respDescr = ndr_uint32_descr(); + + if (rdpear_kerb_version(context, &commandStream, &status, &uint32Resp)) + ret = CHANNEL_RC_OK; + break; + case RemoteCallKerbCreateApReqAuthenticator: + resp = &createApReqAuthenticatorResp; + respDescr = ndr_CreateApReqAuthenticatorResp_descr(); + + if (rdpear_kerb_CreateApReqAuthenticator(rdpear, context, &commandStream, &status, + &createApReqAuthenticatorResp)) + ret = CHANNEL_RC_OK; + break; + case RemoteCallKerbDecryptApReply: + resp = &asn1Data; + respDescr = ndr_KERB_ASN1_DATA_descr(); + + if (rdpear_kerb_DecryptApReply(rdpear, context, &commandStream, &status, &asn1Data)) + ret = CHANNEL_RC_OK; + break; + case RemoteCallKerbComputeTgsChecksum: + resp = &asn1Data; + respDescr = ndr_KERB_ASN1_DATA_descr(); + + if (rdpear_kerb_ComputeTgsChecksum(rdpear, context, &commandStream, &status, &asn1Data)) + ret = CHANNEL_RC_OK; + break; + case RemoteCallKerbBuildEncryptedAuthData: + resp = &asn1Data; + respDescr = ndr_KERB_ASN1_DATA_descr(); + + if (rdpear_kerb_BuildEncryptedAuthData(rdpear, context, &commandStream, &status, + &asn1Data)) + ret = CHANNEL_RC_OK; + break; + case RemoteCallKerbUnpackKdcReplyBody: + resp = &unpackKdcReplyBodyResp; + respDescr = ndr_UnpackKdcReplyBodyResp_descr(); + + if (rdpear_kerb_UnpackKdcReplyBody(rdpear, context, &commandStream, &status, + &unpackKdcReplyBodyResp)) + ret = CHANNEL_RC_OK; + break; + case RemoteCallKerbPackApReply: + resp = &packApReplyResp; + respDescr = ndr_PackApReplyResp_descr(); + + if (rdpear_kerb_PackApReply(rdpear, context, &commandStream, &status, &packApReplyResp)) + ret = CHANNEL_RC_OK; + break; + + case RemoteCallNtlmNegotiateVersion: + WLog_ERR(TAG, "don't wanna support NTLM"); + break; + + default: + WLog_DBG(TAG, "Unhandled callId=0x%x", callId); + winpr_HexDump(TAG, WLOG_DEBUG, Stream_PointerAs(&commandStream, BYTE), + Stream_GetRemainingLength(&commandStream)); + break; + } + + if (!rdpear_prepare_response(context, callId, status, &wcontext, respStream)) + goto out; + + if (resp && respDescr) + { + WINPR_ASSERT(respDescr->writeFn); + + BOOL r = respDescr->writeFn(wcontext, respStream, NULL, resp) && + ndr_treat_deferred_write(wcontext, respStream); + + if (respDescr->destroyFn) + respDescr->destroyFn(wcontext, NULL, resp); + + if (!r) + { + WLog_DBG(TAG, "!writeFn || !ndr_treat_deferred_write"); + goto out; + } + } + + if (!ndr_end_constructed(wcontext, respStream) || + !rdpear_send_payload(rdpear, pChannelCallback, RDPEAR_PACKAGE_KERBEROS, respStream)) + { + WLog_DBG(TAG, "rdpear_send_payload !!!!!!!!"); + goto out; + } +out: + if (context) + ndr_context_destroy(&context); + + if (wcontext) + ndr_context_destroy(&wcontext); + + if (respStream) + Stream_Free(respStream, TRUE); + return ret; +} + +static UINT rdpear_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* s) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + WINPR_ASSERT(callback); + UINT ret = ERROR_INVALID_DATA; + + // winpr_HexDump(TAG, WLOG_DEBUG, Stream_PointerAs(s, BYTE), Stream_GetRemainingLength(s)); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 24)) + return ERROR_INVALID_DATA; + + UINT32 protocolMagic = 0; + UINT32 Length = 0; + UINT32 Version = 0; + Stream_Read_UINT32(s, protocolMagic); + if (protocolMagic != 0x4EACC3C8) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, Length); + + Stream_Read_UINT32(s, Version); + if (Version != 0x00000000) + return ERROR_INVALID_DATA; + + Stream_Seek(s, 4); /* Reserved (4 bytes) */ + Stream_Seek(s, 8); /* TsPkgContext (8 bytes) */ + + if (!Stream_CheckAndLogRequiredLength(TAG, s, Length)) + return ERROR_INVALID_DATA; + + SecBuffer inBuffer = { Length, SECBUFFER_TOKEN, Stream_PointerAs(s, void) }; + SecBuffer decrypted = { 0 }; + + RDPEAR_PLUGIN* rdpear = (RDPEAR_PLUGIN*)callback->plugin; + WINPR_ASSERT(rdpear); + if (!freerdp_nla_decrypt(rdpear->rdp_context, &inBuffer, &decrypted)) + goto out; + + WinPrAsn1Decoder dec = { 0 }; + WinPrAsn1Decoder dec2 = { 0 }; + wStream decodedStream = { 0 }; + Stream_StaticInit(&decodedStream, decrypted.pvBuffer, decrypted.cbBuffer); + WinPrAsn1Decoder_Init(&dec, WINPR_ASN1_DER, &decodedStream); + + if (!WinPrAsn1DecReadSequence(&dec, &dec2)) + goto out; + + WinPrAsn1_OctetString packageName = { 0 }; + WinPrAsn1_OctetString payload = { 0 }; + BOOL error = 0; + if (!WinPrAsn1DecReadContextualOctetString(&dec2, 1, &error, &packageName, FALSE)) + goto out; + + if (!WinPrAsn1DecReadContextualOctetString(&dec2, 2, &error, &payload, FALSE)) + goto out; + + wStream payloadStream = { 0 }; + Stream_StaticInit(&payloadStream, payload.data, payload.len); + + ret = rdpear_decode_payload(rdpear, pChannelCallback, &payloadStream); +out: + sspi_SecBufferFree(&decrypted); + return ret; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpear_on_open(IWTSVirtualChannelCallback* pChannelCallback) +{ + WINPR_UNUSED(pChannelCallback); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpear_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + WINPR_UNUSED(pChannelCallback); + return CHANNEL_RC_OK; +} + +static void terminate_plugin_cb(GENERIC_DYNVC_PLUGIN* base) +{ + WINPR_ASSERT(base); + + RDPEAR_PLUGIN* rdpear = (RDPEAR_PLUGIN*)base; + krb5_free_context(rdpear->krbContext); +} + +static UINT init_plugin_cb(GENERIC_DYNVC_PLUGIN* base, rdpContext* rcontext, rdpSettings* settings) +{ + WINPR_ASSERT(base); + WINPR_UNUSED(settings); + + RDPEAR_PLUGIN* rdpear = (RDPEAR_PLUGIN*)base; + rdpear->rdp_context = rcontext; + if (krb5_init_context(&rdpear->krbContext)) + return CHANNEL_RC_INITIALIZATION_ERROR; + return CHANNEL_RC_OK; +} + +static const IWTSVirtualChannelCallback rdpear_callbacks = { rdpear_on_data_received, + rdpear_on_open, rdpear_on_close, + NULL }; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT rdpear_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, RDPEAR_DVC_CHANNEL_NAME, + sizeof(RDPEAR_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK), + &rdpear_callbacks, init_plugin_cb, terminate_plugin_cb); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..654940b014403038285899daf4b2f031af4c9364 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/CMakeLists.txt @@ -0,0 +1,37 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2024 David Fort +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_library(rdpear-common INTERFACE) +add_library( + rdpear-common-obj OBJECT ndr.c rdpear_asn1.c rdpear_common.c rdpear-common/ndr.h rdpear-common/rdpear_asn1.h + rdpear-common/rdpear_common.h +) + +target_include_directories(rdpear-common SYSTEM INTERFACE ${KRB5_INCLUDE_DIRS}) +target_compile_options(rdpear-common INTERFACE ${KRB5_CFLAGS}) +target_link_options(rdpear-common INTERFACE ${KRB5_LDFLAGS}) + +target_include_directories(rdpear-common-obj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) +target_include_directories(rdpear-common-obj SYSTEM PRIVATE ${KRB5_INCLUDE_DIRS}) +target_link_directories(rdpear-common INTERFACE ${KRB5_LIBRARY_DIRS}) +target_link_libraries(rdpear-common INTERFACE ${KRB5_LIBRARIES} $) + +channel_install(rdpear-common ${FREERDP_ADDIN_PATH} "FreeRDPTargets") + +if(BUILD_TESTING_INTERNAL OR BUILD_TESTING) + add_subdirectory(test) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/ndr.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/ndr.c new file mode 100644 index 0000000000000000000000000000000000000000..9d4df2940a13c93bbeebc1e1b9877a07442079cc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/ndr.c @@ -0,0 +1,994 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Authentication redirection virtual channel + * + * Copyright 2024 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +#include + +#include + +#define TAG FREERDP_TAG("ndr") + +#define NDR_MAX_CONSTRUCTS 16 +#define NDR_MAX_DEFERRED 50 + +struct NdrContext_s +{ + BYTE version; + BOOL bigEndianDrep; + size_t alignBytes; + + int currentLevel; + size_t indentLevels[16]; + + int constructLevel; + size_t constructs[NDR_MAX_CONSTRUCTS]; + + wHashTable* refPointers; + size_t ndeferred; + NdrDeferredEntry deferred[NDR_MAX_DEFERRED]; + + UINT32 refIdCounter; +}; + +NdrContext* ndr_context_new(BOOL bigEndianDrep, BYTE version) +{ + NdrContext* ret = calloc(1, sizeof(*ret)); + if (!ret) + return NULL; + + ret->version = version; + ret->bigEndianDrep = bigEndianDrep; + ret->alignBytes = 4; + ret->refPointers = HashTable_New(FALSE); + if (!ret->refPointers) + { + free(ret); + return NULL; + } + + ndr_context_reset(ret); + return ret; +} + +void ndr_context_reset(NdrContext* context) +{ + WINPR_ASSERT(context); + + context->currentLevel = 0; + context->constructLevel = -1; + memset(context->indentLevels, 0, sizeof(context->indentLevels)); + + if (context->refPointers) + HashTable_Clear(context->refPointers); + context->ndeferred = 0; + context->refIdCounter = 0x20000; +} + +NdrContext* ndr_context_copy(const NdrContext* src) +{ + WINPR_ASSERT(src); + + NdrContext* ret = calloc(1, sizeof(*ret)); + if (!ret) + return NULL; + + *ret = *src; + + ret->refPointers = HashTable_New(FALSE); + if (!ret->refPointers) + { + free(ret); + return NULL; + } + + ndr_context_reset(ret); + return ret; +} + +void ndr_context_free(NdrContext* context) +{ + if (context) + { + HashTable_Free(context->refPointers); + free(context); + } +} + +static void ndr_context_bytes_read(NdrContext* context, size_t len) +{ + WINPR_ASSERT(context); + context->indentLevels[context->currentLevel] += len; +} + +static void ndr_context_bytes_written(NdrContext* context, size_t len) +{ + ndr_context_bytes_read(context, len); +} + +NdrContext* ndr_read_header(wStream* s) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return NULL; + + BYTE version = Stream_Get_UINT8(s); + BYTE drep = Stream_Get_UINT8(s); + UINT16 headerLen = Stream_Get_UINT16(s); + + if (headerLen < 4 || !Stream_CheckAndLogRequiredLength(TAG, s, headerLen - 4)) + return NULL; + + /* skip filler */ + Stream_Seek(s, headerLen - 4); + + return ndr_context_new((drep != 0x10), version); +} + +BOOL ndr_write_header(NdrContext* context, wStream* s) +{ + WINPR_ASSERT(context); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + + Stream_Write_UINT8(s, context->version); + Stream_Write_UINT8(s, context->bigEndianDrep ? 0x00 : 0x10); + Stream_Write_UINT16(s, 0x8); /* header len */ + + BYTE filler[] = { 0xcc, 0xcc, 0xcc, 0xcc }; + Stream_Write(s, filler, sizeof(filler)); + return TRUE; +} + +BOOL ndr_skip_bytes(NdrContext* context, wStream* s, size_t nbytes) +{ + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, nbytes)) + return FALSE; + + context->indentLevels[context->currentLevel] += nbytes; + Stream_Seek(s, nbytes); + return TRUE; +} + +BOOL ndr_read_align(NdrContext* context, wStream* s, size_t sz) +{ + WINPR_ASSERT(context); + + size_t rest = context->indentLevels[context->currentLevel] % sz; + if (rest) + { + size_t padding = (sz - rest); + if (!Stream_CheckAndLogRequiredLength(TAG, s, padding)) + return FALSE; + + Stream_Seek(s, padding); + context->indentLevels[context->currentLevel] += padding; + } + + return TRUE; +} + +BOOL ndr_write_align(NdrContext* context, wStream* s, size_t sz) +{ + WINPR_ASSERT(context); + + size_t rest = context->indentLevels[context->currentLevel] % sz; + if (rest) + { + size_t padding = (sz - rest); + + if (!Stream_EnsureRemainingCapacity(s, padding)) + return FALSE; + + Stream_Zero(s, padding); + context->indentLevels[context->currentLevel] += padding; + } + + return TRUE; +} + +BOOL ndr_read_pickle(NdrContext* context, wStream* s) +{ + WINPR_ASSERT(context); + + UINT32 v = 0; + + /* NDR format label */ + if (!ndr_read_uint32(context, s, &v) || v != 0x20000) + return FALSE; + + return ndr_read_uint32(context, s, &v); // padding +} + +BOOL ndr_write_pickle(NdrContext* context, wStream* s) +{ + WINPR_ASSERT(context); + + /* NDR format label */ + if (!ndr_write_uint32(context, s, 0x20000)) + return FALSE; + + ndr_write_uint32(context, s, 0); /* padding */ + return TRUE; +} + +BOOL ndr_read_constructed(NdrContext* context, wStream* s, wStream* target) +{ + WINPR_ASSERT(context); + + UINT32 len = 0; + + /* len */ + if (!ndr_read_uint32(context, s, &len)) + return FALSE; + + /* padding */ + if (!ndr_skip_bytes(context, s, 4)) + return FALSE; + + /* payload */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, len)) + return FALSE; + + Stream_StaticInit(target, Stream_PointerAs(s, BYTE), len); + Stream_Seek(s, len); + return TRUE; +} + +BOOL ndr_start_constructed(NdrContext* context, wStream* s) +{ + WINPR_ASSERT(context); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + + if (context->constructLevel == NDR_MAX_CONSTRUCTS) + return FALSE; + + context->constructLevel++; + context->constructs[context->constructLevel] = Stream_GetPosition(s); + + Stream_Zero(s, 8); + return TRUE; +} + +BOOL ndr_end_constructed(NdrContext* context, wStream* s) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(context->constructs); + WINPR_ASSERT(context->constructLevel >= 0); + + size_t offset = context->constructs[context->constructLevel]; + + wStream staticS = { 0 }; + Stream_StaticInit(&staticS, Stream_Buffer(s) + offset, 4); + + /* len */ + const size_t len = Stream_GetPosition(s) - (offset + 8); + if (len > UINT32_MAX) + return FALSE; + if (!ndr_write_uint32(context, &staticS, (UINT32)len)) + return FALSE; + + return TRUE; +} + +static size_t ndr_hintsCount(NdrMessageType msgType, const void* hints) +{ + WINPR_ASSERT(msgType); + + switch (msgType->arity) + { + case NDR_ARITY_SIMPLE: + return 1; + case NDR_ARITY_ARRAYOF: + WINPR_ASSERT(hints); + return ((const NdrArrayHints*)hints)->count; + case NDR_ARITY_VARYING_ARRAYOF: + WINPR_ASSERT(hints); + return ((const NdrVaryingArrayHints*)hints)->maxLength; + default: + WINPR_ASSERT(0 && "unknown arity"); + return 0; + } +} + +BOOL ndr_read_uint8(NdrContext* context, wStream* s, BYTE* v) +{ + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, *v); + + ndr_context_bytes_read(context, 1); + return TRUE; +} + +BOOL ndr_read_uint8_(NdrContext* context, wStream* s, const void* hints, void* v) +{ + WINPR_UNUSED(hints); + return ndr_read_uint8(context, s, (BYTE*)v); +} + +BOOL ndr_write_uint8(NdrContext* context, wStream* s, BYTE v) +{ + if (!Stream_EnsureRemainingCapacity(s, 1)) + return FALSE; + + Stream_Write_UINT8(s, v); + ndr_context_bytes_written(context, 1); + return TRUE; +} + +BOOL ndr_write_uint8_(NdrContext* context, wStream* s, const void* hints, const void* v) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(v); + WINPR_UNUSED(hints); + + return ndr_write_uint8(context, s, *(const BYTE*)v); +} + +const static NdrMessageDescr uint8_descr = { NDR_ARITY_SIMPLE, 1, ndr_read_uint8_, + ndr_write_uint8_, NULL, NULL }; + +NdrMessageType ndr_uint8_descr(void) +{ + return &uint8_descr; +} + +#define SIMPLE_TYPE_IMPL(UPPERTYPE, LOWERTYPE) \ + BOOL ndr_read_##LOWERTYPE(NdrContext* context, wStream* s, UPPERTYPE* v) \ + { \ + WINPR_ASSERT(context); \ + \ + if (!Stream_CheckAndLogRequiredLength(TAG, s, sizeof(UPPERTYPE))) \ + return FALSE; \ + \ + if (!ndr_read_align(context, s, sizeof(UPPERTYPE))) \ + return FALSE; \ + \ + if (context->bigEndianDrep) \ + Stream_Read_##UPPERTYPE##_BE(s, *v); \ + else \ + Stream_Read_##UPPERTYPE(s, *v); \ + \ + ndr_context_bytes_read(context, sizeof(UPPERTYPE)); \ + return TRUE; \ + } \ + \ + BOOL ndr_read_##LOWERTYPE##_(NdrContext* context, wStream* s, const void* hints, void* v) \ + { \ + WINPR_UNUSED(hints); \ + return ndr_read_##LOWERTYPE(context, s, (UPPERTYPE*)v); \ + } \ + \ + BOOL ndr_write_##LOWERTYPE(NdrContext* context, wStream* s, UPPERTYPE v) \ + { \ + if (!ndr_write_align(context, s, sizeof(UPPERTYPE)) || \ + !Stream_EnsureRemainingCapacity(s, sizeof(UPPERTYPE))) \ + return FALSE; \ + \ + if (context->bigEndianDrep) \ + Stream_Write_##UPPERTYPE##_BE(s, v); \ + else \ + Stream_Write_##UPPERTYPE(s, v); \ + \ + ndr_context_bytes_written(context, sizeof(UPPERTYPE)); \ + return TRUE; \ + } \ + \ + BOOL ndr_write_##LOWERTYPE##_(NdrContext* context, wStream* s, const void* hints, \ + const void* v) \ + { \ + WINPR_ASSERT(context); \ + WINPR_ASSERT(s); \ + WINPR_ASSERT(v); \ + WINPR_UNUSED(hints); \ + \ + return ndr_write_##LOWERTYPE(context, s, *(const UPPERTYPE*)v); \ + } \ + \ + const NdrMessageDescr ndr_##LOWERTYPE##_descr_s = { NDR_ARITY_SIMPLE, \ + sizeof(UPPERTYPE), \ + ndr_read_##LOWERTYPE##_, \ + ndr_write_##LOWERTYPE##_, \ + NULL, \ + NULL }; \ + \ + NdrMessageType ndr_##LOWERTYPE##_descr(void) \ + { \ + return &ndr_##LOWERTYPE##_descr_s; \ + } + +SIMPLE_TYPE_IMPL(UINT32, uint32) +SIMPLE_TYPE_IMPL(UINT16, uint16) +SIMPLE_TYPE_IMPL(UINT64, uint64) + +#define ARRAY_OF_TYPE_IMPL(TYPE, UPPERTYPE) \ + BOOL ndr_read_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, void* v) \ + { \ + WINPR_ASSERT(context); \ + WINPR_ASSERT(s); \ + WINPR_ASSERT(hints); \ + return ndr_read_uconformant_array(context, s, hints, ndr_##TYPE##_descr(), v); \ + } \ + \ + BOOL ndr_write_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, \ + const void* v) \ + { \ + WINPR_ASSERT(context); \ + WINPR_ASSERT(s); \ + WINPR_ASSERT(hints); \ + const NdrArrayHints* ahints = (const NdrArrayHints*)hints; \ + return ndr_write_uconformant_array(context, s, ahints->count, ndr_##TYPE##_descr(), v); \ + } \ + void ndr_destroy_##TYPE##Array(NdrContext* context, const void* hints, void* obj) \ + { \ + WINPR_ASSERT(context); \ + WINPR_ASSERT(obj); \ + WINPR_ASSERT(hints); \ + const NdrArrayHints* ahints = (const NdrArrayHints*)hints; \ + NdrMessageType descr = ndr_##TYPE##_descr(); \ + if (descr->destroyFn) \ + { \ + UPPERTYPE* ptr = (UPPERTYPE*)obj; \ + for (UINT32 i = 0; i < ahints->count; i++, ptr++) \ + descr->destroyFn(context, NULL, ptr); \ + } \ + } \ + \ + const NdrMessageDescr ndr_##TYPE##Array_descr_s = { \ + NDR_ARITY_ARRAYOF, sizeof(UPPERTYPE), ndr_read_##TYPE##Array, \ + ndr_write_##TYPE##Array, ndr_destroy_##TYPE##Array, NULL \ + }; \ + \ + NdrMessageType ndr_##TYPE##Array_descr(void) \ + { \ + return &ndr_##TYPE##Array_descr_s; \ + } \ + \ + BOOL ndr_read_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \ + void* v) \ + { \ + WINPR_ASSERT(context); \ + WINPR_ASSERT(s); \ + WINPR_ASSERT(hints); \ + return ndr_read_uconformant_varying_array(context, s, (const NdrVaryingArrayHints*)hints, \ + ndr_##TYPE##_descr(), v); \ + } \ + BOOL ndr_write_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \ + const void* v) \ + { \ + WINPR_ASSERT(context); \ + WINPR_ASSERT(s); \ + WINPR_ASSERT(hints); \ + return ndr_write_uconformant_varying_array(context, s, (const NdrVaryingArrayHints*)hints, \ + ndr_##TYPE##_descr(), v); \ + } \ + \ + const NdrMessageDescr ndr_##TYPE##VaryingArray_descr_s = { NDR_ARITY_VARYING_ARRAYOF, \ + sizeof(UPPERTYPE), \ + ndr_read_##TYPE##VaryingArray, \ + ndr_write_##TYPE##VaryingArray, \ + NULL, \ + NULL }; \ + \ + NdrMessageType ndr_##TYPE##VaryingArray_descr(void) \ + { \ + return &ndr_##TYPE##VaryingArray_descr_s; \ + } + +ARRAY_OF_TYPE_IMPL(uint8, BYTE) +ARRAY_OF_TYPE_IMPL(uint16, UINT16) + +BOOL ndr_read_wchar(NdrContext* context, wStream* s, WCHAR* ptr) +{ + return ndr_read_uint16(context, s, (UINT16*)ptr); +} + +BOOL ndr_read_uconformant_varying_array(NdrContext* context, wStream* s, + const NdrVaryingArrayHints* hints, NdrMessageType itemType, + void* ptarget) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(hints); + WINPR_ASSERT(itemType); + WINPR_ASSERT(ptarget); + + UINT32 maxCount = 0; + UINT32 offset = 0; + UINT32 length = 0; + + if (!ndr_read_uint32(context, s, &maxCount) || !ndr_read_uint32(context, s, &offset) || + !ndr_read_uint32(context, s, &length)) + return FALSE; + + if ((length * itemType->itemSize) < hints->length) + return FALSE; + + if ((maxCount * itemType->itemSize) < hints->maxLength) + return FALSE; + + BYTE* target = (BYTE*)ptarget; + for (UINT32 i = 0; i < length; i++, target += itemType->itemSize) + { + if (!itemType->readFn(context, s, NULL, target)) + return FALSE; + } + + return ndr_read_align(context, s, 4); +} + +BOOL ndr_write_uconformant_varying_array(NdrContext* context, wStream* s, + const NdrVaryingArrayHints* hints, NdrMessageType itemType, + const void* psrc) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(hints); + WINPR_ASSERT(itemType); + WINPR_ASSERT(psrc); + + if (!ndr_write_uint32(context, s, hints->maxLength) || !ndr_write_uint32(context, s, 0) || + !ndr_write_uint32(context, s, hints->length)) + return FALSE; + + const BYTE* src = (const BYTE*)psrc; + for (UINT32 i = 0; i < hints->length; i++, src += itemType->itemSize) + { + if (!itemType->writeFn(context, s, NULL, src)) + return FALSE; + } + + return TRUE; +} + +BOOL ndr_read_uconformant_array(NdrContext* context, wStream* s, const NdrArrayHints* hints, + NdrMessageType itemType, void* vtarget) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(itemType); + WINPR_ASSERT(vtarget); + + UINT32 count = 0; + + if (!ndr_read_uint32(context, s, &count)) + return FALSE; + + if ((count * itemType->itemSize < hints->count)) + return FALSE; + + BYTE* target = (BYTE*)vtarget; + for (UINT32 i = 0; i < count; i++, target += itemType->itemSize) + { + if (!itemType->readFn(context, s, NULL, target)) + return FALSE; + } + + return ndr_read_align(context, s, /*context->alignBytes*/ 4); +} + +BOOL ndr_write_uconformant_array(NdrContext* context, wStream* s, UINT32 len, + NdrMessageType itemType, const BYTE* ptr) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(itemType); + WINPR_ASSERT(ptr); + + size_t toWrite = len * itemType->itemSize; + size_t padding = (4 - (toWrite % 4)) % 4; + if (!ndr_write_uint32(context, s, len) || !Stream_EnsureRemainingCapacity(s, toWrite + padding)) + return FALSE; + + for (UINT32 i = 0; i < len; i++, ptr += itemType->itemSize) + { + if (!itemType->writeFn(context, s, NULL, ptr)) + return FALSE; + } + + if (padding) + { + Stream_Zero(s, padding); + ndr_context_bytes_written(context, padding); + } + return TRUE; +} + +BOOL ndr_struct_read_fromDescr(NdrContext* context, wStream* s, const NdrStructDescr* descr, + void* target) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(descr); + WINPR_ASSERT(target); + +#define NDR_MAX_STRUCT_DEFERRED 16 + NdrDeferredEntry deferreds[NDR_MAX_STRUCT_DEFERRED] = { 0 }; + size_t ndeferred = 0; + + for (size_t i = 0; i < descr->nfields; i++) + { + const NdrFieldStruct* field = &descr->fields[i]; + BYTE* ptr = target; + ptr += field->structOffset; + void* hints = NULL; + + if (field->hintsField >= 0) + { + /* computes the address of the hints field if any */ + WINPR_ASSERT((size_t)field->hintsField < descr->nfields); + const NdrFieldStruct* hintsField = &descr->fields[field->hintsField]; + + hints = (BYTE*)target + hintsField->structOffset; + } + + switch (field->pointerType) + { + case NDR_NOT_POINTER: + if (!field->typeDescr->readFn(context, s, hints, ptr)) + { + WLog_ERR(TAG, "error when reading %s.%s", descr->name, field->name); + return FALSE; + } + break; + case NDR_POINTER: + case NDR_POINTER_NON_NULL: + { + NdrDeferredEntry* deferred = &deferreds[ndeferred]; + if (ndeferred >= NDR_MAX_STRUCT_DEFERRED) + { + WLog_ERR(TAG, "too many deferred when calling ndr_read_struct_fromDescr for %s", + descr->name); + return FALSE; + } + + deferred->name = field->name; + deferred->hints = hints; + deferred->target = ptr; + deferred->msg = field->typeDescr; + if (!ndr_read_refpointer(context, s, &deferred->ptrId)) + { + WLog_ERR(TAG, "error when reading %s.%s", descr->name, field->name); + return FALSE; + } + + if (!deferred->ptrId && field->pointerType == NDR_POINTER_NON_NULL) + { + WLog_ERR(TAG, "%s.%s can't be null", descr->name, field->name); + return FALSE; + } + ndeferred++; + break; + } + default: + WLog_ERR(TAG, "%s.%s unknown pointer type 0x%x", descr->name, field->name, + field->pointerType); + return FALSE; + } + } + + return ndr_push_deferreds(context, deferreds, ndeferred); +} + +BOOL ndr_struct_write_fromDescr(NdrContext* context, wStream* s, const NdrStructDescr* descr, + const void* src) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(descr); + WINPR_ASSERT(src); + + NdrDeferredEntry deferreds[NDR_MAX_STRUCT_DEFERRED] = { 0 }; + size_t ndeferred = 0; + + for (size_t i = 0; i < descr->nfields; i++) + { + const NdrFieldStruct* field = &descr->fields[i]; + const BYTE* ptr = (const BYTE*)src + field->structOffset; + + const void* hints = NULL; + + if (field->hintsField >= 0) + { + /* computes the address of the hints field if any */ + WINPR_ASSERT((size_t)field->hintsField < descr->nfields); + const NdrFieldStruct* hintsField = &descr->fields[field->hintsField]; + + hints = (const BYTE*)src + hintsField->structOffset; + } + + switch (field->pointerType) + { + case NDR_POINTER: + case NDR_POINTER_NON_NULL: + { + ndr_refid ptrId = NDR_PTR_NULL; + BOOL isNew = 0; + ptr = *(WINPR_CAST_CONST_PTR_AWAY(ptr, const void**)); + + if (!ptr && field->pointerType == NDR_POINTER_NON_NULL) + { + WLog_ERR(TAG, "%s.%s can't be null", descr->name, field->name); + return FALSE; + } + + if (!ndr_context_allocatePtr(context, ptr, &ptrId, &isNew)) + return FALSE; + + if (isNew) + { + NdrDeferredEntry* deferred = &deferreds[ndeferred]; + if (ndeferred >= NDR_MAX_STRUCT_DEFERRED) + { + WLog_ERR(TAG, + "too many deferred when calling ndr_read_struct_fromDescr for %s", + descr->name); + return FALSE; + } + + deferred->name = field->name; + deferred->hints = WINPR_CAST_CONST_PTR_AWAY(hints, void*); + deferred->target = WINPR_CAST_CONST_PTR_AWAY(ptr, void*); + deferred->msg = field->typeDescr; + ndeferred++; + } + + if (!ndr_write_uint32(context, s, ptrId)) + return FALSE; + break; + } + case NDR_NOT_POINTER: + if (!field->typeDescr->writeFn(context, s, hints, ptr)) + { + WLog_ERR(TAG, "error when writing %s.%s", descr->name, field->name); + return FALSE; + } + break; + default: + break; + } + } + + return ndr_push_deferreds(context, deferreds, ndeferred); +} + +void ndr_struct_dump_fromDescr(wLog* logger, UINT32 lvl, size_t identLevel, + const NdrStructDescr* descr, const void* obj) +{ + char tabArray[30 + 1]; + size_t ntabs = (identLevel <= 30) ? identLevel : 30; + + memset(tabArray, '\t', ntabs); + tabArray[ntabs] = 0; + + WLog_Print(logger, lvl, "%s%s", tabArray, descr->name); + for (size_t i = 0; i < descr->nfields; i++) + { + const NdrFieldStruct* field = &descr->fields[i]; + const BYTE* ptr = (const BYTE*)obj + field->structOffset; + + switch (field->pointerType) + { + case NDR_POINTER: + case NDR_POINTER_NON_NULL: + ptr = *(WINPR_CAST_CONST_PTR_AWAY(ptr, const void**)); + break; + case NDR_NOT_POINTER: + break; + default: + WLog_ERR(TAG, "invalid field->pointerType"); + break; + } + + WLog_Print(logger, lvl, "%s*%s:", tabArray, field->name); + if (field->typeDescr->dumpFn) + field->typeDescr->dumpFn(logger, lvl, identLevel + 1, ptr); + else + WLog_Print(logger, lvl, "%s\t", tabArray); + } +} + +void ndr_struct_destroy(NdrContext* context, const NdrStructDescr* descr, void* pptr) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(descr); + WINPR_ASSERT(pptr); + + for (size_t i = 0; i < descr->nfields; i++) + { + const NdrFieldStruct* field = &descr->fields[i]; + void* ptr = (BYTE*)pptr + field->structOffset; + void* hints = NULL; + + if (field->hintsField >= 0) + { + /* computes the address of the hints field if any */ + WINPR_ASSERT((size_t)field->hintsField < descr->nfields); + const NdrFieldStruct* hintsField = &descr->fields[field->hintsField]; + + hints = (BYTE*)pptr + hintsField->structOffset; + } + + if (field->pointerType != NDR_NOT_POINTER) + ptr = *(void**)ptr; + + if (ptr && field->typeDescr->destroyFn) + field->typeDescr->destroyFn(context, hints, ptr); + + if (field->pointerType != NDR_NOT_POINTER) + free(ptr); + } +} + +ndr_refid ndr_pointer_refid(const void* ptr) +{ + return (ndr_refid)((ULONG_PTR)ptr); +} + +BOOL ndr_read_refpointer(NdrContext* context, wStream* s, ndr_refid* refId) +{ + return ndr_read_uint32(context, s, refId); +} + +typedef struct +{ + const void* needle; + ndr_refid* presult; +} FindValueArgs; + +static BOOL findValueRefFn(const void* key, void* value, void* parg) +{ + WINPR_ASSERT(parg); + + FindValueArgs* args = (FindValueArgs*)parg; + if (args->needle == value) + { + *args->presult = (ndr_refid)(UINT_PTR)key; + return FALSE; + } + return TRUE; +} + +BOOL ndr_context_allocatePtr(NdrContext* context, const void* ptr, ndr_refid* prefId, BOOL* pnewPtr) +{ + WINPR_ASSERT(context); + + FindValueArgs findArgs = { ptr, prefId }; + if (!HashTable_Foreach(context->refPointers, findValueRefFn, &findArgs)) + { + *pnewPtr = FALSE; + return TRUE; + } + + *pnewPtr = TRUE; + *prefId = context->refIdCounter + 4; + if (!HashTable_Insert(context->refPointers, (void*)(UINT_PTR)(*prefId), ptr)) + return FALSE; + + context->refIdCounter += 4; + return TRUE; +} + +BOOL ndr_read_pointedMessageEx(NdrContext* context, wStream* s, ndr_refid ptrId, + NdrMessageType descr, void* hints, void** target) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(descr); + WINPR_ASSERT(target); + + *target = NULL; + if (!ptrId) + return TRUE; + + void* ret = HashTable_GetItemValue(context->refPointers, (void*)(UINT_PTR)ptrId); + if (!ret) + { + size_t itemCount = ndr_hintsCount(descr, hints); + ret = calloc(itemCount, descr->itemSize); + if (!ret) + return FALSE; + + if (!descr->readFn(context, s, hints, ret) || + !HashTable_Insert(context->refPointers, (void*)(UINT_PTR)ptrId, ret)) + { + if (descr->destroyFn) + descr->destroyFn(context, hints, ret); + free(ret); + return FALSE; + } + } + + *target = ret; + return TRUE; +} + +BOOL ndr_push_deferreds(NdrContext* context, NdrDeferredEntry* deferreds, size_t ndeferred) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(deferreds); + + if (!ndeferred) + return TRUE; + + if (context->ndeferred + ndeferred > NDR_MAX_DEFERRED) + { + WLog_ERR(TAG, "too many deferred"); + return FALSE; + } + + for (size_t i = ndeferred; i > 0; i--, context->ndeferred++) + { + context->deferred[context->ndeferred] = deferreds[i - 1]; + } + return TRUE; +} + +BOOL ndr_treat_deferred_read(NdrContext* context, wStream* s) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + + while (context->ndeferred) + { + NdrDeferredEntry current = context->deferred[context->ndeferred - 1]; + context->ndeferred--; + + WLog_VRB(TAG, "treating read deferred 0x%x for %s", current.ptrId, current.name); + if (!ndr_read_pointedMessageEx(context, s, current.ptrId, current.msg, current.hints, + (void**)current.target)) + { + WLog_ERR(TAG, "error parsing deferred %s", current.name); + return FALSE; + } + } + + return TRUE; +} + +BOOL ndr_treat_deferred_write(NdrContext* context, wStream* s) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + + while (context->ndeferred) + { + NdrDeferredEntry current = context->deferred[context->ndeferred - 1]; + context->ndeferred--; + + WLog_VRB(TAG, "treating write deferred for %s", current.name); + if (!current.msg->writeFn(context, s, current.hints, current.target)) + { + WLog_ERR(TAG, "error writing deferred %s", current.name); + return FALSE; + } + } + + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/ndr.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/ndr.h new file mode 100644 index 0000000000000000000000000000000000000000..ff017c737cbf319147b1fb855834c3eb027f31d0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/ndr.h @@ -0,0 +1,217 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Authentication redirection virtual channel + * + * Copyright 2024 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CHANNELS_RDPEAR_NDR_H_ +#define CHANNELS_RDPEAR_NDR_H_ + +#include +#include + +#define NDR_PTR_NULL (0UL) + +#define NDR_SIMPLE_TYPE_DECL(LOWER, UPPER) \ + BOOL ndr_read_##LOWER(NdrContext* context, wStream* s, UPPER* v); \ + BOOL ndr_read_##LOWER##_(NdrContext* context, wStream* s, const void* hints, void* v); \ + BOOL ndr_write_##LOWER(NdrContext* context, wStream* s, UPPER v); \ + BOOL ndr_write_##LOWER##_(NdrContext* context, wStream* s, const void* hints, const void* v); \ + extern const NdrMessageDescr ndr_##LOWER##_descr_s; \ + NdrMessageType ndr_##LOWER##_descr(void) + +#define NDR_ARRAY_OF_TYPE_DECL(TYPE, UPPERTYPE) \ + BOOL ndr_read_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, void* v); \ + BOOL ndr_write_##TYPE##Array(NdrContext* context, wStream* s, const void* hints, \ + const void* v); \ + void ndr_destroy_##TYPE##Array(NdrContext* context, const void* hints, void* obj); \ + extern const NdrMessageDescr ndr_##TYPE##Array_descr_s; \ + NdrMessageType ndr_##TYPE##Array_descr(void); \ + \ + BOOL ndr_read_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \ + void* v); \ + BOOL ndr_write_##TYPE##VaryingArray(NdrContext* context, wStream* s, const void* hints, \ + const void* v); \ + extern const NdrMessageDescr ndr_##TYPE##VaryingArray_descr_s; \ + NdrMessageType ndr_##TYPE##VaryingArray_descr(void) + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct NdrContext_s NdrContext; + + typedef UINT32 ndr_refid; + + typedef BOOL (*NDR_READER_FN)(NdrContext* context, wStream* s, const void* hints, void* target); + typedef BOOL (*NDR_WRITER_FN)(NdrContext* context, wStream* s, const void* hints, + const void* obj); + typedef void (*NDR_DESTROY_FN)(NdrContext* context, const void* hints, void* obj); + typedef void (*NDR_DUMP_FN)(wLog* logger, UINT32 lvl, size_t indentLevel, const void* obj); + + /** @brief arity of a message */ + typedef enum + { + NDR_ARITY_SIMPLE, + NDR_ARITY_ARRAYOF, + NDR_ARITY_VARYING_ARRAYOF, + } NdrTypeArity; + + /** @brief message descriptor */ + typedef struct + { + NdrTypeArity arity; + size_t itemSize; + NDR_READER_FN readFn; + NDR_WRITER_FN writeFn; + NDR_DESTROY_FN destroyFn; + NDR_DUMP_FN dumpFn; + } NdrMessageDescr; + + typedef const NdrMessageDescr* NdrMessageType; + + /** @brief pointer or not and if null is accepted */ + typedef enum + { + NDR_NOT_POINTER, + NDR_POINTER_NON_NULL, + NDR_POINTER + } NdrPointerType; + + /** @brief descriptor of a field in a structure */ + typedef struct + { + const char* name; + size_t structOffset; + NdrPointerType pointerType; + ssize_t hintsField; + NdrMessageType typeDescr; + } NdrFieldStruct; + + /** @brief structure descriptor */ + typedef struct + { + const char* name; + size_t nfields; + const NdrFieldStruct* fields; + } NdrStructDescr; + + /** @brief a deferred pointer */ + typedef struct + { + ndr_refid ptrId; + const char* name; + void* hints; + void* target; + NdrMessageType msg; + } NdrDeferredEntry; + + void ndr_context_free(NdrContext* context); + + static INLINE void ndr_context_destroy(NdrContext** pcontext) + { + WINPR_ASSERT(pcontext); + ndr_context_free(*pcontext); + *pcontext = NULL; + } + + WINPR_ATTR_MALLOC(ndr_context_free, 1) + NdrContext* ndr_context_new(BOOL bigEndianDrep, BYTE version); + + void ndr_context_reset(NdrContext* context); + + WINPR_ATTR_MALLOC(ndr_context_free, 1) + NdrContext* ndr_context_copy(const NdrContext* src); + + WINPR_ATTR_MALLOC(ndr_context_free, 1) + NdrContext* ndr_read_header(wStream* s); + + BOOL ndr_write_header(NdrContext* context, wStream* s); + + NDR_SIMPLE_TYPE_DECL(uint8, UINT8); + NDR_SIMPLE_TYPE_DECL(uint16, UINT16); + NDR_SIMPLE_TYPE_DECL(uint32, UINT32); + NDR_SIMPLE_TYPE_DECL(uint64, UINT64); + + NDR_ARRAY_OF_TYPE_DECL(uint8, BYTE); + NDR_ARRAY_OF_TYPE_DECL(uint16, UINT16); + + BOOL ndr_skip_bytes(NdrContext* context, wStream* s, size_t nbytes); + BOOL ndr_read_align(NdrContext* context, wStream* s, size_t sz); + BOOL ndr_write_align(NdrContext* context, wStream* s, size_t sz); + + BOOL ndr_read_pickle(NdrContext* context, wStream* s); + BOOL ndr_write_pickle(NdrContext* context, wStream* s); + + BOOL ndr_read_constructed(NdrContext* context, wStream* s, wStream* target); + BOOL ndr_write_constructed(NdrContext* context, wStream* s, wStream* payload); + + BOOL ndr_start_constructed(NdrContext* context, wStream* s); + BOOL ndr_end_constructed(NdrContext* context, wStream* s); + + BOOL ndr_read_wchar(NdrContext* context, wStream* s, WCHAR* ptr); + + /** @brief hints for a varying conformant array */ + typedef struct + { + UINT32 length; + UINT32 maxLength; + } NdrVaryingArrayHints; + + BOOL ndr_read_uconformant_varying_array(NdrContext* context, wStream* s, + const NdrVaryingArrayHints* hints, + NdrMessageType itemType, void* ptarget); + BOOL ndr_write_uconformant_varying_array(NdrContext* context, wStream* s, + const NdrVaryingArrayHints* hints, + NdrMessageType itemType, const void* src); + + /** @brief hints for a conformant array */ + typedef struct + { + UINT32 count; + } NdrArrayHints; + + BOOL ndr_read_uconformant_array(NdrContext* context, wStream* s, const NdrArrayHints* hints, + NdrMessageType itemType, void* vtarget); + BOOL ndr_write_uconformant_array(NdrContext* context, wStream* s, UINT32 len, + NdrMessageType itemType, const BYTE* ptr); + + BOOL ndr_struct_read_fromDescr(NdrContext* context, wStream* s, const NdrStructDescr* descr, + void* target); + BOOL ndr_struct_write_fromDescr(NdrContext* context, wStream* s, const NdrStructDescr* descr, + const void* src); + void ndr_struct_dump_fromDescr(wLog* logger, UINT32 lvl, size_t identLevel, + const NdrStructDescr* descr, const void* obj); + void ndr_struct_destroy(NdrContext* context, const NdrStructDescr* descr, void* pptr); + + ndr_refid ndr_pointer_refid(const void* ptr); + BOOL ndr_read_refpointer(NdrContext* context, wStream* s, UINT32* refId); + BOOL ndr_context_allocatePtr(NdrContext* context, const void* ptr, ndr_refid* prefId, + BOOL* pnewPtr); + + BOOL ndr_read_pointedMessageEx(NdrContext* context, wStream* s, ndr_refid ptrId, + NdrMessageType descr, void* hints, void** target); + + BOOL ndr_push_deferreds(NdrContext* context, NdrDeferredEntry* deferreds, size_t ndeferred); + BOOL ndr_treat_deferred_read(NdrContext* context, wStream* s); + BOOL ndr_treat_deferred_write(NdrContext* context, wStream* s); + +#ifdef __cplusplus +} +#endif + +#endif /* CHANNELS_RDPEAR_NDR_H_ */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/rdpear_asn1.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/rdpear_asn1.h new file mode 100644 index 0000000000000000000000000000000000000000..9b865fdcffc3138e1d8ceafe3f2171de3bfa950a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/rdpear_asn1.h @@ -0,0 +1,31 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ASN1 routines for RDPEAR + * + * Copyright 2024 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RPDEAR_RDPEAR_ASN1_H__ +#define RPDEAR_RDPEAR_ASN1_H__ + +#include + +#include + +wStream* rdpear_enc_Checksum(UINT32 cksumtype, krb5_checksum* csum); + +wStream* rdpear_enc_EncryptedData(UINT32 encType, krb5_data* payload); + +#endif /* RPDEAR_RDPEAR_ASN1_H__ */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/rdpear_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/rdpear_common.h new file mode 100644 index 0000000000000000000000000000000000000000..1734548f516dbaa561bc9c44666fca11b6196c39 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear-common/rdpear_common.h @@ -0,0 +1,236 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2023 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEAR_COMMON_H +#define FREERDP_CHANNEL_RDPEAR_COMMON_H + +#include +#include +#include +#include + +#include + +#include + +typedef enum +{ + RDPEAR_PACKAGE_KERBEROS, + RDPEAR_PACKAGE_NTLM, + RDPEAR_PACKAGE_UNKNOWN +} RdpEarPackageType; + +/* RDPEAR 2.2.1.1 */ +typedef enum +{ + // Start Kerberos remote calls + RemoteCallKerbMinimum = 0x100, + RemoteCallKerbNegotiateVersion = 0x100, + RemoteCallKerbBuildAsReqAuthenticator, + RemoteCallKerbVerifyServiceTicket, + RemoteCallKerbCreateApReqAuthenticator, + RemoteCallKerbDecryptApReply, + RemoteCallKerbUnpackKdcReplyBody, + RemoteCallKerbComputeTgsChecksum, + RemoteCallKerbBuildEncryptedAuthData, + RemoteCallKerbPackApReply, + RemoteCallKerbHashS4UPreauth, + RemoteCallKerbSignS4UPreauthData, + RemoteCallKerbVerifyChecksum, + RemoteCallKerbReserved1, + RemoteCallKerbReserved2, + RemoteCallKerbReserved3, + RemoteCallKerbReserved4, + RemoteCallKerbReserved5, + RemoteCallKerbReserved6, + RemoteCallKerbReserved7, + RemoteCallKerbDecryptPacCredentials, + RemoteCallKerbCreateECDHKeyAgreement, + RemoteCallKerbCreateDHKeyAgreement, + RemoteCallKerbDestroyKeyAgreement, + RemoteCallKerbKeyAgreementGenerateNonce, + RemoteCallKerbFinalizeKeyAgreement, + RemoteCallKerbMaximum = 0x1ff, + // End Kerberos remote calls + + // Start NTLM remote calls + RemoteCallNtlmMinimum = 0x200, + RemoteCallNtlmNegotiateVersion = 0x200, + RemoteCallNtlmLm20GetNtlm3ChallengeResponse, + RemoteCallNtlmCalculateNtResponse, + RemoteCallNtlmCalculateUserSessionKeyNt, + RemoteCallNtlmCompareCredentials, + RemoteCallNtlmMaximum = 0x2ff, + // End NTLM remote calls +} RemoteGuardCallId; + +FREERDP_LOCAL RdpEarPackageType rdpear_packageType_from_name(WinPrAsn1_OctetString* package); +FREERDP_LOCAL wStream* rdpear_encodePayload(RdpEarPackageType packageType, wStream* payload); + +#define RDPEAR_COMMON_MESSAGE_DECL(V) \ + FREERDP_LOCAL BOOL ndr_read_##V(NdrContext* context, wStream* s, const void* hints, V* obj); \ + FREERDP_LOCAL BOOL ndr_write_##V(NdrContext* context, wStream* s, const void* hints, \ + const V* obj); \ + FREERDP_LOCAL void ndr_destroy_##V(NdrContext* context, const void* hints, V* obj); \ + FREERDP_LOCAL void ndr_dump_##V(wLog* logger, UINT32 lvl, size_t indentLevel, const V* obj); \ + FREERDP_LOCAL NdrMessageType ndr_##V##_descr(void) + +/** @brief 2.2.1.2.2 KERB_RPC_OCTET_STRING */ +typedef struct +{ + UINT32 length; + BYTE* value; +} KERB_RPC_OCTET_STRING; + +RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_OCTET_STRING); + +/** @brief 2.2.1.2.1 KERB_ASN1_DATA */ +typedef struct +{ + UINT32 Pdu; + NdrArrayHints Asn1BufferHints; + BYTE* Asn1Buffer; +} KERB_ASN1_DATA; + +RDPEAR_COMMON_MESSAGE_DECL(KERB_ASN1_DATA); + +/** @brief 2.3.10 RPC_UNICODE_STRING (MS-DTYP) */ +typedef struct +{ + NdrVaryingArrayHints lenHints; + UINT32 strLength; + WCHAR* Buffer; +} RPC_UNICODE_STRING; + +RDPEAR_COMMON_MESSAGE_DECL(RPC_UNICODE_STRING); + +/** @brief 2.2.1.2.3 KERB_RPC_INTERNAL_NAME */ +typedef struct +{ + UINT16 NameType; + NdrArrayHints nameHints; + RPC_UNICODE_STRING* Names; +} KERB_RPC_INTERNAL_NAME; + +RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_INTERNAL_NAME); + +/** @brief 2.2.1.2.8 KERB_RPC_ENCRYPTION_KEY */ +typedef struct +{ + UINT32 reserved1; + UINT32 reserved2; + KERB_RPC_OCTET_STRING reserved3; +} KERB_RPC_ENCRYPTION_KEY; + +RDPEAR_COMMON_MESSAGE_DECL(KERB_RPC_ENCRYPTION_KEY); + +/** @brief 2.2.2.1.8 BuildEncryptedAuthData */ +typedef struct +{ + UINT32 KeyUsage; + KERB_RPC_ENCRYPTION_KEY* Key; + KERB_ASN1_DATA* PlainAuthData; +} BuildEncryptedAuthDataReq; + +RDPEAR_COMMON_MESSAGE_DECL(BuildEncryptedAuthDataReq); + +/** @brief 2.2.2.1.7 ComputeTgsChecksum */ +typedef struct +{ + KERB_ASN1_DATA* requestBody; + KERB_RPC_ENCRYPTION_KEY* Key; + UINT32 ChecksumType; +} ComputeTgsChecksumReq; + +RDPEAR_COMMON_MESSAGE_DECL(ComputeTgsChecksumReq); + +/** @brief 2.2.2.1.4 CreateApReqAuthenticator */ +typedef struct +{ + KERB_RPC_ENCRYPTION_KEY* EncryptionKey; + ULONG SequenceNumber; + KERB_RPC_INTERNAL_NAME* ClientName; + RPC_UNICODE_STRING* ClientRealm; + PLARGE_INTEGER SkewTime; + KERB_RPC_ENCRYPTION_KEY* SubKey; // optional + KERB_ASN1_DATA* AuthData; // optional + KERB_ASN1_DATA* GssChecksum; // optional + ULONG KeyUsage; +} CreateApReqAuthenticatorReq; + +RDPEAR_COMMON_MESSAGE_DECL(CreateApReqAuthenticatorReq); + +/** @brief 2.2.2.1.4 CreateApReqAuthenticator */ +typedef struct +{ + LARGE_INTEGER AuthenticatorTime; + KERB_ASN1_DATA Authenticator; + LONG KerbProtocolError; +} CreateApReqAuthenticatorResp; + +RDPEAR_COMMON_MESSAGE_DECL(CreateApReqAuthenticatorResp); + +/** @brief 2.2.2.1.6 UnpackKdcReplyBody */ +typedef struct +{ + KERB_ASN1_DATA* EncryptedData; + KERB_RPC_ENCRYPTION_KEY* Key; + KERB_RPC_ENCRYPTION_KEY* StrengthenKey; + ULONG Pdu; + ULONG KeyUsage; +} UnpackKdcReplyBodyReq; + +RDPEAR_COMMON_MESSAGE_DECL(UnpackKdcReplyBodyReq); + +/** @brief 2.2.2.1.6 UnpackKdcReplyBody */ +typedef struct +{ + LONG KerbProtocolError; + KERB_ASN1_DATA ReplyBody; +} UnpackKdcReplyBodyResp; + +RDPEAR_COMMON_MESSAGE_DECL(UnpackKdcReplyBodyResp); + +typedef struct +{ + KERB_ASN1_DATA* EncryptedReply; + KERB_RPC_ENCRYPTION_KEY* Key; +} DecryptApReplyReq; + +RDPEAR_COMMON_MESSAGE_DECL(DecryptApReplyReq); + +typedef struct +{ + KERB_ASN1_DATA* Reply; + KERB_ASN1_DATA* ReplyBody; + KERB_RPC_ENCRYPTION_KEY* SessionKey; +} PackApReplyReq; + +RDPEAR_COMMON_MESSAGE_DECL(PackApReplyReq); + +typedef struct +{ + NdrArrayHints PackedReplyHints; + BYTE* PackedReply; +} PackApReplyResp; + +RDPEAR_COMMON_MESSAGE_DECL(PackApReplyResp); + +#undef RDPEAR_COMMON_MESSAGE_DECL + +#endif /* FREERDP_CHANNEL_RDPEAR_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear_asn1.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear_asn1.c new file mode 100644 index 0000000000000000000000000000000000000000..c16006648babc753a4a81f7210974795a026b337 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear_asn1.c @@ -0,0 +1,104 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ASN1 routines for RDPEAR + * + * Copyright 2024 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +wStream* rdpear_enc_Checksum(UINT32 cksumtype, krb5_checksum* csum) +{ + /** + * Checksum ::= SEQUENCE { + * cksumtype [0] Int32, + * checksum [1] OCTET STRING + * } + */ + wStream* ret = NULL; + WinPrAsn1Encoder* enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER); + if (!enc) + return NULL; + + if (!WinPrAsn1EncSeqContainer(enc)) + goto out; + + if (!WinPrAsn1EncContextualInteger(enc, 0, (WinPrAsn1_INTEGER)cksumtype)) + goto out; + + WinPrAsn1_OctetString octets; + octets.data = (BYTE*)csum->contents; + octets.len = csum->length; + if (!WinPrAsn1EncContextualOctetString(enc, 1, &octets) || !WinPrAsn1EncEndContainer(enc)) + goto out; + + ret = Stream_New(NULL, 1024); + if (!ret) + goto out; + + if (!WinPrAsn1EncToStream(enc, ret)) + { + Stream_Free(ret, TRUE); + ret = NULL; + goto out; + } + +out: + WinPrAsn1Encoder_Free(&enc); + return ret; +} + +wStream* rdpear_enc_EncryptedData(UINT32 encType, krb5_data* payload) +{ + /** + * EncryptedData ::= SEQUENCE { + * etype [0] Int32 -- EncryptionType --, + * kvno [1] UInt32 OPTIONAL, + * cipher [2] OCTET STRING -- ciphertext + * } + */ + wStream* ret = NULL; + WinPrAsn1Encoder* enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER); + if (!enc) + return NULL; + + if (!WinPrAsn1EncSeqContainer(enc)) + goto out; + + if (!WinPrAsn1EncContextualInteger(enc, 0, (WinPrAsn1_INTEGER)encType)) + goto out; + + WinPrAsn1_OctetString octets; + octets.data = (BYTE*)payload->data; + octets.len = payload->length; + if (!WinPrAsn1EncContextualOctetString(enc, 2, &octets) || !WinPrAsn1EncEndContainer(enc)) + goto out; + + ret = Stream_New(NULL, 1024); + if (!ret) + goto out; + + if (!WinPrAsn1EncToStream(enc, ret)) + { + Stream_Free(ret, TRUE); + ret = NULL; + goto out; + } + +out: + WinPrAsn1Encoder_Free(&enc); + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear_common.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear_common.c new file mode 100644 index 0000000000000000000000000000000000000000..6f80270bad1af9fb97f7e435cdeddcf0fa5d7033 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/rdpear_common.c @@ -0,0 +1,565 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2023 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include +#include + +#define TAG CHANNELS_TAG("rdpear") + +static char kerberosPackageName[] = { + 'K', 0, 'e', 0, 'r', 0, 'b', 0, 'e', 0, 'r', 0, 'o', 0, 's', 0 +}; +static char ntlmPackageName[] = { 'N', 0, 'T', 0, 'L', 0, 'M', 0 }; + +RdpEarPackageType rdpear_packageType_from_name(WinPrAsn1_OctetString* package) +{ + if (package->len == sizeof(kerberosPackageName) && + memcmp(package->data, kerberosPackageName, package->len) == 0) + return RDPEAR_PACKAGE_KERBEROS; + + if (package->len == sizeof(ntlmPackageName) && + memcmp(package->data, ntlmPackageName, package->len) == 0) + return RDPEAR_PACKAGE_NTLM; + + return RDPEAR_PACKAGE_UNKNOWN; +} + +wStream* rdpear_encodePayload(RdpEarPackageType packageType, wStream* payload) +{ + wStream* ret = NULL; + WinPrAsn1Encoder* enc = WinPrAsn1Encoder_New(WINPR_ASN1_DER); + if (!enc) + return NULL; + + /* TSRemoteGuardInnerPacket ::= SEQUENCE { */ + if (!WinPrAsn1EncSeqContainer(enc)) + goto out; + + /* packageName [1] OCTET STRING */ + WinPrAsn1_OctetString packageOctetString; + switch (packageType) + { + case RDPEAR_PACKAGE_KERBEROS: + packageOctetString.data = (BYTE*)kerberosPackageName; + packageOctetString.len = sizeof(kerberosPackageName); + break; + case RDPEAR_PACKAGE_NTLM: + packageOctetString.data = (BYTE*)ntlmPackageName; + packageOctetString.len = sizeof(ntlmPackageName); + break; + default: + goto out; + } + + if (!WinPrAsn1EncContextualOctetString(enc, 1, &packageOctetString)) + goto out; + + /* buffer [2] OCTET STRING*/ + WinPrAsn1_OctetString payloadOctetString = { Stream_GetPosition(payload), + Stream_Buffer(payload) }; + if (!WinPrAsn1EncContextualOctetString(enc, 2, &payloadOctetString)) + goto out; + + /* } */ + if (!WinPrAsn1EncEndContainer(enc)) + goto out; + + ret = Stream_New(NULL, 100); + if (!ret) + goto out; + + if (!WinPrAsn1EncToStream(enc, ret)) + { + Stream_Free(ret, TRUE); + ret = NULL; + goto out; + } +out: + WinPrAsn1Encoder_Free(&enc); + return ret; +} + +#define RDPEAR_SIMPLE_MESSAGE_TYPE(V) \ + BOOL ndr_read_##V(NdrContext* context, wStream* s, const void* hints, V* obj) \ + { \ + WINPR_UNUSED(hints); \ + return ndr_struct_read_fromDescr(context, s, &V##_struct, obj); \ + } \ + BOOL ndr_write_##V(NdrContext* context, wStream* s, const void* hints, const V* obj) \ + { \ + WINPR_UNUSED(hints); \ + return ndr_struct_write_fromDescr(context, s, &V##_struct, obj); \ + } \ + void ndr_destroy_##V(NdrContext* context, const void* hints, V* obj) \ + { \ + WINPR_UNUSED(hints); \ + ndr_struct_destroy(context, &V##_struct, obj); \ + } \ + void ndr_dump_##V(wLog* logger, UINT32 lvl, size_t indentLevel, const V* obj) \ + { \ + ndr_struct_dump_fromDescr(logger, lvl, indentLevel, &V##_struct, obj); \ + } \ + \ + static BOOL ndr_descr_read_##V(NdrContext* context, wStream* s, const void* hints, void* obj) \ + { \ + WINPR_UNUSED(hints); \ + return ndr_struct_read_fromDescr(context, s, &V##_struct, obj); \ + } \ + static BOOL ndr_descr_write_##V(NdrContext* context, wStream* s, const void* hints, \ + const void* obj) \ + { \ + WINPR_UNUSED(hints); \ + return ndr_struct_write_fromDescr(context, s, &V##_struct, obj); \ + } \ + static void ndr_descr_destroy_##V(NdrContext* context, const void* hints, void* obj) \ + { \ + WINPR_UNUSED(hints); \ + ndr_struct_destroy(context, &V##_struct, obj); \ + } \ + static void ndr_descr_dump_##V(wLog* logger, UINT32 lvl, size_t indentLevel, const void* obj) \ + { \ + ndr_struct_dump_fromDescr(logger, lvl, indentLevel, &V##_struct, obj); \ + } \ + \ + static NdrMessageDescr ndr_##V##_descr_s = { \ + NDR_ARITY_SIMPLE, sizeof(V), ndr_descr_read_##V, ndr_descr_write_##V, \ + ndr_descr_destroy_##V, ndr_descr_dump_##V, \ + }; \ + \ + NdrMessageType ndr_##V##_descr(void) \ + { \ + return &ndr_##V##_descr_s; \ + } + +static const NdrFieldStruct KERB_RPC_OCTET_STRING_fields[] = { + { "Length", offsetof(KERB_RPC_OCTET_STRING, length), NDR_NOT_POINTER, -1, &ndr_uint32_descr_s }, + { "value", offsetof(KERB_RPC_OCTET_STRING, value), NDR_POINTER_NON_NULL, 0, + &ndr_uint8Array_descr_s } +}; +static const NdrStructDescr KERB_RPC_OCTET_STRING_struct = { "KERB_RPC_OCTET_STRING", 2, + KERB_RPC_OCTET_STRING_fields }; + +RDPEAR_SIMPLE_MESSAGE_TYPE(KERB_RPC_OCTET_STRING) + +/* ============================= KERB_ASN1_DATA ============================== */ + +static const NdrFieldStruct KERB_ASN1_DATA_fields[] = { + { "Pdu", offsetof(KERB_ASN1_DATA, Pdu), NDR_NOT_POINTER, -1, &ndr_uint32_descr_s }, + { "Count", offsetof(KERB_ASN1_DATA, Asn1BufferHints.count), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, + { "Asn1Buffer", offsetof(KERB_ASN1_DATA, Asn1Buffer), NDR_POINTER_NON_NULL, 1, + &ndr_uint8Array_descr_s } +}; +static const NdrStructDescr KERB_ASN1_DATA_struct = { "KERB_ASN1_DATA", + ARRAYSIZE(KERB_ASN1_DATA_fields), + KERB_ASN1_DATA_fields }; + +RDPEAR_SIMPLE_MESSAGE_TYPE(KERB_ASN1_DATA) + +/* ============================ RPC_UNICODE_STRING ========================== */ + +BOOL ndr_read_RPC_UNICODE_STRING(NdrContext* context, wStream* s, const void* hints, + RPC_UNICODE_STRING* res) +{ + NdrDeferredEntry bufferDesc = { NDR_PTR_NULL, "RPC_UNICODE_STRING.Buffer", &res->lenHints, + (void*)&res->Buffer, ndr_uint16VaryingArray_descr() }; + UINT16 Length = 0; + UINT16 MaximumLength = 0; + + WINPR_UNUSED(hints); + if (!ndr_read_uint16(context, s, &Length) || !ndr_read_uint16(context, s, &MaximumLength) || + !ndr_read_refpointer(context, s, &bufferDesc.ptrId) || Length > MaximumLength) + return FALSE; + + res->lenHints.length = Length; + res->lenHints.maxLength = MaximumLength; + res->strLength = Length / 2; + + return ndr_push_deferreds(context, &bufferDesc, 1); +} + +static BOOL ndr_descr_read_RPC_UNICODE_STRING(NdrContext* context, wStream* s, const void* hints, + void* res) +{ + return ndr_read_RPC_UNICODE_STRING(context, s, hints, res); +} + +#if 0 +BOOL ndr_write_RPC_UNICODE_STRING(NdrContext* context, wStream* s, const void* hints, + const RPC_UNICODE_STRING* res) +{ + return ndr_write_uint32(context, s, res->lenHints.length) && + ndr_write_uint32(context, s, res->lenHints.maxLength) /*&& + ndr_write_BYTE_ptr(context, s, (BYTE*)res->Buffer, res->Length)*/ + ; +} +#endif + +void ndr_dump_RPC_UNICODE_STRING(wLog* logger, UINT32 lvl, size_t indentLevel, + const RPC_UNICODE_STRING* obj) +{ + WINPR_UNUSED(indentLevel); + WLog_Print(logger, lvl, "\tLength=%d MaximumLength=%d", obj->lenHints.length, + obj->lenHints.maxLength); + winpr_HexLogDump(logger, lvl, obj->Buffer, obj->lenHints.length); +} + +static void ndr_descr_dump_RPC_UNICODE_STRING(wLog* logger, UINT32 lvl, size_t indentLevel, + const void* obj) +{ + ndr_dump_RPC_UNICODE_STRING(logger, lvl, indentLevel, obj); +} + +void ndr_destroy_RPC_UNICODE_STRING(NdrContext* context, const void* hints, RPC_UNICODE_STRING* obj) +{ + WINPR_UNUSED(context); + WINPR_UNUSED(hints); + if (!obj) + return; + free(obj->Buffer); + obj->Buffer = NULL; +} + +static void ndr_descr_destroy_RPC_UNICODE_STRING(NdrContext* context, const void* hints, void* obj) +{ + ndr_destroy_RPC_UNICODE_STRING(context, hints, obj); +} + +static const NdrMessageDescr RPC_UNICODE_STRING_descr_s = { NDR_ARITY_SIMPLE, + sizeof(RPC_UNICODE_STRING), + ndr_descr_read_RPC_UNICODE_STRING, + /*ndr_write_RPC_UNICODE_STRING*/ NULL, + ndr_descr_destroy_RPC_UNICODE_STRING, + ndr_descr_dump_RPC_UNICODE_STRING }; + +NdrMessageType ndr_RPC_UNICODE_STRING_descr(void) +{ + return &RPC_UNICODE_STRING_descr_s; +} + +/* ========================= RPC_UNICODE_STRING_Array ======================== */ + +static BOOL ndr_read_RPC_UNICODE_STRING_Array(NdrContext* context, wStream* s, const void* hints, + void* v) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(hints); + return ndr_read_uconformant_array(context, s, hints, ndr_RPC_UNICODE_STRING_descr(), v); +} + +static BOOL ndr_write_RPC_UNICODE_STRING_Array(NdrContext* context, wStream* s, const void* ghints, + const void* v) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(ghints); + + const NdrArrayHints* hints = (const NdrArrayHints*)ghints; + + return ndr_write_uconformant_array(context, s, hints->count, ndr_RPC_UNICODE_STRING_descr(), v); +} + +static const NdrMessageDescr RPC_UNICODE_STRING_Array_descr_s = { + NDR_ARITY_ARRAYOF, + sizeof(RPC_UNICODE_STRING), + ndr_read_RPC_UNICODE_STRING_Array, + ndr_write_RPC_UNICODE_STRING_Array, + NULL, + NULL +}; + +static NdrMessageType ndr_RPC_UNICODE_STRING_Array_descr(void) +{ + return &RPC_UNICODE_STRING_Array_descr_s; +} + +/* ========================== KERB_RPC_INTERNAL_NAME ======================== */ + +BOOL ndr_read_KERB_RPC_INTERNAL_NAME(NdrContext* context, wStream* s, const void* hints, + KERB_RPC_INTERNAL_NAME* res) +{ + WINPR_ASSERT(res); + + union + { + RPC_UNICODE_STRING** ppstr; + void* pv; + } cnv; + cnv.ppstr = &res->Names; + NdrDeferredEntry names = { NDR_PTR_NULL, "KERB_RPC_INTERNAL_NAME.Names", &res->nameHints, + cnv.pv, ndr_RPC_UNICODE_STRING_Array_descr() }; + + UINT16 nameCount = 0; + WINPR_UNUSED(hints); + + if (!ndr_read_uint16(context, s, &res->NameType) || !ndr_read_uint16(context, s, &nameCount)) + return FALSE; + + res->nameHints.count = nameCount; + + return ndr_read_refpointer(context, s, &names.ptrId) && ndr_push_deferreds(context, &names, 1); +} + +static BOOL ndr_descr_read_KERB_RPC_INTERNAL_NAME(NdrContext* context, wStream* s, + const void* hints, void* res) +{ + return ndr_read_KERB_RPC_INTERNAL_NAME(context, s, hints, res); +} + +BOOL ndr_write_KERB_RPC_INTERNAL_NAME(NdrContext* context, wStream* s, const void* hints, + const KERB_RPC_INTERNAL_NAME* res) +{ + WINPR_UNUSED(context); + WINPR_UNUSED(s); + WINPR_UNUSED(hints); + WINPR_UNUSED(res); + WLog_ERR(TAG, "TODO: implement this"); + return FALSE; +} + +void ndr_dump_KERB_RPC_INTERNAL_NAME(wLog* logger, UINT32 lvl, size_t indentLevel, + const KERB_RPC_INTERNAL_NAME* obj) +{ + WINPR_UNUSED(indentLevel); + WINPR_UNUSED(obj); + WLog_Print(logger, lvl, "TODO: implement this"); +} + +static void ndr_descr_dump_KERB_RPC_INTERNAL_NAME(wLog* logger, UINT32 lvl, size_t indentLevel, + const void* obj) +{ + ndr_dump_KERB_RPC_INTERNAL_NAME(logger, lvl, indentLevel, obj); +} + +void ndr_destroy_KERB_RPC_INTERNAL_NAME(NdrContext* context, const void* hints, + KERB_RPC_INTERNAL_NAME* obj) +{ + WINPR_UNUSED(hints); + if (!obj) + return; + + for (UINT32 i = 0; i < obj->nameHints.count; i++) + ndr_destroy_RPC_UNICODE_STRING(context, NULL, &obj->Names[i]); + + free(obj->Names); + obj->Names = NULL; +} + +static void ndr_descr_destroy_KERB_RPC_INTERNAL_NAME(NdrContext* context, const void* hints, + void* obj) +{ + ndr_destroy_KERB_RPC_INTERNAL_NAME(context, hints, obj); +} + +static NdrMessageDescr KERB_RPC_INTERNAL_NAME_descr_s = { NDR_ARITY_SIMPLE, + sizeof(KERB_RPC_INTERNAL_NAME), + ndr_descr_read_KERB_RPC_INTERNAL_NAME, + NULL, + ndr_descr_destroy_KERB_RPC_INTERNAL_NAME, + ndr_descr_dump_KERB_RPC_INTERNAL_NAME }; + +NdrMessageType ndr_KERB_RPC_INTERNAL_NAME_descr(void) +{ + return &KERB_RPC_INTERNAL_NAME_descr_s; +} + +/* ========================== KERB_RPC_ENCRYPTION_KEY ======================== */ + +static const NdrFieldStruct KERB_RPC_ENCRYPTION_KEY_fields[] = { + { "reserved1", offsetof(KERB_RPC_ENCRYPTION_KEY, reserved1), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, + { "reserved2", offsetof(KERB_RPC_ENCRYPTION_KEY, reserved2), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, + { "reserved3", offsetof(KERB_RPC_ENCRYPTION_KEY, reserved3), NDR_NOT_POINTER, -1, + &ndr_KERB_RPC_OCTET_STRING_descr_s } +}; +static const NdrStructDescr KERB_RPC_ENCRYPTION_KEY_struct = { + "KERB_RPC_ENCRYPTION_KEY", ARRAYSIZE(KERB_RPC_ENCRYPTION_KEY_fields), + KERB_RPC_ENCRYPTION_KEY_fields +}; + +RDPEAR_SIMPLE_MESSAGE_TYPE(KERB_RPC_ENCRYPTION_KEY) + +/* ========================== BuildEncryptedAuthDataReq ======================== */ + +static const NdrFieldStruct BuildEncryptedAuthDataReq_fields[] = { + { "KeyUsage", offsetof(BuildEncryptedAuthDataReq, KeyUsage), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, + { "key", offsetof(BuildEncryptedAuthDataReq, Key), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s }, + { "plainAuthData", offsetof(BuildEncryptedAuthDataReq, PlainAuthData), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_ASN1_DATA_descr_s } +}; +static const NdrStructDescr BuildEncryptedAuthDataReq_struct = { + "BuildEncryptedAuthDataReq", ARRAYSIZE(BuildEncryptedAuthDataReq_fields), + BuildEncryptedAuthDataReq_fields +}; + +RDPEAR_SIMPLE_MESSAGE_TYPE(BuildEncryptedAuthDataReq) + +/* ========================== ComputeTgsChecksumReq ======================== */ + +static const NdrFieldStruct ComputeTgsChecksumReq_fields[] = { + { "requestBody", offsetof(ComputeTgsChecksumReq, requestBody), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "key", offsetof(ComputeTgsChecksumReq, Key), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s }, + { "ChecksumType", offsetof(ComputeTgsChecksumReq, ChecksumType), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s } +}; +static const NdrStructDescr ComputeTgsChecksumReq_struct = { + "ComputeTgsChecksumReq", ARRAYSIZE(ComputeTgsChecksumReq_fields), ComputeTgsChecksumReq_fields +}; + +RDPEAR_SIMPLE_MESSAGE_TYPE(ComputeTgsChecksumReq) + +/* ========================== CreateApReqAuthenticatorReq ======================== */ + +static const NdrFieldStruct CreateApReqAuthenticatorReq_fields[] = { + { "EncryptionKey", offsetof(CreateApReqAuthenticatorReq, EncryptionKey), NDR_POINTER_NON_NULL, + -1, &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s }, + { "SequenceNumber", offsetof(CreateApReqAuthenticatorReq, SequenceNumber), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, + { "ClientName", offsetof(CreateApReqAuthenticatorReq, ClientName), NDR_POINTER_NON_NULL, -1, + &KERB_RPC_INTERNAL_NAME_descr_s }, + { "ClientRealm", offsetof(CreateApReqAuthenticatorReq, ClientRealm), NDR_POINTER_NON_NULL, -1, + &RPC_UNICODE_STRING_descr_s }, + { "SkewTime", offsetof(CreateApReqAuthenticatorReq, SkewTime), NDR_POINTER_NON_NULL, -1, + &ndr_uint64_descr_s }, + { "SubKey", offsetof(CreateApReqAuthenticatorReq, SubKey), NDR_POINTER, -1, + &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s }, + { "AuthData", offsetof(CreateApReqAuthenticatorReq, AuthData), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "GssChecksum", offsetof(CreateApReqAuthenticatorReq, GssChecksum), NDR_POINTER, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "KeyUsage", offsetof(CreateApReqAuthenticatorReq, KeyUsage), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, +}; +static const NdrStructDescr CreateApReqAuthenticatorReq_struct = { + "CreateApReqAuthenticatorReq", ARRAYSIZE(CreateApReqAuthenticatorReq_fields), + CreateApReqAuthenticatorReq_fields +}; + +RDPEAR_SIMPLE_MESSAGE_TYPE(CreateApReqAuthenticatorReq) + +/* ========================== CreateApReqAuthenticatorResp ======================== */ + +static const NdrFieldStruct CreateApReqAuthenticatorResp_fields[] = { + { "AuthenticatorTime", offsetof(CreateApReqAuthenticatorResp, AuthenticatorTime), + NDR_NOT_POINTER, -1, &ndr_uint64_descr_s }, + { "Authenticator", offsetof(CreateApReqAuthenticatorResp, Authenticator), NDR_NOT_POINTER, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "KerbProtocolError", offsetof(CreateApReqAuthenticatorResp, KerbProtocolError), + NDR_NOT_POINTER, -1, &ndr_uint32_descr_s }, +}; + +static const NdrStructDescr CreateApReqAuthenticatorResp_struct = { + "CreateApReqAuthenticatorResp", ARRAYSIZE(CreateApReqAuthenticatorResp_fields), + CreateApReqAuthenticatorResp_fields +}; + +RDPEAR_SIMPLE_MESSAGE_TYPE(CreateApReqAuthenticatorResp) + +/* ========================== UnpackKdcReplyBodyReq ======================== */ + +static const NdrFieldStruct UnpackKdcReplyBodyReq_fields[] = { + { "EncryptedData", offsetof(UnpackKdcReplyBodyReq, EncryptedData), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "Key", offsetof(UnpackKdcReplyBodyReq, Key), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s }, + { "StrenghtenKey", offsetof(UnpackKdcReplyBodyReq, StrengthenKey), NDR_POINTER, -1, + &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s }, + { "Pdu", offsetof(UnpackKdcReplyBodyReq, Pdu), NDR_NOT_POINTER, -1, &ndr_uint32_descr_s }, + { "KeyUsage", offsetof(UnpackKdcReplyBodyReq, KeyUsage), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, +}; + +static const NdrStructDescr UnpackKdcReplyBodyReq_struct = { + "UnpackKdcReplyBodyReq", ARRAYSIZE(UnpackKdcReplyBodyReq_fields), UnpackKdcReplyBodyReq_fields +}; + +RDPEAR_SIMPLE_MESSAGE_TYPE(UnpackKdcReplyBodyReq) + +/* ========================== UnpackKdcReplyBodyResp ======================== */ + +static const NdrFieldStruct UnpackKdcReplyBodyResp_fields[] = { + { "KerbProtocolError", offsetof(UnpackKdcReplyBodyResp, KerbProtocolError), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, + { "ReplyBody", offsetof(UnpackKdcReplyBodyResp, ReplyBody), NDR_NOT_POINTER, -1, + &ndr_KERB_ASN1_DATA_descr_s } +}; + +static const NdrStructDescr UnpackKdcReplyBodyResp_struct = { + "UnpackKdcReplyBodyResp", ARRAYSIZE(UnpackKdcReplyBodyResp_fields), + UnpackKdcReplyBodyResp_fields +}; + +RDPEAR_SIMPLE_MESSAGE_TYPE(UnpackKdcReplyBodyResp) + +/* ========================== DecryptApReplyReq ======================== */ + +static const NdrFieldStruct DecryptApReplyReq_fields[] = { + { "EncryptedReply", offsetof(DecryptApReplyReq, EncryptedReply), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "Key", offsetof(DecryptApReplyReq, Key), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s } +}; + +static const NdrStructDescr DecryptApReplyReq_struct = { "DecryptApReplyReq", + ARRAYSIZE(DecryptApReplyReq_fields), + DecryptApReplyReq_fields }; + +RDPEAR_SIMPLE_MESSAGE_TYPE(DecryptApReplyReq) + +/* ========================== PackApReplyReq ======================== */ + +static const NdrFieldStruct PackApReplyReq_fields[] = { + { "Reply", offsetof(PackApReplyReq, Reply), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "ReplyBody", offsetof(PackApReplyReq, ReplyBody), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_ASN1_DATA_descr_s }, + { "SessionKey", offsetof(PackApReplyReq, SessionKey), NDR_POINTER_NON_NULL, -1, + &ndr_KERB_RPC_ENCRYPTION_KEY_descr_s } +}; + +static const NdrStructDescr PackApReplyReq_struct = { "PackApReplyReq", + ARRAYSIZE(PackApReplyReq_fields), + PackApReplyReq_fields }; + +RDPEAR_SIMPLE_MESSAGE_TYPE(PackApReplyReq) + +/* ========================== PackApReplyResp ======================== */ + +static const NdrFieldStruct PackApReplyResp_fields[] = { + { "PackedReplySize", offsetof(PackApReplyResp, PackedReplyHints), NDR_NOT_POINTER, -1, + &ndr_uint32_descr_s }, + { "PackedReply", offsetof(PackApReplyResp, PackedReply), NDR_POINTER_NON_NULL, 0, + &ndr_uint8Array_descr_s }, +}; + +static const NdrStructDescr PackApReplyResp_struct = { "PackApReplyResp", + ARRAYSIZE(PackApReplyResp_fields), + PackApReplyResp_fields }; + +RDPEAR_SIMPLE_MESSAGE_TYPE(PackApReplyResp) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0a09a4ac0f7094cb74c5c05b78a80d390ab89351 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/CMakeLists.txt @@ -0,0 +1,30 @@ +set(MODULE_NAME "TestRdpear") +set(MODULE_PREFIX "TEST_RDPEAR") + +set(TEST_RDPEAR_DRIVER TestRdpear.c) + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(TEST_RDPEAR_TESTS TestNdr.c) + +if(BUILD_TESTING_INTERNAL) + list(APPEND TEST_RDPEAR_TESTS TestNdrEar.c) +endif() + +create_test_sourcelist(TEST_RDPEAR_SRCS TestRdpear.c ${TEST_RDPEAR_TESTS}) + +add_executable(${MODULE_NAME} ${TEST_RDPEAR_SRCS}) + +add_compile_definitions(TESTING_OUTPUT_DIRECTORY="${PROJECT_BINARY_DIR}") +add_compile_definitions(TESTING_SRC_DIRECTORY="${PROJECT_SOURCE_DIR}") + +target_link_libraries(${MODULE_NAME} freerdp winpr freerdp-client) + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${${MODULE_PREFIX}_TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Rdpear/Test") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/TestNdr.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/TestNdr.c new file mode 100644 index 0000000000000000000000000000000000000000..934ff11c552924e10603c952300982e95309a942 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/TestNdr.c @@ -0,0 +1,40 @@ +#include + +int TestNdr(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + int retCode = -2; + NdrContext* context = ndr_context_new(FALSE, 1); + if (!context) + return -1; + + BYTE payload[] = { + // == conformant array == + 0x02, 0x00, 0x00, 0x00, // (nitems) + 0x30, 0x00, // content + 0x00, 0x00 // (padding) + }; + wStream staticS; + wStream* s = Stream_StaticInit(&staticS, payload, sizeof(payload)); + + BYTE* target = NULL; + NdrArrayHints hints = { 2 }; + NdrDeferredEntry e = { 0x020028, "arrayContent", &hints, (void*)&target, + ndr_uint8Array_descr() }; + + if (!ndr_push_deferreds(context, &e, 1)) + goto out; + + if (!ndr_treat_deferred_read(context, s)) + goto out; + + NdrMessageType descr = ndr_uint8Array_descr(); + descr->destroyFn(context, &hints, target); + free(target); + retCode = 0; +out: + ndr_context_destroy(&context); + return retCode; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/TestNdrEar.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/TestNdrEar.c new file mode 100644 index 0000000000000000000000000000000000000000..a9112b1c39ab6c089a3d49e138688aeecc00ae94 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpear/common/test/TestNdrEar.c @@ -0,0 +1,381 @@ +#include + +#include +#include + +#ifndef MAX +#define MAX(a, b) ((a) > (b)) ? (a) : (b) +#endif +#ifndef MIN +#define MIN(a, b) ((a) < (b)) ? (a) : (b) +#endif + +static BYTE nextValue(BYTE old, INT32 offset, char symbol, char startSymbol) +{ + const INT32 uold = 16 * old; + const INT32 diff = symbol - startSymbol; + const INT32 res = uold + diff + offset; + return (BYTE)MIN(MAX(0, res), UINT8_MAX); +} + +static BYTE* parseHexBlock(const char* str, size_t* plen) +{ + WINPR_ASSERT(str); + WINPR_ASSERT(plen); + + BYTE* ret = malloc(strlen(str) / 2); + BYTE* dest = ret; + const char* ptr = str; + BYTE tmp = 0; + size_t nchars = 0; + size_t len = 0; + + for (; *ptr; ptr++) + { + switch (*ptr) + { + case ' ': + case '\n': + case '\t': + if (nchars) + { + WLog_ERR("", "error parsing hex block, unpaired char"); + free(ret); + return NULL; + } + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + tmp = nextValue(tmp, 0, *ptr, '0'); + nchars++; + if (nchars == 2) + { + *dest = tmp; + dest++; + len++; + tmp = 0; + nchars = 0; + } + break; + + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + tmp = nextValue(tmp, 10, *ptr, 'a'); + nchars++; + if (nchars == 2) + { + *dest = tmp; + dest++; + len++; + tmp = 0; + nchars = 0; + } + break; + + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + tmp = nextValue(tmp, 10, *ptr, 'A'); + nchars++; + if (nchars == 2) + { + *dest = tmp; + dest++; + len++; + tmp = 0; + nchars = 0; + } + break; + default: + WLog_ERR("", "invalid char in hex block"); + free(ret); + return NULL; + } + } + + *plen = len; + return ret; +} + +static int TestNdrEarWrite(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + int rc = -1; + BYTE buffer[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; + KERB_ASN1_DATA asn1 = { 7, { 16 }, buffer }; + + wStream* s = Stream_New(NULL, 100); + if (!s) + return -1; + + NdrContext* context = ndr_context_new(FALSE, 1); + if (!context) + goto fail; + + if (!ndr_write_KERB_ASN1_DATA(context, s, NULL, &asn1)) + goto fail; + if (!ndr_treat_deferred_write(context, s)) + goto fail; + + // winpr_HexDump("", WLOG_DEBUG, Stream_Buffer(s), Stream_GetPosition(s)); + + rc = 0; +fail: + ndr_context_destroy(&context); + Stream_Free(s, TRUE); + return rc; +} + +static int TestNdrEarRead(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + int retCode = -2; + + /* ====================================================================== */ + NdrContext* context = ndr_context_new(FALSE, 1); + if (!context) + return -1; + + wStream staticS = { 0 }; + wStream* s = NULL; + +#if 0 + BYTE payload[] = { + 0x00, 0x00, 0x00, 0x00, // (PduType) + 0x02, 0x00, 0x00, 0x00, // (Length) + 0x28, 0x00, 0x02, 0x00, // (Asn1Buffer) + + // == conformant array == + 0x02, 0x00, 0x00, 0x00, // (nitems) + 0x30, 0x00, // content + 0x00, 0x00 // (padding) + }; + s = Stream_StaticInit(&staticS, payload, sizeof(payload)); + + KERB_ASN1_DATA asn1 = { 0 }; + if (!ndr_read_KERB_ASN1_DATA(context, s, NULL, &asn1) || !ndr_treat_deferred_read(context, s) || + asn1.Asn1BufferHints.count != 2 || *asn1.Asn1Buffer != 0x30) + goto out; + KERB_ASN1_DATA_destroy(context, &asn1); + ndr_context_reset(context); + + /* ====================================================================== */ + BYTE payload2[] = { + // ------------ a RPC_UNICODE_STRING: Administrateur ------------------------- + 0x1c, 0x00, // (Length) + 0x1e, 0x00, // (MaximumLength) + 0x1c, 0x00, 0x02, 0x00, // (Buffer ptr) + // == conformant array == + 0x0f, 0x00, 0x00, 0x00, // (maximum count) + 0x00, 0x00, 0x00, 0x00, // (offset) + 0x0e, 0x00, 0x00, 0x00, // (length) + + 0x48, 0x00, 0x41, 0x00, 0x52, 0x00, 0x44, 0x00, 0x45, 0x00, 0x4e, 0x00, 0x49, 0x00, 0x4e, + 0x00, 0x47, 0x00, 0x33, 0x00, 0x2e, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x4d, 0x00, 0x00, 0x00, + + 0x00, 0x00 + }; + retCode = -3; + + s = Stream_StaticInit(&staticS, payload2, sizeof(payload2)); + RPC_UNICODE_STRING unicode = { 0 }; + if (!ndr_read_RPC_UNICODE_STRING(context, s, NULL, &unicode) || !ndr_treat_deferred_read(context, s)) + goto out; + RPC_UNICODE_STRING_destroy(context, &unicode); + ndr_context_reset(context); + + /* ====================================================================== */ + BYTE payload3[] = { + // ------------ an KERB_RPC_INTERNAL_NAME: HARDENING3.COM ------------------------- + 0x01, 0x00, // (NameType) + 0x01, 0x00, // (NameCount) + 0x10, 0x00, 0x02, 0x00, // (Names) + // == conformant array == + 0x01, 0x00, 0x00, 0x00, // (nitems) + + // = RPC_UNICODE_STRING = + 0x1c, 0x00, // (Length) + 0x1e, 0x00, // (MaximumLength) + 0x14, 0x00, 0x02, 0x00, /// (Buffer ptr) + // == Uni-dimensional Conformant-varying Array == + 0x0f, 0x00, 0x00, 0x00, // (maximum count) + 0x00, 0x00, 0x00, 0x00, // (offset) + 0x0e, 0x00, 0x00, 0x00, // (length) + 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74, + 0x00, 0x72, 0x00, 0x61, 0x00, 0x74, 0x00, 0x65, 0x00, 0x75, 0x00, 0x72, 0x00, 0x00, 0x00, + + 0x00, 0x00 + }; + KERB_RPC_INTERNAL_NAME intName = { 0 }; + retCode = -4; + s = Stream_StaticInit(&staticS, payload3, sizeof(payload3)); + if (!ndr_read_KERB_RPC_INTERNAL_NAME(context, s, NULL, &intName) || !ndr_treat_deferred_read(context, s)) + goto out; + KERB_RPC_INTERNAL_NAME_destroy(context, &intName); + ndr_context_reset(context); +#endif + + /* ====================================================================== */ +#if 0 + BYTE payload4[] = { + 0x03, 0x01, 0x03, 0x01, // unionId / unionId + 0x04, 0x00, 0x02, 0x00, // (EncryptionKey ptr) + 0xf8, 0xca, 0x95, 0x11, // (SequenceNumber) + 0x0c, 0x00, 0x02, 0x00, // (ClientName ptr) + 0x18, 0x00, 0x02, 0x00, // (ClientRealm ptr) + 0x20, 0x00, 0x02, 0x00, // (SkewTime ptr) + 0x00, 0x00, 0x00, 0x00, // (SubKey ptr) + 0x24, 0x00, 0x02, 0x00, // (AuthData ptr) + 0x2c, 0x00, 0x02, 0x00, // (GssChecksum ptr) + 0x07, 0x00, 0x00, 0x00, // (KeyUsage) + + // === EncryptionKey === + 0x40, 0xe9, 0x12, 0xdf, // reserved1 + 0x12, 0x00, 0x00, 0x00, // reserved2 + // KERB_RPC_OCTET_STRING + 0x4c, 0x00, 0x00, 0x00, // (length) + 0x08, 0x00, 0x02, 0x00, // (value ptr) + // == conformant array == + 0x4c, 0x00, 0x00, 0x00, // (length) + 0xc4, 0x41, 0xee, 0x34, + 0x82, 0x2b, 0x29, 0x61, 0xe2, 0x96, 0xb5, 0x75, 0x61, 0x2d, 0xbf, 0x86, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x89, 0x08, 0x60, 0x2e, + 0x30, 0x3e, 0xfe, 0x56, 0x11, 0xf0, 0x31, 0xf2, 0xd6, 0x2e, 0x3d, 0x33, 0xfe, 0xce, 0x56, 0x12, + 0xbf, 0xb2, 0xe5, 0x86, 0x29, 0x8d, 0x29, 0x74, 0x1f, 0x8a, 0xf9, 0xb9, 0x8c, 0xd4, 0x86, 0x3a, + 0x21, 0x92, 0xb2, 0x07, 0x95, 0x4b, 0xea, 0xee, + + //=== ClientName - KERB_RPC_INTERNAL_NAME === + 0x01, 0x00, // (NameType) + 0x01, 0x00, // (NameCount) + 0x10, 0x00, 0x02, 0x00, // (Names) + + 0x01, 0x00, 0x00, 0x00, // (nitems) + + // = RPC_UNICODE_STRING = + 0x1c, 0x00, // (Length) + 0x1e, 0x00, // (MaximumLength) + 0x14, 0x00, 0x02, 0x00, //(Buffer ptr) + // == Uni-dimensional Conformant-varying Array == + 0x0f, 0x00, 0x00, 0x00, // (maximum count) + 0x00, 0x00, 0x00, 0x00, // (offset) + 0x0e, 0x00, 0x00, 0x00, // (length) + 0x41, 0x00, 0x64, 0x00, 0x6d, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x73, 0x00, 0x74, 0x00, + 0x72, 0x00, 0x61, 0x00, 0x74, 0x00, 0x65, 0x00, 0x75, 0x00, 0x72, 0x00, + + // === ClientRealm - RPC_UNICODE_STRING === + 0x1c, 0x00, // (Length) + 0x1e, 0x00, // (MaximumLength) + 0x1c, 0x00, 0x02, 0x00, // (Buffer ptr) + // == Uni-dimensional conformant varying array == + 0x0f, 0x00, 0x00, 0x00, // (maximum count) + 0x00, 0x00, 0x00, 0x00, // (offset) + 0x0e, 0x00, 0x00, 0x00, // (length) + 0x48, 0x00, 0x41, 0x00, 0x52, 0x00, 0x44, 0x00, 0x45, 0x00, 0x4e, 0x00, 0x49, 0x00, 0x4e, 0x00, + 0x47, 0x00, 0x33, 0x00, 0x2e, 0x00, 0x43, 0x00, 0x4f, 0x00, 0x4d, 0x00, + + 0x00, 0x00, 0x00, 0x00, // padding + + // == SkewTime == + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + // === AuthData - KERB_ASN1_DATA == + 0x00, 0x00, 0x00, 0x00, // (PduType) + 0x02, 0x00, 0x00, 0x00, // (Length) + 0x28, 0x00, 0x02, 0x00, // (Asn1Buffer) + // == conformant array == + 0x02, 0x00, 0x00, 0x00, // (nitems) + 0x30, 0x00, + 0x00, 0x00, // (padding) + + // === GssChecksum - KERB_ASN1_DATA === + 0x08, 0x00, 0x00, 0x00, // (PduType) + 0x1b, 0x00, 0x00, 0x00, // (Length) + 0x30, 0x00, 0x02, 0x00, // (Asn1Buffer) + // == conformant array == + 0x1b, 0x00, 0x00, 0x00, // (length) + 0x30, 0x19, + 0xa0, 0x03, + 0x02, 0x01, 0x07, + 0xa1, 0x12, + 0x04, 0x10, 0xb9, 0x4f, 0xcd, 0xae, 0xd9, 0xa8, 0xff, 0x49, 0x69, 0x5a, 0xd1, + 0x1d, 0x38, 0x49, 0xb6, 0x92, 0x00 + }; + size_t sizeofPayload4 = sizeof(payload4); +#endif +#if 1 + size_t sizeofPayload4 = 0; + BYTE* payload4 = parseHexBlock("03 01 03 01 \ + 04 00 02 00 38 9e ef 6b 0c 00 02 00 18 00 02 00 \ + 20 00 02 00 00 00 00 00 24 00 02 00 2c 00 02 00 \ + 07 00 00 00 13 8a a5 a8 12 00 00 00 20 00 00 00 \ + 08 00 02 00 20 00 00 00 c9 03 42 a8 17 8f d9 c4 \ + 9b d2 c4 6e 73 64 98 7b 90 f5 9a 28 77 8e ca de \ + 29 2e a3 8d 8a 56 36 d5 01 00 01 00 10 00 02 00 \ + 01 00 00 00 1c 00 1e 00 14 00 02 00 0f 00 00 00 \ + 00 00 00 00 0e 00 00 00 41 00 64 00 6d 00 69 00 \ + 6e 00 69 00 73 00 74 00 72 00 61 00 74 00 65 00 \ + 75 00 72 00 1c 00 1e 00 1c 00 02 00 0f 00 00 00 \ + 00 00 00 00 0e 00 00 00 48 00 41 00 52 00 44 00 \ + 45 00 4e 00 49 00 4e 00 47 00 33 00 2e 00 43 00 \ + 4f 00 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 \ + 02 00 00 00 28 00 02 00 02 00 00 00 30 00 00 00 \ + 08 00 00 00 1b 00 00 00 30 00 02 00 1b 00 00 00 \ + 30 19 a0 03 02 01 07 a1 12 04 10 e4 aa ff 2b 93 \ + 97 4c f2 5c 0b 49 85 72 92 94 54 00", + &sizeofPayload4); + + if (!payload4) + goto out; +#endif + + CreateApReqAuthenticatorReq createApReqAuthenticatorReq = { 0 }; + s = Stream_StaticInit(&staticS, payload4, sizeofPayload4); + if (!ndr_skip_bytes(context, s, 4) || /* skip union id */ + !ndr_read_CreateApReqAuthenticatorReq(context, s, NULL, &createApReqAuthenticatorReq) || + !ndr_treat_deferred_read(context, s) || createApReqAuthenticatorReq.KeyUsage != 7 || + !createApReqAuthenticatorReq.EncryptionKey || createApReqAuthenticatorReq.SubKey || + !createApReqAuthenticatorReq.ClientName || + createApReqAuthenticatorReq.ClientName->nameHints.count != 1 || + !createApReqAuthenticatorReq.ClientRealm || !createApReqAuthenticatorReq.AuthData || + createApReqAuthenticatorReq.AuthData->Asn1BufferHints.count != 2 || + !createApReqAuthenticatorReq.SkewTime || + createApReqAuthenticatorReq.SkewTime->QuadPart != 0) + goto out; + ndr_destroy_CreateApReqAuthenticatorReq(context, NULL, &createApReqAuthenticatorReq); + ndr_context_reset(context); + + /* ============ successful end of test =============== */ + retCode = 0; +out: + free(payload4); + ndr_context_destroy(&context); + return retCode; +} + +int TestNdrEar(int argc, char* argv[]) +{ + const int rc = TestNdrEarWrite(argc, argv); + if (rc) + return rc; + return TestNdrEarRead(argc, argv); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..525d8d04195f8a4667ff73f82918503913ae9b31 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2022 Pascal Nowack +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdpecam") + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_CLIENT_CHANNELS) + option(RDPECAM_CLIENT_CHANNEL_STUB "Only build [MS-RDPECAM] channel stub" OFF) + if(NOT RDPECAM_CLIENT_CHANNEL_STUB) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) + endif() +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..ba12c2d8b1da275511228b54d68cd52ebd09dc86 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT OFF) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "rdpecam" + TYPE + "dynamic" + DESCRIPTION + "Video Capture Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPECAM]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/camera.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/camera.h new file mode 100644 index 0000000000000000000000000000000000000000..68282f28fbb490783601d49d93194f23d8dcbba5 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/camera.h @@ -0,0 +1,209 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * MS-RDPECAM Implementation, main header file + * + * Copyright 2024 Oleg Turovski + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CLIENT_CAMERA_H +#define FREERDP_CLIENT_CAMERA_H + +#include +#include +#include +#include + +#if defined(WITH_INPUT_FORMAT_MJPG) +#include +#endif + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#define ECAM_PROTO_VERSION 0x02 +/* currently supporting 1 stream per device */ +#define ECAM_DEVICE_MAX_STREAMS 1 +#define ECAM_MAX_MEDIA_TYPE_DESCRIPTORS 256 + +/* Allow to send up to that many unsolicited samples. + * For example, to support 30 fps with 250 ms round trip + * ECAM_MAX_SAMPLE_CREDITS has to be at least 8. + */ +#define ECAM_MAX_SAMPLE_CREDITS 8 + +/* Having this hardcoded allows to preallocate and reuse buffer + * for sample responses. Excessive size is to make sure any sample + * will fit in, even with highest resolution. + */ +#define ECAM_SAMPLE_RESPONSE_BUFFER_SIZE (1024ULL * 4050ULL) + +/* Special format addition for CAM_MEDIA_FORMAT enum formats + * used to support H264 stream muxed in MJPG container stream. + * The value picked not to overlap with enum values + */ +#define CAM_MEDIA_FORMAT_MJPG_H264 0x0401 + +typedef struct s_ICamHal ICamHal; + +typedef struct +{ + IWTSPlugin iface; + IWTSListener* listener; + GENERIC_LISTENER_CALLBACK* hlistener; + + /* HAL interface */ + ICamHal* ihal; + char* subsystem; + + BOOL initialized; + BOOL attached; + + UINT32 version; + wHashTable* devices; + +} CameraPlugin; + +typedef struct +{ + CAM_MEDIA_FORMAT inputFormat; /* camera side */ + CAM_MEDIA_FORMAT outputFormat; /* network side */ + +} CAM_MEDIA_FORMAT_INFO; + +typedef struct +{ + BOOL streaming; + CAM_MEDIA_FORMAT_INFO formats; + CAM_MEDIA_TYPE_DESCRIPTION currMediaType; + + GENERIC_CHANNEL_CALLBACK* hSampleReqChannel; + INT nSampleCredits; + wStream* sampleRespBuffer; + + H264_CONTEXT* h264; + +#if defined(WITH_INPUT_FORMAT_MJPG) + AVCodecContext* avContext; + AVPacket* avInputPkt; + AVFrame* avOutFrame; +#endif + +#if defined(WITH_INPUT_FORMAT_H264) + size_t h264FrameMaxSize; + BYTE* h264Frame; +#endif + + /* sws_scale */ + struct SwsContext* sws; + +} CameraDeviceStream; + +static INLINE CAM_MEDIA_FORMAT streamInputFormat(CameraDeviceStream* stream) +{ + return stream->formats.inputFormat; +} +static INLINE CAM_MEDIA_FORMAT streamOutputFormat(CameraDeviceStream* stream) +{ + return stream->formats.outputFormat; +} + +typedef struct +{ + IWTSListener* listener; + GENERIC_LISTENER_CALLBACK* hlistener; + CameraPlugin* ecam; + ICamHal* ihal; /* HAL interface, same as used by CameraPlugin */ + char deviceId[32]; + CameraDeviceStream streams[ECAM_DEVICE_MAX_STREAMS]; + +} CameraDevice; + +/** + * Subsystem (Hardware Abstraction Layer, HAL) Interface + */ + +typedef UINT (*ICamHalEnumCallback)(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, + const char* deviceId, const char* deviceName); + +/* may run in context of different thread */ +typedef UINT (*ICamHalSampleCapturedCallback)(CameraDevice* dev, int streamIndex, + const BYTE* sample, size_t size); + +struct s_ICamHal +{ + UINT(*Enumerate) + (ICamHal* ihal, ICamHalEnumCallback callback, CameraPlugin* ecam, + GENERIC_CHANNEL_CALLBACK* hchannel); + INT16(*GetMediaTypeDescriptions) + (ICamHal* ihal, const char* deviceId, int streamIndex, + const CAM_MEDIA_FORMAT_INFO* supportedFormats, size_t nSupportedFormats, + CAM_MEDIA_TYPE_DESCRIPTION* mediaTypes, size_t* nMediaTypes); + UINT(*StartStream) + (ICamHal* ihal, CameraDevice* dev, int streamIndex, const CAM_MEDIA_TYPE_DESCRIPTION* mediaType, + ICamHalSampleCapturedCallback callback); + UINT (*StopStream)(ICamHal* ihal, const char* deviceId, int streamIndex); + UINT (*Free)(ICamHal* hal); +}; + +typedef UINT (*PREGISTERCAMERAHAL)(IWTSPlugin* plugin, ICamHal* hal); + +typedef struct +{ + IWTSPlugin* plugin; + PREGISTERCAMERAHAL pRegisterCameraHal; + CameraPlugin* ecam; + const ADDIN_ARGV* args; + +} FREERDP_CAMERA_HAL_ENTRY_POINTS; + +typedef FREERDP_CAMERA_HAL_ENTRY_POINTS* PFREERDP_CAMERA_HAL_ENTRY_POINTS; + +/* entry point called by addin manager */ +typedef UINT(VCAPITYPE* PFREERDP_CAMERA_HAL_ENTRY)(PFREERDP_CAMERA_HAL_ENTRY_POINTS pEntryPoints); + +/* common functions */ +UINT ecam_channel_send_generic_msg(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, + CAM_MSG_ID msg); +UINT ecam_channel_send_error_response(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, + CAM_ERROR_CODE code); +UINT ecam_channel_write(CameraPlugin* ecam, GENERIC_CHANNEL_CALLBACK* hchannel, CAM_MSG_ID msg, + wStream* out, BOOL freeStream); + +/* ecam device interface */ +void ecam_dev_destroy(CameraDevice* dev); + +WINPR_ATTR_MALLOC(ecam_dev_destroy, 1) +CameraDevice* ecam_dev_create(CameraPlugin* ecam, const char* deviceId, const char* deviceName); + +/* video encoding interface */ +BOOL ecam_encoder_context_init(CameraDeviceStream* stream); +BOOL ecam_encoder_context_free(CameraDeviceStream* stream); +BOOL ecam_encoder_compress(CameraDeviceStream* stream, const BYTE* srcData, size_t srcSize, + BYTE** ppDstData, size_t* pDstSize); +UINT32 h264_get_max_bitrate(UINT32 height); + +#endif /* FREERDP_CLIENT_CAMERA_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/v4l/camera_v4l.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/v4l/camera_v4l.c new file mode 100644 index 0000000000000000000000000000000000000000..c2b7a69607fad3b3da1a225e31bffbd2869454b4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/v4l/camera_v4l.c @@ -0,0 +1,791 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * MS-RDPECAM Implementation, V4L Interface + * + * Copyright 2024 Oleg Turovski + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +/* v4l includes */ +#include + +#include "camera_v4l.h" +#include "uvc_h264.h" + +#define TAG CHANNELS_TAG("rdpecam-v4l.client") + +#define CAM_V4L2_BUFFERS_COUNT 4 +#define CAM_V4L2_CAPTURE_THREAD_SLEEP_MS 1000 + +#define CAM_V4L2_FRAMERATE_NUMERATOR_DEFAULT 30 +#define CAM_V4L2_FRAMERATE_DENOMINATOR_DEFAULT 1 + +typedef struct +{ + ICamHal iHal; + + wHashTable* streams; /* Index: deviceId, Value: CamV4lStream */ + +} CamV4lHal; + +static CamV4lStream* cam_v4l_stream_create(const char* deviceId, int streamIndex); +static void cam_v4l_stream_free(void* obj); +static void cam_v4l_stream_close_device(CamV4lStream* stream); +static UINT cam_v4l_stream_stop(CamV4lStream* stream); + +/** + * Function description + * + * @return NULL-terminated fourcc string + */ +static const char* cam_v4l_get_fourcc_str(unsigned int fourcc, char* buffer, size_t size) +{ + if (size < 5) + return NULL; + + buffer[0] = (char)(fourcc & 0xFF); + buffer[1] = (char)((fourcc >> 8) & 0xFF); + buffer[2] = (char)((fourcc >> 16) & 0xFF); + buffer[3] = (char)((fourcc >> 24) & 0xFF); + buffer[4] = '\0'; + return buffer; +} + +/** + * Function description + * + * @return one of V4L2_PIX_FMT + */ +static UINT32 ecamToV4L2PixFormat(CAM_MEDIA_FORMAT ecamFormat) +{ + switch (ecamFormat) + { + case CAM_MEDIA_FORMAT_H264: + return V4L2_PIX_FMT_H264; + case CAM_MEDIA_FORMAT_MJPG: + return V4L2_PIX_FMT_MJPEG; + case CAM_MEDIA_FORMAT_YUY2: + return V4L2_PIX_FMT_YUYV; + case CAM_MEDIA_FORMAT_NV12: + return V4L2_PIX_FMT_NV12; + case CAM_MEDIA_FORMAT_I420: + return V4L2_PIX_FMT_YUV420; + case CAM_MEDIA_FORMAT_RGB24: + return V4L2_PIX_FMT_RGB24; + case CAM_MEDIA_FORMAT_RGB32: + return V4L2_PIX_FMT_RGB32; + default: + WLog_ERR(TAG, "Unsupported CAM_MEDIA_FORMAT %d", ecamFormat); + return 0; + } +} + +/** + * Function description + * + * @return TRUE or FALSE + */ +static BOOL cam_v4l_format_supported(int fd, UINT32 format) +{ + struct v4l2_fmtdesc fmtdesc = { 0 }; + fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + for (fmtdesc.index = 0; ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc) == 0; fmtdesc.index++) + { + if (fmtdesc.pixelformat == format) + return TRUE; + } + return FALSE; +} + +/** + * Function description + * + * @return file descriptor + */ +static int cam_v4l_open_device(const char* deviceId, int flags) +{ + char device[20] = { 0 }; + int fd = -1; + struct v4l2_capability cap = { 0 }; + + if (!deviceId) + return -1; + + if (0 == strncmp(deviceId, "/dev/video", 10)) + return open(deviceId, flags); + + for (UINT n = 0; n < 64; n++) + { + (void)_snprintf(device, sizeof(device), "/dev/video%" PRIu32, n); + if ((fd = open(device, flags)) == -1) + continue; + + /* query device capabilities and make sure this is a video capture device */ + if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0 || !(cap.device_caps & V4L2_CAP_VIDEO_CAPTURE)) + { + close(fd); + continue; + } + + if (cap.bus_info[0] != 0 && 0 == strcmp((const char*)cap.bus_info, deviceId)) + return fd; + + close(fd); + } + + return fd; +} + +/** + * Function description + * + * @return -1 if error, otherwise index of supportedFormats array and mediaTypes/nMediaTypes filled + * in + */ +static INT16 cam_v4l_get_media_type_descriptions(ICamHal* ihal, const char* deviceId, + int streamIndex, + const CAM_MEDIA_FORMAT_INFO* supportedFormats, + size_t nSupportedFormats, + CAM_MEDIA_TYPE_DESCRIPTION* mediaTypes, + size_t* nMediaTypes) +{ + CamV4lHal* hal = (CamV4lHal*)ihal; + size_t maxMediaTypes = *nMediaTypes; + size_t nTypes = 0; + BOOL formatFound = FALSE; + + CamV4lStream* stream = (CamV4lStream*)HashTable_GetItemValue(hal->streams, deviceId); + + if (!stream) + { + stream = cam_v4l_stream_create(deviceId, streamIndex); + if (!stream) + return CAM_ERROR_CODE_OutOfMemory; + + if (!HashTable_Insert(hal->streams, deviceId, stream)) + { + cam_v4l_stream_free(stream); + return CAM_ERROR_CODE_UnexpectedError; + } + } + + int fd = cam_v4l_open_device(deviceId, O_RDONLY); + if (fd == -1) + { + WLog_ERR(TAG, "Unable to open device %s", deviceId); + return -1; + } + + size_t formatIndex = 0; + for (; formatIndex < nSupportedFormats; formatIndex++) + { + UINT32 pixelFormat = 0; + if (supportedFormats[formatIndex].inputFormat == CAM_MEDIA_FORMAT_MJPG_H264) + { + if (stream->h264UnitId > 0) + pixelFormat = V4L2_PIX_FMT_MJPEG; + else + continue; /* not supported */ + } + else + { + pixelFormat = ecamToV4L2PixFormat(supportedFormats[formatIndex].inputFormat); + } + + WINPR_ASSERT(pixelFormat != 0); + struct v4l2_frmsizeenum frmsize = { 0 }; + + if (!cam_v4l_format_supported(fd, pixelFormat)) + continue; + + frmsize.pixel_format = pixelFormat; + for (frmsize.index = 0; ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) == 0; frmsize.index++) + { + struct v4l2_frmivalenum frmival = { 0 }; + + if (frmsize.type != V4L2_FRMSIZE_TYPE_DISCRETE) + break; /* don't support size types other than discrete */ + + formatFound = TRUE; + mediaTypes->Width = frmsize.discrete.width; + mediaTypes->Height = frmsize.discrete.height; + mediaTypes->Format = supportedFormats[formatIndex].inputFormat; + + /* query frame rate (1st is highest fps supported) */ + frmival.index = 0; + frmival.pixel_format = pixelFormat; + frmival.width = frmsize.discrete.width; + frmival.height = frmsize.discrete.height; + if (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival) == 0 && + frmival.type == V4L2_FRMIVAL_TYPE_DISCRETE) + { + /* inverse of a fraction */ + mediaTypes->FrameRateNumerator = frmival.discrete.denominator; + mediaTypes->FrameRateDenominator = frmival.discrete.numerator; + } + else + { + WLog_DBG(TAG, "VIDIOC_ENUM_FRAMEINTERVALS failed, using default framerate"); + mediaTypes->FrameRateNumerator = CAM_V4L2_FRAMERATE_NUMERATOR_DEFAULT; + mediaTypes->FrameRateDenominator = CAM_V4L2_FRAMERATE_DENOMINATOR_DEFAULT; + } + + mediaTypes->PixelAspectRatioNumerator = mediaTypes->PixelAspectRatioDenominator = 1; + + char fourccstr[5] = { 0 }; + WLog_DBG(TAG, "Camera format: %s, width: %u, height: %u, fps: %u/%u", + cam_v4l_get_fourcc_str(pixelFormat, fourccstr, ARRAYSIZE(fourccstr)), + mediaTypes->Width, mediaTypes->Height, mediaTypes->FrameRateNumerator, + mediaTypes->FrameRateDenominator); + + mediaTypes++; + nTypes++; + + if (nTypes == maxMediaTypes) + { + WLog_ERR(TAG, "Media types reached buffer maximum %" PRIu32 "", maxMediaTypes); + goto error; + } + } + + if (formatFound) + { + /* we are interested in 1st supported format only, with all supported sizes */ + break; + } + } + +error: + + *nMediaTypes = nTypes; + close(fd); + if (formatIndex > INT16_MAX) + return -1; + return (INT16)formatIndex; +} + +/** + * Function description + * + * @return number of video capture devices + */ +static UINT cam_v4l_enumerate(ICamHal* ihal, ICamHalEnumCallback callback, CameraPlugin* ecam, + GENERIC_CHANNEL_CALLBACK* hchannel) +{ + UINT count = 0; + + for (UINT n = 0; n < 64; n++) + { + char device[20] = { 0 }; + struct v4l2_capability cap = { 0 }; + (void)_snprintf(device, sizeof(device), "/dev/video%" PRIu32, n); + int fd = open(device, O_RDONLY); + if (fd == -1) + continue; + + /* query device capabilities and make sure this is a video capture device */ + if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0 || !(cap.device_caps & V4L2_CAP_VIDEO_CAPTURE)) + { + close(fd); + continue; + } + count++; + + const char* deviceName = (char*)cap.card; + const char* deviceId = device; + if (cap.bus_info[0] != 0) /* may not be available in all drivers */ + deviceId = (char*)cap.bus_info; + + IFCALL(callback, ecam, hchannel, deviceId, deviceName); + + close(fd); + } + + return count; +} + +static void cam_v4l_stream_free_buffers(CamV4lStream* stream) +{ + if (!stream || !stream->buffers) + return; + + /* unmap buffers */ + for (size_t i = 0; i < stream->nBuffers; i++) + { + if (stream->buffers[i].length && stream->buffers[i].start != MAP_FAILED) + { + munmap(stream->buffers[i].start, stream->buffers[i].length); + } + } + + free(stream->buffers); + stream->buffers = NULL; + stream->nBuffers = 0; +} + +/** + * Function description + * + * @return 0 on failure, otherwise allocated buffer size + */ +static size_t cam_v4l_stream_alloc_buffers(CamV4lStream* stream) +{ + struct v4l2_requestbuffers rbuffer = { 0 }; + + rbuffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + rbuffer.memory = V4L2_MEMORY_MMAP; + rbuffer.count = CAM_V4L2_BUFFERS_COUNT; + + if (ioctl(stream->fd, VIDIOC_REQBUFS, &rbuffer) < 0 || rbuffer.count == 0) + { + WLog_ERR(TAG, "Failure in VIDIOC_REQBUFS, errno %d, count %d", errno, rbuffer.count); + return 0; + } + + stream->nBuffers = rbuffer.count; + + /* Map the buffers */ + stream->buffers = (CamV4lBuffer*)calloc(rbuffer.count, sizeof(CamV4lBuffer)); + if (!stream->buffers) + { + WLog_ERR(TAG, "Failure in calloc"); + return 0; + } + + for (unsigned int i = 0; i < rbuffer.count; i++) + { + struct v4l2_buffer buffer = { 0 }; + buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buffer.memory = V4L2_MEMORY_MMAP; + buffer.index = i; + + if (ioctl(stream->fd, VIDIOC_QUERYBUF, &buffer) < 0) + { + WLog_ERR(TAG, "Failure in VIDIOC_QUERYBUF, errno %d", errno); + cam_v4l_stream_free_buffers(stream); + return 0; + } + + stream->buffers[i].start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, MAP_SHARED, + stream->fd, buffer.m.offset); + + if (MAP_FAILED == stream->buffers[i].start) + { + WLog_ERR(TAG, "Failure in mmap, errno %d", errno); + cam_v4l_stream_free_buffers(stream); + return 0; + } + + stream->buffers[i].length = buffer.length; + + WLog_DBG(TAG, "Buffer %d mapped, size: %d", i, buffer.length); + + if (ioctl(stream->fd, VIDIOC_QBUF, &buffer) < 0) + { + WLog_ERR(TAG, "Failure in VIDIOC_QBUF, errno %d", errno); + cam_v4l_stream_free_buffers(stream); + return 0; + } + } + + return stream->buffers[0].length; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cam_v4l_stream_capture_thread(void* param) +{ + CamV4lStream* stream = (CamV4lStream*)param; + + int fd = stream->fd; + + do + { + int retVal = 0; + struct pollfd pfd = { 0 }; + + pfd.fd = fd; + pfd.events = POLLIN; + + retVal = poll(&pfd, 1, CAM_V4L2_CAPTURE_THREAD_SLEEP_MS); + + if (retVal == 0) + { + /* poll timed out */ + continue; + } + else if (retVal < 0) + { + WLog_DBG(TAG, "Failure in poll, errno %d", errno); + Sleep(CAM_V4L2_CAPTURE_THREAD_SLEEP_MS); /* trying to recover */ + continue; + } + else if (!(pfd.revents & POLLIN)) + { + WLog_DBG(TAG, "poll reported non-read event %d", pfd.revents); + Sleep(CAM_V4L2_CAPTURE_THREAD_SLEEP_MS); /* also trying to recover */ + continue; + } + + EnterCriticalSection(&stream->lock); + if (stream->streaming) + { + struct v4l2_buffer buf = { 0 }; + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buf.memory = V4L2_MEMORY_MMAP; + + /* dequeue buffers until empty */ + while (ioctl(fd, VIDIOC_DQBUF, &buf) != -1) + { + stream->sampleCallback(stream->dev, stream->streamIndex, + stream->buffers[buf.index].start, buf.bytesused); + + /* enqueue buffer back */ + if (ioctl(fd, VIDIOC_QBUF, &buf) == -1) + { + WLog_ERR(TAG, "Failure in VIDIOC_QBUF, errno %d", errno); + } + } + } + LeaveCriticalSection(&stream->lock); + + } while (stream->streaming); + + return CHANNEL_RC_OK; +} + +void cam_v4l_stream_close_device(CamV4lStream* stream) +{ + if (stream->fd != -1) + { + close(stream->fd); + stream->fd = -1; + } +} + +/** + * Function description + * + * @return Null on failure, otherwise pointer to new CamV4lStream + */ +static CamV4lStream* cam_v4l_stream_create(const char* deviceId, int streamIndex) +{ + CamV4lStream* stream = calloc(1, sizeof(CamV4lStream)); + + if (!stream) + { + WLog_ERR(TAG, "Failure in calloc"); + return NULL; + } + stream->streamIndex = streamIndex; + stream->fd = -1; + stream->h264UnitId = get_uvc_h624_unit_id(deviceId); + + if (!InitializeCriticalSectionEx(&stream->lock, 0, 0)) + { + WLog_ERR(TAG, "Failure in calloc"); + free(stream); + return NULL; + } + + return stream; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT cam_v4l_stream_stop(CamV4lStream* stream) +{ + if (!stream || !stream->streaming) + return CHANNEL_RC_OK; + + stream->streaming = FALSE; /* this will terminate capture thread */ + + if (stream->captureThread) + { + (void)WaitForSingleObject(stream->captureThread, INFINITE); + (void)CloseHandle(stream->captureThread); + stream->captureThread = NULL; + } + + EnterCriticalSection(&stream->lock); + + /* stop streaming */ + enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(stream->fd, VIDIOC_STREAMOFF, &type) < 0) + { + WLog_ERR(TAG, "Failure in VIDIOC_STREAMOFF, errno %d", errno); + } + + cam_v4l_stream_free_buffers(stream); + cam_v4l_stream_close_device(stream); + + LeaveCriticalSection(&stream->lock); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise CAM_ERROR_CODE + */ +static UINT cam_v4l_stream_start(ICamHal* ihal, CameraDevice* dev, int streamIndex, + const CAM_MEDIA_TYPE_DESCRIPTION* mediaType, + ICamHalSampleCapturedCallback callback) +{ + CamV4lHal* hal = (CamV4lHal*)ihal; + + CamV4lStream* stream = (CamV4lStream*)HashTable_GetItemValue(hal->streams, dev->deviceId); + + if (!stream) + { + WLog_ERR(TAG, "Unable to find stream, device %s, streamIndex %d", dev->deviceId, + streamIndex); + return CAM_ERROR_CODE_UnexpectedError; + } + + if (stream->streaming) + { + WLog_ERR(TAG, "Streaming already in progress, device %s, streamIndex %d", dev->deviceId, + streamIndex); + return CAM_ERROR_CODE_UnexpectedError; + } + + stream->dev = dev; + stream->sampleCallback = callback; + + if ((stream->fd = cam_v4l_open_device(dev->deviceId, O_RDWR | O_NONBLOCK)) == -1) + { + WLog_ERR(TAG, "Unable to open device %s", dev->deviceId); + return CAM_ERROR_CODE_UnexpectedError; + } + + struct v4l2_format video_fmt = { 0 }; + video_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + video_fmt.fmt.pix.sizeimage = 0; + + UINT32 pixelFormat = 0; + if (mediaType->Format == CAM_MEDIA_FORMAT_MJPG_H264) + { + pixelFormat = V4L2_PIX_FMT_MJPEG; + } + else + { + pixelFormat = ecamToV4L2PixFormat(mediaType->Format); + } + + if (pixelFormat == 0) + { + cam_v4l_stream_close_device(stream); + return CAM_ERROR_CODE_InvalidMediaType; + } + + video_fmt.fmt.pix.pixelformat = pixelFormat; + video_fmt.fmt.pix.width = mediaType->Width; + video_fmt.fmt.pix.height = mediaType->Height; + + /* set format and frame size */ + if (ioctl(stream->fd, VIDIOC_S_FMT, &video_fmt) < 0) + { + WLog_ERR(TAG, "Failure in VIDIOC_S_FMT, errno %d", errno); + cam_v4l_stream_close_device(stream); + return CAM_ERROR_CODE_InvalidMediaType; + } + + /* trying to set frame rate, if driver supports it */ + struct v4l2_streamparm sp1 = { 0 }; + struct v4l2_streamparm sp2 = { 0 }; + sp1.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(stream->fd, VIDIOC_G_PARM, &sp1) < 0 || + !(sp1.parm.capture.capability & V4L2_CAP_TIMEPERFRAME)) + { + WLog_INFO(TAG, "Driver doesn't support setting framerate"); + } + else + { + sp2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + + /* inverse of a fraction */ + sp2.parm.capture.timeperframe.numerator = mediaType->FrameRateDenominator; + sp2.parm.capture.timeperframe.denominator = mediaType->FrameRateNumerator; + + if (ioctl(stream->fd, VIDIOC_S_PARM, &sp2) < 0) + { + WLog_INFO(TAG, "Failed to set the framerate, errno %d", errno); + } + } + + if (mediaType->Format == CAM_MEDIA_FORMAT_MJPG_H264) + { + if (!set_h264_muxed_format(stream, mediaType)) + { + WLog_ERR(TAG, "Failure to set H264 muxed format"); + cam_v4l_stream_close_device(stream); + return CAM_ERROR_CODE_UnexpectedError; + } + + /* set pixelFormat for following WLog_INFO */ + pixelFormat = V4L2_PIX_FMT_H264; + } + + size_t maxSample = cam_v4l_stream_alloc_buffers(stream); + if (maxSample == 0) + { + WLog_ERR(TAG, "Failure to allocate video buffers"); + cam_v4l_stream_close_device(stream); + return CAM_ERROR_CODE_OutOfMemory; + } + + stream->streaming = TRUE; + + /* start streaming */ + enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(stream->fd, VIDIOC_STREAMON, &type) < 0) + { + WLog_ERR(TAG, "Failure in VIDIOC_STREAMON, errno %d", errno); + cam_v4l_stream_stop(stream); + return CAM_ERROR_CODE_UnexpectedError; + } + + stream->captureThread = CreateThread(NULL, 0, cam_v4l_stream_capture_thread, stream, 0, NULL); + if (!stream->captureThread) + { + WLog_ERR(TAG, "CreateThread failure"); + cam_v4l_stream_stop(stream); + return CAM_ERROR_CODE_OutOfMemory; + } + + char fourccstr[5] = { 0 }; + WLog_INFO(TAG, "Camera format: %s, width: %u, height: %u, fps: %u/%u", + cam_v4l_get_fourcc_str(pixelFormat, fourccstr, ARRAYSIZE(fourccstr)), + mediaType->Width, mediaType->Height, mediaType->FrameRateNumerator, + mediaType->FrameRateDenominator); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cam_v4l_stream_stop_by_device_id(ICamHal* ihal, const char* deviceId, int streamIndex) +{ + CamV4lHal* hal = (CamV4lHal*)ihal; + + CamV4lStream* stream = (CamV4lStream*)HashTable_GetItemValue(hal->streams, deviceId); + + if (!stream) + return CHANNEL_RC_OK; + + return cam_v4l_stream_stop(stream); +} + +/** + * Function description + * + * OBJECT_FREE_FN for streams hash table value + * + */ +void cam_v4l_stream_free(void* obj) +{ + CamV4lStream* stream = (CamV4lStream*)obj; + if (!stream) + return; + + cam_v4l_stream_stop(stream); + + DeleteCriticalSection(&stream->lock); + free(stream); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT cam_v4l_free(ICamHal* ihal) +{ + CamV4lHal* hal = (CamV4lHal*)ihal; + + if (hal == NULL) + return ERROR_INVALID_PARAMETER; + + HashTable_Free(hal->streams); + + free(hal); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE v4l_freerdp_rdpecam_client_subsystem_entry( + PFREERDP_CAMERA_HAL_ENTRY_POINTS pEntryPoints)) +{ + UINT ret = CHANNEL_RC_OK; + WINPR_ASSERT(pEntryPoints); + + CamV4lHal* hal = (CamV4lHal*)calloc(1, sizeof(CamV4lHal)); + + if (hal == NULL) + return CHANNEL_RC_NO_MEMORY; + + hal->iHal.Enumerate = cam_v4l_enumerate; + hal->iHal.GetMediaTypeDescriptions = cam_v4l_get_media_type_descriptions; + hal->iHal.StartStream = cam_v4l_stream_start; + hal->iHal.StopStream = cam_v4l_stream_stop_by_device_id; + hal->iHal.Free = cam_v4l_free; + + hal->streams = HashTable_New(FALSE); + if (!hal->streams) + { + ret = CHANNEL_RC_NO_MEMORY; + goto error; + } + + HashTable_SetupForStringData(hal->streams, FALSE); + + wObject* obj = HashTable_ValueObject(hal->streams); + WINPR_ASSERT(obj); + obj->fnObjectFree = cam_v4l_stream_free; + + if ((ret = pEntryPoints->pRegisterCameraHal(pEntryPoints->plugin, &hal->iHal))) + { + WLog_ERR(TAG, "RegisterCameraHal failed with error %" PRIu32 "", ret); + goto error; + } + + return ret; + +error: + cam_v4l_free(&hal->iHal); + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/v4l/uvc_h264.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/v4l/uvc_h264.c new file mode 100644 index 0000000000000000000000000000000000000000..0cfcedc36dbaf2815c41b3a1fc549e4659919b28 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/client/v4l/uvc_h264.c @@ -0,0 +1,474 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * MS-RDPECAM Implementation, UVC H264 support + * + * See USB_Video_Payload_H 264_1 0.pdf for more details + * + * Credits: + * guvcview http://guvcview.sourceforge.net + * Paulo Assis + * + * Copyright 2025 Oleg Turovski + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "uvc_h264.h" + +/* UVC H.264 extension unit GUID: {A29E7641-DE04-47E3-8B2B-F4341AFF003B} */ +static uint8_t GUID_UVCX_H264_XU[16] = { 0x41, 0x76, 0x9E, 0xA2, 0x04, 0xDE, 0xE3, 0x47, + 0x8B, 0x2B, 0xF4, 0x34, 0x1A, 0xFF, 0x00, 0x3B }; + +#define TAG CHANNELS_TAG("uvc_h264.client") + +/* + * get length of xu control defined by unit id and selector + * args: + * stream - pointer to video device data + * unit - unit id of xu control + * selector - selector for control + * + * returns: length of xu control + */ +static uint16_t get_length_xu_control(CamV4lStream* stream, uint8_t unit, uint8_t selector) +{ + WINPR_ASSERT(stream); + WINPR_ASSERT(stream->fd > 0); + + uint16_t length = 0; + + struct uvc_xu_control_query xu_ctrl_query = { .unit = unit, + .selector = selector, + .query = UVC_GET_LEN, + .size = sizeof(length), + .data = (uint8_t*)&length }; + + if (ioctl(stream->fd, UVCIOC_CTRL_QUERY, &xu_ctrl_query) < 0) + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "UVCIOC_CTRL_QUERY (GET_LEN) - Error: %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); + return 0; + } + + return length; +} + +/* + * runs a query on xu control defined by unit id and selector + * args: + * stream - pointer to video device data + * unit - unit id of xu control + * selector - selector for control + * query - query type + * data - pointer to query data + * + * returns: 0 if query succeeded or error code on fail + */ +static int query_xu_control(CamV4lStream* stream, uint8_t unit, uint8_t selector, uint8_t query, + void* data) +{ + int err = 0; + uint16_t len = get_length_xu_control(stream, unit, selector); + + struct uvc_xu_control_query xu_ctrl_query = { + .unit = unit, .selector = selector, .query = query, .size = len, .data = (uint8_t*)data + }; + + /*get query data*/ + if ((err = ioctl(stream->fd, UVCIOC_CTRL_QUERY, &xu_ctrl_query)) < 0) + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "UVCIOC_CTRL_QUERY (%" PRIu8 ") - Error: %s", query, + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); + } + + return err; +} + +/* + * resets the h264 encoder + * args: + * stream - pointer to video device data + * + * returns: 0 on success or error code on fail + */ +static int uvcx_video_encoder_reset(CamV4lStream* stream) +{ + WINPR_ASSERT(stream); + + uvcx_encoder_reset encoder_reset_req = { 0 }; + + int err = 0; + + if ((err = query_xu_control(stream, stream->h264UnitId, UVCX_ENCODER_RESET, UVC_SET_CUR, + &encoder_reset_req)) < 0) + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "UVCX_ENCODER_RESET error: %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); + } + + return err; +} + +/* + * probes the h264 encoder config + * args: + * stream - pointer to video device data + * query - probe query + * uvcx_video_config - pointer to probe/commit config data + * + * returns: 0 on success or error code on fail + */ +static int uvcx_video_probe(CamV4lStream* stream, uint8_t query, + uvcx_video_config_probe_commit_t* uvcx_video_config) +{ + WINPR_ASSERT(stream); + + int err = 0; + + if ((err = query_xu_control(stream, stream->h264UnitId, UVCX_VIDEO_CONFIG_PROBE, query, + uvcx_video_config)) < 0) + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "UVCX_VIDEO_CONFIG_PROBE error: %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); + } + + return err; +} + +/* + * commits the h264 encoder config + * args: + * stream - pointer to video device data + * uvcx_video_config - pointer to probe/commit config data + * + * returns: 0 on success or error code on fail + */ +static int uvcx_video_commit(CamV4lStream* stream, + uvcx_video_config_probe_commit_t* uvcx_video_config) +{ + WINPR_ASSERT(stream); + + int err = 0; + + if ((err = query_xu_control(stream, stream->h264UnitId, UVCX_VIDEO_CONFIG_COMMIT, UVC_SET_CUR, + uvcx_video_config)) < 0) + { + char ebuffer[256] = { 0 }; + WLog_ERR(TAG, "UVCX_VIDEO_CONFIG_COMMIT error: %s", + winpr_strerror(errno, ebuffer, sizeof(ebuffer))); + } + + return err; +} + +/* + * sets h264 muxed format (must not be called while streaming) + * args: + * stream - pointer to video device data + * mediaType + * + * returns: TRUE on success or FALSE on fail + */ +BOOL set_h264_muxed_format(CamV4lStream* stream, const CAM_MEDIA_TYPE_DESCRIPTION* mediaType) +{ + WINPR_ASSERT(stream); + WINPR_ASSERT(mediaType); + + uvcx_video_config_probe_commit_t config_probe_req = { 0 }; + int err = 0; + + /* reset the encoder */ + err = uvcx_video_encoder_reset(stream); + if (err != 0) + return FALSE; + + /* get default values */ + err = uvcx_video_probe(stream, UVC_GET_DEF, &config_probe_req); + if (err != 0) + return FALSE; + + /* set resolution */ + config_probe_req.wWidth = WINPR_ASSERTING_INT_CAST(uint16_t, mediaType->Width); + config_probe_req.wHeight = WINPR_ASSERTING_INT_CAST(uint16_t, mediaType->Height); + + /* set frame rate in 100ns units */ + uint32_t frame_interval = + (mediaType->FrameRateDenominator * 1000000000LL / mediaType->FrameRateNumerator) / 100; + config_probe_req.dwFrameInterval = frame_interval; + + /* quality settings */ + config_probe_req.wProfile = PROFILE_HIGH; + config_probe_req.bUsageType = USAGETYPE_REALTIME; + config_probe_req.bRateControlMode = RATECONTROL_VBR; + config_probe_req.dwBitRate = h264_get_max_bitrate(mediaType->Height); + config_probe_req.bEntropyCABAC = ENTROPY_CABAC; + config_probe_req.wIFramePeriod = 1000; /* ms, 1 sec */ + + /* hints which parameters are configured */ + config_probe_req.bmHints = BMHINTS_RESOLUTION | BMHINTS_FRAME_INTERVAL | BMHINTS_PROFILE | + BMHINTS_USAGE | BMHINTS_RATECONTROL | BMHINTS_BITRATE | + BMHINTS_ENTROPY | BMHINTS_IFRAMEPERIOD; + + /* set the aux stream */ + config_probe_req.bStreamMuxOption = STREAMMUX_H264; + + /* probe the format */ + err = uvcx_video_probe(stream, UVC_SET_CUR, &config_probe_req); + if (err != 0) + return FALSE; + + err = uvcx_video_probe(stream, UVC_GET_CUR, &config_probe_req); + if (err != 0) + return FALSE; + + if (config_probe_req.wWidth != mediaType->Width) + { + WLog_ERR(TAG, "Requested width %" PRIu16 " but got %" PRIu16, mediaType->Width, + config_probe_req.wWidth); + return FALSE; + } + if (config_probe_req.wHeight != mediaType->Height) + { + WLog_ERR(TAG, "Requested height %" PRIu16 " but got %" PRIu16, mediaType->Height, + config_probe_req.wHeight); + return FALSE; + } + if (config_probe_req.dwFrameInterval != frame_interval) + { + WLog_ERR(TAG, "Requested frame interval %" PRIu32 " but got %" PRIu32, frame_interval, + config_probe_req.dwFrameInterval); + return FALSE; + } + + /* commit the format */ + err = uvcx_video_commit(stream, &config_probe_req); + if (err != 0) + return FALSE; + + return TRUE; +} + +/* + * parses deviceId such as usb-0000:00:1a.0-1.2.2 to return devpath (1.2.2) + * + * deviceID format is: usb-- + * see kernel's usb_make_path() + * + * args: + * deviceId + * path - buffer to return devpath + * size - buffer size + * + * returns: TRUE if success, FALSE otherwise + */ +static BOOL get_devpath_from_device_id(const char* deviceId, char* path, size_t size) +{ + if (0 != strncmp(deviceId, "usb-", 4)) + return FALSE; + + /* find second `-` */ + const char* p = strchr(deviceId + 4, '-'); + if (!p) + return FALSE; + + p++; // now points to NULL terminated devpath + + strncpy(path, p, size - 1); + return TRUE; +} + +/* + * return devpath of a given libusb_device as text string such as: 1.2.2 or 2.3 + * + * args: + * device + * path - buffer to return devpath + * size - buffer size + * + * returns: TRUE if success, FALSE otherwise + */ +static BOOL get_devpath_from_device(libusb_device* device, char* path, size_t size) +{ + uint8_t ports[MAX_DEVPATH_DEPTH] = { 0 }; + int nPorts = libusb_get_port_numbers(device, ports, sizeof(ports)); + + if (nPorts <= 0) + return FALSE; + + for (int i = 0; i < nPorts; i++) + { + int nChars = snprintf(path, size, "%" PRIu8, ports[i]); + if ((nChars <= 0) || ((size_t)nChars >= size)) + return FALSE; + + size -= (size_t)nChars; + path += nChars; + + if (i < nPorts - 1) + { + *path++ = '.'; + size--; + } + } + return TRUE; +} + +/* + * get GUID unit id from libusb_device, if any + * + * args: + * device + * guid - 16 byte xu GUID + * + * returns: unit id for the matching GUID or 0 if none + */ +static uint8_t get_guid_unit_id_from_device(libusb_device* device, const uint8_t* guid) +{ + struct libusb_device_descriptor ddesc = { 0 }; + + if (libusb_get_device_descriptor(device, &ddesc) != 0) + { + WLog_ERR(TAG, "Couldn't get device descriptor"); + return 0; + } + + for (uint8_t i = 0; i < ddesc.bNumConfigurations; ++i) + { + struct libusb_config_descriptor* config = NULL; + + if (libusb_get_config_descriptor(device, i, &config) != 0) + { + WLog_ERR(TAG, + "Couldn't get config descriptor for " + "configuration %" PRIu8, + i); + continue; + } + + for (uint8_t j = 0; j < config->bNumInterfaces; j++) + { + const struct libusb_interface* cfg = &config->interface[j]; + for (int k = 0; k < cfg->num_altsetting; k++) + { + const struct libusb_interface_descriptor* interface = &cfg->altsetting[k]; + if (interface->bInterfaceClass != LIBUSB_CLASS_VIDEO || + interface->bInterfaceSubClass != USB_VIDEO_CONTROL) + continue; + + const uint8_t* ptr = interface->extra; + while (ptr < interface->extra + interface->extra_length) + { + const xu_descriptor* desc = (const xu_descriptor*)ptr; + if (desc->bDescriptorType == USB_VIDEO_CONTROL_INTERFACE && + desc->bDescriptorSubType == USB_VIDEO_CONTROL_XU_TYPE && + memcmp(desc->guidExtensionCode, guid, 16) == 0) + { + int8_t unit_id = desc->bUnitID; + + WLog_DBG(TAG, + "For camera %04" PRIx16 ":%04" PRIx16 + " found UVCX H264 UnitID %" PRId8, + ddesc.idVendor, ddesc.idProduct, unit_id); + return unit_id; + } + ptr += desc->bLength; + } + } + } + } + + /* no match found */ + return 0; +} + +/* + * get GUID unit id, if any + * + * args: + * deviceId - camera deviceId such as: usb-0000:00:1a.0-1.2.2 + * guid - 16 byte xu GUID + * + * returns: unit id for the matching GUID or 0 if none + */ +static uint8_t get_guid_unit_id(const char* deviceId, const uint8_t* guid) +{ + char cam_devpath[MAX_DEVPATH_STR_SIZE] = { 0 }; + libusb_context* usb_ctx = NULL; + libusb_device** device_list = NULL; + uint8_t unit_id = 0; + + if (!get_devpath_from_device_id(deviceId, cam_devpath, sizeof(cam_devpath))) + { + WLog_ERR(TAG, "Unable to get devpath from deviceId %s", deviceId); + return 0; + } + + if (0 != libusb_init(&usb_ctx)) + { + WLog_ERR(TAG, "Unable to initialize libusb"); + return 0; + } + + ssize_t cnt = libusb_get_device_list(usb_ctx, &device_list); + + for (ssize_t i = 0; i < cnt; i++) + { + char path[MAX_DEVPATH_STR_SIZE] = { 0 }; + libusb_device* device = device_list[i]; + + if (!device || !get_devpath_from_device(device, path, sizeof(path))) + continue; + + if (0 != strcmp(cam_devpath, path)) + continue; + + /* found device with matching devpath, try to get guid unit id */ + unit_id = get_guid_unit_id_from_device(device, guid); + + if (unit_id > 0) + break; /* got it */ + + /* there's chance for another devpath match - continue */ + } + + libusb_free_device_list(device_list, TRUE); + libusb_exit(usb_ctx); + return unit_id; +} + +/* + * gets the uvc h264 xu control unit id, if any + * + * args: + * deviceId - camera deviceId such as: usb-0000:00:1a.0-1.2.2 + * + * returns: unit id or 0 if none + */ +uint8_t get_uvc_h624_unit_id(const char* deviceId) +{ + WINPR_ASSERT(deviceId); + + WLog_DBG(TAG, "Checking for UVCX H264 UnitID for %s", deviceId); + + return get_guid_unit_id(deviceId, GUID_UVCX_H264_XU); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bd843379f7aefcc9940a5cb94c11b2295e19fbf6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2022 Pascal Nowack +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("rdpecam") + +set(${MODULE_PREFIX}_SRCS camera_device_enumerator_main.c camera_device_main.c) + +set(${MODULE_PREFIX}_LIBS freerdp) + +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/camera_device_enumerator_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/camera_device_enumerator_main.c new file mode 100644 index 0000000000000000000000000000000000000000..02c34200dac2947457ce0efef34ef9a5e0962a6c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/camera_device_enumerator_main.c @@ -0,0 +1,620 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Capture Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include +#include + +#define TAG CHANNELS_TAG("rdpecam-enumerator.server") + +typedef enum +{ + ENUMERATOR_INITIAL, + ENUMERATOR_OPENED, +} eEnumeratorChannelState; + +typedef struct +{ + CamDevEnumServerContext context; + + HANDLE stopEvent; + + HANDLE thread; + void* enumerator_channel; + + DWORD SessionId; + + BOOL isOpened; + BOOL externalThread; + + /* Channel state */ + eEnumeratorChannelState state; + + wStream* buffer; +} enumerator_server; + +static UINT enumerator_server_initialize(CamDevEnumServerContext* context, BOOL externalThread) +{ + UINT error = CHANNEL_RC_OK; + enumerator_server* enumerator = (enumerator_server*)context; + + WINPR_ASSERT(enumerator); + + if (enumerator->isOpened) + { + WLog_WARN(TAG, "Application error: Camera Device Enumerator channel already initialized, " + "calling in this state is not possible!"); + return ERROR_INVALID_STATE; + } + + enumerator->externalThread = externalThread; + + return error; +} + +static UINT enumerator_server_open_channel(enumerator_server* enumerator) +{ + CamDevEnumServerContext* context = &enumerator->context; + DWORD Error = ERROR_SUCCESS; + HANDLE hEvent = NULL; + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + UINT32 channelId = 0; + BOOL status = TRUE; + + WINPR_ASSERT(enumerator); + + if (WTSQuerySessionInformationA(enumerator->context.vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + return ERROR_INTERNAL_ERROR; + } + + enumerator->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + hEvent = WTSVirtualChannelManagerGetEventHandle(enumerator->context.vcm); + + if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED) + { + Error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", Error); + return Error; + } + + enumerator->enumerator_channel = WTSVirtualChannelOpenEx( + enumerator->SessionId, RDPECAM_CONTROL_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC); + if (!enumerator->enumerator_channel) + { + Error = GetLastError(); + WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed with error %" PRIu32 "!", Error); + return Error; + } + + channelId = WTSChannelGetIdByHandle(enumerator->enumerator_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + + return Error; +} + +static UINT enumerator_server_handle_select_version_request(CamDevEnumServerContext* context, + wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_SELECT_VERSION_REQUEST pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + IFCALLRET(context->SelectVersionRequest, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->SelectVersionRequest failed with error %" PRIu32 "", error); + + return error; +} + +static UINT enumerator_server_recv_device_added_notification(CamDevEnumServerContext* context, + wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_DEVICE_ADDED_NOTIFICATION pdu; + UINT error = CHANNEL_RC_OK; + size_t remaining_length = 0; + WCHAR* channel_name_start = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + /* + * RequiredLength 4: + * + * Nullterminator DeviceName (2), + * VirtualChannelName (>= 1), + * Nullterminator VirtualChannelName (1) + */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_NO_DATA; + + pdu.DeviceName = Stream_Pointer(s); + + remaining_length = Stream_GetRemainingLength(s); + channel_name_start = Stream_Pointer(s); + + /* Search for null terminator of DeviceName */ + size_t i = 0; + for (; i < remaining_length; i += sizeof(WCHAR), ++channel_name_start) + { + if (*channel_name_start == L'\0') + break; + } + + if (*channel_name_start != L'\0') + { + WLog_ERR(TAG, "enumerator_server_recv_device_added_notification: Invalid DeviceName!"); + return ERROR_INVALID_DATA; + } + + pdu.VirtualChannelName = (char*)++channel_name_start; + ++i; + + if (i >= remaining_length || *pdu.VirtualChannelName == '\0') + { + WLog_ERR(TAG, + "enumerator_server_recv_device_added_notification: Invalid VirtualChannelName!"); + return ERROR_INVALID_DATA; + } + + char* tmp = pdu.VirtualChannelName; + for (; i < remaining_length; ++i, ++tmp) + { + if (*tmp == '\0') + break; + } + + if (*tmp != '\0') + { + WLog_ERR(TAG, + "enumerator_server_recv_device_added_notification: Invalid VirtualChannelName!"); + return ERROR_INVALID_DATA; + } + + IFCALLRET(context->DeviceAddedNotification, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->DeviceAddedNotification failed with error %" PRIu32 "", error); + + return error; +} + +static UINT enumerator_server_recv_device_removed_notification(CamDevEnumServerContext* context, + wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_DEVICE_REMOVED_NOTIFICATION pdu; + UINT error = CHANNEL_RC_OK; + size_t remaining_length = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_NO_DATA; + + pdu.VirtualChannelName = Stream_Pointer(s); + + remaining_length = Stream_GetRemainingLength(s); + char* tmp = pdu.VirtualChannelName + 1; + + for (size_t i = 1; i < remaining_length; ++i, ++tmp) + { + if (*tmp == '\0') + break; + } + + if (*tmp != '\0') + { + WLog_ERR(TAG, + "enumerator_server_recv_device_removed_notification: Invalid VirtualChannelName!"); + return ERROR_INVALID_DATA; + } + + IFCALLRET(context->DeviceRemovedNotification, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->DeviceRemovedNotification failed with error %" PRIu32 "", error); + + return error; +} + +static UINT enumerator_process_message(enumerator_server* enumerator) +{ + BOOL rc = 0; + UINT error = ERROR_INTERNAL_ERROR; + ULONG BytesReturned = 0; + CAM_SHARED_MSG_HEADER header = { 0 }; + wStream* s = NULL; + + WINPR_ASSERT(enumerator); + WINPR_ASSERT(enumerator->enumerator_channel); + + s = enumerator->buffer; + WINPR_ASSERT(s); + + Stream_SetPosition(s, 0); + rc = WTSVirtualChannelRead(enumerator->enumerator_channel, 0, NULL, 0, &BytesReturned); + if (!rc) + goto out; + + if (BytesReturned < 1) + { + error = CHANNEL_RC_OK; + goto out; + } + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + if (WTSVirtualChannelRead(enumerator->enumerator_channel, 0, Stream_BufferAs(s, char), + (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + goto out; + } + + Stream_SetLength(s, BytesReturned); + if (!Stream_CheckAndLogRequiredLength(TAG, s, CAM_HEADER_SIZE)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, header.Version); + Stream_Read_UINT8(s, header.MessageId); + + switch (header.MessageId) + { + case CAM_MSG_ID_SelectVersionRequest: + error = + enumerator_server_handle_select_version_request(&enumerator->context, s, &header); + break; + case CAM_MSG_ID_DeviceAddedNotification: + error = + enumerator_server_recv_device_added_notification(&enumerator->context, s, &header); + break; + case CAM_MSG_ID_DeviceRemovedNotification: + error = enumerator_server_recv_device_removed_notification(&enumerator->context, s, + &header); + break; + default: + WLog_ERR(TAG, "enumerator_process_message: unknown or invalid MessageId %" PRIu8 "", + header.MessageId); + break; + } + +out: + if (error) + WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error); + + return error; +} + +static UINT enumerator_server_context_poll_int(CamDevEnumServerContext* context) +{ + enumerator_server* enumerator = (enumerator_server*)context; + UINT error = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(enumerator); + + switch (enumerator->state) + { + case ENUMERATOR_INITIAL: + error = enumerator_server_open_channel(enumerator); + if (error) + WLog_ERR(TAG, "enumerator_server_open_channel failed with error %" PRIu32 "!", + error); + else + enumerator->state = ENUMERATOR_OPENED; + break; + case ENUMERATOR_OPENED: + error = enumerator_process_message(enumerator); + break; + default: + break; + } + + return error; +} + +static HANDLE enumerator_server_get_channel_handle(enumerator_server* enumerator) +{ + void* buffer = NULL; + DWORD BytesReturned = 0; + HANDLE ChannelEvent = NULL; + + WINPR_ASSERT(enumerator); + + if (WTSVirtualChannelQuery(enumerator->enumerator_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) == TRUE) + { + if (BytesReturned == sizeof(HANDLE)) + ChannelEvent = *(HANDLE*)buffer; + + WTSFreeMemory(buffer); + } + + return ChannelEvent; +} + +static DWORD WINAPI enumerator_server_thread_func(LPVOID arg) +{ + DWORD nCount = 0; + HANDLE events[2] = { 0 }; + enumerator_server* enumerator = (enumerator_server*)arg; + UINT error = CHANNEL_RC_OK; + DWORD status = 0; + + WINPR_ASSERT(enumerator); + + nCount = 0; + events[nCount++] = enumerator->stopEvent; + + while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0)) + { + switch (enumerator->state) + { + case ENUMERATOR_INITIAL: + error = enumerator_server_context_poll_int(&enumerator->context); + if (error == CHANNEL_RC_OK) + { + events[1] = enumerator_server_get_channel_handle(enumerator); + nCount = 2; + } + break; + case ENUMERATOR_OPENED: + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + switch (status) + { + case WAIT_OBJECT_0: + break; + case WAIT_OBJECT_0 + 1: + case WAIT_TIMEOUT: + error = enumerator_server_context_poll_int(&enumerator->context); + break; + + case WAIT_FAILED: + default: + error = ERROR_INTERNAL_ERROR; + break; + } + break; + default: + break; + } + } + + (void)WTSVirtualChannelClose(enumerator->enumerator_channel); + enumerator->enumerator_channel = NULL; + + if (error && enumerator->context.rdpcontext) + setChannelError(enumerator->context.rdpcontext, error, + "enumerator_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +static UINT enumerator_server_open(CamDevEnumServerContext* context) +{ + enumerator_server* enumerator = (enumerator_server*)context; + + WINPR_ASSERT(enumerator); + + if (!enumerator->externalThread && (enumerator->thread == NULL)) + { + enumerator->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!enumerator->stopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + enumerator->thread = + CreateThread(NULL, 0, enumerator_server_thread_func, enumerator, 0, NULL); + if (!enumerator->thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + (void)CloseHandle(enumerator->stopEvent); + enumerator->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + } + enumerator->isOpened = TRUE; + + return CHANNEL_RC_OK; +} + +static UINT enumerator_server_close(CamDevEnumServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + enumerator_server* enumerator = (enumerator_server*)context; + + WINPR_ASSERT(enumerator); + + if (!enumerator->externalThread && enumerator->thread) + { + (void)SetEvent(enumerator->stopEvent); + + if (WaitForSingleObject(enumerator->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(enumerator->thread); + (void)CloseHandle(enumerator->stopEvent); + enumerator->thread = NULL; + enumerator->stopEvent = NULL; + } + if (enumerator->externalThread) + { + if (enumerator->state != ENUMERATOR_INITIAL) + { + (void)WTSVirtualChannelClose(enumerator->enumerator_channel); + enumerator->enumerator_channel = NULL; + enumerator->state = ENUMERATOR_INITIAL; + } + } + enumerator->isOpened = FALSE; + + return error; +} + +static UINT enumerator_server_context_poll(CamDevEnumServerContext* context) +{ + enumerator_server* enumerator = (enumerator_server*)context; + + WINPR_ASSERT(enumerator); + + if (!enumerator->externalThread) + return ERROR_INTERNAL_ERROR; + + return enumerator_server_context_poll_int(context); +} + +static BOOL enumerator_server_context_handle(CamDevEnumServerContext* context, HANDLE* handle) +{ + enumerator_server* enumerator = (enumerator_server*)context; + + WINPR_ASSERT(enumerator); + WINPR_ASSERT(handle); + + if (!enumerator->externalThread) + return FALSE; + if (enumerator->state == ENUMERATOR_INITIAL) + return FALSE; + + *handle = enumerator_server_get_channel_handle(enumerator); + + return TRUE; +} + +static UINT enumerator_server_packet_send(CamDevEnumServerContext* context, wStream* s) +{ + enumerator_server* enumerator = (enumerator_server*)context; + UINT error = CHANNEL_RC_OK; + ULONG written = 0; + + const size_t len = Stream_GetPosition(s); + WINPR_ASSERT(len <= UINT32_MAX); + if (!WTSVirtualChannelWrite(enumerator->enumerator_channel, Stream_BufferAs(s, char), + (UINT32)len, &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + if (written < Stream_GetPosition(s)) + { + WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written, + Stream_GetPosition(s)); + } + +out: + Stream_Free(s, TRUE); + return error; +} + +static UINT enumerator_send_select_version_response_pdu( + CamDevEnumServerContext* context, const CAM_SELECT_VERSION_RESPONSE* selectVersionResponse) +{ + wStream* s = NULL; + + s = Stream_New(NULL, CAM_HEADER_SIZE); + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return ERROR_NOT_ENOUGH_MEMORY; + } + + Stream_Write_UINT8(s, selectVersionResponse->Header.Version); + Stream_Write_UINT8(s, + WINPR_ASSERTING_INT_CAST(uint8_t, selectVersionResponse->Header.MessageId)); + + return enumerator_server_packet_send(context, s); +} + +CamDevEnumServerContext* cam_dev_enum_server_context_new(HANDLE vcm) +{ + enumerator_server* enumerator = (enumerator_server*)calloc(1, sizeof(enumerator_server)); + + if (!enumerator) + return NULL; + + enumerator->context.vcm = vcm; + enumerator->context.Initialize = enumerator_server_initialize; + enumerator->context.Open = enumerator_server_open; + enumerator->context.Close = enumerator_server_close; + enumerator->context.Poll = enumerator_server_context_poll; + enumerator->context.ChannelHandle = enumerator_server_context_handle; + + enumerator->context.SelectVersionResponse = enumerator_send_select_version_response_pdu; + + enumerator->buffer = Stream_New(NULL, 4096); + if (!enumerator->buffer) + goto fail; + + return &enumerator->context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + cam_dev_enum_server_context_free(&enumerator->context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void cam_dev_enum_server_context_free(CamDevEnumServerContext* context) +{ + enumerator_server* enumerator = (enumerator_server*)context; + + if (enumerator) + { + enumerator_server_close(context); + Stream_Free(enumerator->buffer, TRUE); + } + + free(enumerator); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/camera_device_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/camera_device_main.c new file mode 100644 index 0000000000000000000000000000000000000000..3591a382fbbd2ef97ebb446a0e0e7c6b0da5ac3b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpecam/server/camera_device_main.c @@ -0,0 +1,978 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Capture Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include +#include + +#define TAG CHANNELS_TAG("rdpecam.server") + +typedef enum +{ + CAMERA_DEVICE_INITIAL, + CAMERA_DEVICE_OPENED, +} eCameraDeviceChannelState; + +typedef struct +{ + CameraDeviceServerContext context; + + HANDLE stopEvent; + + HANDLE thread; + void* device_channel; + + DWORD SessionId; + + BOOL isOpened; + BOOL externalThread; + + /* Channel state */ + eCameraDeviceChannelState state; + + wStream* buffer; +} device_server; + +static UINT device_server_initialize(CameraDeviceServerContext* context, BOOL externalThread) +{ + UINT error = CHANNEL_RC_OK; + device_server* device = (device_server*)context; + + WINPR_ASSERT(device); + + if (device->isOpened) + { + WLog_WARN(TAG, "Application error: Camera channel already initialized, " + "calling in this state is not possible!"); + return ERROR_INVALID_STATE; + } + + device->externalThread = externalThread; + + return error; +} + +static UINT device_server_open_channel(device_server* device) +{ + CameraDeviceServerContext* context = &device->context; + DWORD Error = ERROR_SUCCESS; + HANDLE hEvent = NULL; + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + UINT32 channelId = 0; + BOOL status = TRUE; + + WINPR_ASSERT(device); + + if (WTSQuerySessionInformationA(device->context.vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + return ERROR_INTERNAL_ERROR; + } + + device->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + hEvent = WTSVirtualChannelManagerGetEventHandle(device->context.vcm); + + if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED) + { + Error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", Error); + return Error; + } + + device->device_channel = WTSVirtualChannelOpenEx(device->SessionId, context->virtualChannelName, + WTS_CHANNEL_OPTION_DYNAMIC); + if (!device->device_channel) + { + Error = GetLastError(); + WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed with error %" PRIu32 "!", Error); + return Error; + } + + channelId = WTSChannelGetIdByHandle(device->device_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + + return Error; +} + +static UINT device_server_handle_success_response(CameraDeviceServerContext* context, wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_SUCCESS_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + IFCALLRET(context->SuccessResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->SuccessResponse failed with error %" PRIu32 "", error); + + return error; +} + +static UINT device_server_recv_error_response(CameraDeviceServerContext* context, wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_ERROR_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_NO_DATA; + + Stream_Read_UINT32(s, pdu.ErrorCode); + + IFCALLRET(context->ErrorResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->ErrorResponse failed with error %" PRIu32 "", error); + + return error; +} + +static UINT device_server_recv_stream_list_response(CameraDeviceServerContext* context, wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_STREAM_LIST_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 5)) + return ERROR_NO_DATA; + + pdu.N_Descriptions = 255; + const size_t len = Stream_GetRemainingLength(s) / 5; + if (len < 255) + pdu.N_Descriptions = (BYTE)len; + + for (BYTE i = 0; i < pdu.N_Descriptions; ++i) + { + CAM_STREAM_DESCRIPTION* StreamDescription = &pdu.StreamDescriptions[i]; + + Stream_Read_UINT16(s, StreamDescription->FrameSourceTypes); + Stream_Read_UINT8(s, StreamDescription->StreamCategory); + Stream_Read_UINT8(s, StreamDescription->Selected); + Stream_Read_UINT8(s, StreamDescription->CanBeShared); + } + + IFCALLRET(context->StreamListResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->StreamListResponse failed with error %" PRIu32 "", error); + + return error; +} + +static UINT device_server_recv_media_type_list_response(CameraDeviceServerContext* context, + wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_MEDIA_TYPE_LIST_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 26)) + return ERROR_NO_DATA; + + pdu.N_Descriptions = Stream_GetRemainingLength(s) / 26; + + pdu.MediaTypeDescriptions = calloc(pdu.N_Descriptions, sizeof(CAM_MEDIA_TYPE_DESCRIPTION)); + if (!pdu.MediaTypeDescriptions) + { + WLog_ERR(TAG, "Failed to allocate %zu CAM_MEDIA_TYPE_DESCRIPTION structs", + pdu.N_Descriptions); + return ERROR_NOT_ENOUGH_MEMORY; + } + + for (size_t i = 0; i < pdu.N_Descriptions; ++i) + { + CAM_MEDIA_TYPE_DESCRIPTION* MediaTypeDescriptions = &pdu.MediaTypeDescriptions[i]; + + Stream_Read_UINT8(s, MediaTypeDescriptions->Format); + Stream_Read_UINT32(s, MediaTypeDescriptions->Width); + Stream_Read_UINT32(s, MediaTypeDescriptions->Height); + Stream_Read_UINT32(s, MediaTypeDescriptions->FrameRateNumerator); + Stream_Read_UINT32(s, MediaTypeDescriptions->FrameRateDenominator); + Stream_Read_UINT32(s, MediaTypeDescriptions->PixelAspectRatioNumerator); + Stream_Read_UINT32(s, MediaTypeDescriptions->PixelAspectRatioDenominator); + Stream_Read_UINT8(s, MediaTypeDescriptions->Flags); + } + + IFCALLRET(context->MediaTypeListResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->MediaTypeListResponse failed with error %" PRIu32 "", error); + + free(pdu.MediaTypeDescriptions); + + return error; +} + +static UINT device_server_recv_current_media_type_response(CameraDeviceServerContext* context, + wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_CURRENT_MEDIA_TYPE_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 26)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, pdu.MediaTypeDescription.Format); + Stream_Read_UINT32(s, pdu.MediaTypeDescription.Width); + Stream_Read_UINT32(s, pdu.MediaTypeDescription.Height); + Stream_Read_UINT32(s, pdu.MediaTypeDescription.FrameRateNumerator); + Stream_Read_UINT32(s, pdu.MediaTypeDescription.FrameRateDenominator); + Stream_Read_UINT32(s, pdu.MediaTypeDescription.PixelAspectRatioNumerator); + Stream_Read_UINT32(s, pdu.MediaTypeDescription.PixelAspectRatioDenominator); + Stream_Read_UINT8(s, pdu.MediaTypeDescription.Flags); + + IFCALLRET(context->CurrentMediaTypeResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->CurrentMediaTypeResponse failed with error %" PRIu32 "", error); + + return error; +} + +static UINT device_server_recv_sample_response(CameraDeviceServerContext* context, wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_SAMPLE_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, pdu.StreamIndex); + + pdu.SampleSize = Stream_GetRemainingLength(s); + pdu.Sample = Stream_Pointer(s); + + IFCALLRET(context->SampleResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->SampleResponse failed with error %" PRIu32 "", error); + + return error; +} + +static UINT device_server_recv_sample_error_response(CameraDeviceServerContext* context, wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_SAMPLE_ERROR_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 5)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, pdu.StreamIndex); + Stream_Read_UINT32(s, pdu.ErrorCode); + + IFCALLRET(context->SampleErrorResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->SampleErrorResponse failed with error %" PRIu32 "", error); + + return error; +} + +static UINT device_server_recv_property_list_response(CameraDeviceServerContext* context, + wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_PROPERTY_LIST_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + pdu.N_Properties = Stream_GetRemainingLength(s) / 19; + + if (pdu.N_Properties > 0) + { + pdu.Properties = calloc(pdu.N_Properties, sizeof(CAM_PROPERTY_DESCRIPTION)); + if (!pdu.Properties) + { + WLog_ERR(TAG, "Failed to allocate %zu CAM_PROPERTY_DESCRIPTION structs", + pdu.N_Properties); + return ERROR_NOT_ENOUGH_MEMORY; + } + + for (size_t i = 0; i < pdu.N_Properties; ++i) + { + Stream_Read_UINT8(s, pdu.Properties[i].PropertySet); + Stream_Read_UINT8(s, pdu.Properties[i].PropertyId); + Stream_Read_UINT8(s, pdu.Properties[i].Capabilities); + Stream_Read_INT32(s, pdu.Properties[i].MinValue); + Stream_Read_INT32(s, pdu.Properties[i].MaxValue); + Stream_Read_INT32(s, pdu.Properties[i].Step); + Stream_Read_INT32(s, pdu.Properties[i].DefaultValue); + } + } + + IFCALLRET(context->PropertyListResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->PropertyListResponse failed with error %" PRIu32 "", error); + + free(pdu.Properties); + + return error; +} + +static UINT device_server_recv_property_value_response(CameraDeviceServerContext* context, + wStream* s, + const CAM_SHARED_MSG_HEADER* header) +{ + CAM_PROPERTY_VALUE_RESPONSE pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(header); + + pdu.Header = *header; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 5)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, pdu.PropertyValue.Mode); + Stream_Read_INT32(s, pdu.PropertyValue.Value); + + IFCALLRET(context->PropertyValueResponse, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->PropertyValueResponse failed with error %" PRIu32 "", error); + + return error; +} + +static UINT device_process_message(device_server* device) +{ + BOOL rc = 0; + UINT error = ERROR_INTERNAL_ERROR; + ULONG BytesReturned = 0; + CAM_SHARED_MSG_HEADER header = { 0 }; + wStream* s = NULL; + + WINPR_ASSERT(device); + WINPR_ASSERT(device->device_channel); + + s = device->buffer; + WINPR_ASSERT(s); + + Stream_SetPosition(s, 0); + rc = WTSVirtualChannelRead(device->device_channel, 0, NULL, 0, &BytesReturned); + if (!rc) + goto out; + + if (BytesReturned < 1) + { + error = CHANNEL_RC_OK; + goto out; + } + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + if (WTSVirtualChannelRead(device->device_channel, 0, Stream_BufferAs(s, char), + (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + goto out; + } + + Stream_SetLength(s, BytesReturned); + if (!Stream_CheckAndLogRequiredLength(TAG, s, CAM_HEADER_SIZE)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, header.Version); + Stream_Read_UINT8(s, header.MessageId); + + switch (header.MessageId) + { + case CAM_MSG_ID_SuccessResponse: + error = device_server_handle_success_response(&device->context, s, &header); + break; + case CAM_MSG_ID_ErrorResponse: + error = device_server_recv_error_response(&device->context, s, &header); + break; + case CAM_MSG_ID_StreamListResponse: + error = device_server_recv_stream_list_response(&device->context, s, &header); + break; + case CAM_MSG_ID_MediaTypeListResponse: + error = device_server_recv_media_type_list_response(&device->context, s, &header); + break; + case CAM_MSG_ID_CurrentMediaTypeResponse: + error = device_server_recv_current_media_type_response(&device->context, s, &header); + break; + case CAM_MSG_ID_SampleResponse: + error = device_server_recv_sample_response(&device->context, s, &header); + break; + case CAM_MSG_ID_SampleErrorResponse: + error = device_server_recv_sample_error_response(&device->context, s, &header); + break; + case CAM_MSG_ID_PropertyListResponse: + error = device_server_recv_property_list_response(&device->context, s, &header); + break; + case CAM_MSG_ID_PropertyValueResponse: + error = device_server_recv_property_value_response(&device->context, s, &header); + break; + default: + WLog_ERR(TAG, "device_process_message: unknown or invalid MessageId %" PRIu8 "", + header.MessageId); + break; + } + +out: + if (error) + WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error); + + return error; +} + +static UINT device_server_context_poll_int(CameraDeviceServerContext* context) +{ + device_server* device = (device_server*)context; + UINT error = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(device); + + switch (device->state) + { + case CAMERA_DEVICE_INITIAL: + error = device_server_open_channel(device); + if (error) + WLog_ERR(TAG, "device_server_open_channel failed with error %" PRIu32 "!", error); + else + device->state = CAMERA_DEVICE_OPENED; + break; + case CAMERA_DEVICE_OPENED: + error = device_process_message(device); + break; + default: + break; + } + + return error; +} + +static HANDLE device_server_get_channel_handle(device_server* device) +{ + void* buffer = NULL; + DWORD BytesReturned = 0; + HANDLE ChannelEvent = NULL; + + WINPR_ASSERT(device); + + if (WTSVirtualChannelQuery(device->device_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) == TRUE) + { + if (BytesReturned == sizeof(HANDLE)) + ChannelEvent = *(HANDLE*)buffer; + + WTSFreeMemory(buffer); + } + + return ChannelEvent; +} + +static DWORD WINAPI device_server_thread_func(LPVOID arg) +{ + DWORD nCount = 0; + HANDLE events[2] = { 0 }; + device_server* device = (device_server*)arg; + UINT error = CHANNEL_RC_OK; + DWORD status = 0; + + WINPR_ASSERT(device); + + nCount = 0; + events[nCount++] = device->stopEvent; + + while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0)) + { + switch (device->state) + { + case CAMERA_DEVICE_INITIAL: + error = device_server_context_poll_int(&device->context); + if (error == CHANNEL_RC_OK) + { + events[1] = device_server_get_channel_handle(device); + nCount = 2; + } + break; + case CAMERA_DEVICE_OPENED: + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + switch (status) + { + case WAIT_OBJECT_0: + break; + case WAIT_OBJECT_0 + 1: + case WAIT_TIMEOUT: + error = device_server_context_poll_int(&device->context); + break; + + case WAIT_FAILED: + default: + error = ERROR_INTERNAL_ERROR; + break; + } + break; + default: + break; + } + } + + (void)WTSVirtualChannelClose(device->device_channel); + device->device_channel = NULL; + + if (error && device->context.rdpcontext) + setChannelError(device->context.rdpcontext, error, + "device_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +static UINT device_server_open(CameraDeviceServerContext* context) +{ + device_server* device = (device_server*)context; + + WINPR_ASSERT(device); + + if (!device->externalThread && (device->thread == NULL)) + { + device->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!device->stopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + device->thread = CreateThread(NULL, 0, device_server_thread_func, device, 0, NULL); + if (!device->thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + (void)CloseHandle(device->stopEvent); + device->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + } + device->isOpened = TRUE; + + return CHANNEL_RC_OK; +} + +static UINT device_server_close(CameraDeviceServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + device_server* device = (device_server*)context; + + WINPR_ASSERT(device); + + if (!device->externalThread && device->thread) + { + (void)SetEvent(device->stopEvent); + + if (WaitForSingleObject(device->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(device->thread); + (void)CloseHandle(device->stopEvent); + device->thread = NULL; + device->stopEvent = NULL; + } + if (device->externalThread) + { + if (device->state != CAMERA_DEVICE_INITIAL) + { + (void)WTSVirtualChannelClose(device->device_channel); + device->device_channel = NULL; + device->state = CAMERA_DEVICE_INITIAL; + } + } + device->isOpened = FALSE; + + return error; +} + +static UINT device_server_context_poll(CameraDeviceServerContext* context) +{ + device_server* device = (device_server*)context; + + WINPR_ASSERT(device); + + if (!device->externalThread) + return ERROR_INTERNAL_ERROR; + + return device_server_context_poll_int(context); +} + +static BOOL device_server_context_handle(CameraDeviceServerContext* context, HANDLE* handle) +{ + device_server* device = (device_server*)context; + + WINPR_ASSERT(device); + WINPR_ASSERT(handle); + + if (!device->externalThread) + return FALSE; + if (device->state == CAMERA_DEVICE_INITIAL) + return FALSE; + + *handle = device_server_get_channel_handle(device); + + return TRUE; +} + +static wStream* device_server_packet_new(size_t size, BYTE version, BYTE messageId) +{ + wStream* s = NULL; + + /* Allocate what we need plus header bytes */ + s = Stream_New(NULL, size + CAM_HEADER_SIZE); + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return NULL; + } + + Stream_Write_UINT8(s, version); + Stream_Write_UINT8(s, messageId); + + return s; +} + +static UINT device_server_packet_send(CameraDeviceServerContext* context, wStream* s) +{ + device_server* device = (device_server*)context; + UINT error = CHANNEL_RC_OK; + ULONG written = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(s); + + const size_t len = Stream_GetPosition(s); + WINPR_ASSERT(len <= UINT32_MAX); + if (!WTSVirtualChannelWrite(device->device_channel, Stream_BufferAs(s, char), (UINT32)len, + &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + if (written < Stream_GetPosition(s)) + { + WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written, + Stream_GetPosition(s)); + } + +out: + Stream_Free(s, TRUE); + return error; +} + +static UINT device_server_write_and_send_header(CameraDeviceServerContext* context, BYTE messageId) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + + s = device_server_packet_new(0, context->protocolVersion, messageId); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + return device_server_packet_send(context, s); +} + +static UINT +device_send_activate_device_request_pdu(CameraDeviceServerContext* context, + const CAM_ACTIVATE_DEVICE_REQUEST* activateDeviceRequest) +{ + WINPR_ASSERT(context); + + return device_server_write_and_send_header(context, CAM_MSG_ID_ActivateDeviceRequest); +} + +static UINT device_send_deactivate_device_request_pdu( + CameraDeviceServerContext* context, + const CAM_DEACTIVATE_DEVICE_REQUEST* deactivateDeviceRequest) +{ + WINPR_ASSERT(context); + + return device_server_write_and_send_header(context, CAM_MSG_ID_DeactivateDeviceRequest); +} + +static UINT device_send_stream_list_request_pdu(CameraDeviceServerContext* context, + const CAM_STREAM_LIST_REQUEST* streamListRequest) +{ + WINPR_ASSERT(context); + + return device_server_write_and_send_header(context, CAM_MSG_ID_StreamListRequest); +} + +static UINT +device_send_media_type_list_request_pdu(CameraDeviceServerContext* context, + const CAM_MEDIA_TYPE_LIST_REQUEST* mediaTypeListRequest) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(mediaTypeListRequest); + + s = device_server_packet_new(1, context->protocolVersion, CAM_MSG_ID_MediaTypeListRequest); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT8(s, mediaTypeListRequest->StreamIndex); + + return device_server_packet_send(context, s); +} + +static UINT device_send_current_media_type_request_pdu( + CameraDeviceServerContext* context, + const CAM_CURRENT_MEDIA_TYPE_REQUEST* currentMediaTypeRequest) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(currentMediaTypeRequest); + + s = device_server_packet_new(1, context->protocolVersion, CAM_MSG_ID_CurrentMediaTypeRequest); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT8(s, currentMediaTypeRequest->StreamIndex); + + return device_server_packet_send(context, s); +} + +static UINT +device_send_start_streams_request_pdu(CameraDeviceServerContext* context, + const CAM_START_STREAMS_REQUEST* startStreamsRequest) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(startStreamsRequest); + + s = device_server_packet_new(startStreamsRequest->N_Infos * 27ul, context->protocolVersion, + CAM_MSG_ID_StartStreamsRequest); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + for (size_t i = 0; i < startStreamsRequest->N_Infos; ++i) + { + const CAM_START_STREAM_INFO* info = &startStreamsRequest->StartStreamsInfo[i]; + const CAM_MEDIA_TYPE_DESCRIPTION* description = &info->MediaTypeDescription; + + Stream_Write_UINT8(s, info->StreamIndex); + + Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, description->Format)); + Stream_Write_UINT32(s, description->Width); + Stream_Write_UINT32(s, description->Height); + Stream_Write_UINT32(s, description->FrameRateNumerator); + Stream_Write_UINT32(s, description->FrameRateDenominator); + Stream_Write_UINT32(s, description->PixelAspectRatioNumerator); + Stream_Write_UINT32(s, description->PixelAspectRatioDenominator); + Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, description->Flags)); + } + + return device_server_packet_send(context, s); +} + +static UINT device_send_stop_streams_request_pdu(CameraDeviceServerContext* context, + const CAM_STOP_STREAMS_REQUEST* stopStreamsRequest) +{ + WINPR_ASSERT(context); + + return device_server_write_and_send_header(context, CAM_MSG_ID_StopStreamsRequest); +} + +static UINT device_send_sample_request_pdu(CameraDeviceServerContext* context, + const CAM_SAMPLE_REQUEST* sampleRequest) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(sampleRequest); + + s = device_server_packet_new(1, context->protocolVersion, CAM_MSG_ID_SampleRequest); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT8(s, sampleRequest->StreamIndex); + + return device_server_packet_send(context, s); +} + +static UINT +device_send_property_list_request_pdu(CameraDeviceServerContext* context, + const CAM_PROPERTY_LIST_REQUEST* propertyListRequest) +{ + WINPR_ASSERT(context); + + return device_server_write_and_send_header(context, CAM_MSG_ID_PropertyListRequest); +} + +static UINT +device_send_property_value_request_pdu(CameraDeviceServerContext* context, + const CAM_PROPERTY_VALUE_REQUEST* propertyValueRequest) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(propertyValueRequest); + + s = device_server_packet_new(2, context->protocolVersion, CAM_MSG_ID_PropertyValueRequest); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, propertyValueRequest->PropertySet)); + Stream_Write_UINT8(s, propertyValueRequest->PropertyId); + + return device_server_packet_send(context, s); +} + +static UINT device_send_set_property_value_request_pdu( + CameraDeviceServerContext* context, + const CAM_SET_PROPERTY_VALUE_REQUEST* setPropertyValueRequest) +{ + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(setPropertyValueRequest); + + s = device_server_packet_new(2 + 5, context->protocolVersion, + CAM_MSG_ID_SetPropertyValueRequest); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, setPropertyValueRequest->PropertySet)); + Stream_Write_UINT8(s, setPropertyValueRequest->PropertyId); + + Stream_Write_UINT8( + s, WINPR_ASSERTING_INT_CAST(uint8_t, setPropertyValueRequest->PropertyValue.Mode)); + Stream_Write_INT32(s, setPropertyValueRequest->PropertyValue.Value); + + return device_server_packet_send(context, s); +} + +CameraDeviceServerContext* camera_device_server_context_new(HANDLE vcm) +{ + device_server* device = (device_server*)calloc(1, sizeof(device_server)); + + if (!device) + return NULL; + + device->context.vcm = vcm; + device->context.Initialize = device_server_initialize; + device->context.Open = device_server_open; + device->context.Close = device_server_close; + device->context.Poll = device_server_context_poll; + device->context.ChannelHandle = device_server_context_handle; + + device->context.ActivateDeviceRequest = device_send_activate_device_request_pdu; + device->context.DeactivateDeviceRequest = device_send_deactivate_device_request_pdu; + + device->context.StreamListRequest = device_send_stream_list_request_pdu; + device->context.MediaTypeListRequest = device_send_media_type_list_request_pdu; + device->context.CurrentMediaTypeRequest = device_send_current_media_type_request_pdu; + + device->context.StartStreamsRequest = device_send_start_streams_request_pdu; + device->context.StopStreamsRequest = device_send_stop_streams_request_pdu; + device->context.SampleRequest = device_send_sample_request_pdu; + + device->context.PropertyListRequest = device_send_property_list_request_pdu; + device->context.PropertyValueRequest = device_send_property_value_request_pdu; + device->context.SetPropertyValueRequest = device_send_set_property_value_request_pdu; + + device->buffer = Stream_New(NULL, 4096); + if (!device->buffer) + goto fail; + + return &device->context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + camera_device_server_context_free(&device->context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void camera_device_server_context_free(CameraDeviceServerContext* context) +{ + device_server* device = (device_server*)context; + + if (device) + { + device_server_close(context); + Stream_Free(device->buffer, TRUE); + } + + free(context->virtualChannelName); + + free(device); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ddabd7aafdf5c4d9ed039f2ab4ecbaf217d322b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdpei") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6f6d568f6d32314c1baf4308d47563b4bf2c82c0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "rdpei" + TYPE + "dynamic" + DESCRIPTION + "Input Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEI]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/rdpei_common.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/rdpei_common.c new file mode 100644 index 0000000000000000000000000000000000000000..5e046280d8a7894ce38d22eb0fbc26f427687de2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/rdpei_common.c @@ -0,0 +1,645 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Input Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2014 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "rdpei_common.h" + +#include + +#define TAG FREERDP_TAG("channels.rdpei.common") + +BOOL rdpei_read_2byte_unsigned(wStream* s, UINT16* value) +{ + BYTE byte = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, byte); + + if (byte & 0x80) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + const INT32 ibyte = ((byte & 0x7F) << 8); + *value = WINPR_ASSERTING_INT_CAST(UINT16, ibyte); + Stream_Read_UINT8(s, byte); + *value |= byte; + } + else + { + *value = (byte & 0x7F); + } + + return TRUE; +} + +BOOL rdpei_write_2byte_unsigned(wStream* s, UINT16 value) +{ + BYTE byte = 0; + + if (!Stream_EnsureRemainingCapacity(s, 2)) + return FALSE; + + if (value > 0x7FFF) + return FALSE; + + if (value >= 0x7F) + { + byte = ((value & 0x7F00) >> 8); + Stream_Write_UINT8(s, byte | 0x80); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else + { + byte = (value & 0x7F); + Stream_Write_UINT8(s, byte); + } + + return TRUE; +} + +BOOL rdpei_read_2byte_signed(wStream* s, INT16* value) +{ + BYTE byte = 0; + BOOL negative = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, byte); + + negative = (byte & 0x40) ? TRUE : FALSE; + + const BYTE val = (byte & 0x3F); + + if (byte & 0x80) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, byte); + *value = (INT16)((val << 8) | byte); + } + else + *value = val; + + if (negative) + *value *= -1; + + return TRUE; +} + +BOOL rdpei_write_2byte_signed(wStream* s, INT16 value) +{ + BYTE byte = 0; + BOOL negative = FALSE; + + if (!Stream_EnsureRemainingCapacity(s, 2)) + return FALSE; + + if (value < 0) + { + negative = TRUE; + value *= -1; + } + + if (value > 0x3FFF) + return FALSE; + + if (value >= 0x3F) + { + byte = ((value & 0x3F00) >> 8); + + if (negative) + byte |= 0x40; + + Stream_Write_UINT8(s, byte | 0x80); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else + { + byte = (value & 0x3F); + + if (negative) + byte |= 0x40; + + Stream_Write_UINT8(s, byte); + } + + return TRUE; +} + +BOOL rdpei_read_4byte_unsigned(wStream* s, UINT32* value) +{ + BYTE byte = 0; + BYTE count = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, byte); + + count = (byte & 0xC0) >> 6; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, count)) + return FALSE; + + switch (count) + { + case 0: + *value = (byte & 0x3F); + break; + + case 1: + *value = ((byte & 0x3F) << 8) & 0xFF00; + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 2: + *value = ((byte & 0x3F) << 16) & 0xFF0000; + Stream_Read_UINT8(s, byte); + *value |= ((byte << 8) & 0xFF00); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 3: + *value = ((UINT32)(byte & 0x3F) << 24) & 0xFF000000; + Stream_Read_UINT8(s, byte); + *value |= ((UINT32)(byte << 16) & 0xFF0000); + Stream_Read_UINT8(s, byte); + *value |= ((UINT32)(byte << 8) & 0xFF00); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + default: + break; + } + + return TRUE; +} + +BOOL rdpei_write_4byte_unsigned(wStream* s, UINT32 value) +{ + BYTE byte = 0; + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + + if (value <= 0x3FUL) + { + Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(uint8_t, value)); + } + else if (value <= 0x3FFFUL) + { + byte = (value >> 8) & 0x3F; + Stream_Write_UINT8(s, byte | 0x40); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x3FFFFFUL) + { + byte = (value >> 16) & 0x3F; + Stream_Write_UINT8(s, byte | 0x80); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x3FFFFFFFUL) + { + byte = (value >> 24) & 0x3F; + Stream_Write_UINT8(s, byte | 0xC0); + byte = (value >> 16) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else + { + return FALSE; + } + + return TRUE; +} + +BOOL rdpei_read_4byte_signed(wStream* s, INT32* value) +{ + BYTE byte = 0; + BYTE count = 0; + BOOL negative = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, byte); + + count = (byte & 0xC0) >> 6; + negative = (byte & 0x20) ? TRUE : FALSE; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, count)) + return FALSE; + + switch (count) + { + case 0: + *value = (byte & 0x1F); + break; + + case 1: + *value = (byte & 0x1F) << 8; + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 2: + *value = (byte & 0x1F) << 16; + Stream_Read_UINT8(s, byte); + *value |= (byte << 8); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 3: + *value = (byte & 0x1F) << 24; + Stream_Read_UINT8(s, byte); + *value |= (byte << 16); + Stream_Read_UINT8(s, byte); + *value |= (byte << 8); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + default: + break; + } + + if (negative) + *value *= -1; + + return TRUE; +} + +BOOL rdpei_write_4byte_signed(wStream* s, INT32 value) +{ + BYTE byte = 0; + BOOL negative = FALSE; + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + + if (value < 0) + { + negative = TRUE; + value *= -1; + } + + if (value <= 0x1FL) + { + byte = value & 0x1F; + + if (negative) + byte |= 0x20; + + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFL) + { + byte = (value >> 8) & 0x1F; + + if (negative) + byte |= 0x20; + + Stream_Write_UINT8(s, byte | 0x40); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFL) + { + byte = (value >> 16) & 0x1F; + + if (negative) + byte |= 0x20; + + Stream_Write_UINT8(s, byte | 0x80); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFFFL) + { + byte = (value >> 24) & 0x1F; + + if (negative) + byte |= 0x20; + + Stream_Write_UINT8(s, byte | 0xC0); + byte = (value >> 16) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else + { + return FALSE; + } + + return TRUE; +} + +BOOL rdpei_read_8byte_unsigned(wStream* s, UINT64* value) +{ + UINT64 byte = 0; + BYTE count = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, byte); + + count = (byte & 0xE0) >> 5; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, count)) + return FALSE; + + switch (count) + { + case 0: + *value = (byte & 0x1F); + break; + + case 1: + *value = (byte & 0x1FU) << 8U; + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 2: + *value = (byte & 0x1FU) << 16U; + Stream_Read_UINT8(s, byte); + *value |= (byte << 8U); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 3: + *value = (byte & 0x1FU) << 24U; + Stream_Read_UINT8(s, byte); + *value |= (byte << 16U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 8U); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 4: + *value = ((byte & 0x1FU)) << 32U; + Stream_Read_UINT8(s, byte); + *value |= (byte << 24U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 16U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 8U); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 5: + *value = ((byte & 0x1FU)) << 40U; + Stream_Read_UINT8(s, byte); + *value |= ((byte) << 32U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 24U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 16U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 8U); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 6: + *value = ((byte & 0x1FU)) << 48U; + Stream_Read_UINT8(s, byte); + *value |= ((byte) << 40U); + Stream_Read_UINT8(s, byte); + *value |= ((byte) << 32U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 24U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 16U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 8U); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + case 7: + *value = ((byte & 0x1FU)) << 56U; + Stream_Read_UINT8(s, byte); + *value |= ((byte) << 48U); + Stream_Read_UINT8(s, byte); + *value |= ((byte) << 40U); + Stream_Read_UINT8(s, byte); + *value |= ((byte) << 32U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 24U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 16U); + Stream_Read_UINT8(s, byte); + *value |= (byte << 8U); + Stream_Read_UINT8(s, byte); + *value |= byte; + break; + + default: + break; + } + + return TRUE; +} + +BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value) +{ + BYTE byte = 0; + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + + if (value <= 0x1FULL) + { + byte = value & 0x1F; + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFULL) + { + byte = (value >> 8) & 0x1F; + byte |= (1 << 5); + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFULL) + { + byte = (value >> 16) & 0x1F; + byte |= (2 << 5); + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFFFULL) + { + byte = (value >> 24) & 0x1F; + byte |= (3 << 5); + Stream_Write_UINT8(s, byte); + byte = (value >> 16) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFFFFFULL) + { + byte = (value >> 32) & 0x1F; + byte |= (4 << 5); + Stream_Write_UINT8(s, byte); + byte = (value >> 24) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 16) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFFFFFFFULL) + { + byte = (value >> 40) & 0x1F; + byte |= (5 << 5); + Stream_Write_UINT8(s, byte); + byte = (value >> 32) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 24) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 16) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFFFFFFFFFULL) + { + byte = (value >> 48) & 0x1F; + byte |= (6 << 5); + Stream_Write_UINT8(s, byte); + byte = (value >> 40) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 32) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 24) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 16) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else if (value <= 0x1FFFFFFFFFFFFFFFULL) + { + byte = (value >> 56) & 0x1F; + byte |= (7 << 5); + Stream_Write_UINT8(s, byte); + byte = (value >> 48) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 40) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 32) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 24) & 0x1F; + Stream_Write_UINT8(s, byte); + byte = (value >> 16) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value >> 8) & 0xFF; + Stream_Write_UINT8(s, byte); + byte = (value & 0xFF); + Stream_Write_UINT8(s, byte); + } + else + { + return FALSE; + } + + return TRUE; +} + +void touch_event_reset(RDPINPUT_TOUCH_EVENT* event) +{ + for (UINT16 i = 0; i < event->frameCount; i++) + touch_frame_reset(&event->frames[i]); + + free(event->frames); + event->frames = NULL; + event->frameCount = 0; +} + +void touch_frame_reset(RDPINPUT_TOUCH_FRAME* frame) +{ + free(frame->contacts); + frame->contacts = NULL; + frame->contactCount = 0; +} + +void pen_event_reset(RDPINPUT_PEN_EVENT* event) +{ + for (UINT16 i = 0; i < event->frameCount; i++) + pen_frame_reset(&event->frames[i]); + + free(event->frames); + event->frames = NULL; + event->frameCount = 0; +} + +void pen_frame_reset(RDPINPUT_PEN_FRAME* frame) +{ + free(frame->contacts); + frame->contacts = NULL; + frame->contactCount = 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/rdpei_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/rdpei_common.h new file mode 100644 index 0000000000000000000000000000000000000000..3a5362f734ee924942aada12291005979346918f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpei/rdpei_common.h @@ -0,0 +1,57 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Input Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2014 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEI_COMMON_H +#define FREERDP_CHANNEL_RDPEI_COMMON_H + +#include +#include +#include + +/** @brief input event ids */ +enum +{ + EVENTID_SC_READY = 0x0001, + EVENTID_CS_READY = 0x0002, + EVENTID_TOUCH = 0x0003, + EVENTID_SUSPEND_TOUCH = 0x0004, + EVENTID_RESUME_TOUCH = 0x0005, + EVENTID_DISMISS_HOVERING_CONTACT = 0x0006, + EVENTID_PEN = 0x0008 +}; + +BOOL rdpei_read_2byte_unsigned(wStream* s, UINT16* value); +BOOL rdpei_write_2byte_unsigned(wStream* s, UINT16 value); +BOOL rdpei_read_2byte_signed(wStream* s, INT16* value); +BOOL rdpei_write_2byte_signed(wStream* s, INT16 value); +BOOL rdpei_read_4byte_unsigned(wStream* s, UINT32* value); +BOOL rdpei_write_4byte_unsigned(wStream* s, UINT32 value); +BOOL rdpei_read_4byte_signed(wStream* s, INT32* value); +BOOL rdpei_write_4byte_signed(wStream* s, INT32 value); +BOOL rdpei_read_8byte_unsigned(wStream* s, UINT64* value); +BOOL rdpei_write_8byte_unsigned(wStream* s, UINT64 value); + +void touch_event_reset(RDPINPUT_TOUCH_EVENT* event); +void touch_frame_reset(RDPINPUT_TOUCH_FRAME* frame); + +void pen_event_reset(RDPINPUT_PEN_EVENT* event); +void pen_frame_reset(RDPINPUT_PEN_FRAME* frame); + +#endif /* FREERDP_CHANNEL_RDPEI_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b17d26e2985dc631957078f464530c31941f379a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2023 Pascal Nowack +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdpemsc") + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..df2563f92b5717409be6e17810662eac6c730c81 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT OFF) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "rdpemsc" + TYPE + "dynamic" + DESCRIPTION + "Mouse Cursor Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEMSC]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5844b5d324d4097b077e13c1f12cf84e332d158e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/server/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2023 Pascal Nowack +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("rdpemsc") + +set(${MODULE_PREFIX}_SRCS mouse_cursor_main.c) + +set(${MODULE_PREFIX}_LIBS freerdp) + +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/server/mouse_cursor_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/server/mouse_cursor_main.c new file mode 100644 index 0000000000000000000000000000000000000000..861f2de456e7a8fb47dadda1e0c375dd49ab5709 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpemsc/server/mouse_cursor_main.c @@ -0,0 +1,737 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Mouse Cursor Virtual Channel Extension + * + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#define TAG CHANNELS_TAG("rdpemsc.server") + +typedef enum +{ + MOUSE_CURSOR_INITIAL, + MOUSE_CURSOR_OPENED, +} eMouseCursorChannelState; + +typedef struct +{ + MouseCursorServerContext context; + + HANDLE stopEvent; + + HANDLE thread; + void* mouse_cursor_channel; + + DWORD SessionId; + + BOOL isOpened; + BOOL externalThread; + + /* Channel state */ + eMouseCursorChannelState state; + + wStream* buffer; +} mouse_cursor_server; + +static UINT mouse_cursor_server_initialize(MouseCursorServerContext* context, BOOL externalThread) +{ + UINT error = CHANNEL_RC_OK; + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + + WINPR_ASSERT(mouse_cursor); + + if (mouse_cursor->isOpened) + { + WLog_WARN(TAG, "Application error: Mouse Cursor channel already initialized, " + "calling in this state is not possible!"); + return ERROR_INVALID_STATE; + } + + mouse_cursor->externalThread = externalThread; + + return error; +} + +static UINT mouse_cursor_server_open_channel(mouse_cursor_server* mouse_cursor) +{ + MouseCursorServerContext* context = NULL; + DWORD Error = ERROR_SUCCESS; + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + UINT32 channelId = 0; + BOOL status = TRUE; + + WINPR_ASSERT(mouse_cursor); + context = &mouse_cursor->context; + WINPR_ASSERT(context); + + if (WTSQuerySessionInformationA(mouse_cursor->context.vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + return ERROR_INTERNAL_ERROR; + } + + mouse_cursor->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + + mouse_cursor->mouse_cursor_channel = WTSVirtualChannelOpenEx( + mouse_cursor->SessionId, RDPEMSC_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC); + if (!mouse_cursor->mouse_cursor_channel) + { + Error = GetLastError(); + WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed with error %" PRIu32 "!", Error); + return Error; + } + + channelId = WTSChannelGetIdByHandle(mouse_cursor->mouse_cursor_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + + return Error; +} + +static BOOL read_cap_set(wStream* s, wArrayList* capsSets) +{ + RDP_MOUSE_CURSOR_CAPSET* capsSet = NULL; + UINT32 signature = 0; + RDP_MOUSE_CURSOR_CAPVERSION version = RDP_MOUSE_CURSOR_CAPVERSION_INVALID; + UINT32 size = 0; + size_t capsDataSize = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return FALSE; + + Stream_Read_UINT32(s, signature); + Stream_Read_UINT32(s, version); + Stream_Read_UINT32(s, size); + + if (size < 12) + { + WLog_ERR(TAG, "Size of caps set is invalid: %u", size); + return FALSE; + } + + capsDataSize = size - 12; + if (!Stream_CheckAndLogRequiredLength(TAG, s, capsDataSize)) + return FALSE; + + switch (version) + { + case RDP_MOUSE_CURSOR_CAPVERSION_1: + { + RDP_MOUSE_CURSOR_CAPSET_VERSION1* capsSetV1 = NULL; + + capsSetV1 = calloc(1, sizeof(RDP_MOUSE_CURSOR_CAPSET_VERSION1)); + if (!capsSetV1) + return FALSE; + + capsSet = (RDP_MOUSE_CURSOR_CAPSET*)capsSetV1; + break; + } + default: + WLog_WARN(TAG, "Received caps set with unknown version %u", version); + Stream_Seek(s, capsDataSize); + return TRUE; + } + WINPR_ASSERT(capsSet); + + capsSet->signature = signature; + capsSet->version = version; + capsSet->size = size; + + if (!ArrayList_Append(capsSets, capsSet)) + { + WLog_ERR(TAG, "Failed to append caps set to arraylist"); + free(capsSet); + return FALSE; + } + + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): ArrayList_Append owns capsSet + return TRUE; +} + +static UINT mouse_cursor_server_recv_cs_caps_advertise(MouseCursorServerContext* context, + wStream* s, + const RDP_MOUSE_CURSOR_HEADER* header) +{ + RDP_MOUSE_CURSOR_CAPS_ADVERTISE_PDU pdu = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(s); + WINPR_ASSERT(header); + + pdu.header = *header; + + /* There must be at least one capability set present */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_NO_DATA; + + pdu.capsSets = ArrayList_New(FALSE); + if (!pdu.capsSets) + { + WLog_ERR(TAG, "Failed to allocate arraylist"); + return ERROR_NOT_ENOUGH_MEMORY; + } + + wObject* aobj = ArrayList_Object(pdu.capsSets); + WINPR_ASSERT(aobj); + aobj->fnObjectFree = free; + + while (Stream_GetRemainingLength(s) > 0) + { + if (!read_cap_set(s, pdu.capsSets)) + { + ArrayList_Free(pdu.capsSets); + return ERROR_INVALID_DATA; + } + } + + IFCALLRET(context->CapsAdvertise, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->CapsAdvertise failed with error %" PRIu32 "", error); + + ArrayList_Free(pdu.capsSets); + + return error; +} + +static UINT mouse_cursor_process_message(mouse_cursor_server* mouse_cursor) +{ + BOOL rc = 0; + UINT error = ERROR_INTERNAL_ERROR; + ULONG BytesReturned = 0; + RDP_MOUSE_CURSOR_HEADER header = { 0 }; + wStream* s = NULL; + + WINPR_ASSERT(mouse_cursor); + WINPR_ASSERT(mouse_cursor->mouse_cursor_channel); + + s = mouse_cursor->buffer; + WINPR_ASSERT(s); + + Stream_SetPosition(s, 0); + rc = WTSVirtualChannelRead(mouse_cursor->mouse_cursor_channel, 0, NULL, 0, &BytesReturned); + if (!rc) + goto out; + + if (BytesReturned < 1) + { + error = CHANNEL_RC_OK; + goto out; + } + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + if (WTSVirtualChannelRead(mouse_cursor->mouse_cursor_channel, 0, Stream_BufferAs(s, char), + (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + goto out; + } + + Stream_SetLength(s, BytesReturned); + if (!Stream_CheckAndLogRequiredLength(TAG, s, RDPEMSC_HEADER_SIZE)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, header.pduType); + Stream_Read_UINT8(s, header.updateType); + Stream_Read_UINT16(s, header.reserved); + + switch (header.pduType) + { + case PDUTYPE_CS_CAPS_ADVERTISE: + error = mouse_cursor_server_recv_cs_caps_advertise(&mouse_cursor->context, s, &header); + break; + default: + WLog_ERR(TAG, "mouse_cursor_process_message: unknown or invalid pduType %" PRIu8 "", + header.pduType); + break; + } + +out: + if (error) + WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error); + + return error; +} + +static UINT mouse_cursor_server_context_poll_int(MouseCursorServerContext* context) +{ + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + UINT error = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(mouse_cursor); + + switch (mouse_cursor->state) + { + case MOUSE_CURSOR_INITIAL: + error = mouse_cursor_server_open_channel(mouse_cursor); + if (error) + WLog_ERR(TAG, "mouse_cursor_server_open_channel failed with error %" PRIu32 "!", + error); + else + mouse_cursor->state = MOUSE_CURSOR_OPENED; + break; + case MOUSE_CURSOR_OPENED: + error = mouse_cursor_process_message(mouse_cursor); + break; + default: + break; + } + + return error; +} + +static HANDLE mouse_cursor_server_get_channel_handle(mouse_cursor_server* mouse_cursor) +{ + void* buffer = NULL; + DWORD BytesReturned = 0; + HANDLE ChannelEvent = NULL; + + WINPR_ASSERT(mouse_cursor); + + if (WTSVirtualChannelQuery(mouse_cursor->mouse_cursor_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) == TRUE) + { + if (BytesReturned == sizeof(HANDLE)) + ChannelEvent = *(HANDLE*)buffer; + + WTSFreeMemory(buffer); + } + + return ChannelEvent; +} + +static DWORD WINAPI mouse_cursor_server_thread_func(LPVOID arg) +{ + DWORD nCount = 0; + HANDLE events[2] = { 0 }; + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)arg; + UINT error = CHANNEL_RC_OK; + DWORD status = 0; + + WINPR_ASSERT(mouse_cursor); + + nCount = 0; + events[nCount++] = mouse_cursor->stopEvent; + + while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0)) + { + switch (mouse_cursor->state) + { + case MOUSE_CURSOR_INITIAL: + error = mouse_cursor_server_context_poll_int(&mouse_cursor->context); + if (error == CHANNEL_RC_OK) + { + events[1] = mouse_cursor_server_get_channel_handle(mouse_cursor); + nCount = 2; + } + break; + case MOUSE_CURSOR_OPENED: + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + switch (status) + { + case WAIT_OBJECT_0: + break; + case WAIT_OBJECT_0 + 1: + case WAIT_TIMEOUT: + error = mouse_cursor_server_context_poll_int(&mouse_cursor->context); + break; + + case WAIT_FAILED: + default: + error = ERROR_INTERNAL_ERROR; + break; + } + break; + default: + break; + } + } + + (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel); + mouse_cursor->mouse_cursor_channel = NULL; + + if (error && mouse_cursor->context.rdpcontext) + setChannelError(mouse_cursor->context.rdpcontext, error, + "mouse_cursor_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +static UINT mouse_cursor_server_open(MouseCursorServerContext* context) +{ + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + + WINPR_ASSERT(mouse_cursor); + + if (!mouse_cursor->externalThread && (mouse_cursor->thread == NULL)) + { + mouse_cursor->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!mouse_cursor->stopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + mouse_cursor->thread = + CreateThread(NULL, 0, mouse_cursor_server_thread_func, mouse_cursor, 0, NULL); + if (!mouse_cursor->thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + (void)CloseHandle(mouse_cursor->stopEvent); + mouse_cursor->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + } + mouse_cursor->isOpened = TRUE; + + return CHANNEL_RC_OK; +} + +static UINT mouse_cursor_server_close(MouseCursorServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + + WINPR_ASSERT(mouse_cursor); + + if (!mouse_cursor->externalThread && mouse_cursor->thread) + { + (void)SetEvent(mouse_cursor->stopEvent); + + if (WaitForSingleObject(mouse_cursor->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(mouse_cursor->thread); + (void)CloseHandle(mouse_cursor->stopEvent); + mouse_cursor->thread = NULL; + mouse_cursor->stopEvent = NULL; + } + if (mouse_cursor->externalThread) + { + if (mouse_cursor->state != MOUSE_CURSOR_INITIAL) + { + (void)WTSVirtualChannelClose(mouse_cursor->mouse_cursor_channel); + mouse_cursor->mouse_cursor_channel = NULL; + mouse_cursor->state = MOUSE_CURSOR_INITIAL; + } + } + mouse_cursor->isOpened = FALSE; + + return error; +} + +static UINT mouse_cursor_server_context_poll(MouseCursorServerContext* context) +{ + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + + WINPR_ASSERT(mouse_cursor); + + if (!mouse_cursor->externalThread) + return ERROR_INTERNAL_ERROR; + + return mouse_cursor_server_context_poll_int(context); +} + +static BOOL mouse_cursor_server_context_handle(MouseCursorServerContext* context, HANDLE* handle) +{ + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + + WINPR_ASSERT(mouse_cursor); + WINPR_ASSERT(handle); + + if (!mouse_cursor->externalThread) + return FALSE; + if (mouse_cursor->state == MOUSE_CURSOR_INITIAL) + return FALSE; + + *handle = mouse_cursor_server_get_channel_handle(mouse_cursor); + + return TRUE; +} + +static wStream* mouse_cursor_server_packet_new(size_t size, RDP_MOUSE_CURSOR_PDUTYPE pduType, + const RDP_MOUSE_CURSOR_HEADER* header) +{ + wStream* s = NULL; + + /* Allocate what we need plus header bytes */ + s = Stream_New(NULL, size + RDPEMSC_HEADER_SIZE); + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return NULL; + } + + WINPR_ASSERT(pduType <= UINT8_MAX); + Stream_Write_UINT8(s, (BYTE)pduType); + + WINPR_ASSERT(header->updateType <= UINT8_MAX); + Stream_Write_UINT8(s, (BYTE)header->updateType); + Stream_Write_UINT16(s, header->reserved); + + return s; +} + +static UINT mouse_cursor_server_packet_send(MouseCursorServerContext* context, wStream* s) +{ + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + UINT error = CHANNEL_RC_OK; + ULONG written = 0; + + WINPR_ASSERT(mouse_cursor); + WINPR_ASSERT(s); + + const size_t pos = Stream_GetPosition(s); + + WINPR_ASSERT(pos <= UINT32_MAX); + if (!WTSVirtualChannelWrite(mouse_cursor->mouse_cursor_channel, Stream_BufferAs(s, char), + (ULONG)pos, &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + if (written < Stream_GetPosition(s)) + { + WLog_WARN(TAG, "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written, + Stream_GetPosition(s)); + } + +out: + Stream_Free(s, TRUE); + return error; +} + +static UINT +mouse_cursor_server_send_sc_caps_confirm(MouseCursorServerContext* context, + const RDP_MOUSE_CURSOR_CAPS_CONFIRM_PDU* capsConfirm) +{ + RDP_MOUSE_CURSOR_CAPSET* capsetHeader = NULL; + RDP_MOUSE_CURSOR_PDUTYPE pduType = PDUTYPE_EMSC_RESERVED; + size_t caps_size = 0; + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(capsConfirm); + + capsetHeader = capsConfirm->capsSet; + WINPR_ASSERT(capsetHeader); + + caps_size = 12; + switch (capsetHeader->version) + { + case RDP_MOUSE_CURSOR_CAPVERSION_1: + break; + default: + WINPR_ASSERT(FALSE); + break; + } + + pduType = PDUTYPE_SC_CAPS_CONFIRM; + s = mouse_cursor_server_packet_new(caps_size, pduType, &capsConfirm->header); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT32(s, capsetHeader->signature); + Stream_Write_UINT32(s, capsetHeader->version); + Stream_Write_UINT32(s, capsetHeader->size); + + /* Write capsData */ + switch (capsetHeader->version) + { + case RDP_MOUSE_CURSOR_CAPVERSION_1: + break; + default: + WINPR_ASSERT(FALSE); + break; + } + + return mouse_cursor_server_packet_send(context, s); +} + +static void write_point16(wStream* s, const TS_POINT16* point16) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(point16); + + Stream_Write_UINT16(s, point16->xPos); + Stream_Write_UINT16(s, point16->yPos); +} + +static UINT mouse_cursor_server_send_sc_mouseptr_update( + MouseCursorServerContext* context, const RDP_MOUSE_CURSOR_MOUSEPTR_UPDATE_PDU* mouseptrUpdate) +{ + TS_POINT16* position = NULL; + TS_POINTERATTRIBUTE* pointerAttribute = NULL; + TS_LARGEPOINTERATTRIBUTE* largePointerAttribute = NULL; + RDP_MOUSE_CURSOR_PDUTYPE pduType = PDUTYPE_EMSC_RESERVED; + size_t update_size = 0; + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(mouseptrUpdate); + + position = mouseptrUpdate->position; + pointerAttribute = mouseptrUpdate->pointerAttribute; + largePointerAttribute = mouseptrUpdate->largePointerAttribute; + + switch (mouseptrUpdate->header.updateType) + { + case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL: + case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT: + update_size = 0; + break; + case TS_UPDATETYPE_MOUSEPTR_POSITION: + WINPR_ASSERT(position); + update_size = 4; + break; + case TS_UPDATETYPE_MOUSEPTR_CACHED: + WINPR_ASSERT(mouseptrUpdate->cachedPointerIndex); + update_size = 2; + break; + case TS_UPDATETYPE_MOUSEPTR_POINTER: + WINPR_ASSERT(pointerAttribute); + update_size = 2 + 2 + 4 + 2 + 2 + 2 + 2; + update_size += pointerAttribute->lengthAndMask; + update_size += pointerAttribute->lengthXorMask; + break; + case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER: + WINPR_ASSERT(largePointerAttribute); + update_size = 2 + 2 + 4 + 2 + 2 + 4 + 4; + update_size += largePointerAttribute->lengthAndMask; + update_size += largePointerAttribute->lengthXorMask; + break; + default: + WINPR_ASSERT(FALSE); + break; + } + + pduType = PDUTYPE_SC_MOUSEPTR_UPDATE; + s = mouse_cursor_server_packet_new(update_size, pduType, &mouseptrUpdate->header); + if (!s) + return ERROR_NOT_ENOUGH_MEMORY; + + switch (mouseptrUpdate->header.updateType) + { + case TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL: + case TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT: + break; + case TS_UPDATETYPE_MOUSEPTR_POSITION: + write_point16(s, position); + break; + case TS_UPDATETYPE_MOUSEPTR_CACHED: + Stream_Write_UINT16(s, *mouseptrUpdate->cachedPointerIndex); + break; + case TS_UPDATETYPE_MOUSEPTR_POINTER: + Stream_Write_UINT16(s, pointerAttribute->xorBpp); + Stream_Write_UINT16(s, pointerAttribute->cacheIndex); + write_point16(s, &pointerAttribute->hotSpot); + Stream_Write_UINT16(s, pointerAttribute->width); + Stream_Write_UINT16(s, pointerAttribute->height); + Stream_Write_UINT16(s, pointerAttribute->lengthAndMask); + Stream_Write_UINT16(s, pointerAttribute->lengthXorMask); + Stream_Write(s, pointerAttribute->xorMaskData, pointerAttribute->lengthXorMask); + Stream_Write(s, pointerAttribute->andMaskData, pointerAttribute->lengthAndMask); + break; + case TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER: + Stream_Write_UINT16(s, largePointerAttribute->xorBpp); + Stream_Write_UINT16(s, largePointerAttribute->cacheIndex); + write_point16(s, &largePointerAttribute->hotSpot); + Stream_Write_UINT16(s, largePointerAttribute->width); + Stream_Write_UINT16(s, largePointerAttribute->height); + Stream_Write_UINT32(s, largePointerAttribute->lengthAndMask); + Stream_Write_UINT32(s, largePointerAttribute->lengthXorMask); + Stream_Write(s, largePointerAttribute->xorMaskData, + largePointerAttribute->lengthXorMask); + Stream_Write(s, largePointerAttribute->andMaskData, + largePointerAttribute->lengthAndMask); + break; + default: + WINPR_ASSERT(FALSE); + break; + } + + return mouse_cursor_server_packet_send(context, s); +} + +MouseCursorServerContext* mouse_cursor_server_context_new(HANDLE vcm) +{ + mouse_cursor_server* mouse_cursor = + (mouse_cursor_server*)calloc(1, sizeof(mouse_cursor_server)); + + if (!mouse_cursor) + return NULL; + + mouse_cursor->context.vcm = vcm; + mouse_cursor->context.Initialize = mouse_cursor_server_initialize; + mouse_cursor->context.Open = mouse_cursor_server_open; + mouse_cursor->context.Close = mouse_cursor_server_close; + mouse_cursor->context.Poll = mouse_cursor_server_context_poll; + mouse_cursor->context.ChannelHandle = mouse_cursor_server_context_handle; + + mouse_cursor->context.CapsConfirm = mouse_cursor_server_send_sc_caps_confirm; + mouse_cursor->context.MouseptrUpdate = mouse_cursor_server_send_sc_mouseptr_update; + + mouse_cursor->buffer = Stream_New(NULL, 4096); + if (!mouse_cursor->buffer) + goto fail; + + return &mouse_cursor->context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + mouse_cursor_server_context_free(&mouse_cursor->context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void mouse_cursor_server_context_free(MouseCursorServerContext* context) +{ + mouse_cursor_server* mouse_cursor = (mouse_cursor_server*)context; + + if (mouse_cursor) + { + mouse_cursor_server_close(context); + Stream_Free(mouse_cursor->buffer, TRUE); + } + + free(mouse_cursor); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4745eb8047d59ef6cdacafc2a2e506a98f2cfa52 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdpgfx") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..ce3b5e3e884dc5fec342d423dbc3f7b1eede4a25 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "rdpgfx" + TYPE + "dynamic" + DESCRIPTION + "Graphics Pipeline Extension" + SPECIFICATIONS + "[MS-RDPEGFX]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..69cec9beb46ba787ac41af848d9d8aefe2991e8a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2013 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("rdpgfx") + +set(${MODULE_PREFIX}_SRCS rdpgfx_main.c rdpgfx_main.h rdpgfx_codec.c rdpgfx_codec.h ../rdpgfx_common.c + ../rdpgfx_common.h +) + +set(${MODULE_PREFIX}_LIBS winpr freerdp) +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_codec.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_codec.c new file mode 100644 index 0000000000000000000000000000000000000000..b08aa0149fcd3ceb6c81d85216f36c9991eb8d58 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_codec.c @@ -0,0 +1,304 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2014 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include "rdpgfx_common.h" + +#include "rdpgfx_codec.h" + +#define TAG CHANNELS_TAG("rdpgfx.client") + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_read_h264_metablock(RDPGFX_PLUGIN* gfx, wStream* s, RDPGFX_H264_METABLOCK* meta) +{ + RECTANGLE_16* regionRect = NULL; + RDPGFX_H264_QUANT_QUALITY* quantQualityVal = NULL; + UINT error = ERROR_INVALID_DATA; + meta->regionRects = NULL; + meta->quantQualityVals = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + goto error_out; + + Stream_Read_UINT32(s, meta->numRegionRects); /* numRegionRects (4 bytes) */ + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, meta->numRegionRects, 8ull)) + goto error_out; + + meta->regionRects = (RECTANGLE_16*)calloc(meta->numRegionRects, sizeof(RECTANGLE_16)); + + if (!meta->regionRects) + { + WLog_ERR(TAG, "malloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + meta->quantQualityVals = + (RDPGFX_H264_QUANT_QUALITY*)calloc(meta->numRegionRects, sizeof(RDPGFX_H264_QUANT_QUALITY)); + + if (!meta->quantQualityVals) + { + WLog_ERR(TAG, "malloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + WLog_DBG(TAG, "H264_METABLOCK: numRegionRects: %" PRIu32 "", meta->numRegionRects); + + for (UINT32 index = 0; index < meta->numRegionRects; index++) + { + regionRect = &(meta->regionRects[index]); + + if ((error = rdpgfx_read_rect16(s, regionRect))) + { + WLog_ERR(TAG, "rdpgfx_read_rect16 failed with error %" PRIu32 "!", error); + goto error_out; + } + + WLog_DBG(TAG, + "regionRects[%" PRIu32 "]: left: %" PRIu16 " top: %" PRIu16 " right: %" PRIu16 + " bottom: %" PRIu16 "", + index, regionRect->left, regionRect->top, regionRect->right, regionRect->bottom); + } + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, meta->numRegionRects, 2ull)) + { + error = ERROR_INVALID_DATA; + goto error_out; + } + + for (UINT32 index = 0; index < meta->numRegionRects; index++) + { + quantQualityVal = &(meta->quantQualityVals[index]); + Stream_Read_UINT8(s, quantQualityVal->qpVal); /* qpVal (1 byte) */ + Stream_Read_UINT8(s, quantQualityVal->qualityVal); /* qualityVal (1 byte) */ + quantQualityVal->qp = quantQualityVal->qpVal & 0x3F; + quantQualityVal->r = (quantQualityVal->qpVal >> 6) & 1; + quantQualityVal->p = (quantQualityVal->qpVal >> 7) & 1; + WLog_DBG(TAG, + "quantQualityVals[%" PRIu32 "]: qp: %" PRIu8 " r: %" PRIu8 " p: %" PRIu8 + " qualityVal: %" PRIu8 "", + index, quantQualityVal->qp, quantQualityVal->r, quantQualityVal->p, + quantQualityVal->qualityVal); + } + + return CHANNEL_RC_OK; +error_out: + free_h264_metablock(meta); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_decode_AVC420(RDPGFX_PLUGIN* gfx, RDPGFX_SURFACE_COMMAND* cmd) +{ + UINT error = 0; + RDPGFX_AVC420_BITMAP_STREAM h264 = { 0 }; + RdpgfxClientContext* context = gfx->context; + wStream* s = Stream_New(cmd->data, cmd->length); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if ((error = rdpgfx_read_h264_metablock(gfx, s, &(h264.meta)))) + { + Stream_Free(s, FALSE); + WLog_ERR(TAG, "rdpgfx_read_h264_metablock failed with error %" PRIu32 "!", error); + return error; + } + + h264.data = Stream_Pointer(s); + h264.length = (UINT32)Stream_GetRemainingLength(s); + Stream_Free(s, FALSE); + cmd->extra = (void*)&h264; + + if (context) + { + IFCALLRET(context->SurfaceCommand, error, context, cmd); + + if (error) + WLog_ERR(TAG, "context->SurfaceCommand failed with error %" PRIu32 "", error); + } + + free_h264_metablock(&h264.meta); + cmd->extra = NULL; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_decode_AVC444(RDPGFX_PLUGIN* gfx, RDPGFX_SURFACE_COMMAND* cmd) +{ + UINT error = 0; + UINT32 tmp = 0; + size_t pos1 = 0; + size_t pos2 = 0; + + RDPGFX_AVC444_BITMAP_STREAM h264 = { 0 }; + RdpgfxClientContext* context = gfx->context; + wStream* s = Stream_New(cmd->data, cmd->length); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + Stream_Read_UINT32(s, tmp); + h264.cbAvc420EncodedBitstream1 = tmp & 0x3FFFFFFFUL; + h264.LC = (tmp >> 30UL) & 0x03UL; + + if (h264.LC == 0x03) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + pos1 = Stream_GetPosition(s); + + if ((error = rdpgfx_read_h264_metablock(gfx, s, &(h264.bitstream[0].meta)))) + { + WLog_ERR(TAG, "rdpgfx_read_h264_metablock failed with error %" PRIu32 "!", error); + goto fail; + } + + pos2 = Stream_GetPosition(s); + h264.bitstream[0].data = Stream_Pointer(s); + + if (h264.LC == 0) + { + const size_t bitstreamLen = 1ULL * h264.cbAvc420EncodedBitstream1 - pos2 + pos1; + + if ((bitstreamLen > UINT32_MAX) || !Stream_CheckAndLogRequiredLength(TAG, s, bitstreamLen)) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + h264.bitstream[0].length = (UINT32)bitstreamLen; + Stream_Seek(s, bitstreamLen); + + if ((error = rdpgfx_read_h264_metablock(gfx, s, &(h264.bitstream[1].meta)))) + { + WLog_ERR(TAG, "rdpgfx_read_h264_metablock failed with error %" PRIu32 "!", error); + goto fail; + } + + h264.bitstream[1].data = Stream_Pointer(s); + + const size_t len = Stream_GetRemainingLength(s); + if (len > UINT32_MAX) + goto fail; + h264.bitstream[1].length = (UINT32)len; + } + else + { + const size_t len = Stream_GetRemainingLength(s); + if (len > UINT32_MAX) + goto fail; + h264.bitstream[0].length = (UINT32)len; + } + + cmd->extra = (void*)&h264; + + if (context) + { + IFCALLRET(context->SurfaceCommand, error, context, cmd); + + if (error) + WLog_ERR(TAG, "context->SurfaceCommand failed with error %" PRIu32 "", error); + } + +fail: + Stream_Free(s, FALSE); + free_h264_metablock(&h264.bitstream[0].meta); + free_h264_metablock(&h264.bitstream[1].meta); + cmd->extra = NULL; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_decode(RDPGFX_PLUGIN* gfx, RDPGFX_SURFACE_COMMAND* cmd) +{ + UINT error = CHANNEL_RC_OK; + RdpgfxClientContext* context = gfx->context; + PROFILER_ENTER(context->SurfaceProfiler) + + switch (cmd->codecId) + { + case RDPGFX_CODECID_AVC420: + if ((error = rdpgfx_decode_AVC420(gfx, cmd))) + WLog_ERR(TAG, "rdpgfx_decode_AVC420 failed with error %" PRIu32 "", error); + + break; + + case RDPGFX_CODECID_AVC444: + case RDPGFX_CODECID_AVC444v2: + if ((error = rdpgfx_decode_AVC444(gfx, cmd))) + WLog_ERR(TAG, "rdpgfx_decode_AVC444 failed with error %" PRIu32 "", error); + + break; + + default: + if (context) + { + IFCALLRET(context->SurfaceCommand, error, context, cmd); + + if (error) + WLog_ERR(TAG, "context->SurfaceCommand failed with error %" PRIu32 "", error); + } + + break; + } + + PROFILER_EXIT(context->SurfaceProfiler) + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_codec.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_codec.h new file mode 100644 index 0000000000000000000000000000000000000000..03d1bac994981ade4c617f56a1172ef9b9dee3cc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_codec.h @@ -0,0 +1,35 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2014 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPGFX_CLIENT_CODEC_H +#define FREERDP_CHANNEL_RDPGFX_CLIENT_CODEC_H + +#include +#include + +#include +#include + +#include "rdpgfx_main.h" + +FREERDP_LOCAL UINT rdpgfx_decode(RDPGFX_PLUGIN* gfx, RDPGFX_SURFACE_COMMAND* cmd); + +#endif /* FREERDP_CHANNEL_RDPGFX_CLIENT_CODEC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_main.c new file mode 100644 index 0000000000000000000000000000000000000000..553a2fc0eb03593b214bd0a6cf842106af57c081 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_main.c @@ -0,0 +1,2437 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2013-2014 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Thincast Technologies GmbH + * Copyright 2016 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "rdpgfx_common.h" +#include "rdpgfx_codec.h" + +#include "rdpgfx_main.h" + +#define TAG CHANNELS_TAG("rdpgfx.client") + +static BOOL delete_surface(const void* key, void* value, void* arg) +{ + const UINT16 id = (UINT16)(uintptr_t)(key); + RdpgfxClientContext* context = arg; + RDPGFX_DELETE_SURFACE_PDU pdu = { 0 }; + + WINPR_UNUSED(value); + pdu.surfaceId = id - 1; + + if (context) + { + UINT error = CHANNEL_RC_OK; + IFCALLRET(context->DeleteSurface, error, context, &pdu); + + if (error) + { + WLog_ERR(TAG, "context->DeleteSurface failed with error %" PRIu32 "", error); + } + } + return TRUE; +} + +static void free_surfaces(RdpgfxClientContext* context, wHashTable* SurfaceTable) +{ + HashTable_Foreach(SurfaceTable, delete_surface, context); +} + +static void evict_cache_slots(RdpgfxClientContext* context, UINT16 MaxCacheSlots, void** CacheSlots) +{ + WINPR_ASSERT(CacheSlots); + for (UINT16 index = 0; index < MaxCacheSlots; index++) + { + if (CacheSlots[index]) + { + RDPGFX_EVICT_CACHE_ENTRY_PDU pdu = { 0 }; + pdu.cacheSlot = index + 1; + + if (context && context->EvictCacheEntry) + { + context->EvictCacheEntry(context, &pdu); + } + + CacheSlots[index] = NULL; + } + } +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_caps_advertise_pdu(RdpgfxClientContext* context, + const RDPGFX_CAPS_ADVERTISE_PDU* pdu) +{ + UINT error = CHANNEL_RC_OK; + RDPGFX_HEADER header = { 0 }; + RDPGFX_PLUGIN* gfx = NULL; + GENERIC_CHANNEL_CALLBACK* callback = NULL; + wStream* s = NULL; + + WINPR_ASSERT(pdu); + WINPR_ASSERT(context); + + gfx = (RDPGFX_PLUGIN*)context->handle; + + if (!gfx || !gfx->base.listener_callback) + return ERROR_BAD_ARGUMENTS; + + callback = gfx->base.listener_callback->channel_callback; + + header.flags = 0; + header.cmdId = RDPGFX_CMDID_CAPSADVERTISE; + header.pduLength = RDPGFX_HEADER_SIZE + 2; + + for (UINT16 index = 0; index < pdu->capsSetCount; index++) + { + const RDPGFX_CAPSET* capsSet = &(pdu->capsSets[index]); + header.pduLength += RDPGFX_CAPSET_BASE_SIZE + capsSet->length; + } + + DEBUG_RDPGFX(gfx->log, "SendCapsAdvertisePdu %" PRIu16 "", pdu->capsSetCount); + s = Stream_New(NULL, header.pduLength); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if ((error = rdpgfx_write_header(s, &header))) + goto fail; + + /* RDPGFX_CAPS_ADVERTISE_PDU */ + Stream_Write_UINT16(s, pdu->capsSetCount); /* capsSetCount (2 bytes) */ + + for (UINT16 index = 0; index < pdu->capsSetCount; index++) + { + const RDPGFX_CAPSET* capsSet = &(pdu->capsSets[index]); + + DEBUG_RDPGFX(gfx->log, "Sending %s [0x%08" PRIx32 "] flags=0x%08" PRIx32, + rdpgfx_caps_version_str(capsSet->version), capsSet->version, capsSet->flags); + + Stream_Write_UINT32(s, capsSet->version); /* version (4 bytes) */ + Stream_Write_UINT32(s, capsSet->length); /* capsDataLength (4 bytes) */ + Stream_Write_UINT32(s, capsSet->flags); /* capsData (4 bytes) */ + Stream_Zero(s, capsSet->length - 4); + } + + Stream_SealLength(s); + error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s), + NULL); +fail: + Stream_Free(s, TRUE); + return error; +} + +static BOOL rdpgfx_is_capability_filtered(RDPGFX_PLUGIN* gfx, UINT32 caps) +{ + WINPR_ASSERT(gfx); + const UINT32 filter = + freerdp_settings_get_uint32(gfx->rdpcontext->settings, FreeRDP_GfxCapsFilter); + const UINT32 capList[] = { RDPGFX_CAPVERSION_8, RDPGFX_CAPVERSION_81, + RDPGFX_CAPVERSION_10, RDPGFX_CAPVERSION_101, + RDPGFX_CAPVERSION_102, RDPGFX_CAPVERSION_103, + RDPGFX_CAPVERSION_104, RDPGFX_CAPVERSION_105, + RDPGFX_CAPVERSION_106, RDPGFX_CAPVERSION_106_ERR, + RDPGFX_CAPVERSION_107 }; + + for (size_t x = 0; x < ARRAYSIZE(capList); x++) + { + if (caps == capList[x]) + return (filter & (1 << x)) != 0; + } + + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_supported_caps(GENERIC_CHANNEL_CALLBACK* callback) +{ + RDPGFX_PLUGIN* gfx = NULL; + RdpgfxClientContext* context = NULL; + RDPGFX_CAPSET* capsSet = NULL; + RDPGFX_CAPSET capsSets[RDPGFX_NUMBER_CAPSETS] = { 0 }; + RDPGFX_CAPS_ADVERTISE_PDU pdu = { 0 }; + + if (!callback) + return ERROR_BAD_ARGUMENTS; + + gfx = (RDPGFX_PLUGIN*)callback->plugin; + + if (!gfx) + return ERROR_BAD_CONFIGURATION; + + context = gfx->context; + + if (!context) + return ERROR_BAD_CONFIGURATION; + + pdu.capsSetCount = 0; + pdu.capsSets = (RDPGFX_CAPSET*)capsSets; + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_8)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_8; + capsSet->length = 4; + capsSet->flags = 0; + + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxThinClient)) + capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT; + + /* in CAPVERSION_8 the spec says that we should not have both + * thinclient and smallcache (and thinclient implies a small cache) + */ + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxSmallCache) && + !freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxThinClient)) + capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE; + } + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_81)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_81; + capsSet->length = 4; + capsSet->flags = 0; + + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxThinClient)) + capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT; + + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxSmallCache)) + capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE; + +#ifdef WITH_GFX_H264 + + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxH264)) + capsSet->flags |= RDPGFX_CAPS_FLAG_AVC420_ENABLED; + +#endif + } + + if (!freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxH264) || + freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxAVC444)) + { + UINT32 caps10Flags = 0; + + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxSmallCache)) + caps10Flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE; + +#ifdef WITH_GFX_H264 + + if (!freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxAVC444)) + caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED; + +#else + caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED; +#endif + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_10)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_10; + capsSet->length = 4; + capsSet->flags = caps10Flags; + } + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_101)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_101; + capsSet->length = 0x10; + capsSet->flags = 0; + } + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_102)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_102; + capsSet->length = 0x4; + capsSet->flags = caps10Flags; + } + + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxThinClient)) + { + if ((caps10Flags & RDPGFX_CAPS_FLAG_AVC_DISABLED) == 0) + caps10Flags |= RDPGFX_CAPS_FLAG_AVC_THINCLIENT; + } + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_103)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_103; + capsSet->length = 0x4; + capsSet->flags = caps10Flags & ~RDPGFX_CAPS_FLAG_SMALL_CACHE; + } + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_104)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_104; + capsSet->length = 0x4; + capsSet->flags = caps10Flags; + } + + /* The following capabilities expect support for image scaling. + * Disable these for builds that do not have support for that. + */ +#if defined(WITH_CAIRO) || defined(WITH_SWSCALE) + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_105)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_105; + capsSet->length = 0x4; + capsSet->flags = caps10Flags; + } + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_106; + capsSet->length = 0x4; + capsSet->flags = caps10Flags; + } + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106_ERR)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_106_ERR; + capsSet->length = 0x4; + capsSet->flags = caps10Flags; + } +#endif + + if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_107)) + { + capsSet = &capsSets[pdu.capsSetCount++]; + capsSet->version = RDPGFX_CAPVERSION_107; + capsSet->length = 0x4; + capsSet->flags = caps10Flags; +#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE) + capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE; +#endif + } + } + + return IFCALLRESULT(ERROR_BAD_CONFIGURATION, context->CapsAdvertise, context, &pdu); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_caps_confirm_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_CAPSET capsSet = { 0 }; + RDPGFX_CAPS_CONFIRM_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + + pdu.capsSet = &capsSet; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, capsSet.version); /* version (4 bytes) */ + Stream_Read_UINT32(s, capsSet.length); /* capsDataLength (4 bytes) */ + Stream_Read_UINT32(s, capsSet.flags); /* capsData (4 bytes) */ + gfx->TotalDecodedFrames = 0; + gfx->ConnectionCaps = capsSet; + DEBUG_RDPGFX(gfx->log, + "RecvCapsConfirmPdu: version: %s [0x%08" PRIX32 "] flags: 0x%08" PRIX32 "", + rdpgfx_caps_version_str(capsSet.version), capsSet.version, capsSet.flags); + + if (!context) + return ERROR_BAD_CONFIGURATION; + + return IFCALLRESULT(CHANNEL_RC_OK, context->CapsConfirm, context, &pdu); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_frame_acknowledge_pdu(RdpgfxClientContext* context, + const RDPGFX_FRAME_ACKNOWLEDGE_PDU* pdu) +{ + UINT error = 0; + wStream* s = NULL; + RDPGFX_HEADER header = { 0 }; + RDPGFX_PLUGIN* gfx = NULL; + GENERIC_CHANNEL_CALLBACK* callback = NULL; + + if (!context || !pdu) + return ERROR_BAD_ARGUMENTS; + + gfx = (RDPGFX_PLUGIN*)context->handle; + + if (!gfx || !gfx->base.listener_callback) + return ERROR_BAD_CONFIGURATION; + + callback = gfx->base.listener_callback->channel_callback; + + if (!callback) + return ERROR_BAD_CONFIGURATION; + + header.flags = 0; + header.cmdId = RDPGFX_CMDID_FRAMEACKNOWLEDGE; + header.pduLength = RDPGFX_HEADER_SIZE + 12; + DEBUG_RDPGFX(gfx->log, "SendFrameAcknowledgePdu: %" PRIu32 "", pdu->frameId); + s = Stream_New(NULL, header.pduLength); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if ((error = rdpgfx_write_header(s, &header))) + goto fail; + + /* RDPGFX_FRAME_ACKNOWLEDGE_PDU */ + Stream_Write_UINT32(s, pdu->queueDepth); /* queueDepth (4 bytes) */ + Stream_Write_UINT32(s, pdu->frameId); /* frameId (4 bytes) */ + Stream_Write_UINT32(s, pdu->totalFramesDecoded); /* totalFramesDecoded (4 bytes) */ + error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s), + NULL); + + if (error == CHANNEL_RC_OK) /* frame successfully acked */ + gfx->UnacknowledgedFrames--; + +fail: + Stream_Free(s, TRUE); + return error; +} + +static UINT rdpgfx_send_qoe_frame_acknowledge_pdu(RdpgfxClientContext* context, + const RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU* pdu) +{ + UINT error = 0; + wStream* s = NULL; + RDPGFX_HEADER header = { 0 }; + GENERIC_CHANNEL_CALLBACK* callback = NULL; + RDPGFX_PLUGIN* gfx = NULL; + + header.flags = 0; + header.cmdId = RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE; + header.pduLength = RDPGFX_HEADER_SIZE + 12; + + if (!context || !pdu) + return ERROR_BAD_ARGUMENTS; + + gfx = (RDPGFX_PLUGIN*)context->handle; + + if (!gfx || !gfx->base.listener_callback) + return ERROR_BAD_CONFIGURATION; + + callback = gfx->base.listener_callback->channel_callback; + + if (!callback) + return ERROR_BAD_CONFIGURATION; + + DEBUG_RDPGFX(gfx->log, "SendQoeFrameAcknowledgePdu: %" PRIu32 "", pdu->frameId); + s = Stream_New(NULL, header.pduLength); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if ((error = rdpgfx_write_header(s, &header))) + goto fail; + + /* RDPGFX_FRAME_ACKNOWLEDGE_PDU */ + Stream_Write_UINT32(s, pdu->frameId); + Stream_Write_UINT32(s, pdu->timestamp); + Stream_Write_UINT16(s, pdu->timeDiffSE); + Stream_Write_UINT16(s, pdu->timeDiffEDR); + error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s), + NULL); +fail: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_reset_graphics_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_RESET_GRAPHICS_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + WINPR_ASSERT(gfx); + + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + GraphicsResetEventArgs graphicsReset = { 0 }; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, pdu.width); /* width (4 bytes) */ + Stream_Read_UINT32(s, pdu.height); /* height (4 bytes) */ + Stream_Read_UINT32(s, pdu.monitorCount); /* monitorCount (4 bytes) */ + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, pdu.monitorCount, 20ull)) + return ERROR_INVALID_DATA; + + pdu.monitorDefArray = (MONITOR_DEF*)calloc(pdu.monitorCount, sizeof(MONITOR_DEF)); + + if (!pdu.monitorDefArray) + { + WLog_Print(gfx->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + for (UINT32 index = 0; index < pdu.monitorCount; index++) + { + MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]); + Stream_Read_INT32(s, monitor->left); /* left (4 bytes) */ + Stream_Read_INT32(s, monitor->top); /* top (4 bytes) */ + Stream_Read_INT32(s, monitor->right); /* right (4 bytes) */ + Stream_Read_INT32(s, monitor->bottom); /* bottom (4 bytes) */ + Stream_Read_UINT32(s, monitor->flags); /* flags (4 bytes) */ + } + + const size_t size = (RDPGFX_HEADER_SIZE + 12ULL + (pdu.monitorCount * 20ULL)); + if (size > 340) + { + free(pdu.monitorDefArray); + return CHANNEL_RC_NULL_DATA; + } + const size_t pad = 340ULL - size; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, (size_t)pad)) + { + free(pdu.monitorDefArray); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Seek(s, pad); /* pad (total size is 340 bytes) */ + DEBUG_RDPGFX(gfx->log, + "RecvResetGraphicsPdu: width: %" PRIu32 " height: %" PRIu32 " count: %" PRIu32 "", + pdu.width, pdu.height, pdu.monitorCount); + +#if defined(WITH_DEBUG_RDPGFX) + for (UINT32 index = 0; index < pdu.monitorCount; index++) + { + MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]); + DEBUG_RDPGFX(gfx->log, + "RecvResetGraphicsPdu: monitor left:%" PRIi32 " top:%" PRIi32 " right:%" PRIi32 + " bottom:%" PRIi32 " flags:0x%" PRIx32 "", + monitor->left, monitor->top, monitor->right, monitor->bottom, monitor->flags); + } +#endif + + if (context) + { + IFCALLRET(context->ResetGraphics, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, "context->ResetGraphics failed with error %" PRIu32 "", + error); + } + + /* some listeners may be interested (namely the display channel) */ + EventArgsInit(&graphicsReset, "libfreerdp"); + graphicsReset.width = pdu.width; + graphicsReset.height = pdu.height; + PubSub_OnGraphicsReset(gfx->rdpcontext->pubSub, gfx->rdpcontext, &graphicsReset); + free(pdu.monitorDefArray); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_evict_cache_entry_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_EVICT_CACHE_ENTRY_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.cacheSlot); /* cacheSlot (2 bytes) */ + WLog_Print(gfx->log, WLOG_DEBUG, "RecvEvictCacheEntryPdu: cacheSlot: %" PRIu16 "", + pdu.cacheSlot); + + if (context) + { + IFCALLRET(context->EvictCacheEntry, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->EvictCacheEntry failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Load cache import offer from file (offline replay) + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_load_cache_import_offer(RDPGFX_PLUGIN* gfx, RDPGFX_CACHE_IMPORT_OFFER_PDU* offer) +{ + int count = 0; + UINT error = CHANNEL_RC_OK; + PERSISTENT_CACHE_ENTRY entry; + rdpPersistentCache* persistent = NULL; + WINPR_ASSERT(gfx); + WINPR_ASSERT(gfx->rdpcontext); + rdpSettings* settings = gfx->rdpcontext->settings; + + WINPR_ASSERT(offer); + WINPR_ASSERT(settings); + + offer->cacheEntriesCount = 0; + + if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled)) + return CHANNEL_RC_OK; + + const char* BitmapCachePersistFile = + freerdp_settings_get_string(settings, FreeRDP_BitmapCachePersistFile); + if (!BitmapCachePersistFile) + return CHANNEL_RC_OK; + + persistent = persistent_cache_new(); + + if (!persistent) + return CHANNEL_RC_NO_MEMORY; + + if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1) + { + error = CHANNEL_RC_INITIALIZATION_ERROR; + goto fail; + } + + if (persistent_cache_get_version(persistent) != 3) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + count = persistent_cache_get_count(persistent); + + if (count < 1) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + if (count >= RDPGFX_CACHE_ENTRY_MAX_COUNT) + count = RDPGFX_CACHE_ENTRY_MAX_COUNT - 1; + + if (count > gfx->MaxCacheSlots) + count = gfx->MaxCacheSlots; + + offer->cacheEntriesCount = (UINT16)count; + + for (int idx = 0; idx < count; idx++) + { + if (persistent_cache_read_entry(persistent, &entry) < 1) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + offer->cacheEntries[idx].cacheKey = entry.key64; + offer->cacheEntries[idx].bitmapLength = entry.size; + } + + persistent_cache_free(persistent); + + return error; +fail: + persistent_cache_free(persistent); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_save_persistent_cache(RDPGFX_PLUGIN* gfx) +{ + UINT error = CHANNEL_RC_OK; + PERSISTENT_CACHE_ENTRY cacheEntry; + rdpPersistentCache* persistent = NULL; + WINPR_ASSERT(gfx); + WINPR_ASSERT(gfx->rdpcontext); + rdpSettings* settings = gfx->rdpcontext->settings; + RdpgfxClientContext* context = gfx->context; + + WINPR_ASSERT(context); + WINPR_ASSERT(settings); + + if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled)) + return CHANNEL_RC_OK; + + const char* BitmapCachePersistFile = + freerdp_settings_get_string(settings, FreeRDP_BitmapCachePersistFile); + if (!BitmapCachePersistFile) + return CHANNEL_RC_OK; + + if (!context->ExportCacheEntry) + return CHANNEL_RC_INITIALIZATION_ERROR; + + persistent = persistent_cache_new(); + + if (!persistent) + return CHANNEL_RC_NO_MEMORY; + + if (persistent_cache_open(persistent, BitmapCachePersistFile, TRUE, 3) < 1) + { + error = CHANNEL_RC_INITIALIZATION_ERROR; + goto fail; + } + + for (UINT16 idx = 0; idx < gfx->MaxCacheSlots; idx++) + { + if (gfx->CacheSlots[idx]) + { + UINT16 cacheSlot = idx; + + if (context->ExportCacheEntry(context, cacheSlot, &cacheEntry) != CHANNEL_RC_OK) + continue; + + persistent_cache_write_entry(persistent, &cacheEntry); + } + } + + persistent_cache_free(persistent); + + return error; +fail: + persistent_cache_free(persistent); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_cache_import_offer_pdu(RdpgfxClientContext* context, + const RDPGFX_CACHE_IMPORT_OFFER_PDU* pdu) +{ + UINT error = CHANNEL_RC_OK; + wStream* s = NULL; + RDPGFX_HEADER header; + GENERIC_CHANNEL_CALLBACK* callback = NULL; + + if (!context || !pdu) + return ERROR_BAD_ARGUMENTS; + + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)context->handle; + + if (!gfx || !gfx->base.listener_callback) + return ERROR_BAD_CONFIGURATION; + + callback = gfx->base.listener_callback->channel_callback; + + if (!callback) + return ERROR_BAD_CONFIGURATION; + + header.flags = 0; + header.cmdId = RDPGFX_CMDID_CACHEIMPORTOFFER; + header.pduLength = RDPGFX_HEADER_SIZE + 2ul + pdu->cacheEntriesCount * 12ul; + DEBUG_RDPGFX(gfx->log, "SendCacheImportOfferPdu: cacheEntriesCount: %" PRIu16 "", + pdu->cacheEntriesCount); + s = Stream_New(NULL, header.pduLength); + + if (!s) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if ((error = rdpgfx_write_header(s, &header))) + goto fail; + + if (pdu->cacheEntriesCount <= 0) + { + WLog_ERR(TAG, "Invalid cacheEntriesCount: %" PRIu16 "", pdu->cacheEntriesCount); + error = ERROR_INVALID_DATA; + goto fail; + } + + /* cacheEntriesCount (2 bytes) */ + Stream_Write_UINT16(s, pdu->cacheEntriesCount); + + for (UINT16 index = 0; index < pdu->cacheEntriesCount; index++) + { + const RDPGFX_CACHE_ENTRY_METADATA* cacheEntry = &(pdu->cacheEntries[index]); + Stream_Write_UINT64(s, cacheEntry->cacheKey); /* cacheKey (8 bytes) */ + Stream_Write_UINT32(s, cacheEntry->bitmapLength); /* bitmapLength (4 bytes) */ + } + + error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s), + NULL); + +fail: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_cache_offer(RDPGFX_PLUGIN* gfx) +{ + int count = 0; + UINT error = CHANNEL_RC_OK; + PERSISTENT_CACHE_ENTRY entry; + RDPGFX_CACHE_IMPORT_OFFER_PDU* offer = NULL; + rdpPersistentCache* persistent = NULL; + + WINPR_ASSERT(gfx); + WINPR_ASSERT(gfx->rdpcontext); + + RdpgfxClientContext* context = gfx->context; + rdpSettings* settings = gfx->rdpcontext->settings; + + if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled)) + return CHANNEL_RC_OK; + + const char* BitmapCachePersistFile = + freerdp_settings_get_string(settings, FreeRDP_BitmapCachePersistFile); + if (!BitmapCachePersistFile) + return CHANNEL_RC_OK; + + persistent = persistent_cache_new(); + + if (!persistent) + return CHANNEL_RC_NO_MEMORY; + + if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1) + { + error = CHANNEL_RC_INITIALIZATION_ERROR; + goto fail; + } + + if (persistent_cache_get_version(persistent) != 3) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + count = persistent_cache_get_count(persistent); + if (count < 0) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + if (count >= RDPGFX_CACHE_ENTRY_MAX_COUNT) + count = RDPGFX_CACHE_ENTRY_MAX_COUNT - 1; + + if (count > gfx->MaxCacheSlots) + count = gfx->MaxCacheSlots; + + offer = (RDPGFX_CACHE_IMPORT_OFFER_PDU*)calloc(1, sizeof(RDPGFX_CACHE_IMPORT_OFFER_PDU)); + if (!offer) + { + error = CHANNEL_RC_NO_MEMORY; + goto fail; + } + + WINPR_ASSERT(count <= UINT16_MAX); + offer->cacheEntriesCount = (UINT16)count; + + WLog_DBG(TAG, "Sending Cache Import Offer: %d", count); + + for (int idx = 0; idx < count; idx++) + { + if (persistent_cache_read_entry(persistent, &entry) < 1) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + offer->cacheEntries[idx].cacheKey = entry.key64; + offer->cacheEntries[idx].bitmapLength = entry.size; + } + + if (offer->cacheEntriesCount > 0) + { + error = rdpgfx_send_cache_import_offer_pdu(context, offer); + if (error != CHANNEL_RC_OK) + { + WLog_Print(gfx->log, WLOG_ERROR, "Failed to send cache import offer PDU"); + goto fail; + } + } + +fail: + persistent_cache_free(persistent); + free(offer); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_load_cache_import_reply(RDPGFX_PLUGIN* gfx, + const RDPGFX_CACHE_IMPORT_REPLY_PDU* reply) +{ + int count = 0; + UINT error = CHANNEL_RC_OK; + rdpPersistentCache* persistent = NULL; + WINPR_ASSERT(gfx); + WINPR_ASSERT(gfx->rdpcontext); + rdpSettings* settings = gfx->rdpcontext->settings; + RdpgfxClientContext* context = gfx->context; + + WINPR_ASSERT(settings); + WINPR_ASSERT(reply); + if (!freerdp_settings_get_bool(settings, FreeRDP_BitmapCachePersistEnabled)) + return CHANNEL_RC_OK; + + const char* BitmapCachePersistFile = + freerdp_settings_get_string(settings, FreeRDP_BitmapCachePersistFile); + if (!BitmapCachePersistFile) + return CHANNEL_RC_OK; + + persistent = persistent_cache_new(); + + if (!persistent) + return CHANNEL_RC_NO_MEMORY; + + if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1) + { + error = CHANNEL_RC_INITIALIZATION_ERROR; + goto fail; + } + + if (persistent_cache_get_version(persistent) != 3) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + count = persistent_cache_get_count(persistent); + + count = (count < reply->importedEntriesCount) ? count : reply->importedEntriesCount; + + WLog_DBG(TAG, "Receiving Cache Import Reply: %d", count); + + for (int idx = 0; idx < count; idx++) + { + PERSISTENT_CACHE_ENTRY entry = { 0 }; + if (persistent_cache_read_entry(persistent, &entry) < 1) + { + error = ERROR_INVALID_DATA; + goto fail; + } + + const UINT16 cacheSlot = reply->cacheSlots[idx]; + if (context && context->ImportCacheEntry) + context->ImportCacheEntry(context, cacheSlot, &entry); + } + + persistent_cache_free(persistent); + + return error; +fail: + persistent_cache_free(persistent); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_cache_import_reply_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_CACHE_IMPORT_REPLY_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.importedEntriesCount); /* cacheSlot (2 bytes) */ + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, pdu.importedEntriesCount, 2ull)) + return ERROR_INVALID_DATA; + + if (pdu.importedEntriesCount > RDPGFX_CACHE_ENTRY_MAX_COUNT) + return ERROR_INVALID_DATA; + + for (UINT16 idx = 0; idx < pdu.importedEntriesCount; idx++) + { + Stream_Read_UINT16(s, pdu.cacheSlots[idx]); /* cacheSlot (2 bytes) */ + } + + DEBUG_RDPGFX(gfx->log, "RecvCacheImportReplyPdu: importedEntriesCount: %" PRIu16 "", + pdu.importedEntriesCount); + + error = rdpgfx_load_cache_import_reply(gfx, &pdu); + + if (error) + { + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_load_cache_import_reply failed with error %" PRIu32 "", error); + return error; + } + + if (context) + { + IFCALLRET(context->CacheImportReply, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->CacheImportReply failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_create_surface_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_CREATE_SURFACE_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 7)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT16(s, pdu.width); /* width (2 bytes) */ + Stream_Read_UINT16(s, pdu.height); /* height (2 bytes) */ + Stream_Read_UINT8(s, pdu.pixelFormat); /* RDPGFX_PIXELFORMAT (1 byte) */ + DEBUG_RDPGFX(gfx->log, + "RecvCreateSurfacePdu: surfaceId: %" PRIu16 " width: %" PRIu16 " height: %" PRIu16 + " pixelFormat: 0x%02" PRIX8 "", + pdu.surfaceId, pdu.width, pdu.height, pdu.pixelFormat); + + if (context) + { + /* create surface PDU sometimes happens for surface ID that are already in use and have not + * been removed yet. Ensure that there is no surface with the new ID by trying to remove it + * manually. + */ + RDPGFX_DELETE_SURFACE_PDU deletePdu = { pdu.surfaceId }; + IFCALL(context->DeleteSurface, context, &deletePdu); + + IFCALLRET(context->CreateSurface, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, "context->CreateSurface failed with error %" PRIu32 "", + error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_delete_surface_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_DELETE_SURFACE_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + DEBUG_RDPGFX(gfx->log, "RecvDeleteSurfacePdu: surfaceId: %" PRIu16 "", pdu.surfaceId); + + if (context) + { + IFCALLRET(context->DeleteSurface, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, "context->DeleteSurface failed with error %" PRIu32 "", + error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_start_frame_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_START_FRAME_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RDPGFX_START_FRAME_PDU_SIZE)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, pdu.timestamp); /* timestamp (4 bytes) */ + Stream_Read_UINT32(s, pdu.frameId); /* frameId (4 bytes) */ + DEBUG_RDPGFX(gfx->log, "RecvStartFramePdu: frameId: %" PRIu32 " timestamp: 0x%08" PRIX32 "", + pdu.frameId, pdu.timestamp); + gfx->StartDecodingTime = GetTickCount64(); + + if (context) + { + IFCALLRET(context->StartFrame, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, "context->StartFrame failed with error %" PRIu32 "", + error); + } + + gfx->UnacknowledgedFrames++; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_end_frame_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_END_FRAME_PDU pdu = { 0 }; + RDPGFX_FRAME_ACKNOWLEDGE_PDU ack = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RDPGFX_END_FRAME_PDU_SIZE)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, pdu.frameId); /* frameId (4 bytes) */ + DEBUG_RDPGFX(gfx->log, "RecvEndFramePdu: frameId: %" PRIu32 "", pdu.frameId); + + const UINT64 start = GetTickCount64(); + if (context) + { + IFCALLRET(context->EndFrame, error, context, &pdu); + + if (error) + { + WLog_Print(gfx->log, WLOG_ERROR, "context->EndFrame failed with error %" PRIu32 "", + error); + return error; + } + } + const UINT64 end = GetTickCount64(); + const UINT64 EndFrameTime = end - start; + gfx->TotalDecodedFrames++; + + if (!gfx->sendFrameAcks) + return error; + + ack.frameId = pdu.frameId; + ack.totalFramesDecoded = gfx->TotalDecodedFrames; + + if (gfx->suspendFrameAcks) + { + ack.queueDepth = SUSPEND_FRAME_ACKNOWLEDGEMENT; + + if (gfx->TotalDecodedFrames == 1) + if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32 "", + error); + } + else + { + ack.queueDepth = QUEUE_DEPTH_UNAVAILABLE; + + if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32 "", error); + } + + switch (gfx->ConnectionCaps.version) + { + case RDPGFX_CAPVERSION_10: + case RDPGFX_CAPVERSION_102: + case RDPGFX_CAPVERSION_103: + case RDPGFX_CAPVERSION_104: + case RDPGFX_CAPVERSION_105: + case RDPGFX_CAPVERSION_106: + case RDPGFX_CAPVERSION_106_ERR: + case RDPGFX_CAPVERSION_107: + if (freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxSendQoeAck)) + { + RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU qoe = { 0 }; + UINT64 diff = (GetTickCount64() - gfx->StartDecodingTime); + + if (diff > 65000) + diff = 0; + + qoe.frameId = pdu.frameId; + qoe.timestamp = gfx->StartDecodingTime % UINT32_MAX; + qoe.timeDiffSE = WINPR_ASSERTING_INT_CAST(UINT16, diff); + qoe.timeDiffEDR = WINPR_ASSERTING_INT_CAST(UINT16, EndFrameTime); + + if ((error = rdpgfx_send_qoe_frame_acknowledge_pdu(context, &qoe))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_send_qoe_frame_acknowledge_pdu failed with error %" PRIu32 + "", + error); + } + + break; + + default: + break; + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_wire_to_surface_1_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_SURFACE_COMMAND cmd = { 0 }; + RDPGFX_WIRE_TO_SURFACE_PDU_1 pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + UINT error = 0; + + WINPR_ASSERT(gfx); + if (!Stream_CheckAndLogRequiredLength(TAG, s, RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT16(s, pdu.codecId); /* codecId (2 bytes) */ + Stream_Read_UINT8(s, pdu.pixelFormat); /* pixelFormat (1 byte) */ + + if ((error = rdpgfx_read_rect16(s, &(pdu.destRect)))) /* destRect (8 bytes) */ + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_rect16 failed with error %" PRIu32 "", error); + return error; + } + + Stream_Read_UINT32(s, pdu.bitmapDataLength); /* bitmapDataLength (4 bytes) */ + + if (!Stream_CheckAndLogRequiredLength(TAG, s, pdu.bitmapDataLength)) + return ERROR_INVALID_DATA; + + pdu.bitmapData = Stream_Pointer(s); + Stream_Seek(s, pdu.bitmapDataLength); + + DEBUG_RDPGFX(gfx->log, + "RecvWireToSurface1Pdu: surfaceId: %" PRIu16 " codecId: %s (0x%04" PRIX16 + ") pixelFormat: 0x%02" PRIX8 " " + "destRect: left: %" PRIu16 " top: %" PRIu16 " right: %" PRIu16 " bottom: %" PRIu16 + " bitmapDataLength: %" PRIu32 "", + pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId, + pdu.pixelFormat, pdu.destRect.left, pdu.destRect.top, pdu.destRect.right, + pdu.destRect.bottom, pdu.bitmapDataLength); + cmd.surfaceId = pdu.surfaceId; + cmd.codecId = pdu.codecId; + cmd.contextId = 0; + + switch (pdu.pixelFormat) + { + case GFX_PIXEL_FORMAT_XRGB_8888: + cmd.format = PIXEL_FORMAT_BGRX32; + break; + + case GFX_PIXEL_FORMAT_ARGB_8888: + cmd.format = PIXEL_FORMAT_BGRA32; + break; + + default: + return ERROR_INVALID_DATA; + } + + cmd.left = pdu.destRect.left; + cmd.top = pdu.destRect.top; + cmd.right = pdu.destRect.right; + cmd.bottom = pdu.destRect.bottom; + cmd.width = cmd.right - cmd.left; + cmd.height = cmd.bottom - cmd.top; + cmd.length = pdu.bitmapDataLength; + cmd.data = pdu.bitmapData; + cmd.extra = NULL; + + if (cmd.right < cmd.left) + { + WLog_Print(gfx->log, WLOG_ERROR, "RecvWireToSurface1Pdu right=%" PRIu32 " < left=%" PRIu32, + cmd.right, cmd.left); + return ERROR_INVALID_DATA; + } + if (cmd.bottom < cmd.top) + { + WLog_Print(gfx->log, WLOG_ERROR, "RecvWireToSurface1Pdu bottom=%" PRIu32 " < top=%" PRIu32, + cmd.bottom, cmd.top); + return ERROR_INVALID_DATA; + } + + if ((error = rdpgfx_decode(gfx, &cmd))) + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_decode failed with error %" PRIu32 "!", error); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_wire_to_surface_2_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_SURFACE_COMMAND cmd = { 0 }; + RDPGFX_WIRE_TO_SURFACE_PDU_2 pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT16(s, pdu.codecId); /* codecId (2 bytes) */ + Stream_Read_UINT32(s, pdu.codecContextId); /* codecContextId (4 bytes) */ + Stream_Read_UINT8(s, pdu.pixelFormat); /* pixelFormat (1 byte) */ + Stream_Read_UINT32(s, pdu.bitmapDataLength); /* bitmapDataLength (4 bytes) */ + pdu.bitmapData = Stream_Pointer(s); + Stream_Seek(s, pdu.bitmapDataLength); + + DEBUG_RDPGFX(gfx->log, + "RecvWireToSurface2Pdu: surfaceId: %" PRIu16 " codecId: %s (0x%04" PRIX16 ") " + "codecContextId: %" PRIu32 " pixelFormat: 0x%02" PRIX8 + " bitmapDataLength: %" PRIu32 "", + pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId, + pdu.codecContextId, pdu.pixelFormat, pdu.bitmapDataLength); + + cmd.surfaceId = pdu.surfaceId; + cmd.codecId = pdu.codecId; + cmd.contextId = pdu.codecContextId; + + switch (pdu.pixelFormat) + { + case GFX_PIXEL_FORMAT_XRGB_8888: + cmd.format = PIXEL_FORMAT_BGRX32; + break; + + case GFX_PIXEL_FORMAT_ARGB_8888: + cmd.format = PIXEL_FORMAT_BGRA32; + break; + + default: + return ERROR_INVALID_DATA; + } + + cmd.left = 0; + cmd.top = 0; + cmd.right = 0; + cmd.bottom = 0; + cmd.width = 0; + cmd.height = 0; + cmd.length = pdu.bitmapDataLength; + cmd.data = pdu.bitmapData; + cmd.extra = NULL; + + if (context) + { + IFCALLRET(context->SurfaceCommand, error, context, &cmd); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->SurfaceCommand failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_delete_encoding_context_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_DELETE_ENCODING_CONTEXT_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 6)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT32(s, pdu.codecContextId); /* codecContextId (4 bytes) */ + + DEBUG_RDPGFX(gfx->log, + "RecvDeleteEncodingContextPdu: surfaceId: %" PRIu16 " codecContextId: %" PRIu32 "", + pdu.surfaceId, pdu.codecContextId); + + if (context) + { + IFCALLRET(context->DeleteEncodingContext, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->DeleteEncodingContext failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_solid_fill_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RECTANGLE_16* fillRect = NULL; + RDPGFX_SOLID_FILL_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + + if ((error = rdpgfx_read_color32(s, &(pdu.fillPixel)))) /* fillPixel (4 bytes) */ + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_color32 failed with error %" PRIu32 "!", + error); + return error; + } + + Stream_Read_UINT16(s, pdu.fillRectCount); /* fillRectCount (2 bytes) */ + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, pdu.fillRectCount, 8ull)) + return ERROR_INVALID_DATA; + + pdu.fillRects = (RECTANGLE_16*)calloc(pdu.fillRectCount, sizeof(RECTANGLE_16)); + + if (!pdu.fillRects) + { + WLog_Print(gfx->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + for (UINT16 index = 0; index < pdu.fillRectCount; index++) + { + fillRect = &(pdu.fillRects[index]); + + if ((error = rdpgfx_read_rect16(s, fillRect))) + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_rect16 failed with error %" PRIu32 "!", + error); + free(pdu.fillRects); + return error; + } + } + DEBUG_RDPGFX(gfx->log, "RecvSolidFillPdu: surfaceId: %" PRIu16 " fillRectCount: %" PRIu16 "", + pdu.surfaceId, pdu.fillRectCount); + + if (context) + { + IFCALLRET(context->SolidFill, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, "context->SolidFill failed with error %" PRIu32 "", + error); + } + + free(pdu.fillRects); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_surface_to_surface_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_POINT16* destPt = NULL; + RDPGFX_SURFACE_TO_SURFACE_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 14)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceIdSrc); /* surfaceIdSrc (2 bytes) */ + Stream_Read_UINT16(s, pdu.surfaceIdDest); /* surfaceIdDest (2 bytes) */ + + if ((error = rdpgfx_read_rect16(s, &(pdu.rectSrc)))) /* rectSrc (8 bytes ) */ + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_rect16 failed with error %" PRIu32 "!", + error); + return error; + } + + Stream_Read_UINT16(s, pdu.destPtsCount); /* destPtsCount (2 bytes) */ + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, pdu.destPtsCount, 4ull)) + return ERROR_INVALID_DATA; + + pdu.destPts = (RDPGFX_POINT16*)calloc(pdu.destPtsCount, sizeof(RDPGFX_POINT16)); + + if (!pdu.destPts) + { + WLog_Print(gfx->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + for (UINT16 index = 0; index < pdu.destPtsCount; index++) + { + destPt = &(pdu.destPts[index]); + + if ((error = rdpgfx_read_point16(s, destPt))) + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_point16 failed with error %" PRIu32 "!", + error); + free(pdu.destPts); + return error; + } + } + + DEBUG_RDPGFX(gfx->log, + "RecvSurfaceToSurfacePdu: surfaceIdSrc: %" PRIu16 " surfaceIdDest: %" PRIu16 " " + "left: %" PRIu16 " top: %" PRIu16 " right: %" PRIu16 " bottom: %" PRIu16 + " destPtsCount: %" PRIu16 "", + pdu.surfaceIdSrc, pdu.surfaceIdDest, pdu.rectSrc.left, pdu.rectSrc.top, + pdu.rectSrc.right, pdu.rectSrc.bottom, pdu.destPtsCount); + + if (context) + { + IFCALLRET(context->SurfaceToSurface, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->SurfaceToSurface failed with error %" PRIu32 "", error); + } + + free(pdu.destPts); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_surface_to_cache_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_SURFACE_TO_CACHE_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 20)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT64(s, pdu.cacheKey); /* cacheKey (8 bytes) */ + Stream_Read_UINT16(s, pdu.cacheSlot); /* cacheSlot (2 bytes) */ + + if ((error = rdpgfx_read_rect16(s, &(pdu.rectSrc)))) /* rectSrc (8 bytes ) */ + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_rect16 failed with error %" PRIu32 "!", + error); + return error; + } + + DEBUG_RDPGFX(gfx->log, + "RecvSurfaceToCachePdu: surfaceId: %" PRIu16 " cacheKey: 0x%016" PRIX64 + " cacheSlot: %" PRIu16 " " + "left: %" PRIu16 " top: %" PRIu16 " right: %" PRIu16 " bottom: %" PRIu16 "", + pdu.surfaceId, pdu.cacheKey, pdu.cacheSlot, pdu.rectSrc.left, pdu.rectSrc.top, + pdu.rectSrc.right, pdu.rectSrc.bottom); + + if (context) + { + IFCALLRET(context->SurfaceToCache, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->SurfaceToCache failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_cache_to_surface_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_POINT16* destPt = NULL; + RDPGFX_CACHE_TO_SURFACE_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 6)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.cacheSlot); /* cacheSlot (2 bytes) */ + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT16(s, pdu.destPtsCount); /* destPtsCount (2 bytes) */ + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, pdu.destPtsCount, 4ull)) + return ERROR_INVALID_DATA; + + pdu.destPts = (RDPGFX_POINT16*)calloc(pdu.destPtsCount, sizeof(RDPGFX_POINT16)); + + if (!pdu.destPts) + { + WLog_Print(gfx->log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + for (UINT16 index = 0; index < pdu.destPtsCount; index++) + { + destPt = &(pdu.destPts[index]); + + if ((error = rdpgfx_read_point16(s, destPt))) + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_point16 failed with error %" PRIu32 "", + error); + free(pdu.destPts); + return error; + } + } + + DEBUG_RDPGFX(gfx->log, + "RdpGfxRecvCacheToSurfacePdu: cacheSlot: %" PRIu16 " surfaceId: %" PRIu16 + " destPtsCount: %" PRIu16 "", + pdu.cacheSlot, pdu.surfaceId, pdu.destPtsCount); + + if (context) + { + IFCALLRET(context->CacheToSurface, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->CacheToSurface failed with error %" PRIu32 "", error); + } + + free(pdu.destPts); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_map_surface_to_output_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT16(s, pdu.reserved); /* reserved (2 bytes) */ + Stream_Read_UINT32(s, pdu.outputOriginX); /* outputOriginX (4 bytes) */ + Stream_Read_UINT32(s, pdu.outputOriginY); /* outputOriginY (4 bytes) */ + DEBUG_RDPGFX(gfx->log, + "RecvMapSurfaceToOutputPdu: surfaceId: %" PRIu16 " outputOriginX: %" PRIu32 + " outputOriginY: %" PRIu32 "", + pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY); + + if (context) + { + IFCALLRET(context->MapSurfaceToOutput, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->MapSurfaceToOutput failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rdpgfx_recv_map_surface_to_scaled_output_pdu(GENERIC_CHANNEL_CALLBACK* callback, + wStream* s) +{ + RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 20)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT16(s, pdu.reserved); /* reserved (2 bytes) */ + Stream_Read_UINT32(s, pdu.outputOriginX); /* outputOriginX (4 bytes) */ + Stream_Read_UINT32(s, pdu.outputOriginY); /* outputOriginY (4 bytes) */ + Stream_Read_UINT32(s, pdu.targetWidth); /* targetWidth (4 bytes) */ + Stream_Read_UINT32(s, pdu.targetHeight); /* targetHeight (4 bytes) */ + DEBUG_RDPGFX(gfx->log, + "RecvMapSurfaceToScaledOutputPdu: surfaceId: %" PRIu16 " outputOriginX: %" PRIu32 + " outputOriginY: %" PRIu32 " targetWidth: %" PRIu32 " targetHeight: %" PRIu32, + pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY, pdu.targetWidth, + pdu.targetHeight); + + if (context) + { + IFCALLRET(context->MapSurfaceToScaledOutput, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->MapSurfaceToScaledOutput failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_map_surface_to_window_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + RDPGFX_MAP_SURFACE_TO_WINDOW_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 18)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT64(s, pdu.windowId); /* windowId (8 bytes) */ + Stream_Read_UINT32(s, pdu.mappedWidth); /* mappedWidth (4 bytes) */ + Stream_Read_UINT32(s, pdu.mappedHeight); /* mappedHeight (4 bytes) */ + DEBUG_RDPGFX(gfx->log, + "RecvMapSurfaceToWindowPdu: surfaceId: %" PRIu16 " windowId: 0x%016" PRIX64 + " mappedWidth: %" PRIu32 " mappedHeight: %" PRIu32 "", + pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight); + + if (context && context->MapSurfaceToWindow) + { + IFCALLRET(context->MapSurfaceToWindow, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->MapSurfaceToWindow failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT rdpgfx_recv_map_surface_to_scaled_window_pdu(GENERIC_CHANNEL_CALLBACK* callback, + wStream* s) +{ + RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU pdu = { 0 }; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 26)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.surfaceId); /* surfaceId (2 bytes) */ + Stream_Read_UINT64(s, pdu.windowId); /* windowId (8 bytes) */ + Stream_Read_UINT32(s, pdu.mappedWidth); /* mappedWidth (4 bytes) */ + Stream_Read_UINT32(s, pdu.mappedHeight); /* mappedHeight (4 bytes) */ + Stream_Read_UINT32(s, pdu.targetWidth); /* targetWidth (4 bytes) */ + Stream_Read_UINT32(s, pdu.targetHeight); /* targetHeight (4 bytes) */ + DEBUG_RDPGFX(gfx->log, + "RecvMapSurfaceToScaledWindowPdu: surfaceId: %" PRIu16 " windowId: 0x%016" PRIX64 + " mappedWidth: %" PRIu32 " mappedHeight: %" PRIu32 " targetWidth: %" PRIu32 + " targetHeight: %" PRIu32 "", + pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight, pdu.targetWidth, + pdu.targetHeight); + + if (context && context->MapSurfaceToScaledWindow) + { + IFCALLRET(context->MapSurfaceToScaledWindow, error, context, &pdu); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, + "context->MapSurfaceToScaledWindow failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_pdu(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + size_t end = 0; + RDPGFX_HEADER header = { 0 }; + UINT error = 0; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + const size_t beg = Stream_GetPosition(s); + + WINPR_ASSERT(gfx); + if ((error = rdpgfx_read_header(s, &header))) + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_read_header failed with error %" PRIu32 "!", + error); + return error; + } + + DEBUG_RDPGFX( + gfx->log, "cmdId: %s (0x%04" PRIX16 ") flags: 0x%04" PRIX16 " pduLength: %" PRIu32 "", + rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags, header.pduLength); + + switch (header.cmdId) + { + case RDPGFX_CMDID_WIRETOSURFACE_1: + if ((error = rdpgfx_recv_wire_to_surface_1_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_wire_to_surface_1_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_WIRETOSURFACE_2: + if ((error = rdpgfx_recv_wire_to_surface_2_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_wire_to_surface_2_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_DELETEENCODINGCONTEXT: + if ((error = rdpgfx_recv_delete_encoding_context_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_delete_encoding_context_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_SOLIDFILL: + if ((error = rdpgfx_recv_solid_fill_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_solid_fill_pdu failed with error %" PRIu32 "!", error); + + break; + + case RDPGFX_CMDID_SURFACETOSURFACE: + if ((error = rdpgfx_recv_surface_to_surface_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_surface_to_surface_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_SURFACETOCACHE: + if ((error = rdpgfx_recv_surface_to_cache_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_surface_to_cache_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_CACHETOSURFACE: + if ((error = rdpgfx_recv_cache_to_surface_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_cache_to_surface_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_EVICTCACHEENTRY: + if ((error = rdpgfx_recv_evict_cache_entry_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_evict_cache_entry_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_CREATESURFACE: + if ((error = rdpgfx_recv_create_surface_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_create_surface_pdu failed with error %" PRIu32 "!", error); + + break; + + case RDPGFX_CMDID_DELETESURFACE: + if ((error = rdpgfx_recv_delete_surface_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_delete_surface_pdu failed with error %" PRIu32 "!", error); + + break; + + case RDPGFX_CMDID_STARTFRAME: + if ((error = rdpgfx_recv_start_frame_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_start_frame_pdu failed with error %" PRIu32 "!", error); + + break; + + case RDPGFX_CMDID_ENDFRAME: + if ((error = rdpgfx_recv_end_frame_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_end_frame_pdu failed with error %" PRIu32 "!", error); + + break; + + case RDPGFX_CMDID_RESETGRAPHICS: + if ((error = rdpgfx_recv_reset_graphics_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_reset_graphics_pdu failed with error %" PRIu32 "!", error); + + break; + + case RDPGFX_CMDID_MAPSURFACETOOUTPUT: + if ((error = rdpgfx_recv_map_surface_to_output_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_map_surface_to_output_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_CACHEIMPORTREPLY: + if ((error = rdpgfx_recv_cache_import_reply_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_cache_import_reply_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_CAPSCONFIRM: + if ((error = rdpgfx_recv_caps_confirm_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_caps_confirm_pdu failed with error %" PRIu32 "!", error); + + if ((error = rdpgfx_send_cache_offer(gfx))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_send_cache_offer failed with error %" PRIu32 "!", error); + + break; + + case RDPGFX_CMDID_MAPSURFACETOWINDOW: + if ((error = rdpgfx_recv_map_surface_to_window_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_map_surface_to_window_pdu failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW: + if ((error = rdpgfx_recv_map_surface_to_scaled_window_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_map_surface_to_scaled_window_pdu failed with error %" PRIu32 + "!", + error); + + break; + + case RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT: + if ((error = rdpgfx_recv_map_surface_to_scaled_output_pdu(callback, s))) + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_recv_map_surface_to_scaled_output_pdu failed with error %" PRIu32 + "!", + error); + + break; + + default: + error = CHANNEL_RC_BAD_PROC; + break; + } + + if (error) + { + WLog_Print(gfx->log, WLOG_ERROR, "Error while processing GFX cmdId: %s (0x%04" PRIX16 ")", + rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId); + Stream_SetPosition(s, (beg + header.pduLength)); + return error; + } + + end = Stream_GetPosition(s); + + if (end != (beg + header.pduLength)) + { + WLog_Print(gfx->log, WLOG_ERROR, + "Unexpected gfx pdu end: Actual: %" PRIuz ", Expected: %" PRIuz, end, + (beg + header.pduLength)); + Stream_SetPosition(s, (beg + header.pduLength)); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + int status = 0; + UINT32 DstSize = 0; + BYTE* pDstData = NULL; + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(gfx); + status = zgfx_decompress(gfx->zgfx, Stream_ConstPointer(data), + (UINT32)Stream_GetRemainingLength(data), &pDstData, &DstSize, 0); + + if (status < 0) + { + WLog_Print(gfx->log, WLOG_ERROR, "zgfx_decompress failure! status: %d", status); + free(pDstData); + return ERROR_INTERNAL_ERROR; + } + + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticConstInit(&sbuffer, pDstData, DstSize); + + if (!s) + { + WLog_Print(gfx->log, WLOG_ERROR, "calloc failed!"); + free(pDstData); + return CHANNEL_RC_NO_MEMORY; + } + + while (Stream_GetPosition(s) < Stream_Length(s)) + { + if ((error = rdpgfx_recv_pdu(callback, s))) + { + WLog_Print(gfx->log, WLOG_ERROR, "rdpgfx_recv_pdu failed with error %" PRIu32 "!", + error); + break; + } + } + + free(pDstData); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_on_open(IWTSVirtualChannelCallback* pChannelCallback) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + UINT error = CHANNEL_RC_OK; + BOOL do_caps_advertise = TRUE; + gfx->sendFrameAcks = TRUE; + + if (context) + { + IFCALLRET(context->OnOpen, error, context, &do_caps_advertise, &gfx->sendFrameAcks); + + if (error) + WLog_Print(gfx->log, WLOG_ERROR, "context->OnOpen failed with error %" PRIu32 "", + error); + } + + if (do_caps_advertise) + error = rdpgfx_send_supported_caps(callback); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + UINT error = CHANNEL_RC_OK; + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + WINPR_ASSERT(callback); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)callback->plugin; + + if (!gfx) + goto fail; + + RdpgfxClientContext* context = gfx->context; + + DEBUG_RDPGFX(gfx->log, "OnClose"); + error = rdpgfx_save_persistent_cache(gfx); + + if (error) + { + // print error, but don't consider this a hard failure + WLog_Print(gfx->log, WLOG_ERROR, + "rdpgfx_save_persistent_cache failed with error %" PRIu32 "", error); + } + + free_surfaces(context, gfx->SurfaceTable); + evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots); + + free(callback); + gfx->UnacknowledgedFrames = 0; + gfx->TotalDecodedFrames = 0; + + if (context) + { + IFCALL(context->OnClose, context); + } + +fail: + return CHANNEL_RC_OK; +} + +static void terminate_plugin_cb(GENERIC_DYNVC_PLUGIN* base) +{ + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)base; + WINPR_ASSERT(gfx); + RdpgfxClientContext* context = gfx->context; + + DEBUG_RDPGFX(gfx->log, "Terminated"); + rdpgfx_client_context_free(context); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context, UINT16 surfaceId, void* pData) +{ + ULONG_PTR key = 0; + WINPR_ASSERT(context); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)context->handle; + WINPR_ASSERT(gfx); + key = ((ULONG_PTR)surfaceId) + 1; + + if (pData) + { + if (!HashTable_Insert(gfx->SurfaceTable, (void*)key, pData)) + return ERROR_BAD_ARGUMENTS; + } + else + HashTable_Remove(gfx->SurfaceTable, (void*)key); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, UINT16** ppSurfaceIds, + UINT16* count_out) +{ + size_t count = 0; + UINT16* pSurfaceIds = NULL; + ULONG_PTR* pKeys = NULL; + WINPR_ASSERT(context); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)context->handle; + WINPR_ASSERT(gfx); + count = HashTable_GetKeys(gfx->SurfaceTable, &pKeys); + + WINPR_ASSERT(ppSurfaceIds); + WINPR_ASSERT(count_out); + if (count < 1) + { + *count_out = 0; + return CHANNEL_RC_OK; + } + + pSurfaceIds = (UINT16*)calloc(count, sizeof(UINT16)); + + if (!pSurfaceIds) + { + WLog_Print(gfx->log, WLOG_ERROR, "calloc failed!"); + free(pKeys); + return CHANNEL_RC_NO_MEMORY; + } + + for (size_t index = 0; index < count; index++) + { + pSurfaceIds[index] = (UINT16)(pKeys[index] - 1); + } + + free(pKeys); + *ppSurfaceIds = pSurfaceIds; + *count_out = (UINT16)count; + return CHANNEL_RC_OK; +} + +static void* rdpgfx_get_surface_data(RdpgfxClientContext* context, UINT16 surfaceId) +{ + ULONG_PTR key = 0; + void* pData = NULL; + WINPR_ASSERT(context); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)context->handle; + WINPR_ASSERT(gfx); + key = ((ULONG_PTR)surfaceId) + 1; + pData = HashTable_GetItemValue(gfx->SurfaceTable, (void*)key); + return pData; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot, void* pData) +{ + WINPR_ASSERT(context); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)context->handle; + + WINPR_ASSERT(gfx); + /* Microsoft uses 1-based indexing for the egfx bitmap cache ! */ + if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots) + { + WLog_ERR(TAG, "invalid cache slot %" PRIu16 ", must be between 1 and %" PRIu16 "", + cacheSlot, gfx->MaxCacheSlots); + return ERROR_INVALID_INDEX; + } + + gfx->CacheSlots[cacheSlot - 1] = pData; + return CHANNEL_RC_OK; +} + +static void* rdpgfx_get_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot) +{ + void* pData = NULL; + WINPR_ASSERT(context); + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)context->handle; + WINPR_ASSERT(gfx); + /* Microsoft uses 1-based indexing for the egfx bitmap cache ! */ + if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots) + { + WLog_ERR(TAG, "invalid cache slot %" PRIu16 ", must be between 1 and %" PRIu16 "", + cacheSlot, gfx->MaxCacheSlots); + return NULL; + } + + pData = gfx->CacheSlots[cacheSlot - 1]; + return pData; +} + +static UINT init_plugin_cb(GENERIC_DYNVC_PLUGIN* base, rdpContext* rcontext, rdpSettings* settings) +{ + RdpgfxClientContext* context = NULL; + RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*)base; + + WINPR_ASSERT(base); + gfx->rdpcontext = rcontext; + gfx->log = WLog_Get(TAG); + + gfx->SurfaceTable = HashTable_New(TRUE); + if (!gfx->SurfaceTable) + { + WLog_ERR(TAG, "HashTable_New for surfaces failed !"); + return CHANNEL_RC_NO_MEMORY; + } + + gfx->suspendFrameAcks = + freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxSuspendFrameAck); + gfx->MaxCacheSlots = + freerdp_settings_get_bool(gfx->rdpcontext->settings, FreeRDP_GfxSmallCache) ? 4096 : 25600; + + context = (RdpgfxClientContext*)calloc(1, sizeof(RdpgfxClientContext)); + if (!context) + { + WLog_ERR(TAG, "context calloc failed!"); + HashTable_Free(gfx->SurfaceTable); + gfx->SurfaceTable = NULL; + return CHANNEL_RC_NO_MEMORY; + } + + gfx->zgfx = zgfx_context_new(FALSE); + if (!gfx->zgfx) + { + WLog_ERR(TAG, "zgfx_context_new failed!"); + HashTable_Free(gfx->SurfaceTable); + gfx->SurfaceTable = NULL; + free(context); + return CHANNEL_RC_NO_MEMORY; + } + + context->handle = (void*)gfx; + context->GetSurfaceIds = rdpgfx_get_surface_ids; + context->SetSurfaceData = rdpgfx_set_surface_data; + context->GetSurfaceData = rdpgfx_get_surface_data; + context->SetCacheSlotData = rdpgfx_set_cache_slot_data; + context->GetCacheSlotData = rdpgfx_get_cache_slot_data; + context->CapsAdvertise = rdpgfx_send_caps_advertise_pdu; + context->FrameAcknowledge = rdpgfx_send_frame_acknowledge_pdu; + context->CacheImportOffer = rdpgfx_send_cache_import_offer_pdu; + context->QoeFrameAcknowledge = rdpgfx_send_qoe_frame_acknowledge_pdu; + + gfx->base.iface.pInterface = (void*)context; + gfx->context = context; + return CHANNEL_RC_OK; +} + +void rdpgfx_client_context_free(RdpgfxClientContext* context) +{ + + RDPGFX_PLUGIN* gfx = NULL; + + if (!context) + return; + + gfx = (RDPGFX_PLUGIN*)context->handle; + + free_surfaces(context, gfx->SurfaceTable); + evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots); + + if (gfx->zgfx) + { + zgfx_context_free(gfx->zgfx); + gfx->zgfx = NULL; + } + + HashTable_Free(gfx->SurfaceTable); + free(context); +} + +static const IWTSVirtualChannelCallback rdpgfx_callbacks = { rdpgfx_on_data_received, + rdpgfx_on_open, rdpgfx_on_close, + NULL }; + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE rdpgfx_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + return freerdp_generic_DVCPluginEntry(pEntryPoints, TAG, RDPGFX_DVC_CHANNEL_NAME, + sizeof(RDPGFX_PLUGIN), sizeof(GENERIC_CHANNEL_CALLBACK), + &rdpgfx_callbacks, init_plugin_cb, terminate_plugin_cb); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_main.h new file mode 100644 index 0000000000000000000000000000000000000000..41ce4afd5c367b6dcc58e6ebe5ae0a4d5f4fa441 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/client/rdpgfx_main.h @@ -0,0 +1,61 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2013-2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPGFX_CLIENT_MAIN_H +#define FREERDP_CHANNEL_RDPGFX_CLIENT_MAIN_H + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +typedef struct +{ + GENERIC_DYNVC_PLUGIN base; + + ZGFX_CONTEXT* zgfx; + UINT32 UnacknowledgedFrames; + UINT32 TotalDecodedFrames; + UINT64 StartDecodingTime; + BOOL suspendFrameAcks; + BOOL sendFrameAcks; + + wHashTable* SurfaceTable; + + UINT16 MaxCacheSlots; + void* CacheSlots[25600]; + rdpPersistentCache* persistent; + + rdpContext* rdpcontext; + + wLog* log; + RDPGFX_CAPSET ConnectionCaps; + RdpgfxClientContext* context; +} RDPGFX_PLUGIN; + +#endif /* FREERDP_CHANNEL_RDPGFX_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/rdpgfx_common.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/rdpgfx_common.c new file mode 100644 index 0000000000000000000000000000000000000000..775641c184ee8114fd8e5f572189a25dd00ec467 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/rdpgfx_common.c @@ -0,0 +1,197 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("rdpgfx.common") + +#include "rdpgfx_common.h" + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_read_header(wStream* s, RDPGFX_HEADER* header) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(header); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Read_UINT16(s, header->cmdId); /* cmdId (2 bytes) */ + Stream_Read_UINT16(s, header->flags); /* flags (2 bytes) */ + Stream_Read_UINT32(s, header->pduLength); /* pduLength (4 bytes) */ + + if (header->pduLength < 8) + { + WLog_ERR(TAG, "header->pduLength %u less than 8!", header->pduLength); + return ERROR_INVALID_DATA; + } + if (!Stream_CheckAndLogRequiredLength(TAG, s, (header->pduLength - 8))) + return ERROR_INVALID_DATA; + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_write_header(wStream* s, const RDPGFX_HEADER* header) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(header); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return CHANNEL_RC_NO_MEMORY; + Stream_Write_UINT16(s, header->cmdId); /* cmdId (2 bytes) */ + Stream_Write_UINT16(s, header->flags); /* flags (2 bytes) */ + Stream_Write_UINT32(s, header->pduLength); /* pduLength (4 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_read_point16(wStream* s, RDPGFX_POINT16* pt16) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(pt16); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pt16->x); /* x (2 bytes) */ + Stream_Read_UINT16(s, pt16->y); /* y (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_write_point16(wStream* s, const RDPGFX_POINT16* point16) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(point16); + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write_UINT16(s, point16->x); /* x (2 bytes) */ + Stream_Write_UINT16(s, point16->y); /* y (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_read_rect16(wStream* s, RECTANGLE_16* rect16) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(rect16); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, rect16->left); /* left (2 bytes) */ + Stream_Read_UINT16(s, rect16->top); /* top (2 bytes) */ + Stream_Read_UINT16(s, rect16->right); /* right (2 bytes) */ + Stream_Read_UINT16(s, rect16->bottom); /* bottom (2 bytes) */ + if (rect16->left >= rect16->right) + return ERROR_INVALID_DATA; + if (rect16->top >= rect16->bottom) + return ERROR_INVALID_DATA; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_write_rect16(wStream* s, const RECTANGLE_16* rect16) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(rect16); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write_UINT16(s, rect16->left); /* left (2 bytes) */ + Stream_Write_UINT16(s, rect16->top); /* top (2 bytes) */ + Stream_Write_UINT16(s, rect16->right); /* right (2 bytes) */ + Stream_Write_UINT16(s, rect16->bottom); /* bottom (2 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_read_color32(wStream* s, RDPGFX_COLOR32* color32) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(color32); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT8(s, color32->B); /* B (1 byte) */ + Stream_Read_UINT8(s, color32->G); /* G (1 byte) */ + Stream_Read_UINT8(s, color32->R); /* R (1 byte) */ + Stream_Read_UINT8(s, color32->XA); /* XA (1 byte) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpgfx_write_color32(wStream* s, const RDPGFX_COLOR32* color32) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(color32); + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write_UINT8(s, color32->B); /* B (1 byte) */ + Stream_Write_UINT8(s, color32->G); /* G (1 byte) */ + Stream_Write_UINT8(s, color32->R); /* R (1 byte) */ + Stream_Write_UINT8(s, color32->XA); /* XA (1 byte) */ + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/rdpgfx_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/rdpgfx_common.h new file mode 100644 index 0000000000000000000000000000000000000000..246b6aee7e39ddd7fd80d523ed39c935351c5a20 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/rdpgfx_common.h @@ -0,0 +1,54 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPGFX_COMMON_H +#define FREERDP_CHANNEL_RDPGFX_COMMON_H + +#include +#include + +#include +#include +#include +#include + +FREERDP_LOCAL UINT rdpgfx_read_header(wStream* s, RDPGFX_HEADER* header); +FREERDP_LOCAL UINT rdpgfx_write_header(wStream* s, const RDPGFX_HEADER* header); + +FREERDP_LOCAL UINT rdpgfx_read_point16(wStream* s, RDPGFX_POINT16* pt16); +FREERDP_LOCAL UINT rdpgfx_write_point16(wStream* s, const RDPGFX_POINT16* point16); + +FREERDP_LOCAL UINT rdpgfx_read_rect16(wStream* s, RECTANGLE_16* rect16); +FREERDP_LOCAL UINT rdpgfx_write_rect16(wStream* s, const RECTANGLE_16* rect16); + +FREERDP_LOCAL UINT rdpgfx_read_color32(wStream* s, RDPGFX_COLOR32* color32); +FREERDP_LOCAL UINT rdpgfx_write_color32(wStream* s, const RDPGFX_COLOR32* color32); + +#ifdef WITH_DEBUG_RDPGFX +#define DEBUG_RDPGFX(_LOGGER, ...) WLog_Print(_LOGGER, WLOG_DEBUG, __VA_ARGS__) +#else +#define DEBUG_RDPGFX(_LOGGER, ...) \ + do \ + { \ + } while (0) +#endif + +#endif /* FREERDP_CHANNEL_RDPGFX_COMMON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3c47952f7d975526765574e5079f08ed984f4724 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2016 Jiang Zihao +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("rdpgfx") + +set(${MODULE_PREFIX}_SRCS rdpgfx_main.c rdpgfx_main.h ../rdpgfx_common.c ../rdpgfx_common.h) + +set(${MODULE_PREFIX}_LIBS freerdp) + +include_directories(..) + +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/rdpgfx_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/rdpgfx_main.c new file mode 100644 index 0000000000000000000000000000000000000000..eccf178320f4acaa3e031fac94d3e9e9e7d52dd6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/rdpgfx_main.c @@ -0,0 +1,1882 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2016 Jiang Zihao + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "rdpgfx_common.h" +#include "rdpgfx_main.h" + +#define TAG CHANNELS_TAG("rdpgfx.server") +#define RDPGFX_RESET_GRAPHICS_PDU_SIZE 340 + +#define checkCapsAreExchanged(context) \ + checkCapsAreExchangedInt(context, __FILE__, __func__, __LINE__) +static BOOL checkCapsAreExchangedInt(RdpgfxServerContext* context, const char* file, + const char* fkt, size_t line) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + const DWORD level = WLOG_TRACE; + if (WLog_IsLevelActive(context->priv->log, level)) + { + WLog_PrintMessage(context->priv->log, WLOG_MESSAGE_TEXT, level, line, file, fkt, + "activeCapSet{Version=0x%08" PRIx32 ", flags=0x%08" PRIx32 "}", + context->priv->activeCapSet.version, context->priv->activeCapSet.flags); + } + return context->priv->activeCapSet.version > 0; +} + +/** + * Function description + * Calculate packet size from data length. + * It would be data length + header. + * + * @param dataLen estimated data length without header + * + * @return new stream + */ +static INLINE UINT32 rdpgfx_pdu_length(UINT32 dataLen) +{ + return RDPGFX_HEADER_SIZE + dataLen; +} + +static INLINE UINT rdpgfx_server_packet_init_header(wStream* s, UINT16 cmdId, UINT32 pduLength) +{ + RDPGFX_HEADER header; + header.flags = 0; + header.cmdId = cmdId; + header.pduLength = pduLength; + /* Write header. Note that actual length might be changed + * after the entire packet has been constructed. */ + return rdpgfx_write_header(s, &header); +} + +/** + * Function description + * Complete the rdpgfx packet header. + * + * @param s stream + * @param start saved start pos of the packet in the stream + */ +static INLINE BOOL rdpgfx_server_packet_complete_header(wStream* s, size_t start) +{ + const size_t current = Stream_GetPosition(s); + const size_t cap = Stream_Capacity(s); + if (cap < start + RDPGFX_HEADER_SIZE) + return FALSE; + if ((start > UINT32_MAX) || (current < start)) + return FALSE; + /* Fill actual length */ + Stream_SetPosition(s, start + RDPGFX_HEADER_SIZE - sizeof(UINT32)); + Stream_Write_UINT32(s, (UINT32)(current - start)); /* pduLength (4 bytes) */ + Stream_SetPosition(s, current); + return TRUE; +} + +/** + * Function description + * Send the stream for rdpgfx server packet. + * The packet would be compressed according to [MS-RDPEGFX]. + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_server_packet_send(RdpgfxServerContext* context, wStream* s) +{ + UINT error = 0; + UINT32 flags = 0; + ULONG written = 0; + BYTE* pSrcData = Stream_Buffer(s); + const size_t SrcSize = Stream_GetPosition(s); + if (SrcSize > UINT32_MAX) + return ERROR_INTERNAL_ERROR; + + wStream* fs = NULL; + /* Allocate new stream with enough capacity. Additional overhead is + * descriptor (1 bytes) + segmentCount (2 bytes) + uncompressedSize (4 bytes) + * + segmentCount * size (4 bytes) */ + fs = Stream_New(NULL, SrcSize + 7 + (SrcSize / ZGFX_SEGMENTED_MAXSIZE + 1) * 4); + + if (!fs) + { + WLog_Print(context->priv->log, WLOG_ERROR, "Stream_New failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + if (zgfx_compress_to_stream(context->priv->zgfx, fs, pSrcData, (UINT32)SrcSize, &flags) < 0) + { + WLog_Print(context->priv->log, WLOG_ERROR, "zgfx_compress_to_stream failed!"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + const size_t pos = Stream_GetPosition(fs); + + WINPR_ASSERT(pos <= UINT32_MAX); + if (!WTSVirtualChannelWrite(context->priv->rdpgfx_channel, Stream_BufferAs(fs, char), + (UINT32)pos, &written)) + { + WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + if (written < Stream_GetPosition(fs)) + { + WLog_Print(context->priv->log, WLOG_WARN, + "Unexpected bytes written: %" PRIu32 "/%" PRIuz "", written, + Stream_GetPosition(fs)); + } + + error = CHANNEL_RC_OK; +out: + Stream_Free(fs, TRUE); + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * Create new stream for single rdpgfx packet. The new stream length + * would be required data length + header. The header will be written + * to the stream before return, but the pduLength field might be + * changed in rdpgfx_server_single_packet_send. + * + * @param cmdId The CommandID to write + * @param dataLen estimated data length without header + * + * @return new stream + */ +static wStream* rdpgfx_server_single_packet_new(wLog* log, UINT16 cmdId, UINT32 dataLen) +{ + UINT error = 0; + wStream* s = NULL; + UINT32 pduLength = rdpgfx_pdu_length(dataLen); + s = Stream_New(NULL, pduLength); + + if (!s) + { + WLog_Print(log, WLOG_ERROR, "Stream_New failed!"); + goto error; + } + + if ((error = rdpgfx_server_packet_init_header(s, cmdId, pduLength))) + { + WLog_Print(log, WLOG_ERROR, "Failed to init header with error %" PRIu32 "!", error); + goto error; + } + + return s; +error: + Stream_Free(s, TRUE); + return NULL; +} + +/** + * Function description + * Send the stream for single rdpgfx packet. + * The header will be filled with actual length. + * The packet would be compressed according to [MS-RDPEGFX]. + * + * @return 0 on success, otherwise a Win32 error code + */ +static INLINE UINT rdpgfx_server_single_packet_send(RdpgfxServerContext* context, wStream* s) +{ + /* Fill actual length */ + rdpgfx_server_packet_complete_header(s, 0); + return rdpgfx_server_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_caps_confirm_pdu(RdpgfxServerContext* context, + const RDPGFX_CAPS_CONFIRM_PDU* capsConfirm) +{ + wStream* s = NULL; + RDPGFX_CAPSET* capsSet = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(capsConfirm); + + capsSet = capsConfirm->capsSet; + WINPR_ASSERT(capsSet); + + s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CAPSCONFIRM, + RDPGFX_CAPSET_BASE_SIZE + capsSet->length); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + WLog_DBG(TAG, "CAPS version=0x%04" PRIx32 ", flags=0x%04" PRIx32 ", length=%" PRIu32, + capsSet->version, capsSet->flags, capsSet->length); + Stream_Write_UINT32(s, capsSet->version); /* version (4 bytes) */ + Stream_Write_UINT32(s, capsSet->length); /* capsDataLength (4 bytes) */ + + if (capsSet->length >= 4) + { + Stream_Write_UINT32(s, capsSet->flags); /* capsData (4 bytes) */ + Stream_Zero(s, capsSet->length - 4); + } + else + Stream_Zero(s, capsSet->length); + + context->priv->activeCapSet = *capsSet; + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_reset_graphics_pdu(RdpgfxServerContext* context, + const RDPGFX_RESET_GRAPHICS_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + + wStream* s = NULL; + + /* Check monitorCount. This ensures total size within 340 bytes) */ + if (pdu->monitorCount >= 16) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "Monitor count MUST be less than or equal to 16: %" PRIu32 "", + pdu->monitorCount); + return ERROR_INVALID_DATA; + } + + s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_RESETGRAPHICS, + RDPGFX_RESET_GRAPHICS_PDU_SIZE - RDPGFX_HEADER_SIZE); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT32(s, pdu->width); /* width (4 bytes) */ + Stream_Write_UINT32(s, pdu->height); /* height (4 bytes) */ + Stream_Write_UINT32(s, pdu->monitorCount); /* monitorCount (4 bytes) */ + + for (UINT32 index = 0; index < pdu->monitorCount; index++) + { + const MONITOR_DEF* monitor = &(pdu->monitorDefArray[index]); + Stream_Write_INT32(s, monitor->left); /* left (4 bytes) */ + Stream_Write_INT32(s, monitor->top); /* top (4 bytes) */ + Stream_Write_INT32(s, monitor->right); /* right (4 bytes) */ + Stream_Write_INT32(s, monitor->bottom); /* bottom (4 bytes) */ + Stream_Write_UINT32(s, monitor->flags); /* flags (4 bytes) */ + } + + /* pad (total size must be 340 bytes) */ + Stream_SetPosition(s, RDPGFX_RESET_GRAPHICS_PDU_SIZE); + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_evict_cache_entry_pdu(RdpgfxServerContext* context, + const RDPGFX_EVICT_CACHE_ENTRY_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = + rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_EVICTCACHEENTRY, 2); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->cacheSlot); /* cacheSlot (2 bytes) */ + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_cache_import_reply_pdu(RdpgfxServerContext* context, + const RDPGFX_CACHE_IMPORT_REPLY_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + WINPR_ASSERT(context); + WINPR_ASSERT(pdu); + + WLog_DBG(TAG, "reply with %" PRIu16 " entries", pdu->importedEntriesCount); + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CACHEIMPORTREPLY, + 2 + 2 * pdu->importedEntriesCount); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + /* importedEntriesCount (2 bytes) */ + Stream_Write_UINT16(s, pdu->importedEntriesCount); + + for (UINT16 index = 0; index < pdu->importedEntriesCount; index++) + { + Stream_Write_UINT16(s, pdu->cacheSlots[index]); /* cacheSlot (2 bytes) */ + } + + return rdpgfx_server_single_packet_send(context, s); +} + +static UINT +rdpgfx_process_cache_import_offer_pdu(RdpgfxServerContext* context, + const RDPGFX_CACHE_IMPORT_OFFER_PDU* cacheImportOffer) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + WINPR_ASSERT(context); + WINPR_ASSERT(cacheImportOffer); + + RDPGFX_CACHE_IMPORT_REPLY_PDU reply = { 0 }; + WLog_DBG(TAG, "received %" PRIu16 " entries, reply with %" PRIu16 " entries", + cacheImportOffer->cacheEntriesCount, reply.importedEntriesCount); + return IFCALLRESULT(CHANNEL_RC_OK, context->CacheImportReply, context, &reply); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_create_surface_pdu(RdpgfxServerContext* context, + const RDPGFX_CREATE_SURFACE_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CREATESURFACE, 7); + + WINPR_ASSERT(context); + WINPR_ASSERT(pdu); + WINPR_ASSERT((pdu->pixelFormat == GFX_PIXEL_FORMAT_XRGB_8888) || + (pdu->pixelFormat == GFX_PIXEL_FORMAT_ARGB_8888)); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT16(s, pdu->width); /* width (2 bytes) */ + Stream_Write_UINT16(s, pdu->height); /* height (2 bytes) */ + Stream_Write_UINT8(s, pdu->pixelFormat); /* RDPGFX_PIXELFORMAT (1 byte) */ + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_delete_surface_pdu(RdpgfxServerContext* context, + const RDPGFX_DELETE_SURFACE_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_DELETESURFACE, 2); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + return rdpgfx_server_single_packet_send(context, s); +} + +static INLINE BOOL rdpgfx_write_start_frame_pdu(wStream* s, const RDPGFX_START_FRAME_PDU* pdu) +{ + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + Stream_Write_UINT32(s, pdu->timestamp); /* timestamp (4 bytes) */ + Stream_Write_UINT32(s, pdu->frameId); /* frameId (4 bytes) */ + return TRUE; +} + +static INLINE BOOL rdpgfx_write_end_frame_pdu(wStream* s, const RDPGFX_END_FRAME_PDU* pdu) +{ + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + Stream_Write_UINT32(s, pdu->frameId); /* frameId (4 bytes) */ + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_start_frame_pdu(RdpgfxServerContext* context, + const RDPGFX_START_FRAME_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_STARTFRAME, + RDPGFX_START_FRAME_PDU_SIZE); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rdpgfx_write_start_frame_pdu(s, pdu); + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_end_frame_pdu(RdpgfxServerContext* context, const RDPGFX_END_FRAME_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_ENDFRAME, + RDPGFX_END_FRAME_PDU_SIZE); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + rdpgfx_write_end_frame_pdu(s, pdu); + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * Estimate RFX_AVC420_BITMAP_STREAM structure size in stream + * + * @return estimated size + */ +static INLINE UINT32 rdpgfx_estimate_h264_avc420(const RDPGFX_AVC420_BITMAP_STREAM* havc420) +{ + /* H264 metadata + H264 stream. See rdpgfx_write_h264_avc420 */ + return sizeof(UINT32) /* numRegionRects */ + + 10ULL /* regionRects + quantQualityVals */ + * havc420->meta.numRegionRects + + havc420->length; +} + +/** + * Function description + * Estimate surface command packet size in stream without header + * + * @return estimated size + */ +static INLINE UINT32 rdpgfx_estimate_surface_command(const RDPGFX_SURFACE_COMMAND* cmd) +{ + RDPGFX_AVC420_BITMAP_STREAM* havc420 = NULL; + RDPGFX_AVC444_BITMAP_STREAM* havc444 = NULL; + UINT32 h264Size = 0; + + /* Estimate stream size according to codec. */ + switch (cmd->codecId) + { + case RDPGFX_CODECID_CAPROGRESSIVE: + case RDPGFX_CODECID_CAPROGRESSIVE_V2: + return RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE + cmd->length; + + case RDPGFX_CODECID_AVC420: + havc420 = (RDPGFX_AVC420_BITMAP_STREAM*)cmd->extra; + h264Size = rdpgfx_estimate_h264_avc420(havc420); + return RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE + h264Size; + + case RDPGFX_CODECID_AVC444: + havc444 = (RDPGFX_AVC444_BITMAP_STREAM*)cmd->extra; + h264Size = sizeof(UINT32); /* cbAvc420EncodedBitstream1 */ + /* avc420EncodedBitstream1 */ + havc420 = &(havc444->bitstream[0]); + h264Size += rdpgfx_estimate_h264_avc420(havc420); + + /* avc420EncodedBitstream2 */ + if (havc444->LC == 0) + { + havc420 = &(havc444->bitstream[1]); + h264Size += rdpgfx_estimate_h264_avc420(havc420); + } + + return RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE + h264Size; + + default: + return RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE + cmd->length; + } +} + +/** + * Function description + * Resolve RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 + * according to codecId + * + * @return 0 on success, otherwise a Win32 error code + */ +static INLINE UINT16 rdpgfx_surface_command_cmdid(const RDPGFX_SURFACE_COMMAND* cmd) +{ + if (cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE || + cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE_V2) + { + return RDPGFX_CMDID_WIRETOSURFACE_2; + } + + return RDPGFX_CMDID_WIRETOSURFACE_1; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_write_h264_metablock(wLog* log, wStream* s, const RDPGFX_H264_METABLOCK* meta) +{ + RECTANGLE_16* regionRect = NULL; + RDPGFX_H264_QUANT_QUALITY* quantQualityVal = NULL; + UINT error = CHANNEL_RC_OK; + + if (!Stream_EnsureRemainingCapacity(s, 4 + meta->numRegionRects * 10)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(s, meta->numRegionRects); /* numRegionRects (4 bytes) */ + + for (UINT32 index = 0; index < meta->numRegionRects; index++) + { + regionRect = &(meta->regionRects[index]); + + if ((error = rdpgfx_write_rect16(s, regionRect))) + { + WLog_Print(log, WLOG_ERROR, "rdpgfx_write_rect16 failed with error %" PRIu32 "!", + error); + return error; + } + } + + for (UINT32 index = 0; index < meta->numRegionRects; index++) + { + quantQualityVal = &(meta->quantQualityVals[index]); + Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST( + uint8_t, quantQualityVal->qp | (quantQualityVal->r << 6) | + (quantQualityVal->p << 7))); /* qpVal (1 byte) */ + /* qualityVal (1 byte) */ + Stream_Write_UINT8(s, quantQualityVal->qualityVal); + } + + return error; +} + +/** + * Function description + * Write RFX_AVC420_BITMAP_STREAM structure to stream + * + * @return 0 on success, otherwise a Win32 error code + */ +static INLINE UINT rdpgfx_write_h264_avc420(wLog* log, wStream* s, + RDPGFX_AVC420_BITMAP_STREAM* havc420) +{ + UINT error = CHANNEL_RC_OK; + + if ((error = rdpgfx_write_h264_metablock(log, s, &(havc420->meta)))) + { + WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_metablock failed with error %" PRIu32 "!", + error); + return error; + } + + if (!Stream_EnsureRemainingCapacity(s, havc420->length)) + return ERROR_OUTOFMEMORY; + + Stream_Write(s, havc420->data, havc420->length); + return error; +} + +/** + * Function description + * Write RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 + * to the stream according to RDPGFX_SURFACE_COMMAND message + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_write_surface_command(wLog* log, wStream* s, const RDPGFX_SURFACE_COMMAND* cmd) +{ + UINT error = CHANNEL_RC_OK; + RDPGFX_AVC420_BITMAP_STREAM* havc420 = NULL; + RDPGFX_AVC444_BITMAP_STREAM* havc444 = NULL; + UINT8 pixelFormat = 0; + + switch (cmd->format) + { + case PIXEL_FORMAT_BGRX32: + pixelFormat = GFX_PIXEL_FORMAT_XRGB_8888; + break; + + case PIXEL_FORMAT_BGRA32: + pixelFormat = GFX_PIXEL_FORMAT_ARGB_8888; + break; + + default: + WLog_Print(log, WLOG_ERROR, "Format %s not supported!", + FreeRDPGetColorFormatName(cmd->format)); + return ERROR_INVALID_DATA; + } + + if (cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE || + cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE_V2) + { + if (!Stream_EnsureRemainingCapacity(s, 13 + cmd->length)) + return ERROR_INTERNAL_ERROR; + /* Write RDPGFX_CMDID_WIRETOSURFACE_2 format for CAPROGRESSIVE */ + Stream_Write_UINT16( + s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->surfaceId)); /* surfaceId (2 bytes) */ + Stream_Write_UINT16( + s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->codecId)); /* codecId (2 bytes) */ + Stream_Write_UINT32(s, cmd->contextId); /* codecContextId (4 bytes) */ + Stream_Write_UINT8(s, pixelFormat); /* pixelFormat (1 byte) */ + Stream_Write_UINT32(s, cmd->length); /* bitmapDataLength (4 bytes) */ + Stream_Write(s, cmd->data, cmd->length); + } + else + { + /* Write RDPGFX_CMDID_WIRETOSURFACE_1 format for others */ + if (!Stream_EnsureRemainingCapacity(s, 17)) + return ERROR_INTERNAL_ERROR; + Stream_Write_UINT16( + s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->surfaceId)); /* surfaceId (2 bytes) */ + Stream_Write_UINT16( + s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->codecId)); /* codecId (2 bytes) */ + Stream_Write_UINT8(s, pixelFormat); /* pixelFormat (1 byte) */ + Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->left)); /* left (2 bytes) */ + Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, cmd->top)); /* top (2 bytes) */ + Stream_Write_UINT16(s, + WINPR_ASSERTING_INT_CAST(uint16_t, cmd->right)); /* right (2 bytes) */ + Stream_Write_UINT16(s, + WINPR_ASSERTING_INT_CAST(uint16_t, cmd->bottom)); /* bottom (2 bytes) */ + Stream_Write_UINT32(s, cmd->length); /* bitmapDataLength (4 bytes) */ + const size_t bitmapDataStart = Stream_GetPosition(s); + + if (cmd->codecId == RDPGFX_CODECID_AVC420) + { + havc420 = (RDPGFX_AVC420_BITMAP_STREAM*)cmd->extra; + error = rdpgfx_write_h264_avc420(log, s, havc420); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_avc420 failed!"); + return error; + } + } + else if ((cmd->codecId == RDPGFX_CODECID_AVC444) || + (cmd->codecId == RDPGFX_CODECID_AVC444v2)) + { + havc444 = (RDPGFX_AVC444_BITMAP_STREAM*)cmd->extra; + havc420 = &(havc444->bitstream[0]); /* avc420EncodedBitstreamInfo (4 bytes) */ + if (!Stream_EnsureRemainingCapacity(s, 4)) + return ERROR_INTERNAL_ERROR; + Stream_Write_UINT32(s, havc444->cbAvc420EncodedBitstream1 | + ((uint32_t)havc444->LC << 30UL)); + /* avc420EncodedBitstream1 */ + error = rdpgfx_write_h264_avc420(log, s, havc420); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_avc420 failed!"); + return error; + } + + /* avc420EncodedBitstream2 */ + if (havc444->LC == 0) + { + havc420 = &(havc444->bitstream[1]); + error = rdpgfx_write_h264_avc420(log, s, havc420); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(log, WLOG_ERROR, "rdpgfx_write_h264_avc420 failed!"); + return error; + } + } + } + else + { + if (!Stream_EnsureRemainingCapacity(s, cmd->length)) + return ERROR_INTERNAL_ERROR; + Stream_Write(s, cmd->data, cmd->length); + } + + /* Fill actual bitmap data length */ + const size_t bitmapDataLength = Stream_GetPosition(s) - bitmapDataStart; + if (bitmapDataLength > UINT32_MAX) + return ERROR_INTERNAL_ERROR; + + Stream_SetPosition(s, bitmapDataStart - sizeof(UINT32)); + if (!Stream_EnsureRemainingCapacity(s, 4)) + return ERROR_INTERNAL_ERROR; + Stream_Write_UINT32(s, (UINT32)bitmapDataLength); /* bitmapDataLength (4 bytes) */ + if (!Stream_SafeSeek(s, bitmapDataLength)) + return ERROR_INTERNAL_ERROR; + } + + return error; +} + +/** + * Function description + * Send RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 + * message according to codecId + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_surface_command(RdpgfxServerContext* context, + const RDPGFX_SURFACE_COMMAND* cmd) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + UINT error = CHANNEL_RC_OK; + wStream* s = NULL; + s = rdpgfx_server_single_packet_new(context->priv->log, rdpgfx_surface_command_cmdid(cmd), + rdpgfx_estimate_surface_command(cmd)); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + error = rdpgfx_write_surface_command(context->priv->log, s, cmd); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_write_surface_command failed!"); + goto error; + } + + return rdpgfx_server_single_packet_send(context, s); +error: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * Send RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 + * message according to codecId. + * Prepend/append start/end frame message in same packet if exists. + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_surface_frame_command(RdpgfxServerContext* context, + const RDPGFX_SURFACE_COMMAND* cmd, + const RDPGFX_START_FRAME_PDU* startFrame, + const RDPGFX_END_FRAME_PDU* endFrame) + +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + UINT error = CHANNEL_RC_OK; + UINT32 size = rdpgfx_pdu_length(rdpgfx_estimate_surface_command(cmd)); + + if (startFrame) + { + size += rdpgfx_pdu_length(RDPGFX_START_FRAME_PDU_SIZE); + } + + if (endFrame) + { + size += rdpgfx_pdu_length(RDPGFX_END_FRAME_PDU_SIZE); + } + + wStream* s = Stream_New(NULL, size); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + /* Write start frame if exists */ + if (startFrame) + { + const size_t position = Stream_GetPosition(s); + error = rdpgfx_server_packet_init_header(s, RDPGFX_CMDID_STARTFRAME, 0); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "Failed to init header with error %" PRIu32 "!", error); + goto error; + } + + if (!rdpgfx_write_start_frame_pdu(s, startFrame) || + !rdpgfx_server_packet_complete_header(s, position)) + goto error; + } + + /* Write RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 */ + const size_t pos = Stream_GetPosition(s); + error = rdpgfx_server_packet_init_header(s, rdpgfx_surface_command_cmdid(cmd), + 0); // Actual length will be filled later + + if (error != CHANNEL_RC_OK) + { + WLog_Print(context->priv->log, WLOG_ERROR, "Failed to init header with error %" PRIu32 "!", + error); + goto error; + } + + error = rdpgfx_write_surface_command(context->priv->log, s, cmd); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_write_surface_command failed!"); + goto error; + } + + if (!rdpgfx_server_packet_complete_header(s, pos)) + goto error; + + /* Write end frame if exists */ + if (endFrame) + { + const size_t position = Stream_GetPosition(s); + error = rdpgfx_server_packet_init_header(s, RDPGFX_CMDID_ENDFRAME, 0); + + if (error != CHANNEL_RC_OK) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "Failed to init header with error %" PRIu32 "!", error); + goto error; + } + + if (!rdpgfx_write_end_frame_pdu(s, endFrame) || + !rdpgfx_server_packet_complete_header(s, position)) + goto error; + } + + return rdpgfx_server_packet_send(context, s); +error: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_delete_encoding_context_pdu(RdpgfxServerContext* context, + const RDPGFX_DELETE_ENCODING_CONTEXT_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = + rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_DELETEENCODINGCONTEXT, 6); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT32(s, pdu->codecContextId); /* codecContextId (4 bytes) */ + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_solid_fill_pdu(RdpgfxServerContext* context, + const RDPGFX_SOLID_FILL_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + UINT error = CHANNEL_RC_OK; + RECTANGLE_16* fillRect = NULL; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_SOLIDFILL, + 8 + 8 * pdu->fillRectCount); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + + /* fillPixel (4 bytes) */ + if ((error = rdpgfx_write_color32(s, &(pdu->fillPixel)))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_write_color32 failed with error %" PRIu32 "!", error); + goto error; + } + + Stream_Write_UINT16(s, pdu->fillRectCount); /* fillRectCount (2 bytes) */ + + for (UINT16 index = 0; index < pdu->fillRectCount; index++) + { + fillRect = &(pdu->fillRects[index]); + + if ((error = rdpgfx_write_rect16(s, fillRect))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_write_rect16 failed with error %" PRIu32 "!", error); + goto error; + } + } + + return rdpgfx_server_single_packet_send(context, s); +error: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_surface_to_surface_pdu(RdpgfxServerContext* context, + const RDPGFX_SURFACE_TO_SURFACE_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + UINT error = CHANNEL_RC_OK; + RDPGFX_POINT16* destPt = NULL; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_SURFACETOSURFACE, + 14 + 4 * pdu->destPtsCount); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceIdSrc); /* surfaceIdSrc (2 bytes) */ + Stream_Write_UINT16(s, pdu->surfaceIdDest); /* surfaceIdDest (2 bytes) */ + + /* rectSrc (8 bytes ) */ + if ((error = rdpgfx_write_rect16(s, &(pdu->rectSrc)))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_write_rect16 failed with error %" PRIu32 "!", error); + goto error; + } + + Stream_Write_UINT16(s, pdu->destPtsCount); /* destPtsCount (2 bytes) */ + + for (UINT16 index = 0; index < pdu->destPtsCount; index++) + { + destPt = &(pdu->destPts[index]); + + if ((error = rdpgfx_write_point16(s, destPt))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_write_point16 failed with error %" PRIu32 "!", error); + goto error; + } + } + + return rdpgfx_server_single_packet_send(context, s); +error: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_surface_to_cache_pdu(RdpgfxServerContext* context, + const RDPGFX_SURFACE_TO_CACHE_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + UINT error = CHANNEL_RC_OK; + wStream* s = + rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_SURFACETOCACHE, 20); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT64(s, pdu->cacheKey); /* cacheKey (8 bytes) */ + Stream_Write_UINT16(s, pdu->cacheSlot); /* cacheSlot (2 bytes) */ + + /* rectSrc (8 bytes ) */ + if ((error = rdpgfx_write_rect16(s, &(pdu->rectSrc)))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_write_rect16 failed with error %" PRIu32 "!", error); + goto error; + } + + return rdpgfx_server_single_packet_send(context, s); +error: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_cache_to_surface_pdu(RdpgfxServerContext* context, + const RDPGFX_CACHE_TO_SURFACE_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + UINT error = CHANNEL_RC_OK; + RDPGFX_POINT16* destPt = NULL; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_CACHETOSURFACE, + 6 + 4 * pdu->destPtsCount); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->cacheSlot); /* cacheSlot (2 bytes) */ + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT16(s, pdu->destPtsCount); /* destPtsCount (2 bytes) */ + + for (UINT16 index = 0; index < pdu->destPtsCount; index++) + { + destPt = &(pdu->destPts[index]); + + if ((error = rdpgfx_write_point16(s, destPt))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_write_point16 failed with error %" PRIu32 "", error); + goto error; + } + } + + return rdpgfx_server_single_packet_send(context, s); +error: + Stream_Free(s, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_map_surface_to_output_pdu(RdpgfxServerContext* context, + const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = + rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_MAPSURFACETOOUTPUT, 12); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT16(s, 0); /* reserved (2 bytes). Must be 0 */ + Stream_Write_UINT32(s, pdu->outputOriginX); /* outputOriginX (4 bytes) */ + Stream_Write_UINT32(s, pdu->outputOriginY); /* outputOriginY (4 bytes) */ + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_send_map_surface_to_window_pdu(RdpgfxServerContext* context, + const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = + rdpgfx_server_single_packet_new(context->priv->log, RDPGFX_CMDID_MAPSURFACETOWINDOW, 18); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT64(s, pdu->windowId); /* windowId (8 bytes) */ + Stream_Write_UINT32(s, pdu->mappedWidth); /* mappedWidth (4 bytes) */ + Stream_Write_UINT32(s, pdu->mappedHeight); /* mappedHeight (4 bytes) */ + return rdpgfx_server_single_packet_send(context, s); +} + +static UINT +rdpgfx_send_map_surface_to_scaled_window_pdu(RdpgfxServerContext* context, + const RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, + RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW, 26); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT64(s, pdu->windowId); /* windowId (8 bytes) */ + Stream_Write_UINT32(s, pdu->mappedWidth); /* mappedWidth (4 bytes) */ + Stream_Write_UINT32(s, pdu->mappedHeight); /* mappedHeight (4 bytes) */ + Stream_Write_UINT32(s, pdu->targetWidth); /* targetWidth (4 bytes) */ + Stream_Write_UINT32(s, pdu->targetHeight); /* targetHeight (4 bytes) */ + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_frame_acknowledge_pdu(RdpgfxServerContext* context, wStream* s) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + RDPGFX_FRAME_ACKNOWLEDGE_PDU pdu; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, pdu.queueDepth); /* queueDepth (4 bytes) */ + Stream_Read_UINT32(s, pdu.frameId); /* frameId (4 bytes) */ + Stream_Read_UINT32(s, pdu.totalFramesDecoded); /* totalFramesDecoded (4 bytes) */ + + if (context) + { + IFCALLRET(context->FrameAcknowledge, error, context, &pdu); + + if (error) + WLog_Print(context->priv->log, WLOG_ERROR, + "context->FrameAcknowledge failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_cache_import_offer_pdu(RdpgfxServerContext* context, wStream* s) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + + RDPGFX_CACHE_IMPORT_OFFER_PDU pdu = { 0 }; + RDPGFX_CACHE_ENTRY_METADATA* cacheEntry = NULL; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_INVALID_DATA; + + /* cacheEntriesCount (2 bytes) */ + Stream_Read_UINT16(s, pdu.cacheEntriesCount); + + /* 2.2.2.16 RDPGFX_CACHE_IMPORT_OFFER_PDU */ + if (pdu.cacheEntriesCount >= 5462) + { + WLog_Print(context->priv->log, WLOG_ERROR, "Invalid cacheEntriesCount: %" PRIu16 "", + pdu.cacheEntriesCount); + return ERROR_INVALID_DATA; + } + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, pdu.cacheEntriesCount, 12ull)) + return ERROR_INVALID_DATA; + + for (UINT16 index = 0; index < pdu.cacheEntriesCount; index++) + { + cacheEntry = &(pdu.cacheEntries[index]); + Stream_Read_UINT64(s, cacheEntry->cacheKey); /* cacheKey (8 bytes) */ + Stream_Read_UINT32(s, cacheEntry->bitmapLength); /* bitmapLength (4 bytes) */ + } + + if (context) + { + IFCALLRET(context->CacheImportOffer, error, context, &pdu); + + if (error) + WLog_Print(context->priv->log, WLOG_ERROR, + "context->CacheImportOffer failed with error %" PRIu32 "", error); + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_caps_advertise_pdu(RdpgfxServerContext* context, wStream* s) +{ + RDPGFX_CAPSET* capsSets = NULL; + RDPGFX_CAPS_ADVERTISE_PDU pdu = { 0 }; + UINT error = ERROR_INVALID_DATA; + + if (!context) + return ERROR_BAD_ARGUMENTS; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, pdu.capsSetCount); /* capsSetCount (2 bytes) */ + if (pdu.capsSetCount > 0) + { + capsSets = calloc(pdu.capsSetCount, (RDPGFX_CAPSET_BASE_SIZE + 4)); + if (!capsSets) + return ERROR_OUTOFMEMORY; + } + + pdu.capsSets = capsSets; + + for (UINT16 index = 0; index < pdu.capsSetCount; index++) + { + RDPGFX_CAPSET* capsSet = &(pdu.capsSets[index]); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + goto fail; + + Stream_Read_UINT32(s, capsSet->version); /* version (4 bytes) */ + Stream_Read_UINT32(s, capsSet->length); /* capsDataLength (4 bytes) */ + + if (capsSet->length >= 4) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + goto fail; + + Stream_Peek_UINT32(s, capsSet->flags); /* capsData (4 bytes) */ + } + + if (!Stream_SafeSeek(s, capsSet->length)) + goto fail; + } + + error = ERROR_BAD_CONFIGURATION; + IFCALLRET(context->CapsAdvertise, error, context, &pdu); + + if (error) + WLog_Print(context->priv->log, WLOG_ERROR, + "context->CapsAdvertise failed with error %" PRIu32 "", error); + +fail: + free(capsSets); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_recv_qoe_frame_acknowledge_pdu(RdpgfxServerContext* context, wStream* s) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU pdu; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, pdu.frameId); /* frameId (4 bytes) */ + Stream_Read_UINT32(s, pdu.timestamp); /* timestamp (4 bytes) */ + Stream_Read_UINT16(s, pdu.timeDiffSE); /* timeDiffSE (2 bytes) */ + Stream_Read_UINT16(s, pdu.timeDiffEDR); /* timeDiffEDR (2 bytes) */ + + if (context) + { + IFCALLRET(context->QoeFrameAcknowledge, error, context, &pdu); + + if (error) + WLog_Print(context->priv->log, WLOG_ERROR, + "context->QoeFrameAcknowledge failed with error %" PRIu32 "", error); + } + + return error; +} + +static UINT +rdpgfx_send_map_surface_to_scaled_output_pdu(RdpgfxServerContext* context, + const RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU* pdu) +{ + if (!checkCapsAreExchanged(context)) + return CHANNEL_RC_NOT_INITIALIZED; + wStream* s = rdpgfx_server_single_packet_new(context->priv->log, + RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT, 20); + + if (!s) + { + WLog_Print(context->priv->log, WLOG_ERROR, "rdpgfx_server_single_packet_new failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT16(s, pdu->surfaceId); /* surfaceId (2 bytes) */ + Stream_Write_UINT16(s, 0); /* reserved (2 bytes). Must be 0 */ + Stream_Write_UINT32(s, pdu->outputOriginX); /* outputOriginX (4 bytes) */ + Stream_Write_UINT32(s, pdu->outputOriginY); /* outputOriginY (4 bytes) */ + Stream_Write_UINT32(s, pdu->targetWidth); /* targetWidth (4 bytes) */ + Stream_Write_UINT32(s, pdu->targetHeight); /* targetHeight (4 bytes) */ + return rdpgfx_server_single_packet_send(context, s); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpgfx_server_receive_pdu(RdpgfxServerContext* context, wStream* s) +{ + size_t beg = 0; + size_t end = 0; + RDPGFX_HEADER header; + UINT error = CHANNEL_RC_OK; + beg = Stream_GetPosition(s); + + if ((error = rdpgfx_read_header(s, &header))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_read_header failed with error %" PRIu32 "!", error); + return error; + } + +#ifdef WITH_DEBUG_RDPGFX + WLog_DBG(TAG, "cmdId: %s (0x%04" PRIX16 ") flags: 0x%04" PRIX16 " pduLength: %" PRIu32 "", + rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags, header.pduLength); +#endif + + switch (header.cmdId) + { + case RDPGFX_CMDID_FRAMEACKNOWLEDGE: + if ((error = rdpgfx_recv_frame_acknowledge_pdu(context, s))) + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_recv_frame_acknowledge_pdu " + "failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_CACHEIMPORTOFFER: + if ((error = rdpgfx_recv_cache_import_offer_pdu(context, s))) + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_recv_cache_import_offer_pdu " + "failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_CAPSADVERTISE: + if ((error = rdpgfx_recv_caps_advertise_pdu(context, s))) + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_recv_caps_advertise_pdu " + "failed with error %" PRIu32 "!", + error); + + break; + + case RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE: + if ((error = rdpgfx_recv_qoe_frame_acknowledge_pdu(context, s))) + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_recv_qoe_frame_acknowledge_pdu " + "failed with error %" PRIu32 "!", + error); + + break; + + default: + error = CHANNEL_RC_BAD_PROC; + break; + } + + if (error) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "Error while parsing GFX cmdId: %s (0x%04" PRIX16 ")", + rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId); + return error; + } + + end = Stream_GetPosition(s); + + if (end != (beg + header.pduLength)) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "Unexpected gfx pdu end: Actual: %" PRIuz ", Expected: %" PRIuz "", end, + (beg + header.pduLength)); + Stream_SetPosition(s, (beg + header.pduLength)); + } + + return error; +} + +static BOOL rdpgfx_server_close(RdpgfxServerContext* context); + +static DWORD WINAPI rdpgfx_server_thread_func(LPVOID arg) +{ + RdpgfxServerContext* context = (RdpgfxServerContext*)arg; + WINPR_ASSERT(context); + + RdpgfxServerPrivate* priv = context->priv; + DWORD status = 0; + DWORD nCount = 0; + HANDLE events[8] = { 0 }; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(priv); + + if (priv->ownThread) + { + WINPR_ASSERT(priv->stopEvent); + events[nCount++] = priv->stopEvent; + } + + WINPR_ASSERT(priv->channelEvent); + events[nCount++] = priv->channelEvent; + + /* Main virtual channel loop. RDPGFX do not need version negotiation */ + while (TRUE) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_Print(context->priv->log, WLOG_ERROR, + "WaitForMultipleObjects failed with error %" PRIu32 "", error); + break; + } + + /* Stop Event */ + if (status == WAIT_OBJECT_0) + break; + + if ((error = rdpgfx_server_handle_messages(context))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_server_handle_messages failed with error %" PRIu32 "", error); + break; + } + } + + if (error && context->rdpcontext) + setChannelError(context->rdpcontext, error, "rdpgfx_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +static BOOL rdpgfx_server_open(RdpgfxServerContext* context) +{ + WINPR_ASSERT(context); + RdpgfxServerPrivate* priv = context->priv; + void* buffer = NULL; + + WINPR_ASSERT(priv); + + if (!priv->isOpened) + { + PULONG pSessionId = NULL; + DWORD BytesReturned = 0; + priv->SessionId = WTS_CURRENT_SESSION; + UINT32 channelId = 0; + BOOL status = TRUE; + + if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_Print(context->priv->log, WLOG_ERROR, "WTSQuerySessionInformationA failed!"); + return FALSE; + } + + priv->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + priv->rdpgfx_channel = WTSVirtualChannelOpenEx(priv->SessionId, RDPGFX_DVC_CHANNEL_NAME, + WTS_CHANNEL_OPTION_DYNAMIC); + + if (!priv->rdpgfx_channel) + { + WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelOpenEx failed!"); + return FALSE; + } + + channelId = WTSChannelGetIdByHandle(priv->rdpgfx_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_Print(context->priv->log, WLOG_ERROR, "context->ChannelIdAssigned failed!"); + goto fail; + } + + /* Query for channel event handle */ + if (!WTSVirtualChannelQuery(priv->rdpgfx_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) || + (BytesReturned != sizeof(HANDLE))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "WTSVirtualChannelQuery failed " + "or invalid returned size(%" PRIu32 ")", + BytesReturned); + + if (buffer) + WTSFreeMemory(buffer); + + goto fail; + } + + priv->channelEvent = *(HANDLE*)buffer; + WTSFreeMemory(buffer); + + if (!(priv->zgfx = zgfx_context_new(TRUE))) + { + WLog_Print(context->priv->log, WLOG_ERROR, "Create zgfx context failed!"); + goto fail; + } + + priv->isReady = FALSE; + const RDPGFX_CAPSET empty = { 0 }; + priv->activeCapSet = empty; + if (priv->ownThread) + { + if (!(priv->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) + { + WLog_Print(context->priv->log, WLOG_ERROR, "CreateEvent failed!"); + goto fail; + } + + if (!(priv->thread = + CreateThread(NULL, 0, rdpgfx_server_thread_func, (void*)context, 0, NULL))) + { + WLog_Print(context->priv->log, WLOG_ERROR, "CreateThread failed!"); + goto fail; + } + } + + priv->isOpened = TRUE; + return TRUE; + } + + WLog_Print(context->priv->log, WLOG_ERROR, "RDPGFX channel is already opened!"); + return FALSE; +fail: + rdpgfx_server_close(context); + return FALSE; +} + +BOOL rdpgfx_server_close(RdpgfxServerContext* context) +{ + WINPR_ASSERT(context); + + RdpgfxServerPrivate* priv = context->priv; + WINPR_ASSERT(priv); + + if (priv->ownThread && priv->thread) + { + (void)SetEvent(priv->stopEvent); + + if (WaitForSingleObject(priv->thread, INFINITE) == WAIT_FAILED) + { + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", GetLastError()); + return FALSE; + } + + (void)CloseHandle(priv->thread); + (void)CloseHandle(priv->stopEvent); + priv->thread = NULL; + priv->stopEvent = NULL; + } + + zgfx_context_free(priv->zgfx); + priv->zgfx = NULL; + + if (priv->rdpgfx_channel) + { + (void)WTSVirtualChannelClose(priv->rdpgfx_channel); + priv->rdpgfx_channel = NULL; + } + + priv->channelEvent = NULL; + priv->isOpened = FALSE; + priv->isReady = FALSE; + const RDPGFX_CAPSET empty = { 0 }; + priv->activeCapSet = empty; + return TRUE; +} + +static BOOL rdpgfx_server_initialize(RdpgfxServerContext* context, BOOL externalThread) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + if (context->priv->isOpened) + { + WLog_Print(context->priv->log, WLOG_WARN, + "Application error: RDPEGFX channel already initialized, " + "calling in this state is not possible!"); + return FALSE; + } + + context->priv->ownThread = !externalThread; + return TRUE; +} + +RdpgfxServerContext* rdpgfx_server_context_new(HANDLE vcm) +{ + RdpgfxServerContext* context = (RdpgfxServerContext*)calloc(1, sizeof(RdpgfxServerContext)); + + if (!context) + { + WLog_ERR(TAG, "calloc failed!"); + return NULL; + } + + context->vcm = vcm; + context->Initialize = rdpgfx_server_initialize; + context->Open = rdpgfx_server_open; + context->Close = rdpgfx_server_close; + context->ResetGraphics = rdpgfx_send_reset_graphics_pdu; + context->StartFrame = rdpgfx_send_start_frame_pdu; + context->EndFrame = rdpgfx_send_end_frame_pdu; + context->SurfaceCommand = rdpgfx_send_surface_command; + context->SurfaceFrameCommand = rdpgfx_send_surface_frame_command; + context->DeleteEncodingContext = rdpgfx_send_delete_encoding_context_pdu; + context->CreateSurface = rdpgfx_send_create_surface_pdu; + context->DeleteSurface = rdpgfx_send_delete_surface_pdu; + context->SolidFill = rdpgfx_send_solid_fill_pdu; + context->SurfaceToSurface = rdpgfx_send_surface_to_surface_pdu; + context->SurfaceToCache = rdpgfx_send_surface_to_cache_pdu; + context->CacheToSurface = rdpgfx_send_cache_to_surface_pdu; + context->CacheImportOffer = rdpgfx_process_cache_import_offer_pdu; + context->CacheImportReply = rdpgfx_send_cache_import_reply_pdu; + context->EvictCacheEntry = rdpgfx_send_evict_cache_entry_pdu; + context->MapSurfaceToOutput = rdpgfx_send_map_surface_to_output_pdu; + context->MapSurfaceToWindow = rdpgfx_send_map_surface_to_window_pdu; + context->MapSurfaceToScaledOutput = rdpgfx_send_map_surface_to_scaled_output_pdu; + context->MapSurfaceToScaledWindow = rdpgfx_send_map_surface_to_scaled_window_pdu; + context->CapsAdvertise = NULL; + context->CapsConfirm = rdpgfx_send_caps_confirm_pdu; + context->FrameAcknowledge = NULL; + context->QoeFrameAcknowledge = NULL; + RdpgfxServerPrivate* priv = context->priv = + (RdpgfxServerPrivate*)calloc(1, sizeof(RdpgfxServerPrivate)); + + if (!priv) + { + WLog_ERR(TAG, "calloc failed!"); + goto fail; + } + + priv->log = WLog_Get(TAG); + if (!priv->log) + goto fail; + + /* Create shared input stream */ + priv->input_stream = Stream_New(NULL, 4); + + if (!priv->input_stream) + { + WLog_Print(context->priv->log, WLOG_ERROR, "Stream_New failed!"); + goto fail; + } + + priv->isOpened = FALSE; + priv->isReady = FALSE; + priv->ownThread = TRUE; + + const RDPGFX_CAPSET empty = { 0 }; + priv->activeCapSet = empty; + return context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + rdpgfx_server_context_free(context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void rdpgfx_server_context_free(RdpgfxServerContext* context) +{ + if (!context) + return; + + rdpgfx_server_close(context); + + if (context->priv) + Stream_Free(context->priv->input_stream, TRUE); + + free(context->priv); + free(context); +} + +HANDLE rdpgfx_server_get_event_handle(RdpgfxServerContext* context) +{ + if (!context) + return NULL; + if (!context->priv) + return NULL; + return context->priv->channelEvent; +} + +/* + * Handle rpdgfx messages - server side + * + * @param Server side context + * + * @return 0 on success + * ERROR_NO_DATA if no data could be read this time + * otherwise a Win32 error code + */ +UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context) +{ + DWORD BytesReturned = 0; + void* buffer = NULL; + UINT ret = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + RdpgfxServerPrivate* priv = context->priv; + wStream* s = priv->input_stream; + + /* Check whether the dynamic channel is ready */ + if (!priv->isReady) + { + if (WTSVirtualChannelQuery(priv->rdpgfx_channel, WTSVirtualChannelReady, &buffer, + &BytesReturned) == FALSE) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelQuery failed"); + return ERROR_INTERNAL_ERROR; + } + + priv->isReady = *((BOOL*)buffer); + WTSFreeMemory(buffer); + } + + /* Consume channel event only after the gfx dynamic channel is ready */ + if (priv->isReady) + { + Stream_SetPosition(s, 0); + + if (!WTSVirtualChannelRead(priv->rdpgfx_channel, 0, NULL, 0, &BytesReturned)) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + if (BytesReturned < 1) + return CHANNEL_RC_OK; + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_Print(context->priv->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + const size_t len = Stream_Capacity(s); + if (len > UINT32_MAX) + return ERROR_INTERNAL_ERROR; + if (WTSVirtualChannelRead(priv->rdpgfx_channel, 0, Stream_BufferAs(s, char), (UINT32)len, + &BytesReturned) == FALSE) + { + WLog_Print(context->priv->log, WLOG_ERROR, "WTSVirtualChannelRead failed!"); + return ERROR_INTERNAL_ERROR; + } + + Stream_SetLength(s, BytesReturned); + Stream_SetPosition(s, 0); + + while (Stream_GetPosition(s) < Stream_Length(s)) + { + if ((ret = rdpgfx_server_receive_pdu(context, s))) + { + WLog_Print(context->priv->log, WLOG_ERROR, + "rdpgfx_server_receive_pdu " + "failed with error %" PRIu32 "!", + ret); + return ret; + } + } + } + + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/rdpgfx_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/rdpgfx_main.h new file mode 100644 index 0000000000000000000000000000000000000000..8b184bb8961b6fe2547aef9c92b0026f7e4528f5 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpgfx/server/rdpgfx_main.h @@ -0,0 +1,42 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2016 Jiang Zihao + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPGFX_SERVER_MAIN_H +#define FREERDP_CHANNEL_RDPGFX_SERVER_MAIN_H + +#include +#include + +struct s_rdpgfx_server_private +{ + ZGFX_CONTEXT* zgfx; + BOOL ownThread; + HANDLE thread; + HANDLE stopEvent; + HANDLE channelEvent; + void* rdpgfx_channel; + DWORD SessionId; + wStream* input_stream; + BOOL isOpened; + BOOL isReady; + wLog* log; + RDPGFX_CAPSET activeCapSet; +}; + +#endif /* FREERDP_CHANNEL_RDPGFX_SERVER_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c749552bab6eb41689994f305bb3e40092f331b1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdpsnd") + +include_directories(common) +add_subdirectory(common) + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..f4a76335e20e9b7517150491afff4a47f798af3b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "rdpsnd" + TYPE + "static;dynamic" + DESCRIPTION + "Audio Output Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEA]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/alsa/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/alsa/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..63c2db3f2b86038e1fa559b3de2576ec461d79a7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/alsa/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "alsa" "") + +find_package(ALSA REQUIRED) + +set(${MODULE_PREFIX}_SRCS rdpsnd_alsa.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${ALSA_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${ALSA_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/alsa/rdpsnd_alsa.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/alsa/rdpsnd_alsa.c new file mode 100644 index 0000000000000000000000000000000000000000..003dcab871fe983650abb884ec5ed976d693ac41 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/alsa/rdpsnd_alsa.c @@ -0,0 +1,568 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; + + UINT32 latency; + AUDIO_FORMAT aformat; + char* device_name; + snd_pcm_t* pcm_handle; + snd_mixer_t* mixer_handle; + + UINT32 actual_rate; + snd_pcm_format_t format; + UINT32 actual_channels; + + snd_pcm_uframes_t buffer_size; + snd_pcm_uframes_t period_size; +} rdpsndAlsaPlugin; + +#define SND_PCM_CHECK(_func, _status) \ + do \ + { \ + if ((_status) < 0) \ + { \ + WLog_ERR(TAG, "%s: %d\n", (_func), (_status)); \ + return -1; \ + } \ + } while (0) + +static int rdpsnd_alsa_set_hw_params(rdpsndAlsaPlugin* alsa) +{ + int status = 0; + snd_pcm_hw_params_t* hw_params = NULL; + snd_pcm_uframes_t buffer_size_max = 0; + status = snd_pcm_hw_params_malloc(&hw_params); + SND_PCM_CHECK("snd_pcm_hw_params_malloc", status); + status = snd_pcm_hw_params_any(alsa->pcm_handle, hw_params); + SND_PCM_CHECK("snd_pcm_hw_params_any", status); + /* Set interleaved read/write access */ + status = + snd_pcm_hw_params_set_access(alsa->pcm_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); + SND_PCM_CHECK("snd_pcm_hw_params_set_access", status); + /* Set sample format */ + status = snd_pcm_hw_params_set_format(alsa->pcm_handle, hw_params, alsa->format); + SND_PCM_CHECK("snd_pcm_hw_params_set_format", status); + /* Set sample rate */ + status = snd_pcm_hw_params_set_rate_near(alsa->pcm_handle, hw_params, &alsa->actual_rate, NULL); + SND_PCM_CHECK("snd_pcm_hw_params_set_rate_near", status); + /* Set number of channels */ + status = snd_pcm_hw_params_set_channels(alsa->pcm_handle, hw_params, alsa->actual_channels); + SND_PCM_CHECK("snd_pcm_hw_params_set_channels", status); + /* Get maximum buffer size */ + status = snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size_max); + SND_PCM_CHECK("snd_pcm_hw_params_get_buffer_size_max", status); + /** + * ALSA Parameters + * + * http://www.alsa-project.org/main/index.php/FramesPeriods + * + * buffer_size = period_size * periods + * period_bytes = period_size * bytes_per_frame + * bytes_per_frame = channels * bytes_per_sample + * + * A frame is equivalent of one sample being played, + * irrespective of the number of channels or the number of bits + * + * A period is the number of frames in between each hardware interrupt. + * + * The buffer size always has to be greater than one period size. + * Commonly this is (2 * period_size), but some hardware can do 8 periods per buffer. + * It is also possible for the buffer size to not be an integer multiple of the period size. + */ + const size_t interrupts_per_sec_near = 50; + const size_t bytes_per_sec = + (1ull * alsa->actual_rate * alsa->aformat.wBitsPerSample / 8 * alsa->actual_channels); + alsa->buffer_size = buffer_size_max; + alsa->period_size = (bytes_per_sec / interrupts_per_sec_near); + + if (alsa->period_size > buffer_size_max) + { + WLog_ERR(TAG, "Warning: requested sound buffer size %lu, got %lu instead\n", + alsa->buffer_size, buffer_size_max); + alsa->period_size = (buffer_size_max / 8); + } + + /* Set buffer size */ + status = + snd_pcm_hw_params_set_buffer_size_near(alsa->pcm_handle, hw_params, &alsa->buffer_size); + SND_PCM_CHECK("snd_pcm_hw_params_set_buffer_size_near", status); + /* Set period size */ + status = snd_pcm_hw_params_set_period_size_near(alsa->pcm_handle, hw_params, &alsa->period_size, + NULL); + SND_PCM_CHECK("snd_pcm_hw_params_set_period_size_near", status); + status = snd_pcm_hw_params(alsa->pcm_handle, hw_params); + SND_PCM_CHECK("snd_pcm_hw_params", status); + snd_pcm_hw_params_free(hw_params); + return 0; +} + +static int rdpsnd_alsa_set_sw_params(rdpsndAlsaPlugin* alsa) +{ + int status = 0; + snd_pcm_sw_params_t* sw_params = NULL; + status = snd_pcm_sw_params_malloc(&sw_params); + SND_PCM_CHECK("snd_pcm_sw_params_malloc", status); + status = snd_pcm_sw_params_current(alsa->pcm_handle, sw_params); + SND_PCM_CHECK("snd_pcm_sw_params_current", status); + status = snd_pcm_sw_params_set_avail_min( + alsa->pcm_handle, sw_params, (1ULL * alsa->aformat.nChannels * alsa->actual_channels)); + SND_PCM_CHECK("snd_pcm_sw_params_set_avail_min", status); + status = snd_pcm_sw_params_set_start_threshold(alsa->pcm_handle, sw_params, + alsa->aformat.nBlockAlign); + SND_PCM_CHECK("snd_pcm_sw_params_set_start_threshold", status); + status = snd_pcm_sw_params(alsa->pcm_handle, sw_params); + SND_PCM_CHECK("snd_pcm_sw_params", status); + snd_pcm_sw_params_free(sw_params); + status = snd_pcm_prepare(alsa->pcm_handle); + SND_PCM_CHECK("snd_pcm_prepare", status); + return 0; +} + +static int rdpsnd_alsa_validate_params(rdpsndAlsaPlugin* alsa) +{ + int status = 0; + snd_pcm_uframes_t buffer_size = 0; + snd_pcm_uframes_t period_size = 0; + status = snd_pcm_get_params(alsa->pcm_handle, &buffer_size, &period_size); + SND_PCM_CHECK("snd_pcm_get_params", status); + return 0; +} + +static int rdpsnd_alsa_set_params(rdpsndAlsaPlugin* alsa) +{ + snd_pcm_drop(alsa->pcm_handle); + + if (rdpsnd_alsa_set_hw_params(alsa) < 0) + return -1; + + if (rdpsnd_alsa_set_sw_params(alsa) < 0) + return -1; + + return rdpsnd_alsa_validate_params(alsa); +} + +static BOOL rdpsnd_alsa_set_format(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 latency) +{ + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + + if (format) + { + alsa->aformat = *format; + alsa->actual_rate = format->nSamplesPerSec; + alsa->actual_channels = format->nChannels; + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + switch (format->wBitsPerSample) + { + case 8: + alsa->format = SND_PCM_FORMAT_S8; + break; + + case 16: + alsa->format = SND_PCM_FORMAT_S16_LE; + break; + + default: + return FALSE; + } + + break; + + default: + return FALSE; + } + } + + alsa->latency = latency; + return (rdpsnd_alsa_set_params(alsa) == 0); +} + +static void rdpsnd_alsa_close_mixer(rdpsndAlsaPlugin* alsa) +{ + if (alsa && alsa->mixer_handle) + { + snd_mixer_close(alsa->mixer_handle); + alsa->mixer_handle = NULL; + } +} + +static BOOL rdpsnd_alsa_open_mixer(rdpsndAlsaPlugin* alsa) +{ + int status = 0; + + if (alsa->mixer_handle) + return TRUE; + + status = snd_mixer_open(&alsa->mixer_handle, 0); + + if (status < 0) + { + WLog_ERR(TAG, "snd_mixer_open failed"); + goto fail; + } + + status = snd_mixer_attach(alsa->mixer_handle, alsa->device_name); + + if (status < 0) + { + WLog_ERR(TAG, "snd_mixer_attach failed"); + goto fail; + } + + status = snd_mixer_selem_register(alsa->mixer_handle, NULL, NULL); + + if (status < 0) + { + WLog_ERR(TAG, "snd_mixer_selem_register failed"); + goto fail; + } + + status = snd_mixer_load(alsa->mixer_handle); + + if (status < 0) + { + WLog_ERR(TAG, "snd_mixer_load failed"); + goto fail; + } + + return TRUE; +fail: + rdpsnd_alsa_close_mixer(alsa); + return FALSE; +} + +static void rdpsnd_alsa_pcm_close(rdpsndAlsaPlugin* alsa) +{ + if (alsa && alsa->pcm_handle) + { + snd_pcm_drain(alsa->pcm_handle); + snd_pcm_close(alsa->pcm_handle); + alsa->pcm_handle = 0; + } +} + +static BOOL rdpsnd_alsa_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, UINT32 latency) +{ + int mode = 0; + int status = 0; + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + + if (alsa->pcm_handle) + return TRUE; + + mode = 0; + /*mode |= SND_PCM_NONBLOCK;*/ + status = snd_pcm_open(&alsa->pcm_handle, alsa->device_name, SND_PCM_STREAM_PLAYBACK, mode); + + if (status < 0) + { + WLog_ERR(TAG, "snd_pcm_open failed"); + return FALSE; + } + + return rdpsnd_alsa_set_format(device, format, latency) && rdpsnd_alsa_open_mixer(alsa); +} + +static void rdpsnd_alsa_close(rdpsndDevicePlugin* device) +{ + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + + if (!alsa) + return; + + rdpsnd_alsa_close_mixer(alsa); +} + +static void rdpsnd_alsa_free(rdpsndDevicePlugin* device) +{ + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + rdpsnd_alsa_pcm_close(alsa); + rdpsnd_alsa_close_mixer(alsa); + free(alsa->device_name); + free(alsa); +} + +static BOOL rdpsnd_alsa_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->cbSize == 0 && format->nSamplesPerSec <= 48000 && + (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) && + (format->nChannels == 1 || format->nChannels == 2)) + { + return TRUE; + } + + break; + default: + break; + } + + return FALSE; +} + +static UINT32 rdpsnd_alsa_get_volume(rdpsndDevicePlugin* device) +{ + long volume_min = 0; + long volume_max = 0; + long volume_left = 0; + long volume_right = 0; + + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + UINT32 dwVolumeLeft = ((50 * 0xFFFF) / 100); /* 50% */ + UINT32 dwVolumeRight = ((50 * 0xFFFF) / 100); /* 50% */ + + if (!rdpsnd_alsa_open_mixer(alsa)) + return 0; + + for (snd_mixer_elem_t* elem = snd_mixer_first_elem(alsa->mixer_handle); elem; + elem = snd_mixer_elem_next(elem)) + { + if (snd_mixer_selem_has_playback_volume(elem)) + { + snd_mixer_selem_get_playback_volume_range(elem, &volume_min, &volume_max); + snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &volume_left); + snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_RIGHT, &volume_right); + dwVolumeLeft = + (UINT16)(((volume_left * 0xFFFF) - volume_min) / (volume_max - volume_min)); + dwVolumeRight = + (UINT16)(((volume_right * 0xFFFF) - volume_min) / (volume_max - volume_min)); + break; + } + } + + return (dwVolumeLeft << 16) | dwVolumeRight; +} + +static BOOL rdpsnd_alsa_set_volume(rdpsndDevicePlugin* device, UINT32 value) +{ + long left = 0; + long right = 0; + long volume_min = 0; + long volume_max = 0; + long volume_left = 0; + long volume_right = 0; + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + + if (!rdpsnd_alsa_open_mixer(alsa)) + return FALSE; + + left = (value & 0xFFFF); + right = ((value >> 16) & 0xFFFF); + + for (snd_mixer_elem_t* elem = snd_mixer_first_elem(alsa->mixer_handle); elem; + elem = snd_mixer_elem_next(elem)) + { + if (snd_mixer_selem_has_playback_volume(elem)) + { + snd_mixer_selem_get_playback_volume_range(elem, &volume_min, &volume_max); + volume_left = volume_min + (left * (volume_max - volume_min)) / 0xFFFF; + volume_right = volume_min + (right * (volume_max - volume_min)) / 0xFFFF; + + if ((snd_mixer_selem_set_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, volume_left) < + 0) || + (snd_mixer_selem_set_playback_volume(elem, SND_MIXER_SCHN_FRONT_RIGHT, + volume_right) < 0)) + { + WLog_ERR(TAG, "error setting the volume\n"); + return FALSE; + } + } + } + + return TRUE; +} + +static UINT rdpsnd_alsa_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) +{ + UINT latency = 0; + size_t offset = 0; + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + WINPR_ASSERT(alsa); + WINPR_ASSERT(data || (size == 0)); + const size_t frame_size = 1ull * alsa->actual_channels * alsa->aformat.wBitsPerSample / 8; + if (frame_size == 0) + return 0; + + while (offset < size) + { + snd_pcm_sframes_t status = + snd_pcm_writei(alsa->pcm_handle, &data[offset], (size - offset) / frame_size); + + if (status < 0) + status = snd_pcm_recover(alsa->pcm_handle, (int)status, 0); + + if (status < 0) + { + WLog_ERR(TAG, "status: %d\n", status); + rdpsnd_alsa_close(device); + rdpsnd_alsa_open(device, NULL, alsa->latency); + break; + } + + offset += WINPR_ASSERTING_INT_CAST(size_t, status) * frame_size; + } + + { + snd_pcm_sframes_t available = 0; + snd_pcm_sframes_t delay = 0; + int rc = snd_pcm_avail_delay(alsa->pcm_handle, &available, &delay); + + if ((rc == 0) && (available == 0)) /* Get [ms] from number of samples */ + latency = (UINT32)MIN(UINT32_MAX, delay * 1000 / alsa->actual_rate); + } + + return latency + alsa->latency; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_alsa_parse_addin_args(rdpsndDevicePlugin* device, const ADDIN_ARGV* args) +{ + int status = 0; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device; + COMMAND_LINE_ARGUMENT_A rdpsnd_alsa_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "device" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_alsa_args, flags, alsa, NULL, + NULL); + + if (status < 0) + { + WLog_ERR(TAG, "CommandLineParseArgumentsA failed!"); + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + arg = rdpsnd_alsa_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + alsa->device_name = _strdup(arg->Value); + + if (!alsa->device_name) + return CHANNEL_RC_NO_MEMORY; + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE alsa_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args = NULL; + rdpsndAlsaPlugin* alsa = NULL; + UINT error = 0; + alsa = (rdpsndAlsaPlugin*)calloc(1, sizeof(rdpsndAlsaPlugin)); + + if (!alsa) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + alsa->device.Open = rdpsnd_alsa_open; + alsa->device.FormatSupported = rdpsnd_alsa_format_supported; + alsa->device.GetVolume = rdpsnd_alsa_get_volume; + alsa->device.SetVolume = rdpsnd_alsa_set_volume; + alsa->device.Play = rdpsnd_alsa_play; + alsa->device.Close = rdpsnd_alsa_close; + alsa->device.Free = rdpsnd_alsa_free; + args = pEntryPoints->args; + + if (args->argc > 1) + { + if ((error = rdpsnd_alsa_parse_addin_args(&alsa->device, args))) + { + WLog_ERR(TAG, "rdpsnd_alsa_parse_addin_args failed with error %" PRIu32 "", error); + goto error_parse_args; + } + } + + if (!alsa->device_name) + { + alsa->device_name = _strdup("default"); + + if (!alsa->device_name) + { + WLog_ERR(TAG, "_strdup failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_strdup; + } + } + + alsa->pcm_handle = 0; + alsa->actual_rate = 22050; + alsa->format = SND_PCM_FORMAT_S16_LE; + alsa->actual_channels = 2; + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)alsa); + return CHANNEL_RC_OK; +error_strdup: + free(alsa->device_name); +error_parse_args: + free(alsa); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/fake/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/fake/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a307854db25f6525b8350e9b0d52a88e998e121 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/fake/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2019 Armin Novak +# Copyright 2019 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "fake" "") + +set(${MODULE_PREFIX}_SRCS rdpsnd_fake.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp) + +include_directories(..) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/fake/rdpsnd_fake.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/fake/rdpsnd_fake.c new file mode 100644 index 0000000000000000000000000000000000000000..9e06f4c112880a383a86b418c58cf62e30d4a6b0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/fake/rdpsnd_fake.c @@ -0,0 +1,147 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2019 Armin Novak + * Copyright 2019 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; +} rdpsndFakePlugin; + +static BOOL rdpsnd_fake_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, UINT32 latency) +{ + return TRUE; +} + +static void rdpsnd_fake_close(rdpsndDevicePlugin* device) +{ +} + +static BOOL rdpsnd_fake_set_volume(rdpsndDevicePlugin* device, UINT32 value) +{ + return TRUE; +} + +static void rdpsnd_fake_free(rdpsndDevicePlugin* device) +{ + rdpsndFakePlugin* fake = (rdpsndFakePlugin*)device; + + if (!fake) + return; + + free(fake); +} + +static BOOL rdpsnd_fake_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format) +{ + return TRUE; +} + +static UINT rdpsnd_fake_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) +{ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_fake_parse_addin_args(rdpsndFakePlugin* fake, const ADDIN_ARGV* args) +{ + int status = 0; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + COMMAND_LINE_ARGUMENT_A rdpsnd_fake_args[] = { { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_fake_args, flags, fake, NULL, + NULL); + + if (status < 0) + return ERROR_INVALID_DATA; + + arg = rdpsnd_fake_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE fake_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args = NULL; + rdpsndFakePlugin* fake = NULL; + UINT ret = CHANNEL_RC_OK; + fake = (rdpsndFakePlugin*)calloc(1, sizeof(rdpsndFakePlugin)); + + if (!fake) + return CHANNEL_RC_NO_MEMORY; + + fake->device.Open = rdpsnd_fake_open; + fake->device.FormatSupported = rdpsnd_fake_format_supported; + fake->device.SetVolume = rdpsnd_fake_set_volume; + fake->device.Play = rdpsnd_fake_play; + fake->device.Close = rdpsnd_fake_close; + fake->device.Free = rdpsnd_fake_free; + args = pEntryPoints->args; + + if (args->argc > 1) + { + ret = rdpsnd_fake_parse_addin_args(fake, args); + + if (ret != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "error parsing arguments"); + goto error; + } + } + + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &fake->device); + return ret; +error: + rdpsnd_fake_free(&fake->device); + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..16491c2322e8df89536000669da9dd37ea9218cb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/CMakeLists.txt @@ -0,0 +1,32 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Laxmikant Rashinkar +# Copyright 2012 Marc-Andre Moreau +# Copyright 2013 Corey Clayton +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "ios" "") + +find_library(CORE_AUDIO CoreAudio) +find_library(AUDIO_TOOL AudioToolbox) +find_library(CORE_FOUNDATION CoreFoundation) + +set(${MODULE_PREFIX}_SRCS rdpsnd_ios.c TPCircularBuffer.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${AUDIO_TOOL} ${CORE_AUDIO} ${CORE_FOUNDATION}) + +include_directories(..) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/TPCircularBuffer.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/TPCircularBuffer.c new file mode 100644 index 0000000000000000000000000000000000000000..b29f61184fe37968f0f93bf8aa42a25cdb01fc8f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/TPCircularBuffer.c @@ -0,0 +1,153 @@ +// +// TPCircularBuffer.c +// Circular/Ring buffer implementation +// +// https://github.com/michaeltyson/TPCircularBuffer +// +// Created by Michael Tyson on 10/12/2011. +// +// Copyright (C) 2012-2013 A Tasty Pixel +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// + +#include + +#include "TPCircularBuffer.h" +#include "rdpsnd_main.h" + +#include +#include + +#define reportResult(result, operation) (_reportResult((result), (operation), __FILE__, __LINE__)) +static inline bool _reportResult(kern_return_t result, const char* operation, const char* file, + int line) +{ + if (result != ERR_SUCCESS) + { + WLog_DBG(TAG, "%s:%d: %s: %s\n", file, line, operation, mach_error_string(result)); + return false; + } + return true; +} + +bool TPCircularBufferInit(TPCircularBuffer* buffer, int length) +{ + + // Keep trying until we get our buffer, needed to handle race conditions + int retries = 3; + while (true) + { + + buffer->length = round_page(length); // We need whole page sizes + + // Temporarily allocate twice the length, so we have the contiguous address space to + // support a second instance of the buffer directly after + vm_address_t bufferAddress; + kern_return_t result = vm_allocate(mach_task_self(), &bufferAddress, buffer->length * 2, + VM_FLAGS_ANYWHERE); // allocate anywhere it'll fit + if (result != ERR_SUCCESS) + { + if (retries-- == 0) + { + reportResult(result, "Buffer allocation"); + return false; + } + // Try again if we fail + continue; + } + + // Now replace the second half of the allocation with a virtual copy of the first half. + // Deallocate the second half... + result = vm_deallocate(mach_task_self(), bufferAddress + buffer->length, buffer->length); + if (result != ERR_SUCCESS) + { + if (retries-- == 0) + { + reportResult(result, "Buffer deallocation"); + return false; + } + // If this fails somehow, deallocate the whole region and try again + vm_deallocate(mach_task_self(), bufferAddress, buffer->length); + continue; + } + + // Re-map the buffer to the address space immediately after the buffer + vm_address_t virtualAddress = bufferAddress + buffer->length; + vm_prot_t cur_prot, max_prot; + result = vm_remap(mach_task_self(), + &virtualAddress, // mirror target + buffer->length, // size of mirror + 0, // auto alignment + 0, // force remapping to virtualAddress + mach_task_self(), // same task + bufferAddress, // mirror source + 0, // MAP READ-WRITE, NOT COPY + &cur_prot, // unused protection struct + &max_prot, // unused protection struct + VM_INHERIT_DEFAULT); + if (result != ERR_SUCCESS) + { + if (retries-- == 0) + { + reportResult(result, "Remap buffer memory"); + return false; + } + // If this remap failed, we hit a race condition, so deallocate and try again + vm_deallocate(mach_task_self(), bufferAddress, buffer->length); + continue; + } + + if (virtualAddress != bufferAddress + buffer->length) + { + // If the memory is not contiguous, clean up both allocated buffers and try again + if (retries-- == 0) + { + WLog_DBG(TAG, "Couldn't map buffer memory to end of buffer"); + return false; + } + + vm_deallocate(mach_task_self(), virtualAddress, buffer->length); + vm_deallocate(mach_task_self(), bufferAddress, buffer->length); + continue; + } + + buffer->buffer = (void*)bufferAddress; + buffer->fillCount = 0; + buffer->head = buffer->tail = 0; + + return true; + } + return false; +} + +void TPCircularBufferCleanup(TPCircularBuffer* buffer) +{ + vm_deallocate(mach_task_self(), (vm_address_t)buffer->buffer, buffer->length * 2); + memset(buffer, 0, sizeof(TPCircularBuffer)); +} + +void TPCircularBufferClear(TPCircularBuffer* buffer) +{ + int32_t fillCount; + if (TPCircularBufferTail(buffer, &fillCount)) + { + TPCircularBufferConsume(buffer, fillCount); + } +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/TPCircularBuffer.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/TPCircularBuffer.h new file mode 100644 index 0000000000000000000000000000000000000000..97e10954132eb5089c03572e4d60017eb56cc18b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/TPCircularBuffer.h @@ -0,0 +1,217 @@ +// +// TPCircularBuffer.h +// Circular/Ring buffer implementation +// +// https://github.com/michaeltyson/TPCircularBuffer +// +// Created by Michael Tyson on 10/12/2011. +// +// +// This implementation makes use of a virtual memory mapping technique that inserts a virtual copy +// of the buffer memory directly after the buffer's end, negating the need for any buffer +// wrap-around logic. Clients can simply use the returned memory address as if it were contiguous +// space. +// +// The implementation is thread-safe in the case of a single producer and single consumer. +// +// Virtual memory technique originally proposed by Philip Howard (http://vrb.slashusr.org/), and +// adapted to Darwin by Kurt Revis (http://www.snoize.com, +// http://www.snoize.com/Code/PlayBufferedSoundFile.tar.gz) +// +// +// Copyright (C) 2012-2013 A Tasty Pixel +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// + +#ifndef TPCircularBuffer_h +#define TPCircularBuffer_h + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + void* buffer; + int32_t length; + int32_t tail; + int32_t head; + volatile int32_t fillCount; + } TPCircularBuffer; + + /*! + * Initialise buffer + * + * Note that the length is advisory only: Because of the way the + * memory mirroring technique works, the true buffer length will + * be multiples of the device page size (e.g. 4096 bytes) + * + * @param buffer Circular buffer + * @param length Length of buffer + */ + bool TPCircularBufferInit(TPCircularBuffer* buffer, int32_t length); + + /*! + * Cleanup buffer + * + * Releases buffer resources. + */ + void TPCircularBufferCleanup(TPCircularBuffer* buffer); + + /*! + * Clear buffer + * + * Resets buffer to original, empty state. + * + * This is safe for use by consumer while producer is accessing + * buffer. + */ + void TPCircularBufferClear(TPCircularBuffer* buffer); + + // Reading (consuming) + + /*! + * Access end of buffer + * + * This gives you a pointer to the end of the buffer, ready + * for reading, and the number of available bytes to read. + * + * @param buffer Circular buffer + * @param availableBytes On output, the number of bytes ready for reading + * @return Pointer to the first bytes ready for reading, or NULL if buffer is empty + */ + static __inline__ __attribute__((always_inline)) void* + TPCircularBufferTail(TPCircularBuffer* buffer, int32_t* availableBytes) + { + *availableBytes = buffer->fillCount; + if (*availableBytes == 0) + return NULL; + return (void*)((char*)buffer->buffer + buffer->tail); + } + + /*! + * Consume bytes in buffer + * + * This frees up the just-read bytes, ready for writing again. + * + * @param buffer Circular buffer + * @param amount Number of bytes to consume + */ + static __inline__ __attribute__((always_inline)) void + TPCircularBufferConsume(TPCircularBuffer* buffer, int32_t amount) + { + buffer->tail = (buffer->tail + amount) % buffer->length; + OSAtomicAdd32Barrier(-amount, &buffer->fillCount); + WINPR_ASSERT(buffer->fillCount >= 0); + } + + /*! + * Version of TPCircularBufferConsume without the memory barrier, for more optimal use in + * single-threaded contexts + */ + static __inline__ __attribute__((always_inline)) void + TPCircularBufferConsumeNoBarrier(TPCircularBuffer* buffer, int32_t amount) + { + buffer->tail = (buffer->tail + amount) % buffer->length; + buffer->fillCount -= amount; + WINPR_ASSERT(buffer->fillCount >= 0); + } + + /*! + * Access front of buffer + * + * This gives you a pointer to the front of the buffer, ready + * for writing, and the number of available bytes to write. + * + * @param buffer Circular buffer + * @param availableBytes On output, the number of bytes ready for writing + * @return Pointer to the first bytes ready for writing, or NULL if buffer is full + */ + static __inline__ __attribute__((always_inline)) void* + TPCircularBufferHead(TPCircularBuffer* buffer, int32_t* availableBytes) + { + *availableBytes = (buffer->length - buffer->fillCount); + if (*availableBytes == 0) + return NULL; + return (void*)((char*)buffer->buffer + buffer->head); + } + + // Writing (producing) + + /*! + * Produce bytes in buffer + * + * This marks the given section of the buffer ready for reading. + * + * @param buffer Circular buffer + * @param amount Number of bytes to produce + */ + static __inline__ __attribute__((always_inline)) void + TPCircularBufferProduce(TPCircularBuffer* buffer, int amount) + { + buffer->head = (buffer->head + amount) % buffer->length; + OSAtomicAdd32Barrier(amount, &buffer->fillCount); + WINPR_ASSERT(buffer->fillCount <= buffer->length); + } + + /*! + * Version of TPCircularBufferProduce without the memory barrier, for more optimal use in + * single-threaded contexts + */ + static __inline__ __attribute__((always_inline)) void + TPCircularBufferProduceNoBarrier(TPCircularBuffer* buffer, int amount) + { + buffer->head = (buffer->head + amount) % buffer->length; + buffer->fillCount += amount; + WINPR_ASSERT(buffer->fillCount <= buffer->length); + } + + /*! + * Helper routine to copy bytes to buffer + * + * This copies the given bytes to the buffer, and marks them ready for writing. + * + * @param buffer Circular buffer + * @param src Source buffer + * @param len Number of bytes in source buffer + * @return true if bytes copied, false if there was insufficient space + */ + static __inline__ __attribute__((always_inline)) bool + TPCircularBufferProduceBytes(TPCircularBuffer* buffer, const void* src, int32_t len) + { + int32_t space; + void* ptr = TPCircularBufferHead(buffer, &space); + if (space < len) + return false; + memcpy(ptr, src, len); + TPCircularBufferProduce(buffer, len); + return true; + } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/rdpsnd_ios.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/rdpsnd_ios.c new file mode 100644 index 0000000000000000000000000000000000000000..c3e17ece616f87d87b99ffb936cd2e1b00fc49c6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/ios/rdpsnd_ios.c @@ -0,0 +1,282 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2013 Dell Software + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include + +#import + +#include "rdpsnd_main.h" +#include "TPCircularBuffer.h" + +#define INPUT_BUFFER_SIZE 32768 +#define CIRCULAR_BUFFER_SIZE (INPUT_BUFFER_SIZE * 4) + +typedef struct +{ + rdpsndDevicePlugin device; + AudioComponentInstance audio_unit; + TPCircularBuffer buffer; + BOOL is_opened; + BOOL is_playing; +} rdpsndIOSPlugin; + +#define THIS(__ptr) ((rdpsndIOSPlugin*)__ptr) + +static OSStatus rdpsnd_ios_render_cb(void* inRefCon, + AudioUnitRenderActionFlags __unused* ioActionFlags, + const AudioTimeStamp __unused* inTimeStamp, UInt32 inBusNumber, + UInt32 __unused inNumberFrames, AudioBufferList* ioData) +{ + if (inBusNumber != 0) + { + return noErr; + } + + rdpsndIOSPlugin* p = THIS(inRefCon); + + for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) + { + AudioBuffer* target_buffer = &ioData->mBuffers[i]; + int32_t available_bytes = 0; + const void* buffer = TPCircularBufferTail(&p->buffer, &available_bytes); + + if (buffer != NULL && available_bytes > 0) + { + const int bytes_to_copy = MIN((int32_t)target_buffer->mDataByteSize, available_bytes); + memcpy(target_buffer->mData, buffer, bytes_to_copy); + target_buffer->mDataByteSize = bytes_to_copy; + TPCircularBufferConsume(&p->buffer, bytes_to_copy); + } + else + { + target_buffer->mDataByteSize = 0; + AudioOutputUnitStop(p->audio_unit); + p->is_playing = 0; + } + } + + return noErr; +} + +static BOOL rdpsnd_ios_format_supported(rdpsndDevicePlugin* __unused device, + const AUDIO_FORMAT* format) +{ + if (format->wFormatTag == WAVE_FORMAT_PCM) + { + return 1; + } + + return 0; +} + +static BOOL rdpsnd_ios_set_volume(rdpsndDevicePlugin* __unused device, UINT32 __unused value) +{ + return TRUE; +} + +static void rdpsnd_ios_start(rdpsndDevicePlugin* device) +{ + rdpsndIOSPlugin* p = THIS(device); + + /* If this device is not playing... */ + if (!p->is_playing) + { + /* Start the device. */ + int32_t available_bytes = 0; + TPCircularBufferTail(&p->buffer, &available_bytes); + + if (available_bytes > 0) + { + p->is_playing = 1; + AudioOutputUnitStart(p->audio_unit); + } + } +} + +static void rdpsnd_ios_stop(rdpsndDevicePlugin* __unused device) +{ + rdpsndIOSPlugin* p = THIS(device); + + /* If the device is playing... */ + if (p->is_playing) + { + /* Stop the device. */ + AudioOutputUnitStop(p->audio_unit); + p->is_playing = 0; + /* Free all buffers. */ + TPCircularBufferClear(&p->buffer); + } +} + +static UINT rdpsnd_ios_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) +{ + rdpsndIOSPlugin* p = THIS(device); + const BOOL ok = TPCircularBufferProduceBytes(&p->buffer, data, size); + + if (!ok) + return 0; + + rdpsnd_ios_start(device); + return 10; /* TODO: Get real latencry in [ms] */ +} + +static BOOL rdpsnd_ios_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 __unused latency) +{ + rdpsndIOSPlugin* p = THIS(device); + + if (p->is_opened) + return TRUE; + + /* Find the output audio unit. */ + AudioComponentDescription desc; + desc.componentManufacturer = kAudioUnitManufacturer_Apple; + desc.componentType = kAudioUnitType_Output; + desc.componentSubType = kAudioUnitSubType_RemoteIO; + desc.componentFlags = 0; + desc.componentFlagsMask = 0; + AudioComponent audioComponent = AudioComponentFindNext(NULL, &desc); + + if (audioComponent == NULL) + return FALSE; + + /* Open the audio unit. */ + OSStatus status = AudioComponentInstanceNew(audioComponent, &p->audio_unit); + + if (status != 0) + return FALSE; + + /* Set the format for the AudioUnit. */ + AudioStreamBasicDescription audioFormat = { 0 }; + audioFormat.mSampleRate = format->nSamplesPerSec; + audioFormat.mFormatID = kAudioFormatLinearPCM; + audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; + audioFormat.mFramesPerPacket = 1; /* imminent property of the Linear PCM */ + audioFormat.mChannelsPerFrame = format->nChannels; + audioFormat.mBitsPerChannel = format->wBitsPerSample; + audioFormat.mBytesPerFrame = (format->wBitsPerSample * format->nChannels) / 8; + audioFormat.mBytesPerPacket = audioFormat.mBytesPerFrame * audioFormat.mFramesPerPacket; + status = AudioUnitSetProperty(p->audio_unit, kAudioUnitProperty_StreamFormat, + kAudioUnitScope_Input, 0, &audioFormat, sizeof(audioFormat)); + + if (status != 0) + { + AudioComponentInstanceDispose(p->audio_unit); + p->audio_unit = NULL; + return FALSE; + } + + /* Set up the AudioUnit callback. */ + AURenderCallbackStruct callbackStruct = { 0 }; + callbackStruct.inputProc = rdpsnd_ios_render_cb; + callbackStruct.inputProcRefCon = p; + status = + AudioUnitSetProperty(p->audio_unit, kAudioUnitProperty_SetRenderCallback, + kAudioUnitScope_Input, 0, &callbackStruct, sizeof(callbackStruct)); + + if (status != 0) + { + AudioComponentInstanceDispose(p->audio_unit); + p->audio_unit = NULL; + return FALSE; + } + + /* Initialize the AudioUnit. */ + status = AudioUnitInitialize(p->audio_unit); + + if (status != 0) + { + AudioComponentInstanceDispose(p->audio_unit); + p->audio_unit = NULL; + return FALSE; + } + + /* Allocate the circular buffer. */ + const BOOL ok = TPCircularBufferInit(&p->buffer, CIRCULAR_BUFFER_SIZE); + + if (!ok) + { + AudioUnitUninitialize(p->audio_unit); + AudioComponentInstanceDispose(p->audio_unit); + p->audio_unit = NULL; + return FALSE; + } + + p->is_opened = 1; + return TRUE; +} + +static void rdpsnd_ios_close(rdpsndDevicePlugin* device) +{ + rdpsndIOSPlugin* p = THIS(device); + /* Make sure the device is stopped. */ + rdpsnd_ios_stop(device); + + /* If the device is open... */ + if (p->is_opened) + { + /* Close the device. */ + AudioUnitUninitialize(p->audio_unit); + AudioComponentInstanceDispose(p->audio_unit); + p->audio_unit = NULL; + p->is_opened = 0; + /* Destroy the circular buffer. */ + TPCircularBufferCleanup(&p->buffer); + } +} + +static void rdpsnd_ios_free(rdpsndDevicePlugin* device) +{ + rdpsndIOSPlugin* p = THIS(device); + /* Ensure the device is closed. */ + rdpsnd_ios_close(device); + /* Free memory associated with the device. */ + free(p); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE ios_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + rdpsndIOSPlugin* p = (rdpsndIOSPlugin*)calloc(1, sizeof(rdpsndIOSPlugin)); + + if (!p) + return CHANNEL_RC_NO_MEMORY; + + p->device.Open = rdpsnd_ios_open; + p->device.FormatSupported = rdpsnd_ios_format_supported; + p->device.SetVolume = rdpsnd_ios_set_volume; + p->device.Play = rdpsnd_ios_play; + p->device.Start = rdpsnd_ios_start; + p->device.Close = rdpsnd_ios_close; + p->device.Free = rdpsnd_ios_free; + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)p); + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/mac/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/mac/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..57c15589b007227b5ebfc814eccbf58f2ca28c5b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/mac/CMakeLists.txt @@ -0,0 +1,43 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Laxmikant Rashinkar +# Copyright 2012 Marc-Andre Moreau +# Copyright 2013 Corey Clayton +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "mac" "") + +find_library(COCOA_LIBRARY Cocoa REQUIRED) +find_library(CORE_FOUNDATION CoreFoundation) +find_library(CORE_AUDIO CoreAudio REQUIRED) +find_library(AUDIO_TOOL AudioToolbox REQUIRED) +find_library(AV_FOUNDATION AVFoundation REQUIRED) + +set(${MODULE_PREFIX}_SRCS rdpsnd_mac.m) + +set(${MODULE_PREFIX}_LIBS + winpr + freerdp + ${AUDIO_TOOL} + ${AV_FOUNDATION} + ${CORE_AUDIO} + ${COCOA_LIBRARY} + ${CORE_FOUNDATION} +) + +include_directories(..) +include_directories(SYSTEM ${MACAUDIO_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/mac/rdpsnd_mac.m b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/mac/rdpsnd_mac.m new file mode 100644 index 0000000000000000000000000000000000000000..89e02c2d548d36021711d4ee6c54a0374a4d9eef --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/mac/rdpsnd_mac.m @@ -0,0 +1,402 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2012 Laxmikant Rashinkar + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Inuvika Inc. + * Copyright 2016 David PHAM-VAN + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; + + BOOL isOpen; + BOOL isPlaying; + + UINT32 latency; + AUDIO_FORMAT format; + + AVAudioEngine *engine; + AVAudioPlayerNode *player; + UINT64 diff; +} rdpsndMacPlugin; + +static BOOL rdpsnd_mac_set_format(rdpsndDevicePlugin *device, const AUDIO_FORMAT *format, + UINT32 latency) +{ + rdpsndMacPlugin *mac = (rdpsndMacPlugin *)device; + if (!mac || !format) + return FALSE; + + mac->latency = latency; + mac->format = *format; + + audio_format_print(WLog_Get(TAG), WLOG_DEBUG, format); + return TRUE; +} + +static char *FormatError(OSStatus st) +{ + switch (st) + { + case kAudioFileUnspecifiedError: + return "kAudioFileUnspecifiedError"; + + case kAudioFileUnsupportedFileTypeError: + return "kAudioFileUnsupportedFileTypeError"; + + case kAudioFileUnsupportedDataFormatError: + return "kAudioFileUnsupportedDataFormatError"; + + case kAudioFileUnsupportedPropertyError: + return "kAudioFileUnsupportedPropertyError"; + + case kAudioFileBadPropertySizeError: + return "kAudioFileBadPropertySizeError"; + + case kAudioFilePermissionsError: + return "kAudioFilePermissionsError"; + + case kAudioFileNotOptimizedError: + return "kAudioFileNotOptimizedError"; + + case kAudioFileInvalidChunkError: + return "kAudioFileInvalidChunkError"; + + case kAudioFileDoesNotAllow64BitDataSizeError: + return "kAudioFileDoesNotAllow64BitDataSizeError"; + + case kAudioFileInvalidPacketOffsetError: + return "kAudioFileInvalidPacketOffsetError"; + + case kAudioFileInvalidFileError: + return "kAudioFileInvalidFileError"; + + case kAudioFileOperationNotSupportedError: + return "kAudioFileOperationNotSupportedError"; + + case kAudioFileNotOpenError: + return "kAudioFileNotOpenError"; + + case kAudioFileEndOfFileError: + return "kAudioFileEndOfFileError"; + + case kAudioFilePositionError: + return "kAudioFilePositionError"; + + case kAudioFileFileNotFoundError: + return "kAudioFileFileNotFoundError"; + + default: + return "unknown error"; + } +} + +static void rdpsnd_mac_release(rdpsndMacPlugin *mac) +{ + if (mac->player) + [mac->player release]; + mac->player = NULL; + + if (mac->engine) + [mac->engine release]; + mac->engine = NULL; +} + +static BOOL rdpsnd_mac_open(rdpsndDevicePlugin *device, const AUDIO_FORMAT *format, UINT32 latency) +{ + @autoreleasepool + { + AudioDeviceID outputDeviceID; + UInt32 propertySize; + OSStatus err; + NSError *error; + rdpsndMacPlugin *mac = (rdpsndMacPlugin *)device; + AudioObjectPropertyAddress propertyAddress = { + kAudioHardwarePropertyDefaultOutputDevice, + kAudioObjectPropertyScopeGlobal, +#if defined(MAC_OS_VERSION_12_0) + kAudioObjectPropertyElementMain +#else + kAudioObjectPropertyElementMaster +#endif + }; + + if (mac->isOpen) + return TRUE; + + if (!rdpsnd_mac_set_format(device, format, latency)) + return FALSE; + + propertySize = sizeof(outputDeviceID); + err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, + &propertySize, &outputDeviceID); + if (err) + { + WLog_ERR(TAG, "AudioHardwareGetProperty: %s", FormatError(err)); + return FALSE; + } + + mac->engine = [[AVAudioEngine alloc] init]; + if (!mac->engine) + return FALSE; + + err = AudioUnitSetProperty(mac->engine.outputNode.audioUnit, + kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, + 0, &outputDeviceID, sizeof(outputDeviceID)); + if (err) + { + rdpsnd_mac_release(mac); + WLog_ERR(TAG, "AudioUnitSetProperty: %s", FormatError(err)); + return FALSE; + } + + mac->player = [[AVAudioPlayerNode alloc] init]; + if (!mac->player) + { + rdpsnd_mac_release(mac); + WLog_ERR(TAG, "AVAudioPlayerNode::init() failed"); + return FALSE; + } + + [mac->engine attachNode:mac->player]; + + [mac->engine connect:mac->player to:mac->engine.mainMixerNode format:nil]; + + [mac->engine prepare]; + + if (![mac->engine startAndReturnError:&error]) + { + device->Close(device); + WLog_ERR(TAG, "Failed to start audio player %s", + [error.localizedDescription UTF8String]); + return FALSE; + } + + mac->isOpen = TRUE; + return TRUE; + } +} + +static void rdpsnd_mac_close(rdpsndDevicePlugin *device) +{ + @autoreleasepool + { + rdpsndMacPlugin *mac = (rdpsndMacPlugin *)device; + + if (mac->isPlaying) + { + [mac->player stop]; + mac->isPlaying = FALSE; + } + + if (mac->isOpen) + { + [mac->engine stop]; + mac->isOpen = FALSE; + } + + rdpsnd_mac_release(mac); + } +} + +static void rdpsnd_mac_free(rdpsndDevicePlugin *device) +{ + rdpsndMacPlugin *mac = (rdpsndMacPlugin *)device; + device->Close(device); + free(mac); +} + +static BOOL rdpsnd_mac_format_supported(rdpsndDevicePlugin *device, const AUDIO_FORMAT *format) +{ + WINPR_UNUSED(device); + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->wBitsPerSample != 16) + return FALSE; + + if (format->nChannels != 2) + return FALSE; + return TRUE; + + default: + return FALSE; + } +} + +static BOOL rdpsnd_mac_set_volume(rdpsndDevicePlugin *device, UINT32 value) +{ + @autoreleasepool + { + Float32 fVolume; + UINT16 volumeLeft; + UINT16 volumeRight; + rdpsndMacPlugin *mac = (rdpsndMacPlugin *)device; + + if (!mac->player) + return FALSE; + + volumeLeft = (value & 0xFFFF); + volumeRight = ((value >> 16) & 0xFFFF); + fVolume = ((float)volumeLeft) / 65535.0f; + + mac->player.volume = fVolume; + + return TRUE; + } +} + +static void rdpsnd_mac_start(rdpsndDevicePlugin *device) +{ + @autoreleasepool + { + rdpsndMacPlugin *mac = (rdpsndMacPlugin *)device; + + if (!mac->isPlaying) + { + if (!mac->engine.isRunning) + { + NSError *error; + + if (![mac->engine startAndReturnError:&error]) + { + device->Close(device); + WLog_ERR(TAG, "Failed to start audio player %s", + [error.localizedDescription UTF8String]); + return; + } + } + + [mac->player play]; + + mac->isPlaying = TRUE; + mac->diff = 100; /* Initial latency, corrected after first sample is played. */ + } + } +} + +static UINT rdpsnd_mac_play(rdpsndDevicePlugin *device, const BYTE *data, size_t size) +{ + @autoreleasepool + { + rdpsndMacPlugin *mac = (rdpsndMacPlugin *)device; + AVAudioPCMBuffer *buffer; + AVAudioFormat *format; + float *const *db; + size_t step; + AVAudioFrameCount count; + UINT64 start = GetTickCount64(); + + if (!mac->isOpen) + return 0; + + step = 2 * mac->format.nChannels; + + count = size / step; + format = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32 + sampleRate:mac->format.nSamplesPerSec + channels:mac->format.nChannels + interleaved:NO]; + + if (!format) + { + WLog_WARN(TAG, "AVAudioFormat::init() failed"); + return 0; + } + + buffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:format frameCapacity:count]; + [format release]; + + if (!buffer) + { + WLog_WARN(TAG, "AVAudioPCMBuffer::init() failed"); + return 0; + } + + buffer.frameLength = buffer.frameCapacity; + db = buffer.floatChannelData; + + for (size_t pos = 0; pos < count; pos++) + { + const BYTE *d = &data[pos * step]; + for (size_t x = 0; x < mac->format.nChannels; x++) + { + const float val = (int16_t)((uint16_t)d[0] | ((uint16_t)d[1] << 8)) / 32768.0f; + db[x][pos] = val; + d += sizeof(int16_t); + } + } + + rdpsnd_mac_start(device); + + [mac->player scheduleBuffer:buffer + completionHandler:^{ + UINT64 stop = GetTickCount64(); + if (start > stop) + mac->diff = 0; + else + mac->diff = stop - start; + }]; + + [buffer release]; + + return mac->diff > UINT_MAX ? UINT_MAX : mac->diff; + } +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE mac_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + rdpsndMacPlugin *mac; + mac = (rdpsndMacPlugin *)calloc(1, sizeof(rdpsndMacPlugin)); + + if (!mac) + return CHANNEL_RC_NO_MEMORY; + + mac->device.Open = rdpsnd_mac_open; + mac->device.FormatSupported = rdpsnd_mac_format_supported; + mac->device.SetVolume = rdpsnd_mac_set_volume; + mac->device.Play = rdpsnd_mac_play; + mac->device.Close = rdpsnd_mac_close; + mac->device.Free = rdpsnd_mac_free; + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin *)mac); + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a93720e5ac8f72cda59f6ab7bfdcf0dae70212b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2013 Armin Novak +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "opensles" "") + +find_package(OpenSLES REQUIRED) + +set(${MODULE_PREFIX}_SRCS opensl_io.c rdpsnd_opensles.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${OpenSLES_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${OpenSLES_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/opensl_io.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/opensl_io.c new file mode 100644 index 0000000000000000000000000000000000000000..70da341b31bcfcff33c7d1265b3f1f515c8abdfd --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/opensl_io.c @@ -0,0 +1,422 @@ +/* +opensl_io.c: +Android OpenSL input/output module +Copyright (c) 2012, Victor Lazzarini +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#include "rdpsnd_main.h" +#include "opensl_io.h" +#define CONV16BIT 32768 +#define CONVMYFLT (1. / 32768.) + +static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context); + +// creates the OpenSL ES audio engine +static SLresult openSLCreateEngine(OPENSL_STREAM* p) +{ + SLresult result; + // create engine + result = slCreateEngine(&(p->engineObject), 0, NULL, 0, NULL, NULL); + DEBUG_SND("engineObject=%p", (void*)p->engineObject); + + if (result != SL_RESULT_SUCCESS) + goto engine_end; + + // realize the engine + result = (*p->engineObject)->Realize(p->engineObject, SL_BOOLEAN_FALSE); + DEBUG_SND("Realize=%" PRIu32 "", result); + + if (result != SL_RESULT_SUCCESS) + goto engine_end; + + // get the engine interface, which is needed in order to create other objects + result = (*p->engineObject)->GetInterface(p->engineObject, SL_IID_ENGINE, &(p->engineEngine)); + DEBUG_SND("engineEngine=%p", (void*)p->engineEngine); + + if (result != SL_RESULT_SUCCESS) + goto engine_end; + +engine_end: + return result; +} + +// opens the OpenSL ES device for output +static SLresult openSLPlayOpen(OPENSL_STREAM* p) +{ + SLresult result; + SLuint32 sr = p->sr; + SLuint32 channels = p->outchannels; + WINPR_ASSERT(p->engineObject); + WINPR_ASSERT(p->engineEngine); + + if (channels) + { + // configure audio source + SLDataLocator_AndroidSimpleBufferQueue loc_bufq = { SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, + p->queuesize }; + + switch (sr) + { + case 8000: + sr = SL_SAMPLINGRATE_8; + break; + + case 11025: + sr = SL_SAMPLINGRATE_11_025; + break; + + case 16000: + sr = SL_SAMPLINGRATE_16; + break; + + case 22050: + sr = SL_SAMPLINGRATE_22_05; + break; + + case 24000: + sr = SL_SAMPLINGRATE_24; + break; + + case 32000: + sr = SL_SAMPLINGRATE_32; + break; + + case 44100: + sr = SL_SAMPLINGRATE_44_1; + break; + + case 48000: + sr = SL_SAMPLINGRATE_48; + break; + + case 64000: + sr = SL_SAMPLINGRATE_64; + break; + + case 88200: + sr = SL_SAMPLINGRATE_88_2; + break; + + case 96000: + sr = SL_SAMPLINGRATE_96; + break; + + case 192000: + sr = SL_SAMPLINGRATE_192; + break; + + default: + return -1; + } + + const SLInterfaceID ids[] = { SL_IID_VOLUME }; + const SLboolean req[] = { SL_BOOLEAN_FALSE }; + result = (*p->engineEngine) + ->CreateOutputMix(p->engineEngine, &(p->outputMixObject), 1, ids, req); + DEBUG_SND("engineEngine=%p", (void*)p->engineEngine); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + // realize the output mix + result = (*p->outputMixObject)->Realize(p->outputMixObject, SL_BOOLEAN_FALSE); + DEBUG_SND("Realize=%" PRIu32 "", result); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + int speakers; + + if (channels > 1) + speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; + else + speakers = SL_SPEAKER_FRONT_CENTER; + + SLDataFormat_PCM format_pcm = { SL_DATAFORMAT_PCM, + channels, + sr, + SL_PCMSAMPLEFORMAT_FIXED_16, + SL_PCMSAMPLEFORMAT_FIXED_16, + speakers, + SL_BYTEORDER_LITTLEENDIAN }; + SLDataSource audioSrc = { &loc_bufq, &format_pcm }; + // configure audio sink + SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, p->outputMixObject }; + SLDataSink audioSnk = { &loc_outmix, NULL }; + // create audio player + const SLInterfaceID ids1[] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_VOLUME }; + const SLboolean req1[] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE }; + result = (*p->engineEngine) + ->CreateAudioPlayer(p->engineEngine, &(p->bqPlayerObject), &audioSrc, + &audioSnk, 2, ids1, req1); + DEBUG_SND("bqPlayerObject=%p", (void*)p->bqPlayerObject); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + // realize the player + result = (*p->bqPlayerObject)->Realize(p->bqPlayerObject, SL_BOOLEAN_FALSE); + DEBUG_SND("Realize=%" PRIu32 "", result); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + // get the play interface + result = + (*p->bqPlayerObject)->GetInterface(p->bqPlayerObject, SL_IID_PLAY, &(p->bqPlayerPlay)); + DEBUG_SND("bqPlayerPlay=%p", (void*)p->bqPlayerPlay); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + // get the volume interface + result = (*p->bqPlayerObject) + ->GetInterface(p->bqPlayerObject, SL_IID_VOLUME, &(p->bqPlayerVolume)); + DEBUG_SND("bqPlayerVolume=%p", (void*)p->bqPlayerVolume); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + // get the buffer queue interface + result = (*p->bqPlayerObject) + ->GetInterface(p->bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, + &(p->bqPlayerBufferQueue)); + DEBUG_SND("bqPlayerBufferQueue=%p", (void*)p->bqPlayerBufferQueue); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + // register callback on the buffer queue + result = (*p->bqPlayerBufferQueue) + ->RegisterCallback(p->bqPlayerBufferQueue, bqPlayerCallback, p); + DEBUG_SND("bqPlayerCallback=%p", (void*)p->bqPlayerCallback); + WINPR_ASSERT(!result); + + if (result != SL_RESULT_SUCCESS) + goto end_openaudio; + + // set the player's state to playing + result = (*p->bqPlayerPlay)->SetPlayState(p->bqPlayerPlay, SL_PLAYSTATE_PLAYING); + DEBUG_SND("SetPlayState=%" PRIu32 "", result); + WINPR_ASSERT(!result); + end_openaudio: + WINPR_ASSERT(!result); + return result; + } + + return SL_RESULT_SUCCESS; +} + +// close the OpenSL IO and destroy the audio engine +static void openSLDestroyEngine(OPENSL_STREAM* p) +{ + // destroy buffer queue audio player object, and invalidate all associated interfaces + if (p->bqPlayerObject != NULL) + { + (*p->bqPlayerObject)->Destroy(p->bqPlayerObject); + p->bqPlayerObject = NULL; + p->bqPlayerVolume = NULL; + p->bqPlayerPlay = NULL; + p->bqPlayerBufferQueue = NULL; + p->bqPlayerEffectSend = NULL; + } + + // destroy output mix object, and invalidate all associated interfaces + if (p->outputMixObject != NULL) + { + (*p->outputMixObject)->Destroy(p->outputMixObject); + p->outputMixObject = NULL; + } + + // destroy engine object, and invalidate all associated interfaces + if (p->engineObject != NULL) + { + (*p->engineObject)->Destroy(p->engineObject); + p->engineObject = NULL; + p->engineEngine = NULL; + } +} + +// open the android audio device for and/or output +OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels, int bufferframes) +{ + OPENSL_STREAM* p; + p = (OPENSL_STREAM*)calloc(1, sizeof(OPENSL_STREAM)); + + if (!p) + return NULL; + + p->queuesize = bufferframes; + p->outchannels = outchannels; + p->sr = sr; + + if (openSLCreateEngine(p) != SL_RESULT_SUCCESS) + { + android_CloseAudioDevice(p); + return NULL; + } + + if (openSLPlayOpen(p) != SL_RESULT_SUCCESS) + { + android_CloseAudioDevice(p); + return NULL; + } + + p->queue = Queue_New(TRUE, -1, -1); + + if (!p->queue) + { + android_CloseAudioDevice(p); + return NULL; + } + + return p; +} + +// close the android audio device +void android_CloseAudioDevice(OPENSL_STREAM* p) +{ + if (p == NULL) + return; + + openSLDestroyEngine(p); + + if (p->queue) + Queue_Free(p->queue); + + free(p); +} + +// this callback handler is called every time a buffer finishes playing +static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context) +{ + OPENSL_STREAM* p = (OPENSL_STREAM*)context; + WINPR_ASSERT(p); + WINPR_ASSERT(p->queue); + void* data = Queue_Dequeue(p->queue); + free(data); +} + +// puts a buffer of size samples to the device +int android_AudioOut(OPENSL_STREAM* p, const short* buffer, int size) +{ + HANDLE ev; + WINPR_ASSERT(p); + WINPR_ASSERT(buffer); + WINPR_ASSERT(size > 0); + + ev = Queue_Event(p->queue); + /* Assure, that the queue is not full. */ + if (p->queuesize <= Queue_Count(p->queue) && WaitForSingleObject(ev, INFINITE) == WAIT_FAILED) + { + DEBUG_SND("WaitForSingleObject failed!"); + return -1; + } + + void* data = calloc(size, sizeof(short)); + + if (!data) + { + DEBUG_SND("unable to allocate a buffer"); + return -1; + } + + memcpy(data, buffer, size * sizeof(short)); + Queue_Enqueue(p->queue, data); + (*p->bqPlayerBufferQueue)->Enqueue(p->bqPlayerBufferQueue, data, sizeof(short) * size); + return size; +} + +int android_GetOutputMute(OPENSL_STREAM* p) +{ + SLboolean mute; + WINPR_ASSERT(p); + WINPR_ASSERT(p->bqPlayerVolume); + SLresult rc = (*p->bqPlayerVolume)->GetMute(p->bqPlayerVolume, &mute); + + if (SL_RESULT_SUCCESS != rc) + return SL_BOOLEAN_FALSE; + + return mute; +} + +BOOL android_SetOutputMute(OPENSL_STREAM* p, BOOL _mute) +{ + SLboolean mute = _mute; + WINPR_ASSERT(p); + WINPR_ASSERT(p->bqPlayerVolume); + SLresult rc = (*p->bqPlayerVolume)->SetMute(p->bqPlayerVolume, mute); + + if (SL_RESULT_SUCCESS != rc) + return FALSE; + + return TRUE; +} + +int android_GetOutputVolume(OPENSL_STREAM* p) +{ + SLmillibel level; + WINPR_ASSERT(p); + WINPR_ASSERT(p->bqPlayerVolume); + SLresult rc = (*p->bqPlayerVolume)->GetVolumeLevel(p->bqPlayerVolume, &level); + + if (SL_RESULT_SUCCESS != rc) + return 0; + + return level; +} + +int android_GetOutputVolumeMax(OPENSL_STREAM* p) +{ + SLmillibel level; + WINPR_ASSERT(p); + WINPR_ASSERT(p->bqPlayerVolume); + SLresult rc = (*p->bqPlayerVolume)->GetMaxVolumeLevel(p->bqPlayerVolume, &level); + + if (SL_RESULT_SUCCESS != rc) + return 0; + + return level; +} + +BOOL android_SetOutputVolume(OPENSL_STREAM* p, int level) +{ + SLresult rc = (*p->bqPlayerVolume)->SetVolumeLevel(p->bqPlayerVolume, level); + + if (SL_RESULT_SUCCESS != rc) + return FALSE; + + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/opensl_io.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/opensl_io.h new file mode 100644 index 0000000000000000000000000000000000000000..f303d2145b523a85e5243dc644a4810318afdd8d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/opensl_io.h @@ -0,0 +1,110 @@ +/* +opensl_io.c: +Android OpenSL input/output module header +Copyright (c) 2012, Victor Lazzarini +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef FREERDP_CHANNEL_RDPSND_CLIENT_OPENSL_IO_H +#define FREERDP_CHANNEL_RDPSND_CLIENT_OPENSL_IO_H + +#include +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + // engine interfaces + SLObjectItf engineObject; + SLEngineItf engineEngine; + + // output mix interfaces + SLObjectItf outputMixObject; + + // buffer queue player interfaces + SLObjectItf bqPlayerObject; + SLPlayItf bqPlayerPlay; + SLVolumeItf bqPlayerVolume; + SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue; + SLEffectSendItf bqPlayerEffectSend; + + unsigned int outchannels; + unsigned int sr; + + unsigned int queuesize; + wQueue* queue; + } OPENSL_STREAM; + + /* + Open the audio device with a given sampling rate (sr), output channels and IO buffer size + in frames. Returns a handle to the OpenSL stream + */ + FREERDP_LOCAL OPENSL_STREAM* android_OpenAudioDevice(int sr, int outchannels, int bufferframes); + /* + Close the audio device + */ + FREERDP_LOCAL void android_CloseAudioDevice(OPENSL_STREAM* p); + /* + Write a buffer to the OpenSL stream *p, of size samples. Returns the number of samples written. + */ + FREERDP_LOCAL int android_AudioOut(OPENSL_STREAM* p, const short* buffer, int size); + /* + * Set the volume input level. + */ + FREERDP_LOCAL void android_SetInputVolume(OPENSL_STREAM* p, int level); + /* + * Get the current output mute setting. + */ + FREERDP_LOCAL int android_GetOutputMute(OPENSL_STREAM* p); + /* + * Change the current output mute setting. + */ + FREERDP_LOCAL BOOL android_SetOutputMute(OPENSL_STREAM* p, BOOL mute); + /* + * Get the current output volume level. + */ + FREERDP_LOCAL int android_GetOutputVolume(OPENSL_STREAM* p); + /* + * Get the maximum output volume level. + */ + FREERDP_LOCAL int android_GetOutputVolumeMax(OPENSL_STREAM* p); + + /* + * Set the volume output level. + */ + FREERDP_LOCAL BOOL android_SetOutputVolume(OPENSL_STREAM* p, int level); +#ifdef __cplusplus +}; +#endif + +#endif /* FREERDP_CHANNEL_RDPSND_CLIENT_OPENSL_IO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/rdpsnd_opensles.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/rdpsnd_opensles.c new file mode 100644 index 0000000000000000000000000000000000000000..1417899efcccbb527427ee7e8469c8eaa785b16f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/opensles/rdpsnd_opensles.c @@ -0,0 +1,378 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2013 Armin Novak + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "opensl_io.h" +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; + + UINT32 latency; + int wformat; + int block_size; + char* device_name; + + OPENSL_STREAM* stream; + + UINT32 volume; + + UINT32 rate; + UINT32 channels; + int format; +} rdpsndopenslesPlugin; + +static int rdpsnd_opensles_volume_to_millibel(unsigned short level, int max) +{ + const int min = SL_MILLIBEL_MIN; + const int step = max - min; + const int rc = (level * step / 0xFFFF) + min; + DEBUG_SND("level=%hu, min=%d, max=%d, step=%d, result=%d", level, min, max, step, rc); + return rc; +} + +static unsigned short rdpsnd_opensles_millibel_to_volume(int millibel, int max) +{ + const int min = SL_MILLIBEL_MIN; + const int range = max - min; + const int rc = ((millibel - min) * 0xFFFF + range / 2 + 1) / range; + DEBUG_SND("millibel=%d, min=%d, max=%d, range=%d, result=%d", millibel, min, max, range, rc); + return rc; +} + +static bool rdpsnd_opensles_check_handle(const rdpsndopenslesPlugin* hdl) +{ + bool rc = true; + + if (!hdl) + rc = false; + else + { + if (!hdl->stream) + rc = false; + } + + return rc; +} + +static BOOL rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device, UINT32 volume); + +static int rdpsnd_opensles_set_params(rdpsndopenslesPlugin* opensles) +{ + DEBUG_SND("opensles=%p", (void*)opensles); + + if (!rdpsnd_opensles_check_handle(opensles)) + return 0; + + if (opensles->stream) + android_CloseAudioDevice(opensles->stream); + + opensles->stream = android_OpenAudioDevice(opensles->rate, opensles->channels, 20); + return 0; +} + +static BOOL rdpsnd_opensles_set_format(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 latency) +{ + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + rdpsnd_opensles_check_handle(opensles); + DEBUG_SND("opensles=%p format=%p, latency=%" PRIu32, (void*)opensles, (void*)format, latency); + + if (format) + { + DEBUG_SND("format=%" PRIu16 ", cbsize=%" PRIu16 ", samples=%" PRIu32 ", bits=%" PRIu16 + ", channels=%" PRIu16 ", align=%" PRIu16 "", + format->wFormatTag, format->cbSize, format->nSamplesPerSec, + format->wBitsPerSample, format->nChannels, format->nBlockAlign); + opensles->rate = format->nSamplesPerSec; + opensles->channels = format->nChannels; + opensles->format = format->wFormatTag; + opensles->wformat = format->wFormatTag; + opensles->block_size = format->nBlockAlign; + } + + opensles->latency = latency; + return (rdpsnd_opensles_set_params(opensles) == 0); +} + +static BOOL rdpsnd_opensles_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 latency) +{ + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + DEBUG_SND("opensles=%p format=%p, latency=%" PRIu32 ", rate=%" PRIu32 "", (void*)opensles, + (void*)format, latency, opensles->rate); + + if (rdpsnd_opensles_check_handle(opensles)) + return TRUE; + + opensles->stream = android_OpenAudioDevice(opensles->rate, opensles->channels, 20); + WINPR_ASSERT(opensles->stream); + + if (!opensles->stream) + WLog_ERR(TAG, "android_OpenAudioDevice failed"); + else + rdpsnd_opensles_set_volume(device, opensles->volume); + + return rdpsnd_opensles_set_format(device, format, latency); +} + +static void rdpsnd_opensles_close(rdpsndDevicePlugin* device) +{ + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + DEBUG_SND("opensles=%p", (void*)opensles); + + if (!rdpsnd_opensles_check_handle(opensles)) + return; + + android_CloseAudioDevice(opensles->stream); + opensles->stream = NULL; +} + +static void rdpsnd_opensles_free(rdpsndDevicePlugin* device) +{ + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + DEBUG_SND("opensles=%p", (void*)opensles); + WINPR_ASSERT(opensles); + WINPR_ASSERT(opensles->device_name); + free(opensles->device_name); + free(opensles); +} + +static BOOL rdpsnd_opensles_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format) +{ + DEBUG_SND("format=%" PRIu16 ", cbsize=%" PRIu16 ", samples=%" PRIu32 ", bits=%" PRIu16 + ", channels=%" PRIu16 ", align=%" PRIu16 "", + format->wFormatTag, format->cbSize, format->nSamplesPerSec, format->wBitsPerSample, + format->nChannels, format->nBlockAlign); + WINPR_ASSERT(device); + WINPR_ASSERT(format); + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->cbSize == 0 && format->nSamplesPerSec <= 48000 && + (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) && + (format->nChannels == 1 || format->nChannels == 2)) + { + return TRUE; + } + + break; + + default: + break; + } + + return FALSE; +} + +static UINT32 rdpsnd_opensles_get_volume(rdpsndDevicePlugin* device) +{ + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + DEBUG_SND("opensles=%p", (void*)opensles); + WINPR_ASSERT(opensles); + + if (opensles->stream) + { + const int max = android_GetOutputVolumeMax(opensles->stream); + const int rc = android_GetOutputVolume(opensles->stream); + + if (android_GetOutputMute(opensles->stream)) + opensles->volume = 0; + else + { + const unsigned short vol = rdpsnd_opensles_millibel_to_volume(rc, max); + opensles->volume = (vol << 16) | (vol & 0xFFFF); + } + } + + return opensles->volume; +} + +static BOOL rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device, UINT32 value) +{ + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + DEBUG_SND("opensles=%p, value=%" PRIu32 "", (void*)opensles, value); + WINPR_ASSERT(opensles); + opensles->volume = value; + + if (opensles->stream) + { + if (0 == opensles->volume) + return android_SetOutputMute(opensles->stream, true); + else + { + const int max = android_GetOutputVolumeMax(opensles->stream); + const int vol = rdpsnd_opensles_volume_to_millibel(value & 0xFFFF, max); + + if (!android_SetOutputMute(opensles->stream, false)) + return FALSE; + + if (!android_SetOutputVolume(opensles->stream, vol)) + return FALSE; + } + } + + return TRUE; +} + +static UINT rdpsnd_opensles_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) +{ + union + { + const BYTE* b; + const short* s; + } src; + int ret; + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + DEBUG_SND("opensles=%p, data=%p, size=%d", (void*)opensles, (void*)data, size); + + if (!rdpsnd_opensles_check_handle(opensles)) + return 0; + + src.b = data; + DEBUG_SND("size=%d, src=%p", size, (void*)src.b); + WINPR_ASSERT(0 == size % 2); + WINPR_ASSERT(size > 0); + WINPR_ASSERT(src.b); + ret = android_AudioOut(opensles->stream, src.s, size / 2); + + if (ret < 0) + WLog_ERR(TAG, "android_AudioOut failed (%d)", ret); + + return 10; /* TODO: Get real latencry in [ms] */ +} + +static void rdpsnd_opensles_start(rdpsndDevicePlugin* device) +{ + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + rdpsnd_opensles_check_handle(opensles); + DEBUG_SND("opensles=%p", (void*)opensles); +} + +static int rdpsnd_opensles_parse_addin_args(rdpsndDevicePlugin* device, ADDIN_ARGV* args) +{ + int status; + DWORD flags; + const COMMAND_LINE_ARGUMENT_A* arg; + rdpsndopenslesPlugin* opensles = (rdpsndopenslesPlugin*)device; + COMMAND_LINE_ARGUMENT_A rdpsnd_opensles_args[] = { + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "device" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } + }; + + WINPR_ASSERT(opensles); + WINPR_ASSERT(args); + DEBUG_SND("opensles=%p, args=%p", (void*)opensles, (void*)args); + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_opensles_args, flags, + opensles, NULL, NULL); + + if (status < 0) + return status; + + arg = rdpsnd_opensles_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + opensles->device_name = _strdup(arg->Value); + + if (!opensles->device_name) + return ERROR_OUTOFMEMORY; + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE opensles_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + ADDIN_ARGV* args; + rdpsndopenslesPlugin* opensles; + UINT error; + DEBUG_SND("pEntryPoints=%p", (void*)pEntryPoints); + opensles = (rdpsndopenslesPlugin*)calloc(1, sizeof(rdpsndopenslesPlugin)); + + if (!opensles) + return CHANNEL_RC_NO_MEMORY; + + opensles->device.Open = rdpsnd_opensles_open; + opensles->device.FormatSupported = rdpsnd_opensles_format_supported; + opensles->device.GetVolume = rdpsnd_opensles_get_volume; + opensles->device.SetVolume = rdpsnd_opensles_set_volume; + opensles->device.Start = rdpsnd_opensles_start; + opensles->device.Play = rdpsnd_opensles_play; + opensles->device.Close = rdpsnd_opensles_close; + opensles->device.Free = rdpsnd_opensles_free; + args = pEntryPoints->args; + rdpsnd_opensles_parse_addin_args((rdpsndDevicePlugin*)opensles, args); + + if (!opensles->device_name) + { + opensles->device_name = _strdup("default"); + + if (!opensles->device_name) + { + error = CHANNEL_RC_NO_MEMORY; + goto outstrdup; + } + } + + opensles->rate = 44100; + opensles->channels = 2; + opensles->format = WAVE_FORMAT_ADPCM; + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)opensles); + DEBUG_SND("success"); + return CHANNEL_RC_OK; +outstrdup: + free(opensles); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/oss/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/oss/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e97d183c19fde0d253b56cacdce6cda8a64a50cf --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/oss/CMakeLists.txt @@ -0,0 +1,31 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Rozhuk Ivan +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "oss" "") + +find_package(OSS REQUIRED) + +set(${MODULE_PREFIX}_SRCS rdpsnd_oss.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${OSS_LIBRARIES}) + +include_directories(..) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(SYSTEM ${OSS_INCLUDE_DIRS}) +cleaning_configure_file(${CMAKE_SOURCE_DIR}/cmake/oss-includes.h.in ${CMAKE_CURRENT_BINARY_DIR}/oss-includes.h @ONLY) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/oss/rdpsnd_oss.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/oss/rdpsnd_oss.c new file mode 100644 index 0000000000000000000000000000000000000000..69f51650d9ef00e70c8e96c45f48d75bb0327ff0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/oss/rdpsnd_oss.c @@ -0,0 +1,460 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright (c) 2015 Rozhuk Ivan + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; + + int pcm_handle; + int mixer_handle; + int dev_unit; + + int supported_formats; + + UINT32 latency; + AUDIO_FORMAT format; +} rdpsndOssPlugin; + +#define OSS_LOG_ERR(_text, _error) \ + do \ + { \ + if ((_error) != 0) \ + { \ + char ebuffer[256] = { 0 }; \ + WLog_ERR(TAG, "%s: %i - %s", (_text), (_error), \ + winpr_strerror((_error), ebuffer, sizeof(ebuffer))); \ + } \ + } while (0) + +static int rdpsnd_oss_get_format(const AUDIO_FORMAT* format) +{ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + switch (format->wBitsPerSample) + { + case 8: + return AFMT_S8; + + case 16: + return AFMT_S16_LE; + default: + break; + } + + break; + default: + break; + } + + return 0; +} + +static BOOL rdpsnd_oss_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format) +{ + int req_fmt = 0; + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + + if (device == NULL || format == NULL) + return FALSE; + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->cbSize != 0 || format->nSamplesPerSec > 48000 || + (format->wBitsPerSample != 8 && format->wBitsPerSample != 16) || + (format->nChannels != 1 && format->nChannels != 2)) + return FALSE; + + break; + + default: + return FALSE; + } + + req_fmt = rdpsnd_oss_get_format(format); + + /* Check really supported formats by dev. */ + if (oss->pcm_handle != -1) + { + if ((req_fmt & oss->supported_formats) == 0) + return FALSE; + } + else + { + if (req_fmt == 0) + return FALSE; + } + + return TRUE; +} + +static BOOL rdpsnd_oss_set_format(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 latency) +{ + int tmp = 0; + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + + if (device == NULL || oss->pcm_handle == -1 || format == NULL) + return FALSE; + + oss->latency = latency; + CopyMemory(&(oss->format), format, sizeof(AUDIO_FORMAT)); + tmp = rdpsnd_oss_get_format(format); + + if (ioctl(oss->pcm_handle, SNDCTL_DSP_SETFMT, &tmp) == -1) + { + OSS_LOG_ERR("SNDCTL_DSP_SETFMT failed", errno); + return FALSE; + } + + tmp = format->nChannels; + + if (ioctl(oss->pcm_handle, SNDCTL_DSP_CHANNELS, &tmp) == -1) + { + OSS_LOG_ERR("SNDCTL_DSP_CHANNELS failed", errno); + return FALSE; + } + + tmp = (int)format->nSamplesPerSec; + + if (ioctl(oss->pcm_handle, SNDCTL_DSP_SPEED, &tmp) == -1) + { + OSS_LOG_ERR("SNDCTL_DSP_SPEED failed", errno); + return FALSE; + } + + tmp = format->nBlockAlign; + + if (ioctl(oss->pcm_handle, SNDCTL_DSP_SETFRAGMENT, &tmp) == -1) + { + OSS_LOG_ERR("SNDCTL_DSP_SETFRAGMENT failed", errno); + return FALSE; + } + + return TRUE; +} + +static void rdpsnd_oss_open_mixer(rdpsndOssPlugin* oss) +{ + int devmask = 0; + char mixer_name[PATH_MAX] = "/dev/mixer"; + + if (oss->mixer_handle != -1) + return; + + if (oss->dev_unit != -1) + (void)sprintf_s(mixer_name, PATH_MAX - 1, "/dev/mixer%i", oss->dev_unit); + + if ((oss->mixer_handle = open(mixer_name, O_RDWR)) < 0) + { + OSS_LOG_ERR("mixer open failed", errno); + oss->mixer_handle = -1; + return; + } + + if (ioctl(oss->mixer_handle, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) + { + OSS_LOG_ERR("SOUND_MIXER_READ_DEVMASK failed", errno); + close(oss->mixer_handle); + oss->mixer_handle = -1; + return; + } +} + +static BOOL rdpsnd_oss_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, UINT32 latency) +{ + char dev_name[PATH_MAX] = "/dev/dsp"; + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + + if (device == NULL || oss->pcm_handle != -1) + return TRUE; + + if (oss->dev_unit != -1) + (void)sprintf_s(dev_name, PATH_MAX - 1, "/dev/dsp%i", oss->dev_unit); + + WLog_INFO(TAG, "open: %s", dev_name); + + if ((oss->pcm_handle = open(dev_name, O_WRONLY)) < 0) + { + OSS_LOG_ERR("sound dev open failed", errno); + oss->pcm_handle = -1; + return FALSE; + } + +#if 0 /* FreeBSD OSS implementation at this moment (2015.03) does not set PCM_CAP_OUTPUT flag. */ + int mask = 0; + + if (ioctl(oss->pcm_handle, SNDCTL_DSP_GETCAPS, &mask) == -1) + { + OSS_LOG_ERR("SNDCTL_DSP_GETCAPS failed, try ignored", errno); + } + else if ((mask & PCM_CAP_OUTPUT) == 0) + { + OSS_LOG_ERR("Device does not supports playback", EOPNOTSUPP); + close(oss->pcm_handle); + oss->pcm_handle = -1; + return; + } + +#endif + + if (ioctl(oss->pcm_handle, SNDCTL_DSP_GETFMTS, &oss->supported_formats) == -1) + { + OSS_LOG_ERR("SNDCTL_DSP_GETFMTS failed", errno); + close(oss->pcm_handle); + oss->pcm_handle = -1; + return FALSE; + } + + rdpsnd_oss_set_format(device, format, latency); + rdpsnd_oss_open_mixer(oss); + return TRUE; +} + +static void rdpsnd_oss_close(rdpsndDevicePlugin* device) +{ + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + + if (device == NULL) + return; + + if (oss->pcm_handle != -1) + { + WLog_INFO(TAG, "close: dsp"); + close(oss->pcm_handle); + oss->pcm_handle = -1; + } + + if (oss->mixer_handle != -1) + { + WLog_INFO(TAG, "close: mixer"); + close(oss->mixer_handle); + oss->mixer_handle = -1; + } +} + +static void rdpsnd_oss_free(rdpsndDevicePlugin* device) +{ + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + + if (device == NULL) + return; + + rdpsnd_oss_close(device); + free(oss); +} + +static UINT32 rdpsnd_oss_get_volume(rdpsndDevicePlugin* device) +{ + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + WINPR_ASSERT(oss); + int vol = 0; + + /* On error return 50% volume. */ + UINT32 dwVolumeLeft = ((50 * 0xFFFF) / 100); /* 50% */ + UINT32 dwVolumeRight = ((50 * 0xFFFF) / 100); /* 50% */ + UINT32 dwVolume = ((dwVolumeLeft << 16) | dwVolumeRight); + + if (device == NULL || oss->mixer_handle == -1) + return dwVolume; + + if (ioctl(oss->mixer_handle, MIXER_READ(SOUND_MIXER_VOLUME), &vol) == -1) + { + OSS_LOG_ERR("MIXER_READ", errno); + return dwVolume; + } + + dwVolumeLeft = (((vol & 0x7f) * 0xFFFF) / 100); + dwVolumeRight = ((((vol >> 8) & 0x7f) * 0xFFFF) / 100); + dwVolume = ((dwVolumeLeft << 16) | dwVolumeRight); + return dwVolume; +} + +static BOOL rdpsnd_oss_set_volume(rdpsndDevicePlugin* device, UINT32 value) +{ + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + WINPR_ASSERT(oss); + + if (device == NULL || oss->mixer_handle == -1) + return FALSE; + + unsigned left = (((value & 0xFFFF) * 100) / 0xFFFF); + unsigned right = ((((value >> 16) & 0xFFFF) * 100) / 0xFFFF); + + left |= (right << 8); + + if (ioctl(oss->mixer_handle, MIXER_WRITE(SOUND_MIXER_VOLUME), &left) == -1) + { + OSS_LOG_ERR("WRITE_MIXER", errno); + return FALSE; + } + + return TRUE; +} + +static UINT rdpsnd_oss_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) +{ + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + + if (device == NULL || oss->mixer_handle == -1) + return 0; + + while (size > 0) + { + ssize_t status = write(oss->pcm_handle, data, size); + + if (status < 0) + { + OSS_LOG_ERR("write fail", errno); + rdpsnd_oss_close(device); + rdpsnd_oss_open(device, NULL, oss->latency); + break; + } + + data += status; + + if ((size_t)status <= size) + size -= (size_t)status; + else + size = 0; + } + + return 10; /* TODO: Get real latency in [ms] */ +} + +static int rdpsnd_oss_parse_addin_args(rdpsndDevicePlugin* device, const ADDIN_ARGV* args) +{ + int status = 0; + char* str_num = NULL; + char* eptr = NULL; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)device; + COMMAND_LINE_ARGUMENT_A rdpsnd_oss_args[] = { { "dev", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "device" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = + CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_oss_args, flags, oss, NULL, NULL); + + if (status < 0) + return status; + + arg = rdpsnd_oss_args; + errno = 0; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + str_num = _strdup(arg->Value); + + if (!str_num) + return ERROR_OUTOFMEMORY; + + { + long val = strtol(str_num, &eptr, 10); + + if ((errno != 0) || (val < INT32_MIN) || (val > INT32_MAX)) + { + free(str_num); + return CHANNEL_RC_NULL_DATA; + } + + oss->dev_unit = (int)val; + } + + if (oss->dev_unit < 0 || *eptr != '\0') + oss->dev_unit = -1; + + free(str_num); + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE oss_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args = NULL; + rdpsndOssPlugin* oss = (rdpsndOssPlugin*)calloc(1, sizeof(rdpsndOssPlugin)); + + if (!oss) + return CHANNEL_RC_NO_MEMORY; + + oss->device.Open = rdpsnd_oss_open; + oss->device.FormatSupported = rdpsnd_oss_format_supported; + oss->device.GetVolume = rdpsnd_oss_get_volume; + oss->device.SetVolume = rdpsnd_oss_set_volume; + oss->device.Play = rdpsnd_oss_play; + oss->device.Close = rdpsnd_oss_close; + oss->device.Free = rdpsnd_oss_free; + oss->pcm_handle = -1; + oss->mixer_handle = -1; + oss->dev_unit = -1; + args = pEntryPoints->args; + if (rdpsnd_oss_parse_addin_args(&oss->device, args) < 0) + { + free(oss); + return ERROR_INVALID_PARAMETER; + } + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)oss); + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/pulse/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/pulse/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e08491e01a674c22f2ea29490f3cfce5bb26e254 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/pulse/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "pulse" "") + +find_package(PulseAudio REQUIRED) + +set(${MODULE_PREFIX}_SRCS rdpsnd_pulse.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_MAINLOOP_LIBRARY}) + +include_directories(..) +include_directories(SYSTEM ${PULSEAUDIO_INCLUDE_DIR}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/pulse/rdpsnd_pulse.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/pulse/rdpsnd_pulse.c new file mode 100644 index 0000000000000000000000000000000000000000..e3591cb65d0455f5cbd93ed52fbf2d253f59f762 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/pulse/rdpsnd_pulse.c @@ -0,0 +1,769 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; + + char* device_name; + pa_threaded_mainloop* mainloop; + pa_context* context; + pa_sample_spec sample_spec; + pa_stream* stream; + UINT32 latency; + UINT32 volume; + time_t reconnect_delay_seconds; + time_t reconnect_time; +} rdpsndPulsePlugin; + +static BOOL rdpsnd_check_pulse(rdpsndPulsePlugin* pulse, BOOL haveStream) +{ + BOOL rc = TRUE; + WINPR_ASSERT(pulse); + + if (!pulse->context) + { + WLog_WARN(TAG, "pulse->context=%p", pulse->context); + rc = FALSE; + } + + if (haveStream) + { + if (!pulse->stream) + { + WLog_WARN(TAG, "pulse->stream=%p", pulse->stream); + rc = FALSE; + } + } + + if (!pulse->mainloop) + { + WLog_WARN(TAG, "pulse->mainloop=%p", pulse->mainloop); + rc = FALSE; + } + + return rc; +} + +static BOOL rdpsnd_pulse_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format); + +static void rdpsnd_pulse_get_sink_info(pa_context* c, const pa_sink_info* i, int eol, + void* userdata) +{ + UINT16 dwVolumeLeft = ((50 * 0xFFFF) / 100); /* 50% */ + UINT16 dwVolumeRight = ((50 * 0xFFFF) / 100); /* 50% */ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)userdata; + + WINPR_ASSERT(c); + if (!rdpsnd_check_pulse(pulse, FALSE) || !i) + return; + + for (uint8_t x = 0; x < i->volume.channels; x++) + { + pa_volume_t volume = i->volume.values[x]; + + if (volume >= PA_VOLUME_NORM) + volume = PA_VOLUME_NORM - 1; + + switch (x) + { + case 0: + dwVolumeLeft = (UINT16)volume; + break; + + case 1: + dwVolumeRight = (UINT16)volume; + break; + + default: + break; + } + } + + pulse->volume = ((UINT32)dwVolumeLeft << 16U) | dwVolumeRight; +} + +static void rdpsnd_pulse_context_state_callback(pa_context* context, void* userdata) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)userdata; + + WINPR_ASSERT(context); + WINPR_ASSERT(pulse); + + pa_context_state_t state = pa_context_get_state(context); + + switch (state) + { + case PA_CONTEXT_READY: + pa_threaded_mainloop_signal(pulse->mainloop, 0); + break; + + case PA_CONTEXT_FAILED: + // Destroy context now, create new one for next connection attempt + pa_context_unref(pulse->context); + pulse->context = NULL; + if (pulse->reconnect_delay_seconds >= 0) + pulse->reconnect_time = time(NULL) + pulse->reconnect_delay_seconds; + pa_threaded_mainloop_signal(pulse->mainloop, 0); + break; + + case PA_CONTEXT_TERMINATED: + pa_threaded_mainloop_signal(pulse->mainloop, 0); + break; + + default: + break; + } +} + +static BOOL rdpsnd_pulse_connect(rdpsndDevicePlugin* device) +{ + BOOL rc = 0; + pa_operation* o = NULL; + pa_context_state_t state = PA_CONTEXT_FAILED; + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + if (!rdpsnd_check_pulse(pulse, FALSE)) + return FALSE; + + pa_threaded_mainloop_lock(pulse->mainloop); + + if (pa_context_connect(pulse->context, NULL, 0, NULL) < 0) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + return FALSE; + } + + for (;;) + { + state = pa_context_get_state(pulse->context); + + if (state == PA_CONTEXT_READY) + break; + + if (!PA_CONTEXT_IS_GOOD(state)) + { + break; + } + + pa_threaded_mainloop_wait(pulse->mainloop); + } + + o = pa_context_get_sink_info_by_index(pulse->context, 0, rdpsnd_pulse_get_sink_info, pulse); + + if (o) + pa_operation_unref(o); + + if (state == PA_CONTEXT_READY) + { + rc = TRUE; + } + else + { + pa_context_disconnect(pulse->context); + rc = FALSE; + } + + pa_threaded_mainloop_unlock(pulse->mainloop); + return rc; +} + +static void rdpsnd_pulse_stream_success_callback(pa_stream* stream, int success, void* userdata) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)userdata; + + if (!rdpsnd_check_pulse(pulse, TRUE)) + return; + + pa_threaded_mainloop_signal(pulse->mainloop, 0); +} + +static void rdpsnd_pulse_wait_for_operation(rdpsndPulsePlugin* pulse, pa_operation* operation) +{ + if (!rdpsnd_check_pulse(pulse, TRUE)) + return; + + if (!operation) + return; + + while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING) + { + pa_threaded_mainloop_wait(pulse->mainloop); + } + + pa_operation_unref(operation); +} + +static void rdpsnd_pulse_stream_state_callback(pa_stream* stream, void* userdata) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)userdata; + + WINPR_ASSERT(stream); + if (!rdpsnd_check_pulse(pulse, TRUE)) + return; + + pa_stream_state_t state = pa_stream_get_state(stream); + + switch (state) + { + case PA_STREAM_READY: + pa_threaded_mainloop_signal(pulse->mainloop, 0); + break; + + case PA_STREAM_FAILED: + case PA_STREAM_TERMINATED: + // Stream object is about to be destroyed, clean up our pointer + pulse->stream = NULL; + pa_threaded_mainloop_signal(pulse->mainloop, 0); + break; + + default: + break; + } +} + +static void rdpsnd_pulse_stream_request_callback(pa_stream* stream, size_t length, void* userdata) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)userdata; + + WINPR_ASSERT(stream); + if (!rdpsnd_check_pulse(pulse, TRUE)) + return; + + pa_threaded_mainloop_signal(pulse->mainloop, 0); +} + +static void rdpsnd_pulse_close(rdpsndDevicePlugin* device) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + WINPR_ASSERT(pulse); + + if (!rdpsnd_check_pulse(pulse, FALSE)) + return; + + pa_threaded_mainloop_lock(pulse->mainloop); + if (pulse->stream) + { + rdpsnd_pulse_wait_for_operation( + pulse, pa_stream_drain(pulse->stream, rdpsnd_pulse_stream_success_callback, pulse)); + pa_stream_disconnect(pulse->stream); + pa_stream_unref(pulse->stream); + pulse->stream = NULL; + } + pa_threaded_mainloop_unlock(pulse->mainloop); +} + +static BOOL rdpsnd_pulse_set_format_spec(rdpsndPulsePlugin* pulse, const AUDIO_FORMAT* format) +{ + pa_sample_spec sample_spec = { 0 }; + + WINPR_ASSERT(format); + + if (!rdpsnd_check_pulse(pulse, FALSE)) + return FALSE; + + if (!rdpsnd_pulse_format_supported(&pulse->device, format)) + return FALSE; + + sample_spec.rate = format->nSamplesPerSec; + sample_spec.channels = WINPR_ASSERTING_INT_CAST(uint8_t, format->nChannels); + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + switch (format->wBitsPerSample) + { + case 8: + sample_spec.format = PA_SAMPLE_U8; + break; + + case 16: + sample_spec.format = PA_SAMPLE_S16LE; + break; + + default: + return FALSE; + } + + break; + + default: + return FALSE; + } + + pulse->sample_spec = sample_spec; + return TRUE; +} + +static BOOL rdpsnd_pulse_context_connect(rdpsndDevicePlugin* device) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + pulse->context = pa_context_new(pa_threaded_mainloop_get_api(pulse->mainloop), "freerdp"); + + if (!pulse->context) + return FALSE; + + pa_context_set_state_callback(pulse->context, rdpsnd_pulse_context_state_callback, pulse); + + if (!rdpsnd_pulse_connect((rdpsndDevicePlugin*)pulse)) + return FALSE; + + return TRUE; +} + +static BOOL rdpsnd_pulse_open_stream(rdpsndDevicePlugin* device) +{ + pa_stream_state_t state = PA_STREAM_FAILED; + int flags = PA_STREAM_NOFLAGS; + pa_buffer_attr buffer_attr = { 0 }; + char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = { 0 }; + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + if (pa_sample_spec_valid(&pulse->sample_spec) == 0) + { + pa_sample_spec_snprint(ss, sizeof(ss), &pulse->sample_spec); + return FALSE; + } + + pa_threaded_mainloop_lock(pulse->mainloop); + if (!pulse->context) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + if (pulse->reconnect_delay_seconds >= 0 && time(NULL) - pulse->reconnect_time >= 0) + rdpsnd_pulse_context_connect(device); + pa_threaded_mainloop_lock(pulse->mainloop); + } + + if (!rdpsnd_check_pulse(pulse, FALSE)) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + return FALSE; + } + + pulse->stream = pa_stream_new(pulse->context, "freerdp", &pulse->sample_spec, NULL); + + if (!pulse->stream) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + return FALSE; + } + + /* register essential callbacks */ + pa_stream_set_state_callback(pulse->stream, rdpsnd_pulse_stream_state_callback, pulse); + pa_stream_set_write_callback(pulse->stream, rdpsnd_pulse_stream_request_callback, pulse); + flags = PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_AUTO_TIMING_UPDATE; + + if (pulse->latency > 0) + { + const size_t val = pa_usec_to_bytes(1000ULL * pulse->latency, &pulse->sample_spec); + buffer_attr.maxlength = UINT32_MAX; + buffer_attr.tlength = (val > UINT32_MAX) ? UINT32_MAX : (UINT32)val; + buffer_attr.prebuf = UINT32_MAX; + buffer_attr.minreq = UINT32_MAX; + buffer_attr.fragsize = UINT32_MAX; + flags |= PA_STREAM_ADJUST_LATENCY; + } + + // NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) + pa_stream_flags_t eflags = (pa_stream_flags_t)flags; + if (pa_stream_connect_playback(pulse->stream, pulse->device_name, + pulse->latency > 0 ? &buffer_attr : NULL, eflags, NULL, + NULL) < 0) + { + WLog_ERR(TAG, "error connecting playback stream"); + pa_stream_unref(pulse->stream); + pulse->stream = NULL; + pa_threaded_mainloop_unlock(pulse->mainloop); + return FALSE; + } + + while (pulse->stream) + { + state = pa_stream_get_state(pulse->stream); + + if (state == PA_STREAM_READY) + break; + + if (!PA_STREAM_IS_GOOD(state)) + { + break; + } + + pa_threaded_mainloop_wait(pulse->mainloop); + } + + pa_threaded_mainloop_unlock(pulse->mainloop); + + if (state == PA_STREAM_READY) + return TRUE; + + rdpsnd_pulse_close(device); + return FALSE; +} + +static BOOL rdpsnd_pulse_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 latency) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + WINPR_ASSERT(format); + + if (!rdpsnd_check_pulse(pulse, FALSE)) + return TRUE; + + if (!rdpsnd_pulse_set_format_spec(pulse, format)) + return FALSE; + + pulse->latency = latency; + + return rdpsnd_pulse_open_stream(device); +} + +static void rdpsnd_pulse_free(rdpsndDevicePlugin* device) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + if (!pulse) + return; + + rdpsnd_pulse_close(device); + + if (pulse->mainloop) + pa_threaded_mainloop_stop(pulse->mainloop); + + if (pulse->context) + { + pa_context_disconnect(pulse->context); + pa_context_unref(pulse->context); + pulse->context = NULL; + } + + if (pulse->mainloop) + { + pa_threaded_mainloop_free(pulse->mainloop); + pulse->mainloop = NULL; + } + + free(pulse->device_name); + free(pulse); +} + +static BOOL rdpsnd_pulse_default_format(rdpsndDevicePlugin* device, const AUDIO_FORMAT* desired, + AUDIO_FORMAT* defaultFormat) +{ + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + if (!pulse || !defaultFormat) + return FALSE; + + *defaultFormat = *desired; + defaultFormat->data = NULL; + defaultFormat->cbSize = 0; + defaultFormat->wFormatTag = WAVE_FORMAT_PCM; + if ((defaultFormat->nChannels < 1) || (defaultFormat->nChannels > PA_CHANNELS_MAX)) + defaultFormat->nChannels = 2; + if ((defaultFormat->nSamplesPerSec < 1) || (defaultFormat->nSamplesPerSec > PA_RATE_MAX)) + defaultFormat->nSamplesPerSec = 44100; + if ((defaultFormat->wBitsPerSample != 8) && (defaultFormat->wBitsPerSample != 16)) + defaultFormat->wBitsPerSample = 16; + + defaultFormat->nBlockAlign = defaultFormat->nChannels * defaultFormat->wBitsPerSample / 8; + defaultFormat->nAvgBytesPerSec = defaultFormat->nBlockAlign * defaultFormat->nSamplesPerSec; + return TRUE; +} + +BOOL rdpsnd_pulse_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format) +{ + WINPR_ASSERT(device); + WINPR_ASSERT(format); + + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + if (format->cbSize == 0 && (format->nSamplesPerSec <= PA_RATE_MAX) && + (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) && + (format->nChannels >= 1 && format->nChannels <= PA_CHANNELS_MAX)) + { + return TRUE; + } + + break; + + default: + break; + } + + return FALSE; +} + +static UINT32 rdpsnd_pulse_get_volume(rdpsndDevicePlugin* device) +{ + pa_operation* o = NULL; + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + if (!rdpsnd_check_pulse(pulse, FALSE)) + return 0; + + pa_threaded_mainloop_lock(pulse->mainloop); + o = pa_context_get_sink_info_by_index(pulse->context, 0, rdpsnd_pulse_get_sink_info, pulse); + if (o) + pa_operation_unref(o); + pa_threaded_mainloop_unlock(pulse->mainloop); + return pulse->volume; +} + +static void rdpsnd_set_volume_success_cb(pa_context* c, int success, void* userdata) +{ + rdpsndPulsePlugin* pulse = userdata; + + if (!rdpsnd_check_pulse(pulse, TRUE)) + return; + WINPR_ASSERT(c); + + WLog_INFO(TAG, "%d", success); +} + +static BOOL rdpsnd_pulse_set_volume(rdpsndDevicePlugin* device, UINT32 value) +{ + pa_cvolume cv = { 0 }; + pa_volume_t left = 0; + pa_volume_t right = 0; + pa_operation* operation = NULL; + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + if (!rdpsnd_check_pulse(pulse, TRUE)) + { + WLog_WARN(TAG, "%s called before pulse backend was initialized"); + return FALSE; + } + + left = (pa_volume_t)(value & 0xFFFF); + right = (pa_volume_t)((value >> 16) & 0xFFFF); + pa_cvolume_init(&cv); + cv.channels = 2; + cv.values[0] = PA_VOLUME_MUTED + (left * (PA_VOLUME_NORM - PA_VOLUME_MUTED)) / PA_VOLUME_NORM; + cv.values[1] = PA_VOLUME_MUTED + (right * (PA_VOLUME_NORM - PA_VOLUME_MUTED)) / PA_VOLUME_NORM; + pa_threaded_mainloop_lock(pulse->mainloop); + operation = pa_context_set_sink_input_volume(pulse->context, pa_stream_get_index(pulse->stream), + &cv, rdpsnd_set_volume_success_cb, pulse); + + if (operation) + pa_operation_unref(operation); + + pa_threaded_mainloop_unlock(pulse->mainloop); + return TRUE; +} + +static UINT rdpsnd_pulse_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) +{ + size_t length = 0; + void* pa_data = NULL; + int status = 0; + pa_usec_t latency = 0; + int negative = 0; + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + + if (!data) + return 0; + + pa_threaded_mainloop_lock(pulse->mainloop); + + if (!rdpsnd_check_pulse(pulse, TRUE)) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + // Discard this playback request and just attempt to reconnect the stream + WLog_DBG(TAG, "reconnecting playback stream"); + rdpsnd_pulse_open_stream(device); + return 0; + } + + while (size > 0) + { + length = size; + + status = pa_stream_begin_write(pulse->stream, &pa_data, &length); + + if (status < 0) + break; + + memcpy(pa_data, data, length); + + status = pa_stream_write(pulse->stream, pa_data, length, NULL, 0LL, PA_SEEK_RELATIVE); + + if (status < 0) + { + break; + } + + data += length; + size -= length; + } + + if (pa_stream_get_latency(pulse->stream, &latency, &negative) != 0) + latency = 0; + + pa_threaded_mainloop_unlock(pulse->mainloop); + + const pa_usec_t val = latency / 1000; + if (val > UINT32_MAX) + return UINT32_MAX; + return (UINT32)val; +} + +static UINT rdpsnd_pulse_parse_addin_args(rdpsndDevicePlugin* device, const ADDIN_ARGV* args) +{ + int status = 0; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device; + COMMAND_LINE_ARGUMENT_A rdpsnd_pulse_args[] = { + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "device" }, + { "reconnect_delay_seconds", COMMAND_LINE_VALUE_REQUIRED, "", NULL, + NULL, -1, NULL, "reconnect_delay_seconds" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } + }; + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + + WINPR_ASSERT(pulse); + WINPR_ASSERT(args); + + status = CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_pulse_args, flags, pulse, + NULL, NULL); + + if (status < 0) + return ERROR_INVALID_DATA; + + arg = rdpsnd_pulse_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dev") + { + pulse->device_name = _strdup(arg->Value); + + if (!pulse->device_name) + return ERROR_OUTOFMEMORY; + } + CommandLineSwitchCase(arg, "reconnect_delay_seconds") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val > INT32_MAX)) + return ERROR_INVALID_DATA; + + pulse->reconnect_delay_seconds = (time_t)val; + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +FREERDP_ENTRY_POINT(UINT VCAPITYPE pulse_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args = NULL; + rdpsndPulsePlugin* pulse = NULL; + UINT ret = 0; + + WINPR_ASSERT(pEntryPoints); + + pulse = (rdpsndPulsePlugin*)calloc(1, sizeof(rdpsndPulsePlugin)); + + if (!pulse) + return CHANNEL_RC_NO_MEMORY; + + pulse->device.Open = rdpsnd_pulse_open; + pulse->device.FormatSupported = rdpsnd_pulse_format_supported; + pulse->device.GetVolume = rdpsnd_pulse_get_volume; + pulse->device.SetVolume = rdpsnd_pulse_set_volume; + pulse->device.Play = rdpsnd_pulse_play; + pulse->device.Close = rdpsnd_pulse_close; + pulse->device.Free = rdpsnd_pulse_free; + pulse->device.DefaultFormat = rdpsnd_pulse_default_format; + args = pEntryPoints->args; + + if (args->argc > 1) + { + ret = rdpsnd_pulse_parse_addin_args(&pulse->device, args); + + if (ret != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "error parsing arguments"); + goto error; + } + } + pulse->reconnect_delay_seconds = 5; + pulse->reconnect_time = time(NULL); + + ret = CHANNEL_RC_NO_MEMORY; + pulse->mainloop = pa_threaded_mainloop_new(); + + if (!pulse->mainloop) + goto error; + + pa_threaded_mainloop_lock(pulse->mainloop); + + if (pa_threaded_mainloop_start(pulse->mainloop) < 0) + { + pa_threaded_mainloop_unlock(pulse->mainloop); + goto error; + } + + pa_threaded_mainloop_unlock(pulse->mainloop); + + if (!rdpsnd_pulse_context_connect((rdpsndDevicePlugin*)pulse)) + goto error; + + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)pulse); + return CHANNEL_RC_OK; +error: + rdpsnd_pulse_free((rdpsndDevicePlugin*)pulse); + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/rdpsnd_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/rdpsnd_main.c new file mode 100644 index 0000000000000000000000000000000000000000..0ed4aa2beb3d41ddd979fec728a2f29d12285578 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/rdpsnd_main.c @@ -0,0 +1,1858 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2011 Vic Lee + * Copyright 2012-2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 David PHAM-VAN + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#ifndef _WIN32 +#include +#include +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "rdpsnd_common.h" +#include "rdpsnd_main.h" + +struct rdpsnd_plugin +{ + IWTSPlugin iface; + IWTSListener* listener; + GENERIC_LISTENER_CALLBACK* listener_callback; + + CHANNEL_DEF channelDef; + CHANNEL_ENTRY_POINTS_FREERDP_EX channelEntryPoints; + + wStreamPool* pool; + wStream* data_in; + + void* InitHandle; + DWORD OpenHandle; + + wLog* log; + + BYTE cBlockNo; + UINT16 wQualityMode; + UINT16 wCurrentFormatNo; + + AUDIO_FORMAT* ServerFormats; + UINT16 NumberOfServerFormats; + + AUDIO_FORMAT* ClientFormats; + UINT16 NumberOfClientFormats; + + BOOL attached; + BOOL connected; + BOOL dynamic; + + BOOL expectingWave; + BYTE waveData[4]; + UINT16 waveDataSize; + UINT16 wTimeStamp; + UINT64 wArrivalTime; + + UINT32 latency; + BOOL isOpen; + AUDIO_FORMAT* fixed_format; + + UINT32 startPlayTime; + size_t totalPlaySize; + + char* subsystem; + char* device_name; + + /* Device plugin */ + rdpsndDevicePlugin* device; + rdpContext* rdpcontext; + + FREERDP_DSP_CONTEXT* dsp_context; + + HANDLE thread; + wMessageQueue* queue; + BOOL initialized; + + UINT16 wVersion; + UINT32 volume; + BOOL applyVolume; + + size_t references; + BOOL OnOpenCalled; + BOOL async; +}; + +static const char* rdpsnd_is_dyn_str(BOOL dynamic) +{ + if (dynamic) + return "[dynamic]"; + return "[static]"; +} + +static void rdpsnd_virtual_channel_event_terminated(rdpsndPlugin* rdpsnd); + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_virtual_channel_write(rdpsndPlugin* rdpsnd, wStream* s); + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_send_quality_mode_pdu(rdpsndPlugin* rdpsnd) +{ + wStream* pdu = NULL; + WINPR_ASSERT(rdpsnd); + pdu = Stream_New(NULL, 8); + + if (!pdu) + { + WLog_ERR(TAG, "%s Stream_New failed!", rdpsnd_is_dyn_str(rdpsnd->dynamic)); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT8(pdu, SNDC_QUALITYMODE); /* msgType */ + Stream_Write_UINT8(pdu, 0); /* bPad */ + Stream_Write_UINT16(pdu, 4); /* BodySize */ + Stream_Write_UINT16(pdu, rdpsnd->wQualityMode); /* wQualityMode */ + Stream_Write_UINT16(pdu, 0); /* Reserved */ + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s QualityMode: %" PRIu16 "", + rdpsnd_is_dyn_str(rdpsnd->dynamic), rdpsnd->wQualityMode); + return rdpsnd_virtual_channel_write(rdpsnd, pdu); +} + +static void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd) +{ + WINPR_ASSERT(rdpsnd); + audio_formats_free(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats); + rdpsnd->NumberOfClientFormats = 0; + rdpsnd->ClientFormats = NULL; + + if (!rdpsnd->NumberOfServerFormats) + return; + + rdpsnd->ClientFormats = audio_formats_new(rdpsnd->NumberOfServerFormats); + + if (!rdpsnd->ClientFormats || !rdpsnd->device) + return; + + for (UINT16 index = 0; index < rdpsnd->NumberOfServerFormats; index++) + { + const AUDIO_FORMAT* serverFormat = &rdpsnd->ServerFormats[index]; + + if (!audio_format_compatible(rdpsnd->fixed_format, serverFormat)) + continue; + + WINPR_ASSERT(rdpsnd->device->FormatSupported); + if (freerdp_dsp_supports_format(serverFormat, FALSE) || + rdpsnd->device->FormatSupported(rdpsnd->device, serverFormat)) + { + AUDIO_FORMAT* clientFormat = &rdpsnd->ClientFormats[rdpsnd->NumberOfClientFormats++]; + audio_format_copy(serverFormat, clientFormat); + } + } +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_send_client_audio_formats(rdpsndPlugin* rdpsnd) +{ + wStream* pdu = NULL; + UINT16 length = 0; + UINT32 dwVolume = 0; + UINT16 wNumberOfFormats = 0; + WINPR_ASSERT(rdpsnd); + + if (!rdpsnd->device || (!rdpsnd->dynamic && (rdpsnd->OpenHandle == 0))) + return CHANNEL_RC_INITIALIZATION_ERROR; + + dwVolume = IFCALLRESULT(0, rdpsnd->device->GetVolume, rdpsnd->device); + wNumberOfFormats = rdpsnd->NumberOfClientFormats; + length = 4 + 20; + + for (UINT16 index = 0; index < wNumberOfFormats; index++) + length += (18 + rdpsnd->ClientFormats[index].cbSize); + + pdu = Stream_New(NULL, length); + + if (!pdu) + { + WLog_ERR(TAG, "%s Stream_New failed!", rdpsnd_is_dyn_str(rdpsnd->dynamic)); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT8(pdu, SNDC_FORMATS); /* msgType */ + Stream_Write_UINT8(pdu, 0); /* bPad */ + Stream_Write_UINT16(pdu, length - 4); /* BodySize */ + Stream_Write_UINT32(pdu, TSSNDCAPS_ALIVE | TSSNDCAPS_VOLUME); /* dwFlags */ + Stream_Write_UINT32(pdu, dwVolume); /* dwVolume */ + Stream_Write_UINT32(pdu, 0); /* dwPitch */ + Stream_Write_UINT16(pdu, 0); /* wDGramPort */ + Stream_Write_UINT16(pdu, wNumberOfFormats); /* wNumberOfFormats */ + Stream_Write_UINT8(pdu, 0); /* cLastBlockConfirmed */ + Stream_Write_UINT16(pdu, CHANNEL_VERSION_WIN_MAX); /* wVersion */ + Stream_Write_UINT8(pdu, 0); /* bPad */ + + for (UINT16 index = 0; index < wNumberOfFormats; index++) + { + const AUDIO_FORMAT* clientFormat = &rdpsnd->ClientFormats[index]; + + if (!audio_format_write(pdu, clientFormat)) + { + Stream_Free(pdu, TRUE); + return ERROR_INTERNAL_ERROR; + } + } + + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Client Audio Formats", + rdpsnd_is_dyn_str(rdpsnd->dynamic)); + return rdpsnd_virtual_channel_write(rdpsnd, pdu); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd, wStream* s) +{ + UINT16 wNumberOfFormats = 0; + UINT ret = ERROR_BAD_LENGTH; + + WINPR_ASSERT(rdpsnd); + audio_formats_free(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats); + rdpsnd->NumberOfServerFormats = 0; + rdpsnd->ServerFormats = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 30)) + return ERROR_BAD_LENGTH; + + /* http://msdn.microsoft.com/en-us/library/cc240956.aspx */ + Stream_Seek_UINT32(s); /* dwFlags */ + Stream_Seek_UINT32(s); /* dwVolume */ + Stream_Seek_UINT32(s); /* dwPitch */ + Stream_Seek_UINT16(s); /* wDGramPort */ + Stream_Read_UINT16(s, wNumberOfFormats); + Stream_Read_UINT8(s, rdpsnd->cBlockNo); /* cLastBlockConfirmed */ + Stream_Read_UINT16(s, rdpsnd->wVersion); /* wVersion */ + Stream_Seek_UINT8(s); /* bPad */ + rdpsnd->NumberOfServerFormats = wNumberOfFormats; + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, wNumberOfFormats, 14ull)) + return ERROR_BAD_LENGTH; + + if (rdpsnd->NumberOfServerFormats > 0) + { + rdpsnd->ServerFormats = audio_formats_new(wNumberOfFormats); + + if (!rdpsnd->ServerFormats) + return CHANNEL_RC_NO_MEMORY; + + for (UINT16 index = 0; index < wNumberOfFormats; index++) + { + AUDIO_FORMAT* format = &rdpsnd->ServerFormats[index]; + + if (!audio_format_read(s, format)) + goto out_fail; + } + } + + WINPR_ASSERT(rdpsnd->device); + ret = IFCALLRESULT(CHANNEL_RC_OK, rdpsnd->device->ServerFormatAnnounce, rdpsnd->device, + rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats); + if (ret != CHANNEL_RC_OK) + goto out_fail; + + rdpsnd_select_supported_audio_formats(rdpsnd); + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Server Audio Formats", + rdpsnd_is_dyn_str(rdpsnd->dynamic)); + ret = rdpsnd_send_client_audio_formats(rdpsnd); + + if (ret == CHANNEL_RC_OK) + { + if (rdpsnd->wVersion >= CHANNEL_VERSION_WIN_7) + ret = rdpsnd_send_quality_mode_pdu(rdpsnd); + } + + return ret; +out_fail: + audio_formats_free(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats); + rdpsnd->ServerFormats = NULL; + rdpsnd->NumberOfServerFormats = 0; + return ret; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_send_training_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, + UINT16 wPackSize) +{ + wStream* pdu = NULL; + WINPR_ASSERT(rdpsnd); + pdu = Stream_New(NULL, 8); + + if (!pdu) + { + WLog_ERR(TAG, "%s Stream_New failed!", rdpsnd_is_dyn_str(rdpsnd->dynamic)); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT8(pdu, SNDC_TRAINING); /* msgType */ + Stream_Write_UINT8(pdu, 0); /* bPad */ + Stream_Write_UINT16(pdu, 4); /* BodySize */ + Stream_Write_UINT16(pdu, wTimeStamp); + Stream_Write_UINT16(pdu, wPackSize); + WLog_Print(rdpsnd->log, WLOG_DEBUG, + "%s Training Response: wTimeStamp: %" PRIu16 " wPackSize: %" PRIu16 "", + rdpsnd_is_dyn_str(rdpsnd->dynamic), wTimeStamp, wPackSize); + return rdpsnd_virtual_channel_write(rdpsnd, pdu); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_recv_training_pdu(rdpsndPlugin* rdpsnd, wStream* s) +{ + UINT16 wTimeStamp = 0; + UINT16 wPackSize = 0; + WINPR_ASSERT(rdpsnd); + WINPR_ASSERT(s); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_BAD_LENGTH; + + Stream_Read_UINT16(s, wTimeStamp); + Stream_Read_UINT16(s, wPackSize); + WLog_Print(rdpsnd->log, WLOG_DEBUG, + "%s Training Request: wTimeStamp: %" PRIu16 " wPackSize: %" PRIu16 "", + rdpsnd_is_dyn_str(rdpsnd->dynamic), wTimeStamp, wPackSize); + return rdpsnd_send_training_confirm_pdu(rdpsnd, wTimeStamp, wPackSize); +} + +static BOOL rdpsnd_apply_volume(rdpsndPlugin* rdpsnd) +{ + WINPR_ASSERT(rdpsnd); + + if (rdpsnd->isOpen && rdpsnd->applyVolume && rdpsnd->device) + { + BOOL rc = IFCALLRESULT(TRUE, rdpsnd->device->SetVolume, rdpsnd->device, rdpsnd->volume); + if (!rc) + return FALSE; + rdpsnd->applyVolume = FALSE; + } + return TRUE; +} + +static BOOL rdpsnd_ensure_device_is_open(rdpsndPlugin* rdpsnd, UINT16 wFormatNo, + const AUDIO_FORMAT* format) +{ + if (!rdpsnd) + return FALSE; + WINPR_ASSERT(format); + + if (!rdpsnd->isOpen || (wFormatNo != rdpsnd->wCurrentFormatNo)) + { + BOOL rc = 0; + BOOL supported = 0; + AUDIO_FORMAT deviceFormat = *format; + + IFCALL(rdpsnd->device->Close, rdpsnd->device); + supported = IFCALLRESULT(FALSE, rdpsnd->device->FormatSupported, rdpsnd->device, format); + + if (!supported) + { + if (!IFCALLRESULT(FALSE, rdpsnd->device->DefaultFormat, rdpsnd->device, format, + &deviceFormat)) + { + deviceFormat.wFormatTag = WAVE_FORMAT_PCM; + deviceFormat.wBitsPerSample = 16; + deviceFormat.cbSize = 0; + } + } + + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Opening device with format %s [backend %s]", + rdpsnd_is_dyn_str(rdpsnd->dynamic), + audio_format_get_tag_string(format->wFormatTag), + audio_format_get_tag_string(deviceFormat.wFormatTag)); + rc = IFCALLRESULT(FALSE, rdpsnd->device->Open, rdpsnd->device, &deviceFormat, + rdpsnd->latency); + + if (!rc) + return FALSE; + + if (!supported) + { + if (!freerdp_dsp_context_reset(rdpsnd->dsp_context, format, 0u)) + return FALSE; + } + + rdpsnd->isOpen = TRUE; + rdpsnd->wCurrentFormatNo = wFormatNo; + rdpsnd->startPlayTime = 0; + rdpsnd->totalPlaySize = 0; + } + + return rdpsnd_apply_volume(rdpsnd); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_recv_wave_info_pdu(rdpsndPlugin* rdpsnd, wStream* s, UINT16 BodySize) +{ + UINT16 wFormatNo = 0; + const AUDIO_FORMAT* format = NULL; + WINPR_ASSERT(rdpsnd); + WINPR_ASSERT(s); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_BAD_LENGTH; + + rdpsnd->wArrivalTime = GetTickCount64(); + Stream_Read_UINT16(s, rdpsnd->wTimeStamp); + Stream_Read_UINT16(s, wFormatNo); + + if (wFormatNo >= rdpsnd->NumberOfClientFormats) + return ERROR_INVALID_DATA; + + Stream_Read_UINT8(s, rdpsnd->cBlockNo); + Stream_Seek(s, 3); /* bPad */ + Stream_Read(s, rdpsnd->waveData, 4); + rdpsnd->waveDataSize = BodySize - 8; + format = &rdpsnd->ClientFormats[wFormatNo]; + WLog_Print(rdpsnd->log, WLOG_DEBUG, + "%s WaveInfo: cBlockNo: %" PRIu8 " wFormatNo: %" PRIu16 " [%s]", + rdpsnd_is_dyn_str(rdpsnd->dynamic), rdpsnd->cBlockNo, wFormatNo, + audio_format_get_tag_string(format->wFormatTag)); + + if (!rdpsnd_ensure_device_is_open(rdpsnd, wFormatNo, format)) + return ERROR_INTERNAL_ERROR; + + rdpsnd->expectingWave = TRUE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_send_wave_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, + BYTE cConfirmedBlockNo) +{ + wStream* pdu = NULL; + WINPR_ASSERT(rdpsnd); + pdu = Stream_New(NULL, 8); + + if (!pdu) + { + WLog_ERR(TAG, "%s Stream_New failed!", rdpsnd_is_dyn_str(rdpsnd->dynamic)); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write_UINT8(pdu, SNDC_WAVECONFIRM); + Stream_Write_UINT8(pdu, 0); + Stream_Write_UINT16(pdu, 4); + Stream_Write_UINT16(pdu, wTimeStamp); + Stream_Write_UINT8(pdu, cConfirmedBlockNo); /* cConfirmedBlockNo */ + Stream_Write_UINT8(pdu, 0); /* bPad */ + return rdpsnd_virtual_channel_write(rdpsnd, pdu); +} + +static BOOL rdpsnd_detect_overrun(rdpsndPlugin* rdpsnd, const AUDIO_FORMAT* format, size_t size) +{ + UINT32 bpf = 0; + UINT32 now = 0; + UINT32 duration = 0; + UINT32 totalDuration = 0; + UINT32 remainingDuration = 0; + UINT32 maxDuration = 0; + + if (!rdpsnd || !format) + return FALSE; + + /* Older windows RDP servers do not limit the send buffer, which can + * cause quite a large amount of sound data buffered client side. + * If e.g. sound is paused server side the client will keep playing + * for a long time instead of pausing playback. + * + * To avoid this we check: + * + * 1. Is the sound sample received from a known format these servers + * support + * 2. If it is calculate the size of the client side sound buffer + * 3. If the buffer is too large silently drop the sample which will + * trigger a retransmit later on. + * + * This check must only be applied to these known formats, because + * with newer and other formats the sample size can not be calculated + * without decompressing the sample first. + */ + switch (format->wFormatTag) + { + case WAVE_FORMAT_PCM: + case WAVE_FORMAT_DVI_ADPCM: + case WAVE_FORMAT_ADPCM: + case WAVE_FORMAT_ALAW: + case WAVE_FORMAT_MULAW: + break; + case WAVE_FORMAT_MSG723: + case WAVE_FORMAT_GSM610: + case WAVE_FORMAT_AAC_MS: + default: + return FALSE; + } + + audio_format_print(WLog_Get(TAG), WLOG_DEBUG, format); + bpf = format->nChannels * format->wBitsPerSample * format->nSamplesPerSec / 8; + if (bpf == 0) + return FALSE; + + duration = (UINT32)(1000 * size / bpf); + totalDuration = (UINT32)(1000 * rdpsnd->totalPlaySize / bpf); + now = GetTickCountPrecise(); + if (rdpsnd->startPlayTime == 0) + { + rdpsnd->startPlayTime = now; + rdpsnd->totalPlaySize = size; + return FALSE; + } + else if (now - rdpsnd->startPlayTime > totalDuration + 10) + { + /* Buffer underrun */ + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Buffer underrun by %u ms", + rdpsnd_is_dyn_str(rdpsnd->dynamic), + (UINT)(now - rdpsnd->startPlayTime - totalDuration)); + rdpsnd->startPlayTime = now; + rdpsnd->totalPlaySize = size; + return FALSE; + } + else + { + /* Calculate remaining duration to be played */ + remainingDuration = totalDuration - (now - rdpsnd->startPlayTime); + + /* Maximum allow duration calculation */ + maxDuration = duration * 2 + rdpsnd->latency; + + if (remainingDuration + duration > maxDuration) + { + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Buffer overrun pending %u ms dropping %u ms", + rdpsnd_is_dyn_str(rdpsnd->dynamic), remainingDuration, duration); + return TRUE; + } + + rdpsnd->totalPlaySize += size; + return FALSE; + } +} + +static UINT rdpsnd_treat_wave(rdpsndPlugin* rdpsnd, wStream* s, size_t size) +{ + AUDIO_FORMAT* format = NULL; + UINT64 end = 0; + UINT64 diffMS = 0; + UINT64 ts = 0; + UINT latency = 0; + UINT error = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, size)) + return ERROR_BAD_LENGTH; + + if (rdpsnd->wCurrentFormatNo >= rdpsnd->NumberOfClientFormats) + return ERROR_INTERNAL_ERROR; + + /* + * Send the first WaveConfirm PDU. The server side uses this to determine the + * network latency. + * See also [MS-RDPEA] 2.2.3.8 Wave Confirm PDU + */ + error = rdpsnd_send_wave_confirm_pdu(rdpsnd, rdpsnd->wTimeStamp, rdpsnd->cBlockNo); + if (error) + return error; + + const BYTE* data = Stream_ConstPointer(s); + format = &rdpsnd->ClientFormats[rdpsnd->wCurrentFormatNo]; + WLog_Print(rdpsnd->log, WLOG_DEBUG, + "%s Wave: cBlockNo: %" PRIu8 " wTimeStamp: %" PRIu16 ", size: %" PRIdz, + rdpsnd_is_dyn_str(rdpsnd->dynamic), rdpsnd->cBlockNo, rdpsnd->wTimeStamp, size); + + if (rdpsnd->device && rdpsnd->attached && !rdpsnd_detect_overrun(rdpsnd, format, size)) + { + UINT status = CHANNEL_RC_OK; + wStream* pcmData = StreamPool_Take(rdpsnd->pool, 4096); + + if (rdpsnd->device->FormatSupported(rdpsnd->device, format)) + { + if (rdpsnd->device->PlayEx) + latency = rdpsnd->device->PlayEx(rdpsnd->device, format, data, size); + else + latency = IFCALLRESULT(0, rdpsnd->device->Play, rdpsnd->device, data, size); + } + else if (freerdp_dsp_decode(rdpsnd->dsp_context, format, data, size, pcmData)) + { + Stream_SealLength(pcmData); + + if (rdpsnd->device->PlayEx) + latency = rdpsnd->device->PlayEx(rdpsnd->device, format, Stream_Buffer(pcmData), + Stream_Length(pcmData)); + else + latency = IFCALLRESULT(0, rdpsnd->device->Play, rdpsnd->device, + Stream_Buffer(pcmData), Stream_Length(pcmData)); + } + else + status = ERROR_INTERNAL_ERROR; + + Stream_Release(pcmData); + + if (status != CHANNEL_RC_OK) + return status; + } + + end = GetTickCount64(); + diffMS = end - rdpsnd->wArrivalTime + latency; + ts = (rdpsnd->wTimeStamp + diffMS) % UINT16_MAX; + + /* + * Send the second WaveConfirm PDU. With the first WaveConfirm PDU, + * the server side uses this second WaveConfirm PDU to determine the actual + * render latency. + */ + return rdpsnd_send_wave_confirm_pdu(rdpsnd, (UINT16)ts, rdpsnd->cBlockNo); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_recv_wave_pdu(rdpsndPlugin* rdpsnd, wStream* s) +{ + rdpsnd->expectingWave = FALSE; + + /** + * The Wave PDU is a special case: it is always sent after a Wave Info PDU, + * and we do not process its header. Instead, the header is pad that needs + * to be filled with the first four bytes of the audio sample data sent as + * part of the preceding Wave Info PDU. + */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + CopyMemory(Stream_Buffer(s), rdpsnd->waveData, 4); + return rdpsnd_treat_wave(rdpsnd, s, rdpsnd->waveDataSize); +} + +static UINT rdpsnd_recv_wave2_pdu(rdpsndPlugin* rdpsnd, wStream* s, UINT16 BodySize) +{ + UINT16 wFormatNo = 0; + AUDIO_FORMAT* format = NULL; + UINT32 dwAudioTimeStamp = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_BAD_LENGTH; + + Stream_Read_UINT16(s, rdpsnd->wTimeStamp); + Stream_Read_UINT16(s, wFormatNo); + Stream_Read_UINT8(s, rdpsnd->cBlockNo); + Stream_Seek(s, 3); /* bPad */ + Stream_Read_UINT32(s, dwAudioTimeStamp); + if (wFormatNo >= rdpsnd->NumberOfClientFormats) + return ERROR_INVALID_DATA; + format = &rdpsnd->ClientFormats[wFormatNo]; + rdpsnd->waveDataSize = BodySize - 12; + rdpsnd->wArrivalTime = GetTickCount64(); + WLog_Print(rdpsnd->log, WLOG_DEBUG, + "%s Wave2PDU: cBlockNo: %" PRIu8 " wFormatNo: %" PRIu16 " [%s] , align=%hu", + rdpsnd_is_dyn_str(rdpsnd->dynamic), rdpsnd->cBlockNo, wFormatNo, + audio_format_get_tag_string(format->wFormatTag), format->nBlockAlign); + + if (!rdpsnd_ensure_device_is_open(rdpsnd, wFormatNo, format)) + return ERROR_INTERNAL_ERROR; + + return rdpsnd_treat_wave(rdpsnd, s, rdpsnd->waveDataSize); +} + +static void rdpsnd_recv_close_pdu(rdpsndPlugin* rdpsnd) +{ + if (rdpsnd->isOpen) + { + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Closing device", + rdpsnd_is_dyn_str(rdpsnd->dynamic)); + } + else + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Device already closed", + rdpsnd_is_dyn_str(rdpsnd->dynamic)); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_recv_volume_pdu(rdpsndPlugin* rdpsnd, wStream* s) +{ + BOOL rc = TRUE; + UINT32 dwVolume = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_BAD_LENGTH; + + Stream_Read_UINT32(s, dwVolume); + WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Volume: 0x%08" PRIX32 "", + rdpsnd_is_dyn_str(rdpsnd->dynamic), dwVolume); + + rdpsnd->volume = dwVolume; + rdpsnd->applyVolume = TRUE; + rc = rdpsnd_apply_volume(rdpsnd); + + if (!rc) + { + WLog_ERR(TAG, "%s error setting volume", rdpsnd_is_dyn_str(rdpsnd->dynamic)); + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_recv_pdu(rdpsndPlugin* rdpsnd, wStream* s) +{ + BYTE msgType = 0; + UINT16 BodySize = 0; + UINT status = CHANNEL_RC_OK; + + if (rdpsnd->expectingWave) + { + status = rdpsnd_recv_wave_pdu(rdpsnd, s); + goto out; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + { + status = ERROR_BAD_LENGTH; + goto out; + } + + Stream_Read_UINT8(s, msgType); /* msgType */ + Stream_Seek_UINT8(s); /* bPad */ + Stream_Read_UINT16(s, BodySize); + + switch (msgType) + { + case SNDC_FORMATS: + status = rdpsnd_recv_server_audio_formats_pdu(rdpsnd, s); + break; + + case SNDC_TRAINING: + status = rdpsnd_recv_training_pdu(rdpsnd, s); + break; + + case SNDC_WAVE: + status = rdpsnd_recv_wave_info_pdu(rdpsnd, s, BodySize); + break; + + case SNDC_CLOSE: + rdpsnd_recv_close_pdu(rdpsnd); + break; + + case SNDC_SETVOLUME: + status = rdpsnd_recv_volume_pdu(rdpsnd, s); + break; + + case SNDC_WAVE2: + status = rdpsnd_recv_wave2_pdu(rdpsnd, s, BodySize); + break; + + default: + WLog_ERR(TAG, "%s unknown msgType %" PRIu8 "", rdpsnd_is_dyn_str(rdpsnd->dynamic), + msgType); + break; + } + +out: + Stream_Release(s); + return status; +} + +static void rdpsnd_register_device_plugin(rdpsndPlugin* rdpsnd, rdpsndDevicePlugin* device) +{ + if (rdpsnd->device) + { + WLog_ERR(TAG, "%s existing device, abort.", rdpsnd_is_dyn_str(FALSE)); + return; + } + + rdpsnd->device = device; + device->rdpsnd = rdpsnd; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_load_device_plugin(rdpsndPlugin* rdpsnd, const char* name, + const ADDIN_ARGV* args) +{ + FREERDP_RDPSND_DEVICE_ENTRY_POINTS entryPoints = { 0 }; + UINT error = 0; + DWORD flags = FREERDP_ADDIN_CHANNEL_STATIC | FREERDP_ADDIN_CHANNEL_ENTRYEX; + if (rdpsnd->dynamic) + flags = FREERDP_ADDIN_CHANNEL_DYNAMIC; + PVIRTUALCHANNELENTRY pvce = + freerdp_load_channel_addin_entry(RDPSND_CHANNEL_NAME, name, NULL, flags); + PFREERDP_RDPSND_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_RDPSND_DEVICE_ENTRY); + + if (!entry) + return ERROR_INTERNAL_ERROR; + + entryPoints.rdpsnd = rdpsnd; + entryPoints.pRegisterRdpsndDevice = rdpsnd_register_device_plugin; + entryPoints.args = args; + + error = entry(&entryPoints); + if (error) + WLog_ERR(TAG, "%s %s entry returns error %" PRIu32 "", rdpsnd_is_dyn_str(rdpsnd->dynamic), + name, error); + + WLog_INFO(TAG, "%s Loaded %s backend for rdpsnd", rdpsnd_is_dyn_str(rdpsnd->dynamic), name); + return error; +} + +static BOOL rdpsnd_set_subsystem(rdpsndPlugin* rdpsnd, const char* subsystem) +{ + free(rdpsnd->subsystem); + rdpsnd->subsystem = _strdup(subsystem); + return (rdpsnd->subsystem != NULL); +} + +static BOOL rdpsnd_set_device_name(rdpsndPlugin* rdpsnd, const char* device_name) +{ + free(rdpsnd->device_name); + rdpsnd->device_name = _strdup(device_name); + return (rdpsnd->device_name != NULL); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_process_addin_args(rdpsndPlugin* rdpsnd, const ADDIN_ARGV* args) +{ + int status = 0; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + COMMAND_LINE_ARGUMENT_A rdpsnd_args[] = { + { "sys", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "subsystem" }, + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "device" }, + { "format", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "format" }, + { "rate", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "rate" }, + { "channel", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "channel" }, + { "latency", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "latency" }, + { "quality", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, + "quality mode" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } + }; + rdpsnd->wQualityMode = HIGH_QUALITY; /* default quality mode */ + + if (args->argc > 1) + { + flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON; + status = CommandLineParseArgumentsA(args->argc, args->argv, rdpsnd_args, flags, rdpsnd, + NULL, NULL); + + if (status < 0) + return CHANNEL_RC_INITIALIZATION_ERROR; + + arg = rdpsnd_args; + errno = 0; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "sys") + { + if (!rdpsnd_set_subsystem(rdpsnd, arg->Value)) + return CHANNEL_RC_NO_MEMORY; + } + CommandLineSwitchCase(arg, "dev") + { + if (!rdpsnd_set_device_name(rdpsnd, arg->Value)) + return CHANNEL_RC_NO_MEMORY; + } + CommandLineSwitchCase(arg, "format") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val > UINT16_MAX)) + return CHANNEL_RC_INITIALIZATION_ERROR; + + rdpsnd->fixed_format->wFormatTag = (UINT16)val; + } + CommandLineSwitchCase(arg, "rate") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val > UINT32_MAX)) + return CHANNEL_RC_INITIALIZATION_ERROR; + + rdpsnd->fixed_format->nSamplesPerSec = (UINT32)val; + } + CommandLineSwitchCase(arg, "channel") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val > UINT16_MAX)) + return CHANNEL_RC_INITIALIZATION_ERROR; + + rdpsnd->fixed_format->nChannels = (UINT16)val; + } + CommandLineSwitchCase(arg, "latency") + { + unsigned long val = strtoul(arg->Value, NULL, 0); + + if ((errno != 0) || (val > UINT32_MAX)) + return CHANNEL_RC_INITIALIZATION_ERROR; + + rdpsnd->latency = (UINT32)val; + } + CommandLineSwitchCase(arg, "quality") + { + long wQualityMode = DYNAMIC_QUALITY; + + if (_stricmp(arg->Value, "dynamic") == 0) + wQualityMode = DYNAMIC_QUALITY; + else if (_stricmp(arg->Value, "medium") == 0) + wQualityMode = MEDIUM_QUALITY; + else if (_stricmp(arg->Value, "high") == 0) + wQualityMode = HIGH_QUALITY; + else + { + wQualityMode = strtol(arg->Value, NULL, 0); + + if (errno != 0) + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + if ((wQualityMode < 0) || (wQualityMode > 2)) + wQualityMode = DYNAMIC_QUALITY; + + rdpsnd->wQualityMode = (UINT16)wQualityMode; + } + CommandLineSwitchDefault(arg) + { + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_process_connect(rdpsndPlugin* rdpsnd) +{ + const struct + { + const char* subsystem; + const char* device; + } backends[] = { +#if defined(WITH_IOSAUDIO) + { "ios", "" }, +#endif +#if defined(WITH_OPENSLES) + { "opensles", "" }, +#endif +#if defined(WITH_PULSE) + { "pulse", "" }, +#endif +#if defined(WITH_ALSA) + { "alsa", "default" }, +#endif +#if defined(WITH_OSS) + { "oss", "" }, +#endif +#if defined(WITH_MACAUDIO) + { "mac", "default" }, +#endif +#if defined(WITH_WINMM) + { "winmm", "" }, +#endif +#if defined(WITH_SNDIO) + { "sndio", "" }, +#endif + { "fake", "" } + }; + const ADDIN_ARGV* args = NULL; + UINT status = ERROR_INTERNAL_ERROR; + WINPR_ASSERT(rdpsnd); + rdpsnd->latency = 0; + args = (const ADDIN_ARGV*)rdpsnd->channelEntryPoints.pExtendedData; + + if (args) + { + status = rdpsnd_process_addin_args(rdpsnd, args); + + if (status != CHANNEL_RC_OK) + return status; + } + + if (rdpsnd->subsystem) + { + if ((status = rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args))) + { + WLog_ERR(TAG, + "%s Unable to load sound playback subsystem %s because of error %" PRIu32 "", + rdpsnd_is_dyn_str(rdpsnd->dynamic), rdpsnd->subsystem, status); + return status; + } + } + else + { + for (size_t x = 0; x < ARRAYSIZE(backends); x++) + { + const char* subsystem_name = backends[x].subsystem; + const char* device_name = backends[x].device; + + if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args))) + WLog_ERR(TAG, + "%s Unable to load sound playback subsystem %s because of error %" PRIu32 + "", + rdpsnd_is_dyn_str(rdpsnd->dynamic), subsystem_name, status); + + if (!rdpsnd->device) + continue; + + if (!rdpsnd_set_subsystem(rdpsnd, subsystem_name) || + !rdpsnd_set_device_name(rdpsnd, device_name)) + return CHANNEL_RC_NO_MEMORY; + + break; + } + + if (!rdpsnd->device || status) + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpsnd_virtual_channel_write(rdpsndPlugin* rdpsnd, wStream* s) +{ + UINT status = CHANNEL_RC_BAD_INIT_HANDLE; + + if (rdpsnd) + { + if (rdpsnd->dynamic) + { + IWTSVirtualChannel* channel = NULL; + if (rdpsnd->listener_callback) + { + channel = rdpsnd->listener_callback->channel_callback->channel; + status = channel->Write(channel, (UINT32)Stream_Length(s), Stream_Buffer(s), NULL); + } + Stream_Free(s, TRUE); + } + else + { + status = rdpsnd->channelEntryPoints.pVirtualChannelWriteEx( + rdpsnd->InitHandle, rdpsnd->OpenHandle, Stream_Buffer(s), + (UINT32)Stream_GetPosition(s), s); + + if (status != CHANNEL_RC_OK) + { + Stream_Free(s, TRUE); + WLog_ERR(TAG, "%s pVirtualChannelWriteEx failed with %s [%08" PRIX32 "]", + rdpsnd_is_dyn_str(FALSE), WTSErrorToString(status), status); + } + } + } + + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_virtual_channel_event_data_received(rdpsndPlugin* plugin, void* pData, + UINT32 dataLength, UINT32 totalLength, + UINT32 dataFlags) +{ + if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) + return CHANNEL_RC_OK; + + if (dataFlags & CHANNEL_FLAG_FIRST) + { + if (!plugin->data_in) + plugin->data_in = StreamPool_Take(plugin->pool, totalLength); + + Stream_SetPosition(plugin->data_in, 0); + } + + if (!Stream_EnsureRemainingCapacity(plugin->data_in, dataLength)) + return CHANNEL_RC_NO_MEMORY; + + Stream_Write(plugin->data_in, pData, dataLength); + + if (dataFlags & CHANNEL_FLAG_LAST) + { + Stream_SealLength(plugin->data_in); + Stream_SetPosition(plugin->data_in, 0); + + if (plugin->async) + { + if (!MessageQueue_Post(plugin->queue, NULL, 0, plugin->data_in, NULL)) + return ERROR_INTERNAL_ERROR; + plugin->data_in = NULL; + } + else + { + UINT error = rdpsnd_recv_pdu(plugin, plugin->data_in); + plugin->data_in = NULL; + if (error) + return error; + } + } + + return CHANNEL_RC_OK; +} + +static VOID VCAPITYPE rdpsnd_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle, + UINT event, LPVOID pData, + UINT32 dataLength, UINT32 totalLength, + UINT32 dataFlags) +{ + UINT error = CHANNEL_RC_OK; + rdpsndPlugin* rdpsnd = (rdpsndPlugin*)lpUserParam; + WINPR_ASSERT(rdpsnd); + WINPR_ASSERT(!rdpsnd->dynamic); + + switch (event) + { + case CHANNEL_EVENT_DATA_RECEIVED: + if (!rdpsnd) + return; + + if (rdpsnd->OpenHandle != openHandle) + { + WLog_ERR(TAG, "%s error no match", rdpsnd_is_dyn_str(rdpsnd->dynamic)); + return; + } + if ((error = rdpsnd_virtual_channel_event_data_received(rdpsnd, pData, dataLength, + totalLength, dataFlags))) + WLog_ERR(TAG, + "%s rdpsnd_virtual_channel_event_data_received failed with error %" PRIu32 + "", + rdpsnd_is_dyn_str(rdpsnd->dynamic), error); + + break; + + case CHANNEL_EVENT_WRITE_CANCELLED: + case CHANNEL_EVENT_WRITE_COMPLETE: + { + wStream* s = (wStream*)pData; + Stream_Free(s, TRUE); + } + break; + + case CHANNEL_EVENT_USER: + break; + default: + break; + } + + if (error && rdpsnd && rdpsnd->rdpcontext) + { + char buffer[8192]; + (void)_snprintf(buffer, sizeof(buffer), + "%s rdpsnd_virtual_channel_open_event_ex reported an error", + rdpsnd_is_dyn_str(rdpsnd->dynamic)); + setChannelError(rdpsnd->rdpcontext, error, buffer); + } +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_virtual_channel_event_connected(rdpsndPlugin* rdpsnd, LPVOID pData, + UINT32 dataLength) +{ + UINT32 status = 0; + DWORD opened = 0; + WINPR_UNUSED(pData); + WINPR_UNUSED(dataLength); + + WINPR_ASSERT(rdpsnd); + WINPR_ASSERT(!rdpsnd->dynamic); + + status = rdpsnd->channelEntryPoints.pVirtualChannelOpenEx( + rdpsnd->InitHandle, &opened, rdpsnd->channelDef.name, rdpsnd_virtual_channel_open_event_ex); + + if (status != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "%s pVirtualChannelOpenEx failed with %s [%08" PRIX32 "]", + rdpsnd_is_dyn_str(rdpsnd->dynamic), WTSErrorToString(status), status); + goto fail; + } + + if (rdpsnd_process_connect(rdpsnd) != CHANNEL_RC_OK) + goto fail; + + rdpsnd->OpenHandle = opened; + return CHANNEL_RC_OK; +fail: + if (opened != 0) + rdpsnd->channelEntryPoints.pVirtualChannelCloseEx(rdpsnd->InitHandle, opened); + return CHANNEL_RC_NO_MEMORY; +} + +static void cleanup_internals(rdpsndPlugin* rdpsnd) +{ + if (!rdpsnd) + return; + + if (rdpsnd->pool) + StreamPool_Return(rdpsnd->pool, rdpsnd->data_in); + + audio_formats_free(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats); + audio_formats_free(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats); + + rdpsnd->NumberOfClientFormats = 0; + rdpsnd->ClientFormats = NULL; + rdpsnd->NumberOfServerFormats = 0; + rdpsnd->ServerFormats = NULL; + + rdpsnd->data_in = NULL; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_virtual_channel_event_disconnected(rdpsndPlugin* rdpsnd) +{ + UINT error = 0; + + WINPR_ASSERT(rdpsnd); + WINPR_ASSERT(!rdpsnd->dynamic); + if (rdpsnd->OpenHandle != 0) + { + DWORD opened = rdpsnd->OpenHandle; + rdpsnd->OpenHandle = 0; + if (rdpsnd->device) + IFCALL(rdpsnd->device->Close, rdpsnd->device); + + error = rdpsnd->channelEntryPoints.pVirtualChannelCloseEx(rdpsnd->InitHandle, opened); + + if (CHANNEL_RC_OK != error) + { + WLog_ERR(TAG, "%s pVirtualChannelCloseEx failed with %s [%08" PRIX32 "]", + rdpsnd_is_dyn_str(rdpsnd->dynamic), WTSErrorToString(error), error); + return error; + } + } + + cleanup_internals(rdpsnd); + + if (rdpsnd->device) + { + IFCALL(rdpsnd->device->Free, rdpsnd->device); + rdpsnd->device = NULL; + } + + return CHANNEL_RC_OK; +} + +static void queue_free(void* obj) +{ + wMessage* msg = obj; + if (!msg) + return; + if (msg->id != 0) + return; + wStream* s = msg->wParam; + Stream_Release(s); +} + +static void free_internals(rdpsndPlugin* rdpsnd) +{ + if (!rdpsnd) + return; + + if (rdpsnd->references > 0) + rdpsnd->references--; + + if (rdpsnd->references > 0) + return; + + freerdp_dsp_context_free(rdpsnd->dsp_context); + StreamPool_Free(rdpsnd->pool); + rdpsnd->pool = NULL; + rdpsnd->dsp_context = NULL; +} + +static BOOL allocate_internals(rdpsndPlugin* rdpsnd) +{ + WINPR_ASSERT(rdpsnd); + + if (!rdpsnd->pool) + { + rdpsnd->pool = StreamPool_New(TRUE, 4096); + if (!rdpsnd->pool) + return FALSE; + } + + if (!rdpsnd->dsp_context) + { + rdpsnd->dsp_context = freerdp_dsp_context_new(FALSE); + if (!rdpsnd->dsp_context) + return FALSE; + } + rdpsnd->references++; + + return TRUE; +} + +static DWORD WINAPI play_thread(LPVOID arg) +{ + UINT error = CHANNEL_RC_OK; + rdpsndPlugin* rdpsnd = arg; + + if (!rdpsnd || !rdpsnd->queue) + return ERROR_INVALID_PARAMETER; + + while (TRUE) + { + int rc = -1; + wMessage message = { 0 }; + wStream* s = NULL; + DWORD status = 0; + DWORD nCount = 0; + HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 }; + + handles[nCount++] = MessageQueue_Event(rdpsnd->queue); + handles[nCount++] = freerdp_abort_event(rdpsnd->rdpcontext); + status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE); + switch (status) + { + case WAIT_OBJECT_0: + break; + default: + return ERROR_TIMEOUT; + } + + rc = MessageQueue_Peek(rdpsnd->queue, &message, TRUE); + if (rc < 1) + continue; + + if (message.id == WMQ_QUIT) + break; + + s = message.wParam; + error = rdpsnd_recv_pdu(rdpsnd, s); + + if (error) + return error; + } + + return CHANNEL_RC_OK; +} + +static UINT rdpsnd_virtual_channel_event_initialized(rdpsndPlugin* rdpsnd) +{ + if (!rdpsnd) + return ERROR_INVALID_PARAMETER; + + if (rdpsnd->async) + { + wObject obj = { 0 }; + + obj.fnObjectFree = queue_free; + rdpsnd->queue = MessageQueue_New(&obj); + if (!rdpsnd->queue) + return CHANNEL_RC_NO_MEMORY; + + rdpsnd->thread = CreateThread(NULL, 0, play_thread, rdpsnd, 0, NULL); + if (!rdpsnd->thread) + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + if (!allocate_internals(rdpsnd)) + return CHANNEL_RC_NO_MEMORY; + + return CHANNEL_RC_OK; +} + +void rdpsnd_virtual_channel_event_terminated(rdpsndPlugin* rdpsnd) +{ + if (rdpsnd) + { + if (rdpsnd->queue) + MessageQueue_PostQuit(rdpsnd->queue, 0); + + if (rdpsnd->thread) + { + (void)WaitForSingleObject(rdpsnd->thread, INFINITE); + (void)CloseHandle(rdpsnd->thread); + } + MessageQueue_Free(rdpsnd->queue); + + free_internals(rdpsnd); + audio_formats_free(rdpsnd->fixed_format, 1); + free(rdpsnd->subsystem); + free(rdpsnd->device_name); + rdpsnd->InitHandle = 0; + } + + free(rdpsnd); +} + +static VOID VCAPITYPE rdpsnd_virtual_channel_init_event_ex(LPVOID lpUserParam, LPVOID pInitHandle, + UINT event, LPVOID pData, + UINT dataLength) +{ + UINT error = CHANNEL_RC_OK; + rdpsndPlugin* plugin = (rdpsndPlugin*)lpUserParam; + + if (!plugin) + return; + + if (plugin->InitHandle != pInitHandle) + { + WLog_ERR(TAG, "%s error no match", rdpsnd_is_dyn_str(plugin->dynamic)); + return; + } + + switch (event) + { + case CHANNEL_EVENT_INITIALIZED: + error = rdpsnd_virtual_channel_event_initialized(plugin); + break; + + case CHANNEL_EVENT_CONNECTED: + error = rdpsnd_virtual_channel_event_connected(plugin, pData, dataLength); + break; + + case CHANNEL_EVENT_DISCONNECTED: + error = rdpsnd_virtual_channel_event_disconnected(plugin); + break; + + case CHANNEL_EVENT_TERMINATED: + rdpsnd_virtual_channel_event_terminated(plugin); + plugin = NULL; + break; + + case CHANNEL_EVENT_ATTACHED: + plugin->attached = TRUE; + break; + + case CHANNEL_EVENT_DETACHED: + plugin->attached = FALSE; + break; + + default: + break; + } + + if (error && plugin && plugin->rdpcontext) + { + char buffer[8192]; + (void)_snprintf(buffer, sizeof(buffer), "%s reported an error", + rdpsnd_is_dyn_str(plugin->dynamic)); + setChannelError(plugin->rdpcontext, error, buffer); + } +} + +rdpContext* freerdp_rdpsnd_get_context(rdpsndPlugin* plugin) +{ + if (!plugin) + return NULL; + + return plugin->rdpcontext; +} + +static rdpsndPlugin* allocatePlugin(void) +{ + rdpsndPlugin* rdpsnd = (rdpsndPlugin*)calloc(1, sizeof(rdpsndPlugin)); + if (!rdpsnd) + goto fail; + + rdpsnd->fixed_format = audio_format_new(); + if (!rdpsnd->fixed_format) + goto fail; + rdpsnd->log = WLog_Get("com.freerdp.channels.rdpsnd.client"); + if (!rdpsnd->log) + goto fail; + + rdpsnd->attached = TRUE; + return rdpsnd; + +fail: + if (rdpsnd) + audio_formats_free(rdpsnd->fixed_format, 1); + free(rdpsnd); + return NULL; +} +/* rdpsnd is always built-in */ +FREERDP_ENTRY_POINT(BOOL VCAPITYPE rdpsnd_VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, + PVOID pInitHandle)) +{ + UINT rc = 0; + rdpsndPlugin* rdpsnd = NULL; + CHANNEL_ENTRY_POINTS_FREERDP_EX* pEntryPointsEx = NULL; + + if (!pEntryPoints) + return FALSE; + + rdpsnd = allocatePlugin(); + + if (!rdpsnd) + return FALSE; + + rdpsnd->channelDef.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP; + (void)sprintf_s(rdpsnd->channelDef.name, ARRAYSIZE(rdpsnd->channelDef.name), + RDPSND_CHANNEL_NAME); + pEntryPointsEx = (CHANNEL_ENTRY_POINTS_FREERDP_EX*)pEntryPoints; + + if ((pEntryPointsEx->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)) && + (pEntryPointsEx->MagicNumber == FREERDP_CHANNEL_MAGIC_NUMBER)) + { + rdpsnd->rdpcontext = pEntryPointsEx->context; + if (!freerdp_settings_get_bool(rdpsnd->rdpcontext->settings, + FreeRDP_SynchronousStaticChannels)) + rdpsnd->async = TRUE; + } + + CopyMemory(&(rdpsnd->channelEntryPoints), pEntryPoints, + sizeof(CHANNEL_ENTRY_POINTS_FREERDP_EX)); + rdpsnd->InitHandle = pInitHandle; + + WINPR_ASSERT(rdpsnd->channelEntryPoints.pVirtualChannelInitEx); + rc = rdpsnd->channelEntryPoints.pVirtualChannelInitEx( + rdpsnd, NULL, pInitHandle, &rdpsnd->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, + rdpsnd_virtual_channel_init_event_ex); + + if (CHANNEL_RC_OK != rc) + { + WLog_ERR(TAG, "%s pVirtualChannelInitEx failed with %s [%08" PRIX32 "]", + rdpsnd_is_dyn_str(FALSE), WTSErrorToString(rc), rc); + rdpsnd_virtual_channel_event_terminated(rdpsnd); + return FALSE; + } + + return TRUE; +} + +static UINT rdpsnd_on_open(IWTSVirtualChannelCallback* pChannelCallback) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + rdpsndPlugin* rdpsnd = NULL; + + WINPR_ASSERT(callback); + + rdpsnd = (rdpsndPlugin*)callback->plugin; + WINPR_ASSERT(rdpsnd); + + if (rdpsnd->OnOpenCalled) + return CHANNEL_RC_OK; + rdpsnd->OnOpenCalled = TRUE; + + if (!allocate_internals(rdpsnd)) + return ERROR_OUTOFMEMORY; + + return rdpsnd_process_connect(rdpsnd); +} + +static UINT rdpsnd_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + rdpsndPlugin* plugin = NULL; + wStream* copy = NULL; + size_t len = 0; + + len = Stream_GetRemainingLength(data); + + if (!callback || !callback->plugin) + return ERROR_INVALID_PARAMETER; + plugin = (rdpsndPlugin*)callback->plugin; + WINPR_ASSERT(plugin); + + copy = StreamPool_Take(plugin->pool, len); + if (!copy) + return ERROR_OUTOFMEMORY; + Stream_Copy(data, copy, len); + Stream_SealLength(copy); + Stream_SetPosition(copy, 0); + + if (plugin->async) + { + if (!MessageQueue_Post(plugin->queue, NULL, 0, copy, NULL)) + { + Stream_Release(copy); + return ERROR_INTERNAL_ERROR; + } + } + else + { + UINT error = rdpsnd_recv_pdu(plugin, copy); + if (error) + return error; + } + + return CHANNEL_RC_OK; +} + +static UINT rdpsnd_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + rdpsndPlugin* rdpsnd = NULL; + + WINPR_ASSERT(callback); + + rdpsnd = (rdpsndPlugin*)callback->plugin; + WINPR_ASSERT(rdpsnd); + + rdpsnd->OnOpenCalled = FALSE; + if (rdpsnd->device) + IFCALL(rdpsnd->device->Close, rdpsnd->device); + + cleanup_internals(rdpsnd); + + if (rdpsnd->device) + { + IFCALL(rdpsnd->device->Free, rdpsnd->device); + rdpsnd->device = NULL; + } + + free_internals(rdpsnd); + free(pChannelCallback); + return CHANNEL_RC_OK; +} + +// NOLINTBEGIN(readability-non-const-parameter) +static UINT rdpsnd_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, + IWTSVirtualChannel* pChannel, BYTE* Data, + BOOL* pbAccept, + IWTSVirtualChannelCallback** ppCallback) +// NOLINTEND(readability-non-const-parameter) +{ + GENERIC_CHANNEL_CALLBACK* callback = NULL; + GENERIC_LISTENER_CALLBACK* listener_callback = (GENERIC_LISTENER_CALLBACK*)pListenerCallback; + WINPR_ASSERT(listener_callback); + WINPR_ASSERT(pChannel); + WINPR_ASSERT(ppCallback); + callback = (GENERIC_CHANNEL_CALLBACK*)calloc(1, sizeof(GENERIC_CHANNEL_CALLBACK)); + + WINPR_UNUSED(Data); + WINPR_UNUSED(pbAccept); + + if (!callback) + { + WLog_ERR(TAG, "%s calloc failed!", rdpsnd_is_dyn_str(TRUE)); + return CHANNEL_RC_NO_MEMORY; + } + + callback->iface.OnOpen = rdpsnd_on_open; + callback->iface.OnDataReceived = rdpsnd_on_data_received; + callback->iface.OnClose = rdpsnd_on_close; + callback->plugin = listener_callback->plugin; + callback->channel_mgr = listener_callback->channel_mgr; + callback->channel = pChannel; + listener_callback->channel_callback = callback; + *ppCallback = &callback->iface; + return CHANNEL_RC_OK; +} + +static UINT rdpsnd_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr) +{ + UINT status = 0; + rdpsndPlugin* rdpsnd = (rdpsndPlugin*)pPlugin; + WINPR_ASSERT(rdpsnd); + WINPR_ASSERT(pChannelMgr); + if (rdpsnd->initialized) + { + WLog_ERR(TAG, "[%s] channel initialized twice, aborting", RDPSND_DVC_CHANNEL_NAME); + return ERROR_INVALID_DATA; + } + rdpsnd->listener_callback = + (GENERIC_LISTENER_CALLBACK*)calloc(1, sizeof(GENERIC_LISTENER_CALLBACK)); + + if (!rdpsnd->listener_callback) + { + WLog_ERR(TAG, "%s calloc failed!", rdpsnd_is_dyn_str(TRUE)); + return CHANNEL_RC_NO_MEMORY; + } + + rdpsnd->listener_callback->iface.OnNewChannelConnection = rdpsnd_on_new_channel_connection; + rdpsnd->listener_callback->plugin = pPlugin; + rdpsnd->listener_callback->channel_mgr = pChannelMgr; + status = pChannelMgr->CreateListener(pChannelMgr, RDPSND_DVC_CHANNEL_NAME, 0, + &rdpsnd->listener_callback->iface, &(rdpsnd->listener)); + if (status != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "%s CreateListener failed!", rdpsnd_is_dyn_str(TRUE)); + return status; + } + + rdpsnd->listener->pInterface = rdpsnd->iface.pInterface; + status = rdpsnd_virtual_channel_event_initialized(rdpsnd); + + rdpsnd->initialized = status == CHANNEL_RC_OK; + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_plugin_terminated(IWTSPlugin* pPlugin) +{ + rdpsndPlugin* rdpsnd = (rdpsndPlugin*)pPlugin; + if (rdpsnd) + { + if (rdpsnd->listener_callback) + { + IWTSVirtualChannelManager* mgr = rdpsnd->listener_callback->channel_mgr; + if (mgr) + IFCALL(mgr->DestroyListener, mgr, rdpsnd->listener); + } + free(rdpsnd->listener_callback); + free(rdpsnd->iface.pInterface); + } + rdpsnd_virtual_channel_event_terminated(rdpsnd); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE rdpsnd_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + UINT error = CHANNEL_RC_OK; + rdpsndPlugin* rdpsnd = NULL; + + WINPR_ASSERT(pEntryPoints); + WINPR_ASSERT(pEntryPoints->GetPlugin); + + rdpsnd = (rdpsndPlugin*)pEntryPoints->GetPlugin(pEntryPoints, RDPSND_CHANNEL_NAME); + + if (!rdpsnd) + { + IWTSPlugin* iface = NULL; + union + { + const void* cev; + void* ev; + } cnv; + + rdpsnd = allocatePlugin(); + if (!rdpsnd) + { + WLog_ERR(TAG, "%s calloc failed!", rdpsnd_is_dyn_str(TRUE)); + return CHANNEL_RC_NO_MEMORY; + } + + iface = &rdpsnd->iface; + iface->Initialize = rdpsnd_plugin_initialize; + iface->Connected = NULL; + iface->Disconnected = NULL; + iface->Terminated = rdpsnd_plugin_terminated; + + rdpsnd->dynamic = TRUE; + + WINPR_ASSERT(pEntryPoints->GetRdpContext); + rdpsnd->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); + + if (!freerdp_settings_get_bool(rdpsnd->rdpcontext->settings, + FreeRDP_SynchronousDynamicChannels)) + rdpsnd->async = TRUE; + + /* user data pointer is not const, cast to avoid warning. */ + cnv.cev = pEntryPoints->GetPluginData(pEntryPoints); + WINPR_ASSERT(pEntryPoints->GetPluginData); + rdpsnd->channelEntryPoints.pExtendedData = cnv.ev; + + error = pEntryPoints->RegisterPlugin(pEntryPoints, RDPSND_CHANNEL_NAME, iface); + } + else + { + WLog_ERR(TAG, "%s could not get rdpsnd Plugin.", rdpsnd_is_dyn_str(TRUE)); + return CHANNEL_RC_BAD_CHANNEL; + } + + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/sndio/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/sndio/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ba42fa194d702dcb4cbf7d653a45ff53c7b90fd8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/sndio/CMakeLists.txt @@ -0,0 +1,30 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Rozhuk Ivan +# Copyright (c) 2020 Ingo Feinerer +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "sndio" "") + +find_package(SNDIO REQUIRED) + +set(${MODULE_PREFIX}_SRCS rdpsnd_sndio.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${SNDIO_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${SNDIO_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/sndio/rdpsnd_sndio.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/sndio/rdpsnd_sndio.c new file mode 100644 index 0000000000000000000000000000000000000000..541c6f7b5420fbfeb6c668f9850efd766ae50d31 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/sndio/rdpsnd_sndio.c @@ -0,0 +1,217 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2019 Armin Novak + * Copyright 2019 Thincast Technologies GmbH + * Copyright 2020 Ingo Feinerer + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; + + struct sio_hdl* hdl; + struct sio_par par; +} rdpsndSndioPlugin; + +static BOOL rdpsnd_sndio_open(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, int latency) +{ + rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device; + + if (device == NULL || format == NULL) + return FALSE; + + if (sndio->hdl != NULL) + return TRUE; + + sndio->hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0); + if (sndio->hdl == NULL) + { + WLog_ERR(TAG, "could not open audio device"); + return FALSE; + } + + sio_initpar(&sndio->par); + sndio->par.bits = format->wBitsPerSample; + sndio->par.pchan = format->nChannels; + sndio->par.rate = format->nSamplesPerSec; + if (!sio_setpar(sndio->hdl, &sndio->par)) + { + WLog_ERR(TAG, "could not set audio parameters"); + return FALSE; + } + if (!sio_getpar(sndio->hdl, &sndio->par)) + { + WLog_ERR(TAG, "could not get audio parameters"); + return FALSE; + } + + if (!sio_start(sndio->hdl)) + { + WLog_ERR(TAG, "could not start audio device"); + return FALSE; + } + + return TRUE; +} + +static void rdpsnd_sndio_close(rdpsndDevicePlugin* device) +{ + rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device; + + if (device == NULL) + return; + + if (sndio->hdl != NULL) + { + sio_stop(sndio->hdl); + sio_close(sndio->hdl); + sndio->hdl = NULL; + } +} + +static BOOL rdpsnd_sndio_set_volume(rdpsndDevicePlugin* device, UINT32 value) +{ + rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device; + + if (device == NULL || sndio->hdl == NULL) + return FALSE; + + /* + * Low-order word contains the left-channel volume setting. + * We ignore the right-channel volume setting in the high-order word. + */ + return sio_setvol(sndio->hdl, ((value & 0xFFFF) * SIO_MAXVOL) / 0xFFFF); +} + +static void rdpsnd_sndio_free(rdpsndDevicePlugin* device) +{ + rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device; + + if (device == NULL) + return; + + rdpsnd_sndio_close(device); + free(sndio); +} + +static BOOL rdpsnd_sndio_format_supported(rdpsndDevicePlugin* device, AUDIO_FORMAT* format) +{ + if (format == NULL) + return FALSE; + + return (format->wFormatTag == WAVE_FORMAT_PCM); +} + +static void rdpsnd_sndio_play(rdpsndDevicePlugin* device, BYTE* data, int size) +{ + rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device; + + if (device == NULL || sndio->hdl == NULL) + return; + + sio_write(sndio->hdl, data, size); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_sndio_parse_addin_args(rdpsndDevicePlugin* device, ADDIN_ARGV* args) +{ + int status; + DWORD flags; + COMMAND_LINE_ARGUMENT_A* arg; + rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device; + COMMAND_LINE_ARGUMENT_A rdpsnd_sndio_args[] = { { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, rdpsnd_sndio_args, + flags, sndio, NULL, NULL); + + if (status < 0) + return ERROR_INVALID_DATA; + + arg = rdpsnd_sndio_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE sndio_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + ADDIN_ARGV* args; + rdpsndSndioPlugin* sndio; + UINT ret = CHANNEL_RC_OK; + sndio = (rdpsndSndioPlugin*)calloc(1, sizeof(rdpsndSndioPlugin)); + + if (sndio == NULL) + return CHANNEL_RC_NO_MEMORY; + + sndio->device.Open = rdpsnd_sndio_open; + sndio->device.FormatSupported = rdpsnd_sndio_format_supported; + sndio->device.SetVolume = rdpsnd_sndio_set_volume; + sndio->device.Play = rdpsnd_sndio_play; + sndio->device.Close = rdpsnd_sndio_close; + sndio->device.Free = rdpsnd_sndio_free; + args = pEntryPoints->args; + + if (args->argc > 1) + { + ret = rdpsnd_sndio_parse_addin_args((rdpsndDevicePlugin*)sndio, args); + + if (ret != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "error parsing arguments"); + goto error; + } + } + + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &sndio->device); + return ret; +error: + rdpsnd_sndio_free(&sndio->device); + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/winmm/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/winmm/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..a58138e153d3f3ac6cb4547b8c61f68abcbd1b57 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/winmm/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("rdpsnd" "winmm" "") + +set(${MODULE_PREFIX}_SRCS rdpsnd_winmm.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp winmm.lib) + +include_directories(..) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/winmm/rdpsnd_winmm.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/winmm/rdpsnd_winmm.c new file mode 100644 index 0000000000000000000000000000000000000000..fd4c471b2be4bc40cfc5d5754115721073bb7d0b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/client/winmm/rdpsnd_winmm.c @@ -0,0 +1,348 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2009-2012 Jay Sorg + * Copyright 2010-2012 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 David PHAM-VAN + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "rdpsnd_main.h" + +typedef struct +{ + rdpsndDevicePlugin device; + + HWAVEOUT hWaveOut; + WAVEFORMATEX format; + UINT32 volume; + wLog* log; + UINT32 latency; + HANDLE hThread; + DWORD threadId; + CRITICAL_SECTION cs; +} rdpsndWinmmPlugin; + +static BOOL rdpsnd_winmm_convert_format(const AUDIO_FORMAT* in, WAVEFORMATEX* out) +{ + if (!in || !out) + return FALSE; + + ZeroMemory(out, sizeof(WAVEFORMATEX)); + out->wFormatTag = WAVE_FORMAT_PCM; + out->nChannels = in->nChannels; + out->nSamplesPerSec = in->nSamplesPerSec; + + switch (in->wFormatTag) + { + case WAVE_FORMAT_PCM: + out->wBitsPerSample = in->wBitsPerSample; + break; + + default: + return FALSE; + } + + out->nBlockAlign = out->nChannels * out->wBitsPerSample / 8; + out->nAvgBytesPerSec = out->nSamplesPerSec * out->nBlockAlign; + return TRUE; +} + +static BOOL rdpsnd_winmm_set_format(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 latency) +{ + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)device; + + winmm->latency = latency; + if (!rdpsnd_winmm_convert_format(format, &winmm->format)) + return FALSE; + + return TRUE; +} + +static DWORD WINAPI waveOutProc(LPVOID lpParameter) +{ + MSG msg; + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)lpParameter; + while (GetMessage(&msg, NULL, 0, 0)) + { + if (msg.message == MM_WOM_CLOSE) + { + /* device was closed - exit thread */ + break; + } + else if (msg.message == MM_WOM_DONE) + { + /* free buffer */ + LPWAVEHDR waveHdr = (LPWAVEHDR)msg.lParam; + EnterCriticalSection(&winmm->cs); + waveOutUnprepareHeader((HWAVEOUT)msg.wParam, waveHdr, sizeof(WAVEHDR)); + LeaveCriticalSection(&winmm->cs); + free(waveHdr->lpData); + free(waveHdr); + } + } + + return 0; +} + +static BOOL rdpsnd_winmm_open(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + UINT32 latency) +{ + MMRESULT mmResult; + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)device; + + if (winmm->hWaveOut) + return TRUE; + + if (!rdpsnd_winmm_set_format(device, format, latency)) + return FALSE; + + winmm->hThread = CreateThread(NULL, 0, waveOutProc, winmm, 0, &winmm->threadId); + if (!winmm->hThread) + { + WLog_Print(winmm->log, WLOG_ERROR, "CreateThread failed: %" PRIu32 "", GetLastError()); + return FALSE; + } + + mmResult = waveOutOpen(&winmm->hWaveOut, WAVE_MAPPER, &winmm->format, + (DWORD_PTR)winmm->threadId, 0, CALLBACK_THREAD); + + if (mmResult != MMSYSERR_NOERROR) + { + WLog_Print(winmm->log, WLOG_ERROR, "waveOutOpen failed: %" PRIu32 "", mmResult); + return FALSE; + } + + mmResult = waveOutSetVolume(winmm->hWaveOut, winmm->volume); + + if (mmResult != MMSYSERR_NOERROR) + { + WLog_Print(winmm->log, WLOG_ERROR, "waveOutSetVolume failed: %" PRIu32 "", mmResult); + return FALSE; + } + + return TRUE; +} + +static void rdpsnd_winmm_close(rdpsndDevicePlugin* device) +{ + MMRESULT mmResult; + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)device; + + if (winmm->hWaveOut) + { + EnterCriticalSection(&winmm->cs); + + mmResult = waveOutReset(winmm->hWaveOut); + if (mmResult != MMSYSERR_NOERROR) + WLog_Print(winmm->log, WLOG_ERROR, "waveOutReset failure: %" PRIu32 "", mmResult); + + mmResult = waveOutClose(winmm->hWaveOut); + if (mmResult != MMSYSERR_NOERROR) + WLog_Print(winmm->log, WLOG_ERROR, "waveOutClose failure: %" PRIu32 "", mmResult); + + LeaveCriticalSection(&winmm->cs); + + winmm->hWaveOut = NULL; + } + + if (winmm->hThread) + { + (void)WaitForSingleObject(winmm->hThread, INFINITE); + (void)CloseHandle(winmm->hThread); + winmm->hThread = NULL; + } +} + +static void rdpsnd_winmm_free(rdpsndDevicePlugin* device) +{ + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)device; + + if (winmm) + { + rdpsnd_winmm_close(device); + DeleteCriticalSection(&winmm->cs); + free(winmm); + } +} + +static BOOL rdpsnd_winmm_format_supported(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format) +{ + MMRESULT result; + WAVEFORMATEX out; + + WINPR_UNUSED(device); + if (rdpsnd_winmm_convert_format(format, &out)) + { + result = waveOutOpen(NULL, WAVE_MAPPER, &out, 0, 0, WAVE_FORMAT_QUERY); + + if (result == MMSYSERR_NOERROR) + return TRUE; + } + + return FALSE; +} + +static UINT32 rdpsnd_winmm_get_volume(rdpsndDevicePlugin* device) +{ + MMRESULT mmResult; + DWORD dwVolume = UINT32_MAX; + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)device; + + if (!winmm->hWaveOut) + return dwVolume; + + mmResult = waveOutGetVolume(winmm->hWaveOut, &dwVolume); + if (mmResult != MMSYSERR_NOERROR) + { + WLog_Print(winmm->log, WLOG_ERROR, "waveOutGetVolume failure: %" PRIu32 "", mmResult); + dwVolume = UINT32_MAX; + } + return dwVolume; +} + +static BOOL rdpsnd_winmm_set_volume(rdpsndDevicePlugin* device, UINT32 value) +{ + MMRESULT mmResult; + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)device; + winmm->volume = value; + + if (!winmm->hWaveOut) + return TRUE; + + mmResult = waveOutSetVolume(winmm->hWaveOut, value); + if (mmResult != MMSYSERR_NOERROR) + { + WLog_Print(winmm->log, WLOG_ERROR, "waveOutGetVolume failure: %" PRIu32 "", mmResult); + return FALSE; + } + return TRUE; +} + +static UINT rdpsnd_winmm_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) +{ + MMRESULT mmResult; + LPWAVEHDR lpWaveHdr; + rdpsndWinmmPlugin* winmm = (rdpsndWinmmPlugin*)device; + + if (!winmm->hWaveOut) + return 0; + + if (size > UINT32_MAX) + return 0; + + lpWaveHdr = (LPWAVEHDR)calloc(1, sizeof(WAVEHDR)); + if (!lpWaveHdr) + return 0; + + lpWaveHdr->dwFlags = 0; + lpWaveHdr->dwLoops = 0; + lpWaveHdr->lpData = malloc(size); + if (!lpWaveHdr->lpData) + goto fail; + memcpy(lpWaveHdr->lpData, data, size); + lpWaveHdr->dwBufferLength = (DWORD)size; + + EnterCriticalSection(&winmm->cs); + + mmResult = waveOutPrepareHeader(winmm->hWaveOut, lpWaveHdr, sizeof(WAVEHDR)); + if (mmResult != MMSYSERR_NOERROR) + { + WLog_Print(winmm->log, WLOG_ERROR, "waveOutPrepareHeader failure: %" PRIu32 "", mmResult); + goto failCS; + } + + mmResult = waveOutWrite(winmm->hWaveOut, lpWaveHdr, sizeof(WAVEHDR)); + if (mmResult != MMSYSERR_NOERROR) + { + WLog_Print(winmm->log, WLOG_ERROR, "waveOutWrite failure: %" PRIu32 "", mmResult); + waveOutUnprepareHeader(winmm->hWaveOut, lpWaveHdr, sizeof(WAVEHDR)); + goto failCS; + } + + LeaveCriticalSection(&winmm->cs); + return winmm->latency; +failCS: + LeaveCriticalSection(&winmm->cs); +fail: + if (lpWaveHdr) + free(lpWaveHdr->lpData); + free(lpWaveHdr); + return 0; +} + +static void rdpsnd_winmm_parse_addin_args(rdpsndDevicePlugin* device, const ADDIN_ARGV* args) +{ + WINPR_UNUSED(device); + WINPR_UNUSED(args); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE winmm_freerdp_rdpsnd_client_subsystem_entry( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)) +{ + const ADDIN_ARGV* args; + rdpsndWinmmPlugin* winmm; + + if (waveOutGetNumDevs() == 0) + { + WLog_Print(WLog_Get(TAG), WLOG_ERROR, "No sound playback device available!"); + return ERROR_DEVICE_NOT_AVAILABLE; + } + + winmm = (rdpsndWinmmPlugin*)calloc(1, sizeof(rdpsndWinmmPlugin)); + if (!winmm) + return CHANNEL_RC_NO_MEMORY; + + winmm->device.Open = rdpsnd_winmm_open; + winmm->device.FormatSupported = rdpsnd_winmm_format_supported; + winmm->device.GetVolume = rdpsnd_winmm_get_volume; + winmm->device.SetVolume = rdpsnd_winmm_set_volume; + winmm->device.Play = rdpsnd_winmm_play; + winmm->device.Close = rdpsnd_winmm_close; + winmm->device.Free = rdpsnd_winmm_free; + winmm->log = WLog_Get(TAG); + InitializeCriticalSection(&winmm->cs); + + args = pEntryPoints->args; + rdpsnd_winmm_parse_addin_args(&winmm->device, args); + winmm->volume = 0xFFFFFFFF; + pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)winmm); + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/common/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/common/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..08a9e91d7ac1b7467f205a5d3023afe371d0893f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/common/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2018 Armin Novak +# Copyright 2018 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(SRCS rdpsnd_common.h rdpsnd_common.c) + +# Library currently header only +add_library(rdpsnd-common STATIC ${SRCS}) + +channel_install(rdpsnd-common ${FREERDP_ADDIN_PATH} "FreeRDPTargets") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/common/rdpsnd_common.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/common/rdpsnd_common.h new file mode 100644 index 0000000000000000000000000000000000000000..6afcbc749203dcebe1cd7b4862b730bb4015ad2a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/common/rdpsnd_common.h @@ -0,0 +1,43 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Audio Virtual Channel + * + * Copyright 2018 Armin Novak + * Copyright 2018 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPSND_COMMON_MAIN_H +#define FREERDP_CHANNEL_RDPSND_COMMON_MAIN_H + +#include +#include +#include + +#include +#include +#include +#include + +typedef enum +{ + CHANNEL_VERSION_WIN_XP = 0x02, + CHANNEL_VERSION_WIN_XP_SP1 = 0x05, + CHANNEL_VERSION_WIN_VISTA = 0x05, + CHANNEL_VERSION_WIN_7 = 0x06, + CHANNEL_VERSION_WIN_8 = 0x08, + CHANNEL_VERSION_WIN_MAX = CHANNEL_VERSION_WIN_8 +} RdpSndChannelVersion; + +#endif /* FREERDP_CHANNEL_RDPSND_COMMON_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/server/rdpsnd_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/server/rdpsnd_main.c new file mode 100644 index 0000000000000000000000000000000000000000..93091c1e959a34d4e39bc212cdb2d26c0f7196ec --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/server/rdpsnd_main.c @@ -0,0 +1,1249 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Audio Virtual Channel + * + * Copyright 2012 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "rdpsnd_common.h" +#include "rdpsnd_main.h" + +static wStream* rdpsnd_server_get_buffer(RdpsndServerContext* context) +{ + wStream* s = NULL; + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + s = context->priv->rdpsnd_pdu; + Stream_SetPosition(s, 0); + return s; +} + +/** + * Send Server Audio Formats and Version PDU (2.2.2.1) + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_send_formats(RdpsndServerContext* context) +{ + wStream* s = rdpsnd_server_get_buffer(context); + BOOL status = FALSE; + ULONG written = 0; + + if (!Stream_EnsureRemainingCapacity(s, 24)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT8(s, SNDC_FORMATS); + Stream_Write_UINT8(s, 0); + Stream_Seek_UINT16(s); + Stream_Write_UINT32(s, 0); /* dwFlags */ + Stream_Write_UINT32(s, 0); /* dwVolume */ + Stream_Write_UINT32(s, 0); /* dwPitch */ + Stream_Write_UINT16(s, 0); /* wDGramPort */ + Stream_Write_UINT16( + s, WINPR_ASSERTING_INT_CAST(uint16_t, context->num_server_formats)); /* wNumberOfFormats */ + Stream_Write_UINT8(s, context->block_no); /* cLastBlockConfirmed */ + Stream_Write_UINT16(s, CHANNEL_VERSION_WIN_MAX); /* wVersion */ + Stream_Write_UINT8(s, 0); /* bPad */ + + for (size_t i = 0; i < context->num_server_formats; i++) + { + const AUDIO_FORMAT* format = &context->server_formats[i]; + + if (!audio_format_write(s, format)) + goto fail; + } + + const size_t pos = Stream_GetPosition(s); + if (pos > UINT16_MAX) + goto fail; + + WINPR_ASSERT(pos >= 4); + Stream_SetPosition(s, 2); + Stream_Write_UINT16(s, (UINT16)(pos - 4)); + Stream_SetPosition(s, pos); + + WINPR_ASSERT(context->priv); + + status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), + (UINT32)pos, &written); + Stream_SetPosition(s, 0); +fail: + return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; +} + +/** + * Read Wave Confirm PDU (2.2.3.8) and handle callback + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_recv_waveconfirm(RdpsndServerContext* context, wStream* s) +{ + UINT16 timestamp = 0; + BYTE confirmBlockNum = 0; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, timestamp); + Stream_Read_UINT8(s, confirmBlockNum); + Stream_Seek_UINT8(s); + IFCALLRET(context->ConfirmBlock, error, context, confirmBlockNum, timestamp); + + if (error) + WLog_ERR(TAG, "context->ConfirmBlock failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Read Training Confirm PDU (2.2.3.2) and handle callback + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_recv_trainingconfirm(RdpsndServerContext* context, wStream* s) +{ + UINT16 timestamp = 0; + UINT16 packsize = 0; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT16(s, timestamp); + Stream_Read_UINT16(s, packsize); + + IFCALLRET(context->TrainingConfirm, error, context, timestamp, packsize); + if (error) + WLog_ERR(TAG, "context->TrainingConfirm failed with error %" PRIu32 "", error); + + return error; +} + +/** + * Read Quality Mode PDU (2.2.2.3) + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_recv_quality_mode(RdpsndServerContext* context, wStream* s) +{ + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + { + WLog_ERR(TAG, "not enough data in stream!"); + return ERROR_INVALID_DATA; + } + + Stream_Read_UINT16(s, context->qualityMode); /* wQualityMode */ + Stream_Seek_UINT16(s); /* Reserved */ + + WLog_DBG(TAG, "Client requested sound quality: 0x%04" PRIX16 "", context->qualityMode); + + return CHANNEL_RC_OK; +} + +/** + * Read Client Audio Formats and Version PDU (2.2.2.2) + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_recv_formats(RdpsndServerContext* context, wStream* s) +{ + UINT16 num_known_format = 0; + UINT16 udpPort = 0; + BYTE lastblock = 0; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 20)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, context->capsFlags); /* dwFlags */ + Stream_Read_UINT32(s, context->initialVolume); /* dwVolume */ + Stream_Read_UINT32(s, context->initialPitch); /* dwPitch */ + Stream_Read_UINT16(s, udpPort); /* wDGramPort */ + Stream_Read_UINT16(s, context->num_client_formats); /* wNumberOfFormats */ + Stream_Read_UINT8(s, lastblock); /* cLastBlockConfirmed */ + Stream_Read_UINT16(s, context->clientVersion); /* wVersion */ + Stream_Seek_UINT8(s); /* bPad */ + + /* this check is only a guess as cbSize can influence the size of a format record */ + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, context->num_client_formats, 18ull)) + return ERROR_INVALID_DATA; + + if (!context->num_client_formats) + { + WLog_ERR(TAG, "client doesn't support any format!"); + return ERROR_INTERNAL_ERROR; + } + + context->client_formats = audio_formats_new(context->num_client_formats); + + if (!context->client_formats) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + for (UINT16 i = 0; i < context->num_client_formats; i++) + { + AUDIO_FORMAT* format = &context->client_formats[i]; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 18)) + { + WLog_ERR(TAG, "not enough data in stream!"); + error = ERROR_INVALID_DATA; + goto out_free; + } + + Stream_Read_UINT16(s, format->wFormatTag); + Stream_Read_UINT16(s, format->nChannels); + Stream_Read_UINT32(s, format->nSamplesPerSec); + Stream_Read_UINT32(s, format->nAvgBytesPerSec); + Stream_Read_UINT16(s, format->nBlockAlign); + Stream_Read_UINT16(s, format->wBitsPerSample); + Stream_Read_UINT16(s, format->cbSize); + + if (format->cbSize > 0) + { + if (!Stream_SafeSeek(s, format->cbSize)) + { + WLog_ERR(TAG, "Stream_SafeSeek failed!"); + error = ERROR_INTERNAL_ERROR; + goto out_free; + } + } + + if (format->wFormatTag != 0) + { + // lets call this a known format + // TODO: actually look through our own list of known formats + num_known_format++; + } + } + + if (!context->num_client_formats) + { + WLog_ERR(TAG, "client doesn't support any known format!"); + goto out_free; + } + + return CHANNEL_RC_OK; +out_free: + free(context->client_formats); + return error; +} + +static DWORD WINAPI rdpsnd_server_thread(LPVOID arg) +{ + DWORD nCount = 0; + DWORD status = 0; + HANDLE events[2] = { 0 }; + RdpsndServerContext* context = (RdpsndServerContext*)arg; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + events[nCount++] = context->priv->channelEvent; + events[nCount++] = context->priv->StopEvent; + + WINPR_ASSERT(nCount <= ARRAYSIZE(events)); + + while (TRUE) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "!", error); + break; + } + + status = WaitForSingleObject(context->priv->StopEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error); + break; + } + + if (status == WAIT_OBJECT_0) + break; + + if ((error = rdpsnd_server_handle_messages(context))) + { + WLog_ERR(TAG, "rdpsnd_server_handle_messages failed with error %" PRIu32 "", error); + break; + } + } + + if (error && context->rdpcontext) + setChannelError(context->rdpcontext, error, "rdpsnd_server_thread reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_initialize(RdpsndServerContext* context, BOOL ownThread) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + context->priv->ownThread = ownThread; + return context->Start(context); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_select_format(RdpsndServerContext* context, UINT16 client_format_index) +{ + size_t bs = 0; + size_t out_buffer_size = 0; + AUDIO_FORMAT* format = NULL; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + if ((client_format_index >= context->num_client_formats) || (!context->src_format)) + { + WLog_ERR(TAG, "index %" PRIu16 " is not correct.", client_format_index); + return ERROR_INVALID_DATA; + } + + EnterCriticalSection(&context->priv->lock); + context->priv->src_bytes_per_sample = context->src_format->wBitsPerSample / 8; + context->priv->src_bytes_per_frame = + context->priv->src_bytes_per_sample * context->src_format->nChannels; + context->selected_client_format = client_format_index; + format = &context->client_formats[client_format_index]; + + if (format->nSamplesPerSec == 0) + { + WLog_ERR(TAG, "invalid Client Sound Format!!"); + error = ERROR_INVALID_DATA; + goto out; + } + + if (context->latency <= 0) + context->latency = 50; + + context->priv->out_frames = context->src_format->nSamplesPerSec * context->latency / 1000; + + if (context->priv->out_frames < 1) + context->priv->out_frames = 1; + + switch (format->wFormatTag) + { + case WAVE_FORMAT_DVI_ADPCM: + bs = 4ULL * (format->nBlockAlign - 4ULL * format->nChannels); + context->priv->out_frames -= context->priv->out_frames % bs; + + if (context->priv->out_frames < bs) + context->priv->out_frames = bs; + + break; + + case WAVE_FORMAT_ADPCM: + bs = (format->nBlockAlign - 7 * format->nChannels) * 2 / format->nChannels + 2; + context->priv->out_frames -= context->priv->out_frames % bs; + + if (context->priv->out_frames < bs) + context->priv->out_frames = bs; + + break; + default: + break; + } + + context->priv->out_pending_frames = 0; + out_buffer_size = context->priv->out_frames * context->priv->src_bytes_per_frame; + + if (context->priv->out_buffer_size < out_buffer_size) + { + BYTE* newBuffer = NULL; + newBuffer = (BYTE*)realloc(context->priv->out_buffer, out_buffer_size); + + if (!newBuffer) + { + WLog_ERR(TAG, "realloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + context->priv->out_buffer = newBuffer; + context->priv->out_buffer_size = out_buffer_size; + } + + freerdp_dsp_context_reset(context->priv->dsp_context, format, 0u); +out: + LeaveCriticalSection(&context->priv->lock); + return error; +} + +/** + * Send Training PDU (2.2.3.1) + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_training(RdpsndServerContext* context, UINT16 timestamp, UINT16 packsize, + BYTE* data) +{ + ULONG written = 0; + BOOL status = 0; + wStream* s = rdpsnd_server_get_buffer(context); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return ERROR_INTERNAL_ERROR; + + Stream_Write_UINT8(s, SNDC_TRAINING); + Stream_Write_UINT8(s, 0); + Stream_Seek_UINT16(s); + Stream_Write_UINT16(s, timestamp); + Stream_Write_UINT16(s, packsize); + + if (packsize > 0) + { + if (!Stream_EnsureRemainingCapacity(s, packsize)) + { + Stream_SetPosition(s, 0); + return ERROR_INTERNAL_ERROR; + } + + Stream_Write(s, data, packsize); + } + + const size_t end = Stream_GetPosition(s); + if ((end < 4) || (end > UINT16_MAX)) + return ERROR_INTERNAL_ERROR; + + Stream_SetPosition(s, 2); + Stream_Write_UINT16(s, (UINT16)(end - 4)); + + status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), + (UINT32)end, &written); + + Stream_SetPosition(s, 0); + + return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; +} + +static BOOL rdpsnd_server_align_wave_pdu(wStream* s, UINT32 alignment) +{ + size_t size = 0; + Stream_SealLength(s); + size = Stream_Length(s); + + if ((size % alignment) != 0) + { + size_t offset = alignment - size % alignment; + + if (!Stream_EnsureRemainingCapacity(s, offset)) + return FALSE; + + Stream_Zero(s, offset); + } + + Stream_SealLength(s); + return TRUE; +} + +/** + * Function description + * context->priv->lock should be obtained before calling this function + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_send_wave_pdu(RdpsndServerContext* context, UINT16 wTimestamp) +{ + AUDIO_FORMAT* format = NULL; + ULONG written = 0; + UINT error = CHANNEL_RC_OK; + wStream* s = rdpsnd_server_get_buffer(context); + + if (context->selected_client_format > context->num_client_formats) + return ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(context->client_formats); + + format = &context->client_formats[context->selected_client_format]; + /* WaveInfo PDU */ + Stream_SetPosition(s, 0); + + if (!Stream_EnsureRemainingCapacity(s, 16)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT8(s, SNDC_WAVE); /* msgType */ + Stream_Write_UINT8(s, 0); /* bPad */ + Stream_Write_UINT16(s, 0); /* BodySize */ + Stream_Write_UINT16(s, wTimestamp); /* wTimeStamp */ + Stream_Write_UINT16(s, context->selected_client_format); /* wFormatNo */ + Stream_Write_UINT8(s, context->block_no); /* cBlockNo */ + Stream_Seek(s, 3); /* bPad */ + const size_t start = Stream_GetPosition(s); + const BYTE* src = context->priv->out_buffer; + const size_t length = + 1ull * context->priv->out_pending_frames * context->priv->src_bytes_per_frame; + + if (!freerdp_dsp_encode(context->priv->dsp_context, context->src_format, src, length, s)) + return ERROR_INTERNAL_ERROR; + + /* Set stream size */ + if (!rdpsnd_server_align_wave_pdu(s, format->nBlockAlign)) + return ERROR_INTERNAL_ERROR; + + const size_t end = Stream_GetPosition(s); + const size_t pos = end - start + 8ULL; + if (pos > UINT16_MAX) + return ERROR_INTERNAL_ERROR; + Stream_SetPosition(s, 2); + Stream_Write_UINT16(s, (UINT16)pos); + Stream_SetPosition(s, end); + + if (!WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), + (UINT32)(start + 4), &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + } + + if (error != CHANNEL_RC_OK) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + goto out; + } + + Stream_SetPosition(s, start); + Stream_Write_UINT32(s, 0); /* bPad */ + Stream_SetPosition(s, start); + + WINPR_ASSERT((end - start) <= UINT32_MAX); + if (!WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_Pointer(s), + (UINT32)(end - start), &written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed!"); + error = ERROR_INTERNAL_ERROR; + } + + context->block_no = (context->block_no + 1) % 256; + +out: + Stream_SetPosition(s, 0); + context->priv->out_pending_frames = 0; + return error; +} + +/** + * Function description + * context->priv->lock should be obtained before calling this function + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_send_wave2_pdu(RdpsndServerContext* context, UINT16 formatNo, + const BYTE* data, size_t size, BOOL encoded, + UINT16 timestamp, UINT32 audioTimeStamp) +{ + ULONG written = 0; + UINT error = CHANNEL_RC_OK; + BOOL status = 0; + wStream* s = rdpsnd_server_get_buffer(context); + + if (!Stream_EnsureRemainingCapacity(s, 16)) + { + error = ERROR_INTERNAL_ERROR; + goto out; + } + + /* Wave2 PDU */ + Stream_Write_UINT8(s, SNDC_WAVE2); /* msgType */ + Stream_Write_UINT8(s, 0); /* bPad */ + Stream_Write_UINT16(s, 0); /* BodySize */ + Stream_Write_UINT16(s, timestamp); /* wTimeStamp */ + Stream_Write_UINT16(s, formatNo); /* wFormatNo */ + Stream_Write_UINT8(s, context->block_no); /* cBlockNo */ + Stream_Write_UINT8(s, 0); /* bPad */ + Stream_Write_UINT8(s, 0); /* bPad */ + Stream_Write_UINT8(s, 0); /* bPad */ + Stream_Write_UINT32(s, audioTimeStamp); /* dwAudioTimeStamp */ + + if (encoded) + { + if (!Stream_EnsureRemainingCapacity(s, size)) + { + error = ERROR_INTERNAL_ERROR; + goto out; + } + + Stream_Write(s, data, size); + } + else + { + AUDIO_FORMAT* format = NULL; + + if (!freerdp_dsp_encode(context->priv->dsp_context, context->src_format, data, size, s)) + { + error = ERROR_INTERNAL_ERROR; + goto out; + } + + format = &context->client_formats[formatNo]; + if (!rdpsnd_server_align_wave_pdu(s, format->nBlockAlign)) + { + error = ERROR_INTERNAL_ERROR; + goto out; + } + } + + const size_t end = Stream_GetPosition(s); + if (end > UINT16_MAX + 4) + { + error = ERROR_INTERNAL_ERROR; + goto out; + } + + Stream_SetPosition(s, 2); + Stream_Write_UINT16(s, (UINT16)(end - 4)); + + status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), + (UINT32)end, &written); + + if (!status || (end != written)) + { + WLog_ERR(TAG, "WTSVirtualChannelWrite failed! [stream length=%" PRIuz " - written=%" PRIu32, + end, written); + error = ERROR_INTERNAL_ERROR; + } + + context->block_no = (context->block_no + 1) % 256; + +out: + Stream_SetPosition(s, 0); + context->priv->out_pending_frames = 0; + return error; +} + +/* Wrapper function to send WAVE or WAVE2 PDU depending on client connected */ +static UINT rdpsnd_server_send_audio_pdu(RdpsndServerContext* context, UINT16 wTimestamp) +{ + const BYTE* src = NULL; + size_t length = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + if (context->selected_client_format >= context->num_client_formats) + return ERROR_INTERNAL_ERROR; + + src = context->priv->out_buffer; + length = context->priv->out_pending_frames * context->priv->src_bytes_per_frame; + + if (context->clientVersion >= CHANNEL_VERSION_WIN_8) + return rdpsnd_server_send_wave2_pdu(context, context->selected_client_format, src, length, + FALSE, wTimestamp, wTimestamp); + else + return rdpsnd_server_send_wave_pdu(context, wTimestamp); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_send_samples(RdpsndServerContext* context, const void* buf, + size_t nframes, UINT16 wTimestamp) +{ + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + EnterCriticalSection(&context->priv->lock); + + if (context->selected_client_format >= context->num_client_formats) + { + /* It's possible while format negotiation has not been done */ + WLog_WARN(TAG, "Drop samples because client format has not been negotiated."); + error = ERROR_NOT_READY; + goto out; + } + + while (nframes > 0) + { + const size_t cframes = + MIN(nframes, context->priv->out_frames - context->priv->out_pending_frames); + size_t cframesize = cframes * context->priv->src_bytes_per_frame; + CopyMemory(context->priv->out_buffer + + (context->priv->out_pending_frames * context->priv->src_bytes_per_frame), + buf, cframesize); + buf = (const BYTE*)buf + cframesize; + nframes -= cframes; + context->priv->out_pending_frames += cframes; + + if (context->priv->out_pending_frames >= context->priv->out_frames) + { + if ((error = rdpsnd_server_send_audio_pdu(context, wTimestamp))) + { + WLog_ERR(TAG, "rdpsnd_server_send_audio_pdu failed with error %" PRIu32 "", error); + break; + } + } + } + +out: + LeaveCriticalSection(&context->priv->lock); + return error; +} + +/** + * Send encoded audio samples using a Wave2 PDU. + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_send_samples2(RdpsndServerContext* context, UINT16 formatNo, + const void* buf, size_t size, UINT16 timestamp, + UINT32 audioTimeStamp) +{ + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + if (context->clientVersion < CHANNEL_VERSION_WIN_8) + return ERROR_INTERNAL_ERROR; + + EnterCriticalSection(&context->priv->lock); + + error = + rdpsnd_server_send_wave2_pdu(context, formatNo, buf, size, TRUE, timestamp, audioTimeStamp); + + LeaveCriticalSection(&context->priv->lock); + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_set_volume(RdpsndServerContext* context, UINT16 left, UINT16 right) +{ + BOOL status = 0; + ULONG written = 0; + wStream* s = rdpsnd_server_get_buffer(context); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return ERROR_NOT_ENOUGH_MEMORY; + + Stream_Write_UINT8(s, SNDC_SETVOLUME); + Stream_Write_UINT8(s, 0); + Stream_Write_UINT16(s, 4); /* Payload length */ + Stream_Write_UINT16(s, left); + Stream_Write_UINT16(s, right); + + const size_t len = Stream_GetPosition(s); + WINPR_ASSERT(len <= UINT32_MAX); + status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), + (ULONG)len, &written); + Stream_SetPosition(s, 0); + return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_close(RdpsndServerContext* context) +{ + BOOL status = 0; + ULONG written = 0; + UINT error = CHANNEL_RC_OK; + wStream* s = rdpsnd_server_get_buffer(context); + + EnterCriticalSection(&context->priv->lock); + + if (context->priv->out_pending_frames > 0) + { + if (context->selected_client_format >= context->num_client_formats) + { + WLog_ERR(TAG, "Pending audio frame exists while no format selected."); + error = ERROR_INVALID_DATA; + } + else if ((error = rdpsnd_server_send_audio_pdu(context, 0))) + { + WLog_ERR(TAG, "rdpsnd_server_send_audio_pdu failed with error %" PRIu32 "", error); + } + } + + LeaveCriticalSection(&context->priv->lock); + + if (error) + return error; + + context->selected_client_format = 0xFFFF; + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT8(s, SNDC_CLOSE); + Stream_Write_UINT8(s, 0); + Stream_Seek_UINT16(s); + const size_t pos = Stream_GetPosition(s); + WINPR_ASSERT(pos >= 4); + Stream_SetPosition(s, 2); + Stream_Write_UINT16(s, WINPR_ASSERTING_INT_CAST(uint16_t, pos - 4)); + Stream_SetPosition(s, pos); + + const size_t len = Stream_GetPosition(s); + WINPR_ASSERT(len <= UINT32_MAX); + status = WTSVirtualChannelWrite(context->priv->ChannelHandle, Stream_BufferAs(s, char), + (UINT32)len, &written); + Stream_SetPosition(s, 0); + return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_start(RdpsndServerContext* context) +{ + void* buffer = NULL; + DWORD bytesReturned = 0; + RdpsndServerPrivate* priv = NULL; + UINT error = ERROR_INTERNAL_ERROR; + PULONG pSessionId = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + priv = context->priv; + priv->SessionId = WTS_CURRENT_SESSION; + + if (context->use_dynamic_virtual_channel) + { + UINT32 channelId = 0; + BOOL status = TRUE; + + if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &bytesReturned)) + { + priv->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + priv->ChannelHandle = WTSVirtualChannelOpenEx(priv->SessionId, RDPSND_DVC_CHANNEL_NAME, + WTS_CHANNEL_OPTION_DYNAMIC); + if (!priv->ChannelHandle) + { + WLog_ERR(TAG, "Open audio dynamic virtual channel (%s) failed!", + RDPSND_DVC_CHANNEL_NAME); + return ERROR_INTERNAL_ERROR; + } + + channelId = WTSChannelGetIdByHandle(priv->ChannelHandle); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + goto out_close; + } + } + else + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + return ERROR_INTERNAL_ERROR; + } + } + else + { + priv->ChannelHandle = + WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, RDPSND_CHANNEL_NAME); + if (!priv->ChannelHandle) + { + WLog_ERR(TAG, "Open audio static virtual channel (rdpsnd) failed!"); + return ERROR_INTERNAL_ERROR; + } + } + + if (!WTSVirtualChannelQuery(priv->ChannelHandle, WTSVirtualEventHandle, &buffer, + &bytesReturned) || + (bytesReturned != sizeof(HANDLE))) + { + WLog_ERR(TAG, + "error during WTSVirtualChannelQuery(WTSVirtualEventHandle) or invalid returned " + "size(%" PRIu32 ")", + bytesReturned); + + if (buffer) + WTSFreeMemory(buffer); + + goto out_close; + } + + priv->channelEvent = *(HANDLE*)buffer; + WTSFreeMemory(buffer); + priv->rdpsnd_pdu = Stream_New(NULL, 4096); + + if (!priv->rdpsnd_pdu) + { + WLog_ERR(TAG, "Stream_New failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out_close; + } + + if (!InitializeCriticalSectionEx(&context->priv->lock, 0, 0)) + { + WLog_ERR(TAG, "InitializeCriticalSectionEx failed!"); + goto out_pdu; + } + + if ((error = rdpsnd_server_send_formats(context))) + { + WLog_ERR(TAG, "rdpsnd_server_send_formats failed with error %" PRIu32 "", error); + goto out_lock; + } + + if (priv->ownThread) + { + context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (!context->priv->StopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + goto out_lock; + } + + context->priv->Thread = + CreateThread(NULL, 0, rdpsnd_server_thread, (void*)context, 0, NULL); + + if (!context->priv->Thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + goto out_stopEvent; + } + } + + return CHANNEL_RC_OK; +out_stopEvent: + (void)CloseHandle(context->priv->StopEvent); + context->priv->StopEvent = NULL; +out_lock: + DeleteCriticalSection(&context->priv->lock); +out_pdu: + Stream_Free(context->priv->rdpsnd_pdu, TRUE); + context->priv->rdpsnd_pdu = NULL; +out_close: + (void)WTSVirtualChannelClose(context->priv->ChannelHandle); + context->priv->ChannelHandle = NULL; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT rdpsnd_server_stop(RdpsndServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + if (!context->priv->StopEvent) + return error; + + if (context->priv->ownThread) + { + if (context->priv->StopEvent) + { + (void)SetEvent(context->priv->StopEvent); + + if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error); + return error; + } + + (void)CloseHandle(context->priv->Thread); + (void)CloseHandle(context->priv->StopEvent); + context->priv->Thread = NULL; + context->priv->StopEvent = NULL; + } + } + + DeleteCriticalSection(&context->priv->lock); + + if (context->priv->rdpsnd_pdu) + { + Stream_Free(context->priv->rdpsnd_pdu, TRUE); + context->priv->rdpsnd_pdu = NULL; + } + + if (context->priv->ChannelHandle) + { + (void)WTSVirtualChannelClose(context->priv->ChannelHandle); + context->priv->ChannelHandle = NULL; + } + + return error; +} + +RdpsndServerContext* rdpsnd_server_context_new(HANDLE vcm) +{ + RdpsndServerPrivate* priv = NULL; + RdpsndServerContext* context = (RdpsndServerContext*)calloc(1, sizeof(RdpsndServerContext)); + + if (!context) + goto fail; + + context->vcm = vcm; + context->Start = rdpsnd_server_start; + context->Stop = rdpsnd_server_stop; + context->selected_client_format = 0xFFFF; + context->Initialize = rdpsnd_server_initialize; + context->SendFormats = rdpsnd_server_send_formats; + context->SelectFormat = rdpsnd_server_select_format; + context->Training = rdpsnd_server_training; + context->SendSamples = rdpsnd_server_send_samples; + context->SendSamples2 = rdpsnd_server_send_samples2; + context->SetVolume = rdpsnd_server_set_volume; + context->Close = rdpsnd_server_close; + context->priv = priv = (RdpsndServerPrivate*)calloc(1, sizeof(RdpsndServerPrivate)); + + if (!priv) + { + WLog_ERR(TAG, "calloc failed!"); + goto fail; + } + + priv->dsp_context = freerdp_dsp_context_new(TRUE); + + if (!priv->dsp_context) + { + WLog_ERR(TAG, "freerdp_dsp_context_new failed!"); + goto fail; + } + + priv->input_stream = Stream_New(NULL, 4); + + if (!priv->input_stream) + { + WLog_ERR(TAG, "Stream_New failed!"); + goto fail; + } + + priv->expectedBytes = 4; + priv->waitingHeader = TRUE; + priv->ownThread = TRUE; + return context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + rdpsnd_server_context_free(context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void rdpsnd_server_context_reset(RdpsndServerContext* context) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + context->priv->expectedBytes = 4; + context->priv->waitingHeader = TRUE; + Stream_SetPosition(context->priv->input_stream, 0); +} + +void rdpsnd_server_context_free(RdpsndServerContext* context) +{ + if (!context) + return; + + if (context->priv) + { + rdpsnd_server_stop(context); + + free(context->priv->out_buffer); + + if (context->priv->dsp_context) + freerdp_dsp_context_free(context->priv->dsp_context); + + if (context->priv->input_stream) + Stream_Free(context->priv->input_stream, TRUE); + } + + free(context->server_formats); + free(context->client_formats); + free(context->priv); + free(context); +} + +HANDLE rdpsnd_server_get_event_handle(RdpsndServerContext* context) +{ + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + return context->priv->channelEvent; +} + +/* + * Handle rpdsnd messages - server side + * + * @param Server side context + * + * @return 0 on success + * ERROR_NO_DATA if no data could be read this time + * otherwise error + */ +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT rdpsnd_server_handle_messages(RdpsndServerContext* context) +{ + DWORD bytesReturned = 0; + UINT ret = CHANNEL_RC_OK; + RdpsndServerPrivate* priv = NULL; + wStream* s = NULL; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->priv); + + priv = context->priv; + s = priv->input_stream; + + if (!WTSVirtualChannelRead(priv->ChannelHandle, 0, Stream_Pointer(s), priv->expectedBytes, + &bytesReturned)) + { + if (GetLastError() == ERROR_NO_DATA) + return ERROR_NO_DATA; + + WLog_ERR(TAG, "channel connection closed"); + return ERROR_INTERNAL_ERROR; + } + + priv->expectedBytes -= bytesReturned; + Stream_Seek(s, bytesReturned); + + if (priv->expectedBytes) + return CHANNEL_RC_OK; + + Stream_SealLength(s); + Stream_SetPosition(s, 0); + + if (priv->waitingHeader) + { + /* header case */ + Stream_Read_UINT8(s, priv->msgType); + Stream_Seek_UINT8(s); /* bPad */ + Stream_Read_UINT16(s, priv->expectedBytes); + priv->waitingHeader = FALSE; + Stream_SetPosition(s, 0); + + if (priv->expectedBytes) + { + if (!Stream_EnsureCapacity(s, priv->expectedBytes)) + { + WLog_ERR(TAG, "Stream_EnsureCapacity failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + return CHANNEL_RC_OK; + } + } + + /* when here we have the header + the body */ +#ifdef WITH_DEBUG_SND + WLog_DBG(TAG, "message type %" PRIu8 "", priv->msgType); +#endif + priv->expectedBytes = 4; + priv->waitingHeader = TRUE; + + switch (priv->msgType) + { + case SNDC_WAVECONFIRM: + ret = rdpsnd_server_recv_waveconfirm(context, s); + break; + + case SNDC_TRAINING: + ret = rdpsnd_server_recv_trainingconfirm(context, s); + break; + + case SNDC_FORMATS: + ret = rdpsnd_server_recv_formats(context, s); + + if ((ret == CHANNEL_RC_OK) && (context->clientVersion < CHANNEL_VERSION_WIN_7)) + IFCALL(context->Activated, context); + + break; + + case SNDC_QUALITYMODE: + ret = rdpsnd_server_recv_quality_mode(context, s); + + if ((ret == CHANNEL_RC_OK) && (context->clientVersion >= CHANNEL_VERSION_WIN_7)) + IFCALL(context->Activated, context); + + break; + + default: + WLog_ERR(TAG, "UNKNOWN MESSAGE TYPE!! (0x%02" PRIX8 ")", priv->msgType); + ret = ERROR_INVALID_DATA; + break; + } + + Stream_SetPosition(s, 0); + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/server/rdpsnd_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/server/rdpsnd_main.h new file mode 100644 index 0000000000000000000000000000000000000000..8623dd451715d4cbbf87af006e0752e5675a32e7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/rdpsnd/server/rdpsnd_main.h @@ -0,0 +1,59 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Audio Virtual Channel + * + * Copyright 2012 Vic Lee + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPSND_SERVER_MAIN_H +#define FREERDP_CHANNEL_RDPSND_SERVER_MAIN_H + +#include +#include +#include + +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("rdpsnd.server") + +struct s_rdpsnd_server_private +{ + BOOL ownThread; + HANDLE Thread; + HANDLE StopEvent; + HANDLE channelEvent; + void* ChannelHandle; + DWORD SessionId; + + BOOL waitingHeader; + DWORD expectedBytes; + BYTE msgType; + wStream* input_stream; + wStream* rdpsnd_pdu; + BYTE* out_buffer; + size_t out_buffer_size; + size_t out_frames; + size_t out_pending_frames; + UINT32 src_bytes_per_sample; + UINT32 src_bytes_per_frame; + FREERDP_DSP_CONTEXT* dsp_context; + CRITICAL_SECTION lock; /* Protect out_buffer and related parameters */ +}; + +#endif /* FREERDP_CHANNEL_RDPSND_SERVER_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/remdesk/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/remdesk/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c9520412137c480f1adb6a05a6c13cb41f21077c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/remdesk/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("remdesk") + +include_directories(common) +add_subdirectory(common) + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/remdesk/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/remdesk/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..652e2b7365b2784f5012e9e2c9480c251cc2a76b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/remdesk/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "remdesk" + TYPE + "static" + DESCRIPTION + "Remote Assistance Virtual Channel Extension" + SPECIFICATIONS + "[MS-RA]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/serial/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..41b312aa9862cf8851e97a1a7ec028e84ae58663 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("serial") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/serial/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..7f47678188bd52bc2a4f789925fc3a36f3d6fea6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/ChannelOptions.cmake @@ -0,0 +1,38 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +if(WIN32) + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) + message("Serial redirection not supported on windows") +endif() + +if(ANDROID) + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) + message("Serial redirection not supported on android") +endif() + +if(APPLE) + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) + message("Serial redirection not supported on apple") +endif() + +define_channel_options( + NAME + "serial" + TYPE + "device" + DESCRIPTION + "Serial Port Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPESP]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/serial/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dffd985626a6f9e1589ea1e29320b51ce6a0381c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/client/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("serial") + +set(${MODULE_PREFIX}_SRCS serial_main.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp) + +# Serial implementation is currently linux only. BSD* might also work but untested +if(UNIX AND NOT APPLE AND NOT ANDROID) + add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DeviceServiceEntry") +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/serial/client/serial_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/client/serial_main.c new file mode 100644 index 0000000000000000000000000000000000000000..ee04433bcd8a080e76c45b1f91cb9034788de5ce --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/serial/client/serial_main.c @@ -0,0 +1,997 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Serial Port Device Service Virtual Channel + * + * Copyright 2011 O.S. Systems Software Ltda. + * Copyright 2011 Eduardo Fiss Beloni + * Copyright 2014 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define TAG CHANNELS_TAG("serial.client") + +#define MAX_IRP_THREADS 5 + +typedef struct +{ + DEVICE device; + BOOL permissive; + SERIAL_DRIVER_ID ServerSerialDriverId; + HANDLE hComm; + + wLog* log; + HANDLE MainThread; + wMessageQueue* MainIrpQueue; + + /* one thread per pending IRP and indexed according their CompletionId */ + wListDictionary* IrpThreads; + CRITICAL_SECTION TerminatingIrpThreadsLock; + rdpContext* rdpcontext; +} SERIAL_DEVICE; + +typedef struct +{ + SERIAL_DEVICE* serial; + IRP* irp; +} IRP_THREAD_DATA; + +static void close_terminated_irp_thread_handles(SERIAL_DEVICE* serial, BOOL forceClose); +static NTSTATUS GetLastErrorToIoStatus(SERIAL_DEVICE* serial) +{ + /* http://msdn.microsoft.com/en-us/library/ff547466%28v=vs.85%29.aspx#generic_status_values_for_serial_device_control_requests + */ + switch (GetLastError()) + { + case ERROR_BAD_DEVICE: + return STATUS_INVALID_DEVICE_REQUEST; + + case ERROR_CALL_NOT_IMPLEMENTED: + return STATUS_NOT_IMPLEMENTED; + + case ERROR_CANCELLED: + return STATUS_CANCELLED; + + case ERROR_INSUFFICIENT_BUFFER: + return STATUS_BUFFER_TOO_SMALL; /* NB: STATUS_BUFFER_SIZE_TOO_SMALL not defined */ + + case ERROR_INVALID_DEVICE_OBJECT_PARAMETER: /* eg: SerCx2.sys' _purge() */ + return STATUS_INVALID_DEVICE_STATE; + + case ERROR_INVALID_HANDLE: + return STATUS_INVALID_DEVICE_REQUEST; + + case ERROR_INVALID_PARAMETER: + return STATUS_INVALID_PARAMETER; + + case ERROR_IO_DEVICE: + return STATUS_IO_DEVICE_ERROR; + + case ERROR_IO_PENDING: + return STATUS_PENDING; + + case ERROR_NOT_SUPPORTED: + return STATUS_NOT_SUPPORTED; + + case ERROR_TIMEOUT: + return STATUS_TIMEOUT; + default: + break; + } + + WLog_Print(serial->log, WLOG_DEBUG, "unexpected last-error: 0x%08" PRIX32 "", GetLastError()); + return STATUS_UNSUCCESSFUL; +} + +static UINT serial_process_irp_create(SERIAL_DEVICE* serial, IRP* irp) +{ + DWORD DesiredAccess = 0; + DWORD SharedAccess = 0; + DWORD CreateDisposition = 0; + UINT32 PathLength = 0; + + WINPR_ASSERT(serial); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(irp->input, DesiredAccess); /* DesiredAccess (4 bytes) */ + Stream_Seek_UINT64(irp->input); /* AllocationSize (8 bytes) */ + Stream_Seek_UINT32(irp->input); /* FileAttributes (4 bytes) */ + Stream_Read_UINT32(irp->input, SharedAccess); /* SharedAccess (4 bytes) */ + Stream_Read_UINT32(irp->input, CreateDisposition); /* CreateDisposition (4 bytes) */ + Stream_Seek_UINT32(irp->input); /* CreateOptions (4 bytes) */ + Stream_Read_UINT32(irp->input, PathLength); /* PathLength (4 bytes) */ + + if (!Stream_SafeSeek(irp->input, PathLength)) /* Path (variable) */ + return ERROR_INVALID_DATA; + + WINPR_ASSERT(PathLength == 0); /* MS-RDPESP 2.2.2.2 */ +#ifndef _WIN32 + /* Windows 2012 server sends on a first call : + * DesiredAccess = 0x00100080: SYNCHRONIZE | FILE_READ_ATTRIBUTES + * SharedAccess = 0x00000007: FILE_SHARE_DELETE | FILE_SHARE_WRITE | FILE_SHARE_READ + * CreateDisposition = 0x00000001: CREATE_NEW + * + * then Windows 2012 sends : + * DesiredAccess = 0x00120089: SYNCHRONIZE | READ_CONTROL | FILE_READ_ATTRIBUTES | + * FILE_READ_EA | FILE_READ_DATA SharedAccess = 0x00000007: FILE_SHARE_DELETE | + * FILE_SHARE_WRITE | FILE_SHARE_READ CreateDisposition = 0x00000001: CREATE_NEW + * + * WINPR_ASSERT(DesiredAccess == (GENERIC_READ | GENERIC_WRITE)); + * WINPR_ASSERT(SharedAccess == 0); + * WINPR_ASSERT(CreateDisposition == OPEN_EXISTING); + * + */ + WLog_Print(serial->log, WLOG_DEBUG, + "DesiredAccess: 0x%" PRIX32 ", SharedAccess: 0x%" PRIX32 + ", CreateDisposition: 0x%" PRIX32 "", + DesiredAccess, SharedAccess, CreateDisposition); + /* FIXME: As of today only the flags below are supported by CommCreateFileA: */ + DesiredAccess = GENERIC_READ | GENERIC_WRITE; + SharedAccess = 0; + CreateDisposition = OPEN_EXISTING; +#endif + serial->hComm = + CreateFile(serial->device.name, DesiredAccess, SharedAccess, NULL, /* SecurityAttributes */ + CreateDisposition, 0, /* FlagsAndAttributes */ + NULL); /* TemplateFile */ + + if (!serial->hComm || (serial->hComm == INVALID_HANDLE_VALUE)) + { + WLog_Print(serial->log, WLOG_WARN, "CreateFile failure: %s last-error: 0x%08" PRIX32 "", + serial->device.name, GetLastError()); + irp->IoStatus = STATUS_UNSUCCESSFUL; + goto error_handle; + } + + _comm_setServerSerialDriver(serial->hComm, serial->ServerSerialDriverId); + _comm_set_permissive(serial->hComm, serial->permissive); + /* NOTE: binary mode/raw mode required for the redirection. On + * Linux, CommCreateFileA forces this setting. + */ + /* ZeroMemory(&dcb, sizeof(DCB)); */ + /* dcb.DCBlength = sizeof(DCB); */ + /* GetCommState(serial->hComm, &dcb); */ + /* dcb.fBinary = TRUE; */ + /* SetCommState(serial->hComm, &dcb); */ + WINPR_ASSERT(irp->FileId == 0); + irp->FileId = irp->devman->id_sequence++; /* FIXME: why not ((WINPR_COMM*)hComm)->fd? */ + irp->IoStatus = STATUS_SUCCESS; + WLog_Print(serial->log, WLOG_DEBUG, "%s (DeviceId: %" PRIu32 ", FileId: %" PRIu32 ") created.", + serial->device.name, irp->device->id, irp->FileId); +error_handle: + Stream_Write_UINT32(irp->output, irp->FileId); /* FileId (4 bytes) */ + Stream_Write_UINT8(irp->output, 0); /* Information (1 byte) */ + return CHANNEL_RC_OK; +} + +static UINT serial_process_irp_close(SERIAL_DEVICE* serial, IRP* irp) +{ + WINPR_ASSERT(serial); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32)) + return ERROR_INVALID_DATA; + + Stream_Seek(irp->input, 32); /* Padding (32 bytes) */ + + close_terminated_irp_thread_handles(serial, TRUE); + + if (!CloseHandle(serial->hComm)) + { + WLog_Print(serial->log, WLOG_WARN, "CloseHandle failure: %s (%" PRIu32 ") closed.", + serial->device.name, irp->device->id); + irp->IoStatus = STATUS_UNSUCCESSFUL; + goto error_handle; + } + + WLog_Print(serial->log, WLOG_DEBUG, "%s (DeviceId: %" PRIu32 ", FileId: %" PRIu32 ") closed.", + serial->device.name, irp->device->id, irp->FileId); + irp->IoStatus = STATUS_SUCCESS; +error_handle: + serial->hComm = NULL; + Stream_Zero(irp->output, 5); /* Padding (5 bytes) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT serial_process_irp_read(SERIAL_DEVICE* serial, IRP* irp) +{ + UINT32 Length = 0; + UINT64 Offset = 0; + BYTE* buffer = NULL; + DWORD nbRead = 0; + + WINPR_ASSERT(serial); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(irp->input, Length); /* Length (4 bytes) */ + Stream_Read_UINT64(irp->input, Offset); /* Offset (8 bytes) */ + (void)Offset; /* [MS-RDPESP] 3.2.5.1.4 Processing a Server Read Request Message + * ignored */ + Stream_Seek(irp->input, 20); /* Padding (20 bytes) */ + buffer = (BYTE*)calloc(Length, sizeof(BYTE)); + + if (buffer == NULL) + { + irp->IoStatus = STATUS_NO_MEMORY; + goto error_handle; + } + + /* MS-RDPESP 3.2.5.1.4: If the Offset field is not set to 0, the value MUST be ignored + * WINPR_ASSERT(Offset == 0); + */ + WLog_Print(serial->log, WLOG_DEBUG, "reading %" PRIu32 " bytes from %s", Length, + serial->device.name); + + /* FIXME: CommReadFile to be replaced by ReadFile */ + if (CommReadFile(serial->hComm, buffer, Length, &nbRead, NULL)) + { + irp->IoStatus = STATUS_SUCCESS; + } + else + { + WLog_Print(serial->log, WLOG_DEBUG, + "read failure to %s, nbRead=%" PRIu32 ", last-error: 0x%08" PRIX32 "", + serial->device.name, nbRead, GetLastError()); + irp->IoStatus = GetLastErrorToIoStatus(serial); + } + + WLog_Print(serial->log, WLOG_DEBUG, "%" PRIu32 " bytes read from %s", nbRead, + serial->device.name); +error_handle: + Stream_Write_UINT32(irp->output, nbRead); /* Length (4 bytes) */ + + if (nbRead > 0) + { + if (!Stream_EnsureRemainingCapacity(irp->output, nbRead)) + { + WLog_Print(serial->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!"); + free(buffer); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write(irp->output, buffer, nbRead); /* ReadData */ + } + + free(buffer); + return CHANNEL_RC_OK; +} + +static UINT serial_process_irp_write(SERIAL_DEVICE* serial, IRP* irp) +{ + UINT32 Length = 0; + UINT64 Offset = 0; + DWORD nbWritten = 0; + + WINPR_ASSERT(serial); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(irp->input, Length); /* Length (4 bytes) */ + Stream_Read_UINT64(irp->input, Offset); /* Offset (8 bytes) */ + (void)Offset; /* [MS-RDPESP] 3.2.5.1.4 Processing a Server Read Request Message + * ignored */ + if (!Stream_SafeSeek(irp->input, 20)) /* Padding (20 bytes) */ + return ERROR_INVALID_DATA; + + /* MS-RDPESP 3.2.5.1.5: The Offset field is ignored + * WINPR_ASSERT(Offset == 0); + * + * Using a serial printer, noticed though this field could be + * set. + */ + WLog_Print(serial->log, WLOG_DEBUG, "writing %" PRIu32 " bytes to %s", Length, + serial->device.name); + + const void* ptr = Stream_ConstPointer(irp->input); + if (!Stream_SafeSeek(irp->input, Length)) + return ERROR_INVALID_DATA; + /* FIXME: CommWriteFile to be replaced by WriteFile */ + if (CommWriteFile(serial->hComm, ptr, Length, &nbWritten, NULL)) + { + irp->IoStatus = STATUS_SUCCESS; + } + else + { + WLog_Print(serial->log, WLOG_DEBUG, + "write failure to %s, nbWritten=%" PRIu32 ", last-error: 0x%08" PRIX32 "", + serial->device.name, nbWritten, GetLastError()); + irp->IoStatus = GetLastErrorToIoStatus(serial); + } + + WLog_Print(serial->log, WLOG_DEBUG, "%" PRIu32 " bytes written to %s", nbWritten, + serial->device.name); + Stream_Write_UINT32(irp->output, nbWritten); /* Length (4 bytes) */ + Stream_Write_UINT8(irp->output, 0); /* Padding (1 byte) */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT serial_process_irp_device_control(SERIAL_DEVICE* serial, IRP* irp) +{ + UINT32 IoControlCode = 0; + UINT32 InputBufferLength = 0; + BYTE* InputBuffer = NULL; + UINT32 OutputBufferLength = 0; + BYTE* OutputBuffer = NULL; + DWORD BytesReturned = 0; + + WINPR_ASSERT(serial); + WINPR_ASSERT(irp); + + if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(irp->input, OutputBufferLength); /* OutputBufferLength (4 bytes) */ + Stream_Read_UINT32(irp->input, InputBufferLength); /* InputBufferLength (4 bytes) */ + Stream_Read_UINT32(irp->input, IoControlCode); /* IoControlCode (4 bytes) */ + Stream_Seek(irp->input, 20); /* Padding (20 bytes) */ + + if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, InputBufferLength)) + return ERROR_INVALID_DATA; + + OutputBuffer = (BYTE*)calloc(OutputBufferLength, sizeof(BYTE)); + + if (OutputBuffer == NULL) + { + irp->IoStatus = STATUS_NO_MEMORY; + goto error_handle; + } + + InputBuffer = (BYTE*)calloc(InputBufferLength, sizeof(BYTE)); + + if (InputBuffer == NULL) + { + irp->IoStatus = STATUS_NO_MEMORY; + goto error_handle; + } + + Stream_Read(irp->input, InputBuffer, InputBufferLength); + WLog_Print(serial->log, WLOG_DEBUG, + "CommDeviceIoControl: CompletionId=%" PRIu32 ", IoControlCode=[0x%" PRIX32 "] %s", + irp->CompletionId, IoControlCode, _comm_serial_ioctl_name(IoControlCode)); + + /* FIXME: CommDeviceIoControl to be replaced by DeviceIoControl() */ + if (CommDeviceIoControl(serial->hComm, IoControlCode, InputBuffer, InputBufferLength, + OutputBuffer, OutputBufferLength, &BytesReturned, NULL)) + { + /* WLog_Print(serial->log, WLOG_DEBUG, "CommDeviceIoControl: CompletionId=%"PRIu32", + * IoControlCode=[0x%"PRIX32"] %s done", irp->CompletionId, IoControlCode, + * _comm_serial_ioctl_name(IoControlCode)); */ + irp->IoStatus = STATUS_SUCCESS; + } + else + { + WLog_Print(serial->log, WLOG_DEBUG, + "CommDeviceIoControl failure: IoControlCode=[0x%" PRIX32 + "] %s, last-error: 0x%08" PRIX32 "", + IoControlCode, _comm_serial_ioctl_name(IoControlCode), GetLastError()); + irp->IoStatus = GetLastErrorToIoStatus(serial); + } + +error_handle: + /* FIXME: find out whether it's required or not to get + * BytesReturned == OutputBufferLength when + * CommDeviceIoControl returns FALSE */ + WINPR_ASSERT(OutputBufferLength == BytesReturned); + Stream_Write_UINT32(irp->output, BytesReturned); /* OutputBufferLength (4 bytes) */ + + if (BytesReturned > 0) + { + if (!Stream_EnsureRemainingCapacity(irp->output, BytesReturned)) + { + WLog_Print(serial->log, WLOG_ERROR, "Stream_EnsureRemainingCapacity failed!"); + free(InputBuffer); + free(OutputBuffer); + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write(irp->output, OutputBuffer, BytesReturned); /* OutputBuffer */ + } + + /* FIXME: Why at least Windows 2008R2 gets lost with this + * extra byte and likely on a IOCTL_SERIAL_SET_BAUD_RATE? The + * extra byte is well required according MS-RDPEFS + * 2.2.1.5.5 */ + /* else */ + /* { */ + /* Stream_Write_UINT8(irp->output, 0); /\* Padding (1 byte) *\/ */ + /* } */ + free(InputBuffer); + free(OutputBuffer); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT serial_process_irp(SERIAL_DEVICE* serial, IRP* irp) +{ + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(serial); + WINPR_ASSERT(irp); + + WLog_Print(serial->log, WLOG_DEBUG, "IRP MajorFunction: %s, MinorFunction: 0x%08" PRIX32 "\n", + rdpdr_irp_string(irp->MajorFunction), irp->MinorFunction); + + switch (irp->MajorFunction) + { + case IRP_MJ_CREATE: + error = serial_process_irp_create(serial, irp); + break; + + case IRP_MJ_CLOSE: + error = serial_process_irp_close(serial, irp); + break; + + case IRP_MJ_READ: + error = serial_process_irp_read(serial, irp); + break; + + case IRP_MJ_WRITE: + error = serial_process_irp_write(serial, irp); + break; + + case IRP_MJ_DEVICE_CONTROL: + error = serial_process_irp_device_control(serial, irp); + break; + + default: + irp->IoStatus = STATUS_NOT_SUPPORTED; + break; + } + + DWORD level = WLOG_TRACE; + if (error) + level = WLOG_WARN; + + WLog_Print(serial->log, level, + "[%s|0x%08" PRIx32 "] completed with %s [0x%08" PRIx32 "] (IoStatus %s [0x%08" PRIx32 + "])", + rdpdr_irp_string(irp->MajorFunction), irp->MajorFunction, WTSErrorToString(error), + error, NtStatus2Tag(irp->IoStatus), irp->IoStatus); + + return error; +} + +static DWORD WINAPI irp_thread_func(LPVOID arg) +{ + IRP_THREAD_DATA* data = (IRP_THREAD_DATA*)arg; + UINT error = 0; + + WINPR_ASSERT(data); + WINPR_ASSERT(data->serial); + WINPR_ASSERT(data->irp); + + /* blocks until the end of the request */ + if ((error = serial_process_irp(data->serial, data->irp))) + { + WLog_Print(data->serial->log, WLOG_ERROR, + "serial_process_irp failed with error %" PRIu32 "", error); + goto error_out; + } + + EnterCriticalSection(&data->serial->TerminatingIrpThreadsLock); + error = data->irp->Complete(data->irp); + LeaveCriticalSection(&data->serial->TerminatingIrpThreadsLock); +error_out: + + if (error && data->serial->rdpcontext) + setChannelError(data->serial->rdpcontext, error, "irp_thread_func reported an error"); + + /* NB: At this point, the server might already being reusing + * the CompletionId whereas the thread is not yet + * terminated */ + free(data); + ExitThread(error); + return error; +} + +static void close_unterminated_irp_thread(wListDictionary* list, wLog* log, ULONG_PTR id) +{ + WINPR_ASSERT(list); + HANDLE self = _GetCurrentThread(); + HANDLE cirpThread = ListDictionary_GetItemValue(list, (void*)id); + if (self == cirpThread) + WLog_Print(log, WLOG_DEBUG, "Skipping termination of own IRP thread"); + else + ListDictionary_Remove(list, (void*)id); +} + +static void close_terminated_irp_thread(wListDictionary* list, wLog* log, ULONG_PTR id) +{ + WINPR_ASSERT(list); + + HANDLE cirpThread = ListDictionary_GetItemValue(list, (void*)id); + /* FIXME: not quite sure a zero timeout is a good thing to check whether a thread is + * still alive or not */ + const DWORD waitResult = WaitForSingleObject(cirpThread, 0); + + if (waitResult == WAIT_OBJECT_0) + ListDictionary_Remove(list, (void*)id); + else if (waitResult != WAIT_TIMEOUT) + { + /* unexpected thread state */ + WLog_Print(log, WLOG_WARN, "WaitForSingleObject, got an unexpected result=0x%" PRIX32 "\n", + waitResult); + } +} + +void close_terminated_irp_thread_handles(SERIAL_DEVICE* serial, BOOL forceClose) +{ + WINPR_ASSERT(serial); + + EnterCriticalSection(&serial->TerminatingIrpThreadsLock); + + ULONG_PTR* ids = NULL; + const size_t nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids); + + for (size_t i = 0; i < nbIds; i++) + { + ULONG_PTR id = ids[i]; + if (forceClose) + close_unterminated_irp_thread(serial->IrpThreads, serial->log, id); + else + close_terminated_irp_thread(serial->IrpThreads, serial->log, id); + } + + free(ids); + + LeaveCriticalSection(&serial->TerminatingIrpThreadsLock); +} + +static void create_irp_thread(SERIAL_DEVICE* serial, IRP* irp) +{ + IRP_THREAD_DATA* data = NULL; + HANDLE irpThread = NULL; + HANDLE previousIrpThread = NULL; + uintptr_t key = 0; + + WINPR_ASSERT(serial); + WINPR_ASSERT(irp); + + close_terminated_irp_thread_handles(serial, FALSE); + + /* NB: At this point and thanks to the synchronization we're + * sure that the incoming IRP uses well a recycled + * CompletionId or the server sent again an IRP already posted + * which didn't get yet a response (this later server behavior + * at least observed with IOCTL_SERIAL_WAIT_ON_MASK and + * mstsc.exe). + * + * FIXME: behavior documented somewhere? behavior not yet + * observed with FreeRDP). + */ + key = irp->CompletionId + 1ull; + previousIrpThread = ListDictionary_GetItemValue(serial->IrpThreads, (void*)key); + + if (previousIrpThread) + { + /* Thread still alived <=> Request still pending */ + WLog_Print(serial->log, WLOG_DEBUG, + "IRP recall: IRP with the CompletionId=%" PRIu32 " not yet completed!", + irp->CompletionId); + WINPR_ASSERT(FALSE); /* unimplemented */ + /* TODO: WINPR_ASSERTs that previousIrpThread handles well + * the same request by checking more details. Need an + * access to the IRP object used by previousIrpThread + */ + /* TODO: taking over the pending IRP or sending a kind + * of wake up signal to accelerate the pending + * request + * + * To be considered: + * if (IoControlCode == IOCTL_SERIAL_WAIT_ON_MASK) { + * pComm->PendingEvents |= SERIAL_EV_FREERDP_*; + * } + */ + irp->Discard(irp); + return; + } + + if (ListDictionary_Count(serial->IrpThreads) >= MAX_IRP_THREADS) + { + WLog_Print(serial->log, WLOG_WARN, + "Number of IRP threads threshold reached: %" PRIuz ", keep on anyway", + ListDictionary_Count(serial->IrpThreads)); + WINPR_ASSERT(FALSE); /* unimplemented */ + /* TODO: MAX_IRP_THREADS has been thought to avoid a + * flooding of pending requests. Use + * WaitForMultipleObjects() when available in winpr + * for threads. + */ + } + + /* error_handle to be used ... */ + data = (IRP_THREAD_DATA*)calloc(1, sizeof(IRP_THREAD_DATA)); + + if (data == NULL) + { + WLog_Print(serial->log, WLOG_WARN, "Could not allocate a new IRP_THREAD_DATA."); + goto error_handle; + } + + data->serial = serial; + data->irp = irp; + /* data freed by irp_thread_func */ + irpThread = CreateThread(NULL, 0, irp_thread_func, (void*)data, CREATE_SUSPENDED, NULL); + + if (irpThread == INVALID_HANDLE_VALUE) + { + WLog_Print(serial->log, WLOG_WARN, "Could not allocate a new IRP thread."); + goto error_handle; + } + + key = irp->CompletionId + 1ull; + + if (!ListDictionary_Add(serial->IrpThreads, (void*)key, irpThread)) + { + WLog_Print(serial->log, WLOG_ERROR, "ListDictionary_Add failed!"); + goto error_handle; + } + + ResumeThread(irpThread); + + return; +error_handle: + if (irpThread) + (void)CloseHandle(irpThread); + irp->IoStatus = STATUS_NO_MEMORY; + irp->Complete(irp); + free(data); +} + +static DWORD WINAPI serial_thread_func(LPVOID arg) +{ + IRP* irp = NULL; + wMessage message = { 0 }; + SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(serial); + + while (1) + { + if (!MessageQueue_Wait(serial->MainIrpQueue)) + { + WLog_Print(serial->log, WLOG_ERROR, "MessageQueue_Wait failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (!MessageQueue_Peek(serial->MainIrpQueue, &message, TRUE)) + { + WLog_Print(serial->log, WLOG_ERROR, "MessageQueue_Peek failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (message.id == WMQ_QUIT) + break; + + irp = (IRP*)message.wParam; + + if (irp) + create_irp_thread(serial, irp); + } + + ListDictionary_Clear(serial->IrpThreads); + if (error && serial->rdpcontext) + setChannelError(serial->rdpcontext, error, "serial_thread_func reported an error"); + + ExitThread(error); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT serial_irp_request(DEVICE* device, IRP* irp) +{ + SERIAL_DEVICE* serial = (SERIAL_DEVICE*)device; + WINPR_ASSERT(irp != NULL); + WINPR_ASSERT(serial); + + if (irp == NULL) + return CHANNEL_RC_OK; + + /* NB: ENABLE_ASYNCIO is set, (MS-RDPEFS 2.2.2.7.2) this + * allows the server to send multiple simultaneous read or + * write requests. + */ + + if (!MessageQueue_Post(serial->MainIrpQueue, NULL, 0, (void*)irp, NULL)) + { + WLog_Print(serial->log, WLOG_ERROR, "MessageQueue_Post failed!"); + return ERROR_INTERNAL_ERROR; + } + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT serial_free(DEVICE* device) +{ + UINT error = 0; + SERIAL_DEVICE* serial = (SERIAL_DEVICE*)device; + if (!serial) + return CHANNEL_RC_OK; + + WLog_Print(serial->log, WLOG_DEBUG, "freeing"); + if (serial->MainIrpQueue) + MessageQueue_PostQuit(serial->MainIrpQueue, 0); + + if (serial->MainThread) + { + if (WaitForSingleObject(serial->MainThread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_Print(serial->log, WLOG_ERROR, + "WaitForSingleObject failed with error %" PRIu32 "!", error); + } + (void)CloseHandle(serial->MainThread); + } + + if (serial->hComm) + (void)CloseHandle(serial->hComm); + + /* Clean up resources */ + Stream_Free(serial->device.data, TRUE); + MessageQueue_Free(serial->MainIrpQueue); + ListDictionary_Free(serial->IrpThreads); + DeleteCriticalSection(&serial->TerminatingIrpThreadsLock); + free(serial); + return CHANNEL_RC_OK; +} + +static void serial_message_free(void* obj) +{ + wMessage* msg = obj; + if (!msg) + return; + if (msg->id != 0) + return; + + IRP* irp = (IRP*)msg->wParam; + if (!irp) + return; + WINPR_ASSERT(irp->Discard); + irp->Discard(irp); +} + +static void irp_thread_close(void* arg) +{ + HANDLE hdl = arg; + if (hdl) + { + HANDLE thz = _GetCurrentThread(); + if (thz == hdl) + WLog_WARN(TAG, "closing self, ignoring..."); + else + { + (void)TerminateThread(hdl, 0); + (void)WaitForSingleObject(hdl, INFINITE); + (void)CloseHandle(hdl); + } + } +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT( + UINT VCAPITYPE serial_DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints)) +{ + size_t len = 0; + SERIAL_DEVICE* serial = NULL; + UINT error = CHANNEL_RC_OK; + + WINPR_ASSERT(pEntryPoints); + + RDPDR_SERIAL* device = (RDPDR_SERIAL*)pEntryPoints->device; + WINPR_ASSERT(device); + + wLog* log = WLog_Get(TAG); + const char* name = device->device.Name; + const char* path = device->Path; + const char* driver = device->Driver; + + if (!name || (name[0] == '*')) + { + /* TODO: implement auto detection of serial ports */ + WLog_Print(log, WLOG_WARN, + "Serial port autodetection not implemented, nothing will be redirected!"); + return CHANNEL_RC_OK; + } + + if ((name && name[0]) && (path && path[0])) + { + WLog_Print(log, WLOG_DEBUG, "Defining %s as %s", name, path); + + if (!DefineCommDevice(name /* eg: COM1 */, path /* eg: /dev/ttyS0 */)) + { + DWORD status = GetLastError(); + WLog_Print(log, WLOG_ERROR, "DefineCommDevice failed with %08" PRIx32, status); + return ERROR_INTERNAL_ERROR; + } + + serial = (SERIAL_DEVICE*)calloc(1, sizeof(SERIAL_DEVICE)); + + if (!serial) + { + WLog_Print(log, WLOG_ERROR, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + serial->log = log; + serial->device.type = RDPDR_DTYP_SERIAL; + serial->device.name = name; + serial->device.IRPRequest = serial_irp_request; + serial->device.Free = serial_free; + serial->rdpcontext = pEntryPoints->rdpcontext; + len = strlen(name); + serial->device.data = Stream_New(NULL, len + 1); + + if (!serial->device.data) + { + WLog_Print(serial->log, WLOG_ERROR, "calloc failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + for (size_t i = 0; i <= len; i++) + Stream_Write_INT8(serial->device.data, name[i] < 0 ? '_' : name[i]); + + if (driver != NULL) + { + if (_stricmp(driver, "Serial") == 0) + serial->ServerSerialDriverId = SerialDriverSerialSys; + else if (_stricmp(driver, "SerCx") == 0) + serial->ServerSerialDriverId = SerialDriverSerCxSys; + else if (_stricmp(driver, "SerCx2") == 0) + serial->ServerSerialDriverId = SerialDriverSerCx2Sys; + else + { + WLog_Print(serial->log, WLOG_WARN, "Unknown server's serial driver: %s.", driver); + WLog_Print(serial->log, WLOG_WARN, + "Valid options are: 'Serial' (default), 'SerCx' and 'SerCx2'"); + goto error_out; + } + } + else + { + /* default driver */ + serial->ServerSerialDriverId = SerialDriverSerialSys; + } + + if (device->Permissive != NULL) + { + if (_stricmp(device->Permissive, "permissive") == 0) + { + serial->permissive = TRUE; + } + else + { + WLog_Print(serial->log, WLOG_WARN, "Unknown flag: %s", device->Permissive); + goto error_out; + } + } + + WLog_Print(serial->log, WLOG_DEBUG, "Server's serial driver: %s (id: %d)", driver, + serial->ServerSerialDriverId); + + serial->MainIrpQueue = MessageQueue_New(NULL); + + if (!serial->MainIrpQueue) + { + WLog_Print(serial->log, WLOG_ERROR, "MessageQueue_New failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + { + wObject* obj = MessageQueue_Object(serial->MainIrpQueue); + WINPR_ASSERT(obj); + obj->fnObjectFree = serial_message_free; + } + + /* IrpThreads content only modified by create_irp_thread() */ + serial->IrpThreads = ListDictionary_New(FALSE); + + if (!serial->IrpThreads) + { + WLog_Print(serial->log, WLOG_ERROR, "ListDictionary_New failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto error_out; + } + + { + wObject* obj = ListDictionary_ValueObject(serial->IrpThreads); + WINPR_ASSERT(obj); + obj->fnObjectFree = irp_thread_close; + } + + InitializeCriticalSection(&serial->TerminatingIrpThreadsLock); + + error = pEntryPoints->RegisterDevice(pEntryPoints->devman, &serial->device); + if (error != CHANNEL_RC_OK) + { + WLog_Print(serial->log, WLOG_ERROR, + "EntryPoints->RegisterDevice failed with error %" PRIu32 "!", error); + goto error_out; + } + + serial->MainThread = CreateThread(NULL, 0, serial_thread_func, serial, 0, NULL); + if (!serial->MainThread) + { + WLog_Print(serial->log, WLOG_ERROR, "CreateThread failed!"); + error = ERROR_INTERNAL_ERROR; + goto error_out; + } + } + + return error; +error_out: + if (serial) + serial_free(&serial->device); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5b55d145604c4713e73a23fae17a413318ea942c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/server/CMakeLists.txt @@ -0,0 +1,36 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(MODULE_NAME "freerdp-channels-server") +set(MODULE_PREFIX "FREERDP_CHANNELS_SERVER") + +set(${MODULE_PREFIX}_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/channels.c ${CMAKE_CURRENT_SOURCE_DIR}/channels.h) + +foreach(STATIC_MODULE ${CHANNEL_STATIC_SERVER_MODULES}) + set(STATIC_MODULE_NAME ${${STATIC_MODULE}_SERVER_NAME}) + set(STATIC_MODULE_CHANNEL ${${STATIC_MODULE}_SERVER_CHANNEL}) + set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${STATIC_MODULE_NAME}) +endforeach() + +add_library(${MODULE_NAME} STATIC ${${MODULE_PREFIX}_SRCS}) + +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) + +set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} PARENT_SCOPE) +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE) + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Server/Common") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/server/channels.c b/local-test-freerdp-delta-01/afc-freerdp/channels/server/channels.c new file mode 100644 index 0000000000000000000000000000000000000000..19b57310d4dab7b15bb9ebbbe38843378e552cc4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/server/channels.c @@ -0,0 +1,195 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Channels + * + * Copyright 2011-2012 Vic Lee + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "channels.h" + +/** + * this is a workaround to force importing symbols + * will need to fix that later on cleanly + */ + +#if defined(CHANNEL_AUDIN_SERVER) +#include +#endif +#include +#include +#include +#include +#if defined(CHANNEL_RAIL_SERVER) +#include +#endif +#include +#include +#include +#if defined(CHANNEL_RAIL_SERVER) +#include +#endif +#include +#if defined(CHANNEL_RDPGFX_SERVER) +#include +#endif +#if defined(CHANNEL_DISP_SERVER) +#include +#endif + +#if defined(CHANNEL_RDPEMSC_SERVER) +#include +#endif /* CHANNEL_RDPEMSC_SERVER */ + +#if defined(CHANNEL_RDPECAM_SERVER) +#include +#include +#endif + +#if defined(CHANNEL_LOCATION_SERVER) +#include +#endif /* CHANNEL_LOCATION_SERVER */ + +#ifdef WITH_CHANNEL_GFXREDIR +#include +#endif /* WITH_CHANNEL_GFXREDIR */ + +#if defined(CHANNEL_AINPUT_SERVER) +#include +#endif + +extern void freerdp_channels_dummy(void); + +void freerdp_channels_dummy(void) +{ +#if defined(CHANNEL_AUDIN_SERVER) + audin_server_context* audin = NULL; +#endif + RdpsndServerContext* rdpsnd = NULL; + CliprdrServerContext* cliprdr = NULL; + echo_server_context* echo = NULL; + RdpdrServerContext* rdpdr = NULL; + DrdynvcServerContext* drdynvc = NULL; +#if defined(CHANNEL_RDPEI_SERVER) + RdpeiServerContext* rdpei = NULL; +#endif + RemdeskServerContext* remdesk = NULL; + EncomspServerContext* encomsp = NULL; +#if defined(CHANNEL_RAIL_SERVER) + RailServerContext* rail = NULL; +#endif + TelemetryServerContext* telemetry = NULL; +#if defined(CHANNEL_RDPGFX_SERVER) + RdpgfxServerContext* rdpgfx = NULL; +#endif +#if defined(CHANNEL_DISP_SERVER) + DispServerContext* disp = NULL; +#endif +#if defined(CHANNEL_RDPEMSC_SERVER) + MouseCursorServerContext* mouse_cursor = NULL; +#endif /* CHANNEL_RDPEMSC_SERVER */ +#if defined(CHANNEL_RDPECAM_SERVER) + CamDevEnumServerContext* camera_enumerator = NULL; + CameraDeviceServerContext* camera_device = NULL; +#endif +#if defined(CHANNEL_LOCATION_SERVER) + LocationServerContext* location = NULL; +#endif /* CHANNEL_LOCATION_SERVER */ +#ifdef WITH_CHANNEL_GFXREDIR + GfxRedirServerContext* gfxredir; +#endif // WITH_CHANNEL_GFXREDIR +#if defined(CHANNEL_AUDIN_SERVER) + audin = audin_server_context_new(NULL); +#endif +#if defined(CHANNEL_AUDIN_SERVER) + audin_server_context_free(audin); +#endif + rdpsnd = rdpsnd_server_context_new(NULL); + rdpsnd_server_context_free(rdpsnd); + cliprdr = cliprdr_server_context_new(NULL); + cliprdr_server_context_free(cliprdr); + echo = echo_server_context_new(NULL); + echo_server_context_free(echo); + rdpdr = rdpdr_server_context_new(NULL); + rdpdr_server_context_free(rdpdr); + drdynvc = drdynvc_server_context_new(NULL); + drdynvc_server_context_free(drdynvc); +#if defined(CHANNEL_RDPEI_SERVER) + rdpei = rdpei_server_context_new(NULL); + rdpei_server_context_free(rdpei); +#endif + remdesk = remdesk_server_context_new(NULL); + remdesk_server_context_free(remdesk); + encomsp = encomsp_server_context_new(NULL); + encomsp_server_context_free(encomsp); +#if defined(CHANNEL_RAIL_SERVER) + rail = rail_server_context_new(NULL); + rail_server_context_free(rail); +#endif + telemetry = telemetry_server_context_new(NULL); + telemetry_server_context_free(telemetry); +#if defined(CHANNEL_RDPGFX_SERVER) + rdpgfx = rdpgfx_server_context_new(NULL); + rdpgfx_server_context_free(rdpgfx); +#endif +#if defined(CHANNEL_DISP_SERVER) + disp = disp_server_context_new(NULL); + disp_server_context_free(disp); +#endif +#if defined(CHANNEL_RDPEMSC_SERVER) + mouse_cursor = mouse_cursor_server_context_new(NULL); + mouse_cursor_server_context_free(mouse_cursor); +#endif /* CHANNEL_RDPEMSC_SERVER */ + +#if defined(CHANNEL_RDPECAM_SERVER) + camera_enumerator = cam_dev_enum_server_context_new(NULL); + cam_dev_enum_server_context_free(camera_enumerator); + camera_device = camera_device_server_context_new(NULL); + camera_device_server_context_free(camera_device); +#endif + +#if defined(CHANNEL_LOCATION_SERVER) + location = location_server_context_new(NULL); + location_server_context_free(location); +#endif /* CHANNEL_LOCATION_SERVER */ + +#ifdef WITH_CHANNEL_GFXREDIR + gfxredir = gfxredir_server_context_new(NULL); + gfxredir_server_context_free(gfxredir); +#endif // WITH_CHANNEL_GFXREDIR +#if defined(CHANNEL_AINPUT_SERVER) + { + ainput_server_context* ainput = ainput_server_context_new(NULL); + ainput_server_context_free(ainput); + } +#endif +} + +/** + * end of ugly symbols import workaround + */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/server/channels.h b/local-test-freerdp-delta-01/afc-freerdp/channels/server/channels.h new file mode 100644 index 0000000000000000000000000000000000000000..a6c4791cab090efd3b97315c3b246e50a10b5eab --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/server/channels.h @@ -0,0 +1,24 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Channels + * + * Copyright 2011-2012 Vic Lee + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_SERVER_CHANNELS_H +#define FREERDP_CHANNEL_SERVER_CHANNELS_H + +#endif /* FREERDP_CHANNEL_SERVER_CHANNELS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..00ad99eea6fd068180c5ee6bcd5e83c6c0b78138 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("smartcard") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..14966b0e68329eacf735c729e41253d1733855f7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options( + NAME + "smartcard" + TYPE + "device" + DESCRIPTION + "Smart Card Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPESC]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..473f3d987af4241b21287d88f2fbefdc0a89ce06 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/smartcard/client/CMakeLists.txt @@ -0,0 +1,26 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("smartcard") + +set(${MODULE_PREFIX}_SRCS smartcard_main.c smartcard_main.h) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${OPENSSL_LIBRARIES}) +if(WITH_SMARTCARD_EMULATE) + list(APPEND ${MODULE_PREFIX}_LIBS ZLIB::ZLIB) +endif() +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DeviceServiceEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d0e7c1250929703fcc4ec45e8f045124dca49134 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/CMakeLists.txt @@ -0,0 +1,23 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# Copyright 2017 Ben Cohen +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("sshagent") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6672256a6c20efa783c8d2e7e00d923a4f3f1020 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT OFF) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "sshagent" + TYPE + "dynamic" + DESCRIPTION + "SSH Agent Forwarding (experimental)" + SPECIFICATIONS + "" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b09c4f6b51d2158b8f990bd473079c9aaf7572b0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# Copyright 2017 Ben Cohen +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("sshagent") + +set(${MODULE_PREFIX}_SRCS sshagent_main.c sshagent_main.h) + +set(${MODULE_PREFIX}_LIBS winpr) + +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/sshagent_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/sshagent_main.c new file mode 100644 index 0000000000000000000000000000000000000000..28025c262ef5fc8778e06b9f6fa5addd4a982d58 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/sshagent_main.c @@ -0,0 +1,398 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * SSH Agent Virtual Channel Extension + * + * Copyright 2013 Christian Hofstaedtler + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2017 Ben Cohen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * sshagent_main.c: DVC plugin to forward queries from RDP to the ssh-agent + * + * This relays data to and from an ssh-agent program equivalent running on the + * RDP server to an ssh-agent running locally. Unlike the normal ssh-agent, + * which sends data over an SSH channel, the data is send over an RDP dynamic + * virtual channel. + * + * protocol specification: + * Forward data verbatim over RDP dynamic virtual channel named "sshagent" + * between a ssh client on the xrdp server and the real ssh-agent where + * the RDP client is running. Each connection by a separate client to + * xrdp-ssh-agent gets a separate DVC invocation. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "sshagent_main.h" + +#include +#include +#include + +#define TAG CHANNELS_TAG("sshagent.client") + +typedef struct +{ + IWTSListenerCallback iface; + + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; + + rdpContext* rdpcontext; + const char* agent_uds_path; +} SSHAGENT_LISTENER_CALLBACK; + +typedef struct +{ + GENERIC_CHANNEL_CALLBACK generic; + + rdpContext* rdpcontext; + int agent_fd; + HANDLE thread; + CRITICAL_SECTION lock; +} SSHAGENT_CHANNEL_CALLBACK; + +typedef struct +{ + IWTSPlugin iface; + + SSHAGENT_LISTENER_CALLBACK* listener_callback; + + rdpContext* rdpcontext; +} SSHAGENT_PLUGIN; + +/** + * Function to open the connection to the sshagent + * + * @return The fd on success, otherwise -1 + */ +static int connect_to_sshagent(const char* udspath) +{ + WINPR_ASSERT(udspath); + + int agent_fd = socket(AF_UNIX, SOCK_STREAM, 0); + + if (agent_fd == -1) + { + WLog_ERR(TAG, "Can't open Unix domain socket!"); + return -1; + } + + struct sockaddr_un addr = { 0 }; + + addr.sun_family = AF_UNIX; + + strncpy(addr.sun_path, udspath, sizeof(addr.sun_path) - 1); + + int rc = connect(agent_fd, (struct sockaddr*)&addr, sizeof(addr)); + + if (rc != 0) + { + WLog_ERR(TAG, "Can't connect to Unix domain socket \"%s\"!", udspath); + close(agent_fd); + return -1; + } + + return agent_fd; +} + +/** + * Entry point for thread to read from the ssh-agent socket and forward + * the data to RDP + * + * @return NULL + */ +static DWORD WINAPI sshagent_read_thread(LPVOID data) +{ + SSHAGENT_CHANNEL_CALLBACK* callback = (SSHAGENT_CHANNEL_CALLBACK*)data; + WINPR_ASSERT(callback); + + BYTE buffer[4096] = { 0 }; + int going = 1; + UINT status = CHANNEL_RC_OK; + + while (going) + { + const ssize_t bytes_read = read(callback->agent_fd, buffer, sizeof(buffer)); + + if (bytes_read == 0) + { + /* Socket closed cleanly at other end */ + going = 0; + } + else if (bytes_read < 0) + { + if (errno != EINTR) + { + WLog_ERR(TAG, "Error reading from sshagent, errno=%d", errno); + status = ERROR_READ_FAULT; + going = 0; + } + } + else if ((size_t)bytes_read > ULONG_MAX) + { + status = ERROR_READ_FAULT; + going = 0; + } + else + { + /* Something read: forward to virtual channel */ + IWTSVirtualChannel* channel = callback->generic.channel; + status = channel->Write(channel, (ULONG)bytes_read, buffer, NULL); + + if (status != CHANNEL_RC_OK) + { + going = 0; + } + } + } + + close(callback->agent_fd); + + if (status != CHANNEL_RC_OK) + setChannelError(callback->rdpcontext, status, "sshagent_read_thread reported an error"); + + ExitThread(status); + return status; +} + +/** + * Callback for data received from the RDP server; forward this to ssh-agent + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT sshagent_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + SSHAGENT_CHANNEL_CALLBACK* callback = (SSHAGENT_CHANNEL_CALLBACK*)pChannelCallback; + WINPR_ASSERT(callback); + + BYTE* pBuffer = Stream_Pointer(data); + size_t cbSize = Stream_GetRemainingLength(data); + BYTE* pos = pBuffer; + /* Forward what we have received to the ssh agent */ + size_t bytes_to_write = cbSize; + errno = 0; + + while (bytes_to_write > 0) + { + const ssize_t bytes_written = write(callback->agent_fd, pos, bytes_to_write); + + if (bytes_written < 0) + { + if (errno != EINTR) + { + WLog_ERR(TAG, "Error writing to sshagent, errno=%d", errno); + return ERROR_WRITE_FAULT; + } + } + else + { + bytes_to_write -= WINPR_ASSERTING_INT_CAST(size_t, bytes_written); + pos += bytes_written; + } + } + + /* Consume stream */ + Stream_Seek(data, cbSize); + return CHANNEL_RC_OK; +} + +/** + * Callback for when the virtual channel is closed + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT sshagent_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + SSHAGENT_CHANNEL_CALLBACK* callback = (SSHAGENT_CHANNEL_CALLBACK*)pChannelCallback; + WINPR_ASSERT(callback); + + /* Call shutdown() to wake up the read() in sshagent_read_thread(). */ + shutdown(callback->agent_fd, SHUT_RDWR); + EnterCriticalSection(&callback->lock); + + if (WaitForSingleObject(callback->thread, INFINITE) == WAIT_FAILED) + { + UINT error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error); + return error; + } + + (void)CloseHandle(callback->thread); + LeaveCriticalSection(&callback->lock); + DeleteCriticalSection(&callback->lock); + free(callback); + return CHANNEL_RC_OK; +} + +/** + * Callback for when a new virtual channel is opened + * + * @return 0 on success, otherwise a Win32 error code + */ +// NOLINTBEGIN(readability-non-const-parameter) +static UINT sshagent_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, + IWTSVirtualChannel* pChannel, BYTE* Data, + BOOL* pbAccept, + IWTSVirtualChannelCallback** ppCallback) +// NOLINTEND(readability-non-const-parameter) +{ + SSHAGENT_LISTENER_CALLBACK* listener_callback = (SSHAGENT_LISTENER_CALLBACK*)pListenerCallback; + WINPR_UNUSED(Data); + WINPR_UNUSED(pbAccept); + + SSHAGENT_CHANNEL_CALLBACK* callback = + (SSHAGENT_CHANNEL_CALLBACK*)calloc(1, sizeof(SSHAGENT_CHANNEL_CALLBACK)); + + if (!callback) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + /* Now open a connection to the local ssh-agent. Do this for each + * connection to the plugin in case we mess up the agent session. */ + callback->agent_fd = connect_to_sshagent(listener_callback->agent_uds_path); + + if (callback->agent_fd == -1) + { + free(callback); + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + InitializeCriticalSection(&callback->lock); + + GENERIC_CHANNEL_CALLBACK* generic = &callback->generic; + generic->iface.OnDataReceived = sshagent_on_data_received; + generic->iface.OnClose = sshagent_on_close; + generic->plugin = listener_callback->plugin; + generic->channel_mgr = listener_callback->channel_mgr; + generic->channel = pChannel; + callback->rdpcontext = listener_callback->rdpcontext; + callback->thread = CreateThread(NULL, 0, sshagent_read_thread, (void*)callback, 0, NULL); + + if (!callback->thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + DeleteCriticalSection(&callback->lock); + free(callback); + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + *ppCallback = (IWTSVirtualChannelCallback*)callback; + return CHANNEL_RC_OK; +} + +/** + * Callback for when the plugin is initialised + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT sshagent_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr) +{ + SSHAGENT_PLUGIN* sshagent = (SSHAGENT_PLUGIN*)pPlugin; + WINPR_ASSERT(sshagent); + WINPR_ASSERT(pChannelMgr); + + sshagent->listener_callback = + (SSHAGENT_LISTENER_CALLBACK*)calloc(1, sizeof(SSHAGENT_LISTENER_CALLBACK)); + + if (!sshagent->listener_callback) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + sshagent->listener_callback->rdpcontext = sshagent->rdpcontext; + sshagent->listener_callback->iface.OnNewChannelConnection = sshagent_on_new_channel_connection; + sshagent->listener_callback->plugin = pPlugin; + sshagent->listener_callback->channel_mgr = pChannelMgr; + // NOLINTNEXTLINE(concurrency-mt-unsafe) + sshagent->listener_callback->agent_uds_path = getenv("SSH_AUTH_SOCK"); + + if (sshagent->listener_callback->agent_uds_path == NULL) + { + WLog_ERR(TAG, "Environment variable $SSH_AUTH_SOCK undefined!"); + free(sshagent->listener_callback); + sshagent->listener_callback = NULL; + return CHANNEL_RC_INITIALIZATION_ERROR; + } + + return pChannelMgr->CreateListener(pChannelMgr, "SSHAGENT", 0, + (IWTSListenerCallback*)sshagent->listener_callback, NULL); +} + +/** + * Callback for when the plugin is terminated + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT sshagent_plugin_terminated(IWTSPlugin* pPlugin) +{ + SSHAGENT_PLUGIN* sshagent = (SSHAGENT_PLUGIN*)pPlugin; + free(sshagent); + return CHANNEL_RC_OK; +} + +/** + * Main entry point for sshagent DVC plugin + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE sshagent_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + UINT status = CHANNEL_RC_OK; + + WINPR_ASSERT(pEntryPoints); + + SSHAGENT_PLUGIN* sshagent = (SSHAGENT_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, "sshagent"); + + if (!sshagent) + { + sshagent = (SSHAGENT_PLUGIN*)calloc(1, sizeof(SSHAGENT_PLUGIN)); + + if (!sshagent) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + sshagent->iface.Initialize = sshagent_plugin_initialize; + sshagent->iface.Connected = NULL; + sshagent->iface.Disconnected = NULL; + sshagent->iface.Terminated = sshagent_plugin_terminated; + sshagent->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); + status = pEntryPoints->RegisterPlugin(pEntryPoints, "sshagent", &sshagent->iface); + } + + return status; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/sshagent_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/sshagent_main.h new file mode 100644 index 0000000000000000000000000000000000000000..1fcc21473f202fa7f621274cc3adc6bc70580dcf --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/sshagent/client/sshagent_main.h @@ -0,0 +1,42 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * SSH Agent Virtual Channel Extension + * + * Copyright 2013 Christian Hofstaedtler + * Copyright 2017 Ben Cohen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SSHAGENT_MAIN_H +#define SSHAGENT_MAIN_H + +#include + +#include + +#include +#include +#include + +#define DVC_TAG CHANNELS_TAG("sshagent.client") +#ifdef WITH_DEBUG_SSHAGENT +#define DEBUG_SSHAGENT(...) WLog_DBG(DVC_TAG, __VA_ARGS__) +#else +#define DEBUG_SSHAGENT(...) \ + do \ + { \ + } while (0) +#endif + +#endif /* SSHAGENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ddef6f7aab352a0589538de859e92a8b798eeaf6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2022 Pascal Nowack +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("telemetry") + +if(WITH_SERVER_CHANNELS) + add_channel_server(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..153fd57b38c391942a3fb04d7a6cc7da21084a39 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT OFF) +set(OPTION_SERVER_DEFAULT ON) + +define_channel_options( + NAME + "telemetry" + TYPE + "dynamic" + DESCRIPTION + "Telemetry Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPET]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/server/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/server/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea023cb618197ea173aaa67eb9cf2e8f4d41d670 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/server/CMakeLists.txt @@ -0,0 +1,24 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2022 Pascal Nowack +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_server("telemetry") + +set(${MODULE_PREFIX}_SRCS telemetry_main.c) + +set(${MODULE_PREFIX}_LIBS freerdp) + +add_channel_server_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} FALSE "DVCPluginEntry") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/server/telemetry_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/server/telemetry_main.c new file mode 100644 index 0000000000000000000000000000000000000000..9be00f209f7e70f0401f54726630da3c9693eafd --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/telemetry/server/telemetry_main.c @@ -0,0 +1,448 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Telemetry Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#define TAG CHANNELS_TAG("telemetry.server") + +typedef enum +{ + TELEMETRY_INITIAL, + TELEMETRY_OPENED, +} eTelemetryChannelState; + +typedef struct +{ + TelemetryServerContext context; + + HANDLE stopEvent; + + HANDLE thread; + void* telemetry_channel; + + DWORD SessionId; + + BOOL isOpened; + BOOL externalThread; + + /* Channel state */ + eTelemetryChannelState state; + + wStream* buffer; +} telemetry_server; + +static UINT telemetry_server_initialize(TelemetryServerContext* context, BOOL externalThread) +{ + UINT error = CHANNEL_RC_OK; + telemetry_server* telemetry = (telemetry_server*)context; + + WINPR_ASSERT(telemetry); + + if (telemetry->isOpened) + { + WLog_WARN(TAG, "Application error: TELEMETRY channel already initialized, " + "calling in this state is not possible!"); + return ERROR_INVALID_STATE; + } + + telemetry->externalThread = externalThread; + + return error; +} + +static UINT telemetry_server_open_channel(telemetry_server* telemetry) +{ + TelemetryServerContext* context = &telemetry->context; + DWORD Error = ERROR_SUCCESS; + HANDLE hEvent = NULL; + DWORD BytesReturned = 0; + PULONG pSessionId = NULL; + UINT32 channelId = 0; + BOOL status = TRUE; + + WINPR_ASSERT(telemetry); + + if (WTSQuerySessionInformationA(telemetry->context.vcm, WTS_CURRENT_SESSION, WTSSessionId, + (LPSTR*)&pSessionId, &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); + return ERROR_INTERNAL_ERROR; + } + + telemetry->SessionId = (DWORD)*pSessionId; + WTSFreeMemory(pSessionId); + hEvent = WTSVirtualChannelManagerGetEventHandle(telemetry->context.vcm); + + if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED) + { + Error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", Error); + return Error; + } + + telemetry->telemetry_channel = WTSVirtualChannelOpenEx( + telemetry->SessionId, TELEMETRY_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC); + if (!telemetry->telemetry_channel) + { + Error = GetLastError(); + WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed with error %" PRIu32 "!", Error); + return Error; + } + + channelId = WTSChannelGetIdByHandle(telemetry->telemetry_channel); + + IFCALLRET(context->ChannelIdAssigned, status, context, channelId); + if (!status) + { + WLog_ERR(TAG, "context->ChannelIdAssigned failed!"); + return ERROR_INTERNAL_ERROR; + } + + return Error; +} + +static UINT telemetry_server_recv_rdp_telemetry_pdu(TelemetryServerContext* context, wStream* s) +{ + TELEMETRY_RDP_TELEMETRY_PDU pdu; + UINT error = CHANNEL_RC_OK; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 16)) + return ERROR_NO_DATA; + + Stream_Read_UINT32(s, pdu.PromptForCredentialsMillis); + Stream_Read_UINT32(s, pdu.PromptForCredentialsDoneMillis); + Stream_Read_UINT32(s, pdu.GraphicsChannelOpenedMillis); + Stream_Read_UINT32(s, pdu.FirstGraphicsReceivedMillis); + + IFCALLRET(context->RdpTelemetry, error, context, &pdu); + if (error) + WLog_ERR(TAG, "context->RdpTelemetry failed with error %" PRIu32 "", error); + + return error; +} + +static UINT telemetry_process_message(telemetry_server* telemetry) +{ + BOOL rc = 0; + UINT error = ERROR_INTERNAL_ERROR; + ULONG BytesReturned = 0; + BYTE MessageId = 0; + BYTE Length = 0; + wStream* s = NULL; + + WINPR_ASSERT(telemetry); + WINPR_ASSERT(telemetry->telemetry_channel); + + s = telemetry->buffer; + WINPR_ASSERT(s); + + Stream_SetPosition(s, 0); + rc = WTSVirtualChannelRead(telemetry->telemetry_channel, 0, NULL, 0, &BytesReturned); + if (!rc) + goto out; + + if (BytesReturned < 1) + { + error = CHANNEL_RC_OK; + goto out; + } + + if (!Stream_EnsureRemainingCapacity(s, BytesReturned)) + { + WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); + error = CHANNEL_RC_NO_MEMORY; + goto out; + } + + if (WTSVirtualChannelRead(telemetry->telemetry_channel, 0, Stream_BufferAs(s, char), + (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE) + { + WLog_ERR(TAG, "WTSVirtualChannelRead failed!"); + goto out; + } + + Stream_SetLength(s, BytesReturned); + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return ERROR_NO_DATA; + + Stream_Read_UINT8(s, MessageId); + Stream_Read_UINT8(s, Length); + if (!Stream_CheckAndLogRequiredLength(TAG, s, Length)) + return ERROR_NO_DATA; + + switch (MessageId) + { + case 0x01: + error = telemetry_server_recv_rdp_telemetry_pdu(&telemetry->context, s); + break; + default: + WLog_ERR(TAG, "telemetry_process_message: unknown MessageId %" PRIu8 "", MessageId); + break; + } + +out: + if (error) + WLog_ERR(TAG, "Response failed with error %" PRIu32 "!", error); + + return error; +} + +static UINT telemetry_server_context_poll_int(TelemetryServerContext* context) +{ + telemetry_server* telemetry = (telemetry_server*)context; + UINT error = ERROR_INTERNAL_ERROR; + + WINPR_ASSERT(telemetry); + + switch (telemetry->state) + { + case TELEMETRY_INITIAL: + error = telemetry_server_open_channel(telemetry); + if (error) + WLog_ERR(TAG, "telemetry_server_open_channel failed with error %" PRIu32 "!", + error); + else + telemetry->state = TELEMETRY_OPENED; + break; + case TELEMETRY_OPENED: + error = telemetry_process_message(telemetry); + break; + default: + break; + } + + return error; +} + +static HANDLE telemetry_server_get_channel_handle(telemetry_server* telemetry) +{ + void* buffer = NULL; + DWORD BytesReturned = 0; + HANDLE ChannelEvent = NULL; + + WINPR_ASSERT(telemetry); + + if (WTSVirtualChannelQuery(telemetry->telemetry_channel, WTSVirtualEventHandle, &buffer, + &BytesReturned) == TRUE) + { + if (BytesReturned == sizeof(HANDLE)) + ChannelEvent = *(HANDLE*)buffer; + + WTSFreeMemory(buffer); + } + + return ChannelEvent; +} + +static DWORD WINAPI telemetry_server_thread_func(LPVOID arg) +{ + DWORD nCount = 0; + HANDLE events[2] = { 0 }; + telemetry_server* telemetry = (telemetry_server*)arg; + UINT error = CHANNEL_RC_OK; + DWORD status = 0; + + WINPR_ASSERT(telemetry); + + nCount = 0; + events[nCount++] = telemetry->stopEvent; + + while ((error == CHANNEL_RC_OK) && (WaitForSingleObject(events[0], 0) != WAIT_OBJECT_0)) + { + switch (telemetry->state) + { + case TELEMETRY_INITIAL: + error = telemetry_server_context_poll_int(&telemetry->context); + if (error == CHANNEL_RC_OK) + { + events[1] = telemetry_server_get_channel_handle(telemetry); + nCount = 2; + } + break; + case TELEMETRY_OPENED: + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + switch (status) + { + case WAIT_OBJECT_0: + break; + case WAIT_OBJECT_0 + 1: + case WAIT_TIMEOUT: + error = telemetry_server_context_poll_int(&telemetry->context); + break; + + case WAIT_FAILED: + default: + error = ERROR_INTERNAL_ERROR; + break; + } + break; + default: + break; + } + } + + (void)WTSVirtualChannelClose(telemetry->telemetry_channel); + telemetry->telemetry_channel = NULL; + + if (error && telemetry->context.rdpcontext) + setChannelError(telemetry->context.rdpcontext, error, + "telemetry_server_thread_func reported an error"); + + ExitThread(error); + return error; +} + +static UINT telemetry_server_open(TelemetryServerContext* context) +{ + telemetry_server* telemetry = (telemetry_server*)context; + + WINPR_ASSERT(telemetry); + + if (!telemetry->externalThread && (telemetry->thread == NULL)) + { + telemetry->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!telemetry->stopEvent) + { + WLog_ERR(TAG, "CreateEvent failed!"); + return ERROR_INTERNAL_ERROR; + } + + telemetry->thread = CreateThread(NULL, 0, telemetry_server_thread_func, telemetry, 0, NULL); + if (!telemetry->thread) + { + WLog_ERR(TAG, "CreateThread failed!"); + (void)CloseHandle(telemetry->stopEvent); + telemetry->stopEvent = NULL; + return ERROR_INTERNAL_ERROR; + } + } + telemetry->isOpened = TRUE; + + return CHANNEL_RC_OK; +} + +static UINT telemetry_server_close(TelemetryServerContext* context) +{ + UINT error = CHANNEL_RC_OK; + telemetry_server* telemetry = (telemetry_server*)context; + + WINPR_ASSERT(telemetry); + + if (!telemetry->externalThread && telemetry->thread) + { + (void)SetEvent(telemetry->stopEvent); + + if (WaitForSingleObject(telemetry->thread, INFINITE) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", error); + return error; + } + + (void)CloseHandle(telemetry->thread); + (void)CloseHandle(telemetry->stopEvent); + telemetry->thread = NULL; + telemetry->stopEvent = NULL; + } + if (telemetry->externalThread) + { + if (telemetry->state != TELEMETRY_INITIAL) + { + (void)WTSVirtualChannelClose(telemetry->telemetry_channel); + telemetry->telemetry_channel = NULL; + telemetry->state = TELEMETRY_INITIAL; + } + } + telemetry->isOpened = FALSE; + + return error; +} + +static UINT telemetry_server_context_poll(TelemetryServerContext* context) +{ + telemetry_server* telemetry = (telemetry_server*)context; + + WINPR_ASSERT(telemetry); + + if (!telemetry->externalThread) + return ERROR_INTERNAL_ERROR; + + return telemetry_server_context_poll_int(context); +} + +static BOOL telemetry_server_context_handle(TelemetryServerContext* context, HANDLE* handle) +{ + telemetry_server* telemetry = (telemetry_server*)context; + + WINPR_ASSERT(telemetry); + WINPR_ASSERT(handle); + + if (!telemetry->externalThread) + return FALSE; + if (telemetry->state == TELEMETRY_INITIAL) + return FALSE; + + *handle = telemetry_server_get_channel_handle(telemetry); + + return TRUE; +} + +TelemetryServerContext* telemetry_server_context_new(HANDLE vcm) +{ + telemetry_server* telemetry = (telemetry_server*)calloc(1, sizeof(telemetry_server)); + + if (!telemetry) + return NULL; + + telemetry->context.vcm = vcm; + telemetry->context.Initialize = telemetry_server_initialize; + telemetry->context.Open = telemetry_server_open; + telemetry->context.Close = telemetry_server_close; + telemetry->context.Poll = telemetry_server_context_poll; + telemetry->context.ChannelHandle = telemetry_server_context_handle; + + telemetry->buffer = Stream_New(NULL, 4096); + if (!telemetry->buffer) + goto fail; + + return &telemetry->context; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + telemetry_server_context_free(&telemetry->context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void telemetry_server_context_free(TelemetryServerContext* context) +{ + telemetry_server* telemetry = (telemetry_server*)context; + + if (telemetry) + { + telemetry_server_close(context); + Stream_Free(telemetry->buffer, TRUE); + } + + free(telemetry); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..762a747391799f5814717b2bae328cec90c358b0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("tsmf") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..1a17beac2b401be59002766c6161f57f8b84136c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT OFF) +set(OPTION_CLIENT_DEFAULT OFF) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options( + NAME + "tsmf" + TYPE + "dynamic" + DESCRIPTION + "[DEPRECATED] Video Redirection Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEV]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/alsa/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/alsa/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e9d74eec979cff7311c3f4328586d936539a342 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/alsa/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("tsmf" "alsa" "audio") + +find_package(ALSA REQUIRED) + +set(${MODULE_PREFIX}_SRCS tsmf_alsa.c) + +set(${MODULE_PREFIX}_LIBS winpr freerdp ${ALSA_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${ALSA_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/ffmpeg/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/ffmpeg/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..717cdde46966d05e4f1285ab52f16f9e207a1f9b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/ffmpeg/CMakeLists.txt @@ -0,0 +1,35 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("tsmf" "ffmpeg" "decoder") + +set(${MODULE_PREFIX}_SRCS tsmf_ffmpeg.c) + +set(${MODULE_PREFIX}_LIBS freerdp ${FFMPEG_LIBRARIES}) +if(APPLE) + # For this to work on apple, we need to add some frameworks + find_library(COREFOUNDATION_LIBRARY CoreFoundation) + find_library(COREVIDEO_LIBRARY CoreVideo) + find_library(COREVIDEODECODE_LIBRARY VideoDecodeAcceleration) + + list(APPEND ${MODULE_PREFIX}_LIBS ${COREFOUNDATION_LIBRARY} ${COREVIDEO_LIBRARY} ${COREVIDEODECODE_LIBRARY}) +endif() + +include_directories(..) +include_directories(SYSTEM ${FFMPEG_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c new file mode 100644 index 0000000000000000000000000000000000000000..bda0fba76053670b9b31eb1b851bc1b3aab1afb3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c @@ -0,0 +1,725 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - FFmpeg Decoder + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#include "tsmf_constants.h" +#include "tsmf_decoder.h" +#include "tsmf_audio.h" + +/* Compatibility with older FFmpeg */ +#if LIBAVUTIL_VERSION_MAJOR < 50 +#define AVMEDIA_TYPE_VIDEO 0 +#define AVMEDIA_TYPE_AUDIO 1 +#endif + +#if LIBAVCODEC_VERSION_MAJOR < 54 +#define MAX_AUDIO_FRAME_SIZE AVCODEC_MAX_AUDIO_FRAME_SIZE +#else +#define MAX_AUDIO_FRAME_SIZE 192000 +#endif + +#if LIBAVCODEC_VERSION_MAJOR < 55 +#define AV_CODEC_ID_VC1 CODEC_ID_VC1 +#define AV_CODEC_ID_WMAV2 CODEC_ID_WMAV2 +#define AV_CODEC_ID_WMAPRO CODEC_ID_WMAPRO +#define AV_CODEC_ID_MP3 CODEC_ID_MP3 +#define AV_CODEC_ID_MP2 CODEC_ID_MP2 +#define AV_CODEC_ID_MPEG2VIDEO CODEC_ID_MPEG2VIDEO +#define AV_CODEC_ID_WMV3 CODEC_ID_WMV3 +#define AV_CODEC_ID_AAC CODEC_ID_AAC +#define AV_CODEC_ID_H264 CODEC_ID_H264 +#define AV_CODEC_ID_AC3 CODEC_ID_AC3 +#endif + +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56, 34, 2) +#define AV_CODEC_CAP_TRUNCATED CODEC_CAP_TRUNCATED +#define AV_CODEC_FLAG_TRUNCATED CODEC_FLAG_TRUNCATED +#endif + +#if LIBAVUTIL_VERSION_MAJOR < 52 +#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P +#endif + +typedef struct +{ + ITSMFDecoder iface; + + int media_type; +#if LIBAVCODEC_VERSION_MAJOR < 55 + enum CodecID codec_id; +#else + enum AVCodecID codec_id; +#endif + AVCodecContext* codec_context; + const AVCodec* codec; + AVFrame* frame; + int prepared; + + BYTE* decoded_data; + UINT32 decoded_size; + UINT32 decoded_size_max; +} TSMFFFmpegDecoder; + +static BOOL tsmf_ffmpeg_init_context(ITSMFDecoder* decoder) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + mdecoder->codec_context = avcodec_alloc_context3(NULL); + + if (!mdecoder->codec_context) + { + WLog_ERR(TAG, "avcodec_alloc_context failed."); + return FALSE; + } + + return TRUE; +} + +static BOOL tsmf_ffmpeg_init_video_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYPE* media_type) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + mdecoder->codec_context->width = media_type->Width; + mdecoder->codec_context->height = media_type->Height; + mdecoder->codec_context->bit_rate = media_type->BitRate; + mdecoder->codec_context->time_base.den = media_type->SamplesPerSecond.Numerator; + mdecoder->codec_context->time_base.num = media_type->SamplesPerSecond.Denominator; +#if LIBAVCODEC_VERSION_MAJOR < 55 + mdecoder->frame = avcodec_alloc_frame(); +#else + mdecoder->frame = av_frame_alloc(); +#endif + return TRUE; +} + +static BOOL tsmf_ffmpeg_init_audio_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYPE* media_type) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + mdecoder->codec_context->sample_rate = media_type->SamplesPerSecond.Numerator; + mdecoder->codec_context->bit_rate = media_type->BitRate; +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100) + mdecoder->codec_context->ch_layout.nb_channels = media_type->Channels; +#else + mdecoder->codec_context->channels = media_type->Channels; +#endif + mdecoder->codec_context->block_align = media_type->BlockAlign; +#if LIBAVCODEC_VERSION_MAJOR < 55 +#ifdef AV_CPU_FLAG_SSE2 + mdecoder->codec_context->dsp_mask = AV_CPU_FLAG_SSE2 | AV_CPU_FLAG_MMX2; +#else +#if LIBAVCODEC_VERSION_MAJOR < 53 + mdecoder->codec_context->dsp_mask = FF_MM_SSE2 | FF_MM_MMXEXT; +#else + mdecoder->codec_context->dsp_mask = FF_MM_SSE2 | FF_MM_MMX2; +#endif +#endif +#else /* LIBAVCODEC_VERSION_MAJOR < 55 */ +#ifdef AV_CPU_FLAG_SSE2 +#if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(57, 17, 100) + av_set_cpu_flags_mask(AV_CPU_FLAG_SSE2 | AV_CPU_FLAG_MMXEXT); +#else + av_force_cpu_flags(AV_CPU_FLAG_SSE2 | AV_CPU_FLAG_MMXEXT); +#endif +#else + av_set_cpu_flags_mask(FF_MM_SSE2 | FF_MM_MMX2); +#endif +#endif /* LIBAVCODEC_VERSION_MAJOR < 55 */ + return TRUE; +} + +static BOOL tsmf_ffmpeg_init_stream(ITSMFDecoder* decoder, const TS_AM_MEDIA_TYPE* media_type) +{ + BYTE* p = NULL; + UINT32 size = 0; + const BYTE* s = NULL; + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_QUALIFIERS + mdecoder->codec = avcodec_find_decoder(mdecoder->codec_id); + WINPR_PRAGMA_DIAG_POP + + if (!mdecoder->codec) + { + WLog_ERR(TAG, "avcodec_find_decoder failed."); + return FALSE; + } + + mdecoder->codec_context->codec_id = mdecoder->codec_id; + mdecoder->codec_context->codec_type = mdecoder->media_type; + + switch (mdecoder->media_type) + { + case AVMEDIA_TYPE_VIDEO: + if (!tsmf_ffmpeg_init_video_stream(decoder, media_type)) + return FALSE; + + break; + + case AVMEDIA_TYPE_AUDIO: + if (!tsmf_ffmpeg_init_audio_stream(decoder, media_type)) + return FALSE; + + break; + + default: + WLog_ERR(TAG, "unknown media_type %d", mdecoder->media_type); + break; + } + + if (media_type->ExtraData) + { + /* Add a padding to avoid invalid memory read in some codec */ + mdecoder->codec_context->extradata_size = media_type->ExtraDataSize + 8; + mdecoder->codec_context->extradata = calloc(1, mdecoder->codec_context->extradata_size); + + if (!mdecoder->codec_context->extradata) + return FALSE; + + if (media_type->SubType == TSMF_SUB_TYPE_AVC1 && + media_type->FormatType == TSMF_FORMAT_TYPE_MPEG2VIDEOINFO) + { + size_t required = 6; + /* The extradata format that FFmpeg uses is following CodecPrivate in Matroska. + See http://haali.su/mkv/codecs.pdf */ + p = mdecoder->codec_context->extradata; + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) + return FALSE; + *p++ = 1; /* Reserved? */ + *p++ = media_type->ExtraData[8]; /* Profile */ + *p++ = 0; /* Profile */ + *p++ = media_type->ExtraData[12]; /* Level */ + *p++ = 0xff; /* Flag? */ + *p++ = 0xe0 | 0x01; /* Reserved | #sps */ + s = media_type->ExtraData + 20; + size = ((UINT32)(*s)) * 256 + ((UINT32)(*(s + 1))); + required += size + 2; + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) + return FALSE; + memcpy(p, s, size + 2); + s += size + 2; + p += size + 2; + required++; + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) + return FALSE; + *p++ = 1; /* #pps */ + size = ((UINT32)(*s)) * 256 + ((UINT32)(*(s + 1))); + required += size + 2; + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < required)) + return FALSE; + memcpy(p, s, size + 2); + } + else + { + memcpy(mdecoder->codec_context->extradata, media_type->ExtraData, + media_type->ExtraDataSize); + if ((mdecoder->codec_context->extradata_size < 0) || + ((size_t)mdecoder->codec_context->extradata_size < + media_type->ExtraDataSize + 8ull)) + return FALSE; + memset(mdecoder->codec_context->extradata + media_type->ExtraDataSize, 0, 8); + } + } + +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 18, 100) + if (mdecoder->codec->capabilities & AV_CODEC_CAP_TRUNCATED) + mdecoder->codec_context->flags |= AV_CODEC_FLAG_TRUNCATED; +#endif + + return TRUE; +} + +static BOOL tsmf_ffmpeg_prepare(ITSMFDecoder* decoder) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + + if (avcodec_open2(mdecoder->codec_context, mdecoder->codec, NULL) < 0) + { + WLog_ERR(TAG, "avcodec_open2 failed."); + return FALSE; + } + + mdecoder->prepared = 1; + return TRUE; +} + +static BOOL tsmf_ffmpeg_set_format(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* media_type) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + + WINPR_ASSERT(mdecoder); + WINPR_ASSERT(media_type); + + switch (media_type->MajorType) + { + case TSMF_MAJOR_TYPE_VIDEO: + mdecoder->media_type = AVMEDIA_TYPE_VIDEO; + break; + + case TSMF_MAJOR_TYPE_AUDIO: + mdecoder->media_type = AVMEDIA_TYPE_AUDIO; + break; + + default: + return FALSE; + } + + switch (media_type->SubType) + { + case TSMF_SUB_TYPE_WVC1: + mdecoder->codec_id = AV_CODEC_ID_VC1; + break; + + case TSMF_SUB_TYPE_WMA2: + mdecoder->codec_id = AV_CODEC_ID_WMAV2; + break; + + case TSMF_SUB_TYPE_WMA9: + mdecoder->codec_id = AV_CODEC_ID_WMAPRO; + break; + + case TSMF_SUB_TYPE_MP3: + mdecoder->codec_id = AV_CODEC_ID_MP3; + break; + + case TSMF_SUB_TYPE_MP2A: + mdecoder->codec_id = AV_CODEC_ID_MP2; + break; + + case TSMF_SUB_TYPE_MP2V: + mdecoder->codec_id = AV_CODEC_ID_MPEG2VIDEO; + break; + + case TSMF_SUB_TYPE_WMV3: + mdecoder->codec_id = AV_CODEC_ID_WMV3; + break; + + case TSMF_SUB_TYPE_AAC: + mdecoder->codec_id = AV_CODEC_ID_AAC; + + /* For AAC the pFormat is a HEAACWAVEINFO struct, and the codec data + is at the end of it. See + http://msdn.microsoft.com/en-us/library/dd757806.aspx */ + if (media_type->ExtraData) + { + if (media_type->ExtraDataSize < 12) + return FALSE; + + media_type->ExtraData += 12; + media_type->ExtraDataSize -= 12; + } + + break; + + case TSMF_SUB_TYPE_H264: + case TSMF_SUB_TYPE_AVC1: + mdecoder->codec_id = AV_CODEC_ID_H264; + break; + + case TSMF_SUB_TYPE_AC3: + mdecoder->codec_id = AV_CODEC_ID_AC3; + break; + + default: + return FALSE; + } + + if (!tsmf_ffmpeg_init_context(decoder)) + return FALSE; + + if (!tsmf_ffmpeg_init_stream(decoder, media_type)) + return FALSE; + + if (!tsmf_ffmpeg_prepare(decoder)) + return FALSE; + + return TRUE; +} + +static BOOL tsmf_ffmpeg_decode_video(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, + UINT32 extensions) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + int decoded = 0; + int len = 0; + AVFrame* frame = NULL; + BOOL ret = TRUE; +#if LIBAVCODEC_VERSION_MAJOR < 52 || \ + (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR <= 20) + len = avcodec_decode_video(mdecoder->codec_context, mdecoder->frame, &decoded, data, data_size); +#else + { + AVPacket pkt = { 0 }; +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 133, 100) + av_init_packet(&pkt); +#endif + pkt.data = WINPR_CAST_CONST_PTR_AWAY(data, BYTE*); + pkt.size = data_size; + + if (extensions & TSMM_SAMPLE_EXT_CLEANPOINT) + pkt.flags |= AV_PKT_FLAG_KEY; + +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 48, 101) + len = avcodec_decode_video2(mdecoder->codec_context, mdecoder->frame, &decoded, &pkt); +#else + len = avcodec_send_packet(mdecoder->codec_context, &pkt); + if (len > 0) + { + len = avcodec_receive_frame(mdecoder->codec_context, mdecoder->frame); + if (len == AVERROR(EAGAIN)) + return TRUE; + } +#endif + } +#endif + + if (len < 0) + { + WLog_ERR(TAG, "data_size %" PRIu32 ", avcodec_decode_video failed (%d)", data_size, len); + ret = FALSE; + } + else if (!decoded) + { + WLog_ERR(TAG, "data_size %" PRIu32 ", no frame is decoded.", data_size); + ret = FALSE; + } + else + { + DEBUG_TSMF("linesize[0] %d linesize[1] %d linesize[2] %d linesize[3] %d " + "pix_fmt %d width %d height %d", + mdecoder->frame->linesize[0], mdecoder->frame->linesize[1], + mdecoder->frame->linesize[2], mdecoder->frame->linesize[3], + mdecoder->codec_context->pix_fmt, mdecoder->codec_context->width, + mdecoder->codec_context->height); + mdecoder->decoded_size = av_image_get_buffer_size(mdecoder->codec_context->pix_fmt, + mdecoder->codec_context->width, + mdecoder->codec_context->height, 1); + mdecoder->decoded_data = calloc(1, mdecoder->decoded_size); + + if (!mdecoder->decoded_data) + return FALSE; + +#if LIBAVCODEC_VERSION_MAJOR < 55 + frame = avcodec_alloc_frame(); +#else + frame = av_frame_alloc(); +#endif + av_image_fill_arrays(frame->data, frame->linesize, mdecoder->decoded_data, + mdecoder->codec_context->pix_fmt, mdecoder->codec_context->width, + mdecoder->codec_context->height, 1); + + const uint8_t* ptr[AV_NUM_DATA_POINTERS] = { 0 }; + for (size_t x = 0; x < AV_NUM_DATA_POINTERS; x++) + ptr[x] = mdecoder->frame->data[x]; + + av_image_copy(frame->data, frame->linesize, ptr, mdecoder->frame->linesize, + mdecoder->codec_context->pix_fmt, mdecoder->codec_context->width, + mdecoder->codec_context->height); + av_free(frame); + } + + return ret; +} + +static BOOL tsmf_ffmpeg_decode_audio(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, + UINT32 extensions) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + int len = 0; + int frame_size = 0; + +#if 0 + WLog_DBG(TAG, ("tsmf_ffmpeg_decode_audio: data_size %"PRIu32"", data_size)); + + for (int i = 0; i < data_size; i++) + { + WLog_DBG(TAG, ("%02"PRIX8"", data[i])); + + if (i % 16 == 15) + WLog_DBG(TAG, ("\n")); + } + +#endif + + if (mdecoder->decoded_size_max == 0) + mdecoder->decoded_size_max = MAX_AUDIO_FRAME_SIZE + 16; + + mdecoder->decoded_data = calloc(1, mdecoder->decoded_size_max); + + if (!mdecoder->decoded_data) + return FALSE; + + /* align the memory for SSE2 needs */ + BYTE* dst = (BYTE*)(((uintptr_t)mdecoder->decoded_data + 15) & ~0x0F); + size_t dst_offset = (size_t)(dst - mdecoder->decoded_data); + const BYTE* src = data; + UINT32 src_size = data_size; + + while (src_size > 0) + { + /* Ensure enough space for decoding */ + if (mdecoder->decoded_size_max - mdecoder->decoded_size < MAX_AUDIO_FRAME_SIZE) + { + BYTE* tmp_data = NULL; + tmp_data = realloc(mdecoder->decoded_data, mdecoder->decoded_size_max * 2 + 16); + + if (!tmp_data) + return FALSE; + + mdecoder->decoded_size_max = mdecoder->decoded_size_max * 2 + 16; + mdecoder->decoded_data = tmp_data; + dst = (BYTE*)(((uintptr_t)mdecoder->decoded_data + 15) & ~0x0F); + + const size_t diff = (size_t)(dst - mdecoder->decoded_data); + if (diff != dst_offset) + { + /* re-align the memory if the alignment has changed after realloc */ + memmove(dst, mdecoder->decoded_data + dst_offset, mdecoder->decoded_size); + dst_offset = diff; + } + + dst += mdecoder->decoded_size; + } + + frame_size = mdecoder->decoded_size_max - mdecoder->decoded_size; +#if LIBAVCODEC_VERSION_MAJOR < 52 || \ + (LIBAVCODEC_VERSION_MAJOR == 52 && LIBAVCODEC_VERSION_MINOR <= 20) + len = avcodec_decode_audio2(mdecoder->codec_context, (int16_t*)dst, &frame_size, src, + src_size); +#else + { +#if LIBAVCODEC_VERSION_MAJOR < 55 + AVFrame* decoded_frame = avcodec_alloc_frame(); +#else + AVFrame* decoded_frame = av_frame_alloc(); +#endif + int got_frame = 0; + AVPacket pkt = { 0 }; +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 133, 100) + av_init_packet(&pkt); +#endif + + pkt.data = WINPR_CAST_CONST_PTR_AWAY(src, BYTE*); + pkt.size = src_size; +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 48, 101) + len = avcodec_decode_audio4(mdecoder->codec_context, decoded_frame, &got_frame, &pkt); +#else + len = avcodec_send_packet(mdecoder->codec_context, &pkt); + if (len > 0) + { + len = avcodec_receive_frame(mdecoder->codec_context, decoded_frame); + if (len == AVERROR(EAGAIN)) + return TRUE; + } +#endif + + if (len >= 0 && got_frame) + { +#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100) + const int channels = mdecoder->codec_context->ch_layout.nb_channels; +#else + const int channels = mdecoder->codec_context->channels; +#endif + frame_size = av_samples_get_buffer_size(NULL, channels, decoded_frame->nb_samples, + mdecoder->codec_context->sample_fmt, 1); + memcpy(dst, decoded_frame->data[0], frame_size); + } + else + { + frame_size = 0; + } + + av_free(decoded_frame); + } +#endif + + if (len > 0) + { + src += len; + src_size -= len; + } + + if (frame_size > 0) + { + mdecoder->decoded_size += frame_size; + dst += frame_size; + } + } + + if (mdecoder->decoded_size == 0) + { + free(mdecoder->decoded_data); + mdecoder->decoded_data = NULL; + } + else if (dst_offset) + { + /* move the aligned decoded data to original place */ + memmove(mdecoder->decoded_data, mdecoder->decoded_data + dst_offset, + mdecoder->decoded_size); + } + + DEBUG_TSMF("data_size %" PRIu32 " decoded_size %" PRIu32 "", data_size, mdecoder->decoded_size); + return TRUE; +} + +static BOOL tsmf_ffmpeg_decode(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, + UINT32 extensions) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + + if (mdecoder->decoded_data) + { + free(mdecoder->decoded_data); + mdecoder->decoded_data = NULL; + } + + mdecoder->decoded_size = 0; + + switch (mdecoder->media_type) + { + case AVMEDIA_TYPE_VIDEO: + return tsmf_ffmpeg_decode_video(decoder, data, data_size, extensions); + + case AVMEDIA_TYPE_AUDIO: + return tsmf_ffmpeg_decode_audio(decoder, data, data_size, extensions); + + default: + WLog_ERR(TAG, "unknown media type."); + return FALSE; + } +} + +static BYTE* tsmf_ffmpeg_get_decoded_data(ITSMFDecoder* decoder, UINT32* size) +{ + BYTE* buf = NULL; + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + *size = mdecoder->decoded_size; + buf = mdecoder->decoded_data; + mdecoder->decoded_data = NULL; + mdecoder->decoded_size = 0; + return buf; +} + +static UINT32 tsmf_ffmpeg_get_decoded_format(ITSMFDecoder* decoder) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + + switch (mdecoder->codec_context->pix_fmt) + { + case AV_PIX_FMT_YUV420P: + return RDP_PIXFMT_I420; + + default: + WLog_ERR(TAG, "unsupported pixel format %u", mdecoder->codec_context->pix_fmt); + return (UINT32)-1; + } +} + +static BOOL tsmf_ffmpeg_get_decoded_dimension(ITSMFDecoder* decoder, UINT32* width, UINT32* height) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + + if (mdecoder->codec_context->width > 0 && mdecoder->codec_context->height > 0) + { + *width = mdecoder->codec_context->width; + *height = mdecoder->codec_context->height; + return TRUE; + } + else + { + return FALSE; + } +} + +static void tsmf_ffmpeg_free(ITSMFDecoder* decoder) +{ + TSMFFFmpegDecoder* mdecoder = (TSMFFFmpegDecoder*)decoder; + + if (mdecoder->frame) + av_free(mdecoder->frame); + + free(mdecoder->decoded_data); + + if (mdecoder->codec_context) + { + free(mdecoder->codec_context->extradata); + mdecoder->codec_context->extradata = NULL; + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55, 69, 100) + avcodec_free_context(&mdecoder->codec_context); +#else + if (mdecoder->prepared) + avcodec_close(mdecoder->codec_context); + + av_free(mdecoder->codec_context); +#endif + } + + free(decoder); +} + +static INIT_ONCE g_Initialized = INIT_ONCE_STATIC_INIT; +static BOOL CALLBACK InitializeAvCodecs(PINIT_ONCE once, PVOID param, PVOID* context) +{ +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100) + avcodec_register_all(); +#endif + return TRUE; +} + +FREERDP_ENTRY_POINT(UINT VCAPITYPE ffmpeg_freerdp_tsmf_client_decoder_subsystem_entry(void* ptr)) +{ + ITSMFDecoder** sptr = (ITSMFDecoder**)ptr; + WINPR_ASSERT(sptr); + *sptr = NULL; + + TSMFFFmpegDecoder* decoder = NULL; + InitOnceExecuteOnce(&g_Initialized, InitializeAvCodecs, NULL, NULL); + WLog_DBG(TAG, "TSMFDecoderEntry FFMPEG"); + decoder = (TSMFFFmpegDecoder*)calloc(1, sizeof(TSMFFFmpegDecoder)); + + if (!decoder) + return ERROR_OUTOFMEMORY; + + decoder->iface.SetFormat = tsmf_ffmpeg_set_format; + decoder->iface.Decode = tsmf_ffmpeg_decode; + decoder->iface.GetDecodedData = tsmf_ffmpeg_get_decoded_data; + decoder->iface.GetDecodedFormat = tsmf_ffmpeg_get_decoded_format; + decoder->iface.GetDecodedDimension = tsmf_ffmpeg_get_decoded_dimension; + decoder->iface.Free = tsmf_ffmpeg_free; + *sptr = &decoder->iface; + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/gstreamer/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/gstreamer/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..75c15d7eba70c3ba9b750cabc2ca648a6067da1c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/gstreamer/CMakeLists.txt @@ -0,0 +1,59 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script for gstreamer subsystem +# +# (C) Copyright 2012 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("tsmf" "gstreamer" "decoder") + +if(NOT gstreamer_FOUND) + message(FATAL_ERROR "GStreamer library not found, but required for TSMF module.") +endif() + +set(SRC "tsmf_gstreamer.c") + +pkg_check_modules(gstreamerbase gstreamer-base-1.0 REQUIRED) +pkg_check_modules(gstreamervideo gstreamer-video-1.0 REQUIRED) +pkg_check_modules(gstreamerapp gstreamer-app-1.0 REQUIRED) + +set(LIBS ${gstreamer_LIBRARIES} ${gstreamerbase_LIBRARIES} ${gstreamervideo_LIBRARIES} ${gstreamerapp_LIBRARIES}) +include_directories( + SYSTEM ${gstreamer_INCLUDE_DIRS} ${gstreamerbase_INCLUDE_DIRS} ${gstreamervideo_INCLUDE_DIRS} + ${gstreamerapp_INCLUDE_DIRS} +) + +if(ANDROID) + set(SRC ${SRC} tsmf_android.c) +else() + find_package(X11 REQUIRED) + + list(APPEND SRC tsmf_X11.c) + list(APPEND LIBS ${X11_LIBRARIES} ${X11_Xext_LIB}) + if(NOT APPLE) + list(APPEND LIBS rt) + endif() + + if(X11_Xext_FOUND) + add_compile_definitions(WITH_XEXT=1) + endif() + +endif() + +set(${MODULE_PREFIX}_SRCS "${SRC}") + +set(${MODULE_PREFIX}_LIBS ${LIBS} winpr) + +include_directories(..) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/gstreamer/tsmf_platform.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/gstreamer/tsmf_platform.h new file mode 100644 index 0000000000000000000000000000000000000000..681095cf1a41554a851d79805287f08117f13133 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/gstreamer/tsmf_platform.h @@ -0,0 +1,85 @@ +/* + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - GStreamer Decoder + * platform specific functions + * + * (C) Copyright 2014 Thincast Technologies GmbH + * (C) Copyright 2014 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_GST_PLATFORM_H +#define FREERDP_CHANNEL_TSMF_CLIENT_GST_PLATFORM_H + +#include +#include + +typedef struct +{ + ITSMFDecoder iface; + + int media_type; /* TSMF_MAJOR_TYPE_AUDIO or TSMF_MAJOR_TYPE_VIDEO */ + + gint64 duration; + + GstState state; + GstCaps* gst_caps; + + GstElement* pipe; + GstElement* src; + GstElement* queue; + GstElement* outsink; + GstElement* volume; + + BOOL ready; + BOOL paused; + UINT64 last_sample_start_time; + UINT64 last_sample_end_time; + BOOL seeking; + UINT64 seek_offset; + + double gstVolume; + BOOL gstMuted; + + int pipeline_start_time_valid; /* We've set the start time and have not reset the pipeline */ + int shutdown; /* The decoder stream is shutting down */ + + void* platform; + + BOOL (*ack_cb)(void*, BOOL); + void (*sync_cb)(void*); + void* stream; + +} TSMFGstreamerDecoder; + +const char* tsmf_platform_get_video_sink(void); +const char* tsmf_platform_get_audio_sink(void); + +int tsmf_platform_create(TSMFGstreamerDecoder* decoder); +int tsmf_platform_set_format(TSMFGstreamerDecoder* decoder); +int tsmf_platform_register_handler(TSMFGstreamerDecoder* decoder); +int tsmf_platform_free(TSMFGstreamerDecoder* decoder); + +int tsmf_window_create(TSMFGstreamerDecoder* decoder); +int tsmf_window_resize(TSMFGstreamerDecoder* decoder, int x, int y, int width, int height, + int nr_rect, RDP_RECT* visible); +int tsmf_window_destroy(TSMFGstreamerDecoder* decoder); + +int tsmf_window_map(TSMFGstreamerDecoder* decoder); +int tsmf_window_unmap(TSMFGstreamerDecoder* decoder); + +BOOL tsmf_gstreamer_add_pad(TSMFGstreamerDecoder* mdecoder); +void tsmf_gstreamer_remove_pad(TSMFGstreamerDecoder* mdecoder); + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_GST_PLATFORM_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/oss/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/oss/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..20c384ed841fe7ccc9ed20b434144541cf81eb00 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/oss/CMakeLists.txt @@ -0,0 +1,29 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright (c) 2015 Rozhuk Ivan +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("tsmf" "oss" "audio") + +find_package(OSS REQUIRED) + +set(${MODULE_PREFIX}_SRCS tsmf_oss.c) + +set(${MODULE_PREFIX}_LIBS winpr ${OSS_LIBRARIES}) + +include_directories(..) +include_directories(SYSTEM ${OSS_INCLUDE_DIRS}) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_audio.c b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_audio.c new file mode 100644 index 0000000000000000000000000000000000000000..6aaec3f3aa708b97059fe36589e01ceb4efbb47b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_audio.c @@ -0,0 +1,99 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Audio Device Manager + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "tsmf_audio.h" + +static ITSMFAudioDevice* tsmf_load_audio_device_by_name(const char* name, const char* device) +{ + ITSMFAudioDevice* audio = NULL; + union + { + PVIRTUALCHANNELENTRY pvce; + TSMF_AUDIO_DEVICE_ENTRY entry; + } cnv; + cnv.pvce = freerdp_load_channel_addin_entry("tsmf", name, "audio", 0); + + if (!cnv.entry) + return NULL; + + const UINT rc = cnv.entry(&audio); + + if ((rc != CHANNEL_RC_OK) || !audio) + { + WLog_ERR(TAG, "failed to call export function in %s", name); + return NULL; + } + + if (!audio->Open(audio, device)) + { + audio->Free(audio); + audio = NULL; + WLog_ERR(TAG, "failed to open, name: %s, device: %s", name, device); + } + else + { + WLog_DBG(TAG, "name: %s, device: %s", name, device); + } + + return audio; +} + +ITSMFAudioDevice* tsmf_load_audio_device(const char* name, const char* device) +{ + ITSMFAudioDevice* audio = NULL; + + if (name) + { + audio = tsmf_load_audio_device_by_name(name, device); + } + else + { +#if defined(WITH_PULSE) + if (!audio) + audio = tsmf_load_audio_device_by_name("pulse", device); +#endif + +#if defined(WITH_OSS) + if (!audio) + audio = tsmf_load_audio_device_by_name("oss", device); +#endif + +#if defined(WITH_ALSA) + if (!audio) + audio = tsmf_load_audio_device_by_name("alsa", device); +#endif + } + + if (audio == NULL) + { + WLog_ERR(TAG, "no sound device."); + } + else + { + WLog_DBG(TAG, "name: %s, device: %s", name, device); + } + + return audio; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_audio.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_audio.h new file mode 100644 index 0000000000000000000000000000000000000000..a3a5be0a2b436556923d8ef30a5639abad947cac --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_audio.h @@ -0,0 +1,51 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Audio Device Manager + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_AUDIO_H +#define FREERDP_CHANNEL_TSMF_CLIENT_AUDIO_H + +#include "tsmf_types.h" + +typedef struct s_ITSMFAudioDevice ITSMFAudioDevice; + +struct s_ITSMFAudioDevice +{ + /* Open the audio device. */ + BOOL (*Open)(ITSMFAudioDevice* audio, const char* device); + /* Set the audio data format. */ + BOOL(*SetFormat) + (ITSMFAudioDevice* audio, UINT32 sample_rate, UINT32 channels, UINT32 bits_per_sample); + /* Play audio data. */ + BOOL (*Play)(ITSMFAudioDevice* audio, const BYTE* data, UINT32 data_size); + /* Get the latency of the last written sample, in 100ns */ + UINT64 (*GetLatency)(ITSMFAudioDevice* audio); + /* Change the playback volume level */ + BOOL (*ChangeVolume)(ITSMFAudioDevice* audio, UINT32 newVolume, UINT32 muted); + /* Flush queued audio data */ + BOOL (*Flush)(ITSMFAudioDevice* audio); + /* Free the audio device */ + void (*Free)(ITSMFAudioDevice* audio); +}; + +#define TSMF_AUDIO_DEVICE_EXPORT_FUNC_NAME "TSMFAudioDeviceEntry" +typedef UINT(VCAPITYPE* TSMF_AUDIO_DEVICE_ENTRY)(ITSMFAudioDevice** dev); + +ITSMFAudioDevice* tsmf_load_audio_device(const char* name, const char* device); + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_AUDIO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_codec.c b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_codec.c new file mode 100644 index 0000000000000000000000000000000000000000..68d06a43d28a54b8eac28896acd8e63abc8e9eb2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_codec.c @@ -0,0 +1,616 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Codec + * + * Copyright 2010-2011 Vic Lee + * Copyright 2012 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "tsmf_decoder.h" +#include "tsmf_constants.h" +#include "tsmf_types.h" + +#include "tsmf_codec.h" + +#include + +#define TAG CHANNELS_TAG("tsmf.client") + +typedef struct +{ + BYTE guid[16]; + const char* name; + int type; +} TSMFMediaTypeMap; + +static const TSMFMediaTypeMap tsmf_major_type_map[] = { + /* 73646976-0000-0010-8000-00AA00389B71 */ + { { 0x76, 0x69, 0x64, 0x73, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIATYPE_Video", + TSMF_MAJOR_TYPE_VIDEO }, + + /* 73647561-0000-0010-8000-00AA00389B71 */ + { { 0x61, 0x75, 0x64, 0x73, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIATYPE_Audio", + TSMF_MAJOR_TYPE_AUDIO }, + + { { 0 }, "Unknown", TSMF_MAJOR_TYPE_UNKNOWN } +}; + +static const TSMFMediaTypeMap tsmf_sub_type_map[] = { + /* 31435657-0000-0010-8000-00AA00389B71 */ + { { 0x57, 0x56, 0x43, 0x31, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_WVC1", + TSMF_SUB_TYPE_WVC1 }, + + /* 00000160-0000-0010-8000-00AA00389B71 */ + { { 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_WMAudioV1", /* V7, V8 has the same GUID */ + TSMF_SUB_TYPE_WMA1 }, + + /* 00000161-0000-0010-8000-00AA00389B71 */ + { { 0x61, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_WMAudioV2", /* V7, V8 has the same GUID */ + TSMF_SUB_TYPE_WMA2 }, + + /* 00000162-0000-0010-8000-00AA00389B71 */ + { { 0x62, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_WMAudioV9", + TSMF_SUB_TYPE_WMA9 }, + + /* 00000055-0000-0010-8000-00AA00389B71 */ + { { 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_MP3", + TSMF_SUB_TYPE_MP3 }, + + /* E06D802B-DB46-11CF-B4D1-00805F6CBBEA */ + { { 0x2B, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, + 0xEA }, + "MEDIASUBTYPE_MPEG2_AUDIO", + TSMF_SUB_TYPE_MP2A }, + + /* E06D8026-DB46-11CF-B4D1-00805F6CBBEA */ + { { 0x26, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, + 0xEA }, + "MEDIASUBTYPE_MPEG2_VIDEO", + TSMF_SUB_TYPE_MP2V }, + + /* 31564D57-0000-0010-8000-00AA00389B71 */ + { { 0x57, 0x4D, 0x56, 0x31, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_WMV1", + TSMF_SUB_TYPE_WMV1 }, + + /* 32564D57-0000-0010-8000-00AA00389B71 */ + { { 0x57, 0x4D, 0x56, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_WMV2", + TSMF_SUB_TYPE_WMV2 }, + + /* 33564D57-0000-0010-8000-00AA00389B71 */ + { { 0x57, 0x4D, 0x56, 0x33, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_WMV3", + TSMF_SUB_TYPE_WMV3 }, + + /* 00001610-0000-0010-8000-00AA00389B71 */ + { { 0x10, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_MPEG_HEAAC", + TSMF_SUB_TYPE_AAC }, + + /* 34363248-0000-0010-8000-00AA00389B71 */ + { { 0x48, 0x32, 0x36, 0x34, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_H264", + TSMF_SUB_TYPE_H264 }, + + /* 31435641-0000-0010-8000-00AA00389B71 */ + { { 0x41, 0x56, 0x43, 0x31, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_AVC1", + TSMF_SUB_TYPE_AVC1 }, + + /* 3334504D-0000-0010-8000-00AA00389B71 */ + { { 0x4D, 0x50, 0x34, 0x33, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_MP43", + TSMF_SUB_TYPE_MP43 }, + + /* 5634504D-0000-0010-8000-00AA00389B71 */ + { { 0x4D, 0x50, 0x34, 0x56, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_MP4S", + TSMF_SUB_TYPE_MP4S }, + + /* 3234504D-0000-0010-8000-00AA00389B71 */ + { { 0x4D, 0x50, 0x34, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_MP42", + TSMF_SUB_TYPE_MP42 }, + + /* 3253344D-0000-0010-8000-00AA00389B71 */ + { { 0x4D, 0x34, 0x53, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_MP42", + TSMF_SUB_TYPE_M4S2 }, + + /* E436EB81-524F-11CE-9F53-0020AF0BA770 */ + { { 0x81, 0xEB, 0x36, 0xE4, 0x4F, 0x52, 0xCE, 0x11, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, + 0x70 }, + "MEDIASUBTYPE_MP1V", + TSMF_SUB_TYPE_MP1V }, + + /* 00000050-0000-0010-8000-00AA00389B71 */ + { { 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_MP1A", + TSMF_SUB_TYPE_MP1A }, + + /* E06D802C-DB46-11CF-B4D1-00805F6CBBEA */ + { { 0x2C, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, + 0xEA }, + "MEDIASUBTYPE_DOLBY_AC3", + TSMF_SUB_TYPE_AC3 }, + + /* 32595559-0000-0010-8000-00AA00389B71 */ + { { 0x59, 0x55, 0x59, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_YUY2", + TSMF_SUB_TYPE_YUY2 }, + + /* Opencodec IDS */ + { { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_FLAC", + TSMF_SUB_TYPE_FLAC }, + + { { 0x61, 0x34, 0x70, 0x6D, 0x7A, 0x76, 0x4D, 0x49, 0xB4, 0x78, 0xF2, 0x9D, 0x25, 0xDC, 0x90, + 0x37 }, + "MEDIASUBTYPE_OGG", + TSMF_SUB_TYPE_OGG }, + + { { 0x4D, 0x34, 0x53, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_H263", + TSMF_SUB_TYPE_H263 }, + + /* WebMMF codec IDS */ + { { 0x56, 0x50, 0x38, 0x30, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, + 0x71 }, + "MEDIASUBTYPE_VP8", + TSMF_SUB_TYPE_VP8 }, + + { { 0x0B, 0xD1, 0x2F, 0x8D, 0x41, 0x58, 0x6B, 0x4A, 0x89, 0x05, 0x58, 0x8F, 0xEC, 0x1A, 0xDE, + 0xD9 }, + "MEDIASUBTYPE_OGG", + TSMF_SUB_TYPE_OGG }, + + { { 0 }, "Unknown", TSMF_SUB_TYPE_UNKNOWN } + +}; + +static const TSMFMediaTypeMap tsmf_format_type_map[] = { + /* AED4AB2D-7326-43CB-9464-C879CAB9C43D */ + { { 0x2D, 0xAB, 0xD4, 0xAE, 0x26, 0x73, 0xCB, 0x43, 0x94, 0x64, 0xC8, 0x79, 0xCA, 0xB9, 0xC4, + 0x3D }, + "FORMAT_MFVideoFormat", + TSMF_FORMAT_TYPE_MFVIDEOFORMAT }, + + /* 05589F81-C356-11CE-BF01-00AA0055595A */ + { { 0x81, 0x9F, 0x58, 0x05, 0x56, 0xC3, 0xCE, 0x11, 0xBF, 0x01, 0x00, 0xAA, 0x00, 0x55, 0x59, + 0x5A }, + "FORMAT_WaveFormatEx", + TSMF_FORMAT_TYPE_WAVEFORMATEX }, + + /* E06D80E3-DB46-11CF-B4D1-00805F6CBBEA */ + { { 0xE3, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, + 0xEA }, + "FORMAT_MPEG2_VIDEO", + TSMF_FORMAT_TYPE_MPEG2VIDEOINFO }, + + /* F72A76A0-EB0A-11D0-ACE4-0000C0CC16BA */ + { { 0xA0, 0x76, 0x2A, 0xF7, 0x0A, 0xEB, 0xD0, 0x11, 0xAC, 0xE4, 0x00, 0x00, 0xC0, 0xCC, 0x16, + 0xBA }, + "FORMAT_VideoInfo2", + TSMF_FORMAT_TYPE_VIDEOINFO2 }, + + /* 05589F82-C356-11CE-BF01-00AA0055595A */ + { { 0x82, 0x9F, 0x58, 0x05, 0x56, 0xC3, 0xCE, 0x11, 0xBF, 0x01, 0x00, 0xAA, 0x00, 0x55, 0x59, + 0x5A }, + "FORMAT_MPEG1_VIDEO", + TSMF_FORMAT_TYPE_MPEG1VIDEOINFO }, + + { { 0 }, "Unknown", TSMF_FORMAT_TYPE_UNKNOWN } +}; + +static void tsmf_print_guid(const BYTE* guid) +{ + WINPR_UNUSED(guid); + +#ifdef WITH_DEBUG_TSMF + char guidString[37]; + + (void)snprintf(guidString, sizeof(guidString), + "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 + "-%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 "-%02" PRIX8 "%02" PRIX8 + "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "%02" PRIX8 "", + guid[3], guid[2], guid[1], guid[0], guid[5], guid[4], guid[7], guid[6], guid[8], + guid[9], guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]); + + WLog_INFO(TAG, "%s", guidString); +#endif +} + +/* http://msdn.microsoft.com/en-us/library/dd318229.aspx */ +static UINT32 tsmf_codec_parse_BITMAPINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, wStream* s, + BOOL bypass) +{ + UINT32 biSize = 0; + UINT32 biWidth = 0; + UINT32 biHeight = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 40)) + return 0; + Stream_Read_UINT32(s, biSize); + Stream_Read_UINT32(s, biWidth); + Stream_Read_UINT32(s, biHeight); + Stream_Seek(s, 28); + + if (mediatype->Width == 0) + mediatype->Width = biWidth; + + if (mediatype->Height == 0) + mediatype->Height = biHeight; + + /* Assume there will be no color table for video? */ + if (biSize < 40) + return 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, (biSize - 40))) + return 0; + + if (bypass && biSize > 40) + Stream_Seek(s, biSize - 40); + + return (bypass ? biSize : 40); +} + +/* http://msdn.microsoft.com/en-us/library/dd407326.aspx */ +static UINT32 tsmf_codec_parse_VIDEOINFOHEADER2(TS_AM_MEDIA_TYPE* mediatype, wStream* s) +{ + UINT64 AvgTimePerFrame = 0; + + /* VIDEOINFOHEADER2.rcSource, RECT(LONG left, LONG top, LONG right, LONG bottom) */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 72)) + return 0; + + Stream_Seek_UINT32(s); + Stream_Seek_UINT32(s); + Stream_Read_UINT32(s, mediatype->Width); + Stream_Read_UINT32(s, mediatype->Height); + /* VIDEOINFOHEADER2.rcTarget */ + Stream_Seek(s, 16); + /* VIDEOINFOHEADER2.dwBitRate */ + Stream_Read_UINT32(s, mediatype->BitRate); + /* VIDEOINFOHEADER2.dwBitErrorRate */ + Stream_Seek_UINT32(s); + /* VIDEOINFOHEADER2.AvgTimePerFrame */ + Stream_Read_UINT64(s, AvgTimePerFrame); + mediatype->SamplesPerSecond.Numerator = 1000000; + mediatype->SamplesPerSecond.Denominator = (UINT32)(AvgTimePerFrame / 10ULL); + /* Remaining fields before bmiHeader */ + Stream_Seek(s, 24); + return 72; +} + +/* http://msdn.microsoft.com/en-us/library/dd390700.aspx */ +static UINT32 tsmf_codec_parse_VIDEOINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, wStream* s) +{ + /* + typedef struct { + RECT rcSource; //16 + RECT rcTarget; //16 32 + DWORD dwBitRate; //4 36 + DWORD dwBitErrorRate; //4 40 + REFERENCE_TIME AvgTimePerFrame; //8 48 + BITMAPINFOHEADER bmiHeader; + } VIDEOINFOHEADER; + */ + UINT64 AvgTimePerFrame = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 48)) + return 0; + + /* VIDEOINFOHEADER.rcSource, RECT(LONG left, LONG top, LONG right, LONG bottom) */ + Stream_Seek_UINT32(s); + Stream_Seek_UINT32(s); + Stream_Read_UINT32(s, mediatype->Width); + Stream_Read_UINT32(s, mediatype->Height); + /* VIDEOINFOHEADER.rcTarget */ + Stream_Seek(s, 16); + /* VIDEOINFOHEADER.dwBitRate */ + Stream_Read_UINT32(s, mediatype->BitRate); + /* VIDEOINFOHEADER.dwBitErrorRate */ + Stream_Seek_UINT32(s); + /* VIDEOINFOHEADER.AvgTimePerFrame */ + Stream_Read_UINT64(s, AvgTimePerFrame); + mediatype->SamplesPerSecond.Numerator = 1000000; + mediatype->SamplesPerSecond.Denominator = (UINT32)(AvgTimePerFrame / 10ULL); + return 48; +} + +static BOOL tsmf_read_format_type(TS_AM_MEDIA_TYPE* mediatype, wStream* s, UINT32 cbFormat) +{ + UINT32 i = 0; + UINT32 j = 0; + + switch (mediatype->FormatType) + { + case TSMF_FORMAT_TYPE_MFVIDEOFORMAT: + /* http://msdn.microsoft.com/en-us/library/aa473808.aspx */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 176)) + return FALSE; + + Stream_Seek(s, 8); /* dwSize and ? */ + Stream_Read_UINT32(s, mediatype->Width); /* videoInfo.dwWidth */ + Stream_Read_UINT32(s, mediatype->Height); /* videoInfo.dwHeight */ + Stream_Seek(s, 32); + /* videoInfo.FramesPerSecond */ + Stream_Read_UINT32(s, mediatype->SamplesPerSecond.Numerator); + Stream_Read_UINT32(s, mediatype->SamplesPerSecond.Denominator); + Stream_Seek(s, 80); + Stream_Read_UINT32(s, mediatype->BitRate); /* compressedInfo.AvgBitrate */ + Stream_Seek(s, 36); + + if (cbFormat > 176) + { + const size_t nsize = cbFormat - 176; + if (mediatype->ExtraDataSize < nsize) + return FALSE; + if (!Stream_CheckAndLogRequiredLength(TAG, s, nsize)) + return FALSE; + mediatype->ExtraDataSize = (UINT32)nsize; + mediatype->ExtraData = Stream_Pointer(s); + } + break; + + case TSMF_FORMAT_TYPE_WAVEFORMATEX: + /* http://msdn.microsoft.com/en-us/library/dd757720.aspx */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 18)) + return FALSE; + + Stream_Seek_UINT16(s); + Stream_Read_UINT16(s, mediatype->Channels); + Stream_Read_UINT32(s, mediatype->SamplesPerSecond.Numerator); + mediatype->SamplesPerSecond.Denominator = 1; + Stream_Read_UINT32(s, mediatype->BitRate); + mediatype->BitRate *= 8; + Stream_Read_UINT16(s, mediatype->BlockAlign); + Stream_Read_UINT16(s, mediatype->BitsPerSample); + Stream_Read_UINT16(s, mediatype->ExtraDataSize); + + if (mediatype->ExtraDataSize > 0) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, mediatype->ExtraDataSize)) + return FALSE; + mediatype->ExtraData = Stream_Pointer(s); + } + break; + + case TSMF_FORMAT_TYPE_MPEG1VIDEOINFO: + /* http://msdn.microsoft.com/en-us/library/dd390700.aspx */ + i = tsmf_codec_parse_VIDEOINFOHEADER(mediatype, s); + if (!i) + return FALSE; + j = tsmf_codec_parse_BITMAPINFOHEADER(mediatype, s, TRUE); + if (!j) + return FALSE; + i += j; + + if (cbFormat > i) + { + mediatype->ExtraDataSize = cbFormat - i; + if (!Stream_CheckAndLogRequiredLength(TAG, s, mediatype->ExtraDataSize)) + return FALSE; + mediatype->ExtraData = Stream_Pointer(s); + } + break; + + case TSMF_FORMAT_TYPE_MPEG2VIDEOINFO: + /* http://msdn.microsoft.com/en-us/library/dd390707.aspx */ + i = tsmf_codec_parse_VIDEOINFOHEADER2(mediatype, s); + if (!i) + return FALSE; + j = tsmf_codec_parse_BITMAPINFOHEADER(mediatype, s, TRUE); + if (!j) + return FALSE; + i += j; + + if (cbFormat > i) + { + mediatype->ExtraDataSize = cbFormat - i; + if (!Stream_CheckAndLogRequiredLength(TAG, s, mediatype->ExtraDataSize)) + return FALSE; + mediatype->ExtraData = Stream_Pointer(s); + } + break; + + case TSMF_FORMAT_TYPE_VIDEOINFO2: + i = tsmf_codec_parse_VIDEOINFOHEADER2(mediatype, s); + if (!i) + return FALSE; + j = tsmf_codec_parse_BITMAPINFOHEADER(mediatype, s, FALSE); + if (!j) + return FALSE; + i += j; + + if (cbFormat > i) + { + mediatype->ExtraDataSize = cbFormat - i; + if (!Stream_CheckAndLogRequiredLength(TAG, s, mediatype->ExtraDataSize)) + return FALSE; + mediatype->ExtraData = Stream_Pointer(s); + } + break; + + default: + WLog_INFO(TAG, "unhandled format type 0x%x", mediatype->FormatType); + break; + } + return TRUE; +} + +BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, wStream* s) +{ + UINT32 cbFormat = 0; + BOOL ret = TRUE; + + ZeroMemory(mediatype, sizeof(TS_AM_MEDIA_TYPE)); + + /* MajorType */ + DEBUG_TSMF("MediaMajorType:"); + if (!Stream_CheckAndLogRequiredLength(TAG, s, 16)) + return FALSE; + tsmf_print_guid(Stream_Pointer(s)); + + size_t i = 0; + for (; tsmf_major_type_map[i].type != TSMF_MAJOR_TYPE_UNKNOWN; i++) + { + if (memcmp(tsmf_major_type_map[i].guid, Stream_Pointer(s), 16) == 0) + break; + } + + mediatype->MajorType = tsmf_major_type_map[i].type; + if (mediatype->MajorType == TSMF_MAJOR_TYPE_UNKNOWN) + ret = FALSE; + + DEBUG_TSMF("MediaMajorType %s", tsmf_major_type_map[i].name); + Stream_Seek(s, 16); + + /* SubType */ + DEBUG_TSMF("MediaSubType:"); + if (!Stream_CheckAndLogRequiredLength(TAG, s, 16)) + return FALSE; + tsmf_print_guid(Stream_Pointer(s)); + + for (i = 0; tsmf_sub_type_map[i].type != TSMF_SUB_TYPE_UNKNOWN; i++) + { + if (memcmp(tsmf_sub_type_map[i].guid, Stream_Pointer(s), 16) == 0) + break; + } + + mediatype->SubType = tsmf_sub_type_map[i].type; + if (mediatype->SubType == TSMF_SUB_TYPE_UNKNOWN) + ret = FALSE; + + DEBUG_TSMF("MediaSubType %s", tsmf_sub_type_map[i].name); + Stream_Seek(s, 16); + + /* bFixedSizeSamples, bTemporalCompression, SampleSize */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return FALSE; + Stream_Seek(s, 12); + + /* FormatType */ + DEBUG_TSMF("FormatType:"); + if (!Stream_CheckAndLogRequiredLength(TAG, s, 16)) + return FALSE; + tsmf_print_guid(Stream_Pointer(s)); + + for (i = 0; tsmf_format_type_map[i].type != TSMF_FORMAT_TYPE_UNKNOWN; i++) + { + if (memcmp(tsmf_format_type_map[i].guid, Stream_Pointer(s), 16) == 0) + break; + } + + mediatype->FormatType = tsmf_format_type_map[i].type; + if (mediatype->FormatType == TSMF_FORMAT_TYPE_UNKNOWN) + ret = FALSE; + + DEBUG_TSMF("FormatType %s", tsmf_format_type_map[i].name); + Stream_Seek(s, 16); + + /* cbFormat */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return FALSE; + Stream_Read_UINT32(s, cbFormat); + DEBUG_TSMF("cbFormat %" PRIu32 "", cbFormat); +#ifdef WITH_DEBUG_TSMF + winpr_HexDump(TAG, WLOG_DEBUG, Stream_Pointer(s), cbFormat); +#endif + + ret = tsmf_read_format_type(mediatype, s, cbFormat); + + if (mediatype->SamplesPerSecond.Numerator == 0) + mediatype->SamplesPerSecond.Numerator = 1; + + if (mediatype->SamplesPerSecond.Denominator == 0) + mediatype->SamplesPerSecond.Denominator = 1; + + return ret; +} + +BOOL tsmf_codec_check_media_type(const char* decoder_name, wStream* s) +{ + size_t pos = 0; + BOOL ret = FALSE; + TS_AM_MEDIA_TYPE mediatype; + + static BOOL decoderAvailable = FALSE; + static BOOL firstRun = TRUE; + + if (firstRun) + { + firstRun = FALSE; + if (tsmf_check_decoder_available(decoder_name)) + decoderAvailable = TRUE; + } + + pos = Stream_GetPosition(s); + if (decoderAvailable) + ret = tsmf_codec_parse_media_type(&mediatype, s); + Stream_SetPosition(s, pos); + + if (ret) + { + ITSMFDecoder* decoder = tsmf_load_decoder(decoder_name, &mediatype); + + if (!decoder) + { + WLog_WARN(TAG, "Format not supported by decoder %s", decoder_name); + ret = FALSE; + } + else + { + decoder->Free(decoder); + } + } + + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_codec.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_codec.h new file mode 100644 index 0000000000000000000000000000000000000000..ab988991db1a01ad8d87dd2c5d0e5dc14c676108 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_codec.h @@ -0,0 +1,28 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Codec + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_CODEC_H +#define FREERDP_CHANNEL_TSMF_CLIENT_CODEC_H + +#include "tsmf_types.h" + +BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, wStream* s); +BOOL tsmf_codec_check_media_type(const char* decoder_name, wStream* s); + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_CODEC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_constants.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_constants.h new file mode 100644 index 0000000000000000000000000000000000000000..abfa4e4fa34af88b261c2b5c08af44b92b4ea429 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_constants.h @@ -0,0 +1,139 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Constants + * + * Copyright 2010-2011 Vic Lee + * Copyright 2012 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_CONSTANTS_H +#define FREERDP_CHANNEL_TSMF_CLIENT_CONSTANTS_H + +#define GUID_SIZE 16 +#define TSMF_BUFFER_PADDING_SIZE 8 + +/* Interface IDs defined in [MS-RDPEV]. There's no constant names in the MS + documentation, so we create them on our own. */ +#define TSMF_INTERFACE_DEFAULT 0x00000000 +#define TSMF_INTERFACE_CLIENT_NOTIFICATIONS 0x00000001 +#define TSMF_INTERFACE_CAPABILITIES 0x00000002 + +/* Interface ID Mask */ +#define STREAM_ID_STUB 0x80000000 +#define STREAM_ID_PROXY 0x40000000 +#define STREAM_ID_NONE 0x00000000 + +/* Function ID */ +/* Common IDs for all interfaces are as follows. */ +#define RIMCALL_RELEASE 0x00000001 +#define RIMCALL_QUERYINTERFACE 0x00000002 +/* Capabilities Negotiator Interface IDs are as follows. */ +#define RIM_EXCHANGE_CAPABILITY_REQUEST 0x00000100 +/* The Client Notifications Interface ID is as follows. */ +#define PLAYBACK_ACK 0x00000100 +#define CLIENT_EVENT_NOTIFICATION 0x00000101 +/* Server Data Interface IDs are as follows. */ +#define EXCHANGE_CAPABILITIES_REQ 0x00000100 +#define SET_CHANNEL_PARAMS 0x00000101 +#define ADD_STREAM 0x00000102 +#define ON_SAMPLE 0x00000103 +#define SET_VIDEO_WINDOW 0x00000104 +#define ON_NEW_PRESENTATION 0x00000105 +#define SHUTDOWN_PRESENTATION_REQ 0x00000106 +#define SET_TOPOLOGY_REQ 0x00000107 +#define CHECK_FORMAT_SUPPORT_REQ 0x00000108 +#define ON_PLAYBACK_STARTED 0x00000109 +#define ON_PLAYBACK_PAUSED 0x0000010a +#define ON_PLAYBACK_STOPPED 0x0000010b +#define ON_PLAYBACK_RESTARTED 0x0000010c +#define ON_PLAYBACK_RATE_CHANGED 0x0000010d +#define ON_FLUSH 0x0000010e +#define ON_STREAM_VOLUME 0x0000010f +#define ON_CHANNEL_VOLUME 0x00000110 +#define ON_END_OF_STREAM 0x00000111 +#define SET_ALLOCATOR 0x00000112 +#define NOTIFY_PREROLL 0x00000113 +#define UPDATE_GEOMETRY_INFO 0x00000114 +#define REMOVE_STREAM 0x00000115 +#define SET_SOURCE_VIDEO_RECT 0x00000116 + +/* Supported platform */ +#define MMREDIR_CAPABILITY_PLATFORM_MF 0x00000001 +#define MMREDIR_CAPABILITY_PLATFORM_DSHOW 0x00000002 +#define MMREDIR_CAPABILITY_PLATFORM_OTHER 0x00000004 + +/* TSMM_CLIENT_EVENT Constants */ +#define TSMM_CLIENT_EVENT_ENDOFSTREAM 0x0064 +#define TSMM_CLIENT_EVENT_STOP_COMPLETED 0x00C8 +#define TSMM_CLIENT_EVENT_START_COMPLETED 0x00C9 +#define TSMM_CLIENT_EVENT_MONITORCHANGED 0x012C + +/* TS_MM_DATA_SAMPLE.SampleExtensions */ +#define TSMM_SAMPLE_EXT_CLEANPOINT 0x00000001 +#define TSMM_SAMPLE_EXT_DISCONTINUITY 0x00000002 +#define TSMM_SAMPLE_EXT_INTERLACED 0x00000004 +#define TSMM_SAMPLE_EXT_BOTTOMFIELDFIRST 0x00000008 +#define TSMM_SAMPLE_EXT_REPEATFIELDFIRST 0x00000010 +#define TSMM_SAMPLE_EXT_SINGLEFIELD 0x00000020 +#define TSMM_SAMPLE_EXT_DERIVEDFROMTOPFIELD 0x00000040 +#define TSMM_SAMPLE_EXT_HAS_NO_TIMESTAMPS 0x00000080 +#define TSMM_SAMPLE_EXT_RELATIVE_TIMESTAMPS 0x00000100 +#define TSMM_SAMPLE_EXT_ABSOLUTE_TIMESTAMPS 0x00000200 + +/* MajorType */ +#define TSMF_MAJOR_TYPE_UNKNOWN 0 +#define TSMF_MAJOR_TYPE_VIDEO 1 +#define TSMF_MAJOR_TYPE_AUDIO 2 + +/* SubType */ +#define TSMF_SUB_TYPE_UNKNOWN 0 +#define TSMF_SUB_TYPE_WVC1 1 +#define TSMF_SUB_TYPE_WMA2 2 +#define TSMF_SUB_TYPE_WMA9 3 +#define TSMF_SUB_TYPE_MP3 4 +#define TSMF_SUB_TYPE_MP2A 5 +#define TSMF_SUB_TYPE_MP2V 6 +#define TSMF_SUB_TYPE_WMV3 7 +#define TSMF_SUB_TYPE_AAC 8 +#define TSMF_SUB_TYPE_H264 9 +#define TSMF_SUB_TYPE_AVC1 10 +#define TSMF_SUB_TYPE_AC3 11 +#define TSMF_SUB_TYPE_WMV2 12 +#define TSMF_SUB_TYPE_WMV1 13 +#define TSMF_SUB_TYPE_MP1V 14 +#define TSMF_SUB_TYPE_MP1A 15 +#define TSMF_SUB_TYPE_YUY2 16 +#define TSMF_SUB_TYPE_MP43 17 +#define TSMF_SUB_TYPE_MP4S 18 +#define TSMF_SUB_TYPE_MP42 19 +#define TSMF_SUB_TYPE_OGG 20 +#define TSMF_SUB_TYPE_SPEEX 21 +#define TSMF_SUB_TYPE_THEORA 22 +#define TSMF_SUB_TYPE_FLAC 23 +#define TSMF_SUB_TYPE_VP8 24 +#define TSMF_SUB_TYPE_VP9 25 +#define TSMF_SUB_TYPE_H263 26 +#define TSMF_SUB_TYPE_M4S2 27 +#define TSMF_SUB_TYPE_WMA1 28 + +/* FormatType */ +#define TSMF_FORMAT_TYPE_UNKNOWN 0 +#define TSMF_FORMAT_TYPE_MFVIDEOFORMAT 1 +#define TSMF_FORMAT_TYPE_WAVEFORMATEX 2 +#define TSMF_FORMAT_TYPE_MPEG2VIDEOINFO 3 +#define TSMF_FORMAT_TYPE_VIDEOINFO2 4 +#define TSMF_FORMAT_TYPE_MPEG1VIDEOINFO 5 + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_CONSTANTS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_decoder.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_decoder.h new file mode 100644 index 0000000000000000000000000000000000000000..457b745e1f930c96e6a4f23a37642b35a1e803dc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_decoder.h @@ -0,0 +1,78 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Decoder + * + * Copyright 2010-2011 Vic Lee + * Copyright 2012 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_DECODER_H +#define FREERDP_CHANNEL_TSMF_CLIENT_DECODER_H + +#include "tsmf_types.h" + +typedef enum +{ + Control_Pause, + Control_Resume, + Control_Restart, + Control_Stop +} ITSMFControlMsg; + +typedef struct s_ITSMFDecoder ITSMFDecoder; + +struct s_ITSMFDecoder +{ + /* Set the decoder format. Return true if supported. */ + BOOL (*SetFormat)(ITSMFDecoder* decoder, TS_AM_MEDIA_TYPE* media_type); + /* Decode a sample. */ + BOOL (*Decode)(ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, UINT32 extensions); + /* Get the decoded data */ + BYTE* (*GetDecodedData)(ITSMFDecoder* decoder, UINT32* size); + /* Get the pixel format of decoded video frame */ + UINT32 (*GetDecodedFormat)(ITSMFDecoder* decoder); + /* Get the width and height of decoded video frame */ + BOOL (*GetDecodedDimension)(ITSMFDecoder* decoder, UINT32* width, UINT32* height); + /* Free the decoder */ + void (*Free)(ITSMFDecoder* decoder); + /* Optional Control function */ + BOOL (*Control)(ITSMFDecoder* decoder, ITSMFControlMsg control_msg, UINT32* arg); + /* Decode a sample with extended interface. */ + BOOL(*DecodeEx) + (ITSMFDecoder* decoder, const BYTE* data, UINT32 data_size, UINT32 extensions, + UINT64 start_time, UINT64 end_time, UINT64 duration); + /* Get current play time */ + UINT64 (*GetRunningTime)(ITSMFDecoder* decoder); + /* Update Gstreamer Rendering Area */ + BOOL(*UpdateRenderingArea) + (ITSMFDecoder* decoder, UINT32 newX, UINT32 newY, UINT32 newWidth, UINT32 newHeight, + UINT32 numRectangles, const RECTANGLE_32* rectangles); + /* Change Gstreamer Audio Volume */ + BOOL (*ChangeVolume)(ITSMFDecoder* decoder, UINT32 newVolume, UINT32 muted); + /* Check buffer level */ + BOOL (*BufferLevel)(ITSMFDecoder* decoder); + /* Register a callback for frame ack. */ + BOOL (*SetAckFunc)(ITSMFDecoder* decoder, BOOL (*cb)(void*, BOOL), void* stream); + /* Register a callback for stream seek detection. */ + BOOL (*SetSyncFunc)(ITSMFDecoder* decoder, void (*cb)(void*), void* stream); +}; + +#define TSMF_DECODER_EXPORT_FUNC_NAME "TSMFDecoderEntry" +typedef UINT(VCAPITYPE* TSMF_DECODER_ENTRY)(ITSMFDecoder** decoder); + +ITSMFDecoder* tsmf_load_decoder(const char* name, TS_AM_MEDIA_TYPE* media_type); +BOOL tsmf_check_decoder_available(const char* name); + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_DECODER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_ifman.c b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_ifman.c new file mode 100644 index 0000000000000000000000000000000000000000..dc97c56b1cb613418bb78181d873c1ab0ea32eec --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_ifman.c @@ -0,0 +1,841 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Interface Manipulation + * + * Copyright 2010-2011 Vic Lee + * Copyright 2012 Hewlett-Packard Development Company, L.P. + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include + +#include + +#include "tsmf_types.h" +#include "tsmf_constants.h" +#include "tsmf_media.h" +#include "tsmf_codec.h" + +#include "tsmf_ifman.h" + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_rim_exchange_capability_request(TSMF_IFMAN* ifman) +{ + UINT32 CapabilityValue = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(ifman->input, CapabilityValue); + DEBUG_TSMF("server CapabilityValue %" PRIu32 "", CapabilityValue); + + if (!Stream_EnsureRemainingCapacity(ifman->output, 8)) + return ERROR_INVALID_DATA; + + Stream_Write_UINT32(ifman->output, 1); /* CapabilityValue */ + Stream_Write_UINT32(ifman->output, 0); /* Result */ + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_exchange_capability_request(TSMF_IFMAN* ifman) +{ + UINT32 CapabilityType = 0; + UINT32 cbCapabilityLength = 0; + UINT32 numHostCapabilities = 0; + + WINPR_ASSERT(ifman); + if (!Stream_EnsureRemainingCapacity(ifman->output, ifman->input_size + 4)) + return ERROR_OUTOFMEMORY; + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, ifman->input_size)) + return ERROR_INVALID_DATA; + + const size_t xpos = Stream_GetPosition(ifman->output); + Stream_Copy(ifman->input, ifman->output, ifman->input_size); + Stream_SetPosition(ifman->output, xpos); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(ifman->output, numHostCapabilities); + + for (UINT32 i = 0; i < numHostCapabilities; i++) + { + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(ifman->output, CapabilityType); + Stream_Read_UINT32(ifman->output, cbCapabilityLength); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, cbCapabilityLength)) + return ERROR_INVALID_DATA; + + const size_t pos = Stream_GetPosition(ifman->output); + + switch (CapabilityType) + { + case 1: /* Protocol version request */ + { + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 4)) + return ERROR_INVALID_DATA; + + const UINT32 v = Stream_Get_UINT32(ifman->output); + WINPR_UNUSED(v); + DEBUG_TSMF("server protocol version %" PRIu32 "", v); + } + break; + + case 2: /* Supported platform */ + { + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->output, 4)) + return ERROR_INVALID_DATA; + + const UINT32 v = Stream_Get_UINT32(ifman->output); + WINPR_UNUSED(v); + DEBUG_TSMF("server supported platform %" PRIu32 "", v); + /* Claim that we support both MF and DShow platforms. */ + Stream_Write_UINT32(ifman->output, MMREDIR_CAPABILITY_PLATFORM_MF | + MMREDIR_CAPABILITY_PLATFORM_DSHOW); + } + break; + + default: + WLog_ERR(TAG, "skipping unknown capability type %" PRIu32 "", CapabilityType); + break; + } + + Stream_SetPosition(ifman->output, pos + cbCapabilityLength); + } + + Stream_Write_UINT32(ifman->output, 0); /* Result */ + ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_check_format_support_request(TSMF_IFMAN* ifman) +{ + UINT32 numMediaType = 0; + UINT32 PlatformCookie = 0; + UINT32 FormatSupported = 1; + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(ifman->input, PlatformCookie); + Stream_Seek_UINT32(ifman->input); /* NoRolloverFlags (4 bytes) */ + Stream_Read_UINT32(ifman->input, numMediaType); + DEBUG_TSMF("PlatformCookie %" PRIu32 " numMediaType %" PRIu32 "", PlatformCookie, numMediaType); + + if (!tsmf_codec_check_media_type(ifman->decoder_name, ifman->input)) + FormatSupported = 0; + + if (FormatSupported) + DEBUG_TSMF("format ok."); + + if (!Stream_EnsureRemainingCapacity(ifman->output, 12)) + return -1; + + Stream_Write_UINT32(ifman->output, FormatSupported); + Stream_Write_UINT32(ifman->output, PlatformCookie); + Stream_Write_UINT32(ifman->output, 0); /* Result */ + ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_new_presentation(TSMF_IFMAN* ifman) +{ + UINT status = CHANNEL_RC_OK; + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (presentation) + { + DEBUG_TSMF("Presentation already exists"); + ifman->output_pending = FALSE; + return CHANNEL_RC_OK; + } + + presentation = tsmf_presentation_new(Stream_Pointer(ifman->input), ifman->channel_callback); + + if (!presentation) + status = ERROR_OUTOFMEMORY; + else + tsmf_presentation_set_audio_device(presentation, ifman->audio_name, ifman->audio_device); + + ifman->output_pending = TRUE; + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_add_stream(TSMF_IFMAN* ifman, rdpContext* rdpcontext) +{ + UINT32 StreamId = 0; + UINT status = CHANNEL_RC_OK; + TSMF_STREAM* stream = NULL; + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 8)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + Stream_Seek(ifman->input, GUID_SIZE); + + if (!presentation) + { + WLog_ERR(TAG, "unknown presentation id"); + status = ERROR_NOT_FOUND; + } + else + { + Stream_Read_UINT32(ifman->input, StreamId); + Stream_Seek_UINT32(ifman->input); /* numMediaType */ + stream = tsmf_stream_new(presentation, StreamId, rdpcontext); + + if (!stream) + { + WLog_ERR(TAG, "failed to create stream"); + return ERROR_OUTOFMEMORY; + } + + if (!tsmf_stream_set_format(stream, ifman->decoder_name, ifman->input)) + { + WLog_ERR(TAG, "failed to set stream format"); + return ERROR_OUTOFMEMORY; + } + + tsmf_stream_start_threads(stream); + } + + ifman->output_pending = TRUE; + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_set_topology_request(TSMF_IFMAN* ifman) +{ + DEBUG_TSMF(""); + + if (!Stream_EnsureRemainingCapacity(ifman->output, 8)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(ifman->output, 1); /* TopologyReady */ + Stream_Write_UINT32(ifman->output, 0); /* Result */ + ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_remove_stream(TSMF_IFMAN* ifman) +{ + int status = CHANNEL_RC_OK; + UINT32 StreamId = 0; + TSMF_STREAM* stream = NULL; + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 20)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + Stream_Seek(ifman->input, GUID_SIZE); + + if (!presentation) + { + status = ERROR_NOT_FOUND; + } + else + { + Stream_Read_UINT32(ifman->input, StreamId); + stream = tsmf_stream_find_by_id(presentation, StreamId); + + if (stream) + tsmf_stream_free(stream); + else + status = ERROR_NOT_FOUND; + } + + ifman->output_pending = TRUE; + return status; +} + +static float tsmf_stream_read_float(wStream* s) +{ + float fValue = NAN; + UINT32 iValue = 0; + Stream_Read_UINT32(s, iValue); + CopyMemory(&fValue, &iValue, 4); + return fValue; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_set_source_video_rect(TSMF_IFMAN* ifman) +{ + UINT status = CHANNEL_RC_OK; + float Left = NAN; + float Top = NAN; + float Right = NAN; + float Bottom = NAN; + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 32)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + Stream_Seek(ifman->input, GUID_SIZE); + + if (!presentation) + { + status = ERROR_NOT_FOUND; + } + else + { + Left = tsmf_stream_read_float(ifman->input); /* Left (4 bytes) */ + Top = tsmf_stream_read_float(ifman->input); /* Top (4 bytes) */ + Right = tsmf_stream_read_float(ifman->input); /* Right (4 bytes) */ + Bottom = tsmf_stream_read_float(ifman->input); /* Bottom (4 bytes) */ + DEBUG_TSMF("SetSourceVideoRect: Left: %f Top: %f Right: %f Bottom: %f", Left, Top, Right, + Bottom); + } + + ifman->output_pending = TRUE; + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_shutdown_presentation(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (presentation) + tsmf_presentation_free(presentation); + else + { + WLog_ERR(TAG, "unknown presentation id"); + return ERROR_NOT_FOUND; + } + + if (!Stream_EnsureRemainingCapacity(ifman->output, 4)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(ifman->output, 0); /* Result */ + ifman->output_interface_id = TSMF_INTERFACE_DEFAULT | STREAM_ID_STUB; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_stream_volume(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + UINT32 newVolume = 0; + UINT32 muted = 0; + DEBUG_TSMF("on stream volume"); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 8)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (!presentation) + { + WLog_ERR(TAG, "unknown presentation id"); + return ERROR_NOT_FOUND; + } + + Stream_Seek(ifman->input, 16); + Stream_Read_UINT32(ifman->input, newVolume); + DEBUG_TSMF("on stream volume: new volume=[%" PRIu32 "]", newVolume); + Stream_Read_UINT32(ifman->input, muted); + DEBUG_TSMF("on stream volume: muted=[%" PRIu32 "]", muted); + + if (!tsmf_presentation_volume_changed(presentation, newVolume, muted)) + return ERROR_INVALID_OPERATION; + + ifman->output_pending = TRUE; + return 0; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_channel_volume(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF("on channel volume"); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 8)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (presentation) + { + UINT32 channelVolume = 0; + UINT32 changedChannel = 0; + Stream_Seek(ifman->input, 16); + Stream_Read_UINT32(ifman->input, channelVolume); + DEBUG_TSMF("on channel volume: channel volume=[%" PRIu32 "]", channelVolume); + Stream_Read_UINT32(ifman->input, changedChannel); + DEBUG_TSMF("on stream volume: changed channel=[%" PRIu32 "]", changedChannel); + } + + ifman->output_pending = TRUE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_set_video_window(TSMF_IFMAN* ifman) +{ + DEBUG_TSMF(""); + ifman->output_pending = TRUE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_update_geometry_info(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + UINT32 numGeometryInfo = 0; + UINT32 Left = 0; + UINT32 Top = 0; + UINT32 Width = 0; + UINT32 Height = 0; + UINT32 cbVisibleRect = 0; + RECTANGLE_32* rects = NULL; + UINT error = CHANNEL_RC_OK; + size_t pos = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, GUID_SIZE + 32)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (!presentation) + return ERROR_NOT_FOUND; + + Stream_Seek(ifman->input, 16); + Stream_Read_UINT32(ifman->input, numGeometryInfo); + pos = Stream_GetPosition(ifman->input); + Stream_Seek(ifman->input, 12); /* VideoWindowId (8 bytes), VideoWindowState (4 bytes) */ + Stream_Read_UINT32(ifman->input, Width); + Stream_Read_UINT32(ifman->input, Height); + Stream_Read_UINT32(ifman->input, Left); + Stream_Read_UINT32(ifman->input, Top); + Stream_SetPosition(ifman->input, pos + numGeometryInfo); + Stream_Read_UINT32(ifman->input, cbVisibleRect); + const UINT32 num_rects = cbVisibleRect / 16; + DEBUG_TSMF("numGeometryInfo %" PRIu32 " Width %" PRIu32 " Height %" PRIu32 " Left %" PRIu32 + " Top %" PRIu32 " cbVisibleRect %" PRIu32 " num_rects %d", + numGeometryInfo, Width, Height, Left, Top, cbVisibleRect, num_rects); + + if (num_rects > 0) + { + rects = (RECTANGLE_32*)calloc(num_rects, sizeof(RECTANGLE_32)); + + for (size_t i = 0; i < num_rects; i++) + { + Stream_Read_UINT32(ifman->input, rects[i].top); /* Top */ + Stream_Read_UINT32(ifman->input, rects[i].left); /* Left */ + Stream_Read_UINT32(ifman->input, rects[i].height); /* Bottom */ + Stream_Read_UINT32(ifman->input, rects[i].width); /* Right */ + rects[i].width -= rects[i].left; + rects[i].height -= rects[i].top; + DEBUG_TSMF("rect %d: %" PRId16 " %" PRId16 " %" PRId16 " %" PRId16 "", i, rects[i].x, + rects[i].y, rects[i].width, rects[i].height); + } + } + + const BOOL rc = tsmf_presentation_set_geometry_info(presentation, Left, Top, Width, Height, + num_rects, rects); + free(rects); + if (!rc) + return ERROR_INVALID_OPERATION; + + ifman->output_pending = TRUE; + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_set_allocator(TSMF_IFMAN* ifman) +{ + DEBUG_TSMF(""); + ifman->output_pending = TRUE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_notify_preroll(TSMF_IFMAN* ifman) +{ + DEBUG_TSMF(""); + tsmf_ifman_on_playback_paused(ifman); + ifman->output_pending = TRUE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_sample(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + TSMF_STREAM* stream = NULL; + UINT32 StreamId = 0; + UINT64 SampleStartTime = 0; + UINT64 SampleEndTime = 0; + UINT64 ThrottleDuration = 0; + UINT32 SampleExtensions = 0; + UINT32 cbData = 0; + UINT error = 0; + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 60)) + return ERROR_INVALID_DATA; + + Stream_Seek(ifman->input, 16); + Stream_Read_UINT32(ifman->input, StreamId); + Stream_Seek_UINT32(ifman->input); /* numSample */ + Stream_Read_UINT64(ifman->input, SampleStartTime); + Stream_Read_UINT64(ifman->input, SampleEndTime); + Stream_Read_UINT64(ifman->input, ThrottleDuration); + Stream_Seek_UINT32(ifman->input); /* SampleFlags */ + Stream_Read_UINT32(ifman->input, SampleExtensions); + Stream_Read_UINT32(ifman->input, cbData); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, cbData)) + return ERROR_INVALID_DATA; + + DEBUG_TSMF("MessageId %" PRIu32 " StreamId %" PRIu32 " SampleStartTime %" PRIu64 + " SampleEndTime %" PRIu64 " " + "ThrottleDuration %" PRIu64 " SampleExtensions %" PRIu32 " cbData %" PRIu32 "", + ifman->message_id, StreamId, SampleStartTime, SampleEndTime, ThrottleDuration, + SampleExtensions, cbData); + presentation = tsmf_presentation_find_by_id(ifman->presentation_id); + + if (!presentation) + { + WLog_ERR(TAG, "unknown presentation id"); + return ERROR_NOT_FOUND; + } + + stream = tsmf_stream_find_by_id(presentation, StreamId); + + if (!stream) + { + WLog_ERR(TAG, "unknown stream id"); + return ERROR_NOT_FOUND; + } + + if (!tsmf_stream_push_sample(stream, ifman->channel_callback, ifman->message_id, + SampleStartTime, SampleEndTime, ThrottleDuration, SampleExtensions, + cbData, Stream_Pointer(ifman->input))) + { + WLog_ERR(TAG, "unable to push sample"); + return ERROR_OUTOFMEMORY; + } + + if ((error = tsmf_presentation_sync(presentation))) + { + WLog_ERR(TAG, "tsmf_presentation_sync failed with error %" PRIu32 "", error); + return error; + } + + ifman->output_pending = TRUE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman) +{ + UINT32 StreamId = 0; + TSMF_PRESENTATION* presentation = NULL; + TSMF_STREAM* stream = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 20)) + return ERROR_INVALID_DATA; + + Stream_Seek(ifman->input, 16); + Stream_Read_UINT32(ifman->input, StreamId); + DEBUG_TSMF("StreamId %" PRIu32 "", StreamId); + presentation = tsmf_presentation_find_by_id(ifman->presentation_id); + + if (!presentation) + { + WLog_ERR(TAG, "unknown presentation id"); + return ERROR_NOT_FOUND; + } + + /* Flush message is for a stream, not the entire presentation + * therefore we only flush the stream as intended per the MS-RDPEV spec + */ + stream = tsmf_stream_find_by_id(presentation, StreamId); + + if (stream) + { + if (!tsmf_stream_flush(stream)) + return ERROR_INVALID_OPERATION; + } + else + WLog_ERR(TAG, "unknown stream id"); + + ifman->output_pending = TRUE; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_end_of_stream(TSMF_IFMAN* ifman) +{ + UINT32 StreamId = 0; + TSMF_STREAM* stream = NULL; + TSMF_PRESENTATION* presentation = NULL; + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 20)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + Stream_Seek(ifman->input, 16); + Stream_Read_UINT32(ifman->input, StreamId); + + if (presentation) + { + stream = tsmf_stream_find_by_id(presentation, StreamId); + + if (stream) + tsmf_stream_end(stream, ifman->message_id, ifman->channel_callback); + } + + DEBUG_TSMF("StreamId %" PRIu32 "", StreamId); + ifman->output_pending = TRUE; + ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_playback_started(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + + if (!Stream_CheckAndLogRequiredLength(TAG, ifman->input, 16)) + return ERROR_INVALID_DATA; + + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (presentation) + tsmf_presentation_start(presentation); + else + WLog_ERR(TAG, "unknown presentation id"); + + if (!Stream_EnsureRemainingCapacity(ifman->output, 16)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ + Stream_Write_UINT32(ifman->output, 0); /* StreamId */ + Stream_Write_UINT32(ifman->output, TSMM_CLIENT_EVENT_START_COMPLETED); /* EventId */ + Stream_Write_UINT32(ifman->output, 0); /* cbData */ + ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_playback_paused(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + ifman->output_pending = TRUE; + /* Added pause control so gstreamer pipeline can be paused accordingly */ + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (presentation) + { + if (!tsmf_presentation_paused(presentation)) + return ERROR_INVALID_OPERATION; + } + else + WLog_ERR(TAG, "unknown presentation id"); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_playback_restarted(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + ifman->output_pending = TRUE; + /* Added restart control so gstreamer pipeline can be resumed accordingly */ + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (presentation) + { + if (!tsmf_presentation_restarted(presentation)) + return ERROR_INVALID_OPERATION; + } + else + WLog_ERR(TAG, "unknown presentation id"); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_playback_stopped(TSMF_IFMAN* ifman) +{ + TSMF_PRESENTATION* presentation = NULL; + DEBUG_TSMF(""); + presentation = tsmf_presentation_find_by_id(Stream_Pointer(ifman->input)); + + if (presentation) + { + if (!tsmf_presentation_stop(presentation)) + return ERROR_INVALID_OPERATION; + } + else + WLog_ERR(TAG, "unknown presentation id"); + + if (!Stream_EnsureRemainingCapacity(ifman->output, 16)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ + Stream_Write_UINT32(ifman->output, 0); /* StreamId */ + Stream_Write_UINT32(ifman->output, TSMM_CLIENT_EVENT_STOP_COMPLETED); /* EventId */ + Stream_Write_UINT32(ifman->output, 0); /* cbData */ + ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_ifman_on_playback_rate_changed(TSMF_IFMAN* ifman) +{ + DEBUG_TSMF(""); + + if (!Stream_EnsureRemainingCapacity(ifman->output, 16)) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(ifman->output, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ + Stream_Write_UINT32(ifman->output, 0); /* StreamId */ + Stream_Write_UINT32(ifman->output, TSMM_CLIENT_EVENT_MONITORCHANGED); /* EventId */ + Stream_Write_UINT32(ifman->output, 0); /* cbData */ + ifman->output_interface_id = TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY; + return CHANNEL_RC_OK; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_ifman.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_ifman.h new file mode 100644 index 0000000000000000000000000000000000000000..9547f6b0877f1244bfa5b5880cbf8edef3e973e6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_ifman.h @@ -0,0 +1,68 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Interface Manipulation + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_IFMAN_H +#define FREERDP_CHANNEL_TSMF_CLIENT_IFMAN_H + +#include + +typedef struct +{ + IWTSVirtualChannelCallback* channel_callback; + const char* decoder_name; + const char* audio_name; + const char* audio_device; + BYTE presentation_id[16]; + UINT32 stream_id; + UINT32 message_id; + + wStream* input; + UINT32 input_size; + wStream* output; + BOOL output_pending; + UINT32 output_interface_id; +} TSMF_IFMAN; + +UINT tsmf_ifman_rim_exchange_capability_request(TSMF_IFMAN* ifman); +UINT tsmf_ifman_exchange_capability_request(TSMF_IFMAN* ifman); +UINT tsmf_ifman_check_format_support_request(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_new_presentation(TSMF_IFMAN* ifman); +UINT tsmf_ifman_add_stream(TSMF_IFMAN* ifman, rdpContext* rdpcontext); +UINT tsmf_ifman_set_topology_request(TSMF_IFMAN* ifman); +UINT tsmf_ifman_remove_stream(TSMF_IFMAN* ifman); +UINT tsmf_ifman_set_source_video_rect(TSMF_IFMAN* ifman); +UINT tsmf_ifman_shutdown_presentation(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_stream_volume(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_channel_volume(TSMF_IFMAN* ifman); +UINT tsmf_ifman_set_video_window(TSMF_IFMAN* ifman); +UINT tsmf_ifman_update_geometry_info(TSMF_IFMAN* ifman); +UINT tsmf_ifman_set_allocator(TSMF_IFMAN* ifman); +UINT tsmf_ifman_notify_preroll(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_sample(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_flush(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_end_of_stream(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_playback_started(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_playback_paused(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_playback_restarted(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_playback_stopped(TSMF_IFMAN* ifman); +UINT tsmf_ifman_on_playback_rate_changed(TSMF_IFMAN* ifman); + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_IFMAN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_main.c new file mode 100644 index 0000000000000000000000000000000000000000..05151434a2d480b5eea5f06cb70fe23f44d2780a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_main.c @@ -0,0 +1,614 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include + +#include "tsmf_types.h" +#include "tsmf_constants.h" +#include "tsmf_ifman.h" +#include "tsmf_media.h" + +#include "tsmf_main.h" + +BOOL tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id) +{ + ssize_t status = -1; + TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*)pChannelCallback; + + if (!callback) + { + DEBUG_TSMF("No callback reference - unable to send eos response!"); + return FALSE; + } + + if (callback && callback->stream_id && callback->channel && callback->channel->Write) + { + wStream* s = Stream_New(NULL, 24); + + if (!s) + return FALSE; + + Stream_Write_UINT32(s, TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY); + Stream_Write_UINT32(s, message_id); + Stream_Write_UINT32(s, CLIENT_EVENT_NOTIFICATION); /* FunctionId */ + Stream_Write_UINT32(s, callback->stream_id); /* StreamId */ + Stream_Write_UINT32(s, TSMM_CLIENT_EVENT_ENDOFSTREAM); /* EventId */ + Stream_Write_UINT32(s, 0); /* cbData */ + const size_t pos = Stream_GetPosition(s); + DEBUG_TSMF("EOS response size %" PRIuz "", pos); + WINPR_ASSERT(pos <= UINT32_MAX); + status = callback->channel->Write(callback->channel, (UINT32)pos, Stream_Buffer(s), NULL); + + if (status) + { + WLog_ERR(TAG, "response error %d", status); + } + + Stream_Free(s, TRUE); + } + + return (status == 0); +} + +BOOL tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id, + UINT64 duration, UINT32 data_size) +{ + ssize_t status = -1; + TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*)pChannelCallback; + + if (!callback) + return FALSE; + + wStream* s = Stream_New(NULL, 32); + + if (!s) + return FALSE; + + Stream_Write_UINT32(s, TSMF_INTERFACE_CLIENT_NOTIFICATIONS | STREAM_ID_PROXY); + Stream_Write_UINT32(s, message_id); + Stream_Write_UINT32(s, PLAYBACK_ACK); /* FunctionId */ + Stream_Write_UINT32(s, callback->stream_id); /* StreamId */ + Stream_Write_UINT64(s, duration); /* DataDuration */ + Stream_Write_UINT64(s, data_size); /* cbData */ + + const size_t pos = Stream_GetPosition(s); + DEBUG_TSMF("ACK response size %" PRIuz "", pos); + + if (!callback->channel || !callback->channel->Write) + { + WLog_ERR(TAG, "callback=%p, channel=%p, write=%p", callback, + (callback ? callback->channel : NULL), + (callback && callback->channel ? callback->channel->Write : NULL)); + } + else + { + WINPR_ASSERT(pos <= UINT32_MAX); + status = callback->channel->Write(callback->channel, (UINT32)pos, Stream_Buffer(s), NULL); + } + + if (status) + { + WLog_ERR(TAG, "response error %d", status); + } + + Stream_Free(s, TRUE); + return (status == 0); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT tsmf_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + wStream* input = NULL; + wStream* output = NULL; + UINT error = CHANNEL_RC_OK; + BOOL processed = FALSE; + TSMF_IFMAN ifman = { 0 }; + UINT32 MessageId = 0; + UINT32 FunctionId = 0; + UINT32 InterfaceId = 0; + TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*)pChannelCallback; + const size_t cbSize = Stream_GetRemainingLength(data); + + /* 2.2.1 Shared Message Header (SHARED_MSG_HEADER) */ + if (!Stream_CheckAndLogRequiredLength(TAG, data, 12) || (cbSize > UINT32_MAX)) + return ERROR_INVALID_DATA; + + input = data; + output = Stream_New(NULL, 256); + + if (!output) + return ERROR_OUTOFMEMORY; + + Stream_Seek(output, 8); + Stream_Read_UINT32(input, InterfaceId); /* InterfaceId (4 bytes) */ + Stream_Read_UINT32(input, MessageId); /* MessageId (4 bytes) */ + Stream_Read_UINT32(input, FunctionId); /* FunctionId (4 bytes) */ + DEBUG_TSMF("cbSize=%" PRIu32 " InterfaceId=0x%" PRIX32 " MessageId=0x%" PRIX32 + " FunctionId=0x%" PRIX32 "", + cbSize, InterfaceId, MessageId, FunctionId); + ifman.channel_callback = pChannelCallback; + ifman.decoder_name = ((TSMF_PLUGIN*)callback->plugin)->decoder_name; + ifman.audio_name = ((TSMF_PLUGIN*)callback->plugin)->audio_name; + ifman.audio_device = ((TSMF_PLUGIN*)callback->plugin)->audio_device; + CopyMemory(ifman.presentation_id, callback->presentation_id, GUID_SIZE); + ifman.stream_id = callback->stream_id; + ifman.message_id = MessageId; + ifman.input = input; + ifman.input_size = (UINT32)(cbSize - 12U); + ifman.output = output; + ifman.output_pending = FALSE; + ifman.output_interface_id = InterfaceId; + + // (void)fprintf(stderr, "InterfaceId: 0x%08"PRIX32" MessageId: 0x%08"PRIX32" FunctionId: + // 0x%08"PRIX32"\n", InterfaceId, MessageId, FunctionId); + + switch (InterfaceId) + { + case TSMF_INTERFACE_CAPABILITIES | STREAM_ID_NONE: + switch (FunctionId) + { + case RIM_EXCHANGE_CAPABILITY_REQUEST: + error = tsmf_ifman_rim_exchange_capability_request(&ifman); + processed = TRUE; + break; + + case RIMCALL_RELEASE: + case RIMCALL_QUERYINTERFACE: + break; + + default: + break; + } + + break; + + case TSMF_INTERFACE_DEFAULT | STREAM_ID_PROXY: + switch (FunctionId) + { + case SET_CHANNEL_PARAMS: + if (!Stream_CheckAndLogRequiredLength(TAG, input, GUID_SIZE + 4)) + { + error = ERROR_INVALID_DATA; + goto out; + } + + CopyMemory(callback->presentation_id, Stream_Pointer(input), GUID_SIZE); + Stream_Seek(input, GUID_SIZE); + Stream_Read_UINT32(input, callback->stream_id); + DEBUG_TSMF("SET_CHANNEL_PARAMS StreamId=%" PRIu32 "", callback->stream_id); + ifman.output_pending = TRUE; + processed = TRUE; + break; + + case EXCHANGE_CAPABILITIES_REQ: + error = tsmf_ifman_exchange_capability_request(&ifman); + processed = TRUE; + break; + + case CHECK_FORMAT_SUPPORT_REQ: + error = tsmf_ifman_check_format_support_request(&ifman); + processed = TRUE; + break; + + case ON_NEW_PRESENTATION: + error = tsmf_ifman_on_new_presentation(&ifman); + processed = TRUE; + break; + + case ADD_STREAM: + error = + tsmf_ifman_add_stream(&ifman, ((TSMF_PLUGIN*)callback->plugin)->rdpcontext); + processed = TRUE; + break; + + case SET_TOPOLOGY_REQ: + error = tsmf_ifman_set_topology_request(&ifman); + processed = TRUE; + break; + + case REMOVE_STREAM: + error = tsmf_ifman_remove_stream(&ifman); + processed = TRUE; + break; + + case SET_SOURCE_VIDEO_RECT: + error = tsmf_ifman_set_source_video_rect(&ifman); + processed = TRUE; + break; + + case SHUTDOWN_PRESENTATION_REQ: + error = tsmf_ifman_shutdown_presentation(&ifman); + processed = TRUE; + break; + + case ON_STREAM_VOLUME: + error = tsmf_ifman_on_stream_volume(&ifman); + processed = TRUE; + break; + + case ON_CHANNEL_VOLUME: + error = tsmf_ifman_on_channel_volume(&ifman); + processed = TRUE; + break; + + case SET_VIDEO_WINDOW: + error = tsmf_ifman_set_video_window(&ifman); + processed = TRUE; + break; + + case UPDATE_GEOMETRY_INFO: + error = tsmf_ifman_update_geometry_info(&ifman); + processed = TRUE; + break; + + case SET_ALLOCATOR: + error = tsmf_ifman_set_allocator(&ifman); + processed = TRUE; + break; + + case NOTIFY_PREROLL: + error = tsmf_ifman_notify_preroll(&ifman); + processed = TRUE; + break; + + case ON_SAMPLE: + error = tsmf_ifman_on_sample(&ifman); + processed = TRUE; + break; + + case ON_FLUSH: + error = tsmf_ifman_on_flush(&ifman); + processed = TRUE; + break; + + case ON_END_OF_STREAM: + error = tsmf_ifman_on_end_of_stream(&ifman); + processed = TRUE; + break; + + case ON_PLAYBACK_STARTED: + error = tsmf_ifman_on_playback_started(&ifman); + processed = TRUE; + break; + + case ON_PLAYBACK_PAUSED: + error = tsmf_ifman_on_playback_paused(&ifman); + processed = TRUE; + break; + + case ON_PLAYBACK_RESTARTED: + error = tsmf_ifman_on_playback_restarted(&ifman); + processed = TRUE; + break; + + case ON_PLAYBACK_STOPPED: + error = tsmf_ifman_on_playback_stopped(&ifman); + processed = TRUE; + break; + + case ON_PLAYBACK_RATE_CHANGED: + error = tsmf_ifman_on_playback_rate_changed(&ifman); + processed = TRUE; + break; + + case RIMCALL_RELEASE: + case RIMCALL_QUERYINTERFACE: + break; + + default: + break; + } + + break; + + default: + break; + } + + input = NULL; + ifman.input = NULL; + + if (error) + { + WLog_ERR(TAG, "ifman data received processing error %" PRIu32 "", error); + } + + if (!processed) + { + switch (FunctionId) + { + case RIMCALL_RELEASE: + /* [MS-RDPEXPS] 2.2.2.2 Interface Release (IFACE_RELEASE) + This message does not require a reply. */ + processed = TRUE; + ifman.output_pending = 1; + break; + + case RIMCALL_QUERYINTERFACE: + /* [MS-RDPEXPS] 2.2.2.1.2 Query Interface Response (QI_RSP) + This message is not supported in this channel. */ + processed = TRUE; + break; + default: + break; + } + + if (!processed) + { + WLog_ERR(TAG, + "Unknown InterfaceId: 0x%08" PRIX32 " MessageId: 0x%08" PRIX32 + " FunctionId: 0x%08" PRIX32 "\n", + InterfaceId, MessageId, FunctionId); + /* When a request is not implemented we return empty response indicating error */ + } + + processed = TRUE; + } + + if (processed && !ifman.output_pending) + { + /* Response packet does not have FunctionId */ + const size_t length = Stream_GetPosition(output); + if (length > UINT32_MAX) + goto out; + Stream_SetPosition(output, 0); + Stream_Write_UINT32(output, ifman.output_interface_id); + Stream_Write_UINT32(output, MessageId); + DEBUG_TSMF("response size %d", length); + error = callback->channel->Write(callback->channel, (UINT32)length, Stream_Buffer(output), + NULL); + + if (error) + { + WLog_ERR(TAG, "response error %" PRIu32 "", error); + } + } + +out: + Stream_Free(output, TRUE); + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT tsmf_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + TSMF_STREAM* stream = NULL; + TSMF_PRESENTATION* presentation = NULL; + TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*)pChannelCallback; + DEBUG_TSMF(""); + + if (callback->stream_id) + { + presentation = tsmf_presentation_find_by_id(callback->presentation_id); + + if (presentation) + { + stream = tsmf_stream_find_by_id(presentation, callback->stream_id); + + if (stream) + tsmf_stream_free(stream); + } + } + + free(pChannelCallback); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT tsmf_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, + IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept, + IWTSVirtualChannelCallback** ppCallback) +{ + TSMF_CHANNEL_CALLBACK* callback = NULL; + TSMF_LISTENER_CALLBACK* listener_callback = (TSMF_LISTENER_CALLBACK*)pListenerCallback; + DEBUG_TSMF(""); + callback = (TSMF_CHANNEL_CALLBACK*)calloc(1, sizeof(TSMF_CHANNEL_CALLBACK)); + + if (!callback) + return CHANNEL_RC_NO_MEMORY; + + callback->iface.OnDataReceived = tsmf_on_data_received; + callback->iface.OnClose = tsmf_on_close; + callback->iface.OnOpen = NULL; + callback->plugin = listener_callback->plugin; + callback->channel_mgr = listener_callback->channel_mgr; + callback->channel = pChannel; + *ppCallback = (IWTSVirtualChannelCallback*)callback; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT tsmf_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr) +{ + UINT status = 0; + TSMF_PLUGIN* tsmf = (TSMF_PLUGIN*)pPlugin; + DEBUG_TSMF(""); + tsmf->listener_callback = (TSMF_LISTENER_CALLBACK*)calloc(1, sizeof(TSMF_LISTENER_CALLBACK)); + + if (!tsmf->listener_callback) + return CHANNEL_RC_NO_MEMORY; + + tsmf->listener_callback->iface.OnNewChannelConnection = tsmf_on_new_channel_connection; + tsmf->listener_callback->plugin = pPlugin; + tsmf->listener_callback->channel_mgr = pChannelMgr; + status = pChannelMgr->CreateListener( + pChannelMgr, "TSMF", 0, (IWTSListenerCallback*)tsmf->listener_callback, &(tsmf->listener)); + tsmf->listener->pInterface = tsmf->iface.pInterface; + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT tsmf_plugin_terminated(IWTSPlugin* pPlugin) +{ + TSMF_PLUGIN* tsmf = (TSMF_PLUGIN*)pPlugin; + DEBUG_TSMF(""); + free(tsmf->listener_callback); + free(tsmf); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT tsmf_process_addin_args(IWTSPlugin* pPlugin, const ADDIN_ARGV* args) +{ + int status = 0; + DWORD flags = 0; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + TSMF_PLUGIN* tsmf = (TSMF_PLUGIN*)pPlugin; + COMMAND_LINE_ARGUMENT_A tsmf_args[] = { { "sys", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "audio subsystem" }, + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, + NULL, -1, NULL, "audio device name" }, + { "decoder", COMMAND_LINE_VALUE_REQUIRED, "", + NULL, NULL, -1, NULL, "decoder subsystem" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; + flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON; + status = CommandLineParseArgumentsA(args->argc, args->argv, tsmf_args, flags, tsmf, NULL, NULL); + + if (status != 0) + return ERROR_INVALID_DATA; + + arg = tsmf_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "sys") + { + tsmf->audio_name = _strdup(arg->Value); + + if (!tsmf->audio_name) + return ERROR_OUTOFMEMORY; + } + CommandLineSwitchCase(arg, "dev") + { + tsmf->audio_device = _strdup(arg->Value); + + if (!tsmf->audio_device) + return ERROR_OUTOFMEMORY; + } + CommandLineSwitchCase(arg, "decoder") + { + tsmf->decoder_name = _strdup(arg->Value); + + if (!tsmf->decoder_name) + return ERROR_OUTOFMEMORY; + } + CommandLineSwitchDefault(arg) + { + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE tsmf_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + UINT status = 0; + TSMF_PLUGIN* tsmf = NULL; + TsmfClientContext* context = NULL; + UINT error = CHANNEL_RC_NO_MEMORY; + tsmf = (TSMF_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, "tsmf"); + + if (!tsmf) + { + tsmf = (TSMF_PLUGIN*)calloc(1, sizeof(TSMF_PLUGIN)); + + if (!tsmf) + { + WLog_ERR(TAG, "calloc failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + tsmf->iface.Initialize = tsmf_plugin_initialize; + tsmf->iface.Connected = NULL; + tsmf->iface.Disconnected = NULL; + tsmf->iface.Terminated = tsmf_plugin_terminated; + tsmf->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints); + context = (TsmfClientContext*)calloc(1, sizeof(TsmfClientContext)); + + if (!context) + { + WLog_ERR(TAG, "calloc failed!"); + goto error_context; + } + + context->handle = (void*)tsmf; + tsmf->iface.pInterface = (void*)context; + + if (!tsmf_media_init()) + { + error = ERROR_INVALID_OPERATION; + goto error_init; + } + + status = pEntryPoints->RegisterPlugin(pEntryPoints, "tsmf", &tsmf->iface); + } + + if (status == CHANNEL_RC_OK) + { + status = tsmf_process_addin_args(&tsmf->iface, pEntryPoints->GetPluginData(pEntryPoints)); + } + + return status; +error_init: + free(context); +error_context: + free(tsmf); + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_main.h new file mode 100644 index 0000000000000000000000000000000000000000..fb783c180eb0f5e42ad81e8fb2953a0f75f45e50 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_main.h @@ -0,0 +1,65 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_MAIN_H +#define FREERDP_CHANNEL_TSMF_CLIENT_MAIN_H + +#include + +typedef struct +{ + IWTSListenerCallback iface; + + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; +} TSMF_LISTENER_CALLBACK; + +typedef struct +{ + IWTSVirtualChannelCallback iface; + + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; + IWTSVirtualChannel* channel; + + BYTE presentation_id[GUID_SIZE]; + UINT32 stream_id; +} TSMF_CHANNEL_CALLBACK; + +typedef struct +{ + IWTSPlugin iface; + + IWTSListener* listener; + TSMF_LISTENER_CALLBACK* listener_callback; + + const char* decoder_name; + const char* audio_name; + const char* audio_device; + + rdpContext* rdpcontext; +} TSMF_PLUGIN; + +BOOL tsmf_send_eos_response(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id); +BOOL tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id, + UINT64 duration, UINT32 data_size); + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_media.c b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_media.c new file mode 100644 index 0000000000000000000000000000000000000000..ff7460f0b3b092092be9b49c33e052c479cbca27 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_media.c @@ -0,0 +1,1555 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Media Container + * + * Copyright 2010-2011 Vic Lee + * Copyright 2012 Hewlett-Packard Development Company, L.P. + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#ifndef _WIN32 +#include +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "tsmf_constants.h" +#include "tsmf_types.h" +#include "tsmf_decoder.h" +#include "tsmf_audio.h" +#include "tsmf_main.h" +#include "tsmf_codec.h" +#include "tsmf_media.h" + +#define AUDIO_TOLERANCE 10000000LL + +/* 1 second = 10,000,000 100ns units*/ +#define VIDEO_ADJUST_MAX (10ULL * 1000ULL * 1000ULL) + +#define MAX_ACK_TIME 666667 + +#define AUDIO_MIN_BUFFER_LEVEL 3 +#define AUDIO_MAX_BUFFER_LEVEL 6 + +#define VIDEO_MIN_BUFFER_LEVEL 10 +#define VIDEO_MAX_BUFFER_LEVEL 30 + +struct S_TSMF_PRESENTATION +{ + BYTE presentation_id[GUID_SIZE]; + + const char* audio_name; + const char* audio_device; + + IWTSVirtualChannelCallback* channel_callback; + + UINT64 audio_start_time; + UINT64 audio_end_time; + + UINT32 volume; + UINT32 muted; + + wArrayList* stream_list; + + RECTANGLE_32 rect; + + UINT32 nr_rects; + RECTANGLE_32* rects; +}; + +struct S_TSMF_STREAM +{ + UINT32 stream_id; + + TSMF_PRESENTATION* presentation; + + ITSMFDecoder* decoder; + + int major_type; + int eos; + UINT32 eos_message_id; + IWTSVirtualChannelCallback* eos_channel_callback; + int delayed_stop; + UINT32 width; + UINT32 height; + + ITSMFAudioDevice* audio; + UINT32 sample_rate; + UINT32 channels; + UINT32 bits_per_sample; + + /* The start time of last played sample */ + UINT64 last_start_time; + /* The end_time of last played sample */ + UINT64 last_end_time; + /* Next sample should not start before this system time. */ + UINT64 next_start_time; + + UINT32 minBufferLevel; + UINT32 maxBufferLevel; + UINT32 currentBufferLevel; + + HANDLE play_thread; + HANDLE ack_thread; + HANDLE stopEvent; + HANDLE ready; + + wQueue* sample_list; + wQueue* sample_ack_list; + rdpContext* rdpcontext; + + BOOL seeking; +}; + +struct S_TSMF_SAMPLE +{ + UINT32 sample_id; + UINT64 start_time; + UINT64 end_time; + UINT64 duration; + UINT32 extensions; + UINT32 data_size; + BYTE* data; + UINT32 decoded_size; + UINT32 pixfmt; + + BOOL invalidTimestamps; + + TSMF_STREAM* stream; + IWTSVirtualChannelCallback* channel_callback; + UINT64 ack_time; +}; + +static wArrayList* presentation_list = NULL; +static int TERMINATING = 0; + +static void s_tsmf_presentation_free(void* obj); +static void s_tsmf_stream_free(void* obj); + +static UINT64 get_current_time(void) +{ + struct timeval tp; + gettimeofday(&tp, 0); + return ((UINT64)tp.tv_sec) * 10000000LL + ((UINT64)tp.tv_usec) * 10LL; +} + +static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) +{ + TSMF_SAMPLE* sample = NULL; + BOOL pending = FALSE; + + if (!stream) + return NULL; + + TSMF_PRESENTATION* presentation = stream->presentation; + + if (Queue_Count(stream->sample_list) < 1) + return NULL; + + if (sync) + { + if (stream->decoder) + { + if (stream->decoder->GetDecodedData) + { + if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO) + { + /* Check if some other stream has earlier sample that needs to be played first + */ + /* Start time is more reliable than end time as some stream types seem to have + * incorrect end times from the server + */ + if (stream->last_start_time > AUDIO_TOLERANCE) + { + ArrayList_Lock(presentation->stream_list); + const size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + TSMF_STREAM* s = + (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + + /* Start time is more reliable than end time as some stream types seem + * to have incorrect end times from the server + */ + if (s != stream && !s->eos && s->last_start_time && + s->last_start_time < stream->last_start_time - AUDIO_TOLERANCE) + { + DEBUG_TSMF("Pending due to audio tolerance"); + pending = TRUE; + break; + } + } + + ArrayList_Unlock(presentation->stream_list); + } + } + else + { + /* Start time is more reliable than end time as some stream types seem to have + * incorrect end times from the server + */ + if (stream->last_start_time > presentation->audio_start_time) + { + DEBUG_TSMF("Pending due to stream start time > audio start time"); + pending = TRUE; + } + } + } + } + } + + if (pending) + return NULL; + + sample = (TSMF_SAMPLE*)Queue_Dequeue(stream->sample_list); + + /* Only update stream last end time if the sample end time is valid and greater than the current + * stream end time */ + if (sample && (sample->end_time > stream->last_end_time) && (!sample->invalidTimestamps)) + stream->last_end_time = sample->end_time; + + /* Only update stream last start time if the sample start time is valid and greater than the + * current stream start time */ + if (sample && (sample->start_time > stream->last_start_time) && (!sample->invalidTimestamps)) + stream->last_start_time = sample->start_time; + + return sample; +} + +static void tsmf_sample_free(void* arg) +{ + TSMF_SAMPLE* sample = arg; + + if (!sample) + return; + + free(sample->data); + free(sample); +} + +static BOOL tsmf_sample_ack(TSMF_SAMPLE* sample) +{ + if (!sample) + return FALSE; + + return tsmf_playback_ack(sample->channel_callback, sample->sample_id, sample->duration, + sample->data_size); +} + +static BOOL tsmf_sample_queue_ack(TSMF_SAMPLE* sample) +{ + if (!sample) + return FALSE; + + if (!sample->stream) + return FALSE; + + return Queue_Enqueue(sample->stream->sample_ack_list, sample); +} + +/* Returns TRUE if no more samples are currently available + * Returns FALSE otherwise + */ +static BOOL tsmf_stream_process_ack(void* arg, BOOL force) +{ + TSMF_STREAM* stream = arg; + TSMF_SAMPLE* sample = NULL; + UINT64 ack_time = 0; + BOOL rc = FALSE; + + if (!stream) + return TRUE; + + Queue_Lock(stream->sample_ack_list); + sample = (TSMF_SAMPLE*)Queue_Peek(stream->sample_ack_list); + + if (!sample) + { + rc = TRUE; + goto finally; + } + + if (!force) + { + /* Do some min/max ack limiting if we have access to Buffer level information */ + if (stream->decoder && stream->decoder->BufferLevel) + { + /* Try to keep buffer level below max by withholding acks */ + if (stream->currentBufferLevel > stream->maxBufferLevel) + goto finally; + /* Try to keep buffer level above min by pushing acks through quickly */ + else if (stream->currentBufferLevel < stream->minBufferLevel) + goto dequeue; + } + + /* Time based acks only */ + ack_time = get_current_time(); + + if (sample->ack_time > ack_time) + goto finally; + } + +dequeue: + sample = Queue_Dequeue(stream->sample_ack_list); + + if (sample) + { + tsmf_sample_ack(sample); + tsmf_sample_free(sample); + } + +finally: + Queue_Unlock(stream->sample_ack_list); + return rc; +} + +TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, + IWTSVirtualChannelCallback* pChannelCallback) +{ + wObject* obj = NULL; + TSMF_PRESENTATION* presentation = NULL; + + if (!guid || !pChannelCallback) + return NULL; + + presentation = (TSMF_PRESENTATION*)calloc(1, sizeof(TSMF_PRESENTATION)); + + if (!presentation) + { + WLog_ERR(TAG, "calloc failed"); + return NULL; + } + + CopyMemory(presentation->presentation_id, guid, GUID_SIZE); + presentation->channel_callback = pChannelCallback; + presentation->volume = 5000; /* 50% */ + presentation->muted = 0; + + if (!(presentation->stream_list = ArrayList_New(TRUE))) + goto error_stream_list; + + obj = ArrayList_Object(presentation->stream_list); + if (!obj) + goto error_add; + obj->fnObjectFree = s_tsmf_stream_free; + + if (!ArrayList_Append(presentation_list, presentation)) + goto error_add; + + return presentation; +error_add: + ArrayList_Free(presentation->stream_list); +error_stream_list: + free(presentation); + return NULL; +} + +static char* guid_to_string(const BYTE* guid, char* str, size_t len) +{ + if (!guid || !str) + return NULL; + + for (size_t i = 0; i < GUID_SIZE && (len > 2 * i); i++) + (void)sprintf_s(str + (2 * i), len - 2 * i, "%02" PRIX8 "", guid[i]); + + return str; +} + +TSMF_PRESENTATION* tsmf_presentation_find_by_id(const BYTE* guid) +{ + BOOL found = FALSE; + char guid_str[GUID_SIZE * 2 + 1] = { 0 }; + TSMF_PRESENTATION* presentation = NULL; + ArrayList_Lock(presentation_list); + const size_t count = ArrayList_Count(presentation_list); + + for (size_t index = 0; index < count; index++) + { + presentation = (TSMF_PRESENTATION*)ArrayList_GetItem(presentation_list, index); + + if (memcmp(presentation->presentation_id, guid, GUID_SIZE) == 0) + { + found = TRUE; + break; + } + } + + ArrayList_Unlock(presentation_list); + + if (!found) + WLog_WARN(TAG, "presentation id %s not found", + guid_to_string(guid, guid_str, sizeof(guid_str))); + + return (found) ? presentation : NULL; +} + +static BOOL tsmf_sample_playback_video(TSMF_SAMPLE* sample) +{ + WINPR_ASSERT(sample); + + TSMF_STREAM* stream = sample->stream; + TSMF_PRESENTATION* presentation = stream->presentation; + TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*)sample->channel_callback; + TsmfClientContext* tsmf = (TsmfClientContext*)callback->plugin->pInterface; + DEBUG_TSMF("MessageId %" PRIu32 " EndTime %" PRIu64 " data_size %" PRIu32 " consumed.", + sample->sample_id, sample->end_time, sample->data_size); + + if (sample->data) + { + const UINT64 t = get_current_time(); + + /* Start time is more reliable than end time as some stream types seem to have incorrect + * end times from the server + */ + if (stream->next_start_time > t && + ((sample->start_time >= presentation->audio_start_time) || + ((sample->start_time < stream->last_start_time) && (!sample->invalidTimestamps)))) + { + size_t delay = (stream->next_start_time - t) / 10; + while (delay > 0) + { + const UINT32 d = (delay > UINT32_MAX) ? UINT32_MAX : (UINT32)delay; + USleep(d); + delay -= d; + } + } + + if (sample->stream->width > INT16_MAX) + return FALSE; + if (sample->stream->height > INT16_MAX) + return FALSE; + if (presentation->rect.left > INT16_MAX) + return FALSE; + if (presentation->rect.top > INT16_MAX) + return FALSE; + if (presentation->rect.width > INT16_MAX) + return FALSE; + if (presentation->rect.height > INT16_MAX) + return FALSE; + if (presentation->nr_rects > UINT16_MAX) + return FALSE; + + stream->next_start_time = t + sample->duration - 50000; + + TSMF_VIDEO_FRAME_EVENT event = { 0 }; + event.frameData = sample->data; + event.frameSize = sample->decoded_size; + event.framePixFmt = sample->pixfmt; + event.frameWidth = (INT16)sample->stream->width; + event.frameHeight = (INT16)sample->stream->height; + event.x = (INT16)presentation->rect.left; + event.y = (INT16)presentation->rect.top; + event.width = (INT16)presentation->rect.width; + event.height = (INT16)presentation->rect.height; + + if (presentation->nr_rects > 0) + { + event.numVisibleRects = (UINT16)presentation->nr_rects; + event.visibleRects = (RECTANGLE_16*)calloc(event.numVisibleRects, sizeof(RECTANGLE_16)); + + if (!event.visibleRects) + { + WLog_ERR(TAG, "can't allocate memory for copy rectangles"); + return FALSE; + } + + for (size_t x = 0; x < presentation->nr_rects; x++) + { + const RECTANGLE_32* cur = &presentation->rects[x]; + RECTANGLE_16* dst = &event.visibleRects[x]; + if ((cur->left > UINT16_MAX) || (cur->top > UINT16_MAX) || + (cur->width > UINT16_MAX) || (cur->height > UINT16_MAX)) + { + free(event.visibleRects); + return FALSE; + } + dst->right = dst->left = (UINT16)cur->left; + dst->bottom = dst->top = (UINT16)cur->top; + dst->right += (UINT16)cur->width; + dst->bottom += (UINT16)cur->height; + } + memcpy(event.visibleRects, presentation->rects, + presentation->nr_rects * sizeof(RECTANGLE_16)); + presentation->nr_rects = 0; + } + + /* The frame data ownership is passed to the event object, and is freed after the event is + * processed. */ + sample->data = NULL; + sample->decoded_size = 0; + + if (tsmf->FrameEvent) + tsmf->FrameEvent(tsmf, &event); + + free(event.frameData); + free(event.visibleRects); + } + + return TRUE; +} + +static BOOL tsmf_sample_playback_audio(TSMF_SAMPLE* sample) +{ + UINT64 latency = 0; + TSMF_STREAM* stream = sample->stream; + BOOL ret = 0; + DEBUG_TSMF("MessageId %" PRIu32 " EndTime %" PRIu64 " consumed.", sample->sample_id, + sample->end_time); + + if (stream->audio && sample->data) + { + ret = + sample->stream->audio->Play(sample->stream->audio, sample->data, sample->decoded_size); + free(sample->data); + sample->data = NULL; + sample->decoded_size = 0; + + if (stream->audio->GetLatency) + latency = stream->audio->GetLatency(stream->audio); + } + else + { + ret = TRUE; + latency = 0; + } + + sample->ack_time = latency + get_current_time(); + + /* Only update stream times if the sample timestamps are valid */ + if (!sample->invalidTimestamps) + { + stream->last_start_time = sample->start_time + latency; + stream->last_end_time = sample->end_time + latency; + stream->presentation->audio_start_time = sample->start_time + latency; + stream->presentation->audio_end_time = sample->end_time + latency; + } + + return ret; +} + +static BOOL tsmf_sample_playback(TSMF_SAMPLE* sample) +{ + BOOL ret = FALSE; + UINT32 width = 0; + UINT32 height = 0; + UINT32 pixfmt = 0; + TSMF_STREAM* stream = sample->stream; + + if (stream->decoder) + { + if (stream->decoder->DecodeEx) + { + /* Try to "sync" video buffers to audio buffers by looking at the running time for each + * stream The difference between the two running times causes an offset between audio + * and video actual render times. So, we try to adjust timestamps on the video buffer to + * match those on the audio buffer. + */ + if (stream->major_type == TSMF_MAJOR_TYPE_VIDEO) + { + TSMF_STREAM* temp_stream = NULL; + TSMF_PRESENTATION* presentation = stream->presentation; + ArrayList_Lock(presentation->stream_list); + const size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + UINT64 time_diff = 0; + temp_stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + + if (temp_stream->major_type == TSMF_MAJOR_TYPE_AUDIO) + { + UINT64 video_time = stream->decoder->GetRunningTime(stream->decoder); + UINT64 audio_time = + temp_stream->decoder->GetRunningTime(temp_stream->decoder); + UINT64 max_adjust = VIDEO_ADJUST_MAX; + + if (video_time < audio_time) + max_adjust = -VIDEO_ADJUST_MAX; + + if (video_time > audio_time) + time_diff = video_time - audio_time; + else + time_diff = audio_time - video_time; + + time_diff = time_diff < VIDEO_ADJUST_MAX ? time_diff : max_adjust; + sample->start_time += time_diff; + sample->end_time += time_diff; + break; + } + } + + ArrayList_Unlock(presentation->stream_list); + } + + ret = stream->decoder->DecodeEx(stream->decoder, sample->data, sample->data_size, + sample->extensions, sample->start_time, + sample->end_time, sample->duration); + } + else + { + ret = stream->decoder->Decode(stream->decoder, sample->data, sample->data_size, + sample->extensions); + } + } + + if (!ret) + { + WLog_ERR(TAG, "decode error, queue ack anyways"); + + if (!tsmf_sample_queue_ack(sample)) + { + WLog_ERR(TAG, "error queuing sample for ack"); + return FALSE; + } + + return TRUE; + } + + free(sample->data); + sample->data = NULL; + + if (stream->major_type == TSMF_MAJOR_TYPE_VIDEO) + { + if (stream->decoder->GetDecodedFormat) + { + pixfmt = stream->decoder->GetDecodedFormat(stream->decoder); + + if (pixfmt == ((UINT32)-1)) + { + WLog_ERR(TAG, "unable to decode video format"); + + if (!tsmf_sample_queue_ack(sample)) + { + WLog_ERR(TAG, "error queuing sample for ack"); + } + + return FALSE; + } + + sample->pixfmt = pixfmt; + } + + if (stream->decoder->GetDecodedDimension) + { + ret = stream->decoder->GetDecodedDimension(stream->decoder, &width, &height); + + if (ret && (width != stream->width || height != stream->height)) + { + DEBUG_TSMF("video dimension changed to %" PRIu32 " x %" PRIu32 "", width, height); + stream->width = width; + stream->height = height; + } + } + } + + if (stream->decoder->GetDecodedData) + { + sample->data = stream->decoder->GetDecodedData(stream->decoder, &sample->decoded_size); + + switch (sample->stream->major_type) + { + case TSMF_MAJOR_TYPE_VIDEO: + ret = tsmf_sample_playback_video(sample) && tsmf_sample_queue_ack(sample); + break; + + case TSMF_MAJOR_TYPE_AUDIO: + ret = tsmf_sample_playback_audio(sample) && tsmf_sample_queue_ack(sample); + break; + default: + break; + } + } + else + { + UINT64 ack_anticipation_time = get_current_time(); + BOOL buffer_filled = TRUE; + + /* Classify the buffer as filled once it reaches minimum level */ + if (stream->decoder->BufferLevel) + { + if (stream->currentBufferLevel < stream->minBufferLevel) + buffer_filled = FALSE; + } + + ack_anticipation_time += + (sample->duration / 2 < MAX_ACK_TIME) ? sample->duration / 2 : MAX_ACK_TIME; + + switch (sample->stream->major_type) + { + case TSMF_MAJOR_TYPE_VIDEO: + { + break; + } + + case TSMF_MAJOR_TYPE_AUDIO: + { + break; + } + default: + break; + } + + sample->ack_time = ack_anticipation_time; + + if (!tsmf_sample_queue_ack(sample)) + { + WLog_ERR(TAG, "error queuing sample for ack"); + ret = FALSE; + } + } + + return ret; +} + +static DWORD WINAPI tsmf_stream_ack_func(LPVOID arg) +{ + HANDLE hdl[2]; + TSMF_STREAM* stream = (TSMF_STREAM*)arg; + UINT error = CHANNEL_RC_OK; + DEBUG_TSMF("in %" PRIu32 "", stream->stream_id); + hdl[0] = stream->stopEvent; + hdl[1] = Queue_Event(stream->sample_ack_list); + + while (1) + { + DWORD ev = WaitForMultipleObjects(2, hdl, FALSE, 1000); + + if (ev == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "!", error); + break; + } + + if (stream->decoder) + if (stream->decoder->BufferLevel) + stream->currentBufferLevel = stream->decoder->BufferLevel(stream->decoder); + + if (stream->eos) + { + while ((stream->currentBufferLevel > 0) && !(tsmf_stream_process_ack(stream, TRUE))) + { + DEBUG_TSMF("END OF STREAM PROCESSING!"); + + if (stream->decoder && stream->decoder->BufferLevel) + stream->currentBufferLevel = stream->decoder->BufferLevel(stream->decoder); + else + stream->currentBufferLevel = 1; + + USleep(1000); + } + + tsmf_send_eos_response(stream->eos_channel_callback, stream->eos_message_id); + stream->eos = 0; + + if (stream->delayed_stop) + { + DEBUG_TSMF("Finishing delayed stream stop, now that eos has processed."); + tsmf_stream_flush(stream); + + if (stream->decoder && stream->decoder->Control) + stream->decoder->Control(stream->decoder, Control_Stop, NULL); + } + } + + /* Stream stopped force all of the acks to happen */ + if (ev == WAIT_OBJECT_0) + { + DEBUG_TSMF("ack: Stream stopped!"); + + while (1) + { + if (tsmf_stream_process_ack(stream, TRUE)) + break; + + USleep(1000); + } + + break; + } + + if (tsmf_stream_process_ack(stream, FALSE)) + continue; + + if (stream->currentBufferLevel > stream->minBufferLevel) + USleep(1000); + } + + if (error && stream->rdpcontext) + setChannelError(stream->rdpcontext, error, "tsmf_stream_ack_func reported an error"); + + DEBUG_TSMF("out %" PRIu32 "", stream->stream_id); + ExitThread(error); + return error; +} + +static DWORD WINAPI tsmf_stream_playback_func(LPVOID arg) +{ + HANDLE hdl[2]; + TSMF_SAMPLE* sample = NULL; + TSMF_STREAM* stream = (TSMF_STREAM*)arg; + TSMF_PRESENTATION* presentation = stream->presentation; + UINT error = CHANNEL_RC_OK; + DWORD status = 0; + DEBUG_TSMF("in %" PRIu32 "", stream->stream_id); + + if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO && stream->sample_rate && stream->channels && + stream->bits_per_sample) + { + if (stream->decoder) + { + if (stream->decoder->GetDecodedData) + { + stream->audio = tsmf_load_audio_device( + presentation->audio_name && presentation->audio_name[0] + ? presentation->audio_name + : NULL, + presentation->audio_device && presentation->audio_device[0] + ? presentation->audio_device + : NULL); + + if (stream->audio) + { + stream->audio->SetFormat(stream->audio, stream->sample_rate, stream->channels, + stream->bits_per_sample); + } + } + } + } + + hdl[0] = stream->stopEvent; + hdl[1] = Queue_Event(stream->sample_list); + + while (1) + { + status = WaitForMultipleObjects(2, hdl, FALSE, 1000); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForMultipleObjects failed with error %" PRIu32 "!", error); + break; + } + + status = WaitForSingleObject(stream->stopEvent, 0); + + if (status == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error); + break; + } + + if (status == WAIT_OBJECT_0) + break; + + if (stream->decoder) + if (stream->decoder->BufferLevel) + stream->currentBufferLevel = stream->decoder->BufferLevel(stream->decoder); + + sample = tsmf_stream_pop_sample(stream, 0); + + if (sample && !tsmf_sample_playback(sample)) + { + WLog_ERR(TAG, "error playing sample"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (stream->currentBufferLevel > stream->minBufferLevel) + USleep(1000); + } + + if (stream->audio) + { + stream->audio->Free(stream->audio); + stream->audio = NULL; + } + + if (error && stream->rdpcontext) + setChannelError(stream->rdpcontext, error, "tsmf_stream_playback_func reported an error"); + + DEBUG_TSMF("out %" PRIu32 "", stream->stream_id); + ExitThread(error); + return error; +} + +static BOOL tsmf_stream_start(TSMF_STREAM* stream) +{ + if (!stream || !stream->presentation || !stream->decoder || !stream->decoder->Control) + return TRUE; + + stream->eos = 0; + return stream->decoder->Control(stream->decoder, Control_Restart, NULL); +} + +static BOOL tsmf_stream_stop(TSMF_STREAM* stream) +{ + if (!stream || !stream->decoder || !stream->decoder->Control) + return TRUE; + + /* If stopping after eos - we delay until the eos has been processed + * this allows us to process any buffers that have been acked even though + * they have not actually been completely processes by the decoder + */ + if (stream->eos) + { + DEBUG_TSMF("Setting up a delayed stop for once the eos has been processed."); + stream->delayed_stop = 1; + return TRUE; + } + /* Otherwise force stop immediately */ + else + { + DEBUG_TSMF("Stop with no pending eos response, so do it immediately."); + tsmf_stream_flush(stream); + return stream->decoder->Control(stream->decoder, Control_Stop, NULL); + } +} + +static BOOL tsmf_stream_pause(TSMF_STREAM* stream) +{ + if (!stream || !stream->decoder || !stream->decoder->Control) + return TRUE; + + return stream->decoder->Control(stream->decoder, Control_Pause, NULL); +} + +static BOOL tsmf_stream_restart(TSMF_STREAM* stream) +{ + if (!stream || !stream->decoder || !stream->decoder->Control) + return TRUE; + + stream->eos = 0; + return stream->decoder->Control(stream->decoder, Control_Restart, NULL); +} + +static BOOL tsmf_stream_change_volume(TSMF_STREAM* stream, UINT32 newVolume, UINT32 muted) +{ + if (!stream || !stream->decoder) + return TRUE; + + if (stream->decoder != NULL && stream->decoder->ChangeVolume) + { + return stream->decoder->ChangeVolume(stream->decoder, newVolume, muted); + } + else if (stream->audio != NULL && stream->audio->ChangeVolume) + { + return stream->audio->ChangeVolume(stream->audio, newVolume, muted); + } + + return TRUE; +} + +BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION* presentation, UINT32 newVolume, + UINT32 muted) +{ + TSMF_STREAM* stream = NULL; + BOOL ret = TRUE; + presentation->volume = newVolume; + presentation->muted = muted; + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + ret &= tsmf_stream_change_volume(stream, newVolume, muted); + } + + ArrayList_Unlock(presentation->stream_list); + return ret; +} + +BOOL tsmf_presentation_paused(TSMF_PRESENTATION* presentation) +{ + TSMF_STREAM* stream = NULL; + BOOL ret = TRUE; + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + ret &= tsmf_stream_pause(stream); + } + + ArrayList_Unlock(presentation->stream_list); + return ret; +} + +BOOL tsmf_presentation_restarted(TSMF_PRESENTATION* presentation) +{ + TSMF_STREAM* stream = NULL; + BOOL ret = TRUE; + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + ret &= tsmf_stream_restart(stream); + } + + ArrayList_Unlock(presentation->stream_list); + return ret; +} + +BOOL tsmf_presentation_start(TSMF_PRESENTATION* presentation) +{ + TSMF_STREAM* stream = NULL; + BOOL ret = TRUE; + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + ret &= tsmf_stream_start(stream); + } + + ArrayList_Unlock(presentation->stream_list); + return ret; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +UINT tsmf_presentation_sync(TSMF_PRESENTATION* presentation) +{ + UINT error = 0; + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + TSMF_STREAM* stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + + if (WaitForSingleObject(stream->ready, 500) == WAIT_FAILED) + { + error = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", error); + return error; + } + } + + ArrayList_Unlock(presentation->stream_list); + return CHANNEL_RC_OK; +} + +BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation) +{ + TSMF_STREAM* stream = NULL; + BOOL ret = TRUE; + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + ret &= tsmf_stream_stop(stream); + } + + ArrayList_Unlock(presentation->stream_list); + presentation->audio_start_time = 0; + presentation->audio_end_time = 0; + return ret; +} + +BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 num_rects, + const RECTANGLE_32* rects) +{ + TSMF_STREAM* stream = NULL; + BOOL ret = TRUE; + + /* The server may send messages with invalid width / height. + * Ignore those messages. */ + if (!width || !height) + return TRUE; + + /* Streams can be added/removed from the presentation and the server will resend geometry info + * when a new stream is added to the presentation. Also, num_rects is used to indicate whether + * or not the window is visible. So, always process a valid message with unchanged position/size + * and/or no visibility rects. + */ + presentation->rect.left = x; + presentation->rect.top = y; + presentation->rect.width = width; + presentation->rect.height = height; + void* tmp_rects = realloc(presentation->rects, sizeof(RECTANGLE_32) * num_rects); + + if (!tmp_rects && num_rects) + return FALSE; + + presentation->nr_rects = num_rects; + presentation->rects = (RECTANGLE_32*)tmp_rects; + if (presentation->rects) + CopyMemory(presentation->rects, rects, sizeof(RECTANGLE_32) * num_rects); + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + + if (!stream->decoder) + continue; + + if (stream->decoder->UpdateRenderingArea) + { + ret = stream->decoder->UpdateRenderingArea(stream->decoder, x, y, width, height, + num_rects, rects); + } + } + + ArrayList_Unlock(presentation->stream_list); + return ret; +} + +void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation, const char* name, + const char* device) +{ + presentation->audio_name = name; + presentation->audio_device = device; +} + +BOOL tsmf_stream_flush(TSMF_STREAM* stream) +{ + BOOL ret = TRUE; + + // TSMF_SAMPLE* sample; + /* TODO: free lists */ + if (stream->audio) + ret = stream->audio->Flush(stream->audio); + + stream->eos = 0; + stream->eos_message_id = 0; + stream->eos_channel_callback = NULL; + stream->delayed_stop = 0; + stream->last_end_time = 0; + stream->next_start_time = 0; + + if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO) + { + stream->presentation->audio_start_time = 0; + stream->presentation->audio_end_time = 0; + } + + return ret; +} + +void s_tsmf_presentation_free(void* obj) +{ + TSMF_PRESENTATION* presentation = (TSMF_PRESENTATION*)obj; + + if (presentation) + { + tsmf_presentation_stop(presentation); + ArrayList_Clear(presentation->stream_list); + ArrayList_Free(presentation->stream_list); + free(presentation->rects); + ZeroMemory(presentation, sizeof(TSMF_PRESENTATION)); + free(presentation); + } +} + +void tsmf_presentation_free(TSMF_PRESENTATION* presentation) +{ + ArrayList_Remove(presentation_list, presentation); +} + +TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id, + rdpContext* rdpcontext) +{ + wObject* obj = NULL; + TSMF_STREAM* stream = NULL; + stream = tsmf_stream_find_by_id(presentation, stream_id); + + if (stream) + { + WLog_ERR(TAG, "duplicated stream id %" PRIu32 "!", stream_id); + return NULL; + } + + stream = (TSMF_STREAM*)calloc(1, sizeof(TSMF_STREAM)); + + if (!stream) + { + WLog_ERR(TAG, "Calloc failed"); + return NULL; + } + + stream->minBufferLevel = VIDEO_MIN_BUFFER_LEVEL; + stream->maxBufferLevel = VIDEO_MAX_BUFFER_LEVEL; + stream->currentBufferLevel = 1; + stream->seeking = FALSE; + stream->eos = 0; + stream->eos_message_id = 0; + stream->eos_channel_callback = NULL; + stream->stream_id = stream_id; + stream->presentation = presentation; + stream->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (!stream->stopEvent) + goto error_stopEvent; + + stream->ready = CreateEvent(NULL, TRUE, TRUE, NULL); + + if (!stream->ready) + goto error_ready; + + stream->sample_list = Queue_New(TRUE, -1, -1); + + if (!stream->sample_list) + goto error_sample_list; + + obj = Queue_Object(stream->sample_list); + if (!obj) + goto error_sample_ack_list; + obj->fnObjectFree = tsmf_sample_free; + + stream->sample_ack_list = Queue_New(TRUE, -1, -1); + + if (!stream->sample_ack_list) + goto error_sample_ack_list; + + obj = Queue_Object(stream->sample_ack_list); + if (!obj) + goto error_play_thread; + obj->fnObjectFree = tsmf_sample_free; + + stream->play_thread = + CreateThread(NULL, 0, tsmf_stream_playback_func, stream, CREATE_SUSPENDED, NULL); + + if (!stream->play_thread) + goto error_play_thread; + + stream->ack_thread = + CreateThread(NULL, 0, tsmf_stream_ack_func, stream, CREATE_SUSPENDED, NULL); + + if (!stream->ack_thread) + goto error_ack_thread; + + if (!ArrayList_Append(presentation->stream_list, stream)) + goto error_add; + + stream->rdpcontext = rdpcontext; + return stream; +error_add: + (void)SetEvent(stream->stopEvent); + + if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED) + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", GetLastError()); + +error_ack_thread: + (void)SetEvent(stream->stopEvent); + + if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED) + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", GetLastError()); + +error_play_thread: + Queue_Free(stream->sample_ack_list); +error_sample_ack_list: + Queue_Free(stream->sample_list); +error_sample_list: + (void)CloseHandle(stream->ready); +error_ready: + (void)CloseHandle(stream->stopEvent); +error_stopEvent: + free(stream); + return NULL; +} + +void tsmf_stream_start_threads(TSMF_STREAM* stream) +{ + ResumeThread(stream->play_thread); + ResumeThread(stream->ack_thread); +} + +TSMF_STREAM* tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stream_id) +{ + BOOL found = FALSE; + TSMF_STREAM* stream = NULL; + ArrayList_Lock(presentation->stream_list); + size_t count = ArrayList_Count(presentation->stream_list); + + for (size_t index = 0; index < count; index++) + { + stream = (TSMF_STREAM*)ArrayList_GetItem(presentation->stream_list, index); + + if (stream->stream_id == stream_id) + { + found = TRUE; + break; + } + } + + ArrayList_Unlock(presentation->stream_list); + return (found) ? stream : NULL; +} + +static void tsmf_stream_resync(void* arg) +{ + TSMF_STREAM* stream = arg; + (void)ResetEvent(stream->ready); +} + +BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, wStream* s) +{ + TS_AM_MEDIA_TYPE mediatype; + BOOL ret = TRUE; + + if (stream->decoder) + { + WLog_ERR(TAG, "duplicated call"); + return FALSE; + } + + if (!tsmf_codec_parse_media_type(&mediatype, s)) + { + WLog_ERR(TAG, "unable to parse media type"); + return FALSE; + } + + if (mediatype.MajorType == TSMF_MAJOR_TYPE_VIDEO) + { + DEBUG_TSMF("video width %" PRIu32 " height %" PRIu32 " bit_rate %" PRIu32 + " frame_rate %f codec_data %" PRIu32 "", + mediatype.Width, mediatype.Height, mediatype.BitRate, + (double)mediatype.SamplesPerSecond.Numerator / + (double)mediatype.SamplesPerSecond.Denominator, + mediatype.ExtraDataSize); + stream->minBufferLevel = VIDEO_MIN_BUFFER_LEVEL; + stream->maxBufferLevel = VIDEO_MAX_BUFFER_LEVEL; + } + else if (mediatype.MajorType == TSMF_MAJOR_TYPE_AUDIO) + { + DEBUG_TSMF("audio channel %" PRIu32 " sample_rate %" PRIu32 " bits_per_sample %" PRIu32 + " codec_data %" PRIu32 "", + mediatype.Channels, mediatype.SamplesPerSecond.Numerator, + mediatype.BitsPerSample, mediatype.ExtraDataSize); + stream->sample_rate = mediatype.SamplesPerSecond.Numerator; + stream->channels = mediatype.Channels; + stream->bits_per_sample = mediatype.BitsPerSample; + + if (stream->bits_per_sample == 0) + stream->bits_per_sample = 16; + + stream->minBufferLevel = AUDIO_MIN_BUFFER_LEVEL; + stream->maxBufferLevel = AUDIO_MAX_BUFFER_LEVEL; + } + + stream->major_type = mediatype.MajorType; + stream->width = mediatype.Width; + stream->height = mediatype.Height; + stream->decoder = tsmf_load_decoder(name, &mediatype); + ret &= tsmf_stream_change_volume(stream, stream->presentation->volume, + stream->presentation->muted); + + if (!stream->decoder) + return FALSE; + + if (stream->decoder->SetAckFunc) + ret &= stream->decoder->SetAckFunc(stream->decoder, tsmf_stream_process_ack, stream); + + if (stream->decoder->SetSyncFunc) + ret &= stream->decoder->SetSyncFunc(stream->decoder, tsmf_stream_resync, stream); + + return ret; +} + +void tsmf_stream_end(TSMF_STREAM* stream, UINT32 message_id, + IWTSVirtualChannelCallback* pChannelCallback) +{ + if (!stream) + return; + + stream->eos = 1; + stream->eos_message_id = message_id; + stream->eos_channel_callback = pChannelCallback; +} + +void s_tsmf_stream_free(void* obj) +{ + TSMF_STREAM* stream = (TSMF_STREAM*)obj; + + if (!stream) + return; + + tsmf_stream_stop(stream); + (void)SetEvent(stream->stopEvent); + + if (stream->play_thread) + { + if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED) + { + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", GetLastError()); + return; + } + + (void)CloseHandle(stream->play_thread); + stream->play_thread = NULL; + } + + if (stream->ack_thread) + { + if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED) + { + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "!", GetLastError()); + return; + } + + (void)CloseHandle(stream->ack_thread); + stream->ack_thread = NULL; + } + + Queue_Free(stream->sample_list); + Queue_Free(stream->sample_ack_list); + + if (stream->decoder && stream->decoder->Free) + { + stream->decoder->Free(stream->decoder); + stream->decoder = NULL; + } + + (void)CloseHandle(stream->stopEvent); + (void)CloseHandle(stream->ready); + ZeroMemory(stream, sizeof(TSMF_STREAM)); + free(stream); +} + +void tsmf_stream_free(TSMF_STREAM* stream) +{ + TSMF_PRESENTATION* presentation = stream->presentation; + ArrayList_Remove(presentation->stream_list, stream); +} + +BOOL tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback* pChannelCallback, + UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, + UINT32 extensions, UINT32 data_size, BYTE* data) +{ + TSMF_SAMPLE* sample = NULL; + (void)SetEvent(stream->ready); + + if (TERMINATING) + return TRUE; + + sample = (TSMF_SAMPLE*)calloc(1, sizeof(TSMF_SAMPLE)); + + if (!sample) + { + WLog_ERR(TAG, "calloc sample failed!"); + return FALSE; + } + + sample->sample_id = sample_id; + sample->start_time = start_time; + sample->end_time = end_time; + sample->duration = duration; + sample->extensions = extensions; + + if ((sample->extensions & 0x00000080) || (sample->extensions & 0x00000040)) + sample->invalidTimestamps = TRUE; + else + sample->invalidTimestamps = FALSE; + + sample->stream = stream; + sample->channel_callback = pChannelCallback; + sample->data_size = data_size; + sample->data = calloc(1, data_size + TSMF_BUFFER_PADDING_SIZE); + + if (!sample->data) + goto fail; + + CopyMemory(sample->data, data, data_size); + if (!Queue_Enqueue(stream->sample_list, sample)) + goto fail; + + return TRUE; + +fail: + if (sample) + free(sample->data); + free(sample); + return FALSE; +} + +#ifndef _WIN32 + +static void tsmf_signal_handler(int s) +{ + TERMINATING = 1; + ArrayList_Free(presentation_list); + + if (s == SIGINT) + { + (void)signal(s, SIG_DFL); + kill(getpid(), s); + } + else if (s == SIGUSR1) + { + (void)signal(s, SIG_DFL); + } +} + +#endif + +BOOL tsmf_media_init(void) +{ + wObject* obj = NULL; +#ifndef _WIN32 + struct sigaction sigtrap; + sigtrap.sa_handler = tsmf_signal_handler; + sigemptyset(&sigtrap.sa_mask); + sigtrap.sa_flags = 0; + sigaction(SIGINT, &sigtrap, 0); + sigaction(SIGUSR1, &sigtrap, 0); +#endif + + if (!presentation_list) + { + presentation_list = ArrayList_New(TRUE); + + if (!presentation_list) + return FALSE; + + obj = ArrayList_Object(presentation_list); + if (!obj) + return FALSE; + obj->fnObjectFree = s_tsmf_presentation_free; + } + + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_media.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_media.h new file mode 100644 index 0000000000000000000000000000000000000000..eaa9cac8833d79748cab5cdaa97eca0ae8aa7049 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_media.h @@ -0,0 +1,72 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Media Container + * + * Copyright 2010-2011 Vic Lee + * Copyright 2012 Hewlett-Packard Development Company, L.P. + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The media container maintains a global list of presentations, and a list of + * streams in each presentation. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_MEDIA_H +#define FREERDP_CHANNEL_TSMF_CLIENT_MEDIA_H + +#include + +typedef struct S_TSMF_PRESENTATION TSMF_PRESENTATION; + +typedef struct S_TSMF_STREAM TSMF_STREAM; + +typedef struct S_TSMF_SAMPLE TSMF_SAMPLE; + +TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, + IWTSVirtualChannelCallback* pChannelCallback); +TSMF_PRESENTATION* tsmf_presentation_find_by_id(const BYTE* guid); +BOOL tsmf_presentation_start(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_stop(TSMF_PRESENTATION* presentation); +UINT tsmf_presentation_sync(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_paused(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_restarted(TSMF_PRESENTATION* presentation); +BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION* presentation, UINT32 newVolume, + UINT32 muted); +BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, UINT32 x, UINT32 y, + UINT32 width, UINT32 height, UINT32 num_rects, + const RECTANGLE_32* rects); +void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation, const char* name, + const char* device); +void tsmf_presentation_free(TSMF_PRESENTATION* presentation); + +TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id, + rdpContext* rdpcontext); +TSMF_STREAM* tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stream_id); +BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, wStream* s); +void tsmf_stream_end(TSMF_STREAM* stream, UINT32 message_id, + IWTSVirtualChannelCallback* pChannelCallback); +void tsmf_stream_free(TSMF_STREAM* stream); +BOOL tsmf_stream_flush(TSMF_STREAM* stream); + +BOOL tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback* pChannelCallback, + UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, + UINT32 extensions, UINT32 data_size, BYTE* data); + +BOOL tsmf_media_init(void); +void tsmf_stream_start_threads(TSMF_STREAM* stream); + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_MEDIA_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_types.h b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_types.h new file mode 100644 index 0000000000000000000000000000000000000000..708f2083d8f0e236890e19fe7b1f399b275d6d41 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/tsmf/client/tsmf_types.h @@ -0,0 +1,61 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Types + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_TYPES_H +#define FREERDP_CHANNEL_TSMF_CLIENT_TYPES_H + +#include + +#include +#include +#include + +#define TAG CHANNELS_TAG("tsmf.client") + +#ifdef WITH_DEBUG_TSMF +#define DEBUG_TSMF(...) WLog_DBG(TAG, __VA_ARGS__) +#else +#define DEBUG_TSMF(...) \ + do \ + { \ + } while (0) +#endif + +typedef struct +{ + int MajorType; + int SubType; + int FormatType; + + UINT32 Width; + UINT32 Height; + UINT32 BitRate; + struct + { + UINT32 Numerator; + UINT32 Denominator; + } SamplesPerSecond; + UINT32 Channels; + UINT32 BitsPerSample; + UINT32 BlockAlign; + const BYTE* ExtraData; + UINT32 ExtraDataSize; +} TS_AM_MEDIA_TYPE; + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_TYPES_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7443f421d0d63af6c597fdceb266f6d1e368572 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/CMakeLists.txt @@ -0,0 +1,30 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("urbdrc") + +include_directories(common) +add_subdirectory(common) + +if(WITH_CLIENT_CHANNELS) + option(WITH_DEBUG_URBDRC "Dump data send/received in URBDRC channel" ${DEFAULT_DEBUG_OPTION}) + + find_package(libusb-1.0 REQUIRED) + include_directories(SYSTEM ${LIBUSB_1_INCLUDE_DIRS}) + + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..2612bb1fe6a1afd48875122170a7357279e65f3c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/ChannelOptions.cmake @@ -0,0 +1,26 @@ +if(IOS OR ANDROID) + set(OPTION_DEFAULT OFF) + set(OPTION_CLIENT_DEFAULT OFF) + set(OPTION_SERVER_DEFAULT OFF) +else() + set(OPTION_DEFAULT ON) + set(OPTION_CLIENT_DEFAULT ON) + set(OPTION_SERVER_DEFAULT OFF) +endif() + +define_channel_options( + NAME + "urbdrc" + TYPE + "dynamic" + DESCRIPTION + "USB Devices Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEUSB]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f9c8e72bae9dd4be09a0d94be41925d290aafdb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/CMakeLists.txt @@ -0,0 +1,31 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Atrust corp. +# Copyright 2012 Alfred Liu +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("urbdrc") + +set(${MODULE_PREFIX}_SRCS data_transfer.c data_transfer.h urbdrc_main.c urbdrc_main.h) + +set(${MODULE_PREFIX}_LIBS winpr freerdp urbdrc-common) +if(UDEV_FOUND AND UDEV_LIBRARIES) + list(APPEND ${MODULE_PREFIX}_LIBS ${UDEV_LIBRARIES}) +endif() + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") + +# libusb subsystem +add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "libusb" "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/data_transfer.c b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/data_transfer.c new file mode 100644 index 0000000000000000000000000000000000000000..5a04ffce263bb6dce9ef14b1726c45e1a9ad722e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/data_transfer.c @@ -0,0 +1,1956 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include + +#include + +#include "urbdrc_types.h" +#include "data_transfer.h" + +static void usb_process_get_port_status(IUDEVICE* pdev, wStream* out) +{ + int bcdUSB = pdev->query_device_descriptor(pdev, BCD_USB); + + switch (bcdUSB) + { + case USB_v1_0: + Stream_Write_UINT32(out, 0x303); + break; + + case USB_v1_1: + Stream_Write_UINT32(out, 0x103); + break; + + case USB_v2_0: + default: + Stream_Write_UINT32(out, 0x503); + break; + } +} + +static UINT urb_write_completion(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, BOOL noAck, + wStream* out, UINT32 InterfaceId, UINT32 MessageId, + UINT32 RequestId, UINT32 usbd_status, UINT32 OutputBufferSize) +{ + if (!out) + return ERROR_INVALID_PARAMETER; + + if (Stream_Capacity(out) < OutputBufferSize + 36) + { + Stream_Free(out, TRUE); + return ERROR_INVALID_PARAMETER; + } + + Stream_SetPosition(out, 0); + Stream_Write_UINT32(out, InterfaceId); /** interface */ + Stream_Write_UINT32(out, MessageId); /** message id */ + + if (OutputBufferSize != 0) + Stream_Write_UINT32(out, URB_COMPLETION); + else + Stream_Write_UINT32(out, URB_COMPLETION_NO_DATA); + + Stream_Write_UINT32(out, RequestId); /** RequestId */ + Stream_Write_UINT32(out, 8); /** CbTsUrbResult */ + /** TsUrbResult TS_URB_RESULT_HEADER */ + Stream_Write_UINT16(out, 8); /** Size */ + Stream_Write_UINT16(out, 0); /* Padding */ + Stream_Write_UINT32(out, usbd_status); /** UsbdStatus */ + Stream_Write_UINT32(out, 0); /** HResult */ + Stream_Write_UINT32(out, OutputBufferSize); /** OutputBufferSize */ + Stream_Seek(out, OutputBufferSize); + + if (!noAck) + return stream_write_and_free(callback->plugin, callback->channel, out); + else + Stream_Free(out, TRUE); + + return ERROR_SUCCESS; +} + +static wStream* urb_create_iocompletion(UINT32 InterfaceField, UINT32 MessageId, UINT32 RequestId, + UINT32 OutputBufferSize) +{ + const UINT32 InterfaceId = (STREAM_ID_PROXY << 30) | (InterfaceField & 0x3FFFFFFF); + +#if UINT32_MAX >= SIZE_MAX + if (OutputBufferSize > UINT32_MAX - 28ull) + return NULL; +#endif + + wStream* out = Stream_New(NULL, OutputBufferSize + 28ull); + + if (!out) + return NULL; + + Stream_Write_UINT32(out, InterfaceId); /** interface */ + Stream_Write_UINT32(out, MessageId); /** message id */ + Stream_Write_UINT32(out, IOCONTROL_COMPLETION); /** function id */ + Stream_Write_UINT32(out, RequestId); /** RequestId */ + Stream_Write_UINT32(out, USBD_STATUS_SUCCESS); /** HResult */ + Stream_Write_UINT32(out, OutputBufferSize); /** Information */ + Stream_Write_UINT32(out, OutputBufferSize); /** OutputBufferSize */ + return out; +} + +static UINT urbdrc_process_register_request_callback(IUDEVICE* pdev, + GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + IUDEVMAN* udevman) +{ + UINT32 NumRequestCompletion = 0; + UINT32 RequestCompletion = 0; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + WLog_Print(urbdrc->log, WLOG_DEBUG, "urbdrc_process_register_request_callback"); + + if (Stream_GetRemainingLength(s) >= 8) + { + Stream_Read_UINT32(s, NumRequestCompletion); /** must be 1 */ + /** RequestCompletion: + * unique Request Completion interface for the client to use */ + Stream_Read_UINT32(s, RequestCompletion); + pdev->set_ReqCompletion(pdev, RequestCompletion); + } + else if (Stream_GetRemainingLength(s) >= 4) /** Unregister the device */ + { + Stream_Read_UINT32(s, RequestCompletion); + + if (pdev->get_ReqCompletion(pdev) == RequestCompletion) + pdev->setChannelClosed(pdev); + } + else + return ERROR_INVALID_DATA; + + return ERROR_SUCCESS; +} + +static UINT urbdrc_process_cancel_request(IUDEVICE* pdev, wStream* s, IUDEVMAN* udevman) +{ + UINT32 CancelId = 0; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)udevman->plugin; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, CancelId); + WLog_Print(urbdrc->log, WLOG_DEBUG, "CANCEL_REQUEST: CancelId=%08" PRIx32 "", CancelId); + + if (pdev->cancel_transfer_request(pdev, CancelId) < 0) + return ERROR_INTERNAL_ERROR; + + return ERROR_SUCCESS; +} + +static UINT urbdrc_process_retract_device_request(IUDEVICE* pdev, wStream* s, IUDEVMAN* udevman) +{ + UINT32 Reason = 0; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!s || !udevman) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)udevman->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, Reason); /** Reason */ + + switch (Reason) + { + case UsbRetractReason_BlockedByPolicy: + WLog_Print(urbdrc->log, WLOG_DEBUG, + "UsbRetractReason_BlockedByPolicy: now it is not support"); + return ERROR_ACCESS_DENIED; + + default: + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urbdrc_process_retract_device_request: Unknown Reason %" PRIu32 "", Reason); + return ERROR_ACCESS_DENIED; + } + + return ERROR_SUCCESS; +} + +static UINT urbdrc_process_io_control(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 MessageId, IUDEVMAN* udevman) +{ + UINT32 InterfaceId = 0; + UINT32 IoControlCode = 0; + UINT32 InputBufferSize = 0; + UINT32 OutputBufferSize = 0; + UINT32 RequestId = 0; + UINT32 usbd_status = USBD_STATUS_SUCCESS; + wStream* out = NULL; + int success = 0; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, IoControlCode); + Stream_Read_UINT32(s, InputBufferSize); + + if (!Stream_SafeSeek(s, InputBufferSize)) + return ERROR_INVALID_DATA; + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8ULL)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, OutputBufferSize); + Stream_Read_UINT32(s, RequestId); + + if (OutputBufferSize > UINT32_MAX - 4) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + out = urb_create_iocompletion(InterfaceId, MessageId, RequestId, OutputBufferSize + 4); + + if (!out) + return ERROR_OUTOFMEMORY; + + switch (IoControlCode) + { + case IOCTL_INTERNAL_USB_SUBMIT_URB: /** 0x00220003 */ + WLog_Print(urbdrc->log, WLOG_DEBUG, "ioctl: IOCTL_INTERNAL_USB_SUBMIT_URB"); + WLog_Print(urbdrc->log, WLOG_ERROR, + " Function IOCTL_INTERNAL_USB_SUBMIT_URB: Unchecked"); + break; + + case IOCTL_INTERNAL_USB_RESET_PORT: /** 0x00220007 */ + WLog_Print(urbdrc->log, WLOG_DEBUG, "ioctl: IOCTL_INTERNAL_USB_RESET_PORT"); + break; + + case IOCTL_INTERNAL_USB_GET_PORT_STATUS: /** 0x00220013 */ + WLog_Print(urbdrc->log, WLOG_DEBUG, "ioctl: IOCTL_INTERNAL_USB_GET_PORT_STATUS"); + success = pdev->query_device_port_status(pdev, &usbd_status, &OutputBufferSize, + Stream_Pointer(out)); + + if (success) + { + if (!Stream_SafeSeek(out, OutputBufferSize)) + { + Stream_Free(out, TRUE); + return ERROR_INVALID_DATA; + } + + if (pdev->isExist(pdev) == 0) + Stream_Write_UINT32(out, 0); + else + usb_process_get_port_status(pdev, out); + } + + break; + + case IOCTL_INTERNAL_USB_CYCLE_PORT: /** 0x0022001F */ + WLog_Print(urbdrc->log, WLOG_DEBUG, "ioctl: IOCTL_INTERNAL_USB_CYCLE_PORT"); + WLog_Print(urbdrc->log, WLOG_ERROR, + " Function IOCTL_INTERNAL_USB_CYCLE_PORT: Unchecked"); + break; + + case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: /** 0x00220027 */ + WLog_Print(urbdrc->log, WLOG_DEBUG, + "ioctl: IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION"); + WLog_Print(urbdrc->log, WLOG_ERROR, + " Function IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: Unchecked"); + break; + + default: + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urbdrc_process_io_control: unknown IoControlCode 0x%" PRIX32 "", + IoControlCode); + Stream_Free(out, TRUE); + return ERROR_INVALID_OPERATION; + } + + return stream_write_and_free(callback->plugin, callback->channel, out); +} + +static UINT urbdrc_process_internal_io_control(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 MessageId, IUDEVMAN* udevman) +{ + wStream* out = NULL; + UINT32 IoControlCode = 0; + UINT32 InterfaceId = 0; + UINT32 InputBufferSize = 0; + UINT32 OutputBufferSize = 0; + UINT32 RequestId = 0; + UINT32 frames = 0; + + if (!pdev || !callback || !s || !udevman) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, IoControlCode); + Stream_Read_UINT32(s, InputBufferSize); + + if (!Stream_SafeSeek(s, InputBufferSize)) + return ERROR_INVALID_DATA; + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8ULL)) + return ERROR_INVALID_DATA; + Stream_Read_UINT32(s, OutputBufferSize); + Stream_Read_UINT32(s, RequestId); + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + // TODO: Implement control code. + /** Fixme: Currently this is a FALSE bustime... */ + frames = GetTickCount(); + out = urb_create_iocompletion(InterfaceId, MessageId, RequestId, 4); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, frames); /** OutputBuffer */ + return stream_write_and_free(callback->plugin, callback->channel, out); +} + +static UINT urbdrc_process_query_device_text(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 MessageId, IUDEVMAN* udevman) +{ + UINT32 out_size = 0; + UINT32 TextType = 0; + UINT32 LocaleId = 0; + UINT32 InterfaceId = 0; + UINT8 bufferSize = 0xFF; + UINT32 hr = 0; + wStream* out = NULL; + BYTE DeviceDescription[0x100] = { 0 }; + + if (!pdev || !callback || !s || !udevman) + return ERROR_INVALID_PARAMETER; + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, TextType); + Stream_Read_UINT32(s, LocaleId); + if (LocaleId > UINT16_MAX) + return ERROR_INVALID_DATA; + + hr = pdev->control_query_device_text(pdev, TextType, (UINT16)LocaleId, &bufferSize, + DeviceDescription); + InterfaceId = ((STREAM_ID_STUB << 30) | pdev->get_UsbDevice(pdev)); + out_size = 16 + bufferSize; + + if (bufferSize != 0) + out_size += 2; + + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /** interface */ + Stream_Write_UINT32(out, MessageId); /** message id */ + Stream_Write_UINT32(out, bufferSize / 2); /** cchDeviceDescription in WCHAR */ + Stream_Write(out, DeviceDescription, bufferSize); /* '\0' terminated unicode */ + Stream_Write_UINT32(out, hr); /** HResult */ + return stream_write_and_free(callback->plugin, callback->channel, out); +} + +static void func_select_all_interface_for_msconfig(IUDEVICE* pdev, + MSUSB_CONFIG_DESCRIPTOR* MsConfig) +{ + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = MsConfig->MsInterfaces; + BYTE InterfaceNumber = 0; + BYTE AlternateSetting = 0; + UINT32 NumInterfaces = MsConfig->NumInterfaces; + + for (UINT32 inum = 0; inum < NumInterfaces; inum++) + { + InterfaceNumber = MsInterfaces[inum]->InterfaceNumber; + AlternateSetting = MsInterfaces[inum]->AlternateSetting; + pdev->select_interface(pdev, InterfaceNumber, AlternateSetting); + } +} + +static UINT urb_select_configuration(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman, + int transferDir) +{ + MSUSB_CONFIG_DESCRIPTOR* MsConfig = NULL; + size_t out_size = 0; + UINT32 InterfaceId = 0; + UINT32 NumInterfaces = 0; + UINT32 usbd_status = 0; + BYTE ConfigurationDescriptorIsValid = 0; + wStream* out = NULL; + size_t MsOutSize = 0; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (transferDir == 0) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "urb_select_configuration: unsupported transfer out"); + return ERROR_INVALID_PARAMETER; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT8(s, ConfigurationDescriptorIsValid); + Stream_Seek(s, 3); /* Padding */ + Stream_Read_UINT32(s, NumInterfaces); + + /** if ConfigurationDescriptorIsValid is zero, then just do nothing.*/ + if (ConfigurationDescriptorIsValid) + { + /* parser data for struct config */ + MsConfig = msusb_msconfig_read(s, NumInterfaces); + + if (!MsConfig) + return ERROR_INVALID_DATA; + + /* select config */ + pdev->select_configuration(pdev, MsConfig->bConfigurationValue); + /* select all interface */ + func_select_all_interface_for_msconfig(pdev, MsConfig); + /* complete configuration setup */ + if (!pdev->complete_msconfig_setup(pdev, MsConfig)) + { + msusb_msconfig_free(MsConfig); + MsConfig = NULL; + } + } + + if (MsConfig) + MsOutSize = WINPR_ASSERTING_INT_CAST(size_t, MsConfig->MsOutSize); + + if (MsOutSize > 0) + { + if (MsOutSize > SIZE_MAX - 36) + return ERROR_INVALID_DATA; + + out_size = 36 + MsOutSize; + } + else + out_size = 44; + + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /** interface */ + Stream_Write_UINT32(out, MessageId); /** message id */ + Stream_Write_UINT32(out, URB_COMPLETION_NO_DATA); /** function id */ + Stream_Write_UINT32(out, RequestId); /** RequestId */ + + if (MsOutSize > 0) + { + /** CbTsUrbResult */ + Stream_Write_UINT32(out, 8U + (UINT32)MsOutSize); + /** TS_URB_RESULT_HEADER Size*/ + Stream_Write_UINT16(out, WINPR_ASSERTING_INT_CAST(uint16_t, 8U + (UINT32)MsOutSize)); + } + else + { + Stream_Write_UINT32(out, 16); + Stream_Write_UINT16(out, 16); + } + + /** Padding, MUST be ignored upon receipt */ + Stream_Write_UINT16(out, TS_URB_SELECT_CONFIGURATION); + Stream_Write_UINT32(out, usbd_status); /** UsbdStatus */ + + /** TS_URB_SELECT_CONFIGURATION_RESULT */ + if (MsOutSize > 0) + msusb_msconfig_write(MsConfig, out); + else + { + Stream_Write_UINT32(out, 0); /** ConfigurationHandle */ + Stream_Write_UINT32(out, NumInterfaces); /** NumInterfaces */ + } + + Stream_Write_UINT32(out, 0); /** HResult */ + Stream_Write_UINT32(out, 0); /** OutputBufferSize */ + + if (!noAck) + return stream_write_and_free(callback->plugin, callback->channel, out); + else + Stream_Free(out, TRUE); + + return ERROR_SUCCESS; +} + +static UINT urb_select_interface(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman, + int transferDir) +{ + MSUSB_CONFIG_DESCRIPTOR* MsConfig = NULL; + MSUSB_INTERFACE_DESCRIPTOR* MsInterface = NULL; + UINT32 out_size = 0; + UINT32 InterfaceId = 0; + UINT32 ConfigurationHandle = 0; + UINT32 OutputBufferSize = 0; + BYTE InterfaceNumber = 0; + wStream* out = NULL; + UINT32 interface_size = 0; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (transferDir == 0) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "urb_select_interface: not support transfer out"); + return ERROR_INVALID_PARAMETER; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT32(s, ConfigurationHandle); + MsInterface = msusb_msinterface_read(s); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4) || !MsInterface) + { + msusb_msinterface_free(MsInterface); + return ERROR_INVALID_DATA; + } + + Stream_Read_UINT32(s, OutputBufferSize); + pdev->select_interface(pdev, MsInterface->InterfaceNumber, MsInterface->AlternateSetting); + /* replace device's MsInterface */ + MsConfig = pdev->get_MsConfig(pdev); + InterfaceNumber = MsInterface->InterfaceNumber; + if (!msusb_msinterface_replace(MsConfig, InterfaceNumber, MsInterface)) + { + msusb_msconfig_free(MsConfig); + return ERROR_BAD_CONFIGURATION; + } + /* complete configuration setup */ + if (!pdev->complete_msconfig_setup(pdev, MsConfig)) + { + msusb_msconfig_free(MsConfig); + return ERROR_BAD_CONFIGURATION; + } + MsInterface = MsConfig->MsInterfaces[InterfaceNumber]; + interface_size = 16 + (MsInterface->NumberOfPipes * 20); + out_size = 36 + interface_size; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /** interface */ + Stream_Write_UINT32(out, MessageId); /** message id */ + Stream_Write_UINT32(out, URB_COMPLETION_NO_DATA); /** function id */ + Stream_Write_UINT32(out, RequestId); /** RequestId */ + Stream_Write_UINT32(out, 8 + interface_size); /** CbTsUrbResult */ + /** TS_URB_RESULT_HEADER */ + Stream_Write_UINT16(out, WINPR_ASSERTING_INT_CAST(uint16_t, 8 + interface_size)); /** Size */ + /** Padding, MUST be ignored upon receipt */ + Stream_Write_UINT16(out, TS_URB_SELECT_INTERFACE); + Stream_Write_UINT32(out, USBD_STATUS_SUCCESS); /** UsbdStatus */ + /** TS_URB_SELECT_INTERFACE_RESULT */ + msusb_msinterface_write(MsInterface, out); + Stream_Write_UINT32(out, 0); /** HResult */ + Stream_Write_UINT32(out, 0); /** OutputBufferSize */ + + if (!noAck) + return stream_write_and_free(callback->plugin, callback->channel, out); + else + Stream_Free(out, TRUE); + + return ERROR_SUCCESS; +} + +static UINT urb_control_transfer(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman, + int transferDir, int External) +{ + UINT32 out_size = 0; + UINT32 InterfaceId = 0; + UINT32 EndpointAddress = 0; + UINT32 PipeHandle = 0; + UINT32 TransferFlags = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + UINT32 Timeout = 0; + BYTE bmRequestType = 0; + BYTE Request = 0; + UINT16 Value = 0; + UINT16 Index = 0; + UINT16 length = 0; + BYTE* buffer = NULL; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT32(s, PipeHandle); + Stream_Read_UINT32(s, TransferFlags); /** TransferFlags */ + EndpointAddress = (PipeHandle & 0x000000ff); + Timeout = 2000; + + switch (External) + { + case URB_CONTROL_TRANSFER_EXTERNAL: + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, Timeout); /** TransferFlags */ + break; + + case URB_CONTROL_TRANSFER_NONEXTERNAL: + break; + default: + break; + } + + /** SetupPacket 8 bytes */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT8(s, bmRequestType); + Stream_Read_UINT8(s, Request); + Stream_Read_UINT16(s, Value); + Stream_Read_UINT16(s, Index); + Stream_Read_UINT16(s, length); + Stream_Read_UINT32(s, OutputBufferSize); + + if (length != OutputBufferSize) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "urb_control_transfer ERROR: buf != length"); + return ERROR_INVALID_DATA; + } + + out_size = 36 + OutputBufferSize; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + /** Get Buffer Data */ + buffer = Stream_Pointer(out); + + if (transferDir == USBD_TRANSFER_DIRECTION_OUT) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize)) + { + Stream_Free(out, TRUE); + return ERROR_INVALID_DATA; + } + Stream_Copy(s, out, OutputBufferSize); + } + + /** process TS_URB_CONTROL_TRANSFER */ + if (!pdev->control_transfer(pdev, RequestId, EndpointAddress, TransferFlags, bmRequestType, + Request, Value, Index, &usbd_status, &OutputBufferSize, buffer, + Timeout)) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "control_transfer failed"); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +static void urb_bulk_transfer_cb(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, wStream* out, + UINT32 InterfaceId, BOOL noAck, UINT32 MessageId, UINT32 RequestId, + UINT32 NumberOfPackets, UINT32 status, UINT32 StartFrame, + UINT32 ErrorCount, UINT32 OutputBufferSize) +{ + if (!pdev->isChannelClosed(pdev)) + urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, status, + OutputBufferSize); + else + Stream_Free(out, TRUE); +} + +static UINT urb_bulk_or_interrupt_transfer(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, int transferDir) +{ + UINT32 EndpointAddress = 0; + UINT32 PipeHandle = 0; + UINT32 TransferFlags = 0; + UINT32 OutputBufferSize = 0; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!pdev || !callback || !s || !udevman) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, PipeHandle); + Stream_Read_UINT32(s, TransferFlags); /** TransferFlags */ + Stream_Read_UINT32(s, OutputBufferSize); + EndpointAddress = (PipeHandle & 0x000000ff); + + if (transferDir == USBD_TRANSFER_DIRECTION_OUT) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize)) + { + return ERROR_INVALID_DATA; + } + } + + /** process TS_URB_BULK_OR_INTERRUPT_TRANSFER */ + const int rc = pdev->bulk_or_interrupt_transfer( + pdev, callback, MessageId, RequestId, EndpointAddress, TransferFlags, noAck, + OutputBufferSize, (transferDir == USBD_TRANSFER_DIRECTION_OUT) ? Stream_Pointer(s) : NULL, + urb_bulk_transfer_cb, 10000); + + return (uint32_t)rc; +} + +static void urb_isoch_transfer_cb(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, wStream* out, + UINT32 InterfaceId, BOOL noAck, UINT32 MessageId, + UINT32 RequestId, UINT32 NumberOfPackets, UINT32 status, + UINT32 StartFrame, UINT32 ErrorCount, UINT32 OutputBufferSize) +{ + if (!noAck) + { + UINT32 packetSize = (status == 0) ? NumberOfPackets * 12 : 0; + Stream_SetPosition(out, 0); + /* fill the send data */ + Stream_Write_UINT32(out, InterfaceId); /** interface */ + Stream_Write_UINT32(out, MessageId); /** message id */ + + if (OutputBufferSize == 0) + Stream_Write_UINT32(out, URB_COMPLETION_NO_DATA); /** function id */ + else + Stream_Write_UINT32(out, URB_COMPLETION); /** function id */ + + Stream_Write_UINT32(out, RequestId); /** RequestId */ + Stream_Write_UINT32(out, 20 + packetSize); /** CbTsUrbResult */ + /** TsUrbResult TS_URB_RESULT_HEADER */ + Stream_Write_UINT16(out, WINPR_ASSERTING_INT_CAST(uint16_t, 20 + packetSize)); /** Size */ + Stream_Write_UINT16(out, 0); /* Padding */ + Stream_Write_UINT32(out, status); /** UsbdStatus */ + Stream_Write_UINT32(out, StartFrame); /** StartFrame */ + + if (status == 0) + { + /** NumberOfPackets */ + Stream_Write_UINT32(out, NumberOfPackets); + Stream_Write_UINT32(out, ErrorCount); /** ErrorCount */ + Stream_Seek(out, packetSize); + } + else + { + Stream_Write_UINT32(out, 0); /** NumberOfPackets */ + Stream_Write_UINT32(out, ErrorCount); /** ErrorCount */ + } + + Stream_Write_UINT32(out, 0); /** HResult */ + Stream_Write_UINT32(out, OutputBufferSize); /** OutputBufferSize */ + Stream_Seek(out, OutputBufferSize); + + stream_write_and_free(callback->plugin, callback->channel, out); + } +} + +static UINT urb_isoch_transfer(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman, + int transferDir) +{ + int rc = 0; + UINT32 EndpointAddress = 0; + UINT32 PipeHandle = 0; + UINT32 TransferFlags = 0; + UINT32 StartFrame = 0; + UINT32 NumberOfPackets = 0; + UINT32 ErrorCount = 0; + UINT32 OutputBufferSize = 0; + BYTE* packetDescriptorData = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!pdev || !callback || !udevman) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 20)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, PipeHandle); + EndpointAddress = (PipeHandle & 0x000000ff); + Stream_Read_UINT32(s, TransferFlags); /** TransferFlags */ + Stream_Read_UINT32(s, StartFrame); /** StartFrame */ + Stream_Read_UINT32(s, NumberOfPackets); /** NumberOfPackets */ + Stream_Read_UINT32(s, ErrorCount); /** ErrorCount */ + + if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, NumberOfPackets, 12ull)) + return ERROR_INVALID_DATA; + + packetDescriptorData = Stream_Pointer(s); + Stream_Seek(s, 12ULL * NumberOfPackets); + + if (!Stream_CheckAndLogRequiredLength(TAG, s, sizeof(UINT32))) + return ERROR_INVALID_DATA; + Stream_Read_UINT32(s, OutputBufferSize); + + if (transferDir == USBD_TRANSFER_DIRECTION_OUT) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize)) + return ERROR_INVALID_DATA; + } + + rc = pdev->isoch_transfer( + pdev, callback, MessageId, RequestId, EndpointAddress, TransferFlags, StartFrame, + ErrorCount, noAck, packetDescriptorData, NumberOfPackets, OutputBufferSize, + (transferDir == USBD_TRANSFER_DIRECTION_OUT) ? Stream_Pointer(s) : NULL, + urb_isoch_transfer_cb, 2000); + + if (rc < 0) + return ERROR_INTERNAL_ERROR; + return (UINT)rc; +} + +static UINT urb_control_descriptor_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, BYTE func_recipient, int transferDir) +{ + size_t out_size = 0; + UINT32 InterfaceId = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + BYTE bmRequestType = 0; + BYTE desc_index = 0; + BYTE desc_type = 0; + UINT16 langId = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT8(s, desc_index); + Stream_Read_UINT8(s, desc_type); + Stream_Read_UINT16(s, langId); + Stream_Read_UINT32(s, OutputBufferSize); + if (OutputBufferSize > UINT32_MAX - 36) + return ERROR_INVALID_DATA; + if (transferDir == USBD_TRANSFER_DIRECTION_OUT) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize)) + return ERROR_INVALID_DATA; + } + + out_size = 36ULL + OutputBufferSize; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + bmRequestType = func_recipient; + + switch (transferDir) + { + case USBD_TRANSFER_DIRECTION_IN: + bmRequestType |= 0x80; + break; + + case USBD_TRANSFER_DIRECTION_OUT: + bmRequestType |= 0x00; + Stream_Copy(s, out, OutputBufferSize); + Stream_Rewind(out, OutputBufferSize); + break; + + default: + WLog_Print(urbdrc->log, WLOG_DEBUG, "get error transferDir"); + OutputBufferSize = 0; + usbd_status = USBD_STATUS_STALL_PID; + break; + } + + /** process get usb device descriptor */ + if (!pdev->control_transfer(pdev, RequestId, 0, 0, bmRequestType, + 0x06, /* REQUEST_GET_DESCRIPTOR */ + WINPR_ASSERTING_INT_CAST(UINT16, ((desc_type << 8) | desc_index)), + langId, &usbd_status, &OutputBufferSize, Stream_Pointer(out), 1000)) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "get_descriptor failed"); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +static UINT urb_control_get_status_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, BYTE func_recipient, int transferDir) +{ + size_t out_size = 0; + UINT32 InterfaceId = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + UINT16 Index = 0; + BYTE bmRequestType = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (transferDir == 0) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urb_control_get_status_request: transfer out not supported"); + return ERROR_INVALID_PARAMETER; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT16(s, Index); /** Index */ + Stream_Seek(s, 2); + Stream_Read_UINT32(s, OutputBufferSize); + if (OutputBufferSize > UINT32_MAX - 36) + return ERROR_INVALID_DATA; + out_size = 36ULL + OutputBufferSize; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + bmRequestType = func_recipient | 0x80; + + if (!pdev->control_transfer(pdev, RequestId, 0, 0, bmRequestType, 0x00, /* REQUEST_GET_STATUS */ + 0, Index, &usbd_status, &OutputBufferSize, Stream_Pointer(out), + 1000)) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "control_transfer failed"); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +static UINT urb_control_vendor_or_class_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, BYTE func_type, + BYTE func_recipient, int transferDir) +{ + UINT32 out_size = 0; + UINT32 InterfaceId = 0; + UINT32 TransferFlags = 0; + UINT32 usbd_status = 0; + UINT32 OutputBufferSize = 0; + BYTE ReqTypeReservedBits = 0; + BYTE Request = 0; + BYTE bmRequestType = 0; + UINT16 Value = 0; + UINT16 Index = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 16)) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT32(s, TransferFlags); /** TransferFlags */ + Stream_Read_UINT8(s, ReqTypeReservedBits); /** ReqTypeReservedBids */ + Stream_Read_UINT8(s, Request); /** Request */ + Stream_Read_UINT16(s, Value); /** value */ + Stream_Read_UINT16(s, Index); /** index */ + Stream_Seek_UINT16(s); /** Padding */ + Stream_Read_UINT32(s, OutputBufferSize); + if (OutputBufferSize > UINT32_MAX - 36) + return ERROR_INVALID_DATA; + + if (transferDir == USBD_TRANSFER_DIRECTION_OUT) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize)) + return ERROR_INVALID_DATA; + } + + out_size = 36ULL + OutputBufferSize; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + + /** Get Buffer */ + if (transferDir == USBD_TRANSFER_DIRECTION_OUT) + { + Stream_Copy(s, out, OutputBufferSize); + Stream_Rewind(out, OutputBufferSize); + } + + /** vendor or class command */ + bmRequestType = func_type | func_recipient; + + if (TransferFlags & USBD_TRANSFER_DIRECTION) + bmRequestType |= 0x80; + + WLog_Print(urbdrc->log, WLOG_DEBUG, + "RequestId 0x%" PRIx32 " TransferFlags: 0x%" PRIx32 " ReqTypeReservedBits: 0x%" PRIx8 + " " + "Request:0x%" PRIx8 " Value: 0x%" PRIx16 " Index: 0x%" PRIx16 + " OutputBufferSize: 0x%" PRIx32 " bmRequestType: 0x%" PRIx8, + RequestId, TransferFlags, ReqTypeReservedBits, Request, Value, Index, + OutputBufferSize, bmRequestType); + + if (!pdev->control_transfer(pdev, RequestId, 0, 0, bmRequestType, Request, Value, Index, + &usbd_status, &OutputBufferSize, Stream_Pointer(out), 2000)) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "control_transfer failed"); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +static UINT urb_os_feature_descriptor_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, int transferDir) +{ + size_t out_size = 0; + UINT32 InterfaceId = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + BYTE Recipient = 0; + BYTE InterfaceNumber = 0; + BYTE Ms_PageIndex = 0; + UINT16 Ms_featureDescIndex = 0; + wStream* out = NULL; + int ret = 0; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + /* 2.2.9.15 TS_URB_OS_FEATURE_DESCRIPTOR_REQUEST */ + Stream_Read_UINT8(s, Recipient); /** Recipient */ + Recipient = (Recipient & 0x1f); /* Mask out Padding1 */ + Stream_Read_UINT8(s, InterfaceNumber); /** InterfaceNumber */ + Stream_Read_UINT8(s, Ms_PageIndex); /** Ms_PageIndex */ + Stream_Read_UINT16(s, Ms_featureDescIndex); /** Ms_featureDescIndex */ + Stream_Seek(s, 3); /* Padding 2 */ + Stream_Read_UINT32(s, OutputBufferSize); + if (OutputBufferSize > UINT32_MAX - 36) + return ERROR_INVALID_DATA; + + switch (transferDir) + { + case USBD_TRANSFER_DIRECTION_OUT: + if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize)) + return ERROR_INVALID_DATA; + + break; + + default: + break; + } + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + out_size = 36ULL + OutputBufferSize; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + + switch (transferDir) + { + case USBD_TRANSFER_DIRECTION_OUT: + Stream_Copy(s, out, OutputBufferSize); + Stream_Rewind(out, OutputBufferSize); + break; + + case USBD_TRANSFER_DIRECTION_IN: + break; + default: + break; + } + + WLog_Print(urbdrc->log, WLOG_DEBUG, + "Ms descriptor arg: Recipient:0x%" PRIx8 ", " + "InterfaceNumber:0x%" PRIx8 ", Ms_PageIndex:0x%" PRIx8 ", " + "Ms_featureDescIndex:0x%" PRIx16 ", OutputBufferSize:0x%" PRIx32 "", + Recipient, InterfaceNumber, Ms_PageIndex, Ms_featureDescIndex, OutputBufferSize); + /** get ms string */ + ret = pdev->os_feature_descriptor_request(pdev, RequestId, Recipient, InterfaceNumber, + Ms_PageIndex, Ms_featureDescIndex, &usbd_status, + &OutputBufferSize, Stream_Pointer(out), 1000); + + if (ret < 0) + WLog_Print(urbdrc->log, WLOG_DEBUG, "os_feature_descriptor_request: error num %d", ret); + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +static UINT urb_pipe_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman, + int transferDir, int action) +{ + UINT32 out_size = 0; + UINT32 InterfaceId = 0; + UINT32 PipeHandle = 0; + UINT32 EndpointAddress = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + wStream* out = NULL; + UINT32 ret = USBD_STATUS_REQUEST_FAILED; + int rc = 0; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + if (transferDir == 0) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, "urb_pipe_request: not support transfer out"); + return ERROR_INVALID_PARAMETER; + } + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT32(s, PipeHandle); /** PipeHandle */ + Stream_Read_UINT32(s, OutputBufferSize); + EndpointAddress = (PipeHandle & 0x000000ff); + + switch (action) + { + case PIPE_CANCEL: + rc = pdev->control_pipe_request(pdev, RequestId, EndpointAddress, &usbd_status, + PIPE_CANCEL); + + if (rc < 0) + WLog_Print(urbdrc->log, WLOG_DEBUG, "PIPE SET HALT: error %d", ret); + else + ret = USBD_STATUS_SUCCESS; + + break; + + case PIPE_RESET: + WLog_Print(urbdrc->log, WLOG_DEBUG, "urb_pipe_request: PIPE_RESET ep 0x%" PRIx32 "", + EndpointAddress); + rc = pdev->control_pipe_request(pdev, RequestId, EndpointAddress, &usbd_status, + PIPE_RESET); + + if (rc < 0) + WLog_Print(urbdrc->log, WLOG_DEBUG, "PIPE RESET: error %d", ret); + else + ret = USBD_STATUS_SUCCESS; + + break; + + default: + WLog_Print(urbdrc->log, WLOG_DEBUG, "urb_pipe_request action: %d not supported", + action); + ret = USBD_STATUS_INVALID_URB_FUNCTION; + break; + } + + /** send data */ + out_size = 36; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, ret, + 0); +} + +static UINT urb_get_current_frame_number(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, int transferDir) +{ + UINT32 out_size = 0; + UINT32 InterfaceId = 0; + UINT32 OutputBufferSize = 0; + UINT32 dummy_frames = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + if (transferDir == 0) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urb_get_current_frame_number: not support transfer out"); + return ERROR_INVALID_PARAMETER; + } + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT32(s, OutputBufferSize); + /** Fixme: Need to fill actual frame number!!*/ + dummy_frames = GetTickCount(); + out_size = 40; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /** interface */ + Stream_Write_UINT32(out, MessageId); /** message id */ + Stream_Write_UINT32(out, URB_COMPLETION_NO_DATA); + Stream_Write_UINT32(out, RequestId); /** RequestId */ + Stream_Write_UINT32(out, 12); /** CbTsUrbResult */ + /** TsUrbResult TS_URB_RESULT_HEADER */ + Stream_Write_UINT16(out, 12); /** Size */ + /** Padding, MUST be ignored upon receipt */ + Stream_Write_UINT16(out, TS_URB_GET_CURRENT_FRAME_NUMBER); + Stream_Write_UINT32(out, USBD_STATUS_SUCCESS); /** UsbdStatus */ + Stream_Write_UINT32(out, dummy_frames); /** FrameNumber */ + Stream_Write_UINT32(out, 0); /** HResult */ + Stream_Write_UINT32(out, 0); /** OutputBufferSize */ + + if (!noAck) + return stream_write_and_free(callback->plugin, callback->channel, out); + else + Stream_Free(out, TRUE); + + return ERROR_SUCCESS; +} + +/* Unused function for current server */ +static UINT urb_control_get_configuration_request(IUDEVICE* pdev, + GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, int transferDir) +{ + size_t out_size = 0; + UINT32 InterfaceId = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (transferDir == 0) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urb_control_get_configuration_request:" + " not support transfer out"); + return ERROR_INVALID_PARAMETER; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, OutputBufferSize); + if (OutputBufferSize > UINT32_MAX - 36) + return ERROR_INVALID_DATA; + out_size = 36ULL + OutputBufferSize; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + + if (!pdev->control_transfer(pdev, RequestId, 0, 0, 0x80 | 0x00, + 0x08, /* REQUEST_GET_CONFIGURATION */ + 0, 0, &usbd_status, &OutputBufferSize, Stream_Pointer(out), 1000)) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, "control_transfer failed"); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +/* Unused function for current server */ +static UINT urb_control_get_interface_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, int transferDir) +{ + size_t out_size = 0; + UINT32 InterfaceId = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + UINT16 InterfaceNr = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + if (transferDir == 0) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urb_control_get_interface_request: not support transfer out"); + return ERROR_INVALID_PARAMETER; + } + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT16(s, InterfaceNr); + Stream_Seek(s, 2); + Stream_Read_UINT32(s, OutputBufferSize); + if (OutputBufferSize > UINT32_MAX - 36) + return ERROR_INVALID_DATA; + out_size = 36ULL + OutputBufferSize; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + + if (!pdev->control_transfer( + pdev, RequestId, 0, 0, 0x80 | 0x01, 0x0A, /* REQUEST_GET_INTERFACE */ + 0, InterfaceNr, &usbd_status, &OutputBufferSize, Stream_Pointer(out), 1000)) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, "control_transfer failed"); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +static UINT urb_control_feature_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 RequestField, UINT32 MessageId, + IUDEVMAN* udevman, BYTE func_recipient, BYTE command, + int transferDir) +{ + UINT32 InterfaceId = 0; + UINT32 OutputBufferSize = 0; + UINT32 usbd_status = 0; + UINT16 FeatureSelector = 0; + UINT16 Index = 0; + BYTE bmRequestType = 0; + BYTE bmRequest = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + const BOOL noAck = (RequestField & 0x80000000U) != 0; + const UINT32 RequestId = RequestField & 0x7FFFFFFF; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 8)) + return ERROR_INVALID_DATA; + + InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev)); + Stream_Read_UINT16(s, FeatureSelector); + Stream_Read_UINT16(s, Index); + Stream_Read_UINT32(s, OutputBufferSize); + if (OutputBufferSize > UINT32_MAX - 36) + return ERROR_INVALID_DATA; + switch (transferDir) + { + case USBD_TRANSFER_DIRECTION_OUT: + if (!Stream_CheckAndLogRequiredLength(TAG, s, OutputBufferSize)) + return ERROR_INVALID_DATA; + + break; + + default: + break; + } + + out = Stream_New(NULL, 36ULL + OutputBufferSize); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Seek(out, 36); + bmRequestType = func_recipient; + + switch (transferDir) + { + case USBD_TRANSFER_DIRECTION_OUT: + WLog_Print(urbdrc->log, WLOG_ERROR, + "Function urb_control_feature_request: OUT Unchecked"); + Stream_Copy(s, out, OutputBufferSize); + Stream_Rewind(out, OutputBufferSize); + bmRequestType |= 0x00; + break; + + case USBD_TRANSFER_DIRECTION_IN: + bmRequestType |= 0x80; + break; + default: + break; + } + + switch (command) + { + case URB_SET_FEATURE: + bmRequest = 0x03; /* REQUEST_SET_FEATURE */ + break; + + case URB_CLEAR_FEATURE: + bmRequest = 0x01; /* REQUEST_CLEAR_FEATURE */ + break; + + default: + WLog_Print(urbdrc->log, WLOG_ERROR, + "urb_control_feature_request: Error Command 0x%02" PRIx8 "", command); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + if (!pdev->control_transfer(pdev, RequestId, 0, 0, bmRequestType, bmRequest, FeatureSelector, + Index, &usbd_status, &OutputBufferSize, Stream_Pointer(out), 1000)) + { + WLog_Print(urbdrc->log, WLOG_DEBUG, "feature control transfer failed"); + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, + usbd_status, OutputBufferSize); +} + +static UINT urbdrc_process_transfer_request(IUDEVICE* pdev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* s, UINT32 MessageId, IUDEVMAN* udevman, + int transferDir) +{ + UINT32 CbTsUrb = 0; + UINT16 Size = 0; + UINT16 URB_Function = 0; + UINT32 RequestId = 0; + UINT error = ERROR_INTERNAL_ERROR; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!callback || !s || !udevman || !pdev) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, CbTsUrb); /** CbTsUrb */ + Stream_Read_UINT16(s, Size); /** size */ + Stream_Read_UINT16(s, URB_Function); + Stream_Read_UINT32(s, RequestId); + WLog_Print(urbdrc->log, WLOG_DEBUG, "URB %s[%" PRIu16 "]", urb_function_string(URB_Function), + URB_Function); + + switch (URB_Function) + { + case TS_URB_SELECT_CONFIGURATION: /** 0x0000 */ + error = urb_select_configuration(pdev, callback, s, RequestId, MessageId, udevman, + transferDir); + break; + + case TS_URB_SELECT_INTERFACE: /** 0x0001 */ + error = + urb_select_interface(pdev, callback, s, RequestId, MessageId, udevman, transferDir); + break; + + case TS_URB_PIPE_REQUEST: /** 0x0002 */ + error = urb_pipe_request(pdev, callback, s, RequestId, MessageId, udevman, transferDir, + PIPE_CANCEL); + break; + + case TS_URB_TAKE_FRAME_LENGTH_CONTROL: /** 0x0003 */ + /** This URB function is obsolete in Windows 2000 + * and later operating systems + * and is not supported by Microsoft. */ + break; + + case TS_URB_RELEASE_FRAME_LENGTH_CONTROL: /** 0x0004 */ + /** This URB function is obsolete in Windows 2000 + * and later operating systems + * and is not supported by Microsoft. */ + break; + + case TS_URB_GET_FRAME_LENGTH: /** 0x0005 */ + /** This URB function is obsolete in Windows 2000 + * and later operating systems + * and is not supported by Microsoft. */ + break; + + case TS_URB_SET_FRAME_LENGTH: /** 0x0006 */ + /** This URB function is obsolete in Windows 2000 + * and later operating systems + * and is not supported by Microsoft. */ + break; + + case TS_URB_GET_CURRENT_FRAME_NUMBER: /** 0x0007 */ + error = urb_get_current_frame_number(pdev, callback, s, RequestId, MessageId, udevman, + transferDir); + break; + + case TS_URB_CONTROL_TRANSFER: /** 0x0008 */ + error = urb_control_transfer(pdev, callback, s, RequestId, MessageId, udevman, + transferDir, URB_CONTROL_TRANSFER_NONEXTERNAL); + break; + + case TS_URB_BULK_OR_INTERRUPT_TRANSFER: /** 0x0009 */ + error = urb_bulk_or_interrupt_transfer(pdev, callback, s, RequestId, MessageId, udevman, + transferDir); + break; + + case TS_URB_ISOCH_TRANSFER: /** 0x000A */ + error = + urb_isoch_transfer(pdev, callback, s, RequestId, MessageId, udevman, transferDir); + break; + + case TS_URB_GET_DESCRIPTOR_FROM_DEVICE: /** 0x000B */ + error = urb_control_descriptor_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x00, transferDir); + break; + + case TS_URB_SET_DESCRIPTOR_TO_DEVICE: /** 0x000C */ + error = urb_control_descriptor_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x00, transferDir); + break; + + case TS_URB_SET_FEATURE_TO_DEVICE: /** 0x000D */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x00, URB_SET_FEATURE, transferDir); + break; + + case TS_URB_SET_FEATURE_TO_INTERFACE: /** 0x000E */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x01, URB_SET_FEATURE, transferDir); + break; + + case TS_URB_SET_FEATURE_TO_ENDPOINT: /** 0x000F */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x02, URB_SET_FEATURE, transferDir); + break; + + case TS_URB_CLEAR_FEATURE_TO_DEVICE: /** 0x0010 */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x00, URB_CLEAR_FEATURE, transferDir); + break; + + case TS_URB_CLEAR_FEATURE_TO_INTERFACE: /** 0x0011 */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x01, URB_CLEAR_FEATURE, transferDir); + break; + + case TS_URB_CLEAR_FEATURE_TO_ENDPOINT: /** 0x0012 */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x02, URB_CLEAR_FEATURE, transferDir); + break; + + case TS_URB_GET_STATUS_FROM_DEVICE: /** 0x0013 */ + error = urb_control_get_status_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x00, transferDir); + break; + + case TS_URB_GET_STATUS_FROM_INTERFACE: /** 0x0014 */ + error = urb_control_get_status_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x01, transferDir); + break; + + case TS_URB_GET_STATUS_FROM_ENDPOINT: /** 0x0015 */ + error = urb_control_get_status_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x02, transferDir); + break; + + case TS_URB_RESERVED_0X0016: /** 0x0016 */ + break; + + case TS_URB_VENDOR_DEVICE: /** 0x0017 */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x02 << 5), /* vendor type */ + 0x00, transferDir); + break; + + case TS_URB_VENDOR_INTERFACE: /** 0x0018 */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x02 << 5), /* vendor type */ + 0x01, transferDir); + break; + + case TS_URB_VENDOR_ENDPOINT: /** 0x0019 */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x02 << 5), /* vendor type */ + 0x02, transferDir); + break; + + case TS_URB_CLASS_DEVICE: /** 0x001A */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x01 << 5), /* class type */ + 0x00, transferDir); + break; + + case TS_URB_CLASS_INTERFACE: /** 0x001B */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x01 << 5), /* class type */ + 0x01, transferDir); + break; + + case TS_URB_CLASS_ENDPOINT: /** 0x001C */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x01 << 5), /* class type */ + 0x02, transferDir); + break; + + case TS_URB_RESERVE_0X001D: /** 0x001D */ + break; + + case TS_URB_SYNC_RESET_PIPE_AND_CLEAR_STALL: /** 0x001E */ + error = urb_pipe_request(pdev, callback, s, RequestId, MessageId, udevman, transferDir, + PIPE_RESET); + break; + + case TS_URB_CLASS_OTHER: /** 0x001F */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x01 << 5), /* class type */ + 0x03, transferDir); + break; + + case TS_URB_VENDOR_OTHER: /** 0x0020 */ + error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId, + udevman, (0x02 << 5), /* vendor type */ + 0x03, transferDir); + break; + + case TS_URB_GET_STATUS_FROM_OTHER: /** 0x0021 */ + error = urb_control_get_status_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x03, transferDir); + break; + + case TS_URB_CLEAR_FEATURE_TO_OTHER: /** 0x0022 */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x03, URB_CLEAR_FEATURE, transferDir); + break; + + case TS_URB_SET_FEATURE_TO_OTHER: /** 0x0023 */ + error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x03, URB_SET_FEATURE, transferDir); + break; + + case TS_URB_GET_DESCRIPTOR_FROM_ENDPOINT: /** 0x0024 */ + error = urb_control_descriptor_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x02, transferDir); + break; + + case TS_URB_SET_DESCRIPTOR_TO_ENDPOINT: /** 0x0025 */ + error = urb_control_descriptor_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x02, transferDir); + break; + + case TS_URB_CONTROL_GET_CONFIGURATION_REQUEST: /** 0x0026 */ + error = urb_control_get_configuration_request(pdev, callback, s, RequestId, MessageId, + udevman, transferDir); + break; + + case TS_URB_CONTROL_GET_INTERFACE_REQUEST: /** 0x0027 */ + error = urb_control_get_interface_request(pdev, callback, s, RequestId, MessageId, + udevman, transferDir); + break; + + case TS_URB_GET_DESCRIPTOR_FROM_INTERFACE: /** 0x0028 */ + error = urb_control_descriptor_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x01, transferDir); + break; + + case TS_URB_SET_DESCRIPTOR_TO_INTERFACE: /** 0x0029 */ + error = urb_control_descriptor_request(pdev, callback, s, RequestId, MessageId, udevman, + 0x01, transferDir); + break; + + case TS_URB_GET_OS_FEATURE_DESCRIPTOR_REQUEST: /** 0x002A */ + error = urb_os_feature_descriptor_request(pdev, callback, s, RequestId, MessageId, + udevman, transferDir); + break; + + case TS_URB_RESERVE_0X002B: /** 0x002B */ + case TS_URB_RESERVE_0X002C: /** 0x002C */ + case TS_URB_RESERVE_0X002D: /** 0x002D */ + case TS_URB_RESERVE_0X002E: /** 0x002E */ + case TS_URB_RESERVE_0X002F: /** 0x002F */ + break; + + /** USB 2.0 calls start at 0x0030 */ + case TS_URB_SYNC_RESET_PIPE: /** 0x0030 */ + error = urb_pipe_request(pdev, callback, s, RequestId, MessageId, udevman, transferDir, + PIPE_RESET); + break; + + case TS_URB_SYNC_CLEAR_STALL: /** 0x0031 */ + urb_pipe_request(pdev, callback, s, RequestId, MessageId, udevman, transferDir, + PIPE_RESET); + break; + + case TS_URB_CONTROL_TRANSFER_EX: /** 0x0032 */ + error = urb_control_transfer(pdev, callback, s, RequestId, MessageId, udevman, + transferDir, URB_CONTROL_TRANSFER_EXTERNAL); + break; + + default: + WLog_Print(urbdrc->log, WLOG_DEBUG, "URB_Func: %" PRIx16 " is not found!", + URB_Function); + break; + } + + if (error) + { + WLog_Print(urbdrc->log, WLOG_WARN, + "USB transfer request URB Function '%s' [0x%08x] failed with %08" PRIx32, + urb_function_string(URB_Function), URB_Function, error); + } + + return error; +} + +UINT urbdrc_process_udev_data_transfer(GENERIC_CHANNEL_CALLBACK* callback, URBDRC_PLUGIN* urbdrc, + IUDEVMAN* udevman, wStream* data) +{ + UINT32 InterfaceId = 0; + UINT32 MessageId = 0; + UINT32 FunctionId = 0; + IUDEVICE* pdev = NULL; + UINT error = ERROR_INTERNAL_ERROR; + + if (!urbdrc || !data || !callback || !udevman) + goto fail; + + if (!Stream_CheckAndLogRequiredLength(TAG, data, 8)) + goto fail; + + Stream_Rewind_UINT32(data); + + Stream_Read_UINT32(data, InterfaceId); + Stream_Read_UINT32(data, MessageId); + Stream_Read_UINT32(data, FunctionId); + + pdev = udevman->get_udevice_by_UsbDevice(udevman, InterfaceId); + + /* Device does not exist, ignore this request. */ + if (pdev == NULL) + { + error = ERROR_SUCCESS; + goto fail; + } + + /* Device has been removed, ignore this request. */ + if (pdev->isChannelClosed(pdev)) + { + error = ERROR_SUCCESS; + goto fail; + } + + /* USB kernel driver detach!! */ + pdev->detach_kernel_driver(pdev); + + switch (FunctionId) + { + case CANCEL_REQUEST: + error = urbdrc_process_cancel_request(pdev, data, udevman); + break; + + case REGISTER_REQUEST_CALLBACK: + error = urbdrc_process_register_request_callback(pdev, callback, data, udevman); + break; + + case IO_CONTROL: + error = urbdrc_process_io_control(pdev, callback, data, MessageId, udevman); + break; + + case INTERNAL_IO_CONTROL: + error = urbdrc_process_internal_io_control(pdev, callback, data, MessageId, udevman); + break; + + case QUERY_DEVICE_TEXT: + error = urbdrc_process_query_device_text(pdev, callback, data, MessageId, udevman); + break; + + case TRANSFER_IN_REQUEST: + error = urbdrc_process_transfer_request(pdev, callback, data, MessageId, udevman, + USBD_TRANSFER_DIRECTION_IN); + break; + + case TRANSFER_OUT_REQUEST: + error = urbdrc_process_transfer_request(pdev, callback, data, MessageId, udevman, + USBD_TRANSFER_DIRECTION_OUT); + break; + + case RETRACT_DEVICE: + error = urbdrc_process_retract_device_request(pdev, data, udevman); + break; + + default: + WLog_Print(urbdrc->log, WLOG_WARN, + "urbdrc_process_udev_data_transfer:" + " unknown FunctionId 0x%" PRIX32 "", + FunctionId); + break; + } + +fail: + if (error) + { + WLog_WARN(TAG, "USB request failed with %08" PRIx32, error); + } + + return error; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/data_transfer.h b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/data_transfer.h new file mode 100644 index 0000000000000000000000000000000000000000..1d7126d2e249179b1bbe2b8d286f0e6b9db70333 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/data_transfer.h @@ -0,0 +1,36 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_URBDRC_CLIENT_DATA_TRANSFER_H +#define FREERDP_CHANNEL_URBDRC_CLIENT_DATA_TRANSFER_H + +#include + +#include "urbdrc_main.h" + +#define DEVICE_CTX(dev) ((dev)->ctx) +#define HANDLE_CTX(handle) (DEVICE_CTX((handle)->dev)) +#define TRANSFER_CTX(transfer) (HANDLE_CTX((transfer)->dev_handle)) +#define ITRANSFER_CTX(transfer) (TRANSFER_CTX(__USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer))) + +UINT urbdrc_process_udev_data_transfer(GENERIC_CHANNEL_CALLBACK* callback, URBDRC_PLUGIN* urbdrc, + IUDEVMAN* udevman, wStream* data); + +#endif /* FREERDP_CHANNEL_URBDRC_CLIENT_DATA_TRANSFER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5de9381db88eba22bb81f5add7edada6de1509e0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/CMakeLists.txt @@ -0,0 +1,27 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Atrust corp. +# Copyright 2012 Alfred Liu +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client_subsystem("urbdrc" "libusb" "") + +set(${MODULE_PREFIX}_SRCS libusb_udevman.c libusb_udevice.c libusb_udevice.h) + +set(${MODULE_PREFIX}_LIBS ${CMAKE_THREAD_LIBS_INIT} ${LIBUSB_1_LIBRARIES} winpr freerdp) + +include_directories(..) + +add_channel_client_subsystem_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} "" TRUE "") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevice.c b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevice.c new file mode 100644 index 0000000000000000000000000000000000000000..b153a22b76782f37f3708e5ab556180a755b2048 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevice.c @@ -0,0 +1,1864 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "libusb_udevice.h" +#include "../common/urbdrc_types.h" + +#define BASIC_STATE_FUNC_DEFINED(_arg, _type) \ + static _type udev_get_##_arg(IUDEVICE* idev) \ + { \ + UDEVICE* pdev = (UDEVICE*)idev; \ + return pdev->_arg; \ + } \ + static void udev_set_##_arg(IUDEVICE* idev, _type _t) \ + { \ + UDEVICE* pdev = (UDEVICE*)idev; \ + pdev->_arg = _t; \ + } + +#define BASIC_POINT_FUNC_DEFINED(_arg, _type) \ + static _type udev_get_p_##_arg(IUDEVICE* idev) \ + { \ + UDEVICE* pdev = (UDEVICE*)idev; \ + return pdev->_arg; \ + } \ + static void udev_set_p_##_arg(IUDEVICE* idev, _type _t) \ + { \ + UDEVICE* pdev = (UDEVICE*)idev; \ + pdev->_arg = _t; \ + } + +#define BASIC_STATE_FUNC_REGISTER(_arg, _dev) \ + _dev->iface.get_##_arg = udev_get_##_arg; \ + (_dev)->iface.set_##_arg = udev_set_##_arg + +#if LIBUSB_API_VERSION >= 0x01000103 +#define HAVE_STREAM_ID_API 1 +#endif + +typedef struct +{ + wStream* data; + BOOL noack; + UINT32 MessageId; + UINT32 StartFrame; + UINT32 ErrorCount; + IUDEVICE* idev; + UINT32 OutputBufferSize; + GENERIC_CHANNEL_CALLBACK* callback; + t_isoch_transfer_cb cb; + wArrayList* queue; +#if !defined(HAVE_STREAM_ID_API) + UINT32 streamID; +#endif +} ASYNC_TRANSFER_USER_DATA; + +static void request_free(void* value); + +static struct libusb_transfer* list_contains(wArrayList* list, UINT32 streamID) +{ + size_t count = 0; + if (!list) + return NULL; + count = ArrayList_Count(list); + for (size_t x = 0; x < count; x++) + { + struct libusb_transfer* transfer = ArrayList_GetItem(list, x); + +#if defined(HAVE_STREAM_ID_API) + const UINT32 currentID = libusb_transfer_get_stream_id(transfer); +#else + const ASYNC_TRANSFER_USER_DATA* user_data = (ASYNC_TRANSFER_USER_DATA*)transfer->user_data; + const UINT32 currentID = user_data->streamID; +#endif + if (currentID == streamID) + return transfer; + } + return NULL; +} + +static UINT32 stream_id_from_buffer(struct libusb_transfer* transfer) +{ + if (!transfer) + return 0; +#if defined(HAVE_STREAM_ID_API) + return libusb_transfer_get_stream_id(transfer); +#else + ASYNC_TRANSFER_USER_DATA* user_data = (ASYNC_TRANSFER_USER_DATA*)transfer->user_data; + if (!user_data) + return 0; + return user_data->streamID; +#endif +} + +static void set_stream_id_for_buffer(struct libusb_transfer* transfer, UINT32 streamID) +{ +#if defined(HAVE_STREAM_ID_API) + libusb_transfer_set_stream_id(transfer, streamID); +#else + ASYNC_TRANSFER_USER_DATA* user_data = (ASYNC_TRANSFER_USER_DATA*)transfer->user_data; + if (!user_data) + return; + user_data->streamID = streamID; +#endif +} + +WINPR_ATTR_FORMAT_ARG(3, 8) +static BOOL log_libusb_result_(wLog* log, DWORD lvl, WINPR_FORMAT_ARG const char* fmt, + const char* fkt, const char* file, size_t line, int error, ...) +{ + WINPR_UNUSED(file); + + if (error < 0) + { + char buffer[8192] = { 0 }; + va_list ap = { 0 }; + va_start(ap, error); + (void)vsnprintf(buffer, sizeof(buffer), fmt, ap); + va_end(ap); + + WLog_Print(log, lvl, "[%s:%" PRIuz "]: %s: error %s[%d]", fkt, line, buffer, + libusb_error_name(error), error); + return TRUE; + } + return FALSE; +} + +#define log_libusb_result(log, lvl, fmt, error, ...) \ + log_libusb_result_((log), (lvl), (fmt), __func__, __FILE__, __LINE__, error, ##__VA_ARGS__) + +const char* usb_interface_class_to_string(uint8_t class) +{ + switch (class) + { + case LIBUSB_CLASS_PER_INTERFACE: + return "LIBUSB_CLASS_PER_INTERFACE"; + case LIBUSB_CLASS_AUDIO: + return "LIBUSB_CLASS_AUDIO"; + case LIBUSB_CLASS_COMM: + return "LIBUSB_CLASS_COMM"; + case LIBUSB_CLASS_HID: + return "LIBUSB_CLASS_HID"; + case LIBUSB_CLASS_PHYSICAL: + return "LIBUSB_CLASS_PHYSICAL"; + case LIBUSB_CLASS_PRINTER: + return "LIBUSB_CLASS_PRINTER"; + case LIBUSB_CLASS_IMAGE: + return "LIBUSB_CLASS_IMAGE"; + case LIBUSB_CLASS_MASS_STORAGE: + return "LIBUSB_CLASS_MASS_STORAGE"; + case LIBUSB_CLASS_HUB: + return "LIBUSB_CLASS_HUB"; + case LIBUSB_CLASS_DATA: + return "LIBUSB_CLASS_DATA"; + case LIBUSB_CLASS_SMART_CARD: + return "LIBUSB_CLASS_SMART_CARD"; + case LIBUSB_CLASS_CONTENT_SECURITY: + return "LIBUSB_CLASS_CONTENT_SECURITY"; + case LIBUSB_CLASS_VIDEO: + return "LIBUSB_CLASS_VIDEO"; + case LIBUSB_CLASS_PERSONAL_HEALTHCARE: + return "LIBUSB_CLASS_PERSONAL_HEALTHCARE"; + case LIBUSB_CLASS_DIAGNOSTIC_DEVICE: + return "LIBUSB_CLASS_DIAGNOSTIC_DEVICE"; + case LIBUSB_CLASS_WIRELESS: + return "LIBUSB_CLASS_WIRELESS"; + case LIBUSB_CLASS_APPLICATION: + return "LIBUSB_CLASS_APPLICATION"; + case LIBUSB_CLASS_VENDOR_SPEC: + return "LIBUSB_CLASS_VENDOR_SPEC"; + default: + return "UNKNOWN_DEVICE_CLASS"; + } +} + +static ASYNC_TRANSFER_USER_DATA* async_transfer_user_data_new(IUDEVICE* idev, UINT32 MessageId, + size_t offset, size_t BufferSize, + const BYTE* data, size_t packetSize, + BOOL NoAck, t_isoch_transfer_cb cb, + GENERIC_CHANNEL_CALLBACK* callback) +{ + ASYNC_TRANSFER_USER_DATA* user_data = NULL; + UDEVICE* pdev = (UDEVICE*)idev; + + if (BufferSize > UINT32_MAX) + return NULL; + + user_data = calloc(1, sizeof(ASYNC_TRANSFER_USER_DATA)); + if (!user_data) + return NULL; + + user_data->data = Stream_New(NULL, offset + BufferSize + packetSize); + + if (!user_data->data) + { + free(user_data); + return NULL; + } + + Stream_Seek(user_data->data, offset); /* Skip header offset */ + if (data) + memcpy(Stream_Pointer(user_data->data), data, BufferSize); + else + user_data->OutputBufferSize = (UINT32)BufferSize; + + user_data->noack = NoAck; + user_data->cb = cb; + user_data->callback = callback; + user_data->idev = idev; + user_data->MessageId = MessageId; + + user_data->queue = pdev->request_queue; + + return user_data; +} + +static void async_transfer_user_data_free(ASYNC_TRANSFER_USER_DATA* user_data) +{ + if (user_data) + { + Stream_Free(user_data->data, TRUE); + free(user_data); + } +} + +static void LIBUSB_CALL func_iso_callback(struct libusb_transfer* transfer) +{ + ASYNC_TRANSFER_USER_DATA* user_data = (ASYNC_TRANSFER_USER_DATA*)transfer->user_data; + const UINT32 streamID = stream_id_from_buffer(transfer); + wArrayList* list = user_data->queue; + + ArrayList_Lock(list); + switch (transfer->status) + { + case LIBUSB_TRANSFER_COMPLETED: + { + UINT32 index = 0; + BYTE* dataStart = Stream_Pointer(user_data->data); + Stream_SetPosition(user_data->data, + 40); /* TS_URB_ISOCH_TRANSFER_RESULT IsoPacket offset */ + + for (uint32_t i = 0; i < WINPR_ASSERTING_INT_CAST(uint32_t, transfer->num_iso_packets); + i++) + { + const UINT32 act_len = transfer->iso_packet_desc[i].actual_length; + Stream_Write_UINT32(user_data->data, index); + Stream_Write_UINT32(user_data->data, act_len); + Stream_Write_UINT32(user_data->data, transfer->iso_packet_desc[i].status); + + if (transfer->iso_packet_desc[i].status != USBD_STATUS_SUCCESS) + user_data->ErrorCount++; + else + { + const unsigned char* packetBuffer = + libusb_get_iso_packet_buffer_simple(transfer, i); + BYTE* data = dataStart + index; + + if (data != packetBuffer) + memmove(data, packetBuffer, act_len); + + index += act_len; + } + } + } + /* fallthrough */ + WINPR_FALLTHROUGH + case LIBUSB_TRANSFER_CANCELLED: + /* fallthrough */ + WINPR_FALLTHROUGH + case LIBUSB_TRANSFER_TIMED_OUT: + /* fallthrough */ + WINPR_FALLTHROUGH + case LIBUSB_TRANSFER_ERROR: + { + const UINT32 InterfaceId = + ((STREAM_ID_PROXY << 30) | user_data->idev->get_ReqCompletion(user_data->idev)); + + if (list_contains(list, streamID)) + { + if (!user_data->noack) + { + const UINT32 RequestID = streamID & INTERFACE_ID_MASK; + user_data->cb(user_data->idev, user_data->callback, user_data->data, + InterfaceId, user_data->noack, user_data->MessageId, RequestID, + WINPR_ASSERTING_INT_CAST(uint32_t, transfer->num_iso_packets), + transfer->status, user_data->StartFrame, user_data->ErrorCount, + user_data->OutputBufferSize); + user_data->data = NULL; + } + ArrayList_Remove(list, transfer); + } + } + break; + default: + break; + } + ArrayList_Unlock(list); +} + +static const LIBUSB_ENDPOINT_DESCEIPTOR* func_get_ep_desc(LIBUSB_CONFIG_DESCRIPTOR* LibusbConfig, + MSUSB_CONFIG_DESCRIPTOR* MsConfig, + UINT32 EndpointAddress) +{ + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = MsConfig->MsInterfaces; + const LIBUSB_INTERFACE* interface = LibusbConfig->interface; + + for (UINT32 inum = 0; inum < MsConfig->NumInterfaces; inum++) + { + BYTE alt = MsInterfaces[inum]->AlternateSetting; + const LIBUSB_ENDPOINT_DESCEIPTOR* endpoint = interface[inum].altsetting[alt].endpoint; + + for (UINT32 pnum = 0; pnum < MsInterfaces[inum]->NumberOfPipes; pnum++) + { + if (endpoint[pnum].bEndpointAddress == EndpointAddress) + { + return &endpoint[pnum]; + } + } + } + + return NULL; +} + +static void LIBUSB_CALL func_bulk_transfer_cb(struct libusb_transfer* transfer) +{ + ASYNC_TRANSFER_USER_DATA* user_data = NULL; + uint32_t streamID = 0; + wArrayList* list = NULL; + + user_data = (ASYNC_TRANSFER_USER_DATA*)transfer->user_data; + if (!user_data) + { + WLog_ERR(TAG, "[%s]: Invalid transfer->user_data!"); + return; + } + list = user_data->queue; + ArrayList_Lock(list); + streamID = stream_id_from_buffer(transfer); + + if (list_contains(list, streamID)) + { + const UINT32 InterfaceId = + ((STREAM_ID_PROXY << 30) | user_data->idev->get_ReqCompletion(user_data->idev)); + const UINT32 RequestID = streamID & INTERFACE_ID_MASK; + + user_data->cb(user_data->idev, user_data->callback, user_data->data, InterfaceId, + user_data->noack, user_data->MessageId, RequestID, + WINPR_ASSERTING_INT_CAST(uint32_t, transfer->num_iso_packets), + transfer->status, user_data->StartFrame, user_data->ErrorCount, + WINPR_ASSERTING_INT_CAST(uint32_t, transfer->actual_length)); + user_data->data = NULL; + ArrayList_Remove(list, transfer); + } + ArrayList_Unlock(list); +} + +static BOOL func_set_usbd_status(URBDRC_PLUGIN* urbdrc, UDEVICE* pdev, UINT32* status, + int err_result) +{ + if (!urbdrc || !status) + return FALSE; + + switch (err_result) + { + case LIBUSB_SUCCESS: + *status = USBD_STATUS_SUCCESS; + break; + + case LIBUSB_ERROR_IO: + *status = USBD_STATUS_STALL_PID; + break; + + case LIBUSB_ERROR_INVALID_PARAM: + *status = USBD_STATUS_INVALID_PARAMETER; + break; + + case LIBUSB_ERROR_ACCESS: + *status = USBD_STATUS_NOT_ACCESSED; + break; + + case LIBUSB_ERROR_NO_DEVICE: + *status = USBD_STATUS_DEVICE_GONE; + + if (pdev) + { + if (!(pdev->status & URBDRC_DEVICE_NOT_FOUND)) + pdev->status |= URBDRC_DEVICE_NOT_FOUND; + } + + break; + + case LIBUSB_ERROR_NOT_FOUND: + *status = USBD_STATUS_STALL_PID; + break; + + case LIBUSB_ERROR_BUSY: + *status = USBD_STATUS_STALL_PID; + break; + + case LIBUSB_ERROR_TIMEOUT: + *status = USBD_STATUS_TIMEOUT; + break; + + case LIBUSB_ERROR_OVERFLOW: + *status = USBD_STATUS_STALL_PID; + break; + + case LIBUSB_ERROR_PIPE: + *status = USBD_STATUS_STALL_PID; + break; + + case LIBUSB_ERROR_INTERRUPTED: + *status = USBD_STATUS_STALL_PID; + break; + + case LIBUSB_ERROR_NO_MEM: + *status = USBD_STATUS_NO_MEMORY; + break; + + case LIBUSB_ERROR_NOT_SUPPORTED: + *status = USBD_STATUS_NOT_SUPPORTED; + break; + + case LIBUSB_ERROR_OTHER: + *status = USBD_STATUS_STALL_PID; + break; + + default: + *status = USBD_STATUS_SUCCESS; + break; + } + + return TRUE; +} + +static int func_config_release_all_interface(URBDRC_PLUGIN* urbdrc, + LIBUSB_DEVICE_HANDLE* libusb_handle, + UINT32 NumInterfaces) +{ + if (NumInterfaces > INT32_MAX) + return -1; + for (INT32 i = 0; i < (INT32)NumInterfaces; i++) + { + int ret = libusb_release_interface(libusb_handle, i); + + if (log_libusb_result(urbdrc->log, WLOG_WARN, "libusb_release_interface", ret)) + return -1; + } + + return 0; +} + +static int func_claim_all_interface(URBDRC_PLUGIN* urbdrc, LIBUSB_DEVICE_HANDLE* libusb_handle, + int NumInterfaces) +{ + int ret = 0; + + for (int i = 0; i < NumInterfaces; i++) + { + ret = libusb_claim_interface(libusb_handle, i); + + if (log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_claim_interface", ret)) + return -1; + } + + return 0; +} + +static LIBUSB_DEVICE* udev_get_libusb_dev(libusb_context* context, uint8_t bus_number, + uint8_t dev_number) +{ + LIBUSB_DEVICE** libusb_list = NULL; + LIBUSB_DEVICE* device = NULL; + const ssize_t total_device = libusb_get_device_list(context, &libusb_list); + + for (ssize_t i = 0; i < total_device; i++) + { + LIBUSB_DEVICE* dev = libusb_list[i]; + if ((bus_number == libusb_get_bus_number(dev)) && + (dev_number == libusb_get_device_address(dev))) + device = dev; + else + libusb_unref_device(dev); + } + + libusb_free_device_list(libusb_list, 0); + return device; +} + +static LIBUSB_DEVICE_DESCRIPTOR* udev_new_descript(URBDRC_PLUGIN* urbdrc, LIBUSB_DEVICE* libusb_dev) +{ + int ret = 0; + LIBUSB_DEVICE_DESCRIPTOR* descriptor = + (LIBUSB_DEVICE_DESCRIPTOR*)calloc(1, sizeof(LIBUSB_DEVICE_DESCRIPTOR)); + if (!descriptor) + return NULL; + ret = libusb_get_device_descriptor(libusb_dev, descriptor); + + if (log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_get_device_descriptor", ret)) + { + free(descriptor); + return NULL; + } + + return descriptor; +} + +static int libusb_udev_select_interface(IUDEVICE* idev, BYTE InterfaceNumber, BYTE AlternateSetting) +{ + int error = 0; + int diff = 0; + UDEVICE* pdev = (UDEVICE*)idev; + URBDRC_PLUGIN* urbdrc = NULL; + MSUSB_CONFIG_DESCRIPTOR* MsConfig = NULL; + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = NULL; + + if (!pdev || !pdev->urbdrc) + return -1; + + urbdrc = pdev->urbdrc; + MsConfig = pdev->MsConfig; + + if (MsConfig) + { + MsInterfaces = MsConfig->MsInterfaces; + if (MsInterfaces) + { + WLog_Print(urbdrc->log, WLOG_INFO, + "select Interface(%" PRIu8 ") curr AlternateSetting(%" PRIu8 + ") new AlternateSetting(%" PRIu8 ")", + InterfaceNumber, MsInterfaces[InterfaceNumber]->AlternateSetting, + AlternateSetting); + + if (MsInterfaces[InterfaceNumber]->AlternateSetting != AlternateSetting) + { + diff = 1; + } + } + + if (diff) + { + error = libusb_set_interface_alt_setting(pdev->libusb_handle, InterfaceNumber, + AlternateSetting); + + log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_set_interface_alt_setting", error); + } + } + + return error; +} + +static MSUSB_CONFIG_DESCRIPTOR* +libusb_udev_complete_msconfig_setup(IUDEVICE* idev, MSUSB_CONFIG_DESCRIPTOR* MsConfig) +{ + UDEVICE* pdev = (UDEVICE*)idev; + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = NULL; + MSUSB_INTERFACE_DESCRIPTOR* MsInterface = NULL; + MSUSB_PIPE_DESCRIPTOR** MsPipes = NULL; + MSUSB_PIPE_DESCRIPTOR* MsPipe = NULL; + MSUSB_PIPE_DESCRIPTOR** t_MsPipes = NULL; + MSUSB_PIPE_DESCRIPTOR* t_MsPipe = NULL; + LIBUSB_CONFIG_DESCRIPTOR* LibusbConfig = NULL; + const LIBUSB_INTERFACE* LibusbInterface = NULL; + const LIBUSB_INTERFACE_DESCRIPTOR* LibusbAltsetting = NULL; + const LIBUSB_ENDPOINT_DESCEIPTOR* LibusbEndpoint = NULL; + BYTE LibusbNumEndpoint = 0; + URBDRC_PLUGIN* urbdrc = NULL; + UINT32 MsOutSize = 0; + + if (!pdev || !pdev->LibusbConfig || !pdev->urbdrc || !MsConfig) + return NULL; + + urbdrc = pdev->urbdrc; + LibusbConfig = pdev->LibusbConfig; + + if (LibusbConfig->bNumInterfaces != MsConfig->NumInterfaces) + { + WLog_Print(urbdrc->log, WLOG_ERROR, + "Select Configuration: Libusb NumberInterfaces(%" PRIu8 ") is different " + "with MsConfig NumberInterfaces(%" PRIu32 ")", + LibusbConfig->bNumInterfaces, MsConfig->NumInterfaces); + } + + /* replace MsPipes for libusb */ + MsInterfaces = MsConfig->MsInterfaces; + + for (UINT32 inum = 0; inum < MsConfig->NumInterfaces; inum++) + { + MsInterface = MsInterfaces[inum]; + /* get libusb's number of endpoints */ + LibusbInterface = &LibusbConfig->interface[MsInterface->InterfaceNumber]; + LibusbAltsetting = &LibusbInterface->altsetting[MsInterface->AlternateSetting]; + LibusbNumEndpoint = LibusbAltsetting->bNumEndpoints; + t_MsPipes = + (MSUSB_PIPE_DESCRIPTOR**)calloc(LibusbNumEndpoint, sizeof(MSUSB_PIPE_DESCRIPTOR*)); + + for (UINT32 pnum = 0; pnum < LibusbNumEndpoint; pnum++) + { + t_MsPipe = (MSUSB_PIPE_DESCRIPTOR*)calloc(1, sizeof(MSUSB_PIPE_DESCRIPTOR)); + + if (pnum < MsInterface->NumberOfPipes && MsInterface->MsPipes) + { + MsPipe = MsInterface->MsPipes[pnum]; + t_MsPipe->MaximumPacketSize = MsPipe->MaximumPacketSize; + t_MsPipe->MaximumTransferSize = MsPipe->MaximumTransferSize; + t_MsPipe->PipeFlags = MsPipe->PipeFlags; + } + else + { + t_MsPipe->MaximumPacketSize = 0; + t_MsPipe->MaximumTransferSize = 0xffffffff; + t_MsPipe->PipeFlags = 0; + } + + t_MsPipe->PipeHandle = 0; + t_MsPipe->bEndpointAddress = 0; + t_MsPipe->bInterval = 0; + t_MsPipe->PipeType = 0; + t_MsPipe->InitCompleted = 0; + t_MsPipes[pnum] = t_MsPipe; + } + + msusb_mspipes_replace(MsInterface, t_MsPipes, LibusbNumEndpoint); + } + + /* setup configuration */ + MsOutSize = 8; + /* ConfigurationHandle: 4 bytes + * --------------------------------------------------------------- + * ||<<< 1 byte >>>|<<< 1 byte >>>|<<<<<<<<<< 2 byte >>>>>>>>>>>|| + * || bus_number | dev_number | bConfigurationValue || + * --------------------------------------------------------------- + * ***********************/ + MsConfig->ConfigurationHandle = (uint32_t)MsConfig->bConfigurationValue | + ((uint32_t)pdev->bus_number << 24) | + (((uint32_t)pdev->dev_number << 16) & 0xFF0000); + MsInterfaces = MsConfig->MsInterfaces; + + for (UINT32 inum = 0; inum < MsConfig->NumInterfaces; inum++) + { + MsOutSize += 16; + MsInterface = MsInterfaces[inum]; + /* get libusb's interface */ + LibusbInterface = &LibusbConfig->interface[MsInterface->InterfaceNumber]; + LibusbAltsetting = &LibusbInterface->altsetting[MsInterface->AlternateSetting]; + /* InterfaceHandle: 4 bytes + * --------------------------------------------------------------- + * ||<<< 1 byte >>>|<<< 1 byte >>>|<<< 1 byte >>>|<<< 1 byte >>>|| + * || bus_number | dev_number | altsetting | interfaceNum || + * --------------------------------------------------------------- + * ***********************/ + MsInterface->InterfaceHandle = + WINPR_ASSERTING_INT_CAST(UINT32, (LibusbAltsetting->bInterfaceNumber | + (LibusbAltsetting->bAlternateSetting << 8) | + (pdev->dev_number << 16) | (pdev->bus_number << 24))); + const size_t len = 16 + (MsInterface->NumberOfPipes * 20); + MsInterface->Length = WINPR_ASSERTING_INT_CAST(UINT16, len); + MsInterface->bInterfaceClass = LibusbAltsetting->bInterfaceClass; + MsInterface->bInterfaceSubClass = LibusbAltsetting->bInterfaceSubClass; + MsInterface->bInterfaceProtocol = LibusbAltsetting->bInterfaceProtocol; + MsInterface->InitCompleted = 1; + MsPipes = MsInterface->MsPipes; + LibusbNumEndpoint = LibusbAltsetting->bNumEndpoints; + + for (UINT32 pnum = 0; pnum < LibusbNumEndpoint; pnum++) + { + MsOutSize += 20; + MsPipe = MsPipes[pnum]; + /* get libusb's endpoint */ + LibusbEndpoint = &LibusbAltsetting->endpoint[pnum]; + /* PipeHandle: 4 bytes + * --------------------------------------------------------------- + * ||<<< 1 byte >>>|<<< 1 byte >>>|<<<<<<<<<< 2 byte >>>>>>>>>>>|| + * || bus_number | dev_number | bEndpointAddress || + * --------------------------------------------------------------- + * ***********************/ + MsPipe->PipeHandle = LibusbEndpoint->bEndpointAddress | + (((uint32_t)pdev->dev_number << 16) & 0xFF0000) | + (((uint32_t)pdev->bus_number << 24) & 0xFF000000); + /* count endpoint max packet size */ + unsigned max = LibusbEndpoint->wMaxPacketSize & 0x07ff; + BYTE attr = LibusbEndpoint->bmAttributes; + + if ((attr & 0x3) == 1 || (attr & 0x3) == 3) + { + max *= (1 + ((LibusbEndpoint->wMaxPacketSize >> 11) & 3)); + } + + MsPipe->MaximumPacketSize = WINPR_ASSERTING_INT_CAST(uint16_t, max); + MsPipe->bEndpointAddress = LibusbEndpoint->bEndpointAddress; + MsPipe->bInterval = LibusbEndpoint->bInterval; + MsPipe->PipeType = attr & 0x3; + MsPipe->InitCompleted = 1; + } + } + + MsConfig->MsOutSize = WINPR_ASSERTING_INT_CAST(int, MsOutSize); + MsConfig->InitCompleted = 1; + + /* replace device's MsConfig */ + if (MsConfig != pdev->MsConfig) + { + msusb_msconfig_free(pdev->MsConfig); + pdev->MsConfig = MsConfig; + } + + return MsConfig; +} + +static int libusb_udev_select_configuration(IUDEVICE* idev, UINT32 bConfigurationValue) +{ + UDEVICE* pdev = (UDEVICE*)idev; + MSUSB_CONFIG_DESCRIPTOR* MsConfig = NULL; + LIBUSB_DEVICE_HANDLE* libusb_handle = NULL; + LIBUSB_DEVICE* libusb_dev = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + LIBUSB_CONFIG_DESCRIPTOR** LibusbConfig = NULL; + int ret = 0; + + if (!pdev || !pdev->MsConfig || !pdev->LibusbConfig || !pdev->urbdrc) + return -1; + + urbdrc = pdev->urbdrc; + MsConfig = pdev->MsConfig; + libusb_handle = pdev->libusb_handle; + libusb_dev = pdev->libusb_dev; + LibusbConfig = &pdev->LibusbConfig; + + if (MsConfig->InitCompleted) + { + func_config_release_all_interface(pdev->urbdrc, libusb_handle, + (*LibusbConfig)->bNumInterfaces); + } + + /* The configuration value -1 is mean to put the device in unconfigured state. */ + if (bConfigurationValue == 0) + ret = libusb_set_configuration(libusb_handle, -1); + else + ret = libusb_set_configuration(libusb_handle, + WINPR_ASSERTING_INT_CAST(int, bConfigurationValue)); + + if (log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_set_configuration", ret)) + { + func_claim_all_interface(urbdrc, libusb_handle, (*LibusbConfig)->bNumInterfaces); + return -1; + } + else + { + ret = libusb_get_active_config_descriptor(libusb_dev, LibusbConfig); + + if (log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_set_configuration", ret)) + { + func_claim_all_interface(urbdrc, libusb_handle, (*LibusbConfig)->bNumInterfaces); + return -1; + } + } + + func_claim_all_interface(urbdrc, libusb_handle, (*LibusbConfig)->bNumInterfaces); + return 0; +} + +static int libusb_udev_control_pipe_request(IUDEVICE* idev, UINT32 RequestId, + UINT32 EndpointAddress, UINT32* UsbdStatus, int command) +{ + int error = 0; + UDEVICE* pdev = (UDEVICE*)idev; + + WINPR_ASSERT(EndpointAddress <= UINT8_MAX); + /* + pdev->request_queue->register_request(pdev->request_queue, RequestId, NULL, 0); + */ + switch (command) + { + case PIPE_CANCEL: + /** cancel bulk or int transfer */ + idev->cancel_all_transfer_request(idev); + // dummy_wait_s_obj(1); + /** set feature to ep (set halt)*/ + /* + uint8_t request_type, uint8_t bRequest, + */ + error = libusb_control_transfer(pdev->libusb_handle, + (uint8_t)LIBUSB_ENDPOINT_OUT | + (uint8_t)LIBUSB_RECIPIENT_ENDPOINT, + LIBUSB_REQUEST_SET_FEATURE, ENDPOINT_HALT, + (uint16_t)EndpointAddress, NULL, 0, 1000); + break; + + case PIPE_RESET: + idev->cancel_all_transfer_request(idev); + error = libusb_clear_halt(pdev->libusb_handle, (uint8_t)EndpointAddress); + // func_set_usbd_status(pdev, UsbdStatus, error); + break; + + default: + error = -0xff; + break; + } + + *UsbdStatus = 0; + return error; +} + +static UINT32 libusb_udev_control_query_device_text(IUDEVICE* idev, UINT32 TextType, + UINT16 LocaleId, UINT8* BufferSize, + BYTE* Buffer) +{ + UDEVICE* pdev = (UDEVICE*)idev; + LIBUSB_DEVICE_DESCRIPTOR* devDescriptor = NULL; + const char strDesc[] = "Generic Usb String"; + char deviceLocation[25] = { 0 }; + BYTE bus_number = 0; + BYTE device_address = 0; + int ret = 0; + size_t len = 0; + URBDRC_PLUGIN* urbdrc = NULL; + WCHAR* text = (WCHAR*)Buffer; + BYTE slen = 0; + BYTE locale = 0; + const UINT8 inSize = *BufferSize; + + *BufferSize = 0; + if (!pdev || !pdev->devDescriptor || !pdev->urbdrc) + return ERROR_INVALID_DATA; + + urbdrc = pdev->urbdrc; + devDescriptor = pdev->devDescriptor; + + switch (TextType) + { + case DeviceTextDescription: + { + BYTE data[0x100] = { 0 }; + ret = libusb_get_string_descriptor(pdev->libusb_handle, devDescriptor->iProduct, + LocaleId, data, 0xFF); + /* The returned data in the buffer is: + * 1 byte length of following data + * 1 byte descriptor type, must be 0x03 for strings + * n WCHAR unicode string (of length / 2 characters) including '\0' + */ + slen = data[0]; + locale = data[1]; + + if ((ret <= 0) || (ret <= 4) || (slen <= 4) || (locale != LIBUSB_DT_STRING) || + (ret > UINT8_MAX)) + { + const char* msg = "SHORT_DESCRIPTOR"; + if (ret < 0) + msg = libusb_error_name(ret); + WLog_Print(urbdrc->log, WLOG_DEBUG, + "libusb_get_string_descriptor: " + "%s [%d], iProduct: %" PRIu8 "!", + msg, ret, devDescriptor->iProduct); + + len = MIN(sizeof(strDesc), inSize); + for (size_t i = 0; i < len; i++) + text[i] = (WCHAR)strDesc[i]; + + *BufferSize = (BYTE)(len * 2); + } + else + { + /* ret and slen should be equals, but you never know creativity + * of device manufacturers... + * So also check the string length returned as server side does + * not honor strings with multi '\0' characters well. + */ + const size_t rchar = _wcsnlen((WCHAR*)&data[2], sizeof(data) / 2); + len = MIN((BYTE)ret - 2, slen); + len = MIN(len, inSize); + len = MIN(len, rchar * 2 + sizeof(WCHAR)); + memcpy(Buffer, &data[2], len); + + /* Just as above, the returned WCHAR string should be '\0' + * terminated, but never trust hardware to conform to specs... */ + Buffer[len - 2] = '\0'; + Buffer[len - 1] = '\0'; + *BufferSize = (BYTE)len; + } + } + break; + + case DeviceTextLocationInformation: + bus_number = libusb_get_bus_number(pdev->libusb_dev); + device_address = libusb_get_device_address(pdev->libusb_dev); + (void)sprintf_s(deviceLocation, sizeof(deviceLocation), + "Port_#%04" PRIu8 ".Hub_#%04" PRIu8 "", device_address, bus_number); + + len = strnlen(deviceLocation, + MIN(sizeof(deviceLocation), (inSize > 0) ? inSize - 1U : 0)); + for (size_t i = 0; i < len; i++) + text[i] = (WCHAR)deviceLocation[i]; + text[len++] = '\0'; + *BufferSize = (UINT8)(len * sizeof(WCHAR)); + break; + + default: + WLog_Print(urbdrc->log, WLOG_DEBUG, "Query Text: unknown TextType %" PRIu32 "", + TextType); + return ERROR_INVALID_DATA; + } + + return S_OK; +} + +static int libusb_udev_os_feature_descriptor_request(IUDEVICE* idev, UINT32 RequestId, + BYTE Recipient, BYTE InterfaceNumber, + BYTE Ms_PageIndex, UINT16 Ms_featureDescIndex, + UINT32* UsbdStatus, UINT32* BufferSize, + BYTE* Buffer, UINT32 Timeout) +{ + UDEVICE* pdev = (UDEVICE*)idev; + BYTE ms_string_desc[0x13] = { 0 }; + int error = 0; + + WINPR_ASSERT(idev); + WINPR_ASSERT(UsbdStatus); + WINPR_ASSERT(BufferSize); + WINPR_ASSERT(*BufferSize <= UINT16_MAX); + + /* + pdev->request_queue->register_request(pdev->request_queue, RequestId, NULL, 0); + */ + error = libusb_control_transfer(pdev->libusb_handle, LIBUSB_ENDPOINT_IN | Recipient, + LIBUSB_REQUEST_GET_DESCRIPTOR, 0x03ee, 0, ms_string_desc, 0x12, + Timeout); + + log_libusb_result(pdev->urbdrc->log, WLOG_DEBUG, "libusb_control_transfer", error); + + if (error > 0) + { + const BYTE bMS_Vendorcode = ms_string_desc[16]; + /** get os descriptor */ + error = libusb_control_transfer( + pdev->libusb_handle, + (uint8_t)LIBUSB_ENDPOINT_IN | (uint8_t)LIBUSB_REQUEST_TYPE_VENDOR | Recipient, + bMS_Vendorcode, (UINT16)((InterfaceNumber << 8) | Ms_PageIndex), Ms_featureDescIndex, + Buffer, (UINT16)*BufferSize, Timeout); + log_libusb_result(pdev->urbdrc->log, WLOG_DEBUG, "libusb_control_transfer", error); + + if (error >= 0) + *BufferSize = (UINT32)error; + } + + if (error < 0) + *UsbdStatus = USBD_STATUS_STALL_PID; + else + *UsbdStatus = USBD_STATUS_SUCCESS; + + return ERROR_SUCCESS; +} + +static int libusb_udev_query_device_descriptor(IUDEVICE* idev, int offset) +{ + UDEVICE* pdev = (UDEVICE*)idev; + + switch (offset) + { + case B_LENGTH: + return pdev->devDescriptor->bLength; + + case B_DESCRIPTOR_TYPE: + return pdev->devDescriptor->bDescriptorType; + + case BCD_USB: + return pdev->devDescriptor->bcdUSB; + + case B_DEVICE_CLASS: + return pdev->devDescriptor->bDeviceClass; + + case B_DEVICE_SUBCLASS: + return pdev->devDescriptor->bDeviceSubClass; + + case B_DEVICE_PROTOCOL: + return pdev->devDescriptor->bDeviceProtocol; + + case B_MAX_PACKET_SIZE0: + return pdev->devDescriptor->bMaxPacketSize0; + + case ID_VENDOR: + return pdev->devDescriptor->idVendor; + + case ID_PRODUCT: + return pdev->devDescriptor->idProduct; + + case BCD_DEVICE: + return pdev->devDescriptor->bcdDevice; + + case I_MANUFACTURER: + return pdev->devDescriptor->iManufacturer; + + case I_PRODUCT: + return pdev->devDescriptor->iProduct; + + case I_SERIAL_NUMBER: + return pdev->devDescriptor->iSerialNumber; + + case B_NUM_CONFIGURATIONS: + return pdev->devDescriptor->bNumConfigurations; + + default: + return 0; + } +} + +static BOOL libusb_udev_detach_kernel_driver(IUDEVICE* idev) +{ + int err = 0; + UDEVICE* pdev = (UDEVICE*)idev; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!pdev || !pdev->LibusbConfig || !pdev->libusb_handle || !pdev->urbdrc) + return FALSE; + +#ifdef _WIN32 + return TRUE; +#else + urbdrc = pdev->urbdrc; + + if ((pdev->status & URBDRC_DEVICE_DETACH_KERNEL) == 0) + { + for (int i = 0; i < pdev->LibusbConfig->bNumInterfaces; i++) + { + err = libusb_kernel_driver_active(pdev->libusb_handle, i); + log_libusb_result(urbdrc->log, WLOG_DEBUG, "libusb_kernel_driver_active", err); + + if (err) + { + err = libusb_detach_kernel_driver(pdev->libusb_handle, i); + log_libusb_result(urbdrc->log, WLOG_DEBUG, "libusb_detach_kernel_driver", err); + } + } + + pdev->status |= URBDRC_DEVICE_DETACH_KERNEL; + } + + return TRUE; +#endif +} + +static BOOL libusb_udev_attach_kernel_driver(IUDEVICE* idev) +{ + int err = 0; + UDEVICE* pdev = (UDEVICE*)idev; + + if (!pdev || !pdev->LibusbConfig || !pdev->libusb_handle || !pdev->urbdrc) + return FALSE; + + for (int i = 0; i < pdev->LibusbConfig->bNumInterfaces && err != LIBUSB_ERROR_NO_DEVICE; i++) + { + err = libusb_release_interface(pdev->libusb_handle, i); + + log_libusb_result(pdev->urbdrc->log, WLOG_DEBUG, "libusb_release_interface", err); + +#ifndef _WIN32 + if (err != LIBUSB_ERROR_NO_DEVICE) + { + err = libusb_attach_kernel_driver(pdev->libusb_handle, i); + log_libusb_result(pdev->urbdrc->log, WLOG_DEBUG, "libusb_attach_kernel_driver if=%d", + err, i); + } +#endif + } + + return TRUE; +} + +static int libusb_udev_is_composite_device(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + return pdev->isCompositeDevice; +} + +static int libusb_udev_is_exist(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + return (pdev->status & URBDRC_DEVICE_NOT_FOUND) ? 0 : 1; +} + +static int libusb_udev_is_channel_closed(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + IUDEVMAN* udevman = NULL; + if (!pdev || !pdev->urbdrc) + return 1; + + udevman = pdev->urbdrc->udevman; + if (udevman) + { + if (udevman->status & URBDRC_DEVICE_CHANNEL_CLOSED) + return 1; + } + + if (pdev->status & URBDRC_DEVICE_CHANNEL_CLOSED) + return 1; + + return 0; +} + +static int libusb_udev_is_already_send(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + return (pdev->status & URBDRC_DEVICE_ALREADY_SEND) ? 1 : 0; +} + +/* This is called from channel cleanup code. + * Avoid double free, just remove the device and mark the channel closed. */ +static void libusb_udev_mark_channel_closed(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + if (pdev && ((pdev->status & URBDRC_DEVICE_CHANNEL_CLOSED) == 0)) + { + URBDRC_PLUGIN* urbdrc = pdev->urbdrc; + const uint8_t busNr = idev->get_bus_number(idev); + const uint8_t devNr = idev->get_dev_number(idev); + + pdev->status |= URBDRC_DEVICE_CHANNEL_CLOSED; + urbdrc->udevman->unregister_udevice(urbdrc->udevman, busNr, devNr); + } +} + +/* This is called by local events where the device is removed or in an error + * state. Remove the device from redirection and close the channel. */ +static void libusb_udev_channel_closed(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + if (pdev && ((pdev->status & URBDRC_DEVICE_CHANNEL_CLOSED) == 0)) + { + URBDRC_PLUGIN* urbdrc = pdev->urbdrc; + const uint8_t busNr = idev->get_bus_number(idev); + const uint8_t devNr = idev->get_dev_number(idev); + IWTSVirtualChannel* channel = NULL; + + if (pdev->channelManager) + channel = IFCALLRESULT(NULL, pdev->channelManager->FindChannelById, + pdev->channelManager, pdev->channelID); + + pdev->status |= URBDRC_DEVICE_CHANNEL_CLOSED; + + if (channel) + channel->Write(channel, 0, NULL, NULL); + + urbdrc->udevman->unregister_udevice(urbdrc->udevman, busNr, devNr); + } +} + +static void libusb_udev_set_already_send(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + pdev->status |= URBDRC_DEVICE_ALREADY_SEND; +} + +static char* libusb_udev_get_path(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + return pdev->path; +} + +static int libusb_udev_query_device_port_status(IUDEVICE* idev, UINT32* UsbdStatus, + UINT32* BufferSize, BYTE* Buffer) +{ + UDEVICE* pdev = (UDEVICE*)idev; + int success = 0; + int ret = 0; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!pdev || !pdev->urbdrc) + return -1; + + urbdrc = pdev->urbdrc; + + if (pdev->hub_handle != NULL) + { + ret = idev->control_transfer( + idev, 0xffff, 0, 0, + (uint8_t)LIBUSB_ENDPOINT_IN | (uint8_t)LIBUSB_REQUEST_TYPE_CLASS | + (uint8_t)LIBUSB_RECIPIENT_OTHER, + LIBUSB_REQUEST_GET_STATUS, 0, pdev->port_number, UsbdStatus, BufferSize, Buffer, 1000); + + if (log_libusb_result(urbdrc->log, WLOG_DEBUG, "libusb_control_transfer", ret)) + *BufferSize = 0; + else + { + WLog_Print(urbdrc->log, WLOG_DEBUG, + "PORT STATUS:0x%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "", Buffer[3], + Buffer[2], Buffer[1], Buffer[0]); + success = 1; + } + } + + return success; +} + +static int libusb_udev_isoch_transfer(IUDEVICE* idev, GENERIC_CHANNEL_CALLBACK* callback, + UINT32 MessageId, UINT32 RequestId, UINT32 EndpointAddress, + UINT32 TransferFlags, UINT32 StartFrame, UINT32 ErrorCount, + BOOL NoAck, const BYTE* packetDescriptorData, + UINT32 NumberOfPackets, UINT32 BufferSize, const BYTE* Buffer, + t_isoch_transfer_cb cb, UINT32 Timeout) +{ + int rc = 0; + UINT32 iso_packet_size = 0; + UDEVICE* pdev = (UDEVICE*)idev; + ASYNC_TRANSFER_USER_DATA* user_data = NULL; + struct libusb_transfer* iso_transfer = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + size_t outSize = (12ULL * NumberOfPackets); + uint32_t streamID = 0x40000000 | RequestId; + + if (!pdev || !pdev->urbdrc) + return -1; + + urbdrc = pdev->urbdrc; + user_data = async_transfer_user_data_new(idev, MessageId, 48, BufferSize, Buffer, + outSize + 1024, NoAck, cb, callback); + + if (!user_data) + return -1; + + user_data->ErrorCount = ErrorCount; + user_data->StartFrame = StartFrame; + + if (!Buffer) + Stream_Seek(user_data->data, (12ULL * NumberOfPackets)); + + if (NumberOfPackets > 0) + { + iso_packet_size = BufferSize / NumberOfPackets; + iso_transfer = libusb_alloc_transfer((int)NumberOfPackets); + } + + if (iso_transfer == NULL) + { + WLog_Print(urbdrc->log, WLOG_ERROR, + "Error: libusb_alloc_transfer [NumberOfPackets=%" PRIu32 ", BufferSize=%" PRIu32 + " ]", + NumberOfPackets, BufferSize); + async_transfer_user_data_free(user_data); + return -1; + } + + /** process URB_FUNCTION_IOSCH_TRANSFER */ + libusb_fill_iso_transfer( + iso_transfer, pdev->libusb_handle, WINPR_ASSERTING_INT_CAST(uint8_t, EndpointAddress), + Stream_Pointer(user_data->data), WINPR_ASSERTING_INT_CAST(int, BufferSize), + WINPR_ASSERTING_INT_CAST(int, NumberOfPackets), func_iso_callback, user_data, Timeout); + set_stream_id_for_buffer(iso_transfer, streamID); + libusb_set_iso_packet_lengths(iso_transfer, iso_packet_size); + + if (!ArrayList_Append(pdev->request_queue, iso_transfer)) + { + WLog_Print(urbdrc->log, WLOG_WARN, + "Failed to queue iso transfer, streamID %08" PRIx32 " already in use!", + streamID); + request_free(iso_transfer); + return -1; + } + rc = libusb_submit_transfer(iso_transfer); + if (log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_submit_transfer", rc)) + return -1; + return rc; +} + +static BOOL libusb_udev_control_transfer(IUDEVICE* idev, UINT32 RequestId, UINT32 EndpointAddress, + UINT32 TransferFlags, BYTE bmRequestType, BYTE Request, + UINT16 Value, UINT16 Index, UINT32* UrbdStatus, + UINT32* BufferSize, BYTE* Buffer, UINT32 Timeout) +{ + int status = 0; + UDEVICE* pdev = (UDEVICE*)idev; + + WINPR_ASSERT(BufferSize); + WINPR_ASSERT(*BufferSize <= UINT16_MAX); + + if (!pdev || !pdev->urbdrc) + return FALSE; + + status = libusb_control_transfer(pdev->libusb_handle, bmRequestType, Request, Value, Index, + Buffer, (UINT16)*BufferSize, Timeout); + + if (status >= 0) + *BufferSize = (UINT32)status; + else + log_libusb_result(pdev->urbdrc->log, WLOG_ERROR, "libusb_control_transfer", status); + + if (!func_set_usbd_status(pdev->urbdrc, pdev, UrbdStatus, status)) + return FALSE; + + return TRUE; +} + +static int libusb_udev_bulk_or_interrupt_transfer(IUDEVICE* idev, + GENERIC_CHANNEL_CALLBACK* callback, + UINT32 MessageId, UINT32 RequestId, + UINT32 EndpointAddress, UINT32 TransferFlags, + BOOL NoAck, UINT32 BufferSize, const BYTE* data, + t_isoch_transfer_cb cb, UINT32 Timeout) +{ + int rc = 0; + UINT32 transfer_type = 0; + UDEVICE* pdev = (UDEVICE*)idev; + const LIBUSB_ENDPOINT_DESCEIPTOR* ep_desc = NULL; + struct libusb_transfer* transfer = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + ASYNC_TRANSFER_USER_DATA* user_data = NULL; + uint32_t streamID = 0x80000000 | RequestId; + + if (!pdev || !pdev->LibusbConfig || !pdev->urbdrc) + return -1; + + urbdrc = pdev->urbdrc; + user_data = + async_transfer_user_data_new(idev, MessageId, 36, BufferSize, data, 0, NoAck, cb, callback); + + if (!user_data) + return -1; + + /* alloc memory for urb transfer */ + transfer = libusb_alloc_transfer(0); + if (!transfer) + { + async_transfer_user_data_free(user_data); + return -1; + } + transfer->user_data = user_data; + + ep_desc = func_get_ep_desc(pdev->LibusbConfig, pdev->MsConfig, EndpointAddress); + + if (!ep_desc) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "func_get_ep_desc: endpoint 0x%" PRIx32 " not found", + EndpointAddress); + request_free(transfer); + return -1; + } + + transfer_type = (ep_desc->bmAttributes) & 0x3; + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urb_bulk_or_interrupt_transfer: ep:0x%" PRIx32 " " + "transfer_type %" PRIu32 " flag:%" PRIu32 " OutputBufferSize:0x%" PRIx32 "", + EndpointAddress, transfer_type, TransferFlags, BufferSize); + + switch (transfer_type) + { + case BULK_TRANSFER: + /** Bulk Transfer */ + libusb_fill_bulk_transfer( + transfer, pdev->libusb_handle, WINPR_ASSERTING_INT_CAST(uint8_t, EndpointAddress), + Stream_Pointer(user_data->data), WINPR_ASSERTING_INT_CAST(int, BufferSize), + func_bulk_transfer_cb, user_data, Timeout); + break; + + case INTERRUPT_TRANSFER: + /** Interrupt Transfer */ + libusb_fill_interrupt_transfer( + transfer, pdev->libusb_handle, WINPR_ASSERTING_INT_CAST(uint8_t, EndpointAddress), + Stream_Pointer(user_data->data), WINPR_ASSERTING_INT_CAST(int, BufferSize), + func_bulk_transfer_cb, user_data, Timeout); + break; + + default: + WLog_Print(urbdrc->log, WLOG_DEBUG, + "urb_bulk_or_interrupt_transfer:" + " other transfer type 0x%" PRIX32 "", + transfer_type); + request_free(transfer); + return -1; + } + + set_stream_id_for_buffer(transfer, streamID); + + if (!ArrayList_Append(pdev->request_queue, transfer)) + { + WLog_Print(urbdrc->log, WLOG_WARN, + "Failed to queue transfer, streamID %08" PRIx32 " already in use!", streamID); + request_free(transfer); + return -1; + } + rc = libusb_submit_transfer(transfer); + if (log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_submit_transfer", rc)) + return -1; + return rc; +} + +static int func_cancel_xact_request(URBDRC_PLUGIN* urbdrc, struct libusb_transfer* transfer) +{ + int status = 0; + + if (!urbdrc || !transfer) + return -1; + + status = libusb_cancel_transfer(transfer); + + if (log_libusb_result(urbdrc->log, WLOG_WARN, "libusb_cancel_transfer", status)) + { + if (status == LIBUSB_ERROR_NOT_FOUND) + return -1; + } + else + return 1; + + return 0; +} + +static void libusb_udev_cancel_all_transfer_request(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + size_t count = 0; + + if (!pdev || !pdev->request_queue || !pdev->urbdrc) + return; + + ArrayList_Lock(pdev->request_queue); + count = ArrayList_Count(pdev->request_queue); + + for (size_t x = 0; x < count; x++) + { + struct libusb_transfer* transfer = ArrayList_GetItem(pdev->request_queue, x); + func_cancel_xact_request(pdev->urbdrc, transfer); + } + + ArrayList_Unlock(pdev->request_queue); +} + +static int libusb_udev_cancel_transfer_request(IUDEVICE* idev, UINT32 RequestId) +{ + int rc = -1; + UDEVICE* pdev = (UDEVICE*)idev; + struct libusb_transfer* transfer = NULL; + uint32_t cancelID1 = 0x40000000 | RequestId; + uint32_t cancelID2 = 0x80000000 | RequestId; + + if (!idev || !pdev->urbdrc || !pdev->request_queue) + return -1; + + ArrayList_Lock(pdev->request_queue); + transfer = list_contains(pdev->request_queue, cancelID1); + if (!transfer) + transfer = list_contains(pdev->request_queue, cancelID2); + + if (transfer) + { + URBDRC_PLUGIN* urbdrc = pdev->urbdrc; + + rc = func_cancel_xact_request(urbdrc, transfer); + } + ArrayList_Unlock(pdev->request_queue); + return rc; +} + +BASIC_STATE_FUNC_DEFINED(channelManager, IWTSVirtualChannelManager*) +BASIC_STATE_FUNC_DEFINED(channelID, UINT32) +BASIC_STATE_FUNC_DEFINED(ReqCompletion, UINT32) +BASIC_STATE_FUNC_DEFINED(bus_number, BYTE) +BASIC_STATE_FUNC_DEFINED(dev_number, BYTE) +BASIC_STATE_FUNC_DEFINED(port_number, UINT8) +BASIC_STATE_FUNC_DEFINED(MsConfig, MSUSB_CONFIG_DESCRIPTOR*) + +BASIC_POINT_FUNC_DEFINED(udev, void*) +BASIC_POINT_FUNC_DEFINED(prev, void*) +BASIC_POINT_FUNC_DEFINED(next, void*) + +static UINT32 udev_get_UsbDevice(IUDEVICE* idev) +{ + UDEVICE* pdev = (UDEVICE*)idev; + + if (!pdev) + return 0; + + return pdev->UsbDevice; +} + +static void udev_set_UsbDevice(IUDEVICE* idev, UINT32 val) +{ + UDEVICE* pdev = (UDEVICE*)idev; + + if (!pdev) + return; + + pdev->UsbDevice = val; +} + +static void udev_free(IUDEVICE* idev) +{ + int rc = 0; + UDEVICE* udev = (UDEVICE*)idev; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!idev || !udev->urbdrc) + return; + + urbdrc = udev->urbdrc; + + libusb_udev_cancel_all_transfer_request(&udev->iface); + if (udev->libusb_handle) + { + rc = libusb_reset_device(udev->libusb_handle); + + log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_reset_device", rc); + } + + /* HACK: We need to wait until the cancel transfer has been processed by + * poll_libusb_events + */ + Sleep(100); + + /* release all interface and attach kernel driver */ + udev->iface.attach_kernel_driver(idev); + ArrayList_Free(udev->request_queue); + /* free the config descriptor that send from windows */ + msusb_msconfig_free(udev->MsConfig); + libusb_unref_device(udev->libusb_dev); + libusb_close(udev->libusb_handle); + libusb_close(udev->hub_handle); + free(udev->devDescriptor); + free(idev); +} + +static void udev_load_interface(UDEVICE* pdev) +{ + WINPR_ASSERT(pdev); + + /* load interface */ + /* Basic */ + BASIC_STATE_FUNC_REGISTER(channelManager, pdev); + BASIC_STATE_FUNC_REGISTER(channelID, pdev); + BASIC_STATE_FUNC_REGISTER(UsbDevice, pdev); + BASIC_STATE_FUNC_REGISTER(ReqCompletion, pdev); + BASIC_STATE_FUNC_REGISTER(bus_number, pdev); + BASIC_STATE_FUNC_REGISTER(dev_number, pdev); + BASIC_STATE_FUNC_REGISTER(port_number, pdev); + BASIC_STATE_FUNC_REGISTER(MsConfig, pdev); + BASIC_STATE_FUNC_REGISTER(p_udev, pdev); + BASIC_STATE_FUNC_REGISTER(p_prev, pdev); + BASIC_STATE_FUNC_REGISTER(p_next, pdev); + pdev->iface.isCompositeDevice = libusb_udev_is_composite_device; + pdev->iface.isExist = libusb_udev_is_exist; + pdev->iface.isAlreadySend = libusb_udev_is_already_send; + pdev->iface.isChannelClosed = libusb_udev_is_channel_closed; + pdev->iface.setAlreadySend = libusb_udev_set_already_send; + pdev->iface.setChannelClosed = libusb_udev_channel_closed; + pdev->iface.markChannelClosed = libusb_udev_mark_channel_closed; + pdev->iface.getPath = libusb_udev_get_path; + /* Transfer */ + pdev->iface.isoch_transfer = libusb_udev_isoch_transfer; + pdev->iface.control_transfer = libusb_udev_control_transfer; + pdev->iface.bulk_or_interrupt_transfer = libusb_udev_bulk_or_interrupt_transfer; + pdev->iface.select_interface = libusb_udev_select_interface; + pdev->iface.select_configuration = libusb_udev_select_configuration; + pdev->iface.complete_msconfig_setup = libusb_udev_complete_msconfig_setup; + pdev->iface.control_pipe_request = libusb_udev_control_pipe_request; + pdev->iface.control_query_device_text = libusb_udev_control_query_device_text; + pdev->iface.os_feature_descriptor_request = libusb_udev_os_feature_descriptor_request; + pdev->iface.cancel_all_transfer_request = libusb_udev_cancel_all_transfer_request; + pdev->iface.cancel_transfer_request = libusb_udev_cancel_transfer_request; + pdev->iface.query_device_descriptor = libusb_udev_query_device_descriptor; + pdev->iface.detach_kernel_driver = libusb_udev_detach_kernel_driver; + pdev->iface.attach_kernel_driver = libusb_udev_attach_kernel_driver; + pdev->iface.query_device_port_status = libusb_udev_query_device_port_status; + pdev->iface.free = udev_free; +} + +static int udev_get_device_handle(URBDRC_PLUGIN* urbdrc, libusb_context* ctx, UDEVICE* pdev, + UINT16 bus_number, UINT16 dev_number) +{ + int error = -1; + uint8_t port_numbers[16] = { 0 }; + LIBUSB_DEVICE** libusb_list = NULL; + const ssize_t total_device = libusb_get_device_list(ctx, &libusb_list); + + WINPR_ASSERT(urbdrc); + + /* Look for device. */ + for (ssize_t i = 0; i < total_device; i++) + { + LIBUSB_DEVICE* dev = libusb_list[i]; + + if ((bus_number != libusb_get_bus_number(dev)) || + (dev_number != libusb_get_device_address(dev))) + libusb_unref_device(dev); + else + { + error = libusb_open(dev, &pdev->libusb_handle); + + if (log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_open", error)) + { + libusb_unref_device(dev); + continue; + } + + /* get port number */ + error = libusb_get_port_numbers(dev, port_numbers, sizeof(port_numbers)); + if (error < 1) + { + /* Prevent open hub, treat as error. */ + log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_get_port_numbers", error); + libusb_unref_device(dev); + continue; + } + + pdev->port_number = port_numbers[(error - 1)]; + error = 0; + WLog_Print(urbdrc->log, WLOG_DEBUG, " Port: %" PRIu8, pdev->port_number); + /* gen device path */ + (void)_snprintf(pdev->path, sizeof(pdev->path), "%" PRIu16 "-%d", bus_number, + pdev->port_number); + + WLog_Print(urbdrc->log, WLOG_DEBUG, " DevPath: %s", pdev->path); + } + } + libusb_free_device_list(libusb_list, 0); + + if (error < 0) + return -1; + return 0; +} + +static int udev_get_hub_handle(URBDRC_PLUGIN* urbdrc, libusb_context* ctx, UDEVICE* pdev, + UINT16 bus_number, UINT16 dev_number) +{ + int error = -1; + LIBUSB_DEVICE** libusb_list = NULL; + LIBUSB_DEVICE_HANDLE* handle = NULL; + const ssize_t total_device = libusb_get_device_list(ctx, &libusb_list); + + WINPR_ASSERT(urbdrc); + + /* Look for device hub. */ + for (ssize_t i = 0; i < total_device; i++) + { + LIBUSB_DEVICE* dev = libusb_list[i]; + + if ((bus_number != libusb_get_bus_number(dev)) || + (1 != libusb_get_device_address(dev))) /* Root hub always first on bus. */ + libusb_unref_device(dev); + else + { + WLog_Print(urbdrc->log, WLOG_DEBUG, " Open hub: %" PRIu16 "", bus_number); + error = libusb_open(dev, &handle); + + if (!log_libusb_result(urbdrc->log, WLOG_ERROR, "libusb_open", error)) + pdev->hub_handle = handle; + else + libusb_unref_device(dev); + } + } + + libusb_free_device_list(libusb_list, 0); + + if (error < 0) + return -1; + + return 0; +} + +static void request_free(void* value) +{ + ASYNC_TRANSFER_USER_DATA* user_data = NULL; + struct libusb_transfer* transfer = (struct libusb_transfer*)value; + if (!transfer) + return; + + user_data = (ASYNC_TRANSFER_USER_DATA*)transfer->user_data; + async_transfer_user_data_free(user_data); + transfer->user_data = NULL; + libusb_free_transfer(transfer); +} + +static IUDEVICE* udev_init(URBDRC_PLUGIN* urbdrc, libusb_context* context, LIBUSB_DEVICE* device, + BYTE bus_number, BYTE dev_number) +{ + UDEVICE* pdev = NULL; + int status = LIBUSB_ERROR_OTHER; + LIBUSB_DEVICE_DESCRIPTOR* devDescriptor = NULL; + LIBUSB_CONFIG_DESCRIPTOR* config_temp = NULL; + LIBUSB_INTERFACE_DESCRIPTOR interface_temp; + + WINPR_ASSERT(urbdrc); + + pdev = (PUDEVICE)calloc(1, sizeof(UDEVICE)); + + if (!pdev) + return NULL; + + pdev->urbdrc = urbdrc; + udev_load_interface(pdev); + + if (device) + pdev->libusb_dev = device; + else + pdev->libusb_dev = udev_get_libusb_dev(context, bus_number, dev_number); + + if (pdev->libusb_dev == NULL) + goto fail; + + if (urbdrc->listener_callback) + udev_set_channelManager(&pdev->iface, urbdrc->listener_callback->channel_mgr); + + /* Get DEVICE handle */ + status = udev_get_device_handle(urbdrc, context, pdev, bus_number, dev_number); + if (status != LIBUSB_SUCCESS) + { + struct libusb_device_descriptor desc; + const uint8_t port = libusb_get_port_number(pdev->libusb_dev); + libusb_get_device_descriptor(pdev->libusb_dev, &desc); + + log_libusb_result(urbdrc->log, WLOG_ERROR, + "libusb_open [b=0x%02X,p=0x%02X,a=0x%02X,VID=0x%04X,PID=0x%04X]", status, + bus_number, port, dev_number, desc.idVendor, desc.idProduct); + goto fail; + } + + /* Get HUB handle */ + status = udev_get_hub_handle(urbdrc, context, pdev, bus_number, dev_number); + + if (status < 0) + pdev->hub_handle = NULL; + + pdev->devDescriptor = udev_new_descript(urbdrc, pdev->libusb_dev); + + if (!pdev->devDescriptor) + goto fail; + + status = libusb_get_active_config_descriptor(pdev->libusb_dev, &pdev->LibusbConfig); + + if (status == LIBUSB_ERROR_NOT_FOUND) + status = libusb_get_config_descriptor(pdev->libusb_dev, 0, &pdev->LibusbConfig); + + if (status < 0) + goto fail; + + config_temp = pdev->LibusbConfig; + /* get the first interface and first altsetting */ + interface_temp = config_temp->interface[0].altsetting[0]; + WLog_Print(urbdrc->log, WLOG_DEBUG, + "Registered Device: Vid: 0x%04" PRIX16 " Pid: 0x%04" PRIX16 "" + " InterfaceClass = %s", + pdev->devDescriptor->idVendor, pdev->devDescriptor->idProduct, + usb_interface_class_to_string(interface_temp.bInterfaceClass)); + /* Check composite device */ + devDescriptor = pdev->devDescriptor; + + if ((devDescriptor->bNumConfigurations == 1) && (config_temp->bNumInterfaces > 1) && + (devDescriptor->bDeviceClass == LIBUSB_CLASS_PER_INTERFACE)) + { + pdev->isCompositeDevice = 1; + } + else if ((devDescriptor->bDeviceClass == 0xef) && + (devDescriptor->bDeviceSubClass == LIBUSB_CLASS_COMM) && + (devDescriptor->bDeviceProtocol == 0x01)) + { + pdev->isCompositeDevice = 1; + } + else + pdev->isCompositeDevice = 0; + + /* set device class to first interface class */ + devDescriptor->bDeviceClass = interface_temp.bInterfaceClass; + devDescriptor->bDeviceSubClass = interface_temp.bInterfaceSubClass; + devDescriptor->bDeviceProtocol = interface_temp.bInterfaceProtocol; + /* initialize pdev */ + pdev->bus_number = bus_number; + pdev->dev_number = dev_number; + pdev->request_queue = ArrayList_New(TRUE); + + if (!pdev->request_queue) + goto fail; + + ArrayList_Object(pdev->request_queue)->fnObjectFree = request_free; + + /* set config of windows */ + pdev->MsConfig = msusb_msconfig_new(); + + if (!pdev->MsConfig) + goto fail; + + // deb_config_msg(pdev->libusb_dev, config_temp, devDescriptor->bNumConfigurations); + return &pdev->iface; +fail: + pdev->iface.free(&pdev->iface); + return NULL; +} + +size_t udev_new_by_id(URBDRC_PLUGIN* urbdrc, libusb_context* ctx, UINT16 idVendor, UINT16 idProduct, + IUDEVICE*** devArray) +{ + LIBUSB_DEVICE** libusb_list = NULL; + UDEVICE** array = NULL; + ssize_t total_device = 0; + size_t num = 0; + + if (!urbdrc || !devArray) + return 0; + + WLog_Print(urbdrc->log, WLOG_INFO, "VID: 0x%04" PRIX16 ", PID: 0x%04" PRIX16 "", idVendor, + idProduct); + total_device = libusb_get_device_list(ctx, &libusb_list); + if (total_device < 0) + return 0; + + array = (UDEVICE**)calloc((size_t)total_device, sizeof(UDEVICE*)); + + if (!array) + goto fail; + + for (ssize_t i = 0; i < total_device; i++) + { + LIBUSB_DEVICE* dev = libusb_list[i]; + LIBUSB_DEVICE_DESCRIPTOR* descriptor = udev_new_descript(urbdrc, dev); + + if ((descriptor->idVendor == idVendor) && (descriptor->idProduct == idProduct)) + { + array[num] = (PUDEVICE)udev_init(urbdrc, ctx, dev, libusb_get_bus_number(dev), + libusb_get_device_address(dev)); + + if (array[num] != NULL) + num++; + } + else + libusb_unref_device(dev); + + free(descriptor); + } + +fail: + libusb_free_device_list(libusb_list, 0); + *devArray = (IUDEVICE**)array; + return num; +} + +IUDEVICE* udev_new_by_addr(URBDRC_PLUGIN* urbdrc, libusb_context* context, BYTE bus_number, + BYTE dev_number) +{ + WLog_Print(urbdrc->log, WLOG_DEBUG, "bus:%d dev:%d", bus_number, dev_number); + return udev_init(urbdrc, context, NULL, bus_number, dev_number); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevice.h b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevice.h new file mode 100644 index 0000000000000000000000000000000000000000..ac12abf43343aea5ea7accee60bcfa55e262e1b1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevice.h @@ -0,0 +1,76 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_URBDRC_CLIENT_LIBUSB_UDEVICE_H +#define FREERDP_CHANNEL_URBDRC_CLIENT_LIBUSB_UDEVICE_H + +#include +#include + +#include "urbdrc_types.h" +#include "urbdrc_main.h" + +typedef struct libusb_device LIBUSB_DEVICE; +typedef struct libusb_device_handle LIBUSB_DEVICE_HANDLE; +typedef struct libusb_device_descriptor LIBUSB_DEVICE_DESCRIPTOR; +typedef struct libusb_config_descriptor LIBUSB_CONFIG_DESCRIPTOR; +typedef struct libusb_interface LIBUSB_INTERFACE; +typedef struct libusb_interface_descriptor LIBUSB_INTERFACE_DESCRIPTOR; +typedef struct libusb_endpoint_descriptor LIBUSB_ENDPOINT_DESCEIPTOR; + +typedef struct +{ + IUDEVICE iface; + + void* udev; + void* prev; + void* next; + + UINT32 UsbDevice; /* An unique interface ID */ + UINT32 ReqCompletion; /* An unique interface ID */ + IWTSVirtualChannelManager* channelManager; + UINT32 channelID; + UINT16 status; + BYTE bus_number; + BYTE dev_number; + char path[17]; + UINT8 port_number; + int isCompositeDevice; + + LIBUSB_DEVICE_HANDLE* libusb_handle; + LIBUSB_DEVICE_HANDLE* hub_handle; + LIBUSB_DEVICE* libusb_dev; + LIBUSB_DEVICE_DESCRIPTOR* devDescriptor; + MSUSB_CONFIG_DESCRIPTOR* MsConfig; + LIBUSB_CONFIG_DESCRIPTOR* LibusbConfig; + + wArrayList* request_queue; + + URBDRC_PLUGIN* urbdrc; +} UDEVICE; +typedef UDEVICE* PUDEVICE; + +size_t udev_new_by_id(URBDRC_PLUGIN* urbdrc, libusb_context* ctx, UINT16 idVendor, UINT16 idProduct, + IUDEVICE*** devArray); +IUDEVICE* udev_new_by_addr(URBDRC_PLUGIN* urbdrc, libusb_context* context, BYTE bus_number, + BYTE dev_number); +const char* usb_interface_class_to_string(uint8_t class); + +#endif /* FREERDP_CHANNEL_URBDRC_CLIENT_LIBUSB_UDEVICE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevman.c b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevman.c new file mode 100644 index 0000000000000000000000000000000000000000..554620fd4e1f0872ef9e15cc6295593ba2b7774f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/libusb/libusb_udevman.c @@ -0,0 +1,965 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "urbdrc_types.h" +#include "urbdrc_main.h" + +#include "libusb_udevice.h" + +#include + +#if !defined(LIBUSB_HOTPLUG_NO_FLAGS) +#define LIBUSB_HOTPLUG_NO_FLAGS 0 +#endif + +#define BASIC_STATE_FUNC_DEFINED(_arg, _type) \ + static _type udevman_get_##_arg(IUDEVMAN* idevman) \ + { \ + UDEVMAN* udevman = (UDEVMAN*)idevman; \ + return udevman->_arg; \ + } \ + static void udevman_set_##_arg(IUDEVMAN* idevman, _type _t) \ + { \ + UDEVMAN* udevman = (UDEVMAN*)idevman; \ + udevman->_arg = _t; \ + } + +#define BASIC_STATE_FUNC_REGISTER(_arg, _man) \ + _man->iface.get_##_arg = udevman_get_##_arg; \ + (_man)->iface.set_##_arg = udevman_set_##_arg + +typedef struct +{ + UINT16 vid; + UINT16 pid; +} VID_PID_PAIR; + +typedef struct +{ + IUDEVMAN iface; + + IUDEVICE* idev; /* iterator device */ + IUDEVICE* head; /* head device in linked list */ + IUDEVICE* tail; /* tail device in linked list */ + + LPCSTR devices_vid_pid; + LPCSTR devices_addr; + wArrayList* hotplug_vid_pids; + UINT16 flags; + UINT32 device_num; + UINT32 next_device_id; + UINT32 channel_id; + + HANDLE devman_loading; + libusb_context* context; + HANDLE thread; + BOOL running; +} UDEVMAN; +typedef UDEVMAN* PUDEVMAN; + +static BOOL poll_libusb_events(UDEVMAN* udevman); + +static void udevman_rewind(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + udevman->idev = udevman->head; +} + +static BOOL udevman_has_next(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + + if (!udevman || !udevman->idev) + return FALSE; + else + return TRUE; +} + +static IUDEVICE* udevman_get_next(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + IUDEVICE* pdev = NULL; + pdev = udevman->idev; + udevman->idev = (IUDEVICE*)((UDEVICE*)udevman->idev)->next; + return pdev; +} + +static IUDEVICE* udevman_get_udevice_by_addr(IUDEVMAN* idevman, BYTE bus_number, BYTE dev_number) +{ + IUDEVICE* dev = NULL; + + if (!idevman) + return NULL; + + idevman->loading_lock(idevman); + idevman->rewind(idevman); + + while (idevman->has_next(idevman)) + { + IUDEVICE* pdev = idevman->get_next(idevman); + + if ((pdev->get_bus_number(pdev) == bus_number) && + (pdev->get_dev_number(pdev) == dev_number)) + { + dev = pdev; + break; + } + } + + idevman->loading_unlock(idevman); + return dev; +} + +static size_t udevman_register_udevice(IUDEVMAN* idevman, BYTE bus_number, BYTE dev_number, + UINT16 idVendor, UINT16 idProduct, UINT32 flag) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + IUDEVICE* pdev = NULL; + IUDEVICE** devArray = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + size_t num = 0; + size_t addnum = 0; + + if (!idevman || !idevman->plugin) + return 0; + + urbdrc = (URBDRC_PLUGIN*)idevman->plugin; + pdev = udevman_get_udevice_by_addr(idevman, bus_number, dev_number); + + if (pdev != NULL) + return 0; + + if (flag & UDEVMAN_FLAG_ADD_BY_ADDR) + { + UINT32 id = 0; + IUDEVICE* tdev = udev_new_by_addr(urbdrc, udevman->context, bus_number, dev_number); + + if (tdev == NULL) + return 0; + + id = idevman->get_next_device_id(idevman); + tdev->set_UsbDevice(tdev, id); + idevman->loading_lock(idevman); + + if (udevman->head == NULL) + { + /* linked list is empty */ + udevman->head = tdev; + udevman->tail = tdev; + } + else + { + /* append device to the end of the linked list */ + udevman->tail->set_p_next(udevman->tail, tdev); + tdev->set_p_prev(tdev, udevman->tail); + udevman->tail = tdev; + } + + udevman->device_num += 1; + idevman->loading_unlock(idevman); + } + else if (flag & UDEVMAN_FLAG_ADD_BY_VID_PID) + { + addnum = 0; + /* register all device that match pid vid */ + num = udev_new_by_id(urbdrc, udevman->context, idVendor, idProduct, &devArray); + + if (num == 0) + { + WLog_Print(urbdrc->log, WLOG_WARN, + "Could not find or redirect any usb devices by id %04x:%04x", idVendor, + idProduct); + } + + for (size_t i = 0; i < num; i++) + { + UINT32 id = 0; + IUDEVICE* tdev = devArray[i]; + + if (udevman_get_udevice_by_addr(idevman, tdev->get_bus_number(tdev), + tdev->get_dev_number(tdev)) != NULL) + { + tdev->free(tdev); + devArray[i] = NULL; + continue; + } + + id = idevman->get_next_device_id(idevman); + tdev->set_UsbDevice(tdev, id); + idevman->loading_lock(idevman); + + if (udevman->head == NULL) + { + /* linked list is empty */ + udevman->head = tdev; + udevman->tail = tdev; + } + else + { + /* append device to the end of the linked list */ + udevman->tail->set_p_next(udevman->tail, tdev); + tdev->set_p_prev(tdev, udevman->tail); + udevman->tail = tdev; + } + + udevman->device_num += 1; + idevman->loading_unlock(idevman); + addnum++; + } + + free((void*)devArray); + return addnum; + } + else + { + WLog_Print(urbdrc->log, WLOG_ERROR, "udevman_register_udevice: Invalid flag=%08" PRIx32, + flag); + return 0; + } + + return 1; +} + +static BOOL udevman_unregister_udevice(IUDEVMAN* idevman, BYTE bus_number, BYTE dev_number) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + UDEVICE* pdev = NULL; + UDEVICE* dev = (UDEVICE*)udevman_get_udevice_by_addr(idevman, bus_number, dev_number); + + if (!dev || !idevman) + return FALSE; + + idevman->loading_lock(idevman); + idevman->rewind(idevman); + + while (idevman->has_next(idevman)) + { + pdev = (UDEVICE*)idevman->get_next(idevman); + + if (pdev == dev) /* device exists */ + { + /* set previous device to point to next device */ + if (dev->prev != NULL) + { + /* unregistered device is not the head */ + pdev = dev->prev; + pdev->next = dev->next; + } + else + { + /* unregistered device is the head, update head */ + udevman->head = (IUDEVICE*)dev->next; + } + + /* set next device to point to previous device */ + + if (dev->next != NULL) + { + /* unregistered device is not the tail */ + pdev = (UDEVICE*)dev->next; + pdev->prev = dev->prev; + } + else + { + /* unregistered device is the tail, update tail */ + udevman->tail = (IUDEVICE*)dev->prev; + } + + udevman->device_num--; + break; + } + } + + idevman->loading_unlock(idevman); + + if (dev) + { + dev->iface.free(&dev->iface); + return TRUE; /* unregistration successful */ + } + + /* if we reach this point, the device wasn't found */ + return FALSE; +} + +static BOOL udevman_unregister_all_udevices(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + + if (!idevman) + return FALSE; + + if (!udevman->head) + return TRUE; + + idevman->loading_lock(idevman); + idevman->rewind(idevman); + + while (idevman->has_next(idevman)) + { + UDEVICE* dev = (UDEVICE*)idevman->get_next(idevman); + + if (!dev) + continue; + + /* set previous device to point to next device */ + if (dev->prev != NULL) + { + /* unregistered device is not the head */ + UDEVICE* pdev = dev->prev; + pdev->next = dev->next; + } + else + { + /* unregistered device is the head, update head */ + udevman->head = (IUDEVICE*)dev->next; + } + + /* set next device to point to previous device */ + + if (dev->next != NULL) + { + /* unregistered device is not the tail */ + UDEVICE* pdev = (UDEVICE*)dev->next; + pdev->prev = dev->prev; + } + else + { + /* unregistered device is the tail, update tail */ + udevman->tail = (IUDEVICE*)dev->prev; + } + + dev->iface.free(&dev->iface); + udevman->device_num--; + } + + idevman->loading_unlock(idevman); + + return TRUE; +} + +static int udevman_is_auto_add(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + return (udevman->flags & UDEVMAN_FLAG_ADD_BY_AUTO) ? 1 : 0; +} + +static IUDEVICE* udevman_get_udevice_by_UsbDevice(IUDEVMAN* idevman, UINT32 UsbDevice) +{ + UDEVICE* pdev = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!idevman || !idevman->plugin) + return NULL; + + /* Mask highest 2 bits, must be ignored */ + UsbDevice = UsbDevice & INTERFACE_ID_MASK; + urbdrc = (URBDRC_PLUGIN*)idevman->plugin; + idevman->loading_lock(idevman); + idevman->rewind(idevman); + + while (idevman->has_next(idevman)) + { + pdev = (UDEVICE*)idevman->get_next(idevman); + + if (pdev->UsbDevice == UsbDevice) + { + idevman->loading_unlock(idevman); + return (IUDEVICE*)pdev; + } + } + + idevman->loading_unlock(idevman); + WLog_Print(urbdrc->log, WLOG_WARN, "Failed to find a USB device mapped to deviceId=%08" PRIx32, + UsbDevice); + return NULL; +} + +static IUDEVICE* udevman_get_udevice_by_ChannelID(IUDEVMAN* idevman, UINT32 channelID) +{ + UDEVICE* pdev = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!idevman || !idevman->plugin) + return NULL; + + /* Mask highest 2 bits, must be ignored */ + urbdrc = (URBDRC_PLUGIN*)idevman->plugin; + idevman->loading_lock(idevman); + idevman->rewind(idevman); + + while (idevman->has_next(idevman)) + { + pdev = (UDEVICE*)idevman->get_next(idevman); + + if (pdev->channelID == channelID) + { + idevman->loading_unlock(idevman); + return (IUDEVICE*)pdev; + } + } + + idevman->loading_unlock(idevman); + WLog_Print(urbdrc->log, WLOG_WARN, "Failed to find a USB device mapped to channelID=%08" PRIx32, + channelID); + return NULL; +} + +static void udevman_loading_lock(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + (void)WaitForSingleObject(udevman->devman_loading, INFINITE); +} + +static void udevman_loading_unlock(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + (void)ReleaseMutex(udevman->devman_loading); +} + +BASIC_STATE_FUNC_DEFINED(device_num, UINT32) + +static UINT32 udevman_get_next_device_id(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + return udevman->next_device_id++; +} + +static void udevman_set_next_device_id(IUDEVMAN* idevman, UINT32 _t) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + udevman->next_device_id = _t; +} + +static void udevman_free(IUDEVMAN* idevman) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + + if (!udevman) + return; + + udevman->running = FALSE; + if (udevman->thread) + { + (void)WaitForSingleObject(udevman->thread, INFINITE); + (void)CloseHandle(udevman->thread); + } + + udevman_unregister_all_udevices(idevman); + + if (udevman->devman_loading) + (void)CloseHandle(udevman->devman_loading); + + libusb_exit(udevman->context); + + ArrayList_Free(udevman->hotplug_vid_pids); + free(udevman); +} + +static BOOL filter_by_class(uint8_t bDeviceClass, uint8_t bDeviceSubClass) +{ + switch (bDeviceClass) + { + case LIBUSB_CLASS_AUDIO: + case LIBUSB_CLASS_HID: + case LIBUSB_CLASS_MASS_STORAGE: + case LIBUSB_CLASS_HUB: + case LIBUSB_CLASS_SMART_CARD: + return TRUE; + default: + break; + } + + switch (bDeviceSubClass) + { + default: + break; + } + + return FALSE; +} + +static BOOL append(char* dst, size_t length, const char* src) +{ + return winpr_str_append(src, dst, length, NULL); +} + +static BOOL device_is_filtered(struct libusb_device* dev, + const struct libusb_device_descriptor* desc, + libusb_hotplug_event event) +{ + char buffer[8192] = { 0 }; + char* what = NULL; + BOOL filtered = FALSE; + append(buffer, sizeof(buffer), usb_interface_class_to_string(desc->bDeviceClass)); + if (filter_by_class(desc->bDeviceClass, desc->bDeviceSubClass)) + filtered = TRUE; + + switch (desc->bDeviceClass) + { + case LIBUSB_CLASS_PER_INTERFACE: + { + struct libusb_config_descriptor* config = NULL; + int rc = libusb_get_active_config_descriptor(dev, &config); + if (rc == LIBUSB_SUCCESS) + { + for (uint8_t x = 0; x < config->bNumInterfaces; x++) + { + const struct libusb_interface* ifc = &config->interface[x]; + for (int y = 0; y < ifc->num_altsetting; y++) + { + const struct libusb_interface_descriptor* const alt = &ifc->altsetting[y]; + if (filter_by_class(alt->bInterfaceClass, alt->bInterfaceSubClass)) + filtered = TRUE; + + append(buffer, sizeof(buffer), "|"); + append(buffer, sizeof(buffer), + usb_interface_class_to_string(alt->bInterfaceClass)); + } + } + } + libusb_free_config_descriptor(config); + } + break; + default: + break; + } + + if (filtered) + what = "Filtered"; + else + { + switch (event) + { + case LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT: + what = "Hotplug remove"; + break; + case LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED: + what = "Hotplug add"; + break; + default: + what = "Hotplug unknown"; + break; + } + } + + WLog_DBG(TAG, "%s device VID=0x%04X,PID=0x%04X class %s", what, desc->idVendor, desc->idProduct, + buffer); + return filtered; +} + +static int LIBUSB_CALL hotplug_callback(struct libusb_context* ctx, struct libusb_device* dev, + libusb_hotplug_event event, void* user_data) +{ + VID_PID_PAIR pair; + struct libusb_device_descriptor desc; + UDEVMAN* udevman = (UDEVMAN*)user_data; + const uint8_t bus = libusb_get_bus_number(dev); + const uint8_t addr = libusb_get_device_address(dev); + int rc = libusb_get_device_descriptor(dev, &desc); + + WINPR_UNUSED(ctx); + + if (rc != LIBUSB_SUCCESS) + return rc; + + switch (event) + { + case LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED: + pair.vid = desc.idVendor; + pair.pid = desc.idProduct; + if ((ArrayList_Contains(udevman->hotplug_vid_pids, &pair)) || + (udevman->iface.isAutoAdd(&udevman->iface) && + !device_is_filtered(dev, &desc, event))) + { + add_device(&udevman->iface, DEVICE_ADD_FLAG_ALL, bus, addr, desc.idVendor, + desc.idProduct); + } + break; + + case LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT: + del_device(&udevman->iface, DEVICE_ADD_FLAG_ALL, bus, addr, desc.idVendor, + desc.idProduct); + break; + + default: + break; + } + + return 0; +} + +static BOOL udevman_initialize(IUDEVMAN* idevman, UINT32 channelId) +{ + UDEVMAN* udevman = (UDEVMAN*)idevman; + + if (!udevman) + return FALSE; + + idevman->status &= (uint32_t)~URBDRC_DEVICE_CHANNEL_CLOSED; + idevman->controlChannelId = channelId; + return TRUE; +} + +static BOOL udevman_vid_pid_pair_equals(const void* objA, const void* objB) +{ + const VID_PID_PAIR* a = objA; + const VID_PID_PAIR* b = objB; + + return (a->vid == b->vid) && (a->pid == b->pid); +} + +static BOOL udevman_parse_device_id_addr(const char** str, UINT16* id1, UINT16* id2, UINT16 max, + char split_sign, char delimiter) +{ + char* mid = NULL; + char* end = NULL; + unsigned long rc = 0; + + rc = strtoul(*str, &mid, 16); + + if ((mid == *str) || (*mid != split_sign) || (rc > max)) + return FALSE; + + *id1 = (UINT16)rc; + rc = strtoul(++mid, &end, 16); + + if ((end == mid) || (rc > max)) + return FALSE; + + *id2 = (UINT16)rc; + + *str += end - *str; + if (*end == '\0') + return TRUE; + if (*end == delimiter) + { + (*str)++; + return TRUE; + } + + return FALSE; +} + +static BOOL urbdrc_udevman_register_devices(UDEVMAN* udevman, const char* devices, BOOL add_by_addr) +{ + const char* pos = devices; + VID_PID_PAIR* idpair = NULL; + UINT16 id1 = 0; + UINT16 id2 = 0; + + while (*pos != '\0') + { + if (!udevman_parse_device_id_addr(&pos, &id1, &id2, (add_by_addr) ? UINT8_MAX : UINT16_MAX, + ':', '#')) + { + WLog_ERR(TAG, "Invalid device argument: \"%s\"", devices); + return FALSE; + } + + if (add_by_addr) + { + add_device(&udevman->iface, DEVICE_ADD_FLAG_BUS | DEVICE_ADD_FLAG_DEV, (UINT8)id1, + (UINT8)id2, 0, 0); + } + else + { + idpair = calloc(1, sizeof(VID_PID_PAIR)); + if (!idpair) + return CHANNEL_RC_NO_MEMORY; + idpair->vid = id1; + idpair->pid = id2; + if (!ArrayList_Append(udevman->hotplug_vid_pids, idpair)) + { + free(idpair); + return CHANNEL_RC_NO_MEMORY; + } + + add_device(&udevman->iface, DEVICE_ADD_FLAG_VENDOR | DEVICE_ADD_FLAG_PRODUCT, 0, 0, id1, + id2); + } + } + + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): ArrayList_Append owns idpair + return CHANNEL_RC_OK; +} + +static UINT urbdrc_udevman_parse_addin_args(UDEVMAN* udevman, const ADDIN_ARGV* args) +{ + LPCSTR devices = NULL; + + for (int x = 0; x < args->argc; x++) + { + const char* arg = args->argv[x]; + if (strcmp(arg, "dbg") == 0) + { + WLog_SetLogLevel(WLog_Get(TAG), WLOG_TRACE); + } + else if (_strnicmp(arg, "device:", 7) == 0) + { + /* Redirect all local devices */ + const char* val = &arg[7]; + const size_t len = strlen(val); + if (strcmp(val, "*") == 0) + { + udevman->flags |= UDEVMAN_FLAG_ADD_BY_AUTO; + } + else if (_strnicmp(arg, "USBInstanceID:", 14) == 0) + { + // TODO: Usb instance ID + } + else if ((val[0] == '{') && (val[len - 1] == '}')) + { + // TODO: Usb device class + } + } + else if (_strnicmp(arg, "dev:", 4) == 0) + { + devices = &arg[4]; + } + else if (_strnicmp(arg, "id", 2) == 0) + { + const char* p = strchr(arg, ':'); + if (p) + udevman->devices_vid_pid = p + 1; + else + udevman->flags = UDEVMAN_FLAG_ADD_BY_VID_PID; + } + else if (_strnicmp(arg, "addr", 4) == 0) + { + const char* p = strchr(arg, ':'); + if (p) + udevman->devices_addr = p + 1; + else + udevman->flags = UDEVMAN_FLAG_ADD_BY_ADDR; + } + else if (strcmp(arg, "auto") == 0) + { + udevman->flags |= UDEVMAN_FLAG_ADD_BY_AUTO; + } + else + { + const size_t len = strlen(arg); + if ((arg[0] == '{') && (arg[len - 1] == '}')) + { + // TODO: Check for {Device Setup Class GUID}: + } + } + } + if (devices) + { + if (udevman->flags & UDEVMAN_FLAG_ADD_BY_VID_PID) + udevman->devices_vid_pid = devices; + else if (udevman->flags & UDEVMAN_FLAG_ADD_BY_ADDR) + udevman->devices_addr = devices; + } + + return CHANNEL_RC_OK; +} + +static UINT udevman_listener_created_callback(IUDEVMAN* iudevman) +{ + UDEVMAN* udevman = (UDEVMAN*)iudevman; + WINPR_ASSERT(udevman); + + if (udevman->devices_vid_pid) + return urbdrc_udevman_register_devices(udevman, udevman->devices_vid_pid, FALSE); + + if (udevman->devices_addr) + return urbdrc_udevman_register_devices(udevman, udevman->devices_addr, TRUE); + + return CHANNEL_RC_OK; +} + +static void udevman_load_interface(UDEVMAN* udevman) +{ + /* standard */ + udevman->iface.free = udevman_free; + /* manage devices */ + udevman->iface.rewind = udevman_rewind; + udevman->iface.get_next = udevman_get_next; + udevman->iface.has_next = udevman_has_next; + udevman->iface.register_udevice = udevman_register_udevice; + udevman->iface.unregister_udevice = udevman_unregister_udevice; + udevman->iface.get_udevice_by_UsbDevice = udevman_get_udevice_by_UsbDevice; + udevman->iface.get_udevice_by_ChannelID = udevman_get_udevice_by_ChannelID; + /* Extension */ + udevman->iface.isAutoAdd = udevman_is_auto_add; + /* Basic state */ + BASIC_STATE_FUNC_REGISTER(device_num, udevman); + BASIC_STATE_FUNC_REGISTER(next_device_id, udevman); + + /* control semaphore or mutex lock */ + udevman->iface.loading_lock = udevman_loading_lock; + udevman->iface.loading_unlock = udevman_loading_unlock; + udevman->iface.initialize = udevman_initialize; + udevman->iface.listener_created_callback = udevman_listener_created_callback; +} + +static BOOL poll_libusb_events(UDEVMAN* udevman) +{ + int rc = LIBUSB_SUCCESS; + struct timeval tv = { 0, 500 }; + if (libusb_try_lock_events(udevman->context) == 0) + { + if (libusb_event_handling_ok(udevman->context)) + { + rc = libusb_handle_events_locked(udevman->context, &tv); + if (rc != LIBUSB_SUCCESS) + WLog_WARN(TAG, "libusb_handle_events_locked %d", rc); + } + libusb_unlock_events(udevman->context); + } + else + { + libusb_lock_event_waiters(udevman->context); + if (libusb_event_handler_active(udevman->context)) + { + rc = libusb_wait_for_event(udevman->context, &tv); + if (rc < LIBUSB_SUCCESS) + WLog_WARN(TAG, "libusb_wait_for_event %d", rc); + } + libusb_unlock_event_waiters(udevman->context); + } + + return rc > 0; +} + +static DWORD WINAPI poll_thread(LPVOID lpThreadParameter) +{ + libusb_hotplug_callback_handle handle = 0; + UDEVMAN* udevman = (UDEVMAN*)lpThreadParameter; + BOOL hasHotplug = libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG); + + if (hasHotplug) + { + int rc = libusb_hotplug_register_callback( + udevman->context, + LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, + LIBUSB_HOTPLUG_NO_FLAGS, LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY, + LIBUSB_HOTPLUG_MATCH_ANY, hotplug_callback, udevman, &handle); + + if (rc != LIBUSB_SUCCESS) + udevman->running = FALSE; + } + else + WLog_WARN(TAG, "Platform does not support libusb hotplug. USB devices plugged in later " + "will not be detected."); + + while (udevman->running) + { + poll_libusb_events(udevman); + } + + if (hasHotplug) + libusb_hotplug_deregister_callback(udevman->context, handle); + + /* Process remaining usb events */ + while (poll_libusb_events(udevman)) + ; + + ExitThread(0); + return 0; +} + +FREERDP_ENTRY_POINT(UINT VCAPITYPE libusb_freerdp_urbdrc_client_subsystem_entry( + PFREERDP_URBDRC_SERVICE_ENTRY_POINTS pEntryPoints)) +{ + wObject* obj = NULL; + UINT status = 0; + UDEVMAN* udevman = NULL; + const ADDIN_ARGV* args = pEntryPoints->args; + udevman = (PUDEVMAN)calloc(1, sizeof(UDEVMAN)); + + if (!udevman) + goto fail; + + udevman->hotplug_vid_pids = ArrayList_New(TRUE); + if (!udevman->hotplug_vid_pids) + goto fail; + obj = ArrayList_Object(udevman->hotplug_vid_pids); + obj->fnObjectFree = free; + obj->fnObjectEquals = udevman_vid_pid_pair_equals; + + udevman->next_device_id = BASE_USBDEVICE_NUM; + udevman->iface.plugin = pEntryPoints->plugin; + const int res = libusb_init(&udevman->context); + + if (res != LIBUSB_SUCCESS) + goto fail; + +#ifdef _WIN32 +#if LIBUSB_API_VERSION >= 0x01000106 + /* Prefer usbDK backend on windows. Not supported on other platforms. */ + const int rc = libusb_set_option(udevman->context, LIBUSB_OPTION_USE_USBDK); + switch (rc) + { + case LIBUSB_SUCCESS: + break; + case LIBUSB_ERROR_NOT_FOUND: + case LIBUSB_ERROR_NOT_SUPPORTED: + WLog_WARN(TAG, "LIBUSB_OPTION_USE_USBDK %s [%d]", libusb_strerror(rc), rc); + break; + default: + WLog_ERR(TAG, "LIBUSB_OPTION_USE_USBDK %s [%d]", libusb_strerror(rc), rc); + goto fail; + } +#endif +#endif + + udevman->flags = UDEVMAN_FLAG_ADD_BY_VID_PID; + udevman->devman_loading = CreateMutexA(NULL, FALSE, "devman_loading"); + + if (!udevman->devman_loading) + goto fail; + + /* load usb device service management */ + udevman_load_interface(udevman); + status = urbdrc_udevman_parse_addin_args(udevman, args); + + if (status != CHANNEL_RC_OK) + goto fail; + + udevman->running = TRUE; + udevman->thread = CreateThread(NULL, 0, poll_thread, udevman, 0, NULL); + + if (!udevman->thread) + goto fail; + + if (!pEntryPoints->pRegisterUDEVMAN(pEntryPoints->plugin, (IUDEVMAN*)udevman)) + goto fail; + + WLog_DBG(TAG, "UDEVMAN device registered."); + return 0; +fail: + udevman_free(&udevman->iface); + return ERROR_INTERNAL_ERROR; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/urbdrc_main.c b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/urbdrc_main.c new file mode 100644 index 0000000000000000000000000000000000000000..d03c2a55767dc63cf3784a5403a080ee65fc4ce2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/urbdrc_main.c @@ -0,0 +1,1030 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "urbdrc_types.h" +#include "urbdrc_main.h" +#include "data_transfer.h" + +#include + +static IWTSVirtualChannel* get_channel(IUDEVMAN* idevman) +{ + IWTSVirtualChannelManager* channel_mgr = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!idevman) + return NULL; + + urbdrc = (URBDRC_PLUGIN*)idevman->plugin; + + if (!urbdrc || !urbdrc->listener_callback) + return NULL; + + channel_mgr = urbdrc->listener_callback->channel_mgr; + + if (!channel_mgr) + return NULL; + + return channel_mgr->FindChannelById(channel_mgr, idevman->controlChannelId); +} + +static int func_container_id_generate(IUDEVICE* pdev, char* strContainerId) +{ + char* p = NULL; + char* path = NULL; + UINT8 containerId[17] = { 0 }; + UINT16 idVendor = 0; + UINT16 idProduct = 0; + idVendor = (UINT16)pdev->query_device_descriptor(pdev, ID_VENDOR); + idProduct = (UINT16)pdev->query_device_descriptor(pdev, ID_PRODUCT); + path = pdev->getPath(pdev); + + if (strlen(path) > 8) + p = (path + strlen(path)) - 8; + else + p = path; + + (void)sprintf_s((char*)containerId, sizeof(containerId), "%04" PRIX16 "%04" PRIX16 "%s", + idVendor, idProduct, p); + /* format */ + (void)sprintf_s(strContainerId, DEVICE_CONTAINER_STR_SIZE, + "{%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 + "-%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 + "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "}", + containerId[0], containerId[1], containerId[2], containerId[3], containerId[4], + containerId[5], containerId[6], containerId[7], containerId[8], containerId[9], + containerId[10], containerId[11], containerId[12], containerId[13], + containerId[14], containerId[15]); + return 0; +} + +static int func_instance_id_generate(IUDEVICE* pdev, char* strInstanceId, size_t len) +{ + char instanceId[17] = { 0 }; + (void)sprintf_s(instanceId, sizeof(instanceId), "\\%s", pdev->getPath(pdev)); + /* format */ + (void)sprintf_s(strInstanceId, len, + "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 + "-%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 "-%02" PRIx8 "%02" PRIx8 + "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "%02" PRIx8 "", + instanceId[0], instanceId[1], instanceId[2], instanceId[3], instanceId[4], + instanceId[5], instanceId[6], instanceId[7], instanceId[8], instanceId[9], + instanceId[10], instanceId[11], instanceId[12], instanceId[13], instanceId[14], + instanceId[15]); + return 0; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_process_capability_request(GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 MessageId) +{ + UINT32 InterfaceId = 0; + UINT32 Version = 0; + UINT32 out_size = 0; + wStream* out = NULL; + + if (!callback || !s) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, Version); + + if (Version > RIM_CAPABILITY_VERSION_01) + Version = RIM_CAPABILITY_VERSION_01; + + InterfaceId = ((STREAM_ID_NONE << 30) | CAPABILITIES_NEGOTIATOR); + out_size = 16; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /* interface id */ + Stream_Write_UINT32(out, MessageId); /* message id */ + Stream_Write_UINT32(out, Version); /* usb protocol version */ + Stream_Write_UINT32(out, 0x00000000); /* HRESULT */ + return stream_write_and_free(callback->plugin, callback->channel, out); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_process_channel_create(GENERIC_CHANNEL_CALLBACK* callback, wStream* s, + UINT32 MessageId) +{ + UINT32 InterfaceId = 0; + UINT32 out_size = 0; + UINT32 MajorVersion = 0; + UINT32 MinorVersion = 0; + UINT32 Capabilities = 0; + wStream* out = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!callback || !s || !callback->plugin) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 12)) + return ERROR_INVALID_DATA; + + Stream_Read_UINT32(s, MajorVersion); + Stream_Read_UINT32(s, MinorVersion); + Stream_Read_UINT32(s, Capabilities); + + /* Version check, we only support version 1.0 */ + if ((MajorVersion != 1) || (MinorVersion != 0)) + { + WLog_Print(urbdrc->log, WLOG_WARN, + "server supports USB channel version %" PRIu32 ".%" PRIu32); + WLog_Print(urbdrc->log, WLOG_WARN, "we only support channel version 1.0"); + MajorVersion = 1; + MinorVersion = 0; + } + + InterfaceId = ((STREAM_ID_PROXY << 30) | CLIENT_CHANNEL_NOTIFICATION); + out_size = 24; + out = Stream_New(NULL, out_size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /* interface id */ + Stream_Write_UINT32(out, MessageId); /* message id */ + Stream_Write_UINT32(out, CHANNEL_CREATED); /* function id */ + Stream_Write_UINT32(out, MajorVersion); + Stream_Write_UINT32(out, MinorVersion); + Stream_Write_UINT32(out, Capabilities); /* capabilities version */ + return stream_write_and_free(callback->plugin, callback->channel, out); +} + +static UINT urdbrc_send_virtual_channel_add(IWTSPlugin* plugin, IWTSVirtualChannel* channel, + UINT32 MessageId) +{ + const UINT32 InterfaceId = ((STREAM_ID_PROXY << 30) | CLIENT_DEVICE_SINK); + wStream* out = Stream_New(NULL, 12); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /* interface */ + Stream_Write_UINT32(out, MessageId); /* message id */ + Stream_Write_UINT32(out, ADD_VIRTUAL_CHANNEL); /* function id */ + return stream_write_and_free(plugin, channel, out); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urdbrc_send_usb_device_add(GENERIC_CHANNEL_CALLBACK* callback, IUDEVICE* pdev) +{ + wStream* out = NULL; + UINT32 InterfaceId = 0; + char HardwareIds[2][DEVICE_HARDWARE_ID_SIZE] = { { 0 } }; + char CompatibilityIds[3][DEVICE_COMPATIBILITY_ID_SIZE] = { { 0 } }; + char strContainerId[DEVICE_CONTAINER_STR_SIZE] = { 0 }; + char strInstanceId[DEVICE_INSTANCE_STR_SIZE] = { 0 }; + const char* composite_str = "USB\\COMPOSITE"; + const size_t composite_len = 13; + size_t size = 0; + size_t CompatibilityIdLen[3]; + size_t HardwareIdsLen[2]; + size_t ContainerIdLen = 0; + size_t InstanceIdLen = 0; + size_t cchCompatIds = 0; + UINT32 bcdUSB = 0; + InterfaceId = ((STREAM_ID_PROXY << 30) | CLIENT_DEVICE_SINK); + /* USB kernel driver detach!! */ + pdev->detach_kernel_driver(pdev); + { + const UINT16 idVendor = (UINT16)pdev->query_device_descriptor(pdev, ID_VENDOR); + const UINT16 idProduct = (UINT16)pdev->query_device_descriptor(pdev, ID_PRODUCT); + const UINT16 bcdDevice = (UINT16)pdev->query_device_descriptor(pdev, BCD_DEVICE); + (void)sprintf_s(HardwareIds[1], DEVICE_HARDWARE_ID_SIZE, + "USB\\VID_%04" PRIX16 "&PID_%04" PRIX16 "", idVendor, idProduct); + (void)sprintf_s(HardwareIds[0], DEVICE_HARDWARE_ID_SIZE, + "USB\\VID_%04" PRIX16 "&PID_%04" PRIX16 "&REV_%04" PRIX16 "", idVendor, + idProduct, bcdDevice); + } + { + const UINT8 bDeviceClass = (UINT8)pdev->query_device_descriptor(pdev, B_DEVICE_CLASS); + const UINT8 bDeviceSubClass = (UINT8)pdev->query_device_descriptor(pdev, B_DEVICE_SUBCLASS); + const UINT8 bDeviceProtocol = (UINT8)pdev->query_device_descriptor(pdev, B_DEVICE_PROTOCOL); + + if (!(pdev->isCompositeDevice(pdev))) + { + (void)sprintf_s(CompatibilityIds[2], DEVICE_COMPATIBILITY_ID_SIZE, + "USB\\Class_%02" PRIX8 "", bDeviceClass); + (void)sprintf_s(CompatibilityIds[1], DEVICE_COMPATIBILITY_ID_SIZE, + "USB\\Class_%02" PRIX8 "&SubClass_%02" PRIX8 "", bDeviceClass, + bDeviceSubClass); + (void)sprintf_s(CompatibilityIds[0], DEVICE_COMPATIBILITY_ID_SIZE, + "USB\\Class_%02" PRIX8 "&SubClass_%02" PRIX8 "&Prot_%02" PRIX8 "", + bDeviceClass, bDeviceSubClass, bDeviceProtocol); + } + else + { + (void)sprintf_s(CompatibilityIds[2], DEVICE_COMPATIBILITY_ID_SIZE, "USB\\DevClass_00"); + (void)sprintf_s(CompatibilityIds[1], DEVICE_COMPATIBILITY_ID_SIZE, + "USB\\DevClass_00&SubClass_00"); + (void)sprintf_s(CompatibilityIds[0], DEVICE_COMPATIBILITY_ID_SIZE, + "USB\\DevClass_00&SubClass_00&Prot_00"); + } + } + func_instance_id_generate(pdev, strInstanceId, DEVICE_INSTANCE_STR_SIZE); + func_container_id_generate(pdev, strContainerId); + CompatibilityIdLen[0] = strnlen(CompatibilityIds[0], sizeof(CompatibilityIds[0])); + CompatibilityIdLen[1] = strnlen(CompatibilityIds[1], sizeof(CompatibilityIds[1])); + CompatibilityIdLen[2] = strnlen(CompatibilityIds[2], sizeof(CompatibilityIds[2])); + HardwareIdsLen[0] = strnlen(HardwareIds[0], sizeof(HardwareIds[0])); + HardwareIdsLen[1] = strnlen(HardwareIds[1], sizeof(HardwareIds[1])); + cchCompatIds = + CompatibilityIdLen[0] + 1 + CompatibilityIdLen[1] + 1 + CompatibilityIdLen[2] + 2; + InstanceIdLen = strnlen(strInstanceId, sizeof(strInstanceId)); + ContainerIdLen = strnlen(strContainerId, sizeof(strContainerId)); + + if (pdev->isCompositeDevice(pdev)) + cchCompatIds += composite_len + 1; + + size = 24; + size += (InstanceIdLen + 1) * 2 + (HardwareIdsLen[0] + 1) * 2 + 4 + + (HardwareIdsLen[1] + 1) * 2 + 2 + 4 + (cchCompatIds)*2 + (ContainerIdLen + 1) * 2 + 4 + + 28; + out = Stream_New(NULL, size); + + if (!out) + return ERROR_OUTOFMEMORY; + + Stream_Write_UINT32(out, InterfaceId); /* interface */ + Stream_Write_UINT32(out, 0); + Stream_Write_UINT32(out, ADD_DEVICE); /* function id */ + Stream_Write_UINT32(out, 0x00000001); /* NumUsbDevice */ + Stream_Write_UINT32(out, pdev->get_UsbDevice(pdev)); /* UsbDevice */ + Stream_Write_UINT32(out, (UINT32)InstanceIdLen + 1); /* cchDeviceInstanceId */ + if (Stream_Write_UTF16_String_From_UTF8(out, InstanceIdLen, strInstanceId, InstanceIdLen, + TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + const size_t len = HardwareIdsLen[0] + HardwareIdsLen[1] + 3; + if (len > UINT32_MAX) + goto fail; + Stream_Write_UINT32(out, (UINT32)len); /* cchHwIds */ + /* HardwareIds 1 */ + if (Stream_Write_UTF16_String_From_UTF8(out, HardwareIdsLen[0], HardwareIds[0], + HardwareIdsLen[0], TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + if (Stream_Write_UTF16_String_From_UTF8(out, HardwareIdsLen[1], HardwareIds[1], + HardwareIdsLen[1], TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + Stream_Write_UINT16(out, 0); /* add "\0" */ + Stream_Write_UINT32(out, (UINT32)cchCompatIds); /* cchCompatIds */ + /* CompatibilityIds */ + if (Stream_Write_UTF16_String_From_UTF8(out, CompatibilityIdLen[0], CompatibilityIds[0], + CompatibilityIdLen[0], TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + if (Stream_Write_UTF16_String_From_UTF8(out, CompatibilityIdLen[1], CompatibilityIds[1], + CompatibilityIdLen[1], TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + if (Stream_Write_UTF16_String_From_UTF8(out, CompatibilityIdLen[2], CompatibilityIds[2], + CompatibilityIdLen[2], TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + + if (pdev->isCompositeDevice(pdev)) + { + if (Stream_Write_UTF16_String_From_UTF8(out, composite_len, composite_str, composite_len, + TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + } + + Stream_Write_UINT16(out, 0x0000); /* add "\0" */ + Stream_Write_UINT32(out, (UINT32)ContainerIdLen + 1); /* cchContainerId */ + /* ContainerId */ + if (Stream_Write_UTF16_String_From_UTF8(out, ContainerIdLen, strContainerId, ContainerIdLen, + TRUE) < 0) + goto fail; + Stream_Write_UINT16(out, 0); + /* USB_DEVICE_CAPABILITIES 28 bytes */ + Stream_Write_UINT32(out, 0x0000001c); /* CbSize */ + Stream_Write_UINT32(out, 2); /* UsbBusInterfaceVersion, 0 ,1 or 2 */ // TODO: Get from libusb + Stream_Write_UINT32(out, 0x600); /* USBDI_Version, 0x500 or 0x600 */ // TODO: Get from libusb + /* Supported_USB_Version, 0x110,0x110 or 0x200(usb2.0) */ + bcdUSB = WINPR_ASSERTING_INT_CAST(uint32_t, pdev->query_device_descriptor(pdev, BCD_USB)); + Stream_Write_UINT32(out, bcdUSB); + Stream_Write_UINT32(out, 0x00000000); /* HcdCapabilities, MUST always be zero */ + + if (bcdUSB < 0x200) + Stream_Write_UINT32(out, 0x00000000); /* DeviceIsHighSpeed */ + else + Stream_Write_UINT32(out, 0x00000001); /* DeviceIsHighSpeed */ + + Stream_Write_UINT32(out, 0x50); /* NoAckIsochWriteJitterBufferSizeInMs, >=10 or <=512 */ + return stream_write_and_free(callback->plugin, callback->channel, out); + +fail: + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_exchange_capabilities(GENERIC_CHANNEL_CALLBACK* callback, wStream* data) +{ + UINT32 MessageId = 0; + UINT32 FunctionId = 0; + UINT32 InterfaceId = 0; + UINT error = CHANNEL_RC_OK; + + if (!data) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, data, 8)) + return ERROR_INVALID_DATA; + + Stream_Rewind_UINT32(data); + Stream_Read_UINT32(data, InterfaceId); + Stream_Read_UINT32(data, MessageId); + Stream_Read_UINT32(data, FunctionId); + + switch (FunctionId) + { + case RIM_EXCHANGE_CAPABILITY_REQUEST: + error = urbdrc_process_capability_request(callback, data, MessageId); + break; + + case RIMCALL_RELEASE: + break; + + default: + error = ERROR_NOT_FOUND; + break; + } + + return error; +} + +static BOOL urbdrc_announce_devices(IUDEVMAN* udevman) +{ + UINT error = ERROR_SUCCESS; + + udevman->loading_lock(udevman); + udevman->rewind(udevman); + + while (udevman->has_next(udevman)) + { + IUDEVICE* pdev = udevman->get_next(udevman); + + if (!pdev->isAlreadySend(pdev)) + { + const UINT32 deviceId = pdev->get_UsbDevice(pdev); + UINT cerror = + urdbrc_send_virtual_channel_add(udevman->plugin, get_channel(udevman), deviceId); + + if (cerror != ERROR_SUCCESS) + break; + } + } + + udevman->loading_unlock(udevman); + + return error == ERROR_SUCCESS; +} + +static UINT urbdrc_device_control_channel(GENERIC_CHANNEL_CALLBACK* callback, wStream* s) +{ + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)callback->plugin; + IUDEVMAN* udevman = urbdrc->udevman; + IWTSVirtualChannel* channel = callback->channel; + IUDEVICE* pdev = NULL; + BOOL found = FALSE; + UINT error = ERROR_INTERNAL_ERROR; + UINT32 channelId = callback->channel_mgr->GetChannelId(channel); + + switch (urbdrc->vchannel_status) + { + case INIT_CHANNEL_IN: + /* Control channel was established */ + error = ERROR_SUCCESS; + udevman->initialize(udevman, channelId); + + if (!urbdrc_announce_devices(udevman)) + goto fail; + + urbdrc->vchannel_status = INIT_CHANNEL_OUT; + break; + + case INIT_CHANNEL_OUT: + /* A new device channel was created, add the channel + * to the device */ + udevman->loading_lock(udevman); + udevman->rewind(udevman); + + while (udevman->has_next(udevman)) + { + pdev = udevman->get_next(udevman); + + if (!pdev->isAlreadySend(pdev)) + { + const UINT32 channelID = callback->channel_mgr->GetChannelId(channel); + found = TRUE; + pdev->setAlreadySend(pdev); + pdev->set_channelManager(pdev, callback->channel_mgr); + pdev->set_channelID(pdev, channelID); + break; + } + } + + udevman->loading_unlock(udevman); + error = ERROR_SUCCESS; + + if (found && pdev->isAlreadySend(pdev)) + error = urdbrc_send_usb_device_add(callback, pdev); + + break; + + default: + WLog_Print(urbdrc->log, WLOG_ERROR, "vchannel_status unknown value %" PRIu32 "", + urbdrc->vchannel_status); + break; + } + +fail: + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_process_channel_notification(GENERIC_CHANNEL_CALLBACK* callback, wStream* data) +{ + UINT32 MessageId = 0; + UINT32 FunctionId = 0; + UINT32 InterfaceId = 0; + UINT error = CHANNEL_RC_OK; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!callback || !data) + return ERROR_INVALID_PARAMETER; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (!urbdrc) + return ERROR_INVALID_PARAMETER; + + if (!Stream_CheckAndLogRequiredLength(TAG, data, 8)) + return ERROR_INVALID_DATA; + + Stream_Rewind(data, 4); + Stream_Read_UINT32(data, InterfaceId); + Stream_Read_UINT32(data, MessageId); + Stream_Read_UINT32(data, FunctionId); + WLog_Print(urbdrc->log, WLOG_TRACE, "%s [%" PRIu32 "]", + call_to_string(FALSE, InterfaceId, FunctionId), FunctionId); + + switch (FunctionId) + { + case CHANNEL_CREATED: + error = urbdrc_process_channel_create(callback, data, MessageId); + break; + + case RIMCALL_RELEASE: + error = urbdrc_device_control_channel(callback, data); + break; + + default: + WLog_Print(urbdrc->log, WLOG_TRACE, "unknown FunctionId 0x%" PRIX32 "", FunctionId); + error = 1; + break; + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + URBDRC_PLUGIN* urbdrc = NULL; + IUDEVMAN* udevman = NULL; + UINT32 InterfaceId = 0; + UINT error = ERROR_INTERNAL_ERROR; + + if (callback == NULL) + return ERROR_INVALID_PARAMETER; + + if (callback->plugin == NULL) + return error; + + urbdrc = (URBDRC_PLUGIN*)callback->plugin; + + if (urbdrc->udevman == NULL) + return error; + + udevman = urbdrc->udevman; + + if (!Stream_CheckAndLogRequiredLength(TAG, data, 12)) + return ERROR_INVALID_DATA; + + urbdrc_dump_message(urbdrc->log, FALSE, FALSE, data); + Stream_Read_UINT32(data, InterfaceId); + + /* Need to check InterfaceId and mask values */ + switch (InterfaceId) + { + case CAPABILITIES_NEGOTIATOR | (STREAM_ID_NONE << 30): + error = urbdrc_exchange_capabilities(callback, data); + break; + + case SERVER_CHANNEL_NOTIFICATION | (STREAM_ID_PROXY << 30): + error = urbdrc_process_channel_notification(callback, data); + break; + + default: + error = urbdrc_process_udev_data_transfer(callback, urbdrc, udevman, data); + WLog_DBG(TAG, "urbdrc_process_udev_data_transfer returned 0x%08" PRIx32, error); + error = ERROR_SUCCESS; /* Ignore errors, the device may have been unplugged. */ + break; + } + + return error; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + GENERIC_CHANNEL_CALLBACK* callback = (GENERIC_CHANNEL_CALLBACK*)pChannelCallback; + if (callback) + { + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)callback->plugin; + if (urbdrc) + { + IUDEVMAN* udevman = urbdrc->udevman; + if (udevman && callback->channel_mgr) + { + UINT32 control = callback->channel_mgr->GetChannelId(callback->channel); + if (udevman->controlChannelId == control) + udevman->status |= URBDRC_DEVICE_CHANNEL_CLOSED; + else + { /* Need to notify the local backend the device is gone */ + IUDEVICE* pdev = udevman->get_udevice_by_ChannelID(udevman, control); + if (pdev) + pdev->markChannelClosed(pdev); + } + } + } + } + free(callback); + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, + IWTSVirtualChannel* pChannel, BYTE* pData, + BOOL* pbAccept, + IWTSVirtualChannelCallback** ppCallback) +{ + GENERIC_LISTENER_CALLBACK* listener_callback = (GENERIC_LISTENER_CALLBACK*)pListenerCallback; + GENERIC_CHANNEL_CALLBACK* callback = NULL; + + if (!ppCallback) + return ERROR_INVALID_PARAMETER; + + callback = (GENERIC_CHANNEL_CALLBACK*)calloc(1, sizeof(GENERIC_CHANNEL_CALLBACK)); + + if (!callback) + return ERROR_OUTOFMEMORY; + + callback->iface.OnDataReceived = urbdrc_on_data_received; + callback->iface.OnClose = urbdrc_on_close; + callback->plugin = listener_callback->plugin; + callback->channel_mgr = listener_callback->channel_mgr; + callback->channel = pChannel; + *ppCallback = (IWTSVirtualChannelCallback*)callback; + return CHANNEL_RC_OK; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr) +{ + UINT status = 0; + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin; + IUDEVMAN* udevman = NULL; + char channelName[sizeof(URBDRC_CHANNEL_NAME)] = { URBDRC_CHANNEL_NAME }; + + if (!urbdrc || !urbdrc->udevman) + return ERROR_INVALID_PARAMETER; + + if (urbdrc->initialized) + { + WLog_ERR(TAG, "[%s] channel initialized twice, aborting", URBDRC_CHANNEL_NAME); + return ERROR_INVALID_DATA; + } + udevman = urbdrc->udevman; + urbdrc->listener_callback = + (GENERIC_LISTENER_CALLBACK*)calloc(1, sizeof(GENERIC_LISTENER_CALLBACK)); + + if (!urbdrc->listener_callback) + return CHANNEL_RC_NO_MEMORY; + + urbdrc->listener_callback->iface.OnNewChannelConnection = urbdrc_on_new_channel_connection; + urbdrc->listener_callback->plugin = pPlugin; + urbdrc->listener_callback->channel_mgr = pChannelMgr; + + /* [MS-RDPEUSB] 2.1 Transport defines the channel name in uppercase letters */ + CharUpperA(channelName); + status = pChannelMgr->CreateListener(pChannelMgr, channelName, 0, + &urbdrc->listener_callback->iface, &urbdrc->listener); + if (status != CHANNEL_RC_OK) + return status; + + status = CHANNEL_RC_OK; + if (udevman->listener_created_callback) + status = udevman->listener_created_callback(udevman); + + urbdrc->initialized = status == CHANNEL_RC_OK; + return status; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_plugin_terminated(IWTSPlugin* pPlugin) +{ + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin; + IUDEVMAN* udevman = NULL; + + if (!urbdrc) + return ERROR_INVALID_DATA; + if (urbdrc->listener_callback) + { + IWTSVirtualChannelManager* mgr = urbdrc->listener_callback->channel_mgr; + if (mgr) + IFCALL(mgr->DestroyListener, mgr, urbdrc->listener); + } + udevman = urbdrc->udevman; + + if (udevman) + { + udevman->free(udevman); + udevman = NULL; + } + + free(urbdrc->subsystem); + free(urbdrc->listener_callback); + free(urbdrc); + return CHANNEL_RC_OK; +} + +static BOOL urbdrc_register_udevman_addin(IWTSPlugin* pPlugin, IUDEVMAN* udevman) +{ + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin; + + if (urbdrc->udevman) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "existing device, abort."); + return FALSE; + } + + DEBUG_DVC("device registered."); + urbdrc->udevman = udevman; + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_load_udevman_addin(IWTSPlugin* pPlugin, LPCSTR name, const ADDIN_ARGV* args) +{ + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin; + FREERDP_URBDRC_SERVICE_ENTRY_POINTS entryPoints = { 0 }; + + PVIRTUALCHANNELENTRY pvce = + freerdp_load_channel_addin_entry(URBDRC_CHANNEL_NAME, name, NULL, 0); + PFREERDP_URBDRC_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_URBDRC_DEVICE_ENTRY); + + if (!entry) + return ERROR_INVALID_OPERATION; + + entryPoints.plugin = pPlugin; + entryPoints.pRegisterUDEVMAN = urbdrc_register_udevman_addin; + entryPoints.args = args; + + const UINT error = entry(&entryPoints); + if (error) + { + WLog_Print(urbdrc->log, WLOG_ERROR, "%s entry returns error.", name); + return error; + } + + return CHANNEL_RC_OK; +} + +static BOOL urbdrc_set_subsystem(URBDRC_PLUGIN* urbdrc, const char* subsystem) +{ + free(urbdrc->subsystem); + urbdrc->subsystem = _strdup(subsystem); + return (urbdrc->subsystem != NULL); +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +static UINT urbdrc_process_addin_args(URBDRC_PLUGIN* urbdrc, const ADDIN_ARGV* args) +{ + int status = 0; + COMMAND_LINE_ARGUMENT_A urbdrc_args[] = { + { "dbg", COMMAND_LINE_VALUE_FLAG, "", NULL, BoolValueFalse, -1, NULL, "debug" }, + { "sys", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "subsystem" }, + { "dev", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, NULL, "devices" }, + { "encode", COMMAND_LINE_VALUE_FLAG, "", NULL, NULL, -1, NULL, "encode" }, + { "quality", COMMAND_LINE_VALUE_REQUIRED, "<[0-2] -> [high-medium-low]>", NULL, NULL, -1, + NULL, "quality" }, + { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } + }; + + const DWORD flags = + COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD; + const COMMAND_LINE_ARGUMENT_A* arg = NULL; + status = + CommandLineParseArgumentsA(args->argc, args->argv, urbdrc_args, flags, urbdrc, NULL, NULL); + + if (status < 0) + return ERROR_INVALID_DATA; + + arg = urbdrc_args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dbg") + { + WLog_SetLogLevel(urbdrc->log, WLOG_TRACE); + } + CommandLineSwitchCase(arg, "sys") + { + if (!urbdrc_set_subsystem(urbdrc, arg->Value)) + return ERROR_OUTOFMEMORY; + } + CommandLineSwitchDefault(arg) + { + } + CommandLineSwitchEnd(arg) + } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + return CHANNEL_RC_OK; +} + +BOOL add_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum, UINT16 idVendor, + UINT16 idProduct) +{ + size_t success = 0; + URBDRC_PLUGIN* urbdrc = NULL; + UINT32 mask = 0; + UINT32 regflags = 0; + + if (!idevman) + return FALSE; + + urbdrc = (URBDRC_PLUGIN*)idevman->plugin; + + if (!urbdrc || !urbdrc->listener_callback) + return FALSE; + + mask = (DEVICE_ADD_FLAG_VENDOR | DEVICE_ADD_FLAG_PRODUCT); + if ((flags & mask) == mask) + regflags |= UDEVMAN_FLAG_ADD_BY_VID_PID; + mask = (DEVICE_ADD_FLAG_BUS | DEVICE_ADD_FLAG_DEV); + if ((flags & mask) == mask) + regflags |= UDEVMAN_FLAG_ADD_BY_ADDR; + + success = idevman->register_udevice(idevman, busnum, devnum, idVendor, idProduct, regflags); + + if ((success > 0) && (flags & DEVICE_ADD_FLAG_REGISTER)) + { + if (!urbdrc_announce_devices(idevman)) + return FALSE; + } + + return TRUE; +} + +BOOL del_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum, UINT16 idVendor, + UINT16 idProduct) +{ + IUDEVICE* pdev = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + + if (!idevman) + return FALSE; + + urbdrc = (URBDRC_PLUGIN*)idevman->plugin; + + if (!urbdrc || !urbdrc->listener_callback) + return FALSE; + + idevman->loading_lock(idevman); + idevman->rewind(idevman); + + while (idevman->has_next(idevman)) + { + BOOL match = TRUE; + IUDEVICE* dev = idevman->get_next(idevman); + + if ((flags & (DEVICE_ADD_FLAG_BUS | DEVICE_ADD_FLAG_DEV | DEVICE_ADD_FLAG_VENDOR | + DEVICE_ADD_FLAG_PRODUCT)) == 0) + match = FALSE; + if (flags & DEVICE_ADD_FLAG_BUS) + { + if (dev->get_bus_number(dev) != busnum) + match = FALSE; + } + if (flags & DEVICE_ADD_FLAG_DEV) + { + if (dev->get_dev_number(dev) != devnum) + match = FALSE; + } + if (flags & DEVICE_ADD_FLAG_VENDOR) + { + int vid = dev->query_device_descriptor(dev, ID_VENDOR); + if (vid != idVendor) + match = FALSE; + } + if (flags & DEVICE_ADD_FLAG_PRODUCT) + { + int pid = dev->query_device_descriptor(dev, ID_PRODUCT); + if (pid != idProduct) + match = FALSE; + } + + if (match) + { + pdev = dev; + break; + } + } + + if (pdev) + pdev->setChannelClosed(pdev); + + idevman->loading_unlock(idevman); + return TRUE; +} + +/** + * Function description + * + * @return 0 on success, otherwise a Win32 error code + */ +FREERDP_ENTRY_POINT(UINT VCAPITYPE urbdrc_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)) +{ + UINT status = 0; + const ADDIN_ARGV* args = NULL; + URBDRC_PLUGIN* urbdrc = NULL; + urbdrc = (URBDRC_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, URBDRC_CHANNEL_NAME); + args = pEntryPoints->GetPluginData(pEntryPoints); + + if (urbdrc == NULL) + { + urbdrc = (URBDRC_PLUGIN*)calloc(1, sizeof(URBDRC_PLUGIN)); + + if (!urbdrc) + return CHANNEL_RC_NO_MEMORY; + + urbdrc->iface.Initialize = urbdrc_plugin_initialize; + urbdrc->iface.Terminated = urbdrc_plugin_terminated; + urbdrc->vchannel_status = INIT_CHANNEL_IN; + status = pEntryPoints->RegisterPlugin(pEntryPoints, URBDRC_CHANNEL_NAME, &urbdrc->iface); + + /* After we register the plugin free will be taken care of by dynamic channel */ + if (status != CHANNEL_RC_OK) + { + free(urbdrc); + goto fail; + } + + urbdrc->log = WLog_Get(TAG); + + if (!urbdrc->log) + goto fail; + } + + status = urbdrc_process_addin_args(urbdrc, args); + + if (status != CHANNEL_RC_OK) + goto fail; + + if (!urbdrc->subsystem && !urbdrc_set_subsystem(urbdrc, "libusb")) + goto fail; + + return urbdrc_load_udevman_addin(&urbdrc->iface, urbdrc->subsystem, args); +fail: + return status; +} + +UINT stream_write_and_free(IWTSPlugin* plugin, IWTSVirtualChannel* channel, wStream* out) +{ + URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)plugin; + + if (!out) + return ERROR_INVALID_PARAMETER; + + if (!channel || !out || !urbdrc) + { + Stream_Free(out, TRUE); + return ERROR_INVALID_PARAMETER; + } + + if (!channel->Write) + { + Stream_Free(out, TRUE); + return ERROR_INTERNAL_ERROR; + } + + urbdrc_dump_message(urbdrc->log, TRUE, TRUE, out); + const size_t len = Stream_GetPosition(out); + UINT rc = ERROR_INTERNAL_ERROR; + if (len <= UINT32_MAX) + rc = channel->Write(channel, (UINT32)len, Stream_Buffer(out), NULL); + Stream_Free(out, TRUE); + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/urbdrc_main.h b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/urbdrc_main.h new file mode 100644 index 0000000000000000000000000000000000000000..4eead9f2b510f85ea15f19cfdfcb7db6f6986427 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/client/urbdrc_main.h @@ -0,0 +1,225 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_URBDRC_CLIENT_MAIN_H +#define FREERDP_CHANNEL_URBDRC_CLIENT_MAIN_H + +#include +#include +#include + +#include + +#define DEVICE_HARDWARE_ID_SIZE 32 +#define DEVICE_COMPATIBILITY_ID_SIZE 36 +#define DEVICE_INSTANCE_STR_SIZE 37 +#define DEVICE_CONTAINER_STR_SIZE 39 + +#define TAG CHANNELS_TAG("urbdrc.client") +#ifdef WITH_DEBUG_DVC +#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__) +#else +#define DEBUG_DVC(...) \ + do \ + { \ + } while (0) +#endif + +typedef struct S_IUDEVICE IUDEVICE; +typedef struct S_IUDEVMAN IUDEVMAN; + +#define BASIC_DEV_STATE_DEFINED(_arg, _type) \ + _type (*get_##_arg)(IUDEVICE * pdev); \ + void (*set_##_arg)(IUDEVICE * pdev, _type _arg) + +#define BASIC_DEVMAN_STATE_DEFINED(_arg, _type) \ + _type (*get_##_arg)(IUDEVMAN * udevman); \ + void (*set_##_arg)(IUDEVMAN * udevman, _type _arg) + +typedef struct +{ + IWTSPlugin iface; + + GENERIC_LISTENER_CALLBACK* listener_callback; + + IUDEVMAN* udevman; + UINT32 vchannel_status; + char* subsystem; + + wLog* log; + IWTSListener* listener; + BOOL initialized; +} URBDRC_PLUGIN; + +typedef BOOL (*PREGISTERURBDRCSERVICE)(IWTSPlugin* plugin, IUDEVMAN* udevman); +typedef struct +{ + IWTSPlugin* plugin; + PREGISTERURBDRCSERVICE pRegisterUDEVMAN; + const ADDIN_ARGV* args; +} FREERDP_URBDRC_SERVICE_ENTRY_POINTS; +typedef FREERDP_URBDRC_SERVICE_ENTRY_POINTS* PFREERDP_URBDRC_SERVICE_ENTRY_POINTS; + +typedef UINT(VCAPITYPE* PFREERDP_URBDRC_DEVICE_ENTRY)( + PFREERDP_URBDRC_SERVICE_ENTRY_POINTS pEntryPoints); + +typedef struct +{ + GENERIC_CHANNEL_CALLBACK* callback; + URBDRC_PLUGIN* urbdrc; + IUDEVMAN* udevman; + IWTSVirtualChannel* channel; + wStream* s; +} TRANSFER_DATA; + +typedef void (*t_isoch_transfer_cb)(IUDEVICE* idev, GENERIC_CHANNEL_CALLBACK* callback, + wStream* out, UINT32 InterfaceId, BOOL noAck, UINT32 MessageId, + UINT32 RequestId, UINT32 NumberOfPackets, UINT32 status, + UINT32 StartFrame, UINT32 ErrorCount, UINT32 OutputBufferSize); + +struct S_IUDEVICE +{ + /* Transfer */ + int (*isoch_transfer)(IUDEVICE* idev, GENERIC_CHANNEL_CALLBACK* callback, UINT32 MessageId, + UINT32 RequestId, UINT32 EndpointAddress, UINT32 TransferFlags, + UINT32 StartFrame, UINT32 ErrorCount, BOOL NoAck, + const BYTE* packetDescriptorData, UINT32 NumberOfPackets, + UINT32 BufferSize, const BYTE* Buffer, t_isoch_transfer_cb cb, + UINT32 Timeout); + + BOOL(*control_transfer) + (IUDEVICE* idev, UINT32 RequestId, UINT32 EndpointAddress, UINT32 TransferFlags, + BYTE bmRequestType, BYTE Request, UINT16 Value, UINT16 Index, UINT32* UrbdStatus, + UINT32* BufferSize, BYTE* Buffer, UINT32 Timeout); + + int (*bulk_or_interrupt_transfer)(IUDEVICE* idev, GENERIC_CHANNEL_CALLBACK* callback, + UINT32 MessageId, UINT32 RequestId, UINT32 EndpointAddress, + UINT32 TransferFlags, BOOL NoAck, UINT32 BufferSize, + const BYTE* data, t_isoch_transfer_cb cb, UINT32 Timeout); + + int (*select_configuration)(IUDEVICE* idev, UINT32 bConfigurationValue); + + int (*select_interface)(IUDEVICE* idev, BYTE InterfaceNumber, BYTE AlternateSetting); + + int (*control_pipe_request)(IUDEVICE* idev, UINT32 RequestId, UINT32 EndpointAddress, + UINT32* UsbdStatus, int command); + + UINT32(*control_query_device_text) + (IUDEVICE* idev, UINT32 TextType, UINT16 LocaleId, UINT8* BufferSize, BYTE* Buffer); + + int (*os_feature_descriptor_request)(IUDEVICE* idev, UINT32 RequestId, BYTE Recipient, + BYTE InterfaceNumber, BYTE Ms_PageIndex, + UINT16 Ms_featureDescIndex, UINT32* UsbdStatus, + UINT32* BufferSize, BYTE* Buffer, UINT32 Timeout); + + void (*cancel_all_transfer_request)(IUDEVICE* idev); + + int (*cancel_transfer_request)(IUDEVICE* idev, UINT32 RequestId); + + int (*query_device_descriptor)(IUDEVICE* idev, int offset); + + BOOL (*detach_kernel_driver)(IUDEVICE* idev); + + BOOL (*attach_kernel_driver)(IUDEVICE* idev); + + int (*query_device_port_status)(IUDEVICE* idev, UINT32* UsbdStatus, UINT32* BufferSize, + BYTE* Buffer); + + MSUSB_CONFIG_DESCRIPTOR* (*complete_msconfig_setup)(IUDEVICE* idev, + MSUSB_CONFIG_DESCRIPTOR* MsConfig); + /* Basic state */ + int (*isCompositeDevice)(IUDEVICE* idev); + + int (*isExist)(IUDEVICE* idev); + int (*isAlreadySend)(IUDEVICE* idev); + int (*isChannelClosed)(IUDEVICE* idev); + + void (*setAlreadySend)(IUDEVICE* idev); + void (*setChannelClosed)(IUDEVICE* idev); + void (*markChannelClosed)(IUDEVICE* idev); + char* (*getPath)(IUDEVICE* idev); + + void (*free)(IUDEVICE* idev); + + BASIC_DEV_STATE_DEFINED(channelManager, IWTSVirtualChannelManager*); + BASIC_DEV_STATE_DEFINED(channelID, UINT32); + BASIC_DEV_STATE_DEFINED(UsbDevice, UINT32); + BASIC_DEV_STATE_DEFINED(ReqCompletion, UINT32); + BASIC_DEV_STATE_DEFINED(bus_number, BYTE); + BASIC_DEV_STATE_DEFINED(dev_number, BYTE); + BASIC_DEV_STATE_DEFINED(port_number, UINT8); + BASIC_DEV_STATE_DEFINED(MsConfig, MSUSB_CONFIG_DESCRIPTOR*); + + BASIC_DEV_STATE_DEFINED(p_udev, void*); + BASIC_DEV_STATE_DEFINED(p_prev, void*); + BASIC_DEV_STATE_DEFINED(p_next, void*); +}; + +struct S_IUDEVMAN +{ + /* Standard */ + void (*free)(IUDEVMAN* idevman); + + /* Manage devices */ + void (*rewind)(IUDEVMAN* idevman); + BOOL (*has_next)(IUDEVMAN* idevman); + BOOL (*unregister_udevice)(IUDEVMAN* idevman, BYTE bus_number, BYTE dev_number); + size_t (*register_udevice)(IUDEVMAN* idevman, BYTE bus_number, BYTE dev_number, UINT16 idVendor, + UINT16 idProduct, UINT32 flag); + IUDEVICE* (*get_next)(IUDEVMAN* idevman); + IUDEVICE* (*get_udevice_by_UsbDevice)(IUDEVMAN* idevman, UINT32 UsbDevice); + IUDEVICE* (*get_udevice_by_ChannelID)(IUDEVMAN* idevman, UINT32 channelID); + + /* Extension */ + int (*isAutoAdd)(IUDEVMAN* idevman); + + /* Basic state */ + BASIC_DEVMAN_STATE_DEFINED(device_num, UINT32); + BASIC_DEVMAN_STATE_DEFINED(next_device_id, UINT32); + + /* control semaphore or mutex lock */ + void (*loading_lock)(IUDEVMAN* idevman); + void (*loading_unlock)(IUDEVMAN* idevman); + BOOL (*initialize)(IUDEVMAN* idevman, UINT32 channelId); + UINT (*listener_created_callback)(IUDEVMAN* idevman); + + IWTSPlugin* plugin; + UINT32 controlChannelId; + UINT32 status; +}; + +#define DEVICE_ADD_FLAG_BUS 0x01 +#define DEVICE_ADD_FLAG_DEV 0x02 +#define DEVICE_ADD_FLAG_VENDOR 0x04 +#define DEVICE_ADD_FLAG_PRODUCT 0x08 +#define DEVICE_ADD_FLAG_REGISTER 0x10 + +#define DEVICE_ADD_FLAG_ALL \ + (DEVICE_ADD_FLAG_BUS | DEVICE_ADD_FLAG_DEV | DEVICE_ADD_FLAG_VENDOR | \ + DEVICE_ADD_FLAG_PRODUCT | DEVICE_ADD_FLAG_REGISTER) + +FREERDP_API BOOL add_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum, + UINT16 idVendor, UINT16 idProduct); +FREERDP_API BOOL del_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum, + UINT16 idVendor, UINT16 idProduct); + +UINT stream_write_and_free(IWTSPlugin* plugin, IWTSVirtualChannel* channel, wStream* out); + +#endif /* FREERDP_CHANNEL_URBDRC_CLIENT_MAIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..efe28060a5cb1b3d6a757c0b2dfc0ede0b44385f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/CMakeLists.txt @@ -0,0 +1,23 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2019 Armin Novak +# Copyright 2019 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(SRCS urbdrc_types.h urbdrc_helpers.h urbdrc_helpers.c msusb.h msusb.c) + +add_library(urbdrc-common STATIC ${SRCS}) + +channel_install(urbdrc-common ${FREERDP_ADDIN_PATH} "FreeRDPTargets") diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/msusb.c b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/msusb.c new file mode 100644 index 0000000000000000000000000000000000000000..9515e2bfdf6085420f9341c0331e641bd176e990 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/msusb.c @@ -0,0 +1,395 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include + +#define TAG FREERDP_TAG("utils") + +static MSUSB_PIPE_DESCRIPTOR* msusb_mspipe_new(void) +{ + return (MSUSB_PIPE_DESCRIPTOR*)calloc(1, sizeof(MSUSB_PIPE_DESCRIPTOR)); +} + +static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes, UINT32 NumberOfPipes) +{ + if (MsPipes) + { + for (UINT32 pnum = 0; pnum < NumberOfPipes && MsPipes[pnum]; pnum++) + free(MsPipes[pnum]); + + free((void*)MsPipes); + } +} + +BOOL msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, + MSUSB_PIPE_DESCRIPTOR** NewMsPipes, UINT32 NewNumberOfPipes) +{ + if (!MsInterface || !NewMsPipes) + return FALSE; + + /* free original MsPipes */ + msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes); + /* And replace it */ + MsInterface->MsPipes = NewMsPipes; + MsInterface->NumberOfPipes = NewNumberOfPipes; + return TRUE; +} + +static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(wStream* s, UINT32 NumberOfPipes) +{ + MSUSB_PIPE_DESCRIPTOR** MsPipes = NULL; + + if (!Stream_CheckAndLogRequiredCapacityOfSize(TAG, (s), NumberOfPipes, 12ull)) + return NULL; + + MsPipes = (MSUSB_PIPE_DESCRIPTOR**)calloc(NumberOfPipes, sizeof(MSUSB_PIPE_DESCRIPTOR*)); + + if (!MsPipes) + return NULL; + + for (UINT32 pnum = 0; pnum < NumberOfPipes; pnum++) + { + MSUSB_PIPE_DESCRIPTOR* MsPipe = msusb_mspipe_new(); + + if (!MsPipe) + goto out_error; + + Stream_Read_UINT16(s, MsPipe->MaximumPacketSize); + Stream_Seek(s, 2); + Stream_Read_UINT32(s, MsPipe->MaximumTransferSize); + Stream_Read_UINT32(s, MsPipe->PipeFlags); + /* Already set to zero by memset + MsPipe->PipeHandle = 0; + MsPipe->bEndpointAddress = 0; + MsPipe->bInterval = 0; + MsPipe->PipeType = 0; + MsPipe->InitCompleted = 0; + */ + MsPipes[pnum] = MsPipe; + } + + return MsPipes; +out_error: + + for (UINT32 pnum = 0; pnum < NumberOfPipes; pnum++) + free(MsPipes[pnum]); + + free((void*)MsPipes); + return NULL; +} + +static MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_new(void) +{ + return (MSUSB_INTERFACE_DESCRIPTOR*)calloc(1, sizeof(MSUSB_INTERFACE_DESCRIPTOR)); +} + +void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface) +{ + if (MsInterface) + { + msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes); + MsInterface->MsPipes = NULL; + free(MsInterface); + } +} + +static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces, + UINT32 NumInterfaces) +{ + if (MsInterfaces) + { + for (UINT32 inum = 0; inum < NumInterfaces; inum++) + { + msusb_msinterface_free(MsInterfaces[inum]); + } + + free((void*)MsInterfaces); + } +} + +BOOL msusb_msinterface_replace(MSUSB_CONFIG_DESCRIPTOR* MsConfig, BYTE InterfaceNumber, + MSUSB_INTERFACE_DESCRIPTOR* NewMsInterface) +{ + if (!MsConfig || !MsConfig->MsInterfaces) + return FALSE; + + msusb_msinterface_free(MsConfig->MsInterfaces[InterfaceNumber]); + MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface; + return TRUE; +} + +MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(wStream* s) +{ + MSUSB_INTERFACE_DESCRIPTOR* MsInterface = NULL; + + if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 12)) + return NULL; + + MsInterface = msusb_msinterface_new(); + + if (!MsInterface) + return NULL; + + Stream_Read_UINT16(s, MsInterface->Length); + Stream_Read_UINT16(s, MsInterface->NumberOfPipesExpected); + Stream_Read_UINT8(s, MsInterface->InterfaceNumber); + Stream_Read_UINT8(s, MsInterface->AlternateSetting); + Stream_Seek(s, 2); + Stream_Read_UINT32(s, MsInterface->NumberOfPipes); + MsInterface->InterfaceHandle = 0; + MsInterface->bInterfaceClass = 0; + MsInterface->bInterfaceSubClass = 0; + MsInterface->bInterfaceProtocol = 0; + MsInterface->InitCompleted = 0; + MsInterface->MsPipes = NULL; + + if (MsInterface->NumberOfPipes > 0) + { + MsInterface->MsPipes = msusb_mspipes_read(s, MsInterface->NumberOfPipes); + + if (!MsInterface->MsPipes) + goto out_error; + } + + return MsInterface; +out_error: + msusb_msinterface_free(MsInterface); + return NULL; +} + +BOOL msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, wStream* out) +{ + MSUSB_PIPE_DESCRIPTOR** MsPipes = NULL; + MSUSB_PIPE_DESCRIPTOR* MsPipe = NULL; + + if (!MsInterface) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(out, 16 + MsInterface->NumberOfPipes * 20)) + return FALSE; + + /* Length */ + Stream_Write_UINT16(out, MsInterface->Length); + /* InterfaceNumber */ + Stream_Write_UINT8(out, MsInterface->InterfaceNumber); + /* AlternateSetting */ + Stream_Write_UINT8(out, MsInterface->AlternateSetting); + /* bInterfaceClass */ + Stream_Write_UINT8(out, MsInterface->bInterfaceClass); + /* bInterfaceSubClass */ + Stream_Write_UINT8(out, MsInterface->bInterfaceSubClass); + /* bInterfaceProtocol */ + Stream_Write_UINT8(out, MsInterface->bInterfaceProtocol); + /* Padding */ + Stream_Write_UINT8(out, 0); + /* InterfaceHandle */ + Stream_Write_UINT32(out, MsInterface->InterfaceHandle); + /* NumberOfPipes */ + Stream_Write_UINT32(out, MsInterface->NumberOfPipes); + /* Pipes */ + MsPipes = MsInterface->MsPipes; + + for (UINT32 pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++) + { + MsPipe = MsPipes[pnum]; + /* MaximumPacketSize */ + Stream_Write_UINT16(out, MsPipe->MaximumPacketSize); + /* EndpointAddress */ + Stream_Write_UINT8(out, MsPipe->bEndpointAddress); + /* Interval */ + Stream_Write_UINT8(out, MsPipe->bInterval); + /* PipeType */ + Stream_Write_UINT32(out, MsPipe->PipeType); + /* PipeHandle */ + Stream_Write_UINT32(out, MsPipe->PipeHandle); + /* MaximumTransferSize */ + Stream_Write_UINT32(out, MsPipe->MaximumTransferSize); + /* PipeFlags */ + Stream_Write_UINT32(out, MsPipe->PipeFlags); + } + + return TRUE; +} + +static MSUSB_INTERFACE_DESCRIPTOR** msusb_msinterface_read_list(wStream* s, UINT32 NumInterfaces) +{ + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = NULL; + MsInterfaces = + (MSUSB_INTERFACE_DESCRIPTOR**)calloc(NumInterfaces, sizeof(MSUSB_INTERFACE_DESCRIPTOR*)); + + if (!MsInterfaces) + return NULL; + + for (UINT32 inum = 0; inum < NumInterfaces; inum++) + { + MsInterfaces[inum] = msusb_msinterface_read(s); + + if (!MsInterfaces[inum]) + goto fail; + } + + return MsInterfaces; +fail: + + for (UINT32 inum = 0; inum < NumInterfaces; inum++) + msusb_msinterface_free(MsInterfaces[inum]); + + free((void*)MsInterfaces); + return NULL; +} + +BOOL msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, wStream* out) +{ + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = NULL; + MSUSB_INTERFACE_DESCRIPTOR* MsInterface = NULL; + + if (!MsConfg) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(out, 8)) + return FALSE; + + /* ConfigurationHandle*/ + Stream_Write_UINT32(out, MsConfg->ConfigurationHandle); + /* NumInterfaces*/ + Stream_Write_UINT32(out, MsConfg->NumInterfaces); + /* Interfaces */ + MsInterfaces = MsConfg->MsInterfaces; + + for (UINT32 inum = 0; inum < MsConfg->NumInterfaces; inum++) + { + MsInterface = MsInterfaces[inum]; + + if (!msusb_msinterface_write(MsInterface, out)) + return FALSE; + } + + return TRUE; +} + +MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_new(void) +{ + return (MSUSB_CONFIG_DESCRIPTOR*)calloc(1, sizeof(MSUSB_CONFIG_DESCRIPTOR)); +} + +void msusb_msconfig_free(MSUSB_CONFIG_DESCRIPTOR* MsConfig) +{ + if (MsConfig) + { + msusb_msinterface_free_list(MsConfig->MsInterfaces, MsConfig->NumInterfaces); + MsConfig->MsInterfaces = NULL; + free(MsConfig); + } +} + +MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(wStream* s, UINT32 NumInterfaces) +{ + MSUSB_CONFIG_DESCRIPTOR* MsConfig = NULL; + BYTE lenConfiguration = 0; + BYTE typeConfiguration = 0; + + if (!Stream_CheckAndLogRequiredCapacityOfSize(TAG, (s), 3ULL + NumInterfaces, 2ULL)) + return NULL; + + MsConfig = msusb_msconfig_new(); + + if (!MsConfig) + goto fail; + + MsConfig->MsInterfaces = msusb_msinterface_read_list(s, NumInterfaces); + + if (!MsConfig->MsInterfaces) + goto fail; + + Stream_Read_UINT8(s, lenConfiguration); + Stream_Read_UINT8(s, typeConfiguration); + + if (lenConfiguration != 0x9 || typeConfiguration != 0x2) + { + WLog_ERR(TAG, "len and type must be 0x9 and 0x2 , but it is 0x%" PRIx8 " and 0x%" PRIx8 "", + lenConfiguration, typeConfiguration); + goto fail; + } + + Stream_Read_UINT16(s, MsConfig->wTotalLength); + Stream_Seek(s, 1); + Stream_Read_UINT8(s, MsConfig->bConfigurationValue); + MsConfig->NumInterfaces = NumInterfaces; + return MsConfig; +fail: + msusb_msconfig_free(MsConfig); + return NULL; +} + +void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig) +{ + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = NULL; + MSUSB_INTERFACE_DESCRIPTOR* MsInterface = NULL; + MSUSB_PIPE_DESCRIPTOR** MsPipes = NULL; + MSUSB_PIPE_DESCRIPTOR* MsPipe = NULL; + + WLog_INFO(TAG, "=================MsConfig:========================"); + WLog_INFO(TAG, "wTotalLength:%" PRIu16 "", MsConfig->wTotalLength); + WLog_INFO(TAG, "bConfigurationValue:%" PRIu8 "", MsConfig->bConfigurationValue); + WLog_INFO(TAG, "ConfigurationHandle:0x%08" PRIx32 "", MsConfig->ConfigurationHandle); + WLog_INFO(TAG, "InitCompleted:%d", MsConfig->InitCompleted); + WLog_INFO(TAG, "MsOutSize:%d", MsConfig->MsOutSize); + WLog_INFO(TAG, "NumInterfaces:%" PRIu32 "", MsConfig->NumInterfaces); + MsInterfaces = MsConfig->MsInterfaces; + + for (UINT32 inum = 0; inum < MsConfig->NumInterfaces; inum++) + { + MsInterface = MsInterfaces[inum]; + WLog_INFO(TAG, " Interface: %" PRIu8 "", MsInterface->InterfaceNumber); + WLog_INFO(TAG, " Length: %" PRIu16 "", MsInterface->Length); + WLog_INFO(TAG, " NumberOfPipesExpected: %" PRIu16 "", + MsInterface->NumberOfPipesExpected); + WLog_INFO(TAG, " AlternateSetting: %" PRIu8 "", MsInterface->AlternateSetting); + WLog_INFO(TAG, " NumberOfPipes: %" PRIu32 "", MsInterface->NumberOfPipes); + WLog_INFO(TAG, " InterfaceHandle: 0x%08" PRIx32 "", MsInterface->InterfaceHandle); + WLog_INFO(TAG, " bInterfaceClass: 0x%02" PRIx8 "", MsInterface->bInterfaceClass); + WLog_INFO(TAG, " bInterfaceSubClass: 0x%02" PRIx8 "", MsInterface->bInterfaceSubClass); + WLog_INFO(TAG, " bInterfaceProtocol: 0x%02" PRIx8 "", MsInterface->bInterfaceProtocol); + WLog_INFO(TAG, " InitCompleted: %d", MsInterface->InitCompleted); + MsPipes = MsInterface->MsPipes; + + for (UINT32 pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++) + { + MsPipe = MsPipes[pnum]; + WLog_INFO(TAG, " Pipe: %" PRIu32, pnum); + WLog_INFO(TAG, " MaximumPacketSize: 0x%04" PRIx16 "", MsPipe->MaximumPacketSize); + WLog_INFO(TAG, " MaximumTransferSize: 0x%08" PRIx32 "", + MsPipe->MaximumTransferSize); + WLog_INFO(TAG, " PipeFlags: 0x%08" PRIx32 "", MsPipe->PipeFlags); + WLog_INFO(TAG, " PipeHandle: 0x%08" PRIx32 "", MsPipe->PipeHandle); + WLog_INFO(TAG, " bEndpointAddress: 0x%02" PRIx8 "", MsPipe->bEndpointAddress); + WLog_INFO(TAG, " bInterval: %" PRIu8 "", MsPipe->bInterval); + WLog_INFO(TAG, " PipeType: 0x%02" PRIx8 "", MsPipe->PipeType); + WLog_INFO(TAG, " InitCompleted: %d", MsPipe->InitCompleted); + } + } + + WLog_INFO(TAG, "=================================================="); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/msusb.h b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/msusb.h new file mode 100644 index 0000000000000000000000000000000000000000..6ce843f836f7cd4d7adb5ff7ff5050259b2daeda --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/msusb.h @@ -0,0 +1,98 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_MSCONFIG_H +#define FREERDP_UTILS_MSCONFIG_H + +#include +#include + +typedef struct +{ + UINT16 MaximumPacketSize; + UINT32 MaximumTransferSize; + UINT32 PipeFlags; + UINT32 PipeHandle; + BYTE bEndpointAddress; + BYTE bInterval; + BYTE PipeType; + int InitCompleted; +} MSUSB_PIPE_DESCRIPTOR; + +typedef struct +{ + UINT16 Length; + UINT16 NumberOfPipesExpected; + BYTE InterfaceNumber; + BYTE AlternateSetting; + UINT32 NumberOfPipes; + UINT32 InterfaceHandle; + BYTE bInterfaceClass; + BYTE bInterfaceSubClass; + BYTE bInterfaceProtocol; + MSUSB_PIPE_DESCRIPTOR** MsPipes; + int InitCompleted; +} MSUSB_INTERFACE_DESCRIPTOR; + +typedef struct +{ + UINT16 wTotalLength; + BYTE bConfigurationValue; + UINT32 ConfigurationHandle; + UINT32 NumInterfaces; + MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces; + int InitCompleted; + int MsOutSize; +} MSUSB_CONFIG_DESCRIPTOR; + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* MSUSB_PIPE exported functions */ + FREERDP_API BOOL msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, + MSUSB_PIPE_DESCRIPTOR** NewMsPipes, + UINT32 NewNumberOfPipes); + + /* MSUSB_INTERFACE exported functions */ + FREERDP_API BOOL msusb_msinterface_replace(MSUSB_CONFIG_DESCRIPTOR* MsConfig, + BYTE InterfaceNumber, + MSUSB_INTERFACE_DESCRIPTOR* NewMsInterface); + FREERDP_API MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(wStream* out); + FREERDP_API BOOL msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, wStream* out); + FREERDP_API void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface); + + /* MSUSB_CONFIG exported functions */ + FREERDP_API void msusb_msconfig_free(MSUSB_CONFIG_DESCRIPTOR* MsConfig); + + WINPR_ATTR_MALLOC(msusb_msconfig_free, 1) + FREERDP_API MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_new(void); + + WINPR_ATTR_MALLOC(msusb_msconfig_free, 1) + FREERDP_API MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(wStream* s, UINT32 NumInterfaces); + FREERDP_API BOOL msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, wStream* out); + FREERDP_API void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfg); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_MSCONFIG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_helpers.c b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_helpers.c new file mode 100644 index 0000000000000000000000000000000000000000..9d6bb243144714513aa17067b86a3c71b567a638 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_helpers.c @@ -0,0 +1,425 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server USB redirection channel - helper functions + * + * Copyright 2019 Armin Novak + * Copyright 2019 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include "urbdrc_helpers.h" +#include "urbdrc_types.h" +#include + +const char* mask_to_string(UINT32 mask) +{ + switch (mask) + { + case STREAM_ID_NONE: + return "STREAM_ID_NONE"; + + case STREAM_ID_PROXY: + return "STREAM_ID_PROXY"; + + case STREAM_ID_STUB: + return "STREAM_ID_STUB"; + + default: + return "UNKNOWN"; + } +} +const char* interface_to_string(UINT32 id) +{ + switch (id) + { + case CAPABILITIES_NEGOTIATOR: + return "CAPABILITIES_NEGOTIATOR"; + + case SERVER_CHANNEL_NOTIFICATION: + return "SERVER_CHANNEL_NOTIFICATION"; + + case CLIENT_CHANNEL_NOTIFICATION: + return "CLIENT_CHANNEL_NOTIFICATION"; + + default: + return "DEVICE_MESSAGE"; + } +} + +static const char* call_to_string_none(BOOL client, UINT32 interfaceId, UINT32 functionId) +{ + WINPR_UNUSED(interfaceId); + + if (client) + return "RIM_EXCHANGE_CAPABILITY_RESPONSE [none |client]"; + else + { + switch (functionId) + { + case RIM_EXCHANGE_CAPABILITY_REQUEST: + return "RIM_EXCHANGE_CAPABILITY_REQUEST [none |server]"; + + case RIMCALL_RELEASE: + return "RIMCALL_RELEASE [none |server]"; + + case RIMCALL_QUERYINTERFACE: + return "RIMCALL_QUERYINTERFACE [none |server]"; + + default: + return "UNKNOWN [none |server]"; + } + } +} + +static const char* call_to_string_proxy_server(UINT32 functionId) +{ + switch (functionId) + { + case QUERY_DEVICE_TEXT: + return "QUERY_DEVICE_TEXT [proxy|server]"; + + case INTERNAL_IO_CONTROL: + return "INTERNAL_IO_CONTROL [proxy|server]"; + + case IO_CONTROL: + return "IO_CONTROL [proxy|server]"; + + case REGISTER_REQUEST_CALLBACK: + return "REGISTER_REQUEST_CALLBACK [proxy|server]"; + + case CANCEL_REQUEST: + return "CANCEL_REQUEST [proxy|server]"; + + case RETRACT_DEVICE: + return "RETRACT_DEVICE [proxy|server]"; + + case TRANSFER_IN_REQUEST: + return "TRANSFER_IN_REQUEST [proxy|server]"; + + case TRANSFER_OUT_REQUEST: + return "TRANSFER_OUT_REQUEST [proxy|server]"; + + default: + return "UNKNOWN [proxy|server]"; + } +} + +static const char* call_to_string_proxy_client(UINT32 functionId) +{ + switch (functionId) + { + case URB_COMPLETION_NO_DATA: + return "URB_COMPLETION_NO_DATA [proxy|client]"; + + case URB_COMPLETION: + return "URB_COMPLETION [proxy|client]"; + + case IOCONTROL_COMPLETION: + return "IOCONTROL_COMPLETION [proxy|client]"; + + case TRANSFER_OUT_REQUEST: + return "TRANSFER_OUT_REQUEST [proxy|client]"; + + default: + return "UNKNOWN [proxy|client]"; + } +} + +static const char* call_to_string_proxy(BOOL client, UINT32 interfaceId, UINT32 functionId) +{ + switch (interfaceId & INTERFACE_ID_MASK) + { + case CLIENT_DEVICE_SINK: + switch (functionId) + { + case ADD_VIRTUAL_CHANNEL: + return "ADD_VIRTUAL_CHANNEL [proxy|sink ]"; + + case ADD_DEVICE: + return "ADD_DEVICE [proxy|sink ]"; + case RIMCALL_RELEASE: + return "RIMCALL_RELEASE [proxy|sink ]"; + + case RIMCALL_QUERYINTERFACE: + return "RIMCALL_QUERYINTERFACE [proxy|sink ]"; + default: + return "UNKNOWN [proxy|sink ]"; + } + + case SERVER_CHANNEL_NOTIFICATION: + switch (functionId) + { + case CHANNEL_CREATED: + return "CHANNEL_CREATED [proxy|server]"; + + case RIMCALL_RELEASE: + return "RIMCALL_RELEASE [proxy|server]"; + + case RIMCALL_QUERYINTERFACE: + return "RIMCALL_QUERYINTERFACE [proxy|server]"; + + default: + return "UNKNOWN [proxy|server]"; + } + + case CLIENT_CHANNEL_NOTIFICATION: + switch (functionId) + { + case CHANNEL_CREATED: + return "CHANNEL_CREATED [proxy|client]"; + case RIMCALL_RELEASE: + return "RIMCALL_RELEASE [proxy|client]"; + case RIMCALL_QUERYINTERFACE: + return "RIMCALL_QUERYINTERFACE [proxy|client]"; + default: + return "UNKNOWN [proxy|client]"; + } + + default: + if (client) + return call_to_string_proxy_client(functionId); + else + return call_to_string_proxy_server(functionId); + } +} + +static const char* call_to_string_stub(BOOL client, UINT32 interfaceNr, UINT32 functionId) +{ + return "QUERY_DEVICE_TEXT_RSP [stub |client]"; +} + +const char* call_to_string(BOOL client, UINT32 interfaceNr, UINT32 functionId) +{ + const UINT32 mask = (interfaceNr & STREAM_ID_MASK) >> 30; + const UINT32 interfaceId = interfaceNr & INTERFACE_ID_MASK; + + switch (mask) + { + case STREAM_ID_NONE: + return call_to_string_none(client, interfaceId, functionId); + + case STREAM_ID_PROXY: + return call_to_string_proxy(client, interfaceId, functionId); + + case STREAM_ID_STUB: + return call_to_string_stub(client, interfaceId, functionId); + + default: + return "UNKNOWN[mask]"; + } +} + +const char* urb_function_string(UINT16 urb) +{ + switch (urb) + { + case TS_URB_SELECT_CONFIGURATION: + return "TS_URB_SELECT_CONFIGURATION"; + + case TS_URB_SELECT_INTERFACE: + return "TS_URB_SELECT_INTERFACE"; + + case TS_URB_PIPE_REQUEST: + return "TS_URB_PIPE_REQUEST"; + + case TS_URB_TAKE_FRAME_LENGTH_CONTROL: + return "TS_URB_TAKE_FRAME_LENGTH_CONTROL"; + + case TS_URB_RELEASE_FRAME_LENGTH_CONTROL: + return "TS_URB_RELEASE_FRAME_LENGTH_CONTROL"; + + case TS_URB_GET_FRAME_LENGTH: + return "TS_URB_GET_FRAME_LENGTH"; + + case TS_URB_SET_FRAME_LENGTH: + return "TS_URB_SET_FRAME_LENGTH"; + + case TS_URB_GET_CURRENT_FRAME_NUMBER: + return "TS_URB_GET_CURRENT_FRAME_NUMBER"; + + case TS_URB_CONTROL_TRANSFER: + return "TS_URB_CONTROL_TRANSFER"; + + case TS_URB_BULK_OR_INTERRUPT_TRANSFER: + return "TS_URB_BULK_OR_INTERRUPT_TRANSFER"; + + case TS_URB_ISOCH_TRANSFER: + return "TS_URB_ISOCH_TRANSFER"; + + case TS_URB_GET_DESCRIPTOR_FROM_DEVICE: + return "TS_URB_GET_DESCRIPTOR_FROM_DEVICE"; + + case TS_URB_SET_DESCRIPTOR_TO_DEVICE: + return "TS_URB_SET_DESCRIPTOR_TO_DEVICE"; + + case TS_URB_SET_FEATURE_TO_DEVICE: + return "TS_URB_SET_FEATURE_TO_DEVICE"; + + case TS_URB_SET_FEATURE_TO_INTERFACE: + return "TS_URB_SET_FEATURE_TO_INTERFACE"; + + case TS_URB_SET_FEATURE_TO_ENDPOINT: + return "TS_URB_SET_FEATURE_TO_ENDPOINT"; + + case TS_URB_CLEAR_FEATURE_TO_DEVICE: + return "TS_URB_CLEAR_FEATURE_TO_DEVICE"; + + case TS_URB_CLEAR_FEATURE_TO_INTERFACE: + return "TS_URB_CLEAR_FEATURE_TO_INTERFACE"; + + case TS_URB_CLEAR_FEATURE_TO_ENDPOINT: + return "TS_URB_CLEAR_FEATURE_TO_ENDPOINT"; + + case TS_URB_GET_STATUS_FROM_DEVICE: + return "TS_URB_GET_STATUS_FROM_DEVICE"; + + case TS_URB_GET_STATUS_FROM_INTERFACE: + return "TS_URB_GET_STATUS_FROM_INTERFACE"; + + case TS_URB_GET_STATUS_FROM_ENDPOINT: + return "TS_URB_GET_STATUS_FROM_ENDPOINT"; + + case TS_URB_RESERVED_0X0016: + return "TS_URB_RESERVED_0X0016"; + + case TS_URB_VENDOR_DEVICE: + return "TS_URB_VENDOR_DEVICE"; + + case TS_URB_VENDOR_INTERFACE: + return "TS_URB_VENDOR_INTERFACE"; + + case TS_URB_VENDOR_ENDPOINT: + return "TS_URB_VENDOR_ENDPOINT"; + + case TS_URB_CLASS_DEVICE: + return "TS_URB_CLASS_DEVICE"; + + case TS_URB_CLASS_INTERFACE: + return "TS_URB_CLASS_INTERFACE"; + + case TS_URB_CLASS_ENDPOINT: + return "TS_URB_CLASS_ENDPOINT"; + + case TS_URB_RESERVE_0X001D: + return "TS_URB_RESERVE_0X001D"; + + case TS_URB_SYNC_RESET_PIPE_AND_CLEAR_STALL: + return "TS_URB_SYNC_RESET_PIPE_AND_CLEAR_STALL"; + + case TS_URB_CLASS_OTHER: + return "TS_URB_CLASS_OTHER"; + + case TS_URB_VENDOR_OTHER: + return "TS_URB_VENDOR_OTHER"; + + case TS_URB_GET_STATUS_FROM_OTHER: + return "TS_URB_GET_STATUS_FROM_OTHER"; + + case TS_URB_CLEAR_FEATURE_TO_OTHER: + return "TS_URB_CLEAR_FEATURE_TO_OTHER"; + + case TS_URB_SET_FEATURE_TO_OTHER: + return "TS_URB_SET_FEATURE_TO_OTHER"; + + case TS_URB_GET_DESCRIPTOR_FROM_ENDPOINT: + return "TS_URB_GET_DESCRIPTOR_FROM_ENDPOINT"; + + case TS_URB_SET_DESCRIPTOR_TO_ENDPOINT: + return "TS_URB_SET_DESCRIPTOR_TO_ENDPOINT"; + + case TS_URB_CONTROL_GET_CONFIGURATION_REQUEST: + return "TS_URB_CONTROL_GET_CONFIGURATION_REQUEST"; + + case TS_URB_CONTROL_GET_INTERFACE_REQUEST: + return "TS_URB_CONTROL_GET_INTERFACE_REQUEST"; + + case TS_URB_GET_DESCRIPTOR_FROM_INTERFACE: + return "TS_URB_GET_DESCRIPTOR_FROM_INTERFACE"; + + case TS_URB_SET_DESCRIPTOR_TO_INTERFACE: + return "TS_URB_SET_DESCRIPTOR_TO_INTERFACE"; + + case TS_URB_GET_OS_FEATURE_DESCRIPTOR_REQUEST: + return "TS_URB_GET_OS_FEATURE_DESCRIPTOR_REQUEST"; + + case TS_URB_RESERVE_0X002B: + return "TS_URB_RESERVE_0X002B"; + + case TS_URB_RESERVE_0X002C: + return "TS_URB_RESERVE_0X002C"; + + case TS_URB_RESERVE_0X002D: + return "TS_URB_RESERVE_0X002D"; + + case TS_URB_RESERVE_0X002E: + return "TS_URB_RESERVE_0X002E"; + + case TS_URB_RESERVE_0X002F: + return "TS_URB_RESERVE_0X002F"; + + case TS_URB_SYNC_RESET_PIPE: + return "TS_URB_SYNC_RESET_PIPE"; + + case TS_URB_SYNC_CLEAR_STALL: + return "TS_URB_SYNC_CLEAR_STALL"; + + case TS_URB_CONTROL_TRANSFER_EX: + return "TS_URB_CONTROL_TRANSFER_EX"; + + default: + return "UNKNOWN"; + } +} + +void urbdrc_dump_message(wLog* log, BOOL client, BOOL write, wStream* s) +{ + const char* type = write ? "WRITE" : "READ"; + UINT32 InterfaceId = 0; + UINT32 MessageId = 0; + UINT32 FunctionId = 0; + size_t length = 0; + size_t pos = 0; + + pos = Stream_GetPosition(s); + if (write) + { + length = pos; + Stream_SetPosition(s, 0); + } + else + length = Stream_GetRemainingLength(s); + + if (length < 12) + return; + + Stream_Read_UINT32(s, InterfaceId); + Stream_Read_UINT32(s, MessageId); + Stream_Read_UINT32(s, FunctionId); + Stream_SetPosition(s, pos); + + WLog_Print(log, WLOG_DEBUG, + "[%-5s] %s [%08" PRIx32 "] InterfaceId=%08" PRIx32 ", MessageId=%08" PRIx32 + ", FunctionId=%08" PRIx32 ", length=%" PRIuz, + type, call_to_string(client, InterfaceId, FunctionId), FunctionId, InterfaceId, + MessageId, FunctionId, length); +#if defined(WITH_DEBUG_URBDRC) + if (write) + WLog_Print(log, WLOG_TRACE, "-------------------------- URBDRC sent: ---"); + else + WLog_Print(log, WLOG_TRACE, "-------------------------- URBDRC received:"); + winpr_HexLogDump(log, WLOG_TRACE, Stream_Buffer(s), length); + WLog_Print(log, WLOG_TRACE, "-------------------------- URBDRC end -----"); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_helpers.h b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_helpers.h new file mode 100644 index 0000000000000000000000000000000000000000..d766ac55efbd0ef6fcae0ef4518817ef6c4646f4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_helpers.h @@ -0,0 +1,45 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server USB redirection channel - helper functions + * + * Copyright 2019 Armin Novak + * Copyright 2019 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_URBDRC_HELPERS_H +#define FREERDP_CHANNEL_URBDRC_HELPERS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include + + const char* urb_function_string(UINT16 urb); + const char* mask_to_string(UINT32 mask); + const char* interface_to_string(UINT32 id); + const char* call_to_string(BOOL client, UINT32 interfaceNr, UINT32 functionId); + + void urbdrc_dump_message(wLog* log, BOOL client, BOOL write, wStream* s); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_URBDRC_HELPERS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_types.h b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_types.h new file mode 100644 index 0000000000000000000000000000000000000000..a3deaf1952c14cc3d53e210a1557df2422e8808d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/urbdrc/common/urbdrc_types.h @@ -0,0 +1,306 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX USB Redirection + * + * Copyright 2012 Atrust corp. + * Copyright 2012 Alfred Liu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_URBDRC_CLIENT_TYPES_H +#define FREERDP_CHANNEL_URBDRC_CLIENT_TYPES_H + +#include + +#include +#include + +#include + +#include + +#define RIM_CAPABILITY_VERSION_01 0x00000001 + +#define CAPABILITIES_NEGOTIATOR 0x00000000 +#define CLIENT_DEVICE_SINK 0x00000001 +#define SERVER_CHANNEL_NOTIFICATION 0x00000002 +#define CLIENT_CHANNEL_NOTIFICATION 0x00000003 +#define BASE_USBDEVICE_NUM 0x00000005 + +#define RIMCALL_RELEASE 0x00000001 +#define RIMCALL_QUERYINTERFACE 0x00000002 +#define RIM_EXCHANGE_CAPABILITY_REQUEST 0x00000100 +#define CHANNEL_CREATED 0x00000100 +#define ADD_VIRTUAL_CHANNEL 0x00000100 +#define ADD_DEVICE 0x00000101 + +#define INIT_CHANNEL_IN 1 +#define INIT_CHANNEL_OUT 0 + +/* InterfaceClass */ +#define CLASS_RESERVE 0x00 +#define CLASS_AUDIO 0x01 +#define CLASS_COMMUNICATION_IF 0x02 +#define CLASS_HID 0x03 +#define CLASS_PHYSICAL 0x05 +#define CLASS_IMAGE 0x06 +#define CLASS_PRINTER 0x07 +#define CLASS_MASS_STORAGE 0x08 +#define CLASS_HUB 0x09 +#define CLASS_COMMUNICATION_DATA_IF 0x0a +#define CLASS_SMART_CARD 0x0b +#define CLASS_CONTENT_SECURITY 0x0d +#define CLASS_VIDEO 0x0e +#define CLASS_PERSONAL_HEALTHCARE 0x0f +#define CLASS_DIAGNOSTIC 0xdc +#define CLASS_WIRELESS_CONTROLLER 0xe0 +#define CLASS_ELSE_DEVICE 0xef +#define CLASS_DEPENDENCE 0xfe +#define CLASS_VENDOR_DEPENDENCE 0xff + +/* usb version */ +#define USB_v1_0 0x100 +#define USB_v1_1 0x110 +#define USB_v2_0 0x200 +#define USB_v3_0 0x300 + +#define STREAM_ID_NONE 0x0UL +#define STREAM_ID_PROXY 0x1UL +#define STREAM_ID_STUB 0x2UL +#define STREAM_ID_MASK 0xC0000000 +#define INTERFACE_ID_MASK 0x3FFFFFFF + +#define CANCEL_REQUEST 0x00000100 +#define REGISTER_REQUEST_CALLBACK 0x00000101 +#define IO_CONTROL 0x00000102 +#define INTERNAL_IO_CONTROL 0x00000103 +#define QUERY_DEVICE_TEXT 0x00000104 + +#define TRANSFER_IN_REQUEST 0x00000105 +#define TRANSFER_OUT_REQUEST 0x00000106 +#define RETRACT_DEVICE 0x00000107 + +#define IOCONTROL_COMPLETION 0x00000100 +#define URB_COMPLETION 0x00000101 +#define URB_COMPLETION_NO_DATA 0x00000102 + +/* The USB device is to be stopped from being redirected because the + * device is blocked by the server's policy. */ +#define UsbRetractReason_BlockedByPolicy 0x00000001 + +enum device_text_type +{ + DeviceTextDescription = 0, + DeviceTextLocationInformation = 1, +}; + +enum device_descriptor_table +{ + B_LENGTH = 0, + B_DESCRIPTOR_TYPE = 1, + BCD_USB = 2, + B_DEVICE_CLASS = 4, + B_DEVICE_SUBCLASS = 5, + B_DEVICE_PROTOCOL = 6, + B_MAX_PACKET_SIZE0 = 7, + ID_VENDOR = 8, + ID_PRODUCT = 10, + BCD_DEVICE = 12, + I_MANUFACTURER = 14, + I_PRODUCT = 15, + I_SERIAL_NUMBER = 16, + B_NUM_CONFIGURATIONS = 17 +}; + +#define PIPE_CANCEL 0 +#define PIPE_RESET 1 + +#define IOCTL_INTERNAL_USB_SUBMIT_URB 0x00220003 +#define IOCTL_INTERNAL_USB_RESET_PORT 0x00220007 +#define IOCTL_INTERNAL_USB_GET_PORT_STATUS 0x00220013 +#define IOCTL_INTERNAL_USB_CYCLE_PORT 0x0022001F +#define IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION 0x00220027 + +#define TS_URB_SELECT_CONFIGURATION 0x0000 +#define TS_URB_SELECT_INTERFACE 0x0001 +#define TS_URB_PIPE_REQUEST 0x0002 +#define TS_URB_TAKE_FRAME_LENGTH_CONTROL 0x0003 +#define TS_URB_RELEASE_FRAME_LENGTH_CONTROL 0x0004 +#define TS_URB_GET_FRAME_LENGTH 0x0005 +#define TS_URB_SET_FRAME_LENGTH 0x0006 +#define TS_URB_GET_CURRENT_FRAME_NUMBER 0x0007 +#define TS_URB_CONTROL_TRANSFER 0x0008 +#define TS_URB_BULK_OR_INTERRUPT_TRANSFER 0x0009 +#define TS_URB_ISOCH_TRANSFER 0x000A +#define TS_URB_GET_DESCRIPTOR_FROM_DEVICE 0x000B +#define TS_URB_SET_DESCRIPTOR_TO_DEVICE 0x000C +#define TS_URB_SET_FEATURE_TO_DEVICE 0x000D +#define TS_URB_SET_FEATURE_TO_INTERFACE 0x000E +#define TS_URB_SET_FEATURE_TO_ENDPOINT 0x000F +#define TS_URB_CLEAR_FEATURE_TO_DEVICE 0x0010 +#define TS_URB_CLEAR_FEATURE_TO_INTERFACE 0x0011 +#define TS_URB_CLEAR_FEATURE_TO_ENDPOINT 0x0012 +#define TS_URB_GET_STATUS_FROM_DEVICE 0x0013 +#define TS_URB_GET_STATUS_FROM_INTERFACE 0x0014 +#define TS_URB_GET_STATUS_FROM_ENDPOINT 0x0015 +#define TS_URB_RESERVED_0X0016 0x0016 +#define TS_URB_VENDOR_DEVICE 0x0017 +#define TS_URB_VENDOR_INTERFACE 0x0018 +#define TS_URB_VENDOR_ENDPOINT 0x0019 +#define TS_URB_CLASS_DEVICE 0x001A +#define TS_URB_CLASS_INTERFACE 0x001B +#define TS_URB_CLASS_ENDPOINT 0x001C +#define TS_URB_RESERVE_0X001D 0x001D +#define TS_URB_SYNC_RESET_PIPE_AND_CLEAR_STALL 0x001E +#define TS_URB_CLASS_OTHER 0x001F +#define TS_URB_VENDOR_OTHER 0x0020 +#define TS_URB_GET_STATUS_FROM_OTHER 0x0021 +#define TS_URB_CLEAR_FEATURE_TO_OTHER 0x0022 +#define TS_URB_SET_FEATURE_TO_OTHER 0x0023 +#define TS_URB_GET_DESCRIPTOR_FROM_ENDPOINT 0x0024 +#define TS_URB_SET_DESCRIPTOR_TO_ENDPOINT 0x0025 +#define TS_URB_CONTROL_GET_CONFIGURATION_REQUEST 0x0026 +#define TS_URB_CONTROL_GET_INTERFACE_REQUEST 0x0027 +#define TS_URB_GET_DESCRIPTOR_FROM_INTERFACE 0x0028 +#define TS_URB_SET_DESCRIPTOR_TO_INTERFACE 0x0029 +#define TS_URB_GET_OS_FEATURE_DESCRIPTOR_REQUEST 0x002A +#define TS_URB_RESERVE_0X002B 0x002B +#define TS_URB_RESERVE_0X002C 0x002C +#define TS_URB_RESERVE_0X002D 0x002D +#define TS_URB_RESERVE_0X002E 0x002E +#define TS_URB_RESERVE_0X002F 0x002F +// USB 2.0 calls start at 0x0030 +#define TS_URB_SYNC_RESET_PIPE 0x0030 +#define TS_URB_SYNC_CLEAR_STALL 0x0031 +#define TS_URB_CONTROL_TRANSFER_EX 0x0032 + +#define USBD_STATUS_SUCCESS 0x0 +#define USBD_STATUS_PENDING 0x40000000 +#define USBD_STATUS_CANCELED 0xC0010000 + +#define USBD_STATUS_INVALID_URB_FUNCTION 0x80000200 +#define USBD_STATUS_CRC 0xC0000001 +#define USBD_STATUS_BTSTUFF 0xC0000002 +#define USBD_STATUS_DATA_TOGGLE_MISMATCH 0xC0000003 +#define USBD_STATUS_STALL_PID 0xC0000004 +#define USBD_STATUS_DEV_NOT_RESPONDING 0xC0000005 +#define USBD_STATUS_PID_CHECK_FAILURE 0xC0000006 +#define USBD_STATUS_UNEXPECTED_PID 0xC0000007 +#define USBD_STATUS_DATA_OVERRUN 0xC0000008 +#define USBD_STATUS_DATA_UNDERRUN 0xC0000009 +#define USBD_STATUS_RESERVED1 0xC000000A +#define USBD_STATUS_RESERVED2 0xC000000B +#define USBD_STATUS_BUFFER_OVERRUN 0xC000000C +#define USBD_STATUS_BUFFER_UNDERRUN 0xC000000D + +/* unknown */ +#define USBD_STATUS_NO_DATA 0xC000000E + +#define USBD_STATUS_NOT_ACCESSED 0xC000000F +#define USBD_STATUS_FIFO 0xC0000010 +#define USBD_STATUS_XACT_ERROR 0xC0000011 +#define USBD_STATUS_BABBLE_DETECTED 0xC0000012 +#define USBD_STATUS_DATA_BUFFER_ERROR 0xC0000013 + +#define USBD_STATUS_NOT_SUPPORTED 0xC0000E00 +#define USBD_STATUS_BUFFER_TOO_SMALL 0xC0003000 +#define USBD_STATUS_TIMEOUT 0xC0006000 +#define USBD_STATUS_DEVICE_GONE 0xC0007000 + +#define USBD_STATUS_NO_MEMORY 0x80000100 +#define USBD_STATUS_INVALID_URB_FUNCTION 0x80000200 +#define USBD_STATUS_INVALID_PARAMETER 0x80000300 +#define USBD_STATUS_REQUEST_FAILED 0x80000500 +#define USBD_STATUS_INVALID_PIPE_HANDLE 0x80000600 +#define USBD_STATUS_ERROR_SHORT_TRANSFER 0x80000900 + +// Values for URB TransferFlags Field +// + +/* + Set if data moves device->host +*/ +#define USBD_TRANSFER_DIRECTION 0x00000001 +/* + This bit if not set indicates that a short packet, and hence, + a short transfer is an error condition +*/ +#define USBD_SHORT_TRANSFER_OK 0x00000002 +/* + Subit the iso transfer on the next frame +*/ +#define USBD_START_ISO_TRANSFER_ASAP 0x00000004 +#define USBD_DEFAULT_PIPE_TRANSFER 0x00000008 + +#define USBD_TRANSFER_DIRECTION_FLAG(flags) ((flags)&USBD_TRANSFER_DIRECTION) + +#define USBD_TRANSFER_DIRECTION_OUT 0 +#define USBD_TRANSFER_DIRECTION_IN 1 + +#define VALID_TRANSFER_FLAGS_MASK USBD_SHORT_TRANSFER_OK | \ + USBD_TRANSFER_DIRECTION | \ + USBD_START_ISO_TRANSFER_ASAP | \ + USBD_DEFAULT_PIPE_TRANSFER) + +#define ENDPOINT_HALT 0x00 +#define DEVICE_REMOTE_WAKEUP 0x01 + +/* transfer type */ +#define CONTROL_TRANSFER 0x00 +#define ISOCHRONOUS_TRANSFER 0x01 +#define BULK_TRANSFER 0x02 +#define INTERRUPT_TRANSFER 0x03 + +#define ClearHubFeature (0x2000 | LIBUSB_REQUEST_CLEAR_FEATURE) +#define ClearPortFeature (0x2300 | LIBUSB_REQUEST_CLEAR_FEATURE) +#define GetHubDescriptor (0xa000 | LIBUSB_REQUEST_GET_DESCRIPTOR) +#define GetHubStatus (0xa000 | LIBUSB_REQUEST_GET_STATUS) +#define GetPortStatus (0xa300 | LIBUSB_REQUEST_GET_STATUS) +#define SetHubFeature (0x2000 | LIBUSB_REQUEST_SET_FEATURE) +#define SetPortFeature (0x2300 | LIBUSB_REQUEST_SET_FEATURE) + +#define USBD_PF_CHANGE_MAX_PACKET 0x00000001 +#define USBD_PF_SHORT_PACKET_OPT 0x00000002 +#define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004 +#define USBD_PF_MAP_ADD_TRANSFERS 0x00000008 + +/* feature request */ +#define URB_SET_FEATURE 0x00 +#define URB_CLEAR_FEATURE 0x01 + +#define USBD_PF_CHANGE_MAX_PACKET 0x00000001 +#define USBD_PF_SHORT_PACKET_OPT 0x00000002 +#define USBD_PF_ENABLE_RT_THREAD_ACCESS 0x00000004 +#define USBD_PF_MAP_ADD_TRANSFERS 0x00000008 + +#define URB_CONTROL_TRANSFER_EXTERNAL 0x1 +#define URB_CONTROL_TRANSFER_NONEXTERNAL 0x0 + +#define USBFS_URB_SHORT_NOT_OK 0x01 +#define USBFS_URB_ISO_ASAP 0x02 +#define USBFS_URB_BULK_CONTINUATION 0x04 +#define USBFS_URB_QUEUE_BULK 0x10 + +#define URBDRC_DEVICE_INITIALIZED 0x01 +#define URBDRC_DEVICE_NOT_FOUND 0x02 +#define URBDRC_DEVICE_CHANNEL_CLOSED 0x08 +#define URBDRC_DEVICE_ALREADY_SEND 0x10 +#define URBDRC_DEVICE_DETACH_KERNEL 0x20 + +#define UDEVMAN_FLAG_ADD_BY_VID_PID 0x01 +#define UDEVMAN_FLAG_ADD_BY_ADDR 0x02 +#define UDEVMAN_FLAG_ADD_BY_AUTO 0x04 +#define UDEVMAN_FLAG_DEBUG 0x08 + +#endif /* FREERDP_CHANNEL_URBDRC_CLIENT_TYPES_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/video/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/channels/video/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..389a884aeec94784973d530cf47c39f3a41f792c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/video/CMakeLists.txt @@ -0,0 +1,22 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2017 David Fort +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("video") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/channels/video/ChannelOptions.cmake b/local-test-freerdp-delta-01/afc-freerdp/channels/video/ChannelOptions.cmake new file mode 100644 index 0000000000000000000000000000000000000000..c477a741ede9c6cdacee1b6884bfef01fb1721b6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/channels/video/ChannelOptions.cmake @@ -0,0 +1,20 @@ +set(OPTION_DEFAULT ON) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options( + NAME + "video" + TYPE + "dynamic" + DESCRIPTION + "Video optimized remoting Virtual Channel Extension" + SPECIFICATIONS + "[MS-RDPEVOR]" + DEFAULT + ${OPTION_DEFAULT} + CLIENT_DEFAULT + ${OPTION_CLIENT_DEFAULT} + SERVER_DEFAULT + ${OPTION_SERVER_DEFAULT} +) diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/config/build-config.h.in b/local-test-freerdp-delta-01/afc-freerdp/include/config/build-config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..5df41112d1e7f28e4c6c4a467768285d15e4fe0b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/config/build-config.h.in @@ -0,0 +1,22 @@ +#ifndef FREERDP_BUILD_CONFIG_H +#define FREERDP_BUILD_CONFIG_H + +#define FREERDP_DATA_PATH "${NATIVE_FREERDP_DATA_PATH}" +#define FREERDP_KEYMAP_PATH "${NATIVE_FREERDP_KEYMAP_PATH}" +#define FREERDP_PLUGIN_PATH "${NATIVE_FREERDP_PLUGIN_PATH}" + +#define FREERDP_INSTALL_PREFIX "${NATIVE_FREERDP_INSTALL_PREFIX}" + +#define FREERDP_LIBRARY_PATH "${NATIVE_FREERDP_LIBRARY_PATH}" + +#define FREERDP_ADDIN_PATH "${NATIVE_FREERDP_ADDIN_PATH}" + +#define FREERDP_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" +#define FREERDP_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}" + +#define FREERDP_VENDOR_STRING "${VENDOR}" /** @since version 3.3.0 */ +#define FREERDP_PRODUCT_STRING "${PRODUCT}" /** @since version 3.3.0 */ + +#define FREERDP_PROXY_PLUGINDIR "${NATIVE_FREERDP_PROXY_PLUGINDIR}" /** @since version 3.3.0 */ + +#endif /* FREERDP_BUILD_CONFIG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/config/buildflags.h.in b/local-test-freerdp-delta-01/afc-freerdp/include/config/buildflags.h.in new file mode 100644 index 0000000000000000000000000000000000000000..f45331b86ffdf6909ae13efa774dc4c951279b46 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/config/buildflags.h.in @@ -0,0 +1,11 @@ +#ifndef FREERDP_BUILD_FLAGS_H +#define FREERDP_BUILD_FLAGS_H + +#define FREERDP_CFLAGS "${CURRENT_C_FLAGS}" +#define FREERDP_COMPILER_ID "${CMAKE_C_COMPILER_ID}" +#define FREERDP_COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION}" +#define FREERDP_TARGET_ARCH "${TARGET_ARCH}" +#define FREERDP_BUILD_CONFIG "${FREERDP_BUILD_CONFIG}" +#define FREERDP_BUILD_TYPE "${CURRENT_BUILD_CONFIG}" + +#endif /* FREERDP_BUILD_FLAGS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/config/config.h.in b/local-test-freerdp-delta-01/afc-freerdp/include/config/config.h.in new file mode 100644 index 0000000000000000000000000000000000000000..284a681eccf02c128f706af11009db0d55f5bcbc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/config/config.h.in @@ -0,0 +1,230 @@ +#ifndef FREERDP_CONFIG_H +#define FREERDP_CONFIG_H + +#include + +/* Include files */ +#cmakedefine FREERDP_HAVE_VALGRIND_MEMCHECK_H + +/* Features */ +#cmakedefine SWRESAMPLE_FOUND +#cmakedefine AVRESAMPLE_FOUND + +/* Options */ +/** If set the rdpSettings struct is opaque and internals can only be accessed + * through getters/setters + * + * \since version 3.0.0 + */ +#cmakedefine WITH_OPAQUE_SETTINGS + +#cmakedefine WITH_ADD_PLUGIN_TO_RPATH +#cmakedefine WITH_PROFILER +#cmakedefine WITH_GPROF +#cmakedefine WITH_SIMD +#cmakedefine WITH_AVX2 +#cmakedefine WITH_CUPS +#cmakedefine WITH_JPEG +#cmakedefine WITH_WIN8 +#cmakedefine WITH_AAD +#cmakedefine WITH_CAIRO +#cmakedefine WITH_SWSCALE +#cmakedefine WITH_RDPSND_DSOUND + +#cmakedefine WITH_WINMM +#cmakedefine WITH_MACAUDIO +#cmakedefine WITH_OSS +#cmakedefine WITH_ALSA +#cmakedefine WITH_PULSE +#cmakedefine WITH_IOSAUDIO +#cmakedefine WITH_OPENSLES +#cmakedefine WITH_GSM +#cmakedefine WITH_LAME +/** If defined Opus codec support is available. + * + * \since version 3.0.0 + */ +#cmakedefine WITH_OPUS +#cmakedefine WITH_FAAD2 +#cmakedefine WITH_FAAC +#cmakedefine WITH_SOXR +#cmakedefine WITH_GFX_H264 +#cmakedefine WITH_OPENH264 +#cmakedefine WITH_OPENH264_LOADING +#cmakedefine WITH_VIDEO_FFMPEG +#cmakedefine WITH_DSP_EXPERIMENTAL +#cmakedefine WITH_DSP_FFMPEG +#cmakedefine WITH_OPENCL +#cmakedefine WITH_MEDIA_FOUNDATION +#cmakedefine WITH_MEDIACODEC + +#cmakedefine WITH_VAAPI + +#cmakedefine WITH_CHANNELS +#cmakedefine WITH_CLIENT_CHANNELS +#cmakedefine WITH_SERVER_CHANNELS + +#cmakedefine WITH_CHANNEL_GFXREDIR +#cmakedefine WITH_CHANNEL_RDPAPPLIST + +/* Plugins */ +#cmakedefine WITH_RDPDR + +/* Channels */ +#cmakedefine CHANNEL_AINPUT +#cmakedefine CHANNEL_AINPUT_CLIENT +#cmakedefine CHANNEL_AINPUT_SERVER +#cmakedefine CHANNEL_AUDIN +#cmakedefine CHANNEL_AUDIN_CLIENT +#cmakedefine CHANNEL_AUDIN_SERVER +#cmakedefine CHANNEL_CLIPRDR +#cmakedefine CHANNEL_CLIPRDR_CLIENT +#cmakedefine CHANNEL_CLIPRDR_SERVER +#cmakedefine CHANNEL_DISP +#cmakedefine CHANNEL_DISP_CLIENT +#cmakedefine CHANNEL_DISP_SERVER +#cmakedefine CHANNEL_DRDYNVC +#cmakedefine CHANNEL_DRDYNVC_CLIENT +#cmakedefine CHANNEL_DRDYNVC_SERVER +#cmakedefine CHANNEL_DRIVE +#cmakedefine CHANNEL_DRIVE_CLIENT +#cmakedefine CHANNEL_DRIVE_SERVER +#cmakedefine CHANNEL_ECHO +#cmakedefine CHANNEL_ECHO_CLIENT +#cmakedefine CHANNEL_ECHO_SERVER +#cmakedefine CHANNEL_ENCOMSP +#cmakedefine CHANNEL_ENCOMSP_CLIENT +#cmakedefine CHANNEL_ENCOMSP_SERVER +#cmakedefine CHANNEL_GEOMETRY +#cmakedefine CHANNEL_GEOMETRY_CLIENT +#cmakedefine CHANNEL_GEOMETRY_SERVER +#cmakedefine CHANNEL_GFXREDIR +#cmakedefine CHANNEL_GFXREDIR_CLIENT +#cmakedefine CHANNEL_GFXREDIR_SERVER +/** If defined location channel support is available. + * + * \since version 3.0.0 + */ +#cmakedefine CHANNEL_LOCATION +/** If defined location client side channel support is available. + * + * \since version 3.0.0 + */ +#cmakedefine CHANNEL_LOCATION_CLIENT +/** If defined location server side channel support is available. + * + * \since version 3.0.0 + */ +#cmakedefine CHANNEL_LOCATION_SERVER +#cmakedefine CHANNEL_PARALLEL +#cmakedefine CHANNEL_PARALLEL_CLIENT +#cmakedefine CHANNEL_PARALLEL_SERVER +#cmakedefine CHANNEL_PRINTER +#cmakedefine CHANNEL_PRINTER_CLIENT +#cmakedefine CHANNEL_PRINTER_SERVER +#cmakedefine CHANNEL_RAIL +#cmakedefine CHANNEL_RAIL_CLIENT +#cmakedefine CHANNEL_RAIL_SERVER +#cmakedefine CHANNEL_RDPAPPLIST +#cmakedefine CHANNEL_RDPAPPLIST_CLIENT +#cmakedefine CHANNEL_RDPAPPLIST_SERVER +#cmakedefine CHANNEL_RDPDR +#cmakedefine CHANNEL_RDPDR_CLIENT +#cmakedefine CHANNEL_RDPDR_SERVER +#cmakedefine CHANNEL_RDPECAM +#cmakedefine CHANNEL_RDPECAM_CLIENT +#cmakedefine CHANNEL_RDPECAM_SERVER +#cmakedefine CHANNEL_RDPEI +#cmakedefine CHANNEL_RDPEI_CLIENT +#cmakedefine CHANNEL_RDPEI_SERVER +#cmakedefine CHANNEL_RDPGFX +#cmakedefine CHANNEL_RDPGFX_CLIENT +#cmakedefine CHANNEL_RDPGFX_SERVER +/** If defined mouse cursor channel support is available. + * + * \since version 3.0.0 + */ +#cmakedefine CHANNEL_RDPEMSC + +/** If defined mouse cursor channel support is available. + * + * \since version 3.0.0 + */ +#cmakedefine CHANNEL_RDPEMSC_CLIENT + +/** If defined mouse cursor channel support is available. + * + * \since version 3.0.0 + */ +#cmakedefine CHANNEL_RDPEMSC_SERVER +#cmakedefine CHANNEL_RDPSND +#cmakedefine CHANNEL_RDPSND_CLIENT +#cmakedefine CHANNEL_RDPSND_SERVER +#cmakedefine CHANNEL_REMDESK +#cmakedefine CHANNEL_REMDESK_CLIENT +#cmakedefine CHANNEL_REMDESK_SERVER +#cmakedefine CHANNEL_SERIAL +#cmakedefine CHANNEL_SERIAL_CLIENT +#cmakedefine CHANNEL_SERIAL_SERVER +#cmakedefine CHANNEL_SMARTCARD +#cmakedefine CHANNEL_SMARTCARD_CLIENT +#cmakedefine CHANNEL_SMARTCARD_SERVER +#cmakedefine CHANNEL_SSHAGENT +#cmakedefine CHANNEL_SSHAGENT_CLIENT +#cmakedefine CHANNEL_SSHAGENT_SERVER +#cmakedefine CHANNEL_TELEMETRY +#cmakedefine CHANNEL_TELEMETRY_CLIENT +#cmakedefine CHANNEL_TELEMETRY_SERVER +#cmakedefine CHANNEL_TSMF +#cmakedefine CHANNEL_TSMF_CLIENT +#cmakedefine CHANNEL_TSMF_SERVER +#cmakedefine CHANNEL_URBDRC +#cmakedefine CHANNEL_URBDRC_CLIENT +#cmakedefine CHANNEL_URBDRC_SERVER +#cmakedefine CHANNEL_VIDEO +#cmakedefine CHANNEL_VIDEO_CLIENT +#cmakedefine CHANNEL_VIDEO_SERVER + +/* Debug */ +#cmakedefine WITH_DEBUG_CERTIFICATE +#cmakedefine WITH_DEBUG_CAPABILITIES +#cmakedefine WITH_DEBUG_CHANNELS +#cmakedefine WITH_DEBUG_CLIPRDR +#cmakedefine WITH_DEBUG_CODECS +#cmakedefine WITH_DEBUG_RDPGFX +#cmakedefine WITH_DEBUG_DVC +#cmakedefine WITH_DEBUG_TSMF +#cmakedefine WITH_DEBUG_KBD +#cmakedefine WITH_DEBUG_LICENSE +#cmakedefine WITH_DEBUG_NEGO +#cmakedefine WITH_DEBUG_NLA +#cmakedefine WITH_DEBUG_TSG +#cmakedefine WITH_DEBUG_RAIL +#cmakedefine WITH_DEBUG_RDP +#cmakedefine WITH_DEBUG_REDIR +#cmakedefine WITH_DEBUG_RDPDR +#cmakedefine WITH_DEBUG_RFX +#cmakedefine WITH_DEBUG_SCARD +#cmakedefine WITH_DEBUG_SND +#cmakedefine WITH_DEBUG_SVC +#cmakedefine WITH_DEBUG_RDPEI +#cmakedefine WITH_DEBUG_TIMEZONE +#cmakedefine WITH_DEBUG_URBDRC +#cmakedefine WITH_DEBUG_TRANSPORT +#cmakedefine WITH_DEBUG_WND +#cmakedefine WITH_DEBUG_X11 +#cmakedefine WITH_DEBUG_X11_LOCAL_MOVESIZE +#cmakedefine WITH_DEBUG_XV +#cmakedefine WITH_DEBUG_RINGBUFFER + +/* Proxy */ +#cmakedefine WITH_PROXY_MODULES +#cmakedefine WITH_PROXY_EMULATE_SMARTCARD + +/** If defined linux/vm_sockets.h support is available. + * + * \since version 3.0.0 + */ +#cmakedefine HAVE_AF_VSOCK_H + +#endif /* FREERDP_CONFIG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/config/settings_keys.h.in b/local-test-freerdp-delta-01/afc-freerdp/include/config/settings_keys.h.in new file mode 100644 index 0000000000000000000000000000000000000000..9635f71ca5e2ffd9643263a15a3e7b0a256b2103 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/config/settings_keys.h.in @@ -0,0 +1,123 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Internal settings header for functions not exported + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SETTINGS_KEYS_H +#define FREERDP_SETTINGS_KEYS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** A list of available settings keys of type BOOL + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_BOOL@ +} FreeRDP_Settings_Keys_Bool; + +/** A list of available settings keys of type INT16 + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_INT16@ +} FreeRDP_Settings_Keys_Int16; + +/** A list of available settings keys of type UINT16 + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_UINT16@ +} FreeRDP_Settings_Keys_UInt16; + +/** A list of available settings keys of type INT32 + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_INT32@ +} FreeRDP_Settings_Keys_Int32; + +/** A list of available settings keys of type UINT32 + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_UINT32@ +} FreeRDP_Settings_Keys_UInt32; + +/** A list of available settings keys of type INT64 + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_INT64@ +} FreeRDP_Settings_Keys_Int64; + +/** A list of available settings keys of type UINT64 + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_UINT64@ +} FreeRDP_Settings_Keys_UInt64; + +/** A list of available settings keys of type STRING + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_STRING@ +} FreeRDP_Settings_Keys_String; + +/** A list of available settings keys of type POINTER + * + * \since version 3.0.0 + */ +typedef enum +{ + @SETTINGS_KEYS_POINTER@ +} FreeRDP_Settings_Keys_Pointer; + + +/** Highest index in the rdpSettings stable API + * + * \since version 3.0.0 + */ +#define FreeRDP_Settings_StableAPI_MAX 5312 + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SETTINGS_KEYS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/config/version.h.in b/local-test-freerdp-delta-01/afc-freerdp/include/config/version.h.in new file mode 100644 index 0000000000000000000000000000000000000000..0dffcbac9f601bb060c75667ed68e23697d79d63 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/config/version.h.in @@ -0,0 +1,35 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Version includes + * + * Copyright 2013 Thincast Technologies GmbH + * Copyright 2013 Bernhard Miklautz + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FREERDP_VERSION_H +#define FREERDP_VERSION_H + +#define FREERDP_VERSION_MAJOR ${FREERDP_VERSION_MAJOR} +#define FREERDP_VERSION_MINOR ${FREERDP_VERSION_MINOR} +#define FREERDP_VERSION_REVISION ${FREERDP_VERSION_REVISION} +#define FREERDP_VERSION_SUFFIX "${FREERDP_VERSION_SUFFIX}" +#define FREERDP_API_VERSION "${FREERDP_API_VERSION}" +#define FREERDP_VERSION "${FREERDP_VERSION}" +#define FREERDP_VERSION_FULL "${FREERDP_VERSION_FULL}" +#define FREERDP_GIT_REVISION "${GIT_REVISION}" +#define FREERDP_USER_AGENT "FreeRDP/${FREERDP_VERSION_FULL}" +#define FREERDP_VENDOR "${VENDOR}" +#define FREERDP_PRODUCT "${PRODUCT}" + +#endif /* FREERDP_VERSION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/addin.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/addin.h new file mode 100644 index 0000000000000000000000000000000000000000..cec491aa6a2c9877ee1cb24ae7a50828beed58ac --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/addin.h @@ -0,0 +1,81 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Addin Loader + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_COMMON_ADDIN_H +#define FREERDP_COMMON_ADDIN_H + +#include +#include + +#define FREERDP_ADDIN_CLIENT 0x00000001 +#define FREERDP_ADDIN_SERVER 0x00000002 + +#define FREERDP_ADDIN_STATIC 0x00000010 +#define FREERDP_ADDIN_DYNAMIC 0x00000020 + +#define FREERDP_ADDIN_NAME 0x00000100 +#define FREERDP_ADDIN_SUBSYSTEM 0x00000200 +#define FREERDP_ADDIN_TYPE 0x00000400 + +#define FREERDP_ADDIN_CHANNEL_STATIC 0x00001000 +#define FREERDP_ADDIN_CHANNEL_DYNAMIC 0x00002000 +#define FREERDP_ADDIN_CHANNEL_DEVICE 0x00004000 +#define FREERDP_ADDIN_CHANNEL_ENTRYEX 0x00008000 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + DWORD dwFlags; + CHAR cName[16]; + CHAR cType[16]; + CHAR cSubsystem[16]; + } FREERDP_ADDIN; + + typedef PVIRTUALCHANNELENTRY (*FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN)(LPCSTR pszName, + LPCSTR pszSubsystem, + LPCSTR pszType, + DWORD dwFlags); + + FREERDP_API LPSTR freerdp_get_library_install_path(void); + FREERDP_API LPSTR freerdp_get_dynamic_addin_install_path(void); + + FREERDP_API int freerdp_register_addin_provider(FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN provider, + DWORD dwFlags); + FREERDP_API FREERDP_LOAD_CHANNEL_ADDIN_ENTRY_FN freerdp_get_current_addin_provider(void); + + FREERDP_API PVIRTUALCHANNELENTRY freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, + LPCSTR pszEntryName); + FREERDP_API PVIRTUALCHANNELENTRY freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, + LPCSTR pszSubsystem, + LPCSTR pszType, + DWORD dwFlags); + FREERDP_API PVIRTUALCHANNELENTRY freerdp_load_channel_addin_entry(LPCSTR pszName, + LPCSTR pszSubsystem, + LPCSTR pszType, + DWORD dwFlags); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_COMMON_ADDIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/altsec.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/altsec.h new file mode 100644 index 0000000000000000000000000000000000000000..348662cc1c9842586199a8956dc7e7dff76923d8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/altsec.h @@ -0,0 +1,210 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Alternate Secondary Drawing Orders Interface API + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UPDATE_ALTSEC_H +#define FREERDP_UPDATE_ALTSEC_H + +#include + +#define DSDNG_STRETCH 0x00000001 +#define DSDNG_TILE 0x00000002 +#define DSDNG_PERPIXELALPHA 0x00000004 +#define DSDNG_TRANSPARENT 0x00000008 +#define DSDNG_MUSTFLIP 0x00000010 +#define DSDNG_TRUESIZE 0x00000020 + +#define FRAME_START 0x00000000 +#define FRAME_END 0x00000001 + +#define STREAM_BITMAP_END 0x01 +#define STREAM_BITMAP_COMPRESSED 0x02 +#define STREAM_BITMAP_V2 0x04 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 sIndices; + UINT32 cIndices; + UINT16* indices; + } OFFSCREEN_DELETE_LIST; + + typedef struct + { + UINT32 id; + UINT32 cx; + UINT32 cy; + OFFSCREEN_DELETE_LIST deleteList; + } CREATE_OFFSCREEN_BITMAP_ORDER; + + typedef struct + { + UINT32 bitmapId; + } SWITCH_SURFACE_ORDER; + + typedef struct + { + UINT32 flFlags; + UINT32 ulLeftWidth; + UINT32 ulRightWidth; + UINT32 ulTopHeight; + UINT32 ulBottomHeight; + UINT32 crTransparent; + } NINE_GRID_BITMAP_INFO; + + typedef struct + { + UINT32 bitmapBpp; + UINT32 bitmapId; + UINT32 cx; + UINT32 cy; + NINE_GRID_BITMAP_INFO nineGridInfo; + } CREATE_NINE_GRID_BITMAP_ORDER; + + typedef struct + { + UINT32 action; + } FRAME_MARKER_ORDER; + + typedef struct + { + UINT32 bitmapFlags; + UINT32 bitmapBpp; + UINT32 bitmapType; + UINT32 bitmapWidth; + UINT32 bitmapHeight; + UINT32 bitmapSize; + UINT32 bitmapBlockSize; + BYTE* bitmapBlock; + } STREAM_BITMAP_FIRST_ORDER; + + typedef struct + { + UINT32 bitmapFlags; + UINT32 bitmapType; + UINT32 bitmapBlockSize; + BYTE* bitmapBlock; + } STREAM_BITMAP_NEXT_ORDER; + + typedef struct + { + UINT32 cbSize; + UINT32 cbTotalSize; + UINT32 cbTotalEmfSize; + BYTE* emfRecords; + } DRAW_GDIPLUS_FIRST_ORDER; + + typedef struct + { + UINT32 cbSize; + BYTE* emfRecords; + } DRAW_GDIPLUS_NEXT_ORDER; + + typedef struct + { + UINT32 cbSize; + UINT32 cbTotalSize; + UINT32 cbTotalEmfSize; + BYTE* emfRecords; + } DRAW_GDIPLUS_END_ORDER; + + typedef struct + { + UINT32 flags; + UINT32 cacheType; + UINT32 cacheIndex; + UINT32 cbSize; + UINT32 cbTotalSize; + BYTE* emfRecords; + } DRAW_GDIPLUS_CACHE_FIRST_ORDER; + + typedef struct + { + UINT32 flags; + UINT32 cacheType; + UINT32 cacheIndex; + UINT32 cbSize; + BYTE* emfRecords; + } DRAW_GDIPLUS_CACHE_NEXT_ORDER; + + typedef struct + { + UINT32 flags; + UINT32 cacheType; + UINT32 cacheIndex; + UINT32 cbSize; + UINT32 cbTotalSize; + BYTE* emfRecords; + } DRAW_GDIPLUS_CACHE_END_ORDER; + + typedef BOOL (*pCreateOffscreenBitmap)( + rdpContext* context, const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); + typedef BOOL (*pSwitchSurface)(rdpContext* context, const SWITCH_SURFACE_ORDER* switch_surface); + typedef BOOL (*pCreateNineGridBitmap)( + rdpContext* context, const CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap); + typedef BOOL (*pFrameMarker)(rdpContext* context, const FRAME_MARKER_ORDER* frame_marker); + typedef BOOL (*pStreamBitmapFirst)(rdpContext* context, + const STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first); + typedef BOOL (*pStreamBitmapNext)(rdpContext* context, + const STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next); + typedef BOOL (*pDrawGdiPlusFirst)(rdpContext* context, + const DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first); + typedef BOOL (*pDrawGdiPlusNext)(rdpContext* context, + const DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next); + typedef BOOL (*pDrawGdiPlusEnd)(rdpContext* context, + const DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end); + typedef BOOL (*pDrawGdiPlusCacheFirst)( + rdpContext* context, const DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first); + typedef BOOL (*pDrawGdiPlusCacheNext)( + rdpContext* context, const DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next); + typedef BOOL (*pDrawGdiPlusCacheEnd)( + rdpContext* context, const DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end); + typedef BOOL (*pDrawOrderInfo)(rdpContext* context, UINT8 orderType, const char* orderName); + + struct rdp_altsec_update + { + rdpContext* context; /* 0 */ + UINT32 paddingA[16 - 1]; /* 1 */ + + pCreateOffscreenBitmap CreateOffscreenBitmap; /* 16 */ + pSwitchSurface SwitchSurface; /* 17 */ + pCreateNineGridBitmap CreateNineGridBitmap; /* 18 */ + pFrameMarker FrameMarker; /* 19 */ + pStreamBitmapFirst StreamBitmapFirst; /* 20 */ + pStreamBitmapNext StreamBitmapNext; /* 21 */ + pDrawGdiPlusFirst DrawGdiPlusFirst; /* 22 */ + pDrawGdiPlusNext DrawGdiPlusNext; /* 23 */ + pDrawGdiPlusEnd DrawGdiPlusEnd; /* 24 */ + pDrawGdiPlusCacheFirst DrawGdiPlusCacheFirst; /* 25 */ + pDrawGdiPlusCacheNext DrawGdiPlusCacheNext; /* 26 */ + pDrawGdiPlusCacheEnd DrawGdiPlusCacheEnd; /* 27 */ + /* Statistics callback */ + pDrawOrderInfo DrawOrderInfo; /* 28 */ + UINT32 paddingB[32 - 29]; /* 29 */ + }; + typedef struct rdp_altsec_update rdpAltSecUpdate; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UPDATE_ALTSEC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/api.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/api.h new file mode 100644 index 0000000000000000000000000000000000000000..b7655cf20e102d53d6a2c3718303c392450cf583 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/api.h @@ -0,0 +1,116 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Interface + * + * Copyright 2009-2011 Jay Sorg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_API_H +#define FREERDP_API_H + +#include +#include +#include + +/* To silence missing prototype warnings for library entry points use this macro. + * It first declares the function as prototype and then again as function implementation + */ +#define FREERDP_ENTRY_POINT(fkt) \ + fkt; \ + fkt + +#ifdef _WIN32 +#define FREERDP_CC __cdecl +#else +#define FREERDP_CC +#endif + +#if defined _WIN32 || defined __CYGWIN__ +#ifdef FREERDP_EXPORTS +#ifdef __GNUC__ +#define FREERDP_API __attribute__((dllexport)) +#else +#define FREERDP_API __declspec(dllexport) +#endif +#else +#ifdef __GNUC__ +#define FREERDP_API __attribute__((dllimport)) +#else +#define FREERDP_API __declspec(dllimport) +#endif +#endif +#else +#if defined(__GNUC__) && (__GNUC__ >= 4) +#define FREERDP_API __attribute__((visibility("default"))) +#else +#define FREERDP_API +#endif +#endif + +#if defined(EXPORT_ALL_SYMBOLS) +#define FREERDP_LOCAL FREERDP_API +#else +#if defined _WIN32 || defined __CYGWIN__ +#define FREERDP_LOCAL +#else +#if defined(__GNUC__) && (__GNUC__ >= 4) +#define FREERDP_LOCAL __attribute__((visibility("hidden"))) +#else +#define FREERDP_LOCAL +#endif +#endif +#endif + +#define IFCALL(_cb, ...) \ + do \ + { \ + if (_cb != NULL) \ + _cb(__VA_ARGS__); \ + else \ + WLog_VRB("com.freerdp.api", "IFCALL(" #_cb ") == NULL"); \ + } while (0) +#define IFCALLRET(_cb, _ret, ...) \ + do \ + { \ + if (_cb != NULL) \ + _ret = _cb(__VA_ARGS__); \ + else \ + WLog_VRB("com.freerdp.api", "IFCALLRET(" #_cb ") == NULL"); \ + } while (0) + +#if 0 // defined(__GNUC__) +#define IFCALLRESULT(_default_return, _cb, ...) \ + ({ \ + (_cb != NULL) ? _cb(__VA_ARGS__) : ({ \ + WLog_VRB("com.freerdp.api", "IFCALLRESULT(" #_cb ") == NULL"); \ + (_default_return); \ + }); \ + }) +#else +#define IFCALLRESULT(_default_return, _cb, ...) \ + ((_cb != NULL) ? _cb(__VA_ARGS__) : (_default_return)) +#endif + +#if defined(__GNUC__) || defined(__clang__) +#define ALIGN64 __attribute__((aligned(8))) +#else +#ifdef _WIN32 +#define ALIGN64 __declspec(align(8)) +#else +#define ALIGN64 +#endif +#endif + +#endif /* FREERDP_API */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/assistance.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/assistance.h new file mode 100644 index 0000000000000000000000000000000000000000..e38e58b771c3ac9d3f2f61e19c7b0bfd62b91f6a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/assistance.h @@ -0,0 +1,77 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Assistance + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_REMOTE_ASSISTANCE_H +#define FREERDP_REMOTE_ASSISTANCE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_assistance_file rdpAssistanceFile; + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API BYTE* freerdp_assistance_hex_string_to_bin(const void* str, size_t* size); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_assistance_bin_to_hex_string(const void* data, size_t size); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_assistance_generate_pass_stub(DWORD flags); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_assistance_construct_expert_blob(const char* name, const char* pass); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API BYTE* freerdp_assistance_encrypt_pass_stub(const char* password, + const char* passStub, + size_t* pEncryptedSize); + + FREERDP_API int freerdp_assistance_set_connection_string2(rdpAssistanceFile* file, + const char* string, + const char* password); + + FREERDP_API int freerdp_assistance_parse_file_buffer(rdpAssistanceFile* file, + const char* buffer, size_t size, + const char* password); + FREERDP_API int freerdp_assistance_parse_file(rdpAssistanceFile* file, const char* name, + const char* password); + + FREERDP_API BOOL freerdp_assistance_populate_settings_from_assistance_file( + rdpAssistanceFile* file, rdpSettings* settings); + FREERDP_API BOOL freerdp_assistance_get_encrypted_pass_stub(rdpAssistanceFile* file, + const char** pwd, size_t* size); + + FREERDP_API void freerdp_assistance_file_free(rdpAssistanceFile* file); + + WINPR_ATTR_MALLOC(freerdp_assistance_file_free, 1) + FREERDP_API rdpAssistanceFile* freerdp_assistance_file_new(void); + + FREERDP_API void freerdp_assistance_print_file(rdpAssistanceFile* file, wLog* log, DWORD level); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_REMOTE_ASSISTANCE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/autodetect.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/autodetect.h new file mode 100644 index 0000000000000000000000000000000000000000..b8551488d15a8f79e3eb2fad4443265b21a59b77 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/autodetect.h @@ -0,0 +1,144 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Auto-Detect PDUs + * + * Copyright 2014 Dell Software + * Copyright 2014 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_AUTODETECT_H +#define FREERDP_AUTODETECT_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + FREERDP_AUTODETECT_STATE_INITIAL, + FREERDP_AUTODETECT_STATE_REQUEST, + FREERDP_AUTODETECT_STATE_RESPONSE, + FREERDP_AUTODETECT_STATE_COMPLETE, + FREERDP_AUTODETECT_STATE_FAIL + } FREERDP_AUTODETECT_STATE; + + typedef enum + { + RDP_NETCHAR_RESERVED = 0x0000U, + /* The baseRTT and averageRTT fields are valid */ + RDP_NETCHAR_RESULT_TYPE_BASE_RTT_AVG_RTT = 0x0840U, + /* The bandwidth and averageRTT fields are valid */ + RDP_NETCHAR_RESULT_TYPE_BW_AVG_RTT = 0x0880U, + /* The baseRTT, bandwidth and averageRTT fields are valid */ + RDP_NETCHAR_RESULT_TYPE_BASE_RTT_BW_AVG_RTT = 0x08C0U + } RDP_NETCHAR_RESULT_TYPE; + + typedef enum + { + RDP_BW_RESULTS_RESPONSE_TYPE_CONNECTTIME = 0x0003, + RDP_BW_RESULTS_RESPONSE_TYPE_CONTINUOUS = 0x000B + } RDP_BW_RESULTS_RESPONSE_TYPE; + + typedef struct rdp_autodetect rdpAutoDetect; + typedef struct rdp_network_characteristics_result rdpNetworkCharacteristicsResult; + + typedef BOOL (*pRTTMeasureRequest)(rdpAutoDetect* autodetect, RDP_TRANSPORT_TYPE transport, + UINT16 sequenceNumber); + typedef BOOL (*pRTTMeasureResponse)(rdpAutoDetect* autodetect, RDP_TRANSPORT_TYPE transport, + UINT16 sequenceNumber); + typedef BOOL (*pBandwidthMeasureStart)(rdpAutoDetect* autodetect, RDP_TRANSPORT_TYPE transport, + UINT16 sequenceNumber); + typedef BOOL (*pBandwidthMeasurePayload)(rdpAutoDetect* autodetect, + RDP_TRANSPORT_TYPE transport, UINT16 sequenceNumber, + UINT16 payloadLength); + typedef BOOL (*pBandwidthMeasureStop)(rdpAutoDetect* autodetect, RDP_TRANSPORT_TYPE transport, + UINT16 sequenceNumber, UINT16 payloadLength); + typedef BOOL (*pBandwidthMeasureResults)(rdpAutoDetect* autodetect, + RDP_TRANSPORT_TYPE transport, UINT16 sequenceNumber, + UINT16 responseType, UINT32 timeDelta, + UINT32 byteCount); + typedef BOOL (*pNetworkCharacteristicsResult)(rdpAutoDetect* autodetect, + RDP_TRANSPORT_TYPE transport, + UINT16 sequenceNumber, + const rdpNetworkCharacteristicsResult* result); + typedef BOOL (*pClientBandwidthMeasureResult)(rdpAutoDetect* autodetect, + RDP_TRANSPORT_TYPE transport, UINT16 responseType, + UINT16 sequenceNumber, UINT32 timeDelta, + UINT32 byteCount); + typedef BOOL (*pNetworkCharacteristicsSync)(rdpAutoDetect* autodetect, + RDP_TRANSPORT_TYPE transport, UINT16 sequenceNumber, + UINT32 bandwidth, UINT32 rtt); + typedef BOOL (*pRxTxReceived)(rdpAutoDetect* autodetect, RDP_TRANSPORT_TYPE transport, + UINT16 requestType, UINT16 sequenceNumber); + typedef FREERDP_AUTODETECT_STATE (*pOnConnectTimeAutoDetect)(rdpAutoDetect* autodetect); + + struct rdp_network_characteristics_result + { + /* Specifies, which fields are valid */ + RDP_NETCHAR_RESULT_TYPE type; + + /* Lowest detected round-trip time in milliseconds. */ + UINT32 baseRTT; + /* Current average round-trip time in milliseconds. */ + UINT32 averageRTT; + /* Current bandwidth in kilobits per second. */ + UINT32 bandwidth; + }; + + struct rdp_autodetect + { + ALIGN64 rdpContext* context; /* 0 */ + /* RTT measurement */ + ALIGN64 UINT64 rttMeasureStartTime; /* 1 */ + /* Bandwidth measurement */ + ALIGN64 UINT64 bandwidthMeasureStartTime; /* 2 */ + ALIGN64 UINT64 bandwidthMeasureTimeDelta; /* 3 */ + ALIGN64 UINT32 bandwidthMeasureByteCount; /* 4 */ + /* Network characteristics (as reported by server) */ + ALIGN64 UINT32 netCharBandwidth; /* 5 */ + ALIGN64 UINT32 netCharBaseRTT; /* 6 */ + ALIGN64 UINT32 netCharAverageRTT; /* 7 */ + ALIGN64 BOOL bandwidthMeasureStarted; /* 8 */ + ALIGN64 FREERDP_AUTODETECT_STATE state; /* 9 */ + ALIGN64 void* custom; /* 10 */ + ALIGN64 wLog* log; /* 11 */ + UINT64 paddingA[16 - 12]; /* 12 */ + + ALIGN64 pRTTMeasureRequest RTTMeasureRequest; /* 16 */ + ALIGN64 pRTTMeasureResponse RTTMeasureResponse; /* 17 */ + ALIGN64 pBandwidthMeasureStart BandwidthMeasureStart; /* 18 */ + ALIGN64 pBandwidthMeasurePayload BandwidthMeasurePayload; /* 19 */ + ALIGN64 pBandwidthMeasureStop BandwidthMeasureStop; /* 20 */ + ALIGN64 pBandwidthMeasureResults BandwidthMeasureResults; /* 21 */ + ALIGN64 pNetworkCharacteristicsResult NetworkCharacteristicsResult; /* 22 */ + ALIGN64 pClientBandwidthMeasureResult ClientBandwidthMeasureResult; /* 23 */ + ALIGN64 pNetworkCharacteristicsSync NetworkCharacteristicsSync; /* 24 */ + ALIGN64 pRxTxReceived RequestReceived; /* 25 */ + ALIGN64 pRxTxReceived ResponseReceived; /* 26 */ + ALIGN64 pOnConnectTimeAutoDetect OnConnectTimeAutoDetectBegin; /* 27 */ + ALIGN64 pOnConnectTimeAutoDetect OnConnectTimeAutoDetectProgress; /* 28 */ + UINT64 paddingB[32 - 29]; /* 29 */ + }; + FREERDP_API rdpAutoDetect* autodetect_get(rdpContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_AUTODETECT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/cache/persistent.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/cache/persistent.h new file mode 100644 index 0000000000000000000000000000000000000000..a36595b81b40bf589f1bd43eeb60bdf5e10f01cc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/cache/persistent.h @@ -0,0 +1,100 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Persistent Bitmap Cache + * + * Copyright 2016 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_PERSISTENT_CACHE_H +#define FREERDP_PERSISTENT_CACHE_H + +#include +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_persistent_cache rdpPersistentCache; + +#pragma pack(push, 1) + +/* 12 bytes */ + + typedef struct + { + BYTE sig[8]; + UINT32 flags; /* 0x00000003, 0x00000006 */ + } PERSISTENT_CACHE_HEADER_V3; + +/* 12 bytes */ + + typedef struct + { + UINT64 key64; + UINT16 width; + UINT16 height; + } PERSISTENT_CACHE_ENTRY_V3; + +/* 20 bytes */ + + typedef struct + { + UINT64 key64; + UINT16 width; + UINT16 height; + UINT32 size; + UINT32 flags; /* 0x00000011 */ + } PERSISTENT_CACHE_ENTRY_V2; + +#pragma pack(pop) + + typedef struct + { + UINT64 key64; + UINT16 width; + UINT16 height; + UINT32 size; + UINT32 flags; + BYTE* data; + } PERSISTENT_CACHE_ENTRY; + + FREERDP_API int persistent_cache_get_version(rdpPersistentCache* persistent); + FREERDP_API int persistent_cache_get_count(rdpPersistentCache* persistent); + + FREERDP_API int persistent_cache_read_entry(rdpPersistentCache* persistent, + PERSISTENT_CACHE_ENTRY* entry); + FREERDP_API int persistent_cache_write_entry(rdpPersistentCache* persistent, + const PERSISTENT_CACHE_ENTRY* entry); + + FREERDP_API int persistent_cache_open(rdpPersistentCache* persistent, const char* filename, + BOOL write, UINT32 version); + FREERDP_API int persistent_cache_close(rdpPersistentCache* persistent); + + FREERDP_API void persistent_cache_free(rdpPersistentCache* persistent); + + WINPR_ATTR_MALLOC(persistent_cache_free, 1) + FREERDP_API rdpPersistentCache* persistent_cache_new(void); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_PERSISTENT_CACHE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/ainput.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/ainput.h new file mode 100644 index 0000000000000000000000000000000000000000..aea73bcb9fad70623f517b8c81887b201b920b66 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/ainput.h @@ -0,0 +1,70 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AINPUT_H +#define FREERDP_CHANNEL_AINPUT_H + +#include +#include +#include + +#define AINPUT_CHANNEL_NAME "ainput" +#define AINPUT_DVC_CHANNEL_NAME "FreeRDP::Advanced::Input" + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + MSG_AINPUT_VERSION = 0x01, + MSG_AINPUT_MOUSE = 0x02 + } eAInputMsgType; + + typedef enum + { + AINPUT_FLAGS_WHEEL = 0x0001, + AINPUT_FLAGS_MOVE = 0x0004, + AINPUT_FLAGS_DOWN = 0x0008, + + AINPUT_FLAGS_REL = 0x0010, + AINPUT_FLAGS_HAVE_REL = 0x0020, + + /* Pointer Flags */ + AINPUT_FLAGS_BUTTON1 = 0x1000, /* left */ + AINPUT_FLAGS_BUTTON2 = 0x2000, /* right */ + AINPUT_FLAGS_BUTTON3 = 0x4000, /* middle */ + + /* Extended Pointer Flags */ + AINPUT_XFLAGS_BUTTON1 = 0x0100, + AINPUT_XFLAGS_BUTTON2 = 0x0200 + } AInputEventFlags; + + typedef struct ainput_client_context AInputClientContext; + +#define AINPUT_VERSION_MAJOR 1 +#define AINPUT_VERSION_MINOR 0 + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_AINPUT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/audin.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/audin.h new file mode 100644 index 0000000000000000000000000000000000000000..1bb0e86c371b38d3ff2d907ab97d1184df6f49c5 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/audin.h @@ -0,0 +1,133 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AUDIN_H +#define FREERDP_CHANNEL_AUDIN_H + +#include +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define AUDIN_CHANNEL_NAME "audin" + +/** The name of the channel (protocol internal) + * + * \since version 3.0.0 + */ +#define AUDIN_DVC_CHANNEL_NAME "AUDIO_INPUT" + +typedef struct +{ + BYTE MessageId; +} SNDIN_PDU; + +typedef enum +{ + SNDIN_VERSION_Version_1 = 0x00000001, + SNDIN_VERSION_Version_2 = 0x00000002, +} SNDIN_VERSION_Version; + +typedef struct +{ + SNDIN_PDU Header; + SNDIN_VERSION_Version Version; +} SNDIN_VERSION; + +typedef struct +{ + SNDIN_PDU Header; + UINT32 NumFormats; + UINT32 cbSizeFormatsPacket; + AUDIO_FORMAT* SoundFormats; + size_t ExtraDataSize; +} SNDIN_FORMATS; + +typedef enum +{ + SPEAKER_FRONT_LEFT = 0x00000001, + SPEAKER_FRONT_RIGHT = 0x00000002, + SPEAKER_FRONT_CENTER = 0x00000004, + SPEAKER_LOW_FREQUENCY = 0x00000008, + SPEAKER_BACK_LEFT = 0x00000010, + SPEAKER_BACK_RIGHT = 0x00000020, + SPEAKER_FRONT_LEFT_OF_CENTER = 0x00000040, + SPEAKER_FRONT_RIGHT_OF_CENTER = 0x00000080, + SPEAKER_BACK_CENTER = 0x00000100, + SPEAKER_SIDE_LEFT = 0x00000200, + SPEAKER_SIDE_RIGHT = 0x00000400, + SPEAKER_TOP_CENTER = 0x00000800, + SPEAKER_TOP_FRONT_LEFT = 0x00001000, + SPEAKER_TOP_FRONT_CENTER = 0x00002000, + SPEAKER_TOP_FRONT_RIGHT = 0x00004000, + SPEAKER_TOP_BACK_LEFT = 0x00008000, + SPEAKER_TOP_BACK_CENTER = 0x00010000, + SPEAKER_TOP_BACK_RIGHT = 0x00020000, +} AUDIN_SPEAKER; + +typedef struct +{ + union + { + UINT16 wValidBitsPerSample; + UINT16 wSamplesPerBlock; + UINT16 wReserved; + } Samples; + AUDIN_SPEAKER dwChannelMask; + GUID SubFormat; +} WAVEFORMAT_EXTENSIBLE; + +typedef struct +{ + SNDIN_PDU Header; + UINT32 FramesPerPacket; + UINT32 initialFormat; + AUDIO_FORMAT captureFormat; + WAVEFORMAT_EXTENSIBLE* ExtraFormatData; +} SNDIN_OPEN; + +typedef struct +{ + SNDIN_PDU Header; + UINT32 Result; +} SNDIN_OPEN_REPLY; + +typedef struct +{ + SNDIN_PDU Header; +} SNDIN_DATA_INCOMING; + +typedef struct +{ + SNDIN_PDU Header; + wStream* Data; +} SNDIN_DATA; + +typedef struct +{ + SNDIN_PDU Header; + UINT32 NewFormat; +} SNDIN_FORMATCHANGE; + +#endif /* FREERDP_CHANNEL_AUDIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/channels.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/channels.h new file mode 100644 index 0000000000000000000000000000000000000000..aebccb2dc7965eb085437088da04dfd50999f863 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/channels.h @@ -0,0 +1,105 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Virtual Channel Manager + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNELS_H +#define FREERDP_CHANNELS_H + +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @since version 3.9.0 */ + typedef BOOL (*freerdp_channel_handle_fkt_t)(rdpContext* context, void* userdata); + + FREERDP_API int freerdp_channels_client_load(rdpChannels* channels, rdpSettings* settings, + PVIRTUALCHANNELENTRY entry, void* data); + FREERDP_API int freerdp_channels_client_load_ex(rdpChannels* channels, rdpSettings* settings, + PVIRTUALCHANNELENTRYEX entryEx, void* data); + FREERDP_API int freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings, + const char* name, void* data); +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED_VAR( + "Use freerdp_channels_get_event_handle", + BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance, void** read_fds, + int* read_count, void** write_fds, int* write_count)); +#endif + FREERDP_API BOOL freerdp_channels_check_fds(rdpChannels* channels, freerdp* instance); + + FREERDP_API void* freerdp_channels_get_static_channel_interface(rdpChannels* channels, + const char* name); + + /** @brief A channel may register an event handle and a callback function to be called by \b + * freerdp_check_event_handles + * + * If a channel can not or does not want to use a thread to process data asynchronously it can + * register a \b non-blocking function that does this processing. Notification is done with the + * \b event-handle which will trigger the RDP loop. So this function is triggered until the \b + * event-handle is reset. + * @note This function may be called even without the \b event-handle to be set, so it must be + * capable of handling these calls properly. + * + * @param channels A pointer to the channels instance to register with. Must not be \b NULL + * @param handle A \b event-handle to be used to notify the RDP main thread that the callback + * function should be called again. Must not be \b INVALID_HANDLE_PARAM + * @param fkt The callback function responsible to handle the channel specifics. Must not be \b + * NULL + * @param userdata A pointer to a channel specific context. Most likely the channel context. + * May be \b NULL if not required. + * + * @return \b TRUE if successful, \b FALSE if any error occurs. + * @since version 3.9.0 */ + FREERDP_API BOOL freerdp_client_channel_register(rdpChannels* channels, HANDLE handle, + freerdp_channel_handle_fkt_t fkt, + void* userdata); + + /** @brief Remove an existing registration for \b event-handle from the channels instance + * + * @param channels A pointer to the channels instance to register with. Must not be \b NULL + * @param handle A \b event-handle to be used to notify the RDP main thread that the callback + * function should be called again. Must not be \b INVALID_HANDLE_PARAM + * + * @return \b TRUE if successful, \b FALSE if any error occurs. + * @since version 3.9.0 */ + FREERDP_API BOOL freerdp_client_channel_unregister(rdpChannels* channels, HANDLE handle); + + FREERDP_API HANDLE freerdp_channels_get_event_handle(freerdp* instance); + FREERDP_API int freerdp_channels_process_pending_messages(freerdp* instance); + + FREERDP_API BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* data, + size_t dataSize, UINT32 flags, size_t totalSize); + + FREERDP_API UINT16 freerdp_channels_get_id_by_name(freerdp* instance, const char* channel_name); + FREERDP_API const char* freerdp_channels_get_name_by_id(freerdp* instance, UINT16 channelId); + + FREERDP_API const WtsApiFunctionTable* FreeRDP_InitWtsApi(void); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNELS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/cliprdr.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/cliprdr.h new file mode 100644 index 0000000000000000000000000000000000000000..118b52312075c19acc5a3bda623e051eebf5b3ee --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/cliprdr.h @@ -0,0 +1,213 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CLIPRDR_H +#define FREERDP_CHANNEL_CLIPRDR_H + +#include +#include +#include + +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define CLIPRDR_CHANNEL_NAME "cliprdr" +#define CLIPRDR_SVC_CHANNEL_NAME "cliprdr" + +/* CLIPRDR_HEADER.msgType */ +typedef enum +{ + CB_TYPE_NONE = 0x0000, /** @since version 3.10.0 */ + CB_MONITOR_READY = 0x0001, + CB_FORMAT_LIST = 0x0002, + CB_FORMAT_LIST_RESPONSE = 0x0003, + CB_FORMAT_DATA_REQUEST = 0x0004, + CB_FORMAT_DATA_RESPONSE = 0x0005, + CB_TEMP_DIRECTORY = 0x0006, + CB_CLIP_CAPS = 0x0007, + CB_FILECONTENTS_REQUEST = 0x0008, + CB_FILECONTENTS_RESPONSE = 0x0009, + CB_LOCK_CLIPDATA = 0x000A, + CB_UNLOCK_CLIPDATA = 0x000B +} CliprdrMsgType; + +/* CLIPRDR_HEADER.msgFlags */ +#define CB_RESPONSE_OK 0x0001 +#define CB_RESPONSE_FAIL 0x0002 +#define CB_ASCII_NAMES 0x0004 + +/* CLIPRDR_CAPS_SET.capabilitySetType */ +#define CB_CAPSTYPE_GENERAL 0x0001 + +/* CLIPRDR_GENERAL_CAPABILITY.lengthCapability */ +#define CB_CAPSTYPE_GENERAL_LEN 12 + +/* CLIPRDR_GENERAL_CAPABILITY.version */ +#define CB_CAPS_VERSION_1 0x00000001 +#define CB_CAPS_VERSION_2 0x00000002 + +/* CLIPRDR_GENERAL_CAPABILITY.generalFlags */ +#define CB_USE_LONG_FORMAT_NAMES 0x00000002 +#define CB_STREAM_FILECLIP_ENABLED 0x00000004 +#define CB_FILECLIP_NO_FILE_PATHS 0x00000008 +#define CB_CAN_LOCK_CLIPDATA 0x00000010 +#define CB_HUGE_FILE_SUPPORT_ENABLED 0x00000020 + +/* File Contents Request Flags */ +#define FILECONTENTS_SIZE 0x00000001 +#define FILECONTENTS_RANGE 0x00000002 + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Special Clipboard Response Formats */ + + typedef struct + { + UINT32 mappingMode; + UINT32 xExt; + UINT32 yExt; + UINT32 metaFileSize; + BYTE* metaFileData; + } CLIPRDR_MFPICT; + + /* Clipboard Messages */ + + typedef struct + { + UINT16 msgType; + UINT16 msgFlags; + UINT32 dataLen; + } CLIPRDR_HEADER; + + typedef struct + { + UINT16 capabilitySetType; + UINT16 capabilitySetLength; + } CLIPRDR_CAPABILITY_SET; + + typedef struct + { + UINT16 capabilitySetType; + UINT16 capabilitySetLength; + + UINT32 version; + UINT32 generalFlags; + } CLIPRDR_GENERAL_CAPABILITY_SET; + + typedef struct + { + CLIPRDR_HEADER common; + + UINT32 cCapabilitiesSets; + CLIPRDR_CAPABILITY_SET* capabilitySets; + } CLIPRDR_CAPABILITIES; + + typedef struct + { + CLIPRDR_HEADER common; + } CLIPRDR_MONITOR_READY; + + typedef struct + { + CLIPRDR_HEADER common; + + char szTempDir[520]; + } CLIPRDR_TEMP_DIRECTORY; + + typedef struct + { + UINT32 formatId; + char* formatName; + } CLIPRDR_FORMAT; + + typedef struct + { + CLIPRDR_HEADER common; + + UINT32 numFormats; + CLIPRDR_FORMAT* formats; + } CLIPRDR_FORMAT_LIST; + + typedef struct + { + CLIPRDR_HEADER common; + } CLIPRDR_FORMAT_LIST_RESPONSE; + + typedef struct + { + CLIPRDR_HEADER common; + + UINT32 clipDataId; + } CLIPRDR_LOCK_CLIPBOARD_DATA; + + typedef struct + { + CLIPRDR_HEADER common; + + UINT32 clipDataId; + } CLIPRDR_UNLOCK_CLIPBOARD_DATA; + + typedef struct + { + CLIPRDR_HEADER common; + + UINT32 requestedFormatId; + } CLIPRDR_FORMAT_DATA_REQUEST; + + typedef struct + { + CLIPRDR_HEADER common; + + const BYTE* requestedFormatData; + } CLIPRDR_FORMAT_DATA_RESPONSE; + + typedef struct + { + CLIPRDR_HEADER common; + + UINT32 streamId; + UINT32 listIndex; + UINT32 dwFlags; + UINT32 nPositionLow; + UINT32 nPositionHigh; + UINT32 cbRequested; + BOOL haveClipDataId; + UINT32 clipDataId; + } CLIPRDR_FILE_CONTENTS_REQUEST; + + typedef struct + { + CLIPRDR_HEADER common; + + UINT32 streamId; + UINT32 cbRequested; + const BYTE* requestedData; + } CLIPRDR_FILE_CONTENTS_RESPONSE; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_CLIPRDR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/disp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/disp.h new file mode 100644 index 0000000000000000000000000000000000000000..8e08bf2630af60df0d22d8643a2791c111255c08 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/disp.h @@ -0,0 +1,89 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPEDISP Virtual Channel Extension + * + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DISP_H +#define FREERDP_CHANNEL_DISP_H + +#include +#include + +#define DISPLAY_CONTROL_PDU_TYPE_CAPS 0x00000005 +#define DISPLAY_CONTROL_PDU_TYPE_MONITOR_LAYOUT 0x00000002 +#define DISPLAY_CONTROL_MONITOR_LAYOUT_SIZE 40 + +#define DISP_CHANNEL_NAME "disp" + +#define DISP_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::DisplayControl" +#define ORIENTATION_LANDSCAPE 0 +#define ORIENTATION_PORTRAIT 90 +#define ORIENTATION_LANDSCAPE_FLIPPED 180 +#define ORIENTATION_PORTRAIT_FLIPPED 270 + +#define DISPLAY_CONTROL_MONITOR_PRIMARY 0x00000001 +#define DISPLAY_CONTROL_HEADER_LENGTH 0x00000008 + +#define DISPLAY_CONTROL_MIN_MONITOR_WIDTH 200 +#define DISPLAY_CONTROL_MAX_MONITOR_WIDTH 8192 + +#define DISPLAY_CONTROL_MIN_MONITOR_HEIGHT 200 +#define DISPLAY_CONTROL_MAX_MONITOR_HEIGHT 8192 + +#define DISPLAY_CONTROL_MIN_PHYSICAL_MONITOR_WIDTH 10 +#define DISPLAY_CONTROL_MAX_PHYSICAL_MONITOR_WIDTH 10000 + +#define DISPLAY_CONTROL_MIN_PHYSICAL_MONITOR_HEIGHT 10 +#define DISPLAY_CONTROL_MAX_PHYSICAL_MONITOR_HEIGHT 10000 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 type; + UINT32 length; + } DISPLAY_CONTROL_HEADER; + + typedef struct + { + UINT32 Flags; + INT32 Left; + INT32 Top; + UINT32 Width; + UINT32 Height; + UINT32 PhysicalWidth; + UINT32 PhysicalHeight; + UINT32 Orientation; + UINT32 DesktopScaleFactor; + UINT32 DeviceScaleFactor; + } DISPLAY_CONTROL_MONITOR_LAYOUT; + + typedef struct + { + UINT32 MonitorLayoutSize; + UINT32 NumMonitors; + DISPLAY_CONTROL_MONITOR_LAYOUT* Monitors; + } DISPLAY_CONTROL_MONITOR_LAYOUT_PDU; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_DISP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/drdynvc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/drdynvc.h new file mode 100644 index 0000000000000000000000000000000000000000..7d49e157cdf808886b7d6ebc2f28790e1991f8d7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/drdynvc.h @@ -0,0 +1,72 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic Virtual Channel Virtual Channel + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DRDYNVC_H +#define FREERDP_CHANNEL_DRDYNVC_H + +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define DRDYNVC_CHANNEL_NAME "drdynvc" +#define DRDYNVC_SVC_CHANNEL_NAME "drdynvc" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* defined in MS-RDPEDYC 2.2.5.1 Soft-Sync Request PDU (DYNVC_SOFT_SYNC_REQUEST) */ + enum + { + SOFT_SYNC_TCP_FLUSHED = 0x01, + SOFT_SYNC_CHANNEL_LIST_PRESENT = 0x02 + }; + + /* define in MS-RDPEDYC 2.2.5.1.1 Soft-Sync Channel List (DYNVC_SOFT_SYNC_CHANNEL_LIST) */ + enum + { + TUNNELTYPE_UDPFECR = 0x00000001, + TUNNELTYPE_UDPFECL = 0x00000003 + }; + + /* @brief dynamic channel commands */ + typedef enum + { + CREATE_REQUEST_PDU = 0x01, + DATA_FIRST_PDU = 0x02, + DATA_PDU = 0x03, + CLOSE_REQUEST_PDU = 0x04, + CAPABILITY_REQUEST_PDU = 0x05, + DATA_FIRST_COMPRESSED_PDU = 0x06, + DATA_COMPRESSED_PDU = 0x07, + SOFT_SYNC_REQUEST_PDU = 0x08, + SOFT_SYNC_RESPONSE_PDU = 0x09 + } DynamicChannelPDU; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_DRDYNVC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/echo.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/echo.h new file mode 100644 index 0000000000000000000000000000000000000000..346be31f8a6ff7c4f3690e62185dee4b36810bd4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/echo.h @@ -0,0 +1,42 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel + * + * Copyright 2020 Armin Novak + * Copyright 2020 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_ECHO_H +#define FREERDP_CHANNEL_ECHO_H + +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define ECHO_CHANNEL_NAME "echo" +#define ECHO_DVC_CHANNEL_NAME "ECHO" + +#ifdef __cplusplus +extern "C" +{ +#endif +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_ECHO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/encomsp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/encomsp.h new file mode 100644 index 0000000000000000000000000000000000000000..d13570bbfb5ecc8ce7434930bbb60e39ffb1249c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/encomsp.h @@ -0,0 +1,186 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Multiparty Virtual Channel + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_ENCOMSP_H +#define FREERDP_CHANNEL_ENCOMSP_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define ENCOMSP_CHANNEL_NAME "encomsp" +#define ENCOMSP_SVC_CHANNEL_NAME "encomsp" + +typedef struct +{ + UINT16 cchString; + WCHAR wString[1024]; +} ENCOMSP_UNICODE_STRING; + +/* Filter Updated PDU Flags */ + +#define ENCOMSP_FILTER_ENABLED 0x0001 + +/* Application Created PDU Flags */ + +#define ENCOMSP_APPLICATION_SHARED 0x0001 + +/* Window Created PDU Flags */ + +#define ENCOMSP_WINDOW_SHARED 0x0001 + +/* Participant Created PDU Flags */ + +#define ENCOMSP_MAY_VIEW 0x0001 +#define ENCOMSP_MAY_INTERACT 0x0002 +#define ENCOMSP_IS_PARTICIPANT 0x0004 + +/* Participant Removed PDU Disconnection Types */ + +#define ENCOMSP_PARTICIPANT_DISCONNECTION_REASON_APP 0x00000000 +#define ENCOMSP_PARTICIPANT_DISCONNECTION_REASON_CLI 0x00000002 + +/* Change Participant Control Level PDU Flags */ + +#define ENCOMSP_REQUEST_VIEW 0x0001 +#define ENCOMSP_REQUEST_INTERACT 0x0002 +#define ENCOMSP_ALLOW_CONTROL_REQUESTS 0x0008 + +/* PDU Order Types */ + +#define ODTYPE_FILTER_STATE_UPDATED 0x0001 +#define ODTYPE_APP_REMOVED 0x0002 +#define ODTYPE_APP_CREATED 0x0003 +#define ODTYPE_WND_REMOVED 0x0004 +#define ODTYPE_WND_CREATED 0x0005 +#define ODTYPE_WND_SHOW 0x0006 +#define ODTYPE_PARTICIPANT_REMOVED 0x0007 +#define ODTYPE_PARTICIPANT_CREATED 0x0008 +#define ODTYPE_PARTICIPANT_CTRL_CHANGED 0x0009 +#define ODTYPE_GRAPHICS_STREAM_PAUSED 0x000A +#define ODTYPE_GRAPHICS_STREAM_RESUMED 0x000B + +#define DEFINE_ENCOMSP_HEADER_COMMON() \ + UINT16 Type; \ + UINT16 Length + +#define ENCOMSP_ORDER_HEADER_SIZE 4 + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); +} ENCOMSP_ORDER_HEADER; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + BYTE Flags; +} ENCOMSP_FILTER_UPDATED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT16 Flags; + UINT32 AppId; + ENCOMSP_UNICODE_STRING Name; +} ENCOMSP_APPLICATION_CREATED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT32 AppId; +} ENCOMSP_APPLICATION_REMOVED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT16 Flags; + UINT32 AppId; + UINT32 WndId; + ENCOMSP_UNICODE_STRING Name; +} ENCOMSP_WINDOW_CREATED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT32 WndId; +} ENCOMSP_WINDOW_REMOVED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT32 WndId; +} ENCOMSP_SHOW_WINDOW_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT32 ParticipantId; + UINT32 GroupId; + UINT16 Flags; + ENCOMSP_UNICODE_STRING FriendlyName; +} ENCOMSP_PARTICIPANT_CREATED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT32 ParticipantId; + UINT32 DiscType; + UINT32 DiscCode; +} ENCOMSP_PARTICIPANT_REMOVED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); + + UINT16 Flags; + UINT32 ParticipantId; +} ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); +} ENCOMSP_GRAPHICS_STREAM_PAUSED_PDU; + +typedef struct +{ + DEFINE_ENCOMSP_HEADER_COMMON(); +} ENCOMSP_GRAPHICS_STREAM_RESUMED_PDU; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_ENCOMSP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/geometry.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/geometry.h new file mode 100644 index 0000000000000000000000000000000000000000..14ada2452ef1d4b12b9417d17503d8e29644cdbb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/geometry.h @@ -0,0 +1,73 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Geometry tracking Virtual Channel Extension + * + * Copyright 2017 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_GEOMETRY_H +#define FREERDP_CHANNEL_GEOMETRY_H + +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define GEOMETRY_CHANNEL_NAME "geometry" +#define GEOMETRY_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::Geometry::v08.01" + +#ifdef __cplusplus +extern "C" +{ +#endif + + enum + { + GEOMETRY_UPDATE = 1, + GEOMETRY_CLEAR = 2 + }; + + enum + { + RDH_RECTANGLE = 1 + }; + + typedef struct + { + RDP_RECT boundingRect; + UINT32 nRectCount; + RDP_RECT* rects; + } FREERDP_RGNDATA; + + typedef struct + { + UINT32 version; + UINT64 mappingId; + UINT32 updateType; + UINT64 topLevelId; + INT32 left, top, right, bottom; + INT32 topLevelLeft, topLevelTop, topLevelRight, topLevelBottom; + UINT32 geometryType; + + FREERDP_RGNDATA geometry; + } MAPPED_GEOMETRY_PACKET; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_GEOMETRY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/gfxredir.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/gfxredir.h new file mode 100644 index 0000000000000000000000000000000000000000..ff0beacbe6243e45eb478eedf5d283b058b027dc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/gfxredir.h @@ -0,0 +1,165 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPXXXX Remote App Graphics Redirection Virtual Channel Extension + * + * Copyright 2020 Hideyuki Nagase + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_GFXREDIR_H +#define FREERDP_CHANNEL_GFXREDIR_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define GFXREDIR_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::RemoteAppGraphicsRedirection" + +/* GFXREDIR_LEGACY_CAPS_PDU.version */ +#define GFXREDIR_CHANNEL_VERSION_LEGACY 1 + +#define GFXREDIR_CHANNEL_VERSION_MAJOR 2 +#define GFXREDIR_CHANNEL_VERSION_MINOR 0 + +/* GFXREDIR_CAPS_VERSION1 */ +#define GFXREDIR_CMDID_LEGACY_CAPS 0x00000001 +#define GFXREDIR_CMDID_ERROR 0x00000006 +#define GFXREDIR_CMDID_CAPS_ADVERTISE 0x00000008 +#define GFXREDIR_CMDID_CAPS_CONFIRM 0x00000009 +/* GFXREDIR_CAPS_VERSION2_0 */ +#define GFXREDIR_CMDID_OPEN_POOL 0x0000000a +#define GFXREDIR_CMDID_CLOSE_POOL 0x0000000b +#define GFXREDIR_CMDID_CREATE_BUFFER 0x0000000c +#define GFXREDIR_CMDID_DESTROY_BUFFER 0x0000000d +#define GFXREDIR_CMDID_PRESENT_BUFFER 0x0000000e +#define GFXREDIR_CMDID_PRESENT_BUFFER_ACK 0x0000000f + +/* GFXREDIR_HEADER */ +#define GFXREDIR_HEADER_SIZE 8 + +/* GFXREDIR_CAPS_HEADER */ +#define GFXREDIR_CAPS_HEADER_SIZE 12 +/* GFXREDIR_CAPS_HEADER.signature */ +#define GFXREDIR_CAPS_SIGNATURE 0x53504143 /* = 'SPAC' */ +/* GFXREDIR_CAPS_HEADER.version */ +#define GFXREDIR_CAPS_VERSION1 0x1 +#define GFXREDIR_CAPS_VERSION2_0 0x2000 + +/* GFXREDIR_CREATE_BUFFER_PDU.format */ +#define GFXREDIR_BUFFER_PIXEL_FORMAT_XRGB_8888 1 +#define GFXREDIR_BUFFER_PIXEL_FORMAT_ARGB_8888 2 + +/* GFXREDIR_PRESENT_BUFFER_PDU.numOpaqueRects */ +#define GFXREDIR_MAX_OPAQUE_RECTS 0x10 + +typedef struct +{ + UINT32 cmdId; + UINT32 length; +} GFXREDIR_HEADER; + +typedef struct +{ + UINT16 version; // GFXREDIR_CHANNEL_VERSION_LEGACY +} GFXREDIR_LEGACY_CAPS_PDU; + +typedef struct +{ + UINT32 signature; // GFXREDIR_CAPS_SIGNATURE + UINT32 version; // GFXREDIR_CAPS_VERSION + UINT32 length; // GFXREDIR_CAPS_HEADER_SIZE + size of capsData +} GFXREDIR_CAPS_HEADER; + +typedef struct +{ + GFXREDIR_CAPS_HEADER header; + UINT32 supportedFeatures; /* Reserved for future extensions */ +} GFXREDIR_CAPS_V2_0_PDU; + +typedef struct +{ + UINT32 errorCode; +} GFXREDIR_ERROR_PDU; + +typedef struct +{ + UINT32 length; // length of caps; + const BYTE* caps; // points variable length array of GFXREDIR_CAPS_HEADER. +} GFXREDIR_CAPS_ADVERTISE_PDU; + +typedef struct +{ + UINT32 version; // confirmed version, must be one of advertised by client. + UINT32 length; // GFXREDIR_CAPS_HEADER_SIZE + size of capsData. + const BYTE* capsData; // confirmed capsData from selected GFXREDIR_CAPS_HEADER.capsData. +} GFXREDIR_CAPS_CONFIRM_PDU; + +typedef struct +{ + UINT64 poolId; + UINT64 poolSize; + UINT32 sectionNameLength; // number of characters, must include null terminated char. + const unsigned short* sectionName; // Windows-style 2 bytes wchar_t with null-terminated. +} GFXREDIR_OPEN_POOL_PDU; + +typedef struct +{ + UINT64 poolId; +} GFXREDIR_CLOSE_POOL_PDU; + +typedef struct +{ + UINT64 poolId; + UINT64 bufferId; + UINT64 offset; + UINT32 stride; + UINT32 width; + UINT32 height; + UINT32 format; // GFXREDIR_BUFFER_PIXEL_FORMAT_ +} GFXREDIR_CREATE_BUFFER_PDU; + +typedef struct +{ + UINT64 bufferId; +} GFXREDIR_DESTROY_BUFFER_PDU; + +typedef struct +{ + UINT64 timestamp; + UINT64 presentId; + UINT64 windowId; + UINT64 bufferId; + UINT32 orientation; // 0, 90, 180 or 270. + UINT32 targetWidth; + UINT32 targetHeight; + RECTANGLE_32 dirtyRect; + UINT32 numOpaqueRects; + RECTANGLE_32* opaqueRects; +} GFXREDIR_PRESENT_BUFFER_PDU; + +typedef struct +{ + UINT64 windowId; + UINT64 presentId; +} GFXREDIR_PRESENT_BUFFER_ACK_PDU; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_GFXREDIR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/location.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/location.h new file mode 100644 index 0000000000000000000000000000000000000000..315475937aa769b065136763e313b4288276515e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/location.h @@ -0,0 +1,128 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Location Virtual Channel Extension + * + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_LOCATION_H +#define FREERDP_CHANNEL_LOCATION_H + +#include +#include +#include + +/** @defgroup channel_location Location Channel + * @brief Location channel providing redirection of client side Network/GPS location to the RDP + * server + * @{ + */ + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define LOCATION_CHANNEL_NAME "location" /** @since version 3.4.0 */ + +#define LOCATION_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::Location" + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + PDUTYPE_LOC_RESERVED = 0x0000, + PDUTYPE_SERVER_READY = 0x0001, + PDUTYPE_CLIENT_READY = 0x0002, + PDUTYPE_BASE_LOCATION3D = 0x0003, + PDUTYPE_LOCATION2D_DELTA = 0x0004, + PDUTYPE_LOCATION3D_DELTA = 0x0005, + } LOCATION_PDUTYPE; + +#define LOCATION_HEADER_SIZE 6 + + typedef struct + { + LOCATION_PDUTYPE pduType; + UINT32 pduLength; + } RDPLOCATION_HEADER; + + typedef enum + { + RDPLOCATION_PROTOCOL_VERSION_100 = 0x00010000, + RDPLOCATION_PROTOCOL_VERSION_200 = 0x00020000, + } RDPLOCATION_PROTOCOL_VERSION; + + typedef struct + { + RDPLOCATION_HEADER header; + RDPLOCATION_PROTOCOL_VERSION protocolVersion; + UINT32 flags; + } RDPLOCATION_SERVER_READY_PDU; + + typedef struct + { + RDPLOCATION_HEADER header; + RDPLOCATION_PROTOCOL_VERSION protocolVersion; + UINT32 flags; + } RDPLOCATION_CLIENT_READY_PDU; + + typedef enum + { + LOCATIONSOURCE_IP = 0x00, + LOCATIONSOURCE_WIFI = 0x01, + LOCATIONSOURCE_CELL = 0x02, + LOCATIONSOURCE_GNSS = 0x03, + } LOCATIONSOURCE; + + typedef struct + { + RDPLOCATION_HEADER header; + double latitude; + double longitude; + INT32 altitude; + double* speed; + double* heading; + double* horizontalAccuracy; + LOCATIONSOURCE* source; + } RDPLOCATION_BASE_LOCATION3D_PDU; + + typedef struct + { + RDPLOCATION_HEADER header; + double latitudeDelta; + double longitudeDelta; + double* speedDelta; + double* headingDelta; + } RDPLOCATION_LOCATION2D_DELTA_PDU; + + typedef struct + { + RDPLOCATION_HEADER header; + double latitudeDelta; + double longitudeDelta; + INT32 altitudeDelta; + double* speedDelta; + double* headingDelta; + } RDPLOCATION_LOCATION3D_DELTA_PDU; + +#ifdef __cplusplus +} +#endif +/** @} */ + +#endif /* FREERDP_CHANNEL_LOCATION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/log.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/log.h new file mode 100644 index 0000000000000000000000000000000000000000..36934e651f28a5cc36fa76217bd5a3f87b66fff0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/log.h @@ -0,0 +1,35 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Channel log defines + * + * Copyright 2014 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNELS_LOG_H +#define FREERDP_CHANNELS_LOG_H + +#include +#include + +#define CHANNELS_TAG(tag) FREERDP_TAG("channels.") tag + +#ifdef __cplusplus +extern "C" +{ +#endif +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_UTILS_DEBUG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rail.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rail.h new file mode 100644 index 0000000000000000000000000000000000000000..b8d6b46709a508c49c7128f5f36bf3da4d9aecff --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rail.h @@ -0,0 +1,26 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Applications Integrated Locally (RAIL) + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RAIL_H +#define FREERDP_CHANNEL_RAIL_H + +#include +#include + +#endif /* FREERDP_CHANNEL_RAIL_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdp2tcp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdp2tcp.h new file mode 100644 index 0000000000000000000000000000000000000000..24375e5edeff058f1e1de4e180b682c56439b48d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdp2tcp.h @@ -0,0 +1,38 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * TCP redirection Virtual Channel + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDP2TCP_H +#define FREERDP_CHANNEL_RDP2TCP_H + +#include +#include +#include + +#define RDP2TCP_DVC_CHANNEL_NAME "rdp2tcp" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_RDP2TCP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpdr.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpdr.h new file mode 100644 index 0000000000000000000000000000000000000000..2e947f3f2259f55ded9164541736b6f87274ab78 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpdr.h @@ -0,0 +1,396 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Device Redirection Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2010-2012 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPDR_H +#define FREERDP_CHANNEL_RDPDR_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define RDPDR_CHANNEL_NAME "rdpdr" +#define RDPDR_SVC_CHANNEL_NAME "rdpdr" + +#define RDPDR_DEVICE_IO_REQUEST_LENGTH 24 +#define RDPDR_DEVICE_IO_RESPONSE_LENGTH 16 + +#define RDPDR_DEVICE_IO_CONTROL_REQ_HDR_LENGTH 32 +#define RDPDR_DEVICE_IO_CONTROL_RSP_HDR_LENGTH 4 + +#define RDPDR_VERSION_MAJOR 0x0001 + +#define RDPDR_VERSION_MINOR_RDP50 0x0002 +#define RDPDR_VERSION_MINOR_RDP51 0x0005 +#define RDPDR_VERSION_MINOR_RDP52 0x000A +#define RDPDR_VERSION_MINOR_RDP6X 0x000C +#define RDPDR_VERSION_MINOR_RDP10X 0x000D + +/* RDPDR_HEADER.Component */ +enum RDPDR_CTYP +{ + RDPDR_CTYP_CORE = 0x4472, + RDPDR_CTYP_PRN = 0x5052 +}; + +/* RDPDR_HEADER.PacketId */ +enum RDPDR_PAKID +{ + PAKID_CORE_SERVER_ANNOUNCE = 0x496E, + PAKID_CORE_CLIENTID_CONFIRM = 0x4343, + PAKID_CORE_CLIENT_NAME = 0x434E, + PAKID_CORE_DEVICELIST_ANNOUNCE = 0x4441, + PAKID_CORE_DEVICE_REPLY = 0x6472, + PAKID_CORE_DEVICE_IOREQUEST = 0x4952, + PAKID_CORE_DEVICE_IOCOMPLETION = 0x4943, + PAKID_CORE_SERVER_CAPABILITY = 0x5350, + PAKID_CORE_CLIENT_CAPABILITY = 0x4350, + PAKID_CORE_DEVICELIST_REMOVE = 0x444D, + PAKID_CORE_USER_LOGGEDON = 0x554C, + PAKID_PRN_CACHE_DATA = 0x5043, + PAKID_PRN_USING_XPS = 0x5543 +}; + +/* CAPABILITY_HEADER.CapabilityType */ +enum RDPDR_CAP_TYPE +{ + CAP_GENERAL_TYPE = 0x0001, + CAP_PRINTER_TYPE = 0x0002, + CAP_PORT_TYPE = 0x0003, + CAP_DRIVE_TYPE = 0x0004, + CAP_SMARTCARD_TYPE = 0x0005 +}; + +/* CAPABILITY_HEADER.Version */ +enum RDPDR_CAP_VERSION +{ + GENERAL_CAPABILITY_VERSION_01 = 0x00000001, + GENERAL_CAPABILITY_VERSION_02 = 0x00000002, + PRINT_CAPABILITY_VERSION_01 = 0x00000001, + PORT_CAPABILITY_VERSION_01 = 0x00000001, + DRIVE_CAPABILITY_VERSION_01 = 0x00000001, + DRIVE_CAPABILITY_VERSION_02 = 0x00000002, + SMARTCARD_CAPABILITY_VERSION_01 = 0x00000001 +}; + +/* DR_DEVICE_IOREQUEST.MajorFunction */ +enum IRP_MJ +{ + IRP_MJ_CREATE = 0x00000000, + IRP_MJ_CLOSE = 0x00000002, + IRP_MJ_READ = 0x00000003, + IRP_MJ_WRITE = 0x00000004, + IRP_MJ_DEVICE_CONTROL = 0x0000000E, + IRP_MJ_QUERY_VOLUME_INFORMATION = 0x0000000A, + IRP_MJ_SET_VOLUME_INFORMATION = 0x0000000B, + IRP_MJ_QUERY_INFORMATION = 0x00000005, + IRP_MJ_SET_INFORMATION = 0x00000006, + IRP_MJ_DIRECTORY_CONTROL = 0x0000000C, + IRP_MJ_LOCK_CONTROL = 0x00000011 +}; + +/* DR_DEVICE_IOREQUEST.MinorFunction */ +enum IRP_MN +{ + IRP_MN_QUERY_DIRECTORY = 0x00000001, + IRP_MN_NOTIFY_CHANGE_DIRECTORY = 0x00000002 +}; + +/* DR_CREATE_REQ.CreateDisposition */ + +/* DR_CREATE_REQ.CreateOptions [MS-SMB2] */ + +/* DR_CREATE_REQ.DesiredAccess [MS-SMB2] */ + +/* DR_CREATE_RSP.Information */ +/* DR_DRIVE_CREATE_RSP.DeviceCreateResponse */ + + +/* DR_CORE_CLIENT_ANNOUNCE_RSP.VersionMinor */ +#define RDPDR_MAJOR_RDP_VERSION 1 +enum RDPDR_MINOR_RDP_VERSION +{ + RDPDR_MINOR_RDP_VERSION_5_0 = 0x0002, + RDPDR_MINOR_RDP_VERSION_5_1 = 0x0005, + RDPDR_MINOR_RDP_VERSION_5_2 = 0x000A, + RDPDR_MINOR_RDP_VERSION_6_X = 0x000C, + RDPDR_MINOR_RDP_VERSION_13 = 0x000D +}; + +/* DR_CORE_CLIENT_NAME_REQ.UnicodeFlag */ +enum RDPDR_CLIENT_NAME_FLAG +{ + RDPDR_CLIENT_NAME_UNICODE = 0x00000001, + RDPDR_CLIENT_NAME_ASCII = 0x00000000 +}; + +/* GENERAL_CAPS_SET.ioCode1 */ +enum RDPDR_CAPS_IRP_MJ +{ + RDPDR_IRP_MJ_CREATE = 0x00000001, + RDPDR_IRP_MJ_CLEANUP = 0x00000002, + RDPDR_IRP_MJ_CLOSE = 0x00000004, + RDPDR_IRP_MJ_READ = 0x00000008, + RDPDR_IRP_MJ_WRITE = 0x00000010, + RDPDR_IRP_MJ_FLUSH_BUFFERS = 0x00000020, + RDPDR_IRP_MJ_SHUTDOWN = 0x00000040, + RDPDR_IRP_MJ_DEVICE_CONTROL = 0x00000080, + RDPDR_IRP_MJ_QUERY_VOLUME_INFORMATION = 0x00000100, + RDPDR_IRP_MJ_SET_VOLUME_INFORMATION = 0x00000200, + RDPDR_IRP_MJ_QUERY_INFORMATION = 0x00000400, + RDPDR_IRP_MJ_SET_INFORMATION = 0x00000800, + RDPDR_IRP_MJ_DIRECTORY_CONTROL = 0x00001000, + RDPDR_IRP_MJ_LOCK_CONTROL = 0x00002000, + RDPDR_IRP_MJ_QUERY_SECURITY = 0x00004000, + RDPDR_IRP_MJ_SET_SECURITY = 0x00008000 +}; + +/* GENERAL_CAPS_SET.extendedPDU */ +enum RDPDR_CAPS_PDU +{ + RDPDR_DEVICE_REMOVE_PDUS = 0x00000001, + RDPDR_CLIENT_DISPLAY_NAME_PDU = 0x00000002, + RDPDR_USER_LOGGEDON_PDU = 0x00000004 +}; + +/* GENERAL_CAPS_SET.extraFlags1 */ +enum RDPDR_CAPS_FLAG +{ + ENABLE_ASYNCIO = 0x00000001 +}; + +/* DR_DRIVE_LOCK_REQ.Operation */ +enum RDP_LOWIO_OP +{ + RDP_LOWIO_OP_SHAREDLOCK = 0x00000002, + RDP_LOWIO_OP_EXCLUSIVELOCK = 0x00000003, + RDP_LOWIO_OP_UNLOCK = 0x00000004, + RDP_LOWIO_OP_UNLOCK_MULTIPLE = 0x00000005 +}; + +enum RDPDR_PRINTER_ANNOUNCE_FLAG +{ + RDPDR_PRINTER_ANNOUNCE_FLAG_ASCII = 0x00000001, + RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER = 0x00000002, + RDPDR_PRINTER_ANNOUNCE_FLAG_NETWORKPRINTER = 0x00000004, + RDPDR_PRINTER_ANNOUNCE_FLAG_TSPRINTER = 0x00000008, + RDPDR_PRINTER_ANNOUNCE_FLAG_XPSFORMAT = 0x00000010 +}; + +/* [MS-FSCC] FileAttributes */ + +/* Included with winpr/file.h */ + +/* [MS-FSCC] FSCTL Structures */ + +#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600)) +#define FSCTL_LMR_SET_LINK_TRACKING_INFORMATION 0x1400ec +#define FSCTL_PIPE_PEEK 0x11400c +#define FSCTL_PIPE_TRANSCEIVE 0x11c017 +#define FSCTL_PIPE_WAIT 0x110018 +#define FSCTL_QUERY_ON_DISK_VOLUME_INFO 0x9013c +#define FSCTL_QUERY_SPARING_INFO 0x90138 +#endif + +#ifndef _WIN32 +#define FSCTL_CREATE_OR_GET_OBJECT_ID 0x900c0 +#define FSCTL_GET_REPARSE_POINT 0x900a8 +#define FSCTL_GET_RETRIEVAL_POINTERS 0x90073 +#define FSCTL_IS_PATHNAME_VALID 0x9002c +#define FSCTL_READ_FILE_USN_DATA 0x900eb +#define FSCTL_RECALL_FILE 0x90117 +#define FSCTL_QUERY_FAT_BPB 0x90058 +#define FSCTL_QUERY_ALLOCATED_RANGES 0x940cf +#define FSCTL_SET_COMPRESSION 0x9c040 +#define FSCTL_SET_ENCRYPTION 0x900D7 +#define FSCTL_SET_OBJECT_ID 0x90098 +#define FSCTL_SET_OBJECT_ID_EXTENDED 0x900bc +#define FSCTL_SET_REPARSE_POINT 0x900a4 +#define FSCTL_SET_SPARSE 0x900c4 +#define FSCTL_SET_ZERO_DATA 0x980c8 +#define FSCTL_SIS_COPYFILE 0x90100 +#define FSCTL_WRITE_USN_CLOSE_RECORD 0x900ef +#endif + +#if !defined(_WIN32) || (defined(_WIN32) && (_WIN32_WINNT < 0x0600)) +#define FSCTL_SET_DEFECT_MANAGEMENT 0x98134 +#define FSCTL_SET_ZERO_ON_DEALLOCATION 0x90194 +#endif + +/* [MS-FSCC] FileFsAttributeInformation.FileSystemAttributes */ + +#ifndef _WIN32 + +#define FILE_SUPPORTS_USN_JOURNAL 0x02000000 +#define FILE_SUPPORTS_OPEN_BY_FILE_ID 0x01000000 +#define FILE_SUPPORTS_EXTENDED_ATTRIBUTES 0x00800000 +#define FILE_SUPPORTS_HARD_LINKS 0x00400000 +#define FILE_SUPPORTS_TRANSACTIONS 0x00200000 +#define FILE_SEQUENTIAL_WRITE_ONCE 0x00100000 +#define FILE_READ_ONLY_VOLUME 0x00080000 +#define FILE_NAMED_STREAMS 0x00040000 +#define FILE_SUPPORTS_ENCRYPTION 0x00020000 +#define FILE_SUPPORTS_OBJECT_IDS 0x00010000 +#define FILE_VOLUME_IS_COMPRESSED 0x00008000 +#define FILE_SUPPORTS_REMOTE_STORAGE 0x00000100 +#define FILE_SUPPORTS_REPARSE_POINTS 0x00000080 +#define FILE_SUPPORTS_SPARSE_FILES 0x00000040 +#define FILE_VOLUME_QUOTAS 0x00000020 +#define FILE_FILE_COMPRESSION 0x00000010 +#define FILE_PERSISTENT_ACLS 0x00000008 +#define FILE_UNICODE_ON_DISK 0x00000004 +#define FILE_CASE_PRESERVED_NAMES 0x00000002 +#define FILE_CASE_SENSITIVE_SEARCH 0x00000001 + +#endif + +/* [MS-FSCC] FileFsDeviceInformation.DeviceType */ + +#ifndef FILE_DEVICE_CD_ROM +#define FILE_DEVICE_CD_ROM 0x00000002 +#endif + +#ifndef FILE_DEVICE_DISK +#define FILE_DEVICE_DISK 0x00000007 +#endif + +/* [MS-FSCC] FileFsDeviceInformation.Characteristics */ +enum FILE_FS_DEVICE_FLAG +{ + FILE_REMOVABLE_MEDIA = 0x00000001, + FILE_READ_ONLY_DEVICE = 0x00000002, + FILE_FLOPPY_DISKETTE = 0x00000004, + FILE_WRITE_ONCE_MEDIA = 0x00000008, + FILE_REMOTE_DEVICE = 0x00000010, + FILE_DEVICE_IS_MOUNTED = 0x00000020, + FILE_VIRTUAL_VOLUME = 0x00000040, + FILE_DEVICE_SECURE_OPEN = 0x00000100 +}; + +#ifndef __MINGW32__ +enum FILE_FS_INFORMATION_CLASS +{ + FileFsVolumeInformation = 1, + FileFsLabelInformation, + FileFsSizeInformation, + FileFsDeviceInformation, + FileFsAttributeInformation, + FileFsControlInformation, + FileFsFullSizeInformation, + FileFsObjectIdInformation, + FileFsDriverPathInformation, + FileFsMaximumInformation +}; +#endif + +typedef struct S_DEVICE DEVICE; +typedef struct S_IRP IRP; +typedef struct S_DEVMAN DEVMAN; + +typedef UINT (*pcCustomComponentRequest)(DEVICE* device, UINT16 component, UINT16 packetId, + wStream* s); +typedef UINT (*pcIRPRequest)(DEVICE* device, IRP* irp); +typedef UINT (*pcInitDevice)(DEVICE* device); +typedef UINT (*pcFreeDevice)(DEVICE* device); + +struct S_DEVICE +{ + UINT32 id; + + UINT32 type; + const char* name; + wStream* data; + + pcCustomComponentRequest CustomComponentRequest; + pcIRPRequest IRPRequest; + pcInitDevice Init; + pcFreeDevice Free; +}; + +typedef UINT (*pcIRPResponse)(IRP* irp); + +struct S_IRP +{ + WINPR_SLIST_ENTRY ItemEntry; + + DEVICE* device; + DEVMAN* devman; + UINT32 FileId; + UINT32 CompletionId; + UINT32 MajorFunction; + UINT32 MinorFunction; + wStream* input; + + NTSTATUS IoStatus; + wStream* output; + + pcIRPResponse Complete; + pcIRPResponse Discard; + + HANDLE thread; + BOOL cancelled; +}; + +struct S_DEVMAN +{ + void* plugin; + UINT32 id_sequence; + wListDictionary* devices; +}; + +typedef UINT (*pcRegisterDevice)(DEVMAN* devman, DEVICE* device); + +typedef struct +{ + DEVMAN* devman; + + pcRegisterDevice RegisterDevice; + RDPDR_DEVICE* device; + rdpContext* rdpcontext; +} DEVICE_SERVICE_ENTRY_POINTS; +typedef DEVICE_SERVICE_ENTRY_POINTS* PDEVICE_SERVICE_ENTRY_POINTS; + +typedef UINT(VCAPITYPE* PDEVICE_SERVICE_ENTRY)(PDEVICE_SERVICE_ENTRY_POINTS); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPDR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpear.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpear.h new file mode 100644 index 0000000000000000000000000000000000000000..4be5b76b7f5e79c1570e6c66f19cad1eb70d2a17 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpear.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Authentication redirection channel + * + * Copyright 2023 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEAR_H +#define FREERDP_CHANNEL_RDPEAR_H + +#include +#include +#include + +#define RDPEAR_CHANNEL_NAME "rdpear" +#define RDPEAR_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::AuthRedirection" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPEAR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpecam.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpecam.h new file mode 100644 index 0000000000000000000000000000000000000000..e1ce7317270cc7076078f9531aa9632212e13f3a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpecam.h @@ -0,0 +1,350 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Capture Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPECAM_H +#define FREERDP_CHANNEL_RDPECAM_H + +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define RDPECAM_CHANNEL_NAME "rdpecam" +#define RDPECAM_DVC_CHANNEL_NAME "rdpecam" +#define RDPECAM_CONTROL_DVC_CHANNEL_NAME "RDCamera_Device_Enumerator" + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + CAM_MSG_ID_SuccessResponse = 0x01, + CAM_MSG_ID_ErrorResponse = 0x02, + CAM_MSG_ID_SelectVersionRequest = 0x03, + CAM_MSG_ID_SelectVersionResponse = 0x04, + CAM_MSG_ID_DeviceAddedNotification = 0x05, + CAM_MSG_ID_DeviceRemovedNotification = 0x06, + CAM_MSG_ID_ActivateDeviceRequest = 0x07, + CAM_MSG_ID_DeactivateDeviceRequest = 0x08, + CAM_MSG_ID_StreamListRequest = 0x09, + CAM_MSG_ID_StreamListResponse = 0x0A, + CAM_MSG_ID_MediaTypeListRequest = 0x0B, + CAM_MSG_ID_MediaTypeListResponse = 0x0C, + CAM_MSG_ID_CurrentMediaTypeRequest = 0x0D, + CAM_MSG_ID_CurrentMediaTypeResponse = 0x0E, + CAM_MSG_ID_StartStreamsRequest = 0x0F, + CAM_MSG_ID_StopStreamsRequest = 0x10, + CAM_MSG_ID_SampleRequest = 0x11, + CAM_MSG_ID_SampleResponse = 0x12, + CAM_MSG_ID_SampleErrorResponse = 0x13, + CAM_MSG_ID_PropertyListRequest = 0x14, + CAM_MSG_ID_PropertyListResponse = 0x15, + CAM_MSG_ID_PropertyValueRequest = 0x16, + CAM_MSG_ID_PropertyValueResponse = 0x17, + CAM_MSG_ID_SetPropertyValueRequest = 0x18, + } CAM_MSG_ID; + +#define CAM_HEADER_SIZE 2 + +typedef struct +{ + BYTE Version; + CAM_MSG_ID MessageId; +} CAM_SHARED_MSG_HEADER; + +/* Messages Exchanged on the Device Enumeration Channel (2.2.2) */ + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_SELECT_VERSION_REQUEST; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_SELECT_VERSION_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + WCHAR* DeviceName; + char* VirtualChannelName; +} CAM_DEVICE_ADDED_NOTIFICATION; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + char* VirtualChannelName; +} CAM_DEVICE_REMOVED_NOTIFICATION; + +/* Messages Exchanged on Device Channels (2.2.3) */ + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_SUCCESS_RESPONSE; + +typedef enum +{ + CAM_ERROR_CODE_UnexpectedError = 0x00000001, + CAM_ERROR_CODE_InvalidMessage = 0x00000002, + CAM_ERROR_CODE_NotInitialized = 0x00000003, + CAM_ERROR_CODE_InvalidRequest = 0x00000004, + CAM_ERROR_CODE_InvalidStreamNumber = 0x00000005, + CAM_ERROR_CODE_InvalidMediaType = 0x00000006, + CAM_ERROR_CODE_OutOfMemory = 0x00000007, + CAM_ERROR_CODE_ItemNotFound = 0x00000008, + CAM_ERROR_CODE_SetNotFound = 0x00000009, + CAM_ERROR_CODE_OperationNotSupported = 0x0000000A, +} CAM_ERROR_CODE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + CAM_ERROR_CODE ErrorCode; +} CAM_ERROR_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_ACTIVATE_DEVICE_REQUEST; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_DEACTIVATE_DEVICE_REQUEST; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_STREAM_LIST_REQUEST; + +typedef enum +{ + CAM_STREAM_FRAME_SOURCE_TYPE_Color = 0x0001, + CAM_STREAM_FRAME_SOURCE_TYPE_Infrared = 0x0002, + CAM_STREAM_FRAME_SOURCE_TYPE_Custom = 0x0008, +} CAM_STREAM_FRAME_SOURCE_TYPES; + +typedef enum +{ + CAM_STREAM_CATEGORY_Capture = 0x01, +} CAM_STREAM_CATEGORY; + +typedef struct +{ + CAM_STREAM_FRAME_SOURCE_TYPES FrameSourceTypes; + CAM_STREAM_CATEGORY StreamCategory; + BYTE Selected; + BYTE CanBeShared; +} CAM_STREAM_DESCRIPTION; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + BYTE N_Descriptions; + CAM_STREAM_DESCRIPTION StreamDescriptions[255]; +} CAM_STREAM_LIST_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + BYTE StreamIndex; +} CAM_MEDIA_TYPE_LIST_REQUEST; + +typedef enum +{ + CAM_MEDIA_FORMAT_INVALID = 0x00, + CAM_MEDIA_FORMAT_H264 = 0x01, + CAM_MEDIA_FORMAT_MJPG = 0x02, + CAM_MEDIA_FORMAT_YUY2 = 0x03, + CAM_MEDIA_FORMAT_NV12 = 0x04, + CAM_MEDIA_FORMAT_I420 = 0x05, + CAM_MEDIA_FORMAT_RGB24 = 0x06, + CAM_MEDIA_FORMAT_RGB32 = 0x07, +} CAM_MEDIA_FORMAT; + +typedef enum +{ + CAM_MEDIA_TYPE_DESCRIPTION_FLAG_DecodingRequired = 0x01, + CAM_MEDIA_TYPE_DESCRIPTION_FLAG_BottomUpImage = 0x02, +} CAM_MEDIA_TYPE_DESCRIPTION_FLAGS; + +typedef struct +{ + CAM_MEDIA_FORMAT Format; + UINT32 Width; + UINT32 Height; + UINT32 FrameRateNumerator; + UINT32 FrameRateDenominator; + UINT32 PixelAspectRatioNumerator; + UINT32 PixelAspectRatioDenominator; + CAM_MEDIA_TYPE_DESCRIPTION_FLAGS Flags; +} CAM_MEDIA_TYPE_DESCRIPTION; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + size_t N_Descriptions; + CAM_MEDIA_TYPE_DESCRIPTION* MediaTypeDescriptions; +} CAM_MEDIA_TYPE_LIST_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + BYTE StreamIndex; +} CAM_CURRENT_MEDIA_TYPE_REQUEST; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + CAM_MEDIA_TYPE_DESCRIPTION MediaTypeDescription; +} CAM_CURRENT_MEDIA_TYPE_RESPONSE; + +typedef struct +{ + BYTE StreamIndex; + CAM_MEDIA_TYPE_DESCRIPTION MediaTypeDescription; +} CAM_START_STREAM_INFO; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + BYTE N_Infos; + CAM_START_STREAM_INFO StartStreamsInfo[255]; +} CAM_START_STREAMS_REQUEST; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_STOP_STREAMS_REQUEST; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + BYTE StreamIndex; +} CAM_SAMPLE_REQUEST; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + BYTE StreamIndex; + size_t SampleSize; + BYTE* Sample; +} CAM_SAMPLE_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + BYTE StreamIndex; + CAM_ERROR_CODE ErrorCode; +} CAM_SAMPLE_ERROR_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; +} CAM_PROPERTY_LIST_REQUEST; + +typedef enum +{ + CAM_PROPERTY_SET_CameraControl = 0x01, + CAM_PROPERTY_SET_VideoProcAmp = 0x02, +} CAM_PROPERTY_SET; + +/* CameraControl properties */ +#define CAM_PROPERTY_ID_CAMERA_CONTROL_Exposure 0x01 +#define CAM_PROPERTY_ID_CAMERA_CONTROL_Focus 0x02 +#define CAM_PROPERTY_ID_CAMERA_CONTROL_Pan 0x03 +#define CAM_PROPERTY_ID_CAMERA_CONTROL_Roll 0x04 +#define CAM_PROPERTY_ID_CAMERA_CONTROL_Tilt 0x05 +#define CAM_PROPERTY_ID_CAMERA_CONTROL_Zoom 0x06 + +/* VideoProcAmp properties */ +#define CAM_PROPERTY_ID_VIDEO_PROC_AMP_BacklightCompensation 0x01 +#define CAM_PROPERTY_ID_VIDEO_PROC_AMP_Brightness 0x02 +#define CAM_PROPERTY_ID_VIDEO_PROC_AMP_Contrast 0x03 +#define CAM_PROPERTY_ID_VIDEO_PROC_AMP_Hue 0x04 +#define CAM_PROPERTY_ID_VIDEO_PROC_AMP_WhiteBalance 0x05 + +typedef enum +{ + CAM_PROPERTY_CAPABILITY_Manual = 0x01, + CAM_PROPERTY_CAPABILITY_Auto = 0x02, +} CAM_PROPERTY_CAPABILITIES; + +typedef struct +{ + CAM_PROPERTY_SET PropertySet; + BYTE PropertyId; + CAM_PROPERTY_CAPABILITIES Capabilities; + INT32 MinValue; + INT32 MaxValue; + INT32 Step; + INT32 DefaultValue; +} CAM_PROPERTY_DESCRIPTION; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + size_t N_Properties; + CAM_PROPERTY_DESCRIPTION* Properties; +} CAM_PROPERTY_LIST_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + CAM_PROPERTY_SET PropertySet; + BYTE PropertyId; +} CAM_PROPERTY_VALUE_REQUEST; + +typedef enum +{ + CAM_PROPERTY_MODE_Manual = 0x01, + CAM_PROPERTY_MODE_Auto = 0x02, +} CAM_PROPERTY_MODE; + +typedef struct +{ + CAM_PROPERTY_MODE Mode; + INT32 Value; +} CAM_PROPERTY_VALUE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + CAM_PROPERTY_VALUE PropertyValue; +} CAM_PROPERTY_VALUE_RESPONSE; + +typedef struct +{ + CAM_SHARED_MSG_HEADER Header; + CAM_PROPERTY_SET PropertySet; + BYTE PropertyId; + CAM_PROPERTY_VALUE PropertyValue; +} CAM_SET_PROPERTY_VALUE_REQUEST; + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_RDPECAM_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpei.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpei.h new file mode 100644 index 0000000000000000000000000000000000000000..0555d911f487073ac0f91980fb0346fb3ce036c4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpei.h @@ -0,0 +1,170 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Extended Input channel common definitions + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2014 Thincast Technologies Gmbh. + * Copyright 2014 David FORT + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEI_H +#define FREERDP_CHANNEL_RDPEI_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define RDPINPUT_HEADER_LENGTH 6 + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define RDPEI_CHANNEL_NAME "rdpei" +#define RDPEI_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::Input" + +/** @brief protocol version */ +enum +{ + RDPINPUT_PROTOCOL_V10 = 0x00010000, + RDPINPUT_PROTOCOL_V101 = 0x00010001, + RDPINPUT_PROTOCOL_V200 = 0x00020000, + RDPINPUT_PROTOCOL_V300 = 0x00030000 +}; + +/* Server feature flags */ +#define SC_READY_MULTIPEN_INJECTION_SUPPORTED 0x0001 + +/* Client Ready Flags */ +#define CS_READY_FLAGS_SHOW_TOUCH_VISUALS 0x00000001 +#define CS_READY_FLAGS_DISABLE_TIMESTAMP_INJECTION 0x00000002 +#define CS_READY_FLAGS_ENABLE_MULTIPEN_INJECTION 0x00000004 + +/* 2.2.3.3.1.1 RDPINPUT_TOUCH_CONTACT */ +#define CONTACT_DATA_CONTACTRECT_PRESENT 0x0001 +#define CONTACT_DATA_ORIENTATION_PRESENT 0x0002 +#define CONTACT_DATA_PRESSURE_PRESENT 0x0004 + +typedef enum +{ + RDPINPUT_PEN_CONTACT_PENFLAGS_PRESENT = 0x0001, + RDPINPUT_PEN_CONTACT_PRESSURE_PRESENT = 0x0002, + RDPINPUT_PEN_CONTACT_ROTATION_PRESENT = 0x0004, + RDPINPUT_PEN_CONTACT_TILTX_PRESENT = 0x0008, + RDPINPUT_PEN_CONTACT_TILTY_PRESENT = 0x0010 +} RDPINPUT_PEN_FIELDS_PRESENT; + +/* + * Valid combinations of RDPINPUT_CONTACT_FLAGS: + * + * See [MS-RDPEI] 2.2.3.3.1.1 RDPINPUT_TOUCH_CONTACT and 3.1.1.1 Touch Contact State Transitions + * + * UP + * UP | CANCELED + * UPDATE + * UPDATE | CANCELED + * DOWN | INRANGE | INCONTACT + * UPDATE | INRANGE | INCONTACT + * UP | INRANGE + * UPDATE | INRANGE + */ +typedef enum +{ + RDPINPUT_CONTACT_FLAG_DOWN = 0x0001, + RDPINPUT_CONTACT_FLAG_UPDATE = 0x0002, + RDPINPUT_CONTACT_FLAG_UP = 0x0004, + RDPINPUT_CONTACT_FLAG_INRANGE = 0x0008, + RDPINPUT_CONTACT_FLAG_INCONTACT = 0x0010, + RDPINPUT_CONTACT_FLAG_CANCELED = 0x0020 +} RDPINPUT_CONTACT_FLAGS; + +typedef enum +{ + RDPINPUT_PEN_FLAG_BARREL_PRESSED = 0x0001, + RDPINPUT_PEN_FLAG_ERASER_PRESSED = 0x0002, + RDPINPUT_PEN_FLAG_INVERTED = 0x0004 +} RDPINPUT_PEN_FLAGS; + +/** @brief a contact point */ +typedef struct +{ + UINT32 contactId; + UINT16 fieldsPresent; /* Mask of CONTACT_DATA_*_PRESENT values */ + INT32 x; + INT32 y; + UINT32 contactFlags; /* See RDPINPUT_CONTACT_FLAG* */ + INT16 contactRectLeft; /* Present if CONTACT_DATA_CONTACTRECT_PRESENT */ + INT16 contactRectTop; /* Present if CONTACT_DATA_CONTACTRECT_PRESENT */ + INT16 contactRectRight; /* Present if CONTACT_DATA_CONTACTRECT_PRESENT */ + INT16 contactRectBottom; /* Present if CONTACT_DATA_CONTACTRECT_PRESENT */ + UINT32 orientation; /* Present if CONTACT_DATA_ORIENTATION_PRESENT, values in degree, [0-359] */ + UINT32 pressure; /* Present if CONTACT_DATA_PRESSURE_PRESENT, normalized value [0-1024] */ +} RDPINPUT_CONTACT_DATA; + +/** @brief a frame containing contact points */ +typedef struct +{ + UINT16 contactCount; + UINT64 frameOffset; + RDPINPUT_CONTACT_DATA* contacts; +} RDPINPUT_TOUCH_FRAME; + +/** @brief a touch event with some frames*/ +typedef struct +{ + UINT32 encodeTime; + UINT16 frameCount; + RDPINPUT_TOUCH_FRAME* frames; +} RDPINPUT_TOUCH_EVENT; + +typedef struct +{ + UINT8 deviceId; + UINT16 fieldsPresent; /* Mask of RDPINPUT_PEN_FIELDS_PRESENT values */ + INT32 x; + INT32 y; + UINT32 contactFlags; /* See RDPINPUT_CONTACT_FLAG* */ + UINT32 penFlags; /* Present if RDPINPUT_PEN_CONTACT_PENFLAGS_PRESENT, values see + RDPINPUT_PEN_FLAGS */ + UINT16 rotation; /* Present if RDPINPUT_PEN_CONTACT_ROTATION_PRESENT, In degree, [0-359] */ + UINT32 + pressure; /* Present if RDPINPUT_PEN_CONTACT_PRESSURE_PRESENT, normalized value [0-1024] */ + INT16 tiltX; /* Present if PEN_CONTACT_TILTX_PRESENT, range [-90, 90] */ + INT16 tiltY; /* Present if PEN_CONTACT_TILTY_PRESENT, range [-90, 90] */ +} RDPINPUT_PEN_CONTACT; + +typedef struct +{ + UINT16 contactCount; + UINT64 frameOffset; + RDPINPUT_PEN_CONTACT* contacts; +} RDPINPUT_PEN_FRAME; + +/** @brief a touch event with some frames*/ +typedef struct +{ + UINT32 encodeTime; + UINT16 frameCount; + RDPINPUT_PEN_FRAME* frames; +} RDPINPUT_PEN_EVENT; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPEI_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpemsc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpemsc.h new file mode 100644 index 0000000000000000000000000000000000000000..e2ebb7995a5f22a2d229857aefc881d8b9462ef2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpemsc.h @@ -0,0 +1,154 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Mouse Cursor Virtual Channel Extension + * + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEMSC_H +#define FREERDP_CHANNEL_RDPEMSC_H + +/** @defgroup channel_rdpemsc [MS-RDPEMSC] + * @{ + */ + +/** \file @code [MS-RDPEMSC] @endcode Mouse Cursor Virtual Channel Extension + * \link + * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpemsc/2591b507-cd5a-4537-be29-b45540543dc8 + * \since version 3.0.0 + */ +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define RDPEMSC_CHANNEL_NAME "mousecursor" +#define RDPEMSC_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::MouseCursor" + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + PDUTYPE_EMSC_RESERVED = 0x00, + PDUTYPE_CS_CAPS_ADVERTISE = 0x01, + PDUTYPE_SC_CAPS_CONFIRM = 0x02, + PDUTYPE_SC_MOUSEPTR_UPDATE = 0x03, + } RDP_MOUSE_CURSOR_PDUTYPE; + + typedef enum + { + TS_UPDATETYPE_MOUSEPTR_SYSTEM_NULL = 0x05, + TS_UPDATETYPE_MOUSEPTR_SYSTEM_DEFAULT = 0x06, + TS_UPDATETYPE_MOUSEPTR_POSITION = 0x08, + TS_UPDATETYPE_MOUSEPTR_CACHED = 0x0A, + TS_UPDATETYPE_MOUSEPTR_POINTER = 0x0B, + TS_UPDATETYPE_MOUSEPTR_LARGE_POINTER = 0x0C, + } TS_UPDATETYPE_MOUSEPTR; + +#define RDPEMSC_HEADER_SIZE 4 + + typedef struct + { + RDP_MOUSE_CURSOR_PDUTYPE pduType; + TS_UPDATETYPE_MOUSEPTR updateType; + UINT16 reserved; + } RDP_MOUSE_CURSOR_HEADER; + + typedef enum + { + RDP_MOUSE_CURSOR_CAPVERSION_INVALID = 0x00000000, /** @since version 3.3.0 */ + RDP_MOUSE_CURSOR_CAPVERSION_1 = 0x00000001, + } RDP_MOUSE_CURSOR_CAPVERSION; + + typedef struct + { + UINT32 signature; + RDP_MOUSE_CURSOR_CAPVERSION version; + UINT32 size; + } RDP_MOUSE_CURSOR_CAPSET; + + typedef struct + { + RDP_MOUSE_CURSOR_CAPSET capsetHeader; + } RDP_MOUSE_CURSOR_CAPSET_VERSION1; + + typedef struct + { + RDP_MOUSE_CURSOR_HEADER header; + wArrayList* capsSets; + } RDP_MOUSE_CURSOR_CAPS_ADVERTISE_PDU; + + typedef struct + { + RDP_MOUSE_CURSOR_HEADER header; + RDP_MOUSE_CURSOR_CAPSET* capsSet; + } RDP_MOUSE_CURSOR_CAPS_CONFIRM_PDU; + + typedef struct + { + UINT16 xPos; + UINT16 yPos; + } TS_POINT16; + + typedef struct + { + UINT16 xorBpp; + UINT16 cacheIndex; + TS_POINT16 hotSpot; + UINT16 width; + UINT16 height; + UINT16 lengthAndMask; + UINT16 lengthXorMask; + BYTE* xorMaskData; + BYTE* andMaskData; + BYTE pad; + } TS_POINTERATTRIBUTE; + + typedef struct + { + UINT16 xorBpp; + UINT16 cacheIndex; + TS_POINT16 hotSpot; + UINT16 width; + UINT16 height; + UINT32 lengthAndMask; + UINT32 lengthXorMask; + BYTE* xorMaskData; + BYTE* andMaskData; + BYTE pad; + } TS_LARGEPOINTERATTRIBUTE; + + typedef struct + { + RDP_MOUSE_CURSOR_HEADER header; + TS_POINT16* position; + UINT16* cachedPointerIndex; + TS_POINTERATTRIBUTE* pointerAttribute; + TS_LARGEPOINTERATTRIBUTE* largePointerAttribute; + } RDP_MOUSE_CURSOR_MOUSEPTR_UPDATE_PDU; + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif /* FREERDP_CHANNEL_RDPEMSC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpewa.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpewa.h new file mode 100644 index 0000000000000000000000000000000000000000..6005d5673e0ffbba2ddd7428b008b281e85e4d95 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpewa.h @@ -0,0 +1,43 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Capture Virtual Channel Extension + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEWA_H +#define FREERDP_CHANNEL_RDPEWA_H + +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define RDPEWA_CHANNEL_NAME "rdpewa" +#define RDPEWA_DVC_CHANNEL_NAME "rdpewa" + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_RDPEWA_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpgfx.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpgfx.h new file mode 100644 index 0000000000000000000000000000000000000000..6efe3bdb8c7662e1c8b2384bad31866d5fad5db9 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpgfx.h @@ -0,0 +1,413 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPGFX_H +#define FREERDP_CHANNEL_RDPGFX_H + +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define RDPGFX_CHANNEL_NAME "rdpgfx" +#define RDPGFX_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::Graphics" + +#ifdef __cplusplus +extern "C" +{ +#endif + /** + * Common Data Types + */ + + typedef struct + { + UINT16 x; + UINT16 y; + } RDPGFX_POINT16; + + typedef struct + { + BYTE B; + BYTE G; + BYTE R; + BYTE XA; + } RDPGFX_COLOR32; + +#define GFX_PIXEL_FORMAT_XRGB_8888 0x20 +#define GFX_PIXEL_FORMAT_ARGB_8888 0x21 + +typedef BYTE RDPGFX_PIXELFORMAT; + +#define RDPGFX_CMDID_UNUSED_0000 0x0000 +#define RDPGFX_CMDID_WIRETOSURFACE_1 0x0001 +#define RDPGFX_CMDID_WIRETOSURFACE_2 0x0002 +#define RDPGFX_CMDID_DELETEENCODINGCONTEXT 0x0003 +#define RDPGFX_CMDID_SOLIDFILL 0x0004 +#define RDPGFX_CMDID_SURFACETOSURFACE 0x0005 +#define RDPGFX_CMDID_SURFACETOCACHE 0x0006 +#define RDPGFX_CMDID_CACHETOSURFACE 0x0007 +#define RDPGFX_CMDID_EVICTCACHEENTRY 0x0008 +#define RDPGFX_CMDID_CREATESURFACE 0x0009 +#define RDPGFX_CMDID_DELETESURFACE 0x000A +#define RDPGFX_CMDID_STARTFRAME 0x000B +#define RDPGFX_CMDID_ENDFRAME 0x000C +#define RDPGFX_CMDID_FRAMEACKNOWLEDGE 0x000D +#define RDPGFX_CMDID_RESETGRAPHICS 0x000E +#define RDPGFX_CMDID_MAPSURFACETOOUTPUT 0x000F +#define RDPGFX_CMDID_CACHEIMPORTOFFER 0x0010 +#define RDPGFX_CMDID_CACHEIMPORTREPLY 0x0011 +#define RDPGFX_CMDID_CAPSADVERTISE 0x0012 +#define RDPGFX_CMDID_CAPSCONFIRM 0x0013 +#define RDPGFX_CMDID_UNUSED_0014 0x0014 +#define RDPGFX_CMDID_MAPSURFACETOWINDOW 0x0015 +#define RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE 0x0016 +#define RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT 0x0017 +#define RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW 0x0018 + +#define RDPGFX_HEADER_SIZE 8 + +typedef struct +{ + UINT16 cmdId; + UINT16 flags; + UINT32 pduLength; +} RDPGFX_HEADER; + +/** + * Capability Sets [MS-RDPEGFX] 2.2.3 + */ + +#define RDPGFX_CAPVERSION_8 0x00080004 /** [MS-RDPEGFX] 2.2.3.1 */ +#define RDPGFX_CAPVERSION_81 0x00080105 /** [MS-RDPEGFX] 2.2.3.2 */ +#define RDPGFX_CAPVERSION_10 0x000A0002 /** [MS-RDPEGFX] 2.2.3.3 */ +#define RDPGFX_CAPVERSION_101 0x000A0100 /** [MS-RDPEGFX] 2.2.3.4 */ +#define RDPGFX_CAPVERSION_102 0x000A0200 /** [MS-RDPEGFX] 2.2.3.5 */ +#define RDPGFX_CAPVERSION_103 0x000A0301 /** [MS-RDPEGFX] 2.2.3.6 */ +#define RDPGFX_CAPVERSION_104 0x000A0400 /** [MS-RDPEGFX] 2.2.3.7 */ +#define RDPGFX_CAPVERSION_105 0x000A0502 /** [MS-RDPEGFX] 2.2.3.8 */ +#define RDPGFX_CAPVERSION_106 \ + 0x000A0600 /** [MS-RDPEGFX] 2.2.3.9 (the value in the doc is wrong, see \ + * [MS-RDPEGFX]-180912-errata] \ + * Since this is/was documented for a long time, also define \ + * the incorrect value in case some server actually uses it. \ + */ +#define RDPGFX_CAPVERSION_106_ERR 0x000A0601 +#define RDPGFX_CAPVERSION_107 0x000A0701 /** [MS-RDPEGFX] 2.2.3.10 */ + +#define RDPGFX_NUMBER_CAPSETS 11 +#define RDPGFX_CAPSET_BASE_SIZE 8 + +typedef struct +{ + UINT32 version; + UINT32 length; + UINT32 flags; +} RDPGFX_CAPSET; + +#define RDPGFX_CAPS_FLAG_THINCLIENT 0x00000001U /* 8.0+ */ +#define RDPGFX_CAPS_FLAG_SMALL_CACHE 0x00000002U /* 8.0+ */ +#define RDPGFX_CAPS_FLAG_AVC420_ENABLED 0x00000010U /* 8.1+ */ +#define RDPGFX_CAPS_FLAG_AVC_DISABLED 0x00000020U /* 10.0+ */ +#define RDPGFX_CAPS_FLAG_AVC_THINCLIENT 0x00000040U /* 10.3+ */ +#define RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE 0x00000080U /* 10.7+ */ + +typedef struct +{ + UINT32 version; + UINT32 capsDataLength; + UINT32 flags; +} RDPGFX_CAPSET_VERSION8; + +typedef struct +{ + UINT32 version; + UINT32 capsDataLength; + UINT32 flags; +} RDPGFX_CAPSET_VERSION81; + +typedef struct +{ + UINT32 version; + UINT32 capsDataLength; + UINT32 flags; +} RDPGFX_CAPSET_VERSION10; + +/** + * Graphics Messages + */ + +#define RDPGFX_CODECID_UNCOMPRESSED 0x0000 +#define RDPGFX_CODECID_CAVIDEO 0x0003 +#define RDPGFX_CODECID_CLEARCODEC 0x0008 +#define RDPGFX_CODECID_PLANAR 0x000A +#define RDPGFX_CODECID_AVC420 0x000B +#define RDPGFX_CODECID_ALPHA 0x000C +#define RDPGFX_CODECID_AVC444 0x000E +#define RDPGFX_CODECID_AVC444v2 0x000F + +#define RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE 17 + +typedef struct +{ + UINT16 surfaceId; + UINT16 codecId; + RDPGFX_PIXELFORMAT pixelFormat; + RECTANGLE_16 destRect; + UINT32 bitmapDataLength; + BYTE* bitmapData; +} RDPGFX_WIRE_TO_SURFACE_PDU_1; + +#define RDPGFX_CODECID_CAPROGRESSIVE 0x0009 +#define RDPGFX_CODECID_CAPROGRESSIVE_V2 0x000D + +#define RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE 13 + +typedef struct +{ + UINT16 surfaceId; + UINT16 codecId; + UINT32 codecContextId; + RDPGFX_PIXELFORMAT pixelFormat; + UINT32 bitmapDataLength; + BYTE* bitmapData; +} RDPGFX_WIRE_TO_SURFACE_PDU_2; + +typedef struct +{ + UINT32 surfaceId; + UINT32 codecId; + UINT32 contextId; + UINT32 format; /* FreeRDP color format. @see freerdp/codec/color.h */ + UINT32 left; + UINT32 top; + UINT32 right; + UINT32 bottom; + UINT32 width; + UINT32 height; + UINT32 length; + BYTE* data; + void* extra; +} RDPGFX_SURFACE_COMMAND; + +typedef struct +{ + UINT16 surfaceId; + UINT32 codecContextId; +} RDPGFX_DELETE_ENCODING_CONTEXT_PDU; + +typedef struct +{ + UINT16 surfaceId; + RDPGFX_COLOR32 fillPixel; + UINT16 fillRectCount; + RECTANGLE_16* fillRects; +} RDPGFX_SOLID_FILL_PDU; + +typedef struct +{ + UINT16 surfaceIdSrc; + UINT16 surfaceIdDest; + RECTANGLE_16 rectSrc; + UINT16 destPtsCount; + RDPGFX_POINT16* destPts; +} RDPGFX_SURFACE_TO_SURFACE_PDU; + +typedef struct +{ + UINT16 surfaceId; + UINT64 cacheKey; + UINT16 cacheSlot; + RECTANGLE_16 rectSrc; +} RDPGFX_SURFACE_TO_CACHE_PDU; + +typedef struct +{ + UINT16 cacheSlot; + UINT16 surfaceId; + UINT16 destPtsCount; + RDPGFX_POINT16* destPts; +} RDPGFX_CACHE_TO_SURFACE_PDU; + +typedef struct +{ + UINT16 cacheSlot; +} RDPGFX_EVICT_CACHE_ENTRY_PDU; + +typedef struct +{ + UINT16 surfaceId; + UINT16 width; + UINT16 height; + RDPGFX_PIXELFORMAT pixelFormat; +} RDPGFX_CREATE_SURFACE_PDU; + +typedef struct +{ + UINT16 surfaceId; +} RDPGFX_DELETE_SURFACE_PDU; + +#define RDPGFX_START_FRAME_PDU_SIZE 8 + +typedef struct +{ + UINT32 timestamp; + UINT32 frameId; +} RDPGFX_START_FRAME_PDU; + +#define RDPGFX_END_FRAME_PDU_SIZE 4 + +typedef struct +{ + UINT32 frameId; +} RDPGFX_END_FRAME_PDU; + +#define QUEUE_DEPTH_UNAVAILABLE 0x00000000 +#define SUSPEND_FRAME_ACKNOWLEDGEMENT 0xFFFFFFFF + +typedef struct +{ + UINT32 queueDepth; + UINT32 frameId; + UINT32 totalFramesDecoded; +} RDPGFX_FRAME_ACKNOWLEDGE_PDU; + +typedef struct +{ + UINT32 width; + UINT32 height; + UINT32 monitorCount; + MONITOR_DEF* monitorDefArray; +} RDPGFX_RESET_GRAPHICS_PDU; + +typedef struct +{ + UINT16 surfaceId; + UINT16 reserved; + UINT32 outputOriginX; + UINT32 outputOriginY; +} RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU; + +typedef struct +{ + UINT16 surfaceId; + UINT16 reserved; + UINT32 outputOriginX; + UINT32 outputOriginY; + UINT32 targetWidth; + UINT32 targetHeight; +} RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU; + +typedef struct +{ + UINT64 cacheKey; + UINT32 bitmapLength; +} RDPGFX_CACHE_ENTRY_METADATA; + +#define RDPGFX_CACHE_ENTRY_MAX_COUNT 5462 + +typedef struct +{ + UINT16 cacheEntriesCount; + RDPGFX_CACHE_ENTRY_METADATA cacheEntries[RDPGFX_CACHE_ENTRY_MAX_COUNT]; +} RDPGFX_CACHE_IMPORT_OFFER_PDU; + +typedef struct +{ + UINT16 importedEntriesCount; + UINT16 cacheSlots[RDPGFX_CACHE_ENTRY_MAX_COUNT]; +} RDPGFX_CACHE_IMPORT_REPLY_PDU; + +typedef struct +{ + UINT16 capsSetCount; + RDPGFX_CAPSET* capsSets; +} RDPGFX_CAPS_ADVERTISE_PDU; + +typedef struct +{ + RDPGFX_CAPSET* capsSet; +} RDPGFX_CAPS_CONFIRM_PDU; + +typedef struct +{ + UINT16 surfaceId; + UINT64 windowId; + UINT32 mappedWidth; + UINT32 mappedHeight; +} RDPGFX_MAP_SURFACE_TO_WINDOW_PDU; + +typedef struct +{ + UINT16 surfaceId; + UINT64 windowId; + UINT32 mappedWidth; + UINT32 mappedHeight; + UINT32 targetWidth; + UINT32 targetHeight; +} RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU; + +/* H264 */ + +typedef struct +{ + BYTE qpVal; + BYTE qualityVal; + + BYTE qp; + BYTE r; + BYTE p; +} RDPGFX_H264_QUANT_QUALITY; + +typedef struct +{ + UINT32 numRegionRects; + RECTANGLE_16* regionRects; + RDPGFX_H264_QUANT_QUALITY* quantQualityVals; +} RDPGFX_H264_METABLOCK; + +typedef struct +{ + RDPGFX_H264_METABLOCK meta; + UINT32 length; + BYTE* data; +} RDPGFX_AVC420_BITMAP_STREAM; + +typedef struct +{ + UINT32 cbAvc420EncodedBitstream1; + BYTE LC; + RDPGFX_AVC420_BITMAP_STREAM bitstream[2]; +} RDPGFX_AVC444_BITMAP_STREAM; + +typedef struct +{ + UINT32 frameId; + UINT32 timestamp; + UINT16 timeDiffSE; + UINT16 timeDiffEDR; +} RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU; + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_RDPGFX_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpsnd.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpsnd.h new file mode 100644 index 0000000000000000000000000000000000000000..e5c6c6f80ad147afd8333f1bb92566ab4506e253 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/rdpsnd.h @@ -0,0 +1,32 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Virtual Channel Types + * + * Copyright 2012 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPSND_H +#define FREERDP_CHANNEL_RDPSND_H + +#include +#include + +#include + +#define RDPSND_CHANNEL_NAME "rdpsnd" +#define RDPSND_DVC_CHANNEL_NAME "AUDIO_PLAYBACK_DVC" +#define RDPSND_LOSSY_DVC_CHANNEL_NAME "AUDIO_PLAYBACK_LOSSY_DVC" + +#endif /* FREERDP_CHANNEL_RDPSND_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/remdesk.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/remdesk.h new file mode 100644 index 0000000000000000000000000000000000000000..a259e6f44d53f128b016c5155dd0da5538aa8cc1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/remdesk.h @@ -0,0 +1,165 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Assistance Virtual Channel + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_REMDESK_H +#define FREERDP_CHANNEL_REMDESK_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define REMDESK_CHANNEL_NAME "remdesk" +#define REMDESK_SVC_CHANNEL_NAME "remdesk" + +#define REMDESK_ERROR_NOERROR 0 +#define REMDESK_ERROR_NOINFO 1 +#define REMDESK_ERROR_LOCALNOTERROR 3 +#define REMDESK_ERROR_REMOTEBYUSER 4 +#define REMDESK_ERROR_BYSERVER 5 +#define REMDESK_ERROR_DNSLOOKUPFAILED 6 +#define REMDESK_ERROR_OUTOFMEMORY 7 +#define REMDESK_ERROR_CONNECTIONTIMEDOUT 8 +#define REMDESK_ERROR_SOCKETCONNECTFAILED 9 +#define REMDESK_ERROR_HOSTNOTFOUND 11 +#define REMDESK_ERROR_WINSOCKSENDFAILED 12 +#define REMDESK_ERROR_INVALIDIPADDR 14 +#define REMDESK_ERROR_SOCKETRECVFAILED 15 +#define REMDESK_ERROR_INVALIDENCRYPTION 18 +#define REMDESK_ERROR_GETHOSTBYNAMEFAILED 20 +#define REMDESK_ERROR_LICENSINGFAILED 21 +#define REMDESK_ERROR_ENCRYPTIONERROR 22 +#define REMDESK_ERROR_DECRYPTIONERROR 23 +#define REMDESK_ERROR_INVALIDPARAMETERSTRING 24 +#define REMDESK_ERROR_HELPSESSIONNOTFOUND 25 +#define REMDESK_ERROR_INVALIDPASSWORD 26 +#define REMDESK_ERROR_HELPSESSIONEXPIRED 27 +#define REMDESK_ERROR_CANTOPENRESOLVER 28 +#define REMDESK_ERROR_UNKNOWNSESSMGRERROR 29 +#define REMDESK_ERROR_CANTFORMLINKTOUSERSESSION 30 +#define REMDESK_ERROR_RCPROTOCOLERROR 32 +#define REMDESK_ERROR_RCUNKNOWNERROR 33 +#define REMDESK_ERROR_INTERNALERROR 34 +#define REMDESK_ERROR_HELPEERESPONSEPENDING 35 +#define REMDESK_ERROR_HELPEESAIDYES 36 +#define REMDESK_ERROR_HELPEEALREADYBEINGHELPED 37 +#define REMDESK_ERROR_HELPEECONSIDERINGHELP 38 +#define REMDESK_ERROR_HELPEENEVERRESPONDED 40 +#define REMDESK_ERROR_HELPEESAIDNO 41 +#define REMDESK_ERROR_HELPSESSIONACCESSDENIED 42 +#define REMDESK_ERROR_USERNOTFOUND 43 +#define REMDESK_ERROR_SESSMGRERRORNOTINIT 44 +#define REMDESK_ERROR_SELFHELPNOTSUPPORTED 45 +#define REMDESK_ERROR_INCOMPATIBLEVERSION 47 +#define REMDESK_ERROR_SESSIONNOTCONNECTED 48 +#define REMDESK_ERROR_SYSTEMSHUTDOWN 50 +#define REMDESK_ERROR_STOPLISTENBYUSER 51 +#define REMDESK_ERROR_WINSOCK_FAILED 52 +#define REMDESK_ERROR_MISMATCHPARMS 53 +#define REMDESK_ERROR_PASSWORDS_DONT_MATCH 61 +#define REMDESK_ERROR_SHADOWEND_BASE 300 +#define REMDESK_ERROR_SHADOWEND_CONFIGCHANGE 301 +#define REMDESK_ERROR_SHADOWEND_UNKNOWN 302 + +typedef struct +{ + UINT32 DataLength; + char ChannelName[32]; +} REMDESK_CHANNEL_HEADER; + +#define REMDESK_CHANNEL_CTL_NAME "RC_CTL" +#define REMDESK_CHANNEL_CTL_SIZE 22 + +typedef struct +{ + REMDESK_CHANNEL_HEADER ch; + + UINT32 msgType; +} REMDESK_CTL_HEADER; + +#define REMDESK_CTL_REMOTE_CONTROL_DESKTOP 1 +#define REMDESK_CTL_RESULT 2 +#define REMDESK_CTL_AUTHENTICATE 3 +#define REMDESK_CTL_SERVER_ANNOUNCE 4 +#define REMDESK_CTL_DISCONNECT 5 +#define REMDESK_CTL_VERSIONINFO 6 +#define REMDESK_CTL_ISCONNECTED 7 +#define REMDESK_CTL_VERIFY_PASSWORD 8 +#define REMDESK_CTL_EXPERT_ON_VISTA 9 +#define REMDESK_CTL_RANOVICE_NAME 10 +#define REMDESK_CTL_RAEXPERT_NAME 11 +#define REMDESK_CTL_TOKEN 12 + +typedef struct +{ + REMDESK_CTL_HEADER ctlHeader; + + UINT32 result; +} REMDESK_CTL_RESULT_PDU; + +typedef struct +{ + REMDESK_CTL_HEADER ctlHeader; + + UINT32 versionMajor; + UINT32 versionMinor; +} REMDESK_CTL_VERSION_INFO_PDU; + +typedef struct +{ + REMDESK_CTL_HEADER ctlHeader; + + char* raConnectionString; + char* expertBlob; +} REMDESK_CTL_AUTHENTICATE_PDU; + +typedef struct +{ + REMDESK_CTL_HEADER ctlHeader; + + char* raConnectionString; +} REMDESK_CTL_REMOTE_CONTROL_DESKTOP_PDU; + +typedef struct +{ + REMDESK_CTL_HEADER ctlHeader; + + char* expertBlob; +} REMDESK_CTL_VERIFY_PASSWORD_PDU; + +typedef struct +{ + REMDESK_CTL_HEADER ctlHeader; + + BYTE* EncryptedPassword; + UINT32 EncryptedPasswordLength; +} REMDESK_CTL_EXPERT_ON_VISTA_PDU; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_REMDESK_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/scard.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/scard.h new file mode 100644 index 0000000000000000000000000000000000000000..d83e2c8a2638fb83343c6c69fbdd355f0c800c0b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/scard.h @@ -0,0 +1,500 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Smartcard Redirection Virtual Channel + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_SCARD_H +#define FREERDP_CHANNEL_SCARD_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define RDP_SCARD_CTL_CODE(code) \ + CTL_CODE(FILE_DEVICE_FILE_SYSTEM, (code), METHOD_BUFFERED, FILE_ANY_ACCESS) + +#define SCARD_IOCTL_ESTABLISHCONTEXT RDP_SCARD_CTL_CODE(5) /* SCardEstablishContext */ +#define SCARD_IOCTL_RELEASECONTEXT RDP_SCARD_CTL_CODE(6) /* SCardReleaseContext */ +#define SCARD_IOCTL_ISVALIDCONTEXT RDP_SCARD_CTL_CODE(7) /* SCardIsValidContext */ +#define SCARD_IOCTL_LISTREADERGROUPSA RDP_SCARD_CTL_CODE(8) /* SCardListReaderGroupsA */ +#define SCARD_IOCTL_LISTREADERGROUPSW RDP_SCARD_CTL_CODE(9) /* SCardListReaderGroupsW */ +#define SCARD_IOCTL_LISTREADERSA RDP_SCARD_CTL_CODE(10) /* SCardListReadersA */ +#define SCARD_IOCTL_LISTREADERSW RDP_SCARD_CTL_CODE(11) /* SCardListReadersW */ +#define SCARD_IOCTL_INTRODUCEREADERGROUPA RDP_SCARD_CTL_CODE(20) /* SCardIntroduceReaderGroupA */ +#define SCARD_IOCTL_INTRODUCEREADERGROUPW RDP_SCARD_CTL_CODE(21) /* SCardIntroduceReaderGroupW */ +#define SCARD_IOCTL_FORGETREADERGROUPA RDP_SCARD_CTL_CODE(22) /* SCardForgetReaderGroupA */ +#define SCARD_IOCTL_FORGETREADERGROUPW RDP_SCARD_CTL_CODE(23) /* SCardForgetReaderGroupW */ +#define SCARD_IOCTL_INTRODUCEREADERA RDP_SCARD_CTL_CODE(24) /* SCardIntroduceReaderA */ +#define SCARD_IOCTL_INTRODUCEREADERW RDP_SCARD_CTL_CODE(25) /* SCardIntroduceReaderW */ +#define SCARD_IOCTL_FORGETREADERA RDP_SCARD_CTL_CODE(26) /* SCardForgetReaderA */ +#define SCARD_IOCTL_FORGETREADERW RDP_SCARD_CTL_CODE(27) /* SCardForgetReaderW */ +#define SCARD_IOCTL_ADDREADERTOGROUPA RDP_SCARD_CTL_CODE(28) /* SCardAddReaderToGroupA */ +#define SCARD_IOCTL_ADDREADERTOGROUPW RDP_SCARD_CTL_CODE(29) /* SCardAddReaderToGroupW */ +#define SCARD_IOCTL_REMOVEREADERFROMGROUPA \ + RDP_SCARD_CTL_CODE(30) /* SCardRemoveReaderFromGroupA \ + */ +#define SCARD_IOCTL_REMOVEREADERFROMGROUPW \ + RDP_SCARD_CTL_CODE(31) /* SCardRemoveReaderFromGroupW \ + */ +#define SCARD_IOCTL_LOCATECARDSA RDP_SCARD_CTL_CODE(38) /* SCardLocateCardsA */ +#define SCARD_IOCTL_LOCATECARDSW RDP_SCARD_CTL_CODE(39) /* SCardLocateCardsW */ +#define SCARD_IOCTL_GETSTATUSCHANGEA RDP_SCARD_CTL_CODE(40) /* SCardGetStatusChangeA */ +#define SCARD_IOCTL_GETSTATUSCHANGEW RDP_SCARD_CTL_CODE(41) /* SCardGetStatusChangeW */ +#define SCARD_IOCTL_CANCEL RDP_SCARD_CTL_CODE(42) /* SCardCancel */ +#define SCARD_IOCTL_CONNECTA RDP_SCARD_CTL_CODE(43) /* SCardConnectA */ +#define SCARD_IOCTL_CONNECTW RDP_SCARD_CTL_CODE(44) /* SCardConnectW */ +#define SCARD_IOCTL_RECONNECT RDP_SCARD_CTL_CODE(45) /* SCardReconnect */ +#define SCARD_IOCTL_DISCONNECT RDP_SCARD_CTL_CODE(46) /* SCardDisconnect */ +#define SCARD_IOCTL_BEGINTRANSACTION RDP_SCARD_CTL_CODE(47) /* SCardBeginTransaction */ +#define SCARD_IOCTL_ENDTRANSACTION RDP_SCARD_CTL_CODE(48) /* SCardEndTransaction */ +#define SCARD_IOCTL_STATE RDP_SCARD_CTL_CODE(49) /* SCardState */ +#define SCARD_IOCTL_STATUSA RDP_SCARD_CTL_CODE(50) /* SCardStatusA */ +#define SCARD_IOCTL_STATUSW RDP_SCARD_CTL_CODE(51) /* SCardStatusW */ +#define SCARD_IOCTL_TRANSMIT RDP_SCARD_CTL_CODE(52) /* SCardTransmit */ +#define SCARD_IOCTL_CONTROL RDP_SCARD_CTL_CODE(53) /* SCardControl */ +#define SCARD_IOCTL_GETATTRIB RDP_SCARD_CTL_CODE(54) /* SCardGetAttrib */ +#define SCARD_IOCTL_SETATTRIB RDP_SCARD_CTL_CODE(55) /* SCardSetAttrib */ +#define SCARD_IOCTL_ACCESSSTARTEDEVENT RDP_SCARD_CTL_CODE(56) /* SCardAccessStartedEvent */ +#define SCARD_IOCTL_RELEASETARTEDEVENT RDP_SCARD_CTL_CODE(57) /* SCardReleaseStartedEvent */ +#define SCARD_IOCTL_LOCATECARDSBYATRA RDP_SCARD_CTL_CODE(58) /* SCardLocateCardsByATRA */ +#define SCARD_IOCTL_LOCATECARDSBYATRW RDP_SCARD_CTL_CODE(59) /* SCardLocateCardsByATRW */ +#define SCARD_IOCTL_READCACHEA RDP_SCARD_CTL_CODE(60) /* SCardReadCacheA */ +#define SCARD_IOCTL_READCACHEW RDP_SCARD_CTL_CODE(61) /* SCardReadCacheW */ +#define SCARD_IOCTL_WRITECACHEA RDP_SCARD_CTL_CODE(62) /* SCardWriteCacheA */ +#define SCARD_IOCTL_WRITECACHEW RDP_SCARD_CTL_CODE(63) /* SCardWriteCacheW */ +#define SCARD_IOCTL_GETTRANSMITCOUNT RDP_SCARD_CTL_CODE(64) /* SCardGetTransmitCount */ +#define SCARD_IOCTL_GETREADERICON RDP_SCARD_CTL_CODE(65) /* SCardGetReaderIconA */ +#define SCARD_IOCTL_GETDEVICETYPEID RDP_SCARD_CTL_CODE(66) /* SCardGetDeviceTypeIdA */ + +#pragma pack(push, 1) + +/* interface type_scard_pack */ +/* [unique][version][uuid] */ + +typedef struct +{ + /* [range] */ DWORD cbContext; + /* [size_is][unique] */ BYTE pbContext[8]; +} REDIR_SCARDCONTEXT; + +typedef struct +{ + /* [range] */ DWORD cbHandle; + /* [size_is] */ BYTE pbHandle[8]; +} REDIR_SCARDHANDLE; + +typedef struct +{ + LONG ReturnCode; +} Long_Return; + +typedef struct +{ + LONG ReturnCode; + /* [range] */ DWORD cBytes; + /* [size_is][unique] */ BYTE* msz; +} ListReaderGroups_Return, ListReaders_Return; + +typedef struct +{ + LONG ReturnCode; + REDIR_SCARDCONTEXT hContext; +} EstablishContext_Return; + +typedef struct +{ + DWORD dwCurrentState; + DWORD dwEventState; + /* [range] */ DWORD cbAtr; + BYTE rgbAtr[36]; +} ReaderState_Return; + +typedef struct +{ + /* [range] */ DWORD cbAtr; + BYTE rgbAtr[36]; + BYTE rgbMask[36]; +} LocateCards_ATRMask; + +typedef struct +{ + LONG ReturnCode; + /* [range] */ DWORD cReaders; + /* [size_is] */ ReaderState_Return* rgReaderStates; +} LocateCards_Return, GetStatusChange_Return; + +typedef struct +{ + LONG ReturnCode; + ULONG cbDataLen; + BYTE* pbData; +} GetReaderIcon_Return; + +typedef struct +{ + LONG ReturnCode; + ULONG dwDeviceId; +} GetDeviceTypeId_Return; + +typedef struct +{ + LONG ReturnCode; + REDIR_SCARDCONTEXT hContext; + REDIR_SCARDHANDLE hCard; + DWORD dwActiveProtocol; +} Connect_Return; + +typedef struct +{ + LONG ReturnCode; + DWORD dwActiveProtocol; +} Reconnect_Return; + +typedef struct +{ + LONG ReturnCode; + DWORD dwState; + DWORD dwProtocol; + /* [range] */ DWORD cbAtrLen; + /* [size_is][unique] */ BYTE rgAtr[36]; +} State_Return; + +typedef struct +{ + LONG ReturnCode; + /* [range] */ DWORD cBytes; + /* [size_is][unique] */ BYTE* mszReaderNames; + DWORD dwState; + DWORD dwProtocol; + BYTE pbAtr[32]; + /* [range] */ DWORD cbAtrLen; +} Status_Return; + +typedef struct +{ + DWORD dwProtocol; + /* [range] */ DWORD cbExtraBytes; + /* [size_is][unique] */ BYTE* pbExtraBytes; +} SCardIO_Request; + +typedef struct +{ + LONG ReturnCode; + /* [unique] */ LPSCARD_IO_REQUEST pioRecvPci; + /* [range] */ DWORD cbRecvLength; + /* [size_is][unique] */ BYTE* pbRecvBuffer; +} Transmit_Return; + +typedef struct +{ + LONG ReturnCode; + DWORD cTransmitCount; +} GetTransmitCount_Return; + +typedef struct +{ + LONG ReturnCode; + /* [range] */ DWORD cbOutBufferSize; + /* [size_is][unique] */ BYTE* pvOutBuffer; +} Control_Return; + +typedef struct +{ + LONG ReturnCode; + /* [range] */ DWORD cbAttrLen; + /* [size_is][unique] */ BYTE* pbAttr; +} GetAttrib_Return; + +typedef struct +{ + LONG ReturnCode; + /* [range] */ DWORD cbDataLen; + /* [size_is][unique] */ BYTE* pbData; +} ReadCache_Return; +#pragma pack(pop) + +typedef struct +{ + REDIR_SCARDCONTEXT hContext; + REDIR_SCARDHANDLE hCard; +} Handles_Call; + +typedef struct +{ + Handles_Call handles; + LONG fmszGroupsIsNULL; + DWORD cchGroups; +} ListReaderGroups_Call; + +typedef struct +{ + Handles_Call handles; + /* [range] */ DWORD cBytes; + /* [size_is][unique] */ BYTE* mszGroups; + LONG fmszReadersIsNULL; + DWORD cchReaders; +} ListReaders_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwTimeOut; + /* [range] */ DWORD cReaders; + /* [size_is] */ LPSCARD_READERSTATEA rgReaderStates; +} GetStatusChangeA_Call; + +typedef struct +{ + Handles_Call handles; + /* [range] */ DWORD cBytes; + /* [size_is] */ CHAR* mszCards; + /* [range] */ DWORD cReaders; + /* [size_is] */ LPSCARD_READERSTATEA rgReaderStates; +} LocateCardsA_Call; + +typedef struct +{ + Handles_Call handles; + /* [range] */ DWORD cBytes; + /* [size_is] */ WCHAR* mszCards; + /* [range] */ DWORD cReaders; + /* [size_is] */ LPSCARD_READERSTATEW rgReaderStates; +} LocateCardsW_Call; + +typedef struct +{ + Handles_Call handles; + /* [range] */ DWORD cAtrs; + /* [size_is] */ LocateCards_ATRMask* rgAtrMasks; + /* [range] */ DWORD cReaders; + /* [size_is] */ LPSCARD_READERSTATEA rgReaderStates; +} LocateCardsByATRA_Call; + +typedef struct +{ + Handles_Call handles; + /* [range] */ DWORD cAtrs; + /* [size_is] */ LocateCards_ATRMask* rgAtrMasks; + /* [range] */ DWORD cReaders; + /* [size_is] */ LPSCARD_READERSTATEW rgReaderStates; +} LocateCardsByATRW_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwTimeOut; + /* [range] */ DWORD cReaders; + /* [size_is] */ LPSCARD_READERSTATEW rgReaderStates; +} GetStatusChangeW_Call; + +typedef struct +{ + Handles_Call handles; + WCHAR* szReaderName; +} GetReaderIcon_Call; + +typedef struct +{ + Handles_Call handles; + WCHAR* szReaderName; +} GetDeviceTypeId_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwShareMode; + DWORD dwPreferredProtocols; +} Connect_Common_Call; + +typedef struct +{ + Connect_Common_Call Common; + /* [string] */ CHAR* szReader; +} ConnectA_Call; + +typedef struct +{ + Connect_Common_Call Common; + /* [string] */ WCHAR* szReader; +} ConnectW_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwShareMode; + DWORD dwPreferredProtocols; + DWORD dwInitialization; +} Reconnect_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwDisposition; +} HCardAndDisposition_Call; + +typedef struct +{ + Handles_Call handles; + LONG fpbAtrIsNULL; + DWORD cbAtrLen; +} State_Call; + +typedef struct +{ + Handles_Call handles; + LONG fmszReaderNamesIsNULL; + DWORD cchReaderLen; + DWORD cbAtrLen; +} Status_Call; + +typedef struct +{ + Handles_Call handles; + LPSCARD_IO_REQUEST pioSendPci; + /* [range] */ DWORD cbSendLength; + /* [size_is] */ BYTE* pbSendBuffer; + /* [unique] */ LPSCARD_IO_REQUEST pioRecvPci; + LONG fpbRecvBufferIsNULL; + DWORD cbRecvLength; +} Transmit_Call; + +typedef struct +{ + Handles_Call handles; + LONG LongValue; +} Long_Call; + +typedef struct +{ + Handles_Call handles; +} Context_Call; + +typedef struct +{ + Handles_Call handles; + /* [string] */ char* sz; +} ContextAndStringA_Call; + +typedef struct +{ + Handles_Call handles; + /* [string] */ WCHAR* sz; +} ContextAndStringW_Call; + +typedef struct +{ + Handles_Call handles; + /* [string] */ char* sz1; + /* [string] */ char* sz2; +} ContextAndTwoStringA_Call; + +typedef struct +{ + Handles_Call handles; + /* [string] */ WCHAR* sz1; + /* [string] */ WCHAR* sz2; +} ContextAndTwoStringW_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwScope; +} EstablishContext_Call; + +typedef struct +{ + Handles_Call handles; +} GetTransmitCount_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwControlCode; + /* [range] */ DWORD cbInBufferSize; + /* [size_is][unique] */ BYTE* pvInBuffer; + LONG fpvOutBufferIsNULL; + DWORD cbOutBufferSize; +} Control_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwAttrId; + LONG fpbAttrIsNULL; + DWORD cbAttrLen; +} GetAttrib_Call; + +typedef struct +{ + Handles_Call handles; + DWORD dwAttrId; + /* [range] */ DWORD cbAttrLen; + /* [size_is] */ BYTE* pbAttr; +} SetAttrib_Call; + +typedef struct +{ + Handles_Call handles; + UUID* CardIdentifier; + DWORD FreshnessCounter; + LONG fPbDataIsNULL; + DWORD cbDataLen; +} ReadCache_Common; + +typedef struct +{ + ReadCache_Common Common; + /* [string] */ char* szLookupName; +} ReadCacheA_Call; + +typedef struct +{ + ReadCache_Common Common; + /* [string] */ WCHAR* szLookupName; +} ReadCacheW_Call; + +typedef struct +{ + Handles_Call handles; + UUID* CardIdentifier; + DWORD FreshnessCounter; + /* [range] */ DWORD cbDataLen; + /* [size_is][unique] */ BYTE* pbData; +} WriteCache_Common; + +typedef struct +{ + WriteCache_Common Common; + /* [string] */ char* szLookupName; +} WriteCacheA_Call; + +typedef struct +{ + WriteCache_Common Common; + /* [string] */ WCHAR* szLookupName; +} WriteCacheW_Call; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_SCARD_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/telemetry.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/telemetry.h new file mode 100644 index 0000000000000000000000000000000000000000..df992d0209e82c7a64e3b72248a3d41939429495 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/telemetry.h @@ -0,0 +1,51 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Telemetry Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TELEMETRY_H +#define FREERDP_CHANNEL_TELEMETRY_H + +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define TELEMETRY_CHANNEL_NAME "telemetry" +#define TELEMETRY_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::Telemetry" + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 PromptForCredentialsMillis; + UINT32 PromptForCredentialsDoneMillis; + UINT32 GraphicsChannelOpenedMillis; + UINT32 FirstGraphicsReceivedMillis; + } TELEMETRY_RDP_TELEMETRY_PDU; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_TELEMETRY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/tsmf.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/tsmf.h new file mode 100644 index 0000000000000000000000000000000000000000..6d58080d95c005ec199ceec3d3770b051a89337b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/tsmf.h @@ -0,0 +1,40 @@ +/* + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Redirection Virtual Channel - Callback interface + * + * (C) Copyright 2014 Thincast Technologies GmbH + * (C) Copyright 2014 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* DEPRECATION WARNING: + * + * This channel is unmaintained and not used since windows 7. + * Only compile and use it if absolutely necessary, otherwise + * deactivate it or use the newer [MS-RDPEVOR] video redirection. + */ + +#ifndef FREERDP_CHANNEL_TSMF_H +#define FREERDP_CHANNEL_TSMF_H + +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define TSMF_CHANNEL_NAME "tsmf" +#define TSMF_DVC_CHANNEL_NAME "TSMF" + +#endif /* FREERDP_CHANNEL_TSMF_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/urbdrc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/urbdrc.h new file mode 100644 index 0000000000000000000000000000000000000000..1dc51ff485d69f8f4dcce55b63da8112a4b7a38c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/urbdrc.h @@ -0,0 +1,35 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server USB redirection Virtual Channel + * + * Copyright 2019 Armin Novak + * Copyright 2019 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_URBDRC_H +#define FREERDP_CHANNEL_URBDRC_H + +#include +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define URBDRC_CHANNEL_NAME "urbdrc" +#define URBDRC_DVC_CHANNEL_NAME "urbdrc" + +#endif /* FREERDP_CHANNEL_URBDRC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/video.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/video.h new file mode 100644 index 0000000000000000000000000000000000000000..72686357b4a8a68f00ec85f634a2d748dc58652c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/video.h @@ -0,0 +1,126 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Optimized Remoting Virtual Channel Extension + * + * Copyright 2018 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_VIDEO_H +#define FREERDP_CHANNEL_VIDEO_H + +#include +#include + +/** The command line name of the channel + * + * \since version 3.0.0 + */ +#define VIDEO_CHANNEL_NAME "video" +#define VIDEO_CONTROL_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::Video::Control::v08.01" +#define VIDEO_DATA_DVC_CHANNEL_NAME "Microsoft::Windows::RDS::Video::Data::v08.01" + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @brief TSNM packet type */ + enum + { + TSMM_PACKET_TYPE_PRESENTATION_REQUEST = 1, + TSMM_PACKET_TYPE_PRESENTATION_RESPONSE = 2, + TSMM_PACKET_TYPE_CLIENT_NOTIFICATION = 3, + TSMM_PACKET_TYPE_VIDEO_DATA = 4 + }; + + /** @brief TSMM_PRESENTATION_REQUEST commands */ + enum + { + TSMM_START_PRESENTATION = 1, + TSMM_STOP_PRESENTATION = 2 + }; + + /** @brief presentation request struct */ + typedef struct + { + BYTE PresentationId; + BYTE Version; + BYTE Command; + BYTE FrameRate; + UINT32 SourceWidth, SourceHeight; + UINT32 ScaledWidth, ScaledHeight; + UINT64 hnsTimestampOffset; + UINT64 GeometryMappingId; + BYTE VideoSubtypeId[16]; + UINT32 cbExtra; + BYTE* pExtraData; + } TSMM_PRESENTATION_REQUEST; + + /** @brief response to a TSMM_PRESENTATION_REQUEST */ + typedef struct + { + BYTE PresentationId; + } TSMM_PRESENTATION_RESPONSE; + + /** @brief TSMM_VIDEO_DATA flags */ + enum + { + TSMM_VIDEO_DATA_FLAG_HAS_TIMESTAMPS = 0x01, + TSMM_VIDEO_DATA_FLAG_KEYFRAME = 0x02, + TSMM_VIDEO_DATA_FLAG_NEW_FRAMERATE = 0x04 + }; + + /** @brief a video data packet */ + typedef struct + { + BYTE PresentationId; + BYTE Version; + BYTE Flags; + UINT64 hnsTimestamp; + UINT64 hnsDuration; + UINT16 CurrentPacketIndex; + UINT16 PacketsInSample; + UINT32 SampleNumber; + UINT32 cbSample; + BYTE* pSample; + } TSMM_VIDEO_DATA; + + /** @brief values for NotificationType in TSMM_CLIENT_NOTIFICATION */ + enum + { + TSMM_CLIENT_NOTIFICATION_TYPE_NETWORK_ERROR = 1, + TSMM_CLIENT_NOTIFICATION_TYPE_FRAMERATE_OVERRIDE = 2 + }; + + /** @brief struct used when NotificationType is FRAMERATE_OVERRIDE */ + typedef struct + { + UINT32 Flags; + UINT32 DesiredFrameRate; + } TSMM_CLIENT_NOTIFICATION_FRAMERATE_OVERRIDE; + + /** @brief a client to server notification struct */ + typedef struct + { + BYTE PresentationId; + BYTE NotificationType; + TSMM_CLIENT_NOTIFICATION_FRAMERATE_OVERRIDE FramerateOverride; + } TSMM_CLIENT_NOTIFICATION; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_VIDEO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/wtsvc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/wtsvc.h new file mode 100644 index 0000000000000000000000000000000000000000..db7feacc466d5e2d8aa8322a16889dfdc95ed32f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/channels/wtsvc.h @@ -0,0 +1,98 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Virtual Channel Interface + * + * Copyright 2011-2012 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The server-side virtual channel API follows the Microsoft Remote Desktop + * Services API functions WTSVirtualChannel* defined in: + * http://msdn.microsoft.com/en-us/library/windows/desktop/aa383464.aspx + * + * Difference between the MS API are documented in this header. All functions + * are implemented in and integrated with libfreerdp-channels. + * + * Unlike MS API, all functions except WTSVirtualChannelOpenEx in this + * implementation are thread-safe. + */ + +#ifndef FREERDP_WTSVC_H +#define FREERDP_WTSVC_H + +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + enum + { + DRDYNVC_STATE_NONE = 0, + DRDYNVC_STATE_INITIALIZED = 1, + DRDYNVC_STATE_READY = 2, + DRDYNVC_STATE_FAILED = 3 + }; + + typedef BOOL (*psDVCCreationStatusCallback)(void* userdata, UINT32 channelId, + INT32 creationStatus); + + /** + * WTSVirtualChannelManager functions are FreeRDP extensions to the API. + */ +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED_VAR( + "Use WTSVirtualChannelManagerGetEventHandle", + void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count)); +#endif + FREERDP_API BOOL WTSVirtualChannelManagerOpen(HANDLE hServer); + FREERDP_API BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer); + FREERDP_API BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen); + FREERDP_API HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer); + FREERDP_API BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name); + FREERDP_API BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer); + FREERDP_API void WTSVirtualChannelManagerSetDVCCreationCallback(HANDLE hServer, + psDVCCreationStatusCallback cb, + void* userdata); + + /** + * Extended FreeRDP WTS functions for channel handling + */ + FREERDP_API UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name); + FREERDP_API BOOL WTSIsChannelJoinedByName(freerdp_peer* client, const char* channel_name); + FREERDP_API BOOL WTSIsChannelJoinedById(freerdp_peer* client, const UINT16 channel_id); + FREERDP_API BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, + void* handle); + FREERDP_API BOOL WTSChannelSetHandleById(freerdp_peer* client, const UINT16 channel_id, + void* handle); + FREERDP_API void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_name); + FREERDP_API void* WTSChannelGetHandleById(freerdp_peer* client, const UINT16 channel_id); + FREERDP_API const char* WTSChannelGetName(freerdp_peer* client, UINT16 channel_id); + FREERDP_API char** WTSGetAcceptedChannelNames(freerdp_peer* client, size_t* count); + FREERDP_API INT64 WTSChannelGetOptions(freerdp_peer* client, UINT16 channel_id); + + FREERDP_API UINT32 WTSChannelGetIdByHandle(HANDLE hChannelHandle); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_WTSVC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client.h new file mode 100644 index 0000000000000000000000000000000000000000..df81671082e5749c4f8627a03043835fa81136e4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client.h @@ -0,0 +1,323 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Client Interface + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CLIENT_H +#define FREERDP_CLIENT_H + +#include +#include + +#include +#include +#include +#include +#include + +#if defined(CHANNEL_AINPUT_CLIENT) +#include +#endif + +#if defined(CHANNEL_RDPEI_CLIENT) +#include +#endif + +#if defined(CHANNEL_ENCOMSP_CLIENT) +#include +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Entry Points + */ + + typedef BOOL (*pRdpGlobalInit)(void); + typedef void (*pRdpGlobalUninit)(void); + + typedef BOOL (*pRdpClientNew)(freerdp* instance, rdpContext* context); + typedef void (*pRdpClientFree)(freerdp* instance, rdpContext* context); + + typedef int (*pRdpClientStart)(rdpContext* context); + typedef int (*pRdpClientStop)(rdpContext* context); + + struct rdp_client_entry_points_v1 + { + DWORD Size; + DWORD Version; + + rdpSettings* settings; + + pRdpGlobalInit GlobalInit; + pRdpGlobalUninit GlobalUninit; + + DWORD ContextSize; + pRdpClientNew ClientNew; + pRdpClientFree ClientFree; + + pRdpClientStart ClientStart; + pRdpClientStop ClientStop; + }; + +#define RDP_CLIENT_INTERFACE_VERSION 1 +#define RDP_CLIENT_ENTRY_POINT_NAME "RdpClientEntry" + + typedef int (*pRdpClientEntry)(RDP_CLIENT_ENTRY_POINTS* pEntryPoints); + + /* Common Client Interface */ +#define FREERDP_MAX_TOUCH_CONTACTS 10 + + typedef struct + { + ALIGN64 INT32 id; + ALIGN64 UINT32 count; + ALIGN64 INT32 x; + ALIGN64 INT32 y; + ALIGN64 UINT32 flags; + ALIGN64 UINT32 pressure; + } FreeRDP_TouchContact; + +#define FREERDP_MAX_PEN_DEVICES 10 + + typedef struct pen_device + { + ALIGN64 INT32 deviceid; + ALIGN64 UINT32 flags; + ALIGN64 double max_pressure; + ALIGN64 BOOL hovering; + ALIGN64 BOOL pressed; + ALIGN64 INT32 last_x; + ALIGN64 INT32 last_y; + } FreeRDP_PenDevice; + + struct rdp_client_context + { + rdpContext context; + ALIGN64 HANDLE thread; /**< (offset 0) */ +#if defined(CHANNEL_AINPUT_CLIENT) + ALIGN64 AInputClientContext* ainput; /**< (offset 1) */ +#else + UINT64 reserved1; +#endif + +#if defined(CHANNEL_RDPEI_CLIENT) + ALIGN64 RdpeiClientContext* rdpei; /**< (offset 2) */ +#else + UINT64 reserved2; +#endif + + ALIGN64 INT32 lastX; /**< (offset 3) */ + ALIGN64 INT32 lastY; /**< (offset 4) */ + ALIGN64 BOOL mouse_grabbed; /** < (offset 5) */ + +#if defined(CHANNEL_ENCOMSP_CLIENT) + ALIGN64 EncomspClientContext* encomsp; /** < (offset 6) */ + ALIGN64 BOOL controlToggle; /**< (offset 7) */ +#else + UINT64 reserved3[2]; +#endif + ALIGN64 FreeRDP_TouchContact contacts[FREERDP_MAX_TOUCH_CONTACTS]; /**< (offset 8) */ + ALIGN64 FreeRDP_PenDevice pens[FREERDP_MAX_PEN_DEVICES]; /**< (offset 9) */ + UINT64 reserved[128 - 9]; /**< (offset 9) */ + }; + + /* Common client functions */ + + FREERDP_API void freerdp_client_context_free(rdpContext* context); + + WINPR_ATTR_MALLOC(freerdp_client_context_free, 1) + FREERDP_API rdpContext* freerdp_client_context_new(const RDP_CLIENT_ENTRY_POINTS* pEntryPoints); + + FREERDP_API int freerdp_client_start(rdpContext* context); + FREERDP_API int freerdp_client_stop(rdpContext* context); + + FREERDP_API freerdp* freerdp_client_get_instance(rdpContext* context); + FREERDP_API HANDLE freerdp_client_get_thread(rdpContext* context); + + FREERDP_API int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc, + char** argv, BOOL allowUnknown); + + /** + * @brief freerdp_client_settings_parse_command_line_ex + * @param settings Pointer to the settings to populate + * @param argc Number of command line arguments + * @param argv Array of command line arguments + * @param allowUnknown Skip unknown arguments instead of aborting parser + * @param args The allowed command line arguments (client specific, client-common ones are added + * internally) + * @param count Number of client specific command line arguments + * @param handle_userdata Custom user data pointer, will be passed to callback + * @return >=0 for success, <0 in case of parsing failures + * @since version 3.9.0 + */ + FREERDP_API int freerdp_client_settings_parse_command_line_ex( + rdpSettings* settings, int argc, char** argv, BOOL allowUnknown, + COMMAND_LINE_ARGUMENT_A* args, size_t count, + freerdp_command_line_handle_option_t handle_option, void* handle_userdata); + + FREERDP_API int freerdp_client_settings_parse_connection_file(rdpSettings* settings, + const char* filename); + FREERDP_API int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* settings, + const BYTE* buffer, + size_t size); + FREERDP_API int freerdp_client_settings_write_connection_file(const rdpSettings* settings, + const char* filename, + BOOL unicode); + + FREERDP_API int freerdp_client_settings_parse_assistance_file(rdpSettings* settings, int argc, + char* argv[]); + + FREERDP_API BOOL client_cli_authenticate_ex(freerdp* instance, char** username, char** password, + char** domain, rdp_auth_reason reason); + + FREERDP_API BOOL client_cli_choose_smartcard(freerdp* instance, SmartcardCertInfo** cert_list, + DWORD count, DWORD* choice, BOOL gateway); + + FREERDP_API int client_cli_logon_error_info(freerdp* instance, UINT32 data, UINT32 type); + + FREERDP_API BOOL client_cli_get_access_token(freerdp* instance, AccessTokenType tokenType, + char** token, size_t count, ...); + FREERDP_API BOOL client_common_get_access_token(freerdp* instance, const char* request, + char** token); + + FREERDP_API SSIZE_T client_common_retry_dialog(freerdp* instance, const char* what, + size_t current, void* userarg); + + FREERDP_API void + freerdp_client_OnChannelConnectedEventHandler(void* context, + const ChannelConnectedEventArgs* e); + FREERDP_API void + freerdp_client_OnChannelDisconnectedEventHandler(void* context, + const ChannelDisconnectedEventArgs* e); + +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED_VAR("Use client_cli_authenticate_ex", + BOOL client_cli_authenticate(freerdp* instance, + char** username, char** password, + char** domain)); + FREERDP_API + WINPR_DEPRECATED_VAR("Use client_cli_authenticate_ex", + BOOL client_cli_gw_authenticate(freerdp* instance, char** username, + char** password, char** domain)); + + FREERDP_API WINPR_DEPRECATED_VAR( + "Use client_cli_verify_certificate_ex", + DWORD client_cli_verify_certificate(freerdp* instance, const char* common_name, + const char* subject, const char* issuer, + const char* fingerprint, BOOL host_mismatch)); +#endif + + FREERDP_API DWORD client_cli_verify_certificate_ex(freerdp* instance, const char* host, + UINT16 port, const char* common_name, + const char* subject, const char* issuer, + const char* fingerprint, DWORD flags); + +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED_VAR("Use client_cli_verify_changed_certificate_ex", + DWORD client_cli_verify_changed_certificate( + freerdp* instance, const char* common_name, + const char* subject, const char* issuer, + const char* fingerprint, const char* old_subject, + const char* old_issuer, const char* old_fingerprint)); +#endif + + FREERDP_API DWORD client_cli_verify_changed_certificate_ex( + freerdp* instance, const char* host, UINT16 port, const char* common_name, + const char* subject, const char* issuer, const char* fingerprint, const char* old_subject, + const char* old_issuer, const char* old_fingerprint, DWORD flags); + + FREERDP_API BOOL client_cli_present_gateway_message(freerdp* instance, UINT32 type, + BOOL isDisplayMandatory, + BOOL isConsentMandatory, size_t length, + const WCHAR* message); + + FREERDP_API BOOL client_auto_reconnect(freerdp* instance); + FREERDP_API BOOL client_auto_reconnect_ex(freerdp* instance, + BOOL (*window_events)(freerdp* instance)); + + typedef enum + { + FREERDP_TOUCH_DOWN = 0x01, + FREERDP_TOUCH_UP = 0x02, + FREERDP_TOUCH_MOTION = 0x04, + FREERDP_TOUCH_HAS_PRESSURE = 0x100 + } FreeRDPTouchEventType; + + FREERDP_API BOOL freerdp_client_handle_touch(rdpClientContext* cctx, UINT32 flags, INT32 finger, + UINT32 pressure, INT32 x, INT32 y); + + typedef enum + { + FREERDP_PEN_REGISTER = 0x01, + FREERDP_PEN_ERASER_PRESSED = 0x02, + FREERDP_PEN_PRESS = 0x04, + FREERDP_PEN_MOTION = 0x08, + FREERDP_PEN_RELEASE = 0x10, + FREERDP_PEN_BARREL_PRESSED = 0x20, + FREERDP_PEN_HAS_PRESSURE = 0x40, + FREERDP_PEN_HAS_ROTATION = 0x80, + FREERDP_PEN_HAS_TILTX = 0x100, + FREERDP_PEN_HAS_TILTY = 0x200, + FREERDP_PEN_IS_INVERTED = 0x400 + } FreeRDPPenEventType; + + FREERDP_API BOOL freerdp_client_handle_pen(rdpClientContext* cctx, UINT32 flags, INT32 deviceid, + ...); + FREERDP_API BOOL freerdp_client_is_pen(rdpClientContext* cctx, INT32 deviceid); + + FREERDP_API BOOL freerdp_client_pen_cancel_all(rdpClientContext* cctx); + + FREERDP_API BOOL freerdp_client_send_wheel_event(rdpClientContext* cctx, UINT16 mflags); + + FREERDP_API BOOL freerdp_client_send_mouse_event(rdpClientContext* cctx, UINT64 mflags, INT32 x, + INT32 y); + + /** @brief this function checks if relative mouse events are supported and enabled for this + * session. + * + * @param cctx The \b rdpClientContext to check + * + * @return \b TRUE if relative mouse events are to be sent, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_client_use_relative_mouse_events(rdpClientContext* cctx); + + FREERDP_API BOOL freerdp_client_send_button_event(rdpClientContext* cctx, BOOL relative, + UINT16 mflags, INT32 x, INT32 y); + + FREERDP_API BOOL freerdp_client_send_extended_button_event(rdpClientContext* cctx, + BOOL relative, UINT16 mflags, + INT32 x, INT32 y); + + FREERDP_API int freerdp_client_common_stop(rdpContext* context); + + FREERDP_API BOOL freerdp_client_load_channels(freerdp* instance); + +#if defined(CHANNEL_ENCOMSP_CLIENT) + FREERDP_API BOOL freerdp_client_encomsp_toggle_control(EncomspClientContext* encomsp); + FREERDP_API BOOL freerdp_client_encomsp_set_control(EncomspClientContext* encomsp, + BOOL control); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CLIENT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/ainput.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/ainput.h new file mode 100644 index 0000000000000000000000000000000000000000..c4326774768cd2c954ed1fb549f4d728e03fb85b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/ainput.h @@ -0,0 +1,48 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Display Update Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AINPUT_CLIENT_AINPUT_H +#define FREERDP_CHANNEL_AINPUT_CLIENT_AINPUT_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef UINT (*pcAInputSendInputEvent)(AInputClientContext* context, UINT64 flags, INT32 x, + INT32 y); + + struct ainput_client_context + { + void* handle; + void* custom; + + pcAInputSendInputEvent AInputSendInputEvent; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_AINPUT_CLIENT_AINPUT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/audin.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/audin.h new file mode 100644 index 0000000000000000000000000000000000000000..21b6c09f18169d9a64203917d2b0f5b6f2b5b534 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/audin.h @@ -0,0 +1,74 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Input Redirection Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AUDIN_CLIENT_AUDIN_H +#define FREERDP_CHANNEL_AUDIN_CLIENT_AUDIN_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Subsystem Interface + */ + + typedef UINT (*AudinReceive)(const AUDIO_FORMAT* format, const BYTE* data, size_t size, + void* userData); + + typedef struct s_IAudinDevice IAudinDevice; + struct s_IAudinDevice + { + UINT (*Open)(IAudinDevice* devplugin, AudinReceive receive, void* userData); + BOOL (*FormatSupported)(IAudinDevice* devplugin, const AUDIO_FORMAT* format); + UINT(*SetFormat) + (IAudinDevice* devplugin, const AUDIO_FORMAT* format, UINT32 FramesPerPacket); + UINT (*Close)(IAudinDevice* devplugin); + UINT (*Free)(IAudinDevice* devplugin); + }; + +#define AUDIN_DEVICE_EXPORT_FUNC_NAME "freerdp_audin_client_subsystem_entry" + +typedef UINT (*PREGISTERAUDINDEVICE)(IWTSPlugin* plugin, IAudinDevice* device); + +typedef struct +{ + IWTSPlugin* plugin; + PREGISTERAUDINDEVICE pRegisterAudinDevice; + const ADDIN_ARGV* args; + rdpContext* rdpcontext; +} FREERDP_AUDIN_DEVICE_ENTRY_POINTS; +typedef FREERDP_AUDIN_DEVICE_ENTRY_POINTS* PFREERDP_AUDIN_DEVICE_ENTRY_POINTS; + +typedef UINT(VCAPITYPE* PFREERDP_AUDIN_DEVICE_ENTRY)( + PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_AUDIN_CLIENT_AUDIN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/channels.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/channels.h new file mode 100644 index 0000000000000000000000000000000000000000..cfdc866161f7fcc121c023c47141f79d4a3814ad --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/channels.h @@ -0,0 +1,94 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Client Channels + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNELS_CLIENT_H +#define FREERDP_CHANNELS_CLIENT_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + IWTSVirtualChannelCallback iface; + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; + IWTSVirtualChannel* channel; + } GENERIC_CHANNEL_CALLBACK; + + typedef struct + { + IWTSListenerCallback iface; + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; + IWTSVirtualChannel* channel; + GENERIC_CHANNEL_CALLBACK* channel_callback; + } GENERIC_LISTENER_CALLBACK; + + typedef struct GENERIC_DYNVC_PLUGIN GENERIC_DYNVC_PLUGIN; + typedef UINT (*DYNVC_PLUGIN_INIT_FN)(GENERIC_DYNVC_PLUGIN* plugin, rdpContext* context, + rdpSettings* settings); + typedef void (*DYNVC_PLUGIN_TERMINATE_FN)(GENERIC_DYNVC_PLUGIN* plugin); + + struct GENERIC_DYNVC_PLUGIN + { + IWTSPlugin iface; + GENERIC_LISTENER_CALLBACK* listener_callback; + IWTSListener* listener; + BOOL attached; + BOOL initialized; + wLog* log; + char* dynvc_name; + size_t channelCallbackSize; + const IWTSVirtualChannelCallback* channel_callbacks; + DYNVC_PLUGIN_TERMINATE_FN terminatePluginFn; + }; + +#if defined(WITH_CHANNELS) + FREERDP_API void* freerdp_channels_client_find_static_entry(const char* name, + const char* identifier); + FREERDP_API PVIRTUALCHANNELENTRY freerdp_channels_load_static_addin_entry(LPCSTR pszName, + LPCSTR pszSubsystem, + LPCSTR pszType, + DWORD dwFlags); + + FREERDP_API FREERDP_ADDIN** freerdp_channels_list_addins(LPCSTR lpName, LPCSTR lpSubsystem, + LPCSTR lpType, DWORD dwFlags); + FREERDP_API void freerdp_channels_addin_list_free(FREERDP_ADDIN** ppAddins); + + FREERDP_API BOOL freerdp_initialize_generic_dynvc_plugin(GENERIC_DYNVC_PLUGIN* plugin); + FREERDP_API UINT freerdp_generic_DVCPluginEntry( + IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* logTag, const char* name, + size_t pluginSize, size_t channelCallbackSize, + const IWTSVirtualChannelCallback* channel_callbacks, DYNVC_PLUGIN_INIT_FN initPluginFn, + DYNVC_PLUGIN_TERMINATE_FN terminatePluginFn); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNELS_CLIENT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/client_cliprdr_file.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/client_cliprdr_file.h new file mode 100644 index 0000000000000000000000000000000000000000..6dca587f4b305b5a1a21555eefa3cb67e686ea94 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/client_cliprdr_file.h @@ -0,0 +1,105 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * X11 Clipboard Redirection + * + * Copyright 2010-2011 Vic Lee + * Copyright 2023 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CLIENT_X11_CLIPRDR_FILE_H +#define FREERDP_CLIENT_X11_CLIPRDR_FILE_H + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct cliprdr_file_context CliprdrFileContext; + + FREERDP_API void cliprdr_file_context_free(CliprdrFileContext* file); + + WINPR_ATTR_MALLOC(cliprdr_file_context_free, 1) + FREERDP_API CliprdrFileContext* cliprdr_file_context_new(void* context); + + /**! \brief returns if the implementation supports pasting files in a client file browser. + * + * \param file the file context to query + * + * \return \b TRUE if files can be pasted locally, \b FALSE if not (e.g. no FUSE, ...) + */ + FREERDP_API BOOL cliprdr_file_context_has_local_support(CliprdrFileContext* file); + + /**! \brief sets state of local file paste support + * + * \param file the file context to update + * \param available \b TRUE if the client supports pasting files to local file browsers, \b + * FALSE otherwise + * + * \return \b TRUE for success, \b FALSE otherwise + */ + FREERDP_API BOOL cliprdr_file_context_set_locally_available(CliprdrFileContext* file, + BOOL available); + FREERDP_API BOOL cliprdr_file_context_remote_set_flags(CliprdrFileContext* file, UINT32 flags); + FREERDP_API UINT32 cliprdr_file_context_remote_get_flags(CliprdrFileContext* file); + + FREERDP_API UINT32 cliprdr_file_context_current_flags(CliprdrFileContext* file); + + FREERDP_API void* cliprdr_file_context_get_context(CliprdrFileContext* file); + + FREERDP_API BOOL cliprdr_file_context_init(CliprdrFileContext* file, + CliprdrClientContext* cliprdr); + FREERDP_API BOOL cliprdr_file_context_uninit(CliprdrFileContext* file, + CliprdrClientContext* cliprdr); + + FREERDP_API BOOL cliprdr_file_context_clear(CliprdrFileContext* file); + + FREERDP_API UINT + cliprdr_file_context_notify_new_server_format_list(CliprdrFileContext* file_context); + + FREERDP_API UINT + cliprdr_file_context_notify_new_client_format_list(CliprdrFileContext* file_context); + + /** \brief updates the files the client announces to the server + * + * \param file the file context to update + * \param data the file list + * \param count the length of the file list + * + * \return \b TRUE for success, \b FALSE otherwise + */ + FREERDP_API BOOL cliprdr_file_context_update_client_data(CliprdrFileContext* file, + const char* data, size_t count); + /** \brief updates the files the server announces to the client + * + * \param file the file context to update + * \param clip the clipboard instance to use + * \param data the file list [MS-RDPECLIP] 2.2.5.2.3 Packed File List (CLIPRDR_FILELIST) + * \param size the length of the file list + * + * \return \b TRUE for success, \b FALSE otherwise + */ + FREERDP_API BOOL cliprdr_file_context_update_server_data(CliprdrFileContext* file, + wClipboard* clip, const void* data, + size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CLIENT_X11_CLIPRDR_FILE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/cliprdr.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/cliprdr.h new file mode 100644 index 0000000000000000000000000000000000000000..5d1073bf282a12b4a36a74909d9e5e4d1ea0fc66 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/cliprdr.h @@ -0,0 +1,201 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel Extension + * + * Copyright 2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CLIPRDR_CLIENT_CLIPRDR_H +#define FREERDP_CHANNEL_CLIPRDR_CLIENT_CLIPRDR_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + + typedef struct s_cliprdr_client_context CliprdrClientContext; + + typedef UINT (*pcCliprdrServerCapabilities)(CliprdrClientContext* context, + const CLIPRDR_CAPABILITIES* capabilities); + typedef UINT (*pcCliprdrClientCapabilities)(CliprdrClientContext* context, + const CLIPRDR_CAPABILITIES* capabilities); + typedef UINT (*pcCliprdrMonitorReady)(CliprdrClientContext* context, + const CLIPRDR_MONITOR_READY* monitorReady); + typedef UINT (*pcCliprdrTempDirectory)(CliprdrClientContext* context, + const CLIPRDR_TEMP_DIRECTORY* tempDirectory); + typedef UINT (*pcCliprdrClientFormatList)(CliprdrClientContext* context, + const CLIPRDR_FORMAT_LIST* formatList); + typedef UINT (*pcCliprdrServerFormatList)(CliprdrClientContext* context, + const CLIPRDR_FORMAT_LIST* formatList); + typedef UINT (*pcCliprdrClientFormatListResponse)( + CliprdrClientContext* context, const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse); + typedef UINT (*pcCliprdrServerFormatListResponse)( + CliprdrClientContext* context, const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse); + typedef UINT (*pcCliprdrClientLockClipboardData)( + CliprdrClientContext* context, const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData); + typedef UINT (*pcCliprdrServerLockClipboardData)( + CliprdrClientContext* context, const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData); + typedef UINT (*pcCliprdrClientUnlockClipboardData)( + CliprdrClientContext* context, const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData); + typedef UINT (*pcCliprdrServerUnlockClipboardData)( + CliprdrClientContext* context, const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData); + typedef UINT (*pcCliprdrClientFormatDataRequest)( + CliprdrClientContext* context, const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest); + typedef UINT (*pcCliprdrServerFormatDataRequest)( + CliprdrClientContext* context, const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest); + typedef UINT (*pcCliprdrClientFormatDataResponse)( + CliprdrClientContext* context, const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse); + typedef UINT (*pcCliprdrServerFormatDataResponse)( + CliprdrClientContext* context, const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse); + typedef UINT (*pcCliprdrClientFileContentsRequest)( + CliprdrClientContext* context, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest); + typedef UINT (*pcCliprdrServerFileContentsRequest)( + CliprdrClientContext* context, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest); + typedef UINT (*pcCliprdrClientFileContentsResponse)( + CliprdrClientContext* context, const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse); + typedef UINT (*pcCliprdrServerFileContentsResponse)( + CliprdrClientContext* context, const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse); + + struct s_cliprdr_client_context + { + void* handle; + void* custom; + + pcCliprdrServerCapabilities ServerCapabilities; + pcCliprdrClientCapabilities ClientCapabilities; + pcCliprdrMonitorReady MonitorReady; + pcCliprdrTempDirectory TempDirectory; + pcCliprdrClientFormatList ClientFormatList; + pcCliprdrServerFormatList ServerFormatList; + pcCliprdrClientFormatListResponse ClientFormatListResponse; + pcCliprdrServerFormatListResponse ServerFormatListResponse; + pcCliprdrClientLockClipboardData ClientLockClipboardData; + pcCliprdrServerLockClipboardData ServerLockClipboardData; + pcCliprdrClientUnlockClipboardData ClientUnlockClipboardData; + pcCliprdrServerUnlockClipboardData ServerUnlockClipboardData; + pcCliprdrClientFormatDataRequest ClientFormatDataRequest; + pcCliprdrServerFormatDataRequest ServerFormatDataRequest; + pcCliprdrClientFormatDataResponse ClientFormatDataResponse; + pcCliprdrServerFormatDataResponse ServerFormatDataResponse; + pcCliprdrClientFileContentsRequest ClientFileContentsRequest; + pcCliprdrServerFileContentsRequest ServerFileContentsRequest; + pcCliprdrClientFileContentsResponse ClientFileContentsResponse; + pcCliprdrServerFileContentsResponse ServerFileContentsResponse; + + UINT32 lastRequestedFormatId; + rdpContext* rdpcontext; + }; + + typedef struct + { + UINT32 id; + char* name; + int length; + } CLIPRDR_FORMAT_NAME; + + /** + * Clipboard Events + */ + + typedef struct + { + wMessage event; + UINT32 capabilities; + } RDP_CB_CLIP_CAPS; + + typedef struct + { + wMessage event; + UINT32 capabilities; + } RDP_CB_MONITOR_READY_EVENT; + + typedef struct + { + wMessage event; + UINT32* formats; + UINT16 num_formats; + BYTE* raw_format_data; + UINT32 raw_format_data_size; + BOOL raw_format_unicode; + } RDP_CB_FORMAT_LIST_EVENT; + + typedef struct + { + wMessage event; + UINT32 format; + } RDP_CB_DATA_REQUEST_EVENT; + + typedef struct + { + wMessage event; + BYTE* data; + UINT32 size; + } RDP_CB_DATA_RESPONSE_EVENT; + + typedef struct + { + wMessage event; + UINT32 streamId; + UINT32 lindex; + UINT32 dwFlags; + UINT32 nPositionLow; + UINT32 nPositionHigh; + UINT32 cbRequested; + UINT32 clipDataId; + } RDP_CB_FILECONTENTS_REQUEST_EVENT; + + typedef struct + { + wMessage event; + BYTE* data; + UINT32 size; + UINT32 streamId; + } RDP_CB_FILECONTENTS_RESPONSE_EVENT; + + typedef struct + { + wMessage event; + UINT32 clipDataId; + } RDP_CB_LOCK_CLIPDATA_EVENT; + + typedef struct + { + wMessage event; + UINT32 clipDataId; + } RDP_CB_UNLOCK_CLIPDATA_EVENT; + + typedef struct + { + wMessage event; + char dirname[520]; + } RDP_CB_TEMPDIR_EVENT; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_CLIPRDR_CLIENT_CLIPRDR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/cmdline.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/cmdline.h new file mode 100644 index 0000000000000000000000000000000000000000..4e0121274ff7b68fc553bbb1f5067b5b93f59c17 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/cmdline.h @@ -0,0 +1,153 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Client Command-Line Interface + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CLIENT_CMDLINE_H +#define FREERDP_CLIENT_CMDLINE_H + +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @brief Callback function type definition for command line handling + * + * @param arg A pointer to the argument to handle + * @param custom A pointer to user defined data + * + * @return \b 0 for success or a \b COMMAND_LINE_ERROR code + * + * @since version 3.12.0 + */ + typedef int (*freerdp_command_line_handle_option_t)(const COMMAND_LINE_ARGUMENT_A* arg, + void* custom); + + /** \brief parses command line arguments to appropriate settings values. + * + * \param settings The settings instance to store the parsed values to + * \param argc the number of argv values + * \param argv an array of strings (char pointer) + * \param allowUnknown Allow unknown command line arguments or \b FALSE if not. + * + * \return \b 0 in case of success, a negative number in case of failure. + */ + FREERDP_API int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, + int argc, char** argv, + BOOL allowUnknown); + + /** \brief parses command line arguments to appropriate settings values. Additionally allows + * supplying custom command line arguments and a handler function. + * + * \param settings The settings instance to store the parsed values to + * \param argc the number of argv values + * \param argv an array of strings (char pointer) + * \param allowUnknown Allow unknown command line arguments or \b FALSE if not. + * \param args Pointer to the custom arguments + * \param count The number of custom arguments + * \param handle_option the handler function for custom arguments. + * \param handle_userdata custom data supplied to \b handle_option as context + * + * \since version 3.0.0 + * + * \return \b 0 in case of success, a negative number in case of failure. + */ + FREERDP_API int freerdp_client_settings_parse_command_line_arguments_ex( + rdpSettings* settings, int argc, char** argv, BOOL allowUnknown, + COMMAND_LINE_ARGUMENT_A* args, size_t count, + freerdp_command_line_handle_option_t handle_option, void* handle_userdata); + + FREERDP_API int freerdp_client_settings_command_line_status_print(rdpSettings* settings, + int status, int argc, + char** argv); + FREERDP_API int + freerdp_client_settings_command_line_status_print_ex(rdpSettings* settings, int status, + int argc, char** argv, + const COMMAND_LINE_ARGUMENT_A* custom); + FREERDP_API BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings); + + /** Print a command line warning about the component being unmaintained. + * + * \since version 3.0.0 + */ + FREERDP_API void freerdp_client_warn_unmaintained(int argc, char* argv[]); + + /** Print a command line warning about the component being experimental. + * + * \since version 3.0.0 + */ + FREERDP_API void freerdp_client_warn_experimental(int argc, char* argv[]); + + /** Print a command line warning about the component being deprecated. + * + * \since version 3.0.0 + */ + FREERDP_API void freerdp_client_warn_deprecated(int argc, char* argv[]); + + FREERDP_API BOOL freerdp_client_print_version(void); + + /** @brief prints the version of the client including the binary name extracted from \b argv + * + * @param argc the number of command line arguments, must be >= 0 + * @param argv the array of command line argument strings + * + * @return \b TRUE for success + * + * @since version 3.10.0 + */ + FREERDP_API BOOL freerdp_client_print_version_ex(int argc, char** argv); + FREERDP_API BOOL freerdp_client_print_buildconfig(void); + + /** @brief prints the buidconfiguration of the client including the binary name extracted from + * \b argv + * + * @param argc the number of command line arguments, must be >= 0 + * @param argv the array of command line argument strings + * + * @return \b TRUE for success + * + * @since version 3.10.0 + */ + FREERDP_API BOOL freerdp_client_print_buildconfig_ex(int argc, char** argv); + FREERDP_API BOOL freerdp_client_print_command_line_help(int argc, char** argv); + FREERDP_API BOOL freerdp_client_print_command_line_help_ex( + int argc, char** argv, const COMMAND_LINE_ARGUMENT_A* custom); + + FREERDP_API BOOL freerdp_parse_username(const char* username, char** user, char** domain); + FREERDP_API BOOL freerdp_parse_hostname(const char* hostname, char** host, int* port); + FREERDP_API BOOL freerdp_set_connection_type(rdpSettings* settings, UINT32 type); + + FREERDP_API BOOL freerdp_client_add_device_channel(rdpSettings* settings, size_t count, + const char* const* params); + FREERDP_API BOOL freerdp_client_add_static_channel(rdpSettings* settings, size_t count, + const char* const* params); + FREERDP_API BOOL freerdp_client_del_static_channel(rdpSettings* settings, const char* name); + FREERDP_API BOOL freerdp_client_add_dynamic_channel(rdpSettings* settings, size_t count, + const char* const* params); + FREERDP_API BOOL freerdp_client_del_dynamic_channel(rdpSettings* settings, const char* name); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CLIENT_CMDLINE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/disp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/disp.h new file mode 100644 index 0000000000000000000000000000000000000000..26eff2713abb4adb43864cfe0fea87e11ccdfb93 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/disp.h @@ -0,0 +1,52 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Display Update Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DISP_CLIENT_DISP_H +#define FREERDP_CHANNEL_DISP_CLIENT_DISP_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_disp_client_context DispClientContext; + + typedef UINT (*pcDispCaps)(DispClientContext* context, UINT32 MaxNumMonitors, + UINT32 MaxMonitorAreaFactorA, UINT32 MaxMonitorAreaFactorB); + typedef UINT (*pcDispSendMonitorLayout)(DispClientContext* context, UINT32 NumMonitors, + DISPLAY_CONTROL_MONITOR_LAYOUT* Monitors); + + struct s_disp_client_context + { + void* handle; + void* custom; + + pcDispCaps DisplayControlCaps; + pcDispSendMonitorLayout SendMonitorLayout; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_DISP_CLIENT_DISP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/drdynvc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/drdynvc.h new file mode 100644 index 0000000000000000000000000000000000000000..897f9dd7a6235f1c276b46095fd090813bbd2e96 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/drdynvc.h @@ -0,0 +1,62 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DRDYNVC_CLIENT_DRDYNVC_H +#define FREERDP_CHANNEL_DRDYNVC_CLIENT_DRDYNVC_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + + typedef struct s_drdynvc_client_context DrdynvcClientContext; + + typedef int (*pcDrdynvcGetVersion)(DrdynvcClientContext* context); + typedef UINT (*pcDrdynvcOnChannelConnected)(DrdynvcClientContext* context, const char* name, + void* pInterface); + typedef UINT (*pcDrdynvcOnChannelDisconnected)(DrdynvcClientContext* context, const char* name, + void* pInterface); + typedef UINT (*pcDrdynvcOnChannelAttached)(DrdynvcClientContext* context, const char* name, + void* pInterface); + typedef UINT (*pcDrdynvcOnChannelDetached)(DrdynvcClientContext* context, const char* name, + void* pInterface); + + struct s_drdynvc_client_context + { + void* handle; + void* custom; + + pcDrdynvcGetVersion GetVersion; + pcDrdynvcOnChannelConnected OnChannelConnected; + pcDrdynvcOnChannelDisconnected OnChannelDisconnected; + pcDrdynvcOnChannelAttached OnChannelAttached; + pcDrdynvcOnChannelDetached OnChannelDetached; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_DRDYNVC_CLIENT_DRDYNVC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/encomsp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/encomsp.h new file mode 100644 index 0000000000000000000000000000000000000000..005c8b33ab307881132a858fb174571ed2c3e273 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/encomsp.h @@ -0,0 +1,88 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Multiparty Virtual Channel + * + * Copyright 2014 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_ENCOMSP_CLIENT_ENCOMSP_H +#define FREERDP_CHANNEL_ENCOMSP_CLIENT_ENCOMSP_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + + typedef struct s_encomsp_client_context EncomspClientContext; + + typedef UINT (*pcEncomspFilterUpdated)(EncomspClientContext* context, + const ENCOMSP_FILTER_UPDATED_PDU* filterUpdated); + typedef UINT (*pcEncomspApplicationCreated)( + EncomspClientContext* context, const ENCOMSP_APPLICATION_CREATED_PDU* applicationCreated); + typedef UINT (*pcEncomspApplicationRemoved)( + EncomspClientContext* context, const ENCOMSP_APPLICATION_REMOVED_PDU* applicationRemoved); + typedef UINT (*pcEncomspWindowCreated)(EncomspClientContext* context, + const ENCOMSP_WINDOW_CREATED_PDU* windowCreated); + typedef UINT (*pcEncomspWindowRemoved)(EncomspClientContext* context, + const ENCOMSP_WINDOW_REMOVED_PDU* windowRemoved); + typedef UINT (*pcEncomspShowWindow)(EncomspClientContext* context, + const ENCOMSP_SHOW_WINDOW_PDU* showWindow); + typedef UINT (*pcEncomspParticipantCreated)( + EncomspClientContext* context, const ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated); + typedef UINT (*pcEncomspParticipantRemoved)( + EncomspClientContext* context, const ENCOMSP_PARTICIPANT_REMOVED_PDU* participantRemoved); + typedef UINT (*pcEncomspChangeParticipantControlLevel)( + EncomspClientContext* context, + const ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* changeParticipantControlLevel); + typedef UINT (*pcEncomspGraphicsStreamPaused)( + EncomspClientContext* context, + const ENCOMSP_GRAPHICS_STREAM_PAUSED_PDU* graphicsStreamPaused); + typedef UINT (*pcEncomspGraphicsStreamResumed)( + EncomspClientContext* context, + const ENCOMSP_GRAPHICS_STREAM_RESUMED_PDU* graphicsStreamResumed); + + struct s_encomsp_client_context + { + void* handle; + void* custom; + + pcEncomspFilterUpdated FilterUpdated; + pcEncomspApplicationCreated ApplicationCreated; + pcEncomspApplicationRemoved ApplicationRemoved; + pcEncomspWindowCreated WindowCreated; + pcEncomspWindowRemoved WindowRemoved; + pcEncomspShowWindow ShowWindow; + pcEncomspParticipantCreated ParticipantCreated; + pcEncomspParticipantRemoved ParticipantRemoved; + pcEncomspChangeParticipantControlLevel ChangeParticipantControlLevel; + pcEncomspGraphicsStreamPaused GraphicsStreamPaused; + pcEncomspGraphicsStreamResumed GraphicsStreamResumed; + + UINT32 participantId; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_ENCOMSP_CLIENT_ENCOMSP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/file.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/file.h new file mode 100644 index 0000000000000000000000000000000000000000..30c6543d730456cad121346a1fa8429dd19b9237 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/file.h @@ -0,0 +1,82 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * .rdp file + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CLIENT_RDP_FILE_H +#define FREERDP_CLIENT_RDP_FILE_H + +#include +#include +#include + +/* Ignore invalid integer values */ +#define RDP_FILE_FLAG_PARSE_INT_RELAXED 1 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_file rdpFile; + typedef BOOL (*rdp_file_fkt_parse)(void* context, const char* key, char type, + const char* value); + + /* When using freerdp_client_parse_rdp_file_ex or freerdp_client_parse_rdp_file_buffer_ex + * set the context for the callback with this function. */ + FREERDP_API void freerdp_client_rdp_file_set_callback_context(rdpFile* file, void* context); + + FREERDP_API BOOL freerdp_client_parse_rdp_file(rdpFile* file, const char* name); + FREERDP_API BOOL freerdp_client_parse_rdp_file_ex(rdpFile* file, const char* name, + rdp_file_fkt_parse parse); + FREERDP_API BOOL freerdp_client_parse_rdp_file_buffer(rdpFile* file, const BYTE* buffer, + size_t size); + FREERDP_API BOOL freerdp_client_parse_rdp_file_buffer_ex(rdpFile* file, const BYTE* buffer, + size_t size, rdp_file_fkt_parse parse); + FREERDP_API BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, + rdpSettings* settings); + + FREERDP_API BOOL freerdp_client_populate_rdp_file_from_settings(rdpFile* file, + const rdpSettings* settings); + FREERDP_API BOOL freerdp_client_write_rdp_file(const rdpFile* file, const char* name, + BOOL unicode); + FREERDP_API size_t freerdp_client_write_rdp_file_buffer(const rdpFile* file, char* buffer, + size_t size); + + FREERDP_API int freerdp_client_rdp_file_set_string_option(rdpFile* file, const char* name, + const char* value); + FREERDP_API const char* freerdp_client_rdp_file_get_string_option(const rdpFile* file, + const char* name); + + FREERDP_API int freerdp_client_rdp_file_set_integer_option(rdpFile* file, const char* name, + int value); + FREERDP_API int freerdp_client_rdp_file_get_integer_option(const rdpFile* file, + const char* name); + + FREERDP_API void freerdp_client_rdp_file_free(rdpFile* file); + + WINPR_ATTR_MALLOC(freerdp_client_rdp_file_free, 1) + FREERDP_API rdpFile* freerdp_client_rdp_file_new(void); + + WINPR_ATTR_MALLOC(freerdp_client_rdp_file_free, 1) + FREERDP_API rdpFile* freerdp_client_rdp_file_new_ex(DWORD flags); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CLIENT_RDP_FILE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/geometry.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/geometry.h new file mode 100644 index 0000000000000000000000000000000000000000..f1c4e7bed7b9995dc88c323c8684d53d9335e362 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/geometry.h @@ -0,0 +1,76 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Geometry tracking Virtual Channel Extension + * + * Copyright 2017 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNELS_CLIENT_GEOMETRY_H +#define FREERDP_CHANNELS_CLIENT_GEOMETRY_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + typedef struct s_geometry_client_context GeometryClientContext; + + typedef struct S_MAPPED_GEOMETRY MAPPED_GEOMETRY; + typedef BOOL (*pcMappedGeometryAdded)(GeometryClientContext* context, + MAPPED_GEOMETRY* geometry); + typedef BOOL (*pcMappedGeometryUpdate)(MAPPED_GEOMETRY* geometry); + typedef BOOL (*pcMappedGeometryClear)(MAPPED_GEOMETRY* geometry); + + /** @brief a geometry record tracked by the geometry channel */ + struct S_MAPPED_GEOMETRY + { + volatile LONG refCounter; + UINT64 mappingId; + UINT64 topLevelId; + INT32 left, top, right, bottom; + INT32 topLevelLeft, topLevelTop, topLevelRight, topLevelBottom; + FREERDP_RGNDATA geometry; + + void* custom; + pcMappedGeometryUpdate MappedGeometryUpdate; + pcMappedGeometryClear MappedGeometryClear; + }; + + /** @brief the geometry context for client channel */ + struct s_geometry_client_context + { + wHashTable* geometries; + void* handle; + void* custom; + + pcMappedGeometryAdded MappedGeometryAdded; + UINT32 remoteVersion; + }; + + FREERDP_API void mappedGeometryRef(MAPPED_GEOMETRY* g); + FREERDP_API void mappedGeometryUnref(MAPPED_GEOMETRY* g); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNELS_CLIENT_GEOMETRY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/location.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/location.h new file mode 100644 index 0000000000000000000000000000000000000000..0135029d72e80f6e9a43de398495f527cea77cf1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/location.h @@ -0,0 +1,107 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Location Virtual Channel Extension + * + * Copyright 2024 Armin Novak + * Copyright 2024 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_LOCATION_CLIENT_LOCATION_H +#define FREERDP_CHANNEL_LOCATION_CLIENT_LOCATION_H + +#include + +/** @file + * @since version 3.4.0 + */ +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @since version 3.4.0 */ + typedef struct s_location_client_context LocationClientContext; + + /** @since version 3.4.0 */ + typedef UINT (*pcLocationStart)(LocationClientContext* context, UINT32 version, UINT32 flags); + + /** @since version 3.4.0 */ + typedef UINT (*pcLocationStop)(LocationClientContext* context); + + /** @since version 3.4.0 */ + typedef UINT (*pcLocationSend)(LocationClientContext* context, LOCATION_PDUTYPE type, + size_t count, ...); + + /** @since version 3.4.0 */ + struct s_location_client_context + { + void* handle; + void* custom; + + /**! \brief initialize location services on client + * + * \param context The client context to operate on + * \param version The location channel version (determines which features are available. + * \param flags The location channel flags. + * + * \return \b CHANNEL_RC_OK for success, an appropriate error otherwise. + */ + pcLocationStart LocationStart; + + /**! \brief stop location services on client + * + * \param context The client context to operate on + * + * \return \b CHANNEL_RC_OK for success, an appropriate error otherwise. + */ + pcLocationStop LocationStop; + + /**! \brief Send a location update. + * + * This function sends location updates to a server. + * The following parameter formats are supported: + * + * \param type one of the following: + * PDUTYPE_BASE_LOCATION3D : count = 3 | 7 + * latitude : double, required + * longitude : double, required + * altitude : INT32, required + * speed : double, optional + * heading : double, optional + * horizontalAccuracy : double, optional + * source : int, optional + * PDUTYPE_LOCATION2D_DELTA : count = 2 | 4 + * latitudeDelta : double, required + * longitudeDelta : double, required + * speedDelta : double, optional + * headingDelta : double, optional + * PDUTYPE_LOCATION3D_DELTA : count = 3 | 5 + * latitudeDelta : double, required + * longitudeDelta : double, required + * altitudeDelta : INT32, optional + * speedDelta : double, optional + * headingDelta : double, optional + * \param count the number of variable arguments following + * + * return \b CHANNEL_RC_OK for success, an appropriate error otherwise. + */ + pcLocationSend LocationSend; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_LOCATION_CLIENT_LOCATION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/printer.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/printer.h new file mode 100644 index 0000000000000000000000000000000000000000..fd4434594eeefb5ffdf59678b25ff90c2e42ee53 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/printer.h @@ -0,0 +1,89 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Print Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2016 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_PRINTER_CLIENT_PRINTER_H +#define FREERDP_CHANNEL_PRINTER_CLIENT_PRINTER_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_printer_driver rdpPrinterDriver; + typedef struct rdp_printer rdpPrinter; + typedef struct rdp_print_job rdpPrintJob; + + typedef void (*pcReferencePrinterDriver)(rdpPrinterDriver* driver); + typedef rdpPrinter** (*pcEnumPrinters)(rdpPrinterDriver* driver); + typedef void (*pcReleaseEnumPrinters)(rdpPrinter** printers); + + typedef rdpPrinter* (*pcGetPrinter)(rdpPrinterDriver* driver, const char* name, + const char* driverName, BOOL isDefault); + typedef void (*pcReferencePrinter)(rdpPrinter* printer); + + struct rdp_printer_driver + { + pcEnumPrinters EnumPrinters; + pcReleaseEnumPrinters ReleaseEnumPrinters; + pcGetPrinter GetPrinter; + + pcReferencePrinterDriver AddRef; + pcReferencePrinterDriver ReleaseRef; + }; + + typedef rdpPrintJob* (*pcCreatePrintJob)(rdpPrinter* printer, UINT32 id); + typedef rdpPrintJob* (*pcFindPrintJob)(rdpPrinter* printer, UINT32 id); + + struct rdp_printer + { + size_t id; + char* name; + char* driver; + BOOL is_default; + + size_t references; + rdpPrinterDriver* backend; + pcCreatePrintJob CreatePrintJob; + pcFindPrintJob FindPrintJob; + pcReferencePrinter AddRef; + pcReferencePrinter ReleaseRef; + }; + + typedef UINT (*pcWritePrintJob)(rdpPrintJob* printjob, const BYTE* data, size_t size); + typedef void (*pcClosePrintJob)(rdpPrintJob* printjob); + + struct rdp_print_job + { + UINT32 id; + rdpPrinter* printer; + + pcWritePrintJob Write; + pcClosePrintJob Close; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_PRINTER_CLIENT_PRINTER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rail.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rail.h new file mode 100644 index 0000000000000000000000000000000000000000..18582b992a0d9b96d03b7c956bb35457cca0f6d2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rail.h @@ -0,0 +1,143 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Applications Integrated Locally (RAIL) + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RAIL_CLIENT_RAIL_H +#define FREERDP_CHANNEL_RAIL_CLIENT_RAIL_H + +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + + typedef struct s_rail_client_context RailClientContext; + + typedef UINT (*pcRailOnOpen)(RailClientContext* context, BOOL* sendHandshake); + + typedef UINT (*pcRailClientExecute)(RailClientContext* context, const RAIL_EXEC_ORDER* exec); + typedef UINT (*pcRailClientActivate)(RailClientContext* context, + const RAIL_ACTIVATE_ORDER* activate); + typedef UINT (*pcRailClientSystemParam)(RailClientContext* context, + const RAIL_SYSPARAM_ORDER* sysparam); + typedef UINT (*pcRailServerSystemParam)(RailClientContext* context, + const RAIL_SYSPARAM_ORDER* sysparam); + typedef UINT (*pcRailClientSystemCommand)(RailClientContext* context, + const RAIL_SYSCOMMAND_ORDER* syscommand); + typedef UINT (*pcRailClientHandshake)(RailClientContext* context, + const RAIL_HANDSHAKE_ORDER* handshake); + typedef UINT (*pcRailServerHandshake)(RailClientContext* context, + const RAIL_HANDSHAKE_ORDER* handshake); + typedef UINT (*pcRailServerHandshakeEx)(RailClientContext* context, + const RAIL_HANDSHAKE_EX_ORDER* handshakeEx); + typedef UINT (*pcRailClientNotifyEvent)(RailClientContext* context, + const RAIL_NOTIFY_EVENT_ORDER* notifyEvent); + typedef UINT (*pcRailClientWindowMove)(RailClientContext* context, + const RAIL_WINDOW_MOVE_ORDER* windowMove); + typedef UINT (*pcRailServerLocalMoveSize)(RailClientContext* context, + const RAIL_LOCALMOVESIZE_ORDER* localMoveSize); + typedef UINT (*pcRailServerMinMaxInfo)(RailClientContext* context, + const RAIL_MINMAXINFO_ORDER* minMaxInfo); + typedef UINT (*pcRailClientInformation)(RailClientContext* context, + const RAIL_CLIENT_STATUS_ORDER* clientStatus); + typedef UINT (*pcRailClientSystemMenu)(RailClientContext* context, + const RAIL_SYSMENU_ORDER* sysmenu); + typedef UINT (*pcRailServerTaskBarInfo)(RailClientContext* context, + const RAIL_TASKBAR_INFO_ORDER* taskBarInfo); + typedef UINT (*pcRailClientLanguageBarInfo)(RailClientContext* context, + const RAIL_LANGBAR_INFO_ORDER* langBarInfo); + typedef UINT (*pcRailServerLanguageBarInfo)(RailClientContext* context, + const RAIL_LANGBAR_INFO_ORDER* langBarInfo); + typedef UINT (*pcRailClientLanguageIMEInfo)(RailClientContext* context, + const RAIL_LANGUAGEIME_INFO_ORDER* langImeInfo); + typedef UINT (*pcRailServerExecuteResult)(RailClientContext* context, + const RAIL_EXEC_RESULT_ORDER* execResult); + typedef UINT (*pcRailClientGetAppIdRequest)(RailClientContext* context, + const RAIL_GET_APPID_REQ_ORDER* getAppIdReq); + typedef UINT (*pcRailServerGetAppIdResponse)(RailClientContext* context, + const RAIL_GET_APPID_RESP_ORDER* getAppIdResp); + typedef UINT (*pcRailServerZOrderSync)(RailClientContext* context, + const RAIL_ZORDER_SYNC* zorder); + typedef UINT (*pcRailServerCloak)(RailClientContext* context, const RAIL_CLOAK* cloak); + typedef UINT (*pcRailClientCloak)(RailClientContext* context, const RAIL_CLOAK* cloak); + typedef UINT (*pcRailServerPowerDisplayRequest)(RailClientContext* context, + const RAIL_POWER_DISPLAY_REQUEST* power); + typedef UINT (*pcRailClientSnapArrange)(RailClientContext* context, + const RAIL_SNAP_ARRANGE* snap); + typedef UINT (*pcRailServerGetAppidResponseExtended)(RailClientContext* context, + const RAIL_GET_APPID_RESP_EX* id); + typedef UINT (*pcRailClientCompartmentInfo)(RailClientContext* context, + const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo); + typedef UINT (*pcRailClientTextScale)(RailClientContext* context, UINT32 TextScale); + typedef UINT (*pcRailClientCaretBlinkRate)(RailClientContext* context, UINT32 CaretBlinkRate); + + struct s_rail_client_context + { + void* handle; + void* custom; + + pcRailClientExecute ClientExecute; + pcRailClientActivate ClientActivate; + pcRailClientSystemParam ClientSystemParam; + pcRailServerSystemParam ServerSystemParam; + pcRailClientSystemCommand ClientSystemCommand; + pcRailClientHandshake ClientHandshake; + pcRailServerHandshake ServerHandshake; + pcRailServerHandshakeEx ServerHandshakeEx; + pcRailClientNotifyEvent ClientNotifyEvent; + pcRailClientWindowMove ClientWindowMove; + pcRailServerLocalMoveSize ServerLocalMoveSize; + pcRailServerMinMaxInfo ServerMinMaxInfo; + pcRailClientInformation ClientInformation; + pcRailClientSystemMenu ClientSystemMenu; + pcRailServerTaskBarInfo ServerTaskBarInfo; + pcRailClientLanguageBarInfo ClientLanguageBarInfo; + pcRailServerLanguageBarInfo ServerLanguageBarInfo; + pcRailClientLanguageIMEInfo ClientLanguageIMEInfo; + pcRailServerExecuteResult ServerExecuteResult; + pcRailClientGetAppIdRequest ClientGetAppIdRequest; + pcRailServerGetAppIdResponse ServerGetAppIdResponse; + pcRailServerZOrderSync ServerZOrderSync; + pcRailClientCloak ClientCloak; + pcRailServerCloak ServerCloak; + pcRailServerPowerDisplayRequest ServerPowerDisplayRequest; + pcRailClientSnapArrange ClientSnapArrange; + pcRailServerGetAppidResponseExtended ServerGetAppidResponseExtended; + pcRailClientCompartmentInfo ClientCompartmentInfo; + pcRailOnOpen OnOpen; + pcRailClientTextScale ClientTextScale; + pcRailClientCaretBlinkRate ClientCaretBlinkRate; + }; + + FREERDP_API UINT client_rail_server_start_cmd(RailClientContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RAIL_CLIENT_RAIL_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpei.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpei.h new file mode 100644 index 0000000000000000000000000000000000000000..50624f421fe97a64061cc34cd5756c8735da4dc7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpei.h @@ -0,0 +1,110 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEI_CLIENT_RDPEI_H +#define FREERDP_CHANNEL_RDPEI_CLIENT_RDPEI_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + + typedef struct s_rdpei_client_context RdpeiClientContext; + + typedef UINT32 (*pcRdpeiGetVersion)(RdpeiClientContext* context); + typedef UINT32 (*pcRdpeiGetFeatures)(RdpeiClientContext* context); + + typedef UINT (*pcRdpeiAddContact)(RdpeiClientContext* context, + const RDPINPUT_CONTACT_DATA* contact); + + typedef UINT (*pcRdpeiTouchEvent)(RdpeiClientContext* context, INT32 externalId, INT32 x, + INT32 y, INT32* contactId); + typedef UINT (*pcRdpeiTouchRawEvent)(RdpeiClientContext* context, INT32 externalId, INT32 x, + INT32 y, INT32* contactId, UINT32 contactFlags, + UINT32 fieldFlags, ...); + typedef UINT (*pcRdpeiTouchRawEventVA)(RdpeiClientContext* context, INT32 externalId, INT32 x, + INT32 y, INT32* contactId, UINT32 contactFlags, + UINT32 fieldFlags, va_list args); + + typedef UINT (*pcRdpeiAddPen)(RdpeiClientContext* context, INT32 externalId, + const RDPINPUT_PEN_CONTACT* contact); + + typedef UINT (*pcRdpeiPen)(RdpeiClientContext* context, INT32 externalId, UINT32 fieldFlags, + INT32 x, INT32 y, ...); + + typedef UINT (*pcRdpeiPenRawEvent)(RdpeiClientContext* context, INT32 externalId, + UINT32 contactFlags, UINT32 fieldFlags, INT32 x, INT32 y, + ...); + typedef UINT (*pcRdpeiPenRawEventVA)(RdpeiClientContext* context, INT32 externalId, + UINT32 contactFlags, UINT32 fieldFlags, INT32 x, INT32 y, + va_list args); + + typedef UINT (*pcRdpeiSuspendTouch)(RdpeiClientContext* context); + typedef UINT (*pcRdpeiResumeTouch)(RdpeiClientContext* context); + + struct s_rdpei_client_context + { + void* handle; + void* custom; + + pcRdpeiGetVersion GetVersion; + pcRdpeiGetFeatures GetFeatures; + + pcRdpeiAddContact AddContact; + + pcRdpeiTouchEvent TouchBegin; + pcRdpeiTouchEvent TouchUpdate; + pcRdpeiTouchEvent TouchEnd; + + pcRdpeiAddPen AddPen; + + pcRdpeiPen PenBegin; + pcRdpeiPen PenUpdate; + pcRdpeiPen PenEnd; + pcRdpeiPen PenHoverBegin; + pcRdpeiPen PenHoverUpdate; + pcRdpeiPen PenHoverCancel; + + pcRdpeiSuspendTouch SuspendTouch; + pcRdpeiResumeTouch ResumeTouch; + + pcRdpeiTouchEvent TouchCancel; + pcRdpeiTouchRawEvent TouchRawEvent; + pcRdpeiTouchRawEventVA TouchRawEventVA; + + pcRdpeiPen PenCancel; + pcRdpeiPenRawEvent PenRawEvent; + pcRdpeiPenRawEventVA PenRawEventVA; + + UINT32 clientFeaturesMask; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPEI_CLIENT_RDPEI_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpgfx.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpgfx.h new file mode 100644 index 0000000000000000000000000000000000000000..df9e2a7a5ea8d7d9d81eb35c092cfee5ff737c6a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpgfx.h @@ -0,0 +1,189 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPGFX_CLIENT_RDPGFX_H +#define FREERDP_CHANNEL_RDPGFX_CLIENT_RDPGFX_H + +#include +#include + +#include + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + typedef struct gdi_gfx_surface gdiGfxSurface; + typedef struct s_rdpgfx_client_context RdpgfxClientContext; + + typedef UINT (*pcRdpgfxResetGraphics)(RdpgfxClientContext* context, + const RDPGFX_RESET_GRAPHICS_PDU* resetGraphics); + typedef UINT (*pcRdpgfxStartFrame)(RdpgfxClientContext* context, + const RDPGFX_START_FRAME_PDU* startFrame); + typedef UINT (*pcRdpgfxEndFrame)(RdpgfxClientContext* context, + const RDPGFX_END_FRAME_PDU* endFrame); + typedef UINT (*pcRdpgfxSurfaceCommand)(RdpgfxClientContext* context, + const RDPGFX_SURFACE_COMMAND* cmd); + typedef UINT (*pcRdpgfxDeleteEncodingContext)( + RdpgfxClientContext* context, + const RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext); + typedef UINT (*pcRdpgfxCreateSurface)(RdpgfxClientContext* context, + const RDPGFX_CREATE_SURFACE_PDU* createSurface); + typedef UINT (*pcRdpgfxDeleteSurface)(RdpgfxClientContext* context, + const RDPGFX_DELETE_SURFACE_PDU* deleteSurface); + typedef UINT (*pcRdpgfxSolidFill)(RdpgfxClientContext* context, + const RDPGFX_SOLID_FILL_PDU* solidFill); + typedef UINT (*pcRdpgfxSurfaceToSurface)(RdpgfxClientContext* context, + const RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface); + typedef UINT (*pcRdpgfxSurfaceToCache)(RdpgfxClientContext* context, + const RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache); + typedef UINT (*pcRdpgfxCacheToSurface)(RdpgfxClientContext* context, + const RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface); + typedef UINT (*pcRdpgfxCacheImportOffer)(RdpgfxClientContext* context, + const RDPGFX_CACHE_IMPORT_OFFER_PDU* cacheImportOffer); + typedef UINT (*pcRdpgfxCacheImportReply)(RdpgfxClientContext* context, + const RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply); + typedef UINT (*pcRdpgfxEvictCacheEntry)(RdpgfxClientContext* context, + const RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry); + typedef UINT (*pcRdpgfxImportCacheEntry)(RdpgfxClientContext* context, UINT16 cacheSlot, + const PERSISTENT_CACHE_ENTRY* importCacheEntry); + typedef UINT (*pcRdpgfxExportCacheEntry)(RdpgfxClientContext* context, UINT16 cacheSlot, + PERSISTENT_CACHE_ENTRY* importCacheEntry); + typedef UINT (*pcRdpgfxMapSurfaceToOutput)( + RdpgfxClientContext* context, const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput); + typedef UINT (*pcRdpgfxMapSurfaceToScaledOutput)( + RdpgfxClientContext* context, + const RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU* surfaceToOutput); + typedef UINT (*pcRdpgfxMapSurfaceToWindow)( + RdpgfxClientContext* context, const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow); + typedef UINT (*pcRdpgfxMapSurfaceToScaledWindow)( + RdpgfxClientContext* context, + const RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU* surfaceToWindow); + typedef UINT (*pcRdpgfxSetSurfaceData)(RdpgfxClientContext* context, UINT16 surfaceId, + void* pData); + typedef void* (*pcRdpgfxGetSurfaceData)(RdpgfxClientContext* context, UINT16 surfaceId); + typedef UINT (*pcRdpgfxGetSurfaceIds)(RdpgfxClientContext* context, UINT16** ppSurfaceIds, + UINT16* count); + typedef UINT (*pcRdpgfxSetCacheSlotData)(RdpgfxClientContext* context, UINT16 cacheSlot, + void* pData); + typedef void* (*pcRdpgfxGetCacheSlotData)(RdpgfxClientContext* context, UINT16 cacheSlot); + + typedef UINT (*pcRdpgfxUpdateSurfaces)(RdpgfxClientContext* context); + + typedef UINT (*pcRdpgfxUpdateWindowFromSurface)(RdpgfxClientContext* context, + gdiGfxSurface* surface); + + typedef UINT (*pcRdpgfxUpdateSurfaceArea)(RdpgfxClientContext* context, UINT16 surfaceId, + UINT32 nrRects, const RECTANGLE_16* rects); + + typedef UINT (*pcRdpgfxOnOpen)(RdpgfxClientContext* context, BOOL* do_caps_advertise, + BOOL* do_frame_acks); + typedef UINT (*pcRdpgfxOnClose)(RdpgfxClientContext* context); + typedef UINT (*pcRdpgfxCapsAdvertise)(RdpgfxClientContext* context, + const RDPGFX_CAPS_ADVERTISE_PDU* capsAdvertise); + typedef UINT (*pcRdpgfxCapsConfirm)(RdpgfxClientContext* context, + const RDPGFX_CAPS_CONFIRM_PDU* capsConfirm); + typedef UINT (*pcRdpgfxFrameAcknowledge)(RdpgfxClientContext* context, + const RDPGFX_FRAME_ACKNOWLEDGE_PDU* frameAcknowledge); + typedef UINT (*pcRdpgfxQoeFrameAcknowledge)( + RdpgfxClientContext* context, const RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU* qoeFrameAcknowledge); + + typedef UINT (*pcRdpgfxMapWindowForSurface)(RdpgfxClientContext* context, UINT16 surfaceID, + UINT64 windowID); + typedef UINT (*pcRdpgfxUnmapWindowForSurface)(RdpgfxClientContext* context, UINT64 windowID); + + struct s_rdpgfx_client_context + { + void* handle; + void* custom; + + /* Implementations require locking */ + pcRdpgfxResetGraphics ResetGraphics; + pcRdpgfxStartFrame StartFrame; + pcRdpgfxEndFrame EndFrame; + pcRdpgfxSurfaceCommand SurfaceCommand; + pcRdpgfxDeleteEncodingContext DeleteEncodingContext; + pcRdpgfxCreateSurface CreateSurface; + pcRdpgfxDeleteSurface DeleteSurface; + pcRdpgfxSolidFill SolidFill; + pcRdpgfxSurfaceToSurface SurfaceToSurface; + pcRdpgfxSurfaceToCache SurfaceToCache; + pcRdpgfxCacheToSurface CacheToSurface; + pcRdpgfxCacheImportOffer CacheImportOffer; + pcRdpgfxCacheImportReply CacheImportReply; + pcRdpgfxImportCacheEntry ImportCacheEntry; + pcRdpgfxExportCacheEntry ExportCacheEntry; + pcRdpgfxEvictCacheEntry EvictCacheEntry; + pcRdpgfxMapSurfaceToOutput MapSurfaceToOutput; + pcRdpgfxMapSurfaceToScaledOutput MapSurfaceToScaledOutput; + pcRdpgfxMapSurfaceToWindow MapSurfaceToWindow; + pcRdpgfxMapSurfaceToScaledWindow MapSurfaceToScaledWindow; + + pcRdpgfxGetSurfaceIds GetSurfaceIds; + pcRdpgfxSetSurfaceData SetSurfaceData; + pcRdpgfxGetSurfaceData GetSurfaceData; + pcRdpgfxSetCacheSlotData SetCacheSlotData; + pcRdpgfxGetCacheSlotData GetCacheSlotData; + + /* Proxy callbacks */ + pcRdpgfxOnOpen OnOpen; + pcRdpgfxOnClose OnClose; + pcRdpgfxCapsAdvertise CapsAdvertise; + pcRdpgfxCapsConfirm CapsConfirm; + pcRdpgfxFrameAcknowledge FrameAcknowledge; + pcRdpgfxQoeFrameAcknowledge QoeFrameAcknowledge; + + /* No locking required */ + pcRdpgfxUpdateSurfaces UpdateSurfaces; + pcRdpgfxUpdateSurfaceArea UpdateSurfaceArea; + pcRdpgfxUpdateWindowFromSurface UpdateWindowFromSurface; + + /* These callbacks allow creating/destroying a window directly + * mapped to a surface. + * NOTE: The surface is already locked. + */ + pcRdpgfxMapWindowForSurface MapWindowForSurface; + pcRdpgfxUnmapWindowForSurface UnmapWindowForSurface; + + CRITICAL_SECTION mux; + rdpCodecs* codecs; + PROFILER_DEFINE(SurfaceProfiler) + }; + + FREERDP_API void rdpgfx_client_context_free(RdpgfxClientContext* context); + + WINPR_ATTR_MALLOC(rdpgfx_client_context_free, 1) + FREERDP_API RdpgfxClientContext* rdpgfx_client_context_new(rdpContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPGFX_CLIENT_RDPGFX_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpsnd.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpsnd.h new file mode 100644 index 0000000000000000000000000000000000000000..437f256b79cb60031bdbda64f1bd944c6c85cfdb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/rdpsnd.h @@ -0,0 +1,91 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Output Virtual Channel + * + * Copyright 2010-2011 Vic Lee + * Copyright 2012-2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPSND_CLIENT_RDPSND_H +#define FREERDP_CHANNEL_RDPSND_CLIENT_RDPSND_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Subsystem Interface + */ + typedef struct rdpsnd_plugin rdpsndPlugin; + + typedef struct rdpsnd_device_plugin rdpsndDevicePlugin; + + typedef BOOL (*pcFormatSupported)(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format); + typedef BOOL (*pcOpen)(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, UINT32 latency); + typedef UINT32 (*pcGetVolume)(rdpsndDevicePlugin* device); + typedef BOOL (*pcSetVolume)(rdpsndDevicePlugin* device, UINT32 value); + typedef UINT (*pcPlay)(rdpsndDevicePlugin* device, const BYTE* data, size_t size); + typedef UINT (*pcPlayEx)(rdpsndDevicePlugin* device, const AUDIO_FORMAT* format, + const BYTE* data, size_t size); + typedef void (*pcStart)(rdpsndDevicePlugin* device); + typedef void (*pcClose)(rdpsndDevicePlugin* device); + typedef void (*pcFree)(rdpsndDevicePlugin* device); + typedef BOOL (*pcDefaultFormat)(rdpsndDevicePlugin* device, const AUDIO_FORMAT* desired, + AUDIO_FORMAT* defaultFormat); + typedef UINT (*pcServerFormatAnnounce)(rdpsndDevicePlugin* device, const AUDIO_FORMAT* formats, + size_t count); + + struct rdpsnd_device_plugin + { + rdpsndPlugin* rdpsnd; + + pcFormatSupported FormatSupported; + pcOpen Open; + pcGetVolume GetVolume; + pcSetVolume SetVolume; + pcPlay Play; + pcStart Start; /* Deprecated, unused. */ + pcClose Close; + pcFree Free; + pcDefaultFormat DefaultFormat; + pcServerFormatAnnounce ServerFormatAnnounce; + pcPlayEx PlayEx; + }; + +#define RDPSND_DEVICE_EXPORT_FUNC_NAME "freerdp_rdpsnd_client_subsystem_entry" + +typedef void (*PREGISTERRDPSNDDEVICE)(rdpsndPlugin* rdpsnd, rdpsndDevicePlugin* device); + +typedef struct +{ + rdpsndPlugin* rdpsnd; + PREGISTERRDPSNDDEVICE pRegisterRdpsndDevice; + const ADDIN_ARGV* args; +} FREERDP_RDPSND_DEVICE_ENTRY_POINTS; +typedef FREERDP_RDPSND_DEVICE_ENTRY_POINTS* PFREERDP_RDPSND_DEVICE_ENTRY_POINTS; + +typedef UINT(VCAPITYPE* PFREERDP_RDPSND_DEVICE_ENTRY)( + PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints); + +FREERDP_API rdpContext* freerdp_rdpsnd_get_context(rdpsndPlugin* plugin); + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_RDPSND_CLIENT_RDPSND_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/remdesk.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/remdesk.h new file mode 100644 index 0000000000000000000000000000000000000000..cc9799d25f79f24162f699e5ced72ddea2ccea3d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/remdesk.h @@ -0,0 +1,44 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Assistance Virtual Channel + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_REMDESK_CLIENT_REMDESK_H +#define FREERDP_CHANNEL_REMDESK_CLIENT_REMDESK_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Client Interface + */ + + typedef struct + { + void* handle; + void* custom; + } RemdeskClientContext; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_REMDESK_CLIENT_REMDESK_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/sshagent.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/sshagent.h new file mode 100644 index 0000000000000000000000000000000000000000..c3404d1f01d2a9c7550f3514f574d2fb4fc90491 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/sshagent.h @@ -0,0 +1,95 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * SSH Agent Virtual Channel Extension + * + * Copyright 2017 Ben Cohen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CLIENT_SSHAGENT_H +#define FREERDP_CHANNEL_CLIENT_SSHAGENT_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + int ProtocolVersion; + int MaxConnections; + } SSHAgentClientContext; + + /* + * The channel is defined by the sshagent channel in xrdp as follows. + * + * Server to client commands + * ------------------------- + * + * Capabilities (at start of channel stream): + * + * INT32 SA_TAG_CAPABILITY + * INT32 SSHAGENT_CHAN_PROT_VERSION := 1 + * INT32 SSHAGENT_MAX_CONNECTIONS + * + * Open connection: + * + * INT32 SA_TAG_OPEN + * INT32 Connection id (0, ..., SSHAGENT_MAX_CONNECTIONS - 1) + * + * Send data: + * + * INT32 SA_TAG_WRITE + * INT32 Connection id (0, ..., SSHAGENT_MAX_CONNECTIONS - 1) + * INT32 Data length + * DATA ... + * + * Close connection: + * + * INT32 SA_TAG_CLOSE + * INT32 Connection id (0, ..., SSHAGENT_MAX_CONNECTIONS - 1) + * + * Client to server commands + * ------------------------- + * + * Capabilities (in reply to server capabilities): + * + * INT32 SA_TAG_CAPABILITY + * INT32 SSHAGENT_CHAN_PROT_VERSION := 1 + * INT32 SSHAGENT_MAX_CONNECTIONS + * + * Send data: + * + * INT32 SA_TAG_WRITE + * INT32 Connection id (0, ..., SSHAGENT_MAX_CONNECTIONS - 1) + * INT32 Data length + * DATA ... + * + * Close connection (abnormal): + * + * INT32 SA_TAG_CLOSE + * INT32 Connection id (0, ..., SSHAGENT_MAX_CONNECTIONS - 1) + */ + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_CLIENT_SSHAGENT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/tsmf.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/tsmf.h new file mode 100644 index 0000000000000000000000000000000000000000..e9cff3cd54409f8bd6189be015a7fba702360a98 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/tsmf.h @@ -0,0 +1,79 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Multimedia Redirection Virtual Channel Types + * + * Copyright 2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* DEPRECATION WARNING: + * + * This channel is unmaintained and not used since windows 7. + * Only compile and use it if absolutely necessary, otherwise + * deactivate it or use the newer [MS-RDPEVOR] video redirection. + */ + +#ifndef FREERDP_CHANNEL_TSMF_CLIENT_TSMF_H +#define FREERDP_CHANNEL_TSMF_CLIENT_TSMF_H + +#include + +#include + +/* RDP_VIDEO_FRAME_EVENT.frame_pixfmt */ +/* http://www.fourcc.org/yuv.php */ +#define RDP_PIXFMT_I420 0x30323449 +#define RDP_PIXFMT_YV12 0x32315659 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + BYTE* frameData; + UINT32 frameSize; + UINT32 framePixFmt; + INT16 frameWidth; + INT16 frameHeight; + INT16 x; + INT16 y; + INT16 width; + INT16 height; + UINT16 numVisibleRects; + RECTANGLE_16* visibleRects; + } TSMF_VIDEO_FRAME_EVENT; + + /** + * Client Interface + */ + + typedef struct s_tsmf_client_context TsmfClientContext; + + typedef int (*pcTsmfFrameEvent)(TsmfClientContext* context, TSMF_VIDEO_FRAME_EVENT* event); + + struct s_tsmf_client_context + { + void* handle; + void* custom; + + pcTsmfFrameEvent FrameEvent; + }; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_TSMF_CLIENT_TSMF_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/utils/smartcard_cli.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/utils/smartcard_cli.h new file mode 100644 index 0000000000000000000000000000000000000000..4aec92bce8bcafe037b2a1e463842d01d1f62b4d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/utils/smartcard_cli.h @@ -0,0 +1,37 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Smartcard client functions + * + * Copyright 2021 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UTILS_SMARTCARD_CLI_H__ +#define UTILS_SMARTCARD_CLI_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + + FREERDP_API BOOL freerdp_smartcard_list(const rdpSettings* settings); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* UTILS_SMARTCARD_CLI_H__ */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/video.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/video.h new file mode 100644 index 0000000000000000000000000000000000000000..e520e98ee8319dcf9f79c48b0a878a2e0e0d79d3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/client/video.h @@ -0,0 +1,74 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Optimized Remoting Virtual Channel Extension + * + * Copyright 2017 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNELS_CLIENT_VIDEO_H +#define FREERDP_CHANNELS_CLIENT_VIDEO_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_VideoClientContext VideoClientContext; + typedef struct s_VideoClientContextPriv VideoClientContextPriv; + + /** @brief an implementation of surface used by the video channel */ + typedef struct + { + UINT32 x, y, w, h; + UINT32 alignedWidth, alignedHeight; + BYTE* data; + DWORD format; + UINT32 scanline; + } VideoSurface; + + typedef void (*pcVideoTimer)(VideoClientContext* video, UINT64 now); + typedef void (*pcVideoSetGeometry)(VideoClientContext* video, GeometryClientContext* geometry); + typedef VideoSurface* (*pcVideoCreateSurface)(VideoClientContext* video, UINT32 x, UINT32 y, + UINT32 width, UINT32 height); + typedef BOOL (*pcVideoShowSurface)(VideoClientContext* video, const VideoSurface* surface, + UINT32 destinationWidth, UINT32 destinationHeight); + typedef BOOL (*pcVideoDeleteSurface)(VideoClientContext* video, VideoSurface* surface); + + /** @brief context for the video (MS-RDPEVOR) channel */ + struct s_VideoClientContext + { + void* handle; + void* custom; + VideoClientContextPriv* priv; + + pcVideoSetGeometry setGeometry; + pcVideoTimer timer; + pcVideoCreateSurface createSurface; + pcVideoShowSurface showSurface; + pcVideoDeleteSurface deleteSurface; + }; + + FREERDP_API VideoSurface* VideoClient_CreateCommonContext(size_t size, UINT32 x, UINT32 y, + UINT32 w, UINT32 h); + FREERDP_API void VideoClient_DestroyCommonContext(VideoSurface* surface); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNELS_CLIENT_VIDEO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/audio.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/audio.h new file mode 100644 index 0000000000000000000000000000000000000000..fd4b1f9bbec18fd5b3af517d264e65bf04a79928 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/audio.h @@ -0,0 +1,233 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Audio Formats + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_AUDIO_H +#define FREERDP_CODEC_AUDIO_H + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct AUDIO_FORMAT + { + UINT16 wFormatTag; + UINT16 nChannels; + UINT32 nSamplesPerSec; + UINT32 nAvgBytesPerSec; + UINT16 nBlockAlign; + UINT16 wBitsPerSample; + UINT16 cbSize; + BYTE* data; + }; + typedef struct AUDIO_FORMAT AUDIO_FORMAT; + +#define SNDC_CLOSE 1 +#define SNDC_WAVE 2 +#define SNDC_SETVOLUME 3 +#define SNDC_SETPITCH 4 +#define SNDC_WAVECONFIRM 5 +#define SNDC_TRAINING 6 +#define SNDC_FORMATS 7 +#define SNDC_CRYPTKEY 8 +#define SNDC_WAVEENCRYPT 9 +#define SNDC_UDPWAVE 10 +#define SNDC_UDPWAVELAST 11 +#define SNDC_QUALITYMODE 12 +#define SNDC_WAVE2 13 + +#define TSSNDCAPS_ALIVE 1 +#define TSSNDCAPS_VOLUME 2 +#define TSSNDCAPS_PITCH 4 + +#define DYNAMIC_QUALITY 0x0000 +#define MEDIUM_QUALITY 0x0001 +#define HIGH_QUALITY 0x0002 + + /* + * Format Tags: + * http://tools.ietf.org/html/rfc2361 + */ + +#ifndef WAVE_FORMAT_UNKNOWN +#define WAVE_FORMAT_UNKNOWN 0x0000 +#endif /* !WAVE_FORMAT_UNKNOWN */ + +#ifndef WAVE_FORMAT_PCM +#define WAVE_FORMAT_PCM 0x0001 +#endif /* !WAVE_FORMAT_PCM */ + +#ifndef WAVE_FORMAT_ADPCM +#define WAVE_FORMAT_ADPCM 0x0002 +#define WAVE_FORMAT_IEEE_FLOAT 0x0003 +#define WAVE_FORMAT_VSELP 0x0004 +#define WAVE_FORMAT_IBM_CVSD 0x0005 +#define WAVE_FORMAT_ALAW 0x0006 +#define WAVE_FORMAT_MULAW 0x0007 +#define WAVE_FORMAT_OKI_ADPCM 0x0010 +#define WAVE_FORMAT_DVI_ADPCM 0x0011 +#define WAVE_FORMAT_MEDIASPACE_ADPCM 0x0012 +#define WAVE_FORMAT_SIERRA_ADPCM 0x0013 +#define WAVE_FORMAT_G723_ADPCM 0x0014 +#define WAVE_FORMAT_DIGISTD 0x0015 +#define WAVE_FORMAT_DIGIFIX 0x0016 +#define WAVE_FORMAT_DIALOGIC_OKI_ADPCM 0x0017 +#define WAVE_FORMAT_MEDIAVISION_ADPCM 0x0018 +#define WAVE_FORMAT_CU_CODEC 0x0019 +#define WAVE_FORMAT_YAMAHA_ADPCM 0x0020 +#define WAVE_FORMAT_SONARC 0x0021 +#define WAVE_FORMAT_DSPGROUP_TRUESPEECH 0x0022 +#define WAVE_FORMAT_ECHOSC1 0x0023 +#define WAVE_FORMAT_AUDIOFILE_AF36 0x0024 +#define WAVE_FORMAT_APTX 0x0025 +#define WAVE_FORMAT_AUDIOFILE_AF10 0x0026 +#define WAVE_FORMAT_PROSODY_1612 0x0027 +#define WAVE_FORMAT_LRC 0x0028 +#define WAVE_FORMAT_DOLBY_AC2 0x0030 +#define WAVE_FORMAT_GSM610 0x0031 +#define WAVE_FORMAT_MSNAUDIO 0x0032 +#define WAVE_FORMAT_ANTEX_ADPCME 0x0033 +#define WAVE_FORMAT_CONTROL_RES_VQLPC 0x0034 +#define WAVE_FORMAT_DIGIREAL 0x0035 +#define WAVE_FORMAT_DIGIADPCM 0x0036 +#define WAVE_FORMAT_CONTROL_RES_CR10 0x0037 +#define WAVE_FORMAT_NMS_VBXADPCM 0x0038 +#define WAVE_FORMAT_ROLAND_RDAC 0x0039 +#define WAVE_FORMAT_ECHOSC3 0x003A +#define WAVE_FORMAT_ROCKWELL_ADPCM 0x003B +#define WAVE_FORMAT_ROCKWELL_DIGITALK 0x003C +#define WAVE_FORMAT_XEBEC 0x003D +#define WAVE_FORMAT_G721_ADPCM 0x0040 +#define WAVE_FORMAT_G728_CELP 0x0041 +#define WAVE_FORMAT_MSG723 0x0042 +#define WAVE_FORMAT_MPEG 0x0050 +#define WAVE_FORMAT_RT24 0x0052 +#define WAVE_FORMAT_PAC 0x0053 +#endif /* !WAVE_FORMAT_ADPCM */ + +#ifndef WAVE_FORMAT_MPEGLAYER3 +#define WAVE_FORMAT_MPEGLAYER3 0x0055 +#endif + +#ifndef WAVE_FORMAT_LUCENT_G723 +#define WAVE_FORMAT_LUCENT_G723 0x0059 +#define WAVE_FORMAT_CIRRUS 0x0060 +#define WAVE_FORMAT_ESPCM 0x0061 +#define WAVE_FORMAT_VOXWARE 0x0062 +#define WAVE_FORMAT_CANOPUS_ATRAC 0x0063 +#define WAVE_FORMAT_G726_ADPCM 0x0064 +#define WAVE_FORMAT_G722_ADPCM 0x0065 +#define WAVE_FORMAT_DSAT 0x0066 +#define WAVE_FORMAT_DSAT_DISPLAY 0x0067 +#define WAVE_FORMAT_VOXWARE_BYTE_ALIGNED 0x0069 +#define WAVE_FORMAT_VOXWARE_AC8 0x0070 +#define WAVE_FORMAT_VOXWARE_AC10 0x0071 +#define WAVE_FORMAT_VOXWARE_AC16 0x0072 +#define WAVE_FORMAT_VOXWARE_AC20 0x0073 +#define WAVE_FORMAT_VOXWARE_RT24 0x0074 +#define WAVE_FORMAT_VOXWARE_RT29 0x0075 +#define WAVE_FORMAT_VOXWARE_RT29HW 0x0076 +#define WAVE_FORMAT_VOXWARE_VR12 0x0077 +#define WAVE_FORMAT_VOXWARE_VR18 0x0078 +#define WAVE_FORMAT_VOXWARE_TQ40 0x0079 +#define WAVE_FORMAT_SOFTSOUND 0x0080 +#define WAVE_FORMAT_VOXWARE_TQ60 0x0081 +#define WAVE_FORMAT_MSRT24 0x0082 +#define WAVE_FORMAT_G729A 0x0083 +#define WAVE_FORMAT_MVI_MV12 0x0084 +#define WAVE_FORMAT_DF_G726 0x0085 +#define WAVE_FORMAT_DF_GSM610 0x0086 +#define WAVE_FORMAT_ISIAUDIO 0x0088 +#define WAVE_FORMAT_ONLIVE 0x0089 +#define WAVE_FORMAT_SBC24 0x0091 +#define WAVE_FORMAT_DOLBY_AC3_SPDIF 0x0092 +#define WAVE_FORMAT_ZYXEL_ADPCM 0x0097 +#define WAVE_FORMAT_PHILIPS_LPCBB 0x0098 +#define WAVE_FORMAT_PACKED 0x0099 +#define WAVE_FORMAT_RHETOREX_ADPCM 0x0100 +#define WAVE_FORMAT_IRAT 0x0101 +#define WAVE_FORMAT_VIVO_G723 0x0111 +#define WAVE_FORMAT_VIVO_SIREN 0x0112 +#define WAVE_FORMAT_DIGITAL_G723 0x0123 +#define WAVE_FORMAT_WMAUDIO2 0x0161 +#define WAVE_FORMAT_WMAUDIO3 0x0162 +#define WAVE_FORMAT_WMAUDIO_LOSSLESS 0x0163 +#define WAVE_FORMAT_CREATIVE_ADPCM 0x0200 +#define WAVE_FORMAT_CREATIVE_FASTSPEECH8 0x0202 +#define WAVE_FORMAT_CREATIVE_FASTSPEECH10 0x0203 +#define WAVE_FORMAT_QUARTERDECK 0x0220 +#define WAVE_FORMAT_FM_TOWNS_SND 0x0300 +#define WAVE_FORMAT_BTV_DIGITAL 0x0400 +#define WAVE_FORMAT_VME_VMPCM 0x0680 +#define WAVE_FORMAT_OLIGSM 0x1000 +#define WAVE_FORMAT_OLIADPCM 0x1001 +#define WAVE_FORMAT_OLICELP 0x1002 +#define WAVE_FORMAT_OLISBC 0x1003 +#define WAVE_FORMAT_OLIOPR 0x1004 +#define WAVE_FORMAT_LH_CODEC 0x1100 +#define WAVE_FORMAT_NORRIS 0x1400 +#define WAVE_FORMAT_SOUNDSPACE_MUSICOMPRESS 0x1500 +#define WAVE_FORMAT_DVM 0x2000 +#endif /* !WAVE_FORMAT_LUCENT_G723 */ + + /** Opus format identifier + * \since version 3.0.0 + */ +#define WAVE_FORMAT_OPUS 0x704F +#define WAVE_FORMAT_AAC_MS 0xA106 + +#define WAVE_FORMAT_EXTENSIBLE 0xFFFE + + /** + * Audio Format Functions + */ + + FREERDP_API UINT32 audio_format_compute_time_length(const AUDIO_FORMAT* format, size_t size); + + FREERDP_API const char* audio_format_get_tag_string(UINT16 wFormatTag); + + FREERDP_API void audio_format_print(wLog* log, DWORD level, const AUDIO_FORMAT* format); + FREERDP_API void audio_formats_print(wLog* log, DWORD level, const AUDIO_FORMAT* formats, + UINT16 count); + + FREERDP_API BOOL audio_format_read(wStream* s, AUDIO_FORMAT* format); + FREERDP_API BOOL audio_format_write(wStream* s, const AUDIO_FORMAT* format); + FREERDP_API BOOL audio_format_copy(const AUDIO_FORMAT* WINPR_RESTRICT srcFormat, + AUDIO_FORMAT* WINPR_RESTRICT dstFormat); + FREERDP_API BOOL audio_format_compatible(const AUDIO_FORMAT* with, const AUDIO_FORMAT* what); + + FREERDP_API void audio_format_free(AUDIO_FORMAT* format); + FREERDP_API void audio_formats_free(AUDIO_FORMAT* formats, size_t count); + + WINPR_ATTR_MALLOC(audio_formats_free, 1) + FREERDP_API AUDIO_FORMAT* audio_format_new(void); + + WINPR_ATTR_MALLOC(audio_formats_free, 1) + FREERDP_API AUDIO_FORMAT* audio_formats_new(size_t count); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_AUDIO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/bitmap.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/bitmap.h new file mode 100644 index 0000000000000000000000000000000000000000..86fecf96ef838ba8bce389c4e68ba50e107d5e4a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/bitmap.h @@ -0,0 +1,45 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Compressed Bitmap + * + * Copyright 2011 Jay Sorg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_BITMAP_H +#define FREERDP_CODEC_BITMAP_H + +#include +#include + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API SSIZE_T freerdp_bitmap_compress(const void* WINPR_RESTRICT srcData, UINT32 width, + UINT32 height, wStream* WINPR_RESTRICT s, + UINT32 bpp, UINT32 byte_limit, UINT32 start_line, + wStream* WINPR_RESTRICT temp_s, UINT32 e); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_BITMAP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/bulk.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/bulk.h new file mode 100644 index 0000000000000000000000000000000000000000..6f20c806141a8d94eba650c78ebe24e709c41402 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/bulk.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Bulk Data Compression + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_BULK_H +#define FREERDP_CODEC_BULK_H + +#include +#include + +/* Level-2 Compression Flags */ + +#define PACKET_COMPRESSED 0x20 +#define PACKET_AT_FRONT 0x40 +#define PACKET_FLUSHED 0x80 + +/* Level-1 Compression Flags */ + +#define L1_PACKET_AT_FRONT 0x04 +#define L1_NO_COMPRESSION 0x02 +#define L1_COMPRESSED 0x01 +#define L1_INNER_COMPRESSION 0x10 + +#endif /* FREERDP_CODEC_BULK_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/clear.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/clear.h new file mode 100644 index 0000000000000000000000000000000000000000..631838c05efb9b11c001cbd3f0fcd16d36f6c414 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/clear.h @@ -0,0 +1,59 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ClearCodec Bitmap Compression + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_CLEAR_H +#define FREERDP_CODEC_CLEAR_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_CLEAR_CONTEXT CLEAR_CONTEXT; + + FREERDP_API int clear_compress(CLEAR_CONTEXT* WINPR_RESTRICT clear, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + BYTE** WINPR_RESTRICT ppDstData, + UINT32* WINPR_RESTRICT pDstSize); + + FREERDP_API INT32 clear_decompress(CLEAR_CONTEXT* WINPR_RESTRICT clear, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + UINT32 nWidth, UINT32 nHeight, BYTE* WINPR_RESTRICT pDstData, + UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, + UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight, + const gdiPalette* WINPR_RESTRICT palette); + + FREERDP_API BOOL clear_context_reset(CLEAR_CONTEXT* WINPR_RESTRICT clear); + + FREERDP_API void clear_context_free(CLEAR_CONTEXT* WINPR_RESTRICT clear); + + WINPR_ATTR_MALLOC(clear_context_free, 1) + FREERDP_API CLEAR_CONTEXT* clear_context_new(BOOL Compressor); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_CLEAR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/color.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/color.h new file mode 100644 index 0000000000000000000000000000000000000000..78f2d43d0fb1fa82ea3b00a74fb833ee160af5aa --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/color.h @@ -0,0 +1,457 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Color Conversion Routines + * + * Copyright 2010 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_COLOR_H +#define FREERDP_CODEC_COLOR_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define FREERDP_PIXEL_FORMAT_TYPE_A 0 +#define FREERDP_PIXEL_FORMAT_TYPE_ARGB 1 +#define FREERDP_PIXEL_FORMAT_TYPE_ABGR 2 +#define FREERDP_PIXEL_FORMAT_TYPE_RGBA 3 +#define FREERDP_PIXEL_FORMAT_TYPE_BGRA 4 + +#define FREERDP_PIXEL_FORMAT_IS_ABGR(_format) \ + (FREERDP_PIXEL_FORMAT_TYPE(_format) == FREERDP_PIXEL_FORMAT_TYPE_ABGR) + + /** @brief Flags for image copy operations */ + enum FREERDP_IMAGE_FLAGS + { + FREERDP_FLIP_NONE = 0, + FREERDP_FLIP_VERTICAL = 1, + FREERDP_FLIP_HORIZONTAL = 2, + FREERDP_KEEP_DST_ALPHA = 4 + }; + +#define FREERDP_PIXEL_FORMAT(_bpp, _type, _a, _r, _g, _b) \ + ((_bpp << 24) | (_type << 16) | (_a << 12) | (_r << 8) | (_g << 4) | (_b)) + +#define FREERDP_PIXEL_FORMAT_TYPE(_format) (((_format) >> 16) & 0x07) + +/*** Design considerations + * + * The format naming scheme is based on byte position in memory. + * RGBA for example names a byte array with red on position 0, green on 1 etc. + * + * To read and write the appropriate format from / to memory use FreeRDPReadColor and + * FreeRDPWriteColor. + * + * The single pixel manipulation functions use an intermediate integer representation + * that must not be interpreted outside the functions as it is platform dependent. + * + * X for alpha channel denotes unused (but existing) alpha channel data. + */ + +/** @defgroup PIXEL_FORMAT Pixel formats + * @brief PIXEL color ordering formats known + * @{ + */ +/* 32bpp formats */ +#define PIXEL_FORMAT_ARGB32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 8, 8, 8, 8) +#define PIXEL_FORMAT_XRGB32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8) +#define PIXEL_FORMAT_ABGR32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 8, 8, 8, 8) +#define PIXEL_FORMAT_XBGR32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8) +#define PIXEL_FORMAT_BGRA32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 8, 8, 8, 8) +#define PIXEL_FORMAT_BGRX32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 8, 8, 8) +#define PIXEL_FORMAT_RGBA32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 8, 8, 8, 8) +#define PIXEL_FORMAT_RGBX32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 8, 8, 8) +#define PIXEL_FORMAT_BGRX32_DEPTH30 \ + FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 10, 10, 10) +#define PIXEL_FORMAT_RGBX32_DEPTH30 \ + FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 10, 10, 10) + +/* 24bpp formats */ +#define PIXEL_FORMAT_RGB24 FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8) +#define PIXEL_FORMAT_BGR24 FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8) + +/* 16bpp formats */ +#define PIXEL_FORMAT_RGB16 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 6, 5) +#define PIXEL_FORMAT_BGR16 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 6, 5) +#define PIXEL_FORMAT_ARGB15 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 1, 5, 5, 5) +#define PIXEL_FORMAT_RGB15 FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 5, 5) +#define PIXEL_FORMAT_ABGR15 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 1, 5, 5, 5) +#define PIXEL_FORMAT_BGR15 FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 5, 5) + +/* 8bpp formats */ +#define PIXEL_FORMAT_RGB8 FREERDP_PIXEL_FORMAT(8, FREERDP_PIXEL_FORMAT_TYPE_A, 8, 0, 0, 0) + +/* 4 bpp formats */ +#define PIXEL_FORMAT_A4 FREERDP_PIXEL_FORMAT(4, FREERDP_PIXEL_FORMAT_TYPE_A, 4, 0, 0, 0) + +/* 1bpp formats */ +#define PIXEL_FORMAT_MONO FREERDP_PIXEL_FORMAT(1, FREERDP_PIXEL_FORMAT_TYPE_A, 1, 0, 0, 0) + + /** @} */ + + struct gdi_palette + { + UINT32 format; + UINT32 palette[256]; + }; +typedef struct gdi_palette gdiPalette; + + /* Compare two color formats but ignore differences in alpha channel. + */ + FREERDP_API DWORD FreeRDPAreColorFormatsEqualNoAlpha(DWORD first, DWORD second); + + /* Color Space Conversions: http://msdn.microsoft.com/en-us/library/ff566496/ */ + + /*** + * + * Get a string representation of a color + * + * @param format The pixel color format + * + * @return A string representation of format + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define GetColorFormatName(...) FreeRDPGetColorFormatName(__VA_ARGS__) +#endif + FREERDP_API const char* FreeRDPGetColorFormatName(UINT32 format); + + /*** + * + * Converts a pixel color in internal representation to its red, green, blue + * and alpha components. + * + * @param color The color in format internal representation + * @param format one of PIXEL_FORMAT_* color format defines + * @param _r red color value + * @param _g green color value + * @param _b blue color value + * @param _a alpha color value + * @param palette palette to use (only used for 8 bit color!) + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define SplitColor(...) FreeRDPSplitColor(__VA_ARGS__) +#endif + FREERDP_API void FreeRDPSplitColor(UINT32 color, UINT32 format, BYTE* _r, BYTE* _g, BYTE* _b, + BYTE* _a, const gdiPalette* palette); + + /*** + * + * Converts red, green, blue and alpha values to internal representation. + * + * @param format one of PIXEL_FORMAT_* color format defines + * @param r red color value + * @param g green color value + * @param b blue color value + * @param a alpha color value + * + * @return The pixel color in the desired format. Value is in internal + * representation. + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define GetColor(...) FreeRDPGetColor(__VA_ARGS__) +#endif + FREERDP_API UINT32 FreeRDPGetColor(UINT32 format, BYTE r, BYTE g, BYTE b, BYTE a); + + /*** + * + * Returns the number of bits the format format uses. + * + * @param format One of PIXEL_FORMAT_* defines + * + * @return The number of bits the format requires per pixel. + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define GetBitsPerPixel(...) FreeRDPGetBitsPerPixel(__VA_ARGS__) +#endif + static INLINE UINT32 FreeRDPGetBitsPerPixel(UINT32 format) + { + return (((format) >> 24) & 0x3F); + } + + /*** + * @param format one of PIXEL_FORMAT_* color format defines + * + * @return TRUE if the format has an alpha channel, FALSE otherwise. + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define ColorHasAlpha(...) FreeRDPColorHasAlpha(__VA_ARGS__) +#endif + static INLINE BOOL FreeRDPColorHasAlpha(UINT32 format) + { + UINT32 alpha = (((format) >> 12) & 0x0F); + + if (alpha == 0) + return FALSE; + + return TRUE; + } + + /*** + * + * Read a pixel from memory to internal representation + * + * @param src The source buffer + * @param format The PIXEL_FORMAT_* define the source buffer uses for encoding + * + * @return The pixel color in internal representation + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define ReadColor(...) FreeRDPReadColor(__VA_ARGS__) +#endif + FREERDP_API UINT32 FreeRDPReadColor(const BYTE* WINPR_RESTRICT src, UINT32 format); + + /*** + * + * Write a pixel from internal representation to memory + * + * @param dst The destination buffer + * @param format The PIXEL_FORMAT_* define for encoding + * @param color The pixel color in internal representation + * + * @return TRUE if successful, FALSE otherwise + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define WriteColor(...) FreeRDPWriteColor(__VA_ARGS__) +#define WriteColorIgnoreAlpha(...) FreeRDPWriteColorIgnoreAlpha(__VA_ARGS__) +#endif + FREERDP_API BOOL FreeRDPWriteColor(BYTE* WINPR_RESTRICT dst, UINT32 format, UINT32 color); + FREERDP_API BOOL FreeRDPWriteColorIgnoreAlpha(BYTE* WINPR_RESTRICT dst, UINT32 format, + UINT32 color); + + /*** + * + * Converts a pixel in internal representation format srcFormat to internal + * representation format dstFormat + * + * @param color The pixel color in srcFormat representation + * @param srcFormat The PIXEL_FORMAT_* of color + * @param dstFormat The PIXEL_FORMAT_* of the return. + * @param palette palette to use (only used for 8 bit color!) + * + * @return The converted pixel color in dstFormat representation + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define ConvertColor(...) FreeRDPConvertColor(__VA_ARGS__) +#endif + static INLINE UINT32 FreeRDPConvertColor(UINT32 color, UINT32 srcFormat, UINT32 dstFormat, + const gdiPalette* palette) + { + BYTE r = 0; + BYTE g = 0; + BYTE b = 0; + BYTE a = 0; + FreeRDPSplitColor(color, srcFormat, &r, &g, &b, &a, palette); + return FreeRDPGetColor(dstFormat, r, g, b, a); + } + + /*** + * + * Returns the number of bytes the format format uses. + * + * @param format One of PIXEL_FORMAT_* defines + * + * @return The number of bytes the format requires per pixel. + */ +#if defined(WITH_FREERDP_DEPRECATED) +#define GetBytesPerPixel(...) FreeRDPGetBytesPerPixel(__VA_ARGS__) +#endif + static INLINE UINT32 FreeRDPGetBytesPerPixel(UINT32 format) + { + return (FreeRDPGetBitsPerPixel(format) + 7) / 8; + } + + /*** + * + * @param width width to copy in pixels + * @param height height to copy in pixels + * @param data source buffer, must be (nWidth + 7) / 8 bytes long + * + * @return A buffer allocated with winpr_aligned_malloc(width * height, 16) + * if successful, NULL otherwise. + */ + WINPR_ATTR_MALLOC(winpr_aligned_free, 1) + FREERDP_API BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, + const BYTE* WINPR_RESTRICT data); + + /*** + * + * @param pDstData destination buffer + * @param DstFormat destination buffer format + * @param nDstStep destination buffer stride (line in bytes) 0 for default + * @param nXDst destination buffer offset x + * @param nYDst destination buffer offset y + * @param nWidth width to copy in pixels + * @param nHeight height to copy in pixels + * @param pSrcData source buffer, must be (nWidth + 7) / 8 bytes long + * @param backColor The background color in internal representation format + * @param foreColor The foreground color in internal representation format + * @param palette palette to use (only used for 8 bit color!) + * + * @return TRUE if success, FALSE otherwise + */ + FREERDP_API BOOL freerdp_image_copy_from_monochrome( + BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, + UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, + UINT32 backColor, UINT32 foreColor, const gdiPalette* WINPR_RESTRICT palette); + + /*** + * + * @param pDstData destination buffer + * @param DstFormat destination buffer format + * @param nDstStep destination buffer stride (line in bytes) 0 for default + * @param nXDst destination buffer offset x + * @param nYDst destination buffer offset y + * @param nWidth width to copy in pixels + * @param nHeight height to copy in pixels + * @param bitsColor icon's image data buffer + * @param cbBitsColor length of the image data buffer in bytes + * @param bitsMask icon's 1bpp image mask buffer + * @param cbBitsMask length of the image mask buffer in bytes + * @param colorTable icon's image color table + * @param cbColorTable length of the image color table buffer in bytes + * @param bpp color image data bits per pixel + * + * @return TRUE if success, FALSE otherwise + */ + FREERDP_API BOOL freerdp_image_copy_from_icon_data( + BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, + UINT32 nYDst, UINT16 nWidth, UINT16 nHeight, const BYTE* WINPR_RESTRICT bitsColor, + UINT16 cbBitsColor, const BYTE* WINPR_RESTRICT bitsMask, UINT16 cbBitsMask, + const BYTE* WINPR_RESTRICT colorTable, UINT16 cbColorTable, UINT32 bpp); + + /*** + * + * @param pDstData destination buffer + * @param DstFormat destination buffer format + * @param nDstStep destination buffer stride (line in bytes) 0 for default + * @param nXDst destination buffer offset x + * @param nYDst destination buffer offset y + * @param nWidth width to copy in pixels + * @param nHeight height to copy in pixels + * @param xorMask XOR mask buffer + * @param xorMaskLength XOR mask length in bytes + * @param andMask AND mask buffer + * @param andMaskLength AND mask length in bytes + * @param xorBpp XOR bits per pixel + * @param palette palette to use (only used for 8 bit color!) + * + * @return TRUE if success, FALSE otherwise + */ + FREERDP_API BOOL freerdp_image_copy_from_pointer_data( + BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, + UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT xorMask, + UINT32 xorMaskLength, const BYTE* WINPR_RESTRICT andMask, UINT32 andMaskLength, + UINT32 xorBpp, const gdiPalette* WINPR_RESTRICT palette); + + /*** Copies an image from source to destination, converting if necessary. + * Source and destination may overlap. + * + * @param pDstData destination buffer + * @param DstFormat destination buffer format + * @param nDstStep destination buffer stride (line in bytes) 0 for default + * @param nXDst destination buffer offset x + * @param nYDst destination buffer offset y + * @param nWidth width to copy in pixels + * @param nHeight height to copy in pixels + * @param pSrcData source buffer + * @param SrcFormat source buffer format + * @param nSrcStep source buffer stride (line in bytes) 0 for default + * @param nXSrc source buffer x offset in pixels + * @param nYSrc source buffer y offset in pixels + * @param palette palette to use (only used for 8 bit color!) + * @param flags Image flipping flags FREERDP_FLIP_NONE et al + * + * @return TRUE if success, FALSE otherwise + */ + FREERDP_API BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, DWORD SrcFormat, UINT32 nSrcStep, + UINT32 nXSrc, UINT32 nYSrc, + const gdiPalette* WINPR_RESTRICT palette, UINT32 flags); + + /** + * @brief Same as @ref freerdp_image_copy but only for overlapping source and destination + * @since version 3.6.0 + */ + FREERDP_API BOOL freerdp_image_copy_overlap( + BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, + UINT32 nHeight, const BYTE* pSrcData, DWORD SrcFormat, UINT32 nSrcStep, UINT32 nXSrc, + UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette, UINT32 flags); + + /*** Same as @ref freerdp_image_copy but only for non overlapping source and destination + * @since version 3.6.0 + */ + FREERDP_API BOOL freerdp_image_copy_no_overlap( + BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette, + UINT32 flags); + + /*** Scale an image to destination + * + * @param pDstData destination buffer + * @param DstFormat destination buffer format + * @param nDstStep destination buffer stride (line in bytes) 0 for default + * @param nXDst destination buffer offset x + * @param nYDst destination buffer offset y + * @param nDstWidth width of destination in pixels + * @param nDstHeight height of destination in pixels + * @param pSrcData source buffer + * @param SrcFormat source buffer format + * @param nSrcStep source buffer stride (line in bytes) 0 for default + * @param nXSrc source buffer x offset in pixels + * @param nYSrc source buffer y offset in pixels + * @param nSrcWidth width of source in pixels + * @param nSrcHeight height of source in pixels + * + * @return TRUE if success, FALSE otherwise + */ + FREERDP_API BOOL freerdp_image_scale(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nDstWidth, UINT32 nDstHeight, + const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + UINT32 nSrcWidth, UINT32 nSrcHeight); + + /*** + * + * @param pDstData destination buffer + * @param DstFormat destination buffer format + * @param nDstStep destination buffer stride (line in bytes) 0 for default + * @param nXDst destination buffer offset x + * @param nYDst destination buffer offset y + * @param nWidth width to copy in pixels + * @param nHeight height to copy in pixels + * @param color Pixel color in DstFormat (internal representation format, + * use FreeRDPGetColor to create) + * + * @return TRUE if success, FALSE otherwise + */ + FREERDP_API BOOL freerdp_image_fill(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, + UINT32 nHeight, UINT32 color); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_COLOR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/dsp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/dsp.h new file mode 100644 index 0000000000000000000000000000000000000000..ff6c08ad317e5297f833ca959037ed704b5ab3fd --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/dsp.h @@ -0,0 +1,59 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Digital Sound Processing + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_DSP_H +#define FREERDP_CODEC_DSP_H + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_FREERDP_DSP_CONTEXT FREERDP_DSP_CONTEXT; + + FREERDP_API void freerdp_dsp_context_free(FREERDP_DSP_CONTEXT* context); + + WINPR_ATTR_MALLOC(freerdp_dsp_context_free, 1) + FREERDP_API FREERDP_DSP_CONTEXT* freerdp_dsp_context_new(BOOL encoder); + + FREERDP_API BOOL freerdp_dsp_supports_format(const AUDIO_FORMAT* WINPR_RESTRICT format, + BOOL encode); + FREERDP_API BOOL freerdp_dsp_encode(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context, + const AUDIO_FORMAT* WINPR_RESTRICT srcFormat, + const BYTE* WINPR_RESTRICT data, size_t length, + wStream* WINPR_RESTRICT out); + FREERDP_API BOOL freerdp_dsp_decode(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context, + const AUDIO_FORMAT* WINPR_RESTRICT srcFormat, + const BYTE* WINPR_RESTRICT data, size_t length, + wStream* WINPR_RESTRICT out); + + FREERDP_API BOOL freerdp_dsp_context_reset(FREERDP_DSP_CONTEXT* WINPR_RESTRICT context, + const AUDIO_FORMAT* WINPR_RESTRICT targetFormat, + UINT32 FramesPerPacket); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_DSP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/h264.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/h264.h new file mode 100644 index 0000000000000000000000000000000000000000..77fcc0c6f2f5ca7c38220287dc75e584ec068449 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/h264.h @@ -0,0 +1,135 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * H.264 Bitmap Compression + * + * Copyright 2014 Mike McDonald + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_H264_H +#define FREERDP_CODEC_H264_H + +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_H264_CONTEXT_SUBSYSTEM H264_CONTEXT_SUBSYSTEM; + typedef struct S_H264_CONTEXT H264_CONTEXT; + typedef struct S_YUV_CONTEXT YUV_CONTEXT; + + typedef enum + { + H264_RATECONTROL_VBR = 0, + H264_RATECONTROL_CQP + } H264_RATECONTROL_MODE; + + /** + * @brief The usage types for H264 encoding + * @since version 3.6.0 + */ + typedef enum + { + H264_SCREEN_CONTENT_REAL_TIME = 0, + H264_SCREEN_CONTENT_NON_REAL_TIME, + H264_CAMERA_VIDEO_REAL_TIME, + H264_CAMERA_VIDEO_NON_REAL_TIME, + + } H264_USAGETYPE; + + typedef enum + { + H264_CONTEXT_OPTION_RATECONTROL, + H264_CONTEXT_OPTION_BITRATE, + H264_CONTEXT_OPTION_FRAMERATE, + H264_CONTEXT_OPTION_QP, + H264_CONTEXT_OPTION_USAGETYPE, /** @since version 3.6.0 */ + H264_CONTEXT_OPTION_HW_ACCEL, /** set to request hw accel, get to check if hw accel is on, + @since version 3.11.0 */ + } H264_CONTEXT_OPTION; + + FREERDP_API void free_h264_metablock(RDPGFX_H264_METABLOCK* meta); + + FREERDP_API BOOL h264_context_set_option(H264_CONTEXT* h264, H264_CONTEXT_OPTION option, + UINT32 value); + FREERDP_API UINT32 h264_context_get_option(H264_CONTEXT* h264, H264_CONTEXT_OPTION option); + + FREERDP_API INT32 avc420_compress(H264_CONTEXT* h264, const BYTE* pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nSrcWidth, UINT32 nSrcHeight, + const RECTANGLE_16* regionRect, BYTE** ppDstData, + UINT32* pDstSize, RDPGFX_H264_METABLOCK* meta); + + /** @brief API for user to fill YUV I420 buffer before encoding + * + * @param h264 The h264 context to query + * @param nSrcStride The size of a line in bytes of the source image + * @param nSrcWidth The width of the source image in pixels + * @param nSrcHeight The height of the source image + * @param YUVData A pointer to hold the current YUV buffers + * @param stride A pointer to hold the byte length of a line in the YUV buffers + * @return \b >= 0 for success, \b <0 for an error + * @since version 3.6.0 + */ + FREERDP_API INT32 h264_get_yuv_buffer(H264_CONTEXT* h264, UINT32 nSrcStride, UINT32 nSrcWidth, + UINT32 nSrcHeight, BYTE* YUVData[3], UINT32 stride[3]); + + /** + * @brief Compress currently filled image data to H264 stream + * + * @param h264 The H264 context to use for compression + * @param ppDstData A pointer that will hold the allocated result buffer + * @param pDstSize A pointer for the destination buffer size in bytes + * @return \b >= 0 for success, \b <0 for an error + * @since version 3.6.0 + */ + FREERDP_API INT32 h264_compress(H264_CONTEXT* h264, BYTE** ppDstData, UINT32* pDstSize); + + FREERDP_API INT32 avc420_decompress(H264_CONTEXT* h264, const BYTE* pSrcData, UINT32 SrcSize, + BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, + UINT32 nDstWidth, UINT32 nDstHeight, + const RECTANGLE_16* regionRects, UINT32 numRegionRect); + + FREERDP_API INT32 avc444_compress(H264_CONTEXT* h264, const BYTE* pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nSrcWidth, UINT32 nSrcHeight, + BYTE version, const RECTANGLE_16* regionRect, BYTE* op, + BYTE** pDstData, UINT32* pDstSize, BYTE** pAuxDstData, + UINT32* pAuxDstSize, RDPGFX_H264_METABLOCK* meta, + RDPGFX_H264_METABLOCK* auxMeta); + + FREERDP_API INT32 avc444_decompress(H264_CONTEXT* h264, BYTE op, + const RECTANGLE_16* regionRects, UINT32 numRegionRect, + const BYTE* pSrcData, UINT32 SrcSize, + const RECTANGLE_16* auxRegionRects, UINT32 numAuxRegionRect, + const BYTE* pAuxSrcData, UINT32 AuxSrcSize, BYTE* pDstData, + DWORD DstFormat, UINT32 nDstStep, UINT32 nDstWidth, + UINT32 nDstHeight, UINT32 codecId); + + FREERDP_API BOOL h264_context_reset(H264_CONTEXT* h264, UINT32 width, UINT32 height); + + FREERDP_API void h264_context_free(H264_CONTEXT* h264); + + WINPR_ATTR_MALLOC(h264_context_free, 1) + FREERDP_API H264_CONTEXT* h264_context_new(BOOL Compressor); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_H264_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/interleaved.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/interleaved.h new file mode 100644 index 0000000000000000000000000000000000000000..9bc8b96fcc06bfbb7808eb2cd7ff9fec19ab129f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/interleaved.h @@ -0,0 +1,65 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Interleaved RLE Bitmap Codec + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_INTERLEAVED_H +#define FREERDP_CODEC_INTERLEAVED_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_BITMAP_INTERLEAVED_CONTEXT BITMAP_INTERLEAVED_CONTEXT; + + FREERDP_API BOOL interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* WINPR_RESTRICT interleaved, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + UINT32 nSrcWidth, UINT32 nSrcHeight, UINT32 bpp, + BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nDstWidth, UINT32 nDstHeight, + const gdiPalette* WINPR_RESTRICT palette); + + FREERDP_API BOOL interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* WINPR_RESTRICT interleaved, + BYTE* WINPR_RESTRICT pDstData, + UINT32* WINPR_RESTRICT pDstSize, UINT32 nWidth, + UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, + UINT32 SrcFormat, UINT32 nSrcStep, UINT32 nXSrc, + UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette, + UINT32 bpp); + + FREERDP_API BOOL + bitmap_interleaved_context_reset(BITMAP_INTERLEAVED_CONTEXT* WINPR_RESTRICT interleaved); + + FREERDP_API void + bitmap_interleaved_context_free(BITMAP_INTERLEAVED_CONTEXT* WINPR_RESTRICT interleaved); + + WINPR_ATTR_MALLOC(bitmap_interleaved_context_free, 1) + FREERDP_API BITMAP_INTERLEAVED_CONTEXT* bitmap_interleaved_context_new(BOOL Compressor); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_INTERLEAVED_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/jpeg.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/jpeg.h new file mode 100644 index 0000000000000000000000000000000000000000..b9621fd99b60afed36866dd52e1883b51eca525f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/jpeg.h @@ -0,0 +1,38 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Compressed Bitmap + * + * Copyright 2012 Jay Sorg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_JPEG_H +#define FREERDP_CODEC_JPEG_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API BOOL jpeg_decompress(const BYTE* input, BYTE* output, int width, int height, + int size, int bpp); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_JPEG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/nsc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/nsc.h new file mode 100644 index 0000000000000000000000000000000000000000..d2938ab3fb20e6fe70e064bbedf82ba0d2fa26ce --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/nsc.h @@ -0,0 +1,82 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * NSCodec Codec + * + * Copyright 2011 Samsung, Author Jiten Pathy + * Copyright 2012 Vic Lee + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_NSCODEC_H +#define FREERDP_CODEC_NSCODEC_H + +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + NSC_COLOR_LOSS_LEVEL, + NSC_ALLOW_SUBSAMPLING, + NSC_DYNAMIC_COLOR_FIDELITY, + NSC_COLOR_FORMAT + } NSC_PARAMETER; + + typedef struct S_NSC_CONTEXT NSC_CONTEXT; + +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED_VAR("Use nsc_context_set_parameters(NSC_COLOR_FORMAT)", + BOOL nsc_context_set_pixel_format(NSC_CONTEXT* context, + UINT32 pixel_format)); +#endif + + FREERDP_API BOOL nsc_context_set_parameters(NSC_CONTEXT* WINPR_RESTRICT context, + NSC_PARAMETER what, UINT32 value); + + FREERDP_API BOOL nsc_process_message(NSC_CONTEXT* WINPR_RESTRICT context, UINT16 bpp, + UINT32 width, UINT32 height, const BYTE* data, + UINT32 length, BYTE* WINPR_RESTRICT pDstData, + UINT32 DstFormat, UINT32 nDstStride, UINT32 nXDst, + UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, UINT32 flip); + FREERDP_API BOOL nsc_compose_message(NSC_CONTEXT* WINPR_RESTRICT context, + wStream* WINPR_RESTRICT s, + const BYTE* WINPR_RESTRICT bmpdata, UINT32 width, + UINT32 height, UINT32 rowstride); + FREERDP_API BOOL nsc_decompose_message(NSC_CONTEXT* WINPR_RESTRICT context, + wStream* WINPR_RESTRICT s, BYTE* WINPR_RESTRICT bmpdata, + UINT32 x, UINT32 y, UINT32 width, UINT32 height, + UINT32 rowstride, UINT32 format, UINT32 flip); + + FREERDP_API BOOL nsc_context_reset(NSC_CONTEXT* WINPR_RESTRICT context, UINT32 width, + UINT32 height); + + FREERDP_API void nsc_context_free(NSC_CONTEXT* context); + + WINPR_ATTR_MALLOC(nsc_context_free, 1) + FREERDP_API NSC_CONTEXT* nsc_context_new(void); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_NSCODEC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/planar.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/planar.h new file mode 100644 index 0000000000000000000000000000000000000000..fc51f44ec91d40221b4ce0a60ebcebf339cc268f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/planar.h @@ -0,0 +1,88 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP6 Planar Codec + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_PLANAR_H +#define FREERDP_CODEC_PLANAR_H + +#include +#include + +#include +#include + +#define PLANAR_FORMAT_HEADER_CS (1 << 3) +#define PLANAR_FORMAT_HEADER_RLE (1 << 4) +#define PLANAR_FORMAT_HEADER_NA (1 << 5) +#define PLANAR_FORMAT_HEADER_CLL_MASK 0x07 + +#ifdef __cplusplus +extern "C" +{ +#endif + + static inline BYTE PLANAR_CONTROL_BYTE(UINT32 nRunLength, UINT32 cRawBytes) + { + return WINPR_ASSERTING_INT_CAST(UINT8, ((nRunLength & 0x0F) | ((cRawBytes & 0x0F) << 4))); + } + + static inline BYTE PLANAR_CONTROL_BYTE_RUN_LENGTH(UINT32 controlByte) + { + return (controlByte & 0x0F); + } + static inline BYTE PLANAR_CONTROL_BYTE_RAW_BYTES(UINT32 controlByte) + { + return ((controlByte >> 4) & 0x0F); + } + + typedef struct S_BITMAP_PLANAR_CONTEXT BITMAP_PLANAR_CONTEXT; + + FREERDP_API BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT context, + const BYTE* WINPR_RESTRICT data, UINT32 format, + UINT32 width, UINT32 height, UINT32 scanline, + BYTE* WINPR_RESTRICT dstData, + UINT32* WINPR_RESTRICT pDstSize); + + FREERDP_API BOOL freerdp_bitmap_planar_context_reset( + BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT context, UINT32 width, UINT32 height); + + FREERDP_API void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context); + + WINPR_ATTR_MALLOC(freerdp_bitmap_planar_context_free, 1) + FREERDP_API BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, UINT32 width, + UINT32 height); + + FREERDP_API void freerdp_planar_switch_bgr(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, + BOOL bgr); + FREERDP_API void freerdp_planar_topdown_image(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, + BOOL topdown); + + FREERDP_API BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + UINT32 nSrcWidth, UINT32 nSrcHeight, + BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nDstWidth, UINT32 nDstHeight, BOOL vFlip); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_PLANAR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/progressive.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/progressive.h new file mode 100644 index 0000000000000000000000000000000000000000..5aff2a22ac1f8fd3a055e67505b5fa840f90079c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/progressive.h @@ -0,0 +1,89 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Progressive Codec Bitmap Compression + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_PROGRESSIVE_H +#define FREERDP_CODEC_PROGRESSIVE_H + +#include +#include + +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_PROGRESSIVE_CONTEXT PROGRESSIVE_CONTEXT; + + FREERDP_API int progressive_compress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + UINT32 SrcFormat, UINT32 Width, UINT32 Height, + UINT32 ScanLine, + const REGION16* WINPR_RESTRICT invalidRegion, + BYTE** WINPR_RESTRICT ppDstData, + UINT32* WINPR_RESTRICT pDstSize); + + FREERDP_API INT32 progressive_decompress(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + REGION16* WINPR_RESTRICT invalidRegion, + UINT16 surfaceId, UINT32 frameId); + + FREERDP_API INT32 + progressive_create_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, + UINT16 surfaceId, UINT32 width, UINT32 height); + FREERDP_API int + progressive_delete_surface_context(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive, + UINT16 surfaceId); + + FREERDP_API BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* WINPR_RESTRICT progressive); + + FREERDP_API void progressive_context_free(PROGRESSIVE_CONTEXT* progressive); + + WINPR_ATTR_MALLOC(progressive_context_free, 1) + FREERDP_API PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor); + + WINPR_ATTR_MALLOC(progressive_context_free, 1) + FREERDP_API PROGRESSIVE_CONTEXT* progressive_context_new_ex(BOOL Compressor, + UINT32 ThreadingFlags); + + /** Write a RFX message as simple progressive message to a stream. + * Forward wrapper for \link rfx_write_message_progressive_simple + * @param progressive The progressive codec context + * @param s The stream to write to + * @param msg The message to encode + * + * @since version 3.0.0 + * @return \b TRUE in case of success, \b FALSE for any error + */ + FREERDP_API BOOL progressive_rfx_write_message_progressive_simple( + PROGRESSIVE_CONTEXT* progressive, wStream* s, const RFX_MESSAGE* msg); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_PROGRESSIVE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/region.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/region.h new file mode 100644 index 0000000000000000000000000000000000000000..19239b6340e2c5ec7fd10ea6e3e09386cb4b2bf3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/region.h @@ -0,0 +1,148 @@ +/** + * Copyright © 2014 Thincast Technologies GmbH + * Copyright © 2014 Hardening + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of the copyright holders not be used in + * advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. The copyright holders make + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef FREERDP_CODEC_REGION_H +#define FREERDP_CODEC_REGION_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_REGION16_DATA REGION16_DATA; + + typedef struct + { + RECTANGLE_16 extents; + REGION16_DATA* data; + } REGION16; + + /** computes if two rectangles are equal + * @param r1 first rectangle + * @param r2 second rectangle + * @return if the two rectangles are equal + */ + FREERDP_API BOOL rectangles_equal(const RECTANGLE_16* r1, const RECTANGLE_16* r2); + + /** computes if two rectangles intersect + * @param r1 first rectangle + * @param r2 second rectangle + * @return if the two rectangles intersect + */ + FREERDP_API BOOL rectangles_intersects(const RECTANGLE_16* r1, const RECTANGLE_16* r2); + + /** computes the intersection of two rectangles + * @param r1 first rectangle + * @param r2 second rectangle + * @param dst resulting intersection + * @return if the two rectangles intersect + */ + FREERDP_API BOOL rectangles_intersection(const RECTANGLE_16* r1, const RECTANGLE_16* r2, + RECTANGLE_16* dst); + + /** initialize a region16 + * @param region the region to initialise + */ + FREERDP_API void region16_init(REGION16* region); + + /** @return the number of rectangles of this region16 */ + FREERDP_API int region16_n_rects(const REGION16* region); + + /** returns a pointer to rectangles and the number of rectangles in this region. + * nbRects can be set to NULL if not interested in the number of rectangles. + * @param region the input region + * @param nbRects if non-NULL returns the number of rectangles + * @return a pointer on the rectangles + */ + FREERDP_API const RECTANGLE_16* region16_rects(const REGION16* region, UINT32* nbRects); + + /** @return the extents rectangle of this region */ + FREERDP_API const RECTANGLE_16* region16_extents(const REGION16* region); + + /** returns if the rectangle is empty + * @param rect the rectangle to check + * @return if the rectangle is empty + */ + FREERDP_API BOOL rectangle_is_empty(const RECTANGLE_16* rect); + + /** returns if the region is empty + * @param region the region to check + * @return if the region is empty + */ + FREERDP_API BOOL region16_is_empty(const REGION16* region); + + /** clears the region, the region is reset to a (0,0,0,0) region + * @param region the region to clear + */ + FREERDP_API void region16_clear(REGION16* region); + + /** dumps the region on stderr + * @param region the region to dump + */ + FREERDP_API void region16_print(const REGION16* region); + + /** copies the region to another region + * @param dst destination region + * @param src source region + * @return if the operation was successful (false meaning out-of-memory) + */ + FREERDP_API BOOL region16_copy(REGION16* dst, const REGION16* src); + + /** adds a rectangle in src and stores the resulting region in dst + * @param dst destination region + * @param src source region + * @param rect the rectangle to add + * @return if the operation was successful (false meaning out-of-memory) + */ + FREERDP_API BOOL region16_union_rect(REGION16* dst, const REGION16* src, + const RECTANGLE_16* rect); + + /** returns if a rectangle intersects the region + * @param src the region + * @param arg2 the rectangle + * @return if region and rectangle intersect + */ + FREERDP_API BOOL region16_intersects_rect(const REGION16* src, const RECTANGLE_16* arg2); + + /** computes the intersection between a region and a rectangle + * @param dst destination region + * @param src the source region + * @param arg2 the rectangle that intersects + * @return if the operation was successful (false meaning out-of-memory) + */ + FREERDP_API BOOL region16_intersect_rect(REGION16* dst, const REGION16* src, + const RECTANGLE_16* arg2); + + /** release internal data associated with this region + * @param region the region to release + */ + FREERDP_API void region16_uninit(REGION16* region); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_REGION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/rfx.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/rfx.h new file mode 100644 index 0000000000000000000000000000000000000000..5968bb5722f818b7691b9a3b91b2a681739e87ec --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/rfx.h @@ -0,0 +1,180 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX Codec + * + * Copyright 2011 Vic Lee + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_REMOTEFX_H +#define FREERDP_CODEC_REMOTEFX_H + +#include +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + RLGR1, + RLGR3 + } RLGR_MODE; + + typedef struct + { + UINT16 x; + UINT16 y; + UINT16 width; + UINT16 height; + } RFX_RECT; + + typedef struct + { + UINT16 x; + UINT16 y; + UINT32 width; + UINT32 height; + BYTE* data; + UINT32 scanline; + BOOL allocated; + BYTE quantIdxY; + BYTE quantIdxCb; + BYTE quantIdxCr; + UINT16 xIdx; + UINT16 yIdx; + UINT16 YLen; + UINT16 CbLen; + UINT16 CrLen; + BYTE* YData; + BYTE* CbData; + BYTE* CrData; + BYTE* YCbCrData; + } RFX_TILE; + + typedef struct S_RFX_MESSAGE_LIST RFX_MESSAGE_LIST; + typedef struct S_RFX_MESSAGE RFX_MESSAGE; + typedef struct S_RFX_CONTEXT RFX_CONTEXT; + + FREERDP_API BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length, + UINT32 left, UINT32 top, BYTE* dst, UINT32 dstFormat, + UINT32 dstStride, UINT32 dstHeight, + REGION16* invalidRegion); + + FREERDP_API UINT32 rfx_message_get_frame_idx(const RFX_MESSAGE* message); + FREERDP_API const UINT32* rfx_message_get_quants(const RFX_MESSAGE* message, + UINT16* numQuantVals); + + FREERDP_API const RFX_TILE** rfx_message_get_tiles(const RFX_MESSAGE* message, + UINT16* numTiles); + FREERDP_API UINT16 rfx_message_get_tile_count(const RFX_MESSAGE* message); + + FREERDP_API const RFX_RECT* rfx_message_get_rects(const RFX_MESSAGE* message, UINT16* numRects); + FREERDP_API UINT16 rfx_message_get_rect_count(const RFX_MESSAGE* message); + + FREERDP_API void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message); + + FREERDP_API BOOL rfx_compose_message(RFX_CONTEXT* context, wStream* s, const RFX_RECT* rects, + size_t num_rects, const BYTE* image_data, UINT32 width, + UINT32 height, UINT32 rowstride); + + FREERDP_API RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, + size_t numRects, const BYTE* data, UINT32 width, + UINT32 height, size_t scanline); + + FREERDP_API RFX_MESSAGE_LIST* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects, + size_t numRects, const BYTE* data, + UINT32 width, UINT32 height, UINT32 scanline, + size_t* numMessages, size_t maxDataSize); + FREERDP_API void rfx_message_list_free(RFX_MESSAGE_LIST* messages); + + FREERDP_API const RFX_MESSAGE* rfx_message_list_get(const RFX_MESSAGE_LIST* messages, + size_t idx); + + FREERDP_API BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, + const RFX_MESSAGE* message); + + FREERDP_API void rfx_context_free(RFX_CONTEXT* context); + + WINPR_ATTR_MALLOC(rfx_context_free, 1) + FREERDP_API RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags); + + WINPR_ATTR_MALLOC(rfx_context_free, 1) + FREERDP_API RFX_CONTEXT* rfx_context_new(BOOL encoder); + + FREERDP_API BOOL rfx_context_reset(RFX_CONTEXT* WINPR_RESTRICT context, UINT32 width, + UINT32 height); + + FREERDP_API BOOL rfx_context_set_mode(RFX_CONTEXT* context, RLGR_MODE mode); + + /** Getter for RFX mode + * @param context The RFX context to query + * + * @since version 3.0.0 + * + * @return The RFX mode that is currently in use + */ + FREERDP_API RLGR_MODE rfx_context_get_mode(RFX_CONTEXT* WINPR_RESTRICT context); + + FREERDP_API void rfx_context_set_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context, + UINT32 pixel_format); + + /** Getter for RFX pixel format + * @param context The RFX context to query + * + * @since version 3.0.0 + * + * @return The RFX pixel format that is currently in use + */ + FREERDP_API UINT32 rfx_context_get_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context); + + FREERDP_API void rfx_context_set_palette(RFX_CONTEXT* WINPR_RESTRICT context, + const BYTE* WINPR_RESTRICT palette); + + /** Getter for RFX palette + * @param context The RFX context to query + * + * @since version 3.0.0 + * + * @return The RFX palette that is currently in use or \b NULL + */ + FREERDP_API const BYTE* rfx_context_get_palette(RFX_CONTEXT* WINPR_RESTRICT context); + + FREERDP_API UINT32 rfx_context_get_frame_idx(const RFX_CONTEXT* WINPR_RESTRICT context); + + /** Write a RFX message as simple progressive message to a stream. + * + * @param rfx The RFX codec context + * @param s The stream to write to + * @param msg The message to encode + * + * @since version 3.0.0 + * @return \b TRUE in case of success, \b FALSE for any error + */ + FREERDP_API BOOL rfx_write_message_progressive_simple(RFX_CONTEXT* rfx, wStream* s, + const RFX_MESSAGE* msg); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_REMOTEFX_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/yuv.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/yuv.h new file mode 100644 index 0000000000000000000000000000000000000000..07efe481d8ebf090f7de14005bd70cbe7d7e6353 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/yuv.h @@ -0,0 +1,70 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * YUV decoder + * + * Copyright 2017 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_YUV_H +#define FREERDP_CODEC_YUV_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_YUV_CONTEXT YUV_CONTEXT; + + FREERDP_API BOOL yuv420_context_decode( + YUV_CONTEXT* WINPR_RESTRICT context, const BYTE* WINPR_RESTRICT pYUVData[3], + const UINT32 iStride[3], UINT32 yuvHeight, DWORD DstFormat, BYTE* WINPR_RESTRICT dest, + UINT32 nDstStep, const RECTANGLE_16* WINPR_RESTRICT regionRects, UINT32 numRegionRects); + FREERDP_API BOOL yuv420_context_encode(YUV_CONTEXT* WINPR_RESTRICT context, + const BYTE* WINPR_RESTRICT rgbData, UINT32 srcStep, + UINT32 srcFormat, const UINT32 iStride[3], + BYTE* WINPR_RESTRICT yuvData[3], + const RECTANGLE_16* WINPR_RESTRICT regionRects, + UINT32 numRegionRects); + + FREERDP_API BOOL yuv444_context_decode( + YUV_CONTEXT* WINPR_RESTRICT context, BYTE type, const BYTE* WINPR_RESTRICT pYUVData[3], + const UINT32 iStride[3], UINT32 srcYuvHeight, BYTE* WINPR_RESTRICT pYUVDstData[3], + const UINT32 iDstStride[3], DWORD DstFormat, BYTE* WINPR_RESTRICT dest, UINT32 nDstStep, + const RECTANGLE_16* WINPR_RESTRICT regionRects, UINT32 numRegionRects); + FREERDP_API BOOL yuv444_context_encode(YUV_CONTEXT* WINPR_RESTRICT context, BYTE version, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 nSrcStep, + UINT32 SrcFormat, const UINT32 iStride[3], + BYTE* WINPR_RESTRICT pYUVLumaData[3], + BYTE* WINPR_RESTRICT pYUVChromaData[3], + const RECTANGLE_16* WINPR_RESTRICT regionRects, + UINT32 numRegionRects); + + FREERDP_API BOOL yuv_context_reset(YUV_CONTEXT* WINPR_RESTRICT context, UINT32 width, + UINT32 height); + + FREERDP_API void yuv_context_free(YUV_CONTEXT* context); + + WINPR_ATTR_MALLOC(yuv_context_free, 1) + FREERDP_API YUV_CONTEXT* yuv_context_new(BOOL encoder, UINT32 ThreadingFlags); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_YUV_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/zgfx.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/zgfx.h new file mode 100644 index 0000000000000000000000000000000000000000..3a57e7e9aefe8b171ed241e67e6b20fb142f2bbc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codec/zgfx.h @@ -0,0 +1,66 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ZGFX (RDP8) Bulk Data Compression + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODEC_ZGFX_H +#define FREERDP_CODEC_ZGFX_H + +#include +#include + +#include + +#define ZGFX_SEGMENTED_SINGLE 0xE0 +#define ZGFX_SEGMENTED_MULTIPART 0xE1 + +#define ZGFX_PACKET_COMPR_TYPE_RDP8 0x04 + +#define ZGFX_SEGMENTED_MAXSIZE 65535 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_ZGFX_CONTEXT ZGFX_CONTEXT; + + FREERDP_API int zgfx_decompress(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + BYTE** WINPR_RESTRICT ppDstData, + UINT32* WINPR_RESTRICT pDstSize, UINT32 flags); + FREERDP_API int zgfx_compress(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, + const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, + BYTE** WINPR_RESTRICT ppDstData, UINT32* pDstSize, + UINT32* WINPR_RESTRICT pFlags); + FREERDP_API int zgfx_compress_to_stream(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, + wStream* WINPR_RESTRICT sDst, + const BYTE* WINPR_RESTRICT pUncompressed, + UINT32 uncompressedSize, UINT32* WINPR_RESTRICT pFlags); + + FREERDP_API void zgfx_context_reset(ZGFX_CONTEXT* WINPR_RESTRICT zgfx, BOOL flush); + + FREERDP_API void zgfx_context_free(ZGFX_CONTEXT* zgfx); + + WINPR_ATTR_MALLOC(zgfx_context_free, 1) + FREERDP_API ZGFX_CONTEXT* zgfx_context_new(BOOL Compressor); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODEC_ZGFX_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codecs.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codecs.h new file mode 100644 index 0000000000000000000000000000000000000000..95e20d84d6777041130a20ae350a836f5d1dbeab --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/codecs.h @@ -0,0 +1,99 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Codecs + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CODECS_H +#define FREERDP_CODECS_H + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +typedef enum +{ + FREERDP_CODEC_INTERLEAVED = 0x00000001, + FREERDP_CODEC_PLANAR = 0x00000002, + FREERDP_CODEC_NSCODEC = 0x00000004, + FREERDP_CODEC_REMOTEFX = 0x00000008, + FREERDP_CODEC_CLEARCODEC = 0x00000010, + FREERDP_CODEC_ALPHACODEC = 0x00000020, + FREERDP_CODEC_PROGRESSIVE = 0x00000040, + FREERDP_CODEC_AVC420 = 0x00000080, + FREERDP_CODEC_AVC444 = 0x00000100, + FREERDP_CODEC_ALL = 0x7FFFFFFF /* C enum types are restricted to int */ +} FreeRDP_CodecFlags; + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct rdp_codecs + { + UINT32 ThreadingFlags; /** @since version 3.6.0 */ + + RFX_CONTEXT* rfx; + NSC_CONTEXT* nsc; + H264_CONTEXT* h264; + CLEAR_CONTEXT* clear; + PROGRESSIVE_CONTEXT* progressive; + BITMAP_PLANAR_CONTEXT* planar; + BITMAP_INTERLEAVED_CONTEXT* interleaved; + }; + typedef struct rdp_codecs rdpCodecs; + + FREERDP_API BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width, + UINT32 height); + FREERDP_API BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags, UINT32 width, + UINT32 height); + + /** + * @brief Free a rdpCodecs instance + * @param codecs A pointer to a rdpCodecs instance or NULL + * @since version 3.6.0 + */ + FREERDP_API void freerdp_client_codecs_free(rdpCodecs* codecs); + + /** + * @brief Allocate a rdpCodecs instance. + * @return A newly allocated instance or \b NULL in case of failure. + * @since version 3.6.0 + */ + WINPR_ATTR_MALLOC(freerdp_client_codecs_free, 1) + FREERDP_API rdpCodecs* freerdp_client_codecs_new(UINT32 TheadingFlags); + + FREERDP_API WINPR_DEPRECATED_VAR("[since 3.6.0] Use freerdp_client_codecs_free", + void codecs_free(rdpCodecs* codecs)); + + FREERDP_API WINPR_DEPRECATED_VAR("[since 3.6.0] Use freerdp_client_codecs_new", + rdpCodecs* codecs_new(rdpContext* context)); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CODECS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/constants.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/constants.h new file mode 100644 index 0000000000000000000000000000000000000000..b1cb0d75421d1564dd0ffb3791aa24ef32270807 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/constants.h @@ -0,0 +1,70 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Constants + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CONSTANTS_H +#define FREERDP_CONSTANTS_H + +/** + * Codec IDs + */ +enum RDP_CODEC_ID +{ + RDP_CODEC_ID_NONE = 0x00, + RDP_CODEC_ID_NSCODEC = 0x01, + RDP_CODEC_ID_JPEG = 0x02, + RDP_CODEC_ID_REMOTEFX = 0x03, + RDP_CODEC_ID_IMAGE_REMOTEFX = 0x04 +}; + +/** + * CPU Optimization flags + */ +#define CPU_SSE2 0x1 + +/** + * OSMajorType + */ +#define OSMAJORTYPE_UNSPECIFIED 0x0000 +#define OSMAJORTYPE_WINDOWS 0x0001 +#define OSMAJORTYPE_OS2 0x0002 +#define OSMAJORTYPE_MACINTOSH 0x0003 +#define OSMAJORTYPE_UNIX 0x0004 +#define OSMAJORTYPE_IOS 0x0005 +#define OSMAJORTYPE_OSX 0x0006 +#define OSMAJORTYPE_ANDROID 0x0007 +#define OSMAJORTYPE_CHROME_OS 0x0008 + +/** + * OSMinorType + */ +#define OSMINORTYPE_UNSPECIFIED 0x0000 +#define OSMINORTYPE_WINDOWS_31X 0x0001 +#define OSMINORTYPE_WINDOWS_95 0x0002 +#define OSMINORTYPE_WINDOWS_NT 0x0003 +#define OSMINORTYPE_OS2_V21 0x0004 +#define OSMINORTYPE_POWER_PC 0x0005 +#define OSMINORTYPE_MACINTOSH 0x0006 +#define OSMINORTYPE_NATIVE_XSERVER 0x0007 +#define OSMINORTYPE_PSEUDO_XSERVER 0x0008 +#define OSMINORTYPE_WINDOWS_RT 0x0009 +/* As of 2022-03-29 the following does not exist officially in [MS-RDPBCGR] */ +#define OSMINORTYPE_NATIVE_WAYLAND (0xFFFF - 1) +#define OSMINORTYPE_NATIVE_SDL (0xFFFF - 2) + +#endif /* FREERDP_CONSTANTS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/ber.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/ber.h new file mode 100644 index 0000000000000000000000000000000000000000..072517c41b5b16620639b386063e569fb6bf164c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/ber.h @@ -0,0 +1,106 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ASN.1 Basic Encoding Rules (BER) + * + * Copyright 2011-2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_BER_H +#define FREERDP_CRYPTO_BER_H + +#include +#include + +#include + +/* BER type */ + +/* Class - bits 8 and 7 */ +#define BER_CLASS_MASK 0xC0 +#define BER_CLASS_UNIV 0x00 /* 0 0 */ +#define BER_CLASS_APPL 0x40 /* 0 1 */ +#define BER_CLASS_CTXT 0x80 /* 1 0 */ +#define BER_CLASS_PRIV 0xC0 /* 1 1 */ + +/* P/C - bit 6 */ +#define BER_PC_MASK 0x20 +#define BER_PRIMITIVE 0x00 /* 0 */ +#define BER_CONSTRUCT 0x20 /* 1 */ + +/* Tag - bits 5 to 1 */ +#define BER_TAG_MASK 0x1F +#define BER_TAG_BOOLEAN 0x01 +#define BER_TAG_INTEGER 0x02 +#define BER_TAG_BIT_STRING 0x03 +#define BER_TAG_OCTET_STRING 0x04 +#define BER_TAG_OBJECT_IDENFIER 0x06 +#define BER_TAG_ENUMERATED 0x0A +#define BER_TAG_SEQUENCE 0x10 +#define BER_TAG_SEQUENCE_OF 0x10 + +#define BER_PC(_pc) (_pc ? BER_CONSTRUCT : BER_PRIMITIVE) + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API BOOL ber_read_length(wStream* s, size_t* length); + FREERDP_API size_t ber_write_length(wStream* s, size_t length); + FREERDP_API size_t _ber_sizeof_length(size_t length); + FREERDP_API BOOL ber_read_universal_tag(wStream* s, BYTE tag, BOOL pc); + FREERDP_API size_t ber_write_universal_tag(wStream* s, BYTE tag, BOOL pc); + FREERDP_API BOOL ber_read_application_tag(wStream* s, BYTE tag, size_t* length); + FREERDP_API void ber_write_application_tag(wStream* s, BYTE tag, size_t length); + FREERDP_API BOOL ber_read_enumerated(wStream* s, BYTE* enumerated, BYTE count); + FREERDP_API void ber_write_enumerated(wStream* s, BYTE enumerated, BYTE count); + FREERDP_API BOOL ber_read_contextual_tag(wStream* s, BYTE tag, size_t* length, BOOL pc); + FREERDP_API size_t ber_write_contextual_tag(wStream* s, BYTE tag, size_t length, BOOL pc); + FREERDP_API size_t ber_sizeof_contextual_tag(size_t length); + FREERDP_API BOOL ber_read_sequence_tag(wStream* s, size_t* length); + FREERDP_API size_t ber_write_sequence_tag(wStream* s, size_t length); + FREERDP_API size_t ber_sizeof_sequence(size_t length); + FREERDP_API size_t ber_sizeof_sequence_tag(size_t length); + FREERDP_API BOOL ber_read_bit_string(wStream* s, size_t* length, BYTE* padding); + + FREERDP_API BOOL ber_read_octet_string_tag(wStream* s, size_t* length); + FREERDP_API BOOL ber_read_octet_string(wStream* s, BYTE** content, size_t* length); + FREERDP_API size_t ber_write_octet_string_tag(wStream* s, size_t length); + FREERDP_API size_t ber_sizeof_octet_string(size_t length); + FREERDP_API size_t ber_sizeof_contextual_octet_string(size_t length); + FREERDP_API size_t ber_write_char_to_unicode_octet_string(wStream* s, const char* str); + FREERDP_API size_t ber_write_contextual_char_to_unicode_octet_string(wStream* s, BYTE tag, + const char* oct_str); + FREERDP_API size_t ber_write_octet_string(wStream* s, const BYTE* oct_str, size_t length); + FREERDP_API BOOL ber_read_char_from_unicode_octet_string(wStream* s, char** str); + FREERDP_API BOOL ber_read_unicode_octet_string(wStream* s, LPWSTR* str); + FREERDP_API size_t ber_write_contextual_octet_string(wStream* s, BYTE tag, const BYTE* oct_str, + size_t length); + FREERDP_API size_t ber_write_contextual_unicode_octet_string(wStream* s, BYTE tag, LPWSTR str); + + FREERDP_API BOOL ber_read_BOOL(wStream* s, BOOL* value); + FREERDP_API void ber_write_BOOL(wStream* s, BOOL value); + FREERDP_API BOOL ber_read_integer(wStream* s, UINT32* value); + FREERDP_API size_t ber_write_integer(wStream* s, UINT32 value); + FREERDP_API size_t ber_write_contextual_integer(wStream* s, BYTE tag, UINT32 value); + FREERDP_API BOOL ber_read_integer_length(wStream* s, size_t* length); + FREERDP_API size_t ber_sizeof_integer(UINT32 value); + FREERDP_API size_t ber_sizeof_contextual_integer(UINT32 value); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_BER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate.h new file mode 100644 index 0000000000000000000000000000000000000000..be2013f6cdaff6b336b38128148653e3ae636fa0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate.h @@ -0,0 +1,149 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Certificate Handling + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_CERTIFICATE_H +#define FREERDP_CRYPTO_CERTIFICATE_H + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + enum FREERDP_CERT_PARAM + { + FREERDP_CERT_RSA_E, + FREERDP_CERT_RSA_N + }; + + typedef struct rdp_certificate rdpCertificate; + + FREERDP_API void freerdp_certificate_free(rdpCertificate* certificate); + + WINPR_ATTR_MALLOC(freerdp_certificate_free, 1) + FREERDP_API rdpCertificate* freerdp_certificate_new(void); + + WINPR_ATTR_MALLOC(freerdp_certificate_free, 1) + FREERDP_API rdpCertificate* freerdp_certificate_new_from_file(const char* file); + + WINPR_ATTR_MALLOC(freerdp_certificate_free, 1) + FREERDP_API rdpCertificate* freerdp_certificate_new_from_pem(const char* pem); + + WINPR_ATTR_MALLOC(freerdp_certificate_free, 1) + FREERDP_API rdpCertificate* freerdp_certificate_new_from_der(const BYTE* data, size_t length); + + FREERDP_API BOOL freerdp_certificate_is_rsa(const rdpCertificate* certificate); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_hash(const rdpCertificate* certificate, + const char* hash, size_t* plength); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_fingerprint_by_hash(const rdpCertificate* certificate, + const char* hash); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* + freerdp_certificate_get_fingerprint_by_hash_ex(const rdpCertificate* certificate, + const char* hash, BOOL separator); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_fingerprint(const rdpCertificate* certificate); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_pem(const rdpCertificate* certificate, + size_t* pLength); + + FREERDP_API int freerdp_certificate_policies(const rdpCertificate* certificate, + const char* oid); + /** + * @brief Get the certificate as PEM string + * @param certificate A certificate instance to query + * @param pLength A pointer to the size in bytes of the PEM string + * @param withCertChain \b TRUE to export a full chain PEM, \b FALSE for only the last + * certificate in the chain + * @return A newly allocated string containing the requested PEM (free to deallocate) or NULL + * @since version 3.8.0 + */ + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_pem_ex(const rdpCertificate* certificate, + size_t* pLength, BOOL withCertChain); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API BYTE* freerdp_certificate_get_der(const rdpCertificate* certificate, + size_t* pLength); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_subject(const rdpCertificate* certificate); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_issuer(const rdpCertificate* certificate); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_upn(const rdpCertificate* certificate); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_email(const rdpCertificate* certificate); + + /** + * @brief return the date string of the certificate validity + * @param certificate The certificate instance to query + * @param startDate \b TRUE return the start date, \b FALSE for the end date + * @return A newly allocated string containing the date, use \b free to deallocate + * @since version 3.8.0 + */ + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_validity(const rdpCertificate* certificate, + BOOL startDate); + + FREERDP_API WINPR_MD_TYPE freerdp_certificate_get_signature_alg(const rdpCertificate* cert); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_common_name(const rdpCertificate* cert, + size_t* plength); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char** freerdp_certificate_get_dns_names(const rdpCertificate* cert, size_t* pcount, + size_t** pplengths); + FREERDP_API void freerdp_certificate_free_dns_names(size_t count, size_t* lengths, + char** names); + + FREERDP_API BOOL freerdp_certificate_check_eku(const rdpCertificate* certificate, int nid); + + FREERDP_API BOOL freerdp_certificate_get_public_key(const rdpCertificate* cert, + BYTE** PublicKey, DWORD* PublicKeyLength); + + FREERDP_API BOOL freerdp_certificate_verify(const rdpCertificate* cert, + const char* certificate_store_path); + + FREERDP_API BOOL freerdp_certificate_is_rdp_security_compatible(const rdpCertificate* cert); + + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_certificate_get_param(const rdpCertificate* cert, + enum FREERDP_CERT_PARAM what, size_t* psize); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_CERTIFICATE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate_data.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate_data.h new file mode 100644 index 0000000000000000000000000000000000000000..96a620dc83a5bb6d72b60525c355c586ceee1dd1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate_data.h @@ -0,0 +1,74 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Certificate Handling + * + * Copyright 2011-2012 Marc-Andre Moreau + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_CERTIFICATE_DATA_H +#define FREERDP_CRYPTO_CERTIFICATE_DATA_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_certificate_data rdpCertificateData; + + FREERDP_API char* freerdp_certificate_data_hash(const char* hostname, UINT16 port); + + FREERDP_API void freerdp_certificate_data_free(rdpCertificateData* data); + + WINPR_ATTR_MALLOC(freerdp_certificate_data_free, 1) + FREERDP_API rdpCertificateData* freerdp_certificate_data_new(const char* hostname, UINT16 port, + const rdpCertificate* xcert); + + WINPR_ATTR_MALLOC(freerdp_certificate_data_free, 1) + FREERDP_API rdpCertificateData* freerdp_certificate_data_new_from_pem(const char* hostname, + UINT16 port, + const char* pem, + size_t length); + + WINPR_ATTR_MALLOC(freerdp_certificate_data_free, 1) + FREERDP_API rdpCertificateData* + freerdp_certificate_data_new_from_file(const char* hostname, UINT16 port, const char* file); + + FREERDP_API BOOL freerdp_certificate_data_equal(const rdpCertificateData* a, + const rdpCertificateData* b); + + FREERDP_API const char* freerdp_certificate_data_get_hash(const rdpCertificateData* cert); + + FREERDP_API const char* freerdp_certificate_data_get_host(const rdpCertificateData* cert); + FREERDP_API UINT16 freerdp_certificate_data_get_port(const rdpCertificateData* cert); + + FREERDP_API const char* freerdp_certificate_data_get_pem(const rdpCertificateData* cert); + FREERDP_API const char* freerdp_certificate_data_get_pem_ex(const rdpCertificateData* cert, + BOOL withFullChain); + FREERDP_API const char* freerdp_certificate_data_get_subject(const rdpCertificateData* cert); + FREERDP_API const char* freerdp_certificate_data_get_issuer(const rdpCertificateData* cert); + FREERDP_API const char* + freerdp_certificate_data_get_fingerprint(const rdpCertificateData* cert); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_CERTIFICATE_DATA_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate_store.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate_store.h new file mode 100644 index 0000000000000000000000000000000000000000..fc84da105fed784157a26519963aeaf80daf66d6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/certificate_store.h @@ -0,0 +1,82 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Certificate Handling + * + * Copyright 2011-2012 Marc-Andre Moreau + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_CERTIFICATE_STORE_H +#define FREERDP_CRYPTO_CERTIFICATE_STORE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_certificate_store rdpCertificateStore; + + typedef enum + { + CERT_STORE_NOT_FOUND = 1, + CERT_STORE_MATCH = 0, + CERT_STORE_MISMATCH = -1 + } freerdp_certificate_store_result; + + FREERDP_API void freerdp_certificate_store_free(rdpCertificateStore* store); + + WINPR_ATTR_MALLOC(freerdp_certificate_store_free, 1) + FREERDP_API rdpCertificateStore* freerdp_certificate_store_new(const rdpSettings* settings); + + FREERDP_API freerdp_certificate_store_result freerdp_certificate_store_contains_data( + rdpCertificateStore* store, const rdpCertificateData* data); + + WINPR_ATTR_MALLOC(freerdp_certificate_data_free, 1) + FREERDP_API rdpCertificateData* + freerdp_certificate_store_load_data(rdpCertificateStore* store, const char* host, UINT16 port); + + FREERDP_API BOOL freerdp_certificate_store_save_data(rdpCertificateStore* store, + const rdpCertificateData* data); + FREERDP_API BOOL freerdp_certificate_store_remove_data(rdpCertificateStore* store, + const rdpCertificateData* data); + + FREERDP_API const char* + freerdp_certificate_store_get_certs_path(const rdpCertificateStore* store); + FREERDP_API const char* + freerdp_certificate_store_get_hosts_path(const rdpCertificateStore* store); + + /** Query the certificate store path + * + * @param store The certificate store to query + * @param host The hostname to look up + * @param port The port to look up + * + * @since version 3.0.0 + * + * @return The certificate store file path or \b NULL + */ + FREERDP_API char* freerdp_certificate_store_get_cert_path(const rdpCertificateStore* store, + const char* host, UINT16 port); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_CERTIFICATE_STORE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/crypto.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/crypto.h new file mode 100644 index 0000000000000000000000000000000000000000..c052db82e8c8fbab965c5a3910faa88dbd5c7a62 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/crypto.h @@ -0,0 +1,74 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Cryptographic Abstraction Layer + * + * Copyright 2011-2012 Marc-Andre Moreau + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_H +#define FREERDP_CRYPTO_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + struct rdp_CertInfo + { + BYTE* Modulus; + DWORD ModulusLength; + BYTE exponent[4]; + }; + typedef struct rdp_CertInfo rdpCertInfo; + + FREERDP_API char* crypto_base64_encode(const BYTE* WINPR_RESTRICT data, size_t length); + + /** BASE64 encode data + * + * @param data The data to encode + * @param length The length of the data in bytes + * @param withCrLf Option to split the encoded data with CRLF linebreaks + * + * @since version 3.0.0 + * + * @return The encoded BASE64 string or \b NULL if failed + */ + FREERDP_API char* crypto_base64_encode_ex(const BYTE* WINPR_RESTRICT data, size_t length, + BOOL withCrLf); + + FREERDP_API void crypto_base64_decode(const char* WINPR_RESTRICT enc_data, size_t length, + BYTE** WINPR_RESTRICT dec_data, + size_t* WINPR_RESTRICT res_length); + + FREERDP_API char* crypto_base64url_encode(const BYTE* WINPR_RESTRICT data, size_t length); + FREERDP_API void crypto_base64url_decode(const char* WINPR_RESTRICT enc_data, size_t length, + BYTE** WINPR_RESTRICT dec_data, + size_t* WINPR_RESTRICT res_length); + + FREERDP_API char* crypto_read_pem(const char* WINPR_RESTRICT filename, + size_t* WINPR_RESTRICT plength); + FREERDP_API BOOL crypto_write_pem(const char* WINPR_RESTRICT filename, + const char* WINPR_RESTRICT pem, size_t length); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/der.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/der.h new file mode 100644 index 0000000000000000000000000000000000000000..8ec27f08f93eea732baf58900f36c44d85832fe5 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/der.h @@ -0,0 +1,44 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ASN.1 Basic Encoding Rules (DER) + * + * Copyright 2011 Samsung, Author Jiten Pathy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_DER_H +#define FREERDP_CRYPTO_DER_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API int _der_skip_length(int length); + FREERDP_API int der_write_length(wStream* s, int length); + FREERDP_API int der_get_content_length(int length); + FREERDP_API int der_skip_octet_string(int length); + FREERDP_API int der_skip_sequence_tag(int length); + FREERDP_API int der_write_sequence_tag(wStream* s, int length); + FREERDP_API int der_skip_contextual_tag(int length); + FREERDP_API int der_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc); + FREERDP_API void der_write_octet_string(wStream* s, BYTE* oct_str, int length); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_DER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/er.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/er.h new file mode 100644 index 0000000000000000000000000000000000000000..d981b4e936d0087621fa7f86aca49866b1da3ec0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/er.h @@ -0,0 +1,97 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ASN.1 Encoding Rules (BER/DER common functions) + * + * Copyright 2011 Marc-Andre Moreau + * Modified by Jiten Pathy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_ER_H +#define FREERDP_CRYPTO_ER_H + +#include +#include + +#include + +/* ER type */ + +/* Class - bits 8 and 7 */ +#define ER_CLASS_MASK 0xC0 +#define ER_CLASS_UNIV 0x00 /* 0 0 */ +#define ER_CLASS_APPL 0x40 /* 0 1 */ +#define ER_CLASS_CTXT 0x80 /* 1 0 */ +#define ER_CLASS_PRIV 0xC0 /* 1 1 */ + +/* P/C - bit 6 */ +#define ER_PC_MASK 0x20 +#define ER_PRIMITIVE 0x00 /* 0 */ +#define ER_CONSTRUCT 0x20 /* 1 */ + +/* Tag - bits 5 to 1 */ +#define ER_TAG_MASK 0x1F +#define ER_TAG_BOOLEAN 0x01 +#define ER_TAG_INTEGER 0x02 +#define ER_TAG_BIT_STRING 0x03 +#define ER_TAG_OCTET_STRING 0x04 +#define ER_TAG_OBJECT_IDENTIFIER 0x06 +#define ER_TAG_ENUMERATED 0x0A +#define ER_TAG_SEQUENCE 0x10 +#define ER_TAG_SEQUENCE_OF 0x10 +#define ER_TAG_GENERAL_STRING 0x1B +#define ER_TAG_GENERALIZED_TIME 0x18 + +#define ER_PC(_pc) (_pc ? ER_CONSTRUCT : ER_PRIMITIVE) + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API void er_read_length(wStream* s, int* length); + FREERDP_API int er_write_length(wStream* s, int length, BOOL flag); + FREERDP_API int _er_skip_length(int length); + FREERDP_API int er_get_content_length(int length); + FREERDP_API BOOL er_read_universal_tag(wStream* s, BYTE tag, BOOL pc); + FREERDP_API void er_write_universal_tag(wStream* s, BYTE tag, BOOL pc); + FREERDP_API BOOL er_read_application_tag(wStream* s, BYTE tag, int* length); + FREERDP_API void er_write_application_tag(wStream* s, BYTE tag, int length, BOOL flag); + FREERDP_API BOOL er_read_enumerated(wStream* s, BYTE* enumerated, BYTE count); + FREERDP_API void er_write_enumerated(wStream* s, BYTE enumerated, BYTE count, BOOL flag); + FREERDP_API BOOL er_read_contextual_tag(wStream* s, BYTE tag, int* length, BOOL pc); + FREERDP_API int er_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc, BOOL flag); + FREERDP_API int er_skip_contextual_tag(int length); + FREERDP_API BOOL er_read_sequence_tag(wStream* s, int* length); + FREERDP_API int er_write_sequence_tag(wStream* s, int length, BOOL flag); + FREERDP_API int er_skip_sequence(int length); + FREERDP_API int er_skip_sequence_tag(int length); + FREERDP_API BOOL er_read_bit_string(wStream* s, int* length, BYTE* padding); + FREERDP_API BOOL er_write_bit_string_tag(wStream* s, UINT32 length, BYTE padding, BOOL flag); + FREERDP_API BOOL er_read_octet_string(wStream* s, int* length); + FREERDP_API void er_write_octet_string(wStream* s, BYTE* oct_str, int length, BOOL flag); + FREERDP_API int er_write_octet_string_tag(wStream* s, int length, BOOL flag); + FREERDP_API int er_skip_octet_string(int length); + FREERDP_API BOOL er_read_BOOL(wStream* s, BOOL* value); + FREERDP_API void er_write_BOOL(wStream* s, BOOL value); + FREERDP_API BOOL er_read_integer(wStream* s, UINT32* value); + FREERDP_API int er_write_integer(wStream* s, INT32 value); + FREERDP_API BOOL er_read_integer_length(wStream* s, int* length); + FREERDP_API int er_skip_integer(INT32 value); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_ER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/per.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/per.h new file mode 100644 index 0000000000000000000000000000000000000000..087a17fe2c4ba4184dbd75063184925d36c1e32c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/per.h @@ -0,0 +1,62 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ASN.1 Packed Encoding Rules (BER) + * + * Copyright 2011-2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_PER_H +#define FREERDP_CRYPTO_PER_H + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API BOOL per_read_length(wStream* s, UINT16* length); + FREERDP_API BOOL per_write_length(wStream* s, UINT16 length); + FREERDP_API BOOL per_read_choice(wStream* s, BYTE* choice); + FREERDP_API BOOL per_write_choice(wStream* s, BYTE choice); + FREERDP_API BOOL per_read_selection(wStream* s, BYTE* selection); + FREERDP_API BOOL per_write_selection(wStream* s, BYTE selection); + FREERDP_API BOOL per_read_number_of_sets(wStream* s, BYTE* number); + FREERDP_API BOOL per_write_number_of_sets(wStream* s, BYTE number); + FREERDP_API BOOL per_read_padding(wStream* s, UINT16 length); + FREERDP_API BOOL per_write_padding(wStream* s, UINT16 length); + FREERDP_API BOOL per_read_integer(wStream* s, UINT32* integer); + FREERDP_API BOOL per_read_integer16(wStream* s, UINT16* integer, UINT16 min); + FREERDP_API BOOL per_write_integer(wStream* s, UINT32 integer); + FREERDP_API BOOL per_write_integer16(wStream* s, UINT16 integer, UINT16 min); + FREERDP_API BOOL per_read_enumerated(wStream* s, BYTE* enumerated, BYTE count); + FREERDP_API BOOL per_write_enumerated(wStream* s, BYTE enumerated, BYTE count); + FREERDP_API BOOL per_write_object_identifier(wStream* s, const BYTE oid[6]); + FREERDP_API BOOL per_read_object_identifier(wStream* s, const BYTE oid[6]); + FREERDP_API BOOL per_read_octet_string(wStream* s, const BYTE* oct_str, UINT16 length, + UINT16 min); + FREERDP_API BOOL per_write_octet_string(wStream* s, const BYTE* oct_str, UINT16 length, + UINT16 min); + FREERDP_API BOOL per_read_numeric_string(wStream* s, UINT16 min); + FREERDP_API BOOL per_write_numeric_string(wStream* s, const BYTE* num_str, UINT16 length, + UINT16 min); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_PER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/privatekey.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/privatekey.h new file mode 100644 index 0000000000000000000000000000000000000000..58fd94b40067623ecd0cf5a8e747394cc59e5875 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/crypto/privatekey.h @@ -0,0 +1,52 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Private key Handling + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CRYPTO_PRIVATEKEY_H +#define FREERDP_CRYPTO_PRIVATEKEY_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_private_key rdpPrivateKey; + + FREERDP_API void freerdp_key_free(rdpPrivateKey* key); + + WINPR_ATTR_MALLOC(freerdp_key_free, 1) + FREERDP_API rdpPrivateKey* freerdp_key_new(void); + + WINPR_ATTR_MALLOC(freerdp_key_free, 1) + FREERDP_API rdpPrivateKey* freerdp_key_new_from_file(const char* keyfile); + + WINPR_ATTR_MALLOC(freerdp_key_free, 1) + FREERDP_API rdpPrivateKey* freerdp_key_new_from_pem(const char* pem); + + FREERDP_API BOOL freerdp_key_is_rsa(const rdpPrivateKey* key); + + FREERDP_API size_t freerdp_key_get_bits(const rdpPrivateKey* key); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CRYPTO_PRIVATEKEY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/display.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/display.h new file mode 100644 index 0000000000000000000000000000000000000000..33ae6c79ee984034bb6fdc710af9259006afca0d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/display.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Display update notifications + * + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_DISPLAY_H +#define FREERDP_DISPLAY_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API BOOL freerdp_display_send_monitor_layout(rdpContext* context, UINT32 monitorCount, + const MONITOR_DEF* monitorDefArray); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_DISPLAY_UPDATE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/dvc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/dvc.h new file mode 100644 index 0000000000000000000000000000000000000000..c43a641ff6e9baea341e753c200a8d7c4db77797 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/dvc.h @@ -0,0 +1,180 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic Virtual Channel Interface + * + * Copyright 2010-2011 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * DVC Plugin API: See the original MS DVC Client API: + * http://msdn.microsoft.com/en-us/library/bb540880%28v=VS.85%29.aspx + * + * The FreeRDP DVC Plugin API is a simulation of the MS DVC Client API in C. + * The main difference is that every interface method must take an instance + * pointer as the first parameter. + */ + +/** + * Implemented by DRDYNVC: + * o IWTSVirtualChannelManager + * o IWTSListener + * o IWTSVirtualChannel + * + * Implemented by DVC plugin: + * o IWTSPlugin + * o IWTSListenerCallback + * o IWTSVirtualChannelCallback + * + * A basic DVC plugin implementation: + * 1. DVCPluginEntry: + * The plugin entry point, which creates and initializes a new IWTSPlugin + * instance + * 2. IWTSPlugin.Initialize: + * Call IWTSVirtualChannelManager.CreateListener with a newly created + * IWTSListenerCallback instance + * 3. IWTSListenerCallback.OnNewChannelConnection: + * Create IWTSVirtualChannelCallback instance if the new channel is accepted + */ + +#ifndef FREERDP_DVC_H +#define FREERDP_DVC_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_IWTSVirtualChannelManager IWTSVirtualChannelManager; + typedef struct s_IWTSListener IWTSListener; + typedef struct s_IWTSVirtualChannel IWTSVirtualChannel; + + typedef struct s_IWTSPlugin IWTSPlugin; + typedef struct s_IWTSListenerCallback IWTSListenerCallback; + typedef struct s_IWTSVirtualChannelCallback IWTSVirtualChannelCallback; + + struct s_IWTSListener + { + /* Retrieves the listener-specific configuration. */ + UINT (*GetConfiguration)(IWTSListener* pListener, void** ppPropertyBag); + + void* pInterface; + }; + + struct s_IWTSVirtualChannel + { + /* Starts a write request on the channel. */ + UINT(*Write) + (IWTSVirtualChannel* pChannel, ULONG cbSize, const BYTE* pBuffer, void* pReserved); + /* Closes the channel. */ + UINT (*Close)(IWTSVirtualChannel* pChannel); + }; + + struct s_IWTSVirtualChannelManager + { + /* Returns an instance of a listener object that listens on a specific + endpoint, or creates a static channel. */ + UINT(*CreateListener) + (IWTSVirtualChannelManager* pChannelMgr, const char* pszChannelName, ULONG ulFlags, + IWTSListenerCallback* pListenerCallback, IWTSListener** ppListener); + /* Find the channel or ID to send data to a specific endpoint. */ + UINT32 (*GetChannelId)(IWTSVirtualChannel* channel); + IWTSVirtualChannel* (*FindChannelById)(IWTSVirtualChannelManager* pChannelMgr, + UINT32 ChannelId); + const char* (*GetChannelName)(IWTSVirtualChannel* channel); + UINT (*DestroyListener)(IWTSVirtualChannelManager* pChannelMgr, IWTSListener* ppListener); + }; + + struct s_IWTSPlugin + { + /* Used for the first call that is made from the client to the plug-in. */ + UINT (*Initialize)(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr); + /* Notifies the plug-in that the Remote Desktop Connection (RDC) client + has successfully connected to the Remote Desktop Session Host (RD + Session Host) server. */ + UINT (*Connected)(IWTSPlugin* pPlugin); + /* Notifies the plug-in that the Remote Desktop Connection (RDC) client + has disconnected from the RD Session Host server. */ + UINT (*Disconnected)(IWTSPlugin* pPlugin, DWORD dwDisconnectCode); + /* Notifies the plug-in that the Remote Desktop Connection (RDC) client + has terminated. */ + UINT (*Terminated)(IWTSPlugin* pPlugin); + + UINT (*Attached)(IWTSPlugin* pPlugin); + + UINT (*Detached)(IWTSPlugin* pPlugin); + + /* Extended */ + + void* pInterface; + }; + + struct s_IWTSListenerCallback + { + /* Accepts or denies a connection request for an incoming connection to + the associated listener. */ + UINT(*OnNewChannelConnection) + (IWTSListenerCallback* pListenerCallback, IWTSVirtualChannel* pChannel, BYTE* Data, + BOOL* pbAccept, IWTSVirtualChannelCallback** ppCallback); + + void* pInterface; + }; + + struct s_IWTSVirtualChannelCallback + { + UINT(*OnDataReceived) + (IWTSVirtualChannelCallback* pChannelCallback, + wStream* data); /**< Notifies the user about data that is being received. */ + UINT(*OnOpen) + (IWTSVirtualChannelCallback* + pChannelCallback); /**< Notifies the user that the channel has been opened. */ + UINT(*OnClose) + (IWTSVirtualChannelCallback* + pChannelCallback); /**< Notifies the user that the channel has been closed. */ + + void* pInterface; + }; + + /* The DVC Plugin entry points */ + typedef struct rdp_context rdpContext; /* forward declaration, necessary to avoid + * circular includes */ + + typedef struct S_IDRDYNVC_ENTRY_POINTS IDRDYNVC_ENTRY_POINTS; + struct S_IDRDYNVC_ENTRY_POINTS + { + UINT(*RegisterPlugin) + (IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name, IWTSPlugin* pPlugin); + IWTSPlugin* (*GetPlugin)(IDRDYNVC_ENTRY_POINTS* pEntryPoints, const char* name); + const ADDIN_ARGV* (*GetPluginData)(IDRDYNVC_ENTRY_POINTS* pEntryPoints); + rdpSettings* (*GetRdpSettings)(IDRDYNVC_ENTRY_POINTS* pEntryPoints); + rdpContext* (*GetRdpContext)(IDRDYNVC_ENTRY_POINTS* pEntryPoints); + }; + + typedef UINT(VCAPITYPE* PDVC_PLUGIN_ENTRY)(IDRDYNVC_ENTRY_POINTS*); + + void* get_callback_by_name(const char* name, void** context); + void add_callback_by_name(const char* name, void* fkt, void* context); + void remove_callback_by_name(const char* name, void* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_DVC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/emulate/scard/smartcard_emulate.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/emulate/scard/smartcard_emulate.h new file mode 100644 index 0000000000000000000000000000000000000000..c2865b485fb89e8bbb7cabcca1572c4bca98c7d4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/emulate/scard/smartcard_emulate.h @@ -0,0 +1,363 @@ +/** + * WinPR: Windows Portable Runtime + * Smart Card API emulation + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_SMARTCARD_EMULATE_PRIVATE_H +#define WINPR_SMARTCARD_EMULATE_PRIVATE_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct smartcard_emulation_context SmartcardEmulationContext; + + FREERDP_API void Emulate_Free(SmartcardEmulationContext* context); + + WINPR_ATTR_MALLOC(Emulate_Free, 1) + FREERDP_API SmartcardEmulationContext* Emulate_New(const rdpSettings* settings); + + FREERDP_API BOOL Emulate_IsConfigured(SmartcardEmulationContext* context); + + FREERDP_API LONG WINAPI Emulate_SCardEstablishContext(SmartcardEmulationContext* smartcard, + DWORD dwScope, LPCVOID pvReserved1, + LPCVOID pvReserved2, + LPSCARDCONTEXT phContext); + + FREERDP_API LONG WINAPI Emulate_SCardReleaseContext(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext); + + FREERDP_API LONG WINAPI Emulate_SCardIsValidContext(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext); + + FREERDP_API LONG WINAPI Emulate_SCardListReaderGroupsA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPSTR mszGroups, + LPDWORD pcchGroups); + + FREERDP_API LONG WINAPI Emulate_SCardListReaderGroupsW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPWSTR mszGroups, + LPDWORD pcchGroups); + + FREERDP_API LONG WINAPI Emulate_SCardListReadersA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR mszGroups, + LPSTR mszReaders, LPDWORD pcchReaders); + + FREERDP_API LONG WINAPI Emulate_SCardListReadersW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR mszGroups, + LPWSTR mszReaders, LPDWORD pcchReaders); + + FREERDP_API LONG WINAPI Emulate_SCardListCardsA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCBYTE pbAtr, + LPCGUID rgquidInterfaces, + DWORD cguidInterfaceCount, CHAR* mszCards, + LPDWORD pcchCards); + + FREERDP_API LONG WINAPI Emulate_SCardListCardsW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCBYTE pbAtr, + LPCGUID rgquidInterfaces, + DWORD cguidInterfaceCount, WCHAR* mszCards, + LPDWORD pcchCards); + + FREERDP_API LONG WINAPI Emulate_SCardListInterfacesA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szCard, + LPGUID pguidInterfaces, + LPDWORD pcguidInterfaces); + + FREERDP_API LONG WINAPI Emulate_SCardListInterfacesW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szCard, + LPGUID pguidInterfaces, + LPDWORD pcguidInterfaces); + + FREERDP_API LONG WINAPI Emulate_SCardGetProviderIdA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szCard, + LPGUID pguidProviderId); + + FREERDP_API LONG WINAPI Emulate_SCardGetProviderIdW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szCard, + LPGUID pguidProviderId); + + FREERDP_API LONG WINAPI Emulate_SCardGetCardTypeProviderNameA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szCardName, + DWORD dwProviderId, CHAR* szProvider, LPDWORD pcchProvider); + + FREERDP_API LONG WINAPI Emulate_SCardGetCardTypeProviderNameW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szCardName, + DWORD dwProviderId, WCHAR* szProvider, LPDWORD pcchProvider); + + FREERDP_API LONG WINAPI Emulate_SCardIntroduceReaderGroupA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCSTR szGroupName); + + FREERDP_API LONG WINAPI Emulate_SCardIntroduceReaderGroupW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCWSTR szGroupName); + + FREERDP_API LONG WINAPI Emulate_SCardForgetReaderGroupA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCSTR szGroupName); + + FREERDP_API LONG WINAPI Emulate_SCardForgetReaderGroupW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCWSTR szGroupName); + + FREERDP_API LONG WINAPI Emulate_SCardIntroduceReaderA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCSTR szReaderName, LPCSTR szDeviceName); + + FREERDP_API LONG WINAPI Emulate_SCardIntroduceReaderW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCWSTR szReaderName, + LPCWSTR szDeviceName); + + FREERDP_API LONG WINAPI Emulate_SCardForgetReaderA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szReaderName); + + FREERDP_API LONG WINAPI Emulate_SCardForgetReaderW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szReaderName); + + FREERDP_API LONG WINAPI Emulate_SCardAddReaderToGroupA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCSTR szReaderName, LPCSTR szGroupName); + + FREERDP_API LONG WINAPI Emulate_SCardAddReaderToGroupW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCWSTR szReaderName, + LPCWSTR szGroupName); + + FREERDP_API LONG WINAPI + Emulate_SCardRemoveReaderFromGroupA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCSTR szReaderName, LPCSTR szGroupName); + + FREERDP_API LONG WINAPI + Emulate_SCardRemoveReaderFromGroupW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCWSTR szReaderName, LPCWSTR szGroupName); + + FREERDP_API LONG WINAPI Emulate_SCardIntroduceCardTypeA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szCardName, + LPCGUID pguidPrimaryProvider, LPCGUID rgguidInterfaces, DWORD dwInterfaceCount, + LPCBYTE pbAtr, LPCBYTE pbAtrMask, DWORD cbAtrLen); + + FREERDP_API LONG WINAPI Emulate_SCardIntroduceCardTypeW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szCardName, + LPCGUID pguidPrimaryProvider, LPCGUID rgguidInterfaces, DWORD dwInterfaceCount, + LPCBYTE pbAtr, LPCBYTE pbAtrMask, DWORD cbAtrLen); + + FREERDP_API LONG WINAPI Emulate_SCardSetCardTypeProviderNameA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szCardName, + DWORD dwProviderId, LPCSTR szProvider); + + FREERDP_API LONG WINAPI Emulate_SCardSetCardTypeProviderNameW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szCardName, + DWORD dwProviderId, LPCWSTR szProvider); + + FREERDP_API LONG WINAPI Emulate_SCardForgetCardTypeA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szCardName); + + FREERDP_API LONG WINAPI Emulate_SCardForgetCardTypeW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szCardName); + + FREERDP_API LONG WINAPI Emulate_SCardFreeMemory(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPVOID pvMem); + + FREERDP_API HANDLE WINAPI Emulate_SCardAccessStartedEvent(SmartcardEmulationContext* smartcard); + + FREERDP_API void WINAPI Emulate_SCardReleaseStartedEvent(SmartcardEmulationContext* smartcard); + + FREERDP_API LONG WINAPI Emulate_SCardLocateCardsA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR mszCards, + LPSCARD_READERSTATEA rgReaderStates, + DWORD cReaders); + + FREERDP_API LONG WINAPI Emulate_SCardLocateCardsW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR mszCards, + LPSCARD_READERSTATEW rgReaderStates, + DWORD cReaders); + + FREERDP_API LONG WINAPI Emulate_SCardLocateCardsByATRA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPSCARD_ATRMASK rgAtrMasks, DWORD cAtrs, + LPSCARD_READERSTATEA rgReaderStates, + DWORD cReaders); + + FREERDP_API LONG WINAPI Emulate_SCardLocateCardsByATRW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPSCARD_ATRMASK rgAtrMasks, DWORD cAtrs, + LPSCARD_READERSTATEW rgReaderStates, + DWORD cReaders); + + FREERDP_API LONG WINAPI Emulate_SCardGetStatusChangeA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, DWORD dwTimeout, + LPSCARD_READERSTATEA rgReaderStates, + DWORD cReaders); + + FREERDP_API LONG WINAPI Emulate_SCardGetStatusChangeW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, DWORD dwTimeout, + LPSCARD_READERSTATEW rgReaderStates, + DWORD cReaders); + + FREERDP_API LONG WINAPI Emulate_SCardCancel(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext); + + FREERDP_API LONG WINAPI Emulate_SCardConnectA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szReader, + DWORD dwShareMode, DWORD dwPreferredProtocols, + LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol); + + FREERDP_API LONG WINAPI Emulate_SCardConnectW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szReader, + DWORD dwShareMode, DWORD dwPreferredProtocols, + LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol); + + FREERDP_API LONG WINAPI Emulate_SCardReconnect(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, DWORD dwShareMode, + DWORD dwPreferredProtocols, + DWORD dwInitialization, + LPDWORD pdwActiveProtocol); + + FREERDP_API LONG WINAPI Emulate_SCardDisconnect(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, DWORD dwDisposition); + + FREERDP_API LONG WINAPI Emulate_SCardBeginTransaction(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard); + + FREERDP_API LONG WINAPI Emulate_SCardEndTransaction(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, DWORD dwDisposition); + + FREERDP_API LONG WINAPI Emulate_SCardCancelTransaction(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard); + + FREERDP_API LONG WINAPI Emulate_SCardState(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, LPDWORD pdwState, + LPDWORD pdwProtocol, LPBYTE pbAtr, + LPDWORD pcbAtrLen); + + FREERDP_API LONG WINAPI Emulate_SCardStatusA(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, LPSTR mszReaderNames, + LPDWORD pcchReaderLen, LPDWORD pdwState, + LPDWORD pdwProtocol, LPBYTE pbAtr, + LPDWORD pcbAtrLen); + + FREERDP_API LONG WINAPI Emulate_SCardStatusW(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, LPWSTR mszReaderNames, + LPDWORD pcchReaderLen, LPDWORD pdwState, + LPDWORD pdwProtocol, LPBYTE pbAtr, + LPDWORD pcbAtrLen); + + FREERDP_API LONG WINAPI Emulate_SCardTransmit(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, + LPCBYTE pbSendBuffer, DWORD cbSendLength, + LPSCARD_IO_REQUEST pioRecvPci, + LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength); + + FREERDP_API LONG WINAPI Emulate_SCardGetTransmitCount(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, + LPDWORD pcTransmitCount); + + FREERDP_API LONG WINAPI Emulate_SCardControl(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, DWORD dwControlCode, + LPCVOID lpInBuffer, DWORD cbInBufferSize, + LPVOID lpOutBuffer, DWORD cbOutBufferSize, + LPDWORD lpBytesReturned); + + FREERDP_API LONG WINAPI Emulate_SCardGetAttrib(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, + LPDWORD pcbAttrLen); + + FREERDP_API LONG WINAPI Emulate_SCardSetAttrib(SmartcardEmulationContext* smartcard, + SCARDHANDLE hCard, DWORD dwAttrId, + LPCBYTE pbAttr, DWORD cbAttrLen); + + FREERDP_API LONG WINAPI Emulate_SCardUIDlgSelectCardA(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEA_EX pDlgStruc); + + FREERDP_API LONG WINAPI Emulate_SCardUIDlgSelectCardW(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEW_EX pDlgStruc); + + FREERDP_API LONG WINAPI Emulate_GetOpenCardNameA(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEA pDlgStruc); + + FREERDP_API LONG WINAPI Emulate_GetOpenCardNameW(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEW pDlgStruc); + + FREERDP_API LONG WINAPI Emulate_SCardDlgExtendedError(SmartcardEmulationContext* smartcard); + + FREERDP_API LONG WINAPI Emulate_SCardReadCacheA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, UUID* CardIdentifier, + DWORD FreshnessCounter, LPSTR LookupName, + PBYTE Data, DWORD* DataLen); + + FREERDP_API LONG WINAPI Emulate_SCardReadCacheW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, UUID* CardIdentifier, + DWORD FreshnessCounter, LPWSTR LookupName, + PBYTE Data, DWORD* DataLen); + + FREERDP_API LONG WINAPI Emulate_SCardWriteCacheA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, UUID* CardIdentifier, + DWORD FreshnessCounter, LPSTR LookupName, + PBYTE Data, DWORD DataLen); + + FREERDP_API LONG WINAPI Emulate_SCardWriteCacheW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, UUID* CardIdentifier, + DWORD FreshnessCounter, LPWSTR LookupName, + PBYTE Data, DWORD DataLen); + + FREERDP_API LONG WINAPI Emulate_SCardGetReaderIconA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szReaderName, + LPBYTE pbIcon, LPDWORD pcbIcon); + + FREERDP_API LONG WINAPI Emulate_SCardGetReaderIconW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szReaderName, + LPBYTE pbIcon, LPDWORD pcbIcon); + + FREERDP_API LONG WINAPI Emulate_SCardGetDeviceTypeIdA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCSTR szReaderName, + LPDWORD pdwDeviceTypeId); + FREERDP_API LONG WINAPI Emulate_SCardGetDeviceTypeIdW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, + LPCWSTR szReaderName, + LPDWORD pdwDeviceTypeId); + + FREERDP_API LONG WINAPI Emulate_SCardGetReaderDeviceInstanceIdA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szReaderName, + LPSTR szDeviceInstanceId, LPDWORD pcchDeviceInstanceId); + + FREERDP_API LONG WINAPI Emulate_SCardGetReaderDeviceInstanceIdW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szReaderName, + LPWSTR szDeviceInstanceId, LPDWORD pcchDeviceInstanceId); + FREERDP_API LONG WINAPI Emulate_SCardListReadersWithDeviceInstanceIdA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szDeviceInstanceId, + LPSTR mszReaders, LPDWORD pcchReaders); + FREERDP_API LONG WINAPI Emulate_SCardListReadersWithDeviceInstanceIdW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szDeviceInstanceId, + LPWSTR mszReaders, LPDWORD pcchReaders); + FREERDP_API LONG WINAPI Emulate_SCardAudit(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, DWORD dwEvent); + +#ifdef __cplusplus +} +#endif + +#endif /* WINPR_SMARTCARD_EMULATE_PRIVATE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/error.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/error.h new file mode 100644 index 0000000000000000000000000000000000000000..58f93162475980d9d4e2044ed84c21e435762ef3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/error.h @@ -0,0 +1,360 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Error Codes + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_ERROR_H +#define FREERDP_ERROR_H + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Error categories */ +#define CAT_NONE "success" +#define CAT_USE "use" +#define CAT_BROKER "broker" +#define CAT_GATEWAY "gateway" +#define CAT_LICENSING "licensing" +#define CAT_SERVER "server" +#define CAT_CONFIG "config" +#define CAT_PROTOCOL "protocol" +#define CAT_ADMIN "administrative" + +/** + * Error Info Codes (Error Info PDU) + */ + +/* Protocol-independent codes */ +#define ERRINFO_RPC_INITIATED_DISCONNECT 0x00000001 +#define ERRINFO_RPC_INITIATED_LOGOFF 0x00000002 +#define ERRINFO_IDLE_TIMEOUT 0x00000003 +#define ERRINFO_LOGON_TIMEOUT 0x00000004 +#define ERRINFO_DISCONNECTED_BY_OTHER_CONNECTION 0x00000005 +#define ERRINFO_OUT_OF_MEMORY 0x00000006 +#define ERRINFO_SERVER_DENIED_CONNECTION 0x00000007 +#define ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES 0x00000009 +#define ERRINFO_SERVER_FRESH_CREDENTIALS_REQUIRED 0x0000000A +#define ERRINFO_RPC_INITIATED_DISCONNECT_BY_USER 0x0000000B +#define ERRINFO_LOGOFF_BY_USER 0x0000000C +#define ERRINFO_CLOSE_STACK_ON_DRIVER_NOT_READY 0x0000000F +#define ERRINFO_SERVER_DWM_CRASH 0x00000010 +#define ERRINFO_CLOSE_STACK_ON_DRIVER_FAILURE 0x00000011 +#define ERRINFO_CLOSE_STACK_ON_DRIVER_IFACE_FAILURE 0x00000012 +#define ERRINFO_SERVER_WINLOGON_CRASH 0x00000017 +#define ERRINFO_SERVER_CSRSS_CRASH 0x00000018 + +/* Protocol-independent licensing codes */ +#define ERRINFO_LICENSE_INTERNAL 0x00000100 +#define ERRINFO_LICENSE_NO_LICENSE_SERVER 0x00000101 +#define ERRINFO_LICENSE_NO_LICENSE 0x00000102 +#define ERRINFO_LICENSE_BAD_CLIENT_MSG 0x00000103 +#define ERRINFO_LICENSE_HWID_DOESNT_MATCH_LICENSE 0x00000104 +#define ERRINFO_LICENSE_BAD_CLIENT_LICENSE 0x00000105 +#define ERRINFO_LICENSE_CANT_FINISH_PROTOCOL 0x00000106 +#define ERRINFO_LICENSE_CLIENT_ENDED_PROTOCOL 0x00000107 +#define ERRINFO_LICENSE_BAD_CLIENT_ENCRYPTION 0x00000108 +#define ERRINFO_LICENSE_CANT_UPGRADE_LICENSE 0x00000109 +#define ERRINFO_LICENSE_NO_REMOTE_CONNECTIONS 0x0000010A + +/* Protocol-independent codes generated by the Connection Broker */ +#define ERRINFO_CB_DESTINATION_NOT_FOUND 0x0000400 +#define ERRINFO_CB_LOADING_DESTINATION 0x0000402 +#define ERRINFO_CB_REDIRECTING_TO_DESTINATION 0x0000404 +#define ERRINFO_CB_SESSION_ONLINE_VM_WAKE 0x0000405 +#define ERRINFO_CB_SESSION_ONLINE_VM_BOOT 0x0000406 +#define ERRINFO_CB_SESSION_ONLINE_VM_NO_DNS 0x0000407 +#define ERRINFO_CB_DESTINATION_POOL_NOT_FREE 0x0000408 +#define ERRINFO_CB_CONNECTION_CANCELLED 0x0000409 +#define ERRINFO_CB_CONNECTION_ERROR_INVALID_SETTINGS 0x0000410 +#define ERRINFO_CB_SESSION_ONLINE_VM_BOOT_TIMEOUT 0x0000411 +#define ERRINFO_CB_SESSION_ONLINE_VM_SESSMON_FAILED 0x0000412 + +/* RDP specific codes */ +#define ERRINFO_UNKNOWN_DATA_PDU_TYPE 0x000010C9 +#define ERRINFO_UNKNOWN_PDU_TYPE 0x000010CA +#define ERRINFO_DATA_PDU_SEQUENCE 0x000010CB +#define ERRINFO_CONTROL_PDU_SEQUENCE 0x000010CD +#define ERRINFO_INVALID_CONTROL_PDU_ACTION 0x000010CE +#define ERRINFO_INVALID_INPUT_PDU_TYPE 0x000010CF +#define ERRINFO_INVALID_INPUT_PDU_MOUSE 0x000010D0 +#define ERRINFO_INVALID_REFRESH_RECT_PDU 0x000010D1 +#define ERRINFO_CREATE_USER_DATA_FAILED 0x000010D2 +#define ERRINFO_CONNECT_FAILED 0x000010D3 +#define ERRINFO_CONFIRM_ACTIVE_HAS_WRONG_SHAREID 0x000010D4 +#define ERRINFO_CONFIRM_ACTIVE_HAS_WRONG_ORIGINATOR 0x000010D5 +#define ERRINFO_PERSISTENT_KEY_PDU_BAD_LENGTH 0x000010DA +#define ERRINFO_PERSISTENT_KEY_PDU_ILLEGAL_FIRST 0x000010DB +#define ERRINFO_PERSISTENT_KEY_PDU_TOO_MANY_TOTAL_KEYS 0x000010DC +#define ERRINFO_PERSISTENT_KEY_PDU_TOO_MANY_CACHE_KEYS 0x000010DD +#define ERRINFO_INPUT_PDU_BAD_LENGTH 0x000010DE +#define ERRINFO_BITMAP_CACHE_ERROR_PDU_BAD_LENGTH 0x000010DF +#define ERRINFO_SECURITY_DATA_TOO_SHORT 0x000010E0 +#define ERRINFO_VCHANNEL_DATA_TOO_SHORT 0x000010E1 +#define ERRINFO_SHARE_DATA_TOO_SHORT 0x000010E2 +#define ERRINFO_BAD_SUPPRESS_OUTPUT_PDU 0x000010E3 +#define ERRINFO_CONFIRM_ACTIVE_PDU_TOO_SHORT 0x000010E5 +#define ERRINFO_CAPABILITY_SET_TOO_SMALL 0x000010E7 +#define ERRINFO_CAPABILITY_SET_TOO_LARGE 0x000010E8 +#define ERRINFO_NO_CURSOR_CACHE 0x000010E9 +#define ERRINFO_BAD_CAPABILITIES 0x000010EA +#define ERRINFO_VIRTUAL_CHANNEL_DECOMPRESSION 0x000010EC +#define ERRINFO_INVALID_VC_COMPRESSION_TYPE 0x000010ED +#define ERRINFO_INVALID_CHANNEL_ID 0x000010EF +#define ERRINFO_VCHANNELS_TOO_MANY 0x000010F0 +#define ERRINFO_REMOTEAPP_NOT_ENABLED 0x000010F3 +#define ERRINFO_CACHE_CAP_NOT_SET 0x000010F4 +#define ERRINFO_BITMAP_CACHE_ERROR_PDU_BAD_LENGTH2 0x000010F5 +#define ERRINFO_OFFSCREEN_CACHE_ERROR_PDU_BAD_LENGTH 0x000010F6 +#define ERRINFO_DRAWNINEGRID_CACHE_ERROR_PDU_BAD_LENGTH 0x000010F7 +#define ERRINFO_GDIPLUS_PDU_BAD_LENGTH 0x000010F8 +#define ERRINFO_SECURITY_DATA_TOO_SHORT2 0x00001111 +#define ERRINFO_SECURITY_DATA_TOO_SHORT3 0x00001112 +#define ERRINFO_SECURITY_DATA_TOO_SHORT4 0x00001113 +#define ERRINFO_SECURITY_DATA_TOO_SHORT5 0x00001114 +#define ERRINFO_SECURITY_DATA_TOO_SHORT6 0x00001115 +#define ERRINFO_SECURITY_DATA_TOO_SHORT7 0x00001116 +#define ERRINFO_SECURITY_DATA_TOO_SHORT8 0x00001117 +#define ERRINFO_SECURITY_DATA_TOO_SHORT9 0x00001118 +#define ERRINFO_SECURITY_DATA_TOO_SHORT10 0x00001119 +#define ERRINFO_SECURITY_DATA_TOO_SHORT11 0x0000111A +#define ERRINFO_SECURITY_DATA_TOO_SHORT12 0x0000111B +#define ERRINFO_SECURITY_DATA_TOO_SHORT13 0x0000111C +#define ERRINFO_SECURITY_DATA_TOO_SHORT14 0x0000111D +#define ERRINFO_SECURITY_DATA_TOO_SHORT15 0x0000111E +#define ERRINFO_SECURITY_DATA_TOO_SHORT16 0x0000111F +#define ERRINFO_SECURITY_DATA_TOO_SHORT17 0x00001120 +#define ERRINFO_SECURITY_DATA_TOO_SHORT18 0x00001121 +#define ERRINFO_SECURITY_DATA_TOO_SHORT19 0x00001122 +#define ERRINFO_SECURITY_DATA_TOO_SHORT20 0x00001123 +#define ERRINFO_SECURITY_DATA_TOO_SHORT21 0x00001124 +#define ERRINFO_SECURITY_DATA_TOO_SHORT22 0x00001125 +#define ERRINFO_SECURITY_DATA_TOO_SHORT23 0x00001126 +#define ERRINFO_BAD_MONITOR_DATA 0x00001129 +#define ERRINFO_VC_DECOMPRESSED_REASSEMBLE_FAILED 0x0000112A +#define ERRINFO_VC_DATA_TOO_LONG 0x0000112B +#define ERRINFO_BAD_FRAME_ACK_DATA 0x0000112C +#define ERRINFO_GRAPHICS_MODE_NOT_SUPPORTED 0x0000112D +#define ERRINFO_GRAPHICS_SUBSYSTEM_RESET_FAILED 0x0000112E +#define ERRINFO_GRAPHICS_SUBSYSTEM_FAILED 0x0000112F +#define ERRINFO_TIMEZONE_KEY_NAME_LENGTH_TOO_SHORT 0x00001130 +#define ERRINFO_TIMEZONE_KEY_NAME_LENGTH_TOO_LONG 0x00001131 +#define ERRINFO_DYNAMIC_DST_DISABLED_FIELD_MISSING 0x00001132 +#define ERRINFO_VC_DECODING_ERROR 0x00001133 +#define ERRINFO_VIRTUALDESKTOPTOOLARGE 0x00001134 +#define ERRINFO_MONITORGEOMETRYVALIDATIONFAILED 0x00001135 +#define ERRINFO_INVALIDMONITORCOUNT 0x00001136 +#define ERRINFO_UPDATE_SESSION_KEY_FAILED 0x00001191 +#define ERRINFO_DECRYPT_FAILED 0x00001192 +#define ERRINFO_ENCRYPT_FAILED 0x00001193 +#define ERRINFO_ENCRYPTION_PACKAGE_MISMATCH 0x00001194 +#define ERRINFO_DECRYPT_FAILED2 0x00001195 +#define ERRINFO_PEER_DISCONNECTED 0x00001196 + +#define ERRINFO_SUCCESS 0x00000000 +#define ERRINFO_NONE 0xFFFFFFFF + + FREERDP_API const char* freerdp_get_error_info_string(UINT32 code); + FREERDP_API const char* freerdp_get_error_info_name(UINT32 code); + FREERDP_API const char* freerdp_get_error_info_category(UINT32 code); + + /** + * FreeRDP Context Error Codes + */ + +#define MAKE_FREERDP_ERROR(_class, _type) (((FREERDP_ERROR_##_class##_CLASS) << 16) | (_type)) + +#define GET_FREERDP_ERROR_CLASS(_errorCode) ((_errorCode >> 16) & 0xFFFF) + +#define GET_FREERDP_ERROR_TYPE(_errorCode) (_errorCode & 0xFFFF) + +#define GET_FREERDP_ERROR_SUBCODE + +#define FREERDP_ERROR_BASE 0 + +/** + * Error Base Codes + */ +#define FREERDP_ERROR_ERRBASE_CLASS (FREERDP_ERROR_BASE + 0) + +#define ERRBASE_SUCCESS ERRINFO_SUCCESS +#define ERRBASE_NONE ERRINFO_NONE + + FREERDP_API const char* freerdp_get_error_base_string(UINT32 code); + FREERDP_API const char* freerdp_get_error_base_name(UINT32 code); + FREERDP_API const char* freerdp_get_error_base_category(UINT32 code); + +#define FREERDP_ERROR_SUCCESS ERRINFO_SUCCESS +#define FREERDP_ERROR_NONE ERRINFO_NONE + + /* Error Info Codes */ + +#define FREERDP_ERROR_ERRINFO_CLASS (FREERDP_ERROR_BASE + 1) + +#define FREERDP_ERROR_RPC_INITIATED_DISCONNECT \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_RPC_INITIATED_DISCONNECT) +#define FREERDP_ERROR_RPC_INITIATED_LOGOFF MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_RPC_INITIATED_LOGOFF) +#define FREERDP_ERROR_IDLE_TIMEOUT MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_IDLE_TIMEOUT) +#define FREERDP_ERROR_LOGON_TIMEOUT MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_LOGON_TIMEOUT) +#define FREERDP_ERROR_DISCONNECTED_BY_OTHER_CONNECTION \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_DISCONNECTED_BY_OTHER_CONNECTION) +#define FREERDP_ERROR_OUT_OF_MEMORY MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_OUT_OF_MEMORY) +#define FREERDP_ERROR_SERVER_DENIED_CONNECTION \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_SERVER_DENIED_CONNECTION) +#define FREERDP_ERROR_SERVER_INSUFFICIENT_PRIVILEGES \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES) +#define FREERDP_ERROR_SERVER_FRESH_CREDENTIALS_REQUIRED \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_SERVER_FRESH_CREDENTIALS_REQUIRED) +#define FREERDP_ERROR_RPC_INITIATED_DISCONNECT_BY_USER \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_RPC_INITIATED_DISCONNECT_BY_USER) +#define FREERDP_ERROR_LOGOFF_BY_USER MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_LOGOFF_BY_USER) + +#define FREERDP_ERROR_CLOSE_STACK_ON_DRIVER_NOT_READY \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_CLOSE_STACK_ON_DRIVER_NOT_READY) +#define FREERDP_ERROR_SERVER_DWM_CRASH MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_SERVER_DWM_CRASH) +#define FREERDP_ERROR_CLOSE_STACK_ON_DRIVER_FAILURE \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_CLOSE_STACK_ON_DRIVER_FAILURE) +#define FREERDP_ERROR_CLOSE_STACK_ON_DRIVER_IFACE_FAILURE \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_CLOSE_STACK_ON_DRIVER_IFACE_FAILURE) +#define FREERDP_ERROR_SERVER_WINLOGON_CRASH \ + MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_SERVER_WINLOGON_CRASH) +#define FREERDP_ERROR_SERVER_CSRSS_CRASH MAKE_FREERDP_ERROR(ERRINFO, ERRINFO_SERVER_CSRSS_CRASH) + +/* Connection Error Codes */ +#define ERRCONNECT_PRE_CONNECT_FAILED 0x00000001 +#define ERRCONNECT_CONNECT_UNDEFINED 0x00000002 +#define ERRCONNECT_POST_CONNECT_FAILED 0x00000003 +#define ERRCONNECT_DNS_ERROR 0x00000004 +#define ERRCONNECT_DNS_NAME_NOT_FOUND 0x00000005 +#define ERRCONNECT_CONNECT_FAILED 0x00000006 +#define ERRCONNECT_MCS_CONNECT_INITIAL_ERROR 0x00000007 +#define ERRCONNECT_TLS_CONNECT_FAILED 0x00000008 +#define ERRCONNECT_AUTHENTICATION_FAILED 0x00000009 +#define ERRCONNECT_INSUFFICIENT_PRIVILEGES 0x0000000A +#define ERRCONNECT_CONNECT_CANCELLED 0x0000000B +#define ERRCONNECT_SECURITY_NEGO_CONNECT_FAILED 0x0000000C +#define ERRCONNECT_CONNECT_TRANSPORT_FAILED 0x0000000D +#define ERRCONNECT_PASSWORD_EXPIRED 0x0000000E +/* For non-domain workstation where we can't contact a kerberos server */ +#define ERRCONNECT_PASSWORD_CERTAINLY_EXPIRED 0x0000000F +#define ERRCONNECT_CLIENT_REVOKED 0x00000010 +#define ERRCONNECT_KDC_UNREACHABLE 0x00000011 + +#define ERRCONNECT_ACCOUNT_DISABLED 0x00000012 +#define ERRCONNECT_PASSWORD_MUST_CHANGE 0x00000013 +#define ERRCONNECT_LOGON_FAILURE 0x00000014 +#define ERRCONNECT_WRONG_PASSWORD 0x00000015 +#define ERRCONNECT_ACCESS_DENIED 0x00000016 +#define ERRCONNECT_ACCOUNT_RESTRICTION 0x00000017 +#define ERRCONNECT_ACCOUNT_LOCKED_OUT 0x00000018 +#define ERRCONNECT_ACCOUNT_EXPIRED 0x00000019 +#define ERRCONNECT_LOGON_TYPE_NOT_GRANTED 0x0000001A +#define ERRCONNECT_NO_OR_MISSING_CREDENTIALS 0x0000001B +#define ERRCONNECT_ACTIVATION_TIMEOUT 0x0000001C + +#define ERRCONNECT_SUCCESS ERRINFO_SUCCESS +#define ERRCONNECT_NONE ERRINFO_NONE + + FREERDP_API const char* freerdp_get_error_connect_string(UINT32 code); + FREERDP_API const char* freerdp_get_error_connect_name(UINT32 code); + FREERDP_API const char* freerdp_get_error_connect_category(UINT32 code); + +#define FREERDP_ERROR_CONNECT_CLASS (FREERDP_ERROR_BASE + 2) + +#define FREERDP_ERROR_PRE_CONNECT_FAILED MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_PRE_CONNECT_FAILED) + +#define FREERDP_ERROR_CONNECT_UNDEFINED MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_CONNECT_UNDEFINED) + +#define FREERDP_ERROR_POST_CONNECT_FAILED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_POST_CONNECT_FAILED) + +#define FREERDP_ERROR_DNS_ERROR MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_DNS_ERROR) + +#define FREERDP_ERROR_DNS_NAME_NOT_FOUND MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_DNS_NAME_NOT_FOUND) + +#define FREERDP_ERROR_CONNECT_FAILED MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_CONNECT_FAILED) + +#define FREERDP_ERROR_MCS_CONNECT_INITIAL_ERROR \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_MCS_CONNECT_INITIAL_ERROR) + +#define FREERDP_ERROR_TLS_CONNECT_FAILED MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_TLS_CONNECT_FAILED) + +#define FREERDP_ERROR_AUTHENTICATION_FAILED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_AUTHENTICATION_FAILED) + +#define FREERDP_ERROR_INSUFFICIENT_PRIVILEGES \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_INSUFFICIENT_PRIVILEGES) + +#define FREERDP_ERROR_CONNECT_CANCELLED MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_CONNECT_CANCELLED) + +#define FREERDP_ERROR_SECURITY_NEGO_CONNECT_FAILED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_SECURITY_NEGO_CONNECT_FAILED) + +#define FREERDP_ERROR_CONNECT_TRANSPORT_FAILED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_CONNECT_TRANSPORT_FAILED) + +#define FREERDP_ERROR_CONNECT_PASSWORD_EXPIRED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_PASSWORD_EXPIRED) + +#define FREERDP_ERROR_CONNECT_PASSWORD_MUST_CHANGE \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_PASSWORD_MUST_CHANGE) + +#define FREERDP_ERROR_CONNECT_KDC_UNREACHABLE \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_KDC_UNREACHABLE) + +#define FREERDP_ERROR_CONNECT_ACCOUNT_DISABLED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_ACCOUNT_DISABLED) + +#define FREERDP_ERROR_CONNECT_PASSWORD_CERTAINLY_EXPIRED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_PASSWORD_CERTAINLY_EXPIRED) + +#define FREERDP_ERROR_CONNECT_CLIENT_REVOKED MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_CLIENT_REVOKED) + +#define FREERDP_ERROR_CONNECT_LOGON_FAILURE MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_LOGON_FAILURE) + +#define FREERDP_ERROR_CONNECT_WRONG_PASSWORD MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_WRONG_PASSWORD) + +#define FREERDP_ERROR_CONNECT_ACCESS_DENIED MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_ACCESS_DENIED) + +#define FREERDP_ERROR_CONNECT_ACCOUNT_RESTRICTION \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_ACCOUNT_RESTRICTION) + +#define FREERDP_ERROR_CONNECT_ACCOUNT_LOCKED_OUT \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_ACCOUNT_LOCKED_OUT) + +#define FREERDP_ERROR_CONNECT_ACCOUNT_EXPIRED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_ACCOUNT_EXPIRED) + +#define FREERDP_ERROR_CONNECT_LOGON_TYPE_NOT_GRANTED \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_LOGON_TYPE_NOT_GRANTED) + +#define FREERDP_ERROR_CONNECT_NO_OR_MISSING_CREDENTIALS \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_NO_OR_MISSING_CREDENTIALS) + +#define FREERDP_ERROR_CONNECT_ACTIVATION_TIMEOUT \ + MAKE_FREERDP_ERROR(CONNECT, ERRCONNECT_ACTIVATION_TIMEOUT) + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_ERROR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/event.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/event.h new file mode 100644 index 0000000000000000000000000000000000000000..41662d6fadc682d2df313123b6f0eb273f92b2eb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/event.h @@ -0,0 +1,133 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Event Definitions + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_EVENT_H +#define FREERDP_EVENT_H + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define FREERDP_WINDOW_STATE_NORMAL 0 +#define FREERDP_WINDOW_STATE_MINIMIZED 1 +#define FREERDP_WINDOW_STATE_MAXIMIZED 2 +#define FREERDP_WINDOW_STATE_FULLSCREEN 3 +#define FREERDP_WINDOW_STATE_ACTIVE 4 + + DEFINE_EVENT_BEGIN(WindowStateChange) + int state; + DEFINE_EVENT_END(WindowStateChange) + + DEFINE_EVENT_BEGIN(ResizeWindow) + int width; + int height; + DEFINE_EVENT_END(ResizeWindow) + + DEFINE_EVENT_BEGIN(PanningChange) + int dx; + int dy; + DEFINE_EVENT_END(PanningChange) + + DEFINE_EVENT_BEGIN(ZoomingChange) + int dx; + int dy; + DEFINE_EVENT_END(ZoomingChange) + + DEFINE_EVENT_BEGIN(LocalResizeWindow) + int width; + int height; + DEFINE_EVENT_END(LocalResizeWindow) + + DEFINE_EVENT_BEGIN(EmbedWindow) + BOOL embed; + void* handle; + DEFINE_EVENT_END(EmbedWindow) + + DEFINE_EVENT_BEGIN(ErrorInfo) + UINT32 code; + DEFINE_EVENT_END(ErrorInfo) + + DEFINE_EVENT_BEGIN(Activated) + BOOL firstActivation; + DEFINE_EVENT_END(Activated) + + DEFINE_EVENT_BEGIN(ConnectionStateChange) + int state; + BOOL active; + DEFINE_EVENT_END(ConnectionStateChange) + + DEFINE_EVENT_BEGIN(Terminate) + int code; + DEFINE_EVENT_END(Terminate) + + DEFINE_EVENT_BEGIN(ConnectionResult) + int result; + DEFINE_EVENT_END(ConnectionResult) + + DEFINE_EVENT_BEGIN(ChannelConnected) + const char* name; + void* pInterface; + DEFINE_EVENT_END(ChannelConnected) + + DEFINE_EVENT_BEGIN(ChannelDisconnected) + const char* name; + void* pInterface; + DEFINE_EVENT_END(ChannelDisconnected) + + DEFINE_EVENT_BEGIN(ChannelAttached) + const char* name; + void* pInterface; + DEFINE_EVENT_END(ChannelAttached) + + DEFINE_EVENT_BEGIN(ChannelDetached) + const char* name; + void* pInterface; + DEFINE_EVENT_END(ChannelDetached) + + DEFINE_EVENT_BEGIN(MouseEvent) + UINT16 flags; + UINT16 x; + UINT16 y; + DEFINE_EVENT_END(MouseEvent) + + DEFINE_EVENT_BEGIN(MouseEventEx) + UINT16 flags; + UINT16 x; + UINT16 y; + DEFINE_EVENT_END(MouseEventEx) + + DEFINE_EVENT_BEGIN(Timer) + UINT64 now; + DEFINE_EVENT_END(Timer) + + DEFINE_EVENT_BEGIN(GraphicsReset) + UINT32 width; + UINT32 height; + DEFINE_EVENT_END(GraphicsReset) + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_EVENT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/extension.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/extension.h new file mode 100644 index 0000000000000000000000000000000000000000..1f9d4cb5124ab7b06811c1f1d232d4b293396616 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/extension.h @@ -0,0 +1,66 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Extensions + * + * Copyright 2010-2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_EXTENSION_H +#define FREERDP_EXTENSION_H + +#include +#include + +#define FREERDP_EXT_EXPORT_FUNC_NAME "FreeRDPExtensionEntry" + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_ext_plugin rdpExtPlugin; + + struct rdp_ext_plugin + { + void* ext; + int (*init)(rdpExtPlugin* plugin, freerdp* instance); + int (*uninit)(rdpExtPlugin* plugin, freerdp* instance); + }; + + typedef UINT32(FREERDP_CC* PFREERDP_EXTENSION_HOOK)(rdpExtPlugin* plugin, freerdp* instance); + + typedef UINT32(FREERDP_CC* PREGISTEREXTENSION)(rdpExtPlugin* plugin); + typedef UINT32(FREERDP_CC* PREGISTERPRECONNECTHOOK)(rdpExtPlugin* plugin, + PFREERDP_EXTENSION_HOOK hook); + typedef UINT32(FREERDP_CC* PREGISTERPOSTCONNECTHOOK)(rdpExtPlugin* plugin, + PFREERDP_EXTENSION_HOOK hook); + + typedef struct + { + void* ext; /* Reference to internal instance */ + PREGISTEREXTENSION pRegisterExtension; + PREGISTERPRECONNECTHOOK pRegisterPreConnectHook; + PREGISTERPOSTCONNECTHOOK pRegisterPostConnectHook; + void* data; + } FREERDP_EXTENSION_ENTRY_POINTS; + typedef FREERDP_EXTENSION_ENTRY_POINTS* PFREERDP_EXTENSION_ENTRY_POINTS; + + typedef int(FREERDP_CC* PFREERDP_EXTENSION_ENTRY)(PFREERDP_EXTENSION_ENTRY_POINTS pEntryPoints); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_EXTENSION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/freerdp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/freerdp.h new file mode 100644 index 0000000000000000000000000000000000000000..2d29d4ea6b69add0c9e20961ea7334c494574130 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/freerdp.h @@ -0,0 +1,757 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Interface + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_H +#define FREERDP_H + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_rdp rdpRdp; + typedef struct rdp_rail rdpRail; + typedef struct rdp_cache rdpCache; + + typedef struct rdp_client_context rdpClientContext; + typedef struct rdp_client_entry_points_v1 RDP_CLIENT_ENTRY_POINTS_V1; + typedef RDP_CLIENT_ENTRY_POINTS_V1 RDP_CLIENT_ENTRY_POINTS; + +#include +#include +#include +#include + +#define MCS_BASE_CHANNEL_ID 1001 +#define MCS_GLOBAL_CHANNEL_ID 1003 + +/* Flags used by certificate callbacks */ +#define VERIFY_CERT_FLAG_NONE 0x00 +#define VERIFY_CERT_FLAG_LEGACY 0x02 +#define VERIFY_CERT_FLAG_REDIRECT 0x10 +#define VERIFY_CERT_FLAG_GATEWAY 0x20 +#define VERIFY_CERT_FLAG_CHANGED 0x40 +#define VERIFY_CERT_FLAG_MISMATCH 0x80 +#define VERIFY_CERT_FLAG_MATCH_LEGACY_SHA1 0x100 +#define VERIFY_CERT_FLAG_FP_IS_PEM 0x200 + +/* Message types used by gateway messaging callback */ +#define GATEWAY_MESSAGE_CONSENT 1 +#define GATEWAY_MESSAGE_SERVICE 2 + + typedef enum + { + AUTH_NLA, + AUTH_TLS, + AUTH_RDP, + GW_AUTH_HTTP, + GW_AUTH_RDG, + GW_AUTH_RPC, + AUTH_SMARTCARD_PIN + } rdp_auth_reason; + + typedef BOOL (*pContextNew)(freerdp* instance, rdpContext* context); + typedef void (*pContextFree)(freerdp* instance, rdpContext* context); + + typedef BOOL (*pConnectCallback)(freerdp* instance); + typedef void (*pPostDisconnect)(freerdp* instance); + + /** \brief Authentication callback function pointer definition + * + * \param instance A pointer to the instance to work on + * \param username A pointer to the username string. On input the current username, on output + * the username that should be used. Must not be NULL. \param password A pointer to the password + * string. On input the current password, on output the password that sohould be used. Must not + * be NULL. \param domain A pointer to the domain string. On input the current domain, on output + * the domain that sohould be used. Must not be NULL. + * + * \return \b FALSE no valid credentials supplied, continue without \b TRUE valid credentials + * should be available. + */ + + typedef BOOL (*pAuthenticate)(freerdp* instance, char** username, char** password, + char** domain); + + /** \brief Extended authentication callback function pointer definition + * + * \param instance A pointer to the instance to work on + * \param username A pointer to the username string. On input the current username, on output + * the username that should be used. Must not be NULL. \param password A pointer to the password + * string. On input the current password, on output the password that sohould be used. Must not + * be NULL. \param domain A pointer to the domain string. On input the current domain, on output + * the domain that sohould be used. Must not be NULL. \param reason The reason the callback was + * called. (e.g. NLA, TLS, RDP, GATEWAY, ...) + * + * \return \b FALSE to abort the connection, \b TRUE otherwise. + * \note To not provide valid credentials and not abort the connection return \b TRUE and empty + * (as in empty string) credentials + */ + typedef BOOL (*pAuthenticateEx)(freerdp* instance, char** username, char** password, + char** domain, rdp_auth_reason reason); + typedef BOOL (*pChooseSmartcard)(freerdp* instance, SmartcardCertInfo** cert_list, DWORD count, + DWORD* choice, BOOL gateway); + + typedef enum + { + ACCESS_TOKEN_TYPE_AAD, /**!< oauth2 access token for RDS AAD authentication */ + ACCESS_TOKEN_TYPE_AVD /**!< oauth2 access token for Azure Virtual Desktop */ + } AccessTokenType; + + typedef BOOL (*pGetAccessToken)(freerdp* instance, AccessTokenType tokenType, char** token, + size_t count, ...); + + /** @brief Callback used to inform about a reconnection attempt + * + * @param instance The instance the information is for + * @param what A '\0' terminated string describing the module attempting to retry an operation + * @param current The current reconnection attempt, the first attempt will always have the + * value \b 0 + * @param userarg An optional custom argument + * + * @return \b -1 in case of failure (attempts exceeded, ...) or a \b delay in [ms] to wait + * before the next attempt + */ + typedef SSIZE_T (*pRetryDialog)(freerdp* instance, const char* what, size_t current, + void* userarg); + + /** @brief Callback used if user interaction is required to accept + * an unknown certificate. + * + * @deprecated Use pVerifyCertificateEx + * @param common_name The certificate registered hostname. + * @param subject The common name of the certificate. + * @param issuer The issuer of the certificate. + * @param fingerprint The fingerprint of the certificate (old) or the certificate in PEM + * format + * @param host_mismatch A flag indicating the certificate + * subject does not match the host connecting to. + * + * @return 1 to accept and store a certificate, 2 to accept + * a certificate only for this session, 0 otherwise. + */ +#if defined(WITH_FREERDP_DEPRECATED) + typedef WINPR_DEPRECATED_VAR( + "Use pVerifyCertificateEx", + DWORD (*pVerifyCertificate)(freerdp* instance, const char* common_name, const char* subject, + const char* issuer, const char* fingerprint, + BOOL host_mismatch)); +#endif + + /** @brief Callback used if user interaction is required to accept + * an unknown certificate. + * + * @param host The hostname connecting to. + * @param port The port connecting to. + * @param common_name The certificate registered hostname. + * @param subject The common name of the certificate. + * @param issuer The issuer of the certificate. + * @param fingerprint The fingerprint of the certificate (old) or the certificate in PEM + * format (VERIFY_CERT_FLAG_FP_IS_PEM set) + * @param flags Flags of type VERIFY_CERT_FLAG* + * + * @return 1 to accept and store a certificate, 2 to accept + * a certificate only for this session, 0 otherwise. + */ + typedef DWORD (*pVerifyCertificateEx)(freerdp* instance, const char* host, UINT16 port, + const char* common_name, const char* subject, + const char* issuer, const char* fingerprint, DWORD flags); + + /** @brief Callback used if user interaction is required to accept + * a changed certificate. + * + * @deprecated Use pVerifyChangedCertificateEx + * @param common_name The certificate registered hostname. + * @param subject The common name of the new certificate. + * @param issuer The issuer of the new certificate. + * @param new_fingerprint The fingerprint of the new certificate. + * @param old_subject The common name of the old certificate. + * @param old_issuer The issuer of the new certificate. + * @param old_fingerprint The fingerprint of the old certificate. + * + * @return 1 to accept and store a certificate, 2 to accept + * a certificate only for this session, 0 otherwise. + */ +#if defined(WITH_FREERDP_DEPRECATED) + typedef WINPR_DEPRECATED_VAR( + "Use pVerifyChangedCertificateEx", + DWORD (*pVerifyChangedCertificate)(freerdp* instance, const char* common_name, + const char* subject, const char* issuer, + const char* new_fingerprint, const char* old_subject, + const char* old_issuer, const char* old_fingerprint)); +#endif + + /** @brief Callback used if user interaction is required to accept + * a changed certificate. + * + * @param host The hostname connecting to. + * @param port The port connecting to. + * @param common_name The certificate registered hostname. + * @param subject The common name of the new certificate. + * @param issuer The issuer of the new certificate. + * @param new_fingerprint The fingerprint of the new certificate (old) or the certificate in + * PEM format (VERIFY_CERT_FLAG_FP_IS_PEM set) + * @param old_subject The common name of the old certificate. + * @param old_issuer The issuer of the new certificate. + * @param old_fingerprint The fingerprint of the old certificate (old) or the certificate in + * PEM format (VERIFY_CERT_FLAG_FP_IS_PEM set) + * @param flags Flags of type VERIFY_CERT_FLAG* + * + * @return 1 to accept and store a certificate, 2 to accept + * a certificate only for this session, 0 otherwise. + */ + + typedef DWORD (*pVerifyChangedCertificateEx)(freerdp* instance, const char* host, UINT16 port, + const char* common_name, const char* subject, + const char* issuer, const char* new_fingerprint, + const char* old_subject, const char* old_issuer, + const char* old_fingerprint, DWORD flags); + + /** @brief Callback used if user interaction is required to accept + * a certificate. + * + * @param instance Pointer to the freerdp instance. + * @param data Pointer to certificate data (full chain) in PEM format. + * @param length The length of the certificate data. + * @param hostname The hostname connecting to. + * @param port The port connecting to. + * @param flags Flags of type VERIFY_CERT_FLAG* + * + * @return 1 to accept and store a certificate, 2 to accept + * a certificate only for this session, 0 otherwise. + */ + typedef int (*pVerifyX509Certificate)(freerdp* instance, const BYTE* data, size_t length, + const char* hostname, UINT16 port, DWORD flags); + + typedef int (*pLogonErrorInfo)(freerdp* instance, UINT32 data, UINT32 type); + + typedef BOOL (*pSendChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data, + size_t size); + typedef BOOL (*pSendChannelPacket)(freerdp* instance, UINT16 channelId, size_t totalSize, + UINT32 flags, const BYTE* data, size_t chunkSize); + typedef BOOL (*pReceiveChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data, + size_t size, UINT32 flags, size_t totalSize); + + /* type can be one of the GATEWAY_MESSAGE_ type defines */ + typedef BOOL (*pPresentGatewayMessage)(freerdp* instance, UINT32 type, BOOL isDisplayMandatory, + BOOL isConsentMandatory, size_t length, + const WCHAR* message); + + /** + * Defines the context for a given instance of RDP connection. + * It is embedded in the rdp_freerdp structure, and allocated by a call to + * freerdp_context_new(). It is deallocated by a call to freerdp_context_free(). + */ + struct rdp_context + { + ALIGN64 freerdp* instance; /**< (offset 0) + Pointer to a rdp_freerdp structure. + This is a back-link to retrieve the freerdp instance from the context. + It is set by the freerdp_context_new() function */ + ALIGN64 freerdp_peer* peer; /**< (offset 1) + Pointer to the client peer. + This is set by a call to freerdp_peer_context_new() during peer + initialization. This field is used only on the server side. */ + ALIGN64 BOOL ServerMode; /**< (offset 2) true when context is in server mode */ + + ALIGN64 UINT32 LastError; /* 3 */ + + UINT64 paddingA[16 - 4]; /* 4 */ + + ALIGN64 int argc; /**< (offset 16) + Number of arguments given to the program at launch time. + Used to keep this data available and used later on, typically just before + connection initialization. + @see freerdp_parse_args() */ + ALIGN64 char** argv; /**< (offset 17) + List of arguments given to the program at launch time. + Used to keep this data available and used later on, typically just before + connection initialization. + @see freerdp_parse_args() */ + + ALIGN64 wPubSub* pubSub; /* (offset 18) */ + + ALIGN64 HANDLE channelErrorEvent; /* (offset 19)*/ + ALIGN64 UINT channelErrorNum; /*(offset 20)*/ + ALIGN64 char* errorDescription; /*(offset 21)*/ + + UINT64 paddingB[32 - 22]; /* 22 */ + + ALIGN64 rdpRdp* + rdp; /**< (offset 32) + Pointer to a rdp_rdp structure used to keep the connection's parameters. + It is allocated by freerdp_context_new() and deallocated by + freerdp_context_free(), at the same time that this rdp_context + structure - there is no need to specifically allocate/deallocate this. */ + ALIGN64 rdpGdi* gdi; /**< (offset 33) + Pointer to a rdp_gdi structure used to keep the gdi settings. + It is allocated by gdi_init() and deallocated by gdi_free(). + It must be deallocated before deallocating this rdp_context structure. */ + ALIGN64 rdpRail* rail; /* 34 */ + ALIGN64 rdpCache* cache; /* 35 */ + ALIGN64 rdpChannels* channels; /* 36 */ + ALIGN64 rdpGraphics* graphics; /* 37 */ + ALIGN64 rdpInput* input; /* 38 owned by rdpRdp */ + ALIGN64 rdpUpdate* update; /* 39 owned by rdpRdp */ + ALIGN64 rdpSettings* settings; /* 40 owned by rdpRdp */ + ALIGN64 rdpMetrics* metrics; /* 41 */ + ALIGN64 rdpCodecs* codecs; /* 42 */ + ALIGN64 rdpAutoDetect* autodetect; /* 43 owned by rdpRdp */ + UINT64 paddingC1[45 - 44]; /* 44 */ + ALIGN64 int disconnectUltimatum; /* 45 */ + UINT64 paddingC[64 - 46]; /* 46 */ + + ALIGN64 rdpStreamDumpContext* dump; /* 64 */ + ALIGN64 wLog* log; /* 65 */ + + UINT64 paddingD[96 - 66]; /* 66 */ + UINT64 paddingE[128 - 96]; /* 96 */ + }; + + /** + * Defines the possible disconnect reasons in the MCS Disconnect Provider + * Ultimatum PDU + */ + + enum Disconnect_Ultimatum + { + Disconnect_Ultimatum_domain_disconnected = 0, + Disconnect_Ultimatum_provider_initiated = 1, + Disconnect_Ultimatum_token_purged = 2, + Disconnect_Ultimatum_user_requested = 3, + Disconnect_Ultimatum_channel_purged = 4 + }; + +#include + + /** Defines the options for a given instance of RDP connection. + * This is built by the client and given to the FreeRDP library to create the connection + * with the expected options. + * It is allocated by a call to freerdp_new() and deallocated by a call to freerdp_free(). + * Some of its content need specific allocation/deallocation - see field description for + * details. + */ + struct rdp_freerdp + { + ALIGN64 + rdpContext* context; /**< (offset 0) + Pointer to a rdpContext structure. + Client applications can use the ContextSize field to register a + context bigger than the rdpContext structure. This allow clients to + use additional context information. When using this capability, client + application should ALWAYS declare their structure with the rdpContext + field first, and any additional content following it. Can be allocated + by a call to freerdp_context_new(). Must be deallocated by a call to + freerdp_context_free() before deallocating the current instance. */ + + ALIGN64 RDP_CLIENT_ENTRY_POINTS* pClientEntryPoints; + + UINT64 paddingA[16 - 2]; /* 2 */ + +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("use rdpContext::input instead", ALIGN64 rdpInput* input;) /* (offset + 16) Input handle for the connection. Will be initialized by a call + to freerdp_context_new() owned by rdpRdp */ + WINPR_DEPRECATED_VAR("use rdpContext::update instead", + ALIGN64 rdpUpdate* update;) /* (offset 17) + Update display parameters. Used to register display events callbacks +and settings. Will be initialized by a call to freerdp_context_new() owned by rdpRdp */ + WINPR_DEPRECATED_VAR("use rdpContext::settings instead", + ALIGN64 rdpSettings* settings;) /**< (offset 18) + Pointer to a rdpSettings structure. Will be used to maintain the + required RDP settings. Will be + initialized by a call to freerdp_context_new() + owned by rdpRdp + */ + WINPR_DEPRECATED_VAR("use rdpContext::autodetect instead", + ALIGN64 rdpAutoDetect* autodetect;) /* (offset 19) + Auto-Detect handle for the connection. + Will be initialized by a call to freerdp_context_new() +owned by rdpRdp */ +#else + UINT64 paddingX[4]; +#endif + ALIGN64 rdpHeartbeat* heartbeat; /* (offset 21) owned by rdpRdp*/ + + UINT64 paddingB[32 - 21]; /* 21 */ + + ALIGN64 size_t + ContextSize; /* (offset 32) + Specifies the size of the 'context' field. freerdp_context_new() will use this + size to allocate the context buffer. freerdp_new() sets it to + sizeof(rdpContext). If modifying it, there should always be a minimum of + sizeof(rdpContext), as the freerdp library will assume it can use the 'context' + field to set the required information in it. Clients will typically make it + bigger, and use a context structure embedding the rdpContext, and adding + additional information after that. + */ + + ALIGN64 pContextNew + ContextNew; /**< (offset 33) + Callback for context allocation + Can be set before calling freerdp_context_new() to have it executed after + allocation and initialization. Must be set to NULL if not needed. */ + + ALIGN64 pContextFree + ContextFree; /**< (offset 34) + Callback for context deallocation + Can be set before calling freerdp_context_free() to have it executed before + deallocation. Must be set to NULL if not needed. */ + UINT64 paddingC[47 - 35]; /* 35 */ + + ALIGN64 UINT ConnectionCallbackState; /* 47 */ + + ALIGN64 pConnectCallback + PreConnect; /**< (offset 48) + Callback for pre-connect operations. + Can be set before calling freerdp_connect() to have it executed before the + actual connection happens. Must be set to NULL if not needed. */ + + ALIGN64 pConnectCallback + PostConnect; /**< (offset 49) + Callback for post-connect operations. + Can be set before calling freerdp_connect() to have it executed after the + actual connection has succeeded. Must be set to NULL if not needed. */ + + ALIGN64 pAuthenticate Authenticate; /**< (offset 50) + Callback for authentication. + It is used to get the username/password when it was not + provided at connection time. */ +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("Use VerifyCertificateEx or VerifyX509Certificate instead", + ALIGN64 pVerifyCertificate VerifyCertificate;) /**< (offset 51) */ + WINPR_DEPRECATED_VAR("Use VerifyChangedCertificateEx or VerifyX509Certificate instead", + ALIGN64 pVerifyChangedCertificate + VerifyChangedCertificate;) /**< (offset 52) */ +#else + ALIGN64 UINT64 reserved[2]; +#endif + ALIGN64 pVerifyX509Certificate + VerifyX509Certificate; /**< (offset 53) Callback for X509 certificate verification + (PEM format) */ + + ALIGN64 pLogonErrorInfo + LogonErrorInfo; /**< (offset 54) Callback for logon error info, important for logon + system messages with RemoteApp */ + + ALIGN64 pPostDisconnect + PostDisconnect; /**< (offset 55) + Callback for cleaning up + resources allocated by post connect callback. + + This will be called before disconnecting and cleaning up the + channels. + */ + + ALIGN64 pAuthenticate GatewayAuthenticate; /**< (offset 56) + Callback for gateway authentication. + It is used to get the username/password when it was not + provided at connection time. */ + + ALIGN64 pPresentGatewayMessage PresentGatewayMessage; /**< (offset 57) + Callback for gateway consent messages. + It is used to present consent messages to the user. */ + + ALIGN64 pConnectCallback Redirect; /**< (offset 58) + Callback for redirect operations. + Can be set after + rdp_client_disconnect_and_clear and applying redirection settings but before + rdp_client_connect() to have it executed after the actual connection has + succeeded. Must be set to NULL if not needed. */ + ALIGN64 pConnectCallback + LoadChannels; /**< (offset 59) + * callback for loading channel configuration. Might be called multiple + * times when redirection occurs. */ + + ALIGN64 pPostDisconnect + PostFinalDisconnect; /** < (offset 60) + * callback for cleaning up resources allocated in PreConnect + * + * This will be called after all instance related channels and + * threads have been stopped + */ + UINT64 paddingD[64 - 61]; /* 61 */ + + ALIGN64 pSendChannelData + SendChannelData; /* (offset 64) + Callback for sending data to a channel. + By default, it is set by freerdp_new() to freerdp_send_channel_data(), which + eventually calls freerdp_channel_send() */ + ALIGN64 pReceiveChannelData + ReceiveChannelData; /* (offset 65) + Callback for receiving data from a channel. + This is called by freerdp_channel_process() (if not NULL). + Clients will typically use a function that calls freerdp_channels_data() + to perform the needed tasks. */ + + ALIGN64 pVerifyCertificateEx + VerifyCertificateEx; /**< (offset 66) + Callback for certificate validation. + Used to verify that an unknown certificate is trusted. */ + ALIGN64 pVerifyChangedCertificateEx + VerifyChangedCertificateEx; /**< (offset 67) + Callback for changed certificate validation. + Used when a certificate differs from stored fingerprint. */ + ALIGN64 pSendChannelPacket + SendChannelPacket; /* (offset 68) + * Callback for sending RAW data to a channel. In contrast to + * SendChannelData data fragmentation is up to the user and this + * function sends data as is with the provided flags. + */ + ALIGN64 pAuthenticateEx AuthenticateEx; /**< (offset 69) + Callback for authentication. + It is used to get the username/password. The reason + argument tells why it was called. */ + ALIGN64 pChooseSmartcard + ChooseSmartcard; /* (offset 70) + Callback for choosing a smartcard for logon. + Used when multiple smartcards are available. Returns an index into a list + of SmartcardCertInfo pointers */ + ALIGN64 pGetAccessToken GetAccessToken; /* (offset 71) + Callback for obtaining an access token + for \b AccessTokenType authentication */ + ALIGN64 pRetryDialog RetryDialog; /* (offset 72) Callback for displaying a dialog in case of + something needs a retry */ + UINT64 paddingE[80 - 73]; /* 73 */ + }; + + struct rdp_channel_handles + { + wListDictionary* init; + wListDictionary* open; + }; + typedef struct rdp_channel_handles rdpChannelHandles; + + FREERDP_API void freerdp_context_free(freerdp* instance); + + FREERDP_API BOOL freerdp_context_new(freerdp* instance); + FREERDP_API BOOL freerdp_context_new_ex(freerdp* instance, rdpSettings* settings); + + FREERDP_API BOOL freerdp_context_reset(freerdp* instance); + + FREERDP_API BOOL freerdp_connect(freerdp* instance); + + WINPR_DEPRECATED_VAR("use freerdp_abort_connect_context instead", + FREERDP_API BOOL freerdp_abort_connect(freerdp* instance)); + + FREERDP_API BOOL freerdp_abort_connect_context(rdpContext* context); + FREERDP_API HANDLE freerdp_abort_event(rdpContext* context); + + WINPR_DEPRECATED_VAR("use freerdp_shall_disconnect_context instead", + FREERDP_API BOOL freerdp_shall_disconnect(freerdp* instance)); + + FREERDP_API BOOL freerdp_shall_disconnect_context(const rdpContext* context); + FREERDP_API BOOL freerdp_disconnect(freerdp* instance); + + WINPR_DEPRECATED_VAR("use freerdp_disconnect_before_reconnect_context instead", + FREERDP_API BOOL freerdp_disconnect_before_reconnect(freerdp* instance)); + FREERDP_API BOOL freerdp_disconnect_before_reconnect_context(rdpContext* context); + + FREERDP_API BOOL freerdp_reconnect(freerdp* instance); + + FREERDP_API UINT freerdp_channels_attach(freerdp* instance); + FREERDP_API UINT freerdp_channels_detach(freerdp* instance); + +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_get_event_handles", + BOOL freerdp_get_fds(freerdp* instance, void** rfds, + int* rcount, void** wfds, int* wcount)); +#endif + + FREERDP_API BOOL freerdp_check_fds(freerdp* instance); + + FREERDP_API DWORD freerdp_get_event_handles(rdpContext* context, HANDLE* events, DWORD count); + FREERDP_API BOOL freerdp_check_event_handles(rdpContext* context); + + FREERDP_API wMessageQueue* freerdp_get_message_queue(freerdp* instance, DWORD id); + FREERDP_API HANDLE freerdp_get_message_queue_event_handle(freerdp* instance, DWORD id); + FREERDP_API int freerdp_message_queue_process_message(freerdp* instance, DWORD id, + wMessage* message); + FREERDP_API int freerdp_message_queue_process_pending_messages(freerdp* instance, DWORD id); + + FREERDP_API UINT32 freerdp_error_info(freerdp* instance); + FREERDP_API void freerdp_set_error_info(rdpRdp* rdp, UINT32 error); + FREERDP_API BOOL freerdp_send_error_info(rdpRdp* rdp); + FREERDP_API BOOL freerdp_get_stats(rdpRdp* rdp, UINT64* inBytes, UINT64* outBytes, + UINT64* inPackets, UINT64* outPackets); + + FREERDP_API void freerdp_get_version(int* major, int* minor, int* revision); + FREERDP_API const char* freerdp_get_version_string(void); + FREERDP_API const char* freerdp_get_build_revision(void); + FREERDP_API const char* freerdp_get_build_config(void); + + FREERDP_API void freerdp_free(freerdp* instance); + + WINPR_ATTR_MALLOC(freerdp_free, 1) + FREERDP_API freerdp* freerdp_new(void); + + FREERDP_API BOOL freerdp_focus_required(freerdp* instance); + FREERDP_API void freerdp_set_focus(freerdp* instance); + + FREERDP_API int freerdp_get_disconnect_ultimatum(rdpContext* context); + + FREERDP_API UINT32 freerdp_get_last_error(rdpContext* context); + FREERDP_API const char* freerdp_get_last_error_name(UINT32 error); + FREERDP_API const char* freerdp_get_last_error_string(UINT32 error); + FREERDP_API const char* freerdp_get_last_error_category(UINT32 error); + +#define freerdp_set_last_error(context, lastError) \ + freerdp_set_last_error_ex((context), (lastError), __func__, __FILE__, __LINE__) + +#define freerdp_set_last_error_if_not(context, lastError) \ + do \ + { \ + if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS) \ + freerdp_set_last_error_log(context, lastError); \ + } while (0) + +#define freerdp_set_last_error_log(context, lastError) \ + freerdp_set_last_error_ex((context), (lastError), __func__, __FILE__, __LINE__) + FREERDP_API void freerdp_set_last_error_ex(rdpContext* context, UINT32 lastError, + const char* fkt, const char* file, int line); + + FREERDP_API const char* freerdp_get_logon_error_info_type(UINT32 type); + FREERDP_API const char* freerdp_get_logon_error_info_type_ex(UINT32 type, char* buffer, + size_t size); + + FREERDP_API const char* freerdp_get_logon_error_info_data(UINT32 data); + FREERDP_API const char* freerdp_get_logon_error_info_data_ex(UINT32 data, char* buffer, + size_t size); + + FREERDP_API ULONG freerdp_get_transport_sent(rdpContext* context, BOOL resetCount); + + FREERDP_API BOOL freerdp_nla_impersonate(rdpContext* context); + FREERDP_API BOOL freerdp_nla_revert_to_self(rdpContext* context); + + FREERDP_API UINT32 freerdp_get_nla_sspi_error(rdpContext* context); + + /** Encrypts the provided buffer using the NLA's GSSAPI context + * + * \param context the RDP context + * \param inBuffer the SecBuffer buffer to encrypt + * \param outBuffer a SecBuffer to hold the encrypted content + * \returns if the operation completed successfully + * \since version 3.9.0 + */ + FREERDP_API BOOL freerdp_nla_encrypt(rdpContext* context, const SecBuffer* inBuffer, + SecBuffer* outBuffer); + + /** Decrypts the provided buffer using the NLA's GSSAPI context + * + * \param context the RDP context + * \param inBuffer the SecBuffer buffer to decrypt + * \param outBuffer a SecBuffer to hold the decrypted content + * \returns if the operation completed successfully + * \since version 3.9.0 + */ + FREERDP_API BOOL freerdp_nla_decrypt(rdpContext* context, const SecBuffer* inBuffer, + SecBuffer* outBuffer); + + /** Calls QueryContextAttributes on the SSPI context associated with the NLA part of + * the RDP context + * + * \param context the RDP context + * \param ulAttr the attribute + * \param pBuffer an opaque pointer depending on ulAttr + * \returns a SECURITY_STATUS indicating if the operation completed successfully + * \since version 3.9.0 + */ + FREERDP_API SECURITY_STATUS freerdp_nla_QueryContextAttributes(rdpContext* context, + DWORD ulAttr, PVOID pBuffer); + + FREERDP_API void clearChannelError(rdpContext* context); + FREERDP_API HANDLE getChannelErrorEventHandle(rdpContext* context); + FREERDP_API UINT getChannelError(rdpContext* context); + FREERDP_API const char* getChannelErrorDescription(rdpContext* context); + FREERDP_API void setChannelError(rdpContext* context, UINT errorNum, const char* format, ...); + FREERDP_API BOOL checkChannelErrorEvent(rdpContext* context); + + FREERDP_API const char* freerdp_nego_get_routing_token(rdpContext* context, DWORD* length); + + /** \brief returns the current \b CONNECTION_STATE of the context. + * + * \param context A pointer to the context to query state + * + * \return A \b CONNECTION_STATE the context is currently in + */ + FREERDP_API CONNECTION_STATE freerdp_get_state(const rdpContext* context); + + /** \brief returns a string representation of a \b CONNECTION_STATE + * + * \param state the \b CONNECTION_STATE to stringify + * + * \return The string representation of the \b CONNECTION_STATE + */ + FREERDP_API const char* freerdp_state_string(CONNECTION_STATE state); + + /** \brief Queries if the current \b CONNECTION_STATE of the context is an active connection. + * + * A connection is active, if the connection sequence has been passed, no disconnection requests + * have been received and no network or other errors have forced a disconnect. + * + * \param context A pointer to the context to query state + * + * \return \b TRUE if the connection state indicates an active connection, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_is_active_state(const rdpContext* context); + + FREERDP_API BOOL freerdp_channels_from_mcs(rdpSettings* settings, const rdpContext* context); + + FREERDP_API BOOL freerdp_is_valid_mcs_create_request(const BYTE* data, size_t size); + FREERDP_API BOOL freerdp_is_valid_mcs_create_response(const BYTE* data, size_t size); + + /** \brief Persist the current credentials (gateway, target server, ...) + * + * FreeRDP internally keeps a backup of connection settings to revert to whenever a reconnect + * is required. If a client modifies settings during runtime after pre-connect call this + * function or the credentials will be lost on any reconnect, redirect, ... + * + * \param context The RDP context to use, must not be \b NULL + * + * \return \b TRUE if successful, \b FALSE if settings could not be applied (wrong session + * state, ...) + * \since version 3.12.0 + */ + FREERDP_API BOOL freerdp_persist_credentials(rdpContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/bitmap.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/bitmap.h new file mode 100644 index 0000000000000000000000000000000000000000..5f784f0ce69831e3202062a71e2e92d064b97f6f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/bitmap.h @@ -0,0 +1,54 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Bitmap Functions + * + * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_BITMAP_H +#define FREERDP_GDI_BITMAP_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos); + FREERDP_API UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y, UINT32 crColor); + FREERDP_API BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y); + + FREERDP_API HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight, UINT32 format, + BYTE* data); + FREERDP_API HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format, + UINT32 stride, BYTE* data, void (*fkt_free)(void*)); + FREERDP_API HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth, UINT32 nHeight); + + FREERDP_API BOOL gdi_BitBlt(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest, INT32 nWidth, + INT32 nHeight, HGDI_DC hdcSrc, INT32 nXSrc, INT32 nYSrc, DWORD rop, + const gdiPalette* palette); + + typedef BOOL (*p_BitBlt)(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest, INT32 nWidth, + INT32 nHeight, HGDI_DC hdcSrc, INT32 nXSrc, INT32 nYSrc, DWORD rop); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_BITMAP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/dc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/dc.h new file mode 100644 index 0000000000000000000000000000000000000000..d9b5c2bc2fcacc60601f98330d26d727a1825ada --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/dc.h @@ -0,0 +1,44 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Device Context Functions + * + * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_DC_H +#define FREERDP_GDI_DC_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API HGDI_DC gdi_GetDC(void); + FREERDP_API HGDI_DC gdi_CreateDC(UINT32 format); + FREERDP_API HGDI_DC gdi_CreateCompatibleDC(HGDI_DC hdc); + FREERDP_API HGDIOBJECT gdi_SelectObject(HGDI_DC hdc, HGDIOBJECT hgdiobject); + FREERDP_API BOOL gdi_DeleteObject(HGDIOBJECT hgdiobject); + FREERDP_API BOOL gdi_DeleteDC(HGDI_DC hdc); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_DC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/gdi.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/gdi.h new file mode 100644 index 0000000000000000000000000000000000000000..ab6f172e00e50d1d4778ab96ececf3ebe608b53d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/gdi.h @@ -0,0 +1,548 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Library + * + * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_H +#define FREERDP_GDI_H + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +/* For more information, see [MS-RDPEGDI] */ + +/* Binary Raster Operations (ROP2) */ +#define GDI_R2_BLACK 0x01 /* D = 0 */ +#define GDI_R2_NOTMERGEPEN 0x02 /* D = ~(D | P) */ +#define GDI_R2_MASKNOTPEN 0x03 /* D = D & ~P */ +#define GDI_R2_NOTCOPYPEN 0x04 /* D = ~P */ +#define GDI_R2_MASKPENNOT 0x05 /* D = P & ~D */ +#define GDI_R2_NOT 0x06 /* D = ~D */ +#define GDI_R2_XORPEN 0x07 /* D = D ^ P */ +#define GDI_R2_NOTMASKPEN 0x08 /* D = ~(D & P) */ +#define GDI_R2_MASKPEN 0x09 /* D = D & P */ +#define GDI_R2_NOTXORPEN 0x0A /* D = ~(D ^ P) */ +#define GDI_R2_NOP 0x0B /* D = D */ +#define GDI_R2_MERGENOTPEN 0x0C /* D = D | ~P */ +#define GDI_R2_COPYPEN 0x0D /* D = P */ +#define GDI_R2_MERGEPENNOT 0x0E /* D = P | ~D */ +#define GDI_R2_MERGEPEN 0x0F /* D = P | D */ +#define GDI_R2_WHITE 0x10 /* D = 1 */ + +/* Ternary Raster Operations (ROP3) */ +#define GDI_BLACKNESS 0x00000042 +#define GDI_DPSoon 0x00010289 +#define GDI_DPSona 0x00020C89 +#define GDI_PSon 0x000300AA +#define GDI_SDPona 0x00040C88 +#define GDI_DPon 0x000500A9 +#define GDI_PDSxnon 0x00060865 +#define GDI_PDSaon 0x000702C5 +#define GDI_SDPnaa 0x00080F08 +#define GDI_PDSxon 0x00090245 +#define GDI_DPna 0x000A0329 +#define GDI_PSDnaon 0x000B0B2A +#define GDI_SPna 0x000C0324 +#define GDI_PDSnaon 0x000D0B25 +#define GDI_PDSonon 0x000E08A5 +#define GDI_Pn 0x000F0001 +#define GDI_PDSona 0x00100C85 +#define GDI_NOTSRCERASE 0x001100A6 +#define GDI_SDPxnon 0x00120868 +#define GDI_SDPaon 0x001302C8 +#define GDI_DPSxnon 0x00140869 +#define GDI_DPSaon 0x001502C9 +#define GDI_PSDPSanaxx 0x00165CCA +#define GDI_SSPxDSxaxn 0x00171D54 +#define GDI_SPxPDxa 0x00180D59 +#define GDI_SDPSanaxn 0x00191CC8 +#define GDI_PDSPaox 0x001A06C5 +#define GDI_SDPSxaxn 0x001B0768 +#define GDI_PSDPaox 0x001C06CA +#define GDI_DSPDxaxn 0x001D0766 +#define GDI_PDSox 0x001E01A5 +#define GDI_PDSoan 0x001F0385 +#define GDI_DPSnaa 0x00200F09 +#define GDI_SDPxon 0x00210248 +#define GDI_DSna 0x00220326 +#define GDI_SPDnaon 0x00230B24 +#define GDI_SPxDSxa 0x00240D55 +#define GDI_PDSPanaxn 0x00251CC5 +#define GDI_SDPSaox 0x002606C8 +#define GDI_SDPSxnox 0x00271868 +#define GDI_DPSxa 0x00280369 +#define GDI_PSDPSaoxxn 0x002916CA +#define GDI_DPSana 0x002A0CC9 +#define GDI_SSPxPDxaxn 0x002B1D58 +#define GDI_SPDSoax 0x002C0784 +#define GDI_PSDnox 0x002D060A +#define GDI_PSDPxox 0x002E064A +#define GDI_PSDnoan 0x002F0E2A +#define GDI_PSna 0x0030032A +#define GDI_SDPnaon 0x00310B28 +#define GDI_SDPSoox 0x00320688 +#define GDI_NOTSRCCOPY 0x00330008 +#define GDI_SPDSaox 0x003406C4 +#define GDI_SPDSxnox 0x00351864 +#define GDI_SDPox 0x003601A8 +#define GDI_SDPoan 0x00370388 +#define GDI_PSDPoax 0x0038078A +#define GDI_SPDnox 0x00390604 +#define GDI_SPDSxox 0x003A0644 +#define GDI_SPDnoan 0x003B0E24 +#define GDI_PSx 0x003C004A +#define GDI_SPDSonox 0x003D18A4 +#define GDI_SPDSnaox 0x003E1B24 +#define GDI_PSan 0x003F00EA +#define GDI_PSDnaa 0x00400F0A +#define GDI_DPSxon 0x00410249 +#define GDI_SDxPDxa 0x00420D5D +#define GDI_SPDSanaxn 0x00431CC4 +#define GDI_SRCERASE 0x00440328 +#define GDI_DPSnaon 0x00450B29 +#define GDI_DSPDaox 0x004606C6 +#define GDI_PSDPxaxn 0x0047076A +#define GDI_SDPxa 0x00480368 +#define GDI_PDSPDaoxxn 0x004916C5 +#define GDI_DPSDoax 0x004A0789 +#define GDI_PDSnox 0x004B0605 +#define GDI_SDPana 0x004C0CC8 +#define GDI_SSPxDSxoxn 0x004D1954 +#define GDI_PDSPxox 0x004E0645 +#define GDI_PDSnoan 0x004F0E25 +#define GDI_PDna 0x00500325 +#define GDI_DSPnaon 0x00510B26 +#define GDI_DPSDaox 0x005206C9 +#define GDI_SPDSxaxn 0x00530764 +#define GDI_DPSonon 0x005408A9 +#define GDI_DSTINVERT 0x00550009 +#define GDI_DPSox 0x005601A9 +#define GDI_DPSoan 0x00570389 +#define GDI_PDSPoax 0x00580785 +#define GDI_DPSnox 0x00590609 +#define GDI_PATINVERT 0x005A0049 +#define GDI_DPSDonox 0x005B18A9 +#define GDI_DPSDxox 0x005C0649 +#define GDI_DPSnoan 0x005D0E29 +#define GDI_DPSDnaox 0x005E1B29 +#define GDI_DPan 0x005F00E9 +#define GDI_PDSxa 0x00600365 +#define GDI_DSPDSaoxxn 0x006116C6 +#define GDI_DSPDoax 0x00620786 +#define GDI_SDPnox 0x00630608 +#define GDI_SDPSoax 0x00640788 +#define GDI_DSPnox 0x00650606 +#define GDI_SRCINVERT 0x00660046 +#define GDI_SDPSonox 0x006718A8 +#define GDI_DSPDSonoxxn 0x006858A6 +#define GDI_PDSxxn 0x00690145 +#define GDI_DPSax 0x006A01E9 +#define GDI_PSDPSoaxxn 0x006B178A +#define GDI_SDPax 0x006C01E8 +#define GDI_PDSPDoaxxn 0x006D1785 +#define GDI_SDPSnoax 0x006E1E28 +#define GDI_PDSxnan 0x006F0C65 +#define GDI_PDSana 0x00700CC5 +#define GDI_SSDxPDxaxn 0x00711D5C +#define GDI_SDPSxox 0x00720648 +#define GDI_SDPnoan 0x00730E28 +#define GDI_DSPDxox 0x00740646 +#define GDI_DSPnoan 0x00750E26 +#define GDI_SDPSnaox 0x00761B28 +#define GDI_DSan 0x007700E6 +#define GDI_PDSax 0x007801E5 +#define GDI_DSPDSoaxxn 0x00791786 +#define GDI_DPSDnoax 0x007A1E29 +#define GDI_SDPxnan 0x007B0C68 +#define GDI_SPDSnoax 0x007C1E24 +#define GDI_DPSxnan 0x007D0C69 +#define GDI_SPxDSxo 0x007E0955 +#define GDI_DPSaan 0x007F03C9 +#define GDI_DPSaa 0x008003E9 +#define GDI_SPxDSxon 0x00810975 +#define GDI_DPSxna 0x00820C49 +#define GDI_SPDSnoaxn 0x00831E04 +#define GDI_SDPxna 0x00840C48 +#define GDI_PDSPnoaxn 0x00851E05 +#define GDI_DSPDSoaxx 0x008617A6 +#define GDI_PDSaxn 0x008701C5 +#define GDI_SRCAND 0x008800C6 +#define GDI_SDPSnaoxn 0x00891B08 +#define GDI_DSPnoa 0x008A0E06 +#define GDI_DSPDxoxn 0x008B0666 +#define GDI_SDPnoa 0x008C0E08 +#define GDI_SDPSxoxn 0x008D0668 +#define GDI_SSDxPDxax 0x008E1D7C +#define GDI_PDSanan 0x008F0CE5 +#define GDI_PDSxna 0x00900C45 +#define GDI_SDPSnoaxn 0x00911E08 +#define GDI_DPSDPoaxx 0x009217A9 +#define GDI_SPDaxn 0x009301C4 +#define GDI_PSDPSoaxx 0x009417AA +#define GDI_DPSaxn 0x009501C9 +#define GDI_DPSxx 0x00960169 +#define GDI_PSDPSonoxx 0x0097588A +#define GDI_SDPSonoxn 0x00981888 +#define GDI_DSxn 0x00990066 +#define GDI_DPSnax 0x009A0709 +#define GDI_SDPSoaxn 0x009B07A8 +#define GDI_SPDnax 0x009C0704 +#define GDI_DSPDoaxn 0x009D07A6 +#define GDI_DSPDSaoxx 0x009E16E6 +#define GDI_PDSxan 0x009F0345 +#define GDI_DPa 0x00A000C9 +#define GDI_PDSPnaoxn 0x00A11B05 +#define GDI_DPSnoa 0x00A20E09 +#define GDI_DPSDxoxn 0x00A30669 +#define GDI_PDSPonoxn 0x00A41885 +#define GDI_PDxn 0x00A50065 +#define GDI_DSPnax 0x00A60706 +#define GDI_PDSPoaxn 0x00A707A5 +#define GDI_DPSoa 0x00A803A9 +#define GDI_DPSoxn 0x00A90189 +#define GDI_DSTCOPY 0x00AA0029 +#define GDI_DPSono 0x00AB0889 +#define GDI_SPDSxax 0x00AC0744 +#define GDI_DPSDaoxn 0x00AD06E9 +#define GDI_DSPnao 0x00AE0B06 +#define GDI_DPno 0x00AF0229 +#define GDI_PDSnoa 0x00B00E05 +#define GDI_PDSPxoxn 0x00B10665 +#define GDI_SSPxDSxox 0x00B21974 +#define GDI_SDPanan 0x00B30CE8 +#define GDI_PSDnax 0x00B4070A +#define GDI_DPSDoaxn 0x00B507A9 +#define GDI_DPSDPaoxx 0x00B616E9 +#define GDI_SDPxan 0x00B70348 +#define GDI_PSDPxax 0x00B8074A +#define GDI_DSPDaoxn 0x00B906E6 +#define GDI_DPSnao 0x00BA0B09 +#define GDI_MERGEPAINT 0x00BB0226 +#define GDI_SPDSanax 0x00BC1CE4 +#define GDI_SDxPDxan 0x00BD0D7D +#define GDI_DPSxo 0x00BE0269 +#define GDI_DPSano 0x00BF08C9 +#define GDI_MERGECOPY 0x00C000CA +#define GDI_SPDSnaoxn 0x00C11B04 +#define GDI_SPDSonoxn 0x00C21884 +#define GDI_PSxn 0x00C3006A +#define GDI_SPDnoa 0x00C40E04 +#define GDI_SPDSxoxn 0x00C50664 +#define GDI_SDPnax 0x00C60708 +#define GDI_PSDPoaxn 0x00C707AA +#define GDI_SDPoa 0x00C803A8 +#define GDI_SPDoxn 0x00C90184 +#define GDI_DPSDxax 0x00CA0749 +#define GDI_SPDSaoxn 0x00CB06E4 +#define GDI_SRCCOPY 0x00CC0020 +#define GDI_SDPono 0x00CD0888 +#define GDI_SDPnao 0x00CE0B08 +#define GDI_SPno 0x00CF0224 +#define GDI_PSDnoa 0x00D00E0A +#define GDI_PSDPxoxn 0x00D1066A +#define GDI_PDSnax 0x00D20705 +#define GDI_SPDSoaxn 0x00D307A4 +#define GDI_SSPxPDxax 0x00D41D78 +#define GDI_DPSanan 0x00D50CE9 +#define GDI_PSDPSaoxx 0x00D616EA +#define GDI_DPSxan 0x00D70349 +#define GDI_PDSPxax 0x00D80745 +#define GDI_SDPSaoxn 0x00D906E8 +#define GDI_DPSDanax 0x00DA1CE9 +#define GDI_SPxDSxan 0x00DB0D75 +#define GDI_SPDnao 0x00DC0B04 +#define GDI_SDno 0x00DD0228 +#define GDI_SDPxo 0x00DE0268 +#define GDI_SDPano 0x00DF08C8 +#define GDI_PDSoa 0x00E003A5 +#define GDI_PDSoxn 0x00E10185 +#define GDI_DSPDxax 0x00E20746 +#define GDI_PSDPaoxn 0x00E306EA +#define GDI_SDPSxax 0x00E40748 +#define GDI_PDSPaoxn 0x00E506E5 +#define GDI_SDPSanax 0x00E61CE8 +#define GDI_SPxPDxan 0x00E70D79 +#define GDI_SSPxDSxax 0x00E81D74 +#define GDI_DSPDSanaxxn 0x00E95CE6 +#define GDI_DPSao 0x00EA02E9 +#define GDI_DPSxno 0x00EB0849 +#define GDI_SDPao 0x00EC02E8 +#define GDI_SDPxno 0x00ED0848 +#define GDI_SRCPAINT 0x00EE0086 +#define GDI_SDPnoo 0x00EF0A08 +#define GDI_PATCOPY 0x00F00021 +#define GDI_PDSono 0x00F10885 +#define GDI_PDSnao 0x00F20B05 +#define GDI_PSno 0x00F3022A +#define GDI_PSDnao 0x00F40B0A +#define GDI_PDno 0x00F50225 +#define GDI_PDSxo 0x00F60265 +#define GDI_PDSano 0x00F708C5 +#define GDI_PDSao 0x00F802E5 +#define GDI_PDSxno 0x00F90845 +#define GDI_DPo 0x00FA0089 +#define GDI_PATPAINT 0x00FB0A09 +#define GDI_PSo 0x00FC008A +#define GDI_PSDnoo 0x00FD0A0A +#define GDI_DPSoo 0x00FE02A9 +#define GDI_WHITENESS 0x00FF0062 +#define GDI_GLYPH_ORDER 0xFFFFFFFF + +/* Brush Styles */ +#define GDI_BS_SOLID 0x00 +#define GDI_BS_NULL 0x01 +#define GDI_BS_HATCHED 0x02 +#define GDI_BS_PATTERN 0x03 + +/* Hatch Patterns */ +#define GDI_HS_HORIZONTAL 0x00 +#define GDI_HS_VERTICAL 0x01 +#define GDI_HS_FDIAGONAL 0x02 +#define GDI_HS_BDIAGONAL 0x03 +#define GDI_HS_CROSS 0x04 +#define GDI_HS_DIAGCROSS 0x05 + +/* Pen Styles */ +#define GDI_PS_SOLID 0x00 +#define GDI_PS_DASH 0x01 +#define GDI_PS_NULL 0x05 + +/* Background Modes */ +#define GDI_OPAQUE 0x00000001 +#define GDI_TRANSPARENT 0x00000002 + +/* Fill Modes */ +#define GDI_FILL_ALTERNATE 0x01 +#define GDI_FILL_WINDING 0x02 + +/* GDI Object Types */ +#define GDIOBJECT_BITMAP 0x00 +#define GDIOBJECT_PEN 0x01 +#define GDIOBJECT_PALETTE 0x02 +#define GDIOBJECT_BRUSH 0x03 +#define GDIOBJECT_RECT 0x04 +#define GDIOBJECT_REGION 0x05 + +/* Region return values */ +#ifndef NULLREGION +#define NULLREGION 0x01 +#define SIMPLEREGION 0x02 +#define COMPLEXREGION 0x03 +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + BYTE objectType; + } GDIOBJECT; + typedef GDIOBJECT* HGDIOBJECT; + + typedef struct + { + BYTE objectType; + INT32 left; + INT32 top; + INT32 right; + INT32 bottom; + } GDI_RECT; + typedef GDI_RECT* HGDI_RECT; + + typedef struct + { + BYTE objectType; + INT32 x; /* left */ + INT32 y; /* top */ + INT32 w; /* width */ + INT32 h; /* height */ + BOOL null; /* null region */ + } GDI_RGN; + typedef GDI_RGN* HGDI_RGN; + + typedef struct + { + BYTE objectType; + UINT32 format; + INT32 width; + INT32 height; + UINT32 scanline; + BYTE* data; + void (*free)(void*); + } GDI_BITMAP; + typedef GDI_BITMAP* HGDI_BITMAP; + + typedef struct + { + BYTE objectType; + UINT32 style; + INT32 width; + INT32 posX; + INT32 posY; + UINT32 color; + UINT32 format; + const gdiPalette* palette; + } GDI_PEN; + typedef GDI_PEN* HGDI_PEN; + + typedef struct + { + BYTE red; + BYTE green; + BYTE blue; + } GDI_PALETTEENTRY; + + typedef struct + { + UINT16 count; + GDI_PALETTEENTRY* entries; + } GDI_PALETTE; + typedef GDI_PALETTE* HGDI_PALETTE; + + typedef struct + { + INT32 x; + INT32 y; + } GDI_POINT; + typedef GDI_POINT* HGDI_POINT; + + typedef struct + { + BYTE objectType; + int style; + HGDI_BITMAP pattern; + UINT32 color; + INT32 nXOrg; + INT32 nYOrg; + } GDI_BRUSH; + typedef GDI_BRUSH* HGDI_BRUSH; + + typedef struct + { + UINT32 count; + INT32 ninvalid; + HGDI_RGN invalid; + HGDI_RGN cinvalid; + } GDI_WND; + typedef GDI_WND* HGDI_WND; + + typedef struct + { + HGDIOBJECT selectedObject; + UINT32 format; + UINT32 bkColor; + UINT32 textColor; + HGDI_BRUSH brush; + HGDI_RGN clip; + HGDI_PEN pen; + HGDI_WND hwnd; + INT32 drawMode; + INT32 bkMode; + } GDI_DC; + typedef GDI_DC* HGDI_DC; + + struct gdi_bitmap + { + rdpBitmap _p; + + HGDI_DC hdc; + HGDI_BITMAP bitmap; + HGDI_BITMAP org_bitmap; + }; + typedef struct gdi_bitmap gdiBitmap; + + struct gdi_glyph + { + rdpBitmap _p; + + HGDI_DC hdc; + HGDI_BITMAP bitmap; + HGDI_BITMAP org_bitmap; + }; + typedef struct gdi_glyph gdiGlyph; + + struct rdp_gdi + { + rdpContext* context; + + INT32 width; + INT32 height; + UINT32 stride; + UINT32 dstFormat; + UINT32 cursor_x; + UINT32 cursor_y; + + HGDI_DC hdc; + gdiBitmap* primary; + gdiBitmap* drawing; + UINT32 bitmap_size; + UINT32 bitmap_stride; + BYTE* primary_buffer; + gdiPalette palette; + gdiBitmap* image; + void (*free)(void*); + + BOOL inGfxFrame; + BOOL graphicsReset; /* deprecated, remove with FreeRDP v3 */ + BOOL suppressOutput; + UINT16 outputSurfaceId; + UINT32 frameId; + RdpgfxClientContext* gfx; + VideoClientContext* video; + GeometryClientContext* geometry; + + wLog* log; + }; + typedef struct rdp_gdi rdpGdi; + + FREERDP_API DWORD gdi_rop3_code(BYTE code); + FREERDP_API const char* gdi_rop3_code_string(BYTE code); + FREERDP_API const char* gdi_rop3_string(DWORD rop); + + FREERDP_API UINT32 gdi_get_pixel_format(UINT32 bitsPerPixel); + FREERDP_API BOOL gdi_decode_color(rdpGdi* gdi, const UINT32 srcColor, UINT32* color, + UINT32* format); + FREERDP_API BOOL gdi_resize(rdpGdi* gdi, UINT32 width, UINT32 height); + FREERDP_API BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, UINT32 stride, + UINT32 format, BYTE* buffer, void (*pfree)(void*)); + FREERDP_API BOOL gdi_init(freerdp* instance, UINT32 format); + FREERDP_API BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer, + void (*pfree)(void*)); + FREERDP_API void gdi_free(freerdp* instance); + + FREERDP_API BOOL gdi_send_suppress_output(rdpGdi* gdi, BOOL suppress); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/gfx.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/gfx.h new file mode 100644 index 0000000000000000000000000000000000000000..4e731b381390fea26382c9abdee4eb5182107aa6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/gfx.h @@ -0,0 +1,77 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Graphics Pipeline + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_GFX_H +#define FREERDP_GDI_GFX_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct gdi_gfx_surface + { + UINT16 surfaceId; + rdpCodecs* codecs; + H264_CONTEXT* h264; + UINT32 width; + UINT32 height; + UINT32 mappedWidth; + UINT32 mappedHeight; + BYTE* data; + UINT32 scanline; + UINT32 format; + BOOL outputMapped; + UINT32 outputOriginX; + UINT32 outputOriginY; + REGION16 invalidRegion; + UINT64 windowId; + UINT32 outputTargetWidth; + UINT32 outputTargetHeight; + BOOL windowMapped; + BOOL handleInUpdateSurfaceArea; + }; + typedef struct gdi_gfx_surface gdiGfxSurface; + + struct gdi_gfx_cache_entry + { + UINT64 cacheKey; + UINT32 width; + UINT32 height; + BYTE* data; + UINT32 scanline; + UINT32 format; + }; + typedef struct gdi_gfx_cache_entry gdiGfxCacheEntry; + + FREERDP_API BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx); + FREERDP_API BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx, + pcRdpgfxMapWindowForSurface map, + pcRdpgfxUnmapWindowForSurface unmap, + pcRdpgfxUpdateSurfaceArea update); + FREERDP_API void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_GFX_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/pen.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/pen.h new file mode 100644 index 0000000000000000000000000000000000000000..880ef2536427672bd125cdf8074b3a39959e1032 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/pen.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Pen Functions + * + * Copyright 2010-2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_PEN_H +#define FREERDP_GDI_PEN_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API HGDI_PEN gdi_CreatePen(UINT32 fnPenStyle, UINT32 nWidth, UINT32 crColor, + UINT32 format, const gdiPalette* palette); + FREERDP_API UINT32 gdi_GetPenColor(HGDI_PEN pen, UINT32 format); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_PEN_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/region.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/region.h new file mode 100644 index 0000000000000000000000000000000000000000..d515b7bcaefd71a48348555f3009a3c84aceff19 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/region.h @@ -0,0 +1,64 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Region Functions + * + * Copyright 2010-2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_REGION_H +#define FREERDP_GDI_REGION_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API HGDI_RGN gdi_CreateRectRgn(INT32 nLeftRect, INT32 nTopRect, INT32 nRightRect, + INT32 nBottomRect); + FREERDP_API HGDI_RECT gdi_CreateRect(INT32 xLeft, INT32 yTop, INT32 xRight, INT32 yBottom); + FREERDP_API BOOL gdi_RectToRgn(const HGDI_RECT rect, HGDI_RGN rgn); + FREERDP_API BOOL gdi_CRectToRgn(INT32 left, INT32 top, INT32 right, INT32 bottom, HGDI_RGN rgn); + FREERDP_API BOOL gdi_RectToCRgn(const HGDI_RECT rect, INT32* x, INT32* y, INT32* w, INT32* h); + FREERDP_API BOOL gdi_CRectToCRgn(INT32 left, INT32 top, INT32 right, INT32 bottom, INT32* x, + INT32* y, INT32* w, INT32* h); + FREERDP_API BOOL gdi_RgnToRect(const HGDI_RGN rgn, HGDI_RECT rect); + FREERDP_API BOOL gdi_CRgnToRect(INT64 x, INT64 y, INT32 w, INT32 h, HGDI_RECT rect); + FREERDP_API BOOL gdi_RgnToCRect(const HGDI_RGN rgn, INT32* left, INT32* top, INT32* right, + INT32* bottom); + FREERDP_API BOOL gdi_CRgnToCRect(INT32 x, INT32 y, INT32 w, INT32 h, INT32* left, INT32* top, + INT32* right, INT32* bottom); + FREERDP_API BOOL gdi_CopyOverlap(INT32 x, INT32 y, INT32 width, INT32 height, INT32 srcx, + INT32 srcy); + FREERDP_API BOOL gdi_SetRect(HGDI_RECT rc, INT32 xLeft, INT32 yTop, INT32 xRight, + INT32 yBottom); + FREERDP_API BOOL gdi_SetRgn(HGDI_RGN hRgn, INT32 nXLeft, INT32 nYLeft, INT32 nWidth, + INT32 nHeight); + FREERDP_API BOOL gdi_SetRectRgn(HGDI_RGN hRgn, INT32 nLeftRect, INT32 nTopRect, + INT32 nRightRect, INT32 nBottomRect); + FREERDP_API BOOL gdi_EqualRgn(const HGDI_RGN hSrcRgn1, const HGDI_RGN hSrcRgn2); + FREERDP_API BOOL gdi_CopyRect(HGDI_RECT dst, const HGDI_RECT src); + FREERDP_API BOOL gdi_PtInRect(const HGDI_RECT rc, INT32 x, INT32 y); + FREERDP_API BOOL gdi_InvalidateRegion(HGDI_DC hdc, INT32 x, INT32 y, INT32 w, INT32 h); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_REGION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/shape.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/shape.h new file mode 100644 index 0000000000000000000000000000000000000000..d4a183e85ada46ad35593db0b93bdda104ce5c3e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/shape.h @@ -0,0 +1,44 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Shape Functions + * + * Copyright 2010-2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GDI_SHAPE_H +#define FREERDP_GDI_SHAPE_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API BOOL gdi_Ellipse(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, + int nBottomRect); + FREERDP_API BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr); + FREERDP_API BOOL gdi_Polygon(HGDI_DC hdc, GDI_POINT* lpPoints, int nCount); + FREERDP_API BOOL gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT* lpPoints, int* lpPolyCounts, + int nCount); + FREERDP_API BOOL gdi_Rectangle(HGDI_DC hdc, INT32 nXDst, INT32 nYDst, INT32 nWidth, + INT32 nHeight); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_SHAPE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/video.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/video.h new file mode 100644 index 0000000000000000000000000000000000000000..a9e50f81c7cde1bb0116dd6fef106d960d043e04 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/gdi/video.h @@ -0,0 +1,53 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Optimized Remoting Virtual Channel Extension for X11 + * + * Copyright 2017 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FREERDP_GDI_VIDEO_H_ +#define FREERDP_GDI_VIDEO_H_ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_gdiVideoContext gdiVideoContext; + + FREERDP_API void gdi_video_geometry_init(rdpGdi* gdi, GeometryClientContext* geom); + FREERDP_API void gdi_video_geometry_uninit(rdpGdi* gdi, GeometryClientContext* geom); + + FREERDP_API void gdi_video_control_init(rdpGdi* gdi, VideoClientContext* video); + FREERDP_API void gdi_video_control_uninit(rdpGdi* gdi, VideoClientContext* video); + + FREERDP_API void gdi_video_data_init(rdpGdi* gdi, VideoClientContext* video); + FREERDP_API void gdi_video_data_uninit(rdpGdi* gdi, VideoClientContext* context); + + FREERDP_API void gdi_video_free(gdiVideoContext* context); + + WINPR_ATTR_MALLOC(gdi_video_free, 1) + FREERDP_API gdiVideoContext* gdi_video_new(rdpGdi* gdi); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GDI_VIDEO_H_ */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/graphics.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/graphics.h new file mode 100644 index 0000000000000000000000000000000000000000..1b98635b28c7092e71c83816c65c256d59ca2e91 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/graphics.h @@ -0,0 +1,175 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphical Objects + * + * Copyright 2011 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_GRAPHICS_H +#define FREERDP_GRAPHICS_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_bitmap rdpBitmap; + typedef struct rdp_pointer rdpPointer; + typedef struct rdp_glyph rdpGlyph; + + /* Bitmap Class */ + typedef BOOL (*pBitmap_New)(rdpContext* context, rdpBitmap* bitmap); + typedef void (*pBitmap_Free)(rdpContext* context, rdpBitmap* bitmap); + typedef BOOL (*pBitmap_Paint)(rdpContext* context, rdpBitmap* bitmap); + typedef BOOL (*pBitmap_Decompress)(rdpContext* context, rdpBitmap* bitmap, const BYTE* data, + UINT32 width, UINT32 height, UINT32 bpp, UINT32 length, + BOOL compressed, UINT32 codec_id); + typedef BOOL (*pBitmap_SetSurface)(rdpContext* context, rdpBitmap* bitmap, BOOL primary); + + struct rdp_bitmap + { + size_t size; /* 0 */ + pBitmap_New New; /* 1 */ + pBitmap_Free Free; /* 2 */ + pBitmap_Paint Paint; /* 3 */ + pBitmap_Decompress Decompress; /* 4 */ + pBitmap_SetSurface SetSurface; /* 5 */ + UINT32 paddingA[16 - 6]; /* 6 */ + + UINT32 left; /* 16 */ + UINT32 top; /* 17 */ + UINT32 right; /* 18 */ + UINT32 bottom; /* 19 */ + UINT32 width; /* 20 */ + UINT32 height; /* 21 */ + UINT32 format; /* 22 */ + UINT32 flags; /* 23 */ + UINT32 length; /* 24 */ + BYTE* data; /* 25 */ + UINT64 key64; /* 26 */ + UINT32 paddingB[32 - 27]; /* 27 */ + + BOOL compressed; /* 32 */ + BOOL ephemeral; /* 33 */ + UINT32 paddingC[64 - 34]; /* 34 */ + }; + + FREERDP_API rdpBitmap* Bitmap_Alloc(rdpContext* context); + FREERDP_API BOOL Bitmap_SetRectangle(rdpBitmap* bitmap, UINT16 left, UINT16 top, UINT16 right, + UINT16 bottom); + FREERDP_API BOOL Bitmap_SetDimensions(rdpBitmap* bitmap, UINT16 width, UINT16 height); + + /* Pointer Class */ + + typedef BOOL (*pPointer_New)(rdpContext* context, rdpPointer* pointer); + typedef void (*pPointer_Free)(rdpContext* context, rdpPointer* pointer); + typedef BOOL (*pPointer_Set)(rdpContext* context, rdpPointer* pointer); + typedef BOOL (*pPointer_SetNull)(rdpContext* context); + typedef BOOL (*pPointer_SetDefault)(rdpContext* context); + typedef BOOL (*pPointer_SetPosition)(rdpContext* context, UINT32 x, UINT32 y); + + struct rdp_pointer + { + size_t size; /* 0 */ + pPointer_New New; /* 1 */ + pPointer_Free Free; /* 2 */ + pPointer_Set Set; /* 3 */ + pPointer_SetNull SetNull; /* 4*/ + pPointer_SetDefault SetDefault; /* 5 */ + pPointer_SetPosition SetPosition; /* 6 */ + UINT32 paddingA[16 - 7]; /* 7 */ + + UINT32 xPos; /* 16 */ + UINT32 yPos; /* 17 */ + UINT32 width; /* 18 */ + UINT32 height; /* 19 */ + UINT32 xorBpp; /* 20 */ + UINT32 lengthAndMask; /* 21 */ + UINT32 lengthXorMask; /* 22 */ + BYTE* xorMaskData; /* 23 */ + BYTE* andMaskData; /* 24 */ + UINT32 paddingB[32 - 25]; /* 25 */ + }; + + FREERDP_API rdpPointer* Pointer_Alloc(rdpContext* context); + + /* Glyph Class */ + typedef BOOL (*pGlyph_New)(rdpContext* context, rdpGlyph* glyph); + typedef void (*pGlyph_Free)(rdpContext* context, rdpGlyph* glyph); + typedef BOOL (*pGlyph_Draw)(rdpContext* context, const rdpGlyph* glyph, INT32 x, INT32 y, + INT32 w, INT32 h, INT32 sx, INT32 sy, BOOL fOpRedundant); + typedef BOOL (*pGlyph_BeginDraw)(rdpContext* context, INT32 x, INT32 y, INT32 width, + INT32 height, UINT32 bgcolor, UINT32 fgcolor, + BOOL fOpRedundant); + typedef BOOL (*pGlyph_EndDraw)(rdpContext* context, INT32 x, INT32 y, INT32 width, INT32 height, + UINT32 bgcolor, UINT32 fgcolor); + typedef BOOL (*pGlyph_SetBounds)(rdpContext* context, INT32 x, INT32 y, INT32 width, + INT32 height); + + struct rdp_glyph + { + size_t size; /* 0 */ + pGlyph_New New; /* 1 */ + pGlyph_Free Free; /* 2 */ + pGlyph_Draw Draw; /* 3 */ + pGlyph_BeginDraw BeginDraw; /* 4 */ + pGlyph_EndDraw EndDraw; /* 5 */ + pGlyph_SetBounds SetBounds; /* 6 */ + UINT32 paddingA[16 - 7]; /* 7 */ + + INT32 x; /* 16 */ + INT32 y; /* 17 */ + UINT32 cx; /* 18 */ + UINT32 cy; /* 19 */ + UINT32 cb; /* 20 */ + BYTE* aj; /* 21 */ + UINT32 paddingB[32 - 22]; /* 22 */ + }; + + FREERDP_API rdpGlyph* Glyph_Alloc(rdpContext* context, INT32 x, INT32 y, UINT32 cx, UINT32 cy, + UINT32 cb, const BYTE* aj); + + /* Graphics Module */ + + struct rdp_graphics + { + rdpContext* context; /* 0 */ + rdpBitmap* Bitmap_Prototype; /* 1 */ + rdpPointer* Pointer_Prototype; /* 2 */ + rdpGlyph* Glyph_Prototype; /* 3 */ + UINT32 paddingA[16 - 4]; /* 4 */ + }; + typedef struct rdp_graphics rdpGraphics; + + FREERDP_API void graphics_register_bitmap(rdpGraphics* graphics, const rdpBitmap* bitmap); + FREERDP_API void graphics_register_pointer(rdpGraphics* graphics, const rdpPointer* pointer); + FREERDP_API void graphics_register_glyph(rdpGraphics* graphics, const rdpGlyph* glyph); + + FREERDP_API void graphics_free(rdpGraphics* graphics); + + WINPR_ATTR_MALLOC(graphics_free, 1) + FREERDP_API rdpGraphics* graphics_new(rdpContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_GRAPHICS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/heartbeat.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/heartbeat.h new file mode 100644 index 0000000000000000000000000000000000000000..61512e667582978bdadfcd2f63376d883283867c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/heartbeat.h @@ -0,0 +1,47 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Heartbeat PDUs + * + * Copyright 2014 Dell Software + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_HEARTBEAT_H +#define FREERDP_HEARTBEAT_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_heartbeat rdpHeartbeat; + + typedef BOOL (*pServerHeartbeat)(freerdp* instance, BYTE period, BYTE count1, BYTE count2); + + struct rdp_heartbeat + { + pServerHeartbeat ServerHeartbeat; + }; + + FREERDP_API BOOL freerdp_heartbeat_send_heartbeat_pdu(freerdp_peer* peer, BYTE period, + BYTE count1, BYTE count2); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_HEARTBEAT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/input.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/input.h new file mode 100644 index 0000000000000000000000000000000000000000..512fceeade9f9b6b5b3d9d81fd43fd33329ec74b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/input.h @@ -0,0 +1,123 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Input Interface API + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_INPUT_H +#define FREERDP_INPUT_H + +#include +#include +#include + +#include +#include + +/* keyboard Flags */ +#define KBD_FLAGS_EXTENDED 0x0100 +#define KBD_FLAGS_EXTENDED1 0x0200 +#define KBD_FLAGS_DOWN \ + 0x4000 /**< Presence of this flag indicates the key was already down previously */ +#define KBD_FLAGS_RELEASE \ + 0x8000 /**< Presence of this flag indicates a key was released. Absence a key press */ + +/* Pointer Flags */ +#define PTR_FLAGS_HWHEEL 0x0400 +#define PTR_FLAGS_WHEEL 0x0200 +#define PTR_FLAGS_WHEEL_NEGATIVE 0x0100 +#define PTR_FLAGS_MOVE 0x0800 +#define PTR_FLAGS_DOWN 0x8000 +#define PTR_FLAGS_BUTTON1 0x1000 /* left */ +#define PTR_FLAGS_BUTTON2 0x2000 /* right */ +#define PTR_FLAGS_BUTTON3 0x4000 /* middle */ +#define WheelRotationMask 0x01FF + +/* Extended Pointer Flags */ +#define PTR_XFLAGS_DOWN 0x8000 +#define PTR_XFLAGS_BUTTON1 0x0001 +#define PTR_XFLAGS_BUTTON2 0x0002 + +/* Keyboard Toggle Flags */ +#define KBD_SYNC_SCROLL_LOCK 0x00000001 +#define KBD_SYNC_NUM_LOCK 0x00000002 +#define KBD_SYNC_CAPS_LOCK 0x00000004 +#define KBD_SYNC_KANA_LOCK 0x00000008 + +#define RDP_CLIENT_INPUT_PDU_HEADER_LENGTH 4 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_input rdpInput; + + /* defined inside libfreerdp-core */ + typedef struct rdp_input_proxy rdpInputProxy; + + /* Input Interface */ + + typedef BOOL (*pSynchronizeEvent)(rdpInput* input, UINT32 flags); + typedef BOOL (*pKeyboardEvent)(rdpInput* input, UINT16 flags, UINT8 code); + typedef BOOL (*pUnicodeKeyboardEvent)(rdpInput* input, UINT16 flags, UINT16 code); + typedef BOOL (*pMouseEvent)(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); + typedef BOOL (*pRelMouseEvent)(rdpInput* input, UINT16 flags, INT16 xDelta, INT16 yDelta); + typedef BOOL (*pQoEEvent)(rdpInput* input, UINT32 timestampMS); + typedef BOOL (*pExtendedMouseEvent)(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); + typedef BOOL (*pFocusInEvent)(rdpInput* input, UINT16 toggleStates); + typedef BOOL (*pKeyboardPauseEvent)(rdpInput* input); + + struct rdp_input + { + rdpContext* context; /* 0 */ + void* param1; /* 1 */ + UINT32 paddingA[16 - 2]; /* 2 */ + + pSynchronizeEvent SynchronizeEvent; /* 16 */ + pKeyboardEvent KeyboardEvent; /* 17 */ + pUnicodeKeyboardEvent UnicodeKeyboardEvent; /* 18 */ + pMouseEvent MouseEvent; /* 19 */ + pExtendedMouseEvent ExtendedMouseEvent; /* 20 */ + pFocusInEvent FocusInEvent; /*21 */ + pKeyboardPauseEvent KeyboardPauseEvent; /* 22 */ + pRelMouseEvent RelMouseEvent; /* 23 */ + pQoEEvent QoEEvent; /* 24 */ + + UINT32 paddingB[32 - 25]; /* 25 */ + }; + + FREERDP_API BOOL freerdp_input_send_synchronize_event(rdpInput* input, UINT32 flags); + FREERDP_API BOOL freerdp_input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT8 code); + FREERDP_API BOOL freerdp_input_send_keyboard_event_ex(rdpInput* input, BOOL down, BOOL repeat, + UINT32 rdp_scancode); + FREERDP_API BOOL freerdp_input_send_keyboard_pause_event(rdpInput* input); + FREERDP_API BOOL freerdp_input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, + UINT16 code); + FREERDP_API BOOL freerdp_input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, + UINT16 y); + FREERDP_API BOOL freerdp_input_send_rel_mouse_event(rdpInput* input, UINT16 flags, INT16 xDelta, + INT16 yDelta); + FREERDP_API BOOL freerdp_input_send_qoe_timestamp(rdpInput* input, UINT32 timestampMS); + FREERDP_API BOOL freerdp_input_send_extended_mouse_event(rdpInput* input, UINT16 flags, + UINT16 x, UINT16 y); + FREERDP_API BOOL freerdp_input_send_focus_in_event(rdpInput* input, UINT16 toggleStates); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_INPUT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/license.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/license.h new file mode 100644 index 0000000000000000000000000000000000000000..dc195a46b454e5c676ae079f1bb827bcaafaec80 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/license.h @@ -0,0 +1,62 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Licensing API + * + * Copyright 2018 David Fort + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LICENSE_H +#define FREERDP_LICENSE_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + LICENSE_STATE_INITIAL, + LICENSE_STATE_CONFIGURED, + LICENSE_STATE_REQUEST, + LICENSE_STATE_NEW_REQUEST, + LICENSE_STATE_PLATFORM_CHALLENGE, + LICENSE_STATE_PLATFORM_CHALLENGE_RESPONSE, + LICENSE_STATE_COMPLETED, + LICENSE_STATE_ABORTED + } LICENSE_STATE; + + typedef enum + { + LICENSE_TYPE_INVALID = 0, + LICENSE_TYPE_NONE, + LICENSE_TYPE_ISSUED + } LICENSE_TYPE; + + typedef struct rdp_license rdpLicense; + + FREERDP_API rdpLicense* license_get(rdpContext* context); + FREERDP_API LICENSE_STATE license_get_state(const rdpLicense* license); + FREERDP_API LICENSE_TYPE license_get_type(const rdpLicense* license); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_LICENSE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/listener.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/listener.h new file mode 100644 index 0000000000000000000000000000000000000000..56ede560a6f907ac91cc8fb1462573e50ca8dc63 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/listener.h @@ -0,0 +1,86 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Server Listener + * + * Copyright 2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LISTENER_H +#define FREERDP_LISTENER_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_freerdp_listener freerdp_listener; + + typedef BOOL (*psListenerOpen)(freerdp_listener* instance, const char* bind_address, + UINT16 port); + typedef BOOL (*psListenerOpenLocal)(freerdp_listener* instance, const char* path); + typedef BOOL (*psListenerOpenFromSocket)(freerdp_listener* instance, int fd); +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("Use psListenerGetEventHandles instead", + typedef BOOL (*psListenerGetFileDescriptor)(freerdp_listener* instance, + void** rfds, int* rcount);) +#endif + typedef DWORD (*psListenerGetEventHandles)(freerdp_listener* instance, HANDLE* events, + DWORD nCount); + typedef BOOL (*psListenerCheckFileDescriptor)(freerdp_listener* instance); + typedef void (*psListenerClose)(freerdp_listener* instance); + typedef BOOL (*psPeerAccepted)(freerdp_listener* instance, freerdp_peer* client); + + struct rdp_freerdp_listener + { + void* info; + void* listener; + void* param1; + void* param2; + void* param3; + void* param4; + + psListenerOpen Open; + psListenerOpenLocal OpenLocal; +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("Use rdp_freerdp_listener::GetEventHandles instead", + psListenerGetFileDescriptor GetFileDescriptor;) +#else + void* reserved; +#endif + psListenerGetEventHandles GetEventHandles; + psListenerCheckFileDescriptor CheckFileDescriptor; + psListenerClose Close; + + psPeerAccepted PeerAccepted; + psListenerOpenFromSocket OpenFromSocket; + + psListenerCheckFileDescriptor CheckPeerAcceptRestrictions; + }; + + FREERDP_API void freerdp_listener_free(freerdp_listener* instance); + + WINPR_ATTR_MALLOC(freerdp_listener_free, 1) + FREERDP_API freerdp_listener* freerdp_listener_new(void); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_LISTENER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/locale/keyboard.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/locale/keyboard.h new file mode 100644 index 0000000000000000000000000000000000000000..82b13c3f45043c8f486c7c244cbcebdb2f3b03aa --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/locale/keyboard.h @@ -0,0 +1,352 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Keyboard Mapping + * + * Copyright 2009-2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LOCALE_KEYBOARD_H +#define FREERDP_LOCALE_KEYBOARD_H + +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_remap_table FREERDP_REMAP_TABLE; + + typedef enum + { + RDP_KEYBOARD_LAYOUT_TYPE_STANDARD = 1, + RDP_KEYBOARD_LAYOUT_TYPE_VARIANT = 2, + RDP_KEYBOARD_LAYOUT_TYPE_IME = 4 + } FREERDP_KEYBOARD_LAYOUT_TYPES; + + typedef struct + { + UINT16 id; + UINT8 primaryId; + UINT8 subId; + char locale[512]; + char primaryLanguage[512]; + char primaryLanguageSymbol[512]; + char subLanguage[512]; + char subLanguageSymbol[512]; + } RDP_CODEPAGE; + +typedef struct +{ + DWORD code; /* Keyboard layout code */ + char* name; /* Keyboard layout name */ +} RDP_KEYBOARD_LAYOUT; + +/* Keyboard layout IDs */ +typedef enum +{ + KBD_ARABIC_101 = 0x00000401, + KBD_BULGARIAN = 0x00000402, + KBD_CHINESE_TRADITIONAL_US = 0x00000404, + KBD_CZECH = 0x00000405, + KBD_DANISH = 0x00000406, + KBD_GERMAN = 0x00000407, + KBD_GREEK = 0x00000408, + KBD_US = 0x00000409, + KBD_SPANISH = 0x0000040A, + KBD_FINNISH = 0x0000040B, + KBD_FRENCH = 0x0000040C, + KBD_HEBREW = 0x0000040D, + KBD_HUNGARIAN = 0x0000040E, + KBD_ICELANDIC = 0x0000040F, + KBD_ITALIAN = 0x00000410, + KBD_JAPANESE = 0x00000411, + KBD_KOREAN = 0x00000412, + KBD_DUTCH = 0x00000413, + KBD_NORWEGIAN = 0x00000414, + KBD_POLISH_PROGRAMMERS = 0x00000415, + KBD_PORTUGUESE_BRAZILIAN_ABNT = 0x00000416, + KBD_ROMANIAN = 0x00000418, + KBD_RUSSIAN = 0x00000419, + KBD_CROATIAN = 0x0000041A, + KBD_SLOVAK = 0x0000041B, + KBD_ALBANIAN = 0x0000041C, + KBD_SWEDISH = 0x0000041D, + KBD_THAI_KEDMANEE = 0x0000041E, + KBD_TURKISH_Q = 0x0000041F, + KBD_URDU = 0x00000420, + KBD_UKRAINIAN = 0x00000422, + KBD_BELARUSIAN = 0x00000423, + KBD_SLOVENIAN = 0x00000424, + KBD_ESTONIAN = 0x00000425, + KBD_LATVIAN = 0x00000426, + KBD_LITHUANIAN_IBM = 0x00000427, + KBD_FARSI = 0x00000429, + KBD_VIETNAMESE = 0x0000042A, + KBD_ARMENIAN_EASTERN = 0x0000042B, + KBD_AZERI_LATIN = 0x0000042C, + KBD_FYRO_MACEDONIAN = 0x0000042F, + KBD_GEORGIAN = 0x00000437, + KBD_FAEROESE = 0x00000438, + KBD_DEVANAGARI_INSCRIPT = 0x00000439, + KBD_MALTESE_47_KEY = 0x0000043A, + KBD_NORWEGIAN_WITH_SAMI = 0x0000043B, + KBD_KAZAKH = 0x0000043F, + KBD_KYRGYZ_CYRILLIC = 0x00000440, + KBD_TATAR = 0x00000444, + KBD_BENGALI = 0x00000445, + KBD_PUNJABI = 0x00000446, + KBD_GUJARATI = 0x00000447, + KBD_TAMIL = 0x00000449, + KBD_TELUGU = 0x0000044A, + KBD_KANNADA = 0x0000044B, + KBD_MALAYALAM = 0x0000044C, + KBD_MARATHI = 0x0000044E, + KBD_MONGOLIAN_CYRILLIC = 0x00000450, + KBD_UNITED_KINGDOM_EXTENDED = 0x00000452, + KBD_SYRIAC = 0x0000045A, + KBD_NEPALI = 0x00000461, + KBD_PASHTO = 0x00000463, + KBD_DIVEHI_PHONETIC = 0x00000465, + KBD_LUXEMBOURGISH = 0x0000046E, + KBD_MAORI = 0x00000481, + KBD_CHINESE_SIMPLIFIED_US = 0x00000804, + KBD_SWISS_GERMAN = 0x00000807, + KBD_UNITED_KINGDOM = 0x00000809, + KBD_LATIN_AMERICAN = 0x0000080A, + KBD_BELGIAN_FRENCH = 0x0000080C, + KBD_BELGIAN_PERIOD = 0x00000813, + KBD_PORTUGUESE = 0x00000816, + KBD_SERBIAN_LATIN = 0x0000081A, + KBD_AZERI_CYRILLIC = 0x0000082C, + KBD_SWEDISH_WITH_SAMI = 0x0000083B, + KBD_UZBEK_CYRILLIC = 0x00000843, + KBD_INUKTITUT_LATIN = 0x0000085D, + KBD_CANADIAN_FRENCH_LEGACY = 0x00000C0C, + KBD_SERBIAN_CYRILLIC = 0x00000C1A, + KBD_CANADIAN_FRENCH = 0x00001009, + KBD_SWISS_FRENCH = 0x0000100C, + KBD_BOSNIAN = 0x0000141A, + KBD_IRISH = 0x00001809, + KBD_BOSNIAN_CYRILLIC = 0x0000201A +} FREERDP_KBD_LAYOUT_ID; + +/* Keyboard layout variant IDs */ +typedef enum +{ + KBD_ARABIC_102 = 0x00010401, + KBD_BULGARIAN_LATIN = 0x00010402, + KBD_CZECH_QWERTY = 0x00010405, + KBD_GERMAN_IBM = 0x00010407, + KBD_GREEK_220 = 0x00010408, + KBD_UNITED_STATES_DVORAK = 0x00010409, + KBD_SPANISH_VARIATION = 0x0001040A, + KBD_HUNGARIAN_101_KEY = 0x0001040E, + KBD_ITALIAN_142 = 0x00010410, + KBD_POLISH_214 = 0x00010415, + KBD_PORTUGUESE_BRAZILIAN_ABNT2 = 0x00010416, + KBD_ROMANIAN_STANDARD = 0x00010418, + KBD_RUSSIAN_TYPEWRITER = 0x00010419, + KBD_SLOVAK_QWERTY = 0x0001041B, + KBD_THAI_PATTACHOTE = 0x0001041E, + KBD_TURKISH_F = 0x0001041F, + KBD_LATVIAN_QWERTY = 0x00010426, + KBD_LITHUANIAN = 0x00010427, + KBD_ARMENIAN_WESTERN = 0x0001042B, + KBD_GEORGIAN_QUERTY = 0x00010437, + KBD_HINDI_TRADITIONAL = 0x00010439, + KBD_MALTESE_48_KEY = 0x0001043A, + KBD_SAMI_EXTENDED_NORWAY = 0x0001043B, + KBD_BENGALI_INSCRIPT = 0x00010445, + KBD_KHMER = 0x00010453, + KBD_SYRIAC_PHONETIC = 0x0001045A, + KBD_DIVEHI_TYPEWRITER = 0x00010465, + KBD_BELGIAN_COMMA = 0x0001080C, + KBD_FINNISH_WITH_SAMI = 0x0001083B, + KBD_CANADIAN_MULTILINGUAL_STANDARD = 0x00011009, + KBD_GAELIC = 0x00011809, + KBD_ARABIC_102_AZERTY = 0x00020401, + KBD_CZECH_PROGRAMMERS = 0x00020405, + KBD_GREEK_319 = 0x00020408, + KBD_UNITED_STATES_INTERNATIONAL = 0x00020409, + KBD_HEBREW_STANDARD = 0x0002040D, /** @since version 3.6.0 */ + KBD_RUSSIAN_PHONETIC = 0x00020419, + KBD_THAI_KEDMANEE_NON_SHIFTLOCK = 0x0002041E, + KBD_BANGLA = 0x00020445, + KBD_SAMI_EXTENDED_FINLAND_SWEDEN = 0x0002083B, + KBD_GREEK_220_LATIN = 0x00030408, + KBD_UNITED_STATES_DVORAK_FOR_LEFT_HAND = 0x00030409, + KBD_THAI_PATTACHOTE_NON_SHIFTLOCK = 0x0003041E, + KBD_BULGARIAN_PHONETIC = 0x00040402, + KBD_GREEK_319_LATIN = 0x00040408, + KBD_UNITED_STATES_DVORAK_FOR_RIGHT_HAND = 0x00040409, + KBD_UNITED_STATES_DVORAK_PROGRAMMER = 0x19360409, + KBD_GREEK_LATIN = 0x00050408, + KBD_PERSIAN = 0x00050429, + KBD_US_ENGLISH_TABLE_FOR_IBM_ARABIC_238_L = 0x00050409, + KBD_GREEK_POLYTONIC = 0x00060408, + KBD_FRENCH_BEPO = WINPR_CXX_COMPAT_CAST(int, 0xa000040c), + KBD_GERMAN_NEO = WINPR_CXX_COMPAT_CAST(int, 0xB0000407) +} FREERDP_KBD_LAYPUT_VARIANT_ID; + +/* Global Input Method Editor (IME) IDs */ +typedef enum +{ + KBD_CHINESE_TRADITIONAL_PHONETIC = WINPR_CXX_COMPAT_CAST(int, 0xE0010404), + KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002 = WINPR_CXX_COMPAT_CAST(int, 0xE0010411), + KBD_KOREAN_INPUT_SYSTEM_IME_2000 = WINPR_CXX_COMPAT_CAST(int, 0xE0010412), + KBD_CHINESE_SIMPLIFIED_QUANPIN = WINPR_CXX_COMPAT_CAST(int, 0xE0010804), + KBD_CHINESE_TRADITIONAL_CHANGJIE = WINPR_CXX_COMPAT_CAST(int, 0xE0020404), + KBD_CHINESE_SIMPLIFIED_SHUANGPIN = WINPR_CXX_COMPAT_CAST(int, 0xE0020804), + KBD_CHINESE_TRADITIONAL_QUICK = WINPR_CXX_COMPAT_CAST(int, 0xE0030404), + KBD_CHINESE_SIMPLIFIED_ZHENGMA = WINPR_CXX_COMPAT_CAST(int, 0xE0030804), + KBD_CHINESE_TRADITIONAL_BIG5_CODE = WINPR_CXX_COMPAT_CAST(int, 0xE0040404), + KBD_CHINESE_TRADITIONAL_ARRAY = WINPR_CXX_COMPAT_CAST(int, 0xE0050404), + KBD_CHINESE_SIMPLIFIED_NEIMA = WINPR_CXX_COMPAT_CAST(int, 0xE0050804), + KBD_CHINESE_TRADITIONAL_DAYI = WINPR_CXX_COMPAT_CAST(int, 0xE0060404), + KBD_CHINESE_TRADITIONAL_UNICODE = WINPR_CXX_COMPAT_CAST(int, 0xE0070404), + KBD_CHINESE_TRADITIONAL_NEW_PHONETIC = WINPR_CXX_COMPAT_CAST(int, 0xE0080404), + KBD_CHINESE_TRADITIONAL_NEW_CHANGJIE = WINPR_CXX_COMPAT_CAST(int, 0xE0090404), + KBD_CHINESE_TRADITIONAL_MICROSOFT_PINYIN_IME_3 = WINPR_CXX_COMPAT_CAST(int, 0xE00E0804), + KBD_CHINESE_TRADITIONAL_ALPHANUMERIC = WINPR_CXX_COMPAT_CAST(int, 0xE00F0404) +} FREERDP_KBD_IME_ID; + +/** @brief Deallocation function for a \b RDP_KEYBOARD_LAYOUT array of \b count size + * + * @param layouts An array allocated by \ref freerdp_keyboard_get_layouts + * @param count The number of \b RDP_KEYBOARD_LAYOUT members + * + */ +FREERDP_API void freerdp_keyboard_layouts_free(RDP_KEYBOARD_LAYOUT* layouts, size_t count); + +/** @brief Return an allocated array of available keyboard layouts + * + * @param types The types of layout queried. A mask of \b RDP_KEYBOARD_LAYOUT_TYPES + * @param count A pointer that will be set to the number of elements in the returned array + * + * @return An allocated array of keyboard layouts, free with \b freerdp_keyboard_layouts_free + */ +WINPR_ATTR_MALLOC(freerdp_keyboard_layouts_free, 1) +FREERDP_API RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(DWORD types, size_t* count); + +/** @brief Get a string representation of a keyboard layout. + * + * @param keyboardLayoutId The keyboard layout to get a string for + * + * @return The string representation of the layout or the string \b "unknown" in case there is + * none. + */ +FREERDP_API const char* freerdp_keyboard_get_layout_name_from_id(DWORD keyboardLayoutId); + +/** @brief Get a keyboard layout id from a string + * + * @param name The string to convert to a layout id. Must not be \b NULL + * + * @return The keyboard layout id or \b 0 in case of no mapping + */ +FREERDP_API DWORD freerdp_keyboard_get_layout_id_from_name(const char* name); + +WINPR_DEPRECATED_VAR("since 3.11.0, implement yourself in client", + FREERDP_API DWORD freerdp_keyboard_init(DWORD keyboardLayoutId)); + +WINPR_DEPRECATED_VAR("since 3.11.0, implement yourself in client", + FREERDP_API DWORD freerdp_keyboard_init_ex(DWORD keyboardLayoutId, + const char* keyboardRemappingList)); + +WINPR_DEPRECATED_VAR("since 3.11.0, implement yourself in client", + FREERDP_API DWORD + freerdp_keyboard_get_rdp_scancode_from_x11_keycode(DWORD keycode)); + +WINPR_DEPRECATED_VAR("since 3.11.0, implement yourself in client", + FREERDP_API DWORD freerdp_keyboard_get_x11_keycode_from_rdp_scancode( + DWORD scancode, BOOL extended)); + +/** @brief deallocate a \b FREERDP_REMAP_TABLE + * + * @param table The table to deallocate, may be \b NULL + * + * @since version 3.11.0 + */ +FREERDP_API void freerdp_keyboard_remap_free(FREERDP_REMAP_TABLE* table); + +/** @brief parses a key=value string and creates a RDP scancode remapping table from it. + * + * @param list A string containing the comma separated key=value pairs (e.g. + * 'key=val,key2=val2,...') + * + * @return An allocated array of values to remap. Must be deallocated by \ref + * freerdp_keyboard_remap_free + * + * @since version 3.11.0 + */ +WINPR_ATTR_MALLOC(freerdp_keyboard_remap_free, 1) +FREERDP_API FREERDP_REMAP_TABLE* freerdp_keyboard_remap_string_to_list(const char* list); + +/** @brief does remap a RDP scancode according to the remap table provided. + * + * @param remap_table The remapping table to use + * @param rdpScanCode the RDP scancode to remap + * + * @return The remapped RDP scancode (or the rdpScanCode if not remapped) or \b 0 in case of any + * failures + * + * @since version 3.11.0 + */ +FREERDP_API DWORD freerdp_keyboard_remap_key(const FREERDP_REMAP_TABLE* remap_table, + DWORD rdpScanCode); + +/** @brief deallocator for a \b RDP_CODEPAGE array allocated by \ref + * freerdp_keyboard_get_matching_codepages + * + * @param codepages The codepages to free, may be \b NULL + */ +FREERDP_API void freerdp_codepages_free(RDP_CODEPAGE* codepages); + +/** @brief return an allocated array of matching codepages + * + * @param column The column the filter is applied to: + * - 0 : RDP_CODEPAGE::locale + * - 1 : RDP_CODEPAGE::PrimaryLanguage + * - 2 : RDP_CODEPAGE::PrimaryLanguageSymbol + * - 3 : RDP_CODEPAGE::Sublanguage + * - 4 : RDP_CODEPAGE::SublanguageSymbol + * @param filter A filter pattern or \b NULL for no filtering. Simple string match, no expressions + * supported (e.g. \b strstr match) + * @param count A pointer that will be set to the number of codepages found, may be \b NULL + * + * @return An allocated array of \b RDP_CODEPAGE of size \b count or \b NULL if no match. Must be + * freed by \ref freerdp_codepages_free + */ +WINPR_ATTR_MALLOC(freerdp_codepages_free, 1) +FREERDP_API RDP_CODEPAGE* freerdp_keyboard_get_matching_codepages(DWORD column, const char* filter, + size_t* count); + +/** @brief get a string representation of a RDP scancode + * + * @param scancode The RDP scancode to get a string for + * + * @return A string describing the RDP scancode or \b NULL if it does not exist + */ +FREERDP_API const char* freerdp_keyboard_scancode_name(DWORD scancode); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_LOCALE_KEYBOARD_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/locale/locale.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/locale/locale.h new file mode 100644 index 0000000000000000000000000000000000000000..43b0b1883079a00f665e0604c4e50691f5ff28a8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/locale/locale.h @@ -0,0 +1,294 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Microsoft Locales + * + * Copyright 2009-2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Detection of plausible keyboard layout id based on current locale (LANG) setting. */ + +/* + * Refer to "Windows XP/Server 2003 - List of Locale IDs, Input Locale, and Language Collection": + * http://www.microsoft.com/globaldev/reference/winxp/xp-lcid.mspx + */ + +#ifndef FREERDP_LOCALE_H +#define FREERDP_LOCALE_H + +#include +#include + +/** @defgroup keyboard-identifiers Keyboard Layout Identifiers + * @{ + */ +#define AFRIKAANS 0x0436 +#define ALBANIAN 0x041C +#define ALSATIAN 0x0484 +#define AMHARIC 0x045E +#define ARABIC_SAUDI_ARABIA 0x0401 +#define ARABIC_IRAQ 0x0801 +#define ARABIC_EGYPT 0x0C01 +#define ARABIC_LIBYA 0x1001 +#define ARABIC_ALGERIA 0x1401 +#define ARABIC_MOROCCO 0x1801 +#define ARABIC_TUNISIA 0x1C01 +#define ARABIC_OMAN 0x2001 +#define ARABIC_YEMEN 0x2401 +#define ARABIC_SYRIA 0x2801 +#define ARABIC_JORDAN 0x2C01 +#define ARABIC_LEBANON 0x3001 +#define ARABIC_KUWAIT 0x3401 +#define ARABIC_UAE 0x3801 +#define ARABIC_BAHRAIN 0x3C01 +#define ARABIC_QATAR 0x4001 +#define ARMENIAN 0x042B +#define ASSAMESE 0x044D +#define AZERI_LATIN 0x042C +#define AZERI_CYRILLIC 0x082C +#define BASHKIR 0x046D +#define BASQUE 0x042D +#define BELARUSIAN 0x0423 +#define BENGALI_INDIA 0x0445 +#define BOSNIAN_LATIN 0x141A +#define BRETON 0x047E +#define BULGARIAN 0x0402 +#define CATALAN 0x0403 +#define CHEROKEE 0x045C +#define CHINESE_TAIWAN 0x0404 +#define CHINESE_PRC 0x0804 +#define CHINESE_HONG_KONG 0x0C04 +#define CHINESE_SINGAPORE 0x1004 +#define CHINESE_MACAU 0x1404 +#define CROATIAN 0x041A +#define CROATIAN_BOSNIA_HERZEGOVINA 0x101A +#define CZECH 0x0405 +#define DANISH 0x0406 +#define DARI 0x048C +#define DIVEHI 0x0465 +#define DUTCH_STANDARD 0x0413 +#define DUTCH_BELGIAN 0x0813 +#define ENGLISH_UNITED_STATES 0x0409 +#define ENGLISH_UNITED_KINGDOM 0x0809 +#define ENGLISH_AUSTRALIAN 0x0C09 +#define ENGLISH_CANADIAN 0x1009 +#define ENGLISH_NEW_ZEALAND 0x1409 +#define ENGLISH_INDIA 0x4009 +#define ENGLISH_IRELAND 0x1809 +#define ENGLISH_MALAYSIA 0x4409 +#define ENGLISH_SOUTH_AFRICA 0x1C09 +#define ENGLISH_JAMAICA 0x2009 +#define ENGLISH_CARIBBEAN 0x2409 +#define ENGLISH_BELIZE 0x2809 +#define ENGLISH_TRINIDAD 0x2C09 +#define ENGLISH_ZIMBABWE 0x3009 +#define ENGLISH_PHILIPPINES 0x3409 +#define ENGLISH_SINGAPORE 0x4809 +#define ESTONIAN 0x0425 +#define FAEROESE 0x0438 +#define FARSI 0x0429 +#define FILIPINO 0x0464 +#define FINNISH 0x040B +#define FRENCH_STANDARD 0x040C +#define FRENCH_BELGIAN 0x080C +#define FRENCH_CANADIAN 0x0C0C +#define FRENCH_SWISS 0x100C +#define FRENCH_LUXEMBOURG 0x140C +#define FRENCH_MONACO 0x180C +#define FRISIAN 0x0462 +#define GEORGIAN 0x0437 +#define GALICIAN 0x0456 +#define GERMAN_STANDARD 0x0407 +#define GERMAN_SWISS 0x0807 +#define GERMAN_AUSTRIAN 0x0C07 +#define GERMAN_LUXEMBOURG 0x1007 +#define GERMAN_LIECHTENSTEIN 0x1407 +#define GREEK 0x0408 +#define GREENLANDIC 0x046F +#define GUJARATI 0x0447 +#define HAWAIIAN 0x0475 +#define HEBREW 0x040D +#define HINDI 0x0439 +#define HUNGARIAN 0x040E +#define ICELANDIC 0x040F +#define IGBO 0x0470 +#define INDONESIAN 0x0421 +#define INUKTITUT 0x045D +#define IRISH 0x083C +#define ITALIAN_STANDARD 0x0410 +#define ITALIAN_SWISS 0x0810 +#define JAPANESE 0x0411 +#define KANNADA 0x044B +#define KAZAKH 0x043F +#define KHMER 0x0453 +#define KICHE 0x0486 +#define KINYARWANDA 0x0487 +#define KONKANI 0x0457 +#define KOREAN 0x0412 +#define KYRGYZ 0x0440 +#define LAO 0x0454 +#define LATVIAN 0x0426 +#define LITHUANIAN 0x0427 +#define LOWER_SORBIAN 0x082E +#define LUXEMBOURGISH 0x046E +#define MACEDONIAN 0x042F +#define MALAY_MALAYSIA 0x043E +#define MALAY_BRUNEI_DARUSSALAM 0x083E +#define MALAYALAM 0x044C +#define MALTESE 0x043A +#define MAPUDUNGUN 0x047A +#define MAORI 0x0481 +#define MARATHI 0x044E +#define MOHAWK 0x047C +#define MONGOLIAN 0x0450 +#define MYANMAR 0x0455 +#define NEPALI 0x0461 +#define NORWEGIAN_BOKMAL 0x0414 +#define NORWEGIAN_NYNORSK 0x0814 +#define OCCITAN 0x0482 +#define ORIYA 0x0448 +#define PASHTO 0x0463 +#define POLISH 0x0415 +#define PORTUGUESE_BRAZILIAN 0x0416 +#define PORTUGUESE_STANDARD 0x0816 +#define PUNJABI 0x0446 +#define QUECHUA_BOLIVIA 0x046B +#define QUECHUA_ECUADOR 0x086B +#define QUECHUA_PERU 0x0C6B +#define ROMANIAN 0x0418 +#define ROMANSH 0x0417 +#define RUSSIAN 0x0419 +#define SAMI_INARI 0x243B +#define SAMI_LULE_NORWAY 0x103B +#define SAMI_LULE_SWEDEN 0x143B +#define SAMI_NORTHERN_FINLAND 0x0C3B +#define SAMI_NORTHERN_NORWAY 0x043B +#define SAMI_NORTHERN_SWEDEN 0x083B +#define SAMI_SKOLT 0x203B +#define SAMI_SOUTHERN_NORWAY 0x183B +#define SAMI_SOUTHERN_SWEDEN 0x1C3B +#define SANSKRIT 0x044F +#define SERBIAN_LATIN 0x081A +#define SERBIAN_LATIN_BOSNIA_HERZEGOVINA 0x181A +#define SERBIAN_CYRILLIC 0x0C1A +#define SERBIAN_CYRILLIC_BOSNIA_HERZEGOVINA 0x1C1A +#define SESOTHO_SA_LEBOA 0x046C +#define SINHALA 0x045B +#define SLOVAK 0x041B +#define SLOVENIAN 0x0424 +#define SPANISH_TRADITIONAL_SORT 0x040A +#define SPANISH_MEXICAN 0x080A +#define SPANISH_MODERN_SORT 0x0C0A +#define SPANISH_GUATEMALA 0x100A +#define SPANISH_COSTA_RICA 0x140A +#define SPANISH_PANAMA 0x180A +#define SPANISH_DOMINICAN_REPUBLIC 0x1C0A +#define SPANISH_VENEZUELA 0x200A +#define SPANISH_COLOMBIA 0x240A +#define SPANISH_PERU 0x280A +#define SPANISH_ARGENTINA 0x2C0A +#define SPANISH_ECUADOR 0x300A +#define SPANISH_CHILE 0x340A +#define SPANISH_UNITED_STATES 0x540A +#define SPANISH_URUGUAY 0x380A +#define SPANISH_PARAGUAY 0x3C0A +#define SPANISH_BOLIVIA 0x400A +#define SPANISH_EL_SALVADOR 0x440A +#define SPANISH_HONDURAS 0x480A +#define SPANISH_NICARAGUA 0x4C0A +#define SPANISH_PUERTO_RICO 0x500A +#define SWAHILI 0x0441 +#define SWEDISH 0x041D +#define SWEDISH_FINLAND 0x081D +#define SYRIAC 0x045A +#define TAMIL 0x0449 +#define TATAR 0x0444 +#define TELUGU 0x044A +#define THAI 0x041E +#define TIBETAN_BHUTAN 0x0851 +#define TIBETAN_PRC 0x0451 +#define TSWANA 0x0432 +#define UKRAINIAN 0x0422 +#define TURKISH 0x041F +#define TURKMEN 0x0442 +#define UIGHUR 0x0480 +#define UPPER_SORBIAN 0x042E +#define URDU 0x0420 +#define URDU_INDIA 0x0820 +#define UZBEK_LATIN 0x0443 +#define UZBEK_CYRILLIC 0x0843 +#define VIETNAMESE 0x042A +#define WELSH 0x0452 +#define WOLOF 0x0488 +#define XHOSA 0x0434 +#define YAKUT 0x0485 +#define YI 0x0478 +#define YORUBA 0x046A +#define ZULU 0x0435 +/** @} */ + +#define LOCALE_LANGUAGE_LEN 6 /** @since version 3.6.0 */ +#define LOCALE_COUNTRY_LEN 10 /** @since version 3.6.0 */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @brief A SYSTEM_LOCALE holding details about a locale + * @since version 3.6.0 + */ + typedef struct + { + char language[LOCALE_LANGUAGE_LEN]; /* Two or three letter language code */ + char country[LOCALE_COUNTRY_LEN]; /* Two or three letter country code (Sometimes with Cyrl_ + prefix) */ + DWORD code; /* 32-bit unsigned integer corresponding to the locale */ + } SYSTEM_LOCALE; + + FREERDP_API DWORD freerdp_get_system_locale_id(void); + FREERDP_API const char* freerdp_get_system_locale_name_from_id(DWORD localeId); + FREERDP_API int freerdp_detect_keyboard_layout_from_system_locale(DWORD* keyboardLayoutId); + + /** + * @brief Query the list of supported system locales + * @param count A pointer to hold the number of locales found + * @return A pointer to @ref SYSTEM_LOCALE or \b NULL in case none found + * @since version 3.6.0 + */ + FREERDP_API const SYSTEM_LOCALE* freerdp_get_system_locale_list(size_t* count); + + /** + * @brief Query the list of system locales and return a matching one + * + * @param locale A locale string to query + * @return A locale index >= 0 in case of success, <0 for failure + * @since version 3.6.0 + */ + FREERDP_API INT64 freerdp_get_locale_id_from_string(const char* locale); + + /** + * @brief Return the default @ref keyboard-identifiers for a provided locale + * @param locale The locale to query + * @return The @ref keyboard-identifiers to use + * @since version 3.6.0 + */ + FREERDP_API DWORD freerdp_get_keyboard_default_layout_for_locale(DWORD locale); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_LOCALE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/log.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/log.h new file mode 100644 index 0000000000000000000000000000000000000000..2343889ab9abf0ae03de529eeed12c18bc88aee2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/log.h @@ -0,0 +1,29 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP log defines + * + * Copyright 2014 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LOG_H +#define FREERDP_LOG_H + +#include + +#define FREERDP_TAG(tag) "com.freerdp." tag +#define SERVER_TAG(tag) FREERDP_TAG("server.") tag +#define CLIENT_TAG(tag) FREERDP_TAG("client.") tag + +#endif /* FREERDP_UTILS_DEBUG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/message.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/message.h new file mode 100644 index 0000000000000000000000000000000000000000..1c47b9f07366fca342fb546b8721a0622123edab --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/message.h @@ -0,0 +1,376 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Asynchronous Message Interface + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_MESSAGE_H +#define FREERDP_MESSAGE_H + +#define GetMessageType(_id) (_id & 0xFF) +#define GetMessageClass(_id) ((_id >> 16) & 0xFF) + +#define GetMessageId(_class, _type) ((_class << 16) | _type) + +#define MakeMessageId(_class, _type) (((_class##_Class) << 16) | (_class##_##_type)) + +/** + * Update Message Queue + */ + +#define FREERDP_UPDATE_MESSAGE_QUEUE 1 + +#define Update_Base 0 + +/* Update */ + +#define Update_Class (Update_Base + 1) + +#define Update_BeginPaint 1 +#define Update_EndPaint 2 +#define Update_SetBounds 3 +#define Update_Synchronize 4 +#define Update_DesktopResize 5 +#define Update_BitmapUpdate 6 +#define Update_Palette 7 +#define Update_PlaySound 8 +#define Update_RefreshRect 9 +#define Update_SuppressOutput 10 +#define Update_SurfaceCommand 11 +#define Update_SurfaceBits 12 +#define Update_SurfaceFrameMarker 13 +#define Update_SurfaceFrameAcknowledge 14 +#define Update_SetKeyboardIndicators 15 +#define Update_SetKeyboardImeStatus 16 + +#define FREERDP_UPDATE_BEGIN_PAINT MakeMessageId(Update, BeginPaint) +#define FREERDP_UPDATE_ END_PAINT MakeMessageId(Update, EndPaint) +#define FREERDP_UPDATE_SET_BOUNDS MakeMessageId(Update, SetBounds) +#define FREERDP_UPDATE_SYNCHRONIZE MakeMessageId(Update, Synchronize) +#define FREERDP_UPDATE_DESKTOP_RESIZE MakeMessageId(Update, DesktopResize) +#define FREERDP_UPDATE_BITMAP_UPDATE MakeMessageId(Update, BitmapUpdate) +#define FREERDP_UPDATE_PALETTE MakeMessageId(Update, Palette) +#define FREERDP_UPDATE_PLAY_SOUND MakeMessageId(Update, PlaySound) +#define FREERDP_UPDATE_REFRESH_RECT MakeMessageId(Update, RefreshRect) +#define FREERDP_UPDATE_SUPPRESS_OUTPUT MakeMessageId(Update, SuppressOutput) +#define FREERDP_UPDATE_SURFACE_COMMAND MakeMessageId(Update, SurfaceCommand) +#define FREERDP_UPDATE_SURFACE_BITS MakeMessageId(Update, SurfaceBits) +#define FREERDP_UPDATE_SURFACE_FRAME_MARKER MakeMessageId(Update, SurfaceFrameMarker) +#define FREERDP_UPDATE_SURFACE_FRAME_ACKNOWLEDGE MakeMessageId(Update, SurfaceFrameAcknowledge) +#define FREERDP_UPDATE_SET_KEYBOARD_INDICATORS MakeMessageId(Update, SetKeyboardIndicators) + +/* Primary Update */ + +#define PrimaryUpdate_Class (Update_Base + 2) + +#define PrimaryUpdate_DstBlt 1 +#define PrimaryUpdate_PatBlt 2 +#define PrimaryUpdate_ScrBlt 3 +#define PrimaryUpdate_OpaqueRect 4 +#define PrimaryUpdate_DrawNineGrid 5 +#define PrimaryUpdate_MultiDstBlt 6 +#define PrimaryUpdate_MultiPatBlt 7 +#define PrimaryUpdate_MultiScrBlt 8 +#define PrimaryUpdate_MultiOpaqueRect 9 +#define PrimaryUpdate_MultiDrawNineGrid 10 +#define PrimaryUpdate_LineTo 11 +#define PrimaryUpdate_Polyline 12 +#define PrimaryUpdate_MemBlt 13 +#define PrimaryUpdate_Mem3Blt 14 +#define PrimaryUpdate_SaveBitmap 15 +#define PrimaryUpdate_GlyphIndex 16 +#define PrimaryUpdate_FastIndex 17 +#define PrimaryUpdate_FastGlyph 18 +#define PrimaryUpdate_PolygonSC 19 +#define PrimaryUpdate_PolygonCB 20 +#define PrimaryUpdate_EllipseSC 21 +#define PrimaryUpdate_EllipseCB 22 + +#define FREERDP_PRIMARY_UPDATE_DSTBLT MakeMessageId(PrimaryUpdate, DstBlt) +#define FREERDP_PRIMARY_UPDATE_PATBLT MakeMessageId(PrimaryUpdate, PatBlt) +#define FREERDP_PRIMARY_UPDATE_SCRBLT MakeMessageId(PrimaryUpdate, ScrBlt) +#define FREERDP_PRIMARY_UPDATE_OPAQUE_RECT MakeMessageId(PrimaryUpdate, OpaqueRect) +#define FREERDP_PRIMARY_UPDATE_DRAW_NINE_GRID MakeMessageId(PrimaryUpdate, DrawNineGrid) +#define FREERDP_PRIMARY_UPDATE_MULTI_DSTBLT MakeMessageId(PrimaryUpdate, MultiDstBlt) +#define FREERDP_PRIMARY_UPDATE_MULTI_PATBLT MakeMessageId(PrimaryUpdate, MultiPatBlt) +#define FREERDP_PRIMARY_UPDATE_MULTI_SCRBLT MakeMessageId(PrimaryUpdate, MultiScrBlt) +#define FREERDP_PRIMARY_UPDATE_MULTI_OPAQUE_RECT MakeMessageId(PrimaryUpdate, MultiOpaqueRect) +#define FREERDP_PRIMARY_UPDATE_MULTI_DRAW_NINE_GRID MakeMessageId(PrimaryUpdate, MultiDrawNineGrid) +#define FREERDP_PRIMARY_UPDATE_LINE_TO MakeMessageId(PrimaryUpdate, LineTo) +#define FREERDP_PRIMARY_UPDATE_POLYLINE MakeMessageId(PrimaryUpdate, Polyline) +#define FREERDP_PRIMARY_UPDATE_MEMBLT MakeMessageId(PrimaryUpdate, MemBlt) +#define FREERDP_PRIMARY_UPDATE_MEM3BLT MakeMessageId(PrimaryUpdate, Mem3Blt) +#define FREERDP_PRIMARY_UPDATE_SAVE_BITMAP MakeMessageId(PrimaryUpdate, SaveBitmap) +#define FREERDP_PRIMARY_UPDATE_GLYPH_INDEX MakeMessageId(PrimaryUpdate, GlyphIndex) +#define FREERDP_PRIMARY_UPDATE_FAST_INDEX MakeMessageId(PrimaryUpdate, FastIndex) +#define FREERDP_PRIMARY_UPDATE_FAST_GLYPH MakeMessageId(PrimaryUpdate, FastGlyph) +#define FREERDP_PRIMARY_UPDATE_POLYGON_SC MakeMessageId(PrimaryUpdate, PolygonSC) +#define FREERDP_PRIMARY_UPDATE_POLYGON_CB MakeMessageId(PrimaryUpdate, PolygonCB) +#define FREERDP_PRIMARY_UPDATE_ELLIPSE_SC MakeMessageId(PrimaryUpdate, EllipseSC) +#define FREERDP_PRIMARY_UPDATE_ELLIPSE_CB MakeMessageId(PrimaryUpdate, EllipseCB) + +/* Secondary Update */ + +#define SecondaryUpdate_Class (Update_Base + 3) + +#define SecondaryUpdate_CacheBitmap 1 +#define SecondaryUpdate_CacheBitmapV2 2 +#define SecondaryUpdate_CacheBitmapV3 3 +#define SecondaryUpdate_CacheColorTable 4 +#define SecondaryUpdate_CacheGlyph 5 +#define SecondaryUpdate_CacheGlyphV2 6 +#define SecondaryUpdate_CacheBrush 7 + +#define FREERDP_SECONDARY_UPDATE_CACHE_BITMAP MakeMessageId(SecondaryUpdate, CacheBitmap) +#define FREERDP_SECONDARY_UPDATE_CACHE_BITMAP_V2 MakeMessageId(SecondaryUpdate, CacheBitmapV2) +#define FREERDP_SECONDARY_UPDATE_CACHE_BITMAP_V3 MakeMessageId(SecondaryUpdate, CacheBitmapV3) +#define FREERDP_SECONDARY_UPDATE_CACHE_COLOR_TABLE MakeMessageId(SecondaryUpdate, CacheColorTable) +#define FREERDP_SECONDARY_UPDATE_CACHE_GLYPH MakeMessageId(SecondaryUpdate, CacheGlyph) +#define FREERDP_SECONDARY_UPDATE_CACHE_GLYPH_V2 MakeMessageId(SecondaryUpdate, CacheGlyphV2) +#define FREERDP_SECONDARY_UPDATE_CACHE_BRUSH MakeMessageId(SecondaryUpdate, CacheBrush) + +/* Alternate Secondary Update */ + +#define AltSecUpdate_Class (Update_Base + 4) + +#define AltSecUpdate_CreateOffscreenBitmap 1 +#define AltSecUpdate_SwitchSurface 2 +#define AltSecUpdate_CreateNineGridBitmap 3 +#define AltSecUpdate_FrameMarker 4 +#define AltSecUpdate_StreamBitmapFirst 5 +#define AltSecUpdate_StreamBitmapNext 6 +#define AltSecUpdate_DrawGdiPlusFirst 7 +#define AltSecUpdate_DrawGdiPlusNext 8 +#define AltSecUpdate_DrawGdiPlusEnd 9 +#define AltSecUpdate_DrawGdiPlusCacheFirst 10 +#define AltSecUpdate_DrawGdiPlusCacheNext 11 +#define AltSecUpdate_DrawGdiPlusCacheEnd 12 + +#define FREERDP_ALTSEC_UPDATE_CREATE_OFFSCREEN_BITMAP \ + MakeMessageId(AltSecUpdate, CreateOffscreenBitmap) +#define FREERDP_ALTSEC_UPDATE_SWITCH_SURFACE MakeMessageId(AltSecUpdate, SwitchSurface) +#define FREERDP_ALTSEC_UPDATE_CREATE_NINE_GRID_BITMAP \ + MakeMessageId(AltSecUpdate, CreateNineGridBitmap) +#define FREERDP_ALTSEC_UPDATE_FRAME_MARKER MakeMessageId(AltSecUpdate, FrameMarker) +#define FREERDP_ALTSEC_UPDATE_STREAM_BITMAP_FIRST MakeMessageId(AltSecUpdate, StreamBitmapFirst) +#define FREERDP_ALTSEC_UPDATE_STREAM_BITMAP_NEXT MakeMessageId(AltSecUpdate, StreamBitmapNext) +#define FREERDP_ALTSEC_UPDATE_DRAW_GDI_PLUS_FIRST MakeMessageId(AltSecUpdate, DrawGdiPlusFirst) +#define FREERDP_ALTSEC_UPDATE_DRAW_GDI_PLUS_NEXT MakeMessageId(AltSecUpdate, DrawGdiPlusNext) +#define FREERDP_ALTSEC_UPDATE_DRAW_GDI_PLUS_END MakeMessageId(AltSecUpdate, DrawGdiPlusEnd) +#define FREERDP_ALTSEC_UPDATE_DRAW_GDI_PLUS_CACHE_FIRST \ + MakeMessageId(AltSecUpdate, DrawGdiPlusCacheFirst) +#define FREERDP_ALTSEC_UPDATE_DRAW_GDI_PLUS_CACHE_NEXT \ + MakeMessageId(AltSecUpdate, DrawGdiPlusCacheNext) +#define FREERDP_ALTSEC_UPDATE_DRAW_GDI_PLUS_CACHE_END \ + MakeMessageId(AltSecUpdate, DrawGdiPlusCacheEnd) + +/* Window Update */ + +#define WindowUpdate_Class (Update_Base + 5) + +#define WindowUpdate_WindowCreate 1 +#define WindowUpdate_WindowUpdate 2 +#define WindowUpdate_WindowIcon 3 +#define WindowUpdate_WindowCachedIcon 4 +#define WindowUpdate_WindowDelete 5 +#define WindowUpdate_NotifyIconCreate 6 +#define WindowUpdate_NotifyIconUpdate 7 +#define WindowUpdate_NotifyIconDelete 8 +#define WindowUpdate_MonitoredDesktop 9 +#define WindowUpdate_NonMonitoredDesktop 10 + +#define FREERDP_WINDOW_UPDATE_WINDOW_CREATE MakeMessageId(WindowUpdate, WindowCreate) +#define FREERDP_WINDOW_UPDATE_WINDOW_UPDATE MakeMessageId(WindowUpdate, WindowUpdate) +#define FREERDP_WINDOW_UPDATE_WINDOW_ICON MakeMessageId(WindowUpdate, WindowIcon) +#define FREERDP_WINDOW_UPDATE_WINDOW_CACHED_ICON MakeMessageId(WindowUpdate, WindowCachedIcon) +#define FREERDP_WINDOW_UPDATE_WINDOW_DELETE MakeMessageId(WindowUpdate, WindowDelete) +#define FREERDP_WINDOW_UPDATE_NOTIFY_ICON_CREATE MakeMessageId(WindowUpdate, NotifyIconCreate) +#define FREERDP_WINDOW_UPDATE_NOTIFY_ICON_UPDATE MakeMessageId(WindowUpdate, NotifyIconUpdate) +#define FREERDP_WINDOW_UPDATE_NOTIFY_ICON_DELETE MakeMessageId(WindowUpdate, NotifyIconDelete) +#define FREERDP_WINDOW_UPDATE_MONITORED_DESKTOP MakeMessageId(WindowUpdate, MonitoredDesktop) +#define FREERDP_WINDOW_UPDATE_NON_MONITORED_DESKTOP MakeMessageId(WindowUpdate, NonMonitoredDesktop) + +/* Pointer Update */ + +#define PointerUpdate_Class (Update_Base + 6) + +#define PointerUpdate_PointerPosition 1 +#define PointerUpdate_PointerSystem 2 +#define PointerUpdate_PointerColor 3 +#define PointerUpdate_PointerNew 4 +#define PointerUpdate_PointerCached 5 +#define PointerUpdate_PointerLarge 6 + +#define FREERDP_POINTER_UPDATE_ POINTER_POSITION MakeMessageId(PointerUpdate, PointerPosition) +#define FREERDP_POINTER_UPDATE_POINTER_SYSTEM MakeMessageId(PointerUpdate, PointerSystem) +#define FREERDP_POINTER_UPDATE_POINTER_COLOR MakeMessageId(PointerUpdate, PointerColor) +#define FREERDP_POINTER_UPDATE_POINTER_NEW MakeMessageId(PointerUpdate, PointerNew) +#define FREERDP_POINTER_UPDATE_POINTER_CACHED MakeMessageId(PointerUpdate, PointerCached) +#define FREERDP_POINTER_UPDATE_POINTER_LARGE MakeMessageId(PointerUpdate, PointerLarge) + +/** + * Input Message Queue + */ + +#define FREERDP_INPUT_MESSAGE_QUEUE 2 + +#define Input_Base 16 + +/* Input */ + +#define Input_Class (Input_Base + 1) + +#define Input_SynchronizeEvent 1 +#define Input_KeyboardEvent 2 +#define Input_UnicodeKeyboardEvent 3 +#define Input_MouseEvent 4 +#define Input_ExtendedMouseEvent 5 +#define Input_FocusInEvent 6 +#define Input_KeyboardPauseEvent 7 + +#define FREERDP_INPUT_SYNCHRONIZE_EVENT MakeMessageId(Input, SynchronizeEvent) +#define FREERDP_INPUT_KEYBOARD_EVENT MakeMessageId(Input, KeyboardEvent) +#define FREERDP_INPUT_UNICODE_KEYBOARD_EVENT MakeMessageId(Input, UnicodeKeyboardEvent) +#define FREERDP_INPUT_MOUSE_EVENT MakeMessageId(Input, MouseEvent) +#define FREERDP_INPUT_EXTENDED_MOUSE_EVENT MakeMessageId(Input, ExtendedMouseEvent) +#define FREERDP_INPUT_FOCUS_IN_EVENT MakeMessageId(Input, FocusInEvent) +#define FREERDP_INPUT_KEYBOARD_PAUSE_EVENT MakeMessageId(Input, KeyboardPauseEvent) + +/** + * Static Channel Message Queues + */ + +#define FREERDP_CHANNEL_MESSAGE_QUEUE 3 + +#define Channel_Base 20 + +/** + * Debug Channel + */ + +#define DebugChannel_Class (Channel_Base + 1) + +/** + * Clipboard Channel + */ + +#define CliprdrChannel_Class (Channel_Base + 2) + +#define CliprdrChannel_MonitorReady 1 +#define CliprdrChannel_FormatList 2 +#define CliprdrChannel_DataRequest 3 +#define CliprdrChannel_DataResponse 4 +#define CliprdrChannel_ClipCaps 5 +#define CliprdrChannel_FilecontentsRequest 6 +#define CliprdrChannel_FilecontentsResponse 7 +#define CliprdrChannel_LockClipdata 8 +#define CliprdrChannel_UnLockClipdata 9 +#define CliprdrChannel_TemporaryDirectory 10 + +#define FREERDP_CLIPRDR_CHANNEL_MONITOR_READY MakeMessageId(CliprdrChannel, MonitorReady) +#define FREERDP_CLIPRDR_CHANNEL_FORMAT_LIST MakeMessageId(CliprdrChannel, FormatList) +#define FREERDP_CLIPRDR_CHANNEL_DATA_REQUEST MakeMessageId(CliprdrChannel, DataRequest) +#define FREERDP_CLIPRDR_CHANNEL_DATA_RESPONSE MakeMessageId(CliprdrChannel, DataResponse) +#define FREERDP_CLIPRDR_CHANNEL_CLIP_CAPS MakeMessageId(CliprdrChannel, ClipCaps) + +/** + * Multimedia Redirection Channel + */ + +#define TsmfChannel_Class (Channel_Base + 3) + +#define TsmfChannel_VideoFrame 1 +#define TsmfChannel_Redraw 2 + +#define FREERDP_TSMF_CHANNEL_VIDEO_FRAME MakeMessageId(TsmfChannel, VideoFrame) +#define FREERDP_TSMF_CHANNEL_REDRAW MakeMessageId(TsmfChannel, Redraw) + +/** + * RemoteApp Channel + */ + +#define RailChannel_Class (Channel_Base + 4) + +#define RailChannel_ClientExecute 1 +#define RailChannel_ClientActivate 2 +#define RailChannel_GetSystemParam 3 +#define RailChannel_ClientSystemParam 4 +#define RailChannel_ServerSystemParam 5 +#define RailChannel_ClientSystemCommand 6 +#define RailChannel_ClientHandshake 7 +#define RailChannel_ServerHandshake 8 +#define RailChannel_ClientNotifyEvent 9 +#define RailChannel_ClientWindowMove 10 +#define RailChannel_ServerLocalMoveSize 11 +#define RailChannel_ServerMinMaxInfo 12 +#define RailChannel_ClientInformation 13 +#define RailChannel_ClientSystemMenu 14 +#define RailChannel_ClientLanguageBarInfo 15 +#define RailChannel_ServerLanguageBarInfo 16 +#define RailChannel_ServerExecuteResult 17 +#define RailChannel_ClientGetAppIdRequest 18 +#define RailChannel_ServerGetAppIdResponse 19 +#define RailChannel_ClientHandshakeEx 20 +#define RailChannel_ServerHandshakeEx 21 + +#define FREERDP_RAIL_CHANNEL_CLIENT_EXECUTE MakeMessageId(RailChannel, ClientExecute) +#define FREERDP_RAIL_CHANNEL_CLIENT_ACTIVATE MakeMessageId(RailChannel, ClientActivate) +#define FREERDP_RAIL_CHANNEL_GET_SYSTEM_PARAM MakeMessageId(RailChannel, GetSystemParam) +#define FREERDP_RAIL_CHANNEL_CLIENT_SYSTEM_PARAM MakeMessageId(RailChannel, ClientSystemParam) +#define FREERDP_RAIL_CHANNEL_SERVER_SYSTEM_PARAM MakeMessageId(RailChannel, ClientSystemParam) +#define FREERDP_RAIL_CHANNEL_CLIENT_SYSTEM_COMMAND MakeMessageId(RailChannel, ClientSystemCommand) +#define FREERDP_RAIL_CHANNEL_CLIENT_HANDSHAKE MakeMessageId(RailChannel, ClientHandshake) +#define FREERDP_RAIL_CHANNEL_SERVER_HANDSHAKE MakeMessageId(RailChannel, ServerHandshake) +#define FREERDP_RAIL_CHANNEL_CLIENT_NOTIFY_EVENT MakeMessageId(RailChannel, ClientNotifyEvent) +#define FREERDP_RAIL_CHANNEL_CLIENT_WINDOW_MOVE MakeMessageId(RailChannel, ClientWindowMove) +#define FREERDP_RAIL_CHANNEL_SERVER_LOCAL_MOVE_SIZE MakeMessageId(RailChannel, ServerLocalMoveSize) +#define FREERDP_RAIL_CHANNEL_SERVER_MIN_MAX_INFO MakeMessageId(RailChannel, ServerMinMaxInfo) +#define FREERDP_RAIL_CHANNEL_CLIENT_INFORMATION MakeMessageId(RailChannel, ClientInformation) +#define FREERDP_RAIL_CHANNEL_CLIENT_SYSTEM_MENU MakeMessageId(RailChannel, ClientSystemMenu) +#define FREERDP_RAIL_CHANNEL_CLIENT_LANGUAGE_BAR_INFO \ + MakeMessageId(RailChannel, ClientLanguageBarInfo) +#define FREERDP_RAIL_CHANNEL_SERVER_LANGUAGE_BAR_INFO \ + MakeMessageId(RailChannel, ServerLanguageBarInfo) +#define FREERDP_RAIL_CHANNEL_SERVER_EXECUTE_RESULT MakeMessageId(RailChannel, ServerExecuteResult) +#define FREERDP_RAIL_CHANNEL_CLIENT_GET_APP_ID_REQUEST \ + MakeMessageId(RailChannel, ClientGetAppIdRequest) +#define FREERDP_RAIL_CHANNEL_SERVER_GET_APP_ID_RESPONSE \ + MakeMessageId(RailChannel, ServerGetAppIdResponse) +#define FREERDP_RAIL_CHANNEL_CLIENT_HANDSHAKE_EX MakeMessageId(RailChannel, ClientHandshakeEx) +#define FREERDP_RAIL_CHANNEL_SERVER_HANDSHAKE_EX MakeMessageId(RailChannel, ServerHandshakeEx) + +/** + * MultiTouch Input Channel Extension (MS-RDPEDI) + */ + +#define RdpeiChannel_Class (Channel_Base + 5) + +#define RdpeiChannel_ServerReady 1 +#define RdpeiChannel_ClientReady 2 +#define RdpeiChannel_TouchEvent 3 +#define RdpeiChannel_SuspendTouch 4 +#define RdpeiChannel_ResumeTouch 5 +#define RdpeiChannel_DismissHoveringContact 6 + +#define FREERDP_RDPEI_CHANNEL_SERVER_READY MakeMessageId(RdpeiChannel, ServerReady) +#define FREERDP_RDPEI_CHANNEL_CLIENT_READY MakeMessageId(RdpeiChannel, ClientReady) +#define FREERDP_RDPEI_CHANNEL_TOUCH_EVENT MakeMessageId(RdpeiChannel, TouchEvent) +#define FREERDP_RDPEI_CHANNEL_SUSPEND_TOUCH MakeMessageId(RdpeiChannel, SuspendTouch) +#define FREERDP_RDPEI_CHANNEL_RESUME_TOUCH MakeMessageId(RdpeiChannel, ResumeTouch) +#define FREERDP_RDPEI_CHANNEL_DISMISS_HOVERING_CONTACT \ + MakeMessageId(RdpeiChannel, DismissHoveringContact) + +#endif /* FREERDP_MESSAGE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/metrics.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/metrics.h new file mode 100644 index 0000000000000000000000000000000000000000..6d00bfd62648fe9816bbb4d625aedbc93c4b9493 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/metrics.h @@ -0,0 +1,52 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Protocol Metrics + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_METRICS_H +#define FREERDP_METRICS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct rdp_metrics + { + rdpContext* context; + + UINT64 TotalCompressedBytes; + UINT64 TotalUncompressedBytes; + double TotalCompressionRatio; + }; + typedef struct rdp_metrics rdpMetrics; + + FREERDP_API double metrics_write_bytes(rdpMetrics* metrics, UINT32 UncompressedBytes, + UINT32 CompressedBytes); + + FREERDP_API void metrics_free(rdpMetrics* metrics); + + WINPR_ATTR_MALLOC(metrics_free, 1) + FREERDP_API rdpMetrics* metrics_new(rdpContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_METRICS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/peer.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/peer.h new file mode 100644 index 0000000000000000000000000000000000000000..db092281aa7c7e279ae9eaa7b63523c11052c86b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/peer.h @@ -0,0 +1,218 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Server Peer + * + * Copyright 2011 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_PEER_H +#define FREERDP_PEER_H + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef BOOL (*psPeerContextNew)(freerdp_peer* peer, rdpContext* context); + typedef void (*psPeerContextFree)(freerdp_peer* peer, rdpContext* context); + + typedef BOOL (*psPeerInitialize)(freerdp_peer* peer); +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("Use psPeerGetEventHandle instead", + typedef BOOL (*psPeerGetFileDescriptor)(freerdp_peer* peer, void** rfds, + int* rcount);) +#endif + typedef HANDLE (*psPeerGetEventHandle)(freerdp_peer* peer); + typedef DWORD (*psPeerGetEventHandles)(freerdp_peer* peer, HANDLE* events, DWORD count); + typedef HANDLE (*psPeerGetReceiveEventHandle)(freerdp_peer* peer); + typedef BOOL (*psPeerCheckFileDescriptor)(freerdp_peer* peer); + typedef BOOL (*psPeerIsWriteBlocked)(freerdp_peer* peer); + typedef int (*psPeerDrainOutputBuffer)(freerdp_peer* peer); + typedef BOOL (*psPeerHasMoreToRead)(freerdp_peer* peer); + typedef BOOL (*psPeerClose)(freerdp_peer* peer); + typedef void (*psPeerDisconnect)(freerdp_peer* peer); + typedef BOOL (*psPeerRemoteCredentials)(freerdp_peer* peer, KERB_TICKET_LOGON* logonCreds, + MSV1_0_SUPPLEMENTAL_CREDENTIAL* suppCreds); + typedef BOOL (*psPeerCapabilities)(freerdp_peer* peer); + typedef BOOL (*psPeerPostConnect)(freerdp_peer* peer); + typedef BOOL (*psPeerActivate)(freerdp_peer* peer); + typedef BOOL (*psPeerLogon)(freerdp_peer* peer, const SEC_WINNT_AUTH_IDENTITY* identity, + BOOL automatic); + typedef BOOL (*psPeerSendServerRedirection)(freerdp_peer* peer, + const rdpRedirection* redirection); + typedef BOOL (*psPeerAdjustMonitorsLayout)(freerdp_peer* peer); + typedef BOOL (*psPeerClientCapabilities)(freerdp_peer* peer); + + typedef BOOL (*psPeerSendChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data, + size_t size); + typedef BOOL (*psPeerSendChannelPacket)(freerdp_peer* client, UINT16 channelId, + size_t totalSize, UINT32 flags, const BYTE* data, + size_t chunkSize); + typedef BOOL (*psPeerReceiveChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data, + size_t size, UINT32 flags, size_t totalSize); + + typedef HANDLE (*psPeerVirtualChannelOpen)(freerdp_peer* peer, const char* name, UINT32 flags); + typedef BOOL (*psPeerVirtualChannelClose)(freerdp_peer* peer, HANDLE hChannel); + typedef int (*psPeerVirtualChannelRead)(freerdp_peer* peer, HANDLE hChannel, BYTE* buffer, + UINT32 length); + typedef int (*psPeerVirtualChannelWrite)(freerdp_peer* peer, HANDLE hChannel, + const BYTE* buffer, UINT32 length); + typedef void* (*psPeerVirtualChannelGetData)(freerdp_peer* peer, HANDLE hChannel); + typedef int (*psPeerVirtualChannelSetData)(freerdp_peer* peer, HANDLE hChannel, void* data); + typedef BOOL (*psPeerSetState)(freerdp_peer* peer, CONNECTION_STATE state); + typedef BOOL (*psPeerReachedState)(freerdp_peer* peer, CONNECTION_STATE state); + + /** @brief the result of the license callback */ + typedef enum + { + LICENSE_CB_INTERNAL_ERROR, /** an internal error happened in the callback */ + LICENSE_CB_ABORT, /** licensing process failed, abort the connection */ + LICENSE_CB_IN_PROGRESS, /** incoming packet has been treated, we're waiting for further + packets to complete the workflow */ + LICENSE_CB_COMPLETED /** the licensing workflow has completed, go to next step */ + } LicenseCallbackResult; + + typedef LicenseCallbackResult (*psPeerLicenseCallback)(freerdp_peer* peer, wStream* s); + + struct rdp_freerdp_peer + { + ALIGN64 rdpContext* context; + + ALIGN64 int sockfd; + ALIGN64 char hostname[50]; + +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("Use rdpContext::update instead", ALIGN64 rdpUpdate* update;) + WINPR_DEPRECATED_VAR("Use rdpContext::settings instead", ALIGN64 rdpSettings* settings;) + WINPR_DEPRECATED_VAR("Use rdpContext::autodetect instead", + ALIGN64 rdpAutoDetect* autodetect;) +#else + UINT64 reservedX[3]; +#endif + + ALIGN64 void* ContextExtra; + ALIGN64 size_t ContextSize; + ALIGN64 psPeerContextNew ContextNew; + ALIGN64 psPeerContextFree ContextFree; + + ALIGN64 psPeerInitialize Initialize; +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("Use freerdp_peer::GetEventHandle instead", + ALIGN64 psPeerGetFileDescriptor GetFileDescriptor;) +#else + UINT64 reserved; +#endif + ALIGN64 psPeerGetEventHandle GetEventHandle; + ALIGN64 psPeerGetReceiveEventHandle GetReceiveEventHandle; + ALIGN64 psPeerCheckFileDescriptor CheckFileDescriptor; + ALIGN64 psPeerClose Close; + ALIGN64 psPeerDisconnect Disconnect; + + ALIGN64 psPeerCapabilities Capabilities; + ALIGN64 psPeerPostConnect PostConnect; + ALIGN64 psPeerActivate Activate; + ALIGN64 psPeerLogon Logon; + + ALIGN64 psPeerSendServerRedirection SendServerRedirection; + + ALIGN64 psPeerSendChannelData SendChannelData; + ALIGN64 psPeerReceiveChannelData ReceiveChannelData; + + ALIGN64 psPeerVirtualChannelOpen VirtualChannelOpen; + ALIGN64 psPeerVirtualChannelClose VirtualChannelClose; + ALIGN64 psPeerVirtualChannelRead VirtualChannelRead; + ALIGN64 psPeerVirtualChannelWrite VirtualChannelWrite; + ALIGN64 psPeerVirtualChannelGetData VirtualChannelGetData; + ALIGN64 psPeerVirtualChannelSetData VirtualChannelSetData; + + ALIGN64 int pId; + ALIGN64 UINT32 ack_frame_id; + ALIGN64 BOOL local; + ALIGN64 BOOL connected; + ALIGN64 BOOL activated; + ALIGN64 BOOL authenticated; + ALIGN64 SEC_WINNT_AUTH_IDENTITY identity; + + ALIGN64 psPeerIsWriteBlocked IsWriteBlocked; + ALIGN64 psPeerDrainOutputBuffer DrainOutputBuffer; + ALIGN64 psPeerHasMoreToRead HasMoreToRead; + ALIGN64 psPeerGetEventHandles GetEventHandles; + ALIGN64 psPeerAdjustMonitorsLayout AdjustMonitorsLayout; + ALIGN64 psPeerClientCapabilities ClientCapabilities; +#if defined(WITH_FREERDP_DEPRECATED) + WINPR_DEPRECATED_VAR("Use freerdp_peer::SspiNtlmHashCallback instead", + ALIGN64 psPeerComputeNtlmHash ComputeNtlmHash;) +#else + UINT64 reserved2; +#endif + ALIGN64 psPeerLicenseCallback LicenseCallback; + + ALIGN64 psPeerSendChannelPacket SendChannelPacket; + + /** + * @brief SetState Function pointer allowing to manually set the state of the + * internal state machine. + * + * This is useful if certain parts of a RDP connection must be skipped (e.g. + * when replaying a RDP connection dump the authentication/negotiate parts + * must be skipped) + * + * \note Must be called after \b Initialize as that also modifies the state. + */ + ALIGN64 psPeerSetState SetState; + ALIGN64 psPeerReachedState ReachedState; + ALIGN64 psSspiNtlmHashCallback SspiNtlmHashCallback; + /** + * @brief RemoteCredentials Function pointer that will be called when remote + * credentials guard are used by the peer and we receive the logonCreds (kerberos) + * and supplementary creds (NTLM). + */ + ALIGN64 psPeerRemoteCredentials RemoteCredentials; + }; + + FREERDP_API void freerdp_peer_context_free(freerdp_peer* client); + + FREERDP_API BOOL freerdp_peer_context_new(freerdp_peer* client); + FREERDP_API BOOL freerdp_peer_context_new_ex(freerdp_peer* client, const rdpSettings* settings); + + FREERDP_API const char* freerdp_peer_os_major_type_string(freerdp_peer* client); + FREERDP_API const char* freerdp_peer_os_minor_type_string(freerdp_peer* client); + + FREERDP_API void freerdp_peer_free(freerdp_peer* client); + + WINPR_ATTR_MALLOC(freerdp_peer_free, 1) + FREERDP_API freerdp_peer* freerdp_peer_new(int sockfd); + + FREERDP_API BOOL freerdp_peer_set_local_and_hostname(freerdp_peer* client, + const struct sockaddr_storage* peer_addr); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_PEER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/pointer.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/pointer.h new file mode 100644 index 0000000000000000000000000000000000000000..351c02134bd78f540d5036b08eeb9e3c0afd33c4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/pointer.h @@ -0,0 +1,118 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Pointer Updates Interface API + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UPDATE_POINTER_H +#define FREERDP_UPDATE_POINTER_H + +#include + +#define PTR_MSG_TYPE_SYSTEM 0x0001 +#define PTR_MSG_TYPE_POSITION 0x0003 +#define PTR_MSG_TYPE_COLOR 0x0006 +#define PTR_MSG_TYPE_CACHED 0x0007 +#define PTR_MSG_TYPE_POINTER 0x0008 +#define PTR_MSG_TYPE_POINTER_LARGE 0x0009 + +#define SYSPTR_NULL 0x00000000 +#define SYSPTR_DEFAULT 0x00007F00 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 xPos; + UINT32 yPos; + } POINTER_POSITION_UPDATE; + + typedef struct + { + UINT32 type; + } POINTER_SYSTEM_UPDATE; + + typedef struct + { + UINT16 cacheIndex; + UINT16 hotSpotX; + UINT16 hotSpotY; + UINT16 width; + UINT16 height; + UINT16 lengthAndMask; + UINT16 lengthXorMask; + BYTE* xorMaskData; + BYTE* andMaskData; + } POINTER_COLOR_UPDATE; + + typedef struct + { + UINT16 xorBpp; + UINT16 cacheIndex; + UINT16 hotSpotX; + UINT16 hotSpotY; + UINT16 width; + UINT16 height; + UINT32 lengthAndMask; + UINT32 lengthXorMask; + BYTE* xorMaskData; + BYTE* andMaskData; + } POINTER_LARGE_UPDATE; + + typedef struct + { + UINT32 xorBpp; + POINTER_COLOR_UPDATE colorPtrAttr; + } POINTER_NEW_UPDATE; + + typedef struct + { + UINT32 cacheIndex; + } POINTER_CACHED_UPDATE; + + typedef BOOL (*pPointerPosition)(rdpContext* context, + const POINTER_POSITION_UPDATE* pointer_position); + typedef BOOL (*pPointerSystem)(rdpContext* context, + const POINTER_SYSTEM_UPDATE* pointer_system); + typedef BOOL (*pPointerColor)(rdpContext* context, const POINTER_COLOR_UPDATE* pointer_color); + typedef BOOL (*pPointerNew)(rdpContext* context, const POINTER_NEW_UPDATE* pointer_new); + typedef BOOL (*pPointerCached)(rdpContext* context, + const POINTER_CACHED_UPDATE* pointer_cached); + typedef BOOL (*pPointerLarge)(rdpContext* context, const POINTER_LARGE_UPDATE* pointer_large); + + struct rdp_pointer_update + { + rdpContext* context; /* 0 */ + UINT32 paddingA[16 - 1]; /* 1 */ + + pPointerPosition PointerPosition; /* 16 */ + pPointerSystem PointerSystem; /* 17 */ + pPointerColor PointerColor; /* 18 */ + pPointerNew PointerNew; /* 19 */ + pPointerCached PointerCached; /* 20 */ + pPointerLarge PointerLarge; /* 21 */ + UINT32 paddingB[32 - 22]; /* 22 */ + }; + typedef struct rdp_pointer_update rdpPointerUpdate; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UPDATE_POINTER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/primary.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/primary.h new file mode 100644 index 0000000000000000000000000000000000000000..77f3b399c2a66bcb7c3701e4f139e2d015eda491 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/primary.h @@ -0,0 +1,481 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Primary Drawing Orders Interface API + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UPDATE_PRIMARY_H +#define FREERDP_UPDATE_PRIMARY_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 cacheIndex; + INT16 x; + INT16 y; + UINT32 cx; + UINT32 cy; + UINT32 cb; + BYTE* aj; + } GLYPH_DATA; + + typedef struct + { + UINT32 cacheIndex; + INT32 x; + INT32 y; + UINT32 cx; + UINT32 cy; + UINT32 cb; + BYTE* aj; + } GLYPH_DATA_V2; + +#define BACKMODE_TRANSPARENT 0x0001 +#define BACKMODE_OPAQUE 0x0002 + +struct rdp_bounds +{ + INT32 left; + INT32 top; + INT32 right; + INT32 bottom; +}; +typedef struct rdp_bounds rdpBounds; + +struct rdp_brush +{ + UINT32 x; + UINT32 y; + UINT32 bpp; + UINT32 style; + UINT32 hatch; + UINT32 index; + BYTE* data; + BYTE p8x8[8]; +}; +typedef struct rdp_brush rdpBrush; + +typedef struct +{ + UINT32 controlFlags; + UINT32 orderType; + UINT32 fieldFlags; + UINT32 boundsFlags; + rdpBounds bounds; + BOOL deltaCoordinates; +} ORDER_INFO; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; +} DSTBLT_ORDER; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; + UINT32 backColor; + UINT32 foreColor; + rdpBrush brush; +} PATBLT_ORDER; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; + INT32 nXSrc; + INT32 nYSrc; +} SCRBLT_ORDER; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 color; +} OPAQUE_RECT_ORDER; + +typedef struct +{ + INT32 srcLeft; + INT32 srcTop; + INT32 srcRight; + INT32 srcBottom; + UINT32 bitmapId; +} DRAW_NINE_GRID_ORDER; + +typedef struct +{ + INT32 left; + INT32 top; + INT32 width; + INT32 height; +} DELTA_RECT; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; + UINT32 numRectangles; + UINT32 cbData; + DELTA_RECT rectangles[45]; +} MULTI_DSTBLT_ORDER; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; + UINT32 backColor; + UINT32 foreColor; + rdpBrush brush; + UINT32 numRectangles; + UINT32 cbData; + DELTA_RECT rectangles[45]; +} MULTI_PATBLT_ORDER; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; + INT32 nXSrc; + INT32 nYSrc; + UINT32 numRectangles; + UINT32 cbData; + DELTA_RECT rectangles[45]; +} MULTI_SCRBLT_ORDER; + +typedef struct +{ + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 color; + UINT32 numRectangles; + UINT32 cbData; + DELTA_RECT rectangles[45]; +} MULTI_OPAQUE_RECT_ORDER; + +typedef struct +{ + INT32 srcLeft; + INT32 srcTop; + INT32 srcRight; + INT32 srcBottom; + UINT32 bitmapId; + UINT32 nDeltaEntries; + UINT32 cbData; + DELTA_RECT rectangles[45]; +} MULTI_DRAW_NINE_GRID_ORDER; + +typedef struct +{ + UINT32 backMode; + INT32 nXStart; + INT32 nYStart; + INT32 nXEnd; + INT32 nYEnd; + UINT32 backColor; + UINT32 bRop2; + UINT32 penStyle; + UINT32 penWidth; + UINT32 penColor; +} LINE_TO_ORDER; + +typedef struct +{ + INT32 x; + INT32 y; +} DELTA_POINT; + +typedef struct +{ + INT32 xStart; + INT32 yStart; + UINT32 bRop2; + UINT32 penColor; + UINT32 numDeltaEntries; + UINT32 cbData; + DELTA_POINT* points; +} POLYLINE_ORDER; + +typedef struct +{ + UINT32 cacheId; + UINT32 colorIndex; + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; + INT32 nXSrc; + INT32 nYSrc; + UINT32 cacheIndex; + rdpBitmap* bitmap; +} MEMBLT_ORDER; + +typedef struct +{ + UINT32 cacheId; + UINT32 colorIndex; + INT32 nLeftRect; + INT32 nTopRect; + INT32 nWidth; + INT32 nHeight; + UINT32 bRop; + INT32 nXSrc; + INT32 nYSrc; + UINT32 backColor; + UINT32 foreColor; + rdpBrush brush; + UINT32 cacheIndex; + rdpBitmap* bitmap; +} MEM3BLT_ORDER; + +typedef struct +{ + UINT32 savedBitmapPosition; + INT32 nLeftRect; + INT32 nTopRect; + INT32 nRightRect; + INT32 nBottomRect; + UINT32 operation; +} SAVE_BITMAP_ORDER; + +typedef struct +{ + UINT32 index; + UINT32 delta; +} GLYPH_FRAGMENT_INDEX; + +typedef struct +{ + UINT32 operation; + UINT32 index; + UINT32 size; + UINT32 nindices; + GLYPH_FRAGMENT_INDEX* indices; +} GLYPH_FRAGMENT; + +typedef struct +{ + UINT32 cacheId; + UINT32 flAccel; + UINT32 ulCharInc; + UINT32 fOpRedundant; + UINT32 backColor; + UINT32 foreColor; + INT32 bkLeft; + INT32 bkTop; + INT32 bkRight; + INT32 bkBottom; + INT32 opLeft; + INT32 opTop; + INT32 opRight; + INT32 opBottom; + rdpBrush brush; + INT32 x; + INT32 y; + UINT32 cbData; + BYTE data[256]; +} GLYPH_INDEX_ORDER; + +typedef struct +{ + UINT32 cacheId; + UINT32 flAccel; + UINT32 ulCharInc; + UINT32 backColor; + UINT32 foreColor; + INT32 bkLeft; + INT32 bkTop; + INT32 bkRight; + INT32 bkBottom; + INT32 opLeft; + INT32 opTop; + INT32 opRight; + INT32 opBottom; + BOOL opaqueRect; + INT32 x; + INT32 y; + UINT32 cbData; + BYTE data[256]; +} FAST_INDEX_ORDER; + +typedef struct +{ + UINT32 cacheId; + UINT32 flAccel; + UINT32 ulCharInc; + UINT32 backColor; + UINT32 foreColor; + INT32 bkLeft; + INT32 bkTop; + INT32 bkRight; + INT32 bkBottom; + INT32 opLeft; + INT32 opTop; + INT32 opRight; + INT32 opBottom; + INT32 x; + INT32 y; + UINT32 cbData; + BYTE data[256]; + GLYPH_DATA_V2 glyphData; +} FAST_GLYPH_ORDER; + +typedef struct +{ + INT32 xStart; + INT32 yStart; + UINT32 bRop2; + UINT32 fillMode; + UINT32 brushColor; + UINT32 numPoints; + UINT32 cbData; + DELTA_POINT* points; +} POLYGON_SC_ORDER; + +typedef struct +{ + INT32 xStart; + INT32 yStart; + UINT32 bRop2; + UINT32 backMode; + UINT32 fillMode; + UINT32 backColor; + UINT32 foreColor; + rdpBrush brush; + UINT32 numPoints; + UINT32 cbData; + DELTA_POINT* points; +} POLYGON_CB_ORDER; + +typedef struct +{ + INT32 leftRect; + INT32 topRect; + INT32 rightRect; + INT32 bottomRect; + UINT32 bRop2; + UINT32 fillMode; + UINT32 color; +} ELLIPSE_SC_ORDER; + +typedef struct +{ + INT32 leftRect; + INT32 topRect; + INT32 rightRect; + INT32 bottomRect; + UINT32 bRop2; + UINT32 fillMode; + UINT32 backColor; + UINT32 foreColor; + rdpBrush brush; +} ELLIPSE_CB_ORDER; + +typedef BOOL (*pDstBlt)(rdpContext* context, const DSTBLT_ORDER* dstblt); +typedef BOOL (*pPatBlt)(rdpContext* context, PATBLT_ORDER* patblt); +typedef BOOL (*pScrBlt)(rdpContext* context, const SCRBLT_ORDER* scrblt); +typedef BOOL (*pOpaqueRect)(rdpContext* context, const OPAQUE_RECT_ORDER* opaque_rect); +typedef BOOL (*pDrawNineGrid)(rdpContext* context, const DRAW_NINE_GRID_ORDER* draw_nine_grid); +typedef BOOL (*pMultiDstBlt)(rdpContext* context, const MULTI_DSTBLT_ORDER* multi_dstblt); +typedef BOOL (*pMultiPatBlt)(rdpContext* context, const MULTI_PATBLT_ORDER* multi_patblt); +typedef BOOL (*pMultiScrBlt)(rdpContext* context, const MULTI_SCRBLT_ORDER* multi_scrblt); +typedef BOOL (*pMultiOpaqueRect)(rdpContext* context, + const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); +typedef BOOL (*pMultiDrawNineGrid)(rdpContext* context, + const MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); +typedef BOOL (*pLineTo)(rdpContext* context, const LINE_TO_ORDER* line_to); +typedef BOOL (*pPolyline)(rdpContext* context, const POLYLINE_ORDER* polyline); +typedef BOOL (*pMemBlt)(rdpContext* context, MEMBLT_ORDER* memblt); +typedef BOOL (*pMem3Blt)(rdpContext* context, MEM3BLT_ORDER* memblt); +typedef BOOL (*pSaveBitmap)(rdpContext* context, const SAVE_BITMAP_ORDER* save_bitmap); +typedef BOOL (*pGlyphIndex)(rdpContext* context, GLYPH_INDEX_ORDER* glyph_index); +typedef BOOL (*pFastIndex)(rdpContext* context, const FAST_INDEX_ORDER* fast_index); +typedef BOOL (*pFastGlyph)(rdpContext* context, const FAST_GLYPH_ORDER* fast_glyph); +typedef BOOL (*pPolygonSC)(rdpContext* context, const POLYGON_SC_ORDER* polygon_sc); +typedef BOOL (*pPolygonCB)(rdpContext* context, POLYGON_CB_ORDER* polygon_cb); +typedef BOOL (*pEllipseSC)(rdpContext* context, const ELLIPSE_SC_ORDER* ellipse_sc); +typedef BOOL (*pEllipseCB)(rdpContext* context, const ELLIPSE_CB_ORDER* ellipse_cb); +typedef BOOL (*pOrderInfo)(rdpContext* context, const ORDER_INFO* order_info, + const char* order_name); + +struct rdp_primary_update +{ + rdpContext* context; /* 0 */ + UINT32 paddingA[16 - 1]; /* 1 */ + + pDstBlt DstBlt; /* 16 */ + pPatBlt PatBlt; /* 17 */ + pScrBlt ScrBlt; /* 18 */ + pOpaqueRect OpaqueRect; /* 19 */ + pDrawNineGrid DrawNineGrid; /* 20 */ + pMultiDstBlt MultiDstBlt; /* 21 */ + pMultiPatBlt MultiPatBlt; /* 22 */ + pMultiScrBlt MultiScrBlt; /* 23 */ + pMultiOpaqueRect MultiOpaqueRect; /* 24 */ + pMultiDrawNineGrid MultiDrawNineGrid; /* 25 */ + pLineTo LineTo; /* 26 */ + pPolyline Polyline; /* 27 */ + pMemBlt MemBlt; /* 28 */ + pMem3Blt Mem3Blt; /* 29 */ + pSaveBitmap SaveBitmap; /* 30 */ + pGlyphIndex GlyphIndex; /* 31 */ + pFastIndex FastIndex; /* 32 */ + pFastGlyph FastGlyph; /* 33 */ + pPolygonSC PolygonSC; /* 34 */ + pPolygonCB PolygonCB; /* 35 */ + pEllipseSC EllipseSC; /* 36 */ + pEllipseCB EllipseCB; /* 37 */ + /* Statistics callback */ + pOrderInfo OrderInfo; /* 38 */ + UINT32 paddingB[48 - 39]; /* 39 */ +}; +typedef struct rdp_primary_update rdpPrimaryUpdate; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UPDATE_PRIMARY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/primitives.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/primitives.h new file mode 100644 index 0000000000000000000000000000000000000000..c45212ed9ab1ebfe0fdb780d36970bf48c7d9a21 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/primitives.h @@ -0,0 +1,309 @@ +/* primitives.h + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. Algorithms used by + * this code may be covered by patents by HP, Microsoft, or other parties. + */ + +#ifdef __GNUC__ +#pragma once +#endif + +#ifndef FREERDP_PRIMITIVES_H +#define FREERDP_PRIMITIVES_H + +#include + +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef INT32 pstatus_t; /* match IppStatus. */ +#define PRIMITIVES_SUCCESS (0) /* match ippStsNoErr */ + +/* Simple macro for address of an x,y location in 2d 4-byte memory block */ +#define PIXMAP4_ADDR(_dst_, _x_, _y_, _span_) \ + ((void*)(((BYTE*)(_dst_)) + (((_x_) + (_y_) * (_span_)) << 2))) + +#define PRIM_X86_MMX_AVAILABLE (1U << 0) +#define PRIM_X86_3DNOW_AVAILABLE (1U << 1) +#define PRIM_X86_3DNOW_PREFETCH_AVAILABLE (1U << 2) +#define PRIM_X86_SSE_AVAILABLE (1U << 3) +#define PRIM_X86_SSE2_AVAILABLE (1U << 4) +#define PRIM_X86_SSE3_AVAILABLE (1U << 5) +#define PRIM_X86_SSSE3_AVAILABLE (1U << 6) +#define PRIM_X86_SSE41_AVAILABLE (1U << 7) +#define PRIM_X86_SSE42_AVAILABLE (1U << 8) +#define PRIM_X86_AVX_AVAILABLE (1U << 9) +#define PRIM_X86_FMA_AVAILABLE (1U << 10) +#define PRIM_X86_AVX_AES_AVAILABLE (1U << 11) +#define PRIM_X86_AVX2_AVAILABLE (1U << 12) + +#define PRIM_ARM_VFP1_AVAILABLE (1U << 0) +#define PRIM_ARM_VFP2_AVAILABLE (1U << 1) +#define PRIM_ARM_VFP3_AVAILABLE (1U << 2) +#define PRIM_ARM_VFP4_AVAILABLE (1U << 3) +#define PRIM_ARM_FPA_AVAILABLE (1U << 4) +#define PRIM_ARM_FPE_AVAILABLE (1U << 5) +#define PRIM_ARM_IWMMXT_AVAILABLE (1U << 6) +#define PRIM_ARM_NEON_AVAILABLE (1U << 7) + +/** @brief flags of primitives */ +enum +{ + PRIM_FLAGS_HAVE_EXTCPU = (1U << 0), /* primitives are using CPU extensions */ + PRIM_FLAGS_HAVE_EXTGPU = (1U << 1), /* primitives are using the GPU */ +}; + +typedef struct +{ + UINT32 width; + UINT32 height; +} prim_size_t; + +typedef enum +{ + AVC444_LUMA, + AVC444_CHROMAv1, + AVC444_CHROMAv2 +} avc444_frame_type; + +/* Function prototypes for all of the supported primitives. */ +typedef pstatus_t (*__copy_t)(const void* WINPR_RESTRICT pSrc, void* WINPR_RESTRICT pDst, + INT32 bytes); +typedef pstatus_t (*__copy_8u_t)(const BYTE* WINPR_RESTRICT pSrc, BYTE* WINPR_RESTRICT pDst, + INT32 len); +typedef pstatus_t (*__copy_8u_AC4r_t)(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep, /* bytes */ + BYTE* WINPR_RESTRICT pDst, INT32 dstStep, /* bytes */ + INT32 width, INT32 height); /* pixels */ +typedef pstatus_t (*__set_8u_t)(BYTE val, BYTE* WINPR_RESTRICT pDst, UINT32 len); +typedef pstatus_t (*__set_32s_t)(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 len); +typedef pstatus_t (*__set_32u_t)(UINT32 val, UINT32* WINPR_RESTRICT pDst, UINT32 len); +typedef pstatus_t (*__zero_t)(void* WINPR_RESTRICT pDst, size_t bytes); +typedef pstatus_t (*__alphaComp_argb_t)(const BYTE* WINPR_RESTRICT pSrc1, UINT32 src1Step, + const BYTE* WINPR_RESTRICT pSrc2, UINT32 src2Step, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, UINT32 width, + UINT32 height); +typedef pstatus_t (*__add_16s_t)(const INT16* WINPR_RESTRICT pSrc1, + const INT16* WINPR_RESTRICT pSrc2, INT16* WINPR_RESTRICT pDst, + UINT32 len); +/** + * @brief Add INT16 from pSrcDst2 to pSrcDst1 and store in both arrays + * @param pSrcDst1 A pointer to the array of INT16 to add to + * @param pSrcDst2 A pointer to the array of INT16 to add to + * @param len The number of INT16 in the arrays + * @return \b <=0 for failure, success otherwise + * @since version 3.6.0 + */ +typedef pstatus_t (*__add_16s_inplace_t)(INT16* WINPR_RESTRICT pSrcDst1, + INT16* WINPR_RESTRICT pSrcDst2, UINT32 len); + +/** + * @brief Copy (sub)image data without overlapping + * + * @param pDstData The destination image buffer + * @param DstFormat The destination image format @ref PIXEL_FORMAT + * @param nDstStep The destination image line width in bytes (including padding) + * @param nXDst The X coordinate to start copying to + * @param nYDst The Y coordinate to start copying to + * @param nWidth The width in pixels to copy + * @param nHeight The height in pixels to copy + * @param pSrcData The source image buffer + * @param SrcFormat The source image format @ref PIXEL_FORMAT + * @param nSrcStep The source image line with in bytes (including padding) + * @param nXSrc The X coordinate to start copying from + * @param nYSrc The Y coordinate to start copying from + * @param palette A color palette for 8 bit colors + * @param flags Copy flags @ref FREERDP_IMAGE_FLAGS + * @return \b <=0 for failure, success otherwise + * @since version 3.6.0 + */ +typedef pstatus_t (*__copy_no_overlap_t)(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, + UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, + DWORD SrcFormat, UINT32 nSrcStep, UINT32 nXSrc, + UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette, + UINT32 flags); +typedef pstatus_t (*__lShiftC_16s_inplace_t)(INT16* WINPR_RESTRICT pSrcDst, UINT32 val, UINT32 len); +typedef pstatus_t (*__lShiftC_16s_t)(const INT16* pSrc, UINT32 val, INT16* pSrcDst, UINT32 len); +typedef pstatus_t (*__lShiftC_16u_t)(const UINT16* pSrc, UINT32 val, UINT16* pSrcDst, UINT32 len); +typedef pstatus_t (*__rShiftC_16s_t)(const INT16* pSrc, UINT32 val, INT16* pSrcDst, UINT32 len); +typedef pstatus_t (*__rShiftC_16u_t)(const UINT16* pSrc, UINT32 val, UINT16* pSrcDst, UINT32 len); +typedef pstatus_t (*__shiftC_16s_t)(const INT16* pSrc, INT32 val, INT16* pSrcDst, UINT32 len); +typedef pstatus_t (*__shiftC_16u_t)(const UINT16* pSrc, INT32 val, UINT16* pSrcDst, UINT32 len); +typedef pstatus_t (*__sign_16s_t)(const INT16* pSrc, INT16* pSrcDst, UINT32 len); +typedef pstatus_t (*__yCbCrToRGB_16s8u_P3AC4R_t)(const INT16* WINPR_RESTRICT pSrc[3], + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__yCbCrToRGB_16s16s_P3P3_t)(const INT16* WINPR_RESTRICT pSrc[3], INT32 srcStep, + INT16* WINPR_RESTRICT pDst[3], INT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__RGBToYCbCr_16s16s_P3P3_t)(const INT16* WINPR_RESTRICT pSrc[3], INT32 srcStep, + INT16* WINPR_RESTRICT pDst[3], INT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__RGBToRGB_16s8u_P3AC4R_t)(const INT16* WINPR_RESTRICT pSrc[3], UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__YCoCgToRGB_8u_AC4R_t)(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 DstFormat, + INT32 dstStep, UINT32 width, UINT32 height, UINT8 shift, + BOOL withAlpha); +typedef pstatus_t (*__RGB565ToARGB_16u32u_C3C4_t)(const UINT16* WINPR_RESTRICT pSrc, INT32 srcStep, + UINT32* WINPR_RESTRICT pDst, INT32 dstStep, + UINT32 width, UINT32 height, UINT32 format); +typedef pstatus_t (*__YUV420ToRGB_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__YUV444ToRGB_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__RGBToYUV420_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3], + const UINT32 dstStep[3], + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__RGBToYUV444_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3], + const UINT32 dstStep[3], + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__YUV420CombineToYUV444_t)(avc444_frame_type type, + const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], UINT32 nWidth, + UINT32 nHeight, BYTE* WINPR_RESTRICT pDst[3], + const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi); +typedef pstatus_t (*__YUV444SplitToYUV420_t)( + const BYTE* WINPR_RESTRICT pSrc[3], const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pMainDst[3], + const UINT32 dstMainStep[3], BYTE* WINPR_RESTRICT pAuxDst[3], const UINT32 srcAuxStep[3], + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__RGBToAVC444YUV_t)(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pMainDst[3], + const UINT32 dstMainStep[3], + BYTE* WINPR_RESTRICT pAuxDst[3], const UINT32 dstAuxStep[3], + const prim_size_t* WINPR_RESTRICT roi); +typedef pstatus_t (*__andC_32u_t)(const UINT32* WINPR_RESTRICT pSrc, UINT32 val, + UINT32* WINPR_RESTRICT pDst, INT32 len); +typedef pstatus_t (*__orC_32u_t)(const UINT32* WINPR_RESTRICT pSrc, UINT32 val, + UINT32* WINPR_RESTRICT pDst, INT32 len); +typedef pstatus_t (*primitives_uninit_t)(void); + +typedef struct +{ + /* Memory-to-memory copy routines */ + __copy_t copy; /* memcpy/memmove, basically */ + __copy_8u_t copy_8u; /* more strongly typed */ + __copy_8u_AC4r_t copy_8u_AC4r; /* pixel copy function */ + /* Memory setting routines */ + __set_8u_t set_8u; /* memset, basically */ + __set_32s_t set_32s; + __set_32u_t set_32u; + __zero_t zero; /* bzero or faster */ + /* Arithmetic functions */ + __add_16s_t add_16s; + /* And/or */ + __andC_32u_t andC_32u; + __orC_32u_t orC_32u; + /* Shifts */ + __lShiftC_16s_t lShiftC_16s; + __lShiftC_16u_t lShiftC_16u; + __rShiftC_16s_t rShiftC_16s; + __rShiftC_16u_t rShiftC_16u; + __shiftC_16s_t shiftC_16s; + __shiftC_16u_t shiftC_16u; + /* Alpha Composition */ + __alphaComp_argb_t alphaComp_argb; + /* Sign */ + __sign_16s_t sign_16s; + /* Color conversions */ + __yCbCrToRGB_16s8u_P3AC4R_t yCbCrToRGB_16s8u_P3AC4R; + __yCbCrToRGB_16s16s_P3P3_t yCbCrToRGB_16s16s_P3P3; + __RGBToYCbCr_16s16s_P3P3_t RGBToYCbCr_16s16s_P3P3; + __RGBToRGB_16s8u_P3AC4R_t RGBToRGB_16s8u_P3AC4R; + __YCoCgToRGB_8u_AC4R_t YCoCgToRGB_8u_AC4R; + __YUV420ToRGB_8u_P3AC4R_t YUV420ToRGB_8u_P3AC4R; + __RGBToYUV420_8u_P3AC4R_t RGBToYUV420_8u_P3AC4R; + __RGBToYUV444_8u_P3AC4R_t RGBToYUV444_8u_P3AC4R; + __YUV420CombineToYUV444_t YUV420CombineToYUV444; + __YUV444SplitToYUV420_t YUV444SplitToYUV420; + __YUV444ToRGB_8u_P3AC4R_t YUV444ToRGB_8u_P3AC4R; + __RGBToAVC444YUV_t RGBToAVC444YUV; + __RGBToAVC444YUV_t RGBToAVC444YUVv2; + /* flags */ + DWORD flags; + primitives_uninit_t uninit; + + /** \brief Do vecotor addition, store result in both input buffers + * pSrcDst1 = pSrcDst2 = pSrcDst1 + pSrcDst2 + */ + __add_16s_inplace_t add_16s_inplace; /** @since version 3.6.0 */ + __lShiftC_16s_inplace_t lShiftC_16s_inplace; /** @since version 3.6.0 */ + __copy_no_overlap_t copy_no_overlap; /** @since version 3.6.0 */ +} primitives_t; + +typedef enum +{ + PRIMITIVES_PURE_SOFT, /** use generic software implementation */ + PRIMITIVES_ONLY_CPU, /** use generic software or cpu optimized routines */ + PRIMITIVES_ONLY_GPU, /** use opencl optimized routines */ + PRIMITIVES_AUTODETECT /** detect the best routines */ +} primitive_hints; + + FREERDP_API primitives_t* primitives_get(void); + FREERDP_API void primitives_set_hints(primitive_hints hints); + FREERDP_API primitive_hints primitives_get_hints(void); + FREERDP_API primitives_t* primitives_get_generic(void); + FREERDP_API DWORD primitives_flags(primitives_t* p); + FREERDP_API BOOL primitives_init(primitives_t* p, primitive_hints hints); + FREERDP_API void primitives_uninit(void); + + /** @brief get a specific primitives implementation + * + * This will try to return the primitives implementation suggested by \b type + * If that does not exist or does not work on the platform any other (e.g. usually pure + * software) is returned + * + * @param type the type of primitives desired. + * @return A primitive implementation matching the hint closest or \b NULL in case of failure. + * @since version 3.11.0 + */ + FREERDP_API primitives_t* primitives_get_by_type(primitive_hints type); + + /** @brief stringify a \b avc444_frame_type + * + * @param type the type to stringify + * @return A string representation of \b type + * @since version 3.11.0 + */ + FREERDP_API const char* primitives_avc444_frame_type_str(avc444_frame_type type); + + /** @brief convert a hint to a string + * + * @param hint the hint to stringify + * @return the string representation of the hint + * @since version 3.11.0 + */ + FREERDP_API const char* primtives_hint_str(primitive_hints hint); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_PRIMITIVES_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/rail.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/rail.h new file mode 100644 index 0000000000000000000000000000000000000000..223aa0b4c67fcc4d948fdfde72291256a194338f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/rail.h @@ -0,0 +1,602 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Applications Integrated Locally (RAIL) + * + * Copyright 2011 Marc-Andre Moreau + * Copyright 2011 Roman Barabanov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_RAIL_GLOBAL_H +#define FREERDP_RAIL_GLOBAL_H + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define RAIL_SVC_CHANNEL_NAME "rail" + +/* DEPRECATED: RAIL PDU flags use the spec conformant naming with TS_ prefix */ +#if defined(WITH_FREERDP_DEPRECATED) +#define RAIL_EXEC_FLAG_EXPAND_WORKINGDIRECTORY 0x0001 +#define RAIL_EXEC_FLAG_TRANSLATE_FILES 0x0002 +#define RAIL_EXEC_FLAG_FILE 0x0004 +#define RAIL_EXEC_FLAG_EXPAND_ARGUMENTS 0x0008 +#endif + +/* RAIL PDU flags */ +#define TS_RAIL_EXEC_FLAG_EXPAND_WORKINGDIRECTORY 0x0001 +#define TS_RAIL_EXEC_FLAG_TRANSLATE_FILES 0x0002 +#define TS_RAIL_EXEC_FLAG_FILE 0x0004 +#define TS_RAIL_EXEC_FLAG_EXPAND_ARGUMENTS 0x0008 +#define TS_RAIL_EXEC_FLAG_APP_USER_MODEL_ID 0x0010 + +/* Notification Icon Balloon Tooltip */ +#define NIIF_NONE 0x00000000 +#define NIIF_INFO 0x00000001 +#define NIIF_WARNING 0x00000002 +#define NIIF_ERROR 0x00000003 +#define NIIF_NOSOUND 0x00000010 +#define NIIF_LARGE_ICON 0x00000020 + +/* Client Execute PDU Flags */ +#define RAIL_EXEC_FLAG_EXPAND_WORKING_DIRECTORY 0x0001 +#define RAIL_EXEC_FLAG_TRANSLATE_FILES 0x0002 +#define RAIL_EXEC_FLAG_FILE 0x0004 +#define RAIL_EXEC_FLAG_EXPAND_ARGUMENTS 0x0008 +#define RAIL_EXEC_FLAG_APP_USER_MODEL_ID 0x0010 + +/* Server Execute Result PDU */ +#define RAIL_EXEC_S_OK 0x0000 +#define RAIL_EXEC_E_HOOK_NOT_LOADED 0x0001 +#define RAIL_EXEC_E_DECODE_FAILED 0x0002 +#define RAIL_EXEC_E_NOT_IN_ALLOWLIST 0x0003 +#define RAIL_EXEC_E_FILE_NOT_FOUND 0x0005 +#define RAIL_EXEC_E_FAIL 0x0006 +#define RAIL_EXEC_E_SESSION_LOCKED 0x0007 + +/* DEPRECATED: Server System Parameters Update PDU + * use the spec conformant naming scheme from winpr/windows.h + */ +#define SPI_SET_SCREEN_SAVE_ACTIVE 0x00000011 +#define SPI_SET_SCREEN_SAVE_SECURE 0x00000077 + +/*Bit mask values for SPI_ parameters*/ +enum SPI_MASK +{ + SPI_MASK_SET_DRAG_FULL_WINDOWS = 0x00000001, + SPI_MASK_SET_KEYBOARD_CUES = 0x00000002, + SPI_MASK_SET_KEYBOARD_PREF = 0x00000004, + SPI_MASK_SET_MOUSE_BUTTON_SWAP = 0x00000008, + SPI_MASK_SET_WORK_AREA = 0x00000010, + SPI_MASK_DISPLAY_CHANGE = 0x00000020, + SPI_MASK_TASKBAR_POS = 0x00000040, + SPI_MASK_SET_HIGH_CONTRAST = 0x00000080, + SPI_MASK_SET_SCREEN_SAVE_ACTIVE = 0x00000100, + SPI_MASK_SET_SET_SCREEN_SAVE_SECURE = 0x00000200, + SPI_MASK_SET_CARET_WIDTH = 0x00000400, + SPI_MASK_SET_STICKY_KEYS = 0x00000800, + SPI_MASK_SET_TOGGLE_KEYS = 0x00001000, + SPI_MASK_SET_FILTER_KEYS = 0x00002000 +}; + +/* Client System Parameters Update PDU + * some are defined in winuser.h (winpr/windows.h wrapper) + */ +#define SPI_SET_DRAG_FULL_WINDOWS 0x00000025 +#define SPI_SET_KEYBOARD_CUES 0x0000100B +#define SPI_SET_KEYBOARD_PREF 0x00000045 +#define SPI_SET_MOUSE_BUTTON_SWAP 0x00000021 +#define SPI_SET_WORK_AREA 0x0000002F +#define SPI_DISPLAY_CHANGE 0x0000F001 +#define SPI_TASKBAR_POS 0x0000F000 +#define SPI_SET_HIGH_CONTRAST 0x00000043 + +/* Client System Command PDU */ +#define SC_SIZE 0xF000 +#define SC_MOVE 0xF010 +#define SC_MINIMIZE 0xF020 +#define SC_MAXIMIZE 0xF030 +#define SC_CLOSE 0xF060 +#define SC_KEYMENU 0xF100 +#define SC_RESTORE 0xF120 +#define SC_DEFAULT 0xF160 + +/* Client Notify Event PDU */ +#ifndef _WIN32 +#define WM_LBUTTONDOWN 0x00000201 +#define WM_LBUTTONUP 0x00000202 +#define WM_RBUTTONDOWN 0x00000204 +#define WM_RBUTTONUP 0x00000205 +#define WM_CONTEXTMENU 0x0000007b +#define WM_LBUTTONDBLCLK 0x00000203 +#define WM_RBUTTONDBLCLK 0x00000206 + +#define NIN_SELECT 0x00000400 +#define NIN_KEYSELECT 0x00000401 +#define NIN_BALLOONSHOW 0x00000402 +#define NIN_BALLOONHIDE 0x00000403 +#define NIN_BALLOONTIMEOUT 0x00000404 +#define NIN_BALLOONUSERCLICK 0x00000405 +#else +#include +#endif + +/* DEPRECATED: Client Information PDU + * use the spec conformant naming scheme TS_ below + */ +#define RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE 0x00000001 +#define RAIL_CLIENTSTATUS_AUTORECONNECT 0x00000002 + +/* Client Information PDU */ +typedef enum +{ + TS_RAIL_CLIENTSTATUS_ALLOWLOCALMOVESIZE = 0x00000001, + TS_RAIL_CLIENTSTATUS_AUTORECONNECT = 0x00000002, + TS_RAIL_CLIENTSTATUS_ZORDER_SYNC = 0x00000004, + TS_RAIL_CLIENTSTATUS_WINDOW_RESIZE_MARGIN_SUPPORTED = 0x00000010, + TS_RAIL_CLIENTSTATUS_HIGH_DPI_ICONS_SUPPORTED = 0x00000020, + TS_RAIL_CLIENTSTATUS_APPBAR_REMOTING_SUPPORTED = 0x00000040, + TS_RAIL_CLIENTSTATUS_POWER_DISPLAY_REQUEST_SUPPORTED = 0x00000080, + TS_RAIL_CLIENTSTATUS_GET_APPID_RESPONSE_EX_SUPPORTED = 0x00000100, + TS_RAIL_CLIENTSTATUS_BIDIRECTIONAL_CLOAK_SUPPORTED = 0x00000200, + TS_RAIL_CLIENTSTATUS_SUPPRESS_ICON_ORDERS = 0x00000400 +} CLIENT_INFO_PDU; + +/* Server Move/Size Start PDU */ +#define RAIL_WMSZ_LEFT 0x0001 +#define RAIL_WMSZ_RIGHT 0x0002 +#define RAIL_WMSZ_TOP 0x0003 +#define RAIL_WMSZ_TOPLEFT 0x0004 +#define RAIL_WMSZ_TOPRIGHT 0x0005 +#define RAIL_WMSZ_BOTTOM 0x0006 +#define RAIL_WMSZ_BOTTOMLEFT 0x0007 +#define RAIL_WMSZ_BOTTOMRIGHT 0x0008 +#define RAIL_WMSZ_MOVE 0x0009 +#define RAIL_WMSZ_KEYMOVE 0x000A +#define RAIL_WMSZ_KEYSIZE 0x000B + +/* Language Bar Information PDU */ +#define TF_SFT_SHOWNORMAL 0x00000001 +#define TF_SFT_DOCK 0x00000002 +#define TF_SFT_MINIMIZED 0x00000004 +#define TF_SFT_HIDDEN 0x00000008 +#define TF_SFT_NOTRANSPARENCY 0x00000010 +#define TF_SFT_LOWTRANSPARENCY 0x00000020 +#define TF_SFT_HIGHTRANSPARENCY 0x00000040 +#define TF_SFT_LABELS 0x00000080 +#define TF_SFT_NOLABELS 0x00000100 +#define TF_SFT_EXTRAICONSONMINIMIZED 0x00000200 +#define TF_SFT_NOEXTRAICONSONMINIMIZED 0x00000400 +#define TF_SFT_DESKBAND 0x00000800 + +/* DEPRECATED: Extended Handshake Flags + * use the spec conformant naming scheme TS_ below + */ +#define RAIL_ORDER_HANDSHAKEEX_FLAGS_HIDEF 0x00000001 +#define RAIL_ORDER_HANDSHAKE_EX_FLAGS_EXTENDED_SPI_SUPPORTED 0x00000002 +#define RAIL_ORDER_HANDSHAKE_EX_FLAGS_SNAP_ARRANGE_SUPPORTED 0x00000004 + +/* Extended Handshake Flags */ +typedef enum +{ + TS_RAIL_ORDER_HANDSHAKEEX_FLAGS_HIDEF = 0x00000001, + TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_EXTENDED_SPI_SUPPORTED = 0x00000002, + TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_SNAP_ARRANGE_SUPPORTED = 0x00000004, + TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_TEXT_SCALE_SUPPORTED = 0x00000008, + TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_CARET_BLINK_SUPPORTED = 0x00000010, + TS_RAIL_ORDER_HANDSHAKE_EX_FLAGS_EXTENDED_SPI_2_SUPPORTED = 0x00000020 +} EXTENDED_HANDSHAKE_FLAGS; +/* Language Profile Information Flags */ +#define TF_PROFILETYPE_INPUTPROCESSOR 0x00000001 +#define TF_PROFILETYPE_KEYBOARDLAYOUT 0x00000002 + +/* LanguageProfileCLSID and ProfileGUID */ +#ifndef _WIN32 +#define GUID_NULL \ + { \ + 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \ + } +#else +#include +#endif +#define GUID_MSIME_JPN \ + { \ + 0x03B5835F, 0xF03C, 0x411B, 0x9C, 0xE2, 0xAA, 0x23, 0xE1, 0x17, 0x1E, 0x36 \ + } +#define GUID_MSIME_KOR \ + { \ + 0xA028AE76, 0x01B1, 0x46C2, 0x99, 0xC4, 0xAC, 0xD9, 0x85, 0x8A, 0xE0, 0x02 \ + } +#define GUID_CHSIME \ + { \ + 0x81D4E9C9, 0x1D3B, 0x41BC, 0x9E, 0x6C, 0x4B, 0x40, 0xBF, 0x79, 0xE3, 0x5E \ + } +#define GUID_CHTIME \ + { \ + 0x531FDEBF, 0x9B4C, 0x4A43, 0xA2, 0xAA, 0x96, 0x0E, 0x8F, 0xCD, 0xC7, 0x32 \ + } +#define GUID_PROFILE_NEWPHONETIC \ + { \ + 0xB2F9C502, 0x1742, 0x11D4, 0x97, 0x90, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E \ + } +#define GUID_PROFILE_CHANGJIE \ + { \ + 0x4BDF9F03, 0xC7D3, 0x11D4, 0xB2, 0xAB, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E \ + } +#define GUID_PROFILE_QUICK \ + { \ + 0x6024B45F, 0x5C54, 0x11D4, 0xB9, 0x21, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E \ + } +#define GUID_PROFILE_CANTONESE \ + { \ + 0x0AEC109C, 0x7E96, 0x11D4, 0xB2, 0xEF, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E \ + } +#define GUID_PROFILE_PINYIN \ + { \ + 0xF3BA9077, 0x6C7E, 0x11D4, 0x97, 0xFA, 0x00, 0x80, 0xC8, 0x82, 0x68, 0x7E \ + } +#define GUID_PROFILE_SIMPLEFAST \ + { \ + 0xFA550B04, 0x5AD7, 0x411F, 0xA5, 0xAC, 0xCA, 0x03, 0x8E, 0xC5, 0x15, 0xD7 \ + } +#define GUID_GUID_PROFILE_MSIME_JPN \ + { \ + 0xA76C93D9, 0x5523, 0x4E90, 0xAA, 0xFA, 0x4D, 0xB1, 0x12, 0xF9, 0xAC, 0x76 \ + } +#define GUID_PROFILE_MSIME_KOR \ + { \ + 0xB5FE1F02, 0xD5F2, 0x4445, 0x9C, 0x03, 0xC5, 0x68, 0xF2, 0x3C, 0x99, 0xA1 \ + } + +/* ImeState */ +#define IME_STATE_CLOSED 0x00000000 +#define IME_STATE_OPEN 0x00000001 + +/* ImeConvMode */ +#if !defined(_IME_CMODES_) && !defined(__MINGW32__) +#define IME_CMODE_NATIVE 0x00000001 +#define IME_CMODE_KATAKANA 0x00000002 +#define IME_CMODE_FULLSHAPE 0x00000008 +#define IME_CMODE_ROMAN 0x00000010 +#define IME_CMODE_CHARCODE 0x00000020 +#define IME_CMODE_HANJACONVERT 0x00000040 +#define IME_CMODE_SOFTKBD 0x00000080 +#define IME_CMODE_NOCONVERSION 0x00000100 +#define IME_CMODE_EUDC 0x00000200 +#define IME_CMODE_SYMBOL 0x00000400 +#define IME_CMODE_FIXED 0x00000800 +#endif + +/* ImeSentenceMode */ +#ifndef _IMM_ +#define IME_SMODE_NONE 0x00000000 +#define IME_SMODE_PLURALCASE 0x00000001 +#define IME_SMODE_SINGLECONVERT 0x00000002 +#define IME_SMODE_AUTOMATIC 0x00000004 +#define IME_SMODE_PHRASEPREDICT 0x00000008 +#define IME_SMODE_CONVERSATION 0x00000010 +#endif + +/* KANAMode */ +#define KANA_MODE_OFF 0x00000000 +#define KANA_MODE_ON 0x00000001 + +/* Taskbar */ +#define RAIL_TASKBAR_MSG_TAB_REGISTER 0x00000001 +#define RAIL_TASKBAR_MSG_TAB_UNREGISTER 0x00000002 +#define RAIL_TASKBAR_MSG_TAB_ORDER 0x00000003 +#define RAIL_TASKBAR_MSG_TAB_ACTIVE 0x00000004 +#define RAIL_TASKBAR_MSG_TAB_PROPERTIES 0x00000005 + +/* Taskbar body */ +#define RAIL_TASKBAR_MSG_TAB_REGISTER 0x00000001 +#define RAIL_TASKBAR_MSG_TAB_UNREGISTER 0x00000002 +#define RAIL_TASKBAR_MSG_TAB_ORDER 0x00000003 +#define RAIL_TASKBAR_MSG_TAB_ACTIVE 0x00000004 +#define RAIL_TASKBAR_MSG_TAB_PROPERTIES 0x00000005 + +typedef struct +{ + UINT16 length; + BYTE* string; +} RAIL_UNICODE_STRING; + +typedef struct +{ + UINT32 flags; + UINT32 colorSchemeLength; + RAIL_UNICODE_STRING colorScheme; +} RAIL_HIGH_CONTRAST; + +/* RAIL Orders */ + +typedef struct +{ + UINT32 buildNumber; +} RAIL_HANDSHAKE_ORDER; + +typedef struct +{ + UINT32 buildNumber; + UINT32 railHandshakeFlags; +} RAIL_HANDSHAKE_EX_ORDER; + +typedef struct +{ + UINT32 flags; +} RAIL_CLIENT_STATUS_ORDER; + +typedef struct +{ + UINT16 flags; + const char* RemoteApplicationProgram; + const char* RemoteApplicationWorkingDir; + const char* RemoteApplicationArguments; +} RAIL_EXEC_ORDER; + +typedef struct +{ + UINT16 flags; + UINT16 execResult; + UINT32 rawResult; + RAIL_UNICODE_STRING exeOrFile; +} RAIL_EXEC_RESULT_ORDER; + +typedef struct +{ + UINT32 Flags; + UINT32 WaitTime; + UINT32 DelayTime; + UINT32 RepeatTime; + UINT32 BounceTime; +} TS_FILTERKEYS; + +typedef struct +{ + UINT32 param; + UINT32 params; + BOOL dragFullWindows; + BOOL keyboardCues; + BOOL keyboardPref; + BOOL mouseButtonSwap; + RECTANGLE_16 workArea; + RECTANGLE_16 displayChange; + RECTANGLE_16 taskbarPos; + RAIL_HIGH_CONTRAST highContrast; + UINT32 caretWidth; + UINT32 stickyKeys; + UINT32 toggleKeys; + TS_FILTERKEYS filterKeys; + BOOL setScreenSaveActive; + BOOL setScreenSaveSecure; +} RAIL_SYSPARAM_ORDER; + +typedef struct +{ + UINT32 windowId; + BOOL enabled; +} RAIL_ACTIVATE_ORDER; + +typedef struct +{ + UINT32 windowId; + INT16 left; + INT16 top; +} RAIL_SYSMENU_ORDER; + +typedef struct +{ + UINT32 windowId; + UINT16 command; +} RAIL_SYSCOMMAND_ORDER; + +typedef struct +{ + UINT32 windowId; + UINT32 notifyIconId; + UINT32 message; +} RAIL_NOTIFY_EVENT_ORDER; + +typedef struct +{ + UINT32 windowId; + INT16 maxWidth; + INT16 maxHeight; + INT16 maxPosX; + INT16 maxPosY; + INT16 minTrackWidth; + INT16 minTrackHeight; + INT16 maxTrackWidth; + INT16 maxTrackHeight; +} RAIL_MINMAXINFO_ORDER; + +typedef struct +{ + UINT32 windowId; + BOOL isMoveSizeStart; + UINT16 moveSizeType; + INT16 posX; + INT16 posY; +} RAIL_LOCALMOVESIZE_ORDER; + +typedef struct +{ + UINT32 windowId; + INT16 left; + INT16 top; + INT16 right; + INT16 bottom; +} RAIL_WINDOW_MOVE_ORDER; + +typedef struct +{ + UINT32 windowId; +} RAIL_GET_APPID_REQ_ORDER; + +typedef struct +{ + UINT32 windowId; + WCHAR applicationId[260]; +} RAIL_GET_APPID_RESP_ORDER; + +typedef struct +{ + UINT32 languageBarStatus; +} RAIL_LANGBAR_INFO_ORDER; + +typedef struct +{ + UINT32 ImeState; + UINT32 ImeConvMode; + UINT32 ImeSentenceMode; + UINT32 KanaMode; +} RAIL_COMPARTMENT_INFO_ORDER; + +typedef struct +{ + UINT32 windowIdMarker; +} RAIL_ZORDER_SYNC; + +typedef struct +{ + UINT32 windowId; + BOOL cloak; +} RAIL_CLOAK; + +typedef struct +{ + UINT32 active; +} RAIL_POWER_DISPLAY_REQUEST; + +typedef struct +{ + UINT32 TaskbarMessage; + UINT32 WindowIdTab; + UINT32 Body; +} RAIL_TASKBAR_INFO_ORDER; + +typedef struct +{ + UINT32 ProfileType; + UINT32 LanguageID; + GUID LanguageProfileCLSID; + GUID ProfileGUID; + UINT32 KeyboardLayout; +} RAIL_LANGUAGEIME_INFO_ORDER; + +typedef struct +{ + UINT32 windowId; + INT16 left; + INT16 top; + INT16 right; + INT16 bottom; +} RAIL_SNAP_ARRANGE; + +typedef struct +{ + UINT32 windowID; + WCHAR applicationID[520 / sizeof(WCHAR)]; + UINT32 processId; + WCHAR processImageName[520 / sizeof(WCHAR)]; +} RAIL_GET_APPID_RESP_EX; + +/* DEPRECATED: RAIL Constants + * use the spec conformant naming scheme TS_ below + */ + +#define RDP_RAIL_ORDER_EXEC 0x0001 +#define RDP_RAIL_ORDER_ACTIVATE 0x0002 +#define RDP_RAIL_ORDER_SYSPARAM 0x0003 +#define RDP_RAIL_ORDER_SYSCOMMAND 0x0004 +#define RDP_RAIL_ORDER_HANDSHAKE 0x0005 +#define RDP_RAIL_ORDER_NOTIFY_EVENT 0x0006 +#define RDP_RAIL_ORDER_WINDOWMOVE 0x0008 +#define RDP_RAIL_ORDER_LOCALMOVESIZE 0x0009 +#define RDP_RAIL_ORDER_MINMAXINFO 0x000A +#define RDP_RAIL_ORDER_CLIENTSTATUS 0x000B +#define RDP_RAIL_ORDER_SYSMENU 0x000C +#define RDP_RAIL_ORDER_LANGBARINFO 0x000D +#define RDP_RAIL_ORDER_EXEC_RESULT 0x0080 +#define RDP_RAIL_ORDER_GET_APPID_REQ 0x000E +#define RDP_RAIL_ORDER_GET_APPID_RESP 0x000F +#define RDP_RAIL_ORDER_LANGUAGEIMEINFO 0x0011 +#define RDP_RAIL_ORDER_COMPARTMENTINFO 0x0012 +#define RDP_RAIL_ORDER_HANDSHAKE_EX 0x0013 +#define RDP_RAIL_ORDER_ZORDER_SYNC 0x0014 +#define RDP_RAIL_ORDER_CLOAK 0x0015 +#define RDP_RAIL_ORDER_POWER_DISPLAY_REQUEST 0x0016 +#define RDP_RAIL_ORDER_SNAP_ARRANGE 0x0017 +#define RDP_RAIL_ORDER_GET_APPID_RESP_EX 0x0018 + +/* RAIL Constants */ + +typedef enum +{ + TS_RAIL_ORDER_EXEC = 0x0001, + TS_RAIL_ORDER_ACTIVATE = 0x0002, + TS_RAIL_ORDER_SYSPARAM = 0x0003, + TS_RAIL_ORDER_SYSCOMMAND = 0x0004, + TS_RAIL_ORDER_HANDSHAKE = 0x0005, + TS_RAIL_ORDER_NOTIFY_EVENT = 0x0006, + TS_RAIL_ORDER_WINDOWMOVE = 0x0008, + TS_RAIL_ORDER_LOCALMOVESIZE = 0x0009, + TS_RAIL_ORDER_MINMAXINFO = 0x000A, + TS_RAIL_ORDER_CLIENTSTATUS = 0x000B, + TS_RAIL_ORDER_SYSMENU = 0x000C, + TS_RAIL_ORDER_LANGBARINFO = 0x000D, + TS_RAIL_ORDER_GET_APPID_REQ = 0x000E, + TS_RAIL_ORDER_GET_APPID_RESP = 0x000F, + TS_RAIL_ORDER_TASKBARINFO = 0x0010, + TS_RAIL_ORDER_LANGUAGEIMEINFO = 0x0011, + TS_RAIL_ORDER_COMPARTMENTINFO = 0x0012, + TS_RAIL_ORDER_HANDSHAKE_EX = 0x0013, + TS_RAIL_ORDER_ZORDER_SYNC = 0x0014, + TS_RAIL_ORDER_CLOAK = 0x0015, + TS_RAIL_ORDER_POWER_DISPLAY_REQUEST = 0x0016, + TS_RAIL_ORDER_SNAP_ARRANGE = 0x0017, + TS_RAIL_ORDER_GET_APPID_RESP_EX = 0x0018, + TS_RAIL_ORDER_TEXTSCALEINFO = 0x0019, + TS_RAIL_ORDER_CARETBLINKINFO = 0x001A, + TS_RAIL_ORDER_EXEC_RESULT = 0x0080 +} ORDER_TYPE; + + FREERDP_API BOOL rail_read_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string); + FREERDP_API BOOL utf8_string_to_rail_string(const char* string, + RAIL_UNICODE_STRING* unicode_string); + + /** @brief convert rails handshake flags to a string representation + * + * @param flags The flags to stringify + * @param buffer a string buffer to write to + * @param len the size in bytes of the string buffer + * + * @return A pointer to buffer or \b NULL in case of failure + * @since version 3.5.0 + */ + FREERDP_API const char* rail_handshake_ex_flags_to_string(UINT32 flags, char* buffer, + size_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_RAIL_GLOBAL_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/redirection.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/redirection.h new file mode 100644 index 0000000000000000000000000000000000000000..2f40e1010703bfdaabec778381368cf27a14f78b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/redirection.h @@ -0,0 +1,84 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Server Redirection + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_REDIRECTION_H +#define FREERDP_REDIRECTION_H + +#include + +/* Redirection Flags */ +#define LB_TARGET_NET_ADDRESS 0x00000001 +#define LB_LOAD_BALANCE_INFO 0x00000002 +#define LB_USERNAME 0x00000004 +#define LB_DOMAIN 0x00000008 +#define LB_PASSWORD 0x00000010 +#define LB_DONTSTOREUSERNAME 0x00000020 +#define LB_SMARTCARD_LOGON 0x00000040 +#define LB_NOREDIRECT 0x00000080 +#define LB_TARGET_FQDN 0x00000100 +#define LB_TARGET_NETBIOS_NAME 0x00000200 +#define LB_TARGET_NET_ADDRESSES 0x00000800 +#define LB_CLIENT_TSV_URL 0x00001000 +#define LB_SERVER_TSV_CAPABLE 0x00002000 +#define LB_PASSWORD_IS_PK_ENCRYPTED 0x00004000 +#define LB_REDIRECTION_GUID 0x00008000 +#define LB_TARGET_CERTIFICATE 0x00010000 + +#define LB_PASSWORD_MAX_LENGTH 512 + +#define ENCODING_TYPE_ASN1_DER 1 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_redirection rdpRedirection; + + FREERDP_API void redirection_free(rdpRedirection* redirection); + + WINPR_ATTR_MALLOC(redirection_free, 1) + FREERDP_API rdpRedirection* redirection_new(void); + + /** \brief This function checks if all necessary settings for a given \b rdpRedirection are + * available. + * + * \param redirection The redirection settings to check + * \param pFlags An (optional) pointer to UINT32. Is set to the flags that do not have + * necessary data available. + * + * \return \b TRUE if the redirection settings are ready to use, \b FALSE otherwise. + */ + FREERDP_API BOOL redirection_settings_are_valid(rdpRedirection* redirection, UINT32* pFlags); + + FREERDP_API BOOL redirection_set_flags(rdpRedirection* redirection, UINT32 flags); + FREERDP_API BOOL redirection_set_session_id(rdpRedirection* redirection, UINT32 session_id); + FREERDP_API BOOL redirection_set_byte_option(rdpRedirection* redirection, UINT32 flag, + const BYTE* data, size_t length); + FREERDP_API BOOL redirection_set_string_option(rdpRedirection* redirection, UINT32 flag, + const char* str); + FREERDP_API BOOL redirection_set_array_option(rdpRedirection* redirection, UINT32 flag, + const char** str, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_REDIRECTION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/scancode.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/scancode.h new file mode 100644 index 0000000000000000000000000000000000000000..0ee36355c7ca97e29532453517f5d51cb8d64153 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/scancode.h @@ -0,0 +1,237 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP protocol "scancodes" + * + * Copyright 2009-2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LOCALE_KEYBOARD_RDP_SCANCODE_H +#define FREERDP_LOCALE_KEYBOARD_RDP_SCANCODE_H + +#include + +/* msdn{cc240584} says: + * "... (a scancode is an 8-bit value specifying a key location on the keyboard). + * The server accepts a scancode value and translates it into the correct character depending on the + * language locale and keyboard layout used in the session." The 8-bit value is later called + * "keyCode" The extended flag is for all practical an important 9th bit with a strange encoding - + * not just a modifier. + */ + +#define RDP_SCANCODE_CODE(_rdp_scancode) ((BYTE)(_rdp_scancode & 0xFF)) +#define RDP_SCANCODE_EXTENDED(_rdp_scancode) (((_rdp_scancode)&KBDEXT) ? TRUE : FALSE) +#define MAKE_RDP_SCANCODE(_code, _extended) (((_code)&0xFF) | ((_extended) ? KBDEXT : 0)) + +/* Defines for known RDP_SCANCODE protocol values. + * Mostly the same as the PKBDLLHOOKSTRUCT scanCode, "A hardware scan code for the key", + * msdn{ms644967}. Based msdn{ms894073} US, msdn{ms894072} UK, msdn{ms892472} */ + +#define RDP_SCANCODE_UNKNOWN MAKE_RDP_SCANCODE(0x00, FALSE) + +#define RDP_SCANCODE_ESCAPE MAKE_RDP_SCANCODE(0x01, FALSE) /* VK_ESCAPE */ +#define RDP_SCANCODE_KEY_1 MAKE_RDP_SCANCODE(0x02, FALSE) /* VK_KEY_1 */ +#define RDP_SCANCODE_KEY_2 MAKE_RDP_SCANCODE(0x03, FALSE) /* VK_KEY_2 */ +#define RDP_SCANCODE_KEY_3 MAKE_RDP_SCANCODE(0x04, FALSE) /* VK_KEY_3 */ +#define RDP_SCANCODE_KEY_4 MAKE_RDP_SCANCODE(0x05, FALSE) /* VK_KEY_4 */ +#define RDP_SCANCODE_KEY_5 MAKE_RDP_SCANCODE(0x06, FALSE) /* VK_KEY_5 */ +#define RDP_SCANCODE_KEY_6 MAKE_RDP_SCANCODE(0x07, FALSE) /* VK_KEY_6 */ +#define RDP_SCANCODE_KEY_7 MAKE_RDP_SCANCODE(0x08, FALSE) /* VK_KEY_7 */ +#define RDP_SCANCODE_KEY_8 MAKE_RDP_SCANCODE(0x09, FALSE) /* VK_KEY_8 */ +#define RDP_SCANCODE_KEY_9 MAKE_RDP_SCANCODE(0x0A, FALSE) /* VK_KEY_9 */ +#define RDP_SCANCODE_KEY_0 MAKE_RDP_SCANCODE(0x0B, FALSE) /* VK_KEY_0 */ +#define RDP_SCANCODE_OEM_MINUS MAKE_RDP_SCANCODE(0x0C, FALSE) /* VK_OEM_MINUS */ +#define RDP_SCANCODE_OEM_PLUS MAKE_RDP_SCANCODE(0x0D, FALSE) /* VK_OEM_PLUS */ +#define RDP_SCANCODE_BACKSPACE MAKE_RDP_SCANCODE(0x0E, FALSE) /* VK_BACK Backspace */ +#define RDP_SCANCODE_TAB MAKE_RDP_SCANCODE(0x0F, FALSE) /* VK_TAB */ +#define RDP_SCANCODE_KEY_Q MAKE_RDP_SCANCODE(0x10, FALSE) /* VK_KEY_Q */ +#define RDP_SCANCODE_KEY_W MAKE_RDP_SCANCODE(0x11, FALSE) /* VK_KEY_W */ +#define RDP_SCANCODE_KEY_E MAKE_RDP_SCANCODE(0x12, FALSE) /* VK_KEY_E */ +#define RDP_SCANCODE_KEY_R MAKE_RDP_SCANCODE(0x13, FALSE) /* VK_KEY_R */ +#define RDP_SCANCODE_KEY_T MAKE_RDP_SCANCODE(0x14, FALSE) /* VK_KEY_T */ +#define RDP_SCANCODE_KEY_Y MAKE_RDP_SCANCODE(0x15, FALSE) /* VK_KEY_Y */ +#define RDP_SCANCODE_KEY_U MAKE_RDP_SCANCODE(0x16, FALSE) /* VK_KEY_U */ +#define RDP_SCANCODE_KEY_I MAKE_RDP_SCANCODE(0x17, FALSE) /* VK_KEY_I */ +#define RDP_SCANCODE_KEY_O MAKE_RDP_SCANCODE(0x18, FALSE) /* VK_KEY_O */ +#define RDP_SCANCODE_KEY_P MAKE_RDP_SCANCODE(0x19, FALSE) /* VK_KEY_P */ +#define RDP_SCANCODE_OEM_4 MAKE_RDP_SCANCODE(0x1A, FALSE) /* VK_OEM_4 '[' on US */ +#define RDP_SCANCODE_OEM_6 MAKE_RDP_SCANCODE(0x1B, FALSE) /* VK_OEM_6 ']' on US */ +#define RDP_SCANCODE_RETURN MAKE_RDP_SCANCODE(0x1C, FALSE) /* VK_RETURN Normal Enter */ +#define RDP_SCANCODE_LCONTROL MAKE_RDP_SCANCODE(0x1D, FALSE) /* VK_LCONTROL */ +#define RDP_SCANCODE_KEY_A MAKE_RDP_SCANCODE(0x1E, FALSE) /* VK_KEY_A */ +#define RDP_SCANCODE_KEY_S MAKE_RDP_SCANCODE(0x1F, FALSE) /* VK_KEY_S */ +#define RDP_SCANCODE_KEY_D MAKE_RDP_SCANCODE(0x20, FALSE) /* VK_KEY_D */ +#define RDP_SCANCODE_KEY_F MAKE_RDP_SCANCODE(0x21, FALSE) /* VK_KEY_F */ +#define RDP_SCANCODE_KEY_G MAKE_RDP_SCANCODE(0x22, FALSE) /* VK_KEY_G */ +#define RDP_SCANCODE_KEY_H MAKE_RDP_SCANCODE(0x23, FALSE) /* VK_KEY_H */ +#define RDP_SCANCODE_KEY_J MAKE_RDP_SCANCODE(0x24, FALSE) /* VK_KEY_J */ +#define RDP_SCANCODE_KEY_K MAKE_RDP_SCANCODE(0x25, FALSE) /* VK_KEY_K */ +#define RDP_SCANCODE_KEY_L MAKE_RDP_SCANCODE(0x26, FALSE) /* VK_KEY_L */ +#define RDP_SCANCODE_OEM_1 MAKE_RDP_SCANCODE(0x27, FALSE) /* VK_OEM_1 ';' on US */ +#define RDP_SCANCODE_OEM_7 MAKE_RDP_SCANCODE(0x28, FALSE) /* VK_OEM_7 "'" on US */ +#define RDP_SCANCODE_OEM_3 \ + MAKE_RDP_SCANCODE(0x29, FALSE) /* VK_OEM_3 Top left, '`' on US, JP DBE_SBCSCHAR */ +#define RDP_SCANCODE_LSHIFT MAKE_RDP_SCANCODE(0x2A, FALSE) /* VK_LSHIFT */ +#define RDP_SCANCODE_OEM_5 MAKE_RDP_SCANCODE(0x2B, FALSE) /* VK_OEM_5 Next to Enter, '\' on US */ +#define RDP_SCANCODE_KEY_Z MAKE_RDP_SCANCODE(0x2C, FALSE) /* VK_KEY_Z */ +#define RDP_SCANCODE_KEY_X MAKE_RDP_SCANCODE(0x2D, FALSE) /* VK_KEY_X */ +#define RDP_SCANCODE_KEY_C MAKE_RDP_SCANCODE(0x2E, FALSE) /* VK_KEY_C */ +#define RDP_SCANCODE_KEY_V MAKE_RDP_SCANCODE(0x2F, FALSE) /* VK_KEY_V */ +#define RDP_SCANCODE_KEY_B MAKE_RDP_SCANCODE(0x30, FALSE) /* VK_KEY_B */ +#define RDP_SCANCODE_KEY_N MAKE_RDP_SCANCODE(0x31, FALSE) /* VK_KEY_N */ +#define RDP_SCANCODE_KEY_M MAKE_RDP_SCANCODE(0x32, FALSE) /* VK_KEY_M */ +#define RDP_SCANCODE_OEM_COMMA MAKE_RDP_SCANCODE(0x33, FALSE) /* VK_OEM_COMMA */ +#define RDP_SCANCODE_OEM_PERIOD MAKE_RDP_SCANCODE(0x34, FALSE) /* VK_OEM_PERIOD */ +#define RDP_SCANCODE_OEM_2 MAKE_RDP_SCANCODE(0x35, FALSE) /* VK_OEM_2 '/' on US */ +#define RDP_SCANCODE_RSHIFT MAKE_RDP_SCANCODE(0x36, FALSE) /* VK_RSHIFT */ +#define RDP_SCANCODE_MULTIPLY MAKE_RDP_SCANCODE(0x37, FALSE) /* VK_MULTIPLY Numerical */ +#define RDP_SCANCODE_LMENU MAKE_RDP_SCANCODE(0x38, FALSE) /* VK_LMENU Left 'Alt' key */ +#define RDP_SCANCODE_SPACE MAKE_RDP_SCANCODE(0x39, FALSE) /* VK_SPACE */ +#define RDP_SCANCODE_CAPSLOCK \ + MAKE_RDP_SCANCODE(0x3A, FALSE) /* VK_CAPITAL 'Caps Lock', JP DBE_ALPHANUMERIC */ +#define RDP_SCANCODE_F1 MAKE_RDP_SCANCODE(0x3B, FALSE) /* VK_F1 */ +#define RDP_SCANCODE_F2 MAKE_RDP_SCANCODE(0x3C, FALSE) /* VK_F2 */ +#define RDP_SCANCODE_F3 MAKE_RDP_SCANCODE(0x3D, FALSE) /* VK_F3 */ +#define RDP_SCANCODE_F4 MAKE_RDP_SCANCODE(0x3E, FALSE) /* VK_F4 */ +#define RDP_SCANCODE_F5 MAKE_RDP_SCANCODE(0x3F, FALSE) /* VK_F5 */ +#define RDP_SCANCODE_F6 MAKE_RDP_SCANCODE(0x40, FALSE) /* VK_F6 */ +#define RDP_SCANCODE_F7 MAKE_RDP_SCANCODE(0x41, FALSE) /* VK_F7 */ +#define RDP_SCANCODE_F8 MAKE_RDP_SCANCODE(0x42, FALSE) /* VK_F8 */ +#define RDP_SCANCODE_F9 MAKE_RDP_SCANCODE(0x43, FALSE) /* VK_F9 */ +#define RDP_SCANCODE_F10 MAKE_RDP_SCANCODE(0x44, FALSE) /* VK_F10 */ +#define RDP_SCANCODE_NUMLOCK \ + MAKE_RDP_SCANCODE(0x45, FALSE) \ + /* VK_NUMLOCK */ /* Note: when this seems to appear in PKBDLLHOOKSTRUCT it means Pause which \ + must be sent as Ctrl + NumLock */ +#define RDP_SCANCODE_SCROLLLOCK \ + MAKE_RDP_SCANCODE(0x46, FALSE) /* VK_SCROLL 'Scroll Lock', JP OEM_SCROLL */ +#define RDP_SCANCODE_NUMPAD7 MAKE_RDP_SCANCODE(0x47, FALSE) /* VK_NUMPAD7 */ +#define RDP_SCANCODE_NUMPAD8 MAKE_RDP_SCANCODE(0x48, FALSE) /* VK_NUMPAD8 */ +#define RDP_SCANCODE_NUMPAD9 MAKE_RDP_SCANCODE(0x49, FALSE) /* VK_NUMPAD9 */ +#define RDP_SCANCODE_SUBTRACT MAKE_RDP_SCANCODE(0x4A, FALSE) /* VK_SUBTRACT */ +#define RDP_SCANCODE_NUMPAD4 MAKE_RDP_SCANCODE(0x4B, FALSE) /* VK_NUMPAD4 */ +#define RDP_SCANCODE_NUMPAD5 MAKE_RDP_SCANCODE(0x4C, FALSE) /* VK_NUMPAD5 */ +#define RDP_SCANCODE_NUMPAD6 MAKE_RDP_SCANCODE(0x4D, FALSE) /* VK_NUMPAD6 */ +#define RDP_SCANCODE_ADD MAKE_RDP_SCANCODE(0x4E, FALSE) /* VK_ADD */ +#define RDP_SCANCODE_NUMPAD1 MAKE_RDP_SCANCODE(0x4F, FALSE) /* VK_NUMPAD1 */ +#define RDP_SCANCODE_NUMPAD2 MAKE_RDP_SCANCODE(0x50, FALSE) /* VK_NUMPAD2 */ +#define RDP_SCANCODE_NUMPAD3 MAKE_RDP_SCANCODE(0x51, FALSE) /* VK_NUMPAD3 */ +#define RDP_SCANCODE_NUMPAD0 MAKE_RDP_SCANCODE(0x52, FALSE) /* VK_NUMPAD0 */ +#define RDP_SCANCODE_DECIMAL MAKE_RDP_SCANCODE(0x53, FALSE) /* VK_DECIMAL Numerical, '.' on US */ +#define RDP_SCANCODE_SYSREQ MAKE_RDP_SCANCODE(0x54, FALSE) /* Sys Req */ +#define RDP_SCANCODE_OEM_102 MAKE_RDP_SCANCODE(0x56, FALSE) /* VK_OEM_102 Lower left '\' on US */ +#define RDP_SCANCODE_F11 MAKE_RDP_SCANCODE(0x57, FALSE) /* VK_F11 */ +#define RDP_SCANCODE_F12 MAKE_RDP_SCANCODE(0x58, FALSE) /* VK_F12 */ +#define RDP_SCANCODE_SLEEP \ + MAKE_RDP_SCANCODE(0x5F, FALSE) /* VK_SLEEP OEM_8 on FR (undocumented?) \ + */ +#define RDP_SCANCODE_ZOOM MAKE_RDP_SCANCODE(0x62, FALSE) /* VK_ZOOM (undocumented?) */ +#define RDP_SCANCODE_HELP MAKE_RDP_SCANCODE(0x63, FALSE) /* VK_HELP (undocumented?) */ + +#define RDP_SCANCODE_F13 \ + MAKE_RDP_SCANCODE(0x64, FALSE) /* VK_F13 */ /* JP agree, should 0x7d according to ms894073 */ +#define RDP_SCANCODE_F14 MAKE_RDP_SCANCODE(0x65, FALSE) /* VK_F14 */ +#define RDP_SCANCODE_F15 MAKE_RDP_SCANCODE(0x66, FALSE) /* VK_F15 */ +#define RDP_SCANCODE_F16 MAKE_RDP_SCANCODE(0x67, FALSE) /* VK_F16 */ +#define RDP_SCANCODE_F17 MAKE_RDP_SCANCODE(0x68, FALSE) /* VK_F17 */ +#define RDP_SCANCODE_F18 MAKE_RDP_SCANCODE(0x69, FALSE) /* VK_F18 */ +#define RDP_SCANCODE_F19 MAKE_RDP_SCANCODE(0x6A, FALSE) /* VK_F19 */ +#define RDP_SCANCODE_F20 MAKE_RDP_SCANCODE(0x6B, FALSE) /* VK_F20 */ +#define RDP_SCANCODE_F21 MAKE_RDP_SCANCODE(0x6C, FALSE) /* VK_F21 */ +#define RDP_SCANCODE_F22 MAKE_RDP_SCANCODE(0x6D, FALSE) /* VK_F22 */ +#define RDP_SCANCODE_F23 MAKE_RDP_SCANCODE(0x6E, FALSE) /* VK_F23 */ /* JP agree */ +#define RDP_SCANCODE_F24 \ + MAKE_RDP_SCANCODE(0x6F, FALSE) /* VK_F24 */ /* 0x87 according to ms894073 */ + +#define RDP_SCANCODE_HIRAGANA MAKE_RDP_SCANCODE(0x70, FALSE) /* JP DBE_HIRAGANA */ +#define RDP_SCANCODE_HANJA_KANJI \ + MAKE_RDP_SCANCODE(0x71, FALSE) /* VK_HANJA / VK_KANJI (undocumented?) */ +#define RDP_SCANCODE_KANA_HANGUL \ + MAKE_RDP_SCANCODE(0x72, FALSE) /* VK_KANA / VK_HANGUL (undocumented?) */ +#define RDP_SCANCODE_ABNT_C1 MAKE_RDP_SCANCODE(0x73, FALSE) /* VK_ABNT_C1 JP OEM_102 */ +#define RDP_SCANCODE_F24_JP MAKE_RDP_SCANCODE(0x76, FALSE) /* JP F24 */ +#define RDP_SCANCODE_CONVERT_JP MAKE_RDP_SCANCODE(0x79, FALSE) /* JP VK_CONVERT */ +#define RDP_SCANCODE_NONCONVERT_JP MAKE_RDP_SCANCODE(0x7B, FALSE) /* JP VK_NONCONVERT */ +#define RDP_SCANCODE_TAB_JP MAKE_RDP_SCANCODE(0x7C, FALSE) /* JP TAB */ +#define RDP_SCANCODE_BACKSLASH_JP MAKE_RDP_SCANCODE(0x7D, FALSE) /* JP OEM_5 ('\') */ +#define RDP_SCANCODE_ABNT_C2 MAKE_RDP_SCANCODE(0x7E, FALSE) /* VK_ABNT_C2, JP */ +#define RDP_SCANCODE_HANJA MAKE_RDP_SCANCODE(0x71, FALSE) /* KR VK_HANJA */ +#define RDP_SCANCODE_HANGUL MAKE_RDP_SCANCODE(0x72, FALSE) /* KR VK_HANGUL */ + +#define RDP_SCANCODE_RETURN_KP \ + MAKE_RDP_SCANCODE(0x1C, TRUE) /* not RDP_SCANCODE_RETURN Numerical Enter */ +#define RDP_SCANCODE_RCONTROL MAKE_RDP_SCANCODE(0x1D, TRUE) /* VK_RCONTROL */ +#define RDP_SCANCODE_DIVIDE MAKE_RDP_SCANCODE(0x35, TRUE) /* VK_DIVIDE Numerical */ +#define RDP_SCANCODE_PRINTSCREEN \ + MAKE_RDP_SCANCODE(0x37, TRUE) /* VK_EXECUTE/VK_PRINT/VK_SNAPSHOT Print Screen */ +#define RDP_SCANCODE_RMENU MAKE_RDP_SCANCODE(0x38, TRUE) /* VK_RMENU Right 'Alt' / 'Alt Gr' */ +#define RDP_SCANCODE_PAUSE \ + MAKE_RDP_SCANCODE(0x46, TRUE) /* VK_PAUSE Pause / Break (Slightly special handling) */ +#define RDP_SCANCODE_HOME MAKE_RDP_SCANCODE(0x47, TRUE) /* VK_HOME */ +#define RDP_SCANCODE_UP MAKE_RDP_SCANCODE(0x48, TRUE) /* VK_UP */ +#define RDP_SCANCODE_PRIOR MAKE_RDP_SCANCODE(0x49, TRUE) /* VK_PRIOR 'Page Up' */ +#define RDP_SCANCODE_LEFT MAKE_RDP_SCANCODE(0x4B, TRUE) /* VK_LEFT */ +#define RDP_SCANCODE_RIGHT MAKE_RDP_SCANCODE(0x4D, TRUE) /* VK_RIGHT */ +#define RDP_SCANCODE_END MAKE_RDP_SCANCODE(0x4F, TRUE) /* VK_END */ +#define RDP_SCANCODE_DOWN MAKE_RDP_SCANCODE(0x50, TRUE) /* VK_DOWN */ +#define RDP_SCANCODE_NEXT MAKE_RDP_SCANCODE(0x51, TRUE) /* VK_NEXT 'Page Down' */ +#define RDP_SCANCODE_INSERT MAKE_RDP_SCANCODE(0x52, TRUE) /* VK_INSERT */ +#define RDP_SCANCODE_DELETE MAKE_RDP_SCANCODE(0x53, TRUE) /* VK_DELETE */ +#define RDP_SCANCODE_NULL MAKE_RDP_SCANCODE(0x54, TRUE) /* <00> */ +#define RDP_SCANCODE_HELP2 \ + MAKE_RDP_SCANCODE(0x56, TRUE) /* Help - documented, different from VK_HELP */ +#define RDP_SCANCODE_LWIN MAKE_RDP_SCANCODE(0x5B, TRUE) /* VK_LWIN */ +#define RDP_SCANCODE_RWIN MAKE_RDP_SCANCODE(0x5C, TRUE) /* VK_RWIN */ +#define RDP_SCANCODE_APPS MAKE_RDP_SCANCODE(0x5D, TRUE) /* VK_APPS Application */ +#define RDP_SCANCODE_POWER_JP MAKE_RDP_SCANCODE(0x5E, TRUE) /* JP POWER */ +#define RDP_SCANCODE_SLEEP_JP MAKE_RDP_SCANCODE(0x5F, TRUE) /* JP SLEEP */ + +/* _not_ valid scancode, but this is what a windows PKBDLLHOOKSTRUCT for NumLock contains */ +#define RDP_SCANCODE_NUMLOCK_EXTENDED \ + MAKE_RDP_SCANCODE(0x45, TRUE) /* should be RDP_SCANCODE_NUMLOCK */ +#define RDP_SCANCODE_RSHIFT_EXTENDED \ + MAKE_RDP_SCANCODE(0x36, TRUE) /* should be RDP_SCANCODE_RSHIFT */ + +/* Audio */ +#define RDP_SCANCODE_VOLUME_MUTE MAKE_RDP_SCANCODE(0x20, TRUE) /* VK_VOLUME_MUTE */ +#define RDP_SCANCODE_VOLUME_DOWN MAKE_RDP_SCANCODE(0x2E, TRUE) /* VK_VOLUME_DOWN */ +#define RDP_SCANCODE_VOLUME_UP MAKE_RDP_SCANCODE(0x30, TRUE) /* VK_VOLUME_UP */ + +/* Media */ +#define RDP_SCANCODE_MEDIA_NEXT_TRACK MAKE_RDP_SCANCODE(0x19, TRUE) /* VK_MEDIA_NEXT_TRACK */ +#define RDP_SCANCODE_MEDIA_PREV_TRACK MAKE_RDP_SCANCODE(0x10, TRUE) /* VK_MEDIA_PREV_TRACK */ +#define RDP_SCANCODE_MEDIA_STOP MAKE_RDP_SCANCODE(0x24, TRUE) /* VK_MEDIA_MEDIA_STOP */ +#define RDP_SCANCODE_MEDIA_PLAY_PAUSE \ + MAKE_RDP_SCANCODE(0x22, TRUE) /* VK_MEDIA_MEDIA_PLAY_PAUSE \ + */ + +/* Browser functions */ +#define RDP_SCANCODE_BROWSER_BACK MAKE_RDP_SCANCODE(0x6A, TRUE) /* VK_BROWSER_BACK */ +#define RDP_SCANCODE_BROWSER_FORWARD MAKE_RDP_SCANCODE(0x69, TRUE) /* VK_BROWSER_FORWARD */ +#define RDP_SCANCODE_BROWSER_REFRESH MAKE_RDP_SCANCODE(0x67, TRUE) /* VK_BROWSER_REFRESH */ +#define RDP_SCANCODE_BROWSER_STOP MAKE_RDP_SCANCODE(0x68, TRUE) /* VK_BROWSER_STOP */ +#define RDP_SCANCODE_BROWSER_SEARCH MAKE_RDP_SCANCODE(0x65, TRUE) /* VK_BROWSER_SEARCH */ +#define RDP_SCANCODE_BROWSER_FAVORITES MAKE_RDP_SCANCODE(0x66, TRUE) /* VK_BROWSER_FAVORITES */ +#define RDP_SCANCODE_BROWSER_HOME MAKE_RDP_SCANCODE(0x32, TRUE) /* VK_BROWSER_HOME */ + +/* Misc. */ +#define RDP_SCANCODE_LAUNCH_MAIL MAKE_RDP_SCANCODE(0x6C, TRUE) /* VK_LAUNCH_MAIL */ + +#define RDP_SCANCODE_LAUNCH_MEDIA_SELECT \ + MAKE_RDP_SCANCODE(0x6D, TRUE) /* VK_LAUNCH_MEDIA_SELECT \ + */ +#define RDP_SCANCODE_LAUNCH_APP1 MAKE_RDP_SCANCODE(0x6E, TRUE) /* VK_LAUNCH_APP1 */ +#define RDP_SCANCODE_LAUNCH_APP2 MAKE_RDP_SCANCODE(0x6F, TRUE) /* VK_LAUNCH_APP2 */ + +#endif /* FREERDP_LOCALE_KEYBOARD_RDP_SCANCODE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/secondary.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/secondary.h new file mode 100644 index 0000000000000000000000000000000000000000..76ff13d6183d0a83cd497e966652f2df3294d5a7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/secondary.h @@ -0,0 +1,197 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Secondary Drawing Orders Interface API + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UPDATE_SECONDARY_H +#define FREERDP_UPDATE_SECONDARY_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define GLYPH_FRAGMENT_NOP 0x00 +#define GLYPH_FRAGMENT_USE 0xFE +#define GLYPH_FRAGMENT_ADD 0xFF + +#define CBR2_HEIGHT_SAME_AS_WIDTH 0x01 +#define CBR2_PERSISTENT_KEY_PRESENT 0x02 +#define CBR2_NO_BITMAP_COMPRESSION_HDR 0x08 +#define CBR2_DO_NOT_CACHE 0x10 + +#define SCREEN_BITMAP_SURFACE 0xFFFF +#define BITMAP_CACHE_WAITING_LIST_INDEX 0x7FFF + +#define CACHED_BRUSH 0x80 + +#define BMF_1BPP 0x1 +#define BMF_8BPP 0x3 +#define BMF_16BPP 0x4 +#define BMF_24BPP 0x5 +#define BMF_32BPP 0x6 + +#ifndef _WIN32 +#define BS_SOLID 0x00 +#define BS_NULL 0x01 +#define BS_HATCHED 0x02 +#define BS_PATTERN 0x03 +#endif + +#ifndef _WIN32 +#define HS_HORIZONTAL 0x00 +#define HS_VERTICAL 0x01 +#define HS_FDIAGONAL 0x02 +#define HS_BDIAGONAL 0x03 +#define HS_CROSS 0x04 +#define HS_DIAGCROSS 0x05 +#endif + +#define SO_FLAG_DEFAULT_PLACEMENT 0x01 +#define SO_HORIZONTAL 0x02 +#define SO_VERTICAL 0x04 +#define SO_REVERSED 0x08 +#define SO_ZERO_BEARINGS 0x10 +#define SO_CHAR_INC_EQUAL_BM_BASE 0x20 +#define SO_MAXEXT_EQUAL_BM_SIDE 0x40 + +typedef struct +{ + UINT32 cacheId; + UINT32 bitmapBpp; + UINT32 bitmapWidth; + UINT32 bitmapHeight; + UINT32 bitmapLength; + UINT32 cacheIndex; + BOOL compressed; + BYTE bitmapComprHdr[8]; + BYTE* bitmapDataStream; +} CACHE_BITMAP_ORDER; + +typedef struct +{ + UINT32 cacheId; + UINT32 flags; + UINT32 key1; + UINT32 key2; + UINT32 bitmapBpp; + UINT32 bitmapWidth; + UINT32 bitmapHeight; + UINT32 bitmapLength; + UINT32 cacheIndex; + BOOL compressed; + UINT32 cbCompFirstRowSize; + UINT32 cbCompMainBodySize; + UINT32 cbScanWidth; + UINT32 cbUncompressedSize; + BYTE* bitmapDataStream; +} CACHE_BITMAP_V2_ORDER; + +typedef struct +{ + UINT32 bpp; + UINT32 codecID; + UINT32 width; + UINT32 height; + UINT32 length; + BYTE* data; +} BITMAP_DATA_EX; + +typedef struct +{ + UINT32 cacheId; + UINT32 bpp; + UINT32 flags; + UINT32 cacheIndex; + UINT32 key1; + UINT32 key2; + BITMAP_DATA_EX bitmapData; +} CACHE_BITMAP_V3_ORDER; + +typedef struct +{ + UINT32 cacheIndex; + UINT32 numberColors; + UINT32 colorTable[256]; +} CACHE_COLOR_TABLE_ORDER; + +typedef struct +{ + UINT32 cacheId; + UINT32 cGlyphs; + GLYPH_DATA glyphData[256]; + WCHAR* unicodeCharacters; +} CACHE_GLYPH_ORDER; + +typedef struct +{ + UINT32 cacheId; + UINT32 flags; + UINT32 cGlyphs; + GLYPH_DATA_V2 glyphData[256]; + WCHAR* unicodeCharacters; +} CACHE_GLYPH_V2_ORDER; + +typedef struct +{ + UINT32 index; + UINT32 bpp; + UINT32 cx; + UINT32 cy; + UINT32 style; + UINT32 length; + BYTE data[256]; +} CACHE_BRUSH_ORDER; + +typedef BOOL (*pCacheBitmap)(rdpContext* context, const CACHE_BITMAP_ORDER* cache_bitmap_order); +typedef BOOL (*pCacheBitmapV2)(rdpContext* context, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order); +typedef BOOL (*pCacheBitmapV3)(rdpContext* context, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order); +typedef BOOL (*pCacheColorTable)(rdpContext* context, + const CACHE_COLOR_TABLE_ORDER* cache_color_table_order); +typedef BOOL (*pCacheGlyph)(rdpContext* context, const CACHE_GLYPH_ORDER* cache_glyph_order); +typedef BOOL (*pCacheGlyphV2)(rdpContext* context, + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order); +typedef BOOL (*pCacheBrush)(rdpContext* context, const CACHE_BRUSH_ORDER* cache_brush_order); +typedef BOOL (*pCacheOrderInfo)(rdpContext* context, INT16 orderLength, UINT16 extraFlags, + UINT8 orderType, const char* orderName); + +struct rdp_secondary_update +{ + rdpContext* context; /* 0 */ + UINT32 paddingA[16 - 1]; /* 1 */ + + pCacheBitmap CacheBitmap; /* 16 */ + pCacheBitmapV2 CacheBitmapV2; /* 17 */ + pCacheBitmapV3 CacheBitmapV3; /* 18 */ + pCacheColorTable CacheColorTable; /* 19 */ + pCacheGlyph CacheGlyph; /* 20 */ + pCacheGlyphV2 CacheGlyphV2; /* 21 */ + pCacheBrush CacheBrush; /* 22 */ + /* Statistics callback */ + pCacheOrderInfo CacheOrderInfo; /* 23 */ + UINT32 paddingE[32 - 24]; /* 24 */ +}; +typedef struct rdp_secondary_update rdpSecondaryUpdate; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UPDATE_SECONDARY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/ainput.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/ainput.h new file mode 100644 index 0000000000000000000000000000000000000000..21c47d64b532db64fd22e79bbee27cf16ecf5686 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/ainput.h @@ -0,0 +1,124 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * AInput Virtual Channel Extension + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AINPUT_SERVER_H +#define FREERDP_CHANNEL_AINPUT_SERVER_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum AINPUT_SERVER_OPEN_RESULT + { + AINPUT_SERVER_OPEN_RESULT_OK = 0, + AINPUT_SERVER_OPEN_RESULT_CLOSED = 1, + AINPUT_SERVER_OPEN_RESULT_NOTSUPPORTED = 2, + AINPUT_SERVER_OPEN_RESULT_ERROR = 3 + } AINPUT_SERVER_OPEN_RESULT; + + typedef struct s_ainput_server_context ainput_server_context; + + typedef BOOL (*psAInputChannelIdAssigned)(ainput_server_context* context, UINT32 channelId); + + typedef UINT (*psAInputServerInitialize)(ainput_server_context* context, BOOL externalThread); + typedef UINT (*psAInputServerPoll)(ainput_server_context* context); + typedef BOOL (*psAInputServerChannelHandle)(ainput_server_context* context, HANDLE* handle); + + typedef UINT (*psAInputServerOpen)(ainput_server_context* context); + typedef UINT (*psAInputServerClose)(ainput_server_context* context); + typedef BOOL (*psAInputServerIsOpen)(ainput_server_context* context); + + typedef UINT (*psAInputServerOpenResult)(ainput_server_context* context, + AINPUT_SERVER_OPEN_RESULT result); + typedef UINT (*psAInputServerMouseEvent)(ainput_server_context* context, UINT64 timestamp, + UINT64 flags, INT32 x, INT32 y); + + struct s_ainput_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* data; + + /*** APIs called by the server. ***/ + /** + * Open the ainput channel. + */ + psAInputServerOpen Open; + + /** + * Optional: Set thread handling. + * When externalThread=TRUE the application is responsible to call + * ainput_server_context_poll periodically to process input events. + * + * Defaults to externalThread=FALSE + */ + psAInputServerInitialize Initialize; + + /** + * @brief Poll When externalThread=TRUE call periodically from your main loop. + * if externalThread=FALSE do not call. + */ + psAInputServerPoll Poll; + + /** + * @brief Poll When externalThread=TRUE call to get a handle to wait for events. + * Will return FALSE until the handle is available. + */ + psAInputServerChannelHandle ChannelHandle; + + /** + * Close the ainput channel. + */ + psAInputServerClose Close; + /** + * Status of the ainput channel. + */ + psAInputServerIsOpen IsOpen; + + /*** Callbacks registered by the server. ***/ + + /** + * Receive ainput mouse event PDU. + */ + psAInputServerMouseEvent MouseEvent; + + rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psAInputChannelIdAssigned ChannelIdAssigned; + }; + + FREERDP_API void ainput_server_context_free(ainput_server_context* context); + + WINPR_ATTR_MALLOC(ainput_server_context_free, 1) + FREERDP_API ainput_server_context* ainput_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_AINPUT_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/audin.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/audin.h new file mode 100644 index 0000000000000000000000000000000000000000..51d83fe12e81fc3109308fdb01508f70ad5607d0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/audin.h @@ -0,0 +1,179 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Audio Input Virtual Channel + * + * Copyright 2012 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_AUDIN_SERVER_H +#define FREERDP_CHANNEL_AUDIN_SERVER_H + +#include + +#include +#include + +#if !defined(CHANNEL_AUDIN_SERVER) +#error "This header must not be included if CHANNEL_AUDIN_SERVER is not defined" +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_audin_server_context audin_server_context; + + typedef BOOL (*psAudinServerChannelOpen)(audin_server_context* context); + typedef BOOL (*psAudinServerChannelIsOpen)(audin_server_context* context); + typedef BOOL (*psAudinServerChannelClose)(audin_server_context* context); + + typedef BOOL (*psAudinServerChannelIdAssigned)(audin_server_context* context, UINT32 channelId); + + typedef UINT (*psAudinServerVersion)(audin_server_context* context, + const SNDIN_VERSION* version); + typedef UINT (*psAudinServerFormats)(audin_server_context* context, + const SNDIN_FORMATS* formats); + typedef UINT (*psAudinServerOpen)(audin_server_context* context, const SNDIN_OPEN* open); + typedef UINT (*psAudinServerOpenReply)(audin_server_context* context, + const SNDIN_OPEN_REPLY* open_reply); + typedef UINT (*psAudinServerIncomingData)(audin_server_context* context, + const SNDIN_DATA_INCOMING* data_incoming); + typedef UINT (*psAudinServerData)(audin_server_context* context, const SNDIN_DATA* data); + typedef UINT (*psAudinServerFormatChange)(audin_server_context* context, + const SNDIN_FORMATCHANGE* format_change); + + struct s_audin_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* userdata; + + /** + * Server version to send to the client, when the DVC was successfully + * opened. + **/ + SNDIN_VERSION_Version serverVersion; + + /*** APIs called by the server. ***/ + + /** + * Open the audio input channel. + */ + psAudinServerChannelOpen Open; + + /** + * Check, whether the audio input channel thread was created + */ + psAudinServerChannelIsOpen IsOpen; + + /** + * Close the audio input channel. + */ + psAudinServerChannelClose Close; + + /** + * For the following server to client PDUs, + * the message header does not have to be set. + */ + + /** + * Send a Version PDU. + */ + psAudinServerVersion SendVersion; + + /** + * Send a Sound Formats PDU. + */ + psAudinServerFormats SendFormats; + + /** + * Send an Open PDU. + */ + psAudinServerOpen SendOpen; + + /** + * Send a Format Change PDU. + */ + psAudinServerFormatChange SendFormatChange; + + /*** Callbacks registered by the server. ***/ + + /** + * Callback, when the channel got its id assigned. + */ + psAudinServerChannelIdAssigned ChannelIdAssigned; + + /* + * Callback for the Version PDU. + */ + psAudinServerVersion ReceiveVersion; + + /* + * Callback for the Sound Formats PDU. + */ + psAudinServerFormats ReceiveFormats; + + /* + * Callback for the Open Reply PDU. + */ + psAudinServerOpenReply OpenReply; + + /* + * Callback for the Incoming Data PDU. + */ + psAudinServerIncomingData IncomingData; + + /* + * Callback for the Data PDU. + */ + psAudinServerData Data; + + /* + * Callback for the Format Change PDU. + */ + psAudinServerFormatChange ReceiveFormatChange; + + rdpContext* rdpcontext; + }; + + FREERDP_API void audin_server_context_free(audin_server_context* context); + + WINPR_ATTR_MALLOC(audin_server_context_free, 1) + FREERDP_API audin_server_context* audin_server_context_new(HANDLE vcm); + + /** \brief sets the supported audio formats for AUDIN server channel context. + * + * \param context The context to set the formats for + * \param count The number of formats found in \b formats. Use \b -1 to set to default formats + * supported by FreeRDP \param formats An array of \b count elements + * + * \return \b TRUE if successful and at least one format is supported, \b FALSE otherwise. + */ + FREERDP_API BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count, + const AUDIO_FORMAT* formats); + + FREERDP_API const AUDIO_FORMAT* + audin_server_get_negotiated_format(const audin_server_context* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_AUDIN_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/channels.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/channels.h new file mode 100644 index 0000000000000000000000000000000000000000..65b6b7f5b588885896da73be98ba327457b5885c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/channels.h @@ -0,0 +1,25 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Channels + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNELS_SERVER_H +#define FREERDP_CHANNELS_SERVER_H + +#include + +#endif /* FREERDP_CHANNELS_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/cliprdr.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/cliprdr.h new file mode 100644 index 0000000000000000000000000000000000000000..77ebb008ff2c94d0b2ffe267711dee308897cd32 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/cliprdr.h @@ -0,0 +1,146 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Clipboard Virtual Channel Server Interface + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CLIPRDR_SERVER_CLIPRDR_H +#define FREERDP_CHANNEL_CLIPRDR_SERVER_CLIPRDR_H + +#include +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Server Interface + */ + + typedef struct s_cliprdr_server_context CliprdrServerContext; + + typedef UINT (*psCliprdrOpen)(CliprdrServerContext* context); + typedef UINT (*psCliprdrClose)(CliprdrServerContext* context); + typedef UINT (*psCliprdrStart)(CliprdrServerContext* context); + typedef UINT (*psCliprdrStop)(CliprdrServerContext* context); + typedef HANDLE (*psCliprdrGetEventHandle)(CliprdrServerContext* context); + typedef UINT (*psCliprdrCheckEventHandle)(CliprdrServerContext* context); + + typedef UINT (*psCliprdrServerCapabilities)(CliprdrServerContext* context, + const CLIPRDR_CAPABILITIES* capabilities); + typedef UINT (*psCliprdrClientCapabilities)(CliprdrServerContext* context, + const CLIPRDR_CAPABILITIES* capabilities); + typedef UINT (*psCliprdrMonitorReady)(CliprdrServerContext* context, + const CLIPRDR_MONITOR_READY* monitorReady); + typedef UINT (*psCliprdrTempDirectory)(CliprdrServerContext* context, + const CLIPRDR_TEMP_DIRECTORY* tempDirectory); + typedef UINT (*psCliprdrClientFormatList)(CliprdrServerContext* context, + const CLIPRDR_FORMAT_LIST* formatList); + typedef UINT (*psCliprdrServerFormatList)(CliprdrServerContext* context, + const CLIPRDR_FORMAT_LIST* formatList); + typedef UINT (*psCliprdrClientFormatListResponse)( + CliprdrServerContext* context, const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse); + typedef UINT (*psCliprdrServerFormatListResponse)( + CliprdrServerContext* context, const CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse); + typedef UINT (*psCliprdrClientLockClipboardData)( + CliprdrServerContext* context, const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData); + typedef UINT (*psCliprdrServerLockClipboardData)( + CliprdrServerContext* context, const CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData); + typedef UINT (*psCliprdrClientUnlockClipboardData)( + CliprdrServerContext* context, const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData); + typedef UINT (*psCliprdrServerUnlockClipboardData)( + CliprdrServerContext* context, const CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData); + typedef UINT (*psCliprdrClientFormatDataRequest)( + CliprdrServerContext* context, const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest); + typedef UINT (*psCliprdrServerFormatDataRequest)( + CliprdrServerContext* context, const CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest); + typedef UINT (*psCliprdrClientFormatDataResponse)( + CliprdrServerContext* context, const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse); + typedef UINT (*psCliprdrServerFormatDataResponse)( + CliprdrServerContext* context, const CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse); + typedef UINT (*psCliprdrClientFileContentsRequest)( + CliprdrServerContext* context, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest); + typedef UINT (*psCliprdrServerFileContentsRequest)( + CliprdrServerContext* context, const CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest); + typedef UINT (*psCliprdrClientFileContentsResponse)( + CliprdrServerContext* context, const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse); + typedef UINT (*psCliprdrServerFileContentsResponse)( + CliprdrServerContext* context, const CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse); + + struct s_cliprdr_server_context + { + void* handle; + void* custom; + + /* server clipboard capabilities - set by server - updated by the channel after client + * capability exchange */ + BOOL useLongFormatNames; + BOOL streamFileClipEnabled; + BOOL fileClipNoFilePaths; + BOOL canLockClipData; + + psCliprdrOpen Open; + psCliprdrClose Close; + psCliprdrStart Start; + psCliprdrStop Stop; + psCliprdrGetEventHandle GetEventHandle; + psCliprdrCheckEventHandle CheckEventHandle; + + psCliprdrServerCapabilities ServerCapabilities; + psCliprdrClientCapabilities ClientCapabilities; + psCliprdrMonitorReady MonitorReady; + psCliprdrTempDirectory TempDirectory; + psCliprdrClientFormatList ClientFormatList; + psCliprdrServerFormatList ServerFormatList; + psCliprdrClientFormatListResponse ClientFormatListResponse; + psCliprdrServerFormatListResponse ServerFormatListResponse; + psCliprdrClientLockClipboardData ClientLockClipboardData; + psCliprdrServerLockClipboardData ServerLockClipboardData; + psCliprdrClientUnlockClipboardData ClientUnlockClipboardData; + psCliprdrServerUnlockClipboardData ServerUnlockClipboardData; + psCliprdrClientFormatDataRequest ClientFormatDataRequest; + psCliprdrServerFormatDataRequest ServerFormatDataRequest; + psCliprdrClientFormatDataResponse ClientFormatDataResponse; + psCliprdrServerFormatDataResponse ServerFormatDataResponse; + psCliprdrClientFileContentsRequest ClientFileContentsRequest; + psCliprdrServerFileContentsRequest ServerFileContentsRequest; + psCliprdrClientFileContentsResponse ClientFileContentsResponse; + psCliprdrServerFileContentsResponse ServerFileContentsResponse; + + rdpContext* rdpcontext; + BOOL autoInitializationSequence; + UINT32 lastRequestedFormatId; + BOOL hasHugeFileSupport; + }; + + FREERDP_API void cliprdr_server_context_free(CliprdrServerContext* context); + + WINPR_ATTR_MALLOC(cliprdr_server_context_free, 1) + FREERDP_API CliprdrServerContext* cliprdr_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_CLIPRDR_SERVER_CLIPRDR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/disp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/disp.h new file mode 100644 index 0000000000000000000000000000000000000000..d17c3c2994e00d54a4a6bb1f89dca696ba97a3d2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/disp.h @@ -0,0 +1,78 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPEDISP Virtual Channel Extension + * + * Copyright 2019 Kobi Mizrachi + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DISP_SERVER_DISP_H +#define FREERDP_CHANNEL_DISP_SERVER_DISP_H + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_disp_server_private DispServerPrivate; + typedef struct s_disp_server_context DispServerContext; + + typedef BOOL (*psDispChannelIdAssigned)(DispServerContext* context, UINT32 channelId); + + typedef UINT (*psDispMonitorLayout)(DispServerContext* context, + const DISPLAY_CONTROL_MONITOR_LAYOUT_PDU* pdu); + typedef UINT (*psDispCaps)(DispServerContext* context); + typedef UINT (*psDispOpen)(DispServerContext* context); + typedef UINT (*psDispClose)(DispServerContext* context); + + struct s_disp_server_context + { + void* custom; + HANDLE vcm; + + /* Server capabilities */ + UINT32 MaxNumMonitors; + UINT32 MaxMonitorAreaFactorA; + UINT32 MaxMonitorAreaFactorB; + + psDispOpen Open; + psDispClose Close; + + psDispMonitorLayout DispMonitorLayout; + psDispCaps DisplayControlCaps; + + DispServerPrivate* priv; + rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psDispChannelIdAssigned ChannelIdAssigned; + }; + + FREERDP_API void disp_server_context_free(DispServerContext* context); + + WINPR_ATTR_MALLOC(disp_server_context_free, 1) + FREERDP_API DispServerContext* disp_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_DISP_SERVER_DISP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/drdynvc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/drdynvc.h new file mode 100644 index 0000000000000000000000000000000000000000..09453f4c919b3290d8536d8116c897094321208d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/drdynvc.h @@ -0,0 +1,63 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Dynamic Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_DRDYNVC_SERVER_DRDYNVC_H +#define FREERDP_CHANNEL_DRDYNVC_SERVER_DRDYNVC_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Server Interface + */ + + typedef struct s_drdynvc_server_context DrdynvcServerContext; + typedef struct s_drdynvc_server_private DrdynvcServerPrivate; + + typedef UINT (*psDrdynvcStart)(DrdynvcServerContext* context); + typedef UINT (*psDrdynvcStop)(DrdynvcServerContext* context); + + struct s_drdynvc_server_context + { + HANDLE vcm; + + psDrdynvcStart Start; + psDrdynvcStop Stop; + + DrdynvcServerPrivate* priv; + }; + + FREERDP_API void drdynvc_server_context_free(DrdynvcServerContext* context); + + WINPR_ATTR_MALLOC(drdynvc_server_context_free, 1) + FREERDP_API DrdynvcServerContext* drdynvc_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_DRDYNVC_SERVER_DRDYNVC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/echo.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/echo.h new file mode 100644 index 0000000000000000000000000000000000000000..609d8c30d88072417052e0769930d6feba7bbe04 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/echo.h @@ -0,0 +1,102 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Echo Virtual Channel Extension + * + * Copyright 2014 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_ECHO_SERVER_H +#define FREERDP_CHANNEL_ECHO_SERVER_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum ECHO_SERVER_OPEN_RESULT + { + ECHO_SERVER_OPEN_RESULT_OK = 0, + ECHO_SERVER_OPEN_RESULT_CLOSED = 1, + ECHO_SERVER_OPEN_RESULT_NOTSUPPORTED = 2, + ECHO_SERVER_OPEN_RESULT_ERROR = 3 + } ECHO_SERVER_OPEN_RESULT; + + typedef struct s_echo_server_context echo_server_context; + + typedef BOOL (*psEchoServerChannelIdAssigned)(echo_server_context* context, UINT32 channelId); + + typedef UINT (*psEchoServerOpen)(echo_server_context* context); + typedef UINT (*psEchoServerClose)(echo_server_context* context); + typedef BOOL (*psEchoServerRequest)(echo_server_context* context, const BYTE* buffer, + UINT32 length); + + typedef UINT (*psEchoServerOpenResult)(echo_server_context* context, + ECHO_SERVER_OPEN_RESULT result); + typedef UINT (*psEchoServerResponse)(echo_server_context* context, const BYTE* buffer, + UINT32 length); + + struct s_echo_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* data; + + /*** APIs called by the server. ***/ + /** + * Open the echo channel. + */ + psEchoServerOpen Open; + /** + * Close the echo channel. + */ + psEchoServerClose Close; + /** + * Send echo request PDU. + */ + psEchoServerRequest Request; + + /*** Callbacks registered by the server. ***/ + /** + * Indicate whether the channel is opened successfully. + */ + psEchoServerOpenResult OpenResult; + /** + * Receive echo response PDU. + */ + psEchoServerResponse Response; + + rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psEchoServerChannelIdAssigned ChannelIdAssigned; + }; + + FREERDP_API void echo_server_context_free(echo_server_context* context); + + WINPR_ATTR_MALLOC(echo_server_context_free, 1) + FREERDP_API echo_server_context* echo_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_ECHO_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/encomsp.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/encomsp.h new file mode 100644 index 0000000000000000000000000000000000000000..534fd3e18788d2364524925733865ccadf2f82d9 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/encomsp.h @@ -0,0 +1,104 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Multiparty Virtual Channel + * + * Copyright 2014 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_ENCOMSP_SERVER_ENCOMSP_H +#define FREERDP_CHANNEL_ENCOMSP_SERVER_ENCOMSP_H + +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Server Interface + */ + + typedef struct s_encomsp_server_context EncomspServerContext; + typedef struct s_encomsp_server_private EncomspServerPrivate; + + typedef UINT (*psEncomspStart)(EncomspServerContext* context); + typedef UINT (*psEncomspStop)(EncomspServerContext* context); + + typedef UINT (*psEncomspFilterUpdated)(EncomspServerContext* context, + ENCOMSP_FILTER_UPDATED_PDU* filterUpdated); + typedef UINT (*psEncomspApplicationCreated)( + EncomspServerContext* context, ENCOMSP_APPLICATION_CREATED_PDU* applicationCreated); + typedef UINT (*psEncomspApplicationRemoved)( + EncomspServerContext* context, ENCOMSP_APPLICATION_REMOVED_PDU* applicationRemoved); + typedef UINT (*psEncomspWindowCreated)(EncomspServerContext* context, + ENCOMSP_WINDOW_CREATED_PDU* windowCreated); + typedef UINT (*psEncomspWindowRemoved)(EncomspServerContext* context, + ENCOMSP_WINDOW_REMOVED_PDU* windowRemoved); + typedef UINT (*psEncomspShowWindow)(EncomspServerContext* context, + ENCOMSP_SHOW_WINDOW_PDU* showWindow); + typedef UINT (*psEncomspParticipantCreated)( + EncomspServerContext* context, ENCOMSP_PARTICIPANT_CREATED_PDU* participantCreated); + typedef UINT (*psEncomspParticipantRemoved)( + EncomspServerContext* context, ENCOMSP_PARTICIPANT_REMOVED_PDU* participantRemoved); + typedef UINT (*psEncomspChangeParticipantControlLevel)( + EncomspServerContext* context, + ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* changeParticipantControlLevel); + typedef UINT (*psEncomspGraphicsStreamPaused)( + EncomspServerContext* context, ENCOMSP_GRAPHICS_STREAM_PAUSED_PDU* graphicsStreamPaused); + typedef UINT (*psEncomspGraphicsStreamResumed)( + EncomspServerContext* context, ENCOMSP_GRAPHICS_STREAM_RESUMED_PDU* graphicsStreamResumed); + + struct s_encomsp_server_context + { + HANDLE vcm; + void* custom; + + psEncomspStart Start; + psEncomspStop Stop; + + psEncomspFilterUpdated FilterUpdated; + psEncomspApplicationCreated ApplicationCreated; + psEncomspApplicationRemoved ApplicationRemoved; + psEncomspWindowCreated WindowCreated; + psEncomspWindowRemoved WindowRemoved; + psEncomspShowWindow ShowWindow; + psEncomspParticipantCreated ParticipantCreated; + psEncomspParticipantRemoved ParticipantRemoved; + psEncomspChangeParticipantControlLevel ChangeParticipantControlLevel; + psEncomspGraphicsStreamPaused GraphicsStreamPaused; + psEncomspGraphicsStreamResumed GraphicsStreamResumed; + + EncomspServerPrivate* priv; + + rdpContext* rdpcontext; + }; + + FREERDP_API void encomsp_server_context_free(EncomspServerContext* context); + + WINPR_ATTR_MALLOC(encomsp_server_context_free, 1) + FREERDP_API EncomspServerContext* encomsp_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_ENCOMSP_SERVER_ENCOMSP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/gfxredir.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/gfxredir.h new file mode 100644 index 0000000000000000000000000000000000000000..4bd7480f917216068c53c2a03829346c56a44943 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/gfxredir.h @@ -0,0 +1,104 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPXXXX Remote App Graphics Redirection Virtual Channel Extension + * + * Copyright 2020 Microsoft + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_GFXREDIR_SERVER_GFXREDIR_H +#define FREERDP_CHANNEL_GFXREDIR_SERVER_GFXREDIR_H + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_gfxredir_server_private GfxRedirServerPrivate; + typedef struct s_gfxredir_server_context GfxRedirServerContext; + + typedef UINT (*psGfxRedirOpen)(GfxRedirServerContext* context); + typedef UINT (*psGfxRedirClose)(GfxRedirServerContext* context); + + typedef UINT (*psGfxRedirError)(GfxRedirServerContext* context, + const GFXREDIR_ERROR_PDU* error); + + typedef UINT (*psGfxRedirGraphicsRedirectionLegacyCaps)( + GfxRedirServerContext* context, const GFXREDIR_LEGACY_CAPS_PDU* graphicsCaps); + + typedef UINT (*psGfxRedirGraphicsRedirectionCapsAdvertise)( + GfxRedirServerContext* context, const GFXREDIR_CAPS_ADVERTISE_PDU* graphicsCapsAdvertise); + typedef UINT (*psGfxRedirGraphicsRedirectionCapsConfirm)( + GfxRedirServerContext* context, const GFXREDIR_CAPS_CONFIRM_PDU* graphicsCapsConfirm); + + typedef UINT (*psGfxRedirOpenPool)(GfxRedirServerContext* context, + const GFXREDIR_OPEN_POOL_PDU* openPool); + typedef UINT (*psGfxRedirClosePool)(GfxRedirServerContext* context, + const GFXREDIR_CLOSE_POOL_PDU* closePool); + + typedef UINT (*psGfxRedirCreateBuffer)(GfxRedirServerContext* context, + const GFXREDIR_CREATE_BUFFER_PDU* createBuffer); + typedef UINT (*psGfxRedirDestroyBuffer)(GfxRedirServerContext* context, + const GFXREDIR_DESTROY_BUFFER_PDU* destroyBuffer); + + typedef UINT (*psGfxRedirPresentBuffer)(GfxRedirServerContext* context, + const GFXREDIR_PRESENT_BUFFER_PDU* presentBuffer); + typedef UINT (*psGfxRedirPresentBufferAck)( + GfxRedirServerContext* context, const GFXREDIR_PRESENT_BUFFER_ACK_PDU* presentBufferAck); + + struct s_gfxredir_server_context + { + void* custom; + HANDLE vcm; + + psGfxRedirOpen Open; + psGfxRedirClose Close; + + psGfxRedirError Error; + + psGfxRedirGraphicsRedirectionLegacyCaps GraphicsRedirectionLegacyCaps; + + psGfxRedirGraphicsRedirectionCapsAdvertise GraphicsRedirectionCapsAdvertise; + psGfxRedirGraphicsRedirectionCapsConfirm GraphicsRedirectionCapsConfirm; + + psGfxRedirOpenPool OpenPool; + psGfxRedirClosePool ClosePool; + + psGfxRedirCreateBuffer CreateBuffer; + psGfxRedirDestroyBuffer DestroyBuffer; + + psGfxRedirPresentBuffer PresentBuffer; + psGfxRedirPresentBufferAck PresentBufferAck; + + GfxRedirServerPrivate* priv; + rdpContext* rdpcontext; + + UINT32 confirmedCapsVersion; + }; + + FREERDP_API void gfxredir_server_context_free(GfxRedirServerContext* context); + + WINPR_ATTR_MALLOC(gfxredir_server_context_free, 1) + FREERDP_API GfxRedirServerContext* gfxredir_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_GFXREDIR_SERVER_GFXREDIR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/location.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/location.h new file mode 100644 index 0000000000000000000000000000000000000000..8078878f999bcbc2e6cdd5481a6e542cb5882746 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/location.h @@ -0,0 +1,142 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Location Virtual Channel Extension + * + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_LOCATION_SERVER_LOCATION_H +#define FREERDP_CHANNEL_LOCATION_SERVER_LOCATION_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_location_server_context LocationServerContext; + + typedef UINT (*psLocationServerOpen)(LocationServerContext* context); + typedef UINT (*psLocationServerClose)(LocationServerContext* context); + + typedef BOOL (*psLocationServerChannelIdAssigned)(LocationServerContext* context, + UINT32 channelId); + + typedef UINT (*psLocationServerInitialize)(LocationServerContext* context, BOOL externalThread); + typedef UINT (*psLocationServerPoll)(LocationServerContext* context); + typedef BOOL (*psLocationServerChannelHandle)(LocationServerContext* context, HANDLE* handle); + + typedef UINT (*psLocationServerServerReady)(LocationServerContext* context, + const RDPLOCATION_SERVER_READY_PDU* serverReady); + typedef UINT (*psLocationServerClientReady)(LocationServerContext* context, + const RDPLOCATION_CLIENT_READY_PDU* clientReady); + + typedef UINT (*psLocationServerBaseLocation3D)( + LocationServerContext* context, const RDPLOCATION_BASE_LOCATION3D_PDU* baseLocation3D); + typedef UINT (*psLocationServerLocation2DDelta)( + LocationServerContext* context, const RDPLOCATION_LOCATION2D_DELTA_PDU* location2DDelta); + typedef UINT (*psLocationServerLocation3DDelta)( + LocationServerContext* context, const RDPLOCATION_LOCATION3D_DELTA_PDU* location3DDelta); + + struct s_location_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* userdata; + + /*** APIs called by the server. ***/ + + /** + * Optional: Set thread handling. + * When externalThread=TRUE, the application is responsible to call + * Poll() periodically to process channel events. + * + * Defaults to externalThread=FALSE + */ + psLocationServerInitialize Initialize; + + /** + * Open the location channel. + */ + psLocationServerOpen Open; + + /** + * Close the location channel. + */ + psLocationServerClose Close; + + /** + * Poll + * When externalThread=TRUE, call Poll() periodically from your main loop. + * If externalThread=FALSE do not call. + */ + psLocationServerPoll Poll; + + /** + * Retrieve the channel handle for use in conjunction with Poll(). + * If externalThread=FALSE do not call. + */ + psLocationServerChannelHandle ChannelHandle; + + /* All PDUs sent by the server don't require the header to be set */ + + /* + * Send a ServerReady PDU. + */ + psLocationServerServerReady ServerReady; + + /*** Callbacks registered by the server. ***/ + + /** + * Callback, when the channel got its id assigned. + */ + psLocationServerChannelIdAssigned ChannelIdAssigned; + + /** + * Callback for the ClientReady PDU. + */ + psLocationServerClientReady ClientReady; + + /** + * Callback for the BaseLocation3D PDU. + */ + psLocationServerBaseLocation3D BaseLocation3D; + + /** + * Callback for the Location2DDelta PDU. + */ + psLocationServerLocation2DDelta Location2DDelta; + + /** + * Callback for the Location3DDelta PDU. + */ + psLocationServerLocation3DDelta Location3DDelta; + + rdpContext* rdpcontext; + }; + + FREERDP_API void location_server_context_free(LocationServerContext* context); + + WINPR_ATTR_MALLOC(location_server_context_free, 1) + FREERDP_API LocationServerContext* location_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_LOCATION_SERVER_LOCATION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_config.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_config.h new file mode 100644 index 0000000000000000000000000000000000000000..73f7707061be745cda835e1a912389b3c285aa9d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_config.h @@ -0,0 +1,246 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Proxy Server + * + * Copyright 2021-2023 Armin Novak + * Copyright 2021-2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FREERDP_SERVER_PROXY_CONFIG_H +#define FREERDP_SERVER_PROXY_CONFIG_H + +#include +#include + +#include +#include + +/** @defgroup proxy_config Proxy Configuration + * @ingroup proxy + * @{ + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct proxy_config proxyConfig; + + struct proxy_config + { + /* server */ + char* Host; + UINT16 Port; + + /* target */ + BOOL FixedTarget; + char* TargetHost; + UINT16 TargetPort; + char* TargetUser; + char* TargetDomain; + char* TargetPassword; + + /* input */ + BOOL Keyboard; + BOOL Mouse; + BOOL Multitouch; + + /* server security */ + BOOL ServerTlsSecurity; + BOOL ServerRdpSecurity; + BOOL ServerNlaSecurity; + + /* client security */ + BOOL ClientNlaSecurity; + BOOL ClientTlsSecurity; + BOOL ClientRdpSecurity; + BOOL ClientAllowFallbackToTls; + + /* channels */ + BOOL GFX; + BOOL DisplayControl; + BOOL Clipboard; + BOOL AudioOutput; + BOOL AudioInput; + BOOL RemoteApp; + BOOL DeviceRedirection; + BOOL VideoRedirection; + BOOL CameraRedirection; + + BOOL PassthroughIsBlacklist; + char** Passthrough; + size_t PassthroughCount; + char** Intercept; + size_t InterceptCount; + + /* clipboard specific settings */ + WINPR_DEPRECATED_VAR("[since 3.6.0] Unused, ignore", BOOL TextOnly); + WINPR_DEPRECATED_VAR("[since 3.6.0] Unused, ignore", UINT32 MaxTextLength); + + /* gfx settings */ + WINPR_DEPRECATED_VAR("[since 3.6.0] Unused, ignore", BOOL DecodeGFX); + + /* modules */ + char** Modules; /* module file names to load */ + size_t ModulesCount; + + char** RequiredPlugins; /* required plugin names */ + size_t RequiredPluginsCount; + + char* CertificateFile; + char* CertificateContent; + + char* PrivateKeyFile; + char* PrivateKeyContent; + + /* Data extracted from CertificateContent or CertificateFile (evaluation in this order) */ + char* CertificatePEM; + size_t CertificatePEMLength; + + /* Data extracted from PrivateKeyContent or PrivateKeyFile (evaluation in this order) */ + char* PrivateKeyPEM; + size_t PrivateKeyPEMLength; + + wIniFile* ini; + + /* target continued */ + UINT32 TargetTlsSecLevel; /** @since version 3.2.0 */ + }; + + /** + * @brief pf_server_config_dump Dumps a default INI configuration file + * @param file The file to write to. Existing files are truncated. + * @return TRUE for success, FALSE if the file could not be written. + */ + FREERDP_API BOOL pf_server_config_dump(const char* file); + + /** + * @brief pf_server_config_free Releases all resources associated with proxyConfig + * + * @param config A pointer to the proxyConfig to clean up. Might be NULL. + */ + FREERDP_API void pf_server_config_free(proxyConfig* config); + + /** + * @brief server_config_load_ini Create a proxyConfig from a already loaded + * INI file. + * + * @param ini A pointer to the parsed INI file. Must NOT be NULL. + * + * @return A proxyConfig or NULL in case of failure. + */ + WINPR_ATTR_MALLOC(pf_server_config_free, 1) + FREERDP_API proxyConfig* server_config_load_ini(wIniFile* ini); + /** + * @brief pf_server_config_load_file Create a proxyConfig from a INI file found at path. + * + * @param path The path of the INI file + * + * @return A proxyConfig or NULL in case of failure. + */ + WINPR_ATTR_MALLOC(pf_server_config_free, 1) + FREERDP_API proxyConfig* pf_server_config_load_file(const char* path); + + /** + * @brief pf_server_config_load_buffer Create a proxyConfig from a memory string buffer in INI + * file format + * + * @param buffer A pointer to the '\0' terminated INI string. + * + * @return A proxyConfig or NULL in case of failure. + */ + WINPR_ATTR_MALLOC(pf_server_config_free, 1) + FREERDP_API proxyConfig* pf_server_config_load_buffer(const char* buffer); + + /** + * @brief pf_server_config_print Print the configuration to stdout + * + * @param config A pointer to the configuration to print. Must NOT be NULL. + */ + FREERDP_API void pf_server_config_print(const proxyConfig* config); + + /** + * @brief pf_config_required_plugins_count + * + * @param config A pointer to the proxyConfig. Must NOT be NULL. + * + * @return The number of required plugins configured. + */ + FREERDP_API size_t pf_config_required_plugins_count(const proxyConfig* config); + + /** + * @brief pf_config_required_plugin + * @param config A pointer to the proxyConfig. Must NOT be NULL. + * @param index The index of the plugin to return + * + * @return The name of the plugin or NULL. + */ + FREERDP_API const char* pf_config_required_plugin(const proxyConfig* config, size_t index); + + /** + * @brief pf_config_modules_count + * + * @param config A pointer to the proxyConfig. Must NOT be NULL. + * + * @return The number of proxy modules configured. + */ + FREERDP_API size_t pf_config_modules_count(const proxyConfig* config); + + /** + * @brief pf_config_modules + * @param config A pointer to the proxyConfig. Must NOT be NULL. + * + * @return An array of strings of size pf_config_modules_count with the module names. + */ + FREERDP_API const char** pf_config_modules(const proxyConfig* config); + + /** + * @brief pf_config_clone Create a copy of the configuration + * @param dst A pointer that receives the newly allocated copy + * @param config The source configuration to copy + * + * @return TRUE for success, FALSE otherwise + */ + FREERDP_API BOOL pf_config_clone(proxyConfig** dst, const proxyConfig* config); + + /** + * @brief pf_config_plugin Register a proxy plugin handling event filtering + * defined in the configuration. + * + * @param plugins_manager The plugin manager + * @param userdata A proxyConfig* to use as reference + * + * @return TRUE for success, FALSE for failure + */ + FREERDP_API BOOL pf_config_plugin(proxyPluginsManager* plugins_manager, void* userdata); + + /** + * @brief pf_config_get get a value for a section/key + * @param config A pointer to the proxyConfig. Must NOT be NULL. + * @param section The name of the section the key is in, must not be \b NULL + * @param key The name of the key to look for. Must not be \b NULL + * + * @return A pointer to the value for \b section/key or \b NULL if not found + */ + FREERDP_API const char* pf_config_get(const proxyConfig* config, const char* section, + const char* key); + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif /* FREERDP_SERVER_PROXY_CONFIG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_context.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_context.h new file mode 100644 index 0000000000000000000000000000000000000000..0132c666ac5f6e8e702f7619cfb31f15e68daa0a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_context.h @@ -0,0 +1,186 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Proxy Server + * + * Copyright 2019 Mati Shabtay + * Copyright 2019 Kobi Mizrachi + * Copyright 2019 Idan Freiberg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SERVER_PROXY_PFCONTEXT_H +#define FREERDP_SERVER_PROXY_PFCONTEXT_H + +#include +#include + +#include +#include + +#include +#include + +#define PROXY_SESSION_ID_LENGTH 32 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct proxy_data proxyData; + typedef struct proxy_module proxyModule; + typedef struct p_server_static_channel_context pServerStaticChannelContext; + + typedef struct s_InterceptContextMapEntry + { + void (*free)(struct s_InterceptContextMapEntry*); + } InterceptContextMapEntry; + + /* All proxy interception channels derive from this base struct + * and set their cleanup function accordingly. */ + FREERDP_API void intercept_context_entry_free(void* obj); + typedef PfChannelResult (*proxyChannelDataFn)(proxyData* pdata, + const pServerStaticChannelContext* channel, + const BYTE* xdata, size_t xsize, UINT32 flags, + size_t totalSizepServer); + typedef void (*proxyChannelContextDtor)(void* context); + + /** @brief per channel configuration */ + struct p_server_static_channel_context + { + char* channel_name; + UINT32 front_channel_id; + UINT32 back_channel_id; + pf_utils_channel_mode channelMode; + proxyChannelDataFn onFrontData; + proxyChannelDataFn onBackData; + proxyChannelContextDtor contextDtor; + void* context; + }; + + void StaticChannelContext_free(pServerStaticChannelContext* ctx); + + /** + * Wraps rdpContext and holds the state for the proxy's server. + */ + struct p_server_context + { + rdpContext context; + + proxyData* pdata; + + HANDLE vcm; + HANDLE dynvcReady; + + wHashTable* interceptContextMap; + wHashTable* channelsByFrontId; + wHashTable* channelsByBackId; + }; + typedef struct p_server_context pServerContext; + + WINPR_ATTR_MALLOC(StaticChannelContext_free, 1) + pServerStaticChannelContext* StaticChannelContext_new(pServerContext* ps, const char* name, + UINT32 id); + + /** + * Wraps rdpContext and holds the state for the proxy's client. + */ + typedef struct p_client_context pClientContext; + + struct p_client_context + { + rdpContext context; + + proxyData* pdata; + + /* + * In a case when freerdp_connect fails, + * Used for NLA fallback feature, to check if the server should close the connection. + * When it is set to TRUE, proxy's client knows it shouldn't signal the server thread to + * closed the connection when pf_client_post_disconnect is called, because it is trying to + * connect reconnect without NLA. It must be set to TRUE before the first try, and to FALSE + * after the connection fully established, to ensure graceful shutdown of the connection + * when it will be closed. + */ + BOOL allow_next_conn_failure; + + BOOL connected; /* Set after client post_connect. */ + + pReceiveChannelData client_receive_channel_data_original; + wQueue* cached_server_channel_data; + BOOL (*sendChannelData)(pClientContext* pc, const proxyChannelDataEventInfo* ev); + + /* X509 specific */ + char* remote_hostname; + wStream* remote_pem; + UINT16 remote_port; + UINT32 remote_flags; + + BOOL input_state_sync_pending; + UINT32 input_state; + + wHashTable* interceptContextMap; + UINT32 computerNameLen; + BOOL computerNameUnicode; + union + { + WCHAR* wc; + char* c; + void* v; + } computerName; + }; + + /** + * Holds data common to both sides of a proxy's session. + */ + struct proxy_data + { + proxyModule* module; + const proxyConfig* config; + + pServerContext* ps; + pClientContext* pc; + + HANDLE abort_event; + HANDLE client_thread; + HANDLE gfx_server_ready; + + char session_id[PROXY_SESSION_ID_LENGTH + 1]; + + /* used to external modules to store per-session info */ + wHashTable* modules_info; + psPeerReceiveChannelData server_receive_channel_data_original; + }; + + FREERDP_API BOOL pf_context_copy_settings(rdpSettings* dst, const rdpSettings* src); + FREERDP_API BOOL pf_context_init_server_context(freerdp_peer* client); + + WINPR_ATTR_MALLOC(freerdp_client_context_free, 1) + FREERDP_API pClientContext* pf_context_create_client_context(const rdpSettings* clientSettings); + + FREERDP_API void proxy_data_free(proxyData* pdata); + + WINPR_ATTR_MALLOC(proxy_data_free, 1) + FREERDP_API proxyData* proxy_data_new(void); + FREERDP_API void proxy_data_set_client_context(proxyData* pdata, pClientContext* context); + FREERDP_API void proxy_data_set_server_context(proxyData* pdata, pServerContext* context); + + FREERDP_API BOOL proxy_data_shall_disconnect(proxyData* pdata); + FREERDP_API void proxy_data_abort_connect(proxyData* pdata); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SERVER_PROXY_PFCONTEXT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_log.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_log.h new file mode 100644 index 0000000000000000000000000000000000000000..3f3be2c41fe18cc9b7859f5752827a9407b21689 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_log.h @@ -0,0 +1,53 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Proxy Server + * + * Copyright 2019 Mati Shabtay + * Copyright 2019 Kobi Mizrachi + * Copyright 2019 Idan Freiberg + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SERVER_PROXY_LOG_H +#define FREERDP_SERVER_PROXY_LOG_H + +#include +#include + +#define PROXY_TAG(tag) FREERDP_TAG("proxy." tag) + +/* + * log format in proxy is: + * "[SessionID=%s]: Log message" + * SessionID is optional, but if they should be written to the log, + * that's the format. + */ + +/* log macros that prepends session id and function name tp the log message */ +#define PROXY_LOG_INFO(_tag, _context, _format, ...) \ + WLog_INFO(TAG, "[SessionID=%s]: " _format, \ + (_context && _context->pdata) ? _context->pdata->session_id : "null", ##__VA_ARGS__) +#define PROXY_LOG_ERR(_tag, _context, _format, ...) \ + WLog_ERR(TAG, "[SessionID=%s]: " _format, \ + (_context && _context->pdata) ? _context->pdata->session_id : "null", ##__VA_ARGS__) +#define PROXY_LOG_DBG(_tag, _context, _format, ...) \ + WLog_DBG(TAG, "[SessionID=%s]: " _format, \ + (_context && _context->pdata) ? _context->pdata->session_id : "null", ##__VA_ARGS__) +#define PROXY_LOG_WARN(_tag, _context, _format, ...) \ + WLog_WARN(TAG, "[SessionID=%s]: " _format, \ + (_context && _context->pdata) ? _context->pdata->session_id : "null", ##__VA_ARGS__) + +#endif /* FREERDP_SERVER_PROXY_LOG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_modules_api.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_modules_api.h new file mode 100644 index 0000000000000000000000000000000000000000..1887f9091f29a18e7bec3b3f1ab7f372955339aa --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_modules_api.h @@ -0,0 +1,241 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Proxy Server + * + * Copyright 2019 Kobi Mizrachi + * Copyright 2019 Idan Freiberg + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SERVER_PROXY_MODULES_API_H +#define FREERDP_SERVER_PROXY_MODULES_API_H + +#include +#include +#include + +#include + +#define MODULE_TAG(module) "proxy.modules." module + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct proxy_data proxyData; + typedef struct proxy_module proxyModule; + typedef struct proxy_plugin proxyPlugin; + typedef struct proxy_plugins_manager proxyPluginsManager; + + /* hook callback. should return TRUE on success or FALSE on error. */ + typedef BOOL (*proxyHookFn)(proxyPlugin*, proxyData*, void*); + + /* + * Filter callback: + * It MUST return TRUE if the related event should be proxied, + * or FALSE if it should be ignored. + */ + typedef BOOL (*proxyFilterFn)(proxyPlugin*, proxyData*, void*); + + /* describes a plugin: name, description and callbacks to execute. + * + * This is public API, so always add new fields at the end of the struct to keep + * some backward compatibility. + */ + struct proxy_plugin + { + const char* name; /* 0: unique module name */ + const char* description; /* 1: module description */ + + UINT64 reserved1[32 - 2]; /* 2-32 */ + + BOOL (*PluginUnload)(proxyPlugin* plugin); /* 33 */ + UINT64 reserved2[66 - 34]; /* 34 - 65 */ + + /* proxy hooks. a module can set these function pointers to register hooks */ + proxyHookFn ClientInitConnect; /* 66 custom=rdpContext* */ + proxyHookFn ClientUninitConnect; /* 67 custom=rdpContext* */ + proxyHookFn ClientPreConnect; /* 68 custom=rdpContext* */ + proxyHookFn ClientPostConnect; /* 69 custom=rdpContext* */ + proxyHookFn ClientPostDisconnect; /* 70 custom=rdpContext* */ + proxyHookFn ClientX509Certificate; /* 71 custom=rdpContext* */ + proxyHookFn ClientLoginFailure; /* 72 custom=rdpContext* */ + proxyHookFn ClientEndPaint; /* 73 custom=rdpContext* */ + proxyHookFn ClientRedirect; /* 74 custom=rdpContext* */ + proxyHookFn ClientLoadChannels; /* 75 custom=rdpContext* */ + UINT64 reserved3[96 - 76]; /* 76-95 */ + + proxyHookFn ServerPostConnect; /* 96 custom=freerdp_peer* */ + proxyHookFn ServerPeerActivate; /* 97 custom=freerdp_peer* */ + proxyHookFn ServerChannelsInit; /* 98 custom=freerdp_peer* */ + proxyHookFn ServerChannelsFree; /* 99 custom=freerdp_peer* */ + proxyHookFn ServerSessionEnd; /* 100 custom=freerdp_peer* */ + proxyHookFn ServerSessionInitialize; /* 101 custom=freerdp_peer* */ + proxyHookFn ServerSessionStarted; /* 102 custom=freerdp_peer* */ + + UINT64 reserved4[128 - 103]; /* 103 - 127 */ + + /* proxy filters. a module can set these function pointers to register filters */ + proxyFilterFn KeyboardEvent; /* 128 */ + proxyFilterFn MouseEvent; /* 129 */ + proxyFilterFn ClientChannelData; /* 130 passthrough channels data */ + proxyFilterFn ServerChannelData; /* 131 passthrough channels data */ + proxyFilterFn DynamicChannelCreate; /* 132 passthrough drdynvc channel create data */ + proxyFilterFn ServerFetchTargetAddr; /* 133 */ + proxyFilterFn ServerPeerLogon; /* 134 */ + proxyFilterFn ChannelCreate; /* 135 passthrough drdynvc channel create data */ + proxyFilterFn UnicodeEvent; /* 136 */ + proxyFilterFn MouseExEvent; /* 137 */ + + /* proxy dynamic channel filters: + * + * - a function that returns the list of channels to intercept + * - a function to call with the data received + */ + proxyFilterFn DynChannelToIntercept; /* 138 */ + proxyFilterFn DynChannelIntercept; /* 139 */ + proxyFilterFn StaticChannelToIntercept; /* 140 */ + UINT64 reserved5[160 - 141]; /* 141-159 */ + + /* Runtime data fields */ + proxyPluginsManager* mgr; /* 160 */ /** Set during plugin registration */ + void* userdata; /* 161 */ /** Custom data provided with RegisterPlugin, memory managed + outside of plugin. */ + void* custom; /* 162 */ /** Custom configuration data, must be allocated in RegisterPlugin + and freed in PluginUnload */ + + UINT64 reserved6[192 - 163]; /* 163-191 Add some filler data to allow for new callbacks or + * fields without breaking API */ + }; + + /* + * Main API for use by external modules. + * Supports: + * - Registering a plugin. + * - Setting/getting plugin's per-session specific data. + * - Aborting a session. + */ + struct proxy_plugins_manager + { + /* 0 used for registering a fresh new proxy plugin. */ + BOOL (*RegisterPlugin)(struct proxy_plugins_manager* mgr, const proxyPlugin* plugin); + + /* 1 used for setting plugin's per-session info. */ + BOOL (*SetPluginData)(struct proxy_plugins_manager* mgr, const char*, proxyData*, void*); + + /* 2 used for getting plugin's per-session info. */ + void* (*GetPluginData)(struct proxy_plugins_manager* mgr, const char*, proxyData*); + + /* 3 used for aborting a session. */ + void (*AbortConnect)(struct proxy_plugins_manager* mgr, proxyData*); + + UINT64 reserved[128 - 4]; /* 4-127 reserved fields */ + }; + + typedef BOOL (*proxyModuleEntryPoint)(proxyPluginsManager* plugins_manager, void* userdata); + +/* filter events parameters */ +#define WINPR_PACK_PUSH +#include +typedef struct proxy_keyboard_event_info +{ + UINT16 flags; + UINT16 rdp_scan_code; +} proxyKeyboardEventInfo; + +typedef struct proxy_unicode_event_info +{ + UINT16 flags; + UINT16 code; +} proxyUnicodeEventInfo; + +typedef struct proxy_mouse_event_info +{ + UINT16 flags; + UINT16 x; + UINT16 y; +} proxyMouseEventInfo; + +typedef struct proxy_mouse_ex_event_info +{ + UINT16 flags; + UINT16 x; + UINT16 y; +} proxyMouseExEventInfo; + +typedef struct +{ + /* channel metadata */ + const char* channel_name; + UINT16 channel_id; + + /* actual data */ + const BYTE* data; + size_t data_len; + size_t total_size; + UINT32 flags; +} proxyChannelDataEventInfo; + +typedef struct +{ + /* out values */ + char* target_address; + UINT16 target_port; + + /* + * If this value is set to true by a plugin, target info will be fetched from config and proxy + * will connect any client to the same remote server. + */ + ProxyFetchTargetMethod fetch_method; +} proxyFetchTargetEventInfo; + +typedef struct server_peer_logon +{ + const SEC_WINNT_AUTH_IDENTITY* identity; + BOOL automatic; +} proxyServerPeerLogon; + +typedef struct dyn_channel_intercept_data +{ + const char* name; + UINT32 channelId; + wStream* data; + BOOL isBackData; + BOOL first; + BOOL last; + BOOL rewritten; + size_t packetSize; + PfChannelResult result; +} proxyDynChannelInterceptData; + +typedef struct dyn_channel_to_intercept_data +{ + const char* name; + UINT32 channelId; + BOOL intercept; +} proxyChannelToInterceptData; + +#define WINPR_PACK_POP +#include + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SERVER_PROXY_MODULES_API_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_server.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_server.h new file mode 100644 index 0000000000000000000000000000000000000000..702b3268d7e940ef2d55299b4a64c67ffb5c6f83 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_server.h @@ -0,0 +1,115 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Proxy Server + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FREERDP_SERVER_PROXY_SERVER_H +#define FREERDP_SERVER_PROXY_SERVER_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct proxy_server proxyServer; + + /** + * @brief pf_server_free Cleans up a (stopped) proxy server instance. + * + * @param server The proxy server to clean up. Might be NULL. + */ + FREERDP_API void pf_server_free(proxyServer* server); + + /** + * @brief pf_server_new Creates a new proxy server instance + * + * @param config The proxy server configuration to use. Must NOT be NULL. + * + * @return A new proxy server instance or NULL on failure. + */ + WINPR_ATTR_MALLOC(pf_server_free, 1) + FREERDP_API proxyServer* pf_server_new(const proxyConfig* config); + + /** + * @brief pf_server_add_module Allows registering proxy modules that are + * built-in instead of shipped as separate + * module loaded at runtime. + * + * @param server A proxy instance to add the module to. Must NOT be NULL + * @param ep The proxy entry function to add. Must NOT be NULL + * @param userdata Custom data for the module. May be NULL + * + * @return TRUE for success, FALSE otherwise. + */ + FREERDP_API BOOL pf_server_add_module(proxyServer* server, proxyModuleEntryPoint ep, + void* userdata); + + /** + * @brief pf_server_start Starts the proxy, binding the configured port. + * + * @param server The server instance. Must NOT be NULL. + * + * @return TRUE for success, FALSE on error + */ + FREERDP_API BOOL pf_server_start(proxyServer* server); + + /** + * @brief pf_server_start_from_socket Starts the proxy using an existing bound socket + * + * @param server The server instance. Must NOT be NULL. + * @param socket The bound socket to wait for events on. + * + * @return TRUE for success, FALSE on error + */ + FREERDP_API BOOL pf_server_start_from_socket(proxyServer* server, int socket); + + /** + * @brief pf_server_start_with_peer_socket Use existing peer socket + * + * @param server The server instance. Must NOT be NULL. + * @param socket Ready to use peer socket + * + * @return TRUE for success, FALSE on error + */ + FREERDP_API BOOL pf_server_start_with_peer_socket(proxyServer* server, int socket); + + /** + * @brief pf_server_stop Stops a server instance asynchronously. + * Can be called from any thread to stop a running server instance. + * @param server A pointer to the server instance to stop. May be NULL. + */ + FREERDP_API void pf_server_stop(proxyServer* server); + + /** + * @brief pf_server_run This (blocking) function runs the main loop of the + * proxy. + * + * @param server The server instance. Must NOT be NULL. + * + * @return TRUE for successful termination, FALSE otherwise. + */ + FREERDP_API BOOL pf_server_run(proxyServer* server); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SERVER_PROXY_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_types.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_types.h new file mode 100644 index 0000000000000000000000000000000000000000..98ee4b16fd60cab430e8a41d33b58c1a61c39e42 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/proxy/proxy_types.h @@ -0,0 +1,57 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Proxy enum types + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SERVER_PROXY_TYPES_H +#define FREERDP_SERVER_PROXY_TYPES_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @brief how is handled a channel */ + typedef enum + { + PF_UTILS_CHANNEL_NOT_HANDLED, /*!< channel not handled */ + PF_UTILS_CHANNEL_BLOCK, /*!< block and drop traffic on this channel */ + PF_UTILS_CHANNEL_PASSTHROUGH, /*!< pass traffic from this channel */ + PF_UTILS_CHANNEL_INTERCEPT /*!< inspect traffic from this channel */ + } pf_utils_channel_mode; + + /** @brief result of a channel treatment */ + typedef enum + { + PF_CHANNEL_RESULT_PASS, /*!< pass the packet as is */ + PF_CHANNEL_RESULT_DROP, /*!< drop the packet */ + PF_CHANNEL_RESULT_ERROR /*!< error during packet treatment */ + } PfChannelResult; + typedef enum + { + PROXY_FETCH_TARGET_METHOD_DEFAULT, + PROXY_FETCH_TARGET_METHOD_CONFIG, + PROXY_FETCH_TARGET_METHOD_LOAD_BALANCE_INFO, + PROXY_FETCH_TARGET_USE_CUSTOM_ADDR + } ProxyFetchTargetMethod; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SERVER_PROXY_TYPES_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rail.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rail.h new file mode 100644 index 0000000000000000000000000000000000000000..0fdd1a3c181420f4c58b190c82fd0d7e3fba7838 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rail.h @@ -0,0 +1,157 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RAIL Virtual Channel Plugin + * + * Copyright 2019 Mati Shabtay + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RAIL_SERVER_RAIL_H +#define FREERDP_CHANNEL_RAIL_SERVER_RAIL_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_rail_server_context RailServerContext; + typedef struct s_rail_server_private RailServerPrivate; + + typedef UINT (*psRailStart)(RailServerContext* context); + typedef BOOL (*psRailStop)(RailServerContext* context); + + /* Client side callback types */ + typedef UINT (*psRailClientHandshake)(RailServerContext* context, + const RAIL_HANDSHAKE_ORDER* handshake); + typedef UINT (*psRailClientClientStatus)(RailServerContext* context, + const RAIL_CLIENT_STATUS_ORDER* clientStatus); + typedef UINT (*psRailClientExec)(RailServerContext* context, const RAIL_EXEC_ORDER* exec); + typedef UINT (*psRailClientSysparam)(RailServerContext* context, + const RAIL_SYSPARAM_ORDER* sysparam); + typedef UINT (*psRailClientActivate)(RailServerContext* context, + const RAIL_ACTIVATE_ORDER* activate); + typedef UINT (*psRailClientSysmenu)(RailServerContext* context, + const RAIL_SYSMENU_ORDER* sysmenu); + typedef UINT (*psRailClientSyscommand)(RailServerContext* context, + const RAIL_SYSCOMMAND_ORDER* syscommand); + typedef UINT (*psRailClientNotifyEvent)(RailServerContext* context, + const RAIL_NOTIFY_EVENT_ORDER* notifyEvent); + typedef UINT (*psRailClientGetAppidReq)(RailServerContext* context, + const RAIL_GET_APPID_REQ_ORDER* getAppidReq); + typedef UINT (*psRailClientWindowMove)(RailServerContext* context, + const RAIL_WINDOW_MOVE_ORDER* windowMove); + typedef UINT (*psRailClientSnapArrange)(RailServerContext* context, + const RAIL_SNAP_ARRANGE* snapArrange); + typedef UINT (*psRailClientLangbarInfo)(RailServerContext* context, + const RAIL_LANGBAR_INFO_ORDER* langbarInfo); + typedef UINT (*psRailClientLanguageImeInfo)(RailServerContext* context, + const RAIL_LANGUAGEIME_INFO_ORDER* languageImeInfo); + typedef UINT (*psRailClientCompartmentInfo)(RailServerContext* context, + const RAIL_COMPARTMENT_INFO_ORDER* compartmentInfo); + typedef UINT (*psRailClientCloak)(RailServerContext* context, const RAIL_CLOAK* cloak); + typedef UINT (*psRailClientTextScale)(RailServerContext* context, UINT32 TextScale); + typedef UINT (*psRailClientCaretBlinkRate)(RailServerContext* context, UINT32 CaretBlinkRate); + + /* Server side messages sending methods */ + typedef UINT (*psRailServerHandshake)(RailServerContext* context, + const RAIL_HANDSHAKE_ORDER* handshake); + typedef UINT (*psRailServerHandshakeEx)(RailServerContext* context, + const RAIL_HANDSHAKE_EX_ORDER* handshakeEx); + typedef UINT (*psRailServerSysparam)(RailServerContext* context, + const RAIL_SYSPARAM_ORDER* sysparam); + typedef UINT (*psRailServerLocalMoveSize)(RailServerContext* context, + const RAIL_LOCALMOVESIZE_ORDER* localMoveSize); + typedef UINT (*psRailServerMinMaxInfo)(RailServerContext* context, + const RAIL_MINMAXINFO_ORDER* minMaxInfo); + typedef UINT (*psRailServerTaskbarInfo)(RailServerContext* context, + const RAIL_TASKBAR_INFO_ORDER* taskbarInfo); + typedef UINT (*psRailServerLangbarInfo)(RailServerContext* context, + const RAIL_LANGBAR_INFO_ORDER* langbarInfo); + typedef UINT (*psRailServerExecResult)(RailServerContext* context, + const RAIL_EXEC_RESULT_ORDER* execResult); + typedef UINT (*psRailServerGetAppidResp)(RailServerContext* context, + const RAIL_GET_APPID_RESP_ORDER* getAppIdResp); + typedef UINT (*psRailServerZOrderSync)(RailServerContext* context, + const RAIL_ZORDER_SYNC* zOrderSync); + typedef UINT (*psRailServerCloak)(RailServerContext* context, const RAIL_CLOAK* cloak); + typedef UINT (*psRailServerPowerDisplayRequest)( + RailServerContext* context, const RAIL_POWER_DISPLAY_REQUEST* PowerDisplayRequest); + typedef UINT (*psRailServerGetAppidRespEx)(RailServerContext* context, + const RAIL_GET_APPID_RESP_EX* GetAppidRespEx); + + struct s_rail_server_context + { + HANDLE vcm; + void* custom; + + psRailStart Start; + psRailStop Stop; + + /* Callbacks from client */ + psRailClientHandshake ClientHandshake; + psRailClientClientStatus ClientClientStatus; + psRailClientExec ClientExec; + psRailClientSysparam ClientSysparam; + psRailClientActivate ClientActivate; + psRailClientSysmenu ClientSysmenu; + psRailClientSyscommand ClientSyscommand; + psRailClientNotifyEvent ClientNotifyEvent; + psRailClientGetAppidReq ClientGetAppidReq; + psRailClientWindowMove ClientWindowMove; + psRailClientSnapArrange ClientSnapArrange; + psRailClientLangbarInfo ClientLangbarInfo; + psRailClientLanguageImeInfo ClientLanguageImeInfo; + psRailClientCompartmentInfo ClientCompartmentInfo; + psRailClientCloak ClientCloak; + psRailClientTextScale ClientTextScale; + psRailClientCaretBlinkRate ClientCaretBlinkRate; + + /* Methods for sending server side messages */ + psRailServerHandshake ServerHandshake; + psRailServerHandshakeEx ServerHandshakeEx; + psRailServerSysparam ServerSysparam; + psRailServerLocalMoveSize ServerLocalMoveSize; + psRailServerMinMaxInfo ServerMinMaxInfo; + psRailServerTaskbarInfo ServerTaskbarInfo; + psRailServerLangbarInfo ServerLangbarInfo; + psRailServerExecResult ServerExecResult; + psRailServerZOrderSync ServerZOrderSync; + psRailServerCloak ServerCloak; + psRailServerPowerDisplayRequest ServerPowerDisplayRequest; + psRailServerGetAppidResp ServerGetAppidResp; + psRailServerGetAppidRespEx ServerGetAppidRespEx; + + RailServerPrivate* priv; + rdpContext* rdpcontext; + }; + + FREERDP_API void rail_server_context_free(RailServerContext* context); + + WINPR_ATTR_MALLOC(rail_server_context_free, 1) + FREERDP_API RailServerContext* rail_server_context_new(HANDLE vcm); + + FREERDP_API UINT rail_server_handle_messages(RailServerContext* context); + FREERDP_API void rail_server_set_handshake_ex_flags(RailServerContext* context, DWORD flags); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RAIL_SERVER_RAIL_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpdr.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpdr.h new file mode 100644 index 0000000000000000000000000000000000000000..8f01f1fc5e13c086fb2069fe411f2dc2f21eb659 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpdr.h @@ -0,0 +1,227 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Device Redirection Virtual Channel Server Interface + * + * Copyright 2014 Dell Software + * Copyright 2013 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPDR_SERVER_RDPDR_H +#define FREERDP_CHANNEL_RDPDR_SERVER_RDPDR_H + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Server Interface + */ + + typedef struct s_rdpdr_server_context RdpdrServerContext; + typedef struct s_rdpdr_server_private RdpdrServerPrivate; + + typedef struct + { + UINT16 Component; + UINT16 PacketId; + } RDPDR_HEADER; + +#ifndef __MINGW32__ +typedef struct +{ + UINT32 NextEntryOffset; + UINT32 FileIndex; + LARGE_INTEGER CreationTime; + LARGE_INTEGER LastAccessTime; + LARGE_INTEGER LastWriteTime; + LARGE_INTEGER ChangeTime; + LARGE_INTEGER EndOfFile; + LARGE_INTEGER AllocationSize; + UINT32 FileAttributes; + char FileName[512]; +} FILE_DIRECTORY_INFORMATION; +#endif + +typedef UINT (*psRdpdrStart)(RdpdrServerContext* context); +typedef UINT (*psRdpdrStop)(RdpdrServerContext* context); + +typedef UINT (*psRdpdrCapablityPDU)(RdpdrServerContext* context, + const RDPDR_CAPABILITY_HEADER* header, size_t size, + const BYTE* data); +typedef UINT (*psRdpdrReceivePDU)(RdpdrServerContext* context, const RDPDR_HEADER* header, + UINT error); +typedef UINT (*psRdpdrReceiveAnnounceResponse)(RdpdrServerContext* context, UINT16 VersionMajor, + UINT16 VersionMinor, UINT32 ClientId); +typedef UINT (*psRdpdrSendServerAnnounce)(RdpdrServerContext* context); +typedef UINT (*psRdpdrReceiveDeviceAnnounce)(RdpdrServerContext* context, + const RdpdrDevice* device); +typedef UINT (*psRdpdrReceiveDeviceRemove)(RdpdrServerContext* context, UINT32 deviceId, + const RdpdrDevice* device); +typedef UINT (*psRdpdrReceiveClientNameRequest)(RdpdrServerContext* context, size_t ComputerNameLen, + const char* name); + +typedef UINT (*psRdpdrDriveCreateDirectory)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, const char* path); +typedef UINT (*psRdpdrDriveDeleteDirectory)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, const char* path); +typedef UINT (*psRdpdrDriveQueryDirectory)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, const char* path); +typedef UINT (*psRdpdrDriveOpenFile)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, const char* path, UINT32 desiredAccess, + UINT32 createDisposition); +typedef UINT (*psRdpdrDriveReadFile)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, UINT32 fileId, UINT32 length, UINT32 offset); +typedef UINT (*psRdpdrDriveWriteFile)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, UINT32 fileId, const char* buffer, + UINT32 length, UINT32 offset); +typedef UINT (*psRdpdrDriveCloseFile)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, UINT32 fileId); +typedef UINT (*psRdpdrDriveDeleteFile)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, const char* path); +typedef UINT (*psRdpdrDriveRenameFile)(RdpdrServerContext* context, void* callbackData, + UINT32 deviceId, const char* oldPath, const char* newPath); + +typedef void (*psRdpdrOnDriveCreateDirectoryComplete)(RdpdrServerContext* context, + void* callbackData, UINT32 ioStatus); +typedef void (*psRdpdrOnDriveDeleteDirectoryComplete)(RdpdrServerContext* context, + void* callbackData, UINT32 ioStatus); +typedef void (*psRdpdrOnDriveQueryDirectoryComplete)(RdpdrServerContext* context, + void* callbackData, UINT32 ioStatus, + FILE_DIRECTORY_INFORMATION* fdi); +typedef void (*psRdpdrOnDriveOpenFileComplete)(RdpdrServerContext* context, void* callbackData, + UINT32 ioStatus, UINT32 deviceId, UINT32 fileId); +typedef void (*psRdpdrOnDriveReadFileComplete)(RdpdrServerContext* context, void* callbackData, + UINT32 ioStatus, const char* buffer, UINT32 length); +typedef void (*psRdpdrOnDriveWriteFileComplete)(RdpdrServerContext* context, void* callbackData, + UINT32 ioStatus, UINT32 bytesWritten); +typedef void (*psRdpdrOnDriveCloseFileComplete)(RdpdrServerContext* context, void* callbackData, + UINT32 ioStatus); +typedef void (*psRdpdrOnDriveDeleteFileComplete)(RdpdrServerContext* context, void* callbackData, + UINT32 ioStatus); +typedef void (*psRdpdrOnDriveRenameFileComplete)(RdpdrServerContext* context, void* callbackData, + UINT32 ioStatus); + +typedef UINT (*psRdpdrOnDeviceCreate)(RdpdrServerContext* context, const RdpdrDevice* device); +typedef UINT (*psRdpdrOnDeviceDelete)(RdpdrServerContext* context, UINT32 deviceId); + +struct s_rdpdr_server_context +{ + HANDLE vcm; + + psRdpdrStart Start; + psRdpdrStop Stop; + + RdpdrServerPrivate* priv; + + /* Server self-defined pointer. */ + void* data; + + /**< Server supported redirections. + * initially used to determine which redirections are supported by the + * server in the server capability, later on updated with what the client + * actually wants to have supported. + * + * Use the \b RDPDR_DTYP_* defines as a mask to check. + */ + UINT16 supported; + + /*** RDPDR message intercept callbacks */ + psRdpdrCapablityPDU ReceiveCaps; /**< Called for each received capability */ + psRdpdrCapablityPDU SendCaps; /**< Called for each capability to be sent */ + psRdpdrReceivePDU ReceivePDU; /**< Called after a RDPDR pdu was received and parsed */ + psRdpdrSendServerAnnounce + SendServerAnnounce; /**< Called before the server sends the announce message */ + psRdpdrReceiveAnnounceResponse + ReceiveAnnounceResponse; /**< Called after the client announce response is received */ + psRdpdrReceiveClientNameRequest + ReceiveClientNameRequest; /**< Called after a client name request is received */ + psRdpdrReceiveDeviceAnnounce + ReceiveDeviceAnnounce; /** < Called after a new device request was received but before the + device is added */ + psRdpdrReceiveDeviceRemove ReceiveDeviceRemove; /**< Called after a new device request was + received, but before it is removed */ + + /*** Drive APIs called by the server. ***/ + psRdpdrDriveCreateDirectory DriveCreateDirectory; + psRdpdrDriveDeleteDirectory DriveDeleteDirectory; + psRdpdrDriveQueryDirectory DriveQueryDirectory; + psRdpdrDriveOpenFile DriveOpenFile; + psRdpdrDriveReadFile DriveReadFile; + psRdpdrDriveWriteFile DriveWriteFile; + psRdpdrDriveCloseFile DriveCloseFile; + psRdpdrDriveDeleteFile DriveDeleteFile; + psRdpdrDriveRenameFile DriveRenameFile; + + /*** Drive callbacks registered by the server. ***/ + psRdpdrOnDeviceCreate OnDriveCreate; /**< Called for devices of type \b RDPDR_DTYP_FILESYSTEM + after \b ReceiveDeviceAnnounce */ + psRdpdrOnDeviceDelete OnDriveDelete; /**< Called for devices of type \b RDPDR_DTYP_FILESYSTEM + after \b ReceiveDeviceRemove */ + psRdpdrOnDriveCreateDirectoryComplete OnDriveCreateDirectoryComplete; + psRdpdrOnDriveDeleteDirectoryComplete OnDriveDeleteDirectoryComplete; + psRdpdrOnDriveQueryDirectoryComplete OnDriveQueryDirectoryComplete; + psRdpdrOnDriveOpenFileComplete OnDriveOpenFileComplete; + psRdpdrOnDriveReadFileComplete OnDriveReadFileComplete; + psRdpdrOnDriveWriteFileComplete OnDriveWriteFileComplete; + psRdpdrOnDriveCloseFileComplete OnDriveCloseFileComplete; + psRdpdrOnDriveDeleteFileComplete OnDriveDeleteFileComplete; + psRdpdrOnDriveRenameFileComplete OnDriveRenameFileComplete; + + /*** Serial Port callbacks registered by the server. ***/ + psRdpdrOnDeviceCreate OnSerialPortCreate; /**< Called for devices of type \b RDPDR_DTYP_SERIAL + after \b ReceiveDeviceAnnounce */ + psRdpdrOnDeviceDelete OnSerialPortDelete; /**< Called for devices of type \b RDPDR_DTYP_SERIAL + after \b ReceiveDeviceRemove */ + + /*** Parallel Port callbacks registered by the server. ***/ + psRdpdrOnDeviceCreate OnParallelPortCreate; /**< Called for devices of type \b + RDPDR_DTYP_PARALLEL after \b ReceiveDeviceAnnounce */ + psRdpdrOnDeviceDelete OnParallelPortDelete; /**< Called for devices of type \b + RDPDR_DTYP_PARALLEL after \b ReceiveDeviceRemove */ + + /*** Printer callbacks registered by the server. ***/ + psRdpdrOnDeviceCreate OnPrinterCreate; /**< Called for devices of type RDPDR_DTYP_PRINT after \b + ReceiveDeviceAnnounce */ + psRdpdrOnDeviceDelete OnPrinterDelete; /**< Called for devices of type RDPDR_DTYP_PRINT after \b + ReceiveDeviceRemove */ + + /*** Smartcard callbacks registered by the server. ***/ + psRdpdrOnDeviceCreate OnSmartcardCreate; /**< Called for devices of type RDPDR_DTYP_SMARTCARD + after \b ReceiveDeviceAnnounce */ + psRdpdrOnDeviceDelete OnSmartcardDelete; /**< Called for devices of type RDPDR_DTYP_SMARTCARD + after \b ReceiveDeviceRemove */ + + rdpContext* rdpcontext; +}; + +FREERDP_API void rdpdr_server_context_free(RdpdrServerContext* context); + +WINPR_ATTR_MALLOC(rdpdr_server_context_free, 1) +FREERDP_API RdpdrServerContext* rdpdr_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPDR_SERVER_RDPDR_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpecam-enumerator.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpecam-enumerator.h new file mode 100644 index 0000000000000000000000000000000000000000..800caf8a157a0489fcfb1f5a1441b51f9c36f908 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpecam-enumerator.h @@ -0,0 +1,137 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Capture Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CAM_DEV_ENUM_SERVER_CAM_DEV_ENUM_H +#define FREERDP_CHANNEL_CAM_DEV_ENUM_SERVER_CAM_DEV_ENUM_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_cam_dev_enum_server_context CamDevEnumServerContext; + + typedef UINT (*psCamDevEnumServerServerOpen)(CamDevEnumServerContext* context); + typedef UINT (*psCamDevEnumServerServerClose)(CamDevEnumServerContext* context); + + typedef BOOL (*psCamDevEnumServerServerChannelIdAssigned)(CamDevEnumServerContext* context, + UINT32 channelId); + + typedef UINT (*psCamDevEnumServerServerInitialize)(CamDevEnumServerContext* context, + BOOL externalThread); + typedef UINT (*psCamDevEnumServerServerPoll)(CamDevEnumServerContext* context); + typedef BOOL (*psCamDevEnumServerServerChannelHandle)(CamDevEnumServerContext* context, + HANDLE* handle); + + typedef UINT (*psCamDevEnumServerServerSelectVersionRequest)( + CamDevEnumServerContext* context, const CAM_SELECT_VERSION_REQUEST* selectVersionRequest); + typedef UINT (*psCamDevEnumServerServerSelectVersionResponse)( + CamDevEnumServerContext* context, const CAM_SELECT_VERSION_RESPONSE* selectVersionResponse); + + typedef UINT (*psCamDevEnumServerServerDeviceAddedNotification)( + CamDevEnumServerContext* context, + const CAM_DEVICE_ADDED_NOTIFICATION* deviceAddedNotification); + typedef UINT (*psCamDevEnumServerServerDeviceRemovedNotification)( + CamDevEnumServerContext* context, + const CAM_DEVICE_REMOVED_NOTIFICATION* deviceRemovedNotification); + + struct s_cam_dev_enum_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* userdata; + + /*** APIs called by the server. ***/ + + /** + * Optional: Set thread handling. + * When externalThread=TRUE, the application is responsible to call + * Poll() periodically to process channel events. + * + * Defaults to externalThread=FALSE + */ + psCamDevEnumServerServerInitialize Initialize; + + /** + * Open the camera device enumerator channel. + */ + psCamDevEnumServerServerOpen Open; + + /** + * Close the camera device enumerator channel. + */ + psCamDevEnumServerServerClose Close; + + /** + * Poll + * When externalThread=TRUE, call Poll() periodically from your main loop. + * If externalThread=FALSE do not call. + */ + psCamDevEnumServerServerPoll Poll; + + /** + * Retrieve the channel handle for use in conjunction with Poll(). + * If externalThread=FALSE do not call. + */ + psCamDevEnumServerServerChannelHandle ChannelHandle; + + /* + * Send a Select Version Response PDU. + */ + psCamDevEnumServerServerSelectVersionResponse SelectVersionResponse; + + /*** Callbacks registered by the server. ***/ + + /** + * Callback, when the channel got its id assigned. + */ + psCamDevEnumServerServerChannelIdAssigned ChannelIdAssigned; + + /** + * Callback for the Select Version Request PDU. + */ + psCamDevEnumServerServerSelectVersionRequest SelectVersionRequest; + + /** + * Callback for the Device Added Notification PDU. + */ + psCamDevEnumServerServerDeviceAddedNotification DeviceAddedNotification; + + /** + * Callback for the Device Removed Notification PDU. + */ + psCamDevEnumServerServerDeviceRemovedNotification DeviceRemovedNotification; + + rdpContext* rdpcontext; + }; + + FREERDP_API void cam_dev_enum_server_context_free(CamDevEnumServerContext* context); + + WINPR_ATTR_MALLOC(cam_dev_enum_server_context_free, 1) + FREERDP_API CamDevEnumServerContext* cam_dev_enum_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_CAM_DEV_ENUM_SERVER_CAM_DEV_ENUM_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpecam.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpecam.h new file mode 100644 index 0000000000000000000000000000000000000000..dd18494784fdee129168f0d554ddcd980df9dea7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpecam.h @@ -0,0 +1,284 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Video Capture Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_CAMERA_DEVICE_SERVER_CAMERA_DEVICE_H +#define FREERDP_CHANNEL_CAMERA_DEVICE_SERVER_CAMERA_DEVICE_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct camera_device_server_context CameraDeviceServerContext; + + typedef UINT (*psCameraDeviceServerOpen)(CameraDeviceServerContext* context); + typedef UINT (*psCameraDeviceServerClose)(CameraDeviceServerContext* context); + + typedef BOOL (*psCameraDeviceServerChannelIdAssigned)(CameraDeviceServerContext* context, + UINT32 channelId); + + typedef UINT (*psCameraDeviceServerInitialize)(CameraDeviceServerContext* context, + BOOL externalThread); + typedef UINT (*psCameraDeviceServerPoll)(CameraDeviceServerContext* context); + typedef BOOL (*psCameraDeviceServerChannelHandle)(CameraDeviceServerContext* context, + HANDLE* handle); + + typedef UINT (*psCameraDeviceServerSuccessResponse)( + CameraDeviceServerContext* context, const CAM_SUCCESS_RESPONSE* successResponse); + typedef UINT (*psCameraDeviceServerErrorResponse)(CameraDeviceServerContext* context, + const CAM_ERROR_RESPONSE* errorResponse); + + typedef UINT (*psCameraDeviceServerActivateDeviceRequest)( + CameraDeviceServerContext* context, + const CAM_ACTIVATE_DEVICE_REQUEST* activateDeviceRequest); + typedef UINT (*psCameraDeviceServerDeactivateDeviceRequest)( + CameraDeviceServerContext* context, + const CAM_DEACTIVATE_DEVICE_REQUEST* deactivateDeviceRequest); + + typedef UINT (*psCameraDeviceServerStreamListRequest)( + CameraDeviceServerContext* context, const CAM_STREAM_LIST_REQUEST* streamListRequest); + typedef UINT (*psCameraDeviceServerStreamListResponse)( + CameraDeviceServerContext* context, const CAM_STREAM_LIST_RESPONSE* streamListResponse); + + typedef UINT (*psCameraDeviceServerMediaTypeListRequest)( + CameraDeviceServerContext* context, + const CAM_MEDIA_TYPE_LIST_REQUEST* mediaTypeListRequest); + typedef UINT (*psCameraDeviceServerMediaTypeListResponse)( + CameraDeviceServerContext* context, + const CAM_MEDIA_TYPE_LIST_RESPONSE* mediaTypeListResponse); + + typedef UINT (*psCameraDeviceServerCurrentMediaTypeRequest)( + CameraDeviceServerContext* context, + const CAM_CURRENT_MEDIA_TYPE_REQUEST* currentMediaTypeRequest); + typedef UINT (*psCameraDeviceServerCurrentMediaTypeResponse)( + CameraDeviceServerContext* context, + const CAM_CURRENT_MEDIA_TYPE_RESPONSE* currentMediaTypeResponse); + + typedef UINT (*psCameraDeviceServerStartStreamsRequest)( + CameraDeviceServerContext* context, const CAM_START_STREAMS_REQUEST* startStreamsRequest); + typedef UINT (*psCameraDeviceServerStopStreamsRequest)( + CameraDeviceServerContext* context, const CAM_STOP_STREAMS_REQUEST* stopStreamsRequest); + + typedef UINT (*psCameraDeviceServerSampleRequest)(CameraDeviceServerContext* context, + const CAM_SAMPLE_REQUEST* sampleRequest); + typedef UINT (*psCameraDeviceServerSampleResponse)(CameraDeviceServerContext* context, + const CAM_SAMPLE_RESPONSE* sampleResponse); + typedef UINT (*psCameraDeviceServerSampleErrorResponse)( + CameraDeviceServerContext* context, const CAM_SAMPLE_ERROR_RESPONSE* sampleErrorResponse); + + typedef UINT (*psCameraDeviceServerPropertyListRequest)( + CameraDeviceServerContext* context, const CAM_PROPERTY_LIST_REQUEST* propertyListRequest); + typedef UINT (*psCameraDeviceServerPropertyListResponse)( + CameraDeviceServerContext* context, const CAM_PROPERTY_LIST_RESPONSE* propertyListResponse); + + typedef UINT (*psCameraDeviceServerPropertyValueRequest)( + CameraDeviceServerContext* context, const CAM_PROPERTY_VALUE_REQUEST* propertyValueRequest); + typedef UINT (*psCameraDeviceServerPropertyValueResponse)( + CameraDeviceServerContext* context, + const CAM_PROPERTY_VALUE_RESPONSE* propertyValueResponse); + + typedef UINT (*psCameraDeviceServerSetPropertyValueRequest)( + CameraDeviceServerContext* context, + const CAM_SET_PROPERTY_VALUE_REQUEST* setPropertyValueRequest); + + struct camera_device_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* userdata; + + /** + * Name of the virtual channel. Pointer owned by the CameraDeviceServerContext, + * meaning camera_device_server_context_free() takes care of freeing the pointer. + * + * Server implementations should sanitize the virtual channel name for invalid + * names, like names for other known channels + * ("ECHO", "AUDIO_PLAYBACK_DVC", etc.) + */ + char* virtualChannelName; + + /** + * Protocol version to be used. Every sent server to client PDU has the + * version value in the Header set to the following value. + */ + BYTE protocolVersion; + + /*** APIs called by the server. ***/ + + /** + * Optional: Set thread handling. + * When externalThread=TRUE, the application is responsible to call + * Poll() periodically to process channel events. + * + * Defaults to externalThread=FALSE + */ + psCameraDeviceServerInitialize Initialize; + + /** + * Open the camera device channel. + */ + psCameraDeviceServerOpen Open; + + /** + * Close the camera device channel. + */ + psCameraDeviceServerClose Close; + + /** + * Poll + * When externalThread=TRUE, call Poll() periodically from your main loop. + * If externalThread=FALSE do not call. + */ + psCameraDeviceServerPoll Poll; + + /** + * Retrieve the channel handle for use in conjunction with Poll(). + * If externalThread=FALSE do not call. + */ + psCameraDeviceServerChannelHandle ChannelHandle; + + /** + * For the following server to client PDUs, + * the message header does not have to be set. + */ + + /** + * Send a Activate Device Request PDU. + */ + psCameraDeviceServerActivateDeviceRequest ActivateDeviceRequest; + + /** + * Send a Deactivate Device Request PDU. + */ + psCameraDeviceServerDeactivateDeviceRequest DeactivateDeviceRequest; + + /** + * Send a Stream List Request PDU. + */ + psCameraDeviceServerStreamListRequest StreamListRequest; + + /** + * Send a Media Type List Request PDU. + */ + psCameraDeviceServerMediaTypeListRequest MediaTypeListRequest; + + /** + * Send a Current Media Type Request PDU. + */ + psCameraDeviceServerCurrentMediaTypeRequest CurrentMediaTypeRequest; + + /** + * Send a Start Streams Request PDU. + */ + psCameraDeviceServerStartStreamsRequest StartStreamsRequest; + + /** + * Send a Stop Streams Request PDU. + */ + psCameraDeviceServerStopStreamsRequest StopStreamsRequest; + + /** + * Send a Sample Request PDU. + */ + psCameraDeviceServerSampleRequest SampleRequest; + + /** + * Send a Property List Request PDU. + */ + psCameraDeviceServerPropertyListRequest PropertyListRequest; + + /** + * Send a Property Value Request PDU. + */ + psCameraDeviceServerPropertyValueRequest PropertyValueRequest; + + /** + * Send a Set Property Value Request PDU. + */ + psCameraDeviceServerSetPropertyValueRequest SetPropertyValueRequest; + + /*** Callbacks registered by the server. ***/ + + /** + * Callback, when the channel got its id assigned. + */ + psCameraDeviceServerChannelIdAssigned ChannelIdAssigned; + + /** + * Callback for the Success Response PDU. + */ + psCameraDeviceServerSuccessResponse SuccessResponse; + + /** + * Callback for the Error Response PDU. + */ + psCameraDeviceServerErrorResponse ErrorResponse; + + /** + * Callback for the Stream List Response PDU. + */ + psCameraDeviceServerStreamListResponse StreamListResponse; + + /** + * Callback for the Media Type List Response PDU. + */ + psCameraDeviceServerMediaTypeListResponse MediaTypeListResponse; + + /** + * Callback for the Current Media Type Response PDU. + */ + psCameraDeviceServerCurrentMediaTypeResponse CurrentMediaTypeResponse; + + /** + * Callback for the Sample Response PDU. + */ + psCameraDeviceServerSampleResponse SampleResponse; + + /** + * Callback for the Sample Error Response PDU. + */ + psCameraDeviceServerSampleErrorResponse SampleErrorResponse; + + /** + * Callback for the Property List Response PDU. + */ + psCameraDeviceServerPropertyListResponse PropertyListResponse; + + /** + * Callback for the Property Value Response PDU. + */ + psCameraDeviceServerPropertyValueResponse PropertyValueResponse; + + rdpContext* rdpcontext; + }; + + FREERDP_API void camera_device_server_context_free(CameraDeviceServerContext* context); + + WINPR_ATTR_MALLOC(camera_device_server_context_free, 1) + FREERDP_API CameraDeviceServerContext* camera_device_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_CAMERA_DEVICE_SERVER_CAMERA_DEVICE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpei.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpei.h new file mode 100644 index 0000000000000000000000000000000000000000..215f7f1e520bcf86741a2e8b9dd6010e6b0a3f82 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpei.h @@ -0,0 +1,81 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Extended Input channel server-side definitions + * + * Copyright 2014 Thincast Technologies Gmbh. + * Copyright 2014 David FORT + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEI_SERVER_H +#define FREERDP_CHANNEL_RDPEI_SERVER_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_rdpei_server_context RdpeiServerContext; + typedef struct s_rdpei_server_private RdpeiServerPrivate; + + struct s_rdpei_server_context + { + HANDLE vcm; + + RdpeiServerPrivate* priv; + + UINT32 clientVersion; + UINT16 maxTouchPoints; + UINT32 protocolFlags; + + /** callbacks that can be set by the user */ + UINT (*onClientReady)(RdpeiServerContext* context); + UINT (*onTouchEvent)(RdpeiServerContext* context, const RDPINPUT_TOUCH_EVENT* touchEvent); + UINT (*onPenEvent)(RdpeiServerContext* context, const RDPINPUT_PEN_EVENT* penEvent); + UINT (*onTouchReleased)(RdpeiServerContext* context, BYTE contactId); + + void* user_data; /* user data, useful for callbacks */ + + /** + * Callback, when the channel got its id assigned. + */ + BOOL (*onChannelIdAssigned)(RdpeiServerContext* context, UINT32 channelId); + }; + + FREERDP_API void rdpei_server_context_free(RdpeiServerContext* context); + + WINPR_ATTR_MALLOC(rdpei_server_context_free, 1) + FREERDP_API RdpeiServerContext* rdpei_server_context_new(HANDLE vcm); + + FREERDP_API void rdpei_server_context_reset(RdpeiServerContext* context); + + FREERDP_API HANDLE rdpei_server_get_event_handle(RdpeiServerContext* context); + FREERDP_API UINT rdpei_server_init(RdpeiServerContext* context); + FREERDP_API UINT rdpei_server_handle_messages(RdpeiServerContext* context); + + FREERDP_API UINT rdpei_server_send_sc_ready(RdpeiServerContext* context, UINT32 version, + UINT32 features); + FREERDP_API UINT rdpei_server_suspend(RdpeiServerContext* context); + FREERDP_API UINT rdpei_server_resume(RdpeiServerContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPEI_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpemsc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpemsc.h new file mode 100644 index 0000000000000000000000000000000000000000..f1ce98a1e5ebc67f6b1650548f2a2dc564eea646 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpemsc.h @@ -0,0 +1,132 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Mouse Cursor Virtual Channel Extension + * + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEMSC_SERVER_RDPEMSC_H +#define FREERDP_CHANNEL_RDPEMSC_SERVER_RDPEMSC_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_mouse_cursor_server_context MouseCursorServerContext; + + typedef UINT (*psMouseCursorServerOpen)(MouseCursorServerContext* context); + typedef UINT (*psMouseCursorServerClose)(MouseCursorServerContext* context); + + typedef BOOL (*psMouseCursorServerChannelIdAssigned)(MouseCursorServerContext* context, + UINT32 channelId); + + typedef UINT (*psMouseCursorServerInitialize)(MouseCursorServerContext* context, + BOOL externalThread); + typedef UINT (*psMouseCursorServerPoll)(MouseCursorServerContext* context); + typedef BOOL (*psMouseCursorServerChannelHandle)(MouseCursorServerContext* context, + HANDLE* handle); + + typedef UINT (*psMouseCursorServerCapsAdvertise)( + MouseCursorServerContext* context, + const RDP_MOUSE_CURSOR_CAPS_ADVERTISE_PDU* capsAdvertise); + typedef UINT (*psMouseCursorServerCapsConfirm)( + MouseCursorServerContext* context, const RDP_MOUSE_CURSOR_CAPS_CONFIRM_PDU* capsConfirm); + + typedef UINT (*psMouseCursorServerMouseptrUpdate)( + MouseCursorServerContext* context, + const RDP_MOUSE_CURSOR_MOUSEPTR_UPDATE_PDU* mouseptrUpdate); + + struct s_mouse_cursor_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* userdata; + + /*** APIs called by the server. ***/ + + /** + * Optional: Set thread handling. + * When externalThread=TRUE, the application is responsible to call + * Poll() periodically to process channel events. + * + * Defaults to externalThread=FALSE + */ + psMouseCursorServerInitialize Initialize; + + /** + * Open the mouse cursor channel. + */ + psMouseCursorServerOpen Open; + + /** + * Close the mouse cursor channel. + */ + psMouseCursorServerClose Close; + + /** + * Poll + * When externalThread=TRUE, call Poll() periodically from your main loop. + * If externalThread=FALSE do not call. + */ + psMouseCursorServerPoll Poll; + + /** + * Retrieve the channel handle for use in conjunction with Poll(). + * If externalThread=FALSE do not call. + */ + psMouseCursorServerChannelHandle ChannelHandle; + + /* All PDUs sent by the server don't require the pduType to be set */ + + /* + * Send a CapsConfirm PDU. + */ + psMouseCursorServerCapsConfirm CapsConfirm; + + /* + * Send a MouseptrUpdate PDU. + */ + psMouseCursorServerMouseptrUpdate MouseptrUpdate; + + /*** Callbacks registered by the server. ***/ + + /** + * Callback, when the channel got its id assigned. + */ + psMouseCursorServerChannelIdAssigned ChannelIdAssigned; + + /** + * Callback for the CapsAdvertise PDU. + */ + psMouseCursorServerCapsAdvertise CapsAdvertise; + + rdpContext* rdpcontext; + }; + + FREERDP_API void mouse_cursor_server_context_free(MouseCursorServerContext* context); + + WINPR_ATTR_MALLOC(mouse_cursor_server_context_free, 1) + FREERDP_API MouseCursorServerContext* mouse_cursor_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPEMSC_SERVER_RDPEMSC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpgfx.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpgfx.h new file mode 100644 index 0000000000000000000000000000000000000000..262bb386c389b2a35820e117ab06332a1c4c30c7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpgfx.h @@ -0,0 +1,156 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Graphics Pipeline Extension + * + * Copyright 2016 Jiang Zihao + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPGFX_SERVER_RDPGFX_H +#define FREERDP_CHANNEL_RDPGFX_SERVER_RDPGFX_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_rdpgfx_server_context RdpgfxServerContext; + typedef struct s_rdpgfx_server_private RdpgfxServerPrivate; + + typedef BOOL (*psRdpgfxServerOpen)(RdpgfxServerContext* context); + typedef BOOL (*psRdpgfxServerClose)(RdpgfxServerContext* context); + + typedef BOOL (*psRdpgfxServerChannelIdAssigned)(RdpgfxServerContext* context, UINT32 channelId); + + typedef BOOL (*psRdpgfxServerInitialize)(RdpgfxServerContext* context, BOOL externalThread); + + typedef UINT (*psRdpgfxResetGraphics)(RdpgfxServerContext* context, + const RDPGFX_RESET_GRAPHICS_PDU* resetGraphics); + typedef UINT (*psRdpgfxStartFrame)(RdpgfxServerContext* context, + const RDPGFX_START_FRAME_PDU* startFrame); + typedef UINT (*psRdpgfxEndFrame)(RdpgfxServerContext* context, + const RDPGFX_END_FRAME_PDU* endFrame); + typedef UINT (*psRdpgfxSurfaceCommand)(RdpgfxServerContext* context, + const RDPGFX_SURFACE_COMMAND* cmd); + typedef UINT (*psRdpgfxSurfaceFrameCommand)(RdpgfxServerContext* context, + const RDPGFX_SURFACE_COMMAND* cmd, + const RDPGFX_START_FRAME_PDU* startFrame, + const RDPGFX_END_FRAME_PDU* endFrame); + typedef UINT (*psRdpgfxDeleteEncodingContext)( + RdpgfxServerContext* context, + const RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext); + typedef UINT (*psRdpgfxCreateSurface)(RdpgfxServerContext* context, + const RDPGFX_CREATE_SURFACE_PDU* createSurface); + typedef UINT (*psRdpgfxDeleteSurface)(RdpgfxServerContext* context, + const RDPGFX_DELETE_SURFACE_PDU* deleteSurface); + typedef UINT (*psRdpgfxSolidFill)(RdpgfxServerContext* context, + const RDPGFX_SOLID_FILL_PDU* solidFill); + typedef UINT (*psRdpgfxSurfaceToSurface)(RdpgfxServerContext* context, + const RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface); + typedef UINT (*psRdpgfxSurfaceToCache)(RdpgfxServerContext* context, + const RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache); + typedef UINT (*psRdpgfxCacheToSurface)(RdpgfxServerContext* context, + const RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface); + typedef UINT (*psRdpgfxCacheImportOffer)(RdpgfxServerContext* context, + const RDPGFX_CACHE_IMPORT_OFFER_PDU* cacheImportOffer); + typedef UINT (*psRdpgfxCacheImportReply)(RdpgfxServerContext* context, + const RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply); + typedef UINT (*psRdpgfxEvictCacheEntry)(RdpgfxServerContext* context, + const RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry); + typedef UINT (*psRdpgfxMapSurfaceToOutput)( + RdpgfxServerContext* context, const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput); + typedef UINT (*psRdpgfxMapSurfaceToWindow)( + RdpgfxServerContext* context, const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow); + typedef UINT (*psRdpgfxMapSurfaceToScaledOutput)( + RdpgfxServerContext* context, + const RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU* surfaceToOutput); + typedef UINT (*psRdpgfxMapSurfaceToScaledWindow)( + RdpgfxServerContext* context, + const RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU* surfaceToWindow); + typedef UINT (*psRdpgfxCapsAdvertise)(RdpgfxServerContext* context, + const RDPGFX_CAPS_ADVERTISE_PDU* capsAdvertise); + typedef UINT (*psRdpgfxCapsConfirm)(RdpgfxServerContext* context, + const RDPGFX_CAPS_CONFIRM_PDU* capsConfirm); + typedef UINT (*psRdpgfxFrameAcknowledge)(RdpgfxServerContext* context, + const RDPGFX_FRAME_ACKNOWLEDGE_PDU* frameAcknowledge); + typedef UINT (*psRdpgfxQoeFrameAcknowledge)( + RdpgfxServerContext* context, const RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU* qoeFrameAcknowledge); + + struct s_rdpgfx_server_context + { + HANDLE vcm; + void* custom; + + psRdpgfxServerOpen Open; + psRdpgfxServerClose Close; + + psRdpgfxResetGraphics ResetGraphics; + psRdpgfxStartFrame StartFrame; + psRdpgfxEndFrame EndFrame; + psRdpgfxSurfaceCommand SurfaceCommand; + psRdpgfxSurfaceFrameCommand SurfaceFrameCommand; + psRdpgfxDeleteEncodingContext DeleteEncodingContext; + psRdpgfxCreateSurface CreateSurface; + psRdpgfxDeleteSurface DeleteSurface; + psRdpgfxSolidFill SolidFill; + psRdpgfxSurfaceToSurface SurfaceToSurface; + psRdpgfxSurfaceToCache SurfaceToCache; + psRdpgfxCacheToSurface CacheToSurface; + psRdpgfxCacheImportOffer CacheImportOffer; + psRdpgfxCacheImportReply CacheImportReply; + psRdpgfxEvictCacheEntry EvictCacheEntry; + psRdpgfxMapSurfaceToOutput MapSurfaceToOutput; + psRdpgfxMapSurfaceToWindow MapSurfaceToWindow; + psRdpgfxMapSurfaceToScaledOutput MapSurfaceToScaledOutput; + psRdpgfxMapSurfaceToScaledWindow MapSurfaceToScaledWindow; + psRdpgfxCapsAdvertise CapsAdvertise; + psRdpgfxCapsConfirm CapsConfirm; + psRdpgfxFrameAcknowledge FrameAcknowledge; + psRdpgfxQoeFrameAcknowledge QoeFrameAcknowledge; + + RdpgfxServerPrivate* priv; + rdpContext* rdpcontext; + + /** + * Callback, when the channel got its id assigned. + */ + psRdpgfxServerChannelIdAssigned ChannelIdAssigned; + /** + * Optional: Set thread handling. + * When externalThread=TRUE, the application is responsible to call + * Poll() periodically to process channel events. + * + * Defaults to externalThread=FALSE + */ + psRdpgfxServerInitialize Initialize; + }; + + FREERDP_API void rdpgfx_server_context_free(RdpgfxServerContext* context); + + WINPR_ATTR_MALLOC(rdpgfx_server_context_free, 1) + FREERDP_API RdpgfxServerContext* rdpgfx_server_context_new(HANDLE vcm); + + FREERDP_API BOOL rdpgfx_server_set_own_thread(RdpgfxServerContext* context, + BOOL internalThread); + FREERDP_API HANDLE rdpgfx_server_get_event_handle(RdpgfxServerContext* context); + FREERDP_API UINT rdpgfx_server_handle_messages(RdpgfxServerContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPGFX_SERVER_RDPGFX_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpsnd.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpsnd.h new file mode 100644 index 0000000000000000000000000000000000000000..cbd5eab3d6b0773fb3eb9df2bdfb45bcc429c783 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/rdpsnd.h @@ -0,0 +1,196 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Server Audio Virtual Channel + * + * Copyright 2012 Vic Lee + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPSND_SERVER_H +#define FREERDP_CHANNEL_RDPSND_SERVER_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_rdpsnd_server_context RdpsndServerContext; + typedef struct s_rdpsnd_server_context rdpsnd_server_context; + typedef struct s_rdpsnd_server_private RdpsndServerPrivate; + + typedef UINT (*psRdpsndStart)(RdpsndServerContext* context); + typedef UINT (*psRdpsndStop)(RdpsndServerContext* context); + + typedef BOOL (*psRdpsndChannelIdAssigned)(RdpsndServerContext* context, UINT32 channelId); + + typedef UINT (*psRdpsndServerInitialize)(RdpsndServerContext* context, BOOL ownThread); + typedef UINT (*psRdpsndServerSendFormats)(RdpsndServerContext* context); + typedef UINT (*psRdpsndServerSelectFormat)(RdpsndServerContext* context, + UINT16 client_format_index); + typedef UINT (*psRdpsndServerTraining)(RdpsndServerContext* context, UINT16 timestamp, + UINT16 packsize, BYTE* data); + typedef UINT (*psRdpsndServerTrainingConfirm)(RdpsndServerContext* context, UINT16 timestamp, + UINT16 packsize); + typedef UINT (*psRdpsndServerSendSamples)(RdpsndServerContext* context, const void* buf, + size_t nframes, UINT16 wTimestamp); + typedef UINT (*psRdpsndServerSendSamples2)(RdpsndServerContext* context, UINT16 formatNo, + const void* buf, size_t size, UINT16 timestamp, + UINT32 audioTimeStamp); + typedef UINT (*psRdpsndServerConfirmBlock)(RdpsndServerContext* context, BYTE confirmBlockNum, + UINT16 wtimestamp); + typedef UINT (*psRdpsndServerSetVolume)(RdpsndServerContext* context, UINT16 left, + UINT16 right); + typedef UINT (*psRdpsndServerClose)(RdpsndServerContext* context); + + typedef void (*psRdpsndServerActivated)(RdpsndServerContext* context); + + struct s_rdpsnd_server_context + { + HANDLE vcm; + + psRdpsndStart Start; + psRdpsndStop Stop; + + RdpsndServerPrivate* priv; + + /* Server self-defined pointer. */ + void* data; + + /* Server to request to use dynamic virtual channel. */ + BOOL use_dynamic_virtual_channel; + + /* Server supported formats. Set by server. */ + AUDIO_FORMAT* server_formats; + size_t num_server_formats; + + /* Server source PCM audio format. Set by server. */ + AUDIO_FORMAT* src_format; + + /* Server audio latency, or buffer size, in milli-seconds. Set by server. */ + UINT32 latency; + + /* Client supported formats. */ + AUDIO_FORMAT* client_formats; + UINT16 num_client_formats; + UINT16 selected_client_format; + + /* Last sent audio block number. */ + UINT8 block_no; + + /*** APIs called by the server. ***/ + /** + * Initialize the channel. The caller should check the return value to see + * whether the initialization succeed. If not, the "Activated" callback + * will not be called and the server must not call any API on this context. + */ + psRdpsndServerInitialize Initialize; + + /** + * Choose the audio format to be sent. The index argument is an index into + * the client_formats array and must be smaller than num_client_formats. + */ + psRdpsndServerSelectFormat SelectFormat; + /** + * Send audio samples. Actually bytes in the buffer must be: + * nframes * src_format.nBitsPerSample * src_format.nChannels / 8 + */ + psRdpsndServerSendSamples SendSamples; + + /** + * Called when block confirm is received from the client + */ + psRdpsndServerConfirmBlock ConfirmBlock; + /** + * Set the volume level of the client. Valid range is between 0 and 0xFFFF. + */ + psRdpsndServerSetVolume SetVolume; + /** + * Close the audio stream. + */ + psRdpsndServerClose Close; + + /*** Callbacks registered by the server. ***/ + /** + * The channel has been activated. The server maybe choose audio format and + * start audio stream from this point. Note that this callback is called + * from a different thread context so the server must be careful of thread + * synchronization. + */ + psRdpsndServerActivated Activated; + + /** + * MS-RDPEA channel version the client announces + */ + UINT16 clientVersion; + + rdpContext* rdpcontext; + + /* dwFlags in CLIENT_AUDIO_VERSION_AND_FORMATS */ + UINT32 capsFlags; + /* dwVolume in CLIENT_AUDIO_VERSION_AND_FORMATS */ + UINT32 initialVolume; + /* dwPitch in CLIENT_AUDIO_VERSION_AND_FORMATS */ + UINT32 initialPitch; + + UINT16 qualityMode; + + /** + * Send server formats and version to the client. Automatically sent, when + * opening the channel. + * Also used to restart the protocol after sending the Close PDU. + */ + psRdpsndServerSendFormats SendFormats; + /** + * Send Training PDU. + */ + psRdpsndServerTraining Training; + + /** + * Send encoded audio samples using a Wave2 PDU. + * When successful, the block_no member is incremented. + */ + psRdpsndServerSendSamples2 SendSamples2; + + /** + * Called when a TrainingConfirm PDU is received from the client. + */ + psRdpsndServerTrainingConfirm TrainingConfirm; + + /** + * Callback, when the channel got its id assigned. + * Only called, when use_dynamic_virtual_channel=TRUE. + */ + psRdpsndChannelIdAssigned ChannelIdAssigned; + }; + + FREERDP_API void rdpsnd_server_context_free(RdpsndServerContext* context); + + WINPR_ATTR_MALLOC(rdpsnd_server_context_free, 1) + FREERDP_API RdpsndServerContext* rdpsnd_server_context_new(HANDLE vcm); + + FREERDP_API void rdpsnd_server_context_reset(RdpsndServerContext*); + + FREERDP_API HANDLE rdpsnd_server_get_event_handle(RdpsndServerContext* context); + FREERDP_API UINT rdpsnd_server_handle_messages(RdpsndServerContext* context); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_RDPSND_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/remdesk.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/remdesk.h new file mode 100644 index 0000000000000000000000000000000000000000..ef4503220dac9692572f9be5abc82f000253b64e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/remdesk.h @@ -0,0 +1,67 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Assistance Virtual Channel + * + * Copyright 2014 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_REMDESK_SERVER_REMDESK_H +#define FREERDP_CHANNEL_REMDESK_SERVER_REMDESK_H + +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Server Interface + */ + + typedef struct s_remdesk_server_context RemdeskServerContext; + typedef struct s_remdesk_server_private RemdeskServerPrivate; + + typedef UINT (*psRemdeskStart)(RemdeskServerContext* context); + typedef UINT (*psRemdeskStop)(RemdeskServerContext* context); + + struct s_remdesk_server_context + { + HANDLE vcm; + void* custom; + + psRemdeskStart Start; + psRemdeskStop Stop; + + RemdeskServerPrivate* priv; + rdpContext* rdpcontext; + }; + + FREERDP_API void remdesk_server_context_free(RemdeskServerContext* context); + + WINPR_ATTR_MALLOC(remdesk_server_context_free, 1) + FREERDP_API RemdeskServerContext* remdesk_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_REMDESK_SERVER_REMDESK_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/server-common.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/server-common.h new file mode 100644 index 0000000000000000000000000000000000000000..eba831b4f99795ee009943f53a3614c118d23f62 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/server-common.h @@ -0,0 +1,44 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Server Common + * + * Copyright 2018 Armin Novak + * Copyright 2018 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SERVER_COMMON_SERVER_H +#define FREERDP_SERVER_COMMON_SERVER_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API size_t server_audin_get_formats(AUDIO_FORMAT** dst_formats); + FREERDP_API size_t server_rdpsnd_get_formats(AUDIO_FORMAT** dst_formats); + + FREERDP_API void freerdp_server_warn_unmaintained(int argc, char* argv[]); + FREERDP_API void freerdp_server_warn_experimental(int argc, char* argv[]); + FREERDP_API void freerdp_server_warn_deprecated(int argc, char* argv[]); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SERVER_COMMON_SERVER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/shadow.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/shadow.h new file mode 100644 index 0000000000000000000000000000000000000000..302b92ea13a5e1e3d4743474a4d9564155c6283b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/shadow.h @@ -0,0 +1,395 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Session Shadowing + * + * Copyright 2014 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SERVER_SHADOW_H +#define FREERDP_SERVER_SHADOW_H + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#if defined(CHANNEL_AUDIN_SERVER) +#include +#endif +#include + +#include +#include + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_shadow_client rdpShadowClient; + typedef struct rdp_shadow_server rdpShadowServer; + typedef struct rdp_shadow_screen rdpShadowScreen; + typedef struct rdp_shadow_surface rdpShadowSurface; + typedef struct rdp_shadow_encoder rdpShadowEncoder; + typedef struct rdp_shadow_capture rdpShadowCapture; + typedef struct rdp_shadow_subsystem rdpShadowSubsystem; + typedef struct rdp_shadow_multiclient_event rdpShadowMultiClientEvent; + + typedef struct S_RDP_SHADOW_ENTRY_POINTS RDP_SHADOW_ENTRY_POINTS; + typedef int (*pfnShadowSubsystemEntry)(RDP_SHADOW_ENTRY_POINTS* pEntryPoints); + + typedef rdpShadowSubsystem* (*pfnShadowSubsystemNew)(void); + typedef void (*pfnShadowSubsystemFree)(rdpShadowSubsystem* subsystem); + + typedef int (*pfnShadowSubsystemInit)(rdpShadowSubsystem* subsystem); + typedef int (*pfnShadowSubsystemUninit)(rdpShadowSubsystem* subsystem); + + typedef int (*pfnShadowSubsystemStart)(rdpShadowSubsystem* subsystem); + typedef int (*pfnShadowSubsystemStop)(rdpShadowSubsystem* subsystem); + + typedef UINT32 (*pfnShadowEnumMonitors)(MONITOR_DEF* monitors, UINT32 maxMonitors); + + typedef int (*pfnShadowAuthenticate)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, + const char* user, const char* domain, + const char* password); + typedef BOOL (*pfnShadowClientConnect)(rdpShadowSubsystem* subsystem, rdpShadowClient* client); + typedef void (*pfnShadowClientDisconnect)(rdpShadowSubsystem* subsystem, + rdpShadowClient* client); + typedef BOOL (*pfnShadowClientCapabilities)(rdpShadowSubsystem* subsystem, + rdpShadowClient* client); + + typedef BOOL (*pfnShadowSynchronizeEvent)(rdpShadowSubsystem* subsystem, + rdpShadowClient* client, UINT32 flags); + typedef BOOL (*pfnShadowKeyboardEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, + UINT16 flags, UINT8 code); + typedef BOOL (*pfnShadowUnicodeKeyboardEvent)(rdpShadowSubsystem* subsystem, + rdpShadowClient* client, UINT16 flags, + UINT16 code); + typedef BOOL (*pfnShadowMouseEvent)(rdpShadowSubsystem* subsystem, rdpShadowClient* client, + UINT16 flags, UINT16 x, UINT16 y); + typedef BOOL (*pfnShadowExtendedMouseEvent)(rdpShadowSubsystem* subsystem, + rdpShadowClient* client, UINT16 flags, UINT16 x, + UINT16 y); + + typedef BOOL (*pfnShadowChannelAudinServerReceiveSamples)(rdpShadowSubsystem* subsystem, + rdpShadowClient* client, + const AUDIO_FORMAT* format, + wStream* data); + + struct rdp_shadow_client + { + rdpContext context; + + HANDLE thread; + BOOL activated; + BOOL first_frame; + BOOL inLobby; + BOOL mayView; + BOOL mayInteract; + BOOL suppressOutput; + UINT16 surfaceId; + wMessageQueue* MsgQueue; + CRITICAL_SECTION lock; + REGION16 invalidRegion; + rdpShadowServer* server; + rdpShadowEncoder* encoder; + rdpShadowSubsystem* subsystem; + + UINT32 pointerX; + UINT32 pointerY; + + HANDLE vcm; + EncomspServerContext* encomsp; + RemdeskServerContext* remdesk; + RdpsndServerContext* rdpsnd; +#if defined(CHANNEL_AUDIN_SERVER) + audin_server_context* audin; +#endif + RdpgfxServerContext* rdpgfx; + + BOOL resizeRequested; + UINT32 resizeWidth; + UINT32 resizeHeight; + BOOL areGfxCapsReady; /** @since version 3.3.0 */ + }; + + struct rdp_shadow_server + { + void* ext; + HANDLE thread; + HANDLE StopEvent; + wArrayList* clients; + rdpSettings* settings; + rdpShadowScreen* screen; + rdpShadowSurface* surface; + rdpShadowSurface* lobby; + rdpShadowCapture* capture; + rdpShadowSubsystem* subsystem; + + DWORD port; + BOOL mayView; + BOOL mayInteract; + BOOL shareSubRect; + BOOL authentication; + UINT32 selectedMonitor; + RECTANGLE_16 subRect; + + /* Codec settings */ + RLGR_MODE rfxMode; /* unused */ + H264_RATECONTROL_MODE h264RateControlMode; + UINT32 h264BitRate; + UINT32 h264FrameRate; + UINT32 h264QP; + + char* ipcSocket; + char* ConfigPath; + char* CertificateFile; + char* PrivateKeyFile; + CRITICAL_SECTION lock; + freerdp_listener* listener; + + size_t maxClientsConnected; + }; + + struct rdp_shadow_surface + { + rdpShadowServer* server; + + UINT16 x; + UINT16 y; + UINT32 width; + UINT32 height; + UINT32 scanline; + DWORD format; + BYTE* data; + + CRITICAL_SECTION lock; + REGION16 invalidRegion; + }; + + struct S_RDP_SHADOW_ENTRY_POINTS + { + pfnShadowSubsystemNew New; + pfnShadowSubsystemFree Free; + + pfnShadowSubsystemInit Init; + pfnShadowSubsystemUninit Uninit; + + pfnShadowSubsystemStart Start; + pfnShadowSubsystemStop Stop; + + pfnShadowEnumMonitors EnumMonitors; + }; + + struct rdp_shadow_subsystem + { + RDP_SHADOW_ENTRY_POINTS ep; + HANDLE event; + UINT32 numMonitors; + UINT32 captureFrameRate; + UINT32 selectedMonitor; + MONITOR_DEF monitors[16]; + MONITOR_DEF virtualScreen; + + /* This event indicates that we have graphic change */ + /* such as screen update and resize. It should not be */ + /* used by subsystem implementation directly */ + rdpShadowMultiClientEvent* updateEvent; + + wMessagePipe* MsgPipe; + UINT32 pointerX; + UINT32 pointerY; + + AUDIO_FORMAT* rdpsndFormats; + size_t nRdpsndFormats; + AUDIO_FORMAT* audinFormats; + size_t nAudinFormats; + + pfnShadowSynchronizeEvent SynchronizeEvent; + pfnShadowKeyboardEvent KeyboardEvent; + pfnShadowUnicodeKeyboardEvent UnicodeKeyboardEvent; + pfnShadowMouseEvent MouseEvent; + pfnShadowExtendedMouseEvent ExtendedMouseEvent; + pfnShadowChannelAudinServerReceiveSamples AudinServerReceiveSamples; + + pfnShadowAuthenticate Authenticate; + pfnShadowClientConnect ClientConnect; + pfnShadowClientDisconnect ClientDisconnect; + pfnShadowClientCapabilities ClientCapabilities; + + rdpShadowServer* server; + }; + +/* Definition of message between subsystem and clients */ +#define SHADOW_MSG_IN_REFRESH_REQUEST_ID 1001 + + typedef struct S_SHADOW_MSG_OUT SHADOW_MSG_OUT; + typedef void (*MSG_OUT_FREE_FN)(UINT32 id, + SHADOW_MSG_OUT* msg); /* function to free SHADOW_MSG_OUT */ + + struct S_SHADOW_MSG_OUT + { + int refCount; + MSG_OUT_FREE_FN Free; + }; + +#define SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID 2001 +#define SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID 2002 +#define SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES_ID 2003 +#define SHADOW_MSG_OUT_AUDIO_OUT_VOLUME_ID 2004 + + typedef struct + { + SHADOW_MSG_OUT common; + UINT32 xPos; + UINT32 yPos; + } SHADOW_MSG_OUT_POINTER_POSITION_UPDATE; + + typedef struct + { + SHADOW_MSG_OUT common; + UINT32 xHot; + UINT32 yHot; + UINT32 width; + UINT32 height; + UINT32 lengthAndMask; + UINT32 lengthXorMask; + BYTE* xorMaskData; + BYTE* andMaskData; + } SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE; + + typedef struct + { + SHADOW_MSG_OUT common; + AUDIO_FORMAT* audio_format; + void* buf; + size_t nFrames; + UINT16 wTimestamp; + } SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES; + + typedef struct + { + SHADOW_MSG_OUT common; + UINT16 left; + UINT16 right; + } SHADOW_MSG_OUT_AUDIO_OUT_VOLUME; + + FREERDP_API void shadow_subsystem_set_entry_builtin(const char* name); + FREERDP_API void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry); + + FREERDP_API WINPR_DEPRECATED_VAR( + "[since 3.4.0] Use shadow_subsystem_pointer_convert_alpha_pointer_data_to_format instead", + int shadow_subsystem_pointer_convert_alpha_pointer_data( + const BYTE* WINPR_RESTRICT pixels, BOOL premultiplied, UINT32 width, UINT32 height, + SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* WINPR_RESTRICT pointerColor)); + + /** @brief Convert a pointer image from input format to RDP specific encoding + * + * @param pixels A pointer to the pixel data + * @param format The pixel format of the pointer image + * @param premultiplied Premultiplied format, requires scaling of pixel colors + * @param width The width in pixels of the pointer + * @param height The height of the pointer + * @param pointerColor A pointer to the struct that can hold the encoded data + * + * @return \b >=0 for success, \b <0 for any failure + * + * @since version 3.4.0 + */ + FREERDP_API int shadow_subsystem_pointer_convert_alpha_pointer_data_to_format( + const BYTE* WINPR_RESTRICT pixels, UINT32 format, BOOL premultiplied, UINT32 width, + UINT32 height, SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* WINPR_RESTRICT pointerColor); + + FREERDP_API int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** argv, + COMMAND_LINE_ARGUMENT_A* cargs); + FREERDP_API int shadow_server_command_line_status_print(rdpShadowServer* server, int argc, + char** argv, int status, + COMMAND_LINE_ARGUMENT_A* cargs); + + FREERDP_API int shadow_server_start(rdpShadowServer* server); + FREERDP_API int shadow_server_stop(rdpShadowServer* server); + + FREERDP_API int shadow_server_init(rdpShadowServer* server); + FREERDP_API int shadow_server_uninit(rdpShadowServer* server); + + FREERDP_API UINT32 shadow_enum_monitors(MONITOR_DEF* monitors, UINT32 maxMonitors); + + FREERDP_API void shadow_server_free(rdpShadowServer* server); + + WINPR_ATTR_MALLOC(shadow_server_free, 1) + FREERDP_API rdpShadowServer* shadow_server_new(void); + + FREERDP_API int shadow_capture_align_clip_rect(RECTANGLE_16* rect, const RECTANGLE_16* clip); + + FREERDP_API WINPR_DEPRECATED_VAR( + "[since 3.4.0] Use shadow_capture_compare_with_format", + int shadow_capture_compare(const BYTE* WINPR_RESTRICT pData1, UINT32 nStep1, UINT32 nWidth, + UINT32 nHeight, const BYTE* WINPR_RESTRICT pData2, UINT32 nStep2, + RECTANGLE_16* WINPR_RESTRICT rect)); + + /** @brief Compare two framebuffer images of possibly different formats with each other + * + * @param pData1 A pointer to the data of image 1 + * @param format1 The format of image 1 + * @param nStep1 The line width in bytes of image 1 + * @param nWidth The line width in pixels of image 1 + * @param nHeight The height of image 1 + * @param pData2 A pointer to the data of image 2 + * @param format2 The format of image 2 + * @param nStep2 The line width in bytes of image 2 + * @param rect A pointer to the rectangle of the images to compare + * + * @return \b 0 if equal, \b >0 if not equal and \b <0 for any error + * + * @since version 3.4.0 + */ + FREERDP_API int shadow_capture_compare_with_format(const BYTE* WINPR_RESTRICT pData1, + UINT32 format1, UINT32 nStep1, UINT32 nWidth, + UINT32 nHeight, + const BYTE* WINPR_RESTRICT pData2, + UINT32 format2, UINT32 nStep2, + RECTANGLE_16* WINPR_RESTRICT rect); + + FREERDP_API void shadow_subsystem_frame_update(rdpShadowSubsystem* subsystem); + + FREERDP_API BOOL shadow_client_post_msg(rdpShadowClient* client, void* context, UINT32 type, + SHADOW_MSG_OUT* msg, void* lParam); + FREERDP_API int shadow_client_boardcast_msg(rdpShadowServer* server, void* context, UINT32 type, + SHADOW_MSG_OUT* msg, void* lParam); + FREERDP_API int shadow_client_boardcast_quit(rdpShadowServer* server, int nExitCode); + + FREERDP_API UINT32 shadow_encoder_preferred_fps(rdpShadowEncoder* encoder); + FREERDP_API UINT32 shadow_encoder_inflight_frames(rdpShadowEncoder* encoder); + + FREERDP_API BOOL shadow_screen_resize(rdpShadowScreen* screen); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SERVER_SHADOW_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/telemetry.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/telemetry.h new file mode 100644 index 0000000000000000000000000000000000000000..0697e700846c74a33ffa350cefe19c294dc72778 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/server/telemetry.h @@ -0,0 +1,111 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Telemetry Virtual Channel Extension + * + * Copyright 2022 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_TELEMETRY_SERVER_TELEMETRY_H +#define FREERDP_CHANNEL_TELEMETRY_SERVER_TELEMETRY_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_telemetry_server_context TelemetryServerContext; + + typedef UINT (*psTelemetryServerOpen)(TelemetryServerContext* context); + typedef UINT (*psTelemetryServerClose)(TelemetryServerContext* context); + + typedef BOOL (*psTelemetryServerChannelIdAssigned)(TelemetryServerContext* context, + UINT32 channelId); + + typedef UINT (*psTelemetryServerInitialize)(TelemetryServerContext* context, + BOOL externalThread); + typedef UINT (*psTelemetryServerPoll)(TelemetryServerContext* context); + typedef BOOL (*psTelemetryServerChannelHandle)(TelemetryServerContext* context, HANDLE* handle); + + typedef UINT (*psTelemetryServerRdpTelemetry)(TelemetryServerContext* context, + const TELEMETRY_RDP_TELEMETRY_PDU* rdpTelemetry); + + struct s_telemetry_server_context + { + HANDLE vcm; + + /* Server self-defined pointer. */ + void* userdata; + + /*** APIs called by the server. ***/ + + /** + * Optional: Set thread handling. + * When externalThread=TRUE, the application is responsible to call + * Poll() periodically to process channel events. + * + * Defaults to externalThread=FALSE + */ + psTelemetryServerInitialize Initialize; + + /** + * Open the telemetry channel. + */ + psTelemetryServerOpen Open; + + /** + * Close the telemetry channel. + */ + psTelemetryServerClose Close; + + /** + * Poll + * When externalThread=TRUE, call Poll() periodically from your main loop. + * If externalThread=FALSE do not call. + */ + psTelemetryServerPoll Poll; + + /** + * Retrieve the channel handle for use in conjunction with Poll(). + * If externalThread=FALSE do not call. + */ + psTelemetryServerChannelHandle ChannelHandle; + + /*** Callbacks registered by the server. ***/ + + /** + * Callback, when the channel got its id assigned + */ + psTelemetryServerChannelIdAssigned ChannelIdAssigned; + /** + * Callback for the RDP Telemetry PDU. + */ + psTelemetryServerRdpTelemetry RdpTelemetry; + + rdpContext* rdpcontext; + }; + + FREERDP_API void telemetry_server_context_free(TelemetryServerContext* context); + + WINPR_ATTR_MALLOC(telemetry_server_context_free, 1) + FREERDP_API TelemetryServerContext* telemetry_server_context_new(HANDLE vcm); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_TELEMETRY_SERVER_TELEMETRY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/session.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/session.h new file mode 100644 index 0000000000000000000000000000000000000000..12b8032105991e019d9e22a3ba6f48060879f8d3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/session.h @@ -0,0 +1,59 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Client Session Info + * + * Copyright 2016 David FORT + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FREERDP_SESSION_H +#define FREERDP_SESSION_H + +#include + +/* Logon Information Types */ +#define INFO_TYPE_LOGON 0x00000000 +#define INFO_TYPE_LOGON_LONG 0x00000001 +#define INFO_TYPE_LOGON_PLAIN_NOTIFY 0x00000002 +#define INFO_TYPE_LOGON_EXTENDED_INF 0x00000003 + +#ifdef __cplusplus +extern "C" +{ +#endif + + struct rdp_logon_info + { + UINT32 sessionId; + char* username; + char* domain; + }; + typedef struct rdp_logon_info logon_info; + + struct rdp_logon_info_ex + { + BOOL haveCookie; + UINT32 LogonId; + BYTE ArcRandomBits[16]; + + BOOL haveErrorInfo; + UINT32 ErrorNotificationType; + UINT32 ErrorNotificationData; + }; + typedef struct rdp_logon_info_ex logon_info_ex; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SESSION_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings.h new file mode 100644 index 0000000000000000000000000000000000000000..54fe7d0a12f13297220d081427e6b1681f32c80c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings.h @@ -0,0 +1,782 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Settings + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2012 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SETTINGS_H +#define FREERDP_SETTINGS_H + +#include +#include + +#include +#include +#include +#include + +#if !defined(WITH_OPAQUE_SETTINGS) +#include +#endif + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** \defgroup rdpSettings rdpSettings + * \brief This is the FreeRDP settings module. + * + * Settings are used to store configuration data for an RDP connection. + * There are 3 different settings for each client and server: + * + * 1. The initial connection supplied by the user + * 2. The settings sent from client or server during capability exchange + * 3. The settings merged from the capability exchange and the initial configuration. + * + * The lifetime of the settings is as follows: + * 1. Initial configuration is saved and will be valid for the whole application lifecycle + * 2. The client or server settings from the other end are valid from capability exchange until + * the connection is ended (disconnect/redirect/...) + * 3. The merged settings are created from the initial configuration and server settings and + * have the same lifetime, until the connection ends + * + * + * So, when accessing the settings always ensure to know which one you are operating on! (this + * is especially important for the proxy where you have a RDP client and RDP server in the same + * application context) + * + * @{ + */ + + typedef struct rdp_settings rdpSettings; + +/** + * rdpSettings creation flags + */ +#define FREERDP_SETTINGS_SERVER_MODE 0x00000001 +#define FREERDP_SETTINGS_REMOTE_MODE 0x00000002 + + /** \brief Free a settings struct with all data in it + * + * \param settings A pointer to the settings to free, May be NULL + */ + FREERDP_API void freerdp_settings_free(rdpSettings* settings); + + /** \brief creates a new setting struct + * + * \param flags Flags for creation, use \b FREERDP_SETTINGS_SERVER_MODE for server settings, 0 + * for client. + * + * \return A newly allocated settings struct or NULL + */ + WINPR_ATTR_MALLOC(freerdp_settings_free, 1) + FREERDP_API rdpSettings* freerdp_settings_new(DWORD flags); + + /** \brief Creates a deep copy of settings + * + * \param settings A pointer to a settings struct to copy. May be NULL (returns NULL) + * + * \return A newly allocated copy of \b settings or NULL + */ + WINPR_ATTR_MALLOC(freerdp_settings_free, 1) + FREERDP_API rdpSettings* freerdp_settings_clone(const rdpSettings* settings); + + /** \brief Deep copies settings from \b src to \b dst + * + * The function frees up all allocated data in \b dst before copying the data from \b src + * + * \param dst A pointer for the settings to copy data to. May be NULL (fails copy) + * \param src A pointer to the settings to copy. May be NULL (fails copy) + * + * \return \b TRUE for success, \b FALSE for failure. + */ + FREERDP_API BOOL freerdp_settings_copy(rdpSettings* dst, const rdpSettings* src); + + /** \brief copies one setting identified by \b id from \b src to \b dst + * + * The function frees up all allocated data in \b dst before copying the data from \b src + * + * \param dst A pointer for the settings to copy data to. May be NULL (fails copy) + * \param src A pointer to the settings to copy. May be NULL (fails copy) + * \param id The settings identifier to copy + * + * \return \b TRUE for success, \b FALSE for failure. + */ + + FREERDP_API BOOL freerdp_settings_copy_item(rdpSettings* dst, const rdpSettings* src, + SSIZE_T id); + + /** \brief Dumps the contents of a settings struct to a WLog logger + * + * \param log The logger to write to, must not be NULL + * \param level The WLog level to use for the log entries + * \param settings A pointer to the settings to dump. May be NULL. + */ + FREERDP_API void freerdp_settings_dump(wLog* log, DWORD level, const rdpSettings* settings); + + /** \brief Dumps the difference between two settings structs to a WLog + * + * \param log The logger to write to, must not be NULL. + * \param level The WLog level to use for the log entries. + * \param src A pointer to the settings to dump. May be NULL. + * \param other A pointer to the settings to dump. May be NULL. + * + * \return \b TRUE if not equal, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_settings_print_diff(wLog* log, DWORD level, const rdpSettings* src, + const rdpSettings* other); + + FREERDP_API void freerdp_addin_argv_free(ADDIN_ARGV* args); + + WINPR_ATTR_MALLOC(freerdp_addin_argv_free, 1) + FREERDP_API ADDIN_ARGV* freerdp_addin_argv_new(size_t argc, const char* const argv[]); + + WINPR_ATTR_MALLOC(freerdp_addin_argv_free, 1) + FREERDP_API ADDIN_ARGV* freerdp_addin_argv_clone(const ADDIN_ARGV* args); + + FREERDP_API BOOL freerdp_addin_argv_add_argument(ADDIN_ARGV* args, const char* argument); + FREERDP_API BOOL freerdp_addin_argv_add_argument_ex(ADDIN_ARGV* args, const char* argument, + size_t len); + FREERDP_API BOOL freerdp_addin_argv_del_argument(ADDIN_ARGV* args, const char* argument); + + FREERDP_API int freerdp_addin_set_argument(ADDIN_ARGV* args, const char* argument); + FREERDP_API int freerdp_addin_replace_argument(ADDIN_ARGV* args, const char* previous, + const char* argument); + FREERDP_API int freerdp_addin_set_argument_value(ADDIN_ARGV* args, const char* option, + const char* value); + FREERDP_API int freerdp_addin_replace_argument_value(ADDIN_ARGV* args, const char* previous, + const char* option, const char* value); + + FREERDP_API BOOL freerdp_device_collection_add(rdpSettings* settings, RDPDR_DEVICE* device); + + /** \brief Removed a device from the settings, returns ownership of the allocated device to + * caller. + * + * \param settings the settings to remove the device from + * \param device the device to remove + * + * \since version 3.4.0 + * + * \return \b TRUE if the device was removed, \b FALSE if device was not found or is NULL + */ + FREERDP_API BOOL freerdp_device_collection_del(rdpSettings* settings, + const RDPDR_DEVICE* device); + FREERDP_API RDPDR_DEVICE* freerdp_device_collection_find(rdpSettings* settings, + const char* name); + FREERDP_API RDPDR_DEVICE* freerdp_device_collection_find_type(rdpSettings* settings, + UINT32 type); + + FREERDP_API void freerdp_device_free(RDPDR_DEVICE* device); + + WINPR_ATTR_MALLOC(freerdp_device_free, 1) + FREERDP_API RDPDR_DEVICE* freerdp_device_new(UINT32 Type, size_t count, + const char* const args[]); + + WINPR_ATTR_MALLOC(freerdp_device_free, 1) + FREERDP_API RDPDR_DEVICE* freerdp_device_clone(const RDPDR_DEVICE* device); + + FREERDP_API BOOL freerdp_device_equal(const RDPDR_DEVICE* one, const RDPDR_DEVICE* other); + + FREERDP_API void freerdp_device_collection_free(rdpSettings* settings); + + FREERDP_API BOOL freerdp_static_channel_collection_add(rdpSettings* settings, + ADDIN_ARGV* channel); + FREERDP_API BOOL freerdp_static_channel_collection_del(rdpSettings* settings, const char* name); + FREERDP_API ADDIN_ARGV* freerdp_static_channel_collection_find(rdpSettings* settings, + const char* name); +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED(ADDIN_ARGV* freerdp_static_channel_clone(ADDIN_ARGV* channel)); +#endif + + FREERDP_API void freerdp_static_channel_collection_free(rdpSettings* settings); + + FREERDP_API BOOL freerdp_dynamic_channel_collection_add(rdpSettings* settings, + ADDIN_ARGV* channel); + FREERDP_API BOOL freerdp_dynamic_channel_collection_del(rdpSettings* settings, + const char* name); + FREERDP_API ADDIN_ARGV* freerdp_dynamic_channel_collection_find(const rdpSettings* settings, + const char* name); + +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED(ADDIN_ARGV* freerdp_dynamic_channel_clone(ADDIN_ARGV* channel)); +#endif + + FREERDP_API void freerdp_dynamic_channel_collection_free(rdpSettings* settings); + FREERDP_API void freerdp_capability_buffer_free(rdpSettings* settings); + FREERDP_API BOOL freerdp_capability_buffer_copy(rdpSettings* settings, const rdpSettings* src); + + FREERDP_API void freerdp_server_license_issuers_free(rdpSettings* settings); + FREERDP_API BOOL freerdp_server_license_issuers_copy(rdpSettings* settings, char** addresses, + UINT32 count); + + FREERDP_API void freerdp_target_net_addresses_free(rdpSettings* settings); + FREERDP_API BOOL freerdp_target_net_addresses_copy(rdpSettings* settings, char** addresses, + UINT32 count); + + FREERDP_API void freerdp_performance_flags_make(rdpSettings* settings); + FREERDP_API void freerdp_performance_flags_split(rdpSettings* settings); + + FREERDP_API BOOL freerdp_set_gateway_usage_method(rdpSettings* settings, + UINT32 GatewayUsageMethod); + FREERDP_API void freerdp_update_gateway_usage_method(rdpSettings* settings, + UINT32 GatewayEnabled, + UINT32 GatewayBypassLocal); + + /* DEPRECATED: + * the functions freerdp_get_param_* and freerdp_set_param_* are deprecated. + * use freerdp_settings_get_* and freerdp_settings_set_* as a replacement! + */ +#if defined(WITH_FREERDP_DEPRECATED) + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_get_bool instead", + BOOL freerdp_get_param_bool(const rdpSettings* settings, + int id)); + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_set_bool instead", + int freerdp_set_param_bool(rdpSettings* settings, int id, + BOOL param)); + + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_get_int[16|32] instead", + int freerdp_get_param_int(const rdpSettings* settings, + int id)); + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_set_int[16|32] instead", + int freerdp_set_param_int(rdpSettings* settings, int id, + int param)); + + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_set_uint32 instead", + UINT32 freerdp_get_param_uint32(const rdpSettings* settings, + int id)); + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_set_uint32 instead", + int freerdp_set_param_uint32(rdpSettings* settings, int id, + UINT32 param)); + + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_get_uint64 instead", + UINT64 freerdp_get_param_uint64(const rdpSettings* settings, + int id)); + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_set_uint64 instead", + int freerdp_set_param_uint64(rdpSettings* settings, int id, + UINT64 param)); + + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_get_string instead", + char* freerdp_get_param_string(const rdpSettings* settings, + int id)); + FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_settings_set_string instead", + int freerdp_set_param_string(rdpSettings* settings, int id, + const char* param)); +#endif + + /** \brief Returns \b TRUE if settings are in a valid state, \b FALSE otherwise + * + * This function is meant to replace tideous return checks for \b freerdp_settings_set_* with a + * single check after these calls. + * + * \param settings the settings instance to check + * + * \return \b TRUE if valid, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_settings_are_valid(const rdpSettings* settings); + + /** \brief Returns a boolean settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the value of the boolean key + */ + FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings* settings, + FreeRDP_Settings_Keys_Bool id); + + /** \brief Sets a BOOL settings value. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings* settings, FreeRDP_Settings_Keys_Bool id, + BOOL param); + + /** \brief Returns a INT16 settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the value of the INT16 key + */ + FREERDP_API INT16 freerdp_settings_get_int16(const rdpSettings* settings, + FreeRDP_Settings_Keys_Int16 id); + + /** \brief Sets a INT16 settings value. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_int16(rdpSettings* settings, + FreeRDP_Settings_Keys_Int16 id, INT16 param); + + /** \brief Returns a UINT16 settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the value of the UINT16 key + */ + FREERDP_API UINT16 freerdp_settings_get_uint16(const rdpSettings* settings, + FreeRDP_Settings_Keys_UInt16 id); + + /** \brief Sets a UINT16 settings value. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_uint16(rdpSettings* settings, + FreeRDP_Settings_Keys_UInt16 id, UINT16 param); + + /** \brief Returns a INT32 settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the value of the INT32 key + */ + FREERDP_API INT32 freerdp_settings_get_int32(const rdpSettings* settings, + FreeRDP_Settings_Keys_Int32 id); + + /** \brief Sets a INT32 settings value. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_int32(rdpSettings* settings, + FreeRDP_Settings_Keys_Int32 id, INT32 param); + + /** \brief Returns a UINT32 settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the value of the UINT32 key + */ + FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings* settings, + FreeRDP_Settings_Keys_UInt32 id); + + /** \brief Sets a UINT32 settings value. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings* settings, + FreeRDP_Settings_Keys_UInt32 id, UINT32 param); + + /** \brief Returns a INT64 settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the value of the INT64 key + */ + FREERDP_API INT64 freerdp_settings_get_int64(const rdpSettings* settings, + FreeRDP_Settings_Keys_Int64 id); + + /** \brief Sets a INT64 settings value. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_int64(rdpSettings* settings, + FreeRDP_Settings_Keys_Int64 id, INT64 param); + + /** \brief Returns a UINT64 settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the value of the UINT64 key + */ + FREERDP_API UINT64 freerdp_settings_get_uint64(const rdpSettings* settings, + FreeRDP_Settings_Keys_UInt64 id); + + /** \brief Sets a UINT64 settings value. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_uint64(rdpSettings* settings, + FreeRDP_Settings_Keys_UInt64 id, UINT64 param); + + /** \brief Returns a immutable string settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the immutable string pointer + */ + FREERDP_API const char* freerdp_settings_get_string(const rdpSettings* settings, + FreeRDP_Settings_Keys_String id); + + /** \brief Returns a string settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the string pointer + */ + FREERDP_API char* freerdp_settings_get_string_writable(rdpSettings* settings, + FreeRDP_Settings_Keys_String id); + + /** \brief Sets a string settings value. The \b param is copied. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. If NULL allocates an empty string buffer of \b len size, + * otherwise a copy is created. \param len The length of \b param, 0 to remove the old entry. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_string_len(rdpSettings* settings, + FreeRDP_Settings_Keys_String id, + const char* param, size_t len); + + /** \brief Sets a string settings value. The \b param is copied. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. If NULL removes the old entry, otherwise a copy is created. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_string(rdpSettings* settings, + FreeRDP_Settings_Keys_String id, + const char* param); + + /** \brief appends a string to a settings value. The \b param is copied. + * If the initial value of the setting was not empty, @code + * @endcode is created + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param separator The separator string to use. May be NULL (no separator) + * \param param The value to append + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_append_string(rdpSettings* settings, + FreeRDP_Settings_Keys_String id, + const char* separator, const char* param); + + /** \brief Sets a string settings value. The \b param is converted to UTF-8 and the copy stored. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. If NULL removes the old entry, otherwise a copy is created. + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_string_from_utf16(rdpSettings* settings, + FreeRDP_Settings_Keys_String id, + const WCHAR* param); + + /** \brief Sets a string settings value. The \b param is converted to UTF-8 and the copy stored. + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * \param param The value to set. If NULL removes the old entry, otherwise a copy is created. + * \param length The length of the WCHAR string in number of WCHAR characters + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_string_from_utf16N(rdpSettings* settings, + FreeRDP_Settings_Keys_String id, + const WCHAR* param, size_t length); + /** \brief Return an allocated UTF16 string + * + * \param settings A pointer to the settings struct to use + * \param id The settings identifier + * + * \return An allocated, '\0' terminated WCHAR string or NULL + */ + FREERDP_API WCHAR* freerdp_settings_get_string_as_utf16(const rdpSettings* settings, + FreeRDP_Settings_Keys_String id, + size_t* pCharLen); + + /** \brief Returns a immutable pointer settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the immutable pointer value + */ + FREERDP_API const void* freerdp_settings_get_pointer(const rdpSettings* settings, + FreeRDP_Settings_Keys_Pointer id); + + /** \brief Returns a mutable pointer settings value + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to query + * + * \return the mutable pointer value + */ + FREERDP_API void* freerdp_settings_get_pointer_writable(rdpSettings* settings, + FreeRDP_Settings_Keys_Pointer id); + + /** \brief Set a pointer to value \b data + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to update + * \param data The data to set (direct update, no copy created, previous value overwritten) + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_pointer(rdpSettings* settings, + FreeRDP_Settings_Keys_Pointer id, + const void* data); + + /** \brief Set a pointer to value \b data + * + * \param settings A pointer to the settings to query, must not be NULL. + * \param id The key to update + * \param data The data to set (copy created, previous value freed) + * + * \return \b TRUE for success, \b FALSE for failure + */ + FREERDP_API BOOL freerdp_settings_set_pointer_len(rdpSettings* settings, + FreeRDP_Settings_Keys_Pointer id, + const void* data, size_t len); + + FREERDP_API const void* freerdp_settings_get_pointer_array(const rdpSettings* settings, + FreeRDP_Settings_Keys_Pointer id, + size_t offset); + FREERDP_API void* freerdp_settings_get_pointer_array_writable(const rdpSettings* settings, + FreeRDP_Settings_Keys_Pointer id, + size_t offset); + FREERDP_API BOOL freerdp_settings_set_pointer_array(rdpSettings* settings, + FreeRDP_Settings_Keys_Pointer id, + size_t offset, const void* data); + + /** \brief Set a setting \name to value \b value + * Both, key and value are provided as strings and parsed internally. + * + * The \b value will be checked internally: + * - Integer types must be within boundaries + * - \b BOOL must be any of {'true', 'false', 'on', 'off', '0', '1'} (case insensitive) + * - Strings are passed on as is + * - Pointers are also passed as is + * + * @param settings The settings instance to set the value, must not be \b NULL + * @param name The name of the settings key (like 'FreeRDP_Domain', same as output of \ref + * freerdp_settings_get_name_for_key ) Must not be \b NULL + * @param value The value of the setting. Must not be \b NULL + * + * @note If the function fails check \ref wLog output for details + * + * @since version 3.0.0 + * + * @return \b TRUE in case of success, \b FALSE otherwise. + */ + FREERDP_API BOOL freerdp_settings_set_value_for_name(rdpSettings* settings, const char* name, + const char* value); + + /** \brief Get a key index for the name string of that key + * + * \param value A key name string like FreeRDP_ServerMode + * + * \return The key index or -1 in case of an error (e.g. name does not exist) + */ + FREERDP_API SSIZE_T freerdp_settings_get_key_for_name(const char* value); + + /** \brief Get a key type for the name string of that key + * + * \param value A key name string like FreeRDP_ServerMode + * + * \return The key type (e.g. FREERDP_SETTINGS_TYPE_BOOL) or -1 in case of an error (e.g. name + * does not exist) + */ + FREERDP_API SSIZE_T freerdp_settings_get_type_for_name(const char* value); + + /** \brief Get a key type for the key index + * + * \param key The key index like FreeRDP_ServerMode + * + * \return The key type (e.g. FREERDP_SETTINGS_TYPE_BOOL) or -1 in case of an error (e.g. name + * does not exist) + */ + FREERDP_API SSIZE_T freerdp_settings_get_type_for_key(SSIZE_T key); + + /** \brief Returns the type name for a \b key + * + * \param key the key number to stringify + * \return the type name of the key or \b FREERDP_SETTINGS_TYPE_UNKNOWN + */ + FREERDP_API const char* freerdp_settings_get_type_name_for_key(SSIZE_T key); + + /** \brief Returns the type name for a \b type + * + * \param type the type to stringify + * \return the name of the key or \b FREERDP_SETTINGS_TYPE_UNKNOWN + */ + FREERDP_API const char* freerdp_settings_get_type_name_for_type(SSIZE_T type); + + /** \brief Returns the type name for a \b key + * + * \param key the key number to stringify + * \return the name of the key or \b NULL + */ + FREERDP_API const char* freerdp_settings_get_name_for_key(SSIZE_T key); + + /** \brief helper function to get a mask of supported codec flags. + * + * This function checks various settings to create a mask of supported codecs + * \b FreeRDP_CodecFlags defines the codecs + * + * \param settings the settings to check + * + * \return a mask of supported codecs + */ + FREERDP_API UINT32 freerdp_settings_get_codecs_flags(const rdpSettings* settings); + + /** \brief Parse capability data and apply to settings + * + * The capability message is stored in raw form in the settings, the data parsed and applied to + * the settings. + * + * \param settings A pointer to the settings to use + * \param capsFlags A pointer to the capability flags, must have capsCount fields + * \param capsData A pointer array to the RAW capability data, must have capsCount fields + * \param capsSizes A pointer to an array of RAW capability sizes, must have capsCount fields + * \param capsCount The number of capabilities contained in the RAW data + * \param serverReceivedCaps Indicates if the parser should assume to be a server or client + * instance + * + * \return \b TRUE for success, \b FALSE in case of an error + */ + FREERDP_API BOOL freerdp_settings_update_from_caps(rdpSettings* settings, const BYTE* capsFlags, + const BYTE** capsData, + const UINT32* capsSizes, UINT32 capsCount, + BOOL serverReceivedCaps); + + /** \brief A helper function to return the correct server name. + * + * The server name might be in key FreeRDP_ServerHostname or if used in + * FreeRDP_UserSpecifiedServerName. This function returns the correct name to use. + * + * \param settings The settings to query, must not be NULL. + * + * \return A string pointer or NULL in case of failure. + */ + FREERDP_API const char* freerdp_settings_get_server_name(const rdpSettings* settings); + + /** \brief Returns a stringified representation of RAIL support flags + * + * \param flags The flags to stringify + * \param buffer A pointer to the string buffer to write to + * \param length The size of the string buffer + * + * \return A pointer to \b buffer for success, NULL otherwise + */ + FREERDP_API const char* freerdp_rail_support_flags_to_string(UINT32 flags, char* buffer, + size_t length); + + /** \brief Returns a stringified representation of the RDP protocol version. + * + * \param version The RDP protocol version number. + * + * \return A string representation of the protocol version as "RDP_VERSION_10_11" or + * "RDP_VERSION_UNKNOWN" for invalid/unknown versions + */ + FREERDP_API const char* freerdp_rdp_version_string(UINT32 version); + + /** \brief Returns a string representation of \b RDPDR_DTYP_* + * + * \param type The integer of the \b RDPDR_DTYP_* to stringify + * + * \return A string representation of the \b RDPDR_DTYP_* or "RDPDR_DTYP_UNKNOWN" + */ + FREERDP_API const char* freerdp_rdpdr_dtyp_string(UINT32 type); + + FREERDP_API const char* freerdp_encryption_level_string(UINT32 EncryptionLevel); + FREERDP_API const char* freerdp_encryption_methods_string(UINT32 EncryptionLevel, char* buffer, + size_t size); + + /** \brief returns a string representation of \b RNS_UD_XXBPP_SUPPORT values + * + * return A string reprenentation of the bitmask. + */ + FREERDP_API const char* freerdp_supported_color_depths_string(UINT16 mask, char* buffer, + size_t size); + + /** \brief return the configuration directory for the library + * @return The current configuration path or \b NULL + * @since version 3.6.0 + */ + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_settings_get_config_path(void); + + /** @brief Sort monitor array according to: + * 1. First monitor is at x/y 0/0 and is the primary monitor + * 2. The primary monitor must be at 0/0, if not set + * FreeRDP_MonitorLocalShiftX/FreeRDP_MonitorLocalShiftY + * + * The FreeRDP_MonitorLocalShiftX/FreeRDP_MonitorLocalShiftY is required to map the local + * monitors / mouse / touch coordinates to the remote ones. + * + * @param settings The settings to set the monitors for + * @param monitors The unsorted monitors array + * @param count The number of monitors in the unsorted array + * + * @return \b TRUE if the configuration is valid (or could be corrected to a valid one), \b + * FALSE otherwise. + * + * @version since 3.11.0 + */ + FREERDP_API BOOL freerdp_settings_set_monitor_def_array_sorted(rdpSettings* settings, + const rdpMonitor* monitors, + size_t count); + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif /* FREERDP_SETTINGS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings_types.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings_types.h new file mode 100644 index 0000000000000000000000000000000000000000..be1ce6bde6a10bd83fa187b263c53df9ab81bb5f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings_types.h @@ -0,0 +1,510 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Settings + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2010-2012 Marc-Andre Moreau + * Copyright 2016 Armin Novak + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SETTINGS_TYPES_H +#define FREERDP_SETTINGS_TYPES_H + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @addtogroup rdpSettings + * @{ + */ + +/* Surface Commands Flags */ +#define SURFCMDS_SET_SURFACE_BITS 0x00000002 /** @since version 3.7.0 */ +#define SURFCMDS_FRAME_MARKER 0x00000010 /** @since version 3.7.0 */ +#define SURFCMDS_STREAM_SURFACE_BITS 0x00000040 /** @since version 3.7.0 */ + +/* RAIL Support Level */ +#define RAIL_LEVEL_SUPPORTED 0x00000001 +#define RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED 0x00000002 +#define RAIL_LEVEL_SHELL_INTEGRATION_SUPPORTED 0x00000004 +#define RAIL_LEVEL_LANGUAGE_IME_SYNC_SUPPORTED 0x00000008 +#define RAIL_LEVEL_SERVER_TO_CLIENT_IME_SYNC_SUPPORTED 0x00000010 +#define RAIL_LEVEL_HIDE_MINIMIZED_APPS_SUPPORTED 0x00000020 +#define RAIL_LEVEL_WINDOW_CLOAKING_SUPPORTED 0x00000040 +#define RAIL_LEVEL_HANDSHAKE_EX_SUPPORTED 0x00000080 + +/* Performance Flags */ +#define PERF_FLAG_NONE 0x00000000 +#define PERF_DISABLE_WALLPAPER 0x00000001 +#define PERF_DISABLE_FULLWINDOWDRAG 0x00000002 +#define PERF_DISABLE_MENUANIMATIONS 0x00000004 +#define PERF_DISABLE_THEMING 0x00000008 +#define PERF_DISABLE_CURSOR_SHADOW 0x00000020 +#define PERF_DISABLE_CURSORSETTINGS 0x00000040 +#define PERF_ENABLE_FONT_SMOOTHING 0x00000080 +#define PERF_ENABLE_DESKTOP_COMPOSITION 0x00000100 + +/* Connection Types */ +#define CONNECTION_TYPE_INVALID \ + 0x00 /** @brief synthetic, removes RNS_UD_CS_VALID_CONNECTION_TYPE from ConnectionType in \ + * EarlyCapabilityFlags \ + * @since version 3.6.0 \ + */ +#define CONNECTION_TYPE_MODEM 0x01 +#define CONNECTION_TYPE_BROADBAND_LOW 0x02 +#define CONNECTION_TYPE_SATELLITE 0x03 +#define CONNECTION_TYPE_BROADBAND_HIGH 0x04 +#define CONNECTION_TYPE_WAN 0x05 +#define CONNECTION_TYPE_LAN 0x06 +#define CONNECTION_TYPE_AUTODETECT 0x07 + +/* Client to Server (CS) data blocks */ +#define CS_CORE 0xC001 +#define CS_SECURITY 0xC002 +#define CS_NET 0xC003 +#define CS_CLUSTER 0xC004 +#define CS_MONITOR 0xC005 +#define CS_MCS_MSGCHANNEL 0xC006 +#define CS_MONITOR_EX 0xC008 +#define CS_UNUSED1 0xC00C +#define CS_MULTITRANSPORT 0xC00A + +/* Server to Client (SC) data blocks */ +#define SC_CORE 0x0C01 +#define SC_SECURITY 0x0C02 +#define SC_NET 0x0C03 +#define SC_MCS_MSGCHANNEL 0x0C04 +#define SC_MULTITRANSPORT 0x0C08 + + /* RDP versions, see + * [MS-RDPBCGR] 2.2.1.3.2 Client Core Data (TS_UD_CS_CORE) + * [MS-RDPBCGR] 2.2.1.4.2 Server Core Data (TS_UD_SC_CORE) + */ + typedef enum + { + RDP_VERSION_4 = 0x00080001, + RDP_VERSION_5_PLUS = 0x00080004, + RDP_VERSION_10_0 = 0x00080005, + RDP_VERSION_10_1 = 0x00080006, + RDP_VERSION_10_2 = 0x00080007, + RDP_VERSION_10_3 = 0x00080008, + RDP_VERSION_10_4 = 0x00080009, + RDP_VERSION_10_5 = 0x0008000a, + RDP_VERSION_10_6 = 0x0008000b, + RDP_VERSION_10_7 = 0x0008000C, + RDP_VERSION_10_8 = 0x0008000D, + RDP_VERSION_10_9 = 0x0008000E, + RDP_VERSION_10_10 = 0x0008000F, + RDP_VERSION_10_11 = 0x00080010, + RDP_VERSION_10_12 = 0x00080011 + } RDP_VERSION; + +/* Color depth */ +#define RNS_UD_COLOR_4BPP 0xCA00 +#define RNS_UD_COLOR_8BPP 0xCA01 +#define RNS_UD_COLOR_16BPP_555 0xCA02 +#define RNS_UD_COLOR_16BPP_565 0xCA03 +#define RNS_UD_COLOR_24BPP 0xCA04 + +/* Secure Access Sequence */ +#define RNS_UD_SAS_DEL 0xAA03 + +/* Supported Color Depths */ +#define RNS_UD_24BPP_SUPPORT 0x0001 +#define RNS_UD_16BPP_SUPPORT 0x0002 +#define RNS_UD_15BPP_SUPPORT 0x0004 +#define RNS_UD_32BPP_SUPPORT 0x0008 + +/* Audio Mode */ +#define AUDIO_MODE_REDIRECT 0 /* Bring to this computer */ +#define AUDIO_MODE_PLAY_ON_SERVER 1 /* Leave at remote computer */ +#define AUDIO_MODE_NONE 2 /* Do not play */ + +/* Early Capability Flags (Client to Server) */ +#define RNS_UD_CS_SUPPORT_ERRINFO_PDU 0x0001 +#define RNS_UD_CS_WANT_32BPP_SESSION 0x0002 +#define RNS_UD_CS_SUPPORT_STATUSINFO_PDU 0x0004 +#define RNS_UD_CS_STRONG_ASYMMETRIC_KEYS 0x0008 +#define RNS_UD_CS_RELATIVE_MOUSE_INPUT 0x0010 +#define RNS_UD_CS_VALID_CONNECTION_TYPE 0x0020 +#define RNS_UD_CS_SUPPORT_MONITOR_LAYOUT_PDU 0x0040 +#define RNS_UD_CS_SUPPORT_NETCHAR_AUTODETECT 0x0080 +#define RNS_UD_CS_SUPPORT_DYNVC_GFX_PROTOCOL 0x0100 +#define RNS_UD_CS_SUPPORT_DYNAMIC_TIME_ZONE 0x0200 +#define RNS_UD_CS_SUPPORT_HEARTBEAT_PDU 0x0400 +#define RNS_UD_CS_SUPPORT_SKIP_CHANNELJOIN 0x0800 + +/* Early Capability Flags (Server to Client) */ +#define RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V1 0x00000001 +#define RNS_UD_SC_DYNAMIC_DST_SUPPORTED 0x00000002 +#define RNS_UD_SC_EDGE_ACTIONS_SUPPORTED_V2 0x00000004 +#define RNS_UD_SC_SKIP_CHANNELJOIN_SUPPORTED 0x00000008 + +/* Cluster Information Flags */ +#define REDIRECTION_SUPPORTED 0x00000001 +#define REDIRECTED_SESSIONID_FIELD_VALID 0x00000002 +#define REDIRECTED_SMARTCARD 0x00000040 + +#define ServerSessionRedirectionVersionMask 0x0000003c +#define REDIRECTION_VERSION1 0x00 +#define REDIRECTION_VERSION2 0x01 +#define REDIRECTION_VERSION3 0x02 +#define REDIRECTION_VERSION4 0x03 +#define REDIRECTION_VERSION5 0x04 +#define REDIRECTION_VERSION6 0x05 + +#define MONITOR_PRIMARY 0x00000001 + +/* Encryption Methods */ +#define ENCRYPTION_METHOD_NONE 0x00000000 +#define ENCRYPTION_METHOD_40BIT 0x00000001 +#define ENCRYPTION_METHOD_128BIT 0x00000002 +#define ENCRYPTION_METHOD_56BIT 0x00000008 +#define ENCRYPTION_METHOD_FIPS 0x00000010 + +/* Encryption Levels */ +#define ENCRYPTION_LEVEL_NONE 0x00000000 +#define ENCRYPTION_LEVEL_LOW 0x00000001 +#define ENCRYPTION_LEVEL_CLIENT_COMPATIBLE 0x00000002 +#define ENCRYPTION_LEVEL_HIGH 0x00000003 +#define ENCRYPTION_LEVEL_FIPS 0x00000004 + +/* Multitransport Types */ +#define TRANSPORT_TYPE_UDP_FECR 0x00000001 +#define TRANSPORT_TYPE_UDP_FECL 0x00000004 +#define TRANSPORT_TYPE_UDP_PREFERRED 0x00000100 +#define SOFTSYNC_TCP_TO_UDP 0x00000200 + +/* Static Virtual Channel Options */ +#define CHANNEL_OPTION_INITIALIZED 0x80000000 +#define CHANNEL_OPTION_ENCRYPT_RDP 0x40000000 +#define CHANNEL_OPTION_ENCRYPT_SC 0x20000000 +#define CHANNEL_OPTION_ENCRYPT_CS 0x10000000 +#define CHANNEL_OPTION_PRI_HIGH 0x08000000 +#define CHANNEL_OPTION_PRI_MED 0x04000000 +#define CHANNEL_OPTION_PRI_LOW 0x02000000 +#define CHANNEL_OPTION_COMPRESS_RDP 0x00800000 +#define CHANNEL_OPTION_COMPRESS 0x00400000 +#define CHANNEL_OPTION_SHOW_PROTOCOL 0x00200000 +#define CHANNEL_REMOTE_CONTROL_PERSISTENT 0x00100000 + +/* Virtual Channel Capability Flags */ +#define VCCAPS_NO_COMPR 0x00000000 +#define VCCAPS_COMPR_SC 0x00000001 +#define VCCAPS_COMPR_CS_8K 0x00000002 + +/* Large Pointer Support Flags */ +#define LARGE_POINTER_FLAG_96x96 0x00000001 +#define LARGE_POINTER_FLAG_384x384 0x00000002 + +/* Auto Reconnect Version */ +#define AUTO_RECONNECT_VERSION_1 0x00000001 + +/* Cookie Lengths */ +#define MSTSC_COOKIE_MAX_LENGTH 9 +#define DEFAULT_COOKIE_MAX_LENGTH 0xFF + + /* General capability set */ +#define TS_CAPS_PROTOCOLVERSION 0x200 /** @since version 3.6.0 */ + +/* Order Support */ +#define NEG_DSTBLT_INDEX 0x00 +#define NEG_PATBLT_INDEX 0x01 +#define NEG_SCRBLT_INDEX 0x02 +#define NEG_MEMBLT_INDEX 0x03 +#define NEG_MEM3BLT_INDEX 0x04 +#define NEG_ATEXTOUT_INDEX 0x05 +#define NEG_AEXTTEXTOUT_INDEX 0x06 /* Must be ignored */ +#define NEG_DRAWNINEGRID_INDEX 0x07 /* Must be ignored */ +#define NEG_LINETO_INDEX 0x08 +#define NEG_MULTI_DRAWNINEGRID_INDEX 0x09 +#define NEG_OPAQUE_RECT_INDEX 0x0A /* Must be ignored */ +#define NEG_SAVEBITMAP_INDEX 0x0B +#define NEG_WTEXTOUT_INDEX 0x0C /* Must be ignored */ +#define NEG_MEMBLT_V2_INDEX 0x0D /* Must be ignored */ +#define NEG_MEM3BLT_V2_INDEX 0x0E /* Must be ignored */ +#define NEG_MULTIDSTBLT_INDEX 0x0F +#define NEG_MULTIPATBLT_INDEX 0x10 +#define NEG_MULTISCRBLT_INDEX 0x11 +#define NEG_MULTIOPAQUERECT_INDEX 0x12 +#define NEG_FAST_INDEX_INDEX 0x13 +#define NEG_POLYGON_SC_INDEX 0x14 +#define NEG_POLYGON_CB_INDEX 0x15 +#define NEG_POLYLINE_INDEX 0x16 +#define NEG_UNUSED23_INDEX 0x17 /* Must be ignored */ +#define NEG_FAST_GLYPH_INDEX 0x18 +#define NEG_ELLIPSE_SC_INDEX 0x19 +#define NEG_ELLIPSE_CB_INDEX 0x1A +#define NEG_GLYPH_INDEX_INDEX 0x1B +#define NEG_GLYPH_WEXTTEXTOUT_INDEX 0x1C /* Must be ignored */ +#define NEG_GLYPH_WLONGTEXTOUT_INDEX 0x1D /* Must be ignored */ +#define NEG_GLYPH_WLONGEXTTEXTOUT_INDEX 0x1E /* Must be ignored */ +#define NEG_UNUSED31_INDEX 0x1F /* Must be ignored */ + +/* Glyph Support Level */ +#define GLYPH_SUPPORT_NONE 0x0000 +#define GLYPH_SUPPORT_PARTIAL 0x0001 +#define GLYPH_SUPPORT_FULL 0x0002 +#define GLYPH_SUPPORT_ENCODE 0x0003 + +/* Gateway Usage Method */ +#define TSC_PROXY_MODE_NONE_DIRECT 0x0 +#define TSC_PROXY_MODE_DIRECT 0x1 +#define TSC_PROXY_MODE_DETECT 0x2 +#define TSC_PROXY_MODE_DEFAULT 0x3 +#define TSC_PROXY_MODE_NONE_DETECT 0x4 + +/* Gateway Credentials Source */ +#define TSC_PROXY_CREDS_MODE_USERPASS 0x0 +#define TSC_PROXY_CREDS_MODE_SMARTCARD 0x1 +#define TSC_PROXY_CREDS_MODE_ANY 0x2 + +/* Keyboard Hook */ +#define KEYBOARD_HOOK_LOCAL 0 +#define KEYBOARD_HOOK_REMOTE 1 +#define KEYBOARD_HOOK_FULLSCREEN_ONLY 2 + + typedef struct + { + UINT32 Length; + LPWSTR Address; + } TARGET_NET_ADDRESS; + +/* Logon Error Info */ +#define LOGON_MSG_DISCONNECT_REFUSED 0xFFFFFFF9 +#define LOGON_MSG_NO_PERMISSION 0xFFFFFFFA +#define LOGON_MSG_BUMP_OPTIONS 0xFFFFFFFB +#define LOGON_MSG_RECONNECT_OPTIONS 0xFFFFFFFC +#define LOGON_MSG_SESSION_TERMINATE 0xFFFFFFFD +#define LOGON_MSG_SESSION_CONTINUE 0xFFFFFFFE + +#define LOGON_FAILED_BAD_PASSWORD 0x00000000 +#define LOGON_FAILED_UPDATE_PASSWORD 0x00000001 +#define LOGON_FAILED_OTHER 0x00000002 +#define LOGON_WARNING 0x00000003 + +/* Server Status Info */ +#define STATUS_FINDING_DESTINATION 0x00000401 +#define STATUS_LOADING_DESTINATION 0x00000402 +#define STATUS_BRINGING_SESSION_ONLINE 0x00000403 +#define STATUS_REDIRECTING_TO_DESTINATION 0x00000404 +#define STATUS_VM_LOADING 0x00000501 +#define STATUS_VM_WAKING 0x00000502 +#define STATUS_VM_BOOTING 0x00000503 + +/* Compression Flags */ +#define PACKET_COMPR_TYPE_8K 0x00 +#define PACKET_COMPR_TYPE_64K 0x01 +#define PACKET_COMPR_TYPE_RDP6 0x02 +#define PACKET_COMPR_TYPE_RDP61 0x03 +#define PACKET_COMPR_TYPE_RDP8 0x04 + +/* Desktop Rotation Flags */ +#define ORIENTATION_LANDSCAPE 0 +#define ORIENTATION_PORTRAIT 90 +#define ORIENTATION_LANDSCAPE_FLIPPED 180 +#define ORIENTATION_PORTRAIT_FLIPPED 270 + +/* Clipboard feature mask */ +#define CLIPRDR_FLAG_LOCAL_TO_REMOTE 0x01 +#define CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES 0x02 +#define CLIPRDR_FLAG_REMOTE_TO_LOCAL 0x10 +#define CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES 0x20 + +#define CLIPRDR_FLAG_DEFAULT_MASK \ + (CLIPRDR_FLAG_LOCAL_TO_REMOTE | CLIPRDR_FLAG_LOCAL_TO_REMOTE_FILES | \ + CLIPRDR_FLAG_REMOTE_TO_LOCAL | CLIPRDR_FLAG_REMOTE_TO_LOCAL_FILES) + + /* ARC_CS_PRIVATE_PACKET */ + typedef struct + { + UINT32 cbLen; + UINT32 version; + UINT32 logonId; + BYTE securityVerifier[16]; + } ARC_CS_PRIVATE_PACKET; + + /* ARC_SC_PRIVATE_PACKET */ + typedef struct + { + UINT32 cbLen; + UINT32 version; + UINT32 logonId; + BYTE arcRandomBits[16]; + } ARC_SC_PRIVATE_PACKET; + + /* Channels */ + + typedef struct + { + int argc; + char** argv; + } ADDIN_ARGV; + + /* Extensions */ + + struct rdp_ext_set + { + char name[256]; /* plugin name or path */ + void* data; /* plugin data */ + }; + + /* Bitmap Cache */ + + typedef struct + { + UINT16 numEntries; + UINT16 maxSize; + } BITMAP_CACHE_CELL_INFO; + + typedef struct + { + UINT32 numEntries; + BOOL persistent; + } BITMAP_CACHE_V2_CELL_INFO; + + /* Glyph Cache */ + + typedef struct + { + UINT16 cacheEntries; + UINT16 cacheMaximumCellSize; + } GLYPH_CACHE_DEFINITION; + + /* Monitors */ + + typedef struct + { + INT32 left; + INT32 top; + INT32 right; + INT32 bottom; + UINT32 flags; + } MONITOR_DEF; + + typedef struct + { + UINT32 physicalWidth; + UINT32 physicalHeight; + UINT32 orientation; + UINT32 desktopScaleFactor; + UINT32 deviceScaleFactor; + } MONITOR_ATTRIBUTES; + + typedef struct + { + INT32 x; + INT32 y; + INT32 width; + INT32 height; + UINT32 is_primary; + UINT32 orig_screen; + MONITOR_ATTRIBUTES attributes; + } rdpMonitor; + +/* Device Redirection */ +#define RDPDR_DTYP_SERIAL 0x00000001 +#define RDPDR_DTYP_PARALLEL 0x00000002 +#define RDPDR_DTYP_PRINT 0x00000004 +#define RDPDR_DTYP_FILESYSTEM 0x00000008 +#define RDPDR_DTYP_SMARTCARD 0x00000020 + + typedef struct + { + UINT32 Id; + UINT32 Type; + char* Name; + } RDPDR_DEVICE; + + typedef struct + { + RDPDR_DEVICE device; + char* Path; + BOOL automount; + } RDPDR_DRIVE; + + typedef struct + { + RDPDR_DEVICE device; + char* DriverName; + BOOL IsDefault; + } RDPDR_PRINTER; + + typedef struct + { + RDPDR_DEVICE device; + } RDPDR_SMARTCARD; + + typedef struct + { + RDPDR_DEVICE device; + char* Path; + char* Driver; + char* Permissive; + } RDPDR_SERIAL; + + typedef struct + { + RDPDR_DEVICE device; + char* Path; + } RDPDR_PARALLEL; + +#define PROXY_TYPE_NONE 0 +#define PROXY_TYPE_HTTP 1 +#define PROXY_TYPE_SOCKS 2 +#define PROXY_TYPE_IGNORE 0xFFFF + +/* ThreadingFlags */ +#define THREADING_FLAGS_DISABLE_THREADS 0x00000001 + + enum rdp_settings_type + { + RDP_SETTINGS_TYPE_BOOL, + RDP_SETTINGS_TYPE_UINT16, + RDP_SETTINGS_TYPE_INT16, + RDP_SETTINGS_TYPE_UINT32, + RDP_SETTINGS_TYPE_INT32, + RDP_SETTINGS_TYPE_UINT64, + RDP_SETTINGS_TYPE_INT64, + RDP_SETTINGS_TYPE_STRING, + RDP_SETTINGS_TYPE_POINTER + }; + +/** + * rdpSettings creation flags + */ +#define FREERDP_SETTINGS_SERVER_MODE 0x00000001 + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif /* FREERDP_SETTINGS_TYPES_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings_types_private.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings_types_private.h new file mode 100644 index 0000000000000000000000000000000000000000..fa0cd1b9b6b70bf4be6cc658f96eccf42d4e71d3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/settings_types_private.h @@ -0,0 +1,846 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Internal settings header for functions not exported + * + * Copyright 2018 Armin Novak + * Copyright 2018 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SETTINGS_TYPES_PRIVATE_H +#define FREERDP_SETTINGS_TYPES_PRIVATE_H + +#include +#include + +#include + +#include +#include +#include + +#include + +/** \addtogroup rdpSettings + * @{ + */ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#ifndef FREERDP_SETTINGS_INTERNAL_USE +#define SETTINGS_DEPRECATED(x) WINPR_DEPRECATED(x) +#else +#define SETTINGS_DEPRECATED(x) x +#endif + +struct rdp_settings +{ + /** + * WARNING: this data structure is carefully padded for ABI stability! + * Keeping this area clean is particularly challenging, so unless you are + * a trusted developer you should NOT take the liberty of adding your own + * options straight into the ABI stable zone. Instead, append them to the + * very end of this data structure, in the zone marked as ABI unstable. + */ + + SETTINGS_DEPRECATED(ALIGN64 void* instance); /* 0 */ + UINT64 padding001[16 - 1]; /* 1 */ + + /* Core Parameters */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ServerMode); /* 16 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ShareId); /* 17 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 PduSource); /* 18 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ServerPort); /* 19 */ + SETTINGS_DEPRECATED(ALIGN64 char* ServerHostname); /* 20 */ + SETTINGS_DEPRECATED(ALIGN64 char* Username); /* 21 */ + SETTINGS_DEPRECATED(ALIGN64 char* Password); /* 22 */ + SETTINGS_DEPRECATED(ALIGN64 char* Domain); /* 23 */ + SETTINGS_DEPRECATED(ALIGN64 char* PasswordHash); /* 24 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL WaitForOutputBufferFlush); /* 25 */ + UINT64 padding26[27 - 26]; /* 26 */ + SETTINGS_DEPRECATED(ALIGN64 char* AcceptedCert); /* 27 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 AcceptedCertLength); /* 28 */ + SETTINGS_DEPRECATED(ALIGN64 char* UserSpecifiedServerName); /* 29 */ + SETTINGS_DEPRECATED(ALIGN64 char* AadServerHostname); /** 30 + * @since version 3.1.0 + */ + UINT64 padding0064[64 - 31]; /* 31 */ + /* resource management related options */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ThreadingFlags); /* 64 */ + + UINT64 padding0128[128 - 65]; /* 65 */ + + /** + * GCC User Data Blocks + */ + + /* Client/Server Core Data */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RdpVersion); /* 128 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DesktopWidth); /* 129 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DesktopHeight); /* 130 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ColorDepth); /* 131 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ConnectionType); /* 132 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ClientBuild); /* 133 */ + SETTINGS_DEPRECATED(ALIGN64 char* ClientHostname); /* 134 */ + SETTINGS_DEPRECATED(ALIGN64 char* ClientProductId); /* 135 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 EarlyCapabilityFlags); /* 136 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL NetworkAutoDetect); /* 137 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportAsymetricKeys); /* 138 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportErrorInfoPdu); /* 139 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportStatusInfoPdu); /* 140 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportMonitorLayoutPdu); /* 141 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportGraphicsPipeline); /* 142 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportDynamicTimeZone); /* 143 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportHeartbeatPdu); /* 144 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DesktopPhysicalWidth); /* 145 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DesktopPhysicalHeight); /* 146 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 DesktopOrientation); /* 147 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DesktopScaleFactor); /* 148 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DeviceScaleFactor); /* 149 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportEdgeActionV1); /* 150 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportEdgeActionV2); /* 151 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportSkipChannelJoin); /* 152 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 SupportedColorDepths); /* 153 */ + UINT64 padding0192[192 - 154]; /* 154 */ + + /* Client/Server Security Data */ + SETTINGS_DEPRECATED(ALIGN64 BOOL UseRdpSecurityLayer); /* 192 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 EncryptionMethods); /* 193 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ExtEncryptionMethods); /* 194 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 EncryptionLevel); /* 195 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* ServerRandom); /* 196 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ServerRandomLength); /* 197 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* ServerCertificate); /* 198 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ServerCertificateLength); /* 199 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* ClientRandom); /* 200 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ClientRandomLength); /* 201 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ServerLicenseRequired); /* 202 */ + SETTINGS_DEPRECATED(ALIGN64 char* ServerLicenseCompanyName); /* 203 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ServerLicenseProductVersion); /* 204 */ + SETTINGS_DEPRECATED(ALIGN64 char* ServerLicenseProductName); /* 205 */ + SETTINGS_DEPRECATED(ALIGN64 char** ServerLicenseProductIssuers); /* 206 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ServerLicenseProductIssuersCount); /* 207 */ + UINT64 padding0256[256 - 208]; /* 208 */ + + /* Client Network Data */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ChannelCount); /* 256 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ChannelDefArraySize); /* 257 */ + SETTINGS_DEPRECATED(ALIGN64 CHANNEL_DEF* ChannelDefArray); /* 258 */ + UINT64 padding0320[320 - 259]; /* 259 */ + + /* Client Cluster Data */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ClusterInfoFlags); /* 320 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RedirectedSessionId); /* 321 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ConsoleSession); /* 322 */ + UINT64 padding0384[384 - 323]; /* 323 */ + + /* Client Monitor Data */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 MonitorCount); /* 384 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 MonitorDefArraySize); /* 385 */ + SETTINGS_DEPRECATED(ALIGN64 rdpMonitor* MonitorDefArray); /* 386 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SpanMonitors); /* 387 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL UseMultimon); /* 388 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ForceMultimon); /* 389 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DesktopPosX); /* 390 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DesktopPosY); /* 391 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ListMonitors); /* 392 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32* MonitorIds); /* 393 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 NumMonitorIds); /* 394 */ + SETTINGS_DEPRECATED(ALIGN64 INT32 MonitorLocalShiftX); /*395 */ + SETTINGS_DEPRECATED(ALIGN64 INT32 MonitorLocalShiftY); /* 396 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL HasMonitorAttributes); /* 397 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 MonitorFlags); /* 398 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 MonitorAttributeFlags); /* 399 */ + UINT64 padding0448[448 - 400]; /* 400 */ + + /* Client Message Channel Data */ + UINT64 padding0512[512 - 448]; /* 448 */ + + /* Client Multitransport Channel Data */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 MultitransportFlags); /* 512 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportMultitransport); /* 513 */ + UINT64 padding0576[576 - 514]; /* 514 */ + UINT64 padding0640[640 - 576]; /* 576 */ + + /* + * Client Info + */ + + /* Client Info (Shell) */ + SETTINGS_DEPRECATED(ALIGN64 char* AlternateShell); /* 640 */ + SETTINGS_DEPRECATED(ALIGN64 char* ShellWorkingDirectory); /* 641 */ + UINT64 padding0704[704 - 642]; /* 642 */ + + /* Client Info Flags */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AutoLogonEnabled); /* 704 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL CompressionEnabled); /* 705 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableCtrlAltDel); /* 706 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL EnableWindowsKey); /* 707 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MaximizeShell); /* 708 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL LogonNotify); /* 709 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL LogonErrors); /* 710 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MouseAttached); /* 711 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MouseHasWheel); /* 712 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteConsoleAudio); /* 713 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AudioPlayback); /* 714 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AudioCapture); /* 715 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL VideoDisable); /* 716 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL PasswordIsSmartcardPin); /* 717 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL UsingSavedCredentials); /* 718 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ForceEncryptedCsPdu); /* 719 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL HiDefRemoteApp); /* 720 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 CompressionLevel); /* 721 */ + UINT64 padding0768[768 - 722]; /* 722 */ + + /* Client Info (Extra) */ + SETTINGS_DEPRECATED(ALIGN64 BOOL IPv6Enabled); /* 768 */ + SETTINGS_DEPRECATED(ALIGN64 char* ClientAddress); /* 769 */ + SETTINGS_DEPRECATED(ALIGN64 char* ClientDir); /* 770 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ClientSessionId); /* 771 */ + UINT64 padding0832[832 - 772]; /* 772 */ + + /* Client Info (Auto Reconnection) */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AutoReconnectionEnabled); /* 832 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 AutoReconnectMaxRetries); /* 833 */ + SETTINGS_DEPRECATED(ALIGN64 ARC_CS_PRIVATE_PACKET* ClientAutoReconnectCookie); /* 834 */ + SETTINGS_DEPRECATED(ALIGN64 ARC_SC_PRIVATE_PACKET* ServerAutoReconnectCookie); /* 835 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL PrintReconnectCookie); /* 836 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AutoReconnectionPacketSupported); /** 837 + @since version 3.5.0 +*/ + UINT64 padding0896[896 - 838]; /* 838 */ + + /* Client Info (Time Zone) */ + SETTINGS_DEPRECATED(ALIGN64 TIME_ZONE_INFORMATION* ClientTimeZone); /* 896 */ + SETTINGS_DEPRECATED(ALIGN64 char* DynamicDSTTimeZoneKeyName); /* 897 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DynamicDaylightTimeDisabled); /* 898 */ + UINT64 padding0960[960 - 899]; /* 899 */ + + /* Client Info (Performance Flags) */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 PerformanceFlags); /* 960 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AllowFontSmoothing); /* 961 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableWallpaper); /* 962 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableFullWindowDrag); /* 963 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableMenuAnims); /* 964 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableThemes); /* 965 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableCursorShadow); /* 966 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableCursorBlinking); /* 967 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AllowDesktopComposition); /* 968 */ + UINT64 padding1024[1024 - 969]; /* 969 */ + + /* Remote Assistance */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteAssistanceMode); /* 1024 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteAssistanceSessionId); /* 1025 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteAssistancePassStub); /* 1026 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteAssistancePassword); /* 1027 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteAssistanceRCTicket); /* 1028 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL EncomspVirtualChannel); /* 1029 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemdeskVirtualChannel); /* 1030 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL LyncRdpMode); /* 1031 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteAssistanceRequestControl); /* 1032 */ + UINT64 padding1088[1088 - 1033]; /* 1033 */ + + /** + * X.224 Connection Request/Confirm + */ + + /* Protocol Security */ + SETTINGS_DEPRECATED(ALIGN64 BOOL TlsSecurity); /* 1088 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL NlaSecurity); /* 1089 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RdpSecurity); /* 1090 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ExtSecurity); /* 1091 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL Authentication); /* 1092 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RequestedProtocols); /* 1093 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 SelectedProtocol); /* 1094 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 NegotiationFlags); /* 1095 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL NegotiateSecurityLayer); /* 1096 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RestrictedAdminModeRequired); /* 1097 */ + SETTINGS_DEPRECATED(ALIGN64 char* AuthenticationServiceClass); /* 1098 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableCredentialsDelegation); /* 1099 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 AuthenticationLevel); /* 1100 */ + SETTINGS_DEPRECATED(ALIGN64 char* AllowedTlsCiphers); /* 1101 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL VmConnectMode); /* 1102 */ + SETTINGS_DEPRECATED(ALIGN64 char* NtlmSamFile); /* 1103 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL FIPSMode); /* 1104 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 TlsSecLevel); /* 1105 */ + SETTINGS_DEPRECATED(ALIGN64 char* SspiModule); /* 1106 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 TLSMinVersion); /* 1107 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 TLSMaxVersion); /* 1108 */ + SETTINGS_DEPRECATED(ALIGN64 char* TlsSecretsFile); /* 1109 */ + SETTINGS_DEPRECATED(ALIGN64 char* AuthenticationPackageList); /* 1110 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RdstlsSecurity); /* 1111 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AadSecurity); /* 1112 */ + SETTINGS_DEPRECATED(ALIGN64 char* WinSCardModule); /* 1113 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteCredentialGuard); /* 1114 */ + UINT64 padding1152[1152 - 1115]; /* 1115 */ + + /* Connection Cookie */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MstscCookieMode); /* 1152 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 CookieMaxLength); /* 1153 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 PreconnectionId); /* 1154 */ + SETTINGS_DEPRECATED(ALIGN64 char* PreconnectionBlob); /* 1155 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SendPreconnectionPdu); /* 1156 */ + UINT64 padding1216[1216 - 1157]; /* 1157 */ + + /* Server Redirection */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RedirectionFlags); /* 1216 */ + SETTINGS_DEPRECATED(ALIGN64 char* TargetNetAddress); /* 1217 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* LoadBalanceInfo); /* 1218 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 LoadBalanceInfoLength); /* 1219 */ + SETTINGS_DEPRECATED(ALIGN64 char* RedirectionUsername); /* 1220 */ + SETTINGS_DEPRECATED(ALIGN64 char* RedirectionDomain); /* 1221 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* RedirectionPassword); /* 1222 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RedirectionPasswordLength); /* 1223 */ + SETTINGS_DEPRECATED(ALIGN64 char* RedirectionTargetFQDN); /* 1224 */ + SETTINGS_DEPRECATED(ALIGN64 char* RedirectionTargetNetBiosName); /* 1225 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* RedirectionTsvUrl); /* 1226 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RedirectionTsvUrlLength); /* 1227 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 TargetNetAddressCount); /* 1228 */ + SETTINGS_DEPRECATED(ALIGN64 char** TargetNetAddresses); /* 1229 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32* TargetNetPorts); /* 1230 */ + SETTINGS_DEPRECATED(ALIGN64 char* RedirectionAcceptedCert); /* 1231 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RedirectionAcceptedCertLength); /* 1232 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RedirectionPreferType); /* 1233 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* RedirectionGuid); /* 1234 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RedirectionGuidLength); /* 1235 */ + SETTINGS_DEPRECATED(ALIGN64 rdpCertificate* RedirectionTargetCertificate); /* 1236 */ + UINT64 padding1280[1280 - 1237]; /* 1237 */ + + /** + * Security + */ + + /* Credentials Cache */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* Password51); /* 1280 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 Password51Length); /* 1281 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SmartcardLogon); /* 1282 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL PromptForCredentials); /* 1283 */ + UINT64 padding1284[1285 - 1284]; /* 1284 */ + + /* Settings used for smartcard emulation */ + SETTINGS_DEPRECATED(ALIGN64 char* SmartcardCertificate); /* 1285 */ + SETTINGS_DEPRECATED(ALIGN64 char* SmartcardPrivateKey); /* 1286 */ + UINT64 padding1287[1288 - 1287]; /* 1287 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SmartcardEmulation); /* 1288 */ + SETTINGS_DEPRECATED(ALIGN64 char* Pkcs11Module); /* 1289 */ + SETTINGS_DEPRECATED(ALIGN64 char* PkinitAnchors); /* 1290 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 KeySpec); /* 1291 */ + SETTINGS_DEPRECATED(ALIGN64 char* CardName); /* 1292 */ + SETTINGS_DEPRECATED(ALIGN64 char* ReaderName); /* 1293 */ + SETTINGS_DEPRECATED(ALIGN64 char* ContainerName); /* 1294 */ + SETTINGS_DEPRECATED(ALIGN64 char* CspName); /* 1295 */ + UINT64 padding1344[1344 - 1296]; /* 1296 */ + + /* Kerberos Authentication */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosKdcUrl); /* 1344 */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosRealm); /* 1345 */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosStartTime); /* 1346 */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosLifeTime); /* 1347 */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosRenewableLifeTime); /* 1348 */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosCache); /* 1349 */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosArmor); /* 1350 */ + SETTINGS_DEPRECATED(ALIGN64 char* KerberosKeytab); /* 1351 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL KerberosRdgIsProxy); /* 1352 */ + UINT64 padding1408[1408 - 1353]; /* 1353 */ + + /* Server Certificate */ + SETTINGS_DEPRECATED(ALIGN64 BOOL IgnoreCertificate); /* 1408 */ + SETTINGS_DEPRECATED(ALIGN64 char* CertificateName); /* 1409 */ + UINT64 padding1410[1413 - 1410]; /* 1410 */ + SETTINGS_DEPRECATED(ALIGN64 rdpPrivateKey* RdpServerRsaKey); /* 1413 */ + SETTINGS_DEPRECATED(ALIGN64 rdpCertificate* RdpServerCertificate); /* 1414 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ExternalCertificateManagement); /* 1415 */ + UINT64 padding1416[1419 - 1416]; /* 1416 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AutoAcceptCertificate); /* 1419 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AutoDenyCertificate); /* 1420 */ + SETTINGS_DEPRECATED(ALIGN64 char* CertificateAcceptedFingerprints); /* 1421 */ + UINT64 padding1422[1423 - 1422]; /* 1422 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL CertificateCallbackPreferPEM); /* 1423 */ + UINT64 padding1472[1472 - 1424]; /* 1424 */ + UINT64 padding1536[1536 - 1472]; /* 1472 */ + + /** + * User Interface + */ + + /* Window Settings */ + SETTINGS_DEPRECATED(ALIGN64 BOOL Workarea); /* 1536 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL Fullscreen); /* 1537 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 PercentScreen); /* 1538 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GrabKeyboard); /* 1539 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL Decorations); /* 1540 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MouseMotion); /* 1541 */ + SETTINGS_DEPRECATED(ALIGN64 char* WindowTitle); /* 1542 */ + SETTINGS_DEPRECATED(ALIGN64 UINT64 ParentWindowId); /* 1543 */ + UINT64 padding1544[1545 - 1544]; /* 1544 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AsyncUpdate); /* 1545 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AsyncChannels); /* 1546 */ + UINT64 padding1548[1548 - 1547]; /* 1547 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ToggleFullscreen); /* 1548 */ + SETTINGS_DEPRECATED(ALIGN64 char* WmClass); /* 1549 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL EmbeddedWindow); /* 1550 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SmartSizing); /* 1551 */ + SETTINGS_DEPRECATED(ALIGN64 INT32 XPan); /* 1552 */ + SETTINGS_DEPRECATED(ALIGN64 INT32 YPan); /* 1553 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 SmartSizingWidth); /* 1554 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 SmartSizingHeight); /* 1555 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL PercentScreenUseWidth); /* 1556 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL PercentScreenUseHeight); /* 1557 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DynamicResolutionUpdate); /* 1558 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GrabMouse); /* 1559 */ + UINT64 padding1601[1601 - 1560]; /* 1560 */ + + /* Miscellaneous */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SoftwareGdi); /* 1601 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL LocalConnection); /* 1602 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AuthenticationOnly); /* 1603 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL CredentialsFromStdin); /* 1604 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL UnmapButtons); /* 1605 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL OldLicenseBehaviour); /* 1606 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MouseUseRelativeMove); /* 1607 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL UseCommonStdioCallbacks); /* 1608 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL ConnectChildSession); /* 1609 */ + UINT64 padding1664[1664 - 1610]; /* 1610 */ + + /* Names */ + SETTINGS_DEPRECATED(ALIGN64 char* ComputerName); /* 1664 */ + UINT64 padding1728[1728 - 1665]; /* 1665 */ + + /* Files */ + SETTINGS_DEPRECATED(ALIGN64 char* ConnectionFile); /* 1728 */ + SETTINGS_DEPRECATED(ALIGN64 char* AssistanceFile); /* 1729 */ + UINT64 padding1792[1792 - 1730]; /* 1730 */ + + /* Paths */ + SETTINGS_DEPRECATED(ALIGN64 char* HomePath); /* 1792 */ + SETTINGS_DEPRECATED(ALIGN64 char* ConfigPath); /* 1793 */ + SETTINGS_DEPRECATED(ALIGN64 char* CurrentPath); /* 1794 */ + UINT64 padding1856[1856 - 1795]; /* 1795 */ + + /* Recording */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DumpRemoteFx); /* 1856 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL PlayRemoteFx); /* 1857 */ + SETTINGS_DEPRECATED(ALIGN64 char* DumpRemoteFxFile); /* 1858 */ + SETTINGS_DEPRECATED(ALIGN64 char* PlayRemoteFxFile); /* 1859 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL TransportDump); /* 1860 */ + SETTINGS_DEPRECATED(ALIGN64 char* TransportDumpFile); /* 1861 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL TransportDumpReplay); /* 1862 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DeactivateClientDecoding); /* 1863 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL TransportDumpReplayNodelay); /** 1864 + * @since version 3.6.0 + */ + UINT64 padding1920[1920 - 1865]; /* 1865 */ + UINT64 padding1984[1984 - 1920]; /* 1920 */ + + /** + * Gateway + */ + + /* Gateway */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 GatewayUsageMethod); /* 1984 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 GatewayPort); /* 1985 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayHostname); /* 1986 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayUsername); /* 1987 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayPassword); /* 1988 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayDomain); /* 1989 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 GatewayCredentialsSource); /* 1990 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayUseSameCredentials); /* 1991 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayEnabled); /* 1992 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayBypassLocal); /* 1993 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayRpcTransport); /* 1994 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayHttpTransport); /* 1995 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayUdpTransport); /* 1996 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAccessToken); /* 1997 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAcceptedCert); /* 1998 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 GatewayAcceptedCertLength); /* 1999 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayHttpUseWebsockets); /* 2000 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayHttpExtAuthSspiNtlm); /* 2001 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayHttpExtAuthBearer); /* 2002 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayUrl); /* 2003 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayArmTransport); /* 2004 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdWvdEndpointPool); /* 2005 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdGeo); /* 2006 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdArmpath); /* 2007 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdAadtenantid); /* 2008 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdDiagnosticserviceurl); /* 2009 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdHubdiscoverygeourl); /* 2010 */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdActivityhint); /* 2011 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayIgnoreRedirectionPolicy); /** 2012 + * @since version 3.4.0 + */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAvdClientID); /** 2013 + * @since version 3.10.0 + */ + SETTINGS_DEPRECATED(ALIGN64 char* GatewayAzureActiveDirectory); /** 2014 + * @since version 3.10.0 + */ + + /* Proxy */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ProxyType); /* 2015 */ + SETTINGS_DEPRECATED(ALIGN64 char* ProxyHostname); /* 2016 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 ProxyPort); /* 2017 */ + SETTINGS_DEPRECATED(ALIGN64 char* ProxyUsername); /* 2018 */ + SETTINGS_DEPRECATED(ALIGN64 char* ProxyPassword); /* 2019 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GatewayAvdUseTenantid); /** 2020 + * @since version 3.10.0 + */ + UINT64 padding2112[2112 - 2021]; /* 2021 */ + + /** + * RemoteApp + */ + + /* RemoteApp */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteApplicationMode); /* 2112 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteApplicationName); /* 2113 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteApplicationIcon); /* 2114 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteApplicationProgram); /* 2115 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteApplicationFile); /* 2116 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteApplicationGuid); /* 2117 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteApplicationCmdLine); /* 2118 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteApplicationExpandCmdLine); /* 2119 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteApplicationExpandWorkingDir); /* 2120 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DisableRemoteAppCapsCheck); /* 2121 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteAppNumIconCaches); /* 2122 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteAppNumIconCacheEntries); /* 2123 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteAppLanguageBarSupported); /* 2124 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteWndSupportLevel); /* 2125 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteApplicationSupportLevel); /* 2126 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteApplicationSupportMask); /* 2127 */ + SETTINGS_DEPRECATED(ALIGN64 char* RemoteApplicationWorkingDir); /* 2128 */ + UINT64 padding2176[2176 - 2129]; /* 2129 */ + UINT64 padding2240[2240 - 2176]; /* 2176 */ + + /** + * Mandatory Capabilities + */ + + /* Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* ReceivedCapabilities); /* 2240 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ReceivedCapabilitiesSize); /* 2241 */ + SETTINGS_DEPRECATED(ALIGN64 BYTE** ReceivedCapabilityData); /* 2242 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32* ReceivedCapabilityDataSizes); /* 2243 */ + UINT64 padding2304[2304 - 2244]; /* 2244 */ + + /* General Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 OsMajorType); /* 2304 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 OsMinorType); /* 2305 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RefreshRect); /* 2306 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SuppressOutput); /* 2307 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL FastPathOutput); /* 2308 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SaltedChecksum); /* 2309 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL LongCredentialsSupported); /* 2310 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL NoBitmapCompressionHeader); /* 2311 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL BitmapCompressionDisabled); /* 2312 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 CapsProtocolVersion); /* 2313 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 CapsGeneralCompressionTypes); /* 2314 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 CapsUpdateCapabilityFlag); /* 2315 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 CapsRemoteUnshareFlag); /* 2316 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 CapsGeneralCompressionLevel); /* 2317 */ + UINT64 padding2368[2368 - 2318]; /* 2318 */ + + /* Bitmap Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DesktopResize); /* 2368 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DrawAllowDynamicColorFidelity); /* 2369 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DrawAllowColorSubsampling); /* 2370 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DrawAllowSkipAlpha); /* 2371 */ + UINT64 padding2432[2432 - 2372]; /* 2372 */ + + /* Order Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 BYTE* OrderSupport); /* 2432 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL BitmapCacheV3Enabled); /* 2433 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AltSecFrameMarkerSupport); /* 2434 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AllowUnanouncedOrdersFromServer); /* 2435 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 OrderSupportFlags); /* 2436 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 OrderSupportFlagsEx); /* 2437 */ + SETTINGS_DEPRECATED(ALIGN64 char* TerminalDescriptor); /* 2438 */ + SETTINGS_DEPRECATED(ALIGN64 UINT16 TextANSICodePage); /* 2439 */ + UINT64 padding2497[2497 - 2440]; /* 2440 */ + + /* Bitmap Cache Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 BOOL BitmapCacheEnabled); /* 2497 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 BitmapCacheVersion); /* 2498 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL AllowCacheWaitingList); /* 2499 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL BitmapCachePersistEnabled); /* 2500 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 BitmapCacheV2NumCells); /* 2501 */ + SETTINGS_DEPRECATED(ALIGN64 BITMAP_CACHE_V2_CELL_INFO* BitmapCacheV2CellInfo); /* 2502 */ + SETTINGS_DEPRECATED(ALIGN64 char* BitmapCachePersistFile); /* 2503 */ + UINT64 padding2560[2560 - 2504]; /* 2504 */ + + /* Pointer Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ColorPointerCacheSize); /* 2560 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 PointerCacheSize); /* 2561 */ + UINT64 padding2624[2622 - 2562]; /* 2562 */ + + /* Input Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 char* KeyboardRemappingList); /* 2622 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 KeyboardCodePage); /* 2623 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 KeyboardLayout); /* 2624 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 KeyboardType); /* 2625 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 KeyboardSubType); /* 2626 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 KeyboardFunctionKey); /* 2627 */ + SETTINGS_DEPRECATED(ALIGN64 char* ImeFileName); /* 2628 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL UnicodeInput); /* 2629 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL FastPathInput); /* 2630 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MultiTouchInput); /* 2631 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL MultiTouchGestures); /* 2632 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 KeyboardHook); /* 2633 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL HasHorizontalWheel); /* 2634 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL HasExtendedMouseEvent); /* 2635 */ + + /** SuspendInput disables processing of keyboard/mouse/multitouch input. + * If used by an implementation ensure proper state resync after reenabling + * input + */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SuspendInput); /* 2636 */ + SETTINGS_DEPRECATED(ALIGN64 char* KeyboardPipeName); /* 2637 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL HasRelativeMouseEvent); /* 2638 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL HasQoeEvent); /* 2639 */ + UINT64 padding2688[2688 - 2640]; /* 2640 */ + + /* Brush Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 BrushSupportLevel); /* 2688 */ + UINT64 padding2752[2752 - 2689]; /* 2689 */ + + /* Glyph Cache Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 GlyphSupportLevel); /* 2752 */ + SETTINGS_DEPRECATED(ALIGN64 GLYPH_CACHE_DEFINITION* GlyphCache); /* 2753 */ + SETTINGS_DEPRECATED(ALIGN64 GLYPH_CACHE_DEFINITION* FragCache); /* 2754 */ + UINT64 padding2816[2816 - 2755]; /* 2755 */ + + /* Offscreen Bitmap Cache */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 OffscreenSupportLevel); /* 2816 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 OffscreenCacheSize); /* 2817 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 OffscreenCacheEntries); /* 2818 */ + UINT64 padding2880[2880 - 2819]; /* 2819 */ + + /* Virtual Channel Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 VCFlags); /* 2880 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 VCChunkSize); /* 2881 */ + UINT64 padding2944[2944 - 2882]; /* 2882 */ + + /* Sound Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SoundBeepsEnabled); /* 2944 */ + UINT64 padding3008[3008 - 2945]; /* 2945 */ + UINT64 padding3072[3072 - 3008]; /* 3008 */ + + /** + * Optional Capabilities + */ + + /* Bitmap Cache Host Capabilities */ + UINT64 padding3136[3136 - 3072]; /* 3072 */ + + /* Control Capabilities */ + UINT64 padding3200[3200 - 3136]; /* 3136 */ + + /* Window Activation Capabilities */ + UINT64 padding3264[3264 - 3200]; /* 3200 */ + + /* Font Capabilities */ + UINT64 padding3328[3328 - 3264]; /* 3264 */ + + /* Multifragment Update Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 MultifragMaxRequestSize); /* 3328 */ + UINT64 padding3392[3392 - 3329]; /* 3329 */ + + /* Large Pointer Update Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 LargePointerFlag); /* 3392 */ + UINT64 padding3456[3456 - 3393]; /* 3393 */ + + /* Desktop Composition Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 CompDeskSupportLevel); /* 3456 */ + UINT64 padding3520[3520 - 3457]; /* 3457 */ + + /* Surface Commands Capabilities */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SurfaceCommandsEnabled); /* 3520 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL FrameMarkerCommandEnabled); /* 3521 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SurfaceFrameMarkerEnabled); /* 3522 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 SurfaceCommandsSupported); /** 3523 + * @since version 3.7.0 + */ + UINT64 padding3584[3584 - 3524]; /* 3524 */ + UINT64 padding3648[3648 - 3584]; /* 3584 */ + + /* + * Bitmap Codecs Capabilities + */ + + /* RemoteFX */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteFxOnly); /* 3648 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteFxCodec); /* 3649 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteFxCodecId); /* 3650 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteFxCodecMode); /* 3651 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RemoteFxImageCodec); /* 3652 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteFxCaptureFlags); /* 3653 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 RemoteFxRlgrMode); /** 3654 + * @since version 3.7.0 + */ + UINT64 padding3712[3712 - 3655]; /* 3655 */ + + /* NSCodec */ + SETTINGS_DEPRECATED(ALIGN64 BOOL NSCodec); /* 3712 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 NSCodecId); /* 3713 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 FrameAcknowledge); /* 3714 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 NSCodecColorLossLevel); /* 3715 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL NSCodecAllowSubsampling); /* 3716 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL NSCodecAllowDynamicColorFidelity); /* 3717 */ + UINT64 padding3776[3776 - 3718]; /* 3718 */ + + /* JPEG */ + SETTINGS_DEPRECATED(ALIGN64 BOOL JpegCodec); /* 3776 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 JpegCodecId); /* 3777 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 JpegQuality); /* 3778 */ + UINT64 padding3840[3840 - 3779]; /* 3779 */ + + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxThinClient); /* 3840 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxSmallCache); /* 3841 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxProgressive); /* 3842 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxProgressiveV2); /* 3843 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxH264); /* 3844 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxAVC444); /* 3845 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxSendQoeAck); /* 3846 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxAVC444v2); /* 3847 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 GfxCapsFilter); /* 3848 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxPlanar); /* 3849 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL GfxSuspendFrameAck); /** 3850 + * @since version 3.6.0 + */ + UINT64 padding3904[3904 - 3851]; /* 3851 */ + + /** + * Caches + */ + + /* Bitmap Cache V3 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 BitmapCacheV3CodecId); /* 3904 */ + UINT64 padding3968[3968 - 3905]; /* 3905 */ + + /* Draw Nine Grid */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DrawNineGridEnabled); /* 3968 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DrawNineGridCacheSize); /* 3969 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DrawNineGridCacheEntries); /* 3970 */ + UINT64 padding4032[4032 - 3971]; /* 3971 */ + + /* Draw GDI+ */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DrawGdiPlusEnabled); /* 4032 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DrawGdiPlusCacheEnabled); /* 4033 */ + UINT64 padding4096[4096 - 4034]; /* 4034 */ + UINT64 padding4160[4160 - 4096]; /* 4096 */ + + /** + * Device Redirection + */ + + /* Device Redirection */ + SETTINGS_DEPRECATED(ALIGN64 BOOL DeviceRedirection); /* 4160 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DeviceCount); /* 4161 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DeviceArraySize); /* 4162 */ + SETTINGS_DEPRECATED(ALIGN64 RDPDR_DEVICE** DeviceArray); /* 4163 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL IgnoreInvalidDevices); /* 4164 */ + UINT64 padding4288[4288 - 4165]; /* 4165 */ + + /* Drive Redirection */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectDrives); /* 4288 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectHomeDrive); /* 4289 */ + SETTINGS_DEPRECATED(ALIGN64 char* DrivesToRedirect); /* 4290 */ + UINT64 padding4416[4416 - 4291]; /* 4291 */ + + /* Smartcard Redirection */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectSmartCards); /* 4416 */ + /* WebAuthN Redirection */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectWebAuthN); /* 4417 */ + UINT64 padding4544[4544 - 4418]; /* 4418 */ + + /* Printer Redirection */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectPrinters); /* 4544 */ + UINT64 padding4672[4672 - 4545]; /* 4545 */ + + /* Serial and Parallel Port Redirection */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectSerialPorts); /* 4672 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectParallelPorts); /* 4673 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL PreferIPv6OverIPv4); /* 4674 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ForceIPvX); /** 4675 + * @since version 3.6.0 + */ + UINT64 padding4800[4800 - 4676]; /* 4676 */ + + /** + * Other Redirection + */ + + SETTINGS_DEPRECATED(ALIGN64 BOOL RedirectClipboard); /* 4800 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 ClipboardFeatureMask); /* 4801 */ + SETTINGS_DEPRECATED(ALIGN64 char* ClipboardUseSelection); /* 4802 */ + SETTINGS_DEPRECATED(UINT64 padding4928[4928 - 4803]); /* 4803 */ + + /** + * Static Virtual Channels + */ + + SETTINGS_DEPRECATED(ALIGN64 UINT32 StaticChannelCount); /* 4928 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 StaticChannelArraySize); /* 4929 */ + SETTINGS_DEPRECATED(ALIGN64 ADDIN_ARGV** StaticChannelArray); /* 4930 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SynchronousStaticChannels); /** 4931 + * @since version 3.3.0 */ + UINT64 padding5056[5056 - 4932]; /* 4932 */ + + /** + * Dynamic Virtual Channels + */ + + SETTINGS_DEPRECATED(ALIGN64 UINT32 DynamicChannelCount); /* 5056 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 DynamicChannelArraySize); /* 5057 */ + SETTINGS_DEPRECATED(ALIGN64 ADDIN_ARGV** DynamicChannelArray); /* 5058 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportDynamicChannels); /* 5059 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SynchronousDynamicChannels); /** 5060 + * @since version 3.2.0 + */ + UINT64 padding5184[5184 - 5061]; /* 5061 */ + + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportEchoChannel); /* 5184 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportDisplayControl); /* 5185 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportGeometryTracking); /* 5186 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportSSHAgentChannel); /* 5187 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL SupportVideoOptimized); /* 5188 */ + SETTINGS_DEPRECATED(ALIGN64 char* RDP2TCPArgs); /* 5189 */ + SETTINGS_DEPRECATED(ALIGN64 BOOL TcpKeepAlive); /* 5190 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 TcpKeepAliveRetries); /* 5191 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 TcpKeepAliveDelay); /* 5192 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 TcpKeepAliveInterval); /* 5193 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 TcpAckTimeout); /* 5194 */ + SETTINGS_DEPRECATED(ALIGN64 char* ActionScript); /* 5195 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 Floatbar); /* 5196 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 TcpConnectTimeout); /* 5197 */ + SETTINGS_DEPRECATED(ALIGN64 UINT32 FakeMouseMotionInterval); /* 5198 */ + UINT64 padding5312[5312 - 5199]; /* 5199 */ + + /** + * WARNING: End of ABI stable zone! + * + * The zone below this point is ABI unstable, and + * is therefore potentially subject to ABI breakage. + */ +}; + +#ifdef __cplusplus +} +#endif + +/** @} */ + +#endif /* FREERDP_SETTINGS_TYPES_PRIVATE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/streamdump.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/streamdump.h new file mode 100644 index 0000000000000000000000000000000000000000..14bd5fde33ce05158ecddd62abd3d607243ca5e9 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/streamdump.h @@ -0,0 +1,60 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Interface to dump RDP session data to files + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_STREAM_DUMP_H +#define FREERDP_STREAM_DUMP_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct stream_dump_context rdpStreamDumpContext; + + typedef enum + { + STREAM_MSG_SRV_RX = 1, + STREAM_MSG_SRV_TX = 2 + } StreamDumpDirection; + + FREERDP_API SSIZE_T stream_dump_append(const rdpContext* context, UINT32 flags, wStream* s, + size_t* offset); + FREERDP_API SSIZE_T stream_dump_get(const rdpContext* context, UINT32* flags, wStream* s, + size_t* offset, UINT64* pts); + + FREERDP_API BOOL stream_dump_register_handlers(rdpContext* context, CONNECTION_STATE state, + BOOL isServer); + + FREERDP_API void stream_dump_free(rdpStreamDumpContext* dump); + + WINPR_ATTR_MALLOC(stream_dump_free, 1) + FREERDP_API rdpStreamDumpContext* stream_dump_new(void); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_STREAM_DUMP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/svc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/svc.h new file mode 100644 index 0000000000000000000000000000000000000000..e7154a2ae38bd16ec6de9eb58829bd25fc19ec05 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/svc.h @@ -0,0 +1,81 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Static Virtual Channel Interface + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_SVC_H +#define FREERDP_SVC_H + +#include +#include + +#include +#include + +#define CHANNEL_EVENT_USER 1000 + +#define CHANNEL_EXPORT_FUNC_NAME "VirtualChannelEntry" +#define CHANNEL_EXPORT_FUNC_NAME_EX "VirtualChannelEntryEx" + +#define FREERDP_CHANNEL_MAGIC_NUMBER 0x46524450 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 cbSize; + UINT32 protocolVersion; + PVIRTUALCHANNELINIT pVirtualChannelInit; + PVIRTUALCHANNELOPEN pVirtualChannelOpen; + PVIRTUALCHANNELCLOSE pVirtualChannelClose; + PVIRTUALCHANNELWRITE pVirtualChannelWrite; + + /* Extended Fields */ + UINT32 MagicNumber; /* identifies FreeRDP */ + void* pExtendedData; /* extended initial data */ + void* pInterface; /* channel callback interface, use after initialization */ + rdpContext* context; + } CHANNEL_ENTRY_POINTS_FREERDP; + typedef CHANNEL_ENTRY_POINTS_FREERDP* PCHANNEL_ENTRY_POINTS_FREERDP; + + typedef struct + { + UINT32 cbSize; + UINT32 protocolVersion; + PVIRTUALCHANNELINITEX pVirtualChannelInitEx; + PVIRTUALCHANNELOPENEX pVirtualChannelOpenEx; + PVIRTUALCHANNELCLOSEEX pVirtualChannelCloseEx; + PVIRTUALCHANNELWRITEEX pVirtualChannelWriteEx; + + /* Extended Fields */ + UINT32 MagicNumber; /* identifies FreeRDP */ + void* pExtendedData; /* extended initial data */ + void* pInterface; /* channel callback interface, use after initialization */ + rdpContext* context; + } CHANNEL_ENTRY_POINTS_FREERDP_EX; + typedef CHANNEL_ENTRY_POINTS_FREERDP_EX* PCHANNEL_ENTRY_POINTS_FREERDP_EX; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_SVC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/transport_io.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/transport_io.h new file mode 100644 index 0000000000000000000000000000000000000000..fd13dc1b1c0cb62717278a3b71ec4b5454d68acb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/transport_io.h @@ -0,0 +1,163 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * FreeRDP Interface + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_TRANSPORT_IO_H +#define FREERDP_TRANSPORT_IO_H + +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @brief Read data from a transport layer + * @param userContext user defined context passed by @ref freerdp_set_io_callback_context + * @param data a buffer to read to + * @param bytes the size of the buffer + * @return the number of bytes read or <0 for failures + * @since version 3.9.0 + */ + typedef int (*pTransportLayerRead)(void* userContext, void* data, int bytes); + + /** + * @brief write data to a transport layer + * @param userContext user defined context passed by @ref freerdp_set_io_callback_context + * @param data a buffer to write + * @param bytes the size of the buffer + * @return the number of bytes written or <0 for failures + * @since version 3.9.0 + */ + typedef int (*pTransportLayerWrite)(void* userContext, const void* data, int bytes); + typedef BOOL (*pTransportLayerFkt)(void* userContext); + typedef BOOL (*pTransportLayerWait)(void* userContext, BOOL waitWrite, DWORD timeout); + typedef HANDLE (*pTransportLayerGetEvent)(void* userContext); + + /** + * @since version 3.9.0 + */ + typedef struct + { + ALIGN64 void* userContext; + ALIGN64 pTransportLayerRead Read; + ALIGN64 pTransportLayerWrite Write; + ALIGN64 pTransportLayerFkt Close; + ALIGN64 pTransportLayerWait Wait; + ALIGN64 pTransportLayerGetEvent GetEvent; + UINT64 reserved[64 - 6]; /* Reserve some space for ABI compatibility */ + } rdpTransportLayer; + + typedef int (*pTCPConnect)(rdpContext* context, rdpSettings* settings, const char* hostname, + int port, DWORD timeout); + typedef BOOL (*pTransportFkt)(rdpTransport* transport); + typedef BOOL (*pTransportAttach)(rdpTransport* transport, int sockfd); + typedef int (*pTransportRWFkt)(rdpTransport* transport, wStream* s); + typedef SSIZE_T (*pTransportRead)(rdpTransport* transport, BYTE* data, size_t bytes); + typedef BOOL (*pTransportGetPublicKey)(rdpTransport* transport, const BYTE** data, + DWORD* length); + /** + * @brief Modify transport behaviour between blocking and non blocking operation + * + * @param transport The transport to manipulate + * @param blocking Boolean to set the transport \b TRUE blocking and \b FALSE non-blocking + * @return \b TRUE for success, \b FALSE for any error + * + * @since version 3.3.0 + */ + typedef BOOL (*pTransportSetBlockingMode)(rdpTransport* transport, BOOL blocking); + typedef rdpTransportLayer* (*pTransportConnectLayer)(rdpTransport* transport, + const char* hostname, int port, + DWORD timeout); + + /** + * @brief Return the public key as PEM from transport layer. + * @param transport the transport to query + * @param layer the transport layer to attach + * + * @return \b TRUE for success, \b FALSE for failure + * @since version 3.2.0 + */ + typedef BOOL (*pTransportAttachLayer)(rdpTransport* transport, rdpTransportLayer* layer); + + struct rdp_transport_io + { + pTCPConnect TCPConnect; + pTransportFkt TLSConnect; + pTransportFkt TLSAccept; + pTransportAttach TransportAttach; + pTransportFkt TransportDisconnect; + pTransportRWFkt ReadPdu; /* Reads a whole PDU from the transport */ + pTransportRWFkt WritePdu; /* Writes a whole PDU to the transport */ + pTransportRead ReadBytes; /* Reads up to a requested amount of bytes */ + pTransportGetPublicKey GetPublicKey; /** @since version 3.2.0 */ + pTransportSetBlockingMode SetBlockingMode; /** @since version 3.3.0 */ + pTransportConnectLayer ConnectLayer; /** @since 3.9.0 */ + pTransportAttachLayer AttachLayer; /** @since 3.9.0 */ + UINT64 reserved[64 - 12]; /* Reserve some space for ABI compatibility */ + }; + typedef struct rdp_transport_io rdpTransportIo; + + FREERDP_API BOOL freerdp_io_callback_set_event(rdpContext* context, BOOL set); + + FREERDP_API const rdpTransportIo* freerdp_get_io_callbacks(rdpContext* context); + FREERDP_API BOOL freerdp_set_io_callbacks(rdpContext* context, + const rdpTransportIo* io_callbacks); + + FREERDP_API BOOL freerdp_set_io_callback_context(rdpContext* context, void* usercontext); + FREERDP_API void* freerdp_get_io_callback_context(rdpContext* context); + + /* PDU parser. + * incomplete: FALSE if the whole PDU is available, TRUE otherwise + * Return: 0 -> PDU header incomplete + * >0 -> PDU header complete, length of PDU. + * <0 -> Abort, an error occurred + */ + FREERDP_API SSIZE_T transport_parse_pdu(rdpTransport* transport, wStream* s, BOOL* incomplete); + FREERDP_API rdpContext* transport_get_context(rdpTransport* transport); + FREERDP_API rdpTransport* freerdp_get_transport(rdpContext* context); + + /** + * @brief Free a transport layer instance + * @param layer A pointer to the layer to free or \b NULL + * @since version 3.9.0 + */ + FREERDP_API void transport_layer_free(rdpTransportLayer* layer); + + /** + * @brief Create new transport layer instance + * @param transport A pointer to the transport instance to use + * @param contextSize The size of the context to use + * @return A new transport layer instance or \b NULL in case of failure + * @since version 3.9.0 + */ + WINPR_ATTR_MALLOC(transport_layer_free, 1) + FREERDP_API rdpTransportLayer* transport_layer_new(rdpTransport* transport, size_t contextSize); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_TRANSPORT_IO_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/types.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/types.h new file mode 100644 index 0000000000000000000000000000000000000000..044ee5fe7dc34c40ef2d107610338942f5e2bec7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/types.h @@ -0,0 +1,141 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Type Definitions + * + * Copyright 2009-2011 Jay Sorg + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_TYPES_H +#define FREERDP_TYPES_H + +#include +#include + +#ifndef MIN +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#endif + +#ifndef MAX +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum + { + CONNECTION_STATE_INITIAL, + CONNECTION_STATE_NEGO, + CONNECTION_STATE_NLA, + CONNECTION_STATE_AAD, + CONNECTION_STATE_MCS_CREATE_REQUEST, + CONNECTION_STATE_MCS_CREATE_RESPONSE, + CONNECTION_STATE_MCS_ERECT_DOMAIN, + CONNECTION_STATE_MCS_ATTACH_USER, + CONNECTION_STATE_MCS_ATTACH_USER_CONFIRM, + CONNECTION_STATE_MCS_CHANNEL_JOIN_REQUEST, + CONNECTION_STATE_MCS_CHANNEL_JOIN_RESPONSE, + CONNECTION_STATE_RDP_SECURITY_COMMENCEMENT, + CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE, + CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_REQUEST, + CONNECTION_STATE_CONNECT_TIME_AUTO_DETECT_RESPONSE, + CONNECTION_STATE_LICENSING, + CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_REQUEST, + CONNECTION_STATE_MULTITRANSPORT_BOOTSTRAPPING_RESPONSE, + CONNECTION_STATE_CAPABILITIES_EXCHANGE_DEMAND_ACTIVE, + CONNECTION_STATE_CAPABILITIES_EXCHANGE_MONITOR_LAYOUT, + CONNECTION_STATE_CAPABILITIES_EXCHANGE_CONFIRM_ACTIVE, + CONNECTION_STATE_FINALIZATION_SYNC, + CONNECTION_STATE_FINALIZATION_COOPERATE, + CONNECTION_STATE_FINALIZATION_REQUEST_CONTROL, + CONNECTION_STATE_FINALIZATION_PERSISTENT_KEY_LIST, + CONNECTION_STATE_FINALIZATION_FONT_LIST, + CONNECTION_STATE_FINALIZATION_CLIENT_SYNC, + CONNECTION_STATE_FINALIZATION_CLIENT_COOPERATE, + CONNECTION_STATE_FINALIZATION_CLIENT_GRANTED_CONTROL, + CONNECTION_STATE_FINALIZATION_CLIENT_FONT_MAP, + CONNECTION_STATE_ACTIVE + } CONNECTION_STATE; + + typedef struct rdp_channels rdpChannels; + typedef struct rdp_freerdp freerdp; + typedef struct rdp_context rdpContext; + typedef struct rdp_freerdp_peer freerdp_peer; + typedef struct rdp_transport rdpTransport; /* Opaque */ + + typedef struct + { + BYTE red; + BYTE green; + BYTE blue; + } PALETTE_ENTRY; + + typedef struct + { + UINT32 count; + PALETTE_ENTRY entries[256]; + } rdpPalette; + + typedef struct + { + DWORD size; + void* data[4]; + } RDP_PLUGIN_DATA; + + typedef struct + { + INT16 x; + INT16 y; + INT16 width; + INT16 height; + } RDP_RECT; + + typedef struct + { + UINT16 left; + UINT16 top; + UINT16 right; + UINT16 bottom; + } RECTANGLE_16; + + typedef struct + { + UINT32 left; + UINT32 top; + UINT32 width; + UINT32 height; + } RECTANGLE_32; + + /** @brief type of RDP transport */ + typedef enum + { + RDP_TRANSPORT_TCP = 0, + RDP_TRANSPORT_UDP_R, + RDP_TRANSPORT_UDP_L + } RDP_TRANSPORT_TYPE; + +#ifdef __cplusplus +} +#endif + +/* Plugin events */ + +#include +#include + +#endif /* __RDP_TYPES_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/update.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/update.h new file mode 100644 index 0000000000000000000000000000000000000000..abfe640185e985ca81ea4b910847042f551078ed --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/update.h @@ -0,0 +1,250 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Update Interface API + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UPDATE_H +#define FREERDP_UPDATE_H + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* Bitmap Updates */ +#define EX_COMPRESSED_BITMAP_HEADER_PRESENT 0x01 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct rdp_update rdpUpdate; + + typedef struct + { + UINT32 destLeft; + UINT32 destTop; + UINT32 destRight; + UINT32 destBottom; + UINT32 width; + UINT32 height; + UINT32 bitsPerPixel; + UINT32 flags; + UINT32 bitmapLength; + UINT32 cbCompFirstRowSize; + UINT32 cbCompMainBodySize; + UINT32 cbScanWidth; + UINT32 cbUncompressedSize; + BYTE* bitmapDataStream; + BOOL compressed; + } BITMAP_DATA; + + typedef struct + { + UINT32 number; + BITMAP_DATA* rectangles; + BOOL skipCompression; + } BITMAP_UPDATE; + + /* Palette Updates */ + + typedef struct + { + UINT32 number; + PALETTE_ENTRY entries[256]; + } PALETTE_UPDATE; + + /* Play Sound (System Beep) Updates */ + + typedef struct + { + UINT32 duration; + UINT32 frequency; + } PLAY_SOUND_UPDATE; + + /* Surface Command Updates */ + typedef struct + { + UINT32 highUniqueId; + UINT32 lowUniqueId; + UINT64 tmMilliseconds; + UINT64 tmSeconds; + } TS_COMPRESSED_BITMAP_HEADER_EX; + + typedef struct + { + BYTE bpp; + BYTE flags; + UINT16 codecID; + UINT16 width; + UINT16 height; + UINT32 bitmapDataLength; + TS_COMPRESSED_BITMAP_HEADER_EX exBitmapDataHeader; + BYTE* bitmapData; + } TS_BITMAP_DATA_EX; + + enum SURFCMD_CMDTYPE + { + CMDTYPE_SET_SURFACE_BITS = 0x0001, + CMDTYPE_FRAME_MARKER = 0x0004, + CMDTYPE_STREAM_SURFACE_BITS = 0x0006 + }; + + typedef struct + { + UINT32 cmdType; + UINT32 destLeft; + UINT32 destTop; + UINT32 destRight; + UINT32 destBottom; + TS_BITMAP_DATA_EX bmp; + BOOL skipCompression; + } SURFACE_BITS_COMMAND; + + typedef struct + { + UINT32 frameAction; + UINT32 frameId; + } SURFACE_FRAME_MARKER; + + enum SURFCMD_FRAMEACTION + { + SURFACECMD_FRAMEACTION_BEGIN = 0x0000, + SURFACECMD_FRAMEACTION_END = 0x0001 + }; + + /** @brief status code as in 2.2.5.2 Server Status Info PDU */ + enum + { + TS_STATUS_FINDING_DESTINATION = 0x00000401, + TS_STATUS_LOADING_DESTINATION = 0x00000402, + TS_STATUS_BRINGING_SESSION_ONLINE = 0x00000403, + TS_STATUS_REDIRECTING_TO_DESTINATION = 0x00000404, + TS_STATUS_VM_LOADING = 0x00000501, + TS_STATUS_VM_WAKING = 0x00000502, + TS_STATUS_VM_STARTING = 0x00000503, + TS_STATUS_VM_STARTING_MONITORING = 0x00000504, + TS_STATUS_VM_RETRYING_MONITORING = 0x00000505 + }; + + typedef struct + { + UINT32 frameId; + UINT32 commandCount; + SURFACE_BITS_COMMAND* commands; + } SURFACE_FRAME; + + /* defined inside libfreerdp-core */ + typedef struct rdp_update_proxy rdpUpdateProxy; + + /* Update Interface */ + + typedef BOOL (*pBeginPaint)(rdpContext* context); + typedef BOOL (*pEndPaint)(rdpContext* context); + typedef BOOL (*pSetBounds)(rdpContext* context, const rdpBounds* bounds); + + typedef BOOL (*pSynchronize)(rdpContext* context); + typedef BOOL (*pDesktopResize)(rdpContext* context); + typedef BOOL (*pBitmapUpdate)(rdpContext* context, const BITMAP_UPDATE* bitmap); + typedef BOOL (*pPalette)(rdpContext* context, const PALETTE_UPDATE* palette); + typedef BOOL (*pPlaySound)(rdpContext* context, const PLAY_SOUND_UPDATE* play_sound); + typedef BOOL (*pSetKeyboardIndicators)(rdpContext* context, UINT16 led_flags); + + typedef BOOL (*pRefreshRect)(rdpContext* context, BYTE count, const RECTANGLE_16* areas); + typedef BOOL (*pSuppressOutput)(rdpContext* context, BYTE allow, const RECTANGLE_16* area); + typedef BOOL (*pRemoteMonitors)(rdpContext* context, UINT32 count, const MONITOR_DEF* monitors); + + typedef BOOL (*pSurfaceCommand)(rdpContext* context, wStream* s); + typedef BOOL (*pSurfaceBits)(rdpContext* context, + const SURFACE_BITS_COMMAND* surfaceBitsCommand); + typedef BOOL (*pSurfaceFrameMarker)(rdpContext* context, + const SURFACE_FRAME_MARKER* surfaceFrameMarker); + typedef BOOL (*pSurfaceFrameBits)(rdpContext* context, const SURFACE_BITS_COMMAND* cmd, + BOOL first, BOOL last, UINT32 frameId); + typedef BOOL (*pSurfaceFrameAcknowledge)(rdpContext* context, UINT32 frameId); + + typedef BOOL (*pSaveSessionInfo)(rdpContext* context, UINT32 type, void* data); + typedef BOOL (*pSetKeyboardImeStatus)(rdpContext* context, UINT16 imeId, UINT32 imeState, + UINT32 imeConvMode); + typedef BOOL (*pServerStatusInfo)(rdpContext* context, UINT32 status); + + struct rdp_update + { + rdpContext* context; /* 0 */ + UINT32 paddingA[16 - 1]; /* 1 */ + + pBeginPaint BeginPaint; /* 16 */ + pEndPaint EndPaint; /* 17 */ + pSetBounds SetBounds; /* 18 */ + pSynchronize Synchronize; /* 19 */ + pDesktopResize DesktopResize; /* 20 */ + pBitmapUpdate BitmapUpdate; /* 21 */ + pPalette Palette; /* 22 */ + pPlaySound PlaySound; /* 23 */ + pSetKeyboardIndicators SetKeyboardIndicators; /* 24 */ + pSetKeyboardImeStatus SetKeyboardImeStatus; /* 25 */ + UINT32 paddingB[32 - 26]; /* 26 */ + + rdpPointerUpdate* pointer; /* 32 */ + rdpPrimaryUpdate* primary; /* 33 */ + rdpSecondaryUpdate* secondary; /* 34 */ + rdpAltSecUpdate* altsec; /* 35 */ + rdpWindowUpdate* window; /* 36 */ + UINT32 paddingC[48 - 37]; /* 37 */ + + pRefreshRect RefreshRect; /* 48 */ + pSuppressOutput SuppressOutput; /* 49 */ + pRemoteMonitors RemoteMonitors; /* 50 */ + UINT32 paddingD[64 - 51]; /* 51 */ + + pSurfaceCommand SurfaceCommand; /* 64 */ + pSurfaceBits SurfaceBits; /* 65 */ + pSurfaceFrameMarker SurfaceFrameMarker; /* 66 */ + pSurfaceFrameBits SurfaceFrameBits; /* 67 */ + pSurfaceFrameAcknowledge SurfaceFrameAcknowledge; /* 68 */ + pSaveSessionInfo SaveSessionInfo; /* 69 */ + pServerStatusInfo ServerStatusInfo; /* 70 */ + /* if autoCalculateBitmapData is set to TRUE, the server automatically + * fills BITMAP_DATA struct members: flags, cbCompMainBodySize and cbCompFirstRowSize. + */ + BOOL autoCalculateBitmapData; /* 71 */ + UINT32 paddingE[80 - 72]; /* 72 */ + }; + + FREERDP_API void rdp_update_lock(rdpUpdate* update); + FREERDP_API void rdp_update_unlock(rdpUpdate* update); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UPDATE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/aad.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/aad.h new file mode 100644 index 0000000000000000000000000000000000000000..290393c65d893c4cf4282fdb688db06eb0595f65 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/aad.h @@ -0,0 +1,151 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Network Level Authentication (NLA) + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_AAD_H +#define FREERDP_UTILS_AAD_H + +/** \defgroup AAD AAD related helper utilities + * \since version 3.0.0 + */ +#include +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @enum Expected wellknown fields to be supported + * @since version 3.10.0 + */ + typedef enum + { + AAD_WELLKNOWN_token_endpoint = 0, + AAD_WELLKNOWN_token_endpoint_auth_methods_supported, + AAD_WELLKNOWN_jwks_uri, + AAD_WELLKNOWN_response_modes_supported, + AAD_WELLKNOWN_subject_types_supported, + AAD_WELLKNOWN_id_token_signing_alg_values_supported, + AAD_WELLKNOWN_response_types_supported, + AAD_WELLKNOWN_scopes_supported, + AAD_WELLKNOWN_issuer, + AAD_WELLKNOWN_request_uri_parameter_supported, + AAD_WELLKNOWN_userinfo_endpoint, + AAD_WELLKNOWN_authorization_endpoint, + AAD_WELLKNOWN_device_authorization_endpoint, + AAD_WELLKNOWN_http_logout_supported, + AAD_WELLKNOWN_frontchannel_logout_supported, + AAD_WELLKNOWN_end_session_endpoint, + AAD_WELLKNOWN_claims_supported, + AAD_WELLKNOWN_kerberos_endpoint, + AAD_WELLKNOWN_tenant_region_scope, + AAD_WELLKNOWN_cloud_instance_name, + AAD_WELLKNOWN_cloud_graph_host_name, + AAD_WELLKNOWN_msgraph_host, + AAD_WELLKNOWN_rbac_url + } AAD_WELLKNOWN_VALUES; + + /** Helper to retrieve the AAD access token from JSON input + * + * @param data The JSON to parse + * @param length The number of bytes of the JSON data + * + * @since version 3.0.0 + * + * @return The token string or \b NULL + */ + WINPR_ATTR_MALLOC(free, 1) + FREERDP_API char* freerdp_utils_aad_get_access_token(wLog* log, const char* data, + size_t length); + + /** Helper to stringify \ref AAD_WELLKNOWN_VALUES enum + * + * @param which The enum value to stringify + * + * @return The string representation of the enum value + * @since version 3.10.0 + */ + FREERDP_API const char* freerdp_utils_aad_wellknwon_value_name(AAD_WELLKNOWN_VALUES which); + + /** Helper to extract a string from AAD::wellknown JSON + * + * @param context The rdpContext to query for + * @param which The enum value of the field to query + * @return A constant string to be used for queries or \b NULL in case it does not exist. + * + * @since version 3.10.0 + */ + FREERDP_API const char* freerdp_utils_aad_get_wellknown_string(rdpContext* context, + AAD_WELLKNOWN_VALUES which); + + /** Helper to extract a string from AAD::wellknown JSON + * + * @param context The rdpContext to query for + * @param which The raw string name of the field to query + * @return A constant string to be used for queries or \b NULL in case it does not exist. + * + * @since version 3.10.0 + */ + FREERDP_API const char* freerdp_utils_aad_get_wellknown_custom_string(rdpContext* context, + const char* which); + + /** Helper to extract a \b WINPR_JSON object from AAD::wellknown JSON + * + * @param context The rdpContext to query for + * @param which The enum value of the field to query + * @return A \b WINPR_JSON object to be used for queries or \b NULL in case it does not exist. + * + * @since version 3.10.0 + */ + FREERDP_API WINPR_JSON* freerdp_utils_aad_get_wellknown_object(rdpContext* context, + AAD_WELLKNOWN_VALUES which); + + /** Helper to extract a \b WINPR_JSON object from AAD::wellknown JSON + * + * @param context The rdpContext to query for + * @param which The raw string name of the field to query + * @return A \b WINPR_JSON object to be used for queries or \b NULL in case it does not exist. + * + * @since version 3.10.0 + */ + FREERDP_API WINPR_JSON* freerdp_utils_aad_get_wellknown_custom_object(rdpContext* context, + const char* which); + + /** Helper to fetch a \b WINPR_JSON object from AAD/ARM::wellknown JSON + * + * @param log A logger instance to use + * @param base the base URL to connect to + * @param tenantid the tenant to use for the connection, use \b common for default + * @return A \b WINPR_JSON object to be used for queries or \b NULL in case it does not exist. + * + * @since version 3.10.0 + */ + WINPR_ATTR_MALLOC(WINPR_JSON_Delete, 1) + WINPR_JSON* freerdp_utils_aad_get_wellknown(wLog* log, const char* base, const char* tenantid); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_AAD_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/cliprdr_utils.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/cliprdr_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..0b3295bd2dbbdc66a26806ae80816d5eb6a46eee --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/cliprdr_utils.h @@ -0,0 +1,51 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPDR utility functions + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_CLIPRDR_H +#define FREERDP_UTILS_CLIPRDR_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API BOOL cliprdr_read_filedescriptor(wStream* s, FILEDESCRIPTORW* descriptor); + FREERDP_API BOOL cliprdr_write_filedescriptor(wStream* s, const FILEDESCRIPTORW* descriptor); + + FREERDP_API UINT cliprdr_parse_file_list(const BYTE* format_data, UINT32 format_data_length, + FILEDESCRIPTORW** file_descriptor_array, + UINT32* file_descriptor_count); + FREERDP_API UINT cliprdr_serialize_file_list(const FILEDESCRIPTORW* file_descriptor_array, + UINT32 file_descriptor_count, BYTE** format_data, + UINT32* format_data_length); + FREERDP_API UINT cliprdr_serialize_file_list_ex(UINT32 flags, + const FILEDESCRIPTORW* file_descriptor_array, + UINT32 file_descriptor_count, + BYTE** format_data, UINT32* format_data_length); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/drdynvc.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/drdynvc.h new file mode 100644 index 0000000000000000000000000000000000000000..cc96d95ab74cf744a193a7965f6787a69b102d97 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/drdynvc.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * GFX Utils - Helper functions converting something to string + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_DRDYNVC_H +#define FREERDP_UTILS_DRDYNVC_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API const char* drdynvc_get_packet_type(BYTE cmd); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/encoded_types.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/encoded_types.h new file mode 100644 index 0000000000000000000000000000000000000000..d2b35de6cfa939a9817ba26bb5dcb73f434a8980 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/encoded_types.h @@ -0,0 +1,116 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Helper functions to parse encoded types into regular ones + * + * Copyright 2023 Pascal Nowack + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_ENCODED_TYPES_H +#define FREERDP_UTILS_ENCODED_TYPES_H + +/** \file Encoded Types helpers + * \since version 3.0.0 + */ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** Maximum value of a 4 byte signed integer + * \since version 3.5.0 + */ +#define FREERDP_FOUR_BYTE_SIGNED_INT_MAX 0x1FFFFFFFl + +/** Minimum value of a 4 byte signed integer + * \since version 3.5.0 + */ +#define FREERDP_FOUR_BYTE_SIGNED_INT_MIN -0x1FFFFFFFl + +/** Maximum value of a 4 byte float + * \since version 3.5.0 + */ +#define FREERDP_FOUR_BYTE_FLOAT_MAX 0x3FFFFFF + +/** Minimum value of a 4 byte float + * \since version 3.5.0 + */ +#define FREERDP_FOUR_BYTE_FLOAT_MIN -0x3FFFFFF + + /** Read a 4 byte signed integer from a stream and store the decoded value + * + * @param s The steam to read from + * @param value A pointer to an INT32 to hold the result + * + * @since version 3.0.0 + * + * @return \b TRUE for successful reading, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_read_four_byte_signed_integer(wStream* s, INT32* value); + + /** Write a 4 byte signed integer to a stream + * + * @param s The steam to read from + * @param value The INT32 value to encode and write + * + * @since version 3.4.0 + * + * @return \b TRUE for successful writing, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_write_four_byte_signed_integer(wStream* s, INT32 value); + + /** Read a 4 byte float from a stream and store the decoded value + * + * @param s The steam to read from + * @param value A pointer to a double to hold the result + * + * @since version 3.0.0 + * + * @return \b TRUE for successful reading, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_read_four_byte_float(wStream* s, double* value); + + /** Read a 4 byte float from a stream and store the decoded value and exponent + * + * @param s The steam to read from + * @param value A pointer to a double to hold the result + * @param exp A pointer to a BYTE to hold the exponent result + * + * @since version 3.5.0 + * + * @return \b TRUE for successful reading, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_read_four_byte_float_exp(wStream* s, double* value, BYTE* exp); + + /** Write a 4 byte float to a stream + * + * @param s The steam to read from + * @param value The float value to encode and write + * + * @since version 3.4.0 + * + * @return \b TRUE for successful writing, \b FALSE otherwise + */ + FREERDP_API BOOL freerdp_write_four_byte_float(wStream* s, double value); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_ENCODED_TYPES_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/gfx.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/gfx.h new file mode 100644 index 0000000000000000000000000000000000000000..9f25242fd06daad995525693e92063124a6ada4b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/gfx.h @@ -0,0 +1,49 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * GFX Utils - Helper functions converting something to string + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_GFX_H +#define FREERDP_UTILS_GFX_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * @brief Stringification utility for rdpgfx capability versions + * @param capsVersion A capability version integer + * @return The string representation of the capabilities + * @since version 3.9.0 + */ + FREERDP_API const char* rdpgfx_caps_version_str(UINT32 capsVersion); + + FREERDP_API const char* rdpgfx_get_cmd_id_string(UINT16 cmdId); + + FREERDP_API const char* rdpgfx_get_codec_id_string(UINT16 codecId); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/helpers.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/helpers.h new file mode 100644 index 0000000000000000000000000000000000000000..c0c3d18981d9b86fb37365bcc95af6d2ec6a6ea3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/helpers.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * common helper utilities + * + * Copyright 2024 Armin Novak + * Copyright 2024 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +/** @brief Return the absolute path of a configuration file (the path of the configuration + * directory if \b filename is \b NULL) + * + * @param system a boolean indicating the configuration base, \b TRUE for system configuration, + * \b FALSE for user configuration + * @param filename an optional configuration file name to append. + * + * @return The absolute path of the desired configuration or \b NULL in case of failure. Use \b + * free to clean up the allocated string. + * + * + * @since version 3.9.0 + */ +FREERDP_API char* freerdp_GetConfigFilePath(BOOL system, const char* filename); diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/http.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/http.h new file mode 100644 index 0000000000000000000000000000000000000000..b2e643ebff7fb60d38437dd73c82f9f3f618fe41 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/http.h @@ -0,0 +1,75 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Smartcard Device Service Virtual Channel + * + * Copyright 2023 Isaac Klein + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_HTTP_H +#define FREERDP_UTILS_HTTP_H + +#include + +typedef enum +{ + HTTP_STATUS_CONTINUE = 100, + HTTP_STATUS_SWITCH_PROTOCOLS = 101, + HTTP_STATUS_OK = 200, + HTTP_STATUS_CREATED = 201, + HTTP_STATUS_ACCEPTED = 202, + HTTP_STATUS_PARTIAL = 203, + HTTP_STATUS_NO_CONTENT = 204, + HTTP_STATUS_RESET_CONTENT = 205, + HTTP_STATUS_PARTIAL_CONTENT = 206, + HTTP_STATUS_WEBDAV_MULTI_STATUS = 207, + HTTP_STATUS_AMBIGUOUS = 300, + HTTP_STATUS_MOVED = 301, + HTTP_STATUS_REDIRECT = 302, + HTTP_STATUS_REDIRECT_METHOD = 303, + HTTP_STATUS_NOT_MODIFIED = 304, + HTTP_STATUS_USE_PROXY = 305, + HTTP_STATUS_REDIRECT_KEEP_VERB = 307, + HTTP_STATUS_BAD_REQUEST = 400, + HTTP_STATUS_DENIED = 401, + HTTP_STATUS_PAYMENT_REQ = 402, + HTTP_STATUS_FORBIDDEN = 403, + HTTP_STATUS_NOT_FOUND = 404, + HTTP_STATUS_BAD_METHOD = 405, + HTTP_STATUS_NONE_ACCEPTABLE = 406, + HTTP_STATUS_PROXY_AUTH_REQ = 407, + HTTP_STATUS_REQUEST_TIMEOUT = 408, + HTTP_STATUS_CONFLICT = 409, + HTTP_STATUS_GONE = 410, + HTTP_STATUS_LENGTH_REQUIRED = 411, + HTTP_STATUS_PRECOND_FAILED = 412, + HTTP_STATUS_REQUEST_TOO_LARGE = 413, + HTTP_STATUS_URI_TOO_LONG = 414, + HTTP_STATUS_UNSUPPORTED_MEDIA = 415, + HTTP_STATUS_RETRY_WITH = 449, + HTTP_STATUS_SERVER_ERROR = 500, + HTTP_STATUS_NOT_SUPPORTED = 501, + HTTP_STATUS_BAD_GATEWAY = 502, + HTTP_STATUS_SERVICE_UNAVAIL = 503, + HTTP_STATUS_GATEWAY_TIMEOUT = 504, + HTTP_STATUS_VERSION_NOT_SUP = 505 +} FREERDP_HTTP_STATUS; + +FREERDP_API BOOL freerdp_http_request(const char* url, const char* body, long* status_code, + BYTE** response, size_t* response_length); + +FREERDP_API const char* freerdp_http_status_string(long status); +FREERDP_API const char* freerdp_http_status_string_format(long status, char* buffer, size_t size); + +#endif /* FREERDP_UTILS_HTTP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/passphrase.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/passphrase.h new file mode 100644 index 0000000000000000000000000000000000000000..0bcce1953ff6c3f5e1edc7bd207deebabe7426fd --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/passphrase.h @@ -0,0 +1,44 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Passphrase Handling Utils + * + * Copyright 2011 Shea Levy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_PASSPHRASE_H +#define FREERDP_UTILS_PASSPHRASE_H + +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API int freerdp_interruptible_getc(rdpContext* context, FILE* file); + FREERDP_API SSIZE_T freerdp_interruptible_get_line(rdpContext* context, char** lineptr, + size_t* size, FILE* stream); + FREERDP_API const char* freerdp_passphrase_read(rdpContext* context, const char* prompt, + char* buf, size_t bufsiz, int from_stdin); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_PASSPHRASE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/pcap.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/pcap.h new file mode 100644 index 0000000000000000000000000000000000000000..5178f380204b4f831f0cefd3180ba05138c32366 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/pcap.h @@ -0,0 +1,80 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * pcap File Format Utils + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_PCAP_H +#define FREERDP_UTILS_PCAP_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 magic_number; /* magic number */ + UINT16 version_major; /* major version number */ + UINT16 version_minor; /* minor version number */ + INT32 thiszone; /* GMT to local correction */ + UINT32 sigfigs; /* accuracy of timestamps */ + UINT32 snaplen; /* max length of captured packets, in octets */ + UINT32 network; /* data link type */ + } pcap_header; + + typedef struct + { + UINT32 ts_sec; /* timestamp seconds */ + UINT32 ts_usec; /* timestamp microseconds */ + UINT32 incl_len; /* number of octets of packet saved in file */ + UINT32 orig_len; /* actual length of packet */ + } pcap_record_header; + + typedef struct s_pcap_record pcap_record; + + struct s_pcap_record + { + pcap_record_header header; + union + { + void* data; + const void* cdata; + }; + UINT32 length; + pcap_record* next; + }; + + typedef struct rdp_pcap rdpPcap; + + FREERDP_API rdpPcap* pcap_open(const char* name, BOOL write); + FREERDP_API void pcap_close(rdpPcap* pcap); + + FREERDP_API BOOL pcap_add_record(rdpPcap* pcap, const void* data, size_t length); + FREERDP_API BOOL pcap_has_next_record(const rdpPcap* pcap); + FREERDP_API BOOL pcap_get_next_record(rdpPcap* pcap, pcap_record* record); + FREERDP_API BOOL pcap_get_next_record_header(rdpPcap* pcap, pcap_record* record); + FREERDP_API BOOL pcap_get_next_record_content(rdpPcap* pcap, pcap_record* record); + FREERDP_API void pcap_flush(rdpPcap* pcap); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_PCAP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/pod_arrays.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/pod_arrays.h new file mode 100644 index 0000000000000000000000000000000000000000..ef8667d24b7679f3f8d742c3bcc04f5301c17848 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/pod_arrays.h @@ -0,0 +1,138 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * POD arrays + * + * Copyright 2022 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FREERDP_UTILS_POD_ARRAYS_H_ +#define FREERDP_UTILS_POD_ARRAYS_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define POD_ARRAYS_IMPL(T, TLOWER) \ + typedef struct \ + { \ + T* values; \ + size_t nvalues; \ + } Array##T; \ + typedef BOOL Array##T##Cb(T* v, void* data); \ + \ + static INLINE void array_##TLOWER##_init(Array##T* a) \ + { \ + WINPR_ASSERT(a); \ + a->values = NULL; \ + a->nvalues = 0; \ + } \ + \ + static INLINE size_t array_##TLOWER##_size(const Array##T* a) \ + { \ + WINPR_ASSERT(a); \ + return a->nvalues; \ + } \ + \ + static INLINE T* array_##TLOWER##_data(const Array##T* a) \ + { \ + WINPR_ASSERT(a); \ + return a->values; \ + } \ + \ + static INLINE const T* array_##TLOWER##_cdata(const Array##T* a) \ + { \ + WINPR_ASSERT(a); \ + return (const T*)a->values; \ + } \ + \ + static INLINE T array_##TLOWER##_get(const Array##T* a, size_t idx) \ + { \ + WINPR_ASSERT(a); \ + WINPR_ASSERT(a->nvalues > idx); \ + return a->values[idx]; \ + } \ + \ + static INLINE void array_##TLOWER##_set(Array##T* a, size_t idx, T v) \ + { \ + WINPR_ASSERT(a); \ + WINPR_ASSERT(a->nvalues > idx); \ + a->values[idx] = v; \ + } \ + \ + static INLINE BOOL array_##TLOWER##_append(Array##T* a, T v) \ + { \ + WINPR_ASSERT(a); \ + T* tmp = realloc(a->values, sizeof(T) * (a->nvalues + 1)); \ + if (!tmp) \ + return FALSE; \ + \ + tmp[a->nvalues] = v; \ + a->values = tmp; \ + a->nvalues++; \ + return TRUE; \ + } \ + \ + static INLINE BOOL array_##TLOWER##_contains(const Array##T* a, T v) \ + { \ + WINPR_ASSERT(a); \ + \ + for (UINT32 i = 0; i < a->nvalues; i++) \ + { \ + if (memcmp(&a->values[i], &v, sizeof(T)) == 0) \ + return TRUE; \ + } \ + \ + return FALSE; \ + } \ + \ + static INLINE BOOL array_##TLOWER##_foreach(Array##T* a, Array##T##Cb cb, void* data) \ + { \ + WINPR_ASSERT(a); \ + for (size_t i = 0; i < a->nvalues; i++) \ + { \ + if (!cb(&a->values[i], data)) \ + return FALSE; \ + } \ + \ + return TRUE; \ + } \ + \ + static INLINE void array_##TLOWER##_reset(Array##T* a) \ + { \ + WINPR_ASSERT(a); \ + a->nvalues = 0; \ + } \ + \ + static INLINE void array_##TLOWER##_uninit(Array##T* a) \ + { \ + WINPR_ASSERT(a); \ + free(a->values); \ + \ + a->values = NULL; \ + a->nvalues = 0; \ + } + + POD_ARRAYS_IMPL(UINT16, uint16) + POD_ARRAYS_IMPL(UINT32, uint32) + POD_ARRAYS_IMPL(UINT64, uint64) + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_POD_ARRAYS_H_ */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/profiler.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/profiler.h new file mode 100644 index 0000000000000000000000000000000000000000..29b9e32f04df839233640bc3b4845d3724a8c1a2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/profiler.h @@ -0,0 +1,99 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Profiler Utils + * + * Copyright 2011 Stephen Erisman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_PROFILER_H +#define FREERDP_UTILS_PROFILER_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct S_PROFILER PROFILER; + + FREERDP_API PROFILER* profiler_create(const char* name); + FREERDP_API void profiler_free(PROFILER* profiler); + + FREERDP_API void profiler_enter(PROFILER* profiler); + FREERDP_API void profiler_exit(PROFILER* profiler); + + FREERDP_API void profiler_print_header(void); + FREERDP_API void profiler_print(PROFILER* profiler); + FREERDP_API void profiler_print_footer(void); + +#ifdef WITH_PROFILER +#define PROFILER_RENAME(prof, name) \ + do \ + { \ + profiler_free(prof); \ + prof = profiler_create(name); \ + } while (0); +#define PROFILER_DEFINE(prof) PROFILER* prof; +#define PROFILER_CREATE(prof, name) prof = profiler_create(name); +#define PROFILER_FREE(prof) profiler_free(prof); +#define PROFILER_ENTER(prof) profiler_enter(prof); +#define PROFILER_EXIT(prof) profiler_exit(prof); +#define PROFILER_PRINT_HEADER profiler_print_header(); +#define PROFILER_PRINT(prof) profiler_print(prof); +#define PROFILER_PRINT_FOOTER profiler_print_footer(); +#else +#define PROFILER_RENAME(prof, name) \ + do \ + { \ + } while (0); + +#define PROFILER_DEFINE(prof) +#define PROFILER_CREATE(prof, name) \ + do \ + { \ + } while (0); +#define PROFILER_FREE(prof) \ + do \ + { \ + } while (0); +#define PROFILER_ENTER(prof) \ + do \ + { \ + } while (0); +#define PROFILER_EXIT(prof) \ + do \ + { \ + } while (0); +#define PROFILER_PRINT_HEADER \ + do \ + { \ + } while (0); +#define PROFILER_PRINT(prof) \ + do \ + { \ + } while (0); +#define PROFILER_PRINT_FOOTER \ + do \ + { \ + } while (0); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_PROFILER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/proxy_utils.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/proxy_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..57b0ba54038837d0f07ef0b1eb1d0f2641cc2110 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/proxy_utils.h @@ -0,0 +1,45 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDP Proxy Utils + * + * Copyright 2016 Armin Novak + * Copyright 2022 Adrian Vollmer + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_PROXY_UTILS_H +#define FREERDP_PROXY_UTILS_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @brief parse a proxy environment variable string and populate settings from it + * + * @param settings the settings to populate, must not be \b NULL + * @param uri_in the proxy string to parse, must not be \b NULL + * + * @return \b TRUE if parsed successfully + */ + FREERDP_API BOOL proxy_parse_uri(rdpSettings* settings, const char* uri_in); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_PROXY_UTILS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/rdpdr_utils.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/rdpdr_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..1ef53fe024e5cb791ee917eaab4e14e2d69eda92 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/rdpdr_utils.h @@ -0,0 +1,72 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RDPDR utility functions + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_RDPDR_H +#define FREERDP_UTILS_RDPDR_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 DeviceType; + UINT32 DeviceId; + char PreferredDosName[8]; + UINT32 DeviceDataLength; + BYTE* DeviceData; + } RdpdrDevice; + + typedef struct + { + UINT16 CapabilityType; + UINT16 CapabilityLength; + UINT32 Version; + } RDPDR_CAPABILITY_HEADER; + + FREERDP_API const char* rdpdr_component_string(UINT16 component); + FREERDP_API const char* rdpdr_packetid_string(UINT16 packetid); + FREERDP_API const char* rdpdr_irp_string(UINT32 major); + FREERDP_API const char* rdpdr_cap_type_string(UINT16 capability); + + FREERDP_API LONG scard_log_status_error(const char* tag, const char* what, LONG status); + FREERDP_API const char* scard_get_ioctl_string(UINT32 ioControlCode, BOOL funcName); + + FREERDP_API BOOL rdpdr_write_iocompletion_header(wStream* out, UINT32 DeviceId, + UINT32 CompletionId, NTSTATUS ioStatus); + + FREERDP_API void rdpdr_dump_received_packet(wLog* log, DWORD lvl, wStream* out, + const char* custom); + FREERDP_API void rdpdr_dump_send_packet(wLog* log, DWORD lvl, wStream* out, const char* custom); + + FREERDP_API UINT rdpdr_read_capset_header(wLog* log, wStream* s, + RDPDR_CAPABILITY_HEADER* header); + FREERDP_API UINT rdpdr_write_capset_header(wLog* log, wStream* s, + const RDPDR_CAPABILITY_HEADER* header); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/ringbuffer.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/ringbuffer.h new file mode 100644 index 0000000000000000000000000000000000000000..3de191c81bb479ed612e6b57ceee0736d22b578e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/ringbuffer.h @@ -0,0 +1,131 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2014 Thincast Technologies GmbH + * Copyright 2014 Hardening + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_RINGBUFFER_H +#define FREERDP_UTILS_RINGBUFFER_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** @brief ring buffer meta data */ + typedef struct + { + size_t initialSize; + size_t freeSize; + size_t size; + size_t readPtr; + size_t writePtr; + BYTE* buffer; + } RingBuffer; + + /** @brief a piece of data in the ring buffer, exactly like a glibc iovec */ + typedef struct + { + size_t size; + const BYTE* data; + } DataChunk; + + /** + * initialise a ringbuffer + * + * @param initialSize the initial capacity of the ringBuffer + * @return if the initialisation was successful + */ + FREERDP_API BOOL ringbuffer_init(RingBuffer* rb, size_t initialSize); + + /** + * destroys internal data used by this ringbuffer + * + * @param ringbuffer A pointer to the ringbuffer + */ + FREERDP_API void ringbuffer_destroy(RingBuffer* ringbuffer); + + /** + * computes the space used in this ringbuffer + * + * @param ringbuffer A pointer to the ringbuffer + * @return the number of bytes stored in that ringbuffer + */ + FREERDP_API size_t ringbuffer_used(const RingBuffer* ringbuffer); + + /** returns the capacity of the ring buffer + * + * @param ringbuffer A pointer to the ringbuffer + * @return the capacity of this ring buffer + */ + FREERDP_API size_t ringbuffer_capacity(const RingBuffer* ringbuffer); + + /** writes some bytes in the ringbuffer, if the data doesn't fit, the ringbuffer + * is resized automatically + * + * @param rb the ringbuffer + * @param ptr a pointer on the data to add + * @param sz the size of the data to add + * @return if the operation was successful, it could fail in case of OOM during realloc() + */ + FREERDP_API BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz); + + /** ensures that we have sz bytes available at the write head, and return a pointer + * on the write head + * + * @param rb the ring buffer + * @param sz the size to ensure + * @return a pointer on the write head, or NULL in case of OOM + */ + FREERDP_API BYTE* ringbuffer_ensure_linear_write(RingBuffer* rb, size_t sz); + + /** move ahead the write head in case some byte were written directly by using + * a pointer retrieved via ringbuffer_ensure_linear_write(). This function is + * used to commit the written bytes. The provided size should not exceed the + * size ensured by ringbuffer_ensure_linear_write() + * + * @param rb the ring buffer + * @param sz the number of bytes that have been written + * @return if the operation was successful, FALSE is sz is too big + */ + FREERDP_API BOOL ringbuffer_commit_written_bytes(RingBuffer* rb, size_t sz); + + /** peeks the buffer chunks for sz bytes and returns how many chunks are filled. + * Note that the sum of the resulting chunks may be smaller than sz. + * + * @param rb the ringbuffer + * @param chunks an array of data chunks that will contain data / size of chunks + * @param sz the requested size + * @return the number of chunks used for reading sz bytes + */ + FREERDP_API int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz); + + /** move ahead the read head in case some byte were read using ringbuffer_peek() + * This function is used to commit the bytes that were effectively consumed. + * + * @param rb the ring buffer + * @param sz the number of bytes to read + */ + FREERDP_API void ringbuffer_commit_read_bytes(RingBuffer* rb, size_t sz); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_RINGBUFFER_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/signal.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/signal.h new file mode 100644 index 0000000000000000000000000000000000000000..8a74b81f58ee904f5aa0b255b4989c71ff23e0ea --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/signal.h @@ -0,0 +1,63 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Signal handling + * + * Copyright 2011 Shea Levy + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_SIGNAL_H +#define FREERDP_UTILS_SIGNAL_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef void (*freerdp_signal_handler_t)(int signum, const char* signame, void* context); + + FREERDP_API int freerdp_handle_signals(void); + + /** \brief registers a cleanup handler for non fatal signals. + * + * This allows cleaning up resources like with \b atexit but for signals. + * + * \param context a context for the clenaup handler. + * \param handler the function to call on cleanup. Must not be \b NULL + * + * \return \b TRUE if registered successfully, \b FALSE otherwise. + */ + FREERDP_API BOOL freerdp_add_signal_cleanup_handler(void* context, + freerdp_signal_handler_t handler); + + /** \brief unregisters a cleanup handler for non fatal signals. + * + * This allows removal of a cleanup handler for signals. + * + * \param context a context for the clenaup handler. + * \param handler the function to call on cleanup. Must not be \b NULL + * + * \return \b TRUE if unregistered successfully, \b FALSE otherwise. + */ + FREERDP_API BOOL freerdp_del_signal_cleanup_handler(void* context, + freerdp_signal_handler_t handler); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_SIGNAL_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_call.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_call.h new file mode 100644 index 0000000000000000000000000000000000000000..61b41d45ae77e59a680a0a7d63a74f48c86ed10c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_call.h @@ -0,0 +1,65 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Smartcard Device Service Virtual Channel + * + * Copyright 2011 O.S. Systems Software Ltda. + * Copyright 2011 Eduardo Fiss Beloni + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_SMARTCARD_CALL_H +#define FREERDP_CHANNEL_SMARTCARD_CALL_H + +#include +#include + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct s_scard_call_context scard_call_context; + + FREERDP_API void smartcard_call_context_free(scard_call_context* ctx); + + WINPR_ATTR_MALLOC(smartcard_call_context_free, 1) + FREERDP_API scard_call_context* smartcard_call_context_new(const rdpSettings* settings); + + FREERDP_API BOOL smartcard_call_context_signal_stop(scard_call_context* ctx, BOOL reset); + FREERDP_API BOOL smartcard_call_context_add(scard_call_context* ctx, const char* name); + FREERDP_API BOOL smartcard_call_cancel_context(scard_call_context* ctx, SCARDCONTEXT context); + FREERDP_API BOOL smartcard_call_cancel_all_context(scard_call_context* ctx); + FREERDP_API BOOL smartcard_call_release_context(scard_call_context* ctx, SCARDCONTEXT context); + FREERDP_API BOOL smartcard_call_is_configured(scard_call_context* ctx); + + FREERDP_API BOOL smarcard_call_set_callbacks(scard_call_context* ctx, void* userdata, + void* (*fn_new)(void*, SCARDCONTEXT), + void (*fn_free)(void*)); + FREERDP_API void* smartcard_call_get_context(scard_call_context* ctx, SCARDCONTEXT hContext); + + FREERDP_API LONG smartcard_irp_device_control_call(scard_call_context* context, wStream* out, + NTSTATUS* pIoStatus, + SMARTCARD_OPERATION* operation); + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_SMARTCARD_CALL_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_operations.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_operations.h new file mode 100644 index 0000000000000000000000000000000000000000..cab7facfa62b27b9b44d3e7006155220daf039f4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_operations.h @@ -0,0 +1,96 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Smartcard Device Service Virtual Channel + * + * Copyright 2011 O.S. Systems Software Ltda. + * Copyright 2011 Eduardo Fiss Beloni + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_SMARTCARD_OPERATIONS_MAIN_H +#define FREERDP_CHANNEL_SMARTCARD_OPERATIONS_MAIN_H + +#include +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + typedef struct + { + union + { + Handles_Call handles; + Long_Call lng; + Context_Call context; + ContextAndStringA_Call contextAndStringA; + ContextAndStringW_Call contextAndStringW; + ContextAndTwoStringA_Call contextAndTwoStringA; + ContextAndTwoStringW_Call contextAndTwoStringW; + EstablishContext_Call establishContext; + ListReaderGroups_Call listReaderGroups; + ListReaders_Call listReaders; + GetStatusChangeA_Call getStatusChangeA; + LocateCardsA_Call locateCardsA; + LocateCardsW_Call locateCardsW; + LocateCards_ATRMask locateCardsATRMask; + LocateCardsByATRA_Call locateCardsByATRA; + LocateCardsByATRW_Call locateCardsByATRW; + GetStatusChangeW_Call getStatusChangeW; + GetReaderIcon_Call getReaderIcon; + GetDeviceTypeId_Call getDeviceTypeId; + Connect_Common_Call connect; + ConnectA_Call connectA; + ConnectW_Call connectW; + Reconnect_Call reconnect; + HCardAndDisposition_Call hCardAndDisposition; + State_Call state; + Status_Call status; + SCardIO_Request scardIO; + Transmit_Call transmit; + GetTransmitCount_Call getTransmitCount; + Control_Call control; + GetAttrib_Call getAttrib; + SetAttrib_Call setAttrib; + ReadCache_Common readCache; + ReadCacheA_Call readCacheA; + ReadCacheW_Call readCacheW; + WriteCache_Common writeCache; + WriteCacheA_Call writeCacheA; + WriteCacheW_Call writeCacheW; + } call; + UINT32 ioControlCode; + UINT32 completionID; + UINT32 deviceID; + SCARDCONTEXT hContext; + SCARDHANDLE hCard; + const char* ioControlCodeName; + } SMARTCARD_OPERATION; + + FREERDP_API LONG smartcard_irp_device_control_decode(wStream* s, UINT32 CompletionId, + UINT32 FileId, + SMARTCARD_OPERATION* operation); + FREERDP_API void smartcard_operation_free(SMARTCARD_OPERATION* op, BOOL allocated); + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_CHANNEL_SMARTCARD_CLIENT_OPERATIONS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_pack.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_pack.h new file mode 100644 index 0000000000000000000000000000000000000000..42a4f02e63fd2aec81b0904a0d03cda12d7498e1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcard_pack.h @@ -0,0 +1,186 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Smart Card Structure Packing + * + * Copyright 2014 Marc-Andre Moreau + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * Copyright 2020 Armin Novak + * Copyright 2020 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_SMARTCARD_CLIENT_PACK_H +#define FREERDP_CHANNEL_SMARTCARD_CLIENT_PACK_H + +#include +#include +#include + +#include +#include + +#define SMARTCARD_COMMON_TYPE_HEADER_LENGTH 8 +#define SMARTCARD_PRIVATE_TYPE_HEADER_LENGTH 8 + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API LONG smartcard_pack_write_size_align(wStream* s, size_t size, UINT32 alignment); + FREERDP_API LONG smartcard_unpack_read_size_align(wStream* s, size_t size, UINT32 alignment); + + FREERDP_API SCARDCONTEXT smartcard_scard_context_native_from_redir(REDIR_SCARDCONTEXT* context); + FREERDP_API void smartcard_scard_context_native_to_redir(REDIR_SCARDCONTEXT* context, + SCARDCONTEXT hContext); + + FREERDP_API SCARDHANDLE smartcard_scard_handle_native_from_redir(REDIR_SCARDHANDLE* handle); + FREERDP_API void smartcard_scard_handle_native_to_redir(REDIR_SCARDHANDLE* handle, + SCARDHANDLE hCard); + + FREERDP_API LONG smartcard_unpack_common_type_header(wStream* s); + FREERDP_API void smartcard_pack_common_type_header(wStream* s); + + FREERDP_API LONG smartcard_unpack_private_type_header(wStream* s); + FREERDP_API void smartcard_pack_private_type_header(wStream* s, UINT32 objectBufferLength); + + FREERDP_API LONG smartcard_unpack_establish_context_call(wStream* s, + EstablishContext_Call* call); + + FREERDP_API LONG smartcard_pack_establish_context_return(wStream* s, + const EstablishContext_Return* ret); + + FREERDP_API LONG smartcard_unpack_context_call(wStream* s, Context_Call* call, + const char* name); + + FREERDP_API void smartcard_trace_long_return(const Long_Return* ret, const char* name); + + FREERDP_API LONG smartcard_unpack_list_reader_groups_call(wStream* s, + ListReaderGroups_Call* call, + BOOL unicode); + + FREERDP_API LONG smartcard_pack_list_reader_groups_return(wStream* s, + const ListReaderGroups_Return* ret, + BOOL unicode); + + FREERDP_API LONG smartcard_unpack_list_readers_call(wStream* s, ListReaders_Call* call, + BOOL unicode); + + FREERDP_API LONG smartcard_pack_list_readers_return(wStream* s, const ListReaders_Return* ret, + BOOL unicode); + + FREERDP_API LONG + smartcard_unpack_context_and_two_strings_a_call(wStream* s, ContextAndTwoStringA_Call* call); + + FREERDP_API LONG + smartcard_unpack_context_and_two_strings_w_call(wStream* s, ContextAndTwoStringW_Call* call); + + FREERDP_API LONG smartcard_unpack_context_and_string_a_call(wStream* s, + ContextAndStringA_Call* call); + + FREERDP_API LONG smartcard_unpack_context_and_string_w_call(wStream* s, + ContextAndStringW_Call* call); + + FREERDP_API LONG smartcard_unpack_locate_cards_a_call(wStream* s, LocateCardsA_Call* call); + + FREERDP_API LONG smartcard_pack_locate_cards_return(wStream* s, const LocateCards_Return* ret); + + FREERDP_API LONG smartcard_unpack_locate_cards_w_call(wStream* s, LocateCardsW_Call* call); + + FREERDP_API LONG smartcard_pack_locate_cards_w_return(wStream* s, const LocateCardsW_Call* ret); + + FREERDP_API LONG smartcard_unpack_connect_a_call(wStream* s, ConnectA_Call* call); + + FREERDP_API LONG smartcard_unpack_connect_w_call(wStream* s, ConnectW_Call* call); + + FREERDP_API LONG smartcard_pack_connect_return(wStream* s, const Connect_Return* ret); + + FREERDP_API LONG smartcard_unpack_reconnect_call(wStream* s, Reconnect_Call* call); + + FREERDP_API LONG smartcard_pack_reconnect_return(wStream* s, const Reconnect_Return* ret); + + FREERDP_API LONG smartcard_unpack_hcard_and_disposition_call(wStream* s, + HCardAndDisposition_Call* call, + const char* name); + + FREERDP_API LONG smartcard_unpack_get_status_change_a_call(wStream* s, + GetStatusChangeA_Call* call); + + FREERDP_API LONG smartcard_unpack_get_status_change_w_call(wStream* s, + GetStatusChangeW_Call* call); + + FREERDP_API LONG smartcard_pack_get_status_change_return(wStream* s, + const GetStatusChange_Return* ret, + BOOL unicode); + + FREERDP_API LONG smartcard_unpack_state_call(wStream* s, State_Call* call); + FREERDP_API LONG smartcard_pack_state_return(wStream* s, const State_Return* ret); + + FREERDP_API LONG smartcard_unpack_status_call(wStream* s, Status_Call* call, BOOL unicode); + + FREERDP_API LONG smartcard_pack_status_return(wStream* s, const Status_Return* ret, + BOOL unicode); + + FREERDP_API LONG smartcard_unpack_get_attrib_call(wStream* s, GetAttrib_Call* call); + + FREERDP_API LONG smartcard_pack_get_attrib_return(wStream* s, const GetAttrib_Return* ret, + DWORD dwAttrId, DWORD cbAttrCallLen); + + FREERDP_API LONG smartcard_unpack_set_attrib_call(wStream* s, SetAttrib_Call* call); + + FREERDP_API LONG smartcard_unpack_control_call(wStream* s, Control_Call* call); + + FREERDP_API LONG smartcard_pack_control_return(wStream* s, const Control_Return* ret); + + FREERDP_API LONG smartcard_unpack_transmit_call(wStream* s, Transmit_Call* call); + + FREERDP_API LONG smartcard_pack_transmit_return(wStream* s, const Transmit_Return* ret); + + FREERDP_API LONG smartcard_unpack_locate_cards_by_atr_a_call(wStream* s, + LocateCardsByATRA_Call* call); + + FREERDP_API LONG smartcard_unpack_locate_cards_by_atr_w_call(wStream* s, + LocateCardsByATRW_Call* call); + + FREERDP_API LONG smartcard_unpack_read_cache_a_call(wStream* s, ReadCacheA_Call* call); + + FREERDP_API LONG smartcard_unpack_read_cache_w_call(wStream* s, ReadCacheW_Call* call); + + FREERDP_API LONG smartcard_pack_read_cache_return(wStream* s, const ReadCache_Return* ret); + + FREERDP_API LONG smartcard_unpack_write_cache_a_call(wStream* s, WriteCacheA_Call* call); + + FREERDP_API LONG smartcard_unpack_write_cache_w_call(wStream* s, WriteCacheW_Call* call); + + FREERDP_API LONG smartcard_unpack_get_transmit_count_call(wStream* s, + GetTransmitCount_Call* call); + FREERDP_API LONG smartcard_pack_get_transmit_count_return(wStream* s, + const GetTransmitCount_Return* call); + + FREERDP_API LONG smartcard_unpack_get_reader_icon_call(wStream* s, GetReaderIcon_Call* call); + FREERDP_API LONG smartcard_pack_get_reader_icon_return(wStream* s, + const GetReaderIcon_Return* ret); + + FREERDP_API LONG smartcard_unpack_get_device_type_id_call(wStream* s, + GetDeviceTypeId_Call* call); + + FREERDP_API LONG smartcard_pack_device_type_id_return(wStream* s, + const GetDeviceTypeId_Return* ret); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CHANNEL_SMARTCARD_CLIENT_PACK_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcardlogon.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcardlogon.h new file mode 100644 index 0000000000000000000000000000000000000000..66e1097b3f7296f771ec6f4f24f7d25263c414d2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/smartcardlogon.h @@ -0,0 +1,62 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Logging in with smartcards + * + * Copyright 2022 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef FREERDP_UTILS_SMARTCARDLOGON_H +#define FREERDP_UTILS_SMARTCARDLOGON_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct SmartcardKeyInfo_st SmartcardKeyInfo; + + typedef struct SmartcardCertInfo_st + { + LPWSTR csp; + LPWSTR reader; + rdpCertificate* certificate; + char* pkinitArgs; + UINT32 slotId; + char* keyName; + WCHAR* containerName; + char* upn; + char* userHint; + char* domainHint; + char* subject; + char* issuer; + BYTE sha1Hash[20]; + SmartcardKeyInfo* key_info; + } SmartcardCertInfo; + + FREERDP_API BOOL smartcard_enumerateCerts(const rdpSettings* settings, + SmartcardCertInfo*** scCerts, size_t* retCount, + BOOL gateway); + FREERDP_API BOOL smartcard_getCert(const rdpContext* context, SmartcardCertInfo** cert, + BOOL gateway); + FREERDP_API void smartcardCertInfo_Free(SmartcardCertInfo* pscCert); + FREERDP_API void smartcardCertList_Free(SmartcardCertInfo** pscCert, size_t count); + +#ifdef __cplusplus +} +#endif +#endif /* FREERDP_UTILS_SMARTCARDLOGON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/stopwatch.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/stopwatch.h new file mode 100644 index 0000000000000000000000000000000000000000..c26725063f634ee4c82c1a24fa9c4d934cb49ea3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/stopwatch.h @@ -0,0 +1,54 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Stopwatch Utils + * + * Copyright 2011 Stephen Erisman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_STOPWATCH_H +#define FREERDP_UTILS_STOPWATCH_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT64 start; + UINT64 end; + UINT64 elapsed; + UINT32 count; + } STOPWATCH; + + FREERDP_API STOPWATCH* stopwatch_create(void); + FREERDP_API void stopwatch_free(STOPWATCH* stopwatch); + + FREERDP_API void stopwatch_start(STOPWATCH* stopwatch); + FREERDP_API void stopwatch_stop(STOPWATCH* stopwatch); + FREERDP_API void stopwatch_reset(STOPWATCH* stopwatch); + + FREERDP_API double stopwatch_get_elapsed_time_in_seconds(STOPWATCH* stopwatch); + FREERDP_API void stopwatch_get_elapsed_time_in_useconds(STOPWATCH* stopwatch, UINT32* sec, + UINT32* usec); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_STOPWATCH_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/string.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/string.h new file mode 100644 index 0000000000000000000000000000000000000000..41f28ec05375fb76e1b82b982068678b043f0752 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/utils/string.h @@ -0,0 +1,54 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * String Utils - Helper functions converting something to string + * + * Copyright 2022 Armin Novak + * Copyright 2022 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UTILS_STRING_H +#define FREERDP_UTILS_STRING_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + FREERDP_API const char* rdp_redirection_flags_to_string(UINT32 flags, char* buffer, + size_t size); + FREERDP_API const char* rdp_cluster_info_flags_to_string(UINT32 flags, char* buffer, + size_t size); + + /** @brief extracts = pairs from a string + * + * @param str The string to extract data from, must not be \b NULL + * @param pkey A pointer to store the key value, must not be \b NULL + * @param pvalue A pointer to store the value, must not be \b NULL + * + * @return \b TRUE if successfully extracted, \b FALSE if no matching data was found + * + * @since version 3.9.0 + */ + FREERDP_API BOOL freerdp_extract_key_value(const char* str, UINT32* pkey, UINT32* pvalue); + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UTILS_STRING_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/window.h b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/window.h new file mode 100644 index 0000000000000000000000000000000000000000..2b65a76ce4316ccf83b586a8ae416525222f3137 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/include/freerdp/window.h @@ -0,0 +1,298 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Window Alternate Secondary Drawing Orders Interface API + * + * Copyright 2011 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_UPDATE_WINDOW_H +#define FREERDP_UPDATE_WINDOW_H + +#include +#include + +/* Window Order Header Flags */ +#define WINDOW_ORDER_TYPE_WINDOW 0x01000000 +#define WINDOW_ORDER_TYPE_NOTIFY 0x02000000 +#define WINDOW_ORDER_TYPE_DESKTOP 0x04000000 + +#define WINDOW_ORDER_STATE_NEW 0x10000000 +#define WINDOW_ORDER_STATE_DELETED 0x20000000 + +/* Window Order Update */ +#define WINDOW_ORDER_FIELD_OWNER 0x00000002 +#define WINDOW_ORDER_FIELD_STYLE 0x00000008 +#define WINDOW_ORDER_FIELD_SHOW 0x00000010 +#define WINDOW_ORDER_FIELD_TITLE 0x00000004 +#define WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET 0x00004000 +#define WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE 0x00010000 +#define WINDOW_ORDER_FIELD_RESIZE_MARGIN_X 0x00000080 +#define WINDOW_ORDER_FIELD_RESIZE_MARGIN_Y 0x08000000 +#define WINDOW_ORDER_FIELD_RP_CONTENT 0x00020000 +#define WINDOW_ORDER_FIELD_ROOT_PARENT 0x00040000 +#define WINDOW_ORDER_FIELD_WND_OFFSET 0x00000800 +#define WINDOW_ORDER_FIELD_WND_CLIENT_DELTA 0x00008000 +#define WINDOW_ORDER_FIELD_WND_SIZE 0x00000400 +#define WINDOW_ORDER_FIELD_WND_RECTS 0x00000100 +#define WINDOW_ORDER_FIELD_VIS_OFFSET 0x00001000 +#define WINDOW_ORDER_FIELD_VISIBILITY 0x00000200 +#define WINDOW_ORDER_FIELD_OVERLAY_DESCRIPTION 0x00400000 +#define WINDOW_ORDER_FIELD_ICON_OVERLAY_NULL 0x00200000 +#define WINDOW_ORDER_FIELD_TASKBAR_BUTTON 0x00800000 +#define WINDOW_ORDER_FIELD_ENFORCE_SERVER_ZORDER 0x00080000 +#define WINDOW_ORDER_FIELD_APPBAR_STATE 0x00000040 +#define WINDOW_ORDER_FIELD_APPBAR_EDGE 0x00000001 + +/* Window (cached) Icon */ +#define WINDOW_ORDER_ICON 0x40000000 +#define WINDOW_ORDER_CACHED_ICON 0x80000000 +#define WINDOW_ORDER_FIELD_ICON_BIG 0x00002000 +#define WINDOW_ORDER_FIELD_ICON_OVERLAY 0x00100000 + +#define WINDOW_ORDER_FIELD_NOTIFY_VERSION 0x00000008 +#define WINDOW_ORDER_FIELD_NOTIFY_TIP 0x00000001 +#define WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP 0x00000002 +#define WINDOW_ORDER_FIELD_NOTIFY_STATE 0x00000004 +#define WINDOW_ORDER_FIELD_DESKTOP_NONE 0x00000001 +#define WINDOW_ORDER_FIELD_DESKTOP_HOOKED 0x00000002 +#define WINDOW_ORDER_FIELD_DESKTOP_ARC_COMPLETED 0x00000004 +#define WINDOW_ORDER_FIELD_DESKTOP_ARC_BEGAN 0x00000008 +#define WINDOW_ORDER_FIELD_DESKTOP_ZORDER 0x00000010 +#define WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND 0x00000020 + +/* Window Show States */ +#define WINDOW_HIDE 0x00 +#define WINDOW_SHOW_MINIMIZED 0x02 +#define WINDOW_SHOW_MAXIMIZED 0x03 +#define WINDOW_SHOW 0x05 + +/* Window Styles */ +#ifndef _WIN32 +#define WS_NONE 0x00000000 +#define WS_BORDER 0x00800000 +#define WS_CAPTION 0x00C00000 +#define WS_CHILD 0x40000000 +#define WS_CHILDWINDOW 0x40000000 +#define WS_CLIPCHILDREN 0x02000000 +#define WS_CLIPSIBLINGS 0x04000000 +#define WS_DISABLED 0x08000000 +#define WS_DLGFRAME 0x00400000 +#define WS_GROUP 0x00020000 +#define WS_HSCROLL 0x00100000 +#define WS_ICONIC 0x20000000 +#define WS_MAXIMIZE 0x01000000 +#define WS_MAXIMIZEBOX 0x00010000 +#define WS_MINIMIZE 0x20000000 +#define WS_MINIMIZEBOX 0x00020000 +#define WS_OVERLAPPED 0x00000000 +#define WS_OVERLAPPEDWINDOW \ + (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) +#define WS_POPUP 0x80000000 +#define WS_POPUPWINDOW (WS_POPUP | WS_BORDER | WS_SYSMENU) +#define WS_SIZEBOX 0x00040000 +#define WS_SYSMENU 0x00080000 +#define WS_TABSTOP 0x00010000 +#define WS_THICKFRAME 0x00040000 +#define WS_VISIBLE 0x10000000 +#define WS_VSCROLL 0x00200000 +#define WS_TILEDWINDOW \ + (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) +#endif + +/* Extended Window Styles */ +#ifndef _WIN32 +#define WS_EX_NONE 0x00000000 +#define WS_EX_ACCEPTFILES 0x00000010 +#define WS_EX_APPWINDOW 0x00040000 +#define WS_EX_CLIENTEDGE 0x00000200 +#define WS_EX_COMPOSITED 0x02000000 +#define WS_EX_CONTEXTHELP 0x00000400 +#define WS_EX_CONTROLPARENT 0x00010000 +#define WS_EX_DLGMODALFRAME 0x00000001 +#define WS_EX_LAYERED 0x00080000 +#define WS_EX_LAYOUTRTL 0x00400000 +#define WS_EX_LEFT 0x00000000 +#define WS_EX_LEFTSCROLLBAR 0x00004000 +#define WS_EX_LTRREADING 0x00000000 +#define WS_EX_MDICHILD 0x00000040 +#define WS_EX_NOACTIVATE 0x08000000 +#define WS_EX_NOINHERITLAYOUT 0x00100000 +#define WS_EX_NOPARENTNOTIFY 0x00000004 +#define WS_EX_NOREDIRECTIONBITMAP 0x00200000 +#define WS_EX_OVERLAPPEDWINDOW (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE) +#define WS_EX_PALETTEWINDOW (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST) +#define WS_EX_RIGHT 0x00001000 +#define WS_EX_RIGHTSCROLLBAR 0x00000000 +#define WS_EX_RTLREADING 0x00002000 +#define WS_EX_STATICEDGE 0x00020000 +#define WS_EX_TOOLWINDOW 0x00000080 +#define WS_EX_TOPMOST 0x00000008 +#define WS_EX_TRANSPARENT 0x00000020 +#define WS_EX_WINDOWEDGE 0x00000100 +#endif + +/** + * This is a custom extended window style used by XRDP + * instructing the client to use local window decorations + */ + +#define WS_EX_DECORATIONS 0x40000000 + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct + { + UINT32 windowId; + UINT32 fieldFlags; + UINT32 notifyIconId; + } WINDOW_ORDER_INFO; + + typedef struct + { + UINT32 cacheEntry; + UINT32 cacheId; + UINT32 bpp; + UINT32 width; + UINT32 height; + UINT32 cbColorTable; + UINT32 cbBitsMask; + UINT32 cbBitsColor; + BYTE* bitsMask; + BYTE* colorTable; + BYTE* bitsColor; + } ICON_INFO; + + typedef struct + { + UINT32 cacheEntry; + UINT32 cacheId; + } CACHED_ICON_INFO; + + typedef struct + { + UINT32 timeout; + UINT32 flags; + RAIL_UNICODE_STRING text; + RAIL_UNICODE_STRING title; + } NOTIFY_ICON_INFOTIP; + + typedef struct + { + UINT32 ownerWindowId; + UINT32 style; + UINT32 extendedStyle; + UINT32 showState; + RAIL_UNICODE_STRING titleInfo; + INT32 clientOffsetX; + INT32 clientOffsetY; + UINT32 clientAreaWidth; + UINT32 clientAreaHeight; + UINT32 RPContent; + UINT32 rootParentHandle; + INT32 windowOffsetX; + INT32 windowOffsetY; + INT32 windowClientDeltaX; + INT32 windowClientDeltaY; + UINT32 windowWidth; + UINT32 windowHeight; + UINT32 numWindowRects; + RECTANGLE_16* windowRects; + INT32 visibleOffsetX; + INT32 visibleOffsetY; + UINT32 resizeMarginLeft; + UINT32 resizeMarginTop; + UINT32 resizeMarginRight; + UINT32 resizeMarginBottom; + UINT32 numVisibilityRects; + RECTANGLE_16* visibilityRects; + RAIL_UNICODE_STRING OverlayDescription; + BYTE TaskbarButton; + UINT8 EnforceServerZOrder; + UINT8 AppBarState; + UINT8 AppBarEdge; + } WINDOW_STATE_ORDER; + + typedef struct + { + ICON_INFO* iconInfo; + } WINDOW_ICON_ORDER; + + typedef struct + { + CACHED_ICON_INFO cachedIcon; + } WINDOW_CACHED_ICON_ORDER; + + typedef struct + { + UINT32 version; + RAIL_UNICODE_STRING toolTip; + NOTIFY_ICON_INFOTIP infoTip; + UINT32 state; + ICON_INFO icon; + CACHED_ICON_INFO cachedIcon; + } NOTIFY_ICON_STATE_ORDER; + + typedef struct + { + UINT32 activeWindowId; + UINT32 numWindowIds; + UINT32* windowIds; + } MONITORED_DESKTOP_ORDER; + + typedef BOOL (*pWindowCreate)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo, + const WINDOW_STATE_ORDER* window_state); + typedef BOOL (*pWindowUpdate)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo, + const WINDOW_STATE_ORDER* window_state); + typedef BOOL (*pWindowIcon)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo, + const WINDOW_ICON_ORDER* window_icon); + typedef BOOL (*pWindowCachedIcon)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo, + const WINDOW_CACHED_ICON_ORDER* window_cached_icon); + typedef BOOL (*pWindowDelete)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo); + typedef BOOL (*pNotifyIconCreate)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo, + const NOTIFY_ICON_STATE_ORDER* notify_icon_state); + typedef BOOL (*pNotifyIconUpdate)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo, + const NOTIFY_ICON_STATE_ORDER* notify_icon_state); + typedef BOOL (*pNotifyIconDelete)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo); + typedef BOOL (*pMonitoredDesktop)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo, + const MONITORED_DESKTOP_ORDER* monitored_desktop); + typedef BOOL (*pNonMonitoredDesktop)(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo); + + struct rdp_window_update + { + rdpContext* context; /* 0 */ + UINT32 paddingA[16 - 1]; /* 1 */ + + pWindowCreate WindowCreate; /* 16 */ + pWindowUpdate WindowUpdate; /* 17 */ + pWindowIcon WindowIcon; /* 18 */ + pWindowCachedIcon WindowCachedIcon; /* 19 */ + pWindowDelete WindowDelete; /* 20 */ + pNotifyIconCreate NotifyIconCreate; /* 21 */ + pNotifyIconUpdate NotifyIconUpdate; /* 22 */ + pNotifyIconDelete NotifyIconDelete; /* 23 */ + pMonitoredDesktop MonitoredDesktop; /* 24 */ + pNonMonitoredDesktop NonMonitoredDesktop; /* 25 */ + UINT32 paddingB[32 - 26]; /* 26 */ + }; + typedef struct rdp_window_update rdpWindowUpdate; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_UPDATE_WINDOW_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/include/bitmap.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/include/bitmap.h new file mode 100644 index 0000000000000000000000000000000000000000..add8ec80bc131f9ee1710cd654239ebb6d158b8a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/include/bitmap.h @@ -0,0 +1,455 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RLE Compressed Bitmap Stream + * + * Copyright 2011 Jay Sorg + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +/* do not compile the file directly */ + +/** + * Write a foreground/background image to a destination buffer. + */ +static inline BYTE* WRITEFGBGIMAGE(BYTE* WINPR_RESTRICT pbDest, + const BYTE* WINPR_RESTRICT pbDestEnd, UINT32 rowDelta, + BYTE bitmask, PIXEL fgPel, UINT32 cBits) +{ + PIXEL xorPixel = 0; + BYTE mask = 0x01; + + if (cBits > 8) + { + WLog_ERR(TAG, "cBits %d > 8", cBits); + return NULL; + } + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, cBits)) + return NULL; + + UNROLL(cBits, { + PIXEL data = 0; + DESTREADPIXEL(xorPixel, pbDest - rowDelta); + + if (bitmask & mask) + data = xorPixel ^ fgPel; + else + data = xorPixel; + + DESTWRITEPIXEL(pbDest, data); + mask = WINPR_ASSERTING_INT_CAST(BYTE, (mask << 1) & 0xFF); + }); + return pbDest; +} + +/** + * Write a foreground/background image to a destination buffer + * for the first line of compressed data. + */ +static inline BYTE* WRITEFIRSTLINEFGBGIMAGE(BYTE* WINPR_RESTRICT pbDest, + const BYTE* WINPR_RESTRICT pbDestEnd, BYTE bitmask, + PIXEL fgPel, UINT32 cBits) +{ + BYTE mask = 0x01; + + if (cBits > 8) + { + WLog_ERR(TAG, "cBits %d > 8", cBits); + return NULL; + } + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, cBits)) + return NULL; + + UNROLL(cBits, { + PIXEL data; + + if (bitmask & mask) + data = fgPel; + else + data = BLACK_PIXEL; + + DESTWRITEPIXEL(pbDest, data); + mask = WINPR_ASSERTING_INT_CAST(BYTE, (mask << 1) & 0xFF); + }); + return pbDest; +} + +/** + * Decompress an RLE compressed bitmap. + */ +static inline BOOL RLEDECOMPRESS(const BYTE* WINPR_RESTRICT pbSrcBuffer, UINT32 cbSrcBuffer, + BYTE* WINPR_RESTRICT pbDestBuffer, UINT32 rowDelta, UINT32 width, + UINT32 height) +{ +#if defined(WITH_DEBUG_CODECS) + char sbuffer[128] = { 0 }; +#endif + const BYTE* pbSrc = pbSrcBuffer; + BYTE* pbDest = pbDestBuffer; + PIXEL temp = 0; + PIXEL fgPel = WHITE_PIXEL; + BOOL fInsertFgPel = FALSE; + BOOL fFirstLine = TRUE; + BYTE bitmask = 0; + PIXEL pixelA = 0; + PIXEL pixelB = 0; + UINT32 runLength = 0; + UINT32 code = 0; + UINT32 advance = 0; + RLEEXTRA + + if ((rowDelta == 0) || (rowDelta < width)) + { + WLog_ERR(TAG, "Invalid arguments: rowDelta=%" PRIu32 " == 0 || < width=%" PRIu32, rowDelta, + width); + return FALSE; + } + + if (!pbSrcBuffer || !pbDestBuffer) + { + WLog_ERR(TAG, "Invalid arguments: pbSrcBuffer=%p, pbDestBuffer=%p", pbSrcBuffer, + pbDestBuffer); + return FALSE; + } + + const BYTE* pbEnd = &pbSrcBuffer[cbSrcBuffer]; + const BYTE* pbDestEnd = &pbDestBuffer[1ULL * rowDelta * height]; + + while (pbSrc < pbEnd) + { + /* Watch out for the end of the first scanline. */ + if (fFirstLine) + { + if ((UINT32)(pbDest - pbDestBuffer) >= rowDelta) + { + fFirstLine = FALSE; + fInsertFgPel = FALSE; + } + } + + /* + Extract the compression order code ID from the compression + order header. + */ + code = ExtractCodeId(*pbSrc); + +#if defined(WITH_DEBUG_CODECS) + WLog_VRB(TAG, "pbSrc=%p code=%s, rem=%" PRIuz, pbSrc, + rle_code_str_buffer(code, sbuffer, sizeof(sbuffer)), pbEnd - pbSrc); +#endif + + /* Handle Background Run Orders. */ + if ((code == REGULAR_BG_RUN) || (code == MEGA_MEGA_BG_RUN)) + { + runLength = ExtractRunLength(code, pbSrc, pbEnd, &advance); + if (advance == 0) + return FALSE; + pbSrc = pbSrc + advance; + + if (fFirstLine) + { + if (fInsertFgPel) + { + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, 1)) + return FALSE; + + DESTWRITEPIXEL(pbDest, fgPel); + runLength = runLength - 1; + } + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, runLength)) + return FALSE; + + UNROLL(runLength, { DESTWRITEPIXEL(pbDest, BLACK_PIXEL); }); + } + else + { + if (fInsertFgPel) + { + DESTREADPIXEL(temp, pbDest - rowDelta); + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, 1)) + return FALSE; + + DESTWRITEPIXEL(pbDest, temp ^ fgPel); + runLength--; + } + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, runLength)) + return FALSE; + + UNROLL(runLength, { + DESTREADPIXEL(temp, pbDest - rowDelta); + DESTWRITEPIXEL(pbDest, temp); + }); + } + + /* A follow-on background run order will need a foreground pel inserted. */ + fInsertFgPel = TRUE; + continue; + } + + /* For any of the other run-types a follow-on background run + order does not need a foreground pel inserted. */ + fInsertFgPel = FALSE; + + switch (code) + { + /* Handle Foreground Run Orders. */ + case REGULAR_FG_RUN: + case MEGA_MEGA_FG_RUN: + case LITE_SET_FG_FG_RUN: + case MEGA_MEGA_SET_FG_RUN: + runLength = ExtractRunLength(code, pbSrc, pbEnd, &advance); + if (advance == 0) + return FALSE; + pbSrc = pbSrc + advance; + + if (code == LITE_SET_FG_FG_RUN || code == MEGA_MEGA_SET_FG_RUN) + { + if (!buffer_within_range(pbSrc, PIXEL_SIZE, pbEnd)) + return FALSE; + SRCREADPIXEL(fgPel, pbSrc); + } + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, runLength)) + return FALSE; + + if (fFirstLine) + { + UNROLL(runLength, { DESTWRITEPIXEL(pbDest, fgPel); }); + } + else + { + UNROLL(runLength, { + DESTREADPIXEL(temp, pbDest - rowDelta); + DESTWRITEPIXEL(pbDest, temp ^ fgPel); + }); + } + + break; + + /* Handle Dithered Run Orders. */ + case LITE_DITHERED_RUN: + case MEGA_MEGA_DITHERED_RUN: + runLength = ExtractRunLength(code, pbSrc, pbEnd, &advance); + if (advance == 0) + return FALSE; + pbSrc = pbSrc + advance; + if (!buffer_within_range(pbSrc, PIXEL_SIZE, pbEnd)) + return FALSE; + SRCREADPIXEL(pixelA, pbSrc); + if (!buffer_within_range(pbSrc, PIXEL_SIZE, pbEnd)) + return FALSE; + SRCREADPIXEL(pixelB, pbSrc); + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, runLength * 2)) + return FALSE; + + UNROLL(runLength, { + DESTWRITEPIXEL(pbDest, pixelA); + DESTWRITEPIXEL(pbDest, pixelB); + }); + break; + + /* Handle Color Run Orders. */ + case REGULAR_COLOR_RUN: + case MEGA_MEGA_COLOR_RUN: + runLength = ExtractRunLength(code, pbSrc, pbEnd, &advance); + if (advance == 0) + return FALSE; + pbSrc = pbSrc + advance; + if (!buffer_within_range(pbSrc, PIXEL_SIZE, pbEnd)) + return FALSE; + SRCREADPIXEL(pixelA, pbSrc); + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, runLength)) + return FALSE; + + UNROLL(runLength, { DESTWRITEPIXEL(pbDest, pixelA); }); + break; + + /* Handle Foreground/Background Image Orders. */ + case REGULAR_FGBG_IMAGE: + case MEGA_MEGA_FGBG_IMAGE: + case LITE_SET_FG_FGBG_IMAGE: + case MEGA_MEGA_SET_FGBG_IMAGE: + runLength = ExtractRunLength(code, pbSrc, pbEnd, &advance); + if (advance == 0) + return FALSE; + pbSrc = pbSrc + advance; + + if (code == LITE_SET_FG_FGBG_IMAGE || code == MEGA_MEGA_SET_FGBG_IMAGE) + { + if (!buffer_within_range(pbSrc, PIXEL_SIZE, pbEnd)) + return FALSE; + SRCREADPIXEL(fgPel, pbSrc); + } + + if (!buffer_within_range(pbSrc, runLength / 8, pbEnd)) + return FALSE; + if (fFirstLine) + { + while (runLength > 8) + { + bitmask = *pbSrc; + pbSrc = pbSrc + 1; + pbDest = WRITEFIRSTLINEFGBGIMAGE(pbDest, pbDestEnd, bitmask, fgPel, 8); + + if (!pbDest) + return FALSE; + + runLength = runLength - 8; + } + } + else + { + while (runLength > 8) + { + bitmask = *pbSrc++; + + pbDest = WRITEFGBGIMAGE(pbDest, pbDestEnd, rowDelta, bitmask, fgPel, 8); + + if (!pbDest) + return FALSE; + + runLength = runLength - 8; + } + } + + if (runLength > 0) + { + if (!buffer_within_range(pbSrc, 1, pbEnd)) + return FALSE; + bitmask = *pbSrc++; + + if (fFirstLine) + { + pbDest = + WRITEFIRSTLINEFGBGIMAGE(pbDest, pbDestEnd, bitmask, fgPel, runLength); + } + else + { + pbDest = + WRITEFGBGIMAGE(pbDest, pbDestEnd, rowDelta, bitmask, fgPel, runLength); + } + + if (!pbDest) + return FALSE; + } + + break; + + /* Handle Color Image Orders. */ + case REGULAR_COLOR_IMAGE: + case MEGA_MEGA_COLOR_IMAGE: + runLength = ExtractRunLength(code, pbSrc, pbEnd, &advance); + if (advance == 0) + return FALSE; + pbSrc = pbSrc + advance; + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, runLength)) + return FALSE; + if (!ENSURE_CAPACITY(pbSrc, pbEnd, runLength)) + return FALSE; + + UNROLL(runLength, { + SRCREADPIXEL(temp, pbSrc); + DESTWRITEPIXEL(pbDest, temp); + }); + break; + + /* Handle Special Order 1. */ + case SPECIAL_FGBG_1: + if (!buffer_within_range(pbSrc, 1, pbEnd)) + return FALSE; + pbSrc = pbSrc + 1; + + if (fFirstLine) + { + pbDest = + WRITEFIRSTLINEFGBGIMAGE(pbDest, pbDestEnd, g_MaskSpecialFgBg1, fgPel, 8); + } + else + { + pbDest = + WRITEFGBGIMAGE(pbDest, pbDestEnd, rowDelta, g_MaskSpecialFgBg1, fgPel, 8); + } + + if (!pbDest) + return FALSE; + + break; + + /* Handle Special Order 2. */ + case SPECIAL_FGBG_2: + if (!buffer_within_range(pbSrc, 1, pbEnd)) + return FALSE; + pbSrc = pbSrc + 1; + + if (fFirstLine) + { + pbDest = + WRITEFIRSTLINEFGBGIMAGE(pbDest, pbDestEnd, g_MaskSpecialFgBg2, fgPel, 8); + } + else + { + pbDest = + WRITEFGBGIMAGE(pbDest, pbDestEnd, rowDelta, g_MaskSpecialFgBg2, fgPel, 8); + } + + if (!pbDest) + return FALSE; + + break; + + /* Handle White Order. */ + case SPECIAL_WHITE: + if (!buffer_within_range(pbSrc, 1, pbEnd)) + return FALSE; + pbSrc = pbSrc + 1; + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, 1)) + return FALSE; + + DESTWRITEPIXEL(pbDest, WHITE_PIXEL); + break; + + /* Handle Black Order. */ + case SPECIAL_BLACK: + if (!buffer_within_range(pbSrc, 1, pbEnd)) + return FALSE; + pbSrc = pbSrc + 1; + + if (!ENSURE_CAPACITY(pbDest, pbDestEnd, 1)) + return FALSE; + + DESTWRITEPIXEL(pbDest, BLACK_PIXEL); + break; + + default: + WLog_ERR(TAG, "invalid code 0x%08" PRIx32 ", pbSrcBuffer=%p, pbSrc=%p, pbEnd=%p", + code, pbSrcBuffer, pbSrc, pbEnd); + return FALSE; + } + } + + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/nsc_neon.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/nsc_neon.c new file mode 100644 index 0000000000000000000000000000000000000000..cfa7b7f581fa0278ba467a2d6afdc36c79bf539c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/nsc_neon.c @@ -0,0 +1,43 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * NSCodec Library - SSE2 Optimizations + * + * Copyright 2024 Armin Novak + * Copyright 2024 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "../nsc_types.h" +#include "nsc_neon.h" + +#include "../../core/simd.h" + +#if defined(NEON_INTRINSICS_ENABLED) +#define TAG FREERDP_TAG("codec.nsc.neon") +#endif + +void nsc_init_neon(NSC_CONTEXT* context) +{ +#if defined(NEON_INTRINSICS_ENABLED) + if (!IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) + return; + + WLog_WARN(TAG, "TODO: Implement neon optimized version of this function"); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/nsc_neon.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/nsc_neon.h new file mode 100644 index 0000000000000000000000000000000000000000..159ab246a7e8f3b03b2c8326382d5fc8c682c874 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/nsc_neon.h @@ -0,0 +1,28 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * NSCodec Library - NEON Optimizations + * + * Copyright 2012 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CODEC_NSC_NEON_H +#define FREERDP_LIB_CODEC_NSC_NEON_H + +#include +#include + +FREERDP_LOCAL void nsc_init_neon(NSC_CONTEXT* context); + +#endif /* FREERDP_LIB_CODEC_NSC_NEON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/rfx_neon.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/rfx_neon.c new file mode 100644 index 0000000000000000000000000000000000000000..131d91d94655861a871ad8376c1482dbe34fc585 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/rfx_neon.c @@ -0,0 +1,543 @@ +/* + FreeRDP: A Remote Desktop Protocol Implementation + RemoteFX Codec Library - NEON Optimizations + + Copyright 2011 Martin Fleisz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include +#include +#include + +#include "../rfx_types.h" +#include "rfx_neon.h" + +#include "../../core/simd.h" + +#if defined(NEON_INTRINSICS_ENABLED) + +#include +#include +#include +#include +#include + +/* rfx_decode_YCbCr_to_RGB_NEON code now resides in the primitives library. */ + +static __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +rfx_quantization_decode_block_NEON(INT16* buffer, const size_t buffer_size, const UINT32 factor) +{ + int16x8_t quantFactors = vdupq_n_s16(factor); + int16x8_t* buf = (int16x8_t*)buffer; + int16x8_t* buf_end = (int16x8_t*)(buffer + buffer_size); + + do + { + int16x8_t val = vld1q_s16((INT16*)buf); + val = vshlq_s16(val, quantFactors); + vst1q_s16((INT16*)buf, val); + buf++; + } while (buf < buf_end); +} + +static void rfx_quantization_decode_NEON(INT16* buffer, const UINT32* WINPR_RESTRICT quantVals) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(quantVals); + + rfx_quantization_decode_block_NEON(&buffer[0], 1024, quantVals[8] - 1); /* HL1 */ + rfx_quantization_decode_block_NEON(&buffer[1024], 1024, quantVals[7] - 1); /* LH1 */ + rfx_quantization_decode_block_NEON(&buffer[2048], 1024, quantVals[9] - 1); /* HH1 */ + rfx_quantization_decode_block_NEON(&buffer[3072], 256, quantVals[5] - 1); /* HL2 */ + rfx_quantization_decode_block_NEON(&buffer[3328], 256, quantVals[4] - 1); /* LH2 */ + rfx_quantization_decode_block_NEON(&buffer[3584], 256, quantVals[6] - 1); /* HH2 */ + rfx_quantization_decode_block_NEON(&buffer[3840], 64, quantVals[2] - 1); /* HL3 */ + rfx_quantization_decode_block_NEON(&buffer[3904], 64, quantVals[1] - 1); /* LH3 */ + rfx_quantization_decode_block_NEON(&buffer[3968], 64, quantVals[3] - 1); /* HH3 */ + rfx_quantization_decode_block_NEON(&buffer[4032], 64, quantVals[0] - 1); /* LL3 */ +} + +static __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +rfx_dwt_2d_decode_block_horiz_NEON(INT16* WINPR_RESTRICT l, INT16* WINPR_RESTRICT h, + INT16* WINPR_RESTRICT dst, size_t subband_width) +{ + INT16* l_ptr = l; + INT16* h_ptr = h; + INT16* dst_ptr = dst; + + for (size_t y = 0; y < subband_width; y++) + { + /* Even coefficients */ + for (size_t n = 0; n < subband_width; n += 8) + { + // dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); + int16x8_t l_n = vld1q_s16(l_ptr); + int16x8_t h_n = vld1q_s16(h_ptr); + int16x8_t h_n_m = vld1q_s16(h_ptr - 1); + + if (n == 0) + { + int16_t first = vgetq_lane_s16(h_n_m, 1); + h_n_m = vsetq_lane_s16(first, h_n_m, 0); + } + + int16x8_t tmp_n = vaddq_s16(h_n, h_n_m); + tmp_n = vaddq_s16(tmp_n, vdupq_n_s16(1)); + tmp_n = vshrq_n_s16(tmp_n, 1); + int16x8_t dst_n = vsubq_s16(l_n, tmp_n); + vst1q_s16(l_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + } + + l_ptr -= subband_width; + h_ptr -= subband_width; + + /* Odd coefficients */ + for (size_t n = 0; n < subband_width; n += 8) + { + // dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); + int16x8_t h_n = vld1q_s16(h_ptr); + h_n = vshlq_n_s16(h_n, 1); + int16x8x2_t dst_n; + dst_n.val[0] = vld1q_s16(l_ptr); + int16x8_t dst_n_p = vld1q_s16(l_ptr + 1); + + if (n == subband_width - 8) + { + int16_t last = vgetq_lane_s16(dst_n_p, 6); + dst_n_p = vsetq_lane_s16(last, dst_n_p, 7); + } + + dst_n.val[1] = vaddq_s16(dst_n_p, dst_n.val[0]); + dst_n.val[1] = vshrq_n_s16(dst_n.val[1], 1); + dst_n.val[1] = vaddq_s16(dst_n.val[1], h_n); + vst2q_s16(dst_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + dst_ptr += 16; + } + } +} + +static __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +rfx_dwt_2d_decode_block_vert_NEON(INT16* WINPR_RESTRICT l, INT16* WINPR_RESTRICT h, + INT16* WINPR_RESTRICT dst, size_t subband_width) +{ + INT16* l_ptr = l; + INT16* h_ptr = h; + INT16* dst_ptr = dst; + const size_t total_width = subband_width + subband_width; + + /* Even coefficients */ + for (size_t n = 0; n < subband_width; n++) + { + for (size_t x = 0; x < total_width; x += 8) + { + // dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); + int16x8_t l_n = vld1q_s16(l_ptr); + int16x8_t h_n = vld1q_s16(h_ptr); + int16x8_t tmp_n = vaddq_s16(h_n, vdupq_n_s16(1)); + + if (n == 0) + tmp_n = vaddq_s16(tmp_n, h_n); + else + { + int16x8_t h_n_m = vld1q_s16((h_ptr - total_width)); + tmp_n = vaddq_s16(tmp_n, h_n_m); + } + + tmp_n = vshrq_n_s16(tmp_n, 1); + int16x8_t dst_n = vsubq_s16(l_n, tmp_n); + vst1q_s16(dst_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + dst_ptr += 8; + } + + dst_ptr += total_width; + } + + h_ptr = h; + dst_ptr = dst + total_width; + + /* Odd coefficients */ + for (size_t n = 0; n < subband_width; n++) + { + for (size_t x = 0; x < total_width; x += 8) + { + // dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); + int16x8_t h_n = vld1q_s16(h_ptr); + int16x8_t dst_n_m = vld1q_s16(dst_ptr - total_width); + h_n = vshlq_n_s16(h_n, 1); + int16x8_t tmp_n = dst_n_m; + + if (n == subband_width - 1) + tmp_n = vaddq_s16(tmp_n, dst_n_m); + else + { + int16x8_t dst_n_p = vld1q_s16((dst_ptr + total_width)); + tmp_n = vaddq_s16(tmp_n, dst_n_p); + } + + tmp_n = vshrq_n_s16(tmp_n, 1); + int16x8_t dst_n = vaddq_s16(tmp_n, h_n); + vst1q_s16(dst_ptr, dst_n); + h_ptr += 8; + dst_ptr += 8; + } + + dst_ptr += total_width; + } +} + +static __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +rfx_dwt_2d_decode_block_NEON(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT idwt, + size_t subband_width) +{ + INT16 *hl, *lh, *hh, *ll; + INT16 *l_dst, *h_dst; + /* Inverse DWT in horizontal direction, results in 2 sub-bands in L, H order in tmp buffer idwt. + */ + /* The 4 sub-bands are stored in HL(0), LH(1), HH(2), LL(3) order. */ + /* The lower part L uses LL(3) and HL(0). */ + /* The higher part H uses LH(1) and HH(2). */ + ll = buffer + subband_width * subband_width * 3; + hl = buffer; + l_dst = idwt; + rfx_dwt_2d_decode_block_horiz_NEON(ll, hl, l_dst, subband_width); + lh = buffer + subband_width * subband_width; + hh = buffer + subband_width * subband_width * 2; + h_dst = idwt + subband_width * subband_width * 2; + rfx_dwt_2d_decode_block_horiz_NEON(lh, hh, h_dst, subband_width); + /* Inverse DWT in vertical direction, results are stored in original buffer. */ + rfx_dwt_2d_decode_block_vert_NEON(l_dst, h_dst, buffer, subband_width); +} + +static void rfx_dwt_2d_decode_NEON(INT16* buffer, INT16* dwt_buffer) +{ + rfx_dwt_2d_decode_block_NEON(buffer + 3840, dwt_buffer, 8); + rfx_dwt_2d_decode_block_NEON(buffer + 3072, dwt_buffer, 16); + rfx_dwt_2d_decode_block_NEON(buffer, dwt_buffer, 32); +} + +static INLINE void rfx_idwt_extrapolate_horiz_neon(INT16* restrict pLowBand, size_t nLowStep, + const INT16* restrict pHighBand, + size_t nHighStep, INT16* restrict pDstBand, + size_t nDstStep, size_t nLowCount, + size_t nHighCount, size_t nDstCount) +{ + WINPR_ASSERT(pLowBand); + WINPR_ASSERT(pHighBand); + WINPR_ASSERT(pDstBand); + + INT16* l_ptr = pLowBand; + const INT16* h_ptr = pHighBand; + INT16* dst_ptr = pDstBand; + size_t batchSize = (nLowCount + nHighCount) >> 1; + + for (size_t y = 0; y < nDstCount; y++) + { + /* Even coefficients */ + size_t n = 0; + for (; n < batchSize; n += 8) + { + // dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); + int16x8_t l_n = vld1q_s16(l_ptr); + int16x8_t h_n = vld1q_s16(h_ptr); + int16x8_t h_n_m = vld1q_s16(h_ptr - 1); + + if (n == 0) + { + int16_t first = vgetq_lane_s16(h_n_m, 1); + h_n_m = vsetq_lane_s16(first, h_n_m, 0); + } + else if (n == 24) + h_n = vsetq_lane_s16(0, h_n, 7); + + int16x8_t tmp_n = vaddq_s16(h_n, h_n_m); + tmp_n = vaddq_s16(tmp_n, vdupq_n_s16(1)); + tmp_n = vshrq_n_s16(tmp_n, 1); + int16x8_t dst_n = vsubq_s16(l_n, tmp_n); + vst1q_s16(l_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + } + if (n < 32) + *l_ptr -= *(h_ptr - 1); + + l_ptr -= batchSize; + h_ptr -= batchSize; + + /* Odd coefficients */ + n = 0; + for (; n < batchSize; n += 8) + { + // dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); + int16x8_t h_n = vld1q_s16(h_ptr); + h_n = vshlq_n_s16(h_n, 1); + int16x8x2_t dst_n; + dst_n.val[0] = vld1q_s16(l_ptr); + int16x8_t dst_n_p = vld1q_s16(l_ptr + 1); + + if (n == 24) + h_n = vsetq_lane_s16(0, h_n, 7); + + dst_n.val[1] = vaddq_s16(dst_n_p, dst_n.val[0]); + dst_n.val[1] = vshrq_n_s16(dst_n.val[1], 1); + dst_n.val[1] = vaddq_s16(dst_n.val[1], h_n); + vst2q_s16(dst_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + dst_ptr += 16; + } + if (n == 32) + { + h_ptr -= 1; + l_ptr += 1; + } + else + { + *dst_ptr = *l_ptr; + l_ptr += 1; + dst_ptr += 1; + } + } +} + +static INLINE void rfx_idwt_extrapolate_vert_neon(const INT16* restrict pLowBand, size_t nLowStep, + const INT16* restrict pHighBand, size_t nHighStep, + INT16* restrict pDstBand, size_t nDstStep, + size_t nLowCount, size_t nHighCount, + size_t nDstCount) +{ + WINPR_ASSERT(pLowBand); + WINPR_ASSERT(pHighBand); + WINPR_ASSERT(pDstBand); + + const INT16* l_ptr = pLowBand; + const INT16* h_ptr = pHighBand; + INT16* dst_ptr = pDstBand; + size_t batchSize = (nDstCount >> 3) << 3; + size_t forceBandSize = (nLowCount + nHighCount) >> 1; + + /* Even coefficients */ + for (size_t n = 0; n < forceBandSize; n++) + { + for (size_t x = 0; x < batchSize; x += 8) + { + // dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); + int16x8_t l_n = vld1q_s16(l_ptr); + int16x8_t h_n = vld1q_s16((n == 31) ? (h_ptr - nHighStep) : h_ptr); + int16x8_t tmp_n = vaddq_s16(h_n, vdupq_n_s16(1)); + + if (n == 0) + tmp_n = vaddq_s16(tmp_n, h_n); + else if (n < 31) + { + int16x8_t h_n_m = vld1q_s16((h_ptr - nHighStep)); + tmp_n = vaddq_s16(tmp_n, h_n_m); + } + + tmp_n = vshrq_n_s16(tmp_n, 1); + int16x8_t dst_n = vsubq_s16(l_n, tmp_n); + vst1q_s16(dst_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + dst_ptr += 8; + } + + if (nDstCount > batchSize) + { + int16_t h_n = (n == 31) ? *(h_ptr - nHighStep) : *h_ptr; + int16_t tmp_n = h_n + 1; + if (n == 0) + tmp_n += h_n; + else if (n < 31) + tmp_n += *(h_ptr - nHighStep); + tmp_n >>= 1; + *dst_ptr = *l_ptr - tmp_n; + l_ptr += 1; + h_ptr += 1; + dst_ptr += 1; + } + + dst_ptr += nDstStep; + } + + if (forceBandSize < 32) + { + for (size_t x = 0; x < batchSize; x += 8) + { + int16x8_t l_n = vld1q_s16(l_ptr); + int16x8_t h_n = vld1q_s16(h_ptr - nHighStep); + int16x8_t tmp_n = vsubq_s16(l_n, h_n); + vst1q_s16(dst_ptr, tmp_n); + l_ptr += 8; + h_ptr += 8; + dst_ptr += 8; + } + + if (nDstCount > batchSize) + { + *dst_ptr = *l_ptr - *(h_ptr - nHighStep); + l_ptr += 1; + h_ptr += 1; + dst_ptr += 1; + } + } + + h_ptr = pHighBand; + dst_ptr = pDstBand + nDstStep; + + /* Odd coefficients */ + for (size_t n = 0; n < forceBandSize; n++) + { + for (size_t x = 0; x < batchSize; x += 8) + { + // dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); + int16x8_t tmp_n = vld1q_s16(dst_ptr - nDstStep); + if (n == 31) + { + int16x8_t dst_n_p = vld1q_s16(l_ptr); + l_ptr += 8; + tmp_n = vaddq_s16(tmp_n, dst_n_p); + tmp_n = vshrq_n_s16(tmp_n, 1); + } + else + { + int16x8_t dst_n_p = vld1q_s16(dst_ptr + nDstStep); + tmp_n = vaddq_s16(tmp_n, dst_n_p); + tmp_n = vshrq_n_s16(tmp_n, 1); + int16x8_t h_n = vld1q_s16(h_ptr); + h_n = vshlq_n_s16(h_n, 1); + tmp_n = vaddq_s16(tmp_n, h_n); + } + vst1q_s16(dst_ptr, tmp_n); + h_ptr += 8; + dst_ptr += 8; + } + + if (nDstCount > batchSize) + { + int16_t tmp_n = *(dst_ptr - nDstStep); + if (n == 31) + { + int16_t dst_n_p = *l_ptr; + l_ptr += 1; + tmp_n += dst_n_p; + tmp_n >>= 1; + } + else + { + int16_t dst_n_p = *(dst_ptr + nDstStep); + tmp_n += dst_n_p; + tmp_n >>= 1; + int16_t h_n = *h_ptr; + h_n <<= 1; + tmp_n += h_n; + } + *dst_ptr = tmp_n; + h_ptr += 1; + dst_ptr += 1; + } + + dst_ptr += nDstStep; + } +} + +static INLINE size_t prfx_get_band_l_count(size_t level) +{ + return (64 >> level) + 1; +} + +static INLINE size_t prfx_get_band_h_count(size_t level) +{ + if (level == 1) + return (64 >> 1) - 1; + else + return (64 + (1 << (level - 1))) >> level; +} + +static INLINE void rfx_dwt_2d_decode_extrapolate_block_neon(INT16* buffer, INT16* temp, + size_t level) +{ + size_t nDstStepX; + size_t nDstStepY; + INT16 *HL, *LH; + INT16 *HH, *LL; + INT16 *L, *H, *LLx; + + const size_t nBandL = prfx_get_band_l_count(level); + const size_t nBandH = prfx_get_band_h_count(level); + size_t offset = 0; + + WINPR_ASSERT(buffer); + WINPR_ASSERT(temp); + + HL = &buffer[offset]; + offset += (nBandH * nBandL); + LH = &buffer[offset]; + offset += (nBandL * nBandH); + HH = &buffer[offset]; + offset += (nBandH * nBandH); + LL = &buffer[offset]; + nDstStepX = (nBandL + nBandH); + nDstStepY = (nBandL + nBandH); + offset = 0; + L = &temp[offset]; + offset += (nBandL * nDstStepX); + H = &temp[offset]; + LLx = &buffer[0]; + + /* horizontal (LL + HL -> L) */ + rfx_idwt_extrapolate_horiz_neon(LL, nBandL, HL, nBandH, L, nDstStepX, nBandL, nBandH, nBandL); + + /* horizontal (LH + HH -> H) */ + rfx_idwt_extrapolate_horiz_neon(LH, nBandL, HH, nBandH, H, nDstStepX, nBandL, nBandH, nBandH); + + /* vertical (L + H -> LL) */ + rfx_idwt_extrapolate_vert_neon(L, nDstStepX, H, nDstStepX, LLx, nDstStepY, nBandL, nBandH, + nBandL + nBandH); +} + +static void rfx_dwt_2d_extrapolate_decode_neon(INT16* buffer, INT16* temp) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(temp); + rfx_dwt_2d_decode_extrapolate_block_neon(&buffer[3807], temp, 3); + rfx_dwt_2d_decode_extrapolate_block_neon(&buffer[3007], temp, 2); + rfx_dwt_2d_decode_extrapolate_block_neon(&buffer[0], temp, 1); +} +#endif // NEON_INTRINSICS_ENABLED + +void rfx_init_neon(RFX_CONTEXT* context) +{ +#if defined(NEON_INTRINSICS_ENABLED) + if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) + { + DEBUG_RFX("Using NEON optimizations"); + PROFILER_RENAME(context->priv->prof_rfx_ycbcr_to_rgb, "rfx_decode_YCbCr_to_RGB_NEON"); + PROFILER_RENAME(context->priv->prof_rfx_quantization_decode, + "rfx_quantization_decode_NEON"); + PROFILER_RENAME(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode_NEON"); + context->quantization_decode = rfx_quantization_decode_NEON; + context->dwt_2d_decode = rfx_dwt_2d_decode_NEON; + context->dwt_2d_extrapolate_decode = rfx_dwt_2d_extrapolate_decode_neon; + } +#else + WINPR_UNUSED(context); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/rfx_neon.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/rfx_neon.h new file mode 100644 index 0000000000000000000000000000000000000000..472d260bb77298b5d052350a7e73178fe033b36e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/neon/rfx_neon.h @@ -0,0 +1,28 @@ +/* + FreeRDP: A Remote Desktop Protocol Implementation + RemoteFX Codec Library - NEON Optimizations + + Copyright 2011 Martin Fleisz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#ifndef FREERDP_LIB_CODEC_RFX_NEON_H +#define FREERDP_LIB_CODEC_RFX_NEON_H + +#include +#include + +FREERDP_LOCAL void rfx_init_neon(RFX_CONTEXT* context); + +#endif /* FREERDP_LIB_CODEC_RFX_NEON_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/nsc_sse2.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/nsc_sse2.c new file mode 100644 index 0000000000000000000000000000000000000000..e3599888485594d787133e2b3adb742e2060ee26 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/nsc_sse2.c @@ -0,0 +1,402 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * NSCodec Library - SSE2 Optimizations + * + * Copyright 2012 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "../nsc_types.h" +#include "nsc_sse2.h" + +#include "../../core/simd.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include +#include + +#include +#include + +#include +#include +#include + +static inline size_t nsc_encode_next_rgba(UINT32 format, const BYTE* src, const BYTE* palette, + __m128i* r_val, __m128i* g_val, __m128i* b_val, + __m128i* a_val) +{ + switch (format) + { + case PIXEL_FORMAT_BGRX32: + *b_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), + *(src + 8), *(src + 4), *src); + *g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), + *(src + 9), *(src + 5), *(src + 1)); + *r_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), + *(src + 10), *(src + 6), *(src + 2)); + *a_val = _mm_set1_epi16(0xFF); + return 32; + + case PIXEL_FORMAT_BGRA32: + *b_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), + *(src + 8), *(src + 4), *src); + *g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), + *(src + 9), *(src + 5), *(src + 1)); + *r_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), + *(src + 10), *(src + 6), *(src + 2)); + *a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15), + *(src + 11), *(src + 7), *(src + 3)); + return 32; + + case PIXEL_FORMAT_RGBX32: + *r_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), + *(src + 8), *(src + 4), *src); + *g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), + *(src + 9), *(src + 5), *(src + 1)); + *b_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), + *(src + 10), *(src + 6), *(src + 2)); + *a_val = _mm_set1_epi16(0xFF); + return 32; + + case PIXEL_FORMAT_RGBA32: + *r_val = _mm_set_epi16(*(src + 28), *(src + 24), *(src + 20), *(src + 16), *(src + 12), + *(src + 8), *(src + 4), *src); + *g_val = _mm_set_epi16(*(src + 29), *(src + 25), *(src + 21), *(src + 17), *(src + 13), + *(src + 9), *(src + 5), *(src + 1)); + *b_val = _mm_set_epi16(*(src + 30), *(src + 26), *(src + 22), *(src + 18), *(src + 14), + *(src + 10), *(src + 6), *(src + 2)); + *a_val = _mm_set_epi16(*(src + 31), *(src + 27), *(src + 23), *(src + 19), *(src + 15), + *(src + 11), *(src + 7), *(src + 3)); + return 32; + + case PIXEL_FORMAT_BGR24: + *b_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9), + *(src + 6), *(src + 3), *src); + *g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10), + *(src + 7), *(src + 4), *(src + 1)); + *r_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11), + *(src + 8), *(src + 5), *(src + 2)); + *a_val = _mm_set1_epi16(0xFF); + return 24; + + case PIXEL_FORMAT_RGB24: + *r_val = _mm_set_epi16(*(src + 21), *(src + 18), *(src + 15), *(src + 12), *(src + 9), + *(src + 6), *(src + 3), *src); + *g_val = _mm_set_epi16(*(src + 22), *(src + 19), *(src + 16), *(src + 13), *(src + 10), + *(src + 7), *(src + 4), *(src + 1)); + *b_val = _mm_set_epi16(*(src + 23), *(src + 20), *(src + 17), *(src + 14), *(src + 11), + *(src + 8), *(src + 5), *(src + 2)); + *a_val = _mm_set1_epi16(0xFF); + return 24; + + case PIXEL_FORMAT_BGR16: + *b_val = _mm_set_epi16( + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 15)) & 0xF8) | ((*(src + 15)) >> 5)), + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 13)) & 0xF8) | ((*(src + 13)) >> 5)), + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 11)) & 0xF8) | ((*(src + 11)) >> 5)), + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 9)) & 0xF8) | ((*(src + 9)) >> 5)), + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 7)) & 0xF8) | ((*(src + 7)) >> 5)), + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 5)) & 0xF8) | ((*(src + 5)) >> 5)), + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 3)) & 0xF8) | ((*(src + 3)) >> 5)), + WINPR_ASSERTING_INT_CAST(INT16, ((*(src + 1)) & 0xF8) | ((*(src + 1)) >> 5))); + *g_val = + _mm_set_epi16(WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 15)) & 0x07) << 5) | + (((*(src + 14)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 13)) & 0x07) << 5) | + (((*(src + 12)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 11)) & 0x07) << 5) | + (((*(src + 10)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 9)) & 0x07) << 5) | + (((*(src + 8)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 7)) & 0x07) << 5) | + (((*(src + 6)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 5)) & 0x07) << 5) | + (((*(src + 4)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 3)) & 0x07) << 5) | + (((*(src + 2)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 1)) & 0x07) << 5) | + (((*src) & 0xE0) >> 3))); + *r_val = _mm_set_epi16( + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 14)) & 0x1F) << 3) | + (((*(src + 14)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 12)) & 0x1F) << 3) | + (((*(src + 12)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 10)) & 0x1F) << 3) | + (((*(src + 10)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 8)) & 0x1F) << 3) | + (((*(src + 8)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 6)) & 0x1F) << 3) | + (((*(src + 6)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 4)) & 0x1F) << 3) | + (((*(src + 4)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 2)) & 0x1F) << 3) | + (((*(src + 2)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07))); + *a_val = _mm_set1_epi16(0xFF); + return 16; + + case PIXEL_FORMAT_RGB16: + *r_val = + _mm_set_epi16(WINPR_ASSERTING_INT_CAST(INT16, ((src[15] & 0xF8) | (src[15] >> 5))), + WINPR_ASSERTING_INT_CAST(INT16, ((src[13] & 0xF8) | (src[13] >> 5))), + WINPR_ASSERTING_INT_CAST(INT16, ((src[11] & 0xF8) | (src[11] >> 5))), + WINPR_ASSERTING_INT_CAST(INT16, ((src[9] & 0xF8) | (src[9] >> 5))), + WINPR_ASSERTING_INT_CAST(INT16, ((src[7] & 0xF8) | (src[7] >> 5))), + WINPR_ASSERTING_INT_CAST(INT16, ((src[5] & 0xF8) | (src[5] >> 5))), + WINPR_ASSERTING_INT_CAST(INT16, ((src[3] & 0xF8) | (src[3] >> 5))), + WINPR_ASSERTING_INT_CAST(INT16, ((src[1] & 0xF8) | (src[1] >> 5)))); + *g_val = + _mm_set_epi16(WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 15)) & 0x07) << 5) | + (((*(src + 14)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 13)) & 0x07) << 5) | + (((*(src + 12)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 11)) & 0x07) << 5) | + (((*(src + 10)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 9)) & 0x07) << 5) | + (((*(src + 8)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 7)) & 0x07) << 5) | + (((*(src + 6)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 5)) & 0x07) << 5) | + (((*(src + 4)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 3)) & 0x07) << 5) | + (((*(src + 2)) & 0xE0) >> 3)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 1)) & 0x07) << 5) | + (((*src) & 0xE0) >> 3))); + *b_val = _mm_set_epi16( + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 14)) & 0x1F) << 3) | + (((*(src + 14)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 12)) & 0x1F) << 3) | + (((*(src + 12)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 10)) & 0x1F) << 3) | + (((*(src + 10)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 8)) & 0x1F) << 3) | + (((*(src + 8)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 6)) & 0x1F) << 3) | + (((*(src + 6)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 4)) & 0x1F) << 3) | + (((*(src + 4)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*(src + 2)) & 0x1F) << 3) | + (((*(src + 2)) >> 2) & 0x07)), + WINPR_ASSERTING_INT_CAST(INT16, (((*src) & 0x1F) << 3) | (((*src) >> 2) & 0x07))); + *a_val = _mm_set1_epi16(0xFF); + return 16; + + case PIXEL_FORMAT_A4: + { + BYTE idx[8] = { 0 }; + + for (int shift = 7; shift >= 0; shift--) + { + idx[shift] = ((*src) >> shift) & 1; + idx[shift] |= (((*(src + 1)) >> shift) & 1) << 1; + idx[shift] |= (((*(src + 2)) >> shift) & 1) << 2; + idx[shift] |= (((*(src + 3)) >> shift) & 1) << 3; + idx[shift] *= 3; + } + + *r_val = + _mm_set_epi16(palette[idx[0]], palette[idx[1]], palette[idx[2]], palette[idx[3]], + palette[idx[4]], palette[idx[5]], palette[idx[6]], palette[idx[7]]); + *g_val = _mm_set_epi16(palette[idx[0] + 1], palette[idx[1] + 1], palette[idx[2] + 1], + palette[idx[3] + 1], palette[idx[4] + 1], palette[idx[5] + 1], + palette[idx[6] + 1], palette[idx[7] + 1]); + *b_val = _mm_set_epi16(palette[idx[0] + 2], palette[idx[1] + 2], palette[idx[2] + 2], + palette[idx[3] + 2], palette[idx[4] + 2], palette[idx[5] + 2], + palette[idx[6] + 2], palette[idx[7] + 2]); + *a_val = _mm_set1_epi16(0xFF); + return 4; + } + + case PIXEL_FORMAT_RGB8: + { + *r_val = _mm_set_epi16(palette[(*(src + 7ULL)) * 3ULL], palette[(*(src + 6ULL)) * 3ULL], + palette[(*(src + 5ULL)) * 3ULL], palette[(*(src + 4ULL)) * 3ULL], + palette[(*(src + 3ULL)) * 3ULL], palette[(*(src + 2ULL)) * 3ULL], + palette[(*(src + 1ULL)) * 3ULL], palette[(*src) * 3ULL]); + *g_val = _mm_set_epi16( + palette[(*(src + 7ULL)) * 3ULL + 1ULL], palette[(*(src + 6ULL)) * 3ULL + 1ULL], + palette[(*(src + 5ULL)) * 3ULL + 1ULL], palette[(*(src + 4ULL)) * 3ULL + 1ULL], + palette[(*(src + 3ULL)) * 3ULL + 1ULL], palette[(*(src + 2ULL)) * 3ULL + 1ULL], + palette[(*(src + 1ULL)) * 3ULL + 1ULL], palette[(*src) * 3ULL + 1ULL]); + *b_val = _mm_set_epi16( + palette[(*(src + 7ULL)) * 3ULL + 2ULL], palette[(*(src + 6ULL)) * 3ULL + 2ULL], + palette[(*(src + 5ULL)) * 3ULL + 2ULL], palette[(*(src + 4ULL)) * 3ULL + 2ULL], + palette[(*(src + 3ULL)) * 3ULL + 2ULL], palette[(*(src + 2ULL)) * 3ULL + 2ULL], + palette[(*(src + 1ULL)) * 3ULL + 2ULL], palette[(*src) * 3ULL + 2ULL]); + *a_val = _mm_set1_epi16(0xFF); + return 8; + } + + default: + return 0; + } +} + +static BOOL nsc_encode_argb_to_aycocg_sse2(NSC_CONTEXT* context, const BYTE* data, UINT32 scanline) +{ + size_t y = 0; + + if (!context || !data || (scanline == 0)) + return FALSE; + + const UINT16 tempWidth = ROUND_UP_TO(context->width, 8); + const UINT16 rw = (context->ChromaSubsamplingLevel > 0 ? tempWidth : context->width); + + const BYTE ccl = WINPR_ASSERTING_INT_CAST(BYTE, context->ColorLossLevel); + + for (; y < context->height; y++) + { + const BYTE* src = data + (context->height - 1 - y) * scanline; + BYTE* yplane = context->priv->PlaneBuffers[0] + y * rw; + BYTE* coplane = context->priv->PlaneBuffers[1] + y * rw; + BYTE* cgplane = context->priv->PlaneBuffers[2] + y * rw; + BYTE* aplane = context->priv->PlaneBuffers[3] + y * context->width; + + for (UINT16 x = 0; x < context->width; x += 8) + { + __m128i r_val = { 0 }; + __m128i g_val = { 0 }; + __m128i b_val = { 0 }; + __m128i a_val = { 0 }; + + const size_t rc = nsc_encode_next_rgba(context->format, src, context->palette, &r_val, + &g_val, &b_val, &a_val); + src += rc; + + __m128i y_val = _mm_srai_epi16(r_val, 2); + y_val = _mm_add_epi16(y_val, _mm_srai_epi16(g_val, 1)); + y_val = _mm_add_epi16(y_val, _mm_srai_epi16(b_val, 2)); + __m128i co_val = _mm_sub_epi16(r_val, b_val); + co_val = _mm_srai_epi16(co_val, ccl); + __m128i cg_val = _mm_sub_epi16(g_val, _mm_srai_epi16(r_val, 1)); + cg_val = _mm_sub_epi16(cg_val, _mm_srai_epi16(b_val, 1)); + cg_val = _mm_srai_epi16(cg_val, ccl); + y_val = _mm_packus_epi16(y_val, y_val); + _mm_storeu_si128((__m128i*)yplane, y_val); + co_val = _mm_packs_epi16(co_val, co_val); + _mm_storeu_si128((__m128i*)coplane, co_val); + cg_val = _mm_packs_epi16(cg_val, cg_val); + _mm_storeu_si128((__m128i*)cgplane, cg_val); + a_val = _mm_packus_epi16(a_val, a_val); + _mm_storeu_si128((__m128i*)aplane, a_val); + yplane += 8; + coplane += 8; + cgplane += 8; + aplane += 8; + } + + if (context->ChromaSubsamplingLevel > 0 && (context->width % 2) == 1) + { + context->priv->PlaneBuffers[0][y * rw + context->width] = + context->priv->PlaneBuffers[0][y * rw + context->width - 1]; + context->priv->PlaneBuffers[1][y * rw + context->width] = + context->priv->PlaneBuffers[1][y * rw + context->width - 1]; + context->priv->PlaneBuffers[2][y * rw + context->width] = + context->priv->PlaneBuffers[2][y * rw + context->width - 1]; + } + } + + if (context->ChromaSubsamplingLevel > 0 && (y % 2) == 1) + { + BYTE* yplane = context->priv->PlaneBuffers[0] + y * rw; + BYTE* coplane = context->priv->PlaneBuffers[1] + y * rw; + BYTE* cgplane = context->priv->PlaneBuffers[2] + y * rw; + CopyMemory(yplane, yplane - rw, rw); + CopyMemory(coplane, coplane - rw, rw); + CopyMemory(cgplane, cgplane - rw, rw); + } + + return TRUE; +} + +static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context) +{ + BYTE* co_dst = NULL; + BYTE* cg_dst = NULL; + INT8* co_src0 = NULL; + INT8* co_src1 = NULL; + INT8* cg_src0 = NULL; + INT8* cg_src1 = NULL; + UINT32 tempWidth = 0; + UINT32 tempHeight = 0; + __m128i t; + __m128i val; + __m128i mask = _mm_set1_epi16(0xFF); + tempWidth = ROUND_UP_TO(context->width, 8); + tempHeight = ROUND_UP_TO(context->height, 2); + + for (size_t y = 0; y < tempHeight >> 1; y++) + { + co_dst = context->priv->PlaneBuffers[1] + y * (tempWidth >> 1); + cg_dst = context->priv->PlaneBuffers[2] + y * (tempWidth >> 1); + co_src0 = (INT8*)context->priv->PlaneBuffers[1] + (y << 1) * tempWidth; + co_src1 = co_src0 + tempWidth; + cg_src0 = (INT8*)context->priv->PlaneBuffers[2] + (y << 1) * tempWidth; + cg_src1 = cg_src0 + tempWidth; + + for (UINT32 x = 0; x < tempWidth >> 1; x += 8) + { + t = _mm_loadu_si128((__m128i*)co_src0); + t = _mm_avg_epu8(t, _mm_loadu_si128((__m128i*)co_src1)); + val = _mm_and_si128(_mm_srli_si128(t, 1), mask); + val = _mm_avg_epu16(val, _mm_and_si128(t, mask)); + val = _mm_packus_epi16(val, val); + _mm_storeu_si128((__m128i*)co_dst, val); + co_dst += 8; + co_src0 += 16; + co_src1 += 16; + t = _mm_loadu_si128((__m128i*)cg_src0); + t = _mm_avg_epu8(t, _mm_loadu_si128((__m128i*)cg_src1)); + val = _mm_and_si128(_mm_srli_si128(t, 1), mask); + val = _mm_avg_epu16(val, _mm_and_si128(t, mask)); + val = _mm_packus_epi16(val, val); + _mm_storeu_si128((__m128i*)cg_dst, val); + cg_dst += 8; + cg_src0 += 16; + cg_src1 += 16; + } + } +} + +static BOOL nsc_encode_sse2(NSC_CONTEXT* context, const BYTE* data, UINT32 scanline) +{ + if (!nsc_encode_argb_to_aycocg_sse2(context, data, scanline)) + return FALSE; + + if (context->ChromaSubsamplingLevel > 0) + nsc_encode_subsampling_sse2(context); + + return TRUE; +} +#endif + +void nsc_init_sse2(NSC_CONTEXT* context) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + if (!IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE)) + return; + + PROFILER_RENAME(context->priv->prof_nsc_encode, "nsc_encode_sse2") + context->encode = nsc_encode_sse2; +#else + WINPR_UNUSED(context); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/nsc_sse2.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/nsc_sse2.h new file mode 100644 index 0000000000000000000000000000000000000000..8b74cabf8ddd44a1d6ac7dd2bcc9397b5d551a29 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/nsc_sse2.h @@ -0,0 +1,28 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * NSCodec Library - SSE2 Optimizations + * + * Copyright 2012 Vic Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CODEC_NSC_SSE2_H +#define FREERDP_LIB_CODEC_NSC_SSE2_H + +#include +#include + +FREERDP_LOCAL void nsc_init_sse2(NSC_CONTEXT* context); + +#endif /* FREERDP_LIB_CODEC_NSC_SSE2_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/rfx_sse2.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/rfx_sse2.c new file mode 100644 index 0000000000000000000000000000000000000000..af0a6b50d36b776de2f9154f8105106f1ed4296c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/rfx_sse2.c @@ -0,0 +1,470 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX Codec Library - SSE2 Optimizations + * + * Copyright 2011 Stephen Erisman + * Copyright 2011 Norbert Federa + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "../rfx_types.h" +#include "rfx_sse2.h" + +#include "../../core/simd.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include +#include +#include + +#include +#include + +#ifdef _MSC_VER +#define __attribute__(...) +#endif + +#define CACHE_LINE_BYTES 64 + +#ifndef __clang__ +#define ATTRIBUTES __gnu_inline__, __always_inline__, __artificial__ +#else +#define ATTRIBUTES __gnu_inline__, __always_inline__ +#endif + +static __inline void __attribute__((ATTRIBUTES)) +mm_prefetch_buffer(char* WINPR_RESTRICT buffer, size_t num_bytes) +{ + __m128i* buf = (__m128i*)buffer; + + for (size_t i = 0; i < (num_bytes / sizeof(__m128i)); i += (CACHE_LINE_BYTES / sizeof(__m128i))) + { + _mm_prefetch((char*)(&buf[i]), _MM_HINT_NTA); + } +} + +/* rfx_decode_ycbcr_to_rgb_sse2 code now resides in the primitives library. */ +/* rfx_encode_rgb_to_ycbcr_sse2 code now resides in the primitives library. */ + +static __inline void __attribute__((ATTRIBUTES)) +rfx_quantization_decode_block_sse2(INT16* WINPR_RESTRICT buffer, const size_t buffer_size, + const UINT32 factor) +{ + __m128i* ptr = (__m128i*)buffer; + const __m128i* buf_end = (__m128i*)(buffer + buffer_size); + + if (factor == 0) + return; + + do + { + const __m128i la = _mm_load_si128(ptr); + const __m128i a = _mm_slli_epi16(la, WINPR_ASSERTING_INT_CAST(int, factor)); + + _mm_store_si128(ptr, a); + ptr++; + } while (ptr < buf_end); +} + +static void rfx_quantization_decode_sse2(INT16* WINPR_RESTRICT buffer, + const UINT32* WINPR_RESTRICT quantVals) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(quantVals); + + mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16)); + rfx_quantization_decode_block_sse2(&buffer[0], 1024, quantVals[8] - 1); /* HL1 */ + rfx_quantization_decode_block_sse2(&buffer[1024], 1024, quantVals[7] - 1); /* LH1 */ + rfx_quantization_decode_block_sse2(&buffer[2048], 1024, quantVals[9] - 1); /* HH1 */ + rfx_quantization_decode_block_sse2(&buffer[3072], 256, quantVals[5] - 1); /* HL2 */ + rfx_quantization_decode_block_sse2(&buffer[3328], 256, quantVals[4] - 1); /* LH2 */ + rfx_quantization_decode_block_sse2(&buffer[3584], 256, quantVals[6] - 1); /* HH2 */ + rfx_quantization_decode_block_sse2(&buffer[3840], 64, quantVals[2] - 1); /* HL3 */ + rfx_quantization_decode_block_sse2(&buffer[3904], 64, quantVals[1] - 1); /* LH3 */ + rfx_quantization_decode_block_sse2(&buffer[3968], 64, quantVals[3] - 1); /* HH3 */ + rfx_quantization_decode_block_sse2(&buffer[4032], 64, quantVals[0] - 1); /* LL3 */ +} + +static __inline void __attribute__((ATTRIBUTES)) +rfx_quantization_encode_block_sse2(INT16* WINPR_RESTRICT buffer, const unsigned buffer_size, + const INT16 factor) +{ + __m128i* ptr = (__m128i*)buffer; + const __m128i* buf_end = (const __m128i*)(buffer + buffer_size); + + if (factor == 0) + return; + + const __m128i half = _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(INT16, 1 << (factor - 1))); + + do + { + const __m128i la = _mm_load_si128(ptr); + __m128i a = _mm_add_epi16(la, half); + a = _mm_srai_epi16(a, factor); + _mm_store_si128(ptr, a); + ptr++; + } while (ptr < buf_end); +} + +static void rfx_quantization_encode_sse2(INT16* WINPR_RESTRICT buffer, + const UINT32* WINPR_RESTRICT quantization_values) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(quantization_values); + for (size_t x = 0; x < 10; x++) + { + WINPR_ASSERT(quantization_values[x] >= 6); + WINPR_ASSERT(quantization_values[x] <= INT16_MAX + 6); + } + + mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16)); + rfx_quantization_encode_block_sse2( + buffer, 1024, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[8] - 6)); /* HL1 */ + rfx_quantization_encode_block_sse2( + buffer + 1024, 1024, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[7] - 6)); /* LH1 */ + rfx_quantization_encode_block_sse2( + buffer + 2048, 1024, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[9] - 6)); /* HH1 */ + rfx_quantization_encode_block_sse2( + buffer + 3072, 256, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[5] - 6)); /* HL2 */ + rfx_quantization_encode_block_sse2( + buffer + 3328, 256, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[4] - 6)); /* LH2 */ + rfx_quantization_encode_block_sse2( + buffer + 3584, 256, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[6] - 6)); /* HH2 */ + rfx_quantization_encode_block_sse2( + buffer + 3840, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[2] - 6)); /* HL3 */ + rfx_quantization_encode_block_sse2( + buffer + 3904, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[1] - 6)); /* LH3 */ + rfx_quantization_encode_block_sse2( + buffer + 3968, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[3] - 6)); /* HH3 */ + rfx_quantization_encode_block_sse2( + buffer + 4032, 64, WINPR_ASSERTING_INT_CAST(INT16, quantization_values[0] - 6)); /* LL3 */ + rfx_quantization_encode_block_sse2(buffer, 4096, 5); +} + +static __inline void __attribute__((ATTRIBUTES)) +rfx_dwt_2d_decode_block_horiz_sse2(INT16* WINPR_RESTRICT l, INT16* WINPR_RESTRICT h, + INT16* WINPR_RESTRICT dst, size_t subband_width) +{ + INT16* l_ptr = l; + INT16* h_ptr = h; + INT16* dst_ptr = dst; + int first = 0; + int last = 0; + __m128i dst1; + __m128i dst2; + + for (size_t y = 0; y < subband_width; y++) + { + /* Even coefficients */ + for (size_t n = 0; n < subband_width; n += 8) + { + /* dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); */ + __m128i l_n = _mm_load_si128((__m128i*)l_ptr); + __m128i h_n = _mm_load_si128((__m128i*)h_ptr); + __m128i h_n_m = _mm_loadu_si128((__m128i*)(h_ptr - 1)); + + if (n == 0) + { + first = _mm_extract_epi16(h_n_m, 1); + h_n_m = _mm_insert_epi16(h_n_m, first, 0); + } + + __m128i tmp_n = _mm_add_epi16(h_n, h_n_m); + tmp_n = _mm_add_epi16(tmp_n, _mm_set1_epi16(1)); + tmp_n = _mm_srai_epi16(tmp_n, 1); + const __m128i dst_n = _mm_sub_epi16(l_n, tmp_n); + _mm_store_si128((__m128i*)l_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + } + + l_ptr -= subband_width; + h_ptr -= subband_width; + + /* Odd coefficients */ + for (size_t n = 0; n < subband_width; n += 8) + { + /* dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); */ + __m128i h_n = _mm_load_si128((__m128i*)h_ptr); + h_n = _mm_slli_epi16(h_n, 1); + __m128i dst_n = _mm_load_si128((__m128i*)(l_ptr)); + __m128i dst_n_p = _mm_loadu_si128((__m128i*)(l_ptr + 1)); + + if (n == subband_width - 8) + { + last = _mm_extract_epi16(dst_n_p, 6); + dst_n_p = _mm_insert_epi16(dst_n_p, last, 7); + } + + __m128i tmp_n = _mm_add_epi16(dst_n_p, dst_n); + tmp_n = _mm_srai_epi16(tmp_n, 1); + tmp_n = _mm_add_epi16(tmp_n, h_n); + dst1 = _mm_unpacklo_epi16(dst_n, tmp_n); + dst2 = _mm_unpackhi_epi16(dst_n, tmp_n); + _mm_store_si128((__m128i*)dst_ptr, dst1); + _mm_store_si128((__m128i*)(dst_ptr + 8), dst2); + l_ptr += 8; + h_ptr += 8; + dst_ptr += 16; + } + } +} + +static __inline void __attribute__((ATTRIBUTES)) +rfx_dwt_2d_decode_block_vert_sse2(INT16* WINPR_RESTRICT l, INT16* WINPR_RESTRICT h, + INT16* WINPR_RESTRICT dst, size_t subband_width) +{ + INT16* l_ptr = l; + INT16* h_ptr = h; + INT16* dst_ptr = dst; + const size_t total_width = subband_width + subband_width; + + /* Even coefficients */ + for (size_t n = 0; n < subband_width; n++) + { + for (size_t x = 0; x < total_width; x += 8) + { + /* dst[2n] = l[n] - ((h[n-1] + h[n] + 1) >> 1); */ + const __m128i l_n = _mm_load_si128((__m128i*)l_ptr); + const __m128i h_n = _mm_load_si128((__m128i*)h_ptr); + __m128i tmp_n = _mm_add_epi16(h_n, _mm_set1_epi16(1)); + + if (n == 0) + tmp_n = _mm_add_epi16(tmp_n, h_n); + else + { + const __m128i h_n_m = _mm_loadu_si128((__m128i*)(h_ptr - total_width)); + tmp_n = _mm_add_epi16(tmp_n, h_n_m); + } + + tmp_n = _mm_srai_epi16(tmp_n, 1); + const __m128i dst_n = _mm_sub_epi16(l_n, tmp_n); + _mm_store_si128((__m128i*)dst_ptr, dst_n); + l_ptr += 8; + h_ptr += 8; + dst_ptr += 8; + } + + dst_ptr += total_width; + } + + h_ptr = h; + dst_ptr = dst + total_width; + + /* Odd coefficients */ + for (size_t n = 0; n < subband_width; n++) + { + for (size_t x = 0; x < total_width; x += 8) + { + /* dst[2n + 1] = (h[n] << 1) + ((dst[2n] + dst[2n + 2]) >> 1); */ + __m128i h_n = _mm_load_si128((__m128i*)h_ptr); + __m128i dst_n_m = _mm_load_si128((__m128i*)(dst_ptr - total_width)); + h_n = _mm_slli_epi16(h_n, 1); + __m128i tmp_n = dst_n_m; + + if (n == subband_width - 1) + tmp_n = _mm_add_epi16(tmp_n, dst_n_m); + else + { + const __m128i dst_n_p = _mm_loadu_si128((__m128i*)(dst_ptr + total_width)); + tmp_n = _mm_add_epi16(tmp_n, dst_n_p); + } + + tmp_n = _mm_srai_epi16(tmp_n, 1); + const __m128i dst_n = _mm_add_epi16(tmp_n, h_n); + _mm_store_si128((__m128i*)dst_ptr, dst_n); + h_ptr += 8; + dst_ptr += 8; + } + + dst_ptr += total_width; + } +} + +static __inline void __attribute__((ATTRIBUTES)) +rfx_dwt_2d_decode_block_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT idwt, + size_t subband_width) +{ + mm_prefetch_buffer((char*)idwt, 4ULL * subband_width * sizeof(INT16)); + /* Inverse DWT in horizontal direction, results in 2 sub-bands in L, H order in tmp buffer idwt. + */ + /* The 4 sub-bands are stored in HL(0), LH(1), HH(2), LL(3) order. */ + /* The lower part L uses LL(3) and HL(0). */ + /* The higher part H uses LH(1) and HH(2). */ + INT16* ll = buffer + 3ULL * subband_width * subband_width; + INT16* hl = buffer; + INT16* l_dst = idwt; + rfx_dwt_2d_decode_block_horiz_sse2(ll, hl, l_dst, subband_width); + INT16* lh = buffer + 1ULL * subband_width * subband_width; + INT16* hh = buffer + 2ULL * subband_width * subband_width; + INT16* h_dst = idwt + 2ULL * subband_width * subband_width; + rfx_dwt_2d_decode_block_horiz_sse2(lh, hh, h_dst, subband_width); + /* Inverse DWT in vertical direction, results are stored in original buffer. */ + rfx_dwt_2d_decode_block_vert_sse2(l_dst, h_dst, buffer, subband_width); +} + +static void rfx_dwt_2d_decode_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(dwt_buffer); + + mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16)); + rfx_dwt_2d_decode_block_sse2(&buffer[3840], dwt_buffer, 8); + rfx_dwt_2d_decode_block_sse2(&buffer[3072], dwt_buffer, 16); + rfx_dwt_2d_decode_block_sse2(&buffer[0], dwt_buffer, 32); +} + +static __inline void __attribute__((ATTRIBUTES)) +rfx_dwt_2d_encode_block_vert_sse2(INT16* WINPR_RESTRICT src, INT16* WINPR_RESTRICT l, + INT16* WINPR_RESTRICT h, size_t subband_width) +{ + const size_t total_width = subband_width << 1; + + for (size_t n = 0; n < subband_width; n++) + { + for (size_t x = 0; x < total_width; x += 8) + { + __m128i src_2n = _mm_load_si128((__m128i*)src); + __m128i src_2n_1 = _mm_load_si128((__m128i*)(src + total_width)); + __m128i src_2n_2 = src_2n; + + if (n < subband_width - 1) + src_2n_2 = _mm_load_si128((__m128i*)(src + 2ULL * total_width)); + + /* h[n] = (src[2n + 1] - ((src[2n] + src[2n + 2]) >> 1)) >> 1 */ + __m128i h_n = _mm_add_epi16(src_2n, src_2n_2); + h_n = _mm_srai_epi16(h_n, 1); + h_n = _mm_sub_epi16(src_2n_1, h_n); + h_n = _mm_srai_epi16(h_n, 1); + _mm_store_si128((__m128i*)h, h_n); + + __m128i h_n_m = h_n; + if (n != 0) + h_n_m = _mm_load_si128((__m128i*)(h - total_width)); + + /* l[n] = src[2n] + ((h[n - 1] + h[n]) >> 1) */ + __m128i l_n = _mm_add_epi16(h_n_m, h_n); + l_n = _mm_srai_epi16(l_n, 1); + l_n = _mm_add_epi16(l_n, src_2n); + _mm_store_si128((__m128i*)l, l_n); + src += 8; + l += 8; + h += 8; + } + + src += total_width; + } +} + +static __inline void __attribute__((ATTRIBUTES)) +rfx_dwt_2d_encode_block_horiz_sse2(INT16* WINPR_RESTRICT src, INT16* WINPR_RESTRICT l, + INT16* WINPR_RESTRICT h, size_t subband_width) +{ + for (size_t y = 0; y < subband_width; y++) + { + for (size_t n = 0; n < subband_width; n += 8) + { + /* The following 3 Set operations consumes more than half of the total DWT processing + * time! */ + const INT16 src16 = (INT16)(((n + 8) == subband_width) ? src[14] : src[16]); + __m128i src_2n = + _mm_set_epi16(src[14], src[12], src[10], src[8], src[6], src[4], src[2], src[0]); + __m128i src_2n_1 = + _mm_set_epi16(src[15], src[13], src[11], src[9], src[7], src[5], src[3], src[1]); + __m128i src_2n_2 = + _mm_set_epi16(src16, src[14], src[12], src[10], src[8], src[6], src[4], src[2]); + /* h[n] = (src[2n + 1] - ((src[2n] + src[2n + 2]) >> 1)) >> 1 */ + __m128i h_n = _mm_add_epi16(src_2n, src_2n_2); + h_n = _mm_srai_epi16(h_n, 1); + h_n = _mm_sub_epi16(src_2n_1, h_n); + h_n = _mm_srai_epi16(h_n, 1); + _mm_store_si128((__m128i*)h, h_n); + __m128i h_n_m = _mm_loadu_si128((__m128i*)(h - 1)); + + if (n == 0) + { + int first = _mm_extract_epi16(h_n_m, 1); + h_n_m = _mm_insert_epi16(h_n_m, first, 0); + } + + /* l[n] = src[2n] + ((h[n - 1] + h[n]) >> 1) */ + __m128i l_n = _mm_add_epi16(h_n_m, h_n); + l_n = _mm_srai_epi16(l_n, 1); + l_n = _mm_add_epi16(l_n, src_2n); + _mm_store_si128((__m128i*)l, l_n); + src += 16; + l += 8; + h += 8; + } + } +} + +static __inline void __attribute__((ATTRIBUTES)) +rfx_dwt_2d_encode_block_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt, + size_t subband_width) +{ + mm_prefetch_buffer((char*)dwt, 4ULL * subband_width * sizeof(INT16)); + /* DWT in vertical direction, results in 2 sub-bands in L, H order in tmp buffer dwt. */ + INT16* l_src = dwt; + INT16* h_src = dwt + 2ULL * subband_width * subband_width; + rfx_dwt_2d_encode_block_vert_sse2(buffer, l_src, h_src, subband_width); + /* DWT in horizontal direction, results in 4 sub-bands in HL(0), LH(1), HH(2), LL(3) order, + * stored in original buffer. */ + /* The lower part L generates LL(3) and HL(0). */ + /* The higher part H generates LH(1) and HH(2). */ + INT16* ll = buffer + 3ULL * subband_width * subband_width; + INT16* hl = buffer; + INT16* lh = buffer + 1ULL * subband_width * subband_width; + INT16* hh = buffer + 2ULL * subband_width * subband_width; + rfx_dwt_2d_encode_block_horiz_sse2(l_src, ll, hl, subband_width); + rfx_dwt_2d_encode_block_horiz_sse2(h_src, lh, hh, subband_width); +} + +static void rfx_dwt_2d_encode_sse2(INT16* WINPR_RESTRICT buffer, INT16* WINPR_RESTRICT dwt_buffer) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(dwt_buffer); + + mm_prefetch_buffer((char*)buffer, 4096 * sizeof(INT16)); + rfx_dwt_2d_encode_block_sse2(buffer, dwt_buffer, 32); + rfx_dwt_2d_encode_block_sse2(buffer + 3072, dwt_buffer, 16); + rfx_dwt_2d_encode_block_sse2(buffer + 3840, dwt_buffer, 8); +} +#endif + +void rfx_init_sse2(RFX_CONTEXT* context) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + if (!IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE)) + return; + + PROFILER_RENAME(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode_sse2") + PROFILER_RENAME(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode_sse2") + PROFILER_RENAME(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode_sse2") + PROFILER_RENAME(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode_sse2") + context->quantization_decode = rfx_quantization_decode_sse2; + context->quantization_encode = rfx_quantization_encode_sse2; + context->dwt_2d_decode = rfx_dwt_2d_decode_sse2; + context->dwt_2d_encode = rfx_dwt_2d_encode_sse2; +#else + WINPR_UNUSED(context); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/rfx_sse2.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/rfx_sse2.h new file mode 100644 index 0000000000000000000000000000000000000000..d15c1854d33fce2e4affd09d288fc058143b185c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/sse/rfx_sse2.h @@ -0,0 +1,28 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RemoteFX Codec Library - SSE2 Optimizations + * + * Copyright 2011 Stephen Erisman + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CODEC_RFX_SSE2_H +#define FREERDP_LIB_CODEC_RFX_SSE2_H + +#include +#include + +FREERDP_LOCAL void rfx_init_sse2(RFX_CONTEXT* context); + +#endif /* FREERDP_LIB_CODEC_RFX_SSE2_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..eb9f1ff7fa5f6df3b5ae2f4571a32ac98bd62a81 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/CMakeLists.txt @@ -0,0 +1,47 @@ +set(MODULE_NAME "TestFreeRDPCodec") +set(MODULE_PREFIX "TEST_FREERDP_CODEC") + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(DRIVER ${MODULE_NAME}.c) + +set(TESTS + TestFreeRDPRegion.c + TestFreeRDPCodecZGfx.c + TestFreeRDPCodecPlanar.c + TestFreeRDPCodecCopy.c + TestFreeRDPCodecClear.c + TestFreeRDPCodecInterleaved.c + TestFreeRDPCodecProgressive.c + TestFreeRDPCodecRemoteFX.c +) + +if(NOT BUILD_TESTING_NO_H264) + list(APPEND TESTS TestFreeRDPCodecH264.c) +endif() + +if(BUILD_TESTING_INTERNAL) + list(APPEND TESTS TestFreeRDPCodecMppc.c TestFreeRDPCodecNCrush.c TestFreeRDPCodecXCrush.c) +endif() + +create_test_sourcelist(SRCS ${DRIVER} ${TESTS}) + +add_compile_definitions(CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") +add_compile_definitions(CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}") +add_executable(${MODULE_NAME} ${SRCS}) + +target_link_libraries(${MODULE_NAME} freerdp winpr) + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Test") + +set(FUZZERS TestFuzzCodecs.c) + +include(AddFuzzerTest) +add_fuzzer_test("${FUZZERS}" "freerdp winpr") diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecClear.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecClear.c new file mode 100644 index 0000000000000000000000000000000000000000..7bb3a9d5479d5bda35858209d5068c72daeb7a55 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecClear.c @@ -0,0 +1,91 @@ +#include +#include +#include + +#include + +WINPR_PRAGMA_DIAG_PUSH +WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR +/* [MS-RDPEGFX] 4.1.1.1 Example 1 */ +static const BYTE PREPARE_CLEAR_EXAMPLE_1[] = "\x03\xc3\x11\x00"; +static const BYTE TEST_CLEAR_EXAMPLE_1[] = "\x03\xc3\x11\x00"; +WINPR_PRAGMA_DIAG_POP + +/* [MS-RDPEGFX] 4.1.1.1 Example 2 */ +static const BYTE TEST_CLEAR_EXAMPLE_2[] = + "\x00\x0d\x00\x00\x00\x00\x00\x00\x00\x00\x82\x00\x00\x00\x00\x00" + "\x00\x00\x4e\x00\x11\x00\x75\x00\x00\x00\x02\x0e\xff\xff\xff\x00" + "\x00\x00\xdb\xff\xff\x00\x3a\x90\xff\xb6\x66\x66\xb6\xff\xb6\x66" + "\x00\x90\xdb\xff\x00\x00\x3a\xdb\x90\x3a\x3a\x90\xdb\x66\x00\x00" + "\xff\xff\xb6\x64\x64\x64\x11\x04\x11\x4c\x11\x4c\x11\x4c\x11\x4c" + "\x11\x4c\x00\x47\x13\x00\x01\x01\x04\x00\x01\x00\x00\x47\x16\x00" + "\x11\x02\x00\x47\x29\x00\x11\x01\x00\x49\x0a\x00\x01\x00\x04\x00" + "\x01\x00\x00\x4a\x0a\x00\x09\x00\x01\x00\x00\x47\x05\x00\x01\x01" + "\x1c\x00\x01\x00\x11\x4c\x11\x4c\x11\x4c\x00\x47\x0d\x4d\x00\x4d"; + +/* [MS-RDPEGFX] 4.1.1.1 Example 3 */ +static const BYTE TEST_CLEAR_EXAMPLE_3[] = + "\x00\xdf\x0e\x00\x00\x00\x8b\x00\x00\x00\x00\x00\x00\x00\xfe\xfe" + "\xfe\xff\x80\x05\xff\xff\xff\x40\xfe\xfe\xfe\x40\x00\x00\x3f\x00" + "\x03\x00\x0b\x00\xfe\xfe\xfe\xc5\xd0\xc6\xd0\xc7\xd0\x68\xd4\x69" + "\xd4\x6a\xd4\x6b\xd4\x6c\xd4\x6d\xd4\x1a\xd4\x1a\xd4\xa6\xd0\x6e" + "\xd4\x6f\xd4\x70\xd4\x71\xd4\x72\xd4\x73\xd4\x74\xd4\x21\xd4\x22" + "\xd4\x23\xd4\x24\xd4\x25\xd4\xd9\xd0\xda\xd0\xdb\xd0\xc5\xd0\xc5" + "\xd0\xdc\xd0\xc2\xd0\x21\xd4\x22\xd4\x23\xd4\x24\xd4\x25\xd4\xc9" + "\xd0\xca\xd0\x5a\xd4\x2b\xd1\x28\xd1\x2c\xd1\x75\xd4\x27\xd4\x28" + "\xd4\x29\xd4\x2a\xd4\x1a\xd4\x1a\xd4\x1a\xd4\xb7\xd0\xb8\xd0\xb9" + "\xd0\xba\xd0\xbb\xd0\xbc\xd0\xbd\xd0\xbe\xd0\xbf\xd0\xc0\xd0\xc1" + "\xd0\xc2\xd0\xc3\xd0\xc4\xd0"; + +/* [MS-RDPEGFX] 4.1.1.1 Example 4 */ +static const BYTE TEST_CLEAR_EXAMPLE_4[] = + "\x01\x0b\x78\x00\x00\x00\x00\x00\x46\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x06\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x0f\xff\xff\xff" + "\xff\xff\xff\xff\xff\xff\xb6\xff\xff\xff\xff\xff\xff\xff\xff\xff" + "\xb6\x66\xff\xff\xff\xff\xff\xff\xff\xb6\x66\xdb\x90\x3a\xff\xff" + "\xb6\xff\xff\xff\xff\xff\xff\xff\xff\xff\x46\x91\x47\x91\x48\x91" + "\x49\x91\x4a\x91\x1b\x91"; + +static BOOL test_ClearDecompressExample(UINT32 nr, UINT32 width, UINT32 height, + const BYTE* pSrcData, const UINT32 SrcSize) +{ + BOOL rc = FALSE; + int status = 0; + BYTE* pDstData = calloc(4ULL * width, height); + CLEAR_CONTEXT* clear = clear_context_new(FALSE); + + if (!clear || !pDstData) + goto fail; + + status = clear_decompress(clear, pSrcData, SrcSize, width, height, pDstData, + PIXEL_FORMAT_XRGB32, 0, 0, 0, width, height, NULL); + (void)printf("clear_decompress example %" PRIu32 " status: %d\n", nr, status); + (void)fflush(stdout); + rc = (status == 0); +fail: + clear_context_free(clear); + free(pDstData); + return rc; +} + +int TestFreeRDPCodecClear(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + /* Example 1 needs a filled glyph cache + if (!test_ClearDecompressExample(1, 8, 9, TEST_CLEAR_EXAMPLE_1, + sizeof(TEST_CLEAR_EXAMPLE_1))) + return -1; + */ + if (!test_ClearDecompressExample(2, 78, 17, TEST_CLEAR_EXAMPLE_2, sizeof(TEST_CLEAR_EXAMPLE_2))) + return -1; + + if (!test_ClearDecompressExample(3, 64, 24, TEST_CLEAR_EXAMPLE_3, sizeof(TEST_CLEAR_EXAMPLE_3))) + return -1; + + if (!test_ClearDecompressExample(4, 7, 15, TEST_CLEAR_EXAMPLE_4, sizeof(TEST_CLEAR_EXAMPLE_4))) + return -1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecCopy.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecCopy.c new file mode 100644 index 0000000000000000000000000000000000000000..bd990ac071a3238b791abff94c3383beec76b58a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecCopy.c @@ -0,0 +1,130 @@ + +#include +#include +#include +#include + +#include + +#include +#include + +#define TEST_RUNS 2 + +static BOOL TestFreeRDPImageCopy(UINT32 w, UINT32 h, UINT32 srcFormat, UINT32 dstFormat, + size_t runs) +{ + BOOL rc = FALSE; + const size_t sbpp = FreeRDPGetBytesPerPixel(srcFormat); + const size_t dbpp = FreeRDPGetBytesPerPixel(dstFormat); + const size_t srcStep = w * sbpp; + const size_t dstStep = w * dbpp; + char* src = calloc(h, srcStep); + char* dst = calloc(h, dstStep); + if (!src || !dst) + goto fail; + + for (size_t x = 0; x < runs; x++) + { + winpr_RAND_pseudo(src, h * srcStep); + const UINT64 start = winpr_GetUnixTimeNS(); + rc = freerdp_image_copy(dst, dstFormat, dstStep, 0, 0, w, h, src, srcFormat, srcStep, 0, 0, + NULL, 0); + const UINT64 end = winpr_GetUnixTimeNS(); + + double ms = (double)(end - start); + ms /= 1000000.0; + + (void)fprintf(stdout, + "[%s] copied %" PRIu32 "x%" PRIu32 " [%-20s] -> [%-20s] in %lf ms [%s]\n", + __func__, w, h, FreeRDPGetColorFormatName(srcFormat), + FreeRDPGetColorFormatName(dstFormat), ms, rc ? "success" : "failure"); + if (!rc) + break; + } + +fail: + free(src); + free(dst); + return rc; +} + +static BOOL TestFreeRDPImageCopy_no_overlap(UINT32 w, UINT32 h, UINT32 srcFormat, UINT32 dstFormat, + size_t runs) +{ + BOOL rc = FALSE; + const size_t sbpp = FreeRDPGetBytesPerPixel(srcFormat); + const size_t dbpp = FreeRDPGetBytesPerPixel(dstFormat); + const size_t srcStep = w * sbpp; + const size_t dstStep = w * dbpp; + char* src = calloc(h, srcStep); + char* dst = calloc(h, dstStep); + if (!src || !dst) + goto fail; + + for (size_t x = 0; x < runs; x++) + { + winpr_RAND_pseudo(src, h * srcStep); + const UINT64 start = winpr_GetUnixTimeNS(); + rc = freerdp_image_copy_no_overlap(dst, dstFormat, dstStep, 0, 0, w, h, src, srcFormat, + srcStep, 0, 0, NULL, 0); + const UINT64 end = winpr_GetUnixTimeNS(); + + double ms = (double)(end - start); + ms /= 1000000.0; + + (void)fprintf(stdout, + "[%s] copied %" PRIu32 "x%" PRIu32 " [%-20s] -> [%-20s] in %lf ms [%s]\n", + __func__, w, h, FreeRDPGetColorFormatName(srcFormat), + FreeRDPGetColorFormatName(dstFormat), ms, rc ? "success" : "failure"); + if (!rc) + break; + } + +fail: + free(src); + free(dst); + return rc; +} +int TestFreeRDPCodecCopy(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + UINT32 width = 192; + UINT32 height = 108; + const UINT32 formats[] = { + PIXEL_FORMAT_ABGR15, PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_BGR16, + PIXEL_FORMAT_BGR24, PIXEL_FORMAT_RGB15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_RGB24, + PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_XRGB32, + PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_BGRX32, PIXEL_FORMAT_RGBX32, + }; + + if (argc == 3) + { + errno = 0; + width = strtoul(argv[1], NULL, 0); + height = strtoul(argv[2], NULL, 0); + if ((errno != 0) || (width == 0) || (height == 0)) + { + char buffer[128] = { 0 }; + (void)fprintf(stderr, "%s failed: width=%" PRIu32 ", height=%" PRIu32 ", errno=%s\n", + __func__, width, height, winpr_strerror(errno, buffer, sizeof(buffer))); + return -1; + } + } + for (size_t x = 0; x < ARRAYSIZE(formats); x++) + { + const UINT32 SrcFormat = formats[x]; + for (size_t y = 0; y < ARRAYSIZE(formats); y++) + { + const UINT32 DstFormat = formats[y]; + if (!TestFreeRDPImageCopy(width, height, SrcFormat, DstFormat, TEST_RUNS)) + return -1; + if (!TestFreeRDPImageCopy_no_overlap(width, height, SrcFormat, DstFormat, TEST_RUNS)) + return -1; + } + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecH264.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecH264.c new file mode 100644 index 0000000000000000000000000000000000000000..2433263b29e62f65e1ed286e8bffe359016b208f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecH264.c @@ -0,0 +1,192 @@ + +#include +#include +#include +#include + +#include + +#include +#include + +static const char* print_ns(UINT64 start, UINT64 end, char* buffer, size_t len) +{ + const UINT64 diff = end - start; + const unsigned ns = diff % 1000; + const unsigned us = (diff / 1000) % 1000; + const unsigned ms = (diff / 1000000) % 1000; + const unsigned s = (diff / 1000000000ULL) % 1000; + (void)_snprintf(buffer, len, "%03u %03u %03u %03uns", s, ms, us, ns); + return buffer; +} + +static BOOL testContextOptions(BOOL compressor, uint32_t width, uint32_t height) +{ + BOOL rc = FALSE; + const UINT64 start = winpr_GetUnixTimeNS(); + H264_CONTEXT* h264 = h264_context_new(FALSE); + if (!h264) + return FALSE; + + struct optpair_s + { + H264_CONTEXT_OPTION opt; + uint32_t val; + }; + const struct optpair_s optpair[] = { { H264_CONTEXT_OPTION_RATECONTROL, H264_RATECONTROL_VBR }, + { H264_CONTEXT_OPTION_BITRATE, 2323 }, + { H264_CONTEXT_OPTION_FRAMERATE, 23 }, + { H264_CONTEXT_OPTION_QP, 21 }, + { H264_CONTEXT_OPTION_USAGETYPE, 23 } }; + for (size_t x = 0; x < ARRAYSIZE(optpair); x++) + { + const struct optpair_s* cur = &optpair[x]; + if (!h264_context_set_option(h264, cur->opt, cur->val)) + goto fail; + } + if (!h264_context_reset(h264, width, height)) + goto fail; + + rc = TRUE; +fail: + h264_context_free(h264); + const UINT64 end = winpr_GetUnixTimeNS(); + + char buffer[64] = { 0 }; + printf("[%s] %" PRIu32 "x%" PRIu32 " took %s\n", __func__, width, height, + print_ns(start, end, buffer, sizeof(buffer))); + return rc; +} + +static void* allocRGB(uint32_t format, uint32_t width, uint32_t height, uint32_t* pstride) +{ + const size_t bpp = FreeRDPGetBytesPerPixel(format); + const size_t stride = bpp * width + 32; + WINPR_ASSERT(pstride); + *pstride = WINPR_ASSERTING_INT_CAST(uint32_t, stride); + + uint8_t* rgb = calloc(stride, height); + if (!rgb) + return NULL; + + for (size_t x = 0; x < height; x++) + { + winpr_RAND(&rgb[x * stride], width * bpp); + } + return rgb; +} + +static BOOL compareRGB(const uint8_t* src, const uint8_t* dst, uint32_t format, size_t width, + size_t stride, size_t height) +{ + const size_t bpp = FreeRDPGetBytesPerPixel(format); + for (size_t y = 0; y < height; y++) + { + const uint8_t* csrc = &src[y * stride]; + const uint8_t* cdst = &dst[y * stride]; + const int rc = memcmp(csrc, cdst, width * bpp); + // TODO: Both, AVC420 encoding and decoding are lossy. + // TODO: Find a proper error margin to check for +#if 0 + if (rc != 0) + return FALSE; +#endif + } + return TRUE; +} + +static BOOL testEncode(uint32_t format, uint32_t width, uint32_t height) +{ + BOOL rc = FALSE; + void* src = NULL; + void* out = NULL; + RDPGFX_H264_METABLOCK meta = { 0 }; + H264_CONTEXT* h264 = h264_context_new(TRUE); + H264_CONTEXT* h264dec = h264_context_new(FALSE); + if (!h264 || !h264dec) + goto fail; + + if (!h264_context_reset(h264, width, height)) + goto fail; + if (!h264_context_reset(h264dec, width, height)) + goto fail; + + uint32_t stride = 0; + uint32_t ostride = 0; + src = allocRGB(format, width, height, &stride); + out = allocRGB(format, width, height, &ostride); + if (!src || !out || (stride < width) || (stride != ostride)) + goto fail; + + const RECTANGLE_16 rect = { .left = 0, .top = 0, .right = width, .bottom = height }; + uint32_t dstsize = 0; + uint8_t* dst = NULL; + if (avc420_compress(h264, src, format, stride, width, height, &rect, &dst, &dstsize, &meta) < 0) + goto fail; + if ((dstsize == 0) || !dst) + goto fail; + + if (avc420_decompress(h264dec, dst, dstsize, out, format, stride, width, height, &rect, 1) < 0) + goto fail; + + rc = compareRGB(src, out, format, width, stride, height); +fail: + h264_context_free(h264); + h264_context_free(h264dec); + free_h264_metablock(&meta); + free(src); + free(out); + return rc; +} + +int TestFreeRDPCodecH264(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + UINT32 width = 124; + UINT32 height = 54; + const UINT32 formats[] = { + PIXEL_FORMAT_ABGR15, PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_BGR16, + PIXEL_FORMAT_BGR24, PIXEL_FORMAT_RGB15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_RGB24, + PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_XRGB32, + PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_BGRX32, PIXEL_FORMAT_RGBX32, + }; + + if (argc == 3) + { + errno = 0; + width = strtoul(argv[1], NULL, 0); + height = strtoul(argv[2], NULL, 0); + if ((errno != 0) || (width == 0) || (height == 0)) + { + char buffer[128] = { 0 }; + (void)fprintf(stderr, "%s failed: width=%" PRIu32 ", height=%" PRIu32 ", errno=%s\n", + __func__, width, height, winpr_strerror(errno, buffer, sizeof(buffer))); + return -1; + } + } + +#if !defined(WITH_MEDIACODEC) && !defined(WITH_MEDIA_FOUNDATION) && !defined(WITH_OPENH264) && \ + !defined(WITH_VIDEO_FFMPEG) + (void)fprintf(stderr, "[%s] skipping, no H264 encoder/decoder support compiled in\n", __func__); + return 0; +#endif + + if (!testContextOptions(FALSE, width, height)) + return -1; + if (!testContextOptions(TRUE, width, height)) + return -1; + + for (size_t x = 0; x < ARRAYSIZE(formats); x++) + { + const UINT32 SrcFormat = formats[x]; + for (size_t y = 0; y < ARRAYSIZE(formats); y++) + { + if (!testEncode(SrcFormat, width, height)) + return -1; + } + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecInterleaved.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecInterleaved.c new file mode 100644 index 0000000000000000000000000000000000000000..77f390a8e62ea98b48150285add1b6bb4fccbcf0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecInterleaved.c @@ -0,0 +1,219 @@ + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +static BOOL run_encode_decode_single(UINT16 bpp, BITMAP_INTERLEAVED_CONTEXT* encoder, + BITMAP_INTERLEAVED_CONTEXT* decoder +#if defined(WITH_PROFILER) + , + PROFILER* profiler_comp, PROFILER* profiler_decomp +#endif +) +{ + BOOL rc2 = FALSE; + BOOL rc = 0; + const UINT32 w = 64; + const UINT32 h = 64; + const UINT32 x = 0; + const UINT32 y = 0; + const UINT32 format = PIXEL_FORMAT_RGBX32; + const UINT32 bstep = FreeRDPGetBytesPerPixel(format); + const size_t step = (13ULL + w) * 4ULL; + const size_t SrcSize = step * h; + const int maxDiff = 4 * ((bpp < 24) ? 2 : 1); + UINT32 DstSize = SrcSize; + BYTE* pSrcData = calloc(1, SrcSize); + BYTE* pDstData = calloc(1, SrcSize); + BYTE* tmp = calloc(1, SrcSize); + + if (!pSrcData || !pDstData || !tmp) + goto fail; + + winpr_RAND(pSrcData, SrcSize); + + if (!bitmap_interleaved_context_reset(encoder) || !bitmap_interleaved_context_reset(decoder)) + goto fail; + + PROFILER_ENTER(profiler_comp) + rc = + interleaved_compress(encoder, tmp, &DstSize, w, h, pSrcData, format, step, x, y, NULL, bpp); + PROFILER_EXIT(profiler_comp) + + if (!rc) + goto fail; + + PROFILER_ENTER(profiler_decomp) + rc = interleaved_decompress(decoder, tmp, DstSize, w, h, bpp, pDstData, format, step, x, y, w, + h, NULL); + PROFILER_EXIT(profiler_decomp) + + if (!rc) + goto fail; + + for (UINT32 i = 0; i < h; i++) + { + const BYTE* srcLine = &pSrcData[i * step]; + const BYTE* dstLine = &pDstData[i * step]; + + for (UINT32 j = 0; j < w; j++) + { + BYTE r = 0; + BYTE g = 0; + BYTE b = 0; + BYTE dr = 0; + BYTE dg = 0; + BYTE db = 0; + const UINT32 srcColor = FreeRDPReadColor(&srcLine[1ULL * j * bstep], format); + const UINT32 dstColor = FreeRDPReadColor(&dstLine[1ULL * j * bstep], format); + FreeRDPSplitColor(srcColor, format, &r, &g, &b, NULL, NULL); + FreeRDPSplitColor(dstColor, format, &dr, &dg, &db, NULL, NULL); + + if (abs(r - dr) > maxDiff) + goto fail; + + if (abs(g - dg) > maxDiff) + goto fail; + + if (abs(b - db) > maxDiff) + goto fail; + } + } + + rc2 = TRUE; +fail: + free(pSrcData); + free(pDstData); + free(tmp); + return rc2; +} + +static const char* get_profiler_name(BOOL encode, UINT16 bpp) +{ + switch (bpp) + { + case 24: + if (encode) + return "interleaved_compress 24bpp"; + else + return "interleaved_decompress 24bpp"; + + case 16: + if (encode) + return "interleaved_compress 16bpp"; + else + return "interleaved_decompress 16bpp"; + + case 15: + if (encode) + return "interleaved_compress 15bpp"; + else + return "interleaved_decompress 15bpp"; + + default: + return "configuration error!"; + } +} + +static BOOL run_encode_decode(UINT16 bpp, BITMAP_INTERLEAVED_CONTEXT* encoder, + BITMAP_INTERLEAVED_CONTEXT* decoder) +{ + BOOL rc = FALSE; + PROFILER_DEFINE(profiler_comp) + PROFILER_DEFINE(profiler_decomp) + PROFILER_CREATE(profiler_comp, get_profiler_name(TRUE, bpp)) + PROFILER_CREATE(profiler_decomp, get_profiler_name(FALSE, bpp)) + + for (UINT32 x = 0; x < 50; x++) + { + if (!run_encode_decode_single(bpp, encoder, decoder +#if defined(WITH_PROFILER) + , + profiler_comp, profiler_decomp +#endif + )) + goto fail; + } + + rc = TRUE; +fail: + PROFILER_PRINT_HEADER + PROFILER_PRINT(profiler_comp) + PROFILER_PRINT(profiler_decomp) + PROFILER_PRINT_FOOTER + PROFILER_FREE(profiler_comp) + PROFILER_FREE(profiler_decomp) + return rc; +} + +static BOOL TestColorConversion(void) +{ + const UINT32 formats[] = { PIXEL_FORMAT_RGB15, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_ABGR15, + PIXEL_FORMAT_ARGB15, PIXEL_FORMAT_BGR16, PIXEL_FORMAT_RGB16 }; + + /* Check color conversion 15/16 -> 32bit maps to proper values */ + for (UINT32 x = 0; x < ARRAYSIZE(formats); x++) + { + const UINT32 dstFormat = PIXEL_FORMAT_RGBA32; + const UINT32 format = formats[x]; + const UINT32 colorLow = FreeRDPGetColor(format, 0, 0, 0, 255); + const UINT32 colorHigh = FreeRDPGetColor(format, 255, 255, 255, 255); + const UINT32 colorLow32 = FreeRDPConvertColor(colorLow, format, dstFormat, NULL); + const UINT32 colorHigh32 = FreeRDPConvertColor(colorHigh, format, dstFormat, NULL); + BYTE r = 0; + BYTE g = 0; + BYTE b = 0; + BYTE a = 0; + FreeRDPSplitColor(colorLow32, dstFormat, &r, &g, &b, &a, NULL); + if ((r != 0) || (g != 0) || (b != 0)) + return FALSE; + + FreeRDPSplitColor(colorHigh32, dstFormat, &r, &g, &b, &a, NULL); + if ((r != 255) || (g != 255) || (b != 255)) + return FALSE; + } + + return TRUE; +} + +int TestFreeRDPCodecInterleaved(int argc, char* argv[]) +{ + BITMAP_INTERLEAVED_CONTEXT* encoder = NULL; + BITMAP_INTERLEAVED_CONTEXT* decoder = NULL; + int rc = -1; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + encoder = bitmap_interleaved_context_new(TRUE); + decoder = bitmap_interleaved_context_new(FALSE); + + if (!encoder || !decoder) + goto fail; + + if (!run_encode_decode(24, encoder, decoder)) + goto fail; + + if (!run_encode_decode(16, encoder, decoder)) + goto fail; + + if (!run_encode_decode(15, encoder, decoder)) + goto fail; + + if (!TestColorConversion()) + goto fail; + + rc = 0; +fail: + bitmap_interleaved_context_free(encoder); + bitmap_interleaved_context_free(decoder); + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecMppc.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecMppc.c new file mode 100644 index 0000000000000000000000000000000000000000..b0d70d7a698b09301a629c18c1d996379398a48d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecMppc.c @@ -0,0 +1,1093 @@ +#include +#include +#include + +#include +#include + +#include "../mppc.h" + +static const BYTE TEST_RDP5_COMPRESSED_DATA[] = { + 0x24, 0x02, 0x03, 0x09, 0x00, 0x20, 0x0c, 0x05, 0x10, 0x01, 0x40, 0x0a, 0xbf, 0xdf, 0xc3, 0x20, + 0x80, 0x00, 0x1f, 0x0a, 0x00, 0x00, 0x07, 0x43, 0x4e, 0x00, 0x68, 0x02, 0x00, 0x22, 0x00, 0x34, + 0xcb, 0xfb, 0xf8, 0x18, 0x40, 0x01, 0x00, 0x27, 0xe2, 0x90, 0x0f, 0xc3, 0x91, 0xa8, 0x00, 0x08, + 0x00, 0x00, 0x68, 0x50, 0x60, 0x65, 0xfc, 0x0e, 0xfe, 0x04, 0x00, 0x08, 0x00, 0x06, 0x0c, 0x00, + 0x01, 0x00, 0xf8, 0x40, 0x20, 0x00, 0x00, 0x90, 0x00, 0xcf, 0x95, 0x1f, 0x44, 0x90, 0x00, 0x6e, + 0x03, 0xf4, 0x40, 0x21, 0x9f, 0x26, 0x01, 0xbf, 0x88, 0x10, 0x90, 0x00, 0x08, 0x04, 0x00, 0x04, + 0x30, 0x03, 0xe4, 0xc7, 0xea, 0x05, 0x1e, 0x87, 0xf8, 0x20, 0x1c, 0x00, 0x10, 0x84, 0x22, 0x1f, + 0x71, 0x0d, 0x0e, 0xb9, 0x88, 0x9f, 0x5c, 0xee, 0x41, 0x97, 0xfb, 0xf8, 0x88, 0x68, 0x08, 0x6d, + 0xd0, 0x44, 0xfc, 0x34, 0x06, 0xe6, 0x16, 0x21, 0x04, 0x11, 0x0f, 0xb9, 0x85, 0x86, 0x5d, 0x44, + 0x4f, 0xae, 0xb7, 0x40, 0xa8, 0xcd, 0x5b, 0xed, 0x02, 0xee, 0xc2, 0x21, 0x40, 0x21, 0x21, 0x23, + 0x17, 0xb7, 0x00, 0x60, 0x00, 0x3b, 0xfd, 0xfc, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x34, 0x00, 0x33, + 0xc7, 0xe0, 0xc0, 0x0f, 0x07, 0x12, 0x42, 0x01, 0xe8, 0x6c, 0xc7, 0x83, 0x07, 0x8c, 0xd4, 0x30, + 0x07, 0x20, 0x01, 0x90, 0xa3, 0xf1, 0xdb, 0xf5, 0xd4, 0x13, 0xc2, 0x4f, 0x0f, 0xe5, 0xe2, 0xc7, + 0x87, 0xf2, 0xf0, 0x93, 0xc3, 0xf9, 0x78, 0xb0, 0x1a, 0x03, 0xe1, 0xf1, 0xd0, 0x08, 0x4c, 0x66, + 0xac, 0x32, 0x31, 0x70, 0x60, 0x11, 0x01, 0x11, 0x01, 0x01, 0x01, 0xf0, 0x36, 0x1f, 0xe5, 0xe0, + 0x6c, 0xbc, 0x26, 0xf0, 0x36, 0x5f, 0xe5, 0xe0, 0x6c, 0xbc, 0x26, 0xf0, 0x34, 0xf9, 0x94, 0x32, + 0x31, 0x74, 0x20, 0x10, 0x00, 0x00, 0x0f, 0xbf, 0x87, 0xdf, 0xef, 0xfe, 0x4b, 0xbf, 0x02, 0xfa, + 0xde, 0xa7, 0x79, 0x32, 0x44, 0x7c, 0x20, 0x82, 0x00, 0x5f, 0xef, 0xff, 0x09, 0xe1, 0x05, 0x74, + 0x32, 0xea, 0x09, 0xe1, 0x0f, 0x55, 0x83, 0x85, 0x2a, 0xa0, 0x1d, 0x50, 0x0e, 0x0e, 0x0b, 0x01, + 0x01, 0x43, 0x06, 0x02, 0xbe, 0x5f, 0x00, 0x00, 0x0c, 0x3d, 0x4d, 0x87, 0xa6, 0x5e, 0xa6, 0xcb, + 0xc3, 0xcf, 0x53, 0x65, 0xe9, 0x97, 0xa9, 0xb2, 0xf5, 0x9b, 0xd4, 0xd3, 0xee, 0xcd, 0xc0, 0x7c, + 0xae, 0xe0, 0x65, 0x1f, 0xe5, 0xe0, 0x6c, 0xbc, 0x26, 0xf0, 0x36, 0x5f, 0xe5, 0xe0, 0x6c, 0xbc, + 0x26, 0xf0, 0x34, 0xfb, 0xb3, 0xf2, 0x41, 0x30, 0x20, 0x04, 0xa0, 0x80, 0x93, 0xf3, 0xf2, 0x1b, + 0xed, 0xf6, 0x0f, 0x04, 0x82, 0x7b, 0xcc, 0x00, 0x65, 0xef, 0x4f, 0x86, 0x02, 0xf7, 0xa7, 0xe0, + 0x0a, 0x88, 0x1c, 0x34, 0x02, 0x02, 0x02, 0x60, 0x60, 0x49, 0x40, 0xc1, 0x2f, 0x14, 0xca, 0x60, + 0xc1, 0x81, 0x80, 0x07, 0xc3, 0x00, 0x00, 0x39, 0xfa, 0x86, 0x38, 0x93, 0x47, 0x08, 0x27, 0x08, + 0xfc, 0xb8, 0x4e, 0x38, 0x47, 0xe5, 0xc2, 0x09, 0xc2, 0x3f, 0x2e, 0x13, 0x8e, 0x11, 0xf3, 0xc3, + 0x57, 0x1a, 0x88, 0x7d, 0x44, 0x3c, 0x3c, 0x04, 0x0f, 0xd4, 0x3f, 0x83, 0x8d, 0x82, 0x00, 0x25, + 0x04, 0x84, 0xdf, 0xe0, 0x17, 0xf8, 0x04, 0x03, 0xe1, 0x47, 0xc4, 0xaf, 0x9c, 0x00, 0x00, 0x31, + 0xf5, 0x4c, 0x71, 0x78, 0x8f, 0x54, 0xfb, 0x1c, 0x97, 0xa4, 0x04, 0x13, 0xd5, 0x2f, 0x77, 0xc7, + 0xb8, 0x9e, 0xef, 0xcb, 0xc2, 0x6f, 0x77, 0xe5, 0xee, 0x27, 0xbb, 0xf2, 0xf7, 0xe3, 0xdd, 0xf3, + 0xc6, 0xfb, 0x2a, 0x78, 0x6d, 0x3c, 0x34, 0x37, 0xc0, 0xaf, 0x25, 0xc7, 0x81, 0x7d, 0x6e, 0x5d, + 0x5c, 0xd6, 0xe3, 0x43, 0xc0, 0x82, 0xd0, 0x95, 0x90, 0xd8, 0xbd, 0xfc, 0x00, 0x09, 0xc0, 0x34, + 0x39, 0x46, 0x84, 0x20, 0x40, 0x38, 0xa3, 0x42, 0x12, 0xb0, 0x55, 0xbe, 0x28, 0xc0, 0x70, 0x64, + 0x28, 0xc8, 0x48, 0x42, 0x08, 0xb2, 0x1b, 0x46, 0xa6, 0x09, 0x54, 0x2e, 0x5f, 0x73, 0x84, 0xfc, + 0x28, 0x4a, 0x73, 0x79, 0xf2, 0x6c, 0x5d, 0x82, 0x82, 0x6e, 0xc2, 0x27, 0xd7, 0x6b, 0xb8, 0x4f, + 0xa4, 0xa4, 0x22, 0xee, 0x22, 0x7e, 0x10, 0x03, 0x78, 0x08, 0xf4, 0x94, 0x5e, 0x02, 0x01, 0xef, + 0x02, 0x27, 0xd7, 0x8b, 0xc8, 0x3f, 0xa4, 0xa4, 0x1a, 0xf3, 0xd1, 0x84, 0x0c, 0x32, 0x31, 0x75, + 0x60, 0x05, 0xe2, 0x30, 0xb7, 0xad, 0x5b, 0x15, 0xd5, 0xc3, 0xc0, 0x00, 0x11, 0x81, 0x81, 0x69, + 0x8f, 0x06, 0x0f, 0x14, 0xcf, 0xa6, 0xe8, 0xb1, 0x22, 0x77, 0xeb, 0xd7, 0x45, 0x89, 0xf0, 0xb6, + 0x3e, 0x23, 0x06, 0x80, 0xf8, 0x5b, 0x0f, 0x04, 0x83, 0xfc, 0x2d, 0x8f, 0x88, 0xc1, 0xa0, 0x3e, + 0x16, 0x1d, 0x00, 0x83, 0x74, 0x58, 0xa0, 0xc0, 0x10, 0xce, 0x8b, 0x17, 0xe0, 0x68, 0xff, 0x20, + 0xff, 0x03, 0x63, 0xe5, 0xcf, 0x1f, 0xa0, 0x40, 0x00, 0x00, 0x2a, 0xff, 0xd6, 0xd1, 0xc0, 0xb9, + 0xe0, 0x5f, 0x6b, 0x81, 0x73, 0xc9, 0x93, 0xd1, 0x63, 0x50, 0xf0, 0x9b, 0xf0, 0x48, 0x4f, 0xaf, + 0xe0, 0x1b, 0xef, 0x82, 0x6f, 0xc2, 0x40, 0xe0, 0xe4, 0x60, 0xa0, 0x69, 0xa1, 0xa1, 0xbe, 0xba, + 0x04, 0x00, 0x08, 0x00, 0x10, 0x00, 0x20, 0x00, 0x42, 0x00, 0x44, 0x00, 0x88, 0x01, 0x10, 0x02, + 0x21, 0x02, 0x22, 0x04, 0x44, 0x08, 0x9c, 0x8f, 0xcd, 0xe0, 0x02, 0x20, 0x88, 0x02, 0x10, 0x40, + 0x01, 0xf0, 0x60, 0x44, 0xc0, 0xce, 0xb1, 0x8f, 0xd0, 0x30, 0x00, 0x60, 0x00, 0xa0, 0x00, 0xc4, + 0x00, 0xcc, 0x01, 0x98, 0x03, 0x28, 0x03, 0x31, 0x03, 0x33, 0x06, 0x66, 0x07, 0x0e, 0x2c, 0xe3, + 0x7b, 0x18, 0x85, 0xc7, 0xd6, 0x51, 0x71, 0x0f, 0x0e, 0xb8, 0x88, 0x9f, 0x5c, 0x6e, 0x41, 0xde, + 0xeb, 0x71, 0x20, 0x5c, 0xba, 0xf7, 0xc8, 0x6f, 0xba, 0xc1, 0xf7, 0x30, 0xd0, 0xce, 0xc1, 0x31, + 0x74, 0xec, 0x13, 0x41, 0x77, 0x41, 0x13, 0xa0, 0x10, 0xbf, 0x7c, 0x45, 0xd3, 0xa5, 0xbc, 0x55, + 0x84, 0xaa, 0x41, 0xc1, 0xc1, 0xe0, 0xe0, 0x29, 0x01, 0x20, 0x81, 0x00, 0x03, 0x80, 0x07, 0xc0, + 0x0f, 0xe0, 0x06, 0xbe, 0x16, 0x75, 0xe7, 0x9f, 0xfb, 0x1e, 0x17, 0x90, 0xef, 0x0b, 0xbb, 0x15, + 0x03, 0x7c, 0x2b, 0x7e, 0x22, 0x78, 0x56, 0x83, 0xae, 0x77, 0x40, 0xcf, 0xb0, 0xf0, 0x98, 0x28, + 0x04, 0x2f, 0xaf, 0x0e, 0x40, 0xfc, 0x01, 0x1c, 0x5c, 0xb1, 0xf2, 0xbf, 0xa5, 0xd7, 0x8f, 0x97, + 0xc0, 0xfe, 0x9f, 0x02, 0xe7, 0x24, 0x79, 0xe0, 0x9b, 0xa9, 0xfd, 0x74, 0x3b, 0xaf, 0x2d, 0xf8, + 0x4b, 0xd2, 0xf7, 0x84, 0x54, 0x04, 0x2a, 0x02, 0x02, 0x01, 0xe1, 0x1e, 0xf0, 0x87, 0xff, 0x77, + 0x07, 0x00, 0x02, 0x00, 0x0d, 0xbd, 0xe1, 0xf0, 0x01, 0x1e, 0xf0, 0xfd, 0x80, 0x4c, 0x24, 0x11, + 0x2c, 0x10, 0x24, 0x02, 0x01, 0x40, 0xb0, 0x5c, 0x2c, 0x14, 0x08, 0x07, 0x1b, 0x80, 0x01, 0xa7, + 0xbd, 0x3e, 0x00, 0x27, 0xde, 0x9f, 0xb0, 0x85, 0x01, 0xfb, 0xd2, 0x04, 0x0c, 0x1c, 0x2e, 0x0e, + 0x06, 0x18, 0x03, 0xd4, 0x00, 0x00, 0x67, 0xef, 0x4f, 0x80, 0x0a, 0xf7, 0xa7, 0xe3, 0x94, 0xe0, + 0xe0, 0x10, 0x1b, 0xfd, 0xfc, 0x74, 0x62, 0xe8, 0xc0, 0x1d, 0x62, 0x00, 0x0b, 0x00, 0xb7, 0x70, + 0xe6, 0x8a, 0x68, 0x75, 0x38, 0x3c, 0x3c, 0x4c, 0x2f, 0x87, 0xef, 0x01, 0xc7, 0xb2, 0x40, 0x21, + 0xa3, 0x23, 0x0a, 0x08, 0x01, 0xa1, 0xa1, 0xe1, 0x80, 0x69, 0x40, 0xe1, 0x00, 0x00, 0x40, 0xd0, + 0xea, 0xe5, 0xe1, 0xc0, 0x81, 0x87, 0xed, 0x68, 0x1a, 0x08, 0x94, 0x0c, 0x0c, 0xf1, 0x7c, 0xbe, + 0x5f, 0x2f, 0x8f, 0x00, 0x00, 0x0d, 0x1f, 0x68, 0x7a, 0x1a, 0x04, 0x05, 0xce, 0xe6, 0x2a, 0x0c, + 0x01, 0xc2, 0x00, 0x40, 0x42, 0x61, 0xc0, 0x49, 0x41, 0x60, 0xa0, 0x80, 0x01, 0xc0, 0x03, 0xe0, + 0x07, 0xf0, 0x07, 0xfa, 0x00, 0x07, 0x3b, 0x99, 0x01, 0x0f, 0x19, 0x18, 0x54, 0x40, 0xe0, 0x60, + 0xee, 0xd0, 0x0e, 0x19, 0x0a, 0x03, 0xa5, 0x7d, 0x05, 0xd0, 0x83, 0x98, 0x5a, 0x96, 0x21, 0x4b, + 0x10, 0x10, 0xe6, 0x17, 0xaf, 0xeb, 0xaf, 0x34, 0x3c, 0xc8, 0x0f, 0xf0, 0x64, 0x3f, 0xd0, 0x0f, + 0xe0, 0x03, 0xfe, 0x10, 0x02, 0x7d, 0x47, 0x2d, 0x58, 0xfc, 0x35, 0xe0, 0xca, 0x0f, 0x19, 0x0a, + 0xf9, 0xf1, 0xe0, 0xb9, 0xc0, 0x81, 0x10, 0x03, 0xe0, 0xbd, 0x4f, 0xea, 0x61, 0xf7, 0xeb, 0xf6, + 0x02, 0xd4, 0x7a, 0xf9, 0xff, 0x15, 0x30, 0xfa, 0x88, 0x68, 0x68, 0xd8, 0x80, 0x12, 0x60, 0x50, + 0x50, 0xf0, 0x03, 0xfc, 0x01, 0xfe, 0x01, 0x7f, 0xa0, 0x7c, 0x28, 0xbf, 0xd0, 0x3e, 0x64, 0x0f, + 0x00, 0x37, 0x00, 0x08, 0x80, 0x20, 0x0b, 0x88, 0x81, 0xa5, 0x04, 0x84, 0x60, 0x40, 0x36, 0x04, + 0x1b, 0x8f, 0x88, 0x01, 0x00, 0xa1, 0x80, 0x1e, 0x00, 0x36, 0xfd, 0xb9, 0x12, 0x02, 0x4c, 0x09, + 0x08, 0x1e, 0x00, 0x61, 0x80, 0x20, 0x60, 0x44, 0x17, 0xdc, 0x7c, 0x62, 0x00, 0x03, 0x67, 0xdb, + 0x81, 0xb1, 0x30, 0x34, 0xb0, 0xa0, 0xaf, 0xa0, 0x80, 0x75, 0x35, 0x20, 0x7c, 0x49, 0xfc, 0x0f, + 0xf5, 0x0d, 0x7f, 0x7e, 0x45, 0x00, 0x53, 0x42, 0x82, 0x83, 0xc0, 0x0c, 0x28, 0x1f, 0x72, 0x3e, + 0xd3, 0xf5, 0x62, 0xd4, 0x00, 0x22, 0xa8, 0x81, 0xec, 0x67, 0x96, 0x02, 0xa0, 0x49, 0x7d, 0xfd, + 0x6b, 0xbf, 0xcc, 0x7c, 0x4a, 0xf8, 0xd0, 0x00, 0x00, 0xcf, 0xd5, 0xd2, 0x23, 0x35, 0x60, 0x01, + 0xf1, 0x60, 0x14, 0xc0, 0xb0, 0xbe, 0xb3, 0x02, 0x0f, 0x89, 0x5f, 0x1b, 0x00, 0x02, 0x0b, 0xfd, + 0x80, 0x00, 0x01, 0x9b, 0xf3, 0x40, 0x42, 0x10, 0x00, 0xd8, 0xb8, 0x0f, 0xa8, 0x17, 0xfe, 0x59, + 0xef, 0x14, 0x61, 0xf2, 0x30, 0x65, 0xfc, 0x51, 0xe2, 0xc1, 0x18, 0xc0, 0x07, 0x5e, 0x68, 0x08, + 0xe8, 0x46, 0xf8, 0x95, 0xf1, 0xb0, 0xf9, 0x13, 0x7f, 0xbc, 0x00, 0x00, 0x32, 0x7e, 0xa8, 0xeb, + 0xcd, 0x03, 0x20, 0x09, 0xa1, 0x81, 0x97, 0xfb, 0x87, 0x80, 0xb0, 0xf9, 0x19, 0x7c, 0xa8, 0x63, + 0xf3, 0xe6, 0x20, 0x22, 0xbd, 0x85, 0x9e, 0x62, 0x00, 0x8b, 0x7c, 0x87, 0x91, 0x00, 0x22, 0xff, + 0x21, 0xe2, 0xa0, 0x08, 0xc7, 0xc8, 0x78, 0x20, 0x02, 0x33, 0xf2, 0x1c, 0x10, 0x41, 0xe3, 0x40, + 0x69, 0x7c, 0x45, 0x72, 0x62, 0xf0, 0x04, 0x7f, 0x60, 0x68, 0x6f, 0x80, 0x00, 0x08, 0x1f, 0xf7, + 0xad, 0x51, 0x03, 0xf3, 0xf8, 0xa0, 0x9d, 0xa8, 0x40, 0x00, 0x23, 0x42, 0x37, 0x46, 0x0f, 0xde, + 0xa6, 0x06, 0xd3, 0x3c, 0x33, 0xe1, 0x78, 0xd8, 0x34, 0x32, 0x14, 0x67, 0xdb, 0xd2, 0x38, 0xaf, + 0xc7, 0x9c, 0xdf, 0xd0, 0x21, 0xe6, 0xd7, 0x80, 0x40, 0x22, 0x3f, 0x21, 0xe8, 0xd8, 0x12, 0xf9, + 0x0f, 0xb4, 0x01, 0x13, 0xf9, 0x0f, 0x46, 0xc0, 0xa7, 0x13, 0x37, 0x1e, 0x67, 0x07, 0x8b, 0x01, + 0xfd, 0xfe, 0x0f, 0xf7, 0x7a, 0xf0, 0x16, 0x36, 0x0a, 0x92, 0x08, 0x08, 0xc1, 0x70, 0xb8, 0x30, + 0x34, 0xf1, 0xf3, 0x72, 0x27, 0x8f, 0x4b, 0x60, 0x21, 0xc4, 0xdd, 0xe2, 0xdf, 0x0b, 0xca, 0x4f, + 0x2e, 0x4f, 0x9c, 0xde, 0x59, 0xe9, 0xf1, 0x55, 0x00, 0x8d, 0xf2, 0x20, 0x53, 0x3c, 0xc4, 0xf6, + 0x46, 0x7e, 0x24, 0xee, 0xf2, 0x0c, 0x0d, 0x81, 0x83, 0xf9, 0x98, 0x0e, 0x00, 0x02, 0x10, 0x11, + 0x01, 0x08, 0x95, 0x2a, 0xfc, 0x28, 0x95, 0x2a, 0x84, 0x80, 0xbf, 0x81, 0x06, 0x80, 0x0d, 0x00, + 0x86, 0xe0, 0x6b, 0xa5, 0xc3, 0xd8, 0x8f, 0x22, 0xa0, 0x3e, 0xe9, 0x8f, 0x90, 0xf2, 0x6b, 0x85, + 0x77, 0x57, 0x99, 0x43, 0x5c, 0x66, 0x5f, 0x9e, 0x85, 0x7c, 0x3f, 0x1f, 0xb3, 0xce, 0xc0, 0x0e, + 0x64, 0x20, 0x0e, 0x20, 0xdc, 0x7e, 0x18, 0x81, 0x90, 0xa3, 0x13, 0x4e, 0x52, 0x71, 0x81, 0x03, + 0xa4, 0x30, 0x30, 0x6c, 0x73, 0x8f, 0xc4, 0x50, 0x60, 0x16, 0x38, 0x03, 0xbf, 0x6f, 0x89, 0x3e, + 0x00, 0x77, 0x00, 0xb1, 0xc0, 0x28, 0x3d, 0x73, 0x98, 0x06, 0xfe, 0x00, 0xe9, 0x81, 0xa3, 0xb8, + 0x1c, 0x85, 0x20, 0x45, 0x45, 0xe1, 0xa1, 0x23, 0x63, 0xa0, 0x29, 0x61, 0x41, 0x27, 0xf4, 0x03, + 0xfa, 0x01, 0x02, 0x05, 0xff, 0xe1, 0x20, 0x34, 0x08, 0x08, 0x04, 0x04, 0x02, 0xff, 0xeb, 0x96, + 0x05, 0x24, 0x8e, 0x0a, 0xb1, 0xce, 0xf2, 0x06, 0xc7, 0xb9, 0x01, 0xd7, 0x20, 0x52, 0x04, 0x03, + 0xe1, 0x47, 0xc4, 0xa4, 0x0b, 0xfd, 0x03, 0x01, 0xc0, 0x47, 0xe6, 0xc0, 0x2c, 0x7c, 0x09, 0x10, + 0x1c, 0x0a, 0xfd, 0x7e, 0xc0, 0xd2, 0x94, 0x7a, 0x1a, 0x06, 0x07, 0xcf, 0x12, 0x2a, 0x8c, 0x1e, + 0xe7, 0x07, 0x08, 0x81, 0x81, 0x91, 0x90, 0x72, 0x26, 0x9e, 0x55, 0x44, 0x0e, 0x4d, 0x21, 0x00, + 0x08, 0x40, 0x02, 0x20, 0x01, 0x17, 0x2c, 0xd4, 0x22, 0x00, 0x88, 0x80, 0x44, 0x40, 0x23, 0xcd, + 0xf8, 0xf1, 0xc8, 0x9b, 0x02, 0x10, 0x0c, 0x02, 0x99, 0x30, 0x00, 0x0a, 0x06, 0x01, 0x4b, 0x18, + 0x00, 0x46, 0x00, 0x29, 0x9c, 0xa3, 0x86, 0x60, 0x11, 0x98, 0x05, 0x32, 0x80, 0xcc, 0xc0, 0xf3, + 0xc3, 0xb8, 0x7a, 0x21, 0x7d, 0xbe, 0xfa, 0xce, 0x2a, 0x9d, 0xfa, 0xa0, 0x3c, 0x32, 0xfb, 0x7d, + 0x13, 0x22, 0x05, 0xeb, 0x0b, 0xbb, 0xb8, 0x00, 0x15, 0xfe, 0xfe, 0x1a, 0x14, 0x7e, 0x1c, 0x00, + 0x01, 0x82, 0x3a, 0xa7, 0xd2, 0x6c, 0x11, 0xdd, 0x00, 0x00, 0x00, 0xc0, 0x40, 0x18, 0x23, 0x5a, + 0x00, 0x80, 0xb0, 0x47, 0x84, 0x7c, 0xa8, 0x03, 0xa7, 0x82, 0x48, 0x83, 0x01, 0x50, 0x11, 0x2a, + 0x37, 0xfb, 0xfc, 0x03, 0x03, 0xd1, 0xa3, 0x35, 0x68, 0xcd, 0x58, 0x40, 0x03, 0xe3, 0x47, 0xc4, + 0xaf, 0x8d, 0x1f, 0x42, 0x84, 0x20, 0x81, 0x08, 0x57, 0xfb, 0xff, 0xd0, 0x98, 0x27, 0xc8, 0xaf, + 0x99, 0x1f, 0x12, 0x04, 0x3e, 0x84, 0xfe, 0x08, 0x1c, 0xc1, 0x31, 0x58, 0x80, 0x3a, 0xd1, 0x99, + 0x8a, 0x40, 0x02, 0x5a, 0x04, 0x00, 0x02, 0x1a, 0x38, 0xf3, 0x08, 0x00, 0x01, 0xda, 0xe3, 0x35, + 0x60, 0x5f, 0x88, 0x00, 0x03, 0x6e, 0xbf, 0xdf, 0xc0, 0xbe, 0x20, 0x00, 0x42, 0x80, 0x01, 0x77, + 0x9e, 0x80, 0xd0, 0x30, 0x4a, 0x32, 0x81, 0xe3, 0x94, 0x04, 0x21, 0x0a, 0x9c, 0xcc, 0x52, 0x03, + 0x7d, 0xa7, 0x0c, 0x51, 0x80, 0x6f, 0xa5, 0xc0, 0x3f, 0x3e, 0x80, 0xa0, 0x22, 0x10, 0x40, 0x68, + 0x17, 0x9f, 0x60, 0x1e, 0x9b, 0x09, 0x52, 0x03, 0x2d, 0x03, 0x81, 0x88, 0x41, 0x3c, 0x65, 0x14, + 0x98, 0xcd, 0x58, 0x6a, 0x04, 0x21, 0x80, 0x9b, 0x81, 0x45, 0x21, 0x24, 0xe1, 0x8c, 0xf1, 0x9a, + 0xb0, 0xa9, 0x38, 0xef, 0xe7, 0x90, 0xdf, 0x98, 0x00, 0x19, 0xa8, 0x18, 0x42, 0x6a, 0xc0, 0x7f, + 0xda, 0x00, 0x00, 0x2b, 0x1e, 0x36, 0x7c, 0xaa, 0xa0, 0x00, 0xc0, 0xf8, 0xa0, 0xbe, 0x60, 0x2e, + 0xb1, 0x09, 0xab, 0x60, 0x3e, 0x38, 0xf9, 0x6f, 0xa9, 0x3e, 0x08, 0x81, 0xa6, 0x8c, 0x13, 0xae, + 0x83, 0x7e, 0x0a, 0xfb, 0x0f, 0x60, 0x86, 0x3e, 0x90, 0x6d, 0xa2, 0x33, 0x56, 0x06, 0xfa, 0xcf, + 0xc5, 0x1f, 0x12, 0x38, 0x49, 0x3d, 0x04, 0x03, 0xa6, 0x42, 0x54, 0x82, 0x3e, 0xd3, 0xd1, 0xd0, + 0x08, 0x58, 0x06, 0xdc, 0x10, 0x85, 0xe8, 0xf8, 0xf8, 0x94, 0x10, 0x84, 0x21, 0xe7, 0xa3, 0x85, + 0xfe, 0xfe, 0xc1, 0xe9, 0x77, 0xa3, 0x27, 0xe7, 0xbd, 0x31, 0x98, 0x17, 0xa1, 0xe2, 0x13, 0xe8, + 0x5a, 0xf1, 0x44, 0x7c, 0x4a, 0x00, 0x00, 0x07, 0x2d, 0x03, 0x2d, 0x05, 0xa3, 0x46, 0x6a, 0xc1, + 0x9e, 0x9f, 0x9f, 0x51, 0xc0, 0x55, 0x1a, 0x13, 0x56, 0x0e, 0xf4, 0xa4, 0x85, 0xfd, 0x4c, 0x47, + 0x10, 0x0d, 0x70, 0x24, 0x9b, 0xfa, 0x45, 0x41, 0x3a, 0x33, 0xea, 0x28, 0x60, 0x00, 0x80, 0x00, + 0xbc, 0x00, 0x80, 0x7b, 0x2e, 0x43, 0x10, 0x0b, 0x00, 0xec, 0x1e, 0x98, 0x8a, 0xb4, 0x26, 0xac, + 0x5f, 0xf9, 0x20, 0x03, 0xf2, 0xc1, 0xdf, 0xca, 0x14, 0x40, 0x07, 0x40, 0x1e, 0x00, 0x3d, 0x10, + 0xe1, 0x37, 0x90, 0x64, 0x17, 0xec, 0x3d, 0x4c, 0xf5, 0x94, 0x20, 0x15, 0x80, 0xdc, 0x3e, 0x74, + 0x7f, 0x87, 0x87, 0xa9, 0xa6, 0x33, 0x56, 0x16, 0xfd, 0xcf, 0xa9, 0x1f, 0x12, 0x23, 0x35, 0x60, + 0xaf, 0xa4, 0x04, 0xf5, 0xb0, 0x1f, 0xe4, 0x3d, 0x75, 0x1c, 0x20, 0xeb, 0xd7, 0x19, 0x00, 0xb8, + 0x04, 0x21, 0x7a, 0xd3, 0xbe, 0x15, 0xeb, 0x4a, 0xf1, 0x84, 0x78, 0x52, 0x3e, 0x25, 0x03, 0x16, + 0x81, 0xc3, 0x7d, 0x59, 0x1f, 0x12, 0x30, 0x50, 0xe3, 0xe1, 0xcf, 0xc5, 0x8f, 0xa1, 0x1c, 0x0e, + 0x9e, 0xd0, 0x0d, 0x7b, 0x18, 0x14, 0xcc, 0x21, 0x04, 0x1b, 0x6a, 0x8c, 0xd5, 0x86, 0xe0, 0x31, + 0x9a, 0xb0, 0x4f, 0xc8, 0x0b, 0x7c, 0x40, 0x37, 0xc4, 0x5c, 0x22, 0x80, 0x3e, 0x54, 0x71, 0x10, + 0xbf, 0x26, 0xf9, 0xa2, 0x1c, 0x0b, 0x82, 0xf0, 0x8f, 0x22, 0x47, 0x8a, 0xab, 0xca, 0xd4, 0x31, + 0x08, 0xf1, 0xe6, 0x51, 0x9a, 0xb7, 0xcc, 0x80, 0x7f, 0xc9, 0xc2, 0x13, 0x08, 0xfd, 0x95, 0xfe, + 0x23, 0xc0, 0x14, 0x0f, 0x08, 0xe1, 0xb5, 0x5f, 0x4a, 0x38, 0x10, 0x47, 0x1b, 0x17, 0x0a, 0x07, + 0x1d, 0x38, 0xe3, 0xcb, 0x42, 0x10, 0x4f, 0x5d, 0x40, 0x3f, 0xf8, 0xe1, 0x0a, 0xe0, 0x45, 0xa8, + 0x47, 0xe0, 0x78, 0x23, 0x0f, 0x91, 0x5f, 0x4a, 0x7f, 0xe3, 0xc9, 0x11, 0xe0, 0x4a, 0x09, 0xfe, + 0x5a, 0xf0, 0xea, 0x8f, 0x21, 0x57, 0x82, 0xa3, 0xfa, 0x47, 0xc4, 0x8e, 0x0d, 0x8f, 0xcc, 0xfe, + 0x11, 0xf1, 0x22, 0x33, 0x56, 0xe1, 0xf9, 0x1f, 0x9a, 0x83, 0x79, 0x2d, 0xe3, 0xf5, 0x23, 0xf6, + 0x50, 0x64, 0x17, 0xce, 0x4f, 0x12, 0x58, 0x5f, 0xe0, 0xc4, 0x32, 0x0d, 0xfc, 0xab, 0xd5, 0x54, + 0x15, 0x04, 0xfd, 0x91, 0xf1, 0x20, 0x32, 0x0d, 0xe1, 0x48, 0xf8, 0x91, 0xe5, 0x48, 0x09, 0xfc, + 0xdb, 0x7b, 0xab, 0x84, 0x22, 0x0d, 0xfd, 0x23, 0xda, 0xd1, 0xf2, 0x20, 0x2a, 0x11, 0xfe, 0x23, + 0xe7, 0x4f, 0x8c, 0x2f, 0x80, 0xe7, 0x1f, 0x09, 0x40, 0x2f, 0x00, 0xee, 0x7f, 0xf5, 0x1f, 0x12, + 0x3c, 0x0d, 0x40, 0xff, 0xa9, 0xc3, 0x1b, 0x01, 0x42, 0xce, 0x18, 0x5b, 0x52, 0xd9, 0x8a, 0x79, + 0xa7, 0xbc, 0xc5, 0x01, 0x08, 0x41, 0x21, 0xb5, 0xfc, 0x1b, 0x93, 0x1e, 0x8f, 0x60, 0x02, 0x98, + 0xf8, 0xe0, 0x0c, 0x1c, 0x2e, 0x15, 0x00, 0xe7, 0x61, 0x08, 0x02, 0xfd, 0x16, 0x5c, 0xdb, 0xf2, + 0xb8, 0x4f, 0x03, 0xfd, 0x81, 0x8a, 0x88, 0x52, 0x05, 0x20, 0x0e, 0xe9, 0xf9, 0xaa, 0xed, 0x7f, + 0xbf, 0xd0, 0x0b, 0x0b, 0x42, 0x60, 0x85, 0xa1, 0x3f, 0x0a, 0x0b, 0x42, 0x40, 0x08, 0xa8, 0x02, + 0x04, 0xa9, 0x60, 0x46, 0x00, 0x45, 0x40, 0x5c, 0xa7, 0xa6, 0xfa, 0x5c, 0x07, 0xf0, 0xe0, 0xa4, + 0x0f, 0x94, 0xc4, 0x16, 0x82, 0x96, 0x82, 0x94, 0x83, 0x71, 0x76, 0x04, 0x94, 0x8f, 0xa1, 0xf3, + 0x40, 0x00, 0x93, 0x85, 0xa2, 0x50, 0xc0, 0x00, 0x28, 0x1c, 0xbb, 0x03, 0x09, 0x12, 0x5e, 0x91, + 0xaf, 0x21, 0x42, 0x05, 0x09, 0x6b, 0xe5, 0x59, 0x27, 0xcf, 0x8f, 0x88, 0x24, 0x00, 0x90, 0x7c, + 0x60, 0x00, 0x00, 0x17, 0x1a, 0x02, 0x40, 0x2c, 0x03, 0x94, 0x1a, 0xf8, 0x02, 0xa0, 0x80, 0xd2, + 0x15, 0xf5, 0x64, 0x00, 0xc0, 0x32, 0x01, 0x83, 0xa4, 0xc0, 0x5e, 0xb2, 0x0e, 0x70, 0x9a, 0x7b, + 0x12, 0x23, 0x35, 0x6f, 0x26, 0x43, 0x7f, 0x40, 0x6a, 0x04, 0xe8, 0x14, 0x04, 0xa4, 0xb3, 0x14, + 0x81, 0x30, 0x2f, 0x16, 0x84, 0xd0, 0x0c, 0x0b, 0x42, 0x6e, 0x14, 0x00, 0x9a, 0x00, 0x87, 0x76, + 0x80, 0x07, 0x98, 0x2c, 0x03, 0x99, 0x9c, 0xf3, 0xbb, 0x7f, 0xb8, 0xa4, 0xdb, 0xde, 0xfc, 0x4a, + 0x00, 0x05, 0xa4, 0xc2, 0x6a, 0xc0, 0xed, 0x3d, 0x15, 0xc1, 0x04, 0xe1, 0x30, 0x2e, 0x2c, 0xf1, + 0x50, 0x69, 0x84, 0xa9, 0x0f, 0xf8, 0xc2, 0xbe, 0x35, 0xa8, 0x87, 0x50, 0x10, 0x0e, 0x00, 0xe5, + 0x1e, 0xc6, 0xa9, 0x55, 0xfe, 0xff, 0x48, 0xf5, 0xe0, 0x53, 0xdc, 0x78, 0x80, 0x10, 0x51, 0x89, + 0x52, 0xc0, 0x06, 0xab, 0x03, 0x14, 0x6f, 0xed, 0x85, 0xde, 0x80, 0x03, 0x09, 0x52, 0xe5, 0xff, + 0x5e, 0x02, 0xbf, 0x8f, 0x8f, 0xc9, 0xcf, 0xe5, 0xeb, 0xf3, 0x72, 0xbb, 0x80, 0x00, 0xc6, 0x6a, + 0xd8, 0x08, 0x95, 0xf4, 0xb2, 0xf9, 0x4f, 0xa1, 0xc1, 0xc2, 0x5a, 0xef, 0xf7, 0xfa, 0x81, 0xdd, + 0xbd, 0xef, 0xee, 0xe0, 0xd1, 0xe5, 0x72, 0xc5, 0xcd, 0xf0, 0x2c, 0x00, 0x03, 0xcb, 0x98, 0xf0, + 0x7f, 0x52, 0x00 +}; + +static const BYTE TEST_RDP5_UNCOMPRESSED_DATA[] = { + 0x24, 0x02, 0x03, 0x09, 0x00, 0x20, 0x0c, 0x05, 0x10, 0x01, 0x40, 0x0a, 0xff, 0xff, 0x0c, 0x84, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x0d, 0x38, 0x01, 0xc0, 0x10, 0x01, 0x10, + 0x01, 0xcc, 0xff, 0x7f, 0x03, 0x08, 0x00, 0x20, 0x04, 0x05, 0x10, 0x01, 0x40, 0x0a, 0x00, 0x0c, + 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0x00, 0x01, 0x00, 0x00, 0x0d, 0x0a, + 0x0c, 0x0c, 0xff, 0x03, 0xff, 0x02, 0x00, 0x04, 0x00, 0x03, 0x06, 0x00, 0x00, 0x80, 0x00, 0x80, + 0x00, 0x02, 0x00, 0x00, 0x09, 0x00, 0x0c, 0x80, 0x00, 0x80, 0x00, 0x06, 0x00, 0x00, 0x48, 0x00, + 0x37, 0x01, 0x02, 0x00, 0x00, 0x01, 0x0c, 0x48, 0x00, 0x37, 0x01, 0x06, 0x01, 0x00, 0x00, 0x04, + 0x24, 0x00, 0x02, 0x01, 0x00, 0x01, 0x0c, 0x00, 0x04, 0x24, 0x00, 0x02, 0x00, 0x00, 0x09, 0x0a, + 0x3d, 0x0f, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, + 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, + 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, + 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x09, 0x18, 0xfb, 0x70, 0x06, 0x00, 0x03, + 0xff, 0xff, 0x00, 0x03, 0x00, 0x02, 0x00, 0x0d, 0x00, 0x0c, 0x00, 0x00, 0x80, 0x0c, 0x00, 0x0f, + 0x00, 0x01, 0x49, 0x08, 0x07, 0xc3, 0x66, 0x3c, 0x18, 0x3c, 0x66, 0xc3, 0x00, 0x72, 0x00, 0x19, + 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0xff, 0xff, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, + 0xf3, 0xf2, 0x0c, 0x08, 0x42, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, + 0x99, 0xd6, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x10, 0x84, 0x11, + 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x3a, 0x01, 0x09, 0x99, 0xd6, 0x19, 0x18, 0xf0, 0x60, 0x11, 0x01, + 0x11, 0x01, 0x01, 0x01, 0x00, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, + 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, 0xf4, + 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, + 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, 0x18, + 0xf4, 0x20, 0x10, 0x00, 0x00, 0x0f, 0xff, 0x0f, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, + 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, + 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, + 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, + 0x0a, 0x01, 0x09, 0x19, 0x18, 0xf4, 0x20, 0xff, 0xff, 0x00, 0x11, 0x01, 0x11, 0x01, 0x01, 0x11, + 0xf4, 0x20, 0x10, 0x84, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0xdd, 0x0c, 0xf5, + 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, + 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, + 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, + 0x0a, 0x01, 0x09, 0x19, 0x18, 0xf4, 0x60, 0x00, 0x00, 0x00, 0xd0, 0x0e, 0xd0, 0x0e, 0x0e, 0x0b, + 0x01, 0x01, 0x43, 0x06, 0x02, 0xfc, 0xfc, 0x00, 0x00, 0x30, 0x00, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, + 0xf5, 0x04, 0xff, 0xff, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0x08, + 0x42, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x99, 0xd6, 0x11, 0x0f, + 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x10, 0x84, 0x11, 0x0d, 0x01, 0x0b, 0xf6, + 0x11, 0x3a, 0x01, 0x09, 0x99, 0xd6, 0x19, 0x18, 0xf0, 0x60, 0x11, 0x01, 0x11, 0x01, 0x01, 0x01, + 0x01, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, + 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, + 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x99, + 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, 0x18, 0xf4, 0x20, 0x10, 0x00, + 0x00, 0x0f, 0xff, 0x0f, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, + 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, + 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, + 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, + 0x18, 0xf4, 0x20, 0xff, 0xff, 0x00, 0x11, 0x01, 0x11, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, 0x84, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0xdd, 0x0c, 0xf5, 0x04, 0x08, 0x42, 0x11, + 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, + 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, + 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, + 0x18, 0xf4, 0x60, 0x00, 0x00, 0x00, 0xd0, 0x0e, 0xd0, 0x0e, 0x0e, 0x13, 0x02, 0x00, 0x4a, 0x08, + 0x09, 0x3f, 0x3f, 0x21, 0xfd, 0xfd, 0x87, 0x84, 0x84, 0xfc, 0x00, 0x00, 0x00, 0x32, 0x00, 0x19, + 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0xff, 0xff, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, + 0xf3, 0xf2, 0x0c, 0x08, 0x42, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, + 0x99, 0xd6, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x10, 0x84, 0x11, + 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x3a, 0x01, 0x09, 0x99, 0xd6, 0x19, 0x18, 0xf0, 0x60, 0x11, 0x01, + 0x11, 0x01, 0x01, 0x01, 0x02, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, + 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, 0xf4, + 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, + 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, 0x18, + 0xf4, 0x20, 0x10, 0x00, 0x00, 0x0f, 0xff, 0x0f, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, + 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, + 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, + 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, + 0x0a, 0x01, 0x09, 0x19, 0x18, 0x54, 0x40, 0x00, 0x00, 0x00, 0x10, 0x10, 0x13, 0x03, 0x02, 0x4a, + 0x06, 0x09, 0x78, 0xcc, 0xcc, 0x18, 0x30, 0x30, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x73, 0x00, + 0x19, 0x0a, 0x3f, 0xdd, 0x0c, 0xf5, 0x04, 0xff, 0xff, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, + 0x3e, 0xf3, 0xf2, 0x0c, 0x08, 0x42, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, + 0x0b, 0x99, 0xd6, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x10, 0x84, + 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x3a, 0x01, 0x09, 0x99, 0xd6, 0x19, 0x18, 0xf0, 0x60, 0xd1, + 0x0f, 0xd1, 0x0f, 0x0f, 0x01, 0x03, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, + 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, + 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, + 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, + 0x18, 0xf4, 0x20, 0x10, 0x00, 0x00, 0x0f, 0xff, 0x0f, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, + 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, + 0xff, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, + 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, + 0x11, 0x0a, 0x01, 0x09, 0x19, 0x18, 0x54, 0x40, 0x00, 0x00, 0x00, 0x10, 0x10, 0x1b, 0x04, 0x00, + 0x4a, 0x09, 0x09, 0xff, 0x80, 0xff, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0xff, 0x80, 0x00, 0x00, 0x31, 0x00, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, + 0xff, 0xff, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0x08, 0x42, 0x11, + 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x99, 0xd6, 0x11, 0x0f, 0xf3, 0x0b, + 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x10, 0x84, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x3a, + 0x01, 0x09, 0x99, 0xd6, 0x19, 0x18, 0xf0, 0x60, 0x11, 0x01, 0x11, 0x01, 0x01, 0x01, 0x04, 0x19, + 0x0a, 0x3f, 0xdd, 0x0c, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0d, 0x0e, 0xf3, 0x11, 0x3e, + 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0b, + 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, 0xf4, 0x0a, 0x99, 0xd6, 0x11, + 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, 0x18, 0xf4, 0x20, 0x10, 0x00, 0x00, 0xcf, + 0x0d, 0xcf, 0x0d, 0x0d, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, + 0x0d, 0x0e, 0xf3, 0x11, 0x3e, 0xf3, 0xf2, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0d, 0xf4, 0x11, + 0x3f, 0x0d, 0x01, 0xf3, 0x0b, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0b, 0x0c, 0xf5, 0x11, 0x3e, 0xf5, + 0xf4, 0x0a, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0b, 0xf6, 0x11, 0x0a, 0x01, 0x09, 0x19, 0x18, 0xf4, + 0x20, 0xff, 0xff, 0x00, 0x11, 0x01, 0x11, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, 0x84, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0xee, 0x34, 0x3c, 0x08, 0x2d, 0x09, 0x59, 0x0d, 0x97, + 0xff, 0x00, 0x02, 0x70, 0x0d, 0x0e, 0x51, 0xc2, 0x10, 0x20, 0x1c, 0x51, 0xc2, 0x12, 0xe0, 0xd6, + 0x51, 0xc2, 0x12, 0x30, 0x1c, 0x19, 0x0a, 0x32, 0x12, 0x10, 0x84, 0x59, 0x0d, 0xc6, 0xcc, 0x12, + 0xd0, 0xf2, 0x51, 0xc2, 0x10, 0x20, 0x1c, 0x51, 0xc2, 0x12, 0xe0, 0xd6, 0x51, 0xc2, 0x12, 0x30, + 0x1c, 0x19, 0x0a, 0x3f, 0x0a, 0x12, 0xb9, 0xf9, 0x08, 0x42, 0x11, 0x0f, 0xf6, 0x0a, 0x09, 0xf6, + 0x11, 0x3e, 0xf6, 0xf7, 0x09, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x08, 0xf7, 0x11, 0x3f, 0x08, 0x01, + 0xf8, 0x08, 0x10, 0x84, 0x11, 0x0f, 0xf8, 0x08, 0x07, 0xf8, 0x11, 0x3e, 0xf8, 0xf9, 0x07, 0x99, + 0xd6, 0x11, 0x0d, 0x01, 0x06, 0xf9, 0x11, 0x0a, 0x01, 0x06, 0x19, 0x18, 0xf5, 0x60, 0x05, 0x00, + 0x00, 0x00, 0xef, 0x5a, 0xec, 0x57, 0x57, 0x0f, 0x00, 0x00, 0x46, 0x06, 0x05, 0xcc, 0x78, 0x30, + 0x78, 0xcc, 0x00, 0x00, 0x00, 0x72, 0x00, 0x19, 0x0a, 0x3f, 0x13, 0xfe, 0xfa, 0x04, 0xff, 0xff, + 0x11, 0x0f, 0xf6, 0x0a, 0x09, 0xf6, 0x11, 0x3e, 0xf6, 0xf7, 0x09, 0x08, 0x42, 0x11, 0x0d, 0x01, + 0x08, 0xf7, 0x11, 0x3f, 0x08, 0x01, 0xf8, 0x08, 0x99, 0xd6, 0x11, 0x0f, 0xf8, 0x08, 0x07, 0xf8, + 0x11, 0x3e, 0xf8, 0xf9, 0x07, 0x10, 0x84, 0x11, 0x0d, 0x01, 0x06, 0xf9, 0x11, 0x3a, 0x01, 0x06, + 0x99, 0xd6, 0x19, 0x18, 0xf0, 0x60, 0x0c, 0x01, 0x0c, 0x01, 0x01, 0x01, 0x00, 0x19, 0x0a, 0x3f, + 0x13, 0xfe, 0xfa, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf6, 0x0a, 0x09, 0xf6, 0x11, 0x3e, 0xf6, 0xf7, + 0x09, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x08, 0xf7, 0x11, 0x3f, 0x08, 0x01, 0xf8, 0x08, 0x10, 0x84, + 0x11, 0x0f, 0xf8, 0x08, 0x07, 0xf8, 0x11, 0x3e, 0xf8, 0xf9, 0x07, 0x99, 0xd6, 0x11, 0x0d, 0x01, + 0x06, 0xf9, 0x11, 0x0a, 0x01, 0x06, 0x19, 0x18, 0xf4, 0x20, 0x10, 0x00, 0x00, 0x0a, 0xff, 0x0a, + 0xff, 0xff, 0x19, 0x0a, 0x3f, 0x13, 0xfe, 0xfa, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf6, 0x0a, 0x09, + 0xf6, 0x11, 0x3e, 0xf6, 0xf7, 0x09, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x08, 0xf7, 0x11, 0x3f, 0x08, + 0x01, 0xf8, 0x08, 0x10, 0x84, 0x11, 0x0f, 0xf8, 0x08, 0x07, 0xf8, 0x11, 0x3e, 0xf8, 0xf9, 0x07, + 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x06, 0xf9, 0x11, 0x0a, 0x01, 0x06, 0x19, 0x18, 0xf4, 0x20, 0xff, + 0xff, 0x00, 0x0c, 0x01, 0x0c, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, 0x84, 0x00, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x19, 0x0a, 0x0f, 0x09, 0xfe, 0x09, 0x09, 0x19, 0x18, 0xf5, 0x60, 0x06, 0xff, 0xff, + 0x00, 0x09, 0xfe, 0x12, 0x07, 0x07, 0x23, 0x05, 0x03, 0x4d, 0x0d, 0x0d, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x88, 0x01, 0x10, 0x02, 0x20, 0x04, 0x40, 0x08, 0x88, + 0x11, 0x10, 0x22, 0x20, 0x44, 0x40, 0x00, 0x00, 0x6f, 0x00, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, + 0x1f, 0x06, 0x04, 0x4c, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x30, 0x00, 0x60, 0x00, 0xc0, + 0x01, 0x90, 0x03, 0x30, 0x06, 0x60, 0x0c, 0xc0, 0x19, 0x90, 0x33, 0x30, 0x66, 0x60, 0x70, 0x00, + 0x19, 0x0a, 0x37, 0xe3, 0x10, 0xf1, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, + 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, + 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, + 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x60, 0x00, 0x00, + 0x00, 0xd6, 0x12, 0xd2, 0x0e, 0x0e, 0x0f, 0x07, 0x01, 0x48, 0x09, 0x04, 0x08, 0x00, 0x1c, 0x00, + 0x3e, 0x00, 0x7f, 0x00, 0x35, 0x00, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x10, 0x84, 0x11, + 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x0e, 0xf1, 0xf2, 0x0e, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, + 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x99, 0xd6, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x0e, 0xf3, + 0xf4, 0x0c, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x0a, 0x01, 0x0b, 0x19, 0x18, 0xf0, 0x60, 0x11, + 0x01, 0x11, 0x01, 0x01, 0x01, 0x07, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, + 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, + 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, + 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, + 0xd6, 0x19, 0x18, 0xf4, 0x20, 0x10, 0x00, 0x00, 0x0f, 0xff, 0x0f, 0xff, 0xff, 0x19, 0x0a, 0x3f, + 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, 0xf1, 0xf2, + 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x10, 0x84, + 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, + 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x20, 0xff, 0xff, 0x00, 0x11, + 0x01, 0x11, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, 0x84, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x19, + 0x0a, 0x3f, 0xdd, 0x0e, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, + 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, + 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, + 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x60, 0x00, 0x00, + 0x00, 0xd0, 0x10, 0xd0, 0x10, 0x10, 0x0f, 0x08, 0x01, 0x48, 0x09, 0x04, 0x7f, 0x00, 0x3e, 0x00, + 0x1c, 0x00, 0x08, 0x00, 0x36, 0x00, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x10, 0x84, 0x11, + 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x0e, 0xf1, 0xf2, 0x0e, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, + 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x99, 0xd6, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x0e, 0xf3, + 0xf4, 0x0c, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x0a, 0x01, 0x0b, 0x19, 0x18, 0xf0, 0x60, 0x11, + 0x01, 0x11, 0x01, 0x01, 0x01, 0x08, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, + 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, + 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, + 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, + 0xd6, 0x19, 0x18, 0xf4, 0x20, 0x10, 0x00, 0x00, 0x0f, 0xff, 0x0f, 0xff, 0xff, 0x19, 0x0a, 0x3f, + 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, 0xf1, 0xf2, + 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x10, 0x84, + 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, + 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x20, 0xff, 0xff, 0x00, 0x11, + 0x01, 0x11, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, 0x84, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x19, + 0x0a, 0x3f, 0xdd, 0x0e, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, + 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, + 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, + 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x60, 0x00, 0x00, + 0x00, 0xd0, 0x10, 0xd0, 0x10, 0x10, 0x13, 0x09, 0x04, 0x4b, 0x04, 0x09, 0x00, 0x80, 0xc0, 0xe0, + 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, + 0x04, 0x10, 0x84, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x0e, 0xf1, 0xf2, 0x0e, 0x11, 0x0d, + 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x99, 0xd6, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, + 0xf3, 0x11, 0x0e, 0xf3, 0xf4, 0x0c, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x0a, 0x01, 0x0b, 0x19, + 0x18, 0xf0, 0x60, 0x11, 0x01, 0x11, 0x01, 0x01, 0x01, 0x09, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, + 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, 0xf1, 0xf2, 0x0e, 0x99, 0xd6, + 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x10, 0x84, 0x11, 0x0f, 0xf3, + 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, + 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x20, 0x10, 0x00, 0x00, 0x0f, 0xff, 0x0f, 0xff, + 0xff, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, + 0x11, 0x3e, 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, + 0xf3, 0x0d, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, + 0xff, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x20, + 0xff, 0xff, 0x00, 0x11, 0x01, 0x11, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, 0x84, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0xdd, 0x0e, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, + 0x0e, 0xf1, 0x11, 0x3e, 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, + 0x0d, 0x01, 0xf3, 0x0d, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, + 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, + 0xf4, 0x60, 0x00, 0x00, 0x00, 0xd0, 0x10, 0xd0, 0x10, 0x10, 0x13, 0x0a, 0x03, 0x4b, 0x04, 0x09, + 0x00, 0x10, 0x30, 0x70, 0xf0, 0x70, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x19, 0x0a, + 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x10, 0x84, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x0e, 0xf1, + 0xf2, 0x0e, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x99, 0xd6, 0x11, + 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x0e, 0xf3, 0xf4, 0x0c, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, + 0x0a, 0x01, 0x0b, 0x19, 0x18, 0xf0, 0x60, 0x11, 0x01, 0x11, 0x01, 0x01, 0x01, 0x0a, 0x19, 0x0a, + 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, 0xf1, + 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x10, + 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, 0x0d, + 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, 0x19, 0x18, 0xf4, 0x20, 0x10, 0x00, 0x00, + 0x0f, 0xff, 0x0f, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0x1d, 0xfe, 0xf5, 0x04, 0x08, 0x42, 0x11, 0x0f, + 0xf1, 0x0f, 0x0e, 0xf1, 0x11, 0x3e, 0xf1, 0xf2, 0x0e, 0x99, 0xd6, 0x11, 0x0d, 0x01, 0x0d, 0xf2, + 0x11, 0x3f, 0x0d, 0x01, 0xf3, 0x0d, 0x10, 0x84, 0x11, 0x0f, 0xf3, 0x0d, 0x0c, 0xf3, 0x11, 0x3e, + 0xf3, 0xf4, 0x0c, 0xff, 0xff, 0x11, 0x0d, 0x01, 0x0b, 0xf4, 0x11, 0x3a, 0x01, 0x0b, 0x99, 0xd6, + 0x19, 0x18, 0xf4, 0x20, 0xff, 0xff, 0x00, 0x11, 0x01, 0x11, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, + 0x84, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0xce, 0x0e, 0x01, 0x01, 0xff, 0xff, + 0x1d, 0x18, 0xf4, 0x60, 0x0e, 0xe2, 0x00, 0x0b, 0x00, 0xee, 0x00, 0x00, 0x00, 0x00, 0xcd, 0x0e, + 0xce, 0x0f, 0x0f, 0x13, 0x0b, 0x04, 0x4b, 0x04, 0x09, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xe0, 0xc0, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x19, 0x0a, 0x01, 0x0d, 0x19, 0x18, 0x50, 0x40, 0x0d, + 0x0d, 0x0f, 0x0c, 0x03, 0x4a, 0x07, 0x08, 0x00, 0x02, 0x06, 0x8e, 0xdc, 0xf8, 0x70, 0x20, 0x61, + 0x00, 0x19, 0x0a, 0x01, 0x0d, 0x19, 0x18, 0x50, 0x40, 0x0d, 0x0d, 0x0f, 0x0d, 0x04, 0x4a, 0x06, + 0x06, 0x78, 0xfc, 0xfc, 0xfc, 0xfc, 0x78, 0x00, 0x00, 0x68, 0x00, 0x19, 0x0a, 0x3d, 0x0d, 0x02, + 0x02, 0x99, 0xd6, 0x19, 0x18, 0xd0, 0x60, 0x0e, 0x10, 0x02, 0x02, 0x13, 0x0e, 0x02, 0x4a, 0x0b, + 0x05, 0x04, 0x00, 0x0e, 0x00, 0x1f, 0x00, 0x3f, 0x80, 0x7f, 0xc0, 0x00, 0x00, 0x35, 0x00, 0x19, + 0x0a, 0x01, 0x0f, 0x19, 0x18, 0x54, 0x40, 0x10, 0x00, 0x00, 0x0f, 0x0f, 0x01, 0x0e, 0x19, 0x0a, + 0x03, 0xca, 0x0f, 0x19, 0x18, 0xf4, 0x20, 0xff, 0xff, 0x00, 0xcb, 0x10, 0xcb, 0x10, 0x10, 0x11, + 0xf4, 0x20, 0x10, 0x84, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x19, 0x0a, 0x01, 0x0f, 0x19, 0x18, + 0x54, 0x40, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x13, 0x0f, 0x02, 0x4a, 0x0b, 0x05, 0x7f, 0xc0, 0x3f, + 0x80, 0x1f, 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x36, 0x00, 0x19, 0x0a, 0x01, 0x0f, 0x19, + 0x18, 0x54, 0x40, 0x10, 0x00, 0x00, 0x0f, 0x0f, 0x01, 0x0f, 0x19, 0x0a, 0x01, 0x0f, 0x19, 0x18, + 0xf4, 0x20, 0xff, 0xff, 0x00, 0x10, 0x01, 0x10, 0x01, 0x01, 0x11, 0xf4, 0x20, 0x10, 0x84, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x19, 0x0a, 0x3f, 0xd3, 0x0f, 0xfe, 0xfe, 0xff, 0xff, 0x19, 0x18, + 0xf4, 0x60, 0x00, 0x00, 0x00, 0xd3, 0x0f, 0xd1, 0x0d, 0x0d, 0x1b, 0x10, 0x02, 0x4c, 0x0a, 0x0a, + 0x1e, 0x00, 0x7f, 0x80, 0x7f, 0x80, 0xff, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0xff, 0xc0, 0x7f, 0x80, + 0x7f, 0x80, 0x1e, 0x00, 0x6e, 0x00, 0x11, 0x00, 0x40, 0x17, 0x11, 0x03, 0x4a, 0x09, 0x08, 0x01, + 0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x01, 0x00, 0xc3, 0x00, 0x3c, 0x00, 0x6d, + 0x00, 0x11, 0x00, 0x40, 0x17, 0x12, 0x02, 0x4c, 0x09, 0x08, 0x1e, 0x00, 0x61, 0x80, 0x40, 0x00, + 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x40, 0x00, 0x6c, 0x00, 0x11, 0x00, 0x40, 0x1b, + 0x13, 0x03, 0x4b, 0x0a, 0x0a, 0x00, 0x80, 0x00, 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, + 0x40, 0x00, 0x80, 0x00, 0x80, 0xc3, 0x00, 0x3c, 0x00, 0x6b, 0x00, 0x11, 0x00, 0x40, 0x1b, 0x14, + 0x01, 0x4d, 0x0a, 0x0a, 0x0f, 0x00, 0x30, 0xc0, 0x40, 0x00, 0x40, 0x00, 0x80, 0x00, 0x80, 0x00, + 0x80, 0x00, 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x6a, 0x00, 0x11, 0x54, 0x40, 0xff, 0xff, 0x00, + 0x0d, 0x0d, 0x1b, 0x15, 0x02, 0x4b, 0x09, 0x09, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, + 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0xff, 0x80, 0x00, 0x00, 0x67, 0x00, 0x11, 0x04, + 0x40, 0x99, 0xd6, 0x00, 0x1f, 0x16, 0x01, 0x4c, 0x0b, 0x0b, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, + 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0xff, 0xe0, + 0x00, 0x00, 0x66, 0x00, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x1b, 0x17, 0x01, 0x4c, 0x0a, 0x0a, + 0xff, 0xc0, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, + 0x80, 0x00, 0x80, 0x00, 0x65, 0x00, 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, 0x23, 0x18, 0x00, 0x4d, + 0x0d, 0x0d, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, + 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0xff, 0xf8, 0x00, 0x00, 0x64, 0x00, + 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x1f, 0x19, 0x00, 0x4d, 0x0c, 0x0c, 0xff, 0xf0, 0x80, 0x00, + 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, + 0x80, 0x00, 0x80, 0x00, 0x63, 0x00, 0x11, 0x54, 0x40, 0xff, 0xff, 0x00, 0x0d, 0x0d, 0x01, 0x15, + 0x11, 0x04, 0x40, 0x99, 0xd6, 0x00, 0x01, 0x16, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x17, + 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, 0x01, 0x18, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x19, + 0x11, 0x04, 0x40, 0x00, 0x00, 0x00, 0x0f, 0x1a, 0x03, 0x4b, 0x07, 0x08, 0x00, 0x02, 0x06, 0x8e, + 0xdc, 0xf8, 0x70, 0x20, 0x62, 0x00, 0x11, 0x54, 0x40, 0x99, 0xd6, 0x00, 0x0d, 0x0d, 0x01, 0x15, + 0x11, 0x00, 0x40, 0x01, 0x16, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x17, 0x11, 0x04, 0x40, + 0xff, 0xff, 0x00, 0x01, 0x18, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x19, 0x11, 0x54, 0x40, + 0x99, 0xd6, 0x00, 0x0d, 0x0d, 0x01, 0x15, 0x11, 0x00, 0x40, 0x01, 0x16, 0x11, 0x04, 0x40, 0x08, + 0x42, 0x00, 0x01, 0x17, 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, 0x01, 0x18, 0x11, 0x04, 0x40, 0x10, + 0x84, 0x00, 0x01, 0x19, 0x11, 0x04, 0x40, 0x00, 0x00, 0x00, 0x01, 0x1a, 0x11, 0xf4, 0x60, 0x99, + 0xd6, 0x00, 0xcc, 0x0d, 0xcc, 0x0d, 0x0d, 0x01, 0x15, 0x11, 0x00, 0x40, 0x01, 0x16, 0x11, 0x04, + 0x40, 0x08, 0x42, 0x00, 0x01, 0x17, 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, 0x01, 0x18, 0x11, 0x04, + 0x40, 0x10, 0x84, 0x00, 0x01, 0x19, 0x11, 0x00, 0x40, 0x01, 0x1a, 0x19, 0x0a, 0x33, 0x0d, 0x0d, + 0x00, 0x00, 0x19, 0x18, 0x54, 0x40, 0xff, 0xff, 0x00, 0x0d, 0x0d, 0x01, 0x10, 0x11, 0x04, 0x40, + 0x99, 0xd6, 0x00, 0x01, 0x11, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x12, 0x11, 0x04, 0x40, + 0xff, 0xff, 0x00, 0x01, 0x13, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x14, 0x19, 0x0a, 0x01, + 0x0d, 0x19, 0x18, 0x54, 0x40, 0xff, 0xff, 0x00, 0x0d, 0x0d, 0x01, 0x10, 0x11, 0x04, 0x40, 0x99, + 0xd6, 0x00, 0x01, 0x11, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x12, 0x11, 0x04, 0x40, 0xff, + 0xff, 0x00, 0x01, 0x13, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x14, 0x11, 0x04, 0x40, 0x00, + 0x00, 0x00, 0x0b, 0x1b, 0x05, 0x49, 0x04, 0x04, 0x60, 0xf0, 0xf0, 0x60, 0x69, 0x00, 0x19, 0x0a, + 0x01, 0x0d, 0x19, 0x18, 0x54, 0x40, 0x99, 0xd6, 0x00, 0x0d, 0x0d, 0x01, 0x10, 0x11, 0x00, 0x40, + 0x01, 0x11, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x12, 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, + 0x01, 0x13, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x14, 0x19, 0x0a, 0x01, 0x0d, 0x19, 0x18, + 0x54, 0x40, 0x99, 0xd6, 0x00, 0x0d, 0x0d, 0x01, 0x10, 0x11, 0x00, 0x40, 0x01, 0x11, 0x11, 0x04, + 0x40, 0x08, 0x42, 0x00, 0x01, 0x12, 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, 0x01, 0x13, 0x11, 0x04, + 0x40, 0x10, 0x84, 0x00, 0x01, 0x14, 0x11, 0x04, 0x40, 0x00, 0x00, 0x00, 0x01, 0x1b, 0x19, 0x0a, + 0x03, 0xcc, 0x0d, 0x19, 0x18, 0xf4, 0x60, 0x99, 0xd6, 0x00, 0xcc, 0x0d, 0xcc, 0x0d, 0x0d, 0x01, + 0x10, 0x11, 0x00, 0x40, 0x01, 0x11, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x12, 0x11, 0x04, + 0x40, 0xff, 0xff, 0x00, 0x01, 0x13, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x14, 0x11, 0x00, + 0x40, 0x01, 0x1b, 0x03, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x08, 0x08, 0x81, 0x08, 0xaa, + 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0x09, 0x01, 0x7f, 0x02, 0x0d, 0x00, 0x1a, 0x01, 0x0d, + 0x00, 0x0d, 0x00, 0xf0, 0xff, 0xff, 0x00, 0x99, 0xd6, 0x00, 0x81, 0x19, 0x18, 0x54, 0x40, 0x99, + 0xd6, 0x00, 0x0d, 0x0d, 0x01, 0x16, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x17, 0x11, 0x04, + 0x40, 0xff, 0xff, 0x00, 0x01, 0x18, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x19, 0x11, 0x00, + 0x40, 0x01, 0x1a, 0x11, 0x54, 0x40, 0x99, 0xd6, 0x00, 0x0d, 0x0d, 0x01, 0x15, 0x11, 0x00, 0x40, + 0x01, 0x16, 0x11, 0x04, 0x40, 0x08, 0x42, 0x00, 0x01, 0x17, 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, + 0x01, 0x18, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x01, 0x19, 0x11, 0x00, 0x40, 0x01, 0x1a, 0x11, + 0x54, 0x40, 0x99, 0xd6, 0x00, 0x0d, 0x0d, 0x01, 0x15, 0x11, 0x00, 0x40, 0x01, 0x16, 0x11, 0x04, + 0x40, 0x08, 0x42, 0x00, 0x01, 0x17, 0x11, 0x04, 0x40, 0xff, 0xff, 0x00, 0x01, 0x18, 0x11, 0x04, + 0x40, 0x10, 0x84, 0x00, 0x01, 0x19, 0x11, 0x00, 0x40, 0x01, 0x1a, 0x19, 0x0a, 0x31, 0x34, 0xff, + 0xff, 0x19, 0x18, 0x54, 0x40, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x1b, 0x1c, 0x02, 0x4b, 0x09, 0x09, + 0xc1, 0x80, 0xe3, 0x80, 0x77, 0x00, 0x3e, 0x00, 0x1c, 0x00, 0x3e, 0x00, 0x77, 0x00, 0xe3, 0x80, + 0xc1, 0x80, 0x00, 0x00, 0x72, 0x00, 0x19, 0x0a, 0x03, 0xcc, 0x0d, 0x1d, 0x18, 0xf0, 0x60, 0xa0, + 0x45, 0x45, 0xcc, 0x0d, 0xcc, 0x0d, 0x0d, 0x1b, 0x1d, 0x01, 0x4b, 0x0a, 0x09, 0x3f, 0xc0, 0x3f, + 0xc0, 0x20, 0x40, 0xff, 0x40, 0xff, 0x40, 0x81, 0xc0, 0x81, 0x00, 0x81, 0x00, 0xff, 0x00, 0x00, + 0x00, 0x32, 0x00, 0x19, 0x0a, 0x01, 0x0d, 0x19, 0x18, 0x50, 0x40, 0x0d, 0x0d, 0x1b, 0x1e, 0x01, + 0x4c, 0x0a, 0x0a, 0xff, 0xc0, 0xff, 0xc0, 0x80, 0x40, 0x80, 0x40, 0x80, 0x40, 0x80, 0x40, 0x80, + 0x40, 0x80, 0x40, 0x80, 0x40, 0xff, 0xc0, 0x31, 0x00, 0x19, 0x0a, 0x01, 0x0d, 0x19, 0x18, 0x50, + 0x40, 0x0d, 0x0d, 0x0b, 0x1f, 0x02, 0x44, 0x07, 0x02, 0xfe, 0xfe, 0x00, 0x00, 0x30, 0x00, 0x19, + 0x0a, 0x3d, 0x0d, 0x03, 0x03, 0x99, 0xd6, 0x19, 0x18, 0xd4, 0x60, 0xff, 0xff, 0x00, 0x0e, 0x11, + 0x03, 0x03, 0x23, 0x20, 0x00, 0x4d, 0x0d, 0x0d, 0x00, 0x00, 0x80, 0x00, 0x40, 0x00, 0x20, 0x00, + 0x10, 0x00, 0x88, 0x00, 0x44, 0x00, 0x22, 0x00, 0x11, 0x00, 0x88, 0x80, 0x44, 0x40, 0x22, 0x20, + 0x11, 0x10, 0x00, 0x00, 0x78, 0x00, 0x11, 0x04, 0x40, 0x10, 0x84, 0x00, 0x1f, 0x21, 0x00, 0x4c, + 0x0c, 0x0c, 0x00, 0x00, 0x80, 0x00, 0xc0, 0x00, 0x60, 0x00, 0x30, 0x00, 0x98, 0x00, 0xcc, 0x00, + 0x66, 0x00, 0x33, 0x00, 0x99, 0x80, 0xcc, 0xc0, 0x66, 0x60, 0x79, 0x00, 0x19, 0x0a, 0x3d, 0x10, + 0xfd, 0xfd, 0xff, 0xff, 0x19, 0x18, 0xd4, 0x60, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0xfd, 0xfd, 0x13, + 0x22, 0x05, 0x4b, 0x04, 0x09, 0x00, 0x10, 0x30, 0x70, 0xf0, 0x70, 0x30, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x77, 0x00, 0x02, 0xff, 0xff, 0x0d, 0x0a, 0x3f, 0x0e, 0x00, 0x00, 0xff, 0x03, 0xff, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00, 0x06, 0x02, 0x00, 0x48, 0x00, 0x37, + 0x01, 0x02, 0x02, 0x00, 0x09, 0x00, 0x0c, 0x48, 0x00, 0x37, 0x01, 0x03, 0xcf, 0x04, 0xa2, 0x0c, + 0x05, 0x40, 0x44, 0xd1, 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x00, + 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x00, + 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x84, 0x08, 0x42, 0xff, 0xff, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x84, + 0xff, 0xff, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x84, + 0xff, 0xff, 0x99, 0xd6, 0x10, 0x84, 0x08, 0x42, 0x1c, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x75, 0xc6, 0x66, 0x29, 0x00, 0x09, 0x68, 0x10, 0x00, 0x08, 0x68, 0x10, 0x84, + 0x00, 0x20, 0x00, 0x07, 0x6b, 0x99, 0xd6, 0x05, 0x6b, 0x99, 0xd6, 0x00, 0x03, 0x6e, 0xff, 0xff, + 0x02, 0x6e, 0xff, 0xff, 0x00, 0x10, 0xc0, 0x00, 0xf7, 0xbd, 0x01, 0xc0, 0x00, 0x08, 0x42, 0xc0, + 0x00, 0xff, 0xff, 0x81, 0x08, 0x42, 0xce, 0x66, 0x29, 0x01, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0xfd, + 0x2e, 0x01, 0x81, 0x08, 0x42, 0xce, 0x66, 0x29, 0x02, 0x81, 0x10, 0x84, 0x06, 0x82, 0x00, 0x00, + 0x00, 0x00, 0x07, 0xcd, 0x89, 0x52, 0x03, 0x2d, 0x03, 0x83, 0x10, 0x84, 0x99, 0xd6, 0x99, 0xd6, + 0xc9, 0x99, 0xd6, 0x1a, 0x82, 0x10, 0x00, 0x10, 0x00, 0x0a, 0x29, 0x09, 0x27, 0x0c, 0x67, 0x99, + 0xd6, 0x15, 0x27, 0x1d, 0x82, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x67, 0x99, 0xd6, 0x00, 0x19, 0xd0, + 0x30, 0x89, 0xd6, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x99, 0xd6, 0x05, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x83, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x0b, 0xd8, 0x89, + 0xd6, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x83, 0x99, 0xd6, 0x10, 0x00, 0x10, + 0x00, 0x1a, 0x68, 0x00, 0x00, 0x09, 0x86, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x99, 0xd6, 0x18, 0x68, 0x00, 0x00, 0x1b, 0x68, 0x99, 0xd6, 0x06, 0x86, 0x99, 0xd6, 0x10, + 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x99, 0xd6, 0x19, 0x6b, 0x99, 0xd6, 0x03, 0xcc, 0x89, + 0x52, 0x08, 0x68, 0x99, 0xd6, 0x05, 0x6b, 0x99, 0xd6, 0x04, 0x2c, 0x03, 0x6e, 0x08, 0x42, 0x02, + 0x6e, 0xff, 0xff, 0x02, 0x6e, 0xff, 0xff, 0x02, 0x6e, 0x08, 0x42, 0x10, 0x81, 0x08, 0x42, 0x70, + 0xff, 0xff, 0x60, 0x00, 0x08, 0x42, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0x81, 0x08, 0x42, 0xce, 0x66, + 0x29, 0x01, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0xfd, 0x2e, 0x02, 0xcd, 0x89, 0x52, 0x03, 0x89, 0x10, + 0x84, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x07, 0x2d, 0x03, 0x2d, 0x05, 0xc6, 0x99, 0xd6, 0x0c, 0x84, 0x99, 0xd6, 0x99, 0xd6, 0x99, + 0xd6, 0x99, 0xd6, 0x0a, 0xc6, 0x89, 0xd6, 0x0e, 0x82, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x84, 0x99, + 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x1c, 0x40, 0x35, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xd0, 0x4e, 0x99, 0xd6, 0x03, 0x00, 0x00, 0x60, 0x00, 0x80, 0x01, 0x78, 0x01, 0x00, 0x82, + 0x10, 0x00, 0x10, 0x00, 0x0c, 0x40, 0x2c, 0x03, 0xe0, 0x05, 0x00, 0x00, 0x00, 0xd6, 0x89, 0xd6, + 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x4e, 0x99, 0xd6, 0x3b, 0x00, 0x00, 0x00, 0x28, 0x80, + 0x1d, 0x00, 0x78, 0x00, 0x86, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x99, + 0xd6, 0x0c, 0x85, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x40, 0x2b, 0x01, + 0xf0, 0x00, 0x00, 0x00, 0x00, 0xd6, 0x89, 0xd6, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x99, + 0xd6, 0x16, 0x86, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x0a, + 0x69, 0x99, 0xd6, 0x04, 0xcc, 0x89, 0x52, 0x07, 0x69, 0x99, 0xd6, 0x08, 0x68, 0x99, 0xd6, 0x03, + 0x6e, 0xff, 0xff, 0x02, 0x6e, 0x08, 0x42, 0x02, 0x6e, 0xff, 0xff, 0x02, 0x6e, 0xff, 0xff, 0x01, + 0x70, 0x08, 0x42, 0x70, 0xff, 0xff, 0x60, 0x00, 0x08, 0x42, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0x81, + 0x08, 0x42, 0xce, 0x66, 0x29, 0x01, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0xfd, 0x2e, 0x02, 0xcd, 0x89, + 0x52, 0x03, 0x8a, 0x10, 0x84, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x2d, 0x03, 0x8d, 0x99, 0xd6, 0x99, 0xd6, 0x99, + 0xd6, 0x99, 0xd6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x99, + 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x06, 0xc6, 0x99, 0xd6, 0x1a, 0xc6, 0x89, 0xd6, 0x0a, 0x66, 0x10, + 0x84, 0x1b, 0x6a, 0x99, 0xd6, 0x1b, 0x81, 0x99, 0xd6, 0x09, 0x6a, 0x99, 0xd6, 0x16, 0x6a, 0x99, + 0xd6, 0x06, 0x6a, 0x99, 0xd6, 0xf0, 0x94, 0x01, 0xcc, 0x89, 0x52, 0x00, 0x03, 0x6e, 0xff, 0xff, + 0x02, 0x6e, 0x08, 0x42, 0x02, 0x6e, 0xff, 0xff, 0x02, 0x6e, 0xff, 0xff, 0x01, 0x70, 0x08, 0x42, + 0x70, 0xff, 0xff, 0x60, 0x00, 0x08, 0x42, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0x81, 0x08, 0x42, 0xce, + 0x66, 0x29, 0x01, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0xfd, 0x2e, 0x02, 0xcd, 0x89, 0x52, 0x03, 0x10, + 0x2d, 0x03, 0x2d, 0x17, 0x88, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, + 0xd6, 0x00, 0x00, 0x00, 0x00, 0x18, 0x88, 0xff, 0xff, 0xff, 0xff, 0x99, 0xd6, 0x99, 0xd6, 0x99, + 0xd6, 0x99, 0xd6, 0xff, 0xff, 0xff, 0xff, 0x07, 0x88, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, + 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x09, 0x88, 0x99, 0xd6, 0x00, 0x00, 0x00, + 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x07, 0x88, 0x10, 0x00, 0x10, + 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x00, 0x10, 0x00, 0x08, 0x89, 0x10, + 0x84, 0x10, 0x84, 0xff, 0xff, 0xff, 0xff, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x84, 0x10, 0x84, 0x99, + 0xd6, 0x07, 0x88, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x00, + 0x00, 0x99, 0xd6, 0x0a, 0x86, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, + 0xd6, 0x08, 0x88, 0x99, 0xd6, 0x10, 0x00, 0x10, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x00, 0x10, + 0x00, 0x99, 0xd6, 0x08, 0x88, 0x99, 0xd6, 0x10, 0x84, 0x10, 0x84, 0xff, 0xff, 0xff, 0xff, 0x10, + 0x84, 0x10, 0x84, 0x99, 0xd6, 0x09, 0x86, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x99, 0xd6, 0x0c, 0x84, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x0a, 0x86, 0x99, + 0xd6, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x99, 0xd6, 0x0a, 0x86, 0x99, 0xd6, 0x10, + 0x84, 0x10, 0x84, 0x10, 0x84, 0x10, 0x84, 0x99, 0xd6, 0x0b, 0x84, 0x99, 0xd6, 0x00, 0x00, 0x00, + 0x00, 0x99, 0xd6, 0x0d, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x84, 0x99, + 0xd6, 0x10, 0x00, 0x10, 0x00, 0x99, 0xd6, 0x0c, 0x85, 0x99, 0xd6, 0x10, 0x84, 0x10, 0x84, 0xff, + 0xff, 0xff, 0xff, 0x0b, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x86, 0x00, + 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x84, 0x10, 0x00, 0x10, + 0x00, 0x10, 0x00, 0x10, 0x00, 0x0c, 0x86, 0x10, 0x84, 0x10, 0x84, 0x10, 0x84, 0x10, 0x84, 0xff, + 0xff, 0xff, 0xff, 0x09, 0x86, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x00, 0x00, 0x00, + 0x00, 0x0a, 0x88, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x86, 0x10, 0x00, 0x10, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x00, 0x10, + 0x00, 0x0a, 0x88, 0x10, 0x84, 0x10, 0x84, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x84, 0x10, 0x84, 0xff, + 0xff, 0xff, 0xff, 0x07, 0x88, 0x00, 0x00, 0x00, 0x00, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, + 0xd6, 0x00, 0x00, 0x00, 0x00, 0x09, 0x6a, 0x99, 0xd6, 0x05, 0x88, 0x10, 0x00, 0x10, 0x00, 0x99, + 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x00, 0x10, 0x00, 0x08, 0x89, 0x10, 0x84, 0x10, + 0x84, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x10, 0x84, 0x10, 0x84, 0x99, 0xd6, 0x07, + 0x6a, 0x99, 0xd6, 0x16, 0x6a, 0x99, 0xd6, 0x06, 0x6a, 0x99, 0xd6, 0x14, 0x2c, 0x00, 0x03, 0x6e, + 0xff, 0xff, 0x02, 0x6e, 0x08, 0x42, 0x02, 0x6e, 0xff, 0xff, 0x02, 0xcb, 0x66, 0x29, 0x84, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x08, 0x42, 0x09, 0x0d, 0xdf, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x03, 0x15, 0x00, 0xa2, 0x0c, + 0x05, 0x40, 0x40, 0x17, 0xff, 0xff, 0x00, 0x1c, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf0, 0xbc, 0x0f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x0a, 0x40, + 0xc8, 0x03, 0xf4, 0x00, 0xa2, 0x0c, 0x05, 0x40, 0x40, 0xf6, 0xff, 0xff, 0xc0, 0x2c, 0x2d, 0x09, + 0x84, 0x2d, 0x09, 0x2d, 0x09, 0x2d, 0x09, 0x2d, 0x09, 0x00, 0x22, 0xc0, 0x10, 0x25, 0x4b, 0x02, + 0x30, 0x02, 0x2a, 0x02, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0xfd, 0x2e, 0x03, 0xfd, 0x2e, 0x03, 0xfd, + 0x29, 0x03, 0xcd, 0x89, 0x52, 0x03, 0x2d, 0x05, 0x2d, 0x05, 0x29, 0x06, 0xc6, 0x99, 0xd6, 0x09, + 0x29, 0x1f, 0x43, 0x03, 0x00, 0x00, 0x01, 0x27, 0x0b, 0x44, 0xc3, 0x00, 0x00, 0xc0, 0x68, 0x99, + 0xd6, 0x18, 0x48, 0xa5, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xc2, 0x5a, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0xa0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x81, 0x99, 0xd6, 0x48, 0x05, 0x80, 0x05, 0x00, 0x00, 0xfc, + 0x01, 0x50, 0x40, 0x69, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0c, 0x80, 0x06, 0x00, + 0x00, 0x02, 0x6a, 0x99, 0xd6, 0x1c, 0x86, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0x2d, + 0x09, 0x2d, 0x09, 0x6f, 0xff, 0xff, 0x02, 0x6e, 0xff, 0xff, 0x04, 0x6e, 0xff, 0xff, 0x04, 0xc9, + 0x66, 0x29, 0x02, 0x60, 0x5e, 0x2d, 0x09, 0xc0, 0x30, 0x2d, 0x09, 0xf0, 0xc0, 0x09, 0xc0, 0x10, + 0x08, 0x42, 0x00, 0x00, 0xfd, 0xce, 0x18, 0xc6, 0x01, 0xfd, 0x2e, 0x00, 0x02, 0xcd, 0x89, 0x52, + 0x03, 0x83, 0x99, 0xd6, 0x99, 0xd6, 0x99, 0xd6, 0xc9, 0xef, 0x7b, 0x81, 0x99, 0xd6, 0x00, 0x05, + 0xc9, 0x89, 0xd6, 0x07, 0x69, 0x10, 0x84, 0x00, 0x08, 0x27, 0x09, 0x82, 0xff, 0xff, 0x99, 0xd6, + 0xd0, 0x69, 0x89, 0x52, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x51, 0x0e, 0xc0, 0x40, 0x38, 0x03, 0xa8, 0x00, 0xa2, 0x0c, 0x05, 0x40, 0x40, 0xaa, + 0xff, 0xff, 0xc8, 0x2d, 0x09, 0x00, 0x14, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0xc6, 0x25, 0x4b, 0x00, 0x1a, 0xd8, 0x18, 0xc6, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf7, 0xc0, 0x01, 0x89, 0x52, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf7, + 0x00, 0x01, 0x99, 0xd6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x84, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0, 0x3b, 0xef, + 0x7b, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x2d, 0x09, 0x00, 0x58, 0xf3, 0x7c, + 0x0b, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x0a, 0x40, 0xc8, +}; + +/** + * + * for.whom.the.bell.tolls,.the.bell.tolls.for.thee! + * + * for.whom.the.bell.tolls,<16,15>.<40,4><19,3>e! ([MS-RDPBCGR]) + * + * <16,15> : ".the.bell.tolls" + * <40,4> : "for." + * <19,3> : "the" + * + * for.whom.the.bell.tolls,<16,15>.f<40,3><35,3>e! (Microsoft implementation) + * + * <16,15> : ".the.bell.tolls" + * <40,3> : "or." + * <19,3> " "the" + * + * RDP5: + * 01100110 Literal 'f' + * 01101111 Literal 'o' + * 01110010 Literal 'r' + * 00101110 Literal '.' + * 01110111 Literal 'w' + * 01101000 Literal 'h' + * 01101111 Literal 'o' + * 01101101 Literal 'm' + * 00101110 Literal '.' + * 01110100 Literal 't' + * 01101000 Literal 'h' + * 01100101 Literal 'e' + * 00101110 Literal '.' + * 01100010 Literal 'b' + * 01100101 Literal 'e' + * 01101100 Literal 'l' + * 01101100 Literal 'l' + * 00101110 Literal '.' + * 01110100 Literal 't' + * 01101111 Literal 'o' + * 01101100 Literal 'l' + * 01101100 Literal 'l' + * 01110011 Literal 's' + * 00101100 Literal ',' + * 11111+010000 CopyOffset 16 + * 110+111 LengthOfMatch 15 + * 00101110 Literal '.' + * 01100110 Literal 'f' + * 11111+101000 CopyOffset 40 + * 0 LengthOfMatch 3 + * 11111+100011 CopyOffset 35 + * 0 LengthOfMatch 3 + * 01100101 Literal 'e' + * 00100001 Literal '!' + * 0000000 Trailing Bits + * + * RDP4: + * 01100110 Literal 'f' + * 01101111 Literal 'o' + * 01110010 Literal 'r' + * 00101110 Literal '.' + * 01110111 Literal 'w' + * 01101000 Literal 'h' + * 01101111 Literal 'o' + * 01101101 Literal 'm' + * 00101110 Literal '.' + * 01110100 Literal 't' + * 01101000 Literal 'h' + * 01100101 Literal 'e' + * 00101110 Literal '.' + * 01100010 Literal 'b' + * 01100101 Literal 'e' + * 01101100 Literal 'l' + * 01101100 Literal 'l' + * 00101110 Literal '.' + * 01110100 Literal 't' + * 01101111 Literal 'o' + * 01101100 Literal 'l' + * 01101100 Literal 'l' + * 01110011 Literal 's' + * 00101100 Literal ',' + * 1111+010000 CopyOffset 16 + * 110+111 LengthOfMatch 15 + * 00101110 Literal '.' + * 01100110 Literal 'f' + * 1111+101000 CopyOffset 40 + * 0 LengthOfMatch 3 + * 1111+100011 CopyOffset 35 + * 0 LengthOfMatch 3 + * 01100101 Literal 'e' + * 00100001 Literal '!' + * 00 Trailing Bits + */ + +static const BYTE TEST_MPPC_BELLS[] = "for.whom.the.bell.tolls,.the.bell.tolls.for.thee!"; + +/* Flags: 0x0060 Length: 33 */ + +static const BYTE TEST_MPPC_BELLS_RDP4[] = + "\x66\x6f\x72\x2e\x77\x68\x6f\x6d\x2e\x74\x68\x65\x2e\x62\x65\x6c" + "\x6c\x2e\x74\x6f\x6c\x6c\x73\x2c\xf4\x37\x2e\x66\xfa\x1f\x19\x94" + "\x84"; + +/* Flags: 0x0061 Length: 34 */ + +static const BYTE TEST_MPPC_BELLS_RDP5[] = + "\x66\x6f\x72\x2e\x77\x68\x6f\x6d\x2e\x74\x68\x65\x2e\x62\x65\x6c" + "\x6c\x2e\x74\x6f\x6c\x6c\x73\x2c\xfa\x1b\x97\x33\x7e\x87\xe3\x32" + "\x90\x80"; + +static const BYTE TEST_ISLAND_DATA[] = "No man is an island entire of itself; every man " + "is a piece of the continent, a part of the main; " + "if a clod be washed away by the sea, Europe " + "is the less, as well as if a promontory were, as" + "well as any manner of thy friends or of thine " + "own were; any man's death diminishes me, " + "because I am involved in mankind. " + "And therefore never send to know for whom " + "the bell tolls; it tolls for thee."; + +static const BYTE TEST_ISLAND_DATA_RDP5[] = + "\x4e\x6f\x20\x6d\x61\x6e\x20\x69\x73\x20\xf8\xd2\xd8\xc2\xdc\xc8" + "\x40\xca\xdc\xe8\xd2\xe4\xca\x40\xde\xcc\x40\xd2\xe8\xe6\xca\xd8" + "\xcc\x76\x40\xca\xec\xca\xe4\xf3\xfa\x71\x20\x70\x69\x65\x63\xfc" + "\x12\xe8\xd0\xca\x40\xc6\xdf\xfb\xcd\xdf\xd0\x58\x40\xc2\x40\xe0" + "\xc2\xe4\xe9\xfe\x63\xec\xc3\x6b\x0b\x4b\x71\xd9\x03\x4b\x37\xd7" + "\x31\xb6\x37\xb2\x10\x31\x32\x90\x3b\xb0\xb9\xb4\x32\xb2\x10\x30" + "\xbb\xb0\xbc\x90\x31\x3c\x90\x7e\x68\x73\x65\x61\x2c\x20\x45\x75" + "\x72\x6f\x70\x65\xf2\x34\x7d\x38\x6c\x65\x73\x73\xf0\x69\xcc\x81" + "\xdd\x95\xb1\xb0\x81\x85\xcf\xc0\x94\xe0\xe4\xde\xdb\xe2\xb3\x7f" + "\x92\x4e\xec\xae\x4c\xbf\x86\x3f\x06\x0c\x2d\xde\x5d\x96\xe6\x57" + "\x2f\x1e\x53\xc9\x03\x33\x93\x4b\x2b\x73\x23\x99\x03\x7f\xd2\xb6" + "\x96\xef\x38\x1d\xdb\xbc\x24\x72\x65\x3b\xf5\x5b\xf8\x49\x3b\x99" + "\x03\x23\x2b\x0b\xa3\x41\x03\x23\x4b\x6b\x4b\x73\x4f\x96\xce\x64" + "\x0d\xbe\x19\x31\x32\xb1\xb0\xba\xb9\xb2\x90\x24\x90\x30\xb6\x90" + "\x34\xb7\x3b\x37\xb6\x3b\x79\xd4\xd2\xdd\xec\x18\x6b\x69\x6e\x64" + "\x2e\x20\x41\xf7\x33\xcd\x47\x26\x56\x66\xff\x74\x9b\xbd\xbf\x04" + "\x0e\x7e\x31\x10\x3a\x37\x90\x35\xb7\x37\xbb\x90\x7d\x81\x03\xbb" + "\x43\x7b\x6f\xa8\xe5\x8b\xd0\xf0\xe8\xde\xd8\xd8\xe7\xec\xf3\xa7" + "\xe4\x7c\xa7\xe2\x9f\x01\x99\x4b\x80"; + +static int test_MppcCompressBellsRdp5(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + BYTE OutputBuffer[65536] = { 0 }; + const UINT32 SrcSize = sizeof(TEST_MPPC_BELLS) - 1; + const BYTE* pSrcData = (const BYTE*)TEST_MPPC_BELLS; + UINT32 DstSize = sizeof(OutputBuffer); + const BYTE* pDstData = NULL; + const UINT32 expectedSize = sizeof(TEST_MPPC_BELLS_RDP5) - 1; + + MPPC_CONTEXT* mppc = mppc_context_new(1, TRUE); + + if (!mppc) + return -1; + + status = mppc_compress(mppc, pSrcData, SrcSize, OutputBuffer, &pDstData, &DstSize, &Flags); + + if (status < 0) + goto fail; + + printf("Flags: 0x%08" PRIX32 " DstSize: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("MppcCompressBellsRdp5: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_MPPC_BELLS_RDP5, DstSize) != 0) + { + printf("MppcCompressBellsRdp5: output mismatch\n"); + printf("Actual\n"); + BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0); + printf("Expected\n"); + BitDump(__func__, WLOG_INFO, TEST_MPPC_BELLS_RDP5, DstSize * 8, 0); + goto fail; + } + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcCompressBellsRdp4(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + BYTE OutputBuffer[65536] = { 0 }; + const BYTE* pSrcData = (const BYTE*)TEST_MPPC_BELLS; + const UINT32 SrcSize = sizeof(TEST_MPPC_BELLS) - 1; + UINT32 DstSize = sizeof(OutputBuffer); + const BYTE* pDstData = NULL; + const UINT32 expectedSize = sizeof(TEST_MPPC_BELLS_RDP4) - 1; + MPPC_CONTEXT* mppc = mppc_context_new(0, TRUE); + + if (!mppc) + return -1; + + status = mppc_compress(mppc, pSrcData, SrcSize, OutputBuffer, &pDstData, &DstSize, &Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("MppcCompressBellsRdp4: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_MPPC_BELLS_RDP4, DstSize) != 0) + { + printf("MppcCompressBellsRdp4: output mismatch\n"); + printf("Actual\n"); + BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0); + printf("Expected\n"); + BitDump(__func__, WLOG_INFO, TEST_MPPC_BELLS_RDP4, DstSize * 8, 0); + goto fail; + } + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcDecompressBellsRdp5(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + const BYTE* pSrcData = NULL; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + MPPC_CONTEXT* mppc = NULL; + UINT32 expectedSize = 0; + const BYTE* pDstData = NULL; + mppc = mppc_context_new(1, FALSE); + + if (!mppc) + return -1; + + SrcSize = sizeof(TEST_MPPC_BELLS_RDP5) - 1; + pSrcData = TEST_MPPC_BELLS_RDP5; + Flags = PACKET_AT_FRONT | PACKET_COMPRESSED | 1; + expectedSize = sizeof(TEST_MPPC_BELLS) - 1; + status = mppc_decompress(mppc, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("MppcDecompressBellsRdp5: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_MPPC_BELLS, DstSize) != 0) + { + printf("MppcDecompressBellsRdp5: output mismatch\n"); + goto fail; + } + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcDecompressBellsRdp4(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + const BYTE* pSrcData = NULL; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + MPPC_CONTEXT* mppc = NULL; + UINT32 expectedSize = 0; + const BYTE* pDstData = NULL; + mppc = mppc_context_new(0, FALSE); + + if (!mppc) + return -1; + + SrcSize = sizeof(TEST_MPPC_BELLS_RDP4) - 1; + pSrcData = (const BYTE*)TEST_MPPC_BELLS_RDP4; + Flags = PACKET_AT_FRONT | PACKET_COMPRESSED | 0; + expectedSize = sizeof(TEST_MPPC_BELLS) - 1; + status = mppc_decompress(mppc, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("MppcDecompressBellsRdp4: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_MPPC_BELLS, DstSize) != 0) + { + printf("MppcDecompressBellsRdp4: output mismatch\n"); + goto fail; + } + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcCompressIslandRdp5(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + BYTE OutputBuffer[65536] = { 0 }; + const UINT32 SrcSize = sizeof(TEST_ISLAND_DATA) - 1; + const BYTE* pSrcData = (const BYTE*)TEST_ISLAND_DATA; + const UINT32 expectedSize = sizeof(TEST_ISLAND_DATA_RDP5) - 1; + UINT32 DstSize = sizeof(OutputBuffer); + const BYTE* pDstData = NULL; + MPPC_CONTEXT* mppc = mppc_context_new(1, TRUE); + + if (!mppc) + return -1; + + status = mppc_compress(mppc, pSrcData, SrcSize, OutputBuffer, &pDstData, &DstSize, &Flags); + + if (status < 0) + goto fail; + + printf("Flags: 0x%08" PRIX32 " DstSize: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("MppcCompressIslandRdp5: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_ISLAND_DATA_RDP5, DstSize) != 0) + { + printf("MppcCompressIslandRdp5: output mismatch\n"); + printf("Actual\n"); + BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0); + printf("Expected\n"); + BitDump(__func__, WLOG_INFO, TEST_ISLAND_DATA_RDP5, DstSize * 8, 0); + goto fail; + } + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcCompressBufferRdp5(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + BYTE OutputBuffer[65536] = { 0 }; + const UINT32 SrcSize = sizeof(TEST_RDP5_UNCOMPRESSED_DATA); + const BYTE* pSrcData = (const BYTE*)TEST_RDP5_UNCOMPRESSED_DATA; + const UINT32 expectedSize = sizeof(TEST_RDP5_COMPRESSED_DATA); + UINT32 DstSize = sizeof(OutputBuffer); + + const BYTE* pDstData = NULL; + MPPC_CONTEXT* mppc = mppc_context_new(1, TRUE); + + if (!mppc) + return -1; + + status = mppc_compress(mppc, pSrcData, SrcSize, OutputBuffer, &pDstData, &DstSize, &Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("MppcCompressBufferRdp5: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_RDP5_COMPRESSED_DATA, DstSize) != 0) + { + printf("MppcCompressBufferRdp5: output mismatch: compressed output does not match " + "Microsoft implementation\n"); + goto fail; + } + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcDecompressBufferRdp5(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + const BYTE* pSrcData = NULL; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + MPPC_CONTEXT* mppc = NULL; + UINT32 expectedSize = 0; + const BYTE* pDstData = NULL; + mppc = mppc_context_new(1, FALSE); + + if (!mppc) + return -1; + + SrcSize = sizeof(TEST_RDP5_COMPRESSED_DATA); + pSrcData = (const BYTE*)TEST_RDP5_COMPRESSED_DATA; + Flags = PACKET_AT_FRONT | PACKET_COMPRESSED | 1; + expectedSize = sizeof(TEST_RDP5_UNCOMPRESSED_DATA); + status = mppc_decompress(mppc, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("MppcDecompressBufferRdp5: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_RDP5_UNCOMPRESSED_DATA, DstSize) != 0) + { + printf("MppcDecompressBufferRdp5: output mismatch\n"); + goto fail; + } + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +int TestFreeRDPCodecMppc(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (test_MppcCompressIslandRdp5() < 0) + return -1; + + if (test_MppcCompressBellsRdp5() < 0) + return -1; + + if (test_MppcDecompressBellsRdp5() < 0) + return -1; + + if (test_MppcCompressBellsRdp4() < 0) + return -1; + + if (test_MppcDecompressBellsRdp4() < 0) + return -1; + + if (test_MppcCompressBufferRdp5() < 0) + return -1; + + if (test_MppcDecompressBufferRdp5() < 0) + return -1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c new file mode 100644 index 0000000000000000000000000000000000000000..04a910f4bfeb9eea7785e1028cf01ac4deb04b78 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecPlanar.c @@ -0,0 +1,5787 @@ + +#include + +#include +#include +#include + +#include +#include +#include +#include + +/** + * Experimental Case 01: 64x64 (32bpp) + */ + +static const BYTE TEST_RLE_BITMAP_EXPERIMENTAL_01[16384] = + "\x1B\x1A\x16\xFF\x1C\x1A\x16\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF\x18\x16\x12" + "\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF" + "\x1D\x1C\x17\xFF\x1D\x1B\x17\xFF\x1C\x1B\x17\xFF\x1B\x1A\x16\xFF\x1A\x19\x15\xFF\x1A\x19\x15" + "\xFF\x18\x17\x13\xFF\x1A\x19\x15\xFF" + "\x1B\x1A\x16\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF\x18\x16\x14\xFF\x1C\x1A\x16\xFF\x1A\x18\x14" + "\xFF\x1B\x1A\x16\xFF\x19\x17\x13\xFF" + "\x1B\x19\x16\xFF\x1A\x18\x15\xFF\x1A\x18\x13\xFF\x19\x17\x13\xFF\x1B\x19\x15\xFF\x1B\x1A\x16" + "\xFF\x1A\x19\x15\xFF\x18\x16\x12\xFF" + "\x1A\x19\x15\xFF\x1C\x1B\x16\xFF\x1C\x1B\x17\xFF\x1D\x1C\x17\xFF\x1B\x1B\x16\xFF\x18\x17\x13" + "\xFF\x19\x18\x14\xFF\x1B\x19\x14\xFF" + "\x1A\x19\x15\xFF\x1A\x1A\x15\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF\x1C\x1B\x17\xFF\x1D\x1C\x17" + "\xFF\x1B\x1A\x15\xFF\x18\x17\x12\xFF" + "\x1B\x1A\x16\xFF\x18\x17\x13\xFF\x1A\x19\x15\xFF\x1E\x1D\x18\xFF\x19\x18\x14\xFF\x1C\x1B\x17" + "\xFF\x1C\x1A\x16\xFF\x1B\x1A\x18\xFF" + "\x1D\x1B\x16\xFF\x1E\x1B\x17\xFF\x1D\x1C\x18\xFF\x1B\x1A\x16\xFF\x1A\x1A\x14\xFF\x1B\x1B\x15" + "\xFF\x1E\x1C\x17\xFF\x1D\x1B\x17\xFF" + "\x1C\x19\x15\xFF\x1D\x1C\x17\xFF\x1A\x19\x14\xFF\x1C\x1B\x17\xFF\x1E\x1D\x19\xFF\x1C\x1C\x17" + "\xFF\x1B\x1C\x16\xFF\x1D\x1C\x18\xFF" + "\x1C\x1C\x16\xFF\x1D\x1C\x17\xFF\x1F\x1E\x19\xFF\x1A\x18\x14\xFF\x1B\x1A\x16\xFF\x1D\x1C\x18" + "\xFF\x1D\x1C\x17\xFF\x1E\x1B\x19\xFF" + "\x1F\x1C\x18\xFF\x1D\x1C\x18\xFF\x20\x1F\x19\xFF\x1F\x1E\x19\xFF\x1B\x1A\x16\xFF\x1F\x1E\x1A" + "\xFF\x1D\x1C\x17\xFF\x1F\x1C\x18\xFF" + "\x1F\x1D\x18\xFF\x1E\x1C\x18\xFF\x1D\x1C\x17\xFF\x1C\x1C\x16\xFF\x1D\x1C\x18\xFF\x1F\x1F\x19" + "\xFF\x1D\x1C\x18\xFF\x1B\x1B\x16\xFF" + "\x1D\x1D\x17\xFF\x1F\x1E\x19\xFF\x1D\x1C\x16\xFF\x1B\x1A\x15\xFF\x1F\x1D\x19\xFF\x1E\x1C\x18" + "\xFF\x1F\x1E\x1A\xFF\x22\x20\x1C\xFF" + "\x22\x20\x1B\xFF\x20\x1F\x1A\xFF\x1F\x1F\x1A\xFF\x1E\x1E\x1A\xFF\x1D\x1C\x18\xFF\x1F\x1D\x19" + "\xFF\x20\x20\x1A\xFF\x22\x21\x1C\xFF" + "\x20\x1F\x1A\xFF\x1D\x1D\x18\xFF\x1E\x1D\x18\xFF\x22\x20\x1B\xFF\x20\x20\x1A\xFF\x1E\x1D\x18" + "\xFF\x20\x20\x1B\xFF\x20\x1F\x1B\xFF" + "\x1F\x1D\x18\xFF\x1E\x1E\x19\xFF\x1E\x1E\x19\xFF\x1D\x1B\x18\xFF\x1D\x1B\x16\xFF\x1E\x1C\x17" + "\xFF\x1B\x1A\x16\xFF\x1F\x1D\x18\xFF" + "\x1B\x1A\x16\xFF\x1A\x19\x15\xFF\x19\x18\x15\xFF\x1B\x19\x15\xFF\x1B\x19\x15\xFF\x18\x18\x14" + "\xFF\x17\x17\x13\xFF\x19\x18\x15\xFF" + "\x15\x15\x11\xFF\x14\x13\x10\xFF\x4E\x4A\x3D\xFF\x21\x20\x1A\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1F\xFF" + "\x21\x20\x1A\xFF\x24\x23\x1F\xFF\x21\x20\x1A\xFF\x2A\x29\x23\xFF\x21\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x26\x25\x21\xFF\x25\x24\x20\xFF\x21\x20\x1A" + "\xFF\x22\x20\x1B\xFF\x26\x25\x20\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x23\x21\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x22\x21\x1C" + "\xFF\x26\x25\x21\xFF\x23\x21\x1C\xFF" + "\x22\x20\x1A\xFF\x22\x20\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x22\x22\x1C\xFF\x23\x22\x1D" + "\xFF\x24\x23\x1E\xFF\x24\x24\x1E\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x29\x28\x23\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x22\x21\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x24\x22\x1D\xFF\x22\x21\x1B\xFF\x23\x21\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1E\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x28\x26\x21\xFF\x25\x24\x20\xFF\x23\x23\x1E\xFF\x24\x23\x1F" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x28\x26\x21" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x20\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x22\x1D\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x22\x20\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1D" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x24\x22\x1D\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x23\x21\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x26\x24\x20\xFF\x24\x23\x1E\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x25\x24\x20" + "\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1D\xFF\x21\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x21\x1C\xFF" + "\x22\x21\x1B\xFF\x28\x26\x21\xFF\x23\x22\x1C\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x26\x25\x20" + "\xFF\x24\x23\x1E\xFF\x28\x26\x21\xFF" + "\x28\x26\x21\xFF\x22\x22\x1C\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x21\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x28\x26\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x26\x25\x21\xFF" + "\x24\x23\x1E\xFF\x26\x25\x21\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x23\x22\x1E\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x20\xFF\x25\x25\x20\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x25\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x25\x24\x1F\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x2A\x29\x23\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x26\x26\x21\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x27\x25\x20\xFF" + "\x22\x21\x1B\xFF\x26\x26\x20\xFF\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x27\x25\x20\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x27\x26\x21\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x24\x23\x1E" + "\xFF\x25\x24\x1F\xFF\x25\x24\x1F\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x29\x28\x23\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x24\x1F" + "\xFF\x22\x21\x1B\xFF\x29\x26\x21\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1E\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x28\x26\x21\xFF\x26\x25\x20\xFF\x23\x23\x1E\xFF\x24\x23\x1F" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x25\x21\xFF\x29\x26\x21" + "\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x27\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x1F" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x24\x20\xFF\x23\x22\x1C\xFF\x26\x25\x21\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x23\x1E\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1E\xFF\x22\x21\x1B\xFF\x27\x25\x20\xFF\x23\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1E" + "\xFF\x29\x26\x21\xFF\x23\x22\x1C\xFF" + "\x23\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x27\x26\x21\xFF\x24\x23\x1E\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x29\x26\x21\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x27\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x24\x23\x1E\xFF\x26\x24\x20\xFF\x23\x22\x1C\xFF\x26\x25\x20" + "\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x28\x26\x21\xFF\x23\x22\x1C\xFF\x26\x25\x21\xFF\x23\x22\x1C\xFF\x26\x25\x20" + "\xFF\x25\x24\x1F\xFF\x28\x26\x21\xFF" + "\x28\x26\x21\xFF\x22\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x4E\x49\x3C" + "\xFF\x1A\x18\x14\xFF\x1A\x18\x15\xFF" + "\x1B\x1B\x16\xFF\x1D\x1B\x17\xFF\x1F\x1D\x19\xFF\x20\x1D\x19\xFF\x1E\x1D\x19\xFF\x1F\x1D\x19" + "\xFF\x21\x20\x1B\xFF\x23\x21\x1C\xFF" + "\x22\x21\x1C\xFF\x25\x22\x1D\xFF\x25\x22\x1E\xFF\x25\x23\x1E\xFF\x25\x22\x1D\xFF\x25\x23\x1E" + "\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x25\x24\x1E\xFF\x26\x24\x1F\xFF\x25\x22\x1D\xFF\x26\x25\x1F\xFF\x27\x26\x20" + "\xFF\x26\x25\x1F\xFF\x27\x24\x1F\xFF" + "\x27\x25\x20\xFF\x29\x26\x21\xFF\x26\x23\x1F\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x28\x25\x20" + "\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF" + "\x27\x24\x1F\xFF\x28\x25\x20\xFF\x27\x26\x1F\xFF\x27\x24\x1F\xFF\x26\x23\x1F\xFF\x28\x25\x20" + "\xFF\x29\x26\x21\xFF\x2A\x27\x22\xFF" + "\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF\x26\x25\x20\xFF\x26\x24\x1E" + "\xFF\x26\x23\x1D\xFF\x27\x24\x1F\xFF" + "\x26\x23\x1E\xFF\x26\x23\x1F\xFF\x24\x23\x1E\xFF\x26\x24\x1F\xFF\x27\x24\x1E\xFF\x27\x24\x20" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x28\x25\x20\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x28\x25\x20\xFF\x24\x23\x1E\xFF\x25\x23\x1E" + "\xFF\x25\x24\x1E\xFF\x26\x24\x1F\xFF" + "\x28\x26\x21\xFF\x28\x25\x20\xFF\x26\x23\x1E\xFF\x28\x26\x20\xFF\x25\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x29\x26\x21\xFF\x27\x24\x1F\xFF" + "\x25\x22\x1D\xFF\x25\x24\x1E\xFF\x29\x27\x20\xFF\x29\x26\x20\xFF\x28\x26\x20\xFF\x27\x26\x1F" + "\xFF\x28\x25\x20\xFF\x27\x24\x1F\xFF" + "\x26\x25\x1F\xFF\x26\x25\x20\xFF\x27\x24\x1F\xFF\x25\x22\x1E\xFF\x24\x23\x1D\xFF\x23\x22\x1D" + "\xFF\x24\x21\x1C\xFF\x26\x23\x1E\xFF" + "\x27\x24\x1E\xFF\x28\x27\x20\xFF\x27\x25\x1F\xFF\x27\x25\x20\xFF\x25\x22\x1D\xFF\x26\x24\x1E" + "\xFF\x22\x20\x1A\xFF\x24\x24\x1D\xFF" + "\x28\x25\x20\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x26\x23\x1E\xFF\x26\x25\x1F" + "\xFF\x27\x24\x1F\xFF\x26\x25\x1F\xFF" + "\x27\x25\x20\xFF\x28\x27\x21\xFF\x27\x25\x20\xFF\x26\x25\x1F\xFF\x26\x23\x1E\xFF\x22\x21\x1C" + "\xFF\x25\x24\x1E\xFF\x26\x23\x1E\xFF" + "\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x25\x24\x1D\xFF\x23\x23\x1D\xFF\x25\x23\x1E" + "\xFF\x27\x25\x20\xFF\x26\x24\x1E\xFF" + "\x25\x23\x1E\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x27\x26\x20\xFF\x29\x2F\x26\xFF\x3C\x70\x55" + "\xFF\x54\xC5\x92\xFF\x57\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF" + "\x56\xCC\x97\xFF\x4B\xA4\x7B\xFF\x2F\x47\x37\xFF\x26\x26\x20\xFF\x25\x23\x1D\xFF\x24\x23\x1D" + "\xFF\x24\x22\x1D\xFF\x24\x22\x1D\xFF" + "\x26\x23\x1E\xFF\x27\x25\x20\xFF\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x26\x24\x1F\xFF\x24\x23\x1D" + "\xFF\x26\x24\x1F\xFF\x25\x25\x1D\xFF" + "\x27\x2D\x26\xFF\x39\x68\x50\xFF\x54\xC0\x8F\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x97\xFF\x56\xCD\x97\xFF\x49\x9F\x76\xFF\x2D\x42\x33\xFF\x24\x25\x20\xFF\x23\x22\x1D" + "\xFF\x25\x22\x1D\xFF\x24\x21\x1C\xFF" + "\x22\x21\x1C\xFF\x25\x23\x1E\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF\x22\x20\x1B\xFF\x23\x22\x1C" + "\xFF\x25\x25\x1F\xFF\x26\x24\x1E\xFF" + "\x24\x23\x1D\xFF\x24\x23\x1D\xFF\x26\x23\x1F\xFF\x23\x20\x1C\xFF\x28\x26\x1F\xFF\x25\x24\x1F" + "\xFF\x25\x22\x1D\xFF\x24\x21\x1C\xFF" + "\x23\x23\x1D\xFF\x25\x22\x1E\xFF\x24\x22\x1E\xFF\x27\x24\x1F\xFF\x23\x21\x1B\xFF\x26\x25\x1F" + "\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF" + "\x26\x23\x1E\xFF\x28\x25\x20\xFF\x26\x23\x1E\xFF\x24\x21\x1C\xFF\x27\x26\x21\xFF\x25\x22\x1D" + "\xFF\x22\x20\x1C\xFF\x25\x22\x1D\xFF" + "\x26\x24\x1E\xFF\x24\x23\x1D\xFF\x26\x25\x1F\xFF\x24\x22\x1E\xFF\x23\x21\x1C\xFF\x23\x22\x1D" + "\xFF\x24\x22\x1D\xFF\x23\x21\x1C\xFF" + "\x24\x22\x1D\xFF\x24\x22\x1D\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF\x25\x22\x1D\xFF\x25\x23\x1E" + "\xFF\x23\x20\x1B\xFF\x25\x22\x1D\xFF" + "\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x25\x22\x1E\xFF\x24\x21\x1D\xFF\x25\x23\x1E\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1C\xFF\x23\x1F\x1B\xFF" + "\x21\x21\x1B\xFF\x24\x22\x1D\xFF\x24\x23\x1D\xFF\x25\x23\x1E\xFF\x23\x20\x1C\xFF\x26\x24\x1E" + "\xFF\x24\x22\x1D\xFF\x24\x22\x1D\xFF" + "\x21\x21\x1A\xFF\x21\x21\x1C\xFF\x20\x20\x1A\xFF\x22\x21\x1C\xFF\x26\x23\x1E\xFF\x21\x21\x1C" + "\xFF\x22\x21\x1C\xFF\x23\x22\x1D\xFF" + "\x25\x23\x1C\xFF\x26\x23\x1E\xFF\x24\x22\x1D\xFF\x22\x22\x1C\xFF\x22\x22\x1C\xFF\x24\x22\x1D" + "\xFF\x24\x23\x1D\xFF\x25\x22\x1D\xFF" + "\x22\x21\x1D\xFF\x21\x21\x1C\xFF\x23\x22\x1D\xFF\x23\x20\x1C\xFF\x21\x20\x1B\xFF\x24\x23\x1D" + "\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x22\x22\x1C\xFF\x24\x22\x1D\xFF\x23\x21\x1B\xFF\x22\x21\x1C\xFF\x24\x23\x1D\xFF\x23\x21\x1C" + "\xFF\x21\x21\x1B\xFF\x24\x24\x1E\xFF" + "\x24\x22\x1D\xFF\x23\x22\x1D\xFF\x23\x22\x1D\xFF\x21\x20\x1B\xFF\x23\x21\x1C\xFF\x25\x24\x1E" + "\xFF\x24\x21\x1C\xFF\x23\x21\x1C\xFF" + "\x21\x20\x1B\xFF\x22\x20\x1B\xFF\x21\x20\x1B\xFF\x23\x22\x1C\xFF\x23\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x22\x1C\xFF\x22\x22\x1D\xFF" + "\x24\x21\x1C\xFF\x21\x1F\x1B\xFF\x21\x1F\x1A\xFF\x20\x20\x19\xFF\x24\x22\x1B\xFF\x23\x22\x1C" + "\xFF\x27\x25\x1E\xFF\x25\x24\x1E\xFF" + "\x26\x29\x23\xFF\x2F\x45\x37\xFF\x2B\x3E\x2F\xFF\x27\x26\x20\xFF\x21\x1F\x1A\xFF\x21\x20\x1C" + "\xFF\x21\x20\x1B\xFF\x21\x21\x1B\xFF" + "\x20\x1F\x1A\xFF\x25\x23\x1E\xFF\x24\x23\x1D\xFF\x1F\x1E\x1A\xFF\x24\x22\x1C\xFF\x27\x23\x1F" + "\xFF\x24\x22\x1E\xFF\x21\x20\x1C\xFF" + "\x1F\x1E\x19\xFF\x21\x1F\x1B\xFF\x21\x20\x1B\xFF\x22\x21\x1B\xFF\x25\x22\x1D\xFF\x21\x1F\x1A" + "\xFF\x21\x1F\x1C\xFF\x21\x20\x1B\xFF" + "\x24\x21\x1C\xFF\x1F\x1D\x19\xFF\x22\x20\x1A\xFF\x22\x22\x1C\xFF\x22\x20\x1B\xFF\x21\x21\x1A" + "\xFF\x20\x20\x1A\xFF\x21\x20\x1C\xFF" + "\x25\x24\x1E\xFF\x24\x22\x1D\xFF\x21\x20\x1B\xFF\x22\x1F\x1B\xFF\x22\x21\x1C\xFF\x23\x21\x1D" + "\xFF\x20\x1F\x1C\xFF\x22\x21\x1C\xFF" + "\x15\x14\x11\xFF\x15\x13\x10\xFF\x15\x14\x10\xFF\x18\x17\x13\xFF\x16\x15\x11\xFF\x14\x13\x10" + "\xFF\x15\x14\x10\xFF\x14\x13\x0F\xFF" + "\x12\x10\x0E\xFF\x11\x10\x0E\xFF\x10\x0F\x0D\xFF\x14\x12\x10\xFF\x14\x12\x0E\xFF\x14\x13\x0F" + "\xFF\x15\x13\x10\xFF\x12\x10\x0D\xFF" + "\x12\x11\x0E\xFF\x12\x11\x0E\xFF\x17\x16\x12\xFF\x17\x15\x11\xFF\x18\x17\x13\xFF\x15\x13\x10" + "\xFF\x16\x15\x12\xFF\x13\x12\x0E\xFF" + "\x12\x11\x0E\xFF\x14\x13\x0F\xFF\x13\x12\x0F\xFF\x12\x12\x0F\xFF\x15\x15\x11\xFF\x13\x12\x0F" + "\xFF\x13\x11\x0E\xFF\x13\x12\x0F\xFF" + "\x13\x11\x0F\xFF\x13\x12\x0E\xFF\x14\x13\x0F\xFF\x15\x14\x10\xFF\x13\x11\x0F\xFF\x12\x12\x0F" + "\xFF\x14\x13\x10\xFF\x14\x13\x0F\xFF" + "\x17\x16\x12\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x14\x13\x0F\xFF\x14\x13\x0F\xFF\x15\x14\x0F" + "\xFF\x14\x13\x10\xFF\x14\x12\x10\xFF" + "\x15\x14\x10\xFF\x15\x13\x10\xFF\x15\x14\x10\xFF\x15\x13\x10\xFF\x11\x10\x0D\xFF\x14\x13\x10" + "\xFF\x13\x12\x0E\xFF\x14\x12\x0F\xFF" + "\x16\x15\x10\xFF\x14\x13\x0F\xFF\x12\x10\x0E\xFF\x13\x11\x0F\xFF\x12\x10\x0F\xFF\x15\x14\x10" + "\xFF\x15\x14\x11\xFF\x15\x13\x11\xFF" + "\x16\x15\x11\xFF\x17\x16\x12\xFF\x13\x12\x0E\xFF\x12\x11\x0D\xFF\x14\x13\x10\xFF\x17\x16\x12" + "\xFF\x18\x17\x14\xFF\x17\x16\x13\xFF" + "\x15\x14\x10\xFF\x14\x13\x0F\xFF\x14\x13\x0F\xFF\x14\x13\x0F\xFF\x16\x14\x11\xFF\x16\x14\x12" + "\xFF\x14\x13\x0F\xFF\x14\x12\x10\xFF" + "\x14\x13\x10\xFF\x15\x14\x12\xFF\x16\x14\x11\xFF\x15\x13\x0F\xFF\x14\x13\x10\xFF\x15\x13\x10" + "\xFF\x18\x17\x13\xFF\x15\x13\x11\xFF" + "\x14\x13\x0F\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x15\x14\x11\xFF\x13\x12\x0F\xFF\x17\x15\x12" + "\xFF\x15\x13\x11\xFF\x13\x12\x0E\xFF" + "\x17\x16\x13\xFF\x19\x18\x14\xFF\x18\x17\x14\xFF\x17\x16\x13\xFF\x15\x14\x10\xFF\x15\x14\x12" + "\xFF\x14\x13\x0F\xFF\x15\x14\x11\xFF" + "\x16\x15\x11\xFF\x19\x18\x14\xFF\x18\x16\x13\xFF\x14\x13\x10\xFF\x14\x13\x0F\xFF\x15\x13\x11" + "\xFF\x15\x14\x11\xFF\x14\x13\x10\xFF" + "\x15\x14\x11\xFF\x18\x17\x14\xFF\x17\x15\x12\xFF\x16\x15\x11\xFF\x18\x17\x13\xFF\x1B\x1A\x16" + "\xFF\x1A\x19\x16\xFF\x16\x15\x11\xFF" + "\x16\x14\x12\xFF\x16\x15\x11\xFF\x17\x16\x13\xFF\x14\x13\x11\xFF\x17\x16\x12\xFF\x19\x19\x14" + "\xFF\x16\x15\x12\xFF\x19\x18\x14\xFF" + "\x18\x17\x14\xFF\x18\x18\x13\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x17\x15\x13\xFF\x18\x17\x14" + "\xFF\x17\x16\x13\xFF\x16\x15\x11\xFF" + "\x14\x13\x0F\xFF\x16\x15\x11\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF\x18\x17\x14\xFF\x15\x13\x12" + "\xFF\x16\x15\x11\xFF\x18\x16\x12\xFF" + "\x14\x13\x0F\xFF\x15\x14\x10\xFF\x16\x15\x11\xFF\x17\x16\x12\xFF\x1B\x1A\x16\xFF\x1A\x19\x15" + "\xFF\x19\x18\x14\xFF\x16\x15\x11\xFF" + "\x15\x14\x10\xFF\x17\x16\x12\xFF\x19\x18\x13\xFF\x19\x18\x13\xFF\x17\x16\x12\xFF\x17\x16\x12" + "\xFF\x18\x17\x13\xFF\x1B\x18\x15\xFF" + "\x17\x16\x12\xFF\x17\x16\x12\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF\x1A\x19\x15" + "\xFF\x1B\x19\x15\xFF\x1A\x19\x14\xFF" + "\x16\x15\x11\xFF\x1A\x19\x15\xFF\x1A\x18\x15\xFF\x17\x16\x12\xFF\x19\x19\x14\xFF\x19\x18\x14" + "\xFF\x17\x16\x12\xFF\x18\x16\x12\xFF" + "\x19\x18\x14\xFF\x19\x18\x14\xFF\x1B\x1A\x16\xFF\x1C\x1A\x16\xFF\x17\x15\x11\xFF\x19\x19\x14" + "\xFF\x19\x19\x14\xFF\x19\x18\x14\xFF" + "\x1D\x1B\x17\xFF\x1A\x19\x14\xFF\x1A\x19\x15\xFF\x17\x16\x12\xFF\x19\x18\x14\xFF\x19\x17\x14" + "\xFF\x19\x18\x14\xFF\x19\x18\x13\xFF" + "\x1B\x1A\x16\xFF\x1B\x1A\x16\xFF\x19\x17\x13\xFF\x18\x17\x13\xFF\x1A\x18\x14\xFF\x1C\x1A\x16" + "\xFF\x1D\x1C\x17\xFF\x1F\x1E\x19\xFF" + "\x19\x18\x14\xFF\x18\x17\x12\xFF\x18\x17\x12\xFF\x17\x16\x12\xFF\x18\x17\x13\xFF\x19\x18\x14" + "\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF" + "\x1B\x19\x15\xFF\x1B\x19\x15\xFF\x1A\x18\x14\xFF\x17\x16\x12\xFF\x16\x16\x11\xFF\x1A\x18\x14" + "\xFF\x1B\x19\x15\xFF\x1E\x1C\x18\xFF" + "\x1B\x1A\x16\xFF\x1C\x1A\x15\xFF\x19\x18\x14\xFF\x1A\x18\x14\xFF\x1C\x1A\x16\xFF\x1C\x1A\x17" + "\xFF\x1C\x1B\x17\xFF\x1A\x18\x14\xFF" + "\x1B\x19\x15\xFF\x1A\x18\x14\xFF\x1A\x19\x15\xFF\x1B\x1A\x16\xFF\x1B\x1A\x16\xFF\x1B\x1A\x15" + "\xFF\x1C\x1C\x17\xFF\x1C\x1C\x17\xFF" + "\x1B\x19\x15\xFF\x1A\x19\x15\xFF\x1B\x19\x15\xFF\x1D\x1C\x17\xFF\x1C\x1A\x16\xFF\x1C\x1C\x17" + "\xFF\x1C\x1B\x16\xFF\x1D\x1C\x17\xFF" + "\x1D\x1B\x17\xFF\x19\x19\x14\xFF\x1B\x1A\x16\xFF\x1F\x1D\x18\xFF\x1E\x1E\x18\xFF\x1E\x1D\x18" + "\xFF\x1D\x1B\x18\xFF\x1D\x1B\x17\xFF" + "\x1B\x1A\x15\xFF\x1A\x1A\x15\xFF\x1C\x1B\x16\xFF\x1E\x1C\x18\xFF\x1A\x19\x15\xFF\x1A\x19\x15" + "\xFF\x1D\x1C\x17\xFF\x1C\x19\x15\xFF" + "\x1D\x1B\x17\xFF\x1B\x1A\x15\xFF\x1A\x1A\x15\xFF\x1C\x1B\x16\xFF\x22\x20\x1B\xFF\x1E\x1D\x18" + "\xFF\x1D\x1C\x18\xFF\x1C\x1C\x17\xFF" + "\x1B\x1B\x15\xFF\x1B\x1A\x16\xFF\x1A\x19\x15\xFF\x1A\x19\x15\xFF\x1D\x1C\x18\xFF\x1B\x19\x15" + "\xFF\x1D\x1B\x17\xFF\x1B\x1B\x16\xFF" + "\x1F\x1C\x18\xFF\x1E\x1C\x18\xFF\x1F\x1C\x18\xFF\x1E\x1C\x18\xFF\x1C\x1C\x18\xFF\x1D\x1C\x18" + "\xFF\x1D\x1B\x17\xFF\x1E\x1B\x17\xFF" + "\x1D\x1B\x17\xFF\x1D\x1C\x17\xFF\x1E\x1E\x19\xFF\x1E\x1D\x19\xFF\x1C\x1C\x18\xFF\x20\x1F\x19" + "\xFF\x1F\x1D\x1A\xFF\x1F\x1E\x19\xFF" + "\x1D\x1B\x17\xFF\x1C\x1B\x17\xFF\x1B\x1A\x16\xFF\x1B\x1A\x16\xFF\x1E\x1C\x17\xFF\x1A\x19\x15" + "\xFF\x20\x1F\x1A\xFF\x1E\x1D\x18\xFF" + "\x1E\x1D\x18\xFF\x1F\x1D\x19\xFF\x1F\x1E\x1A\xFF\x1F\x1D\x19\xFF\x1D\x1C\x18\xFF\x1E\x1C\x18" + "\xFF\x1D\x1C\x18\xFF\x21\x20\x1B\xFF" + "\x1E\x1E\x19\xFF\x20\x1F\x1A\xFF\x20\x1E\x1A\xFF\x20\x1F\x1A\xFF\x20\x20\x1A\xFF\x21\x20\x1A" + "\xFF\x23\x21\x1B\xFF\x21\x21\x1B\xFF" + "\x1E\x1D\x19\xFF\x1E\x1D\x18\xFF\x1F\x1E\x1A\xFF\x1C\x1B\x18\xFF\x1D\x1C\x17\xFF\x1E\x1C\x17" + "\xFF\x1C\x1B\x17\xFF\x1E\x1D\x18\xFF" + "\x1B\x1A\x16\xFF\x1B\x1B\x16\xFF\x1A\x1A\x15\xFF\x19\x19\x15\xFF\x18\x18\x14\xFF\x17\x16\x12" + "\xFF\x18\x17\x13\xFF\x1A\x19\x15\xFF" + "\x15\x14\x11\xFF\x15\x14\x11\xFF\x51\x4E\x41\xFF\x21\x20\x1A\xFF\x26\x25\x20\xFF\x28\x26\x21" + "\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF" + "\x21\x20\x1A\xFF\x22\x21\x1C\xFF\x21\x20\x1A\xFF\x21\x20\x1A\xFF\x21\x20\x1A\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x26\x25\x21\xFF" + "\x28\x26\x21\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1D" + "\xFF\x24\x23\x1E\xFF\x21\x20\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x24\x23\x1E\xFF\x24\x22\x1D\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x28\x26\x21\xFF\x23\x21\x1C\xFF\x22\x21\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1D" + "\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x24\x23\x1D\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x23\x21\x1C\xFF" + "\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x25\x24\x20\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1D" + "\xFF\x24\x23\x1D\xFF\x25\x23\x1F\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x25\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x21\x1C\xFF\x21\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x25\x24\x20\xFF\x26\x25\x20\xFF\x25\x24\x20\xFF\x23\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x25\x24\x20\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x26\x24\x20" + "\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x25\x25\x20\xFF\x22\x21\x1B\xFF" + "\x26\x24\x20\xFF\x22\x21\x1B\xFF\x22\x22\x1C\xFF\x29\x28\x22\xFF\x23\x22\x1C\xFF\x24\x23\x1E" + "\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF\x29\x28\x23" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x25\x25\x20\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x29\x28\x23" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x23\x21\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x27\x25\x20\xFF\x22\x21\x1B\xFF\x27\x25\x21\xFF\x23\x22\x1C" + "\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1D\xFF\x23\x22\x1D\xFF\x25\x24\x1F\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x28\x26\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x25\x24\x1F" + "\xFF\x22\x21\x1B\xFF\x24\x22\x1D\xFF" + "\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x25\x24\x1F\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x28\x26\x21\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x28\x26\x21" + "\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x26\x25\x21\xFF" + "\x28\x26\x21\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x25\x20\xFF\x23\x22\x1E" + "\xFF\x25\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x23\x1E\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF" + "\x23\x22\x1C\xFF\x28\x26\x21\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x23\x1E" + "\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x27\x25\x20\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x26\x25\x20\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E" + "\xFF\x24\x23\x1E\xFF\x25\x24\x1F\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x26\x26\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x27\x25\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x26\x25\x21\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x26\x25\x20\xFF\x26\x25\x20\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x26\x25\x21\xFF\x29\x27\x21\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x26\x25\x21\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x26\x25\x20" + "\xFF\x26\x26\x20\xFF\x22\x21\x1B\xFF" + "\x26\x24\x20\xFF\x22\x21\x1B\xFF\x22\x22\x1C\xFF\x29\x28\x22\xFF\x23\x22\x1C\xFF\x24\x23\x1E" + "\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x29\x28\x23" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x21\xFF\x22\x21\x1B" + "\xFF\x26\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x29\x28\x23" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x27\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x24\x1F" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x27\x25\x20\xFF\x22\x21\x1B\xFF\x27\x25\x21\xFF\x4F\x4A\x3D" + "\xFF\x19\x18\x15\xFF\x1A\x19\x15\xFF" + "\x1D\x1B\x17\xFF\x1D\x1B\x17\xFF\x1E\x1C\x18\xFF\x1F\x1D\x18\xFF\x1D\x1B\x17\xFF\x1F\x1D\x19" + "\xFF\x21\x1E\x1A\xFF\x22\x21\x1C\xFF" + "\x24\x22\x1D\xFF\x25\x22\x1C\xFF\x23\x22\x1D\xFF\x25\x22\x1D\xFF\x27\x24\x1F\xFF\x26\x23\x1F" + "\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF" + "\x26\x23\x1E\xFF\x25\x23\x1E\xFF\x24\x23\x1D\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF" + "\x25\x24\x1E\xFF\x29\x26\x21\xFF\x28\x25\x1F\xFF\x27\x25\x1F\xFF\x28\x26\x21\xFF\x28\x25\x20" + "\xFF\x26\x24\x1F\xFF\x28\x27\x21\xFF" + "\x28\x25\x20\xFF\x28\x25\x1F\xFF\x27\x24\x1F\xFF\x28\x26\x1F\xFF\x25\x24\x1E\xFF\x26\x25\x1F" + "\xFF\x26\x25\x1F\xFF\x28\x26\x1F\xFF" + "\x27\x24\x1F\xFF\x29\x26\x20\xFF\x27\x25\x1F\xFF\x25\x25\x1F\xFF\x27\x25\x1F\xFF\x27\x25\x1F" + "\xFF\x27\x25\x1F\xFF\x27\x25\x20\xFF" + "\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x24\x24\x1E\xFF\x29\x26\x21\xFF\x28\x26\x1F\xFF\x26\x25\x1F" + "\xFF\x25\x23\x1E\xFF\x26\x25\x1D\xFF" + "\x26\x23\x1E\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x27\x25\x20\xFF\x25\x24\x1E\xFF\x25\x24\x1E" + "\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF" + "\x26\x24\x1F\xFF\x28\x25\x20\xFF\x2A\x26\x21\xFF\x27\x26\x1F\xFF\x27\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x28\x26\x20\xFF\x28\x25\x20\xFF" + "\x25\x23\x1E\xFF\x27\x25\x1F\xFF\x29\x26\x20\xFF\x24\x22\x1D\xFF\x26\x25\x20\xFF\x25\x24\x1F" + "\xFF\x26\x23\x1E\xFF\x26\x24\x1F\xFF" + "\x26\x24\x1F\xFF\x26\x25\x20\xFF\x26\x25\x20\xFF\x25\x23\x1E\xFF\x27\x26\x1F\xFF\x26\x24\x1E" + "\xFF\x24\x22\x1D\xFF\x26\x23\x1E\xFF" + "\x26\x24\x1E\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x26\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x25\x24\x1E\xFF" + "\x26\x22\x1D\xFF\x24\x21\x1C\xFF\x25\x23\x1E\xFF\x29\x28\x22\xFF\x25\x22\x1C\xFF\x27\x25\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x27\x23\x1E\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x25\x23\x1D\xFF\x25\x22\x1D\xFF\x24\x22\x1D" + "\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x29\x26\x20\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x25\x24\x1E\xFF\x26\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF" + "\x26\x25\x1F\xFF\x28\x25\x20\xFF\x25\x23\x1E\xFF\x25\x23\x1D\xFF\x28\x2B\x23\xFF\x35\x57\x43" + "\xFF\x4E\xB1\x84\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x51\xBB\x8A\xFF\x36\x60\x49\xFF\x25\x2A\x23\xFF\x27\x25\x1F\xFF\x26\x23\x1E" + "\xFF\x25\x22\x1D\xFF\x25\x23\x1E\xFF" + "\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x24\x21\x1D\xFF\x27\x24\x1F\xFF\x25\x25\x1F\xFF\x25\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x26\x24\x1E\xFF" + "\x28\x2A\x23\xFF\x33\x50\x3D\xFF\x4E\xAC\x80\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x52\xBF\x8D\xFF\x34\x58\x43\xFF\x26\x28\x21\xFF\x24\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x27\x24\x1F\xFF" + "\x22\x22\x1C\xFF\x22\x22\x1B\xFF\x25\x22\x1E\xFF\x27\x24\x1F\xFF\x24\x23\x1D\xFF\x26\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF" + "\x25\x22\x1D\xFF\x25\x23\x1E\xFF\x24\x22\x1E\xFF\x22\x21\x1B\xFF\x25\x22\x1D\xFF\x24\x23\x1E" + "\xFF\x23\x22\x1C\xFF\x24\x21\x1C\xFF" + "\x24\x23\x1D\xFF\x23\x21\x1C\xFF\x25\x23\x1E\xFF\x27\x24\x1F\xFF\x22\x22\x1C\xFF\x23\x23\x1D" + "\xFF\x24\x23\x1E\xFF\x25\x23\x1E\xFF" + "\x23\x21\x1C\xFF\x25\x23\x1E\xFF\x25\x22\x1D\xFF\x23\x22\x1C\xFF\x26\x25\x1F\xFF\x23\x22\x1D" + "\xFF\x21\x21\x1C\xFF\x25\x23\x1E\xFF" + "\x26\x25\x1F\xFF\x25\x23\x1E\xFF\x26\x24\x1F\xFF\x25\x22\x1D\xFF\x24\x23\x1D\xFF\x22\x21\x1C" + "\xFF\x25\x22\x1D\xFF\x23\x21\x1B\xFF" + "\x25\x22\x1D\xFF\x24\x21\x1C\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x24\x22\x1D\xFF\x24\x23\x1D" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1D\xFF" + "\x24\x22\x1D\xFF\x25\x23\x1E\xFF\x22\x21\x1C\xFF\x23\x22\x1D\xFF\x25\x22\x1D\xFF\x24\x23\x1D" + "\xFF\x23\x22\x1C\xFF\x24\x22\x1D\xFF" + "\x24\x23\x1D\xFF\x24\x23\x1D\xFF\x25\x22\x1D\xFF\x23\x22\x1D\xFF\x25\x23\x1E\xFF\x25\x24\x1D" + "\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF" + "\x22\x22\x1D\xFF\x23\x22\x1D\xFF\x24\x23\x1D\xFF\x24\x22\x1E\xFF\x24\x23\x1E\xFF\x22\x22\x1C" + "\xFF\x24\x22\x1D\xFF\x23\x21\x1C\xFF" + "\x26\x23\x1E\xFF\x24\x23\x1E\xFF\x23\x21\x1C\xFF\x23\x22\x1C\xFF\x24\x22\x1D\xFF\x25\x22\x1D" + "\xFF\x25\x23\x1D\xFF\x25\x23\x1E\xFF" + "\x25\x23\x1E\xFF\x24\x22\x1E\xFF\x24\x23\x1E\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x25\x23\x1E" + "\xFF\x25\x24\x1E\xFF\x26\x24\x1F\xFF" + "\x25\x23\x1D\xFF\x25\x23\x1D\xFF\x23\x22\x1C\xFF\x25\x22\x1D\xFF\x24\x23\x1D\xFF\x24\x22\x1C" + "\xFF\x22\x20\x1B\xFF\x23\x21\x1C\xFF" + "\x22\x22\x1C\xFF\x24\x21\x1D\xFF\x23\x22\x1D\xFF\x25\x22\x1D\xFF\x23\x22\x1C\xFF\x25\x23\x1D" + "\xFF\x24\x21\x1C\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1C\xFF\x26\x23\x1E\xFF\x22\x21\x1C\xFF\x22\x20\x1B\xFF\x24\x21\x1C\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x22\x22\x1D\xFF" + "\x24\x21\x1C\xFF\x24\x21\x1C\xFF\x23\x20\x1B\xFF\x20\x20\x19\xFF\x26\x23\x1E\xFF\x25\x23\x1C" + "\xFF\x23\x22\x1C\xFF\x21\x22\x1B\xFF" + "\x22\x22\x1D\xFF\x27\x2C\x24\xFF\x26\x2A\x23\xFF\x23\x24\x1C\xFF\x23\x24\x1E\xFF\x23\x22\x1D" + "\xFF\x24\x23\x1D\xFF\x22\x22\x1B\xFF" + "\x24\x22\x1D\xFF\x21\x1F\x1A\xFF\x22\x20\x1B\xFF\x21\x20\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x1E" + "\xFF\x23\x22\x1D\xFF\x1F\x1F\x19\xFF" + "\x22\x21\x1B\xFF\x23\x20\x1B\xFF\x24\x22\x1D\xFF\x24\x23\x1D\xFF\x28\x25\x1E\xFF\x25\x22\x1D" + "\xFF\x23\x22\x1D\xFF\x1F\x1E\x19\xFF" + "\x22\x22\x1C\xFF\x20\x1F\x1B\xFF\x22\x20\x1C\xFF\x20\x20\x1B\xFF\x21\x1F\x1B\xFF\x22\x21\x1C" + "\xFF\x21\x20\x1B\xFF\x24\x22\x1D\xFF" + "\x26\x23\x1E\xFF\x26\x23\x1F\xFF\x24\x22\x1D\xFF\x22\x21\x1B\xFF\x24\x23\x1D\xFF\x23\x22\x1D" + "\xFF\x23\x22\x1C\xFF\x25\x24\x1D\xFF" + "\x14\x12\x0F\xFF\x14\x13\x0F\xFF\x13\x12\x0F\xFF\x18\x17\x13\xFF\x13\x12\x0E\xFF\x14\x12\x10" + "\xFF\x16\x13\x10\xFF\x14\x14\x0E\xFF" + "\x12\x10\x0E\xFF\x0F\x0E\x0B\xFF\x11\x10\x0D\xFF\x15\x13\x11\xFF\x16\x14\x10\xFF\x14\x12\x10" + "\xFF\x15\x14\x10\xFF\x14\x13\x10\xFF" + "\x14\x13\x10\xFF\x11\x10\x0F\xFF\x14\x14\x10\xFF\x15\x14\x10\xFF\x16\x15\x11\xFF\x15\x14\x10" + "\xFF\x19\x18\x14\xFF\x15\x14\x10\xFF" + "\x12\x10\x0E\xFF\x10\x10\x0C\xFF\x10\x0F\x0D\xFF\x13\x12\x0F\xFF\x16\x15\x11\xFF\x14\x12\x10" + "\xFF\x14\x13\x10\xFF\x14\x13\x10\xFF" + "\x12\x10\x0F\xFF\x13\x12\x0F\xFF\x15\x13\x11\xFF\x14\x13\x0F\xFF\x14\x13\x10\xFF\x14\x13\x10" + "\xFF\x13\x11\x0F\xFF\x15\x13\x11\xFF" + "\x15\x14\x11\xFF\x13\x12\x0E\xFF\x12\x11\x0E\xFF\x12\x10\x0E\xFF\x12\x11\x0D\xFF\x14\x13\x0F" + "\xFF\x14\x14\x0F\xFF\x12\x11\x0D\xFF" + "\x12\x11\x0E\xFF\x15\x13\x11\xFF\x15\x14\x11\xFF\x15\x14\x11\xFF\x12\x12\x0F\xFF\x14\x14\x0F" + "\xFF\x14\x13\x11\xFF\x14\x13\x10\xFF" + "\x17\x16\x12\xFF\x15\x14\x10\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x14\x12\x10\xFF\x14\x12\x10" + "\xFF\x15\x14\x10\xFF\x13\x12\x0E\xFF" + "\x14\x13\x0F\xFF\x13\x12\x0E\xFF\x11\x10\x0D\xFF\x11\x10\x0C\xFF\x15\x14\x10\xFF\x17\x16\x12" + "\xFF\x16\x14\x11\xFF\x18\x17\x13\xFF" + "\x13\x11\x10\xFF\x14\x12\x10\xFF\x16\x15\x11\xFF\x14\x13\x0F\xFF\x12\x12\x10\xFF\x15\x13\x10" + "\xFF\x12\x12\x0F\xFF\x0F\x0F\x0D\xFF" + "\x13\x11\x10\xFF\x14\x13\x10\xFF\x17\x14\x11\xFF\x15\x14\x10\xFF\x13\x12\x0E\xFF\x12\x11\x0F" + "\xFF\x14\x13\x0F\xFF\x13\x11\x10\xFF" + "\x15\x14\x11\xFF\x16\x15\x11\xFF\x19\x18\x14\xFF\x15\x14\x11\xFF\x13\x11\x0E\xFF\x13\x11\x10" + "\xFF\x14\x13\x11\xFF\x12\x11\x0F\xFF" + "\x17\x16\x12\xFF\x19\x18\x14\xFF\x18\x16\x12\xFF\x18\x16\x13\xFF\x14\x13\x11\xFF\x14\x13\x10" + "\xFF\x17\x15\x14\xFF\x15\x14\x10\xFF" + "\x18\x17\x13\xFF\x18\x17\x12\xFF\x18\x17\x13\xFF\x1A\x19\x15\xFF\x14\x13\x0F\xFF\x16\x14\x12" + "\xFF\x17\x16\x12\xFF\x14\x13\x0F\xFF" + "\x14\x12\x11\xFF\x18\x17\x13\xFF\x15\x14\x11\xFF\x15\x13\x11\xFF\x14\x13\x0F\xFF\x19\x16\x12" + "\xFF\x1A\x19\x15\xFF\x17\x16\x12\xFF" + "\x15\x13\x11\xFF\x14\x13\x0F\xFF\x15\x14\x10\xFF\x14\x13\x10\xFF\x18\x17\x12\xFF\x15\x14\x11" + "\xFF\x16\x14\x11\xFF\x17\x16\x12\xFF" + "\x19\x17\x13\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF\x19\x18\x13\xFF\x17\x16\x12\xFF\x18\x17\x13" + "\xFF\x18\x18\x14\xFF\x17\x16\x12\xFF" + "\x15\x14\x10\xFF\x17\x16\x12\xFF\x18\x17\x13\xFF\x1B\x1A\x16\xFF\x1B\x1A\x16\xFF\x18\x17\x14" + "\xFF\x18\x16\x13\xFF\x1B\x19\x15\xFF" + "\x17\x15\x11\xFF\x14\x15\x11\xFF\x15\x15\x11\xFF\x15\x14\x10\xFF\x17\x16\x12\xFF\x17\x16\x12" + "\xFF\x17\x16\x12\xFF\x1B\x1A\x16\xFF" + "\x19\x18\x14\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF\x18\x17\x12\xFF\x14\x13\x0F\xFF\x16\x15\x11" + "\xFF\x17\x16\x12\xFF\x17\x15\x11\xFF" + "\x19\x18\x14\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x16\x15\x11" + "\xFF\x16\x14\x11\xFF\x1B\x1A\x16\xFF" + "\x1A\x19\x15\xFF\x1A\x19\x16\xFF\x19\x19\x15\xFF\x17\x15\x13\xFF\x19\x18\x14\xFF\x19\x18\x14" + "\xFF\x16\x15\x11\xFF\x1A\x19\x15\xFF" + "\x1F\x1D\x19\xFF\x19\x18\x14\xFF\x1B\x19\x15\xFF\x1B\x1A\x15\xFF\x18\x17\x13\xFF\x1A\x18\x14" + "\xFF\x19\x18\x14\xFF\x19\x17\x13\xFF" + "\x1B\x1A\x16\xFF\x19\x18\x14\xFF\x1A\x19\x15\xFF\x1A\x19\x15\xFF\x1D\x1C\x18\xFF\x19\x18\x14" + "\xFF\x18\x17\x14\xFF\x18\x16\x13\xFF" + "\x19\x17\x13\xFF\x1D\x1A\x16\xFF\x1A\x19\x15\xFF\x17\x16\x12\xFF\x1A\x18\x14\xFF\x19\x18\x14" + "\xFF\x18\x17\x14\xFF\x1A\x19\x15\xFF" + "\x19\x18\x14\xFF\x19\x18\x13\xFF\x19\x17\x13\xFF\x19\x17\x13\xFF\x1C\x1A\x16\xFF\x1B\x19\x15" + "\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF" + "\x1A\x18\x14\xFF\x1C\x1A\x16\xFF\x19\x17\x13\xFF\x17\x16\x12\xFF\x1B\x1A\x16\xFF\x1E\x1B\x17" + "\xFF\x1A\x17\x14\xFF\x19\x18\x14\xFF" + "\x1B\x1A\x16\xFF\x19\x18\x14\xFF\x1B\x19\x15\xFF\x1D\x1A\x16\xFF\x1C\x1B\x17\xFF\x1B\x1A\x16" + "\xFF\x1C\x1B\x17\xFF\x1C\x1B\x16\xFF" + "\x1D\x1C\x18\xFF\x18\x16\x12\xFF\x19\x17\x15\xFF\x19\x18\x15\xFF\x1A\x19\x15\xFF\x1C\x1A\x16" + "\xFF\x1E\x1C\x18\xFF\x20\x1F\x1A\xFF" + "\x18\x17\x13\xFF\x18\x16\x12\xFF\x1B\x19\x14\xFF\x1D\x1D\x17\xFF\x19\x1A\x15\xFF\x1F\x1E\x19" + "\xFF\x1F\x1D\x19\xFF\x20\x1E\x19\xFF" + "\x1A\x19\x14\xFF\x1A\x18\x14\xFF\x1A\x19\x15\xFF\x1D\x1B\x17\xFF\x20\x1D\x1A\xFF\x1F\x1F\x19" + "\xFF\x1E\x1D\x19\xFF\x1B\x19\x16\xFF" + "\x1C\x1B\x16\xFF\x1B\x1B\x16\xFF\x1D\x1C\x17\xFF\x1F\x1D\x18\xFF\x1B\x1B\x16\xFF\x1A\x19\x15" + "\xFF\x1C\x1A\x16\xFF\x1D\x1B\x17\xFF" + "\x1D\x1C\x16\xFF\x19\x18\x14\xFF\x1A\x1A\x15\xFF\x1D\x1D\x17\xFF\x21\x1E\x1A\xFF\x1D\x1D\x18" + "\xFF\x1F\x1E\x19\xFF\x1B\x1A\x16\xFF" + "\x1C\x1B\x16\xFF\x1D\x1C\x18\xFF\x1C\x1B\x16\xFF\x1A\x19\x15\xFF\x1A\x1A\x15\xFF\x1D\x1C\x18" + "\xFF\x1F\x1D\x19\xFF\x1F\x1C\x18\xFF" + "\x1D\x1C\x16\xFF\x1E\x1D\x19\xFF\x1D\x1C\x18\xFF\x1D\x1A\x16\xFF\x1E\x1F\x19\xFF\x1F\x1E\x1A" + "\xFF\x1E\x1C\x19\xFF\x20\x1E\x1A\xFF" + "\x1E\x1D\x18\xFF\x1E\x1C\x16\xFF\x1C\x1C\x17\xFF\x1D\x1D\x17\xFF\x1B\x1A\x16\xFF\x1C\x1A\x16" + "\xFF\x1E\x1C\x18\xFF\x22\x20\x1B\xFF" + "\x1F\x1D\x18\xFF\x1D\x1C\x18\xFF\x1F\x1E\x19\xFF\x20\x1E\x1A\xFF\x1E\x1E\x18\xFF\x1F\x1D\x19" + "\xFF\x1E\x1D\x18\xFF\x1D\x1C\x17\xFF" + "\x1F\x1E\x1A\xFF\x22\x21\x1C\xFF\x21\x20\x1A\xFF\x1E\x1E\x18\xFF\x1C\x1A\x16\xFF\x1F\x1D\x19" + "\xFF\x21\x1F\x1A\xFF\x23\x20\x1B\xFF" + "\x1F\x1F\x1A\xFF\x22\x21\x1C\xFF\x21\x20\x1B\xFF\x22\x22\x1C\xFF\x1C\x1C\x18\xFF\x1D\x1D\x19" + "\xFF\x22\x1F\x1A\xFF\x1F\x1E\x19\xFF" + "\x1A\x1A\x15\xFF\x1C\x1B\x16\xFF\x1D\x1A\x17\xFF\x1C\x1B\x18\xFF\x1F\x1E\x19\xFF\x1C\x1B\x16" + "\xFF\x1B\x1A\x16\xFF\x1E\x1B\x17\xFF" + "\x1A\x1B\x17\xFF\x1D\x1B\x16\xFF\x1C\x1B\x17\xFF\x19\x18\x15\xFF\x17\x16\x13\xFF\x17\x16\x13" + "\xFF\x19\x17\x14\xFF\x19\x19\x15\xFF" + "\x16\x16\x12\xFF\x15\x15\x11\xFF\x50\x4C\x40\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x21\x20\x1A" + "\xFF\x21\x20\x1B\xFF\x24\x22\x1D\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x28\x27\x21" + "\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x23\x22\x1D\xFF\x21\x20\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x23\x21\x1C\xFF\x22\x22\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x21\x20\x1B\xFF\x22\x20\x1B\xFF\x23\x21\x1C\xFF\x23\x21\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x21\x20\x1A\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1D\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1D\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x29\x28\x23" + "\xFF\x22\x21\x1B\xFF\x21\x20\x1A\xFF" + "\x26\x25\x20\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x28\x26\x21" + "\xFF\x23\x21\x1C\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x25\x20\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x21\x20\x1A\xFF\x21\x21\x1B\xFF" + "\x25\x24\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x23\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x23\x21\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x20\x1B\xFF\x22\x21\x1B\xFF" + "\x24\x22\x1E\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x26\x25\x20\xFF\x22\x20\x1B\xFF\x26\x25\x20" + "\xFF\x29\x28\x23\xFF\x26\x25\x20\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x29\x28\x23\xFF\x22\x21\x1B\xFF" + "\x23\x21\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1D\xFF\x22\x22\x1C\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x22\x1D\xFF" + "\x24\x23\x1E\xFF\x22\x22\x1C\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x24\x23\x1D\xFF\x22\x21\x1B" + "\xFF\x24\x22\x1D\xFF\x24\x22\x1D\xFF" + "\x22\x20\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x21\x1C\xFF\x28\x26\x21\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF" + "\x26\x24\x20\xFF\x27\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x28\x26\x21" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF" + "\x25\x24\x20\xFF\x25\x24\x1F\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x28\x26\x21\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x25\x25\x20\xFF\x22\x21\x1B" + "\xFF\x29\x28\x23\xFF\x25\x24\x1F\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x2A\x29\x23\xFF\x26\x25\x20\xFF\x22\x20\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x21\xFF\x23\x21\x1C" + "\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF" + "\x23\x22\x1C\xFF\x27\x25\x21\xFF\x22\x21\x1B\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x26\x24\x20\xFF" + "\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x27\x25\x20\xFF\x25\x24\x20\xFF" + "\x27\x25\x20\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x22\x21\x1B\xFF\x29\x28\x22" + "\xFF\x27\x25\x20\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1E\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x29\x28\x23" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x27\x25\x20\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x28\x26\x21" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x27\x25\x20\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x24\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x23\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x25\x24\x1E\xFF\x27\x26\x20\xFF\x22\x21\x1B\xFF\x27\x25\x20" + "\xFF\x29\x28\x23\xFF\x26\x25\x21\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x29\x28\x23\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x24\x23\x1E\xFF\x22\x22\x1C\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x29\x26\x21\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF" + "\x26\x25\x20\xFF\x26\x26\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x28\x26\x21" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x26\x25\x20\xFF\x25\x24\x1F\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x25\x20" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x28\x26\x21\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x22\x21\x1B" + "\xFF\x29\x28\x23\xFF\x25\x24\x1F\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x2A\x29\x23\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x27\x25\x21\xFF\x4F\x4A\x3D" + "\xFF\x19\x18\x15\xFF\x1B\x1A\x16\xFF" + "\x1D\x1B\x16\xFF\x1D\x1D\x17\xFF\x1D\x1C\x18\xFF\x1E\x1E\x19\xFF\x20\x1D\x19\xFF\x22\x1F\x1B" + "\xFF\x22\x20\x1B\xFF\x24\x21\x1D\xFF" + "\x22\x1F\x1B\xFF\x24\x22\x1D\xFF\x25\x22\x1E\xFF\x26\x24\x1F\xFF\x25\x24\x1E\xFF\x23\x23\x1D" + "\xFF\x25\x22\x1D\xFF\x27\x23\x1E\xFF" + "\x26\x23\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x25\x25\x1F\xFF\x28\x27\x20" + "\xFF\x28\x26\x21\xFF\x27\x24\x1F\xFF" + "\x25\x24\x1E\xFF\x27\x24\x1F\xFF\x28\x25\x1F\xFF\x28\x26\x21\xFF\x27\x25\x20\xFF\x26\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x26\x24\x1F\xFF" + "\x27\x26\x20\xFF\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x25\x24\x1E\xFF\x27\x25\x20\xFF\x28\x25\x20" + "\xFF\x24\x23\x1E\xFF\x26\x24\x1E\xFF" + "\x25\x23\x1E\xFF\x27\x26\x20\xFF\x27\x25\x1F\xFF\x29\x27\x20\xFF\x27\x24\x1F\xFF\x28\x25\x20" + "\xFF\x27\x25\x20\xFF\x27\x25\x1F\xFF" + "\x28\x25\x20\xFF\x28\x25\x20\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x24\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x27\x25\x1F\xFF" + "\x27\x25\x1E\xFF\x27\x25\x20\xFF\x27\x25\x20\xFF\x27\x24\x1F\xFF\x25\x26\x1E\xFF\x26\x25\x1F" + "\xFF\x27\x25\x20\xFF\x27\x24\x1F\xFF" + "\x28\x26\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x23\x22\x1D\xFF\x28\x25\x20\xFF\x29\x27\x20" + "\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF" + "\x23\x22\x1C\xFF\x28\x25\x1F\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x25\x1E" + "\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF" + "\x27\x24\x1F\xFF\x27\x25\x1F\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x26\x25\x20\xFF\x26\x24\x1F" + "\xFF\x23\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x24\x23\x1E\xFF\x25\x24\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF\x27\x26\x1F" + "\xFF\x26\x23\x1E\xFF\x25\x22\x1D\xFF" + "\x26\x23\x1E\xFF\x26\x24\x1E\xFF\x27\x26\x20\xFF\x28\x26\x21\xFF\x25\x22\x1D\xFF\x27\x26\x1F" + "\xFF\x27\x25\x1E\xFF\x24\x23\x1D\xFF" + "\x24\x22\x1E\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x25\x26\x1D\xFF\x29\x26\x21\xFF\x26\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x26\x25\x1E\xFF" + "\x27\x24\x1F\xFF\x25\x23\x1D\xFF\x27\x25\x1E\xFF\x27\x27\x21\xFF\x27\x24\x21\xFF\x28\x26\x1F" + "\xFF\x26\x23\x1E\xFF\x24\x23\x1E\xFF" + "\x24\x23\x1E\xFF\x24\x22\x1D\xFF\x23\x21\x1D\xFF\x26\x23\x1E\xFF\x29\x29\x22\xFF\x2E\x3E\x31" + "\xFF\x48\x9C\x74\xFF\x56\xCC\x97\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCA\x96\xFF\x3F\x7F\x5F\xFF\x28\x33\x28\xFF\x27\x27\x20\xFF\x27\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x24\x23\x1E\xFF" + "\x25\x22\x1D\xFF\x23\x21\x1C\xFF\x23\x21\x1C\xFF\x27\x24\x1F\xFF\x25\x24\x1E\xFF\x24\x24\x1E" + "\xFF\x23\x22\x1E\xFF\x24\x23\x1F\xFF" + "\x25\x27\x1F\xFF\x2B\x38\x2C\xFF\x46\x94\x6F\xFF\x57\xCB\x97\xFF\x57\xCD\x98\xFF\x56\xCD\x98" + "\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCC\x97\xFF\x3E\x7D\x5E\xFF\x28\x2E\x26\xFF\x24\x24\x1F" + "\xFF\x23\x22\x1D\xFF\x26\x23\x1E\xFF" + "\x27\x25\x20\xFF\x26\x24\x1E\xFF\x24\x23\x1D\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x22\x20\x1C" + "\xFF\x24\x22\x1D\xFF\x24\x24\x1E\xFF" + "\x25\x22\x1E\xFF\x26\x23\x1E\xFF\x25\x22\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x27\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x24\x21\x1D\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x24\x22\x1C\xFF\x24\x23\x1D" + "\xFF\x23\x23\x1D\xFF\x25\x22\x1D\xFF" + "\x21\x21\x1B\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x24\x21\x1D\xFF\x23\x22\x1C\xFF\x25\x23\x1E" + "\xFF\x23\x22\x1C\xFF\x25\x22\x1D\xFF" + "\x26\x25\x1F\xFF\x26\x23\x1F\xFF\x23\x22\x1D\xFF\x24\x21\x1C\xFF\x26\x24\x1F\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1C\xFF\x22\x22\x1C\xFF" + "\x24\x22\x1D\xFF\x23\x21\x1C\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x22\x22\x1B\xFF\x25\x23\x1C" + "\xFF\x26\x24\x1E\xFF\x22\x21\x1C\xFF" + "\x24\x22\x1D\xFF\x23\x22\x1C\xFF\x21\x21\x1C\xFF\x24\x22\x1D\xFF\x23\x22\x1C\xFF\x25\x25\x1E" + "\xFF\x24\x23\x1E\xFF\x26\x24\x1D\xFF" + "\x23\x20\x1C\xFF\x23\x21\x1C\xFF\x24\x21\x1C\xFF\x25\x22\x1E\xFF\x23\x23\x1D\xFF\x26\x24\x1E" + "\xFF\x24\x23\x1D\xFF\x24\x22\x1E\xFF" + "\x23\x23\x1D\xFF\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x23\x22\x1D\xFF\x20\x1F\x1A\xFF\x21\x20\x1B" + "\xFF\x25\x21\x1D\xFF\x25\x22\x1E\xFF" + "\x21\x20\x1B\xFF\x22\x20\x1C\xFF\x24\x22\x1D\xFF\x23\x21\x1C\xFF\x23\x20\x1C\xFF\x25\x22\x1D" + "\xFF\x23\x21\x1C\xFF\x21\x22\x1A\xFF" + "\x24\x21\x1C\xFF\x25\x23\x1E\xFF\x26\x24\x1F\xFF\x25\x22\x1D\xFF\x24\x23\x1D\xFF\x25\x24\x1E" + "\xFF\x25\x24\x1E\xFF\x25\x22\x1D\xFF" + "\x27\x24\x1F\xFF\x25\x22\x1D\xFF\x23\x22\x1C\xFF\x24\x23\x1D\xFF\x22\x22\x1A\xFF\x25\x22\x1D" + "\xFF\x26\x22\x1D\xFF\x25\x22\x1D\xFF" + "\x23\x21\x1C\xFF\x22\x21\x1C\xFF\x24\x21\x1C\xFF\x24\x21\x1C\xFF\x22\x22\x1C\xFF\x22\x20\x1B" + "\xFF\x22\x20\x1B\xFF\x23\x23\x1D\xFF" + "\x26\x24\x1F\xFF\x22\x22\x1C\xFF\x21\x20\x1B\xFF\x22\x1F\x1A\xFF\x21\x20\x1B\xFF\x21\x20\x1B" + "\xFF\x22\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x24\x21\x1C\xFF\x23\x20\x1B\xFF\x24\x21\x1C\xFF\x22\x20\x1B\xFF\x22\x21\x1B\xFF\x27\x24\x1F" + "\xFF\x28\x25\x1F\xFF\x25\x23\x1D\xFF" + "\x21\x21\x1B\xFF\x24\x23\x1D\xFF\x26\x23\x1E\xFF\x26\x24\x1C\xFF\x26\x26\x20\xFF\x28\x25\x20" + "\xFF\x23\x22\x1D\xFF\x20\x20\x1B\xFF" + "\x23\x22\x1D\xFF\x23\x21\x1C\xFF\x21\x21\x1B\xFF\x21\x21\x1C\xFF\x25\x23\x1D\xFF\x24\x22\x1D" + "\xFF\x23\x21\x1C\xFF\x20\x20\x1A\xFF" + "\x22\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x23\x1D\xFF\x22\x21\x1C\xFF\x25\x23\x1D\xFF\x23\x21\x1D" + "\xFF\x22\x20\x1B\xFF\x22\x22\x1D\xFF" + "\x25\x22\x1D\xFF\x22\x21\x1C\xFF\x21\x20\x1B\xFF\x20\x20\x1A\xFF\x21\x21\x1C\xFF\x21\x20\x1B" + "\xFF\x20\x20\x1B\xFF\x25\x22\x1D\xFF" + "\x22\x20\x1C\xFF\x26\x24\x20\xFF\x23\x23\x1D\xFF\x24\x23\x1D\xFF\x22\x1F\x1B\xFF\x24\x22\x1E" + "\xFF\x25\x22\x1E\xFF\x24\x23\x1D\xFF" + "\x0F\x0F\x0D\xFF\x13\x12\x0F\xFF\x12\x11\x0E\xFF\x12\x10\x0E\xFF\x11\x10\x0D\xFF\x12\x11\x0E" + "\xFF\x13\x12\x0F\xFF\x11\x0F\x0E\xFF" + "\x12\x11\x0E\xFF\x12\x11\x0F\xFF\x13\x11\x0E\xFF\x12\x11\x0D\xFF\x19\x18\x14\xFF\x16\x15\x12" + "\xFF\x12\x11\x0E\xFF\x11\x10\x0F\xFF" + "\x14\x13\x0F\xFF\x16\x14\x10\xFF\x13\x12\x0E\xFF\x16\x15\x11\xFF\x17\x15\x11\xFF\x13\x13\x0F" + "\xFF\x12\x12\x0E\xFF\x13\x11\x0F\xFF" + "\x13\x12\x0F\xFF\x13\x11\x0F\xFF\x12\x10\x0E\xFF\x16\x14\x11\xFF\x18\x19\x12\xFF\x14\x12\x0F" + "\xFF\x14\x10\x0F\xFF\x12\x10\x0F\xFF" + "\x12\x10\x0F\xFF\x14\x12\x11\xFF\x15\x14\x11\xFF\x18\x18\x12\xFF\x14\x13\x0F\xFF\x13\x12\x0E" + "\xFF\x15\x14\x11\xFF\x14\x12\x11\xFF" + "\x13\x12\x0E\xFF\x13\x12\x0E\xFF\x13\x12\x0E\xFF\x13\x12\x10\xFF\x12\x11\x0F\xFF\x14\x13\x0F" + "\xFF\x15\x14\x10\xFF\x19\x19\x14\xFF" + "\x14\x14\x0F\xFF\x12\x12\x0D\xFF\x12\x10\x0E\xFF\x14\x13\x0F\xFF\x11\x10\x0E\xFF\x13\x13\x10" + "\xFF\x16\x15\x11\xFF\x17\x16\x12\xFF" + "\x10\x0F\x0B\xFF\x11\x10\x0E\xFF\x15\x14\x10\xFF\x14\x12\x10\xFF\x15\x14\x10\xFF\x15\x14\x10" + "\xFF\x14\x13\x0F\xFF\x16\x15\x11\xFF" + "\x13\x12\x0E\xFF\x14\x13\x0F\xFF\x15\x13\x10\xFF\x15\x13\x10\xFF\x14\x13\x0F\xFF\x14\x13\x10" + "\xFF\x13\x12\x0F\xFF\x11\x10\x0C\xFF" + "\x14\x13\x0F\xFF\x14\x13\x10\xFF\x11\x11\x0F\xFF\x12\x11\x0D\xFF\x14\x11\x0D\xFF\x16\x13\x0F" + "\xFF\x15\x13\x12\xFF\x16\x15\x11\xFF" + "\x13\x13\x0F\xFF\x13\x12\x0F\xFF\x16\x15\x12\xFF\x16\x15\x11\xFF\x12\x10\x0F\xFF\x14\x13\x0F" + "\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF" + "\x15\x14\x11\xFF\x13\x12\x0E\xFF\x14\x13\x0F\xFF\x14\x13\x0F\xFF\x14\x13\x10\xFF\x17\x16\x12" + "\xFF\x16\x15\x11\xFF\x14\x13\x10\xFF" + "\x15\x14\x11\xFF\x16\x15\x13\xFF\x16\x14\x11\xFF\x17\x14\x10\xFF\x16\x15\x11\xFF\x16\x15\x11" + "\xFF\x17\x16\x12\xFF\x15\x14\x11\xFF" + "\x17\x16\x13\xFF\x11\x10\x0E\xFF\x13\x12\x0E\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF\x16\x15\x11" + "\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF" + "\x13\x11\x0F\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x16\x15\x12\xFF\x15\x14\x10\xFF\x14\x13\x0E" + "\xFF\x17\x16\x11\xFF\x18\x17\x12\xFF" + "\x16\x15\x11\xFF\x16\x15\x11\xFF\x19\x18\x14\xFF\x16\x15\x11\xFF\x14\x12\x10\xFF\x14\x13\x0F" + "\xFF\x14\x13\x0E\xFF\x14\x13\x0F\xFF" + "\x18\x17\x13\xFF\x16\x16\x12\xFF\x12\x12\x0F\xFF\x14\x13\x0F\xFF\x16\x14\x11\xFF\x15\x13\x11" + "\xFF\x17\x15\x12\xFF\x18\x17\x13\xFF" + "\x18\x17\x13\xFF\x15\x14\x10\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF\x16\x15\x11\xFF\x13\x13\x0E" + "\xFF\x16\x15\x11\xFF\x16\x14\x10\xFF" + "\x15\x13\x11\xFF\x18\x17\x14\xFF\x1C\x1A\x16\xFF\x17\x15\x11\xFF\x14\x13\x0F\xFF\x18\x16\x12" + "\xFF\x1B\x18\x14\xFF\x17\x15\x11\xFF" + "\x14\x13\x0F\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF\x19\x18\x14" + "\xFF\x1B\x1A\x16\xFF\x1B\x1A\x16\xFF" + "\x17\x16\x13\xFF\x15\x14\x10\xFF\x16\x15\x10\xFF\x1B\x1A\x16\xFF\x17\x16\x12\xFF\x1B\x1A\x16" + "\xFF\x18\x17\x13\xFF\x18\x18\x12\xFF" + "\x1A\x17\x14\xFF\x1A\x18\x14\xFF\x1B\x1A\x15\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x17\x16\x12" + "\xFF\x18\x17\x13\xFF\x1B\x1A\x16\xFF" + "\x19\x17\x13\xFF\x18\x17\x13\xFF\x1A\x18\x14\xFF\x1B\x19\x16\xFF\x17\x16\x12\xFF\x18\x17\x13" + "\xFF\x1B\x1A\x16\xFF\x1B\x1B\x16\xFF" + "\x1B\x19\x15\xFF\x18\x16\x12\xFF\x16\x15\x11\xFF\x18\x17\x15\xFF\x1E\x1E\x18\xFF\x1D\x1C\x18" + "\xFF\x1A\x19\x14\xFF\x19\x18\x13\xFF" + "\x1A\x18\x14\xFF\x1A\x19\x15\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF\x1A\x19\x15\xFF\x18\x17\x13" + "\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF" + "\x19\x18\x14\xFF\x1A\x19\x14\xFF\x1C\x1A\x15\xFF\x1A\x19\x14\xFF\x19\x1A\x15\xFF\x1B\x19\x15" + "\xFF\x1D\x1A\x16\xFF\x1E\x1C\x18\xFF" + "\x1F\x1D\x19\xFF\x1A\x18\x14\xFF\x1A\x18\x14\xFF\x1A\x19\x15\xFF\x1B\x19\x17\xFF\x1A\x19\x14" + "\xFF\x1B\x19\x15\xFF\x1A\x18\x14\xFF" + "\x1B\x1A\x16\xFF\x1B\x1A\x15\xFF\x1D\x1C\x17\xFF\x1F\x1E\x19\xFF\x1E\x1C\x17\xFF\x1B\x1B\x15" + "\xFF\x1C\x1B\x17\xFF\x1B\x19\x15\xFF" + "\x1B\x1A\x16\xFF\x1B\x19\x15\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF\x1B\x1A\x16\xFF\x1C\x1A\x17" + "\xFF\x1D\x1B\x18\xFF\x1B\x1B\x15\xFF" + "\x20\x1E\x19\xFF\x1D\x1B\x17\xFF\x1D\x1C\x18\xFF\x1B\x1A\x16\xFF\x1D\x1B\x17\xFF\x1C\x1B\x17" + "\xFF\x1E\x1D\x19\xFF\x1A\x19\x15\xFF" + "\x19\x18\x14\xFF\x19\x19\x15\xFF\x19\x17\x13\xFF\x19\x18\x14\xFF\x1F\x1E\x19\xFF\x1E\x1C\x18" + "\xFF\x1F\x1D\x19\xFF\x1F\x1F\x1A\xFF" + "\x1D\x1B\x17\xFF\x1C\x1A\x16\xFF\x1A\x18\x16\xFF\x18\x17\x13\xFF\x19\x19\x14\xFF\x1E\x1C\x17" + "\xFF\x1B\x19\x15\xFF\x1C\x1B\x17\xFF" + "\x1F\x1C\x18\xFF\x1B\x1A\x16\xFF\x1D\x1C\x18\xFF\x1A\x19\x16\xFF\x1E\x1B\x17\xFF\x20\x1E\x1A" + "\xFF\x1F\x1E\x1A\xFF\x1C\x1B\x17\xFF" + "\x1C\x19\x15\xFF\x20\x1E\x1A\xFF\x22\x20\x1B\xFF\x1F\x1C\x17\xFF\x1F\x1C\x18\xFF\x1E\x1C\x18" + "\xFF\x1C\x1B\x17\xFF\x1A\x19\x15\xFF" + "\x1C\x1B\x17\xFF\x1E\x1C\x18\xFF\x1C\x1B\x18\xFF\x1C\x1C\x17\xFF\x1F\x1E\x1A\xFF\x1D\x1B\x17" + "\xFF\x1E\x1E\x19\xFF\x1D\x1B\x17\xFF" + "\x20\x1F\x1A\xFF\x1D\x1C\x17\xFF\x1D\x1C\x17\xFF\x20\x1D\x19\xFF\x1F\x1E\x19\xFF\x21\x21\x1A" + "\xFF\x1F\x1D\x18\xFF\x1C\x1C\x18\xFF" + "\x1D\x1D\x18\xFF\x20\x20\x1A\xFF\x21\x21\x1B\xFF\x22\x20\x1B\xFF\x1E\x1E\x19\xFF\x1E\x1E\x19" + "\xFF\x1E\x1D\x18\xFF\x1D\x1C\x18\xFF" + "\x20\x1F\x1A\xFF\x22\x20\x1C\xFF\x21\x1F\x1B\xFF\x1F\x1F\x19\xFF\x1E\x1E\x18\xFF\x1C\x1B\x17" + "\xFF\x1F\x1D\x19\xFF\x1E\x1C\x18\xFF" + "\x1D\x1C\x18\xFF\x1C\x1B\x16\xFF\x1D\x1D\x17\xFF\x1F\x1E\x1A\xFF\x1E\x1F\x17\xFF\x1E\x1D\x18" + "\xFF\x1F\x1E\x19\xFF\x20\x20\x1A\xFF" + "\x1F\x1E\x19\xFF\x1F\x1D\x18\xFF\x1F\x1D\x19\xFF\x1F\x1D\x1A\xFF\x1E\x1C\x17\xFF\x1D\x1B\x17" + "\xFF\x1D\x1C\x18\xFF\x1F\x1E\x19\xFF" + "\x1E\x1C\x18\xFF\x1B\x1B\x16\xFF\x1A\x19\x15\xFF\x1C\x1B\x18\xFF\x1A\x18\x15\xFF\x18\x18\x14" + "\xFF\x17\x17\x13\xFF\x17\x17\x13\xFF" + "\x16\x16\x12\xFF\x15\x14\x11\xFF\x4E\x4A\x3D\xFF\x23\x22\x1D\xFF\x21\x20\x1A\xFF\x21\x20\x1A" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF" + "\x22\x21\x1A\xFF\x26\x25\x20\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x28\x26\x21\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x21\x21\x1B\xFF" + "\x28\x27\x21\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x28\x26\x22\xFF\x26\x25\x21" + "\xFF\x28\x26\x21\xFF\x21\x20\x1A\xFF" + "\x28\x26\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x21\x20\x1B\xFF\x22\x21\x1C\xFF\x29\x28\x22" + "\xFF\x23\x22\x1C\xFF\x21\x20\x1A\xFF" + "\x25\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x25\x25\x20\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF" + "\x25\x24\x20\xFF\x28\x26\x21\xFF\x23\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x22\x20\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x20\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x25\x24\x20\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1F\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x25\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x28\x26\x21\xFF\x22\x20\x1B\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF" + "\x25\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x23\x22\x1C\xFF\x22\x22\x1C\xFF\x2A\x29\x23" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x26\x25\x21\xFF\x23\x22\x1C\xFF\x27\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x28\x26\x21\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x22\x1C\xFF" + "\x24\x23\x1E\xFF\x29\x28\x22\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x22\x1C\xFF\x23\x22\x1C\xFF\x28\x26\x22" + "\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x21\x20\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x25\x23\x1E\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x28\x26\x21\xFF\x27\x25\x20\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x25\x23\x1E\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x24\x23\x1E\xFF\x24\x23\x1E" + "\xFF\x29\x28\x23\xFF\x26\x25\x20\xFF" + "\x25\x24\x20\xFF\x26\x25\x20\xFF\x29\x28\x22\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x2A\x29\x23\xFF\x25\x24\x20\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x2B\x2A\x24\xFF" + "\x26\x25\x21\xFF\x23\x23\x1E\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x27\x26\x20\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x29\x28\x22" + "\xFF\x23\x22\x1C\xFF\x25\x24\x1F\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x26\x24\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x26\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x26\x24\x20\xFF\x23\x22\x1C\xFF\x28\x26\x21\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x29\x28\x22\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x28\x26\x22\xFF\x26\x25\x21" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x28\x26\x21\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x29\x28\x22" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x26\x25\x20\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x25\x24\x20\xFF\x28\x26\x21\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x25\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x27\x25\x20\xFF\x26\x24\x20\xFF\x23\x22\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF" + "\x25\x24\x20\xFF\x23\x22\x1C\xFF\x25\x24\x1F\xFF\x26\x25\x21\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x27\x25\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x26\x25\x20" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x26\x25\x20\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x22\x22\x1C\xFF\x2A\x29\x23" + "\xFF\x22\x21\x1B\xFF\x27\x25\x20\xFF" + "\x27\x25\x21\xFF\x23\x22\x1C\xFF\x27\x25\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x28\x26\x21\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x24\x23\x1E\xFF\x29\x28\x22\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x22\x1C\xFF\x23\x22\x1C\xFF\x29\x27\x22" + "\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x25\x24\x1F\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x28\x26\x21\xFF\x27\x26\x21\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x27\x26\x21\xFF" + "\x25\x24\x1F\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x24\x23\x1E\xFF\x24\x23\x1E" + "\xFF\x29\x28\x23\xFF\x26\x25\x20\xFF" + "\x26\x24\x20\xFF\x27\x25\x20\xFF\x29\x28\x22\xFF\x26\x24\x20\xFF\x23\x22\x1C\xFF\x4F\x4A\x3D" + "\xFF\x1A\x19\x15\xFF\x19\x19\x15\xFF" + "\x1B\x1A\x16\xFF\x1D\x1B\x17\xFF\x1D\x1C\x18\xFF\x1D\x1C\x18\xFF\x21\x1E\x19\xFF\x21\x1F\x1B" + "\xFF\x21\x20\x1B\xFF\x21\x21\x1B\xFF" + "\x23\x20\x1C\xFF\x22\x22\x1C\xFF\x21\x21\x1C\xFF\x25\x22\x1D\xFF\x24\x24\x1D\xFF\x25\x24\x1F" + "\xFF\x27\x25\x1F\xFF\x24\x23\x1E\xFF" + "\x24\x23\x1D\xFF\x28\x25\x20\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x25\x24\x1F\xFF\x25\x24\x1E" + "\xFF\x23\x23\x1D\xFF\x27\x25\x1F\xFF" + "\x28\x25\x20\xFF\x29\x26\x21\xFF\x25\x24\x1E\xFF\x24\x22\x1D\xFF\x28\x26\x20\xFF\x27\x25\x1F" + "\xFF\x26\x23\x1E\xFF\x27\x24\x1E\xFF" + "\x27\x24\x1F\xFF\x24\x23\x1E\xFF\x26\x24\x1F\xFF\x28\x28\x22\xFF\x28\x25\x20\xFF\x28\x25\x20" + "\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF" + "\x26\x23\x1E\xFF\x29\x27\x20\xFF\x2A\x27\x22\xFF\x29\x26\x1F\xFF\x26\x25\x1F\xFF\x27\x24\x1F" + "\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF" + "\x28\x25\x20\xFF\x27\x25\x1F\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF\x26\x25\x1F\xFF\x26\x24\x1F" + "\xFF\x28\x24\x1F\xFF\x29\x25\x20\xFF" + "\x27\x26\x20\xFF\x23\x23\x1D\xFF\x26\x24\x1E\xFF\x29\x26\x21\xFF\x25\x24\x1E\xFF\x24\x24\x1E" + "\xFF\x23\x24\x1E\xFF\x28\x28\x21\xFF" + "\x28\x25\x20\xFF\x27\x24\x1F\xFF\x25\x23\x1D\xFF\x25\x24\x1E\xFF\x27\x25\x20\xFF\x27\x25\x1F" + "\xFF\x26\x23\x1E\xFF\x27\x25\x20\xFF" + "\x25\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x24\x23\x1E\xFF\x26\x24\x1F\xFF\x26\x25\x20" + "\xFF\x28\x26\x21\xFF\x28\x26\x21\xFF" + "\x26\x24\x1F\xFF\x25\x24\x1E\xFF\x26\x25\x1F\xFF\x27\x25\x20\xFF\x25\x25\x1F\xFF\x24\x24\x1D" + "\xFF\x27\x26\x1E\xFF\x27\x26\x20\xFF" + "\x25\x25\x1F\xFF\x26\x24\x1F\xFF\x25\x22\x1E\xFF\x26\x23\x1E\xFF\x24\x23\x1E\xFF\x26\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x28\x26\x20\xFF" + "\x25\x22\x1E\xFF\x25\x23\x1E\xFF\x27\x25\x20\xFF\x28\x27\x20\xFF\x26\x26\x1E\xFF\x27\x24\x1F" + "\xFF\x26\x23\x1E\xFF\x25\x25\x1F\xFF" + "\x28\x26\x1F\xFF\x27\x25\x1F\xFF\x26\x24\x1F\xFF\x23\x23\x1D\xFF\x25\x24\x20\xFF\x26\x25\x20" + "\xFF\x29\x25\x20\xFF\x26\x24\x1F\xFF" + "\x24\x22\x1D\xFF\x23\x23\x1D\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF\x24\x23\x1D" + "\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF" + "\x25\x23\x1E\xFF\x26\x23\x1E\xFF\x28\x25\x20\xFF\x27\x24\x1F\xFF\x25\x26\x1F\xFF\x28\x2F\x25" + "\xFF\x3E\x78\x5B\xFF\x54\xC4\x91\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x4C\xA5\x7B\xFF\x30\x46\x37\xFF\x27\x27\x21\xFF\x27\x25\x1F" + "\xFF\x25\x24\x1E\xFF\x26\x23\x1E\xFF" + "\x24\x23\x1C\xFF\x26\x23\x1E\xFF\x24\x22\x1D\xFF\x27\x24\x1F\xFF\x25\x24\x1E\xFF\x29\x26\x21" + "\xFF\x25\x23\x1E\xFF\x25\x24\x1E\xFF" + "\x27\x26\x21\xFF\x28\x2C\x26\xFF\x39\x6C\x52\xFF\x53\xC1\x8F\xFF\x57\xCD\x98\xFF\x56\xCD\x98" + "\xFF\x56\xCD\x98\xFF\x56\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCC\x97\xFF\x4F\xB5\x85\xFF\x29\x38\x2D\xFF\x27\x28\x21" + "\xFF\x24\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x24\x24\x1E\xFF\x24\x22\x1D\xFF\x24\x23\x1D\xFF\x25\x25\x1F\xFF\x27\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x24\x22\x1D\xFF\x22\x21\x1C\xFF" + "\x25\x22\x1D\xFF\x25\x24\x1F\xFF\x24\x23\x1D\xFF\x26\x24\x1E\xFF\x27\x25\x1F\xFF\x25\x23\x1E" + "\xFF\x24\x22\x1E\xFF\x25\x25\x1E\xFF" + "\x26\x24\x1F\xFF\x23\x22\x1D\xFF\x25\x23\x1D\xFF\x25\x22\x1D\xFF\x25\x24\x1E\xFF\x27\x24\x1F" + "\xFF\x26\x23\x1E\xFF\x25\x23\x1E\xFF" + "\x23\x23\x1D\xFF\x25\x25\x1F\xFF\x27\x26\x21\xFF\x26\x24\x1E\xFF\x24\x23\x1E\xFF\x24\x22\x1C" + "\xFF\x22\x21\x1C\xFF\x26\x23\x1E\xFF" + "\x25\x22\x1D\xFF\x24\x22\x1D\xFF\x26\x24\x1E\xFF\x24\x23\x1D\xFF\x27\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x24\x22\x1D\xFF\x23\x22\x1D\xFF" + "\x24\x21\x1C\xFF\x23\x22\x1C\xFF\x25\x24\x1E\xFF\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x24\x21\x1C" + "\xFF\x26\x24\x1F\xFF\x27\x27\x1E\xFF" + "\x25\x24\x1E\xFF\x26\x23\x1E\xFF\x24\x23\x1D\xFF\x22\x23\x1E\xFF\x22\x21\x1B\xFF\x21\x20\x1C" + "\xFF\x23\x22\x1D\xFF\x24\x22\x1D\xFF" + "\x20\x20\x1A\xFF\x21\x20\x1B\xFF\x24\x22\x1D\xFF\x26\x23\x1E\xFF\x24\x24\x1E\xFF\x25\x25\x1E" + "\xFF\x23\x21\x1C\xFF\x21\x20\x1A\xFF" + "\x21\x20\x1B\xFF\x23\x21\x1C\xFF\x24\x22\x1D\xFF\x24\x21\x1D\xFF\x22\x22\x1C\xFF\x22\x21\x1C" + "\xFF\x22\x21\x1C\xFF\x22\x21\x1C\xFF" + "\x24\x21\x1C\xFF\x21\x20\x1B\xFF\x22\x20\x1B\xFF\x26\x24\x1F\xFF\x22\x20\x1B\xFF\x22\x22\x1C" + "\xFF\x24\x23\x1E\xFF\x21\x20\x1B\xFF" + "\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x23\x22\x1D\xFF\x22\x23\x1E\xFF\x22\x22\x1C\xFF\x24\x23\x1D" + "\xFF\x27\x24\x1F\xFF\x25\x22\x1D\xFF" + "\x25\x21\x1C\xFF\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x24\x21\x1D\xFF\x22\x1E\x1A\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x25\x22\x1D\xFF" + "\x22\x22\x1C\xFF\x22\x22\x1D\xFF\x21\x21\x1B\xFF\x23\x23\x1C\xFF\x22\x20\x1B\xFF\x23\x22\x1C" + "\xFF\x25\x23\x1D\xFF\x24\x22\x1D\xFF" + "\x26\x23\x1E\xFF\x24\x22\x1D\xFF\x23\x20\x1B\xFF\x21\x1F\x1A\xFF\x23\x23\x1D\xFF\x22\x22\x1C" + "\xFF\x26\x23\x1E\xFF\x26\x25\x1F\xFF" + "\x27\x24\x1F\xFF\x21\x21\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x23\x21\x1C\xFF\x21\x20\x1A" + "\xFF\x22\x20\x1B\xFF\x20\x20\x1B\xFF" + "\x22\x22\x1C\xFF\x23\x20\x1B\xFF\x25\x22\x1D\xFF\x23\x22\x1C\xFF\x22\x22\x1C\xFF\x21\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x23\x20\x1B\xFF" + "\x22\x20\x1B\xFF\x24\x22\x1D\xFF\x23\x22\x1D\xFF\x20\x20\x1A\xFF\x25\x21\x1C\xFF\x24\x23\x1D" + "\xFF\x20\x21\x1B\xFF\x22\x22\x1C\xFF" + "\x22\x21\x1C\xFF\x1F\x1F\x19\xFF\x20\x1F\x1A\xFF\x1F\x20\x1A\xFF\x23\x20\x1C\xFF\x22\x21\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x21\x1C\xFF" + "\x1F\x1F\x1B\xFF\x21\x22\x1D\xFF\x20\x1F\x1B\xFF\x21\x21\x1B\xFF\x21\x1E\x1A\xFF\x22\x20\x1C" + "\xFF\x23\x21\x1C\xFF\x21\x20\x1B\xFF" + "\x23\x22\x1D\xFF\x25\x21\x1D\xFF\x21\x20\x1B\xFF\x20\x1F\x1B\xFF\x22\x20\x1B\xFF\x25\x23\x1D" + "\xFF\x24\x23\x1E\xFF\x24\x23\x1C\xFF" + "\x14\x13\x10\xFF\x12\x11\x0E\xFF\x12\x12\x0E\xFF\x12\x11\x0E\xFF\x10\x10\x0D\xFF\x10\x10\x0C" + "\xFF\x10\x0F\x0B\xFF\x14\x13\x10\xFF" + "\x11\x0F\x0E\xFF\x12\x11\x0E\xFF\x14\x12\x10\xFF\x13\x11\x10\xFF\x14\x13\x0F\xFF\x11\x10\x0E" + "\xFF\x12\x11\x0F\xFF\x10\x0F\x0E\xFF" + "\x15\x14\x0F\xFF\x12\x11\x0D\xFF\x13\x11\x0E\xFF\x16\x15\x11\xFF\x15\x15\x11\xFF\x16\x15\x11" + "\xFF\x13\x12\x10\xFF\x13\x11\x0F\xFF" + "\x0F\x0F\x0D\xFF\x0F\x0E\x0C\xFF\x10\x0E\x0C\xFF\x14\x11\x10\xFF\x14\x13\x0E\xFF\x13\x12\x0E" + "\xFF\x14\x12\x11\xFF\x12\x10\x0E\xFF" + "\x0F\x0E\x0D\xFF\x13\x11\x10\xFF\x13\x12\x0F\xFF\x14\x12\x0F\xFF\x12\x11\x0D\xFF\x14\x12\x0F" + "\xFF\x15\x14\x10\xFF\x13\x11\x10\xFF" + "\x14\x12\x0E\xFF\x13\x12\x0F\xFF\x14\x13\x0F\xFF\x14\x13\x0E\xFF\x13\x11\x0F\xFF\x14\x13\x10" + "\xFF\x16\x14\x10\xFF\x15\x14\x10\xFF" + "\x13\x11\x0F\xFF\x12\x11\x0D\xFF\x13\x12\x0F\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x14\x13\x10" + "\xFF\x15\x13\x10\xFF\x13\x11\x0F\xFF" + "\x12\x12\x0E\xFF\x10\x0F\x0D\xFF\x14\x13\x0F\xFF\x15\x13\x11\xFF\x13\x12\x0F\xFF\x15\x13\x10" + "\xFF\x16\x15\x11\xFF\x15\x13\x10\xFF" + "\x15\x14\x10\xFF\x14\x13\x0F\xFF\x15\x14\x10\xFF\x15\x14\x10\xFF\x14\x13\x0F\xFF\x13\x12\x0E" + "\xFF\x14\x13\x0F\xFF\x15\x14\x10\xFF" + "\x16\x15\x11\xFF\x14\x13\x0F\xFF\x15\x14\x10\xFF\x14\x13\x0F\xFF\x14\x13\x0F\xFF\x16\x15\x10" + "\xFF\x15\x14\x11\xFF\x15\x14\x10\xFF" + "\x11\x10\x0F\xFF\x14\x12\x0F\xFF\x13\x11\x0F\xFF\x13\x11\x0F\xFF\x15\x13\x10\xFF\x15\x14\x10" + "\xFF\x15\x14\x11\xFF\x16\x15\x11\xFF" + "\x15\x14\x11\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x16\x14\x10\xFF\x16\x15\x13\xFF\x16\x15\x11" + "\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF" + "\x12\x10\x0E\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x15\x14\x11\xFF\x15\x14\x10\xFF\x18\x17\x13" + "\xFF\x17\x16\x12\xFF\x15\x13\x10\xFF" + "\x17\x16\x13\xFF\x13\x11\x10\xFF\x16\x14\x11\xFF\x15\x14\x10\xFF\x13\x11\x10\xFF\x14\x13\x0F" + "\xFF\x15\x14\x10\xFF\x15\x14\x10\xFF" + "\x16\x15\x11\xFF\x16\x15\x10\xFF\x16\x15\x10\xFF\x15\x13\x11\xFF\x16\x15\x11\xFF\x17\x15\x12" + "\xFF\x15\x14\x11\xFF\x12\x12\x0E\xFF" + "\x15\x14\x10\xFF\x16\x15\x11\xFF\x1A\x19\x15\xFF\x19\x18\x14\xFF\x14\x13\x0F\xFF\x15\x14\x10" + "\xFF\x18\x17\x13\xFF\x15\x14\x11\xFF" + "\x17\x15\x11\xFF\x17\x16\x12\xFF\x18\x16\x12\xFF\x18\x16\x12\xFF\x14\x13\x10\xFF\x18\x17\x13" + "\xFF\x17\x16\x12\xFF\x1A\x19\x15\xFF" + "\x19\x18\x14\xFF\x17\x16\x12\xFF\x18\x17\x13\xFF\x16\x15\x11\xFF\x16\x15\x12\xFF\x17\x16\x13" + "\xFF\x18\x17\x13\xFF\x17\x15\x11\xFF" + "\x18\x16\x12\xFF\x16\x15\x12\xFF\x16\x14\x12\xFF\x18\x16\x13\xFF\x15\x14\x10\xFF\x17\x15\x11" + "\xFF\x17\x15\x11\xFF\x14\x13\x0F\xFF" + "\x16\x15\x11\xFF\x16\x15\x11\xFF\x16\x15\x12\xFF\x1B\x1A\x16\xFF\x16\x15\x11\xFF\x19\x18\x14" + "\xFF\x19\x18\x14\xFF\x1C\x1C\x17\xFF" + "\x17\x16\x12\xFF\x18\x17\x12\xFF\x18\x17\x13\xFF\x17\x15\x13\xFF\x16\x15\x12\xFF\x1A\x19\x14" + "\xFF\x1A\x19\x15\xFF\x1A\x19\x15\xFF" + "\x19\x18\x15\xFF\x19\x17\x13\xFF\x19\x17\x13\xFF\x15\x14\x11\xFF\x15\x14\x10\xFF\x17\x16\x12" + "\xFF\x19\x18\x14\xFF\x18\x17\x13\xFF" + "\x18\x17\x13\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF\x18\x17\x14\xFF\x1B\x1A\x16\xFF\x18\x17\x13" + "\xFF\x18\x17\x13\xFF\x1B\x1A\x15\xFF" + "\x17\x16\x12\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF\x1E\x1E\x19\xFF\x1D\x1D\x18" + "\xFF\x1A\x19\x16\xFF\x19\x18\x14\xFF"; + +/** + * Experimental Case 02: 64x64 (32bpp) + */ + +static const BYTE TEST_RLE_BITMAP_EXPERIMENTAL_02[16384] = + "\x1C\x1C\x17\xFF\x1D\x1B\x18\xFF\x1B\x19\x15\xFF\x19\x18\x13\xFF\x19\x18\x14\xFF\x17\x16\x12" + "\xFF\x17\x17\x13\xFF\x19\x17\x14\xFF" + "\x15\x14\x11\xFF\x13\x13\x10\xFF\x4F\x4B\x3E\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x22\x21\x1C" + "\xFF\x22\x21\x1B\xFF\x21\x21\x1A\xFF" + "\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x21\x20\x1A\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x23\x22\x1D" + "\xFF\x22\x20\x1A\xFF\x21\x20\x1A\xFF" + "\x21\x20\x1B\xFF\x24\x23\x1E\xFF\x21\x20\x1B\xFF\x22\x22\x1C\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x29\x28\x23\xFF" + "\x26\x25\x21\xFF\x21\x20\x1B\xFF\x29\x28\x22\xFF\x21\x20\x1A\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x24\x22\x1D\xFF\x26\x25\x20\xFF" + "\x23\x23\x1D\xFF\x2A\x29\x23\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x23\x22\x1D" + "\xFF\x24\x23\x1E\xFF\x21\x20\x1B\xFF" + "\x26\x25\x20\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x25\x24\x20\xFF\x25\x24\x20\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1D\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x28\x26\x21\xFF\x24\x22\x1D\xFF" + "\x23\x22\x1E\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x24\x23\x1E\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x21\x20\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1D" + "\xFF\x2A\x29\x24\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x22\x1D\xFF\x26\x25\x20\xFF\x23\x22\x1D" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x25\x20\xFF\x21\x20\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x25\x20" + "\xFF\x28\x26\x21\xFF\x25\x24\x20\xFF" + "\x24\x23\x1D\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x29\x28\x23" + "\xFF\x29\x28\x22\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x23\x1E\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x22\x20\x1B\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x21\x20\x1B\xFF\x29\x29\x23\xFF\x21\x20\x1A\xFF\x25\x24\x20" + "\xFF\x26\x24\x20\xFF\x21\x21\x1B\xFF" + "\x21\x20\x1B\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x25\x25\x20\xFF" + "\x29\x28\x22\xFF\x23\x23\x1E\xFF\x23\x22\x1C\xFF\x22\x22\x1C\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF" + "\x25\x25\x20\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x29\x28\x22\xFF\x23\x22\x1C\xFF\x23\x22\x1E" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x28\x26\x21" + "\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF" + "\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x22\x1D\xFF\x24\x23\x1D\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x1F\xFF\x25\x24\x20\xFF\x28\x26\x21\xFF\x25\x24\x20\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x28\x26\x21\xFF\x25\x24\x20\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E" + "\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF" + "\x28\x26\x21\xFF\x23\x22\x1C\xFF\x25\x23\x1F\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x29\x28\x23\xFF" + "\x27\x25\x21\xFF\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x26\x25\x20\xFF" + "\x24\x23\x1E\xFF\x2A\x29\x23\xFF\x25\x23\x1E\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x23\x23\x1E" + "\xFF\x24\x24\x1E\xFF\x22\x21\x1B\xFF" + "\x26\x25\x20\xFF\x26\x24\x20\xFF\x23\x22\x1C\xFF\x26\x25\x20\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x26\x25\x21\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x23\x22\x1E\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x28\x26\x21\xFF\x24\x23\x1E\xFF" + "\x23\x23\x1E\xFF\x27\x25\x20\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x25\x24\x1F\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x25\x24\x1F" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1E" + "\xFF\x2A\x29\x24\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1E\xFF\x27\x25\x20\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x27\x25\x20\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x25\x20" + "\xFF\x28\x26\x21\xFF\x25\x24\x20\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x29\x28\x23" + "\xFF\x29\x28\x22\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x23\x1E\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x26\x25\x20" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x2A\x29\x23\xFF\x22\x21\x1B\xFF\x26\x25\x21" + "\xFF\x26\x25\x21\xFF\x22\x23\x1C\xFF" + "\x23\x23\x1C\xFF\x24\x25\x1E\xFF\x27\x2B\x25\xFF\x2B\x2F\x27\xFF\x25\x2C\x23\xFF\x26\x2E\x24" + "\xFF\x26\x2F\x25\xFF\x2A\x35\x2B\xFF" + "\x2E\x39\x2E\xFF\x28\x34\x2A\xFF\x28\x33\x28\xFF\x28\x33\x28\xFF\x2A\x35\x2C\xFF\x27\x32\x27" + "\xFF\x2A\x35\x2C\xFF\x27\x32\x27\xFF" + "\x2A\x36\x2C\xFF\x2B\x36\x2D\xFF\x27\x32\x27\xFF\x28\x33\x28\xFF\x27\x32\x27\xFF\x28\x33\x28" + "\xFF\x28\x33\x28\xFF\x27\x32\x27\xFF" + "\x27\x32\x27\xFF\x27\x32\x27\xFF\x2A\x35\x2C\xFF\x2E\x39\x2E\xFF\x28\x33\x28\xFF\x28\x33\x2A" + "\xFF\x28\x33\x28\xFF\x27\x32\x27\xFF" + "\x27\x32\x27\xFF\x28\x33\x28\xFF\x2D\x37\x2D\xFF\x27\x32\x27\xFF\x2A\x35\x2B\xFF\x54\x51\x43" + "\xFF\x37\x82\x60\xFF\x36\x7A\x5A\xFF" + "\x34\x71\x54\xFF\x32\x68\x4D\xFF\x30\x5D\x46\xFF\x2D\x53\x3F\xFF\x2B\x45\x35\xFF\x26\x35\x29" + "\xFF\x25\x2D\x23\xFF\x26\x2C\x25\xFF" + "\x27\x2A\x23\xFF\x23\x25\x1F\xFF\x23\x23\x1E\xFF\x24\x23\x1D\xFF\x25\x23\x1D\xFF\x25\x23\x1E" + "\xFF\x25\x23\x1D\xFF\x25\x24\x1F\xFF" + "\x28\x2B\x23\xFF\x37\x60\x4A\xFF\x4A\xA2\x78\xFF\x47\x97\x71\xFF\x41\x84\x64\xFF\x3D\x75\x58" + "\xFF\x38\x62\x4B\xFF\x33\x50\x3E\xFF" + "\x2E\x3C\x30\xFF\x2A\x34\x29\xFF\x28\x30\x26\xFF\x27\x2C\x24\xFF\x26\x29\x22\xFF\x27\x28\x21" + "\xFF\x27\x26\x20\xFF\x27\x25\x20\xFF" + "\x25\x25\x20\xFF\x24\x23\x1D\xFF\x26\x23\x1E\xFF\x28\x25\x20\xFF\x26\x24\x1E\xFF\x27\x24\x1F" + "\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF" + "\x26\x25\x1F\xFF\x28\x25\x20\xFF\x28\x26\x21\xFF\x2A\x27\x22\xFF\x26\x25\x1E\xFF\x27\x24\x1F" + "\xFF\x27\x25\x1F\xFF\x28\x25\x1F\xFF" + "\x27\x27\x1F\xFF\x27\x24\x1F\xFF\x25\x24\x1F\xFF\x26\x24\x1F\xFF\x24\x24\x1E\xFF\x25\x24\x1D" + "\xFF\x27\x25\x1F\xFF\x28\x25\x20\xFF" + "\x27\x24\x1F\xFF\x28\x25\x1F\xFF\x27\x26\x1F\xFF\x27\x25\x1E\xFF\x25\x23\x1E\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x25\x20\xFF" + "\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF\x25\x22\x1D" + "\xFF\x26\x23\x1E\xFF\x23\x21\x1C\xFF" + "\x26\x24\x1F\xFF\x28\x25\x20\xFF\x28\x26\x1F\xFF\x28\x25\x1F\xFF\x28\x25\x20\xFF\x26\x24\x1F" + "\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF" + "\x26\x24\x1F\xFF\x25\x25\x1E\xFF\x27\x25\x1F\xFF\x28\x24\x1F\xFF\x29\x27\x1F\xFF\x25\x24\x1E" + "\xFF\x24\x24\x1E\xFF\x25\x24\x1E\xFF" + "\x25\x23\x1E\xFF\x25\x24\x1E\xFF\x25\x24\x1E\xFF\x27\x24\x1F\xFF\x2A\x27\x22\xFF\x2B\x28\x22" + "\xFF\x2B\x28\x21\xFF\x25\x24\x1E\xFF" + "\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x27\x23\x1E\xFF\x28\x25\x20\xFF\x25\x22\x1E\xFF\x25\x23\x1E" + "\xFF\x23\x22\x1C\xFF\x25\x25\x1E\xFF" + "\x26\x26\x20\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x26\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x27\x25\x1E\xFF\x25\x23\x1C\xFF" + "\x25\x23\x1E\xFF\x25\x24\x1E\xFF\x24\x23\x1E\xFF\x24\x21\x1C\xFF\x25\x22\x1D\xFF\x27\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF" + "\x25\x22\x1E\xFF\x25\x22\x1E\xFF\x25\x22\x1D\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x27\x26\x20" + "\xFF\x26\x26\x1F\xFF\x27\x25\x1F\xFF" + "\x27\x26\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF\x23\x22\x1C\xFF\x25\x23\x1D\xFF\x25\x22\x1E" + "\xFF\x26\x24\x1E\xFF\x24\x23\x1E\xFF" + "\x26\x24\x1F\xFF\x27\x26\x20\xFF\x29\x27\x21\xFF\x2A\x26\x21\xFF\x27\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x26\x24\x1F\xFF\x28\x29\x23\xFF" + "\x2F\x46\x36\xFF\x4B\xA5\x7B\xFF\x57\xCD\x97\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x4D\xAC\x7F" + "\xFF\x32\x50\x3D\xFF\x26\x29\x22\xFF" + "\x23\x21\x1C\xFF\x26\x23\x1E\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF\x26\x24\x1F" + "\xFF\x25\x24\x1E\xFF\x25\x24\x1F\xFF" + "\x22\x21\x1C\xFF\x24\x23\x1D\xFF\x24\x24\x1D\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF\x26\x24\x1F" + "\xFF\x25\x27\x21\xFF\x2B\x36\x2B\xFF" + "\x4B\xA7\x7D\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x50\xB9\x89\xFF\x32\x54\x40\xFF\x27\x2A\x23\xFF\x23\x22\x1C\xFF\x25\x24\x1F\xFF\x25\x22\x1D" + "\xFF\x25\x23\x1D\xFF\x25\x22\x1D\xFF" + "\x24\x23\x1D\xFF\x25\x23\x1E\xFF\x24\x22\x1D\xFF\x25\x22\x1D\xFF\x23\x22\x1C\xFF\x24\x23\x1D" + "\xFF\x27\x25\x1F\xFF\x28\x25\x1F\xFF" + "\x25\x23\x1E\xFF\x23\x22\x1D\xFF\x24\x22\x1C\xFF\x24\x23\x1D\xFF\x24\x22\x1D\xFF\x24\x21\x1C" + "\xFF\x25\x24\x1E\xFF\x23\x22\x1C\xFF" + "\x24\x21\x1C\xFF\x25\x23\x1E\xFF\x27\x25\x1F\xFF\x25\x25\x1F\xFF\x24\x22\x1D\xFF\x24\x21\x1C" + "\xFF\x25\x23\x1E\xFF\x22\x21\x1C\xFF" + "\x26\x23\x1F\xFF\x24\x21\x1D\xFF\x24\x22\x1D\xFF\x23\x22\x1C\xFF\x23\x21\x1C\xFF\x24\x21\x1C" + "\xFF\x26\x23\x1E\xFF\x23\x22\x1D\xFF" + "\x22\x21\x1C\xFF\x26\x25\x1F\xFF\x26\x23\x1E\xFF\x25\x23\x1E\xFF\x23\x23\x1D\xFF\x25\x24\x1E" + "\xFF\x26\x25\x1E\xFF\x26\x23\x1E\xFF" + "\x24\x22\x1D\xFF\x24\x22\x1E\xFF\x24\x22\x1D\xFF\x25\x22\x1D\xFF\x23\x22\x1D\xFF\x24\x22\x1D" + "\xFF\x26\x23\x1E\xFF\x26\x24\x1F\xFF" + "\x24\x21\x1D\xFF\x23\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x23\x1E\xFF\x24\x22\x1D\xFF\x21\x1F\x1B" + "\xFF\x22\x20\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x1E\xFF\x24\x24\x1D\xFF\x24\x23\x1D\xFF\x25\x23\x1E\xFF\x23\x22\x1D\xFF\x23\x22\x1D" + "\xFF\x23\x21\x1C\xFF\x22\x21\x1C\xFF" + "\x20\x20\x1B\xFF\x25\x25\x1E\xFF\x24\x22\x1D\xFF\x24\x22\x1D\xFF\x26\x23\x1E\xFF\x23\x22\x1D" + "\xFF\x24\x22\x1D\xFF\x25\x22\x1D\xFF" + "\x24\x22\x1D\xFF\x24\x22\x1D\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x24\x23\x1D\xFF\x25\x24\x1E" + "\xFF\x25\x23\x1E\xFF\x25\x24\x1E\xFF" + "\x25\x23\x1E\xFF\x25\x23\x1E\xFF\x22\x22\x1C\xFF\x22\x20\x1B\xFF\x20\x20\x1A\xFF\x22\x20\x1B" + "\xFF\x21\x20\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1C\xFF\x20\x1F\x1A\xFF\x20\x1F\x1A\xFF\x24\x21\x1C\xFF\x25\x24\x1E" + "\xFF\x25\x23\x1E\xFF\x24\x22\x1D\xFF" + "\x26\x23\x1E\xFF\x24\x22\x1D\xFF\x23\x20\x1B\xFF\x24\x22\x1C\xFF\x25\x23\x1D\xFF\x23\x22\x1D" + "\xFF\x20\x20\x1A\xFF\x20\x1F\x19\xFF" + "\x1F\x1F\x1A\xFF\x23\x23\x1D\xFF\x23\x21\x1C\xFF\x22\x1F\x1B\xFF\x21\x21\x1A\xFF\x22\x22\x1C" + "\xFF\x23\x22\x1D\xFF\x21\x21\x1B\xFF" + "\x21\x21\x1B\xFF\x23\x21\x1C\xFF\x23\x20\x1B\xFF\x20\x20\x1A\xFF\x21\x1F\x1B\xFF\x24\x21\x1C" + "\xFF\x25\x22\x1D\xFF\x22\x22\x1C\xFF" + "\x23\x21\x1C\xFF\x24\x22\x1D\xFF\x23\x21\x1C\xFF\x21\x1E\x19\xFF\x21\x1F\x1B\xFF\x22\x20\x1B" + "\xFF\x23\x21\x1C\xFF\x22\x20\x1B\xFF" + "\x22\x21\x1C\xFF\x20\x20\x1C\xFF\x1F\x1E\x1A\xFF\x22\x21\x1C\xFF\x22\x21\x1C\xFF\x21\x21\x1B" + "\xFF\x21\x21\x1B\xFF\x24\x22\x1F\xFF" + "\x12\x11\x0F\xFF\x11\x10\x0C\xFF\x11\x10\x0D\xFF\x13\x12\x0F\xFF\x12\x11\x0D\xFF\x12\x11\x0E" + "\xFF\x12\x11\x0F\xFF\x16\x15\x11\xFF" + "\x17\x15\x12\xFF\x12\x10\x0E\xFF\x14\x13\x0F\xFF\x14\x13\x10\xFF\x11\x11\x0D\xFF\x10\x10\x0D" + "\xFF\x13\x13\x0F\xFF\x13\x11\x0F\xFF" + "\x13\x12\x0F\xFF\x15\x13\x11\xFF\x13\x12\x0F\xFF\x10\x0E\x0E\xFF\x11\x0F\x0E\xFF\x13\x11\x10" + "\xFF\x13\x11\x10\xFF\x13\x12\x0F\xFF" + "\x15\x13\x12\xFF\x12\x11\x0E\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x14\x12\x0F\xFF\x15\x13\x11" + "\xFF\x17\x16\x12\xFF\x14\x13\x0F\xFF" + "\x14\x13\x11\xFF\x13\x13\x10\xFF\x14\x13\x10\xFF\x16\x16\x12\xFF\x0F\x0F\x0D\xFF\x11\x10\x0D" + "\xFF\x11\x10\x0D\xFF\x12\x10\x0D\xFF" + "\x12\x10\x0E\xFF\x14\x12\x0F\xFF\x15\x13\x11\xFF\x13\x12\x0E\xFF\x14\x13\x0F\xFF\x17\x15\x12" + "\xFF\x15\x14\x12\xFF\x16\x15\x11\xFF" + "\x15\x14\x10\xFF\x18\x17\x13\xFF\x16\x16\x11\xFF\x15\x14\x10\xFF\x15\x14\x10\xFF\x15\x14\x11" + "\xFF\x14\x12\x11\xFF\x13\x12\x10\xFF" + "\x15\x13\x12\xFF\x18\x17\x13\xFF\x16\x15\x11\xFF\x11\x10\x0D\xFF\x14\x13\x10\xFF\x17\x16\x12" + "\xFF\x14\x13\x0F\xFF\x14\x12\x10\xFF" + "\x16\x15\x11\xFF\x19\x17\x13\xFF\x16\x15\x11\xFF\x14\x12\x10\xFF\x14\x12\x10\xFF\x14\x13\x10" + "\xFF\x15\x13\x10\xFF\x13\x11\x10\xFF" + "\x13\x12\x0F\xFF\x13\x11\x0F\xFF\x12\x10\x0F\xFF\x16\x14\x11\xFF\x12\x11\x0F\xFF\x14\x13\x10" + "\xFF\x17\x17\x12\xFF\x18\x18\x12\xFF" + "\x18\x17\x13\xFF\x15\x14\x11\xFF\x16\x15\x11\xFF\x16\x14\x12\xFF\x15\x13\x10\xFF\x15\x13\x11" + "\xFF\x1A\x19\x15\xFF\x19\x18\x14\xFF" + "\x16\x14\x11\xFF\x14\x13\x10\xFF\x14\x13\x0F\xFF\x13\x12\x0E\xFF\x15\x13\x11\xFF\x14\x13\x10" + "\xFF\x15\x14\x10\xFF\x14\x13\x0F\xFF" + "\x15\x14\x10\xFF\x15\x14\x11\xFF\x16\x15\x11\xFF\x16\x14\x12\xFF\x16\x16\x10\xFF\x16\x15\x11" + "\xFF\x15\x14\x11\xFF\x14\x13\x10\xFF" + "\x15\x14\x10\xFF\x16\x14\x11\xFF\x14\x13\x10\xFF\x14\x13\x10\xFF\x17\x16\x12\xFF\x17\x15\x14" + "\xFF\x13\x12\x0F\xFF\x17\x15\x12\xFF" + "\x1A\x18\x14\xFF\x18\x16\x13\xFF\x18\x16\x13\xFF\x18\x16\x12\xFF\x15\x14\x10\xFF\x12\x11\x0E" + "\xFF\x15\x13\x12\xFF\x17\x16\x13\xFF" + "\x15\x14\x12\xFF\x18\x17\x13\xFF\x18\x16\x14\xFF\x12\x11\x10\xFF\x15\x14\x10\xFF\x18\x16\x13" + "\xFF\x17\x15\x12\xFF\x19\x18\x15\xFF" + "\x17\x16\x12\xFF\x17\x16\x12\xFF\x19\x17\x14\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x17\x16\x12" + "\xFF\x16\x15\x11\xFF\x17\x15\x11\xFF" + "\x16\x15\x11\xFF\x15\x14\x10\xFF\x15\x14\x10\xFF\x18\x16\x12\xFF\x16\x15\x11\xFF\x16\x15\x12" + "\xFF\x19\x18\x14\xFF\x18\x17\x13\xFF" + "\x18\x16\x13\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF\x14\x13\x0F\xFF\x17\x16\x13\xFF\x18\x17\x13" + "\xFF\x18\x16\x14\xFF\x18\x17\x14\xFF" + "\x16\x15\x11\xFF\x1C\x1A\x16\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x17\x16\x12\xFF\x1A\x18\x14" + "\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF" + "\x16\x15\x11\xFF\x15\x14\x10\xFF\x17\x16\x12\xFF\x1A\x19\x15\xFF\x19\x18\x14\xFF\x16\x15\x11" + "\xFF\x16\x14\x11\xFF\x16\x15\x11\xFF" + "\x1A\x19\x15\xFF\x15\x14\x11\xFF\x19\x17\x13\xFF\x1E\x1E\x19\xFF\x19\x18\x14\xFF\x1B\x19\x15" + "\xFF\x1C\x1A\x16\xFF\x17\x16\x13\xFF" + "\x16\x14\x12\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF\x19\x18\x14\xFF\x1A\x19\x15\xFF\x1A\x19\x15" + "\xFF\x1A\x19\x15\xFF\x14\x13\x0F\xFF" + "\x16\x15\x11\xFF\x1A\x18\x14\xFF\x18\x16\x12\xFF\x13\x12\x0E\xFF\x16\x16\x12\xFF\x19\x18\x14" + "\xFF\x19\x18\x14\xFF\x1A\x19\x15\xFF" + "\x1C\x1A\x16\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF\x18\x15\x11\xFF\x19\x18\x14\xFF\x1A\x19\x15" + "\xFF\x1B\x1A\x15\xFF\x22\x22\x1D\xFF" + "\x1F\x1D\x18\xFF\x1B\x18\x14\xFF\x1C\x1B\x16\xFF\x19\x18\x14\xFF\x1B\x1A\x16\xFF\x1B\x1A\x16" + "\xFF\x1B\x1A\x15\xFF\x1A\x19\x15\xFF" + "\x1A\x18\x14\xFF\x1C\x1B\x16\xFF\x1C\x1A\x16\xFF\x1C\x19\x15\xFF\x1B\x19\x15\xFF\x19\x18\x14" + "\xFF\x1E\x1C\x18\xFF\x1D\x1A\x16\xFF" + "\x17\x16\x11\xFF\x19\x18\x14\xFF\x18\x17\x13\xFF\x1C\x1B\x17\xFF\x1D\x1C\x17\xFF\x1A\x18\x14" + "\xFF\x19\x17\x14\xFF\x19\x19\x15\xFF" + "\x1B\x1A\x16\xFF\x1C\x1B\x17\xFF\x1E\x1D\x18\xFF\x1C\x1A\x16\xFF\x1A\x18\x14\xFF\x1B\x1A\x16" + "\xFF\x1D\x1C\x17\xFF\x1F\x1E\x19\xFF" + "\x1B\x1A\x16\xFF\x1B\x1A\x16\xFF\x1D\x1C\x17\xFF\x1D\x1B\x17\xFF\x1B\x1A\x16\xFF\x1B\x1A\x16" + "\xFF\x1A\x19\x15\xFF\x1D\x1C\x18\xFF" + "\x1B\x19\x15\xFF\x1C\x1B\x17\xFF\x1C\x1B\x18\xFF\x1A\x1A\x16\xFF\x1E\x1C\x18\xFF\x1E\x1C\x18" + "\xFF\x1F\x1C\x18\xFF\x1F\x1E\x19\xFF" + "\x1C\x1B\x17\xFF\x1B\x1B\x17\xFF\x1A\x19\x15\xFF\x1E\x1C\x18\xFF\x1F\x1F\x19\xFF\x1C\x1C\x17" + "\xFF\x1C\x1A\x18\xFF\x1F\x1C\x19\xFF" + "\x1F\x1D\x18\xFF\x1D\x1C\x18\xFF\x1D\x1B\x17\xFF\x1E\x1D\x19\xFF\x20\x1D\x19\xFF\x1E\x1C\x18" + "\xFF\x1F\x1E\x19\xFF\x1D\x1C\x18\xFF" + "\x1D\x1C\x18\xFF\x22\x21\x1C\xFF\x20\x1F\x1A\xFF\x1F\x1D\x18\xFF\x1C\x1B\x17\xFF\x20\x1F\x19" + "\xFF\x1B\x1B\x16\xFF\x1A\x19\x15\xFF" + "\x1C\x1A\x16\xFF\x1E\x1B\x17\xFF\x1F\x1D\x18\xFF\x1F\x1E\x19\xFF\x21\x1E\x1A\xFF\x1D\x1B\x17" + "\xFF\x1D\x1D\x18\xFF\x1E\x1E\x18\xFF" + "\x1E\x1E\x18\xFF\x1F\x1D\x19\xFF\x1E\x1C\x17\xFF\x1E\x1D\x18\xFF\x1E\x1C\x18\xFF\x1F\x1E\x19" + "\xFF\x1D\x1C\x18\xFF\x1F\x1D\x1A\xFF" + "\x1F\x1E\x18\xFF\x1E\x1D\x18\xFF\x1F\x1E\x19\xFF\x22\x22\x1C\xFF\x1D\x1D\x18\xFF\x1D\x1C\x18" + "\xFF\x20\x1F\x1C\xFF\x1E\x1E\x17\xFF" + "\x1D\x1C\x18\xFF\x1D\x1D\x18\xFF\x20\x21\x1B\xFF\x21\x20\x1B\xFF\x1D\x1C\x18\xFF\x1B\x19\x15" + "\xFF\x1D\x1B\x17\xFF\x20\x1D\x1B\xFF" + "\x1F\x1E\x19\xFF\x1E\x1D\x18\xFF\x20\x1F\x1A\xFF\x1F\x1F\x19\xFF\x22\x20\x1B\xFF\x1F\x1E\x19" + "\xFF\x1E\x1D\x19\xFF\x22\x1F\x1B\xFF" + "\x1E\x1E\x17\xFF\x1C\x1C\x16\xFF\x1B\x1C\x15\xFF\x1D\x1B\x18\xFF\x1E\x1C\x19\xFF\x20\x1E\x19" + "\xFF\x21\x1E\x1A\xFF\x1F\x1D\x18\xFF" + "\x1A\x1A\x15\xFF\x19\x17\x14\xFF\x1B\x1A\x16\xFF\x1B\x19\x15\xFF\x1B\x19\x15\xFF\x18\x18\x14" + "\xFF\x18\x17\x14\xFF\x18\x18\x14\xFF" + "\x19\x17\x14\xFF\x15\x16\x12\xFF\x52\x4E\x42\xFF\x22\x21\x1B\xFF\x22\x20\x1A\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x21\x20\x1B\xFF\x25\x24\x20\xFF\x26\x25\x21" + "\xFF\x23\x22\x1D\xFF\x24\x23\x1E\xFF" + "\x21\x20\x1A\xFF\x26\x25\x20\xFF\x23\x22\x1D\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x20\x1B" + "\xFF\x21\x20\x1A\xFF\x21\x21\x1B\xFF" + "\x26\x25\x20\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x25\x25\x20\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x21\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x28\x26\x22\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x21\x20\x1B" + "\xFF\x26\x25\x21\xFF\x21\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1D\xFF\x23\x22\x1D\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x24\x22\x1D" + "\xFF\x24\x23\x1F\xFF\x25\x24\x20\xFF" + "\x22\x20\x1B\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x20\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x25\x20\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x28\x26\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x24\x23\x1E" + "\xFF\x29\x28\x23\xFF\x25\x24\x20\xFF" + "\x24\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x21\x1C\xFF\x23\x21\x1C\xFF" + "\x24\x23\x1E\xFF\x22\x20\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x22\x1C\xFF\x26\x25\x20\xFF\x22\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x21\x21\x1B\xFF\x26\x25\x20\xFF" + "\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x22\x1C\xFF\x26\x25\x21\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x21\x1C\xFF\x23\x22\x1C\xFF\x26\x25\x21\xFF\x25\x24\x20" + "\xFF\x25\x24\x1F\xFF\x24\x22\x1D\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x25\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x23\x21\x1C\xFF\x23\x23\x1E\xFF\x23\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF" + "\x23\x21\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x28\x26\x21" + "\xFF\x25\x23\x1F\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1D\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x26\x25\x20" + "\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x25\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x1F" + "\xFF\x25\x24\x1F\xFF\x26\x24\x20\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x21\x1C\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x26\x25\x21" + "\xFF\x24\x23\x1E\xFF\x25\x24\x1F\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x26\x25\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x25\x25\x20\xFF" + "\x23\x22\x1C\xFF\x27\x25\x20\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x28\x26\x22\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x24\x23\x1E" + "\xFF\x25\x24\x1F\xFF\x26\x24\x20\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x27\x25\x20\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x27\x26\x21\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x26\x26\x20\xFF" + "\x28\x26\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E" + "\xFF\x29\x28\x23\xFF\x25\x25\x20\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x22\x1C\xFF\x27\x26\x20\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x22\x21\x1B\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x26\x24\x20\xFF\x23\x22\x1C" + "\xFF\x22\x22\x1C\xFF\x26\x25\x21\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x27\x26\x22\xFF\x26\x26\x22" + "\xFF\x26\x27\x21\xFF\x26\x2A\x23\xFF" + "\x26\x2E\x26\xFF\x26\x2F\x25\xFF\x27\x31\x27\xFF\x27\x31\x27\xFF\x28\x33\x28\xFF\x27\x32\x27" + "\xFF\x27\x32\x27\xFF\x29\x34\x2A\xFF" + "\x27\x32\x27\xFF\x2A\x35\x2B\xFF\x2A\x36\x2C\xFF\x28\x33\x28\xFF\x27\x32\x27\xFF\x2A\x35\x2C" + "\xFF\x27\x32\x27\xFF\x2D\x37\x2D\xFF" + "\x28\x33\x28\xFF\x28\x34\x2A\xFF\x28\x34\x2A\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF\x27\x32\x27" + "\xFF\x2B\x36\x2C\xFF\x27\x32\x27\xFF" + "\x28\x33\x28\xFF\x27\x32\x27\xFF\x28\x33\x28\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF\x2D\x37\x2D" + "\xFF\x2A\x35\x2C\xFF\x27\x32\x27\xFF" + "\x27\x32\x27\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF\x28\x33\x28\xFF\x29\x34\x2A\xFF\x4F\x4D\x3F" + "\xFF\x3A\x8B\x67\xFF\x3B\x8C\x68\xFF" + "\x3E\x93\x6D\xFF\x40\x98\x71\xFF\x42\x9A\x72\xFF\x42\x9A\x72\xFF\x42\x97\x70\xFF\x41\x93\x6D" + "\xFF\x3E\x87\x64\xFF\x3B\x75\x56\xFF" + "\x32\x51\x3F\xFF\x29\x37\x2C\xFF\x29\x31\x28\xFF\x27\x2C\x24\xFF\x26\x29\x21\xFF\x28\x28\x22" + "\xFF\x27\x27\x20\xFF\x27\x27\x21\xFF" + "\x29\x2F\x25\xFF\x3C\x73\x56\xFF\x55\xC9\x94\xFF\x56\xCC\x96\xFF\x56\xCB\x97\xFF\x54\xC5\x92" + "\xFF\x52\xBD\x8C\xFF\x50\xB5\x86\xFF" + "\x4D\xAA\x7F\xFF\x48\x99\x71\xFF\x40\x80\x61\xFF\x37\x66\x4D\xFF\x2F\x48\x38\xFF\x2C\x38\x2C" + "\xFF\x2B\x33\x29\xFF\x2A\x2E\x26\xFF" + "\x27\x29\x23\xFF\x27\x27\x21\xFF\x27\x27\x21\xFF\x27\x26\x20\xFF\x26\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x27\x26\x20\xFF\x28\x26\x20\xFF\x28\x25\x20\xFF\x28\x27\x20\xFF\x27\x25\x1F\xFF\x27\x25\x20" + "\xFF\x27\x25\x1F\xFF\x28\x26\x20\xFF" + "\x25\x23\x1E\xFF\x26\x24\x1E\xFF\x25\x23\x1D\xFF\x27\x25\x1F\xFF\x26\x24\x1E\xFF\x26\x23\x1E" + "\xFF\x29\x26\x21\xFF\x28\x25\x20\xFF" + "\x26\x25\x1F\xFF\x27\x25\x1F\xFF\x25\x25\x1F\xFF\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x26\x25\x1F" + "\xFF\x25\x23\x1D\xFF\x27\x24\x1F\xFF" + "\x25\x24\x1F\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF\x27\x24\x1E\xFF\x26\x26\x1E\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x29\x26\x20\xFF\x28\x25\x20\xFF\x27\x26\x1E\xFF\x26\x24\x1E\xFF\x28\x26\x21\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x28\x25\x20\xFF\x27\x24\x1F\xFF\x27\x26\x20\xFF\x27\x25\x1F\xFF\x28\x26\x20\xFF\x26\x23\x1E" + "\xFF\x25\x24\x1D\xFF\x26\x24\x1E\xFF" + "\x26\x24\x1F\xFF\x22\x21\x1B\xFF\x23\x23\x1D\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x26\x23\x1E" + "\xFF\x27\x24\x1E\xFF\x27\x24\x1F\xFF" + "\x27\x25\x1E\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x26\x23\x1F\xFF\x27\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x24\x23\x1D\xFF\x21\x21\x1C\xFF" + "\x26\x23\x1F\xFF\x26\x23\x1F\xFF\x26\x23\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x24\x1E" + "\xFF\x26\x24\x1E\xFF\x24\x24\x1D\xFF" + "\x25\x24\x1E\xFF\x26\x24\x1F\xFF\x27\x26\x1F\xFF\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x26\x24\x1E" + "\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF" + "\x26\x24\x1F\xFF\x24\x21\x1C\xFF\x23\x22\x1C\xFF\x23\x23\x1D\xFF\x27\x25\x20\xFF\x26\x25\x1F" + "\xFF\x27\x26\x20\xFF\x27\x27\x1F\xFF" + "\x29\x26\x21\xFF\x26\x25\x1F\xFF\x23\x23\x1D\xFF\x24\x22\x1D\xFF\x22\x21\x1B\xFF\x23\x21\x1D" + "\xFF\x28\x25\x20\xFF\x27\x24\x1F\xFF" + "\x25\x24\x1F\xFF\x27\x25\x21\xFF\x25\x24\x1F\xFF\x28\x25\x20\xFF\x27\x26\x1F\xFF\x26\x23\x1E" + "\xFF\x25\x22\x1D\xFF\x26\x26\x20\xFF" + "\x2A\x37\x2D\xFF\x42\x87\x66\xFF\x56\xCD\x98\xFF\x56\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x52\xBF\x8E" + "\xFF\x37\x66\x4D\xFF\x28\x2C\x25\xFF" + "\x26\x26\x21\xFF\x27\x24\x1F\xFF\x24\x23\x1E\xFF\x24\x22\x1D\xFF\x27\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x25\x22\x1D\xFF" + "\x22\x22\x1C\xFF\x23\x21\x1C\xFF\x26\x23\x1E\xFF\x24\x23\x1D\xFF\x25\x22\x1C\xFF\x23\x21\x1C" + "\xFF\x28\x27\x20\xFF\x2B\x31\x27\xFF" + "\x3E\x79\x5B\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCC\x97\xFF\x57\xCD\x97" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x54\xC4\x91\xFF\x3E\x79\x5B\xFF\x29\x30\x28\xFF\x25\x25\x1F\xFF\x25\x24\x1E\xFF\x27\x24\x1E" + "\xFF\x24\x23\x1D\xFF\x25\x23\x1F\xFF" + "\x25\x22\x1D\xFF\x26\x24\x1E\xFF\x24\x22\x1D\xFF\x22\x22\x1C\xFF\x22\x1F\x1A\xFF\x23\x21\x1C" + "\xFF\x23\x21\x1C\xFF\x27\x24\x1F\xFF" + "\x27\x26\x21\xFF\x27\x24\x1F\xFF\x24\x21\x1C\xFF\x22\x21\x1C\xFF\x24\x23\x1D\xFF\x23\x20\x1B" + "\xFF\x24\x23\x1D\xFF\x24\x23\x1E\xFF" + "\x25\x24\x1E\xFF\x26\x25\x1F\xFF\x26\x25\x1F\xFF\x28\x26\x21\xFF\x27\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF" + "\x26\x23\x1E\xFF\x24\x21\x1C\xFF\x24\x23\x1D\xFF\x22\x22\x1C\xFF\x22\x20\x1A\xFF\x22\x21\x1B" + "\xFF\x24\x24\x1D\xFF\x25\x23\x1E\xFF" + "\x24\x23\x1E\xFF\x25\x23\x1E\xFF\x23\x22\x1D\xFF\x21\x20\x1B\xFF\x25\x23\x1E\xFF\x24\x23\x1D" + "\xFF\x23\x22\x1C\xFF\x25\x22\x1D\xFF" + "\x23\x21\x1C\xFF\x22\x22\x1D\xFF\x23\x22\x1D\xFF\x27\x25\x20\xFF\x23\x22\x1D\xFF\x26\x22\x1F" + "\xFF\x23\x20\x1D\xFF\x24\x21\x1D\xFF" + "\x25\x22\x1D\xFF\x24\x23\x1E\xFF\x20\x1F\x1A\xFF\x20\x1E\x19\xFF\x23\x22\x1D\xFF\x23\x22\x1B" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x24\x22\x1D\xFF\x24\x23\x1D\xFF\x24\x23\x1D\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x25\x22\x1E" + "\xFF\x21\x20\x1B\xFF\x21\x21\x1B\xFF" + "\x20\x20\x1A\xFF\x24\x23\x1D\xFF\x25\x24\x1E\xFF\x26\x24\x1F\xFF\x22\x1F\x1A\xFF\x24\x21\x1C" + "\xFF\x23\x20\x1C\xFF\x20\x1F\x1A\xFF" + "\x24\x22\x1D\xFF\x23\x21\x1C\xFF\x24\x22\x1C\xFF\x24\x21\x1C\xFF\x22\x22\x1C\xFF\x22\x22\x1C" + "\xFF\x24\x21\x1C\xFF\x23\x21\x1C\xFF" + "\x23\x22\x1C\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x24\x21\x1C" + "\xFF\x22\x20\x1B\xFF\x21\x21\x1B\xFF" + "\x23\x21\x1C\xFF\x23\x21\x1C\xFF\x20\x1E\x19\xFF\x21\x1E\x1A\xFF\x23\x22\x1D\xFF\x26\x24\x1E" + "\xFF\x23\x23\x1C\xFF\x23\x21\x1C\xFF" + "\x22\x20\x1C\xFF\x22\x21\x1C\xFF\x23\x20\x1C\xFF\x24\x22\x1D\xFF\x24\x22\x1C\xFF\x22\x20\x1C" + "\xFF\x22\x20\x1B\xFF\x22\x22\x1C\xFF" + "\x22\x20\x1B\xFF\x22\x20\x1B\xFF\x25\x23\x1D\xFF\x26\x23\x1E\xFF\x21\x21\x1C\xFF\x20\x1F\x1A" + "\xFF\x20\x1F\x1B\xFF\x1F\x1E\x1A\xFF" + "\x22\x1F\x1A\xFF\x27\x25\x1F\xFF\x23\x22\x1D\xFF\x22\x23\x1B\xFF\x25\x22\x1D\xFF\x27\x24\x1F" + "\xFF\x24\x22\x1D\xFF\x23\x23\x1D\xFF" + "\x25\x23\x1D\xFF\x23\x22\x1C\xFF\x24\x22\x1D\xFF\x26\x23\x1C\xFF\x24\x21\x1D\xFF\x22\x20\x1B" + "\xFF\x20\x1E\x1B\xFF\x1D\x1C\x18\xFF" + "\x20\x20\x1A\xFF\x20\x1F\x1A\xFF\x1F\x1D\x19\xFF\x20\x1F\x1A\xFF\x23\x22\x1D\xFF\x23\x22\x1D" + "\xFF\x23\x22\x1D\xFF\x23\x22\x1C\xFF" + "\x13\x12\x0F\xFF\x13\x12\x0E\xFF\x13\x12\x0F\xFF\x12\x10\x0E\xFF\x12\x11\x0F\xFF\x13\x12\x0E" + "\xFF\x14\x13\x0F\xFF\x13\x12\x0E\xFF" + "\x14\x12\x0F\xFF\x12\x11\x0E\xFF\x12\x10\x0E\xFF\x12\x11\x0E\xFF\x13\x11\x0E\xFF\x17\x13\x10" + "\xFF\x13\x12\x0E\xFF\x0E\x0D\x0A\xFF" + "\x0E\x0E\x0C\xFF\x0F\x0F\x0D\xFF\x11\x10\x0D\xFF\x13\x11\x0F\xFF\x0F\x10\x0E\xFF\x11\x10\x0F" + "\xFF\x13\x11\x10\xFF\x13\x12\x10\xFF" + "\x11\x10\x0D\xFF\x12\x11\x0E\xFF\x14\x12\x10\xFF\x14\x12\x10\xFF\x10\x0F\x0D\xFF\x13\x11\x0F" + "\xFF\x14\x13\x10\xFF\x13\x12\x10\xFF" + "\x15\x13\x0F\xFF\x14\x12\x0F\xFF\x12\x10\x0E\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x14\x12\x10" + "\xFF\x13\x11\x0E\xFF\x12\x11\x0F\xFF" + "\x11\x10\x0C\xFF\x14\x13\x0F\xFF\x14\x13\x0F\xFF\x14\x12\x10\xFF\x15\x14\x10\xFF\x15\x14\x10" + "\xFF\x15\x13\x10\xFF\x14\x13\x0F\xFF" + "\x12\x11\x0E\xFF\x13\x12\x0E\xFF\x15\x13\x10\xFF\x12\x11\x0D\xFF\x17\x16\x12\xFF\x17\x16\x13" + "\xFF\x12\x10\x0F\xFF\x14\x13\x0F\xFF" + "\x13\x13\x0F\xFF\x14\x14\x11\xFF\x14\x14\x11\xFF\x13\x12\x0E\xFF\x15\x13\x12\xFF\x14\x13\x10" + "\xFF\x13\x12\x0F\xFF\x15\x13\x11\xFF" + "\x18\x17\x13\xFF\x14\x13\x10\xFF\x17\x16\x13\xFF\x17\x16\x12\xFF\x16\x15\x12\xFF\x14\x12\x10" + "\xFF\x15\x15\x11\xFF\x12\x11\x0D\xFF" + "\x13\x10\x0F\xFF\x13\x12\x0F\xFF\x12\x11\x0D\xFF\x12\x13\x10\xFF\x11\x0F\x0D\xFF\x13\x12\x0E" + "\xFF\x14\x13\x0F\xFF\x12\x11\x0E\xFF" + "\x12\x11\x0D\xFF\x13\x12\x0F\xFF\x14\x12\x0F\xFF\x11\x10\x0D\xFF\x14\x13\x10\xFF\x13\x11\x10" + "\xFF\x11\x10\x0D\xFF\x15\x14\x10\xFF" + "\x18\x16\x14\xFF\x17\x17\x12\xFF\x14\x13\x0F\xFF\x15\x14\x11\xFF\x19\x18\x14\xFF\x16\x15\x11" + "\xFF\x17\x16\x11\xFF\x15\x14\x10\xFF" + "\x19\x17\x15\xFF\x1B\x1B\x16\xFF\x19\x18\x13\xFF\x16\x15\x13\xFF\x14\x13\x0F\xFF\x15\x14\x10" + "\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF" + "\x16\x14\x12\xFF\x15\x14\x10\xFF\x15\x13\x11\xFF\x14\x13\x0F\xFF\x18\x17\x13\xFF\x17\x16\x12" + "\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF" + "\x17\x16\x12\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x15\x14\x10" + "\xFF\x14\x13\x0F\xFF\x16\x15\x11\xFF" + "\x19\x17\x14\xFF\x16\x15\x12\xFF\x15\x14\x10\xFF\x15\x14\x10\xFF\x17\x16\x12\xFF\x17\x15\x13" + "\xFF\x18\x17\x12\xFF\x1B\x1A\x16\xFF" + "\x18\x15\x11\xFF\x14\x13\x0F\xFF\x17\x15\x11\xFF\x15\x13\x10\xFF\x15\x14\x10\xFF\x17\x15\x11" + "\xFF\x14\x13\x0F\xFF\x17\x16\x12\xFF" + "\x18\x17\x13\xFF\x16\x14\x12\xFF\x15\x14\x11\xFF\x16\x15\x11\xFF\x17\x16\x12\xFF\x16\x15\x12" + "\xFF\x18\x17\x14\xFF\x16\x15\x11\xFF" + "\x17\x16\x12\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF\x15\x13\x11\xFF\x1B\x1A\x16\xFF\x1A\x19\x15" + "\xFF\x1B\x1A\x16\xFF\x19\x18\x14\xFF" + "\x19\x18\x14\xFF\x1A\x19\x15\xFF\x17\x16\x12\xFF\x13\x12\x0E\xFF\x1C\x1A\x16\xFF\x1B\x19\x15" + "\xFF\x1A\x19\x15\xFF\x16\x14\x10\xFF" + "\x14\x13\x10\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF\x19\x18\x14" + "\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF" + "\x16\x15\x11\xFF\x16\x15\x11\xFF\x1B\x19\x15\xFF\x1B\x19\x15\xFF\x17\x16\x12\xFF\x17\x16\x12" + "\xFF\x17\x16\x12\xFF\x18\x17\x13\xFF" + "\x1A\x19\x15\xFF\x19\x18\x14\xFF\x1B\x18\x16\xFF\x1C\x19\x16\xFF\x18\x17\x13\xFF\x18\x17\x13" + "\xFF\x19\x18\x13\xFF\x19\x17\x13\xFF" + "\x1B\x18\x14\xFF\x19\x16\x14\xFF\x16\x15\x11\xFF\x17\x16\x13\xFF\x19\x17\x13\xFF\x19\x18\x13" + "\xFF\x18\x17\x13\xFF\x17\x15\x11\xFF" + "\x16\x15\x12\xFF\x16\x16\x12\xFF\x18\x18\x13\xFF\x1B\x1A\x16\xFF\x1D\x1C\x17\xFF\x1A\x17\x13" + "\xFF\x1B\x19\x15\xFF\x1A\x18\x14\xFF" + "\x1A\x19\x15\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF\x1A\x19\x15\xFF\x19\x18\x14\xFF\x18\x17\x13" + "\xFF\x19\x18\x14\xFF\x19\x17\x13\xFF" + "\x19\x18\x14\xFF\x1D\x1B\x17\xFF\x1C\x1B\x17\xFF\x1C\x1A\x16\xFF\x17\x16\x14\xFF\x1B\x1A\x16" + "\xFF\x1A\x19\x15\xFF\x1D\x1B\x17\xFF" + "\x1C\x1B\x17\xFF\x1C\x1A\x16\xFF\x1C\x1A\x16\xFF\x1C\x1A\x16\xFF\x1A\x19\x15\xFF\x19\x18\x14" + "\xFF\x17\x16\x12\xFF\x1A\x19\x15\xFF" + "\x1D\x1C\x17\xFF\x1B\x1A\x16\xFF\x1D\x1C\x18\xFF\x19\x18\x14\xFF\x19\x18\x14\xFF\x1A\x18\x14" + "\xFF\x1C\x1B\x17\xFF\x1A\x19\x15\xFF" + "\x1A\x1A\x16\xFF\x1C\x1B\x16\xFF\x1D\x1C\x18\xFF\x1B\x1A\x17\xFF\x1F\x1F\x19\xFF\x1C\x1C\x17" + "\xFF\x1D\x1B\x17\xFF\x1A\x19\x15\xFF" + "\x18\x19\x14\xFF\x1B\x19\x16\xFF\x1A\x19\x15\xFF\x1A\x1A\x16\xFF\x1C\x1B\x17\xFF\x1C\x1C\x17" + "\xFF\x1D\x1C\x16\xFF\x1E\x1D\x18\xFF" + "\x20\x1E\x19\xFF\x1E\x1B\x17\xFF\x1B\x19\x14\xFF\x1D\x1B\x17\xFF\x1F\x1E\x1A\xFF\x1B\x1A\x16" + "\xFF\x1D\x1C\x17\xFF\x1D\x1D\x17\xFF" + "\x1B\x1A\x16\xFF\x1C\x1B\x16\xFF\x1B\x1A\x15\xFF\x1F\x1F\x1A\xFF\x20\x1D\x19\xFF\x1E\x1C\x18" + "\xFF\x1E\x1C\x17\xFF\x1B\x1A\x16\xFF" + "\x1C\x1B\x17\xFF\x1C\x1C\x17\xFF\x1E\x1F\x19\xFF\x1F\x1D\x18\xFF\x1D\x1B\x19\xFF\x1D\x1C\x17" + "\xFF\x1D\x1C\x17\xFF\x1D\x1B\x17\xFF" + "\x1B\x1A\x17\xFF\x1D\x1D\x18\xFF\x1D\x1C\x17\xFF\x1E\x1D\x18\xFF\x1C\x1C\x17\xFF\x1E\x1C\x18" + "\xFF\x20\x1E\x1A\xFF\x1F\x1E\x19\xFF" + "\x1F\x1E\x19\xFF\x1D\x1C\x18\xFF\x1E\x1C\x18\xFF\x1F\x1D\x19\xFF\x1A\x19\x15\xFF\x1C\x1B\x16" + "\xFF\x1E\x1D\x19\xFF\x22\x21\x1B\xFF" + "\x20\x1F\x19\xFF\x1E\x1E\x18\xFF\x1E\x1E\x18\xFF\x1E\x1E\x18\xFF\x20\x20\x1A\xFF\x1C\x1A\x16" + "\xFF\x1D\x1B\x17\xFF\x1F\x1E\x19\xFF" + "\x20\x1F\x1A\xFF\x1F\x1C\x18\xFF\x20\x1E\x19\xFF\x21\x21\x1B\xFF\x1F\x1E\x19\xFF\x1D\x1D\x18" + "\xFF\x1C\x1B\x16\xFF\x1E\x1D\x18\xFF" + "\x1D\x1C\x18\xFF\x20\x20\x1A\xFF\x1E\x1D\x18\xFF\x1E\x1E\x19\xFF\x22\x20\x1C\xFF\x22\x1F\x1A" + "\xFF\x1E\x1C\x17\xFF\x20\x1D\x18\xFF" + "\x20\x1E\x1A\xFF\x1F\x1D\x19\xFF\x1F\x1E\x19\xFF\x20\x1F\x1B\xFF\x1F\x1E\x18\xFF\x1F\x1C\x17" + "\xFF\x1A\x19\x15\xFF\x1C\x1B\x16\xFF" + "\x1D\x1B\x18\xFF\x1C\x1B\x18\xFF\x1C\x1A\x16\xFF\x1A\x18\x15\xFF\x1C\x19\x15\xFF\x1B\x1B\x17" + "\xFF\x1A\x19\x15\xFF\x16\x16\x13\xFF" + "\x18\x15\x12\xFF\x14\x13\x10\xFF\x4F\x4B\x3F\xFF\x23\x22\x1D\xFF\x26\x25\x21\xFF\x21\x21\x1B" + "\xFF\x26\x25\x20\xFF\x22\x20\x1A\xFF" + "\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x28\x26\x21\xFF\x21\x20\x1A\xFF\x23\x22\x1D\xFF\x26\x25\x20" + "\xFF\x24\x23\x1E\xFF\x25\x24\x20\xFF" + "\x29\x28\x22\xFF\x25\x24\x20\xFF\x22\x20\x1B\xFF\x23\x22\x1C\xFF\x21\x20\x1B\xFF\x21\x20\x1B" + "\xFF\x21\x20\x1B\xFF\x21\x20\x1B\xFF" + "\x22\x21\x1B\xFF\x29\x28\x22\xFF\x21\x20\x1B\xFF\x21\x21\x1B\xFF\x21\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x25\x24\x20\xFF\x2A\x29\x23\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x28\x26\x22\xFF\x21\x20\x1A\xFF\x21\x20\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x20\xFF\x26\x25\x20\xFF\x25\x25\x20\xFF\x21\x21\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B" + "\xFF\x25\x24\x20\xFF\x28\x26\x21\xFF" + "\x28\x26\x21\xFF\x25\x25\x20\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x26\x25\x20\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x26\x25\x21\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1C\xFF\x22\x21\x1B\xFF" + "\x28\x26\x21\xFF\x21\x21\x1B\xFF\x25\x24\x20\xFF\x24\x23\x1E\xFF\x27\x25\x21\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x26\x25\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x24\x22\x1D\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1C\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x29\x28\x23\xFF\x22\x21\x1B" + "\xFF\x25\x24\x20\xFF\x25\x24\x20\xFF" + "\x23\x22\x1C\xFF\x25\x24\x20\xFF\x24\x23\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x20\x1B" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x26\x25\x21\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x20\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x24\x23\x1E\xFF\x28\x26\x21\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF\x24\x24\x1E" + "\xFF\x26\x25\x20\xFF\x24\x23\x1E\xFF" + "\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x25\x23\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x26\x25\x20\xFF\x25\x24\x1F\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1D" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x1E\xFF\x29\x28\x22\xFF\x24\x23\x1E\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x24\x20" + "\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF" + "\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x28\x26\x21\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x28\x26\x21\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1F\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x26\x25\x21\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF\x24\x22\x1E\xFF\x26\x25\x20" + "\xFF\x25\x24\x1F\xFF\x26\x25\x21\xFF" + "\x29\x28\x22\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x25\x24\x20\xFF\x2A\x29\x23\xFF" + "\x24\x22\x1D\xFF\x23\x22\x1C\xFF\x28\x26\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x25\x24\x20\xFF\x26\x25\x20\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x29\x27\x22\xFF" + "\x29\x26\x21\xFF\x26\x26\x21\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x25\x24\x1E" + "\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF" + "\x27\x25\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x24\x20\xFF\x26\x25\x21\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x22\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x28\x26\x21\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x24\x23\x1E\xFF\x26\x25\x21\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x28\x26\x21\xFF" + "\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x21" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x26\x25\x20\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x26\x25\x21\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF\x23\x22\x1C\xFF\x23\x22\x1C" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x29\x28\x23\xFF\x22\x21\x1B" + "\xFF\x26\x25\x20\xFF\x26\x25\x20\xFF" + "\x23\x22\x1C\xFF\x26\x25\x21\xFF\x25\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x27\x26\x22\xFF\x22\x22\x1C\xFF\x29\x29\x23\xFF\x23\x26\x1F\xFF\x29\x2F\x27\xFF\x26\x2F\x25" + "\xFF\x27\x31\x27\xFF\x27\x32\x27\xFF" + "\x2A\x35\x2C\xFF\x27\x32\x27\xFF\x2A\x35\x2C\xFF\x29\x34\x2A\xFF\x2D\x37\x2D\xFF\x27\x32\x27" + "\xFF\x27\x32\x27\xFF\x28\x33\x28\xFF" + "\x27\x32\x27\xFF\x27\x32\x27\xFF\x2A\x35\x2C\xFF\x27\x32\x27\xFF\x2A\x35\x2C\xFF\x29\x35\x2B" + "\xFF\x2A\x35\x2C\xFF\x29\x34\x2B\xFF" + "\x29\x34\x2A\xFF\x29\x34\x2A\xFF\x29\x35\x2B\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF\x28\x33\x28" + "\xFF\x27\x32\x27\xFF\x29\x35\x2B\xFF" + "\x2B\x36\x2C\xFF\x2A\x35\x2B\xFF\x2A\x35\x2C\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF\x29\x34\x2A" + "\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF" + "\x2A\x35\x2B\xFF\x2E\x39\x2E\xFF\x2A\x35\x2B\xFF\x29\x34\x2A\xFF\x28\x33\x28\xFF\x4F\x4D\x3F" + "\xFF\x3B\x8B\x67\xFF\x3B\x8C\x68\xFF" + "\x3E\x93\x6D\xFF\x41\x99\x71\xFF\x43\x9F\x76\xFF\x45\xA4\x7A\xFF\x48\xAA\x7E\xFF\x49\xAE\x81" + "\xFF\x4B\xB2\x84\xFF\x4C\xB6\x87\xFF" + "\x4E\xBA\x89\xFF\x4D\xB3\x83\xFF\x45\x97\x70\xFF\x3D\x79\x5B\xFF\x35\x58\x44\xFF\x30\x48\x39" + "\xFF\x2D\x3A\x2F\xFF\x29\x31\x27\xFF" + "\x2B\x37\x2C\xFF\x3E\x79\x5B\xFF\x56\xCA\x95\xFF\x56\xCC\x96\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x52\xBC\x8B" + "\xFF\x49\x9D\x76\xFF\x3E\x7A\x5C\xFF" + "\x36\x5C\x47\xFF\x31\x4C\x3B\xFF\x2D\x3D\x2F\xFF\x29\x30\x28\xFF\x27\x2B\x23\xFF\x27\x29\x22" + "\xFF\x27\x28\x21\xFF\x28\x27\x21\xFF" + "\x27\x25\x20\xFF\x27\x24\x1F\xFF\x24\x24\x1E\xFF\x25\x23\x1F\xFF\x28\x25\x20\xFF\x29\x26\x20" + "\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF" + "\x26\x23\x1F\xFF\x27\x24\x1F\xFF\x29\x27\x21\xFF\x2A\x27\x21\xFF\x27\x24\x1F\xFF\x25\x24\x1E" + "\xFF\x24\x24\x1F\xFF\x26\x24\x1F\xFF" + "\x28\x25\x1F\xFF\x27\x25\x1E\xFF\x27\x25\x20\xFF\x25\x25\x1F\xFF\x29\x26\x21\xFF\x27\x27\x20" + "\xFF\x26\x25\x1F\xFF\x25\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x23\x23\x1D\xFF\x26\x25\x1E\xFF\x27\x24\x1E\xFF\x25\x22\x1E\xFF\x27\x24\x1F" + "\xFF\x29\x26\x21\xFF\x26\x26\x1E\xFF" + "\x28\x27\x21\xFF\x28\x26\x21\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x25\x23\x1E" + "\xFF\x25\x23\x1F\xFF\x27\x24\x1F\xFF" + "\x27\x24\x1D\xFF\x29\x26\x20\xFF\x27\x26\x20\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x26\x23\x1E" + "\xFF\x25\x24\x1D\xFF\x26\x26\x20\xFF" + "\x25\x22\x1D\xFF\x26\x25\x1E\xFF\x27\x24\x1F\xFF\x25\x22\x1D\xFF\x27\x25\x1F\xFF\x27\x24\x1D" + "\xFF\x24\x22\x1D\xFF\x24\x22\x1D\xFF" + "\x26\x24\x1E\xFF\x25\x24\x1E\xFF\x27\x25\x1F\xFF\x28\x24\x1E\xFF\x27\x24\x1F\xFF\x28\x25\x20" + "\xFF\x27\x24\x1F\xFF\x29\x28\x20\xFF" + "\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x24\x23\x1D\xFF\x25\x24\x1E\xFF\x25\x22\x1D\xFF\x25\x23\x1E" + "\xFF\x26\x24\x1F\xFF\x26\x24\x1E\xFF" + "\x22\x23\x1D\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x25\x24\x1F\xFF\x24\x23\x1E\xFF\x26\x23\x1E" + "\xFF\x27\x25\x20\xFF\x25\x24\x1E\xFF" + "\x27\x25\x20\xFF\x26\x23\x1E\xFF\x25\x23\x1E\xFF\x24\x21\x1C\xFF\x25\x24\x1E\xFF\x24\x24\x1E" + "\xFF\x23\x23\x1D\xFF\x25\x23\x1E\xFF" + "\x26\x25\x1F\xFF\x23\x21\x1C\xFF\x24\x23\x1D\xFF\x26\x24\x1F\xFF\x23\x22\x1D\xFF\x23\x21\x1C" + "\xFF\x25\x23\x1E\xFF\x28\x25\x20\xFF" + "\x28\x26\x1F\xFF\x28\x25\x1E\xFF\x25\x24\x1D\xFF\x26\x25\x20\xFF\x24\x22\x1E\xFF\x25\x23\x1E" + "\xFF\x24\x21\x1D\xFF\x26\x23\x1E\xFF" + "\x27\x2D\x26\xFF\x39\x6A\x50\xFF\x53\xC1\x90\xFF\x58\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98" + "\xFF\x41\x85\x65\xFF\x2A\x35\x2C\xFF" + "\x27\x27\x21\xFF\x26\x25\x1F\xFF\x24\x23\x1E\xFF\x25\x22\x1D\xFF\x26\x22\x1F\xFF\x24\x23\x1E" + "\xFF\x24\x24\x1E\xFF\x22\x21\x1C\xFF" + "\x20\x20\x1A\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x29\x26\x21\xFF\x27\x24\x1F\xFF\x26\x25\x1E" + "\xFF\x27\x27\x1F\xFF\x27\x2A\x24\xFF" + "\x31\x52\x3E\xFF\x51\xBA\x8A\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x97" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x48\x9C\x75\xFF\x2D\x3E\x31\xFF\x27\x28\x22\xFF\x25\x22\x1E\xFF\x25\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x27\x24\x1F\xFF" + "\x28\x26\x20\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x24\x23\x1E\xFF\x26\x23\x1E\xFF\x25\x24\x1E" + "\xFF\x25\x22\x1E\xFF\x25\x22\x1E\xFF" + "\x27\x24\x1F\xFF\x25\x22\x1D\xFF\x24\x22\x1E\xFF\x22\x22\x1D\xFF\x24\x23\x1D\xFF\x21\x21\x1B" + "\xFF\x1F\x1E\x19\xFF\x23\x20\x1B\xFF" + "\x20\x1F\x1A\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF\x24\x21\x1D\xFF\x23\x23\x1D\xFF\x24\x23\x1D" + "\xFF\x23\x21\x1C\xFF\x24\x21\x1C\xFF" + "\x27\x24\x1F\xFF\x24\x22\x1D\xFF\x22\x21\x1B\xFF\x26\x23\x1E\xFF\x26\x25\x1E\xFF\x23\x23\x1D" + "\xFF\x25\x22\x1D\xFF\x28\x24\x20\xFF" + "\x24\x21\x1F\xFF\x26\x24\x1F\xFF\x25\x24\x1E\xFF\x23\x23\x1D\xFF\x23\x21\x1C\xFF\x24\x21\x1C" + "\xFF\x24\x21\x1C\xFF\x21\x20\x1A\xFF" + "\x22\x21\x1B\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF\x23\x21\x1F\xFF\x23\x21\x1C\xFF\x23\x22\x1C" + "\xFF\x24\x23\x1E\xFF\x23\x21\x1C\xFF" + "\x24\x24\x1E\xFF\x23\x23\x1D\xFF\x21\x21\x1B\xFF\x24\x23\x1D\xFF\x22\x22\x1C\xFF\x25\x23\x1E" + "\xFF\x24\x21\x1C\xFF\x21\x1D\x1A\xFF" + "\x23\x22\x1D\xFF\x25\x22\x1D\xFF\x21\x20\x1B\xFF\x21\x1F\x1B\xFF\x21\x1F\x1B\xFF\x25\x23\x1E" + "\xFF\x24\x21\x1D\xFF\x24\x23\x1D\xFF" + "\x26\x24\x1E\xFF\x22\x21\x1C\xFF\x23\x21\x1C\xFF\x22\x22\x1C\xFF\x22\x20\x1B\xFF\x24\x24\x1E" + "\xFF\x25\x23\x1E\xFF\x23\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x21\x21\x1C\xFF\x22\x21\x1C\xFF\x23\x22\x1C\xFF\x21\x1F\x1B\xFF\x23\x20\x1C" + "\xFF\x24\x23\x1D\xFF\x21\x21\x1B\xFF" + "\x22\x22\x1D\xFF\x25\x24\x1E\xFF\x26\x23\x1E\xFF\x25\x22\x1E\xFF\x22\x22\x1C\xFF\x23\x23\x1D" + "\xFF\x23\x23\x1D\xFF\x24\x21\x1C\xFF" + "\x1F\x1E\x1A\xFF\x21\x20\x1A\xFF\x1F\x1D\x18\xFF\x1E\x1D\x19\xFF\x22\x22\x1C\xFF\x21\x21\x1B" + "\xFF\x21\x20\x1B\xFF\x20\x1F\x1A\xFF" + "\x24\x23\x1D\xFF\x21\x20\x1A\xFF\x21\x1F\x1A\xFF\x22\x21\x1C\xFF\x25\x23\x1E\xFF\x23\x22\x1D" + "\xFF\x23\x21\x1D\xFF\x24\x21\x1C\xFF" + "\x23\x21\x1C\xFF\x25\x23\x1E\xFF\x23\x21\x1C\xFF\x22\x22\x1C\xFF\x21\x20\x1B\xFF\x21\x21\x1B" + "\xFF\x23\x21\x1B\xFF\x24\x21\x1C\xFF" + "\x23\x23\x1D\xFF\x23\x21\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x20\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1D\xFF\x20\x1F\x1B\xFF" + "\x25\x23\x1E\xFF\x23\x23\x1E\xFF\x23\x21\x1C\xFF\x28\x25\x20\xFF\x21\x1F\x1B\xFF\x20\x1E\x1A" + "\xFF\x23\x21\x1C\xFF\x23\x21\x1C\xFF" + "\x22\x20\x1B\xFF\x21\x20\x1B\xFF\x23\x22\x1D\xFF\x23\x22\x1C\xFF\x23\x21\x1C\xFF\x24\x23\x1D" + "\xFF\x24\x22\x1C\xFF\x23\x21\x1D\xFF" + "\x12\x11\x0E\xFF\x13\x11\x0F\xFF\x13\x11\x0F\xFF\x12\x11\x0D\xFF\x15\x13\x12\xFF\x15\x14\x11" + "\xFF\x15\x15\x10\xFF\x11\x0F\x0E\xFF" + "\x11\x0E\x0D\xFF\x11\x10\x0E\xFF\x12\x10\x0E\xFF\x11\x0E\x0D\xFF\x10\x0E\x0D\xFF\x12\x10\x0E" + "\xFF\x11\x0F\x0D\xFF\x11\x10\x0E\xFF" + "\x13\x12\x0F\xFF\x13\x12\x0E\xFF\x13\x12\x0F\xFF\x13\x12\x0F\xFF\x10\x10\x0C\xFF\x12\x11\x0E" + "\xFF\x13\x12\x0F\xFF\x12\x12\x0F\xFF" + "\x11\x0F\x0E\xFF\x14\x13\x0F\xFF\x13\x12\x0F\xFF\x14\x13\x0F\xFF\x13\x12\x0F\xFF\x13\x11\x10" + "\xFF\x12\x11\x0F\xFF\x11\x11\x0E\xFF" + "\x11\x11\x0E\xFF\x16\x14\x11\xFF\x13\x11\x0F\xFF\x13\x12\x10\xFF\x16\x14\x10\xFF\x15\x13\x10" + "\xFF\x15\x14\x11\xFF\x12\x12\x0E\xFF" + "\x14\x13\x0F\xFF\x16\x14\x11\xFF\x14\x12\x0F\xFF\x15\x15\x11\xFF\x16\x15\x11\xFF\x15\x14\x10" + "\xFF\x13\x12\x0F\xFF\x12\x11\x0E\xFF" + "\x13\x11\x0F\xFF\x14\x12\x10\xFF\x14\x12\x11\xFF\x13\x13\x10\xFF\x16\x15\x11\xFF\x15\x15\x10" + "\xFF\x13\x13\x0E\xFF\x17\x15\x11\xFF" + "\x10\x10\x0D\xFF\x14\x13\x0F\xFF\x15\x13\x10\xFF\x13\x12\x0F\xFF\x15\x14\x11\xFF\x15\x14\x10" + "\xFF\x11\x10\x0D\xFF\x14\x13\x0F\xFF" + "\x16\x14\x10\xFF\x12\x11\x0E\xFF\x11\x10\x0D\xFF\x14\x12\x10\xFF\x14\x13\x10\xFF\x14\x13\x10" + "\xFF\x13\x12\x0F\xFF\x13\x11\x0E\xFF" + "\x17\x15\x11\xFF\x18\x16\x13\xFF\x18\x17\x13\xFF\x12\x11\x0E\xFF\x15\x14\x10\xFF\x13\x12\x0E" + "\xFF\x14\x13\x0F\xFF\x14\x12\x0F\xFF" + "\x18\x17\x13\xFF\x19\x18\x14\xFF\x16\x15\x11\xFF\x12\x11\x0D\xFF\x14\x13\x10\xFF\x15\x14\x11" + "\xFF\x14\x13\x10\xFF\x13\x13\x0E\xFF" + "\x15\x14\x11\xFF\x18\x17\x13\xFF\x14\x12\x0F\xFF\x13\x12\x0F\xFF\x13\x12\x0E\xFF\x14\x13\x10" + "\xFF\x16\x15\x11\xFF\x18\x16\x13\xFF" + "\x16\x14\x12\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF\x15\x14\x10\xFF\x17\x16\x12\xFF\x15\x14\x11" + "\xFF\x17\x15\x13\xFF\x15\x14\x11\xFF" + "\x16\x14\x10\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x14\x13\x10\xFF\x16\x16\x12\xFF\x17\x16\x12" + "\xFF\x16\x15\x11\xFF\x14\x13\x0F\xFF" + "\x17\x16\x12\xFF\x17\x16\x12\xFF\x15\x14\x10\xFF\x14\x13\x0F\xFF\x16\x15\x11\xFF\x13\x12\x0F" + "\xFF\x13\x12\x0E\xFF\x13\x11\x0F\xFF" + "\x15\x14\x11\xFF\x15\x14\x11\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF\x1A\x19\x15\xFF\x18\x17\x13" + "\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF" + "\x13\x13\x0F\xFF\x17\x15\x11\xFF\x18\x16\x14\xFF\x15\x14\x11\xFF\x15\x14\x10\xFF\x19\x17\x13" + "\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF" + "\x1A\x19\x15\xFF\x19\x18\x14\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF\x16\x15\x11" + "\xFF\x15\x14\x10\xFF\x16\x15\x11\xFF" + "\x19\x18\x14\xFF\x17\x16\x12\xFF\x17\x16\x12\xFF\x16\x14\x11\xFF\x19\x18\x14\xFF\x17\x16\x12" + "\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF" + "\x1B\x1A\x16\xFF\x16\x16\x12\xFF\x17\x16\x12\xFF\x16\x15\x11\xFF\x17\x16\x12\xFF\x18\x17\x13" + "\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF" + "\x15\x14\x10\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF\x17\x16\x12\xFF\x1A\x18\x14\xFF\x1A\x19\x15" + "\xFF\x19\x18\x14\xFF\x19\x17\x13\xFF" + "\x19\x18\x14\xFF\x16\x15\x11\xFF\x17\x16\x12\xFF\x19\x18\x14\xFF\x18\x17\x13\xFF\x19\x18\x14" + "\xFF\x18\x17\x13\xFF\x19\x18\x14\xFF" + "\x1A\x18\x14\xFF\x1A\x17\x14\xFF\x1A\x18\x14\xFF\x13\x13\x11\xFF\x19\x19\x15\xFF\x19\x18\x14" + "\xFF\x19\x19\x14\xFF\x1B\x1A\x16\xFF" + "\x1A\x18\x14\xFF\x18\x17\x13\xFF\x15\x14\x11\xFF\x19\x18\x14\xFF\x1A\x18\x14\xFF\x1B\x1C\x16" + "\xFF\x1A\x19\x15\xFF\x18\x16\x12\xFF" + "\x18\x17\x13\xFF\x1A\x19\x14\xFF\x19\x18\x13\xFF\x1A\x19\x15\xFF\x19\x18\x15\xFF\x1A\x19\x15" + "\xFF\x19\x18\x14\xFF\x1A\x1A\x15\xFF" + "\x1A\x18\x14\xFF\x19\x19\x15\xFF\x1A\x1A\x16\xFF\x1A\x19\x15\xFF\x17\x17\x13\xFF\x19\x19\x15" + "\xFF\x1B\x19\x15\xFF\x19\x17\x13\xFF" + "\x1A\x1A\x15\xFF\x1A\x19\x14\xFF\x1D\x1C\x18\xFF\x1E\x1C\x18\xFF\x19\x17\x14\xFF\x19\x17\x13" + "\xFF\x1A\x19\x15\xFF\x1C\x1A\x16\xFF" + "\x1B\x19\x15\xFF\x18\x16\x13\xFF\x18\x16\x13\xFF\x19\x18\x14\xFF\x18\x17\x13\xFF\x18\x17\x13" + "\xFF\x1A\x19\x14\xFF\x1C\x1B\x16\xFF" + "\x1E\x1B\x17\xFF\x1A\x1A\x15\xFF\x1C\x1A\x16\xFF\x1B\x1A\x15\xFF\x1C\x1B\x17\xFF\x1B\x1B\x16" + "\xFF\x1E\x1C\x18\xFF\x1D\x1B\x17\xFF" + "\x1D\x1B\x16\xFF\x1C\x1B\x16\xFF\x1B\x1A\x17\xFF\x1A\x18\x16\xFF\x1B\x19\x15\xFF\x1B\x1B\x16" + "\xFF\x1A\x19\x15\xFF\x1B\x1A\x16\xFF" + "\x20\x1F\x19\xFF\x1B\x1A\x17\xFF\x1B\x1A\x16\xFF\x19\x19\x15\xFF\x1D\x1C\x18\xFF\x20\x20\x19" + "\xFF\x1F\x1F\x18\xFF\x1D\x1C\x18\xFF" + "\x1E\x1E\x18\xFF\x1C\x1A\x16\xFF\x1A\x19\x14\xFF\x19\x18\x14\xFF\x1C\x1A\x17\xFF\x1B\x1A\x16" + "\xFF\x1E\x1E\x19\xFF\x1F\x1E\x18\xFF" + "\x1C\x1B\x17\xFF\x1B\x1A\x16\xFF\x1C\x1C\x17\xFF\x1F\x1E\x19\xFF\x1F\x1F\x19\xFF\x1F\x1C\x18" + "\xFF\x1E\x1C\x17\xFF\x1C\x1C\x17\xFF" + "\x1D\x1B\x16\xFF\x1F\x1D\x19\xFF\x1F\x1E\x19\xFF\x1C\x1B\x16\xFF\x1E\x1C\x17\xFF\x1B\x1A\x16" + "\xFF\x1D\x1B\x18\xFF\x1E\x1C\x18\xFF" + "\x1C\x1C\x17\xFF\x1F\x1F\x19\xFF\x1D\x1C\x17\xFF\x1E\x1B\x17\xFF\x1F\x1D\x18\xFF\x1D\x1C\x18" + "\xFF\x1D\x1D\x18\xFF\x21\x20\x1B\xFF" + "\x21\x1F\x1C\xFF\x1E\x1D\x19\xFF\x1E\x1C\x18\xFF\x1F\x1D\x19\xFF\x1D\x1C\x18\xFF\x1E\x1C\x17" + "\xFF\x1F\x1D\x18\xFF\x20\x1F\x19\xFF" + "\x20\x1D\x19\xFF\x1C\x1B\x16\xFF\x20\x1F\x1A\xFF\x22\x1F\x1B\xFF\x21\x1F\x1A\xFF\x1E\x1C\x18" + "\xFF\x1D\x1B\x17\xFF\x1E\x1C\x18\xFF" + "\x1D\x1C\x18\xFF\x1E\x1C\x18\xFF\x1F\x1D\x19\xFF\x20\x1F\x1B\xFF\x1F\x1E\x1A\xFF\x1F\x1E\x1A" + "\xFF\x21\x1F\x1A\xFF\x1E\x1D\x19\xFF" + "\x20\x1F\x1B\xFF\x1E\x1E\x18\xFF\x1D\x1D\x18\xFF\x20\x1E\x1A\xFF\x20\x1E\x1A\xFF\x20\x1E\x19" + "\xFF\x1D\x1C\x17\xFF\x1C\x1C\x16\xFF" + "\x1C\x1B\x17\xFF\x1F\x1C\x18\xFF\x20\x1E\x19\xFF\x20\x1E\x1A\xFF\x1D\x1B\x16\xFF\x1C\x1C\x16" + "\xFF\x1C\x1D\x18\xFF\x1D\x1D\x18\xFF" + "\x1B\x19\x16\xFF\x1B\x1B\x15\xFF\x1A\x19\x15\xFF\x1B\x19\x16\xFF\x1C\x1A\x16\xFF\x1D\x1B\x18" + "\xFF\x17\x16\x13\xFF\x16\x15\x11\xFF" + "\x15\x13\x10\xFF\x14\x13\x10\xFF\x4F\x4B\x3E\xFF\x28\x26\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x28\x26\x21\xFF\x26\x25\x20\xFF" + "\x29\x28\x23\xFF\x22\x22\x1D\xFF\x26\x25\x20\xFF\x22\x21\x1C\xFF\x24\x23\x1E\xFF\x25\x24\x20" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x20\x1B\xFF\x25\x25\x20\xFF\x26\x25\x20\xFF\x24\x22\x1D\xFF\x28\x26\x21\xFF\x23\x22\x1D" + "\xFF\x24\x23\x1E\xFF\x28\x26\x21\xFF" + "\x21\x20\x1A\xFF\x28\x26\x21\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1D\xFF" + "\x23\x22\x1C\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x22\x1D\xFF\x25\x24\x20" + "\xFF\x29\x28\x22\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x21\x20\x1B\xFF\x22\x20\x1B\xFF\x21\x20\x1A\xFF\x22\x21\x1B\xFF\x26\x25\x20" + "\xFF\x23\x21\x1C\xFF\x23\x22\x1D\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x23\x1E\xFF\x28\x26\x21\xFF\x23\x22\x1E\xFF\x24\x22\x1D" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1D\xFF" + "\x28\x26\x21\xFF\x24\x22\x1D\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x20\x1B\xFF\x23\x21\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x25\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x21" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1E\xFF" + "\x21\x21\x1B\xFF\x26\x25\x20\xFF\x25\x24\x20\xFF\x22\x22\x1C\xFF\x25\x23\x1E\xFF\x23\x22\x1C" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF" + "\x24\x22\x1D\xFF\x23\x22\x1D\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x25\x24\x20" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x21\x20\x1A\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1F\xFF" + "\x26\x25\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x23\x1F\xFF\x25\x24\x1F\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x25\x24\x20\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x28\x26\x21" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1D\xFF" + "\x22\x22\x1C\xFF\x28\x26\x22\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x23\x22\x1D\xFF\x22\x21\x1B" + "\xFF\x26\x25\x21\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x26\x24\x20\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x26\x25\x21\xFF\x23\x22\x1C\xFF\x24\x24\x1E\xFF\x22\x21\x1B\xFF\x24\x23\x1E" + "\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF" + "\x24\x23\x1E\xFF\x26\x25\x20\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x26\x25\x20\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF" + "\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x22\x21\x1B" + "\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x28\x26\x21\xFF\x23\x22\x1C\xFF\x23\x23\x1E\xFF\x25\x23\x1E\xFF\x24\x23\x1E\xFF\x29\x28\x22" + "\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x22\x22\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x28\x26\x22" + "\xFF\x22\x21\x1B\xFF\x24\x22\x1D\xFF" + "\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x26\x24\x20" + "\xFF\x29\x28\x22\xFF\x22\x21\x1C\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x28\x26\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x28\x26\x21\xFF\x26\x25\x20\xFF" + "\x29\x28\x23\xFF\x23\x23\x1E\xFF\x27\x25\x20\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x25\x24\x20" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x25\x25\x20\xFF\x27\x25\x20\xFF\x24\x22\x1D\xFF\x28\x26\x21\xFF\x24\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x28\x26\x21\xFF" + "\x22\x21\x1B\xFF\x28\x26\x21\xFF\x24\x22\x1D\xFF\x23\x22\x1C\xFF\x23\x22\x1C\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x25\x24\x20" + "\xFF\x29\x28\x22\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x27\x26\x21" + "\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x24\x1F\xFF\x28\x26\x21\xFF\x23\x22\x1E\xFF\x24\x23\x1E" + "\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF" + "\x28\x26\x21\xFF\x24\x23\x1E\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x23\x22\x1C" + "\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF" + "\x23\x22\x1C\xFF\x25\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x26\x21" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1E\xFF" + "\x22\x21\x1B\xFF\x26\x25\x20\xFF\x26\x24\x20\xFF\x23\x22\x1C\xFF\x25\x24\x1F\xFF\x23\x22\x1C" + "\xFF\x28\x26\x21\xFF\x22\x21\x1B\xFF" + "\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x25\x24\x1F\xFF\x23\x22\x1C\xFF" + "\x24\x22\x1D\xFF\x24\x23\x1E\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x26\x25\x20" + "\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF" + "\x23\x22\x1C\xFF\x25\x24\x1F\xFF\x29\x28\x22\xFF\x22\x21\x1B\xFF\x22\x21\x1B\xFF\x22\x21\x1B" + "\xFF\x22\x21\x1B\xFF\x25\x24\x20\xFF" + "\x27\x26\x21\xFF\x22\x21\x1B\xFF\x23\x22\x1C\xFF\x25\x24\x1F\xFF\x25\x24\x1F\xFF\x22\x21\x1B" + "\xFF\x23\x22\x1C\xFF\x26\x25\x20\xFF" + "\x22\x21\x1B\xFF\x27\x25\x20\xFF\x22\x21\x1B\xFF\x25\x24\x1F\xFF\x22\x21\x1B\xFF\x28\x27\x21" + "\xFF\x22\x22\x1B\xFF\x24\x24\x1F\xFF" + "\x23\x26\x1F\xFF\x2A\x2E\x28\xFF\x25\x2D\x24\xFF\x27\x31\x27\xFF\x29\x34\x2A\xFF\x27\x32\x27" + "\xFF\x2B\x36\x2D\xFF\x27\x32\x27\xFF" + "\x29\x34\x2A\xFF\x2A\x35\x2C\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF\x27\x32\x27" + "\xFF\x27\x32\x27\xFF\x27\x32\x27\xFF" + "\x27\x32\x27\xFF\x2B\x36\x2D\xFF\x28\x33\x28\xFF\x2A\x35\x2B\xFF\x27\x32\x27\xFF\x29\x34\x2A" + "\xFF\x28\x33\x28\xFF\x28\x33\x28\xFF" + "\x2A\x35\x2B\xFF\x2A\x35\x2C\xFF\x28\x33\x28\xFF\x27\x32\x27\xFF\x28\x33\x28\xFF\x27\x32\x27" + "\xFF\x27\x32\x27\xFF\x28\x33\x28\xFF" + "\x28\x33\x28\xFF\x2B\x36\x2C\xFF\x27\x32\x27\xFF\x2A\x35\x2B\xFF\x27\x32\x27\xFF\x27\x32\x27" + "\xFF\x28\x33\x28\xFF\x27\x32\x27\xFF" + "\x29\x34\x2A\xFF\x28\x33\x28\xFF\x29\x34\x2A\xFF\x28\x33\x28\xFF\x2A\x35\x2B\xFF\x4F\x4D\x3F" + "\xFF\x3B\x8B\x67\xFF\x3B\x8C\x68\xFF" + "\x3E\x93\x6D\xFF\x41\x99\x71\xFF\x43\x9F\x76\xFF\x45\xA4\x7A\xFF\x48\xAA\x7E\xFF\x4A\xAF\x81" + "\xFF\x4C\xB3\x84\xFF\x4D\xB7\x87\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x50\xC0\x8E\xFF\x51\xC2\x8F\xFF\x52\xBC\x8B\xFF\x4A\xA7\x7C" + "\xFF\x44\x90\x6B\xFF\x3E\x78\x5B\xFF" + "\x36\x63\x4B\xFF\x41\x87\x66\xFF\x55\xCB\x96\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x53\xC2\x90\xFF\x4D\xAD\x81\xFF\x47\x96\x70\xFF\x40\x7E\x5F\xFF\x39\x63\x4C\xFF\x31\x48\x39" + "\xFF\x2D\x36\x2B\xFF\x27\x2C\x24\xFF" + "\x25\x27\x21\xFF\x27\x27\x21\xFF\x26\x24\x1E\xFF\x25\x24\x1E\xFF\x28\x25\x1F\xFF\x26\x24\x1E" + "\xFF\x25\x25\x20\xFF\x26\x24\x1F\xFF" + "\x25\x22\x1E\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x29\x26\x21\xFF\x25\x23\x1D\xFF\x25\x23\x1D" + "\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x2A\x27\x21\xFF\x29\x26\x21\xFF\x28\x25\x20\xFF\x26\x26\x20\xFF\x29\x26\x21\xFF\x29\x26\x21" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x26\x24\x1F\xFF\x25\x24\x1E\xFF\x25\x23\x1E\xFF\x24\x22\x1E\xFF\x28\x25\x20\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x25\x24\x1F\xFF" + "\x28\x27\x1F\xFF\x27\x25\x1F\xFF\x25\x25\x1F\xFF\x27\x25\x1F\xFF\x27\x24\x1F\xFF\x26\x23\x1F" + "\xFF\x25\x23\x1E\xFF\x28\x25\x20\xFF" + "\x28\x25\x20\xFF\x28\x26\x20\xFF\x26\x24\x1F\xFF\x26\x25\x1E\xFF\x26\x24\x1E\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x25\x20\xFF" + "\x25\x23\x1E\xFF\x27\x25\x1E\xFF\x27\x26\x1F\xFF\x26\x24\x1D\xFF\x25\x24\x1D\xFF\x28\x26\x1F" + "\xFF\x28\x27\x21\xFF\x26\x25\x1F\xFF" + "\x25\x23\x1E\xFF\x26\x25\x1F\xFF\x27\x24\x1F\xFF\x27\x25\x1E\xFF\x24\x23\x1E\xFF\x27\x25\x1F" + "\xFF\x27\x25\x20\xFF\x27\x26\x1F\xFF" + "\x29\x26\x20\xFF\x27\x25\x20\xFF\x27\x25\x1F\xFF\x26\x23\x1D\xFF\x23\x22\x1C\xFF\x26\x25\x1F" + "\xFF\x25\x25\x1E\xFF\x25\x24\x1E\xFF" + "\x25\x24\x1E\xFF\x24\x23\x1D\xFF\x24\x23\x1E\xFF\x25\x25\x1F\xFF\x25\x24\x1E\xFF\x25\x23\x1E" + "\xFF\x23\x23\x1E\xFF\x25\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x23\x1F\xFF\x25\x22\x1D\xFF\x27\x24\x1E\xFF\x27\x25\x1F" + "\xFF\x25\x24\x1E\xFF\x25\x23\x1E\xFF" + "\x26\x24\x1F\xFF\x23\x22\x1D\xFF\x26\x24\x1E\xFF\x24\x24\x1E\xFF\x26\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x26\x23\x1E\xFF\x26\x24\x1E\xFF" + "\x26\x24\x1E\xFF\x27\x25\x1E\xFF\x25\x23\x1E\xFF\x28\x25\x20\xFF\x24\x21\x1E\xFF\x25\x23\x1E" + "\xFF\x26\x23\x1F\xFF\x25\x22\x1C\xFF" + "\x26\x29\x22\xFF\x32\x53\x3F\xFF\x4E\xAF\x82\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x4A\xA4\x7A\xFF\x2C\x43\x35\xFF" + "\x28\x28\x22\xFF\x26\x25\x20\xFF\x26\x24\x1F\xFF\x25\x23\x1F\xFF\x25\x23\x1C\xFF\x25\x22\x1D" + "\xFF\x25\x24\x1D\xFF\x23\x23\x1D\xFF" + "\x23\x23\x1D\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x27\x25\x20\xFF\x23\x22\x1C\xFF\x24\x22\x1D" + "\xFF\x24\x23\x1D\xFF\x24\x25\x1F\xFF" + "\x2C\x40\x30\xFF\x47\x98\x71\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x56\xCC\x98\xFF\x56\xCC\x97" + "\xFF\x57\xCC\x97\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x4E\xB2\x84\xFF\x32\x56\x42\xFF\x25\x2A\x22\xFF\x25\x25\x1F\xFF\x26\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x25\x22\x1D\xFF" + "\x24\x24\x1E\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF\x27\x24\x1E\xFF\x25\x23\x1D" + "\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x25\x22\x1D\xFF\x24\x23\x1E\xFF\x25\x23\x1E\xFF\x23\x22\x1E\xFF\x24\x22\x1E\xFF\x23\x20\x1B" + "\xFF\x23\x22\x1C\xFF\x26\x23\x1E\xFF" + "\x25\x23\x1E\xFF\x23\x22\x1C\xFF\x24\x23\x1E\xFF\x25\x23\x1E\xFF\x25\x24\x1E\xFF\x27\x26\x1F" + "\xFF\x25\x24\x1E\xFF\x22\x20\x1B\xFF" + "\x23\x20\x1B\xFF\x23\x21\x1C\xFF\x23\x21\x1C\xFF\x24\x22\x1D\xFF\x23\x21\x1C\xFF\x23\x22\x1C" + "\xFF\x26\x24\x1E\xFF\x25\x23\x1E\xFF" + "\x23\x21\x1C\xFF\x25\x23\x1E\xFF\x25\x24\x1E\xFF\x22\x21\x1B\xFF\x22\x22\x1C\xFF\x24\x22\x1C" + "\xFF\x24\x21\x1C\xFF\x23\x21\x1C\xFF" + "\x25\x23\x1E\xFF\x26\x22\x1D\xFF\x25\x22\x1D\xFF\x23\x21\x1D\xFF\x24\x22\x1D\xFF\x21\x21\x1B" + "\xFF\x23\x22\x1D\xFF\x24\x23\x1D\xFF" + "\x23\x22\x1D\xFF\x22\x21\x1C\xFF\x23\x20\x1C\xFF\x23\x21\x1D\xFF\x21\x21\x1C\xFF\x25\x23\x1E" + "\xFF\x28\x25\x20\xFF\x23\x20\x1B\xFF" + "\x23\x21\x1C\xFF\x25\x22\x1D\xFF\x26\x23\x1E\xFF\x24\x23\x1E\xFF\x22\x21\x1B\xFF\x22\x20\x1C" + "\xFF\x21\x20\x1B\xFF\x23\x22\x1D\xFF" + "\x26\x24\x1E\xFF\x24\x21\x1D\xFF\x25\x22\x1E\xFF\x24\x22\x1D\xFF\x24\x23\x1E\xFF\x23\x22\x1D" + "\xFF\x23\x22\x1D\xFF\x25\x24\x1E\xFF" + "\x24\x21\x1D\xFF\x27\x24\x20\xFF\x25\x22\x1D\xFF\x26\x24\x1E\xFF\x22\x21\x1B\xFF\x22\x21\x1C" + "\xFF\x24\x21\x1D\xFF\x25\x23\x1F\xFF" + "\x26\x24\x1F\xFF\x26\x23\x1E\xFF\x25\x23\x1E\xFF\x25\x22\x1D\xFF\x23\x21\x1D\xFF\x24\x22\x1D" + "\xFF\x22\x1F\x1A\xFF\x22\x21\x1B\xFF" + "\x20\x1E\x1A\xFF\x21\x20\x1B\xFF\x22\x20\x1B\xFF\x21\x20\x1A\xFF\x22\x22\x1C\xFF\x23\x21\x1C" + "\xFF\x23\x21\x1C\xFF\x21\x20\x1B\xFF" + "\x23\x20\x1C\xFF\x21\x20\x1B\xFF\x22\x20\x1B\xFF\x21\x1F\x1B\xFF\x23\x21\x1C\xFF\x23\x21\x1C" + "\xFF\x24\x22\x1D\xFF\x21\x20\x1B\xFF" + "\x20\x1F\x1A\xFF\x26\x23\x1E\xFF\x25\x22\x1D\xFF\x23\x22\x1B\xFF\x21\x1F\x1B\xFF\x22\x1F\x1B" + "\xFF\x24\x21\x1D\xFF\x25\x23\x1D\xFF" + "\x25\x22\x1D\xFF\x21\x21\x1B\xFF\x21\x20\x1B\xFF\x22\x20\x1C\xFF\x22\x21\x1B\xFF\x1F\x1E\x19" + "\xFF\x22\x20\x1B\xFF\x21\x20\x1B\xFF" + "\x25\x23\x1E\xFF\x21\x21\x1C\xFF\x20\x1F\x1B\xFF\x21\x20\x1B\xFF\x24\x23\x1E\xFF\x22\x22\x1C" + "\xFF\x21\x20\x1B\xFF\x20\x1F\x1A\xFF" + "\x23\x21\x1C\xFF\x24\x22\x1D\xFF\x24\x21\x1D\xFF\x25\x24\x1E\xFF\x22\x21\x1C\xFF\x23\x22\x1C" + "\xFF\x24\x22\x1E\xFF\x22\x21\x1D\xFF" + "\x18\x18\x13\xFF\x15\x14\x10\xFF\x15\x13\x10\xFF\x13\x12\x0E\xFF\x12\x10\x0D\xFF\x12\x11\x0D" + "\xFF\x16\x15\x10\xFF\x14\x12\x10\xFF" + "\x12\x10\x10\xFF\x12\x10\x0E\xFF\x12\x11\x0E\xFF\x11\x10\x0D\xFF\x14\x13\x0F\xFF\x10\x0F\x0C" + "\xFF\x10\x0E\x0D\xFF\x10\x0E\x0D\xFF" + "\x13\x12\x0E\xFF\x10\x0F\x0D\xFF\x10\x0F\x0C\xFF\x13\x11\x0F\xFF\x13\x12\x0E\xFF\x13\x12\x0E" + "\xFF\x14\x13\x0F\xFF\x12\x11\x0F\xFF" + "\x12\x10\x0E\xFF\x13\x12\x0E\xFF\x11\x10\x0D\xFF\x14\x13\x0F\xFF\x14\x13\x10\xFF\x12\x10\x0E" + "\xFF\x13\x11\x0F\xFF\x14\x12\x10\xFF" + "\x13\x10\x0D\xFF\x17\x15\x12\xFF\x17\x17\x13\xFF\x12\x11\x0E\xFF\x16\x15\x11\xFF\x14\x13\x0F" + "\xFF\x13\x11\x0F\xFF\x13\x12\x0E\xFF" + "\x16\x15\x11\xFF\x14\x13\x0F\xFF\x14\x13\x0F\xFF\x1E\x1E\x18\xFF\x17\x15\x13\xFF\x16\x15\x11" + "\xFF\x13\x12\x0E\xFF\x12\x11\x0D\xFF" + "\x14\x12\x10\xFF\x13\x12\x0F\xFF\x14\x13\x0F\xFF\x13\x12\x0F\xFF\x14\x12\x10\xFF\x15\x14\x10" + "\xFF\x14\x14\x10\xFF\x15\x13\x0F\xFF" + "\x15\x14\x10\xFF\x12\x11\x0E\xFF\x12\x10\x0D\xFF\x14\x13\x0F\xFF\x14\x12\x11\xFF\x15\x14\x11" + "\xFF\x12\x11\x0E\xFF\x16\x14\x0F\xFF" + "\x15\x14\x10\xFF\x11\x10\x0C\xFF\x12\x11\x0D\xFF\x16\x15\x12\xFF\x15\x14\x10\xFF\x14\x13\x0F" + "\xFF\x14\x13\x0F\xFF\x12\x11\x0F\xFF" + "\x13\x12\x10\xFF\x14\x12\x11\xFF\x14\x12\x0F\xFF\x12\x11\x0E\xFF\x16\x15\x11\xFF\x17\x16\x12" + "\xFF\x15\x14\x11\xFF\x15\x15\x0F\xFF" + "\x17\x16\x12\xFF\x1A\x18\x15\xFF\x17\x16\x13\xFF\x14\x13\x0F\xFF\x11\x0F\x0E\xFF\x12\x11\x0F" + "\xFF\x14\x13\x10\xFF\x16\x15\x11\xFF" + "\x16\x15\x11\xFF\x16\x15\x11\xFF\x18\x17\x13\xFF\x15\x13\x10\xFF\x12\x11\x0E\xFF\x16\x15\x11" + "\xFF\x17\x16\x12\xFF\x15\x13\x11\xFF" + "\x16\x15\x12\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x18\x17\x13\xFF\x17\x16\x12" + "\xFF\x18\x17\x13\xFF\x14\x12\x0F\xFF" + "\x16\x15\x11\xFF\x15\x14\x10\xFF\x15\x14\x10\xFF\x13\x11\x0F\xFF\x15\x13\x11\xFF\x17\x16\x12" + "\xFF\x18\x17\x13\xFF\x17\x16\x12\xFF" + "\x16\x15\x11\xFF\x17\x16\x12\xFF\x18\x17\x13\xFF\x1C\x1B\x17\xFF\x17\x16\x12\xFF\x16\x15\x11" + "\xFF\x16\x15\x11\xFF\x18\x17\x13\xFF" + "\x14\x13\x0F\xFF\x15\x13\x11\xFF\x14\x12\x0F\xFF\x14\x13\x0F\xFF\x19\x18\x15\xFF\x17\x16\x13" + "\xFF\x15\x14\x11\xFF\x1B\x1A\x16\xFF" + "\x13\x12\x0E\xFF\x17\x15\x11\xFF\x16\x15\x11\xFF\x13\x12\x0F\xFF\x16\x15\x11\xFF\x18\x16\x13" + "\xFF\x18\x16\x13\xFF\x17\x16\x12\xFF" + "\x17\x16\x12\xFF\x16\x15\x11\xFF\x16\x15\x11\xFF\x1B\x1A\x16\xFF\x17\x16\x12\xFF\x17\x16\x12" + "\xFF\x16\x15\x11\xFF\x15\x14\x10\xFF" + "\x17\x16\x12\xFF\x1A\x1A\x15\xFF\x18\x17\x13\xFF\x18\x17\x14\xFF\x16\x15\x11\xFF\x18\x17\x13" + "\xFF\x19\x18\x14\xFF\x16\x15\x11\xFF" + "\x19\x18\x14\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF\x1C\x1B\x17\xFF\x1D\x1B\x17\xFF\x18\x17\x13" + "\xFF\x1C\x1A\x16\xFF\x19\x16\x12\xFF" + "\x16\x15\x11\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF\x1A\x18\x14\xFF\x18\x17\x13" + "\xFF\x19\x18\x14\xFF\x1A\x19\x15\xFF" + "\x19\x18\x14\xFF\x18\x16\x12\xFF\x1A\x18\x14\xFF\x18\x16\x12\xFF\x15\x14\x10\xFF\x17\x16\x12" + "\xFF\x16\x15\x11\xFF\x18\x16\x12\xFF" + "\x17\x17\x13\xFF\x18\x17\x13\xFF\x1B\x1A\x15\xFF\x1B\x1B\x16\xFF\x18\x18\x14\xFF\x18\x18\x14" + "\xFF\x1A\x19\x15\xFF\x19\x18\x14\xFF" + "\x1B\x19\x15\xFF\x1B\x1A\x16\xFF\x19\x18\x14\xFF\x1C\x1A\x16\xFF\x1B\x1A\x16\xFF\x1A\x19\x15" + "\xFF\x18\x17\x13\xFF\x18\x17\x13\xFF" + "\x1A\x19\x15\xFF\x19\x18\x14\xFF\x19\x19\x15\xFF\x1A\x18\x14\xFF\x1D\x1C\x18\xFF\x1B\x1A\x16" + "\xFF\x1E\x1C\x18\xFF\x1D\x1B\x17\xFF" + "\x1B\x18\x14\xFF\x1B\x1A\x16\xFF\x1B\x19\x15\xFF\x1B\x1A\x15\xFF\x18\x16\x12\xFF\x19\x18\x13" + "\xFF\x1B\x1A\x16\xFF\x1A\x19\x15\xFF" + "\x1B\x1A\x16\xFF\x20\x1D\x19\xFF\x1D\x1B\x17\xFF\x18\x18\x13\xFF\x1E\x1B\x17\xFF\x1B\x19\x15" + "\xFF\x1B\x1A\x16\xFF\x1A\x19\x14\xFF" + "\x19\x17\x14\xFF\x1C\x19\x16\xFF\x1B\x19\x15\xFF\x19\x17\x15\xFF\x1A\x19\x15\xFF\x1A\x19\x15" + "\xFF\x19\x19\x14\xFF\x1A\x1A\x15\xFF" + "\x1B\x1A\x15\xFF\x1E\x1C\x17\xFF\x1B\x1A\x15\xFF\x1B\x1A\x15\xFF\x1D\x1D\x17\xFF\x1E\x1D\x17" + "\xFF\x1C\x1B\x16\xFF\x17\x15\x11\xFF" + "\x19\x19\x15\xFF\x1C\x19\x15\xFF\x1D\x1B\x17\xFF\x1D\x1B\x18\xFF\x19\x18\x14\xFF\x1B\x1A\x16" + "\xFF\x1C\x1B\x17\xFF\x18\x17\x13\xFF" + "\x1B\x1A\x16\xFF\x1D\x1C\x17\xFF\x1B\x1A\x15\xFF\x17\x17\x12\xFF\x1A\x19\x15\xFF\x1A\x19\x15" + "\xFF\x17\x17\x13\xFF\x18\x17\x13\xFF" + "\x1D\x1D\x17\xFF\x1F\x1E\x19\xFF\x1A\x19\x14\xFF\x1A\x18\x16\xFF\x1D\x1A\x16\xFF\x1C\x1A\x16" + "\xFF\x1A\x1A\x16\xFF\x1D\x1C\x17\xFF" + "\x1B\x1A\x16\xFF\x1C\x1A\x16\xFF\x1D\x1B\x17\xFF\x1B\x1A\x16\xFF\x1C\x18\x14\xFF\x1D\x1B\x17" + "\xFF\x1C\x1B\x17\xFF\x1E\x1C\x18\xFF" + "\x1F\x1D\x19\xFF\x1E\x1E\x19\xFF\x1F\x1F\x1A\xFF\x1C\x1B\x17\xFF\x1E\x1E\x18\xFF\x1D\x1B\x18" + "\xFF\x1D\x1C\x17\xFF\x1D\x1C\x18\xFF" + "\x1A\x1A\x18\xFF\x1D\x1D\x18\xFF\x1D\x1C\x18\xFF\x1D\x1D\x17\xFF\x1E\x1D\x19\xFF\x1E\x1D\x18" + "\xFF\x1B\x1A\x15\xFF\x1F\x1E\x19\xFF" + "\x1B\x1A\x16\xFF\x1C\x1B\x17\xFF\x1B\x1A\x16\xFF\x1E\x1D\x18\xFF\x1E\x1D\x19\xFF\x1C\x1B\x16" + "\xFF\x1D\x1B\x17\xFF\x1F\x1E\x19\xFF" + "\x1D\x1A\x17\xFF\x1F\x1D\x19\xFF\x22\x21\x1B\xFF\x21\x20\x1B\xFF\x1C\x1B\x17\xFF\x1E\x1D\x18" + "\xFF\x1C\x1B\x17\xFF\x1D\x1D\x17\xFF" + "\x1D\x1C\x16\xFF\x1F\x1D\x18\xFF\x1C\x1B\x16\xFF\x1C\x1B\x17\xFF\x1E\x1C\x18\xFF\x20\x1F\x1A" + "\xFF\x24\x21\x1D\xFF\x21\x21\x1B\xFF" + "\x24\x22\x1D\xFF\x1E\x1D\x18\xFF\x1D\x1C\x18\xFF\x1D\x1C\x17\xFF\x20\x1F\x1B\xFF\x1F\x1E\x19" + "\xFF\x1B\x1A\x16\xFF\x1E\x1C\x17\xFF" + "\x1E\x1D\x19\xFF\x1E\x1D\x18\xFF\x1F\x1D\x18\xFF\x1E\x1B\x18\xFF\x1D\x1C\x17\xFF\x1D\x1C\x17" + "\xFF\x1D\x1D\x19\xFF\x1E\x1E\x18\xFF"; + +/** + * Experimental Case 03: 64x64 (32bpp) + */ + +static const BYTE TEST_RLE_BITMAP_EXPERIMENTAL_03[16384] = + "\x27\x2A\x23\xFF\x23\x25\x1F\xFF\x23\x23\x1E\xFF\x24\x23\x1D\xFF\x25\x23\x1D\xFF\x25\x23\x1E" + "\xFF\x25\x23\x1D\xFF\x25\x24\x1F\xFF" + "\x28\x2B\x23\xFF\x37\x60\x4A\xFF\x4A\xA2\x78\xFF\x47\x97\x71\xFF\x41\x84\x64\xFF\x3D\x75\x58" + "\xFF\x38\x62\x4B\xFF\x33\x50\x3E\xFF" + "\x2E\x3C\x30\xFF\x2A\x34\x29\xFF\x28\x30\x26\xFF\x27\x2C\x24\xFF\x26\x29\x22\xFF\x27\x28\x21" + "\xFF\x27\x26\x20\xFF\x27\x25\x20\xFF" + "\x25\x25\x20\xFF\x24\x23\x1D\xFF\x26\x23\x1E\xFF\x28\x25\x20\xFF\x26\x24\x1E\xFF\x27\x24\x1F" + "\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF" + "\x26\x25\x1F\xFF\x28\x25\x20\xFF\x28\x26\x21\xFF\x2A\x27\x22\xFF\x26\x25\x1E\xFF\x27\x24\x1F" + "\xFF\x27\x25\x1F\xFF\x28\x25\x1F\xFF" + "\x27\x27\x1F\xFF\x27\x24\x1F\xFF\x25\x24\x1F\xFF\x26\x24\x1F\xFF\x24\x24\x1E\xFF\x25\x24\x1D" + "\xFF\x27\x25\x1F\xFF\x28\x25\x20\xFF" + "\x27\x24\x1F\xFF\x28\x25\x1F\xFF\x27\x26\x1F\xFF\x27\x25\x1E\xFF\x25\x23\x1E\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x25\x20\xFF" + "\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF\x25\x22\x1D" + "\xFF\x26\x23\x1E\xFF\x23\x21\x1C\xFF" + "\x32\x51\x3F\xFF\x29\x37\x2C\xFF\x29\x31\x28\xFF\x27\x2C\x24\xFF\x26\x29\x21\xFF\x28\x28\x22" + "\xFF\x27\x27\x20\xFF\x27\x27\x21\xFF" + "\x29\x2F\x25\xFF\x3C\x73\x56\xFF\x55\xC9\x94\xFF\x56\xCC\x96\xFF\x56\xCB\x97\xFF\x54\xC5\x92" + "\xFF\x52\xBD\x8C\xFF\x50\xB5\x86\xFF" + "\x4D\xAA\x7F\xFF\x48\x99\x71\xFF\x40\x80\x61\xFF\x37\x66\x4D\xFF\x2F\x48\x38\xFF\x2C\x38\x2C" + "\xFF\x2B\x33\x29\xFF\x2A\x2E\x26\xFF" + "\x27\x29\x23\xFF\x27\x27\x21\xFF\x27\x27\x21\xFF\x27\x26\x20\xFF\x26\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x27\x26\x20\xFF\x28\x26\x20\xFF\x28\x25\x20\xFF\x28\x27\x20\xFF\x27\x25\x1F\xFF\x27\x25\x20" + "\xFF\x27\x25\x1F\xFF\x28\x26\x20\xFF" + "\x25\x23\x1E\xFF\x26\x24\x1E\xFF\x25\x23\x1D\xFF\x27\x25\x1F\xFF\x26\x24\x1E\xFF\x26\x23\x1E" + "\xFF\x29\x26\x21\xFF\x28\x25\x20\xFF" + "\x26\x25\x1F\xFF\x27\x25\x1F\xFF\x25\x25\x1F\xFF\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x26\x25\x1F" + "\xFF\x25\x23\x1D\xFF\x27\x24\x1F\xFF" + "\x25\x24\x1F\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF\x27\x24\x1E\xFF\x26\x26\x1E\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x4E\xBA\x89\xFF\x4D\xB3\x83\xFF\x45\x97\x70\xFF\x3D\x79\x5B\xFF\x35\x58\x44\xFF\x30\x48\x39" + "\xFF\x2D\x3A\x2F\xFF\x29\x31\x27\xFF" + "\x2B\x37\x2C\xFF\x3E\x79\x5B\xFF\x56\xCA\x95\xFF\x56\xCC\x96\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x52\xBC\x8B" + "\xFF\x49\x9D\x76\xFF\x3E\x7A\x5C\xFF" + "\x36\x5C\x47\xFF\x31\x4C\x3B\xFF\x2D\x3D\x2F\xFF\x29\x30\x28\xFF\x27\x2B\x23\xFF\x27\x29\x22" + "\xFF\x27\x28\x21\xFF\x28\x27\x21\xFF" + "\x27\x25\x20\xFF\x27\x24\x1F\xFF\x24\x24\x1E\xFF\x25\x23\x1F\xFF\x28\x25\x20\xFF\x29\x26\x20" + "\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF" + "\x26\x23\x1F\xFF\x27\x24\x1F\xFF\x29\x27\x21\xFF\x2A\x27\x21\xFF\x27\x24\x1F\xFF\x25\x24\x1E" + "\xFF\x24\x24\x1F\xFF\x26\x24\x1F\xFF" + "\x28\x25\x1F\xFF\x27\x25\x1E\xFF\x27\x25\x20\xFF\x25\x25\x1F\xFF\x29\x26\x21\xFF\x27\x27\x20" + "\xFF\x26\x25\x1F\xFF\x25\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x23\x23\x1D\xFF\x26\x25\x1E\xFF\x27\x24\x1E\xFF\x25\x22\x1E\xFF\x27\x24\x1F" + "\xFF\x29\x26\x21\xFF\x26\x26\x1E\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x50\xC0\x8E\xFF\x51\xC2\x8F\xFF\x52\xBC\x8B\xFF\x4A\xA7\x7C" + "\xFF\x44\x90\x6B\xFF\x3E\x78\x5B\xFF" + "\x36\x63\x4B\xFF\x41\x87\x66\xFF\x55\xCB\x96\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x53\xC2\x90\xFF\x4D\xAD\x81\xFF\x47\x96\x70\xFF\x40\x7E\x5F\xFF\x39\x63\x4C\xFF\x31\x48\x39" + "\xFF\x2D\x36\x2B\xFF\x27\x2C\x24\xFF" + "\x25\x27\x21\xFF\x27\x27\x21\xFF\x26\x24\x1E\xFF\x25\x24\x1E\xFF\x28\x25\x1F\xFF\x26\x24\x1E" + "\xFF\x25\x25\x20\xFF\x26\x24\x1F\xFF" + "\x25\x22\x1E\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x29\x26\x21\xFF\x25\x23\x1D\xFF\x25\x23\x1D" + "\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x2A\x27\x21\xFF\x29\x26\x21\xFF\x28\x25\x20\xFF\x26\x26\x20\xFF\x29\x26\x21\xFF\x29\x26\x21" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x26\x24\x1F\xFF\x25\x24\x1E\xFF\x25\x23\x1E\xFF\x24\x22\x1E\xFF\x28\x25\x20\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x25\x24\x1F\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x50\xC0\x8E\xFF\x51\xC2\x8F\xFF\x53\xC5\x91\xFF\x54\xC7\x92" + "\xFF\x55\xC8\x95\xFF\x53\xC3\x92\xFF" + "\x50\xBA\x89\xFF\x51\xBD\x8C\xFF\x56\xCC\x97\xFF\x57\xCC\x97\xFF\x57\xCD\x99\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x58\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x55\xC8\x95\xFF\x52\xBD\x8D\xFF\x4E\xB0\x82" + "\xFF\x47\x93\x6E\xFF\x38\x65\x4C\xFF" + "\x2D\x3A\x2F\xFF\x2C\x33\x2A\xFF\x26\x2A\x23\xFF\x27\x28\x20\xFF\x28\x27\x21\xFF\x27\x24\x1F" + "\xFF\x26\x23\x1F\xFF\x28\x25\x20\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x24\x23\x1E\xFF\x26\x24\x1D\xFF\x24\x24\x1D\xFF\x24\x22\x1D" + "\xFF\x24\x21\x1D\xFF\x27\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF\x28\x25\x20\xFF\x27\x26\x20\xFF\x27\x25\x1E" + "\xFF\x25\x25\x1E\xFF\x26\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x27\x25\x1E\xFF\x26\x24\x1F\xFF\x27\x24\x20\xFF\x27\x26\x20\xFF\x28\x25\x20" + "\xFF\x27\x24\x1F\xFF\x24\x24\x1E\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x52\xC4\x91\xFF\x54\xC7\x92" + "\xFF\x55\xC8\x95\xFF\x54\xC8\x94\xFF" + "\x55\xCB\x96\xFF\x55\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x97\xFF\x57\xCD\x97\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCC\x97" + "\xFF\x57\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x52\xBE\x8D\xFF\x45\x90\x6C\xFF\x38\x62\x4B\xFF\x2F\x42\x34\xFF\x29\x30\x27\xFF\x27\x28\x22" + "\xFF\x28\x27\x21\xFF\x25\x22\x1E\xFF" + "\x23\x23\x1D\xFF\x25\x24\x1F\xFF\x28\x25\x20\xFF\x26\x25\x1F\xFF\x27\x25\x1F\xFF\x27\x25\x1E" + "\xFF\x25\x24\x1E\xFF\x27\x24\x20\xFF" + "\x27\x25\x1F\xFF\x26\x25\x1F\xFF\x25\x24\x1E\xFF\x28\x26\x20\xFF\x25\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x27\x23\x1F\xFF" + "\x27\x25\x1E\xFF\x26\x25\x1F\xFF\x2A\x27\x21\xFF\x2C\x29\x24\xFF\x27\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x28\x25\x20\xFF\x29\x26\x20\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x53\xC7\x93" + "\xFF\x54\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x55\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x56\xCD\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCC\x97\xFF\x57\xCC\x97\xFF" + "\x56\xCD\x97\xFF\x56\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCC\x98\xFF\x52\xC0\x8E\xFF\x49\x9D\x76\xFF\x3A\x6A\x51\xFF\x2E\x3F\x31" + "\xFF\x29\x2E\x24\xFF\x28\x27\x21\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x24\x1E\xFF\x25\x24\x1E\xFF\x25\x25\x1F\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x27\x25\x20\xFF\x27\x24\x1E\xFF\x27\x25\x20\xFF\x27\x27\x21\xFF\x25\x24\x1E\xFF\x26\x25\x1F" + "\xFF\x27\x25\x1F\xFF\x25\x24\x1E\xFF" + "\x25\x25\x1F\xFF\x28\x25\x20\xFF\x28\x26\x20\xFF\x28\x25\x20\xFF\x25\x23\x1D\xFF\x25\x23\x1E" + "\xFF\x26\x25\x1F\xFF\x27\x26\x20\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x52\xC4\x91\xFF\x53\xC7\x93" + "\xFF\x54\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x55\xCB\x95\xFF\x55\xCA\x95\xFF\x56\xCC\x96\xFF\x56\xCB\x96\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x58\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCC\x96\xFF\x56\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x52\xC1\x8E\xFF\x4C\xA8\x7C\xFF\x45\x92\x6D" + "\xFF\x42\x86\x64\xFF\x47\x99\x72\xFF" + "\x51\xB9\x89\xFF\x56\xCB\x96\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x53\xBF\x8E\xFF\x45\x8F\x6B" + "\xFF\x30\x47\x38\xFF\x28\x2E\x25\xFF" + "\x27\x26\x1E\xFF\x27\x25\x1E\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF\x27\x24\x1F\xFF\x29\x26\x20" + "\xFF\x28\x25\x1F\xFF\x26\x25\x1F\xFF" + "\x25\x24\x1F\xFF\x26\x25\x1F\xFF\x28\x25\x1F\xFF\x26\x24\x1E\xFF\x25\x23\x1E\xFF\x25\x24\x1E" + "\xFF\x29\x26\x21\xFF\x26\x24\x1F\xFF" + "\x27\x25\x1F\xFF\x29\x27\x20\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x26\x24\x1D\xFF\x26\x23\x1E" + "\xFF\x25\x23\x1D\xFF\x26\x24\x1E\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x52\xC4\x91\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x55\xCA\x95\xFF\x55\xCA\x95\xFF\x56\xCC\x96\xFF\x56\xCB\x96\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x99\xFF\x57\xCD\x98" + "\xFF\x56\xCD\x97\xFF\x56\xCD\x98\xFF" + "\x56\xCA\x96\xFF\x50\xB6\x87\xFF\x42\x83\x62\xFF\x30\x48\x39\xFF\x2A\x3B\x2E\xFF\x2B\x39\x2E" + "\xFF\x2D\x3B\x2F\xFF\x2D\x3B\x2F\xFF" + "\x2E\x40\x32\xFF\x35\x58\x45\xFF\x48\x9B\x74\xFF\x54\xC5\x92\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x4C\xA9\x7D\xFF\x34\x52\x3E\xFF" + "\x27\x2B\x22\xFF\x27\x26\x20\xFF\x29\x26\x21\xFF\x2A\x27\x22\xFF\x28\x25\x1E\xFF\x26\x23\x1E" + "\xFF\x29\x26\x21\xFF\x26\x24\x1E\xFF" + "\x25\x24\x1F\xFF\x26\x25\x1F\xFF\x28\x25\x20\xFF\x25\x23\x1E\xFF\x27\x25\x20\xFF\x25\x23\x1E" + "\xFF\x25\x22\x1D\xFF\x25\x23\x1E\xFF" + "\x27\x25\x1F\xFF\x25\x24\x1E\xFF\x27\x24\x1E\xFF\x25\x24\x1F\xFF\x26\x24\x1E\xFF\x25\x22\x1E" + "\xFF\x25\x23\x1D\xFF\x26\x25\x1E\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x56\xCD\x98\xFF" + "\x4C\xA8\x7D\xFF\x37\x5D\x47\xFF\x2D\x3D\x31\xFF\x2E\x3D\x30\xFF\x34\x5F\x49\xFF\x3B\x71\x55" + "\xFF\x3D\x79\x5B\xFF\x3A\x6C\x52\xFF" + "\x33\x50\x3D\xFF\x2F\x3D\x30\xFF\x2F\x47\x37\xFF\x3E\x7A\x5D\xFF\x54\xC5\x92\xFF\x56\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x48\x98\x72\xFF" + "\x2C\x37\x2C\xFF\x29\x2A\x23\xFF\x27\x26\x1F\xFF\x25\x24\x1E\xFF\x27\x25\x20\xFF\x26\x25\x1F" + "\xFF\x29\x27\x21\xFF\x25\x25\x1F\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x28\x26\x21\xFF\x28\x25\x20\xFF\x26\x23\x1E" + "\xFF\x24\x23\x1D\xFF\x25\x22\x1D\xFF" + "\x25\x23\x1E\xFF\x24\x23\x1E\xFF\x29\x26\x21\xFF\x28\x26\x20\xFF\x25\x24\x1F\xFF\x25\x24\x1F" + "\xFF\x25\x24\x1E\xFF\x24\x23\x1D\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x53\xC3\x91\xFF" + "\x35\x59\x45\xFF\x2D\x3B\x2F\xFF\x32\x50\x3E\xFF\x46\x92\x6D\xFF\x51\xBB\x8B\xFF\x54\xC4\x91" + "\xFF\x55\xC7\x93\xFF\x53\xC1\x8F\xFF" + "\x4E\xAE\x81\xFF\x3F\x75\x59\xFF\x2D\x40\x32\xFF\x2D\x3D\x31\xFF\x43\x8C\x68\xFF\x56\xCC\x97" + "\xFF\x56\xCD\x97\xFF\x56\xC8\x94\xFF" + "\x39\x65\x4D\xFF\x2A\x30\x26\xFF\x28\x28\x22\xFF\x27\x25\x1E\xFF\x2A\x27\x22\xFF\x28\x26\x21" + "\xFF\x29\x26\x21\xFF\x26\x25\x1E\xFF" + "\x27\x24\x1F\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x26\x24\x1E\xFF\x26\x25\x20" + "\xFF\x27\x25\x1E\xFF\x28\x25\x1F\xFF" + "\x27\x24\x20\xFF\x26\x23\x1E\xFF\x25\x24\x1E\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x25\x23\x1E\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x97" + "\xFF\x55\xC7\x93\xFF\x3B\x70\x56\xFF" + "\x2E\x3B\x2F\xFF\x36\x59\x44\xFF\x4E\xAE\x81\xFF\x57\xCC\x97\xFF\x57\xCD\x98\xFF\x56\xCC\x97" + "\xFF\x55\xC9\x94\xFF\x54\xC4\x91\xFF" + "\x56\xCB\x96\xFF\x56\xCA\x96\xFF\x43\x8A\x69\xFF\x2E\x41\x33\xFF\x31\x4C\x3A\xFF\x4A\xA1\x79" + "\xFF\x56\xCC\x97\xFF\x57\xCD\x97\xFF" + "\x4E\xB0\x81\xFF\x2F\x45\x37\xFF\x28\x2B\x24\xFF\x25\x23\x1E\xFF\x27\x25\x20\xFF\x27\x25\x20" + "\xFF\x28\x26\x20\xFF\x27\x24\x20\xFF" + "\x26\x23\x1E\xFF\x27\x25\x20\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x25\x1F" + "\xFF\x26\x24\x1E\xFF\x26\x23\x1E\xFF" + "\x28\x26\x21\xFF\x25\x25\x1E\xFF\x26\x23\x1E\xFF\x26\x24\x20\xFF\x27\x24\x1F\xFF\x27\x24\x20" + "\xFF\x26\x23\x1F\xFF\x27\x24\x1F\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98" + "\xFF\x4E\xAF\x82\xFF\x32\x50\x3E\xFF" + "\x2F\x42\x35\xFF\x45\x90\x6C\xFF\x56\xCA\x96\xFF\x57\xCD\x98\xFF\x56\xCB\x96\xFF\x4E\xB0\x82" + "\xFF\x42\x84\x63\xFF\x3D\x74\x57\xFF" + "\x44\x8B\x69\xFF\x50\xB7\x88\xFF\x53\xC0\x8F\xFF\x36\x64\x4C\xFF\x2D\x3C\x2F\xFF\x3E\x76\x59" + "\xFF\x54\xC7\x92\xFF\x57\xCD\x97\xFF" + "\x54\xC3\x91\xFF\x3D\x74\x58\xFF\x2A\x31\x28\xFF\x27\x26\x1F\xFF\x27\x25\x20\xFF\x26\x25\x1F" + "\xFF\x27\x26\x20\xFF\x27\x26\x20\xFF" + "\x27\x24\x1F\xFF\x27\x25\x1F\xFF\x27\x25\x1F\xFF\x26\x25\x20\xFF\x27\x24\x1F\xFF\x27\x26\x1F" + "\xFF\x27\x26\x1F\xFF\x23\x23\x1D\xFF" + "\x25\x23\x1E\xFF\x27\x26\x1F\xFF\x27\x24\x1E\xFF\x29\x26\x20\xFF\x26\x25\x1F\xFF\x26\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x98" + "\xFF\x49\x98\x72\xFF\x2E\x44\x36\xFF" + "\x33\x51\x3F\xFF\x4F\xB4\x86\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x53\xC0\x8F\xFF\x3D\x73\x57" + "\xFF\x2F\x3E\x32\xFF\x2C\x38\x2C\xFF" + "\x2F\x42\x35\xFF\x41\x83\x62\xFF\x55\xC8\x94\xFF\x43\x8F\x6A\xFF\x2E\x3A\x2F\xFF\x39\x66\x4E" + "\xFF\x52\xBB\x8B\xFF\x56\xCD\x97\xFF" + "\x56\xCB\x97\xFF\x48\x9C\x75\xFF\x2E\x42\x34\xFF\x28\x29\x22\xFF\x28\x27\x21\xFF\x28\x26\x1F" + "\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF" + "\x28\x26\x20\xFF\x2A\x27\x21\xFF\x27\x26\x20\xFF\x25\x23\x1E\xFF\x29\x26\x21\xFF\x29\x28\x22" + "\xFF\x26\x25\x1F\xFF\x25\x22\x1D\xFF" + "\x27\x24\x1F\xFF\x28\x25\x1F\xFF\x27\x24\x1E\xFF\x27\x26\x1F\xFF\x27\x25\x1F\xFF\x26\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCD\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCD\x97\xFF\x57\xCD\x98" + "\xFF\x41\x80\x61\xFF\x2B\x39\x2E\xFF" + "\x33\x58\x44\xFF\x54\xC7\x93\xFF\x56\xCD\x98\xFF\x56\xCC\x97\xFF\x55\xC9\x94\xFF\x46\x96\x70" + "\xFF\x34\x5B\x46\xFF\x32\x51\x3E\xFF" + "\x38\x67\x4D\xFF\x49\xA3\x79\xFF\x56\xCD\x97\xFF\x4C\xAC\x80\xFF\x2F\x3D\x31\xFF\x36\x58\x44" + "\xFF\x4E\xAF\x82\xFF\x56\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x52\xBF\x8E\xFF\x39\x69\x50\xFF\x2A\x30\x26\xFF\x26\x25\x1F\xFF\x26\x23\x1E" + "\xFF\x27\x25\x1E\xFF\x28\x25\x20\xFF" + "\x28\x26\x21\xFF\x28\x25\x20\xFF\x26\x25\x1E\xFF\x27\x25\x1F\xFF\x28\x26\x21\xFF\x28\x26\x20" + "\xFF\x28\x26\x1F\xFF\x25\x24\x1D\xFF" + "\x25\x24\x1E\xFF\x25\x25\x1F\xFF\x24\x23\x1D\xFF\x26\x24\x1F\xFF\x25\x22\x1D\xFF\x23\x23\x1D" + "\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCC\x98\xFF\x56\xCC\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98" + "\xFF\x44\x8C\x69\xFF\x2D\x40\x31\xFF" + "\x33\x55\x41\xFF\x52\xBE\x8D\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x55\xC9\x95" + "\xFF\x50\xBA\x8A\xFF\x4D\xAD\x80\xFF" + "\x52\xC0\x8D\xFF\x56\xCC\x97\xFF\x57\xCD\x97\xFF\x4A\xA5\x7A\xFF\x2E\x3B\x2F\xFF\x36\x5A\x45" + "\xFF\x4F\xB1\x83\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x42\x8A\x68\xFF\x2B\x3B\x2E\xFF\x28\x28\x20\xFF\x27\x24\x1E" + "\xFF\x28\x25\x1F\xFF\x28\x25\x1F\xFF" + "\x24\x23\x1E\xFF\x25\x24\x1E\xFF\x27\x25\x1F\xFF\x28\x26\x20\xFF\x26\x25\x1F\xFF\x27\x26\x1F" + "\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF" + "\x27\x25\x1F\xFF\x26\x24\x1E\xFF\x25\x24\x1D\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x97" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x99\xFF\x56\xCD\x97\xFF\x56\xCD\x98" + "\xFF\x49\x9E\x77\xFF\x31\x47\x38\xFF" + "\x2F\x4A\x39\xFF\x4B\xA9\x7E\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x58\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x57\xCE\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x40\x80\x61\xFF\x2E\x3B\x2F\xFF\x38\x6A\x50" + "\xFF\x52\xBF\x8E\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x4D\xAC\x80\xFF\x2F\x4B\x3A\xFF\x28\x2A\x21\xFF\x27\x26\x1F" + "\xFF\x28\x25\x1F\xFF\x29\x26\x21\xFF" + "\x26\x23\x1F\xFF\x27\x26\x20\xFF\x27\x25\x1F\xFF\x27\x25\x20\xFF\x26\x23\x1E\xFF\x27\x24\x1F" + "\xFF\x28\x25\x1F\xFF\x28\x25\x20\xFF" + "\x27\x25\x20\xFF\x26\x25\x1F\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x26\x24\x1E\xFF\x24\x23\x1D" + "\xFF\x27\x24\x1F\xFF\x24\x22\x1D\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCA\x96\xFF\x53\xC1\x8F" + "\xFF\x57\xC7\x94\xFF\x57\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x97\xFF\x56\xCC\x97\xFF\x56\xCD\x97" + "\xFF\x51\xBA\x89\xFF\x37\x5E\x47\xFF" + "\x2D\x39\x2E\xFF\x39\x6B\x52\xFF\x52\xBE\x8D\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCB\x97\xFF\x4C\xA8\x7C\xFF\x31\x4D\x3B\xFF\x2F\x3F\x31\xFF\x41\x86\x65" + "\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF" + "\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xC9\x96\xFF\x39\x63\x4D\xFF\x27\x2D\x26\xFF\x26\x27\x1F" + "\xFF\x27\x26\x20\xFF\x24\x23\x1D\xFF" + "\x24\x22\x1D\xFF\x26\x24\x1D\xFF\x27\x26\x20\xFF\x27\x25\x20\xFF\x27\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x26\x23\x1F\xFF\x25\x23\x1E\xFF" + "\x25\x24\x1F\xFF\x26\x23\x1E\xFF\x28\x26\x20\xFF\x28\x26\x21\xFF\x27\x24\x1F\xFF\x27\x25\x1F" + "\xFF\x26\x23\x1E\xFF\x27\x24\x20\xFF" + "\x4F\xBA\x8A\xFF\x50\xBD\x8C\xFF\x51\xC0\x8F\xFF\x52\xC2\x90\xFF\x53\xC4\x92\xFF\x54\xC6\x93" + "\xFF\x54\xC8\x94\xFF\x55\xC8\x95\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x55\xC8\x94\xFF\x49\x9E\x76" + "\xFF\x43\x8B\x68\xFF\x50\xB5\x87\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCD\x97\xFF\x48\x9A\x72\xFF" + "\x2C\x3B\x2F\xFF\x30\x42\x34\xFF\x3F\x7C\x5D\xFF\x51\xBB\x8B\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x56\xC9\x95\xFF\x4C\xA9\x7D\xFF\x37\x5F\x49\xFF\x2C\x3A\x2E\xFF\x36\x5D\x47\xFF\x50\xB4\x86" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCC\x99\xFF\x57\xCC\x98\xFF\x57\xCD\x98\xFF\x44\x8C\x69\xFF\x29\x30\x27\xFF\x27\x27\x20" + "\xFF\x27\x26\x1F\xFF\x25\x23\x1E\xFF" + "\x23\x22\x1C\xFF\x26\x23\x1E\xFF\x27\x25\x20\xFF\x27\x25\x20\xFF\x26\x23\x1E\xFF\x26\x23\x1E" + "\xFF\x27\x25\x1F\xFF\x26\x23\x1D\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1E\xFF\x26\x25\x1F\xFF\x25\x23\x1E\xFF\x28\x25\x20\xFF\x27\x25\x20" + "\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC4\x92\xFF\x54\xC6\x93" + "\xFF\x54\xC8\x94\xFF\x55\xC9\x95\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x4C\xAA\x7F" + "\xFF\x35\x5E\x49\xFF\x35\x59\x45\xFF" + "\x46\x99\x72\xFF\x55\xC8\x94\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x55\xC8\x94\xFF" + "\x3B\x6C\x51\xFF\x2C\x3A\x2E\xFF\x2E\x3F\x31\xFF\x38\x5F\x49\xFF\x46\x94\x6F\xFF\x4E\xB1\x83" + "\xFF\x50\xB9\x88\xFF\x4C\xAA\x7F\xFF" + "\x41\x80\x61\xFF\x32\x50\x3E\xFF\x2C\x3A\x2E\xFF\x2B\x40\x32\xFF\x4B\xA7\x7C\xFF\x57\xCC\x97" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x4F\xB6\x86\xFF\x2D\x38\x2D\xFF\x29\x2A\x23" + "\xFF\x27\x25\x1F\xFF\x26\x23\x1E\xFF" + "\x26\x24\x1F\xFF\x27\x26\x20\xFF\x29\x26\x21\xFF\x27\x25\x20\xFF\x28\x26\x1F\xFF\x26\x24\x1F" + "\xFF\x25\x23\x1E\xFF\x25\x22\x1D\xFF" + "\x25\x24\x1E\xFF\x25\x24\x1E\xFF\x25\x24\x1F\xFF\x24\x23\x1D\xFF\x25\x24\x1E\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF" + "\x4F\xBB\x8A\xFF\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x54\xC8\x94\xFF\x55\xC9\x95\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x55\xC7\x94" + "\xFF\x40\x7B\x5D\xFF\x2C\x3B\x2E\xFF" + "\x2B\x37\x2C\xFF\x35\x5B\x46\xFF\x48\x9E\x76\xFF\x52\xBF\x8D\xFF\x56\xCC\x97\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x54\xC4\x91\xFF\x44\x89\x67\xFF\x31\x4D\x3C\xFF\x29\x37\x2C\xFF\x2C\x39\x2D\xFF\x2C\x3A\x2E" + "\xFF\x2D\x3C\x2E\xFF\x2C\x3B\x2E\xFF" + "\x2C\x39\x2D\xFF\x2E\x41\x32\xFF\x38\x60\x4B\xFF\x4B\xA2\x79\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x97\xFF\x57\xCC\x97\xFF\x33\x52\x3F\xFF\x28\x2C\x23" + "\xFF\x28\x27\x1F\xFF\x27\x24\x1F\xFF" + "\x23\x22\x1D\xFF\x26\x25\x1F\xFF\x27\x24\x1F\xFF\x24\x23\x1E\xFF\x27\x24\x1F\xFF\x27\x25\x1F" + "\xFF\x26\x25\x1F\xFF\x26\x24\x1F\xFF" + "\x25\x22\x1D\xFF\x27\x24\x1F\xFF\x27\x26\x21\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF\x26\x23\x1F" + "\xFF\x26\x23\x1F\xFF\x27\x24\x1F\xFF" + "\x4F\xBC\x8B\xFF\x51\xBF\x8D\xFF\x52\xC1\x8F\xFF\x53\xC4\x91\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x54\xC8\x94\xFF\x55\xC9\x95\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x4A\xA4\x7A\xFF\x30\x4B\x39\xFF" + "\x2A\x30\x28\xFF\x2A\x32\x28\xFF\x2E\x40\x32\xFF\x38\x67\x4E\xFF\x48\x9B\x74\xFF\x53\xC0\x8F" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x55\xC8\x94\xFF\x4A\xA5\x7A\xFF\x3F\x7D\x5E\xFF\x37\x62\x4C\xFF\x31\x4C\x3A" + "\xFF\x31\x49\x39\xFF\x35\x57\x42\xFF" + "\x3A\x6B\x52\xFF\x44\x8D\x6A\xFF\x50\xBB\x8B\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x56\xCD\x98" + "\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCA\x96\xFF\x4F\xAC\x80\xFF\x2F\x4A\x39\xFF\x28\x2A\x23" + "\xFF\x27\x25\x20\xFF\x27\x25\x1F\xFF" + "\x25\x23\x1E\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x27\x25\x1F\xFF\x29\x26\x21\xFF\x28\x26\x20" + "\xFF\x27\x24\x1F\xFF\x27\x25\x1F\xFF" + "\x28\x25\x20\xFF\x26\x25\x1F\xFF\x25\x24\x1F\xFF\x27\x25\x1F\xFF\x26\x23\x1E\xFF\x28\x25\x20" + "\xFF\x27\x25\x1F\xFF\x26\x25\x20\xFF" + "\x50\xBC\x8C\xFF\x51\xBF\x8D\xFF\x52\xC1\x8F\xFF\x53\xC4\x91\xFF\x53\xC5\x92\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x54\xC6\x93\xFF\x41\x82\x62\xFF" + "\x2D\x3C\x30\xFF\x2B\x34\x29\xFF\x29\x2F\x26\xFF\x27\x30\x27\xFF\x2F\x42\x34\xFF\x38\x63\x4C" + "\xFF\x48\x98\x72\xFF\x55\xC6\x93\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x55\xC7\x94\xFF\x52\xBC\x8C\xFF\x4F\xB2\x84" + "\xFF\x4E\xB0\x83\xFF\x53\xB7\x88\xFF" + "\x53\xC0\x8E\xFF\x55\xC9\x95\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98" + "\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCD\x97\xFF\x52\xBC\x8C\xFF\x40\x81\x62\xFF\x32\x4E\x3D\xFF\x29\x2C\x25\xFF\x29\x27\x21" + "\xFF\x29\x27\x20\xFF\x27\x25\x1F\xFF" + "\x25\x23\x1E\xFF\x26\x24\x1F\xFF\x26\x26\x20\xFF\x26\x25\x20\xFF\x26\x25\x1F\xFF\x28\x26\x20" + "\xFF\x27\x25\x20\xFF\x29\x26\x20\xFF" + "\x27\x25\x1F\xFF\x28\x25\x20\xFF\x25\x23\x1E\xFF\x26\x24\x1E\xFF\x26\x25\x20\xFF\x27\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x27\x25\x1F\xFF" + "\x50\xBD\x8C\xFF\x51\xC0\x8E\xFF\x52\xC2\x90\xFF\x53\xC4\x91\xFF\x54\xC6\x93\xFF\x54\xC7\x93" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCD\x97\xFF\x56\xCC\x97\xFF" + "\x52\xBA\x8B\xFF\x42\x85\x64\xFF\x36\x59\x46\xFF\x2F\x40\x33\xFF\x2B\x31\x28\xFF\x2B\x31\x27" + "\xFF\x2C\x36\x2B\xFF\x31\x4B\x3A\xFF" + "\x41\x82\x61\xFF\x4C\xA8\x7E\xFF\x52\xBC\x8C\xFF\x55\xC9\x95\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x97" + "\xFF\x54\xC8\x93\xFF\x51\xB8\x89\xFF" + "\x3F\x82\x62\xFF\x2F\x47\x38\xFF\x2A\x34\x29\xFF\x26\x2B\x22\xFF\x27\x27\x21\xFF\x26\x25\x1F" + "\xFF\x26\x26\x1F\xFF\x26\x25\x1E\xFF" + "\x27\x24\x20\xFF\x27\x24\x20\xFF\x28\x26\x20\xFF\x28\x26\x21\xFF\x26\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x28\x25\x20\xFF\x26\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x27\x25\x20\xFF\x26\x25\x1F\xFF\x28\x27\x20\xFF\x27\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x28\x26\x1F\xFF" + "\x50\xBE\x8D\xFF\x51\xC0\x8F\xFF\x52\xC3\x90\xFF\x53\xC4\x92\xFF\x54\xC6\x93\xFF\x54\xC8\x94" + "\xFF\x55\xC8\x95\xFF\x55\xC9\x95\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCB\x96\xFF\x50\xBA\x8A\xFF\x46\x94\x6F\xFF\x38\x64\x4B\xFF\x2D\x3F\x32" + "\xFF\x29\x33\x29\xFF\x29\x32\x27\xFF" + "\x2A\x35\x29\xFF\x30\x43\x34\xFF\x38\x61\x4A\xFF\x40\x81\x61\xFF\x49\x9F\x78\xFF\x4E\xB0\x83" + "\xFF\x52\xC0\x8E\xFF\x56\xCB\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xC9\x95\xFF\x4F\xB7\x86\xFF\x48\x9B\x74" + "\xFF\x3F\x7E\x5F\xFF\x35\x5A\x44\xFF" + "\x2A\x36\x2B\xFF\x2B\x34\x2A\xFF\x2B\x37\x2C\xFF\x2D\x3D\x30\xFF\x28\x29\x21\xFF\x25\x25\x1E" + "\xFF\x26\x25\x20\xFF\x26\x26\x1E\xFF" + "\x27\x24\x1F\xFF\x27\x25\x1F\xFF\x27\x24\x1F\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x24\x23\x1D" + "\xFF\x28\x24\x1F\xFF\x25\x22\x1E\xFF" + "\x25\x22\x1E\xFF\x24\x25\x1F\xFF\x27\x25\x20\xFF\x29\x27\x21\xFF\x26\x23\x1E\xFF\x28\x25\x20" + "\xFF\x28\x25\x20\xFF\x26\x25\x1E\xFF" + "\x51\xBF\x8D\xFF\x52\xC1\x8F\xFF\x52\xC3\x90\xFF\x53\xC5\x92\xFF\x54\xC6\x93\xFF\x54\xC8\x94" + "\xFF\x55\xC8\x95\xFF\x55\xCA\x96\xFF" + "\x55\xCA\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x51\xBD\x8C\xFF\x49\xA2\x79" + "\xFF\x3D\x72\x57\xFF\x31\x47\x37\xFF" + "\x2D\x36\x2C\xFF\x2B\x34\x29\xFF\x2A\x33\x28\xFF\x29\x34\x29\xFF\x2F\x43\x35\xFF\x31\x4D\x3C" + "\xFF\x35\x5A\x45\xFF\x3A\x67\x50\xFF" + "\x3D\x73\x57\xFF\x3B\x6B\x52\xFF\x39\x66\x4D\xFF\x37\x61\x4A\xFF\x33\x53\x3F\xFF\x2E\x42\x34" + "\xFF\x29\x35\x2A\xFF\x2A\x34\x2A\xFF" + "\x2B\x3B\x2F\xFF\x37\x5F\x49\xFF\x46\x95\x6F\xFF\x47\x97\x70\xFF\x28\x2E\x25\xFF\x25\x25\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x25\x1F\xFF" + "\x28\x25\x20\xFF\x26\x25\x1F\xFF\x25\x24\x1E\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x26\x24\x1F" + "\xFF\x28\x25\x20\xFF\x25\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x24\x24\x1E\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x25\x22\x1D\xFF\x28\x25\x1F" + "\xFF\x26\x25\x1F\xFF\x25\x25\x1F\xFF" + "\x51\xC0\x8E\xFF\x52\xC2\x90\xFF\x53\xC4\x91\xFF\x53\xC5\x92\xFF\x54\xC7\x93\xFF\x54\xC8\x94" + "\xFF\x55\xC9\x95\xFF\x55\xCA\x96\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCD\x98\xFF\x57\xCC\x97" + "\xFF\x57\xCD\x98\xFF\x54\xC7\x94\xFF" + "\x4A\x9E\x77\xFF\x3E\x75\x58\xFF\x35\x57\x42\xFF\x2E\x40\x32\xFF\x28\x33\x28\xFF\x29\x33\x28" + "\xFF\x28\x32\x27\xFF\x29\x32\x28\xFF" + "\x29\x31\x27\xFF\x2A\x32\x2A\xFF\x2C\x34\x2A\xFF\x2B\x34\x2A\xFF\x2B\x37\x2C\xFF\x2F\x42\x35" + "\xFF\x35\x55\x42\xFF\x3E\x74\x58\xFF" + "\x4E\xB2\x85\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x45\x90\x6B\xFF\x2B\x32\x28\xFF\x25\x25\x20" + "\xFF\x27\x24\x20\xFF\x29\x25\x20\xFF" + "\x25\x23\x1E\xFF\x26\x24\x1F\xFF\x27\x26\x1F\xFF\x25\x23\x1D\xFF\x25\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x26\x25\x1F\xFF\x27\x24\x1F\xFF" + "\x26\x24\x1F\xFF\x22\x21\x1C\xFF\x25\x21\x1D\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF\x27\x25\x1F" + "\xFF\x25\x25\x1F\xFF\x27\x26\x20\xFF" + "\x51\xC0\x8F\xFF\x52\xC2\x90\xFF\x53\xC4\x92\xFF\x54\xC6\x93\xFF\x54\xC7\x93\xFF\x55\xC8\x95" + "\xFF\x55\xC9\x95\xFF\x55\xCA\x96\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCA\x96\xFF\x50\xB8\x89\xFF\x48\x9C\x74\xFF\x41\x83\x62\xFF\x3E\x76\x59" + "\xFF\x38\x66\x4D\xFF\x34\x56\x42\xFF" + "\x31\x4A\x38\xFF\x33\x51\x3F\xFF\x38\x5E\x48\xFF\x3B\x6B\x51\xFF\x41\x83\x62\xFF\x48\x9B\x74" + "\xFF\x4F\xB5\x86\xFF\x55\xC9\x95\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x55\xC5\x92\xFF\x38\x66\x4E\xFF\x2A\x2E\x26\xFF\x28\x26\x21" + "\xFF\x28\x25\x20\xFF\x27\x25\x1F\xFF" + "\x25\x25\x1E\xFF\x26\x25\x1F\xFF\x26\x25\x20\xFF\x22\x23\x1D\xFF\x27\x25\x20\xFF\x27\x25\x20" + "\xFF\x27\x25\x1F\xFF\x26\x24\x1F\xFF" + "\x25\x23\x1D\xFF\x25\x22\x1D\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF\x27\x26\x20\xFF\x27\x27\x1F" + "\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF" + "\x52\xC1\x8F\xFF\x52\xC3\x90\xFF\x53\xC4\x92\xFF\x54\xC6\x93\xFF\x54\xC8\x94\xFF\x55\xC8\x95" + "\xFF\x55\xC9\x95\xFF\x55\xCA\x96\xFF" + "\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCB\x96\xFF\x54\xC5\x92" + "\xFF\x52\xBE\x8D\xFF\x51\xB7\x88\xFF" + "\x4F\xB2\x84\xFF\x4F\xB5\x87\xFF\x52\xBB\x8B\xFF\x53\xC1\x8F\xFF\x55\xCA\x95\xFF\x56\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x49\x9C\x75\xFF\x2F\x44\x35\xFF\x26\x27\x23\xFF\x26\x25\x1E" + "\xFF\x29\x26\x20\xFF\x26\x26\x1E\xFF" + "\x26\x22\x1D\xFF\x26\x23\x1F\xFF\x27\x25\x20\xFF\x27\x24\x20\xFF\x27\x24\x1F\xFF\x25\x23\x1D" + "\xFF\x26\x25\x1E\xFF\x28\x25\x20\xFF" + "\x26\x24\x1D\xFF\x27\x24\x1F\xFF\x27\x25\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x27\x25\x1E" + "\xFF\x27\x25\x1F\xFF\x27\x24\x1F\xFF" + "\x52\xC2\x90\xFF\x53\xC4\x91\xFF\x53\xC5\x92\xFF\x54\xC7\x93\xFF\x54\xC8\x94\xFF\x55\xC9\x95" + "\xFF\x55\xCA\x96\xFF\x55\xCA\x96\xFF" + "\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF" + "\x51\xBC\x8B\xFF\x43\x8C\x69\xFF\x30\x48\x39\xFF\x2A\x2D\x27\xFF\x24\x25\x20\xFF\x24\x24\x1E" + "\xFF\x25\x24\x1E\xFF\x25\x22\x1D\xFF" + "\x27\x25\x1F\xFF\x28\x26\x20\xFF\x25\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x25\x1F\xFF\x27\x24\x1F" + "\xFF\x28\x25\x1F\xFF\x25\x24\x1E\xFF" + "\x25\x22\x1D\xFF\x27\x25\x1F\xFF\x27\x26\x20\xFF\x26\x24\x1E\xFF\x27\x25\x20\xFF\x27\x24\x1F" + "\xFF\x29\x26\x21\xFF\x26\x26\x20\xFF" + "\x52\xC3\x90\xFF\x53\xC4\x92\xFF\x54\xC6\x93\xFF\x54\xC8\x94\xFF\x55\xC8\x95\xFF\x55\xC9\x95" + "\xFF\x55\xCA\x96\xFF\x56\xCB\x96\xFF" + "\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x52\xBE\x8D\xFF\x48\x9A\x73\xFF" + "\x38\x63\x4D\xFF\x2C\x39\x2E\xFF\x27\x2B\x24\xFF\x27\x26\x21\xFF\x25\x23\x1E\xFF\x25\x24\x1E" + "\xFF\x25\x24\x1D\xFF\x25\x26\x1D\xFF" + "\x25\x24\x1F\xFF\x27\x25\x1E\xFF\x26\x25\x1E\xFF\x26\x23\x1E\xFF\x25\x23\x1E\xFF\x26\x25\x20" + "\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF" + "\x27\x25\x1F\xFF\x26\x25\x1E\xFF\x25\x24\x1D\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x27\x24\x20" + "\xFF\x25\x23\x1E\xFF\x26\x24\x1F\xFF" + "\x53\xC4\x91\xFF\x53\xC5\x92\xFF\x54\xC7\x93\xFF\x54\xC8\x94\xFF\x55\xC8\x95\xFF\x55\xC9\x95" + "\xFF\x55\xCA\x96\xFF\x56\xCB\x96\xFF" + "\x56\xCB\x96\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x58\xCC\x99\xFF\x57\xCD\x98\xFF\x57\xCD\x99\xFF\x57\xCD\x98\xFF\x52\xBE\x8D\xFF\x43\x8C\x68" + "\xFF\x35\x5D\x47\xFF\x2E\x40\x32\xFF" + "\x27\x2C\x26\xFF\x28\x2A\x23\xFF\x29\x29\x22\xFF\x27\x26\x20\xFF\x23\x22\x1C\xFF\x25\x23\x1D" + "\xFF\x26\x24\x1E\xFF\x27\x25\x20\xFF" + "\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x27\x26\x1E\xFF\x28\x25\x20\xFF\x26\x24\x1D\xFF\x25\x23\x1E" + "\xFF\x26\x23\x1E\xFF\x24\x23\x1E\xFF" + "\x25\x22\x1C\xFF\x25\x23\x1E\xFF\x25\x23\x1D\xFF\x25\x24\x1E\xFF\x26\x23\x1F\xFF\x28\x25\x20" + "\xFF\x27\x24\x1E\xFF\x27\x24\x1E\xFF" + "\x53\xC4\x92\xFF\x54\xC6\x93\xFF\x54\xC7\x92\xFF\x55\xC8\x94\xFF\x55\xC9\x95\xFF\x54\xC9\x95" + "\xFF\x54\xC9\x95\xFF\x55\xCA\x95\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x56\xCD\x99\xFF\x56\xCD\x97" + "\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCE\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x99\xFF" + "\x56\xCD\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x58\xCD\x98\xFF\x56\xCD\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCC\x97\xFF\x54\xC7\x93\xFF" + "\x51\xBC\x8B\xFF\x4E\xAF\x83\xFF\x46\x92\x6D\xFF\x39\x67\x4E\xFF\x2D\x3B\x30\xFF\x2B\x32\x29" + "\xFF\x29\x2D\x24\xFF\x28\x28\x22\xFF" + "\x27\x26\x20\xFF\x27\x25\x1F\xFF\x28\x26\x20\xFF\x28\x25\x20\xFF\x26\x25\x1F\xFF\x26\x26\x1F" + "\xFF\x26\x25\x1E\xFF\x28\x25\x20\xFF" + "\x2A\x27\x22\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x26\x23\x1C\xFF\x26\x23\x1E" + "\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF" + "\x26\x24\x1F\xFF\x28\x25\x1F\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x25\x23\x1E\xFF\x28\x25\x20" + "\xFF\x29\x26\x21\xFF\x25\x24\x1E\xFF" + "\x53\xC5\x92\xFF\x54\xC7\x93\xFF\x53\xC8\x93\xFF\x54\xC8\x94\xFF\x55\xC8\x94\xFF\x52\xBD\x8C" + "\xFF\x4C\xAD\x80\xFF\x4B\xA7\x7D\xFF" + "\x48\xA1\x77\xFF\x48\xA0\x77\xFF\x4B\xA7\x7D\xFF\x4F\xB0\x83\xFF\x51\xB9\x8A\xFF\x52\xC0\x8E" + "\xFF\x55\xC6\x92\xFF\x56\xCB\x96\xFF" + "\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x56\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x56\xCB\x97\xFF\x54\xC4\x91\xFF\x50\xBA\x8B\xFF\x4E\xAF\x81\xFF\x49\x9F\x77" + "\xFF\x43\x8B\x68\xFF\x3F\x78\x5B\xFF" + "\x37\x61\x4A\xFF\x30\x48\x38\xFF\x2A\x35\x2B\xFF\x2A\x30\x27\xFF\x28\x2B\x22\xFF\x27\x27\x20" + "\xFF\x28\x26\x20\xFF\x28\x25\x20\xFF" + "\x27\x24\x1F\xFF\x25\x24\x1D\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x27\x26\x20\xFF" + "\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x27\x24\x20\xFF\x28\x27\x20\xFF\x27\x24\x1F\xFF\x26\x23\x1E" + "\xFF\x26\x24\x1F\xFF\x27\x24\x20\xFF" + "\x26\x24\x1E\xFF\x27\x24\x1E\xFF\x25\x22\x1D\xFF\x26\x24\x1E\xFF\x26\x25\x1F\xFF\x27\x25\x1F" + "\xFF\x27\x26\x1F\xFF\x26\x24\x1E\xFF" + "\x54\xC6\x92\xFF\x54\xC8\x94\xFF\x54\xC8\x94\xFF\x54\xC8\x94\xFF\x44\x8C\x69\xFF\x37\x5E\x49" + "\xFF\x32\x4D\x3C\xFF\x31\x49\x38\xFF" + "\x2D\x42\x33\xFF\x2D\x44\x33\xFF\x2E\x47\x37\xFF\x32\x4E\x3C\xFF\x35\x54\x42\xFF\x34\x58\x43" + "\xFF\x34\x5C\x45\xFF\x38\x63\x4C\xFF" + "\x3C\x6F\x55\xFF\x40\x7B\x5C\xFF\x43\x87\x65\xFF\x45\x91\x6D\xFF\x44\x8E\x6B\xFF\x43\x8A\x68" + "\xFF\x43\x86\x65\xFF\x41\x81\x61\xFF" + "\x3D\x75\x59\xFF\x38\x67\x4E\xFF\x36\x5C\x47\xFF\x33\x55\x42\xFF\x33\x4E\x3C\xFF\x2F\x41\x34" + "\xFF\x2A\x34\x2A\xFF\x2B\x31\x27\xFF" + "\x27\x2C\x23\xFF\x29\x2B\x23\xFF\x28\x29\x22\xFF\x26\x25\x20\xFF\x29\x28\x22\xFF\x27\x26\x20" + "\xFF\x27\x25\x20\xFF\x27\x24\x20\xFF" + "\x29\x26\x21\xFF\x27\x25\x1F\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF\x25\x25\x1F" + "\xFF\x26\x25\x1E\xFF\x28\x26\x21\xFF" + "\x27\x25\x20\xFF\x25\x25\x1E\xFF\x25\x24\x1F\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF\x26\x24\x1F" + "\xFF\x26\x24\x20\xFF\x25\x24\x1F\xFF" + "\x26\x25\x1F\xFF\x26\x23\x1E\xFF\x23\x21\x1C\xFF\x25\x23\x1C\xFF\x28\x25\x20\xFF\x26\x25\x1F" + "\xFF\x28\x27\x1F\xFF\x27\x25\x1F\xFF" + "\x53\xC7\x92\xFF\x53\xC8\x94\xFF\x53\xC3\x91\xFF\x3E\x7B\x5D\xFF\x2B\x35\x2D\xFF\x25\x2B\x22" + "\xFF\x23\x26\x1E\xFF\x25\x26\x20\xFF" + "\x24\x24\x1E\xFF\x27\x27\x1F\xFF\x28\x28\x22\xFF\x28\x29\x23\xFF\x27\x29\x23\xFF\x27\x29\x23" + "\xFF\x2A\x2C\x25\xFF\x2A\x2D\x25\xFF" + "\x27\x2D\x25\xFF\x27\x2D\x25\xFF\x27\x2D\x24\xFF\x29\x30\x27\xFF\x29\x2F\x28\xFF\x28\x2F\x26" + "\xFF\x29\x30\x27\xFF\x29\x2F\x26\xFF" + "\x28\x2C\x23\xFF\x2A\x2D\x24\xFF\x29\x2B\x23\xFF\x28\x29\x22\xFF\x27\x27\x21\xFF\x26\x26\x21" + "\xFF\x27\x26\x1F\xFF\x29\x26\x21\xFF" + "\x26\x26\x20\xFF\x26\x24\x1F\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x26\x24\x1E\xFF\x26\x25\x1F\xFF" + "\x28\x25\x20\xFF\x28\x25\x20\xFF\x29\x27\x21\xFF\x29\x26\x21\xFF\x27\x24\x20\xFF\x25\x24\x1F" + "\xFF\x25\x24\x1F\xFF\x28\x25\x21\xFF" + "\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x29\x26\x20\xFF\x26\x25\x20\xFF\x29\x26\x21\xFF\x26\x23\x1F" + "\xFF\x27\x26\x20\xFF\x27\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x26\x25\x1F\xFF\x25\x22\x1D\xFF\x25\x23\x1F" + "\xFF\x26\x25\x20\xFF\x26\x25\x1F\xFF" + "\x53\xC8\x94\xFF\x54\xC8\x95\xFF\x49\xA4\x7A\xFF\x30\x49\x39\xFF\x26\x29\x23\xFF\x24\x25\x1F" + "\xFF\x23\x22\x1D\xFF\x25\x22\x1D\xFF" + "\x25\x24\x1D\xFF\x28\x25\x1F\xFF\x28\x26\x20\xFF\x26\x25\x1F\xFF\x25\x24\x1F\xFF\x27\x25\x20" + "\xFF\x27\x25\x20\xFF\x25\x24\x1F\xFF" + "\x26\x25\x1E\xFF\x28\x26\x20\xFF\x28\x27\x20\xFF\x26\x25\x1F\xFF\x27\x26\x20\xFF\x28\x26\x21" + "\xFF\x27\x26\x20\xFF\x26\x25\x20\xFF" + "\x27\x25\x20\xFF\x26\x25\x1F\xFF\x26\x26\x20\xFF\x27\x26\x1F\xFF\x25\x25\x20\xFF\x24\x23\x1D" + "\xFF\x25\x24\x1D\xFF\x27\x25\x1F\xFF" + "\x25\x25\x1E\xFF\x26\x23\x1F\xFF\x27\x25\x1F\xFF\x27\x26\x21\xFF\x29\x27\x22\xFF\x27\x25\x20" + "\xFF\x26\x24\x1D\xFF\x26\x25\x1E\xFF" + "\x27\x26\x20\xFF\x2A\x27\x21\xFF\x29\x27\x21\xFF\x27\x25\x1F\xFF\x25\x22\x1F\xFF\x24\x22\x1D" + "\xFF\x25\x23\x1D\xFF\x28\x26\x21\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x26\x24\x1F" + "\xFF\x27\x26\x20\xFF\x26\x25\x1F\xFF" + "\x26\x23\x1F\xFF\x28\x25\x21\xFF\x28\x25\x20\xFF\x26\x25\x1E\xFF\x26\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x26\x26\x1F\xFF\x26\x24\x1F\xFF" + "\x55\xC8\x94\xFF\x54\xC8\x94\xFF\x40\x80\x60\xFF\x29\x36\x2A\xFF\x26\x26\x20\xFF\x24\x23\x1D" + "\xFF\x24\x22\x1D\xFF\x27\x23\x1F\xFF" + "\x25\x23\x1D\xFF\x26\x24\x1F\xFF\x27\x27\x20\xFF\x29\x27\x21\xFF\x26\x24\x1F\xFF\x24\x24\x1E" + "\xFF\x26\x25\x1F\xFF\x26\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x29\x27\x20\xFF\x29\x26\x20\xFF\x25\x24\x1E\xFF\x26\x24\x1F\xFF\x28\x25\x20" + "\xFF\x28\x25\x20\xFF\x26\x24\x1D\xFF" + "\x28\x25\x20\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x25\x24\x1F\xFF\x28\x25\x1F" + "\xFF\x27\x25\x1E\xFF\x27\x24\x1F\xFF" + "\x27\x25\x1F\xFF\x27\x25\x1F\xFF\x25\x25\x1F\xFF\x25\x24\x1E\xFF\x26\x23\x1F\xFF\x27\x24\x20" + "\xFF\x27\x25\x1F\xFF\x26\x24\x1F\xFF" + "\x25\x24\x1E\xFF\x28\x25\x20\xFF\x26\x23\x1E\xFF\x24\x23\x1E\xFF\x27\x24\x1F\xFF\x25\x25\x1F" + "\xFF\x26\x24\x1F\xFF\x27\x25\x20\xFF" + "\x27\x24\x1F\xFF\x27\x25\x1F\xFF\x27\x27\x20\xFF\x28\x27\x21\xFF\x24\x24\x1E\xFF\x27\x24\x1F" + "\xFF\x27\x26\x20\xFF\x28\x26\x20\xFF" + "\x26\x24\x1F\xFF\x26\x26\x1F\xFF\x29\x27\x21\xFF\x26\x25\x1F\xFF\x25\x25\x1F\xFF\x26\x25\x1F" + "\xFF\x26\x24\x1F\xFF\x26\x26\x1D\xFF" + "\x54\xC9\x94\xFF\x52\xC1\x8E\xFF\x3A\x6C\x52\xFF\x29\x30\x26\xFF\x25\x25\x1F\xFF\x24\x22\x1D" + "\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x25\x24\x1F\xFF\x26\x25\x1F\xFF\x26\x26\x20\xFF\x27\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x27\x25\x1F\xFF\x28\x26\x20\xFF" + "\x29\x26\x22\xFF\x2A\x27\x21\xFF\x28\x26\x20\xFF\x29\x26\x20\xFF\x27\x24\x1F\xFF\x26\x24\x20" + "\xFF\x27\x25\x20\xFF\x27\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x28\x26\x20\xFF\x29\x26\x21\xFF\x28\x25\x21\xFF\x27\x25\x20" + "\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF" + "\x27\x24\x1F\xFF\x28\x26\x21\xFF\x25\x23\x1E\xFF\x23\x23\x1D\xFF\x27\x25\x20\xFF\x26\x24\x1F" + "\xFF\x28\x25\x20\xFF\x26\x25\x1E\xFF" + "\x23\x23\x1D\xFF\x25\x24\x1F\xFF\x26\x23\x1E\xFF\x26\x24\x1F\xFF\x28\x25\x1F\xFF\x26\x23\x1E" + "\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF" + "\x26\x25\x1F\xFF\x27\x25\x1F\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x24\x24\x1E\xFF\x24\x23\x1D" + "\xFF\x26\x24\x1E\xFF\x27\x25\x20\xFF" + "\x27\x26\x20\xFF\x27\x25\x1F\xFF\x28\x25\x1F\xFF\x28\x25\x1E\xFF\x27\x24\x1F\xFF\x27\x25\x20" + "\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x55\xC9\x94\xFF\x52\xBE\x8C\xFF\x38\x68\x4F\xFF\x29\x2E\x25\xFF\x24\x24\x1D\xFF\x26\x23\x1F" + "\xFF\x28\x25\x20\xFF\x26\x23\x1E\xFF" + "\x25\x23\x1D\xFF\x25\x24\x1E\xFF\x27\x24\x1E\xFF\x27\x24\x1E\xFF\x26\x24\x1F\xFF\x26\x25\x1F" + "\xFF\x27\x25\x20\xFF\x26\x26\x20\xFF" + "\x29\x27\x21\xFF\x27\x25\x20\xFF\x27\x25\x20\xFF\x27\x25\x1F\xFF\x27\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x27\x24\x20\xFF" + "\x27\x25\x1E\xFF\x26\x25\x1E\xFF\x27\x26\x20\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x27\x25\x1F" + "\xFF\x28\x26\x20\xFF\x28\x26\x20\xFF" + "\x27\x25\x20\xFF\x27\x24\x1F\xFF\x24\x22\x1D\xFF\x25\x23\x1E\xFF\x28\x26\x20\xFF\x27\x25\x20" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x26\x25\x20\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x27\x24\x1F\xFF\x25\x23\x1E" + "\xFF\x26\x23\x1E\xFF\x26\x25\x1E\xFF" + "\x28\x25\x1F\xFF\x27\x26\x20\xFF\x28\x25\x20\xFF\x27\x25\x1F\xFF\x26\x24\x1F\xFF\x25\x24\x1E" + "\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x25\x23\x1E\xFF\x26\x24\x1E\xFF\x26\x23\x1E\xFF\x26\x25\x1E\xFF\x27\x24\x1F\xFF\x28\x25\x20" + "\xFF\x26\x24\x1F\xFF\x24\x24\x1E\xFF" + "\x55\xCA\x95\xFF\x51\xBB\x8A\xFF\x38\x66\x4D\xFF\x28\x2D\x25\xFF\x24\x22\x1C\xFF\x26\x23\x1D" + "\xFF\x25\x23\x1D\xFF\x25\x24\x1E\xFF" + "\x26\x23\x1E\xFF\x25\x24\x1E\xFF\x25\x25\x1F\xFF\x27\x25\x1F\xFF\x29\x27\x20\xFF\x28\x26\x21" + "\xFF\x27\x24\x1F\xFF\x24\x23\x1D\xFF" + "\x27\x24\x1F\xFF\x28\x25\x20\xFF\x28\x27\x21\xFF\x26\x24\x1F\xFF\x23\x22\x1C\xFF\x25\x24\x1E" + "\xFF\x27\x25\x1F\xFF\x27\x24\x1F\xFF" + "\x25\x25\x1E\xFF\x28\x27\x20\xFF\x27\x25\x1F\xFF\x26\x24\x20\xFF\x29\x26\x21\xFF\x28\x26\x20" + "\xFF\x27\x26\x20\xFF\x2A\x28\x22\xFF" + "\x28\x25\x20\xFF\x28\x25\x20\xFF\x26\x25\x20\xFF\x27\x25\x20\xFF\x26\x23\x1E\xFF\x27\x25\x20" + "\xFF\x27\x26\x1F\xFF\x27\x25\x1F\xFF" + "\x28\x25\x20\xFF\x26\x24\x1E\xFF\x26\x24\x1E\xFF\x24\x21\x1C\xFF\x23\x22\x1C\xFF\x25\x23\x1E" + "\xFF\x25\x25\x1F\xFF\x27\x25\x1E\xFF" + "\x27\x26\x20\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x29\x27\x20\xFF\x27\x24\x20\xFF\x27\x26\x1F" + "\xFF\x27\x25\x1F\xFF\x29\x26\x21\xFF" + "\x25\x24\x1E\xFF\x28\x25\x20\xFF\x26\x24\x1E\xFF\x24\x24\x1E\xFF\x26\x25\x1E\xFF\x28\x25\x20" + "\xFF\x28\x25\x20\xFF\x24\x23\x1E\xFF" + "\x56\xCB\x96\xFF\x53\xC0\x8F\xFF\x39\x6A\x50\xFF\x28\x2D\x25\xFF\x28\x25\x20\xFF\x28\x25\x1F" + "\xFF\x28\x26\x1F\xFF\x27\x24\x1F\xFF" + "\x28\x25\x20\xFF\x27\x25\x20\xFF\x27\x25\x20\xFF\x27\x24\x1F\xFF\x2A\x27\x21\xFF\x2A\x27\x22" + "\xFF\x29\x26\x21\xFF\x29\x26\x21\xFF" + "\x27\x24\x1F\xFF\x27\x25\x1F\xFF\x27\x25\x1F\xFF\x26\x25\x1F\xFF\x25\x23\x1E\xFF\x26\x25\x1F" + "\xFF\x27\x25\x20\xFF\x28\x26\x1F\xFF" + "\x28\x26\x21\xFF\x26\x25\x20\xFF\x27\x25\x20\xFF\x28\x26\x21\xFF\x26\x24\x1F\xFF\x27\x26\x20" + "\xFF\x28\x25\x20\xFF\x27\x25\x1F\xFF" + "\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF\x24\x23\x1D\xFF\x26\x23\x1E" + "\xFF\x26\x25\x1F\xFF\x27\x24\x20\xFF" + "\x25\x25\x1F\xFF\x25\x23\x1E\xFF\x23\x23\x1D\xFF\x25\x22\x1D\xFF\x27\x25\x1D\xFF\x26\x25\x1E" + "\xFF\x28\x27\x20\xFF\x27\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x27\x26\x1F\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x29\x26\x21\xFF\x27\x24\x1F" + "\xFF\x27\x26\x1F\xFF\x27\x25\x1F\xFF" + "\x28\x24\x1F\xFF\x26\x23\x1F\xFF\x26\x23\x1E\xFF\x25\x24\x1E\xFF\x26\x25\x1E\xFF\x25\x23\x1E" + "\xFF\x26\x25\x1F\xFF\x26\x26\x20\xFF" + "\x56\xCB\x96\xFF\x55\xC6\x92\xFF\x3B\x71\x56\xFF\x27\x2F\x26\xFF\x26\x25\x1F\xFF\x24\x23\x1D" + "\xFF\x26\x25\x1F\xFF\x27\x25\x20\xFF" + "\x24\x23\x1D\xFF\x26\x24\x1F\xFF\x27\x25\x20\xFF\x28\x26\x21\xFF\x25\x24\x1E\xFF\x27\x25\x20" + "\xFF\x27\x24\x1F\xFF\x27\x25\x1F\xFF" + "\x29\x26\x20\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF\x26\x23\x1E\xFF\x27\x25\x1F\xFF\x26\x25\x1E" + "\xFF\x27\x25\x1F\xFF\x27\x24\x1F\xFF" + "\x28\x26\x20\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x28\x26\x21\xFF\x25\x24\x1F\xFF\x28\x26\x21" + "\xFF\x27\x24\x1F\xFF\x26\x25\x1F\xFF" + "\x26\x25\x1F\xFF\x25\x23\x1D\xFF\x26\x24\x1F\xFF\x27\x25\x1F\xFF\x26\x23\x1E\xFF\x25\x23\x1E" + "\xFF\x27\x25\x1F\xFF\x28\x26\x21\xFF" + "\x27\x25\x20\xFF\x25\x24\x1F\xFF\x25\x24\x1E\xFF\x26\x24\x1F\xFF\x28\x26\x20\xFF\x26\x26\x1F" + "\xFF\x26\x25\x1E\xFF\x28\x26\x1F\xFF" + "\x26\x22\x1E\xFF\x26\x23\x1E\xFF\x26\x23\x1E\xFF\x27\x25\x20\xFF\x26\x23\x1E\xFF\x26\x24\x1E" + "\xFF\x27\x25\x1F\xFF\x26\x25\x1E\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x28\x25\x1F\xFF\x27\x25\x1F\xFF\x27\x24\x1E\xFF\x27\x25\x20" + "\xFF\x26\x25\x1F\xFF\x25\x24\x1E\xFF" + "\x56\xCB\x96\xFF\x56\xCB\x96\xFF\x43\x87\x66\xFF\x2C\x39\x2D\xFF\x25\x25\x1D\xFF\x25\x22\x1D" + "\xFF\x27\x24\x1F\xFF\x29\x26\x21\xFF" + "\x27\x25\x1F\xFF\x27\x24\x20\xFF\x28\x24\x20\xFF\x28\x27\x22\xFF\x26\x24\x1F\xFF\x25\x24\x1E" + "\xFF\x27\x24\x1F\xFF\x23\x20\x1B\xFF" + "\x23\x23\x1C\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x28\x26\x21\xFF\x27\x24\x1E\xFF\x26\x24\x1E" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x28\x25\x20\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF\x26\x25\x1F\xFF\x2A\x28\x21" + "\xFF\x29\x26\x20\xFF\x27\x26\x20\xFF" + "\x29\x27\x21\xFF\x29\x27\x20\xFF\x29\x26\x21\xFF\x27\x25\x1F\xFF\x28\x25\x20\xFF\x28\x26\x20" + "\xFF\x29\x26\x20\xFF\x27\x25\x1E\xFF" + "\x28\x23\x20\xFF\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x26\x24\x1E\xFF\x25\x24\x1E\xFF\x27\x24\x1F" + "\xFF\x28\x25\x20\xFF\x28\x25\x1E\xFF" + "\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x25\x25\x1D\xFF\x25\x22\x1E\xFF\x27\x24\x1F" + "\xFF\x29\x27\x20\xFF\x26\x24\x1E\xFF" + "\x25\x24\x1F\xFF\x28\x26\x20\xFF\x28\x25\x1E\xFF\x25\x24\x1E\xFF\x28\x26\x1E\xFF\x27\x25\x20" + "\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF" + "\x55\xCC\x96\xFF\x56\xCC\x97\xFF\x4B\xA6\x7A\xFF\x2E\x47\x36\xFF\x25\x25\x20\xFF\x28\x26\x21" + "\xFF\x29\x26\x21\xFF\x28\x25\x20\xFF" + "\x25\x25\x1F\xFF\x25\x22\x1E\xFF\x27\x24\x1F\xFF\x28\x25\x20\xFF\x25\x24\x1E\xFF\x25\x25\x1F" + "\xFF\x27\x25\x20\xFF\x27\x24\x1F\xFF" + "\x23\x23\x1D\xFF\x24\x22\x1D\xFF\x25\x23\x1E\xFF\x26\x26\x20\xFF\x26\x24\x1F\xFF\x26\x23\x1F" + "\xFF\x26\x25\x1F\xFF\x24\x23\x1E\xFF" + "\x25\x24\x1F\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x27\x24\x1F\xFF\x25\x23\x1F\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x24\x23\x1E\xFF" + "\x26\x23\x1F\xFF\x29\x26\x21\xFF\x26\x23\x1E\xFF\x23\x22\x1D\xFF\x27\x24\x1F\xFF\x28\x25\x1F" + "\xFF\x27\x25\x20\xFF\x28\x26\x20\xFF" + "\x26\x24\x1E\xFF\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x26\x23\x1E" + "\xFF\x27\x25\x1F\xFF\x25\x23\x1E\xFF" + "\x28\x26\x1F\xFF\x27\x24\x1F\xFF\x27\x25\x1F\xFF\x26\x24\x1F\xFF\x29\x26\x21\xFF\x28\x25\x20" + "\xFF\x27\x24\x20\xFF\x24\x22\x1D\xFF" + "\x29\x26\x21\xFF\x28\x25\x20\xFF\x27\x24\x1F\xFF\x27\x25\x20\xFF\x26\x23\x1E\xFF\x28\x25\x20" + "\xFF\x28\x25\x1F\xFF\x25\x23\x1E\xFF" + "\x55\xCC\x97\xFF\x56\xCC\x97\xFF\x51\xBE\x8C\xFF\x32\x52\x3F\xFF\x27\x2A\x22\xFF\x28\x26\x21" + "\xFF\x27\x24\x20\xFF\x27\x25\x20\xFF" + "\x26\x24\x1F\xFF\x29\x26\x21\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF\x26\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x28\x25\x20\xFF\x27\x25\x1F\xFF" + "\x26\x25\x20\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x29\x29\x22\xFF\x25\x25\x1F\xFF\x27\x24\x20" + "\xFF\x29\x26\x21\xFF\x26\x24\x1F\xFF" + "\x26\x24\x1E\xFF\x27\x25\x1F\xFF\x29\x26\x21\xFF\x27\x24\x1F\xFF\x26\x25\x1F\xFF\x28\x25\x20" + "\xFF\x27\x24\x1F\xFF\x25\x23\x1E\xFF" + "\x25\x22\x1D\xFF\x25\x22\x1D\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x27\x25\x1F" + "\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF" + "\x26\x25\x1E\xFF\x26\x24\x1F\xFF\x28\x26\x20\xFF\x2A\x27\x22\xFF\x29\x26\x21\xFF\x25\x24\x1E" + "\xFF\x24\x22\x1C\xFF\x24\x23\x1D\xFF" + "\x26\x24\x1F\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x28\x25\x1F\xFF\x26\x24\x1F\xFF\x26\x25\x1F" + "\xFF\x26\x25\x1E\xFF\x25\x23\x1D\xFF" + "\x26\x24\x1E\xFF\x24\x23\x1E\xFF\x26\x23\x1E\xFF\x27\x26\x20\xFF\x26\x23\x1E\xFF\x27\x25\x1E" + "\xFF\x28\x25\x1F\xFF\x27\x25\x1F\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x55\xCA\x95\xFF\x39\x6C\x51\xFF\x29\x2F\x26\xFF\x29\x28\x22" + "\xFF\x28\x25\x20\xFF\x29\x27\x22\xFF" + "\x28\x25\x20\xFF\x26\x25\x1F\xFF\x26\x24\x1F\xFF\x27\x25\x20\xFF\x26\x25\x1E\xFF\x26\x24\x1F" + "\xFF\x25\x22\x1E\xFF\x27\x24\x1F\xFF" + "\x25\x25\x1F\xFF\x25\x24\x1F\xFF\x26\x25\x1F\xFF\x25\x23\x1E\xFF\x26\x24\x1E\xFF\x27\x24\x1F" + "\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF" + "\x27\x24\x1F\xFF\x26\x25\x1E\xFF\x28\x26\x20\xFF\x27\x25\x20\xFF\x26\x24\x1E\xFF\x27\x26\x1F" + "\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF" + "\x26\x25\x1F\xFF\x27\x24\x20\xFF\x27\x26\x20\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x28\x25\x20" + "\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF" + "\x29\x27\x21\xFF\x28\x25\x20\xFF\x26\x25\x1F\xFF\x29\x26\x21\xFF\x29\x26\x21\xFF\x28\x26\x20" + "\xFF\x27\x25\x1E\xFF\x28\x25\x1E\xFF" + "\x27\x26\x21\xFF\x29\x26\x21\xFF\x27\x24\x1F\xFF\x26\x26\x1E\xFF\x25\x24\x1E\xFF\x26\x24\x1E" + "\xFF\x25\x24\x1E\xFF\x26\x25\x1F\xFF" + "\x24\x23\x1D\xFF\x25\x24\x1D\xFF\x26\x24\x1E\xFF\x27\x24\x1F\xFF\x26\x24\x1E\xFF\x25\x23\x1D" + "\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF" + "\x57\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x4A\xA3\x79\xFF\x29\x35\x2B\xFF\x27\x29\x23" + "\xFF\x27\x25\x1F\xFF\x27\x25\x1E\xFF" + "\x27\x26\x1F\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x29\x27\x20\xFF\x27\x25\x20\xFF\x29\x26\x21" + "\xFF\x25\x23\x1E\xFF\x25\x22\x1D\xFF" + "\x25\x25\x1F\xFF\x25\x24\x1E\xFF\x27\x24\x1F\xFF\x29\x26\x21\xFF\x26\x26\x20\xFF\x26\x24\x1F" + "\xFF\x27\x25\x1F\xFF\x26\x25\x1F\xFF" + "\x28\x25\x20\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x25\x23\x1E\xFF\x29\x26\x21\xFF\x29\x27\x20" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x25\x22\x1D\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF\x24\x24\x1F\xFF\x27\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF" + "\x26\x23\x1F\xFF\x28\x26\x20\xFF\x27\x26\x20\xFF\x27\x25\x20\xFF\x27\x25\x20\xFF\x26\x24\x1E" + "\xFF\x27\x25\x1F\xFF\x27\x25\x1E\xFF" + "\x27\x24\x1F\xFF\x28\x27\x21\xFF\x27\x25\x20\xFF\x26\x25\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x26\x24\x1E\xFF\x2A\x26\x21\xFF" + "\x28\x25\x20\xFF\x26\x24\x1E\xFF\x26\x24\x1F\xFF\x25\x24\x1E\xFF\x28\x25\x20\xFF\x26\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x26\x23\x1D\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x55\xC8\x93\xFF\x32\x53\x40\xFF\x28\x2E\x25" + "\xFF\x25\x25\x20\xFF\x24\x23\x1E\xFF" + "\x28\x25\x20\xFF\x28\x26\x21\xFF\x27\x26\x1F\xFF\x27\x26\x20\xFF\x27\x24\x1F\xFF\x27\x26\x1F" + "\xFF\x27\x27\x21\xFF\x26\x25\x20\xFF" + "\x26\x25\x20\xFF\x27\x25\x1F\xFF\x28\x25\x1F\xFF\x26\x24\x1F\xFF\x25\x24\x1E\xFF\x27\x25\x20" + "\xFF\x29\x27\x22\xFF\x27\x25\x20\xFF" + "\x27\x24\x1F\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x24\x23\x1D\xFF\x29\x26\x21\xFF\x27\x25\x20" + "\xFF\x26\x24\x1F\xFF\x26\x23\x1E\xFF" + "\x25\x23\x1E\xFF\x28\x25\x20\xFF\x26\x23\x1E\xFF\x25\x23\x1E\xFF\x29\x25\x20\xFF\x26\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x26\x25\x1F\xFF" + "\x26\x23\x1E\xFF\x29\x26\x21\xFF\x28\x25\x20\xFF\x25\x25\x1F\xFF\x25\x24\x1E\xFF\x25\x22\x1D" + "\xFF\x27\x25\x1F\xFF\x28\x26\x21\xFF" + "\x26\x24\x1F\xFF\x26\x25\x1F\xFF\x26\x25\x1F\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x25\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x28\x26\x20\xFF" + "\x28\x25\x20\xFF\x28\x26\x20\xFF\x28\x25\x1F\xFF\x24\x23\x1D\xFF\x26\x24\x1F\xFF\x26\x25\x1F" + "\xFF\x25\x24\x1E\xFF\x25\x23\x1C\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x97\xFF\x43\x8E\x6A\xFF\x2B\x3C\x2F" + "\xFF\x29\x32\x28\xFF\x28\x30\x26\xFF" + "\x2A\x2F\x28\xFF\x29\x2F\x26\xFF\x29\x2D\x25\xFF\x2A\x2E\x26\xFF\x28\x2B\x23\xFF\x27\x2A\x24" + "\xFF\x28\x2B\x25\xFF\x27\x2A\x23\xFF" + "\x27\x29\x21\xFF\x27\x29\x22\xFF\x27\x28\x20\xFF\x29\x27\x22\xFF\x26\x25\x1F\xFF\x2A\x28\x23" + "\xFF\x28\x28\x21\xFF\x24\x24\x1D\xFF" + "\x26\x23\x1E\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x25\x23\x1E\xFF\x24\x22\x1E\xFF\x26\x23\x1E" + "\xFF\x26\x24\x1F\xFF\x26\x25\x1F\xFF" + "\x26\x24\x1F\xFF\x28\x25\x20\xFF\x28\x26\x21\xFF\x27\x25\x20\xFF\x28\x25\x20\xFF\x27\x24\x1F" + "\xFF\x25\x24\x1F\xFF\x25\x23\x1E\xFF" + "\x26\x23\x1E\xFF\x27\x24\x1F\xFF\x27\x25\x20\xFF\x23\x23\x1D\xFF\x24\x23\x1E\xFF\x25\x23\x1E" + "\xFF\x25\x25\x1F\xFF\x26\x24\x1F\xFF" + "\x28\x25\x20\xFF\x27\x25\x20\xFF\x27\x25\x1F\xFF\x27\x24\x20\xFF\x26\x25\x20\xFF\x26\x23\x1E" + "\xFF\x28\x25\x20\xFF\x25\x22\x1D\xFF" + "\x27\x24\x1F\xFF\x27\x25\x20\xFF\x28\x25\x1F\xFF\x26\x24\x1E\xFF\x27\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x26\x23\x1E\xFF\x25\x24\x1E\xFF" + "\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x56\xCD\x97\xFF\x54\xC5\x93\xFF\x49\xA2\x78" + "\xFF\x47\x94\x6F\xFF\x44\x8D\x6A\xFF" + "\x42\x87\x64\xFF\x40\x7F\x5F\xFF\x3F\x79\x5B\xFF\x3D\x71\x57\xFF\x37\x68\x4F\xFF\x39\x65\x4D" + "\xFF\x38\x60\x4B\xFF\x36\x5E\x49\xFF" + "\x37\x5A\x45\xFF\x32\x51\x3E\xFF\x30\x48\x38\xFF\x2F\x41\x33\xFF\x2A\x35\x2A\xFF\x2C\x31\x2A" + "\xFF\x2B\x31\x29\xFF\x29\x2E\x26\xFF" + "\x2B\x2D\x27\xFF\x28\x2A\x23\xFF\x28\x2A\x23\xFF\x26\x27\x21\xFF\x26\x26\x20\xFF\x26\x25\x1F" + "\xFF\x27\x24\x1E\xFF\x28\x27\x1F\xFF" + "\x27\x26\x1D\xFF\x25\x24\x1F\xFF\x26\x25\x1F\xFF\x26\x24\x1D\xFF\x24\x23\x1D\xFF\x25\x23\x1E" + "\xFF\x25\x23\x1E\xFF\x26\x23\x1E\xFF" + "\x29\x26\x21\xFF\x27\x24\x20\xFF\x28\x27\x20\xFF\x27\x26\x1E\xFF\x28\x26\x21\xFF\x26\x24\x1E" + "\xFF\x27\x25\x1F\xFF\x26\x24\x1F\xFF" + "\x26\x26\x1E\xFF\x28\x26\x20\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x24\x1F" + "\xFF\x27\x25\x20\xFF\x25\x24\x1E\xFF" + "\x28\x25\x20\xFF\x26\x23\x1E\xFF\x29\x26\x21\xFF\x27\x25\x20\xFF\x27\x26\x20\xFF\x26\x25\x1F" + "\xFF\x27\x26\x1F\xFF\x28\x26\x20\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97" + "\xFF\x55\xC9\x95\xFF\x54\xC6\x93\xFF" + "\x53\xBF\x8D\xFF\x4F\xB4\x85\xFF\x4C\xA8\x7D\xFF\x48\x9C\x74\xFF\x44\x8D\x6A\xFF\x41\x82\x62" + "\xFF\x3D\x76\x59\xFF\x3B\x6A\x51\xFF" + "\x36\x5A\x46\xFF\x30\x4B\x3B\xFF\x2C\x3D\x30\xFF\x2B\x35\x2B\xFF\x2B\x32\x2A\xFF\x2A\x2F\x27" + "\xFF\x2A\x2C\x24\xFF\x2A\x2B\x24\xFF" + "\x28\x29\x22\xFF\x27\x26\x20\xFF\x26\x25\x1F\xFF\x27\x24\x1F\xFF\x28\x25\x1E\xFF\x26\x23\x1E" + "\xFF\x26\x24\x1F\xFF\x27\x26\x1F\xFF" + "\x28\x25\x20\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x26\x25\x20\xFF\x25\x24\x1E\xFF\x25\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x20\xFF" + "\x27\x24\x1F\xFF\x25\x25\x1F\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x27\x24\x1F" + "\xFF\x28\x26\x1F\xFF\x28\x26\x1F\xFF" + "\x28\x26\x20\xFF\x28\x26\x1F\xFF\x27\x25\x20\xFF\x27\x26\x20\xFF\x27\x26\x1F\xFF\x28\x26\x20" + "\xFF\x29\x25\x20\xFF\x27\x25\x20\xFF" + "\x56\xCC\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x97\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCA\x96" + "\xFF\x54\xC5\x92\xFF\x53\xC0\x8F\xFF" + "\x51\xB9\x89\xFF\x50\xB3\x85\xFF\x4D\xAC\x80\xFF\x49\xA1\x78\xFF\x43\x8E\x6A\xFF\x3D\x76\x59" + "\xFF\x34\x56\x42\xFF\x2E\x3D\x30\xFF" + "\x2D\x36\x2C\xFF\x2A\x31\x28\xFF\x26\x2A\x23\xFF\x25\x28\x21\xFF\x28\x29\x22\xFF\x27\x26\x1F" + "\xFF\x28\x27\x20\xFF\x26\x26\x1E\xFF" + "\x28\x25\x20\xFF\x29\x26\x21\xFF\x27\x24\x1F\xFF\x25\x25\x1F\xFF\x26\x24\x1F\xFF\x27\x25\x20" + "\xFF\x27\x26\x20\xFF\x27\x24\x1F\xFF" + "\x24\x25\x1F\xFF\x26\x25\x1F\xFF\x28\x26\x20\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x26\x23\x1E" + "\xFF\x25\x23\x1D\xFF\x29\x26\x20\xFF" + "\x28\x26\x1F\xFF\x29\x26\x21\xFF\x27\x26\x20\xFF\x26\x24\x1E\xFF\x27\x25\x1F\xFF\x27\x24\x1F" + "\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF" + "\x56\xCE\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x97\xFF\x58\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x57\xCC\x97\xFF\x56\xC6\x91\xFF" + "\x4B\xA9\x7D\xFF\x42\x8C\x69\xFF\x3A\x6D\x54\xFF\x36\x5B\x46\xFF\x2F\x49\x38\xFF\x2C\x3D\x2F" + "\xFF\x29\x32\x27\xFF\x28\x2E\x26\xFF" + "\x27\x2B\x23\xFF\x27\x28\x22\xFF\x24\x25\x1E\xFF\x23\x23\x1D\xFF\x26\x24\x1F\xFF\x27\x24\x1E" + "\xFF\x26\x23\x1E\xFF\x28\x26\x20\xFF" + "\x27\x26\x20\xFF\x27\x25\x20\xFF\x26\x24\x1E\xFF\x25\x23\x1E\xFF\x25\x24\x1E\xFF\x24\x23\x1D" + "\xFF\x25\x24\x1E\xFF\x27\x24\x1F\xFF" + "\x27\x26\x1E\xFF\x27\x26\x20\xFF\x28\x26\x21\xFF\x28\x25\x20\xFF\x29\x26\x21\xFF\x25\x24\x1E" + "\xFF\x22\x21\x1C\xFF\x26\x24\x1F\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x57\xCD\x98" + "\xFF\x56\xCD\x97\xFF\x56\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x56\xCB\x96\xFF\x52\xC0\x8E\xFF\x4C\xAB\x7E\xFF\x46\x97\x70" + "\xFF\x41\x82\x62\xFF\x3C\x6E\x53\xFF" + "\x34\x54\x41\xFF\x2C\x3C\x31\xFF\x28\x30\x27\xFF\x27\x2C\x23\xFF\x27\x29\x22\xFF\x28\x27\x21" + "\xFF\x26\x25\x1F\xFF\x27\x27\x20\xFF" + "\x28\x25\x20\xFF\x26\x25\x20\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x25\x23\x1E\xFF\x25\x24\x1E" + "\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x28\x26\x21\xFF\x26\x24\x1E\xFF\x25\x25\x1F\xFF\x26\x24\x1F\xFF\x25\x23\x1E\xFF\x27\x24\x1F" + "\xFF\x28\x25\x20\xFF\x26\x24\x1F\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCD\x97\xFF\x56\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCD\x97\xFF\x57\xCD\x97" + "\xFF\x55\xCA\x95\xFF\x53\xC2\x90\xFF" + "\x50\xB6\x88\xFF\x4B\xA7\x7C\xFF\x41\x86\x64\xFF\x35\x5A\x45\xFF\x2B\x38\x2D\xFF\x29\x31\x28" + "\xFF\x28\x2C\x25\xFF\x26\x28\x22\xFF" + "\x26\x26\x21\xFF\x27\x25\x20\xFF\x26\x24\x1F\xFF\x26\x24\x1F\xFF\x27\x24\x1F\xFF\x28\x25\x1F" + "\xFF\x29\x26\x20\xFF\x29\x26\x21\xFF" + "\x2B\x29\x22\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x28\x26\x20\xFF\x29\x27\x20\xFF\x28\x25\x20" + "\xFF\x28\x25\x1F\xFF\x28\x26\x20\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCD\x97\xFF\x57\xCD\x97\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x97" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x97" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCC\x97\xFF\x56\xCD\x97\xFF\x57\xCC\x97\xFF\x52\xBB\x89\xFF\x46\x91\x6C" + "\xFF\x38\x68\x4F\xFF\x31\x4F\x3D\xFF" + "\x2C\x3A\x30\xFF\x2A\x30\x28\xFF\x27\x2A\x24\xFF\x26\x28\x21\xFF\x25\x26\x1E\xFF\x27\x25\x1F" + "\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF" + "\x25\x24\x1D\xFF\x24\x24\x1D\xFF\x27\x25\x1F\xFF\x28\x26\x1F\xFF\x23\x23\x1D\xFF\x26\x23\x1E" + "\xFF\x28\x26\x20\xFF\x27\x25\x1F\xFF" + "\x56\xCB\x96\xFF\x55\xCA\x95\xFF\x55\xC9\x94\xFF\x56\xCB\x96\xFF\x58\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x55\xC8\x94\xFF\x4F\xB4\x86\xFF" + "\x46\x93\x6E\xFF\x3F\x76\x59\xFF\x34\x57\x42\xFF\x2B\x3B\x2E\xFF\x29\x30\x27\xFF\x2B\x2D\x24" + "\xFF\x28\x28\x22\xFF\x26\x25\x1F\xFF" + "\x25\x25\x1E\xFF\x28\x25\x20\xFF\x28\x25\x20\xFF\x27\x25\x1E\xFF\x24\x22\x1D\xFF\x26\x23\x1E" + "\xFF\x28\x24\x1F\xFF\x25\x25\x1E\xFF" + "\x39\x64\x4C\xFF\x38\x62\x4B\xFF\x37\x61\x4A\xFF\x37\x62\x4B\xFF\x39\x68\x4F\xFF\x3B\x71\x55" + "\xFF\x3F\x7B\x5B\xFF\x40\x81\x60\xFF" + "\x44\x8C\x69\xFF\x47\x94\x6F\xFF\x49\x9C\x75\xFF\x4A\xA3\x7A\xFF\x4C\xAB\x7F\xFF\x50\xB5\x86" + "\xFF\x53\xC3\x90\xFF\x56\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x58\xCD\x98\xFF\x57\xCD\x97\xFF\x57\xCD\x97" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x97\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x58\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x54\xC5\x92\xFF\x50\xB8\x88\xFF\x4B\xA5\x7A\xFF\x3F\x79\x5B\xFF\x31\x4C\x3C" + "\xFF\x29\x34\x29\xFF\x27\x2E\x25\xFF" + "\x26\x26\x22\xFF\x26\x25\x20\xFF\x26\x25\x20\xFF\x27\x27\x1F\xFF\x23\x21\x1C\xFF\x29\x26\x20" + "\xFF\x27\x26\x21\xFF\x27\x25\x1F\xFF" + "\x2A\x2C\x24\xFF\x29\x2B\x24\xFF\x26\x28\x23\xFF\x2A\x2C\x25\xFF\x28\x2C\x24\xFF\x27\x2B\x23" + "\xFF\x26\x2B\x23\xFF\x28\x2F\x25\xFF" + "\x27\x2E\x25\xFF\x2A\x31\x28\xFF\x29\x33\x2A\xFF\x29\x34\x2A\xFF\x2D\x37\x2C\xFF\x2D\x38\x2D" + "\xFF\x2C\x3B\x2E\xFF\x2F\x43\x35\xFF" + "\x35\x5B\x47\xFF\x3C\x70\x55\xFF\x41\x83\x62\xFF\x47\x95\x6E\xFF\x4B\xA7\x7B\xFF\x4E\xAF\x82" + "\xFF\x50\xB6\x87\xFF\x52\xBC\x8C\xFF" + "\x54\xC5\x92\xFF\x56\xCB\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x97" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x97\xFF\x56\xCC\x97\xFF\x54\xC6\x92" + "\xFF\x4A\xA1\x78\xFF\x3D\x6E\x54\xFF" + "\x32\x4A\x39\xFF\x2E\x35\x2B\xFF\x27\x29\x22\xFF\x24\x24\x1E\xFF\x28\x27\x1F\xFF\x26\x26\x20" + "\xFF\x26\x24\x1F\xFF\x25\x24\x1E\xFF" + "\x26\x26\x20\xFF\x25\x25\x1F\xFF\x24\x23\x1E\xFF\x24\x23\x1E\xFF\x27\x26\x20\xFF\x26\x25\x1F" + "\xFF\x26\x26\x1F\xFF\x25\x25\x1F\xFF" + "\x26\x25\x1F\xFF\x24\x24\x1F\xFF\x28\x28\x21\xFF\x2A\x2A\x23\xFF\x26\x26\x20\xFF\x26\x28\x21" + "\xFF\x26\x29\x21\xFF\x2A\x2C\x24\xFF" + "\x27\x2B\x24\xFF\x29\x2E\x25\xFF\x29\x30\x27\xFF\x2B\x33\x2A\xFF\x2B\x37\x2D\xFF\x31\x44\x35" + "\xFF\x34\x53\x40\xFF\x38\x61\x4A\xFF" + "\x3C\x74\x58\xFF\x43\x88\x66\xFF\x4A\x9D\x76\xFF\x4E\xB1\x83\xFF\x54\xC4\x91\xFF\x56\xCD\x97" + "\xFF\x57\xCD\x97\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF" + "\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x56\xC9\x94\xFF" + "\x4C\xA7\x7C\xFF\x41\x81\x61\xFF\x35\x58\x44\xFF\x2D\x39\x2F\xFF\x2B\x30\x28\xFF\x28\x2A\x22" + "\xFF\x27\x26\x20\xFF\x27\x25\x20\xFF" + "\x27\x25\x1F\xFF\x26\x24\x1D\xFF\x28\x26\x1F\xFF\x28\x26\x20\xFF\x25\x24\x1F\xFF\x25\x24\x1E" + "\xFF\x25\x23\x1E\xFF\x26\x24\x1F\xFF" + "\x26\x23\x1E\xFF\x25\x24\x1E\xFF\x29\x26\x21\xFF\x2A\x28\x20\xFF\x28\x25\x20\xFF\x28\x26\x20" + "\xFF\x27\x25\x1E\xFF\x26\x26\x1F\xFF" + "\x26\x27\x1F\xFF\x27\x25\x1F\xFF\x25\x26\x1E\xFF\x26\x27\x21\xFF\x27\x28\x22\xFF\x29\x28\x22" + "\xFF\x28\x2A\x23\xFF\x29\x2C\x24\xFF" + "\x2A\x31\x27\xFF\x2A\x35\x2A\xFF\x2F\x42\x35\xFF\x34\x50\x3E\xFF\x38\x61\x4A\xFF\x3C\x74\x56" + "\xFF\x46\x92\x6D\xFF\x4D\xAF\x82\xFF" + "\x53\xC9\x94\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCE\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x55\xC8\x94\xFF\x51\xB8\x89\xFF\x48\x9B\x74\xFF\x38\x5E\x48\xFF\x2C\x39\x2D" + "\xFF\x28\x2F\x26\xFF\x27\x2A\x22\xFF" + "\x27\x24\x1F\xFF\x25\x23\x1E\xFF\x25\x23\x1E\xFF\x27\x24\x1F\xFF\x26\x23\x1E\xFF\x26\x24\x1F" + "\xFF\x28\x25\x20\xFF\x26\x26\x20\xFF" + "\x27\x25\x1F\xFF\x26\x25\x1F\xFF\x25\x25\x1F\xFF\x25\x25\x1F\xFF\x26\x24\x1F\xFF\x27\x24\x1F" + "\xFF\x27\x25\x20\xFF\x25\x24\x1E\xFF" + "\x26\x24\x1F\xFF\x25\x24\x1D\xFF\x25\x22\x1C\xFF\x26\x25\x1F\xFF\x27\x25\x20\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x29\x27\x22\xFF\x27\x27\x21\xFF\x28\x28\x22\xFF\x2B\x2C\x26\xFF\x29\x2B\x23\xFF\x28\x2C\x25" + "\xFF\x29\x31\x27\xFF\x2B\x36\x2C\xFF" + "\x2D\x3F\x31\xFF\x34\x5A\x46\xFF\x3F\x7D\x5E\xFF\x4A\xA0\x77\xFF\x51\xB8\x88\xFF\x55\xC5\x92" + "\xFF\x56\xCC\x97\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCC\x97\xFF\x57\xCC\x97\xFF\x57\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCC\x97" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCD\x98\xFF\x56\xCD\x97\xFF\x56\xCD\x98\xFF\x56\xCC\x97\xFF\x56\xCA\x96\xFF\x4E\xB2\x85" + "\xFF\x3F\x7D\x5E\xFF\x33\x55\x42\xFF" + "\x25\x22\x1E\xFF\x26\x23\x1E\xFF\x27\x25\x1F\xFF\x28\x25\x20\xFF\x27\x25\x20\xFF\x27\x25\x20" + "\xFF\x27\x25\x1F\xFF\x25\x24\x1D\xFF" + "\x27\x24\x1E\xFF\x27\x24\x1F\xFF\x25\x23\x1D\xFF\x27\x24\x1F\xFF\x25\x25\x1F\xFF\x27\x24\x1F" + "\xFF\x27\x24\x1F\xFF\x27\x24\x1F\xFF" + "\x27\x25\x20\xFF\x29\x26\x21\xFF\x28\x26\x21\xFF\x28\x25\x20\xFF\x25\x24\x1F\xFF\x28\x25\x20" + "\xFF\x28\x25\x20\xFF\x26\x25\x1E\xFF" + "\x27\x24\x1F\xFF\x26\x24\x1F\xFF\x28\x25\x20\xFF\x27\x26\x20\xFF\x26\x25\x20\xFF\x28\x26\x20" + "\xFF\x27\x27\x20\xFF\x27\x29\x21\xFF" + "\x28\x2A\x24\xFF\x28\x2C\x25\xFF\x2A\x31\x29\xFF\x2C\x38\x2D\xFF\x35\x57\x43\xFF\x3E\x74\x59" + "\xFF\x46\x91\x6E\xFF\x4E\xAD\x81\xFF" + "\x55\xC7\x93\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x56\xCC\x97\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF" + "\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x56\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98\xFF\x57\xCD\x98" + "\xFF\x56\xCB\x96\xFF\x51\xB7\x88\xFF"; + +static const BYTE TEST_RLE_BITMAP_EXPERIMENTAL_03_RLE[11160] = + "\x30\xF0\x23\x1F\x1E\x1D\x1D\x1E\x1D\x1F\x23\x4A\x78\x71\x64\x58\x4B\xF0\x3E\x30\x29\x26\x24" + "\x22\x21\x20\x20\x20\x1D\x1E\x20\x1E" + "\x1F\x86\x20\x20\x1F\x20\x21\x22\x1E\x1F\xF0\x1E\x1D\x1F\x20\x1F\x1F\x1F\x1E\x1E\x1F\x1F\x20" + "\x1E\x1F\x1F\x50\x1F\x1E\x1D\x1E\x1C" + "\xF0\x38\x1A\x14\x0E\x08\x08\x06\x04\x04\x18\x38\x4A\x66\x74\x82\xF0\x90\x9E\x90\x76\x52\x2C" + "\x16\x12\x0C\x06\x08\x06\x00\x02\x00" + "\xF0\x03\x03\x02\x00\x01\x03\x02\x02\x00\x02\x01\x01\x03\x00\x00\x33\x02\x04\x00\xD0\x02\x00" + "\x00\x03\x01\x02\x00\x02\x01\x00\x04" + "\x02\x06\xF0\x94\xAE\x90\x6E\x46\x2E\x1E\x0C\x0E\x0A\x02\x00\x02\x0C\x18\xF0\x24\x30\x4C\x6C" + "\x94\xBE\xBE\x9A\x6C\x48\x34\x1C\x10" + "\x08\x06\xF0\x06\x06\x00\x01\x03\x01\x02\x00\x02\x00\x02\x02\x08\x04\x02\xF0\x00\x03\x01\x00" + "\x01\x02\x00\x06\x02\x04\x01\x01\x03" + "\x03\x00\x40\x00\x00\x04\x01\xD3\x02\x14\x3C\x68\x8E\x86\x78\x68\x3E\x16\x02\x02\x00\x14\x02" + "\xF0\x1A\x44\x78\x92\x8C\x82\x6E\x52" + "\x2E\x14\x06\x02\x04\x00\x01\xF0\x01\x03\x00\x01\x01\x02\x00\x00\x03\x01\x01\x01\x04\x06\x00" + "\xD0\x02\x00\x02\x00\x02\x02\x02\x00" + "\x00\x04\x00\x03\x02\x04\xAA\x0C\x2C\x54\x6E\x7C\x4C\x02\x00\x02\x00\xF0\x10\x2E\x50\x6C\x82" + "\x92\x86\x50\x1C\x12\x0A\x04\x04\x02" + "\x01\xF0\x02\x02\x01\x05\x07\x00\x00\x01\x02\x03\x05\x03\x00\x01\x05\xA0\x01\x01\x01\x00\x02" + "\x04\x00\x02\x00\x01\xE5\x00\x00\x02" + "\x02\x00\x00\x00\x04\x1A\x14\x00\x00\x01\x00\x35\x01\x01\x00\xF0\x06\x16\x2A\x52\x96\xBC\x84" + "\x50\x28\x0C\x06\x04\x03\x03\x00\xF0" + "\x04\x04\x04\x02\x02\x02\x00\x02\x00\x00\x01\x02\x00\x02\x00\x70\x02\x04\x08\x01\x01\x02\x04" + "\x04\x5C\x02\x02\x00\x02\x00\x14\x01" + "\xF0\x00\x00\x00\x02\x02\x02\x16\x58\x86\x84\x54\x1E\x06\x06\x04\xF0\x00\x03\x01\x00\x02\x02" + "\x01\x02\x01\x04\x02\x01\x00\x02\x01" + "\x80\x02\x02\x01\x07\x03\x01\x01\x00\x04\x53\x01\x00\x00\x00\x01\x16\x00\xF0\x02\x00\x00\x01" + "\x00\x02\x00\x01\x13\x37\x55\x67\x4B" + "\x1D\x03\xF0\x14\x44\x7A\x74\x28\x08\x01\x01\x02\x04\x00\x02\x00\x00\x01\xF0\x02\x01\x05\x00" + "\x01\x04\x02\x00\x00\x00\x01\x00\x00" + "\x03\x03\x41\xF0\x04\x02\x02\x02\x03\x1F\x69\xA9\x9B\x7D\x69\x85\xAD\xA1\x47\xF0\x0B\x14\x5A" + "\x8A\x32\x08\x04\x04\x04\x01\x03\x04" + "\x01\x00\x00\xE0\x02\x00\x04\x00\x07\x01\x00\x03\x03\x00\x02\x00\x00\x00\x04\x53\x02\x00\x00" + "\x00\x02\x17\x00\xF0\x01\x00\x00\x00" + "\x31\x7F\x61\x11\x36\x4E\x58\x46\x16\x29\x79\xF0\x69\x0B\x00\x34\x68\x14\x06\x03\x07\x04\x02" + "\x00\x02\x00\x00\xA3\x00\x06\x00\x00" + "\x00\x01\x01\x00\x06\x02\x10\x01\x71\xF0\x0D\x6F\x2F\x1A\x7A\x84\x78\x70\x7A\x88\x52\x09\x57" + "\x53\x01\xF0\x00\x44\x42\x06\x06\x00" + "\x04\x04\x00\x01\x00\x02\x00\x00\x03\xB0\x04\x02\x04\x04\x00\x05\x00\x00\x00\x02\x02\x41\xF0" + "\x01\x01\x07\x75\x2B\x2A\x86\x54\x1A" + "\x0C\x02\x04\x2A\x7A\x6E\xF0\x04\x5B\x3B\x00\x06\x68\x22\x04\x00\x03\x01\x01\x04\x01\x00\x83" + "\x01\x03\x02\x01\x00\x01\x02\x00\x30" + "\x02\x00\x02\x51\xF0\x02\x21\x2F\x0C\x50\x2A\x02\x03\x29\x61\x73\x59\x1B\x4C\x32\xF0\x15\x3F" + "\x09\x00\x20\x42\x08\x02\x00\x01\x00" + "\x00\x02\x01\x00\xD0\x02\x00\x00\x02\x01\x05\x02\x00\x00\x00\x01\x01\x01\x61\xF0\x1F\x0F\x14" + "\x34\x04\x00\x0D\x55\x61\x55\x67\x4B" + "\x0A\x3C\x00\xF0\x15\x0D\x00\x0C\x3A\x18\x06\x02\x00\x01\x00\x02\x04\x02\x03\xC0\x04\x06\x00" + "\x00\x02\x00\x00\x01\x00\x00\x02\x00" + "\x11\xF0\x01\x01\x01\x00\x00\x21\x0F\x0A\x1A\x00\x01\x0A\x32\x28\x24\xF0\x30\x2E\x06\x2C\x04" + "\x13\x11\x02\x02\x32\x38\x08\x03\x01" + "\x01\xF0\x00\x02\x01\x03\x02\x00\x03\x00\x00\x01\x00\x01\x00\x03\x03\x20\x00\x02\x0E\xF0\x01" + "\x00\x00\x02\x02\x02\x00\x00\x10\x06" + "\x05\x0B\x00\x00\x06\xF0\x4A\x88\x84\x80\x3C\x00\x0B\x03\x02\x02\x00\x00\x12\x30\x10\xF0\x02" + "\x00\x02\x01\x05\x03\x02\x02\x03\x01" + "\x00\x06\x02\x01\x00\x50\x00\x04\x02\x00\x02\x0D\x24\x01\x00\xF0\x02\x00\x00\x1C\x0E\x0F\x1D" + "\x00\x02\x02\x06\x1A\x2E\x16\x02\xF0" + "\x02\x31\x00\x16\x16\x00\x00\x02\x30\x18\x02\x02\x00\x04\x02\xF0\x04\x00\x00\x01\x00\x00\x00" + "\x02\x02\x06\x04\x01\x01\x00\x05\x0C" + "\xF0\x03\x0F\x05\x01\x00\x00\x01\x03\x00\x01\x24\x1E\x15\x57\x15\xF0\x01\x00\x00\x00\x02\x00" + "\x01\x37\x4B\x04\x2A\x12\x00\x00\x00" + "\xF0\x2C\x26\x0A\x00\x02\x07\x03\x05\x02\x00\x02\x00\x00\x03\x01\x70\x01\x00\x00\x02\x04\x01" + "\x06\x33\x00\x01\x00\xF0\x01\x00\x00" + "\x00\x01\x00\x03\x31\x57\x1F\x00\x00\x02\x02\x00\x83\x00\x1C\x56\x02\x3B\x5F\x17\x00\xF0\x05" + "\x33\x65\x19\x2C\x42\x02\x00\x02\x00" + "\x04\x38\x02\x02\x01\xF0\x02\x01\x02\x00\x00\x01\x01\x00\x01\x00\x00\x01\x05\x02\x02\x20\x02" + "\x01\x39\x00\x02\x00\xF0\x06\x12\x3D" + "\x83\x4B\x07\x00\x00\x02\x02\x02\x44\x44\x0B\x57\xF0\x83\x51\x29\x1D\x31\x67\x7D\x35\x08\x6A" + "\x22\x00\x00\x01\x00\xF0\x00\x3A\x0C" + "\x06\x00\x00\x06\x04\x02\x00\x02\x02\x01\x00\x01\x70\x00\x00\x01\x03\x01\x00\x00\x0C\xF0\x02" + "\x2A\x28\x2D\x8B\x9B\x43\x15\x01\x00" + "\x00\x08\x80\x72\x16\xF0\x39\x83\xA9\xB3\xA1\x67\x17\x3A\x8E\x38\x02\x00\x00\x00\x01\xF0\x01" + "\x22\x24\x00\x00\x02\x03\x01\x03\x03" + "\x00\x00\x02\x04\x01\x70\x02\x04\x06\x02\x00\x00\x00\x58\x02\x00\x00\x02\x00\xF0\x08\x3A\x16" + "\x07\x3B\x87\x7D\x45\x11\x00\x00\x0E" + "\x5A\x7C\x64\x94\x3E\x18\x16\x28\x4A\x70\x80\x3C\x00\x83\x02\x01\x2D\x0B\x00\x02\x00\x02\xC0" + "\x04\x02\x00\x00\x06\x00\x03\x01\x01" + "\x02\x00\x02\x24\x02\x00\xF0\x02\x00\x00\x00\x02\x00\x00\x00\x32\x52\x10\x02\x17\x4D\x7F\xF0" + "\x85\x4B\x09\x00\x08\x3A\x6C\x80\x94" + "\x94\x8C\x78\x56\x1A\x02\x13\x00\xF0\x01\x17\x67\x85\x27\x03\x00\x00\x00\x01\x00\x02\x03\x00" + "\x02\x90\x02\x01\x02\x01\x01\x04\x01" + "\x00\x01\x68\x00\x02\x02\x00\x02\x00\xF0\x08\x6A\xB6\x76\x40\x18\x17\x49\x8D\xB1\x6D\x33\x15" + "\x02\x18\xF0\x28\x2A\x20\x12\x04\x01" + "\x00\x00\x01\x09\x1D\x69\xA7\x71\x35\xF0\x07\x03\x01\x01\x04\x02\x00\x02\x00\x01\x00\x03\x01" + "\x00\x02\x50\x04\x01\x00\x00\x00\x77" + "\x02\x02\x00\x02\x00\x02\x00\xF0\x02\x02\x1A\x64\x88\x78\x46\x16\x03\x25\x6F\x93\x83\x67\x3F" + "\xF0\x29\x13\x01\x02\x02\x00\x05\x23" + "\x45\x67\x89\x6D\x1B\x06\x1C\x53\x00\x01\x02\x00\x01\xC0\x00\x03\x01\x00\x00\x01\x02\x02\x01" + "\x02\x02\x01\x07\x28\x02\x00\xF0\x04" + "\x1C\x50\x82\x8E\x5C\x20\x06\x15\x43\x6F\x85\x8D\x91\x8D\xF0\x81\x8B\x93\x95\x8D\x7F\x69\x33" + "\x08\x3E\x86\x80\x08\x02\x01\xF0\x02" + "\x02\x00\x01\x01\x02\x04\x02\x00\x00\x01\x00\x00\x01\x01\x20\x01\x02\x4D\x02\x02\x02\x00\x03" + "\xF0\x18\x3C\x82\xBA\x96\x5E\x34\x12" + "\x19\x27\x3B\x4F\x5F\x4F\x45\xF0\x3F\x25\x02\x30\x5C\xAC\x9C\x50\x09\x06\x02\x02\x02\x03\x00" + "\xE0\x02\x03\x01\x00\x01\x02\x02\x03" + "\x05\x03\x02\x00\x00\x02\x7C\x02\x00\x02\x02\x00\x02\x00\xF0\x02\x00\x02\x00\x08\x42\x7C\x8E" + "\x84\x74\x62\x4C\x34\x22\x2A\xF0\x3C" + "\x4E\x6C\x7E\x88\x7A\x26\x02\x09\x39\x03\x02\x00\x01\x00\xF0\x00\x02\x00\x02\x02\x00\x00\x03" + "\x02\x02\x00\x04\x00\x02\x00\x04\x23" + "\x02\x00\x2E\x02\x00\xF0\x04\x1E\x48\x68\x72\x80\x8C\x98\x90\x86\x7C\x66\x48\x24\x06\xF0\x00" + "\x00\x39\x31\x05\x05\x00\x01\x01\x00" + "\x00\x06\x01\x05\x01\x63\x02\x00\x04\x00\x00\x01\x33\x02\x02\x00\x2F\x02\x00\x05\xF0\x04\x0C" + "\x14\x1E\x28\x22\x1A\x12\x06\x00\x01" + "\x00\x19\x5D\x77\xF0\x1B\x05\x00\x03\x01\x04\x02\x01\x01\x00\x04\x02\x03\x00\x00\x60\x04\x01" + "\x02\x02\x04\x02\x23\x00\x02\x1F\x00" + "\x0F\xF0\x01\x01\x13\x49\x7B\x75\x29\x0B\x03\x00\x01\x00\x00\x03\x01\xD0\x01\x01\x02\x02\x04" + "\x04\x01\x05\x02\x00\x02\x05\x01\x29" + "\x02\x00\x26\x02\x00\x23\x01\x00\x33\x01\x01\x00\xF0\x02\x02\x02\x00\x02\x00\x13\x5D\x8B\x81" + "\x4D\x15\x03\x01\x03\xF0\x01\x02\x06" + "\x00\x02\x00\x04\x01\x03\x03\x03\x05\x00\x00\x01\x40\x01\x00\x00\x01\xF4\x02\x02\x01\x00\x00" + "\x00\x01\x01\x02\x00\x00\x00\x02\x01" + "\x00\xF0\x02\x00\x00\x00\x02\x00\x00\x01\x00\x01\x01\x01\x09\x1B\x29\xF0\x57\x93\xB9\x7D\x45" + "\x1F\x0B\x07\x03\x00\x06\x04\x00\x00" + "\x06\xF0\x02\x04\x00\x01\x00\x02\x00\x06\x02\x06\x04\x01\x00\x06\x00\xF0\x00\x00\x02\x00\x01" + "\x11\x29\x2F\x3F\x3F\x33\x29\x1D\x11" + "\x0B\x26\x03\x00\xF0\x03\x02\x00\x0B\x19\x2B\x3F\x5D\x6F\x81\x95\x83\x4D\x1B\x11\xF0\x07\x03" + "\x01\x03\x03\x01\x00\x00\x02\x00\x05" + "\x03\x00\x00\x06\xB0\x00\x00\x04\x01\x01\x05\x03\x02\x01\x03\x00\xF0\x00\x02\x02\x00\x55\x85" + "\x87\x89\x87\x87\x8B\x8D\x8F\x95\x99" + "\xF0\x93\x85\x77\x65\x55\x59\x5F\x65\x6B\x7D\x91\x93\x91\x89\x85\x73\x7B\x67\x4D\x29\x11\x0D" + "\x00\xF0\x04\x04\x04\x02\x00\x00\x01" + "\x02\x02\x00\x01\x00\x02\x02\x02\x90\x01\x02\x00\x01\x03\x02\x00\x00\x02\xF0\x00\x00\x05\x6D" + "\x77\x4D\x3B\x2F\x29\x27\x29\x31\x3D" + "\x3F\x3F\xF0\x4D\x5F\x6D\x81\x8B\x85\x83\x7B\x75\x6B\x53\x47\x3F\x35\x25\xC3\x15\x0B\x05\x07" + "\x07\x01\x05\x01\x03\x01\x01\x02\x93" + "\x00\x02\x00\x01\x02\x02\x00\x02\x00\x70\x04\x06\x06\x05\x00\x02\x00\xF0\x04\x02\x2D\x47\x13" + "\x05\x01\x05\x01\x00\x03\x07\x07\x05" + "\x09\xF0\x0B\x0D\x09\x07\x0F\x0F\x09\x0D\x0B\x05\x09\x05\x05\x01\x07\xF0\x03\x03\x03\x00\x02" + "\x04\x06\x02\x01\x01\x00\x02\x00\x03" + "\x01\x75\x03\x03\x00\x00\x00\x01\x00\x70\x02\x02\x01\x04\x00\x01\x00\xF0\x00\x01\x33\x1D\x05" + "\x03\x00\x04\x00\x00\x00\x04\x00\x03" + "\x01\xF0\x00\x02\x00\x00\x01\x01\x01\x00\x05\x00\x00\x00\x02\x01\x04\xF0\x02\x00\x02\x00\x00" + "\x05\x05\x00\x04\x02\x03\x01\x05\x01" + "\x00\xF0\x04\x04\x01\x00\x00\x02\x02\x05\x00\x00\x02\x00\x03\x02\x02\x40\x00\x00\x00\x03\xF0" + "\x00\x0B\x1B\x07\x01\x00\x02\x01\x02" + "\x00\x01\x01\x00\x02\x00\xF0\x02\x06\x02\x00\x04\x00\x00\x00\x04\x01\x00\x00\x02\x04\x02\xF0" + "\x04\x02\x00\x04\x01\x01\x02\x01\x02" + "\x01\x01\x01\x00\x02\x00\xF0\x01\x00\x03\x00\x00\x01\x03\x00\x03\x03\x00\x02\x00\x03\x01\x40" + "\x00\x02\x00\x04\xF0\x00\x03\x05\x01" + "\x03\x04\x04\x00\x01\x01\x01\x03\x00\x00\x02\xF0\x00\x01\x01\x00\x01\x00\x03\x03\x02\x01\x01" + "\x00\x01\x01\x01\xF0\x00\x00\x02\x03" + "\x01\x02\x00\x02\x01\x02\x06\x02\x04\x02\x00\xF3\x00\x01\x00\x00\x02\x02\x00\x02\x02\x00\x03" + "\x03\x01\x01\x00\x10\x01\xF0\x02\x03" + "\x03\x00\x01\x03\x05\x00\x02\x00\x02\x02\x02\x04\x01\xF0\x05\x03\x00\x02\x00\x05\x00\x02\x01" + "\x00\x04\x01\x00\x02\x02\x83\x00\x04" + "\x00\x02\x06\x04\x03\x00\xB3\x03\x03\x07\x05\x00\x02\x00\x02\x01\x01\x02\x90\x06\x00\x04\x00" + "\x00\x01\x00\x02\x00\xF0\x02\x0A\x06" + "\x00\x08\x04\x04\x02\x04\x04\x02\x00\x02\x02\x04\xF0\x08\x00\x01\x03\x00\x04\x02\x02\x00\x06" + "\x00\x02\x02\x03\x00\xF0\x00\x05\x01" + "\x03\x01\x03\x01\x03\x00\x02\x01\x00\x01\x02\x02\xF0\x00\x02\x02\x01\x00\x01\x03\x02\x00\x00" + "\x03\x02\x01\x00\x00\x40\x00\x03\x01" + "\x04\xF0\x00\x06\x0C\x02\x01\x03\x00\x02\x05\x01\x00\x04\x05\x03\x03\xB3\x03\x02\x00\x01\x01" + "\x02\x01\x01\x00\x01\x00\xB3\x02\x01" + "\x00\x00\x01\x00\x02\x02\x00\x00\x02\xF0\x04\x06\x02\x03\x00\x01\x01\x00\x04\x05\x01\x00\x01" + "\x00\x00\x60\x02\x02\x00\x04\x00\x03" + "\xF0\x00\x08\x20\x0E\x03\x00\x00\x02\x04\x02\x00\x02\x02\x03\x00\x73\x07\x07\x02\x02\x06\x01" + "\x00\xF0\x03\x01\x01\x00\x00\x02\x02" + "\x04\x06\x04\x00\x04\x04\x02\x05\xF0\x00\x00\x02\x01\x03\x00\x04\x01\x00\x02\x00\x05\x00\x02" + "\x02\x63\x00\x00\x02\x01\x01\x00\xF0" + "\x00\x02\x28\x12\x06\x08\x04\x01\x00\x03\x01\x03\x01\x02\x02\xF0\x08\x02\x05\x01\x01\x02\x02" + "\x00\x01\x01\x04\x02\x01\x00\x03\xF0" + "\x01\x03\x03\x02\x05\x03\x01\x01\x00\x04\x03\x01\x00\x02\x00\xF0\x01\x01\x00\x02\x00\x02\x04" + "\x06\x02\x00\x01\x04\x00\x02\x04\x13" + "\x00\xF0\x02\x00\x24\x12\x04\x00\x01\x00\x00\x06\x00\x03\x02\x00\x00\xF0\x00\x06\x06\x04\x04" + "\x00\x02\x04\x02\x01\x01\x02\x00\x00" + "\x02\xF0\x00\x00\x03\x07\x02\x04\x01\x00\x00\x01\x00\x02\x02\x06\x06\xF0\x00\x05\x01\x00\x02" + "\x02\x00\x03\x01\x03\x00\x05\x03\x01" + "\x00\x40\x00\x03\x00\x02\xF0\x00\x00\x12\x24\x08\x02\x00\x04\x02\x03\x00\x04\x01\x00\x03\xF0" + "\x00\x01\x01\x01\x07\x01\x01\x01\x00" + "\x02\x01\x01\x02\x01\x01\xF0\x02\x02\x04\x06\x02\x00\x02\x02\x00\x00\x06\x02\x01\x01\x00\x63" + "\x04\x04\x02\x04\x02\x01\xA0\x00\x04" + "\x01\x01\x00\x01\x00\x01\x00\x02\xF0\x00\x02\x06\x50\x0A\x02\x01\x07\x01\x02\x04\x00\x04\x04" + "\x00\xF0\x03\x00\x01\x00\x06\x04\x00" + "\x01\x00\x02\x04\x00\x03\x06\x02\xF0\x01\x00\x03\x03\x01\x00\x00\x01\x01\x01\x03\x00\x02\x01" + "\x01\x63\x03\x02\x00\x03\x00\x02\xA0" + "\x00\x04\x06\x02\x02\x01\x04\x04\x00\x05\xF0\x02\x00\x00\x34\x2A\x04\x02\x00\x02\x02\x03\x00" + "\x01\x03\x06\xF0\x06\x02\x02\x00\x03" + "\x03\x02\x06\x02\x01\x00\x00\x01\x00\x00\xF0\x00\x01\x02\x04\x01\x01\x02\x00\x00\x02\x01\x02" + "\x00\x01\x03\xF0\x01\x00\x06\x00\x03" + "\x01\x02\x02\x00\x02\x01\x00\x04\x00\x01\x40\x01\x00\x01\x01\x03\xF0\x08\x54\x14\x10\x10\x10" + "\x0A\x0C\x0C\x08\x0A\x08\x06\x02\x06" + "\xF0\x02\x06\x02\x06\x01\x05\x01\x00\x00\x02\x05\x03\x00\x02\x02\xF0\x00\x06\x04\x00\x00\x00" + "\x01\x00\x03\x00\x03\x00\x02\x00\x03" + "\xF0\x02\x02\x00\x00\x00\x01\x02\x05\x01\x00\x00\x02\x00\x00\x00\x10\x04\x04\xF0\x52\x92\x8E" + "\x88\x78\x72\x6C\x62\x58\x52\x4C\x4C" + "\x48\x38\x30\xF0\x22\x16\x0E\x10\x12\x12\x06\x06\x06\x04\x02\x01\x00\x03\x01\xF0\x03\x05\x05" + "\x01\x01\x00\x06\x02\x00\x02\x06\x00" + "\x00\x00\x03\xF0\x00\x00\x01\x01\x02\x00\x02\x02\x03\x04\x04\x02\x00\x02\x04\x03\xF0\x02\x0A" + "\x40\x52\x5C\x68\x72\x7A\x82\x92\x94" + "\x94\x94\x90\x8E\xF0\x8A\x82\x80\x70\x60\x56\x3E\x30\x1A\x14\x14\x10\x0C\x0A\x0A\xF0\x02\x00" + "\x04\x02\x00\x02\x02\x01\x00\x00\x04" + "\x05\x02\x00\x02\xF0\x02\x01\x00\x00\x02\x00\x01\x02\x00\x02\x01\x00\x01\x02\x02\x10\x00\x39" + "\x00\x01\x00\xF0\x01\x02\x06\x0A\x16" + "\x26\x34\x48\x5A\x68\x72\x7C\x86\x94\xA0\xF0\x9A\x80\x64\x3C\x18\x14\x10\x08\x04\x08\x02\x02" + "\x01\x00\x02\xF0\x01\x01\x02\x02\x02" + "\x01\x00\x00\x02\x00\x01\x01\x03\x02\x01\x70\x04\x00\x03\x00\x01\x01\x01\x04\x5A\x01\x00\x00" + "\x01\x00\xF0\x01\x02\x04\x0C\x10\x1E" + "\x26\x30\x3E\x5A\x7C\xAA\xC2\xA2\x82\xF0\x62\x4A\x2C\x20\x0E\x10\x06\x02\x01\x03\x00\x03\x03" + "\x02\x02\xF0\x02\x03\x01\x01\x01\x02" + "\x01\x01\x01\x02\x04\x04\x01\x05\x00\x33\x00\x02\x00\x24\x01\x00\x29\x02\x00\x53\x02\x00\x00" + "\x00\x02\xF0\x0E\x34\x5E\x84\x90\x8C" + "\x82\x76\x5A\x3C\x1E\x12\x0C\x06\x06\xF0\x02\x00\x00\x00\x02\x00\x00\x02\x02\x00\x06\x03\x03" + "\x01\x05\x30\x02\x08\x00\x03\x3A\x01" + "\x02\x00\x53\x01\x00\x02\x02\x00\x28\x01\x00\xF0\x04\x12\x32\x4E\x66\x7A\x8E\x96\x7A\x44\x16" + "\x0E\x0C\x04\x02\x33\x00\x00\x02\x90" + "\x04\x02\x04\x02\x02\x04\x02\x01\x02\x55\x00\x01\x01\x02\x00\xA8\x01\x01\x01\x00\x00\x01\x00" + "\x01\x01\x00\xF0\x01\x01\x00\x00\x02" + "\x00\x00\x02\x02\x00\x04\x10\x20\x36\x66\xF0\xA4\xB8\x88\x54\x36\x1E\x10\x0A\x04\x01\x00\x01" + "\x05\x09\x05\x60\x01\x01\x05\x03\x02" + "\x01\xF0\x03\x03\x05\x03\x00\x00\x02\x02\x00\x01\x02\x02\x02\x00\x00\x54\x02\x00\x00\x02\x00" + "\x94\x02\x00\x00\x00\x02\x02\x00\x01" + "\x00\xF0\x02\x02\x00\x01\x02\x02\x02\x1E\x58\x8A\x92\x7C\x62\x3C\x1A\xC0\x12\x0A\x06\x02\x02" + "\x06\x02\x01\x00\x00\x01\x01\xF0\x93" + "\x93\x93\x95\x91\x85\x79\x6F\x5D\x4F\x45\x3B\x31\x23\x0F\x8D\x01\x02\x02\x00\x00\x01\x01\x00" + "\x13\x01\xF0\x00\x01\x01\x00\x00\x00" + "\x08\x24\x52\x72\x8C\x98\x68\x30\x0E\x90\x0C\x08\x00\x00\x02\x01\x04\x04\x02\xF0\x4F\x4D\x4D" + "\x4B\x55\x63\x6F\x75\x87\x8D\x95\x9F" + "\xA5\xB1\xC3\xF0\xC3\xA1\x85\x6B\x53\x37\x29\x21\x17\x0B\x01\x00\x00\x00\x01\x49\x01\x02\x01" + "\x00\x14\x01\xF0\x00\x0C\x20\x3A\x78" + "\xAC\x9E\x5E\x2E\x16\x04\x01\x06\x00\x03\x10\x01\xF0\x07\x09\x09\x0D\x07\x07\x07\x0B\x0B\x11" + "\x11\x0D\x17\x17\x19\xF0\x21\x45\x5F" + "\x75\x87\x9B\x99\x8D\x83\x73\x61\x43\x29\x0D\x00\xC6\x00\x00\x02\x00\x00\x00\x02\x02\x00\x00" + "\x02\x00\xF0\x02\x01\x00\x02\x02\x0C" + "\x40\x80\x86\x6C\x44\x22\x12\x04\x02\x10\x04\xF0\x01\x03\x02\x04\x01\x01\x01\x00\x01\x01\x00" + "\x05\x00\x01\x05\xF0\x09\x09\x0B\x11" + "\x11\x15\x25\x39\x4B\x61\x77\x81\x89\x8D\x81\xE4\x53\x2B\x07\x00\x01\x01\x00\x00\x02\x02\x00" + "\x00\x00\x02\x34\x00\x02\x00\x90\x08" + "\x36\x66\x8A\x8A\x40\x16\x0C\x04\xF0\x00\x02\x01\x01\x01\x02\x04\x02\x02\x02\x03\x01\x01\x01" + "\x04\x33\x01\x00\x03\xF0\x05\x07\x09" + "\x09\x11\x25\x2F\x4D\x61\x8B\xAB\xC5\xA3\x71\x3F\x44\x1F\x0B\x01\x00\x66\x01\x01\x00\x00\x01" + "\x00\x80\x02\x06\x1E\x46\x9C\xB0\x70" + "\x40\xF0\x01\x00\x02\x02\x04\x02\x01\x05\x01\x00\x03\x00\x00\x00\x01\xF0\x02\x02\x08\x0A\x02" + "\x01\x02\x02\x01\x05\x03\x03\x0B\x05" + "\x09\xF0\x0D\x15\x19\x41\x69\x93\x89\x71\x51\x2D\x09\x02\x02\x00\x02\x2A\x02\x00\x70\x02\x00" + "\x02\x04\x26\x70\x8C\x34\x2A\x25\x23" + "\xF0\x24\x2B\x60\xA2\x97\x84\x75\x62\x50\x3C\x34\x30\x2C\x29\x28\x93\x26\x25\x25\x23\x23\x25" + "\x24\x24\x25\x84\x26\x27\x25\x24\x25" + "\x25\x27\x24\xC3\x25\x25\x24\x25\x26\x25\x23\x24\x24\x25\x23\x24\x30\x22\x23\x21\xF0\x4E\x24" + "\x1C\x12\x0C\x0A\x08\x06\x08\x26\x4E" + "\x6A\x8E\xA0\xB6\xF0\xCA\xDC\xCA\xA0\x74\x3E\x20\x1A\x12\x08\x08\x08\x02\x02\x02\xF0\x03\x03" + "\x02\x02\x01\x00\x00\x02\x00\x02\x07" + "\x00\x01\x02\x00\xF0\x01\x02\x00\x02\x00\x01\x01\x00\x02\x01\x01\x02\x00\x02\x00\x40\x04\x04" + "\x02\x06\xF0\xD2\xF8\xCC\x9A\x5E\x40" + "\x26\x14\x10\x0C\x02\x00\x04\x10\x20\xF0\x30\x44\x66\x98\xCC\xF7\xF7\xD4\x98\x66\x4A\x2C\x14" + "\x0C\x08\xF0\x0A\x08\x01\x03\x01\x07" + "\x00\x02\x00\x01\x00\x00\x08\x04\x00\xF0\x02\x03\x01\x00\x00\x00\x02\x06\x04\x04\x01\x01\x01" + "\x00\x00\x40\x07\x00\x04\x04\xC4\x02" + "\x16\x52\x92\xC8\xBE\xAC\x8E\x58\x1C\x02\x00\x14\x02\xF0\x22\x60\xA6\xCC\xC2\xB2\x9C\x70\x3E" + "\x1C\x0A\x04\x06\x00\x02\x75\x00\x03" + "\x00\x01\x01\x02\x01\xF0\x04\x02\x00\x02\x00\x01\x01\x02\x02\x02\x03\x03\x06\x00\x03\x10\x03" + "\x04\x8C\x12\x40\x70\x96\xAE\x6C\x02" + "\x00\xF0\x16\x40\x6E\x94\xB4\xD0\xBA\x72\x26\x18\x0C\x08\x04\x00\x03\xF0\x02\x04\x01\x05\x03" + "\x02\x01\x03\x02\x05\x05\x03\x01\x00" + "\x01\xA0\x02\x01\x01\x02\x02\x04\x02\x02\x00\x00\x03\x8D\x02\x01\x00\x00\x0A\x22\x1C\x00\x03" + "\xF0\x0A\x20\x38\x72\xCE\xF7\xBA\x70" + "\x34\x12\x08\x08\x05\x01\x00\xF0\x04\x02\x02\x06\x06\x00\x02\x04\x02\x02\x03\x01\x03\x00\x04" + "\x70\x00\x06\x0A\x03\x01\x02\x04\x04" + "\x5C\x02\x00\x00\x02\x00\x44\x01\x01\x01\x00\xF0\x02\x02\x02\x1E\x78\xBC\xB6\x74\x2E\x0E\x0A" + "\x02\x00\x01\x01\xF0\x00\x01\x00\x00" + "\x00\x01\x02\x02\x00\x02\x04\x02\x00\x00\x01\x50\x07\x01\x01\x00\x00\x04\x23\x01\x00\x47\x01" + "\x00\x01\x00\x23\x01\x00\xF0\x01\x01" + "\x17\x49\x75\x8D\x67\x27\x01\x1A\x60\xAA\xA0\x32\x0E\xF0\x04\x02\x00\x02\x01\x04\x02\x02\x01" + "\x02\x00\x05\x01\x01\x02\x90\x00\x00" + "\x04\x01\x01\x02\x00\x03\x03\x08\x2A\x01\x00\x13\x02\xF0\x05\x2B\x91\xF1\xD9\xB1\x95\xBB\xF1" + "\xE5\x63\x0F\x1C\x7C\xC4\xF0\x48\x0A" + "\x02\x04\x04\x02\x05\x02\x01\x00\x00\x00\x01\x04\x01\xA0\x07\x01\x00\x05\x01\x00\x00\x01\x00" + "\x02\x04\x99\x02\x00\x00\x00\x02\x02" + "\x00\x02\x00\xF0\x01\x00\x43\xB1\x8B\x15\x48\x70\x7C\x62\x20\x35\xA7\x95\x0F\xF0\x00\x46\x8C" + "\x18\x08\x00\x05\x00\x04\x02\x02\x00" + "\x01\x00\x06\xC0\x00\x00\x02\x01\x03\x01\x04\x04\x00\x04\x02\x03\x71\xF0\x13\x9D\x43\x26\xAA" + "\xB8\xA6\x9C\xAA\xBC\x70\x0D\x79\x71" + "\x01\xF0\x02\x60\x5C\x0C\x04\x02\x04\x02\x01\x00\x00\x02\x00\x00\x01\x83\x04\x04\x06\x02\x00" + "\x03\x01\x00\x41\xF0\x01\x00\x09\xA5" + "\x3B\x3C\xBC\x74\x24\x10\x04\x06\x3A\xAA\x94\xF0\x08\x7F\x55\x01\x0A\x96\x2A\x06\x03\x03\x01" + "\x00\x01\x01\x00\xE0\x01\x03\x00\x00" + "\x01\x03\x04\x04\x01\x01\x00\x00\x01\x02\x61\xF0\x2F\x3F\x0E\x6E\x38\x02\x03\x37\x89\x9F\x7F" + "\x25\x6C\x46\x1F\xF0\x55\x09\x00\x26" + "\x5E\x0C\x06\x00\x00\x00\x04\x02\x00\x02\x02\xC0\x00\x02\x04\x00\x05\x02\x02\x04\x02\x00\x00" + "\x01\x41\xF0\x02\x00\x2D\x17\x1E\x48" + "\x06\x00\x15\x79\x8B\x77\x91\x67\x10\xF0\x56\x03\x1F\x17\x00\x10\x50\x22\x06\x04\x02\x03\x01" + "\x04\x04\x93\x02\x03\x04\x04\x01\x01" + "\x02\x01\x00\x20\x02\x00\x21\xF0\x01\x01\x00\x00\x2F\x15\x0E\x26\x00\x01\x12\x46\x3A\x32\x4A" + "\xF0\x40\x0A\x3A\x06\x1B\x17\x00\x04" + "\x46\x4E\x0E\x03\x05\x02\x00\xF0\x00\x03\x01\x04\x00\x03\x02\x04\x00\x00\x01\x03\x05\x01\x00" + "\x10\x02\x11\xF0\x01\x00\x02\x01\x00" + "\x18\x0E\x05\x11\x00\x00\x06\x66\xBE\xB8\xF0\xB2\x52\x00\x0D\x03\x04\x04\x00\x00\x1A\x42\x16" + "\x06\x02\x00\xF0\x00\x05\x01\x00\x02" + "\x01\x00\x03\x02\x02\x01\x02\x00\x04\x00\x20\x00\x02\x11\xF0\x02\x02\x00\x02\x00\x24\x0E\x15" + "\x29\x00\x02\x02\x08\x24\x3E\xF0\x1C" + "\x02\x00\x49\x00\x20\x1C\x00\x00\x02\x44\x20\x04\x04\x00\xF0\x02\x00\x04\x00\x01\x03\x03\x02" + "\x00\x00\x02\x02\x04\x00\x00\x20\x00" + "\x05\x0C\x53\x05\x17\x0B\x01\x00\xF0\x01\x00\x38\x2E\x21\x7B\x1D\x01\x00\x00\x02\x02\x01\x03" + "\x49\xF0\x65\x08\x38\x1A\x00\x00\x00" + "\x3A\x30\x06\x02\x02\x05\x01\x03\xE0\x02\x00\x04\x02\x03\x03\x01\x03\x02\x00\x00\x04\x01\x04" + "\xF0\x01\x01\x00\x01\x01\x01\x00\x01" + "\x01\x00\x01\x00\x03\x45\x77\x24\x2D\x00\x83\x01\x26\x78\x04\x51\x83\x21\x00\xE3\x07\x43\x91" + "\x25\x3C\x5C\x02\x00\x01\x01\x08\x52" + "\x06\x00\xF0\x01\x01\x00\x03\x03\x04\x00\x00\x02\x01\x05\x02\x00\x02\x00\x93\x02\x02\x00\x02" + "\x00\x00\x00\x02\x00\xF0\x08\x18\x59" + "\xB7\x67\x09\x00\x00\x02\x02\x00\x5C\x62\x0F\x79\xF0\xB7\x71\x37\x27\x45\x91\xB1\x49\x0C\x94" + "\x30\x00\x00\x02\x02\xF0\x00\x54\x10" + "\x06\x01\x00\x04\x06\x02\x00\x06\x02\x03\x01\x00\x70\x00\x01\x00\x01\x01\x00\x00\x04\x35\x02" + "\x02\x00\xF0\x02\x3A\x3A\x3B\xC3\xD9" + "\x5D\x1B\x01\x00\x00\x0A\xB0\x9E\x1C\xC4\x4F\xB5\xED\xF9\xDD\x8D\x1D\x4C\xC4\x4C\x02\x00\xF0" + "\x2C\x34\x04\x04\x02\x03\x01\x03\x03" + "\x03\x02\x04\x04\x03\x00\x60\x04\x04\x00\x01\x01\x00\x13\x02\x18\x00\xF0\x0C\x52\x20\x0D\x51" + "\xBB\xAF\x61\x19\x00\x00\x12\x7E\xB0" + "\x8C\x95\x52\x24\x1A\x38\x64\x98\xB6\x54\x00\xF0\x05\x3F\x0F\x03\x03\x02\x02\x00\x02\x04\x04" + "\x02\x01\x02\x06\x70\x02\x03\x00\x01" + "\x04\x04\x02\x0A\xF0\x02\x00\x00\x00\x44\x6E\x18\x04\x21\x6D\xB1\xB9\x69\x0D\x00\xC4\x0A\x4E" + "\x94\xB4\xCC\xCE\xC0\xAA\x78\x24\x02" + "\x00\xF0\x21\x91\xBB\x3B\x05\x04\x00\x00\x01\x02\x00\x01\x00\x02\x02\x80\x00\x00\x01\x01\x04" + "\x01\x01\x00\x68\x02\x02\x02\x00\x02" + "\x00\xF0\x0E\x94\xFC\xA2\x54\x20\x21\x63\xC3\xF5\x95\x49\x1F\x04\x22\xF0\x36\x3A\x2C\x18\x06" + "\x01\x00\x00\x00\x09\x29\x95\xE9\x99" + "\x45\xF0\x09\x03\x01\x00\x02\x00\x00\x02\x00\x01\x00\x05\x03\x00\x04\x50\x06\x01\x00\x00\x02" + "\x78\x02\x00\x02\x00\x00\x02\x00\xF0" + "\x02\x26\x8C\xC2\xA8\x66\x1C\x05\x31\x99\xC9\xB5\x8F\x5B\x39\xF0\x19\x03\x02\x02\x00\x07\x2B" + "\x63\x93\xBB\x97\x25\x06\x24\x04\xF0" + "\x00\x01\x02\x00\x02\x03\x01\x01\x03\x01\x01\x01\x00\x00\x00\x40\x01\x02\x02\x01\x98\x02\x02" + "\x00\x02\x00\x00\x00\x02\x00\xF0\x04" + "\x26\x70\xB2\xC6\x7E\x2A\x02\x1D\x5B\x99\xB7\xC5\xCB\xC7\xF0\xB3\xC3\xCB\xCF\xC7\xB1\x91\x4B" + "\x0A\x56\xBC\xB4\x0A\x00\x01\x64\x01" + "\x02\x00\x00\x01\x02\x70\x01\x00\x01\x01\x00\x00\x00\xAA\x02\x02\x02\x00\x02\x00\x02\x00\x02" + "\x00\xF0\x20\x54\xB6\xFF\xD0\x82\x48" + "\x18\x1F\x33\x4F\x69\x83\x71\x63\xF0\x59\x37\x00\x40\x80\xEE\xDA\x6E\x0D\x08\x00\x00\x00\x03" + "\x01\xE0\x04\x01\x00\x02\x00\x02\x02" + "\x05\x07\x03\x02\x00\x00\x02\x03\x2E\x02\x00\xF0\x02\x00\x02\x00\x0C\x5E\xAA\xC2\xB8\xA0\x86" + "\x68\x48\x32\x3E\xF0\x54\x6E\x98\xB2" + "\xC0\xAA\x36\x02\x0D\x53\x07\x02\x02\x00\x04\x34\x02\x01\x00\x80\x01\x02\x06\x00\x06\x04\x00" + "\x01\x63\x02\x02\x00\x00\x02\x00\x2E" + "\x02\x00\xF0\x06\x2A\x62\x90\x9E\xB0\xC2\xD0\xC8\xBA\xAC\x8E\x64\x30\x08\xF0\x00\x00\x51\x43" + "\x0D\x01\x02\x02\x05\x03\x00\x02\x01" + "\x03\x00\x90\x02\x02\x04\x02\x00\x03\x03\x00\x01\x13\x02\x4F\x00\x02\x02\x00\x05\xF0\x04\x10" + "\x1C\x2A\x36\x30\x24\x18\x06\x00\x01" + "\x00\x21\x81\xA7\xF0\x2D\x03\x01\x03\x07\x06\x06\x01\x00\x02\x02\x00\x01\x03\x02\x60\x02\x00" + "\x02\x01\x02\x04\x9F\x02\x00\x02\x02" + "\x00\x00\x00\x02\x00\x0C\xF0\x01\x01\x1B\x65\xB1\xA5\x39\x0D\x03\x00\x00\x08\x01\x01\x02\xD0" + "\x01\x03\x02\x00\x02\x06\x00\x03\x00" + "\x00\x00\x05\x03\x47\x02\x02\x02\x00\x2B\x02\x00\x33\x01\x01\x00\xF0\x02\x02\x01\x00\x00\x00" + "\x1B\x7F\xC1\xB3\x6D\x1D\x03\x00\x01" + "\xF0\x01\x00\x01\x00\x01\x02\x04\x02\x03\x03\x03\x05\x03\x01\x00\x40\x03\x02\x02\x00\xA6\x00" + "\x02\x00\x00\x02\x00\x01\x01\x02\x00" + "\x26\x02\x00\xF0\x02\x00\x01\x00\x00\x01\x01\x0B\x1F\x3B\x75\xCB\xFA\xB3\x5F\xF0\x2F\x0B\x09" + "\x05\x01\x06\x06\x02\x00\x06\x02\x01" + "\x00\x01\x00\xA0\x02\x00\x04\x04\x04\x02\x00\x00\x04\x00\xF0\x02\x02\x02\x00\x01\x17\x37\x45" + "\x55\x57\x49\x39\x27\x19\x0D\x37\x03" + "\x01\x00\xF0\x01\x0F\x25\x3B\x59\x81\x9D\xB5\xCD\xB9\x6D\x1F\x15\x0D\x05\xF0\x03\x01\x05\x01" + "\x01\x03\x01\x02\x05\x03\x01\x04\x02" + "\x00\x00\x90\x02\x00\x01\x05\x01\x04\x00\x00\x00\xF0\x02\x02\x00\x00\x77\xBD\xBF\xBB\xBD\xB7" + "\xBF\xC3\xC9\xCF\xD3\xF0\xCF\xBB\xA3" + "\x8B\x77\x7D\x85\x8D\x97\xAF\xC7\xCF\xC9\xC1\xBB\xF0\xAD\x8D\x69\x39\x17\x15\x05\x01\x01\x01" + "\x04\x02\x04\x02\x00\xF0\x02\x02\x00" + "\x02\x04\x00\x03\x02\x02\x00\x00\x02\x01\x01\x01\x40\x00\x00\x02\x02\xF0\x02\x00\x09\x99\xAD" + "\x65\x4D\x45\x3B\x39\x3D\x49\x55\x5D" + "\x5F\xF0\x6B\x83\x9B\xB3\xC1\xBD\xB5\xAB\xA3\x91\x73\x61\x57\x4D\x35\xF0\x1B\x15\x0B\x0D\x09" + "\x01\x07\x03\x01\x02\x01\x00\x04\x02" + "\x00\x14\x01\xE0\x04\x00\x02\x01\x04\x00\x01\x04\x06\x04\x05\x03\x03\x00\xF0\x02\x00\x3D\x63" + "\x17\x0B\x07\x07\x00\x03\x03\x07\x09" + "\x07\x0D\xF0\x11\x0F\x0D\x0B\x15\x11\x11\x13\x13\x0D\x0F\x09\x05\x03\x05\xF0\x03\x01\x01\x01" + "\x02\x04\x06\x02\x00\x00\x02\x04\x00" + "\x01\x03\xF0\x03\x01\x02\x00\x00\x03\x00\x00\x02\x00\x02\x01\x00\x02\x00\x40\x06\x04\x02\x01" + "\xF0\x00\x00\x47\x25\x05\x03\x00\x02" + "\x01\x01\x02\x04\x00\x01\x00\xB3\x00\x01\x02\x01\x01\x03\x01\x01\x01\x00\x01\xF0\x04\x02\x01" + "\x00\x04\x00\x03\x07\x01\x02\x01\x03" + "\x03\x07\x03\xF0\x04\x06\x02\x01\x00\x02\x06\x04\x03\x00\x00\x02\x02\x02\x04\x50\x00\x00\x00" + "\x03\x04\xF0\x02\x0D\x27\x0B\x01\x01" + "\x02\x00\x00\x00\x03\x01\x00\x00\x00\xF0\x04\x04\x00\x00\x04\x00\x01\x00\x00\x01\x00\x02\x02" + "\x02\x00\xF0\x00\x02\x01\x02\x03\x01" + "\x04\x00\x00\x02\x01\x01\x00\x02\x02\xF0\x03\x00\x03\x02\x00\x05\x05\x00\x01\x03\x01\x04\x01" + "\x03\x00\x40\x01\x00\x00\x03\xF0\x00" + "\x05\x07\x03\x01\x02\x04\x00\x00\x00\x01\x03\x00\x02\x00\xF0\x00\x02\x03\x01\x01\x00\x01\x03" + "\x00\x02\x02\x00\x01\x00\x00\xF0\x02" + "\x02\x02\x03\x01\x00\x02\x02\x01\x01\x04\x02\x04\x02\x01\xF4\x00\x01\x04\x00\x02\x02\x02\x00" + "\x02\x01\x03\x05\x01\x03\x00\xF0\x02" + "\x05\x03\x01\x03\x00\x03\x02\x00\x00\x02\x02\x06\x02\x01\xF0\x05\x05\x00\x04\x01\x03\x02\x04" + "\x00\x00\x04\x01\x01\x02\x02\xF0\x00" + "\x04\x00\x02\x06\x04\x05\x00\x04\x02\x00\x01\x01\x07\x03\xF0\x00\x04\x00\x02\x03\x01\x04\x00" + "\x04\x04\x06\x02\x02\x02\x01\x40\x02" + "\x00\x02\x01\xF0\x02\x0A\x08\x00\x06\x04\x06\x00\x04\x02\x00\x01\x00\x02\x04\xF0\x06\x00\x00" + "\x03\x02\x02\x02\x00\x04\x02\x03\x00" + "\x04\x03\x00\xF0\x01\x05\x01\x03\x01\x03\x00\x03\x01\x01\x00\x01\x01\x02\x06\xF0\x04\x04\x01" + "\x03\x04\x01\x07\x04\x03\x02\x01\x00" + "\x03\x01\x00\x40\x00\x03\x00\x06\xF0\x00\x0C\x0E\x04\x00\x03\x01\x02\x03\x01\x00\x04\x05\x03" + "\x03\xA5\x01\x04\x01\x01\x03\x04\x00" + "\x00\x03\x00\xF0\x01\x00\x02\x00\x00\x04\x00\x00\x00\x04\x00\x02\x02\x04\x02\xF0\x02\x03\x04" + "\x03\x05\x00\x04\x05\x00\x01\x00\x00" + "\x02\x04\x02\x40\x01\x04\x00\x03\xF0\x00\x0A\x2C\x14\x00\x01\x01\x02\x04\x00\x01\x02\x00\x01" + "\x00\xF0\x09\x05\x02\x00\x06\x01\x01" + "\x01\x00\x01\x03\x01\x01\x02\x04\xF0\x04\x02\x04\x08\x04\x00\x04\x06\x02\x01\x03\x00\x00\x00" + "\x03\xF0\x03\x00\x01\x02\x02\x00\x00" + "\x01\x00\x04\x01\x00\x04\x00\x01\x40\x04\x00\x01\x01\xF0\x02\x02\x3E\x1C\x00\x08\x04\x01\x00" + "\x03\x00\x03\x00\x02\x02\xF0\x08\x00" + "\x05\x01\x00\x00\x01\x02\x01\x01\x04\x02\x01\x03\x07\xF0\x03\x05\x07\x01\x05\x05\x01\x01\x01" + "\x02\x02\x01\x00\x00\x01\xF0\x01\x00" + "\x03\x06\x00\x04\x01\x08\x02\x05\x03\x04\x01\x01\x02\x40\x05\x00\x02\x00\xF0\x00\x00\x30\x16" + "\x0A\x00\x03\x00\x01\x08\x00\x03\x00" + "\x01\x00\x63\x02\x04\x06\x04\x06\x02\xF0\x00\x00\x02\x00\x04\x02\x00\x00\x01\x07\x02\x04\x01" + "\x00\x00\xF0\x03\x02\x02\x04\x06\x06" + "\x02\x05\x00\x03\x02\x00\x02\x03\x00\xA0\x02\x02\x03\x03\x01\x02\x00\x00\x00\x04\xF0\x00\x00" + "\x18\x34\x0A\x04\x02\x04\x02\x01\x00" + "\x04\x02\x00\x05\x93\x01\x00\x01\x00\x0B\x01\x00\x01\x00\xF0\x02\x01\x02\x02\x02\x06\x04\x04" + "\x00\x02\x00\x00\x00\x04\x02\xF0\x01" + "\x01\x00\x04\x06\x04\x04\x02\x01\x02\x00\x01\x01\x04\x01\x70\x02\x02\x03\x02\x03\x01\x00\xF0" + "\x00\x02\x06\x6E\x0C\x02\x00\x03\x02" + "\x00\x04\x04\x00\x04\x02\xF0\x03\x00\x00\x01\x06\x04\x00\x00\x02\x02\x00\x01\x03\x04\x02\xF0" + "\x01\x00\x05\x00\x03\x00\x00\x01\x01" + "\x01\x07\x02\x02\x01\x01\xF0\x03\x00\x00\x03\x02\x02\x01\x00\x00\x00\x02\x04\x00\x00\x00\x40" + "\x02\x02\x00\x03\xF0\x02\x00\x00\x4A" + "\x3C\x0A\x00\x03\x01\x02\x00\x01\x01\x00\x08\xB3\x06\x00\x02\x02\x03\x03\x02\x04\x00\x01\x00" + "\xF0\x03\x00\x01\x02\x02\x01\x01\x02" + "\x00\x00\x04\x00\x00\x01\x00\xA3\x01\x03\x00\x02\x00\x03\x00\x00\x02\x00\x70\x04\x02\x01\x01" + "\x02\x00\x00\x03\xF0\x0A\x76\x1C\x1A" + "\x1A\x14\x12\x0E\x10\x0E\x08\x08\x0A\x08\x08\xF0\x06\x06\x02\x06\x02\x01\x01\x00\x00\x00\x07" + "\x03\x00\x04\x02\xF0\x00\x06\x04\x00" + "\x00\x00\x03\x00\x03\x00\x03\x01\x02\x00\x03\xF0\x02\x00\x00\x01\x00\x01\x02\x07\x01\x01\x00" + "\x02\x00\x01\x01\x10\x02\x04\xF0\x6E" + "\xCC\xC4\xBA\xB0\xA0\x98\x86\x7A\x76\x6A\x68\x62\x50\x40\xF0\x34\x20\x12\x12\x14\x14\x0A\x0A" + "\x08\x08\x04\x00\x04\x04\x01\xF0\x01" + "\x01\x03\x01\x01\x00\x06\x00\x04\x06\x06\x02\x00\x00\x02\xF0\x02\x01\x00\x01\x02\x00\x04\x02" + "\x03\x02\x02\x04\x02\x06\x04\x04\xF0" + "\x10\x56\x72\x80\x8C\x9C\xA8\xB8\xCA\xCE\xD2\xD0\xCA\xC6\xC0\xF0\xB6\xB0\xA2\x8A\x78\x5A\x42" + "\x26\x1C\x18\x14\x10\x08\x06\x04\xF0" + "\x00\x00\x04\x00\x02\x06\x01\x02\x03\x01\x03\x00\x01\x00\x03\xF0\x01\x00\x00\x02\x00\x02\x04" + "\x02\x06\x01\x02\x00\x02\x01\x01\x39" + "\x01\x01\x00\xF0\x01\x02\x08\x0E\x1C\x32\x4A\x62\x7E\x90\x9E\xAC\xBE\xD0\xDE\xF0\xD8\xB8\x8E" + "\x54\x24\x1A\x16\x0A\x08\x08\x06\x06" + "\x00\x00\x02\xF0\x01\x00\x00\x02\x04\x00\x02\x00\x04\x00\x01\x01\x05\x00\x00\x70\x00\x02\x03" + "\x01\x03\x01\x01\x6C\x04\x00\x00\x00" + "\x01\x00\xF0\x01\x01\x02\x06\x10\x1A\x28\x34\x42\x58\x7C\xAC\xEC\xED\xE6\xF0\xB6\x86\x66\x40" + "\x2E\x16\x10\x0C\x04\x02\x03\x00\x01" + "\x05\x04\xF0\x02\x00\x03\x01\x00\x00\x02\x03\x00\x00\x00\x02\x02\x00\x05\x10\x00\x34\x01\x02" + "\x00\x23\x01\x00\x2E\x02\x00\xF0\x02" + "\x02\x02\x0E\x46\x82\xBC\xCA\xC4\xB4\xA0\x80\x52\x28\x16\xF0\x12\x0A\x06\x04\x02\x01\x00\x00" + "\x00\x01\x02\x00\x00\x00\x03\x60\x01" + "\x01\x05\x00\x08\x00\x03\x67\x01\x02\x00\x00\x02\x00\x53\x01\x00\x02\x02\x00\x28\x01\x00\xF0" + "\x04\x18\x44\x6C\x90\xA8\xC4\xD6\xAC" + "\x5C\x1E\x14\x0E\x02\x02\xF0\x00\x00\x02\x02\x02\x04\x04\x06\x02\x00\x04\x08\x02\x00\x04\x03" + "\x25\x02\x00\x25\x01\x00\x34\x01\x01" + "\x00\x26\x02\x00\xF0\x02\x00\x00\x02\x00\x00\x06\x16\x2E\x4A\x8E\xE4\xF9\xC0\x78\xF0\x4E\x28" + "\x16\x0C\x08\x04\x00\x03\x05\x09\x01" + "\x00\x00\x07\x03\x20\x02\x01\x55\x03\x05\x07\x03\x00\x2F\x02\x00\x0D\xF0\x01\x02\x00\x02\x24" + "\x78\xC0\xCA\xB2\x8C\x5A\x26\x14\x10" + "\x08\x90\x04\x02\x02\x00\x01\x01\x00\x03\x00\xF0\xCD\xCF\xCF\xD1\xC9\xB7\xA3\x97\x81\x71\x61" + "\x53\x43\x2F\x13\x5D\x01\x02\x02\x02" + "\x00\x03\x13\x01\xF0\x00\x01\x01\x00\x00\x00\x0A\x32\x72\x9E\xC2\xD4\x92\x3E\x18\x90\x12\x02" + "\x00\x00\x04\x01\x06\x04\x00\xF0\x6F" + "\x6D\x71\x6B\x77\x8B\x9F\xA3\xBB\xC5\xD1\xDD\xE7\xF9\xF0\xC5\xEE\xE3\xB9\x93\x6F\x4B\x3B\x2D" + "\x21\x0F\x03\x00\x29\x01\x00\x14\x01" + "\xF0\x00\x10\x2A\x50\xA6\xF4\xDA\x80\x48\x20\x08\x05\x0C\x00\x03\x10\x01\xF0\x0B\x0B\x09\x11" + "\x0B\x0B\x09\x13\x11\x19\x15\x13\x21" + "\x1F\x23\xF0\x2D\x5F\x83\xA5\xC3\xDF\xD5\xC5\xB5\xA1\x85\x5F\x37\x11\x00\xC6\x00\x00\x02\x00" + "\x00\x00\x02\x02\x00\x00\x02\x00\xF0" + "\x02\x01\x00\x00\x02\x0E\x58\xB6\xBA\x98\x5E\x2A\x12\x08\x04\x10\x02\xF0\x01\x01\x06\x06\x03" + "\x01\x05\x01\x03\x00\x03\x03\x01\x03" + "\x07\xF0\x0B\x07\x11\x13\x17\x1D\x37\x51\x69\x85\xA5\xB5\xC1\xC5\xB1\xE4\x75\x3B\x07\x00\x01" + "\x01\x00\x00\x02\x02\x00\x00\x00\x02" + "\xF0\x00\x02\x00\x00\x02\x00\x00\x08\x4A\x8E\xC0\xC4\x5C\x1E\x12\x10\x0A\xF0\x01\x01\x05\x03" + "\x01\x00\x04\x04\x04\x02\x01\x05\x01" + "\x03\x00\xF0\x03\x05\x01\x07\x03\x05\x07\x0B\x0F\x13\x1B\x33\x47\x6B\x8F\xA4\xC1\xF1\xEC\xE5" + "\x9D\x57\x29\x0F\x01\x00\xF0\x01\x01" + "\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02\x0A\x2A\x50\x62\xD8\xF2\x9C\x56\xF0\x03\x00\x04" + "\x02\x04\x02\x00\x03\x01\x01\x03\x01" + "\x02\x00\x01\xF0\x00\x02\x04\x08\x00\x01\x02\x02\x02\x05\x05\x05\x0B\x0B\x0B\xF0\x13\x19\x29" + "\x5B\x97\xCF\xC1\xA1\x75\x3F\x0B\x02" + "\x02\x00\x02\x2C\x02\x00\x50\x02\x06\x36\x9C\xC4\x53\x27\x23\x23\x24\x25\xF0\x28\x37\x4A\x47" + "\x41\x3D\x38\x33\x2E\x2A\x28\x27\x26" + "\x27\x27\xF0\x27\x25\x24\x26\x28\x26\x27\x28\x28\x26\x28\x28\x2A\x26\x27\xF0\x27\x28\x27\x27" + "\x25\x26\x24\x25\x27\x28\x27\x28\x27" + "\x27\x25\xB0\x26\x27\x27\x26\x27\x27\x27\x26\x25\x26\x23\xF0\x16\x0C\x0C\x06\x02\x06\x04\x04" + "\x02\x0A\x16\x1E\x2A\x2E\x34\xF0\x3A" + "\x3E\x3C\x30\x20\x12\x0A\x08\x06\x04\x06\x02\x01\x00\x01\xF0\x05\x03\x02\x00\x00\x03\x02\x00" + "\x00\x00\x03\x01\x00\x02\x04\xF0\x02" + "\x04\x00\x01\x01\x03\x00\x00\x00\x03\x00\x01\x00\x02\x00\x40\x00\x04\x02\x08\xF0\x38\x48\x38" + "\x2C\x1E\x10\x0C\x04\x04\x04\x02\x00" + "\x02\x06\x0A\xF0\x0E\x12\x1C\x2C\x3E\x4E\x4C\x3C\x28\x1E\x14\x0C\x04\x02\x02\xF0\x04\x04\x00" + "\x01\x07\x05\x02\x04\x00\x00\x02\x02" + "\x08\x06\x02\xF0\x01\x09\x03\x04\x00\x04\x03\x08\x02\x02\x03\x02\x07\x03\x00\x40\x01\x00\x04" + "\x01\xC4\x02\x06\x16\x28\x3A\x34\x2E" + "\x2A\x16\x06\x01\x00\x13\x02\xF0\x00\x0A\x1C\x32\x3A\x38\x34\x2E\x24\x14\x0C\x01\x03\x00\x04" + "\xF0\x00\x00\x05\x03\x03\x01\x02\x00" + "\x01\x03\x00\x04\x00\x04\x04\xE0\x02\x02\x00\x04\x02\x04\x00\x04\x01\x05\x06\x00\x03\x01\x04" + "\x96\x02\x14\x22\x2A\x34\x20\x02\x02" + "\x00\xF0\x01\x02\x00\x00\x00\x0A\x14\x20\x2A\x32\x3A\x34\x22\x10\x0A\xF0\x00\x04\x00\x02\x02" + "\x04\x04\x03\x09\x05\x01\x01\x03\x02" + "\x05\xF0\x07\x03\x04\x03\x03\x03\x01\x00\x04\x02\x06\x01\x02\x00\x01\xDB\x00\x00\x02\x02\x01" + "\x00\x00\x02\x0A\x08\x00\x01\x00\xF0" + "\x03\x01\x00\x04\x0A\x12\x20\x3C\x4A\x32\x24\x10\x02\x00\x04\xF0\x05\x07\x01\x08\x00\x06\x06" + "\x02\x00\x00\x02\x01\x00\x03\x01\xA0" + "\x00\x02\x02\x01\x08\x0A\x00\x01\x02\x0A\x04\x78\x02\x01\x01\x02\x00\x02\x00\x57\x02\x01\x01" + "\x01\x00\xF0\x02\x0A\x22\x34\x34\x22" + "\x0E\x02\x06\x08\x02\x03\x01\x03\x01\xF3\x04\x00\x00\x02\x04\x01\x00\x00\x04\x03\x03\x04\x03" + "\x07\x03\x04\x23\x01\x00\x28\x01\x00" + "\xF0\x02\x00\x00\x00\x01\x02\x00\x01\x09\x15\x23\x29\x1F\x0B\x00\xF0\x0A\x1C\x32\x2E\x0E\x00" + "\x00\x02\x02\x06\x04\x06\x02\x01\x03" + "\xF0\x01\x02\x01\x00\x01\x04\x02\x04\x02\x01\x03\x02\x02\x01\x01\x05\x3B\x02\x02\x00\xF0\x01" + "\x02\x02\x00\x00\x01\x0B\x27\x43\x43" + "\x33\x29\x33\x45\x41\xE3\x1D\x05\x08\x24\x38\x18\x00\x00\x04\x04\x02\x05\x02\x00\xD0\x01\x04" + "\x00\x07\x01\x00\x07\x00\x01\x00\x01" + "\x00\x00\x04\x7D\x02\x00\x00\x00\x02\x02\x00\xF0\x13\x31\x29\x03\x14\x20\x20\x1A\x0A\x0B\x31" + "\x2B\x05\x01\x14\xF0\x28\x0A\x04\x03" + "\x09\x01\x00\x00\x01\x04\x00\x00\x06\x02\x02\xA0\x01\x00\x03\x01\x04\x06\x01\x00\x00\x03\x71" + "\xF0\x05\x2D\x13\x0A\x30\x3A\x32\x30" + "\x32\x36\x20\x03\x21\x21\x00\xF0\x00\x1C\x1A\x02\x02\x04\x06\x04\x00\x02\x00\x04\x00\x02\x03" + "\xB0\x00\x06\x06\x04\x04\x07\x00\x02" + "\x02\x04\x02\x41\xF0\x01\x00\x01\x2F\x0D\x12\x38\x22\x0C\x04\x00\x02\x10\x2E\x2C\xF0\x02\x23" + "\x17\x00\x02\x2A\x0A\x00\x03\x05\x01" + "\x01\x02\x01\x01\xE0\x01\x05\x00\x00\x01\x03\x02\x01\x02\x03\x02\x02\x01\x04\x61\xF0\x0D\x11" + "\x02\x1E\x10\x00\x01\x0F\x25\x2D\x23" + "\x0B\x20\x10\x07\xF0\x17\x03\x00\x0C\x1C\x04\x04\x00\x01\x01\x00\x02\x00\x00\x00\x93\x02\x02" + "\x02\x05\x05\x04\x02\x06\x01\x41\xF0" + "\x02\x00\x09\x07\x08\x14\x02\x00\x05\x21\x25\x21\x29\x1D\x04\xF0\x1A\x02\x09\x03\x01\x04\x16" + "\x08\x02\x02\x04\x01\x02\x02\x06\xE0" + "\x00\x01\x04\x04\x01\x04\x04\x02\x00\x03\x02\x00\x02\x01\x11\x13\x01\xF0\x00\x0F\x05\x00\x0A" + "\x01\x01\x04\x12\x0A\x0C\x12\x10\x02" + "\x12\xF0\x02\x05\x07\x00\x02\x14\x16\x04\x03\x03\x02\x00\x00\x03\x01\xD0\x04\x01\x01\x04\x00" + "\x03\x05\x05\x01\x03\x05\x00\x04\x31" + "\xF0\x02\x00\x00\x06\x04\x00\x03\x02\x00\x02\x1E\x38\x36\x34\x1A\xF0\x02\x03\x01\x00\x02\x02" + "\x00\x08\x12\x02\x04\x02\x02\x00\x07" + "\xF0\x05\x02\x02\x03\x01\x01\x06\x04\x02\x02\x00\x02\x04\x02\x02\x11\xF0\x02\x02\x00\x00\x01" + "\x0A\x08\x07\x0D\x00\x02\x04\x04\x0C" + "\x12\xF0\x0A\x02\x00\x13\x00\x04\x06\x00\x00\x02\x16\x08\x00\x00\x00\xF0\x02\x04\x04\x00\x01" + "\x00\x00\x02\x00\x00\x00\x06\x06\x00" + "\x01\x20\x00\x07\x0C\x37\x01\x07\x00\xF0\x10\x0C\x03\x23\x09\x01\x01\x00\x02\x02\x00\x00\x15" + "\x1D\x02\xF0\x12\x08\x00\x01\x01\x12" + "\x14\x01\x01\x01\x09\x03\x01\x00\x00\xC0\x02\x01\x03\x05\x03\x00\x00\x01\x02\x06\x01\x06\x06" + "\xF0\x01\x00\x01\x00\x00\x00\x01\x13" + "\x27\x0D\x00\x00\x01\x01\x00\x83\x00\x0A\x22\x01\x11\x25\x09\x00\xF0\x01\x15\x29\x09\x0E\x1E" + "\x02\x00\x02\x02\x02\x16\x04\x02\x00" + "\xF0\x02\x01\x00\x00\x00\x01\x00\x02\x02\x04\x00\x03\x05\x02\x00\x20\x02\x01\x0C\xF0\x02\x06" + "\x1B\x35\x21\x03\x00\x00\x02\x02\x02" + "\x1A\x1E\x07\x21\xC4\x31\x21\x11\x0D\x15\x29\x33\x15\x01\x2A\x0E\x00\xF0\x16\x08\x04\x00\x02" + "\x06\x02\x04\x00\x04\x00\x03\x01\x03" + "\x01\x60\x01\x01\x05\x01\x00\x00\x0C\xF0\x02\x12\x16\x11\x35\x3F\x1B\x07\x01\x00\x00\x04\x32" + "\x30\x06\xB5\x1D\x33\x43\x45\x3F\x29" + "\x07\x18\x40\x18\x00\xF0\x10\x0C\x01\x02\x02\x05\x01\x03\x05\x01\x02\x02\x02\x00\x04\x60\x04" + "\x08\x02\x00\x01\x02\x58\x00\x02\x02" + "\x02\x00\xF0\x04\x14\x08\x01\x15\x33\x33\x1B\x07\x00\x00\x06\x22\x32\x2C\xF0\x16\x0A\x08\x12" + "\x1C\x2C\x30\x16\x00\x01\x01\x00\x01" + "\x00\x01\xF0\x0F\x07\x00\x01\x00\x04\x04\x00\x06\x04\x02\x02\x02\x06\x01\x60\x03\x01\x00\x04" + "\x02\x01\x24\x02\x00\x26\x02\x00\xF0" + "\x14\x22\x06\x02\x09\x21\x31\x35\x1D\x03\x00\x04\x18\x2C\x36\x84\x3C\x3A\x3C\x32\x22\x0E\x02" + "\x00\xF0\x09\x2B\x39\x0B\x02\x04\x00" + "\x00\x03\x01\x01\x05\x00\x00\x04\x80\x01\x04\x00\x01\x00\x01\x01\x02\x04\x28\x02\x00\xF0\x04" + "\x2A\x4A\x2E\x1A\x10\x07\x19\x37\x47" + "\x2B\x15\x07\x00\x0A\xF0\x10\x12\x08\x06\x02\x01\x00\x01\x00\x03\x0B\x2D\x45\x2B\x17\xF0\x03" + "\x05\x05\x01\x04\x02\x04\x04\x00\x03" + "\x02\x05\x01\x01\x02\x50\x04\x02\x00\x02\x02\x0E\xF0\x02\x00\x0A\x28\x34\x2E\x1A\x04\x05\x0F" + "\x2D\x37\x33\x29\x1B\xF0\x11\x09\x01" + "\x02\x02\x00\x01\x0D\x1B\x29\x37\x29\x07\x02\x0E\x33\x02\x01\x00\xE0\x01\x01\x00\x03\x00\x01" + "\x01\x05\x02\x02\x01\x02\x02\x03\x3E" + "\x02\x02\x00\xF0\x02\x0E\x20\x32\x38\x28\x10\x06\x09\x1B\x2D\x33\x39\x39\x37\xF0\x33\x37\x39" + "\x3D\x37\x33\x2B\x15\x02\x18\x36\x34" + "\x00\x00\x02\xF0\x02\x02\x01\x03\x01\x04\x04\x00\x00\x02\x00\x02\x00\x01\x00\x20\x03\x01\x44" + "\x00\x00\x02\x00\x25\x02\x00\x23\x02" + "\x00\xF0\x0A\x1C\x34\x46\x3A\x26\x16\x0A\x0D\x0F\x19\x21\x27\x21\x19\xF0\x17\x0F\x02\x18\x28" + "\x46\x3E\x20\x03\x06\x00\x00\x04\x05" + "\x00\xE0\x04\x01\x05\x00\x03\x04\x00\x03\x05\x05\x02\x01\x01\x04\x03\x4C\x02\x00\x02\x00\xF0" + "\x02\x02\x00\x00\x06\x1A\x30\x36\x34" + "\x32\x2A\x20\x16\x10\x12\xF0\x18\x20\x2C\x32\x34\x2E\x12\x02\x01\x19\x01\x06\x02\x03\x00\xF0" + "\x00\x01\x05\x04\x02\x02\x01\x01\x06" + "\x02\x00\x02\x00\x04\x02\x2F\x02\x00\x08\xF0\x02\x0E\x1C\x2A\x2C\x34\x3A\x3C\x38\x34\x30\x28" + "\x1C\x10\x04\xF0\x00\x00\x17\x11\x07" + "\x03\x02\x01\x02\x00\x02\x0A\x00\x03\x01\x90\x04\x02\x04\x02\x02\x00\x00\x00\x01\x3F\x00\x02" + "\x00\x09\xF0\x02\x02\x06\x08\x0A\x10" + "\x0E\x08\x06\x02\x00\x01\x00\x0B\x27\xF0\x31\x09\x03\x03\x07\x01\x02\x04\x03\x01\x01\x04\x04" + "\x05\x01\x70\x00\x00\x01\x00\x00\x04" + "\x01\x9F\x00\x00\x02\x00\x02\x00\x00\x02\x00\x09\x23\x02\x00\xF0\x07\x1D\x31\x2D\x11\x05\x02" + "\x02\x00\x00\x03\x01\x02\x00\x01\xB0" + "\x01\x00\x04\x04\x01\x03\x00\x02\x00\x07\x00\x29\x02\x00\x2B\x02\x00\x33\x01\x01\x00\xF0\x02" + "\x02\x02\x00\x02\x02\x07\x25\x39\x33" + "\x21\x07\x04\x00\x03\xF0\x00\x02\x04\x04\x00\x02\x04\x02\x01\x03\x05\x03\x01\x00\x01\x40\x03" + "\x02\x04\x02\x93\x00\x02\x00\x02\x00" + "\x01\x01\x01\x00\xA4\x01\x01\x01\x00\x01\x01\x00\x00\x01\x00\xF0\x01\x02\x01\x01\x01\x05\x0D" + "\x11\x21\x3B\x49\x2F\x17\x0B\x00\xF0" + "\x01\x01\x02\x06\x02\x00\x02\x06\x02\x02\x00\x00\x02\x00\x04\x80\x02\x06\x06\x06\x01\x00\x04" + "\x03\xF0\x00\x00\x01\x01\x00\x03\x0F" + "\x13\x1B\x1B\x15\x0F\x09\x07\x01\x24\x01\x00\xF0\x01\x00\x01\x02\x00\x03\x0F\x0F\x19\x25\x29" + "\x33\x3B\x37\x1D\xF0\x09\x07\x01\x00" + "\x00\x03\x03\x01\x00\x02\x00\x01\x05\x05\x01\xD0\x00\x02\x00\x00\x02\x00\x01\x05\x03\x02\x01" + "\x03\x02\xF0\x02\x00\x02\x00\x21\x35" + "\x33\x33\x35\x35\x39\x39\x37\x3B\x41\xF0\x3B\x33\x2B\x27\x23\x23\x25\x27\x29\x33\x3B\x3B\x39" + "\x35\x33\xF0\x31\x27\x1F\x0D\x03\x07" + "\x02\x00\x01\x01\x04\x04\x02\x02\x00\xF0\x03\x00\x02\x00\x00\x03\x01\x02\x00\x00\x03\x00\x01" + "\x03\x01\x40\x04\x01\x02\x02\xF0\x01" + "\x01\x01\x2B\x31\x23\x1D\x17\x11\x0B\x0B\x13\x1B\x19\x13\xF0\x1B\x29\x31\x37\x37\x35\x35\x33" + "\x2F\x29\x1B\x19\x15\x17\x11\x83\x05" + "\x03\x01\x05\x03\x00\x03\x01\xF0\x02\x04\x02\x02\x00\x01\x00\x00\x04\x08\x01\x02\x00\x02\x04" + "\x80\x02\x02\x06\x02\x05\x01\x03\x01" + "\xF0\x00\x02\x13\x1B\x09\x01\x00\x00\x02\x02\x00\x03\x03\x00\x05\xE3\x09\x01\x02\x02\x05\x03" + "\x00\x03\x05\x01\x07\x05\x01\x03\xF0" + "\x01\x00\x02\x02\x04\x02\x00\x00\x01\x04\x00\x03\x03\x01\x00\xF0\x00\x00\x01\x03\x04\x00\x00" + "\x00\x01\x01\x02\x04\x00\x02\x02\x20" + "\x00\x00\xF0\x04\x00\x11\x0D\x00\x00\x02\x04\x00\x03\x01\x06\x02\x05\x01\x13\x02\xF0\x01\x01" + "\x00\x02\x00\x02\x02\x04\x00\x00\x08" + "\x04\x00\x04\x02\xF0\x03\x03\x05\x00\x02\x00\x03\x03\x05\x05\x04\x02\x02\x01\x00\xF0\x02\x00" + "\x00\x09\x02\x00\x04\x00\x03\x02\x00" + "\x01\x00\x00\x00\xF0\x01\x03\x0B\x00\x01\x00\x04\x01\x02\x01\x01\x05\x02\x06\x02\xF0\x04\x04" + "\x02\x01\x08\x02\x03\x01\x02\x01\x00" + "\x00\x04\x06\x01\xF0\x00\x02\x00\x02\x00\x03\x02\x01\x02\x00\x03\x05\x00\x04\x02\xF0\x02\x00" + "\x03\x01\x00\x00\x01\x00\x05\x01\x01" + "\x02\x02\x01\x04\x40\x04\x02\x00\x02\xF0\x02\x00\x03\x00\x01\x04\x04\x00\x01\x00\x02\x02\x01" + "\x01\x00\xF0\x03\x00\x05\x01\x03\x00" + "\x01\x03\x00\x00\x01\x01\x01\x00\x00\xF0\x02\x00\x00\x01\x01\x04\x02\x02\x01\x02\x06\x04\x04" + "\x02\x01\xF0\x01\x00\x02\x04\x00\x02" + "\x00\x04\x02\x01\x01\x03\x01\x03\x03\x40\x00\x02\x00\x05\xF0\x00\x01\x00\x01\x00\x00\x05\x01" + "\x02\x00\x03\x00\x06\x04\x00\xF0\x03" + "\x03\x02\x02\x01\x07\x00\x04\x00\x03\x04\x00\x03\x02\x02\xF0\x01\x04\x02\x02\x04\x04\x03\x00" + "\x00\x00\x04\x01\x03\x05\x07\xF0\x00" + "\x01\x02\x01\x01\x01\x04\x02\x04\x04\x06\x00\x04\x00\x03\x40\x01\x00\x04\x00\x83\x02\x04\x02" + "\x00\x08\x04\x06\x04\xF0\x00\x02\x04" + "\x04\x0A\x00\x01\x01\x00\x04\x02\x00\x02\x06\x03\xF0\x00\x04\x05\x01\x02\x05\x03\x05\x00\x01" + "\x03\x01\x01\x00\x05\xF0\x01\x05\x02" + "\x08\x02\x06\x00\x00\x02\x01\x05\x04\x00\x00\x03\x80\x06\x03\x00\x02\x00\x05\x03\x04\xF0\x00" + "\x04\x04\x01\x03\x07\x03\x00\x07\x01" + "\x00\x02\x09\x05\x03\xF0\x03\x04\x00\x01\x00\x04\x00\x00\x01\x00\x04\x02\x00\x01\x02\xF0\x01" + "\x01\x00\x00\x00\x02\x04\x01\x02\x02" + "\x04\x00\x04\x02\x02\xF0\x00\x03\x02\x01\x01\x00\x02\x05\x01\x00\x01\x01\x00\x04\x04\x40\x02" + "\x04\x00\x01\xF0\x00\x02\x10\x0A\x01" + "\x02\x02\x04\x06\x02\x02\x00\x02\x03\x00\x64\x07\x0B\x00\x00\x04\x00\xF0\x03\x01\x00\x02\x04" + "\x04\x02\x06\x08\x06\x00\x04\x06\x04" + "\x01\xF0\x02\x04\x02\x00\x05\x02\x04\x00\x00\x02\x01\x03\x01\x02\x04\x90\x00\x03\x04\x00\x03" + "\x02\x00\x02\x02\xF0\x01\x00\x10\x04" + "\x00\x06\x04\x01\x03\x03\x01\x00\x01\x00\x00\xF0\x08\x00\x05\x01\x03\x01\x00\x01\x05\x05\x04" + "\x02\x01\x01\x05\xF0\x03\x05\x05\x00" + "\x05\x07\x01\x00\x03\x02\x03\x01\x02\x02\x02\xF0\x01\x01\x05\x04\x00\x04\x02\x08\x02\x03\x03" + "\x08\x00\x01\x04\x40\x03\x02\x02\x01" + "\xF0\x00\x00\x0C\x08\x04\x00\x03\x01\x02\x08\x01\x03\x02\x02\x02\xF0\x00\x06\x08\x06\x06\x01" + "\x02\x06\x04\x02\x01\x02\x00\x02\x02" + "\xF0\x00\x02\x01\x07\x00\x08\x03\x01\x02\x03\x00\x00\x02\x06\x06\xF0\x01\x05\x01\x03\x02\x02" + "\x04\x05\x03\x01\x02\x05\x07\x01\x00" + "\x40\x00\x01\x00\x04\xF0\x02\x00\x08\x0E\x04\x02\x02\x04\x04\x05\x00\x02\x00\x00\x05\xF0\x00" + "\x01\x05\x03\x07\x02\x00\x01\x00\x02" + "\x01\x01\x00\x00\x01\xF0\x00\x02\x02\x04\x02\x00\x04\x02\x00\x00\x06\x04\x03\x01\x00\xF0\x06" + "\x06\x08\x02\x02\x01\x03\x01\x00\x01" + "\x02\x03\x02\x00\x00\x40\x00\x03\x03\x02\xF0\x02\x02\x04\x22\x00\x03\x01\x03\x01\x04\x06\x04" + "\x02\x06\x00\xF0\x03\x00\x00\x02\x08" + "\x00\x01\x01\x00\x02\x04\x01\x03\x06\x04\xF0\x00\x02\x01\x01\x01\x05\x00\x01\x03\x00\x05\x00" + "\x02\x03\x03\xF0\x03\x00\x01\x00\x01" + "\x00\x00\x04\x00\x02\x08\x08\x02\x00\x03\x40\x04\x02\x02\x03\x03\xF0\x16\x12\x02\x03\x05\x02" + "\x00\x03\x03\x00\x03\x04\x02\x02\x04" + "\xF0\x02\x05\x01\x02\x04\x02\x01\x00\x02\x01\x00\x03\x01\x01\x00\xF0\x04\x00\x02\x04\x01\x00" + "\x00\x00\x02\x02\x03\x03\x01\x00\x02" + "\xF0\x01\x03\x01\x04\x02\x01\x02\x03\x00\x04\x04\x01\x03\x00\x03\x10\x01\xF0\x00\x00\x01\x02" + "\x22\x06\x08\x08\x04\x02\x04\x06\x02" + "\x00\x02\xF0\x02\x02\x00\x01\x06\x02\x06\x01\x05\x01\x00\x00\x02\x09\x01\xF0\x00\x00\x02\x00" + "\x04\x04\x01\x02\x01\x01\x00\x03\x01" + "\x03\x01\xF0\x00\x03\x03\x04\x02\x02\x01\x03\x02\x02\x05\x01\x01\x00\x04\x40\x02\x02\x02\x00" + "\xF0\x01\x00\x00\x00\x22\x3C\x3C\x38" + "\x30\x2E\x2C\x26\x1E\x24\x20\xF0\x1E\x20\x16\x12\x0C\x08\x04\x06\x0A\x0A\x00\x00\x02\x04\x00" + "\xF0\x02\x04\x02\x05\x03\x01\x07\x03" + "\x00\x02\x06\x00\x02\x08\x08\xF0\x02\x04\x00\x03\x02\x00\x00\x02\x00\x01\x00\x02\x01\x02\x02" + "\x40\x00\x01\x02\x06\xF0\x02\x00\x02" + "\x02\x06\x1C\x20\x26\x2A\x2E\x30\x34\x40\x3A\x3A\xF0\x3C\x38\x3A\x38\x32\x34\x2A\x24\x24\x16" + "\x10\x08\x0A\x0A\x08\xF0\x06\x04\x02" + "\x04\x00\x02\x08\x02\x02\x02\x01\x02\x00\x01\x05\xF0\x01\x00\x02\x02\x05\x01\x01\x02\x02\x02" + "\x06\x00\x04\x03\x00\x40\x00\x04\x04" + "\x01\x66\x01\x01\x00\x00\x01\x00\xF0\x01\x02\x04\x06\x08\x10\x14\x1E\x24\x2A\x2E\x30\x36\x40" + "\x42\xF0\x3C\x30\x26\x14\x08\x0A\x06" + "\x00\x03\x00\x02\x04\x01\x00\x02\xF0\x01\x01\x02\x04\x00\x00\x05\x02\x04\x00\x01\x01\x05\x02" + "\x00\x70\x02\x00\x01\x00\x01\x05\x01" + "\x31\xF0\x01\x02\x02\x06\x08\x0C\x0E\x12\x1C\x2A\x32\x46\x50\x3C\x30\xF0\x28\x22\x0E\x0A\x02" + "\x04\x01\x03\x05\x03\x00\x00\x01\x02" + "\x06\xF0\x02\x03\x01\x03\x03\x00\x03\x01\x03\x02\x04\x04\x03\x07\x00\x33\x02\x02\x00\x33\x01" + "\x01\x00\x2E\x02\x00\xF0\x01\x02\x00" + "\x02\x16\x2A\x38\x38\x3A\x34\x30\x28\x1A\x0A\x08\xF0\x08\x02\x02\x00\x01\x02\x01\x02\x02\x00" + "\x02\x02\x00\x02\x01\x60\x05\x03\x07" + "\x04\x0C\x00\x04\x2A\x02\x00\x53\x01\x00\x02\x02\x00\x46\x01\x00\x02\x00\xF0\x02\x08\x14\x22" + "\x28\x2E\x38\x3E\x32\x1C\x08\x02\x04" + "\x01\x03\xF0\x02\x01\x00\x04\x06\x06\x04\x06\x04\x04\x04\x08\x02\x00\x04\x06\x74\x02\x02\x00" + "\x00\x01\x01\x00\x37\x01\x01\x00\x23" + "\x01\x00\xF0\x02\x00\x00\x02\x02\x00\x04\x08\x0E\x18\x2A\x44\x4E\x3A\x20\xF0\x16\x0C\x06\x02" + "\x00\x03\x01\x03\x05\x0B\x07\x00\x00" + "\x0B\x03\x20\x00\x01\x64\x01\x03\x03\x01\x02\x00\x3B\x02\x02\x00\x5B\x02\x00\x00\x02\x00\xF0" + "\x01\x00\x02\x00\x0A\x22\x3A\x3C\x34" + "\x2A\x1A\x0A\x08\x08\x02\x90\x00\x00\x08\x02\x01\x02\x00\x00\x03\xF0\x39\x39\x3B\x3D\x3D\x37" + "\x2F\x2D\x25\x1F\x1B\x19\x15\x0D\x07" + "\x23\x01\x02\x1F\x00\x13\x01\xF0\x00\x01\x01\x02\x01\x00\x04\x10\x20\x2A\x38\x40\x2C\x0C\x02" + "\x90\x02\x02\x03\x03\x00\x01\x06\x01" + "\x04\xF0\x1D\x1D\x21\x19\x21\x27\x31\x2F\x39\x39\x3F\x41\x3D\x45\x4D\xC5\x4D\x43\x35\x2B\x21" + "\x17\x11\x0D\x09\x05\x01\x00\x29\x01" + "\x00\xF0\x03\x00\x01\x01\x01\x00\x06\x0E\x16\x2E\x46\x42\x2C\x18\x10\x60\x02\x05\x0A\x05\x01" + "\x03\xF0\x07\x07\x03\x0B\x01\x01\x00" + "\x05\x01\x0B\x01\x02\x0D\x0D\x0B\xF0\x09\x1B\x25\x2F\x37\x3F\x39\x37\x33\x2F\x25\x19\x11\x05" + "\x01\xC6\x00\x00\x02\x00\x00\x00\x02" + "\x02\x00\x00\x02\x00\xF0\x02\x01\x01\x00\x02\x06\x1A\x32\x34\x26\x1C\x12\x06\x04\x02\x10\x04" + "\xF0\x02\x02\x08\x08\x03\x01\x01\x02" + "\x00\x02\x02\x00\x04\x04\x02\xF0\x07\x01\x03\x07\x09\x07\x0F\x17\x1D\x23\x31\x35\x33\x37\x33" + "\xE4\x21\x13\x07\x00\x01\x01\x00\x00" + "\x02\x02\x00\x00\x00\x02\xF0\x00\x02\x02\x02\x00\x00\x00\x02\x14\x28\x38\x36\x1A\x08\x02\x10" + "\x00\xF0\x00\x01\x05\x01\x02\x02\x06" + "\x00\x02\x02\x07\x09\x03\x01\x00\xF0\x01\x00\x03\x00\x00\x00\x03\x01\x03\x01\x05\x0D\x11\x1D" + "\x27\xF0\x39\x43\x4B\x45\x2D\x17\x0B" + "\x03\x01\x00\x00\x02\x02\x00\x01\x84\x01\x00\x00\x01\x00\x00\x01\x00\x70\x02\x0A\x1C\x3C\x44" + "\x2E\x18\xF0\x03\x02\x04\x02\x02\x02" + "\x01\x01\x00\x02\x00\x04\x01\x00\x00\xF0\x04\x02\x08\x06\x04\x03\x02\x02\x01\x03\x01\x00\x07" + "\x05\x00\xF0\x03\x07\x09\x17\x29\x3B" + "\x37\x2D\x1F\x11\x03\x00\x00\x00\x02\x24\x02\x00\x23\x02\x00\x80\x02\x02\x00\x02\x02\x12\x2E" + "\x3C"; + +static const BYTE TEST_64X64_RED_PLANE[4096] = + "\x23\x1F\x1E\x1D\x1D\x1E\x1D\x1F\x23\x4A\x78\x71\x64\x58\x4B\x3E\x30\x29\x26\x24\x22\x21\x20" + "\x20\x20\x1D\x1E\x20\x1E\x1F\x20\x20" + "\x1F\x20\x21\x22\x1E\x1F\x1F\x1F\x1F\x1F\x1F\x1F\x1E\x1D\x1F\x20\x1F\x1F\x1F\x1E\x1E\x1F\x1F" + "\x20\x1E\x1F\x1F\x1F\x1E\x1D\x1E\x1C" + "\x3F\x2C\x28\x24\x21\x22\x20\x21\x25\x56\x94\x96\x97\x92\x8C\x86\x7F\x71\x61\x4D\x38\x2C\x29" + "\x26\x23\x21\x21\x20\x1F\x1F\x1E\x1E" + "\x20\x20\x20\x20\x1F\x20\x1F\x20\x1E\x1E\x1D\x1F\x1E\x1E\x21\x20\x1F\x1F\x1F\x1F\x1E\x1F\x1D" + "\x1F\x1F\x1F\x20\x1E\x1E\x1F\x1F\x1F" + "\x89\x83\x70\x5B\x44\x39\x2F\x27\x2C\x5B\x95\x96\x98\x98\x98\x98\x97\x97\x97\x97\x97\x8B\x76" + "\x5C\x47\x3B\x2F\x28\x23\x22\x21\x21" + "\x20\x1F\x1E\x1F\x20\x20\x20\x20\x1F\x1F\x21\x21\x1F\x1E\x1F\x1F\x1F\x1E\x20\x1F\x21\x20\x1F" + "\x1E\x1E\x1D\x1E\x1E\x1E\x1F\x21\x1E" + "\x8A\x8D\x8E\x8F\x8B\x7C\x6B\x5B\x4B\x66\x96\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x98\x90\x81\x70\x5F\x4C\x39\x2B\x24" + "\x21\x21\x1E\x1E\x1F\x1E\x20\x1F\x1E\x20\x21\x21\x1D\x1D\x1E\x1E\x21\x21\x20\x20\x21\x21\x1F" + "\x1F\x1F\x1E\x1E\x1E\x20\x1F\x1F\x1F" + "\x8A\x8D\x8E\x8F\x91\x92\x95\x92\x89\x8C\x97\x97\x99\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x98\x98\x98\x98\x95\x8D\x82\x6E\x4C" + "\x2F\x2A\x23\x20\x21\x1F\x1F\x20\x1F\x1F\x1E\x1D\x1D\x1D\x1D\x1F\x1F\x1E\x1E\x20\x20\x1E\x1E" + "\x1E\x1E\x1E\x1F\x20\x20\x20\x1F\x1E" + "\x8A\x8D\x8F\x90\x91\x92\x95\x94\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x97\x97\x98\x98" + "\x98\x98\x98\x98\x98\x98\x97\x97\x97" + "\x8D\x6C\x4B\x34\x27\x22\x21\x1E\x1D\x1F\x20\x1F\x1F\x1E\x1E\x20\x1F\x1F\x1E\x20\x1F\x1F\x1E" + "\x1F\x1E\x1F\x21\x24\x1F\x1F\x20\x20" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x97\x97\x97\x97" + "\x97\x97\x97\x98\x98\x98\x98\x98\x98" + "\x98\x98\x8E\x76\x51\x31\x24\x21\x1F\x1F\x1E\x1E\x1F\x1F\x1F\x1F\x20\x1E\x20\x21\x1E\x1F\x1F" + "\x1E\x1F\x20\x20\x20\x1D\x1E\x1F\x20" + "\x8A\x8D\x8F\x90\x91\x93\x95\x95\x95\x95\x96\x96\x98\x98\x98\x98\x98\x98\x98\x98\x97\x97\x96" + "\x97\x98\x97\x97\x8E\x7C\x6D\x64\x72" + "\x89\x96\x98\x98\x8E\x6B\x38\x25\x1E\x1E\x1F\x20\x1F\x20\x1F\x1F\x1F\x1F\x1F\x1E\x1E\x1E\x21" + "\x1F\x1F\x20\x20\x1F\x1D\x1E\x1D\x1E" + "\x8A\x8D\x8F\x90\x91\x93\x95\x95\x95\x95\x96\x96\x98\x98\x98\x98\x98\x98\x98\x98\x99\x98\x97" + "\x98\x96\x87\x62\x39\x2E\x2E\x2F\x2F" + "\x32\x45\x74\x92\x98\x98\x7D\x3E\x22\x20\x21\x22\x1E\x1E\x21\x1E\x1F\x1F\x20\x1E\x20\x1E\x1D" + "\x1E\x1F\x1E\x1E\x1F\x1E\x1E\x1D\x1E" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x97" + "\x98\x7D\x47\x31\x30\x49\x55\x5B\x52" + "\x3D\x30\x37\x5D\x92\x98\x97\x72\x2C\x23\x1F\x1E\x20\x1F\x21\x1F\x1F\x1F\x20\x21\x20\x1E\x1D" + "\x1D\x1E\x1E\x21\x20\x1F\x1F\x1E\x1D" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x97" + "\x91\x45\x2F\x3E\x6D\x8B\x91\x93\x8F" + "\x81\x59\x32\x31\x68\x97\x97\x94\x4D\x26\x22\x1E\x22\x21\x21\x1E\x1F\x20\x20\x21\x1E\x20\x1E" + "\x1F\x20\x1E\x1E\x20\x1F\x1F\x1F\x1E" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x97\x97\x93" + "\x56\x2F\x44\x81\x97\x98\x97\x94\x91" + "\x96\x96\x69\x33\x3A\x79\x97\x97\x81\x37\x24\x1E\x20\x20\x20\x20\x1E\x20\x1F\x1F\x1F\x1F\x1E" + "\x1E\x21\x1E\x1E\x20\x1F\x20\x1F\x1F" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x97\x98\x82" + "\x3E\x35\x6C\x96\x98\x96\x82\x63\x57" + "\x69\x88\x8F\x4C\x2F\x59\x92\x97\x91\x58\x28\x1F\x20\x1F\x20\x20\x1F\x1F\x1F\x20\x1F\x1F\x1F" + "\x1D\x1E\x1F\x1E\x20\x1F\x1F\x1E\x1E" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x97\x98\x72" + "\x36\x3F\x86\x98\x98\x8F\x57\x32\x2C" + "\x35\x62\x94\x6A\x2F\x4E\x8B\x97\x97\x75\x34\x22\x21\x1F\x1F\x20\x20\x21\x20\x1E\x21\x22\x1F" + "\x1D\x1F\x1F\x1E\x1F\x1F\x1F\x1F\x1E" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x97\x97\x97\x97\x98\x61" + "\x2E\x44\x93\x98\x97\x94\x70\x46\x3E" + "\x4D\x79\x97\x80\x31\x44\x82\x98\x98\x8E\x50\x26\x1F\x1E\x1E\x20\x21\x20\x1E\x1F\x21\x20\x1F" + "\x1D\x1E\x1F\x1D\x1F\x1D\x1D\x1F\x1F" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x97\x98\x98\x98\x98\x98\x97\x98\x69" + "\x31\x41\x8D\x98\x97\x97\x95\x8A\x80" + "\x8D\x97\x97\x7A\x2F\x45\x83\x98\x98\x97\x68\x2E\x20\x1E\x1F\x1F\x1E\x1E\x1F\x20\x1F\x1F\x1F" + "\x20\x1F\x1E\x1D\x1F\x1F\x1E\x1F\x20" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x98\x97\x97\x98\x98\x98\x98\x99\x97\x98\x77" + "\x38\x39\x7E\x98\x98\x98\x98\x97\x97" + "\x98\x98\x98\x61\x2F\x50\x8E\x98\x98\x98\x80\x3A\x21\x1F\x1F\x21\x1F\x20\x1F\x20\x1E\x1F\x1F" + "\x20\x20\x1F\x20\x21\x1E\x1D\x1F\x1D" + "\x8A\x8D\x8F\x90\x92\x93\x95\x95\x96\x96\x97\x97\x96\x8F\x94\x97\x98\x98\x97\x97\x97\x97\x89" + "\x47\x2E\x52\x8D\x97\x98\x98\x97\x98" + "\x98\x97\x7C\x3B\x31\x65\x97\x98\x98\x98\x96\x4D\x26\x1F\x20\x1D\x1D\x1D\x20\x20\x1F\x1F\x1F" + "\x1E\x1F\x1E\x20\x21\x1F\x1F\x1E\x20" + "\x8A\x8C\x8F\x90\x92\x93\x94\x95\x96\x96\x96\x97\x94\x76\x68\x87\x98\x98\x98\x98\x97\x97\x97" + "\x72\x2F\x34\x5D\x8B\x98\x98\x97\x98" + "\x95\x7D\x49\x2E\x47\x86\x98\x98\x99\x98\x98\x69\x27\x20\x1F\x1E\x1C\x1E\x20\x20\x1E\x1E\x1F" + "\x1D\x1F\x1E\x1F\x1E\x20\x20\x1F\x1F" + "\x8A\x8D\x8F\x90\x92\x93\x94\x95\x96\x96\x96\x97\x97\x7F\x49\x45\x72\x94\x98\x98\x98\x98\x98" + "\x94\x51\x2E\x31\x49\x6F\x83\x88\x7F" + "\x61\x3E\x2E\x32\x7C\x97\x98\x98\x98\x98\x98\x86\x2D\x23\x1F\x1E\x1F\x20\x21\x20\x1F\x1F\x1E" + "\x1D\x1E\x1E\x1F\x1D\x1E\x1F\x1F\x1F" + "\x8A\x8D\x8F\x90\x92\x93\x94\x95\x96\x96\x96\x97\x98\x94\x5D\x2E\x2C\x46\x76\x8D\x97\x98\x98" + "\x98\x91\x67\x3C\x2C\x2D\x2E\x2E\x2E" + "\x2D\x32\x4B\x79\x98\x98\x98\x98\x98\x97\x97\x97\x3F\x23\x1F\x1F\x1D\x1F\x1F\x1E\x1F\x1F\x1F" + "\x1F\x1D\x1F\x21\x20\x1F\x1F\x1F\x1F" + "\x8B\x8D\x8F\x91\x92\x93\x94\x95\x96\x96\x96\x97\x98\x98\x7A\x39\x28\x28\x32\x4E\x74\x8F\x98" + "\x98\x98\x94\x7A\x5E\x4C\x3A\x39\x42" + "\x52\x6A\x8B\x97\x98\x98\x98\x98\x98\x98\x96\x80\x39\x23\x20\x1F\x1E\x20\x20\x1F\x21\x20\x1F" + "\x1F\x20\x1F\x1F\x1F\x1E\x20\x1F\x20" + "\x8C\x8D\x8F\x91\x92\x93\x95\x95\x96\x96\x97\x97\x98\x98\x93\x62\x30\x29\x26\x27\x34\x4C\x72" + "\x93\x98\x98\x97\x94\x8C\x84\x83\x88" + "\x8E\x95\x98\x98\x98\x98\x98\x98\x97\x8C\x62\x3D\x25\x21\x20\x1F\x1E\x1F\x20\x20\x1F\x20\x20" + "\x20\x1F\x20\x1E\x1E\x20\x1F\x1F\x1F" + "\x8C\x8E\x90\x91\x93\x93\x95\x95\x96\x96\x97\x97\x98\x98\x97\x97\x8B\x64\x46\x33\x28\x27\x2B" + "\x3A\x61\x7E\x8C\x95\x98\x98\x98\x98" + "\x97\x97\x97\x98\x98\x97\x93\x89\x62\x38\x29\x22\x21\x1F\x1F\x1E\x20\x20\x20\x21\x1F\x1F\x20" + "\x1E\x1E\x20\x1F\x20\x1F\x1F\x1F\x1F" + "\x8D\x8F\x90\x92\x93\x94\x95\x95\x96\x96\x97\x97\x98\x98\x98\x98\x98\x96\x8A\x6F\x4B\x32\x29" + "\x27\x29\x34\x4A\x61\x78\x83\x8E\x97" + "\x98\x98\x97\x95\x86\x74\x5F\x44\x2B\x2A\x2C\x30\x21\x1E\x20\x1E\x1F\x1F\x1F\x20\x1F\x1D\x1F" + "\x1E\x1E\x1F\x20\x21\x1E\x20\x20\x1E" + "\x8D\x8F\x90\x92\x93\x94\x95\x96\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x97\x8C\x79\x57" + "\x37\x2C\x29\x28\x29\x35\x3C\x45\x50" + "\x57\x52\x4D\x4A\x3F\x34\x2A\x2A\x2F\x49\x6F\x70\x25\x1F\x1F\x1F\x20\x1F\x1E\x1F\x20\x1F\x20" + "\x1E\x1E\x1E\x20\x21\x1D\x1F\x1F\x1F" + "\x8E\x90\x91\x92\x93\x94\x95\x96\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x97\x98\x97\x98" + "\x94\x77\x58\x42\x32\x28\x28\x27\x28" + "\x27\x2A\x2A\x2A\x2C\x35\x42\x58\x85\x97\x97\x6B\x28\x20\x20\x20\x1E\x1F\x1F\x1D\x1F\x1F\x1F" + "\x1F\x1F\x1C\x1D\x1F\x1E\x1F\x1F\x20" + "\x8F\x90\x92\x93\x93\x95\x95\x96\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x98\x98\x96\x89\x74\x62\x59\x4D\x42" + "\x38\x3F\x48\x51\x62\x74\x86\x95\x98\x98\x92\x4E\x26\x21\x20\x1F\x1E\x1F\x20\x1D\x20\x20\x1F" + "\x1F\x1D\x1D\x1E\x1F\x20\x1F\x20\x20" + "\x8F\x90\x92\x93\x94\x95\x95\x96\x96\x97\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x98\x98\x98\x98\x98\x96\x92\x8D\x88" + "\x84\x87\x8B\x8F\x95\x98\x98\x98\x98\x98\x75\x35\x23\x1E\x20\x1E\x1D\x1F\x20\x20\x1F\x1D\x1E" + "\x20\x1D\x1F\x1E\x1F\x1F\x1E\x1F\x1F" + "\x90\x91\x92\x93\x94\x95\x96\x96\x96\x97\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x98\x98\x98\x98\x98\x98\x98\x97\x97" + "\x98\x98\x98\x98\x98\x98\x97\x98\x8B\x69\x39\x27\x20\x1E\x1E\x1D\x1F\x20\x1F\x1F\x1F\x1F\x1F" + "\x1E\x1D\x1F\x20\x1E\x20\x1F\x21\x20" + "\x90\x92\x93\x94\x95\x95\x96\x96\x96\x97\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x98\x98\x98\x98\x98\x98\x98\x97\x97" + "\x98\x98\x98\x98\x97\x97\x8D\x73\x4D\x2E\x24\x21\x1E\x1E\x1D\x1D\x1F\x1E\x1E\x1E\x1E\x20\x20" + "\x20\x1F\x1E\x1D\x1F\x20\x20\x1E\x1F" + "\x91\x92\x93\x94\x95\x95\x96\x96\x96\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x97\x98\x98\x98" + "\x98\x97\x97\x98\x98\x98\x98\x98\x98" + "\x99\x98\x99\x98\x8D\x68\x47\x32\x26\x23\x22\x20\x1C\x1D\x1E\x20\x1F\x1F\x1E\x20\x1D\x1E\x1E" + "\x1E\x1C\x1E\x1D\x1E\x1F\x20\x1E\x1E" + "\x92\x93\x92\x94\x95\x95\x95\x95\x97\x97\x97\x98\x99\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x99\x97\x97\x97\x98\x97\x97\x97\x93" + "\x8B\x83\x6D\x4E\x30\x29\x24\x22\x20\x1F\x20\x20\x1F\x1F\x1E\x20\x22\x20\x20\x20\x1C\x1E\x1F" + "\x1E\x1F\x1F\x20\x20\x1E\x20\x21\x1E" + "\x92\x93\x93\x94\x94\x8C\x80\x7D\x77\x77\x7D\x83\x8A\x8E\x92\x96\x98\x98\x98\x98\x98\x98\x98" + "\x97\x98\x97\x91\x8B\x81\x77\x68\x5B" + "\x4A\x38\x2B\x27\x22\x20\x20\x20\x1F\x1D\x1E\x1F\x1F\x1F\x1F\x20\x1F\x1E\x20\x20\x1F\x1E\x1F" + "\x20\x1E\x1E\x1D\x1E\x1F\x1F\x1F\x1E" + "\x92\x94\x94\x94\x69\x49\x3C\x38\x33\x33\x37\x3C\x42\x43\x45\x4C\x55\x5C\x65\x6D\x6B\x68\x65" + "\x61\x59\x4E\x47\x42\x3C\x34\x2A\x27" + "\x23\x23\x22\x20\x22\x20\x20\x20\x21\x1F\x20\x20\x1F\x1F\x1E\x21\x20\x1E\x1F\x20\x20\x1F\x20" + "\x1F\x1F\x1E\x1C\x1C\x20\x1F\x1F\x1F" + "\x92\x94\x91\x5D\x2D\x22\x1E\x20\x1E\x1F\x22\x23\x23\x23\x25\x25\x25\x25\x24\x27\x28\x26\x27" + "\x26\x23\x24\x23\x22\x21\x21\x1F\x21" + "\x20\x1F\x1E\x1F\x1F\x1F\x1E\x1F\x20\x20\x21\x21\x20\x1F\x1F\x21\x1F\x1F\x20\x20\x21\x1F\x20" + "\x1F\x1F\x20\x1F\x1F\x1D\x1F\x20\x1F" + "\x94\x95\x7A\x39\x23\x1F\x1D\x1D\x1D\x1F\x20\x1F\x1F\x20\x20\x1F\x1E\x20\x20\x1F\x20\x21\x20" + "\x20\x20\x1F\x20\x1F\x20\x1D\x1D\x1F" + "\x1E\x1F\x1F\x21\x22\x20\x1D\x1E\x20\x21\x21\x1F\x1F\x1D\x1D\x21\x1F\x1F\x1F\x20\x21\x1F\x20" + "\x1F\x1F\x21\x20\x1E\x1F\x1F\x1F\x1F" + "\x94\x94\x60\x2A\x20\x1D\x1D\x1F\x1D\x1F\x20\x21\x1F\x1E\x1F\x1F\x1F\x20\x20\x1E\x1F\x20\x20" + "\x1D\x20\x1F\x20\x20\x1F\x1F\x1E\x1F" + "\x1F\x1F\x1F\x1E\x1F\x20\x1F\x1F\x1E\x20\x1E\x1E\x1F\x1F\x1F\x20\x1F\x1F\x20\x21\x1E\x1F\x20" + "\x20\x1F\x1F\x21\x1F\x1F\x1F\x1F\x1D" + "\x94\x8E\x52\x26\x1F\x1D\x1E\x1E\x1E\x1F\x1F\x20\x1F\x1F\x1F\x20\x22\x21\x20\x20\x1F\x20\x20" + "\x1F\x1F\x1F\x20\x21\x21\x20\x20\x20" + "\x1F\x21\x1E\x1D\x20\x1F\x20\x1E\x1D\x1F\x1E\x1F\x1F\x1E\x1F\x1E\x1F\x1F\x1F\x1F\x1E\x1D\x1E" + "\x20\x20\x1F\x1F\x1E\x1F\x20\x1F\x1F" + "\x94\x8C\x4F\x25\x1D\x1F\x20\x1E\x1D\x1E\x1E\x1E\x1F\x1F\x20\x20\x21\x20\x20\x1F\x1F\x1E\x1E" + "\x20\x1E\x1E\x20\x20\x20\x1F\x20\x20" + "\x20\x1F\x1D\x1E\x20\x20\x1F\x1F\x20\x20\x20\x20\x1F\x1E\x1E\x1E\x1F\x20\x20\x1F\x1F\x1E\x1E" + "\x1E\x1E\x1E\x1E\x1E\x1F\x20\x1F\x1E" + "\x95\x8A\x4D\x25\x1C\x1D\x1D\x1E\x1E\x1E\x1F\x1F\x20\x21\x1F\x1D\x1F\x20\x21\x1F\x1C\x1E\x1F" + "\x1F\x1E\x20\x1F\x20\x21\x20\x20\x22" + "\x20\x20\x20\x20\x1E\x20\x1F\x1F\x20\x1E\x1E\x1C\x1C\x1E\x1F\x1E\x20\x1F\x1F\x20\x20\x1F\x1F" + "\x21\x1E\x20\x1E\x1E\x1E\x20\x20\x1E" + "\x96\x8F\x50\x25\x20\x1F\x1F\x1F\x20\x20\x20\x1F\x21\x22\x21\x21\x1F\x1F\x1F\x1F\x1E\x1F\x20" + "\x1F\x21\x20\x20\x21\x1F\x20\x20\x1F" + "\x1F\x1E\x1F\x1E\x1D\x1E\x1F\x20\x1F\x1E\x1D\x1D\x1D\x1E\x20\x1F\x1F\x1F\x1E\x1E\x21\x1F\x1F" + "\x1F\x1F\x1F\x1E\x1E\x1E\x1E\x1F\x20" + "\x96\x92\x56\x26\x1F\x1D\x1F\x20\x1D\x1F\x20\x21\x1E\x20\x1F\x1F\x20\x1F\x1E\x1E\x1F\x1E\x1F" + "\x1F\x20\x20\x20\x21\x1F\x21\x1F\x1F" + "\x1F\x1D\x1F\x1F\x1E\x1E\x1F\x21\x20\x1F\x1E\x1F\x20\x1F\x1E\x1F\x1E\x1E\x1E\x20\x1E\x1E\x1F" + "\x1E\x1F\x1F\x1F\x1F\x1E\x20\x1F\x1E" + "\x96\x96\x66\x2D\x1D\x1D\x1F\x21\x1F\x20\x20\x22\x1F\x1E\x1F\x1B\x1C\x20\x1F\x21\x1E\x1E\x1F" + "\x1F\x20\x1E\x1F\x20\x1F\x21\x20\x20" + "\x21\x20\x21\x1F\x20\x20\x20\x1E\x20\x1F\x1F\x1E\x1E\x1F\x20\x1E\x1E\x1F\x1E\x1D\x1E\x1F\x20" + "\x1E\x1F\x20\x1E\x1E\x1E\x20\x1F\x1E" + "\x96\x97\x7A\x36\x20\x21\x21\x20\x1F\x1E\x1F\x20\x1E\x1F\x20\x1F\x1D\x1D\x1E\x20\x1F\x1F\x1F" + "\x1E\x1F\x20\x20\x1F\x1F\x1F\x1F\x1E" + "\x1F\x21\x1E\x1D\x1F\x1F\x20\x20\x1E\x1E\x1F\x1F\x1E\x1E\x1F\x1E\x1F\x1F\x1F\x1F\x21\x20\x20" + "\x1D\x21\x20\x1F\x20\x1E\x20\x1F\x1E" + "\x97\x97\x8C\x3F\x22\x21\x20\x20\x1F\x21\x1F\x1E\x1F\x1F\x20\x1F\x20\x20\x20\x22\x1F\x20\x21" + "\x1F\x1E\x1F\x21\x1F\x1F\x20\x1F\x1E" + "\x1D\x1D\x1F\x1F\x1E\x1F\x20\x1F\x1E\x1F\x20\x22\x21\x1E\x1C\x1D\x1F\x20\x20\x1F\x1F\x1F\x1E" + "\x1D\x1E\x1E\x1E\x20\x1E\x1E\x1F\x1F" + "\x97\x97\x95\x51\x26\x22\x20\x22\x20\x1F\x1F\x20\x1E\x1F\x1E\x1F\x1F\x1F\x1F\x1E\x1E\x1F\x20" + "\x1F\x1F\x1E\x20\x20\x1E\x1F\x20\x1F" + "\x1F\x20\x20\x1F\x1F\x20\x20\x1F\x21\x20\x1F\x21\x21\x20\x1E\x1E\x21\x21\x1F\x1E\x1E\x1E\x1E" + "\x1F\x1D\x1D\x1E\x1F\x1E\x1D\x1F\x20" + "\x97\x98\x98\x79\x2B\x23\x1F\x1E\x1F\x20\x21\x20\x20\x21\x1E\x1D\x1F\x1E\x1F\x21\x20\x1F\x1F" + "\x1F\x20\x20\x20\x1E\x21\x20\x1F\x1F" + "\x1D\x1E\x1F\x1F\x1F\x1F\x1F\x1E\x1F\x20\x20\x20\x20\x1E\x1F\x1E\x1F\x21\x20\x1F\x1F\x1F\x1E" + "\x21\x20\x1E\x1F\x1E\x20\x1F\x1F\x1D" + "\x98\x98\x98\x93\x40\x25\x20\x1E\x20\x21\x1F\x20\x1F\x1F\x21\x20\x20\x1F\x1F\x1F\x1E\x20\x22" + "\x20\x1F\x20\x20\x1D\x21\x20\x1F\x1E" + "\x1E\x20\x1E\x1E\x20\x1F\x1F\x1F\x1E\x21\x20\x1F\x1E\x1D\x1F\x21\x1F\x1F\x1F\x20\x20\x1F\x1F" + "\x20\x20\x20\x1F\x1D\x1F\x1F\x1E\x1C" + "\x98\x98\x98\x97\x6A\x2F\x28\x26\x28\x26\x25\x26\x23\x24\x25\x23\x21\x22\x20\x22\x1F\x23\x21" + "\x1D\x1E\x20\x20\x1E\x1E\x1E\x1F\x1F" + "\x1F\x20\x21\x20\x20\x1F\x1F\x1E\x1E\x1F\x20\x1D\x1E\x1E\x1F\x1F\x20\x20\x1F\x20\x20\x1E\x20" + "\x1D\x1F\x20\x1F\x1E\x1F\x1F\x1E\x1E" + "\x98\x98\x98\x97\x93\x78\x6F\x6A\x64\x5F\x5B\x57\x4F\x4D\x4B\x49\x45\x3E\x38\x33\x2A\x2A\x29" + "\x26\x27\x23\x23\x21\x20\x1F\x1E\x1F" + "\x1D\x1F\x1F\x1D\x1D\x1E\x1E\x1E\x21\x20\x20\x1E\x21\x1E\x1F\x1F\x1E\x20\x1F\x1F\x1F\x1F\x20" + "\x1E\x20\x1E\x21\x20\x20\x1F\x1F\x20" + "\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x97\x95\x93\x8D\x85\x7D\x74\x6A\x62\x59" + "\x51\x46\x3B\x30\x2B\x2A\x27\x24\x24" + "\x22\x20\x1F\x1F\x1E\x1E\x1F\x1F\x20\x20\x20\x20\x1E\x1F\x1F\x20\x1F\x1F\x1F\x1F\x20\x1F\x1F" + "\x1F\x20\x1F\x20\x20\x1F\x20\x20\x20" + "\x98\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x97\x98\x98\x98\x98\x98\x97\x98\x97\x96\x92" + "\x8F\x89\x85\x80\x78\x6A\x59\x42\x30" + "\x2C\x28\x23\x21\x22\x1F\x20\x1E\x20\x21\x1F\x1F\x1F\x20\x20\x1F\x1F\x1F\x20\x1F\x1F\x1E\x1D" + "\x20\x1F\x21\x20\x1E\x1F\x1F\x1F\x1F" + "\x98\x97\x98\x98\x97\x98\x98\x97\x98\x98\x98\x98\x97\x98\x98\x98\x98\x98\x97\x97\x98\x98\x98" + "\x97\x98\x98\x98\x97\x97\x97\x97\x91" + "\x7D\x69\x54\x46\x38\x2F\x27\x26\x23\x22\x1E\x1D\x1F\x1E\x1E\x20\x20\x20\x1E\x1E\x1E\x1D\x1E" + "\x1F\x1E\x20\x21\x20\x21\x1E\x1C\x1F" + "\x98\x98\x98\x98\x97\x98\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x97\x97\x98\x98\x98" + "\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x97\x98\x96\x8E\x7E\x70\x62\x53\x41\x31\x27\x23\x22\x21\x1F\x20\x20\x20\x1F\x1E\x1E\x1E\x1F" + "\x1F\x21\x1E\x1F\x1F\x1E\x1F\x20\x1F" + "\x98\x98\x98\x97\x98\x98\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x97\x98\x98\x98\x98\x98\x98" + "\x98\x97\x98\x98\x98\x98\x98\x98\x98" + "\x97\x98\x98\x97\x97\x97\x95\x90\x88\x7C\x64\x45\x2D\x28\x25\x22\x21\x20\x1F\x1F\x1F\x1F\x20" + "\x21\x22\x20\x20\x20\x20\x20\x1F\x20" + "\x98\x97\x97\x98\x98\x98\x97\x97\x98\x98\x97\x97\x97\x98\x98\x97\x97\x97\x97\x98\x98\x98\x98" + "\x98\x97\x98\x98\x98\x97\x97\x98\x98" + "\x98\x98\x98\x98\x98\x97\x97\x98\x98\x97\x97\x97\x89\x6C\x4F\x3D\x30\x28\x24\x21\x1E\x1F\x1F" + "\x1E\x1D\x1D\x1F\x1F\x1D\x1E\x20\x1F" + "\x96\x95\x94\x96\x98\x98\x98\x98\x98\x97\x98\x98\x98\x98\x98\x98\x97\x97\x98\x98\x98\x98\x98" + "\x98\x98\x98\x98\x98\x98\x98\x98\x97" + "\x98\x98\x98\x98\x98\x98\x98\x98\x97\x98\x98\x98\x98\x98\x94\x86\x6E\x59\x42\x2E\x27\x24\x22" + "\x1F\x1E\x20\x20\x1E\x1D\x1E\x1F\x1E" + "\x4C\x4B\x4A\x4B\x4F\x55\x5B\x60\x69\x6F\x75\x7A\x7F\x86\x90\x97\x98\x98\x98\x98\x97\x97\x98" + "\x98\x98\x98\x98\x98\x98\x98\x98\x97" + "\x98\x98\x98\x98\x97\x97\x97\x97\x97\x97\x97\x98\x98\x98\x98\x98\x97\x92\x88\x7A\x5B\x3C\x29" + "\x25\x22\x20\x20\x1F\x1C\x20\x21\x1F" + "\x24\x24\x23\x25\x24\x23\x23\x25\x25\x28\x2A\x2A\x2C\x2D\x2E\x35\x47\x55\x62\x6E\x7B\x82\x87" + "\x8C\x92\x97\x98\x98\x98\x97\x97\x98" + "\x97\x98\x98\x98\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x97\x98\x98\x97\x97\x92\x78" + "\x54\x39\x2B\x22\x1E\x1F\x20\x1F\x1E" + "\x20\x1F\x1E\x1E\x20\x1F\x1F\x1F\x1F\x1F\x21\x23\x20\x21\x21\x24\x24\x25\x27\x2A\x2D\x35\x40" + "\x4A\x58\x66\x76\x83\x91\x97\x97\x98" + "\x98\x98\x98\x98\x98\x98\x97\x97\x98\x97\x97\x97\x97\x97\x97\x97\x98\x97\x98\x98\x98\x98\x98" + "\x94\x7C\x61\x44\x2F\x28\x22\x20\x20" + "\x1F\x1D\x1F\x20\x1F\x1E\x1E\x1F\x1E\x1E\x21\x20\x20\x20\x1E\x1F\x1F\x1F\x1E\x21\x22\x22\x23" + "\x24\x27\x2A\x35\x3E\x4A\x56\x6D\x82" + "\x94\x98\x97\x97\x98\x98\x98\x98\x98\x97\x97\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98\x98" + "\x98\x97\x94\x89\x74\x48\x2D\x26\x22" + "\x1F\x1E\x1E\x1F\x1E\x1F\x20\x20\x1F\x1F\x1F\x1F\x1F\x1F\x20\x1E\x1F\x1D\x1C\x1F\x20\x1F\x1F" + "\x1F\x22\x21\x22\x26\x23\x25\x27\x2C" + "\x31\x46\x5E\x77\x88\x92\x97\x98\x98\x97\x97\x98\x97\x97\x98\x98\x97\x98\x98\x98\x98\x98\x98" + "\x98\x98\x97\x98\x97\x96\x85\x5E\x42" + "\x1E\x1E\x1F\x20\x20\x20\x1F\x1D\x1E\x1F\x1D\x1F\x1F\x1F\x1F\x1F\x20\x21\x21\x20\x1F\x20\x20" + "\x1E\x1F\x1F\x20\x20\x20\x20\x20\x21" + "\x24\x25\x29\x2D\x43\x59\x6E\x81\x93\x98\x98\x98\x98\x98\x98\x98\x97\x98\x98\x98\x98\x98\x98" + "\x98\x98\x98\x98\x98\x98\x98\x96\x88"; + +static const BYTE TEST_64X64_RED_PLANE_RLE[3739] = + "\xF0\x23\x1F\x1E\x1D\x1D\x1E\x1D\x1F\x23\x4A\x78\x71\x64\x58\x4B\xF0\x3E\x30\x29\x26\x24\x22" + "\x21\x20\x20\x20\x1D\x1E\x20\x1E\x1F" + "\x86\x20\x20\x1F\x20\x21\x22\x1E\x1F\xF0\x1E\x1D\x1F\x20\x1F\x1F\x1F\x1E\x1E\x1F\x1F\x20\x1E" + "\x1F\x1F\x50\x1F\x1E\x1D\x1E\x1C\xF0" + "\x38\x1A\x14\x0E\x08\x08\x06\x04\x04\x18\x38\x4A\x66\x74\x82\xF0\x90\x9E\x90\x76\x52\x2C\x16" + "\x12\x0C\x06\x08\x06\x00\x02\x00\xF0" + "\x03\x03\x02\x00\x01\x03\x02\x02\x00\x02\x01\x01\x03\x00\x00\x33\x02\x04\x00\xD0\x02\x00\x00" + "\x03\x01\x02\x00\x02\x01\x00\x04\x02" + "\x06\xF0\x94\xAE\x90\x6E\x46\x2E\x1E\x0C\x0E\x0A\x02\x00\x02\x0C\x18\xF0\x24\x30\x4C\x6C\x94" + "\xBE\xBE\x9A\x6C\x48\x34\x1C\x10\x08" + "\x06\xF0\x06\x06\x00\x01\x03\x01\x02\x00\x02\x00\x02\x02\x08\x04\x02\xF0\x00\x03\x01\x00\x01" + "\x02\x00\x06\x02\x04\x01\x01\x03\x03" + "\x00\x40\x00\x00\x04\x01\xD3\x02\x14\x3C\x68\x8E\x86\x78\x68\x3E\x16\x02\x02\x00\x14\x02\xF0" + "\x1A\x44\x78\x92\x8C\x82\x6E\x52\x2E" + "\x14\x06\x02\x04\x00\x01\xF0\x01\x03\x00\x01\x01\x02\x00\x00\x03\x01\x01\x01\x04\x06\x00\xD0" + "\x02\x00\x02\x00\x02\x02\x02\x00\x00" + "\x04\x00\x03\x02\x04\xAA\x0C\x2C\x54\x6E\x7C\x4C\x02\x00\x02\x00\xF0\x10\x2E\x50\x6C\x82\x92" + "\x86\x50\x1C\x12\x0A\x04\x04\x02\x01" + "\xF0\x02\x02\x01\x05\x07\x00\x00\x01\x02\x03\x05\x03\x00\x01\x05\xA0\x01\x01\x01\x00\x02\x04" + "\x00\x02\x00\x01\xE5\x00\x00\x02\x02" + "\x00\x00\x00\x04\x1A\x14\x00\x00\x01\x00\x35\x01\x01\x00\xF0\x06\x16\x2A\x52\x96\xBC\x84\x50" + "\x28\x0C\x06\x04\x03\x03\x00\xF0\x04" + "\x04\x04\x02\x02\x02\x00\x02\x00\x00\x01\x02\x00\x02\x00\x70\x02\x04\x08\x01\x01\x02\x04\x04" + "\x5C\x02\x02\x00\x02\x00\x14\x01\xF0" + "\x00\x00\x00\x02\x02\x02\x16\x58\x86\x84\x54\x1E\x06\x06\x04\xF0\x00\x03\x01\x00\x02\x02\x01" + "\x02\x01\x04\x02\x01\x00\x02\x01\x80" + "\x02\x02\x01\x07\x03\x01\x01\x00\x04\x53\x01\x00\x00\x00\x01\x16\x00\xF0\x02\x00\x00\x01\x00" + "\x02\x00\x01\x13\x37\x55\x67\x4B\x1D" + "\x03\xF0\x14\x44\x7A\x74\x28\x08\x01\x01\x02\x04\x00\x02\x00\x00\x01\xF0\x02\x01\x05\x00\x01" + "\x04\x02\x00\x00\x00\x01\x00\x00\x03" + "\x03\x41\xF0\x04\x02\x02\x02\x03\x1F\x69\xA9\x9B\x7D\x69\x85\xAD\xA1\x47\xF0\x0B\x14\x5A\x8A" + "\x32\x08\x04\x04\x04\x01\x03\x04\x01" + "\x00\x00\xE0\x02\x00\x04\x00\x07\x01\x00\x03\x03\x00\x02\x00\x00\x00\x04\x53\x02\x00\x00\x00" + "\x02\x17\x00\xF0\x01\x00\x00\x00\x31" + "\x7F\x61\x11\x36\x4E\x58\x46\x16\x29\x79\xF0\x69\x0B\x00\x34\x68\x14\x06\x03\x07\x04\x02\x00" + "\x02\x00\x00\xA3\x00\x06\x00\x00\x00" + "\x01\x01\x00\x06\x02\x10\x01\x71\xF0\x0D\x6F\x2F\x1A\x7A\x84\x78\x70\x7A\x88\x52\x09\x57\x53" + "\x01\xF0\x00\x44\x42\x06\x06\x00\x04" + "\x04\x00\x01\x00\x02\x00\x00\x03\xB0\x04\x02\x04\x04\x00\x05\x00\x00\x00\x02\x02\x41\xF0\x01" + "\x01\x07\x75\x2B\x2A\x86\x54\x1A\x0C" + "\x02\x04\x2A\x7A\x6E\xF0\x04\x5B\x3B\x00\x06\x68\x22\x04\x00\x03\x01\x01\x04\x01\x00\x83\x01" + "\x03\x02\x01\x00\x01\x02\x00\x30\x02" + "\x00\x02\x51\xF0\x02\x21\x2F\x0C\x50\x2A\x02\x03\x29\x61\x73\x59\x1B\x4C\x32\xF0\x15\x3F\x09" + "\x00\x20\x42\x08\x02\x00\x01\x00\x00" + "\x02\x01\x00\xD0\x02\x00\x00\x02\x01\x05\x02\x00\x00\x00\x01\x01\x01\x61\xF0\x1F\x0F\x14\x34" + "\x04\x00\x0D\x55\x61\x55\x67\x4B\x0A" + "\x3C\x00\xF0\x15\x0D\x00\x0C\x3A\x18\x06\x02\x00\x01\x00\x02\x04\x02\x03\xC0\x04\x06\x00\x00" + "\x02\x00\x00\x01\x00\x00\x02\x00\x11" + "\xF0\x01\x01\x01\x00\x00\x21\x0F\x0A\x1A\x00\x01\x0A\x32\x28\x24\xF0\x30\x2E\x06\x2C\x04\x13" + "\x11\x02\x02\x32\x38\x08\x03\x01\x01" + "\xF0\x00\x02\x01\x03\x02\x00\x03\x00\x00\x01\x00\x01\x00\x03\x03\x20\x00\x02\x0E\xF0\x01\x00" + "\x00\x02\x02\x02\x00\x00\x10\x06\x05" + "\x0B\x00\x00\x06\xF0\x4A\x88\x84\x80\x3C\x00\x0B\x03\x02\x02\x00\x00\x12\x30\x10\xF0\x02\x00" + "\x02\x01\x05\x03\x02\x02\x03\x01\x00" + "\x06\x02\x01\x00\x50\x00\x04\x02\x00\x02\x0D\x24\x01\x00\xF0\x02\x00\x00\x1C\x0E\x0F\x1D\x00" + "\x02\x02\x06\x1A\x2E\x16\x02\xF0\x02" + "\x31\x00\x16\x16\x00\x00\x02\x30\x18\x02\x02\x00\x04\x02\xF0\x04\x00\x00\x01\x00\x00\x00\x02" + "\x02\x06\x04\x01\x01\x00\x05\x0C\xF0" + "\x03\x0F\x05\x01\x00\x00\x01\x03\x00\x01\x24\x1E\x15\x57\x15\xF0\x01\x00\x00\x00\x02\x00\x01" + "\x37\x4B\x04\x2A\x12\x00\x00\x00\xF0" + "\x2C\x26\x0A\x00\x02\x07\x03\x05\x02\x00\x02\x00\x00\x03\x01\x70\x01\x00\x00\x02\x04\x01\x06" + "\x33\x00\x01\x00\xF0\x01\x00\x00\x00" + "\x01\x00\x03\x31\x57\x1F\x00\x00\x02\x02\x00\x83\x00\x1C\x56\x02\x3B\x5F\x17\x00\xF0\x05\x33" + "\x65\x19\x2C\x42\x02\x00\x02\x00\x04" + "\x38\x02\x02\x01\xF0\x02\x01\x02\x00\x00\x01\x01\x00\x01\x00\x00\x01\x05\x02\x02\x20\x02\x01" + "\x39\x00\x02\x00\xF0\x06\x12\x3D\x83" + "\x4B\x07\x00\x00\x02\x02\x02\x44\x44\x0B\x57\xF0\x83\x51\x29\x1D\x31\x67\x7D\x35\x08\x6A\x22" + "\x00\x00\x01\x00\xF0\x00\x3A\x0C\x06" + "\x00\x00\x06\x04\x02\x00\x02\x02\x01\x00\x01\x70\x00\x00\x01\x03\x01\x00\x00\x0C\xF0\x02\x2A" + "\x28\x2D\x8B\x9B\x43\x15\x01\x00\x00" + "\x08\x80\x72\x16\xF0\x39\x83\xA9\xB3\xA1\x67\x17\x3A\x8E\x38\x02\x00\x00\x00\x01\xF0\x01\x22" + "\x24\x00\x00\x02\x03\x01\x03\x03\x00" + "\x00\x02\x04\x01\x70\x02\x04\x06\x02\x00\x00\x00\x58\x02\x00\x00\x02\x00\xF0\x08\x3A\x16\x07" + "\x3B\x87\x7D\x45\x11\x00\x00\x0E\x5A" + "\x7C\x64\x94\x3E\x18\x16\x28\x4A\x70\x80\x3C\x00\x83\x02\x01\x2D\x0B\x00\x02\x00\x02\xC0\x04" + "\x02\x00\x00\x06\x00\x03\x01\x01\x02" + "\x00\x02\x24\x02\x00\xF0\x02\x00\x00\x00\x02\x00\x00\x00\x32\x52\x10\x02\x17\x4D\x7F\xF0\x85" + "\x4B\x09\x00\x08\x3A\x6C\x80\x94\x94" + "\x8C\x78\x56\x1A\x02\x13\x00\xF0\x01\x17\x67\x85\x27\x03\x00\x00\x00\x01\x00\x02\x03\x00\x02" + "\x90\x02\x01\x02\x01\x01\x04\x01\x00" + "\x01\x68\x00\x02\x02\x00\x02\x00\xF0\x08\x6A\xB6\x76\x40\x18\x17\x49\x8D\xB1\x6D\x33\x15\x02" + "\x18\xF0\x28\x2A\x20\x12\x04\x01\x00" + "\x00\x01\x09\x1D\x69\xA7\x71\x35\xF0\x07\x03\x01\x01\x04\x02\x00\x02\x00\x01\x00\x03\x01\x00" + "\x02\x50\x04\x01\x00\x00\x00\x77\x02" + "\x02\x00\x02\x00\x02\x00\xF0\x02\x02\x1A\x64\x88\x78\x46\x16\x03\x25\x6F\x93\x83\x67\x3F\xF0" + "\x29\x13\x01\x02\x02\x00\x05\x23\x45" + "\x67\x89\x6D\x1B\x06\x1C\x53\x00\x01\x02\x00\x01\xC0\x00\x03\x01\x00\x00\x01\x02\x02\x01\x02" + "\x02\x01\x07\x28\x02\x00\xF0\x04\x1C" + "\x50\x82\x8E\x5C\x20\x06\x15\x43\x6F\x85\x8D\x91\x8D\xF0\x81\x8B\x93\x95\x8D\x7F\x69\x33\x08" + "\x3E\x86\x80\x08\x02\x01\xF0\x02\x02" + "\x00\x01\x01\x02\x04\x02\x00\x00\x01\x00\x00\x01\x01\x20\x01\x02\x4D\x02\x02\x02\x00\x03\xF0" + "\x18\x3C\x82\xBA\x96\x5E\x34\x12\x19" + "\x27\x3B\x4F\x5F\x4F\x45\xF0\x3F\x25\x02\x30\x5C\xAC\x9C\x50\x09\x06\x02\x02\x02\x03\x00\xE0" + "\x02\x03\x01\x00\x01\x02\x02\x03\x05" + "\x03\x02\x00\x00\x02\x7C\x02\x00\x02\x02\x00\x02\x00\xF0\x02\x00\x02\x00\x08\x42\x7C\x8E\x84" + "\x74\x62\x4C\x34\x22\x2A\xF0\x3C\x4E" + "\x6C\x7E\x88\x7A\x26\x02\x09\x39\x03\x02\x00\x01\x00\xF0\x00\x02\x00\x02\x02\x00\x00\x03\x02" + "\x02\x00\x04\x00\x02\x00\x04\x23\x02" + "\x00\x2E\x02\x00\xF0\x04\x1E\x48\x68\x72\x80\x8C\x98\x90\x86\x7C\x66\x48\x24\x06\xF0\x00\x00" + "\x39\x31\x05\x05\x00\x01\x01\x00\x00" + "\x06\x01\x05\x01\x63\x02\x00\x04\x00\x00\x01\x33\x02\x02\x00\x2F\x02\x00\x05\xF0\x04\x0C\x14" + "\x1E\x28\x22\x1A\x12\x06\x00\x01\x00" + "\x19\x5D\x77\xF0\x1B\x05\x00\x03\x01\x04\x02\x01\x01\x00\x04\x02\x03\x00\x00\x60\x04\x01\x02" + "\x02\x04\x02\x23\x00\x02\x1F\x00\x0F" + "\xF0\x01\x01\x13\x49\x7B\x75\x29\x0B\x03\x00\x01\x00\x00\x03\x01\xD0\x01\x01\x02\x02\x04\x04" + "\x01\x05\x02\x00\x02\x05\x01\x29\x02" + "\x00\x26\x02\x00\x23\x01\x00\x33\x01\x01\x00\xF0\x02\x02\x02\x00\x02\x00\x13\x5D\x8B\x81\x4D" + "\x15\x03\x01\x03\xF0\x01\x02\x06\x00" + "\x02\x00\x04\x01\x03\x03\x03\x05\x00\x00\x01\x40\x01\x00\x00\x01\xF4\x02\x02\x01\x00\x00\x00" + "\x01\x01\x02\x00\x00\x00\x02\x01\x00" + "\xF0\x02\x00\x00\x00\x02\x00\x00\x01\x00\x01\x01\x01\x09\x1B\x29\xF0\x57\x93\xB9\x7D\x45\x1F" + "\x0B\x07\x03\x00\x06\x04\x00\x00\x06" + "\xF0\x02\x04\x00\x01\x00\x02\x00\x06\x02\x06\x04\x01\x00\x06\x00\xF0\x00\x00\x02\x00\x01\x11" + "\x29\x2F\x3F\x3F\x33\x29\x1D\x11\x0B" + "\x26\x03\x00\xF0\x03\x02\x00\x0B\x19\x2B\x3F\x5D\x6F\x81\x95\x83\x4D\x1B\x11\xF0\x07\x03\x01" + "\x03\x03\x01\x00\x00\x02\x00\x05\x03" + "\x00\x00\x06\xB0\x00\x00\x04\x01\x01\x05\x03\x02\x01\x03\x00\xF0\x00\x02\x02\x00\x55\x85\x87" + "\x89\x87\x87\x8B\x8D\x8F\x95\x99\xF0" + "\x93\x85\x77\x65\x55\x59\x5F\x65\x6B\x7D\x91\x93\x91\x89\x85\x73\x7B\x67\x4D\x29\x11\x0D\x00" + "\xF0\x04\x04\x04\x02\x00\x00\x01\x02" + "\x02\x00\x01\x00\x02\x02\x02\x90\x01\x02\x00\x01\x03\x02\x00\x00\x02\xF0\x00\x00\x05\x6D\x77" + "\x4D\x3B\x2F\x29\x27\x29\x31\x3D\x3F" + "\x3F\xF0\x4D\x5F\x6D\x81\x8B\x85\x83\x7B\x75\x6B\x53\x47\x3F\x35\x25\xC3\x15\x0B\x05\x07\x07" + "\x01\x05\x01\x03\x01\x01\x02\x93\x00" + "\x02\x00\x01\x02\x02\x00\x02\x00\x70\x04\x06\x06\x05\x00\x02\x00\xF0\x04\x02\x2D\x47\x13\x05" + "\x01\x05\x01\x00\x03\x07\x07\x05\x09" + "\xF0\x0B\x0D\x09\x07\x0F\x0F\x09\x0D\x0B\x05\x09\x05\x05\x01\x07\xF0\x03\x03\x03\x00\x02\x04" + "\x06\x02\x01\x01\x00\x02\x00\x03\x01" + "\x75\x03\x03\x00\x00\x00\x01\x00\x70\x02\x02\x01\x04\x00\x01\x00\xF0\x00\x01\x33\x1D\x05\x03" + "\x00\x04\x00\x00\x00\x04\x00\x03\x01" + "\xF0\x00\x02\x00\x00\x01\x01\x01\x00\x05\x00\x00\x00\x02\x01\x04\xF0\x02\x00\x02\x00\x00\x05" + "\x05\x00\x04\x02\x03\x01\x05\x01\x00" + "\xF0\x04\x04\x01\x00\x00\x02\x02\x05\x00\x00\x02\x00\x03\x02\x02\x40\x00\x00\x00\x03\xF0\x00" + "\x0B\x1B\x07\x01\x00\x02\x01\x02\x00" + "\x01\x01\x00\x02\x00\xF0\x02\x06\x02\x00\x04\x00\x00\x00\x04\x01\x00\x00\x02\x04\x02\xF0\x04" + "\x02\x00\x04\x01\x01\x02\x01\x02\x01" + "\x01\x01\x00\x02\x00\xF0\x01\x00\x03\x00\x00\x01\x03\x00\x03\x03\x00\x02\x00\x03\x01\x40\x00" + "\x02\x00\x04\xF0\x00\x03\x05\x01\x03" + "\x04\x04\x00\x01\x01\x01\x03\x00\x00\x02\xF0\x00\x01\x01\x00\x01\x00\x03\x03\x02\x01\x01\x00" + "\x01\x01\x01\xF0\x00\x00\x02\x03\x01" + "\x02\x00\x02\x01\x02\x06\x02\x04\x02\x00\xF3\x00\x01\x00\x00\x02\x02\x00\x02\x02\x00\x03\x03" + "\x01\x01\x00\x10\x01\xF0\x02\x03\x03" + "\x00\x01\x03\x05\x00\x02\x00\x02\x02\x02\x04\x01\xF0\x05\x03\x00\x02\x00\x05\x00\x02\x01\x00" + "\x04\x01\x00\x02\x02\x83\x00\x04\x00" + "\x02\x06\x04\x03\x00\xB3\x03\x03\x07\x05\x00\x02\x00\x02\x01\x01\x02\x90\x06\x00\x04\x00\x00" + "\x01\x00\x02\x00\xF0\x02\x0A\x06\x00" + "\x08\x04\x04\x02\x04\x04\x02\x00\x02\x02\x04\xF0\x08\x00\x01\x03\x00\x04\x02\x02\x00\x06\x00" + "\x02\x02\x03\x00\xF0\x00\x05\x01\x03" + "\x01\x03\x01\x03\x00\x02\x01\x00\x01\x02\x02\xF0\x00\x02\x02\x01\x00\x01\x03\x02\x00\x00\x03" + "\x02\x01\x00\x00\x40\x00\x03\x01\x04" + "\xF0\x00\x06\x0C\x02\x01\x03\x00\x02\x05\x01\x00\x04\x05\x03\x03\xB3\x03\x02\x00\x01\x01\x02" + "\x01\x01\x00\x01\x00\xB3\x02\x01\x00" + "\x00\x01\x00\x02\x02\x00\x00\x02\xF0\x04\x06\x02\x03\x00\x01\x01\x00\x04\x05\x01\x00\x01\x00" + "\x00\x60\x02\x02\x00\x04\x00\x03\xF0" + "\x00\x08\x20\x0E\x03\x00\x00\x02\x04\x02\x00\x02\x02\x03\x00\x73\x07\x07\x02\x02\x06\x01\x00" + "\xF0\x03\x01\x01\x00\x00\x02\x02\x04" + "\x06\x04\x00\x04\x04\x02\x05\xF0\x00\x00\x02\x01\x03\x00\x04\x01\x00\x02\x00\x05\x00\x02\x02" + "\x63\x00\x00\x02\x01\x01\x00\xF0\x00" + "\x02\x28\x12\x06\x08\x04\x01\x00\x03\x01\x03\x01\x02\x02\xF0\x08\x02\x05\x01\x01\x02\x02\x00" + "\x01\x01\x04\x02\x01\x00\x03\xF0\x01" + "\x03\x03\x02\x05\x03\x01\x01\x00\x04\x03\x01\x00\x02\x00\xF0\x01\x01\x00\x02\x00\x02\x04\x06" + "\x02\x00\x01\x04\x00\x02\x04\x13\x00" + "\xF0\x02\x00\x24\x12\x04\x00\x01\x00\x00\x06\x00\x03\x02\x00\x00\xF0\x00\x06\x06\x04\x04\x00" + "\x02\x04\x02\x01\x01\x02\x00\x00\x02" + "\xF0\x00\x00\x03\x07\x02\x04\x01\x00\x00\x01\x00\x02\x02\x06\x06\xF0\x00\x05\x01\x00\x02\x02" + "\x00\x03\x01\x03\x00\x05\x03\x01\x00" + "\x40\x00\x03\x00\x02\xF0\x00\x00\x12\x24\x08\x02\x00\x04\x02\x03\x00\x04\x01\x00\x03\xF0\x00" + "\x01\x01\x01\x07\x01\x01\x01\x00\x02" + "\x01\x01\x02\x01\x01\xF0\x02\x02\x04\x06\x02\x00\x02\x02\x00\x00\x06\x02\x01\x01\x00\x63\x04" + "\x04\x02\x04\x02\x01\xA0\x00\x04\x01" + "\x01\x00\x01\x00\x01\x00\x02\xF0\x00\x02\x06\x50\x0A\x02\x01\x07\x01\x02\x04\x00\x04\x04\x00" + "\xF0\x03\x00\x01\x00\x06\x04\x00\x01" + "\x00\x02\x04\x00\x03\x06\x02\xF0\x01\x00\x03\x03\x01\x00\x00\x01\x01\x01\x03\x00\x02\x01\x01" + "\x63\x03\x02\x00\x03\x00\x02\xA0\x00" + "\x04\x06\x02\x02\x01\x04\x04\x00\x05\xF0\x02\x00\x00\x34\x2A\x04\x02\x00\x02\x02\x03\x00\x01" + "\x03\x06\xF0\x06\x02\x02\x00\x03\x03" + "\x02\x06\x02\x01\x00\x00\x01\x00\x00\xF0\x00\x01\x02\x04\x01\x01\x02\x00\x00\x02\x01\x02\x00" + "\x01\x03\xF0\x01\x00\x06\x00\x03\x01" + "\x02\x02\x00\x02\x01\x00\x04\x00\x01\x40\x01\x00\x01\x01\x03\xF0\x08\x54\x14\x10\x10\x10\x0A" + "\x0C\x0C\x08\x0A\x08\x06\x02\x06\xF0" + "\x02\x06\x02\x06\x01\x05\x01\x00\x00\x02\x05\x03\x00\x02\x02\xF0\x00\x06\x04\x00\x00\x00\x01" + "\x00\x03\x00\x03\x00\x02\x00\x03\xF0" + "\x02\x02\x00\x00\x00\x01\x02\x05\x01\x00\x00\x02\x00\x00\x00\x10\x04\x04\xF0\x52\x92\x8E\x88" + "\x78\x72\x6C\x62\x58\x52\x4C\x4C\x48" + "\x38\x30\xF0\x22\x16\x0E\x10\x12\x12\x06\x06\x06\x04\x02\x01\x00\x03\x01\xF0\x03\x05\x05\x01" + "\x01\x00\x06\x02\x00\x02\x06\x00\x00" + "\x00\x03\xF0\x00\x00\x01\x01\x02\x00\x02\x02\x03\x04\x04\x02\x00\x02\x04\x03\xF0\x02\x0A\x40" + "\x52\x5C\x68\x72\x7A\x82\x92\x94\x94" + "\x94\x90\x8E\xF0\x8A\x82\x80\x70\x60\x56\x3E\x30\x1A\x14\x14\x10\x0C\x0A\x0A\xF0\x02\x00\x04" + "\x02\x00\x02\x02\x01\x00\x00\x04\x05" + "\x02\x00\x02\xF0\x02\x01\x00\x00\x02\x00\x01\x02\x00\x02\x01\x00\x01\x02\x02\x10\x00\x39\x00" + "\x01\x00\xF0\x01\x02\x06\x0A\x16\x26" + "\x34\x48\x5A\x68\x72\x7C\x86\x94\xA0\xF0\x9A\x80\x64\x3C\x18\x14\x10\x08\x04\x08\x02\x02\x01" + "\x00\x02\xF0\x01\x01\x02\x02\x02\x01" + "\x00\x00\x02\x00\x01\x01\x03\x02\x01\x70\x04\x00\x03\x00\x01\x01\x01\x04\x5A\x01\x00\x00\x01" + "\x00\xF0\x01\x02\x04\x0C\x10\x1E\x26" + "\x30\x3E\x5A\x7C\xAA\xC2\xA2\x82\xF0\x62\x4A\x2C\x20\x0E\x10\x06\x02\x01\x03\x00\x03\x03\x02" + "\x02\xF0\x02\x03\x01\x01\x01\x02\x01" + "\x01\x01\x02\x04\x04\x01\x05\x00\x33\x00\x02\x00\x24\x01\x00\x29\x02\x00\x53\x02\x00\x00\x00" + "\x02\xF0\x0E\x34\x5E\x84\x90\x8C\x82" + "\x76\x5A\x3C\x1E\x12\x0C\x06\x06\xF0\x02\x00\x00\x00\x02\x00\x00\x02\x02\x00\x06\x03\x03\x01" + "\x05\x30\x02\x08\x00\x03\x3A\x01\x02" + "\x00\x53\x01\x00\x02\x02\x00\x28\x01\x00\xF0\x04\x12\x32\x4E\x66\x7A\x8E\x96\x7A\x44\x16\x0E" + "\x0C\x04\x02\x33\x00\x00\x02\x90\x04" + "\x02\x04\x02\x02\x04\x02\x01\x02\x55\x00\x01\x01\x02\x00\xA8\x01\x01\x01\x00\x00\x01\x00\x01" + "\x01\x00\xF0\x01\x01\x00\x00\x02\x00" + "\x00\x02\x02\x00\x04\x10\x20\x36\x66\xF0\xA4\xB8\x88\x54\x36\x1E\x10\x0A\x04\x01\x00\x01\x05" + "\x09\x05\x60\x01\x01\x05\x03\x02\x01" + "\xF0\x03\x03\x05\x03\x00\x00\x02\x02\x00\x01\x02\x02\x02\x00\x00\x54\x02\x00\x00\x02\x00\x94" + "\x02\x00\x00\x00\x02\x02\x00\x01\x00" + "\xF0\x02\x02\x00\x01\x02\x02\x02\x1E\x58\x8A\x92\x7C\x62\x3C\x1A\xC0\x12\x0A\x06\x02\x02\x06" + "\x02\x01\x00\x00\x01\x01\xF0\x93\x93" + "\x93\x95\x91\x85\x79\x6F\x5D\x4F\x45\x3B\x31\x23\x0F\x8D\x01\x02\x02\x00\x00\x01\x01\x00\x13" + "\x01\xF0\x00\x01\x01\x00\x00\x00\x08" + "\x24\x52\x72\x8C\x98\x68\x30\x0E\x90\x0C\x08\x00\x00\x02\x01\x04\x04\x02\xF0\x4F\x4D\x4D\x4B" + "\x55\x63\x6F\x75\x87\x8D\x95\x9F\xA5" + "\xB1\xC3\xF0\xC3\xA1\x85\x6B\x53\x37\x29\x21\x17\x0B\x01\x00\x00\x00\x01\x49\x01\x02\x01\x00" + "\x14\x01\xF0\x00\x0C\x20\x3A\x78\xAC" + "\x9E\x5E\x2E\x16\x04\x01\x06\x00\x03\x10\x01\xF0\x07\x09\x09\x0D\x07\x07\x07\x0B\x0B\x11\x11" + "\x0D\x17\x17\x19\xF0\x21\x45\x5F\x75" + "\x87\x9B\x99\x8D\x83\x73\x61\x43\x29\x0D\x00\xC6\x00\x00\x02\x00\x00\x00\x02\x02\x00\x00\x02" + "\x00\xF0\x02\x01\x00\x02\x02\x0C\x40" + "\x80\x86\x6C\x44\x22\x12\x04\x02\x10\x04\xF0\x01\x03\x02\x04\x01\x01\x01\x00\x01\x01\x00\x05" + "\x00\x01\x05\xF0\x09\x09\x0B\x11\x11" + "\x15\x25\x39\x4B\x61\x77\x81\x89\x8D\x81\xE4\x53\x2B\x07\x00\x01\x01\x00\x00\x02\x02\x00\x00" + "\x00\x02\x34\x00\x02\x00\x90\x08\x36" + "\x66\x8A\x8A\x40\x16\x0C\x04\xF0\x00\x02\x01\x01\x01\x02\x04\x02\x02\x02\x03\x01\x01\x01\x04" + "\x33\x01\x00\x03\xF0\x05\x07\x09\x09" + "\x11\x25\x2F\x4D\x61\x8B\xAB\xC5\xA3\x71\x3F\x44\x1F\x0B\x01\x00\x66\x01\x01\x00\x00\x01\x00" + "\x80\x02\x06\x1E\x46\x9C\xB0\x70\x40" + "\xF0\x01\x00\x02\x02\x04\x02\x01\x05\x01\x00\x03\x00\x00\x00\x01\xF0\x02\x02\x08\x0A\x02\x01" + "\x02\x02\x01\x05\x03\x03\x0B\x05\x09" + "\xF0\x0D\x15\x19\x41\x69\x93\x89\x71\x51\x2D\x09\x02\x02\x00\x02\x2A\x02\x00\x70\x02\x00\x02" + "\x04\x26\x70\x8C"; + +static const BYTE TEST_64X64_GREEN_PLANE[4096] = + "\x2A\x25\x23\x23\x23\x23\x23\x24\x2B\x60\xA2\x97\x84\x75\x62\x50\x3C\x34\x30\x2C\x29\x28\x26" + "\x25\x25\x23\x23\x25\x24\x24\x25\x25" + "\x25\x25\x26\x27\x25\x24\x25\x25\x27\x24\x24\x24\x24\x24\x25\x25\x24\x25\x26\x25\x23\x24\x24" + "\x25\x23\x24\x24\x24\x24\x22\x23\x21" + "\x51\x37\x31\x2C\x29\x28\x27\x27\x2F\x73\xC9\xCC\xCB\xC5\xBD\xB5\xAA\x99\x80\x66\x48\x38\x33" + "\x2E\x29\x27\x27\x26\x25\x25\x23\x23" + "\x26\x26\x25\x27\x25\x25\x25\x26\x23\x24\x23\x25\x24\x23\x26\x25\x25\x25\x25\x24\x23\x25\x23" + "\x24\x24\x24\x25\x24\x26\x24\x24\x24" + "\xBA\xB3\x97\x79\x58\x48\x3A\x31\x37\x79\xCA\xCC\xCD\xCD\xCD\xCD\xCC\xCC\xCC\xCC\xCC\xBC\x9D" + "\x7A\x5C\x4C\x3D\x30\x2B\x29\x28\x27" + "\x25\x24\x24\x23\x25\x26\x25\x25\x23\x24\x27\x27\x24\x24\x24\x24\x25\x25\x25\x25\x26\x27\x25" + "\x23\x23\x23\x25\x24\x22\x24\x26\x26" + "\xBB\xBE\xC0\xC2\xBC\xA7\x90\x78\x63\x87\xCB\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xC2\xAD\x96\x7E\x63\x48\x36\x2C" + "\x27\x27\x24\x24\x25\x24\x25\x24\x22\x25\x26\x26\x23\x23\x23\x23\x27\x26\x25\x26\x26\x26\x24" + "\x24\x24\x24\x23\x22\x25\x24\x24\x24" + "\xBB\xBE\xC0\xC2\xC5\xC7\xC8\xC3\xBA\xBD\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xC8\xBD\xB0\x93\x65" + "\x3A\x33\x2A\x28\x27\x24\x23\x25\x24\x24\x23\x24\x24\x22\x21\x24\x24\x23\x23\x25\x26\x25\x25" + "\x23\x23\x25\x24\x24\x26\x25\x24\x24" + "\xBB\xBE\xC0\xC3\xC4\xC7\xC8\xC8\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCC" + "\xBE\x90\x62\x42\x30\x28\x27\x22\x23\x24\x25\x25\x25\x25\x24\x24\x25\x25\x24\x26\x24\x24\x23" + "\x23\x25\x25\x27\x29\x24\x24\x25\x26" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC" + "\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCC\xC0\x9D\x6A\x3F\x2E\x27\x24\x24\x24\x24\x25\x24\x24\x24\x25\x24\x25\x27\x24\x25\x25" + "\x24\x25\x25\x26\x25\x23\x23\x25\x26" + "\xBB\xBE\xC0\xC3\xC4\xC7\xC8\xC9\xCB\xCA\xCC\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCC" + "\xCC\xCD\xCC\xCC\xC1\xA8\x92\x86\x99" + "\xB9\xCB\xCD\xCD\xBF\x8F\x47\x2E\x26\x25\x24\x25\x24\x26\x25\x25\x24\x25\x25\x24\x23\x24\x26" + "\x24\x25\x27\x25\x24\x24\x23\x23\x24" + "\xBB\xBE\xC0\xC3\xC4\xC7\xC8\xC9\xCA\xCA\xCC\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCA\xB6\x83\x48\x3B\x39\x3B\x3B" + "\x40\x58\x9B\xC5\xCD\xCD\xA9\x52\x2B\x26\x26\x27\x25\x23\x26\x24\x24\x25\x25\x23\x25\x23\x22" + "\x23\x25\x24\x24\x24\x24\x22\x23\x25" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC" + "\xCD\xA8\x5D\x3D\x3D\x5F\x71\x79\x6C" + "\x50\x3D\x47\x7A\xC5\xCD\xCC\x98\x37\x2A\x26\x24\x25\x25\x27\x25\x24\x24\x25\x26\x25\x23\x23" + "\x22\x23\x23\x26\x26\x24\x24\x24\x23" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC" + "\xC3\x59\x3B\x50\x92\xBB\xC4\xC7\xC1" + "\xAE\x75\x40\x3D\x8C\xCC\xCD\xC8\x65\x30\x28\x25\x27\x26\x26\x25\x24\x25\x25\x26\x24\x25\x25" + "\x25\x24\x23\x24\x25\x24\x24\x24\x23" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xC7" + "\x70\x3B\x59\xAE\xCC\xCD\xCC\xC9\xC4" + "\xCB\xCA\x8A\x41\x4C\xA1\xCC\xCD\xB0\x45\x2B\x23\x25\x25\x26\x24\x23\x25\x24\x24\x24\x25\x24" + "\x23\x26\x25\x23\x24\x24\x24\x23\x24" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xAF" + "\x50\x42\x90\xCA\xCD\xCB\xB0\x84\x74" + "\x8B\xB7\xC0\x64\x3C\x76\xC7\xCD\xC3\x74\x31\x26\x25\x25\x26\x26\x24\x25\x25\x25\x24\x26\x26" + "\x23\x23\x26\x24\x26\x25\x24\x23\x23" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\x98" + "\x44\x51\xB4\xCD\xCD\xC0\x73\x3E\x38" + "\x42\x83\xC8\x8F\x3A\x66\xBB\xCD\xCB\x9C\x42\x29\x27\x26\x24\x25\x26\x27\x26\x23\x26\x28\x25" + "\x22\x24\x25\x24\x26\x25\x24\x24\x23" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCD\xCD\x80" + "\x39\x58\xC7\xCD\xCC\xC9\x96\x5B\x51" + "\x67\xA3\xCD\xAC\x3D\x58\xAF\xCD\xCD\xBF\x69\x30\x25\x23\x25\x25\x26\x25\x25\x25\x26\x26\x26" + "\x24\x24\x25\x23\x24\x22\x23\x24\x24" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCD\xCC\xCD\x8C" + "\x40\x55\xBE\xCD\xCC\xCC\xC9\xBA\xAD" + "\xC0\xCC\xCD\xA5\x3B\x5A\xB1\xCD\xCD\xCC\x8A\x3B\x28\x24\x25\x25\x23\x24\x25\x26\x25\x26\x24" + "\x25\x25\x24\x24\x24\x24\x23\x24\x25" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\x9E" + "\x47\x4A\xA9\xCD\xCD\xCD\xCD\xCC\xCC" + "\xCE\xCD\xCD\x80\x3B\x6A\xBF\xCD\xCD\xCD\xAC\x4B\x2A\x26\x25\x26\x23\x26\x25\x25\x23\x24\x25" + "\x25\x25\x25\x25\x26\x24\x23\x24\x22" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCB\xCB\xCC\xCC\xCA\xC1\xC7\xCC\xCD\xCD\xCD\xCD\xCC\xCD\xBA" + "\x5E\x39\x6B\xBE\xCC\xCD\xCD\xCD\xCD" + "\xCD\xCB\xA8\x4D\x3F\x86\xCC\xCD\xCD\xCD\xC9\x63\x2D\x27\x26\x23\x22\x24\x26\x25\x25\x25\x23" + "\x23\x24\x23\x26\x26\x24\x25\x23\x24" + "\xBA\xBD\xC0\xC2\xC4\xC6\xC8\xC8\xCA\xCB\xCB\xCC\xC8\x9E\x8B\xB5\xCD\xCD\xCD\xCD\xCC\xCC\xCD" + "\x9A\x3B\x42\x7C\xBB\xCD\xCD\xCD\xCD" + "\xC9\xA9\x5F\x3A\x5D\xB4\xCD\xCD\xCC\xCC\xCD\x8C\x30\x27\x26\x23\x22\x23\x25\x25\x23\x23\x25" + "\x23\x24\x24\x25\x23\x25\x25\x24\x24" + "\xBB\xBE\xC0\xC3\xC4\xC6\xC8\xC9\xCA\xCB\xCB\xCC\xCC\xAA\x5E\x59\x99\xC8\xCD\xCD\xCD\xCD\xCD" + "\xC8\x6C\x3A\x3F\x5F\x94\xB1\xB9\xAA" + "\x80\x50\x3A\x40\xA7\xCC\xCD\xCD\xCD\xCD\xCD\xB6\x38\x2A\x25\x23\x24\x26\x26\x25\x26\x24\x23" + "\x22\x24\x24\x24\x23\x24\x24\x24\x24" + "\xBB\xBE\xC0\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCB\xCC\xCD\xC7\x7B\x3B\x37\x5B\x9E\xBF\xCC\xCD\xCD" + "\xCD\xC4\x89\x4D\x37\x39\x3A\x3C\x3B" + "\x39\x41\x60\xA2\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\x52\x2C\x27\x24\x22\x25\x24\x23\x24\x25\x25" + "\x24\x22\x24\x26\x25\x24\x23\x23\x24" + "\xBC\xBF\xC1\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCB\xCC\xCD\xCD\xA4\x4B\x30\x32\x40\x67\x9B\xC0\xCD" + "\xCD\xCD\xC8\xA5\x7D\x62\x4C\x49\x57" + "\x6B\x8D\xBB\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCA\xAC\x4A\x2A\x25\x25\x23\x25\x25\x25\x26\x26\x24" + "\x25\x25\x25\x24\x25\x23\x25\x25\x25" + "\xBC\xBF\xC1\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCC\xCD\xCD\xC6\x82\x3C\x34\x2F\x30\x42\x63\x98" + "\xC6\xCD\xCD\xCC\xC7\xBC\xB2\xB0\xB7" + "\xC0\xC9\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xBC\x81\x4E\x2C\x27\x27\x25\x23\x24\x26\x25\x25\x26\x25" + "\x26\x25\x25\x23\x24\x25\x24\x24\x25" + "\xBD\xC0\xC2\xC4\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCC\xCD\xCD\xCD\xCC\xBA\x85\x59\x40\x31\x31\x36" + "\x4B\x82\xA8\xBC\xC9\xCD\xCD\xCD\xCD" + "\xCC\xCC\xCC\xCD\xCD\xCD\xC8\xB8\x82\x47\x34\x2B\x27\x25\x26\x25\x24\x24\x26\x26\x25\x25\x25" + "\x23\x23\x25\x25\x27\x24\x24\x24\x26" + "\xBE\xC0\xC3\xC4\xC6\xC8\xC8\xC9\xCA\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCB\xBA\x94\x64\x3F\x33" + "\x32\x35\x43\x61\x81\x9F\xB0\xC0\xCB" + "\xCD\xCD\xCC\xC9\xB7\x9B\x7E\x5A\x36\x34\x37\x3D\x29\x25\x25\x26\x24\x25\x24\x25\x24\x23\x24" + "\x22\x22\x25\x25\x27\x23\x25\x25\x25" + "\xBF\xC1\xC3\xC5\xC6\xC8\xC8\xCA\xCA\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xBD\xA2\x72" + "\x47\x36\x34\x33\x34\x43\x4D\x5A\x67" + "\x73\x6B\x66\x61\x53\x42\x35\x34\x3B\x5F\x95\x97\x2E\x25\x24\x25\x25\x25\x24\x24\x25\x24\x25" + "\x23\x23\x24\x25\x26\x22\x25\x25\x25" + "\xC0\xC2\xC4\xC5\xC7\xC8\xC9\xCA\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCC\xCD" + "\xC7\x9E\x75\x57\x40\x33\x33\x32\x32" + "\x31\x32\x34\x34\x37\x42\x55\x74\xB2\xCC\xCC\x90\x32\x25\x24\x25\x23\x24\x26\x23\x25\x25\x25" + "\x24\x24\x21\x21\x24\x23\x25\x25\x26" + "\xC0\xC2\xC4\xC6\xC7\xC8\xC9\xCA\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCA\xB8\x9C\x83\x76\x66\x56" + "\x4A\x51\x5E\x6B\x83\x9B\xB5\xC9\xCD\xCD\xC5\x66\x2E\x26\x25\x25\x25\x25\x25\x23\x25\x25\x25" + "\x24\x23\x22\x24\x24\x26\x27\x25\x25" + "\xC1\xC3\xC4\xC6\xC8\xC8\xC9\xCA\xCB\xCC\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCB\xC5\xBE\xB7" + "\xB2\xB5\xBB\xC1\xCA\xCD\xCD\xCD\xCD\xCD\x9C\x44\x27\x25\x26\x26\x22\x23\x25\x24\x24\x23\x25" + "\x25\x24\x24\x25\x24\x24\x25\x25\x24" + "\xC2\xC4\xC5\xC7\xC8\xC9\xCA\xCA\xCB\xCC\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xBC\x8C\x48\x2D\x25\x24\x24\x22\x25\x26\x24\x24\x25\x24\x25" + "\x24\x22\x25\x26\x24\x25\x24\x26\x26" + "\xC3\xC4\xC6\xC8\xC8\xC9\xCA\xCB\xCB\xCC\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC" + "\xCD\xCD\xCD\xCD\xCC\xCC\xBE\x9A\x63\x39\x2B\x26\x23\x24\x24\x26\x24\x25\x25\x23\x23\x25\x25" + "\x25\x25\x25\x24\x24\x25\x24\x23\x24" + "\xC4\xC5\xC7\xC8\xC8\xC9\xCA\xCB\xCB\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCC\xCD\xCD\xCD\xBE\x8C\x5D\x40\x2C\x2A\x29\x26\x22\x23\x24\x25\x24\x24\x26\x25\x24\x23\x23" + "\x23\x22\x23\x23\x24\x23\x25\x24\x24" + "\xC4\xC6\xC7\xC8\xC9\xC9\xC9\xCA\xCC\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCE\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCC\xCC\xCD\xCD\xCC\xCC\xC7" + "\xBC\xAF\x92\x67\x3B\x32\x2D\x28\x26\x25\x26\x25\x25\x26\x25\x25\x27\x25\x25\x25\x23\x23\x24" + "\x23\x24\x25\x25\x25\x23\x25\x26\x24" + "\xC5\xC7\xC8\xC8\xC8\xBD\xAD\xA7\xA1\xA0\xA7\xB0\xB9\xC0\xC6\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCB\xC4\xBA\xAF\x9F\x8B\x78" + "\x61\x48\x35\x30\x2B\x27\x26\x25\x24\x24\x23\x24\x24\x24\x24\x26\x24\x23\x24\x27\x24\x23\x24" + "\x24\x24\x24\x22\x24\x25\x25\x26\x24" + "\xC6\xC8\xC8\xC8\x8C\x5E\x4D\x49\x42\x44\x47\x4E\x54\x58\x5C\x63\x6F\x7B\x87\x91\x8E\x8A\x86" + "\x81\x75\x67\x5C\x55\x4E\x41\x34\x31" + "\x2C\x2B\x29\x25\x28\x26\x25\x24\x26\x25\x25\x25\x24\x25\x25\x26\x25\x25\x24\x25\x25\x24\x24" + "\x24\x25\x23\x21\x23\x25\x25\x27\x25" + "\xC7\xC8\xC3\x7B\x35\x2B\x26\x26\x24\x27\x28\x29\x29\x29\x2C\x2D\x2D\x2D\x2D\x30\x2F\x2F\x30" + "\x2F\x2C\x2D\x2B\x29\x27\x26\x26\x26" + "\x26\x24\x24\x24\x24\x24\x24\x25\x25\x25\x27\x26\x24\x24\x24\x25\x24\x24\x26\x25\x26\x23\x26" + "\x24\x24\x25\x24\x25\x22\x23\x25\x25" + "\xC8\xC8\xA4\x49\x29\x25\x22\x22\x24\x25\x26\x25\x24\x25\x25\x24\x25\x26\x27\x25\x26\x26\x26" + "\x25\x25\x25\x26\x26\x25\x23\x24\x25" + "\x25\x23\x25\x26\x27\x25\x24\x25\x26\x27\x27\x25\x22\x22\x23\x26\x24\x24\x24\x25\x26\x24\x26" + "\x25\x23\x25\x25\x25\x25\x25\x26\x24" + "\xC8\xC8\x80\x36\x26\x23\x22\x23\x23\x24\x27\x27\x24\x24\x25\x24\x24\x27\x26\x24\x24\x25\x25" + "\x24\x25\x24\x25\x25\x24\x25\x25\x24" + "\x25\x25\x25\x24\x23\x24\x25\x24\x24\x25\x23\x23\x24\x25\x24\x25\x24\x25\x27\x27\x24\x24\x26" + "\x26\x24\x26\x27\x25\x25\x25\x24\x26" + "\xC9\xC1\x6C\x30\x25\x22\x23\x23\x23\x24\x25\x26\x24\x24\x25\x26\x26\x27\x26\x26\x24\x24\x25" + "\x24\x24\x24\x26\x26\x25\x25\x25\x25" + "\x24\x26\x23\x23\x25\x24\x25\x25\x23\x24\x23\x24\x25\x23\x24\x23\x25\x25\x24\x24\x24\x23\x24" + "\x25\x26\x25\x25\x25\x24\x25\x24\x24" + "\xC9\xBE\x68\x2E\x24\x23\x25\x23\x23\x24\x24\x24\x24\x25\x25\x26\x27\x25\x25\x25\x24\x23\x23" + "\x24\x25\x25\x26\x25\x25\x25\x26\x26" + "\x25\x24\x22\x23\x26\x25\x24\x24\x25\x25\x25\x25\x24\x23\x23\x25\x25\x26\x25\x25\x24\x24\x23" + "\x23\x23\x24\x23\x25\x24\x25\x24\x24" + "\xCA\xBB\x66\x2D\x22\x23\x23\x24\x23\x24\x25\x25\x27\x26\x24\x23\x24\x25\x27\x24\x22\x24\x25" + "\x24\x25\x27\x25\x24\x26\x26\x26\x28" + "\x25\x25\x25\x25\x23\x25\x26\x25\x25\x24\x24\x21\x22\x23\x25\x25\x26\x24\x24\x27\x24\x26\x25" + "\x26\x24\x25\x24\x24\x25\x25\x25\x23" + "\xCB\xC0\x6A\x2D\x25\x25\x26\x24\x25\x25\x25\x24\x27\x27\x26\x26\x24\x25\x25\x25\x23\x25\x25" + "\x26\x26\x25\x25\x26\x24\x26\x25\x25" + "\x24\x23\x24\x23\x23\x23\x25\x24\x25\x23\x23\x22\x25\x25\x27\x24\x24\x26\x23\x23\x26\x24\x26" + "\x25\x24\x23\x23\x24\x25\x23\x25\x26" + "\xCB\xC6\x71\x2F\x25\x23\x25\x25\x23\x24\x25\x26\x24\x25\x24\x25\x26\x24\x24\x23\x25\x25\x25" + "\x24\x26\x25\x25\x26\x24\x26\x24\x25" + "\x25\x23\x24\x25\x23\x23\x25\x26\x25\x24\x24\x24\x26\x26\x25\x26\x22\x23\x23\x25\x23\x24\x25" + "\x25\x24\x24\x25\x25\x24\x25\x25\x24" + "\xCB\xCB\x87\x39\x25\x22\x24\x26\x25\x24\x24\x27\x24\x24\x24\x20\x23\x25\x24\x26\x24\x24\x24" + "\x24\x25\x23\x24\x25\x25\x28\x26\x26" + "\x27\x27\x26\x25\x25\x26\x26\x25\x23\x24\x24\x24\x24\x24\x25\x25\x23\x24\x23\x25\x22\x24\x27" + "\x24\x24\x26\x25\x24\x26\x25\x24\x23" + "\xCC\xCC\xA6\x47\x25\x26\x26\x25\x25\x22\x24\x25\x24\x25\x25\x24\x23\x22\x23\x26\x24\x23\x25" + "\x23\x24\x25\x25\x24\x23\x24\x24\x23" + "\x23\x26\x23\x22\x24\x25\x25\x26\x24\x23\x24\x24\x23\x23\x25\x23\x26\x24\x25\x24\x26\x25\x24" + "\x22\x26\x25\x24\x25\x23\x25\x25\x23" + "\xCC\xCC\xBE\x52\x2A\x26\x24\x25\x24\x26\x24\x23\x24\x24\x25\x25\x25\x25\x25\x29\x25\x24\x26" + "\x24\x24\x25\x26\x24\x25\x25\x24\x23" + "\x22\x22\x24\x24\x23\x25\x25\x24\x25\x24\x26\x27\x26\x24\x22\x23\x24\x25\x25\x25\x24\x25\x25" + "\x23\x24\x23\x23\x26\x23\x25\x25\x25" + "\xCC\xCC\xCA\x6C\x2F\x28\x25\x27\x25\x25\x24\x25\x25\x24\x22\x24\x25\x24\x25\x23\x24\x24\x25" + "\x24\x24\x25\x26\x25\x24\x26\x25\x24" + "\x25\x24\x26\x24\x24\x25\x25\x24\x27\x25\x25\x26\x26\x26\x25\x25\x26\x26\x24\x26\x24\x24\x24" + "\x25\x23\x24\x24\x24\x24\x23\x24\x25" + "\xCC\xCD\xCD\xA3\x35\x29\x25\x25\x26\x25\x26\x27\x25\x26\x23\x22\x25\x24\x24\x26\x26\x24\x25" + "\x25\x25\x25\x25\x23\x26\x27\x24\x24" + "\x22\x24\x24\x24\x24\x24\x24\x23\x23\x26\x26\x25\x25\x24\x25\x25\x24\x27\x25\x25\x24\x24\x24" + "\x26\x25\x24\x24\x24\x25\x24\x24\x23" + "\xCD\xCD\xCD\xC8\x53\x2E\x25\x23\x25\x26\x26\x26\x24\x26\x27\x25\x25\x25\x25\x24\x24\x25\x27" + "\x25\x24\x25\x25\x23\x26\x25\x24\x23" + "\x23\x25\x23\x23\x25\x24\x24\x25\x23\x26\x25\x25\x24\x22\x25\x26\x24\x25\x25\x25\x25\x24\x24" + "\x26\x25\x26\x25\x23\x24\x25\x24\x23" + "\xCD\xCD\xCD\xCD\x8E\x3C\x32\x30\x2F\x2F\x2D\x2E\x2B\x2A\x2B\x2A\x29\x29\x28\x27\x25\x28\x28" + "\x24\x23\x25\x25\x23\x22\x23\x24\x25" + "\x24\x25\x26\x25\x25\x24\x24\x23\x23\x24\x25\x23\x23\x23\x25\x24\x25\x25\x25\x24\x25\x23\x25" + "\x22\x24\x25\x25\x24\x24\x24\x23\x24" + "\xCD\xCD\xCD\xCD\xC5\xA2\x94\x8D\x87\x7F\x79\x71\x68\x65\x60\x5E\x5A\x51\x48\x41\x35\x31\x31" + "\x2E\x2D\x2A\x2A\x27\x26\x25\x24\x27" + "\x26\x24\x25\x24\x23\x23\x23\x23\x26\x24\x27\x26\x26\x24\x25\x24\x26\x26\x24\x24\x24\x24\x25" + "\x24\x25\x23\x26\x25\x26\x25\x26\x26" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xC9\xC6\xBF\xB4\xA8\x9C\x8D\x82\x76" + "\x6A\x5A\x4B\x3D\x35\x32\x2F\x2C\x2B" + "\x29\x26\x25\x24\x25\x23\x24\x26\x25\x25\x25\x25\x24\x24\x24\x24\x24\x25\x24\x24\x25\x24\x26" + "\x26\x26\x26\x25\x26\x26\x26\x25\x25" + "\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCA\xC5" + "\xC0\xB9\xB3\xAC\xA1\x8E\x76\x56\x3D" + "\x36\x31\x2A\x28\x29\x26\x27\x26\x25\x26\x24\x25\x24\x25\x26\x24\x25\x25\x26\x24\x24\x23\x23" + "\x26\x26\x26\x26\x24\x25\x24\x24\x24" + "\xCE\xCC\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCC\xC6" + "\xA9\x8C\x6D\x5B\x49\x3D\x32\x2E\x2B\x28\x25\x23\x24\x24\x23\x26\x26\x25\x24\x23\x24\x23\x24" + "\x24\x26\x26\x26\x25\x26\x24\x21\x24" + "\xCD\xCD\xCD\xCD\xCC\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCC\xCD\xCB\xC0\xAB\x97\x82\x6E\x54\x3C\x30\x2C\x29\x27\x25\x27\x25\x25\x24\x23\x23\x24\x24" + "\x24\x26\x24\x25\x24\x23\x24\x25\x24" + "\xCD\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCC\xCD\xCD\xCC\xCD\xCD\xCA\xC2\xB6\xA7\x86\x5A\x38\x31\x2C\x28\x26\x25\x24\x24\x24\x25\x26" + "\x26\x29\x25\x25\x26\x27\x25\x25\x26" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCC\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCC\xBB\x91\x68\x4F\x3A\x30\x2A\x28\x26\x25\x24" + "\x23\x24\x24\x25\x26\x23\x23\x26\x25" + "\xCB\xCA\xC9\xCB\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCC\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xC8\xB4\x93\x76\x57\x3B\x30\x2D\x28" + "\x25\x25\x25\x25\x25\x22\x23\x24\x25" + "\x64\x62\x61\x62\x68\x71\x7B\x81\x8C\x94\x9C\xA3\xAB\xB5\xC3\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCC\xC5\xB8\xA5\x79\x4C\x34" + "\x2E\x26\x25\x25\x27\x21\x26\x26\x25" + "\x2C\x2B\x28\x2C\x2C\x2B\x2B\x2F\x2E\x31\x33\x34\x37\x38\x3B\x43\x5B\x70\x83\x95\xA7\xAF\xB6" + "\xBC\xC5\xCB\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCC\xCD\xCD\xCD\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCD\xCD\xCD\xCC\xC6\xA1" + "\x6E\x4A\x35\x29\x24\x27\x26\x24\x24" + "\x26\x25\x23\x23\x26\x25\x26\x25\x25\x24\x28\x2A\x26\x28\x29\x2C\x2B\x2E\x30\x33\x37\x44\x53" + "\x61\x74\x88\x9D\xB1\xC4\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCD\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCD\xCC\xCD\xCD\xCD\xCD\xCD" + "\xC9\xA7\x81\x58\x39\x30\x2A\x26\x25" + "\x25\x24\x26\x26\x24\x24\x23\x24\x23\x24\x26\x28\x25\x26\x25\x26\x27\x25\x26\x27\x28\x28\x2A" + "\x2C\x31\x35\x42\x50\x61\x74\x92\xAF" + "\xC9\xCD\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCC\xCC\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCE\xCD\xCD" + "\xCD\xCC\xC8\xB8\x9B\x5E\x39\x2F\x2A" + "\x24\x23\x23\x24\x23\x24\x25\x26\x25\x25\x25\x25\x24\x24\x25\x24\x24\x24\x22\x25\x25\x24\x24" + "\x24\x27\x27\x28\x2C\x2B\x2C\x31\x36" + "\x3F\x5A\x7D\xA0\xB8\xC5\xCC\xCD\xCD\xCC\xCC\xCD\xCC\xCC\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCC\xCA\xB2\x7D\x55" + "\x22\x23\x25\x25\x25\x25\x25\x24\x24\x24\x23\x24\x25\x24\x24\x24\x25\x26\x26\x25\x24\x25\x25" + "\x25\x24\x24\x25\x26\x25\x26\x27\x29" + "\x2A\x2C\x31\x38\x57\x74\x91\xAD\xC7\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCC\xCD\xCD\xCD\xCD\xCD\xCD" + "\xCD\xCD\xCD\xCD\xCD\xCD\xCD\xCB\xB7"; + +static const BYTE TEST_64X64_GREEN_PLANE_RLE[3696] = + "\x34\x2A\x25\x23\xF0\x24\x2B\x60\xA2\x97\x84\x75\x62\x50\x3C\x34\x30\x2C\x29\x28\x93\x26\x25" + "\x25\x23\x23\x25\x24\x24\x25\x84\x26" + "\x27\x25\x24\x25\x25\x27\x24\xC3\x25\x25\x24\x25\x26\x25\x23\x24\x24\x25\x23\x24\x30\x22\x23" + "\x21\xF0\x4E\x24\x1C\x12\x0C\x0A\x08" + "\x06\x08\x26\x4E\x6A\x8E\xA0\xB6\xF0\xCA\xDC\xCA\xA0\x74\x3E\x20\x1A\x12\x08\x08\x08\x02\x02" + "\x02\xF0\x03\x03\x02\x02\x01\x00\x00" + "\x02\x00\x02\x07\x00\x01\x02\x00\xF0\x01\x02\x00\x02\x00\x01\x01\x00\x02\x01\x01\x02\x00\x02" + "\x00\x40\x04\x04\x02\x06\xF0\xD2\xF8" + "\xCC\x9A\x5E\x40\x26\x14\x10\x0C\x02\x00\x04\x10\x20\xF0\x30\x44\x66\x98\xCC\xF7\xF7\xD4\x98" + "\x66\x4A\x2C\x14\x0C\x08\xF0\x0A\x08" + "\x01\x03\x01\x07\x00\x02\x00\x01\x00\x00\x08\x04\x00\xF0\x02\x03\x01\x00\x00\x00\x02\x06\x04" + "\x04\x01\x01\x01\x00\x00\x40\x07\x00" + "\x04\x04\xC4\x02\x16\x52\x92\xC8\xBE\xAC\x8E\x58\x1C\x02\x00\x14\x02\xF0\x22\x60\xA6\xCC\xC2" + "\xB2\x9C\x70\x3E\x1C\x0A\x04\x06\x00" + "\x02\x75\x00\x03\x00\x01\x01\x02\x01\xF0\x04\x02\x00\x02\x00\x01\x01\x02\x02\x02\x03\x03\x06" + "\x00\x03\x10\x03\x04\x8C\x12\x40\x70" + "\x96\xAE\x6C\x02\x00\xF0\x16\x40\x6E\x94\xB4\xD0\xBA\x72\x26\x18\x0C\x08\x04\x00\x03\xF0\x02" + "\x04\x01\x05\x03\x02\x01\x03\x02\x05" + "\x05\x03\x01\x00\x01\xA0\x02\x01\x01\x02\x02\x04\x02\x02\x00\x00\x03\x8D\x02\x01\x00\x00\x0A" + "\x22\x1C\x00\x03\xF0\x0A\x20\x38\x72" + "\xCE\xF7\xBA\x70\x34\x12\x08\x08\x05\x01\x00\xF0\x04\x02\x02\x06\x06\x00\x02\x04\x02\x02\x03" + "\x01\x03\x00\x04\x70\x00\x06\x0A\x03" + "\x01\x02\x04\x04\x5C\x02\x00\x00\x02\x00\x44\x01\x01\x01\x00\xF0\x02\x02\x02\x1E\x78\xBC\xB6" + "\x74\x2E\x0E\x0A\x02\x00\x01\x01\xF0" + "\x00\x01\x00\x00\x00\x01\x02\x02\x00\x02\x04\x02\x00\x00\x01\x50\x07\x01\x01\x00\x00\x04\x23" + "\x01\x00\x47\x01\x00\x01\x00\x23\x01" + "\x00\xF0\x01\x01\x17\x49\x75\x8D\x67\x27\x01\x1A\x60\xAA\xA0\x32\x0E\xF0\x04\x02\x00\x02\x01" + "\x04\x02\x02\x01\x02\x00\x05\x01\x01" + "\x02\x90\x00\x00\x04\x01\x01\x02\x00\x03\x03\x08\x2A\x01\x00\x13\x02\xF0\x05\x2B\x91\xF1\xD9" + "\xB1\x95\xBB\xF1\xE5\x63\x0F\x1C\x7C" + "\xC4\xF0\x48\x0A\x02\x04\x04\x02\x05\x02\x01\x00\x00\x00\x01\x04\x01\xA0\x07\x01\x00\x05\x01" + "\x00\x00\x01\x00\x02\x04\x99\x02\x00" + "\x00\x00\x02\x02\x00\x02\x00\xF0\x01\x00\x43\xB1\x8B\x15\x48\x70\x7C\x62\x20\x35\xA7\x95\x0F" + "\xF0\x00\x46\x8C\x18\x08\x00\x05\x00" + "\x04\x02\x02\x00\x01\x00\x06\xC0\x00\x00\x02\x01\x03\x01\x04\x04\x00\x04\x02\x03\x71\xF0\x13" + "\x9D\x43\x26\xAA\xB8\xA6\x9C\xAA\xBC" + "\x70\x0D\x79\x71\x01\xF0\x02\x60\x5C\x0C\x04\x02\x04\x02\x01\x00\x00\x02\x00\x00\x01\x83\x04" + "\x04\x06\x02\x00\x03\x01\x00\x41\xF0" + "\x01\x00\x09\xA5\x3B\x3C\xBC\x74\x24\x10\x04\x06\x3A\xAA\x94\xF0\x08\x7F\x55\x01\x0A\x96\x2A" + "\x06\x03\x03\x01\x00\x01\x01\x00\xE0" + "\x01\x03\x00\x00\x01\x03\x04\x04\x01\x01\x00\x00\x01\x02\x61\xF0\x2F\x3F\x0E\x6E\x38\x02\x03" + "\x37\x89\x9F\x7F\x25\x6C\x46\x1F\xF0" + "\x55\x09\x00\x26\x5E\x0C\x06\x00\x00\x00\x04\x02\x00\x02\x02\xC0\x00\x02\x04\x00\x05\x02\x02" + "\x04\x02\x00\x00\x01\x41\xF0\x02\x00" + "\x2D\x17\x1E\x48\x06\x00\x15\x79\x8B\x77\x91\x67\x10\xF0\x56\x03\x1F\x17\x00\x10\x50\x22\x06" + "\x04\x02\x03\x01\x04\x04\x93\x02\x03" + "\x04\x04\x01\x01\x02\x01\x00\x20\x02\x00\x21\xF0\x01\x01\x00\x00\x2F\x15\x0E\x26\x00\x01\x12" + "\x46\x3A\x32\x4A\xF0\x40\x0A\x3A\x06" + "\x1B\x17\x00\x04\x46\x4E\x0E\x03\x05\x02\x00\xF0\x00\x03\x01\x04\x00\x03\x02\x04\x00\x00\x01" + "\x03\x05\x01\x00\x10\x02\x11\xF0\x01" + "\x00\x02\x01\x00\x18\x0E\x05\x11\x00\x00\x06\x66\xBE\xB8\xF0\xB2\x52\x00\x0D\x03\x04\x04\x00" + "\x00\x1A\x42\x16\x06\x02\x00\xF0\x00" + "\x05\x01\x00\x02\x01\x00\x03\x02\x02\x01\x02\x00\x04\x00\x20\x00\x02\x11\xF0\x02\x02\x00\x02" + "\x00\x24\x0E\x15\x29\x00\x02\x02\x08" + "\x24\x3E\xF0\x1C\x02\x00\x49\x00\x20\x1C\x00\x00\x02\x44\x20\x04\x04\x00\xF0\x02\x00\x04\x00" + "\x01\x03\x03\x02\x00\x00\x02\x02\x04" + "\x00\x00\x20\x00\x05\x0C\x53\x05\x17\x0B\x01\x00\xF0\x01\x00\x38\x2E\x21\x7B\x1D\x01\x00\x00" + "\x02\x02\x01\x03\x49\xF0\x65\x08\x38" + "\x1A\x00\x00\x00\x3A\x30\x06\x02\x02\x05\x01\x03\xE0\x02\x00\x04\x02\x03\x03\x01\x03\x02\x00" + "\x00\x04\x01\x04\xF0\x01\x01\x00\x01" + "\x01\x01\x00\x01\x01\x00\x01\x00\x03\x45\x77\x24\x2D\x00\x83\x01\x26\x78\x04\x51\x83\x21\x00" + "\xE3\x07\x43\x91\x25\x3C\x5C\x02\x00" + "\x01\x01\x08\x52\x06\x00\xF0\x01\x01\x00\x03\x03\x04\x00\x00\x02\x01\x05\x02\x00\x02\x00\x93" + "\x02\x02\x00\x02\x00\x00\x00\x02\x00" + "\xF0\x08\x18\x59\xB7\x67\x09\x00\x00\x02\x02\x00\x5C\x62\x0F\x79\xF0\xB7\x71\x37\x27\x45\x91" + "\xB1\x49\x0C\x94\x30\x00\x00\x02\x02" + "\xF0\x00\x54\x10\x06\x01\x00\x04\x06\x02\x00\x06\x02\x03\x01\x00\x70\x00\x01\x00\x01\x01\x00" + "\x00\x04\x35\x02\x02\x00\xF0\x02\x3A" + "\x3A\x3B\xC3\xD9\x5D\x1B\x01\x00\x00\x0A\xB0\x9E\x1C\xC4\x4F\xB5\xED\xF9\xDD\x8D\x1D\x4C\xC4" + "\x4C\x02\x00\xF0\x2C\x34\x04\x04\x02" + "\x03\x01\x03\x03\x03\x02\x04\x04\x03\x00\x60\x04\x04\x00\x01\x01\x00\x13\x02\x18\x00\xF0\x0C" + "\x52\x20\x0D\x51\xBB\xAF\x61\x19\x00" + "\x00\x12\x7E\xB0\x8C\x95\x52\x24\x1A\x38\x64\x98\xB6\x54\x00\xF0\x05\x3F\x0F\x03\x03\x02\x02" + "\x00\x02\x04\x04\x02\x01\x02\x06\x70" + "\x02\x03\x00\x01\x04\x04\x02\x0A\xF0\x02\x00\x00\x00\x44\x6E\x18\x04\x21\x6D\xB1\xB9\x69\x0D" + "\x00\xC4\x0A\x4E\x94\xB4\xCC\xCE\xC0" + "\xAA\x78\x24\x02\x00\xF0\x21\x91\xBB\x3B\x05\x04\x00\x00\x01\x02\x00\x01\x00\x02\x02\x80\x00" + "\x00\x01\x01\x04\x01\x01\x00\x68\x02" + "\x02\x02\x00\x02\x00\xF0\x0E\x94\xFC\xA2\x54\x20\x21\x63\xC3\xF5\x95\x49\x1F\x04\x22\xF0\x36" + "\x3A\x2C\x18\x06\x01\x00\x00\x00\x09" + "\x29\x95\xE9\x99\x45\xF0\x09\x03\x01\x00\x02\x00\x00\x02\x00\x01\x00\x05\x03\x00\x04\x50\x06" + "\x01\x00\x00\x02\x78\x02\x00\x02\x00" + "\x00\x02\x00\xF0\x02\x26\x8C\xC2\xA8\x66\x1C\x05\x31\x99\xC9\xB5\x8F\x5B\x39\xF0\x19\x03\x02" + "\x02\x00\x07\x2B\x63\x93\xBB\x97\x25" + "\x06\x24\x04\xF0\x00\x01\x02\x00\x02\x03\x01\x01\x03\x01\x01\x01\x00\x00\x00\x40\x01\x02\x02" + "\x01\x98\x02\x02\x00\x02\x00\x00\x00" + "\x02\x00\xF0\x04\x26\x70\xB2\xC6\x7E\x2A\x02\x1D\x5B\x99\xB7\xC5\xCB\xC7\xF0\xB3\xC3\xCB\xCF" + "\xC7\xB1\x91\x4B\x0A\x56\xBC\xB4\x0A" + "\x00\x01\x64\x01\x02\x00\x00\x01\x02\x70\x01\x00\x01\x01\x00\x00\x00\xAA\x02\x02\x02\x00\x02" + "\x00\x02\x00\x02\x00\xF0\x20\x54\xB6" + "\xFF\xD0\x82\x48\x18\x1F\x33\x4F\x69\x83\x71\x63\xF0\x59\x37\x00\x40\x80\xEE\xDA\x6E\x0D\x08" + "\x00\x00\x00\x03\x01\xE0\x04\x01\x00" + "\x02\x00\x02\x02\x05\x07\x03\x02\x00\x00\x02\x03\x2E\x02\x00\xF0\x02\x00\x02\x00\x0C\x5E\xAA" + "\xC2\xB8\xA0\x86\x68\x48\x32\x3E\xF0" + "\x54\x6E\x98\xB2\xC0\xAA\x36\x02\x0D\x53\x07\x02\x02\x00\x04\x34\x02\x01\x00\x80\x01\x02\x06" + "\x00\x06\x04\x00\x01\x63\x02\x02\x00" + "\x00\x02\x00\x2E\x02\x00\xF0\x06\x2A\x62\x90\x9E\xB0\xC2\xD0\xC8\xBA\xAC\x8E\x64\x30\x08\xF0" + "\x00\x00\x51\x43\x0D\x01\x02\x02\x05" + "\x03\x00\x02\x01\x03\x00\x90\x02\x02\x04\x02\x00\x03\x03\x00\x01\x13\x02\x4F\x00\x02\x02\x00" + "\x05\xF0\x04\x10\x1C\x2A\x36\x30\x24" + "\x18\x06\x00\x01\x00\x21\x81\xA7\xF0\x2D\x03\x01\x03\x07\x06\x06\x01\x00\x02\x02\x00\x01\x03" + "\x02\x60\x02\x00\x02\x01\x02\x04\x9F" + "\x02\x00\x02\x02\x00\x00\x00\x02\x00\x0C\xF0\x01\x01\x1B\x65\xB1\xA5\x39\x0D\x03\x00\x00\x08" + "\x01\x01\x02\xD0\x01\x03\x02\x00\x02" + "\x06\x00\x03\x00\x00\x00\x05\x03\x47\x02\x02\x02\x00\x2B\x02\x00\x33\x01\x01\x00\xF0\x02\x02" + "\x01\x00\x00\x00\x1B\x7F\xC1\xB3\x6D" + "\x1D\x03\x00\x01\xF0\x01\x00\x01\x00\x01\x02\x04\x02\x03\x03\x03\x05\x03\x01\x00\x40\x03\x02" + "\x02\x00\xA6\x00\x02\x00\x00\x02\x00" + "\x01\x01\x02\x00\x26\x02\x00\xF0\x02\x00\x01\x00\x00\x01\x01\x0B\x1F\x3B\x75\xCB\xFA\xB3\x5F" + "\xF0\x2F\x0B\x09\x05\x01\x06\x06\x02" + "\x00\x06\x02\x01\x00\x01\x00\xA0\x02\x00\x04\x04\x04\x02\x00\x00\x04\x00\xF0\x02\x02\x02\x00" + "\x01\x17\x37\x45\x55\x57\x49\x39\x27" + "\x19\x0D\x37\x03\x01\x00\xF0\x01\x0F\x25\x3B\x59\x81\x9D\xB5\xCD\xB9\x6D\x1F\x15\x0D\x05\xF0" + "\x03\x01\x05\x01\x01\x03\x01\x02\x05" + "\x03\x01\x04\x02\x00\x00\x90\x02\x00\x01\x05\x01\x04\x00\x00\x00\xF0\x02\x02\x00\x00\x77\xBD" + "\xBF\xBB\xBD\xB7\xBF\xC3\xC9\xCF\xD3" + "\xF0\xCF\xBB\xA3\x8B\x77\x7D\x85\x8D\x97\xAF\xC7\xCF\xC9\xC1\xBB\xF0\xAD\x8D\x69\x39\x17\x15" + "\x05\x01\x01\x01\x04\x02\x04\x02\x00" + "\xF0\x02\x02\x00\x02\x04\x00\x03\x02\x02\x00\x00\x02\x01\x01\x01\x40\x00\x00\x02\x02\xF0\x02" + "\x00\x09\x99\xAD\x65\x4D\x45\x3B\x39" + "\x3D\x49\x55\x5D\x5F\xF0\x6B\x83\x9B\xB3\xC1\xBD\xB5\xAB\xA3\x91\x73\x61\x57\x4D\x35\xF0\x1B" + "\x15\x0B\x0D\x09\x01\x07\x03\x01\x02" + "\x01\x00\x04\x02\x00\x14\x01\xE0\x04\x00\x02\x01\x04\x00\x01\x04\x06\x04\x05\x03\x03\x00\xF0" + "\x02\x00\x3D\x63\x17\x0B\x07\x07\x00" + "\x03\x03\x07\x09\x07\x0D\xF0\x11\x0F\x0D\x0B\x15\x11\x11\x13\x13\x0D\x0F\x09\x05\x03\x05\xF0" + "\x03\x01\x01\x01\x02\x04\x06\x02\x00" + "\x00\x02\x04\x00\x01\x03\xF0\x03\x01\x02\x00\x00\x03\x00\x00\x02\x00\x02\x01\x00\x02\x00\x40" + "\x06\x04\x02\x01\xF0\x00\x00\x47\x25" + "\x05\x03\x00\x02\x01\x01\x02\x04\x00\x01\x00\xB3\x00\x01\x02\x01\x01\x03\x01\x01\x01\x00\x01" + "\xF0\x04\x02\x01\x00\x04\x00\x03\x07" + "\x01\x02\x01\x03\x03\x07\x03\xF0\x04\x06\x02\x01\x00\x02\x06\x04\x03\x00\x00\x02\x02\x02\x04" + "\x50\x00\x00\x00\x03\x04\xF0\x02\x0D" + "\x27\x0B\x01\x01\x02\x00\x00\x00\x03\x01\x00\x00\x00\xF0\x04\x04\x00\x00\x04\x00\x01\x00\x00" + "\x01\x00\x02\x02\x02\x00\xF0\x00\x02" + "\x01\x02\x03\x01\x04\x00\x00\x02\x01\x01\x00\x02\x02\xF0\x03\x00\x03\x02\x00\x05\x05\x00\x01" + "\x03\x01\x04\x01\x03\x00\x40\x01\x00" + "\x00\x03\xF0\x00\x05\x07\x03\x01\x02\x04\x00\x00\x00\x01\x03\x00\x02\x00\xF0\x00\x02\x03\x01" + "\x01\x00\x01\x03\x00\x02\x02\x00\x01" + "\x00\x00\xF0\x02\x02\x02\x03\x01\x00\x02\x02\x01\x01\x04\x02\x04\x02\x01\xF4\x00\x01\x04\x00" + "\x02\x02\x02\x00\x02\x01\x03\x05\x01" + "\x03\x00\xF0\x02\x05\x03\x01\x03\x00\x03\x02\x00\x00\x02\x02\x06\x02\x01\xF0\x05\x05\x00\x04" + "\x01\x03\x02\x04\x00\x00\x04\x01\x01" + "\x02\x02\xF0\x00\x04\x00\x02\x06\x04\x05\x00\x04\x02\x00\x01\x01\x07\x03\xF0\x00\x04\x00\x02" + "\x03\x01\x04\x00\x04\x04\x06\x02\x02" + "\x02\x01\x40\x02\x00\x02\x01\xF0\x02\x0A\x08\x00\x06\x04\x06\x00\x04\x02\x00\x01\x00\x02\x04" + "\xF0\x06\x00\x00\x03\x02\x02\x02\x00" + "\x04\x02\x03\x00\x04\x03\x00\xF0\x01\x05\x01\x03\x01\x03\x00\x03\x01\x01\x00\x01\x01\x02\x06" + "\xF0\x04\x04\x01\x03\x04\x01\x07\x04" + "\x03\x02\x01\x00\x03\x01\x00\x40\x00\x03\x00\x06\xF0\x00\x0C\x0E\x04\x00\x03\x01\x02\x03\x01" + "\x00\x04\x05\x03\x03\xA5\x01\x04\x01" + "\x01\x03\x04\x00\x00\x03\x00\xF0\x01\x00\x02\x00\x00\x04\x00\x00\x00\x04\x00\x02\x02\x04\x02" + "\xF0\x02\x03\x04\x03\x05\x00\x04\x05" + "\x00\x01\x00\x00\x02\x04\x02\x40\x01\x04\x00\x03\xF0\x00\x0A\x2C\x14\x00\x01\x01\x02\x04\x00" + "\x01\x02\x00\x01\x00\xF0\x09\x05\x02" + "\x00\x06\x01\x01\x01\x00\x01\x03\x01\x01\x02\x04\xF0\x04\x02\x04\x08\x04\x00\x04\x06\x02\x01" + "\x03\x00\x00\x00\x03\xF0\x03\x00\x01" + "\x02\x02\x00\x00\x01\x00\x04\x01\x00\x04\x00\x01\x40\x04\x00\x01\x01\xF0\x02\x02\x3E\x1C\x00" + "\x08\x04\x01\x00\x03\x00\x03\x00\x02" + "\x02\xF0\x08\x00\x05\x01\x00\x00\x01\x02\x01\x01\x04\x02\x01\x03\x07\xF0\x03\x05\x07\x01\x05" + "\x05\x01\x01\x01\x02\x02\x01\x00\x00" + "\x01\xF0\x01\x00\x03\x06\x00\x04\x01\x08\x02\x05\x03\x04\x01\x01\x02\x40\x05\x00\x02\x00\xF0" + "\x00\x00\x30\x16\x0A\x00\x03\x00\x01" + "\x08\x00\x03\x00\x01\x00\x63\x02\x04\x06\x04\x06\x02\xF0\x00\x00\x02\x00\x04\x02\x00\x00\x01" + "\x07\x02\x04\x01\x00\x00\xF0\x03\x02" + "\x02\x04\x06\x06\x02\x05\x00\x03\x02\x00\x02\x03\x00\xA0\x02\x02\x03\x03\x01\x02\x00\x00\x00" + "\x04\xF0\x00\x00\x18\x34\x0A\x04\x02" + "\x04\x02\x01\x00\x04\x02\x00\x05\x93\x01\x00\x01\x00\x0B\x01\x00\x01\x00\xF0\x02\x01\x02\x02" + "\x02\x06\x04\x04\x00\x02\x00\x00\x00" + "\x04\x02\xF0\x01\x01\x00\x04\x06\x04\x04\x02\x01\x02\x00\x01\x01\x04\x01\x70\x02\x02\x03\x02" + "\x03\x01\x00\xF0\x00\x02\x06\x6E\x0C" + "\x02\x00\x03\x02\x00\x04\x04\x00\x04\x02\xF0\x03\x00\x00\x01\x06\x04\x00\x00\x02\x02\x00\x01" + "\x03\x04\x02\xF0\x01\x00\x05\x00\x03" + "\x00\x00\x01\x01\x01\x07\x02\x02\x01\x01\xF0\x03\x00\x00\x03\x02\x02\x01\x00\x00\x00\x02\x04" + "\x00\x00\x00\x40\x02\x02\x00\x03\xF0" + "\x02\x00\x00\x4A\x3C\x0A\x00\x03\x01\x02\x00\x01\x01\x00\x08\xB3\x06\x00\x02\x02\x03\x03\x02" + "\x04\x00\x01\x00\xF0\x03\x00\x01\x02" + "\x02\x01\x01\x02\x00\x00\x04\x00\x00\x01\x00\xA3\x01\x03\x00\x02\x00\x03\x00\x00\x02\x00\x70" + "\x04\x02\x01\x01\x02\x00\x00\x03\xF0" + "\x0A\x76\x1C\x1A\x1A\x14\x12\x0E\x10\x0E\x08\x08\x0A\x08\x08\xF0\x06\x06\x02\x06\x02\x01\x01" + "\x00\x00\x00\x07\x03\x00\x04\x02\xF0" + "\x00\x06\x04\x00\x00\x00\x03\x00\x03\x00\x03\x01\x02\x00\x03\xF0\x02\x00\x00\x01\x00\x01\x02" + "\x07\x01\x01\x00\x02\x00\x01\x01\x10" + "\x02\x04\xF0\x6E\xCC\xC4\xBA\xB0\xA0\x98\x86\x7A\x76\x6A\x68\x62\x50\x40\xF0\x34\x20\x12\x12" + "\x14\x14\x0A\x0A\x08\x08\x04\x00\x04" + "\x04\x01\xF0\x01\x01\x03\x01\x01\x00\x06\x00\x04\x06\x06\x02\x00\x00\x02\xF0\x02\x01\x00\x01" + "\x02\x00\x04\x02\x03\x02\x02\x04\x02" + "\x06\x04\x04\xF0\x10\x56\x72\x80\x8C\x9C\xA8\xB8\xCA\xCE\xD2\xD0\xCA\xC6\xC0\xF0\xB6\xB0\xA2" + "\x8A\x78\x5A\x42\x26\x1C\x18\x14\x10" + "\x08\x06\x04\xF0\x00\x00\x04\x00\x02\x06\x01\x02\x03\x01\x03\x00\x01\x00\x03\xF0\x01\x00\x00" + "\x02\x00\x02\x04\x02\x06\x01\x02\x00" + "\x02\x01\x01\x39\x01\x01\x00\xF0\x01\x02\x08\x0E\x1C\x32\x4A\x62\x7E\x90\x9E\xAC\xBE\xD0\xDE" + "\xF0\xD8\xB8\x8E\x54\x24\x1A\x16\x0A" + "\x08\x08\x06\x06\x00\x00\x02\xF0\x01\x00\x00\x02\x04\x00\x02\x00\x04\x00\x01\x01\x05\x00\x00" + "\x70\x00\x02\x03\x01\x03\x01\x01\x6C" + "\x04\x00\x00\x00\x01\x00\xF0\x01\x01\x02\x06\x10\x1A\x28\x34\x42\x58\x7C\xAC\xEC\xED\xE6\xF0" + "\xB6\x86\x66\x40\x2E\x16\x10\x0C\x04" + "\x02\x03\x00\x01\x05\x04\xF0\x02\x00\x03\x01\x00\x00\x02\x03\x00\x00\x00\x02\x02\x00\x05\x10" + "\x00\x34\x01\x02\x00\x23\x01\x00\x2E" + "\x02\x00\xF0\x02\x02\x02\x0E\x46\x82\xBC\xCA\xC4\xB4\xA0\x80\x52\x28\x16\xF0\x12\x0A\x06\x04" + "\x02\x01\x00\x00\x00\x01\x02\x00\x00" + "\x00\x03\x60\x01\x01\x05\x00\x08\x00\x03\x67\x01\x02\x00\x00\x02\x00\x53\x01\x00\x02\x02\x00" + "\x28\x01\x00\xF0\x04\x18\x44\x6C\x90" + "\xA8\xC4\xD6\xAC\x5C\x1E\x14\x0E\x02\x02\xF0\x00\x00\x02\x02\x02\x04\x04\x06\x02\x00\x04\x08" + "\x02\x00\x04\x03\x25\x02\x00\x25\x01" + "\x00\x34\x01\x01\x00\x26\x02\x00\xF0\x02\x00\x00\x02\x00\x00\x06\x16\x2E\x4A\x8E\xE4\xF9\xC0" + "\x78\xF0\x4E\x28\x16\x0C\x08\x04\x00" + "\x03\x05\x09\x01\x00\x00\x07\x03\x20\x02\x01\x55\x03\x05\x07\x03\x00\x2F\x02\x00\x0D\xF0\x01" + "\x02\x00\x02\x24\x78\xC0\xCA\xB2\x8C" + "\x5A\x26\x14\x10\x08\x90\x04\x02\x02\x00\x01\x01\x00\x03\x00\xF0\xCD\xCF\xCF\xD1\xC9\xB7\xA3" + "\x97\x81\x71\x61\x53\x43\x2F\x13\x5D" + "\x01\x02\x02\x02\x00\x03\x13\x01\xF0\x00\x01\x01\x00\x00\x00\x0A\x32\x72\x9E\xC2\xD4\x92\x3E" + "\x18\x90\x12\x02\x00\x00\x04\x01\x06" + "\x04\x00\xF0\x6F\x6D\x71\x6B\x77\x8B\x9F\xA3\xBB\xC5\xD1\xDD\xE7\xF9\xF0\xC5\xEE\xE3\xB9\x93" + "\x6F\x4B\x3B\x2D\x21\x0F\x03\x00\x29" + "\x01\x00\x14\x01\xF0\x00\x10\x2A\x50\xA6\xF4\xDA\x80\x48\x20\x08\x05\x0C\x00\x03\x10\x01\xF0" + "\x0B\x0B\x09\x11\x0B\x0B\x09\x13\x11" + "\x19\x15\x13\x21\x1F\x23\xF0\x2D\x5F\x83\xA5\xC3\xDF\xD5\xC5\xB5\xA1\x85\x5F\x37\x11\x00\xC6" + "\x00\x00\x02\x00\x00\x00\x02\x02\x00" + "\x00\x02\x00\xF0\x02\x01\x00\x00\x02\x0E\x58\xB6\xBA\x98\x5E\x2A\x12\x08\x04\x10\x02\xF0\x01" + "\x01\x06\x06\x03\x01\x05\x01\x03\x00" + "\x03\x03\x01\x03\x07\xF0\x0B\x07\x11\x13\x17\x1D\x37\x51\x69\x85\xA5\xB5\xC1\xC5\xB1\xE4\x75" + "\x3B\x07\x00\x01\x01\x00\x00\x02\x02" + "\x00\x00\x00\x02\xF0\x00\x02\x00\x00\x02\x00\x00\x08\x4A\x8E\xC0\xC4\x5C\x1E\x12\x10\x0A\xF0" + "\x01\x01\x05\x03\x01\x00\x04\x04\x04" + "\x02\x01\x05\x01\x03\x00\xF0\x03\x05\x01\x07\x03\x05\x07\x0B\x0F\x13\x1B\x33\x47\x6B\x8F\xA4" + "\xC1\xF1\xEC\xE5\x9D\x57\x29\x0F\x01" + "\x00\xF0\x01\x01\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02\x0A\x2A\x50\x62\xD8\xF2\x9C\x56" + "\xF0\x03\x00\x04\x02\x04\x02\x00\x03" + "\x01\x01\x03\x01\x02\x00\x01\xF0\x00\x02\x04\x08\x00\x01\x02\x02\x02\x05\x05\x05\x0B\x0B\x0B" + "\xF0\x13\x19\x29\x5B\x97\xCF\xC1\xA1" + "\x75\x3F\x0B\x02\x02\x00\x02\x2C\x02\x00\x50\x02\x06\x36\x9C\xC4"; + +static const BYTE TEST_64X64_BLUE_PLANE[4096] = + "\x27\x23\x23\x24\x25\x25\x25\x25\x28\x37\x4A\x47\x41\x3D\x38\x33\x2E\x2A\x28\x27\x26\x27\x27" + "\x27\x25\x24\x26\x28\x26\x27\x28\x28" + "\x26\x28\x28\x2A\x26\x27\x27\x28\x27\x27\x25\x26\x24\x25\x27\x28\x27\x28\x27\x27\x25\x26\x27" + "\x27\x26\x27\x27\x27\x26\x25\x26\x23" + "\x32\x29\x29\x27\x26\x28\x27\x27\x29\x3C\x55\x56\x56\x54\x52\x50\x4D\x48\x40\x37\x2F\x2C\x2B" + "\x2A\x27\x27\x27\x27\x26\x26\x25\x26" + "\x27\x28\x28\x28\x27\x27\x27\x28\x25\x26\x25\x27\x26\x26\x29\x28\x26\x27\x25\x27\x25\x26\x25" + "\x27\x25\x27\x28\x27\x26\x27\x27\x27" + "\x4E\x4D\x45\x3D\x35\x30\x2D\x29\x2B\x3E\x56\x56\x57\x57\x57\x57\x56\x56\x56\x56\x56\x52\x49" + "\x3E\x36\x31\x2D\x29\x27\x27\x27\x28" + "\x27\x27\x24\x25\x28\x29\x27\x28\x26\x27\x29\x2A\x27\x25\x24\x26\x28\x27\x27\x25\x29\x27\x26" + "\x25\x26\x23\x26\x27\x25\x27\x29\x26" + "\x4F\x50\x50\x51\x52\x4A\x44\x3E\x36\x41\x55\x56\x57\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57" + "\x57\x53\x4D\x47\x40\x39\x31\x2D\x27" + "\x25\x27\x26\x25\x28\x26\x25\x26\x25\x28\x29\x29\x25\x25\x26\x26\x2A\x29\x28\x26\x29\x29\x27" + "\x27\x26\x25\x25\x24\x28\x27\x27\x25" + "\x4F\x50\x50\x51\x53\x54\x55\x53\x50\x51\x56\x57\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57\x57" + "\x57\x58\x57\x57\x55\x52\x4E\x47\x38" + "\x2D\x2C\x26\x27\x28\x27\x26\x28\x27\x26\x24\x26\x24\x24\x24\x27\x27\x25\x26\x28\x27\x27\x25" + "\x26\x26\x27\x26\x27\x27\x28\x27\x24" + "\x4F\x50\x51\x52\x52\x54\x55\x54\x55\x55\x56\x56\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57\x57" + "\x57\x56\x56\x57\x57\x57\x57\x57\x56" + "\x52\x45\x38\x2F\x29\x27\x28\x25\x23\x25\x28\x26\x27\x27\x25\x27\x27\x26\x25\x28\x25\x26\x25" + "\x27\x27\x26\x2A\x2C\x27\x27\x28\x29" + "\x4F\x50\x51\x52\x53\x53\x54\x55\x55\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x56\x56\x56" + "\x57\x56\x56\x57\x57\x57\x57\x57\x57" + "\x57\x56\x52\x49\x3A\x2E\x29\x28\x27\x26\x26\x25\x25\x26\x27\x27\x27\x27\x27\x27\x25\x26\x27" + "\x25\x25\x28\x28\x28\x25\x25\x26\x27" + "\x4F\x50\x51\x52\x52\x53\x54\x55\x55\x55\x56\x56\x57\x57\x57\x57\x57\x57\x57\x58\x56\x56\x56" + "\x56\x57\x56\x56\x52\x4C\x45\x42\x47" + "\x51\x56\x57\x57\x53\x45\x30\x28\x27\x27\x27\x28\x27\x29\x28\x26\x25\x26\x28\x26\x25\x25\x29" + "\x26\x27\x29\x27\x26\x26\x26\x25\x26" + "\x4F\x50\x51\x52\x52\x54\x55\x55\x55\x55\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56" + "\x56\x56\x50\x42\x30\x2A\x2B\x2D\x2D" + "\x2E\x35\x48\x54\x57\x57\x4C\x34\x27\x27\x29\x2A\x28\x26\x29\x26\x25\x26\x28\x25\x27\x25\x25" + "\x25\x27\x25\x27\x25\x26\x25\x25\x26" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56" + "\x56\x4C\x37\x2D\x2E\x34\x3B\x3D\x3A" + "\x33\x2F\x2F\x3E\x54\x56\x56\x48\x2C\x29\x27\x25\x27\x26\x29\x25\x27\x26\x28\x28\x28\x26\x24" + "\x25\x25\x24\x29\x28\x25\x25\x25\x24" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56" + "\x53\x35\x2D\x32\x46\x51\x54\x55\x53" + "\x4E\x3F\x2D\x2D\x43\x56\x56\x56\x39\x2A\x28\x27\x2A\x28\x29\x26\x27\x28\x28\x29\x26\x26\x27" + "\x28\x27\x26\x25\x28\x26\x26\x27\x25" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x56\x57\x55" + "\x3B\x2E\x36\x4E\x57\x57\x56\x55\x54" + "\x56\x56\x43\x2E\x31\x4A\x56\x57\x4E\x2F\x28\x25\x27\x27\x28\x27\x26\x27\x27\x26\x26\x26\x26" + "\x26\x28\x25\x26\x26\x27\x27\x26\x27" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x56\x57\x4E" + "\x32\x2F\x45\x56\x57\x56\x4E\x42\x3D" + "\x44\x50\x53\x36\x2D\x3E\x54\x57\x54\x3D\x2A\x27\x27\x26\x27\x27\x27\x27\x27\x26\x27\x27\x27" + "\x23\x25\x27\x27\x29\x26\x26\x25\x26" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x49" + "\x2E\x33\x4F\x57\x57\x53\x3D\x2F\x2C" + "\x2F\x41\x55\x43\x2E\x39\x52\x56\x56\x48\x2E\x28\x28\x28\x26\x28\x28\x2A\x27\x25\x29\x29\x26" + "\x25\x27\x28\x27\x27\x27\x26\x26\x25" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x56\x56\x56\x56\x57\x41" + "\x2B\x33\x54\x56\x56\x55\x46\x34\x32" + "\x38\x49\x56\x4C\x2F\x36\x4E\x56\x57\x52\x39\x2A\x26\x26\x27\x28\x28\x28\x26\x27\x28\x28\x28" + "\x25\x25\x25\x24\x26\x25\x23\x26\x27" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x56\x56\x57\x56\x57\x44" + "\x2D\x33\x52\x57\x56\x56\x55\x50\x4D" + "\x52\x56\x57\x4A\x2E\x36\x4F\x57\x57\x56\x42\x2B\x28\x27\x28\x28\x24\x25\x27\x28\x26\x27\x27" + "\x28\x27\x26\x25\x26\x26\x25\x27\x28" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x56\x56\x49" + "\x31\x2F\x4B\x57\x57\x58\x57\x56\x56" + "\x57\x57\x57\x40\x2E\x38\x52\x57\x57\x57\x4D\x2F\x28\x27\x28\x29\x26\x27\x27\x27\x26\x27\x28" + "\x28\x27\x26\x28\x29\x26\x24\x27\x24" + "\x4F\x50\x51\x52\x53\x54\x55\x55\x56\x56\x56\x56\x56\x53\x57\x57\x57\x57\x57\x57\x56\x56\x51" + "\x37\x2D\x39\x52\x56\x57\x57\x57\x57" + "\x57\x57\x4C\x31\x2F\x41\x56\x57\x56\x56\x56\x39\x27\x26\x27\x24\x24\x26\x27\x27\x27\x26\x26" + "\x25\x25\x26\x28\x28\x27\x27\x26\x27" + "\x4F\x50\x51\x52\x53\x54\x54\x55\x55\x56\x56\x56\x55\x49\x43\x50\x57\x57\x56\x56\x56\x56\x56" + "\x48\x2C\x30\x3F\x51\x57\x57\x57\x57" + "\x56\x4C\x37\x2C\x36\x50\x57\x57\x57\x57\x57\x44\x29\x27\x27\x25\x23\x26\x27\x27\x26\x26\x27" + "\x26\x27\x26\x26\x25\x28\x27\x27\x26" + "\x4F\x50\x51\x52\x53\x54\x54\x55\x55\x56\x56\x56\x56\x4C\x35\x35\x46\x55\x56\x56\x57\x57\x57" + "\x55\x3B\x2C\x2E\x38\x46\x4E\x50\x4C" + "\x41\x32\x2C\x2B\x4B\x57\x57\x57\x57\x57\x57\x4F\x2D\x29\x27\x26\x26\x27\x29\x27\x28\x26\x25" + "\x25\x25\x25\x25\x24\x25\x26\x27\x26" + "\x4F\x50\x51\x52\x53\x54\x54\x55\x55\x56\x56\x56\x57\x55\x40\x2C\x2B\x35\x48\x52\x56\x57\x57" + "\x57\x54\x44\x31\x29\x2C\x2C\x2D\x2C" + "\x2C\x2E\x38\x4B\x57\x57\x57\x57\x57\x57\x57\x57\x33\x28\x28\x27\x23\x26\x27\x24\x27\x27\x26" + "\x26\x25\x27\x27\x28\x26\x26\x26\x27" + "\x4F\x51\x52\x53\x53\x54\x54\x55\x55\x56\x56\x56\x57\x57\x4A\x30\x2A\x2A\x2E\x38\x48\x53\x57" + "\x57\x57\x55\x4A\x3F\x37\x31\x31\x35" + "\x3A\x44\x50\x56\x57\x56\x56\x57\x56\x57\x56\x4F\x2F\x28\x27\x27\x25\x28\x27\x27\x29\x28\x27" + "\x27\x28\x26\x25\x27\x26\x28\x27\x26" + "\x50\x51\x52\x53\x53\x54\x55\x55\x55\x56\x56\x56\x57\x57\x54\x41\x2D\x2B\x29\x27\x2F\x38\x48" + "\x55\x57\x57\x56\x55\x52\x4F\x4E\x53" + "\x53\x55\x57\x57\x57\x56\x56\x57\x56\x52\x40\x32\x29\x29\x29\x27\x25\x26\x26\x26\x26\x28\x27" + "\x29\x27\x28\x25\x26\x26\x27\x26\x27" + "\x50\x51\x52\x53\x54\x54\x55\x55\x55\x56\x56\x56\x57\x57\x56\x56\x52\x42\x36\x2F\x2B\x2B\x2C" + "\x31\x41\x4C\x52\x55\x57\x57\x57\x57" + "\x56\x56\x56\x57\x56\x56\x54\x51\x3F\x2F\x2A\x26\x27\x26\x26\x26\x27\x27\x28\x28\x26\x26\x28" + "\x26\x26\x27\x26\x28\x27\x27\x27\x28" + "\x50\x51\x52\x53\x54\x54\x55\x55\x55\x56\x56\x56\x57\x57\x57\x56\x57\x56\x50\x46\x38\x2D\x29" + "\x29\x2A\x30\x38\x40\x49\x4E\x52\x56" + "\x57\x57\x56\x56\x4F\x48\x3F\x35\x2A\x2B\x2B\x2D\x28\x25\x26\x26\x27\x27\x27\x27\x26\x24\x28" + "\x25\x25\x24\x27\x29\x26\x28\x28\x26" + "\x51\x52\x52\x53\x54\x54\x55\x55\x55\x56\x56\x56\x57\x57\x57\x56\x57\x57\x57\x56\x51\x49\x3D" + "\x31\x2D\x2B\x2A\x29\x2F\x31\x35\x3A" + "\x3D\x3B\x39\x37\x33\x2E\x29\x2A\x2B\x37\x46\x47\x28\x25\x27\x27\x28\x26\x25\x26\x28\x26\x28" + "\x25\x26\x24\x28\x29\x25\x28\x26\x25" + "\x51\x52\x53\x53\x54\x54\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x56\x56\x57\x57" + "\x54\x4A\x3E\x35\x2E\x28\x29\x28\x29" + "\x29\x2A\x2C\x2B\x2B\x2F\x35\x3E\x4E\x56\x56\x45\x2B\x25\x27\x29\x25\x26\x27\x25\x25\x26\x26" + "\x27\x26\x22\x25\x26\x26\x27\x25\x27" + "\x51\x52\x53\x54\x54\x55\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x57\x56\x50\x48\x41\x3E\x38\x34" + "\x31\x33\x38\x3B\x41\x48\x4F\x55\x57\x57\x55\x38\x2A\x28\x28\x27\x25\x26\x26\x22\x27\x27\x27" + "\x26\x25\x25\x26\x26\x27\x27\x27\x28" + "\x52\x52\x53\x54\x54\x55\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x57\x57\x57\x56\x56\x54\x52\x51" + "\x4F\x4F\x52\x53\x55\x56\x57\x57\x57\x57\x49\x2F\x26\x26\x29\x26\x26\x26\x27\x27\x27\x25\x26" + "\x28\x26\x27\x27\x27\x27\x27\x27\x27" + "\x52\x53\x53\x54\x54\x55\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x57\x57\x57\x57\x57\x57\x56\x56" + "\x57\x56\x56\x56\x56\x56\x56\x57\x51\x43\x30\x2A\x24\x24\x25\x25\x27\x28\x25\x26\x26\x27\x28" + "\x25\x25\x27\x27\x26\x27\x27\x29\x26" + "\x52\x53\x54\x54\x55\x55\x55\x56\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x57\x57\x57\x57\x57\x57\x56\x56" + "\x57\x57\x56\x56\x56\x56\x52\x48\x38\x2C\x27\x27\x25\x25\x25\x25\x25\x27\x26\x26\x25\x26\x28" + "\x27\x27\x26\x25\x26\x28\x27\x25\x26" + "\x53\x53\x54\x54\x55\x55\x55\x56\x56\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x56\x56\x57\x57\x57\x57\x57\x57" + "\x58\x57\x57\x57\x52\x43\x35\x2E\x27\x28\x29\x27\x23\x25\x26\x27\x27\x27\x27\x28\x26\x25\x26" + "\x24\x25\x25\x25\x25\x26\x28\x27\x27" + "\x53\x54\x54\x55\x55\x54\x54\x55\x56\x56\x56\x57\x56\x56\x56\x57\x56\x56\x57\x57\x56\x57\x57" + "\x57\x56\x56\x56\x58\x56\x56\x56\x54" + "\x51\x4E\x46\x39\x2D\x2B\x29\x28\x27\x27\x28\x28\x26\x26\x26\x28\x2A\x28\x28\x28\x26\x26\x26" + "\x26\x26\x28\x28\x28\x25\x28\x29\x25" + "\x53\x54\x53\x54\x55\x52\x4C\x4B\x48\x48\x4B\x4F\x51\x52\x55\x56\x56\x56\x57\x57\x56\x56\x57" + "\x56\x57\x56\x54\x50\x4E\x49\x43\x3F" + "\x37\x30\x2A\x2A\x28\x27\x28\x28\x27\x25\x26\x27\x26\x27\x26\x27\x27\x25\x27\x28\x27\x26\x26" + "\x27\x26\x27\x25\x26\x26\x27\x27\x26" + "\x54\x54\x54\x54\x44\x37\x32\x31\x2D\x2D\x2E\x32\x35\x34\x34\x38\x3C\x40\x43\x45\x44\x43\x43" + "\x41\x3D\x38\x36\x33\x33\x2F\x2A\x2B" + "\x27\x29\x28\x26\x29\x27\x27\x27\x29\x27\x27\x28\x26\x25\x26\x28\x27\x25\x25\x27\x28\x26\x26" + "\x25\x26\x26\x23\x25\x28\x26\x28\x27" + "\x53\x53\x53\x3E\x2B\x25\x23\x25\x24\x27\x28\x28\x27\x27\x2A\x2A\x27\x27\x27\x29\x29\x28\x29" + "\x29\x28\x2A\x29\x28\x27\x26\x27\x29" + "\x26\x26\x26\x26\x27\x26\x26\x26\x28\x28\x29\x29\x27\x25\x25\x28\x27\x27\x29\x26\x29\x26\x27" + "\x27\x27\x27\x26\x26\x25\x25\x26\x26" + "\x53\x54\x49\x30\x26\x24\x23\x25\x25\x28\x28\x26\x25\x27\x27\x25\x26\x28\x28\x26\x27\x28\x27" + "\x26\x27\x26\x26\x27\x25\x24\x25\x27" + "\x25\x26\x27\x27\x29\x27\x26\x26\x27\x2A\x29\x27\x25\x24\x25\x28\x27\x26\x27\x28\x29\x26\x27" + "\x26\x26\x28\x28\x26\x26\x26\x26\x26" + "\x55\x54\x40\x29\x26\x24\x24\x27\x25\x26\x27\x29\x26\x24\x26\x26\x27\x29\x29\x25\x26\x28\x28" + "\x26\x28\x27\x28\x27\x25\x28\x27\x27" + "\x27\x27\x25\x25\x26\x27\x27\x26\x25\x28\x26\x24\x27\x25\x26\x27\x27\x27\x27\x28\x24\x27\x27" + "\x28\x26\x26\x29\x26\x25\x26\x26\x26" + "\x54\x52\x3A\x29\x25\x24\x26\x26\x26\x25\x26\x26\x27\x27\x27\x28\x29\x2A\x28\x29\x27\x26\x27" + "\x27\x27\x27\x28\x29\x28\x27\x27\x28" + "\x27\x28\x25\x23\x27\x26\x28\x26\x23\x25\x26\x26\x28\x26\x26\x25\x26\x27\x27\x27\x24\x24\x26" + "\x27\x27\x27\x28\x28\x27\x27\x26\x27" + "\x55\x52\x38\x29\x24\x26\x28\x26\x25\x25\x27\x27\x26\x26\x27\x26\x29\x27\x27\x27\x27\x25\x25" + "\x27\x27\x26\x27\x28\x28\x27\x28\x28" + "\x27\x27\x24\x25\x28\x27\x27\x27\x26\x27\x28\x27\x27\x25\x26\x26\x28\x27\x28\x27\x26\x25\x25" + "\x26\x25\x26\x26\x26\x27\x28\x26\x24" + "\x55\x51\x38\x28\x24\x26\x25\x25\x26\x25\x25\x27\x29\x28\x27\x24\x27\x28\x28\x26\x23\x25\x27" + "\x27\x25\x28\x27\x26\x29\x28\x27\x2A" + "\x28\x28\x26\x27\x26\x27\x27\x27\x28\x26\x26\x24\x23\x25\x25\x27\x27\x26\x27\x29\x27\x27\x27" + "\x29\x25\x28\x26\x24\x26\x28\x28\x24" + "\x56\x53\x39\x28\x28\x28\x28\x27\x28\x27\x27\x27\x2A\x2A\x29\x29\x27\x27\x27\x26\x25\x26\x27" + "\x28\x28\x26\x27\x28\x26\x27\x28\x27" + "\x26\x25\x26\x26\x24\x26\x26\x27\x25\x25\x23\x25\x27\x26\x28\x27\x27\x27\x26\x26\x29\x27\x27" + "\x27\x28\x26\x26\x25\x26\x25\x26\x26" + "\x56\x55\x3B\x27\x26\x24\x26\x27\x24\x26\x27\x28\x25\x27\x27\x27\x29\x27\x26\x26\x27\x26\x27" + "\x27\x28\x28\x28\x28\x25\x28\x27\x26" + "\x26\x25\x26\x27\x26\x25\x27\x28\x27\x25\x25\x26\x28\x26\x26\x28\x26\x26\x26\x27\x26\x26\x27" + "\x26\x27\x26\x28\x27\x27\x27\x26\x25" + "\x56\x56\x43\x2C\x25\x25\x27\x29\x27\x27\x28\x28\x26\x25\x27\x23\x23\x27\x26\x28\x27\x26\x27" + "\x27\x28\x26\x27\x28\x26\x2A\x29\x27" + "\x29\x29\x29\x27\x28\x28\x29\x27\x28\x27\x26\x26\x25\x27\x28\x28\x26\x27\x25\x25\x25\x27\x29" + "\x26\x25\x28\x28\x25\x28\x27\x27\x26" + "\x55\x56\x4B\x2E\x25\x28\x29\x28\x25\x25\x27\x28\x25\x25\x27\x27\x23\x24\x25\x26\x26\x26\x26" + "\x24\x25\x28\x28\x27\x25\x27\x27\x24" + "\x26\x29\x26\x23\x27\x28\x27\x28\x26\x26\x27\x27\x26\x26\x27\x25\x28\x27\x27\x26\x29\x28\x27" + "\x24\x29\x28\x27\x27\x26\x28\x28\x25" + "\x55\x56\x51\x32\x27\x28\x27\x27\x26\x29\x26\x26\x26\x26\x28\x27\x26\x28\x28\x29\x25\x27\x29" + "\x26\x26\x27\x29\x27\x26\x28\x27\x25" + "\x25\x25\x26\x27\x25\x27\x28\x26\x26\x26\x28\x2A\x29\x25\x24\x24\x26\x28\x28\x28\x26\x26\x26" + "\x25\x26\x24\x26\x27\x26\x27\x28\x27" + "\x56\x56\x55\x39\x29\x29\x28\x29\x28\x26\x26\x27\x26\x26\x25\x27\x25\x25\x26\x25\x26\x27\x28" + "\x26\x27\x26\x28\x27\x26\x27\x27\x26" + "\x26\x27\x27\x27\x27\x28\x28\x26\x29\x28\x26\x29\x29\x28\x27\x28\x27\x29\x27\x26\x25\x26\x25" + "\x26\x24\x25\x26\x27\x26\x25\x26\x28" + "\x57\x57\x57\x4A\x29\x27\x27\x27\x27\x28\x29\x29\x27\x29\x25\x25\x25\x25\x27\x29\x26\x26\x27" + "\x26\x28\x28\x27\x25\x29\x29\x27\x27" + "\x25\x26\x26\x24\x27\x27\x26\x26\x26\x28\x27\x27\x27\x26\x27\x27\x27\x28\x27\x26\x27\x26\x26" + "\x2A\x28\x26\x26\x25\x28\x26\x27\x26" + "\x57\x57\x57\x55\x32\x28\x25\x24\x28\x28\x27\x27\x27\x27\x27\x26\x26\x27\x28\x26\x25\x27\x29" + "\x27\x27\x28\x28\x24\x29\x27\x26\x26" + "\x25\x28\x26\x25\x29\x26\x26\x26\x26\x29\x28\x25\x25\x25\x27\x28\x26\x26\x26\x28\x28\x25\x27" + "\x28\x28\x28\x28\x24\x26\x26\x25\x25" + "\x57\x57\x56\x56\x43\x2B\x29\x28\x2A\x29\x29\x2A\x28\x27\x28\x27\x27\x27\x27\x29\x26\x2A\x28" + "\x24\x26\x28\x28\x25\x24\x26\x26\x26" + "\x26\x28\x28\x27\x28\x27\x25\x25\x26\x27\x27\x23\x24\x25\x25\x26\x28\x27\x27\x27\x26\x26\x28" + "\x25\x27\x27\x28\x26\x27\x27\x26\x25" + "\x56\x57\x56\x56\x54\x49\x47\x44\x42\x40\x3F\x3D\x37\x39\x38\x36\x37\x32\x30\x2F\x2A\x2C\x2B" + "\x29\x2B\x28\x28\x26\x26\x26\x27\x28" + "\x27\x25\x26\x26\x24\x25\x25\x26\x29\x27\x28\x27\x28\x26\x27\x26\x26\x28\x27\x27\x27\x26\x27" + "\x25\x28\x26\x29\x27\x27\x26\x27\x28" + "\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56\x55\x54\x53\x4F\x4C\x48\x44\x41\x3D" + "\x3B\x36\x30\x2C\x2B\x2B\x2A\x2A\x2A" + "\x28\x27\x26\x27\x28\x26\x26\x27\x28\x28\x28\x26\x25\x25\x27\x27\x27\x25\x26\x26\x28\x27\x28" + "\x28\x28\x28\x27\x27\x27\x28\x29\x27" + "\x56\x56\x57\x57\x56\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57\x57\x57\x57\x56\x57\x56\x56\x54" + "\x53\x51\x50\x4D\x49\x43\x3D\x34\x2E" + "\x2D\x2A\x26\x25\x28\x27\x28\x26\x28\x29\x27\x25\x26\x27\x27\x27\x24\x26\x28\x26\x27\x26\x25" + "\x29\x28\x29\x27\x26\x27\x27\x26\x26" + "\x56\x56\x57\x57\x56\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57\x57\x57\x57\x56\x56\x57\x57\x57" + "\x57\x57\x57\x56\x57\x58\x56\x57\x56" + "\x4B\x42\x3A\x36\x2F\x2C\x29\x28\x27\x27\x24\x23\x26\x27\x26\x28\x27\x27\x26\x25\x25\x24\x25" + "\x27\x27\x27\x28\x28\x29\x25\x22\x26" + "\x57\x57\x57\x57\x56\x57\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56\x56\x57\x57\x57" + "\x57\x57\x57\x56\x57\x57\x57\x57\x57" + "\x56\x57\x56\x52\x4C\x46\x41\x3C\x34\x2C\x28\x27\x27\x28\x26\x27\x28\x26\x27\x26\x25\x25\x26" + "\x27\x28\x26\x25\x26\x25\x27\x28\x26" + "\x57\x57\x57\x57\x57\x57\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57\x57\x57\x57\x57" + "\x57\x56\x57\x57\x57\x57\x57\x57\x57" + "\x56\x57\x57\x56\x56\x57\x55\x53\x50\x4B\x41\x35\x2B\x29\x28\x26\x26\x27\x26\x26\x27\x28\x29" + "\x29\x2B\x28\x27\x28\x29\x28\x28\x28" + "\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56\x56\x57\x57\x57\x57\x56\x56\x56\x57\x57\x57\x57" + "\x57\x56\x57\x57\x56\x57\x57\x57\x57" + "\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56\x57\x52\x46\x38\x31\x2C\x2A\x27\x26\x25\x27\x27" + "\x26\x25\x24\x27\x28\x23\x26\x28\x27" + "\x56\x55\x55\x56\x58\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x56\x56\x56\x57\x57\x57\x57" + "\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57\x57\x57\x57\x55\x4F\x46\x3F\x34\x2B\x29\x2B\x28" + "\x26\x25\x28\x28\x27\x24\x26\x28\x25" + "\x39\x38\x37\x37\x39\x3B\x3F\x40\x44\x47\x49\x4A\x4C\x50\x53\x56\x57\x57\x57\x58\x57\x57\x57" + "\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x57\x57\x57\x56\x56\x56\x56\x56\x56\x56\x58\x56\x57\x57\x57\x56\x54\x50\x4B\x3F\x31\x29" + "\x27\x26\x26\x26\x27\x23\x29\x27\x27" + "\x2A\x29\x26\x2A\x28\x27\x26\x28\x27\x2A\x29\x29\x2D\x2D\x2C\x2F\x35\x3C\x41\x47\x4B\x4E\x50" + "\x52\x54\x56\x57\x57\x57\x57\x57\x57" + "\x56\x57\x57\x57\x56\x56\x56\x56\x56\x56\x56\x56\x56\x56\x56\x56\x56\x57\x57\x56\x56\x54\x4A" + "\x3D\x32\x2E\x27\x24\x28\x26\x26\x25" + "\x26\x25\x24\x24\x27\x26\x26\x25\x26\x24\x28\x2A\x26\x26\x26\x2A\x27\x29\x29\x2B\x2B\x31\x34" + "\x38\x3C\x43\x4A\x4E\x54\x56\x57\x57" + "\x57\x57\x57\x57\x57\x57\x56\x56\x57\x56\x56\x56\x56\x56\x56\x56\x57\x56\x56\x56\x57\x57\x57" + "\x56\x4C\x41\x35\x2D\x2B\x28\x27\x27" + "\x27\x26\x28\x28\x25\x25\x25\x26\x26\x25\x29\x2A\x28\x28\x27\x26\x26\x27\x25\x26\x27\x29\x28" + "\x29\x2A\x2A\x2F\x34\x38\x3C\x46\x4D" + "\x53\x57\x56\x56\x57\x57\x57\x57\x57\x56\x56\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57\x57" + "\x57\x56\x55\x51\x48\x38\x2C\x28\x27" + "\x27\x25\x25\x27\x26\x26\x28\x26\x27\x26\x25\x25\x26\x27\x27\x25\x26\x25\x25\x26\x27\x27\x27" + "\x27\x29\x27\x28\x2B\x29\x28\x29\x2B" + "\x2D\x34\x3F\x4A\x51\x55\x56\x57\x57\x57\x57\x57\x56\x56\x57\x57\x56\x57\x57\x56\x57\x57\x57" + "\x57\x56\x56\x56\x56\x56\x4E\x3F\x33" + "\x25\x26\x27\x28\x27\x27\x27\x25\x27\x27\x25\x27\x25\x27\x27\x27\x27\x29\x28\x28\x25\x28\x28" + "\x26\x27\x26\x28\x27\x26\x28\x27\x27" + "\x28\x28\x2A\x2C\x35\x3E\x46\x4E\x55\x57\x57\x57\x57\x57\x57\x57\x56\x57\x57\x57\x57\x57\x57" + "\x57\x57\x57\x56\x57\x57\x57\x56\x51"; + +static const BYTE TEST_64X64_BLUE_PLANE_RLE[3724] = + "\x53\x27\x23\x23\x24\x25\xF0\x28\x37\x4A\x47\x41\x3D\x38\x33\x2E\x2A\x28\x27\x26\x27\x27\xF0" + "\x27\x25\x24\x26\x28\x26\x27\x28\x28" + "\x26\x28\x28\x2A\x26\x27\xF0\x27\x28\x27\x27\x25\x26\x24\x25\x27\x28\x27\x28\x27\x27\x25\xB0" + "\x26\x27\x27\x26\x27\x27\x27\x26\x25" + "\x26\x23\xF0\x16\x0C\x0C\x06\x02\x06\x04\x04\x02\x0A\x16\x1E\x2A\x2E\x34\xF0\x3A\x3E\x3C\x30" + "\x20\x12\x0A\x08\x06\x04\x06\x02\x01" + "\x00\x01\xF0\x05\x03\x02\x00\x00\x03\x02\x00\x00\x00\x03\x01\x00\x02\x04\xF0\x02\x04\x00\x01" + "\x01\x03\x00\x00\x00\x03\x00\x01\x00" + "\x02\x00\x40\x00\x04\x02\x08\xF0\x38\x48\x38\x2C\x1E\x10\x0C\x04\x04\x04\x02\x00\x02\x06\x0A" + "\xF0\x0E\x12\x1C\x2C\x3E\x4E\x4C\x3C" + "\x28\x1E\x14\x0C\x04\x02\x02\xF0\x04\x04\x00\x01\x07\x05\x02\x04\x00\x00\x02\x02\x08\x06\x02" + "\xF0\x01\x09\x03\x04\x00\x04\x03\x08" + "\x02\x02\x03\x02\x07\x03\x00\x40\x01\x00\x04\x01\xC4\x02\x06\x16\x28\x3A\x34\x2E\x2A\x16\x06" + "\x01\x00\x13\x02\xF0\x00\x0A\x1C\x32" + "\x3A\x38\x34\x2E\x24\x14\x0C\x01\x03\x00\x04\xF0\x00\x00\x05\x03\x03\x01\x02\x00\x01\x03\x00" + "\x04\x00\x04\x04\xE0\x02\x02\x00\x04" + "\x02\x04\x00\x04\x01\x05\x06\x00\x03\x01\x04\x96\x02\x14\x22\x2A\x34\x20\x02\x02\x00\xF0\x01" + "\x02\x00\x00\x00\x0A\x14\x20\x2A\x32" + "\x3A\x34\x22\x10\x0A\xF0\x00\x04\x00\x02\x02\x04\x04\x03\x09\x05\x01\x01\x03\x02\x05\xF0\x07" + "\x03\x04\x03\x03\x03\x01\x00\x04\x02" + "\x06\x01\x02\x00\x01\xDB\x00\x00\x02\x02\x01\x00\x00\x02\x0A\x08\x00\x01\x00\xF0\x03\x01\x00" + "\x04\x0A\x12\x20\x3C\x4A\x32\x24\x10" + "\x02\x00\x04\xF0\x05\x07\x01\x08\x00\x06\x06\x02\x00\x00\x02\x01\x00\x03\x01\xA0\x00\x02\x02" + "\x01\x08\x0A\x00\x01\x02\x0A\x04\x78" + "\x02\x01\x01\x02\x00\x02\x00\x57\x02\x01\x01\x01\x00\xF0\x02\x0A\x22\x34\x34\x22\x0E\x02\x06" + "\x08\x02\x03\x01\x03\x01\xF3\x04\x00" + "\x00\x02\x04\x01\x00\x00\x04\x03\x03\x04\x03\x07\x03\x04\x23\x01\x00\x28\x01\x00\xF0\x02\x00" + "\x00\x00\x01\x02\x00\x01\x09\x15\x23" + "\x29\x1F\x0B\x00\xF0\x0A\x1C\x32\x2E\x0E\x00\x00\x02\x02\x06\x04\x06\x02\x01\x03\xF0\x01\x02" + "\x01\x00\x01\x04\x02\x04\x02\x01\x03" + "\x02\x02\x01\x01\x05\x3B\x02\x02\x00\xF0\x01\x02\x02\x00\x00\x01\x0B\x27\x43\x43\x33\x29\x33" + "\x45\x41\xE3\x1D\x05\x08\x24\x38\x18" + "\x00\x00\x04\x04\x02\x05\x02\x00\xD0\x01\x04\x00\x07\x01\x00\x07\x00\x01\x00\x01\x00\x00\x04" + "\x7D\x02\x00\x00\x00\x02\x02\x00\xF0" + "\x13\x31\x29\x03\x14\x20\x20\x1A\x0A\x0B\x31\x2B\x05\x01\x14\xF0\x28\x0A\x04\x03\x09\x01\x00" + "\x00\x01\x04\x00\x00\x06\x02\x02\xA0" + "\x01\x00\x03\x01\x04\x06\x01\x00\x00\x03\x71\xF0\x05\x2D\x13\x0A\x30\x3A\x32\x30\x32\x36\x20" + "\x03\x21\x21\x00\xF0\x00\x1C\x1A\x02" + "\x02\x04\x06\x04\x00\x02\x00\x04\x00\x02\x03\xB0\x00\x06\x06\x04\x04\x07\x00\x02\x02\x04\x02" + "\x41\xF0\x01\x00\x01\x2F\x0D\x12\x38" + "\x22\x0C\x04\x00\x02\x10\x2E\x2C\xF0\x02\x23\x17\x00\x02\x2A\x0A\x00\x03\x05\x01\x01\x02\x01" + "\x01\xE0\x01\x05\x00\x00\x01\x03\x02" + "\x01\x02\x03\x02\x02\x01\x04\x61\xF0\x0D\x11\x02\x1E\x10\x00\x01\x0F\x25\x2D\x23\x0B\x20\x10" + "\x07\xF0\x17\x03\x00\x0C\x1C\x04\x04" + "\x00\x01\x01\x00\x02\x00\x00\x00\x93\x02\x02\x02\x05\x05\x04\x02\x06\x01\x41\xF0\x02\x00\x09" + "\x07\x08\x14\x02\x00\x05\x21\x25\x21" + "\x29\x1D\x04\xF0\x1A\x02\x09\x03\x01\x04\x16\x08\x02\x02\x04\x01\x02\x02\x06\xE0\x00\x01\x04" + "\x04\x01\x04\x04\x02\x00\x03\x02\x00" + "\x02\x01\x11\x13\x01\xF0\x00\x0F\x05\x00\x0A\x01\x01\x04\x12\x0A\x0C\x12\x10\x02\x12\xF0\x02" + "\x05\x07\x00\x02\x14\x16\x04\x03\x03" + "\x02\x00\x00\x03\x01\xD0\x04\x01\x01\x04\x00\x03\x05\x05\x01\x03\x05\x00\x04\x31\xF0\x02\x00" + "\x00\x06\x04\x00\x03\x02\x00\x02\x1E" + "\x38\x36\x34\x1A\xF0\x02\x03\x01\x00\x02\x02\x00\x08\x12\x02\x04\x02\x02\x00\x07\xF0\x05\x02" + "\x02\x03\x01\x01\x06\x04\x02\x02\x00" + "\x02\x04\x02\x02\x11\xF0\x02\x02\x00\x00\x01\x0A\x08\x07\x0D\x00\x02\x04\x04\x0C\x12\xF0\x0A" + "\x02\x00\x13\x00\x04\x06\x00\x00\x02" + "\x16\x08\x00\x00\x00\xF0\x02\x04\x04\x00\x01\x00\x00\x02\x00\x00\x00\x06\x06\x00\x01\x20\x00" + "\x07\x0C\x37\x01\x07\x00\xF0\x10\x0C" + "\x03\x23\x09\x01\x01\x00\x02\x02\x00\x00\x15\x1D\x02\xF0\x12\x08\x00\x01\x01\x12\x14\x01\x01" + "\x01\x09\x03\x01\x00\x00\xC0\x02\x01" + "\x03\x05\x03\x00\x00\x01\x02\x06\x01\x06\x06\xF0\x01\x00\x01\x00\x00\x00\x01\x13\x27\x0D\x00" + "\x00\x01\x01\x00\x83\x00\x0A\x22\x01" + "\x11\x25\x09\x00\xF0\x01\x15\x29\x09\x0E\x1E\x02\x00\x02\x02\x02\x16\x04\x02\x00\xF0\x02\x01" + "\x00\x00\x00\x01\x00\x02\x02\x04\x00" + "\x03\x05\x02\x00\x20\x02\x01\x0C\xF0\x02\x06\x1B\x35\x21\x03\x00\x00\x02\x02\x02\x1A\x1E\x07" + "\x21\xC4\x31\x21\x11\x0D\x15\x29\x33" + "\x15\x01\x2A\x0E\x00\xF0\x16\x08\x04\x00\x02\x06\x02\x04\x00\x04\x00\x03\x01\x03\x01\x60\x01" + "\x01\x05\x01\x00\x00\x0C\xF0\x02\x12" + "\x16\x11\x35\x3F\x1B\x07\x01\x00\x00\x04\x32\x30\x06\xB5\x1D\x33\x43\x45\x3F\x29\x07\x18\x40" + "\x18\x00\xF0\x10\x0C\x01\x02\x02\x05" + "\x01\x03\x05\x01\x02\x02\x02\x00\x04\x60\x04\x08\x02\x00\x01\x02\x58\x00\x02\x02\x02\x00\xF0" + "\x04\x14\x08\x01\x15\x33\x33\x1B\x07" + "\x00\x00\x06\x22\x32\x2C\xF0\x16\x0A\x08\x12\x1C\x2C\x30\x16\x00\x01\x01\x00\x01\x00\x01\xF0" + "\x0F\x07\x00\x01\x00\x04\x04\x00\x06" + "\x04\x02\x02\x02\x06\x01\x60\x03\x01\x00\x04\x02\x01\x24\x02\x00\x26\x02\x00\xF0\x14\x22\x06" + "\x02\x09\x21\x31\x35\x1D\x03\x00\x04" + "\x18\x2C\x36\x84\x3C\x3A\x3C\x32\x22\x0E\x02\x00\xF0\x09\x2B\x39\x0B\x02\x04\x00\x00\x03\x01" + "\x01\x05\x00\x00\x04\x80\x01\x04\x00" + "\x01\x00\x01\x01\x02\x04\x28\x02\x00\xF0\x04\x2A\x4A\x2E\x1A\x10\x07\x19\x37\x47\x2B\x15\x07" + "\x00\x0A\xF0\x10\x12\x08\x06\x02\x01" + "\x00\x01\x00\x03\x0B\x2D\x45\x2B\x17\xF0\x03\x05\x05\x01\x04\x02\x04\x04\x00\x03\x02\x05\x01" + "\x01\x02\x50\x04\x02\x00\x02\x02\x0E" + "\xF0\x02\x00\x0A\x28\x34\x2E\x1A\x04\x05\x0F\x2D\x37\x33\x29\x1B\xF0\x11\x09\x01\x02\x02\x00" + "\x01\x0D\x1B\x29\x37\x29\x07\x02\x0E" + "\x33\x02\x01\x00\xE0\x01\x01\x00\x03\x00\x01\x01\x05\x02\x02\x01\x02\x02\x03\x3E\x02\x02\x00" + "\xF0\x02\x0E\x20\x32\x38\x28\x10\x06" + "\x09\x1B\x2D\x33\x39\x39\x37\xF0\x33\x37\x39\x3D\x37\x33\x2B\x15\x02\x18\x36\x34\x00\x00\x02" + "\xF0\x02\x02\x01\x03\x01\x04\x04\x00" + "\x00\x02\x00\x02\x00\x01\x00\x20\x03\x01\x44\x00\x00\x02\x00\x25\x02\x00\x23\x02\x00\xF0\x0A" + "\x1C\x34\x46\x3A\x26\x16\x0A\x0D\x0F" + "\x19\x21\x27\x21\x19\xF0\x17\x0F\x02\x18\x28\x46\x3E\x20\x03\x06\x00\x00\x04\x05\x00\xE0\x04" + "\x01\x05\x00\x03\x04\x00\x03\x05\x05" + "\x02\x01\x01\x04\x03\x4C\x02\x00\x02\x00\xF0\x02\x02\x00\x00\x06\x1A\x30\x36\x34\x32\x2A\x20" + "\x16\x10\x12\xF0\x18\x20\x2C\x32\x34" + "\x2E\x12\x02\x01\x19\x01\x06\x02\x03\x00\xF0\x00\x01\x05\x04\x02\x02\x01\x01\x06\x02\x00\x02" + "\x00\x04\x02\x2F\x02\x00\x08\xF0\x02" + "\x0E\x1C\x2A\x2C\x34\x3A\x3C\x38\x34\x30\x28\x1C\x10\x04\xF0\x00\x00\x17\x11\x07\x03\x02\x01" + "\x02\x00\x02\x0A\x00\x03\x01\x90\x04" + "\x02\x04\x02\x02\x00\x00\x00\x01\x3F\x00\x02\x00\x09\xF0\x02\x02\x06\x08\x0A\x10\x0E\x08\x06" + "\x02\x00\x01\x00\x0B\x27\xF0\x31\x09" + "\x03\x03\x07\x01\x02\x04\x03\x01\x01\x04\x04\x05\x01\x70\x00\x00\x01\x00\x00\x04\x01\x9F\x00" + "\x00\x02\x00\x02\x00\x00\x02\x00\x09" + "\x23\x02\x00\xF0\x07\x1D\x31\x2D\x11\x05\x02\x02\x00\x00\x03\x01\x02\x00\x01\xB0\x01\x00\x04" + "\x04\x01\x03\x00\x02\x00\x07\x00\x29" + "\x02\x00\x2B\x02\x00\x33\x01\x01\x00\xF0\x02\x02\x02\x00\x02\x02\x07\x25\x39\x33\x21\x07\x04" + "\x00\x03\xF0\x00\x02\x04\x04\x00\x02" + "\x04\x02\x01\x03\x05\x03\x01\x00\x01\x40\x03\x02\x04\x02\x93\x00\x02\x00\x02\x00\x01\x01\x01" + "\x00\xA4\x01\x01\x01\x00\x01\x01\x00" + "\x00\x01\x00\xF0\x01\x02\x01\x01\x01\x05\x0D\x11\x21\x3B\x49\x2F\x17\x0B\x00\xF0\x01\x01\x02" + "\x06\x02\x00\x02\x06\x02\x02\x00\x00" + "\x02\x00\x04\x80\x02\x06\x06\x06\x01\x00\x04\x03\xF0\x00\x00\x01\x01\x00\x03\x0F\x13\x1B\x1B" + "\x15\x0F\x09\x07\x01\x24\x01\x00\xF0" + "\x01\x00\x01\x02\x00\x03\x0F\x0F\x19\x25\x29\x33\x3B\x37\x1D\xF0\x09\x07\x01\x00\x00\x03\x03" + "\x01\x00\x02\x00\x01\x05\x05\x01\xD0" + "\x00\x02\x00\x00\x02\x00\x01\x05\x03\x02\x01\x03\x02\xF0\x02\x00\x02\x00\x21\x35\x33\x33\x35" + "\x35\x39\x39\x37\x3B\x41\xF0\x3B\x33" + "\x2B\x27\x23\x23\x25\x27\x29\x33\x3B\x3B\x39\x35\x33\xF0\x31\x27\x1F\x0D\x03\x07\x02\x00\x01" + "\x01\x04\x04\x02\x02\x00\xF0\x03\x00" + "\x02\x00\x00\x03\x01\x02\x00\x00\x03\x00\x01\x03\x01\x40\x04\x01\x02\x02\xF0\x01\x01\x01\x2B" + "\x31\x23\x1D\x17\x11\x0B\x0B\x13\x1B" + "\x19\x13\xF0\x1B\x29\x31\x37\x37\x35\x35\x33\x2F\x29\x1B\x19\x15\x17\x11\x83\x05\x03\x01\x05" + "\x03\x00\x03\x01\xF0\x02\x04\x02\x02" + "\x00\x01\x00\x00\x04\x08\x01\x02\x00\x02\x04\x80\x02\x02\x06\x02\x05\x01\x03\x01\xF0\x00\x02" + "\x13\x1B\x09\x01\x00\x00\x02\x02\x00" + "\x03\x03\x00\x05\xE3\x09\x01\x02\x02\x05\x03\x00\x03\x05\x01\x07\x05\x01\x03\xF0\x01\x00\x02" + "\x02\x04\x02\x00\x00\x01\x04\x00\x03" + "\x03\x01\x00\xF0\x00\x00\x01\x03\x04\x00\x00\x00\x01\x01\x02\x04\x00\x02\x02\x20\x00\x00\xF0" + "\x04\x00\x11\x0D\x00\x00\x02\x04\x00" + "\x03\x01\x06\x02\x05\x01\x13\x02\xF0\x01\x01\x00\x02\x00\x02\x02\x04\x00\x00\x08\x04\x00\x04" + "\x02\xF0\x03\x03\x05\x00\x02\x00\x03" + "\x03\x05\x05\x04\x02\x02\x01\x00\xF0\x02\x00\x00\x09\x02\x00\x04\x00\x03\x02\x00\x01\x00\x00" + "\x00\xF0\x01\x03\x0B\x00\x01\x00\x04" + "\x01\x02\x01\x01\x05\x02\x06\x02\xF0\x04\x04\x02\x01\x08\x02\x03\x01\x02\x01\x00\x00\x04\x06" + "\x01\xF0\x00\x02\x00\x02\x00\x03\x02" + "\x01\x02\x00\x03\x05\x00\x04\x02\xF0\x02\x00\x03\x01\x00\x00\x01\x00\x05\x01\x01\x02\x02\x01" + "\x04\x40\x04\x02\x00\x02\xF0\x02\x00" + "\x03\x00\x01\x04\x04\x00\x01\x00\x02\x02\x01\x01\x00\xF0\x03\x00\x05\x01\x03\x00\x01\x03\x00" + "\x00\x01\x01\x01\x00\x00\xF0\x02\x00" + "\x00\x01\x01\x04\x02\x02\x01\x02\x06\x04\x04\x02\x01\xF0\x01\x00\x02\x04\x00\x02\x00\x04\x02" + "\x01\x01\x03\x01\x03\x03\x40\x00\x02" + "\x00\x05\xF0\x00\x01\x00\x01\x00\x00\x05\x01\x02\x00\x03\x00\x06\x04\x00\xF0\x03\x03\x02\x02" + "\x01\x07\x00\x04\x00\x03\x04\x00\x03" + "\x02\x02\xF0\x01\x04\x02\x02\x04\x04\x03\x00\x00\x00\x04\x01\x03\x05\x07\xF0\x00\x01\x02\x01" + "\x01\x01\x04\x02\x04\x04\x06\x00\x04" + "\x00\x03\x40\x01\x00\x04\x00\x83\x02\x04\x02\x00\x08\x04\x06\x04\xF0\x00\x02\x04\x04\x0A\x00" + "\x01\x01\x00\x04\x02\x00\x02\x06\x03" + "\xF0\x00\x04\x05\x01\x02\x05\x03\x05\x00\x01\x03\x01\x01\x00\x05\xF0\x01\x05\x02\x08\x02\x06" + "\x00\x00\x02\x01\x05\x04\x00\x00\x03" + "\x80\x06\x03\x00\x02\x00\x05\x03\x04\xF0\x00\x04\x04\x01\x03\x07\x03\x00\x07\x01\x00\x02\x09" + "\x05\x03\xF0\x03\x04\x00\x01\x00\x04" + "\x00\x00\x01\x00\x04\x02\x00\x01\x02\xF0\x01\x01\x00\x00\x00\x02\x04\x01\x02\x02\x04\x00\x04" + "\x02\x02\xF0\x00\x03\x02\x01\x01\x00" + "\x02\x05\x01\x00\x01\x01\x00\x04\x04\x40\x02\x04\x00\x01\xF0\x00\x02\x10\x0A\x01\x02\x02\x04" + "\x06\x02\x02\x00\x02\x03\x00\x64\x07" + "\x0B\x00\x00\x04\x00\xF0\x03\x01\x00\x02\x04\x04\x02\x06\x08\x06\x00\x04\x06\x04\x01\xF0\x02" + "\x04\x02\x00\x05\x02\x04\x00\x00\x02" + "\x01\x03\x01\x02\x04\x90\x00\x03\x04\x00\x03\x02\x00\x02\x02\xF0\x01\x00\x10\x04\x00\x06\x04" + "\x01\x03\x03\x01\x00\x01\x00\x00\xF0" + "\x08\x00\x05\x01\x03\x01\x00\x01\x05\x05\x04\x02\x01\x01\x05\xF0\x03\x05\x05\x00\x05\x07\x01" + "\x00\x03\x02\x03\x01\x02\x02\x02\xF0" + "\x01\x01\x05\x04\x00\x04\x02\x08\x02\x03\x03\x08\x00\x01\x04\x40\x03\x02\x02\x01\xF0\x00\x00" + "\x0C\x08\x04\x00\x03\x01\x02\x08\x01" + "\x03\x02\x02\x02\xF0\x00\x06\x08\x06\x06\x01\x02\x06\x04\x02\x01\x02\x00\x02\x02\xF0\x00\x02" + "\x01\x07\x00\x08\x03\x01\x02\x03\x00" + "\x00\x02\x06\x06\xF0\x01\x05\x01\x03\x02\x02\x04\x05\x03\x01\x02\x05\x07\x01\x00\x40\x00\x01" + "\x00\x04\xF0\x02\x00\x08\x0E\x04\x02" + "\x02\x04\x04\x05\x00\x02\x00\x00\x05\xF0\x00\x01\x05\x03\x07\x02\x00\x01\x00\x02\x01\x01\x00" + "\x00\x01\xF0\x00\x02\x02\x04\x02\x00" + "\x04\x02\x00\x00\x06\x04\x03\x01\x00\xF0\x06\x06\x08\x02\x02\x01\x03\x01\x00\x01\x02\x03\x02" + "\x00\x00\x40\x00\x03\x03\x02\xF0\x02" + "\x02\x04\x22\x00\x03\x01\x03\x01\x04\x06\x04\x02\x06\x00\xF0\x03\x00\x00\x02\x08\x00\x01\x01" + "\x00\x02\x04\x01\x03\x06\x04\xF0\x00" + "\x02\x01\x01\x01\x05\x00\x01\x03\x00\x05\x00\x02\x03\x03\xF0\x03\x00\x01\x00\x01\x00\x00\x04" + "\x00\x02\x08\x08\x02\x00\x03\x40\x04" + "\x02\x02\x03\x03\xF0\x16\x12\x02\x03\x05\x02\x00\x03\x03\x00\x03\x04\x02\x02\x04\xF0\x02\x05" + "\x01\x02\x04\x02\x01\x00\x02\x01\x00" + "\x03\x01\x01\x00\xF0\x04\x00\x02\x04\x01\x00\x00\x00\x02\x02\x03\x03\x01\x00\x02\xF0\x01\x03" + "\x01\x04\x02\x01\x02\x03\x00\x04\x04" + "\x01\x03\x00\x03\x10\x01\xF0\x00\x00\x01\x02\x22\x06\x08\x08\x04\x02\x04\x06\x02\x00\x02\xF0" + "\x02\x02\x00\x01\x06\x02\x06\x01\x05" + "\x01\x00\x00\x02\x09\x01\xF0\x00\x00\x02\x00\x04\x04\x01\x02\x01\x01\x00\x03\x01\x03\x01\xF0" + "\x00\x03\x03\x04\x02\x02\x01\x03\x02" + "\x02\x05\x01\x01\x00\x04\x40\x02\x02\x02\x00\xF0\x01\x00\x00\x00\x22\x3C\x3C\x38\x30\x2E\x2C" + "\x26\x1E\x24\x20\xF0\x1E\x20\x16\x12" + "\x0C\x08\x04\x06\x0A\x0A\x00\x00\x02\x04\x00\xF0\x02\x04\x02\x05\x03\x01\x07\x03\x00\x02\x06" + "\x00\x02\x08\x08\xF0\x02\x04\x00\x03" + "\x02\x00\x00\x02\x00\x01\x00\x02\x01\x02\x02\x40\x00\x01\x02\x06\xF0\x02\x00\x02\x02\x06\x1C" + "\x20\x26\x2A\x2E\x30\x34\x40\x3A\x3A" + "\xF0\x3C\x38\x3A\x38\x32\x34\x2A\x24\x24\x16\x10\x08\x0A\x0A\x08\xF0\x06\x04\x02\x04\x00\x02" + "\x08\x02\x02\x02\x01\x02\x00\x01\x05" + "\xF0\x01\x00\x02\x02\x05\x01\x01\x02\x02\x02\x06\x00\x04\x03\x00\x40\x00\x04\x04\x01\x66\x01" + "\x01\x00\x00\x01\x00\xF0\x01\x02\x04" + "\x06\x08\x10\x14\x1E\x24\x2A\x2E\x30\x36\x40\x42\xF0\x3C\x30\x26\x14\x08\x0A\x06\x00\x03\x00" + "\x02\x04\x01\x00\x02\xF0\x01\x01\x02" + "\x04\x00\x00\x05\x02\x04\x00\x01\x01\x05\x02\x00\x70\x02\x00\x01\x00\x01\x05\x01\x31\xF0\x01" + "\x02\x02\x06\x08\x0C\x0E\x12\x1C\x2A" + "\x32\x46\x50\x3C\x30\xF0\x28\x22\x0E\x0A\x02\x04\x01\x03\x05\x03\x00\x00\x01\x02\x06\xF0\x02" + "\x03\x01\x03\x03\x00\x03\x01\x03\x02" + "\x04\x04\x03\x07\x00\x33\x02\x02\x00\x33\x01\x01\x00\x2E\x02\x00\xF0\x01\x02\x00\x02\x16\x2A" + "\x38\x38\x3A\x34\x30\x28\x1A\x0A\x08" + "\xF0\x08\x02\x02\x00\x01\x02\x01\x02\x02\x00\x02\x02\x00\x02\x01\x60\x05\x03\x07\x04\x0C\x00" + "\x04\x2A\x02\x00\x53\x01\x00\x02\x02" + "\x00\x46\x01\x00\x02\x00\xF0\x02\x08\x14\x22\x28\x2E\x38\x3E\x32\x1C\x08\x02\x04\x01\x03\xF0" + "\x02\x01\x00\x04\x06\x06\x04\x06\x04" + "\x04\x04\x08\x02\x00\x04\x06\x74\x02\x02\x00\x00\x01\x01\x00\x37\x01\x01\x00\x23\x01\x00\xF0" + "\x02\x00\x00\x02\x02\x00\x04\x08\x0E" + "\x18\x2A\x44\x4E\x3A\x20\xF0\x16\x0C\x06\x02\x00\x03\x01\x03\x05\x0B\x07\x00\x00\x0B\x03\x20" + "\x00\x01\x64\x01\x03\x03\x01\x02\x00" + "\x3B\x02\x02\x00\x5B\x02\x00\x00\x02\x00\xF0\x01\x00\x02\x00\x0A\x22\x3A\x3C\x34\x2A\x1A\x0A" + "\x08\x08\x02\x90\x00\x00\x08\x02\x01" + "\x02\x00\x00\x03\xF0\x39\x39\x3B\x3D\x3D\x37\x2F\x2D\x25\x1F\x1B\x19\x15\x0D\x07\x23\x01\x02" + "\x1F\x00\x13\x01\xF0\x00\x01\x01\x02" + "\x01\x00\x04\x10\x20\x2A\x38\x40\x2C\x0C\x02\x90\x02\x02\x03\x03\x00\x01\x06\x01\x04\xF0\x1D" + "\x1D\x21\x19\x21\x27\x31\x2F\x39\x39" + "\x3F\x41\x3D\x45\x4D\xC5\x4D\x43\x35\x2B\x21\x17\x11\x0D\x09\x05\x01\x00\x29\x01\x00\xF0\x03" + "\x00\x01\x01\x01\x00\x06\x0E\x16\x2E" + "\x46\x42\x2C\x18\x10\x60\x02\x05\x0A\x05\x01\x03\xF0\x07\x07\x03\x0B\x01\x01\x00\x05\x01\x0B" + "\x01\x02\x0D\x0D\x0B\xF0\x09\x1B\x25" + "\x2F\x37\x3F\x39\x37\x33\x2F\x25\x19\x11\x05\x01\xC6\x00\x00\x02\x00\x00\x00\x02\x02\x00\x00" + "\x02\x00\xF0\x02\x01\x01\x00\x02\x06" + "\x1A\x32\x34\x26\x1C\x12\x06\x04\x02\x10\x04\xF0\x02\x02\x08\x08\x03\x01\x01\x02\x00\x02\x02" + "\x00\x04\x04\x02\xF0\x07\x01\x03\x07" + "\x09\x07\x0F\x17\x1D\x23\x31\x35\x33\x37\x33\xE4\x21\x13\x07\x00\x01\x01\x00\x00\x02\x02\x00" + "\x00\x00\x02\xF0\x00\x02\x02\x02\x00" + "\x00\x00\x02\x14\x28\x38\x36\x1A\x08\x02\x10\x00\xF0\x00\x01\x05\x01\x02\x02\x06\x00\x02\x02" + "\x07\x09\x03\x01\x00\xF0\x01\x00\x03" + "\x00\x00\x00\x03\x01\x03\x01\x05\x0D\x11\x1D\x27\xF0\x39\x43\x4B\x45\x2D\x17\x0B\x03\x01\x00" + "\x00\x02\x02\x00\x01\x84\x01\x00\x00" + "\x01\x00\x00\x01\x00\x70\x02\x0A\x1C\x3C\x44\x2E\x18\xF0\x03\x02\x04\x02\x02\x02\x01\x01\x00" + "\x02\x00\x04\x01\x00\x00\xF0\x04\x02" + "\x08\x06\x04\x03\x02\x02\x01\x03\x01\x00\x07\x05\x00\xF0\x03\x07\x09\x17\x29\x3B\x37\x2D\x1F" + "\x11\x03\x00\x00\x00\x02\x24\x02\x00" + "\x23\x02\x00\x80\x02\x02\x00\x02\x02\x12\x2E\x3C"; + +/** + * [MS-RDPEGDI] Test Bitmap 32x32 (16bpp) + */ + +static const BYTE TEST_RLE_UNCOMPRESSED_BITMAP_16BPP[2048] = + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84" + "\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x99\xD6\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\xFF\xFF" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84" + "\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x08\x42" + "\x08\x42\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84" + "\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x99\xD6\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\xFF\xFF" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84" + "\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x08\x42" + "\x08\x42\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00" + "\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6" + "\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00" + "\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00" + "\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00" + "\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00" + "\x00\x00\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00" + "\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00" + "\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6" + "\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x00\x00\x00\x00\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\xFF\xFF" + "\xFF\xFF\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6" + "\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x99\xD6\x10\x84\x08\x42" + "\x08\x42\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84" + "\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x10\x84\x99\xD6\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42" + "\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\x08\x42\xFF\xFF"; + +static const UINT32 colorFormatList[] = { + PIXEL_FORMAT_RGB15, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_BGR16, + PIXEL_FORMAT_RGB24, PIXEL_FORMAT_BGR24, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32, + PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRX32 + +}; +static const UINT32 colorFormatCount = sizeof(colorFormatList) / sizeof(colorFormatList[0]); + +static BOOL CompareBitmap(const BYTE* srcA, UINT32 srcAFormat, const BYTE* srcB, UINT32 srcBFormat, + UINT32 width, UINT32 height) +{ + double maxDiff = NAN; + const UINT32 srcABits = FreeRDPGetBitsPerPixel(srcAFormat); + const UINT32 srcBBits = FreeRDPGetBitsPerPixel(srcBFormat); + UINT32 diff = WINPR_ASSERTING_INT_CAST(uint32_t, fabs((double)srcABits - srcBBits)); + + /* No support for 8bpp */ + if ((srcABits < 15) || (srcBBits < 15)) + return FALSE; + + /* Compare with following granularity: + * 32 --> 24 bpp: Each color channel has 8bpp, no difference expected + * 24/32 --> 15/16 bpp: 8bit per channel against 5/6bit per channel, +/- 3bit + * 16 --> 15bpp: 5/6bit per channel against 5 bit per channel, +/- 1bit + */ + switch (diff) + { + case 1: + maxDiff = 2 * 2.0; + break; + + case 8: + case 9: + case 16: + case 17: + maxDiff = 2 * 8.0; + break; + + default: + maxDiff = 0.0; + break; + } + + if ((srcABits == 32) || (srcBBits == 32)) + { + if (diff == 8) + maxDiff = 0.0; + } + + for (size_t y = 0; y < height; y++) + { + const BYTE* lineA = &srcA[y * width * FreeRDPGetBytesPerPixel(srcAFormat)]; + const BYTE* lineB = &srcB[y * width * FreeRDPGetBytesPerPixel(srcBFormat)]; + + for (size_t x = 0; x < width; x++) + { + BYTE sR = 0; + BYTE sG = 0; + BYTE sB = 0; + BYTE sA = 0; + BYTE dR = 0; + BYTE dG = 0; + BYTE dB = 0; + BYTE dA = 0; + const BYTE* a = &lineA[x * FreeRDPGetBytesPerPixel(srcAFormat)]; + const BYTE* b = &lineB[x * FreeRDPGetBytesPerPixel(srcBFormat)]; + UINT32 colorA = FreeRDPReadColor(a, srcAFormat); + UINT32 colorB = FreeRDPReadColor(b, srcBFormat); + FreeRDPSplitColor(colorA, srcAFormat, &sR, &sG, &sB, &sA, NULL); + FreeRDPSplitColor(colorB, srcBFormat, &dR, &dG, &dB, &dA, NULL); + + if (fabs((double)sR - dR) > maxDiff) + return FALSE; + + if (fabs((double)sG - dG) > maxDiff) + return FALSE; + + if (fabs((double)sB - dB) > maxDiff) + return FALSE; + + if (fabs((double)sA - dA) > maxDiff) + return FALSE; + } + } + + return TRUE; +} + +static BOOL RunTestPlanar(BITMAP_PLANAR_CONTEXT* planar, const BYTE* srcBitmap, + const UINT32 srcFormat, const UINT32 dstFormat, const UINT32 width, + const UINT32 height) +{ + BOOL rc = FALSE; + UINT32 dstSize = 0; + BYTE* compressedBitmap = freerdp_bitmap_compress_planar(planar, srcBitmap, srcFormat, width, + height, 0, NULL, &dstSize); + BYTE* decompressedBitmap = + (BYTE*)calloc(height, 1ULL * width * FreeRDPGetBytesPerPixel(dstFormat)); + (void)printf("%s [%s] --> [%s]: ", __func__, FreeRDPGetColorFormatName(srcFormat), + FreeRDPGetColorFormatName(dstFormat)); + (void)fflush(stdout); + printf("TODO: Skipping unfinished test!"); + rc = TRUE; + goto fail; + + if (!compressedBitmap || !decompressedBitmap) + goto fail; + + if (!planar_decompress(planar, compressedBitmap, dstSize, width, height, decompressedBitmap, + dstFormat, 0, 0, 0, width, height, FALSE)) + { + printf("failed to decompress experimental bitmap 01: width: %" PRIu32 " height: %" PRIu32 + "\n", + width, height); + goto fail; + } + + if (!CompareBitmap(decompressedBitmap, dstFormat, srcBitmap, srcFormat, width, height)) + { + printf("FAIL"); + goto fail; + } + + printf("SUCCESS"); + rc = TRUE; +fail: + free(compressedBitmap); + free(decompressedBitmap); + (void)printf("\n"); + (void)fflush(stdout); + return rc; +} + +static BOOL RunTestPlanarSingleColor(BITMAP_PLANAR_CONTEXT* planar, const UINT32 srcFormat, + const UINT32 dstFormat) +{ + BOOL rc = FALSE; + (void)printf("%s: [%s] --> [%s]: ", __func__, FreeRDPGetColorFormatName(srcFormat), + FreeRDPGetColorFormatName(dstFormat)); + (void)fflush(stdout); + + for (UINT32 j = 0; j < 32; j += 8) + { + for (UINT32 i = 4; i < 32; i += 8) + { + UINT32 compressedSize = 0; + const UINT32 fill = j; + const UINT32 color = + FreeRDPGetColor(srcFormat, (fill >> 8) & 0xF, (fill >> 4) & 0xF, (fill)&0xF, 0xFF); + const UINT32 width = i; + const UINT32 height = i; + BOOL failed = TRUE; + const UINT32 srcSize = width * height * FreeRDPGetBytesPerPixel(srcFormat); + const UINT32 dstSize = width * height * FreeRDPGetBytesPerPixel(dstFormat); + BYTE* compressedBitmap = NULL; + BYTE* bmp = malloc(srcSize); + BYTE* decompressedBitmap = (BYTE*)malloc(dstSize); + + if (!bmp || !decompressedBitmap) + goto fail_loop; + + for (size_t y = 0; y < height; y++) + { + BYTE* line = &bmp[y * width * FreeRDPGetBytesPerPixel(srcFormat)]; + + for (size_t x = 0; x < width; x++) + { + FreeRDPWriteColor(line, srcFormat, color); + line += FreeRDPGetBytesPerPixel(srcFormat); + } + } + + compressedBitmap = freerdp_bitmap_compress_planar(planar, bmp, srcFormat, width, height, + 0, NULL, &compressedSize); + + if (!compressedBitmap) + goto fail_loop; + + if (!planar_decompress(planar, compressedBitmap, compressedSize, width, height, + decompressedBitmap, dstFormat, 0, 0, 0, width, height, FALSE)) + goto fail_loop; + + if (!CompareBitmap(decompressedBitmap, dstFormat, bmp, srcFormat, width, height)) + goto fail_loop; + + failed = FALSE; + fail_loop: + free(bmp); + free(compressedBitmap); + free(decompressedBitmap); + + if (failed) + { + printf("FAIL"); + goto fail; + } + } + } + + (void)printf("SUCCESS"); + rc = TRUE; +fail: + (void)printf("\n"); + (void)fflush(stdout); + return rc; +} + +static BOOL TestPlanar(const UINT32 format) +{ + BOOL rc = FALSE; + const DWORD planarFlags = PLANAR_FORMAT_HEADER_NA | PLANAR_FORMAT_HEADER_RLE; + BITMAP_PLANAR_CONTEXT* planar = freerdp_bitmap_planar_context_new(planarFlags, 64, 64); + + if (!planar) + goto fail; + + if (!RunTestPlanar(planar, TEST_RLE_BITMAP_EXPERIMENTAL_01, PIXEL_FORMAT_RGBX32, format, 64, + 64)) + goto fail; + + if (!RunTestPlanar(planar, TEST_RLE_BITMAP_EXPERIMENTAL_02, PIXEL_FORMAT_RGBX32, format, 64, + 64)) + goto fail; + + if (!RunTestPlanar(planar, TEST_RLE_BITMAP_EXPERIMENTAL_03, PIXEL_FORMAT_RGBX32, format, 64, + 64)) + goto fail; + + if (!RunTestPlanar(planar, TEST_RLE_UNCOMPRESSED_BITMAP_16BPP, PIXEL_FORMAT_RGB16, format, 32, + 32)) + goto fail; + + for (UINT32 x = 0; x < colorFormatCount; x++) + { + if (!RunTestPlanarSingleColor(planar, format, colorFormatList[x])) + goto fail; + } + + rc = TRUE; +fail: + freerdp_bitmap_planar_context_free(planar); + return rc; +} + +static UINT32 prand(UINT32 max) +{ + UINT32 tmp = 0; + if (max <= 1) + return 1; + winpr_RAND(&tmp, sizeof(tmp)); + return tmp % (max - 1) + 1; +} + +static BOOL FuzzPlanar(void) +{ + BOOL rc = FALSE; + const DWORD planarFlags = PLANAR_FORMAT_HEADER_NA | PLANAR_FORMAT_HEADER_RLE; + BITMAP_PLANAR_CONTEXT* planar = freerdp_bitmap_planar_context_new(planarFlags, 64, 64); + + if (!planar) + goto fail; + + for (UINT32 x = 0; x < 100; x++) + { + BYTE data[0x10000] = { 0 }; + size_t dataSize = 0x10000; + BYTE dstData[0x10000] = { 0 }; + + UINT32 DstFormat = 0; + UINT32 nDstStep = 0; + UINT32 nXDst = 0; + UINT32 nYDst = 0; + UINT32 nDstWidth = 0; + UINT32 nDstHeight = 0; + BOOL invalid = TRUE; + do + { + switch (prand(17) - 1) + { + case 0: + DstFormat = PIXEL_FORMAT_RGB8; + break; + case 1: + DstFormat = PIXEL_FORMAT_BGR15; + break; + case 2: + DstFormat = PIXEL_FORMAT_RGB15; + break; + case 3: + DstFormat = PIXEL_FORMAT_ABGR15; + break; + case 4: + DstFormat = PIXEL_FORMAT_ABGR15; + break; + case 5: + DstFormat = PIXEL_FORMAT_BGR16; + break; + case 6: + DstFormat = PIXEL_FORMAT_RGB16; + break; + case 7: + DstFormat = PIXEL_FORMAT_BGR24; + break; + case 8: + DstFormat = PIXEL_FORMAT_RGB24; + break; + case 9: + DstFormat = PIXEL_FORMAT_BGRA32; + break; + case 10: + DstFormat = PIXEL_FORMAT_BGRX32; + break; + case 11: + DstFormat = PIXEL_FORMAT_RGBA32; + break; + case 12: + DstFormat = PIXEL_FORMAT_RGBX32; + break; + case 13: + DstFormat = PIXEL_FORMAT_ABGR32; + break; + case 14: + DstFormat = PIXEL_FORMAT_XBGR32; + break; + case 15: + DstFormat = PIXEL_FORMAT_ARGB32; + break; + case 16: + DstFormat = PIXEL_FORMAT_XRGB32; + break; + default: + break; + } + nDstStep = prand(sizeof(dstData)); + nXDst = prand(nDstStep); + nYDst = prand(sizeof(dstData) / nDstStep); + nDstWidth = prand(nDstStep / FreeRDPGetBytesPerPixel(DstFormat)); + nDstHeight = prand(sizeof(dstData) / nDstStep); + invalid = nXDst * FreeRDPGetBytesPerPixel(DstFormat) + (nYDst + nDstHeight) * nDstStep > + sizeof(dstData); + } while (invalid); + printf("DstFormat=%s, nXDst=%" PRIu32 ", nYDst=%" PRIu32 ", nDstWidth=%" PRIu32 + ", nDstHeight=%" PRIu32 ", nDstStep=%" PRIu32 ", total size=%" PRIuz "\n", + FreeRDPGetColorFormatName(DstFormat), nXDst, nYDst, nDstWidth, nDstHeight, nDstStep, + sizeof(dstData)); + freerdp_planar_switch_bgr(planar, ((prand(2) % 2) != 0) ? TRUE : FALSE); + planar_decompress(planar, data, dataSize, prand(4096), prand(4096), dstData, DstFormat, + nDstStep, nXDst, nYDst, nDstWidth, nDstHeight, + ((prand(2) % 2) != 0) ? TRUE : FALSE); + } + + rc = TRUE; +fail: + freerdp_bitmap_planar_context_free(planar); + return rc; +} + +int TestFreeRDPCodecPlanar(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!FuzzPlanar()) + return -2; + + for (UINT32 x = 0; x < colorFormatCount; x++) + { + if (!TestPlanar(colorFormatList[x])) + return -1; + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c new file mode 100644 index 0000000000000000000000000000000000000000..821907b8eefefd08139d9fde06e7967bdd61e17e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecProgressive.c @@ -0,0 +1,1472 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include "../progressive.h" + +/** + * Microsoft Progressive Codec Sample Data + * (available under NDA only) + * + * ____. + * + * readme.pdf + * + * bitmaps/ + * 1920by1080-SampleImage1.bmp + * 1920by1080-SampleImage2.bmp + * 1920by1080-SampleImage3.bmp + * + * compress/ + * enc_0_0_025_sampleimage1.bin + * enc_0_0_050_sampleimage1.bin + * enc_0_0_075_sampleimage1.bin + * enc_0_0_100_sampleimage1.bin + * enc_0_1_025_sampleimage1.bin + * enc_0_1_050_sampleimage1.bin + * enc_0_1_075_sampleimage1.bin + * enc_0_1_100_sampleimage1.bin + * enc_0_2_025_sampleimage1.bin + * enc_0_2_050_sampleimage1.bin + * enc_0_2_075_sampleimage1.bin + * enc_0_2_100_sampleimage1.bin + * enc_0_3_025_sampleimage1.bin + * enc_0_3_050_sampleimage1.bin + * enc_0_3_075_sampleimage1.bin + * enc_0_3_100_sampleimage1.bin + * enc_1_0_025_sampleimage2.bin + * enc_1_0_050_sampleimage2.bin + * enc_1_0_075_sampleimage2.bin + * enc_1_0_100_sampleimage2.bin + * enc_1_1_025_sampleimage2.bin + * enc_1_1_050_sampleimage2.bin + * enc_1_1_075_sampleimage2.bin + * enc_1_1_100_sampleimage2.bin + * enc_1_2_025_sampleimage2.bin + * enc_1_2_050_sampleimage2.bin + * enc_1_2_075_sampleimage2.bin + * enc_1_2_100_sampleimage2.bin + * enc_1_3_025_sampleimage2.bin + * enc_1_3_050_sampleimage2.bin + * enc_1_3_075_sampleimage2.bin + * enc_1_3_100_sampleimage2.bin + * enc_2_0_025_sampleimage3.bin + * enc_2_0_050_sampleimage3.bin + * enc_2_0_075_sampleimage3.bin + * enc_2_0_100_sampleimage3.bin + * enc_2_1_025_sampleimage3.bin + * enc_2_1_050_sampleimage3.bin + * enc_2_1_075_sampleimage3.bin + * enc_2_1_100_sampleimage3.bin + * enc_2_2_025_sampleimage3.bin + * enc_2_2_050_sampleimage3.bin + * enc_2_2_075_sampleimage3.bin + * enc_2_2_100_sampleimage3.bin + * enc_2_3_025_sampleimage3.bin + * enc_2_3_050_sampleimage3.bin + * enc_2_3_075_sampleimage3.bin + * enc_2_3_100_sampleimage3.bin + * + * decompress/ + * dec_0_0_025_sampleimage1.bmp + * dec_0_0_050_sampleimage1.bmp + * dec_0_0_075_sampleimage1.bmp + * dec_0_0_100_sampleimage1.bmp + * dec_0_1_025_sampleimage1.bmp + * dec_0_1_050_sampleimage1.bmp + * dec_0_1_075_sampleimage1.bmp + * dec_0_1_100_sampleimage1.bmp + * dec_0_2_025_sampleimage1.bmp + * dec_0_2_050_sampleimage1.bmp + * dec_0_2_075_sampleimage1.bmp + * dec_0_2_100_sampleimage1.bmp + * dec_0_3_025_sampleimage1.bmp + * dec_0_3_050_sampleimage1.bmp + * dec_0_3_075_sampleimage1.bmp + * dec_0_3_100_sampleimage1.bmp + * dec_1_0_025_sampleimage2.bmp + * dec_1_0_050_sampleimage2.bmp + * dec_1_0_075_sampleimage2.bmp + * dec_1_0_100_sampleimage2.bmp + * dec_1_1_025_sampleimage2.bmp + * dec_1_1_050_sampleimage2.bmp + * dec_1_1_075_sampleimage2.bmp + * dec_1_1_100_sampleimage2.bmp + * dec_1_2_025_sampleimage2.bmp + * dec_1_2_050_sampleimage2.bmp + * dec_1_2_075_sampleimage2.bmp + * dec_1_2_100_sampleimage2.bmp + * dec_1_3_025_sampleimage2.bmp + * dec_1_3_050_sampleimage2.bmp + * dec_1_3_075_sampleimage2.bmp + * dec_1_3_100_sampleimage2.bmp + * dec_2_0_025_sampleimage3.bmp + * dec_2_0_050_sampleimage3.bmp + * dec_2_0_075_sampleimage3.bmp + * dec_2_0_100_sampleimage3.bmp + * dec_2_1_025_sampleimage3.bmp + * dec_2_1_050_sampleimage3.bmp + * dec_2_1_075_sampleimage3.bmp + * dec_2_1_100_sampleimage3.bmp + * dec_2_2_025_sampleimage3.bmp + * dec_2_2_050_sampleimage3.bmp + * dec_2_2_075_sampleimage3.bmp + * dec_2_2_100_sampleimage3.bmp + * dec_2_3_025_sampleimage3.bmp + * dec_2_3_050_sampleimage3.bmp + * dec_2_3_075_sampleimage3.bmp + * dec_2_3_100_sampleimage3.bmp + */ + +typedef struct +{ + BYTE* buffer; + size_t size; +} EGFX_SAMPLE_FILE; + +static int g_Width = 0; +static int g_Height = 0; +static int g_DstStep = 0; +static BYTE* g_DstData = NULL; + +static void sample_file_free(EGFX_SAMPLE_FILE* file) +{ + if (!file) + return; + + free(file->buffer); + file->buffer = NULL; + file->size = 0; +} + +static void test_fill_image_alpha_channel(BYTE* data, UINT32 width, UINT32 height, BYTE value) +{ + UINT32* pixel = NULL; + + for (UINT32 i = 0; i < height; i++) + { + for (UINT32 j = 0; j < width; j++) + { + pixel = (UINT32*)&data[((1ULL * i * width) + j) * 4ULL]; + *pixel = ((*pixel & 0x00FFFFFF) | (value << 24)); + } + } +} + +static void* test_image_memset32(UINT32* ptr, UINT32 fill, size_t length) +{ + while (length--) + { + *ptr++ = fill; + } + + return (void*)ptr; +} + +static int test_image_fill(BYTE* pDstData, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT32 color) +{ + UINT32* pDstPixel = NULL; + + if (nDstStep < 0) + nDstStep = 4 * nWidth; + + for (UINT32 y = 0; y < nHeight; y++) + { + pDstPixel = (UINT32*)&pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)]; + test_image_memset32(pDstPixel, color, nWidth); + } + + return 1; +} + +static int test_image_fill_quarter(BYTE* pDstData, UINT32 nDstStep, UINT32 nWidth, UINT32 nHeight, + UINT32 color, UINT32 quarter) +{ + UINT32 x = 0; + UINT32 y = 0; + UINT32 width = 0; + UINT32 height = 0; + + switch (quarter) + { + case 0: + x = 0; + y = 0; + width = nWidth / 2; + height = nHeight / 2; + break; + + case 1: + x = nWidth / 2; + y = nHeight / 2; + width = nWidth / 2; + height = nHeight / 2; + break; + + case 2: + x = 0; + y = nHeight / 2; + width = nWidth / 2; + height = nHeight / 2; + break; + + case 3: + x = nWidth / 2; + y = 0; + width = nWidth / 2; + height = nHeight / 2; + break; + default: + return -1; + } + + test_image_fill(pDstData, nDstStep, x, y, width, height, 0xFF000000); + return 1; +} + +static int test_image_fill_unused_quarters(BYTE* pDstData, UINT32 nDstStep, UINT32 nWidth, + UINT32 nHeight, UINT32 color, UINT32 quarter) +{ + return 1; + + if (quarter == 0) + { + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 1); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 2); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 3); + } + else if (quarter == 1) + { + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 0); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 2); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 3); + } + else if (quarter == 2) + { + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 0); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 1); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 3); + } + else if (quarter == 3) + { + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 0); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 1); + test_image_fill_quarter(pDstData, nDstStep, nWidth, nHeight, color, 2); + } + + return 1; +} + +static BYTE* test_progressive_load_file(const char* path, const char* file, size_t* size) +{ + char* filename = GetCombinedPath(path, file); + + if (!filename) + return NULL; + + FILE* fp = winpr_fopen(filename, "r"); + free(filename); + + if (!fp) + return NULL; + + (void)_fseeki64(fp, 0, SEEK_END); + const INT64 pos = _ftelli64(fp); + WINPR_ASSERT(pos >= 0); + WINPR_ASSERT(pos <= SIZE_MAX); + *size = (size_t)pos; + (void)_fseeki64(fp, 0, SEEK_SET); + BYTE* buffer = (BYTE*)malloc(*size); + + if (!buffer) + { + (void)fclose(fp); + return NULL; + } + + if (fread(buffer, *size, 1, fp) != 1) + { + free(buffer); + (void)fclose(fp); + return NULL; + } + + (void)fclose(fp); + return buffer; +} + +static int test_progressive_load_files(char* ms_sample_path, EGFX_SAMPLE_FILE files[3][4][4]) +{ + int imageNo = 0; + int quarterNo = 0; + int passNo = 0; + /* image 1 */ + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_0_025_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_0_050_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_0_075_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_0_100_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_1_025_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_1_050_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_1_075_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_1_100_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_2_025_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_2_050_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_2_075_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_2_100_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_3_025_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_3_050_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_3_075_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_0_3_100_sampleimage1.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + imageNo++; + /* image 2 */ + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_0_025_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_0_050_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_0_075_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_0_100_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_1_025_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_1_050_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_1_075_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_1_100_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_2_025_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_2_050_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_2_075_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_2_100_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_3_025_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_3_050_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_3_075_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_1_3_100_sampleimage2.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + imageNo++; + /* image 3 */ + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_0_025_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_0_050_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_0_075_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_0_100_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_1_025_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_1_050_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_1_075_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_1_100_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_2_025_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_2_050_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_2_075_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_2_100_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_3_025_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_3_050_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_3_075_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + passNo = (passNo + 1) % 4; + files[imageNo][quarterNo][passNo].buffer = + test_progressive_load_file(ms_sample_path, "compress/enc_2_3_100_sampleimage3.bin", + &(files[imageNo][quarterNo][passNo].size)); + + /* check if all test data has been loaded */ + + for (imageNo = 0; imageNo < 3; imageNo++) + { + for (quarterNo = 0; quarterNo < 4; quarterNo++) + { + for (passNo = 0; passNo < 4; passNo++) + { + if (!files[imageNo][quarterNo][passNo].buffer) + return -1; + } + } + } + + return 1; +} + +static BYTE* test_progressive_load_bitmap(char* path, char* file, size_t* size, int quarter) +{ + int status = 0; + BYTE* buffer = NULL; + wImage* image = NULL; + char* filename = NULL; + filename = GetCombinedPath(path, file); + + if (!filename) + return NULL; + + image = winpr_image_new(); + + if (!image) + return NULL; + + status = winpr_image_read(image, filename); + + if (status < 0) + return NULL; + + buffer = image->data; + *size = 1ULL * image->height * image->scanline; + test_fill_image_alpha_channel(image->data, image->width, image->height, 0xFF); + test_image_fill_unused_quarters(image->data, image->scanline, image->width, image->height, + quarter, 0xFF000000); + winpr_image_free(image, FALSE); + free(filename); + return buffer; +} + +static int test_progressive_load_bitmaps(char* ms_sample_path, EGFX_SAMPLE_FILE bitmaps[3][4][4]) +{ + int imageNo = 0; + int quarterNo = 0; + int passNo = 0; + /* image 1 */ + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_0_025_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_0_050_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_0_075_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_0_100_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_1_025_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_1_050_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_1_075_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_1_100_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_2_025_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_2_050_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_2_075_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_2_100_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_3_025_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_3_050_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_3_075_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_0_3_100_sampleimage1.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + imageNo++; + /* image 2 */ + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_0_025_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_0_050_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_0_075_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_0_100_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_1_025_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_1_050_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_1_075_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_1_100_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_2_025_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_2_050_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_2_075_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_2_100_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_3_025_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_3_050_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_3_075_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_1_3_100_sampleimage2.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + imageNo++; + /* image 3 */ + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_0_025_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_0_050_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_0_075_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_0_100_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_1_025_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_1_050_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_1_075_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_1_100_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_2_025_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_2_050_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_2_075_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_2_100_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + quarterNo = (quarterNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_3_025_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_3_050_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_3_075_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + passNo = (passNo + 1) % 4; + bitmaps[imageNo][quarterNo][passNo].buffer = + test_progressive_load_bitmap(ms_sample_path, "decompress/dec_2_3_100_sampleimage3.bmp", + &(bitmaps[imageNo][quarterNo][passNo].size), quarterNo); + + /* check if all test data has been loaded */ + + for (imageNo = 0; imageNo < 3; imageNo++) + { + for (quarterNo = 0; quarterNo < 4; quarterNo++) + { + for (passNo = 0; passNo < 4; passNo++) + { + if (!bitmaps[imageNo][quarterNo][passNo].buffer) + return -1; + } + } + } + + return 1; +} + +static size_t test_memcmp_count(const BYTE* mem1, const BYTE* mem2, size_t size, int margin) +{ + size_t count = 0; + + for (size_t index = 0; index < size; index++) + { + if (*mem1 != *mem2) + { + const int error = (*mem1 > *mem2) ? *mem1 - *mem2 : *mem2 - *mem1; + + if (error > margin) + count++; + } + + mem1++; + mem2++; + } + + return count; +} + +static int test_progressive_decode(PROGRESSIVE_CONTEXT* progressive, EGFX_SAMPLE_FILE files[4], + EGFX_SAMPLE_FILE bitmaps[4], int quarter, int count) +{ + int nXSrc = 0; + int nYSrc = 0; + + RECTANGLE_16 clippingRect = { 0 }; + clippingRect.right = g_Width; + clippingRect.bottom = g_Height; + + for (int pass = 0; pass < count; pass++) + { + const int status = + progressive_decompress(progressive, files[pass].buffer, files[pass].size, g_DstData, + PIXEL_FORMAT_XRGB32, g_DstStep, 0, 0, NULL, 0, 0); + printf("ProgressiveDecompress: status: %d pass: %d\n", status, pass + 1); + PROGRESSIVE_BLOCK_REGION* region = &(progressive->region); + + switch (quarter) + { + case 0: + clippingRect.left = 0; + clippingRect.top = 0; + clippingRect.right = g_Width / 2; + clippingRect.bottom = g_Height / 2; + break; + + case 1: + clippingRect.left = g_Width / 2; + clippingRect.top = g_Height / 2; + clippingRect.right = g_Width; + clippingRect.bottom = g_Height; + break; + + case 2: + clippingRect.left = 0; + clippingRect.top = g_Height / 2; + clippingRect.right = g_Width / 2; + clippingRect.bottom = g_Height; + break; + + case 3: + clippingRect.left = g_Width / 2; + clippingRect.top = 0; + clippingRect.right = g_Width; + clippingRect.bottom = g_Height / 2; + break; + default: + return -1; + } + + for (UINT16 index = 0; index < region->numTiles; index++) + { + RFX_PROGRESSIVE_TILE* tile = region->tiles[index]; + + const RECTANGLE_16 tileRect = { tile->x, tile->y, tile->x + tile->width, + tile->y + tile->height }; + RECTANGLE_16 updateRect = { 0 }; + rectangles_intersection(&tileRect, &clippingRect, &updateRect); + const UINT16 nXDst = updateRect.left; + const UINT16 nYDst = updateRect.top; + const UINT16 nWidth = updateRect.right - updateRect.left; + const UINT16 nHeight = updateRect.bottom - updateRect.top; + + if ((nWidth <= 0) || (nHeight <= 0)) + continue; + + nXSrc = nXDst - WINPR_ASSERTING_INT_CAST(int, tile->x); + nYSrc = nYDst - WINPR_ASSERTING_INT_CAST(int, tile->y); + freerdp_image_copy(g_DstData, PIXEL_FORMAT_XRGB32, g_DstStep, nXDst, nYDst, nWidth, + nHeight, tile->data, PIXEL_FORMAT_XRGB32, 64 * 4, nXSrc, nYSrc, NULL, + FREERDP_FLIP_NONE); + } + + const size_t size = bitmaps[pass].size; + const size_t cnt = test_memcmp_count(g_DstData, bitmaps[pass].buffer, size, 1); + + if (cnt) + { + const float rate = ((float)cnt) / ((float)size) * 100.0f; + printf("Progressive RemoteFX decompression failure\n"); + printf("Actual, Expected (%" PRIuz "/%" PRIuz " = %.3f%%):\n", cnt, size, rate); + } + + // WLog_Image(progressive->log, WLOG_TRACE, g_DstData, g_Width, g_Height, 32); + } + + return 1; +} + +static int test_progressive_ms_sample(char* ms_sample_path) +{ + int count = 0; + int status = 0; + EGFX_SAMPLE_FILE files[3][4][4] = { 0 }; + EGFX_SAMPLE_FILE bitmaps[3][4][4] = { 0 }; + PROGRESSIVE_CONTEXT* progressive = NULL; + g_Width = 1920; + g_Height = 1080; + g_DstStep = g_Width * 4; + status = test_progressive_load_files(ms_sample_path, files); + + if (status < 0) + { + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 4; j++) + { + for (int k = 0; k < 4; k++) + sample_file_free(&files[i][j][k]); + } + } + + return -1; + } + + status = test_progressive_load_bitmaps(ms_sample_path, bitmaps); + + if (status < 0) + { + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 4; j++) + { + for (int k = 0; k < 4; k++) + sample_file_free(&files[i][j][k]); + } + } + + return -1; + } + + count = 4; + progressive = progressive_context_new(FALSE); + g_DstData = winpr_aligned_malloc(1LL * g_DstStep * g_Height, 16); + progressive_create_surface_context(progressive, 0, g_Width, g_Height); + + /* image 1 */ + + if (1) + { + printf("\nSample Image 1\n"); + test_image_fill(g_DstData, g_DstStep, 0, 0, g_Width, g_Height, 0xFF000000); + test_progressive_decode(progressive, files[0][0], bitmaps[0][0], 0, count); + test_progressive_decode(progressive, files[0][1], bitmaps[0][1], 1, count); + test_progressive_decode(progressive, files[0][2], bitmaps[0][2], 2, count); + test_progressive_decode(progressive, files[0][3], bitmaps[0][3], 3, count); + } + + /* image 2 */ + + if (0) + { + printf("\nSample Image 2\n"); /* sample data is in incorrect order */ + test_image_fill(g_DstData, g_DstStep, 0, 0, g_Width, g_Height, 0xFF000000); + test_progressive_decode(progressive, files[1][0], bitmaps[1][0], 0, count); + test_progressive_decode(progressive, files[1][1], bitmaps[1][1], 1, count); + test_progressive_decode(progressive, files[1][2], bitmaps[1][2], 2, count); + test_progressive_decode(progressive, files[1][3], bitmaps[1][3], 3, count); + } + + /* image 3 */ + + if (0) + { + printf("\nSample Image 3\n"); /* sample data is in incorrect order */ + test_image_fill(g_DstData, g_DstStep, 0, 0, g_Width, g_Height, 0xFF000000); + test_progressive_decode(progressive, files[2][0], bitmaps[2][0], 0, count); + test_progressive_decode(progressive, files[2][1], bitmaps[2][1], 1, count); + test_progressive_decode(progressive, files[2][2], bitmaps[2][2], 2, count); + test_progressive_decode(progressive, files[2][3], bitmaps[2][3], 3, count); + } + + progressive_context_free(progressive); + + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 4; j++) + { + for (int k = 0; k < 4; k++) + { + sample_file_free(&bitmaps[i][j][k]); + sample_file_free(&files[i][j][k]); + } + } + } + + winpr_aligned_free(g_DstData); + return 0; +} + +static BOOL diff(BYTE a, BYTE b) +{ + BYTE big = MAX(a, b); + BYTE little = MIN(a, b); + if (big - little <= 0x25) + return TRUE; + return FALSE; +} + +static BOOL colordiff(UINT32 format, UINT32 a, UINT32 b) +{ + BYTE ar = 0; + BYTE ag = 0; + BYTE ab = 0; + BYTE aa = 0; + BYTE br = 0; + BYTE bg = 0; + BYTE bb = 0; + BYTE ba = 0; + FreeRDPSplitColor(a, format, &ar, &ag, &ab, &aa, NULL); + FreeRDPSplitColor(b, format, &br, &bg, &bb, &ba, NULL); + if (!diff(aa, ba) || !diff(ar, br) || !diff(ag, bg) || !diff(ab, bb)) + return FALSE; + return TRUE; +} + +static BOOL test_encode_decode(const char* path) +{ + BOOL res = FALSE; + int rc = 0; + BYTE* resultData = NULL; + BYTE* dstData = NULL; + UINT32 dstSize = 0; + UINT32 ColorFormat = PIXEL_FORMAT_BGRX32; + REGION16 invalidRegion = { 0 }; + wImage* image = winpr_image_new(); + wImage* dstImage = winpr_image_new(); + char* name = GetCombinedPath(path, "progressive.bmp"); + PROGRESSIVE_CONTEXT* progressiveEnc = progressive_context_new(TRUE); + PROGRESSIVE_CONTEXT* progressiveDec = progressive_context_new(FALSE); + + region16_init(&invalidRegion); + if (!image || !dstImage || !name || !progressiveEnc || !progressiveDec) + goto fail; + + rc = winpr_image_read(image, name); + if (rc <= 0) + goto fail; + + resultData = calloc(image->scanline, image->height); + if (!resultData) + goto fail; + + // Progressive encode + rc = progressive_compress(progressiveEnc, image->data, image->scanline * image->height, + ColorFormat, image->width, image->height, image->scanline, NULL, + &dstData, &dstSize); + if (rc < 0) + goto fail; + + // Progressive decode + rc = progressive_create_surface_context(progressiveDec, 0, image->width, image->height); + if (rc <= 0) + goto fail; + + rc = progressive_decompress(progressiveDec, dstData, dstSize, resultData, ColorFormat, + image->scanline, 0, 0, &invalidRegion, 0, 0); + if (rc < 0) + goto fail; + + // Compare result + if (0) // Dump result image for manual inspection + { + *dstImage = *image; + dstImage->data = resultData; + winpr_image_write(dstImage, "/tmp/test.bmp"); + } + for (size_t y = 0; y < image->height; y++) + { + const BYTE* orig = &image->data[y * image->scanline]; + const BYTE* dec = &resultData[y * image->scanline]; + for (size_t x = 0; x < image->width; x++) + { + const BYTE* po = &orig[x * 4]; + const BYTE* pd = &dec[x * 4]; + + const DWORD a = FreeRDPReadColor(po, ColorFormat); + const DWORD b = FreeRDPReadColor(pd, ColorFormat); + if (!colordiff(ColorFormat, a, b)) + { + printf("xxxxxxx [%u:%u] [%s] %08X != %08X\n", x, y, + FreeRDPGetColorFormatName(ColorFormat), a, b); + goto fail; + } + } + } + res = TRUE; +fail: + region16_uninit(&invalidRegion); + progressive_context_free(progressiveEnc); + progressive_context_free(progressiveDec); + winpr_image_free(image, TRUE); + winpr_image_free(dstImage, FALSE); + free(resultData); + free(name); + return res; +} + +static BOOL read_cmd(FILE* fp, RDPGFX_SURFACE_COMMAND* cmd, UINT32* frameId) +{ + WINPR_ASSERT(fp); + WINPR_ASSERT(cmd); + WINPR_ASSERT(frameId); + + // NOLINTBEGIN(cert-err34-c) + if (1 != fscanf(fp, "frameid: %" PRIu32 "\n", frameId)) + return FALSE; + if (1 != fscanf(fp, "surfaceId: %" PRIu32 "\n", &cmd->surfaceId)) + return FALSE; + if (1 != fscanf(fp, "codecId: %" PRIu32 "\n", &cmd->codecId)) + return FALSE; + if (1 != fscanf(fp, "contextId: %" PRIu32 "\n", &cmd->contextId)) + return FALSE; + if (1 != fscanf(fp, "format: %" PRIu32 "\n", &cmd->format)) + return FALSE; + if (1 != fscanf(fp, "left: %" PRIu32 "\n", &cmd->left)) + return FALSE; + if (1 != fscanf(fp, "top: %" PRIu32 "\n", &cmd->top)) + return FALSE; + if (1 != fscanf(fp, "right: %" PRIu32 "\n", &cmd->right)) + return FALSE; + if (1 != fscanf(fp, "bottom: %" PRIu32 "\n", &cmd->bottom)) + return FALSE; + if (1 != fscanf(fp, "width: %" PRIu32 "\n", &cmd->width)) + return FALSE; + if (1 != fscanf(fp, "height: %" PRIu32 "\n", &cmd->height)) + return FALSE; + if (1 != fscanf(fp, "length: %" PRIu32 "\n", &cmd->length)) + return FALSE; + // NOLINTEND(cert-err34-c) + + char* data = NULL; + + size_t dlen = SIZE_MAX; + SSIZE_T slen = GetLine(&data, &slen, fp); + if (slen < 0) + return FALSE; + + if (slen >= 7) + { + const char* b64 = &data[6]; + slen -= 7; + crypto_base64_decode(b64, slen, &cmd->data, &dlen); + } + free(data); + + return cmd->length == dlen; +} + +static void free_cmd(RDPGFX_SURFACE_COMMAND* cmd) +{ + free(cmd->data); +} + +static WINPR_NORETURN(void usage(const char* name)) +{ + FILE* fp = stdout; + (void)fprintf(fp, "%s \n", name); + // NOLINTNEXTLINE(concurrency-mt-unsafe) + exit(-1); +} + +static void print_codec_stats(const char* name, UINT64 timeNS) +{ + const double dectimeMS = (double)timeNS / 1000.0 / 1000.0; + (void)fprintf(stderr, "[%s] took %lf ms to decode\n", name, dectimeMS); +} + +static UINT64 measure_diff_and_print(const char* cname, UINT32 frameId, UINT64 start) +{ + const UINT64 end = winpr_GetTickCount64NS(); + const UINT64 diff = end - start; + const double ddiff = (double)diff / 1000000.0; + (void)fprintf(stderr, "frame [%s] %" PRIu32 " took %lf ms\n", cname, frameId, ddiff); + return diff; +} + +static int test_dump(int argc, char* argv[]) +{ + int success = -1; + UINT32 count = 0; + + UINT64 CAPROGRESSIVE_dectime = 0; + UINT64 UNCOMPRESSED_dectime = 0; + UINT64 CAVIDEO_dectime = 0; + UINT64 CLEARCODEC_dectime = 0; + UINT64 PLANAR_dectime = 0; + UINT64 AVC420_dectime = 0; + UINT64 ALPHA_dectime = 0; + UINT64 AVC444_dectime = 0; + UINT64 AVC444v2_dectime = 0; + UINT64 copytime = 0; + + if (argc < 4) + usage(argv[0]); + + const char* path = argv[1]; + errno = 0; + const unsigned long width = strtoul(argv[2], NULL, 0); + if ((errno != 0) || (width <= 0)) + usage(argv[0]); + const unsigned long height = strtoul(argv[3], NULL, 0); + if ((errno != 0) || (height <= 0)) + usage(argv[0]); + + rdpCodecs* codecs = freerdp_client_codecs_new(0); + if (!codecs) + return -2; + + UINT32 DstFormat = PIXEL_FORMAT_BGRA32; + const UINT32 stride = (width + 16) * FreeRDPGetBytesPerPixel(DstFormat); + + BYTE* dst = calloc(stride, height); + BYTE* output = calloc(stride, height); + if (!dst || !output) + goto fail; + + if (!freerdp_client_codecs_prepare(codecs, FREERDP_CODEC_ALL, width, height)) + goto fail; + + success = 0; + while (success >= 0) + { + char* fname = NULL; + size_t flen = 0; + winpr_asprintf(&fname, &flen, "%s/%08" PRIx32 ".raw", path, count++); + FILE* fp = fopen(fname, "r"); + free(fname); + + if (!fp) + break; + + UINT32 frameId = 0; + RDPGFX_SURFACE_COMMAND cmd = { 0 }; + + if (read_cmd(fp, &cmd, &frameId)) + { + REGION16 invalid = { 0 }; + region16_init(&invalid); + + const char* cname = rdpgfx_get_codec_id_string(cmd.codecId); + switch (cmd.codecId) + { + case RDPGFX_CODECID_CAPROGRESSIVE: + { + const UINT64 start = winpr_GetTickCount64NS(); + success = progressive_create_surface_context(codecs->progressive, cmd.surfaceId, + width, height); + if (success >= 0) + success = progressive_decompress(codecs->progressive, cmd.data, cmd.length, + dst, DstFormat, 0, cmd.left, cmd.top, + &invalid, cmd.surfaceId, frameId); + CAPROGRESSIVE_dectime += measure_diff_and_print(cname, frameId, start); + } + break; + + case RDPGFX_CODECID_UNCOMPRESSED: + { + const UINT64 start = winpr_GetTickCount64NS(); + if (!freerdp_image_copy_no_overlap(dst, DstFormat, stride, cmd.left, cmd.top, + cmd.width, cmd.height, cmd.data, cmd.format, + 0, 0, 0, NULL, FREERDP_FLIP_NONE)) + success = -1; + + RECTANGLE_16 invalidRect = { .left = (UINT16)MIN(UINT16_MAX, cmd.left), + .top = (UINT16)MIN(UINT16_MAX, cmd.top), + .right = (UINT16)MIN(UINT16_MAX, cmd.right), + .bottom = (UINT16)MIN(UINT16_MAX, cmd.bottom) }; + region16_union_rect(&invalid, &invalid, &invalidRect); + UNCOMPRESSED_dectime += measure_diff_and_print(cname, frameId, start); + } + break; + case RDPGFX_CODECID_CAVIDEO: + { + const UINT64 start = winpr_GetTickCount64NS(); + if (!rfx_process_message(codecs->rfx, cmd.data, cmd.length, cmd.left, cmd.top, + dst, DstFormat, stride, height, &invalid)) + success = -1; + + CAVIDEO_dectime += measure_diff_and_print(cname, frameId, start); + } + break; + case RDPGFX_CODECID_CLEARCODEC: + { + const UINT64 start = winpr_GetTickCount64NS(); + success = clear_decompress(codecs->clear, cmd.data, cmd.length, cmd.width, + cmd.height, dst, DstFormat, stride, cmd.left, + cmd.top, width, height, NULL); + + const RECTANGLE_16 invalidRect = { .left = (UINT16)MIN(UINT16_MAX, cmd.left), + .top = (UINT16)MIN(UINT16_MAX, cmd.top), + .right = (UINT16)MIN(UINT16_MAX, cmd.right), + .bottom = + (UINT16)MIN(UINT16_MAX, cmd.bottom) }; + region16_union_rect(&invalid, &invalid, &invalidRect); + CLEARCODEC_dectime += measure_diff_and_print(cname, frameId, start); + } + break; + case RDPGFX_CODECID_PLANAR: + { + const UINT64 start = winpr_GetTickCount64NS(); + + if (!planar_decompress(codecs->planar, cmd.data, cmd.length, cmd.width, + cmd.height, dst, DstFormat, stride, cmd.left, cmd.top, + cmd.width, cmd.height, FALSE)) + success = -1; + + const RECTANGLE_16 invalidRect = { .left = (UINT16)MIN(UINT16_MAX, cmd.left), + .top = (UINT16)MIN(UINT16_MAX, cmd.top), + .right = (UINT16)MIN(UINT16_MAX, cmd.right), + .bottom = + (UINT16)MIN(UINT16_MAX, cmd.bottom) }; + region16_union_rect(&invalid, &invalid, &invalidRect); + + PLANAR_dectime += measure_diff_and_print(cname, frameId, start); + } + break; + case RDPGFX_CODECID_AVC420: + { + const UINT64 start = winpr_GetTickCount64NS(); + + AVC420_dectime += measure_diff_and_print(cname, frameId, start); + success = -1; + } + break; + case RDPGFX_CODECID_ALPHA: + { + const UINT64 start = winpr_GetTickCount64NS(); + + ALPHA_dectime += measure_diff_and_print(cname, frameId, start); + success = -1; + } + break; + case RDPGFX_CODECID_AVC444: + { + const UINT64 start = winpr_GetTickCount64NS(); + + AVC444_dectime += measure_diff_and_print(cname, frameId, start); + success = -1; + } + break; + case RDPGFX_CODECID_AVC444v2: + { + const UINT64 start = winpr_GetTickCount64NS(); + + AVC444v2_dectime += measure_diff_and_print(cname, frameId, start); + success = -1; + } + break; + default: + (void)fprintf(stderr, "unexpected codec %s [0x%08" PRIx32 "]", + rdpgfx_get_codec_id_string(cmd.codecId), cmd.codecId); + success = -1; + break; + } + + if (success >= 0) + { + UINT32 nbRects = 0; + const UINT64 start = winpr_GetTickCount64NS(); + + const RECTANGLE_16* rects = region16_rects(&invalid, &nbRects); + for (size_t x = 0; x < nbRects; x++) + { + RECTANGLE_16* rect = &rects[x]; + const UINT32 w = rect->right - rect->left; + const UINT32 h = rect->bottom - rect->top; + if (!freerdp_image_copy_no_overlap(output, DstFormat, stride, rect->left, + rect->top, w, h, dst, DstFormat, stride, + rect->left, rect->top, NULL, 0)) + success = -42; + } + copytime += measure_diff_and_print(cname, frameId, start); + } + region16_clear(&invalid); + } + free_cmd(&cmd); + (void)fclose(fp); + } + +fail: + freerdp_client_codecs_free(codecs); + free(output); + free(dst); + + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_UNCOMPRESSED), + UNCOMPRESSED_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_CAPROGRESSIVE), + CAPROGRESSIVE_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_CAVIDEO), CAVIDEO_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_CLEARCODEC), CLEARCODEC_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_PLANAR), PLANAR_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_AVC420), AVC420_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_AVC444), AVC444_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_AVC444v2), AVC444v2_dectime); + print_codec_stats(rdpgfx_get_codec_id_string(RDPGFX_CODECID_ALPHA), ALPHA_dectime); + + const UINT64 decodetime = UNCOMPRESSED_dectime + CAPROGRESSIVE_dectime + CAVIDEO_dectime + + CLEARCODEC_dectime + PLANAR_dectime + AVC420_dectime + + AVC444_dectime + AVC444v2_dectime + ALPHA_dectime; + print_codec_stats("surface copy", copytime); + print_codec_stats("total decode", decodetime); + print_codec_stats("total", decodetime + copytime); + + return success; +} + +int TestFreeRDPCodecProgressive(int argc, char* argv[]) +{ + if (argc > 1) + return test_dump(argc, argv); + + int rc = -1; + char* ms_sample_path = NULL; + char name[8192]; + SYSTEMTIME systemTime; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + GetSystemTime(&systemTime); + (void)sprintf_s(name, sizeof(name), + "EGFX_PROGRESSIVE_MS_SAMPLE-%04" PRIu16 "%02" PRIu16 "%02" PRIu16 "%02" PRIu16 + "%02" PRIu16 "%02" PRIu16 "%04" PRIu16, + systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, + systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds); + ms_sample_path = _strdup(CMAKE_CURRENT_SOURCE_DIR); + + if (!ms_sample_path) + { + printf("Memory allocation failed\n"); + goto fail; + } + + if (winpr_PathFileExists(ms_sample_path)) + { + /* + if (test_progressive_ms_sample(ms_sample_path) < 0) + goto fail; + */ + if (!test_encode_decode(ms_sample_path)) + goto fail; + rc = 0; + } + +fail: + free(ms_sample_path); + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecRemoteFX.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecRemoteFX.c new file mode 100644 index 0000000000000000000000000000000000000000..61226486e17c6f56104f16b20ab47f112f8c0b95 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecRemoteFX.c @@ -0,0 +1,894 @@ +#include +#include + +#include +#include + +static BYTE encodeHeaderSample[] = { + /* as in 4.2.2 */ + 0xc0, 0xcc, 0x0c, 0x00, 0x00, 0x00, 0xca, 0xac, 0xcc, 0xca, 0x00, 0x01, 0xc3, 0xcc, 0x0d, 0x00, + 0x00, 0x00, 0x01, 0xff, 0x00, 0x40, 0x00, 0x28, 0xa8, 0xc1, 0xcc, 0x0a, 0x00, 0x00, 0x00, 0x01, + 0x01, 0x00, 0x01, 0xc2, 0xcc, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x40, 0x00, 0x40, 0x00 +}; + +static BYTE encodeDataSample[] = { + /* FRAME_BEGIN as in 4.2.3 */ + 0xc4, 0xcc, 0x0e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + + /* REGION as in 4.2.3 */ + 0xc6, 0xcc, 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, 0xcd, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x40, 0x00, 0xc1, 0xca, 0x01, 0x00, + + /* TILESET as in 4.2.4.1 */ + 0xc7, 0xcc, 0x3e, 0x0b, 0x00, 0x00, 0x01, 0x00, 0xc2, 0xca, 0x00, 0x00, 0x51, 0x50, 0x01, 0x40, + 0x01, 0x00, 0x23, 0x0b, 0x00, 0x00, 0x66, 0x66, 0x77, 0x88, 0x98, 0xc3, 0xca, 0x23, 0x0b, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xae, 0x03, 0xcf, 0x03, 0x93, 0x03, 0xc0, 0x01, + 0x01, 0x15, 0x48, 0x99, 0xc7, 0x41, 0xa1, 0x12, 0x68, 0x11, 0xdc, 0x22, 0x29, 0x74, 0xef, 0xfd, + 0x20, 0x92, 0xe0, 0x4e, 0xa8, 0x69, 0x3b, 0xfd, 0x41, 0x83, 0xbf, 0x28, 0x53, 0x0c, 0x1f, 0xe2, + 0x54, 0x0c, 0x77, 0x7c, 0xa3, 0x05, 0x7c, 0x30, 0xd0, 0x9c, 0xe8, 0x09, 0x39, 0x1a, 0x5d, 0xff, + 0xe2, 0x01, 0x22, 0x13, 0x80, 0x90, 0x87, 0xd2, 0x9f, 0xfd, 0xfd, 0x50, 0x09, 0x0d, 0x24, 0xa0, + 0x8f, 0xab, 0xfe, 0x3c, 0x04, 0x84, 0xc6, 0x9c, 0xde, 0xf8, 0x80, 0xc3, 0x22, 0x50, 0xaf, 0x4c, + 0x2a, 0x7f, 0xfe, 0xe0, 0x5c, 0xa9, 0x52, 0x8a, 0x06, 0x7d, 0x3d, 0x09, 0x03, 0x65, 0xa3, 0xaf, + 0xd2, 0x61, 0x1f, 0x72, 0x04, 0x50, 0x8d, 0x3e, 0x16, 0x4a, 0x3f, 0xff, 0xfd, 0x41, 0x42, 0x87, + 0x24, 0x37, 0x06, 0x17, 0x2e, 0x56, 0x05, 0x9c, 0x1c, 0xb3, 0x84, 0x6a, 0xff, 0xfb, 0x43, 0x8b, + 0xa3, 0x7a, 0x32, 0x43, 0x28, 0xe1, 0x1f, 0x50, 0x54, 0xfc, 0xca, 0xa5, 0xdf, 0xff, 0x08, 0x04, + 0x48, 0x15, 0x61, 0xd9, 0x76, 0x43, 0xf8, 0x2a, 0x07, 0xe9, 0x65, 0xf7, 0xc6, 0x89, 0x2d, 0x40, + 0xa1, 0xc3, 0x35, 0x8d, 0xf5, 0xed, 0xf5, 0x91, 0xae, 0x2f, 0xcc, 0x01, 0xce, 0x03, 0x48, 0xc0, + 0x8d, 0x63, 0xf4, 0xfd, 0x50, 0x20, 0x2d, 0x0c, 0x9b, 0xb0, 0x8d, 0x13, 0xc0, 0x8a, 0x09, 0x52, + 0x1b, 0x02, 0x6e, 0x42, 0x3b, 0xd0, 0x13, 0x4e, 0x84, 0x01, 0x26, 0x88, 0x6a, 0x04, 0x84, 0x34, + 0x2a, 0xa5, 0x00, 0xba, 0x54, 0x48, 0x58, 0xea, 0x54, 0x02, 0xb4, 0x1d, 0xa7, 0xfa, 0x47, 0x82, + 0xec, 0x7a, 0x77, 0xfd, 0x00, 0x92, 0x66, 0x62, 0x04, 0xa6, 0x9b, 0xff, 0xf6, 0x80, 0xc0, 0x69, + 0x01, 0xc2, 0x3e, 0x90, 0x14, 0x20, 0x2f, 0xfc, 0x40, 0x96, 0x59, 0x58, 0x0c, 0xb1, 0x13, 0x68, + 0x20, 0x2e, 0xb5, 0xf5, 0xdf, 0xff, 0xf8, 0xfc, 0x56, 0x88, 0x60, 0x24, 0x53, 0xb5, 0x41, 0x46, + 0x5f, 0xf8, 0xf1, 0x7e, 0xde, 0x4a, 0x08, 0x97, 0xe0, 0x55, 0x03, 0x8f, 0xe5, 0x75, 0x61, 0x03, + 0xf2, 0xe1, 0x90, 0x01, 0xa2, 0x8e, 0x88, 0x04, 0x98, 0x05, 0x93, 0x6b, 0xff, 0xea, 0xc0, 0x60, + 0xa1, 0x88, 0x04, 0x49, 0xbf, 0xf7, 0xff, 0x8c, 0xb4, 0x59, 0x90, 0x80, 0x30, 0x64, 0x53, 0xff, + 0xf5, 0xc4, 0x48, 0xda, 0xda, 0xcb, 0x80, 0x38, 0x61, 0x57, 0xb2, 0xaf, 0x00, 0xe8, 0x7b, 0x46, + 0xe6, 0xd8, 0x02, 0x03, 0x8a, 0x06, 0x18, 0x14, 0x32, 0x83, 0xd0, 0x8a, 0xee, 0xbc, 0x81, 0xb4, + 0x28, 0xc4, 0x7f, 0xf9, 0xa1, 0x69, 0x00, 0x91, 0xc5, 0x51, 0xff, 0xfe, 0x3f, 0xe9, 0xf1, 0x70, + 0x30, 0x24, 0x10, 0xa7, 0xcb, 0x1f, 0x8a, 0x24, 0x93, 0xed, 0x83, 0x00, 0x36, 0x20, 0xd1, 0x50, + 0xe7, 0xd8, 0xad, 0x58, 0x20, 0x09, 0x22, 0x80, 0xd0, 0xca, 0x5d, 0x1a, 0xd7, 0xf1, 0x60, 0x75, + 0x2a, 0xf2, 0xd7, 0xf8, 0xc0, 0x32, 0x45, 0x86, 0x00, 0x43, 0x01, 0xfe, 0x80, 0xf7, 0x42, 0x81, + 0x74, 0x84, 0x4c, 0xa1, 0x60, 0x4c, 0xcb, 0x14, 0x58, 0x01, 0x4d, 0x18, 0xa1, 0xaa, 0x47, 0x0e, + 0x11, 0x1a, 0x40, 0x7d, 0x41, 0x02, 0xe3, 0x30, 0xcd, 0x33, 0x81, 0x34, 0x06, 0x46, 0x83, 0xa2, + 0x47, 0x1c, 0x04, 0xaa, 0x20, 0x12, 0xa2, 0x8b, 0x81, 0xc4, 0x9c, 0xa0, 0x2e, 0x06, 0x32, 0xf8, + 0x86, 0x85, 0x01, 0xe8, 0x70, 0xf9, 0x46, 0x09, 0x6a, 0xbf, 0xe0, 0xf5, 0xa4, 0xc8, 0x78, 0xe7, + 0xd2, 0x97, 0x0b, 0xbc, 0x3c, 0x97, 0xff, 0xd5, 0x40, 0x94, 0xb2, 0xc1, 0x18, 0x18, 0x11, 0x1f, + 0x43, 0xc1, 0x18, 0xc3, 0x83, 0x7f, 0x9a, 0x31, 0xc4, 0x8e, 0x70, 0x56, 0xda, 0xf6, 0x17, 0xde, + 0xd1, 0x02, 0x0d, 0x42, 0x21, 0x13, 0xdc, 0x3a, 0x3c, 0x40, 0x9e, 0xf4, 0x01, 0x43, 0xea, 0x0c, + 0x46, 0x73, 0xa2, 0x7b, 0x0c, 0x80, 0xff, 0xe4, 0xad, 0x2e, 0x09, 0xb4, 0x63, 0xb0, 0x8c, 0x54, + 0x59, 0xfa, 0xac, 0x76, 0x36, 0x10, 0x05, 0xf0, 0x98, 0x88, 0x83, 0x42, 0x00, 0x20, 0x71, 0xcc, + 0xc1, 0xa9, 0x97, 0x3e, 0x5a, 0x0d, 0x04, 0x50, 0x92, 0x23, 0x20, 0x0d, 0x0a, 0x1c, 0x57, 0xd7, + 0xff, 0x10, 0xf2, 0x03, 0x0f, 0x58, 0x1b, 0xa5, 0x11, 0xf8, 0xf1, 0xb4, 0x12, 0xdb, 0x1a, 0x48, + 0x56, 0x1f, 0xe3, 0xc7, 0x50, 0xe9, 0x16, 0xb4, 0xbc, 0xb0, 0x40, 0x93, 0xea, 0xb5, 0x5b, 0x2f, + 0xfc, 0x50, 0x0a, 0x6f, 0xcc, 0x25, 0xe0, 0x06, 0xab, 0x5f, 0x24, 0xfe, 0x8b, 0xcb, 0x42, 0x43, + 0x7e, 0x69, 0x02, 0x25, 0xc7, 0x38, 0x00, 0x6e, 0xe5, 0x80, 0xa8, 0xa4, 0x30, 0x44, 0x15, 0x8f, + 0xe9, 0x0c, 0xd3, 0xa6, 0xc2, 0x14, 0x34, 0x4a, 0xfe, 0x03, 0x7f, 0x06, 0xa5, 0x91, 0x02, 0x54, + 0xf1, 0xa1, 0xa1, 0x53, 0xbf, 0x11, 0xf2, 0x8f, 0x83, 0x67, 0x80, 0x09, 0x08, 0x12, 0x3f, 0xfd, + 0x44, 0x91, 0xc2, 0x83, 0x30, 0x50, 0x07, 0x02, 0x82, 0x4d, 0x31, 0x34, 0x06, 0x41, 0x79, 0x6f, + 0xf0, 0xcc, 0x03, 0x79, 0x00, 0x2c, 0x05, 0x24, 0xec, 0x8d, 0x29, 0x15, 0xaf, 0x44, 0xc8, 0xeb, + 0x4f, 0xe1, 0xfd, 0xf1, 0x41, 0x48, 0x81, 0x08, 0xaf, 0xfe, 0x51, 0x48, 0xce, 0xe7, 0xf9, 0xb6, + 0x0a, 0x30, 0x83, 0x11, 0xf0, 0x0c, 0x3b, 0xd2, 0xa6, 0x24, 0x24, 0xef, 0x25, 0xfa, 0x5a, 0x3e, + 0x92, 0x3e, 0x79, 0x0e, 0x35, 0x61, 0xc8, 0xaa, 0x1c, 0x2e, 0x9a, 0x27, 0x7f, 0xff, 0xf0, 0x7d, + 0x30, 0x5b, 0xbc, 0x91, 0xff, 0xfe, 0x43, 0x24, 0x28, 0x66, 0xa7, 0x70, 0x99, 0x28, 0x6e, 0x2b, + 0x18, 0x2b, 0xd4, 0xa1, 0x77, 0x3b, 0x96, 0x9f, 0xf7, 0xeb, 0xbe, 0x1f, 0x04, 0x34, 0x75, 0x84, + 0x31, 0x42, 0x4c, 0x65, 0xaa, 0x09, 0x50, 0xa0, 0xc4, 0x51, 0x31, 0xd3, 0x26, 0x3a, 0x1b, 0xf4, + 0x6e, 0x4a, 0x4e, 0x17, 0x25, 0x84, 0x78, 0x7d, 0x2c, 0x3f, 0x46, 0x18, 0xca, 0x5f, 0xf9, 0xe5, + 0x38, 0x2f, 0xd8, 0x71, 0x94, 0x94, 0xe2, 0xcc, 0xa3, 0x15, 0xb0, 0xda, 0xa9, 0xcb, 0x58, 0xe4, + 0x18, 0x77, 0x93, 0x8a, 0x51, 0xc6, 0x23, 0xc4, 0x4e, 0x6d, 0xd9, 0x14, 0x1e, 0x9b, 0x8d, 0xbc, + 0xcb, 0x9d, 0xc4, 0x18, 0x05, 0xf5, 0xa9, 0x29, 0xf8, 0x6d, 0x29, 0x38, 0xc7, 0x44, 0xe5, 0x3a, + 0xcd, 0xba, 0x61, 0x98, 0x4a, 0x57, 0x02, 0x96, 0x42, 0x02, 0xd9, 0x37, 0x11, 0xde, 0x2d, 0xd4, + 0x3f, 0xfe, 0x61, 0xe7, 0x33, 0xd7, 0x89, 0x4a, 0xdd, 0xb0, 0x34, 0x47, 0xf4, 0xdc, 0xad, 0xaa, + 0xc9, 0x9d, 0x7e, 0x6d, 0x4b, 0xcc, 0xdc, 0x17, 0x89, 0x57, 0xfd, 0xbb, 0x37, 0x75, 0x47, 0x5a, + 0xec, 0x2c, 0x6e, 0x3c, 0x15, 0x92, 0x54, 0x64, 0x2c, 0xab, 0x9e, 0xab, 0x2b, 0xdd, 0x3c, 0x66, + 0xa0, 0x8f, 0x47, 0x5e, 0x93, 0x1a, 0x37, 0x16, 0xf4, 0x89, 0x23, 0x00, 0x00, 0xb0, 0x33, 0x56, + 0xfa, 0x14, 0x1e, 0xff, 0x48, 0x7a, 0x7e, 0x0f, 0x10, 0x1f, 0xf4, 0x91, 0xc8, 0x10, 0x56, 0x84, + 0xff, 0x08, 0xec, 0xb4, 0xac, 0x0e, 0x0f, 0xff, 0xad, 0xc5, 0xe0, 0x1a, 0x2f, 0x82, 0x04, 0x9f, + 0x91, 0xc2, 0x0e, 0xfe, 0x48, 0x36, 0x79, 0x01, 0x42, 0x14, 0xff, 0xfe, 0x30, 0xf0, 0x08, 0x18, + 0xf1, 0x81, 0x45, 0x9a, 0x60, 0xc1, 0x79, 0xf0, 0x14, 0x12, 0x10, 0xce, 0xea, 0x31, 0x5a, 0xff, + 0xfc, 0x20, 0x13, 0x82, 0x2f, 0xc9, 0x02, 0x1f, 0x81, 0xcb, 0x00, 0xe1, 0x10, 0xd2, 0xb4, 0xbe, + 0x87, 0xff, 0xb0, 0x1e, 0x27, 0x81, 0xb7, 0x04, 0x06, 0x3c, 0xc2, 0x04, 0xf6, 0x06, 0x0e, 0x28, + 0xbc, 0x40, 0xbf, 0x12, 0x1e, 0x86, 0xd4, 0x6a, 0x7f, 0x18, 0x1b, 0x96, 0x85, 0x4c, 0x16, 0x80, + 0xdf, 0x2c, 0xa5, 0x8d, 0x86, 0xa3, 0x4a, 0x8a, 0xb4, 0x1b, 0xa1, 0x38, 0xa9, 0xd5, 0xff, 0xff, + 0xea, 0x06, 0x20, 0xd2, 0x95, 0x1e, 0xf4, 0x2f, 0xb2, 0x12, 0x0e, 0x61, 0x78, 0x4a, 0x17, 0x52, + 0x5d, 0xe4, 0x25, 0x1f, 0xfe, 0xc0, 0xb3, 0x1f, 0xff, 0xff, 0xec, 0x02, 0x82, 0x80, 0x90, 0x41, + 0x88, 0xde, 0x48, 0x2c, 0x42, 0x52, 0x0b, 0x2f, 0x43, 0x7e, 0x50, 0x78, 0xf2, 0x67, 0x78, 0x41, + 0x34, 0x3d, 0xc8, 0x0f, 0x67, 0xa1, 0xeb, 0x21, 0xfe, 0xc0, 0x1f, 0x22, 0x60, 0x41, 0x6c, 0x00, + 0x92, 0x4b, 0x60, 0x10, 0xd0, 0x0d, 0x01, 0x35, 0x05, 0x0e, 0x87, 0xa2, 0xa0, 0x5d, 0x1f, 0xa3, + 0xaf, 0x7f, 0xf1, 0xbe, 0x8f, 0xcd, 0xa5, 0x00, 0x1c, 0x10, 0x40, 0x15, 0x76, 0x81, 0x05, 0xef, + 0xee, 0x00, 0x60, 0x84, 0x00, 0x99, 0x40, 0x4a, 0x82, 0x17, 0xe9, 0xfc, 0xc4, 0x7f, 0xff, 0xfd, + 0x04, 0x80, 0x06, 0x06, 0xdc, 0xaf, 0xa7, 0x7e, 0x94, 0x75, 0x74, 0x01, 0x00, 0xe0, 0x91, 0x00, + 0x85, 0x7f, 0x8e, 0xd6, 0x0b, 0x20, 0x21, 0x30, 0xca, 0x62, 0x8e, 0x07, 0x04, 0xe9, 0x45, 0x40, + 0x5f, 0x47, 0x4a, 0x30, 0x15, 0x41, 0xcb, 0xdf, 0xff, 0xfc, 0xbf, 0xc3, 0xb4, 0x46, 0x6a, 0x01, + 0x40, 0xd0, 0xa7, 0x34, 0x18, 0x24, 0x1c, 0x2a, 0x45, 0xfe, 0xa8, 0x05, 0x08, 0x61, 0xfd, 0xa8, + 0x80, 0x71, 0x01, 0x25, 0x9c, 0xc1, 0x47, 0x17, 0x37, 0x02, 0x7a, 0x15, 0xff, 0xf3, 0x01, 0x45, + 0x7f, 0xd6, 0x80, 0x60, 0x83, 0x67, 0xf8, 0x9d, 0x2f, 0xf4, 0xdd, 0x8c, 0x30, 0x01, 0x51, 0x42, + 0xbc, 0x43, 0x7a, 0x6b, 0x9f, 0x84, 0x1e, 0x00, 0x48, 0xc1, 0xe0, 0xb7, 0xe0, 0x7e, 0x99, 0xf2, + 0x4a, 0xe9, 0x40, 0x02, 0x81, 0xc3, 0x00, 0x24, 0x3a, 0xc5, 0x52, 0x0f, 0x91, 0xc8, 0x68, 0x25, + 0x40, 0x99, 0xa4, 0x25, 0x1a, 0x04, 0xd0, 0xa2, 0x91, 0xdd, 0xeb, 0x93, 0x00, 0x21, 0x49, 0x24, + 0x8b, 0x40, 0x75, 0x38, 0x14, 0xa1, 0xfd, 0x3f, 0x88, 0x25, 0xbf, 0x32, 0x00, 0xe3, 0x19, 0xfc, + 0xb9, 0xf8, 0x6f, 0x81, 0xc0, 0x01, 0xb3, 0x93, 0x20, 0x09, 0x08, 0x25, 0x84, 0xe1, 0x34, 0xd4, + 0x1b, 0x48, 0x88, 0x11, 0xa0, 0x15, 0x59, 0xd7, 0x07, 0x81, 0x81, 0x3b, 0xa1, 0x40, 0x2e, 0x2f, + 0x48, 0x70, 0x09, 0xc4, 0x76, 0x49, 0x0f, 0x2e, 0x50, 0x2e, 0x46, 0x19, 0xa4, 0x16, 0xa2, 0x1b, + 0x84, 0xa2, 0x89, 0x58, 0xfc, 0x4f, 0x3f, 0x40, 0x90, 0x4c, 0xa3, 0x01, 0x32, 0x09, 0x02, 0x80, + 0x9c, 0x91, 0x13, 0x2c, 0xba, 0xde, 0x5d, 0x99, 0xf2, 0xff, 0xff, 0x3d, 0x5a, 0x1f, 0xa9, 0x02, + 0x90, 0x8f, 0xf3, 0x08, 0xbd, 0x01, 0xf8, 0xd0, 0x2a, 0x95, 0x41, 0x0c, 0x40, 0x0a, 0x20, 0xc4, + 0xd4, 0xcc, 0x6b, 0x0f, 0xf0, 0x80, 0xb1, 0x5d, 0x28, 0x3d, 0x08, 0xc2, 0xf8, 0x31, 0x02, 0x49, + 0x88, 0x14, 0x28, 0xed, 0xe8, 0x86, 0x3b, 0x00, 0x9f, 0x95, 0x06, 0x37, 0x15, 0xa4, 0x59, 0xc8, + 0x80, 0xb6, 0x10, 0xf0, 0xe5, 0xb8, 0x18, 0x00, 0x56, 0x1c, 0xff, 0x95, 0x21, 0x0e, 0x7f, 0x2b, + 0xc5, 0x08, 0x59, 0x10, 0xe1, 0x46, 0x31, 0x8d, 0xec, 0xe0, 0xa1, 0x99, 0xbb, 0x21, 0xff, 0xfe, + 0x30, 0x10, 0xd0, 0x05, 0xe3, 0x08, 0x50, 0xfc, 0xf3, 0x0e, 0x00, 0x8d, 0x68, 0x8e, 0x07, 0xa6, + 0x80, 0x34, 0x42, 0xed, 0x1f, 0x88, 0x00, 0xf0, 0x8a, 0x21, 0xae, 0xf7, 0xfb, 0x80, 0x28, 0x86, + 0x0f, 0xff, 0xff, 0x82, 0xea, 0x47, 0x95, 0x91, 0xe0, 0x04, 0x01, 0x44, 0x0c, 0x29, 0xff, 0x0e, + 0x33, 0xe8, 0xc0, 0x54, 0x04, 0x23, 0xfc, 0x81, 0x5b, 0xf0, 0x3c, 0x07, 0x10, 0x70, 0x30, 0xd8, + 0x21, 0x6f, 0xef, 0xde, 0x46, 0x09, 0x43, 0xfa, 0x5f, 0xff, 0x0d, 0x72, 0x30, 0xdd, 0x00, 0xdb, + 0xe4, 0x48, 0x24, 0x97, 0x08, 0x46, 0xb1, 0x49, 0xc4, 0x4d, 0x80, 0x12, 0x60, 0xff, 0xa4, 0xa6, + 0xff, 0xf6, 0x8c, 0x00, 0x40, 0x05, 0x02, 0xb4, 0x0f, 0xf0, 0x3e, 0xfc, 0x84, 0x38, 0x81, 0x94, + 0x8b, 0xfe, 0x49, 0xef, 0xc0, 0x10, 0x49, 0x88, 0x28, 0xa2, 0x1c, 0x2a, 0x8b, 0x64, 0xd4, 0x86, + 0xd7, 0xff, 0xff, 0xff, 0xeb, 0x91, 0x6b, 0x11, 0x10, 0x00, 0x69, 0x4c, 0xbf, 0xb4, 0x1c, 0xd8, + 0x00, 0x07, 0x16, 0x80, 0x60, 0x0a, 0x1c, 0x82, 0x42, 0x27, 0x82, 0x43, 0xc9, 0x0a, 0x64, 0x20, + 0x5a, 0x5f, 0x4e, 0xbf, 0x8c, 0x38, 0x82, 0x36, 0x02, 0x07, 0x72, 0x79, 0x07, 0x23, 0xb4, 0xbb, + 0x57, 0x5f, 0xe8, 0x04, 0xdd, 0x39, 0xe9, 0x07, 0x95, 0xbe, 0x04, 0x2b, 0xdd, 0x8e, 0x22, 0xdc, + 0x14, 0x2c, 0x61, 0xa3, 0xa9, 0xcd, 0x4f, 0x82, 0x5d, 0xa0, 0x44, 0xdf, 0xf4, 0x96, 0xff, 0xf5, + 0x2b, 0xff, 0xfe, 0x01, 0x19, 0xd2, 0xa2, 0x9e, 0x43, 0xa5, 0x7f, 0xf0, 0x4c, 0x4c, 0x2b, 0x3c, + 0x33, 0xe2, 0x55, 0xff, 0x04, 0x06, 0x29, 0x2c, 0x0d, 0x22, 0x5d, 0x7c, 0x93, 0xba, 0x18, 0xaf, + 0xf9, 0x32, 0xa6, 0xc3, 0x99, 0x46, 0x79, 0xe3, 0x06, 0xa6, 0x38, 0x8b, 0x92, 0x22, 0x4b, 0xdb, + 0x1b, 0x36, 0x20, 0xb0, 0x6c, 0x20, 0xce, 0x37, 0x42, 0xe1, 0x66, 0xd4, 0x49, 0x34, 0x42, 0x8b, + 0xfa, 0x9c, 0x12, 0x99, 0xdc, 0x06, 0x87, 0xfa, 0x46, 0xf8, 0x2f, 0x04, 0xa9, 0xd8, 0x82, 0x07, + 0xa6, 0x30, 0x0f, 0xc0, 0xdf, 0x35, 0xe8, 0x90, 0xf0, 0xff, 0xff, 0xa8, 0xe0, 0xd7, 0x02, 0x60, + 0x1a, 0xc3, 0x20, 0x28, 0xa2, 0x31, 0x29, 0x3c, 0xeb, 0x04, 0xa5, 0xdd, 0x48, 0x0e, 0x82, 0xa4, + 0xb6, 0x56, 0x22, 0x06, 0x57, 0xe0, 0xda, 0x10, 0x27, 0x31, 0x0e, 0x11, 0x77, 0xfe, 0x02, 0x60, + 0x16, 0x48, 0x81, 0x8c, 0x0d, 0x05, 0x17, 0x7f, 0xcb, 0xbb, 0x7e, 0x25, 0x2a, 0x41, 0xfd, 0x8a, + 0x7f, 0xc9, 0x36, 0x7c, 0xe0, 0x98, 0x7e, 0x92, 0xef, 0x7e, 0x06, 0x03, 0x13, 0x3e, 0x20, 0x3a, + 0xbf, 0x4c, 0xc3, 0x0f, 0x2e, 0x80, 0x74, 0xbf, 0x39, 0x3c, 0xf0, 0xa6, 0xb2, 0xe9, 0x3f, 0x41, + 0x55, 0x1f, 0x2c, 0xf5, 0xd2, 0x7e, 0x8c, 0xae, 0x4e, 0xaa, 0x61, 0x3c, 0xbc, 0x3f, 0xc4, 0xc7, + 0x36, 0xdc, 0x23, 0xc8, 0xb8, 0x52, 0xe2, 0x8a, 0x80, 0x18, 0x00, 0x00, 0xb2, 0x46, 0xa2, 0x56, + 0x0d, 0x12, 0x94, 0xaa, 0xbd, 0x01, 0x07, 0xff, 0xfa, 0x34, 0x0c, 0x5f, 0xf8, 0x0c, 0x12, 0x50, + 0xaf, 0xd6, 0xd1, 0x89, 0x40, 0xa4, 0xff, 0xe0, 0xce, 0xc4, 0x49, 0x25, 0x9d, 0xc1, 0xff, 0x7e, + 0x60, 0x24, 0x5d, 0xcc, 0x10, 0xc0, 0xbe, 0x5a, 0x12, 0xd3, 0xc3, 0xfe, 0x2d, 0x40, 0x7c, 0x28, + 0x9e, 0x71, 0x01, 0xd2, 0x6e, 0x86, 0x0b, 0xc8, 0xf2, 0x9b, 0x45, 0x08, 0x4c, 0x04, 0x52, 0x7e, + 0xf2, 0x7e, 0xd9, 0xcc, 0x0b, 0x1c, 0x20, 0x80, 0xae, 0xaf, 0xfe, 0xb0, 0x6d, 0x23, 0xf2, 0x41, + 0xe3, 0x2e, 0x20, 0x11, 0x4b, 0x74, 0x89, 0xdd, 0xff, 0xa8, 0x38, 0xa3, 0x95, 0x82, 0x15, 0xf0, + 0xd0, 0xd5, 0xf1, 0x92, 0x8e, 0xee, 0xc0, 0x26, 0x81, 0xe9, 0x47, 0xff, 0xee, 0x0d, 0x20, 0x34, + 0x31, 0x3a, 0xef, 0x40, 0xb2, 0x29, 0x47, 0x19, 0x7f, 0x04, 0x27, 0xf1, 0x90, 0x85, 0x09, 0x86, + 0x7d, 0x42, 0xe2, 0x54, 0x5d, 0x5f, 0xe8, 0x0e, 0xd0, 0x2c, 0xaa, 0x16, 0xbf, 0x04, 0xa7, 0xf8, + 0xa2, 0x46, 0x0b, 0x08, 0x7a, 0x79, 0xe9, 0x28, 0x62, 0x7c, 0x33, 0xf4, 0x0b, 0x14, 0x82, 0xfa, + 0x61, 0xeb, 0xc1, 0xff, 0x4c, 0xa4, 0x11, 0x7f, 0x03, 0x68, 0x44, 0xc1, 0x1f, 0x81, 0x3a, 0x6c, + 0x77, 0x95, 0x02, 0x2b, 0x53, 0x80, 0xe5, 0x10, 0x1e, 0x90, 0xe8, 0xfd, 0x1f, 0xa6, 0x40, 0x0b, + 0x13, 0xff, 0x4e, 0x4d, 0x7f, 0x52, 0xe8, 0xaf, 0x9a, 0xc1, 0x80, 0x0f, 0x0a, 0x14, 0x02, 0x3c, + 0xc0, 0x09, 0x13, 0xe7, 0xdc, 0xc0, 0x1a, 0x28, 0xa0, 0xe4, 0x83, 0x8e, 0x03, 0x88, 0xd5, 0xaf, + 0x1a, 0xbd, 0x91, 0x00, 0xb7, 0x4e, 0xba, 0xdf, 0xf8, 0xdb, 0xcc, 0x02, 0x43, 0xc4, 0x14, 0x2a, + 0x3f, 0xc8, 0x0d, 0x09, 0x1c, 0x44, 0xf4, 0x01, 0x3c, 0xca, 0x28, 0x56, 0x80, 0xa6, 0x85, 0x00, + 0xea, 0x3e, 0x8f, 0xeb, 0x9f, 0xfc, 0x6e, 0x07, 0xc4, 0xe0, 0x30, 0x78, 0xa0, 0x1e, 0x6f, 0x54, + 0x78, 0x51, 0xff, 0x56, 0x4a, 0x01, 0x47, 0x02, 0x4c, 0x21, 0x3b, 0xfb, 0x90, 0x0a, 0xcc, 0x1d, + 0xd2, 0x47, 0xff, 0xfc, 0x70, 0x18, 0x22, 0xc0, 0xb9, 0x2f, 0xe9, 0x7f, 0x91, 0xd3, 0x66, 0x2f, + 0x80, 0x2c, 0x24, 0xa7, 0xfa, 0x84, 0x51, 0xab, 0x6b, 0x72, 0x00, 0xab, 0x33, 0x04, 0xcf, 0x43, + 0xff, 0x17, 0x51, 0x84, 0x0c, 0x01, 0x50, 0x10, 0x8f, 0x90, 0x34, 0x41, 0x44, 0x84, 0x8e, 0x08, + 0x19, 0x04, 0x48, 0x50, 0x84, 0x38, 0x3d, 0x02, 0x52, 0xf9, 0x7c, 0xd2, 0xd0, 0x1f, 0x13, 0x42, + 0xa0, 0x21, 0x41, 0xc4, 0x02, 0x02, 0x3d, 0x09, 0xc8, 0xfd, 0x60, 0x7d, 0x35, 0x4f, 0x7f, 0xff, + 0xf9, 0x97, 0x6a, 0xd8, 0x00, 0xc3, 0x83, 0x00, 0x09, 0x50, 0x4b, 0x90, 0x8a, 0xc7, 0x94, 0x4d, + 0x47, 0xc1, 0x62, 0x32, 0x28, 0x24, 0x09, 0x52, 0x2e, 0x2e, 0x1c, 0x96, 0x44, 0xa0, 0x09, 0xc8, + 0xce, 0x64, 0xa9, 0x1c, 0x19, 0x0e, 0x52, 0x3e, 0x3e, 0x19, 0x93, 0xa0, 0x36, 0x26, 0x22, 0x08, + 0x9a, 0x00, 0xdd, 0x66, 0x3a, 0x93, 0xd5, 0x89, 0xd1, 0x40, 0x06, 0xd4, 0xa8, 0x22, 0x73, 0x7b, + 0x3d, 0x3f, 0xe3, 0x04, 0x94, 0xff, 0xff, 0xff, 0xff, 0x0c, 0x56, 0x77, 0xac, 0xe0, 0xc4, 0x06, + 0x1f, 0xb8, 0xa5, 0x80, 0xfd, 0x68, 0x1c, 0x32, 0x16, 0x03, 0xde, 0x71, 0x2a, 0x3d, 0x14, 0x19, + 0xbe, 0xc2, 0x88, 0xd9, 0x24, 0x92, 0x5f, 0xc5, 0x90, 0x0a, 0x85, 0xc2, 0x3f, 0x87, 0x03, 0xa8, + 0x26, 0x17, 0xc4, 0x06, 0x86, 0x12, 0x87, 0x76, 0x0a, 0x48, 0x16, 0xed, 0x96, 0x93, 0xec, 0x1b, + 0x30, 0x73, 0xe8, 0x1a, 0x3f, 0xff, 0x4d, 0xce, 0x40, 0xf3, 0x0c, 0x51, 0x4b, 0x84, 0x9e, 0x67, + 0x2b, 0x15, 0x40, 0x1a, 0xa0, 0xfc, 0x10, 0x0f, 0xd8, 0x81, 0x35, 0x87, 0xff, 0x98, 0x0f, 0x40, + 0x00, 0xba, 0xc0, 0x71, 0xe2, 0x00, 0x18, 0x28, 0xb3, 0x82, 0xcc, 0x80, 0x6a, 0xa0, 0x43, 0xff, + 0x2d, 0xd6, 0x04, 0x8a, 0x68, 0xff, 0xff, 0xff, 0xfc, 0x1a, 0xf3, 0x1a, 0x2a, 0x06, 0xc0, 0x01, + 0x40, 0x0c, 0x30, 0xc1, 0xd0, 0xd7, 0x4f, 0xcb, 0x74, 0x1f, 0x07, 0xd3, 0xb4, 0x0d, 0x88, 0x98, + 0xea, 0xda, 0x9f, 0xce, 0x2b, 0x3c, 0x55, 0xb3, 0x40, 0x14, 0xff, 0xff, 0xff, 0xea, 0xdb, 0x9b, + 0x92, 0xd8, 0x68, 0x08, 0x0b, 0x41, 0x09, 0x26, 0x40, 0x8c, 0xf1, 0xb0, 0x9a, 0x98, 0xc0, 0x80, + 0x8b, 0xf0, 0x3d, 0xe7, 0xec, 0x19, 0x68, 0x21, 0x03, 0x29, 0x7f, 0xe1, 0x6d, 0x4c, 0x0f, 0x01, + 0xd1, 0x51, 0x01, 0x1a, 0x50, 0x2a, 0x59, 0x27, 0x80, 0xc1, 0x6e, 0x33, 0xf1, 0x80, 0xe1, 0x49, + 0x08, 0xe9, 0x17, 0xff, 0xff, 0xff, 0x80, 0x5a, 0x10, 0x10, 0x36, 0x5e, 0xca, 0xf8, 0x3a, 0x00, + 0x1e, 0xb0, 0x06, 0x84, 0x01, 0xf3, 0x07, 0x1b, 0x4a, 0xc0, 0x1e, 0x21, 0x43, 0x8e, 0xa5, 0x55, + 0x77, 0xc7, 0x65, 0x7c, 0xc2, 0xdf, 0x5e, 0x0c, 0x42, 0x20, 0xd2, 0x48, 0x61, 0xc8, 0x1c, 0x65, + 0xf8, 0xfe, 0x4c, 0x88, 0x71, 0x1f, 0x82, 0x50, 0x81, 0xa3, 0x54, 0x09, 0x13, 0x28, 0x52, 0xf5, + 0xe0, 0x82, 0xc3, 0x06, 0x7f, 0xfa, 0x2c, 0xcf, 0xf8, 0xf4, 0x7f, 0xff, 0xfd, 0x01, 0x49, 0xa4, + 0xb8, 0xde, 0x62, 0x84, 0xfe, 0xed, 0x65, 0x1f, 0x3c, 0x3c, 0xb2, 0x50, 0x76, 0x30, 0x5b, 0x03, + 0xc0, 0x08, 0xa6, 0x64, 0x90, 0xc8, 0xcd, 0x14, 0x6e, 0x69, 0x46, 0x7a, 0xc6, 0x1c, 0x87, 0xd7, + 0x48, 0x7b, 0x49, 0x05, 0x2d, 0x5e, 0x7f, 0xcb, 0x67, 0xf0, 0xd9, 0x0d, 0x1e, 0x9e, 0x53, 0xb7, + 0x64, 0xa5, 0xa5, 0x10, 0x39, 0x06, 0x11, 0x3f, 0xb1, 0xa9, 0xa6, 0xe8, 0x4d, 0x47, 0x77, 0xda, + 0x43, 0x76, 0x89, 0x45, 0x09, 0x70, 0xc2, 0x38, 0x0f, 0x09, 0x6f, 0xe7, 0x2d, 0x82, 0x35, 0x07, + 0xfe, 0x64, 0x18, 0x2e, 0xb8, 0x04, 0x42, 0x54, 0x80, 0x43, 0x12, 0x6c, 0x9a, 0x55, 0xc9, 0x0a, + 0xa0, 0x79, 0x47, 0x52, 0x65, 0x2a, 0xff, 0x50, 0x11, 0xc9, 0x4e, 0xfe, 0x5b, 0x30, 0xa4, 0xe8, + 0x30, 0x63, 0xff, 0x21, 0x12, 0x1b, 0xdc, 0x1c, 0x01, 0x41, 0x51, 0x1f, 0xff, 0xfa, 0xc3, 0xe3, + 0x55, 0xf1, 0x66, 0xe2, 0xd5, 0x78, 0x5e, 0xfa, 0x4d, 0xf2, 0x61, 0x01, 0x26, 0x15, 0xa9, 0xf9, + 0xd9, 0x32, 0x41, 0x90, 0x36, 0x4e, 0xae, 0xe3, 0x0b, 0x16, 0x56, 0x8c, 0x6e, 0x42, 0x5d, 0xd8, + 0x1e, 0xfe, 0x1d, 0x40, 0x3a, 0x50, 0x9f, 0x09, 0x14, 0xeb, 0x6e, 0x48, 0x7a, 0x91, 0x88, 0x7b, + 0x7d, 0x8f, 0x72, 0x42, 0x39, 0xb0, 0x1c, 0x65, 0x18, 0x23, 0x8b, 0x60, 0x30, 0x00, + + /* FRAME_END as in 4.2.3 */ + 0xc5, 0xcc, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00 +}; + +static UINT32 srefImage + [] = { /* 4.2.4.4 Inverse Color Conversion */ + 0x00229cdf, 0x00249de0, 0x00259fe2, 0x002ca5e8, 0x00229cdf, 0x00229ce0, 0x00239de0, + 0x00229ce0, 0x00229cdf, 0x00229cdf, 0x00239ce0, 0x00249ce0, 0x00249ce0, 0x00219ce3, + 0x001e9ce6, 0x00209ae2, 0x002299dd, 0x002199de, 0x00209adf, 0x00209ae0, 0x001f9be0, + 0x001e9ae0, 0x001d99e0, 0x001c98e0, 0x001b97df, 0x001e96dc, 0x002194d9, 0x001f93dd, + 0x001d93e0, 0x001b94dc, 0x001895d8, 0x001c92db, 0x00208fde, 0x001b91de, 0x001693df, + 0x001793df, 0x001992df, 0x001891df, 0x00178fdf, 0x00178edf, 0x00168dde, 0x00158cdd, + 0x00148cdc, 0x00128cda, 0x00118cd9, 0x00118bd9, 0x00128ada, 0x001289da, 0x001288db, + 0x001187da, 0x001186da, 0x001085da, 0x000f85d9, 0x000f84d9, 0x000e83d9, 0x000d82d8, + 0x000d82d8, 0x000d81d8, 0x000d80d7, 0x000d7fd7, 0x000d7ed6, 0x000d7ed6, 0x000d7ed6, + 0x000d7ed6, 0x00259fe1, 0x0027a1e2, 0x0029a2e3, 0x002ba4e6, 0x00249fe1, 0x00249fe1, + 0x00249fe1, 0x00249ee1, 0x00239ee1, 0x00249ee1, 0x00249ee1, 0x00259de1, 0x00259de2, + 0x00249de2, 0x00229de2, 0x00229ce1, 0x00229bdf, 0x00219ce0, 0x00209ce1, 0x00209ce2, + 0x00209ce2, 0x00209ae0, 0x002199de, 0x001f99df, 0x001d98e0, 0x001e97e0, 0x001f97e0, + 0x001d96df, 0x001c95de, 0x001c94e0, 0x001c94e1, 0x001d93e1, 0x001d92e0, 0x001b93de, + 0x001a94dc, 0x001a93de, 0x001a93e0, 0x001992e0, 0x001891df, 0x00188fdf, 0x00178edf, + 0x00168ede, 0x00158edd, 0x00148ddc, 0x00138ddb, 0x00138cdb, 0x00138bdb, 0x00128adb, + 0x001289db, 0x001288db, 0x001187db, 0x001186db, 0x001085db, 0x000f84da, 0x000e83d9, + 0x000e83d9, 0x000e83d9, 0x000e82d9, 0x000e81d8, 0x000e80d8, 0x000d7fd7, 0x000d7fd7, + 0x000d7fd7, 0x000d7fd7, 0x0027a3e3, 0x002aa4e3, 0x002ea6e3, 0x002aa4e3, 0x0026a2e3, + 0x0026a1e3, 0x0025a1e3, 0x0025a0e3, 0x0025a0e3, 0x0025a0e3, 0x00259fe3, 0x00269fe3, + 0x00269ee4, 0x00279ee1, 0x00279edf, 0x00259ee0, 0x00239ee1, 0x00219ee2, 0x00209ee4, + 0x00209de4, 0x00219de3, 0x00229be0, 0x002499dc, 0x002299de, 0x001f98e0, 0x001d99e4, + 0x001b9ae7, 0x001c98e2, 0x001c96dc, 0x001e94e3, 0x002092ea, 0x001d94e6, 0x001a96e2, + 0x001c96de, 0x001d95da, 0x001c94de, 0x001b94e1, 0x001a93e0, 0x001a92e0, 0x001991e0, + 0x001890e0, 0x001790df, 0x00178fde, 0x00168fde, 0x00158edd, 0x00148ddd, 0x00138cdc, + 0x00138bdc, 0x00128adc, 0x001289dc, 0x001188dc, 0x001187dd, 0x001086dd, 0x000f85db, + 0x000e83d9, 0x000e84da, 0x000f84da, 0x000e83da, 0x000e82d9, 0x000e81d9, 0x000e80d8, + 0x000e80d8, 0x000e80d8, 0x000e80d8, 0x002aa7e5, 0x002da7e4, 0x0031a8e3, 0x002ca6e3, + 0x0027a4e4, 0x0027a3e4, 0x0027a3e4, 0x0027a3e4, 0x0026a2e4, 0x0026a2e4, 0x0027a1e5, + 0x0027a0e5, 0x0027a0e6, 0x0026a0e5, 0x0025a0e4, 0x00259fe4, 0x00259ee3, 0x00239ee5, + 0x00229fe6, 0x00229fe5, 0x00229fe4, 0x0013a5e6, 0x001b9fe8, 0x0016a0e8, 0x0011a0e7, + 0x00129fef, 0x00139ef7, 0x001b99ec, 0x00179ae2, 0x00149ce4, 0x001d98e5, 0x001c97e6, + 0x001b96e7, 0x001c98dc, 0x001d97df, 0x001c96e1, 0x001c94e2, 0x001b94e1, 0x001b93e1, + 0x001a93e0, 0x001a92e0, 0x001991e0, 0x001890e0, 0x001790df, 0x00168fdf, 0x00158ede, + 0x00158dde, 0x00148cdd, 0x00138bdc, 0x00128add, 0x001289dd, 0x001188de, 0x001187de, + 0x000f85dc, 0x000d83da, 0x000f85db, 0x001086db, 0x000f84db, 0x000f83da, 0x000e82da, + 0x000e81da, 0x000e81da, 0x000e81da, 0x000e81da, 0x002caae7, 0x0030aae5, 0x0034abe3, + 0x002ea8e4, 0x0029a6e5, 0x0028a6e5, 0x0028a5e5, 0x0028a5e5, 0x0028a5e6, 0x0028a4e6, + 0x0028a3e7, 0x0028a2e7, 0x0028a1e8, 0x0025a2e9, 0x0023a3ea, 0x0025a0e8, 0x00279ee6, + 0x00259fe7, 0x0023a0e9, 0x0018a4f5, 0x000ea7ff, 0x001ba6de, 0x00558ebb, 0x006f839c, + 0x0089797e, 0x008d797c, 0x00917979, 0x007f7b94, 0x005687af, 0x00229bd6, 0x0004a4fd, + 0x00109df4, 0x001c97eb, 0x001c9ada, 0x001c98e4, 0x001c97e3, 0x001d95e2, 0x001c95e2, + 0x001c94e2, 0x001c94e1, 0x001b94e1, 0x001a93e1, 0x001a92e1, 0x001991e1, 0x001890e1, + 0x00178fe0, 0x00158edf, 0x00148dde, 0x00138cdd, 0x00128bde, 0x00128adf, 0x001289df, + 0x001188e0, 0x000f85dd, 0x000d83da, 0x000f85db, 0x001187dd, 0x001086dc, 0x000f84dc, + 0x000e83db, 0x000e81db, 0x000e81db, 0x000e81db, 0x000e81db, 0x0030abe5, 0x0036afe8, + 0x0034abe4, 0x002faae5, 0x002ba8e6, 0x0036aee8, 0x0026a6e8, 0x0029a7e7, 0x002ca8e7, + 0x002da7e6, 0x002fa5e5, 0x002ca5e7, 0x0029a4e9, 0x002ba5e5, 0x002ca5e2, 0x0010aaef, + 0x0013adf6, 0x0023a3f8, 0x006091a5, 0x00a6755d, 0x00ec5915, 0x00ff490c, 0x00fa5504, + 0x00ff590f, 0x00ff5d1b, 0x00ff6116, 0x00fa6412, 0x00ff550f, 0x00ff4b0d, 0x00fb4918, + 0x00f54823, 0x008e737e, 0x00269eda, 0x0006a2ff, 0x001d97e2, 0x001799ea, 0x001c97e4, + 0x001a98e4, 0x001898e4, 0x001a96e3, 0x001b95e3, 0x001a94e2, 0x001a93e0, 0x001992e1, + 0x001891e2, 0x001790e1, 0x00168fe0, 0x00158fdf, 0x00138ede, 0x00138ddf, 0x00138ce0, + 0x00128be0, 0x001189e0, 0x001087de, 0x000f85db, 0x00138ae0, 0x000f87dc, 0x000f86dc, + 0x000f85dc, 0x000f84dc, 0x000e83db, 0x000e83db, 0x000e83db, 0x000e83db, 0x0034abe2, + 0x003cb4ec, 0x0034ace5, 0x0031abe6, 0x002daae8, 0x0044b6eb, 0x0024a7ea, 0x0029aaea, + 0x002face9, 0x0032a9e6, 0x0035a7e3, 0x0030a7e6, 0x002ba8ea, 0x0025aaf0, 0x0020adf6, + 0x004d8ba7, 0x00b8674c, 0x00ff5510, 0x00f7650c, 0x00f86313, 0x00fa611b, 0x00f0671f, + 0x00fc6222, 0x00fb6926, 0x00f96f29, 0x00f67122, 0x00f3721b, 0x00f26b20, 0x00f16424, + 0x00ff5622, 0x00ff531f, 0x00ff4b17, 0x00ff440e, 0x00b1615b, 0x001f95e0, 0x00129bf0, + 0x001c9ae5, 0x00189ae6, 0x00159be7, 0x001898e6, 0x001b95e5, 0x001b95e2, 0x001995e0, + 0x001994e1, 0x001892e2, 0x001792e1, 0x001691e0, 0x001590df, 0x00148fdf, 0x00148fe0, + 0x00148fe1, 0x00128de1, 0x00108be0, 0x001189de, 0x001186dd, 0x00178fe4, 0x000e87db, + 0x000e87dc, 0x000f87dd, 0x000f85dc, 0x000e84dc, 0x000e84dc, 0x000e84dc, 0x000e84dc, + 0x0036b1eb, 0x0036b4f0, 0x002eafed, 0x002caeec, 0x002aadec, 0x0041b4ef, 0x0029abe9, + 0x002cabe8, 0x002fabe7, 0x0031abe6, 0x0032aae6, 0x002faae7, 0x002ca9e8, 0x0025a7eb, + 0x00946a5f, 0x00ff3e06, 0x00f95618, 0x00e27312, 0x00f87329, 0x00f77427, 0x00f77626, + 0x00f27628, 0x00f8712b, 0x00f9772e, 0x00f97e30, 0x00f77f2e, 0x00f5812b, 0x00f57b2c, + 0x00f5752d, 0x00fd6a2b, 0x00fb652a, 0x00f65e2c, 0x00f1572e, 0x00ff4810, 0x00ff460f, + 0x00817680, 0x0002a7f1, 0x002496ea, 0x00199be4, 0x001b98e4, 0x001d96e5, 0x001b96e2, + 0x001a96e0, 0x001995e1, 0x001794e3, 0x001793e2, 0x001692e1, 0x001691e0, 0x001590df, + 0x001591e1, 0x001591e3, 0x00138fe1, 0x00108ce0, 0x00128be0, 0x00158ae0, 0x00168de2, + 0x000f89dd, 0x000f88dd, 0x000f88dd, 0x000f86dd, 0x000f85dc, 0x000f85dc, 0x000f85dc, + 0x000f85dc, 0x005fc1e7, 0x0057bee8, 0x004fbbe9, 0x004ebae6, 0x004ebae3, 0x0051b6ee, + 0x002eaee8, 0x002eade6, 0x002fabe5, 0x002face7, 0x002eade9, 0x002eace7, 0x002daae5, + 0x0015b2ff, 0x00ec4310, 0x00f15016, 0x00f75d1c, 0x00f87123, 0x00f9862a, 0x00f6882d, + 0x00f48b31, 0x00f48532, 0x00f47f33, 0x00f78535, 0x00fa8c37, 0x00f88e39, 0x00f7903a, + 0x00f88b38, 0x00f98635, 0x00f87e35, 0x00f77635, 0x00f76d34, 0x00f76532, 0x00f85e31, + 0x00f95730, 0x00ff5125, 0x00f65237, 0x0003a5fd, 0x001e9be1, 0x001e98e3, 0x001f96e5, + 0x001c97e2, 0x001a97df, 0x001896e1, 0x001795e4, 0x001794e3, 0x001793e2, 0x001692e1, + 0x001692e0, 0x001693e2, 0x001794e4, 0x001391e2, 0x000f8ee0, 0x00148ee1, 0x00198ee3, + 0x00148ce1, 0x000f8bde, 0x000f8ade, 0x000f89de, 0x000f88dd, 0x000f86dd, 0x000f86dd, + 0x000f86dd, 0x000f86dd, 0x003cb6ee, 0x0036b4ef, 0x0030b2f0, 0x0030b1ee, 0x002fb1ec, + 0x0038b0ef, 0x002eaee9, 0x002faee8, 0x0031ade6, 0x002fafe8, 0x002eb1ea, 0x0031adec, + 0x0029afee, 0x0030aac8, 0x00ff3d05, 0x00fa501a, 0x00f96021, 0x00f87428, 0x00f7882f, + 0x00fa9638, 0x00f59b38, 0x00f5973b, 0x00f6923e, 0x00f89440, 0x00fa9742, 0x00fa9a44, + 0x00fa9d46, 0x00f99845, 0x00f89444, 0x00f98d43, 0x00fa8641, 0x00f97d3f, 0x00f9743d, + 0x00f77039, 0x00f56d35, 0x00ff6122, 0x00bf6c63, 0x00129eef, 0x00229ae8, 0x001c99ed, + 0x00179ce4, 0x001498f0, 0x001b94e1, 0x001a96e2, 0x001998e3, 0x001897e4, 0x001896e5, + 0x001895e4, 0x001993e2, 0x001792e1, 0x001590df, 0x001692e2, 0x001793e5, 0x001490e4, + 0x00128ee2, 0x00118de3, 0x00108de3, 0x00118bde, 0x001289d9, 0x000f88e2, 0x000c89dd, + 0x001085e0, 0x000987e4, 0x000987e4, 0x0040b5e9, 0x003bb4e9, 0x0037b2ea, 0x0037b2e9, + 0x0038b1e8, 0x0033b0ea, 0x002eaeeb, 0x0030afe9, 0x0033afe8, 0x0030b2ea, 0x002eb5ec, + 0x0034aff2, 0x0025b4f7, 0x008d7f86, 0x00f64f00, 0x00ed5c1e, 0x00fa6326, 0x00f7762d, + 0x00f58a35, 0x00fea242, 0x00f7ab3f, 0x00f7a843, 0x00f7a548, 0x00f9a34a, 0x00faa24c, + 0x00fba64f, 0x00fcaa52, 0x00f9a652, 0x00f7a252, 0x00fa9c50, 0x00fd974e, 0x00fc8d4b, + 0x00fb8348, 0x00f68341, 0x00f1823a, 0x00f5732c, 0x00718cac, 0x00179af0, 0x002599ef, + 0x002697e9, 0x00269bc6, 0x001696f1, 0x001d91e3, 0x001c96e3, 0x001b9be3, 0x001a99e6, + 0x001998e9, 0x001b97e7, 0x001c95e5, 0x001891df, 0x00138dda, 0x001992e2, 0x001e98ea, + 0x001592e6, 0x000b8de2, 0x000e8ee5, 0x00108fe9, 0x00128cdf, 0x001489d4, 0x000e88e6, + 0x00088cdc, 0x001184e4, 0x000488ec, 0x000488ec, 0x003eb6ea, 0x003bb5eb, 0x0038b4eb, + 0x0038b4eb, 0x0038b3eb, 0x0035b2eb, 0x0033b1ec, 0x0034b1eb, 0x0035b1ea, 0x0032b3e9, + 0x0030b5e9, 0x0034b0f0, 0x0023b6f8, 0x00c56044, 0x00f9540c, 0x00f26322, 0x00f77029, + 0x00f77d2f, 0x00f78b35, 0x00fba142, 0x00f6b046, 0x00fbb44f, 0x00f7b051, 0x00f9af54, + 0x00fbad56, 0x00fcb25a, 0x00feb75d, 0x00fab35f, 0x00f6b061, 0x00faac5d, 0x00fda95a, + 0x00fb9f55, 0x00f99551, 0x00f7914b, 0x00f68d45, 0x00ff7e23, 0x001ba5f0, 0x00129ef4, + 0x002896f1, 0x00239fb1, 0x006c9600, 0x003c9c82, 0x00179ef8, 0x00169cf4, 0x00149de3, + 0x00169ae5, 0x001897e7, 0x001995e6, 0x001a93e5, 0x001993e3, 0x001793e0, 0x001c98e6, + 0x001a95e5, 0x001692e5, 0x00138fe5, 0x00138ceb, 0x00138be3, 0x000087e4, 0x00007cf5, + 0x001a86d3, 0x000d8cf1, 0x00008fe2, 0x000d85ea, 0x000886f1, 0x003cb7ec, 0x003bb7ed, + 0x003ab6ed, 0x0039b6ed, 0x0038b5ed, 0x0037b5ed, 0x0037b4ed, 0x0037b3ed, 0x0036b3ec, + 0x0034b4e9, 0x0031b5e5, 0x0035b1ef, 0x0021b8fa, 0x00fd4203, 0x00fc581e, 0x00f86a26, + 0x00f47c2d, 0x00f78431, 0x00f98c36, 0x00f8a041, 0x00f6b54d, 0x00fec05b, 0x00f6bc5a, + 0x00f8ba5d, 0x00fbb861, 0x00fdbe65, 0x00ffc469, 0x00fbc16c, 0x00f5bd70, 0x00fabc6b, + 0x00febb66, 0x00fab160, 0x00f6a75a, 0x00f89f55, 0x00fa984f, 0x00df956f, 0x0008a6fc, + 0x00259ddb, 0x00159ff3, 0x004aa172, 0x0069a90d, 0x0062a406, 0x005a981b, 0x0034969b, + 0x000e99ff, 0x001297f2, 0x001695e4, 0x001793e5, 0x001892e5, 0x001995e6, 0x001a98e7, + 0x00209deb, 0x001593df, 0x001892e4, 0x001a91e9, 0x002095eb, 0x00259dd1, 0x00d0f772, + 0x00c1f396, 0x000083f1, 0x001782a0, 0x003c7e2f, 0x001787cc, 0x000b8ada, 0x003db9ed, + 0x003cb8ed, 0x003bb8ed, 0x003ab7ed, 0x0039b7ed, 0x0039b7ed, 0x0039b6ed, 0x003ab6ed, + 0x003ab6ed, 0x0037b4ed, 0x0034b2ec, 0x0035abf3, 0x006e96b3, 0x00ff4601, 0x00f86520, + 0x00f67329, 0x00f58131, 0x00f78b37, 0x00f9953e, 0x00f8a649, 0x00f8b854, 0x00fcc260, + 0x00f8c465, 0x00f9c36a, 0x00fac26e, 0x00fac773, 0x00facb77, 0x00fbcb7b, 0x00fccb7e, + 0x00fac87b, 0x00f8c578, 0x00f9bc72, 0x00fbb46d, 0x00f6b069, 0x00feaa57, 0x0094a0a5, + 0x0013a1f3, 0x00219df0, 0x00199eff, 0x0071c124, 0x0079b826, 0x0072b21e, 0x006aaa24, + 0x0067a125, 0x00649a19, 0x00419d72, 0x001f9fcb, 0x001994ff, 0x001399f1, 0x00199cf4, + 0x001ea0f8, 0x001b9cff, 0x001193f6, 0x001293f1, 0x001393ec, 0x000083ff, 0x0072cca0, + 0x00cbf982, 0x00d0ffac, 0x0079a046, 0x00337700, 0x003a7c03, 0x000d8de2, 0x000d8edb, + 0x003fbbee, 0x003ebaed, 0x003db9ed, 0x003cb9ed, 0x003bb8ed, 0x003bb8ed, 0x003cb9ee, + 0x003cb9ee, 0x003db9ef, 0x003ab4f1, 0x0037aff3, 0x0032b3fe, 0x00b48f7d, 0x00ff5907, + 0x00f37122, 0x00f57c2b, 0x00f68735, 0x00f7923d, 0x00f89d45, 0x00f9ac50, 0x00f9bb5a, + 0x00f9c465, 0x00facd71, 0x00facd76, 0x00facd7b, 0x00f7cf80, 0x00f4d286, 0x00fcd689, + 0x00ffd98c, 0x00fbd48b, 0x00f3cf8a, 0x00f9c885, 0x00ffc17f, 0x00f5c27d, 0x00ffbc5e, + 0x0048abdc, 0x001e9deb, 0x001ea2e8, 0x001da8e5, 0x0099d31c, 0x008acb22, 0x0082c427, + 0x007abc2c, 0x0075b429, 0x0070ad25, 0x006dab17, 0x006ba908, 0x005ea912, 0x00519f54, + 0x00489b6d, 0x003e9887, 0x003b9592, 0x00389880, 0x00449663, 0x00509446, 0x0083b43c, + 0x004f851b, 0x00afe187, 0x009fcc83, 0x00368011, 0x0043821c, 0x0032853c, 0x000492f9, + 0x001092dd, 0x0040bcee, 0x003fbcee, 0x003ebbee, 0x003dbaed, 0x003cbaed, 0x003cb9ed, + 0x003cb9ec, 0x003cb9ec, 0x003cb8ec, 0x003fb4f0, 0x0043aff5, 0x000ebbe9, 0x00ffb897, + 0x00f7814d, 0x00f57623, 0x00f6812e, 0x00f88c39, 0x00f89943, 0x00f8a64d, 0x00f8b257, + 0x00f9bd60, 0x00fac96d, 0x00fbd47b, 0x00fad681, 0x00fad788, 0x00fbd98e, 0x00fbda93, + 0x00fae5a1, 0x00fed692, 0x00fadea0, 0x00f9db98, 0x00fad694, 0x00fbd090, 0x00ffd285, + 0x00ffc778, 0x00009afd, 0x0026a8f2, 0x0020a4f8, 0x0053bea5, 0x00a4da31, 0x009dd638, + 0x0097d03a, 0x0091ca3d, 0x008bc539, 0x0085c035, 0x007dbe31, 0x0074bc2d, 0x0076b81c, + 0x0077b027, 0x0072ab25, 0x006da724, 0x006ba328, 0x0068a31f, 0x0058951a, 0x0078b745, + 0x00bbf181, 0x0073ad4c, 0x00417c15, 0x00508b1e, 0x0043861c, 0x00498614, 0x0017868b, + 0x000b90f6, 0x00168ee8, 0x0042beef, 0x0041bdee, 0x0040bcee, 0x003fbced, 0x003ebbed, + 0x003dbaec, 0x003db9eb, 0x003cb8ea, 0x003bb7e9, 0x0039b9f0, 0x0037bbf7, 0x0050b5dc, + 0x00ff9744, 0x00fec49d, 0x00f87a24, 0x00f88530, 0x00f9913d, 0x00f8a049, 0x00f7af55, + 0x00f8b85d, 0x00f9c065, 0x00face75, 0x00fcdb85, 0x00fbde8d, 0x00fae195, 0x00fee29b, + 0x00ffe2a0, 0x00fbe9a4, 0x00ffbe6b, 0x00fdde9f, 0x00ffe8a6, 0x00fbe3a3, 0x00f8dea0, + 0x00fdd899, 0x00b6bdab, 0x00119ff1, 0x001ea4e9, 0x001a9fff, 0x0089d465, 0x00b0e245, + 0x00b0e04e, 0x00acdc4e, 0x00a7d94e, 0x00a1d649, 0x009ad345, 0x0097ce3d, 0x0094c935, + 0x008dc534, 0x0086c133, 0x007bbc32, 0x006fb731, 0x006db330, 0x006cae2e, 0x007eba3f, + 0x0070a531, 0x007bb54f, 0x00579a20, 0x005c9f2b, 0x00519425, 0x0080b965, 0x00609a1d, + 0x000390e3, 0x00118ef2, 0x001c89f2, 0x0044c0ef, 0x0043bfef, 0x0042beee, 0x0040bdee, + 0x003fbcee, 0x003fbbed, 0x0040baeb, 0x003eb9ed, 0x003cb9ee, 0x0037b9eb, 0x0027bcf7, + 0x00949c8f, 0x00fb9637, 0x00f9bc7c, 0x00f9b585, 0x00f7994a, 0x00f69b43, 0x00f6a64e, + 0x00f7b259, 0x00f8bc66, 0x00fac672, 0x00fad380, 0x00fae08d, 0x00f9e698, 0x00f9eba2, + 0x00feeaa6, 0x00ffeaab, 0x00fcefa9, 0x00faba62, 0x00fbdc99, 0x00fff4b9, 0x00fbecb2, + 0x00f7e6ab, 0x00ffe5a3, 0x0064b1d1, 0x00199ff0, 0x00269fe9, 0x000499f2, 0x00e3f051, + 0x00d5ef58, 0x00c0e364, 0x00bde165, 0x00bae065, 0x00b5de5d, 0x00b0dc56, 0x00aad74e, + 0x00a3d346, 0x009bd043, 0x0093cd3f, 0x008cc93e, 0x0084c63c, 0x0081c139, 0x007dbc36, + 0x008bc746, 0x0089c245, 0x0063a02c, 0x0065aa2c, 0x005ea42d, 0x00509626, 0x00a4cf98, + 0x00d9eadd, 0x00b9ddff, 0x00389ef4, 0x00008fd4, 0x0046c1ef, 0x0044c0ef, 0x0043bfef, + 0x0042beef, 0x0040bdef, 0x0042bced, 0x0043baec, 0x0040baf0, 0x003dbaf4, 0x0035b8e7, + 0x0017bdf7, 0x00d97f50, 0x00f79147, 0x00f7a554, 0x00ffdbba, 0x00f8a24d, 0x00f3a549, + 0x00f5ad53, 0x00f7b55e, 0x00f9c16f, 0x00fbcc7f, 0x00f9d88a, 0x00f8e595, 0x00f8eda2, + 0x00f8f5ae, 0x00fff3b2, 0x00fff2b6, 0x00fef5ae, 0x00f4b659, 0x00f9db93, 0x00feffcd, + 0x00fbf6c1, 0x00f7edb6, 0x00fff2ac, 0x0013a4f7, 0x0016a5f0, 0x0018a5e8, 0x0056b4cd, + 0x00f1f271, 0x00d5ef84, 0x00cfe67b, 0x00cde77c, 0x00cbe77c, 0x00c9e672, 0x00c7e567, + 0x00bce15f, 0x00b1dd57, 0x00a9dc51, 0x00a0da4b, 0x009dd749, 0x009ad447, 0x0094cf43, + 0x008fcb3f, 0x0088c43c, 0x0082be39, 0x0072b430, 0x0063a928, 0x0059a028, 0x004e9827, + 0x00a0c479, 0x00fffbf7, 0x007fd3f5, 0x00038fe2, 0x000e89e2, 0x0048c3ef, 0x0046c2ef, + 0x0045c1f0, 0x0043c0f0, 0x0042bff0, 0x0042beee, 0x0043bdec, 0x0041bcef, 0x003fbcf2, + 0x002fc0fe, 0x0036bdfc, 0x00f54c00, 0x00ff8a52, 0x00faa65e, 0x00fdc48e, 0x00fbc185, + 0x00f5ae50, 0x00f7b65e, 0x00f9be6c, 0x00fac978, 0x00fbd485, 0x00fede98, 0x00ffe8aa, + 0x00fdeeae, 0x00f9f5b2, 0x00fcf6ba, 0x00fff7c2, 0x00fcf0b2, 0x00f7cc6e, 0x00fbde91, + 0x00fdfcca, 0x00fffbd1, 0x00fffdc8, 0x00cae4c8, 0x0016a1f2, 0x001da4ef, 0x0012a1f1, + 0x009fd5b9, 0x00eaf28c, 0x00dcf095, 0x00d9eb90, 0x00d9ec93, 0x00d9ec95, 0x00d6eb8c, + 0x00d4ea83, 0x00c9e779, 0x00bfe36f, 0x00b8e368, 0x00b1e262, 0x00afe05e, 0x00addf5a, + 0x00a3d952, 0x0099d449, 0x008ecb41, 0x0084c33a, 0x0075b833, 0x0066ac2c, 0x005da329, + 0x00559927, 0x004b9421, 0x002499b9, 0x001593fe, 0x000993d8, 0x000f90d8, 0x004ac5ef, + 0x0048c4f0, 0x0046c2f0, 0x0045c1f1, 0x0043c0f1, 0x0043bfef, 0x0043bfed, 0x0042beee, + 0x0041bdf0, 0x0038bbf0, 0x0072a1b8, 0x00ff5d1e, 0x00f97931, 0x00f5a151, 0x00f9ad61, + 0x00fee0bd, 0x00f8b758, 0x00fabf69, 0x00fcc87a, 0x00fcd282, 0x00fcdc8b, 0x00fbde8f, + 0x00fbe193, 0x00fbeba4, 0x00fbf5b5, 0x00faf8c2, 0x00f9fcce, 0x00f9ecb7, 0x00fae183, + 0x00fee290, 0x00fbfac8, 0x00fdf8d8, 0x00fffccb, 0x008bcedc, 0x00189fee, 0x0025a3ee, + 0x000b9dfb, 0x00e8f6a5, 0x00e4f1a6, 0x00e4f0a6, 0x00e4efa6, 0x00e5f1aa, 0x00e6f2ad, + 0x00e3f1a6, 0x00e0ef9e, 0x00d7ec93, 0x00cde987, 0x00c8ea80, 0x00c2eb78, 0x00c1ea73, + 0x00c0e96e, 0x00b1e360, 0x00a3dd53, 0x0094d247, 0x0086c83b, 0x0078bc35, 0x0069b030, + 0x0062a52b, 0x005b9b27, 0x0057920a, 0x000995fc, 0x000d96e5, 0x001091eb, 0x001091eb, + 0x004ac5f0, 0x0049c4f0, 0x0047c3f1, 0x0045c2f1, 0x0044c1f2, 0x0041c1f2, 0x003fc1f2, + 0x003fbff1, 0x003fbcf0, 0x0032c3fe, 0x00be7f6e, 0x00fe6526, 0x00f67b35, 0x00f59a4d, + 0x00f8ab5c, 0x00fbd0a0, 0x00f7c783, 0x00fec16b, 0x00fdd17f, 0x00fbdb87, 0x00f9e590, + 0x00f8ed9a, 0x00f7f4a5, 0x00fbea9a, 0x00ffdf8e, 0x00fce3a0, 0x00f7e6b1, 0x00fceecc, + 0x00fffbcb, 0x00fff3c7, 0x00fcf1c3, 0x00fef5d2, 0x00fffcd3, 0x004bb5e7, 0x0021a5ed, + 0x001ca2ee, 0x003daae2, 0x00eef6ac, 0x00e6f2b1, 0x00e8f2b5, 0x00e9f3b8, 0x00eaf4ba, + 0x00ebf5bc, 0x00e8f3b6, 0x00e6f2af, 0x00e0f0a8, 0x00dbeea2, 0x00d6ef9a, 0x00d1f092, + 0x00c9ed82, 0x00c1eb73, 0x00b0e362, 0x00a1dc51, 0x0094d347, 0x0088ca3e, 0x007bbf38, + 0x006eb433, 0x0066a92e, 0x005da01b, 0x003d9448, 0x000a93f6, 0x000e94ec, 0x001193f0, + 0x001193f0, 0x004bc5f1, 0x004ac5f1, 0x0048c4f1, 0x0047c3f2, 0x0045c3f2, 0x0040c3f4, + 0x003bc4f6, 0x003cbff3, 0x003ebbf0, 0x002dcaff, 0x00ff5d25, 0x00fe6d2f, 0x00f37d39, + 0x00f59348, 0x00f8a958, 0x00f7c083, 0x00f7d7ae, 0x00ffc36d, 0x00ffda84, 0x00fbe48c, + 0x00f7ee94, 0x00f8ed9e, 0x00faeca7, 0x00f9f1b4, 0x00f8f6c1, 0x00fcf6c8, 0x00fff6d0, + 0x00fef2d3, 0x00fcf4ba, 0x00fffee8, 0x00f7fdea, 0x00fdfde3, 0x00fffcdc, 0x000b9df1, + 0x002aaaed, 0x001baaf6, 0x0080c8da, 0x00fdffbb, 0x00e8f2bd, 0x00ebf4c4, 0x00eff7cb, + 0x00eff7cb, 0x00eff7cb, 0x00edf6c5, 0x00ebf5c0, 0x00eaf4be, 0x00e8f3bd, 0x00e4f4b4, + 0x00e0f6ab, 0x00d0f191, 0x00c1ec77, 0x00b0e463, 0x009edb4e, 0x0095d448, 0x008bcc42, + 0x007fc23b, 0x0073b935, 0x006aac31, 0x0060a510, 0x00229687, 0x000b91f1, 0x000e93f3, + 0x001294f5, 0x001294f5, 0x004cc6f1, 0x004bc5f2, 0x0049c5f2, 0x0047c4f2, 0x0046c4f2, + 0x0043c4f1, 0x0040c4f0, 0x0042c0f3, 0x0039c1f6, 0x005eacca, 0x00fb591e, 0x00f36e31, + 0x00f88135, 0x00fb923f, 0x00fbaf5e, 0x00ffc373, 0x00fde2ba, 0x00ffcd75, 0x00ffd372, + 0x00ffe584, 0x00fff796, 0x00fef4a2, 0x00fdf1ae, 0x00fff8c2, 0x00fcf8cd, 0x00fef8d2, + 0x00fff9d6, 0x00fef6e1, 0x00fcf5dd, 0x00fffbee, 0x00fbfce8, 0x00fffce0, 0x00b2e0e8, + 0x0019a4f0, 0x0026abec, 0x0016a8f6, 0x00c2e4d8, 0x00f9fac5, 0x00eff6cb, 0x00f0f7ce, + 0x00f1f8d2, 0x00f1f8d1, 0x00f2f9d1, 0x00f1f9cd, 0x00f1f9ca, 0x00f2fbca, 0x00f4fdca, + 0x00e7f8b6, 0x00daf3a2, 0x00cbef8a, 0x00bcec71, 0x00b0e661, 0x00a5e151, 0x009ad949, + 0x008fd240, 0x0083c73b, 0x0077bc35, 0x006ab31d, 0x005ea905, 0x00138dea, 0x001193ef, + 0x001093f0, 0x000f93f0, 0x000f93f0, 0x004dc6f2, 0x004cc6f2, 0x004ac5f3, 0x0048c5f3, + 0x0047c5f3, 0x0046c4ef, 0x0046c4eb, 0x0048c0f3, 0x0034c7fb, 0x00989591, 0x00fc6428, + 0x00f1773b, 0x00fc8432, 0x00ff9135, 0x00ffb564, 0x00ffbe5a, 0x00f3ddb6, 0x00ccd097, + 0x00b4cea5, 0x00b0d3b1, 0x00abd7bd, 0x00c3e1bf, 0x00daebc1, 0x00f5fdc7, 0x00ffffbd, + 0x00fffecd, 0x00fffcdc, 0x00fffce0, 0x00fbfce5, 0x00fdfbe6, 0x00fffae7, 0x00fffbdd, + 0x0061c4f4, 0x0026aaee, 0x0022abec, 0x0010a7f6, 0x00ffffd7, 0x00f5f5d0, 0x00f6fad9, + 0x00f4f9d9, 0x00f2f9da, 0x00f3fad8, 0x00f4fbd7, 0x00f5fcd5, 0x00f7fdd4, 0x00f3face, + 0x00f0f7c8, 0x00e2f4b0, 0x00d4f199, 0x00c5ee82, 0x00b7eb6b, 0x00b1e95f, 0x00abe754, + 0x009fdf49, 0x0094d83f, 0x0087cc3a, 0x007bc034, 0x006bb425, 0x005ba332, 0x000495f9, + 0x001795ee, 0x001293ed, 0x000c91eb, 0x000c91eb, 0x004fc8f3, 0x004dc8f3, 0x004cc8f4, + 0x004bc8f4, 0x0049c8f4, 0x0047c5f2, 0x0045c2ef, 0x0042c2f8, 0x0034c8ff, 0x00df6746, + 0x00ff632a, 0x00ff701b, 0x00e18b53, 0x00a4a185, 0x0063c1cd, 0x0026c0ff, 0x002ab8ff, + 0x0025b5f1, 0x0027b7f9, 0x0026b5f6, 0x0023b3f2, 0x0024b5fa, 0x0025b7ff, 0x00189ddf, + 0x0043bbf4, 0x009edae8, 0x00f9f9dc, 0x00f3fbe6, 0x00ffffea, 0x00fdffe6, 0x00fafce2, + 0x00ffffff, 0x001ea8ef, 0x001ca8f1, 0x001ba8f2, 0x005bc4f1, 0x00ffffe7, 0x00fbf9e1, + 0x00fbfce3, 0x00f8fbe0, 0x00f5fadd, 0x00f5fbdb, 0x00f5fbda, 0x00f6fcd7, 0x00f6fdd3, + 0x00f0f8c9, 0x00ebf4be, 0x00dff2a9, 0x00d4f094, 0x00c7f47b, 0x00baf862, 0x00b0ef58, + 0x00a6e64e, 0x00a3e248, 0x0098d73a, 0x008acd38, 0x007bc435, 0x0070b821, 0x003b9c84, + 0x000d93f4, 0x001394ed, 0x001193e9, 0x000f92e6, 0x000f92e6, 0x0050c9f4, 0x004fcaf4, + 0x004ecaf5, 0x004dcaf5, 0x004ccaf6, 0x0048c5f4, 0x0045c0f3, 0x0047c2ef, 0x004ac4eb, + 0x00ff521f, 0x00a79a92, 0x0051b7e6, 0x0028c7ff, 0x002cc4f9, 0x0031c1f1, 0x003fbbf0, + 0x0037c0ef, 0x0039b9f0, 0x003bb3f1, 0x0038b5f4, 0x0036b7f7, 0x0032b9f0, 0x002fbbe8, + 0x002fb8eb, 0x002fb5ed, 0x0020acf3, 0x0010a3fa, 0x0070c9f3, 0x00f5f9df, 0x00f6fbde, + 0x00f6fdde, 0x00d8ebe4, 0x0011a5ee, 0x002db2f5, 0x0014a5f8, 0x00a5e2ec, 0x00fffff8, + 0x00fffef3, 0x00fffded, 0x00fcfde6, 0x00f8fce0, 0x00f7fcde, 0x00f6fcdd, 0x00f6fcd8, + 0x00f5fdd3, 0x00edf7c4, 0x00e5f1b4, 0x00e5f5b8, 0x00e4f9bb, 0x00ecfed2, 0x00f3ffe9, + 0x00edfedb, 0x00e8f9cd, 0x00caef89, 0x009cd636, 0x0084c72e, 0x006bb826, 0x006cb315, + 0x001a95d6, 0x001591ef, 0x001093eb, 0x001193e6, 0x001294e1, 0x001294e1, 0x0052cbf4, + 0x0050caf4, 0x004ecaf4, 0x004ccaf3, 0x004ac9f3, 0x0048c8f5, 0x0046c7f6, 0x0040bfed, + 0x0041bfeb, 0x0041d4f9, 0x0033c9fc, 0x002fc9ff, 0x0042c3ec, 0x0040c3f4, 0x003ec3fc, + 0x0035bbf4, 0x0033bbf3, 0x0049bdf7, 0x0039b7f9, 0x0037b7f6, 0x0035b7f2, 0x002eb5f4, + 0x0028b3f5, 0x002fbbf8, 0x002fbaf2, 0x0030b5f2, 0x0031b0f1, 0x001facf6, 0x000dabed, + 0x007fd2ed, 0x00ffffe6, 0x0080d9d2, 0x002faaf8, 0x001dafec, 0x0003aae6, 0x00fff8ff, + 0x00fffffe, 0x00fffff9, 0x00fffdf4, 0x00fdfeeb, 0x00fbfee3, 0x00f9fde1, 0x00f7fce0, + 0x00f5fdd8, 0x00f4fdcf, 0x00f5fce2, 0x00f6fde8, 0x00f3fde8, 0x00f1fde9, 0x00ebfdd3, + 0x00e6fdbe, 0x00e0f8ba, 0x00daf2b7, 0x00eafcd2, 0x00f2fde6, 0x00b7de8d, 0x0084c73d, + 0x009ab848, 0x0014a1f9, 0x000494f3, 0x001094ef, 0x001095ec, 0x001095e9, 0x001095e9, + 0x0054ccf5, 0x0051cbf4, 0x004ecaf3, 0x004cc9f2, 0x0049c8f1, 0x0048cbf5, 0x0048cef9, + 0x0040c4f3, 0x0049cafc, 0x0040c2f1, 0x0047caf5, 0x0046c7f4, 0x0046c4f3, 0x0039b5ee, + 0x002ca5e8, 0x002eb1e1, 0x0056c1ea, 0x006dc9e9, 0x0037c2e5, 0x0051caeb, 0x006bd2f1, + 0x0074d1f5, 0x007dcff9, 0x0056c7f8, 0x001fafe8, 0x0025b1ee, 0x002cb3f4, 0x003eb5f9, + 0x002bb3ee, 0x001baff5, 0x0032b5f0, 0x003fb2f9, 0x0026a9f2, 0x001faeeb, 0x003fb8f4, + 0x00fcfff3, 0x00ffffff, 0x00ffffff, 0x00fffefb, 0x00fefff1, 0x00feffe6, 0x00fbffe5, + 0x00f8fde3, 0x00f5fdd7, 0x00f3fecb, 0x00f5fbeb, 0x00f7feee, 0x00f2fdde, 0x00edfccf, + 0x00e3f9b0, 0x00d9f692, 0x00d2f48b, 0x00ccf184, 0x00ceee97, 0x00d0eaa9, 0x00daebc1, + 0x00f4fbe9, 0x007fc679, 0x005ac1ff, 0x001aa1eb, 0x001195f2, 0x000f96f2, 0x000e97f2, + 0x000e97f2, 0x0054cdf5, 0x0052ccf4, 0x004fcbf3, 0x004dc9f3, 0x004ac8f2, 0x0049c6f2, + 0x0047c4f2, 0x0049d2f3, 0x0046c8f3, 0x004dc5fc, 0x002c9add, 0x001883cd, 0x00046cbe, + 0x000080c5, 0x000f96d4, 0x002eaddb, 0x0060c6eb, 0x0076cdef, 0x0051caea, 0x0069d2f0, + 0x0081daf5, 0x009ae4f7, 0x00b3eff9, 0x00cffaff, 0x00e3feff, 0x009ae1ff, 0x0048bcf7, + 0x0011b5dd, 0x0032aef0, 0x0028acfc, 0x0031b2f3, 0x0034b1f6, 0x0025adf0, 0x0026acf6, + 0x0098d1fc, 0x00fffdf8, 0x00ffffff, 0x00fffffb, 0x00fefff4, 0x00fdffee, 0x00fcfde7, + 0x00fbfee4, 0x00faffe0, 0x00f8fde7, 0x00f7fcef, 0x00f3fbeb, 0x00effdd9, 0x00e9fbc2, + 0x00e3f9ac, 0x00d9f49b, 0x00ceef8b, 0x00c1ea76, 0x00b4e562, 0x00abdd5a, 0x00a2d261, + 0x00c1e98e, 0x00dbe8b9, 0x0096d4ff, 0x008ed0fa, 0x0042aeee, 0x001095f1, 0x001096f1, + 0x000f96f1, 0x000f96f1, 0x0055cef5, 0x0053ccf4, 0x0050cbf4, 0x004ecaf4, 0x004cc8f4, + 0x0051caf7, 0x0057cbfa, 0x0045c0ea, 0x001a75c7, 0x000058ad, 0x00015bb4, 0x00066fc0, + 0x000b84cd, 0x000093ce, 0x0011a7e0, 0x003eb9e6, 0x006bcbeb, 0x007ed1f6, 0x006cd3f0, + 0x0082dbf4, 0x0098e3f9, 0x00a5ecf7, 0x00b2f4f5, 0x00c7f7f9, 0x00ddfafd, 0x00f2ffff, + 0x00f8fff6, 0x00bcebfe, 0x0022b4f2, 0x0029afff, 0x002fb0f7, 0x0029b1f2, 0x0023b1ee, + 0x001aa7fa, 0x00cae6f4, 0x00f7f8f4, 0x00feffff, 0x00fefff7, 0x00feffed, 0x00fcffeb, + 0x00fbfae9, 0x00fbfee3, 0x00fbffdc, 0x00fbffe9, 0x00fbfff7, 0x00f1fedd, 0x00e7fbc3, + 0x00e0f6b4, 0x00d8f0a5, 0x00ceec94, 0x00c4e884, 0x00b8e678, 0x00ace36c, 0x00a0df53, + 0x0094d455, 0x0080bd41, 0x00d2e599, 0x002ca1f4, 0x0030a2f6, 0x00209cf3, 0x001096f1, + 0x001096f1, 0x001096f1, 0x001096f1, 0x0055cef4, 0x0053cdf4, 0x0051cbf5, 0x0050cbf5, + 0x004ecaf6, 0x004dc9f4, 0x0054d0fa, 0x002b86ce, 0x000752b1, 0x00045fb9, 0x000a74c9, + 0x000882ce, 0x000691d4, 0x0002a0d5, 0x0024b5e7, 0x004cc4ea, 0x0074d3ee, 0x0083d9f5, + 0x007fddf4, 0x0093e4f6, 0x00a8ecf9, 0x00b6f2f9, 0x00c3f9f9, 0x00d3fafb, 0x00e3fcfc, + 0x00edfefb, 0x00f0f9f3, 0x00ffffff, 0x00fffdff, 0x007edcef, 0x0026adfd, 0x002aaff7, + 0x002db2f2, 0x0034b1e0, 0x0009a7f7, 0x008dd3f5, 0x00fdfbf9, 0x00fffff6, 0x00fdffeb, + 0x00fcffe6, 0x00fcfce0, 0x00f9fcde, 0x00f7fcdd, 0x00fcffef, 0x00f9fdec, 0x00e8f5d0, + 0x00dff5bd, 0x00d9f1ad, 0x00d2ed9d, 0x00c5e97e, 0x00b8e26d, 0x00abdd5e, 0x009fd74f, + 0x0098c95f, 0x0092c735, 0x008bc942, 0x0080b34d, 0x00009bf2, 0x001894f8, 0x001595f5, + 0x001397f2, 0x001296f1, 0x001195f0, 0x001195f0, 0x0056cff4, 0x0054cdf5, 0x0052ccf5, + 0x0051cbf7, 0x0051cbf9, 0x0049c8f1, 0x0051d5fa, 0x001662c1, 0x00005cbb, 0x000874cd, + 0x00037cce, 0x00028dd4, 0x00019edb, 0x0009aedc, 0x0037c2ee, 0x005acfef, 0x007edcf0, + 0x0088e1f4, 0x0092e6f8, 0x00a5eef8, 0x00b9f5f9, 0x00c7f9fb, 0x00d5fdfe, 0x00dffdfc, + 0x00e9fdfa, 0x00f0fefe, 0x00f8ffff, 0x00fafffe, 0x00fdfffc, 0x00fdfbff, 0x001db0e8, + 0x002ab1ee, 0x0037b2f5, 0x0025b9f7, 0x0029b4f8, 0x0022aff5, 0x001baaf2, 0x009fd7f6, + 0x00fdffea, 0x00fcfee0, 0x00fcfdd7, 0x00f8fada, 0x00f4f7dd, 0x00fdfef5, 0x00f6fae1, + 0x00dfecc3, 0x00d8efb6, 0x00d2eca6, 0x00ccea95, 0x00bce567, 0x00abdb56, 0x009fd344, + 0x0092cb33, 0x0085c824, 0x0079b46a, 0x003a9eaf, 0x000c97ff, 0x001994f9, 0x000f9bee, + 0x00139af0, 0x001699f3, 0x001497f1, 0x001295ef, 0x001295ef, 0x0058d0f5, 0x0056cef5, + 0x0053cdf4, 0x0053ccf6, 0x0052cbf8, 0x0053d6fb, 0x004fc8fc, 0x00004cad, 0x00096fca, + 0x000b80d4, 0x000588d5, 0x000598db, 0x0005a8e1, 0x0018b6e6, 0x003fc8f2, 0x0063d3f3, + 0x0086dff5, 0x0091e4f7, 0x009ce9fa, 0x00aef0f9, 0x00c0f7f9, 0x00cbfafb, 0x00d7fdfd, + 0x00defdfc, 0x00e6fefb, 0x00f0fffe, 0x00faffff, 0x00f2fefb, 0x00fefffd, 0x00c6e9fb, + 0x001eb0ec, 0x0030b4f6, 0x0030b7f8, 0x0019a8f7, 0x0026b0f0, 0x0022aef3, 0x001eabf5, + 0x0027aafa, 0x001ca6f6, 0x007dcdea, 0x00dff4dd, 0x00eaffb0, 0x00fdfeed, 0x00ffffef, + 0x00fcf9d3, 0x00edeeb4, 0x00e6e9ac, 0x00d9e68a, 0x00cbe367, 0x00b9e153, 0x00a6dd4d, + 0x0075c57f, 0x0043adb0, 0x00229bf3, 0x000a9cff, 0x000998f6, 0x00109cef, 0x00189aee, + 0x00149ded, 0x00159bf0, 0x001599f2, 0x001397f0, 0x001195ee, 0x001195ee, 0x005ad1f6, + 0x0057cff5, 0x0054cef4, 0x0054cdf6, 0x0053cbf8, 0x004dd3f4, 0x002c9add, 0x00045ec1, + 0x000572c9, 0x000683d2, 0x000794dc, 0x0008a2e2, 0x0008b1e8, 0x0028bfef, 0x0048cef6, + 0x006bd8f8, 0x008fe3fa, 0x009be8fa, 0x00a6edfb, 0x00b7f3fb, 0x00c7f9fa, 0x00d0fbfc, + 0x00d9fdfd, 0x00defefd, 0x00e2fffc, 0x00effffe, 0x00fcffff, 0x00ebfef7, 0x00fffffe, + 0x008fd7f8, 0x001eb0f1, 0x002eb0f6, 0x0018abec, 0x00e0f7fd, 0x0024ade9, 0x0023acf1, + 0x0021acf8, 0x0026aef7, 0x002cb0f6, 0x001aa9f5, 0x0008a3f4, 0x0022a7f9, 0x004cc2f2, + 0x006dcdef, 0x007ec9db, 0x007fcac2, 0x0081c6c6, 0x0061bccb, 0x0041b3d0, 0x0024a7e9, + 0x00089bff, 0x00119dff, 0x001a9fff, 0x000f99e9, 0x00149cf9, 0x00159cf7, 0x00159cf5, + 0x00179df1, 0x00199eed, 0x00179cef, 0x001599f1, 0x001397ef, 0x001195ed, 0x001195ed, + 0x005cd2f6, 0x0059d0f5, 0x0055cff3, 0x0054cdf5, 0x0053ccf8, 0x0051d5f6, 0x00167bcf, + 0x000467c6, 0x00067bcf, 0x00068bd7, 0x00059cdf, 0x0008a9e5, 0x000ab6eb, 0x002bc4f1, + 0x004cd2f7, 0x006ddbf9, 0x008ee5fa, 0x009deafb, 0x00aceffb, 0x00bdf5fb, 0x00cefbfa, + 0x00d5fbfc, 0x00dcfcfd, 0x00dcfefd, 0x00ddfffd, 0x00e4fffd, 0x00eafffd, 0x00fffffe, + 0x00ffffff, 0x0027c0de, 0x0026b5f6, 0x001fb0f9, 0x004dc6ff, 0x00fff9ef, 0x00fefffa, + 0x008bd8f7, 0x0018a7f3, 0x001daaf4, 0x0023acf6, 0x0022acf3, 0x0022abf0, 0x001aa3f2, + 0x001aa6ee, 0x0018a8f5, 0x000ea2f3, 0x0011a4f2, 0x0014a4ff, 0x0015a3fc, 0x0016a3fa, + 0x0017a2f3, 0x0019a2ec, 0x000e99fe, 0x00169bed, 0x0000a1ff, 0x002b9de8, 0x0061b5b0, + 0x00109af7, 0x00149cf2, 0x00189eed, 0x00169cef, 0x00149af0, 0x001298ee, 0x001096ec, + 0x001096ec, 0x005fd3f7, 0x005bd2f5, 0x0056d0f3, 0x0055cef5, 0x0053cdf7, 0x0056d8f8, + 0x00005cc0, 0x000370cb, 0x000785d6, 0x000594dc, 0x0004a3e2, 0x0008afe8, 0x000cbcee, + 0x002ec8f3, 0x0050d5f9, 0x006fdefa, 0x008de7fb, 0x009fecfb, 0x00b1f2fb, 0x00c3f7fb, + 0x00d4fcfa, 0x00d9fcfc, 0x00defcfd, 0x00dbfdfd, 0x00d9fffd, 0x00d9fdfb, 0x00d9fcfa, + 0x00e5fafa, 0x00a4eaf7, 0x002badfb, 0x002fb9fa, 0x001aaeed, 0x0099dbf8, 0x00ffffff, + 0x00fefdfc, 0x00fffefd, 0x00fffffd, 0x008cd4fa, 0x0019a9f6, 0x0018a9f7, 0x0016aaf9, + 0x001aa7f3, 0x001ea5ee, 0x001fa7f2, 0x0021a9f6, 0x001ea7f7, 0x001ba5f7, 0x0017a4f9, + 0x0012a2fb, 0x000b9dfd, 0x000399fe, 0x0026a2fa, 0x006fc0b0, 0x00cfca5e, 0x00ffe528, + 0x0074b4b3, 0x000b98fa, 0x00119af4, 0x00179dee, 0x00159cee, 0x00139aef, 0x001198ed, + 0x000f96eb, 0x000f96eb, 0x005dd1f6, 0x005bd2f5, 0x0058d2f4, 0x0053cef4, 0x0056d2fb, + 0x0040b2e6, 0x000164c6, 0x000376cf, 0x000487d7, 0x000296dd, 0x0001a4e4, 0x0004b1ea, + 0x0007bdf1, 0x001bc8f2, 0x0043d5fc, 0x0064ddfb, 0x0085e6fb, 0x0098ebfc, 0x00acf1fd, + 0x00bef9ff, 0x00cfffff, 0x00cffdff, 0x00cff9fb, 0x00d2fefe, 0x00d5ffff, 0x00c6f9ff, + 0x00b8efff, 0x005ad7d9, 0x0040b9e9, 0x002fb9ff, 0x002bb2f0, 0x0028afeb, 0x00def0f2, + 0x00ffffff, 0x00feffff, 0x00fffefe, 0x00fffefa, 0x00fffffa, 0x00fffff9, 0x00c2e8f0, + 0x0084cde7, 0x0053bbe9, 0x0022a9eb, 0x0014a1ff, 0x00069ff8, 0x000fa0f8, 0x0019a3eb, + 0x0043b1e1, 0x006ec2c9, 0x00b0d79a, 0x00f2eb6b, 0x00ebee32, 0x00f8e647, 0x00ffe23a, + 0x00fde142, 0x000098f4, 0x0019a1fc, 0x00169ef7, 0x00129bf1, 0x00139af1, 0x00149af0, + 0x001298ee, 0x001096ec, 0x001096ec, 0x005ccff6, 0x005bd2f6, 0x005ad4f6, 0x0052cdf2, + 0x005ad6fe, 0x00298cd5, 0x00026ccc, 0x00027bd2, 0x000189d8, 0x000097df, 0x0000a6e6, + 0x0000b2ed, 0x0002bef4, 0x0009c7f1, 0x0035d5ff, 0x0059ddfd, 0x007ce5fb, 0x0091eafd, + 0x00a6f0ff, 0x00b1f2ff, 0x00bbf5ff, 0x00bef5fc, 0x00c1f6f9, 0x00c1f7f7, 0x00c1f9f4, + 0x00c7fdfc, 0x00cdffff, 0x00c2f9f8, 0x005acdf4, 0x0039b1f3, 0x0038baf5, 0x002ab4f7, + 0x00fcfbf8, 0x00fdfeff, 0x00feffff, 0x00fffeff, 0x00fffcf6, 0x00fdfef2, 0x00f7ffee, + 0x00fcffea, 0x00ffffe5, 0x00ffffd8, 0x00ffffcb, 0x00fffbf1, 0x00ffffdf, 0x00fdfdc2, + 0x00f7ff88, 0x00fbfe92, 0x00ffff7f, 0x00fdfc6c, 0x00faf759, 0x00f8f059, 0x00f7e958, + 0x00f7e359, 0x00d0d368, 0x000998ff, 0x00189aef, 0x00129af2, 0x000c99f5, 0x001199f3, + 0x001599f2, 0x001397f0, 0x001195ee, 0x001195ee, 0x005fd2f9, 0x005cd3f8, 0x0059d4f6, + 0x0058d3f8, 0x005edaff, 0x001971cd, 0x00026ecd, 0x00037bd3, 0x000488d9, 0x000497e0, + 0x0005a6e6, 0x0001ade7, 0x0000b5e8, 0x0007beea, 0x0023cbf5, 0x004cd7f8, 0x0074e4fc, + 0x0089e8fd, 0x009fecfe, 0x00a5edfe, 0x00abeffe, 0x00aeeffc, 0x00b0eff9, 0x00b3f3f9, + 0x00b6f6f8, 0x00b6f9fc, 0x00b5fcff, 0x00daf3ff, 0x001ab9f1, 0x0028b3f4, 0x002bb3f6, + 0x0073cef4, 0x00fdfdf5, 0x00fdfefa, 0x00fdfffe, 0x00fffef9, 0x00fffdf3, 0x00fdfeee, + 0x00faffe9, 0x00fdffe4, 0x00ffffde, 0x00ffffd0, 0x00ffffc2, 0x00fdfad7, 0x00fffcf3, + 0x00ffffc0, 0x00fcfbc5, 0x00fcff84, 0x00fcfb8b, 0x00fbf67a, 0x00f9f269, 0x00f7ed5e, + 0x00f4e954, 0x00f7e948, 0x0087bda9, 0x00109afc, 0x00179cf2, 0x00149bf1, 0x00119af1, + 0x001399f2, 0x001698f3, 0x001496f1, 0x001294ef, 0x001294ef, 0x0062d4fc, 0x005dd4f9, + 0x0059d4f6, 0x0056d1f6, 0x0053cef5, 0x00014ebe, 0x00026fcd, 0x00057bd4, 0x000787da, + 0x000996e0, 0x000ca5e7, 0x000bb0e9, 0x0009bbeb, 0x0015c5f3, 0x0021d0fc, 0x0046dafc, + 0x006ce3fc, 0x0082e6fd, 0x0097e9fe, 0x0099e9fe, 0x009ce8fe, 0x009ee9fb, 0x00a0e9f9, + 0x00a6eefa, 0x00acf3fc, 0x00b0effc, 0x00b5ecfb, 0x0089ddf9, 0x0028b4f3, 0x003ebef7, + 0x001eadf7, 0x00bde8f0, 0x00fefff2, 0x00fefff3, 0x00fdfff4, 0x00fefef2, 0x00fefef0, + 0x00fefeea, 0x00fefee4, 0x00fefede, 0x00fefed8, 0x00fcffc9, 0x00fbffba, 0x00f6fea0, + 0x00ffffce, 0x00fff9f6, 0x00ffffc9, 0x00fdf7be, 0x00f8f87a, 0x00f9f66b, 0x00f9f35c, + 0x00f5ee56, 0x00f1e84f, 0x00f8ee37, 0x003fa7ea, 0x00189df5, 0x00179df4, 0x00169cf1, + 0x00159bee, 0x00169af2, 0x001798f5, 0x001596f3, 0x001394f1, 0x001394f1, 0x0066d7fc, + 0x005fd1f5, 0x0060d4f6, 0x0059d8f9, 0x00399ddb, 0x000858be, 0x00096ccd, 0x000c7ad2, + 0x001087d7, 0x001296df, 0x0013a6e8, 0x0013b0eb, 0x001bc3f5, 0x000fc8f3, 0x0017d0f9, + 0x0027d3f4, 0x004bd7f7, 0x0061dbf8, 0x0077def9, 0x007fe0fa, 0x0088e1fa, 0x008de4fb, + 0x0091e7fb, 0x0096eafc, 0x009aedfd, 0x009feafb, 0x00a3e7fa, 0x005eccfb, 0x002db7f5, + 0x0024b8f9, 0x0014b1f5, 0x00fffbff, 0x00feffec, 0x00ffffed, 0x00ffffee, 0x00ffffec, + 0x00fefdeb, 0x00fefde4, 0x00fefddd, 0x00fefed6, 0x00fefece, 0x00fcfdc1, 0x00fcfcb5, + 0x00f6fb8d, 0x00f8fc8a, 0x00f8facc, 0x00f8fef2, 0x00f9ffbe, 0x00fbf9c2, 0x00fbf8ac, + 0x00fcf796, 0x00faf491, 0x00f7f18d, 0x00ffe5a9, 0x000096f7, 0x00089af7, 0x00159ef7, + 0x00169df4, 0x00169cf0, 0x00169bf2, 0x001699f4, 0x001497f3, 0x001396f1, 0x001396f1, + 0x006bd9fb, 0x0061cef1, 0x0067d3f7, 0x005cdefd, 0x001f6cc0, 0x000f63bf, 0x000f6acd, + 0x001478d1, 0x001887d4, 0x001997df, 0x001aa6e9, 0x0014a9e4, 0x001dbbef, 0x000dbeeb, + 0x0023c5f6, 0x0013c6ed, 0x002acbf3, 0x0040cff4, 0x0056d4f4, 0x0065d7f6, 0x0074daf7, + 0x007bdffb, 0x0083e5fe, 0x0086e6fe, 0x0089e8fd, 0x008ee5fb, 0x0092e2fa, 0x0033bcfc, + 0x0032b9f7, 0x0031bafd, 0x0057c5f7, 0x00f4ffde, 0x00fdffe7, 0x00ffffe7, 0x00ffffe7, + 0x00ffffe6, 0x00fdfce6, 0x00fdfddd, 0x00fdfdd5, 0x00fdfdcd, 0x00fefdc5, 0x00fdfaba, + 0x00fcf8af, 0x00fef99f, 0x00fffb8e, 0x00fafe77, 0x00f4fb7d, 0x00f9f8d2, 0x00fdffee, + 0x00fefedf, 0x00fffcd0, 0x00fefacd, 0x00fdf9ca, 0x00a6d3ce, 0x000399eb, 0x001ea1ec, + 0x00149ffa, 0x00159ef6, 0x00179ef2, 0x00169cf3, 0x00159af3, 0x001499f2, 0x001398f1, + 0x001398f1, 0x0055d4f4, 0x005bd1f1, 0x0069d6f6, 0x006ee2ff, 0x000c50a8, 0x001161be, + 0x000f6acd, 0x001f83d6, 0x001f89dc, 0x000f8cdd, 0x001a9be0, 0x0022b1f4, 0x001dabe1, + 0x0014aedf, 0x0026bdee, 0x0015bae7, 0x001fc1ef, 0x0025c7ef, 0x002bcdef, 0x003dcdf1, + 0x004ecef3, 0x005bd6f9, 0x0068defe, 0x006eddfc, 0x0073ddfb, 0x0076ddf5, 0x0070d3f7, + 0x0031bafb, 0x0033b9f6, 0x0024b6ff, 0x00a4dee5, 0x00f9ffdc, 0x00fdfedc, 0x00ffffdc, + 0x00ffffdc, 0x00fefedb, 0x00fcfdda, 0x00fdfdd2, 0x00fdfdcb, 0x00fdfdc3, 0x00fefdbc, + 0x00fdfbaf, 0x00fcfaa2, 0x00fdfb93, 0x00fefb83, 0x00fcfd6b, 0x00f9fc60, 0x00fbf85d, + 0x00fdf74c, 0x00fef576, 0x00fff2a1, 0x00f6ec87, 0x00f8e360, 0x0051bbb4, 0x000d9afe, + 0x001a9ef7, 0x00159ef6, 0x00159df4, 0x00159df2, 0x00149bf2, 0x001299f2, 0x001299f2, + 0x001299f2, 0x001299f2, 0x0067d4fd, 0x0069d6f9, 0x006cd9f5, 0x004fb7dc, 0x001953af, + 0x001c67c6, 0x00005abd, 0x001a7eca, 0x00157bd4, 0x000581dc, 0x002aa1e7, 0x000189d3, + 0x002dabe3, 0x0023a7dc, 0x0029b4e6, 0x0017ade1, 0x0014b7ec, 0x0015b9ea, 0x0016bbe9, + 0x001fbfec, 0x0028c2ef, 0x003bcdf7, 0x004ed8ff, 0x0056d5fb, 0x005dd2f8, 0x005ed6f0, + 0x004ec5f4, 0x002fb9fa, 0x0035b8f4, 0x0017b1ff, 0x00f0f7d2, 0x00feffda, 0x00fdfcd2, + 0x00fdfdd1, 0x00fdfed1, 0x00fdfecf, 0x00fcfecd, 0x00fcfdc7, 0x00fdfdc0, 0x00fdfdb9, + 0x00fdfdb2, 0x00fdfca4, 0x00fdfc95, 0x00fdfc87, 0x00fdfc79, 0x00fdfa6c, 0x00fef85f, + 0x00f9f645, 0x00f6ef47, 0x00f2e938, 0x00efe428, 0x00eee425, 0x00ffdd05, 0x000399ff, + 0x0017a1f5, 0x00179ef4, 0x00169cf3, 0x00159cf3, 0x00149cf3, 0x00129bf1, 0x001099f0, + 0x00119af1, 0x00129bf2, 0x00129bf2, 0x0066d5fb, 0x0070d5fc, 0x0078e2ff, 0x003b86c7, + 0x00235fba, 0x001e6aba, 0x00227ad1, 0x002787d8, 0x00248cd7, 0x001d8dd4, 0x002189d1, + 0x002ca1ea, 0x002296d5, 0x0031aaef, 0x0020a1db, 0x0017a1dd, 0x000ea1e0, 0x001aace3, + 0x0013b1eb, 0x0010b8ed, 0x000dc0ef, 0x001cc1ef, 0x002cc3f0, 0x0036c4f2, 0x0040c5f4, + 0x0047c9f2, 0x0045c3f6, 0x0031bafa, 0x0031b7f7, 0x004cc2f4, 0x00f5fac0, 0x00fdffc6, + 0x00fdfcc5, 0x00fdfdc4, 0x00fdfdc4, 0x00fcfdc2, 0x00fbfdc1, 0x00f8f9b6, 0x00fdfdb3, + 0x00fdfdab, 0x00fdfca3, 0x00fcfc95, 0x00fcfb88, 0x00fcfb7b, 0x00fbfb6d, 0x00fcf962, + 0x00fcf757, 0x00f8f245, 0x00f4eb41, 0x00f0e532, 0x00ebe023, 0x00fbe01c, 0x00c5d244, + 0x000aa2fe, 0x00169ff9, 0x00179ff6, 0x00189ff3, 0x00179ef2, 0x00159df2, 0x00179ff5, + 0x0018a1f8, 0x00159ef5, 0x00129bf2, 0x00129bf2, 0x0065d7fa, 0x0064d1f7, 0x005de7ff, + 0x0004439b, 0x000e4ca5, 0x00317bcd, 0x000455c1, 0x000053c9, 0x000368c6, 0x002687ca, + 0x002881ca, 0x002789d1, 0x002791d7, 0x000774c9, 0x00178dcf, 0x001f9ce1, 0x00179be4, + 0x001e9eda, 0x000097de, 0x0003a5e6, 0x0008b1ee, 0x0009b0e8, 0x000aafe2, 0x0017b4e9, + 0x0024b9ef, 0x0030bdf4, 0x003cc1f9, 0x0034bcf9, 0x002cb6f9, 0x0080d2e8, 0x00fafdaf, + 0x00fcfdb3, 0x00fdfcb7, 0x00fdfcb7, 0x00fdfdb7, 0x00fcfcb6, 0x00fbfcb5, 0x00f4f4a5, + 0x00fdfda5, 0x00fcfc9d, 0x00fcfc94, 0x00fbfb87, 0x00fbfb7b, 0x00fafa6e, 0x00fafa61, + 0x00faf758, 0x00faf54e, 0x00f7ee44, 0x00f3e73a, 0x00ede12c, 0x00e7db1e, 0x00ffd21a, + 0x0078b090, 0x0009a0fd, 0x00159dfd, 0x0018a0f8, 0x001aa2f2, 0x0018a0f2, 0x00169ef2, + 0x00139bf2, 0x001099f1, 0x00119af2, 0x00129bf3, 0x00129bf3, 0x0060d4f7, 0x0067dcfd, + 0x004fc2f0, 0x00002c8a, 0x002e6bc0, 0x000547ad, 0x000044ba, 0x003685c4, 0x00064ebc, + 0x001462c3, 0x002d70cb, 0x000f5ab4, 0x002274cd, 0x001169c2, 0x001979c2, 0x001d80d0, + 0x001980d7, 0x001a86d3, 0x001090de, 0x00038dda, 0x000599e6, 0x00059ce1, 0x00049edd, + 0x0005a6e1, 0x0000a7de, 0x001fb6ee, 0x0039bdf7, 0x0038bcf6, 0x0024b5fc, 0x00bfe8b9, + 0x00fafea2, 0x00fbfca5, 0x00fcfaa8, 0x00fcfca7, 0x00fdfda6, 0x00fbfca3, 0x00f9fb9f, + 0x00f6f795, 0x00fafb92, 0x00fbfb8b, 0x00fbfb85, 0x00fafa79, 0x00fafa6d, 0x00f9f961, + 0x00f8f956, 0x00f9f64c, 0x00f9f442, 0x00f5ec39, 0x00f2e531, 0x00efde28, 0x00ecd620, + 0x00eed900, 0x0032a6e5, 0x0019a4ff, 0x0029a4f4, 0x0020a2f4, 0x0018a0f5, 0x00179ef4, + 0x00159df4, 0x00139bf3, 0x001199f2, 0x00129af2, 0x00129af3, 0x00129af3, 0x005bd1f5, + 0x0063dffa, 0x00318dcc, 0x00062d91, 0x000e499a, 0x0000369f, 0x00003897, 0x00155fb6, + 0x0053aad9, 0x0031a6e2, 0x0045bcef, 0x006dddff, 0x0076defa, 0x006dd9f9, 0x0064d5f9, + 0x0054c5f3, 0x0045b5ed, 0x00238ed6, 0x001277ce, 0x00006cc6, 0x000282de, 0x000187db, + 0x00008dd7, 0x00079be1, 0x000099dc, 0x0022b1f0, 0x0036baf4, 0x003cbcf4, 0x001cb5ff, + 0x00fffe89, 0x00fbff96, 0x00fbfc98, 0x00fbf99a, 0x00fcfb98, 0x00fdfd96, 0x00fafb90, + 0x00f6f98a, 0x00f7f984, 0x00f8fa7f, 0x00fafa7a, 0x00fbfb75, 0x00fafa6a, 0x00f9f960, + 0x00f8f855, 0x00f7f84a, 0x00f7f540, 0x00f8f336, 0x00f4eb2f, 0x00f0e328, 0x00f0da24, + 0x00f0d121, 0x00e9ca24, 0x00049bff, 0x0020a3f6, 0x0016a1f7, 0x0016a0f7, 0x00169ef7, + 0x00159df6, 0x00149cf5, 0x00139bf4, 0x00129af3, 0x00129af3, 0x00129af3, 0x00129af3, + 0x005ae3ff, 0x0064d8ff, 0x000d4798, 0x00002682, 0x001d6bb7, 0x003aa2de, 0x005fe5ff, + 0x0052d8fd, 0x004dd6f6, 0x0048ccf5, 0x005fd0f6, 0x0068d9ff, 0x0061d3f8, 0x005bd2f8, + 0x0042cbff, 0x0053cefe, 0x0051cff5, 0x0049caf6, 0x004acdff, 0x0040baff, 0x000e7edb, + 0x000069c2, 0x000584da, 0x000184d5, 0x00068cd8, 0x0038bef8, 0x003abef7, 0x0035beff, + 0x0062c7e2, 0x00fbf379, 0x00f8fa83, 0x00f9f983, 0x00faf884, 0x00f9f77f, 0x00f7f77b, + 0x00f8f979, 0x00f9fa77, 0x00f8f972, 0x00f7f86c, 0x00fcfc6c, 0x00f9f864, 0x00f8f85b, + 0x00f8f752, 0x00f7f649, 0x00f6f53f, 0x00f5f237, 0x00f4ef2f, 0x00f1e628, 0x00eede20, + 0x00ead61f, 0x00f2cc11, 0x009db96c, 0x000c9ffe, 0x001ba3f9, 0x0017a2f9, 0x0017a0f9, + 0x00169ef8, 0x00169df7, 0x00159cf6, 0x00149bf5, 0x00139af5, 0x00139af5, 0x00139af5, + 0x00139af5, 0x0060d8f9, 0x005bd9f8, 0x004cadd7, 0x0069ddff, 0x0056ddf8, 0x0055d6fc, + 0x0055d0ff, 0x005cd5ff, 0x0053cbf2, 0x004bcaf6, 0x0043cafa, 0x0047c9f8, 0x004cc8f6, + 0x005ccff1, 0x0046ccf8, 0x0055caff, 0x003ec4fa, 0x0043c3fb, 0x0048c2fd, 0x003ebff4, + 0x0044ccfb, 0x0037b3fc, 0x000b7bdd, 0x00006dc9, 0x000d80d4, 0x004eccff, 0x003ec3fa, + 0x002ec2ff, 0x00a7dea8, 0x00f8ec5b, 0x00f5f570, 0x00f7f66f, 0x00faf76e, 0x00f5f467, + 0x00f1f060, 0x00f6f663, 0x00fbfc65, 0x00f8f95f, 0x00f6f659, 0x00fefe5d, 0x00f7f652, + 0x00f7f54c, 0x00f7f545, 0x00f6f33d, 0x00f6f235, 0x00f3ef2f, 0x00f1eb29, 0x00efe221, + 0x00ecd818, 0x00e5d21a, 0x00f3c700, 0x0052a9b4, 0x0014a4fb, 0x0015a3fb, 0x0017a3fc, + 0x0017a1fa, 0x00179ff8, 0x00169df8, 0x00159cf7, 0x00159bf7, 0x001499f6, 0x001499f6, + 0x001499f6, 0x001499f6, 0x0058cff2, 0x0059ddfd, 0x0055d5f9, 0x005ddeff, 0x004dcef3, + 0x004dcbf3, 0x004cc8f3, 0x0056d2fc, 0x0059d3fd, 0x0050cefb, 0x0047cafa, 0x0048c9f9, + 0x0049c7f9, 0x0051cbf6, 0x0045c9f9, 0x004bc8fd, 0x003fc5f9, 0x0041c4fa, 0x0043c2fb, + 0x003bbdf3, 0x003ac0f4, 0x003ec7fc, 0x003ac6fc, 0x0025a1e3, 0x001f8dd9, 0x0037b9f7, + 0x0026bbfa, 0x002abbf4, 0x00ced857, 0x00f9fa5b, 0x00d9db49, 0x00edec58, 0x00faf560, + 0x00f2ef4d, 0x00e9ea3b, 0x00eeef46, 0x00f2f451, 0x00f9f34f, 0x00edf145, 0x00fef84b, + 0x00f4f542, 0x00f5f43d, 0x00f6f337, 0x00f5f131, 0x00f5ef2b, 0x00f2eb27, 0x00f0e622, + 0x00eedb1d, 0x00ecd117, 0x00f1cc09, 0x00f5c509, 0x000fadff, 0x0017a1f9, 0x0018a1f9, + 0x0018a1f8, 0x0018a0f9, 0x00179ff9, 0x00169df9, 0x00169cf8, 0x00159bf8, 0x001599f8, + 0x001599f8, 0x001599f8, 0x001599f8, 0x0060d5fb, 0x005bd3fb, 0x0056d2fb, 0x0055d1fc, + 0x0055d0fe, 0x0054d0fa, 0x0053d1f6, 0x0051cef7, 0x004ecbf8, 0x004dcbf9, 0x004ccafb, + 0x0049c8fb, 0x0047c6fc, 0x0045c6fb, 0x0043c6fa, 0x0041c6fa, 0x0040c7f9, 0x003fc5f9, + 0x003ec3f9, 0x003fc3fb, 0x0041c4fd, 0x0038baf2, 0x0040c1f8, 0x003dc3fb, 0x003bc5fe, + 0x0037c1f6, 0x0034beef, 0x002ebcf0, 0x00ded722, 0x00bfdc38, 0x00dee142, 0x00ecea4a, + 0x00eae442, 0x00eee942, 0x00f2ee42, 0x00eeed3f, 0x00eaec3d, 0x00fbee3f, 0x00e5ec31, + 0x00fff239, 0x00f2f531, 0x00f4f32e, 0x00f5f12a, 0x00f5ee25, 0x00f4ec21, 0x00f2e71e, + 0x00f0e11c, 0x00eed519, 0x00ecc917, 0x00dec40c, 0x00bbbe39, 0x000798f8, 0x001a9ff8, + 0x001a9ff7, 0x001a9ff5, 0x00189ff7, 0x00179ff9, 0x00179ef9, 0x00169cf9, 0x00169bf9, + 0x001699f9, 0x001699f9, 0x001699f9, 0x001699f9, 0x005cd4f9, 0x0058d4f9, 0x0055d3f9, + 0x0056d2fa, 0x0058d0fb, 0x0056d0f8, 0x0054d0f6, 0x0051cef7, 0x004dccf9, 0x004ccbfa, + 0x004bcafb, 0x0049c8fb, 0x0047c7fb, 0x0045c7fb, 0x0043c6fa, 0x0041c6fa, 0x0040c6f9, + 0x003fc4f9, 0x003ec3f9, 0x003ec2fa, 0x003ec2fb, 0x003abef5, 0x003ec2f8, 0x003bc1f9, + 0x0037c0f9, 0x0036beff, 0x0035bbff, 0x0067bb84, 0x00b0d219, 0x00b4d31a, 0x00d3da39, + 0x00e2dd3d, 0x00d6d532, 0x00e1df38, 0x00ece93e, 0x00e1e636, 0x00e9e536, 0x00f1e634, + 0x00e5e42b, 0x00f6e62e, 0x00e9eb29, 0x00f0ee2a, 0x00f0e824, 0x00ece420, 0x00e9e01d, + 0x00ebdb1c, 0x00edd71c, 0x00e9ce19, 0x00e5c516, 0x00e7c004, 0x006cb292, 0x00109dfc, + 0x0018a1f7, 0x001aa0f5, 0x001ca0f3, 0x0019a0f6, 0x00179ff9, 0x00169ef9, 0x00169cf9, + 0x00159bf8, 0x00159af8, 0x001499f8, 0x001499f7, 0x001499f7, 0x0058d4f6, 0x0056d4f6, + 0x0054d5f7, 0x0057d3f7, 0x005bd1f8, 0x0058d0f6, 0x0054cff5, 0x0050cef8, 0x004dcdfa, + 0x004bcbfb, 0x004acafb, 0x0048c9fb, 0x0046c7fb, 0x0045c7fa, 0x0043c7fa, 0x0042c6fa, + 0x0040c6f9, 0x003fc4f9, 0x003ec3f9, 0x003dc1f9, 0x003cc0f9, 0x003cc1f8, 0x003cc2f7, + 0x0038bff6, 0x0034bbf5, 0x0035bdfd, 0x0037beff, 0x0046bcfc, 0x0082c92c, 0x00a0be02, + 0x00b8c420, 0x00d8cf31, 0x00d2d632, 0x00d4d52e, 0x00d7d42a, 0x00cdd725, 0x00e9df2f, + 0x00e6dd2a, 0x00e4dc25, 0x00edd922, 0x00e0e220, 0x00ede927, 0x00eae01e, 0x00e4da1c, + 0x00ded319, 0x00e5d01a, 0x00ebcd1b, 0x00e5c818, 0x00dec214, 0x00f0bc00, 0x001da5eb, + 0x0019a1ff, 0x0016a2f7, 0x0019a2f4, 0x001ea2f1, 0x001aa0f5, 0x00169ff9, 0x00169ef8, + 0x00159df8, 0x00159cf8, 0x00149bf8, 0x00139af7, 0x001299f6, 0x001299f6, 0x005ed5f9, + 0x0063d6fc, 0x0068d6ff, 0x005fd3fc, 0x0056d0f8, 0x0053cff8, 0x0051cef8, 0x004ecdf9, + 0x004bccfb, 0x004acbfb, 0x0048cafb, 0x0047c9fa, 0x0046c8fb, 0x0044c7fa, 0x0043c7fa, + 0x0042c6fa, 0x0040c5f9, 0x003fc4f9, 0x003ec3f9, 0x003dc1f9, 0x003cc0f9, 0x003bc1f9, + 0x003bc1f8, 0x0038bff7, 0x0036bdf7, 0x0035bdfa, 0x0034bdfe, 0x0022c3f6, 0x0027bbfc, + 0x0053b0b2, 0x009bc606, 0x00c1d322, 0x00d3dd36, 0x00b4ba12, 0x00c4c71f, 0x00c5cf22, + 0x00d9d82d, 0x00dfdb30, 0x00dcd52b, 0x00e8d520, 0x00d5d51c, 0x00e8e428, 0x00ece324, + 0x00d1ce1f, 0x00d3c51d, 0x00dcc302, 0x00cfc312, 0x00e3c209, 0x00e3be00, 0x0084bf6e, + 0x000ca0f6, 0x00129ffd, 0x0018a2f6, 0x0019a1f5, 0x001ba1f4, 0x0018a0f6, 0x00169ff8, + 0x00159ef8, 0x00159df8, 0x00149cf7, 0x00139bf7, 0x00129af6, 0x001098f4, 0x001098f4, + 0x0065d7fb, 0x005dd4fa, 0x0056d2f8, 0x0053d0f9, 0x0050cff9, 0x004fcef9, 0x004dcdfa, + 0x004bcdfa, 0x004accfb, 0x0048cbfb, 0x0047cafb, 0x0046c9fa, 0x0045c8fa, 0x0044c7fa, + 0x0043c7fa, 0x0042c6fa, 0x0040c5fa, 0x003fc4f9, 0x003ec3f9, 0x003dc1f9, 0x003bc0f9, + 0x003ac0f9, 0x0039c0f9, 0x0038bff9, 0x0037bff9, 0x0034bef8, 0x0031bcf7, 0x0033bbf8, + 0x0035bbfa, 0x002cbcff, 0x0061c2df, 0x0093cb85, 0x00c5d52b, 0x00cbd82f, 0x00b0bb13, + 0x00b5be17, 0x00b9c21b, 0x00c7c826, 0x00c5bf21, 0x00dbc817, 0x00cac819, 0x00dbd722, + 0x00ddd61a, 0x00b7bd0d, 0x00c8bd04, 0x00d0c000, 0x00adc951, 0x006cb8b1, 0x0004a3ff, + 0x0013a4fb, 0x0021a4f5, 0x001ea3f5, 0x001aa1f6, 0x0019a1f6, 0x0018a0f7, 0x0017a0f7, + 0x00169ff8, 0x00159ef7, 0x00149ef7, 0x00139df7, 0x00139cf6, 0x00119af4, 0x000f98f2, + 0x000f98f2, 0x005cd5f9, 0x0058d3f8, 0x0053d1f8, 0x0052d0f9, 0x0050cff9, 0x004ecefa, + 0x004ccdfa, 0x004accfa, 0x0048ccfa, 0x0047cbfa, 0x0046cafa, 0x0045c9fa, 0x0044c8fa, + 0x0043c7fa, 0x0042c7fa, 0x0041c6fa, 0x0040c5fa, 0x003fc4f9, 0x003ec2f9, 0x003cc1f9, + 0x003bc0f9, 0x003ac0f9, 0x0038bff9, 0x0037bff9, 0x0036bff9, 0x0035bdf6, 0x0034bbf3, + 0x0035b9f7, 0x0035b8fb, 0x0022b5ff, 0x002fb5ff, 0x004dbae6, 0x006bbfce, 0x0027b1c5, + 0x006cbc7c, 0x008abd49, 0x00a7be15, 0x00b9bf09, 0x00ccc000, 0x00dac43d, 0x00bbca20, + 0x00aec73e, 0x0099bc54, 0x005aad8b, 0x0036abc4, 0x0004b3ff, 0x0015a7ff, 0x0021a4ff, + 0x0019a0fb, 0x001ba2fa, 0x001da4f9, 0x001ba3f8, 0x001aa1f7, 0x0019a1f7, 0x0018a0f7, + 0x0017a0f7, 0x00169ff8, 0x00159ef7, 0x00149ef7, 0x00139df7, 0x00129cf6, 0x00119af5, + 0x000f99f3, 0x000f99f3, 0x0053d2f6, 0x0052d1f7, 0x0051d1f8, 0x0050d0f9, 0x004fcffa, + 0x004dcefa, 0x004bcdfa, 0x0049ccfa, 0x0047cbfa, 0x0046caf9, 0x0045caf9, 0x0044c9f9, + 0x0044c8fa, 0x0043c7fa, 0x0042c6f9, 0x0041c6f9, 0x0040c5fa, 0x003fc4f9, 0x003dc2f9, + 0x003cc1f9, 0x003ac0f9, 0x0039c0f9, 0x0038bff9, 0x0036bff9, 0x0035bef8, 0x0036bcf4, + 0x0038baf0, 0x0036b8f6, 0x0034b5fc, 0x002cb6f9, 0x0023b7f6, 0x0025b5fa, 0x0028b4ff, + 0x0028b6ff, 0x0029b7ff, 0x001fb5ff, 0x0015b2ff, 0x0020aef7, 0x003cb9ff, 0x005acbf0, + 0x0042befa, 0x002ab6fc, 0x0012adff, 0x0018acfc, 0x001eacfa, 0x001ea9fd, 0x001ea7ff, + 0x001ba8fa, 0x0018a8f4, 0x0018a6f8, 0x0018a4fd, 0x0019a3fa, 0x001aa1f7, 0x0019a1f7, + 0x0018a0f8, 0x0017a0f8, 0x00169ff8, 0x00159ef7, 0x00149df7, 0x00139cf6, 0x00129bf6, + 0x00119af5, 0x001099f4, 0x001099f4, 0x0054d1f8, 0x0052d1f8, 0x0051d0f9, 0x004fcff9, + 0x004ecffa, 0x004ccefa, 0x004acdf9, 0x0048ccf9, 0x0045cbf9, 0x0045caf9, 0x0044c9f9, + 0x0043c8f9, 0x0043c8f9, 0x0042c7f9, 0x0042c6f9, 0x0041c5f9, 0x0040c5fa, 0x003fc4f9, + 0x003dc2f9, 0x003bc1f9, 0x003ac0fa, 0x0038bff9, 0x0037bff9, 0x0036bef9, 0x0034bef8, + 0x0035bcf6, 0x0035baf5, 0x0034b8f8, 0x0033b6fc, 0x002eb6f9, 0x0029b6f7, 0x0029b5f8, + 0x002ab4fa, 0x002ab5fb, 0x002ab5fc, 0x002ab2f6, 0x002aafef, 0x001ba9f6, 0x009bcfd9, + 0x006dcfe9, 0x0074c7e4, 0x0080c9dd, 0x0019adfb, 0x001cacf9, 0x001fabf8, 0x001fa9f9, + 0x001ea7fb, 0x001ca7f9, 0x001aa7f6, 0x001aa5f8, 0x001aa4fb, 0x001aa3fa, 0x001aa2f8, + 0x0019a1f8, 0x0018a0f8, 0x0017a0f8, 0x00169ff8, 0x00159ef7, 0x00149df7, 0x00139cf6, + 0x00129bf6, 0x00119bf5, 0x00119af5, 0x00119af5, 0x0055d0f9, 0x0053d0fa, 0x0051d0fa, + 0x004fcffa, 0x004dcffa, 0x004bcefa, 0x0049cdf9, 0x0046ccf9, 0x0044caf8, 0x0043caf8, + 0x0043c9f8, 0x0043c8f9, 0x0042c8f9, 0x0042c7f9, 0x0041c6f9, 0x0041c6f9, 0x0040c5fa, + 0x003ec3f9, 0x003dc2fa, 0x003bc1fa, 0x0039c0fa, 0x0038bff9, 0x0036bff9, 0x0035bef9, + 0x0034bdf8, 0x0033bcf9, 0x0033bafa, 0x0032b9fb, 0x0032b8fc, 0x0030b7fa, 0x002eb6f8, + 0x002db5f7, 0x002bb4f5, 0x002bb4f6, 0x002bb3f7, 0x0029b2f9, 0x0028b2fc, 0x0030b2f7, + 0x0012a8fe, 0x007fd4e1, 0x0058bbe6, 0x0015aafb, 0x001fadf8, 0x0020acf7, 0x0020aaf5, + 0x001fa9f6, 0x001ea8f7, 0x001da6f7, 0x001ca5f8, 0x001ca4f8, 0x001ba3f9, 0x001ba3f9, + 0x001ba2f9, 0x0019a1f9, 0x0018a0f8, 0x0017a0f8, 0x00169ff8, 0x00159ef7, 0x00149df7, + 0x00139cf6, 0x00129bf5, 0x00129bf5, 0x00129bf5, 0x00129bf5, 0x0055d0f9, 0x0053d0fa, + 0x0051d0fa, 0x004fcffa, 0x004dcffa, 0x004bcefa, 0x0049cdf9, 0x0046ccf9, 0x0044caf8, + 0x0043caf8, 0x0043c9f8, 0x0043c8f9, 0x0042c8f9, 0x0042c7f9, 0x0041c6f9, 0x0041c6f9, + 0x0040c5fa, 0x003ec3f9, 0x003dc2fa, 0x003bc1fa, 0x0039c0fa, 0x0038bff9, 0x0036bff9, + 0x0035bef9, 0x0034bdf8, 0x0033bcf9, 0x0033bafa, 0x0032b9fb, 0x0032b8fc, 0x0030b7fa, + 0x002eb6f8, 0x002db5f7, 0x002bb4f5, 0x002bb4f6, 0x002bb3f7, 0x002ab2f8, 0x0029b2fa, + 0x002db6f5, 0x001db5f6, 0x00239bff, 0x0020b6f3, 0x000cacfb, 0x001eacf7, 0x001fabf6, + 0x0020aaf5, 0x001fa9f6, 0x001ea8f7, 0x001da6f7, 0x001ca5f8, 0x001ca4f8, 0x001ba3f9, + 0x001ba3f9, 0x001ba2f9, 0x0019a1f9, 0x0018a0f8, 0x0017a0f8, 0x00169ff8, 0x00159ef7, + 0x00149df7, 0x00139cf6, 0x00129bf5, 0x00129bf5, 0x00129bf5, 0x00129bf5, 0x0055d0f9, + 0x0053d0fa, 0x0051d0fa, 0x004fcffa, 0x004dcffa, 0x004bcefa, 0x0049cdf9, 0x0046ccf9, + 0x0044caf8, 0x0043caf8, 0x0043c9f8, 0x0043c8f9, 0x0042c8f9, 0x0042c7f9, 0x0041c6f9, + 0x0041c6f9, 0x0040c5fa, 0x003ec3f9, 0x003dc2fa, 0x003bc1fa, 0x0039c0fa, 0x0038bff9, + 0x0036bff9, 0x0035bef9, 0x0034bdf8, 0x0033bcf9, 0x0033bafa, 0x0032b9fb, 0x0032b8fc, + 0x0030b7fa, 0x002eb6f8, 0x002db5f7, 0x002bb4f5, 0x002bb4f6, 0x002bb3f7, 0x002bb2f8, + 0x002bb1f8, 0x0022aff9, 0x0019acfa, 0x001eadf7, 0x0024aef3, 0x0020adf5, 0x001dabf6, + 0x001fabf6, 0x0020aaf5, 0x001fa9f6, 0x001ea8f7, 0x001da6f7, 0x001ca5f8, 0x001ca4f8, + 0x001ba3f9, 0x001ba3f9, 0x001ba2f9, 0x0019a1f9, 0x0018a0f8, 0x0017a0f8, 0x00169ff8, + 0x00159ef7, 0x00149df7, 0x00139cf6, 0x00129bf5, 0x00129bf5, 0x00129bf5, 0x00129bf5, + 0x0055d0f9, 0x0053d0fa, 0x0051d0fa, 0x004fcffa, 0x004dcffa, 0x004bcefa, 0x0049cdf9, + 0x0046ccf9, 0x0044caf8, 0x0043caf8, 0x0043c9f8, 0x0043c8f9, 0x0042c8f9, 0x0042c7f9, + 0x0041c6f9, 0x0041c6f9, 0x0040c5fa, 0x003ec3f9, 0x003dc2fa, 0x003bc1fa, 0x0039c0fa, + 0x0038bff9, 0x0036bff9, 0x0035bef9, 0x0034bdf8, 0x0033bcf9, 0x0033bafa, 0x0032b9fb, + 0x0032b8fc, 0x0030b7fa, 0x002eb6f8, 0x002db5f7, 0x002bb4f5, 0x002bb4f6, 0x002bb3f7, + 0x002bb2f8, 0x002bb1f8, 0x0022aff9, 0x0019acfa, 0x001eadf7, 0x0024aef3, 0x0020adf5, + 0x001dabf6, 0x001fabf6, 0x0020aaf5, 0x001fa9f6, 0x001ea8f7, 0x001da6f7, 0x001ca5f8, + 0x001ca4f8, 0x001ba3f9, 0x001ba3f9, 0x001ba2f9, 0x0019a1f9, 0x0018a0f8, 0x0017a0f8, + 0x00169ff8, 0x00159ef7, 0x00149df7, 0x00139cf6, 0x00129bf5, 0x00129bf5, 0x00129bf5, + 0x00129bf5 + }; + +#define IMG_WIDTH 64ULL +#define IMG_HEIGHT 64ULL +#define FORMAT_SIZE 4ULL +#define FORMAT PIXEL_FORMAT_XRGB32 + +static INLINE size_t fuzzyCompare(BYTE b1, BYTE b2) +{ + if (b1 > b2) + return b1 - b2; + return b2 - b1; +} + +static BOOL fuzzyCompareImage(const UINT32* crefImage, const BYTE* img, size_t npixels) +{ + size_t totalDelta = 0; + + for (size_t i = 0; i < npixels; i++, crefImage++) + { + BYTE A = *img++; + BYTE R = *img++; + BYTE G = *img++; + BYTE B = *img++; + size_t delta = 0; + + if (A != 0x00) + return FALSE; + + delta = fuzzyCompare(R, (*crefImage & 0x00ff0000) >> 16); + if (delta > 1) + return FALSE; + totalDelta += delta; + + delta = fuzzyCompare(G, (*crefImage & 0x0000ff00) >> 8); + if (delta > 1) + return FALSE; + totalDelta += delta; + + delta = fuzzyCompare(B, (*crefImage & 0x0000ff)); + if (delta > 1) + return FALSE; + totalDelta += delta; + } + + WLog_DBG("test", "totalDelta=%d (npixels=%d)", totalDelta, npixels); + return TRUE; +} + +int TestFreeRDPCodecRemoteFX(int argc, char* argv[]) +{ + int rc = -1; + REGION16 region = { 0 }; + RFX_CONTEXT* context = NULL; + BYTE* dest = NULL; + size_t stride = FORMAT_SIZE * IMG_WIDTH; + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + /* use default threading options here, pass zero as + * ThreadingFlags */ + context = rfx_context_new(FALSE); + if (!context) + goto fail; + + dest = calloc(IMG_WIDTH * IMG_HEIGHT, FORMAT_SIZE); + if (!dest) + goto fail; + + region16_init(®ion); + if (!rfx_process_message(context, encodeHeaderSample, sizeof(encodeHeaderSample), 0, 0, dest, + FORMAT, stride, IMG_HEIGHT, ®ion)) + goto fail; + + region16_clear(®ion); + if (!rfx_process_message(context, encodeDataSample, sizeof(encodeDataSample), 0, 0, dest, + FORMAT, stride, IMG_HEIGHT, ®ion)) + goto fail; + region16_print(®ion); + +#if 0 + FILE *f = fopen("/tmp/windows.data", "w"); + if (f) { + fwrite(dest, IMG_WIDTH * IMG_HEIGHT, FORMAT_SIZE, f); + fclose(f); + } +#endif + + if (!fuzzyCompareImage(srefImage, dest, IMG_WIDTH * IMG_HEIGHT)) + goto fail; + + rc = 0; +fail: + region16_uninit(®ion); + rfx_context_free(context); + free(dest); + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecXCrush.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecXCrush.c new file mode 100644 index 0000000000000000000000000000000000000000..5b13532c2202325bb89f20890f022d2eb6070371 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecXCrush.c @@ -0,0 +1,130 @@ +#include +#include + +#include "../xcrush.h" + +static const BYTE TEST_BELLS_DATA[] = "for.whom.the.bell.tolls,.the.bell.tolls.for.thee!"; + +static const BYTE TEST_BELLS_DATA_XCRUSH[] = + "\x12\x00\x66\x6f\x72\x2e\x77\x68\x6f\x6d\x2e\x74\x68\x65\x2e\x62" + "\x65\x6c\x6c\x2e\x74\x6f\x6c\x6c\x73\x2c\x2e\x74\x68\x65\x2e\x62" + "\x65\x6c\x6c\x2e\x74\x6f\x6c\x6c\x73\x2e\x66\x6f\x72\x2e\x74\x68" + "\x65"; + +static const BYTE TEST_ISLAND_DATA[] = "No man is an island entire of itself; every man " + "is a piece of the continent, a part of the main; " + "if a clod be washed away by the sea, Europe " + "is the less, as well as if a promontory were, as" + "well as any manner of thy friends or of thine " + "own were; any man's death diminishes me, " + "because I am involved in mankind. " + "And therefore never send to know for whom " + "the bell tolls; it tolls for thee."; + +static const BYTE TEST_ISLAND_DATA_XCRUSH[] = + "\x12\x61\x4e\x6f\x20\x6d\x61\x6e\x20\x69\x73\x20\xf8\xd2\xd8\xc2" + "\xdc\xc8\x40\xca\xdc\xe8\xd2\xe4\xca\x40\xde\xcc\x40\xd2\xe8\xe6" + "\xca\xd8\xcc\x76\x40\xca\xec\xca\xe4\xf3\xfa\x71\x20\x70\x69\x65" + "\x63\xfc\x12\xe8\xd0\xca\x40\xc6\xdf\xfb\xcd\xdf\xd0\x58\x40\xc2" + "\x40\xe0\xc2\xe4\xe9\xfe\x63\xec\xc3\x6b\x0b\x4b\x71\xd9\x03\x4b" + "\x37\xd7\x31\xb6\x37\xb2\x10\x31\x32\x90\x3b\xb0\xb9\xb4\x32\xb2" + "\x10\x30\xbb\xb0\xbc\x90\x31\x3c\x90\x7e\x68\x73\x65\x61\x2c\x20" + "\x45\x75\x72\x6f\x70\x65\xf2\x34\x7d\x38\x6c\x65\x73\x73\xf0\x69" + "\xcc\x81\xdd\x95\xb1\xb0\x81\x85\xcf\xc0\x94\xe0\xe4\xde\xdb\xe2" + "\xb3\x7f\x92\x4e\xec\xae\x4c\xbf\x86\x3f\x06\x0c\x2d\xde\x5d\x96" + "\xe6\x57\x2f\x1e\x53\xc9\x03\x33\x93\x4b\x2b\x73\x23\x99\x03\x7f" + "\xd2\xb6\x96\xef\x38\x1d\xdb\xbc\x24\x72\x65\x3b\xf5\x5b\xf8\x49" + "\x3b\x99\x03\x23\x2b\x0b\xa3\x41\x03\x23\x4b\x6b\x4b\x73\x4f\x96" + "\xce\x64\x0d\xbe\x19\x31\x32\xb1\xb0\xba\xb9\xb2\x90\x24\x90\x30" + "\xb6\x90\x34\xb7\x3b\x37\xb6\x3b\x79\xd4\xd2\xdd\xec\x18\x6b\x69" + "\x6e\x64\x2e\x20\x41\xf7\x33\xcd\x47\x26\x56\x66\xff\x74\x9b\xbd" + "\xbf\x04\x0e\x7e\x31\x10\x3a\x37\x90\x35\xb7\x37\xbb\x90\x7d\x81" + "\x03\xbb\x43\x7b\x6f\xa8\xe5\x8b\xd0\xf0\xe8\xde\xd8\xd8\xe7\xec" + "\xf3\xa7\xe4\x7c\xa7\xe2\x9f\x01\x99\x4b\x80"; + +static void test_dump(const char* fkt, const void* generated, size_t generated_size, + const void* expected, size_t expected_size) +{ + printf("[%s] output size mismatch: Actual: %" PRIuz ", Expected: %" PRIuz "\n", fkt, + generated_size, expected_size); + printf("[%s] Actual\n", fkt); + BitDump(fkt, WLOG_INFO, generated, generated_size * 8ull, 0); + printf("[%s] Expected\n", fkt); + BitDump(fkt, WLOG_INFO, expected, expected_size * 8ull, 0); +} + +static BOOL test_compare(const char* fkt, const void* generated, size_t generated_size, + const void* expected, size_t expected_size) +{ + if (generated_size != expected_size) + { + test_dump(fkt, generated, generated_size, expected, expected_size); + return FALSE; + } + + if (memcmp(generated, expected, generated_size) != 0) + { + test_dump(fkt, generated, generated_size, expected, expected_size); + return FALSE; + } + + return TRUE; +} + +static BOOL test_run(const char* fkt, const void* src, UINT32 src_size, const void* expected, + size_t expected_size) +{ + BOOL rc = FALSE; + int status = -1; + UINT32 Flags = 0; + const BYTE* pDstData = NULL; + BYTE OutputBuffer[65536] = { 0 }; + UINT32 DstSize = sizeof(OutputBuffer); + XCRUSH_CONTEXT* xcrush = xcrush_context_new(TRUE); + if (!xcrush) + return -1; + status = xcrush_compress(xcrush, src, src_size, OutputBuffer, &pDstData, &DstSize, &Flags); + printf("[%s] status: %d Flags: 0x%08" PRIX32 " DstSize: %" PRIu32 "\n", fkt, status, Flags, + DstSize); + + rc = test_compare(fkt, pDstData, DstSize, expected, expected_size); + + xcrush_context_free(xcrush); + return rc; +} + +struct test_argument +{ + const char* name; + const void* src; + UINT32 src_size; + const void* expected; + size_t expected_size; +}; + +static const struct test_argument tests[] = { + { "XCrushCompressIsland", TEST_ISLAND_DATA, sizeof(TEST_ISLAND_DATA) - 1, + TEST_ISLAND_DATA_XCRUSH, sizeof(TEST_ISLAND_DATA_XCRUSH) - 1 } +#if 0 + ,{ "XCrushCompressBells", TEST_BELLS_DATA, sizeof(TEST_BELLS_DATA) - 1, TEST_BELLS_DATA_XCRUSH, + sizeof(TEST_BELLS_DATA_XCRUSH) - 1 } +#endif +}; + +int TestFreeRDPCodecXCrush(int argc, char* argv[]) +{ + int rc = 0; + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + for (size_t x = 0; x < ARRAYSIZE(tests); x++) + { + const struct test_argument* arg = &tests[x]; + + if (!test_run(arg->name, arg->src, arg->src_size, arg->expected, arg->expected_size)) + rc = -1; + } + + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecZGfx.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecZGfx.c new file mode 100644 index 0000000000000000000000000000000000000000..68db553ddbd02a83123ed90b30425b23e0e6f083 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPCodecZGfx.c @@ -0,0 +1,274 @@ +#include +#include +#include + +#include +#include +#include + +/* Sample from [MS-RDPEGFX] */ +static const BYTE TEST_FOX_DATA[] = "The quick brown " + "fox jumps over t" + "he lazy dog"; + +static const BYTE TEST_FOX_DATA_SINGLE[] = + "\xE0\x04\x54\x68\x65\x20\x71\x75\x69\x63\x6B\x20\x62\x72\x6F\x77" + "\x6E\x20\x66\x6F\x78\x20\x6A\x75\x6D\x70\x73\x20\x6F\x76\x65\x72" + "\x20\x74\x68\x65\x20\x6C\x61\x7A\x79\x20\x64\x6F\x67"; + +static const BYTE TEST_FOX_DATA_MULTIPART[] = + "\xE1\x03\x00\x2B\x00\x00\x00\x11\x00\x00\x00\x04\x54\x68\x65\x20" + "\x71\x75\x69\x63\x6B\x20\x62\x72\x6F\x77\x6E\x20\x0E\x00\x00\x00" + "\x04\x66\x6F\x78\x20\x6A\x75\x6D\x70\x73\x20\x6F\x76\x65\x10\x00" + "\x00\x00\x24\x39\x08\x0E\x91\xF8\xD8\x61\x3D\x1E\x44\x06\x43\x79" + "\x9C\x02"; + +static int test_ZGfxCompressFox(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + const BYTE* pSrcData = NULL; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + BYTE* pDstData = NULL; + ZGFX_CONTEXT* zgfx = NULL; + UINT32 expectedSize = 0; + zgfx = zgfx_context_new(TRUE); + + if (!zgfx) + return -1; + + SrcSize = sizeof(TEST_FOX_DATA) - 1; + pSrcData = (const BYTE*)TEST_FOX_DATA; + Flags = 0; + expectedSize = sizeof(TEST_FOX_DATA_SINGLE) - 1; + status = zgfx_compress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, &Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("test_ZGfxCompressFox: output size mismatch: Actual: %" PRIu32 ", Expected: %" PRIu32 + "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_FOX_DATA_SINGLE, DstSize) != 0) + { + printf("test_ZGfxCompressFox: output mismatch\n"); + printf("Actual\n"); + BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0); + printf("Expected\n"); + BitDump(__func__, WLOG_INFO, TEST_FOX_DATA_SINGLE, DstSize * 8, 0); + goto fail; + } + + rc = 0; +fail: + free(pDstData); + zgfx_context_free(zgfx); + return rc; +} + +static int test_ZGfxDecompressFoxSingle(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + const BYTE* pSrcData = NULL; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + BYTE* pDstData = NULL; + ZGFX_CONTEXT* zgfx = NULL; + UINT32 expectedSize = 0; + zgfx = zgfx_context_new(TRUE); + + if (!zgfx) + return -1; + + SrcSize = sizeof(TEST_FOX_DATA_SINGLE) - 1; + pSrcData = (const BYTE*)TEST_FOX_DATA_SINGLE; + Flags = 0; + expectedSize = sizeof(TEST_FOX_DATA) - 1; + status = zgfx_decompress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_FOX_DATA, DstSize) != 0) + { + printf("test_ZGfxDecompressFoxSingle: output mismatch\n"); + printf("Actual\n"); + BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0); + printf("Expected\n"); + BitDump(__func__, WLOG_INFO, TEST_FOX_DATA, DstSize * 8, 0); + goto fail; + } + + rc = 0; +fail: + free(pDstData); + zgfx_context_free(zgfx); + return rc; +} + +static int test_ZGfxDecompressFoxMultipart(void) +{ + int rc = -1; + int status = 0; + UINT32 Flags = 0; + const BYTE* pSrcData = NULL; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + BYTE* pDstData = NULL; + ZGFX_CONTEXT* zgfx = NULL; + UINT32 expectedSize = 0; + zgfx = zgfx_context_new(TRUE); + + if (!zgfx) + return -1; + + SrcSize = sizeof(TEST_FOX_DATA_MULTIPART) - 1; + pSrcData = (const BYTE*)TEST_FOX_DATA_MULTIPART; + Flags = 0; + expectedSize = sizeof(TEST_FOX_DATA) - 1; + status = zgfx_decompress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + printf("flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, TEST_FOX_DATA, DstSize) != 0) + { + printf("test_ZGfxDecompressFoxSingle: output mismatch\n"); + printf("Actual\n"); + BitDump(__func__, WLOG_INFO, pDstData, DstSize * 8, 0); + printf("Expected\n"); + BitDump(__func__, WLOG_INFO, TEST_FOX_DATA, DstSize * 8, 0); + goto fail; + } + + rc = 0; +fail: + free(pDstData); + zgfx_context_free(zgfx); + return rc; +} + +static int test_ZGfxCompressConsistent(void) +{ + int rc = -1; + int status = 0; + + UINT32 Flags = 0; + const BYTE* pSrcData = NULL; + UINT32 SrcSize = 0; + UINT32 DstSize = 0; + BYTE* pDstData = NULL; + UINT32 DstSize2 = 0; + BYTE* pDstData2 = NULL; + ZGFX_CONTEXT* zgfx = NULL; + UINT32 expectedSize = 0; + BYTE BigBuffer[65536]; + memset(BigBuffer, 0xaa, sizeof(BigBuffer)); + memcpy(BigBuffer, TEST_FOX_DATA, sizeof(TEST_FOX_DATA) - 1); + zgfx = zgfx_context_new(TRUE); + + if (!zgfx) + return -1; + + /* Compress */ + expectedSize = SrcSize = sizeof(BigBuffer); + pSrcData = (const BYTE*)BigBuffer; + Flags = 0; + status = zgfx_compress(zgfx, pSrcData, SrcSize, &pDstData2, &DstSize2, &Flags); + + if (status < 0) + goto fail; + + printf("Compress: flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize2); + /* Decompress */ + status = zgfx_decompress(zgfx, pDstData2, DstSize2, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + printf("Decompress: flags: 0x%08" PRIX32 " size: %" PRIu32 "\n", Flags, DstSize); + + if (DstSize != expectedSize) + { + printf("test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %" PRIu32 + ", Expected: %" PRIu32 "\n", + DstSize, expectedSize); + goto fail; + } + + if (memcmp(pDstData, BigBuffer, DstSize) != 0) + { + printf("test_ZGfxDecompressFoxSingle: output mismatch\n"); + printf("Actual\n"); + BitDump(__func__, WLOG_INFO, pDstData, 64 * 8, 0); + printf("...\n"); + BitDump(__func__, WLOG_INFO, pDstData + DstSize - 64, 64 * 8, 0); + printf("Expected\n"); + BitDump(__func__, WLOG_INFO, BigBuffer, 64 * 8, 0); + printf("...\n"); + BitDump(__func__, WLOG_INFO, BigBuffer + DstSize - 64, 64 * 8, 0); + printf("Middle Result\n"); + BitDump(__func__, WLOG_INFO, pDstData2, 64 * 8, 0); + printf("...\n"); + BitDump(__func__, WLOG_INFO, pDstData2 + DstSize2 - 64, 64 * 8, 0); + goto fail; + } + + rc = 0; +fail: + free(pDstData); + free(pDstData2); + zgfx_context_free(zgfx); + return rc; +} + +int TestFreeRDPCodecZGfx(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (test_ZGfxCompressFox() < 0) + return -1; + + if (test_ZGfxDecompressFoxSingle() < 0) + return -1; + + if (test_ZGfxDecompressFoxMultipart() < 0) + return -1; + + if (test_ZGfxCompressConsistent() < 0) + return -1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPRegion.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPRegion.c new file mode 100644 index 0000000000000000000000000000000000000000..e8a18573e6b998f7f59756fea2636aae91719d11 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFreeRDPRegion.c @@ -0,0 +1,876 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2014 Thincast Technologies GmbH + * Copyright 2014 Hardening + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +static BOOL compareRectangles(const RECTANGLE_16* src1, const RECTANGLE_16* src2, int nb) +{ + for (int i = 0; i < nb; i++, src1++, src2++) + { + if (memcmp(src1, src2, sizeof(RECTANGLE_16)) != 0) + { + (void)fprintf(stderr, + "expecting rect %d (%" PRIu16 ",%" PRIu16 "-%" PRIu16 ",%" PRIu16 + ") and have (%" PRIu16 ",%" PRIu16 "-%" PRIu16 ",%" PRIu16 ")\n", + i, src2->left, src2->top, src2->right, src2->bottom, src1->left, + src1->top, src1->right, src1->bottom); + return FALSE; + } + } + + return TRUE; +} + +static int test_basic(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + /* R1 + R2 ==> disjointed rects */ + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r2 = { 150, 301, 250, 401 }; + RECTANGLE_16 r1_r2[] = { { 0, 101, 200, 201 }, { 150, 301, 250, 401 } }; + /* r1 */ + region16_init(®ion); + + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 1 || memcmp(rects, &r1, sizeof(RECTANGLE_16)) != 0) + goto out; + + /* r1 + r2 */ + if (!region16_union_rect(®ion, ®ion, &r2)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 2 || + !compareRectangles(rects, r1_r2, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + /* clear region */ + region16_clear(®ion); + region16_rects(®ion, &nbRects); + + if (nbRects) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r1_r3(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r3 = { 150, 151, 250, 251 }; + RECTANGLE_16 r1_r3[] = { { 0, 101, 200, 151 }, { 0, 151, 250, 201 }, { 150, 201, 250, 251 } }; + region16_init(®ion); + /* + * +=============================================================== + * | + * |+-----+ +-----+ + * || r1 | | | + * || +-+------+ +-----+--------+ + * || | r3 | | | + * |+---+ | ====> +-----+--------+ + * | | | | | + * | +--------+ +--------+ + */ + + /* R1 + R3 */ + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r3)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 3 || + !compareRectangles(rects, r1_r3, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + /* R3 + R1 */ + region16_clear(®ion); + + if (!region16_union_rect(®ion, ®ion, &r3)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 3 || + !compareRectangles(rects, r1_r3, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r9_r10(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + /* + * +=============================================================== + * | + * | +---+ +---+ + * |+--|r10|-+ +--+---+-+ + * ||r9| | | | | + * || | | | | | + * || | | | =====> | | + * || | | | | | + * || | | | | | + * |+--| |-+ +--+---+-+ + * | +---+ +---+ + */ + RECTANGLE_16 r9 = { 0, 100, 400, 200 }; + RECTANGLE_16 r10 = { 200, 0, 300, 300 }; + RECTANGLE_16 r9_r10[] = { + { 200, 0, 300, 100 }, + { 0, 100, 400, 200 }, + { 200, 200, 300, 300 }, + }; + region16_init(®ion); + + if (!region16_union_rect(®ion, ®ion, &r9)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r10)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 3 || + !compareRectangles(rects, r9_r10, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r1_r5(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r5 = { 150, 121, 300, 131 }; + RECTANGLE_16 r1_r5[] = { { 0, 101, 200, 121 }, { 0, 121, 300, 131 }, { 0, 131, 200, 201 } }; + region16_init(®ion); + + /* + * +=============================================================== + * | + * |+--------+ +--------+ + * || r1 | | | + * || +--+----+ +--------+----+ + * || | r5 | =====> | | + * || +-------+ +--------+----+ + * || | | | + * |+--------+ +--------+ + * | + * + */ + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r5)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 3 || + !compareRectangles(rects, r1_r5, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r1_r6(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r6 = { 150, 121, 170, 131 }; + region16_init(®ion); + /* + * +=============================================================== + * | + * |+--------+ +--------+ + * || r1 | | | + * || +--+ | | | + * || |r6| | =====> | | + * || +--+ | | | + * || | | | + * |+--------+ +--------+ + * | + */ + region16_clear(®ion); + + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r6)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 1 || + !compareRectangles(rects, &r1, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r1_r2_r4(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r2 = { 150, 301, 250, 401 }; + RECTANGLE_16 r4 = { 150, 251, 250, 301 }; + RECTANGLE_16 r1_r2_r4[] = { { 0, 101, 200, 201 }, { 150, 251, 250, 401 } }; + /* + * +=============================================================== + * | + * |+-----+ +-----+ + * || r1 | | | + * || | | | + * || | | | + * |+-----+ ====> +-----+ + * | + * | +--------+ +--------+ + * | | r4 | | | + * | +--------+ | | + * | | r2 | | | + * | | | | | + * | +--------+ +--------+ + * + */ + region16_init(®ion); + + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r2)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r4)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 2 || + !compareRectangles(rects, r1_r2_r4, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r1_r7_r8(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r7 = { 300, 101, 500, 201 }; + RECTANGLE_16 r8 = { 150, 121, 400, 131 }; + RECTANGLE_16 r1_r7_r8[] = { + { 0, 101, 200, 121 }, { 300, 101, 500, 121 }, { 0, 121, 500, 131 }, + { 0, 131, 200, 201 }, { 300, 131, 500, 201 }, + }; + /* + * +=============================================================== + * | + * |+--------+ +--------+ +--------+ +--------+ + * || r1 | | r7 | | | | | + * || +------------+ | +--------+---+--------+ + * || | r8 | | =====> | | + * || +------------+ | +--------+---+--------+ + * || | | | | | | | + * |+--------+ +--------+ +--------+ +--------+ + * | + */ + region16_init(®ion); + + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r7)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r8)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 5 || + !compareRectangles(rects, r1_r7_r8, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + region16_clear(®ion); + + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r8)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r7)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 5 || + !compareRectangles(rects, r1_r7_r8, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + region16_clear(®ion); + + if (!region16_union_rect(®ion, ®ion, &r8)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r7)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 5 || + !compareRectangles(rects, r1_r7_r8, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r1_r2_r3_r4(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r2 = { 150, 301, 250, 401 }; + RECTANGLE_16 r3 = { 150, 151, 250, 251 }; + RECTANGLE_16 r4 = { 150, 251, 250, 301 }; + RECTANGLE_16 r1_r2_r3[] = { + { 0, 101, 200, 151 }, { 0, 151, 250, 201 }, { 150, 201, 250, 251 }, { 150, 301, 250, 401 } + }; + RECTANGLE_16 r1_r2_r3_r4[] = { { 0, 101, 200, 151 }, + { 0, 151, 250, 201 }, + { 150, 201, 250, 401 } }; + region16_init(®ion); + + /* + * +=============================================================== + * | + * |+-----+ +-----+ + * || r1 | | | + * || +-+------+ +-----+--------+ + * || | r3 | | | + * |+---+ | ====> +-----+--------+ + * | | | | | + * | +--------+ +--------+ + * | +--------+ +--------+ + * | | r2 | | | + * | | | | | + * | +--------+ +--------+ + */ + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r2)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r3)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 4 || !compareRectangles(rects, r1_r2_r3, 4)) + goto out; + + /* + * +=============================================================== + * | + * |+-----+ +-----+ + * || | | | + * |+-----+--------+ +-----+--------+ + * || | ==> | | + * |+-----+--------+ +-----+--------+ + * | | | | | + * | +--------+ | | + * | | + r4 | | | + * | +--------+ | | + * | | | | | + * | | | | | + * | +--------+ +--------+ + */ + if (!region16_union_rect(®ion, ®ion, &r4)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3_r4, 3)) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_from_weston(void) +{ + /* + * 0: 0,0 -> 640,32 (w=640 h=32) + * 1: 236,169 -> 268,201 (w=32 h=32) + * 2: 246,258 -> 278,290 (w=32 h=32) + */ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 0, 640, 32 }; + RECTANGLE_16 r2 = { 236, 169, 268, 201 }; + RECTANGLE_16 r3 = { 246, 258, 278, 290 }; + RECTANGLE_16 r1_r2_r3[] = { { 0, 0, 640, 32 }, { 236, 169, 268, 201 }, { 246, 258, 278, 290 } }; + region16_init(®ion); + + /* + * +=============================================================== + * |+-------------------------------------------------------------+ + * || r1 | + * |+-------------------------------------------------------------+ + * | + * | +---------------+ + * | | r2 | + * | +---------------+ + * | + * | +---------------+ + * | | r3 | + * | +---------------+ + * | + */ + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r2)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r3)) + goto out; + + rects = region16_rects(®ion, &nbRects); + + if (!rects || nbRects != 3 || !compareRectangles(rects, r1_r2_r3, 3)) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_r1_inter_r3(void) +{ + REGION16 region; + REGION16 intersection; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r3 = { 150, 151, 250, 251 }; + RECTANGLE_16 r1_inter_r3[] = { + { 150, 151, 200, 201 }, + }; + region16_init(®ion); + region16_init(&intersection); + + /* + * +=============================================================== + * | + * |+-----+ + * || r1 | + * || +-+------+ +-+ + * || | r3 | r1&r3 | | + * |+---+ | ====> +-+ + * | | | + * | +--------+ + */ + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_intersects_rect(®ion, &r3)) + goto out; + + if (!region16_intersect_rect(&intersection, ®ion, &r3)) + goto out; + + rects = region16_rects(&intersection, &nbRects); + + if (!rects || nbRects != 1 || + !compareRectangles(rects, r1_inter_r3, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(®ion); + region16_uninit(&intersection); + return retCode; +} + +static int test_r1_r3_inter_r11(void) +{ + REGION16 region; + REGION16 intersection; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 r1 = { 0, 101, 200, 201 }; + RECTANGLE_16 r3 = { 150, 151, 250, 251 }; + RECTANGLE_16 r11 = { 170, 151, 600, 301 }; + RECTANGLE_16 r1_r3_inter_r11[] = { + { 170, 151, 250, 251 }, + }; + region16_init(®ion); + region16_init(&intersection); + + /* + * +=============================================================== + * | + * |+-----+ + * || | + * || +------+ + * || r1+r3 | (r1+r3) & r11 + * || +----------------+ +--------+ + * |+---+ | | | ====> | | + * | | | | | | | + * | | | | | | | + * | +-|------+ | +--------+ + * | | r11 | + * | +----------------+ + * + * + * R1+R3 is made of 3 bands, R11 overlap the second and the third band. The + * intersection is made of two band that must be reassembled to give only + * one + */ + if (!region16_union_rect(®ion, ®ion, &r1)) + goto out; + + if (!region16_union_rect(®ion, ®ion, &r3)) + goto out; + + if (!region16_intersects_rect(®ion, &r11)) + goto out; + + if (!region16_intersect_rect(&intersection, ®ion, &r11)) + goto out; + + rects = region16_rects(&intersection, &nbRects); + + if (!rects || nbRects != 1 || + !compareRectangles(rects, r1_r3_inter_r11, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + retCode = 0; +out: + region16_uninit(&intersection); + region16_uninit(®ion); + return retCode; +} + +static int test_norbert_case(void) +{ + REGION16 region; + REGION16 intersection; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 inRectangles[5] = { { 1680, 0, 1920, 242 }, + { 294, 242, 971, 776 }, + { 1680, 242, 1920, 776 }, + { 1680, 776, 1920, 1036 }, + { 2, 1040, 53, 1078 } }; + RECTANGLE_16 screenRect = { 0, 0, 1920, 1080 }; + RECTANGLE_16 expected_inter_extents = { 2, 0, 1920, 1078 }; + region16_init(®ion); + region16_init(&intersection); + + /* + * Consider following as a screen with resolution 1920*1080 + * | | | | | | | + * | |2 |53 |294 |971 |1680 | + * | | | | | | | + * 0 +=+======================================+======+ + * | | | | + * | | R[0]| + * 242 | +-----------+ +------+ + * | | | | | | + * | | | | | + * | | R[1]| | R[2]| + * 776 | | +-----------+ +------+ + * | | | + * | | R[3]| + * 1036 | | +------+ + * 1040 | +----+ + * | |R[4]| Union of R[0-4]| + * 1078 | +----+ - - - - - - - -+ + * 1080 | + * + * + * The result is union of R[0] - R[4]. + * After intersected with the full screen rect, the + * result should keep the same. + */ + for (int i = 0; i < 5; i++) + { + if (!region16_union_rect(®ion, ®ion, &inRectangles[i])) + goto out; + } + + if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1)) + goto out; + + if (!region16_intersect_rect(&intersection, ®ion, &screenRect)) + goto out; + + rects = region16_rects(&intersection, &nbRects); + + if (!rects || nbRects != 5 || + !compareRectangles(rects, inRectangles, WINPR_ASSERTING_INT_CAST(int, nbRects))) + goto out; + + if (!compareRectangles(region16_extents(&intersection), &expected_inter_extents, 1)) + goto out; + + retCode = 0; +out: + region16_uninit(&intersection); + region16_uninit(®ion); + return retCode; +} + +static int test_norbert2_case(void) +{ + REGION16 region; + int retCode = -1; + const RECTANGLE_16* rects = NULL; + UINT32 nbRects = 0; + RECTANGLE_16 rect1 = { 464, 696, 476, 709 }; + RECTANGLE_16 rect2 = { 0, 0, 1024, 32 }; + region16_init(®ion); + + if (!region16_union_rect(®ion, ®ion, &rect1)) + { + (void)fprintf(stderr, "%s: Error 1 - region16_union_rect failed\n", __func__); + goto out; + } + + if (!(rects = region16_rects(®ion, &nbRects))) + { + (void)fprintf(stderr, "%s: Error 2 - region16_rects failed\n", __func__); + goto out; + } + + if (nbRects != 1) + { + (void)fprintf(stderr, "%s: Error 3 - expected nbRects == 1 but got %" PRIu32 "\n", __func__, + nbRects); + goto out; + } + + if (!compareRectangles(&rects[0], &rect1, 1)) + { + (void)fprintf(stderr, "%s: Error 4 - compare failed\n", __func__); + goto out; + } + + if (!region16_union_rect(®ion, ®ion, &rect2)) + { + (void)fprintf(stderr, "%s: Error 5 - region16_union_rect failed\n", __func__); + goto out; + } + + if (!(rects = region16_rects(®ion, &nbRects))) + { + (void)fprintf(stderr, "%s: Error 6 - region16_rects failed\n", __func__); + goto out; + } + + if (nbRects != 2) + { + (void)fprintf(stderr, "%s: Error 7 - expected nbRects == 2 but got %" PRIu32 "\n", __func__, + nbRects); + goto out; + } + + if (!compareRectangles(&rects[0], &rect2, 1)) + { + (void)fprintf(stderr, "%s: Error 8 - compare failed\n", __func__); + goto out; + } + + if (!compareRectangles(&rects[1], &rect1, 1)) + { + (void)fprintf(stderr, "%s: Error 9 - compare failed\n", __func__); + goto out; + } + + retCode = 0; +out: + region16_uninit(®ion); + return retCode; +} + +static int test_empty_rectangle(void) +{ + REGION16 region; + REGION16 intersection; + int retCode = -1; + RECTANGLE_16 emptyRectangles[3] = { { 0, 0, 0, 0 }, { 10, 10, 10, 11 }, { 10, 10, 11, 10 } }; + RECTANGLE_16 firstRect = { 0, 0, 100, 100 }; + RECTANGLE_16 anotherRect = { 100, 100, 200, 200 }; + RECTANGLE_16 expected_inter_extents = { 0, 0, 0, 0 }; + region16_init(®ion); + region16_init(&intersection); + + /* Check for empty rectangles */ + for (int i = 0; i < 3; i++) + { + if (!rectangle_is_empty(&emptyRectangles[i])) + goto out; + } + + /* Check for non-empty rectangles */ + if (rectangle_is_empty(&firstRect)) + goto out; + + /* Intersect 2 non-intersect rectangle, result should be empty */ + if (!region16_union_rect(®ion, ®ion, &firstRect)) + goto out; + + if (!region16_intersect_rect(®ion, ®ion, &anotherRect)) + goto out; + + if (!compareRectangles(region16_extents(®ion), &expected_inter_extents, 1)) + goto out; + + if (!region16_is_empty(®ion)) + goto out; + + if (!rectangle_is_empty(region16_extents(&intersection))) + goto out; + + retCode = 0; +out: + region16_uninit(&intersection); + region16_uninit(®ion); + return retCode; +} + +typedef int (*TestFunction)(void); +struct UnitaryTest +{ + const char* name; + TestFunction func; +}; + +static struct UnitaryTest tests[] = { { "Basic trivial tests", test_basic }, + { "R1+R3 and R3+R1", test_r1_r3 }, + { "R1+R5", test_r1_r5 }, + { "R1+R6", test_r1_r6 }, + { "R9+R10", test_r9_r10 }, + { "R1+R2+R4", test_r1_r2_r4 }, + { "R1+R7+R8 in many orders", test_r1_r7_r8 }, + { "R1+R2+R3+R4", test_r1_r2_r3_r4 }, + { "data from weston", test_from_weston }, + { "R1 & R3", test_r1_inter_r3 }, + { "(R1+R3)&R11 (band merge)", test_r1_r3_inter_r11 }, + { "norbert's case", test_norbert_case }, + { "norbert's case 2", test_norbert2_case }, + { "empty rectangle case", test_empty_rectangle }, + + { NULL, NULL } }; + +int TestFreeRDPRegion(int argc, char* argv[]) +{ + int testNb = 0; + int retCode = -1; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + for (int i = 0; tests[i].func; i++) + { + testNb++; + (void)fprintf(stderr, "%d: %s\n", testNb, tests[i].name); + retCode = tests[i].func(); + + if (retCode < 0) + break; + } + + if (retCode < 0) + (void)fprintf(stderr, "failed for test %d\n", testNb); + + return retCode; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFuzzCodecs.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFuzzCodecs.c new file mode 100644 index 0000000000000000000000000000000000000000..f9237659bb47a43a3e0220692cadffbdb43dcb10 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/codec/test/TestFuzzCodecs.c @@ -0,0 +1,467 @@ +/* https://github.com/ergnoorr/fuzzrdp + * + * MIT License + * + * Copyright (c) 2024 ergnoorr + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "../progressive.h" +#include "../mppc.h" +#include "../xcrush.h" +#include "../ncrush.h" + +static BOOL test_ClearDecompressExample(UINT32 nr, UINT32 width, UINT32 height, + const BYTE* pSrcData, const UINT32 SrcSize) +{ + BOOL rc = FALSE; + int status = 0; + BYTE* pDstData = calloc(1ull * width * height, 4); + CLEAR_CONTEXT* clear = clear_context_new(FALSE); + + WINPR_UNUSED(nr); + if (!clear || !pDstData) + goto fail; + + status = clear_decompress(clear, pSrcData, SrcSize, width, height, pDstData, + PIXEL_FORMAT_XRGB32, 0, 0, 0, width, height, NULL); + // printf("clear_decompress example %" PRIu32 " status: %d\n", nr, status); + // fflush(stdout); + rc = (status == 0); +fail: + clear_context_free(clear); + free(pDstData); + return rc; +} + +static int TestFreeRDPCodecClear(const uint8_t* Data, size_t Size) +{ + if (Size > UINT32_MAX) + return -1; + test_ClearDecompressExample(2, 78, 17, Data, (UINT32)Size); + test_ClearDecompressExample(3, 64, 24, Data, (UINT32)Size); + test_ClearDecompressExample(4, 7, 15, Data, (UINT32)Size); + return 0; +} + +static int TestFreeRDPCodecXCrush(const uint8_t* Data, size_t Size) +{ + if (Size > UINT32_MAX) + return -1; + + const BYTE* OutputBuffer = NULL; + UINT32 DstSize = 0; + XCRUSH_CONTEXT* xcrush = xcrush_context_new(TRUE); + if (!xcrush) + return 0; + xcrush_decompress(xcrush, Data, (UINT32)Size, &OutputBuffer, &DstSize, 0); + xcrush_context_free(xcrush); + return 0; +} + +static int test_ZGfxDecompressFoxSingle(const uint8_t* Data, size_t Size) +{ + if (Size > UINT32_MAX) + return -1; + int rc = -1; + int status = 0; + UINT32 Flags = 0; + const BYTE* pSrcData = (const BYTE*)Data; + UINT32 SrcSize = (UINT32)Size; + UINT32 DstSize = 0; + BYTE* pDstData = NULL; + ZGFX_CONTEXT* zgfx = zgfx_context_new(TRUE); + + if (!zgfx) + return -1; + + status = zgfx_decompress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + if (status < 0) + goto fail; + + rc = 0; +fail: + free(pDstData); + zgfx_context_free(zgfx); + return rc; +} + +static int TestFreeRDPCodecZGfx(const uint8_t* Data, size_t Size) +{ + test_ZGfxDecompressFoxSingle(Data, Size); + return 0; +} + +static BOOL test_NCrushDecompressBells(const uint8_t* Data, size_t Size) +{ + if (Size > UINT32_MAX) + return FALSE; + + BOOL rc = FALSE; + int status = 0; + UINT32 Flags = PACKET_COMPRESSED | 2; + const BYTE* pSrcData = (const BYTE*)Data; + UINT32 SrcSize = (UINT32)Size; + UINT32 DstSize = 0; + const BYTE* pDstData = NULL; + NCRUSH_CONTEXT* ncrush = ncrush_context_new(FALSE); + + if (!ncrush) + return rc; + + status = ncrush_decompress(ncrush, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + if (status < 0) + goto fail; + + rc = TRUE; +fail: + ncrush_context_free(ncrush); + return rc; +} + +static int TestFreeRDPCodecNCrush(const uint8_t* Data, size_t Size) +{ + test_NCrushDecompressBells(Data, Size); + return 0; +} + +static const size_t IMG_WIDTH = 64; +static const size_t IMG_HEIGHT = 64; +static const size_t FORMAT_SIZE = 4; +static const UINT32 FORMAT = PIXEL_FORMAT_XRGB32; + +static int TestFreeRDPCodecRemoteFX(const uint8_t* Data, size_t Size) +{ + int rc = -1; + REGION16 region = { 0 }; + RFX_CONTEXT* context = rfx_context_new(FALSE); + BYTE* dest = calloc(IMG_WIDTH * IMG_HEIGHT, FORMAT_SIZE); + size_t stride = FORMAT_SIZE * IMG_WIDTH; + if (!context) + goto fail; + if (Size > UINT32_MAX) + goto fail; + if (stride > UINT32_MAX) + goto fail; + if (!dest) + goto fail; + + region16_init(®ion); + if (!rfx_process_message(context, Data, (UINT32)Size, 0, 0, dest, FORMAT, (UINT32)stride, + IMG_HEIGHT, ®ion)) + goto fail; + + region16_clear(®ion); + if (!rfx_process_message(context, Data, (UINT32)Size, 0, 0, dest, FORMAT, (UINT32)stride, + IMG_HEIGHT, ®ion)) + goto fail; + region16_print(®ion); + + rc = 0; +fail: + region16_uninit(®ion); + rfx_context_free(context); + free(dest); + return rc; +} + +static int test_MppcDecompressBellsRdp5(const uint8_t* Data, size_t Size) +{ + int rc = -1; + int status = 0; + UINT32 Flags = PACKET_AT_FRONT | PACKET_COMPRESSED | 1; + const BYTE* pSrcData = Data; + UINT32 SrcSize = (UINT32)Size; + UINT32 DstSize = 0; + const BYTE* pDstData = NULL; + MPPC_CONTEXT* mppc = mppc_context_new(1, FALSE); + + if (!mppc) + return -1; + + status = mppc_decompress(mppc, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + rc = 0; + +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcDecompressBellsRdp4(const uint8_t* Data, size_t Size) +{ + if (Size > UINT32_MAX) + return -1; + int rc = -1; + int status = 0; + UINT32 Flags = PACKET_AT_FRONT | PACKET_COMPRESSED | 0; + const BYTE* pSrcData = (const BYTE*)Data; + UINT32 SrcSize = (UINT32)Size; + UINT32 DstSize = 0; + const BYTE* pDstData = NULL; + MPPC_CONTEXT* mppc = mppc_context_new(0, FALSE); + + if (!mppc) + return -1; + + status = mppc_decompress(mppc, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int test_MppcDecompressBufferRdp5(const uint8_t* Data, size_t Size) +{ + if (Size > UINT32_MAX) + return -1; + int rc = -1; + int status = 0; + UINT32 Flags = PACKET_AT_FRONT | PACKET_COMPRESSED | 1; + const BYTE* pSrcData = (const BYTE*)Data; + UINT32 SrcSize = (UINT32)Size; + UINT32 DstSize = 0; + const BYTE* pDstData = NULL; + MPPC_CONTEXT* mppc = mppc_context_new(1, FALSE); + + if (!mppc) + return -1; + + status = mppc_decompress(mppc, pSrcData, SrcSize, &pDstData, &DstSize, Flags); + + if (status < 0) + goto fail; + + rc = 0; +fail: + mppc_context_free(mppc); + return rc; +} + +static int TestFreeRDPCodecMppc(const uint8_t* Data, size_t Size) +{ + test_MppcDecompressBellsRdp5(Data, Size); + test_MppcDecompressBellsRdp4(Data, Size); + test_MppcDecompressBufferRdp5(Data, Size); + return 0; +} + +static BOOL progressive_decode(const uint8_t* Data, size_t Size) +{ + BOOL res = FALSE; + int rc = 0; + BYTE* resultData = NULL; + UINT32 ColorFormat = PIXEL_FORMAT_BGRX32; + REGION16 invalidRegion = { 0 }; + UINT32 scanline = 4240; + UINT32 width = 1060; + UINT32 height = 827; + if (Size > UINT32_MAX) + return FALSE; + + PROGRESSIVE_CONTEXT* progressiveDec = progressive_context_new(FALSE); + + region16_init(&invalidRegion); + if (!progressiveDec) + goto fail; + + resultData = calloc(scanline, height); + if (!resultData) + goto fail; + + rc = progressive_create_surface_context(progressiveDec, 0, width, height); + if (rc <= 0) + goto fail; + + rc = progressive_decompress(progressiveDec, Data, (UINT32)Size, resultData, ColorFormat, + scanline, 0, 0, &invalidRegion, 0, 0); + if (rc < 0) + goto fail; + + res = TRUE; +fail: + region16_uninit(&invalidRegion); + progressive_context_free(progressiveDec); + free(resultData); + return res; +} + +static int TestFreeRDPCodecProgressive(const uint8_t* Data, size_t Size) +{ + progressive_decode(Data, Size); + return 0; +} + +static BOOL i_run_encode_decode(UINT16 bpp, BITMAP_INTERLEAVED_CONTEXT* encoder, + BITMAP_INTERLEAVED_CONTEXT* decoder, const uint8_t* Data, + size_t Size) +{ + BOOL rc2 = FALSE; + BOOL rc = 0; + const UINT32 w = 64; + const UINT32 h = 64; + const UINT32 x = 0; + const UINT32 y = 0; + const UINT32 format = PIXEL_FORMAT_RGBX32; + const size_t step = (w + 13ull) * 4ull; + const size_t SrcSize = step * h; + BYTE* pSrcData = calloc(1, SrcSize); + BYTE* pDstData = calloc(1, SrcSize); + BYTE* tmp = calloc(1, SrcSize); + + WINPR_UNUSED(encoder); + if (!pSrcData || !pDstData || !tmp) + goto fail; + + if (Size > UINT32_MAX) + goto fail; + + winpr_RAND(pSrcData, SrcSize); + + if (!bitmap_interleaved_context_reset(decoder)) + goto fail; + + rc = interleaved_decompress(decoder, Data, (UINT32)Size, w, h, bpp, pDstData, format, step, x, + y, w, h, NULL); + + if (!rc) + goto fail; + + rc2 = TRUE; +fail: + free(pSrcData); + free(pDstData); + free(tmp); + return rc2; +} + +static int TestFreeRDPCodecInterleaved(const uint8_t* Data, size_t Size) +{ + int rc = -1; + BITMAP_INTERLEAVED_CONTEXT* decoder = bitmap_interleaved_context_new(FALSE); + + if (!decoder) + goto fail; + + i_run_encode_decode(24, NULL, decoder, Data, Size); + i_run_encode_decode(16, NULL, decoder, Data, Size); + i_run_encode_decode(15, NULL, decoder, Data, Size); + rc = 0; +fail: + bitmap_interleaved_context_free(decoder); + return rc; +} + +static BOOL RunTestPlanar(BITMAP_PLANAR_CONTEXT* planar, const BYTE* srcBitmap, + const UINT32 srcFormat, const UINT32 dstFormat, const UINT32 width, + const UINT32 height, const uint8_t* Data, size_t Size) +{ + BOOL rc = FALSE; + WINPR_UNUSED(srcBitmap); + WINPR_UNUSED(srcFormat); + if (Size > UINT32_MAX) + return FALSE; + UINT32 dstSize = (UINT32)Size; + const BYTE* compressedBitmap = Data; + BYTE* decompressedBitmap = + (BYTE*)calloc(height, 1ull * width * FreeRDPGetBytesPerPixel(dstFormat)); + rc = TRUE; + + if (!decompressedBitmap) + goto fail; + + if (!planar_decompress(planar, compressedBitmap, dstSize, width, height, decompressedBitmap, + dstFormat, 0, 0, 0, width, height, FALSE)) + { + goto fail; + } + + rc = TRUE; +fail: + free(decompressedBitmap); + return rc; +} + +static BOOL TestPlanar(const UINT32 format, const uint8_t* Data, size_t Size) +{ + BOOL rc = FALSE; + const DWORD planarFlags = PLANAR_FORMAT_HEADER_NA | PLANAR_FORMAT_HEADER_RLE; + BITMAP_PLANAR_CONTEXT* planar = freerdp_bitmap_planar_context_new(planarFlags, 64, 64); + + if (!planar) + goto fail; + + RunTestPlanar(planar, NULL, PIXEL_FORMAT_RGBX32, format, 64, 64, Data, Size); + + RunTestPlanar(planar, NULL, PIXEL_FORMAT_RGB16, format, 32, 32, Data, Size); + + rc = TRUE; +fail: + freerdp_bitmap_planar_context_free(planar); + return rc; +} + +static int TestFreeRDPCodecPlanar(const uint8_t* Data, size_t Size) +{ + TestPlanar(0, Data, Size); + return 0; +} + +int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) +{ + if (Size < 4) + return 0; + + TestFreeRDPCodecClear(Data, Size); + TestFreeRDPCodecXCrush(Data, Size); + TestFreeRDPCodecZGfx(Data, Size); + TestFreeRDPCodecNCrush(Data, Size); + TestFreeRDPCodecRemoteFX(Data, Size); + TestFreeRDPCodecMppc(Data, Size); + TestFreeRDPCodecProgressive(Data, Size); + TestFreeRDPCodecInterleaved(Data, Size); + TestFreeRDPCodecPlanar(Data, Size); + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..445f89ae35275371d7e3481eec97c721405c3c8f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/CMakeLists.txt @@ -0,0 +1,30 @@ +set(MODULE_NAME "TestCommon") +set(MODULE_PREFIX "TEST_COMMON") + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c) + +set(${MODULE_PREFIX}_TESTS TestAddinArgv.c TestCommonAssistance.c) + +set(FUZZERS TestFuzzCommonAssistanceParseFileBuffer.c TestFuzzCommonAssistanceBinToHexString.c + TestFuzzCommonAssistanceHexStringToBin.c +) + +create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS}) + +add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + +target_link_libraries(${MODULE_NAME} freerdp winpr) + +include(AddFuzzerTest) +add_fuzzer_test("${FUZZERS}" "freerdp winpr") + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${${MODULE_PREFIX}_TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Common/Test") diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestAddinArgv.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestAddinArgv.c new file mode 100644 index 0000000000000000000000000000000000000000..f9a1f8bc52cbabb1974aad59570df28c146e9ee5 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestAddinArgv.c @@ -0,0 +1,345 @@ +#include +#include + +#include + +static BOOL test_alloc(void) +{ + BOOL rc = FALSE; + int rng = 0; + const char* param[] = { "foo:", "bar", "bla", "rdp", NULL }; + ADDIN_ARGV* arg1 = NULL; + ADDIN_ARGV* arg2 = NULL; + ADDIN_ARGV* arg3 = NULL; + ADDIN_ARGV* arg4 = NULL; + + /* Test empty allocation */ + arg1 = freerdp_addin_argv_new(0, NULL); + if (!arg1 || (arg1->argc != 0) || (arg1->argv)) + goto fail; + + /* Test allocation without initializing arguments of random size > 0 */ + winpr_RAND(&rng, sizeof(rng)); + rng = abs(rng % 8192) + 1; + + arg2 = freerdp_addin_argv_new(rng, NULL); + if (!arg2 || (arg2->argc != rng) || (!arg2->argv)) + goto fail; + for (int x = 0; x < arg2->argc; x++) + { + if (arg2->argv[x]) + goto fail; + } + + /* Test allocation with initializing arguments of size > 0 */ + arg3 = freerdp_addin_argv_new(ARRAYSIZE(param) - 1, param); + if (!arg3 || (arg3->argc != ARRAYSIZE(param) - 1) || (!arg3->argv)) + goto fail; + + for (int x = 0; x < arg3->argc; x++) + { + if (strcmp(arg3->argv[x], param[x]) != 0) + goto fail; + } + + /* Input lists with NULL elements are not allowed */ + arg4 = freerdp_addin_argv_new(ARRAYSIZE(param), param); + if (arg4) + goto fail; + rc = TRUE; +fail: + freerdp_addin_argv_free(arg1); + freerdp_addin_argv_free(arg2); + freerdp_addin_argv_free(arg3); + freerdp_addin_argv_free(arg4); + printf("%s: %d\n", __func__, rc); + return rc; +} + +static BOOL test_clone(void) +{ + BOOL rc = FALSE; + const char* param[] = { "foo:", "bar", "bla", "rdp" }; + ADDIN_ARGV* arg = NULL; + ADDIN_ARGV* clone = NULL; + ADDIN_ARGV* clone2 = NULL; + + arg = freerdp_addin_argv_new(ARRAYSIZE(param), param); + if (!arg || (arg->argc != ARRAYSIZE(param))) + goto fail; + clone = freerdp_addin_argv_clone(arg); + if (!clone || (clone->argc != arg->argc)) + goto fail; + + for (int x = 0; x < arg->argc; x++) + { + if (strcmp(param[x], arg->argv[x]) != 0) + goto fail; + if (strcmp(param[x], clone->argv[x]) != 0) + goto fail; + } + + clone2 = freerdp_addin_argv_clone(NULL); + if (clone2) + goto fail; + rc = TRUE; +fail: + freerdp_addin_argv_free(arg); + freerdp_addin_argv_free(clone); + freerdp_addin_argv_free(clone2); + printf("%s: %d\n", __func__, rc); + return rc; +} + +static BOOL test_add_remove(void) +{ + const char* args[] = { "foo", "bar", "bla", "gaga" }; + BOOL rc = FALSE; + ADDIN_ARGV* arg = freerdp_addin_argv_new(0, NULL); + + if (!arg || (arg->argc != 0) || arg->argv) + goto fail; + for (size_t y = 0; y < ARRAYSIZE(args); y++) + { + const char* param = args[y]; + if (!freerdp_addin_argv_add_argument(arg, param)) + goto fail; + if (arg->argc != (int)y + 1) + goto fail; + if (!arg->argv) + goto fail; + if (strcmp(arg->argv[y], param) != 0) + goto fail; + } + + /* Try to remove non existing element, must not return TRUE */ + if (freerdp_addin_argv_del_argument(arg, "foobar")) + goto fail; + + /* Invalid parameters, must return FALSE */ + if (freerdp_addin_argv_del_argument(NULL, "foobar")) + goto fail; + + /* Invalid parameters, must return FALSE */ + if (freerdp_addin_argv_del_argument(arg, NULL)) + goto fail; + + /* Remove elements one by one to test argument index move */ + for (size_t y = 0; y < ARRAYSIZE(args); y++) + { + const char* param = args[y]; + if (!freerdp_addin_argv_del_argument(arg, param)) + goto fail; + for (size_t x = y + 1; x < ARRAYSIZE(args); x++) + { + if (strcmp(arg->argv[x - y - 1], args[x]) != 0) + goto fail; + } + } + rc = TRUE; +fail: + freerdp_addin_argv_free(arg); + printf("%s: %d\n", __func__, rc); + return rc; +} + +static BOOL test_set_argument(void) +{ + int ret = 0; + const char* newarg = "foobar"; + const char* args[] = { "foo", "bar", "bla", "gaga" }; + BOOL rc = FALSE; + ADDIN_ARGV* arg = NULL; + + arg = freerdp_addin_argv_new(ARRAYSIZE(args), args); + if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv) + goto fail; + + /* Check invalid parameters */ + ret = freerdp_addin_set_argument(NULL, "foo"); + if (ret >= 0) + goto fail; + ret = freerdp_addin_set_argument(arg, NULL); + if (ret >= 0) + goto fail; + + /* Try existing parameter */ + ret = freerdp_addin_set_argument(arg, "foo"); + if ((ret != 1) || (arg->argc != ARRAYSIZE(args))) + goto fail; + + /* Try new parameter */ + ret = freerdp_addin_set_argument(arg, newarg); + if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) || + (strcmp(newarg, arg->argv[ARRAYSIZE(args)]) != 0)) + goto fail; + + rc = TRUE; +fail: + freerdp_addin_argv_free(arg); + printf("%s: %d\n", __func__, rc); + return rc; +} + +static BOOL test_replace_argument(void) +{ + int ret = 0; + const char* newarg = "foobar"; + const char* args[] = { "foo", "bar", "bla", "gaga" }; + BOOL rc = FALSE; + ADDIN_ARGV* arg = NULL; + + arg = freerdp_addin_argv_new(ARRAYSIZE(args), args); + if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv) + goto fail; + + /* Check invalid parameters */ + ret = freerdp_addin_replace_argument(NULL, "foo", newarg); + if (ret >= 0) + goto fail; + ret = freerdp_addin_replace_argument(arg, NULL, newarg); + if (ret >= 0) + goto fail; + ret = freerdp_addin_replace_argument(arg, "foo", NULL); + if (ret >= 0) + goto fail; + + /* Try existing parameter */ + ret = freerdp_addin_replace_argument(arg, "foo", newarg); + if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[0], newarg) != 0)) + goto fail; + + /* Try new parameter */ + ret = freerdp_addin_replace_argument(arg, "lalala", newarg); + if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) || + (strcmp(newarg, arg->argv[ARRAYSIZE(args)]) != 0)) + goto fail; + + rc = TRUE; +fail: + freerdp_addin_argv_free(arg); + printf("%s: %d\n", __func__, rc); + return rc; +} + +static BOOL test_set_argument_value(void) +{ + int ret = 0; + const char* newarg1 = "foobar"; + const char* newarg2 = "lalala"; + const char* fullnewarg1 = "foo:foobar"; + const char* fullnewarg2 = "foo:lalala"; + const char* fullnewvalue = "lalala:foobar"; + const char* args[] = { "foo", "foo:", "bar", "bla", "gaga" }; + BOOL rc = FALSE; + ADDIN_ARGV* arg = NULL; + + arg = freerdp_addin_argv_new(ARRAYSIZE(args), args); + if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv) + goto fail; + + /* Check invalid parameters */ + ret = freerdp_addin_set_argument_value(NULL, "foo", newarg1); + if (ret >= 0) + goto fail; + ret = freerdp_addin_set_argument_value(arg, NULL, newarg1); + if (ret >= 0) + goto fail; + ret = freerdp_addin_set_argument_value(arg, "foo", NULL); + if (ret >= 0) + goto fail; + + /* Try existing parameter */ + ret = freerdp_addin_set_argument_value(arg, "foo", newarg1); + if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[1], fullnewarg1) != 0)) + goto fail; + ret = freerdp_addin_set_argument_value(arg, "foo", newarg2); + if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[1], fullnewarg2) != 0)) + goto fail; + + /* Try new parameter */ + ret = freerdp_addin_set_argument_value(arg, newarg2, newarg1); + if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) || + (strcmp(fullnewvalue, arg->argv[ARRAYSIZE(args)]) != 0)) + goto fail; + + rc = TRUE; +fail: + freerdp_addin_argv_free(arg); + printf("%s: %d\n", __func__, rc); + return rc; +} + +static BOOL test_replace_argument_value(void) +{ + int ret = 0; + const char* newarg1 = "foobar"; + const char* newarg2 = "lalala"; + const char* fullnewarg1 = "foo:foobar"; + const char* fullnewarg2 = "foo:lalala"; + const char* fullnewvalue = "lalala:foobar"; + const char* args[] = { "foo", "foo:", "bar", "bla", "gaga" }; + BOOL rc = FALSE; + ADDIN_ARGV* arg = NULL; + + arg = freerdp_addin_argv_new(ARRAYSIZE(args), args); + if (!arg || (arg->argc != ARRAYSIZE(args)) || !arg->argv) + goto fail; + + /* Check invalid parameters */ + ret = freerdp_addin_replace_argument_value(NULL, "bar", "foo", newarg1); + if (ret >= 0) + goto fail; + ret = freerdp_addin_replace_argument_value(arg, NULL, "foo", newarg1); + if (ret >= 0) + goto fail; + ret = freerdp_addin_replace_argument_value(arg, "foo", NULL, newarg1); + if (ret >= 0) + goto fail; + ret = freerdp_addin_replace_argument_value(arg, "bar", "foo", NULL); + if (ret >= 0) + goto fail; + + /* Try existing parameter */ + ret = freerdp_addin_replace_argument_value(arg, "bla", "foo", newarg1); + if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[3], fullnewarg1) != 0)) + goto fail; + ret = freerdp_addin_replace_argument_value(arg, "foo", "foo", newarg2); + if ((ret != 1) || (arg->argc != ARRAYSIZE(args)) || (strcmp(arg->argv[0], fullnewarg2) != 0)) + goto fail; + + /* Try new parameter */ + ret = freerdp_addin_replace_argument_value(arg, "hahaha", newarg2, newarg1); + if ((ret != 0) || (arg->argc != ARRAYSIZE(args) + 1) || + (strcmp(fullnewvalue, arg->argv[ARRAYSIZE(args)]) != 0)) + goto fail; + + rc = TRUE; +fail: + freerdp_addin_argv_free(arg); + printf("%s: %d\n", __func__, rc); + return rc; +} + +int TestAddinArgv(int argc, char* argv[]) +{ + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!test_alloc()) + return -1; + if (!test_clone()) + return -1; + if (!test_add_remove()) + return -1; + if (!test_set_argument()) + return -1; + if (!test_replace_argument()) + return -1; + if (!test_set_argument_value()) + return -1; + if (!test_replace_argument_value()) + return -1; + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestCommonAssistance.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestCommonAssistance.c new file mode 100644 index 0000000000000000000000000000000000000000..0dba986cbd9b5793087a931afb5a2765544007cc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestCommonAssistance.c @@ -0,0 +1,317 @@ +#include +#include +#include +#include +#include + +#include + +static const char TEST_MSRC_INCIDENT_PASSWORD_TYPE1[] = "Password1"; +static const BYTE TEST_MSRC_INCIDENT_PASSWORD_TYPE1_ENC[32] = { + 0x3c, 0x9c, 0xae, 0xb, 0xce, 0x7a, 0xb1, 0x5c, 0x8a, 0xac, 0x1, 0xd6, 0x76, 0x4, 0x5e, 0xdf, + 0x3f, 0xfa, 0xf0, 0x92, 0xe2, 0xde, 0x36, 0x8a, 0x20, 0x17, 0xe6, 0x8a, 0xd, 0xed, 0x7c, 0x90 +}; + +static const char TEST_MSRC_INCIDENT_FILE_TYPE1[] = + "" + "" + "" + ""; + +WINPR_PRAGMA_DIAG_PUSH +WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR +static const BYTE TEST_MSRC_INCIDENT_EXPERT_BLOB_TYPE1[32] = + "\x3C\x9C\xAE\x0B\xCE\x7A\xB1\x5C\x8A\xAC\x01\xD6\x76\x04\x5E\xDF" + "\x3F\xFA\xF0\x92\xE2\xDE\x36\x8A\x20\x17\xE6\x8A\x0D\xED\x7C\x90"; +WINPR_PRAGMA_DIAG_POP + +static const char TEST_MSRC_INCIDENT_PASSWORD_TYPE2[] = "48BJQ853X3B4"; +static const BYTE TEST_MSRC_INCIDENT_PASSWORD_TYPE2_ENC[32] = { + 0x77, 0x7d, 0xfa, 0xae, 0x90, 0x28, 0x12, 0x4d, 0xd0, 0x2e, 0xde, 0x80, 0x14, 0x22, 0x1b, 0x4a, + 0xd1, 0xf4, 0xec, 0x13, 0x85, 0x39, 0xd7, 0x33, 0xac, 0x76, 0x78, 0x95, 0xb2, 0xd8, 0x57, 0xd9 +}; + +static const char TEST_MSRC_INCIDENT_FILE_TYPE2[] = + "" + "" + "" + ""; + +/** + * Decrypted Connection String 2: + * + * + * + * + * + * + */ +static const char connectionstr2[] = + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + ""; + +static const char* fail_tests[] = { + "", + "(E>" +}; + +static const char connectionstr3[] = + "\n" + "" + ""; +static const char connectionpwd3[] = "4X638PTVZTKZ"; +static const BYTE connectionpwd3_enc[32] = { 0x15, 0x20, 0x04, 0x96, 0xaf, 0x33, 0xc6, 0xe0, + 0x1b, 0xbf, 0x4a, 0x15, 0xc9, 0xc1, 0xb8, 0x71, + 0x44, 0x3f, 0x2e, 0x93, 0xa8, 0x82, 0x35, 0x2b, + 0x24, 0x08, 0x06, 0x55, 0x16, 0x4e, 0x9d, 0x3b }; + +static BOOL run_test_parse(wLog* log, const char* input, size_t len, const char* password, + BOOL expect) +{ + rdpAssistanceFile* file = freerdp_assistance_file_new(); + if (!file) + return FALSE; + + const int status = freerdp_assistance_parse_file_buffer(file, input, len, password); + const BOOL success = status >= 0; + + freerdp_assistance_print_file(file, log, WLOG_INFO); + freerdp_assistance_file_free(file); + return success == expect; +} + +static BOOL test_file_to_settings(wLog* log, rdpAssistanceFile* file) +{ + rdpSettings* settings = freerdp_settings_new(0); + if (!settings) + return FALSE; + const BOOL rc = freerdp_assistance_populate_settings_from_assistance_file(file, settings); + freerdp_settings_free(settings); + return rc; +} + +static BOOL test_file_from_buffer(wLog* log, const char* data, size_t size, const char* pwd, + const BYTE* enc, size_t encsize) +{ + BOOL rc = FALSE; + int status = 0; + char* pass = NULL; + char* expertBlob = NULL; + const char* EncryptedPassStub = NULL; + size_t EncryptedPassStubLength = 0; + rdpAssistanceFile* file = freerdp_assistance_file_new(); + + if (!file) + return FALSE; + + status = freerdp_assistance_parse_file_buffer(file, data, size, pwd); + WLog_Print(log, WLOG_INFO, "freerdp_assistance_parse_file_buffer: %d", status); + + if (status < 0) + goto fail; + + freerdp_assistance_print_file(file, WLog_Get("foo"), WLOG_INFO); + + if (!freerdp_assistance_get_encrypted_pass_stub(file, &EncryptedPassStub, + &EncryptedPassStubLength)) + goto fail; + + if (EncryptedPassStubLength > 0) + { + pass = freerdp_assistance_bin_to_hex_string(EncryptedPassStub, EncryptedPassStubLength); + + if (!pass) + goto fail; + + WLog_Print(log, WLOG_INFO, "freerdp_assistance_decrypt: %d %s [%" PRIdz "]", status, pass, + EncryptedPassStubLength); + expertBlob = freerdp_assistance_construct_expert_blob("Edgar Olougouna", pass); + + WLog_Print(log, WLOG_INFO, "expertBlob='%s'", expertBlob); + } + if (encsize != EncryptedPassStubLength) + goto fail; + if (encsize > 0) + { + if (memcmp(EncryptedPassStub, enc, encsize) != 0) + goto fail; + } + + rc = test_file_to_settings(log, file); +fail: + freerdp_assistance_file_free(file); + free(pass); + free(expertBlob); + return rc; +} + +static BOOL test_msrsc_incident_file_type1(wLog* log) +{ + return test_file_from_buffer( + log, TEST_MSRC_INCIDENT_FILE_TYPE1, sizeof(TEST_MSRC_INCIDENT_FILE_TYPE1), + TEST_MSRC_INCIDENT_PASSWORD_TYPE1, TEST_MSRC_INCIDENT_PASSWORD_TYPE1_ENC, + sizeof(TEST_MSRC_INCIDENT_PASSWORD_TYPE1_ENC)); +} + +static BOOL test_msrsc_incident_file_type2(wLog* log) +{ + if (!test_file_from_buffer(log, connectionstr2, sizeof(connectionstr2), + TEST_MSRC_INCIDENT_PASSWORD_TYPE2, NULL, 0)) + return FALSE; + if (!test_file_from_buffer(log, connectionstr3, sizeof(connectionstr3), connectionpwd3, + connectionpwd3_enc, sizeof(connectionpwd3_enc))) + return FALSE; + if (!test_file_from_buffer( + log, TEST_MSRC_INCIDENT_FILE_TYPE2, sizeof(TEST_MSRC_INCIDENT_FILE_TYPE2), + TEST_MSRC_INCIDENT_PASSWORD_TYPE2, TEST_MSRC_INCIDENT_PASSWORD_TYPE2_ENC, + sizeof(TEST_MSRC_INCIDENT_PASSWORD_TYPE2_ENC))) + return FALSE; + return TRUE; +} + +int TestCommonAssistance(int argc, char* argv[]) +{ + wLog* log = NULL; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + log = WLog_Get(__func__); + winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT); + + for (size_t x = 0; x < ARRAYSIZE(fail_tests); x++) + { + const char* test = fail_tests[x]; + const size_t len = strlen(test); + + if (!run_test_parse(log, test, len + 1, NULL, FALSE)) + return -1; + } + + if (!test_msrsc_incident_file_type1(log)) + { + WLog_Print(log, WLOG_ERROR, "test_msrsc_incident_file_type1 failed"); + return -1; + } + + if (!test_msrsc_incident_file_type2(log)) + { + WLog_Print(log, WLOG_ERROR, "test_msrsc_incident_file_type2 failed"); + return -1; + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceBinToHexString.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceBinToHexString.c new file mode 100644 index 0000000000000000000000000000000000000000..6b23c78794043508590f6d33af618ea4b55c6db3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceBinToHexString.c @@ -0,0 +1,8 @@ +#include + +int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) +{ + char* pass = freerdp_assistance_bin_to_hex_string((void*)Data, Size); + free(pass); + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceHexStringToBin.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceHexStringToBin.c new file mode 100644 index 0000000000000000000000000000000000000000..b0847d87f8236afdcf3ea0a8eb181bb0ec04186b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceHexStringToBin.c @@ -0,0 +1,16 @@ +#include + +int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) +{ + char* buf = calloc(Size + 1, sizeof(char)); + if (buf == NULL) + return 0; + memcpy(buf, Data, Size); + buf[Size] = '\0'; + + BYTE* pass = freerdp_assistance_hex_string_to_bin((void*)buf, &Size); + free(pass); + free(buf); + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceParseFileBuffer.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceParseFileBuffer.c new file mode 100644 index 0000000000000000000000000000000000000000..03856e489f4ec823917ba89e9079d9ab63b9a38c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/common/test/TestFuzzCommonAssistanceParseFileBuffer.c @@ -0,0 +1,31 @@ +#include + +static int parse_file_buffer(const uint8_t* Data, size_t Size) +{ + static const char TEST_MSRC_INCIDENT_PASSWORD_TYPE2[] = "48BJQ853X3B4"; + int status = -1; + rdpAssistanceFile* file = freerdp_assistance_file_new(); + if (!file) + return -1; + + char* buf = calloc(Size + 1, sizeof(char)); + if (buf == NULL) + goto err; + memcpy(buf, Data, Size); + buf[Size] = '\0'; + + status = freerdp_assistance_parse_file_buffer(file, buf, Size + 1, + TEST_MSRC_INCIDENT_PASSWORD_TYPE2); + +err: + freerdp_assistance_file_free(file); + free(buf); + + return status >= 0 ? TRUE : FALSE; +} + +int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) +{ + parse_file_buffer(Data, Size); + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/arm.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/arm.c new file mode 100644 index 0000000000000000000000000000000000000000..5eabbb01fe800c44770de9a8615c7c0197142fda --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/arm.c @@ -0,0 +1,1123 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Azure Virtual Desktop Gateway / Azure Resource Manager + * + * Copyright 2023 Michael Saxl + * Copyright 2023 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "../settings.h" + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "arm.h" +#include "wst.h" +#include "websocket.h" +#include "http.h" +#include "../credssp_auth.h" +#include "../proxy.h" +#include "../rdp.h" +#include "../../crypto/crypto.h" +#include "../../crypto/certificate.h" +#include "../../crypto/opensslcompat.h" +#include "rpc_fault.h" +#include "../utils.h" +#include "../redirection.h" + +#include + +#include + +struct rdp_arm +{ + rdpContext* context; + rdpTls* tls; + HttpContext* http; + + UINT32 gateway_retry; + wLog* log; +}; + +typedef struct rdp_arm rdpArm; + +#define TAG FREERDP_TAG("core.gateway.arm") + +#ifdef WITH_AAD +static BOOL arm_tls_connect(rdpArm* arm, rdpTls* tls, UINT32 timeout) +{ + WINPR_ASSERT(arm); + WINPR_ASSERT(tls); + int sockfd = 0; + long status = 0; + BIO* socketBio = NULL; + BIO* bufferedBio = NULL; + rdpSettings* settings = arm->context->settings; + if (!settings) + return FALSE; + + const char* peerHostname = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname); + if (!peerHostname) + return FALSE; + + UINT16 peerPort = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_GatewayPort); + const char* proxyUsername = NULL; + const char* proxyPassword = NULL; + BOOL isProxyConnection = + proxy_prepare(settings, &peerHostname, &peerPort, &proxyUsername, &proxyPassword); + + sockfd = freerdp_tcp_connect(arm->context, peerHostname, peerPort, timeout); + + WLog_Print(arm->log, WLOG_DEBUG, "connecting to %s %d", peerHostname, peerPort); + if (sockfd < 0) + return FALSE; + + socketBio = BIO_new(BIO_s_simple_socket()); + + if (!socketBio) + { + closesocket((SOCKET)sockfd); + return FALSE; + } + + BIO_set_fd(socketBio, sockfd, BIO_CLOSE); + bufferedBio = BIO_new(BIO_s_buffered_socket()); + + if (!bufferedBio) + { + BIO_free_all(socketBio); + return FALSE; + } + + bufferedBio = BIO_push(bufferedBio, socketBio); + if (!bufferedBio) + return FALSE; + + status = BIO_set_nonblock(bufferedBio, TRUE); + + if (isProxyConnection) + { + if (!proxy_connect(arm->context, bufferedBio, proxyUsername, proxyPassword, + freerdp_settings_get_string(settings, FreeRDP_GatewayHostname), + (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_GatewayPort))) + { + BIO_free_all(bufferedBio); + return FALSE; + } + } + + if (!status) + { + BIO_free_all(bufferedBio); + return FALSE; + } + + tls->hostname = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname); + tls->port = MIN(UINT16_MAX, WINPR_ASSERTING_INT_CAST(int32_t, settings->GatewayPort)); + tls->isGatewayTransport = TRUE; + status = freerdp_tls_connect(tls, bufferedBio); + if (status < 1) + { + rdpContext* context = arm->context; + if (status < 0) + freerdp_set_last_error_if_not(context, FREERDP_ERROR_TLS_CONNECT_FAILED); + else + freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED); + + return FALSE; + } + return (status >= 1); +} + +static BOOL arm_fetch_wellknown(rdpArm* arm) +{ + WINPR_ASSERT(arm); + WINPR_ASSERT(arm->context); + WINPR_ASSERT(arm->context->rdp); + + rdpRdp* rdp = arm->context->rdp; + if (rdp->wellknown) + return TRUE; + + const char* base = + freerdp_settings_get_string(arm->context->settings, FreeRDP_GatewayAzureActiveDirectory); + const BOOL useTenant = + freerdp_settings_get_bool(arm->context->settings, FreeRDP_GatewayAvdUseTenantid); + const char* tenantid = "common"; + if (useTenant) + tenantid = + freerdp_settings_get_string(arm->context->settings, FreeRDP_GatewayAvdAadtenantid); + + rdp->wellknown = freerdp_utils_aad_get_wellknown(arm->log, base, tenantid); + return rdp->wellknown ? TRUE : FALSE; +} + +static wStream* arm_build_http_request(rdpArm* arm, const char* method, + TRANSFER_ENCODING transferEncoding, const char* content_type, + size_t content_length) +{ + wStream* s = NULL; + HttpRequest* request = NULL; + const char* uri = NULL; + + WINPR_ASSERT(arm); + WINPR_ASSERT(method); + WINPR_ASSERT(content_type); + + WINPR_ASSERT(arm->context); + + freerdp* instance = arm->context->instance; + WINPR_ASSERT(instance); + + uri = http_context_get_uri(arm->http); + request = http_request_new(); + + if (!request) + return NULL; + + if (!http_request_set_method(request, method) || !http_request_set_uri(request, uri)) + goto out; + + if (!freerdp_settings_get_string(arm->context->settings, FreeRDP_GatewayHttpExtAuthBearer)) + { + char* token = NULL; + + if (!instance->GetAccessToken) + { + WLog_Print(arm->log, WLOG_ERROR, "No authorization token provided"); + goto out; + } + + if (!arm_fetch_wellknown(arm)) + goto out; + + if (!instance->GetAccessToken(instance, ACCESS_TOKEN_TYPE_AVD, &token, 0)) + { + WLog_Print(arm->log, WLOG_ERROR, "Unable to obtain access token"); + goto out; + } + + if (!freerdp_settings_set_string(arm->context->settings, FreeRDP_GatewayHttpExtAuthBearer, + token)) + { + free(token); + goto out; + } + free(token); + } + + if (!http_request_set_auth_scheme(request, "Bearer") || + !http_request_set_auth_param( + request, + freerdp_settings_get_string(arm->context->settings, FreeRDP_GatewayHttpExtAuthBearer))) + goto out; + + if (!http_request_set_transfer_encoding(request, transferEncoding) || + !http_request_set_content_length(request, content_length) || + !http_request_set_content_type(request, content_type)) + goto out; + + s = http_request_write(arm->http, request); +out: + http_request_free(request); + + if (s) + Stream_SealLength(s); + + return s; +} + +static BOOL arm_send_http_request(rdpArm* arm, rdpTls* tls, const char* method, + const char* content_type, const char* data, size_t content_length) +{ + int status = -1; + wStream* s = + arm_build_http_request(arm, method, TransferEncodingIdentity, content_type, content_length); + + if (!s) + return FALSE; + + const size_t sz = Stream_Length(s); + status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); + + Stream_Free(s, TRUE); + if (status >= 0 && content_length > 0 && data) + status = freerdp_tls_write_all(tls, (const BYTE*)data, content_length); + + return (status >= 0); +} + +static void arm_free(rdpArm* arm) +{ + if (!arm) + return; + + freerdp_tls_free(arm->tls); + http_context_free(arm->http); + + free(arm); +} + +static rdpArm* arm_new(rdpContext* context) +{ + WINPR_ASSERT(context); + + rdpArm* arm = (rdpArm*)calloc(1, sizeof(rdpArm)); + if (!arm) + goto fail; + + arm->log = WLog_Get(TAG); + arm->context = context; + arm->tls = freerdp_tls_new(context); + if (!arm->tls) + goto fail; + + arm->http = http_context_new(); + + if (!arm->http) + goto fail; + + return arm; + +fail: + arm_free(arm); + return NULL; +} + +static char* arm_create_request_json(rdpArm* arm) +{ + char* lbi = NULL; + char* message = NULL; + + WINPR_ASSERT(arm); + + WINPR_JSON* json = WINPR_JSON_CreateObject(); + if (!json) + goto arm_create_cleanup; + WINPR_JSON_AddStringToObject( + json, "application", + freerdp_settings_get_string(arm->context->settings, FreeRDP_RemoteApplicationProgram)); + + lbi = calloc( + freerdp_settings_get_uint32(arm->context->settings, FreeRDP_LoadBalanceInfoLength) + 1, + sizeof(char)); + if (!lbi) + goto arm_create_cleanup; + + const size_t len = + freerdp_settings_get_uint32(arm->context->settings, FreeRDP_LoadBalanceInfoLength); + memcpy(lbi, freerdp_settings_get_pointer(arm->context->settings, FreeRDP_LoadBalanceInfo), len); + + WINPR_JSON_AddStringToObject(json, "loadBalanceInfo", lbi); + WINPR_JSON_AddNullToObject(json, "LogonToken"); + WINPR_JSON_AddNullToObject(json, "gatewayLoadBalancerToken"); + + message = WINPR_JSON_PrintUnformatted(json); +arm_create_cleanup: + if (json) + WINPR_JSON_Delete(json); + free(lbi); + return message; +} + +/** + * @brief treats the redirectedAuthBlob + * + * sample pbInput: + * @code + * 41004500530000004b44424d01000000200000006ee71b295810b3fd13799da3825d0efa3a628e8f4a6eda609ffa975408556546 + * 'A\x00E\x00S\x00\x00\x00KDBM\x01\x00\x00\x00 + * \x00\x00\x00n\xe7\x1b)X\x10\xb3\xfd\x13y\x9d\xa3\x82]\x0e\xfa:b\x8e\x8fJn\xda`\x9f\xfa\x97T\x08UeF' + * @endcode + * + * @param pbInput the raw auth blob (base64 and utf16 decoded) + * @param cbInput size of pbInput + * @return the corresponding WINPR_CIPHER_CTX if success, NULL otherwise + */ +static WINPR_CIPHER_CTX* treatAuthBlob(wLog* log, const BYTE* pbInput, size_t cbInput) +{ + WINPR_CIPHER_CTX* ret = NULL; + char algoName[100] = { 0 }; + + SSIZE_T algoSz = ConvertWCharNToUtf8((const WCHAR*)pbInput, cbInput / sizeof(WCHAR), algoName, + sizeof(algoName)); + if (algoSz <= 0) + { + WLog_Print(log, WLOG_ERROR, "invalid algoName"); + return NULL; + } + + algoName[algoSz] = 0; + if (strcmp(algoName, "AES") != 0) + { + WLog_Print(log, WLOG_ERROR, "only AES is supported for now"); + return NULL; + } + + cbInput -= WINPR_ASSERTING_INT_CAST(size_t, (algoSz + 1)) * sizeof(WCHAR); + + if (cbInput < 12) + { + WLog_Print(log, WLOG_ERROR, "invalid AuthBlob size"); + return NULL; + } + + /* BCRYPT_KEY_DATA_BLOB_HEADER */ + wStream staticStream = { 0 }; + wStream* s = Stream_StaticConstInit( + &staticStream, pbInput + WINPR_ASSERTING_INT_CAST(size_t, (algoSz + 1)) * sizeof(WCHAR), + cbInput); + + UINT32 dwMagic = 0; + Stream_Read_UINT32(s, dwMagic); + + if (dwMagic != BCRYPT_KEY_DATA_BLOB_MAGIC) + { + WLog_Print(log, WLOG_ERROR, "unsupported authBlob type"); + return NULL; + } + + UINT32 dwVersion = 0; + Stream_Read_UINT32(s, dwVersion); + if (dwVersion != BCRYPT_KEY_DATA_BLOB_VERSION1) + { + WLog_Print(log, WLOG_ERROR, "unsupported authBlob version %d, expecting %d", dwVersion, + BCRYPT_KEY_DATA_BLOB_VERSION1); + return NULL; + } + + UINT32 cbKeyData = 0; + Stream_Read_UINT32(s, cbKeyData); + cbInput -= 12; + + if (cbKeyData > cbInput) + { + WLog_Print(log, WLOG_ERROR, "invalid authBlob size"); + return NULL; + } + + WINPR_CIPHER_TYPE cipherType = 0; + switch (cbKeyData) + { + case 16: + cipherType = WINPR_CIPHER_AES_128_CBC; + break; + case 24: + cipherType = WINPR_CIPHER_AES_192_CBC; + break; + case 32: + cipherType = WINPR_CIPHER_AES_256_CBC; + break; + default: + WLog_Print(log, WLOG_ERROR, "invalid authBlob cipher size"); + return NULL; + } + + ret = winpr_Cipher_NewEx(cipherType, WINPR_ENCRYPT, Stream_Pointer(s), cbKeyData, NULL, 0); + if (!ret) + { + WLog_Print(log, WLOG_ERROR, "error creating cipher"); + return NULL; + } + + if (!winpr_Cipher_SetPadding(ret, TRUE)) + { + WLog_Print(log, WLOG_ERROR, "unable to enable padding on cipher"); + winpr_Cipher_Free(ret); + return NULL; + } + + return ret; +} + +static BOOL arm_stringEncodeW(const BYTE* pin, size_t cbIn, BYTE** ppOut, size_t* pcbOut) +{ + *ppOut = NULL; + *pcbOut = 0; + + /* encode to base64 with crlf */ + char* b64encoded = crypto_base64_encode_ex(pin, cbIn, TRUE); + if (!b64encoded) + return FALSE; + + /* and then convert to Unicode */ + size_t outSz = 0; + *ppOut = (BYTE*)ConvertUtf8NToWCharAlloc(b64encoded, strlen(b64encoded), &outSz); + free(b64encoded); + + if (!*ppOut) + return FALSE; + + *pcbOut = (outSz + 1) * sizeof(WCHAR); + return TRUE; +} + +static BOOL arm_encodeRedirectPasswd(wLog* log, rdpSettings* settings, const rdpCertificate* cert, + WINPR_CIPHER_CTX* cipher) +{ + BOOL ret = FALSE; + BYTE* output = NULL; + BYTE* finalOutput = NULL; + + /* let's prepare the encrypted password, first we do a + * cipheredPass = AES(redirectedAuthBlob, toUtf16(passwd)) + */ + + size_t wpasswdLen = 0; + WCHAR* wpasswd = freerdp_settings_get_string_as_utf16(settings, FreeRDP_Password, &wpasswdLen); + if (!wpasswd) + { + WLog_Print(log, WLOG_ERROR, "error when converting password to UTF16"); + return FALSE; + } + + size_t wpasswdBytes = (wpasswdLen + 1) * sizeof(WCHAR); + BYTE* encryptedPass = calloc(1, wpasswdBytes + 16); /* 16: block size of AES (padding) */ + size_t encryptedPassLen = 0; + size_t finalLen = 0; + if (!encryptedPass || + !winpr_Cipher_Update(cipher, wpasswd, wpasswdBytes, encryptedPass, &encryptedPassLen) || + !winpr_Cipher_Final(cipher, encryptedPass + encryptedPassLen, &finalLen)) + { + WLog_Print(log, WLOG_ERROR, "error when ciphering password"); + goto out; + } + encryptedPassLen += finalLen; + + /* then encrypt(cipheredPass, publicKey(redirectedServerCert) */ + size_t output_length = 0; + + if (!freerdp_certificate_publickey_encrypt(cert, encryptedPass, encryptedPassLen, &output, + &output_length)) + { + WLog_Print(log, WLOG_ERROR, "unable to encrypt with the server's public key"); + goto out; + } + + size_t finalOutputLen = 0; + if (!arm_stringEncodeW(output, output_length, &finalOutput, &finalOutputLen)) + { + WLog_Print(log, WLOG_ERROR, "unable to base64+utf16 final blob"); + goto out; + } + + if (!freerdp_settings_set_pointer_len(settings, FreeRDP_RedirectionPassword, finalOutput, + finalOutputLen)) + { + WLog_Print(log, WLOG_ERROR, "unable to set the redirection password in settings"); + goto out; + } + + settings->RdstlsSecurity = TRUE; + settings->AadSecurity = FALSE; + settings->NlaSecurity = FALSE; + settings->RdpSecurity = FALSE; + settings->TlsSecurity = FALSE; + settings->RedirectionFlags = LB_PASSWORD_IS_PK_ENCRYPTED; + ret = TRUE; +out: + free(finalOutput); + free(output); + free(encryptedPass); + free(wpasswd); + return ret; +} + +/** extract that stupidly over-encoded field that is the equivalent of + * base64.b64decode( base64.b64decode(input).decode('utf-16') ) + * in python + */ +static BOOL arm_pick_base64Utf16Field(wLog* log, const WINPR_JSON* json, const char* name, + BYTE** poutput, size_t* plen) +{ + *poutput = NULL; + *plen = 0; + + WINPR_JSON* node = WINPR_JSON_GetObjectItemCaseSensitive(json, name); + if (!node || !WINPR_JSON_IsString(node)) + return TRUE; + + const char* nodeValue = WINPR_JSON_GetStringValue(node); + if (!nodeValue) + return TRUE; + + BYTE* output1 = NULL; + size_t len1 = 0; + crypto_base64_decode(nodeValue, strlen(nodeValue), &output1, &len1); + if (!output1 || !len1) + { + WLog_Print(log, WLOG_ERROR, "error when first unbase64 for %s", name); + free(output1); + return FALSE; + } + + size_t len2 = 0; + char* output2 = ConvertWCharNToUtf8Alloc((WCHAR*)output1, len1 / sizeof(WCHAR), &len2); + free(output1); + if (!output2 || !len2) + { + WLog_Print(log, WLOG_ERROR, "error when decode('utf-16') for %s", name); + free(output2); + return FALSE; + } + + BYTE* output = NULL; + crypto_base64_decode(output2, len2, &output, plen); + free(output2); + if (!output || !*plen) + { + WLog_Print(log, WLOG_ERROR, "error when second unbase64 for %s", name); + free(output); + return FALSE; + } + + *poutput = output; + return TRUE; +} + +/** + * treats the Azure network meta data that will typically look like: + * + * {'interface': [ + * {'ipv4': { + * 'ipAddress': [ + * {'privateIpAddress': 'X.X.X.X', + * 'publicIpAddress': 'X.X.X.X'} + * ], + * 'subnet': [ + * {'address': 'X.X.X.X', 'prefix': '24'} + * ] + * }, + * 'ipv6': {'ipAddress': []}, + * 'macAddress': 'YYYYYYY'} + * ] + * } + * + */ + +static size_t arm_parse_ipvx_count(WINPR_JSON* ipvX) +{ + WINPR_ASSERT(ipvX); + WINPR_JSON* ipAddress = WINPR_JSON_GetObjectItem(ipvX, "ipAddress"); + if (!ipAddress || !WINPR_JSON_IsArray(ipAddress)) + return 0; + return WINPR_JSON_GetArraySize(ipAddress); +} + +static BOOL arm_parse_ipv6(rdpSettings* settings, WINPR_JSON* ipv6, size_t* pAddressIdx) +{ + WINPR_ASSERT(settings); + WINPR_ASSERT(ipv6); + WINPR_ASSERT(pAddressIdx); + + if (!freerdp_settings_get_bool(settings, FreeRDP_IPv6Enabled)) + return TRUE; + + WINPR_JSON* ipAddress = WINPR_JSON_GetObjectItem(ipv6, "ipAddress"); + if (!ipAddress || !WINPR_JSON_IsArray(ipAddress)) + return TRUE; + const size_t naddresses = WINPR_JSON_GetArraySize(ipAddress); + for (size_t j = 0; j < naddresses; j++) + { + WINPR_JSON* adressN = WINPR_JSON_GetArrayItem(ipAddress, j); + if (!adressN || !WINPR_JSON_IsString(adressN)) + continue; + + const char* addr = WINPR_JSON_GetStringValue(adressN); + if (utils_str_is_empty(addr)) + continue; + if (!freerdp_settings_set_pointer_array(settings, FreeRDP_TargetNetAddresses, + (*pAddressIdx)++, addr)) + return FALSE; + } + return TRUE; +} + +static BOOL arm_parse_ipv4(rdpSettings* settings, WINPR_JSON* ipv4, size_t* pAddressIdx) +{ + WINPR_ASSERT(settings); + WINPR_ASSERT(ipv4); + WINPR_ASSERT(pAddressIdx); + + WINPR_JSON* ipAddress = WINPR_JSON_GetObjectItem(ipv4, "ipAddress"); + if (!ipAddress || !WINPR_JSON_IsArray(ipAddress)) + return TRUE; + + const size_t naddresses = WINPR_JSON_GetArraySize(ipAddress); + for (size_t j = 0; j < naddresses; j++) + { + WINPR_JSON* adressN = WINPR_JSON_GetArrayItem(ipAddress, j); + if (!adressN) + continue; + + WINPR_JSON* publicIpNode = WINPR_JSON_GetObjectItem(adressN, "publicIpAddress"); + if (publicIpNode && WINPR_JSON_IsString(publicIpNode)) + { + const char* publicIp = WINPR_JSON_GetStringValue(publicIpNode); + if (!utils_str_is_empty(publicIp)) + { + if (!freerdp_settings_set_pointer_array(settings, FreeRDP_TargetNetAddresses, + (*pAddressIdx)++, publicIp)) + return FALSE; + } + } + + WINPR_JSON* privateIpNode = WINPR_JSON_GetObjectItem(adressN, "privateIpAddress"); + if (privateIpNode && WINPR_JSON_IsString(privateIpNode)) + { + const char* privateIp = WINPR_JSON_GetStringValue(privateIpNode); + if (!utils_str_is_empty(privateIp)) + { + if (!freerdp_settings_set_pointer_array(settings, FreeRDP_TargetNetAddresses, + (*pAddressIdx)++, privateIp)) + return FALSE; + } + } + } + return TRUE; +} + +static BOOL arm_treat_azureInstanceNetworkMetadata(wLog* log, const char* metadata, + rdpSettings* settings) +{ + BOOL ret = FALSE; + + WINPR_ASSERT(settings); + + if (!freerdp_target_net_adresses_reset(settings, 0)) + return FALSE; + + WINPR_JSON* json = WINPR_JSON_Parse(metadata); + if (!json) + { + WLog_Print(log, WLOG_ERROR, "invalid azureInstanceNetworkMetadata"); + return FALSE; + } + + WINPR_JSON* iface = WINPR_JSON_GetObjectItem(json, "interface"); + if (!iface) + { + ret = TRUE; + goto out; + } + + if (!WINPR_JSON_IsArray(iface)) + { + WLog_Print(log, WLOG_ERROR, "expecting interface to be an Array"); + goto out; + } + + size_t interfaceSz = WINPR_JSON_GetArraySize(iface); + if (interfaceSz == 0) + { + WLog_WARN(TAG, "no addresses in azure instance metadata"); + ret = TRUE; + goto out; + } + + size_t count = 0; + for (size_t i = 0; i < interfaceSz; i++) + { + WINPR_JSON* interN = WINPR_JSON_GetArrayItem(iface, i); + if (!interN) + continue; + + WINPR_JSON* ipv6 = WINPR_JSON_GetObjectItem(interN, "ipv6"); + if (ipv6) + count += arm_parse_ipvx_count(ipv6); + + WINPR_JSON* ipv4 = WINPR_JSON_GetObjectItem(interN, "ipv4"); + if (ipv4) + count += arm_parse_ipvx_count(ipv4); + } + + if (!freerdp_target_net_adresses_reset(settings, count)) + return FALSE; + + size_t addressIdx = 0; + for (size_t i = 0; i < interfaceSz; i++) + { + WINPR_JSON* interN = WINPR_JSON_GetArrayItem(iface, i); + if (!interN) + continue; + + WINPR_JSON* ipv6 = WINPR_JSON_GetObjectItem(interN, "ipv6"); + if (ipv6) + { + if (!arm_parse_ipv6(settings, ipv6, &addressIdx)) + goto out; + } + + WINPR_JSON* ipv4 = WINPR_JSON_GetObjectItem(interN, "ipv4"); + if (ipv4) + { + if (!arm_parse_ipv4(settings, ipv4, &addressIdx)) + goto out; + } + } + if (addressIdx > UINT32_MAX) + goto out; + + if (!freerdp_settings_set_uint32(settings, FreeRDP_TargetNetAddressCount, (UINT32)addressIdx)) + goto out; + + ret = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount) > 0; + +out: + WINPR_JSON_Delete(json); + return ret; +} + +static BOOL arm_fill_rdstls(rdpArm* arm, rdpSettings* settings, const WINPR_JSON* json) +{ + BOOL ret = TRUE; + BYTE* cert = NULL; + BYTE* authBlob = NULL; + rdpCertificate* redirectedServerCert = NULL; + + do + { + /* redirectedAuthGuid */ + WINPR_JSON* redirectedAuthGuidNode = + WINPR_JSON_GetObjectItemCaseSensitive(json, "redirectedAuthGuid"); + if (!redirectedAuthGuidNode || !WINPR_JSON_IsString(redirectedAuthGuidNode)) + break; + + const char* redirectedAuthGuid = WINPR_JSON_GetStringValue(redirectedAuthGuidNode); + if (!redirectedAuthGuid) + break; + + WCHAR wGUID[72] = { + 0 + }; /* A GUID string is between 32 and 68 characters as string, depending on representation. + Add a few extra bytes for braces et al */ + const SSIZE_T wGUID_len = ConvertUtf8ToWChar(redirectedAuthGuid, wGUID, ARRAYSIZE(wGUID)); + if (wGUID_len < 0) + { + WLog_Print(arm->log, WLOG_ERROR, "unable to allocate space for redirectedAuthGuid"); + ret = FALSE; + goto endOfFunction; + } + + BOOL status = freerdp_settings_set_pointer_len( + settings, FreeRDP_RedirectionGuid, wGUID, + WINPR_ASSERTING_INT_CAST(size_t, (wGUID_len + 1)) * sizeof(WCHAR)); + if (!status) + { + WLog_Print(arm->log, WLOG_ERROR, "unable to set RedirectionGuid"); + ret = FALSE; + goto endOfFunction; + } + + /* redirectedServerCert */ + size_t certLen = 0; + if (!arm_pick_base64Utf16Field(arm->log, json, "redirectedServerCert", &cert, &certLen)) + break; + + if (!rdp_redirection_read_target_cert(&redirectedServerCert, cert, certLen)) + break; + + /* redirectedAuthBlob */ + size_t authBlobLen = 0; + if (!arm_pick_base64Utf16Field(arm->log, json, "redirectedAuthBlob", &authBlob, + &authBlobLen)) + break; + + WINPR_CIPHER_CTX* cipher = treatAuthBlob(arm->log, authBlob, authBlobLen); + if (!cipher) + break; + + const BOOL rerp = + arm_encodeRedirectPasswd(arm->log, settings, redirectedServerCert, cipher); + winpr_Cipher_Free(cipher); + if (!rerp) + break; + + ret = TRUE; + } while (FALSE); + + free(cert); + freerdp_certificate_free(redirectedServerCert); + free(authBlob); + +endOfFunction: + return ret; +} + +static BOOL arm_fill_gateway_parameters(rdpArm* arm, const char* message, size_t len) +{ + WINPR_ASSERT(arm); + WINPR_ASSERT(arm->context); + WINPR_ASSERT(message); + + WINPR_JSON* json = WINPR_JSON_ParseWithLength(message, len); + BOOL status = FALSE; + if (!json) + return FALSE; + + rdpSettings* settings = arm->context->settings; + WINPR_JSON* gwurl = WINPR_JSON_GetObjectItemCaseSensitive(json, "gatewayLocation"); + const char* gwurlstr = WINPR_JSON_GetStringValue(gwurl); + if (gwurlstr != NULL) + { + WLog_Print(arm->log, WLOG_DEBUG, "extracted target url %s", gwurlstr); + if (!freerdp_settings_set_string(settings, FreeRDP_GatewayUrl, gwurlstr)) + status = FALSE; + else + status = TRUE; + } + + WINPR_JSON* serverNameNode = WINPR_JSON_GetObjectItem(json, "redirectedServerName"); + if (serverNameNode) + { + const char* serverName = WINPR_JSON_GetStringValue(serverNameNode); + if (serverName) + status = freerdp_settings_set_string(settings, FreeRDP_ServerHostname, serverName); + } + + WINPR_JSON* azureMeta = WINPR_JSON_GetObjectItem(json, "azureInstanceNetworkMetadata"); + if (azureMeta && WINPR_JSON_IsString(azureMeta)) + { + if (!arm_treat_azureInstanceNetworkMetadata(arm->log, WINPR_JSON_GetStringValue(azureMeta), + settings)) + { + WLog_Print(arm->log, WLOG_ERROR, "error when treating azureInstanceNetworkMetadata"); + } + } + + if (freerdp_settings_get_string(settings, FreeRDP_Password)) + { + /* note: we retrieve some more fields for RDSTLS only if we have a password provided by the + * user, otherwise these are useless: we will not be able to do RDSTLS + */ + status = arm_fill_rdstls(arm, settings, json); + } + + WINPR_JSON_Delete(json); + return status; +} + +static BOOL arm_handle_request_ok(rdpArm* arm, const HttpResponse* response) +{ + const size_t len = http_response_get_body_length(response); + const char* msg = (const char*)http_response_get_body(response); + if (strnlen(msg, len + 1) > len) + return FALSE; + + WLog_Print(arm->log, WLOG_DEBUG, "Got HTTP Response data: %s", msg); + return arm_fill_gateway_parameters(arm, msg, len); +} + +static BOOL arm_handle_bad_request(rdpArm* arm, const HttpResponse* response, BOOL* retry) +{ + WINPR_ASSERT(response); + WINPR_ASSERT(retry); + + *retry = FALSE; + + BOOL rc = FALSE; + + const size_t len = http_response_get_body_length(response); + const char* msg = (const char*)http_response_get_body(response); + if (strnlen(msg, len + 1) > len) + return FALSE; + + WLog_Print(arm->log, WLOG_DEBUG, "Got HTTP Response data: %s", msg); + + WINPR_JSON* json = WINPR_JSON_ParseWithLength(msg, len); + if (json == NULL) + { + const char* error_ptr = WINPR_JSON_GetErrorPtr(); + if (error_ptr != NULL) + WLog_Print(arm->log, WLOG_ERROR, "NullPoException: %s", error_ptr); + + return FALSE; + } + + WINPR_JSON* gateway_code_obj = WINPR_JSON_GetObjectItemCaseSensitive(json, "Code"); + const char* gw_code_str = WINPR_JSON_GetStringValue(gateway_code_obj); + if (gw_code_str == NULL) + { + WLog_Print(arm->log, WLOG_ERROR, "Response has no \"Code\" property"); + http_response_log_error_status(WLog_Get(TAG), WLOG_ERROR, response); + goto fail; + } + + if (strcmp(gw_code_str, "E_PROXY_ORCHESTRATION_LB_SESSIONHOST_DEALLOCATED") == 0) + { + *retry = TRUE; + WINPR_JSON* message = WINPR_JSON_GetObjectItemCaseSensitive(json, "Message"); + const char* msgstr = WINPR_JSON_GetStringValue(message); + if (!msgstr) + WLog_WARN(TAG, "Starting your VM. It may take up to 5 minutes"); + else + WLog_WARN(TAG, "%s", msgstr); + } + else + { + http_response_log_error_status(WLog_Get(TAG), WLOG_ERROR, response); + goto fail; + } + + rc = TRUE; +fail: + WINPR_JSON_Delete(json); + return rc; +} + +static BOOL arm_handle_request(rdpArm* arm, BOOL* retry, DWORD timeout) +{ + WINPR_ASSERT(retry); + + if (!arm_fetch_wellknown(arm)) + { + *retry = TRUE; + return FALSE; + } + + *retry = FALSE; + + char* message = NULL; + BOOL rc = FALSE; + + HttpResponse* response = NULL; + long StatusCode = 0; + + if (!http_context_set_uri(arm->http, "/api/arm/v2/connections/") || + !http_context_set_accept(arm->http, "application/json") || + !http_context_set_cache_control(arm->http, "no-cache") || + !http_context_set_pragma(arm->http, "no-cache") || + !http_context_set_connection(arm->http, "Keep-Alive") || + !http_context_set_user_agent(arm->http, FREERDP_USER_AGENT) || + !http_context_set_x_ms_user_agent(arm->http, FREERDP_USER_AGENT) || + !http_context_set_host(arm->http, freerdp_settings_get_string(arm->context->settings, + FreeRDP_GatewayHostname))) + goto arm_error; + + if (!arm_tls_connect(arm, arm->tls, timeout)) + goto arm_error; + + message = arm_create_request_json(arm); + if (!message) + goto arm_error; + + if (!arm_send_http_request(arm, arm->tls, "POST", "application/json", message, strlen(message))) + goto arm_error; + + response = http_response_recv(arm->tls, TRUE); + if (!response) + goto arm_error; + + StatusCode = http_response_get_status_code(response); + if (StatusCode == HTTP_STATUS_OK) + { + if (!arm_handle_request_ok(arm, response)) + goto arm_error; + } + else if (StatusCode == HTTP_STATUS_BAD_REQUEST) + { + if (!arm_handle_bad_request(arm, response, retry)) + goto arm_error; + } + else + { + http_response_log_error_status(WLog_Get(TAG), WLOG_ERROR, response); + goto arm_error; + } + + rc = TRUE; +arm_error: + http_response_free(response); + free(message); + return rc; +} + +#endif + +BOOL arm_resolve_endpoint(wLog* log, rdpContext* context, DWORD timeout) +{ +#ifndef WITH_AAD + WLog_Print(log, WLOG_ERROR, "arm gateway support not compiled in"); + return FALSE; +#else + + if (!context) + return FALSE; + + if (!context->settings) + return FALSE; + + if ((freerdp_settings_get_uint32(context->settings, FreeRDP_LoadBalanceInfoLength) == 0) || + (freerdp_settings_get_string(context->settings, FreeRDP_RemoteApplicationProgram) == NULL)) + { + WLog_Print(log, WLOG_ERROR, "loadBalanceInfo and RemoteApplicationProgram needed"); + return FALSE; + } + + rdpArm* arm = arm_new(context); + if (!arm) + return FALSE; + + BOOL retry = FALSE; + BOOL rc = FALSE; + do + { + if (retry && rc) + { + freerdp* instance = context->instance; + WINPR_ASSERT(instance); + SSIZE_T delay = IFCALLRESULT(-1, instance->RetryDialog, instance, "arm-transport", + arm->gateway_retry, arm); + arm->gateway_retry++; + if (delay <= 0) + break; /* error or no retry desired, abort loop */ + else + { + WLog_Print(arm->log, WLOG_DEBUG, "Delay for %" PRIdz "ms before next attempt", + delay); + while (delay > 0) + { + DWORD slp = (UINT32)delay; + if (delay > UINT32_MAX) + slp = UINT32_MAX; + Sleep(slp); + delay -= slp; + } + } + } + rc = arm_handle_request(arm, &retry, timeout); + + } while (retry && rc); + arm_free(arm); + return rc; +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/arm.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/arm.h new file mode 100644 index 0000000000000000000000000000000000000000..5f6764508ab45219a7a336c556c47d7aa3659818 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/arm.h @@ -0,0 +1,31 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Azure Virtual Desktop Gateway / Azure Resource Manager + * + * Copyright 2023 Michael Saxl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_ARM_H +#define FREERDP_LIB_CORE_GATEWAY_ARM_H + +#include +#include + +#include +#include + +FREERDP_LOCAL BOOL arm_resolve_endpoint(wLog* log, rdpContext* context, DWORD timeout); + +#endif /* FREERDP_LIB_CORE_GATEWAY_ARM_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/http.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/http.c new file mode 100644 index 0000000000000000000000000000000000000000..d6f03962cc0e11a18ef2ad6df9be5155051031be --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/http.c @@ -0,0 +1,1730 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Hypertext Transfer Protocol (HTTP) + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +/* websocket need sha1 for Sec-Websocket-Accept */ +#include + +#ifdef FREERDP_HAVE_VALGRIND_MEMCHECK_H +#include +#endif + +#include "http.h" +#include "../tcp.h" + +#define TAG FREERDP_TAG("core.gateway.http") + +#define RESPONSE_SIZE_LIMIT (64ULL * 1024ULL * 1024ULL) + +#define WEBSOCKET_MAGIC_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" + +struct s_http_context +{ + char* Method; + char* URI; + char* UserAgent; + char* X_MS_UserAgent; + char* Host; + char* Accept; + char* CacheControl; + char* Connection; + char* Pragma; + char* RdgConnectionId; + char* RdgCorrelationId; + char* RdgAuthScheme; + BOOL websocketUpgrade; + char* SecWebsocketKey; + wListDictionary* cookies; +}; + +struct s_http_request +{ + char* Method; + char* URI; + char* AuthScheme; + char* AuthParam; + char* Authorization; + size_t ContentLength; + char* ContentType; + TRANSFER_ENCODING TransferEncoding; +}; + +struct s_http_response +{ + size_t count; + char** lines; + + INT16 StatusCode; + const char* ReasonPhrase; + + size_t ContentLength; + const char* ContentType; + TRANSFER_ENCODING TransferEncoding; + const char* SecWebsocketVersion; + const char* SecWebsocketAccept; + + size_t BodyLength; + BYTE* BodyContent; + + wListDictionary* Authenticates; + wListDictionary* SetCookie; + wStream* data; +}; + +static char* string_strnstr(char* str1, const char* str2, size_t slen) +{ + char c = 0; + char sc = 0; + size_t len = 0; + + if ((c = *str2++) != '\0') + { + len = strnlen(str2, slen + 1); + + do + { + do + { + if (slen-- < 1 || (sc = *str1++) == '\0') + return NULL; + } while (sc != c); + + if (len > slen) + return NULL; + } while (strncmp(str1, str2, len) != 0); + + str1--; + } + + return str1; +} + +static BOOL strings_equals_nocase(const void* obj1, const void* obj2) +{ + if (!obj1 || !obj2) + return FALSE; + + return _stricmp(obj1, obj2) == 0; +} + +HttpContext* http_context_new(void) +{ + HttpContext* context = (HttpContext*)calloc(1, sizeof(HttpContext)); + if (!context) + return NULL; + + context->cookies = ListDictionary_New(FALSE); + if (!context->cookies) + goto fail; + + wObject* key = ListDictionary_KeyObject(context->cookies); + wObject* value = ListDictionary_ValueObject(context->cookies); + if (!key || !value) + goto fail; + + key->fnObjectFree = winpr_ObjectStringFree; + key->fnObjectNew = winpr_ObjectStringClone; + value->fnObjectFree = winpr_ObjectStringFree; + value->fnObjectNew = winpr_ObjectStringClone; + + return context; + +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + http_context_free(context); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +BOOL http_context_set_method(HttpContext* context, const char* Method) +{ + if (!context || !Method) + return FALSE; + + free(context->Method); + context->Method = _strdup(Method); + + if (!context->Method) + return FALSE; + + return TRUE; +} + +BOOL http_request_set_content_type(HttpRequest* request, const char* ContentType) +{ + if (!request || !ContentType) + return FALSE; + + free(request->ContentType); + request->ContentType = _strdup(ContentType); + + if (!request->ContentType) + return FALSE; + + return TRUE; +} + +const char* http_context_get_uri(HttpContext* context) +{ + if (!context) + return NULL; + + return context->URI; +} + +BOOL http_context_set_uri(HttpContext* context, const char* URI) +{ + if (!context || !URI) + return FALSE; + + free(context->URI); + context->URI = _strdup(URI); + + if (!context->URI) + return FALSE; + + return TRUE; +} + +BOOL http_context_set_user_agent(HttpContext* context, const char* UserAgent) +{ + if (!context || !UserAgent) + return FALSE; + + free(context->UserAgent); + context->UserAgent = _strdup(UserAgent); + + if (!context->UserAgent) + return FALSE; + + return TRUE; +} + +BOOL http_context_set_x_ms_user_agent(HttpContext* context, const char* X_MS_UserAgent) +{ + if (!context || !X_MS_UserAgent) + return FALSE; + + free(context->X_MS_UserAgent); + context->X_MS_UserAgent = _strdup(X_MS_UserAgent); + + if (!context->X_MS_UserAgent) + return FALSE; + + return TRUE; +} + +BOOL http_context_set_host(HttpContext* context, const char* Host) +{ + if (!context || !Host) + return FALSE; + + free(context->Host); + context->Host = _strdup(Host); + + if (!context->Host) + return FALSE; + + return TRUE; +} + +BOOL http_context_set_accept(HttpContext* context, const char* Accept) +{ + if (!context || !Accept) + return FALSE; + + free(context->Accept); + context->Accept = _strdup(Accept); + + if (!context->Accept) + return FALSE; + + return TRUE; +} + +BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl) +{ + if (!context || !CacheControl) + return FALSE; + + free(context->CacheControl); + context->CacheControl = _strdup(CacheControl); + + if (!context->CacheControl) + return FALSE; + + return TRUE; +} + +BOOL http_context_set_connection(HttpContext* context, const char* Connection) +{ + if (!context || !Connection) + return FALSE; + + free(context->Connection); + context->Connection = _strdup(Connection); + + if (!context->Connection) + return FALSE; + + return TRUE; +} + +WINPR_ATTR_FORMAT_ARG(2, 0) +static BOOL list_append(HttpContext* context, WINPR_FORMAT_ARG const char* str, va_list ap) +{ + BOOL rc = FALSE; + va_list vat; + char* Pragma = NULL; + size_t PragmaSize = 0; + + va_copy(vat, ap); + const int size = winpr_vasprintf(&Pragma, &PragmaSize, str, ap); + va_end(vat); + + if (size <= 0) + goto fail; + + char* sstr = NULL; + size_t slen = 0; + if (context->Pragma) + { + winpr_asprintf(&sstr, &slen, "%s, %s", context->Pragma, Pragma); + free(Pragma); + } + else + sstr = Pragma; + Pragma = NULL; + + free(context->Pragma); + context->Pragma = sstr; + + rc = TRUE; + +fail: + va_end(ap); + return rc; +} + +WINPR_ATTR_FORMAT_ARG(2, 3) +BOOL http_context_set_pragma(HttpContext* context, WINPR_FORMAT_ARG const char* Pragma, ...) +{ + if (!context || !Pragma) + return FALSE; + + free(context->Pragma); + context->Pragma = NULL; + + va_list ap = { 0 }; + va_start(ap, Pragma); + return list_append(context, Pragma, ap); +} + +WINPR_ATTR_FORMAT_ARG(2, 3) +BOOL http_context_append_pragma(HttpContext* context, const char* Pragma, ...) +{ + if (!context || !Pragma) + return FALSE; + + va_list ap = { 0 }; + va_start(ap, Pragma); + return list_append(context, Pragma, ap); +} + +static char* guid2str(const GUID* guid) +{ + if (!guid) + return NULL; + char* strguid = NULL; + char bracedGuid[64] = { 0 }; + + RPC_STATUS rpcStatus = UuidToStringA(guid, &strguid); + + if (rpcStatus != RPC_S_OK) + return NULL; + + (void)sprintf_s(bracedGuid, sizeof(bracedGuid), "{%s}", strguid); + RpcStringFreeA(&strguid); + return _strdup(bracedGuid); +} + +BOOL http_context_set_rdg_connection_id(HttpContext* context, const GUID* RdgConnectionId) +{ + if (!context || !RdgConnectionId) + return FALSE; + + free(context->RdgConnectionId); + context->RdgConnectionId = guid2str(RdgConnectionId); + + if (!context->RdgConnectionId) + return FALSE; + + return TRUE; +} + +BOOL http_context_set_rdg_correlation_id(HttpContext* context, const GUID* RdgCorrelationId) +{ + if (!context || !RdgCorrelationId) + return FALSE; + + free(context->RdgCorrelationId); + context->RdgCorrelationId = guid2str(RdgCorrelationId); + + if (!context->RdgCorrelationId) + return FALSE; + + return TRUE; +} + +BOOL http_context_enable_websocket_upgrade(HttpContext* context, BOOL enable) +{ + if (!context) + return FALSE; + + if (enable) + { + GUID key = { 0 }; + if (RPC_S_OK != UuidCreate(&key)) + return FALSE; + + free(context->SecWebsocketKey); + context->SecWebsocketKey = crypto_base64_encode((BYTE*)&key, sizeof(key)); + if (!context->SecWebsocketKey) + return FALSE; + } + + context->websocketUpgrade = enable; + return TRUE; +} + +BOOL http_context_is_websocket_upgrade_enabled(HttpContext* context) +{ + return context->websocketUpgrade; +} + +BOOL http_context_set_rdg_auth_scheme(HttpContext* context, const char* RdgAuthScheme) +{ + if (!context || !RdgAuthScheme) + return FALSE; + + free(context->RdgAuthScheme); + context->RdgAuthScheme = _strdup(RdgAuthScheme); + return context->RdgAuthScheme != NULL; +} + +BOOL http_context_set_cookie(HttpContext* context, const char* CookieName, const char* CookieValue) +{ + if (!context || !CookieName || !CookieValue) + return FALSE; + if (ListDictionary_Contains(context->cookies, CookieName)) + { + if (!ListDictionary_SetItemValue(context->cookies, CookieName, CookieValue)) + return FALSE; + } + else + { + if (!ListDictionary_Add(context->cookies, CookieName, CookieValue)) + return FALSE; + } + return TRUE; +} + +void http_context_free(HttpContext* context) +{ + if (context) + { + free(context->SecWebsocketKey); + free(context->UserAgent); + free(context->X_MS_UserAgent); + free(context->Host); + free(context->URI); + free(context->Accept); + free(context->Method); + free(context->CacheControl); + free(context->Connection); + free(context->Pragma); + free(context->RdgConnectionId); + free(context->RdgCorrelationId); + free(context->RdgAuthScheme); + ListDictionary_Free(context->cookies); + free(context); + } +} + +BOOL http_request_set_method(HttpRequest* request, const char* Method) +{ + if (!request || !Method) + return FALSE; + + free(request->Method); + request->Method = _strdup(Method); + + if (!request->Method) + return FALSE; + + return TRUE; +} + +BOOL http_request_set_uri(HttpRequest* request, const char* URI) +{ + if (!request || !URI) + return FALSE; + + free(request->URI); + request->URI = _strdup(URI); + + if (!request->URI) + return FALSE; + + return TRUE; +} + +BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme) +{ + if (!request || !AuthScheme) + return FALSE; + + free(request->AuthScheme); + request->AuthScheme = _strdup(AuthScheme); + + if (!request->AuthScheme) + return FALSE; + + return TRUE; +} + +BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam) +{ + if (!request || !AuthParam) + return FALSE; + + free(request->AuthParam); + request->AuthParam = _strdup(AuthParam); + + if (!request->AuthParam) + return FALSE; + + return TRUE; +} + +BOOL http_request_set_transfer_encoding(HttpRequest* request, TRANSFER_ENCODING TransferEncoding) +{ + if (!request || TransferEncoding == TransferEncodingUnknown) + return FALSE; + + request->TransferEncoding = TransferEncoding; + + return TRUE; +} + +WINPR_ATTR_FORMAT_ARG(2, 3) +static BOOL http_encode_print(wStream* s, WINPR_FORMAT_ARG const char* fmt, ...) +{ + char* str = NULL; + va_list ap = { 0 }; + int length = 0; + int used = 0; + + if (!s || !fmt) + return FALSE; + + va_start(ap, fmt); + length = vsnprintf(NULL, 0, fmt, ap) + 1; + va_end(ap); + + if (!Stream_EnsureRemainingCapacity(s, (size_t)length)) + return FALSE; + + str = (char*)Stream_Pointer(s); + va_start(ap, fmt); + used = vsnprintf(str, (size_t)length, fmt, ap); + va_end(ap); + + /* Strip the trailing '\0' from the string. */ + if ((used + 1) != length) + return FALSE; + + Stream_Seek(s, (size_t)used); + return TRUE; +} + +static BOOL http_encode_body_line(wStream* s, const char* param, const char* value) +{ + if (!s || !param || !value) + return FALSE; + + return http_encode_print(s, "%s: %s\r\n", param, value); +} + +static BOOL http_encode_content_length_line(wStream* s, size_t ContentLength) +{ + return http_encode_print(s, "Content-Length: %" PRIuz "\r\n", ContentLength); +} + +static BOOL http_encode_header_line(wStream* s, const char* Method, const char* URI) +{ + if (!s || !Method || !URI) + return FALSE; + + return http_encode_print(s, "%s %s HTTP/1.1\r\n", Method, URI); +} + +static BOOL http_encode_authorization_line(wStream* s, const char* AuthScheme, + const char* AuthParam) +{ + if (!s || !AuthScheme || !AuthParam) + return FALSE; + + return http_encode_print(s, "Authorization: %s %s\r\n", AuthScheme, AuthParam); +} + +static BOOL http_encode_cookie_line(wStream* s, wListDictionary* cookies) +{ + ULONG_PTR* keys = NULL; + BOOL status = TRUE; + + if (!s && !cookies) + return FALSE; + + ListDictionary_Lock(cookies); + const size_t count = ListDictionary_GetKeys(cookies, &keys); + + if (count == 0) + goto unlock; + + status = http_encode_print(s, "Cookie: "); + if (!status) + goto unlock; + + for (size_t x = 0; status && x < count; x++) + { + char* cur = (char*)ListDictionary_GetItemValue(cookies, (void*)keys[x]); + if (!cur) + { + status = FALSE; + continue; + } + if (x > 0) + { + status = http_encode_print(s, "; "); + if (!status) + continue; + } + status = http_encode_print(s, "%s=%s", (char*)keys[x], cur); + } + + status = http_encode_print(s, "\r\n"); +unlock: + free(keys); + ListDictionary_Unlock(cookies); + return status; +} + +wStream* http_request_write(HttpContext* context, HttpRequest* request) +{ + wStream* s = NULL; + + if (!context || !request) + return NULL; + + s = Stream_New(NULL, 1024); + + if (!s) + return NULL; + + if (!http_encode_header_line(s, request->Method, request->URI) || + !http_encode_body_line(s, "Cache-Control", context->CacheControl) || + !http_encode_body_line(s, "Pragma", context->Pragma) || + !http_encode_body_line(s, "Accept", context->Accept) || + !http_encode_body_line(s, "User-Agent", context->UserAgent) || + !http_encode_body_line(s, "Host", context->Host)) + goto fail; + + if (!context->websocketUpgrade) + { + if (!http_encode_body_line(s, "Connection", context->Connection)) + goto fail; + } + else + { + if (!http_encode_body_line(s, "Connection", "Upgrade") || + !http_encode_body_line(s, "Upgrade", "websocket") || + !http_encode_body_line(s, "Sec-Websocket-Version", "13") || + !http_encode_body_line(s, "Sec-Websocket-Key", context->SecWebsocketKey)) + goto fail; + } + + if (context->RdgConnectionId) + { + if (!http_encode_body_line(s, "RDG-Connection-Id", context->RdgConnectionId)) + goto fail; + } + + if (context->RdgCorrelationId) + { + if (!http_encode_body_line(s, "RDG-Correlation-Id", context->RdgCorrelationId)) + goto fail; + } + + if (context->RdgAuthScheme) + { + if (!http_encode_body_line(s, "RDG-Auth-Scheme", context->RdgAuthScheme)) + goto fail; + } + + if (request->TransferEncoding != TransferEncodingIdentity) + { + if (request->TransferEncoding == TransferEncodingChunked) + { + if (!http_encode_body_line(s, "Transfer-Encoding", "chunked")) + goto fail; + } + else + goto fail; + } + else + { + if (!http_encode_content_length_line(s, request->ContentLength)) + goto fail; + } + + if (request->Authorization) + { + if (!http_encode_body_line(s, "Authorization", request->Authorization)) + goto fail; + } + else if (request->AuthScheme && request->AuthParam) + { + if (!http_encode_authorization_line(s, request->AuthScheme, request->AuthParam)) + goto fail; + } + + if (context->cookies) + { + if (!http_encode_cookie_line(s, context->cookies)) + goto fail; + } + + if (request->ContentType) + { + if (!http_encode_body_line(s, "Content-Type", request->ContentType)) + goto fail; + } + + if (context->X_MS_UserAgent) + { + if (!http_encode_body_line(s, "X-MS-User-Agent", context->X_MS_UserAgent)) + goto fail; + } + + if (!http_encode_print(s, "\r\n")) + goto fail; + + Stream_SealLength(s); + return s; +fail: + Stream_Free(s, TRUE); + return NULL; +} + +HttpRequest* http_request_new(void) +{ + HttpRequest* request = (HttpRequest*)calloc(1, sizeof(HttpRequest)); + if (!request) + return NULL; + + request->TransferEncoding = TransferEncodingIdentity; + return request; +} + +void http_request_free(HttpRequest* request) +{ + if (!request) + return; + + free(request->AuthParam); + free(request->AuthScheme); + free(request->Authorization); + free(request->ContentType); + free(request->Method); + free(request->URI); + free(request); +} + +static BOOL http_response_parse_header_status_line(HttpResponse* response, const char* status_line) +{ + BOOL rc = FALSE; + char* separator = NULL; + char* status_code = NULL; + char* reason_phrase = NULL; + + if (!response) + goto fail; + + if (status_line) + separator = strchr(status_line, ' '); + + if (!separator) + goto fail; + + status_code = separator + 1; + separator = strchr(status_code, ' '); + + if (!separator) + goto fail; + + reason_phrase = separator + 1; + *separator = '\0'; + errno = 0; + { + long val = strtol(status_code, NULL, 0); + + if ((errno != 0) || (val < 0) || (val > INT16_MAX)) + goto fail; + + response->StatusCode = (INT16)val; + } + response->ReasonPhrase = reason_phrase; + + if (!response->ReasonPhrase) + goto fail; + + *separator = ' '; + rc = TRUE; +fail: + + if (!rc) + WLog_ERR(TAG, "http_response_parse_header_status_line failed [%s]", status_line); + + return rc; +} + +static BOOL http_response_parse_header_field(HttpResponse* response, const char* name, + const char* value) +{ + BOOL status = TRUE; + + WINPR_ASSERT(response); + + if (!name) + return FALSE; + + if (_stricmp(name, "Content-Length") == 0) + { + unsigned long long val = 0; + errno = 0; + val = _strtoui64(value, NULL, 0); + + if ((errno != 0) || (val > INT32_MAX)) + return FALSE; + + response->ContentLength = val; + } + else if (_stricmp(name, "Content-Type") == 0) + { + response->ContentType = value; + + if (!response->ContentType) + return FALSE; + } + else if (_stricmp(name, "Transfer-Encoding") == 0) + { + if (_stricmp(value, "identity") == 0) + response->TransferEncoding = TransferEncodingIdentity; + else if (_stricmp(value, "chunked") == 0) + response->TransferEncoding = TransferEncodingChunked; + else + response->TransferEncoding = TransferEncodingUnknown; + } + else if (_stricmp(name, "Sec-WebSocket-Version") == 0) + { + response->SecWebsocketVersion = value; + + if (!response->SecWebsocketVersion) + return FALSE; + } + else if (_stricmp(name, "Sec-WebSocket-Accept") == 0) + { + response->SecWebsocketAccept = value; + + if (!response->SecWebsocketAccept) + return FALSE; + } + else if (_stricmp(name, "WWW-Authenticate") == 0) + { + char* separator = NULL; + const char* authScheme = NULL; + char* authValue = NULL; + separator = strchr(value, ' '); + + if (separator) + { + /* WWW-Authenticate: Basic realm="" + * WWW-Authenticate: NTLM base64token + * WWW-Authenticate: Digest realm="testrealm@host.com", qop="auth, auth-int", + * nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", + * opaque="5ccc069c403ebaf9f0171e9517f40e41" + */ + *separator = '\0'; + authScheme = value; + authValue = separator + 1; + + if (!authScheme || !authValue) + return FALSE; + } + else + { + authScheme = value; + + if (!authScheme) + return FALSE; + + authValue = NULL; + } + + status = ListDictionary_Add(response->Authenticates, authScheme, authValue); + } + else if (_stricmp(name, "Set-Cookie") == 0) + { + char* separator = NULL; + const char* CookieName = NULL; + char* CookieValue = NULL; + separator = strchr(value, '='); + + if (separator) + { + /* Set-Cookie: name=value + * Set-Cookie: name=value; Attribute=value + * Set-Cookie: name="value with spaces"; Attribute=value + */ + *separator = '\0'; + CookieName = value; + CookieValue = separator + 1; + + if (!CookieName || !CookieValue) + return FALSE; + + if (*CookieValue == '"') + { + char* p = CookieValue; + while (*p != '"' && *p != '\0') + { + p++; + if (*p == '\\') + p++; + } + *p = '\0'; + } + else + { + char* p = CookieValue; + while (*p != ';' && *p != '\0' && *p != ' ') + { + p++; + } + *p = '\0'; + } + } + else + { + return FALSE; + } + + status = ListDictionary_Add(response->SetCookie, CookieName, CookieValue); + } + + return status; +} + +static BOOL http_response_parse_header(HttpResponse* response) +{ + BOOL rc = FALSE; + char c = 0; + char* line = NULL; + char* name = NULL; + char* colon_pos = NULL; + char* end_of_header = NULL; + char end_of_header_char = 0; + + if (!response) + goto fail; + + if (!response->lines) + goto fail; + + if (!http_response_parse_header_status_line(response, response->lines[0])) + goto fail; + + for (size_t count = 1; count < response->count; count++) + { + line = response->lines[count]; + + /** + * name end_of_header + * | | + * v v + *
:
+ * ^ ^ + * | | + * colon_pos value + */ + if (line) + colon_pos = strchr(line, ':'); + else + colon_pos = NULL; + + if ((colon_pos == NULL) || (colon_pos == line)) + return FALSE; + + /* retrieve the position just after header name */ + for (end_of_header = colon_pos; end_of_header != line; end_of_header--) + { + c = end_of_header[-1]; + + if (c != ' ' && c != '\t' && c != ':') + break; + } + + if (end_of_header == line) + goto fail; + + end_of_header_char = *end_of_header; + *end_of_header = '\0'; + name = line; + + /* eat space and tabs before header value */ + char* value = colon_pos + 1; + for (; *value; value++) + { + if ((*value != ' ') && (*value != '\t')) + break; + } + + const int res = http_response_parse_header_field(response, name, value); + *end_of_header = end_of_header_char; + if (!res) + goto fail; + } + + rc = TRUE; +fail: + + if (!rc) + WLog_ERR(TAG, "parsing failed"); + + return rc; +} + +static void http_response_print(wLog* log, DWORD level, const HttpResponse* response) +{ + char buffer[64] = { 0 }; + + WINPR_ASSERT(log); + WINPR_ASSERT(response); + + if (!WLog_IsLevelActive(log, level)) + return; + + const long status = http_response_get_status_code(response); + WLog_Print(log, level, "HTTP status: %s", + freerdp_http_status_string_format(status, buffer, ARRAYSIZE(buffer))); + + for (size_t i = 0; i < response->count; i++) + WLog_Print(log, WLOG_DEBUG, "[%" PRIuz "] %s", i, response->lines[i]); + + if (response->ReasonPhrase) + WLog_Print(log, level, "[reason] %s", response->ReasonPhrase); + + WLog_Print(log, WLOG_TRACE, "[body][%" PRIuz "] %s", response->BodyLength, + response->BodyContent); +} + +static BOOL http_use_content_length(const char* cur) +{ + size_t pos = 0; + + if (!cur) + return FALSE; + + if (_strnicmp(cur, "application/rpc", 15) == 0) + pos = 15; + else if (_strnicmp(cur, "text/plain", 10) == 0) + pos = 10; + else if (_strnicmp(cur, "text/html", 9) == 0) + pos = 9; + else if (_strnicmp(cur, "application/json", 16) == 0) + pos = 16; + + if (pos > 0) + { + char end = cur[pos]; + + switch (end) + { + case ' ': + case ';': + case '\0': + case '\r': + case '\n': + return TRUE; + + default: + return FALSE; + } + } + + return FALSE; +} + +static int print_bio_error(const char* str, size_t len, void* bp) +{ + wLog* log = bp; + + WINPR_UNUSED(bp); + WLog_Print(log, WLOG_ERROR, "%s", str); + if (len > INT32_MAX) + return -1; + return (int)len; +} + +int http_chuncked_read(BIO* bio, BYTE* pBuffer, size_t size, + http_encoding_chunked_context* encodingContext) +{ + int status = 0; + int effectiveDataLen = 0; + WINPR_ASSERT(bio); + WINPR_ASSERT(pBuffer); + WINPR_ASSERT(encodingContext != NULL); + WINPR_ASSERT(size <= INT32_MAX); + while (TRUE) + { + switch (encodingContext->state) + { + case ChunkStateData: + { + const size_t rd = + (size > encodingContext->nextOffset ? encodingContext->nextOffset : size); + if (rd > INT32_MAX) + return -1; + + ERR_clear_error(); + status = BIO_read(bio, pBuffer, (int)rd); + if (status <= 0) + return (effectiveDataLen > 0 ? effectiveDataLen : status); + + encodingContext->nextOffset -= WINPR_ASSERTING_INT_CAST(uint32_t, status); + if (encodingContext->nextOffset == 0) + { + encodingContext->state = ChunkStateFooter; + encodingContext->headerFooterPos = 0; + } + effectiveDataLen += status; + + if ((size_t)status == size) + return effectiveDataLen; + + pBuffer += status; + size -= (size_t)status; + } + break; + case ChunkStateFooter: + { + char _dummy[2] = { 0 }; + WINPR_ASSERT(encodingContext->nextOffset == 0); + WINPR_ASSERT(encodingContext->headerFooterPos < 2); + ERR_clear_error(); + status = BIO_read(bio, _dummy, (int)(2 - encodingContext->headerFooterPos)); + if (status >= 0) + { + encodingContext->headerFooterPos += (size_t)status; + if (encodingContext->headerFooterPos == 2) + { + encodingContext->state = ChunkStateLenghHeader; + encodingContext->headerFooterPos = 0; + } + } + else + return (effectiveDataLen > 0 ? effectiveDataLen : status); + } + break; + case ChunkStateLenghHeader: + { + BOOL _haveNewLine = FALSE; + char* dst = &encodingContext->lenBuffer[encodingContext->headerFooterPos]; + WINPR_ASSERT(encodingContext->nextOffset == 0); + while (encodingContext->headerFooterPos < 10 && !_haveNewLine) + { + ERR_clear_error(); + status = BIO_read(bio, dst, 1); + if (status >= 0) + { + if (*dst == '\n') + _haveNewLine = TRUE; + encodingContext->headerFooterPos += (size_t)status; + dst += status; + } + else + return (effectiveDataLen > 0 ? effectiveDataLen : status); + } + *dst = '\0'; + /* strtoul is tricky, error are reported via errno, we also need + * to ensure the result does not overflow */ + errno = 0; + size_t tmp = strtoul(encodingContext->lenBuffer, NULL, 16); + if ((errno != 0) || (tmp > SIZE_MAX)) + { + /* denote end of stream if something bad happens */ + encodingContext->nextOffset = 0; + encodingContext->state = ChunkStateEnd; + return -1; + } + encodingContext->nextOffset = tmp; + encodingContext->state = ChunkStateData; + + if (encodingContext->nextOffset == 0) + { /* end of stream */ + WLog_DBG(TAG, "chunked encoding end of stream received"); + encodingContext->headerFooterPos = 0; + encodingContext->state = ChunkStateEnd; + return (effectiveDataLen > 0 ? effectiveDataLen : 0); + } + } + break; + default: + /* invalid state / ChunkStateEnd */ + return -1; + } + } +} + +#define sleep_or_timeout(tls, startMS, timeoutMS) \ + sleep_or_timeout_((tls), (startMS), (timeoutMS), __FILE__, __func__, __LINE__) +static BOOL sleep_or_timeout_(rdpTls* tls, UINT64 startMS, UINT32 timeoutMS, const char* file, + const char* fkt, size_t line) +{ + WINPR_ASSERT(tls); + + USleep(100); + const UINT64 nowMS = GetTickCount64(); + if (nowMS - startMS > timeoutMS) + { + DWORD level = WLOG_ERROR; + wLog* log = WLog_Get(TAG); + if (WLog_IsLevelActive(log, level)) + WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, fkt, + "timeout [%" PRIu32 "ms] exceeded", timeoutMS); + return TRUE; + } + if (!BIO_should_retry(tls->bio)) + { + DWORD level = WLOG_ERROR; + wLog* log = WLog_Get(TAG); + if (WLog_IsLevelActive(log, level)) + { + WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, fkt, "Retries exceeded"); + ERR_print_errors_cb(print_bio_error, log); + } + return TRUE; + } + if (freerdp_shall_disconnect_context(tls->context)) + return TRUE; + + return FALSE; +} + +static SSIZE_T http_response_recv_line(rdpTls* tls, HttpResponse* response) +{ + WINPR_ASSERT(tls); + WINPR_ASSERT(response); + + SSIZE_T payloadOffset = -1; + const UINT32 timeoutMS = + freerdp_settings_get_uint32(tls->context->settings, FreeRDP_TcpConnectTimeout); + const UINT64 startMS = GetTickCount64(); + while (payloadOffset <= 0) + { + size_t bodyLength = 0; + size_t position = 0; + int status = -1; + size_t s = 0; + char* end = NULL; + /* Read until we encounter \r\n\r\n */ + ERR_clear_error(); + + status = BIO_read(tls->bio, Stream_Pointer(response->data), 1); + if (status <= 0) + { + if (sleep_or_timeout(tls, startMS, timeoutMS)) + goto out_error; + continue; + } + +#ifdef FREERDP_HAVE_VALGRIND_MEMCHECK_H + VALGRIND_MAKE_MEM_DEFINED(Stream_Pointer(response->data), status); +#endif + Stream_Seek(response->data, (size_t)status); + + if (!Stream_EnsureRemainingCapacity(response->data, 1024)) + goto out_error; + + position = Stream_GetPosition(response->data); + + if (position < 4) + continue; + else if (position > RESPONSE_SIZE_LIMIT) + { + WLog_ERR(TAG, "Request header too large! (%" PRIdz " bytes) Aborting!", bodyLength); + goto out_error; + } + + /* Always check at most the lase 8 bytes for occurrence of the desired + * sequence of \r\n\r\n */ + s = (position > 8) ? 8 : position; + end = (char*)Stream_Pointer(response->data) - s; + + if (string_strnstr(end, "\r\n\r\n", s) != NULL) + payloadOffset = WINPR_ASSERTING_INT_CAST(SSIZE_T, Stream_GetPosition(response->data)); + } + +out_error: + return payloadOffset; +} + +static BOOL http_response_recv_body(rdpTls* tls, HttpResponse* response, BOOL readContentLength, + size_t payloadOffset, size_t bodyLength) +{ + BOOL rc = FALSE; + + WINPR_ASSERT(tls); + WINPR_ASSERT(response); + + const UINT64 startMS = GetTickCount64(); + const UINT32 timeoutMS = + freerdp_settings_get_uint32(tls->context->settings, FreeRDP_TcpConnectTimeout); + + if ((response->TransferEncoding == TransferEncodingChunked) && readContentLength) + { + http_encoding_chunked_context ctx = { 0 }; + ctx.state = ChunkStateLenghHeader; + ctx.nextOffset = 0; + ctx.headerFooterPos = 0; + int full_len = 0; + do + { + if (!Stream_EnsureRemainingCapacity(response->data, 2048)) + goto out_error; + + int status = http_chuncked_read(tls->bio, Stream_Pointer(response->data), + Stream_GetRemainingCapacity(response->data), &ctx); + if (status <= 0) + { + if (sleep_or_timeout(tls, startMS, timeoutMS)) + goto out_error; + } + else + { + Stream_Seek(response->data, (size_t)status); + full_len += status; + } + } while (ctx.state != ChunkStateEnd); + response->BodyLength = WINPR_ASSERTING_INT_CAST(uint32_t, full_len); + if (response->BodyLength > 0) + response->BodyContent = &(Stream_Buffer(response->data))[payloadOffset]; + } + else + { + while (response->BodyLength < bodyLength) + { + int status = 0; + + if (!Stream_EnsureRemainingCapacity(response->data, bodyLength - response->BodyLength)) + goto out_error; + + ERR_clear_error(); + size_t diff = bodyLength - response->BodyLength; + if (diff > INT32_MAX) + diff = INT32_MAX; + status = BIO_read(tls->bio, Stream_Pointer(response->data), (int)diff); + + if (status <= 0) + { + if (sleep_or_timeout(tls, startMS, timeoutMS)) + goto out_error; + continue; + } + + Stream_Seek(response->data, (size_t)status); + response->BodyLength += (unsigned long)status; + + if (response->BodyLength > RESPONSE_SIZE_LIMIT) + { + WLog_ERR(TAG, "Request body too large! (%" PRIdz " bytes) Aborting!", + response->BodyLength); + goto out_error; + } + } + + if (response->BodyLength > 0) + response->BodyContent = &(Stream_Buffer(response->data))[payloadOffset]; + + if (bodyLength != response->BodyLength) + { + WLog_WARN(TAG, "%s unexpected body length: actual: %" PRIuz ", expected: %" PRIuz, + response->ContentType, response->BodyLength, bodyLength); + + if (bodyLength > 0) + response->BodyLength = MIN(bodyLength, response->BodyLength); + } + + /* '\0' terminate the http body */ + if (!Stream_EnsureRemainingCapacity(response->data, sizeof(UINT16))) + goto out_error; + Stream_Write_UINT16(response->data, 0); + } + + rc = TRUE; +out_error: + return rc; +} + +HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength) +{ + size_t bodyLength = 0; + HttpResponse* response = http_response_new(); + + if (!response) + return NULL; + + response->ContentLength = 0; + + const SSIZE_T payloadOffset = http_response_recv_line(tls, response); + if (payloadOffset < 0) + goto out_error; + + if (payloadOffset) + { + size_t count = 0; + char* buffer = Stream_BufferAs(response->data, char); + char* line = Stream_BufferAs(response->data, char); + char* context = NULL; + + while ((line = string_strnstr(line, "\r\n", + WINPR_ASSERTING_INT_CAST(size_t, payloadOffset) - + WINPR_ASSERTING_INT_CAST(size_t, (line - buffer)) - 2UL))) + { + line += 2; + count++; + } + + response->count = count; + + if (count) + { + response->lines = (char**)calloc(response->count, sizeof(char*)); + + if (!response->lines) + goto out_error; + } + + buffer[payloadOffset - 1] = '\0'; + buffer[payloadOffset - 2] = '\0'; + count = 0; + line = strtok_s(buffer, "\r\n", &context); + + while (line && (response->count > count)) + { + response->lines[count] = line; + line = strtok_s(NULL, "\r\n", &context); + count++; + } + + if (!http_response_parse_header(response)) + goto out_error; + + response->BodyLength = + Stream_GetPosition(response->data) - WINPR_ASSERTING_INT_CAST(size_t, payloadOffset); + + WINPR_ASSERT(response->BodyLength == 0); + bodyLength = response->BodyLength; /* expected body length */ + + if (readContentLength) + { + const char* cur = response->ContentType; + + while (cur != NULL) + { + if (http_use_content_length(cur)) + { + if (response->ContentLength < RESPONSE_SIZE_LIMIT) + bodyLength = response->ContentLength; + + break; + } + else + readContentLength = FALSE; /* prevent chunked read */ + + cur = strchr(cur, ';'); + } + } + + if (bodyLength > RESPONSE_SIZE_LIMIT) + { + WLog_ERR(TAG, "Expected request body too large! (%" PRIdz " bytes) Aborting!", + bodyLength); + goto out_error; + } + + /* Fetch remaining body! */ + if (!http_response_recv_body(tls, response, readContentLength, + WINPR_ASSERTING_INT_CAST(size_t, payloadOffset), bodyLength)) + goto out_error; + } + Stream_SealLength(response->data); + + /* Ensure '\0' terminated string */ + if (!Stream_EnsureRemainingCapacity(response->data, 2)) + goto out_error; + Stream_Write_UINT16(response->data, 0); + + return response; +out_error: + http_response_free(response); + return NULL; +} + +const BYTE* http_response_get_body(const HttpResponse* response) +{ + if (!response) + return NULL; + + return response->BodyContent; +} + +static BOOL set_compare(wListDictionary* dict) +{ + WINPR_ASSERT(dict); + wObject* key = ListDictionary_KeyObject(dict); + wObject* value = ListDictionary_KeyObject(dict); + if (!key || !value) + return FALSE; + key->fnObjectEquals = strings_equals_nocase; + value->fnObjectEquals = strings_equals_nocase; + return TRUE; +} + +HttpResponse* http_response_new(void) +{ + HttpResponse* response = (HttpResponse*)calloc(1, sizeof(HttpResponse)); + + if (!response) + return NULL; + + response->Authenticates = ListDictionary_New(FALSE); + + if (!response->Authenticates) + goto fail; + + if (!set_compare(response->Authenticates)) + goto fail; + + response->SetCookie = ListDictionary_New(FALSE); + + if (!response->SetCookie) + goto fail; + + if (!set_compare(response->SetCookie)) + goto fail; + + response->data = Stream_New(NULL, 2048); + + if (!response->data) + goto fail; + + response->TransferEncoding = TransferEncodingIdentity; + return response; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + http_response_free(response); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void http_response_free(HttpResponse* response) +{ + if (!response) + return; + + free((void*)response->lines); + ListDictionary_Free(response->Authenticates); + ListDictionary_Free(response->SetCookie); + Stream_Free(response->data, TRUE); + free(response); +} + +const char* http_request_get_uri(HttpRequest* request) +{ + if (!request) + return NULL; + + return request->URI; +} + +SSIZE_T http_request_get_content_length(HttpRequest* request) +{ + if (!request) + return -1; + + return (SSIZE_T)request->ContentLength; +} + +BOOL http_request_set_content_length(HttpRequest* request, size_t length) +{ + if (!request) + return FALSE; + + request->ContentLength = length; + return TRUE; +} + +INT16 http_response_get_status_code(const HttpResponse* response) +{ + WINPR_ASSERT(response); + + return response->StatusCode; +} + +size_t http_response_get_body_length(const HttpResponse* response) +{ + WINPR_ASSERT(response); + + return response->BodyLength; +} + +const char* http_response_get_auth_token(const HttpResponse* response, const char* method) +{ + if (!response || !method) + return NULL; + + if (!ListDictionary_Contains(response->Authenticates, method)) + return NULL; + + return ListDictionary_GetItemValue(response->Authenticates, method); +} + +const char* http_response_get_setcookie(const HttpResponse* response, const char* cookie) +{ + if (!response || !cookie) + return NULL; + + if (!ListDictionary_Contains(response->SetCookie, cookie)) + return NULL; + + return ListDictionary_GetItemValue(response->SetCookie, cookie); +} + +TRANSFER_ENCODING http_response_get_transfer_encoding(const HttpResponse* response) +{ + if (!response) + return TransferEncodingUnknown; + + return response->TransferEncoding; +} + +BOOL http_response_is_websocket(const HttpContext* http, const HttpResponse* response) +{ + BOOL isWebsocket = FALSE; + WINPR_DIGEST_CTX* sha1 = NULL; + char* base64accept = NULL; + BYTE sha1_digest[WINPR_SHA1_DIGEST_LENGTH]; + + if (!http || !response) + return FALSE; + + if (!http->websocketUpgrade || response->StatusCode != HTTP_STATUS_SWITCH_PROTOCOLS) + return FALSE; + + if (response->SecWebsocketVersion && _stricmp(response->SecWebsocketVersion, "13") != 0) + return FALSE; + + if (!response->SecWebsocketAccept) + return FALSE; + + /* now check if Sec-Websocket-Accept is correct */ + + sha1 = winpr_Digest_New(); + if (!sha1) + goto out; + + if (!winpr_Digest_Init(sha1, WINPR_MD_SHA1)) + goto out; + + if (!winpr_Digest_Update(sha1, (BYTE*)http->SecWebsocketKey, strlen(http->SecWebsocketKey))) + goto out; + if (!winpr_Digest_Update(sha1, (const BYTE*)WEBSOCKET_MAGIC_GUID, strlen(WEBSOCKET_MAGIC_GUID))) + goto out; + + if (!winpr_Digest_Final(sha1, sha1_digest, sizeof(sha1_digest))) + goto out; + + base64accept = crypto_base64_encode(sha1_digest, WINPR_SHA1_DIGEST_LENGTH); + if (!base64accept) + goto out; + + if (_stricmp(response->SecWebsocketAccept, base64accept) != 0) + { + WLog_WARN(TAG, "Webserver gave Websocket Upgrade response but sanity check failed"); + goto out; + } + isWebsocket = TRUE; +out: + winpr_Digest_Free(sha1); + free(base64accept); + return isWebsocket; +} + +void http_response_log_error_status(wLog* log, DWORD level, const HttpResponse* response) +{ + WINPR_ASSERT(log); + WINPR_ASSERT(response); + + if (!WLog_IsLevelActive(log, level)) + return; + + char buffer[64] = { 0 }; + const long status = http_response_get_status_code(response); + WLog_Print(log, level, "Unexpected HTTP status: %s", + freerdp_http_status_string_format(status, buffer, ARRAYSIZE(buffer))); + http_response_print(log, level, response); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/http.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/http.h new file mode 100644 index 0000000000000000000000000000000000000000..337b674c6e4fd878f92dc16e1aeec0b406d547da --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/http.h @@ -0,0 +1,135 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Hypertext Transfer Protocol (HTTP) + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_HTTP_H +#define FREERDP_LIB_CORE_GATEWAY_HTTP_H + +#include + +#include +#include + +#include "../../crypto/tls.h" + +typedef enum +{ + TransferEncodingUnknown, + TransferEncodingIdentity, + TransferEncodingChunked +} TRANSFER_ENCODING; + +typedef enum +{ + ChunkStateLenghHeader, + ChunkStateData, + ChunkStateFooter, + ChunkStateEnd +} CHUNK_STATE; + +typedef struct +{ + size_t nextOffset; + size_t headerFooterPos; + CHUNK_STATE state; + char lenBuffer[11]; +} http_encoding_chunked_context; + +/* HTTP context */ +typedef struct s_http_context HttpContext; + +FREERDP_LOCAL void http_context_free(HttpContext* context); + +WINPR_ATTR_MALLOC(http_context_free, 1) +FREERDP_LOCAL HttpContext* http_context_new(void); + +FREERDP_LOCAL BOOL http_context_set_method(HttpContext* context, const char* Method); +FREERDP_LOCAL const char* http_context_get_uri(HttpContext* context); +FREERDP_LOCAL BOOL http_context_set_uri(HttpContext* context, const char* URI); +FREERDP_LOCAL BOOL http_context_set_user_agent(HttpContext* context, const char* UserAgent); +FREERDP_LOCAL BOOL http_context_set_x_ms_user_agent(HttpContext* context, const char* UserAgent); +FREERDP_LOCAL BOOL http_context_set_host(HttpContext* context, const char* Host); +FREERDP_LOCAL BOOL http_context_set_accept(HttpContext* context, const char* Accept); +FREERDP_LOCAL BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl); +FREERDP_LOCAL BOOL http_context_set_connection(HttpContext* context, const char* Connection); +FREERDP_LOCAL BOOL http_context_set_pragma(HttpContext* context, + WINPR_FORMAT_ARG const char* Pragma, ...); +FREERDP_LOCAL BOOL http_context_append_pragma(HttpContext* context, + WINPR_FORMAT_ARG const char* Pragma, ...); +FREERDP_LOCAL BOOL http_context_set_cookie(HttpContext* context, const char* CookieName, + const char* CookieValue); +FREERDP_LOCAL BOOL http_context_set_rdg_connection_id(HttpContext* context, + const GUID* RdgConnectionId); +FREERDP_LOCAL BOOL http_context_set_rdg_correlation_id(HttpContext* context, + const GUID* RdgConnectionId); +FREERDP_LOCAL BOOL http_context_set_rdg_auth_scheme(HttpContext* context, + const char* RdgAuthScheme); +FREERDP_LOCAL BOOL http_context_enable_websocket_upgrade(HttpContext* context, BOOL enable); +FREERDP_LOCAL BOOL http_context_is_websocket_upgrade_enabled(HttpContext* context); + +/* HTTP request */ +typedef struct s_http_request HttpRequest; + +FREERDP_LOCAL void http_request_free(HttpRequest* request); + +WINPR_ATTR_MALLOC(http_request_free, 1) +FREERDP_LOCAL HttpRequest* http_request_new(void); + +FREERDP_LOCAL BOOL http_request_set_method(HttpRequest* request, const char* Method); +FREERDP_LOCAL BOOL http_request_set_content_type(HttpRequest* request, const char* ContentType); +FREERDP_LOCAL SSIZE_T http_request_get_content_length(HttpRequest* request); +FREERDP_LOCAL BOOL http_request_set_content_length(HttpRequest* request, size_t length); + +FREERDP_LOCAL const char* http_request_get_uri(HttpRequest* request); +FREERDP_LOCAL BOOL http_request_set_uri(HttpRequest* request, const char* URI); +FREERDP_LOCAL BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme); +FREERDP_LOCAL BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam); +FREERDP_LOCAL BOOL http_request_set_transfer_encoding(HttpRequest* request, + TRANSFER_ENCODING TransferEncoding); + +FREERDP_LOCAL wStream* http_request_write(HttpContext* context, HttpRequest* request); + +/* HTTP response */ +typedef struct s_http_response HttpResponse; + +FREERDP_LOCAL void http_response_free(HttpResponse* response); + +WINPR_ATTR_MALLOC(http_response_free, 1) +FREERDP_LOCAL HttpResponse* http_response_new(void); + +FREERDP_LOCAL HttpResponse* http_response_recv(rdpTls* tls, BOOL readContentLength); + +FREERDP_LOCAL INT16 http_response_get_status_code(const HttpResponse* response); +FREERDP_LOCAL size_t http_response_get_body_length(const HttpResponse* response); +FREERDP_LOCAL const BYTE* http_response_get_body(const HttpResponse* response); +FREERDP_LOCAL const char* http_response_get_auth_token(const HttpResponse* response, + const char* method); +FREERDP_LOCAL const char* http_response_get_setcookie(const HttpResponse* response, + const char* cookie); +FREERDP_LOCAL TRANSFER_ENCODING http_response_get_transfer_encoding(const HttpResponse* response); +FREERDP_LOCAL BOOL http_response_is_websocket(const HttpContext* http, + const HttpResponse* response); + +FREERDP_LOCAL void http_response_log_error_status(wLog* log, DWORD level, + const HttpResponse* response); + +/* chunked read helper */ +FREERDP_LOCAL int http_chuncked_read(BIO* bio, BYTE* pBuffer, size_t size, + http_encoding_chunked_context* encodingContext); + +#endif /* FREERDP_LIB_CORE_GATEWAY_HTTP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/ncacn_http.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/ncacn_http.c new file mode 100644 index 0000000000000000000000000000000000000000..05975984f42b982b6ac7ecdcc0766b378fce3d45 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/ncacn_http.c @@ -0,0 +1,278 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC over HTTP (ncacn_http) + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../settings.h" +#include "ncacn_http.h" + +#include +#include +#include +#include + +#include "../utils.h" + +#define TAG FREERDP_TAG("core.gateway.ntlm") + +#define AUTH_PKG NTLM_SSP_NAME + +static wStream* rpc_auth_http_request(HttpContext* http, const char* method, size_t contentLength, + const SecBuffer* authToken, const char* auth_scheme) +{ + wStream* s = NULL; + HttpRequest* request = NULL; + char* base64AuthToken = NULL; + const char* uri = NULL; + + if (!http || !method) + goto fail; + + request = http_request_new(); + + if (!request) + goto fail; + + if (authToken) + base64AuthToken = crypto_base64_encode(authToken->pvBuffer, authToken->cbBuffer); + + uri = http_context_get_uri(http); + + if (!http_request_set_method(request, method) || + !http_request_set_content_length(request, contentLength) || + !http_request_set_uri(request, uri)) + goto fail; + + if (base64AuthToken) + { + if (!http_request_set_auth_scheme(request, auth_scheme) || + !http_request_set_auth_param(request, base64AuthToken)) + goto fail; + } + + s = http_request_write(http, request); +fail: + http_request_free(request); + free(base64AuthToken); + return s; +} + +BOOL rpc_ncacn_http_send_in_channel_request(RpcChannel* inChannel) +{ + wStream* s = NULL; + SSIZE_T status = 0; + rdpCredsspAuth* auth = NULL; + HttpContext* http = NULL; + const SecBuffer* buffer = NULL; + int rc = 0; + + if (!inChannel || !inChannel->auth || !inChannel->http) + return FALSE; + + auth = inChannel->auth; + http = inChannel->http; + + rc = credssp_auth_authenticate(auth); + if (rc < 0) + return FALSE; + + const size_t contentLength = (rc == 0) ? 0 : 0x40000000; + buffer = credssp_auth_have_output_token(auth) ? credssp_auth_get_output_buffer(auth) : NULL; + s = rpc_auth_http_request(http, "RPC_IN_DATA", contentLength, buffer, + credssp_auth_pkg_name(auth)); + + if (!s) + return -1; + + status = rpc_channel_write(inChannel, Stream_Buffer(s), Stream_Length(s)); + Stream_Free(s, TRUE); + return (status > 0) ? 1 : -1; +} + +BOOL rpc_ncacn_http_recv_in_channel_response(RpcChannel* inChannel, HttpResponse* response) +{ + size_t authTokenLength = 0; + BYTE* authTokenData = NULL; + + if (!inChannel || !response || !inChannel->auth) + return FALSE; + + rdpCredsspAuth* auth = inChannel->auth; + const char* token64 = http_response_get_auth_token(response, credssp_auth_pkg_name(auth)); + + if (token64) + crypto_base64_decode(token64, strlen(token64), &authTokenData, &authTokenLength); + + if (authTokenLength > UINT32_MAX) + { + free(authTokenData); + return FALSE; + } + + SecBuffer buffer = { .pvBuffer = authTokenData, .cbBuffer = (UINT32)authTokenLength }; + + if (authTokenData && authTokenLength) + { + credssp_auth_take_input_buffer(auth, &buffer); + return TRUE; + } + + sspi_SecBufferFree(&buffer); + return TRUE; +} + +BOOL rpc_ncacn_http_auth_init(rdpContext* context, RpcChannel* channel) +{ + rdpTls* tls = NULL; + rdpCredsspAuth* auth = NULL; + rdpSettings* settings = NULL; + freerdp* instance = NULL; + auth_status rc = AUTH_FAILED; + SEC_WINNT_AUTH_IDENTITY identity = { 0 }; + + if (!context || !channel) + return FALSE; + + tls = channel->tls; + auth = channel->auth; + settings = context->settings; + instance = context->instance; + + if (!tls || !auth || !instance || !settings) + return FALSE; + + rc = utils_authenticate_gateway(instance, GW_AUTH_HTTP); + switch (rc) + { + case AUTH_SUCCESS: + case AUTH_SKIP: + break; + case AUTH_CANCELLED: + freerdp_set_last_error_log(instance->context, FREERDP_ERROR_CONNECT_CANCELLED); + return FALSE; + case AUTH_NO_CREDENTIALS: + WLog_INFO(TAG, "No credentials provided - using NULL identity"); + break; + case AUTH_FAILED: + default: + return FALSE; + } + + if (!credssp_auth_init(auth, AUTH_PKG, tls->Bindings)) + return FALSE; + + if (!identity_set_from_settings(&identity, settings, FreeRDP_GatewayUsername, + FreeRDP_GatewayDomain, FreeRDP_GatewayPassword)) + return FALSE; + + SEC_WINNT_AUTH_IDENTITY* identityArg = (settings->GatewayUsername ? &identity : NULL); + const BOOL res = + credssp_auth_setup_client(auth, "HTTP", settings->GatewayHostname, identityArg, NULL); + + sspi_FreeAuthIdentity(&identity); + + credssp_auth_set_flags(auth, ISC_REQ_CONFIDENTIALITY); + + return res; +} + +void rpc_ncacn_http_auth_uninit(RpcChannel* channel) +{ + if (!channel) + return; + + credssp_auth_free(channel->auth); + channel->auth = NULL; +} + +BOOL rpc_ncacn_http_send_out_channel_request(RpcChannel* outChannel, BOOL replacement) +{ + BOOL status = TRUE; + wStream* s = NULL; + size_t contentLength = 0; + rdpCredsspAuth* auth = NULL; + HttpContext* http = NULL; + const SecBuffer* buffer = NULL; + int rc = 0; + + if (!outChannel || !outChannel->auth || !outChannel->http) + return FALSE; + + auth = outChannel->auth; + http = outChannel->http; + + rc = credssp_auth_authenticate(auth); + if (rc < 0) + return FALSE; + + if (!replacement) + contentLength = (rc == 0) ? 0 : 76; + else + contentLength = (rc == 0) ? 0 : 120; + + buffer = credssp_auth_have_output_token(auth) ? credssp_auth_get_output_buffer(auth) : NULL; + s = rpc_auth_http_request(http, "RPC_OUT_DATA", contentLength, buffer, + credssp_auth_pkg_name(auth)); + + if (!s) + return -1; + + if (rpc_channel_write(outChannel, Stream_Buffer(s), Stream_Length(s)) < 0) + status = FALSE; + + Stream_Free(s, TRUE); + return status; +} + +BOOL rpc_ncacn_http_recv_out_channel_response(RpcChannel* outChannel, HttpResponse* response) +{ + size_t authTokenLength = 0; + BYTE* authTokenData = NULL; + + if (!outChannel || !response || !outChannel->auth) + return FALSE; + + rdpCredsspAuth* auth = outChannel->auth; + const char* token64 = http_response_get_auth_token(response, credssp_auth_pkg_name(auth)); + + if (token64) + crypto_base64_decode(token64, strlen(token64), &authTokenData, &authTokenLength); + + if (authTokenLength > UINT32_MAX) + { + free(authTokenData); + return FALSE; + } + SecBuffer buffer = { .pvBuffer = authTokenData, .cbBuffer = (UINT32)authTokenLength }; + + if (authTokenData && authTokenLength) + { + credssp_auth_take_input_buffer(auth, &buffer); + return TRUE; + } + + sspi_SecBufferFree(&buffer); + return TRUE; +} + +BOOL rpc_ncacn_http_is_final_request(RpcChannel* channel) +{ + WINPR_ASSERT(channel); + return credssp_auth_is_complete(channel->auth); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/ncacn_http.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/ncacn_http.h new file mode 100644 index 0000000000000000000000000000000000000000..4fb4f7b7e494d2ec5dc4a5d612291082bfb6c863 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/ncacn_http.h @@ -0,0 +1,41 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC over HTTP (ncacn_http) + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_NCACN_HTTP_H +#define FREERDP_LIB_CORE_GATEWAY_NCACN_HTTP_H + +#include + +#include "rpc.h" +#include "http.h" + +FREERDP_LOCAL BOOL rpc_ncacn_http_auth_init(rdpContext* context, RpcChannel* channel); +FREERDP_LOCAL void rpc_ncacn_http_auth_uninit(RpcChannel* channel); + +FREERDP_LOCAL BOOL rpc_ncacn_http_send_in_channel_request(RpcChannel* inChannel); +FREERDP_LOCAL BOOL rpc_ncacn_http_recv_in_channel_response(RpcChannel* inChannel, + HttpResponse* response); + +FREERDP_LOCAL BOOL rpc_ncacn_http_send_out_channel_request(RpcChannel* outChannel, + BOOL replacement); +FREERDP_LOCAL BOOL rpc_ncacn_http_recv_out_channel_response(RpcChannel* outChannel, + HttpResponse* response); +FREERDP_LOCAL BOOL rpc_ncacn_http_is_final_request(RpcChannel* channel); + +#endif /* FREERDP_LIB_CORE_GATEWAY_NCACN_HTTP_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rdg.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rdg.c new file mode 100644 index 0000000000000000000000000000000000000000..6a9a149edef4450e8aaedaea69b3fe25c4a2f549 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rdg.c @@ -0,0 +1,2277 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Desktop Gateway (RDG) + * + * Copyright 2015 Denis Vincent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "../settings.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "rdg.h" +#include "websocket.h" +#include "../credssp_auth.h" +#include "../proxy.h" +#include "../rdp.h" +#include "../../crypto/opensslcompat.h" +#include "rpc_fault.h" +#include "../utils.h" + +#define TAG FREERDP_TAG("core.gateway.rdg") + +#define AUTH_PKG NEGO_SSP_NAME + +/* HTTP channel response fields present flags. */ +#define HTTP_CHANNEL_RESPONSE_FIELD_CHANNELID 0x1 +#define HTTP_CHANNEL_RESPONSE_OPTIONAL 0x2 +#define HTTP_CHANNEL_RESPONSE_FIELD_UDPPORT 0x4 + +/* HTTP extended auth. */ +#define HTTP_EXTENDED_AUTH_NONE 0x0 +#define HTTP_EXTENDED_AUTH_SC 0x1 /* Smart card authentication. */ +#define HTTP_EXTENDED_AUTH_PAA 0x02 /* Pluggable authentication. */ +#define HTTP_EXTENDED_AUTH_SSPI_NTLM 0x04 /* NTLM extended authentication. */ +#define HTTP_EXTENDED_AUTH_BEARER 0x08 /* HTTP Bearer authentication. */ + +/* HTTP packet types. */ +#define PKT_TYPE_HANDSHAKE_REQUEST 0x1 +#define PKT_TYPE_HANDSHAKE_RESPONSE 0x2 +#define PKT_TYPE_EXTENDED_AUTH_MSG 0x3 +#define PKT_TYPE_TUNNEL_CREATE 0x4 +#define PKT_TYPE_TUNNEL_RESPONSE 0x5 +#define PKT_TYPE_TUNNEL_AUTH 0x6 +#define PKT_TYPE_TUNNEL_AUTH_RESPONSE 0x7 +#define PKT_TYPE_CHANNEL_CREATE 0x8 +#define PKT_TYPE_CHANNEL_RESPONSE 0x9 +#define PKT_TYPE_DATA 0xA +#define PKT_TYPE_SERVICE_MESSAGE 0xB +#define PKT_TYPE_REAUTH_MESSAGE 0xC +#define PKT_TYPE_KEEPALIVE 0xD +#define PKT_TYPE_CLOSE_CHANNEL 0x10 +#define PKT_TYPE_CLOSE_CHANNEL_RESPONSE 0x11 + +/* HTTP tunnel auth fields present flags. */ +// #define HTTP_TUNNEL_AUTH_FIELD_SOH 0x1 + +/* HTTP tunnel auth response fields present flags. */ +#define HTTP_TUNNEL_AUTH_RESPONSE_FIELD_REDIR_FLAGS 0x1 +#define HTTP_TUNNEL_AUTH_RESPONSE_FIELD_IDLE_TIMEOUT 0x2 +#define HTTP_TUNNEL_AUTH_RESPONSE_FIELD_SOH_RESPONSE 0x4 + +/* HTTP tunnel packet fields present flags. */ +#define HTTP_TUNNEL_PACKET_FIELD_PAA_COOKIE 0x1 +// #define HTTP_TUNNEL_PACKET_FIELD_REAUTH 0x2 + +/* HTTP tunnel response fields present flags. */ +#define HTTP_TUNNEL_RESPONSE_FIELD_TUNNEL_ID 0x1 +#define HTTP_TUNNEL_RESPONSE_FIELD_CAPS 0x2 +#define HTTP_TUNNEL_RESPONSE_FIELD_SOH_REQ 0x4 +#define HTTP_TUNNEL_RESPONSE_FIELD_CONSENT_MSG 0x10 + +/* HTTP capability type enumeration. */ +#define HTTP_CAPABILITY_TYPE_QUAR_SOH 0x1 +#define HTTP_CAPABILITY_IDLE_TIMEOUT 0x2 +#define HTTP_CAPABILITY_MESSAGING_CONSENT_SIGN 0x4 +#define HTTP_CAPABILITY_MESSAGING_SERVICE_MSG 0x8 +#define HTTP_CAPABILITY_REAUTH 0x10 +#define HTTP_CAPABILITY_UDP_TRANSPORT 0x20 + +typedef struct +{ + TRANSFER_ENCODING httpTransferEncoding; + BOOL isWebsocketTransport; + union context + { + http_encoding_chunked_context chunked; + websocket_context* websocket; + } context; +} rdg_http_encoding_context; + +struct rdp_rdg +{ + rdpContext* context; + BOOL attached; + BIO* frontBio; + rdpTls* tlsIn; + rdpTls* tlsOut; + rdpCredsspAuth* auth; + HttpContext* http; + CRITICAL_SECTION writeSection; + + UUID guid; + + int state; + UINT16 packetRemainingCount; + UINT16 reserved1; + int timeout; + UINT16 extAuth; + UINT16 reserved2; + rdg_http_encoding_context transferEncoding; + + SmartcardCertInfo* smartcard; + wLog* log; +}; + +enum +{ + RDG_CLIENT_STATE_INITIAL, + RDG_CLIENT_STATE_HANDSHAKE, + RDG_CLIENT_STATE_TUNNEL_CREATE, + RDG_CLIENT_STATE_TUNNEL_AUTHORIZE, + RDG_CLIENT_STATE_CHANNEL_CREATE, + RDG_CLIENT_STATE_OPENED, +}; + +#pragma pack(push, 1) + +typedef struct rdg_packet_header +{ + UINT16 type; + UINT16 reserved; + UINT32 packetLength; +} RdgPacketHeader; + +#pragma pack(pop) + +typedef struct +{ + UINT32 code; + const char* name; +} t_flag_mapping; + +static const t_flag_mapping tunnel_response_fields_present[] = { + { HTTP_TUNNEL_RESPONSE_FIELD_TUNNEL_ID, "HTTP_TUNNEL_RESPONSE_FIELD_TUNNEL_ID" }, + { HTTP_TUNNEL_RESPONSE_FIELD_CAPS, "HTTP_TUNNEL_RESPONSE_FIELD_CAPS" }, + { HTTP_TUNNEL_RESPONSE_FIELD_SOH_REQ, "HTTP_TUNNEL_RESPONSE_FIELD_SOH_REQ" }, + { HTTP_TUNNEL_RESPONSE_FIELD_CONSENT_MSG, "HTTP_TUNNEL_RESPONSE_FIELD_CONSENT_MSG" } +}; + +static const t_flag_mapping channel_response_fields_present[] = { + { HTTP_CHANNEL_RESPONSE_FIELD_CHANNELID, "HTTP_CHANNEL_RESPONSE_FIELD_CHANNELID" }, + { HTTP_CHANNEL_RESPONSE_OPTIONAL, "HTTP_CHANNEL_RESPONSE_OPTIONAL" }, + { HTTP_CHANNEL_RESPONSE_FIELD_UDPPORT, "HTTP_CHANNEL_RESPONSE_FIELD_UDPPORT" } +}; + +static const t_flag_mapping tunnel_authorization_response_fields_present[] = { + { HTTP_TUNNEL_AUTH_RESPONSE_FIELD_REDIR_FLAGS, "HTTP_TUNNEL_AUTH_RESPONSE_FIELD_REDIR_FLAGS" }, + { HTTP_TUNNEL_AUTH_RESPONSE_FIELD_IDLE_TIMEOUT, + "HTTP_TUNNEL_AUTH_RESPONSE_FIELD_IDLE_TIMEOUT" }, + { HTTP_TUNNEL_AUTH_RESPONSE_FIELD_SOH_RESPONSE, + "HTTP_TUNNEL_AUTH_RESPONSE_FIELD_SOH_RESPONSE" } +}; + +static const t_flag_mapping extended_auth[] = { + { HTTP_EXTENDED_AUTH_NONE, "HTTP_EXTENDED_AUTH_NONE" }, + { HTTP_EXTENDED_AUTH_SC, "HTTP_EXTENDED_AUTH_SC" }, + { HTTP_EXTENDED_AUTH_PAA, "HTTP_EXTENDED_AUTH_PAA" }, + { HTTP_EXTENDED_AUTH_SSPI_NTLM, "HTTP_EXTENDED_AUTH_SSPI_NTLM" } +}; + +static const t_flag_mapping capabilities_enum[] = { + { HTTP_CAPABILITY_TYPE_QUAR_SOH, "HTTP_CAPABILITY_TYPE_QUAR_SOH" }, + { HTTP_CAPABILITY_IDLE_TIMEOUT, "HTTP_CAPABILITY_IDLE_TIMEOUT" }, + { HTTP_CAPABILITY_MESSAGING_CONSENT_SIGN, "HTTP_CAPABILITY_MESSAGING_CONSENT_SIGN" }, + { HTTP_CAPABILITY_MESSAGING_SERVICE_MSG, "HTTP_CAPABILITY_MESSAGING_SERVICE_MSG" }, + { HTTP_CAPABILITY_REAUTH, "HTTP_CAPABILITY_REAUTH" }, + { HTTP_CAPABILITY_UDP_TRANSPORT, "HTTP_CAPABILITY_UDP_TRANSPORT" } +}; + +static const char* flags_to_string(UINT32 flags, const t_flag_mapping* map, size_t elements) +{ + static char buffer[1024] = { 0 }; + char fields[12] = { 0 }; + + for (size_t x = 0; x < elements; x++) + { + const t_flag_mapping* cur = &map[x]; + + if ((cur->code & flags) != 0) + winpr_str_append(cur->name, buffer, sizeof(buffer), "|"); + } + + (void)sprintf_s(fields, ARRAYSIZE(fields), " [%04" PRIx32 "]", flags); + winpr_str_append(fields, buffer, sizeof(buffer), NULL); + return buffer; +} + +static const char* channel_response_fields_present_to_string(UINT16 fieldsPresent) +{ + return flags_to_string(fieldsPresent, channel_response_fields_present, + ARRAYSIZE(channel_response_fields_present)); +} + +static const char* tunnel_response_fields_present_to_string(UINT16 fieldsPresent) +{ + return flags_to_string(fieldsPresent, tunnel_response_fields_present, + ARRAYSIZE(tunnel_response_fields_present)); +} + +static const char* tunnel_authorization_response_fields_present_to_string(UINT16 fieldsPresent) +{ + return flags_to_string(fieldsPresent, tunnel_authorization_response_fields_present, + ARRAYSIZE(tunnel_authorization_response_fields_present)); +} + +static const char* extended_auth_to_string(UINT16 auth) +{ + if (auth == HTTP_EXTENDED_AUTH_NONE) + return "HTTP_EXTENDED_AUTH_NONE [0x0000]"; + + return flags_to_string(auth, extended_auth, ARRAYSIZE(extended_auth)); +} + +static const char* capabilities_enum_to_string(UINT32 capabilities) +{ + return flags_to_string(capabilities, capabilities_enum, ARRAYSIZE(capabilities_enum)); +} + +static BOOL rdg_read_http_unicode_string(wLog* log, wStream* s, const WCHAR** string, + UINT16* lengthInBytes) +{ + UINT16 strLenBytes = 0; + size_t rem = Stream_GetRemainingLength(s); + + /* Read length of the string */ + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4)) + { + WLog_Print(log, WLOG_ERROR, "Could not read stream length, only have %" PRIuz " bytes", + rem); + return FALSE; + } + Stream_Read_UINT16(s, strLenBytes); + + /* Remember position of our string */ + const WCHAR* str = Stream_ConstPointer(s); + + /* seek past the string - if this fails something is wrong */ + if (!Stream_SafeSeek(s, strLenBytes)) + { + WLog_Print(log, WLOG_ERROR, + "Could not read stream data, only have %" PRIuz " bytes, expected %" PRIu16, + rem - 4, strLenBytes); + return FALSE; + } + + /* return the string data (if wanted) */ + if (string) + *string = str; + if (lengthInBytes) + *lengthInBytes = strLenBytes; + + return TRUE; +} + +static BOOL rdg_write_chunked(BIO* bio, wStream* sPacket) +{ + size_t len = 0; + int status = 0; + wStream* sChunk = NULL; + char chunkSize[11]; + (void)sprintf_s(chunkSize, sizeof(chunkSize), "%" PRIXz "\r\n", Stream_Length(sPacket)); + sChunk = Stream_New(NULL, strnlen(chunkSize, sizeof(chunkSize)) + Stream_Length(sPacket) + 2); + + if (!sChunk) + return FALSE; + + Stream_Write(sChunk, chunkSize, strnlen(chunkSize, sizeof(chunkSize))); + Stream_Write(sChunk, Stream_Buffer(sPacket), Stream_Length(sPacket)); + Stream_Write(sChunk, "\r\n", 2); + Stream_SealLength(sChunk); + len = Stream_Length(sChunk); + + if (len > INT_MAX) + { + Stream_Free(sChunk, TRUE); + return FALSE; + } + + ERR_clear_error(); + status = BIO_write(bio, Stream_Buffer(sChunk), (int)len); + Stream_Free(sChunk, TRUE); + + if (status != (SSIZE_T)len) + return FALSE; + + return TRUE; +} + +static BOOL rdg_write_packet(rdpRdg* rdg, wStream* sPacket) +{ + if (rdg->transferEncoding.isWebsocketTransport) + return websocket_context_write_wstream(rdg->transferEncoding.context.websocket, + rdg->tlsOut->bio, sPacket, WebsocketBinaryOpcode); + + return rdg_write_chunked(rdg->tlsIn->bio, sPacket); +} + +static int rdg_socket_read(BIO* bio, BYTE* pBuffer, size_t size, + rdg_http_encoding_context* encodingContext) +{ + WINPR_ASSERT(encodingContext != NULL); + if (size > INT32_MAX) + return -1; + + if (encodingContext->isWebsocketTransport) + return websocket_context_read(encodingContext->context.websocket, bio, pBuffer, size); + + switch (encodingContext->httpTransferEncoding) + { + case TransferEncodingIdentity: + ERR_clear_error(); + return BIO_read(bio, pBuffer, (int)size); + case TransferEncodingChunked: + return http_chuncked_read(bio, pBuffer, size, &encodingContext->context.chunked); + default: + return -1; + } +} + +static BOOL rdg_shall_abort(rdpRdg* rdg) +{ + WINPR_ASSERT(rdg); + return freerdp_shall_disconnect_context(rdg->context); +} + +static BOOL rdg_read_all(rdpContext* context, rdpTls* tls, BYTE* buffer, size_t size, + rdg_http_encoding_context* transferEncoding) +{ + size_t readCount = 0; + BYTE* pBuffer = buffer; + + while (readCount < size) + { + if (freerdp_shall_disconnect_context(context)) + return FALSE; + + int status = rdg_socket_read(tls->bio, pBuffer, size - readCount, transferEncoding); + if (status <= 0) + { + if (!BIO_should_retry(tls->bio)) + return FALSE; + + Sleep(10); + continue; + } + + readCount += WINPR_ASSERTING_INT_CAST(uint32_t, status); + pBuffer += WINPR_ASSERTING_INT_CAST(uint32_t, status); + } + + return TRUE; +} + +static wStream* rdg_receive_packet(rdpRdg* rdg) +{ + const size_t header = sizeof(RdgPacketHeader); + size_t packetLength = 0; + wStream* s = Stream_New(NULL, 1024); + + if (!s) + return NULL; + + if (!rdg_read_all(rdg->context, rdg->tlsOut, Stream_Buffer(s), header, &rdg->transferEncoding)) + { + Stream_Free(s, TRUE); + return NULL; + } + + Stream_Seek(s, 4); + Stream_Read_UINT32(s, packetLength); + + if ((packetLength > INT_MAX) || !Stream_EnsureCapacity(s, packetLength) || + (packetLength < header)) + { + Stream_Free(s, TRUE); + return NULL; + } + + if (!rdg_read_all(rdg->context, rdg->tlsOut, Stream_Buffer(s) + header, packetLength - header, + &rdg->transferEncoding)) + { + Stream_Free(s, TRUE); + return NULL; + } + + Stream_SetLength(s, packetLength); + return s; +} + +static BOOL rdg_send_handshake(rdpRdg* rdg) +{ + BOOL status = FALSE; + wStream* s = Stream_New(NULL, 14); + + if (!s) + return FALSE; + + Stream_Write_UINT16(s, PKT_TYPE_HANDSHAKE_REQUEST); /* Type (2 bytes) */ + Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ + Stream_Write_UINT32(s, 14); /* PacketLength (4 bytes) */ + Stream_Write_UINT8(s, 1); /* VersionMajor (1 byte) */ + Stream_Write_UINT8(s, 0); /* VersionMinor (1 byte) */ + Stream_Write_UINT16(s, 0); /* ClientVersion (2 bytes), must be 0 */ + Stream_Write_UINT16(s, rdg->extAuth); /* ExtendedAuthentication (2 bytes) */ + Stream_SealLength(s); + status = rdg_write_packet(rdg, s); + Stream_Free(s, TRUE); + + if (status) + { + rdg->state = RDG_CLIENT_STATE_HANDSHAKE; + } + + return status; +} + +static BOOL rdg_send_extauth_sspi(rdpRdg* rdg) +{ + wStream* s = NULL; + BOOL status = 0; + UINT32 packetSize = 8 + 4 + 2; + + WINPR_ASSERT(rdg); + + const SecBuffer* authToken = credssp_auth_get_output_buffer(rdg->auth); + if (!authToken) + return FALSE; + packetSize += authToken->cbBuffer; + + s = Stream_New(NULL, packetSize); + + if (!s) + return FALSE; + + Stream_Write_UINT16(s, PKT_TYPE_EXTENDED_AUTH_MSG); /* Type (2 bytes) */ + Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ + Stream_Write_UINT32(s, packetSize); /* PacketLength (4 bytes) */ + Stream_Write_UINT32(s, ERROR_SUCCESS); /* Error code */ + Stream_Write_UINT16(s, (UINT16)authToken->cbBuffer); + Stream_Write(s, authToken->pvBuffer, authToken->cbBuffer); + + Stream_SealLength(s); + status = rdg_write_packet(rdg, s); + Stream_Free(s, TRUE); + + return status; +} + +static BOOL rdg_send_tunnel_request(rdpRdg* rdg) +{ + wStream* s = NULL; + BOOL status = 0; + UINT32 packetSize = 16; + UINT16 fieldsPresent = 0; + WCHAR* PAACookie = NULL; + size_t PAACookieLen = 0; + const UINT32 capabilities = HTTP_CAPABILITY_TYPE_QUAR_SOH | + HTTP_CAPABILITY_MESSAGING_CONSENT_SIGN | + HTTP_CAPABILITY_MESSAGING_SERVICE_MSG; + + if (rdg->extAuth == HTTP_EXTENDED_AUTH_PAA) + { + PAACookie = + ConvertUtf8ToWCharAlloc(rdg->context->settings->GatewayAccessToken, &PAACookieLen); + + if (!PAACookie || (PAACookieLen > UINT16_MAX / sizeof(WCHAR))) + { + free(PAACookie); + return FALSE; + } + + PAACookieLen += 1; /* include \0 */ + packetSize += 2 + (UINT32)(PAACookieLen) * sizeof(WCHAR); + fieldsPresent = HTTP_TUNNEL_PACKET_FIELD_PAA_COOKIE; + } + + s = Stream_New(NULL, packetSize); + + if (!s) + { + free(PAACookie); + return FALSE; + } + + Stream_Write_UINT16(s, PKT_TYPE_TUNNEL_CREATE); /* Type (2 bytes) */ + Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ + Stream_Write_UINT32(s, packetSize); /* PacketLength (4 bytes) */ + Stream_Write_UINT32(s, capabilities); /* CapabilityFlags (4 bytes) */ + Stream_Write_UINT16(s, fieldsPresent); /* FieldsPresent (2 bytes) */ + Stream_Write_UINT16(s, 0); /* Reserved (2 bytes), must be 0 */ + + if (PAACookie) + { + Stream_Write_UINT16(s, (UINT16)PAACookieLen * sizeof(WCHAR)); /* PAA cookie string length */ + Stream_Write_UTF16_String(s, PAACookie, PAACookieLen); + } + + Stream_SealLength(s); + status = rdg_write_packet(rdg, s); + Stream_Free(s, TRUE); + free(PAACookie); + + if (status) + { + rdg->state = RDG_CLIENT_STATE_TUNNEL_CREATE; + } + + return status; +} + +static BOOL rdg_send_tunnel_authorization(rdpRdg* rdg) +{ + wStream* s = NULL; + BOOL status = 0; + WINPR_ASSERT(rdg); + size_t clientNameLen = 0; + WCHAR* clientName = freerdp_settings_get_string_as_utf16( + rdg->context->settings, FreeRDP_ClientHostname, &clientNameLen); + + clientNameLen++; // length including terminating '\0' + + const size_t packetSize = 12ull + clientNameLen * sizeof(WCHAR); + if (!clientName || (clientNameLen >= UINT16_MAX / sizeof(WCHAR)) || (packetSize > UINT32_MAX)) + { + free(clientName); + return FALSE; + } + + s = Stream_New(NULL, packetSize); + + if (!s) + { + free(clientName); + return FALSE; + } + + Stream_Write_UINT16(s, PKT_TYPE_TUNNEL_AUTH); /* Type (2 bytes) */ + Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ + Stream_Write_UINT32(s, (UINT32)packetSize); /* PacketLength (4 bytes) */ + Stream_Write_UINT16(s, 0); /* FieldsPresent (2 bytes) */ + Stream_Write_UINT16(s, (UINT16)clientNameLen * sizeof(WCHAR)); /* Client name string length */ + Stream_Write_UTF16_String(s, clientName, clientNameLen); + Stream_SealLength(s); + status = rdg_write_packet(rdg, s); + Stream_Free(s, TRUE); + free(clientName); + + if (status) + { + rdg->state = RDG_CLIENT_STATE_TUNNEL_AUTHORIZE; + } + + return status; +} + +static BOOL rdg_send_channel_create(rdpRdg* rdg) +{ + wStream* s = NULL; + BOOL status = FALSE; + WCHAR* serverName = NULL; + size_t serverNameLen = 0; + + WINPR_ASSERT(rdg); + serverName = freerdp_settings_get_string_as_utf16(rdg->context->settings, + FreeRDP_ServerHostname, &serverNameLen); + + serverNameLen++; // length including terminating '\0' + const size_t packetSize = 16ull + serverNameLen * sizeof(WCHAR); + if (!serverName || (serverNameLen >= UINT16_MAX / sizeof(WCHAR)) || (packetSize > UINT32_MAX)) + goto fail; + + s = Stream_New(NULL, packetSize); + + if (!s) + goto fail; + + Stream_Write_UINT16(s, PKT_TYPE_CHANNEL_CREATE); /* Type (2 bytes) */ + Stream_Write_UINT16(s, 0); /* Reserved (2 bytes) */ + Stream_Write_UINT32(s, (UINT32)packetSize); /* PacketLength (4 bytes) */ + Stream_Write_UINT8(s, 1); /* Number of resources. (1 byte) */ + Stream_Write_UINT8(s, 0); /* Number of alternative resources (1 byte) */ + Stream_Write_UINT16(s, + (UINT16)rdg->context->settings->ServerPort); /* Resource port (2 bytes) */ + Stream_Write_UINT16(s, 3); /* Protocol number (2 bytes) */ + Stream_Write_UINT16(s, (UINT16)serverNameLen * sizeof(WCHAR)); + Stream_Write_UTF16_String(s, serverName, serverNameLen); + Stream_SealLength(s); + status = rdg_write_packet(rdg, s); +fail: + free(serverName); + Stream_Free(s, TRUE); + + if (status) + rdg->state = RDG_CLIENT_STATE_CHANNEL_CREATE; + + return status; +} + +static BOOL rdg_set_auth_header(rdpCredsspAuth* auth, HttpRequest* request) +{ + const SecBuffer* authToken = credssp_auth_get_output_buffer(auth); + char* base64AuthToken = NULL; + + if (authToken) + { + if (authToken->cbBuffer > INT_MAX) + return FALSE; + + base64AuthToken = crypto_base64_encode(authToken->pvBuffer, authToken->cbBuffer); + } + + if (base64AuthToken) + { + BOOL rc = http_request_set_auth_scheme(request, credssp_auth_pkg_name(auth)) && + http_request_set_auth_param(request, base64AuthToken); + free(base64AuthToken); + + if (!rc) + return FALSE; + } + + return TRUE; +} + +static wStream* rdg_build_http_request(rdpRdg* rdg, const char* method, + TRANSFER_ENCODING transferEncoding) +{ + wStream* s = NULL; + HttpRequest* request = NULL; + const char* uri = NULL; + + if (!rdg || !method) + return NULL; + + uri = http_context_get_uri(rdg->http); + request = http_request_new(); + + if (!request) + return NULL; + + if (!http_request_set_method(request, method) || !http_request_set_uri(request, uri)) + goto out; + + if (rdg->auth) + { + if (!rdg_set_auth_header(rdg->auth, request)) + goto out; + } + + else if (rdg->extAuth == HTTP_EXTENDED_AUTH_BEARER) + { + http_request_set_auth_scheme(request, "Bearer"); + http_request_set_auth_param(request, rdg->context->settings->GatewayHttpExtAuthBearer); + } + + http_request_set_transfer_encoding(request, transferEncoding); + + s = http_request_write(rdg->http, request); +out: + http_request_free(request); + + if (s) + Stream_SealLength(s); + + return s; +} + +static BOOL rdg_recv_auth_token(wLog* log, rdpCredsspAuth* auth, HttpResponse* response) +{ + size_t len = 0; + const char* token64 = NULL; + size_t authTokenLength = 0; + BYTE* authTokenData = NULL; + SecBuffer authToken = { 0 }; + long StatusCode = 0; + int rc = 0; + + if (!auth || !response) + return FALSE; + + StatusCode = http_response_get_status_code(response); + switch (StatusCode) + { + case HTTP_STATUS_DENIED: + case HTTP_STATUS_OK: + case HTTP_STATUS_SWITCH_PROTOCOLS: + break; + default: + http_response_log_error_status(log, WLOG_WARN, response); + return FALSE; + } + + token64 = http_response_get_auth_token(response, credssp_auth_pkg_name(auth)); + + if (!token64) + return FALSE; + + len = strlen(token64); + + crypto_base64_decode(token64, len, &authTokenData, &authTokenLength); + + if (authTokenLength && authTokenData && (authTokenLength <= UINT32_MAX)) + { + authToken.pvBuffer = authTokenData; + authToken.cbBuffer = (UINT32)authTokenLength; + credssp_auth_take_input_buffer(auth, &authToken); + } + else + free(authTokenData); + + rc = credssp_auth_authenticate(auth); + if (rc < 0) + return FALSE; + + return TRUE; +} + +static BOOL rdg_skip_seed_payload(rdpContext* context, rdpTls* tls, size_t lastResponseLength, + rdg_http_encoding_context* transferEncoding) +{ + BYTE seed_payload[10] = { 0 }; + const size_t size = sizeof(seed_payload); + + /* Per [MS-TSGU] 3.3.5.1 step 4, after final OK response RDG server sends + * random "seed" payload of limited size. In practice it's 10 bytes. + */ + if (lastResponseLength < size) + { + if (!rdg_read_all(context, tls, seed_payload, size - lastResponseLength, transferEncoding)) + { + return FALSE; + } + } + + return TRUE; +} + +static BOOL rdg_process_handshake_response(rdpRdg* rdg, wStream* s) +{ + UINT32 errorCode = 0; + UINT16 serverVersion = 0; + UINT16 extendedAuth = 0; + BYTE verMajor = 0; + BYTE verMinor = 0; + const char* error = NULL; + WLog_Print(rdg->log, WLOG_DEBUG, "Handshake response received"); + + if (rdg->state != RDG_CLIENT_STATE_HANDSHAKE) + { + return FALSE; + } + + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 10)) + return FALSE; + + Stream_Read_UINT32(s, errorCode); + Stream_Read_UINT8(s, verMajor); + Stream_Read_UINT8(s, verMinor); + Stream_Read_UINT16(s, serverVersion); + Stream_Read_UINT16(s, extendedAuth); + error = rpc_error_to_string(errorCode); + WLog_Print(rdg->log, WLOG_DEBUG, + "errorCode=%s, verMajor=%" PRId8 ", verMinor=%" PRId8 ", serverVersion=%" PRId16 + ", extendedAuth=%s", + error, verMajor, verMinor, serverVersion, extended_auth_to_string(extendedAuth)); + + if (FAILED((HRESULT)errorCode)) + { + WLog_Print(rdg->log, WLOG_ERROR, "Handshake error %s", error); + freerdp_set_last_error_log(rdg->context, errorCode); + return FALSE; + } + + if (rdg->extAuth == HTTP_EXTENDED_AUTH_SSPI_NTLM) + return rdg_send_extauth_sspi(rdg); + + return rdg_send_tunnel_request(rdg); +} + +static BOOL rdg_process_tunnel_response_optional(rdpRdg* rdg, wStream* s, UINT16 fieldsPresent) +{ + if (fieldsPresent & HTTP_TUNNEL_RESPONSE_FIELD_TUNNEL_ID) + { + /* Seek over tunnelId (4 bytes) */ + if (!Stream_SafeSeek(s, 4)) + { + WLog_Print(rdg->log, WLOG_ERROR, "Short tunnelId, got %" PRIuz ", expected 4", + Stream_GetRemainingLength(s)); + return FALSE; + } + } + + if (fieldsPresent & HTTP_TUNNEL_RESPONSE_FIELD_CAPS) + { + UINT32 caps = 0; + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 4)) + return FALSE; + + Stream_Read_UINT32(s, caps); + WLog_Print(rdg->log, WLOG_DEBUG, "capabilities=%s", capabilities_enum_to_string(caps)); + } + + if (fieldsPresent & HTTP_TUNNEL_RESPONSE_FIELD_SOH_REQ) + { + /* Seek over nonce (20 bytes) */ + if (!Stream_SafeSeek(s, 20)) + { + WLog_Print(rdg->log, WLOG_ERROR, "Short nonce, got %" PRIuz ", expected 20", + Stream_GetRemainingLength(s)); + return FALSE; + } + + /* Read serverCert */ + if (!rdg_read_http_unicode_string(rdg->log, s, NULL, NULL)) + { + WLog_Print(rdg->log, WLOG_ERROR, "Failed to read server certificate"); + return FALSE; + } + } + + if (fieldsPresent & HTTP_TUNNEL_RESPONSE_FIELD_CONSENT_MSG) + { + const WCHAR* msg = NULL; + UINT16 msgLenBytes = 0; + rdpContext* context = rdg->context; + + WINPR_ASSERT(context); + WINPR_ASSERT(context->instance); + + /* Read message string and invoke callback */ + if (!rdg_read_http_unicode_string(rdg->log, s, &msg, &msgLenBytes)) + { + WLog_Print(rdg->log, WLOG_ERROR, "Failed to read consent message"); + return FALSE; + } + + return IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, + GATEWAY_MESSAGE_CONSENT, TRUE, TRUE, msgLenBytes, msg); + } + + return TRUE; +} + +static BOOL rdg_process_tunnel_response(rdpRdg* rdg, wStream* s) +{ + UINT16 serverVersion = 0; + UINT16 fieldsPresent = 0; + UINT32 errorCode = 0; + const char* error = NULL; + WLog_Print(rdg->log, WLOG_DEBUG, "Tunnel response received"); + + if (rdg->state != RDG_CLIENT_STATE_TUNNEL_CREATE) + { + return FALSE; + } + + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 10)) + return FALSE; + + Stream_Read_UINT16(s, serverVersion); + Stream_Read_UINT32(s, errorCode); + Stream_Read_UINT16(s, fieldsPresent); + Stream_Seek_UINT16(s); /* reserved */ + error = rpc_error_to_string(errorCode); + WLog_Print(rdg->log, WLOG_DEBUG, "serverVersion=%" PRId16 ", errorCode=%s, fieldsPresent=%s", + serverVersion, error, tunnel_response_fields_present_to_string(fieldsPresent)); + + if (FAILED((HRESULT)errorCode)) + { + WLog_Print(rdg->log, WLOG_ERROR, "Tunnel creation error %s", error); + freerdp_set_last_error_log(rdg->context, errorCode); + return FALSE; + } + + if (!rdg_process_tunnel_response_optional(rdg, s, fieldsPresent)) + return FALSE; + + return rdg_send_tunnel_authorization(rdg); +} + +static BOOL rdg_process_tunnel_authorization_response(rdpRdg* rdg, wStream* s) +{ + UINT32 errorCode = 0; + UINT16 fieldsPresent = 0; + const char* error = NULL; + WLog_Print(rdg->log, WLOG_DEBUG, "Tunnel authorization received"); + + if (rdg->state != RDG_CLIENT_STATE_TUNNEL_AUTHORIZE) + { + return FALSE; + } + + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 8)) + return FALSE; + + Stream_Read_UINT32(s, errorCode); + Stream_Read_UINT16(s, fieldsPresent); + Stream_Seek_UINT16(s); /* reserved */ + error = rpc_error_to_string(errorCode); + WLog_Print(rdg->log, WLOG_DEBUG, "errorCode=%s, fieldsPresent=%s", error, + tunnel_authorization_response_fields_present_to_string(fieldsPresent)); + + /* [MS-TSGU] 3.7.5.2.7 */ + if (errorCode != S_OK && errorCode != E_PROXY_QUARANTINE_ACCESSDENIED) + { + WLog_Print(rdg->log, WLOG_ERROR, "Tunnel authorization error %s", error); + freerdp_set_last_error_log(rdg->context, errorCode); + return FALSE; + } + + if (fieldsPresent & HTTP_TUNNEL_AUTH_RESPONSE_FIELD_REDIR_FLAGS) + { + UINT32 redirFlags = 0; + if (!Stream_CheckAndLogRequiredCapacityWLog(rdg->log, s, 4)) + return FALSE; + Stream_Read_UINT32(s, redirFlags); + + rdpContext* context = rdg->context; + if (!utils_apply_gateway_policy(rdg->log, context, redirFlags, "RDG")) + return FALSE; + } + + if (fieldsPresent & HTTP_TUNNEL_AUTH_RESPONSE_FIELD_IDLE_TIMEOUT) + { + UINT32 idleTimeout = 0; + if (!Stream_CheckAndLogRequiredCapacityWLog(rdg->log, s, 4)) + return FALSE; + Stream_Read_UINT32(s, idleTimeout); + WLog_Print(rdg->log, WLOG_DEBUG, "[IDLE_TIMEOUT] idleTimeout=%" PRIu32 ": TODO: unused", + idleTimeout); + } + + if (fieldsPresent & HTTP_TUNNEL_AUTH_RESPONSE_FIELD_SOH_RESPONSE) + { + UINT16 cbLen = 0; + if (!Stream_CheckAndLogRequiredCapacityWLog(rdg->log, s, 2)) + return FALSE; + Stream_Read_UINT16(s, cbLen); + + WLog_Print(rdg->log, WLOG_DEBUG, "[SOH_RESPONSE] cbLen=%" PRIu16 ": TODO: unused", cbLen); + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, cbLen)) + return FALSE; + Stream_Seek(s, cbLen); + } + + return rdg_send_channel_create(rdg); +} + +static BOOL rdg_process_extauth_sspi(rdpRdg* rdg, wStream* s) +{ + INT32 errorCode = 0; + UINT16 authBlobLen = 0; + SecBuffer authToken = { 0 }; + BYTE* authTokenData = NULL; + + WINPR_ASSERT(rdg); + + Stream_Read_INT32(s, errorCode); + Stream_Read_UINT16(s, authBlobLen); + + if (errorCode != ERROR_SUCCESS) + { + WLog_Print(rdg->log, WLOG_ERROR, "EXTAUTH_SSPI_NTLM failed with error %s [0x%08X]", + GetSecurityStatusString(errorCode), errorCode); + return FALSE; + } + + if (authBlobLen == 0) + { + if (credssp_auth_is_complete(rdg->auth)) + { + credssp_auth_free(rdg->auth); + rdg->auth = NULL; + return rdg_send_tunnel_request(rdg); + } + return FALSE; + } + + authTokenData = malloc(authBlobLen); + if (authTokenData == NULL) + return FALSE; + Stream_Read(s, authTokenData, authBlobLen); + + authToken.pvBuffer = authTokenData; + authToken.cbBuffer = authBlobLen; + + credssp_auth_take_input_buffer(rdg->auth, &authToken); + + if (credssp_auth_authenticate(rdg->auth) < 0) + return FALSE; + + if (credssp_auth_have_output_token(rdg->auth)) + return rdg_send_extauth_sspi(rdg); + + return FALSE; +} + +static BOOL rdg_process_channel_response(rdpRdg* rdg, wStream* s) +{ + UINT16 fieldsPresent = 0; + UINT32 errorCode = 0; + const char* error = NULL; + WLog_Print(rdg->log, WLOG_DEBUG, "Channel response received"); + + if (rdg->state != RDG_CLIENT_STATE_CHANNEL_CREATE) + { + return FALSE; + } + + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 8)) + return FALSE; + + Stream_Read_UINT32(s, errorCode); + Stream_Read_UINT16(s, fieldsPresent); + Stream_Seek_UINT16(s); /* reserved */ + error = rpc_error_to_string(errorCode); + WLog_Print(rdg->log, WLOG_DEBUG, "channel response errorCode=%s, fieldsPresent=%s", error, + channel_response_fields_present_to_string(fieldsPresent)); + + if (FAILED((HRESULT)errorCode)) + { + WLog_Print(rdg->log, WLOG_ERROR, "channel response errorCode=%s, fieldsPresent=%s", error, + channel_response_fields_present_to_string(fieldsPresent)); + freerdp_set_last_error_log(rdg->context, errorCode); + return FALSE; + } + + rdg->state = RDG_CLIENT_STATE_OPENED; + return TRUE; +} + +static BOOL rdg_process_packet(rdpRdg* rdg, wStream* s) +{ + BOOL status = TRUE; + UINT16 type = 0; + UINT32 packetLength = 0; + Stream_SetPosition(s, 0); + + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 8)) + return FALSE; + + Stream_Read_UINT16(s, type); + Stream_Seek_UINT16(s); /* reserved */ + Stream_Read_UINT32(s, packetLength); + + if (Stream_Length(s) < packetLength) + { + WLog_Print(rdg->log, WLOG_ERROR, "Short packet %" PRIuz ", expected %" PRIuz, + Stream_Length(s), packetLength); + return FALSE; + } + + switch (type) + { + case PKT_TYPE_HANDSHAKE_RESPONSE: + status = rdg_process_handshake_response(rdg, s); + break; + + case PKT_TYPE_TUNNEL_RESPONSE: + status = rdg_process_tunnel_response(rdg, s); + break; + + case PKT_TYPE_TUNNEL_AUTH_RESPONSE: + status = rdg_process_tunnel_authorization_response(rdg, s); + break; + + case PKT_TYPE_CHANNEL_RESPONSE: + status = rdg_process_channel_response(rdg, s); + break; + + case PKT_TYPE_DATA: + WLog_Print(rdg->log, WLOG_ERROR, "Unexpected packet type DATA"); + return FALSE; + + case PKT_TYPE_EXTENDED_AUTH_MSG: + status = rdg_process_extauth_sspi(rdg, s); + break; + + default: + WLog_Print(rdg->log, WLOG_ERROR, "PKG TYPE 0x%x not implemented", type); + return FALSE; + } + + return status; +} + +DWORD rdg_get_event_handles(rdpRdg* rdg, HANDLE* events, DWORD count) +{ + DWORD nCount = 0; + WINPR_ASSERT(rdg != NULL); + + if (rdg->tlsOut && rdg->tlsOut->bio) + { + if (events && (nCount < count)) + { + BIO_get_event(rdg->tlsOut->bio, &events[nCount]); + nCount++; + } + else + return 0; + } + + /* We just need the read event handle even in non-websocket mode. */ + + return nCount; +} + +static BOOL rdg_get_gateway_credentials(rdpContext* context, rdp_auth_reason reason) +{ + freerdp* instance = context->instance; + + auth_status rc = utils_authenticate_gateway(instance, reason); + switch (rc) + { + case AUTH_SUCCESS: + case AUTH_SKIP: + return TRUE; + case AUTH_CANCELLED: + freerdp_set_last_error_log(instance->context, FREERDP_ERROR_CONNECT_CANCELLED); + return FALSE; + case AUTH_NO_CREDENTIALS: + WLog_INFO(TAG, "No credentials provided - using NULL identity"); + return TRUE; + case AUTH_FAILED: + default: + return FALSE; + } +} + +static BOOL rdg_auth_init(rdpRdg* rdg, rdpTls* tls, TCHAR* authPkg) +{ + rdpContext* context = rdg->context; + rdpSettings* settings = context->settings; + SEC_WINNT_AUTH_IDENTITY identity = { 0 }; + int rc = 0; + + rdg->auth = credssp_auth_new(context); + if (!rdg->auth) + return FALSE; + + if (!credssp_auth_init(rdg->auth, authPkg, tls->Bindings)) + return FALSE; + + BOOL doSCLogon = freerdp_settings_get_bool(settings, FreeRDP_SmartcardLogon); + if (doSCLogon) + { + if (!smartcard_getCert(context, &rdg->smartcard, TRUE)) + return FALSE; + + if (!rdg_get_gateway_credentials(context, AUTH_SMARTCARD_PIN)) + return FALSE; + } + else + { + if (!rdg_get_gateway_credentials(context, GW_AUTH_RDG)) + return FALSE; + + /* Auth callback might changed logon to smartcard so check again */ + doSCLogon = freerdp_settings_get_bool(settings, FreeRDP_SmartcardLogon); + if (doSCLogon && !smartcard_getCert(context, &rdg->smartcard, TRUE)) + return FALSE; + } + + SEC_WINNT_AUTH_IDENTITY* identityArg = &identity; + if (doSCLogon) + { + if (!identity_set_from_smartcard_hash(&identity, settings, FreeRDP_GatewayUsername, + FreeRDP_GatewayDomain, FreeRDP_GatewayPassword, + rdg->smartcard->sha1Hash, + sizeof(rdg->smartcard->sha1Hash))) + return FALSE; + } + else + { + if (!identity_set_from_settings(&identity, settings, FreeRDP_GatewayUsername, + FreeRDP_GatewayDomain, FreeRDP_GatewayPassword)) + return FALSE; + + if (!settings->GatewayUsername) + identityArg = NULL; + } + + if (!credssp_auth_setup_client(rdg->auth, "HTTP", settings->GatewayHostname, identityArg, + rdg->smartcard ? rdg->smartcard->pkinitArgs : NULL)) + { + sspi_FreeAuthIdentity(&identity); + return FALSE; + } + sspi_FreeAuthIdentity(&identity); + + credssp_auth_set_flags(rdg->auth, ISC_REQ_CONFIDENTIALITY | ISC_REQ_MUTUAL_AUTH); + + rc = credssp_auth_authenticate(rdg->auth); + if (rc < 0) + return FALSE; + + return TRUE; +} + +static BOOL rdg_send_http_request(rdpRdg* rdg, rdpTls* tls, const char* method, + TRANSFER_ENCODING transferEncoding) +{ + int status = -1; + wStream* s = rdg_build_http_request(rdg, method, transferEncoding); + + if (!s) + return FALSE; + + const size_t sz = Stream_Length(s); + status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); + + Stream_Free(s, TRUE); + return (status >= 0); +} + +static BOOL rdg_tls_connect(rdpRdg* rdg, rdpTls* tls, const char* peerAddress, UINT32 timeout) +{ + long status = 0; + BIO* layerBio = NULL; + BIO* bufferedBio = NULL; + rdpTransportLayer* layer = NULL; + rdpSettings* settings = rdg->context->settings; + rdpTransport* transport = freerdp_get_transport(rdg->context); + const char* peerHostname = settings->GatewayHostname; + UINT16 peerPort = (UINT16)settings->GatewayPort; + const char* proxyUsername = NULL; + const char* proxyPassword = NULL; + BOOL isProxyConnection = + proxy_prepare(settings, &peerHostname, &peerPort, &proxyUsername, &proxyPassword); + + if (settings->GatewayPort > UINT16_MAX) + return FALSE; + + layer = transport_connect_layer(transport, peerAddress ? peerAddress : peerHostname, peerPort, + timeout); + + if (!layer) + { + return FALSE; + } + + layerBio = BIO_new(BIO_s_transport_layer()); + if (!layerBio) + { + transport_layer_free(layer); + return FALSE; + } + BIO_set_data(layerBio, layer); + + bufferedBio = BIO_new(BIO_s_buffered_socket()); + if (!bufferedBio) + { + BIO_free_all(layerBio); + return FALSE; + } + + bufferedBio = BIO_push(bufferedBio, layerBio); + status = BIO_set_nonblock(bufferedBio, TRUE); + + if (isProxyConnection) + { + if (!proxy_connect(rdg->context, bufferedBio, proxyUsername, proxyPassword, + settings->GatewayHostname, (UINT16)settings->GatewayPort)) + { + BIO_free_all(bufferedBio); + return FALSE; + } + } + + if (!status) + { + BIO_free_all(bufferedBio); + return FALSE; + } + + tls->hostname = settings->GatewayHostname; + tls->port = WINPR_ASSERTING_INT_CAST(int32_t, MIN(UINT16_MAX, settings->GatewayPort)); + tls->isGatewayTransport = TRUE; + status = freerdp_tls_connect(tls, bufferedBio); + if (status < 1) + { + rdpContext* context = rdg->context; + if (status < 0) + { + freerdp_set_last_error_if_not(context, FREERDP_ERROR_TLS_CONNECT_FAILED); + } + else + { + freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED); + } + + return FALSE; + } + return (status >= 1); +} + +static BOOL rdg_establish_data_connection(rdpRdg* rdg, rdpTls* tls, const char* method, + const char* peerAddress, UINT32 timeout, + BOOL* rpcFallback) +{ + char buffer[64] = { 0 }; + HttpResponse* response = NULL; + + if (!rdg_tls_connect(rdg, tls, peerAddress, timeout)) + return FALSE; + + WINPR_ASSERT(rpcFallback); + if (rdg->context->settings->GatewayHttpExtAuthBearer && rdg->extAuth == HTTP_EXTENDED_AUTH_NONE) + rdg->extAuth = HTTP_EXTENDED_AUTH_BEARER; + if (rdg->extAuth == HTTP_EXTENDED_AUTH_NONE) + { + if (!rdg_auth_init(rdg, tls, AUTH_PKG)) + return FALSE; + + if (!rdg_send_http_request(rdg, tls, method, TransferEncodingIdentity)) + return FALSE; + + response = http_response_recv(tls, TRUE); + /* MS RD Gateway seems to just terminate the tls connection without + * sending an answer if it is not happy with the http request */ + if (!response) + { + WLog_Print(rdg->log, WLOG_INFO, "RD Gateway HTTP transport broken."); + *rpcFallback = TRUE; + return FALSE; + } + + const long StatusCode = http_response_get_status_code(response); + + switch (StatusCode) + { + case HTTP_STATUS_NOT_FOUND: + { + WLog_Print(rdg->log, WLOG_INFO, "RD Gateway does not support HTTP transport."); + *rpcFallback = TRUE; + + http_response_free(response); + return FALSE; + } + case HTTP_STATUS_OK: + break; + default: + http_response_log_error_status(rdg->log, WLOG_WARN, response); + break; + } + + while (!credssp_auth_is_complete(rdg->auth)) + { + if (!rdg_recv_auth_token(rdg->log, rdg->auth, response)) + { + http_response_free(response); + return FALSE; + } + + if (credssp_auth_have_output_token(rdg->auth)) + { + http_response_free(response); + + if (!rdg_send_http_request(rdg, tls, method, TransferEncodingIdentity)) + return FALSE; + + response = http_response_recv(tls, TRUE); + if (!response) + { + WLog_Print(rdg->log, WLOG_INFO, "RD Gateway HTTP transport broken."); + *rpcFallback = TRUE; + return FALSE; + } + } + } + credssp_auth_free(rdg->auth); + rdg->auth = NULL; + } + else + { + credssp_auth_free(rdg->auth); + rdg->auth = NULL; + + if (!rdg_send_http_request(rdg, tls, method, TransferEncodingIdentity)) + return FALSE; + + response = http_response_recv(tls, TRUE); + + if (!response) + { + WLog_Print(rdg->log, WLOG_INFO, "RD Gateway HTTP transport broken."); + *rpcFallback = TRUE; + return FALSE; + } + } + + const long statusCode = http_response_get_status_code(response); + const size_t bodyLength = http_response_get_body_length(response); + const TRANSFER_ENCODING encoding = http_response_get_transfer_encoding(response); + const BOOL isWebsocket = http_response_is_websocket(rdg->http, response); + + WLog_Print(rdg->log, WLOG_DEBUG, "%s authorization result: %s", method, + freerdp_http_status_string_format(statusCode, buffer, ARRAYSIZE(buffer))); + + switch (statusCode) + { + case HTTP_STATUS_OK: + /* old rdg endpoint without websocket support, don't request websocket for RDG_IN_DATA + */ + http_context_enable_websocket_upgrade(rdg->http, FALSE); + http_response_free(response); + break; + case HTTP_STATUS_DENIED: + freerdp_set_last_error_log(rdg->context, FREERDP_ERROR_CONNECT_ACCESS_DENIED); + http_response_free(response); + return FALSE; + case HTTP_STATUS_SWITCH_PROTOCOLS: + http_response_free(response); + if (!isWebsocket) + { + /* + * webserver is broken, a fallback may be possible here + * but only if already tested with oppurtonistic upgrade + */ + if (http_context_is_websocket_upgrade_enabled(rdg->http)) + { + long fd = BIO_get_fd(tls->bio, NULL); + if (fd >= 0) + closesocket((SOCKET)fd); + http_context_enable_websocket_upgrade(rdg->http, FALSE); + return rdg_establish_data_connection(rdg, tls, method, peerAddress, timeout, + rpcFallback); + } + return FALSE; + } + + rdg->transferEncoding.isWebsocketTransport = TRUE; + if (!websocket_context_reset(rdg->transferEncoding.context.websocket)) + return FALSE; + + if (rdg->extAuth == HTTP_EXTENDED_AUTH_SSPI_NTLM) + { + /* create a new auth context for SSPI_NTLM. This must be done after the last + * rdg_send_http_request */ + if (!rdg_auth_init(rdg, tls, NTLM_SSP_NAME)) + return FALSE; + } + return TRUE; + default: + http_response_log_error_status(rdg->log, WLOG_WARN, response); + http_response_free(response); + return FALSE; + } + + if (strcmp(method, "RDG_OUT_DATA") == 0) + { + if (encoding == TransferEncodingChunked) + { + rdg->transferEncoding.httpTransferEncoding = TransferEncodingChunked; + rdg->transferEncoding.context.chunked.nextOffset = 0; + rdg->transferEncoding.context.chunked.headerFooterPos = 0; + rdg->transferEncoding.context.chunked.state = ChunkStateLenghHeader; + } + if (!rdg_skip_seed_payload(rdg->context, tls, bodyLength, &rdg->transferEncoding)) + { + return FALSE; + } + } + else + { + if (!rdg_send_http_request(rdg, tls, method, TransferEncodingChunked)) + return FALSE; + + if (rdg->extAuth == HTTP_EXTENDED_AUTH_SSPI_NTLM) + { + /* create a new auth context for SSPI_NTLM. This must be done after the last + * rdg_send_http_request (RDG_IN_DATA is always after RDG_OUT_DATA) */ + if (!rdg_auth_init(rdg, tls, NTLM_SSP_NAME)) + return FALSE; + } + } + + return TRUE; +} + +static BOOL rdg_tunnel_connect(rdpRdg* rdg) +{ + BOOL status = 0; + wStream* s = NULL; + rdg_send_handshake(rdg); + + while (rdg->state < RDG_CLIENT_STATE_OPENED) + { + status = FALSE; + s = rdg_receive_packet(rdg); + + if (s) + { + status = rdg_process_packet(rdg, s); + Stream_Free(s, TRUE); + } + + if (!status) + { + WINPR_ASSERT(rdg); + WINPR_ASSERT(rdg->context); + WINPR_ASSERT(rdg->context->rdp); + transport_set_layer(rdg->context->rdp->transport, TRANSPORT_LAYER_CLOSED); + return FALSE; + } + } + + return TRUE; +} + +BOOL rdg_connect(rdpRdg* rdg, DWORD timeout, BOOL* rpcFallback) +{ + BOOL status = 0; + SOCKET outConnSocket = 0; + char* peerAddress = NULL; + BOOL rpcFallbackLocal = FALSE; + + WINPR_ASSERT(rdg != NULL); + status = rdg_establish_data_connection(rdg, rdg->tlsOut, "RDG_OUT_DATA", NULL, timeout, + &rpcFallbackLocal); + + if (status) + { + if (rdg->transferEncoding.isWebsocketTransport) + { + WLog_Print(rdg->log, WLOG_DEBUG, "Upgraded to websocket. RDG_IN_DATA not required"); + } + else + { + /* Establish IN connection with the same peer/server as OUT connection, + * even when server hostname resolves to different IP addresses. + */ + BIO_get_socket(rdg->tlsOut->underlying, &outConnSocket); + peerAddress = freerdp_tcp_get_peer_address(outConnSocket); + status = rdg_establish_data_connection(rdg, rdg->tlsIn, "RDG_IN_DATA", peerAddress, + timeout, &rpcFallbackLocal); + free(peerAddress); + } + } + + if (rpcFallback) + *rpcFallback = rpcFallbackLocal; + + if (!status) + { + WINPR_ASSERT(rdg); + WINPR_ASSERT(rdg->context); + WINPR_ASSERT(rdg->context->rdp); + if (rpcFallbackLocal) + { + http_context_enable_websocket_upgrade(rdg->http, FALSE); + credssp_auth_free(rdg->auth); + rdg->auth = NULL; + } + + transport_set_layer(rdg->context->rdp->transport, TRANSPORT_LAYER_CLOSED); + return FALSE; + } + + status = rdg_tunnel_connect(rdg); + + if (!status) + return FALSE; + + return TRUE; +} + +static int rdg_write_websocket_data_packet(rdpRdg* rdg, const BYTE* buf, int isize) +{ + WINPR_ASSERT(rdg); + if (isize < 0) + return -1; + + const size_t payloadSize = (size_t)isize + 10; + union + { + UINT32 u32; + UINT8 u8[4]; + } maskingKey; + + wStream* sWS = + websocket_context_packet_new(payloadSize, WebsocketBinaryOpcode, &maskingKey.u32); + if (!sWS) + return FALSE; + + Stream_Write_UINT16( + sWS, WINPR_ASSERTING_INT_CAST( + uint16_t, PKT_TYPE_DATA ^ (maskingKey.u8[0] | maskingKey.u8[1] << 8))); /* Type */ + Stream_Write_UINT16( + sWS, WINPR_ASSERTING_INT_CAST( + uint16_t, 0 ^ (maskingKey.u8[2] | maskingKey.u8[3] << 8))); /* Reserved */ + Stream_Write_UINT32( + sWS, WINPR_ASSERTING_INT_CAST(uint32_t, payloadSize ^ maskingKey.u32)); /* Packet length */ + Stream_Write_UINT16( + sWS, WINPR_ASSERTING_INT_CAST( + uint16_t, isize ^ (maskingKey.u8[0] | maskingKey.u8[1] << 8))); /* Data size */ + + /* masking key is now off by 2 bytes. fix that */ + maskingKey.u32 = (maskingKey.u32 & 0xffff) << 16 | (maskingKey.u32 >> 16); + + WINPR_ASSERT(rdg->tlsOut); + wStream sPacket = { 0 }; + Stream_StaticConstInit(&sPacket, buf, (size_t)isize); + if (!websocket_context_mask_and_send(rdg->tlsOut->bio, sWS, &sPacket, maskingKey.u32)) + return -1; + + return isize; +} + +static int rdg_write_chunked_data_packet(rdpRdg* rdg, const BYTE* buf, int isize) +{ + int status = 0; + size_t len = 0; + wStream* sChunk = NULL; + + if (isize > UINT16_MAX) + return -1; + + const size_t size = (size_t)isize; + if (size < 1) + return 0; + + const size_t packetSize = size + 10; + char chunkSize[11] = { 0 }; + (void)sprintf_s(chunkSize, sizeof(chunkSize), "%" PRIxz "\r\n", packetSize); + sChunk = Stream_New(NULL, strnlen(chunkSize, sizeof(chunkSize)) + packetSize + 2); + + if (!sChunk) + return -1; + + Stream_Write(sChunk, chunkSize, strnlen(chunkSize, sizeof(chunkSize))); + Stream_Write_UINT16(sChunk, PKT_TYPE_DATA); /* Type */ + Stream_Write_UINT16(sChunk, 0); /* Reserved */ + Stream_Write_UINT32(sChunk, (UINT32)packetSize); /* Packet length */ + Stream_Write_UINT16(sChunk, (UINT16)size); /* Data size */ + Stream_Write(sChunk, buf, size); /* Data */ + Stream_Write(sChunk, "\r\n", 2); + Stream_SealLength(sChunk); + len = Stream_Length(sChunk); + + status = freerdp_tls_write_all(rdg->tlsIn, Stream_Buffer(sChunk), len); + Stream_Free(sChunk, TRUE); + + if (status < 0) + return -1; + + return (int)size; +} + +static int rdg_write_data_packet(rdpRdg* rdg, const BYTE* buf, int isize) +{ + WINPR_ASSERT(rdg); + if (rdg->transferEncoding.isWebsocketTransport) + return rdg_write_websocket_data_packet(rdg, buf, isize); + else + return rdg_write_chunked_data_packet(rdg, buf, isize); +} + +static BOOL rdg_process_close_packet(rdpRdg* rdg, wStream* s) +{ + int status = -1; + wStream* sClose = NULL; + UINT32 errorCode = 0; + UINT32 packetSize = 12; + + /* Read error code */ + if (!Stream_CheckAndLogRequiredLengthWLog(rdg->log, s, 4)) + return FALSE; + Stream_Read_UINT32(s, errorCode); + + if (errorCode != 0) + freerdp_set_last_error_log(rdg->context, errorCode); + + sClose = Stream_New(NULL, packetSize); + if (!sClose) + return FALSE; + + Stream_Write_UINT16(sClose, PKT_TYPE_CLOSE_CHANNEL_RESPONSE); /* Type */ + Stream_Write_UINT16(sClose, 0); /* Reserved */ + Stream_Write_UINT32(sClose, packetSize); /* Packet length */ + Stream_Write_UINT32(sClose, 0); /* Status code */ + Stream_SealLength(sClose); + status = rdg_write_packet(rdg, sClose); + Stream_Free(sClose, TRUE); + + return (status < 0 ? FALSE : TRUE); +} + +static BOOL rdg_process_keep_alive_packet(rdpRdg* rdg) +{ + int status = -1; + wStream* sKeepAlive = NULL; + size_t packetSize = 8; + + sKeepAlive = Stream_New(NULL, packetSize); + + if (!sKeepAlive) + return FALSE; + + Stream_Write_UINT16(sKeepAlive, PKT_TYPE_KEEPALIVE); /* Type */ + Stream_Write_UINT16(sKeepAlive, 0); /* Reserved */ + Stream_Write_UINT32(sKeepAlive, (UINT32)packetSize); /* Packet length */ + Stream_SealLength(sKeepAlive); + status = rdg_write_packet(rdg, sKeepAlive); + Stream_Free(sKeepAlive, TRUE); + + return (status < 0 ? FALSE : TRUE); +} + +static BOOL rdg_process_service_message(rdpRdg* rdg, wStream* s) +{ + const WCHAR* msg = NULL; + UINT16 msgLenBytes = 0; + rdpContext* context = rdg->context; + WINPR_ASSERT(context); + WINPR_ASSERT(context->instance); + + /* Read message string */ + if (!rdg_read_http_unicode_string(rdg->log, s, &msg, &msgLenBytes)) + { + WLog_Print(rdg->log, WLOG_ERROR, "Failed to read string"); + return FALSE; + } + + return IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, + GATEWAY_MESSAGE_SERVICE, TRUE, FALSE, msgLenBytes, msg); +} + +static BOOL rdg_process_unknown_packet(rdpRdg* rdg, int type) +{ + WINPR_UNUSED(rdg); + WINPR_UNUSED(type); + WLog_Print(rdg->log, WLOG_WARN, "Unknown Control Packet received: %X", type); + return TRUE; +} + +static BOOL rdg_process_control_packet(rdpRdg* rdg, int type, size_t packetLength) +{ + wStream* s = NULL; + size_t readCount = 0; + int status = 0; + size_t payloadSize = packetLength - sizeof(RdgPacketHeader); + + if (packetLength < sizeof(RdgPacketHeader)) + return FALSE; + + // NOLINTNEXTLINE(bugprone-sizeof-expression) + WINPR_ASSERT(sizeof(RdgPacketHeader) < INT_MAX); + + if (payloadSize) + { + s = Stream_New(NULL, payloadSize); + + if (!s) + return FALSE; + + while (readCount < payloadSize) + { + if (rdg_shall_abort(rdg)) + { + Stream_Free(s, TRUE); + return FALSE; + } + status = rdg_socket_read(rdg->tlsOut->bio, Stream_Pointer(s), payloadSize - readCount, + &rdg->transferEncoding); + + if (status <= 0) + { + if (!BIO_should_retry(rdg->tlsOut->bio)) + { + Stream_Free(s, TRUE); + return FALSE; + } + + continue; + } + + Stream_Seek(s, (size_t)status); + readCount += (size_t)status; + + if (readCount > INT_MAX) + { + Stream_Free(s, TRUE); + return FALSE; + } + } + + Stream_SetPosition(s, 0); + } + + switch (type) + { + case PKT_TYPE_CLOSE_CHANNEL: + EnterCriticalSection(&rdg->writeSection); + status = rdg_process_close_packet(rdg, s); + LeaveCriticalSection(&rdg->writeSection); + break; + + case PKT_TYPE_KEEPALIVE: + EnterCriticalSection(&rdg->writeSection); + status = rdg_process_keep_alive_packet(rdg); + LeaveCriticalSection(&rdg->writeSection); + break; + + case PKT_TYPE_SERVICE_MESSAGE: + if (!s) + { + WLog_Print(rdg->log, WLOG_ERROR, + "PKT_TYPE_SERVICE_MESSAGE requires payload but none was sent"); + return FALSE; + } + status = rdg_process_service_message(rdg, s); + break; + + case PKT_TYPE_REAUTH_MESSAGE: + default: + status = rdg_process_unknown_packet(rdg, type); + break; + } + + Stream_Free(s, TRUE); + return status; +} + +static int rdg_read_data_packet(rdpRdg* rdg, BYTE* buffer, size_t size) +{ + RdgPacketHeader header = { 0 }; + size_t readCount = 0; + size_t readSize = 0; + int status = 0; + + if (!rdg->packetRemainingCount) + { + // NOLINTNEXTLINE(bugprone-sizeof-expression) + WINPR_ASSERT(sizeof(RdgPacketHeader) < INT_MAX); + + while (readCount < sizeof(RdgPacketHeader)) + { + if (rdg_shall_abort(rdg)) + return -1; + + status = rdg_socket_read(rdg->tlsOut->bio, (BYTE*)(&header) + readCount, + sizeof(RdgPacketHeader) - readCount, &rdg->transferEncoding); + + if (status <= 0) + { + if (!BIO_should_retry(rdg->tlsOut->bio)) + return -1; + + if (!readCount) + return 0; + + BIO_wait_read(rdg->tlsOut->bio, 50); + continue; + } + + readCount += (size_t)status; + + if (readCount > INT_MAX) + return -1; + } + + if (header.type != PKT_TYPE_DATA) + { + status = rdg_process_control_packet(rdg, header.type, header.packetLength); + + if (!status) + return -1; + + return 0; + } + + readCount = 0; + + while (readCount < 2) + { + if (rdg_shall_abort(rdg)) + return -1; + status = + rdg_socket_read(rdg->tlsOut->bio, (BYTE*)(&rdg->packetRemainingCount) + readCount, + 2 - readCount, &rdg->transferEncoding); + + if (status < 0) + { + if (!BIO_should_retry(rdg->tlsOut->bio)) + return -1; + + BIO_wait_read(rdg->tlsOut->bio, 50); + continue; + } + + readCount += (size_t)status; + } + } + + readSize = (rdg->packetRemainingCount < size) ? rdg->packetRemainingCount : size; + status = rdg_socket_read(rdg->tlsOut->bio, buffer, readSize, &rdg->transferEncoding); + + if (status <= 0) + { + if (!BIO_should_retry(rdg->tlsOut->bio)) + { + return -1; + } + + return 0; + } + + rdg->packetRemainingCount -= status; + return status; +} + +static int rdg_bio_write(BIO* bio, const char* buf, int num) +{ + int status = 0; + rdpRdg* rdg = (rdpRdg*)BIO_get_data(bio); + if (num < 0) + return num; + + BIO_clear_flags(bio, BIO_FLAGS_WRITE); + EnterCriticalSection(&rdg->writeSection); + status = rdg_write_data_packet(rdg, (const BYTE*)buf, num); + LeaveCriticalSection(&rdg->writeSection); + + if (status < 0) + { + BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return -1; + } + else if (status < num) + { + BIO_set_flags(bio, BIO_FLAGS_WRITE); + WSASetLastError(WSAEWOULDBLOCK); + } + else + { + BIO_set_flags(bio, BIO_FLAGS_WRITE); + } + + return status; +} + +static int rdg_bio_read(BIO* bio, char* buf, int size) +{ + int status = 0; + rdpRdg* rdg = (rdpRdg*)BIO_get_data(bio); + if (size < 0) + return size; + status = rdg_read_data_packet(rdg, (BYTE*)buf, (size_t)size); + + if (status < 0) + { + BIO_clear_retry_flags(bio); + return -1; + } + else if (status == 0) + { + BIO_set_retry_read(bio); + WSASetLastError(WSAEWOULDBLOCK); + return -1; + } + else + { + BIO_set_flags(bio, BIO_FLAGS_READ); + } + + return status; +} + +static int rdg_bio_puts(BIO* bio, const char* str) +{ + WINPR_UNUSED(bio); + WINPR_UNUSED(str); + return -2; +} + +// NOLINTNEXTLINE(readability-non-const-parameter) +static int rdg_bio_gets(BIO* bio, char* str, int size) +{ + WINPR_UNUSED(bio); + WINPR_UNUSED(str); + WINPR_UNUSED(size); + return -2; +} + +static long rdg_bio_ctrl(BIO* in_bio, int cmd, long arg1, void* arg2) +{ + long status = -1; + rdpRdg* rdg = (rdpRdg*)BIO_get_data(in_bio); + rdpTls* tlsOut = rdg->tlsOut; + rdpTls* tlsIn = rdg->tlsIn; + + if (cmd == BIO_CTRL_FLUSH) + { + (void)BIO_flush(tlsOut->bio); + if (!rdg->transferEncoding.isWebsocketTransport) + (void)BIO_flush(tlsIn->bio); + status = 1; + } + else if (cmd == BIO_C_SET_NONBLOCK) + { + status = 1; + } + else if (cmd == BIO_C_READ_BLOCKED) + { + BIO* cbio = tlsOut->bio; + status = BIO_read_blocked(cbio); + } + else if (cmd == BIO_C_WRITE_BLOCKED) + { + BIO* cbio = tlsIn->bio; + + if (rdg->transferEncoding.isWebsocketTransport) + cbio = tlsOut->bio; + + status = BIO_write_blocked(cbio); + } + else if (cmd == BIO_C_WAIT_READ) + { + int timeout = (int)arg1; + BIO* cbio = tlsOut->bio; + + if (BIO_read_blocked(cbio)) + return BIO_wait_read(cbio, timeout); + else if (BIO_write_blocked(cbio)) + return BIO_wait_write(cbio, timeout); + else + status = 1; + } + else if (cmd == BIO_C_WAIT_WRITE) + { + int timeout = (int)arg1; + BIO* cbio = tlsIn->bio; + + if (rdg->transferEncoding.isWebsocketTransport) + cbio = tlsOut->bio; + + if (BIO_write_blocked(cbio)) + status = BIO_wait_write(cbio, timeout); + else if (BIO_read_blocked(cbio)) + status = BIO_wait_read(cbio, timeout); + else + status = 1; + } + else if (cmd == BIO_C_GET_EVENT || cmd == BIO_C_GET_FD) + { + /* + * A note about BIO_C_GET_FD: + * Even if two FDs are part of RDG, only one FD can be returned here. + * + * In FreeRDP, BIO FDs are only used for polling, so it is safe to use the outgoing FD only + * + * See issue #3602 + */ + status = BIO_ctrl(tlsOut->bio, cmd, arg1, arg2); + } +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + else if (cmd == BIO_CTRL_GET_KTLS_SEND) + { + /* Even though BIO_get_ktls_send says that returning negative values is valid + * openssl internal sources are full of if(!BIO_get_ktls_send && ) stuff. This has some + * nasty sideeffects. return 0 as proper no KTLS offloading flag + */ + status = 0; + } + else if (cmd == BIO_CTRL_GET_KTLS_RECV) + { + /* Even though BIO_get_ktls_recv says that returning negative values is valid + * there is no reason to trust trust negative values are implemented right everywhere + */ + status = 0; + } +#endif + return status; +} + +static int rdg_bio_new(BIO* bio) +{ + BIO_set_init(bio, 1); + BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return 1; +} + +static int rdg_bio_free(BIO* bio) +{ + WINPR_UNUSED(bio); + return 1; +} + +static BIO_METHOD* BIO_s_rdg(void) +{ + static BIO_METHOD* bio_methods = NULL; + + if (bio_methods == NULL) + { + if (!(bio_methods = BIO_meth_new(BIO_TYPE_TSG, "RDGateway"))) + return NULL; + + BIO_meth_set_write(bio_methods, rdg_bio_write); + BIO_meth_set_read(bio_methods, rdg_bio_read); + BIO_meth_set_puts(bio_methods, rdg_bio_puts); + BIO_meth_set_gets(bio_methods, rdg_bio_gets); + BIO_meth_set_ctrl(bio_methods, rdg_bio_ctrl); + BIO_meth_set_create(bio_methods, rdg_bio_new); + BIO_meth_set_destroy(bio_methods, rdg_bio_free); + } + + return bio_methods; +} + +rdpRdg* rdg_new(rdpContext* context) +{ + if (!context) + return NULL; + + rdpRdg* rdg = (rdpRdg*)calloc(1, sizeof(rdpRdg)); + if (!rdg) + return NULL; + + rdg->log = WLog_Get(TAG); + rdg->state = RDG_CLIENT_STATE_INITIAL; + rdg->context = context; + rdg->extAuth = + (rdg->context->settings->GatewayHttpExtAuthSspiNtlm ? HTTP_EXTENDED_AUTH_SSPI_NTLM + : HTTP_EXTENDED_AUTH_NONE); + + if (rdg->context->settings->GatewayAccessToken) + rdg->extAuth = HTTP_EXTENDED_AUTH_PAA; + + UuidCreate(&rdg->guid); + + rdg->tlsOut = freerdp_tls_new(rdg->context); + + if (!rdg->tlsOut) + goto rdg_alloc_error; + + rdg->tlsIn = freerdp_tls_new(rdg->context); + + if (!rdg->tlsIn) + goto rdg_alloc_error; + + rdg->http = http_context_new(); + + if (!rdg->http) + goto rdg_alloc_error; + + if (!http_context_set_uri(rdg->http, "/remoteDesktopGateway/") || + !http_context_set_accept(rdg->http, "*/*") || + !http_context_set_cache_control(rdg->http, "no-cache") || + !http_context_set_pragma(rdg->http, "no-cache") || + !http_context_set_connection(rdg->http, "Keep-Alive") || + !http_context_set_user_agent(rdg->http, "MS-RDGateway/1.0") || + !http_context_set_host(rdg->http, rdg->context->settings->GatewayHostname) || + !http_context_set_rdg_connection_id(rdg->http, &rdg->guid) || + !http_context_set_rdg_correlation_id(rdg->http, &rdg->guid) || + !http_context_enable_websocket_upgrade( + rdg->http, + freerdp_settings_get_bool(rdg->context->settings, FreeRDP_GatewayHttpUseWebsockets))) + { + goto rdg_alloc_error; + } + + if (rdg->extAuth != HTTP_EXTENDED_AUTH_NONE) + { + switch (rdg->extAuth) + { + case HTTP_EXTENDED_AUTH_PAA: + if (!http_context_set_rdg_auth_scheme(rdg->http, "PAA")) + goto rdg_alloc_error; + + break; + + case HTTP_EXTENDED_AUTH_SSPI_NTLM: + if (!http_context_set_rdg_auth_scheme(rdg->http, "SSPI_NTLM")) + goto rdg_alloc_error; + + break; + + default: + WLog_Print(rdg->log, WLOG_DEBUG, + "RDG extended authentication method %d not supported", rdg->extAuth); + } + } + + rdg->frontBio = BIO_new(BIO_s_rdg()); + + if (!rdg->frontBio) + goto rdg_alloc_error; + + BIO_set_data(rdg->frontBio, rdg); + InitializeCriticalSection(&rdg->writeSection); + + rdg->transferEncoding.httpTransferEncoding = TransferEncodingIdentity; + rdg->transferEncoding.isWebsocketTransport = FALSE; + + rdg->transferEncoding.context.websocket = websocket_context_new(); + if (!rdg->transferEncoding.context.websocket) + goto rdg_alloc_error; + + return rdg; +rdg_alloc_error: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + rdg_free(rdg); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void rdg_free(rdpRdg* rdg) +{ + if (!rdg) + return; + + freerdp_tls_free(rdg->tlsOut); + freerdp_tls_free(rdg->tlsIn); + http_context_free(rdg->http); + credssp_auth_free(rdg->auth); + + if (!rdg->attached) + BIO_free_all(rdg->frontBio); + + DeleteCriticalSection(&rdg->writeSection); + + smartcardCertInfo_Free(rdg->smartcard); + + websocket_context_free(rdg->transferEncoding.context.websocket); + + free(rdg); +} + +BIO* rdg_get_front_bio_and_take_ownership(rdpRdg* rdg) +{ + if (!rdg) + return NULL; + + rdg->attached = TRUE; + return rdg->frontBio; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rdg.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rdg.h new file mode 100644 index 0000000000000000000000000000000000000000..29d1a220a26b369843c87991e2deecfbd25b854f --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rdg.h @@ -0,0 +1,42 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Remote Desktop Gateway (RDG) + * + * Copyright 2015 Denis Vincent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_RDG_H +#define FREERDP_LIB_CORE_GATEWAY_RDG_H + +#include +#include +#include + +/* needed for BIO */ +#include + +typedef struct rdp_rdg rdpRdg; + +FREERDP_LOCAL void rdg_free(rdpRdg* rdg); + +WINPR_ATTR_MALLOC(rdg_free, 1) +FREERDP_LOCAL rdpRdg* rdg_new(rdpContext* context); + +FREERDP_LOCAL BIO* rdg_get_front_bio_and_take_ownership(rdpRdg* rdg); + +FREERDP_LOCAL BOOL rdg_connect(rdpRdg* rdg, DWORD timeout, BOOL* rpcFallback); +FREERDP_LOCAL DWORD rdg_get_event_handles(rdpRdg* rdg, HANDLE* events, DWORD count); + +#endif /* FREERDP_LIB_CORE_GATEWAY_RDG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc.c new file mode 100644 index 0000000000000000000000000000000000000000..f08f18e15897918c452ef28f8f796133fabc5a19 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc.c @@ -0,0 +1,977 @@ +/* + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC over HTTP + * + * Copyright 2012 Fujitsu Technology Solutions GmbH + * Copyright 2012 Dmitrij Jasnov + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../settings.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef FREERDP_HAVE_VALGRIND_MEMCHECK_H +#include +#endif + +#include "../proxy.h" +#include "http.h" +#include "../credssp_auth.h" +#include "ncacn_http.h" +#include "rpc_bind.h" +#include "rpc_fault.h" +#include "rpc_client.h" + +#include "rpc.h" +#include "rts.h" + +#define TAG FREERDP_TAG("core.gateway.rpc") + +static const char* PTYPE_STRINGS[] = { "PTYPE_REQUEST", "PTYPE_PING", + "PTYPE_RESPONSE", "PTYPE_FAULT", + "PTYPE_WORKING", "PTYPE_NOCALL", + "PTYPE_REJECT", "PTYPE_ACK", + "PTYPE_CL_CANCEL", "PTYPE_FACK", + "PTYPE_CANCEL_ACK", "PTYPE_BIND", + "PTYPE_BIND_ACK", "PTYPE_BIND_NAK", + "PTYPE_ALTER_CONTEXT", "PTYPE_ALTER_CONTEXT_RESP", + "PTYPE_RPC_AUTH_3", "PTYPE_SHUTDOWN", + "PTYPE_CO_CANCEL", "PTYPE_ORPHANED", + "PTYPE_RTS", "" }; + +static const char* client_in_state_str(CLIENT_IN_CHANNEL_STATE state) +{ + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + const char* str = "CLIENT_IN_CHANNEL_STATE_UNKNOWN"; + + switch (state) + { + case CLIENT_IN_CHANNEL_STATE_INITIAL: + str = "CLIENT_IN_CHANNEL_STATE_INITIAL"; + break; + + case CLIENT_IN_CHANNEL_STATE_CONNECTED: + str = "CLIENT_IN_CHANNEL_STATE_CONNECTED"; + break; + + case CLIENT_IN_CHANNEL_STATE_SECURITY: + str = "CLIENT_IN_CHANNEL_STATE_SECURITY"; + break; + + case CLIENT_IN_CHANNEL_STATE_NEGOTIATED: + str = "CLIENT_IN_CHANNEL_STATE_NEGOTIATED"; + break; + + case CLIENT_IN_CHANNEL_STATE_OPENED: + str = "CLIENT_IN_CHANNEL_STATE_OPENED"; + break; + + case CLIENT_IN_CHANNEL_STATE_OPENED_A4W: + str = "CLIENT_IN_CHANNEL_STATE_OPENED_A4W"; + break; + + case CLIENT_IN_CHANNEL_STATE_FINAL: + str = "CLIENT_IN_CHANNEL_STATE_FINAL"; + break; + default: + break; + } + return str; +} + +static const char* client_out_state_str(CLIENT_OUT_CHANNEL_STATE state) +{ + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + const char* str = "CLIENT_OUT_CHANNEL_STATE_UNKNOWN"; + + switch (state) + { + case CLIENT_OUT_CHANNEL_STATE_INITIAL: + str = "CLIENT_OUT_CHANNEL_STATE_INITIAL"; + break; + + case CLIENT_OUT_CHANNEL_STATE_CONNECTED: + str = "CLIENT_OUT_CHANNEL_STATE_CONNECTED"; + break; + + case CLIENT_OUT_CHANNEL_STATE_SECURITY: + str = "CLIENT_OUT_CHANNEL_STATE_SECURITY"; + break; + + case CLIENT_OUT_CHANNEL_STATE_NEGOTIATED: + str = "CLIENT_OUT_CHANNEL_STATE_NEGOTIATED"; + break; + + case CLIENT_OUT_CHANNEL_STATE_OPENED: + str = "CLIENT_OUT_CHANNEL_STATE_OPENED"; + break; + + case CLIENT_OUT_CHANNEL_STATE_OPENED_A6W: + str = "CLIENT_OUT_CHANNEL_STATE_OPENED_A6W"; + break; + + case CLIENT_OUT_CHANNEL_STATE_OPENED_A10W: + str = "CLIENT_OUT_CHANNEL_STATE_OPENED_A10W"; + break; + + case CLIENT_OUT_CHANNEL_STATE_OPENED_B3W: + str = "CLIENT_OUT_CHANNEL_STATE_OPENED_B3W"; + break; + + case CLIENT_OUT_CHANNEL_STATE_RECYCLED: + str = "CLIENT_OUT_CHANNEL_STATE_RECYCLED"; + break; + + case CLIENT_OUT_CHANNEL_STATE_FINAL: + str = "CLIENT_OUT_CHANNEL_STATE_FINAL"; + break; + default: + break; + } + return str; +} + +const char* rpc_vc_state_str(VIRTUAL_CONNECTION_STATE state) +{ + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + const char* str = "VIRTUAL_CONNECTION_STATE_UNKNOWN"; + + switch (state) + { + case VIRTUAL_CONNECTION_STATE_INITIAL: + str = "VIRTUAL_CONNECTION_STATE_INITIAL"; + break; + + case VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT: + str = "VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT"; + break; + + case VIRTUAL_CONNECTION_STATE_WAIT_A3W: + str = "VIRTUAL_CONNECTION_STATE_WAIT_A3W"; + break; + + case VIRTUAL_CONNECTION_STATE_WAIT_C2: + str = "VIRTUAL_CONNECTION_STATE_WAIT_C2"; + break; + + case VIRTUAL_CONNECTION_STATE_OPENED: + str = "VIRTUAL_CONNECTION_STATE_OPENED"; + break; + + case VIRTUAL_CONNECTION_STATE_FINAL: + str = "VIRTUAL_CONNECTION_STATE_FINAL"; + break; + default: + break; + } + return str; +} + +/* + * [MS-RPCH]: Remote Procedure Call over HTTP Protocol Specification: + * http://msdn.microsoft.com/en-us/library/cc243950/ + * + * + * + * Connection Establishment + * + * Client Outbound Proxy Inbound Proxy Server + * | | | | + * |-----------------IN Channel Request--------------->| | + * |---OUT Channel Request-->| |<-Legacy Server Response-| + * | |<--------------Legacy Server Response--------------| + * | | | | + * |---------CONN_A1-------->| | | + * |----------------------CONN_B1--------------------->| | + * | |----------------------CONN_A2--------------------->| + * | | | | + * |<--OUT Channel Response--| |---------CONN_B2-------->| + * |<--------CONN_A3---------| | | + * | |<---------------------CONN_C1----------------------| + * | | |<--------CONN_B3---------| + * |<--------CONN_C2---------| | | + * | | | | + * + */ + +void rpc_pdu_header_print(wLog* log, const rpcconn_hdr_t* header) +{ + WINPR_ASSERT(header); + + WLog_Print(log, WLOG_INFO, "rpc_vers: %" PRIu8 "", header->common.rpc_vers); + WLog_Print(log, WLOG_INFO, "rpc_vers_minor: %" PRIu8 "", header->common.rpc_vers_minor); + + if (header->common.ptype > PTYPE_RTS) + WLog_Print(log, WLOG_INFO, "ptype: %s (%" PRIu8 ")", "PTYPE_UNKNOWN", header->common.ptype); + else + WLog_Print(log, WLOG_INFO, "ptype: %s (%" PRIu8 ")", PTYPE_STRINGS[header->common.ptype], + header->common.ptype); + + WLog_Print(log, WLOG_INFO, "pfc_flags (0x%02" PRIX8 ") = {", header->common.pfc_flags); + + if (header->common.pfc_flags & PFC_FIRST_FRAG) + WLog_Print(log, WLOG_INFO, " PFC_FIRST_FRAG"); + + if (header->common.pfc_flags & PFC_LAST_FRAG) + WLog_Print(log, WLOG_INFO, " PFC_LAST_FRAG"); + + if (header->common.pfc_flags & PFC_PENDING_CANCEL) + WLog_Print(log, WLOG_INFO, " PFC_PENDING_CANCEL"); + + if (header->common.pfc_flags & PFC_RESERVED_1) + WLog_Print(log, WLOG_INFO, " PFC_RESERVED_1"); + + if (header->common.pfc_flags & PFC_CONC_MPX) + WLog_Print(log, WLOG_INFO, " PFC_CONC_MPX"); + + if (header->common.pfc_flags & PFC_DID_NOT_EXECUTE) + WLog_Print(log, WLOG_INFO, " PFC_DID_NOT_EXECUTE"); + + if (header->common.pfc_flags & PFC_OBJECT_UUID) + WLog_Print(log, WLOG_INFO, " PFC_OBJECT_UUID"); + + WLog_Print(log, WLOG_INFO, " }"); + WLog_Print(log, WLOG_INFO, + "packed_drep[4]: %02" PRIX8 " %02" PRIX8 " %02" PRIX8 " %02" PRIX8 "", + header->common.packed_drep[0], header->common.packed_drep[1], + header->common.packed_drep[2], header->common.packed_drep[3]); + WLog_Print(log, WLOG_INFO, "frag_length: %" PRIu16 "", header->common.frag_length); + WLog_Print(log, WLOG_INFO, "auth_length: %" PRIu16 "", header->common.auth_length); + WLog_Print(log, WLOG_INFO, "call_id: %" PRIu32 "", header->common.call_id); + + if (header->common.ptype == PTYPE_RESPONSE) + { + WLog_Print(log, WLOG_INFO, "alloc_hint: %" PRIu32 "", header->response.alloc_hint); + WLog_Print(log, WLOG_INFO, "p_cont_id: %" PRIu16 "", header->response.p_cont_id); + WLog_Print(log, WLOG_INFO, "cancel_count: %" PRIu8 "", header->response.cancel_count); + WLog_Print(log, WLOG_INFO, "reserved: %" PRIu8 "", header->response.reserved); + } +} + +rpcconn_common_hdr_t rpc_pdu_header_init(const rdpRpc* rpc) +{ + rpcconn_common_hdr_t header = { 0 }; + WINPR_ASSERT(rpc); + + header.rpc_vers = rpc->rpc_vers; + header.rpc_vers_minor = rpc->rpc_vers_minor; + header.packed_drep[0] = rpc->packed_drep[0]; + header.packed_drep[1] = rpc->packed_drep[1]; + header.packed_drep[2] = rpc->packed_drep[2]; + header.packed_drep[3] = rpc->packed_drep[3]; + return header; +} + +size_t rpc_offset_align(size_t* offset, size_t alignment) +{ + size_t pad = 0; + pad = *offset; + *offset = (*offset + alignment - 1) & ~(alignment - 1); + pad = *offset - pad; + return pad; +} + +size_t rpc_offset_pad(size_t* offset, size_t pad) +{ + *offset += pad; + return pad; +} + +/* + * PDU Segments: + * ________________________________ + * | | + * | PDU Header | + * |________________________________| + * | | + * | | + * | PDU Body | + * | | + * |________________________________| + * | | + * | Security Trailer | + * |________________________________| + * | | + * | Authentication Token | + * |________________________________| + */ + +/* + * PDU Structure with verification trailer + * + * MUST only appear in a request PDU! + * ________________________________ + * | | + * | PDU Header | + * |________________________________| _______ + * | | /|\ + * | | | + * | Stub Data | | + * | | | + * |________________________________| | + * | | PDU Body + * | Stub Pad | | + * |________________________________| | + * | | | + * | Verification Trailer | | + * |________________________________| | + * | | | + * | Authentication Pad | | + * |________________________________| __\|/__ + * | | + * | Security Trailer | + * |________________________________| + * | | + * | Authentication Token | + * |________________________________| + * + */ + +/* + * Security Trailer: + * + * The sec_trailer structure MUST be placed at the end of the PDU, including past stub data, + * when present. The sec_trailer structure MUST be 4-byte aligned with respect to the beginning + * of the PDU. Padding octets MUST be used to align the sec_trailer structure if its natural + * beginning is not already 4-byte aligned. + * + * All PDUs that carry sec_trailer information share certain common fields: + * frag_length and auth_length. The beginning of the sec_trailer structure for each PDU MUST be + * calculated to start from offset (frag_length – auth_length – 8) from the beginning of the PDU. + * + * Immediately after the sec_trailer structure, there MUST be a BLOB carrying the authentication + * information produced by the security provider. This BLOB is called the authentication token and + * MUST be of size auth_length. The size MUST also be equal to the length from the first octet + * immediately after the sec_trailer structure all the way to the end of the fragment; + * the two values MUST be the same. + * + * A client or a server that (during composing of a PDU) has allocated more space for the + * authentication token than the security provider fills in SHOULD fill in the rest of + * the allocated space with zero octets. These zero octets are still considered to belong + * to the authentication token part of the PDU. + * + */ + +BOOL rpc_get_stub_data_info(rdpRpc* rpc, const rpcconn_hdr_t* header, size_t* poffset, + size_t* length) +{ + size_t used = 0; + size_t offset = 0; + BOOL rc = FALSE; + UINT32 frag_length = 0; + UINT32 auth_length = 0; + UINT32 auth_pad_length = 0; + UINT32 sec_trailer_offset = 0; + const rpc_sec_trailer* sec_trailer = NULL; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(header); + WINPR_ASSERT(poffset); + WINPR_ASSERT(length); + + offset = RPC_COMMON_FIELDS_LENGTH; + + switch (header->common.ptype) + { + case PTYPE_RESPONSE: + offset += 8; + rpc_offset_align(&offset, 8); + sec_trailer = &header->response.auth_verifier; + break; + + case PTYPE_REQUEST: + offset += 4; + rpc_offset_align(&offset, 8); + sec_trailer = &header->request.auth_verifier; + break; + + case PTYPE_RTS: + offset += 4; + break; + + default: + WLog_Print(rpc->log, WLOG_ERROR, "Unknown PTYPE: 0x%02" PRIX8 "", header->common.ptype); + goto fail; + } + + frag_length = header->common.frag_length; + auth_length = header->common.auth_length; + + if (poffset) + *poffset = offset; + + /* The fragment must be larger than the authentication trailer */ + used = offset + auth_length + 8ull; + if (sec_trailer) + { + auth_pad_length = sec_trailer->auth_pad_length; + used += sec_trailer->auth_pad_length; + } + + if (frag_length < used) + goto fail; + + if (!length) + return TRUE; + + sec_trailer_offset = frag_length - auth_length - 8; + + /* + * According to [MS-RPCE], auth_pad_length is the number of padding + * octets used to 4-byte align the security trailer, but in practice + * we get values up to 15, which indicates 16-byte alignment. + */ + + if ((frag_length - (sec_trailer_offset + 8)) != auth_length) + { + WLog_Print(rpc->log, WLOG_ERROR, + "invalid auth_length: actual: %" PRIu32 ", expected: %" PRIu32 "", auth_length, + (frag_length - (sec_trailer_offset + 8))); + } + + *length = sec_trailer_offset - auth_pad_length - offset; + + rc = TRUE; +fail: + return rc; +} + +SSIZE_T rpc_channel_read(RpcChannel* channel, wStream* s, size_t length) +{ + int status = 0; + + if (!channel || (length > INT32_MAX)) + return -1; + + ERR_clear_error(); + status = BIO_read(channel->tls->bio, Stream_Pointer(s), (INT32)length); + + if (status > 0) + { + Stream_Seek(s, (size_t)status); + return status; + } + + if (BIO_should_retry(channel->tls->bio)) + return 0; + + WLog_Print(channel->rpc->log, WLOG_ERROR, "rpc_channel_read: Out of retries"); + return -1; +} + +SSIZE_T rpc_channel_write(RpcChannel* channel, const BYTE* data, size_t length) +{ + if (!channel) + return -1; + + return freerdp_tls_write_all(channel->tls, data, length); +} + +BOOL rpc_in_channel_transition_to_state(RpcInChannel* inChannel, CLIENT_IN_CHANNEL_STATE state) +{ + if (!inChannel) + return FALSE; + + inChannel->State = state; + WLog_Print(inChannel->common.rpc->log, WLOG_DEBUG, "%s", client_in_state_str(state)); + return TRUE; +} + +static int rpc_channel_rpch_init(RpcClient* client, RpcChannel* channel, const char* inout, + const GUID* guid) +{ + HttpContext* http = NULL; + rdpSettings* settings = NULL; + UINT32 timeout = 0; + + if (!client || !channel || !inout || !client->context || !client->context->settings) + return -1; + + settings = client->context->settings; + channel->auth = credssp_auth_new(client->context); + rts_generate_cookie((BYTE*)&channel->Cookie); + channel->client = client; + + if (!channel->auth) + return -1; + + channel->http = http_context_new(); + + if (!channel->http) + return -1; + + http = channel->http; + + { + if (!http_context_set_pragma(http, "ResourceTypeUuid=44e265dd-7daf-42cd-8560-3cdb6e7a2729")) + return -1; + + if (guid) + { + char* strguid = NULL; + RPC_STATUS rpcStatus = UuidToStringA(guid, &strguid); + + if (rpcStatus != RPC_S_OK) + return -1; + + const BOOL rc = http_context_append_pragma(http, "SessionId=%s", strguid); + RpcStringFreeA(&strguid); + if (!rc) + return -1; + } + if (timeout) + { + if (!http_context_append_pragma(http, "MinConnTimeout=%" PRIu32, timeout)) + return -1; + } + + if (!http_context_set_rdg_correlation_id(http, guid) || + !http_context_set_rdg_connection_id(http, guid)) + return -1; + } + + /* TODO: "/rpcwithcert/rpcproxy.dll". */ + if (!http_context_set_method(http, inout) || + !http_context_set_uri(http, "/rpc/rpcproxy.dll?localhost:3388") || + !http_context_set_accept(http, "application/rpc") || + !http_context_set_cache_control(http, "no-cache") || + !http_context_set_connection(http, "Keep-Alive") || + !http_context_set_user_agent(http, "MSRPC") || + !http_context_set_host(http, settings->GatewayHostname)) + return -1; + + return 1; +} + +static int rpc_in_channel_init(rdpRpc* rpc, RpcInChannel* inChannel, const GUID* guid) +{ + WINPR_ASSERT(rpc); + WINPR_ASSERT(inChannel); + + inChannel->common.rpc = rpc; + inChannel->State = CLIENT_IN_CHANNEL_STATE_INITIAL; + inChannel->BytesSent = 0; + inChannel->SenderAvailableWindow = rpc->ReceiveWindow; + inChannel->PingOriginator.ConnectionTimeout = 30; + inChannel->PingOriginator.KeepAliveInterval = 0; + + if (rpc_channel_rpch_init(rpc->client, &inChannel->common, "RPC_IN_DATA", guid) < 0) + return -1; + + return 1; +} + +static RpcInChannel* rpc_in_channel_new(rdpRpc* rpc, const GUID* guid) +{ + RpcInChannel* inChannel = (RpcInChannel*)calloc(1, sizeof(RpcInChannel)); + + if (inChannel) + { + rpc_in_channel_init(rpc, inChannel, guid); + } + + return inChannel; +} + +void rpc_channel_free(RpcChannel* channel) +{ + if (!channel) + return; + + credssp_auth_free(channel->auth); + http_context_free(channel->http); + freerdp_tls_free(channel->tls); + free(channel); +} + +BOOL rpc_out_channel_transition_to_state(RpcOutChannel* outChannel, CLIENT_OUT_CHANNEL_STATE state) +{ + if (!outChannel) + return FALSE; + + outChannel->State = state; + WLog_Print(outChannel->common.rpc->log, WLOG_DEBUG, "%s", client_out_state_str(state)); + return TRUE; +} + +static int rpc_out_channel_init(rdpRpc* rpc, RpcOutChannel* outChannel, const GUID* guid) +{ + WINPR_ASSERT(rpc); + WINPR_ASSERT(outChannel); + + outChannel->common.rpc = rpc; + outChannel->State = CLIENT_OUT_CHANNEL_STATE_INITIAL; + outChannel->BytesReceived = 0; + outChannel->ReceiverAvailableWindow = rpc->ReceiveWindow; + outChannel->ReceiveWindow = rpc->ReceiveWindow; + outChannel->ReceiveWindowSize = rpc->ReceiveWindow; + outChannel->AvailableWindowAdvertised = rpc->ReceiveWindow; + + if (rpc_channel_rpch_init(rpc->client, &outChannel->common, "RPC_OUT_DATA", guid) < 0) + return -1; + + return 1; +} + +RpcOutChannel* rpc_out_channel_new(rdpRpc* rpc, const GUID* guid) +{ + RpcOutChannel* outChannel = (RpcOutChannel*)calloc(1, sizeof(RpcOutChannel)); + + if (outChannel) + { + rpc_out_channel_init(rpc, outChannel, guid); + } + + return outChannel; +} + +BOOL rpc_virtual_connection_transition_to_state(rdpRpc* rpc, RpcVirtualConnection* connection, + VIRTUAL_CONNECTION_STATE state) +{ + if (!connection) + return FALSE; + + WINPR_ASSERT(rpc); + connection->State = state; + WLog_Print(rpc->log, WLOG_DEBUG, "%s", rpc_vc_state_str(state)); + return TRUE; +} + +static void rpc_virtual_connection_free(RpcVirtualConnection* connection) +{ + if (!connection) + return; + + if (connection->DefaultInChannel) + rpc_channel_free(&connection->DefaultInChannel->common); + if (connection->NonDefaultInChannel) + rpc_channel_free(&connection->NonDefaultInChannel->common); + if (connection->DefaultOutChannel) + rpc_channel_free(&connection->DefaultOutChannel->common); + if (connection->NonDefaultOutChannel) + rpc_channel_free(&connection->NonDefaultOutChannel->common); + free(connection); +} + +static RpcVirtualConnection* rpc_virtual_connection_new(rdpRpc* rpc) +{ + WINPR_ASSERT(rpc); + + RpcVirtualConnection* connection = + (RpcVirtualConnection*)calloc(1, sizeof(RpcVirtualConnection)); + + if (!connection) + return NULL; + + rts_generate_cookie((BYTE*)&(connection->Cookie)); + rts_generate_cookie((BYTE*)&(connection->AssociationGroupId)); + connection->State = VIRTUAL_CONNECTION_STATE_INITIAL; + + connection->DefaultInChannel = rpc_in_channel_new(rpc, &connection->Cookie); + + if (!connection->DefaultInChannel) + goto fail; + + connection->DefaultOutChannel = rpc_out_channel_new(rpc, &connection->Cookie); + + if (!connection->DefaultOutChannel) + goto fail; + + return connection; +fail: + rpc_virtual_connection_free(connection); + return NULL; +} + +static BOOL rpc_channel_tls_connect(RpcChannel* channel, UINT32 timeout) +{ + if (!channel || !channel->client || !channel->client->context || + !channel->client->context->settings) + return FALSE; + + rdpContext* context = channel->client->context; + WINPR_ASSERT(context); + + rdpSettings* settings = context->settings; + WINPR_ASSERT(settings); + + const char* proxyUsername = freerdp_settings_get_string(settings, FreeRDP_ProxyUsername); + const char* proxyPassword = freerdp_settings_get_string(settings, FreeRDP_ProxyPassword); + + rdpTransport* transport = freerdp_get_transport(context); + rdpTransportLayer* layer = + transport_connect_layer(transport, channel->client->host, channel->client->port, timeout); + + if (!layer) + return FALSE; + + BIO* layerBio = BIO_new(BIO_s_transport_layer()); + if (!layerBio) + { + transport_layer_free(layer); + return FALSE; + } + BIO_set_data(layerBio, layer); + + BIO* bufferedBio = BIO_new(BIO_s_buffered_socket()); + if (!bufferedBio) + { + BIO_free_all(layerBio); + return FALSE; + } + + bufferedBio = BIO_push(bufferedBio, layerBio); + + if (!BIO_set_nonblock(bufferedBio, TRUE)) + { + BIO_free_all(bufferedBio); + return FALSE; + } + + if (channel->client->isProxy) + { + WINPR_ASSERT(settings->GatewayPort <= UINT16_MAX); + if (!proxy_connect(context, bufferedBio, proxyUsername, proxyPassword, + settings->GatewayHostname, (UINT16)settings->GatewayPort)) + { + BIO_free_all(bufferedBio); + return FALSE; + } + } + + channel->bio = bufferedBio; + rdpTls* tls = channel->tls = freerdp_tls_new(context); + + if (!tls) + return FALSE; + + tls->hostname = settings->GatewayHostname; + tls->port = WINPR_ASSERTING_INT_CAST(int32_t, MIN(UINT16_MAX, settings->GatewayPort)); + tls->isGatewayTransport = TRUE; + int tlsStatus = freerdp_tls_connect(tls, bufferedBio); + + if (tlsStatus < 1) + { + if (tlsStatus < 0) + { + freerdp_set_last_error_if_not(context, FREERDP_ERROR_TLS_CONNECT_FAILED); + } + else + { + freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED); + } + + return FALSE; + } + + return TRUE; +} + +static int rpc_in_channel_connect(RpcInChannel* inChannel, UINT32 timeout) +{ + rdpContext* context = NULL; + + if (!inChannel || !inChannel->common.client || !inChannel->common.client->context) + return -1; + + context = inChannel->common.client->context; + + /* Connect IN Channel */ + + if (!rpc_channel_tls_connect(&inChannel->common, timeout)) + return -1; + + rpc_in_channel_transition_to_state(inChannel, CLIENT_IN_CHANNEL_STATE_CONNECTED); + + if (!rpc_ncacn_http_auth_init(context, &inChannel->common)) + return -1; + + /* Send IN Channel Request */ + + if (!rpc_ncacn_http_send_in_channel_request(&inChannel->common)) + { + WLog_Print(inChannel->common.rpc->log, WLOG_ERROR, + "rpc_ncacn_http_send_in_channel_request failure"); + return -1; + } + + if (!rpc_in_channel_transition_to_state(inChannel, CLIENT_IN_CHANNEL_STATE_SECURITY)) + return -1; + + return 1; +} + +static int rpc_out_channel_connect(RpcOutChannel* outChannel, UINT32 timeout) +{ + rdpContext* context = NULL; + + if (!outChannel || !outChannel->common.client || !outChannel->common.client->context) + return -1; + + context = outChannel->common.client->context; + + /* Connect OUT Channel */ + + if (!rpc_channel_tls_connect(&outChannel->common, timeout)) + return -1; + + rpc_out_channel_transition_to_state(outChannel, CLIENT_OUT_CHANNEL_STATE_CONNECTED); + + if (!rpc_ncacn_http_auth_init(context, &outChannel->common)) + return FALSE; + + /* Send OUT Channel Request */ + + if (!rpc_ncacn_http_send_out_channel_request(&outChannel->common, FALSE)) + { + WLog_Print(outChannel->common.rpc->log, WLOG_ERROR, + "rpc_ncacn_http_send_out_channel_request failure"); + return FALSE; + } + + rpc_out_channel_transition_to_state(outChannel, CLIENT_OUT_CHANNEL_STATE_SECURITY); + return 1; +} + +int rpc_out_channel_replacement_connect(RpcOutChannel* outChannel, uint32_t timeout) +{ + rdpContext* context = NULL; + + if (!outChannel || !outChannel->common.client || !outChannel->common.client->context) + return -1; + + context = outChannel->common.client->context; + + /* Connect OUT Channel */ + + if (!rpc_channel_tls_connect(&outChannel->common, timeout)) + return -1; + + rpc_out_channel_transition_to_state(outChannel, CLIENT_OUT_CHANNEL_STATE_CONNECTED); + + if (!rpc_ncacn_http_auth_init(context, (RpcChannel*)outChannel)) + return FALSE; + + /* Send OUT Channel Request */ + + if (!rpc_ncacn_http_send_out_channel_request(&outChannel->common, TRUE)) + { + WLog_Print(outChannel->common.rpc->log, WLOG_ERROR, + "rpc_ncacn_http_send_out_channel_request failure"); + return FALSE; + } + + rpc_out_channel_transition_to_state(outChannel, CLIENT_OUT_CHANNEL_STATE_SECURITY); + return 1; +} + +BOOL rpc_connect(rdpRpc* rpc, UINT32 timeout) +{ + RpcInChannel* inChannel = NULL; + RpcOutChannel* outChannel = NULL; + RpcVirtualConnection* connection = NULL; + rpc->VirtualConnection = rpc_virtual_connection_new(rpc); + + if (!rpc->VirtualConnection) + return FALSE; + + connection = rpc->VirtualConnection; + inChannel = connection->DefaultInChannel; + outChannel = connection->DefaultOutChannel; + rpc_virtual_connection_transition_to_state(rpc, connection, VIRTUAL_CONNECTION_STATE_INITIAL); + + if (rpc_in_channel_connect(inChannel, timeout) < 0) + return FALSE; + + if (rpc_out_channel_connect(outChannel, timeout) < 0) + return FALSE; + + return TRUE; +} + +rdpRpc* rpc_new(rdpTransport* transport) +{ + rdpContext* context = transport_get_context(transport); + rdpRpc* rpc = NULL; + + WINPR_ASSERT(context); + + rpc = (rdpRpc*)calloc(1, sizeof(rdpRpc)); + + if (!rpc) + return NULL; + + rpc->log = WLog_Get(TAG); + rpc->State = RPC_CLIENT_STATE_INITIAL; + rpc->transport = transport; + rpc->SendSeqNum = 0; + rpc->auth = credssp_auth_new(context); + + if (!rpc->auth) + goto out_free; + + rpc->PipeCallId = 0; + rpc->StubCallId = 0; + rpc->StubFragCount = 0; + rpc->rpc_vers = 5; + rpc->rpc_vers_minor = 0; + /* little-endian data representation */ + rpc->packed_drep[0] = 0x10; + rpc->packed_drep[1] = 0x00; + rpc->packed_drep[2] = 0x00; + rpc->packed_drep[3] = 0x00; + rpc->max_xmit_frag = 0x0FF8; + rpc->max_recv_frag = 0x0FF8; + rpc->ReceiveWindow = 0x00010000; + rpc->ChannelLifetime = 0x40000000; + rpc->KeepAliveInterval = 300000; + rpc->CurrentKeepAliveInterval = rpc->KeepAliveInterval; + rpc->CurrentKeepAliveTime = 0; + rpc->CallId = 2; + rpc->client = rpc_client_new(context, rpc->max_recv_frag); + + if (!rpc->client) + goto out_free; + + return rpc; +out_free: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + rpc_free(rpc); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void rpc_free(rdpRpc* rpc) +{ + if (rpc) + { + rpc_client_free(rpc->client); + credssp_auth_free(rpc->auth); + rpc_virtual_connection_free(rpc->VirtualConnection); + free(rpc); + } +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc.h new file mode 100644 index 0000000000000000000000000000000000000000..2366886179b44114c928de38e1e3d96dd1af2a6c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc.h @@ -0,0 +1,796 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC over HTTP + * + * Copyright 2012 Fujitsu Technology Solutions GmbH + * Copyright 2012 Dmitrij Jasnov + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_RPC_H +#define FREERDP_LIB_CORE_GATEWAY_RPC_H + +#include +#include +#include +#include + +#include +#include + +#include "../../crypto/tls.h" + +typedef struct rdp_rpc rdpRpc; + +#pragma pack(push, 1) + +typedef struct +{ + BYTE rpc_vers; + BYTE rpc_vers_minor; + BYTE ptype; + BYTE pfc_flags; + BYTE packed_drep[4]; + UINT16 frag_length; + UINT16 auth_length; + UINT32 call_id; +} rpcconn_common_hdr_t; + +#define RPC_COMMON_FIELDS_LENGTH sizeof(rpcconn_common_hdr_t) + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT16 Flags; + UINT16 NumberOfCommands; +} rpcconn_rts_hdr_t; + +#define RTS_PDU_HEADER_LENGTH 20 + +#define RPC_PDU_FLAG_STUB 0x00000001 + +typedef struct +{ + wStream* s; + UINT32 Type; + UINT32 Flags; + UINT32 CallId; +} RPC_PDU, *PRPC_PDU; + +#pragma pack(pop) + +#include "../tcp.h" +#include "../transport.h" + +#include "http.h" +#include "../credssp_auth.h" + +#include + +#include +#include + +#include +#include +#include +#include + +#include + +/** + * CAE Specification + * DCE 1.1: Remote Procedure Call + * Document Number: C706 + * http://pubs.opengroup.org/onlinepubs/9629399/ + */ + +#define PTYPE_REQUEST 0x00 +#define PTYPE_PING 0x01 +#define PTYPE_RESPONSE 0x02 +#define PTYPE_FAULT 0x03 +#define PTYPE_WORKING 0x04 +#define PTYPE_NOCALL 0x05 +#define PTYPE_REJECT 0x06 +#define PTYPE_ACK 0x07 +#define PTYPE_CL_CANCEL 0x08 +#define PTYPE_FACK 0x09 +#define PTYPE_CANCEL_ACK 0x0A +#define PTYPE_BIND 0x0B +#define PTYPE_BIND_ACK 0x0C +#define PTYPE_BIND_NAK 0x0D +#define PTYPE_ALTER_CONTEXT 0x0E +#define PTYPE_ALTER_CONTEXT_RESP 0x0F +#define PTYPE_RPC_AUTH_3 0x10 +#define PTYPE_SHUTDOWN 0x11 +#define PTYPE_CO_CANCEL 0x12 +#define PTYPE_ORPHANED 0x13 +#define PTYPE_RTS 0x14 + +#define PFC_FIRST_FRAG 0x01 +#define PFC_LAST_FRAG 0x02 +#define PFC_PENDING_CANCEL 0x04 +#define PFC_SUPPORT_HEADER_SIGN 0x04 +#define PFC_RESERVED_1 0x08 +#define PFC_CONC_MPX 0x10 +#define PFC_DID_NOT_EXECUTE 0x20 +#define PFC_MAYBE 0x40 +#define PFC_OBJECT_UUID 0x80 + +/* Minimum fragment sizes */ +#define RPC_CO_MUST_RECV_FRAG_SIZE 1432 +#define RPC_CL_MUST_RECV_FRAG_SIZE 1464 + +/** + * The PDU maximum header length is enough + * to contain either the RPC common fields + * or all fields up to the stub data in PDUs + * that use it (request, response, fault) + */ +#define RPC_PDU_HEADER_MAX_LENGTH 32 + +#pragma pack(push, 1) + +typedef UINT16 p_context_id_t; +typedef UINT16 p_reject_reason_t; + +typedef struct +{ + UINT32 time_low; + UINT16 time_mid; + UINT16 time_hi_and_version; + BYTE clock_seq_hi_and_reserved; + BYTE clock_seq_low; + BYTE node[6]; +} p_uuid_t; + +#define ndr_c_int_big_endian 0 +#define ndr_c_int_little_endian 1 +#define ndr_c_float_ieee 0 +#define ndr_c_float_vax 1 +#define ndr_c_float_cray 2 +#define ndr_c_float_ibm 3 +#define ndr_c_char_ascii 0 +#define ndr_c_char_ebcdic 1 + +typedef struct +{ + BYTE int_rep; + BYTE char_rep; + BYTE float_rep; + BYTE reserved; +} ndr_format_t, *ndr_format_p_t; + +typedef struct ndr_context_handle +{ + UINT32 context_handle_attributes; + p_uuid_t context_handle_uuid; +} ndr_context_handle; + +typedef struct +{ + p_uuid_t if_uuid; + UINT32 if_version; +} p_syntax_id_t; + +typedef struct +{ + p_context_id_t p_cont_id; + BYTE n_transfer_syn; /* number of items */ + BYTE reserved; /* alignment pad, m.b.z. */ + p_syntax_id_t abstract_syntax; /* transfer syntax list */ + p_syntax_id_t* transfer_syntaxes; /* size_is(n_transfer_syn) */ +} p_cont_elem_t; + +typedef struct +{ + BYTE n_context_elem; /* number of items */ + BYTE reserved; /* alignment pad, m.b.z. */ + UINT16 reserved2; /* alignment pad, m.b.z. */ + p_cont_elem_t* p_cont_elem; /* size_is(n_cont_elem) */ +} p_cont_list_t; + +typedef enum +{ + acceptance, + user_rejection, + provider_rejection +} p_cont_def_result_t; + +typedef enum +{ + reason_not_specified, + abstract_syntax_not_supported, + proposed_transfer_syntaxes_not_supported, + local_limit_exceeded +} p_provider_reason_t; + +typedef struct +{ + p_cont_def_result_t result; + p_provider_reason_t reason; + p_syntax_id_t transfer_syntax; +} p_result_t; + +/* Same order and number of elements as in bind request */ + +typedef struct +{ + BYTE n_results; /* count */ + BYTE reserved; /* alignment pad, m.b.z. */ + UINT16 reserved2; /* alignment pad, m.b.z. */ + p_result_t* p_results; /* size_is(n_results) */ +} p_result_list_t; + +typedef struct +{ + BYTE major; + BYTE minor; +} version_t; +typedef version_t p_rt_version_t; + +typedef struct +{ + BYTE n_protocols; /* count */ + p_rt_version_t* p_protocols; /* size_is(n_protocols) */ +} p_rt_versions_supported_t; + +typedef struct +{ + UINT16 length; + char* port_spec; /* port string spec; size_is(length) */ +} port_any_t; + +#define REASON_NOT_SPECIFIED 0 +#define TEMPORARY_CONGESTION 1 +#define LOCAL_LIMIT_EXCEEDED 2 +#define CALLED_PADDR_UNKNOWN 3 +#define PROTOCOL_VERSION_NOT_SUPPORTED 4 +#define DEFAULT_CONTEXT_NOT_SUPPORTED 5 +#define USER_DATA_NOT_READABLE 6 +#define NO_PSAP_AVAILABLE 7 + +typedef UINT16 rpcrt_reason_code_t; + +typedef struct +{ + BYTE rpc_vers; + BYTE rpc_vers_minor; + BYTE reserved[2]; + BYTE packed_drep[4]; + UINT32 reject_status; + BYTE reserved2[4]; +} rpcrt_optional_data_t; + +typedef struct +{ + rpcrt_reason_code_t reason_code; + rpcrt_optional_data_t rpc_info; +} rpcconn_reject_optional_data_t; + +typedef struct +{ + rpcrt_reason_code_t reason_code; + rpcrt_optional_data_t rpc_info; +} rpcconn_disc_optional_data_t; + +typedef struct +{ + BYTE signature[8]; +} rpc_sec_verification_trailer; + +struct auth_verifier_co_s +{ + /* restore 4-byte alignment */ + + BYTE auth_type; + BYTE auth_level; + BYTE auth_pad_length; + BYTE auth_reserved; + UINT32 auth_context_id; + + BYTE* auth_value; +}; + +typedef struct auth_verifier_co_s rpc_sec_trailer; +typedef struct auth_verifier_co_s auth_verifier_co_t; + +/* Connection-oriented PDU Definitions */ + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT16 max_xmit_frag; + UINT16 max_recv_frag; + UINT32 assoc_group_id; + + p_cont_list_t p_context_elem; + + auth_verifier_co_t auth_verifier; + +} rpcconn_alter_context_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT16 max_xmit_frag; + UINT16 max_recv_frag; + UINT32 assoc_group_id; + port_any_t sec_addr; + + /* restore 4-octet alignment */ + + p_result_list_t p_result_list; + + auth_verifier_co_t auth_verifier; +} rpcconn_alter_context_response_hdr_t; + +/* bind header */ +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT16 max_xmit_frag; + UINT16 max_recv_frag; + UINT32 assoc_group_id; + + p_cont_list_t p_context_elem; + + auth_verifier_co_t auth_verifier; +} rpcconn_bind_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT16 max_xmit_frag; + UINT16 max_recv_frag; + UINT32 assoc_group_id; + + port_any_t sec_addr; + + /* restore 4-octet alignment */ + + p_result_list_t p_result_list; + + auth_verifier_co_t auth_verifier; +} rpcconn_bind_ack_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT16 max_xmit_frag; + UINT16 max_recv_frag; + + auth_verifier_co_t auth_verifier; +} rpcconn_rpc_auth_3_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + p_reject_reason_t provider_reject_reason; + + p_rt_versions_supported_t versions; +} rpcconn_bind_nak_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + auth_verifier_co_t auth_verifier; + +} rpcconn_cancel_hdr_t; + +#pragma pack(pop) + +/* fault codes */ + +typedef struct +{ + UINT32 code; + const char* name; + const char* category; +} RPC_FAULT_CODE; + +#define DEFINE_RPC_FAULT_CODE(_code, cat) \ + { \ + _code, #_code, cat \ + } + +#define nca_s_comm_failure 0x1C010001 +#define nca_s_op_rng_error 0x1C010002 +#define nca_s_unk_if 0x1C010003 +#define nca_s_wrong_boot_time 0x1C010006 +#define nca_s_you_crashed 0x1C010009 +#define nca_s_proto_error 0x1C01000B +#define nca_s_out_args_too_big 0x1C010013 +#define nca_s_server_too_busy 0x1C010014 +#define nca_s_fault_string_too_long 0x1C010015 +#define nca_s_unsupported_type 0x1C010017 +#define nca_s_fault_int_div_by_zero 0x1C000001 +#define nca_s_fault_addr_error 0x1C000002 +#define nca_s_fault_fp_div_zero 0x1C000003 +#define nca_s_fault_fp_underflow 0x1C000004 +#define nca_s_fault_fp_overflow 0x1C000005 +#define nca_s_fault_invalid_tag 0x1C000006 +#define nca_s_fault_invalid_bound 0x1C000007 +#define nca_s_rpc_version_mismatch 0x1C000008 +#define nca_s_unspec_reject 0x1C000009 +#define nca_s_bad_actid 0x1C00000A +#define nca_s_who_are_you_failed 0x1C00000B +#define nca_s_manager_not_entered 0x1C00000C +#define nca_s_fault_cancel 0x1C00000D +#define nca_s_fault_ill_inst 0x1C00000E +#define nca_s_fault_fp_error 0x1C00000F +#define nca_s_fault_int_overflow 0x1C000010 +#define nca_s_fault_unspec 0x1C000012 +#define nca_s_fault_remote_comm_failure 0x1C000013 +#define nca_s_fault_pipe_empty 0x1C000014 +#define nca_s_fault_pipe_closed 0x1C000015 +#define nca_s_fault_pipe_order 0x1C000016 +#define nca_s_fault_pipe_discipline 0x1C000017 +#define nca_s_fault_pipe_comm_error 0x1C000018 +#define nca_s_fault_pipe_memory 0x1C000019 +#define nca_s_fault_context_mismatch 0x1C00001A +#define nca_s_fault_remote_no_memory 0x1C00001B +#define nca_s_invalid_pres_context_id 0x1C00001C +#define nca_s_unsupported_authn_level 0x1C00001D +#define nca_s_invalid_checksum 0x1C00001F +#define nca_s_invalid_crc 0x1C000020 +#define nca_s_fault_user_defined 0x1C000021 +#define nca_s_fault_tx_open_failed 0x1C000022 +#define nca_s_fault_codeset_conv_error 0x1C000023 +#define nca_s_fault_object_not_found 0x1C000024 +#define nca_s_fault_no_client_stub 0x1C000025 + +#pragma pack(push, 1) + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT32 alloc_hint; + p_context_id_t p_cont_id; + + BYTE cancel_count; + BYTE reserved; + + UINT32 status; + + /* align(8) */ + + BYTE* stub_data; + + auth_verifier_co_t auth_verifier; +} rpcconn_fault_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + auth_verifier_co_t auth_verifier; +} rpcconn_orphaned_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT32 alloc_hint; + + p_context_id_t p_cont_id; + UINT16 opnum; + + /* optional field for request, only present if the PFC_OBJECT_UUID field is non-zero */ + p_uuid_t object; + + /* align(8) */ + + BYTE* stub_data; + + auth_verifier_co_t auth_verifier; +} rpcconn_request_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; + + UINT32 alloc_hint; + p_context_id_t p_cont_id; + + BYTE cancel_count; + BYTE reserved; + + /* align(8) */ + + BYTE* stub_data; + + auth_verifier_co_t auth_verifier; +} rpcconn_response_hdr_t; + +typedef struct +{ + rpcconn_common_hdr_t header; +} rpcconn_shutdown_hdr_t; + +typedef union +{ + rpcconn_common_hdr_t common; + rpcconn_alter_context_hdr_t alter_context; + rpcconn_alter_context_response_hdr_t alter_context_response; + rpcconn_bind_hdr_t bind; + rpcconn_bind_ack_hdr_t bind_ack; + rpcconn_rpc_auth_3_hdr_t rpc_auth_3; + rpcconn_bind_nak_hdr_t bind_nak; + rpcconn_cancel_hdr_t cancel; + rpcconn_fault_hdr_t fault; + rpcconn_orphaned_hdr_t orphaned; + rpcconn_request_hdr_t request; + rpcconn_response_hdr_t response; + rpcconn_shutdown_hdr_t shutdown; + rpcconn_rts_hdr_t rts; +} rpcconn_hdr_t; + +#pragma pack(pop) + +typedef struct +{ + UINT32 Id; + LONG EvenLegs; + LONG NumLegs; +} RPC_SECURITY_PROVIDER_INFO; + +typedef enum +{ + RPC_CLIENT_STATE_INITIAL, + RPC_CLIENT_STATE_ESTABLISHED, + RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK, + RPC_CLIENT_STATE_WAIT_UNSECURE_BIND_ACK, + RPC_CLIENT_STATE_WAIT_SECURE_ALTER_CONTEXT_RESPONSE, + RPC_CLIENT_STATE_CONTEXT_NEGOTIATED, + RPC_CLIENT_STATE_WAIT_RESPONSE, + RPC_CLIENT_STATE_FINAL +} RPC_CLIENT_STATE; + +typedef enum +{ + RPC_CLIENT_CALL_STATE_INITIAL, + RPC_CLIENT_CALL_STATE_SEND_PDUS, + RPC_CLIENT_CALL_STATE_DISPATCHED, + RPC_CLIENT_CALL_STATE_RECEIVE_PDU, + RPC_CLIENT_CALL_STATE_COMPLETE, + RPC_CLIENT_CALL_STATE_FAULT, + RPC_CLIENT_CALL_STATE_FINAL +} RPC_CLIENT_CALL_STATE; + +typedef struct +{ + UINT32 CallId; + UINT32 OpNum; + RPC_CLIENT_CALL_STATE State; +} RpcClientCall; + +typedef struct +{ + rdpContext* context; + RPC_PDU* pdu; + HANDLE PipeEvent; + RingBuffer ReceivePipe; + wStream* ReceiveFragment; + CRITICAL_SECTION PipeLock; + wArrayList* ClientCallList; + char* host; + UINT16 port; + BOOL isProxy; +} RpcClient; + +typedef struct +{ + RpcClient* client; + BIO* bio; + rdpTls* tls; + rdpCredsspAuth* auth; + HttpContext* http; + GUID Cookie; + rdpRpc* rpc; +} RpcChannel; + +/* Ping Originator */ + +typedef struct +{ + UINT32 ConnectionTimeout; + UINT32 LastPacketSentTimestamp; + UINT32 KeepAliveInterval; +} RpcPingOriginator; + +/* Client In Channel */ + +typedef enum +{ + CLIENT_IN_CHANNEL_STATE_INITIAL, + CLIENT_IN_CHANNEL_STATE_CONNECTED, + CLIENT_IN_CHANNEL_STATE_SECURITY, + CLIENT_IN_CHANNEL_STATE_NEGOTIATED, + CLIENT_IN_CHANNEL_STATE_OPENED, + CLIENT_IN_CHANNEL_STATE_OPENED_A4W, + CLIENT_IN_CHANNEL_STATE_FINAL +} CLIENT_IN_CHANNEL_STATE; + +typedef struct +{ + /* Sending Channel */ + + RpcChannel common; + + CLIENT_IN_CHANNEL_STATE State; + + UINT32 PlugState; + void* SendQueue; + UINT32 BytesSent; + UINT32 SenderAvailableWindow; + UINT32 PeerReceiveWindow; + + /* Ping Originator */ + + RpcPingOriginator PingOriginator; +} RpcInChannel; + +/* Client Out Channel */ + +typedef enum +{ + CLIENT_OUT_CHANNEL_STATE_INITIAL, + CLIENT_OUT_CHANNEL_STATE_CONNECTED, + CLIENT_OUT_CHANNEL_STATE_SECURITY, + CLIENT_OUT_CHANNEL_STATE_NEGOTIATED, + CLIENT_OUT_CHANNEL_STATE_OPENED, + CLIENT_OUT_CHANNEL_STATE_OPENED_A6W, + CLIENT_OUT_CHANNEL_STATE_OPENED_A10W, + CLIENT_OUT_CHANNEL_STATE_OPENED_B3W, + CLIENT_OUT_CHANNEL_STATE_RECYCLED, + CLIENT_OUT_CHANNEL_STATE_FINAL +} CLIENT_OUT_CHANNEL_STATE; + +typedef struct +{ + /* Receiving Channel */ + + RpcChannel common; + + CLIENT_OUT_CHANNEL_STATE State; + + UINT32 ReceiveWindow; + UINT32 ReceiveWindowSize; + UINT32 ReceiverAvailableWindow; + UINT32 BytesReceived; + UINT32 AvailableWindowAdvertised; +} RpcOutChannel; + +/* Client Virtual Connection */ + +typedef enum +{ + VIRTUAL_CONNECTION_STATE_INITIAL, + VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT, + VIRTUAL_CONNECTION_STATE_WAIT_A3W, + VIRTUAL_CONNECTION_STATE_WAIT_C2, + VIRTUAL_CONNECTION_STATE_OPENED, + VIRTUAL_CONNECTION_STATE_FINAL +} VIRTUAL_CONNECTION_STATE; + +typedef struct +{ + GUID Cookie; + GUID AssociationGroupId; + VIRTUAL_CONNECTION_STATE State; + RpcInChannel* DefaultInChannel; + RpcInChannel* NonDefaultInChannel; + RpcOutChannel* DefaultOutChannel; + RpcOutChannel* NonDefaultOutChannel; +} RpcVirtualConnection; + +/* Virtual Connection Cookie Table */ + +#define RPC_UUID_FORMAT_STRING \ + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define RPC_UUID_FORMAT_ARGUMENTS(_rpc_uuid) \ + _rpc_uuid[0], _rpc_uuid[1], _rpc_uuid[2], _rpc_uuid[3], _rpc_uuid[4], _rpc_uuid[5], \ + _rpc_uuid[6], _rpc_uuid[7], _rpc_uuid[8], _rpc_uuid[9], _rpc_uuid[10], _rpc_uuid[11], \ + _rpc_uuid[12], _rpc_uuid[13], _rpc_uuid[14], _rpc_uuid[15] + +typedef struct +{ + GUID Cookie; + UINT32 ReferenceCount; + RpcVirtualConnection* Reference; +} RpcVirtualConnectionCookieEntry; + +struct rdp_rpc +{ + RPC_CLIENT_STATE State; + + UINT32 result; + + rdpCredsspAuth* auth; + UINT32 SendSeqNum; + + RpcClient* client; + + rdpTransport* transport; + + UINT32 CallId; + UINT32 PipeCallId; + + UINT32 StubCallId; + UINT32 StubFragCount; + + BYTE rpc_vers; + BYTE rpc_vers_minor; + BYTE packed_drep[4]; + + UINT16 max_xmit_frag; + UINT16 max_recv_frag; + + UINT32 ReceiveWindow; + UINT32 ChannelLifetime; + UINT32 KeepAliveInterval; + UINT32 CurrentKeepAliveTime; + UINT32 CurrentKeepAliveInterval; + + RpcVirtualConnection* VirtualConnection; + wLog* log; +}; + +FREERDP_LOCAL const char* rpc_vc_state_str(VIRTUAL_CONNECTION_STATE state); +FREERDP_LOCAL void rpc_pdu_header_print(wLog* log, const rpcconn_hdr_t* header); +FREERDP_LOCAL rpcconn_common_hdr_t rpc_pdu_header_init(const rdpRpc* rpc); + +FREERDP_LOCAL size_t rpc_offset_align(size_t* offset, size_t alignment); +FREERDP_LOCAL size_t rpc_offset_pad(size_t* offset, size_t pad); + +FREERDP_LOCAL BOOL rpc_get_stub_data_info(rdpRpc* rpc, const rpcconn_hdr_t* header, size_t* offset, + size_t* length); + +FREERDP_LOCAL SSIZE_T rpc_channel_write(RpcChannel* channel, const BYTE* data, size_t length); + +FREERDP_LOCAL SSIZE_T rpc_channel_read(RpcChannel* channel, wStream* s, size_t length); + +FREERDP_LOCAL void rpc_channel_free(RpcChannel* channel); + +WINPR_ATTR_MALLOC(rpc_channel_free, 1) +FREERDP_LOCAL RpcOutChannel* rpc_out_channel_new(rdpRpc* rpc, const GUID* guid); +FREERDP_LOCAL int rpc_out_channel_replacement_connect(RpcOutChannel* outChannel, uint32_t timeout); + +FREERDP_LOCAL BOOL rpc_in_channel_transition_to_state(RpcInChannel* inChannel, + CLIENT_IN_CHANNEL_STATE state); +FREERDP_LOCAL BOOL rpc_out_channel_transition_to_state(RpcOutChannel* outChannel, + CLIENT_OUT_CHANNEL_STATE state); + +FREERDP_LOCAL BOOL rpc_virtual_connection_transition_to_state(rdpRpc* rpc, + RpcVirtualConnection* connection, + VIRTUAL_CONNECTION_STATE state); + +FREERDP_LOCAL BOOL rpc_connect(rdpRpc* rpc, UINT32 timeout); + +FREERDP_LOCAL void rpc_free(rdpRpc* rpc); + +WINPR_ATTR_MALLOC(rpc_free, 1) +FREERDP_LOCAL rdpRpc* rpc_new(rdpTransport* transport); + +#endif /* FREERDP_LIB_CORE_GATEWAY_RPC_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_bind.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_bind.c new file mode 100644 index 0000000000000000000000000000000000000000..ce53a4d2792dc0976b9b2d6cd5fd9ac09c088121 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_bind.c @@ -0,0 +1,470 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC Secure Context Binding + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../settings.h" + +#include +#include +#include + +#include + +#include "rpc_client.h" + +#include "rts.h" + +#include "rpc_bind.h" +#include "../utils.h" + +#define TAG FREERDP_TAG("core.gateway.rpc") + +#define AUTH_PKG NTLM_SSP_NAME + +/** + * Connection-Oriented RPC Protocol Client Details: + * http://msdn.microsoft.com/en-us/library/cc243724/ + */ + +/* Syntax UUIDs */ + +const p_uuid_t TSGU_UUID = { + 0x44E265DD, /* time_low */ + 0x7DAF, /* time_mid */ + 0x42CD, /* time_hi_and_version */ + 0x85, /* clock_seq_hi_and_reserved */ + 0x60, /* clock_seq_low */ + { 0x3C, 0xDB, 0x6E, 0x7A, 0x27, 0x29 } /* node[6] */ +}; + +const p_uuid_t NDR_UUID = { + 0x8A885D04, /* time_low */ + 0x1CEB, /* time_mid */ + 0x11C9, /* time_hi_and_version */ + 0x9F, /* clock_seq_hi_and_reserved */ + 0xE8, /* clock_seq_low */ + { 0x08, 0x00, 0x2B, 0x10, 0x48, 0x60 } /* node[6] */ +}; + +const p_uuid_t BTFN_UUID = { + 0x6CB71C2C, /* time_low */ + 0x9812, /* time_mid */ + 0x4540, /* time_hi_and_version */ + 0x03, /* clock_seq_hi_and_reserved */ + 0x00, /* clock_seq_low */ + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } /* node[6] */ +}; + +/** + * Secure Connection-Oriented RPC Packet Sequence + * + * Client Server + * | | + * |-------------------SECURE_BIND-------------------->| + * | | + * |<----------------SECURE_BIND_ACK-------------------| + * | | + * |--------------------RPC_AUTH_3-------------------->| + * | | + * | | + * |------------------REQUEST_PDU_#1------------------>| + * |------------------REQUEST_PDU_#2------------------>| + * | | + * | ... | + * | | + * |<-----------------RESPONSE_PDU_#1------------------| + * |<-----------------RESPONSE_PDU_#2------------------| + * | | + * | ... | + */ + +/** + * SECURE_BIND: RPC bind PDU with sec_trailer and auth_token. Auth_token is generated by calling + * the implementation equivalent of the abstract GSS_Init_sec_context call. Upon receiving that, the + * server calls the implementation equivalent of the abstract GSS_Accept_sec_context call, which + * returns an auth_token and continue status in this example. Assume the following: + * + * 1) The client chooses the auth_context_id field in the sec_trailer sent with this PDU to be 1. + * + * 2) The client uses the RPC_C_AUTHN_LEVEL_PKT_PRIVACY authentication level and the + * Authentication Service (AS) NTLM. + * + * 3) The client sets the PFC_SUPPORT_HEADER_SIGN flag in the PDU header. + */ + +static int rpc_bind_setup(rdpRpc* rpc) +{ + SEC_WINNT_AUTH_IDENTITY identity = { 0 }; + + WINPR_ASSERT(rpc); + + rdpContext* context = transport_get_context(rpc->transport); + WINPR_ASSERT(context); + + rdpSettings* settings = context->settings; + WINPR_ASSERT(settings); + + freerdp* instance = context->instance; + WINPR_ASSERT(instance); + + credssp_auth_free(rpc->auth); + rpc->auth = credssp_auth_new(context); + if (!rpc->auth) + return -1; + + auth_status rc = utils_authenticate_gateway(instance, GW_AUTH_RPC); + switch (rc) + { + case AUTH_SUCCESS: + case AUTH_SKIP: + break; + case AUTH_CANCELLED: + freerdp_set_last_error_log(instance->context, FREERDP_ERROR_CONNECT_CANCELLED); + return -1; + case AUTH_NO_CREDENTIALS: + WLog_INFO(TAG, "No credentials provided - using NULL identity"); + break; + case AUTH_FAILED: + default: + return -1; + } + + if (!credssp_auth_init(rpc->auth, AUTH_PKG, NULL)) + return -1; + + if (!identity_set_from_settings(&identity, settings, FreeRDP_GatewayUsername, + FreeRDP_GatewayDomain, FreeRDP_GatewayPassword)) + return -1; + + SEC_WINNT_AUTH_IDENTITY* identityArg = (settings->GatewayUsername ? &identity : NULL); + if (!credssp_auth_setup_client(rpc->auth, NULL, settings->GatewayHostname, identityArg, NULL)) + { + sspi_FreeAuthIdentity(&identity); + return -1; + } + sspi_FreeAuthIdentity(&identity); + + credssp_auth_set_flags(rpc->auth, ISC_REQ_USE_DCE_STYLE | ISC_REQ_DELEGATE | + ISC_REQ_REPLAY_DETECT | ISC_REQ_SEQUENCE_DETECT); + + if (credssp_auth_authenticate(rpc->auth) < 0) + return -1; + + return 1; +} + +int rpc_send_bind_pdu(rdpRpc* rpc, BOOL initial) +{ + int status = -1; + wStream* buffer = NULL; + UINT32 offset = 0; + RpcClientCall* clientCall = NULL; + p_cont_elem_t* p_cont_elem = NULL; + rpcconn_bind_hdr_t bind_pdu = { 0 }; + RpcVirtualConnection* connection = NULL; + RpcInChannel* inChannel = NULL; + const SecBuffer* sbuffer = NULL; + + WINPR_ASSERT(rpc); + + connection = rpc->VirtualConnection; + + WINPR_ASSERT(connection); + + inChannel = connection->DefaultInChannel; + + if (initial && rpc_bind_setup(rpc) < 0) + return -1; + + WLog_DBG(TAG, initial ? "Sending Bind PDU" : "Sending Alter Context PDU"); + + sbuffer = credssp_auth_get_output_buffer(rpc->auth); + + if (!sbuffer) + goto fail; + + bind_pdu.header = rpc_pdu_header_init(rpc); + bind_pdu.header.auth_length = (UINT16)sbuffer->cbBuffer; + bind_pdu.auth_verifier.auth_value = sbuffer->pvBuffer; + bind_pdu.header.ptype = initial ? PTYPE_BIND : PTYPE_ALTER_CONTEXT; + bind_pdu.header.pfc_flags = + PFC_FIRST_FRAG | PFC_LAST_FRAG | PFC_SUPPORT_HEADER_SIGN | PFC_CONC_MPX; + bind_pdu.header.call_id = 2; + bind_pdu.max_xmit_frag = rpc->max_xmit_frag; + bind_pdu.max_recv_frag = rpc->max_recv_frag; + bind_pdu.assoc_group_id = 0; + bind_pdu.p_context_elem.n_context_elem = 2; + bind_pdu.p_context_elem.reserved = 0; + bind_pdu.p_context_elem.reserved2 = 0; + bind_pdu.p_context_elem.p_cont_elem = + calloc(bind_pdu.p_context_elem.n_context_elem, sizeof(p_cont_elem_t)); + + if (!bind_pdu.p_context_elem.p_cont_elem) + goto fail; + + p_cont_elem = &bind_pdu.p_context_elem.p_cont_elem[0]; + p_cont_elem->p_cont_id = 0; + p_cont_elem->n_transfer_syn = 1; + p_cont_elem->reserved = 0; + CopyMemory(&(p_cont_elem->abstract_syntax.if_uuid), &TSGU_UUID, sizeof(p_uuid_t)); + p_cont_elem->abstract_syntax.if_version = TSGU_SYNTAX_IF_VERSION; + p_cont_elem->transfer_syntaxes = malloc(sizeof(p_syntax_id_t)); + + if (!p_cont_elem->transfer_syntaxes) + goto fail; + + CopyMemory(&(p_cont_elem->transfer_syntaxes[0].if_uuid), &NDR_UUID, sizeof(p_uuid_t)); + p_cont_elem->transfer_syntaxes[0].if_version = NDR_SYNTAX_IF_VERSION; + p_cont_elem = &bind_pdu.p_context_elem.p_cont_elem[1]; + p_cont_elem->p_cont_id = 1; + p_cont_elem->n_transfer_syn = 1; + p_cont_elem->reserved = 0; + CopyMemory(&(p_cont_elem->abstract_syntax.if_uuid), &TSGU_UUID, sizeof(p_uuid_t)); + p_cont_elem->abstract_syntax.if_version = TSGU_SYNTAX_IF_VERSION; + p_cont_elem->transfer_syntaxes = malloc(sizeof(p_syntax_id_t)); + + if (!p_cont_elem->transfer_syntaxes) + goto fail; + + CopyMemory(&(p_cont_elem->transfer_syntaxes[0].if_uuid), &BTFN_UUID, sizeof(p_uuid_t)); + p_cont_elem->transfer_syntaxes[0].if_version = BTFN_SYNTAX_IF_VERSION; + offset = 116; + + bind_pdu.auth_verifier.auth_type = + rpc_auth_pkg_to_security_provider(credssp_auth_pkg_name(rpc->auth)); + bind_pdu.auth_verifier.auth_level = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY; + bind_pdu.auth_verifier.auth_reserved = 0x00; + bind_pdu.auth_verifier.auth_context_id = 0x00000000; + offset += (8 + bind_pdu.header.auth_length); + + WINPR_ASSERT(offset <= UINT16_MAX); + bind_pdu.header.frag_length = (UINT16)offset; + + buffer = Stream_New(NULL, bind_pdu.header.frag_length); + + if (!buffer) + goto fail; + + if (!rts_write_pdu_bind(buffer, &bind_pdu)) + goto fail; + + clientCall = rpc_client_call_new(bind_pdu.header.call_id, 0); + + if (!clientCall) + goto fail; + + if (!ArrayList_Append(rpc->client->ClientCallList, clientCall)) + { + rpc_client_call_free(clientCall); + goto fail; + } + + Stream_SealLength(buffer); + status = rpc_in_channel_send_pdu(inChannel, Stream_Buffer(buffer), Stream_Length(buffer)); +fail: + + if (bind_pdu.p_context_elem.p_cont_elem) + { + free(bind_pdu.p_context_elem.p_cont_elem[0].transfer_syntaxes); + free(bind_pdu.p_context_elem.p_cont_elem[1].transfer_syntaxes); + } + + free(bind_pdu.p_context_elem.p_cont_elem); + bind_pdu.p_context_elem.p_cont_elem = NULL; + + Stream_Free(buffer, TRUE); + return (status > 0) ? 1 : -1; +} + +/** + * Maximum Transmit/Receive Fragment Size Negotiation + * + * The client determines, and then sends in the bind PDU, its desired maximum size for transmitting + * fragments, and its desired maximum receive fragment size. Similarly, the server determines its + * desired maximum sizes for transmitting and receiving fragments. Transmit and receive sizes may be + * different to help preserve buffering. When the server receives the client’s values, it sets its + * operational transmit size to the minimum of the client’s receive size (from the bind PDU) and its + * own desired transmit size. Then it sets its actual receive size to the minimum of the client’s + * transmit size (from the bind) and its own desired receive size. The server then returns its + * operational values in the bind_ack PDU. The client then sets its operational values from the + * received bind_ack PDU. The received transmit size becomes the client’s receive size, and the + * received receive size becomes the client’s transmit size. Either party may use receive buffers + * larger than negotiated — although this will not provide any advantage — but may not transmit + * larger fragments than negotiated. + */ + +/** + * + * SECURE_BIND_ACK: RPC bind_ack PDU with sec_trailer and auth_token. The PFC_SUPPORT_HEADER_SIGN + * flag in the PDU header is also set in this example. Auth_token is generated by the server in the + * previous step. Upon receiving that PDU, the client calls the implementation equivalent of the + * abstract GSS_Init_sec_context call, which returns an auth_token and continue status in this + * example. + */ + +BOOL rpc_recv_bind_ack_pdu(rdpRpc* rpc, wStream* s) +{ + BOOL rc = FALSE; + const BYTE* auth_data = NULL; + size_t pos = 0; + size_t end = 0; + rpcconn_hdr_t header = { 0 }; + SecBuffer buffer = { 0 }; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->auth); + WINPR_ASSERT(s); + + pos = Stream_GetPosition(s); + if (!rts_read_pdu_header(s, &header)) + goto fail; + + WLog_DBG(TAG, header.common.ptype == PTYPE_BIND_ACK ? "Receiving BindAck PDU" + : "Receiving AlterContextResp PDU"); + + rpc->max_recv_frag = header.bind_ack.max_xmit_frag; + rpc->max_xmit_frag = header.bind_ack.max_recv_frag; + + /* Get the correct offset in the input data and pass that on as input buffer. + * rts_read_pdu_header did already do consistency checks */ + end = Stream_GetPosition(s); + Stream_SetPosition(s, pos + header.common.frag_length - header.common.auth_length); + auth_data = Stream_ConstPointer(s); + Stream_SetPosition(s, end); + + buffer.cbBuffer = header.common.auth_length; + buffer.pvBuffer = malloc(buffer.cbBuffer); + if (!buffer.pvBuffer) + goto fail; + memcpy(buffer.pvBuffer, auth_data, buffer.cbBuffer); + credssp_auth_take_input_buffer(rpc->auth, &buffer); + + if (credssp_auth_authenticate(rpc->auth) < 0) + goto fail; + + rc = TRUE; +fail: + rts_free_pdu_header(&header, FALSE); + return rc; +} + +/** + * RPC_AUTH_3: The client knows that this is an NTLM that uses three legs. It sends an rpc_auth_3 + * PDU with the auth_token obtained in the previous step. Upon receiving this PDU, the server calls + * the implementation equivalent of the abstract GSS_Accept_sec_context call, which returns success + * status in this example. + */ + +int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc) +{ + int status = -1; + wStream* buffer = NULL; + size_t offset = 0; + const SecBuffer* sbuffer = NULL; + RpcClientCall* clientCall = NULL; + rpcconn_rpc_auth_3_hdr_t auth_3_pdu = { 0 }; + RpcVirtualConnection* connection = NULL; + RpcInChannel* inChannel = NULL; + + WINPR_ASSERT(rpc); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + inChannel = connection->DefaultInChannel; + WINPR_ASSERT(inChannel); + + WLog_DBG(TAG, "Sending RpcAuth3 PDU"); + + sbuffer = credssp_auth_get_output_buffer(rpc->auth); + + if (!sbuffer) + return -1; + + auth_3_pdu.header = rpc_pdu_header_init(rpc); + auth_3_pdu.header.auth_length = (UINT16)sbuffer->cbBuffer; + auth_3_pdu.auth_verifier.auth_value = sbuffer->pvBuffer; + auth_3_pdu.header.ptype = PTYPE_RPC_AUTH_3; + auth_3_pdu.header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG | PFC_CONC_MPX; + auth_3_pdu.header.call_id = 2; + auth_3_pdu.max_xmit_frag = rpc->max_xmit_frag; + auth_3_pdu.max_recv_frag = rpc->max_recv_frag; + offset = 20; + + const size_t align = rpc_offset_align(&offset, 4); + WINPR_ASSERT(align <= UINT8_MAX); + auth_3_pdu.auth_verifier.auth_pad_length = (BYTE)align; + auth_3_pdu.auth_verifier.auth_type = + rpc_auth_pkg_to_security_provider(credssp_auth_pkg_name(rpc->auth)); + auth_3_pdu.auth_verifier.auth_level = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY; + auth_3_pdu.auth_verifier.auth_reserved = 0x00; + auth_3_pdu.auth_verifier.auth_context_id = 0x00000000; + offset += (8 + auth_3_pdu.header.auth_length); + + WINPR_ASSERT(offset <= UINT16_MAX); + auth_3_pdu.header.frag_length = (UINT16)offset; + + buffer = Stream_New(NULL, auth_3_pdu.header.frag_length); + + if (!buffer) + return -1; + + if (!rts_write_pdu_auth3(buffer, &auth_3_pdu)) + goto fail; + + clientCall = rpc_client_call_new(auth_3_pdu.header.call_id, 0); + + if (ArrayList_Append(rpc->client->ClientCallList, clientCall)) + { + Stream_SealLength(buffer); + status = rpc_in_channel_send_pdu(inChannel, Stream_Buffer(buffer), Stream_Length(buffer)); + } + +fail: + Stream_Free(buffer, TRUE); + return (status > 0) ? 1 : -1; +} + +enum RPC_BIND_STATE rpc_bind_state(rdpRpc* rpc) +{ + BOOL complete = 0; + BOOL have_token = 0; + WINPR_ASSERT(rpc); + + complete = credssp_auth_is_complete(rpc->auth); + have_token = credssp_auth_have_output_token(rpc->auth); + + return complete ? (have_token ? RPC_BIND_STATE_LAST_LEG : RPC_BIND_STATE_COMPLETE) + : RPC_BIND_STATE_INCOMPLETE; +} + +BYTE rpc_auth_pkg_to_security_provider(const char* name) +{ + if (strcmp(name, CREDSSP_AUTH_PKG_SPNEGO) == 0) + return RPC_C_AUTHN_GSS_NEGOTIATE; + else if (strcmp(name, CREDSSP_AUTH_PKG_NTLM) == 0) + return RPC_C_AUTHN_WINNT; + else if (strcmp(name, CREDSSP_AUTH_PKG_KERBEROS) == 0) + return RPC_C_AUTHN_GSS_KERBEROS; + else if (strcmp(name, CREDSSP_AUTH_PKG_SCHANNEL) == 0) + return RPC_C_AUTHN_GSS_SCHANNEL; + else + return RPC_C_AUTHN_NONE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_bind.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_bind.h new file mode 100644 index 0000000000000000000000000000000000000000..7d33d5f0d908ba559e4dc6ff5564e502f8c70700 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_bind.h @@ -0,0 +1,50 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC Secure Context Binding + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_RPC_BIND_H +#define FREERDP_LIB_CORE_GATEWAY_RPC_BIND_H + +#include "rpc.h" + +#include +#include + +FREERDP_LOCAL extern const p_uuid_t TSGU_UUID; +#define TSGU_SYNTAX_IF_VERSION 0x00030001 + +FREERDP_LOCAL extern const p_uuid_t NDR_UUID; +#define NDR_SYNTAX_IF_VERSION 0x00000002 + +FREERDP_LOCAL extern const p_uuid_t BTFN_UUID; +#define BTFN_SYNTAX_IF_VERSION 0x00000001 + +enum RPC_BIND_STATE +{ + RPC_BIND_STATE_INCOMPLETE, + RPC_BIND_STATE_LAST_LEG, + RPC_BIND_STATE_COMPLETE +}; + +FREERDP_LOCAL int rpc_send_bind_pdu(rdpRpc* rpc, BOOL initial); +FREERDP_LOCAL BOOL rpc_recv_bind_ack_pdu(rdpRpc* rpc, wStream* s); +FREERDP_LOCAL int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc); +FREERDP_LOCAL enum RPC_BIND_STATE rpc_bind_state(rdpRpc* rpc); +FREERDP_LOCAL BYTE rpc_auth_pkg_to_security_provider(const char* name); + +#endif /* FREERDP_LIB_CORE_GATEWAY_RPC_BIND_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_client.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_client.c new file mode 100644 index 0000000000000000000000000000000000000000..b83d0cadc1a68265a3b49911f03043c608c0dd61 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_client.c @@ -0,0 +1,1248 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC Client + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "http.h" +#include "ncacn_http.h" + +#include "rpc_bind.h" +#include "rpc_fault.h" +#include "rpc_client.h" +#include "rts_signature.h" + +#include "../utils.h" +#include "../rdp.h" +#include "../proxy.h" + +#define TAG FREERDP_TAG("core.gateway.rpc") + +static const char* rpc_client_state_str(RPC_CLIENT_STATE state) +{ + // NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) + const char* str = "RPC_CLIENT_STATE_UNKNOWN"; + + switch (state) + { + case RPC_CLIENT_STATE_INITIAL: + str = "RPC_CLIENT_STATE_INITIAL"; + break; + + case RPC_CLIENT_STATE_ESTABLISHED: + str = "RPC_CLIENT_STATE_ESTABLISHED"; + break; + + case RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK: + str = "RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK"; + break; + + case RPC_CLIENT_STATE_WAIT_UNSECURE_BIND_ACK: + str = "RPC_CLIENT_STATE_WAIT_UNSECURE_BIND_ACK"; + break; + + case RPC_CLIENT_STATE_WAIT_SECURE_ALTER_CONTEXT_RESPONSE: + str = "RPC_CLIENT_STATE_WAIT_SECURE_ALTER_CONTEXT_RESPONSE"; + break; + + case RPC_CLIENT_STATE_CONTEXT_NEGOTIATED: + str = "RPC_CLIENT_STATE_CONTEXT_NEGOTIATED"; + break; + + case RPC_CLIENT_STATE_WAIT_RESPONSE: + str = "RPC_CLIENT_STATE_WAIT_RESPONSE"; + break; + + case RPC_CLIENT_STATE_FINAL: + str = "RPC_CLIENT_STATE_FINAL"; + break; + default: + break; + } + return str; +} + +static void rpc_pdu_reset(RPC_PDU* pdu) +{ + pdu->Type = 0; + pdu->Flags = 0; + pdu->CallId = 0; + Stream_SetPosition(pdu->s, 0); + Stream_SetLength(pdu->s, 0); +} + +static RPC_PDU* rpc_pdu_new(void) +{ + RPC_PDU* pdu = NULL; + pdu = (RPC_PDU*)malloc(sizeof(RPC_PDU)); + + if (!pdu) + return NULL; + + pdu->s = Stream_New(NULL, 4096); + + if (!pdu->s) + { + free(pdu); + return NULL; + } + + rpc_pdu_reset(pdu); + return pdu; +} + +static void rpc_pdu_free(RPC_PDU* pdu) +{ + if (!pdu) + return; + + Stream_Free(pdu->s, TRUE); + free(pdu); +} + +static int rpc_client_receive_pipe_write(RpcClient* client, const BYTE* buffer, size_t length) +{ + int status = 0; + + if (!client || !buffer) + return -1; + + EnterCriticalSection(&(client->PipeLock)); + + if (ringbuffer_write(&(client->ReceivePipe), buffer, length)) + status += (int)length; + + if (ringbuffer_used(&(client->ReceivePipe)) > 0) + (void)SetEvent(client->PipeEvent); + + LeaveCriticalSection(&(client->PipeLock)); + return status; +} + +int rpc_client_receive_pipe_read(RpcClient* client, BYTE* buffer, size_t length) +{ + size_t status = 0; + int nchunks = 0; + DataChunk chunks[2]; + + if (!client || !buffer) + return -1; + + EnterCriticalSection(&(client->PipeLock)); + nchunks = ringbuffer_peek(&(client->ReceivePipe), chunks, length); + + for (int index = 0; index < nchunks; index++) + { + CopyMemory(&buffer[status], chunks[index].data, chunks[index].size); + status += chunks[index].size; + } + + if (status > 0) + ringbuffer_commit_read_bytes(&(client->ReceivePipe), status); + + if (ringbuffer_used(&(client->ReceivePipe)) < 1) + (void)ResetEvent(client->PipeEvent); + + LeaveCriticalSection(&(client->PipeLock)); + + if (status > INT_MAX) + return -1; + return (int)status; +} + +static int rpc_client_transition_to_state(rdpRpc* rpc, RPC_CLIENT_STATE state) +{ + int status = 1; + + rpc->State = state; + WLog_DBG(TAG, "%s", rpc_client_state_str(state)); + return status; +} + +static int rpc_client_recv_pdu_int(rdpRpc* rpc, RPC_PDU* pdu) +{ + int status = -1; + RtsPduSignature found = { 0 }; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(pdu); + + rdpTsg* tsg = transport_get_tsg(rpc->transport); + + WLog_VRB(TAG, "client state %s, vc state %s", rpc_client_state_str(rpc->State), + rpc_vc_state_str(rpc->VirtualConnection->State)); + + const BOOL rc = rts_match_pdu_signature_ex(&RTS_PDU_PING_SIGNATURE, pdu->s, NULL, &found, TRUE); + rts_print_pdu_signature(rpc->log, WLOG_TRACE, &found); + if (rc) + return rts_recv_ping_pdu(rpc, pdu->s); + + if (rpc->VirtualConnection->State < VIRTUAL_CONNECTION_STATE_OPENED) + { + switch (rpc->VirtualConnection->State) + { + case VIRTUAL_CONNECTION_STATE_INITIAL: + break; + + case VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT: + break; + + case VIRTUAL_CONNECTION_STATE_WAIT_A3W: + if (memcmp(&found, &RTS_PDU_CONN_A3_SIGNATURE, sizeof(found)) != 0) + { + wLog* log = WLog_Get(TAG); + WLog_Print(log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/A3"); + rts_print_pdu_signature(log, WLOG_ERROR, &found); + return -1; + } + + if (!rts_recv_CONN_A3_pdu(rpc, pdu->s)) + { + WLog_ERR(TAG, "rts_recv_CONN_A3_pdu failure"); + return -1; + } + + rpc_virtual_connection_transition_to_state(rpc, rpc->VirtualConnection, + VIRTUAL_CONNECTION_STATE_WAIT_C2); + status = 1; + break; + + case VIRTUAL_CONNECTION_STATE_WAIT_C2: + if (memcmp(&found, &RTS_PDU_CONN_C2_SIGNATURE, sizeof(found)) != 0) + { + wLog* log = WLog_Get(TAG); + WLog_Print(log, WLOG_ERROR, "unexpected RTS PDU: Expected CONN/C2"); + rts_print_pdu_signature(log, WLOG_ERROR, &found); + return -1; + } + + if (!rts_recv_CONN_C2_pdu(rpc, pdu->s)) + { + WLog_ERR(TAG, "rts_recv_CONN_C2_pdu failure"); + return -1; + } + + rpc_virtual_connection_transition_to_state(rpc, rpc->VirtualConnection, + VIRTUAL_CONNECTION_STATE_OPENED); + rpc_client_transition_to_state(rpc, RPC_CLIENT_STATE_ESTABLISHED); + + if (rpc_send_bind_pdu(rpc, TRUE) < 0) + { + WLog_ERR(TAG, "rpc_send_bind_pdu failure"); + return -1; + } + + rpc_client_transition_to_state(rpc, RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK); + status = 1; + break; + + case VIRTUAL_CONNECTION_STATE_OPENED: + break; + + case VIRTUAL_CONNECTION_STATE_FINAL: + break; + default: + break; + } + } + else if (rpc->State < RPC_CLIENT_STATE_CONTEXT_NEGOTIATED) + { + if (rpc->State == RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK) + { + if (pdu->Type == PTYPE_BIND_ACK || pdu->Type == PTYPE_ALTER_CONTEXT_RESP) + { + if (!rpc_recv_bind_ack_pdu(rpc, pdu->s)) + { + WLog_ERR(TAG, "rpc_recv_bind_ack_pdu failure"); + return -1; + } + } + else + { + WLog_ERR(TAG, + "RPC_CLIENT_STATE_WAIT_SECURE_BIND_ACK unexpected pdu type: 0x%08" PRIX32 + "", + pdu->Type); + return -1; + } + + switch (rpc_bind_state(rpc)) + { + case RPC_BIND_STATE_INCOMPLETE: + if (rpc_send_bind_pdu(rpc, FALSE) < 0) + { + WLog_ERR(TAG, "rpc_send_bind_pdu failure"); + return -1; + } + break; + case RPC_BIND_STATE_LAST_LEG: + if (rpc_send_rpc_auth_3_pdu(rpc) < 0) + { + WLog_ERR(TAG, "rpc_secure_bind: error sending rpc_auth_3 pdu!"); + return -1; + } + /* fallthrough */ + WINPR_FALLTHROUGH + case RPC_BIND_STATE_COMPLETE: + rpc_client_transition_to_state(rpc, RPC_CLIENT_STATE_CONTEXT_NEGOTIATED); + + if (!tsg_proxy_begin(tsg)) + { + WLog_ERR(TAG, "tsg_proxy_begin failure"); + return -1; + } + break; + default: + break; + } + + status = 1; + } + else + { + WLog_ERR(TAG, "invalid rpc->State: %d", rpc->State); + } + } + else if (rpc->State >= RPC_CLIENT_STATE_CONTEXT_NEGOTIATED) + { + if (!tsg_recv_pdu(tsg, pdu)) + status = -1; + else + status = 1; + } + + return status; +} + +static int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu) +{ + WINPR_ASSERT(rpc); + WINPR_ASSERT(pdu); + + Stream_SealLength(pdu->s); + Stream_SetPosition(pdu->s, 0); + + const size_t before = Stream_GetRemainingLength(pdu->s); + WLog_VRB(TAG, "RPC PDU parsing %" PRIuz " bytes", before); + const int rc = rpc_client_recv_pdu_int(rpc, pdu); + if (rc < 0) + return rc; + const size_t after = Stream_GetRemainingLength(pdu->s); + if (after > 0) + { + /* Just log so we do not fail if we have some unprocessed padding bytes */ + WLog_WARN(TAG, "Incompletely parsed RPC PDU (%" PRIuz " bytes remain)", after); + } + + return rc; +} + +static int rpc_client_recv_fragment(rdpRpc* rpc, wStream* fragment) +{ + int rc = -1; + RPC_PDU* pdu = NULL; + size_t StubOffset = 0; + size_t StubLength = 0; + RpcClientCall* call = NULL; + rpcconn_hdr_t header = { 0 }; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->client); + WINPR_ASSERT(fragment); + + pdu = rpc->client->pdu; + WINPR_ASSERT(pdu); + + Stream_SealLength(fragment); + Stream_SetPosition(fragment, 0); + + if (!rts_read_pdu_header(fragment, &header)) + goto fail; + + if (header.common.ptype == PTYPE_RESPONSE) + { + rpc->VirtualConnection->DefaultOutChannel->BytesReceived += header.common.frag_length; + rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow -= + header.common.frag_length; + + if (rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow < + (rpc->ReceiveWindow / 2)) + { + if (!rts_send_flow_control_ack_pdu(rpc)) + goto fail; + } + + if (!rpc_get_stub_data_info(rpc, &header, &StubOffset, &StubLength)) + { + WLog_ERR(TAG, "expected stub"); + goto fail; + } + + if (StubLength == 4) + { + if ((header.common.call_id == rpc->PipeCallId) && + (header.common.pfc_flags & PFC_LAST_FRAG)) + { + /* End of TsProxySetupReceivePipe */ + TerminateEventArgs e; + rdpContext* context = transport_get_context(rpc->transport); + rdpTsg* tsg = transport_get_tsg(rpc->transport); + + WINPR_ASSERT(context); + + if (Stream_Length(fragment) < StubOffset + 4) + goto fail; + Stream_SetPosition(fragment, StubOffset); + Stream_Read_UINT32(fragment, rpc->result); + + utils_abort_connect(context->rdp); + tsg_set_state(tsg, TSG_STATE_TUNNEL_CLOSE_PENDING); + EventArgsInit(&e, "freerdp"); + e.code = 0; + PubSub_OnTerminate(context->rdp->pubSub, context, &e); + rc = 0; + goto success; + } + + if (header.common.call_id != rpc->PipeCallId) + { + /* Ignoring non-TsProxySetupReceivePipe Response */ + rc = 0; + goto success; + } + } + + if (rpc->StubFragCount == 0) + rpc->StubCallId = header.common.call_id; + + if (rpc->StubCallId != header.common.call_id) + { + WLog_ERR(TAG, + "invalid call_id: actual: %" PRIu32 ", expected: %" PRIu32 + ", frag_count: %" PRIu32 "", + rpc->StubCallId, header.common.call_id, rpc->StubFragCount); + } + + call = rpc_client_call_find_by_id(rpc->client, rpc->StubCallId); + + if (!call) + goto fail; + + if (call->OpNum != TsProxySetupReceivePipeOpnum) + { + const rpcconn_response_hdr_t* response = + (const rpcconn_response_hdr_t*)&header.response; + if (!Stream_EnsureCapacity(pdu->s, response->alloc_hint)) + goto fail; + + if (Stream_Length(fragment) < StubOffset + StubLength) + goto fail; + + Stream_SetPosition(fragment, StubOffset); + Stream_Write(pdu->s, Stream_ConstPointer(fragment), StubLength); + rpc->StubFragCount++; + + if (response->alloc_hint == StubLength) + { + pdu->Flags = RPC_PDU_FLAG_STUB; + pdu->Type = PTYPE_RESPONSE; + pdu->CallId = rpc->StubCallId; + + if (rpc_client_recv_pdu(rpc, pdu) < 0) + goto fail; + rpc_pdu_reset(pdu); + rpc->StubFragCount = 0; + rpc->StubCallId = 0; + } + } + else + { + const rpcconn_response_hdr_t* response = &header.response; + if (Stream_Length(fragment) < StubOffset + StubLength) + goto fail; + Stream_SetPosition(fragment, StubOffset); + rpc_client_receive_pipe_write(rpc->client, Stream_ConstPointer(fragment), StubLength); + rpc->StubFragCount++; + + if (response->alloc_hint == StubLength) + { + rpc->StubFragCount = 0; + rpc->StubCallId = 0; + } + } + + goto success; + } + else if (header.common.ptype == PTYPE_RTS) + { + if (rpc->State < RPC_CLIENT_STATE_CONTEXT_NEGOTIATED) + { + pdu->Flags = 0; + pdu->Type = header.common.ptype; + pdu->CallId = header.common.call_id; + + const size_t len = Stream_Length(fragment); + if (!Stream_EnsureCapacity(pdu->s, len)) + goto fail; + + Stream_Write(pdu->s, Stream_Buffer(fragment), len); + + if (rpc_client_recv_pdu(rpc, pdu) < 0) + goto fail; + + rpc_pdu_reset(pdu); + } + else + { + if (!rts_recv_out_of_sequence_pdu(rpc, fragment, &header)) + goto fail; + } + + goto success; + } + else if (header.common.ptype == PTYPE_BIND_ACK || + header.common.ptype == PTYPE_ALTER_CONTEXT_RESP) + { + pdu->Flags = 0; + pdu->Type = header.common.ptype; + pdu->CallId = header.common.call_id; + + const size_t len = Stream_Length(fragment); + if (!Stream_EnsureCapacity(pdu->s, len)) + goto fail; + + Stream_Write(pdu->s, Stream_Buffer(fragment), len); + + if (rpc_client_recv_pdu(rpc, pdu) < 0) + goto fail; + + rpc_pdu_reset(pdu); + goto success; + } + else if (header.common.ptype == PTYPE_FAULT) + { + const rpcconn_fault_hdr_t* fault = (const rpcconn_fault_hdr_t*)&header.fault; + rpc_recv_fault_pdu(fault->status); + goto fail; + } + else + { + WLog_ERR(TAG, "unexpected RPC PDU type 0x%02" PRIX8 "", header.common.ptype); + goto fail; + } + +success: + rc = (rc < 0) ? 1 : 0; /* In case of default error return change to 1, otherwise we already set + the return code */ +fail: + rts_free_pdu_header(&header, FALSE); + return rc; +} + +static SSIZE_T rpc_client_default_out_channel_recv(rdpRpc* rpc) +{ + SSIZE_T status = -1; + HttpResponse* response = NULL; + RpcInChannel* inChannel = NULL; + RpcOutChannel* outChannel = NULL; + HANDLE outChannelEvent = NULL; + RpcVirtualConnection* connection = rpc->VirtualConnection; + inChannel = connection->DefaultInChannel; + outChannel = connection->DefaultOutChannel; + BIO_get_event(outChannel->common.tls->bio, &outChannelEvent); + + if (outChannel->State < CLIENT_OUT_CHANNEL_STATE_OPENED) + { + if (WaitForSingleObject(outChannelEvent, 0) != WAIT_OBJECT_0) + return 1; + + response = http_response_recv(outChannel->common.tls, TRUE); + + if (!response) + return -1; + + if (outChannel->State == CLIENT_OUT_CHANNEL_STATE_SECURITY) + { + /* Receive OUT Channel Response */ + if (!rpc_ncacn_http_recv_out_channel_response(&outChannel->common, response)) + { + http_response_free(response); + WLog_ERR(TAG, "rpc_ncacn_http_recv_out_channel_response failure"); + return -1; + } + + /* Send OUT Channel Request */ + + if (!rpc_ncacn_http_send_out_channel_request(&outChannel->common, FALSE)) + { + http_response_free(response); + WLog_ERR(TAG, "rpc_ncacn_http_send_out_channel_request failure"); + return -1; + } + + if (rpc_ncacn_http_is_final_request(&outChannel->common)) + { + rpc_ncacn_http_auth_uninit(&outChannel->common); + rpc_out_channel_transition_to_state(outChannel, + CLIENT_OUT_CHANNEL_STATE_NEGOTIATED); + + /* Send CONN/A1 PDU over OUT channel */ + + if (!rts_send_CONN_A1_pdu(rpc)) + { + http_response_free(response); + WLog_ERR(TAG, "rpc_send_CONN_A1_pdu error!"); + return -1; + } + + rpc_out_channel_transition_to_state(outChannel, CLIENT_OUT_CHANNEL_STATE_OPENED); + + if (inChannel->State == CLIENT_IN_CHANNEL_STATE_OPENED) + { + rpc_virtual_connection_transition_to_state( + rpc, connection, VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT); + } + } + + status = 1; + } + + http_response_free(response); + } + else if (connection->State == VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT) + { + /* Receive OUT channel response */ + if (WaitForSingleObject(outChannelEvent, 0) != WAIT_OBJECT_0) + return 1; + + response = http_response_recv(outChannel->common.tls, FALSE); + + if (!response) + return -1; + + const INT16 statusCode = http_response_get_status_code(response); + + if (statusCode != HTTP_STATUS_OK) + { + http_response_log_error_status(WLog_Get(TAG), WLOG_ERROR, response); + + if (statusCode == HTTP_STATUS_DENIED) + { + rdpContext* context = transport_get_context(rpc->transport); + freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_ACCESS_DENIED); + } + + http_response_free(response); + return -1; + } + + http_response_free(response); + rpc_virtual_connection_transition_to_state(rpc, rpc->VirtualConnection, + VIRTUAL_CONNECTION_STATE_WAIT_A3W); + status = 1; + } + else + { + wStream* fragment = rpc->client->ReceiveFragment; + + while (1) + { + size_t pos = 0; + rpcconn_common_hdr_t header = { 0 }; + + while (Stream_GetPosition(fragment) < RPC_COMMON_FIELDS_LENGTH) + { + status = rpc_channel_read(&outChannel->common, fragment, + RPC_COMMON_FIELDS_LENGTH - Stream_GetPosition(fragment)); + + if (status < 0) + return -1; + + if (Stream_GetPosition(fragment) < RPC_COMMON_FIELDS_LENGTH) + return 0; + } + + pos = Stream_GetPosition(fragment); + Stream_SetPosition(fragment, 0); + + /* Ignore errors, the PDU might not be complete. */ + rts_read_common_pdu_header(fragment, &header, TRUE); + Stream_SetPosition(fragment, pos); + + if (header.frag_length > rpc->max_recv_frag) + { + WLog_ERR(TAG, + "rpc_client_recv: invalid fragment size: %" PRIu16 " (max: %" PRIu16 ")", + header.frag_length, rpc->max_recv_frag); + winpr_HexDump(TAG, WLOG_ERROR, Stream_Buffer(fragment), + Stream_GetPosition(fragment)); + return -1; + } + + while (Stream_GetPosition(fragment) < header.frag_length) + { + status = rpc_channel_read(&outChannel->common, fragment, + header.frag_length - Stream_GetPosition(fragment)); + + if (status < 0) + { + WLog_ERR(TAG, "error reading fragment body"); + return -1; + } + + if (Stream_GetPosition(fragment) < header.frag_length) + return 0; + } + + { + /* complete fragment received */ + status = rpc_client_recv_fragment(rpc, fragment); + + if (status < 0) + return status; + + /* channel recycling may update channel pointers */ + if (outChannel->State == CLIENT_OUT_CHANNEL_STATE_RECYCLED && + connection->NonDefaultOutChannel) + { + rpc_channel_free(&connection->DefaultOutChannel->common); + connection->DefaultOutChannel = connection->NonDefaultOutChannel; + connection->NonDefaultOutChannel = NULL; + rpc_out_channel_transition_to_state(connection->DefaultOutChannel, + CLIENT_OUT_CHANNEL_STATE_OPENED); + rpc_virtual_connection_transition_to_state( + rpc, connection, VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT); + return 0; + } + + Stream_SetPosition(fragment, 0); + } + } + } + + return status; +} + +static SSIZE_T rpc_client_nondefault_out_channel_recv(rdpRpc* rpc) +{ + SSIZE_T status = -1; + HttpResponse* response = NULL; + RpcOutChannel* nextOutChannel = NULL; + HANDLE nextOutChannelEvent = NULL; + nextOutChannel = rpc->VirtualConnection->NonDefaultOutChannel; + BIO_get_event(nextOutChannel->common.tls->bio, &nextOutChannelEvent); + + if (WaitForSingleObject(nextOutChannelEvent, 0) != WAIT_OBJECT_0) + return 1; + + response = http_response_recv(nextOutChannel->common.tls, TRUE); + + if (response) + { + switch (nextOutChannel->State) + { + case CLIENT_OUT_CHANNEL_STATE_SECURITY: + if (rpc_ncacn_http_recv_out_channel_response(&nextOutChannel->common, response)) + { + if (rpc_ncacn_http_send_out_channel_request(&nextOutChannel->common, TRUE)) + { + if (rpc_ncacn_http_is_final_request(&nextOutChannel->common)) + { + rpc_ncacn_http_auth_uninit(&nextOutChannel->common); + + if (rts_send_OUT_R1_A3_pdu(rpc)) + { + status = 1; + rpc_out_channel_transition_to_state( + nextOutChannel, CLIENT_OUT_CHANNEL_STATE_OPENED_A6W); + } + else + { + WLog_ERR(TAG, "rts_send_OUT_R1/A3_pdu failure"); + } + } + else + { + status = 1; + } + } + else + { + WLog_ERR(TAG, "rpc_ncacn_http_send_out_channel_request failure"); + } + } + else + { + WLog_ERR(TAG, "rpc_ncacn_http_recv_out_channel_response failure"); + } + + break; + + case CLIENT_OUT_CHANNEL_STATE_INITIAL: + case CLIENT_OUT_CHANNEL_STATE_CONNECTED: + case CLIENT_OUT_CHANNEL_STATE_NEGOTIATED: + default: + WLog_ERR(TAG, + "rpc_client_nondefault_out_channel_recv: Unexpected message %08" PRIx32, + nextOutChannel->State); + status = -1; + } + + http_response_free(response); + } + + return status; +} + +int rpc_client_out_channel_recv(rdpRpc* rpc) +{ + SSIZE_T status = 0; + RpcVirtualConnection* connection = rpc->VirtualConnection; + + if (connection->DefaultOutChannel) + { + status = rpc_client_default_out_channel_recv(rpc); + + if (status < 0) + return -1; + } + + if (connection->NonDefaultOutChannel) + { + status = rpc_client_nondefault_out_channel_recv(rpc); + + if (status < 0) + return -1; + } + + return 1; +} + +int rpc_client_in_channel_recv(rdpRpc* rpc) +{ + int status = 1; + HttpResponse* response = NULL; + RpcInChannel* inChannel = NULL; + RpcOutChannel* outChannel = NULL; + HANDLE InChannelEvent = NULL; + RpcVirtualConnection* connection = rpc->VirtualConnection; + inChannel = connection->DefaultInChannel; + outChannel = connection->DefaultOutChannel; + BIO_get_event(inChannel->common.tls->bio, &InChannelEvent); + + if (WaitForSingleObject(InChannelEvent, 0) != WAIT_OBJECT_0) + return 1; + + if (inChannel->State < CLIENT_IN_CHANNEL_STATE_OPENED) + { + response = http_response_recv(inChannel->common.tls, TRUE); + + if (!response) + return -1; + + if (inChannel->State == CLIENT_IN_CHANNEL_STATE_SECURITY) + { + if (!rpc_ncacn_http_recv_in_channel_response(&inChannel->common, response)) + { + WLog_ERR(TAG, "rpc_ncacn_http_recv_in_channel_response failure"); + http_response_free(response); + return -1; + } + + /* Send IN Channel Request */ + + if (!rpc_ncacn_http_send_in_channel_request(&inChannel->common)) + { + WLog_ERR(TAG, "rpc_ncacn_http_send_in_channel_request failure"); + http_response_free(response); + return -1; + } + + if (rpc_ncacn_http_is_final_request(&inChannel->common)) + { + rpc_ncacn_http_auth_uninit(&inChannel->common); + rpc_in_channel_transition_to_state(inChannel, CLIENT_IN_CHANNEL_STATE_NEGOTIATED); + + /* Send CONN/B1 PDU over IN channel */ + + if (!rts_send_CONN_B1_pdu(rpc)) + { + WLog_ERR(TAG, "rpc_send_CONN_B1_pdu error!"); + http_response_free(response); + return -1; + } + + rpc_in_channel_transition_to_state(inChannel, CLIENT_IN_CHANNEL_STATE_OPENED); + + if (outChannel->State == CLIENT_OUT_CHANNEL_STATE_OPENED) + { + rpc_virtual_connection_transition_to_state( + rpc, connection, VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT); + } + } + + status = 1; + } + + http_response_free(response); + } + else + { + response = http_response_recv(inChannel->common.tls, TRUE); + + if (!response) + return -1; + + /* We can receive an unauthorized HTTP response on the IN channel */ + http_response_free(response); + } + + return status; +} + +/** + * [MS-RPCE] Client Call: + * http://msdn.microsoft.com/en-us/library/gg593159/ + */ + +RpcClientCall* rpc_client_call_find_by_id(RpcClient* client, UINT32 CallId) +{ + RpcClientCall* clientCall = NULL; + + if (!client) + return NULL; + + ArrayList_Lock(client->ClientCallList); + const size_t count = ArrayList_Count(client->ClientCallList); + + for (size_t index = 0; index < count; index++) + { + clientCall = (RpcClientCall*)ArrayList_GetItem(client->ClientCallList, index); + + if (clientCall->CallId == CallId) + break; + } + + ArrayList_Unlock(client->ClientCallList); + return clientCall; +} + +RpcClientCall* rpc_client_call_new(UINT32 CallId, UINT32 OpNum) +{ + RpcClientCall* clientCall = NULL; + clientCall = (RpcClientCall*)calloc(1, sizeof(RpcClientCall)); + + if (!clientCall) + return NULL; + + clientCall->CallId = CallId; + clientCall->OpNum = OpNum; + clientCall->State = RPC_CLIENT_CALL_STATE_SEND_PDUS; + return clientCall; +} + +void rpc_client_call_free(RpcClientCall* clientCall) +{ + free(clientCall); +} + +static void rpc_array_client_call_free(void* call) +{ + rpc_client_call_free((RpcClientCall*)call); +} + +int rpc_in_channel_send_pdu(RpcInChannel* inChannel, const BYTE* buffer, size_t length) +{ + SSIZE_T status = 0; + RpcClientCall* clientCall = NULL; + wStream s; + rpcconn_common_hdr_t header = { 0 }; + + status = rpc_channel_write(&inChannel->common, buffer, length); + + if (status <= 0) + return -1; + + Stream_StaticConstInit(&s, buffer, length); + if (!rts_read_common_pdu_header(&s, &header, FALSE)) + return -1; + + clientCall = rpc_client_call_find_by_id(inChannel->common.client, header.call_id); + if (!clientCall) + return -1; + + clientCall->State = RPC_CLIENT_CALL_STATE_DISPATCHED; + + /* + * This protocol specifies that only RPC PDUs are subject to the flow control abstract + * data model. RTS PDUs and the HTTP request and response headers are not subject to flow + * control. Implementations of this protocol MUST NOT include them when computing any of the + * variables specified by this abstract data model. + */ + + if (header.ptype == PTYPE_REQUEST) + { + inChannel->BytesSent += status; + inChannel->SenderAvailableWindow -= status; + } + + if (status > INT32_MAX) + return -1; + return (int)status; +} + +BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum) +{ + size_t offset = 0; + BYTE* buffer = NULL; + size_t stub_data_pad = 0; + SecBuffer plaintext; + SecBuffer ciphertext = { 0 }; + RpcClientCall* clientCall = NULL; + rdpCredsspAuth* auth = NULL; + rpcconn_request_hdr_t request_pdu = { 0 }; + RpcVirtualConnection* connection = NULL; + RpcInChannel* inChannel = NULL; + BOOL rc = FALSE; + + if (!s) + return FALSE; + + if (!rpc) + goto fail; + + auth = rpc->auth; + connection = rpc->VirtualConnection; + + if (!auth) + { + WLog_ERR(TAG, "invalid auth context"); + goto fail; + } + + if (!connection) + goto fail; + + inChannel = connection->DefaultInChannel; + + if (!inChannel) + goto fail; + + Stream_SealLength(s); + const size_t length = Stream_Length(s); + if (length > UINT32_MAX) + goto fail; + + const size_t asize = credssp_auth_trailer_size(auth); + + request_pdu.header = rpc_pdu_header_init(rpc); + request_pdu.header.ptype = PTYPE_REQUEST; + request_pdu.header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG; + request_pdu.header.auth_length = (UINT16)asize; + request_pdu.header.call_id = rpc->CallId++; + request_pdu.alloc_hint = (UINT32)length; + request_pdu.p_cont_id = 0x0000; + request_pdu.opnum = opnum; + clientCall = rpc_client_call_new(request_pdu.header.call_id, request_pdu.opnum); + + if (!clientCall) + goto fail; + + if (!ArrayList_Append(rpc->client->ClientCallList, clientCall)) + { + rpc_client_call_free(clientCall); + goto fail; + } + + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): ArrayList_Append takes ownership of clientCall + if (request_pdu.opnum == TsProxySetupReceivePipeOpnum) + rpc->PipeCallId = request_pdu.header.call_id; + + request_pdu.stub_data = Stream_Buffer(s); + offset = 24; + stub_data_pad = rpc_offset_align(&offset, 8); + offset += length; + + const size_t alg = rpc_offset_align(&offset, 4); + WINPR_ASSERT(alg <= UINT8_MAX); + request_pdu.auth_verifier.auth_pad_length = (UINT8)alg; + request_pdu.auth_verifier.auth_type = + rpc_auth_pkg_to_security_provider(credssp_auth_pkg_name(rpc->auth)); + request_pdu.auth_verifier.auth_level = RPC_C_AUTHN_LEVEL_PKT_INTEGRITY; + request_pdu.auth_verifier.auth_reserved = 0x00; + request_pdu.auth_verifier.auth_context_id = 0x00000000; + offset += (8 + request_pdu.header.auth_length); + + if (offset > UINT16_MAX) + goto fail; + request_pdu.header.frag_length = (UINT16)offset; + buffer = (BYTE*)calloc(1, request_pdu.header.frag_length); + + if (!buffer) + goto fail; + + CopyMemory(buffer, &request_pdu, 24); + offset = 24; + rpc_offset_pad(&offset, stub_data_pad); + CopyMemory(&buffer[offset], request_pdu.stub_data, length); + offset += length; + rpc_offset_pad(&offset, request_pdu.auth_verifier.auth_pad_length); + CopyMemory(&buffer[offset], &request_pdu.auth_verifier.auth_type, 8); + offset += 8; + + if (offset > UINT32_MAX) + goto fail; + + plaintext.pvBuffer = buffer; + plaintext.cbBuffer = (UINT32)offset; + plaintext.BufferType = SECBUFFER_READONLY; + + size_t size = 0; + if (!credssp_auth_encrypt(auth, &plaintext, &ciphertext, &size, rpc->SendSeqNum++)) + goto fail; + + CopyMemory(&buffer[offset], ciphertext.pvBuffer, size); + offset += size; + + sspi_SecBufferFree(&ciphertext); + + if (rpc_in_channel_send_pdu(inChannel, buffer, request_pdu.header.frag_length) < 0) + goto fail; + + rc = TRUE; +fail: + free(buffer); + Stream_Free(s, TRUE); + return rc; +} + +static BOOL rpc_client_resolve_gateway(rdpSettings* settings, char** host, UINT16* port, + BOOL* isProxy) +{ + struct addrinfo* result = NULL; + + if (!settings || !host || !port || !isProxy) + return FALSE; + else + { + const char* peerHostname = freerdp_settings_get_string(settings, FreeRDP_GatewayHostname); + const char* proxyUsername = freerdp_settings_get_string(settings, FreeRDP_GatewayUsername); + const char* proxyPassword = freerdp_settings_get_string(settings, FreeRDP_GatewayPassword); + *port = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_GatewayPort); + *isProxy = proxy_prepare(settings, &peerHostname, port, &proxyUsername, &proxyPassword); + result = freerdp_tcp_resolve_host(peerHostname, *port, 0); + + if (!result) + return FALSE; + + *host = + freerdp_tcp_address_to_string((const struct sockaddr_storage*)result->ai_addr, NULL); + freeaddrinfo(result); + return TRUE; + } +} + +RpcClient* rpc_client_new(rdpContext* context, UINT32 max_recv_frag) +{ + wObject* obj = NULL; + RpcClient* client = (RpcClient*)calloc(1, sizeof(RpcClient)); + + if (!client) + return NULL; + + if (!rpc_client_resolve_gateway(context->settings, &client->host, &client->port, + &client->isProxy)) + goto fail; + + client->context = context; + + if (!client->context) + goto fail; + + client->pdu = rpc_pdu_new(); + + if (!client->pdu) + goto fail; + + client->ReceiveFragment = Stream_New(NULL, max_recv_frag); + + if (!client->ReceiveFragment) + goto fail; + + client->PipeEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (!client->PipeEvent) + goto fail; + + if (!ringbuffer_init(&(client->ReceivePipe), 4096)) + goto fail; + + if (!InitializeCriticalSectionAndSpinCount(&(client->PipeLock), 4000)) + goto fail; + + client->ClientCallList = ArrayList_New(TRUE); + + if (!client->ClientCallList) + goto fail; + + obj = ArrayList_Object(client->ClientCallList); + obj->fnObjectFree = rpc_array_client_call_free; + return client; +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + rpc_client_free(client); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void rpc_client_free(RpcClient* client) +{ + if (!client) + return; + + free(client->host); + + if (client->ReceiveFragment) + Stream_Free(client->ReceiveFragment, TRUE); + + if (client->PipeEvent) + (void)CloseHandle(client->PipeEvent); + + ringbuffer_destroy(&(client->ReceivePipe)); + DeleteCriticalSection(&(client->PipeLock)); + + if (client->pdu) + rpc_pdu_free(client->pdu); + + if (client->ClientCallList) + ArrayList_Free(client->ClientCallList); + + free(client); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_client.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_client.h new file mode 100644 index 0000000000000000000000000000000000000000..4e075b8a7e46c83a4e0bd78d01a892194312d437 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_client.h @@ -0,0 +1,51 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC Client + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_RPC_CLIENT_H +#define FREERDP_LIB_CORE_GATEWAY_RPC_CLIENT_H + +#include +#include +#include + +#include "rpc.h" + +FREERDP_LOCAL RpcClientCall* rpc_client_call_find_by_id(RpcClient* client, UINT32 CallId); + +FREERDP_LOCAL void rpc_client_call_free(RpcClientCall* client_call); + +WINPR_ATTR_MALLOC(rpc_client_call_free, 1) +FREERDP_LOCAL RpcClientCall* rpc_client_call_new(UINT32 CallId, UINT32 OpNum); + +FREERDP_LOCAL int rpc_in_channel_send_pdu(RpcInChannel* inChannel, const BYTE* buffer, + size_t length); + +FREERDP_LOCAL int rpc_client_in_channel_recv(rdpRpc* rpc); +FREERDP_LOCAL int rpc_client_out_channel_recv(rdpRpc* rpc); + +FREERDP_LOCAL int rpc_client_receive_pipe_read(RpcClient* client, BYTE* buffer, size_t length); + +FREERDP_LOCAL BOOL rpc_client_write_call(rdpRpc* rpc, wStream* s, UINT16 opnum); + +FREERDP_LOCAL void rpc_client_free(RpcClient* client); + +WINPR_ATTR_MALLOC(rpc_client_free, 1) +FREERDP_LOCAL RpcClient* rpc_client_new(rdpContext* context, UINT32 max_recv_frag); + +#endif /* FREERDP_LIB_CORE_GATEWAY_RPC_CLIENT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_fault.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_fault.c new file mode 100644 index 0000000000000000000000000000000000000000..dcc201cc05c5a2c250b0e67d2176e3bcfed1cc29 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_fault.c @@ -0,0 +1,427 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC Fault Handling + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "rpc_fault.h" + +#include "rpc.h" + +#define TAG FREERDP_TAG("core.gateway.rpc") + +static ALIGN64 const RPC_FAULT_CODE RPC_FAULT_CODES[] = { + DEFINE_RPC_FAULT_CODE(nca_s_fault_object_not_found, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_cancel, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_addr_error, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_context_mismatch, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_fp_div_zero, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_fp_error, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_fp_overflow, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_fp_underflow, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_ill_inst, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_int_div_by_zero, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_int_overflow, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_invalid_bound, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_invalid_tag, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_pipe_closed, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_pipe_comm_error, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_pipe_discipline, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_pipe_empty, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_pipe_memory, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_pipe_order, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_remote_no_memory, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_user_defined, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_tx_open_failed, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_codeset_conv_error, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(nca_s_fault_no_client_stub, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_STRING_BINDING, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_WRONG_KIND_OF_BINDING, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_BINDING, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_PROTSEQ_NOT_SUPPORTED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_RPC_PROTSEQ, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_STRING_UUID, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_ENDPOINT_FORMAT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_NET_ADDR, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_ENDPOINT_FOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_TIMEOUT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_OBJECT_NOT_FOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ALREADY_REGISTERED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_TYPE_ALREADY_REGISTERED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ALREADY_LISTENING, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_PROTSEQS_REGISTERED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NOT_LISTENING, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNKNOWN_MGR_TYPE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNKNOWN_IF, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_BINDINGS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_PROTSEQS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_CANT_CREATE_ENDPOINT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_OUT_OF_RESOURCES, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_SERVER_UNAVAILABLE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_SERVER_TOO_BUSY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_NETWORK_OPTIONS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_CALL_ACTIVE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_CALL_FAILED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_CALL_FAILED_DNE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_PROTOCOL_ERROR, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_PROXY_ACCESS_DENIED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNSUPPORTED_TRANS_SYN, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNSUPPORTED_TYPE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_TAG, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_BOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_ENTRY_NAME, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_NAME_SYNTAX, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNSUPPORTED_NAME_SYNTAX, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UUID_NO_ADDRESS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_DUPLICATE_ENDPOINT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNKNOWN_AUTHN_TYPE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_MAX_CALLS_TOO_SMALL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_STRING_TOO_LONG, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_PROTSEQ_NOT_FOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_PROCNUM_OUT_OF_RANGE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_BINDING_HAS_NO_AUTH, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNKNOWN_AUTHN_SERVICE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNKNOWN_AUTHN_LEVEL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_AUTH_IDENTITY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNKNOWN_AUTHZ_SERVICE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(EPT_S_INVALID_ENTRY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(EPT_S_CANT_PERFORM_OP, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(EPT_S_NOT_REGISTERED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NOTHING_TO_EXPORT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INCOMPLETE_NAME, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_VERS_OPTION, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_MORE_MEMBERS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NOT_ALL_OBJS_UNEXPORTED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INTERFACE_NOT_FOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ENTRY_ALREADY_EXISTS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ENTRY_NOT_FOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NAME_SERVICE_UNAVAILABLE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_NAF_ID, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_CANNOT_SUPPORT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_CONTEXT_AVAILABLE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INTERNAL_ERROR, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ZERO_DIVIDE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ADDRESS_ERROR, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_FP_DIV_ZERO, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_FP_UNDERFLOW, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_FP_OVERFLOW, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_NO_MORE_ENTRIES, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_SS_CHAR_TRANS_OPEN_FAIL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_SS_CHAR_TRANS_SHORT_FILE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_SS_IN_NULL_CONTEXT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_SS_CONTEXT_DAMAGED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_SS_HANDLES_MISMATCH, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_SS_CANNOT_GET_CALL_HANDLE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_NULL_REF_POINTER, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_ENUM_VALUE_OUT_OF_RANGE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_BYTE_COUNT_TOO_SMALL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_BAD_STUB_DATA, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_INTERFACES, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_CALL_CANCELLED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_BINDING_INCOMPLETE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_COMM_FAILURE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNSUPPORTED_AUTHN_LEVEL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NO_PRINC_NAME, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NOT_RPC_ERROR, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UUID_LOCAL_ONLY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_SEC_PKG_ERROR, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_NOT_CANCELLED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_INVALID_ES_ACTION, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_WRONG_ES_VERSION, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_WRONG_STUB_VERSION, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_INVALID_PIPE_OBJECT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_WRONG_PIPE_ORDER, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_WRONG_PIPE_VERSION, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_COOKIE_AUTH_FAILED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_GROUP_MEMBER_NOT_FOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(EPT_S_CANT_CREATE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_OBJECT, CAT_GATEWAY) +}; + +static const RPC_FAULT_CODE RPC_TSG_FAULT_CODES[] = { + DEFINE_RPC_FAULT_CODE(RPC_S_OK, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_ARG, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_OUT_OF_MEMORY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_OUT_OF_THREADS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_LEVEL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_BUFFER_TOO_SMALL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_INVALID_SECURITY_DESC, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ACCESS_DENIED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_SERVER_OUT_OF_MEMORY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_ASYNC_CALL_PENDING, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_UNKNOWN_PRINCIPAL, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_S_TIMEOUT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_NO_MEMORY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_INVALID_BOUND, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_INVALID_TAG, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_ENUM_VALUE_TOO_LARGE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_SS_CONTEXT_MISMATCH, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_INVALID_BUFFER, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_PIPE_APP_MEMORY, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(RPC_X_INVALID_PIPE_OPERATION, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(ERROR_ONLY_IF_CONNECTED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(ERROR_GRACEFUL_DISCONNECT, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(ERROR_OPERATION_ABORTED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(ERROR_BAD_ARGUMENTS, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_INTERNALERROR, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_RAP_ACCESSDENIED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_NAP_ACCESSDENIED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_TS_CONNECTFAILED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_ALREADYDISCONNECTED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_QUARANTINE_ACCESSDENIED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_NOCERTAVAILABLE, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_COOKIE_BADPACKET, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_COOKIE_AUTHENTICATION_ACCESS_DENIED, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_UNSUPPORTED_AUTHENTICATION_METHOD, CAT_GATEWAY), + DEFINE_RPC_FAULT_CODE(E_PROXY_CAPABILITYMISMATCH, CAT_GATEWAY), + { HRESULT_CODE(E_PROXY_NOTSUPPORTED), "E_PROXY_NOTSUPPORTED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_TS_CONNECTFAILED), "E_PROXY_TS_CONNECTFAILED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_MAXCONNECTIONSREACHED), "E_PROXY_MAXCONNECTIONSREACHED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_INTERNALERROR), "E_PROXY_INTERNALERROR", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_SESSIONTIMEOUT), "E_PROXY_SESSIONTIMEOUT", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_REAUTH_AUTHN_FAILED), "E_PROXY_REAUTH_AUTHN_FAILED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_REAUTH_CAP_FAILED), "E_PROXY_REAUTH_CAP_FAILED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_REAUTH_RAP_FAILED), "E_PROXY_REAUTH_RAP_FAILED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_SDR_NOT_SUPPORTED_BY_TS), "E_PROXY_SDR_NOT_SUPPORTED_BY_TS", + CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_REAUTH_NAP_FAILED), "E_PROXY_REAUTH_NAP_FAILED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_CONNECTIONABORTED), "E_PROXY_CONNECTIONABORTED", CAT_GATEWAY }, + { HRESULT_CODE(E_PROXY_NOCERTAVAILABLE), "E_PROXY_NOCERTAVAILABLE", CAT_GATEWAY }, + { HRESULT_CODE(RPC_S_CALL_CANCELLED), "RPC_S_CALL_CANCELLED", CAT_GATEWAY } +}; + +/** + * [MS-RPCE] 3.1.1.5.5 Returning Win32 Error Values: + * http://msdn.microsoft.com/en-us/library/ee442005/ + */ + +static UINT32 rpc_map_status_code_to_win32_error_code(UINT32 code) +{ + switch (code) + { + case nca_s_comm_failure: + return RPC_S_COMM_FAILURE; + + case nca_s_op_rng_error: + return RPC_S_PROCNUM_OUT_OF_RANGE; + + case nca_s_unk_if: + return RPC_S_UNKNOWN_IF; + + case nca_s_wrong_boot_time: + return nca_s_wrong_boot_time; + + case nca_s_you_crashed: + return RPC_S_CALL_FAILED; + + case nca_s_proto_error: + return RPC_S_PROTOCOL_ERROR; + + case nca_s_out_args_too_big: + return RPC_S_SERVER_OUT_OF_MEMORY; + + case nca_s_server_too_busy: + return RPC_S_SERVER_TOO_BUSY; + + case nca_s_unsupported_type: + return RPC_S_UNSUPPORTED_TYPE; + + case nca_s_fault_int_div_by_zero: + return RPC_S_ZERO_DIVIDE; + + case nca_s_fault_addr_error: + return RPC_S_ADDRESS_ERROR; + + case nca_s_fault_fp_div_zero: + return RPC_S_FP_DIV_ZERO; + + case nca_s_fault_fp_underflow: + return RPC_S_FP_UNDERFLOW; + + case nca_s_fault_fp_overflow: + return RPC_S_FP_OVERFLOW; + + case nca_s_fault_invalid_tag: + return RPC_S_INVALID_TAG; + + case nca_s_fault_invalid_bound: + return RPC_S_INVALID_BOUND; + + case nca_s_rpc_version_mismatch: + return RPC_S_PROTOCOL_ERROR; + + case nca_s_unspec_reject: + return RPC_S_CALL_FAILED; + + case nca_s_bad_actid: + return RPC_S_CALL_FAILED_DNE; + + case nca_s_who_are_you_failed: + return RPC_S_CALL_FAILED; + + case nca_s_manager_not_entered: + return RPC_S_CALL_FAILED_DNE; + + case nca_s_fault_cancel: + return RPC_S_CALL_CANCELLED; + + case nca_s_fault_ill_inst: + return RPC_S_ADDRESS_ERROR; + + case nca_s_fault_fp_error: + return RPC_S_FP_OVERFLOW; + + case nca_s_fault_int_overflow: + return RPC_S_ADDRESS_ERROR; + + case nca_s_fault_unspec: + return RPC_S_CALL_FAILED; + + case nca_s_fault_remote_comm_failure: + return nca_s_fault_remote_comm_failure; + + case nca_s_fault_pipe_empty: + return RPC_X_PIPE_EMPTY; + + case nca_s_fault_pipe_closed: + return RPC_X_PIPE_CLOSED; + + case nca_s_fault_pipe_order: + return RPC_X_WRONG_PIPE_ORDER; + + case nca_s_fault_pipe_discipline: + return RPC_X_PIPE_DISCIPLINE_ERROR; + + case nca_s_fault_pipe_comm_error: + return RPC_S_COMM_FAILURE; + + case nca_s_fault_pipe_memory: + return RPC_S_OUT_OF_MEMORY; + + case nca_s_fault_context_mismatch: + return RPC_X_SS_CONTEXT_MISMATCH; + + case nca_s_fault_remote_no_memory: + return RPC_S_SERVER_OUT_OF_MEMORY; + + case nca_s_invalid_pres_context_id: + return RPC_S_PROTOCOL_ERROR; + + case nca_s_unsupported_authn_level: + return RPC_S_UNSUPPORTED_AUTHN_LEVEL; + + case nca_s_invalid_checksum: + return RPC_S_CALL_FAILED_DNE; + + case nca_s_invalid_crc: + return RPC_S_CALL_FAILED_DNE; + + case nca_s_fault_user_defined: + return nca_s_fault_user_defined; + + case nca_s_fault_tx_open_failed: + return nca_s_fault_tx_open_failed; + + case nca_s_fault_codeset_conv_error: + return nca_s_fault_codeset_conv_error; + + case nca_s_fault_object_not_found: + return nca_s_fault_object_not_found; + + case nca_s_fault_no_client_stub: + return nca_s_fault_no_client_stub; + default: + break; + } + + return code; +} + +const char* rpc_error_to_string(UINT32 code) +{ + static char buffer[1024]; + + for (size_t index = 0; index < ARRAYSIZE(RPC_FAULT_CODES); index++) + { + const RPC_FAULT_CODE* current = &RPC_FAULT_CODES[index]; + if (current->code == code) + { + (void)sprintf_s(buffer, ARRAYSIZE(buffer), "%s", current->name); + goto out; + } + } + + for (size_t index = 0; index < ARRAYSIZE(RPC_TSG_FAULT_CODES); index++) + { + const RPC_FAULT_CODE* current = &RPC_TSG_FAULT_CODES[index]; + if (current->code == code) + { + (void)sprintf_s(buffer, ARRAYSIZE(buffer), "%s", current->name); + goto out; + } + } + + for (size_t index = 0; index < ARRAYSIZE(RPC_TSG_FAULT_CODES); index++) + { + const RPC_FAULT_CODE* current = &RPC_TSG_FAULT_CODES[index]; + if (current->code == HRESULT_CODE(code)) + { + (void)sprintf_s(buffer, ARRAYSIZE(buffer), "%s", current->name); + goto out; + } + } + + (void)sprintf_s(buffer, ARRAYSIZE(buffer), "%s [0x%08" PRIX32 "]", "UNKNOWN", code); +out: + return buffer; +} + +const char* rpc_error_to_category(UINT32 code) +{ + for (size_t index = 0; index < ARRAYSIZE(RPC_FAULT_CODES); index++) + { + const RPC_FAULT_CODE* current = &RPC_FAULT_CODES[index]; + if (current->code == code) + return current->category; + } + + for (size_t index = 0; index < ARRAYSIZE(RPC_TSG_FAULT_CODES); index++) + { + const RPC_FAULT_CODE* current = &RPC_TSG_FAULT_CODES[index]; + if (current->code == code) + return current->category; + } + + for (size_t index = 0; index < ARRAYSIZE(RPC_TSG_FAULT_CODES); index++) + { + const RPC_FAULT_CODE* current = &RPC_TSG_FAULT_CODES[index]; + if (current->code == HRESULT_CODE(code)) + return current->category; + } + + return "UNKNOWN"; +} + +int rpc_recv_fault_pdu(UINT32 status) +{ + UINT32 code = rpc_map_status_code_to_win32_error_code(status); + WLog_ERR(TAG, "RPC Fault PDU: status=%s", rpc_error_to_string(code)); + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_fault.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_fault.h new file mode 100644 index 0000000000000000000000000000000000000000..802a40ef6f6638f394982026ba4e41df9ac6c052 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rpc_fault.h @@ -0,0 +1,30 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * RPC Fault Handling + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_RPC_FAULT_H +#define FREERDP_LIB_CORE_GATEWAY_RPC_FAULT_H + +#include +#include + +FREERDP_LOCAL int rpc_recv_fault_pdu(UINT32 status); +FREERDP_LOCAL const char* rpc_error_to_string(UINT32 error); +FREERDP_LOCAL const char* rpc_error_to_category(UINT32 error); + +#endif /* FREERDP_LIB_CORE_GATEWAY_RPC_FAULT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts.c new file mode 100644 index 0000000000000000000000000000000000000000..3d7904089ea4158d4904e93326751c7efedfc8ef --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts.c @@ -0,0 +1,2392 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Request To Send (RTS) PDUs + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include + +#include "ncacn_http.h" +#include "rpc_client.h" +#include "rts_signature.h" + +#include "rts.h" + +#define TAG FREERDP_TAG("core.gateway.rts") + +/** + * RTS PDU Header + * + * The RTS PDU Header has the same layout as the common header of the connection-oriented RPC + * PDU as specified in [C706] section 12.6.1, with a few additional requirements around the contents + * of the header fields. The additional requirements are as follows: + * + * All fields MUST use little-endian byte order. + * + * Fragmentation MUST NOT occur for an RTS PDU. + * + * PFC_FIRST_FRAG and PFC_LAST_FRAG MUST be present in all RTS PDUs, and all other PFC flags + * MUST NOT be present. + * + * The rpc_vers and rpc_vers_minor fields MUST contain version information as described in + * [MS-RPCE] section 1.7. + * + * PTYPE MUST be set to a value of 20 (0x14). This field differentiates RTS packets from other RPC + * packets. + * + * The packed_drep MUST indicate little-endian integer and floating-pointer byte order, IEEE + * float-point format representation, and ASCII character format as specified in [C706] + * section 12.6. + * + * The auth_length MUST be set to 0. + * + * The frag_length field MUST reflect the size of the header plus the size of all commands, + * including the variable portion of variable-sized commands. + * + * The call_id MUST be set to 0 by senders and MUST be 0 on receipt. + * + */ + +static int rts_destination_command_read(rdpRpc* rpc, wStream* buffer, UINT32* Destination); + +static const char* rts_command_to_string(UINT32 cmd, char* buffer, size_t len) +{ + const char* str = NULL; + +#undef ENTRY +#define ENTRY(x) \ + case x: \ + str = "#x"; \ + break + + switch (cmd) + { + ENTRY(RTS_CMD_RECEIVE_WINDOW_SIZE); + ENTRY(RTS_CMD_FLOW_CONTROL_ACK); + ENTRY(RTS_CMD_CONNECTION_TIMEOUT); + ENTRY(RTS_CMD_COOKIE); + ENTRY(RTS_CMD_CHANNEL_LIFETIME); + ENTRY(RTS_CMD_CLIENT_KEEPALIVE); + ENTRY(RTS_CMD_VERSION); + ENTRY(RTS_CMD_EMPTY); + ENTRY(RTS_CMD_PADDING); + ENTRY(RTS_CMD_NEGATIVE_ANCE); + ENTRY(RTS_CMD_ANCE); + ENTRY(RTS_CMD_CLIENT_ADDRESS); + ENTRY(RTS_CMD_ASSOCIATION_GROUP_ID); + ENTRY(RTS_CMD_DESTINATION); + ENTRY(RTS_CMD_PING_TRAFFIC_SENT_NOTIFY); + ENTRY(RTS_CMD_LAST_ID); + default: + str = "RTS_CMD_UNKNOWN"; + break; + } + +#undef ENTRY + + (void)_snprintf(buffer, len, "%s [0x%08" PRIx32 "]", str, cmd); + return buffer; +} + +static const char* rts_pdu_ptype_to_string(UINT32 ptype) +{ + switch (ptype) + { + case PTYPE_REQUEST: + return "PTYPE_REQUEST"; + case PTYPE_PING: + return "PTYPE_PING"; + case PTYPE_RESPONSE: + return "PTYPE_RESPONSE"; + case PTYPE_FAULT: + return "PTYPE_FAULT"; + case PTYPE_WORKING: + return "PTYPE_WORKING"; + case PTYPE_NOCALL: + return "PTYPE_NOCALL"; + case PTYPE_REJECT: + return "PTYPE_REJECT"; + case PTYPE_ACK: + return "PTYPE_ACK"; + case PTYPE_CL_CANCEL: + return "PTYPE_CL_CANCEL"; + case PTYPE_FACK: + return "PTYPE_FACK"; + case PTYPE_CANCEL_ACK: + return "PTYPE_CANCEL_ACK"; + case PTYPE_BIND: + return "PTYPE_BIND"; + case PTYPE_BIND_ACK: + return "PTYPE_BIND_ACK"; + case PTYPE_BIND_NAK: + return "PTYPE_BIND_NAK"; + case PTYPE_ALTER_CONTEXT: + return "PTYPE_ALTER_CONTEXT"; + case PTYPE_ALTER_CONTEXT_RESP: + return "PTYPE_ALTER_CONTEXT_RESP"; + case PTYPE_RPC_AUTH_3: + return "PTYPE_RPC_AUTH_3"; + case PTYPE_SHUTDOWN: + return "PTYPE_SHUTDOWN"; + case PTYPE_CO_CANCEL: + return "PTYPE_CO_CANCEL"; + case PTYPE_ORPHANED: + return "PTYPE_ORPHANED"; + case PTYPE_RTS: + return "PTYPE_RTS"; + default: + return "UNKNOWN"; + } +} + +static rpcconn_rts_hdr_t rts_pdu_header_init(void) +{ + rpcconn_rts_hdr_t header = { 0 }; + header.header.rpc_vers = 5; + header.header.rpc_vers_minor = 0; + header.header.ptype = PTYPE_RTS; + header.header.packed_drep[0] = 0x10; + header.header.packed_drep[1] = 0x00; + header.header.packed_drep[2] = 0x00; + header.header.packed_drep[3] = 0x00; + header.header.pfc_flags = PFC_FIRST_FRAG | PFC_LAST_FRAG; + header.header.auth_length = 0; + header.header.call_id = 0; + + return header; +} + +static BOOL rts_align_stream(wStream* s, size_t alignment, BOOL silent) +{ + size_t pos = 0; + size_t pad = 0; + + WINPR_ASSERT(s); + WINPR_ASSERT(alignment > 0); + + pos = Stream_GetPosition(s); + pad = rpc_offset_align(&pos, alignment); + return Stream_ConditionalSafeSeek(s, pad, silent); +} + +static char* sdup(const void* src, size_t length) +{ + char* dst = NULL; + WINPR_ASSERT(src || (length == 0)); + if (length == 0) + return NULL; + + dst = calloc(length + 1, sizeof(char)); + if (!dst) + return NULL; + memcpy(dst, src, length); + return dst; +} + +static BOOL rts_write_common_pdu_header(wStream* s, const rpcconn_common_hdr_t* header) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(header); + if (!Stream_EnsureRemainingCapacity(s, sizeof(rpcconn_common_hdr_t))) + return FALSE; + + Stream_Write_UINT8(s, header->rpc_vers); + Stream_Write_UINT8(s, header->rpc_vers_minor); + Stream_Write_UINT8(s, header->ptype); + Stream_Write_UINT8(s, header->pfc_flags); + Stream_Write(s, header->packed_drep, ARRAYSIZE(header->packed_drep)); + Stream_Write_UINT16(s, header->frag_length); + Stream_Write_UINT16(s, header->auth_length); + Stream_Write_UINT32(s, header->call_id); + return TRUE; +} + +BOOL rts_read_common_pdu_header(wStream* s, rpcconn_common_hdr_t* header, BOOL ignoreErrors) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(header); + + if (!ignoreErrors) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, sizeof(rpcconn_common_hdr_t))) + return FALSE; + } + else + { + const size_t sz = Stream_GetRemainingLength(s); + if (sz < sizeof(rpcconn_common_hdr_t)) + return FALSE; + } + + Stream_Read_UINT8(s, header->rpc_vers); + Stream_Read_UINT8(s, header->rpc_vers_minor); + Stream_Read_UINT8(s, header->ptype); + Stream_Read_UINT8(s, header->pfc_flags); + Stream_Read(s, header->packed_drep, ARRAYSIZE(header->packed_drep)); + Stream_Read_UINT16(s, header->frag_length); + Stream_Read_UINT16(s, header->auth_length); + Stream_Read_UINT32(s, header->call_id); + + if (header->frag_length < sizeof(rpcconn_common_hdr_t)) + { + if (!ignoreErrors) + WLog_WARN(TAG, "Invalid header->frag_length of %" PRIu16 ", expected %" PRIuz, + header->frag_length, sizeof(rpcconn_common_hdr_t)); + return FALSE; + } + + if (!ignoreErrors) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, + header->frag_length - sizeof(rpcconn_common_hdr_t))) + return FALSE; + } + else + { + const size_t sz2 = Stream_GetRemainingLength(s); + if (sz2 < header->frag_length - sizeof(rpcconn_common_hdr_t)) + return FALSE; + } + return TRUE; +} + +static BOOL rts_read_auth_verifier_no_checks(wStream* s, auth_verifier_co_t* auth, + const rpcconn_common_hdr_t* header, size_t* startPos, + BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(auth); + WINPR_ASSERT(header); + + WINPR_ASSERT(header->frag_length > header->auth_length + 8); + + if (startPos) + *startPos = Stream_GetPosition(s); + + /* Read the auth verifier and check padding matches frag_length */ + { + const size_t expected = header->frag_length - header->auth_length - 8; + + Stream_SetPosition(s, expected); + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 8, silent)) + return FALSE; + + Stream_Read_UINT8(s, auth->auth_type); + Stream_Read_UINT8(s, auth->auth_level); + Stream_Read_UINT8(s, auth->auth_pad_length); + Stream_Read_UINT8(s, auth->auth_reserved); + Stream_Read_UINT32(s, auth->auth_context_id); + } + + if (header->auth_length != 0) + { + const void* ptr = Stream_Pointer(s); + if (!Stream_ConditionalSafeSeek(s, header->auth_length, silent)) + return FALSE; + auth->auth_value = (BYTE*)sdup(ptr, header->auth_length); + if (auth->auth_value == NULL) + return FALSE; + } + + return TRUE; +} + +static BOOL rts_read_auth_verifier(wStream* s, auth_verifier_co_t* auth, + const rpcconn_common_hdr_t* header, BOOL silent) +{ + size_t pos = 0; + WINPR_ASSERT(s); + WINPR_ASSERT(auth); + WINPR_ASSERT(header); + + if (!rts_read_auth_verifier_no_checks(s, auth, header, &pos, silent)) + return FALSE; + + const size_t expected = header->frag_length - header->auth_length - 8; + WINPR_ASSERT(pos + auth->auth_pad_length == expected); + return pos + auth->auth_pad_length == expected; +} + +static BOOL rts_read_auth_verifier_with_stub(wStream* s, auth_verifier_co_t* auth, + rpcconn_common_hdr_t* header, BOOL silent) +{ + size_t pos = 0; + size_t alloc_hint = 0; + BYTE** ptr = NULL; + + if (!rts_read_auth_verifier_no_checks(s, auth, header, &pos, silent)) + return FALSE; + + switch (header->ptype) + { + case PTYPE_FAULT: + { + rpcconn_fault_hdr_t* hdr = (rpcconn_fault_hdr_t*)header; + alloc_hint = hdr->alloc_hint; + ptr = &hdr->stub_data; + } + break; + case PTYPE_RESPONSE: + { + rpcconn_response_hdr_t* hdr = (rpcconn_response_hdr_t*)header; + alloc_hint = hdr->alloc_hint; + ptr = &hdr->stub_data; + } + break; + case PTYPE_REQUEST: + { + rpcconn_request_hdr_t* hdr = (rpcconn_request_hdr_t*)header; + alloc_hint = hdr->alloc_hint; + ptr = &hdr->stub_data; + } + break; + default: + return FALSE; + } + + if (alloc_hint > 0) + { + const size_t off = header->auth_length + 8 + auth->auth_pad_length + pos; + const size_t size = header->frag_length - MIN(header->frag_length, off); + const void* src = Stream_Buffer(s) + pos; + + if (off > header->frag_length) + WLog_WARN(TAG, + "Unexpected alloc_hint(%" PRIuz ") for PDU %s: size %" PRIuz + ", offset %" PRIuz, + alloc_hint, rts_pdu_ptype_to_string(header->ptype), header->frag_length, off); + *ptr = (BYTE*)sdup(src, size); + if (!*ptr) + return FALSE; + } + + return TRUE; +} + +static void rts_free_auth_verifier(auth_verifier_co_t* auth) +{ + if (!auth) + return; + free(auth->auth_value); +} + +static BOOL rts_write_auth_verifier(wStream* s, const auth_verifier_co_t* auth, + const rpcconn_common_hdr_t* header) +{ + size_t pos = 0; + UINT8 auth_pad_length = 0; + + WINPR_ASSERT(s); + WINPR_ASSERT(auth); + WINPR_ASSERT(header); + + /* Align start to a multiple of 4 */ + pos = Stream_GetPosition(s); + if ((pos % 4) != 0) + { + auth_pad_length = 4 - (pos % 4); + if (!Stream_EnsureRemainingCapacity(s, auth_pad_length)) + return FALSE; + Stream_Zero(s, auth_pad_length); + } + +#if defined(WITH_VERBOSE_WINPR_ASSERT) && (WITH_VERBOSE_WINPR_ASSERT != 0) + WINPR_ASSERT(header->frag_length + 8ull > header->auth_length); + { + size_t apos = Stream_GetPosition(s); + size_t expected = header->frag_length - header->auth_length - 8; + + WINPR_ASSERT(apos == expected); + } +#endif + + if (!Stream_EnsureRemainingCapacity(s, sizeof(auth_verifier_co_t))) + return FALSE; + + Stream_Write_UINT8(s, auth->auth_type); + Stream_Write_UINT8(s, auth->auth_level); + Stream_Write_UINT8(s, auth_pad_length); + Stream_Write_UINT8(s, 0); /* auth->auth_reserved */ + Stream_Write_UINT32(s, auth->auth_context_id); + + if (!Stream_EnsureRemainingCapacity(s, header->auth_length)) + return FALSE; + Stream_Write(s, auth->auth_value, header->auth_length); + return TRUE; +} + +static BOOL rts_read_version(wStream* s, p_rt_version_t* version, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(version); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 2 * sizeof(UINT8), silent)) + return FALSE; + Stream_Read_UINT8(s, version->major); + Stream_Read_UINT8(s, version->minor); + return TRUE; +} + +static void rts_free_supported_versions(p_rt_versions_supported_t* versions) +{ + if (!versions) + return; + free(versions->p_protocols); + versions->p_protocols = NULL; +} + +static BOOL rts_read_supported_versions(wStream* s, p_rt_versions_supported_t* versions, + BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(versions); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, sizeof(UINT8), silent)) + return FALSE; + + Stream_Read_UINT8(s, versions->n_protocols); /* count */ + + if (versions->n_protocols > 0) + { + versions->p_protocols = calloc(versions->n_protocols, sizeof(p_rt_version_t)); + if (!versions->p_protocols) + return FALSE; + } + for (BYTE x = 0; x < versions->n_protocols; x++) + { + p_rt_version_t* version = &versions->p_protocols[x]; + if (!rts_read_version(s, version, silent)) /* size_is(n_protocols) */ + { + rts_free_supported_versions(versions); + return FALSE; + } + } + + return TRUE; +} + +static BOOL rts_read_port_any(wStream* s, port_any_t* port, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(port); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, sizeof(UINT16), silent)) + return FALSE; + + Stream_Read_UINT16(s, port->length); + if (port->length == 0) + return TRUE; + + const void* ptr = Stream_ConstPointer(s); + if (!Stream_ConditionalSafeSeek(s, port->length, silent)) + return FALSE; + port->port_spec = sdup(ptr, port->length); + return port->port_spec != NULL; +} + +static void rts_free_port_any(port_any_t* port) +{ + if (!port) + return; + free(port->port_spec); +} + +static BOOL rts_read_uuid(wStream* s, p_uuid_t* uuid, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(uuid); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, sizeof(p_uuid_t), silent)) + return FALSE; + + Stream_Read_UINT32(s, uuid->time_low); + Stream_Read_UINT16(s, uuid->time_mid); + Stream_Read_UINT16(s, uuid->time_hi_and_version); + Stream_Read_UINT8(s, uuid->clock_seq_hi_and_reserved); + Stream_Read_UINT8(s, uuid->clock_seq_low); + Stream_Read(s, uuid->node, ARRAYSIZE(uuid->node)); + return TRUE; +} + +static BOOL rts_write_uuid(wStream* s, const p_uuid_t* uuid) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(uuid); + + if (!Stream_EnsureRemainingCapacity(s, sizeof(p_uuid_t))) + return FALSE; + + Stream_Write_UINT32(s, uuid->time_low); + Stream_Write_UINT16(s, uuid->time_mid); + Stream_Write_UINT16(s, uuid->time_hi_and_version); + Stream_Write_UINT8(s, uuid->clock_seq_hi_and_reserved); + Stream_Write_UINT8(s, uuid->clock_seq_low); + Stream_Write(s, uuid->node, ARRAYSIZE(uuid->node)); + return TRUE; +} + +static p_syntax_id_t* rts_syntax_id_new(size_t count) +{ + return calloc(count, sizeof(p_syntax_id_t)); +} + +static void rts_syntax_id_free(p_syntax_id_t* ptr) +{ + free(ptr); +} + +static BOOL rts_read_syntax_id(wStream* s, p_syntax_id_t* syntax_id, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(syntax_id); + + if (!rts_read_uuid(s, &syntax_id->if_uuid, silent)) + return FALSE; + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 4, silent)) + return FALSE; + + Stream_Read_UINT32(s, syntax_id->if_version); + return TRUE; +} + +static BOOL rts_write_syntax_id(wStream* s, const p_syntax_id_t* syntax_id) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(syntax_id); + + if (!rts_write_uuid(s, &syntax_id->if_uuid)) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + + Stream_Write_UINT32(s, syntax_id->if_version); + return TRUE; +} + +static p_cont_elem_t* rts_context_elem_new(size_t count) +{ + p_cont_elem_t* ctx = calloc(count, sizeof(p_cont_elem_t)); + return ctx; +} + +static void rts_context_elem_free(p_cont_elem_t* ptr) +{ + if (!ptr) + return; + rts_syntax_id_free(ptr->transfer_syntaxes); + free(ptr); +} + +static BOOL rts_read_context_elem(wStream* s, p_cont_elem_t* element, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(element); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 4, silent)) + return FALSE; + + Stream_Read_UINT16(s, element->p_cont_id); + Stream_Read_UINT8(s, element->n_transfer_syn); /* number of items */ + Stream_Read_UINT8(s, element->reserved); /* alignment pad, m.b.z. */ + + if (!rts_read_syntax_id(s, &element->abstract_syntax, silent)) /* transfer syntax list */ + return FALSE; + + if (element->n_transfer_syn > 0) + { + element->transfer_syntaxes = rts_syntax_id_new(element->n_transfer_syn); + if (!element->transfer_syntaxes) + return FALSE; + for (BYTE x = 0; x < element->n_transfer_syn; x++) + { + p_syntax_id_t* syn = &element->transfer_syntaxes[x]; + if (!rts_read_syntax_id(s, syn, silent)) /* size_is(n_transfer_syn) */ + return FALSE; + } + } + + return TRUE; +} + +static BOOL rts_write_context_elem(wStream* s, const p_cont_elem_t* element) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(element); + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + Stream_Write_UINT16(s, element->p_cont_id); + Stream_Write_UINT8(s, element->n_transfer_syn); /* number of items */ + Stream_Write_UINT8(s, element->reserved); /* alignment pad, m.b.z. */ + if (!rts_write_syntax_id(s, &element->abstract_syntax)) /* transfer syntax list */ + return FALSE; + + for (BYTE x = 0; x < element->n_transfer_syn; x++) + { + const p_syntax_id_t* syn = &element->transfer_syntaxes[x]; + if (!rts_write_syntax_id(s, syn)) /* size_is(n_transfer_syn) */ + return FALSE; + } + + return TRUE; +} + +static BOOL rts_read_context_list(wStream* s, p_cont_list_t* list, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(list); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 4, silent)) + return FALSE; + Stream_Read_UINT8(s, list->n_context_elem); /* number of items */ + Stream_Read_UINT8(s, list->reserved); /* alignment pad, m.b.z. */ + Stream_Read_UINT16(s, list->reserved2); /* alignment pad, m.b.z. */ + + if (list->n_context_elem > 0) + { + list->p_cont_elem = rts_context_elem_new(list->n_context_elem); + if (!list->p_cont_elem) + return FALSE; + for (BYTE x = 0; x < list->n_context_elem; x++) + { + p_cont_elem_t* element = &list->p_cont_elem[x]; + if (!rts_read_context_elem(s, element, silent)) + return FALSE; + } + } + return TRUE; +} + +static void rts_free_context_list(p_cont_list_t* list) +{ + if (!list) + return; + rts_context_elem_free(list->p_cont_elem); +} + +static BOOL rts_write_context_list(wStream* s, const p_cont_list_t* list) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(list); + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + Stream_Write_UINT8(s, list->n_context_elem); /* number of items */ + Stream_Write_UINT8(s, 0); /* alignment pad, m.b.z. */ + Stream_Write_UINT16(s, 0); /* alignment pad, m.b.z. */ + + for (BYTE x = 0; x < list->n_context_elem; x++) + { + const p_cont_elem_t* element = &list->p_cont_elem[x]; + if (!rts_write_context_elem(s, element)) + return FALSE; + } + return TRUE; +} + +static p_result_t* rts_result_new(size_t count) +{ + return calloc(count, sizeof(p_result_t)); +} + +static void rts_result_free(p_result_t* results) +{ + if (!results) + return; + free(results); +} + +static BOOL rts_read_result(wStream* s, p_result_t* result, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(result); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 2, silent)) + return FALSE; + Stream_Read_UINT16(s, result->result); + Stream_Read_UINT16(s, result->reason); + + return rts_read_syntax_id(s, &result->transfer_syntax, silent); +} + +static void rts_free_result(p_result_t* result) +{ + if (!result) + return; +} + +static BOOL rts_read_result_list(wStream* s, p_result_list_t* list, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(list); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 4, silent)) + return FALSE; + Stream_Read_UINT8(s, list->n_results); /* count */ + Stream_Read_UINT8(s, list->reserved); /* alignment pad, m.b.z. */ + Stream_Read_UINT16(s, list->reserved2); /* alignment pad, m.b.z. */ + + if (list->n_results > 0) + { + list->p_results = rts_result_new(list->n_results); + if (!list->p_results) + return FALSE; + + for (BYTE x = 0; x < list->n_results; x++) + { + p_result_t* result = &list->p_results[x]; /* size_is(n_results) */ + if (!rts_read_result(s, result, silent)) + return FALSE; + } + } + + return TRUE; +} + +static void rts_free_result_list(p_result_list_t* list) +{ + if (!list) + return; + for (BYTE x = 0; x < list->n_results; x++) + { + p_result_t* result = &list->p_results[x]; + rts_free_result(result); + } + rts_result_free(list->p_results); +} + +static void rts_free_pdu_alter_context(rpcconn_alter_context_hdr_t* ctx) +{ + if (!ctx) + return; + + rts_free_context_list(&ctx->p_context_elem); + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_alter_context(wStream* s, rpcconn_alter_context_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_alter_context_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + + Stream_Read_UINT16(s, ctx->max_xmit_frag); + Stream_Read_UINT16(s, ctx->max_recv_frag); + Stream_Read_UINT32(s, ctx->assoc_group_id); + + if (!rts_read_context_list(s, &ctx->p_context_elem, silent)) + return FALSE; + + if (!rts_read_auth_verifier(s, &ctx->auth_verifier, &ctx->header, silent)) + return FALSE; + + return TRUE; +} + +static BOOL rts_read_pdu_alter_context_response(wStream* s, + rpcconn_alter_context_response_hdr_t* ctx, + BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_alter_context_response_hdr_t) - sizeof(rpcconn_common_hdr_t), + silent)) + return FALSE; + Stream_Read_UINT16(s, ctx->max_xmit_frag); + Stream_Read_UINT16(s, ctx->max_recv_frag); + Stream_Read_UINT32(s, ctx->assoc_group_id); + + if (!rts_read_port_any(s, &ctx->sec_addr, silent)) + return FALSE; + + if (!rts_align_stream(s, 4, silent)) + return FALSE; + + if (!rts_read_result_list(s, &ctx->p_result_list, silent)) + return FALSE; + + if (!rts_read_auth_verifier(s, &ctx->auth_verifier, &ctx->header, silent)) + return FALSE; + + return TRUE; +} + +static void rts_free_pdu_alter_context_response(rpcconn_alter_context_response_hdr_t* ctx) +{ + if (!ctx) + return; + + rts_free_port_any(&ctx->sec_addr); + rts_free_result_list(&ctx->p_result_list); + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_bind(wStream* s, rpcconn_bind_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_bind_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + Stream_Read_UINT16(s, ctx->max_xmit_frag); + Stream_Read_UINT16(s, ctx->max_recv_frag); + Stream_Read_UINT32(s, ctx->assoc_group_id); + + if (!rts_read_context_list(s, &ctx->p_context_elem, silent)) + return FALSE; + + if (!rts_read_auth_verifier(s, &ctx->auth_verifier, &ctx->header, silent)) + return FALSE; + + return TRUE; +} + +static void rts_free_pdu_bind(rpcconn_bind_hdr_t* ctx) +{ + if (!ctx) + return; + rts_free_context_list(&ctx->p_context_elem); + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_bind_ack(wStream* s, rpcconn_bind_ack_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_CheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_bind_ack_hdr_t) - sizeof(rpcconn_common_hdr_t))) + return FALSE; + Stream_Read_UINT16(s, ctx->max_xmit_frag); + Stream_Read_UINT16(s, ctx->max_recv_frag); + Stream_Read_UINT32(s, ctx->assoc_group_id); + + if (!rts_read_port_any(s, &ctx->sec_addr, silent)) + return FALSE; + + if (!rts_align_stream(s, 4, silent)) + return FALSE; + + if (!rts_read_result_list(s, &ctx->p_result_list, silent)) + return FALSE; + + return rts_read_auth_verifier(s, &ctx->auth_verifier, &ctx->header, silent); +} + +static void rts_free_pdu_bind_ack(rpcconn_bind_ack_hdr_t* ctx) +{ + if (!ctx) + return; + rts_free_port_any(&ctx->sec_addr); + rts_free_result_list(&ctx->p_result_list); + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_bind_nak(wStream* s, rpcconn_bind_nak_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_bind_nak_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + Stream_Read_UINT16(s, ctx->provider_reject_reason); + return rts_read_supported_versions(s, &ctx->versions, silent); +} + +static void rts_free_pdu_bind_nak(rpcconn_bind_nak_hdr_t* ctx) +{ + if (!ctx) + return; + + rts_free_supported_versions(&ctx->versions); +} + +static BOOL rts_read_pdu_auth3(wStream* s, rpcconn_rpc_auth_3_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_rpc_auth_3_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + Stream_Read_UINT16(s, ctx->max_xmit_frag); + Stream_Read_UINT16(s, ctx->max_recv_frag); + + return rts_read_auth_verifier(s, &ctx->auth_verifier, &ctx->header, silent); +} + +static void rts_free_pdu_auth3(rpcconn_rpc_auth_3_hdr_t* ctx) +{ + if (!ctx) + return; + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_fault(wStream* s, rpcconn_fault_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 12, silent)) + return FALSE; + Stream_Read_UINT32(s, ctx->alloc_hint); + Stream_Read_UINT16(s, ctx->p_cont_id); + Stream_Read_UINT8(s, ctx->cancel_count); + Stream_Read_UINT8(s, ctx->reserved); + Stream_Read_UINT32(s, ctx->status); + + WLog_WARN(TAG, "status=%s", Win32ErrorCode2Tag(ctx->status & 0xFFFF)); + return rts_read_auth_verifier_with_stub(s, &ctx->auth_verifier, &ctx->header, silent); +} + +static void rts_free_pdu_fault(rpcconn_fault_hdr_t* ctx) +{ + if (!ctx) + return; + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_cancel_ack(wStream* s, rpcconn_cancel_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_cancel_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + return rts_read_auth_verifier(s, &ctx->auth_verifier, &ctx->header, silent); +} + +static void rts_free_pdu_cancel_ack(rpcconn_cancel_hdr_t* ctx) +{ + if (!ctx) + return; + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_orphaned(wStream* s, rpcconn_orphaned_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_orphaned_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + return rts_read_auth_verifier(s, &ctx->auth_verifier, &ctx->header, silent); +} + +static void rts_free_pdu_orphaned(rpcconn_orphaned_hdr_t* ctx) +{ + if (!ctx) + return; + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_request(wStream* s, rpcconn_request_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_request_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + Stream_Read_UINT32(s, ctx->alloc_hint); + Stream_Read_UINT16(s, ctx->p_cont_id); + Stream_Read_UINT16(s, ctx->opnum); + if (!rts_read_uuid(s, &ctx->object, silent)) + return FALSE; + + return rts_read_auth_verifier_with_stub(s, &ctx->auth_verifier, &ctx->header, silent); +} + +static void rts_free_pdu_request(rpcconn_request_hdr_t* ctx) +{ + if (!ctx) + return; + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_response(wStream* s, rpcconn_response_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_response_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + Stream_Read_UINT32(s, ctx->alloc_hint); + Stream_Read_UINT16(s, ctx->p_cont_id); + Stream_Read_UINT8(s, ctx->cancel_count); + Stream_Read_UINT8(s, ctx->reserved); + + if (!rts_align_stream(s, 8, silent)) + return FALSE; + + return rts_read_auth_verifier_with_stub(s, &ctx->auth_verifier, &ctx->header, silent); +} + +static void rts_free_pdu_response(rpcconn_response_hdr_t* ctx) +{ + if (!ctx) + return; + free(ctx->stub_data); + rts_free_auth_verifier(&ctx->auth_verifier); +} + +static BOOL rts_read_pdu_rts(wStream* s, rpcconn_rts_hdr_t* ctx, BOOL silent) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(ctx); + + if (!Stream_ConditionalCheckAndLogRequiredLength( + TAG, s, sizeof(rpcconn_rts_hdr_t) - sizeof(rpcconn_common_hdr_t), silent)) + return FALSE; + + Stream_Read_UINT16(s, ctx->Flags); + Stream_Read_UINT16(s, ctx->NumberOfCommands); + return TRUE; +} + +static void rts_free_pdu_rts(rpcconn_rts_hdr_t* ctx) +{ + WINPR_UNUSED(ctx); +} + +void rts_free_pdu_header(rpcconn_hdr_t* header, BOOL allocated) +{ + if (!header) + return; + + switch (header->common.ptype) + { + case PTYPE_ALTER_CONTEXT: + rts_free_pdu_alter_context(&header->alter_context); + break; + case PTYPE_ALTER_CONTEXT_RESP: + rts_free_pdu_alter_context_response(&header->alter_context_response); + break; + case PTYPE_BIND: + rts_free_pdu_bind(&header->bind); + break; + case PTYPE_BIND_ACK: + rts_free_pdu_bind_ack(&header->bind_ack); + break; + case PTYPE_BIND_NAK: + rts_free_pdu_bind_nak(&header->bind_nak); + break; + case PTYPE_RPC_AUTH_3: + rts_free_pdu_auth3(&header->rpc_auth_3); + break; + case PTYPE_CANCEL_ACK: + rts_free_pdu_cancel_ack(&header->cancel); + break; + case PTYPE_FAULT: + rts_free_pdu_fault(&header->fault); + break; + case PTYPE_ORPHANED: + rts_free_pdu_orphaned(&header->orphaned); + break; + case PTYPE_REQUEST: + rts_free_pdu_request(&header->request); + break; + case PTYPE_RESPONSE: + rts_free_pdu_response(&header->response); + break; + case PTYPE_RTS: + rts_free_pdu_rts(&header->rts); + break; + /* No extra fields */ + case PTYPE_SHUTDOWN: + break; + + /* not handled */ + case PTYPE_PING: + case PTYPE_WORKING: + case PTYPE_NOCALL: + case PTYPE_REJECT: + case PTYPE_ACK: + case PTYPE_CL_CANCEL: + case PTYPE_FACK: + case PTYPE_CO_CANCEL: + default: + break; + } + + if (allocated) + free(header); +} + +BOOL rts_read_pdu_header(wStream* s, rpcconn_hdr_t* header) +{ + return rts_read_pdu_header_ex(s, header, FALSE); +} + +BOOL rts_read_pdu_header_ex(wStream* s, rpcconn_hdr_t* header, BOOL silent) +{ + BOOL rc = FALSE; + WINPR_ASSERT(s); + WINPR_ASSERT(header); + + if (!rts_read_common_pdu_header(s, &header->common, silent)) + return FALSE; + + WLog_DBG(TAG, "Reading PDU type %s", rts_pdu_ptype_to_string(header->common.ptype)); + + switch (header->common.ptype) + { + case PTYPE_ALTER_CONTEXT: + rc = rts_read_pdu_alter_context(s, &header->alter_context, silent); + break; + case PTYPE_ALTER_CONTEXT_RESP: + rc = rts_read_pdu_alter_context_response(s, &header->alter_context_response, silent); + break; + case PTYPE_BIND: + rc = rts_read_pdu_bind(s, &header->bind, silent); + break; + case PTYPE_BIND_ACK: + rc = rts_read_pdu_bind_ack(s, &header->bind_ack, silent); + break; + case PTYPE_BIND_NAK: + rc = rts_read_pdu_bind_nak(s, &header->bind_nak, silent); + break; + case PTYPE_RPC_AUTH_3: + rc = rts_read_pdu_auth3(s, &header->rpc_auth_3, silent); + break; + case PTYPE_CANCEL_ACK: + rc = rts_read_pdu_cancel_ack(s, &header->cancel, silent); + break; + case PTYPE_FAULT: + rc = rts_read_pdu_fault(s, &header->fault, silent); + break; + case PTYPE_ORPHANED: + rc = rts_read_pdu_orphaned(s, &header->orphaned, silent); + break; + case PTYPE_REQUEST: + rc = rts_read_pdu_request(s, &header->request, silent); + break; + case PTYPE_RESPONSE: + rc = rts_read_pdu_response(s, &header->response, silent); + break; + case PTYPE_RTS: + rc = rts_read_pdu_rts(s, &header->rts, silent); + break; + case PTYPE_SHUTDOWN: + rc = TRUE; /* No extra fields */ + break; + + /* not handled */ + case PTYPE_PING: + case PTYPE_WORKING: + case PTYPE_NOCALL: + case PTYPE_REJECT: + case PTYPE_ACK: + case PTYPE_CL_CANCEL: + case PTYPE_FACK: + case PTYPE_CO_CANCEL: + default: + break; + } + + return rc; +} + +static BOOL rts_write_pdu_header(wStream* s, const rpcconn_rts_hdr_t* header) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(header); + if (!Stream_EnsureRemainingCapacity(s, sizeof(rpcconn_rts_hdr_t))) + return FALSE; + + if (!rts_write_common_pdu_header(s, &header->header)) + return FALSE; + + Stream_Write_UINT16(s, header->Flags); + Stream_Write_UINT16(s, header->NumberOfCommands); + return TRUE; +} + +static BOOL rts_receive_window_size_command_read(rdpRpc* rpc, wStream* buffer, + UINT64* ReceiveWindowSize) +{ + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + if (!Stream_CheckAndLogRequiredLength(TAG, buffer, 8)) + return FALSE; + const UINT64 val = Stream_Get_UINT64(buffer); + if (ReceiveWindowSize) + *ReceiveWindowSize = val; /* ReceiveWindowSize (8 bytes) */ + + return TRUE; +} + +static BOOL rts_receive_window_size_command_write(wStream* s, UINT32 ReceiveWindowSize) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 2 * sizeof(UINT32))) + return FALSE; + + Stream_Write_UINT32(s, RTS_CMD_RECEIVE_WINDOW_SIZE); /* CommandType (4 bytes) */ + Stream_Write_UINT32(s, ReceiveWindowSize); /* ReceiveWindowSize (4 bytes) */ + + return TRUE; +} + +static int rts_flow_control_ack_command_read(rdpRpc* rpc, wStream* buffer, UINT32* BytesReceived, + UINT32* AvailableWindow, BYTE* ChannelCookie) +{ + UINT32 val = 0; + UINT32 Command = 0; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + int rc = rts_destination_command_read(rpc, buffer, &Command); + if (rc < 0) + return rc; + + if (Command != RTS_CMD_FLOW_CONTROL_ACK) + { + char buffer1[64] = { 0 }; + char buffer2[64] = { 0 }; + WLog_Print(rpc->log, WLOG_ERROR, "got command %s, expected %s", + rts_command_to_string(Command, buffer1, sizeof(buffer1)), + rts_command_to_string(RTS_CMD_FLOW_CONTROL_ACK, buffer2, sizeof(buffer2))); + return -1; + } + + /* Ack (24 bytes) */ + if (!Stream_CheckAndLogRequiredLength(TAG, buffer, 24)) + return -1; + + Stream_Read_UINT32(buffer, val); + if (BytesReceived) + *BytesReceived = val; /* BytesReceived (4 bytes) */ + + Stream_Read_UINT32(buffer, val); + if (AvailableWindow) + *AvailableWindow = val; /* AvailableWindow (4 bytes) */ + + if (ChannelCookie) + Stream_Read(buffer, ChannelCookie, 16); /* ChannelCookie (16 bytes) */ + else + Stream_Seek(buffer, 16); + return 24; +} + +static BOOL rts_flow_control_ack_command_write(wStream* s, UINT32 BytesReceived, + UINT32 AvailableWindow, BYTE* ChannelCookie) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 28)) + return FALSE; + + Stream_Write_UINT32(s, RTS_CMD_FLOW_CONTROL_ACK); /* CommandType (4 bytes) */ + Stream_Write_UINT32(s, BytesReceived); /* BytesReceived (4 bytes) */ + Stream_Write_UINT32(s, AvailableWindow); /* AvailableWindow (4 bytes) */ + Stream_Write(s, ChannelCookie, 16); /* ChannelCookie (16 bytes) */ + + return TRUE; +} + +static BOOL rts_connection_timeout_command_read(rdpRpc* rpc, wStream* buffer, + UINT64* ConnectionTimeout) +{ + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + if (!Stream_CheckAndLogRequiredLength(TAG, buffer, 8)) + return FALSE; + + UINT64 val = Stream_Get_UINT64(buffer); + if (ConnectionTimeout) + *ConnectionTimeout = val; /* ConnectionTimeout (8 bytes) */ + + return TRUE; +} + +static BOOL rts_cookie_command_write(wStream* s, const BYTE* Cookie) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 20)) + return FALSE; + + Stream_Write_UINT32(s, RTS_CMD_COOKIE); /* CommandType (4 bytes) */ + Stream_Write(s, Cookie, 16); /* Cookie (16 bytes) */ + + return TRUE; +} + +static BOOL rts_channel_lifetime_command_write(wStream* s, UINT32 ChannelLifetime) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + Stream_Write_UINT32(s, RTS_CMD_CHANNEL_LIFETIME); /* CommandType (4 bytes) */ + Stream_Write_UINT32(s, ChannelLifetime); /* ChannelLifetime (4 bytes) */ + + return TRUE; +} + +static BOOL rts_client_keepalive_command_write(wStream* s, UINT32 ClientKeepalive) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + /** + * An unsigned integer that specifies the keep-alive interval, in milliseconds, + * that this connection is configured to use. This value MUST be 0 or in the inclusive + * range of 60,000 through 4,294,967,295. If it is 0, it MUST be interpreted as 300,000. + */ + + Stream_Write_UINT32(s, RTS_CMD_CLIENT_KEEPALIVE); /* CommandType (4 bytes) */ + Stream_Write_UINT32(s, ClientKeepalive); /* ClientKeepalive (4 bytes) */ + + return TRUE; +} + +static BOOL rts_version_command_read(rdpRpc* rpc, wStream* buffer) +{ + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + if (!Stream_SafeSeek(buffer, 8)) + return FALSE; + + /* command (4 bytes) */ + /* Version (4 bytes) */ + return TRUE; +} + +static BOOL rts_version_command_write(wStream* buffer) +{ + WINPR_ASSERT(buffer); + + if (!Stream_EnsureRemainingCapacity((buffer), 8)) + return FALSE; + + Stream_Write_UINT32(buffer, RTS_CMD_VERSION); /* CommandType (4 bytes) */ + Stream_Write_UINT32(buffer, 1); /* Version (4 bytes) */ + + return TRUE; +} + +static BOOL rts_empty_command_write(wStream* s) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + + Stream_Write_UINT32(s, RTS_CMD_EMPTY); /* CommandType (4 bytes) */ + + return TRUE; +} + +static BOOL rts_padding_command_read(wStream* s, size_t* length, BOOL silent) +{ + UINT32 ConformanceCount = 0; + WINPR_ASSERT(s); + WINPR_ASSERT(length); + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 4, silent)) + return FALSE; + Stream_Read_UINT32(s, ConformanceCount); /* ConformanceCount (4 bytes) */ + *length = ConformanceCount + 4; + return TRUE; +} + +static BOOL rts_client_address_command_read(wStream* s, size_t* length, BOOL silent) +{ + UINT32 AddressType = 0; + + WINPR_ASSERT(s); + WINPR_ASSERT(length); + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 4, silent)) + return FALSE; + Stream_Read_UINT32(s, AddressType); /* AddressType (4 bytes) */ + + if (AddressType == 0) + { + /* ClientAddress (4 bytes) */ + /* padding (12 bytes) */ + *length = 4 + 4 + 12; + } + else + { + /* ClientAddress (16 bytes) */ + /* padding (12 bytes) */ + *length = 4 + 16 + 12; + } + return TRUE; +} + +static BOOL rts_association_group_id_command_write(wStream* s, const BYTE* AssociationGroupId) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 20)) + return FALSE; + + Stream_Write_UINT32(s, RTS_CMD_ASSOCIATION_GROUP_ID); /* CommandType (4 bytes) */ + Stream_Write(s, AssociationGroupId, 16); /* AssociationGroupId (16 bytes) */ + + return TRUE; +} + +static int rts_destination_command_read(rdpRpc* rpc, wStream* buffer, UINT32* Destination) +{ + UINT32 val = 0; + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + if (!Stream_CheckAndLogRequiredLength(TAG, buffer, 4)) + return -1; + Stream_Read_UINT32(buffer, val); + if (Destination) + *Destination = val; /* Destination (4 bytes) */ + + return 4; +} + +static BOOL rts_destination_command_write(wStream* s, UINT32 Destination) +{ + WINPR_ASSERT(s); + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + + Stream_Write_UINT32(s, RTS_CMD_DESTINATION); /* CommandType (4 bytes) */ + Stream_Write_UINT32(s, Destination); /* Destination (4 bytes) */ + + return TRUE; +} + +void rts_generate_cookie(BYTE* cookie) +{ + WINPR_ASSERT(cookie); + winpr_RAND(cookie, 16); +} + +static BOOL rts_send_buffer(RpcChannel* channel, wStream* s, size_t frag_length) +{ + BOOL status = FALSE; + SSIZE_T rc = 0; + + WINPR_ASSERT(channel); + WINPR_ASSERT(s); + + Stream_SealLength(s); + if (Stream_Length(s) < sizeof(rpcconn_common_hdr_t)) + goto fail; + if (Stream_Length(s) != frag_length) + goto fail; + + rc = rpc_channel_write(channel, Stream_Buffer(s), Stream_Length(s)); + if (rc < 0) + goto fail; + if ((size_t)rc != Stream_Length(s)) + goto fail; + status = TRUE; +fail: + return status; +} + +/* CONN/A Sequence */ + +BOOL rts_send_CONN_A1_pdu(rdpRpc* rpc) +{ + BOOL status = FALSE; + wStream* buffer = NULL; + rpcconn_rts_hdr_t header = rts_pdu_header_init(); + UINT32 ReceiveWindowSize = 0; + BYTE* OUTChannelCookie = NULL; + BYTE* VirtualConnectionCookie = NULL; + RpcVirtualConnection* connection = NULL; + RpcOutChannel* outChannel = NULL; + + WINPR_ASSERT(rpc); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + outChannel = connection->DefaultOutChannel; + WINPR_ASSERT(outChannel); + + header.header.frag_length = 76; + header.Flags = RTS_FLAG_NONE; + header.NumberOfCommands = 4; + + WLog_DBG(TAG, "Sending CONN/A1 RTS PDU"); + VirtualConnectionCookie = (BYTE*)&(connection->Cookie); + OUTChannelCookie = (BYTE*)&(outChannel->common.Cookie); + ReceiveWindowSize = outChannel->ReceiveWindow; + + buffer = Stream_New(NULL, header.header.frag_length); + + if (!buffer) + return -1; + + if (!rts_write_pdu_header(buffer, &header)) /* RTS Header (20 bytes) */ + goto fail; + status = rts_version_command_write(buffer); /* Version (8 bytes) */ + if (!status) + goto fail; + status = rts_cookie_command_write( + buffer, VirtualConnectionCookie); /* VirtualConnectionCookie (20 bytes) */ + if (!status) + goto fail; + status = rts_cookie_command_write(buffer, OUTChannelCookie); /* OUTChannelCookie (20 bytes) */ + if (!status) + goto fail; + status = rts_receive_window_size_command_write( + buffer, ReceiveWindowSize); /* ReceiveWindowSize (8 bytes) */ + if (!status) + goto fail; + status = rts_send_buffer(&outChannel->common, buffer, header.header.frag_length); +fail: + Stream_Free(buffer, TRUE); + return status; +} + +BOOL rts_recv_CONN_A3_pdu(rdpRpc* rpc, wStream* buffer) +{ + BOOL rc = 0; + UINT64 ConnectionTimeout = 0; + + if (!Stream_SafeSeek(buffer, 20)) + return FALSE; + + rc = rts_connection_timeout_command_read(rpc, buffer, &ConnectionTimeout); + if (!rc || (ConnectionTimeout > UINT32_MAX)) + return rc; + + WLog_DBG(TAG, "Receiving CONN/A3 RTS PDU: ConnectionTimeout: %" PRIu64 "", ConnectionTimeout); + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->VirtualConnection); + WINPR_ASSERT(rpc->VirtualConnection->DefaultInChannel); + + rpc->VirtualConnection->DefaultInChannel->PingOriginator.ConnectionTimeout = + (UINT32)ConnectionTimeout; + return TRUE; +} + +/* CONN/B Sequence */ + +BOOL rts_send_CONN_B1_pdu(rdpRpc* rpc) +{ + BOOL status = FALSE; + wStream* buffer = NULL; + rpcconn_rts_hdr_t header = rts_pdu_header_init(); + BYTE* INChannelCookie = NULL; + BYTE* AssociationGroupId = NULL; + BYTE* VirtualConnectionCookie = NULL; + RpcVirtualConnection* connection = NULL; + RpcInChannel* inChannel = NULL; + + WINPR_ASSERT(rpc); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + inChannel = connection->DefaultInChannel; + WINPR_ASSERT(inChannel); + + header.header.frag_length = 104; + header.Flags = RTS_FLAG_NONE; + header.NumberOfCommands = 6; + + WLog_DBG(TAG, "Sending CONN/B1 RTS PDU"); + + VirtualConnectionCookie = (BYTE*)&(connection->Cookie); + INChannelCookie = (BYTE*)&(inChannel->common.Cookie); + AssociationGroupId = (BYTE*)&(connection->AssociationGroupId); + buffer = Stream_New(NULL, header.header.frag_length); + + if (!buffer) + goto fail; + if (!rts_write_pdu_header(buffer, &header)) /* RTS Header (20 bytes) */ + goto fail; + if (!rts_version_command_write(buffer)) /* Version (8 bytes) */ + goto fail; + if (!rts_cookie_command_write(buffer, + VirtualConnectionCookie)) /* VirtualConnectionCookie (20 bytes) */ + goto fail; + if (!rts_cookie_command_write(buffer, INChannelCookie)) /* INChannelCookie (20 bytes) */ + goto fail; + if (!rts_channel_lifetime_command_write(buffer, + rpc->ChannelLifetime)) /* ChannelLifetime (8 bytes) */ + goto fail; + if (!rts_client_keepalive_command_write(buffer, + rpc->KeepAliveInterval)) /* ClientKeepalive (8 bytes) */ + goto fail; + if (!rts_association_group_id_command_write( + buffer, AssociationGroupId)) /* AssociationGroupId (20 bytes) */ + goto fail; + status = rts_send_buffer(&inChannel->common, buffer, header.header.frag_length); +fail: + Stream_Free(buffer, TRUE); + return status; +} + +/* CONN/C Sequence */ + +BOOL rts_recv_CONN_C2_pdu(rdpRpc* rpc, wStream* buffer) +{ + BOOL rc = FALSE; + UINT64 ReceiveWindowSize = 0; + UINT64 ConnectionTimeout = 0; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + if (!Stream_SafeSeek(buffer, 20)) + return FALSE; + + rc = rts_version_command_read(rpc, buffer); + if (!rc) + return rc; + rc = rts_receive_window_size_command_read(rpc, buffer, &ReceiveWindowSize); + if (!rc || (ReceiveWindowSize > UINT32_MAX)) + return rc; + rc = rts_connection_timeout_command_read(rpc, buffer, &ConnectionTimeout); + if (!rc || (ConnectionTimeout > UINT32_MAX)) + return rc; + + WLog_DBG(TAG, + "Receiving CONN/C2 RTS PDU: ConnectionTimeout: %" PRIu64 " ReceiveWindowSize: %" PRIu64 + "", + ConnectionTimeout, ReceiveWindowSize); + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->VirtualConnection); + WINPR_ASSERT(rpc->VirtualConnection->DefaultInChannel); + + rpc->VirtualConnection->DefaultInChannel->PingOriginator.ConnectionTimeout = + (UINT32)ConnectionTimeout; + rpc->VirtualConnection->DefaultInChannel->PeerReceiveWindow = (UINT32)ReceiveWindowSize; + return TRUE; +} + +/* Out-of-Sequence PDUs */ + +BOOL rts_send_flow_control_ack_pdu(rdpRpc* rpc) +{ + BOOL status = FALSE; + wStream* buffer = NULL; + rpcconn_rts_hdr_t header = rts_pdu_header_init(); + UINT32 BytesReceived = 0; + UINT32 AvailableWindow = 0; + BYTE* ChannelCookie = NULL; + RpcVirtualConnection* connection = NULL; + RpcInChannel* inChannel = NULL; + RpcOutChannel* outChannel = NULL; + + WINPR_ASSERT(rpc); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + inChannel = connection->DefaultInChannel; + WINPR_ASSERT(inChannel); + + outChannel = connection->DefaultOutChannel; + WINPR_ASSERT(outChannel); + + header.header.frag_length = 56; + header.Flags = RTS_FLAG_OTHER_CMD; + header.NumberOfCommands = 2; + + WLog_DBG(TAG, "Sending FlowControlAck RTS PDU"); + + BytesReceived = outChannel->BytesReceived; + AvailableWindow = outChannel->AvailableWindowAdvertised; + ChannelCookie = (BYTE*)&(outChannel->common.Cookie); + outChannel->ReceiverAvailableWindow = outChannel->AvailableWindowAdvertised; + buffer = Stream_New(NULL, header.header.frag_length); + + if (!buffer) + goto fail; + + if (!rts_write_pdu_header(buffer, &header)) /* RTS Header (20 bytes) */ + goto fail; + if (!rts_destination_command_write(buffer, FDOutProxy)) /* Destination Command (8 bytes) */ + goto fail; + + /* FlowControlAck Command (28 bytes) */ + if (!rts_flow_control_ack_command_write(buffer, BytesReceived, AvailableWindow, ChannelCookie)) + goto fail; + + status = rts_send_buffer(&inChannel->common, buffer, header.header.frag_length); +fail: + Stream_Free(buffer, TRUE); + return status; +} + +static int rts_recv_flow_control_ack_pdu(rdpRpc* rpc, wStream* buffer) +{ + int rc = 0; + UINT32 BytesReceived = 0; + UINT32 AvailableWindow = 0; + BYTE ChannelCookie[16] = { 0 }; + + rc = rts_flow_control_ack_command_read(rpc, buffer, &BytesReceived, &AvailableWindow, + (BYTE*)&ChannelCookie); + if (rc < 0) + return rc; + WLog_ERR(TAG, + "Receiving FlowControlAck RTS PDU: BytesReceived: %" PRIu32 + " AvailableWindow: %" PRIu32 "", + BytesReceived, AvailableWindow); + + WINPR_ASSERT(rpc->VirtualConnection); + WINPR_ASSERT(rpc->VirtualConnection->DefaultInChannel); + + rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow = + AvailableWindow - (rpc->VirtualConnection->DefaultInChannel->BytesSent - BytesReceived); + return 1; +} + +static int rts_recv_flow_control_ack_with_destination_pdu(rdpRpc* rpc, wStream* buffer) +{ + UINT32 Command = 0; + UINT32 Destination = 0; + UINT32 BytesReceived = 0; + UINT32 AvailableWindow = 0; + BYTE ChannelCookie[16] = { 0 }; + /** + * When the sender receives a FlowControlAck RTS PDU, it MUST use the following formula to + * recalculate its Sender AvailableWindow variable: + * + * Sender AvailableWindow = Receiver AvailableWindow_from_ack - (BytesSent - + * BytesReceived_from_ack) + * + * Where: + * + * Receiver AvailableWindow_from_ack is the Available Window field in the Flow Control + * Acknowledgement Structure (section 2.2.3.4) in the PDU received. + * + * BytesReceived_from_ack is the Bytes Received field in the Flow Control Acknowledgement + * structure in the PDU received. + * + */ + + int rc = rts_destination_command_read(rpc, buffer, &Command); + if (rc < 0) + return rc; + + if (Command != RTS_CMD_DESTINATION) + { + char buffer1[64] = { 0 }; + char buffer2[64] = { 0 }; + WLog_Print(rpc->log, WLOG_ERROR, "got command %s, expected %s", + rts_command_to_string(Command, buffer1, sizeof(buffer1)), + rts_command_to_string(RTS_CMD_DESTINATION, buffer2, sizeof(buffer2))); + return -1; + } + + rc = rts_destination_command_read(rpc, buffer, &Destination); + if (rc < 0) + return rc; + + switch (Destination) + { + case FDClient: + break; + case FDInProxy: + break; + case FDServer: + break; + case FDOutProxy: + break; + default: + WLog_Print(rpc->log, WLOG_ERROR, + "got destination %" PRIu32 + ", expected one of [FDClient[0]|FDInProxy[1]|FDServer[2]|FDOutProxy[3]", + Destination); + return -1; + } + + rc = rts_flow_control_ack_command_read(rpc, buffer, &BytesReceived, &AvailableWindow, + ChannelCookie); + if (rc < 0) + return rc; + + WLog_DBG(TAG, + "Receiving FlowControlAckWithDestination RTS PDU: BytesReceived: %" PRIu32 + " AvailableWindow: %" PRIu32 "", + BytesReceived, AvailableWindow); + + WINPR_ASSERT(rpc->VirtualConnection); + WINPR_ASSERT(rpc->VirtualConnection->DefaultInChannel); + rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow = + AvailableWindow - (rpc->VirtualConnection->DefaultInChannel->BytesSent - BytesReceived); + return 1; +} + +BOOL rts_recv_ping_pdu(rdpRpc* rpc, wStream* s) +{ + BOOL rc = FALSE; + rpcconn_hdr_t header = { 0 }; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->auth); + WINPR_ASSERT(s); + + if (!rts_read_pdu_header(s, &header)) + goto fail; + + rc = TRUE; + if (header.common.ptype != PTYPE_RTS) + { + WLog_Print(rpc->log, WLOG_ERROR, "received invalid ping PDU, type is 0x%" PRIx32, + header.common.ptype); + rc = FALSE; + } + if (header.rts.Flags != RTS_FLAG_PING) + { + WLog_Print(rpc->log, WLOG_ERROR, "received unexpected ping PDU::Flags 0x%" PRIx32, + header.rts.Flags); + rc = FALSE; + } +fail: + rts_free_pdu_header(&header, FALSE); + return rc; +} + +static int rts_send_ping_pdu(rdpRpc* rpc) +{ + BOOL status = FALSE; + wStream* buffer = NULL; + rpcconn_rts_hdr_t header = rts_pdu_header_init(); + RpcInChannel* inChannel = NULL; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->VirtualConnection); + + inChannel = rpc->VirtualConnection->DefaultInChannel; + WINPR_ASSERT(inChannel); + + header.header.frag_length = 20; + header.Flags = RTS_FLAG_PING; + header.NumberOfCommands = 0; + + WLog_DBG(TAG, "Sending Ping RTS PDU"); + buffer = Stream_New(NULL, header.header.frag_length); + + if (!buffer) + goto fail; + + if (!rts_write_pdu_header(buffer, &header)) /* RTS Header (20 bytes) */ + goto fail; + status = rts_send_buffer(&inChannel->common, buffer, header.header.frag_length); +fail: + Stream_Free(buffer, TRUE); + return (status) ? 1 : -1; +} + +BOOL rts_command_length(UINT32 CommandType, wStream* s, size_t* length, BOOL silent) +{ + size_t padding = 0; + size_t CommandLength = 0; + + WINPR_ASSERT(s); + + switch (CommandType) + { + case RTS_CMD_RECEIVE_WINDOW_SIZE: + CommandLength = RTS_CMD_RECEIVE_WINDOW_SIZE_LENGTH; + break; + + case RTS_CMD_FLOW_CONTROL_ACK: + CommandLength = RTS_CMD_FLOW_CONTROL_ACK_LENGTH; + break; + + case RTS_CMD_CONNECTION_TIMEOUT: + CommandLength = RTS_CMD_CONNECTION_TIMEOUT_LENGTH; + break; + + case RTS_CMD_COOKIE: + CommandLength = RTS_CMD_COOKIE_LENGTH; + break; + + case RTS_CMD_CHANNEL_LIFETIME: + CommandLength = RTS_CMD_CHANNEL_LIFETIME_LENGTH; + break; + + case RTS_CMD_CLIENT_KEEPALIVE: + CommandLength = RTS_CMD_CLIENT_KEEPALIVE_LENGTH; + break; + + case RTS_CMD_VERSION: + CommandLength = RTS_CMD_VERSION_LENGTH; + break; + + case RTS_CMD_EMPTY: + CommandLength = RTS_CMD_EMPTY_LENGTH; + break; + + case RTS_CMD_PADDING: /* variable-size */ + if (!rts_padding_command_read(s, &padding, silent)) + return FALSE; + break; + + case RTS_CMD_NEGATIVE_ANCE: + CommandLength = RTS_CMD_NEGATIVE_ANCE_LENGTH; + break; + + case RTS_CMD_ANCE: + CommandLength = RTS_CMD_ANCE_LENGTH; + break; + + case RTS_CMD_CLIENT_ADDRESS: /* variable-size */ + if (!rts_client_address_command_read(s, &CommandLength, silent)) + return FALSE; + break; + + case RTS_CMD_ASSOCIATION_GROUP_ID: + CommandLength = RTS_CMD_ASSOCIATION_GROUP_ID_LENGTH; + break; + + case RTS_CMD_DESTINATION: + CommandLength = RTS_CMD_DESTINATION_LENGTH; + break; + + case RTS_CMD_PING_TRAFFIC_SENT_NOTIFY: + CommandLength = RTS_CMD_PING_TRAFFIC_SENT_NOTIFY_LENGTH; + break; + + default: + WLog_ERR(TAG, "Error: Unknown RTS Command Type: 0x%" PRIx32 "", CommandType); + return FALSE; + } + + CommandLength += padding; + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, CommandLength, silent)) + return FALSE; + + if (length) + *length = CommandLength; + return TRUE; +} + +static int rts_send_OUT_R2_A7_pdu(rdpRpc* rpc) +{ + BOOL status = FALSE; + wStream* buffer = NULL; + rpcconn_rts_hdr_t header = rts_pdu_header_init(); + BYTE* SuccessorChannelCookie = NULL; + RpcInChannel* inChannel = NULL; + RpcOutChannel* nextOutChannel = NULL; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->VirtualConnection); + + inChannel = rpc->VirtualConnection->DefaultInChannel; + WINPR_ASSERT(inChannel); + + nextOutChannel = rpc->VirtualConnection->NonDefaultOutChannel; + WINPR_ASSERT(nextOutChannel); + + header.header.frag_length = 56; + header.Flags = RTS_FLAG_OUT_CHANNEL; + header.NumberOfCommands = 3; + + WLog_DBG(TAG, "Sending OUT_R2/A7 RTS PDU"); + + SuccessorChannelCookie = (BYTE*)&(nextOutChannel->common.Cookie); + buffer = Stream_New(NULL, header.header.frag_length); + + if (!buffer) + return -1; + + if (!rts_write_pdu_header(buffer, &header)) /* RTS Header (20 bytes) */ + goto fail; + if (!rts_destination_command_write(buffer, FDServer)) /* Destination (8 bytes)*/ + goto fail; + if (!rts_cookie_command_write(buffer, + SuccessorChannelCookie)) /* SuccessorChannelCookie (20 bytes) */ + goto fail; + if (!rts_version_command_write(buffer)) /* Version (8 bytes) */ + goto fail; + status = rts_send_buffer(&inChannel->common, buffer, header.header.frag_length); +fail: + Stream_Free(buffer, TRUE); + return (status) ? 1 : -1; +} + +static int rts_send_OUT_R2_C1_pdu(rdpRpc* rpc) +{ + BOOL status = FALSE; + wStream* buffer = NULL; + rpcconn_rts_hdr_t header = rts_pdu_header_init(); + RpcOutChannel* nextOutChannel = NULL; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(rpc->VirtualConnection); + + nextOutChannel = rpc->VirtualConnection->NonDefaultOutChannel; + WINPR_ASSERT(nextOutChannel); + + header.header.frag_length = 24; + header.Flags = RTS_FLAG_PING; + header.NumberOfCommands = 1; + + WLog_DBG(TAG, "Sending OUT_R2/C1 RTS PDU"); + buffer = Stream_New(NULL, header.header.frag_length); + + if (!buffer) + return -1; + + if (!rts_write_pdu_header(buffer, &header)) /* RTS Header (20 bytes) */ + goto fail; + + if (!rts_empty_command_write(buffer)) /* Empty command (4 bytes) */ + goto fail; + status = rts_send_buffer(&nextOutChannel->common, buffer, header.header.frag_length); +fail: + Stream_Free(buffer, TRUE); + return (status) ? 1 : -1; +} + +BOOL rts_send_OUT_R1_A3_pdu(rdpRpc* rpc) +{ + BOOL status = FALSE; + wStream* buffer = NULL; + rpcconn_rts_hdr_t header = rts_pdu_header_init(); + UINT32 ReceiveWindowSize = 0; + BYTE* VirtualConnectionCookie = NULL; + BYTE* PredecessorChannelCookie = NULL; + BYTE* SuccessorChannelCookie = NULL; + RpcVirtualConnection* connection = NULL; + RpcOutChannel* outChannel = NULL; + RpcOutChannel* nextOutChannel = NULL; + + WINPR_ASSERT(rpc); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + outChannel = connection->DefaultOutChannel; + WINPR_ASSERT(outChannel); + + nextOutChannel = connection->NonDefaultOutChannel; + WINPR_ASSERT(nextOutChannel); + + header.header.frag_length = 96; + header.Flags = RTS_FLAG_RECYCLE_CHANNEL; + header.NumberOfCommands = 5; + + WLog_DBG(TAG, "Sending OUT_R1/A3 RTS PDU"); + + VirtualConnectionCookie = (BYTE*)&(connection->Cookie); + PredecessorChannelCookie = (BYTE*)&(outChannel->common.Cookie); + SuccessorChannelCookie = (BYTE*)&(nextOutChannel->common.Cookie); + ReceiveWindowSize = outChannel->ReceiveWindow; + buffer = Stream_New(NULL, header.header.frag_length); + + if (!buffer) + return -1; + + if (!rts_write_pdu_header(buffer, &header)) /* RTS Header (20 bytes) */ + goto fail; + if (!rts_version_command_write(buffer)) /* Version (8 bytes) */ + goto fail; + if (!rts_cookie_command_write(buffer, + VirtualConnectionCookie)) /* VirtualConnectionCookie (20 bytes) */ + goto fail; + if (!rts_cookie_command_write( + buffer, PredecessorChannelCookie)) /* PredecessorChannelCookie (20 bytes) */ + goto fail; + if (!rts_cookie_command_write(buffer, + SuccessorChannelCookie)) /* SuccessorChannelCookie (20 bytes) */ + goto fail; + if (!rts_receive_window_size_command_write(buffer, + ReceiveWindowSize)) /* ReceiveWindowSize (8 bytes) */ + goto fail; + + status = rts_send_buffer(&nextOutChannel->common, buffer, header.header.frag_length); +fail: + Stream_Free(buffer, TRUE); + return status; +} + +static int rts_recv_OUT_R1_A2_pdu(rdpRpc* rpc, wStream* buffer) +{ + int status = 0; + UINT32 Destination = 0; + RpcVirtualConnection* connection = NULL; + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + WLog_DBG(TAG, "Receiving OUT R1/A2 RTS PDU"); + + status = rts_destination_command_read(rpc, buffer, &Destination); + if (status < 0) + return status; + + connection->NonDefaultOutChannel = rpc_out_channel_new(rpc, &connection->Cookie); + + if (!connection->NonDefaultOutChannel) + return -1; + + status = rpc_out_channel_replacement_connect(connection->NonDefaultOutChannel, 5000); + + if (status < 0) + { + WLog_ERR(TAG, "rpc_out_channel_replacement_connect failure"); + return -1; + } + + rpc_out_channel_transition_to_state(connection->DefaultOutChannel, + CLIENT_OUT_CHANNEL_STATE_OPENED_A6W); + return 1; +} + +static int rts_recv_OUT_R2_A6_pdu(rdpRpc* rpc, wStream* buffer) +{ + int status = 0; + RpcVirtualConnection* connection = NULL; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + WLog_DBG(TAG, "Receiving OUT R2/A6 RTS PDU"); + status = rts_send_OUT_R2_C1_pdu(rpc); + + if (status < 0) + { + WLog_ERR(TAG, "rts_send_OUT_R2_C1_pdu failure"); + return -1; + } + + status = rts_send_OUT_R2_A7_pdu(rpc); + + if (status < 0) + { + WLog_ERR(TAG, "rts_send_OUT_R2_A7_pdu failure"); + return -1; + } + + rpc_out_channel_transition_to_state(connection->NonDefaultOutChannel, + CLIENT_OUT_CHANNEL_STATE_OPENED_B3W); + rpc_out_channel_transition_to_state(connection->DefaultOutChannel, + CLIENT_OUT_CHANNEL_STATE_OPENED_B3W); + return 1; +} + +static int rts_recv_OUT_R2_B3_pdu(rdpRpc* rpc, wStream* buffer) +{ + RpcVirtualConnection* connection = NULL; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + + connection = rpc->VirtualConnection; + WINPR_ASSERT(connection); + + WLog_DBG(TAG, "Receiving OUT R2/B3 RTS PDU"); + rpc_out_channel_transition_to_state(connection->DefaultOutChannel, + CLIENT_OUT_CHANNEL_STATE_RECYCLED); + return 1; +} + +BOOL rts_recv_out_of_sequence_pdu(rdpRpc* rpc, wStream* buffer, const rpcconn_hdr_t* header) +{ + BOOL status = FALSE; + size_t length = 0; + RtsPduSignature signature = { 0 }; + RpcVirtualConnection* connection = NULL; + + WINPR_ASSERT(rpc); + WINPR_ASSERT(buffer); + WINPR_ASSERT(header); + + wLog* log = WLog_Get(TAG); + + const size_t total = Stream_Length(buffer); + length = header->common.frag_length; + if (total < length) + { + WLog_Print(log, WLOG_ERROR, "PDU length %" PRIuz " does not match available data %" PRIuz, + length, total); + return FALSE; + } + + connection = rpc->VirtualConnection; + + if (!connection) + { + WLog_Print(log, WLOG_ERROR, "not connected, aborting"); + return FALSE; + } + + if (!rts_extract_pdu_signature(&signature, buffer, header)) + return FALSE; + + rts_print_pdu_signature(log, WLOG_TRACE, &signature); + + if (memcmp(&signature, &RTS_PDU_FLOW_CONTROL_ACK_SIGNATURE, sizeof(signature)) == 0) + { + status = rts_recv_flow_control_ack_pdu(rpc, buffer); + } + else if (memcmp(&signature, &RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE, + sizeof(signature)) == 0) + { + status = rts_recv_flow_control_ack_with_destination_pdu(rpc, buffer); + } + else if (memcmp(&signature, &RTS_PDU_PING_SIGNATURE, sizeof(signature)) == 0) + { + status = rts_send_ping_pdu(rpc); + } + else + { + if (connection->DefaultOutChannel->State == CLIENT_OUT_CHANNEL_STATE_OPENED) + { + if (memcmp(&signature, &RTS_PDU_OUT_R1_A2_SIGNATURE, sizeof(signature)) == 0) + { + status = rts_recv_OUT_R1_A2_pdu(rpc, buffer); + } + } + else if (connection->DefaultOutChannel->State == CLIENT_OUT_CHANNEL_STATE_OPENED_A6W) + { + if (memcmp(&signature, &RTS_PDU_OUT_R2_A6_SIGNATURE, sizeof(signature)) == 0) + { + status = rts_recv_OUT_R2_A6_pdu(rpc, buffer); + } + } + else if (connection->DefaultOutChannel->State == CLIENT_OUT_CHANNEL_STATE_OPENED_B3W) + { + if (memcmp(&signature, &RTS_PDU_OUT_R2_B3_SIGNATURE, sizeof(signature)) == 0) + { + status = rts_recv_OUT_R2_B3_pdu(rpc, buffer); + } + } + } + + if (!status) + { + const UINT32 SignatureId = rts_identify_pdu_signature(&signature, NULL); + WLog_Print(log, WLOG_ERROR, "error parsing RTS PDU with signature id: 0x%08" PRIX32 "", + SignatureId); + rts_print_pdu_signature(log, WLOG_ERROR, &signature); + } + + const size_t rem = Stream_GetRemainingLength(buffer); + if (rem > 0) + { + WLog_Print(log, WLOG_ERROR, "%" PRIuz " bytes or %" PRIuz " total not parsed, aborting", + rem, total); + rts_print_pdu_signature(log, WLOG_ERROR, &signature); + return FALSE; + } + + return status; +} + +BOOL rts_write_pdu_auth3(wStream* s, const rpcconn_rpc_auth_3_hdr_t* auth) +{ + WINPR_ASSERT(s); + WINPR_ASSERT(auth); + + if (!rts_write_common_pdu_header(s, &auth->header)) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, 2 * sizeof(UINT16))) + return FALSE; + + Stream_Write_UINT16(s, auth->max_xmit_frag); + Stream_Write_UINT16(s, auth->max_recv_frag); + + return rts_write_auth_verifier(s, &auth->auth_verifier, &auth->header); +} + +BOOL rts_write_pdu_bind(wStream* s, const rpcconn_bind_hdr_t* bind) +{ + + WINPR_ASSERT(s); + WINPR_ASSERT(bind); + + if (!rts_write_common_pdu_header(s, &bind->header)) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, 8)) + return FALSE; + + Stream_Write_UINT16(s, bind->max_xmit_frag); + Stream_Write_UINT16(s, bind->max_recv_frag); + Stream_Write_UINT32(s, bind->assoc_group_id); + + if (!rts_write_context_list(s, &bind->p_context_elem)) + return FALSE; + + return rts_write_auth_verifier(s, &bind->auth_verifier, &bind->header); +} + +BOOL rts_conditional_check_and_log(const char* tag, wStream* s, size_t size, BOOL silent, + const char* fkt, const char* file, size_t line) +{ + if (silent) + { + const size_t rem = Stream_GetRemainingLength(s); + if (rem < size) + return FALSE; + return TRUE; + } + + return Stream_CheckAndLogRequiredLengthEx(tag, WLOG_WARN, s, size, 1, "%s(%s:%" PRIuz ")", fkt, + file, line); +} + +BOOL rts_conditional_safe_seek(wStream* s, size_t size, BOOL silent, const char* fkt, + const char* file, size_t line) +{ + if (silent) + { + const size_t rem = Stream_GetRemainingLength(s); + if (rem < size) + return FALSE; + } + return Stream_SafeSeekEx(s, size, file, line, fkt); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts.h new file mode 100644 index 0000000000000000000000000000000000000000..40535cbf5ecf332523e0787d0e690b000867fcba --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts.h @@ -0,0 +1,123 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Request To Send (RTS) PDUs + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_RTS_H +#define FREERDP_LIB_CORE_GATEWAY_RTS_H + +#include + +#include + +#include +#include +#include + +#include "rpc.h" + +#define RTS_FLAG_NONE 0x0000 +#define RTS_FLAG_PING 0x0001 +#define RTS_FLAG_OTHER_CMD 0x0002 +#define RTS_FLAG_RECYCLE_CHANNEL 0x0004 +#define RTS_FLAG_IN_CHANNEL 0x0008 +#define RTS_FLAG_OUT_CHANNEL 0x0010 +#define RTS_FLAG_EOF 0x0020 +#define RTS_FLAG_ECHO 0x0040 + +#define RTS_CMD_RECEIVE_WINDOW_SIZE 0x00000000 +#define RTS_CMD_FLOW_CONTROL_ACK 0x00000001 +#define RTS_CMD_CONNECTION_TIMEOUT 0x00000002 +#define RTS_CMD_COOKIE 0x00000003 +#define RTS_CMD_CHANNEL_LIFETIME 0x00000004 +#define RTS_CMD_CLIENT_KEEPALIVE 0x00000005 +#define RTS_CMD_VERSION 0x00000006 +#define RTS_CMD_EMPTY 0x00000007 +#define RTS_CMD_PADDING 0x00000008 +#define RTS_CMD_NEGATIVE_ANCE 0x00000009 +#define RTS_CMD_ANCE 0x0000000A +#define RTS_CMD_CLIENT_ADDRESS 0x0000000B +#define RTS_CMD_ASSOCIATION_GROUP_ID 0x0000000C +#define RTS_CMD_DESTINATION 0x0000000D +#define RTS_CMD_PING_TRAFFIC_SENT_NOTIFY 0x0000000E +#define RTS_CMD_LAST_ID 0x0000000F + +#define RTS_CMD_RECEIVE_WINDOW_SIZE_LENGTH 0x00000004 +#define RTS_CMD_FLOW_CONTROL_ACK_LENGTH 0x00000018 +#define RTS_CMD_CONNECTION_TIMEOUT_LENGTH 0x00000004 +#define RTS_CMD_COOKIE_LENGTH 0x00000010 +#define RTS_CMD_CHANNEL_LIFETIME_LENGTH 0x00000004 +#define RTS_CMD_CLIENT_KEEPALIVE_LENGTH 0x00000004 +#define RTS_CMD_VERSION_LENGTH 0x00000004 +#define RTS_CMD_EMPTY_LENGTH 0x00000000 +#define RTS_CMD_PADDING_LENGTH 0x00000000 /* variable-size */ +#define RTS_CMD_NEGATIVE_ANCE_LENGTH 0x00000000 +#define RTS_CMD_ANCE_LENGTH 0x00000000 +#define RTS_CMD_CLIENT_ADDRESS_LENGTH 0x00000000 /* variable-size */ +#define RTS_CMD_ASSOCIATION_GROUP_ID_LENGTH 0x00000010 +#define RTS_CMD_DESTINATION_LENGTH 0x00000004 +#define RTS_CMD_PING_TRAFFIC_SENT_NOTIFY_LENGTH 0x00000004 + +#define FDClient 0x00000000 +#define FDInProxy 0x00000001 +#define FDServer 0x00000002 +#define FDOutProxy 0x00000003 + +FREERDP_LOCAL void rts_generate_cookie(BYTE* cookie); + +FREERDP_LOCAL BOOL rts_write_pdu_auth3(wStream* s, const rpcconn_rpc_auth_3_hdr_t* auth); +FREERDP_LOCAL BOOL rts_write_pdu_bind(wStream* s, const rpcconn_bind_hdr_t* bind); + +FREERDP_LOCAL BOOL rts_read_pdu_header(wStream* s, rpcconn_hdr_t* header); +FREERDP_LOCAL BOOL rts_read_pdu_header_ex(wStream* s, rpcconn_hdr_t* header, BOOL silent); +FREERDP_LOCAL void rts_free_pdu_header(rpcconn_hdr_t* header, BOOL allocated); + +FREERDP_LOCAL BOOL rts_read_common_pdu_header(wStream* s, rpcconn_common_hdr_t* header, + BOOL ignoreErrors); + +FREERDP_LOCAL BOOL rts_command_length(UINT32 CommandType, wStream* s, size_t* length, BOOL silent); + +FREERDP_LOCAL BOOL rts_send_CONN_A1_pdu(rdpRpc* rpc); +FREERDP_LOCAL BOOL rts_recv_CONN_A3_pdu(rdpRpc* rpc, wStream* buffer); + +FREERDP_LOCAL BOOL rts_send_CONN_B1_pdu(rdpRpc* rpc); + +FREERDP_LOCAL BOOL rts_recv_CONN_C2_pdu(rdpRpc* rpc, wStream* buffer); + +FREERDP_LOCAL BOOL rts_send_OUT_R1_A3_pdu(rdpRpc* rpc); + +FREERDP_LOCAL BOOL rts_send_flow_control_ack_pdu(rdpRpc* rpc); + +FREERDP_LOCAL BOOL rts_recv_out_of_sequence_pdu(rdpRpc* rpc, wStream* buffer, + const rpcconn_hdr_t* header); + +FREERDP_LOCAL BOOL rts_recv_ping_pdu(rdpRpc* rpc, wStream* s); + +#define Stream_ConditionalCheckAndLogRequiredLength(tag, s, size, silent) \ + rts_conditional_check_and_log(tag, s, size, silent, __func__, __FILE__, __LINE__) + +FREERDP_LOCAL BOOL rts_conditional_check_and_log(const char* tag, wStream* s, size_t size, + BOOL silent, const char* fkt, const char* file, + size_t line); + +#define Stream_ConditionalSafeSeek(s, size, silent) \ + rts_conditional_safe_seek(s, size, silent, __func__, __FILE__, __LINE__) + +FREERDP_LOCAL BOOL rts_conditional_safe_seek(wStream* s, size_t size, BOOL silent, const char* fkt, + const char* file, size_t line); + +#endif /* FREERDP_LIB_CORE_GATEWAY_RTS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts_signature.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts_signature.c new file mode 100644 index 0000000000000000000000000000000000000000..f549130dc423f92e5f7681808c371a4d79dd68ca --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts_signature.c @@ -0,0 +1,417 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Request To Send (RTS) PDU Signatures + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +#include "rts_signature.h" + +#define TAG FREERDP_TAG("core.gateway.rts") + +const RtsPduSignature RTS_PDU_CONN_A1_SIGNATURE = { + RTS_FLAG_NONE, + 4, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_RECEIVE_WINDOW_SIZE, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_CONN_A2_SIGNATURE = { RTS_FLAG_OUT_CHANNEL, + 5, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, + RTS_CMD_COOKIE, RTS_CMD_CHANNEL_LIFETIME, + RTS_CMD_RECEIVE_WINDOW_SIZE, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_CONN_A3_SIGNATURE = { + RTS_FLAG_NONE, 1, { RTS_CMD_CONNECTION_TIMEOUT, 0, 0, 0, 0, 0, 0, 0 } +}; + +const RtsPduSignature RTS_PDU_CONN_B1_SIGNATURE = { + RTS_FLAG_NONE, + 6, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_CHANNEL_LIFETIME, + RTS_CMD_CLIENT_KEEPALIVE, RTS_CMD_ASSOCIATION_GROUP_ID, 0, 0 } +}; +const RtsPduSignature RTS_PDU_CONN_B2_SIGNATURE = { + RTS_FLAG_IN_CHANNEL, + 7, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_RECEIVE_WINDOW_SIZE, + RTS_CMD_CONNECTION_TIMEOUT, RTS_CMD_ASSOCIATION_GROUP_ID, RTS_CMD_CLIENT_ADDRESS, 0 } +}; +const RtsPduSignature RTS_PDU_CONN_B3_SIGNATURE = { + RTS_FLAG_NONE, 2, { RTS_CMD_RECEIVE_WINDOW_SIZE, RTS_CMD_VERSION, 0, 0, 0, 0, 0, 0 } +}; + +const RtsPduSignature RTS_PDU_CONN_C1_SIGNATURE = { RTS_FLAG_NONE, + 3, + { RTS_CMD_VERSION, RTS_CMD_RECEIVE_WINDOW_SIZE, + RTS_CMD_CONNECTION_TIMEOUT, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_CONN_C2_SIGNATURE = { RTS_FLAG_NONE, + 3, + { RTS_CMD_VERSION, RTS_CMD_RECEIVE_WINDOW_SIZE, + RTS_CMD_CONNECTION_TIMEOUT, 0, 0, 0, 0, 0 } }; + +const RtsPduSignature RTS_PDU_IN_R1_A1_SIGNATURE = { + RTS_FLAG_RECYCLE_CHANNEL, + 4, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_COOKIE, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_IN_R1_A2_SIGNATURE = { + RTS_FLAG_NONE, + 4, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_RECEIVE_WINDOW_SIZE, + RTS_CMD_CONNECTION_TIMEOUT, 0, 0 } +}; +const RtsPduSignature RTS_PDU_IN_R1_A3_SIGNATURE = { RTS_FLAG_NONE, + 4, + { RTS_CMD_DESTINATION, RTS_CMD_VERSION, + RTS_CMD_RECEIVE_WINDOW_SIZE, + RTS_CMD_CONNECTION_TIMEOUT, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_IN_R1_A4_SIGNATURE = { RTS_FLAG_NONE, + 4, + { RTS_CMD_DESTINATION, RTS_CMD_VERSION, + RTS_CMD_RECEIVE_WINDOW_SIZE, + RTS_CMD_CONNECTION_TIMEOUT, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_IN_R1_A5_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_IN_R1_A6_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0, 0 } }; + +const RtsPduSignature RTS_PDU_IN_R1_B1_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_EMPTY, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_IN_R1_B2_SIGNATURE = { + RTS_FLAG_NONE, 1, { RTS_CMD_RECEIVE_WINDOW_SIZE, 0, 0, 0, 0, 0, 0, 0 } +}; + +const RtsPduSignature RTS_PDU_IN_R2_A1_SIGNATURE = { + RTS_FLAG_RECYCLE_CHANNEL, + 4, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_COOKIE, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_IN_R2_A2_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_IN_R2_A3_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_DESTINATION, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_IN_R2_A4_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_DESTINATION, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_IN_R2_A5_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0, 0 } }; + +const RtsPduSignature RTS_PDU_OUT_R1_A1_SIGNATURE = { + RTS_FLAG_RECYCLE_CHANNEL, 1, { RTS_CMD_DESTINATION, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R1_A2_SIGNATURE = { + RTS_FLAG_RECYCLE_CHANNEL, 1, { RTS_CMD_DESTINATION, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R1_A3_SIGNATURE = { RTS_FLAG_RECYCLE_CHANNEL, + 5, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, + RTS_CMD_COOKIE, RTS_CMD_COOKIE, + RTS_CMD_RECEIVE_WINDOW_SIZE, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_OUT_R1_A4_SIGNATURE = { + RTS_FLAG_RECYCLE_CHANNEL | RTS_FLAG_OUT_CHANNEL, + 7, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_COOKIE, RTS_CMD_CHANNEL_LIFETIME, + RTS_CMD_RECEIVE_WINDOW_SIZE, RTS_CMD_CONNECTION_TIMEOUT, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R1_A5_SIGNATURE = { + RTS_FLAG_OUT_CHANNEL, + 3, + { RTS_CMD_DESTINATION, RTS_CMD_VERSION, RTS_CMD_CONNECTION_TIMEOUT, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R1_A6_SIGNATURE = { + RTS_FLAG_OUT_CHANNEL, + 3, + { RTS_CMD_DESTINATION, RTS_CMD_VERSION, RTS_CMD_CONNECTION_TIMEOUT, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R1_A7_SIGNATURE = { + RTS_FLAG_OUT_CHANNEL, 2, { RTS_CMD_DESTINATION, RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R1_A8_SIGNATURE = { + RTS_FLAG_OUT_CHANNEL, 2, { RTS_CMD_DESTINATION, RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R1_A9_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_ANCE, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_OUT_R1_A10_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_ANCE, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_OUT_R1_A11_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_ANCE, 0, 0, 0, 0, 0, 0, 0 } }; + +const RtsPduSignature RTS_PDU_OUT_R2_A1_SIGNATURE = { + RTS_FLAG_RECYCLE_CHANNEL, 1, { RTS_CMD_DESTINATION, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R2_A2_SIGNATURE = { + RTS_FLAG_RECYCLE_CHANNEL, 1, { RTS_CMD_DESTINATION, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R2_A3_SIGNATURE = { RTS_FLAG_RECYCLE_CHANNEL, + 5, + { RTS_CMD_VERSION, RTS_CMD_COOKIE, + RTS_CMD_COOKIE, RTS_CMD_COOKIE, + RTS_CMD_RECEIVE_WINDOW_SIZE, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_OUT_R2_A4_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_OUT_R2_A5_SIGNATURE = { + RTS_FLAG_NONE, 2, { RTS_CMD_DESTINATION, RTS_CMD_ANCE, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R2_A6_SIGNATURE = { + RTS_FLAG_NONE, 2, { RTS_CMD_DESTINATION, RTS_CMD_ANCE, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R2_A7_SIGNATURE = { + RTS_FLAG_NONE, 3, { RTS_CMD_DESTINATION, RTS_CMD_COOKIE, RTS_CMD_VERSION, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R2_A8_SIGNATURE = { + RTS_FLAG_OUT_CHANNEL, 2, { RTS_CMD_DESTINATION, RTS_CMD_COOKIE, 0, 0, 0, 0, 0, 0 } +}; + +const RtsPduSignature RTS_PDU_OUT_R2_B1_SIGNATURE = { RTS_FLAG_NONE, + 1, + { RTS_CMD_ANCE, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_OUT_R2_B2_SIGNATURE = { + RTS_FLAG_NONE, 1, { RTS_CMD_NEGATIVE_ANCE, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_OUT_R2_B3_SIGNATURE = { RTS_FLAG_EOF, + 1, + { RTS_CMD_ANCE, 0, 0, 0, 0, 0, 0, 0 } }; + +const RtsPduSignature RTS_PDU_OUT_R2_C1_SIGNATURE = { RTS_FLAG_PING, + 1, + { 0, 0, 0, 0, 0, 0, 0, 0 } }; + +const RtsPduSignature RTS_PDU_KEEP_ALIVE_SIGNATURE = { + RTS_FLAG_OTHER_CMD, 1, { RTS_CMD_CLIENT_KEEPALIVE, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_PING_TRAFFIC_SENT_NOTIFY_SIGNATURE = { + RTS_FLAG_OTHER_CMD, 1, { RTS_CMD_PING_TRAFFIC_SENT_NOTIFY, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_ECHO_SIGNATURE = { RTS_FLAG_ECHO, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_PING_SIGNATURE = { RTS_FLAG_PING, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }; +const RtsPduSignature RTS_PDU_FLOW_CONTROL_ACK_SIGNATURE = { + RTS_FLAG_OTHER_CMD, 1, { RTS_CMD_FLOW_CONTROL_ACK, 0, 0, 0, 0, 0, 0, 0 } +}; +const RtsPduSignature RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE = { + RTS_FLAG_OTHER_CMD, 2, { RTS_CMD_DESTINATION, RTS_CMD_FLOW_CONTROL_ACK, 0, 0, 0, 0, 0, 0 } +}; + +static const RTS_PDU_SIGNATURE_ENTRY RTS_PDU_SIGNATURE_TABLE[] = { + { RTS_PDU_CONN_A1, FALSE, &RTS_PDU_CONN_A1_SIGNATURE, "CONN/A1" }, + { RTS_PDU_CONN_A2, FALSE, &RTS_PDU_CONN_A2_SIGNATURE, "CONN/A2" }, + { RTS_PDU_CONN_A3, TRUE, &RTS_PDU_CONN_A3_SIGNATURE, "CONN/A3" }, + + { RTS_PDU_CONN_B1, FALSE, &RTS_PDU_CONN_B1_SIGNATURE, "CONN/B1" }, + { RTS_PDU_CONN_B2, FALSE, &RTS_PDU_CONN_B2_SIGNATURE, "CONN/B2" }, + { RTS_PDU_CONN_B3, FALSE, &RTS_PDU_CONN_B3_SIGNATURE, "CONN/B3" }, + + { RTS_PDU_CONN_C1, FALSE, &RTS_PDU_CONN_C1_SIGNATURE, "CONN/C1" }, + { RTS_PDU_CONN_C2, TRUE, &RTS_PDU_CONN_C2_SIGNATURE, "CONN/C2" }, + + { RTS_PDU_IN_R1_A1, FALSE, &RTS_PDU_IN_R1_A1_SIGNATURE, "IN_R1/A1" }, + { RTS_PDU_IN_R1_A2, FALSE, &RTS_PDU_IN_R1_A2_SIGNATURE, "IN_R1/A2" }, + { RTS_PDU_IN_R1_A3, FALSE, &RTS_PDU_IN_R1_A3_SIGNATURE, "IN_R1/A3" }, + { RTS_PDU_IN_R1_A4, TRUE, &RTS_PDU_IN_R1_A4_SIGNATURE, "IN_R1/A4" }, + { RTS_PDU_IN_R1_A5, TRUE, &RTS_PDU_IN_R1_A5_SIGNATURE, "IN_R1/A5" }, + { RTS_PDU_IN_R1_A6, FALSE, &RTS_PDU_IN_R1_A6_SIGNATURE, "IN_R1/A6" }, + + { RTS_PDU_IN_R1_B1, FALSE, &RTS_PDU_IN_R1_B1_SIGNATURE, "IN_R1/B1" }, + { RTS_PDU_IN_R1_B2, FALSE, &RTS_PDU_IN_R1_B2_SIGNATURE, "IN_R1/B2" }, + + { RTS_PDU_IN_R2_A1, FALSE, &RTS_PDU_IN_R2_A1_SIGNATURE, "IN_R2/A1" }, + { RTS_PDU_IN_R2_A2, FALSE, &RTS_PDU_IN_R2_A2_SIGNATURE, "IN_R2/A2" }, + { RTS_PDU_IN_R2_A3, FALSE, &RTS_PDU_IN_R2_A3_SIGNATURE, "IN_R2/A3" }, + { RTS_PDU_IN_R2_A4, TRUE, &RTS_PDU_IN_R2_A4_SIGNATURE, "IN_R2/A4" }, + { RTS_PDU_IN_R2_A5, FALSE, &RTS_PDU_IN_R2_A5_SIGNATURE, "IN_R2/A5" }, + + { RTS_PDU_OUT_R1_A1, FALSE, &RTS_PDU_OUT_R1_A1_SIGNATURE, "OUT_R1/A1" }, + { RTS_PDU_OUT_R1_A2, TRUE, &RTS_PDU_OUT_R1_A2_SIGNATURE, "OUT_R1/A2" }, + { RTS_PDU_OUT_R1_A3, FALSE, &RTS_PDU_OUT_R1_A3_SIGNATURE, "OUT_R1/A3" }, + { RTS_PDU_OUT_R1_A4, FALSE, &RTS_PDU_OUT_R1_A4_SIGNATURE, "OUT_R1/A4" }, + { RTS_PDU_OUT_R1_A5, FALSE, &RTS_PDU_OUT_R1_A5_SIGNATURE, "OUT_R1/A5" }, + { RTS_PDU_OUT_R1_A6, TRUE, &RTS_PDU_OUT_R1_A6_SIGNATURE, "OUT_R1/A6" }, + { RTS_PDU_OUT_R1_A7, FALSE, &RTS_PDU_OUT_R1_A7_SIGNATURE, "OUT_R1/A7" }, + { RTS_PDU_OUT_R1_A8, FALSE, &RTS_PDU_OUT_R1_A8_SIGNATURE, "OUT_R1/A8" }, + { RTS_PDU_OUT_R1_A9, FALSE, &RTS_PDU_OUT_R1_A9_SIGNATURE, "OUT_R1/A9" }, + { RTS_PDU_OUT_R1_A10, TRUE, &RTS_PDU_OUT_R1_A10_SIGNATURE, "OUT_R1/A10" }, + { RTS_PDU_OUT_R1_A11, FALSE, &RTS_PDU_OUT_R1_A11_SIGNATURE, "OUT_R1/A11" }, + + { RTS_PDU_OUT_R2_A1, FALSE, &RTS_PDU_OUT_R2_A1_SIGNATURE, "OUT_R2/A1" }, + { RTS_PDU_OUT_R2_A2, TRUE, &RTS_PDU_OUT_R2_A2_SIGNATURE, "OUT_R2/A2" }, + { RTS_PDU_OUT_R2_A3, FALSE, &RTS_PDU_OUT_R2_A3_SIGNATURE, "OUT_R2/A3" }, + { RTS_PDU_OUT_R2_A4, FALSE, &RTS_PDU_OUT_R2_A4_SIGNATURE, "OUT_R2/A4" }, + { RTS_PDU_OUT_R2_A5, FALSE, &RTS_PDU_OUT_R2_A5_SIGNATURE, "OUT_R2/A5" }, + { RTS_PDU_OUT_R2_A6, TRUE, &RTS_PDU_OUT_R2_A6_SIGNATURE, "OUT_R2/A6" }, + { RTS_PDU_OUT_R2_A7, FALSE, &RTS_PDU_OUT_R2_A7_SIGNATURE, "OUT_R2/A7" }, + { RTS_PDU_OUT_R2_A8, FALSE, &RTS_PDU_OUT_R2_A8_SIGNATURE, "OUT_R2/A8" }, + + { RTS_PDU_OUT_R2_B1, FALSE, &RTS_PDU_OUT_R2_B1_SIGNATURE, "OUT_R2/B1" }, + { RTS_PDU_OUT_R2_B2, FALSE, &RTS_PDU_OUT_R2_B2_SIGNATURE, "OUT_R2/B2" }, + { RTS_PDU_OUT_R2_B3, TRUE, &RTS_PDU_OUT_R2_B3_SIGNATURE, "OUT_R2/B3" }, + + { RTS_PDU_OUT_R2_C1, FALSE, &RTS_PDU_OUT_R2_C1_SIGNATURE, "OUT_R2/C1" }, + + { RTS_PDU_KEEP_ALIVE, TRUE, &RTS_PDU_KEEP_ALIVE_SIGNATURE, "Keep-Alive" }, + { RTS_PDU_PING_TRAFFIC_SENT_NOTIFY, TRUE, &RTS_PDU_PING_TRAFFIC_SENT_NOTIFY_SIGNATURE, + "Ping Traffic Sent Notify" }, + { RTS_PDU_ECHO, TRUE, &RTS_PDU_ECHO_SIGNATURE, "Echo" }, + { RTS_PDU_PING, TRUE, &RTS_PDU_PING_SIGNATURE, "Ping" }, + { RTS_PDU_FLOW_CONTROL_ACK, TRUE, &RTS_PDU_FLOW_CONTROL_ACK_SIGNATURE, "FlowControlAck" }, + { RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION, TRUE, + &RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE, "FlowControlAckWithDestination" } +}; + +BOOL rts_match_pdu_signature(const RtsPduSignature* signature, wStream* src, + const rpcconn_hdr_t* header) +{ + return rts_match_pdu_signature_ex(signature, src, header, NULL, FALSE); +} + +BOOL rts_match_pdu_signature_ex(const RtsPduSignature* signature, wStream* src, + const rpcconn_hdr_t* header, RtsPduSignature* found_signature, + BOOL silent) +{ + RtsPduSignature extracted = { 0 }; + + WINPR_ASSERT(signature); + WINPR_ASSERT(src); + + if (!rts_extract_pdu_signature_ex(&extracted, src, header, silent)) + return FALSE; + + if (found_signature) + *found_signature = extracted; + return memcmp(signature, &extracted, sizeof(extracted)) == 0; +} + +BOOL rts_extract_pdu_signature(RtsPduSignature* signature, wStream* src, + const rpcconn_hdr_t* header) +{ + return rts_extract_pdu_signature_ex(signature, src, header, FALSE); +} + +BOOL rts_extract_pdu_signature_ex(RtsPduSignature* signature, wStream* src, + const rpcconn_hdr_t* header, BOOL silent) +{ + BOOL rc = FALSE; + wStream sbuffer = { 0 }; + rpcconn_hdr_t rheader = { 0 }; + const rpcconn_rts_hdr_t* rts = NULL; + + WINPR_ASSERT(signature); + WINPR_ASSERT(src); + + wStream* s = Stream_StaticInit(&sbuffer, Stream_Pointer(src), Stream_GetRemainingLength(src)); + if (!header) + { + if (!rts_read_pdu_header_ex(s, &rheader, silent)) + goto fail; + header = &rheader; + } + rts = &header->rts; + if (rts->header.frag_length < sizeof(rpcconn_rts_hdr_t)) + goto fail; + + signature->Flags = rts->Flags; + signature->NumberOfCommands = rts->NumberOfCommands; + + for (UINT16 i = 0; i < rts->NumberOfCommands; i++) + { + UINT32 CommandType = 0; + size_t CommandLength = 0; + + if (!Stream_ConditionalCheckAndLogRequiredLength(TAG, s, 4, silent)) + goto fail; + + Stream_Read_UINT32(s, CommandType); /* CommandType (4 bytes) */ + + /* We only need this for comparison against known command types */ + if (i < ARRAYSIZE(signature->CommandTypes)) + signature->CommandTypes[i] = CommandType; + + if (!rts_command_length(CommandType, s, &CommandLength, silent)) + goto fail; + if (!Stream_ConditionalSafeSeek(s, CommandLength, silent)) + goto fail; + } + + rc = TRUE; +fail: + rts_free_pdu_header(&rheader, FALSE); + return rc; +} + +UINT32 rts_identify_pdu_signature(const RtsPduSignature* signature, + const RTS_PDU_SIGNATURE_ENTRY** entry) +{ + if (entry) + *entry = NULL; + + for (size_t i = 0; i < ARRAYSIZE(RTS_PDU_SIGNATURE_TABLE); i++) + { + const RTS_PDU_SIGNATURE_ENTRY* current = &RTS_PDU_SIGNATURE_TABLE[i]; + const RtsPduSignature* pSignature = current->Signature; + + if (!current->SignatureClient) + continue; + + if (signature->Flags != pSignature->Flags) + continue; + + if (signature->NumberOfCommands != pSignature->NumberOfCommands) + continue; + + for (size_t j = 0; j < signature->NumberOfCommands; j++) + { + if (signature->CommandTypes[j] != pSignature->CommandTypes[j]) + continue; + } + + if (entry) + *entry = current; + + return current->SignatureId; + } + + return 0; +} + +BOOL rts_print_pdu_signature(wLog* log, DWORD level, const RtsPduSignature* signature) +{ + UINT32 SignatureId = 0; + const RTS_PDU_SIGNATURE_ENTRY* entry = NULL; + + if (!signature) + return FALSE; + + WLog_Print(log, level, + "RTS PDU Signature: Flags: 0x%04" PRIX16 " NumberOfCommands: %" PRIu16 "", + signature->Flags, signature->NumberOfCommands); + SignatureId = rts_identify_pdu_signature(signature, &entry); + + if (SignatureId) + WLog_Print(log, level, "Identified %s RTS PDU", entry->PduName); + + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts_signature.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts_signature.h new file mode 100644 index 0000000000000000000000000000000000000000..9886ba8c7ec207eb0c9b01c89432599fbc8024c8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/rts_signature.h @@ -0,0 +1,192 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Request To Send (RTS) PDU Signatures + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_RTS_SIGNATURE_H +#define FREERDP_LIB_CORE_GATEWAY_RTS_SIGNATURE_H + +#include "rts.h" + +#include +#include + +typedef struct +{ + UINT16 Flags; + UINT16 NumberOfCommands; + UINT32 CommandTypes[8]; +} RtsPduSignature; + +typedef struct +{ + UINT32 SignatureId; + BOOL SignatureClient; + const RtsPduSignature* Signature; + const char* PduName; +} RTS_PDU_SIGNATURE_ENTRY; + +/* RTS PDU Signature IDs */ + +#define RTS_PDU_CONN_A 0x10000000 +#define RTS_PDU_CONN_A1 (RTS_PDU_CONN_A | 0x00000001) +#define RTS_PDU_CONN_A2 (RTS_PDU_CONN_A | 0x00000002) +#define RTS_PDU_CONN_A3 (RTS_PDU_CONN_A | 0x00000003) + +#define RTS_PDU_CONN_B 0x20000000 +#define RTS_PDU_CONN_B1 (RTS_PDU_CONN_B | 0x00000001) +#define RTS_PDU_CONN_B2 (RTS_PDU_CONN_B | 0x00000002) +#define RTS_PDU_CONN_B3 (RTS_PDU_CONN_B | 0x00000003) + +#define RTS_PDU_CONN_C 0x40000000 +#define RTS_PDU_CONN_C1 (RTS_PDU_CONN_C | 0x00000001) +#define RTS_PDU_CONN_C2 (RTS_PDU_CONN_C | 0x00000002) + +#define RTS_PDU_IN_R1_A 0x01000000 +#define RTS_PDU_IN_R1_A1 (RTS_PDU_IN_R1_A | 0x00000001) +#define RTS_PDU_IN_R1_A2 (RTS_PDU_IN_R1_A | 0x00000002) +#define RTS_PDU_IN_R1_A3 (RTS_PDU_IN_R1_A | 0x00000003) +#define RTS_PDU_IN_R1_A4 (RTS_PDU_IN_R1_A | 0x00000004) +#define RTS_PDU_IN_R1_A5 (RTS_PDU_IN_R1_A | 0x00000005) +#define RTS_PDU_IN_R1_A6 (RTS_PDU_IN_R1_A | 0x00000006) + +#define RTS_PDU_IN_R1_B 0x02000000 +#define RTS_PDU_IN_R1_B1 (RTS_PDU_IN_R1_B | 0x00000001) +#define RTS_PDU_IN_R1_B2 (RTS_PDU_IN_R1_B | 0x00000002) + +#define RTS_PDU_IN_R2_A 0x04000000 +#define RTS_PDU_IN_R2_A1 (RTS_PDU_IN_R2_A | 0x00000001) +#define RTS_PDU_IN_R2_A2 (RTS_PDU_IN_R2_A | 0x00000002) +#define RTS_PDU_IN_R2_A3 (RTS_PDU_IN_R2_A | 0x00000003) +#define RTS_PDU_IN_R2_A4 (RTS_PDU_IN_R2_A | 0x00000004) +#define RTS_PDU_IN_R2_A5 (RTS_PDU_IN_R2_A | 0x00000005) + +#define RTS_PDU_OUT_R1_A 0x00100000 +#define RTS_PDU_OUT_R1_A1 (RTS_PDU_OUT_R1_A | 0x00000001) +#define RTS_PDU_OUT_R1_A2 (RTS_PDU_OUT_R1_A | 0x00000002) +#define RTS_PDU_OUT_R1_A3 (RTS_PDU_OUT_R1_A | 0x00000003) +#define RTS_PDU_OUT_R1_A4 (RTS_PDU_OUT_R1_A | 0x00000004) +#define RTS_PDU_OUT_R1_A5 (RTS_PDU_OUT_R1_A | 0x00000005) +#define RTS_PDU_OUT_R1_A6 (RTS_PDU_OUT_R1_A | 0x00000006) +#define RTS_PDU_OUT_R1_A7 (RTS_PDU_OUT_R1_A | 0x00000007) +#define RTS_PDU_OUT_R1_A8 (RTS_PDU_OUT_R1_A | 0x00000008) +#define RTS_PDU_OUT_R1_A9 (RTS_PDU_OUT_R1_A | 0x00000009) +#define RTS_PDU_OUT_R1_A10 (RTS_PDU_OUT_R1_A | 0x0000000A) +#define RTS_PDU_OUT_R1_A11 (RTS_PDU_OUT_R1_A | 0x0000000B) + +#define RTS_PDU_OUT_R2_A 0x00200000 +#define RTS_PDU_OUT_R2_A1 (RTS_PDU_OUT_R2_A | 0x00000001) +#define RTS_PDU_OUT_R2_A2 (RTS_PDU_OUT_R2_A | 0x00000002) +#define RTS_PDU_OUT_R2_A3 (RTS_PDU_OUT_R2_A | 0x00000003) +#define RTS_PDU_OUT_R2_A4 (RTS_PDU_OUT_R2_A | 0x00000004) +#define RTS_PDU_OUT_R2_A5 (RTS_PDU_OUT_R2_A | 0x00000005) +#define RTS_PDU_OUT_R2_A6 (RTS_PDU_OUT_R2_A | 0x00000006) +#define RTS_PDU_OUT_R2_A7 (RTS_PDU_OUT_R2_A | 0x00000007) +#define RTS_PDU_OUT_R2_A8 (RTS_PDU_OUT_R2_A | 0x00000008) + +#define RTS_PDU_OUT_R2_B 0x00400000 +#define RTS_PDU_OUT_R2_B1 (RTS_PDU_OUT_R2_B | 0x00000001) +#define RTS_PDU_OUT_R2_B2 (RTS_PDU_OUT_R2_B | 0x00000002) +#define RTS_PDU_OUT_R2_B3 (RTS_PDU_OUT_R2_B | 0x00000003) + +#define RTS_PDU_OUT_R2_C 0x00800000 +#define RTS_PDU_OUT_R2_C1 (RTS_PDU_OUT_R2_C | 0x00000001) + +#define RTS_PDU_OUT_OF_SEQUENCE 0x00010000 +#define RTS_PDU_KEEP_ALIVE (RTS_PDU_OUT_OF_SEQUENCE | 0x00000001) +#define RTS_PDU_PING_TRAFFIC_SENT_NOTIFY (RTS_PDU_OUT_OF_SEQUENCE | 0x00000002) +#define RTS_PDU_ECHO (RTS_PDU_OUT_OF_SEQUENCE | 0x00000003) +#define RTS_PDU_PING (RTS_PDU_OUT_OF_SEQUENCE | 0x00000004) +#define RTS_PDU_FLOW_CONTROL_ACK (RTS_PDU_OUT_OF_SEQUENCE | 0x00000005) +#define RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION (RTS_PDU_OUT_OF_SEQUENCE | 0x00000006) + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_A1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_A2_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_A3_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_B1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_B2_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_B3_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_C1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_CONN_C2_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_A1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_A2_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_A3_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_A4_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_A5_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_A6_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_B1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R1_B2_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R2_A1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R2_A2_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R2_A3_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R2_A4_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_IN_R2_A5_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A2_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A3_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A4_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A5_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A6_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A7_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A8_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A9_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A10_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R1_A11_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A2_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A3_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A4_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A5_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A6_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A7_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_A8_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_B1_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_B2_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_B3_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_OUT_R2_C1_SIGNATURE; + +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_KEEP_ALIVE_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_PING_TRAFFIC_SENT_NOTIFY_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_ECHO_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_PING_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_FLOW_CONTROL_ACK_SIGNATURE; +FREERDP_LOCAL extern const RtsPduSignature RTS_PDU_FLOW_CONTROL_ACK_WITH_DESTINATION_SIGNATURE; + +FREERDP_LOCAL BOOL rts_match_pdu_signature(const RtsPduSignature* signature, wStream* s, + const rpcconn_hdr_t* header); +FREERDP_LOCAL BOOL rts_match_pdu_signature_ex(const RtsPduSignature* signature, wStream* s, + const rpcconn_hdr_t* header, + RtsPduSignature* found_signature, BOOL silent); +FREERDP_LOCAL BOOL rts_extract_pdu_signature(RtsPduSignature* signature, wStream* s, + const rpcconn_hdr_t* header); +FREERDP_LOCAL BOOL rts_extract_pdu_signature_ex(RtsPduSignature* signature, wStream* s, + const rpcconn_hdr_t* header, BOOL silent); +FREERDP_LOCAL UINT32 rts_identify_pdu_signature(const RtsPduSignature* signature, + const RTS_PDU_SIGNATURE_ENTRY** entry); +FREERDP_LOCAL BOOL rts_print_pdu_signature(wLog* log, DWORD level, + const RtsPduSignature* signature); + +#endif /* FREERDP_LIB_CORE_GATEWAY_RTS_SIGNATURE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/tsg.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/tsg.c new file mode 100644 index 0000000000000000000000000000000000000000..45b5e3d68891d2420d4cfe7b125d22422a15b145 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/tsg.c @@ -0,0 +1,3128 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Terminal Server Gateway (TSG) + * + * Copyright 2012 Fujitsu Technology Solutions GmbH + * Copyright 2012 Dmitrij Jasnov + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 DI (FH) Martin Haimberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "../settings.h" + +#include +#include +#include +#include +#include + +#include + +#include "rpc_bind.h" +#include "rpc_client.h" +#include "tsg.h" +#include "../utils.h" +#include "../../crypto/opensslcompat.h" + +#define TAG FREERDP_TAG("core.gateway.tsg") + +#define TSG_CAPABILITY_TYPE_NAP 0x00000001 + +#define TSG_PACKET_TYPE_HEADER 0x00004844 +#define TSG_PACKET_TYPE_VERSIONCAPS 0x00005643 +#define TSG_PACKET_TYPE_QUARCONFIGREQUEST 0x00005143 +#define TSG_PACKET_TYPE_QUARREQUEST 0x00005152 +#define TSG_PACKET_TYPE_RESPONSE 0x00005052 +#define TSG_PACKET_TYPE_QUARENC_RESPONSE 0x00004552 +#define TSG_PACKET_TYPE_CAPS_RESPONSE 0x00004350 +#define TSG_PACKET_TYPE_MSGREQUEST_PACKET 0x00004752 +#define TSG_PACKET_TYPE_MESSAGE_PACKET 0x00004750 +#define TSG_PACKET_TYPE_AUTH 0x00004054 +#define TSG_PACKET_TYPE_REAUTH 0x00005250 + +typedef WCHAR* RESOURCENAME; + +typedef struct +{ + RESOURCENAME* resourceName; + UINT32 numResourceNames; + RESOURCENAME* alternateResourceNames; + UINT16 numAlternateResourceNames; + UINT32 Port; +} TSENDPOINTINFO; + +typedef struct +{ + UINT16 ComponentId; + UINT16 PacketId; +} TSG_PACKET_HEADER; + +typedef struct +{ + UINT32 capabilities; +} TSG_CAPABILITY_NAP; + +typedef union +{ + TSG_CAPABILITY_NAP tsgCapNap; +} TSG_CAPABILITIES_UNION; + +typedef struct +{ + UINT32 capabilityType; + TSG_CAPABILITIES_UNION tsgPacket; +} TSG_PACKET_CAPABILITIES; + +typedef struct +{ + TSG_PACKET_HEADER tsgHeader; + TSG_PACKET_CAPABILITIES tsgCaps; + UINT32 numCapabilities; + UINT16 majorVersion; + UINT16 minorVersion; + UINT16 quarantineCapabilities; +} TSG_PACKET_VERSIONCAPS; + +typedef struct +{ + UINT32 flags; +} TSG_PACKET_QUARCONFIGREQUEST; + +typedef struct +{ + UINT32 flags; + WCHAR* machineName; + UINT32 nameLength; + BYTE* data; + UINT32 dataLen; +} TSG_PACKET_QUARREQUEST; + +typedef struct +{ + BOOL enableAllRedirections; + BOOL disableAllRedirections; + BOOL driveRedirectionDisabled; + BOOL printerRedirectionDisabled; + BOOL portRedirectionDisabled; + BOOL reserved; + BOOL clipboardRedirectionDisabled; + BOOL pnpRedirectionDisabled; +} TSG_REDIRECTION_FLAGS; + +typedef struct +{ + UINT32 flags; + UINT32 reserved; + BYTE* responseData; + UINT32 responseDataLen; + TSG_REDIRECTION_FLAGS redirectionFlags; +} TSG_PACKET_RESPONSE; + +typedef struct +{ + UINT32 flags; + UINT32 certChainLen; + WCHAR* certChainData; + GUID nonce; + TSG_PACKET_VERSIONCAPS versionCaps; +} TSG_PACKET_QUARENC_RESPONSE; + +typedef struct +{ + INT32 isDisplayMandatory; + INT32 isConsentMandatory; + UINT32 msgBytes; + WCHAR* msgBuffer; +} TSG_PACKET_STRING_MESSAGE; + +typedef struct +{ + UINT64 tunnelContext; +} TSG_PACKET_REAUTH_MESSAGE; + +typedef struct +{ + UINT32 msgID; + UINT32 msgType; + INT32 isMsgPresent; +} TSG_PACKET_MSG_RESPONSE; + +typedef struct +{ + TSG_PACKET_QUARENC_RESPONSE pktQuarEncResponse; + TSG_PACKET_MSG_RESPONSE pktConsentMessage; +} TSG_PACKET_CAPS_RESPONSE; + +typedef struct +{ + UINT32 maxMessagesPerBatch; +} TSG_PACKET_MSG_REQUEST; + +typedef struct +{ + TSG_PACKET_VERSIONCAPS tsgVersionCaps; + UINT32 cookieLen; + BYTE* cookie; +} TSG_PACKET_AUTH; + +typedef union +{ + TSG_PACKET_VERSIONCAPS packetVersionCaps; + TSG_PACKET_AUTH packetAuth; +} TSG_INITIAL_PACKET_TYPE_UNION; + +typedef struct +{ + UINT64 tunnelContext; + UINT32 packetId; + TSG_INITIAL_PACKET_TYPE_UNION tsgInitialPacket; +} TSG_PACKET_REAUTH; + +typedef union +{ + TSG_PACKET_HEADER packetHeader; + TSG_PACKET_VERSIONCAPS packetVersionCaps; + TSG_PACKET_QUARCONFIGREQUEST packetQuarConfigRequest; + TSG_PACKET_QUARREQUEST packetQuarRequest; + TSG_PACKET_RESPONSE packetResponse; + TSG_PACKET_QUARENC_RESPONSE packetQuarEncResponse; + TSG_PACKET_CAPS_RESPONSE packetCapsResponse; + TSG_PACKET_MSG_REQUEST packetMsgRequest; + TSG_PACKET_MSG_RESPONSE packetMsgResponse; + TSG_PACKET_AUTH packetAuth; + TSG_PACKET_REAUTH packetReauth; +} TSG_PACKET_TYPE_UNION; + +typedef struct +{ + UINT32 packetId; + TSG_PACKET_TYPE_UNION tsgPacket; +} TSG_PACKET; + +struct rdp_tsg +{ + BIO* bio; + rdpRpc* rpc; + UINT16 Port; + LPWSTR Hostname; + LPWSTR MachineName; + TSG_STATE state; + UINT32 TunnelId; + UINT32 ChannelId; + BOOL reauthSequence; + rdpTransport* transport; + UINT64 ReauthTunnelContext; + CONTEXT_HANDLE TunnelContext; + CONTEXT_HANDLE ChannelContext; + CONTEXT_HANDLE NewTunnelContext; + CONTEXT_HANDLE NewChannelContext; + wLog* log; +}; + +static BOOL tsg_stream_align(wLog* log, wStream* s, size_t align); + +static const char* tsg_packet_id_to_string(UINT32 packetId) +{ + switch (packetId) + { + case TSG_PACKET_TYPE_HEADER: + return "TSG_PACKET_TYPE_HEADER"; + case TSG_PACKET_TYPE_VERSIONCAPS: + return "TSG_PACKET_TYPE_VERSIONCAPS"; + case TSG_PACKET_TYPE_QUARCONFIGREQUEST: + return "TSG_PACKET_TYPE_QUARCONFIGREQUEST"; + case TSG_PACKET_TYPE_QUARREQUEST: + return "TSG_PACKET_TYPE_QUARREQUEST"; + case TSG_PACKET_TYPE_RESPONSE: + return "TSG_PACKET_TYPE_RESPONSE"; + case TSG_PACKET_TYPE_QUARENC_RESPONSE: + return "TSG_PACKET_TYPE_QUARENC_RESPONSE"; + case TSG_CAPABILITY_TYPE_NAP: + return "TSG_CAPABILITY_TYPE_NAP"; + case TSG_PACKET_TYPE_CAPS_RESPONSE: + return "TSG_PACKET_TYPE_CAPS_RESPONSE"; + case TSG_PACKET_TYPE_MSGREQUEST_PACKET: + return "TSG_PACKET_TYPE_MSGREQUEST_PACKET"; + case TSG_PACKET_TYPE_MESSAGE_PACKET: + return "TSG_PACKET_TYPE_MESSAGE_PACKET"; + case TSG_PACKET_TYPE_AUTH: + return "TSG_PACKET_TYPE_AUTH"; + case TSG_PACKET_TYPE_REAUTH: + return "TSG_PACKET_TYPE_REAUTH"; + default: + return "UNKNOWN"; + } +} + +static const char* tsg_component_id_to_string(UINT16 ComponentId, char* buffer, size_t bytelen) +{ + const char* str = NULL; + +#define ENTRY(x) \ + case x: \ + str = #x; \ + break + switch (ComponentId) + { + ENTRY(TS_GATEWAY_TRANSPORT); + default: + str = "TS_UNKNOWN"; + break; + } +#undef ENTRY + + (void)_snprintf(buffer, bytelen, "%s [0x%04" PRIx16 "]", str, ComponentId); + return buffer; +} + +static const char* tsg_state_to_string(TSG_STATE state) +{ + switch (state) + { + case TSG_STATE_INITIAL: + return "TSG_STATE_INITIAL"; + case TSG_STATE_CONNECTED: + return "TSG_STATE_CONNECTED"; + case TSG_STATE_AUTHORIZED: + return "TSG_STATE_AUTHORIZED"; + case TSG_STATE_CHANNEL_CREATED: + return "TSG_STATE_CHANNEL_CREATED"; + case TSG_STATE_PIPE_CREATED: + return "TSG_STATE_PIPE_CREATED"; + case TSG_STATE_TUNNEL_CLOSE_PENDING: + return "TSG_STATE_TUNNEL_CLOSE_PENDING"; + case TSG_STATE_CHANNEL_CLOSE_PENDING: + return "TSG_STATE_CHANNEL_CLOSE_PENDING"; + case TSG_STATE_FINAL: + return "TSG_STATE_FINAL"; + default: + return "TSG_STATE_UNKNOWN"; + } +} + +static BOOL TsProxyReadTunnelContext(wLog* log, wStream* s, CONTEXT_HANDLE* tunnelContext) +{ + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20)) + return FALSE; + + WINPR_ASSERT(tunnelContext); + Stream_Read_UINT32(s, tunnelContext->ContextType); /* ContextType (4 bytes) */ + Stream_Read(s, &tunnelContext->ContextUuid, + sizeof(tunnelContext->ContextUuid)); /* ContextUuid (16 bytes) */ + return TRUE; +} + +static BOOL TsProxyWriteTunnelContext(wLog* log, wStream* s, const CONTEXT_HANDLE* tunnelContext) +{ + if (!Stream_EnsureRemainingCapacity(s, 20)) + return FALSE; + + Stream_Write_UINT32(s, tunnelContext->ContextType); /* ContextType (4 bytes) */ + Stream_Write(s, &tunnelContext->ContextUuid, + sizeof(tunnelContext->ContextUuid)); /* ContextUuid (16 bytes) */ + return TRUE; +} + +static BOOL tsg_ndr_pointer_write(wLog* log, wStream* s, UINT32* index, DWORD length) +{ + WINPR_ASSERT(index); + const UINT32 ndrPtr = 0x20000 + (*index) * 4; + + if (!s) + return FALSE; + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + + if (length > 0) + { + Stream_Write_UINT32(s, ndrPtr); /* mszGroupsNdrPtr (4 bytes) */ + (*index) = (*index) + 1; + } + else + Stream_Write_UINT32(s, 0); + return TRUE; +} + +static BOOL tsg_ndr_pointer_read(wLog* log, wStream* s, UINT32* index, UINT32* ptrval, + BOOL required) +{ + WINPR_ASSERT(index); + const UINT32 ndrPtr = 0x20000 + (*index) * 4; + + if (!s) + return FALSE; + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 4)) + return FALSE; + + DWORD val = 0; + Stream_Read_UINT32(s, val); + if (ptrval) + *ptrval = val; + + if (val != 0) + { + if (val != ndrPtr) + { + WLog_Print(log, WLOG_WARN, "Read NDR pointer 0x%04" PRIx32 " but expected 0x%04" PRIx32, + val, ndrPtr); + if ((val & 0xFFFF0000) != (ndrPtr & 0xFFFF0000)) + return FALSE; + } + (*index)++; + } + else if (required) + { + WLog_Print(log, WLOG_ERROR, "NDR pointer == 0, but the field is required"); + return FALSE; + } + + return TRUE; +} + +static BOOL tsg_ndr_write_string(wLog* log, wStream* s, const WCHAR* str, size_t length) +{ + if (!Stream_EnsureRemainingCapacity(s, 12 + length) || (length > UINT32_MAX)) + return FALSE; + + Stream_Write_UINT32(s, (UINT32)length); /* MaxCount (4 bytes) */ + Stream_Write_UINT32(s, 0); /* Offset (4 bytes) */ + Stream_Write_UINT32(s, (UINT32)length); /* ActualCount (4 bytes) */ + Stream_Write_UTF16_String(s, str, length); /* Array */ + return TRUE; +} + +static BOOL tsg_ndr_read_string(wLog* log, wStream* s, WCHAR** str, UINT32 lengthInBytes) +{ + UINT32 MaxCount = 0; + UINT32 Offset = 0; + UINT32 ActualCount = 0; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12)) + return FALSE; + + Stream_Read_UINT32(s, MaxCount); /* MaxCount (4 bytes) */ + Stream_Read_UINT32(s, Offset); /* Offset (4 bytes) */ + Stream_Read_UINT32(s, ActualCount); /* ActualCount (4 bytes) */ + if (ActualCount > MaxCount) + { + WLog_Print(log, WLOG_ERROR, + "failed to read string, ActualCount (%" PRIu32 ") > MaxCount (%" PRIu32 ")", + ActualCount, MaxCount); + return FALSE; + } + if (Offset != 0) + { + WLog_Print(log, WLOG_ERROR, "Unsupported Offset (%" PRIu32 "), expected 0", Offset); + return FALSE; + } + if (ActualCount > lengthInBytes / sizeof(WCHAR)) + { + WLog_Print(log, WLOG_ERROR, + "failed to read string, ActualCount (%" PRIu32 + ") * sizeof(WCHAR) > lengthInBytes (%" PRIu32 ")", + ActualCount, lengthInBytes); + return FALSE; + } + if (str) + *str = Stream_PointerAs(s, WCHAR); + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, MaxCount)) + return FALSE; + Stream_Seek(s, MaxCount); + return TRUE; +} + +static BOOL tsg_ndr_read_packet_header(wLog* log, wStream* s, TSG_PACKET_HEADER* header) +{ + const UINT32 ComponentId = TS_GATEWAY_TRANSPORT; + + WINPR_ASSERT(header); + if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 2, sizeof(UINT16))) + return FALSE; + Stream_Read_UINT16(s, header->ComponentId); + Stream_Read_UINT16(s, header->PacketId); + + if (ComponentId != header->ComponentId) + { + char buffer[64] = { 0 }; + char buffer2[64] = { 0 }; + WLog_Print(log, WLOG_ERROR, "Unexpected ComponentId: %s, Expected %s", + tsg_component_id_to_string(header->ComponentId, buffer, sizeof(buffer)), + tsg_component_id_to_string(ComponentId, buffer2, sizeof(buffer2))); + return FALSE; + } + + return TRUE; +} + +static BOOL tsg_ndr_write_packet_header(wLog* log, wStream* s, const TSG_PACKET_HEADER* header) +{ + WINPR_ASSERT(header); + if (!Stream_EnsureRemainingCapacity(s, 2 * sizeof(UINT16))) + return FALSE; + Stream_Write_UINT16(s, header->ComponentId); + Stream_Write_UINT16(s, header->PacketId); + return TRUE; +} + +static BOOL tsg_ndr_read_nap(wLog* log, wStream* s, TSG_CAPABILITY_NAP* nap) +{ + WINPR_ASSERT(nap); + + if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 1, sizeof(UINT32))) + return FALSE; + Stream_Read_UINT32(s, nap->capabilities); + return TRUE; +} + +static BOOL tsg_ndr_write_nap(wLog* log, wStream* s, const TSG_CAPABILITY_NAP* nap) +{ + WINPR_ASSERT(nap); + + if (!Stream_EnsureRemainingCapacity(s, 1 * sizeof(UINT32))) + return FALSE; + Stream_Write_UINT32(s, nap->capabilities); + return TRUE; +} + +static BOOL tsg_ndr_read_tsg_caps(wLog* log, wStream* s, TSG_PACKET_CAPABILITIES* caps) +{ + UINT32 capabilityType = 0; + UINT32 count = 0; + WINPR_ASSERT(caps); + + if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 3, sizeof(UINT32))) + return FALSE; + Stream_Read_UINT32(s, count); + Stream_Read_UINT32(s, capabilityType); + Stream_Read_UINT32(s, caps->capabilityType); + if (capabilityType != caps->capabilityType) + { + WLog_Print(log, WLOG_ERROR, "Inconsistent data, capabilityType %s != %s", + tsg_packet_id_to_string(capabilityType), + tsg_packet_id_to_string(caps->capabilityType)); + return FALSE; + } + switch (caps->capabilityType) + { + case TSG_CAPABILITY_TYPE_NAP: + return tsg_ndr_read_nap(log, s, &caps->tsgPacket.tsgCapNap); + default: + WLog_Print(log, WLOG_ERROR, + "unknown TSG_PACKET_CAPABILITIES::capabilityType 0x%04" PRIx32, + caps->capabilityType); + return FALSE; + } +} + +static BOOL tsg_ndr_write_tsg_caps(wLog* log, wStream* s, const TSG_PACKET_CAPABILITIES* caps) +{ + WINPR_ASSERT(caps); + + if (!Stream_EnsureRemainingCapacity(s, 2 * sizeof(UINT32))) + return FALSE; + Stream_Write_UINT32(s, caps->capabilityType); + Stream_Write_UINT32(s, caps->capabilityType); + + switch (caps->capabilityType) + { + case TSG_CAPABILITY_TYPE_NAP: + return tsg_ndr_write_nap(log, s, &caps->tsgPacket.tsgCapNap); + default: + WLog_Print(log, WLOG_ERROR, + "unknown TSG_PACKET_CAPABILITIES::capabilityType 0x%04" PRIx32, + caps->capabilityType); + return FALSE; + } +} + +static BOOL tsg_ndr_read_version_caps(wLog* log, wStream* s, UINT32* index, + TSG_PACKET_VERSIONCAPS* caps) +{ + WINPR_ASSERT(caps); + if (!tsg_ndr_read_packet_header(log, s, &caps->tsgHeader)) + return FALSE; + + UINT32 TSGCapsPtr = 0; + if (!tsg_ndr_pointer_read(log, s, index, &TSGCapsPtr, TRUE)) + return FALSE; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 10)) + return FALSE; + Stream_Read_UINT32(s, caps->numCapabilities); + Stream_Read_UINT16(s, caps->majorVersion); + Stream_Read_UINT16(s, caps->minorVersion); + Stream_Read_UINT16(s, caps->quarantineCapabilities); + /* 4-byte alignment */ + if (!tsg_stream_align(log, s, 4)) + return FALSE; + + return tsg_ndr_read_tsg_caps(log, s, &caps->tsgCaps); +} + +static BOOL tsg_ndr_write_version_caps(wLog* log, wStream* s, UINT32* index, + const TSG_PACKET_VERSIONCAPS* caps) +{ + WINPR_ASSERT(caps); + if (!tsg_ndr_write_packet_header(log, s, &caps->tsgHeader)) + return FALSE; + + if (!tsg_ndr_pointer_write(log, s, index, 1)) /* TsgCapsPtr (4 bytes) */ + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, 10)) + return FALSE; + Stream_Write_UINT32(s, caps->numCapabilities); + Stream_Write_UINT16(s, caps->majorVersion); + Stream_Write_UINT16(s, caps->minorVersion); + Stream_Write_UINT16(s, caps->quarantineCapabilities); + + /* 4-byte alignment (30 + 2) */ + Stream_Write_UINT16(s, 0x0000); /* pad (2 bytes) */ + Stream_Write_UINT32(s, caps->numCapabilities); /* MaxCount (4 bytes) */ + return tsg_ndr_write_tsg_caps(log, s, &caps->tsgCaps); +} + +static BOOL tsg_ndr_read_quarenc_response(wLog* log, wStream* s, UINT32* index, + TSG_PACKET_QUARENC_RESPONSE* quarenc) +{ + WINPR_ASSERT(quarenc); + UINT32 CertChainDataPtr = 0; + UINT32 VersionCapsPtr = 0; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8)) + return FALSE; + Stream_Read_UINT32(s, quarenc->flags); + Stream_Read_UINT32(s, quarenc->certChainLen); + + if (!tsg_ndr_pointer_read(log, s, index, &CertChainDataPtr, quarenc->certChainLen != 0)) + return FALSE; + + if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 1, sizeof(quarenc->nonce))) + return FALSE; + Stream_Read(s, &quarenc->nonce, sizeof(quarenc->nonce)); + + if (!tsg_ndr_pointer_read(log, s, index, &VersionCapsPtr, TRUE)) + return FALSE; + + return TRUE; +} + +static BOOL tsg_ndr_read_quarenc_data(wLog* log, wStream* s, UINT32* index, + TSG_PACKET_QUARENC_RESPONSE* quarenc) +{ + WINPR_ASSERT(quarenc); + + if (quarenc->certChainLen > 0) + { + /* [MS-TSGU] 2.2.9.2.1.6 TSG_PACKET_QUARENC_RESPONSE::certChainLen number of WCHAR */ + if (!tsg_ndr_read_string(log, s, &quarenc->certChainData, + quarenc->certChainLen * sizeof(WCHAR))) + return FALSE; + /* 4-byte alignment */ + if (!tsg_stream_align(log, s, 4)) + return FALSE; + } + + return tsg_ndr_read_version_caps(log, s, index, &quarenc->versionCaps); +} + +static BOOL tsg_ndr_write_auth(wLog* log, wStream* s, UINT32* index, const TSG_PACKET_AUTH* auth) +{ + WINPR_ASSERT(auth); + + if (!tsg_ndr_write_version_caps(log, s, index, &auth->tsgVersionCaps)) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + + Stream_Write_UINT32(s, auth->cookieLen); + if (!tsg_ndr_pointer_write(log, s, index, auth->cookieLen)) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, auth->cookieLen)) + return FALSE; + Stream_Write(s, auth->cookie, auth->cookieLen); + return TRUE; +} + +static BOOL tsg_ndr_write_reauth(wLog* log, wStream* s, UINT32* index, + const TSG_PACKET_REAUTH* auth) +{ + WINPR_ASSERT(auth); + + if (!Stream_EnsureRemainingCapacity(s, 12)) + return FALSE; + + Stream_Write_UINT64(s, auth->tunnelContext); /* TunnelContext (8 bytes) */ + Stream_Write_UINT32(s, auth->packetId); /* PacketId (4 bytes) */ + + switch (auth->packetId) + { + case TSG_PACKET_TYPE_VERSIONCAPS: + return tsg_ndr_write_version_caps(log, s, index, + &auth->tsgInitialPacket.packetVersionCaps); + case TSG_PACKET_TYPE_AUTH: + return tsg_ndr_write_auth(log, s, index, &auth->tsgInitialPacket.packetAuth); + default: + WLog_Print(log, WLOG_ERROR, "unexpected packetId %s", + tsg_packet_id_to_string(auth->packetId)); + return FALSE; + } +} + +static BOOL tsg_ndr_read_packet_response(wLog* log, wStream* s, UINT32* index, + TSG_PACKET_RESPONSE* response) +{ + UINT32 ResponseDataPtr = 0; + UINT32 MaxSizeValue = 0; + UINT32 MaxOffsetValue = 0; + UINT32 idleTimeout = 0; + + WINPR_ASSERT(response); + + if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 2, sizeof(UINT32))) + return FALSE; + Stream_Read_UINT32(s, response->flags); /* Flags (4 bytes) */ + Stream_Seek_UINT32(s); /* Reserved (4 bytes) */ + + if (response->flags != TSG_PACKET_TYPE_QUARREQUEST) + { + WLog_Print(log, WLOG_ERROR, + "Unexpected Packet Response Flags: 0x%08" PRIX32 + ", Expected TSG_PACKET_TYPE_QUARREQUEST", + response->flags); + return FALSE; + } + + if (!tsg_ndr_pointer_read(log, s, index, &ResponseDataPtr, TRUE)) + return FALSE; + + if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, s, 10, sizeof(UINT32))) + return FALSE; + + Stream_Read_UINT32(s, response->responseDataLen); /* ResponseDataLength (4 bytes) */ + Stream_Read_INT32( + s, response->redirectionFlags.enableAllRedirections); /* EnableAllRedirections (4 bytes) */ + Stream_Read_INT32( + s, + response->redirectionFlags.disableAllRedirections); /* DisableAllRedirections (4 bytes) */ + Stream_Read_INT32(s, response->redirectionFlags + .driveRedirectionDisabled); /* DriveRedirectionDisabled (4 bytes) */ + Stream_Read_INT32(s, + response->redirectionFlags + .printerRedirectionDisabled); /* PrinterRedirectionDisabled (4 bytes) */ + Stream_Read_INT32( + s, + response->redirectionFlags.portRedirectionDisabled); /* PortRedirectionDisabled (4 bytes) */ + Stream_Read_INT32(s, response->redirectionFlags.reserved); /* Reserved (4 bytes) */ + Stream_Read_INT32( + s, response->redirectionFlags + .clipboardRedirectionDisabled); /* ClipboardRedirectionDisabled (4 bytes) */ + Stream_Read_INT32( + s, + response->redirectionFlags.pnpRedirectionDisabled); /* PnpRedirectionDisabled (4 bytes) */ + + Stream_Read_UINT32(s, MaxSizeValue); /* (4 bytes) */ + Stream_Read_UINT32(s, MaxOffsetValue); /* (4 bytes) */ + + if (MaxSizeValue != response->responseDataLen) + { + WLog_Print(log, WLOG_ERROR, "Unexpected size value: %" PRIu32 ", expected: %" PRIu32 "", + MaxSizeValue, response->responseDataLen); + return FALSE; + } + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, MaxSizeValue)) + return FALSE; + + if (MaxSizeValue == 4) + Stream_Read_UINT32(s, idleTimeout); + else + Stream_Seek(s, MaxSizeValue); /* ResponseData */ + return TRUE; +} + +WINPR_ATTR_FORMAT_ARG(3, 4) +static BOOL tsg_print(char** buffer, size_t* len, WINPR_FORMAT_ARG const char* fmt, ...) +{ + int rc = 0; + va_list ap = { 0 }; + if (!buffer || !len || !fmt) + return FALSE; + va_start(ap, fmt); + rc = vsnprintf(*buffer, *len, fmt, ap); + va_end(ap); + if ((rc < 0) || ((size_t)rc > *len)) + return FALSE; + *len -= (size_t)rc; + *buffer += (size_t)rc; + return TRUE; +} + +static BOOL tsg_packet_header_to_string(char** buffer, size_t* length, + const TSG_PACKET_HEADER* header) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(header); + + return tsg_print(buffer, length, + "header { ComponentId=0x%04" PRIx16 ", PacketId=0x%04" PRIx16 " }", + header->ComponentId, header->PacketId); +} + +static BOOL tsg_type_capability_nap_to_string(char** buffer, size_t* length, + const TSG_CAPABILITY_NAP* cur) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(cur); + + return tsg_print(buffer, length, "%s { capabilities=0x%08" PRIx32 " }", + tsg_packet_id_to_string(TSG_CAPABILITY_TYPE_NAP), cur->capabilities); +} + +static BOOL tsg_packet_capabilities_to_string(char** buffer, size_t* length, + const TSG_PACKET_CAPABILITIES* caps, UINT32 numCaps) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "capabilities { ")) + return FALSE; + + for (UINT32 x = 0; x < numCaps; x++) + { + const TSG_PACKET_CAPABILITIES* cur = &caps[x]; + switch (cur->capabilityType) + { + case TSG_CAPABILITY_TYPE_NAP: + if (!tsg_type_capability_nap_to_string(buffer, length, &cur->tsgPacket.tsgCapNap)) + return FALSE; + break; + default: + if (!tsg_print(buffer, length, "TSG_UNKNOWN_CAPABILITY")) + return FALSE; + break; + } + } + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_versioncaps_to_string(char** buffer, size_t* length, + const TSG_PACKET_VERSIONCAPS* caps) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "versioncaps { ")) + return FALSE; + if (!tsg_packet_header_to_string(buffer, length, &caps->tsgHeader)) + return FALSE; + + if (!tsg_print(buffer, length, " ")) + return FALSE; + + if (!tsg_packet_capabilities_to_string(buffer, length, &caps->tsgCaps, caps->numCapabilities)) + return FALSE; + + if (!tsg_print(buffer, length, + " numCapabilities=0x%08" PRIx32 ", majorVersion=0x%04" PRIx16 + ", minorVersion=0x%04" PRIx16 ", quarantineCapabilities=0x%04" PRIx16, + caps->numCapabilities, caps->majorVersion, caps->minorVersion, + caps->quarantineCapabilities)) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_quarconfigrequest_to_string(char** buffer, size_t* length, + const TSG_PACKET_QUARCONFIGREQUEST* caps) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "quarconfigrequest { ")) + return FALSE; + + if (!tsg_print(buffer, length, " ")) + return FALSE; + + if (!tsg_print(buffer, length, " flags=0x%08" PRIx32, caps->flags)) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_quarrequest_to_string(char** buffer, size_t* length, + const TSG_PACKET_QUARREQUEST* caps) +{ + BOOL rc = FALSE; + char* name = NULL; + char* strdata = NULL; + + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "quarrequest { ")) + return FALSE; + + if (!tsg_print(buffer, length, " ")) + return FALSE; + + if (caps->nameLength > 0) + { + if (caps->nameLength > INT_MAX) + return FALSE; + name = ConvertWCharNToUtf8Alloc(caps->machineName, caps->nameLength, NULL); + if (!name) + return FALSE; + } + + strdata = winpr_BinToHexString(caps->data, caps->dataLen, TRUE); + if (strdata || (caps->dataLen == 0)) + rc = tsg_print(buffer, length, + " flags=0x%08" PRIx32 ", machineName=%s [%" PRIu32 "], data[%" PRIu32 "]=%s", + caps->flags, name, caps->nameLength, caps->dataLen, strdata); + free(name); + free(strdata); + if (!rc) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static const char* tsg_bool_to_string(BOOL val) +{ + if (val) + return "true"; + return "false"; +} + +static const char* tsg_redirection_flags_to_string(char* buffer, size_t size, + const TSG_REDIRECTION_FLAGS* flags) +{ + WINPR_ASSERT(buffer || (size == 0)); + WINPR_ASSERT(flags); + + (void)_snprintf( + buffer, size, + "enableAllRedirections=%s, disableAllRedirections=%s, driveRedirectionDisabled=%s, " + "printerRedirectionDisabled=%s, portRedirectionDisabled=%s, reserved=%s, " + "clipboardRedirectionDisabled=%s, pnpRedirectionDisabled=%s", + tsg_bool_to_string(flags->enableAllRedirections), + tsg_bool_to_string(flags->disableAllRedirections), + tsg_bool_to_string(flags->driveRedirectionDisabled), + tsg_bool_to_string(flags->printerRedirectionDisabled), + tsg_bool_to_string(flags->portRedirectionDisabled), tsg_bool_to_string(flags->reserved), + tsg_bool_to_string(flags->clipboardRedirectionDisabled), + tsg_bool_to_string(flags->pnpRedirectionDisabled)); + return buffer; +} + +static BOOL tsg_packet_response_to_string(char** buffer, size_t* length, + const TSG_PACKET_RESPONSE* caps) +{ + BOOL rc = FALSE; + char* strdata = NULL; + char tbuffer[8192] = { 0 }; + + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "response { ")) + return FALSE; + + if (!tsg_print(buffer, length, " ")) + return FALSE; + + strdata = winpr_BinToHexString(caps->responseData, caps->responseDataLen, TRUE); + if (strdata || (caps->responseDataLen == 0)) + rc = tsg_print( + buffer, length, + " flags=0x%08" PRIx32 ", reserved=0x%08" PRIx32 ", responseData[%" PRIu32 + "]=%s, redirectionFlags={ %s }", + caps->flags, caps->reserved, caps->responseDataLen, strdata, + tsg_redirection_flags_to_string(tbuffer, ARRAYSIZE(tbuffer), &caps->redirectionFlags)); + free(strdata); + if (!rc) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_quarenc_response_to_string(char** buffer, size_t* length, + const TSG_PACKET_QUARENC_RESPONSE* caps) +{ + BOOL rc = FALSE; + char* strdata = NULL; + RPC_CSTR uuid = NULL; + char tbuffer[8192] = { 0 }; + size_t size = ARRAYSIZE(tbuffer); + char* ptbuffer = tbuffer; + + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "quarenc_response { ")) + return FALSE; + + if (!tsg_print(buffer, length, " ")) + return FALSE; + + if (caps->certChainLen > 0) + { + if (caps->certChainLen > INT_MAX) + return FALSE; + strdata = ConvertWCharNToUtf8Alloc(caps->certChainData, caps->certChainLen, NULL); + if (!strdata) + return FALSE; + } + + tsg_packet_versioncaps_to_string(&ptbuffer, &size, &caps->versionCaps); + UuidToStringA(&caps->nonce, &uuid); + if (strdata || (caps->certChainLen == 0)) + rc = + tsg_print(buffer, length, + " flags=0x%08" PRIx32 ", certChain[%" PRIu32 "]=%s, nonce=%s, versionCaps=%s", + caps->flags, caps->certChainLen, strdata, uuid, tbuffer); + free(strdata); + RpcStringFreeA(&uuid); + if (!rc) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_message_response_to_string(char** buffer, size_t* length, + const TSG_PACKET_MSG_RESPONSE* caps) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "msg_response { ")) + return FALSE; + + if (!tsg_print(buffer, length, + " msgID=0x%08" PRIx32 ", msgType=0x%08" PRIx32 ", isMsgPresent=%" PRId32, + caps->msgID, caps->msgType, caps->isMsgPresent)) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_caps_response_to_string(char** buffer, size_t* length, + const TSG_PACKET_CAPS_RESPONSE* caps) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "caps_response { ")) + return FALSE; + + if (!tsg_packet_quarenc_response_to_string(buffer, length, &caps->pktQuarEncResponse)) + return FALSE; + + if (!tsg_packet_message_response_to_string(buffer, length, &caps->pktConsentMessage)) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_message_request_to_string(char** buffer, size_t* length, + const TSG_PACKET_MSG_REQUEST* caps) +{ + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "caps_message_request { ")) + return FALSE; + + if (!tsg_print(buffer, length, " maxMessagesPerBatch=%" PRIu32, caps->maxMessagesPerBatch)) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_auth_to_string(char** buffer, size_t* length, const TSG_PACKET_AUTH* caps) +{ + BOOL rc = FALSE; + char* strdata = NULL; + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "caps_message_request { ")) + return FALSE; + + if (!tsg_packet_versioncaps_to_string(buffer, length, &caps->tsgVersionCaps)) + return FALSE; + + strdata = winpr_BinToHexString(caps->cookie, caps->cookieLen, TRUE); + if (strdata || (caps->cookieLen == 0)) + rc = tsg_print(buffer, length, " cookie[%" PRIu32 "]=%s", caps->cookieLen, strdata); + free(strdata); + if (!rc) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static BOOL tsg_packet_reauth_to_string(char** buffer, size_t* length, + const TSG_PACKET_REAUTH* caps) +{ + BOOL rc = FALSE; + WINPR_ASSERT(buffer); + WINPR_ASSERT(length); + WINPR_ASSERT(caps); + + if (!tsg_print(buffer, length, "caps_message_request { ")) + return FALSE; + + if (!tsg_print(buffer, length, " tunnelContext=0x%016" PRIx64 ", packetId=%s [0x%08" PRIx32 "]", + caps->tunnelContext, tsg_packet_id_to_string(caps->packetId), caps->packetId)) + return FALSE; + + switch (caps->packetId) + { + case TSG_PACKET_TYPE_VERSIONCAPS: + rc = tsg_packet_versioncaps_to_string(buffer, length, + &caps->tsgInitialPacket.packetVersionCaps); + break; + case TSG_PACKET_TYPE_AUTH: + rc = tsg_packet_auth_to_string(buffer, length, &caps->tsgInitialPacket.packetAuth); + break; + default: + rc = tsg_print(buffer, length, "TODO: Unhandled packet type %s [0x%08" PRIx32 "]", + tsg_packet_id_to_string(caps->packetId), caps->packetId); + break; + } + + if (!rc) + return FALSE; + + return tsg_print(buffer, length, " }"); +} + +static const char* tsg_packet_to_string(const TSG_PACKET* packet) +{ + size_t len = 8192; + static char sbuffer[8193] = { 0 }; + char* buffer = sbuffer; + + if (!tsg_print(&buffer, &len, "TSG_PACKET { packetId=%s [0x%08" PRIx32 "], ", + tsg_packet_id_to_string(packet->packetId), packet->packetId)) + goto fail; + + switch (packet->packetId) + { + case TSG_PACKET_TYPE_HEADER: + if (!tsg_packet_header_to_string(&buffer, &len, &packet->tsgPacket.packetHeader)) + goto fail; + break; + case TSG_PACKET_TYPE_VERSIONCAPS: + if (!tsg_packet_versioncaps_to_string(&buffer, &len, + &packet->tsgPacket.packetVersionCaps)) + goto fail; + break; + case TSG_PACKET_TYPE_QUARCONFIGREQUEST: + if (!tsg_packet_quarconfigrequest_to_string(&buffer, &len, + &packet->tsgPacket.packetQuarConfigRequest)) + goto fail; + break; + case TSG_PACKET_TYPE_QUARREQUEST: + if (!tsg_packet_quarrequest_to_string(&buffer, &len, + &packet->tsgPacket.packetQuarRequest)) + goto fail; + break; + case TSG_PACKET_TYPE_RESPONSE: + if (!tsg_packet_response_to_string(&buffer, &len, &packet->tsgPacket.packetResponse)) + goto fail; + break; + case TSG_PACKET_TYPE_QUARENC_RESPONSE: + if (!tsg_packet_quarenc_response_to_string(&buffer, &len, + &packet->tsgPacket.packetQuarEncResponse)) + goto fail; + break; + case TSG_PACKET_TYPE_CAPS_RESPONSE: + if (!tsg_packet_caps_response_to_string(&buffer, &len, + &packet->tsgPacket.packetCapsResponse)) + goto fail; + break; + case TSG_PACKET_TYPE_MSGREQUEST_PACKET: + if (!tsg_packet_message_request_to_string(&buffer, &len, + &packet->tsgPacket.packetMsgRequest)) + goto fail; + break; + case TSG_PACKET_TYPE_MESSAGE_PACKET: + if (!tsg_packet_message_response_to_string(&buffer, &len, + &packet->tsgPacket.packetMsgResponse)) + goto fail; + break; + case TSG_PACKET_TYPE_AUTH: + if (!tsg_packet_auth_to_string(&buffer, &len, &packet->tsgPacket.packetAuth)) + goto fail; + break; + case TSG_PACKET_TYPE_REAUTH: + if (!tsg_packet_reauth_to_string(&buffer, &len, &packet->tsgPacket.packetReauth)) + goto fail; + break; + default: + if (!tsg_print(&buffer, &len, "INVALID")) + goto fail; + break; + } + + if (!tsg_print(&buffer, &len, " }")) + goto fail; + +fail: + return sbuffer; +} + +static BOOL tsg_stream_align(wLog* log, wStream* s, size_t align) +{ + size_t pos = 0; + size_t offset = 0; + + if (!s) + return FALSE; + + pos = Stream_GetPosition(s); + + if ((pos % align) != 0) + offset = align - pos % align; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, offset)) + return FALSE; + Stream_Seek(s, offset); + return TRUE; +} + +static BIO_METHOD* BIO_s_tsg(void); +/** + * RPC Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378623/ + * Remote Procedure Call: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378651/ + * RPC NDR Interface Reference: http://msdn.microsoft.com/en-us/library/windows/desktop/hh802752/ + */ + +/** + * call sequence with silent reauth: + * + * TsProxyCreateTunnelRequest() + * TsProxyCreateTunnelResponse(TunnelContext) + * TsProxyAuthorizeTunnelRequest(TunnelContext) + * TsProxyAuthorizeTunnelResponse() + * TsProxyMakeTunnelCallRequest(TunnelContext) + * TsProxyCreateChannelRequest(TunnelContext) + * TsProxyCreateChannelResponse(ChannelContext) + * TsProxySetupReceivePipeRequest(ChannelContext) + * TsProxySendToServerRequest(ChannelContext) + * + * ... + * + * TsProxyMakeTunnelCallResponse(reauth) + * TsProxyCreateTunnelRequest() + * TsProxyMakeTunnelCallRequest(TunnelContext) + * TsProxyCreateTunnelResponse(NewTunnelContext) + * TsProxyAuthorizeTunnelRequest(NewTunnelContext) + * TsProxyAuthorizeTunnelResponse() + * TsProxyCreateChannelRequest(NewTunnelContext) + * TsProxyCreateChannelResponse(NewChannelContext) + * TsProxyCloseChannelRequest(NewChannelContext) + * TsProxyCloseTunnelRequest(NewTunnelContext) + * TsProxyCloseChannelResponse(NullChannelContext) + * TsProxyCloseTunnelResponse(NullTunnelContext) + * TsProxySendToServerRequest(ChannelContext) + */ + +static int TsProxySendToServer(handle_t IDL_handle, const byte pRpcMessage[], UINT32 count, + const UINT32* lengths) +{ + wStream* s = NULL; + rdpTsg* tsg = NULL; + size_t length = 0; + const byte* buffer1 = NULL; + const byte* buffer2 = NULL; + const byte* buffer3 = NULL; + UINT32 buffer1Length = 0; + UINT32 buffer2Length = 0; + UINT32 buffer3Length = 0; + UINT32 numBuffers = 0; + UINT32 totalDataBytes = 0; + tsg = (rdpTsg*)IDL_handle; + buffer1Length = buffer2Length = buffer3Length = 0; + + if (count > 0) + { + numBuffers++; + buffer1 = &pRpcMessage[0]; + buffer1Length = lengths[0]; + totalDataBytes += lengths[0] + 4; + } + + if (count > 1) + { + numBuffers++; + buffer2 = &pRpcMessage[1]; + buffer2Length = lengths[1]; + totalDataBytes += lengths[1] + 4; + } + + if (count > 2) + { + numBuffers++; + buffer3 = &pRpcMessage[2]; + buffer3Length = lengths[2]; + totalDataBytes += lengths[2] + 4; + } + + length = 28ull + totalDataBytes; + if (length > INT_MAX) + return -1; + s = Stream_New(NULL, length); + + if (!s) + { + WLog_Print(tsg->log, WLOG_ERROR, "Stream_New failed!"); + return -1; + } + + /* PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE_NR (20 bytes) */ + if (!TsProxyWriteTunnelContext(tsg->log, s, &tsg->ChannelContext)) + goto fail; + Stream_Write_UINT32_BE(s, totalDataBytes); /* totalDataBytes (4 bytes) */ + Stream_Write_UINT32_BE(s, numBuffers); /* numBuffers (4 bytes) */ + + if (buffer1Length > 0) + Stream_Write_UINT32_BE(s, buffer1Length); /* buffer1Length (4 bytes) */ + + if (buffer2Length > 0) + Stream_Write_UINT32_BE(s, buffer2Length); /* buffer2Length (4 bytes) */ + + if (buffer3Length > 0) + Stream_Write_UINT32_BE(s, buffer3Length); /* buffer3Length (4 bytes) */ + + if (buffer1Length > 0) + Stream_Write(s, buffer1, buffer1Length); /* buffer1 (variable) */ + + if (buffer2Length > 0) + Stream_Write(s, buffer2, buffer2Length); /* buffer2 (variable) */ + + if (buffer3Length > 0) + Stream_Write(s, buffer3, buffer3Length); /* buffer3 (variable) */ + + if (!rpc_client_write_call(tsg->rpc, s, TsProxySendToServerOpnum)) + return -1; + + return (int)length; +fail: + Stream_Free(s, TRUE); + return -1; +} + +/** + * OpNum = 1 + * + * HRESULT TsProxyCreateTunnel( + * [in, ref] TSG_PACKET* tsgPacket, + * [out, ref] TSG_PACKET** tsgPacketResponse, + * [out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* tunnelContext, + * [out] unsigned long* tunnelId + * ); + */ + +static BOOL TsProxyCreateTunnelWriteRequest(rdpTsg* tsg, const TSG_PACKET* tsgPacket) +{ + BOOL rc = FALSE; + BOOL write = TRUE; + UINT16 opnum = 0; + wStream* s = NULL; + rdpRpc* rpc = NULL; + + if (!tsg || !tsg->rpc) + return FALSE; + + rpc = tsg->rpc; + WLog_Print(tsg->log, WLOG_DEBUG, "%s", tsg_packet_to_string(tsgPacket)); + s = Stream_New(NULL, 108); + + if (!s) + return FALSE; + + switch (tsgPacket->packetId) + { + case TSG_PACKET_TYPE_VERSIONCAPS: + { + UINT32 index = 0; + const TSG_PACKET_VERSIONCAPS* packetVersionCaps = + &tsgPacket->tsgPacket.packetVersionCaps; + + Stream_Write_UINT32(s, tsgPacket->packetId); /* PacketId (4 bytes) */ + Stream_Write_UINT32(s, tsgPacket->packetId); /* SwitchValue (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketVersionCapsPtr (4 bytes) */ + goto fail; + + if (!tsg_ndr_write_version_caps(tsg->log, s, &index, packetVersionCaps)) + goto fail; + /** + * The following 60-byte structure is apparently undocumented, + * but parts of it can be matched to known C706 data structures. + */ + /* + * 8-byte constant (8A E3 13 71 02 F4 36 71) also observed here: + * http://lists.samba.org/archive/cifs-protocol/2010-July/001543.html + */ + Stream_Write_UINT8(s, 0x8A); + Stream_Write_UINT8(s, 0xE3); + Stream_Write_UINT8(s, 0x13); + Stream_Write_UINT8(s, 0x71); + Stream_Write_UINT8(s, 0x02); + Stream_Write_UINT8(s, 0xF4); + Stream_Write_UINT8(s, 0x36); + Stream_Write_UINT8(s, 0x71); + Stream_Write_UINT32(s, 0x00040001); /* 1.4 (version?) */ + Stream_Write_UINT32(s, 0x00000001); /* 1 (element count?) */ + /* p_cont_list_t */ + Stream_Write_UINT8(s, 2); /* ncontext_elem */ + Stream_Write_UINT8(s, 0x40); /* reserved1 */ + Stream_Write_UINT16(s, 0x0028); /* reserved2 */ + /* p_syntax_id_t */ + Stream_Write(s, &TSGU_UUID, sizeof(p_uuid_t)); + Stream_Write_UINT32(s, TSGU_SYNTAX_IF_VERSION); + /* p_syntax_id_t */ + Stream_Write(s, &NDR_UUID, sizeof(p_uuid_t)); + Stream_Write_UINT32(s, NDR_SYNTAX_IF_VERSION); + opnum = TsProxyCreateTunnelOpnum; + } + break; + + case TSG_PACKET_TYPE_REAUTH: + { + const TSG_PACKET_REAUTH* packetReauth = &tsgPacket->tsgPacket.packetReauth; + UINT32 index = 0; + Stream_Write_UINT32(s, tsgPacket->packetId); /* PacketId (4 bytes) */ + Stream_Write_UINT32(s, tsgPacket->packetId); /* SwitchValue (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketReauthPtr (4 bytes) */ + goto fail; + if (!tsg_ndr_write_reauth(tsg->log, s, &index, packetReauth)) + goto fail; + opnum = TsProxyCreateTunnelOpnum; + } + break; + + default: + WLog_Print(tsg->log, WLOG_WARN, "unexpected packetId %s", + tsg_packet_id_to_string(tsgPacket->packetId)); + write = FALSE; + break; + } + + rc = TRUE; + + if (write) + return rpc_client_write_call(rpc, s, opnum); +fail: + Stream_Free(s, TRUE); + return rc; +} + +static BOOL tsg_ndr_read_consent_message(wLog* log, rdpContext* context, wStream* s, UINT32* index) +{ + TSG_PACKET_STRING_MESSAGE packetStringMessage = { 0 }; + UINT32 Pointer = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(index); + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 12)) + return FALSE; + + Stream_Read_INT32(s, packetStringMessage.isDisplayMandatory); + Stream_Read_INT32(s, packetStringMessage.isConsentMandatory); + Stream_Read_UINT32(s, packetStringMessage.msgBytes); + + if (!tsg_ndr_pointer_read(log, s, index, &Pointer, FALSE)) + return FALSE; + + if (Pointer) + { + if (packetStringMessage.msgBytes > TSG_MESSAGING_MAX_MESSAGE_LENGTH) + { + WLog_Print(log, WLOG_ERROR, "Out of Spec Message Length %" PRIu32 "", + packetStringMessage.msgBytes); + return FALSE; + } + if (!tsg_ndr_read_string(log, s, &packetStringMessage.msgBuffer, + packetStringMessage.msgBytes)) + return FALSE; + + if (context->instance) + { + return IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, + TSG_ASYNC_MESSAGE_CONSENT_MESSAGE + ? GATEWAY_MESSAGE_CONSENT + : TSG_ASYNC_MESSAGE_SERVICE_MESSAGE, + packetStringMessage.isDisplayMandatory != 0, + packetStringMessage.isConsentMandatory != 0, + packetStringMessage.msgBytes, packetStringMessage.msgBuffer); + } + } + return TRUE; +} + +static BOOL tsg_ndr_read_tunnel_context(wLog* log, wStream* s, CONTEXT_HANDLE* tunnelContext, + UINT32* tunnelId) +{ + + if (!tsg_stream_align(log, s, 4)) + return FALSE; + + /* TunnelContext (20 bytes) */ + if (!TsProxyReadTunnelContext(log, s, tunnelContext)) + return FALSE; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8)) + return FALSE; + + WINPR_ASSERT(tunnelId); + Stream_Read_UINT32(s, *tunnelId); /* TunnelId (4 bytes) */ + + INT32 ReturnValue = 0; + Stream_Read_INT32(s, ReturnValue); /* ReturnValue (4 bytes) */ + if (ReturnValue != NO_ERROR) + WLog_WARN(TAG, "ReturnValue=%s", NtStatus2Tag(ReturnValue)); + return TRUE; +} + +static BOOL tsg_ndr_read_caps_response(wLog* log, rdpContext* context, wStream* s, UINT32* index, + UINT32 PacketPtr, TSG_PACKET_CAPS_RESPONSE* caps, + CONTEXT_HANDLE* tunnelContext, UINT32* tunnelId) +{ + UINT32 PacketQuarResponsePtr = 0; + UINT32 MessageSwitchValue = 0; + UINT32 MsgId = 0; + UINT32 MsgType = 0; + UINT32 IsMessagePresent = 0; + + WINPR_ASSERT(context); + WINPR_ASSERT(index); + WINPR_ASSERT(caps); + + if (!tsg_ndr_pointer_read(log, s, index, &PacketQuarResponsePtr, TRUE)) + goto fail; + + if (!tsg_ndr_read_quarenc_response(log, s, index, &caps->pktQuarEncResponse)) + goto fail; + + if (PacketPtr) + { + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 16)) + goto fail; + + Stream_Read_UINT32(s, MsgId); /* MsgId (4 bytes) */ + Stream_Read_UINT32(s, MsgType); /* MsgType (4 bytes) */ + Stream_Read_UINT32(s, IsMessagePresent); /* IsMessagePresent (4 bytes) */ + Stream_Read_UINT32(s, MessageSwitchValue); /* MessageSwitchValue (4 bytes) */ + } + + { + UINT32 MsgPtr = 0; + if (!tsg_ndr_pointer_read(log, s, index, &MsgPtr, TRUE)) + return FALSE; + } + if (!tsg_ndr_read_quarenc_data(log, s, index, &caps->pktQuarEncResponse)) + goto fail; + + switch (MessageSwitchValue) + { + case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE: + case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE: + { + if (!tsg_ndr_read_consent_message(log, context, s, index)) + goto fail; + } + break; + + case TSG_ASYNC_MESSAGE_REAUTH: + { + if (!tsg_stream_align(log, s, 8)) + goto fail; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 8)) + goto fail; + + Stream_Seek_UINT64(s); /* TunnelContext (8 bytes) */ + } + break; + + default: + WLog_Print(log, WLOG_ERROR, "Unexpected Message Type: 0x%" PRIX32 "", + MessageSwitchValue); + goto fail; + } + + return tsg_ndr_read_tunnel_context(log, s, tunnelContext, tunnelId); +fail: + return FALSE; +} + +static BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, const RPC_PDU* pdu, + CONTEXT_HANDLE* tunnelContext, UINT32* tunnelId) +{ + BOOL rc = FALSE; + UINT32 index = 0; + TSG_PACKET packet = { 0 }; + UINT32 SwitchValue = 0; + rdpContext* context = NULL; + UINT32 PacketPtr = 0; + + WINPR_ASSERT(tsg); + WINPR_ASSERT(tsg->rpc); + WINPR_ASSERT(tsg->rpc->transport); + + context = transport_get_context(tsg->rpc->transport); + WINPR_ASSERT(context); + + if (!pdu) + return FALSE; + + if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketPtr, TRUE)) + goto fail; + + if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, 8)) + goto fail; + Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */ + Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */ + + WLog_Print(tsg->log, WLOG_DEBUG, "%s", tsg_packet_id_to_string(packet.packetId)); + + if ((packet.packetId == TSG_PACKET_TYPE_CAPS_RESPONSE) && + (SwitchValue == TSG_PACKET_TYPE_CAPS_RESPONSE)) + { + if (!tsg_ndr_read_caps_response(tsg->log, context, pdu->s, &index, PacketPtr, + &packet.tsgPacket.packetCapsResponse, tunnelContext, + tunnelId)) + goto fail; + } + else if ((packet.packetId == TSG_PACKET_TYPE_QUARENC_RESPONSE) && + (SwitchValue == TSG_PACKET_TYPE_QUARENC_RESPONSE)) + { + UINT32 PacketQuarResponsePtr = 0; + + if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketQuarResponsePtr, TRUE)) + goto fail; + + if (!tsg_ndr_read_quarenc_response(tsg->log, pdu->s, &index, + &packet.tsgPacket.packetQuarEncResponse)) + goto fail; + + if (!tsg_ndr_read_quarenc_data(tsg->log, pdu->s, &index, + &packet.tsgPacket.packetQuarEncResponse)) + goto fail; + + if (!tsg_ndr_read_tunnel_context(tsg->log, pdu->s, tunnelContext, tunnelId)) + goto fail; + } + else + { + WLog_Print(tsg->log, WLOG_ERROR, + "Unexpected PacketId: 0x%08" PRIX32 ", Expected TSG_PACKET_TYPE_CAPS_RESPONSE " + "or TSG_PACKET_TYPE_QUARENC_RESPONSE", + packet.packetId); + goto fail; + } + + rc = TRUE; +fail: + return rc; +} + +/** + * OpNum = 2 + * + * HRESULT TsProxyAuthorizeTunnel( + * [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext, + * [in, ref] TSG_PACKET* tsgPacket, + * [out, ref] TSG_PACKET** tsgPacketResponse + * ); + * + */ + +static BOOL TsProxyAuthorizeTunnelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunnelContext) +{ + size_t pad = 0; + wStream* s = NULL; + size_t count = 0; + size_t offset = 0; + rdpRpc* rpc = NULL; + + if (!tsg || !tsg->rpc || !tunnelContext || !tsg->MachineName) + return FALSE; + + count = _wcslen(tsg->MachineName) + 1; + if (count > UINT32_MAX) + return FALSE; + + rpc = tsg->rpc; + WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyAuthorizeTunnelWriteRequest"); + s = Stream_New(NULL, 1024 + count * 2); + + if (!s) + return FALSE; + + if (!TsProxyWriteTunnelContext(tsg->log, s, tunnelContext)) + { + Stream_Free(s, TRUE); + return FALSE; + } + + /* 4-byte alignment */ + UINT32 index = 0; + Stream_Write_UINT32(s, TSG_PACKET_TYPE_QUARREQUEST); /* PacketId (4 bytes) */ + Stream_Write_UINT32(s, TSG_PACKET_TYPE_QUARREQUEST); /* SwitchValue (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketQuarRequestPtr (4 bytes) */ + goto fail; + Stream_Write_UINT32(s, 0x00000000); /* Flags (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* MachineNamePtr (4 bytes) */ + goto fail; + Stream_Write_UINT32(s, (UINT32)count); /* NameLength (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* DataPtr (4 bytes) */ + goto fail; + Stream_Write_UINT32(s, 0); /* DataLength (4 bytes) */ + /* MachineName */ + if (!tsg_ndr_write_string(tsg->log, s, tsg->MachineName, count)) + goto fail; + /* 4-byte alignment */ + offset = Stream_GetPosition(s); + pad = rpc_offset_align(&offset, 4); + Stream_Zero(s, pad); + Stream_Write_UINT32(s, 0x00000000); /* MaxCount (4 bytes) */ + Stream_SealLength(s); + return rpc_client_write_call(rpc, s, TsProxyAuthorizeTunnelOpnum); +fail: + Stream_Free(s, TRUE); + return FALSE; +} + +static UINT32 tsg_redir_to_flags(const TSG_REDIRECTION_FLAGS* redirect) +{ + UINT32 flags = 0; + if (redirect->enableAllRedirections) + flags |= HTTP_TUNNEL_REDIR_ENABLE_ALL; + if (redirect->disableAllRedirections) + flags |= HTTP_TUNNEL_REDIR_DISABLE_ALL; + + if (redirect->driveRedirectionDisabled) + flags |= HTTP_TUNNEL_REDIR_DISABLE_DRIVE; + if (redirect->printerRedirectionDisabled) + flags |= HTTP_TUNNEL_REDIR_DISABLE_PRINTER; + if (redirect->portRedirectionDisabled) + flags |= HTTP_TUNNEL_REDIR_DISABLE_PORT; + if (redirect->clipboardRedirectionDisabled) + flags |= HTTP_TUNNEL_REDIR_DISABLE_CLIPBOARD; + if (redirect->pnpRedirectionDisabled) + flags |= HTTP_TUNNEL_REDIR_DISABLE_PNP; + return flags; +} + +static BOOL tsg_redirect_apply(rdpTsg* tsg, const TSG_REDIRECTION_FLAGS* redirect) +{ + WINPR_ASSERT(tsg); + WINPR_ASSERT(redirect); + + rdpTransport* transport = tsg->transport; + WINPR_ASSERT(transport); + + rdpContext* context = transport_get_context(transport); + UINT32 redirFlags = tsg_redir_to_flags(redirect); + return utils_apply_gateway_policy(tsg->log, context, redirFlags, "TSG"); +} + +static BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, const RPC_PDU* pdu) +{ + BOOL rc = FALSE; + UINT32 SwitchValue = 0; + UINT32 index = 0; + TSG_PACKET packet = { 0 }; + UINT32 PacketPtr = 0; + UINT32 PacketResponsePtr = 0; + + WINPR_ASSERT(tsg); + WINPR_ASSERT(pdu); + + wLog* log = tsg->log; + WINPR_ASSERT(log); + + if (!tsg_ndr_pointer_read(log, pdu->s, &index, &PacketPtr, TRUE)) + goto fail; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 8)) + goto fail; + Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */ + Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */ + + WLog_Print(log, WLOG_DEBUG, "%s", tsg_packet_id_to_string(packet.packetId)); + + if (packet.packetId == E_PROXY_NAP_ACCESSDENIED) + { + WLog_Print(log, WLOG_ERROR, "status: E_PROXY_NAP_ACCESSDENIED (0x%08X)", + E_PROXY_NAP_ACCESSDENIED); + WLog_Print(log, WLOG_ERROR, + "Ensure that the Gateway Connection Authorization Policy is correct"); + goto fail; + } + + if ((packet.packetId != TSG_PACKET_TYPE_RESPONSE) || (SwitchValue != TSG_PACKET_TYPE_RESPONSE)) + { + WLog_Print(log, WLOG_ERROR, + "Unexpected PacketId: 0x%08" PRIX32 ", Expected TSG_PACKET_TYPE_RESPONSE", + packet.packetId); + goto fail; + } + + if (!tsg_ndr_pointer_read(log, pdu->s, &index, &PacketResponsePtr, TRUE)) + goto fail; + + if (!tsg_ndr_read_packet_response(log, pdu->s, &index, &packet.tsgPacket.packetResponse)) + goto fail; + + rc = TRUE; + + if (packet.tsgPacket.packetResponse.flags & TSG_PACKET_TYPE_QUARREQUEST) + rc = tsg_redirect_apply(tsg, &packet.tsgPacket.packetResponse.redirectionFlags); +fail: + return rc; +} + +/** + * OpNum = 3 + * + * HRESULT TsProxyMakeTunnelCall( + * [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext, + * [in] unsigned long procId, + * [in, ref] TSG_PACKET* tsgPacket, + * [out, ref] TSG_PACKET** tsgPacketResponse + * ); + */ + +static BOOL TsProxyMakeTunnelCallWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunnelContext, + UINT32 procId) +{ + wStream* s = NULL; + rdpRpc* rpc = NULL; + + if (!tsg || !tsg->rpc || !tunnelContext) + return FALSE; + + rpc = tsg->rpc; + WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyMakeTunnelCallWriteRequest"); + s = Stream_New(NULL, 40); + + if (!s) + return FALSE; + + /* TunnelContext (20 bytes) */ + UINT32 index = 0; + if (!TsProxyWriteTunnelContext(tsg->log, s, tunnelContext)) + goto fail; + Stream_Write_UINT32(s, procId); /* ProcId (4 bytes) */ + /* 4-byte alignment */ + Stream_Write_UINT32(s, TSG_PACKET_TYPE_MSGREQUEST_PACKET); /* PacketId (4 bytes) */ + Stream_Write_UINT32(s, TSG_PACKET_TYPE_MSGREQUEST_PACKET); /* SwitchValue (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) /* PacketMsgRequestPtr (4 bytes) */ + goto fail; + Stream_Write_UINT32(s, 0x00000001); /* MaxMessagesPerBatch (4 bytes) */ + return rpc_client_write_call(rpc, s, TsProxyMakeTunnelCallOpnum); +fail: + Stream_Free(s, TRUE); + return FALSE; +} + +static BOOL TsProxyReadPacketSTringMessage(rdpTsg* tsg, wStream* s, TSG_PACKET_STRING_MESSAGE* msg) +{ + UINT32 ConsentMessagePtr = 0; + UINT32 MsgPtr = 0; + UINT32 index = 0; + + if (!tsg || !s || !msg) + return FALSE; + + if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, s, 32)) + return FALSE; + + if (!tsg_ndr_pointer_read(tsg->log, s, &index, &ConsentMessagePtr, TRUE)) + return FALSE; + + Stream_Read_INT32(s, msg->isDisplayMandatory); /* IsDisplayMandatory (4 bytes) */ + Stream_Read_INT32(s, msg->isConsentMandatory); /* IsConsentMandatory (4 bytes) */ + Stream_Read_UINT32(s, msg->msgBytes); /* MsgBytes (4 bytes) */ + + if (!tsg_ndr_pointer_read(tsg->log, s, &index, &MsgPtr, TRUE)) + return FALSE; + + return tsg_ndr_read_string(tsg->log, s, &msg->msgBuffer, msg->msgBytes); +} + +static BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, const RPC_PDU* pdu) +{ + BOOL rc = FALSE; + UINT32 index = 0; + UINT32 SwitchValue = 0; + TSG_PACKET packet; + rdpContext* context = NULL; + char* messageText = NULL; + TSG_PACKET_MSG_RESPONSE packetMsgResponse = { 0 }; + TSG_PACKET_STRING_MESSAGE packetStringMessage = { 0 }; + TSG_PACKET_REAUTH_MESSAGE packetReauthMessage = { 0 }; + UINT32 PacketPtr = 0; + UINT32 PacketMsgResponsePtr = 0; + + WINPR_ASSERT(tsg); + WINPR_ASSERT(tsg->rpc); + + context = transport_get_context(tsg->rpc->transport); + WINPR_ASSERT(context); + + /* This is an asynchronous response */ + + if (!pdu) + return FALSE; + + if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, 28)) + goto fail; + + if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketPtr, TRUE)) + goto fail; + + Stream_Read_UINT32(pdu->s, packet.packetId); /* PacketId (4 bytes) */ + Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */ + + WLog_Print(tsg->log, WLOG_DEBUG, "%s", tsg_packet_id_to_string(packet.packetId)); + + if ((packet.packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) || + (SwitchValue != TSG_PACKET_TYPE_MESSAGE_PACKET)) + { + WLog_Print(tsg->log, WLOG_ERROR, + "Unexpected PacketId: 0x%08" PRIX32 ", Expected TSG_PACKET_TYPE_MESSAGE_PACKET", + packet.packetId); + goto fail; + } + + if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &PacketMsgResponsePtr, TRUE)) + goto fail; + + Stream_Read_UINT32(pdu->s, packetMsgResponse.msgID); /* MsgId (4 bytes) */ + Stream_Read_UINT32(pdu->s, packetMsgResponse.msgType); /* MsgType (4 bytes) */ + Stream_Read_INT32(pdu->s, packetMsgResponse.isMsgPresent); /* IsMsgPresent (4 bytes) */ + + /* 2.2.9.2.1.9 TSG_PACKET_MSG_RESPONSE: Ignore empty message body. */ + if (!packetMsgResponse.isMsgPresent) + { + rc = TRUE; + goto fail; + } + + Stream_Read_UINT32(pdu->s, SwitchValue); /* SwitchValue (4 bytes) */ + + switch (SwitchValue) + { + case TSG_ASYNC_MESSAGE_CONSENT_MESSAGE: + if (!TsProxyReadPacketSTringMessage(tsg, pdu->s, &packetStringMessage)) + goto fail; + + messageText = ConvertWCharNToUtf8Alloc( + packetStringMessage.msgBuffer, packetStringMessage.msgBytes / sizeof(WCHAR), NULL); + WLog_Print(tsg->log, WLOG_INFO, "Consent Message: %s", messageText); + free(messageText); + + if (context->instance) + { + rc = IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, + GATEWAY_MESSAGE_CONSENT, + packetStringMessage.isDisplayMandatory != 0, + packetStringMessage.isConsentMandatory != 0, + packetStringMessage.msgBytes, packetStringMessage.msgBuffer); + if (!rc) + goto fail; + } + + break; + + case TSG_ASYNC_MESSAGE_SERVICE_MESSAGE: + if (!TsProxyReadPacketSTringMessage(tsg, pdu->s, &packetStringMessage)) + goto fail; + + messageText = ConvertWCharNToUtf8Alloc( + packetStringMessage.msgBuffer, packetStringMessage.msgBytes / sizeof(WCHAR), NULL); + WLog_Print(tsg->log, WLOG_INFO, "Service Message: %s", messageText); + free(messageText); + + if (context->instance) + { + rc = IFCALLRESULT(TRUE, context->instance->PresentGatewayMessage, context->instance, + GATEWAY_MESSAGE_SERVICE, + packetStringMessage.isDisplayMandatory != 0, + packetStringMessage.isConsentMandatory != 0, + packetStringMessage.msgBytes, packetStringMessage.msgBuffer); + if (!rc) + goto fail; + } + break; + + case TSG_ASYNC_MESSAGE_REAUTH: + { + UINT32 ReauthMessagePtr = 0; + if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, 20)) + goto fail; + + if (!tsg_ndr_pointer_read(tsg->log, pdu->s, &index, &ReauthMessagePtr, TRUE)) + goto fail; + Stream_Seek_UINT32(pdu->s); /* alignment pad (4 bytes) */ + Stream_Read_UINT64(pdu->s, + packetReauthMessage.tunnelContext); /* TunnelContext (8 bytes) */ + Stream_Seek_UINT32(pdu->s); /* ReturnValue (4 bytes) */ + tsg->ReauthTunnelContext = packetReauthMessage.tunnelContext; + } + break; + + default: + WLog_Print(tsg->log, WLOG_ERROR, "unexpected message type: %" PRIu32 "", SwitchValue); + goto fail; + } + + rc = TRUE; +fail: + return rc; +} + +/** + * OpNum = 4 + * + * HRESULT TsProxyCreateChannel( + * [in] PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnelContext, + * [in, ref] PTSENDPOINTINFO tsEndPointInfo, + * [out] PCHANNEL_CONTEXT_HANDLE_SERIALIZE* channelContext, + * [out] unsigned long* channelId + * ); + */ + +static BOOL TsProxyCreateChannelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* tunnelContext) +{ + WINPR_ASSERT(tsg); + WINPR_ASSERT(tunnelContext); + + WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyCreateChannelWriteRequest"); + + if (!tsg->rpc || !tsg->Hostname) + return FALSE; + + rdpRpc* rpc = tsg->rpc; + const size_t count = _wcslen(tsg->Hostname) + 1; + if (count > UINT32_MAX) + return FALSE; + + wStream* s = Stream_New(NULL, 60 + count * 2); + if (!s) + return FALSE; + + /* TunnelContext (20 bytes) */ + if (!TsProxyWriteTunnelContext(tsg->log, s, tunnelContext)) + goto fail; + + /* TSENDPOINTINFO */ + UINT32 index = 0; + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) + goto fail; + Stream_Write_UINT32(s, 0x00000001); /* NumResourceNames (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 0)) + goto fail; + Stream_Write_UINT16(s, 0x0000); /* NumAlternateResourceNames (2 bytes) */ + Stream_Write_UINT16(s, 0x0000); /* Pad (2 bytes) */ + /* Port (4 bytes) */ + Stream_Write_UINT16(s, 0x0003); /* ProtocolId (RDP = 3) (2 bytes) */ + Stream_Write_UINT16(s, tsg->Port); /* PortNumber (0xD3D = 3389) (2 bytes) */ + Stream_Write_UINT32(s, 0x00000001); /* NumResourceNames (4 bytes) */ + if (!tsg_ndr_pointer_write(tsg->log, s, &index, 1)) + goto fail; + if (!tsg_ndr_write_string(tsg->log, s, tsg->Hostname, (UINT32)count)) + goto fail; + return rpc_client_write_call(rpc, s, TsProxyCreateChannelOpnum); + +fail: + Stream_Free(s, TRUE); + return FALSE; +} + +static BOOL TsProxyCreateChannelReadResponse(wLog* log, const RPC_PDU* pdu, + CONTEXT_HANDLE* channelContext, UINT32* channelId) +{ + BOOL rc = FALSE; + + WINPR_ASSERT(log); + WINPR_ASSERT(pdu); + WINPR_ASSERT(channelId); + + WLog_Print(log, WLOG_DEBUG, "TsProxyCreateChannelReadResponse"); + + if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 28)) + goto fail; + + /* ChannelContext (20 bytes) */ + if (!TsProxyReadTunnelContext(log, pdu->s, channelContext)) + goto fail; + if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(log, pdu->s, 2, sizeof(UINT32))) + goto fail; + Stream_Read_UINT32(pdu->s, *channelId); /* ChannelId (4 bytes) */ + Stream_Seek_UINT32(pdu->s); /* ReturnValue (4 bytes) */ + rc = TRUE; +fail: + return rc; +} + +/** + * HRESULT TsProxyCloseChannel( + * [in, out] PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE* context + * ); + */ + +static BOOL TsProxyCloseChannelWriteRequest(rdpTsg* tsg, CONTEXT_HANDLE* context) +{ + WINPR_ASSERT(tsg); + WINPR_ASSERT(context); + + WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyCloseChannelWriteRequest"); + + rdpRpc* rpc = tsg->rpc; + WINPR_ASSERT(rpc); + + wStream* s = Stream_New(NULL, 20); + + if (!s) + return FALSE; + + /* ChannelContext (20 bytes) */ + if (!TsProxyWriteTunnelContext(tsg->log, s, context)) + goto fail; + return rpc_client_write_call(rpc, s, TsProxyCloseChannelOpnum); +fail: + Stream_Free(s, TRUE); + return FALSE; +} + +static BOOL TsProxyCloseChannelReadResponse(wLog* log, const RPC_PDU* pdu, CONTEXT_HANDLE* context) +{ + BOOL rc = FALSE; + WLog_Print(log, WLOG_DEBUG, "TsProxyCloseChannelReadResponse"); + + if (!pdu) + return FALSE; + + if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 24)) + goto fail; + + /* ChannelContext (20 bytes) */ + if (!TsProxyReadTunnelContext(log, pdu->s, context)) + goto fail; + + { + const size_t len = sizeof(UINT32); + if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, len)) + goto fail; + Stream_Seek(pdu->s, len); /* ReturnValue (4 bytes) */ + rc = TRUE; + } +fail: + return rc; +} + +/** + * HRESULT TsProxyCloseTunnel( + * [in, out] PTUNNEL_CONTEXT_HANDLE_SERIALIZE* context + * ); + */ + +static BOOL TsProxyCloseTunnelWriteRequest(rdpTsg* tsg, const CONTEXT_HANDLE* context) +{ + WINPR_ASSERT(tsg); + WINPR_ASSERT(context); + + WLog_Print(tsg->log, WLOG_DEBUG, "TsProxyCloseTunnelWriteRequest"); + + rdpRpc* rpc = tsg->rpc; + WINPR_ASSERT(rpc); + + wStream* s = Stream_New(NULL, 20); + + if (!s) + return FALSE; + + /* TunnelContext (20 bytes) */ + if (!TsProxyWriteTunnelContext(tsg->log, s, context)) + goto fail; + return rpc_client_write_call(rpc, s, TsProxyCloseTunnelOpnum); +fail: + Stream_Free(s, TRUE); + return FALSE; +} + +static BOOL TsProxyCloseTunnelReadResponse(wLog* log, const RPC_PDU* pdu, CONTEXT_HANDLE* context) +{ + BOOL rc = FALSE; + + WINPR_ASSERT(log); + WINPR_ASSERT(pdu); + WINPR_ASSERT(context); + + WLog_Print(log, WLOG_DEBUG, "TsProxyCloseTunnelReadResponse"); + + if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, 24)) + goto fail; + + /* TunnelContext (20 bytes) */ + if (!TsProxyReadTunnelContext(log, pdu->s, context)) + goto fail; + { + const size_t len = sizeof(UINT32); + if (!Stream_CheckAndLogRequiredLengthWLog(log, pdu->s, len)) + goto fail; + Stream_Seek(pdu->s, len); /* ReturnValue (4 bytes) */ + rc = TRUE; + } +fail: + return rc; +} + +/** + * OpNum = 8 + * + * DWORD TsProxySetupReceivePipe( + * [in, max_is(32767)] byte pRpcMessage[] + * ); + */ + +static BOOL TsProxySetupReceivePipeWriteRequest(rdpTsg* tsg, const CONTEXT_HANDLE* channelContext) +{ + wStream* s = NULL; + rdpRpc* rpc = NULL; + WLog_Print(tsg->log, WLOG_DEBUG, "TsProxySetupReceivePipeWriteRequest"); + + WINPR_ASSERT(tsg); + WINPR_ASSERT(tsg->rpc); + + if (!channelContext) + return FALSE; + + rpc = tsg->rpc; + s = Stream_New(NULL, 20); + + if (!s) + return FALSE; + + /* ChannelContext (20 bytes) */ + if (!TsProxyWriteTunnelContext(tsg->log, s, channelContext)) + goto fail; + return rpc_client_write_call(rpc, s, TsProxySetupReceivePipeOpnum); +fail: + Stream_Free(s, TRUE); + return FALSE; +} + +static BOOL tsg_transition_to_state(rdpTsg* tsg, TSG_STATE state) +{ + WINPR_ASSERT(tsg); + const char* oldState = tsg_state_to_string(tsg->state); + const char* newState = tsg_state_to_string(state); + + WLog_Print(tsg->log, WLOG_DEBUG, "%s -> %s", oldState, newState); + return tsg_set_state(tsg, state); +} + +static BOOL tsg_initialize_version_caps(TSG_PACKET_VERSIONCAPS* packetVersionCaps) +{ + WINPR_ASSERT(packetVersionCaps); + + packetVersionCaps->tsgHeader.ComponentId = TS_GATEWAY_TRANSPORT; + packetVersionCaps->tsgHeader.PacketId = TSG_PACKET_TYPE_VERSIONCAPS; + packetVersionCaps->numCapabilities = 1; + packetVersionCaps->majorVersion = 1; + packetVersionCaps->minorVersion = 1; + packetVersionCaps->quarantineCapabilities = 0; + packetVersionCaps->tsgCaps.capabilityType = TSG_CAPABILITY_TYPE_NAP; + /* + * Using reduced capabilities appears to trigger + * TSG_PACKET_TYPE_QUARENC_RESPONSE instead of TSG_PACKET_TYPE_CAPS_RESPONSE + * + * However, reduced capabilities may break connectivity with servers enforcing features, such as + * "Only allow connections from Remote Desktop Services clients that support RD Gateway + * messaging" + */ + + packetVersionCaps->tsgCaps.tsgPacket.tsgCapNap.capabilities = + TSG_NAP_CAPABILITY_QUAR_SOH | TSG_NAP_CAPABILITY_IDLE_TIMEOUT | + TSG_MESSAGING_CAP_CONSENT_SIGN | TSG_MESSAGING_CAP_SERVICE_MSG | TSG_MESSAGING_CAP_REAUTH; + return TRUE; +} + +BOOL tsg_proxy_begin(rdpTsg* tsg) +{ + TSG_PACKET tsgPacket = { 0 }; + + WINPR_ASSERT(tsg); + + tsgPacket.packetId = TSG_PACKET_TYPE_VERSIONCAPS; + if (!tsg_initialize_version_caps(&tsgPacket.tsgPacket.packetVersionCaps) || + !TsProxyCreateTunnelWriteRequest(tsg, &tsgPacket)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateTunnel failure"); + tsg_transition_to_state(tsg, TSG_STATE_FINAL); + return FALSE; + } + + return tsg_transition_to_state(tsg, TSG_STATE_INITIAL); +} + +static BOOL tsg_proxy_reauth(rdpTsg* tsg) +{ + TSG_PACKET tsgPacket = { 0 }; + + WINPR_ASSERT(tsg); + + tsg->reauthSequence = TRUE; + TSG_PACKET_REAUTH* packetReauth = &tsgPacket.tsgPacket.packetReauth; + + tsgPacket.packetId = TSG_PACKET_TYPE_REAUTH; + packetReauth->tunnelContext = tsg->ReauthTunnelContext; + packetReauth->packetId = TSG_PACKET_TYPE_VERSIONCAPS; + + if (!tsg_initialize_version_caps(&packetReauth->tsgInitialPacket.packetVersionCaps)) + return FALSE; + + if (!TsProxyCreateTunnelWriteRequest(tsg, &tsgPacket)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateTunnel failure"); + tsg_transition_to_state(tsg, TSG_STATE_FINAL); + return FALSE; + } + + if (!TsProxyMakeTunnelCallWriteRequest(tsg, &tsg->TunnelContext, + TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCall failure"); + tsg_transition_to_state(tsg, TSG_STATE_FINAL); + return FALSE; + } + + return tsg_transition_to_state(tsg, TSG_STATE_INITIAL); +} + +BOOL tsg_recv_pdu(rdpTsg* tsg, const RPC_PDU* pdu) +{ + BOOL rc = FALSE; + RpcClientCall* call = NULL; + rdpRpc* rpc = NULL; + + WINPR_ASSERT(tsg); + WINPR_ASSERT(pdu); + WINPR_ASSERT(tsg->rpc); + + rpc = tsg->rpc; + + if (!(pdu->Flags & RPC_PDU_FLAG_STUB)) + { + const size_t len = 24; + if (!Stream_CheckAndLogRequiredLengthWLog(tsg->log, pdu->s, len)) + return FALSE; + Stream_Seek(pdu->s, len); + } + + switch (tsg->state) + { + case TSG_STATE_INITIAL: + { + CONTEXT_HANDLE* TunnelContext = NULL; + TunnelContext = (tsg->reauthSequence) ? &tsg->NewTunnelContext : &tsg->TunnelContext; + + if (!TsProxyCreateTunnelReadResponse(tsg, pdu, TunnelContext, &tsg->TunnelId)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateTunnelReadResponse failure"); + return FALSE; + } + + if (!tsg_transition_to_state(tsg, TSG_STATE_CONNECTED)) + return FALSE; + + if (!TsProxyAuthorizeTunnelWriteRequest(tsg, TunnelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyAuthorizeTunnel failure"); + return FALSE; + } + + rc = TRUE; + } + break; + + case TSG_STATE_CONNECTED: + { + CONTEXT_HANDLE* TunnelContext = + (tsg->reauthSequence) ? &tsg->NewTunnelContext : &tsg->TunnelContext; + + if (!TsProxyAuthorizeTunnelReadResponse(tsg, pdu)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyAuthorizeTunnelReadResponse failure"); + return FALSE; + } + + if (!tsg_transition_to_state(tsg, TSG_STATE_AUTHORIZED)) + return FALSE; + + if (!tsg->reauthSequence) + { + if (!TsProxyMakeTunnelCallWriteRequest(tsg, TunnelContext, + TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCall failure"); + return FALSE; + } + } + + if (!TsProxyCreateChannelWriteRequest(tsg, TunnelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateChannel failure"); + return FALSE; + } + + rc = TRUE; + } + break; + + case TSG_STATE_AUTHORIZED: + call = rpc_client_call_find_by_id(rpc->client, pdu->CallId); + + if (!call) + return FALSE; + + if (call->OpNum == TsProxyMakeTunnelCallOpnum) + { + if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCallReadResponse failure"); + return FALSE; + } + + rc = TRUE; + } + else if (call->OpNum == TsProxyCreateChannelOpnum) + { + CONTEXT_HANDLE ChannelContext; + + if (!TsProxyCreateChannelReadResponse(tsg->log, pdu, &ChannelContext, + &tsg->ChannelId)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCreateChannelReadResponse failure"); + return FALSE; + } + + if (!tsg->reauthSequence) + CopyMemory(&tsg->ChannelContext, &ChannelContext, sizeof(CONTEXT_HANDLE)); + else + CopyMemory(&tsg->NewChannelContext, &ChannelContext, sizeof(CONTEXT_HANDLE)); + + if (!tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CREATED)) + return FALSE; + + if (!tsg->reauthSequence) + { + if (!TsProxySetupReceivePipeWriteRequest(tsg, &tsg->ChannelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxySetupReceivePipe failure"); + return FALSE; + } + } + else + { + if (!TsProxyCloseChannelWriteRequest(tsg, &tsg->NewChannelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelWriteRequest failure"); + return FALSE; + } + + if (!TsProxyCloseTunnelWriteRequest(tsg, &tsg->NewTunnelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseTunnelWriteRequest failure"); + return FALSE; + } + } + + rc = tsg_transition_to_state(tsg, TSG_STATE_PIPE_CREATED); + tsg->reauthSequence = FALSE; + } + else + { + WLog_Print(tsg->log, WLOG_ERROR, + "TSG_STATE_AUTHORIZED unexpected OpNum: %" PRIu32 "\n", call->OpNum); + } + + break; + + case TSG_STATE_CHANNEL_CREATED: + break; + + case TSG_STATE_PIPE_CREATED: + call = rpc_client_call_find_by_id(rpc->client, pdu->CallId); + + if (!call) + return FALSE; + + if (call->OpNum == TsProxyMakeTunnelCallOpnum) + { + if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCallReadResponse failure"); + return FALSE; + } + + rc = TRUE; + + if (tsg->ReauthTunnelContext) + rc = tsg_proxy_reauth(tsg); + } + else if (call->OpNum == TsProxyCloseChannelOpnum) + { + CONTEXT_HANDLE ChannelContext; + + if (!TsProxyCloseChannelReadResponse(tsg->log, pdu, &ChannelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelReadResponse failure"); + return FALSE; + } + + rc = TRUE; + } + else if (call->OpNum == TsProxyCloseTunnelOpnum) + { + CONTEXT_HANDLE TunnelContext; + + if (!TsProxyCloseTunnelReadResponse(tsg->log, pdu, &TunnelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseTunnelReadResponse failure"); + return FALSE; + } + + rc = TRUE; + } + + break; + + case TSG_STATE_TUNNEL_CLOSE_PENDING: + { + CONTEXT_HANDLE ChannelContext; + + if (!TsProxyCloseChannelReadResponse(tsg->log, pdu, &ChannelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelReadResponse failure"); + return FALSE; + } + + if (!tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CLOSE_PENDING)) + return FALSE; + + if (!TsProxyCloseChannelWriteRequest(tsg, NULL)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseChannelWriteRequest failure"); + return FALSE; + } + + if (!TsProxyMakeTunnelCallWriteRequest(tsg, &tsg->TunnelContext, + TSG_TUNNEL_CANCEL_ASYNC_MSG_REQUEST)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyMakeTunnelCall failure"); + return FALSE; + } + + rc = TRUE; + } + break; + + case TSG_STATE_CHANNEL_CLOSE_PENDING: + { + CONTEXT_HANDLE TunnelContext; + + if (!TsProxyCloseTunnelReadResponse(tsg->log, pdu, &TunnelContext)) + { + WLog_Print(tsg->log, WLOG_ERROR, "TsProxyCloseTunnelReadResponse failure"); + return FALSE; + } + + rc = tsg_transition_to_state(tsg, TSG_STATE_FINAL); + } + break; + + case TSG_STATE_FINAL: + break; + default: + break; + } + + return rc; +} + +BOOL tsg_check_event_handles(rdpTsg* tsg) +{ + WINPR_ASSERT(tsg); + if (rpc_client_in_channel_recv(tsg->rpc) < 0) + return FALSE; + + if (rpc_client_out_channel_recv(tsg->rpc) < 0) + return FALSE; + + return TRUE; +} + +DWORD tsg_get_event_handles(rdpTsg* tsg, HANDLE* events, DWORD count) +{ + UINT32 nCount = 0; + rdpRpc* rpc = tsg->rpc; + RpcVirtualConnection* connection = rpc->VirtualConnection; + + if (events && (nCount < count)) + { + events[nCount] = rpc->client->PipeEvent; + nCount++; + } + else + return 0; + + if (connection->DefaultInChannel && connection->DefaultInChannel->common.tls) + { + if (events && (nCount < count)) + { + BIO_get_event(connection->DefaultInChannel->common.tls->bio, &events[nCount]); + nCount++; + } + else + return 0; + } + + if (connection->NonDefaultInChannel && connection->NonDefaultInChannel->common.tls) + { + if (events && (nCount < count)) + { + BIO_get_event(connection->NonDefaultInChannel->common.tls->bio, &events[nCount]); + nCount++; + } + else + return 0; + } + + if (connection->DefaultOutChannel && connection->DefaultOutChannel->common.tls) + { + if (events && (nCount < count)) + { + BIO_get_event(connection->DefaultOutChannel->common.tls->bio, &events[nCount]); + nCount++; + } + else + return 0; + } + + if (connection->NonDefaultOutChannel && connection->NonDefaultOutChannel->common.tls) + { + if (events && (nCount < count)) + { + BIO_get_event(connection->NonDefaultOutChannel->common.tls->bio, &events[nCount]); + nCount++; + } + else + return 0; + } + + return nCount; +} + +static BOOL tsg_set_hostname(rdpTsg* tsg, const char* hostname) +{ + WINPR_ASSERT(tsg); + free(tsg->Hostname); + tsg->Hostname = ConvertUtf8ToWCharAlloc(hostname, NULL); + return tsg->Hostname != NULL; +} + +static BOOL tsg_set_machine_name(rdpTsg* tsg, const char* machineName) +{ + WINPR_ASSERT(tsg); + free(tsg->MachineName); + tsg->MachineName = ConvertUtf8ToWCharAlloc(machineName, NULL); + return tsg->MachineName != NULL; +} + +BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, DWORD timeout) +{ + UINT64 looptimeout = timeout * 1000ULL; + DWORD nCount = 0; + HANDLE events[MAXIMUM_WAIT_OBJECTS] = { 0 }; + rdpRpc* rpc = NULL; + rdpContext* context = NULL; + rdpSettings* settings = NULL; + rdpTransport* transport = NULL; + + WINPR_ASSERT(tsg); + + rpc = tsg->rpc; + WINPR_ASSERT(rpc); + + transport = rpc->transport; + context = transport_get_context(transport); + WINPR_ASSERT(context); + + settings = context->settings; + + tsg->Port = port; + tsg->transport = transport; + + if (!settings->GatewayPort) + settings->GatewayPort = 443; + + if (!tsg_set_hostname(tsg, hostname)) + return FALSE; + + if (!tsg_set_machine_name(tsg, settings->ComputerName)) + return FALSE; + + if (!rpc_connect(rpc, timeout)) + { + WLog_Print(tsg->log, WLOG_ERROR, "rpc_connect error!"); + return FALSE; + } + + nCount = tsg_get_event_handles(tsg, events, ARRAYSIZE(events)); + + if (nCount == 0) + return FALSE; + + while (tsg->state != TSG_STATE_PIPE_CREATED) + { + const DWORD polltimeout = 250; + DWORD status = WaitForMultipleObjects(nCount, events, FALSE, polltimeout); + if (status == WAIT_TIMEOUT) + { + if (timeout > 0) + { + if (looptimeout < polltimeout) + return FALSE; + looptimeout -= polltimeout; + } + } + else + looptimeout = timeout * 1000ULL; + + if (!tsg_check_event_handles(tsg)) + { + WLog_Print(tsg->log, WLOG_ERROR, "tsg_check failure"); + transport_set_layer(transport, TRANSPORT_LAYER_CLOSED); + return FALSE; + } + } + + WLog_Print(tsg->log, WLOG_INFO, "TS Gateway Connection Success"); + tsg->bio = BIO_new(BIO_s_tsg()); + + if (!tsg->bio) + return FALSE; + + BIO_set_data(tsg->bio, (void*)tsg); + return TRUE; +} + +BOOL tsg_disconnect(rdpTsg* tsg) +{ + /** + * Gateway Shutdown Phase + * + * Client Server + * | | + * |-------------TsProxyCloseChannel Request---------->| + * | | + * |<-------TsProxySetupReceivePipe Final Response-----| + * |<-----------TsProxyCloseChannel Response-----------| + * | | + * |----TsProxyMakeTunnelCall Request (cancel async)-->| + * | | + * |<---TsProxyMakeTunnelCall Response (call async)----| + * |<---TsProxyMakeTunnelCall Response (cancel async)--| + * | | + * |--------------TsProxyCloseTunnel Request---------->| + * |<-------------TsProxyCloseTunnel Response----------| + * | | + */ + if (!tsg) + return FALSE; + + if (tsg->state != TSG_STATE_TUNNEL_CLOSE_PENDING) + { + if (!TsProxyCloseChannelWriteRequest(tsg, &tsg->ChannelContext)) + return FALSE; + + return tsg_transition_to_state(tsg, TSG_STATE_CHANNEL_CLOSE_PENDING); + } + + return TRUE; +} + +/** + * @brief Read data from TSG + * + * @param[in] tsg The TSG instance to read from + * @param[in] data A pointer to the data buffer + * @param[in] length length of data + * + * @return < 0 on error; 0 if not enough data is available (non blocking mode); > 0 bytes to read + */ + +static int tsg_read(rdpTsg* tsg, BYTE* data, size_t length) +{ + rdpRpc* rpc = NULL; + int status = 0; + + if (!tsg || !data) + return -1; + + rpc = tsg->rpc; + + if (transport_get_layer(rpc->transport) == TRANSPORT_LAYER_CLOSED) + { + WLog_Print(tsg->log, WLOG_ERROR, "tsg_read error: connection lost"); + return -1; + } + + do + { + status = rpc_client_receive_pipe_read(rpc->client, data, length); + + if (status < 0) + return -1; + + if (!status && !transport_get_blocking(rpc->transport)) + return 0; + + if (transport_get_layer(rpc->transport) == TRANSPORT_LAYER_CLOSED) + { + WLog_Print(tsg->log, WLOG_ERROR, "tsg_read error: connection lost"); + return -1; + } + + if (status > 0) + break; + + if (transport_get_blocking(rpc->transport)) + { + while (WaitForSingleObject(rpc->client->PipeEvent, 0) != WAIT_OBJECT_0) + { + if (!tsg_check_event_handles(tsg)) + return -1; + + (void)WaitForSingleObject(rpc->client->PipeEvent, 100); + } + } + } while (transport_get_blocking(rpc->transport)); + + return status; +} + +static int tsg_write(rdpTsg* tsg, const BYTE* data, UINT32 length) +{ + int status = 0; + + if (!tsg || !data || !tsg->rpc || !tsg->rpc->transport) + return -1; + + if (transport_get_layer(tsg->rpc->transport) == TRANSPORT_LAYER_CLOSED) + { + WLog_Print(tsg->log, WLOG_ERROR, "error, connection lost"); + return -1; + } + + status = TsProxySendToServer((handle_t)tsg, data, 1, &length); + + if (status < 0) + return -1; + + return (int)length; +} + +rdpTsg* tsg_new(rdpTransport* transport) +{ + rdpTsg* tsg = (rdpTsg*)calloc(1, sizeof(rdpTsg)); + + if (!tsg) + return NULL; + tsg->log = WLog_Get(TAG); + tsg->transport = transport; + tsg->rpc = rpc_new(tsg->transport); + + if (!tsg->rpc) + goto out_free; + + return tsg; +out_free: + free(tsg); + return NULL; +} + +void tsg_free(rdpTsg* tsg) +{ + if (tsg) + { + rpc_free(tsg->rpc); + free(tsg->Hostname); + free(tsg->MachineName); + free(tsg); + } +} + +static int transport_bio_tsg_write(BIO* bio, const char* buf, int num) +{ + int status = 0; + rdpTsg* tsg = (rdpTsg*)BIO_get_data(bio); + BIO_clear_flags(bio, BIO_FLAGS_WRITE); + + if (num < 0) + return -1; + status = tsg_write(tsg, (const BYTE*)buf, (UINT32)num); + + if (status < 0) + { + BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return -1; + } + else if (status == 0) + { + BIO_set_flags(bio, BIO_FLAGS_WRITE); + WSASetLastError(WSAEWOULDBLOCK); + } + else + { + BIO_set_flags(bio, BIO_FLAGS_WRITE); + } + + return status >= 0 ? status : -1; +} + +static int transport_bio_tsg_read(BIO* bio, char* buf, int size) +{ + int status = 0; + rdpTsg* tsg = (rdpTsg*)BIO_get_data(bio); + + if (!tsg || (size < 0)) + { + BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return -1; + } + + BIO_clear_flags(bio, BIO_FLAGS_READ); + status = tsg_read(tsg, (BYTE*)buf, (size_t)size); + + if (status < 0) + { + BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return -1; + } + else if (status == 0) + { + BIO_set_flags(bio, BIO_FLAGS_READ); + WSASetLastError(WSAEWOULDBLOCK); + } + else + { + BIO_set_flags(bio, BIO_FLAGS_READ); + } + + return status > 0 ? status : -1; +} + +static int transport_bio_tsg_puts(BIO* bio, const char* str) +{ + WINPR_UNUSED(bio); + WINPR_UNUSED(str); + return 1; +} + +// NOLINTNEXTLINE(readability-non-const-parameter) +static int transport_bio_tsg_gets(BIO* bio, char* str, int size) +{ + WINPR_UNUSED(bio); + WINPR_UNUSED(str); + WINPR_UNUSED(size); + return 1; +} + +static long transport_bio_tsg_ctrl(BIO* bio, int cmd, long arg1, void* arg2) +{ + long status = -1; + rdpTsg* tsg = (rdpTsg*)BIO_get_data(bio); + RpcVirtualConnection* connection = tsg->rpc->VirtualConnection; + RpcInChannel* inChannel = connection->DefaultInChannel; + RpcOutChannel* outChannel = connection->DefaultOutChannel; + + switch (cmd) + { + case BIO_CTRL_FLUSH: + (void)BIO_flush(inChannel->common.tls->bio); + (void)BIO_flush(outChannel->common.tls->bio); + status = 1; + break; + + case BIO_C_GET_EVENT: + if (arg2) + { + *((HANDLE*)arg2) = tsg->rpc->client->PipeEvent; + status = 1; + } + + break; + + case BIO_C_SET_NONBLOCK: + status = 1; + break; + + case BIO_C_READ_BLOCKED: + { + BIO* cbio = outChannel->common.bio; + status = BIO_read_blocked(cbio); + } + break; + + case BIO_C_WRITE_BLOCKED: + { + BIO* cbio = inChannel->common.bio; + status = BIO_write_blocked(cbio); + } + break; + + case BIO_C_WAIT_READ: + { + int timeout = (int)arg1; + BIO* cbio = outChannel->common.bio; + + if (BIO_read_blocked(cbio)) + return BIO_wait_read(cbio, timeout); + else if (BIO_write_blocked(cbio)) + return BIO_wait_write(cbio, timeout); + else + status = 1; + } + break; + + case BIO_C_WAIT_WRITE: + { + int timeout = (int)arg1; + BIO* cbio = inChannel->common.bio; + + if (BIO_write_blocked(cbio)) + status = BIO_wait_write(cbio, timeout); + else if (BIO_read_blocked(cbio)) + status = BIO_wait_read(cbio, timeout); + else + status = 1; + } + break; +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + case BIO_CTRL_GET_KTLS_SEND: + status = 0; + break; + case BIO_CTRL_GET_KTLS_RECV: + status = 0; + break; +#endif + default: + break; + } + + return status; +} + +static int transport_bio_tsg_new(BIO* bio) +{ + WINPR_ASSERT(bio); + BIO_set_init(bio, 1); + BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return 1; +} + +static int transport_bio_tsg_free(BIO* bio) +{ + WINPR_ASSERT(bio); + WINPR_UNUSED(bio); + return 1; +} + +BIO_METHOD* BIO_s_tsg(void) +{ + static BIO_METHOD* bio_methods = NULL; + + if (bio_methods == NULL) + { + if (!(bio_methods = BIO_meth_new(BIO_TYPE_TSG, "TSGateway"))) + return NULL; + + BIO_meth_set_write(bio_methods, transport_bio_tsg_write); + BIO_meth_set_read(bio_methods, transport_bio_tsg_read); + BIO_meth_set_puts(bio_methods, transport_bio_tsg_puts); + BIO_meth_set_gets(bio_methods, transport_bio_tsg_gets); + BIO_meth_set_ctrl(bio_methods, transport_bio_tsg_ctrl); + BIO_meth_set_create(bio_methods, transport_bio_tsg_new); + BIO_meth_set_destroy(bio_methods, transport_bio_tsg_free); + } + + return bio_methods; +} + +TSG_STATE tsg_get_state(rdpTsg* tsg) +{ + if (!tsg) + return TSG_STATE_INITIAL; + + return tsg->state; +} + +BIO* tsg_get_bio(rdpTsg* tsg) +{ + if (!tsg) + return NULL; + + return tsg->bio; +} + +BOOL tsg_set_state(rdpTsg* tsg, TSG_STATE state) +{ + if (!tsg) + return FALSE; + + tsg->state = state; + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/tsg.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/tsg.h new file mode 100644 index 0000000000000000000000000000000000000000..81b50a7e5d257acae73510153c68bb98235ca5fd --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/tsg.h @@ -0,0 +1,122 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Terminal Server Gateway (TSG) + * + * Copyright 2012 Fujitsu Technology Solutions GmbH + * Copyright 2012 Dmitrij Jasnov + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_TSG_H +#define FREERDP_LIB_CORE_GATEWAY_TSG_H + +typedef struct rdp_tsg rdpTsg; + +#include "rpc.h" + +#include "../transport.h" + +#include +#include +#include + +#include +#include + +typedef enum +{ + TSG_STATE_INITIAL, + TSG_STATE_CONNECTED, + TSG_STATE_AUTHORIZED, + TSG_STATE_CHANNEL_CREATED, + TSG_STATE_PIPE_CREATED, + TSG_STATE_TUNNEL_CLOSE_PENDING, + TSG_STATE_CHANNEL_CLOSE_PENDING, + TSG_STATE_FINAL +} TSG_STATE; + +#define TsProxyCreateTunnelOpnum 1 +#define TsProxyAuthorizeTunnelOpnum 2 +#define TsProxyMakeTunnelCallOpnum 3 +#define TsProxyCreateChannelOpnum 4 +#define TsProxyUnused5Opnum 5 +#define TsProxyCloseChannelOpnum 6 +#define TsProxyCloseTunnelOpnum 7 +#define TsProxySetupReceivePipeOpnum 8 +#define TsProxySendToServerOpnum 9 + +#define MAX_RESOURCE_NAMES 50 + +#define TS_GATEWAY_TRANSPORT 0x5452 + +#define TSG_ASYNC_MESSAGE_CONSENT_MESSAGE 0x00000001 +#define TSG_ASYNC_MESSAGE_SERVICE_MESSAGE 0x00000002 +#define TSG_ASYNC_MESSAGE_REAUTH 0x00000003 + +#define TSG_TUNNEL_CALL_ASYNC_MSG_REQUEST 0x00000001 +#define TSG_TUNNEL_CANCEL_ASYNC_MSG_REQUEST 0x00000002 + +#define TSG_NAP_CAPABILITY_QUAR_SOH 0x00000001 +#define TSG_NAP_CAPABILITY_IDLE_TIMEOUT 0x00000002 +#define TSG_MESSAGING_CAP_CONSENT_SIGN 0x00000004 +#define TSG_MESSAGING_CAP_SERVICE_MSG 0x00000008 +#define TSG_MESSAGING_CAP_REAUTH 0x00000010 +#define TSG_MESSAGING_MAX_MESSAGE_LENGTH 65536 + +/* Error Codes */ + +#define E_PROXY_INTERNALERROR 0x800759D8 +#define E_PROXY_RAP_ACCESSDENIED 0x800759DA +#define E_PROXY_NAP_ACCESSDENIED 0x800759DB +#define E_PROXY_TS_CONNECTFAILED 0x800759DD +#define E_PROXY_ALREADYDISCONNECTED 0x800759DF +#define E_PROXY_QUARANTINE_ACCESSDENIED 0x800759ED +#define E_PROXY_NOCERTAVAILABLE 0x800759EE +#define E_PROXY_COOKIE_BADPACKET 0x800759F7 +#define E_PROXY_COOKIE_AUTHENTICATION_ACCESS_DENIED 0x800759F8 +#define E_PROXY_UNSUPPORTED_AUTHENTICATION_METHOD 0x800759F9 +#define E_PROXY_CAPABILITYMISMATCH 0x800759E9 + +#define E_PROXY_NOTSUPPORTED 0x000059E8 +#define E_PROXY_MAXCONNECTIONSREACHED 0x000059E6 +#define E_PROXY_SESSIONTIMEOUT 0x000059F6 +#define E_PROXY_REAUTH_AUTHN_FAILED 0x000059FA +#define E_PROXY_REAUTH_CAP_FAILED 0x000059FB +#define E_PROXY_REAUTH_RAP_FAILED 0x000059FC +#define E_PROXY_SDR_NOT_SUPPORTED_BY_TS 0x000059FD +#define E_PROXY_REAUTH_NAP_FAILED 0x00005A00 +#define E_PROXY_CONNECTIONABORTED 0x000004D4 + +FREERDP_LOCAL void tsg_free(rdpTsg* tsg); + +WINPR_ATTR_MALLOC(tsg_free, 1) +FREERDP_LOCAL rdpTsg* tsg_new(rdpTransport* transport); + +FREERDP_LOCAL BOOL tsg_proxy_begin(rdpTsg* tsg); + +FREERDP_LOCAL BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port, DWORD timeout); +FREERDP_LOCAL BOOL tsg_disconnect(rdpTsg* tsg); + +FREERDP_LOCAL BOOL tsg_recv_pdu(rdpTsg* tsg, const RPC_PDU* pdu); + +FREERDP_LOCAL BOOL tsg_check_event_handles(rdpTsg* tsg); +FREERDP_LOCAL DWORD tsg_get_event_handles(rdpTsg* tsg, HANDLE* events, DWORD count); + +FREERDP_LOCAL TSG_STATE tsg_get_state(rdpTsg* tsg); +FREERDP_LOCAL BOOL tsg_set_state(rdpTsg* tsg, TSG_STATE state); + +FREERDP_LOCAL BIO* tsg_get_bio(rdpTsg* tsg); + +#endif /* FREERDP_LIB_CORE_GATEWAY_TSG_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/websocket.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/websocket.c new file mode 100644 index 0000000000000000000000000000000000000000..440c4a99653578ebfa737bf36b12b4afa6230aac --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/websocket.c @@ -0,0 +1,497 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Websocket Framing + * + * Copyright 2023 Michael Saxl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "websocket.h" +#include +#include "../tcp.h" + +#define TAG FREERDP_TAG("core.gateway.websocket") + +struct s_websocket_context +{ + size_t payloadLength; + uint32_t maskingKey; + BOOL masking; + BOOL closeSent; + BYTE opcode; + BYTE fragmentOriginalOpcode; + BYTE lengthAndMaskPosition; + WEBSOCKET_STATE state; + wStream* responseStreamBuffer; +}; + +static int websocket_write_all(BIO* bio, const BYTE* data, size_t length); + +BOOL websocket_context_mask_and_send(BIO* bio, wStream* sPacket, wStream* sDataPacket, + UINT32 maskingKey) +{ + const size_t len = Stream_Length(sDataPacket); + Stream_SetPosition(sDataPacket, 0); + + if (!Stream_EnsureRemainingCapacity(sPacket, len)) + return FALSE; + + /* mask as much as possible with 32bit access */ + size_t streamPos = 0; + for (; streamPos + 4 <= len; streamPos += 4) + { + const uint32_t data = Stream_Get_UINT32(sDataPacket); + Stream_Write_UINT32(sPacket, data ^ maskingKey); + } + + /* mask the rest byte by byte */ + for (; streamPos < len; streamPos++) + { + BYTE data = 0; + BYTE* partialMask = ((BYTE*)&maskingKey) + (streamPos % 4); + Stream_Read_UINT8(sDataPacket, data); + Stream_Write_UINT8(sPacket, data ^ *partialMask); + } + + Stream_SealLength(sPacket); + + ERR_clear_error(); + const size_t size = Stream_Length(sPacket); + const int status = websocket_write_all(bio, Stream_Buffer(sPacket), size); + Stream_Free(sPacket, TRUE); + + if ((status < 0) || ((size_t)status != size)) + return FALSE; + + return TRUE; +} + +wStream* websocket_context_packet_new(size_t len, WEBSOCKET_OPCODE opcode, UINT32* pMaskingKey) +{ + WINPR_ASSERT(pMaskingKey); + if (len > INT_MAX) + return NULL; + + size_t fullLen = 0; + if (len < 126) + fullLen = len + 6; /* 2 byte "mini header" + 4 byte masking key */ + else if (len < 0x10000) + fullLen = len + 8; /* 2 byte "mini header" + 2 byte length + 4 byte masking key */ + else + fullLen = len + 14; /* 2 byte "mini header" + 8 byte length + 4 byte masking key */ + + wStream* sWS = Stream_New(NULL, fullLen); + if (!sWS) + return NULL; + + UINT32 maskingKey = 0; + winpr_RAND(&maskingKey, sizeof(maskingKey)); + + Stream_Write_UINT8(sWS, (UINT8)(WEBSOCKET_FIN_BIT | opcode)); + if (len < 126) + Stream_Write_UINT8(sWS, (UINT8)len | WEBSOCKET_MASK_BIT); + else if (len < 0x10000) + { + Stream_Write_UINT8(sWS, 126 | WEBSOCKET_MASK_BIT); + Stream_Write_UINT16_BE(sWS, (UINT16)len); + } + else + { + Stream_Write_UINT8(sWS, 127 | WEBSOCKET_MASK_BIT); + Stream_Write_UINT32_BE(sWS, 0); /* payload is limited to INT_MAX */ + Stream_Write_UINT32_BE(sWS, (UINT32)len); + } + Stream_Write_UINT32(sWS, maskingKey); + *pMaskingKey = maskingKey; + return sWS; +} + +BOOL websocket_context_write_wstream(websocket_context* context, BIO* bio, wStream* sPacket, + WEBSOCKET_OPCODE opcode) +{ + WINPR_ASSERT(context); + + if (context->closeSent) + return FALSE; + + if (opcode == WebsocketCloseOpcode) + context->closeSent = TRUE; + + WINPR_ASSERT(bio); + WINPR_ASSERT(sPacket); + + const size_t len = Stream_Length(sPacket); + uint32_t maskingKey = 0; + wStream* sWS = websocket_context_packet_new(len, opcode, &maskingKey); + if (!sWS) + return FALSE; + + return websocket_context_mask_and_send(bio, sWS, sPacket, maskingKey); +} + +int websocket_write_all(BIO* bio, const BYTE* data, size_t length) +{ + WINPR_ASSERT(bio); + WINPR_ASSERT(data); + size_t offset = 0; + + if (length > INT32_MAX) + return -1; + + while (offset < length) + { + ERR_clear_error(); + const size_t diff = length - offset; + int status = BIO_write(bio, &data[offset], (int)diff); + + if (status > 0) + offset += (size_t)status; + else + { + if (!BIO_should_retry(bio)) + return -1; + + if (BIO_write_blocked(bio)) + { + const long rstatus = BIO_wait_write(bio, 100); + if (rstatus < 0) + return -1; + } + else if (BIO_read_blocked(bio)) + return -2; /* Abort write, there is data that must be read */ + else + USleep(100); + } + } + + return (int)length; +} + +int websocket_context_write(websocket_context* context, BIO* bio, const BYTE* buf, int isize, + WEBSOCKET_OPCODE opcode) +{ + WINPR_ASSERT(bio); + WINPR_ASSERT(buf); + + if (isize < 0) + return -1; + + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticConstInit(&sbuffer, buf, (size_t)isize); + if (!websocket_context_write_wstream(context, bio, s, opcode)) + return -2; + return isize; +} + +static int websocket_read_data(BIO* bio, BYTE* pBuffer, size_t size, + websocket_context* encodingContext) +{ + int status = 0; + + WINPR_ASSERT(bio); + WINPR_ASSERT(pBuffer); + WINPR_ASSERT(encodingContext); + + if (encodingContext->payloadLength == 0) + { + encodingContext->state = WebsocketStateOpcodeAndFin; + return 0; + } + + const size_t rlen = + (encodingContext->payloadLength < size ? encodingContext->payloadLength : size); + if (rlen > INT32_MAX) + return -1; + + ERR_clear_error(); + status = BIO_read(bio, pBuffer, (int)rlen); + if ((status <= 0) || ((size_t)status > encodingContext->payloadLength)) + return status; + + encodingContext->payloadLength -= (size_t)status; + + if (encodingContext->payloadLength == 0) + encodingContext->state = WebsocketStateOpcodeAndFin; + + return status; +} + +static int websocket_read_wstream(BIO* bio, websocket_context* encodingContext) +{ + WINPR_ASSERT(bio); + WINPR_ASSERT(encodingContext); + + wStream* s = encodingContext->responseStreamBuffer; + WINPR_ASSERT(s); + + if (encodingContext->payloadLength == 0) + { + encodingContext->state = WebsocketStateOpcodeAndFin; + return 0; + } + + if (!Stream_EnsureRemainingCapacity(s, encodingContext->payloadLength)) + { + WLog_WARN(TAG, + "wStream::capacity [%" PRIuz "] != encodingContext::paylaodLangth [%" PRIuz "]", + Stream_GetRemainingCapacity(s), encodingContext->payloadLength); + return -1; + } + + const int status = websocket_read_data(bio, Stream_Pointer(s), Stream_GetRemainingCapacity(s), + encodingContext); + if (status < 0) + return status; + + if (!Stream_SafeSeek(s, (size_t)status)) + return -1; + + return status; +} + +static BOOL websocket_reply_close(BIO* bio, websocket_context* context, wStream* s) +{ + WINPR_ASSERT(bio); + + return websocket_context_write_wstream(context, bio, s, WebsocketCloseOpcode); +} + +static BOOL websocket_reply_pong(BIO* bio, websocket_context* context, wStream* s) +{ + WINPR_ASSERT(bio); + WINPR_ASSERT(s); + + if (Stream_GetPosition(s) != 0) + return websocket_context_write_wstream(context, bio, s, WebsocketPongOpcode); + + return websocket_reply_close(bio, context, NULL); +} + +static int websocket_handle_payload(BIO* bio, BYTE* pBuffer, size_t size, + websocket_context* encodingContext) +{ + int status = 0; + + WINPR_ASSERT(bio); + WINPR_ASSERT(pBuffer); + WINPR_ASSERT(encodingContext); + + const BYTE effectiveOpcode = ((encodingContext->opcode & 0xf) == WebsocketContinuationOpcode + ? encodingContext->fragmentOriginalOpcode & 0xf + : encodingContext->opcode & 0xf); + + switch (effectiveOpcode) + { + case WebsocketBinaryOpcode: + { + status = websocket_read_data(bio, pBuffer, size, encodingContext); + if (status < 0) + return status; + + return status; + } + case WebsocketPingOpcode: + { + status = websocket_read_wstream(bio, encodingContext); + if (status < 0) + return status; + + if (encodingContext->payloadLength == 0) + { + websocket_reply_pong(bio, encodingContext, encodingContext->responseStreamBuffer); + Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + } + } + break; + case WebsocketPongOpcode: + { + status = websocket_read_wstream(bio, encodingContext); + if (status < 0) + return status; + /* We don´t care about pong response data, discard. */ + Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + } + break; + case WebsocketCloseOpcode: + { + status = websocket_read_wstream(bio, encodingContext); + if (status < 0) + return status; + + if (encodingContext->payloadLength == 0) + { + websocket_reply_close(bio, encodingContext, encodingContext->responseStreamBuffer); + encodingContext->closeSent = TRUE; + Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + } + } + break; + default: + WLog_WARN(TAG, "Unimplemented websocket opcode %" PRIx8 ". Dropping", effectiveOpcode); + + status = websocket_read_wstream(bio, encodingContext); + if (status < 0) + return status; + Stream_SetPosition(encodingContext->responseStreamBuffer, 0); + break; + } + /* return how many bytes have been written to pBuffer. + * Only WebsocketBinaryOpcode writes into it and it returns directly */ + return 0; +} + +int websocket_context_read(websocket_context* encodingContext, BIO* bio, BYTE* pBuffer, size_t size) +{ + int status = 0; + size_t effectiveDataLen = 0; + + WINPR_ASSERT(bio); + WINPR_ASSERT(pBuffer); + WINPR_ASSERT(encodingContext); + + while (TRUE) + { + switch (encodingContext->state) + { + case WebsocketStateOpcodeAndFin: + { + BYTE buffer[1] = { 0 }; + + ERR_clear_error(); + status = BIO_read(bio, (char*)buffer, sizeof(buffer)); + if (status <= 0) + return (effectiveDataLen > 0 ? WINPR_ASSERTING_INT_CAST(int, effectiveDataLen) + : status); + + encodingContext->opcode = buffer[0]; + if (((encodingContext->opcode & 0xf) != WebsocketContinuationOpcode) && + (encodingContext->opcode & 0xf) < 0x08) + encodingContext->fragmentOriginalOpcode = encodingContext->opcode; + encodingContext->state = WebsocketStateLengthAndMasking; + } + break; + case WebsocketStateLengthAndMasking: + { + BYTE buffer[1] = { 0 }; + + ERR_clear_error(); + status = BIO_read(bio, (char*)buffer, sizeof(buffer)); + if (status <= 0) + return (effectiveDataLen > 0 ? WINPR_ASSERTING_INT_CAST(int, effectiveDataLen) + : status); + + encodingContext->masking = ((buffer[0] & WEBSOCKET_MASK_BIT) == WEBSOCKET_MASK_BIT); + encodingContext->lengthAndMaskPosition = 0; + encodingContext->payloadLength = 0; + const BYTE len = buffer[0] & 0x7f; + if (len < 126) + { + encodingContext->payloadLength = len; + encodingContext->state = (encodingContext->masking ? WebSocketStateMaskingKey + : WebSocketStatePayload); + } + else if (len == 126) + encodingContext->state = WebsocketStateShortLength; + else + encodingContext->state = WebsocketStateLongLength; + } + break; + case WebsocketStateShortLength: + case WebsocketStateLongLength: + { + BYTE buffer[1] = { 0 }; + const BYTE lenLength = + (encodingContext->state == WebsocketStateShortLength ? 2 : 8); + while (encodingContext->lengthAndMaskPosition < lenLength) + { + ERR_clear_error(); + status = BIO_read(bio, (char*)buffer, sizeof(buffer)); + if (status <= 0) + return (effectiveDataLen > 0 + ? WINPR_ASSERTING_INT_CAST(int, effectiveDataLen) + : status); + if (status > UINT8_MAX) + return -1; + encodingContext->payloadLength = + (encodingContext->payloadLength) << 8 | buffer[0]; + encodingContext->lengthAndMaskPosition += + WINPR_ASSERTING_INT_CAST(BYTE, status); + } + encodingContext->state = + (encodingContext->masking ? WebSocketStateMaskingKey : WebSocketStatePayload); + } + break; + case WebSocketStateMaskingKey: + { + WLog_WARN( + TAG, "Websocket Server sends data with masking key. This is against RFC 6455."); + return -1; + } + case WebSocketStatePayload: + { + status = websocket_handle_payload(bio, pBuffer, size, encodingContext); + if (status < 0) + return (effectiveDataLen > 0 ? WINPR_ASSERTING_INT_CAST(int, effectiveDataLen) + : status); + + effectiveDataLen += WINPR_ASSERTING_INT_CAST(size_t, status); + + if (WINPR_ASSERTING_INT_CAST(size_t, status) >= size) + return WINPR_ASSERTING_INT_CAST(int, effectiveDataLen); + pBuffer += status; + size -= WINPR_ASSERTING_INT_CAST(size_t, status); + } + break; + default: + break; + } + } + /* should be unreachable */ +} + +websocket_context* websocket_context_new(void) +{ + websocket_context* context = calloc(1, sizeof(websocket_context)); + if (!context) + goto fail; + + context->responseStreamBuffer = Stream_New(NULL, 1024); + if (!context->responseStreamBuffer) + goto fail; + + if (!websocket_context_reset(context)) + goto fail; + + return context; +fail: + websocket_context_free(context); + return NULL; +} + +void websocket_context_free(websocket_context* context) +{ + if (!context) + return; + + Stream_Free(context->responseStreamBuffer, TRUE); + free(context); +} + +BOOL websocket_context_reset(websocket_context* context) +{ + WINPR_ASSERT(context); + + context->state = WebsocketStateOpcodeAndFin; + return Stream_SetPosition(context->responseStreamBuffer, 0); +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/websocket.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/websocket.h new file mode 100644 index 0000000000000000000000000000000000000000..edaf152cd71cf5b69b3555f4293c5efadae056e4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/websocket.h @@ -0,0 +1,76 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Websocket Framing + * + * Copyright 2023 Michael Saxl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_H +#define FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_H + +#include +#include + +#include + +#include "../../crypto/tls.h" + +#define WEBSOCKET_MASK_BIT 0x80 +#define WEBSOCKET_FIN_BIT 0x80 + +typedef enum +{ + WebsocketContinuationOpcode = 0x0, + WebsocketTextOpcode = 0x1, + WebsocketBinaryOpcode = 0x2, + WebsocketCloseOpcode = 0x8, + WebsocketPingOpcode = 0x9, + WebsocketPongOpcode = 0xa, +} WEBSOCKET_OPCODE; + +typedef enum +{ + WebsocketStateOpcodeAndFin, + WebsocketStateLengthAndMasking, + WebsocketStateShortLength, + WebsocketStateLongLength, + WebSocketStateMaskingKey, + WebSocketStatePayload, +} WEBSOCKET_STATE; + +typedef struct s_websocket_context websocket_context; + +FREERDP_LOCAL void websocket_context_free(websocket_context* context); + +WINPR_ATTR_MALLOC(websocket_context_free, 1) +FREERDP_LOCAL websocket_context* websocket_context_new(void); + +FREERDP_LOCAL BOOL websocket_context_reset(websocket_context* context); + +FREERDP_LOCAL BOOL websocket_context_write_wstream(websocket_context* context, BIO* bio, + wStream* sPacket, WEBSOCKET_OPCODE opcode); +FREERDP_LOCAL int websocket_context_write(websocket_context* context, BIO* bio, const BYTE* buf, + int isize, WEBSOCKET_OPCODE opcode); +FREERDP_LOCAL int websocket_context_read(websocket_context* encodingContext, BIO* bio, + BYTE* pBuffer, size_t size); + +WINPR_ATTR_MALLOC(Stream_Free, 1) +FREERDP_LOCAL wStream* websocket_context_packet_new(size_t len, WEBSOCKET_OPCODE opcode, + UINT32* pMaskingKey); + +FREERDP_LOCAL BOOL websocket_context_mask_and_send(BIO* bio, wStream* sPacket, wStream* sDataPacket, + UINT32 maskingKey); + +#endif /* FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/wst.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/wst.c new file mode 100644 index 0000000000000000000000000000000000000000..3ccc04ab9e445416d0789a71293684bfe43dded1 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/wst.c @@ -0,0 +1,869 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Websocket Transport + * + * Copyright 2023 Michael Saxl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "../settings.h" + +#include +#include +#include +#include + +#include "wst.h" +#include "websocket.h" +#include "http.h" +#include "../credssp_auth.h" +#include "../proxy.h" +#include "../rdp.h" +#include "../../crypto/opensslcompat.h" +#include "rpc_fault.h" +#include "../utils.h" + +#define TAG FREERDP_TAG("core.gateway.wst") + +#define AUTH_PKG NEGO_SSP_NAME + +struct rdp_wst +{ + rdpContext* context; + BOOL attached; + BIO* frontBio; + rdpTls* tls; + rdpCredsspAuth* auth; + BOOL auth_required; + HttpContext* http; + CRITICAL_SECTION writeSection; + char* gwhostname; + uint16_t gwport; + char* gwpath; + websocket_context* wscontext; +}; + +static const char arm_query_param[] = "%s%cClmTk=Bearer%%20%s&X-MS-User-Agent=FreeRDP%%2F3.0"; + +static BOOL wst_get_gateway_credentials(rdpContext* context, rdp_auth_reason reason) +{ + WINPR_ASSERT(context); + freerdp* instance = context->instance; + + auth_status rc = utils_authenticate_gateway(instance, reason); + switch (rc) + { + case AUTH_SUCCESS: + case AUTH_SKIP: + return TRUE; + case AUTH_CANCELLED: + freerdp_set_last_error_log(instance->context, FREERDP_ERROR_CONNECT_CANCELLED); + return FALSE; + case AUTH_NO_CREDENTIALS: + WLog_INFO(TAG, "No credentials provided - using NULL identity"); + return TRUE; + case AUTH_FAILED: + default: + return FALSE; + } +} + +static BOOL wst_auth_init(rdpWst* wst, rdpTls* tls, TCHAR* authPkg) +{ + WINPR_ASSERT(wst); + WINPR_ASSERT(tls); + WINPR_ASSERT(authPkg); + + rdpContext* context = wst->context; + rdpSettings* settings = context->settings; + SEC_WINNT_AUTH_IDENTITY identity = { 0 }; + int rc = 0; + + wst->auth_required = TRUE; + if (!credssp_auth_init(wst->auth, authPkg, tls->Bindings)) + return FALSE; + + if (!wst_get_gateway_credentials(context, GW_AUTH_RDG)) + return FALSE; + + if (!identity_set_from_settings(&identity, settings, FreeRDP_GatewayUsername, + FreeRDP_GatewayDomain, FreeRDP_GatewayPassword)) + return FALSE; + + SEC_WINNT_AUTH_IDENTITY* identityArg = (settings->GatewayUsername ? &identity : NULL); + if (!credssp_auth_setup_client(wst->auth, "HTTP", wst->gwhostname, identityArg, NULL)) + { + sspi_FreeAuthIdentity(&identity); + return FALSE; + } + sspi_FreeAuthIdentity(&identity); + + credssp_auth_set_flags(wst->auth, ISC_REQ_CONFIDENTIALITY | ISC_REQ_MUTUAL_AUTH); + + rc = credssp_auth_authenticate(wst->auth); + if (rc < 0) + return FALSE; + + return TRUE; +} + +static BOOL wst_set_auth_header(rdpCredsspAuth* auth, HttpRequest* request) +{ + WINPR_ASSERT(auth); + WINPR_ASSERT(request); + + const SecBuffer* authToken = credssp_auth_get_output_buffer(auth); + char* base64AuthToken = NULL; + + if (authToken) + { + if (authToken->cbBuffer > INT_MAX) + return FALSE; + + base64AuthToken = crypto_base64_encode(authToken->pvBuffer, authToken->cbBuffer); + } + + if (base64AuthToken) + { + BOOL rc = http_request_set_auth_scheme(request, credssp_auth_pkg_name(auth)) && + http_request_set_auth_param(request, base64AuthToken); + free(base64AuthToken); + + if (!rc) + return FALSE; + } + + return TRUE; +} + +static BOOL wst_recv_auth_token(rdpCredsspAuth* auth, HttpResponse* response) +{ + size_t len = 0; + const char* token64 = NULL; + size_t authTokenLength = 0; + BYTE* authTokenData = NULL; + SecBuffer authToken = { 0 }; + long StatusCode = 0; + int rc = 0; + + if (!auth || !response) + return FALSE; + + StatusCode = http_response_get_status_code(response); + switch (StatusCode) + { + case HTTP_STATUS_DENIED: + case HTTP_STATUS_OK: + break; + default: + http_response_log_error_status(WLog_Get(TAG), WLOG_WARN, response); + return FALSE; + } + + token64 = http_response_get_auth_token(response, credssp_auth_pkg_name(auth)); + + if (!token64) + return FALSE; + + len = strlen(token64); + + crypto_base64_decode(token64, len, &authTokenData, &authTokenLength); + + if (authTokenLength && (authTokenLength <= UINT32_MAX) && authTokenData) + { + authToken.pvBuffer = authTokenData; + authToken.cbBuffer = (UINT32)authTokenLength; + credssp_auth_take_input_buffer(auth, &authToken); + } + else + free(authTokenData); + + rc = credssp_auth_authenticate(auth); + if (rc < 0) + return FALSE; + + return TRUE; +} + +static BOOL wst_tls_connect(rdpWst* wst, rdpTls* tls, UINT32 timeout) +{ + WINPR_ASSERT(wst); + WINPR_ASSERT(tls); + int sockfd = 0; + long status = 0; + BIO* socketBio = NULL; + BIO* bufferedBio = NULL; + rdpSettings* settings = wst->context->settings; + const char* peerHostname = wst->gwhostname; + UINT16 peerPort = wst->gwport; + const char* proxyUsername = NULL; + const char* proxyPassword = NULL; + BOOL isProxyConnection = + proxy_prepare(settings, &peerHostname, &peerPort, &proxyUsername, &proxyPassword); + + sockfd = freerdp_tcp_connect(wst->context, peerHostname, peerPort, timeout); + + WLog_DBG(TAG, "connecting to %s %d", peerHostname, peerPort); + if (sockfd < 0) + { + return FALSE; + } + + socketBio = BIO_new(BIO_s_simple_socket()); + + if (!socketBio) + { + closesocket((SOCKET)sockfd); + return FALSE; + } + + BIO_set_fd(socketBio, sockfd, BIO_CLOSE); + bufferedBio = BIO_new(BIO_s_buffered_socket()); + + if (!bufferedBio) + { + BIO_free_all(socketBio); + return FALSE; + } + + bufferedBio = BIO_push(bufferedBio, socketBio); + status = BIO_set_nonblock(bufferedBio, TRUE); + + if (isProxyConnection) + { + if (!proxy_connect(wst->context, bufferedBio, proxyUsername, proxyPassword, wst->gwhostname, + wst->gwport)) + { + BIO_free_all(bufferedBio); + return FALSE; + } + } + + if (!status) + { + BIO_free_all(bufferedBio); + return FALSE; + } + + tls->hostname = wst->gwhostname; + tls->port = MIN(UINT16_MAX, wst->gwport); + tls->isGatewayTransport = TRUE; + status = freerdp_tls_connect(tls, bufferedBio); + if (status < 1) + { + rdpContext* context = wst->context; + if (status < 0) + { + freerdp_set_last_error_if_not(context, FREERDP_ERROR_TLS_CONNECT_FAILED); + } + else + { + freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED); + } + + return FALSE; + } + return (status >= 1); +} + +static wStream* wst_build_http_request(rdpWst* wst) +{ + wStream* s = NULL; + HttpRequest* request = NULL; + const char* uri = NULL; + + if (!wst) + return NULL; + + uri = http_context_get_uri(wst->http); + request = http_request_new(); + + if (!request) + return NULL; + + if (!http_request_set_method(request, "GET") || !http_request_set_uri(request, uri)) + goto out; + + if (wst->auth_required) + { + if (!wst_set_auth_header(wst->auth, request)) + goto out; + } + else if (freerdp_settings_get_string(wst->context->settings, FreeRDP_GatewayHttpExtAuthBearer)) + { + http_request_set_auth_scheme(request, "Bearer"); + http_request_set_auth_param( + request, + freerdp_settings_get_string(wst->context->settings, FreeRDP_GatewayHttpExtAuthBearer)); + } + + s = http_request_write(wst->http, request); +out: + http_request_free(request); + + if (s) + Stream_SealLength(s); + + return s; +} + +static BOOL wst_send_http_request(rdpWst* wst, rdpTls* tls) +{ + WINPR_ASSERT(wst); + WINPR_ASSERT(tls); + + wStream* s = wst_build_http_request(wst); + if (!s) + return FALSE; + + const size_t sz = Stream_Length(s); + int status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); + + Stream_Free(s, TRUE); + return (status >= 0); +} + +static BOOL wst_handle_ok_or_forbidden(rdpWst* wst, HttpResponse** ppresponse, DWORD timeout, + long* pStatusCode) +{ + WINPR_ASSERT(wst); + WINPR_ASSERT(ppresponse); + WINPR_ASSERT(*ppresponse); + WINPR_ASSERT(pStatusCode); + + /* AVD returns a 403 response with a ARRAffinity cookie set. retry with that cookie */ + const char* affinity = http_response_get_setcookie(*ppresponse, "ARRAffinity"); + if (affinity && freerdp_settings_get_bool(wst->context->settings, FreeRDP_GatewayArmTransport)) + { + WLog_DBG(TAG, "Got Affinity cookie %s", affinity); + http_context_set_cookie(wst->http, "ARRAffinity", affinity); + http_response_free(*ppresponse); + *ppresponse = NULL; + /* Terminate this connection and make a new one with the Loadbalancing Cookie */ + const long fd = BIO_get_fd(wst->tls->bio, NULL); + if ((fd >= 0) && (fd <= INT32_MAX)) + closesocket((SOCKET)fd); + freerdp_tls_free(wst->tls); + + wst->tls = freerdp_tls_new(wst->context); + if (!wst_tls_connect(wst, wst->tls, timeout)) + return FALSE; + + if (freerdp_settings_get_string(wst->context->settings, FreeRDP_GatewayHttpExtAuthBearer) && + freerdp_settings_get_bool(wst->context->settings, FreeRDP_GatewayArmTransport)) + { + char* urlWithAuth = NULL; + size_t urlLen = 0; + char firstParam = (strchr(wst->gwpath, '?') != NULL) ? '&' : '?'; + winpr_asprintf(&urlWithAuth, &urlLen, arm_query_param, wst->gwpath, firstParam, + freerdp_settings_get_string(wst->context->settings, + FreeRDP_GatewayHttpExtAuthBearer)); + if (!urlWithAuth) + return FALSE; + free(wst->gwpath); + wst->gwpath = urlWithAuth; + if (!http_context_set_uri(wst->http, wst->gwpath)) + return FALSE; + if (!http_context_enable_websocket_upgrade(wst->http, TRUE)) + return FALSE; + } + + if (!wst_send_http_request(wst, wst->tls)) + return FALSE; + *ppresponse = http_response_recv(wst->tls, TRUE); + if (!*ppresponse) + return FALSE; + + *pStatusCode = http_response_get_status_code(*ppresponse); + } + + return TRUE; +} + +static BOOL wst_handle_denied(rdpWst* wst, HttpResponse** ppresponse, long* pStatusCode) +{ + WINPR_ASSERT(wst); + WINPR_ASSERT(ppresponse); + WINPR_ASSERT(*ppresponse); + WINPR_ASSERT(pStatusCode); + + if (freerdp_settings_get_string(wst->context->settings, FreeRDP_GatewayHttpExtAuthBearer)) + return FALSE; + + if (!wst_auth_init(wst, wst->tls, AUTH_PKG)) + return FALSE; + if (!wst_send_http_request(wst, wst->tls)) + return FALSE; + + http_response_free(*ppresponse); + *ppresponse = http_response_recv(wst->tls, TRUE); + if (!*ppresponse) + return FALSE; + + while (!credssp_auth_is_complete(wst->auth)) + { + if (!wst_recv_auth_token(wst->auth, *ppresponse)) + return FALSE; + + if (credssp_auth_have_output_token(wst->auth)) + { + if (!wst_send_http_request(wst, wst->tls)) + return FALSE; + + http_response_free(*ppresponse); + *ppresponse = http_response_recv(wst->tls, TRUE); + if (!*ppresponse) + return FALSE; + } + } + *pStatusCode = http_response_get_status_code(*ppresponse); + return TRUE; +} + +BOOL wst_connect(rdpWst* wst, DWORD timeout) +{ + HttpResponse* response = NULL; + long StatusCode = 0; + + WINPR_ASSERT(wst); + if (!wst_tls_connect(wst, wst->tls, timeout)) + return FALSE; + if (freerdp_settings_get_bool(wst->context->settings, FreeRDP_GatewayArmTransport)) + { + /* + * If we are directed here from a ARM Gateway first + * we need to get a Loadbalancing Cookie (ARRAffinity) + * This is done by a plain GET request on the websocket URL + */ + http_context_enable_websocket_upgrade(wst->http, FALSE); + } + if (!wst_send_http_request(wst, wst->tls)) + return FALSE; + + response = http_response_recv(wst->tls, TRUE); + if (!response) + { + return FALSE; + } + + StatusCode = http_response_get_status_code(response); + BOOL success = TRUE; + switch (StatusCode) + { + case HTTP_STATUS_FORBIDDEN: + case HTTP_STATUS_OK: + success = wst_handle_ok_or_forbidden(wst, &response, timeout, &StatusCode); + break; + + case HTTP_STATUS_DENIED: + success = wst_handle_denied(wst, &response, &StatusCode); + break; + default: + http_response_log_error_status(WLog_Get(TAG), WLOG_WARN, response); + break; + } + + const BOOL isWebsocket = http_response_is_websocket(wst->http, response); + http_response_free(response); + if (!success) + return FALSE; + + if (isWebsocket) + return websocket_context_reset(wst->wscontext); + else + { + char buffer[64] = { 0 }; + WLog_ERR(TAG, "Unexpected HTTP status: %s", + freerdp_http_status_string_format(StatusCode, buffer, ARRAYSIZE(buffer))); + } + return FALSE; +} + +DWORD wst_get_event_handles(rdpWst* wst, HANDLE* events, DWORD count) +{ + DWORD nCount = 0; + WINPR_ASSERT(wst != NULL); + + if (wst->tls) + { + if (events && (nCount < count)) + { + BIO_get_event(wst->tls->bio, &events[nCount]); + nCount++; + } + else + return 0; + } + + return nCount; +} + +static int wst_bio_write(BIO* bio, const char* buf, int num) +{ + int status = 0; + WINPR_ASSERT(bio); + WINPR_ASSERT(buf); + + rdpWst* wst = (rdpWst*)BIO_get_data(bio); + WINPR_ASSERT(wst); + BIO_clear_flags(bio, BIO_FLAGS_WRITE); + EnterCriticalSection(&wst->writeSection); + status = websocket_context_write(wst->wscontext, wst->tls->bio, (const BYTE*)buf, num, + WebsocketBinaryOpcode); + LeaveCriticalSection(&wst->writeSection); + + if (status < 0) + { + BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return -1; + } + else if (status < num) + { + BIO_set_flags(bio, BIO_FLAGS_WRITE); + WSASetLastError(WSAEWOULDBLOCK); + } + else + { + BIO_set_flags(bio, BIO_FLAGS_WRITE); + } + + return status; +} + +static int wst_bio_read(BIO* bio, char* buf, int size) +{ + int status = 0; + WINPR_ASSERT(bio); + WINPR_ASSERT(buf); + WINPR_ASSERT(size >= 0); + + rdpWst* wst = (rdpWst*)BIO_get_data(bio); + WINPR_ASSERT(wst); + + while (status <= 0) + { + status = websocket_context_read(wst->wscontext, wst->tls->bio, (BYTE*)buf, (size_t)size); + if (status <= 0) + { + if (!BIO_should_retry(wst->tls->bio)) + return -1; + return 0; + } + } + + if (status < 0) + { + BIO_clear_retry_flags(bio); + return -1; + } + else if (status == 0) + { + BIO_set_retry_read(bio); + WSASetLastError(WSAEWOULDBLOCK); + return -1; + } + else + { + BIO_set_flags(bio, BIO_FLAGS_READ); + } + + return status; +} + +static int wst_bio_puts(BIO* bio, const char* str) +{ + WINPR_UNUSED(bio); + WINPR_UNUSED(str); + return -2; +} + +// NOLINTNEXTLINE(readability-non-const-parameter) +static int wst_bio_gets(BIO* bio, char* str, int size) +{ + WINPR_UNUSED(bio); + WINPR_UNUSED(str); + WINPR_UNUSED(size); + return -2; +} + +static long wst_bio_ctrl(BIO* bio, int cmd, long arg1, void* arg2) +{ + long status = -1; + WINPR_ASSERT(bio); + + rdpWst* wst = (rdpWst*)BIO_get_data(bio); + WINPR_ASSERT(wst); + rdpTls* tls = wst->tls; + + if (cmd == BIO_CTRL_FLUSH) + { + (void)BIO_flush(tls->bio); + status = 1; + } + else if (cmd == BIO_C_SET_NONBLOCK) + { + status = 1; + } + else if (cmd == BIO_C_READ_BLOCKED) + { + status = BIO_read_blocked(tls->bio); + } + else if (cmd == BIO_C_WRITE_BLOCKED) + { + status = BIO_write_blocked(tls->bio); + } + else if (cmd == BIO_C_WAIT_READ) + { + int timeout = (int)arg1; + + if (BIO_read_blocked(tls->bio)) + return BIO_wait_read(tls->bio, timeout); + status = 1; + } + else if (cmd == BIO_C_WAIT_WRITE) + { + int timeout = (int)arg1; + + if (BIO_write_blocked(tls->bio)) + status = BIO_wait_write(tls->bio, timeout); + else + status = 1; + } + else if (cmd == BIO_C_GET_EVENT || cmd == BIO_C_GET_FD) + { + status = BIO_ctrl(tls->bio, cmd, arg1, arg2); + } +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + else if (cmd == BIO_CTRL_GET_KTLS_SEND) + { + /* Even though BIO_get_ktls_send says that returning negative values is valid + * openssl internal sources are full of if(!BIO_get_ktls_send && ) stuff. This has some + * nasty sideeffects. return 0 as proper no KTLS offloading flag + */ + status = 0; + } + else if (cmd == BIO_CTRL_GET_KTLS_RECV) + { + /* Even though BIO_get_ktls_recv says that returning negative values is valid + * there is no reason to trust trust negative values are implemented right everywhere + */ + status = 0; + } +#endif + return status; +} + +static int wst_bio_new(BIO* bio) +{ + BIO_set_init(bio, 1); + BIO_set_flags(bio, BIO_FLAGS_SHOULD_RETRY); + return 1; +} + +static int wst_bio_free(BIO* bio) +{ + WINPR_UNUSED(bio); + return 1; +} + +static BIO_METHOD* BIO_s_wst(void) +{ + static BIO_METHOD* bio_methods = NULL; + + if (bio_methods == NULL) + { + if (!(bio_methods = BIO_meth_new(BIO_TYPE_TSG, "WSTransport"))) + return NULL; + + BIO_meth_set_write(bio_methods, wst_bio_write); + BIO_meth_set_read(bio_methods, wst_bio_read); + BIO_meth_set_puts(bio_methods, wst_bio_puts); + BIO_meth_set_gets(bio_methods, wst_bio_gets); + BIO_meth_set_ctrl(bio_methods, wst_bio_ctrl); + BIO_meth_set_create(bio_methods, wst_bio_new); + BIO_meth_set_destroy(bio_methods, wst_bio_free); + } + + return bio_methods; +} + +static BOOL wst_parse_url(rdpWst* wst, const char* url) +{ + const char* hostStart = NULL; + const char* pos = NULL; + WINPR_ASSERT(wst); + WINPR_ASSERT(url); + + free(wst->gwhostname); + wst->gwhostname = NULL; + free(wst->gwpath); + wst->gwpath = NULL; + + if (strncmp("wss://", url, 6) != 0) + { + if (strncmp("https://", url, 8) != 0) + { + WLog_ERR(TAG, "Websocket URL is invalid. Only wss:// or https:// URLs are supported"); + return FALSE; + } + else + hostStart = url + 8; + } + else + hostStart = url + 6; + + pos = hostStart; + while (*pos != '\0' && *pos != ':' && *pos != '/') + pos++; + free(wst->gwhostname); + wst->gwhostname = NULL; + if (pos - hostStart == 0) + return FALSE; + wst->gwhostname = strndup(hostStart, WINPR_ASSERTING_INT_CAST(size_t, (pos - hostStart))); + if (!wst->gwhostname) + return FALSE; + + if (*pos == ':') + { + char port[6] = { 0 }; + char* portNumberEnd = NULL; + pos++; + const char* portStart = pos; + while (*pos != '\0' && *pos != '/') + pos++; + if (pos - portStart > 5 || pos - portStart == 0) + return FALSE; + strncpy(port, portStart, WINPR_ASSERTING_INT_CAST(size_t, (pos - portStart))); + port[pos - portStart] = '\0'; + long _p = strtol(port, &portNumberEnd, 10); + if (portNumberEnd && (*portNumberEnd == '\0') && (_p > 0) && (_p <= UINT16_MAX)) + wst->gwport = (uint16_t)_p; + else + return FALSE; + } + else + wst->gwport = 443; + wst->gwpath = _strdup(pos); + if (!wst->gwpath) + return FALSE; + return TRUE; +} + +rdpWst* wst_new(rdpContext* context) +{ + if (!context) + return NULL; + + rdpWst* wst = (rdpWst*)calloc(1, sizeof(rdpWst)); + if (!wst) + return NULL; + + wst->context = context; + + wst->gwhostname = NULL; + wst->gwport = 443; + wst->gwpath = NULL; + + if (!wst_parse_url(wst, context->settings->GatewayUrl)) + goto wst_alloc_error; + + wst->tls = freerdp_tls_new(wst->context); + if (!wst->tls) + goto wst_alloc_error; + + wst->http = http_context_new(); + + if (!wst->http) + goto wst_alloc_error; + + if (!http_context_set_uri(wst->http, wst->gwpath) || + !http_context_set_accept(wst->http, "*/*") || + !http_context_set_cache_control(wst->http, "no-cache") || + !http_context_set_pragma(wst->http, "no-cache") || + !http_context_set_connection(wst->http, "Keep-Alive") || + !http_context_set_user_agent(wst->http, FREERDP_USER_AGENT) || + !http_context_set_x_ms_user_agent(wst->http, FREERDP_USER_AGENT) || + !http_context_set_host(wst->http, wst->gwhostname) || + !http_context_enable_websocket_upgrade(wst->http, TRUE)) + { + goto wst_alloc_error; + } + + wst->frontBio = BIO_new(BIO_s_wst()); + + if (!wst->frontBio) + goto wst_alloc_error; + + BIO_set_data(wst->frontBio, wst); + InitializeCriticalSection(&wst->writeSection); + wst->auth = credssp_auth_new(context); + if (!wst->auth) + goto wst_alloc_error; + + wst->wscontext = websocket_context_new(); + if (!wst->wscontext) + goto wst_alloc_error; + + return wst; +wst_alloc_error: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + wst_free(wst); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void wst_free(rdpWst* wst) +{ + if (!wst) + return; + + freerdp_tls_free(wst->tls); + http_context_free(wst->http); + credssp_auth_free(wst->auth); + free(wst->gwhostname); + free(wst->gwpath); + + if (!wst->attached) + BIO_free_all(wst->frontBio); + + DeleteCriticalSection(&wst->writeSection); + + websocket_context_free(wst->wscontext); + + free(wst); +} + +BIO* wst_get_front_bio_and_take_ownership(rdpWst* wst) +{ + if (!wst) + return NULL; + + wst->attached = TRUE; + return wst->frontBio; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/wst.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/wst.h new file mode 100644 index 0000000000000000000000000000000000000000..e0f2f7aa2072a5994e3220c53defb6286a876591 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/gateway/wst.h @@ -0,0 +1,42 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Websocket Transport + * + * Copyright 2023 Michael Saxl + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_TRANSPORT_H +#define FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_TRANSPORT_H + +#include +#include +#include + +/* needed for BIO */ +#include + +typedef struct rdp_wst rdpWst; + +FREERDP_LOCAL void wst_free(rdpWst* wst); + +WINPR_ATTR_MALLOC(wst_free, 1) +FREERDP_LOCAL rdpWst* wst_new(rdpContext* context); + +FREERDP_LOCAL BIO* wst_get_front_bio_and_take_ownership(rdpWst* wst); + +FREERDP_LOCAL BOOL wst_connect(rdpWst* wst, DWORD timeout); +FREERDP_LOCAL DWORD wst_get_event_handles(rdpWst* wst, HANDLE* events, DWORD count); + +#endif /* FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_TRANSPORT_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..736d45cab2ba75957eae00d8612c4d808a4aab5a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/CMakeLists.txt @@ -0,0 +1,43 @@ +set(MODULE_NAME "TestCore") +set(MODULE_PREFIX "TEST_CORE") + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(DRIVER ${MODULE_NAME}.c) + +set(TESTS TestVersion.c TestSettings.c) + +if(BUILD_TESTING_INTERNAL) + list(APPEND TESTS TestStreamDump.c) +endif() + +set(FUZZERS TestFuzzCoreClient.c TestFuzzCoreServer.c TestFuzzCryptoCertificateDataSetPEM.c) + +# Test not compatible with package tests, disable +if(WITH_SAMPLE AND WITH_SERVER AND NOT WIN32 AND BUILD_TESTING_INTERNAL) + add_compile_definitions(CMAKE_EXECUTABLE_SUFFIX="${CMAKE_EXECUTABLE_SUFFIX}") + set(TESTS ${TESTS} TestConnect.c) +else() + message("Skipping connection tests, requires BUILD_TESTING_INTERNAL, WITH_SAMPLE and WITH_SERVER set!") +endif() + +create_test_sourcelist(SRCS ${DRIVER} ${TESTS}) + +add_executable(${MODULE_NAME} ${SRCS}) + +add_compile_definitions(TESTING_OUTPUT_DIRECTORY="${PROJECT_BINARY_DIR}") +add_compile_definitions(TESTING_SRC_DIRECTORY="${PROJECT_SOURCE_DIR}") + +target_link_libraries(${MODULE_NAME} freerdp winpr freerdp-client) + +include(AddFuzzerTest) +add_fuzzer_test("${FUZZERS}" "freerdp-client freerdp winpr") + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Core/Test") diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestConnect.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestConnect.c new file mode 100644 index 0000000000000000000000000000000000000000..24874a622df1dacb772480366d10e224ad7267dd --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestConnect.c @@ -0,0 +1,338 @@ +#include +#include +#include +#include + +#include +#include +#include + +static HANDLE s_sync = NULL; + +static int runInstance(int argc, char* argv[], freerdp** inst, DWORD timeout) +{ + int rc = -1; + RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 }; + rdpContext* context = NULL; + + clientEntryPoints.Size = sizeof(RDP_CLIENT_ENTRY_POINTS); + clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION; + clientEntryPoints.ContextSize = sizeof(rdpContext); + context = freerdp_client_context_new(&clientEntryPoints); + + if (!context) + goto finish; + + if (inst) + *inst = context->instance; + + context->instance->ChooseSmartcard = NULL; + context->instance->PresentGatewayMessage = NULL; + context->instance->LogonErrorInfo = NULL; + context->instance->AuthenticateEx = NULL; + context->instance->VerifyCertificateEx = NULL; + context->instance->VerifyChangedCertificateEx = NULL; + + if (!freerdp_settings_set_bool(context->settings, FreeRDP_DeactivateClientDecoding, TRUE)) + return FALSE; + + if (freerdp_client_settings_parse_command_line(context->settings, argc, argv, FALSE) < 0) + goto finish; + + if (!freerdp_settings_set_uint32(context->settings, FreeRDP_TcpConnectTimeout, timeout)) + goto finish; + + if (!freerdp_client_load_addins(context->channels, context->settings)) + goto finish; + + if (s_sync) + { + if (!SetEvent(s_sync)) + goto finish; + } + + rc = 1; + + if (!freerdp_connect(context->instance)) + goto finish; + + rc = 2; + + if (!freerdp_disconnect(context->instance)) + goto finish; + + rc = 0; +finish: + freerdp_client_context_free(context); + if (inst) + *inst = NULL; + return rc; +} + +static int testTimeout(int port) +{ + const DWORD timeout = 200; + DWORD start = 0; + DWORD end = 0; + DWORD diff = 0; + char arg1[] = "/v:192.0.2.1:XXXXX"; + char* argv[] = { "test", "/v:192.0.2.1:XXXXX" }; + int rc = 0; + (void)_snprintf(arg1, 18, "/v:192.0.2.1:%d", port); + argv[1] = arg1; + start = GetTickCount(); + rc = runInstance(ARRAYSIZE(argv), argv, NULL, timeout); + end = GetTickCount(); + + if (rc != 1) + return -1; + + diff = end - start; + + if (diff > 4 * timeout) + return -1; + + if (diff < timeout) + return -1; + + printf("%s: Success!\n", __func__); + return 0; +} + +struct testThreadArgs +{ + int port; + freerdp** arg; +}; + +static DWORD WINAPI testThread(LPVOID arg) +{ + char arg1[] = "/v:192.0.2.1:XXXXX"; + char* argv[] = { "test", "/v:192.0.2.1:XXXXX" }; + int rc = 0; + struct testThreadArgs* args = arg; + (void)_snprintf(arg1, 18, "/v:192.0.2.1:%d", args->port); + argv[1] = arg1; + rc = runInstance(ARRAYSIZE(argv), argv, args->arg, 5000); + + if (rc != 1) + ExitThread(-1); + + ExitThread(0); + return 0; +} + +static int testAbort(int port) +{ + DWORD status = 0; + DWORD start = 0; + DWORD end = 0; + DWORD diff = 0; + HANDLE thread = NULL; + struct testThreadArgs args; + freerdp* instance = NULL; + s_sync = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (!s_sync) + return -1; + + args.port = port; + args.arg = &instance; + start = GetTickCount(); + thread = CreateThread(NULL, 0, testThread, &args, 0, NULL); + + if (!thread) + { + (void)CloseHandle(s_sync); + s_sync = NULL; + return -1; + } + + (void)WaitForSingleObject(s_sync, INFINITE); + Sleep(100); /* Wait until freerdp_connect has been called */ + if (instance) + { + freerdp_abort_connect_context(instance->context); + + if (!freerdp_shall_disconnect_context(instance->context)) + { + (void)CloseHandle(s_sync); + (void)CloseHandle(thread); + s_sync = NULL; + return -1; + } + } + + status = WaitForSingleObject(thread, 20000); + end = GetTickCount(); + (void)CloseHandle(s_sync); + (void)CloseHandle(thread); + s_sync = NULL; + diff = end - start; + + if (diff > 5000) + { + printf("%s required %" PRIu32 "ms for the test\n", __func__, diff); + return -1; + } + + if (WAIT_OBJECT_0 != status) + return -1; + + printf("%s: Success!\n", __func__); + return 0; +} + +static char* concatenate(size_t count, ...) +{ + char* rc = NULL; + va_list ap = { 0 }; + va_start(ap, count); + rc = _strdup(va_arg(ap, char*)); + for (size_t x = 1; x < count; x++) + { + const char* cur = va_arg(ap, const char*); + char* tmp = GetCombinedPath(rc, cur); + free(rc); + rc = tmp; + } + va_end(ap); + return rc; +} + +static BOOL prepare_certificates(const char* path) +{ + BOOL rc = FALSE; + char* exe = NULL; + DWORD status = 0; + STARTUPINFOA si = { 0 }; + PROCESS_INFORMATION process = { 0 }; + char commandLine[8192] = { 0 }; + + if (!path) + return FALSE; + + exe = concatenate(5, TESTING_OUTPUT_DIRECTORY, "winpr", "tools", "makecert-cli", + "winpr-makecert" CMAKE_EXECUTABLE_SUFFIX); + if (!exe) + return FALSE; + (void)_snprintf(commandLine, sizeof(commandLine), "%s -format crt -path . -n server", exe); + + rc = CreateProcessA(exe, commandLine, NULL, NULL, TRUE, 0, NULL, path, &si, &process); + free(exe); + if (!rc) + goto fail; + status = WaitForSingleObject(process.hProcess, 30000); + if (status != WAIT_OBJECT_0) + goto fail; + rc = TRUE; +fail: + (void)CloseHandle(process.hProcess); + (void)CloseHandle(process.hThread); + return rc; +} + +static int testSuccess(int port) +{ + int r = 0; + int rc = -2; + STARTUPINFOA si = { 0 }; + PROCESS_INFORMATION process = { 0 }; + char arg1[] = "/v:127.0.0.1:XXXXX"; + char* clientArgs[] = { "test", "/v:127.0.0.1:XXXXX", "/cert:ignore", "/rfx", NULL }; + char* commandLine = NULL; + size_t commandLineLen = 0; + int argc = 4; + char* path = NULL; + char* wpath = NULL; + char* exe = GetCombinedPath(TESTING_OUTPUT_DIRECTORY, "server"); + (void)_snprintf(arg1, 18, "/v:127.0.0.1:%d", port); + clientArgs[1] = arg1; + + if (!exe) + goto fail; + + path = GetCombinedPath(exe, "Sample"); + wpath = GetCombinedPath(exe, "Sample"); + free(exe); + exe = NULL; + + if (!path || !wpath) + goto fail; + + exe = GetCombinedPath(path, "sfreerdp-server" CMAKE_EXECUTABLE_SUFFIX); + + if (!exe) + goto fail; + + printf("Sample Server: %s\n", exe); + printf("Workspace: %s\n", wpath); + + if (!winpr_PathFileExists(exe)) + goto fail; + + if (!prepare_certificates(wpath)) + goto fail; + + // Start sample server locally. + commandLineLen = strlen(exe) + strlen("--port=XXXXX") + 1; + commandLine = malloc(commandLineLen); + + if (!commandLine) + goto fail; + + (void)_snprintf(commandLine, commandLineLen, "%s --port=%d", exe, port); + si.cb = sizeof(si); + + if (!CreateProcessA(NULL, commandLine, NULL, NULL, FALSE, 0, NULL, wpath, &si, &process)) + goto fail; + + Sleep(5000); /* let the server start */ + r = runInstance(argc, clientArgs, NULL, 10000); + + if (!TerminateProcess(process.hProcess, 0)) + goto fail; + + (void)WaitForSingleObject(process.hProcess, INFINITE); + (void)CloseHandle(process.hProcess); + (void)CloseHandle(process.hThread); + printf("%s: returned %d!\n", __func__, r); + rc = r; + + if (rc == 0) + printf("%s: Success!\n", __func__); + +fail: + free(exe); + free(path); + free(wpath); + free(commandLine); + return rc; +} + +int TestConnect(int argc, char* argv[]) +{ + int randomPort = 0; + int random = 0; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + winpr_RAND(&random, sizeof(random)); + randomPort = 3389 + (random % 200); + + /* Test connect to not existing server, + * check if timeout is honored. */ + if (testTimeout(randomPort)) + return -1; + + /* Test connect to not existing server, + * check if connection abort is working. */ + if (testAbort(randomPort)) + return -1; + + /* Test connect to existing server, + * check if connection is working. */ + if (testSuccess(randomPort)) + return -1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCoreClient.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCoreClient.c new file mode 100644 index 0000000000000000000000000000000000000000..d0f76aeddf4a0a0c49c7c6f3527a84bce9ed2bbb --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCoreClient.c @@ -0,0 +1,117 @@ +#include + +#include "../fastpath.h" +#include "../surface.h" +#include "../window.h" +#include "../info.h" +#include "../multitransport.h" + +static BOOL test_client(const uint8_t* Data, size_t Size) +{ + RDP_CLIENT_ENTRY_POINTS entry = { 0 }; + + entry.Version = RDP_CLIENT_INTERFACE_VERSION; + entry.Size = sizeof(RDP_CLIENT_ENTRY_POINTS_V1); + entry.ContextSize = sizeof(rdpContext); + + rdpContext* context = freerdp_client_context_new(&entry); + if (!context) + goto fail; + + rdpRdp* rdp = context->rdp; + WINPR_ASSERT(rdp); + + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticConstInit(&sbuffer, Data, Size); + + { + rdpFastPath* fastpath = rdp->fastpath; + WINPR_ASSERT(fastpath); + + fastpath_recv_updates(fastpath, s); + fastpath_recv_inputs(fastpath, s); + + UINT16 length = 0; + fastpath_read_header_rdp(fastpath, s, &length); + fastpath_decrypt(fastpath, s, &length); + } + + { + UINT16 length = 0; + UINT16 flags = 0; + UINT16 channelId = 0; + UINT16 tpktLength = 0; + UINT16 remainingLength = 0; + UINT16 type = 0; + UINT16 securityFlags = 0; + UINT32 share_id = 0; + BYTE compressed_type = 0; + BYTE btype = 0; + UINT16 compressed_len = 0; + + rdp_recv_callback(rdp->transport, s, rdp); + rdp_read_security_header(rdp, s, &flags, &length); + rdp_read_header(rdp, s, &length, &channelId); + rdp_read_share_control_header(rdp, s, &tpktLength, &remainingLength, &type, &channelId); + rdp_read_share_data_header(rdp, s, &length, &btype, &share_id, &compressed_type, + &compressed_len); + rdp_recv_enhanced_security_redirection_packet(rdp, s); + rdp_recv_out_of_sequence_pdu(rdp, s, type, length); + rdp_recv_message_channel_pdu(rdp, s, securityFlags); + } + { + rdpUpdate* update = rdp->update; + UINT16 channelId = 0; + UINT16 length = 0; + UINT16 pduSource = 0; + UINT16 pduLength = 0; + update_recv_order(update, s); + update_recv_altsec_window_order(update, s); + update_recv_play_sound(update, s); + update_recv_pointer(update, s); + update_recv_surfcmds(update, s); + rdp_recv_get_active_header(rdp, s, &channelId, &length); + rdp_recv_demand_active(rdp, s, pduSource, length); + rdp_recv_confirm_active(rdp, s, pduLength); + } + { + rdpNla* nla = nla_new(rdp->context, rdp->transport); + nla_recv_pdu(nla, s); + nla_free(nla); + } + { + rdp_recv_heartbeat_packet(rdp, s); + rdp->state = CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE; + rdp_recv_client_info(rdp, s); + rdp_recv_save_session_info(rdp, s); + } + { + freerdp_is_valid_mcs_create_request(Data, Size); + freerdp_is_valid_mcs_create_response(Data, Size); + } + { + multitransport_recv_request(rdp->multitransport, s); + multitransport_recv_response(rdp->multitransport, s); + } + { + autodetect_recv_request_packet(rdp->autodetect, RDP_TRANSPORT_TCP, s); + autodetect_recv_response_packet(rdp->autodetect, RDP_TRANSPORT_TCP, s); + } + { + rdp_recv_deactivate_all(rdp, s); + rdp_recv_server_synchronize_pdu(rdp, s); + rdp_recv_client_synchronize_pdu(rdp, s); + + rdp_recv_data_pdu(rdp, s); + rdp_recv_font_map_pdu(rdp, s); + } +fail: + freerdp_client_context_free(context); + return TRUE; +} + +int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) +{ + test_client(Data, Size); + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCoreServer.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCoreServer.c new file mode 100644 index 0000000000000000000000000000000000000000..b43373ce915ad82e3099d21c8018594f0b01c820 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCoreServer.c @@ -0,0 +1,108 @@ +#include + +#include "../fastpath.h" +#include "../surface.h" +#include "../window.h" +#include "../info.h" +#include "../multitransport.h" + +static BOOL test_server(const uint8_t* Data, size_t Size) +{ + freerdp_peer* client = calloc(1, sizeof(freerdp_peer)); + if (!client) + goto fail; + client->ContextSize = sizeof(rdpContext); + if (!freerdp_peer_context_new(client)) + goto fail; + + WINPR_ASSERT(client->context); + rdpRdp* rdp = client->context->rdp; + WINPR_ASSERT(rdp); + + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticConstInit(&sbuffer, Data, Size); + + { + rdpFastPath* fastpath = rdp->fastpath; + WINPR_ASSERT(fastpath); + + fastpath_recv_updates(fastpath, s); + fastpath_recv_inputs(fastpath, s); + + UINT16 length = 0; + fastpath_read_header_rdp(fastpath, s, &length); + fastpath_decrypt(fastpath, s, &length); + } + + { + UINT16 length = 0; + UINT16 flags = 0; + UINT16 channelId = 0; + UINT16 tpktLength = 0; + UINT16 remainingLength = 0; + UINT16 type = 0; + UINT16 securityFlags = 0; + UINT32 share_id = 0; + BYTE compressed_type = 0; + BYTE btype = 0; + UINT16 compressed_len = 0; + rdp_read_security_header(rdp, s, &flags, &length); + rdp_read_header(rdp, s, &length, &channelId); + rdp_read_share_control_header(rdp, s, &tpktLength, &remainingLength, &type, &channelId); + rdp_read_share_data_header(rdp, s, &length, &btype, &share_id, &compressed_type, + &compressed_len); + rdp_recv_message_channel_pdu(rdp, s, securityFlags); + } + { + rdpUpdate* update = rdp->update; + UINT16 channelId = 0; + UINT16 length = 0; + UINT16 pduSource = 0; + UINT16 pduLength = 0; + update_recv_order(update, s); + update_recv_altsec_window_order(update, s); + update_recv_play_sound(update, s); + update_recv_pointer(update, s); + update_recv_surfcmds(update, s); + rdp_recv_get_active_header(rdp, s, &channelId, &length); + rdp_recv_demand_active(rdp, s, pduSource, length); + rdp_recv_confirm_active(rdp, s, pduLength); + } + { + rdpNla* nla = nla_new(rdp->context, rdp->transport); + nla_recv_pdu(nla, s); + nla_free(nla); + } + { + rdp_recv_heartbeat_packet(rdp, s); + rdp->state = CONNECTION_STATE_SECURE_SETTINGS_EXCHANGE; + rdp_recv_client_info(rdp, s); + } + { + freerdp_is_valid_mcs_create_request(Data, Size); + freerdp_is_valid_mcs_create_response(Data, Size); + } + { + multitransport_recv_request(rdp->multitransport, s); + multitransport_recv_response(rdp->multitransport, s); + } + { + autodetect_recv_request_packet(rdp->autodetect, RDP_TRANSPORT_TCP, s); + autodetect_recv_response_packet(rdp->autodetect, RDP_TRANSPORT_TCP, s); + } + { + rdp_recv_deactivate_all(rdp, s); + rdp_recv_server_synchronize_pdu(rdp, s); + rdp_recv_client_synchronize_pdu(rdp, s); + } +fail: + freerdp_peer_context_free(client); + free(client); + return TRUE; +} + +int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) +{ + test_server(Data, Size); + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCryptoCertificateDataSetPEM.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCryptoCertificateDataSetPEM.c new file mode 100644 index 0000000000000000000000000000000000000000..203271564cba7fd7521e5ee8c5e636cf5c915bea --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestFuzzCryptoCertificateDataSetPEM.c @@ -0,0 +1,22 @@ +#include +#include +#include + +int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) +{ + rdpCertificateData* data = NULL; + char* pem = calloc(Size + 1, sizeof(char)); + if (pem == NULL) + goto cleanup; + memcpy(pem, Data, Size); + + data = freerdp_certificate_data_new_from_pem("somehost", 1234, pem, Size); + if (!data) + goto cleanup; + +cleanup: + freerdp_certificate_data_free(data); + free(pem); + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestSettings.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestSettings.c new file mode 100644 index 0000000000000000000000000000000000000000..3778a94155c7f5ade3514a98e2f42e6c6bbc837d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestSettings.c @@ -0,0 +1,1753 @@ +#include + +#include +#include + +#include +#include + +#include "settings_property_lists.h" +#include "../settings.h" + +static BOOL log_result(BOOL value, const char* fkt) +{ + (void)fprintf(stderr, "TestSettings [%s] returned %s\n", fkt, value ? "TRUE" : "FALSE"); + return value; +} + +static BOOL log_result_case(BOOL value, const char* fkt, size_t testcase) +{ + (void)fprintf(stderr, "TestSettings [%s] testcase %" PRIuz " returned %s\n", fkt, testcase, + value ? "TRUE" : "FALSE"); + return value; +} + +static BOOL compare(const ADDIN_ARGV* got, const ADDIN_ARGV* expect) +{ + BOOL rc = TRUE; + if (!got && !expect) + return FALSE; + if (!got && expect) + return FALSE; + if (got && !expect) + return FALSE; + if (got->argc != expect->argc) + return FALSE; + + for (int x = 0; x < expect->argc; x++) + { + if (strcmp(got->argv[x], expect->argv[x]) != 0) + rc = FALSE; + } + return log_result(rc, __func__); +} + +static BOOL test_dyn_channels(void) +{ + BOOL rc = FALSE; + BOOL test = 0; + UINT32 u32 = 0; + rdpSettings* settings = freerdp_settings_new(0); + const char* argv1[] = { "foobar" }; + ADDIN_ARGV* args1 = NULL; + const ADDIN_ARGV* cmp1 = NULL; + const char* argv2[] = { "gaga", "abba", "foo" }; + ADDIN_ARGV* args2 = NULL; + const ADDIN_ARGV* cmp2 = NULL; + const ADDIN_ARGV* got = NULL; + + if (!settings) + goto fail; + + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount); + if (u32 != 0) + goto fail; + + /* Test the function return an error for unknown channels */ + test = freerdp_dynamic_channel_collection_del(settings, "foobar"); + if (test) + goto fail; + got = freerdp_dynamic_channel_collection_find(settings, "foobar"); + if (got) + goto fail; + + /* Add the channel */ + cmp1 = args1 = freerdp_addin_argv_new(ARRAYSIZE(argv1), argv1); + test = freerdp_dynamic_channel_collection_add(settings, args1); + if (!test) + goto fail; + args1 = NULL; /* settings have taken ownership */ + + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount); + if (u32 != 1) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelArraySize); + if (u32 < 1) + goto fail; + + cmp2 = args2 = freerdp_addin_argv_new(ARRAYSIZE(argv2), argv2); + test = freerdp_dynamic_channel_collection_add(settings, args2); + if (!test) + goto fail; + args2 = NULL; /* settings have taken ownership */ + + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount); + if (u32 != 2) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelArraySize); + if (u32 < 2) + goto fail; + + /* Test the function return success for known channels */ + got = freerdp_dynamic_channel_collection_find(settings, "foobar"); + if (!compare(got, cmp1)) + goto fail; + got = freerdp_dynamic_channel_collection_find(settings, "gaga"); + if (!compare(got, cmp2)) + goto fail; + test = freerdp_dynamic_channel_collection_del(settings, "foobar"); + if (!test) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount); + if (u32 != 1) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelArraySize); + if (u32 < 1) + goto fail; + got = freerdp_dynamic_channel_collection_find(settings, "foobar"); + if (compare(got, cmp1)) + goto fail; + got = freerdp_dynamic_channel_collection_find(settings, "gaga"); + if (!compare(got, cmp2)) + goto fail; + test = freerdp_dynamic_channel_collection_del(settings, "gaga"); + if (!test) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_DynamicChannelCount); + if (u32 != 0) + goto fail; + got = freerdp_dynamic_channel_collection_find(settings, "foobar"); + if (compare(got, cmp1)) + goto fail; + got = freerdp_dynamic_channel_collection_find(settings, "gaga"); + if (compare(got, cmp2)) + goto fail; + + rc = TRUE; + +fail: + freerdp_settings_free(settings); + freerdp_addin_argv_free(args1); + freerdp_addin_argv_free(args2); + return log_result(rc, __func__); +} + +static BOOL test_static_channels(void) +{ + BOOL rc = FALSE; + BOOL test = 0; + UINT32 u32 = 0; + rdpSettings* settings = freerdp_settings_new(0); + const char* argv1[] = { "foobar" }; + ADDIN_ARGV* args1 = NULL; + const ADDIN_ARGV* cmp1 = NULL; + const char* argv2[] = { "gaga", "abba", "foo" }; + ADDIN_ARGV* args2 = NULL; + const ADDIN_ARGV* cmp2 = NULL; + const ADDIN_ARGV* got = NULL; + + if (!settings) + goto fail; + + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount); + if (u32 != 0) + goto fail; + + /* Test the function return an error for unknown channels */ + test = freerdp_static_channel_collection_del(settings, "foobar"); + if (test) + goto fail; + got = freerdp_static_channel_collection_find(settings, "foobar"); + if (got) + goto fail; + + /* Add the channel */ + cmp1 = args1 = freerdp_addin_argv_new(ARRAYSIZE(argv1), argv1); + test = freerdp_static_channel_collection_add(settings, args1); + if (!test) + goto fail; + args1 = NULL; /* settings have taken ownership */ + + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount); + if (u32 != 1) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize); + if (u32 < 1) + goto fail; + + cmp2 = args2 = freerdp_addin_argv_new(ARRAYSIZE(argv2), argv2); + test = freerdp_static_channel_collection_add(settings, args2); + if (!test) + goto fail; + args2 = NULL; /* settings have taken ownership */ + + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount); + if (u32 != 2) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize); + if (u32 < 2) + goto fail; + + /* Test the function return success for known channels */ + got = freerdp_static_channel_collection_find(settings, "foobar"); + if (!compare(got, cmp1)) + goto fail; + got = freerdp_static_channel_collection_find(settings, "gaga"); + if (!compare(got, cmp2)) + goto fail; + test = freerdp_static_channel_collection_del(settings, "foobar"); + if (!test) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount); + if (u32 != 1) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelArraySize); + if (u32 < 1) + goto fail; + got = freerdp_static_channel_collection_find(settings, "foobar"); + if (compare(got, cmp1)) + goto fail; + got = freerdp_static_channel_collection_find(settings, "gaga"); + if (!compare(got, cmp2)) + goto fail; + test = freerdp_static_channel_collection_del(settings, "gaga"); + if (!test) + goto fail; + u32 = freerdp_settings_get_uint32(settings, FreeRDP_StaticChannelCount); + if (u32 != 0) + goto fail; + got = freerdp_static_channel_collection_find(settings, "foobar"); + if (compare(got, cmp1)) + goto fail; + got = freerdp_static_channel_collection_find(settings, "gaga"); + if (compare(got, cmp2)) + goto fail; + + rc = TRUE; + +fail: + freerdp_settings_free(settings); + freerdp_addin_argv_free(args1); + freerdp_addin_argv_free(args2); + return log_result(rc, __func__); +} + +static BOOL test_copy(void) +{ + BOOL rc = FALSE; + wLog* log = WLog_Get(__func__); + rdpSettings* settings = freerdp_settings_new(0); + rdpSettings* copy = freerdp_settings_clone(settings); + rdpSettings* modified = freerdp_settings_clone(settings); + + if (!settings || !copy || !modified) + goto fail; + if (!freerdp_settings_set_string(modified, FreeRDP_ServerHostname, "somerandomname")) + goto fail; + if (freerdp_settings_print_diff(log, WLOG_WARN, settings, copy)) + goto fail; + if (!freerdp_settings_print_diff(log, WLOG_WARN, settings, modified)) + goto fail; + + rc = TRUE; + +fail: + freerdp_settings_free(settings); + freerdp_settings_free(copy); + freerdp_settings_free(modified); + return log_result(rc, __func__); +} + +static BOOL test_helpers(void) +{ + BOOL rc = FALSE; + UINT32 flags = 0; + rdpSettings* settings = freerdp_settings_new(0); + if (!settings) + goto fail; + if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, TRUE)) + goto fail; + if (!freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE)) + goto fail; + flags = freerdp_settings_get_codecs_flags(settings); + if (flags != FREERDP_CODEC_ALL) + goto fail; + + if (!freerdp_settings_set_bool(settings, FreeRDP_NSCodec, FALSE)) + goto fail; + flags = freerdp_settings_get_codecs_flags(settings); + if (flags != (FREERDP_CODEC_ALL & ~FREERDP_CODEC_NSCODEC)) + goto fail; + + if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec, FALSE)) + goto fail; + flags = freerdp_settings_get_codecs_flags(settings); + if (flags != (FREERDP_CODEC_ALL & ~(FREERDP_CODEC_NSCODEC | FREERDP_CODEC_REMOTEFX))) + goto fail; + + if (!freerdp_settings_set_bool(settings, FreeRDP_NSCodec, TRUE)) + goto fail; + flags = freerdp_settings_get_codecs_flags(settings); + if (flags != (FREERDP_CODEC_ALL & ~FREERDP_CODEC_REMOTEFX)) + goto fail; + + rc = TRUE; +fail: + freerdp_settings_free(settings); + return log_result(rc, __func__); +} + +static BOOL format_uint(char* buffer, size_t size, UINT64 value, UINT16 intType, UINT64 max) +{ + const UINT64 lvalue = value > max ? max : value; + intType = intType % 3; + switch (intType) + { + case 0: + (void)_snprintf(buffer, size, "%" PRIu64, lvalue); + return TRUE; + case 1: + (void)_snprintf(buffer, size, "0x%" PRIx64, lvalue); + return TRUE; + case 2: + if (max < UINT64_MAX) + (void)_snprintf(buffer, size, "%" PRIu64, max + 1); + else + (void)_snprintf(buffer, size, "too large a number"); + return FALSE; + default: + (void)_snprintf(buffer, size, "not a number value"); + return FALSE; + } +} + +static BOOL print_negative(char* buffer, size_t size, INT64 value, INT64 min) +{ + switch (min) + { + case INT16_MIN: + (void)_snprintf(buffer, size, "%" PRId16, (INT16)value); + return FALSE; + case INT32_MIN: + (void)_snprintf(buffer, size, "%" PRId32, (INT32)value); + return FALSE; + case INT64_MIN: + (void)_snprintf(buffer, size, "%" PRId64, value); + return FALSE; + default: + (void)_snprintf(buffer, size, "too small a number"); + return FALSE; + } +} + +static BOOL print_xpositive(char* buffer, size_t size, INT64 value, INT64 max) +{ + if (value < 0) + { + (void)_snprintf(buffer, size, "%" PRId64, value); + return TRUE; + } + + switch (max) + { + case INT16_MAX: + (void)_snprintf(buffer, size, "%" PRIx16, (INT16)value); + return FALSE; + case INT32_MAX: + (void)_snprintf(buffer, size, "%" PRIx32, (INT32)value); + return FALSE; + case INT64_MAX: + (void)_snprintf(buffer, size, "%" PRIx64, value); + return FALSE; + default: + (void)_snprintf(buffer, size, "too small a number"); + return FALSE; + } +} + +static BOOL format_int(char* buffer, size_t size, INT64 value, UINT16 intType, INT64 max, INT64 min) +{ + const INT64 lvalue = (value > max) ? max : ((value < min) ? min : value); + intType = intType % 4; + + switch (intType) + { + case 0: + (void)_snprintf(buffer, size, "%" PRId64, lvalue); + return TRUE; + case 1: + print_xpositive(buffer, size, lvalue, max); + return TRUE; + case 2: + if (max < INT64_MAX) + (void)_snprintf(buffer, size, "%" PRId64, max + 1); + else + (void)_snprintf(buffer, size, "too large a number"); + return FALSE; + case 3: + if (min < INT64_MIN) + print_negative(buffer, size, min - 1, INT64_MIN); + else + (void)_snprintf(buffer, size, "too small a number"); + return FALSE; + default: + (void)_snprintf(buffer, size, "not a number value"); + return FALSE; + } +} + +static BOOL format_bool(char* buffer, size_t size, UINT16 intType) +{ + intType = intType % 10; + switch (intType) + { + case 0: + (void)_snprintf(buffer, size, "FALSE"); + return TRUE; + case 1: + (void)_snprintf(buffer, size, "FaLsE"); + return TRUE; + case 2: + (void)_snprintf(buffer, size, "False"); + return TRUE; + case 3: + (void)_snprintf(buffer, size, "false"); + return TRUE; + case 4: + (void)_snprintf(buffer, size, "falseentry"); + return FALSE; + case 5: + (void)_snprintf(buffer, size, "TRUE"); + return TRUE; + case 6: + (void)_snprintf(buffer, size, "TrUe"); + return TRUE; + case 7: + (void)_snprintf(buffer, size, "True"); + return TRUE; + case 8: + (void)_snprintf(buffer, size, "true"); + return TRUE; + case 9: + (void)_snprintf(buffer, size, "someentry"); + return FALSE; + default: + (void)_snprintf(buffer, size, "ok"); + return FALSE; + } +} + +static BOOL check_key_helpers(size_t key, const char* stype) +{ + int test_rounds = 100; + BOOL res = FALSE; + rdpSettings* settings = NULL; + SSIZE_T rc = 0; + SSIZE_T tkey = 0; + SSIZE_T type = 0; + const size_t clear_keys[] = { FreeRDP_RdpServerCertificate, + FreeRDP_RdpServerRsaKey, + FreeRDP_RedirectionPassword, + FreeRDP_RedirectionTsvUrl, + FreeRDP_LoadBalanceInfo, + FreeRDP_ServerRandom, + FreeRDP_ClientRandom, + FreeRDP_ServerCertificate, + FreeRDP_TargetNetAddresses, + FreeRDP_ReceivedCapabilities, + FreeRDP_ServerLicenseProductIssuers, + FreeRDP_TargetNetPorts, + FreeRDP_DeviceArray, + FreeRDP_ChannelDefArray, + FreeRDP_MonitorDefArray, + FreeRDP_ClientAutoReconnectCookie, + FreeRDP_ServerAutoReconnectCookie, + FreeRDP_ClientTimeZone, + FreeRDP_BitmapCacheV2CellInfo, + FreeRDP_GlyphCache, + FreeRDP_FragCache, + FreeRDP_StaticChannelArray, + FreeRDP_DynamicChannelArray, + FreeRDP_ReceivedCapabilities, + FreeRDP_OrderSupport, + FreeRDP_MonitorIds }; + const char* name = freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + if (!name) + { + printf("[%s] missing name for key %" PRIuz "\n", stype, key); + return FALSE; + } + tkey = freerdp_settings_get_key_for_name(name); + if (tkey < 0) + { + printf("[%s] missing reverse name for key %s [%" PRIuz "]\n", stype, name, key); + return FALSE; + } + if ((size_t)tkey != key) + { + printf("[%s] mismatch reverse name for key %s [%" PRIuz "]: %" PRIdz "\n", stype, name, key, + tkey); + return FALSE; + } + type = freerdp_settings_get_type_for_name(name); + if (type < 0) + { + printf("[%s] missing reverse type for key %s [%" PRIuz "]\n", stype, name, key); + return FALSE; + } + rc = freerdp_settings_get_type_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + if (rc < 0) + { + printf("[%s] missing reverse name for key %s [%" PRIuz "]\n", stype, name, key); + return FALSE; + } + + if (rc != type) + { + printf("[%s] mismatch reverse type for key %s [%" PRIuz "]: %" PRIdz " <--> %" PRIdz "\n", + stype, name, key, rc, type); + return FALSE; + } + + settings = freerdp_settings_new(0); + if (!settings) + { + printf("[%s] freerdp_settings_new failed\n", stype); + goto fail; + } + for (size_t x = 0; x < ARRAYSIZE(clear_keys); x++) + { + const size_t id = clear_keys[x]; + const char* foo = freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, id)); + if (!freerdp_settings_set_pointer_len(settings, id, NULL, 0)) + { + printf("[%s] freerdp_settings_set_pointer_len(%s, NULL, 0) failed\n", stype, foo); + goto fail; + } + } + do + { + UINT16 intEntryType = 0; + BOOL expect = 0; + BOOL have = 0; + char value[8192] = { 0 }; + union + { + UINT64 u64; + INT64 i64; + UINT32 u32; + INT32 i32; + UINT16 u16; + INT16 i16; + void* pv; + } val; + + winpr_RAND(&intEntryType, sizeof(intEntryType)); + winpr_RAND(&val.u64, sizeof(val.u64)); + + switch (type) + { + case RDP_SETTINGS_TYPE_BOOL: + expect = format_bool(value, sizeof(value), intEntryType); + break; + case RDP_SETTINGS_TYPE_UINT16: + expect = format_uint(value, sizeof(value), val.u64, intEntryType, UINT16_MAX); + break; + case RDP_SETTINGS_TYPE_INT16: + expect = + format_int(value, sizeof(value), val.i64, intEntryType, INT16_MAX, INT16_MIN); + break; + case RDP_SETTINGS_TYPE_UINT32: + expect = format_uint(value, sizeof(value), val.u64, intEntryType, UINT32_MAX); + break; + case RDP_SETTINGS_TYPE_INT32: + expect = + format_int(value, sizeof(value), val.i64, intEntryType, INT32_MAX, INT32_MIN); + break; + case RDP_SETTINGS_TYPE_UINT64: + expect = format_uint(value, sizeof(value), val.u64, intEntryType, UINT64_MAX); + break; + case RDP_SETTINGS_TYPE_INT64: + expect = + format_int(value, sizeof(value), val.i64, intEntryType, INT64_MAX, INT64_MIN); + break; + case RDP_SETTINGS_TYPE_STRING: + expect = TRUE; + (void)_snprintf(value, sizeof(value), "somerandomstring"); + break; + case RDP_SETTINGS_TYPE_POINTER: + expect = FALSE; + break; + + default: + printf("[%s] invalid type for key %s [%" PRIuz "]: %" PRIdz " <--> %" PRIdz "\n", + stype, name, key, rc, type); + goto fail; + } + + have = freerdp_settings_set_value_for_name(settings, name, value); + if (have != expect) + { + printf("[%s] have[%s] != expect[%s]\n", stype, have ? "TRUE" : "FALSE", + expect ? "TRUE" : "FALSE"); + goto fail; + } + + } while (test_rounds-- > 0); + + res = TRUE; +fail: + freerdp_settings_free(settings); + return log_result(res, __func__); +} + +static BOOL check_args(const RDPDR_DEVICE* what, size_t count, const char* args[]) +{ + WINPR_ASSERT(what); + + if (count > 0) + { + if (strcmp(what->Name, args[0]) != 0) + return FALSE; + } + + switch (what->Type) + { + case RDPDR_DTYP_PRINT: + { + const RDPDR_PRINTER* a = (const RDPDR_PRINTER*)what; + if (count <= 1) + return TRUE; + if (!a->DriverName) + return FALSE; + return strcmp(a->DriverName, args[1]) == 0; + } + + case RDPDR_DTYP_SERIAL: + { + const RDPDR_SERIAL* a = (const RDPDR_SERIAL*)what; + + if (count > 1) + { + if (!a->Path) + return FALSE; + if (strcmp(a->Path, args[1]) != 0) + return FALSE; + } + + if (count > 2) + { + if (!a->Driver) + return FALSE; + if (strcmp(a->Driver, args[2]) != 0) + return FALSE; + } + + if (count > 3) + { + if (!a->Permissive) + return FALSE; + if (strcmp(a->Permissive, args[3]) != 0) + return FALSE; + } + return TRUE; + } + + case RDPDR_DTYP_PARALLEL: + { + const RDPDR_PARALLEL* a = (const RDPDR_PARALLEL*)what; + if (count <= 1) + return TRUE; + if (!a->Path) + return FALSE; + return strcmp(a->Path, args[1]) == 0; + } + + case RDPDR_DTYP_SMARTCARD: + return TRUE; + + case RDPDR_DTYP_FILESYSTEM: + { + const RDPDR_DRIVE* a = (const RDPDR_DRIVE*)what; + if (count > 1) + { + if (!a->Path) + return FALSE; + if (strcmp(a->Path, args[1]) != 0) + return FALSE; + } + if (count > 2) + { + return a->automount == (args[2] == NULL) ? TRUE : FALSE; + } + else + return !a->automount; + } + + default: + return FALSE; + } +} + +static int check_device_type_arg(UINT32 Type, size_t count, const char* args[]) +{ + int rc = -3; + RDPDR_DEVICE* device = freerdp_device_new(Type, count, args); + RDPDR_DEVICE* clone = freerdp_device_clone(device); + + if (!device) + goto fail; + + rc++; + if (!clone) + goto fail; + + rc++; + if (!check_args(device, count, args)) + goto fail; + + rc++; + if (!freerdp_device_equal(clone, device)) + goto fail; + rc++; + +fail: + freerdp_device_free(device); + freerdp_device_free(clone); + return log_result(rc, __func__); +} + +static BOOL check_device_type(void) +{ + struct test_entry + { + int expect; + UINT32 type; + size_t count; + const char** args; + }; + const char* args[] = { "somename", "anothername", "3rdname", "4thname" }; + const struct test_entry tests[] = { + { 1, RDPDR_DTYP_SERIAL, 0, NULL }, + { 1, RDPDR_DTYP_SERIAL, 0, args }, + { 1, RDPDR_DTYP_SERIAL, 1, args }, + { 1, RDPDR_DTYP_SERIAL, 2, args }, + { 1, RDPDR_DTYP_SERIAL, 3, args }, + { 1, RDPDR_DTYP_SERIAL, 4, args }, + { 1, RDPDR_DTYP_PARALLEL, 0, NULL }, + { 1, RDPDR_DTYP_PARALLEL, 0, args }, + { 1, RDPDR_DTYP_PARALLEL, 1, args }, + { 1, RDPDR_DTYP_PARALLEL, 2, args }, + { 1, RDPDR_DTYP_PARALLEL, 3, args }, + { 1, RDPDR_DTYP_PARALLEL, 4, args }, + { 1, RDPDR_DTYP_PRINT, 0, NULL }, + { 1, RDPDR_DTYP_PRINT, 0, args }, + { 1, RDPDR_DTYP_PRINT, 1, args }, + { 1, RDPDR_DTYP_PRINT, 2, args }, + { 1, RDPDR_DTYP_PRINT, 3, args }, + { 1, RDPDR_DTYP_PRINT, 4, args }, + { 1, RDPDR_DTYP_FILESYSTEM, 0, NULL }, + { 1, RDPDR_DTYP_FILESYSTEM, 0, args }, + { 1, RDPDR_DTYP_FILESYSTEM, 1, args }, + { 1, RDPDR_DTYP_FILESYSTEM, 2, args }, + { 1, RDPDR_DTYP_FILESYSTEM, 3, args }, + { 1, RDPDR_DTYP_FILESYSTEM, 4, args }, + { 1, RDPDR_DTYP_SMARTCARD, 0, NULL }, + { 1, RDPDR_DTYP_SMARTCARD, 0, args }, + { 1, RDPDR_DTYP_SMARTCARD, 1, args }, + { 1, RDPDR_DTYP_SMARTCARD, 2, args }, + { 1, RDPDR_DTYP_SMARTCARD, 3, args }, + { 1, RDPDR_DTYP_SMARTCARD, 4, args }, + { -3, 0x123, 0, NULL }, + { -3, 0x123, 0, args }, + { -3, 0x123, 1, args }, + { -3, 0x123, 2, args }, + { -3, 0x123, 3, args }, + { -3, 0x123, 4, args }, + }; + BOOL rc = TRUE; + for (size_t x = 0; x < ARRAYSIZE(tests); x++) + { + const struct test_entry* cur = &tests[x]; + int got = check_device_type_arg(cur->type, cur->count, cur->args); + if (got != cur->expect) + rc = FALSE; + } + return log_result(rc, __func__); +} + +static BOOL check_offsets(rdpSettings* settings, size_t id, size_t min, size_t max, BOOL checkPtr) +{ + BOOL rc = TRUE; + + WINPR_ASSERT(settings); + + if (!freerdp_settings_get_pointer(settings, id)) + return FALSE; + + for (size_t x = min; x < max; x++) + { + const void* ptr = freerdp_settings_get_pointer_array(settings, id, x); + if (!ptr && checkPtr) + rc = FALSE; + } + return log_result(rc, __func__); +} + +static BOOL test_write_offsets(rdpSettings* settings, size_t id, size_t elementSize, size_t min, + size_t max) +{ + WINPR_ASSERT(settings); + + for (size_t x = min; x < max; x++) + { + const void* ptr = NULL; + char buffer[8192] = { 0 }; + + winpr_RAND(buffer, sizeof(buffer)); + if (!freerdp_settings_set_pointer_array(settings, id, x, buffer)) + return FALSE; + ptr = freerdp_settings_get_pointer_array(settings, id, x); + if (!ptr) + return FALSE; + if (memcmp(ptr, buffer, elementSize) != 0) + return FALSE; + } + return TRUE; +} + +static BOOL test_pointer_array(void) +{ + struct pointer_test_case + { + BOOL checkPtr; + BOOL write; + size_t id; + SSIZE_T sizeId; + size_t size; + size_t elementSize; + }; + const struct pointer_test_case tests[] = { + { FALSE, FALSE, FreeRDP_DeviceArray, FreeRDP_DeviceArraySize, 32, sizeof(RDPDR_DEVICE*) }, + { FALSE, FALSE, FreeRDP_StaticChannelArray, FreeRDP_StaticChannelArraySize, 32, + sizeof(ADDIN_ARGV*) }, + { FALSE, FALSE, FreeRDP_DynamicChannelArray, FreeRDP_DynamicChannelArraySize, 33, + sizeof(ADDIN_ARGV*) }, + { TRUE, TRUE, FreeRDP_BitmapCacheV2CellInfo, FreeRDP_BitmapCacheV2NumCells, 5, + sizeof(BITMAP_CACHE_V2_CELL_INFO) }, + { FALSE, FALSE, FreeRDP_OrderSupport, -1, 32, sizeof(BYTE) }, + { FALSE, FALSE, FreeRDP_ReceivedCapabilities, -1, 32, sizeof(BYTE) }, + { TRUE, TRUE, FreeRDP_GlyphCache, -1, 10, sizeof(GLYPH_CACHE_DEFINITION) }, + { TRUE, TRUE, FreeRDP_FragCache, -1, 1, sizeof(GLYPH_CACHE_DEFINITION) }, + { TRUE, TRUE, FreeRDP_MonitorIds, FreeRDP_NumMonitorIds, 33, sizeof(UINT32) }, + { TRUE, TRUE, FreeRDP_ChannelDefArray, FreeRDP_ChannelDefArraySize, 42, + sizeof(CHANNEL_DEF) }, + { TRUE, TRUE, FreeRDP_MonitorDefArray, FreeRDP_MonitorDefArraySize, 33, + sizeof(rdpMonitor) }, + { TRUE, TRUE, FreeRDP_ClientTimeZone, -1, 1, sizeof(TIME_ZONE_INFORMATION) }, + { FALSE, FALSE, FreeRDP_RdpServerCertificate, -1, 1, sizeof(rdpCertificate*) }, + //{ FALSE, FALSE, FreeRDP_RdpServerRsaKey, -1, 1, sizeof(rdpPrivateKey*) }, + { TRUE, TRUE, FreeRDP_RedirectionPassword, FreeRDP_RedirectionPasswordLength, 42, + sizeof(char) }, + { TRUE, TRUE, FreeRDP_RedirectionTsvUrl, FreeRDP_RedirectionTsvUrlLength, 42, + sizeof(char) }, + { TRUE, TRUE, FreeRDP_LoadBalanceInfo, FreeRDP_LoadBalanceInfoLength, 42, sizeof(char) }, + { TRUE, TRUE, FreeRDP_ServerRandom, FreeRDP_ServerRandomLength, 42, sizeof(char) }, + { TRUE, TRUE, FreeRDP_ClientRandom, FreeRDP_ClientRandomLength, 42, sizeof(char) }, + { TRUE, TRUE, FreeRDP_ServerCertificate, FreeRDP_ServerCertificateLength, 42, + sizeof(char) }, + { TRUE, TRUE, FreeRDP_ClientAutoReconnectCookie, -1, 1, sizeof(ARC_CS_PRIVATE_PACKET) }, + { TRUE, TRUE, FreeRDP_ServerAutoReconnectCookie, -1, 1, sizeof(ARC_SC_PRIVATE_PACKET) } + }; + BOOL rc = FALSE; + rdpSettings* settings = freerdp_settings_new(0); + if (!settings) + goto fail; + + for (size_t x = 0; x < ARRAYSIZE(tests); x++) + { + const struct pointer_test_case* cur = &tests[x]; + if (!freerdp_settings_set_pointer_len(settings, cur->id, NULL, cur->size)) + goto fail; + if (cur->sizeId >= 0) + { + const UINT32 s = freerdp_settings_get_uint32(settings, (size_t)cur->sizeId); + if (s != cur->size) + goto fail; + } + if (!check_offsets(settings, cur->id, 0, cur->size, cur->checkPtr)) + goto fail; + if (check_offsets(settings, cur->id, cur->size, cur->size + 5, TRUE)) + goto fail; + if (cur->write) + { + if (!test_write_offsets(settings, cur->id, cur->elementSize, 0, cur->size)) + goto fail; + if (test_write_offsets(settings, cur->id, cur->elementSize, cur->size, cur->size + 5)) + goto fail; + } + if (!freerdp_settings_set_pointer_len(settings, cur->id, NULL, 0)) + goto fail; + if (cur->sizeId >= 0) + { + const UINT32 s = freerdp_settings_get_uint32(settings, (size_t)cur->sizeId); + if (s != 0) + goto fail; + } + if (check_offsets(settings, cur->id, 0, cur->size, cur->checkPtr)) + goto fail; + if (cur->write) + { + if (test_write_offsets(settings, cur->id, cur->elementSize, 0, cur->size)) + goto fail; + } + if (!freerdp_settings_set_pointer_len(settings, cur->id, NULL, cur->size)) + goto fail; + if (cur->sizeId >= 0) + { + const UINT32 s = freerdp_settings_get_uint32(settings, (size_t)cur->sizeId); + if (s != cur->size) + goto fail; + } + if (!check_offsets(settings, cur->id, 0, cur->size, cur->checkPtr)) + goto fail; + if (check_offsets(settings, cur->id, cur->size + 1, cur->size + 5, TRUE)) + goto fail; + if (cur->write) + { + if (!test_write_offsets(settings, cur->id, cur->elementSize, 0, cur->size)) + goto fail; + if (test_write_offsets(settings, cur->id, cur->elementSize, cur->size, cur->size + 5)) + goto fail; + } + } + + rc = TRUE; + +fail: + freerdp_settings_free(settings); + return log_result(rc, __func__); +} + +struct validity_test_case +{ + BOOL expected; + size_t count; + const rdpMonitor* monitors; +}; + +static BOOL prepare_monitor_array(rdpSettings* settings, const struct validity_test_case* testcase) +{ + WINPR_ASSERT(settings); + WINPR_ASSERT(testcase); + + return freerdp_settings_set_monitor_def_array_sorted(settings, testcase->monitors, + testcase->count); +} + +static BOOL check_primary_offset(const rdpSettings* settings, const rdpMonitor* monitors, + size_t count) +{ + const rdpMonitor* cprimary = NULL; + for (size_t x = 0; x < count; x++) + { + const rdpMonitor* cur = &monitors[x]; + if (cur->is_primary) + cprimary = cur; + } + if (!cprimary) + { + for (size_t x = 0; x < count; x++) + { + const rdpMonitor* cur = &monitors[x]; + if ((cur->x == 0) && (cur->y == 0)) + cprimary = cur; + } + } + const rdpMonitor* sprimary = NULL; + for (size_t x = 0; x < count; x++) + { + const rdpMonitor* cur = + freerdp_settings_get_pointer_array(settings, FreeRDP_MonitorDefArray, x); + if (!cur) + return FALSE; + if (cur->is_primary) + sprimary = cur; + } + + if (!sprimary || !cprimary) + return FALSE; + + const INT32 xoff = cprimary->x; + const INT32 yoff = cprimary->y; + const INT32 sxoff = freerdp_settings_get_int32(settings, FreeRDP_MonitorLocalShiftX); + const INT32 syoff = freerdp_settings_get_int32(settings, FreeRDP_MonitorLocalShiftY); + if (xoff != sxoff) + return FALSE; + if (yoff != syoff) + return FALSE; + return TRUE; +} + +static BOOL test_validity_check(void) +{ + BOOL rc = FALSE; + rdpSettings* settings = freerdp_settings_new(0); + if (!settings) + goto fail; + + const rdpMonitor single_monitor_valid[] = { + { .x = 0, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor single_monitor_invalid_1[] = { + { .x = 0, + .y = 0, + .width = 192, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor single_monitor_invalid_2[] = { + { .x = 0, + .y = 0, + .width = 192, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor single_monitor_invalid_3[] = { + { .x = 0, + .y = 0, + .width = 192, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor single_monitor_invalid_4[] = { + { .x = 0, + .y = 0, + .width = 192, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor multi_monitor_valid[] = { + { .x = 0, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 1920, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 0, + .y = 1080, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = -1920, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 0, + .y = -1080, + .width = 1920, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 3840, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 5760, + .y = -1079, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 7680, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 7680, + .y = 1080, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 7680, + .y = -1080, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 7680, + .y = -2160, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 9599, + .y = -3240, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + }; + const rdpMonitor multi_monitor_invalid_1[] = { + { .x = 0, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 1920, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor multi_monitor_invalid_2[] = { + { .x = 1, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 1920, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor multi_monitor_invalid_3[] = { + { .x = 0, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 1921, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + const rdpMonitor multi_monitor_invalid_4[] = { + { .x = 0, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 1919, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + + const rdpMonitor multi_monitor_valid_2[] = { + { .x = 0, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 3840, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 1920, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + + const rdpMonitor multi_monitor_valid_3[] = { + { .x = 1920, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = TRUE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 3840, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } }, + { .x = 0, + .y = 0, + .width = 1920, + .height = 1080, + .is_primary = FALSE, + .orig_screen = 0, + .attributes = { .physicalWidth = 100, + .physicalHeight = 100, + .orientation = ORIENTATION_PREFERENCE_LANDSCAPE, + .desktopScaleFactor = 100, + .deviceScaleFactor = 100 } } + }; + + const struct validity_test_case tests[] = { + { TRUE, ARRAYSIZE(single_monitor_valid), single_monitor_valid }, + { FALSE, ARRAYSIZE(single_monitor_invalid_1), single_monitor_invalid_1 }, + { FALSE, ARRAYSIZE(single_monitor_invalid_2), single_monitor_invalid_2 }, + { FALSE, ARRAYSIZE(single_monitor_invalid_3), single_monitor_invalid_3 }, + { FALSE, ARRAYSIZE(single_monitor_invalid_4), single_monitor_invalid_4 }, + { TRUE, ARRAYSIZE(multi_monitor_valid), multi_monitor_valid }, + { TRUE, ARRAYSIZE(multi_monitor_invalid_1), multi_monitor_invalid_1 }, + { FALSE, ARRAYSIZE(multi_monitor_invalid_2), multi_monitor_invalid_2 }, + { FALSE, ARRAYSIZE(multi_monitor_invalid_3), multi_monitor_invalid_3 }, + { FALSE, ARRAYSIZE(multi_monitor_invalid_4), multi_monitor_invalid_4 }, + { TRUE, ARRAYSIZE(multi_monitor_valid_2), multi_monitor_valid_2 }, + { TRUE, ARRAYSIZE(multi_monitor_valid_3), multi_monitor_valid_3 } + }; + + rc = TRUE; + for (size_t x = 0; x < ARRAYSIZE(tests); x++) + { + const struct validity_test_case* cur = &tests[x]; + + if (!prepare_monitor_array(settings, cur)) + rc = log_result_case(FALSE, __func__, x); + else + { +#if defined(BUILD_TESTING_INTERNAL) + const BOOL res = freerdp_settings_check_client_after_preconnect(settings); +#else + const BOOL res = cur->expected; +#endif + + if ((res != cur->expected) || + !check_primary_offset(settings, cur->monitors, cur->count)) + { + rc = log_result_case(FALSE, __func__, x); + } + } + } + +fail: + freerdp_settings_free(settings); + return log_result(rc, __func__); +} + +static BOOL test_string_null(rdpSettings* settings, FreeRDP_Settings_Keys_String id) +{ + if (!freerdp_settings_set_string(settings, id, NULL)) + return FALSE; + + const char* chk = freerdp_settings_get_string(settings, id); + return (chk == NULL); +} + +static BOOL test_string_check(rdpSettings* settings, FreeRDP_Settings_Keys_String id, + const char* string, size_t len) +{ + const char* chk = freerdp_settings_get_string(settings, id); + if (!chk) + return FALSE; + + const size_t clen = strnlen(chk, len + 1); + + /* set strings must always be '\0' terminated */ + if (clen != len) + return FALSE; + + /* Strings must match comparison */ + if (strncmp(string, chk, clen) != 0) + return FALSE; + + return TRUE; +} + +static BOOL test_string_check_reset(rdpSettings* settings, FreeRDP_Settings_Keys_String id, + const char* string, size_t len) +{ + return test_string_check(settings, id, string, len) && test_string_null(settings, id); +} + +static BOOL test_string_set_readback(rdpSettings* settings, FreeRDP_Settings_Keys_String id, + const char* string, size_t len) +{ + WINPR_ASSERT(len > 3); + + BOOL rc = FALSE; + WCHAR* wstr = NULL; + + const size_t slen = strnlen(string, len); + if (!freerdp_settings_set_string_len(settings, id, string, slen - 1)) + goto fail; + + if (!test_string_check_reset(settings, id, string, slen - 1)) + goto fail; + + if (!freerdp_settings_set_string(settings, id, string)) + goto fail; + + size_t wlen = 0; + wstr = freerdp_settings_get_string_as_utf16(settings, id, &wlen); + if (!wstr || (wlen != slen)) + goto fail; + + if (!test_string_check_reset(settings, id, string, slen)) + goto fail; + + if (!freerdp_settings_set_string_from_utf16N(settings, id, wstr, slen - 1)) + goto fail; + + if (!test_string_check(settings, id, string, slen - 1)) + goto fail; + + if (!freerdp_settings_set_string_from_utf16(settings, id, wstr)) + goto fail; + + if (!test_string_check(settings, id, string, slen)) + goto fail; + + rc = TRUE; +fail: + free(wstr); + return rc; +} + +static BOOL test_string_len(rdpSettings* settings) +{ + BOOL rc = FALSE; + + const char user[] = "abcdefg"; + if (!test_string_set_readback(settings, FreeRDP_Username, user, sizeof(user))) + goto fail; + + const char pwd[] = "xyz"; + if (!test_string_set_readback(settings, FreeRDP_Password, pwd, sizeof(pwd))) + goto fail; + + const char domain[] = "foobar"; + if (!test_string_set_readback(settings, FreeRDP_Domain, domain, sizeof(domain))) + goto fail; + + rc = TRUE; +fail: + return rc; +} + +int TestSettings(int argc, char* argv[]) +{ + int rc = -1; + rdpSettings* settings = NULL; + rdpSettings* cloned = NULL; + rdpSettings* cloned2 = NULL; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!test_dyn_channels()) + goto fail; + if (!test_static_channels()) + goto fail; + if (!test_copy()) + goto fail; + if (!test_helpers()) + goto fail; + if (!check_device_type()) + goto fail; + if (!test_pointer_array()) + goto fail; + if (!test_validity_check()) + goto fail; + + settings = freerdp_settings_new(0); + + if (!settings) + { + printf("Couldn't create settings\n"); + return -1; + } + + if (!test_string_len(settings)) + goto fail; + + cloned = freerdp_settings_clone(settings); + + if (!cloned) + goto fail; + +#if defined(have_bool_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(bool_list_indices); x++) + { + const size_t key = bool_list_indices[x]; + const char* name = + freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + const BOOL val = freerdp_settings_get_bool(settings, key); + const BOOL cval = freerdp_settings_get_bool(cloned, key); + if (val != cval) + { + printf("mismatch for key %s: %u -> copy %u\n", name, val, cval); + goto fail; + } + if (!freerdp_settings_set_bool(settings, key, val)) + goto fail; + if (!check_key_helpers(key, "bool")) + goto fail; + } + +#endif +#if defined(have_int16_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(int16_list_indices); x++) + { + const size_t key = int16_list_indices[x]; + const char* name = freerdp_settings_get_name_for_key(key); + const INT16 val = freerdp_settings_get_int16(settings, key); + const INT16 cval = freerdp_settings_get_int16(cloned, key); + if (val != cval) + { + printf("mismatch for key %s: %" PRId16 " -> copy %" PRId16 "\n", name, val, cval); + goto fail; + } + if (!freerdp_settings_set_int16(settings, key, val)) + goto fail; + if (!check_key_helpers(key, "int16")) + goto fail; + } + +#endif +#if defined(have_uint16_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(uint16_list_indices); x++) + { + const size_t key = uint16_list_indices[x]; + const char* name = + freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + const UINT16 val = freerdp_settings_get_uint16(settings, key); + const UINT16 cval = freerdp_settings_get_uint16(cloned, key); + if (val != cval) + { + printf("mismatch for key %s: %" PRIu16 " -> copy %" PRIu16 "\n", name, val, cval); + goto fail; + } + if (!freerdp_settings_set_uint16(settings, key, val)) + goto fail; + if (!check_key_helpers(key, "uint16")) + goto fail; + } + +#endif +#if defined(have_uint32_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(uint32_list_indices); x++) + { + const size_t key = uint32_list_indices[x]; + const char* name = + freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + const UINT32 val = freerdp_settings_get_uint32(settings, key); + const UINT32 cval = freerdp_settings_get_uint32(cloned, key); + if (val != cval) + { + printf("mismatch for key %s: %" PRIu32 " -> copy %" PRIu32 "\n", name, val, cval); + goto fail; + } + if (!freerdp_settings_set_uint32(settings, key, val)) + goto fail; + if (!check_key_helpers(key, "uint32")) + goto fail; + } + +#endif +#if defined(have_int32_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(int32_list_indices); x++) + { + const size_t key = int32_list_indices[x]; + const char* name = + freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + const INT32 val = freerdp_settings_get_int32(settings, key); + const INT32 cval = freerdp_settings_get_int32(cloned, key); + if (val != cval) + { + printf("mismatch for key %s: %" PRId32 " -> copy %" PRId32 "\n", name, val, cval); + goto fail; + } + if (!freerdp_settings_set_int32(settings, key, val)) + goto fail; + if (!check_key_helpers(key, "int32")) + goto fail; + } + +#endif +#if defined(have_uint64_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(uint64_list_indices); x++) + { + const size_t key = uint64_list_indices[x]; + const char* name = + freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + const UINT64 val = freerdp_settings_get_uint64(settings, key); + const UINT64 cval = freerdp_settings_get_uint64(cloned, key); + if (val != cval) + { + printf("mismatch for key %s: %" PRIu64 " -> copy %" PRIu64 "\n", name, val, cval); + goto fail; + } + if (!freerdp_settings_set_uint64(settings, key, val)) + goto fail; + if (!check_key_helpers(key, "uint64")) + goto fail; + } + +#endif +#if defined(have_int64_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(int64_list_indices); x++) + { + const size_t key = int64_list_indices[x]; + const char* name = freerdp_settings_get_name_for_key(key); + const INT64 val = freerdp_settings_get_int64(settings, key); + const INT64 cval = freerdp_settings_get_int64(cloned, key); + if (val != cval) + { + printf("mismatch for key %s: %" PRId64 " -> copy %" PRId64 "\n", name, val, cval); + goto fail; + } + if (!freerdp_settings_set_int64(settings, key, val)) + goto fail; + if (!check_key_helpers(key, "int64")) + goto fail; + } + +#endif +#if defined(have_string_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(string_list_indices); x++) + { + const size_t key = string_list_indices[x]; + const char val[] = "test-string"; + const char* res = NULL; + const char* name = + freerdp_settings_get_name_for_key(WINPR_ASSERTING_INT_CAST(SSIZE_T, key)); + const char* oval = freerdp_settings_get_string(settings, key); + const char* cval = freerdp_settings_get_string(cloned, key); + if ((oval != cval) && (strcmp(oval, cval) != 0)) + { + printf("mismatch for key %s: %s -> copy %s\n", name, oval, cval); + goto fail; + } + if (!freerdp_settings_set_string(settings, key, val)) + goto fail; + + res = freerdp_settings_get_string(settings, key); + + if (strncmp(val, res, sizeof(val)) != 0) + goto fail; + } + +#endif +#if defined(have_pointer_list_indices) + + for (size_t x = 0; x < ARRAYSIZE(pointer_list_indices); x++) + { + const size_t key = pointer_list_indices[x]; + const void* val = freerdp_settings_get_pointer(settings, key); + WINPR_UNUSED(val); + } + +#endif + cloned2 = freerdp_settings_clone(settings); + if (!cloned2) + goto fail; + if (!freerdp_settings_copy(cloned2, cloned)) + goto fail; + + rc = 0; +fail: + freerdp_settings_free(cloned); + freerdp_settings_free(cloned2); + freerdp_settings_free(settings); + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestStreamDump.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestStreamDump.c new file mode 100644 index 0000000000000000000000000000000000000000..b54cae9e31883a34c11ac86d38223a4fa8da08b8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestStreamDump.c @@ -0,0 +1,104 @@ +#include + +#include +#include +#include + +#include +#include + +#include "../streamdump.h" + +static BOOL test_entry_read_write(void) +{ + BOOL rc = FALSE; + FILE* fp = NULL; + wStream* sw = NULL; + wStream* sr = NULL; + size_t offset = 0; + UINT64 ts = 0; + UINT32 flags = 0; + BYTE tmp[16] = { 0 }; + char tmp2[64] = { 0 }; + char* name = NULL; + size_t entrysize = sizeof(UINT64) /* timestamp */ + sizeof(BYTE) /* direction */ + + sizeof(UINT32) /* CRC */ + sizeof(UINT64) /* size */; + + winpr_RAND(tmp, sizeof(tmp)); + + for (size_t x = 0; x < sizeof(tmp); x++) + (void)_snprintf(&tmp2[x * 2], sizeof(tmp2) - 2 * x, "%02" PRIx8, tmp[x]); + name = GetKnownSubPath(KNOWN_PATH_TEMP, tmp2); + if (!name) + { + (void)fprintf(stderr, "[%s] Could not create temporary path\n", __func__); + goto fail; + } + + sw = Stream_New(NULL, 8123); + sr = Stream_New(NULL, 1024); + if (!sr || !sw) + { + (void)fprintf(stderr, "[%s] Could not create iostreams sw=%p, sr=%p\n", __func__, (void*)sw, + (void*)sr); + goto fail; + } + + winpr_RAND(Stream_Buffer(sw), Stream_Capacity(sw)); + entrysize += Stream_Capacity(sw); + Stream_SetLength(sw, Stream_Capacity(sw)); + + fp = fopen(name, "wb"); + if (!fp) + goto fail; + if (!stream_dump_write_line(fp, 0, sw)) + goto fail; + (void)fclose(fp); + + fp = fopen(name, "rb"); + if (!fp) + goto fail; + if (!stream_dump_read_line(fp, sr, &ts, &offset, &flags)) + goto fail; + + if (entrysize != offset) + { + (void)fprintf(stderr, "[%s] offset %" PRIuz " bytes, entrysize %" PRIuz " bytes\n", + __func__, offset, entrysize); + goto fail; + } + + if (Stream_Length(sr) != Stream_Capacity(sw)) + { + (void)fprintf(stderr, "[%s] Written %" PRIuz " bytes, read %" PRIuz " bytes\n", __func__, + Stream_Length(sr), Stream_Capacity(sw)); + goto fail; + } + + if (memcmp(Stream_Buffer(sw), Stream_Buffer(sr), Stream_Capacity(sw)) != 0) + { + (void)fprintf(stderr, "[%s] Written data does not match data read back\n", __func__); + goto fail; + } + rc = TRUE; +fail: + Stream_Free(sr, TRUE); + Stream_Free(sw, TRUE); + if (fp) + (void)fclose(fp); + if (name) + DeleteFileA(name); + free(name); + (void)fprintf(stderr, "xxxxxxxxxxxxx %d\n", rc); + return rc; +} + +int TestStreamDump(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!test_entry_read_write()) + return -1; + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestVersion.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestVersion.c new file mode 100644 index 0000000000000000000000000000000000000000..1853e782735467f5a1c4977011341fcb05f79646 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/TestVersion.c @@ -0,0 +1,44 @@ +#include +#include + +int TestVersion(int argc, char* argv[]) +{ + const char* version = NULL; + const char* git = NULL; + const char* build = NULL; + int major = 0; + int minor = 0; + int revision = 0; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + freerdp_get_version(&major, &minor, &revision); + + if (major != FREERDP_VERSION_MAJOR) + return -1; + + if (minor != FREERDP_VERSION_MINOR) + return -1; + + if (revision != FREERDP_VERSION_REVISION) + return -1; + + version = freerdp_get_version_string(); + + if (!version) + return -1; + + git = freerdp_get_build_revision(); + + if (!git) + return -1; + + if (strncmp(git, FREERDP_GIT_REVISION, sizeof(FREERDP_GIT_REVISION)) != 0) + return -1; + + build = freerdp_get_build_config(); + + if (!build) + return -1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/settings_property_lists.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/settings_property_lists.h new file mode 100644 index 0000000000000000000000000000000000000000..f9df959df6e4afd305cdc18920b49ee3914a771a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/core/test/settings_property_lists.h @@ -0,0 +1,501 @@ +#ifndef TEST_SETTINGS_PROPERTY_LISTS +#define TEST_SETTINGS_PROPERTY_LISTS + +#define have_bool_list_indices +static const size_t bool_list_indices[] = { + FreeRDP_AadSecurity, + FreeRDP_AllowCacheWaitingList, + FreeRDP_AllowDesktopComposition, + FreeRDP_AllowFontSmoothing, + FreeRDP_AllowUnanouncedOrdersFromServer, + FreeRDP_AltSecFrameMarkerSupport, + FreeRDP_AsyncChannels, + FreeRDP_AsyncUpdate, + FreeRDP_AudioCapture, + FreeRDP_AudioPlayback, + FreeRDP_Authentication, + FreeRDP_AuthenticationOnly, + FreeRDP_AutoAcceptCertificate, + FreeRDP_AutoDenyCertificate, + FreeRDP_AutoLogonEnabled, + FreeRDP_AutoReconnectionEnabled, + FreeRDP_AutoReconnectionPacketSupported, + FreeRDP_BitmapCacheEnabled, + FreeRDP_BitmapCachePersistEnabled, + FreeRDP_BitmapCacheV3Enabled, + FreeRDP_BitmapCompressionDisabled, + FreeRDP_CertificateCallbackPreferPEM, + FreeRDP_CompressionEnabled, + FreeRDP_ConnectChildSession, + FreeRDP_ConsoleSession, + FreeRDP_CredentialsFromStdin, + FreeRDP_DeactivateClientDecoding, + FreeRDP_Decorations, + FreeRDP_DesktopResize, + FreeRDP_DeviceRedirection, + FreeRDP_DisableCredentialsDelegation, + FreeRDP_DisableCtrlAltDel, + FreeRDP_DisableCursorBlinking, + FreeRDP_DisableCursorShadow, + FreeRDP_DisableFullWindowDrag, + FreeRDP_DisableMenuAnims, + FreeRDP_DisableRemoteAppCapsCheck, + FreeRDP_DisableThemes, + FreeRDP_DisableWallpaper, + FreeRDP_DrawAllowColorSubsampling, + FreeRDP_DrawAllowDynamicColorFidelity, + FreeRDP_DrawAllowSkipAlpha, + FreeRDP_DrawGdiPlusCacheEnabled, + FreeRDP_DrawGdiPlusEnabled, + FreeRDP_DrawNineGridEnabled, + FreeRDP_DumpRemoteFx, + FreeRDP_DynamicDaylightTimeDisabled, + FreeRDP_DynamicResolutionUpdate, + FreeRDP_EmbeddedWindow, + FreeRDP_EnableWindowsKey, + FreeRDP_EncomspVirtualChannel, + FreeRDP_ExtSecurity, + FreeRDP_ExternalCertificateManagement, + FreeRDP_FIPSMode, + FreeRDP_FastPathInput, + FreeRDP_FastPathOutput, + FreeRDP_ForceEncryptedCsPdu, + FreeRDP_ForceMultimon, + FreeRDP_FrameMarkerCommandEnabled, + FreeRDP_Fullscreen, + FreeRDP_GatewayArmTransport, + FreeRDP_GatewayAvdUseTenantid, + FreeRDP_GatewayBypassLocal, + FreeRDP_GatewayEnabled, + FreeRDP_GatewayHttpExtAuthSspiNtlm, + FreeRDP_GatewayHttpTransport, + FreeRDP_GatewayHttpUseWebsockets, + FreeRDP_GatewayIgnoreRedirectionPolicy, + FreeRDP_GatewayRpcTransport, + FreeRDP_GatewayUdpTransport, + FreeRDP_GatewayUseSameCredentials, + FreeRDP_GfxAVC444, + FreeRDP_GfxAVC444v2, + FreeRDP_GfxH264, + FreeRDP_GfxPlanar, + FreeRDP_GfxProgressive, + FreeRDP_GfxProgressiveV2, + FreeRDP_GfxSendQoeAck, + FreeRDP_GfxSmallCache, + FreeRDP_GfxSuspendFrameAck, + FreeRDP_GfxThinClient, + FreeRDP_GrabKeyboard, + FreeRDP_GrabMouse, + FreeRDP_HasExtendedMouseEvent, + FreeRDP_HasHorizontalWheel, + FreeRDP_HasMonitorAttributes, + FreeRDP_HasQoeEvent, + FreeRDP_HasRelativeMouseEvent, + FreeRDP_HiDefRemoteApp, + FreeRDP_IPv6Enabled, + FreeRDP_IgnoreCertificate, + FreeRDP_IgnoreInvalidDevices, + FreeRDP_JpegCodec, + FreeRDP_KerberosRdgIsProxy, + FreeRDP_ListMonitors, + FreeRDP_LocalConnection, + FreeRDP_LogonErrors, + FreeRDP_LogonNotify, + FreeRDP_LongCredentialsSupported, + FreeRDP_LyncRdpMode, + FreeRDP_MaximizeShell, + FreeRDP_MouseAttached, + FreeRDP_MouseHasWheel, + FreeRDP_MouseMotion, + FreeRDP_MouseUseRelativeMove, + FreeRDP_MstscCookieMode, + FreeRDP_MultiTouchGestures, + FreeRDP_MultiTouchInput, + FreeRDP_NSCodec, + FreeRDP_NSCodecAllowDynamicColorFidelity, + FreeRDP_NSCodecAllowSubsampling, + FreeRDP_NegotiateSecurityLayer, + FreeRDP_NetworkAutoDetect, + FreeRDP_NlaSecurity, + FreeRDP_NoBitmapCompressionHeader, + FreeRDP_OldLicenseBehaviour, + FreeRDP_PasswordIsSmartcardPin, + FreeRDP_PercentScreenUseHeight, + FreeRDP_PercentScreenUseWidth, + FreeRDP_PlayRemoteFx, + FreeRDP_PreferIPv6OverIPv4, + FreeRDP_PrintReconnectCookie, + FreeRDP_PromptForCredentials, + FreeRDP_RdpSecurity, + FreeRDP_RdstlsSecurity, + FreeRDP_RedirectClipboard, + FreeRDP_RedirectDrives, + FreeRDP_RedirectHomeDrive, + FreeRDP_RedirectParallelPorts, + FreeRDP_RedirectPrinters, + FreeRDP_RedirectSerialPorts, + FreeRDP_RedirectSmartCards, + FreeRDP_RedirectWebAuthN, + FreeRDP_RefreshRect, + FreeRDP_RemdeskVirtualChannel, + FreeRDP_RemoteAppLanguageBarSupported, + FreeRDP_RemoteApplicationMode, + FreeRDP_RemoteAssistanceMode, + FreeRDP_RemoteAssistanceRequestControl, + FreeRDP_RemoteConsoleAudio, + FreeRDP_RemoteCredentialGuard, + FreeRDP_RemoteFxCodec, + FreeRDP_RemoteFxImageCodec, + FreeRDP_RemoteFxOnly, + FreeRDP_RestrictedAdminModeRequired, + FreeRDP_SaltedChecksum, + FreeRDP_SendPreconnectionPdu, + FreeRDP_ServerLicenseRequired, + FreeRDP_ServerMode, + FreeRDP_SmartSizing, + FreeRDP_SmartcardEmulation, + FreeRDP_SmartcardLogon, + FreeRDP_SoftwareGdi, + FreeRDP_SoundBeepsEnabled, + FreeRDP_SpanMonitors, + FreeRDP_SupportAsymetricKeys, + FreeRDP_SupportDisplayControl, + FreeRDP_SupportDynamicChannels, + FreeRDP_SupportDynamicTimeZone, + FreeRDP_SupportEchoChannel, + FreeRDP_SupportEdgeActionV1, + FreeRDP_SupportEdgeActionV2, + FreeRDP_SupportErrorInfoPdu, + FreeRDP_SupportGeometryTracking, + FreeRDP_SupportGraphicsPipeline, + FreeRDP_SupportHeartbeatPdu, + FreeRDP_SupportMonitorLayoutPdu, + FreeRDP_SupportMultitransport, + FreeRDP_SupportSSHAgentChannel, + FreeRDP_SupportSkipChannelJoin, + FreeRDP_SupportStatusInfoPdu, + FreeRDP_SupportVideoOptimized, + FreeRDP_SuppressOutput, + FreeRDP_SurfaceCommandsEnabled, + FreeRDP_SurfaceFrameMarkerEnabled, + FreeRDP_SuspendInput, + FreeRDP_SynchronousDynamicChannels, + FreeRDP_SynchronousStaticChannels, + FreeRDP_TcpKeepAlive, + FreeRDP_TlsSecurity, + FreeRDP_ToggleFullscreen, + FreeRDP_TransportDump, + FreeRDP_TransportDumpReplay, + FreeRDP_TransportDumpReplayNodelay, + FreeRDP_UnicodeInput, + FreeRDP_UnmapButtons, + FreeRDP_UseCommonStdioCallbacks, + FreeRDP_UseMultimon, + FreeRDP_UseRdpSecurityLayer, + FreeRDP_UsingSavedCredentials, + FreeRDP_VideoDisable, + FreeRDP_VmConnectMode, + FreeRDP_WaitForOutputBufferFlush, + FreeRDP_Workarea, +}; + +#define have_uint16_list_indices +static const size_t uint16_list_indices[] = { + FreeRDP_CapsGeneralCompressionLevel, + FreeRDP_CapsGeneralCompressionTypes, + FreeRDP_CapsProtocolVersion, + FreeRDP_CapsRemoteUnshareFlag, + FreeRDP_CapsUpdateCapabilityFlag, + FreeRDP_DesktopOrientation, + FreeRDP_OrderSupportFlags, + FreeRDP_OrderSupportFlagsEx, + FreeRDP_ProxyPort, + FreeRDP_SupportedColorDepths, + FreeRDP_TLSMaxVersion, + FreeRDP_TLSMinVersion, + FreeRDP_TextANSICodePage, +}; + +#define have_uint32_list_indices +static const size_t uint32_list_indices[] = { + FreeRDP_AcceptedCertLength, + FreeRDP_AuthenticationLevel, + FreeRDP_AutoReconnectMaxRetries, + FreeRDP_BitmapCacheV2NumCells, + FreeRDP_BitmapCacheV3CodecId, + FreeRDP_BitmapCacheVersion, + FreeRDP_BrushSupportLevel, + FreeRDP_ChannelCount, + FreeRDP_ChannelDefArraySize, + FreeRDP_ClientBuild, + FreeRDP_ClientRandomLength, + FreeRDP_ClientSessionId, + FreeRDP_ClipboardFeatureMask, + FreeRDP_ClusterInfoFlags, + FreeRDP_ColorDepth, + FreeRDP_ColorPointerCacheSize, + FreeRDP_CompDeskSupportLevel, + FreeRDP_CompressionLevel, + FreeRDP_ConnectionType, + FreeRDP_CookieMaxLength, + FreeRDP_DesktopHeight, + FreeRDP_DesktopPhysicalHeight, + FreeRDP_DesktopPhysicalWidth, + FreeRDP_DesktopPosX, + FreeRDP_DesktopPosY, + FreeRDP_DesktopScaleFactor, + FreeRDP_DesktopWidth, + FreeRDP_DeviceArraySize, + FreeRDP_DeviceCount, + FreeRDP_DeviceScaleFactor, + FreeRDP_DrawNineGridCacheEntries, + FreeRDP_DrawNineGridCacheSize, + FreeRDP_DynamicChannelArraySize, + FreeRDP_DynamicChannelCount, + FreeRDP_EarlyCapabilityFlags, + FreeRDP_EncryptionLevel, + FreeRDP_EncryptionMethods, + FreeRDP_ExtEncryptionMethods, + FreeRDP_FakeMouseMotionInterval, + FreeRDP_Floatbar, + FreeRDP_ForceIPvX, + FreeRDP_FrameAcknowledge, + FreeRDP_GatewayAcceptedCertLength, + FreeRDP_GatewayCredentialsSource, + FreeRDP_GatewayPort, + FreeRDP_GatewayUsageMethod, + FreeRDP_GfxCapsFilter, + FreeRDP_GlyphSupportLevel, + FreeRDP_JpegCodecId, + FreeRDP_JpegQuality, + FreeRDP_KeySpec, + FreeRDP_KeyboardCodePage, + FreeRDP_KeyboardFunctionKey, + FreeRDP_KeyboardHook, + FreeRDP_KeyboardLayout, + FreeRDP_KeyboardSubType, + FreeRDP_KeyboardType, + FreeRDP_LargePointerFlag, + FreeRDP_LoadBalanceInfoLength, + FreeRDP_MonitorAttributeFlags, + FreeRDP_MonitorCount, + FreeRDP_MonitorDefArraySize, + FreeRDP_MonitorFlags, + FreeRDP_MonitorLocalShiftX, + FreeRDP_MonitorLocalShiftY, + FreeRDP_MultifragMaxRequestSize, + FreeRDP_MultitransportFlags, + FreeRDP_NSCodecColorLossLevel, + FreeRDP_NSCodecId, + FreeRDP_NegotiationFlags, + FreeRDP_NumMonitorIds, + FreeRDP_OffscreenCacheEntries, + FreeRDP_OffscreenCacheSize, + FreeRDP_OffscreenSupportLevel, + FreeRDP_OsMajorType, + FreeRDP_OsMinorType, + FreeRDP_Password51Length, + FreeRDP_PduSource, + FreeRDP_PercentScreen, + FreeRDP_PerformanceFlags, + FreeRDP_PointerCacheSize, + FreeRDP_PreconnectionId, + FreeRDP_ProxyType, + FreeRDP_RdpVersion, + FreeRDP_ReceivedCapabilitiesSize, + FreeRDP_RedirectedSessionId, + FreeRDP_RedirectionAcceptedCertLength, + FreeRDP_RedirectionFlags, + FreeRDP_RedirectionGuidLength, + FreeRDP_RedirectionPasswordLength, + FreeRDP_RedirectionPreferType, + FreeRDP_RedirectionTsvUrlLength, + FreeRDP_RemoteAppNumIconCacheEntries, + FreeRDP_RemoteAppNumIconCaches, + FreeRDP_RemoteApplicationExpandCmdLine, + FreeRDP_RemoteApplicationExpandWorkingDir, + FreeRDP_RemoteApplicationSupportLevel, + FreeRDP_RemoteApplicationSupportMask, + FreeRDP_RemoteFxCaptureFlags, + FreeRDP_RemoteFxCodecId, + FreeRDP_RemoteFxCodecMode, + FreeRDP_RemoteFxRlgrMode, + FreeRDP_RemoteWndSupportLevel, + FreeRDP_RequestedProtocols, + FreeRDP_SelectedProtocol, + FreeRDP_ServerCertificateLength, + FreeRDP_ServerLicenseProductIssuersCount, + FreeRDP_ServerLicenseProductVersion, + FreeRDP_ServerPort, + FreeRDP_ServerRandomLength, + FreeRDP_ShareId, + FreeRDP_SmartSizingHeight, + FreeRDP_SmartSizingWidth, + FreeRDP_StaticChannelArraySize, + FreeRDP_StaticChannelCount, + FreeRDP_SurfaceCommandsSupported, + FreeRDP_TargetNetAddressCount, + FreeRDP_TcpAckTimeout, + FreeRDP_TcpConnectTimeout, + FreeRDP_TcpKeepAliveDelay, + FreeRDP_TcpKeepAliveInterval, + FreeRDP_TcpKeepAliveRetries, + FreeRDP_ThreadingFlags, + FreeRDP_TlsSecLevel, + FreeRDP_VCChunkSize, + FreeRDP_VCFlags, +}; + +#define have_int32_list_indices +static const size_t int32_list_indices[] = { + FreeRDP_MonitorLocalShiftX, + FreeRDP_MonitorLocalShiftY, + FreeRDP_XPan, + FreeRDP_YPan, +}; + +#define have_uint64_list_indices +static const size_t uint64_list_indices[] = { + FreeRDP_ParentWindowId, +}; + +#define have_string_list_indices +static const size_t string_list_indices[] = { + FreeRDP_AadServerHostname, + FreeRDP_AcceptedCert, + FreeRDP_ActionScript, + FreeRDP_AllowedTlsCiphers, + FreeRDP_AlternateShell, + FreeRDP_AssistanceFile, + FreeRDP_AuthenticationPackageList, + FreeRDP_AuthenticationServiceClass, + FreeRDP_BitmapCachePersistFile, + FreeRDP_CardName, + FreeRDP_CertificateAcceptedFingerprints, + FreeRDP_CertificateName, + FreeRDP_ClientAddress, + FreeRDP_ClientDir, + FreeRDP_ClientHostname, + FreeRDP_ClientProductId, + FreeRDP_ClipboardUseSelection, + FreeRDP_ComputerName, + FreeRDP_ConfigPath, + FreeRDP_ConnectionFile, + FreeRDP_ContainerName, + FreeRDP_CspName, + FreeRDP_CurrentPath, + FreeRDP_Domain, + FreeRDP_DrivesToRedirect, + FreeRDP_DumpRemoteFxFile, + FreeRDP_DynamicDSTTimeZoneKeyName, + FreeRDP_GatewayAcceptedCert, + FreeRDP_GatewayAccessToken, + FreeRDP_GatewayAvdAadtenantid, + FreeRDP_GatewayAvdActivityhint, + FreeRDP_GatewayAvdArmpath, + FreeRDP_GatewayAvdClientID, + FreeRDP_GatewayAvdDiagnosticserviceurl, + FreeRDP_GatewayAvdGeo, + FreeRDP_GatewayAvdHubdiscoverygeourl, + FreeRDP_GatewayAvdWvdEndpointPool, + FreeRDP_GatewayAzureActiveDirectory, + FreeRDP_GatewayDomain, + FreeRDP_GatewayHostname, + FreeRDP_GatewayHttpExtAuthBearer, + FreeRDP_GatewayPassword, + FreeRDP_GatewayUrl, + FreeRDP_GatewayUsername, + FreeRDP_HomePath, + FreeRDP_ImeFileName, + FreeRDP_KerberosArmor, + FreeRDP_KerberosCache, + FreeRDP_KerberosKdcUrl, + FreeRDP_KerberosKeytab, + FreeRDP_KerberosLifeTime, + FreeRDP_KerberosRealm, + FreeRDP_KerberosRenewableLifeTime, + FreeRDP_KerberosStartTime, + FreeRDP_KeyboardPipeName, + FreeRDP_KeyboardRemappingList, + FreeRDP_NtlmSamFile, + FreeRDP_Password, + FreeRDP_PasswordHash, + FreeRDP_Pkcs11Module, + FreeRDP_PkinitAnchors, + FreeRDP_PlayRemoteFxFile, + FreeRDP_PreconnectionBlob, + FreeRDP_ProxyHostname, + FreeRDP_ProxyPassword, + FreeRDP_ProxyUsername, + FreeRDP_RDP2TCPArgs, + FreeRDP_ReaderName, + FreeRDP_RedirectionAcceptedCert, + FreeRDP_RedirectionDomain, + FreeRDP_RedirectionTargetFQDN, + FreeRDP_RedirectionTargetNetBiosName, + FreeRDP_RedirectionUsername, + FreeRDP_RemoteApplicationCmdLine, + FreeRDP_RemoteApplicationFile, + FreeRDP_RemoteApplicationGuid, + FreeRDP_RemoteApplicationIcon, + FreeRDP_RemoteApplicationName, + FreeRDP_RemoteApplicationProgram, + FreeRDP_RemoteApplicationWorkingDir, + FreeRDP_RemoteAssistancePassStub, + FreeRDP_RemoteAssistancePassword, + FreeRDP_RemoteAssistanceRCTicket, + FreeRDP_RemoteAssistanceSessionId, + FreeRDP_ServerHostname, + FreeRDP_ServerLicenseCompanyName, + FreeRDP_ServerLicenseProductName, + FreeRDP_ShellWorkingDirectory, + FreeRDP_SmartcardCertificate, + FreeRDP_SmartcardPrivateKey, + FreeRDP_SspiModule, + FreeRDP_TargetNetAddress, + FreeRDP_TerminalDescriptor, + FreeRDP_TlsSecretsFile, + FreeRDP_TransportDumpFile, + FreeRDP_UserSpecifiedServerName, + FreeRDP_Username, + FreeRDP_WinSCardModule, + FreeRDP_WindowTitle, + FreeRDP_WmClass, +}; + +#define have_pointer_list_indices +static const size_t pointer_list_indices[] = { + FreeRDP_BitmapCacheV2CellInfo, + FreeRDP_ChannelDefArray, + FreeRDP_ClientAutoReconnectCookie, + FreeRDP_ClientRandom, + FreeRDP_ClientTimeZone, + FreeRDP_DeviceArray, + FreeRDP_DynamicChannelArray, + FreeRDP_FragCache, + FreeRDP_GlyphCache, + FreeRDP_LoadBalanceInfo, + FreeRDP_MonitorDefArray, + FreeRDP_MonitorIds, + FreeRDP_OrderSupport, + FreeRDP_Password51, + FreeRDP_RdpServerCertificate, + FreeRDP_RdpServerRsaKey, + FreeRDP_ReceivedCapabilities, + FreeRDP_ReceivedCapabilityData, + FreeRDP_ReceivedCapabilityDataSizes, + FreeRDP_RedirectionGuid, + FreeRDP_RedirectionPassword, + FreeRDP_RedirectionTargetCertificate, + FreeRDP_RedirectionTsvUrl, + FreeRDP_ServerAutoReconnectCookie, + FreeRDP_ServerCertificate, + FreeRDP_ServerLicenseProductIssuers, + FreeRDP_ServerRandom, + FreeRDP_StaticChannelArray, + FreeRDP_TargetNetAddresses, + FreeRDP_TargetNetPorts, + FreeRDP_instance, +}; + +#endif /* TEST_SETTINGS_PROPERTY_LISTS */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/certificate.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/certificate.h new file mode 100644 index 0000000000000000000000000000000000000000..57c0dcb85bd7e35bc51b027db213f629a23a8ff3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/certificate.h @@ -0,0 +1,66 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Certificate Handling + * + * Copyright 2011 Marc-Andre Moreau + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_CERTIFICATE_H +#define FREERDP_LIB_CORE_CERTIFICATE_H + +#include +#include + +#include + +/* Certificate Version */ +#define CERT_CHAIN_VERSION_1 0x00000001 +#define CERT_CHAIN_VERSION_2 0x00000002 +#define CERT_CHAIN_VERSION_MASK 0x7FFFFFFF +#define CERT_PERMANENTLY_ISSUED 0x00000000 +#define CERT_TEMPORARILY_ISSUED 0x80000000 + +#define SIGNATURE_ALG_RSA 0x00000001 +#define KEY_EXCHANGE_ALG_RSA 0x00000001 + +#define BB_RSA_KEY_BLOB 6 +#define BB_RSA_SIGNATURE_BLOB 8 + +WINPR_ATTR_MALLOC(freerdp_certificate_free, 1) +FREERDP_LOCAL rdpCertificate* freerdp_certificate_new_from_x509(const X509* xcert, + const STACK_OF(X509) * chain); + +FREERDP_LOCAL BOOL freerdp_certificate_read_server_cert(rdpCertificate* certificate, + const BYTE* server_cert, size_t length); +FREERDP_LOCAL SSIZE_T freerdp_certificate_write_server_cert(const rdpCertificate* certificate, + UINT32 dwVersion, wStream* s); + +WINPR_ATTR_MALLOC(freerdp_certificate_free, 1) +FREERDP_LOCAL rdpCertificate* freerdp_certificate_clone(const rdpCertificate* certificate); + +FREERDP_LOCAL const rdpCertInfo* freerdp_certificate_get_info(const rdpCertificate* certificate); + +/** \brief returns a pointer to a X509 structure. + * Call X509_free when done. + */ +FREERDP_LOCAL X509* freerdp_certificate_get_x509(rdpCertificate* certificate); + +FREERDP_LOCAL BOOL freerdp_certificate_publickey_encrypt(const rdpCertificate* cert, + const BYTE* input, size_t cbInput, + BYTE** poutput, size_t* pcbOutput); + +#endif /* FREERDP_LIB_CORE_CERTIFICATE_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/certificate_store.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/certificate_store.c new file mode 100644 index 0000000000000000000000000000000000000000..bace3af97d260ed10d79b697323531cd91a5c5c3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/certificate_store.c @@ -0,0 +1,206 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Certificate Handling + * + * Copyright 2011 Jiten Pathy + * Copyright 2011-2012 Marc-Andre Moreau + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +struct rdp_certificate_store +{ + char* certs_path; + char* server_path; +}; + +static const char certificate_store_dir[] = "certs"; +static const char certificate_server_dir[] = "server"; + +static char* freerdp_certificate_store_file_path(const rdpCertificateStore* store, const char* hash) +{ + const char* hosts = freerdp_certificate_store_get_hosts_path(store); + + if (!hosts || !hash) + return NULL; + + return GetCombinedPath(hosts, hash); +} + +freerdp_certificate_store_result +freerdp_certificate_store_contains_data(rdpCertificateStore* store, const rdpCertificateData* data) +{ + freerdp_certificate_store_result rc = CERT_STORE_NOT_FOUND; + const char* host = freerdp_certificate_data_get_host(data); + const UINT16 port = freerdp_certificate_data_get_port(data); + + rdpCertificateData* loaded = freerdp_certificate_store_load_data(store, host, port); + if (!loaded) + goto fail; + + rc = freerdp_certificate_data_equal(data, loaded) ? CERT_STORE_MATCH : CERT_STORE_MISMATCH; + +fail: + freerdp_certificate_data_free(loaded); + return rc; +} + +BOOL freerdp_certificate_store_remove_data(rdpCertificateStore* store, + const rdpCertificateData* data) +{ + BOOL rc = TRUE; + + WINPR_ASSERT(store); + + const char* hash = freerdp_certificate_data_get_hash(data); + if (!hash) + return FALSE; + char* path = freerdp_certificate_store_file_path(store, hash); + + if (!path) + return FALSE; + + if (winpr_PathFileExists(path)) + rc = winpr_DeleteFile(path); + free(path); + return rc; +} + +BOOL freerdp_certificate_store_save_data(rdpCertificateStore* store, const rdpCertificateData* data) +{ + BOOL rc = FALSE; + const char* base = freerdp_certificate_store_get_hosts_path(store); + const char* hash = freerdp_certificate_data_get_hash(data); + char* path = freerdp_certificate_store_file_path(store, hash); + FILE* fp = NULL; + + if (!winpr_PathFileExists(base)) + { + if (!winpr_PathMakePath(base, NULL)) + goto fail; + } + + fp = winpr_fopen(path, "w"); + if (!fp) + goto fail; + + (void)fprintf(fp, "%s", freerdp_certificate_data_get_pem_ex(data, FALSE)); + + rc = TRUE; +fail: + if (fp) + (void)fclose(fp); + free(path); + return rc; +} + +rdpCertificateData* freerdp_certificate_store_load_data(rdpCertificateStore* store, + const char* host, UINT16 port) +{ + char* path = NULL; + rdpCertificateData* data = NULL; + + WINPR_ASSERT(store); + + path = freerdp_certificate_store_get_cert_path(store, host, port); + if (!path) + goto fail; + + data = freerdp_certificate_data_new_from_file(host, port, path); + +fail: + free(path); + return data; +} + +rdpCertificateStore* freerdp_certificate_store_new(const rdpSettings* settings) +{ + rdpCertificateStore* store = (rdpCertificateStore*)calloc(1, sizeof(rdpCertificateStore)); + + if (!store) + return NULL; + + const char* base = freerdp_settings_get_string(settings, FreeRDP_ConfigPath); + if (!base) + goto fail; + + store->certs_path = GetCombinedPath(base, certificate_store_dir); + store->server_path = GetCombinedPath(base, certificate_server_dir); + if (!store->certs_path || !store->server_path) + goto fail; + + return store; + +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + freerdp_certificate_store_free(store); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void freerdp_certificate_store_free(rdpCertificateStore* store) +{ + if (!store) + return; + + free(store->certs_path); + free(store->server_path); + free(store); +} + +const char* freerdp_certificate_store_get_certs_path(const rdpCertificateStore* store) +{ + WINPR_ASSERT(store); + return store->certs_path; +} + +const char* freerdp_certificate_store_get_hosts_path(const rdpCertificateStore* store) +{ + WINPR_ASSERT(store); + return store->server_path; +} + +char* freerdp_certificate_store_get_cert_path(const rdpCertificateStore* store, const char* host, + UINT16 port) +{ + WINPR_ASSERT(store); + + char* hash = freerdp_certificate_data_hash(host, port); + if (!hash) + return NULL; + char* path = freerdp_certificate_store_file_path(store, hash); + free(hash); + return path; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/per.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/per.c new file mode 100644 index 0000000000000000000000000000000000000000..924742334d2b0c8867da4aee74bc20493a4ff634 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/per.c @@ -0,0 +1,605 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * ASN.1 Packed Encoding Rules (BER) + * + * Copyright 2011-2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include +#include + +#include +#define TAG FREERDP_TAG("crypto.per") + +/** + * Read PER length. + * + * @param s stream to read from + * @param length A pointer to return the length read, must not be NULL + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_length(wStream* s, UINT16* length) +{ + BYTE byte = 0; + + WINPR_ASSERT(length); + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, byte); + + if (byte & 0x80) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + byte &= ~(0x80); + *length = WINPR_ASSERTING_INT_CAST(UINT16, byte << 8); + Stream_Read_UINT8(s, byte); + *length += byte; + } + else + { + *length = byte; + } + + return TRUE; +} + +/** + * Write PER length. + * @param s stream + * @param length length + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_length(wStream* s, UINT16 length) +{ + if (length > 0x7F) + { + if (!Stream_EnsureRemainingCapacity(s, 2)) + return FALSE; + Stream_Write_UINT16_BE(s, (length | 0x8000)); + } + else + { + if (!Stream_EnsureRemainingCapacity(s, 1)) + return FALSE; + Stream_Write_UINT8(s, (UINT8)length); + } + return TRUE; +} + +/** + * Read PER choice. + * @param s stream + * @param choice choice + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_choice(wStream* s, BYTE* choice) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, *choice); + return TRUE; +} + +/** + * Write PER CHOICE. + * @param s stream + * @param choice index of chosen field + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_choice(wStream* s, BYTE choice) +{ + if (!Stream_EnsureRemainingCapacity(s, 1)) + return FALSE; + Stream_Write_UINT8(s, choice); + return TRUE; +} + +/** + * Read PER selection. + * @param s stream + * @param selection selection + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_selection(wStream* s, BYTE* selection) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + WINPR_ASSERT(selection); + Stream_Read_UINT8(s, *selection); + return TRUE; +} + +/** + * Write PER selection for OPTIONAL fields. + * @param s stream + * @param selection bit map of selected fields + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_selection(wStream* s, BYTE selection) +{ + if (!Stream_EnsureRemainingCapacity(s, 1)) + return FALSE; + Stream_Write_UINT8(s, selection); + return TRUE; +} + +/** + * Read PER number of sets. + * @param s stream + * @param number number of sets + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_number_of_sets(wStream* s, BYTE* number) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + WINPR_ASSERT(number); + Stream_Read_UINT8(s, *number); + return TRUE; +} + +/** + * Write PER number of sets for SET OF. + * + * @param s stream + * @param number number of sets + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_number_of_sets(wStream* s, BYTE number) +{ + if (!Stream_EnsureRemainingCapacity(s, 1)) + return FALSE; + Stream_Write_UINT8(s, number); + return TRUE; +} + +/** + * Read PER padding with zeros. + * + * @param s A stream to read from + * @param length the data to write + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_padding(wStream* s, UINT16 length) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, length)) + return FALSE; + + Stream_Seek(s, length); + return TRUE; +} + +/** + * Write PER padding with zeros. + * @param s A stream to write to + * @param length the data to write + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_padding(wStream* s, UINT16 length) +{ + if (!Stream_EnsureRemainingCapacity(s, length)) + return FALSE; + Stream_Zero(s, length); + return TRUE; +} + +/** + * Read PER INTEGER. + * @param s stream + * @param integer integer + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_integer(wStream* s, UINT32* integer) +{ + UINT16 length = 0; + + WINPR_ASSERT(integer); + + if (!per_read_length(s, &length)) + return FALSE; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, length)) + return FALSE; + + if (length == 0) + *integer = 0; + else if (length == 1) + Stream_Read_UINT8(s, *integer); + else if (length == 2) + Stream_Read_UINT16_BE(s, *integer); + else + return FALSE; + + return TRUE; +} + +/** + * Write PER INTEGER. + * @param s stream + * @param integer integer + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_integer(wStream* s, UINT32 integer) +{ + if (integer <= UINT8_MAX) + { + if (!per_write_length(s, 1)) + return FALSE; + if (!Stream_EnsureRemainingCapacity(s, 1)) + return FALSE; + Stream_Write_UINT8(s, WINPR_ASSERTING_INT_CAST(UINT8, integer)); + } + else if (integer <= UINT16_MAX) + { + if (!per_write_length(s, 2)) + return FALSE; + if (!Stream_EnsureRemainingCapacity(s, 2)) + return FALSE; + Stream_Write_UINT16_BE(s, WINPR_ASSERTING_INT_CAST(UINT16, integer)); + } + else if (integer <= UINT32_MAX) + { + if (!per_write_length(s, 4)) + return FALSE; + if (!Stream_EnsureRemainingCapacity(s, 4)) + return FALSE; + Stream_Write_UINT32_BE(s, integer); + } + return TRUE; +} + +/** + * Read PER INTEGER (UINT16). + * + * @param s The stream to read from + * @param integer The integer result variable pointer, must not be NULL + * @param min minimum value + * + * @return \b TRUE for success, \b FALSE otherwise + */ + +BOOL per_read_integer16(wStream* s, UINT16* integer, UINT16 min) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 2)) + return FALSE; + + Stream_Read_UINT16_BE(s, *integer); + + if (*integer > UINT16_MAX - min) + { + WLog_WARN(TAG, "PER uint16 invalid value %" PRIu16 " > %" PRIu16, *integer, + UINT16_MAX - min); + return FALSE; + } + + *integer += min; + + return TRUE; +} + +/** + * Write PER INTEGER (UINT16). + * @param s stream + * @param integer integer + * @param min minimum value + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_integer16(wStream* s, UINT16 integer, UINT16 min) +{ + if (min > integer) + return FALSE; + if (!Stream_EnsureRemainingCapacity(s, 2)) + return FALSE; + Stream_Write_UINT16_BE(s, integer - min); + return TRUE; +} + +/** + * Read PER ENUMERATED. + * + * @param s The stream to read from + * @param enumerated enumerated result variable, must not be NULL + * @param count enumeration count + * + * @return \b TRUE for success, \b FALSE otherwise + */ + +BOOL per_read_enumerated(wStream* s, BYTE* enumerated, BYTE count) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + WINPR_ASSERT(enumerated); + Stream_Read_UINT8(s, *enumerated); + + /* check that enumerated value falls within expected range */ + if (*enumerated + 1 > count) + { + WLog_WARN(TAG, "PER invalid data, expected %" PRIu8 " < %" PRIu8, *enumerated, count); + return FALSE; + } + + return TRUE; +} + +/** + * Write PER ENUMERATED. + * + * @param s The stream to write to + * @param enumerated enumerated + * @param count enumeration count + * + * @return \b TRUE for success, \b FALSE otherwise + */ + +BOOL per_write_enumerated(wStream* s, BYTE enumerated, BYTE count) +{ + if (!Stream_EnsureRemainingCapacity(s, 1)) + return FALSE; + Stream_Write_UINT8(s, enumerated); + return TRUE; +} + +static BOOL per_check_oid_and_log_mismatch(const BYTE* got, const BYTE* expect, size_t length) +{ + if (memcmp(got, expect, length) == 0) + { + return TRUE; + } + else + { + char* got_str = winpr_BinToHexString(got, length, TRUE); + char* expect_str = winpr_BinToHexString(expect, length, TRUE); + + WLog_WARN(TAG, "PER OID mismatch, got %s, expected %s", got_str, expect_str); + free(got_str); + free(expect_str); + return FALSE; + } +} + +/** + * Read PER OBJECT_IDENTIFIER (OID). + * + * @param s The stream to read from + * @param oid object identifier (OID) + * @warning It works correctly only for limited set of OIDs. + * + * @return \b TRUE for success, \b FALSE otherwise + */ + +BOOL per_read_object_identifier(wStream* s, const BYTE oid[6]) +{ + BYTE t12 = 0; + UINT16 length = 0; + BYTE a_oid[6] = { 0 }; + + if (!per_read_length(s, &length)) + return FALSE; + + if (length != 5) + { + WLog_WARN(TAG, "PER length, got %" PRIu16 ", expected 5", length); + return FALSE; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, length)) + return FALSE; + + Stream_Read_UINT8(s, t12); /* first two tuples */ + a_oid[0] = t12 / 40; + a_oid[1] = t12 % 40; + + Stream_Read_UINT8(s, a_oid[2]); /* tuple 3 */ + Stream_Read_UINT8(s, a_oid[3]); /* tuple 4 */ + Stream_Read_UINT8(s, a_oid[4]); /* tuple 5 */ + Stream_Read_UINT8(s, a_oid[5]); /* tuple 6 */ + + return per_check_oid_and_log_mismatch(a_oid, oid, sizeof(a_oid)); +} + +/** + * Write PER OBJECT_IDENTIFIER (OID) + * @param s stream + * @param oid object identifier (oid) + * @warning It works correctly only for limited set of OIDs. + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_object_identifier(wStream* s, const BYTE oid[6]) +{ + BYTE t12 = oid[0] * 40 + oid[1]; + if (!Stream_EnsureRemainingCapacity(s, 6)) + return FALSE; + Stream_Write_UINT8(s, 5); /* length */ + Stream_Write_UINT8(s, t12); /* first two tuples */ + Stream_Write_UINT8(s, oid[2]); /* tuple 3 */ + Stream_Write_UINT8(s, oid[3]); /* tuple 4 */ + Stream_Write_UINT8(s, oid[4]); /* tuple 5 */ + Stream_Write_UINT8(s, oid[5]); /* tuple 6 */ + return TRUE; +} + +/** + * Write PER string. + * @param s stream + * @param str string + * @param length string length + */ + +static void per_write_string(wStream* s, BYTE* str, int length) +{ + for (int i = 0; i < length; i++) + Stream_Write_UINT8(s, str[i]); +} + +/** + * Read PER OCTET_STRING. + * + * @param s The stream to read from + * @param oct_str octet string + * @param length string length + * @param min minimum length + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_octet_string(wStream* s, const BYTE* oct_str, UINT16 length, UINT16 min) +{ + UINT16 mlength = 0; + + if (!per_read_length(s, &mlength)) + return FALSE; + + if (mlength + min != length) + { + WLog_ERR(TAG, "length mismatch: %" PRIu16 "!= %" PRIu16, mlength + min, length); + return FALSE; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, length)) + return FALSE; + + const BYTE* a_oct_str = Stream_ConstPointer(s); + Stream_Seek(s, length); + + return per_check_oid_and_log_mismatch(a_oct_str, oct_str, length); +} + +/** + * Write PER OCTET_STRING + * @param s stream + * @param oct_str octet string + * @param length string length + * @param min minimum string length + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_octet_string(wStream* s, const BYTE* oct_str, UINT16 length, UINT16 min) +{ + UINT16 mlength = 0; + + mlength = (length >= min) ? length - min : min; + + if (!per_write_length(s, mlength)) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, length)) + return FALSE; + for (UINT16 i = 0; i < length; i++) + Stream_Write_UINT8(s, oct_str[i]); + return TRUE; +} + +/** + * Read PER NumericString. + * @param s stream + * @param min minimum string length + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_read_numeric_string(wStream* s, UINT16 min) +{ + size_t length = 0; + UINT16 mlength = 0; + + if (!per_read_length(s, &mlength)) + return FALSE; + + length = (mlength + min + 1) / 2; + + if (!Stream_CheckAndLogRequiredLength(TAG, s, length)) + return FALSE; + + Stream_Seek(s, length); + return TRUE; +} + +/** + * Write PER NumericString. + * @param s stream + * @param num_str numeric string + * @param length string length + * @param min minimum string length + * + * @return \b TRUE for success, \b FALSE otherwise. + */ + +BOOL per_write_numeric_string(wStream* s, const BYTE* num_str, UINT16 length, UINT16 min) +{ + WINPR_ASSERT(num_str || (length == 0)); + + const UINT16 mlength = (length >= min) ? length - min : min; + + if (!per_write_length(s, mlength)) + return FALSE; + + if (!Stream_EnsureRemainingCapacity(s, length)) + return FALSE; + for (UINT16 i = 0; i < length; i += 2) + { + BYTE c1 = num_str[i]; + BYTE c2 = ((i + 1) < length) ? num_str[i + 1] : 0x30; + + if ((c1 < 0x30) || (c2 < 0x30)) + return FALSE; + + c1 = (c1 - 0x30) % 10; + c2 = (c2 - 0x30) % 10; + const BYTE num = WINPR_ASSERTING_INT_CAST(BYTE, (c1 << 4) | c2); + + Stream_Write_UINT8(s, num); /* string */ + } + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/privatekey.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/privatekey.h new file mode 100644 index 0000000000000000000000000000000000000000..b423c9a4bd4b46b3ca53fda4081fc1a1efe3c4ee --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/privatekey.h @@ -0,0 +1,67 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Private key Handling + * + * Copyright 2023 Armin Novak + * Copyright 2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_LIB_CORE_PRIVATEKEY_H +#define FREERDP_LIB_CORE_PRIVATEKEY_H + +#include +#include +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + enum FREERDP_KEY_PARAM + { + FREERDP_KEY_PARAM_RSA_D, + FREERDP_KEY_PARAM_RSA_E, + FREERDP_KEY_PARAM_RSA_N + }; + + FREERDP_LOCAL rdpPrivateKey* freerdp_key_clone(const rdpPrivateKey* key); + + FREERDP_LOCAL const rdpCertInfo* freerdp_key_get_info(const rdpPrivateKey* key); + FREERDP_LOCAL const BYTE* freerdp_key_get_exponent(const rdpPrivateKey* key, size_t* plength); + + FREERDP_LOCAL BOOL freerdp_key_generate(rdpPrivateKey* key, size_t bits); + + /** \brief returns a pointer to a EVP_PKEY structure. + * Call EVP_PKEY_free when done. + */ + FREERDP_LOCAL EVP_PKEY* freerdp_key_get_evp_pkey(const rdpPrivateKey* key); + + FREERDP_LOCAL BYTE* freerdp_key_get_param(const rdpPrivateKey* key, + enum FREERDP_KEY_PARAM param, size_t* plength); + + FREERDP_LOCAL WINPR_DIGEST_CTX* freerdp_key_digest_sign(rdpPrivateKey* key, + WINPR_MD_TYPE digest); + + FREERDP_LOCAL extern const rdpPrivateKey* priv_key_tssk; + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_LIB_CORE_PRIVATEKEY_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..351f978fb0f772d27748b530f2b83583201d19c8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/CMakeLists.txt @@ -0,0 +1,32 @@ +set(MODULE_NAME "TestFreeRDPCrypto") +set(MODULE_PREFIX "TEST_FREERDP_CRYPTO") + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(DRIVER ${MODULE_NAME}.c) + +set(TESTS TestKnownHosts.c TestBase64.c) + +if(BUILD_TESTING_INTERNAL) + list(APPEND TESTS Test_x509_utils.c) +endif() + +create_test_sourcelist(SRCS ${DRIVER} ${TESTS}) + +include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR}) + +add_executable(${MODULE_NAME} ${SRCS}) + +set(TEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +add_compile_definitions(TEST_SOURCE_DIR="${TEST_PATH}") +target_link_libraries(${MODULE_NAME} freerdp winpr ${OPENSSL_LIBRARIES}) + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Test") diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/TestBase64.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/TestBase64.c new file mode 100644 index 0000000000000000000000000000000000000000..9576f669e0e49b04512e3da14e94364d5b6d3f14 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/TestBase64.c @@ -0,0 +1,178 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2014 Thincast Technologies GmbH + * Copyright 2014 Hardening + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +struct Encode64test +{ + const char* input; + size_t len; + const char* output; +}; + +static const struct Encode64test encodeTests_base64[] = { + { "\x00", 1, "AA==" }, + { "\x00\x00", 2, "AAA=" }, + { "\x00\x00\x00", 3, "AAAA" }, + { "0123456", 7, "MDEyMzQ1Ng==" }, + { "90123456", 8, "OTAxMjM0NTY=" }, + { "890123456", 9, "ODkwMTIzNDU2" }, + { "7890123456", 10, "Nzg5MDEyMzQ1Ng==" }, + + { NULL, -1, NULL }, /* /!\ last one /!\ */ +}; + +static const struct Encode64test encodeTests_base64url[] = { + { "\x00", 1, "AA" }, + { "\x00\x00", 2, "AAA" }, + { "\x00\x00\x00", 3, "AAAA" }, + { "01?34>6", 7, "MDE_MzQ-Ng" }, + { "90123456", 8, "OTAxMjM0NTY" }, + { "890123456", 9, "ODkwMTIzNDU2" }, + { "78?01>3456", 10, "Nzg_MDE-MzQ1Ng" }, + + { NULL, -1, NULL }, /* /!\ last one /!\ */ +}; + +int TestBase64(int argc, char* argv[]) +{ + int testNb = 0; + size_t outLen = 0; + BYTE* decoded = NULL; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + testNb++; + (void)fprintf(stderr, "%d:encode base64...", testNb); + + for (int i = 0; encodeTests_base64[i].input; i++) + { + char* encoded = crypto_base64_encode((const BYTE*)encodeTests_base64[i].input, + encodeTests_base64[i].len); + + if (strcmp(encodeTests_base64[i].output, encoded) != 0) + { + (void)fprintf(stderr, "ko, error for string %d\n", i); + return -1; + } + + free(encoded); + } + + (void)fprintf(stderr, "ok\n"); + testNb++; + (void)fprintf(stderr, "%d:encode base64url...", testNb); + + for (int i = 0; encodeTests_base64url[i].input; i++) + { + char* encoded = crypto_base64url_encode((const BYTE*)encodeTests_base64url[i].input, + encodeTests_base64url[i].len); + + if (strcmp(encodeTests_base64url[i].output, encoded) != 0) + { + (void)fprintf(stderr, "ko, error for string %d\n", i); + return -1; + } + + free(encoded); + } + + (void)fprintf(stderr, "ok\n"); + testNb++; + (void)fprintf(stderr, "%d:decode base64...", testNb); + + for (int i = 0; encodeTests_base64[i].input; i++) + { + crypto_base64_decode(encodeTests_base64[i].output, strlen(encodeTests_base64[i].output), + &decoded, &outLen); + + if (!decoded || (outLen != encodeTests_base64[i].len) || + memcmp(encodeTests_base64[i].input, decoded, outLen) != 0) + { + (void)fprintf(stderr, "ko, error for string %d\n", i); + return -1; + } + + free(decoded); + } + + (void)fprintf(stderr, "ok\n"); + testNb++; + (void)fprintf(stderr, "%d:decode base64url...", testNb); + + for (int i = 0; encodeTests_base64url[i].input; i++) + { + crypto_base64url_decode(encodeTests_base64url[i].output, + strlen(encodeTests_base64url[i].output), &decoded, &outLen); + + if (!decoded || (outLen != encodeTests_base64url[i].len) || + memcmp(encodeTests_base64url[i].input, decoded, outLen) != 0) + { + (void)fprintf(stderr, "ko, error for string %d\n", i); + return -1; + } + + free(decoded); + } + + (void)fprintf(stderr, "ok\n"); + testNb++; + (void)fprintf(stderr, "%d:decode base64 errors...", testNb); + crypto_base64_decode("000", 3, &decoded, &outLen); + + if (decoded) + { + (void)fprintf(stderr, "ko, badly padded string\n"); + return -1; + } + + crypto_base64_decode("0=00", 4, &decoded, &outLen); + + if (decoded) + { + (void)fprintf(stderr, "ko, = in a wrong place\n"); + return -1; + } + + crypto_base64_decode("00=0", 4, &decoded, &outLen); + + if (decoded) + { + (void)fprintf(stderr, "ko, = in a wrong place\n"); + return -1; + } + (void)fprintf(stderr, "ok\n"); + testNb++; + + /* test the encode_ex version that will add \r\n */ + (void)fprintf(stderr, "%d:encode base64 with crLf...", testNb); + const char* longStr = "01234567890123456789012345678901234567890123456789"; + const char* longStrExpected = + "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3\r\nODk=\r\n"; + + char* encoded = crypto_base64_encode_ex((const BYTE*)longStr, strlen(longStr), TRUE); + if (!encoded || strcmp(encoded, longStrExpected) != 0) + { + (void)fprintf(stderr, "problem with encode with CRLF\n"); + return -1; + } + free(encoded); + (void)fprintf(stderr, "ok\n"); + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/TestKnownHosts.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/TestKnownHosts.c new file mode 100644 index 0000000000000000000000000000000000000000..d6fbedbcaafc99a502fe51d962e7fcd1b9d92114 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/TestKnownHosts.c @@ -0,0 +1,394 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2015 Thincast Technologies GmbH + * Copyright 2015 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include + +/* Some certificates copied from /usr/share/ca-certificates */ +static const char pem1[] = "-----BEGIN CERTIFICATE-----\n" + "MIIFWjCCA0KgAwIBAgIQbkepxUtHDA3sM9CJuRz04TANBgkqhkiG9w0BAQwFADBH\n" + "MQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExM\n" + "QzEUMBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIy\n" + "MDAwMDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNl\n" + "cnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjEwggIiMA0GCSqGSIb3DQEB\n" + "AQUAA4ICDwAwggIKAoICAQC2EQKLHuOhd5s73L+UPreVp0A8of2C+X0yBoJx9vaM\n" + "f/vo27xqLpeXo4xL+Sv2sfnOhB2x+cWX3u+58qPpvBKJXqeqUqv4IyfLpLGcY9vX\n" + "mX7wCl7raKb0xlpHDU0QM+NOsROjyBhsS+z8CZDfnWQpJSMHobTSPS5g4M/SCYe7\n" + "zUjwTcLCeoiKu7rPWRnWr4+wB7CeMfGCwcDfLqZtbBkOtdh+JhpFAz2weaSUKK0P\n" + "fyblqAj+lug8aJRT7oM6iCsVlgmy4HqMLnXWnOunVmSPlk9orj2XwoSPwLxAwAtc\n" + "vfaHszVsrBhQf4TgTM2S0yDpM7xSma8ytSmzJSq0SPly4cpk9+aCEI3oncKKiPo4\n" + "Zor8Y/kB+Xj9e1x3+naH+uzfsQ55lVe0vSbv1gHR6xYKu44LtcXFilWr06zqkUsp\n" + "zBmkMiVOKvFlRNACzqrOSbTqn3yDsEB750Orp2yjj32JgfpMpf/VjsPOS+C12LOO\n" + "Rc92wO1AK/1TD7Cn1TsNsYqiA94xrcx36m97PtbfkSIS5r762DL8EGMUUXLeXdYW\n" + "k70paDPvOmbsB4om3xPXV2V4J95eSRQAogB/mqghtqmxlbCluQ0WEdrHbEg8QOB+\n" + "DVrNVjzRlwW5y0vtOUucxD/SVRNuJLDWcfr0wbrM7Rv1/oFB2ACYPTrIrnqYNxgF\n" + "lQIDAQABo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNV\n" + "HQ4EFgQU5K8rJnEaK0gnhS9SZizv8IkTcT4wDQYJKoZIhvcNAQEMBQADggIBADiW\n" + "Cu49tJYeX++dnAsznyvgyv3SjgofQXSlfKqE1OXyHuY3UjKcC9FhHb8owbZEKTV1\n" + "d5iyfNm9dKyKaOOpMQkpAWBz40d8U6iQSifvS9efk+eCNs6aaAyC58/UEBZvXw6Z\n" + "XPYfcX3v73svfuo21pdwCxXu11xWajOl40k4DLh9+42FpLFZXvRq4d2h9mREruZR\n" + "gyFmxhE+885H7pwoHyXa/6xmld01D1zvICxi/ZG6qcz8WpyTgYMpl0p8WnK0OdC3\n" + "d8t5/Wk6kjftbjhlRn7pYL15iJdfOBL07q9bgsiG1eGZbYwE8na6SfZu6W0eX6Dv\n" + "J4J2QPim01hcDyxC2kLGe4g0x8HYRZvBPsVhHdljUEn2NIVq4BjFbkerQUIpm/Zg\n" + "DdIx02OYI5NaAIFItO/Nis3Jz5nu2Z6qNuFoS3FJFDYoOj0dzpqPJeaAcWErtXvM\n" + "+SUWgeExX6GjfhaknBZqlxi9dnKlC54dNuYvoS++cJEPqOba+MSSQGwlfnuzCdyy\n" + "F62ARPBopY+Udf90WuioAnwMCeKpSwughQtiue+hMZL77/ZRBIls6Kl0obsXs7X9\n" + "SQ98POyDGCBDTtWTurQ0sR8WNh8M5mQ5Fkzc4P4dyKliPUDqysU0ArSuiYgzNdws\n" + "E3PYJ/HQcu51OyLemGhmW/HGY0dVHLqlCFF1pkgl\n" + "-----END CERTIFICATE-----"; + +static const char pem2[] = "-----BEGIN CERTIFICATE-----\n" + "MIIFWjCCA0KgAwIBAgIQbkepxlqz5yDFMJo/aFLybzANBgkqhkiG9w0BAQwFADBH\n" + "MQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExM\n" + "QzEUMBIGA1UEAxMLR1RTIFJvb3QgUjIwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIy\n" + "MDAwMDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNl\n" + "cnZpY2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjIwggIiMA0GCSqGSIb3DQEB\n" + "AQUAA4ICDwAwggIKAoICAQDO3v2m++zsFDQ8BwZabFn3GTXd98GdVarTzTukk3Lv\n" + "CvptnfbwhYBboUhSnznFt+4orO/LdmgUud+tAWyZH8QiHZ/+cnfgLFuv5AS/T3Kg\n" + "GjSY6Dlo7JUle3ah5mm5hRm9iYz+re026nO8/4Piy33B0s5Ks40FnotJk9/BW9Bu\n" + "XvAuMC6C/Pq8tBcKSOWIm8Wba96wyrQD8Nr0kLhlZPdcTK3ofmZemde4wj7I0BOd\n" + "re7kRXuJVfeKH2JShBKzwkCX44ofR5GmdFrS+LFjKBC4swm4VndAoiaYecb+3yXu\n" + "PuWgf9RhD1FLPD+M2uFwdNjCaKH5wQzpoeJ/u1U8dgbuak7MkogwTZq9TwtImoS1\n" + "mKPV+3PBV2HdKFZ1E66HjucMUQkQdYhMvI35ezzUIkgfKtzra7tEscszcTJGr61K\n" + "8YzodDqs5xoic4DSMPclQsciOzsSrZYuxsN2B6ogtzVJV+mSSeh2FnIxZyuWfoqj\n" + "x5RWIr9qS34BIbIjMt/kmkRtWVtd9QCgHJvGeJeNkP+byKq0rxFROV7Z+2et1VsR\n" + "nTKaG73VululycslaVNVJ1zgyjbLiGH7HrfQy+4W+9OmTN6SpdTi3/UGVN4unUu0\n" + "kzCqgc7dGtxRcw1PcOnlthYhGXmy5okLdWTK1au8CcEYof/UVKGFPP0UJAOyh9Ok\n" + "twIDAQABo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNV\n" + "HQ4EFgQUu//KjiOfT5nK2+JopqUVJxce2Q4wDQYJKoZIhvcNAQEMBQADggIBALZp\n" + "8KZ3/p7uC4Gt4cCpx/k1HUCCq+YEtN/L9x0Pg/B+E02NjO7jMyLDOfxA325BS0JT\n" + "vhaI8dI4XsRomRyYUpOM52jtG2pzegVATX9lO9ZY8c6DR2Dj/5epnGB3GFW1fgiT\n" + "z9D2PGcDFWEJ+YF59exTpJ/JjwGLc8R3dtyDovUMSRqodt6Sm2T4syzFJ9MHwAiA\n" + "pJiS4wGWAqoC7o87xdFtCjMwc3i5T1QWvwsHoaRc5svJXISPD+AVdyx+Jn7axEvb\n" + "pxZ3B7DNdehyQtaVhJ2Gg/LkkM0JR9SLA3DaWsYDQvTtN6LwG1BUSw7YhN4ZKJmB\n" + "R64JGz9I0cNv4rBgF/XuIwKl2gBbbZCr7qLpGzvpx0QnRY5rn/WkhLx3+WuXrD5R\n" + "RaIRpsyF7gpo8j5QOHokYh4XIDdtak23CZvJ/KRY9bb7nE4Yu5UC56GtmwfuNmsk\n" + "0jmGwZODUNKBRqhfYlcsu2xkiAhu7xNUX90txGdj08+JN7+dIPT7eoOboB6BAFDC\n" + "5AwiWVIQ7UNWhwD4FFKnHYuTjKJNRn8nxnGbJN7k2oaLDX5rIMHAnuFl2GqjpuiF\n" + "izoHCBy69Y9Vmhh1fuXsgWbRIXOhNUQLgD1bnF5vKheW0YMjiGZt5obicDIvUiLn\n" + "yOd/xCxgXS/Dr55FBcOEArf9LAhST4Ldo/DUhgkC\n" + "-----END CERTIFICATE-----"; + +static const char pem3[] = "-----BEGIN CERTIFICATE-----\n" + "MIICDDCCAZGgAwIBAgIQbkepx2ypcyRAiQ8DVd2NHTAKBggqhkjOPQQDAzBHMQsw\n" + "CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU\n" + "MBIGA1UEAxMLR1RTIFJvb3QgUjMwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAw\n" + "MDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp\n" + "Y2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjMwdjAQBgcqhkjOPQIBBgUrgQQA\n" + "IgNiAAQfTzOHMymKoYTey8chWEGJ6ladK0uFxh1MJ7x/JlFyb+Kf1qPKzEUURout\n" + "736GjOyxfi//qXGdGIRFBEFVbivqJn+7kAHjSxm65FSWRQmx1WyRRK2EE46ajA2A\n" + "DDL24CejQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud\n" + "DgQWBBTB8Sa6oC2uhYHP0/EqEr24Cmf9vDAKBggqhkjOPQQDAwNpADBmAjEAgFuk\n" + "fCPAlaUs3L6JbyO5o91lAFJekazInXJ0glMLfalAvWhgxeG4VDvBNhcl2MG9AjEA\n" + "njWSdIUlUfUk7GRSJFClH9voy8l27OyCbvWFGFPouOOaKaqW04MjyaR7YbPMAuhd\n" + "-----END CERTIFICATE-----"; + +static const char pem4[] = "-----BEGIN CERTIFICATE-----\n" + "MIICCjCCAZGgAwIBAgIQbkepyIuUtui7OyrYorLBmTAKBggqhkjOPQQDAzBHMQsw\n" + "CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU\n" + "MBIGA1UEAxMLR1RTIFJvb3QgUjQwHhcNMTYwNjIyMDAwMDAwWhcNMzYwNjIyMDAw\n" + "MDAwWjBHMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp\n" + "Y2VzIExMQzEUMBIGA1UEAxMLR1RTIFJvb3QgUjQwdjAQBgcqhkjOPQIBBgUrgQQA\n" + "IgNiAATzdHOnaItgrkO4NcWBMHtLSZ37wWHO5t5GvWvVYRg1rkDdc/eJkTBa6zzu\n" + "hXyiQHY7qca4R9gq55KRanPpsXI5nymfopjTX15YhmUPoYRlBtHci8nHc8iMai/l\n" + "xKvRHYqjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MB0GA1Ud\n" + "DgQWBBSATNbrdP9JNqPV2Py1PsVq8JQdjDAKBggqhkjOPQQDAwNnADBkAjBqUFJ0\n" + "CMRw3J5QdCHojXohw0+WbhXRIjVhLfoIN+4Zba3bssx9BzT1YBkstTTZbyACMANx\n" + "sbqjYAuG7ZoIapVon+Kz4ZNkfF6Tpt95LY2F45TPI11xzPKwTdb+mciUqXWi4w==\n" + "-----END CERTIFICATE-----"; + +static int prepare(const char* currentFileV2) +{ + int rc = -1; + const char* hosts[] = { "#somecomment\r\n" + "someurl 3389 ff:11:22:dd c3ViamVjdA== aXNzdWVy\r\n" + " \t#anothercomment\r\n" + "otherurl\t3389\taa:bb:cc:dd\tsubject2\tissuer2\r" }; + FILE* fc = NULL; + fc = winpr_fopen(currentFileV2, "w+"); + + if (!fc) + goto finish; + + for (size_t i = 0; i < ARRAYSIZE(hosts); i++) + { + if (fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1) + goto finish; + } + + rc = 0; +finish: + + if (fc) + (void)fclose(fc); + + return rc; +} + +static BOOL setup_config(rdpSettings** settings) +{ + BOOL rc = FALSE; + char* path = NULL; + char sname[8192]; + SYSTEMTIME systemTime; + + if (!settings) + goto fail; + *settings = freerdp_settings_new(0); + if (!*settings) + goto fail; + + GetSystemTime(&systemTime); + (void)sprintf_s(sname, sizeof(sname), + "TestKnownHostsCurrent-%04" PRIu16 "%02" PRIu16 "%02" PRIu16 "%02" PRIu16 + "%02" PRIu16 "%02" PRIu16 "%04" PRIu16, + systemTime.wYear, systemTime.wMonth, systemTime.wDay, systemTime.wHour, + systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds); + + path = GetKnownSubPath(KNOWN_PATH_TEMP, sname); + if (!path) + goto fail; + if (!winpr_PathFileExists(path)) + { + if (!CreateDirectoryA(path, NULL)) + { + (void)fprintf(stderr, "Could not create %s!\n", path); + goto fail; + } + } + + rc = freerdp_settings_set_string(*settings, FreeRDP_ConfigPath, path); +fail: + free(path); + return rc; +} + +static BOOL equal(const char* a, const char* b) +{ + if (!a && !b) + return TRUE; + if (!a || !b) + return FALSE; + return strcmp(a, b) == 0; +} + +static BOOL compare(const rdpCertificateData* data, const rdpCertificateData* stored) +{ + if (!data || !stored) + return FALSE; + if (!equal(freerdp_certificate_data_get_subject(data), + freerdp_certificate_data_get_subject(stored))) + return FALSE; + if (!equal(freerdp_certificate_data_get_issuer(data), + freerdp_certificate_data_get_issuer(stored))) + return FALSE; + if (!equal(freerdp_certificate_data_get_fingerprint(data), + freerdp_certificate_data_get_fingerprint(stored))) + return FALSE; + return TRUE; +} + +static BOOL pem_equal(const char* a, const char* b) +{ + return strcmp(a, b) == 0; +} + +static BOOL compare_ex(const rdpCertificateData* data, const rdpCertificateData* stored) +{ + if (!compare(data, stored)) + return FALSE; + if (!pem_equal(freerdp_certificate_data_get_pem(data), + freerdp_certificate_data_get_pem(stored))) + return FALSE; + + return TRUE; +} + +static BOOL test_get_data(rdpCertificateStore* store, const rdpCertificateData* data) +{ + BOOL res = 0; + rdpCertificateData* stored = freerdp_certificate_store_load_data( + store, freerdp_certificate_data_get_host(data), freerdp_certificate_data_get_port(data)); + if (!stored) + return FALSE; + + res = compare(data, stored); + freerdp_certificate_data_free(stored); + return res; +} + +static BOOL test_get_data_ex(rdpCertificateStore* store, const rdpCertificateData* data) +{ + BOOL res = 0; + rdpCertificateData* stored = freerdp_certificate_store_load_data( + store, freerdp_certificate_data_get_host(data), freerdp_certificate_data_get_port(data)); + if (!stored) + return FALSE; + + res = compare_ex(data, stored); + freerdp_certificate_data_free(stored); + return res; +} + +static BOOL test_certs_dir(void) +{ + BOOL rc = FALSE; + rdpSettings* settings = NULL; + rdpCertificateStore* store = NULL; + rdpCertificateData* data1 = NULL; + rdpCertificateData* data2 = NULL; + rdpCertificateData* data3 = NULL; + rdpCertificateData* data4 = NULL; + + printf("%s\n", __func__); + if (!setup_config(&settings)) + goto fail; + + printf("freerdp_certificate_store_new()\n"); + store = freerdp_certificate_store_new(settings); + if (!store) + goto fail; + + { + printf("freerdp_certificate_data_new()\n"); + data1 = freerdp_certificate_data_new_from_pem("somehost", 1234, pem1, strlen(pem1)); + data2 = freerdp_certificate_data_new_from_pem("otherhost", 4321, pem2, strlen(pem2)); + data3 = freerdp_certificate_data_new_from_pem("otherhost4", 444, pem3, strlen(pem3)); + data4 = freerdp_certificate_data_new_from_pem("otherhost", 4321, pem4, strlen(pem4)); + if (!data1 || !data2 || !data3 || !data4) + goto fail; + + /* Find non existing in empty store */ + printf("freerdp_certificate_store_load_data on empty store\n"); + if (test_get_data(store, data1)) + goto fail; + if (test_get_data_ex(store, data1)) + goto fail; + if (test_get_data(store, data2)) + goto fail; + if (test_get_data_ex(store, data2)) + goto fail; + if (test_get_data(store, data3)) + goto fail; + if (test_get_data_ex(store, data3)) + goto fail; + + /* Add certificates */ + printf("freerdp_certificate_store_save_data\n"); + if (!freerdp_certificate_store_save_data(store, data1)) + goto fail; + if (!freerdp_certificate_store_save_data(store, data2)) + goto fail; + + /* Find non existing in non empty store */ + printf("freerdp_certificate_store_load_data on filled store, non existing value\n"); + if (test_get_data(store, data3)) + goto fail; + if (test_get_data_ex(store, data3)) + goto fail; + + /* Add remaining certs */ + printf("freerdp_certificate_store_save_data\n"); + if (!freerdp_certificate_store_save_data(store, data3)) + goto fail; + + /* Check existing can all be found */ + printf("freerdp_certificate_store_load_data on filled store, existing value\n"); + if (!test_get_data(store, data1)) + goto fail; + if (!test_get_data_ex(store, data1)) + goto fail; + if (!test_get_data(store, data2)) + goto fail; + if (!test_get_data_ex(store, data2)) + goto fail; + if (!test_get_data(store, data3)) + goto fail; + if (!test_get_data_ex(store, data3)) + goto fail; + + /* Modify existing entry */ + printf("freerdp_certificate_store_save_data modify data\n"); + if (!freerdp_certificate_store_save_data(store, data4)) + goto fail; + + /* Check new data is in store */ + printf("freerdp_certificate_store_load_data check modified data can be loaded\n"); + if (!test_get_data(store, data4)) + goto fail; + if (!test_get_data_ex(store, data4)) + goto fail; + + /* Check old data is no longer valid */ + printf("freerdp_certificate_store_load_data check original data no longer there\n"); + if (test_get_data(store, data2)) + goto fail; + if (test_get_data_ex(store, data2)) + goto fail; + + /* Delete a cert */ + printf("freerdp_certificate_store_remove_data\n"); + if (!freerdp_certificate_store_remove_data(store, data3)) + goto fail; + /* Delete non existing, should succeed */ + printf("freerdp_certificate_store_remove_data missing value\n"); + if (!freerdp_certificate_store_remove_data(store, data3)) + goto fail; + + printf("freerdp_certificate_store_load_data on filled store, existing value\n"); + if (!test_get_data(store, data1)) + goto fail; + if (!test_get_data_ex(store, data1)) + goto fail; + if (!test_get_data(store, data4)) + goto fail; + if (!test_get_data_ex(store, data4)) + goto fail; + + printf("freerdp_certificate_store_load_data on filled store, removed value\n"); + if (test_get_data(store, data3)) + goto fail; + if (test_get_data_ex(store, data3)) + goto fail; + } + + rc = TRUE; +fail: + printf("freerdp_certificate_data_free %d\n", rc); + freerdp_certificate_data_free(data1); + freerdp_certificate_data_free(data2); + freerdp_certificate_data_free(data3); + freerdp_certificate_data_free(data4); + freerdp_certificate_store_free(store); + freerdp_settings_free(settings); + return rc; +} + +int TestKnownHosts(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!test_certs_dir()) + return -1; + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/Test_x509_cert_info.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/Test_x509_cert_info.pem new file mode 100644 index 0000000000000000000000000000000000000000..5ac118709e2cb15771e342e8cad79539f563f2df --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/Test_x509_cert_info.pem @@ -0,0 +1,41 @@ +-----BEGIN CERTIFICATE----- +MIIHNzCCBR+gAwIBAgICEAAwDQYJKoZIhvcNAQEFBQAwcDEqMCgGA1UEAwwhQURN +SU5JU1RSQVRJT04gQ0VOVFJBTEUgREVTIFRFU1RTMQswCQYDVQQGEwJGUjEcMBoG +A1UECgwTTUlOSVNURVJFIERFUyBURVNUUzEXMBUGA1UECwwOMDAwMiAxMTAwMTQw +MTYwHhcNMTgwNTE4MDkyNTU1WhcNMTkwNTEzMDkyNTU1WjCBvzEkMCIGA1UEAwwb +VEVTVEpFQU4gVEVTVE1BUlRJTiA5OTk5OTk5MQswCQYDVQQGEwJGUjEcMBoGA1UE +CgwTTUlOSVNURVJFIERFUyBURVNUUzEXMBUGA1UECwwOMDAwMiAxMTAwMTQwMTYx +EjAQBgNVBAsMCVBFUlNPTk5FUzEXMBUGCgmSJomT8ixkAQEMBzk5OTk5OTkxETAP +BgNVBCoMCFRFU1RKRUFOMRMwEQYDVQQEDApURVNUTUFSVElOMIICIjANBgkqhkiG +9w0BAQEFAAOCAg8AMIICCgKCAgEA3yc22RDYc+Vc6F26/LONvaYkdTVDiCgbh9Ik +6pLF5izNpfdQ/YZU25h/UPECdchYX31UEErVOYudOBOHtU4fNjTO0oK5Va/DoFln +LnfwNpAlBZfogG+yy8fK4yLxG+raoSKDR/5P3hmTqKJqw1WpkwcVE2EDqkP1clMZ +L5cvJj6gLJa2q0JCdoKe7NntZkgpIk5ZHUZm2JYC30xL7XHfvvb/i0OZLpPOIekT +DCzxr9HTjbqe+BRZix2UiGpXzjIlDm6EEQNebZqf5kKgcbkxIDWcVraE0kO3TqJI +P4FBUeuxLqGwQ0AMKrZ+j8U7KAoM9WUoIFcmm8nYGo4hT6ugNIQ9nwQSgyH3yGH1 +PU2k12Ovv2Ft8C/IFuusXxTOJprcFxtjE7qYZ44tmvlozlDOBOJYjLiURAh3r5LL +TadgArZ3XVMyWlwlTEy9qX59izY9Zz27kd5H11DOz5ezopHAWwP6sgCvWeNDyx8Q +I3jY8TYzJHahN2bknP2fqwwdGqFCrHItJx2DhDe2ruTk6vvbnwGgYqGzv+RtdNbW +CL4IMEQQKG9AM40WCz9pu32/vOaQ+hrYyCQMCtli0DSauB+K2IFPsAcz5OAaITJv +LenMt8mUP9NWHWfr5WYm0tuUCCU4dUT38MqkkdQv7oly1LHkvUdMU+Nk/Ki0Q83U +9gMvaPcCAwEAAaOCAYkwggGFMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXg +MDIGA1UdJQQrMCkGCCsGAQUFBwMCBggrBgEFBQcDBAYKKwYBBAGCNxQCAgYHKwYB +BQIDBDAdBgNVHQ4EFgQUXs4RKN+vUVsZjEW/J6qo6EZTLZUwHwYDVR0jBBgwFoAU +fUXj4k7OA3d8KylcprhMptiOL10wgbIGA1UdEQSBqjCBp6A9BgYrBgEFAgKgMzAx +oBYbFGtwbi50ZXN0LmV4YW1wbGUuY29toRcwFRsTdGVzdGplYW4udGVzdG1hcnRp +bqBABgorBgEEAYI3FAIDoDIMMHRlc3RqZWFuLnRlc3RtYXJ0aW4uOTk5OTk5OUB1 +cG4udGVzdC5leGFtcGxlLmNvbYEkdGVzdGplYW4udGVzdG1hcnRpbkB0ZXN0LmV4 +YW1wbGUuY29tMDEGA1UdEgQqMCiCEnJvb3RjYS5leGFtcGxlLmNvbYISaW50ZWNh +LmV4YW1wbGUuY29tMAkGA1UdIAQCMAAwDQYJKoZIhvcNAQEFBQADggIBAKRDovf+ +CCnV2mtXnzH5JlduOjPWJmGB5a8HLPvakfAm4wQ0YyAViE1tar0V9lhG6nCogWWa +28D+eM5vLPjVE8ebq5UjIv76x6gWoJkQ3HtfVJvn9UfXwax6IqT7hb1fAHBqu0rj +uSnSxf1wIzPMp9Lb5x3jBu9ryNMiLUzeY1slBvosOXKlmprPhGWfPYYNCZo2bGJI +1w5alGDgTBcWKl7icJjAIuCpyRTnKCsaN3kyDU7C5aUhsm9AriPiNErzRI+l5+eu +Ywg3MZ7Yfjd3rXb6JleT0ZnCh/nFtVLIccWaI4phCrYTGz6odNIqrZ6X23Pt6Rx3 +ZbQjtj4ipMdvbvJbS90aFMrTyfqhVLOxHy+setDcmPOixUgXlx8ZjFI9vgFUeJbo +OKrkLw4ITUduO+9MplBX7Kt/iCS/CbTfPlHMv03Xb6rbjqHxTJZCCu5QMNHiBeHV +l8FK5R6gv+9FuCl8uPHwGh/jelQp51cVORlQWeKpqWdwTi0Q3VeVeQAG5RR34xgT +cQa8h9AqkxYajhxKUmbUlaoYGd8TwUQLrS2jZxp/9geyApVQLAQ27CyAK5HyHSCA +uqCKsM0gFQyCL4IbXQyFMWgjXZYaorHFjVuMhYEkgWui/9sv+7sMAV5JzROeAw3l +4+D7yhywwuRzH2SzoavzGpWGMUveVsdLMRk9 +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/Test_x509_utils.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/Test_x509_utils.c new file mode 100644 index 0000000000000000000000000000000000000000..255f6d01a57218d9a623117ffcdcb84bc2ed99e5 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/Test_x509_utils.c @@ -0,0 +1,241 @@ +#include +#include +#include "../x509_utils.h" + +typedef char* (*get_field_pr)(const X509*); +typedef struct +{ + enum + { + DISABLED, + ENABLED, + } status; + const char* field_description; + get_field_pr get_field; + const char* expected_result; +} certificate_test_t; + +static char* x509_utils_subject_common_name_wo_length(const X509* xcert) +{ + size_t length = 0; + return x509_utils_get_common_name(xcert, &length); +} + +static char* certificate_path(const char* filename) +{ + /* + Assume the .pem file is in the same directory as this source file. + Assume that __FILE__ will be a valid path to this file, even from the current working directory + where the tests are run. (ie. no chdir occurs between compilation and test running, or __FILE__ + is an absolute path). + */ + static const char dirsep = '/'; +#ifdef TEST_SOURCE_DIR + const char* file = TEST_SOURCE_DIR; + const size_t flen = strlen(file) + sizeof(dirsep) + strlen(filename) + sizeof(char); + char* result = calloc(1, flen); + if (!result) + return NULL; + (void)_snprintf(result, flen, "%s%c%s", file, dirsep, filename); + return result; +#else + const char* file = __FILE__; + const char* last_dirsep = strrchr(file, dirsep); + + if (last_dirsep) + { + const size_t filenameLen = strlen(filename); + const size_t dirsepLen = last_dirsep - file + 1; + char* result = malloc(dirsepLen + filenameLen + 1); + if (!result) + return NULL; + strncpy(result, file, dirsepLen); + strncpy(result + dirsepLen, filename, filenameLen + 1); + return result; + } + else + { + /* No dirsep => relative path in same directory */ + return _strdup(filename); + } +#endif +} + +static const certificate_test_t certificate_tests[] = { + + { ENABLED, "Certificate Common Name", x509_utils_subject_common_name_wo_length, + "TESTJEAN TESTMARTIN 9999999" }, + + { ENABLED, "Certificate subject", x509_utils_get_subject, + "CN = TESTJEAN TESTMARTIN 9999999, C = FR, O = MINISTERE DES TESTS, OU = 0002 110014016, OU " + "= PERSONNES, UID = 9999999, GN = TESTJEAN, SN = TESTMARTIN" }, + + { DISABLED, "Kerberos principal name", 0, "testjean.testmartin@kpn.test.example.com" }, + + { ENABLED, "Certificate e-mail", x509_utils_get_email, "testjean.testmartin@test.example.com" + + }, + + { ENABLED, "Microsoft's Universal Principal Name", x509_utils_get_upn, + "testjean.testmartin.9999999@upn.test.example.com" }, + + { ENABLED, "Certificate issuer", x509_utils_get_issuer, + "CN = ADMINISTRATION CENTRALE DES TESTS, C = FR, O = MINISTERE DES TESTS, OU = 0002 " + "110014016" }, +}; + +static int TestCertificateFile(const char* certificate_path, + const certificate_test_t* ccertificate_tests, size_t count) +{ + int success = 0; + + X509* certificate = x509_utils_from_pem(certificate_path, strlen(certificate_path), TRUE); + + if (!certificate) + { + printf("%s: failure: cannot read certificate file '%s'\n", __func__, certificate_path); + success = -1; + goto fail; + } + + for (size_t i = 0; i < count; i++) + { + const certificate_test_t* test = &ccertificate_tests[i]; + char* result = NULL; + + if (test->status == DISABLED) + { + continue; + } + + result = (test->get_field ? test->get_field(certificate) : 0); + + if (result) + { + printf("%s: crypto got %-40s -> \"%s\"\n", __func__, test->field_description, result); + + if (0 != strcmp(result, test->expected_result)) + { + printf("%s: failure: for %s, actual: \"%s\", expected \"%s\"\n", __func__, + test->field_description, result, test->expected_result); + success = -1; + } + + free(result); + } + else + { + printf("%s: failure: cannot get %s\n", __func__, test->field_description); + } + } + +fail: + X509_free(certificate); + return success; +} + +/* clang-format off */ +/* +These certificates were generated with the following commands: + +openssl ecparam -name P-256 -out /tmp/p256.pem +openssl req -x509 -newkey ec:/tmp/p256.pem -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out ecdsa_sha1_cert.pem -sha1 +openssl req -x509 -newkey ec:/tmp/p256.pem -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out ecdsa_sha256_cert.pem -sha256 +openssl req -x509 -newkey ec:/tmp/p256.pem -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out ecdsa_sha384_cert.pem -sha384 +openssl req -x509 -newkey ec:/tmp/p256.pem -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out ecdsa_sha512_cert.pem -sha512 + +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pkcs1_sha1_cert.pem -sha1 +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pkcs1_sha256_cert.pem -sha256 +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pkcs1_sha384_cert.pem -sha384 +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pkcs1_sha512_cert.pem -sha512 + +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pss_sha1_cert.pem -sha1 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pss_sha256_cert.pem -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pss_sha384_cert.pem -sha384 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pss_sha512_cert.pem -sha512 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest +openssl req -x509 -newkey rsa:2048 -keyout /dev/null -days 3650 -nodes -subj "/CN=Test" -out rsa_pss_sha256_mgf1_sha384_cert.pem -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest -sigopt rsa_mgf1_md:sha384 +*/ +/* clang-format on */ + +typedef struct +{ + const char* filename; + WINPR_MD_TYPE expected; +} signature_alg_test_t; + +static const signature_alg_test_t signature_alg_tests[] = { + { "rsa_pkcs1_sha1_cert.pem", WINPR_MD_SHA1 }, + { "rsa_pkcs1_sha256_cert.pem", WINPR_MD_SHA256 }, + { "rsa_pkcs1_sha384_cert.pem", WINPR_MD_SHA384 }, + { "rsa_pkcs1_sha512_cert.pem", WINPR_MD_SHA512 }, + + { "ecdsa_sha1_cert.pem", WINPR_MD_SHA1 }, + { "ecdsa_sha256_cert.pem", WINPR_MD_SHA256 }, + { "ecdsa_sha384_cert.pem", WINPR_MD_SHA384 }, + { "ecdsa_sha512_cert.pem", WINPR_MD_SHA512 }, + + { "rsa_pss_sha1_cert.pem", WINPR_MD_SHA1 }, + { "rsa_pss_sha256_cert.pem", WINPR_MD_SHA256 }, + { "rsa_pss_sha384_cert.pem", WINPR_MD_SHA384 }, + { "rsa_pss_sha512_cert.pem", WINPR_MD_SHA512 }, + /* + PSS may use different digests for the message hash and MGF-1 hash. In this case, RFC 5929 + leaves the tls-server-end-point hash unspecified, so it should return WINPR_MD_NONE. + */ + { "rsa_pss_sha256_mgf1_sha384_cert.pem", WINPR_MD_NONE }, +}; + +static int TestSignatureAlgorithm(const signature_alg_test_t* test) +{ + int success = 0; + WINPR_MD_TYPE signature_alg = WINPR_MD_NONE; + char* path = certificate_path(test->filename); + X509* certificate = x509_utils_from_pem(path, strlen(path), TRUE); + + if (!certificate) + { + printf("%s: failure: cannot read certificate file '%s'\n", __func__, path); + success = -1; + goto fail; + } + + signature_alg = x509_utils_get_signature_alg(certificate); + if (signature_alg != test->expected) + { + const char* signature_alg_string = + signature_alg == WINPR_MD_NONE ? "none" : winpr_md_type_to_string(signature_alg); + const char* expected_string = + test->expected == WINPR_MD_NONE ? "none" : winpr_md_type_to_string(test->expected); + printf("%s: failure: for \"%s\", actual: %s, expected %s\n", __func__, test->filename, + signature_alg_string, expected_string); + success = -1; + goto fail; + } + +fail: + X509_free(certificate); + free(path); + return success; +} + +int Test_x509_utils(int argc, char* argv[]) +{ + char* cert_path = certificate_path("Test_x509_cert_info.pem"); + int ret = 0; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + ret = TestCertificateFile(cert_path, certificate_tests, ARRAYSIZE(certificate_tests)); + free(cert_path); + if (ret != 0) + return ret; + + for (size_t i = 0; i < ARRAYSIZE(signature_alg_tests); i++) + { + ret = TestSignatureAlgorithm(&signature_alg_tests[i]); + if (ret != 0) + return ret; + } + + return ret; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha1_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha1_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..86b98bdf2c14cc66f262373e52c17992a1f5804d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha1_cert.pem @@ -0,0 +1,10 @@ +-----BEGIN CERTIFICATE----- +MIIBcjCCARigAwIBAgIUP9Q+so71qPtrK898RUJibDMRSYQwCQYHKoZIzj0EATAP +MQ0wCwYDVQQDDARUZXN0MB4XDTI0MDIwNjAzMDkzNFoXDTM0MDIwMzAzMDkzNFow +DzENMAsGA1UEAwwEVGVzdDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABHj9x4Vr +7pGzpilUY799+mWmOsJwtxFZ3lPNRy+wsfxibRE6e2T0Gk2Ifysl8Vya6Ynwrd2d +7ztAk+b6HF+1lgqjUzBRMB0GA1UdDgQWBBSX66LoFThh5RCXaeAS+sjGPmLxKTAf +BgNVHSMEGDAWgBSX66LoFThh5RCXaeAS+sjGPmLxKTAPBgNVHRMBAf8EBTADAQH/ +MAkGByqGSM49BAEDSQAwRgIhAJf3H7PWAZ/5G2SbBKF5jzBVlmWLiVmfanLOvttf +9DFUAiEA3CnntihpfkAGjUCav7CojYfz8hqe0d6F9ZStfzV4t3g= +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha256_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha256_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..29aaf6925638b15e36a822f13c72fd9a32c3da60 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha256_cert.pem @@ -0,0 +1,10 @@ +-----BEGIN CERTIFICATE----- +MIIBdDCCARmgAwIBAgIUUDFppYHwhd7smJSH6W8QSLttoNEwCgYIKoZIzj0EAwIw +DzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA5MzRaFw0zNDAyMDMwMzA5MzRa +MA8xDTALBgNVBAMMBFRlc3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATfQ2ox +CF1xh6Dwcsi3BqyUIlKxgY3J2qOSmOzepOMLWhPpiDsneKskpKx4b5JM92mmIyiq +UMMR7mXlclDHyQtro1MwUTAdBgNVHQ4EFgQUgoV/fxICc75gTRslwgvs/I1YbOUw +HwYDVR0jBBgwFoAUgoV/fxICc75gTRslwgvs/I1YbOUwDwYDVR0TAQH/BAUwAwEB +/zAKBggqhkjOPQQDAgNJADBGAiEAyVInWgy3JVEUPDSpjNseJKPie/hINfO6KbrK +IqGQ0+ACIQDk/oXOIwFZr26TTghYKOn12aOuPCxOqeBu5ObeFMf91Q== +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha384_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha384_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..85b9d886b1cdfd107980bc83356e4ba61dcd9ef0 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha384_cert.pem @@ -0,0 +1,10 @@ +-----BEGIN CERTIFICATE----- +MIIBczCCARmgAwIBAgIUDT9Rw/q4CH5WmNCTbGbNI964MQwwCgYIKoZIzj0EAwMw +DzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA5MzRaFw0zNDAyMDMwMzA5MzRa +MA8xDTALBgNVBAMMBFRlc3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAR0oA7y +QeXAp65otDob8Uqmtthdub5T7fbzMr/qnUTxNYoUpXKnde28Cvan4QPCuepHmVPw +sVx94UX8RIlrXAhdo1MwUTAdBgNVHQ4EFgQUFfghIBL0wxknjd9I8+Wub61VJk4w +HwYDVR0jBBgwFoAUFfghIBL0wxknjd9I8+Wub61VJk4wDwYDVR0TAQH/BAUwAwEB +/zAKBggqhkjOPQQDAwNIADBFAiB66sAH30kMoOsMHu5vb1hUl3DPRLb30WbtVSBC +ZHEDyQIhAK1xgDA005XqcC77o8gzQFFsxIkQrCHTqre2LEGndxLA +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha512_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha512_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..5115ea8acc81d991cce54bd6d677acd871adb486 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/ecdsa_sha512_cert.pem @@ -0,0 +1,10 @@ +-----BEGIN CERTIFICATE----- +MIIBdDCCARmgAwIBAgIUfb77WvmuJ7r/9aLrhvfHymxssoQwCgYIKoZIzj0EAwQw +DzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA5MzRaFw0zNDAyMDMwMzA5MzRa +MA8xDTALBgNVBAMMBFRlc3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARewOb8 +HMJXad76YWUSaPLMUH8IKpzO0iZkQ2d1SSCylEMdrPJKhi54r7/y6m5LXMejyQzi +eB2eiNju1yfs1tkoo1MwUTAdBgNVHQ4EFgQUGSveQiJxuzwWX1jIRXdHCzdvj7Ew +HwYDVR0jBBgwFoAUGSveQiJxuzwWX1jIRXdHCzdvj7EwDwYDVR0TAQH/BAUwAwEB +/zAKBggqhkjOPQQDBANJADBGAiEAspDRGKH6Nlp+XUxyHKc3IGN5WVIg5ezGHJDR +9+Q8RAkCIQDVWMxflgAII4D+t2Z8nT4bavUImHD26kbaGtR2/DYPVw== +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/known_hosts/known_hosts b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/known_hosts/known_hosts new file mode 100644 index 0000000000000000000000000000000000000000..c165fc5c473e5db83709c2d9b56a2eca9f3d9085 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/known_hosts/known_hosts @@ -0,0 +1,2 @@ +someurl ff:11:22:dd +otherurl aa:bb:cc:dd diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/known_hosts/known_hosts.v2 b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/known_hosts/known_hosts.v2 new file mode 100644 index 0000000000000000000000000000000000000000..7d02106791b5ca6a1670e1285f48564aaa05d3db --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/known_hosts/known_hosts.v2 @@ -0,0 +1,2 @@ +someurl 3389 ff:11:22:dd +otherurl 3389 aa:bb:cc:dd diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha1_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha1_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..2b56b5f8b310c6a66d0f61e89c1bbea816b73cc7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha1_cert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIC/zCCAeegAwIBAgIUNveSXnRIoI24dM6PxYjhcXQhsgkwDQYJKoZIhvcNAQEF +BQAwDzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA2MzVaFw0zNDAyMDMwMzA2 +MzVaMA8xDTALBgNVBAMMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQCy23VMgwiNO32ovOxt+7CJCR5Ep1qn1tV5//ONhLEoz+VhEbMTYQNHK1WY +E9isGrcRUVLsBehIFP02ImgOGv1Yep/P1pY+A/fLpy4NhHoLYxmvdhAKQG3TB5P1 +s7GuXTaK4/Kp8CzVYP7xZu7zI2TWWolkCDYZvkewR5QOuyiAstvZp5IoIx0J9mo2 +rI5DqnSmK+zzaYTMaGyWFLXOQJZi+k+RUB3XUFZSid69thW0rfi7tC0fyUm7fP7H +72/27aBmW1S/8hUYSfu88kCCmEEu+KGXbmyNPEVMJcM9cZ43TVMGUPodOXuDydm/ +IKnsZaRnGPi8IBzn0y6k/8ZdmJojAgMBAAGjUzBRMB0GA1UdDgQWBBRsqgoFZ83u +IMZzUjsVI5N73Izq1DAfBgNVHSMEGDAWgBRsqgoFZ83uIMZzUjsVI5N73Izq1DAP +BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQCIFhCbHy6U6EYHogXE +xnoHdtzitHTUU+mymWeQxWxSvZjWX8xdJdbWQyktSCChKrRnQE+P/e5+HOZFn9q5 +jwgj3HwZZwFqt/0nSX7pjEvTOmwEXTo/QBlyHaLSdrxbd85gahkXP1br6vI0yWcT +kkKZCFiqbsGGqcoErRyZjYfJBgaZ5AMYXEKkKCgRJ59Sln+mW+fpta7dmgmnPIdX +Jl/ovEHr0X+PgwLby8BxCb5pOyb6CQvUNWfngtzgm76vricszpmDl4HeBAb0IkZ1 +0hlnHEBNgP46/2EhPvD1QehYOmr5HRi2xSPC9gOW8pkbRRFuCDZwoSfav023xim6 +lOS3 +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha256_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha256_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..2233c1828d8b726a97bb0828769695a59f6584ed --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha256_cert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIC/zCCAeegAwIBAgIUK9L1Ajn7PiMRVvR6YUoATBxgD2wwDQYJKoZIhvcNAQEL +BQAwDzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA2MzVaFw0zNDAyMDMwMzA2 +MzVaMA8xDTALBgNVBAMMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQC73wUpONU4o0abFykUC08A2deojU/+SGomnN8V51VDVeC2BGUljLabjABm +iluh/yUJ0zDHp6x1spr6wdDVzRMvjjxC/G2HVzYRn/3zXhZ0q9avPnCe1hgawHZY +FG4vgysJ1jtPSR97E4MvSg6v6mATCU2ttvceENFwo5FQ6nfBv+rHpepRyOKUtfsa +gxRCWU0uHwyahNsYzWOrbkEcpoQAowAoHZh9EbjyNNbCX0/C3yew/GX8mNBz1UOV +X4taJsOW52LKQ2xgSwl31m6VYmNqqfzTA6pr96PpYqsuAT3WYBBnIk+XT+Yhq3Cs +n96PvHAovUiBwWptvzsICvtAUwCjAgMBAAGjUzBRMB0GA1UdDgQWBBQGUaK7joEk +yFR6FtsA4UjF+FPrRTAfBgNVHSMEGDAWgBQGUaK7joEkyFR6FtsA4UjF+FPrRTAP +BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAkYpNiExDwuqfFCHpz +jWFSkL9drTxMuasGfmq634FSe050TGKl8yUZhz215PoEDHcutGAw6JV59DJMI/wo +Xq4MpJiCLlUu8BOixU41rlyc9XkV6twcnQlkVhYWV07390SP4uKGXRR03yGwjN7C +RDv/4z4t9iMQhiIYkN0EXKvymjRMhb9GocfTQFSXq6vy0fr4MuwnuOkr6EcU41Hr +pQ4nNLuj2P7cAaaFo5RaD/eXzsE4CfgoltmTp+Ir3deXG/RKrJ9V/YTx5d6pqssp +5f7nDKmhiYn6wtF4TlOnujppT1Mr4UZF7lJAfwUX80bYQBbpfczHBKSYQ/Th5Mtx +ediM +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha384_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha384_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..7ab6147976bbfbb2172bcbc3c1783e3235b30036 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha384_cert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIC/zCCAeegAwIBAgIUHpfVpdCFW4e5gmPMyNN/CZou028wDQYJKoZIhvcNAQEM +BQAwDzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA2MzVaFw0zNDAyMDMwMzA2 +MzVaMA8xDTALBgNVBAMMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQCMlHin4N8tMbfDqIahZlyOhBX392Pcyo4bUM7ipUEdLdz1SSCf7/gh4SgH +ihCbN/NWiYoobnR7iS6vBgUMQgzdivwOia0jydcifpf2UR2D1KjBnolALqaRYpDB +zdEOnJ4Nm21sOlfCM/QoiMdPWZlbzisXyGBYHR8E8G5Snfy13cRvfV+M9/epbvwV +1o4m/wPu2H+Q+XVRHJY1H7jAtjUtLSUwii0jc134c9nHOdqXB9fgcn7etkQKXWPv +w7Dg/OWXURpABGjflS6w4UhECzlPInmd9fBtLngf7n9Sa4b0rcdWEWcTbWORmEbj +xoHyWNiRbdzIc0zUb42DFuFgeUcFAgMBAAGjUzBRMB0GA1UdDgQWBBRm5loY68pA +VVlVVcIL3zTv1sCYWjAfBgNVHSMEGDAWgBRm5loY68pAVVlVVcIL3zTv1sCYWjAP +BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDAUAA4IBAQAJFNU9dUNpIbbsgyty +RRd5SVD/4ziOOPoKO6jobBenPxNQNbaOQmENImW0WbgOHWW1kX15afCThMocibKl +OIVoOf2tcrseAYdfsOzEMwDc1hI5y68vNRV32rJamix1223wPhs1xuoX8bn0t0VB +RK4kgb9U1mxSKERjcgtp2Pph5DeflCQDeNayBGAA5PCL4ydO61DEKbVo1Cyqtw9n +yhae7AUR4zzRnZEh1eePd06cXSIYwmTkiJLSF7ILsZnGcqy4bO8yJPrqXT01Iq0S +RzQ2hgyldKD0kJ3EBmki3mIrnswCzNqyXux1CXIR1FjIA5SnwycqiiPUUPLckinq +DtQX +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha512_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha512_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..bb798a35c9351b0f6c791a73167e1c4a2a9bc3c8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pkcs1_sha512_cert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIC/zCCAeegAwIBAgIUTAXZy2Zojh8wh4YSdc2vMBiytGIwDQYJKoZIhvcNAQEN +BQAwDzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA2MzVaFw0zNDAyMDMwMzA2 +MzVaMA8xDTALBgNVBAMMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQDH2av9vKvlzlSB63ylb8OyacC6zkhoiH4ECkVt7DRvBBnHYX39eeXg1KNk +yHBaLA+9ASXucckqAQ8hWlIW7y9KLYYsK8+ajDUnWkzPj+eOonSc2oTbSBtEP8V4 +3TihNGRgyLSZYj6HxUrFWW6pc0Kz7yAG83YNzR8uWCEZV8wYAdBqZDO1RAOd2tLr +DFLI+DJwMtgDquT1Uo/xDsx0p9+tSGXm4eXjlZQguhA4tuP4eJP7qvwR+khJNN9X +u2igfO3zMY26wX4m/kPdljxh5vRc2DVIePfKbTKLyfpsydQUSoKVzlSQG7QJAUmC +jcqgIGQqYy8f6Nq4fRzgiSQOULmPAgMBAAGjUzBRMB0GA1UdDgQWBBQMYhVmmR0c +9DJmJZOqHawdWDVFJDAfBgNVHSMEGDAWgBQMYhVmmR0c9DJmJZOqHawdWDVFJDAP +BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBDQUAA4IBAQBr2I9uvQ8Ccn5yw1Ig +7k2Qmg/HOCFGh42Ufz1PAc9dc1CzBzMlFucJ42shES98Spyh4R+ZCJmlZ9PneViA +s9NW+mHLAFJ2Fuct4XY8RnyDYqTne0in6eQykF33gl79sdYSPuBfAxMfJqUoQo+b +tF0N0DA00i5z69wcF5LQJLRbeTh7T1qikkay3ODMJYpCDVb7GOhWCt4hOkxOszuL +SoJ2gFMGoEKbt19IzcMctsSPgpQCNYZirU9x3l/Ptw5zgUQMEngwuutuhDMxb5Ht +2QHTGt3jwzlOi+lvHFH1AMW3e8/XRZa7jFUa+KCr8vD3yfDimx9J0ESmlUrLxOZG +ayG7 +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha1_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha1_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..dace407211f6b2e3bc5fe61156b30796d2c1438b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha1_cert.pem @@ -0,0 +1,19 @@ +-----BEGIN CERTIFICATE----- +MIIC/zCCAeegAwIBAgIUDZuL7xQULUgo1YKeDIJDFdsVCuMwDQYJKoZIhvcNAQEK +MAAwDzENMAsGA1UEAwwEVGVzdDAeFw0yNDAyMDYwMzA2MzVaFw0zNDAyMDMwMzA2 +MzVaMA8xDTALBgNVBAMMBFRlc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK +AoIBAQCxLekSxv8aVwB5p9UImN+jipKNJUb8fOrtOVHjeO5jK9G920vneZsubpq/ +NngzpjT2A+HOkee9oNG92O8U7DGyGXiZugmeFE6kunPQ+GP5za3XfZqwvAu53+Pg +oyrBGl5ssowRimRDXOH3/x7WSKD2lvQNgLWOS5NTIZethXx29Xj+/nKJ33im8ra/ +YcEB6CANHmo2bDCz8Q54iHjIOro+MiP10oQM2ERzuZREn/+xCFuYYGhXKb3fqy+r +Ze/tIVqEr7yMVpp76RxFM3I4PadHt8T9Q5Oat9FXWaqG/1fBtBKXt6jElkqnd+vv +KtRMEqQ4XNeMJi6Q4oyLsmxGB8q7AgMBAAGjUzBRMB0GA1UdDgQWBBQuCV/GISEn +D18xN3d1KEOo13c/2zAfBgNVHSMEGDAWgBQuCV/GISEnD18xN3d1KEOo13c/2zAP +BgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCjAAA4IBAQA+nnvGYJwVP5byl+XB +1KoFLv4SOS9kDypjv+4Mjo3/houn7DAf1+6ewfmAN7edkElTngpz6rGzJgARULbO +djKi6AJDDqF9NzWbJZC/UEVqqVY1Znw1v8Hwz31YFaoARLWwuKQrKjLZUHphsMok +iWdwusebfQ1SK9b8QTW7s8CncC+PbOHH1UnHhM1XWGz49sWZo/KnHCGL0pGROSro +gT2zEDDk/bpslalcavEGcw2wttaBiYovdpgUHzOIcTxLz/yQGAfaCk/cO8x5mS9y +w6CZVaH6K1TrmXGWBoHtLQ+JMC7msms3PmBZ4XCc8zAqjhVI4o71Jlbrd/Bag0lm +X+89 +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha256_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha256_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..e9e30e09685deb948ba52301b645d6e70e6a66a6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha256_cert.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDZzCCAhugAwIBAgIUChf3gsm9kG9E05UbcYnEzQ/fSfkwQQYJKoZIhvcNAQEK +MDSgDzANBglghkgBZQMEAgEFAKEcMBoGCSqGSIb3DQEBCDANBglghkgBZQMEAgEF +AKIDAgEgMA8xDTALBgNVBAMMBFRlc3QwHhcNMjQwMjA2MDMwNjM1WhcNMzQwMjAz +MDMwNjM1WjAPMQ0wCwYDVQQDDARUZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A +MIIBCgKCAQEAtk22hPAmTxSTSs8MUJInf7N6byDo1LlEgw5juF8y1bVxhoF0U4Ug +u0zqCVtar/JBPmcVofM4IU4+GoIRfI9qyyyD5EQup2e8exUn/Bku+7XTmlCSKfUI +T4u/zpe/qJCyRwT6pLP4POtoqsmrRf+u7zVvS7VHafPioxLLrOIbB750AYmi7y/n +h8MreJHrQ901IQV4Ktf2QgaFrjJFgXD307iTGoiRt+UxkmGsOOzFt+N91lM30ad+ +sCgmc1NVVyo6p4RByl7ilxlQGCATOQ9wTVwehgmtFGpU0denhqViNUU8yuPZ3pTD +w1o9uWTAKdUuMySSUiKmmlE+qnlFfR9uPwIDAQABo1MwUTAdBgNVHQ4EFgQUQPus +AuQ9cNE9E2+vZXKtKAtfDIUwHwYDVR0jBBgwFoAUQPusAuQ9cNE9E2+vZXKtKAtf +DIUwDwYDVR0TAQH/BAUwAwEB/zBBBgkqhkiG9w0BAQowNKAPMA0GCWCGSAFlAwQC +AQUAoRwwGgYJKoZIhvcNAQEIMA0GCWCGSAFlAwQCAQUAogMCASADggEBAGpIH7ic +GwD2vzTGgFhHrh4NkGu9OwI8WA342DKfJq0Cx+BjaFsglhjLVkbqP74XjgQUSqt+ +yp09xgrZdIP8yMJr7mjqQpV7tolB1yrD0h0jtoMe0Pc1+wVwjkMQjsewwSDJvV9O +RjXqmzoIjUAXmASk5JdZ5oDBK6bg7m8/hJyEJnWdOuiVUJTyPz+Y1/6rpzwH/+xX +x3sO6OaWMSIc/ovF1Y7kQ4mwgPjLuq1X8Dx7xM9rcJak5cGAwUwQqvOaD3y9ZQzg +E+kH4mtWw29xRTejbiMSbnbfR8LfZdS2+10ESK66SXChVz3Q7shkR9Gs6kTJiXTu +FUtRtO0G5aoSHeA= +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha256_mgf1_sha384_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha256_mgf1_sha384_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..2142987be1869058ed5f6fd23dd296bc52361997 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha256_mgf1_sha384_cert.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDZzCCAhugAwIBAgIUVvhEAv0+q7jndH6xf2RJjaiaIVswQQYJKoZIhvcNAQEK +MDSgDzANBglghkgBZQMEAgEFAKEcMBoGCSqGSIb3DQEBCDANBglghkgBZQMEAgIF +AKIDAgEgMA8xDTALBgNVBAMMBFRlc3QwHhcNMjQwMjA2MDMwNjM2WhcNMzQwMjAz +MDMwNjM2WjAPMQ0wCwYDVQQDDARUZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A +MIIBCgKCAQEAsC6mgspqVdpZrhHUz5zoY4Sklg+spYAz8axxEyJf3Tdg427ildSH +BLi62qZ+gTXLHgUvdkMWEv8NWODHY5DNuTiL65LjV0gN7eIzVbzc0alTdbp+nc7H +HHZHBedD3CRT4LHqlK9LVTYcQk8qNtnKJ7vxNJHN3vpmr0zxxJf3nle7Ymnx2FiK +mXDu3vQEDSU6eyOu5dk0IsEWlMOCYu5w8dpbdGaE4az3IaHXsDnmfLfIWUaILQxw +Mj0UhNg+vnZsanB7CWiLZOIawEpa6dx2Zcasyi8V6lZV1sxYQrskRbAj9uGtDmtd +kTKeCxtj7Bgj9e6aIN2rh7keH5+pqissxwIDAQABo1MwUTAdBgNVHQ4EFgQUpXlx +cN8y7RSFQjPjO3Kb1x0GWcYwHwYDVR0jBBgwFoAUpXlxcN8y7RSFQjPjO3Kb1x0G +WcYwDwYDVR0TAQH/BAUwAwEB/zBBBgkqhkiG9w0BAQowNKAPMA0GCWCGSAFlAwQC +AQUAoRwwGgYJKoZIhvcNAQEIMA0GCWCGSAFlAwQCAgUAogMCASADggEBAKcp+pEt +hei70aV9+j+p/cjChDSqQyipIvyqt0wdHiM/5WwGO4LnR/JxWqHHGtlQjgphKVpV +bjRMBivrbb//LNb0cx5z3o9hx2H6ITwpwrRA9dvfE1C+hOBbxhUYNtk4jpH1DneX +8l/A9Lm6kmZ02KrJok8VEGthtZqypkRAQFxStY2EuopzWVzdceJYa4AOB26r7F0T +Z5BzO/Piy39lQtZGyMZ2R71ppEDWXVrSaqxV64aFnh3/2aCgFUzuV2FYr1NZ+zQu +EBJZIdd0IvhcgHkiUD6qtlYNJ1H7Jf9hSRDM7d7AblhgxVB1eRU+7Ve1o47LfQqz +iVybceMUSCyMFLk= +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha384_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha384_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..52fadb9d031a974d0bc1584903acb64948536618 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha384_cert.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDZzCCAhugAwIBAgIUI7KZPJ4nCR/qFZWD2bagetWGJRQwQQYJKoZIhvcNAQEK +MDSgDzANBglghkgBZQMEAgIFAKEcMBoGCSqGSIb3DQEBCDANBglghkgBZQMEAgIF +AKIDAgEwMA8xDTALBgNVBAMMBFRlc3QwHhcNMjQwMjA2MDMwNjM2WhcNMzQwMjAz +MDMwNjM2WjAPMQ0wCwYDVQQDDARUZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A +MIIBCgKCAQEA3/WFdrzn9QQjowwZqCmgIJcCWy+8aIjHLlE4OLWyv4rVAdQluFRA +Af1lsKY+ZD6gvWOKhnSNT7z4WfH03vUNpkqOt1kqtjMsuRsy4Zh2n54LYM2IHkVh ++oZpq8dBESkffAHOLwkl6Be/iZE3t4Z2hdrzhFEt1iGxtfwduIcku/geciLKM0D0 +1UHtVzb0762hx94IX506vxAdvNAK48gTSobBBWQJhHz2a2tvt2ON3eRian41qwxW +Nsl7OUyss6PmVXYS3JbmZgyzT0nSHQWEVlEcQOI3UxjNqeK2HMyMDYLgIvVD+IER +1nMT4AUyWDGkRR6bFITS2BmW7JbxQ40ZiwIDAQABo1MwUTAdBgNVHQ4EFgQUn9rP +CfGH3OFxdNXCFbAQrYlgXd4wHwYDVR0jBBgwFoAUn9rPCfGH3OFxdNXCFbAQrYlg +Xd4wDwYDVR0TAQH/BAUwAwEB/zBBBgkqhkiG9w0BAQowNKAPMA0GCWCGSAFlAwQC +AgUAoRwwGgYJKoZIhvcNAQEIMA0GCWCGSAFlAwQCAgUAogMCATADggEBADJ6+6Us +KXbcpyzapxqQGr0rGkGOPf45Vo2EY0H2A0YY9CHYrU/jq2xijHgnw89I3z9Z3h4q +kSD51Rr/3V/e5ffcYwRabC6S515anOgxtCE4cgHEqgIdzrwD3EFGm74D+MnJRTy8 +UpE5pZTaHNRno80rz1kRYN2MHO/sHqQCpFoZ8SI3+Nik5m3FSe2Umb3FLTvrOAcm +biGgj4cF52w1D7XAAo/3bAH9Rt0/FRK46nULoEX54RJHlFN8f3kzBucNNfoHNPBR +2lMQJM1VzpPkjR5rLOwAYKEfvIvwDVEgDMpD4+P5/FMX/fnSm4kVaiZMwLLrtJlX +pS9N0mDlr4wk9hw= +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha512_cert.pem b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha512_cert.pem new file mode 100644 index 0000000000000000000000000000000000000000..85a3694c37100836a12f02086b8f99b42d887eee --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/crypto/test/rsa_pss_sha512_cert.pem @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDZzCCAhugAwIBAgIUCJHdINzBcxL45k+BWvKYcpH8vzQwQQYJKoZIhvcNAQEK +MDSgDzANBglghkgBZQMEAgMFAKEcMBoGCSqGSIb3DQEBCDANBglghkgBZQMEAgMF +AKIDAgFAMA8xDTALBgNVBAMMBFRlc3QwHhcNMjQwMjA2MDMwNjM2WhcNMzQwMjAz +MDMwNjM2WjAPMQ0wCwYDVQQDDARUZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A +MIIBCgKCAQEA6jzuBGtb+D/0ZWRqZAcZh6bkClCbHdiz1yOPuh4APfyfsFGDSRBt +ArMH+l2/Mr7TXeAfdDHX//bNBclPzu0mKWtVamh7s3WWoPBX+r10ie94YxErFY+6 +Po5pGDnSabVawdnXd5FqCdFVpmXP12Ii9qKuRD13XAPJML0Cz9z4pOL0ioWvvUqn +MyWwa8zT8pfK4AJe4XGilQ2uxwJV922XQxv6rY8aOFuwozkNa0/ceN1A2EKIwShB +P3/3Z+9maz4YMg/VgmJfEY/xekawDZ7MC8CY9G/alE1YqHERvR5BwekrnFHSErM4 +ArSUJnavXm7rdB1OCp4kAKXkLvu2H/8AMQIDAQABo1MwUTAdBgNVHQ4EFgQUrLTl +C9kRXzElbsDUCc/ePO75qNkwHwYDVR0jBBgwFoAUrLTlC9kRXzElbsDUCc/ePO75 +qNkwDwYDVR0TAQH/BAUwAwEB/zBBBgkqhkiG9w0BAQowNKAPMA0GCWCGSAFlAwQC +AwUAoRwwGgYJKoZIhvcNAQEIMA0GCWCGSAFlAwQCAwUAogMCAUADggEBAGMyu2fZ +NpvIJQxXPSfhgf8idvGwu7YFdZ/Ct0/HIHJ1h+j2WFwubr/Rcwqu+u6Nq09oMq+H +5EWDtOona78WIQ/RrIs6ltVJBDpirIGjra0IKpYGqYHUEj00u1OZkiQzmMLRT80W +jEe38fATXbpmLhXA8bqlOHuMot2OTWzKEtST4knAAYUCFPIS94mODR4faeqDBwIB +JpYBj2sRwZDU4QbERvLTQMD27kE2ynF4duI4NB6k9w3fJSe60ki5m4avYmiQgj5/ +304UD/AEf+xlMCLh3R8ZGST10zV5M1Wm7czuQ0AKsv45pSltDvWl52OjL3W5CLAJ +iu1eLWBVbFPTK68= +-----END CERTIFICATE----- diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/FreeRDP.ico.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/FreeRDP.ico.c new file mode 100644 index 0000000000000000000000000000000000000000..aab0c41954650465579bda72f22c74507e0be636 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/FreeRDP.ico.c @@ -0,0 +1,458 @@ +#include "FreeRDP.ico.h" + +const unsigned char resources_FreeRDP_ico[] = { + 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x32, 0x1c, + 0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, + 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x06, + 0x00, 0x00, 0x00, 0x5c, 0x72, 0xa8, 0x66, 0x00, 0x00, 0x1b, 0xf9, 0x49, 0x44, 0x41, 0x54, 0x78, + 0xda, 0xed, 0xdd, 0x6f, 0x6c, 0x14, 0xe7, 0x9d, 0x07, 0xf0, 0x6f, 0x0c, 0x78, 0x6d, 0xcc, 0xe2, + 0x01, 0x83, 0x63, 0x5b, 0x38, 0x1e, 0x9a, 0x60, 0x72, 0x05, 0xea, 0x05, 0x5a, 0xe4, 0x52, 0x09, + 0x96, 0x9e, 0x9a, 0xca, 0x70, 0x4d, 0x8d, 0x7a, 0x49, 0xa9, 0x4e, 0xbe, 0x18, 0x89, 0xbc, 0x48, + 0x93, 0x55, 0xa0, 0xd0, 0xaa, 0x2f, 0x92, 0x90, 0xa4, 0x48, 0x77, 0xad, 0x40, 0xa4, 0x72, 0x68, + 0xa4, 0x96, 0xca, 0xe4, 0x56, 0xba, 0xd0, 0x5c, 0x2b, 0x53, 0x52, 0xb3, 0x4a, 0x4f, 0xed, 0x1a, + 0x4b, 0xc0, 0x8a, 0x62, 0xbc, 0xe6, 0x8f, 0xe2, 0x3f, 0xd1, 0x79, 0x89, 0x25, 0x6c, 0x99, 0x58, + 0x59, 0x77, 0x21, 0xb1, 0x9d, 0x2a, 0xbe, 0x17, 0x3b, 0x6b, 0x6c, 0xb3, 0x3b, 0x3b, 0x3b, 0x3b, + 0x33, 0xbf, 0x79, 0x66, 0x7e, 0x9f, 0x57, 0x80, 0xbd, 0xeb, 0xdf, 0x2c, 0x7e, 0xbe, 0xf3, 0x3c, + 0xcf, 0x3c, 0xf3, 0xcc, 0x43, 0x60, 0xae, 0xb4, 0xf3, 0x58, 0x50, 0x06, 0xe0, 0x07, 0x20, 0x03, + 0xa8, 0x03, 0x20, 0xcd, 0xfa, 0x72, 0x1c, 0x40, 0x0f, 0x80, 0x8e, 0x73, 0x07, 0x9b, 0x3a, 0xa8, + 0x6b, 0x65, 0xe6, 0x79, 0x88, 0xba, 0x00, 0x66, 0x1d, 0xa5, 0xd1, 0x37, 0x03, 0x78, 0x06, 0xc9, + 0x86, 0xaf, 0x45, 0x0c, 0xc0, 0x2f, 0xcf, 0x1d, 0x6c, 0x7a, 0x83, 0xba, 0x7e, 0x66, 0x3c, 0x0e, + 0x00, 0x17, 0x50, 0x1a, 0xfe, 0x61, 0x24, 0x1b, 0xbf, 0x5e, 0x67, 0xce, 0x1d, 0x6c, 0xda, 0x4d, + 0x7d, 0x2c, 0xcc, 0x58, 0x1c, 0x00, 0x0e, 0x66, 0x50, 0xc3, 0x9f, 0xed, 0xd4, 0xb9, 0x83, 0x4d, + 0x7b, 0xa9, 0x8f, 0x8b, 0x19, 0x87, 0x03, 0xc0, 0xa1, 0x76, 0x1e, 0x0b, 0xbe, 0x0a, 0xe0, 0x45, + 0xcc, 0x1d, 0xdb, 0x1b, 0x61, 0x07, 0xcf, 0x0b, 0x38, 0xc7, 0x42, 0xea, 0x02, 0x98, 0xb1, 0x76, + 0x1e, 0x0b, 0xfa, 0x00, 0xb4, 0x02, 0xf0, 0x99, 0xf4, 0x23, 0x5e, 0x04, 0xd0, 0x41, 0x7d, 0x9c, + 0xcc, 0x18, 0x05, 0xd4, 0x05, 0x30, 0xe3, 0x28, 0x67, 0xfd, 0x6e, 0x98, 0xd7, 0xf8, 0x81, 0xe4, + 0x95, 0x03, 0xe6, 0x10, 0x3c, 0x04, 0x70, 0x80, 0x9d, 0xc7, 0x82, 0x12, 0x80, 0x36, 0x58, 0xd7, + 0x38, 0x37, 0x9e, 0x3b, 0xd8, 0x14, 0xa5, 0x3e, 0x6e, 0x96, 0x3f, 0x1e, 0x02, 0x08, 0x4e, 0xe9, + 0xf2, 0x87, 0x61, 0xfc, 0x58, 0x5f, 0x8d, 0x95, 0x3f, 0x8b, 0x99, 0x88, 0x87, 0x00, 0x02, 0xdb, + 0x79, 0x2c, 0xd8, 0x8c, 0x64, 0x97, 0x5f, 0xa2, 0xae, 0x85, 0x89, 0x89, 0x03, 0x40, 0x50, 0x3b, + 0x8f, 0x05, 0x8f, 0x23, 0x39, 0xd9, 0xc7, 0x98, 0x6e, 0x3c, 0x04, 0x10, 0xd0, 0xce, 0x63, 0xc1, + 0x56, 0x18, 0x77, 0x6d, 0x9f, 0xb9, 0x18, 0x07, 0x80, 0x40, 0x94, 0xc9, 0xbe, 0x30, 0xcc, 0x9d, + 0xe5, 0x67, 0x2e, 0xc2, 0x43, 0x00, 0x41, 0xd8, 0xac, 0xf1, 0xc7, 0xa8, 0x0b, 0x60, 0xc6, 0xe0, + 0xcb, 0x80, 0x02, 0xb0, 0x59, 0xe3, 0xc7, 0xb9, 0x83, 0x4d, 0xfc, 0x7b, 0xe3, 0x10, 0xdc, 0x03, + 0xb0, 0x39, 0xbb, 0x35, 0x7e, 0xf0, 0x2a, 0x40, 0x47, 0xe1, 0x00, 0xb0, 0x31, 0x1b, 0x36, 0x7e, + 0x00, 0x88, 0x52, 0x17, 0xc0, 0x8c, 0xc3, 0x01, 0x60, 0x53, 0x36, 0x6d, 0xfc, 0x40, 0x72, 0xa3, + 0x10, 0xe6, 0x10, 0x1c, 0x00, 0x36, 0x64, 0xe3, 0xc6, 0x0f, 0xf0, 0x10, 0xc0, 0x51, 0x38, 0x00, + 0x6c, 0xc6, 0xe6, 0x8d, 0x3f, 0x7a, 0xee, 0x60, 0x53, 0x8c, 0xba, 0x08, 0x66, 0x1c, 0x0e, 0x00, + 0x1b, 0xb1, 0x79, 0xe3, 0x07, 0xf8, 0xec, 0xef, 0x38, 0x1c, 0x00, 0xf6, 0x62, 0xe6, 0x7d, 0xfc, + 0x46, 0x78, 0x9b, 0xba, 0x00, 0x66, 0x2c, 0x0e, 0x00, 0x9b, 0x50, 0x96, 0xf7, 0x36, 0x52, 0xd7, + 0xa1, 0x22, 0xc6, 0xb7, 0x00, 0x3b, 0x0f, 0x07, 0x80, 0x0d, 0x28, 0x37, 0xf6, 0x34, 0x53, 0xd7, + 0x91, 0xc5, 0x19, 0xea, 0x02, 0x98, 0xf1, 0x38, 0x00, 0x88, 0x29, 0xb7, 0xf4, 0xee, 0xa7, 0xae, + 0x43, 0x03, 0xee, 0xfe, 0x3b, 0x10, 0x2f, 0xe9, 0x24, 0xb4, 0xf3, 0x58, 0xb0, 0x11, 0xc9, 0x9d, + 0x7c, 0xec, 0x2e, 0x76, 0xee, 0x60, 0xd3, 0x6a, 0xea, 0x22, 0x98, 0xf1, 0xb8, 0x07, 0x40, 0x64, + 0xd6, 0xe6, 0x9d, 0x22, 0xf8, 0x25, 0x75, 0x01, 0xcc, 0x1c, 0x1c, 0x00, 0x04, 0x66, 0xed, 0xe1, + 0x27, 0x51, 0xd7, 0xa2, 0xd1, 0x29, 0xea, 0x02, 0x98, 0x39, 0x38, 0x00, 0x68, 0x84, 0xa1, 0xfd, + 0xd1, 0x5c, 0xd4, 0x4e, 0x9d, 0x3b, 0xd8, 0x14, 0xa7, 0x2e, 0x82, 0x99, 0x83, 0x03, 0xc0, 0x62, + 0xca, 0xe5, 0x3e, 0x1f, 0x75, 0x1d, 0x39, 0xe0, 0xc9, 0x3f, 0x07, 0xe3, 0x49, 0x40, 0x0b, 0xed, + 0x3c, 0x16, 0xdc, 0x0f, 0xe0, 0x38, 0x75, 0x1d, 0x39, 0xe0, 0xc9, 0x3f, 0x87, 0xe3, 0x1e, 0x80, + 0x45, 0x76, 0x1e, 0x0b, 0xfa, 0x21, 0x56, 0xe3, 0x07, 0x80, 0xd7, 0xa8, 0x0b, 0x60, 0xe6, 0xe2, + 0x00, 0xb0, 0x80, 0xf2, 0x90, 0x4e, 0x11, 0x2e, 0xf7, 0xcd, 0x16, 0x07, 0x2f, 0xfe, 0x71, 0x3c, + 0x0e, 0x00, 0x6b, 0x88, 0x34, 0xe3, 0x9f, 0xf2, 0x4b, 0x9e, 0xfc, 0x73, 0x3e, 0x0e, 0x00, 0x93, + 0x09, 0x38, 0xe9, 0x97, 0xf2, 0x06, 0x75, 0x01, 0xcc, 0x7c, 0x1c, 0x00, 0x26, 0x52, 0x96, 0xf9, + 0x36, 0x53, 0xd7, 0xa1, 0x03, 0x5f, 0xfa, 0x73, 0x09, 0x0e, 0x00, 0x93, 0x28, 0x2b, 0xfd, 0x44, + 0x9b, 0xf4, 0x4b, 0xe1, 0x95, 0x7f, 0x2e, 0xc1, 0x01, 0x60, 0x02, 0x65, 0xa5, 0x5f, 0x2b, 0xc4, + 0x1b, 0xf7, 0x03, 0xc9, 0x5d, 0x7f, 0xa2, 0xd4, 0x45, 0x30, 0x6b, 0x70, 0x00, 0x98, 0xe3, 0x38, + 0xc4, 0x1c, 0xf7, 0x03, 0x7c, 0xf6, 0x77, 0x15, 0x0e, 0x00, 0x83, 0x09, 0x3c, 0xee, 0x4f, 0x39, + 0x43, 0x5d, 0x00, 0xb3, 0x0e, 0x07, 0x80, 0x81, 0x94, 0xeb, 0xfd, 0xa2, 0x8e, 0xfb, 0x01, 0xe0, + 0x0c, 0x4f, 0xfe, 0xb9, 0x0b, 0x07, 0x80, 0xb1, 0x44, 0xbc, 0xde, 0x3f, 0x1b, 0xaf, 0xfb, 0x77, + 0x19, 0x0e, 0x00, 0x83, 0x28, 0xdb, 0x7a, 0xf9, 0xa8, 0xeb, 0xc8, 0x53, 0x07, 0x75, 0x01, 0xcc, + 0x5a, 0x1c, 0x00, 0x06, 0x50, 0xd6, 0xf9, 0xef, 0xa7, 0xae, 0x23, 0x4f, 0xdc, 0xfd, 0x77, 0x21, + 0x0e, 0x80, 0x3c, 0xcd, 0xda, 0xdc, 0x43, 0x74, 0x7f, 0xa4, 0x2e, 0x80, 0x59, 0x8f, 0x03, 0x20, + 0x7f, 0xa2, 0x5e, 0xef, 0x9f, 0xaf, 0x83, 0xba, 0x00, 0x66, 0x3d, 0x0e, 0x80, 0x3c, 0x28, 0x97, + 0xfc, 0x1a, 0xa9, 0xeb, 0x30, 0x00, 0x3f, 0xf2, 0xcb, 0xa5, 0x38, 0x00, 0x74, 0x72, 0xc0, 0x25, + 0xbf, 0xd9, 0x3a, 0xa8, 0x0b, 0x60, 0x34, 0x38, 0x00, 0xf4, 0x73, 0x4a, 0xd7, 0x1f, 0x00, 0xce, + 0x53, 0x17, 0xc0, 0x68, 0x70, 0x00, 0xe8, 0xa0, 0x6c, 0xed, 0xe5, 0xa7, 0xae, 0xc3, 0x40, 0x1d, + 0xd4, 0x05, 0x30, 0x1a, 0xbc, 0x27, 0x60, 0x8e, 0x94, 0xae, 0x7f, 0x37, 0x9c, 0x73, 0xf6, 0x8f, + 0x9e, 0x3b, 0xd8, 0xb4, 0x91, 0xba, 0x08, 0x46, 0x83, 0x7b, 0x00, 0xb9, 0x73, 0x52, 0xd7, 0x1f, + 0xe0, 0xb3, 0xbf, 0xab, 0x71, 0x00, 0xe4, 0xc0, 0x81, 0x5d, 0x7f, 0x80, 0xc7, 0xff, 0xae, 0xc6, + 0x01, 0xa0, 0x91, 0xd2, 0xf5, 0x3f, 0x4c, 0x5d, 0x87, 0x09, 0xa2, 0xd4, 0x05, 0x30, 0x3a, 0x1c, + 0x00, 0xda, 0x39, 0xad, 0xeb, 0x0f, 0x24, 0xf7, 0xfd, 0x8f, 0x51, 0x17, 0xc1, 0xe8, 0x70, 0x00, + 0x68, 0xa0, 0x2c, 0xf8, 0xf1, 0x53, 0xd7, 0x61, 0x82, 0x28, 0x75, 0x01, 0x8c, 0x16, 0x07, 0x40, + 0x16, 0xca, 0x5a, 0x7f, 0xa7, 0x2c, 0xf8, 0x99, 0xaf, 0x87, 0xba, 0x00, 0x46, 0x8b, 0x03, 0x20, + 0x3b, 0x27, 0x76, 0xfd, 0x53, 0x3a, 0xa8, 0x0b, 0x60, 0xb4, 0x38, 0x00, 0x54, 0x28, 0xb7, 0xf9, + 0x36, 0x52, 0xd7, 0x61, 0xa2, 0x28, 0x75, 0x01, 0x8c, 0x16, 0x2f, 0x04, 0xca, 0x40, 0xe9, 0xfa, + 0x77, 0x43, 0x9c, 0xc7, 0x78, 0xe7, 0x2a, 0x7e, 0xee, 0x60, 0xd3, 0x32, 0xea, 0x22, 0x18, 0x2d, + 0xee, 0x01, 0x64, 0xb6, 0x1f, 0xce, 0x6d, 0xfc, 0x00, 0x9f, 0xfd, 0x19, 0x38, 0x00, 0xd2, 0x52, + 0x1e, 0xea, 0xe1, 0xc4, 0x6b, 0xfe, 0xb3, 0x45, 0xa9, 0x0b, 0x60, 0xf4, 0x38, 0x00, 0xd2, 0x73, + 0xea, 0xac, 0xff, 0x6c, 0xb7, 0xa8, 0x0b, 0x60, 0xf4, 0x38, 0x00, 0xe6, 0x71, 0xf0, 0x35, 0xff, + 0xf9, 0xa2, 0xd4, 0x05, 0x30, 0x7a, 0x1c, 0x00, 0xb3, 0x38, 0xfc, 0x9a, 0xff, 0x7c, 0x51, 0xea, + 0x02, 0x18, 0xbd, 0x85, 0xd4, 0x05, 0xd8, 0xcc, 0x61, 0x38, 0xf7, 0x9a, 0xff, 0x1c, 0x8f, 0x7e, + 0x79, 0x4d, 0x5b, 0x20, 0x14, 0x49, 0xfd, 0xf5, 0x3c, 0x80, 0x37, 0x5a, 0x1a, 0xea, 0xe3, 0xd4, + 0x75, 0x31, 0x6b, 0xf1, 0x65, 0x40, 0x85, 0x32, 0xf1, 0xd7, 0x4d, 0x5d, 0x87, 0x15, 0x8a, 0x4b, + 0x8a, 0x51, 0x55, 0xb3, 0x6a, 0xfe, 0x3f, 0xc7, 0x01, 0x1c, 0x68, 0x69, 0xa8, 0x3f, 0x45, 0x5d, + 0x1f, 0xb3, 0x0e, 0x0f, 0x01, 0xee, 0x73, 0x4b, 0xd7, 0x1f, 0x05, 0x05, 0x0b, 0xd2, 0xfd, 0xb3, + 0x04, 0xa0, 0x35, 0x10, 0x8a, 0x34, 0x52, 0xd7, 0xc7, 0xac, 0xc3, 0x01, 0x00, 0x60, 0xe7, 0xb1, + 0x60, 0x23, 0xdc, 0x31, 0xf1, 0x07, 0x00, 0xf0, 0x14, 0x79, 0xd4, 0xbe, 0xdc, 0x1a, 0x08, 0x45, + 0x24, 0xea, 0x1a, 0x99, 0x35, 0x38, 0x00, 0x92, 0x5c, 0x73, 0xf6, 0x07, 0x80, 0x82, 0x05, 0xaa, + 0xff, 0xed, 0x12, 0xc4, 0x7f, 0xca, 0x11, 0xd3, 0xc8, 0xf5, 0x01, 0xb0, 0xf3, 0x58, 0xf0, 0x55, + 0x38, 0x7b, 0xc5, 0xdf, 0x03, 0x0a, 0xd5, 0x7b, 0x00, 0x00, 0xf0, 0x62, 0x20, 0x14, 0x91, 0xa9, + 0xeb, 0x64, 0xe6, 0x73, 0x75, 0x00, 0x28, 0x97, 0xfd, 0x5e, 0xa4, 0xae, 0xc3, 0x6a, 0x05, 0x05, + 0x59, 0xff, 0xdb, 0x25, 0x38, 0x7f, 0x25, 0x24, 0x83, 0xcb, 0x03, 0x00, 0xc9, 0xae, 0xbf, 0x44, + 0x5d, 0x84, 0xd5, 0x3c, 0xd9, 0x7b, 0x00, 0x00, 0xd0, 0xcc, 0xbd, 0x00, 0xe7, 0x73, 0x6d, 0x00, + 0x28, 0x7b, 0xfc, 0x35, 0x53, 0xd7, 0x61, 0x73, 0xad, 0xd4, 0x05, 0x30, 0x73, 0xb9, 0x36, 0x00, + 0xe0, 0xd2, 0x5f, 0x6e, 0x8d, 0x67, 0xff, 0x14, 0x7f, 0x20, 0x14, 0xf1, 0x53, 0xd7, 0xcc, 0xcc, + 0xe3, 0xca, 0x00, 0x50, 0x36, 0xfa, 0xf0, 0x53, 0xd7, 0x41, 0x21, 0xcb, 0x15, 0x80, 0x74, 0x5c, + 0x19, 0x94, 0x6e, 0xe1, 0xca, 0x00, 0x80, 0x8b, 0x27, 0xb8, 0x32, 0x2c, 0x02, 0x52, 0x23, 0x07, + 0x42, 0x91, 0x57, 0xa9, 0xeb, 0x66, 0xe6, 0x70, 0x5d, 0x00, 0xb8, 0x6d, 0xd1, 0xcf, 0x83, 0xa6, + 0xf5, 0xbc, 0xe8, 0x45, 0x5e, 0x1c, 0xe4, 0x4c, 0xae, 0x0b, 0x00, 0xb8, 0x6c, 0xd1, 0xcf, 0x7c, + 0xd7, 0x23, 0x5d, 0x48, 0xc4, 0xc7, 0x73, 0x7d, 0x99, 0x04, 0x97, 0x7f, 0x6e, 0x4e, 0xe5, 0xaa, + 0x00, 0x50, 0xee, 0xf5, 0x97, 0xa9, 0xeb, 0xa0, 0xf4, 0x8f, 0xa9, 0xcf, 0xd1, 0xd1, 0x16, 0xd2, + 0xf3, 0xd2, 0x66, 0x9e, 0x10, 0x74, 0x1e, 0x57, 0x05, 0x00, 0x5c, 0x3c, 0xf6, 0x4f, 0x49, 0xc4, + 0xc7, 0x71, 0x3b, 0x36, 0x84, 0xeb, 0x91, 0x2e, 0x3d, 0x2f, 0xe7, 0x5e, 0x80, 0xc3, 0xb8, 0x26, + 0x00, 0xf8, 0xec, 0x3f, 0xd7, 0x95, 0xf0, 0x05, 0x3d, 0x43, 0x01, 0x5f, 0x20, 0x14, 0xd9, 0x4f, + 0x5d, 0x3b, 0x33, 0x8e, 0x6b, 0x02, 0x00, 0x7c, 0xf6, 0x9f, 0x63, 0x6a, 0x62, 0x52, 0xef, 0x50, + 0xe0, 0x30, 0x4f, 0x08, 0x3a, 0x87, 0x2b, 0x02, 0x80, 0xcf, 0xfe, 0xf7, 0x25, 0x3e, 0xb9, 0x7f, + 0xd6, 0xbf, 0x1d, 0x1b, 0x42, 0xac, 0x77, 0x20, 0xd7, 0xb7, 0x90, 0xc0, 0x43, 0x01, 0xc7, 0x70, + 0x45, 0x00, 0x80, 0xcf, 0xfe, 0x33, 0xfe, 0xf1, 0xf9, 0xe7, 0x73, 0xfe, 0x1e, 0x6e, 0x0b, 0x61, + 0x6a, 0x62, 0x32, 0xd7, 0xb7, 0xe1, 0x09, 0x41, 0x87, 0x70, 0x7c, 0x00, 0xf0, 0xd9, 0x5f, 0xdd, + 0xd4, 0xc4, 0x24, 0x2e, 0x86, 0xfe, 0xaa, 0xe7, 0xa5, 0xbc, 0x42, 0xd0, 0x01, 0x1c, 0x1f, 0x00, + 0xe0, 0xb3, 0x7f, 0x56, 0x7d, 0xd1, 0x1b, 0xb8, 0x1d, 0x1b, 0xca, 0xf5, 0x65, 0xbc, 0x42, 0xd0, + 0x01, 0x1c, 0x1d, 0x00, 0x7c, 0xf6, 0xd7, 0xae, 0x43, 0xdf, 0x50, 0x80, 0x37, 0x0e, 0x11, 0x9c, + 0xa3, 0x03, 0x00, 0x7c, 0xf6, 0x9f, 0x43, 0xed, 0xb2, 0x5f, 0x22, 0x3e, 0xae, 0x67, 0x6d, 0x80, + 0x04, 0x9e, 0x10, 0x14, 0x9a, 0x63, 0x03, 0x40, 0xb9, 0xe3, 0x4f, 0xa6, 0xae, 0xc3, 0x4e, 0xfe, + 0x31, 0xf5, 0xb9, 0xea, 0xd7, 0xaf, 0x84, 0x2f, 0x60, 0x6c, 0x64, 0x34, 0xd7, 0xb7, 0x6d, 0xe4, + 0x9d, 0x84, 0xc5, 0xe5, 0xd8, 0x00, 0x00, 0x9f, 0xfd, 0x75, 0xd1, 0x39, 0x21, 0x78, 0x9c, 0xd7, + 0x06, 0x88, 0xc9, 0x91, 0x01, 0xa0, 0x3c, 0xe4, 0xc3, 0x4f, 0x5d, 0x87, 0x88, 0x74, 0x2e, 0x13, + 0x96, 0xc1, 0x3b, 0x09, 0x0b, 0xc9, 0x91, 0x01, 0x00, 0x17, 0x6e, 0xf4, 0x69, 0xa4, 0x2b, 0xe1, + 0x0b, 0x7a, 0x26, 0x04, 0x0f, 0x07, 0x42, 0x11, 0x1f, 0x75, 0xed, 0x2c, 0x37, 0x8e, 0x0b, 0x00, + 0xde, 0xeb, 0x2f, 0x7f, 0x53, 0x13, 0x93, 0x08, 0xeb, 0x5b, 0x26, 0xcc, 0x13, 0x82, 0x82, 0x71, + 0x5c, 0x00, 0x80, 0x1b, 0xbf, 0x21, 0x62, 0xbd, 0x03, 0x7a, 0xd6, 0x06, 0xf8, 0x03, 0xa1, 0x48, + 0x33, 0x75, 0xed, 0x4c, 0x3b, 0x27, 0x06, 0xc0, 0x33, 0xd4, 0x05, 0x38, 0x85, 0xce, 0x9b, 0x85, + 0x78, 0x42, 0x50, 0x20, 0x8e, 0x0a, 0x00, 0x5e, 0xf8, 0x63, 0xac, 0x44, 0x7c, 0x1c, 0x5d, 0x1d, + 0x17, 0x73, 0x7d, 0x99, 0x04, 0x1e, 0x0a, 0x08, 0xc3, 0x51, 0x01, 0x00, 0x3e, 0xfb, 0x1b, 0xee, + 0xda, 0xa5, 0x2b, 0x7a, 0xf6, 0x0d, 0xe0, 0x9b, 0x85, 0x04, 0xe1, 0x98, 0x00, 0x50, 0x26, 0xff, + 0xfc, 0xd4, 0x75, 0x38, 0x4d, 0x1e, 0xfb, 0x06, 0x70, 0x2f, 0x40, 0x00, 0x8e, 0x09, 0x00, 0xf0, + 0xe4, 0x9f, 0x69, 0x6e, 0xc7, 0x86, 0xf4, 0x4c, 0x08, 0xfa, 0xf8, 0x66, 0x21, 0xfb, 0x73, 0x52, + 0x00, 0x70, 0xf7, 0xdf, 0x44, 0x3a, 0x7b, 0x01, 0x7c, 0xb3, 0x90, 0xcd, 0x39, 0x22, 0x00, 0x78, + 0xdd, 0xbf, 0xf9, 0xf2, 0x98, 0x10, 0xe4, 0x7d, 0x03, 0x6c, 0xcc, 0x11, 0x01, 0x00, 0x3e, 0xfb, + 0x5b, 0xe2, 0xda, 0xa5, 0x2b, 0x7a, 0x56, 0x08, 0xfa, 0xf9, 0x66, 0x21, 0xfb, 0x72, 0x4a, 0x00, + 0x34, 0x52, 0x17, 0xe0, 0x06, 0x79, 0xec, 0x1e, 0xc4, 0x6b, 0x03, 0x6c, 0x4a, 0xf8, 0x00, 0x50, + 0x1e, 0xf5, 0x25, 0x51, 0xd7, 0xe1, 0x16, 0x7d, 0xd1, 0x1b, 0x7a, 0x2e, 0x0b, 0xca, 0xe0, 0x9b, + 0x85, 0x6c, 0x49, 0xf8, 0x00, 0x00, 0xb0, 0x9d, 0xba, 0x00, 0xb7, 0xc9, 0x63, 0x3b, 0x71, 0x99, + 0xba, 0x76, 0x36, 0x97, 0x13, 0x02, 0xa0, 0x91, 0xba, 0x00, 0xb7, 0xd1, 0x79, 0x59, 0x10, 0xe0, + 0x09, 0x41, 0xdb, 0x11, 0x3a, 0x00, 0x94, 0xfb, 0xfe, 0x65, 0xea, 0x3a, 0xdc, 0xa8, 0x2b, 0x7c, + 0x41, 0xcf, 0xcb, 0x78, 0x42, 0xd0, 0x66, 0x84, 0x0e, 0x00, 0xf0, 0xca, 0xbf, 0x9c, 0x2c, 0x2c, + 0x5c, 0x64, 0xd8, 0x7b, 0xdd, 0x8e, 0x0d, 0xe9, 0xd9, 0x3e, 0x0c, 0xe0, 0x09, 0x41, 0x5b, 0x11, + 0x3d, 0x00, 0x78, 0xfc, 0x9f, 0x03, 0xaf, 0x54, 0x6a, 0xe8, 0xfb, 0x5d, 0xbf, 0xa4, 0xeb, 0x01, + 0xa3, 0x32, 0x78, 0x42, 0xd0, 0x36, 0x44, 0x0f, 0x00, 0x3f, 0x75, 0x01, 0x6e, 0xa6, 0xf3, 0x8a, + 0x00, 0x90, 0x5c, 0x21, 0x28, 0x51, 0xd7, 0xcf, 0x04, 0x0e, 0x00, 0x65, 0xfc, 0x2f, 0x51, 0xd7, + 0xe1, 0x76, 0xfd, 0xd1, 0x9b, 0x7a, 0x5e, 0x26, 0x81, 0x7b, 0x01, 0xb6, 0x20, 0x6c, 0x00, 0x00, + 0xf0, 0x51, 0x17, 0xc0, 0x80, 0xbe, 0xee, 0x1b, 0x7a, 0x5f, 0xca, 0xbd, 0x00, 0x1b, 0x10, 0x39, + 0x00, 0x78, 0xfc, 0xaf, 0xc3, 0xc2, 0x45, 0xc6, 0x4d, 0x04, 0x02, 0xc9, 0x7b, 0x04, 0x74, 0x3c, + 0x61, 0x18, 0x48, 0xf6, 0x02, 0x9a, 0xa9, 0x3f, 0x0f, 0xb7, 0x13, 0x39, 0x00, 0x7c, 0xd4, 0x05, + 0x88, 0xc8, 0xbb, 0xcc, 0xd8, 0x89, 0x40, 0x00, 0xe8, 0xeb, 0xd6, 0x35, 0x0c, 0x00, 0x78, 0xf7, + 0x66, 0x72, 0x1c, 0x00, 0x2c, 0x6f, 0xb1, 0xde, 0x01, 0x3d, 0x37, 0x09, 0x01, 0xc9, 0x07, 0x8c, + 0xfa, 0xa9, 0xeb, 0x77, 0x33, 0x21, 0x03, 0x40, 0xb9, 0xfd, 0x97, 0xd9, 0xc8, 0xa0, 0xbe, 0x61, + 0x00, 0xc0, 0x77, 0x72, 0x92, 0x12, 0x32, 0x00, 0xc0, 0xab, 0xff, 0x74, 0x2b, 0x2e, 0x59, 0x6c, + 0xca, 0xfb, 0xc6, 0x3e, 0xf8, 0x50, 0xef, 0x4b, 0x1b, 0xa9, 0x3e, 0x0b, 0x26, 0x6e, 0x00, 0xd4, + 0x51, 0x17, 0x20, 0xaa, 0x22, 0xb3, 0x02, 0x40, 0xff, 0x30, 0x40, 0xe2, 0x61, 0x00, 0x1d, 0x51, + 0x03, 0xc0, 0x47, 0x5d, 0x00, 0x7b, 0x50, 0x1e, 0xc3, 0x80, 0xef, 0x52, 0xd7, 0xee, 0x56, 0xa2, + 0x06, 0x80, 0x4c, 0x5d, 0x80, 0xa8, 0x8a, 0x17, 0x9b, 0xd3, 0x03, 0x00, 0x80, 0xe1, 0x41, 0x5d, + 0x77, 0x08, 0x02, 0xbc, 0xa2, 0x93, 0x0c, 0x07, 0x80, 0xcb, 0x98, 0x35, 0x04, 0x00, 0xf2, 0xea, + 0x01, 0xf8, 0x28, 0x3e, 0x0b, 0x26, 0x60, 0x00, 0xf0, 0x15, 0x00, 0xfb, 0x9a, 0x9a, 0x98, 0xd4, + 0x7b, 0x87, 0x20, 0x78, 0x1e, 0x80, 0x86, 0x70, 0x01, 0x00, 0x5e, 0xff, 0x9f, 0x17, 0x33, 0x16, + 0x02, 0xcd, 0xa6, 0x73, 0xa3, 0x10, 0x80, 0x7b, 0x01, 0x24, 0x44, 0x0c, 0x00, 0x1f, 0x75, 0x01, + 0x22, 0x33, 0x7a, 0x29, 0xf0, 0x7c, 0x63, 0xc3, 0xfa, 0x7a, 0x00, 0x00, 0x6a, 0x2c, 0xff, 0x30, + 0x98, 0x90, 0x01, 0x60, 0xee, 0x29, 0xcc, 0x05, 0xcc, 0x0c, 0x81, 0x8f, 0x75, 0x0e, 0x01, 0xc0, + 0xc1, 0x4e, 0x42, 0xc4, 0x00, 0xf0, 0x51, 0x17, 0x20, 0x3a, 0x33, 0x87, 0x01, 0x7a, 0xe7, 0x00, + 0xc0, 0x43, 0x3b, 0x12, 0x22, 0x06, 0x80, 0x44, 0x5d, 0x00, 0x53, 0xa7, 0x33, 0x04, 0x7c, 0xd4, + 0x75, 0xbb, 0x91, 0x88, 0x01, 0xe0, 0xa3, 0x2e, 0x40, 0x74, 0xcb, 0xca, 0x57, 0x98, 0xfa, 0xfe, + 0x93, 0xfa, 0x56, 0x04, 0x32, 0x02, 0x22, 0x06, 0x00, 0xb3, 0xb9, 0x61, 0xfd, 0x57, 0x02, 0x98, + 0xc5, 0x84, 0x0a, 0x00, 0x5e, 0x03, 0x60, 0x8c, 0x65, 0x2b, 0xcd, 0xed, 0x01, 0x30, 0x71, 0x08, + 0x15, 0x00, 0x8c, 0x31, 0x63, 0x89, 0x16, 0x00, 0x12, 0x75, 0x01, 0x4e, 0x60, 0xf6, 0x1c, 0xc0, + 0xed, 0xc1, 0x8f, 0xa8, 0x0f, 0x91, 0x69, 0x24, 0x5a, 0x00, 0xf8, 0xa8, 0x0b, 0x70, 0x0a, 0xb3, + 0x17, 0x04, 0x31, 0x31, 0x88, 0x16, 0x00, 0xcc, 0x20, 0x66, 0x2f, 0x09, 0x66, 0x62, 0x10, 0x2d, + 0x00, 0xf8, 0xb7, 0xd6, 0x20, 0x66, 0xed, 0x0c, 0xc4, 0xc4, 0xb2, 0x90, 0xba, 0x80, 0x1c, 0xf9, + 0xa8, 0x0b, 0xb0, 0x9b, 0x82, 0x05, 0x05, 0xf0, 0x14, 0x79, 0x50, 0x50, 0xb0, 0x00, 0x9e, 0x22, + 0x0f, 0x00, 0x60, 0xe1, 0xa2, 0x85, 0x0f, 0x3c, 0x07, 0x70, 0xd1, 0xa2, 0x85, 0x73, 0xba, 0xfd, + 0x8f, 0x7e, 0x79, 0x0d, 0x12, 0xf1, 0x71, 0x24, 0xe2, 0x7f, 0x9f, 0xf3, 0x7d, 0x63, 0x23, 0xa3, + 0x33, 0x3b, 0xfb, 0xa4, 0xc6, 0xf2, 0xb9, 0xde, 0xe0, 0xa3, 0xf3, 0x11, 0x64, 0x1d, 0xb4, 0x9f, + 0xa4, 0x3b, 0x89, 0x16, 0x00, 0xae, 0xe5, 0x29, 0xf2, 0x60, 0xe1, 0xa2, 0x45, 0xf0, 0x14, 0x79, + 0x50, 0x58, 0x54, 0x38, 0xf3, 0xe7, 0x7c, 0x78, 0xa5, 0xd2, 0x07, 0x1a, 0x6b, 0x95, 0x5c, 0x3d, + 0xf3, 0xe7, 0xcd, 0xfe, 0xad, 0x33, 0x7f, 0x9e, 0x9a, 0x98, 0xc4, 0xc7, 0x23, 0xa3, 0x18, 0x1b, + 0x19, 0x45, 0xe2, 0x93, 0x71, 0x8c, 0x8d, 0x8c, 0x66, 0x0c, 0x06, 0x9d, 0xc3, 0x8b, 0xb8, 0x55, + 0x9f, 0x25, 0xbb, 0x8f, 0x03, 0xc0, 0x86, 0x0a, 0x16, 0x14, 0xa0, 0x78, 0xf1, 0x62, 0x14, 0x97, + 0x14, 0xa3, 0xb0, 0xc8, 0x83, 0xe2, 0xc5, 0xc5, 0xd4, 0x25, 0xa1, 0xb0, 0xc8, 0x83, 0x2a, 0xb9, + 0x7a, 0x4e, 0x40, 0x00, 0x98, 0x09, 0x82, 0xdb, 0x83, 0x43, 0xb8, 0x1d, 0xfb, 0x48, 0xef, 0xbe, + 0x80, 0x00, 0xd0, 0x43, 0x7d, 0x8c, 0x6e, 0x24, 0x5a, 0x00, 0xf8, 0xa9, 0x0b, 0x30, 0xc3, 0xec, + 0x06, 0x5f, 0xe2, 0x2d, 0x11, 0x6a, 0x86, 0xbe, 0xac, 0xa2, 0x1c, 0x65, 0x15, 0xe5, 0xd8, 0x50, + 0xbf, 0x19, 0x40, 0x32, 0x10, 0x0a, 0xf5, 0xf5, 0x4c, 0xa2, 0xd4, 0xc7, 0xe2, 0x46, 0xa2, 0x05, + 0x80, 0x63, 0x2c, 0x5c, 0xb4, 0x08, 0x25, 0xde, 0x12, 0x94, 0x2c, 0x5d, 0x62, 0x8b, 0x33, 0xbc, + 0x51, 0xca, 0x2a, 0xca, 0xf5, 0xbe, 0x34, 0x4a, 0x5d, 0xbb, 0x1b, 0x71, 0x00, 0x58, 0xc8, 0x53, + 0xe4, 0x81, 0x57, 0x5a, 0x2a, 0xdc, 0x59, 0xde, 0x02, 0xb1, 0x96, 0x86, 0xfa, 0x18, 0x75, 0x11, + 0x6e, 0xc4, 0x01, 0x60, 0xb2, 0xd4, 0x99, 0xde, 0x2b, 0x2d, 0xcd, 0x7b, 0xd2, 0xce, 0xc1, 0x3a, + 0xa8, 0x0b, 0x70, 0x2b, 0x61, 0x02, 0x60, 0xe7, 0xb1, 0xa0, 0x4c, 0x5d, 0x43, 0x2e, 0x4a, 0xbc, + 0x4b, 0xe0, 0x95, 0xbc, 0x28, 0xf1, 0x2e, 0xa1, 0x2e, 0x45, 0x04, 0x7f, 0xa4, 0x2e, 0xc0, 0xad, + 0x44, 0x5a, 0x08, 0x24, 0x53, 0x17, 0x90, 0x4d, 0xc1, 0x82, 0x02, 0x2c, 0x5f, 0x59, 0x86, 0x9a, + 0x35, 0x32, 0x2a, 0xaa, 0x2b, 0xb9, 0xf1, 0x6b, 0x77, 0x3c, 0x10, 0x8a, 0x34, 0x53, 0x17, 0xe1, + 0x46, 0x22, 0x05, 0x80, 0x6d, 0x2d, 0x5c, 0xb4, 0x08, 0xe5, 0x55, 0x0f, 0x63, 0xf5, 0xda, 0x47, + 0xb1, 0x6c, 0xe5, 0x72, 0x1e, 0xdf, 0xe7, 0x4e, 0x06, 0xd0, 0x1a, 0x08, 0x45, 0x06, 0x39, 0x08, + 0xac, 0xc5, 0x01, 0x90, 0x87, 0xe2, 0x92, 0x62, 0x54, 0xc9, 0xab, 0x50, 0xb3, 0x46, 0x86, 0x57, + 0x5a, 0x4a, 0x5d, 0x8e, 0x13, 0xc8, 0x48, 0x06, 0x41, 0x98, 0x9f, 0x13, 0x60, 0x0d, 0x61, 0xe6, + 0x00, 0xec, 0xa4, 0xb8, 0xa4, 0x18, 0xcb, 0x56, 0x96, 0x39, 0xea, 0xf2, 0x9d, 0xcd, 0xf8, 0x01, + 0xf8, 0x03, 0xa1, 0xc8, 0x29, 0x00, 0x07, 0x5a, 0x1a, 0xea, 0xe3, 0xd4, 0x05, 0x39, 0x15, 0xf7, + 0x00, 0x72, 0x90, 0x3a, 0xe3, 0x57, 0xd5, 0xac, 0xe2, 0xc6, 0x6f, 0x8d, 0x66, 0x00, 0x83, 0x81, + 0x50, 0xa4, 0x91, 0xba, 0x10, 0xa7, 0x12, 0x29, 0x00, 0x64, 0xaa, 0x1f, 0x9c, 0x1a, 0xe3, 0x73, + 0xc3, 0x27, 0x21, 0x01, 0x68, 0x0b, 0x84, 0x22, 0x6d, 0x81, 0x50, 0x44, 0xa2, 0x2e, 0xc6, 0x69, + 0x38, 0x00, 0x54, 0xcc, 0x9e, 0xd5, 0xe7, 0x31, 0x3e, 0xb9, 0x46, 0x70, 0x6f, 0xc0, 0x70, 0x22, + 0x05, 0x80, 0xa5, 0x4a, 0xbc, 0x4b, 0x50, 0xfd, 0xa5, 0x47, 0xb0, 0x6c, 0xe5, 0x72, 0xea, 0x52, + 0xd8, 0x7d, 0x12, 0x92, 0xbd, 0x81, 0xe3, 0xd4, 0x85, 0x38, 0x05, 0x07, 0xc0, 0x3c, 0x0b, 0x17, + 0x2d, 0x42, 0x95, 0xbc, 0x0a, 0x15, 0xd5, 0x95, 0x7c, 0x39, 0xcf, 0xbe, 0xf6, 0x07, 0x42, 0x91, + 0x6e, 0x1e, 0x12, 0xe4, 0x8f, 0x03, 0x60, 0x96, 0xe5, 0x2b, 0xcb, 0x50, 0xfd, 0xa5, 0x47, 0x78, + 0x9c, 0x2f, 0x06, 0x1f, 0x92, 0x43, 0x02, 0x1f, 0x75, 0x21, 0x22, 0xe3, 0x00, 0x40, 0xf2, 0x26, + 0x9d, 0x55, 0x4a, 0x77, 0xbf, 0x60, 0x01, 0x7f, 0x24, 0x02, 0x91, 0x00, 0x84, 0x79, 0xf1, 0x90, + 0x7e, 0xae, 0xff, 0x6d, 0x2f, 0x5d, 0x2e, 0xa1, 0xaa, 0x66, 0x15, 0xdf, 0xa8, 0x23, 0x2e, 0x09, + 0xc9, 0xc5, 0x43, 0xcd, 0xd4, 0x85, 0x88, 0xc8, 0xb5, 0x01, 0x50, 0xb0, 0xa0, 0x00, 0x55, 0xf2, + 0x2a, 0xac, 0xa8, 0x58, 0xc9, 0x67, 0x7d, 0x67, 0x68, 0x0d, 0x84, 0x22, 0xad, 0xd4, 0x45, 0x88, + 0xc6, 0x95, 0xbf, 0xf9, 0xc5, 0x25, 0xc5, 0xa8, 0x79, 0x6c, 0x35, 0x8f, 0xf5, 0x9d, 0xa7, 0x99, + 0x43, 0x20, 0x37, 0xae, 0x0b, 0x80, 0xe5, 0x2b, 0xcb, 0x50, 0x55, 0xb3, 0x8a, 0xcf, 0xfa, 0xce, + 0xc5, 0x21, 0x90, 0x03, 0xd7, 0xb4, 0x82, 0x82, 0x05, 0x05, 0xa8, 0xa8, 0xae, 0xe4, 0xeb, 0xfa, + 0xee, 0xc0, 0x21, 0xa0, 0x91, 0x2b, 0x02, 0xc0, 0x53, 0xe4, 0x41, 0x55, 0xcd, 0x2a, 0xbe, 0x3f, + 0xdf, 0x5d, 0x9a, 0x03, 0xa1, 0xc8, 0xab, 0xd4, 0x45, 0xd8, 0x9d, 0xe3, 0x03, 0xa0, 0xb8, 0xa4, + 0x98, 0x67, 0xf9, 0xdd, 0xeb, 0x30, 0x5f, 0x1d, 0x50, 0xe7, 0xe8, 0x00, 0xf0, 0x4a, 0x4b, 0x79, + 0xbc, 0xcf, 0x5a, 0x79, 0x6f, 0x81, 0xcc, 0x1c, 0xdb, 0x32, 0x96, 0xaf, 0x2c, 0x43, 0x79, 0xd5, + 0xc3, 0xd4, 0x65, 0x30, 0x7b, 0x68, 0xe3, 0x15, 0x83, 0xe9, 0x39, 0x32, 0x00, 0xca, 0xab, 0x1e, + 0xe6, 0xc9, 0x3e, 0x36, 0x9b, 0x84, 0x64, 0x4f, 0x40, 0xa2, 0x2e, 0xc4, 0x6e, 0x1c, 0x17, 0x00, + 0xe5, 0x55, 0x0f, 0xf3, 0xad, 0xbb, 0x2c, 0x1d, 0x1f, 0x00, 0xbe, 0x32, 0x30, 0x8f, 0xa3, 0x02, + 0x80, 0x1b, 0x3f, 0xcb, 0xa2, 0x31, 0x10, 0x8a, 0xec, 0xa7, 0x2e, 0xc2, 0x4e, 0x1c, 0x13, 0x00, + 0xdc, 0xf8, 0x99, 0x46, 0xc7, 0x79, 0x3e, 0xe0, 0x3e, 0x47, 0x04, 0x00, 0x37, 0x7e, 0x96, 0x23, + 0xde, 0x5e, 0x4c, 0x21, 0x7c, 0x00, 0x70, 0xe3, 0x67, 0x3a, 0xc8, 0x00, 0x0e, 0x53, 0x17, 0x61, + 0x07, 0x42, 0x07, 0x00, 0x37, 0x7e, 0x96, 0x87, 0xfd, 0xbc, 0x3e, 0x40, 0xe0, 0x00, 0xf0, 0x4a, + 0x4b, 0xb9, 0xf1, 0xb3, 0x7c, 0xb9, 0xfe, 0xd2, 0xa0, 0x90, 0x01, 0xe0, 0x95, 0x96, 0xf2, 0x22, + 0x1f, 0x66, 0x04, 0x19, 0xc0, 0x7e, 0xea, 0x22, 0x28, 0x09, 0x17, 0x00, 0x9e, 0x22, 0x0f, 0x56, + 0x3c, 0xbc, 0x92, 0xba, 0x0c, 0xe6, 0x1c, 0x87, 0x03, 0xa1, 0x88, 0x4c, 0x5d, 0x04, 0x15, 0x91, + 0x02, 0xa0, 0xa3, 0x60, 0x41, 0x01, 0xaf, 0xed, 0x67, 0x66, 0x70, 0xed, 0x02, 0x21, 0xa1, 0x5a, + 0x12, 0x37, 0x7e, 0x66, 0x12, 0xbf, 0x5b, 0x27, 0x04, 0x85, 0x69, 0x4d, 0x8f, 0x7e, 0x79, 0xcd, + 0x77, 0xf9, 0x96, 0x5e, 0x66, 0x22, 0x57, 0xf6, 0x02, 0x84, 0x08, 0x00, 0xe5, 0x9e, 0xee, 0xfd, + 0xd4, 0x75, 0x30, 0x47, 0x93, 0xdd, 0xb8, 0x77, 0x80, 0xed, 0x03, 0x40, 0x99, 0xa0, 0xe1, 0x47, + 0x41, 0x31, 0x2b, 0xb8, 0x6e, 0x71, 0x90, 0xed, 0x03, 0x00, 0x40, 0x1b, 0x92, 0xb7, 0x73, 0x32, + 0x66, 0x36, 0xd7, 0xf5, 0x02, 0x6c, 0x1d, 0x00, 0xca, 0x9e, 0x6e, 0x3e, 0xea, 0x3a, 0x98, 0xab, + 0xb8, 0xaa, 0x17, 0xf0, 0x10, 0x75, 0x01, 0x99, 0x28, 0x77, 0x6c, 0x75, 0x53, 0xd7, 0xc1, 0x5c, + 0x69, 0x6f, 0x4b, 0x43, 0xfd, 0x29, 0xea, 0x22, 0xac, 0x60, 0xe7, 0x1e, 0x80, 0x2b, 0x67, 0x65, + 0x99, 0x2d, 0xbc, 0x48, 0x5d, 0x80, 0x55, 0x6c, 0x19, 0x00, 0xdc, 0xf5, 0x67, 0xc4, 0x7c, 0x6e, + 0x59, 0x17, 0x60, 0xbb, 0x00, 0x50, 0x66, 0xfd, 0x5d, 0x35, 0x0e, 0x63, 0xb6, 0xf4, 0x0c, 0x75, + 0x01, 0x56, 0xb0, 0xdd, 0x1c, 0x40, 0x20, 0x14, 0x09, 0x03, 0xf0, 0x53, 0xd7, 0xc1, 0x9c, 0x65, + 0x6a, 0x62, 0x12, 0xd7, 0x23, 0x5d, 0x98, 0xfc, 0x6c, 0x02, 0x63, 0x23, 0xa3, 0xaa, 0xdf, 0x5b, + 0xb5, 0xfa, 0x11, 0x14, 0x16, 0x79, 0x30, 0x35, 0x31, 0xb9, 0xfa, 0xe2, 0xcf, 0x7f, 0x14, 0xa3, + 0xae, 0xdd, 0x4c, 0xb6, 0x0a, 0x80, 0x40, 0x28, 0xd2, 0x88, 0xe4, 0x65, 0x3f, 0xc6, 0x0c, 0xf5, + 0xfe, 0x3b, 0x67, 0x10, 0xeb, 0x1d, 0xc8, 0xf5, 0x65, 0x71, 0x00, 0x3b, 0xa6, 0x2e, 0xff, 0x21, + 0x4a, 0x5d, 0xbf, 0x59, 0xec, 0x36, 0x04, 0xe0, 0x05, 0x3f, 0xcc, 0x14, 0x53, 0x13, 0x13, 0x7a, + 0x5e, 0x26, 0xc1, 0xe1, 0x93, 0xd1, 0xb6, 0x09, 0x00, 0x65, 0xe2, 0x4f, 0xa6, 0xae, 0x83, 0xb1, + 0x79, 0x7c, 0x85, 0x5b, 0xbe, 0xd7, 0x4c, 0x5d, 0x84, 0x59, 0x6c, 0x11, 0x00, 0xca, 0xae, 0x2c, + 0xae, 0xb9, 0xf4, 0xc2, 0x84, 0xe3, 0xd8, 0x09, 0x41, 0x5b, 0x04, 0x00, 0x92, 0x37, 0xfa, 0x48, + 0xd4, 0x45, 0x30, 0xe7, 0xf2, 0x4a, 0xa5, 0xf9, 0xbc, 0xdc, 0x5f, 0xb8, 0xe5, 0x7b, 0x12, 0xf5, + 0x31, 0x98, 0x81, 0x3c, 0x00, 0xf8, 0xec, 0xcf, 0xac, 0x50, 0xb9, 0xba, 0x3a, 0xdf, 0xb7, 0xf0, + 0x53, 0x1f, 0x83, 0x19, 0xc8, 0x03, 0x00, 0x7c, 0xf6, 0x67, 0x16, 0x58, 0xeb, 0x5b, 0x8f, 0xc2, + 0xfc, 0xf6, 0x93, 0xf0, 0x51, 0x1f, 0x83, 0x19, 0x48, 0x03, 0x80, 0xcf, 0xfe, 0xcc, 0x4a, 0x3b, + 0x76, 0x37, 0xe4, 0xf3, 0xf2, 0x1a, 0xea, 0xfa, 0xcd, 0xb0, 0x90, 0xf8, 0xe7, 0xef, 0x87, 0x4b, + 0xce, 0xfe, 0x53, 0x13, 0x93, 0xf8, 0x78, 0x64, 0x14, 0x89, 0xf8, 0x38, 0xee, 0xc6, 0xff, 0x9e, + 0xf1, 0xfb, 0x96, 0x48, 0x4b, 0xe1, 0x95, 0x4a, 0xb1, 0xa2, 0xa2, 0x3c, 0xdf, 0x33, 0x16, 0x9b, + 0x47, 0x7e, 0x7c, 0x0d, 0xbe, 0xba, 0xe3, 0x1b, 0xb8, 0x12, 0xbe, 0xa0, 0xeb, 0xe5, 0xd4, 0xf5, + 0x9b, 0x81, 0x3a, 0x00, 0x1c, 0x3b, 0xbb, 0x3a, 0x35, 0x31, 0x89, 0xc1, 0xde, 0x01, 0x0c, 0x0f, + 0x0e, 0xe1, 0x76, 0x6c, 0x08, 0x89, 0xf8, 0x78, 0xce, 0xef, 0x51, 0x58, 0xe4, 0x41, 0x95, 0xfc, + 0x08, 0xaa, 0x56, 0x57, 0x43, 0x7e, 0xfc, 0xb1, 0x7c, 0x27, 0xb2, 0x18, 0x80, 0xcd, 0xfe, 0xad, + 0xa8, 0xf5, 0xad, 0x43, 0x57, 0xf8, 0xa2, 0xe6, 0xff, 0x97, 0xc2, 0x22, 0x0f, 0x1e, 0xdf, 0xb8, + 0x21, 0x7a, 0xe5, 0xf2, 0x1f, 0xa8, 0xcb, 0x37, 0x1c, 0xd9, 0x4a, 0x40, 0x65, 0xe3, 0x05, 0x47, + 0x2d, 0xb2, 0x48, 0x35, 0xfa, 0xfe, 0xee, 0x1b, 0xb8, 0x1d, 0x1b, 0x32, 0xfc, 0xfd, 0xcb, 0x2a, + 0xca, 0xb1, 0x76, 0xe3, 0x7a, 0x23, 0xc6, 0xb3, 0x4c, 0x91, 0xea, 0x99, 0x4d, 0x4d, 0x4c, 0x60, + 0x6c, 0xe4, 0xce, 0x9c, 0xaf, 0x55, 0xca, 0xd5, 0xf0, 0x14, 0x79, 0x50, 0x56, 0x51, 0x0e, 0x00, + 0xb1, 0x96, 0x86, 0xfa, 0xd5, 0xd4, 0xf5, 0x1a, 0x8d, 0x32, 0x00, 0x1c, 0xb3, 0xe6, 0x3f, 0x11, + 0x1f, 0x47, 0x7f, 0xf4, 0x26, 0xae, 0x5d, 0xba, 0x82, 0xa9, 0x89, 0x49, 0x4b, 0x7e, 0xe6, 0x5a, + 0xdf, 0x7a, 0x6c, 0xde, 0xb1, 0x95, 0x7b, 0x05, 0xd6, 0x5a, 0xdd, 0xd2, 0x50, 0x1f, 0xa3, 0x2e, + 0xc2, 0x48, 0x24, 0x01, 0xa0, 0xdc, 0xf1, 0x37, 0x48, 0x7d, 0xf0, 0xf9, 0x4a, 0xdd, 0x60, 0x62, + 0x65, 0xc3, 0x9f, 0x8f, 0x83, 0xc0, 0x52, 0x07, 0x5a, 0x1a, 0xea, 0xdf, 0xa0, 0x2e, 0xc2, 0x48, + 0x54, 0x73, 0x00, 0xc2, 0xcf, 0xfc, 0xc7, 0x7a, 0x07, 0x10, 0x6e, 0x0b, 0x91, 0x35, 0xfc, 0x94, + 0xbe, 0xe8, 0x0d, 0x0c, 0xf6, 0x0e, 0xe0, 0x2b, 0x5f, 0xff, 0x2a, 0x36, 0xfb, 0xb7, 0x52, 0x7f, + 0x2c, 0x4e, 0xb7, 0x1d, 0xc0, 0x1b, 0xd4, 0x45, 0x18, 0x89, 0x2a, 0x00, 0x9a, 0xa9, 0x0f, 0x5c, + 0xaf, 0xa9, 0x89, 0x49, 0x84, 0xdb, 0x42, 0x7a, 0xee, 0x2c, 0x33, 0xb5, 0xa6, 0x2b, 0xe1, 0x0b, + 0x18, 0xfc, 0x60, 0x00, 0xdf, 0xfe, 0x41, 0x23, 0xf7, 0x06, 0xcc, 0xe3, 0xa7, 0x2e, 0xc0, 0x68, + 0x96, 0x0f, 0x01, 0x44, 0xbe, 0xe5, 0x77, 0x6c, 0x64, 0x14, 0x67, 0x5b, 0x4f, 0x93, 0x9f, 0xf5, + 0xd5, 0x14, 0x16, 0x79, 0xb0, 0x63, 0x77, 0x03, 0xe4, 0xc7, 0xd7, 0x50, 0x97, 0xe2, 0x54, 0x1b, + 0x5b, 0x1a, 0xea, 0xa3, 0xd4, 0x45, 0x18, 0x85, 0x62, 0x21, 0xd0, 0x77, 0xa9, 0x0f, 0x5a, 0x8f, + 0xbe, 0xe8, 0x0d, 0xfc, 0xfe, 0xad, 0xb7, 0x6d, 0xdd, 0xf8, 0x81, 0x64, 0x6f, 0xe0, 0xfd, 0x77, + 0xce, 0xa0, 0xab, 0xe3, 0x22, 0x75, 0x29, 0x4e, 0xe5, 0xa3, 0x2e, 0xc0, 0x48, 0x14, 0x43, 0x80, + 0x46, 0xea, 0x83, 0xce, 0x55, 0x5f, 0xf4, 0x06, 0x3a, 0xda, 0x42, 0x86, 0xbc, 0xd7, 0xb6, 0x4d, + 0xeb, 0x00, 0x00, 0x35, 0x95, 0xe5, 0x90, 0xab, 0x92, 0x4f, 0x39, 0xee, 0xe9, 0x8f, 0x21, 0x9e, + 0xb8, 0x07, 0x00, 0xe8, 0xbc, 0x7a, 0xd3, 0x90, 0x9f, 0x73, 0x25, 0x7c, 0x01, 0x89, 0x4f, 0xc6, + 0xe1, 0xcf, 0x6f, 0xf5, 0x1b, 0x7b, 0xd0, 0x76, 0x00, 0xa7, 0xa8, 0x8b, 0x30, 0x8a, 0xa5, 0x01, + 0xa0, 0x74, 0xff, 0x25, 0xea, 0x83, 0xce, 0x45, 0x3e, 0x8d, 0x5f, 0xf2, 0x96, 0xe0, 0x3b, 0xdb, + 0xb6, 0x60, 0xfb, 0xe6, 0x75, 0xd8, 0xb6, 0x69, 0x1d, 0x6a, 0x2a, 0xb5, 0x3d, 0xd6, 0xfc, 0xd6, + 0xf0, 0x1d, 0x74, 0x5e, 0xbd, 0x89, 0xf3, 0x5d, 0x37, 0xf1, 0x5e, 0xe7, 0xe5, 0x99, 0x70, 0xd0, + 0x53, 0x3b, 0x00, 0x0e, 0x01, 0x63, 0xf9, 0xa8, 0x0b, 0x30, 0x92, 0xa5, 0x73, 0x00, 0x81, 0x50, + 0xa4, 0x15, 0x02, 0x4d, 0x00, 0xea, 0x6d, 0xfc, 0x4f, 0x6e, 0xdf, 0x82, 0xa6, 0x5d, 0x7e, 0x3c, + 0xb9, 0x7d, 0x8b, 0x21, 0x75, 0x9c, 0x3d, 0x7f, 0x19, 0x2d, 0xa7, 0xdb, 0x75, 0xf7, 0x0e, 0x36, + 0xd4, 0x6f, 0xc6, 0xd6, 0x86, 0x6f, 0x9a, 0xfa, 0x59, 0xb9, 0x49, 0x4b, 0x43, 0xbd, 0xad, 0xb6, + 0xd2, 0xcb, 0x87, 0xd5, 0x01, 0x30, 0x08, 0x41, 0xd6, 0x54, 0xdf, 0x8e, 0x0d, 0xe1, 0xbd, 0xd6, + 0xd3, 0x39, 0xbd, 0xa6, 0x69, 0xd7, 0x0e, 0xbc, 0xfc, 0xec, 0xd3, 0x9a, 0xcf, 0xf4, 0x59, 0x4d, + 0x4f, 0x61, 0x7a, 0x7a, 0x12, 0x98, 0xfe, 0x1c, 0xc0, 0x34, 0x6e, 0x8d, 0x7c, 0x82, 0x23, 0x27, + 0xff, 0x88, 0xe0, 0xb9, 0x4b, 0x39, 0xbf, 0x95, 0x7f, 0x77, 0x03, 0xd6, 0xfa, 0xd6, 0x5b, 0xf0, + 0xc9, 0xb9, 0xc2, 0x8e, 0x96, 0x86, 0xfa, 0x0e, 0xea, 0x22, 0x8c, 0x60, 0xd9, 0x24, 0xa0, 0xf2, + 0xa4, 0x1f, 0x99, 0xfa, 0x80, 0xb5, 0x48, 0x4e, 0xa4, 0x69, 0xbf, 0x50, 0x51, 0x57, 0x2b, 0xe3, + 0x7f, 0xdf, 0x7a, 0x0d, 0x27, 0x5f, 0x79, 0xde, 0xb0, 0xc6, 0x3f, 0xfd, 0xc5, 0x5d, 0x4c, 0x7f, + 0x91, 0x00, 0xa6, 0xa7, 0x00, 0x4c, 0x03, 0x00, 0x6a, 0x2a, 0x96, 0xe1, 0x37, 0x2f, 0x35, 0xe3, + 0xf2, 0xdb, 0x2f, 0xa1, 0xa6, 0x72, 0x45, 0x4e, 0xef, 0xd7, 0xd1, 0x16, 0xca, 0xba, 0x1b, 0x2e, + 0xd3, 0xcc, 0x47, 0x5d, 0x80, 0x51, 0xac, 0xbc, 0x0a, 0xe0, 0xa7, 0x3e, 0x58, 0xad, 0xde, 0x7f, + 0xa7, 0x4d, 0xf3, 0x6c, 0x7f, 0x60, 0xcf, 0x2e, 0x5c, 0x0e, 0x1e, 0x9d, 0x99, 0xdc, 0x33, 0xc4, + 0xf4, 0x04, 0x30, 0x9d, 0xf9, 0xe7, 0x7f, 0x65, 0x4d, 0x35, 0x2e, 0xbf, 0x7d, 0x18, 0x81, 0x3d, + 0xbb, 0x72, 0x3c, 0xae, 0x33, 0xb6, 0xbf, 0x8a, 0x21, 0x88, 0x3a, 0xea, 0x02, 0x8c, 0x62, 0x65, + 0x00, 0x6c, 0xa7, 0x3e, 0x58, 0x2d, 0xae, 0x47, 0xba, 0x34, 0xdd, 0xc8, 0x23, 0x79, 0x4b, 0xf0, + 0x3f, 0xbf, 0xf8, 0x09, 0x8e, 0x1e, 0xd8, 0x6b, 0x78, 0x0d, 0xd3, 0x5f, 0x7c, 0x96, 0xf5, 0x7b, + 0x4a, 0x97, 0x14, 0xe2, 0xe8, 0xfe, 0x7f, 0xc3, 0xc9, 0x57, 0x5e, 0x80, 0xe4, 0x2d, 0xd1, 0xf4, + 0xbe, 0x89, 0xf8, 0xb8, 0xde, 0x5b, 0x61, 0xd9, 0x5c, 0x32, 0x75, 0x01, 0x46, 0xe1, 0x1e, 0xc0, + 0x2c, 0x5a, 0x1b, 0x88, 0xe4, 0x2d, 0xc1, 0x9f, 0x7f, 0xf5, 0x9a, 0x61, 0x93, 0x7c, 0x29, 0xc1, + 0xf6, 0x0e, 0x3c, 0xf5, 0xe3, 0xff, 0x00, 0xf0, 0x85, 0xa6, 0xef, 0x9f, 0x9e, 0x9e, 0x42, 0xd3, + 0x2e, 0x3f, 0xfe, 0xfc, 0xab, 0xd7, 0x34, 0x87, 0x80, 0xd6, 0x80, 0x63, 0xaa, 0xfc, 0xd4, 0x05, + 0x18, 0xc5, 0x92, 0x00, 0x50, 0xc6, 0xff, 0x12, 0xf5, 0xc1, 0x66, 0xd3, 0x15, 0xbe, 0x98, 0xb5, + 0x8b, 0x9c, 0x6a, 0xfc, 0x75, 0xb5, 0xb2, 0x61, 0x3f, 0xf7, 0xd6, 0xf0, 0x1d, 0x7c, 0xeb, 0xb9, + 0xc3, 0xd8, 0xf7, 0xfa, 0x9b, 0x88, 0xdf, 0x4d, 0x68, 0x7e, 0xdd, 0xb5, 0xfe, 0xff, 0x43, 0xb0, + 0xbd, 0x03, 0x75, 0xb5, 0x72, 0x4e, 0x21, 0x70, 0x31, 0xf4, 0x57, 0x53, 0x3e, 0x3f, 0x37, 0x51, + 0x6e, 0x68, 0x13, 0x9e, 0x55, 0x3d, 0x00, 0x1f, 0xf5, 0x81, 0x66, 0x93, 0x88, 0x8f, 0xcf, 0x5c, + 0x37, 0xcf, 0xc4, 0x8c, 0xc6, 0xdf, 0xd3, 0x1f, 0xc3, 0x96, 0xa6, 0x43, 0x33, 0x97, 0xf8, 0x6e, + 0x0d, 0x8f, 0x69, 0x7e, 0x6d, 0xfc, 0xee, 0x3d, 0xec, 0x7b, 0xfd, 0x4d, 0xec, 0x7b, 0xfd, 0x44, + 0x4e, 0x21, 0x30, 0x36, 0x32, 0x9a, 0xf5, 0x58, 0x59, 0x56, 0x32, 0x75, 0x01, 0x46, 0xb0, 0x2a, + 0x00, 0x6c, 0x3f, 0xfe, 0xef, 0x0a, 0x67, 0x5f, 0x3a, 0xfb, 0x9b, 0x97, 0x9f, 0x37, 0xbc, 0xf1, + 0x3f, 0xf1, 0xc3, 0xc3, 0x73, 0x16, 0xfa, 0xdc, 0x1a, 0x1e, 0xc3, 0xb5, 0x01, 0x6d, 0x5d, 0xf4, + 0x6b, 0xfd, 0xc9, 0xef, 0x0b, 0xb6, 0x87, 0x67, 0x42, 0x40, 0xeb, 0x9c, 0x84, 0x96, 0xe3, 0x65, + 0xaa, 0xfc, 0xd4, 0x05, 0x18, 0xc1, 0xaa, 0x00, 0x90, 0xa9, 0x0f, 0x54, 0x8d, 0x96, 0xb3, 0x7f, + 0x60, 0xcf, 0x2e, 0x43, 0xc7, 0xfc, 0xf1, 0xc4, 0xbd, 0x07, 0x1a, 0x7f, 0xca, 0x91, 0xdf, 0xfe, + 0x49, 0xd3, 0x7b, 0xb4, 0xbc, 0xfb, 0x97, 0x99, 0x3f, 0x07, 0xdb, 0xc3, 0x08, 0xb6, 0x77, 0xa0, + 0x69, 0x97, 0x5f, 0xd3, 0xd5, 0x81, 0x44, 0x7c, 0x9c, 0xe7, 0x02, 0xf2, 0xe3, 0x88, 0x4d, 0x42, + 0xad, 0x0a, 0x00, 0x3f, 0xf5, 0x81, 0xaa, 0xe9, 0x8f, 0xaa, 0xaf, 0xb0, 0xcb, 0xe5, 0xcc, 0xaa, + 0xd5, 0xa1, 0xe3, 0xa7, 0x32, 0x2e, 0xf1, 0x3d, 0xdb, 0x19, 0xcd, 0x1a, 0x02, 0xcf, 0x1e, 0x39, + 0xf5, 0xc0, 0x70, 0xe1, 0xd0, 0xf1, 0x56, 0xc4, 0x13, 0xf7, 0xf0, 0xd2, 0xbe, 0xa7, 0x51, 0x53, + 0x59, 0x9e, 0xb5, 0x86, 0xeb, 0x97, 0xba, 0x0c, 0x3d, 0x26, 0x97, 0x91, 0xa9, 0x0b, 0x30, 0x82, + 0xe9, 0x01, 0xa0, 0x4c, 0x00, 0xda, 0x5a, 0x5f, 0xb7, 0xfa, 0xd9, 0xdf, 0xe8, 0xc6, 0x7f, 0x6b, + 0xf8, 0x0e, 0x82, 0xed, 0x61, 0xd5, 0xef, 0x39, 0xf2, 0xdb, 0xf7, 0xf0, 0xf4, 0x4f, 0xdf, 0x7a, + 0x60, 0x38, 0xd0, 0xd9, 0xdd, 0x8f, 0x27, 0x5e, 0x38, 0x96, 0x76, 0x35, 0x60, 0x3c, 0x71, 0x0f, + 0x47, 0x4e, 0xbe, 0x0b, 0xc9, 0x5b, 0x82, 0x93, 0xaf, 0x3c, 0x9f, 0xb5, 0x8e, 0x58, 0xef, 0x00, + 0xaf, 0x0b, 0xd0, 0xcf, 0x47, 0x5d, 0x80, 0x11, 0xac, 0xb8, 0x19, 0x48, 0xa2, 0x3e, 0x48, 0x35, + 0x63, 0xca, 0x56, 0xdd, 0x99, 0x3c, 0xb9, 0x7d, 0x8b, 0xb1, 0x8b, 0x7c, 0x00, 0xb4, 0x9c, 0xd6, + 0xd6, 0xc5, 0x3f, 0xdb, 0x19, 0xc5, 0xd9, 0xce, 0x28, 0x00, 0x60, 0xdb, 0xa6, 0x5a, 0x74, 0x5e, + 0xed, 0xcf, 0xfa, 0x9a, 0x60, 0x7b, 0x07, 0x8e, 0x1e, 0xd8, 0x8b, 0x6d, 0x9b, 0x92, 0x37, 0x20, + 0x65, 0xbb, 0x7f, 0x60, 0xb0, 0x77, 0x80, 0x97, 0x08, 0xeb, 0x23, 0x51, 0x17, 0x60, 0x04, 0x2b, + 0x86, 0x00, 0x7e, 0xea, 0x83, 0x54, 0x13, 0xeb, 0xfd, 0x50, 0xf5, 0xeb, 0x2f, 0xed, 0x7b, 0xda, + 0xf0, 0x9f, 0x79, 0xf6, 0xfc, 0xdf, 0x72, 0x7e, 0x8d, 0x96, 0xc6, 0x0f, 0x24, 0x7b, 0x01, 0xa9, + 0x46, 0xff, 0xf2, 0xb3, 0xd9, 0x6b, 0x8f, 0x7d, 0xf0, 0x61, 0xd6, 0xef, 0x61, 0xe9, 0x05, 0x42, + 0x11, 0x3f, 0x75, 0x0d, 0xf9, 0xb2, 0x22, 0x00, 0x6c, 0xbd, 0x3f, 0xd5, 0xed, 0xc1, 0x8f, 0x32, + 0x7e, 0x6d, 0xdb, 0xa6, 0x75, 0x86, 0xce, 0xfa, 0x03, 0xc9, 0x06, 0x7a, 0x6b, 0xd8, 0xdc, 0x35, + 0xf9, 0xa9, 0x00, 0x48, 0xf5, 0x02, 0x54, 0x8f, 0x3f, 0xf6, 0x91, 0x96, 0xb7, 0x64, 0xe9, 0xc9, + 0xd4, 0x05, 0xe4, 0xcb, 0x8a, 0x00, 0xf0, 0x51, 0x1f, 0xa4, 0x1a, 0xb5, 0x99, 0xf0, 0x7f, 0xff, + 0x97, 0x1d, 0x86, 0xff, 0xbc, 0x6b, 0x03, 0x31, 0xd3, 0x8f, 0x29, 0x76, 0xfb, 0xfe, 0xfe, 0xf6, + 0xd9, 0x8e, 0x61, 0x6a, 0x62, 0x92, 0x6f, 0x12, 0xd2, 0x4f, 0xa6, 0x2e, 0x20, 0x5f, 0x76, 0x78, + 0x38, 0x28, 0x19, 0xb5, 0xc6, 0x2f, 0x79, 0x4b, 0xd0, 0xb4, 0xcb, 0x4f, 0x5d, 0xa2, 0x2e, 0xb3, + 0x7b, 0x18, 0xdf, 0xd9, 0xf6, 0xb5, 0xac, 0xdf, 0xff, 0x31, 0x07, 0x80, 0x5e, 0xc2, 0x5f, 0x0a, + 0x74, 0xf5, 0x1c, 0x80, 0xda, 0xe4, 0x9f, 0xd1, 0x13, 0x7f, 0x56, 0x9a, 0xbd, 0x1a, 0x50, 0xf2, + 0x96, 0x64, 0x5d, 0xbf, 0xa0, 0xf6, 0xac, 0x42, 0xa6, 0x4a, 0xa6, 0x2e, 0x20, 0x5f, 0xae, 0xee, + 0x01, 0xa8, 0xfd, 0xe2, 0x9b, 0x15, 0x00, 0xa5, 0x4b, 0xb4, 0xad, 0xd7, 0xcf, 0xc7, 0xfc, 0x79, + 0x8b, 0xac, 0xf3, 0x00, 0x83, 0x3c, 0x0f, 0xa0, 0x93, 0x8f, 0xba, 0x80, 0x7c, 0xb9, 0x3a, 0x00, + 0x26, 0x3f, 0x9b, 0xc8, 0xf8, 0x35, 0xb3, 0x02, 0xa0, 0xae, 0x56, 0xd6, 0x7c, 0xd3, 0x8e, 0x5e, + 0xf3, 0x17, 0x01, 0x19, 0x3d, 0x91, 0xc9, 0x66, 0x48, 0xd4, 0x05, 0xe4, 0xcb, 0xd4, 0x00, 0xb0, + 0xfb, 0x65, 0x12, 0xb5, 0xc9, 0x2f, 0x33, 0x1b, 0x8d, 0xd9, 0xc3, 0x8b, 0xf9, 0xef, 0x2f, 0xf2, + 0x70, 0xc6, 0xee, 0x44, 0x58, 0xe8, 0xa6, 0xc6, 0xd5, 0x3d, 0x80, 0x4c, 0xb4, 0x2c, 0xa3, 0xcd, + 0x87, 0xd1, 0xfb, 0x08, 0xcc, 0x96, 0xcb, 0xee, 0xc3, 0x29, 0x3c, 0x09, 0x98, 0x17, 0x89, 0xba, + 0x80, 0x7c, 0x70, 0x00, 0xa4, 0x61, 0xd8, 0xa6, 0x9e, 0x19, 0x34, 0xed, 0xf2, 0x9b, 0x16, 0x32, + 0x99, 0x16, 0xff, 0xa8, 0xf5, 0x02, 0x78, 0x39, 0x70, 0x5e, 0x64, 0xea, 0x02, 0xf2, 0xc1, 0x01, + 0x40, 0x44, 0xcb, 0x5a, 0xfd, 0x5c, 0xe9, 0x5d, 0xb6, 0x5c, 0x58, 0xe4, 0xa1, 0xfe, 0x38, 0x44, + 0x26, 0x53, 0x17, 0x90, 0x0f, 0x0e, 0x00, 0x22, 0xdb, 0x36, 0xad, 0xcb, 0x79, 0x53, 0x4f, 0x35, + 0x35, 0x95, 0xe5, 0xf8, 0xcd, 0xcb, 0xfa, 0x42, 0x65, 0x45, 0x85, 0xb9, 0x43, 0x1e, 0x66, 0x5f, + 0xae, 0x0e, 0x80, 0x32, 0xe2, 0x5f, 0xfc, 0xa3, 0x07, 0xf6, 0xa2, 0x69, 0x57, 0xfe, 0xab, 0x0d, + 0x53, 0x1b, 0x94, 0x9a, 0x7d, 0x75, 0x81, 0xa5, 0x65, 0xfb, 0xcd, 0x6e, 0xd4, 0xb8, 0x3a, 0x00, + 0x3c, 0xc5, 0x45, 0xd4, 0x25, 0xe0, 0xe4, 0x2b, 0xcf, 0x6b, 0xba, 0x69, 0x27, 0x93, 0xba, 0x5a, + 0x19, 0x7d, 0x6d, 0xbf, 0xca, 0xeb, 0xaa, 0x45, 0x61, 0x11, 0xfd, 0xe7, 0xc0, 0x68, 0xb8, 0x3a, + 0x00, 0x96, 0x48, 0x4b, 0xa9, 0x4b, 0x00, 0x90, 0xbc, 0xe3, 0x30, 0xd7, 0x67, 0x0b, 0x48, 0xde, + 0x12, 0x1c, 0x3d, 0xb0, 0x17, 0x97, 0x83, 0x47, 0x35, 0x9d, 0xf9, 0x6f, 0x0d, 0xdf, 0xc9, 0xf8, + 0xb5, 0x15, 0x26, 0x5f, 0xf5, 0x70, 0x38, 0x99, 0xba, 0x80, 0x7c, 0x50, 0x3c, 0x1d, 0xd8, 0x36, + 0xbc, 0x52, 0xfa, 0x1b, 0x15, 0x8d, 0x7a, 0x42, 0x6f, 0x2e, 0x52, 0x4f, 0x17, 0xea, 0xe9, 0x8f, + 0x21, 0xd8, 0x1e, 0x46, 0xe7, 0xd5, 0x9b, 0xe8, 0xe9, 0x8f, 0xcd, 0xf9, 0x9e, 0x9a, 0xca, 0x72, + 0xd4, 0xd5, 0xca, 0x33, 0xcf, 0x1e, 0xcc, 0x85, 0xda, 0x1d, 0x88, 0x76, 0x09, 0x42, 0x41, 0xc9, + 0xd4, 0x05, 0xe4, 0xc3, 0xd5, 0x01, 0x50, 0x25, 0x57, 0x67, 0xfc, 0xda, 0xad, 0xe1, 0x3b, 0xa6, + 0x5f, 0x0e, 0x4c, 0xa7, 0xae, 0x56, 0x46, 0x5d, 0xad, 0xb1, 0x3b, 0x10, 0xcd, 0x0f, 0x92, 0xf9, + 0x78, 0x12, 0xd0, 0xbd, 0x5c, 0x1d, 0x00, 0x40, 0x32, 0x04, 0xd2, 0xdd, 0x15, 0xd8, 0xd3, 0x3f, + 0x48, 0x12, 0x00, 0x66, 0x50, 0xbb, 0x05, 0xb9, 0xb0, 0xc8, 0x43, 0x3e, 0x19, 0x6a, 0xb4, 0xd4, + 0xff, 0xe7, 0xb0, 0x86, 0x4d, 0x4f, 0x67, 0x1f, 0xbf, 0xda, 0x09, 0x41, 0x4d, 0x20, 0x14, 0x91, + 0x5b, 0x1a, 0xea, 0x63, 0xd4, 0xc7, 0xad, 0x07, 0x07, 0xc0, 0xea, 0x47, 0xd2, 0x06, 0x40, 0xe7, + 0xd5, 0x9b, 0xa6, 0xae, 0xd8, 0xb3, 0xd2, 0xf9, 0xae, 0xcc, 0x43, 0x9a, 0x2a, 0xf9, 0x11, 0xea, + 0xf2, 0xf2, 0x92, 0xda, 0xdd, 0x78, 0x78, 0x70, 0x08, 0x1f, 0x8f, 0x8c, 0x3e, 0xb0, 0xbc, 0xbb, + 0xa6, 0xb2, 0x0c, 0x35, 0x95, 0x65, 0xd8, 0xb6, 0x71, 0xed, 0x9c, 0x7f, 0x1f, 0xbf, 0xfb, 0x29, + 0x7a, 0x06, 0x86, 0xd0, 0x19, 0x9e, 0xbb, 0xd3, 0x92, 0x57, 0x2a, 0x45, 0x95, 0x5c, 0x8d, 0xad, + 0x0d, 0xdf, 0xcc, 0x65, 0x7d, 0x84, 0x0c, 0x20, 0x46, 0xfd, 0x59, 0xe8, 0x61, 0x76, 0x00, 0xc4, + 0xa9, 0x0f, 0x30, 0x1b, 0xf9, 0xf1, 0xc7, 0xd2, 0x3e, 0x0e, 0xec, 0xec, 0xf9, 0xbf, 0x99, 0xf2, + 0xdc, 0x3f, 0x0a, 0x6a, 0x73, 0x1a, 0xf2, 0x3f, 0x3d, 0x46, 0x5d, 0x5e, 0xce, 0xa6, 0x26, 0x26, + 0xd1, 0x17, 0xbd, 0x81, 0xbe, 0xee, 0x1b, 0x69, 0xef, 0xe7, 0x90, 0x96, 0x2c, 0xc6, 0x0b, 0xdf, + 0xff, 0x67, 0x34, 0xed, 0xfc, 0x3a, 0x6a, 0x2a, 0xcb, 0x54, 0xdf, 0x6b, 0xfc, 0xee, 0xa7, 0x08, + 0xb6, 0x5f, 0xc2, 0x91, 0xdf, 0xfe, 0x09, 0xf1, 0xbb, 0x9f, 0x2a, 0x5b, 0xc4, 0x8f, 0xe3, 0xe3, + 0x91, 0x51, 0xfc, 0xeb, 0x73, 0xcf, 0x50, 0x1f, 0xaa, 0xe9, 0x4c, 0x0d, 0x80, 0x96, 0x86, 0xfa, + 0x68, 0x20, 0x14, 0xa1, 0x3e, 0x46, 0x55, 0x65, 0x15, 0xe5, 0xf0, 0x4a, 0xa5, 0x0f, 0xec, 0x0d, + 0x70, 0x6b, 0x78, 0x14, 0x3d, 0xfd, 0x31, 0xe1, 0xef, 0xa4, 0xeb, 0xe9, 0x8f, 0xa9, 0x4e, 0x00, + 0xae, 0x7e, 0x7c, 0x0d, 0x75, 0x89, 0x9a, 0x25, 0xe2, 0xe3, 0xe8, 0x0a, 0x5f, 0x54, 0x7d, 0x86, + 0x43, 0xdd, 0x9a, 0x6a, 0xfc, 0xf9, 0xc4, 0x8f, 0x50, 0xba, 0x64, 0xb1, 0xa6, 0xf7, 0x2c, 0x55, + 0xc2, 0xa2, 0xa6, 0xb2, 0x0c, 0x4f, 0xfd, 0xf4, 0xad, 0x99, 0x7f, 0x1f, 0x1b, 0x19, 0x45, 0xac, + 0x77, 0x00, 0xb2, 0x40, 0x9f, 0x8f, 0x1e, 0xae, 0xbe, 0x0c, 0x98, 0xb2, 0x76, 0x63, 0xfa, 0x5d, + 0x71, 0xb3, 0x6d, 0xdd, 0x2d, 0x82, 0x96, 0xd3, 0xed, 0x99, 0x8f, 0xdb, 0xb7, 0x5e, 0x88, 0x65, + 0xc0, 0x89, 0xf8, 0x38, 0x3a, 0xda, 0x42, 0xf8, 0xef, 0xe3, 0xbf, 0xce, 0xfa, 0x00, 0x97, 0x77, + 0xff, 0xf3, 0x39, 0xcd, 0x8d, 0x7f, 0xb6, 0x52, 0xef, 0x83, 0xaf, 0x19, 0x1b, 0xb9, 0xa3, 0xf5, + 0xe5, 0x32, 0xf5, 0x67, 0xa4, 0x97, 0x15, 0x01, 0x10, 0xa7, 0x3e, 0xc8, 0x6c, 0x6a, 0x7d, 0xe9, + 0xaf, 0xbf, 0x07, 0xdb, 0x3b, 0x32, 0x3e, 0xbc, 0x43, 0x04, 0xf1, 0xc4, 0x3d, 0xd5, 0x10, 0xab, + 0xdd, 0x68, 0xff, 0xed, 0xc0, 0xbb, 0x3a, 0x2e, 0xe2, 0xf7, 0x6f, 0xbd, 0x6d, 0xea, 0xb3, 0x0c, + 0xc7, 0xef, 0x7e, 0x8a, 0x37, 0x7f, 0xf7, 0x97, 0x07, 0xfe, 0x3d, 0x87, 0xcb, 0xa3, 0x32, 0xc9, + 0x87, 0x63, 0x00, 0x2b, 0x02, 0x20, 0x4a, 0x7d, 0x90, 0xd9, 0x78, 0xa5, 0xd2, 0xb4, 0x7b, 0xe3, + 0xc7, 0x13, 0xf7, 0xf0, 0xe6, 0xef, 0xda, 0x75, 0xbc, 0xa3, 0x3d, 0xa8, 0xd5, 0x5e, 0x56, 0x51, + 0xae, 0x7b, 0xd6, 0xdb, 0x0a, 0x89, 0xf8, 0x38, 0xde, 0x6b, 0x3d, 0x8d, 0x2b, 0xe1, 0x0b, 0x39, + 0xdd, 0xad, 0x98, 0xee, 0x61, 0x2a, 0x99, 0x8c, 0xdf, 0xfd, 0x14, 0xc1, 0x73, 0x97, 0xb0, 0xe5, + 0x99, 0x23, 0x33, 0xcf, 0x5f, 0x98, 0xcd, 0xce, 0x9f, 0x8f, 0x51, 0x5c, 0x7f, 0x15, 0x20, 0x65, + 0xf3, 0x8e, 0xad, 0x69, 0xcf, 0x32, 0x2d, 0xa7, 0xdb, 0xf1, 0xc2, 0xf7, 0x77, 0x09, 0xb7, 0xce, + 0xfe, 0xd6, 0xf0, 0x1d, 0xd5, 0xee, 0xff, 0x86, 0xaf, 0x6f, 0xa6, 0x2e, 0x31, 0xa3, 0xb1, 0x91, + 0x51, 0x9c, 0x6d, 0x3d, 0xad, 0xeb, 0x36, 0xe5, 0x9e, 0x81, 0x21, 0x6c, 0x79, 0xe6, 0x08, 0xea, + 0xd6, 0x54, 0x63, 0xdb, 0xa6, 0x5a, 0xd4, 0x54, 0x94, 0xe1, 0x2b, 0xb5, 0xf7, 0x1b, 0xf2, 0xb5, + 0xfe, 0x21, 0xc4, 0xef, 0x7e, 0x86, 0xce, 0xee, 0x3e, 0xd5, 0x67, 0x2d, 0xa4, 0xe6, 0x86, 0x9c, + 0xce, 0x8a, 0x00, 0x38, 0x0f, 0x1b, 0x6f, 0x0c, 0x9a, 0x92, 0xea, 0x05, 0xcc, 0x0f, 0x81, 0x78, + 0xe2, 0x1e, 0x0e, 0x1d, 0x3f, 0x65, 0xca, 0xed, 0xbb, 0x66, 0x4a, 0x3d, 0x27, 0x30, 0x9d, 0x2a, + 0xb9, 0xda, 0xb6, 0x4f, 0x03, 0xea, 0x8b, 0xde, 0xc0, 0xc5, 0xd0, 0x5f, 0xf3, 0xde, 0xa3, 0xa0, + 0x67, 0x60, 0x08, 0x3d, 0x1a, 0x7b, 0x02, 0xe9, 0xd8, 0x39, 0x20, 0x8d, 0xc4, 0x93, 0x80, 0xb3, + 0x64, 0xba, 0xf6, 0x9b, 0x5a, 0x9a, 0x2b, 0x8a, 0xb3, 0xe7, 0x2f, 0xe3, 0xec, 0xf9, 0xcb, 0x19, + 0xbf, 0xbe, 0x79, 0xc7, 0x37, 0xa8, 0x4b, 0x4c, 0x6b, 0x6c, 0x64, 0x14, 0x1d, 0x6d, 0x21, 0xf2, + 0x0d, 0x4a, 0xd6, 0xfa, 0xd6, 0xdb, 0x36, 0x20, 0x8d, 0x66, 0x45, 0x00, 0x74, 0x50, 0x1f, 0xa4, + 0x56, 0x85, 0x45, 0x1e, 0x7c, 0x35, 0x43, 0xe3, 0x78, 0xea, 0x27, 0xbf, 0x10, 0x62, 0x42, 0xf0, + 0xd6, 0xf0, 0x1d, 0x3c, 0xfb, 0xb3, 0x13, 0x19, 0xbf, 0xbe, 0xa1, 0x7e, 0xb3, 0x2d, 0xc7, 0xb6, + 0x89, 0xf8, 0x38, 0xce, 0xb6, 0x9e, 0xa6, 0x2e, 0x03, 0x65, 0x15, 0xe5, 0xd8, 0xda, 0xf0, 0x4d, + 0xea, 0x32, 0x2c, 0xc3, 0x57, 0x01, 0xe6, 0xc9, 0xd4, 0x40, 0xe2, 0x89, 0x7b, 0x78, 0xe2, 0x87, + 0x87, 0x6d, 0x1d, 0x02, 0xf1, 0xc4, 0x3d, 0x3c, 0xf5, 0x93, 0x9f, 0x67, 0xac, 0xd1, 0x2b, 0x95, + 0x66, 0x0c, 0x38, 0x6a, 0xd7, 0x2f, 0x75, 0x91, 0x9f, 0xf9, 0xcb, 0x2a, 0xca, 0xf1, 0xe4, 0xde, + 0x3d, 0x7a, 0x2e, 0x8d, 0xd6, 0x91, 0x16, 0x9e, 0x07, 0xd3, 0x03, 0xa0, 0xa5, 0xa1, 0x3e, 0x4a, + 0x7d, 0x90, 0xb9, 0xfa, 0xf6, 0x0f, 0x76, 0xa7, 0xfd, 0x25, 0xe8, 0xe9, 0x8f, 0xe1, 0xd0, 0xf1, + 0x53, 0xd4, 0xe5, 0x65, 0xf4, 0xec, 0xcf, 0x4e, 0xa8, 0xde, 0xf8, 0xf3, 0xed, 0x1f, 0x34, 0xda, + 0xf6, 0xba, 0x3f, 0xf5, 0xe3, 0xc9, 0xf2, 0x68, 0xfc, 0x80, 0xc0, 0x1b, 0x83, 0x5a, 0x35, 0x07, + 0x10, 0xa5, 0x3e, 0xd0, 0x5c, 0x14, 0x16, 0x79, 0xf0, 0xe4, 0xde, 0x3d, 0x69, 0xbf, 0x16, 0x6c, + 0x0f, 0x63, 0xdf, 0xeb, 0x27, 0x72, 0x7c, 0x47, 0xf3, 0xed, 0x7b, 0xfd, 0x84, 0xea, 0xb8, 0xdf, + 0xbf, 0xbb, 0xc1, 0x71, 0x37, 0xfd, 0x18, 0xc5, 0x2b, 0x95, 0xe6, 0xd3, 0xf8, 0x85, 0xc6, 0x01, + 0x90, 0x41, 0x59, 0x45, 0x39, 0xfc, 0xbb, 0x1b, 0xd2, 0x7e, 0x2d, 0xd8, 0x1e, 0xc6, 0xb7, 0x9e, + 0xb3, 0xc7, 0x70, 0x20, 0x9e, 0xb8, 0x87, 0x2d, 0x4d, 0x87, 0x54, 0x17, 0xfc, 0x6c, 0xa8, 0xdf, + 0xec, 0x9a, 0x49, 0xad, 0x5c, 0x15, 0x16, 0x79, 0x6c, 0xdd, 0x33, 0x32, 0x9b, 0x55, 0x01, 0xd0, + 0x43, 0x7d, 0xa0, 0x7a, 0xac, 0xf5, 0xad, 0xcf, 0x18, 0x02, 0x9d, 0x57, 0x6f, 0xe2, 0x89, 0x1f, + 0x1e, 0xce, 0x7a, 0xaf, 0xbd, 0x99, 0x7a, 0xfa, 0x63, 0xd8, 0xd2, 0xf4, 0x63, 0xd5, 0x1a, 0xd6, + 0xfa, 0xd6, 0x0b, 0x31, 0xa9, 0x55, 0xb5, 0xda, 0xfa, 0xbb, 0x12, 0x53, 0x3d, 0x3d, 0x37, 0xf7, + 0x8c, 0xb8, 0x07, 0x90, 0x85, 0x5a, 0x08, 0x24, 0x1b, 0xe0, 0x21, 0x1c, 0x39, 0xf9, 0xae, 0xe5, + 0x75, 0x1d, 0x39, 0xf9, 0x2e, 0xb6, 0x34, 0x1d, 0x52, 0xbd, 0xd1, 0x47, 0xad, 0x76, 0xbb, 0xd9, + 0xec, 0xdf, 0x6a, 0xe9, 0xd5, 0x09, 0x83, 0x1b, 0x7f, 0xd4, 0xb2, 0xc2, 0x0d, 0xf6, 0x90, 0x55, + 0x3f, 0x28, 0x10, 0x8a, 0x4c, 0x53, 0x1f, 0x6c, 0x3e, 0xb2, 0x2d, 0x50, 0xa9, 0xab, 0x95, 0x71, + 0xf4, 0xc0, 0x5e, 0xd3, 0x1f, 0xc3, 0xd5, 0x79, 0xf5, 0x26, 0xf6, 0xbd, 0x7e, 0x42, 0xb5, 0xe1, + 0x03, 0xc9, 0x35, 0x0d, 0x1b, 0xea, 0xc5, 0x5b, 0xcc, 0xd2, 0x17, 0xbd, 0x81, 0xae, 0xf0, 0x45, + 0xd5, 0x27, 0x37, 0x1b, 0xe1, 0x3b, 0x7b, 0xf7, 0x18, 0x19, 0x38, 0xaf, 0xb5, 0x34, 0xd4, 0xbf, + 0x6a, 0xf6, 0x67, 0x63, 0x06, 0x2b, 0x03, 0xa0, 0x1b, 0x82, 0x3f, 0x4d, 0x75, 0x6c, 0x64, 0x14, + 0xef, 0xbf, 0x73, 0x26, 0xeb, 0x63, 0xc5, 0x03, 0x7b, 0x76, 0x19, 0xbe, 0x99, 0x48, 0xb0, 0xbd, + 0x03, 0xff, 0xf5, 0xa7, 0xec, 0x0b, 0x92, 0x0a, 0x8b, 0x3c, 0xd8, 0xb1, 0xbb, 0x41, 0xf8, 0xdb, + 0x58, 0xc7, 0x46, 0x46, 0x71, 0xfd, 0x52, 0x17, 0x06, 0x7b, 0x07, 0x0c, 0xbf, 0x3c, 0xe8, 0xdf, + 0xdd, 0x60, 0xf4, 0x9c, 0x08, 0x07, 0x40, 0x36, 0x81, 0x50, 0xe4, 0x38, 0x80, 0xfd, 0xd4, 0x07, + 0x9c, 0xaf, 0xa9, 0x89, 0x49, 0x84, 0xdb, 0x42, 0x88, 0xf5, 0x0e, 0xa8, 0x7e, 0x5f, 0x4d, 0x65, + 0x39, 0x9e, 0xdc, 0xfe, 0x35, 0xdd, 0x4f, 0xeb, 0x01, 0x92, 0x67, 0xfb, 0xb3, 0xe7, 0x2f, 0x6b, + 0xbe, 0x2b, 0xb1, 0x4a, 0xae, 0x86, 0x7f, 0x77, 0x83, 0xe3, 0xd6, 0xb0, 0xc7, 0x7a, 0x07, 0x10, + 0xfb, 0xe0, 0x43, 0x43, 0xc2, 0xc0, 0x84, 0xc6, 0x0f, 0x70, 0x00, 0x64, 0x17, 0x08, 0x45, 0x9a, + 0x01, 0xb4, 0x52, 0x1f, 0xb0, 0x51, 0x62, 0xbd, 0x03, 0xb8, 0x18, 0x0a, 0x6b, 0xee, 0xaa, 0x6e, + 0xdb, 0xb4, 0x0e, 0x75, 0xb5, 0xf2, 0xcc, 0xce, 0xbe, 0xe9, 0x74, 0x5e, 0xbd, 0x89, 0x78, 0xe2, + 0x1e, 0x7a, 0xfa, 0x63, 0x39, 0x2d, 0x3d, 0x4e, 0xad, 0x60, 0x14, 0xb1, 0xcb, 0x9f, 0xab, 0xb1, + 0x91, 0x51, 0xf4, 0x75, 0xdf, 0x40, 0xac, 0xf7, 0xc3, 0x9c, 0x87, 0x09, 0x26, 0x35, 0x7e, 0x40, + 0xe0, 0x00, 0xf8, 0x7f, 0x93, 0x99, 0x6d, 0x99, 0x94, 0x53, 0x36, 0xc5, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 +}; +const unsigned int resources_FreeRDP_ico_len = 7240; diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/FreeRDP.ico.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/FreeRDP.ico.h new file mode 100644 index 0000000000000000000000000000000000000000..ce6f97c1b90f3f99650612b6a4101e21b2954e1c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/FreeRDP.ico.h @@ -0,0 +1,15 @@ +/* Generated from resources/FreeRDP.ico with xxd -i + * + * The icon must have the following properties: + * - resolution of 256x256 + * - no alpha + * - no alternate resolutions + */ + +#ifndef FREERDP_ICO_INTERNAL_ +#define FREERDP_ICO_INTERNAL_ + +extern const unsigned char resources_FreeRDP_ico[]; +extern const unsigned int resources_FreeRDP_ico_len; + +#endif /* FREERDP_ICO_INTERNAL_ */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_emulate.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_emulate.c new file mode 100644 index 0000000000000000000000000000000000000000..08de623bb7ab7aaec2d9c9b426d3824e419552c4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_emulate.c @@ -0,0 +1,2782 @@ +/** + * WinPR: Windows Portable Runtime + * Smart Card API emulation + * + * Copyright 2021 Armin Novak + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "FreeRDP.ico.h" + +#include "smartcard_virtual_gids.h" + +#define MAX_CACHE_ITEM_SIZE 4096 +#define MAX_CACHE_ITEM_VALUES 4096 + +static CHAR g_ReaderNameA[] = { 'F', 'r', 'e', 'e', 'R', 'D', 'P', ' ', 'E', + 'm', 'u', 'l', 'a', 't', 'o', 'r', '\0', '\0' }; +static INIT_ONCE g_ReaderNameWGuard = INIT_ONCE_STATIC_INIT; +static WCHAR g_ReaderNameW[32] = { 0 }; +static size_t g_ReaderNameWLen = 0; + +static char* card_id_and_name_a(const UUID* CardIdentifier, LPCSTR LookupName) +{ + WINPR_ASSERT(CardIdentifier); + WINPR_ASSERT(LookupName); + + size_t len = strlen(LookupName) + 34; + char* id = malloc(len); + if (!id) + return NULL; + + (void)snprintf(id, len, "%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X\\%s", + CardIdentifier->Data1, CardIdentifier->Data2, CardIdentifier->Data3, + CardIdentifier->Data4[0], CardIdentifier->Data4[1], CardIdentifier->Data4[2], + CardIdentifier->Data4[3], CardIdentifier->Data4[4], CardIdentifier->Data4[5], + CardIdentifier->Data4[6], CardIdentifier->Data4[7], LookupName); + return id; +} + +static char* card_id_and_name_w(const UUID* CardIdentifier, LPCWSTR LookupName) +{ + char* res = NULL; + char* tmp = ConvertWCharToUtf8Alloc(LookupName, NULL); + if (!tmp) + return NULL; + res = card_id_and_name_a(CardIdentifier, tmp); + free(tmp); + return res; +} + +static BOOL CALLBACK g_ReaderNameWInit(PINIT_ONCE InitOnce, PVOID Parameter, PVOID* Context) +{ + WINPR_UNUSED(InitOnce); + WINPR_UNUSED(Parameter); + WINPR_UNUSED(Context); + InitializeConstWCharFromUtf8(g_ReaderNameA, g_ReaderNameW, ARRAYSIZE(g_ReaderNameW)); + g_ReaderNameWLen = _wcsnlen(g_ReaderNameW, ARRAYSIZE(g_ReaderNameW) - 2) + 2; + return TRUE; +} + +struct smartcard_emulation_context +{ + const rdpSettings* settings; + DWORD log_default_level; + wLog* log; + wHashTable* contexts; + wHashTable* handles; + BOOL configured; + const char* pem; + const char* key; + const char* pin; +}; + +#define MAX_EMULATED_READERS 1 +typedef struct +{ + ULONG readerState; + SCARD_READERSTATEA readerStateA[MAX_EMULATED_READERS]; + SCARD_READERSTATEW readerStateW[MAX_EMULATED_READERS]; + wHashTable* cards; + wArrayList* strings; + wHashTable* cache; + BOOL canceled; +} SCardContext; + +typedef struct +{ + union + { + void* pv; + CHAR* pc; + WCHAR* pw; + } szReader; + BOOL unicode; + BOOL transaction; + DWORD transmitcount; + DWORD dwShareMode; + DWORD dwActiveProtocol; + SCARDCONTEXT hContext; + SCARDHANDLE card; + vgidsContext* vgids; + size_t referencecount; +} SCardHandle; + +typedef struct +{ + DWORD freshness; + DWORD size; + char data[MAX_CACHE_ITEM_SIZE]; +} SCardCacheItem; + +static SCardHandle* find_reader(SmartcardEmulationContext* smartcard, const void* szReader, + BOOL unicode); + +static const BYTE ATR[] = { 0x3b, 0xf7, 0x18, 0x00, 0x00, 0x80, 0x31, 0xfe, 0x45, + 0x73, 0x66, 0x74, 0x65, 0x2d, 0x6e, 0x66, 0xc4 }; + +static BOOL scard_status_transition(SCardContext* context) +{ + WINPR_ASSERT(context); + + switch (context->readerState) + { + default: + case 0: + { + SCARD_READERSTATEA* reader = &context->readerStateA[0]; + reader->szReader = g_ReaderNameA; + reader->dwEventState = SCARD_STATE_PRESENT; + reader->cbAtr = sizeof(ATR); + memcpy(reader->rgbAtr, ATR, sizeof(ATR)); + } + { + InitOnceExecuteOnce(&g_ReaderNameWGuard, g_ReaderNameWInit, NULL, NULL); + SCARD_READERSTATEW* reader = &context->readerStateW[0]; + reader->szReader = g_ReaderNameW; + reader->dwEventState = SCARD_STATE_PRESENT; + reader->cbAtr = sizeof(ATR); + memcpy(reader->rgbAtr, ATR, sizeof(ATR)); + } + context->readerState = 42; + break; + } + + return TRUE; +} + +static UINT32 scard_copy_strings(SCardContext* ctx, void* dst, size_t dstSize, const void* src, + size_t srcSize) +{ + WINPR_ASSERT(ctx); + WINPR_ASSERT(dst); + + WINPR_ASSERT(srcSize <= UINT32_MAX); + WINPR_ASSERT(dstSize <= UINT32_MAX); + + if (dstSize == SCARD_AUTOALLOCATE) + { + void* tmp = malloc(srcSize); + memcpy(tmp, src, srcSize); + ArrayList_Append(ctx->strings, tmp); + *((void**)dst) = tmp; + return (UINT32)srcSize; + } + else + { + const size_t min = MIN(dstSize, srcSize); + memcpy(dst, src, min); + return (UINT32)min; + } +} + +static void scard_context_free(void* context) +{ + SCardContext* ctx = context; + if (ctx) + { + HashTable_Free(ctx->cards); + ArrayList_Free(ctx->strings); + HashTable_Free(ctx->cache); + } + free(ctx); +} + +static SCardContext* scard_context_new(void) +{ + SCardContext* ctx = calloc(1, sizeof(SCardContext)); + if (!ctx) + return NULL; + + ctx->strings = ArrayList_New(FALSE); + if (!ctx->strings) + goto fail; + else + { + wObject* obj = ArrayList_Object(ctx->strings); + WINPR_ASSERT(obj); + obj->fnObjectFree = free; + } + + ctx->cache = HashTable_New(FALSE); + if (!ctx->cache) + goto fail; + if (!HashTable_SetupForStringData(ctx->cache, FALSE)) + goto fail; + else + { + wObject* val = HashTable_ValueObject(ctx->cache); + WINPR_ASSERT(val); + val->fnObjectFree = free; + } + + scard_status_transition(ctx); + return ctx; +fail: + scard_context_free(ctx); + return NULL; +} + +static void scard_handle_free(void* handle) +{ + SCardHandle* hdl = handle; + if (hdl) + { + free(hdl->szReader.pv); + vgids_free(hdl->vgids); + } + free(hdl); +} + +static SCardHandle* scard_handle_new(SmartcardEmulationContext* smartcard, SCARDCONTEXT context, + const void* name, BOOL unicode) +{ + SCardHandle* hdl = NULL; + + WINPR_ASSERT(smartcard); + + hdl = calloc(1, sizeof(SCardHandle)); + if (!hdl) + goto fail; + + /* ATTENTION: Do not use _strdup or _wcsdup! + * These strings are required to be double NULL terminated! + */ + if (unicode) + { + size_t s = _wcslen(name); + + hdl->szReader.pw = calloc(s + 2, sizeof(WCHAR)); + if (!hdl->szReader.pw) + goto fail; + memcpy(hdl->szReader.pv, name, s * sizeof(WCHAR)); + } + else + { + size_t s = strlen(name); + + hdl->szReader.pc = calloc(s + 2, sizeof(CHAR)); + if (!hdl->szReader.pc) + goto fail; + memcpy(hdl->szReader.pv, name, s * sizeof(CHAR)); + } + + if (!hdl->szReader.pv) + goto fail; + + hdl->vgids = vgids_new(); + if (!hdl->vgids) + goto fail; + + { + const char* pem = + freerdp_settings_get_string(smartcard->settings, FreeRDP_SmartcardCertificate); + const char* key = + freerdp_settings_get_string(smartcard->settings, FreeRDP_SmartcardPrivateKey); + + const char* pin = freerdp_settings_get_string(smartcard->settings, FreeRDP_Password); + + if (!vgids_init(hdl->vgids, pem, key, pin)) + goto fail; + } + + hdl->unicode = unicode; + hdl->hContext = context; + return hdl; + +fail: + scard_handle_free(hdl); + return NULL; +} + +static LONG scard_handle_valid(SmartcardEmulationContext* smartcard, SCARDHANDLE handle) +{ + SCardHandle* ctx = NULL; + + WINPR_ASSERT(smartcard); + + ctx = HashTable_GetItemValue(smartcard->handles, (const void*)handle); + if (!ctx) + return SCARD_E_INVALID_HANDLE; + + return SCARD_S_SUCCESS; +} + +static LONG scard_reader_name_valid_a(SmartcardEmulationContext* smartcard, SCARDCONTEXT context, + const char* name) +{ + SCardContext* ctx = NULL; + + WINPR_ASSERT(smartcard); + ctx = HashTable_GetItemValue(smartcard->contexts, (const void*)context); + + WINPR_ASSERT(name); + WINPR_ASSERT(ctx); + + for (size_t x = 0; x < MAX_EMULATED_READERS; x++) + { + const SCARD_READERSTATEA* reader = &ctx->readerStateA[x]; + if (strcmp(reader->szReader, name) == 0) + return SCARD_S_SUCCESS; + } + + return SCARD_E_UNKNOWN_READER; +} + +static LONG scard_reader_name_valid_w(SmartcardEmulationContext* smartcard, SCARDCONTEXT context, + const WCHAR* name) +{ + SCardContext* ctx = NULL; + + WINPR_ASSERT(smartcard); + ctx = HashTable_GetItemValue(smartcard->contexts, (const void*)context); + + WINPR_ASSERT(name); + WINPR_ASSERT(ctx); + + for (size_t x = 0; x < MAX_EMULATED_READERS; x++) + { + const SCARD_READERSTATEW* reader = &ctx->readerStateW[x]; + if (_wcscmp(reader->szReader, name) == 0) + return SCARD_S_SUCCESS; + } + + return SCARD_E_UNKNOWN_READER; +} + +/** + * Standard Windows Smart Card API + */ + +LONG WINAPI Emulate_SCardEstablishContext(SmartcardEmulationContext* smartcard, DWORD dwScope, + LPCVOID pvReserved1, LPCVOID pvReserved2, + LPSCARDCONTEXT phContext) +{ + LONG status = SCARD_E_NO_MEMORY; + SCardContext* ctx = NULL; + + WINPR_ASSERT(smartcard); + + ctx = scard_context_new(); + + WINPR_UNUSED(pvReserved1); + WINPR_UNUSED(pvReserved2); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardEstablishContext { dwScope: %s (0x%08" PRIX32 ")", + SCardGetScopeString(dwScope), dwScope); + + if (ctx) + { + SCARDCONTEXT context = { 0 }; + + winpr_RAND(&context, sizeof(SCARDCONTEXT)); + if (HashTable_Insert(smartcard->contexts, (const void*)context, ctx)) + { + *phContext = context; + status = SCARD_S_SUCCESS; + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardEstablishContext } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + if (status != SCARD_S_SUCCESS) + scard_context_free(ctx); + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): HashTable_Insert takes ownership of ctx + return status; +} + +LONG WINAPI Emulate_SCardReleaseContext(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext) +{ + LONG status = 0; + SCardContext* value = NULL; + + WINPR_ASSERT(smartcard); + + value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardReleaseContext { hContext: %p", + (void*)hContext); + + if (value) + HashTable_Remove(smartcard->contexts, (const void*)hContext); + + status = SCARD_S_SUCCESS; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardReleaseContext } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardIsValidContext(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext) +{ + LONG status = 0; + + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardIsValidContext { hContext: %p", + (void*)hContext); + + status = HashTable_Contains(smartcard->contexts, (const void*)hContext) + ? SCARD_S_SUCCESS + : SCARD_E_INVALID_HANDLE; + if (status == SCARD_S_SUCCESS) + { + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + if (!value) + return SCARD_F_INTERNAL_ERROR; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIsValidContext } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListReaderGroupsA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPSTR mszGroups /* NOLINT(readability-non-const-parameter) */, LPDWORD pcchGroups) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReaderGroupsA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(mszGroups); + WINPR_UNUSED(pcchGroups); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReaderGroupsA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListReaderGroupsW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPWSTR mszGroups /* NOLINT(readability-non-const-parameter) */, LPDWORD pcchGroups) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReaderGroupsW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(mszGroups); + WINPR_UNUSED(pcchGroups); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReaderGroupsW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListReadersA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + if (!pcchReaders) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardListReadersA { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(mszGroups); /* Not required */ + + if (SCARD_S_SUCCESS == status) + { + SCardContext* value = + (SCardContext*)HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + // TODO: If emulator not ready return SCARD_E_NO_READERS_AVAILABLE + + // TODO: argument mszGrous + + /* Return length only */ + if (!mszReaders) + *pcchReaders = ARRAYSIZE(g_ReaderNameA); + else + { + *pcchReaders = scard_copy_strings(value, mszReaders, *pcchReaders, g_ReaderNameA, + sizeof(g_ReaderNameA)); + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReadersA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListReadersW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCWSTR mszGroups, LPWSTR mszReaders, LPDWORD pcchReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!pcchReaders) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardListReadersW { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(mszGroups); /* Not required */ + + InitOnceExecuteOnce(&g_ReaderNameWGuard, g_ReaderNameWInit, NULL, NULL); + if (SCARD_S_SUCCESS == status) + { + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + // TODO: If emulator not ready return SCARD_E_NO_READERS_AVAILABLE + + // TODO: argument mszGrous + + /* Return length only */ + if (!mszReaders) + { + WINPR_ASSERT(g_ReaderNameWLen <= UINT32_MAX); + *pcchReaders = (UINT32)g_ReaderNameWLen; + } + else + { + *pcchReaders = scard_copy_strings(value, mszReaders, *pcchReaders, g_ReaderNameW, + g_ReaderNameWLen * sizeof(WCHAR)) / + sizeof(WCHAR); + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReadersW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListCardsA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCBYTE pbAtr, LPCGUID rgquidInterfaces, + DWORD cguidInterfaceCount, + CHAR* mszCards /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcchCards /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardListCardsA { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(pbAtr); + WINPR_UNUSED(rgquidInterfaces); + WINPR_UNUSED(cguidInterfaceCount); + WINPR_UNUSED(mszCards); + WINPR_UNUSED(pcchCards); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListCardsA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListCardsW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCBYTE pbAtr, LPCGUID rgquidInterfaces, + DWORD cguidInterfaceCount, + WCHAR* mszCards /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcchCards /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardListCardsW { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(pbAtr); + WINPR_UNUSED(rgquidInterfaces); + WINPR_UNUSED(cguidInterfaceCount); + WINPR_UNUSED(mszCards); + WINPR_UNUSED(pcchCards); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListCardsW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListInterfacesA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szCard, + LPGUID pguidInterfaces, LPDWORD pcguidInterfaces /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardListInterfacesA { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szCard); + WINPR_UNUSED(pguidInterfaces); + WINPR_UNUSED(pcguidInterfaces); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListInterfacesA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardListInterfacesW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szCard, + LPGUID pguidInterfaces, LPDWORD pcguidInterfaces /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardListInterfacesW { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szCard); + WINPR_UNUSED(pguidInterfaces); + WINPR_UNUSED(pcguidInterfaces); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListInterfacesW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetProviderIdA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCSTR szCard, LPGUID pguidProviderId) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetProviderIdA { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szCard); + WINPR_UNUSED(pguidProviderId); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetProviderIdA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetProviderIdW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCWSTR szCard, LPGUID pguidProviderId) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetProviderIdW { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szCard); + WINPR_UNUSED(pguidProviderId); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetProviderIdW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetCardTypeProviderNameA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szCardName, + DWORD dwProviderId, CHAR* szProvider /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcchProvider /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetCardTypeProviderNameA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szCardName); + WINPR_UNUSED(dwProviderId); + WINPR_UNUSED(szProvider); + WINPR_UNUSED(pcchProvider); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetCardTypeProviderNameA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardGetCardTypeProviderNameW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szCardName, + DWORD dwProviderId, WCHAR* szProvider /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcchProvider /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetCardTypeProviderNameW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szCardName); + WINPR_UNUSED(dwProviderId); + WINPR_UNUSED(szProvider); + WINPR_UNUSED(pcchProvider); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetCardTypeProviderNameW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardIntroduceReaderGroupA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceReaderGroupA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceReaderGroupA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardIntroduceReaderGroupW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceReaderGroupW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceReaderGroupW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardForgetReaderGroupA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetReaderGroupA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetReaderGroupA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardForgetReaderGroupW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetReaderGroupW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetReaderGroupW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardIntroduceReaderA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szReaderName, + LPCSTR szDeviceName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_a(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardIntroduceReaderA { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szDeviceName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceReaderA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardIntroduceReaderW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szReaderName, + LPCWSTR szDeviceName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_w(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardIntroduceReaderW { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szDeviceName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceReaderW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardForgetReaderA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCSTR szReaderName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_a(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardForgetReaderA { hContext: %p", + (void*)hContext); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetReaderA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardForgetReaderW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCWSTR szReaderName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_w(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardForgetReaderW { hContext: %p", + (void*)hContext); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetReaderW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardAddReaderToGroupA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szReaderName, + LPCSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_a(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardAddReaderToGroupA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardAddReaderToGroupA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardAddReaderToGroupW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szReaderName, + LPCWSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_w(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardAddReaderToGroupW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardAddReaderToGroupW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardRemoveReaderFromGroupA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szReaderName, + LPCSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_a(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardRemoveReaderFromGroupA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardRemoveReaderFromGroupA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardRemoveReaderFromGroupW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szReaderName, + LPCWSTR szGroupName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_w(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardRemoveReaderFromGroupW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szGroupName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardRemoveReaderFromGroupW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardIntroduceCardTypeA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szCardName, + LPCGUID pguidPrimaryProvider, LPCGUID rgguidInterfaces, + DWORD dwInterfaceCount, LPCBYTE pbAtr, + LPCBYTE pbAtrMask, DWORD cbAtrLen) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceCardTypeA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szCardName); + WINPR_UNUSED(pguidPrimaryProvider); + WINPR_UNUSED(rgguidInterfaces); + WINPR_UNUSED(dwInterfaceCount); + WINPR_UNUSED(pbAtr); + WINPR_UNUSED(pbAtrMask); + WINPR_UNUSED(cbAtrLen); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceCardTypeA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardIntroduceCardTypeW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szCardName, + LPCGUID pguidPrimaryProvider, LPCGUID rgguidInterfaces, + DWORD dwInterfaceCount, LPCBYTE pbAtr, + LPCBYTE pbAtrMask, DWORD cbAtrLen) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceCardTypeW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szCardName); + WINPR_UNUSED(pguidPrimaryProvider); + WINPR_UNUSED(rgguidInterfaces); + WINPR_UNUSED(dwInterfaceCount); + WINPR_UNUSED(pbAtr); + WINPR_UNUSED(pbAtrMask); + WINPR_UNUSED(cbAtrLen); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardIntroduceCardTypeW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardSetCardTypeProviderNameA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szCardName, + DWORD dwProviderId, LPCSTR szProvider) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardSetCardTypeProviderNameA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szCardName); + WINPR_UNUSED(dwProviderId); + WINPR_UNUSED(szProvider); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardSetCardTypeProviderNameA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardSetCardTypeProviderNameW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szCardName, + DWORD dwProviderId, LPCWSTR szProvider) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardSetCardTypeProviderNameA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szCardName); + WINPR_UNUSED(dwProviderId); + WINPR_UNUSED(szProvider); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardSetCardTypeProviderNameW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardForgetCardTypeA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szCardName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardForgetCardTypeA { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szCardName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetCardTypeA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardForgetCardTypeW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szCardName) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardForgetCardTypeW { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(szCardName); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardForgetCardTypeW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardFreeMemory(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPVOID pvMem) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardFreeMemory { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + ArrayList_Remove(value->strings, pvMem); + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardFreeMemory } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +HANDLE WINAPI Emulate_SCardAccessStartedEvent(SmartcardEmulationContext* smartcard) +{ + HANDLE hEvent = NULL; + + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardAccessStartedEvent {"); + + /* Not required, return random */ + winpr_RAND((void*)&hEvent, sizeof(hEvent)); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardAccessStartedEvent } hEvent: %p", + hEvent); + + return hEvent; +} + +void WINAPI Emulate_SCardReleaseStartedEvent(SmartcardEmulationContext* smartcard) +{ + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardReleaseStartedEvent {"); + + /* Not required, return not supported */ + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardReleaseStartedEvent }"); +} + +LONG WINAPI Emulate_SCardLocateCardsA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCSTR mszCards, LPSCARD_READERSTATEA rgReaderStates, + DWORD cReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardLocateCardsA { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(mszCards); + WINPR_UNUSED(rgReaderStates); + WINPR_UNUSED(cReaders); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardLocateCardsA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardLocateCardsW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCWSTR mszCards, LPSCARD_READERSTATEW rgReaderStates, + DWORD cReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardLocateCardsW { hContext: %p", + (void*)hContext); + + WINPR_UNUSED(mszCards); + WINPR_UNUSED(rgReaderStates); + WINPR_UNUSED(cReaders); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardLocateCardsW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardLocateCardsByATRA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPSCARD_ATRMASK rgAtrMasks, + DWORD cAtrs, LPSCARD_READERSTATEA rgReaderStates, + DWORD cReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardLocateCardsByATRA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(rgAtrMasks); + WINPR_UNUSED(cAtrs); + WINPR_UNUSED(rgReaderStates); + WINPR_UNUSED(cReaders); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardLocateCardsByATRA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardLocateCardsByATRW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPSCARD_ATRMASK rgAtrMasks, + DWORD cAtrs, LPSCARD_READERSTATEW rgReaderStates, + DWORD cReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardLocateCardsByATRW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(rgAtrMasks); + WINPR_UNUSED(cAtrs); + WINPR_UNUSED(rgReaderStates); + WINPR_UNUSED(cReaders); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardLocateCardsByATRW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetStatusChangeA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, DWORD dwTimeout, + LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetStatusChangeA { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + const DWORD diff = 100; + size_t eventCount = 0; + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + const freerdp* inst = freerdp_settings_get_pointer(smartcard->settings, FreeRDP_instance); + WINPR_ASSERT(inst); + + status = SCARD_E_TIMEOUT; + do + { + for (size_t x = 0; x < cReaders; x++) + { + LPSCARD_READERSTATEA out = &rgReaderStates[x]; + + for (size_t y = 0; y < MAX_EMULATED_READERS; y++) + { + const LPSCARD_READERSTATEA in = &value->readerStateA[y]; + if (strcmp(out->szReader, in->szReader) == 0) + { + const SCardHandle* hdl = find_reader(smartcard, in->szReader, FALSE); + out->dwEventState = in->dwEventState; + if (hdl) + { + out->dwEventState |= SCARD_STATE_INUSE; + if (hdl->dwShareMode == SCARD_SHARE_EXCLUSIVE) + out->dwEventState |= SCARD_STATE_EXCLUSIVE; + } + + if ((out->dwEventState & SCARD_STATE_EMPTY) != + (out->dwCurrentState & SCARD_STATE_EMPTY)) + out->dwEventState |= SCARD_STATE_CHANGED; + if ((out->dwEventState & SCARD_STATE_PRESENT) != + (out->dwCurrentState & SCARD_STATE_PRESENT)) + out->dwEventState |= SCARD_STATE_CHANGED; + + out->cbAtr = in->cbAtr; + memcpy(out->rgbAtr, in->rgbAtr, out->cbAtr); + if (out->dwEventState & SCARD_STATE_CHANGED) + eventCount++; + } + } + } + if (value->canceled) + { + status = SCARD_E_CANCELLED; + break; + } + if (eventCount != 0) + { + status = SCARD_S_SUCCESS; + break; + } + Sleep(diff); + if (dwTimeout != INFINITE) + dwTimeout -= MIN(dwTimeout, diff); + if (freerdp_shall_disconnect_context(inst->context)) + { + status = SCARD_E_CANCELLED; + break; + } + } while (dwTimeout > 0); + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetStatusChangeA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetStatusChangeW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, DWORD dwTimeout, + LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetStatusChangeW { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + const DWORD diff = 100; + size_t eventCount = 0; + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + const freerdp* inst = freerdp_settings_get_pointer(smartcard->settings, FreeRDP_instance); + WINPR_ASSERT(inst); + + status = SCARD_E_TIMEOUT; + do + { + for (size_t x = 0; x < cReaders; x++) + { + LPSCARD_READERSTATEW out = &rgReaderStates[x]; + + for (size_t y = 0; y < MAX_EMULATED_READERS; y++) + { + const LPSCARD_READERSTATEW in = &value->readerStateW[y]; + if (_wcscmp(out->szReader, in->szReader) == 0) + { + const SCardHandle* hdl = find_reader(smartcard, in->szReader, TRUE); + out->dwEventState = in->dwEventState; + if (hdl) + { + out->dwEventState |= SCARD_STATE_INUSE; + if (hdl->dwShareMode == SCARD_SHARE_EXCLUSIVE) + out->dwEventState |= SCARD_STATE_EXCLUSIVE; + } + if ((out->dwEventState & SCARD_STATE_EMPTY) != + (out->dwCurrentState & SCARD_STATE_EMPTY)) + out->dwEventState |= SCARD_STATE_CHANGED; + if ((out->dwEventState & SCARD_STATE_PRESENT) != + (out->dwCurrentState & SCARD_STATE_PRESENT)) + out->dwEventState |= SCARD_STATE_CHANGED; + out->cbAtr = in->cbAtr; + memcpy(out->rgbAtr, in->rgbAtr, out->cbAtr); + + if (out->dwEventState & SCARD_STATE_CHANGED) + eventCount++; + } + } + } + if (value->canceled) + { + status = SCARD_E_CANCELLED; + break; + } + if (eventCount != 0) + { + status = SCARD_S_SUCCESS; + break; + } + Sleep(diff); + if (dwTimeout != INFINITE) + dwTimeout -= MIN(dwTimeout, diff); + if (freerdp_shall_disconnect_context(inst->context)) + { + status = SCARD_E_CANCELLED; + break; + } + } while (dwTimeout > 0); + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetStatusChangeW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardCancel(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardCancel { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); + value->canceled = TRUE; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardCancel } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +SCardHandle* find_reader(SmartcardEmulationContext* smartcard, const void* szReader, BOOL unicode) +{ + SCardHandle* hdl = NULL; + UINT_PTR* keys = NULL; + size_t count = 0; + + WINPR_ASSERT(smartcard); + count = HashTable_GetKeys(smartcard->handles, &keys); + for (size_t x = 0; x < count; x++) + { + SCardHandle* cur = HashTable_GetItemValue(smartcard->handles, (const void*)keys[x]); + WINPR_ASSERT(cur); + + if (cur->unicode != unicode) + continue; + if (!unicode && (strcmp(cur->szReader.pc, szReader) != 0)) + continue; + if (unicode && (_wcscmp(cur->szReader.pw, szReader) != 0)) + continue; + hdl = cur; + break; + } + free(keys); + return hdl; +} + +static SCardHandle* reader2handle(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + const void* szReader, BOOL unicode, DWORD dwShareMode, + SCARDHANDLE* phCard, DWORD dwPreferredProtocols, + LPDWORD pdwActiveProtocol) +{ + SCardHandle* hdl = NULL; + + WINPR_ASSERT(phCard); + + *phCard = 0; + if (Emulate_SCardIsValidContext(smartcard, hContext) != SCARD_S_SUCCESS) + return NULL; + + hdl = scard_handle_new(smartcard, hContext, szReader, unicode); + if (hdl) + { + winpr_RAND(&hdl->card, sizeof(hdl->card)); + hdl->dwActiveProtocol = SCARD_PROTOCOL_T1; + hdl->dwShareMode = dwShareMode; + + if (!HashTable_Insert(smartcard->handles, (const void*)hdl->card, hdl)) + { + scard_handle_free(hdl); + hdl = NULL; + } + else + { + if (pdwActiveProtocol) + { + if ((hdl->dwActiveProtocol & dwPreferredProtocols) == 0) + { + scard_handle_free(hdl); + hdl = NULL; + } + else + *pdwActiveProtocol = hdl->dwActiveProtocol; + } + if (hdl) + { + hdl->referencecount++; + *phCard = hdl->card; + } + } + } + WLog_Print(smartcard->log, smartcard->log_default_level, "{ %p }", (void*)*phCard); + return hdl; +} + +LONG WINAPI Emulate_SCardConnectA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, + LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!phCard || !pdwActiveProtocol) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardConnectA { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + if (!reader2handle(smartcard, hContext, szReader, FALSE, dwShareMode, phCard, + dwPreferredProtocols, pdwActiveProtocol)) + status = SCARD_E_NO_MEMORY; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardConnectA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardConnectW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCWSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, + LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!phCard || !pdwActiveProtocol) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardConnectW { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + if (!reader2handle(smartcard, hContext, szReader, TRUE, dwShareMode, phCard, + dwPreferredProtocols, pdwActiveProtocol)) + status = SCARD_E_NO_MEMORY; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardConnectW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardReconnect(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + DWORD dwShareMode, DWORD dwPreferredProtocols, + DWORD dwInitialization, LPDWORD pdwActiveProtocol) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + if (!pdwActiveProtocol) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardReconnect { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + + // TODO: Implement + hdl->dwShareMode = dwShareMode; + hdl->transaction = FALSE; + + *pdwActiveProtocol = hdl->dwActiveProtocol; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardReconnect } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardDisconnect(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + DWORD dwDisposition) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardDisconnect { hCard: %p", + (void*)hCard); + + WINPR_UNUSED(dwDisposition); /* We just ignore this. All return values are static anyway */ + + if (status == SCARD_S_SUCCESS) + { + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + + hdl->referencecount--; + if (hdl->referencecount == 0) + HashTable_Remove(smartcard->handles, (const void*)hCard); + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardDisconnect } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardBeginTransaction(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardBeginTransaction { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + if (hdl->transaction) + status = SCARD_E_INVALID_VALUE; + else + hdl->transaction = TRUE; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardBeginTransaction } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardEndTransaction(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + DWORD dwDisposition) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardEndTransaction { hCard: %p", + (void*)hCard); + + WINPR_UNUSED(dwDisposition); /* We just ignore this. All return values are static anyway */ + + if (status == SCARD_S_SUCCESS) + { + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + if (!hdl->transaction) + status = SCARD_E_NOT_TRANSACTED; + else + hdl->transaction = FALSE; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardEndTransaction } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardCancelTransaction(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardCancelTransaction { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + if (!hdl->transaction) + status = SCARD_E_NOT_TRANSACTED; + else + hdl->transaction = FALSE; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardCancelTransaction } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardState(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, + LPDWORD pcbAtrLen) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + if (!pdwState || !pdwProtocol) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardState { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + + if (pdwState) + *pdwState = SCARD_SPECIFIC; + if (pdwProtocol) + *pdwProtocol = SCARD_PROTOCOL_T1; + + if (pcbAtrLen) + { + SCardContext* ctx = + HashTable_GetItemValue(smartcard->contexts, (const void*)hdl->hContext); + WINPR_ASSERT(ctx); + + for (size_t x = 0; x < MAX_EMULATED_READERS; x++) + { + const SCARD_READERSTATEA* readerA = &ctx->readerStateA[x]; + const SCARD_READERSTATEW* readerW = &ctx->readerStateW[x]; + if (hdl->unicode) + { + if (_wcscmp(readerW->szReader, hdl->szReader.pw) == 0) + { + *pcbAtrLen = scard_copy_strings(ctx, pbAtr, *pcbAtrLen, readerW->rgbAtr, + readerW->cbAtr); + } + } + else + { + if (strcmp(readerA->szReader, hdl->szReader.pc) == 0) + { + *pcbAtrLen = scard_copy_strings(ctx, pbAtr, *pcbAtrLen, readerA->rgbAtr, + readerA->cbAtr); + } + } + } + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardState } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardStatusA(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + LPSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, + LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardStatusA { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* ctx = NULL; + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + + ctx = HashTable_GetItemValue(smartcard->contexts, (const void*)hdl->hContext); + WINPR_ASSERT(ctx); + + if (pcchReaderLen) + *pcchReaderLen = + scard_copy_strings(ctx, mszReaderNames, *pcchReaderLen, hdl->szReader.pc, + (UINT32)strlen(hdl->szReader.pc) + 2); + + if (pdwState) + *pdwState = SCARD_SPECIFIC; + if (pdwProtocol) + *pdwProtocol = SCARD_PROTOCOL_T1; + + if (pcbAtrLen) + { + for (size_t x = 0; x < MAX_EMULATED_READERS; x++) + { + const SCARD_READERSTATEA* reader = &ctx->readerStateA[x]; + if (strcmp(reader->szReader, hdl->szReader.pc) == 0) + { + *pcbAtrLen = + scard_copy_strings(ctx, pbAtr, *pcbAtrLen, reader->rgbAtr, reader->cbAtr); + } + } + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardStatusA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardStatusW(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + LPWSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, + LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardStatusW { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* ctx = NULL; + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + + ctx = HashTable_GetItemValue(smartcard->contexts, (const void*)hdl->hContext); + WINPR_ASSERT(ctx); + + if (pcchReaderLen) + *pcchReaderLen = + scard_copy_strings(ctx, mszReaderNames, *pcchReaderLen, hdl->szReader.pw, + (UINT32)(_wcslen(hdl->szReader.pw) + 2) * sizeof(WCHAR)) / + sizeof(WCHAR); + + if (pdwState) + *pdwState = SCARD_SPECIFIC; + if (pdwProtocol) + *pdwProtocol = SCARD_PROTOCOL_T1; + + if (pcbAtrLen) + { + for (size_t x = 0; x < MAX_EMULATED_READERS; x++) + { + const SCARD_READERSTATEW* reader = &ctx->readerStateW[x]; + if (_wcscmp(reader->szReader, hdl->szReader.pw) == 0) + *pcbAtrLen = + scard_copy_strings(ctx, pbAtr, *pcbAtrLen, reader->rgbAtr, reader->cbAtr); + } + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardStatusW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardTransmit(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + LPCSCARD_IO_REQUEST pioSendPci, LPCBYTE pbSendBuffer, + DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, + LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + if (!pioSendPci || !pbSendBuffer || !pbRecvBuffer || !pcbRecvLength) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardTransmit { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + BYTE* response = NULL; + DWORD responseSize = 0; + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + + hdl->transmitcount++; + + if (!vgids_process_apdu(hdl->vgids, pbSendBuffer, cbSendLength, &response, &responseSize)) + status = SCARD_E_NO_SMARTCARD; + else + { + SCardContext* ctx = + HashTable_GetItemValue(smartcard->contexts, (const void*)hdl->hContext); + WINPR_ASSERT(ctx); + + *pcbRecvLength = + scard_copy_strings(ctx, pbRecvBuffer, *pcbRecvLength, response, responseSize); + free(response); + + /* Required */ + if (pioRecvPci) + pioRecvPci->dwProtocol = hdl->dwActiveProtocol; + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardTransmit } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardGetTransmitCount(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + LPDWORD pcTransmitCount) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + if (!pcTransmitCount) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetTransmitCount { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + SCardHandle* hdl = HashTable_GetItemValue(smartcard->handles, (const void*)hCard); + WINPR_ASSERT(hdl); + + *pcTransmitCount = hdl->transmitcount; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetTransmitCount } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardControl( + SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, DWORD dwControlCode, + LPCVOID lpInBuffer, DWORD cbInBufferSize, LPVOID lpOutBuffer, DWORD cbOutBufferSize, + LPDWORD lpBytesReturned /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardControl { hCard: %p", + (void*)hCard); + + if (status == SCARD_S_SUCCESS) + { + WINPR_UNUSED(dwControlCode); + WINPR_UNUSED(lpInBuffer); + WINPR_UNUSED(cbInBufferSize); + WINPR_UNUSED(lpOutBuffer); + WINPR_UNUSED(cbOutBufferSize); + WINPR_UNUSED(lpBytesReturned); + + /* Not required, return not supported */ + status = SCARD_E_UNSUPPORTED_FEATURE; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardControl } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardGetAttrib(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + DWORD dwAttrId, + LPBYTE pbAttr /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcbAttrLen /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetAttrib { hCard: %p", + (void*)hCard); + + WINPR_UNUSED(dwAttrId); + WINPR_UNUSED(pbAttr); + WINPR_UNUSED(pcbAttrLen); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_F_INTERNAL_ERROR; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetAttrib } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardSetAttrib(SmartcardEmulationContext* smartcard, SCARDHANDLE hCard, + DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen) +{ + LONG status = scard_handle_valid(smartcard, hCard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardSetAttrib { hCard: %p", + (void*)hCard); + + WINPR_UNUSED(dwAttrId); + WINPR_UNUSED(pbAttr); + WINPR_UNUSED(cbAttrLen); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_F_INTERNAL_ERROR; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardSetAttrib } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardUIDlgSelectCardA(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEA_EX pDlgStruc) +{ + LONG status = 0; + + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardUIDlgSelectCardA {"); + + WINPR_UNUSED(pDlgStruc); + + /* Not required, return not supported */ + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardUIDlgSelectCardA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardUIDlgSelectCardW(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEW_EX pDlgStruc) +{ + LONG status = 0; + + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardUIDlgSelectCardW {"); + + WINPR_UNUSED(pDlgStruc); + + /* Not required, return not supported */ + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardUIDlgSelectCardW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_GetOpenCardNameA(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEA pDlgStruc) +{ + LONG status = 0; + + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "GetOpenCardNameA {"); + + WINPR_UNUSED(pDlgStruc); + + /* Not required, return not supported */ + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "GetOpenCardNameA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_GetOpenCardNameW(SmartcardEmulationContext* smartcard, + LPOPENCARDNAMEW pDlgStruc) +{ + LONG status = 0; + + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "GetOpenCardNameW {"); + + WINPR_UNUSED(pDlgStruc); + + /* Not required, return not supported */ + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "GetOpenCardNameW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardDlgExtendedError(SmartcardEmulationContext* smartcard) +{ + LONG status = 0; + + WINPR_ASSERT(smartcard); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardDlgExtendedError {"); + + /* Not required, return not supported */ + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardDlgExtendedError } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardReadCacheA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + UUID* CardIdentifier, DWORD FreshnessCounter, LPSTR LookupName, + PBYTE Data, DWORD* DataLen) +{ + DWORD count = 0; + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!CardIdentifier || !DataLen) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardReadCacheA { hContext: %p", + (void*)hContext); + + if (DataLen) + { + count = *DataLen; + *DataLen = 0; + } + + if (status == SCARD_S_SUCCESS) + { + SCardCacheItem* data = NULL; + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + char* id = card_id_and_name_a(CardIdentifier, LookupName); + data = HashTable_GetItemValue(value->cache, id); + free(id); + + if (!data) + status = SCARD_W_CACHE_ITEM_NOT_FOUND; + else if (data->freshness != FreshnessCounter) + status = SCARD_W_CACHE_ITEM_STALE; + else + *DataLen = scard_copy_strings(value, Data, count, data->data, data->size); + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardReadCacheA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardReadCacheW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + UUID* CardIdentifier, DWORD FreshnessCounter, LPWSTR LookupName, + PBYTE Data, DWORD* DataLen) +{ + DWORD count = 0; + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!CardIdentifier || !DataLen) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardReadCacheW { hContext: %p", + (void*)hContext); + + if (DataLen) + { + count = *DataLen; + *DataLen = 0; + } + + if (status == SCARD_S_SUCCESS) + { + SCardCacheItem* data = NULL; + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + char* id = card_id_and_name_w(CardIdentifier, LookupName); + data = HashTable_GetItemValue(value->cache, id); + free(id); + if (!data) + status = SCARD_W_CACHE_ITEM_NOT_FOUND; + else if (data->freshness != FreshnessCounter) + status = SCARD_W_CACHE_ITEM_STALE; + else + *DataLen = scard_copy_strings(value, Data, count, data->data, data->size); + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardReadCacheW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +static LONG insert_data(wHashTable* table, DWORD FreshnessCounter, const char* key, + const PBYTE Data, DWORD DataLen) +{ + BOOL rc = 0; + SCardCacheItem* item = NULL; + + WINPR_ASSERT(table); + WINPR_ASSERT(key); + + if (DataLen > MAX_CACHE_ITEM_SIZE) + return SCARD_W_CACHE_ITEM_TOO_BIG; + + if (HashTable_Count(table) > MAX_CACHE_ITEM_VALUES) + return SCARD_E_WRITE_TOO_MANY; + + item = HashTable_GetItemValue(table, key); + if (!item) + { + item = calloc(1, sizeof(SCardCacheItem)); + if (!item) + return SCARD_E_NO_MEMORY; + + rc = HashTable_Insert(table, key, item); + if (!rc) + { + free(item); + return SCARD_E_NO_MEMORY; + } + } + + if (item->freshness > FreshnessCounter) + return SCARD_W_CACHE_ITEM_STALE; + item->freshness = FreshnessCounter; + item->size = DataLen; + memcpy(item->data, Data, DataLen); + + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc): HashTable_Insert takes ownership of item + return SCARD_S_SUCCESS; +} + +LONG WINAPI Emulate_SCardWriteCacheA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + UUID* CardIdentifier, DWORD FreshnessCounter, LPSTR LookupName, + PBYTE Data, DWORD DataLen) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!CardIdentifier) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardWriteCacheA { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + char* id = card_id_and_name_a(CardIdentifier, LookupName); + if (!id) + status = SCARD_E_NO_MEMORY; + else + { + status = insert_data(value->cache, FreshnessCounter, id, Data, DataLen); + free(id); + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardWriteCacheA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardWriteCacheW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + UUID* CardIdentifier, DWORD FreshnessCounter, + LPWSTR LookupName, PBYTE Data, DWORD DataLen) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!CardIdentifier) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardWriteCacheW { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* value = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(value); /* Must be valid after Emulate_SCardIsValidContext */ + + char* id = card_id_and_name_w(CardIdentifier, LookupName); + if (!id) + status = SCARD_E_NO_MEMORY; + else + { + status = insert_data(value->cache, FreshnessCounter, id, Data, DataLen); + free(id); + } + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardWriteCacheW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetReaderIconA(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCSTR szReaderName, LPBYTE pbIcon, LPDWORD pcbIcon) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!szReaderName || !pcbIcon) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetReaderIconA { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_a(smartcard, hContext, szReaderName); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* ctx = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(ctx); + + if (pbIcon) + *pcbIcon = scard_copy_strings(ctx, pbIcon, *pcbIcon, resources_FreeRDP_ico, + resources_FreeRDP_ico_len); + else + *pcbIcon = resources_FreeRDP_ico_len; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetReaderIconA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetReaderIconW(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + LPCWSTR szReaderName, LPBYTE pbIcon, LPDWORD pcbIcon) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!szReaderName || !pcbIcon) + status = SCARD_E_INVALID_PARAMETER; + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetReaderIconW { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_w(smartcard, hContext, szReaderName); + + if (status == SCARD_S_SUCCESS) + { + SCardContext* ctx = HashTable_GetItemValue(smartcard->contexts, (const void*)hContext); + WINPR_ASSERT(ctx); + + if (pbIcon) + *pcbIcon = scard_copy_strings(ctx, pbIcon, *pcbIcon, resources_FreeRDP_ico, + resources_FreeRDP_ico_len); + else + *pcbIcon = resources_FreeRDP_ico_len; + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetReaderIconW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetDeviceTypeIdA(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCSTR szReaderName, + LPDWORD pdwDeviceTypeId) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!pdwDeviceTypeId) + status = SCARD_E_INVALID_PARAMETER; + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_a(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetDeviceTypeIdA { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + *pdwDeviceTypeId = SCARD_READER_TYPE_USB; // SCARD_READER_TYPE_TPM + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetDeviceTypeIdA } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetDeviceTypeIdW(SmartcardEmulationContext* smartcard, + SCARDCONTEXT hContext, LPCWSTR szReaderName, + LPDWORD pdwDeviceTypeId) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (!pdwDeviceTypeId) + status = SCARD_E_INVALID_PARAMETER; + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_w(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardGetDeviceTypeIdW { hContext: %p", + (void*)hContext); + + if (status == SCARD_S_SUCCESS) + { + *pdwDeviceTypeId = SCARD_READER_TYPE_USB; // SCARD_READER_TYPE_TPM + } + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetDeviceTypeIdW } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), + status); + + return status; +} + +LONG WINAPI Emulate_SCardGetReaderDeviceInstanceIdA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szReaderName, + LPSTR szDeviceInstanceId /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcchDeviceInstanceId /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_a(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetReaderDeviceInstanceIdA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szDeviceInstanceId); + WINPR_UNUSED(pcchDeviceInstanceId); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetReaderDeviceInstanceIdA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardGetReaderDeviceInstanceIdW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szReaderName, + LPWSTR szDeviceInstanceId /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcchDeviceInstanceId /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + if (status == SCARD_S_SUCCESS) + status = scard_reader_name_valid_w(smartcard, hContext, szReaderName); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetReaderDeviceInstanceIdW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szDeviceInstanceId); + WINPR_UNUSED(pcchDeviceInstanceId); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardGetReaderDeviceInstanceIdW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardListReadersWithDeviceInstanceIdA( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCSTR szDeviceInstanceId, + LPSTR mszReaders /* NOLINT(readability-non-const-parameter) */, + LPDWORD pcchReaders /* NOLINT(readability-non-const-parameter) */) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReadersWithDeviceInstanceIdA { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szDeviceInstanceId); + WINPR_UNUSED(mszReaders); + WINPR_UNUSED(pcchReaders); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReadersWithDeviceInstanceIdA } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardListReadersWithDeviceInstanceIdW( + SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, LPCWSTR szDeviceInstanceId, + LPWSTR mszReaders /* NOLINT(readability-non-const-parameter) */, LPDWORD pcchReaders) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReadersWithDeviceInstanceIdW { hContext: %p", (void*)hContext); + + WINPR_UNUSED(szDeviceInstanceId); + WINPR_UNUSED(mszReaders); + WINPR_UNUSED(pcchReaders); + + /* Not required, return not supported */ + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardListReadersWithDeviceInstanceIdW } status: %s (0x%08" PRIX32 ")", + SCardGetErrorString(status), status); + + return status; +} + +LONG WINAPI Emulate_SCardAudit(SmartcardEmulationContext* smartcard, SCARDCONTEXT hContext, + DWORD dwEvent) +{ + LONG status = Emulate_SCardIsValidContext(smartcard, hContext); + + WINPR_UNUSED(dwEvent); + + WLog_Print(smartcard->log, smartcard->log_default_level, "SCardAudit { hContext: %p", + (void*)hContext); + + // TODO: Implement + if (status == SCARD_S_SUCCESS) + status = SCARD_E_UNSUPPORTED_FEATURE; + + WLog_Print(smartcard->log, smartcard->log_default_level, + "SCardAudit } status: %s (0x%08" PRIX32 ")", SCardGetErrorString(status), status); + + return status; +} + +static BOOL context_equals(const void* pva, const void* pvb) +{ + const SCARDCONTEXT a = (const SCARDCONTEXT)pva; + const SCARDCONTEXT b = (const SCARDCONTEXT)pvb; + if (!a && !b) + return TRUE; + if (!a || !b) + return FALSE; + + return a == b; +} + +static BOOL handle_equals(const void* pva, const void* pvb) +{ + const SCARDHANDLE a = (const SCARDHANDLE)pva; + const SCARDHANDLE b = (const SCARDHANDLE)pvb; + if (!a && !b) + return TRUE; + if (!a || !b) + return FALSE; + + return a == b; +} + +SmartcardEmulationContext* Emulate_New(const rdpSettings* settings) +{ + SmartcardEmulationContext* smartcard = NULL; + + WINPR_ASSERT(settings); + + smartcard = calloc(1, sizeof(SmartcardEmulationContext)); + if (!smartcard) + goto fail; + + smartcard->settings = settings; + smartcard->log = WLog_Get("EmulateSCard"); + if (!smartcard->log) + goto fail; + smartcard->log_default_level = WLOG_TRACE; + + smartcard->contexts = HashTable_New(FALSE); + if (!smartcard->contexts) + goto fail; + else + { + wObject* obj = HashTable_KeyObject(smartcard->contexts); + WINPR_ASSERT(obj); + obj->fnObjectEquals = context_equals; + } + if (!smartcard->contexts) + goto fail; + else + { + wObject* obj = HashTable_ValueObject(smartcard->contexts); + WINPR_ASSERT(obj); + obj->fnObjectFree = scard_context_free; + } + + smartcard->handles = HashTable_New(FALSE); + if (!smartcard->handles) + goto fail; + else + { + wObject* obj = HashTable_KeyObject(smartcard->handles); + WINPR_ASSERT(obj); + obj->fnObjectEquals = handle_equals; + } + if (!smartcard->handles) + goto fail; + else + { + wObject* obj = HashTable_ValueObject(smartcard->handles); + WINPR_ASSERT(obj); + obj->fnObjectFree = scard_handle_free; + } + + return smartcard; + +fail: + WINPR_PRAGMA_DIAG_PUSH + WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC + Emulate_Free(smartcard); + WINPR_PRAGMA_DIAG_POP + return NULL; +} + +void Emulate_Free(SmartcardEmulationContext* context) +{ + if (!context) + return; + + HashTable_Free(context->handles); + HashTable_Free(context->contexts); + free(context); +} + +BOOL Emulate_IsConfigured(SmartcardEmulationContext* context) +{ + BOOL rc = FALSE; + vgidsContext* vgids = NULL; + const char* pem = NULL; + const char* key = NULL; + const char* pin = NULL; + + WINPR_ASSERT(context); + + pem = freerdp_settings_get_string(context->settings, FreeRDP_SmartcardCertificate); + key = freerdp_settings_get_string(context->settings, FreeRDP_SmartcardPrivateKey); + pin = freerdp_settings_get_string(context->settings, FreeRDP_Password); + + /* Cache result only, if no initialization arguments changed. */ + if ((context->pem == pem) && (context->key == key) && (context->pin == pin)) + return context->configured; + + context->pem = pem; + context->key = key; + context->pin = pin; + + vgids = vgids_new(); + if (vgids) + rc = vgids_init(vgids, context->pem, context->key, context->pin); + vgids_free(vgids); + + context->configured = rc; + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_virtual_gids.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_virtual_gids.c new file mode 100644 index 0000000000000000000000000000000000000000..1cbfe2a49977a44e84950ec0146cc049ba638ca7 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_virtual_gids.c @@ -0,0 +1,1637 @@ +/** + * WinPR: Windows Portable Runtime + * Virtual GIDS implementation + * + * Copyright 2021 Martin Fleisz + * Copyright 2023 Armin Novak + * Copyright 2021,2023 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include + +#include + +#include "../../crypto/certificate.h" +#include "../../crypto/privatekey.h" +#include "smartcard_virtual_gids.h" + +#define TAG CHANNELS_TAG("smartcard.vgids") + +#define VGIDS_EFID_MASTER 0xA000 +#define VGIDS_EFID_COMMON 0xA010 +// #define VGIDS_EFID_CARDCF VGIDS_EFID_COMMON +// #define VGIDS_EFID_CARDAPPS VGIDS_EFID_COMMON +// #define VGIDS_EFID_CMAPFILE VGIDS_EFID_COMMON +#define VGIDS_EFID_CARDID 0xA012 +// #define VGIDS_EFID_KXC00 VGIDS_EFID_COMMON +#define VGIDS_EFID_CURRENTDF 0x3FFF + +#define VGIDS_DO_FILESYSTEMTABLE 0xDF1F +#define VGIDS_DO_KEYMAP 0xDF20 +#define VGIDS_DO_CARDID 0xDF20 +#define VGIDS_DO_CARDAPPS 0xDF21 +#define VGIDS_DO_CARDCF 0xDF22 +#define VGIDS_DO_CMAPFILE 0xDF23 +#define VGIDS_DO_KXC00 0xDF24 + +#define VGIDS_CARDID_SIZE 16 +#define VGIDS_MAX_PIN_SIZE 127 + +#define VGIDS_DEFAULT_RETRY_COUNTER 3 + +#define VGIDS_KEY_TYPE_KEYEXCHANGE 0x9A +// #define VGIDS_KEY_TYPE_SIGNATURE 0x9C + +#define VGIDS_ALGID_RSA_1024 0x06 +#define VGIDS_ALGID_RSA_2048 0x07 +#define VGIDS_ALGID_RSA_3072 0x08 +#define VGIDS_ALGID_RSA_4096 0x09 + +// #define VGIDS_SE_CRT_AUTH 0xA4 +#define VGIDS_SE_CRT_SIGN 0xB6 +#define VGIDS_SE_CRT_CONF 0xB8 + +#define VGIDS_SE_ALGOID_CT_PAD_PKCS1 0x40 +#define VGIDS_SE_ALGOID_CT_PAD_OAEP 0x80 +// #define VGIDS_SE_ALGOID_CT_RSA_1024 0x06 +// #define VGIDS_SE_ALGOID_CT_RSA_2048 0x07 +// #define VGIDS_SE_ALGOID_CT_RSA_3072 0x08 +// #define VGIDS_SE_ALGOID_CT_RSA_4096 0x09 + +#define VGIDS_SE_ALGOID_DST_PAD_PKCS1 0x40 +#define VGIDS_SE_ALGOID_DST_RSA_1024 0x06 +#define VGIDS_SE_ALGOID_DST_RSA_2048 0x07 +#define VGIDS_SE_ALGOID_DST_RSA_3072 0x08 +#define VGIDS_SE_ALGOID_DST_RSA_4096 0x09 +#define VGIDS_SE_ALGOID_DST_ECDSA_P192 0x0A +#define VGIDS_SE_ALGOID_DST_ECDSA_P224 0x0B +#define VGIDS_SE_ALGOID_DST_ECDSA_P256 0x0C +#define VGIDS_SE_ALGOID_DST_ECDSA_P384 0x0D +#define VGIDS_SE_ALGOID_DST_ECDSA_P512 0x0E + +#define VGIDS_DEFAULT_KEY_REF 0x81 + +#define ISO_INS_SELECT 0xA4 +#define ISO_INS_GETDATA 0xCB +#define ISO_INS_GETRESPONSE 0xC0 +#define ISO_INS_MSE 0x22 +#define ISO_INS_PSO 0x2A +#define ISO_INS_VERIFY 0x20 + +#define ISO_STATUS_MORE_DATA 0x6100 +#define ISO_STATUS_VERIFYFAILED 0x6300 +#define ISO_STATUS_WRONGLC 0x6700 +#define ISO_STATUS_COMMANDNOTALLOWED 0x6900 +#define ISO_STATUS_SECURITYSTATUSNOTSATISFIED 0x6982 +#define ISO_STATUS_AUTHMETHODBLOCKED 0x6983 +#define ISO_STATUS_INVALIDCOMMANDDATA 0x6A80 +#define ISO_STATUS_FILENOTFOUND 0x6A82 +#define ISO_STATUS_INVALIDP1P2 0x6A86 +#define ISO_STATUS_INVALIDLC 0x6A87 +#define ISO_STATUS_REFERENCEDATANOTFOUND 0x6A88 +#define ISO_STATUS_SUCCESS 0x9000 + +#define ISO_AID_MAX_SIZE 16 + +#define ISO_FID_MF 0x3F00 + +struct vgids_ef +{ + UINT16 id; + UINT16 dirID; + wStream* data; +}; +typedef struct vgids_ef vgidsEF; + +struct vgids_se +{ + BYTE crt; /* control reference template tag */ + BYTE algoId; /* Algorithm ID */ + BYTE keyRef; /* Key reference */ +}; +typedef struct vgids_se vgidsSE; + +struct vgids_context +{ + UINT16 currentDF; + char* pin; + UINT16 curRetryCounter; + UINT16 retryCounter; + wStream* commandData; + wStream* responseData; + BOOL pinVerified; + vgidsSE currentSE; + + rdpCertificate* certificate; + rdpPrivateKey* privateKey; + + wArrayList* files; +}; + +/* PKCS 1.5 DER encoded digest information */ +#define VGIDS_MAX_DIGEST_INFO 7 + +static const BYTE g_PKCS1_SHA1[] = { 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, + 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 }; +static const BYTE g_PKCS1_SHA224[] = { 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1c }; +static const BYTE g_PKCS1_SHA256[] = { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 }; +static const BYTE g_PKCS1_SHA384[] = { 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 }; +static const BYTE g_PKCS1_SHA512[] = { 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, + 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 }; +static const BYTE g_PKCS1_SHA512_224[] = { 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 0x60, + 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, + 0x05, 0x05, 0x00, 0x04, 0x1c }; +static const BYTE g_PKCS1_SHA512_256[] = { 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, + 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, + 0x06, 0x05, 0x00, 0x04, 0x20 }; + +/* Helper struct to map PKCS1.5 digest info to OpenSSL EVP_MD */ +struct vgids_digest_info_map +{ + const BYTE* info; + size_t infoSize; + const EVP_MD* digest; +}; +typedef struct vgids_digest_info_map vgidsDigestInfoMap; + +/* MS GIDS AID */ +/* xx: Used by the Windows smart card framework for the GIDS version number. This byte must be set + * to the GIDS specification revision number which is either 0x01 or 0x02. + * yy: Reserved for use by the card application (set to 01) + */ +static const BYTE g_MsGidsAID[] = { + 0xA0, 0x00, 0x00, 0x03, 0x97, 0x42, 0x54, 0x46, 0x59, 0x02, 0x01 +}; + +/* GIDS APP File Control Parameter: + FD-Byte (82): 38 (not shareable-DF) + Sec Attr (8C): 03 30 30 Create/Delete File(03) Ext/User-Auth (30) +*/ +static const BYTE g_GidsAppFCP[] = { 0x62, 0x08, 0x82, 0x01, 0x38, 0x8C, 0x03, 0x03, 0x30, 0x30 }; +/* GIDS APP File Control Information: + AppID (4F, Len 0B): A0 00 00 03 97 42 54 46 59 02 01 + Discretionary DOs (73, Len 03): 40 01 C0 + Supported Auth Protocols (40, Len 01): C0 Mutual/External-Auth + */ +static const BYTE g_GidsAppFCI[] = { 0x61, 0x12, 0x4F, 0x0B, 0xA0, 0x00, 0x00, 0x03, 0x97, 0x42, + 0x54, 0x46, 0x59, 0x02, 0x01, 0x73, 0x03, 0x40, 0x01, 0xC0 }; + +/* +typedef struct +{ + BYTE bVersion; // Cache version + BYTE bPinsFreshness; // Card PIN + WORD wContainersFreshness; + WORD wFilesFreshness; +} CARD_CACHE_FILE_FORMAT, *PCARD_CACHE_FILE_FORMAT; */ +static const BYTE g_CardCFContents[] = { 0x00, 0x00, 0x01, 0x00, 0x04, 0x00 }; + +/* {‘mscp’,0,0,0,0} */ +static const BYTE g_CardAppsContents[] = { 0x6d, 0x73, 0x63, 0x70, 0x00, 0x00, 0x00, 0x00 }; + +#pragma pack(push, 1) + +/* Type: CONTAINER_MAP_RECORD (taken from Windows Smart Card Minidriver Specification) + + This structure describes the format of the Base CSP's + container map file, stored on the card. This is wellknown + logical file wszCONTAINER_MAP_FILE. The file consists of + zero or more of these records. */ +#define MAX_CONTAINER_NAME_LEN 39 + +/* This flag is set in the CONTAINER_MAP_RECORD bFlags + member if the corresponding container is valid and currently + exists on the card. // If the container is deleted, its + bFlags field must be cleared. */ +#define CONTAINER_MAP_VALID_CONTAINER 1 + +/* This flag is set in the CONTAINER_MAP_RECORD bFlags + member if the corresponding container is the default + container on the card. */ +#define CONTAINER_MAP_DEFAULT_CONTAINER 2 + +struct vgids_container_map_entry +{ + WCHAR wszGuid[MAX_CONTAINER_NAME_LEN + 1]; + BYTE bFlags; + BYTE bReserved; + WORD wSigKeySizeBits; + WORD wKeyExchangeKeySizeBits; +}; +typedef struct vgids_container_map_entry vgidsContainerMapEntry; + +struct vgids_filesys_table_entry +{ + char directory[9]; + char filename[9]; + UINT16 pad0; + UINT16 dataObjectIdentifier; + UINT16 pad1; + UINT16 fileIdentifier; + UINT16 unknown; +}; +typedef struct vgids_filesys_table_entry vgidsFilesysTableEntry; + +struct vgids_keymap_record +{ + UINT32 state; + BYTE algid; + BYTE keytype; + UINT16 keyref; + UINT16 unknownWithFFFF; + UINT16 unknownWith0000; +}; +typedef struct vgids_keymap_record vgidsKeymapRecord; + +#pragma pack(pop) + +static void vgids_ef_free(void* ptr); + +static vgidsEF* vgids_ef_new(vgidsContext* ctx, USHORT id) +{ + vgidsEF* ef = calloc(1, sizeof(vgidsEF)); + + ef->id = id; + ef->data = Stream_New(NULL, 1024); + if (!ef->data) + { + WLog_ERR(TAG, "Failed to create file data stream"); + goto create_failed; + } + Stream_SetLength(ef->data, 0); + + if (!ArrayList_Append(ctx->files, ef)) + { + WLog_ERR(TAG, "Failed to add new ef to file list"); + goto create_failed; + } + + return ef; + +create_failed: + vgids_ef_free(ef); + return NULL; +} + +static BOOL vgids_write_tlv(wStream* s, UINT16 tag, const void* data, size_t dataSize) +{ + WINPR_ASSERT(dataSize <= UINT16_MAX); + + /* A maximum of 5 additional bytes is needed */ + if (!Stream_EnsureRemainingCapacity(s, dataSize + 5)) + { + WLog_ERR(TAG, "Failed to ensure capacity of DO stream"); + return FALSE; + } + + /* BER encoding: If the most-significant bit is set (0x80) the length is encoded in the + * remaining bits. So lengths < 128 bytes can be set directly, all others are encoded */ + if (tag > 0xFF) + Stream_Write_UINT16_BE(s, tag); + else + Stream_Write_UINT8(s, (BYTE)tag); + if (dataSize < 128) + { + Stream_Write_UINT8(s, (BYTE)dataSize); + } + else if (dataSize < 256) + { + Stream_Write_UINT8(s, 0x81); + Stream_Write_UINT8(s, (BYTE)dataSize); + } + else + { + Stream_Write_UINT8(s, 0x82); + Stream_Write_UINT16_BE(s, (UINT16)dataSize); + } + Stream_Write(s, data, dataSize); + Stream_SealLength(s); + return TRUE; +} + +static BOOL vgids_ef_write_do(vgidsEF* ef, UINT16 doID, const void* data, DWORD dataSize) +{ + /* Write DO to end of file: 2-Byte ID, 1-Byte Len, Data */ + return vgids_write_tlv(ef->data, doID, data, dataSize); +} + +static BOOL vgids_ef_read_do(vgidsEF* ef, UINT16 doID, BYTE** data, DWORD* dataSize) +{ + /* Read the given DO from the file: 2-Byte ID, 1-Byte Len, Data */ + if (!Stream_SetPosition(ef->data, 0)) + { + WLog_ERR(TAG, "Failed to seek to front of file"); + return FALSE; + } + + /* Look for the requested DO */ + while (Stream_GetRemainingLength(ef->data) > 3) + { + BYTE len = 0; + size_t curPos = 0; + UINT16 doSize = 0; + UINT16 nextDOID = 0; + + curPos = Stream_GetPosition(ef->data); + Stream_Read_UINT16_BE(ef->data, nextDOID); + Stream_Read_UINT8(ef->data, len); + if ((len & 0x80)) + { + BYTE lenSize = len & 0x7F; + if (!Stream_CheckAndLogRequiredLength(TAG, ef->data, lenSize)) + return FALSE; + + switch (lenSize) + { + case 1: + Stream_Read_UINT8(ef->data, doSize); + break; + case 2: + Stream_Read_UINT16_BE(ef->data, doSize); + break; + default: + WLog_ERR(TAG, "Unexpected tag length %" PRIu8, lenSize); + return FALSE; + } + } + else + doSize = len; + + if (!Stream_CheckAndLogRequiredLength(TAG, ef->data, doSize)) + return FALSE; + + if (nextDOID == doID) + { + BYTE* outData = NULL; + + /* Include Tag and length in result */ + doSize += (UINT16)(Stream_GetPosition(ef->data) - curPos); + outData = malloc(doSize); + if (!outData) + { + WLog_ERR(TAG, "Failed to allocate output buffer"); + return FALSE; + } + + Stream_SetPosition(ef->data, curPos); + Stream_Read(ef->data, outData, doSize); + *data = outData; + *dataSize = doSize; + return TRUE; + } + else + { + /* Skip DO */ + if (!Stream_SafeSeek(ef->data, doSize)) + return FALSE; + } + } + + return FALSE; +} + +void vgids_ef_free(void* ptr) +{ + vgidsEF* ef = ptr; + if (ef) + { + Stream_Free(ef->data, TRUE); + free(ef); + } +} + +static BOOL vgids_prepare_fstable(const vgidsFilesysTableEntry* fstable, DWORD numEntries, + BYTE** outData, DWORD* outDataSize) +{ + /* Filesystem table: + BYTE unknown: 0x01 + Array of vgidsFilesysTableEntry + */ + BYTE* data = malloc(sizeof(vgidsFilesysTableEntry) * numEntries + 1); + if (!data) + { + WLog_ERR(TAG, "Failed to allocate filesystem table data blob"); + return FALSE; + } + + *data = 0x01; + for (UINT32 i = 0; i < numEntries; ++i) + memcpy(data + 1 + (sizeof(vgidsFilesysTableEntry) * i), &fstable[i], + sizeof(vgidsFilesysTableEntry)); + + *outData = data; + *outDataSize = sizeof(vgidsFilesysTableEntry) * numEntries + 1; + + return TRUE; +} + +static BOOL vgids_prepare_certificate(const rdpCertificate* cert, BYTE** kxc, DWORD* kxcSize) +{ + /* Key exchange container: + UINT16 compression version: 0001 + UINT16 source size + ZLIB compressed cert + */ + uLongf destSize = 0; + wStream* s = NULL; + BYTE* comprData = NULL; + + WINPR_ASSERT(cert); + + size_t certSize = 0; + BYTE* certData = freerdp_certificate_get_der(cert, &certSize); + if (!certData || (certSize == 0)) + { + WLog_ERR(TAG, "Failed to get certificate size"); + goto handle_error; + } + + comprData = malloc(certSize); + if (!comprData) + { + WLog_ERR(TAG, "Failed to allocate certificate buffer"); + goto handle_error; + } + + /* compress certificate data */ + destSize = certSize; + if (compress(comprData, &destSize, certData, certSize) != Z_OK) + { + WLog_ERR(TAG, "Failed to compress certificate data"); + goto handle_error; + } + + /* Write container data */ + s = Stream_New(NULL, destSize + 4); + Stream_Write_UINT16(s, 0x0001); + Stream_Write_UINT16(s, (UINT16)certSize); + Stream_Write(s, comprData, destSize); + Stream_SealLength(s); + + *kxc = Stream_Buffer(s); + *kxcSize = (DWORD)Stream_Length(s); + + Stream_Free(s, FALSE); + free(certData); + free(comprData); + return TRUE; + +handle_error: + Stream_Free(s, TRUE); + free(certData); + free(comprData); + return FALSE; +} + +static size_t get_rsa_key_size(const rdpPrivateKey* privateKey) +{ + WINPR_ASSERT(privateKey); + + return freerdp_key_get_bits(privateKey) / 8; +} + +static BYTE vgids_get_algid(vgidsContext* p_Ctx) +{ + WINPR_ASSERT(p_Ctx); + + switch (get_rsa_key_size(p_Ctx->privateKey)) + { + case (1024 / 8): + return VGIDS_ALGID_RSA_1024; + case (2048 / 8): + return VGIDS_ALGID_RSA_2048; + case (3072 / 8): + return VGIDS_ALGID_RSA_3072; + case (4096 / 8): + return VGIDS_ALGID_RSA_4096; + default: + WLog_ERR(TAG, "Failed to determine algid for private key"); + break; + } + + return 0; +} + +static BOOL vgids_prepare_keymap(vgidsContext* context, BYTE** outData, DWORD* outDataSize) +{ + /* Key map record table: + BYTE unknown (count?): 0x01 + Array of vgidsKeymapRecord + */ + BYTE* data = NULL; + vgidsKeymapRecord record = { + 1, /* state */ + 0, /* algo */ + VGIDS_KEY_TYPE_KEYEXCHANGE, /* keytpe */ + (0xB000 | VGIDS_DEFAULT_KEY_REF), /* keyref */ + 0xFFFF, /* unknown FFFF */ + 0x0000 /* unknown 0000 */ + }; + + /* Determine algo */ + BYTE algid = vgids_get_algid(context); + if (algid == 0) + return FALSE; + + data = malloc(sizeof(record) + 1); + if (!data) + { + WLog_ERR(TAG, "Failed to allocate filesystem table data blob"); + return FALSE; + } + + *data = 0x01; + record.algid = algid; + memcpy(data + 1, &record, sizeof(record)); + + *outData = data; + *outDataSize = sizeof(record) + 1; + + return TRUE; +} + +static BOOL vgids_parse_apdu_header(wStream* s, BYTE* cla, BYTE* ins, BYTE* p1, BYTE* p2, BYTE* lc, + BYTE* le) +{ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 4)) + return FALSE; + + /* Read and verify APDU data */ + if (cla) + Stream_Read_UINT8(s, *cla); + else + Stream_Seek(s, 1); + if (ins) + Stream_Read_UINT8(s, *ins); + else + Stream_Seek(s, 1); + if (p1) + Stream_Read_UINT8(s, *p1); + else + Stream_Seek(s, 1); + if (p2) + Stream_Read_UINT8(s, *p2); + else + Stream_Seek(s, 1); + + /* If LC is requested - check remaining length and read as well */ + if (lc) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + + Stream_Read_UINT8(s, *lc); + if (!Stream_CheckAndLogRequiredLength(TAG, s, *lc)) + return FALSE; + } + + /* read LE */ + if (le) + { + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + return FALSE; + Stream_Read_UINT8(s, *le); + } + + return TRUE; +} + +static BOOL vgids_create_response(UINT16 status, const BYTE* answer, DWORD answerSize, + BYTE** outData, DWORD* outDataSize) +{ + BYTE* out = malloc(answerSize + 2); + if (!out) + { + WLog_ERR(TAG, "Failed to allocate memory for response data"); + return FALSE; + } + + *outData = out; + if (answer) + { + memcpy(out, answer, answerSize); + out += answerSize; + } + + *out = (BYTE)((status >> 8) & 0xFF); + *(out + 1) = (BYTE)(status & 0xFF); + *outDataSize = answerSize + 2; + return TRUE; +} + +static BOOL vgids_read_do_fkt(void* data, size_t index, va_list ap) +{ + BYTE* response = NULL; + DWORD responseSize = 0; + vgidsEF* file = (vgidsEF*)data; + vgidsContext* context = va_arg(ap, vgidsContext*); + UINT16 efID = (UINT16)va_arg(ap, unsigned); + UINT16 doID = (UINT16)va_arg(ap, unsigned); + WINPR_UNUSED(index); + + if (efID == 0x3FFF || efID == file->id) + { + /* If the DO was successfully read - abort file enum */ + if (vgids_ef_read_do(file, doID, &response, &responseSize)) + { + context->responseData = Stream_New(response, (size_t)responseSize); + return FALSE; + } + } + + return TRUE; +} + +static void vgids_read_do(vgidsContext* context, UINT16 efID, UINT16 doID) +{ + ArrayList_ForEach(context->files, vgids_read_do_fkt, context, efID, doID); +} + +static void vgids_reset_context_response(vgidsContext* context) +{ + Stream_Free(context->responseData, TRUE); + context->responseData = NULL; +} + +static void vgids_reset_context_command_data(vgidsContext* context) +{ + Stream_Free(context->commandData, TRUE); + context->commandData = NULL; +} + +static BOOL vgids_ins_select(vgidsContext* context, wStream* s, BYTE** response, + DWORD* responseSize) +{ + BYTE p1 = 0; + BYTE p2 = 0; + BYTE lc = 0; + DWORD resultDataSize = 0; + const BYTE* resultData = NULL; + UINT16 status = ISO_STATUS_SUCCESS; + + /* The only select operations performed are either select by AID or select 3FFF (return + * information about the currently selected DF) */ + if (!vgids_parse_apdu_header(s, NULL, NULL, &p1, &p2, &lc, NULL)) + return FALSE; + + /* Check P1 for selection mode */ + switch (p1) + { + /* Select by AID */ + case 0x04: + { + /* read AID from APDU */ + BYTE aid[ISO_AID_MAX_SIZE] = { 0 }; + if (lc > ISO_AID_MAX_SIZE) + { + WLog_ERR(TAG, "The LC byte is greater than the maximum AID length"); + status = ISO_STATUS_INVALIDLC; + break; + } + + /* Check if we select MS GIDS App (only one we know) */ + Stream_Read(s, aid, lc); + if (memcmp(aid, g_MsGidsAID, lc) != 0) + { + status = ISO_STATUS_FILENOTFOUND; + break; + } + + /* Return FCI or FCP for MsGids App */ + switch (p2) + { + /* Return FCI information */ + case 0x00: + { + resultData = g_GidsAppFCI; + resultDataSize = sizeof(g_GidsAppFCI); + break; + } + /* Return FCP information */ + case 0x04: + { + resultData = g_GidsAppFCP; + resultDataSize = sizeof(g_GidsAppFCP); + break; + } + default: + status = ISO_STATUS_INVALIDP1P2; + break; + } + + if (resultData) + context->currentDF = ISO_FID_MF; + break; + } + /* Select by FID */ + case 0x00: + { + /* read FID from APDU */ + UINT16 fid = 0; + if (lc > 2) + { + WLog_ERR(TAG, "The LC byte for the file ID is greater than 2"); + status = ISO_STATUS_INVALIDLC; + break; + } + + Stream_Read_UINT16_BE(s, fid); + if (fid != VGIDS_EFID_CURRENTDF || context->currentDF == 0) + { + status = ISO_STATUS_FILENOTFOUND; + break; + } + break; + } + default: + { + /* P1 P2 combination not supported */ + status = ISO_STATUS_INVALIDP1P2; + break; + } + } + + return vgids_create_response(status, resultData, resultDataSize, response, responseSize); +} + +static UINT16 vgids_handle_chained_response(vgidsContext* context, const BYTE** response, + DWORD* responseSize) +{ + /* Cap to a maximum of 256 bytes and set status to more data */ + UINT16 status = ISO_STATUS_SUCCESS; + DWORD remainingBytes = (DWORD)Stream_Length(context->responseData); + if (remainingBytes > 256) + { + status = ISO_STATUS_MORE_DATA; + remainingBytes = 256; + } + + *response = Stream_Buffer(context->responseData); + *responseSize = remainingBytes; + Stream_Seek(context->responseData, remainingBytes); + + /* Check if there are more than 256 bytes left or if we can already provide the remaining length + * in the status word */ + remainingBytes = (DWORD)(Stream_Length(context->responseData) - remainingBytes); + if (remainingBytes < 256 && remainingBytes != 0) + status |= (remainingBytes & 0xFF); + return status; +} + +static BOOL vgids_get_public_key(vgidsContext* context, UINT16 doTag) +{ + BOOL rc = FALSE; + wStream* pubKey = NULL; + wStream* response = NULL; + + WINPR_ASSERT(context); + + /* Get key components */ + size_t nSize = 0; + size_t eSize = 0; + + char* n = freerdp_certificate_get_param(context->certificate, FREERDP_CERT_RSA_N, &nSize); + char* e = freerdp_certificate_get_param(context->certificate, FREERDP_CERT_RSA_E, &eSize); + + if (!n || !e) + goto handle_error; + + pubKey = Stream_New(NULL, nSize + eSize + 0x10); + if (!pubKey) + { + WLog_ERR(TAG, "Failed to allocate public key stream"); + goto handle_error; + } + + response = Stream_New(NULL, Stream_Capacity(pubKey) + 0x10); + if (!response) + { + WLog_ERR(TAG, "Failed to allocate response stream"); + goto handle_error; + } + + /* write modulus and exponent DOs */ + if (!vgids_write_tlv(pubKey, 0x81, n, nSize)) + goto handle_error; + + if (!vgids_write_tlv(pubKey, 0x82, e, eSize)) + goto handle_error; + + /* write ISO public key template */ + if (!vgids_write_tlv(response, doTag, Stream_Buffer(pubKey), (DWORD)Stream_Length(pubKey))) + goto handle_error; + + /* set response data */ + Stream_SetPosition(response, 0); + context->responseData = response; + response = NULL; + + rc = TRUE; +handle_error: + free(n); + free(e); + Stream_Free(pubKey, TRUE); + Stream_Free(response, TRUE); + return rc; +} + +static BOOL vgids_ins_getdata(vgidsContext* context, wStream* s, BYTE** response, + DWORD* responseSize) +{ + UINT16 doId = 0; + UINT16 fileId = 0; + BYTE p1 = 0; + BYTE p2 = 0; + BYTE lc = 0; + DWORD resultDataSize = 0; + const BYTE* resultData = NULL; + UINT16 status = ISO_STATUS_SUCCESS; + + /* GetData is called a lot! + - To retrieve DOs from files + - To retrieve public key information + */ + if (!vgids_parse_apdu_header(s, NULL, NULL, &p1, &p2, &lc, NULL)) + return FALSE; + + /* free any previous queried data */ + vgids_reset_context_response(context); + + /* build up file identifier */ + fileId = (UINT16)(((UINT16)p1 << 8) | p2); + + /* Do we have a DO reference? */ + switch (lc) + { + case 4: + { + BYTE tag = 0; + BYTE length = 0; + Stream_Read_UINT8(s, tag); + Stream_Read_UINT8(s, length); + if (tag != 0x5C && length != 0x02) + { + status = ISO_STATUS_INVALIDCOMMANDDATA; + break; + } + + Stream_Read_UINT16_BE(s, doId); + vgids_read_do(context, fileId, doId); + break; + } + case 0xA: + { + UINT16 pubKeyDO = 0; + BYTE tag = 0; + BYTE length = 0; + BYTE keyRef = 0; + + /* We want to retrieve the public key? */ + if (p1 != 0x3F && p2 != 0xFF) + { + status = ISO_STATUS_INVALIDP1P2; + break; + } + + /* read parent tag/length */ + Stream_Read_UINT8(s, tag); + Stream_Read_UINT8(s, length); + if (tag != 0x70 || length != 0x08) + { + status = ISO_STATUS_INVALIDCOMMANDDATA; + break; + } + + /* read key reference TLV */ + Stream_Read_UINT8(s, tag); + Stream_Read_UINT8(s, length); + Stream_Read_UINT8(s, keyRef); + if (tag != 0x84 || length != 0x01 || keyRef != VGIDS_DEFAULT_KEY_REF) + { + status = ISO_STATUS_INVALIDCOMMANDDATA; + break; + } + + /* read key value template TLV */ + Stream_Read_UINT8(s, tag); + Stream_Read_UINT8(s, length); + if (tag != 0xA5 || length != 0x03) + { + status = ISO_STATUS_INVALIDCOMMANDDATA; + break; + } + + Stream_Read_UINT16_BE(s, pubKeyDO); + Stream_Read_UINT8(s, length); + if (pubKeyDO != 0x7F49 || length != 0x80) + { + status = ISO_STATUS_INVALIDCOMMANDDATA; + break; + } + + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + { + status = ISO_STATUS_INVALIDLC; + break; + } + + /* Return public key value */ + vgids_get_public_key(context, pubKeyDO); + break; + } + default: + status = ISO_STATUS_INVALIDCOMMANDDATA; + break; + } + + /* If we have response data, make it ready for return */ + if (context->responseData) + status = vgids_handle_chained_response(context, &resultData, &resultDataSize); + else if (status == ISO_STATUS_SUCCESS) + status = ISO_STATUS_REFERENCEDATANOTFOUND; + + return vgids_create_response(status, resultData, resultDataSize, response, responseSize); +} + +static BOOL vgids_ins_manage_security_environment(vgidsContext* context, wStream* s, + BYTE** response, DWORD* responseSize) +{ + BYTE tag = 0; + BYTE length = 0; + BYTE p1 = 0; + BYTE p2 = 0; + BYTE lc = 0; + DWORD resultDataSize = 0; + const BYTE* resultData = NULL; + UINT16 status = ISO_STATUS_SUCCESS; + + vgids_reset_context_command_data(context); + vgids_reset_context_response(context); + + /* Manage security environment prepares the card for performing crypto operations. */ + if (!vgids_parse_apdu_header(s, NULL, NULL, &p1, &p2, &lc, NULL)) + return FALSE; + + /* Check APDU params */ + /* P1: Set Computation, decipherment, Internal Auth */ + /* P2: Digital Signature (B6), Confidentiality (B8) */ + if (p1 != 0x41 && p2 != 0xB6 && p2 != 0xB8) + { + status = ISO_STATUS_INVALIDP1P2; + goto create_response; + } + + if (lc != 6) + { + status = ISO_STATUS_WRONGLC; + goto create_response; + } + + context->currentSE.crt = p2; + + /* parse command buffer */ + /* Read algo ID */ + Stream_Read_UINT8(s, tag); + Stream_Read_UINT8(s, length); + if (tag != 0x80 || length != 0x01) + { + status = ISO_STATUS_INVALIDCOMMANDDATA; + goto create_response; + } + Stream_Read_UINT8(s, context->currentSE.algoId); + + /* Read private key reference */ + Stream_Read_UINT8(s, tag); + Stream_Read_UINT8(s, length); + if (tag != 0x84 || length != 0x01) + { + status = ISO_STATUS_INVALIDCOMMANDDATA; + goto create_response; + } + Stream_Read_UINT8(s, context->currentSE.keyRef); + +create_response: + /* If an error occurred reset SE */ + if (status != ISO_STATUS_SUCCESS) + memset(&context->currentSE, 0, sizeof(context->currentSE)); + return vgids_create_response(status, resultData, resultDataSize, response, responseSize); +} + +static BOOL vgids_perform_digital_signature(vgidsContext* context) +{ + size_t sigSize = 0; + size_t msgSize = 0; + EVP_PKEY_CTX* ctx = NULL; + EVP_PKEY* pk = freerdp_key_get_evp_pkey(context->privateKey); + const vgidsDigestInfoMap gidsDigestInfo[VGIDS_MAX_DIGEST_INFO] = { + { g_PKCS1_SHA1, sizeof(g_PKCS1_SHA1), EVP_sha1() }, + { g_PKCS1_SHA224, sizeof(g_PKCS1_SHA224), EVP_sha224() }, + { g_PKCS1_SHA256, sizeof(g_PKCS1_SHA256), EVP_sha256() }, + { g_PKCS1_SHA384, sizeof(g_PKCS1_SHA384), EVP_sha384() }, + { g_PKCS1_SHA512, sizeof(g_PKCS1_SHA512), EVP_sha512() }, +#if OPENSSL_VERSION_NUMBER >= 0x10101000L + { g_PKCS1_SHA512_224, sizeof(g_PKCS1_SHA512_224), EVP_sha512_224() }, + { g_PKCS1_SHA512_256, sizeof(g_PKCS1_SHA512_256), EVP_sha512_256() } +#endif + }; + + if (!pk) + { + WLog_ERR(TAG, "Failed to create PKEY"); + return FALSE; + } + + vgids_reset_context_response(context); + + /* for each digest info */ + Stream_SetPosition(context->commandData, 0); + for (int i = 0; i < VGIDS_MAX_DIGEST_INFO; ++i) + { + /* have we found our digest? */ + const vgidsDigestInfoMap* digest = &gidsDigestInfo[i]; + if (Stream_Length(context->commandData) >= digest->infoSize && + memcmp(Stream_Buffer(context->commandData), digest->info, digest->infoSize) == 0) + { + /* skip digest info and calculate message size */ + Stream_Seek(context->commandData, digest->infoSize); + if (!Stream_CheckAndLogRequiredLength(TAG, context->commandData, 2)) + goto sign_failed; + msgSize = Stream_GetRemainingLength(context->commandData); + + /* setup signing context */ + ctx = EVP_PKEY_CTX_new(pk, NULL); + if (!ctx) + { + WLog_ERR(TAG, "Failed to create signing context"); + goto sign_failed; + } + + if (EVP_PKEY_sign_init(ctx) <= 0) + { + WLog_ERR(TAG, "Failed to init signing context"); + goto sign_failed; + } + + /* set padding and signature algo */ + if (context->currentSE.algoId & VGIDS_SE_ALGOID_DST_PAD_PKCS1) + { + if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0) + { + WLog_ERR(TAG, "Failed to set padding mode"); + goto sign_failed; + } + } + + if (EVP_PKEY_CTX_set_signature_md(ctx, digest->digest) <= 0) + { + WLog_ERR(TAG, "Failed to set signing mode"); + goto sign_failed; + } + + /* Determine buffer length */ + if (EVP_PKEY_sign(ctx, NULL, &sigSize, Stream_Pointer(context->commandData), msgSize) <= + 0) + { + WLog_ERR(TAG, "Failed to determine signature size"); + goto sign_failed; + } + + context->responseData = Stream_New(NULL, sigSize); + if (!context->responseData) + { + WLog_ERR(TAG, "Failed to allocate signing buffer"); + goto sign_failed; + } + + /* sign */ + if (EVP_PKEY_sign(ctx, Stream_Buffer(context->responseData), &sigSize, + Stream_Pointer(context->commandData), msgSize) <= 0) + { + WLog_ERR(TAG, "Failed to create signature"); + goto sign_failed; + } + + Stream_SetLength(context->responseData, sigSize); + EVP_PKEY_CTX_free(ctx); + break; + } + } + + EVP_PKEY_free(pk); + vgids_reset_context_command_data(context); + return TRUE; + +sign_failed: + vgids_reset_context_command_data(context); + vgids_reset_context_response(context); + EVP_PKEY_CTX_free(ctx); + EVP_PKEY_free(pk); + return FALSE; +} + +static BOOL vgids_perform_decrypt(vgidsContext* context) +{ + EVP_PKEY_CTX* ctx = NULL; + BOOL rc = FALSE; + int res = 0; + int padding = RSA_NO_PADDING; + + vgids_reset_context_response(context); + + /* determine padding */ + if (context->currentSE.algoId & VGIDS_SE_ALGOID_CT_PAD_PKCS1) + padding = RSA_PKCS1_PADDING; + else if (context->currentSE.algoId & VGIDS_SE_ALGOID_CT_PAD_OAEP) + padding = RSA_PKCS1_OAEP_PADDING; + + /* init response buffer */ + EVP_PKEY* pkey = freerdp_key_get_evp_pkey(context->privateKey); + if (!pkey) + goto decrypt_failed; + ctx = EVP_PKEY_CTX_new(pkey, NULL); + if (!ctx) + goto decrypt_failed; + if (EVP_PKEY_decrypt_init(ctx) <= 0) + goto decrypt_failed; + if (EVP_PKEY_CTX_set_rsa_padding(ctx, padding) <= 0) + goto decrypt_failed; + + /* Determine buffer length */ + const size_t inlen = Stream_Length(context->commandData); + size_t outlen = 0; + res = EVP_PKEY_decrypt(ctx, NULL, &outlen, Stream_Buffer(context->commandData), inlen); + if (res < 0) + { + WLog_ERR(TAG, "Failed to decrypt data"); + goto decrypt_failed; + } + + /* Prepare output buffer */ + context->responseData = Stream_New(NULL, outlen); + if (!context->responseData) + { + WLog_ERR(TAG, "Failed to create decryption buffer"); + goto decrypt_failed; + } + + /* Decrypt */ + res = EVP_PKEY_decrypt(ctx, Stream_Buffer(context->responseData), &outlen, + Stream_Buffer(context->commandData), inlen); + + if (res < 0) + { + WLog_ERR(TAG, "Failed to decrypt data"); + goto decrypt_failed; + } + + Stream_SetLength(context->responseData, outlen); + rc = TRUE; + +decrypt_failed: + EVP_PKEY_CTX_free(ctx); + EVP_PKEY_free(pkey); + vgids_reset_context_command_data(context); + if (!rc) + vgids_reset_context_response(context); + return rc; +} + +static BOOL vgids_ins_perform_security_operation(vgidsContext* context, wStream* s, BYTE** response, + DWORD* responseSize) +{ + BYTE cla = 0; + BYTE p1 = 0; + BYTE p2 = 0; + BYTE lc = 0; + DWORD resultDataSize = 0; + const BYTE* resultData = NULL; + UINT16 status = ISO_STATUS_SUCCESS; + + /* Perform security operation */ + if (!vgids_parse_apdu_header(s, &cla, NULL, &p1, &p2, &lc, NULL)) + return FALSE; + + if (lc == 0) + { + status = ISO_STATUS_WRONGLC; + goto create_response; + } + + /* Is our default key referenced? */ + if (context->currentSE.keyRef != VGIDS_DEFAULT_KEY_REF) + { + status = ISO_STATUS_SECURITYSTATUSNOTSATISFIED; + goto create_response; + } + + /* is the pin protecting the key verified? */ + if (!context->pinVerified) + { + status = ISO_STATUS_SECURITYSTATUSNOTSATISFIED; + goto create_response; + } + + /* Append the data to the context command buffer (PSO might chain command data) */ + if (!context->commandData) + { + context->commandData = Stream_New(NULL, lc); + if (!context->commandData) + return FALSE; + } + else if (!Stream_EnsureRemainingCapacity(context->commandData, lc)) + return FALSE; + + Stream_Write(context->commandData, Stream_Pointer(s), lc); + Stream_SealLength(context->commandData); + + /* Check if the correct operation is requested for our current SE */ + switch (context->currentSE.crt) + { + case VGIDS_SE_CRT_SIGN: + { + if (p1 != 0x9E || p2 != 0x9A) + { + status = ISO_STATUS_INVALIDP1P2; + break; + } + + /* If chaining is over perform op */ + if (!(cla & 0x10)) + vgids_perform_digital_signature(context); + break; + } + case VGIDS_SE_CRT_CONF: + { + if ((p1 != 0x86 || p2 != 0x80) && (p1 != 0x80 || p2 != 0x86)) + { + status = ISO_STATUS_INVALIDP1P2; + break; + } + + /* If chaining is over perform op */ + if (!(cla & 0x10)) + vgids_perform_decrypt(context); + break; + } + default: + status = ISO_STATUS_INVALIDP1P2; + break; + } + + /* Do chaining of response data if necessary */ + if (status == ISO_STATUS_SUCCESS && context->responseData) + status = vgids_handle_chained_response(context, &resultData, &resultDataSize); + + /* Check APDU params */ +create_response: + return vgids_create_response(status, resultData, resultDataSize, response, responseSize); +} + +static BOOL vgids_ins_getresponse(vgidsContext* context, wStream* s, BYTE** response, + DWORD* responseSize) +{ + BYTE p1 = 0; + BYTE p2 = 0; + BYTE le = 0; + DWORD resultDataSize = 0; + const BYTE* resultData = NULL; + DWORD expectedLen = 0; + DWORD remainingSize = 0; + UINT16 status = ISO_STATUS_SUCCESS; + + /* Get response continues data transfer after a previous get data command */ + /* Check if there is any data to transfer left */ + if (!context->responseData || !Stream_CheckAndLogRequiredLength(TAG, context->responseData, 1)) + { + status = ISO_STATUS_COMMANDNOTALLOWED; + goto create_response; + } + + if (!vgids_parse_apdu_header(s, NULL, NULL, &p1, &p2, NULL, &le)) + return FALSE; + + /* Check APDU params */ + if (p1 != 00 || p2 != 0x00) + { + status = ISO_STATUS_INVALIDP1P2; + goto create_response; + } + + /* LE = 0 means 256 bytes expected */ + expectedLen = le; + if (expectedLen == 0) + expectedLen = 256; + + /* prepare response size and update offset */ + remainingSize = (DWORD)Stream_GetRemainingLength(context->responseData); + if (remainingSize < expectedLen) + expectedLen = remainingSize; + + resultData = Stream_Pointer(context->responseData); + resultDataSize = expectedLen; + Stream_Seek(context->responseData, expectedLen); + + /* If more data is left return 61XX - otherwise 9000 */ + remainingSize = (DWORD)Stream_GetRemainingLength(context->responseData); + if (remainingSize > 0) + { + status = ISO_STATUS_MORE_DATA; + if (remainingSize < 256) + status |= (remainingSize & 0xFF); + } + +create_response: + return vgids_create_response(status, resultData, resultDataSize, response, responseSize); +} + +static BOOL vgids_ins_verify(vgidsContext* context, wStream* s, BYTE** response, + DWORD* responseSize) +{ + BYTE ins = 0; + BYTE p1 = 0; + BYTE p2 = 0; + BYTE lc = 0; + UINT16 status = ISO_STATUS_SUCCESS; + char pin[VGIDS_MAX_PIN_SIZE + 1] = { 0 }; + + /* Verify is always called for the application password (PIN) P2=0x80 */ + if (!vgids_parse_apdu_header(s, NULL, &ins, &p1, &p2, NULL, NULL)) + return FALSE; + + /* Check APDU params */ + if (p1 != 00 && p2 != 0x80 && p2 != 0x82) + { + status = ISO_STATUS_INVALIDP1P2; + goto create_response; + } + + /* shall we reset the security state? */ + if (p2 == 0x82) + { + context->pinVerified = FALSE; + goto create_response; + } + + /* Check if pin is not already blocked */ + if (context->curRetryCounter == 0) + { + status = ISO_STATUS_AUTHMETHODBLOCKED; + goto create_response; + } + + /* Read and verify LC */ + if (!Stream_CheckAndLogRequiredLength(TAG, s, 1)) + { + status = ISO_STATUS_INVALIDLC; + goto create_response; + } + + Stream_Read_UINT8(s, lc); + if (!Stream_CheckAndLogRequiredLength(TAG, s, lc) || (lc > VGIDS_MAX_PIN_SIZE)) + { + status = ISO_STATUS_INVALIDLC; + goto create_response; + } + + /* read and verify pin */ + Stream_Read(s, pin, lc); + if (strcmp(context->pin, pin) != 0) + { + /* retries are encoded in the lowest 4-bit of the status code */ + --context->curRetryCounter; + context->pinVerified = FALSE; + status = (ISO_STATUS_VERIFYFAILED | (context->curRetryCounter & 0xFF)); + } + else + { + /* reset retry counter and mark pin as verified */ + context->curRetryCounter = context->retryCounter; + context->pinVerified = TRUE; + } + +create_response: + return vgids_create_response(status, NULL, 0, response, responseSize); +} + +vgidsContext* vgids_new(void) +{ + wObject* obj = NULL; + vgidsContext* ctx = calloc(1, sizeof(vgidsContext)); + + ctx->files = ArrayList_New(FALSE); + if (!ctx->files) + { + WLog_ERR(TAG, "Failed to create files array list"); + goto create_failed; + } + + obj = ArrayList_Object(ctx->files); + obj->fnObjectFree = vgids_ef_free; + + return ctx; + +create_failed: + vgids_free(ctx); + return NULL; +} + +BOOL vgids_init(vgidsContext* ctx, const char* cert, const char* privateKey, const char* pin) +{ + DWORD kxcSize = 0; + DWORD keymapSize = 0; + DWORD fsTableSize = 0; + BOOL rc = FALSE; + BYTE* kxc = NULL; + BYTE* keymap = NULL; + BYTE* fsTable = NULL; + vgidsEF* masterEF = NULL; + vgidsEF* cardidEF = NULL; + vgidsEF* commonEF = NULL; + BYTE cardid[VGIDS_CARDID_SIZE] = { 0 }; + vgidsContainerMapEntry cmrec = { { 'P', 'r', 'i', 'v', 'a', 't', 'e', ' ', 'K', 'e', 'y', ' ', + '0', '0' }, + CONTAINER_MAP_VALID_CONTAINER | + CONTAINER_MAP_DEFAULT_CONTAINER, + 0, + 0, + 0x00 /* key-size in bits - filled out later */ }; + vgidsFilesysTableEntry filesys[] = { + { "mscp", "", 0, 0, 0, 0xA000, 0 }, + { "", "cardid", 0, 0xDF20, 0, 0xA012, 0 }, + { "", "cardapps", 0, 0xDF21, 0, 0xA010, 0 }, + { "", "cardcf", 0, 0xDF22, 0, 0xA010, 0 }, + { "mscp", "cmapfile", 0, 0xDF23, 0, 0xA010, 0 }, + { "mscp", "kxc00", 0, 0xDF24, 0, 0xA010, 0 }, + }; + + /* Check params */ + if (!cert || !privateKey || !pin) + { + WLog_DBG(TAG, "Passed invalid NULL argument: cert=%p, privateKey=%p, pin=%p", cert, + privateKey, pin); + goto init_failed; + } + + /* Convert PEM input to DER certificate/public key/private key */ + ctx->certificate = freerdp_certificate_new_from_pem(cert); + if (!ctx->certificate) + goto init_failed; + + ctx->privateKey = freerdp_key_new_from_pem(privateKey); + if (!ctx->privateKey) + goto init_failed; + + /* create masterfile */ + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc) + masterEF = vgids_ef_new(ctx, VGIDS_EFID_MASTER); + if (!masterEF) + goto init_failed; + + /* create cardid file with cardid DO */ + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc) + cardidEF = vgids_ef_new(ctx, VGIDS_EFID_CARDID); + if (!cardidEF) + goto init_failed; + winpr_RAND(cardid, sizeof(cardid)); + if (!vgids_ef_write_do(cardidEF, VGIDS_DO_CARDID, cardid, sizeof(cardid))) + goto init_failed; + + /* create user common file */ + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc) + commonEF = vgids_ef_new(ctx, VGIDS_EFID_COMMON); + if (!commonEF) + goto init_failed; + + /* write card cache DO */ + if (!vgids_ef_write_do(commonEF, VGIDS_DO_CARDCF, g_CardCFContents, sizeof(g_CardCFContents))) + goto init_failed; + + /* write container map DO */ + const size_t size = get_rsa_key_size(ctx->privateKey); + if ((size == 0) || (size > UINT16_MAX / 8)) + goto init_failed; + + cmrec.wKeyExchangeKeySizeBits = (WORD)size * 8; + if (!vgids_ef_write_do(commonEF, VGIDS_DO_CMAPFILE, &cmrec, sizeof(cmrec))) + goto init_failed; + + /* write cardapps DO */ + if (!vgids_ef_write_do(commonEF, VGIDS_DO_CARDAPPS, g_CardAppsContents, + sizeof(g_CardAppsContents))) + goto init_failed; + + /* convert and write certificate to key exchange container */ + if (!vgids_prepare_certificate(ctx->certificate, &kxc, &kxcSize)) + goto init_failed; + if (!vgids_ef_write_do(commonEF, VGIDS_DO_KXC00, kxc, kxcSize)) + goto init_failed; + + /* prepare and write file system table */ + if (!vgids_prepare_fstable(filesys, ARRAYSIZE(filesys), &fsTable, &fsTableSize)) + goto init_failed; + if (!vgids_ef_write_do(masterEF, VGIDS_DO_FILESYSTEMTABLE, fsTable, fsTableSize)) + goto init_failed; + + /* vgids_prepare_keymap and write to masterEF */ + if (!vgids_prepare_keymap(ctx, &keymap, &keymapSize)) + goto init_failed; + if (!vgids_ef_write_do(masterEF, VGIDS_DO_KEYMAP, keymap, keymapSize)) + goto init_failed; + + /* store user pin */ + ctx->curRetryCounter = ctx->retryCounter = VGIDS_DEFAULT_RETRY_COUNTER; + ctx->pin = _strdup(pin); + if (!ctx->pin) + goto init_failed; + + rc = TRUE; + +init_failed: + // ArrayList_Append in vgids_ef_new takes ownership + // of cardidEF, commonEF, masterEF + // NOLINTNEXTLINE(clang-analyzer-unix.Malloc) + free(kxc); + free(keymap); + free(fsTable); + return rc; +} + +BOOL vgids_process_apdu(vgidsContext* context, const BYTE* data, DWORD dataSize, BYTE** response, + DWORD* responseSize) +{ + wStream s; + static int x = 1; + + /* Check params */ + if (!context || !data || !response || !responseSize) + { + WLog_ERR(TAG, "Invalid NULL pointer passed"); + return FALSE; + } + + if (dataSize < 4) + { + WLog_ERR(TAG, "APDU buffer is less than 4 bytes: %" PRIu32, dataSize); + return FALSE; + } + + /* Examine INS byte */ + Stream_StaticConstInit(&s, data, dataSize); + if (x++ == 0xe) + x = 0xe + 1; + switch (data[1]) + { + case ISO_INS_SELECT: + return vgids_ins_select(context, &s, response, responseSize); + case ISO_INS_GETDATA: + return vgids_ins_getdata(context, &s, response, responseSize); + case ISO_INS_GETRESPONSE: + return vgids_ins_getresponse(context, &s, response, responseSize); + case ISO_INS_MSE: + return vgids_ins_manage_security_environment(context, &s, response, responseSize); + case ISO_INS_PSO: + return vgids_ins_perform_security_operation(context, &s, response, responseSize); + case ISO_INS_VERIFY: + return vgids_ins_verify(context, &s, response, responseSize); + default: + break; + } + + /* return command not allowed */ + return vgids_create_response(ISO_STATUS_COMMANDNOTALLOWED, NULL, 0, response, responseSize); +} + +void vgids_free(vgidsContext* context) +{ + if (context) + { + freerdp_key_free(context->privateKey); + freerdp_certificate_free(context->certificate); + Stream_Free(context->commandData, TRUE); + Stream_Free(context->responseData, TRUE); + free(context->pin); + ArrayList_Free(context->files); + free(context); + } +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_virtual_gids.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_virtual_gids.h new file mode 100644 index 0000000000000000000000000000000000000000..c59b00ec1453fd38085e9a82ca00882eec4b13f9 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/emu/scard/smartcard_virtual_gids.h @@ -0,0 +1,57 @@ +/** + * WinPR: Windows Portable Runtime + * Virtual GIDS implementation + * + * Copyright 2021 Martin Fleisz + * Copyright 2021 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_SMARTCARD_VIRTUAL_GIDS_H +#define WINPR_SMARTCARD_VIRTUAL_GIDS_H + +#include +#include +#include + +/* Virtual GIDS context */ +typedef struct vgids_context vgidsContext; + +/* Creates a new virtual gids context */ +vgidsContext* vgids_new(void); + +/* + Initializes the virtual gids context. + cert: PEM encoded smartcard certificate + privateKey: PEM encoded private key for the smartcard certificate + pin: Pin protecting the usage of the private key + Returns: TRUE on success, FALSE in case of an error +*/ +BOOL vgids_init(vgidsContext* ctx, const char* cert, const char* privateKey, const char* pin); + +/* + Processes the provided APDU returning a response for each processed command. + data: APDU byte stream + dataSize: size of the APDU provided in data + response: Pointer where the response buffer is stored to. Must be freed by caller! + responseSize: Size of the returned data buffer + Returns: TRUE on success, FALSE in case of an error +*/ +BOOL vgids_process_apdu(vgidsContext* context, const BYTE* data, DWORD dataSize, BYTE** response, + DWORD* responseSize); + +/* frees a previously created virtual gids context */ +void vgids_free(vgidsContext* context); + +#endif /* WINPR_SMARTCARD_VIRTUAL_GIDS_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8ae813f0e60c84b79e3268da2d59f89ac3b90bde --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/CMakeLists.txt @@ -0,0 +1,37 @@ +set(MODULE_NAME "TestGdi") +set(MODULE_PREFIX "TEST_GDI") + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c) + +set(${MODULE_PREFIX}_TESTS + TestGdiRop3.c + # TestGdiLine.c # TODO: This test is broken + TestGdiRegion.c + TestGdiRect.c + TestGdiBitBlt.c + TestGdiCreate.c + TestGdiEllipse.c + TestGdiClip.c +) + +create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS}) + +include_directories(..) + +add_library(helpers STATIC helpers.c) +target_link_libraries(helpers freerdp) + +add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + +target_link_libraries(${MODULE_NAME} winpr freerdp helpers) + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${${MODULE_PREFIX}_TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Test") diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/TestGdiBitBlt.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/TestGdiBitBlt.c new file mode 100644 index 0000000000000000000000000000000000000000..9f8c12c590de1a00e60a7e09b846a3746278c769 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/TestGdiBitBlt.c @@ -0,0 +1,577 @@ + +#include + +#include +#include +#include +#include + +#include + +#include "line.h" +#include "brush.h" +#include "helpers.h" + +/* BitBlt() Test Data */ + +/* source bitmap (16x16) */ +static const BYTE bmp_SRC[256] = { + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +}; + +/* destination bitmap (16x16) */ +static const BYTE bmp_DST[256] = { + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" +}; + +/* SRCCOPY (0x00CC0020) */ +static const BYTE bmp_SRCCOPY[256] = { + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +}; + +/* BLACKNESS (0x00000042) */ +static const BYTE bmp_BLACKNESS[256] = { + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +}; + +/* WHITENESS (0x00FF0062) */ +static const BYTE bmp_WHITENESS[256] = { + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +}; + +/* SRCAND (0x008800C6) */ +static const BYTE bmp_SRCAND[256] = { + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" +}; + +/* SRCPAINT (0x00EE0086) */ +static const BYTE bmp_SRCPAINT[256] = { + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +}; + +/* SRCINVERT (0x00660046) */ +static const BYTE bmp_SRCINVERT[256] = { + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x00\x00" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +}; + +/* SRCERASE (0x00440328) */ +static const BYTE bmp_SRCERASE[256] = { + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +}; + +/* NOTSRCCOPY (0x00330008) */ +static const BYTE bmp_NOTSRCCOPY[256] = { + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +}; + +/* NOTSRCERASE (0x001100A6) */ +static const BYTE bmp_NOTSRCERASE[256] = { + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +}; + +/* DSTINVERT (0x00550009) */ +static const BYTE bmp_DSTINVERT[256] = { + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +}; + +/* SPna (0x000C0324) */ +static const BYTE bmp_SPna[256] = { + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" +}; + +/* MERGEPAINT (0x00BB0226) */ +static const BYTE bmp_MERGEPAINT[256] = { + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00" +}; + +/* MERGECOPY (0x00C000CA) */ +static const BYTE bmp_MERGECOPY[256] = { + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\x00\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" +}; + +/* PATPAINT (0x00FB0A09) */ +static const BYTE bmp_PATPAINT[256] = { + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" +}; + +/* PATCOPY (0x00F00021) */ +static const BYTE bmp_PATCOPY[256] = { + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF\x00\x00\xFF\xFF" +}; + +/* PATINVERT (0x005A0049) */ +static const BYTE bmp_PATINVERT[256] = { + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\x00\x00\xFF\xFF\x00\x00\xFF\xFF\xFF\xFF\x00\x00\xFF\xFF\x00\x00" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" + "\xFF\xFF\x00\x00\xFF\xFF\x00\x00\x00\x00\xFF\xFF\x00\x00\xFF\xFF" +}; + +struct test_bitblt +{ + UINT32 rop; + const BYTE* src; + HGDI_BITMAP bmp; +}; + +static BOOL test_rop(HGDI_DC hdcDst, HGDI_DC hdcSrc, HGDI_BITMAP hBmpSrc, HGDI_BITMAP hBmpDst, + HGDI_BITMAP hBmpDstOriginal, UINT32 rop, HGDI_BITMAP expected, + const gdiPalette* hPalette) +{ + BOOL success = FALSE; + + /* restore original destination bitmap */ + gdi_SelectObject(hdcSrc, (HGDIOBJECT)hBmpDstOriginal); + gdi_SelectObject(hdcDst, (HGDIOBJECT)hBmpDst); + + if (!gdi_BitBlt(hdcDst, 0, 0, 16, 16, hdcSrc, 0, 0, GDI_SRCCOPY, hPalette)) + goto fail; + + if (!test_assert_bitmaps_equal(hBmpDst, hBmpDstOriginal, gdi_rop_to_string(GDI_SRCCOPY), + hPalette)) + goto fail; + + gdi_SelectObject(hdcSrc, (HGDIOBJECT)hBmpSrc); + if (!gdi_BitBlt(hdcDst, 0, 0, 16, 16, hdcSrc, 0, 0, rop, hPalette)) + goto fail; + + if (!test_assert_bitmaps_equal(hBmpDst, expected, gdi_rop_to_string(rop), hPalette)) + goto fail; + + success = TRUE; +fail: + (void)fprintf(stderr, "[%s] ROP=%s returned %d\n", __func__, gdi_rop_to_string(rop), success); + return success; +} + +static BOOL test_gdi_BitBlt(UINT32 SrcFormat, UINT32 DstFormat) +{ + BOOL rc = FALSE; + BOOL failed = FALSE; + HGDI_DC hdcSrc = NULL; + HGDI_DC hdcDst = NULL; + const UINT32 RawFormat = PIXEL_FORMAT_RGB8; + struct test_bitblt tests[] = { { GDI_SRCCOPY, bmp_SRCCOPY, NULL }, + { GDI_SPna, bmp_SPna, NULL }, + { GDI_BLACKNESS, bmp_BLACKNESS, NULL }, + { GDI_WHITENESS, bmp_WHITENESS, NULL }, + { GDI_SRCAND, bmp_SRCAND, NULL }, + { GDI_SRCPAINT, bmp_SRCPAINT, NULL }, + { GDI_SRCINVERT, bmp_SRCINVERT, NULL }, + { GDI_SRCERASE, bmp_SRCERASE, NULL }, + { GDI_NOTSRCCOPY, bmp_NOTSRCCOPY, NULL }, + { GDI_NOTSRCERASE, bmp_NOTSRCERASE, NULL }, + { GDI_DSTINVERT, bmp_DSTINVERT, NULL }, + { GDI_MERGECOPY, bmp_MERGECOPY, NULL }, + { GDI_MERGEPAINT, bmp_MERGEPAINT, NULL }, + { GDI_PATCOPY, bmp_PATCOPY, NULL }, + { GDI_PATPAINT, bmp_PATPAINT, NULL }, + { GDI_PATINVERT, bmp_PATINVERT, NULL }, + { GDI_DSTINVERT, bmp_SRC, NULL }, + { GDI_DSPDxax, bmp_SRC, NULL }, + { GDI_PSDPxax, bmp_SRC, NULL }, + { GDI_DSna, bmp_SRC, NULL }, + { GDI_DPa, bmp_SRC, NULL }, + { GDI_PDxn, bmp_SRC, NULL }, + { GDI_DSxn, bmp_SRC, NULL }, + { GDI_PSDnox, bmp_SRC, NULL }, + { GDI_PDSona, bmp_SRC, NULL }, + { GDI_DSPDxox, bmp_SRC, NULL }, + { GDI_DPSDonox, bmp_SRC, NULL }, + { GDI_SPDSxax, bmp_SRC, NULL }, + { GDI_DPon, bmp_SRC, NULL }, + { GDI_DPna, bmp_SRC, NULL }, + { GDI_Pn, bmp_SRC, NULL }, + { GDI_PDna, bmp_SRC, NULL }, + { GDI_DPan, bmp_SRC, NULL }, + { GDI_DSan, bmp_SRC, NULL }, + { GDI_DSxn, bmp_SRC, NULL }, + { GDI_DPa, bmp_SRC, NULL }, + { GDI_DSTCOPY, bmp_SRC, NULL }, + { GDI_DPno, bmp_SRC, NULL }, + { GDI_SDno, bmp_SRC, NULL }, + { GDI_PDno, bmp_SRC, NULL }, + { GDI_DPo, bmp_SRC, NULL } }; + const UINT32 number_tests = sizeof(tests) / sizeof(tests[0]); + HGDI_BITMAP hBmpSrc = NULL; + HGDI_BITMAP hBmpDst = NULL; + HGDI_BITMAP hBmpDstOriginal = NULL; + HGDI_BRUSH brush = NULL; + gdiPalette g; + gdiPalette* hPalette = &g; + g.format = DstFormat; + + for (UINT32 x = 0; x < 256; x++) + g.palette[x] = FreeRDPGetColor(DstFormat, x, x, x, 0xFF); + + if (!(hdcSrc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + goto fail; + } + + hdcSrc->format = SrcFormat; + + if (!(hdcDst = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + goto fail; + } + + hdcDst->format = DstFormat; + hBmpSrc = + test_convert_to_bitmap(bmp_SRC, RawFormat, 0, 0, 0, SrcFormat, 0, 0, 0, 16, 16, hPalette); + + if (!hBmpSrc) + goto fail; + + hBmpDst = + test_convert_to_bitmap(bmp_DST, RawFormat, 0, 0, 0, DstFormat, 0, 0, 0, 16, 16, hPalette); + + if (!hBmpDst) + goto fail; + + hBmpDstOriginal = + test_convert_to_bitmap(bmp_DST, RawFormat, 0, 0, 0, SrcFormat, 0, 0, 0, 16, 16, hPalette); + + if (!hBmpDstOriginal) + goto fail; + + for (size_t x = 0; x < ARRAYSIZE(tests); x++) + { + struct test_bitblt* test = &tests[x]; + test->bmp = test_convert_to_bitmap(test->src, RawFormat, 0, 0, 0, SrcFormat, 0, 0, 0, 16, + 16, hPalette); + + if (!test->bmp) + goto fail; + } + + brush = gdi_CreateSolidBrush(0x123456); + gdi_SelectObject(hdcDst, (HGDIOBJECT)brush); + + for (size_t x = 0; x < ARRAYSIZE(tests); x++) + { + struct test_bitblt* test = &tests[x]; + + if (!test_rop(hdcDst, hdcSrc, hBmpSrc, hBmpDst, hBmpDstOriginal, test->rop, test->bmp, + hPalette)) + failed = TRUE; + } + + gdi_SelectObject(hdcDst, NULL); + gdi_DeleteObject((HGDIOBJECT)brush); + rc = !failed; +fail: + + for (size_t x = 0; x < ARRAYSIZE(tests); x++) + { + struct test_bitblt* test = &tests[x]; + gdi_DeleteObject((HGDIOBJECT)test->bmp); + } + + gdi_DeleteObject((HGDIOBJECT)hBmpSrc); + gdi_DeleteObject((HGDIOBJECT)hBmpDst); + gdi_DeleteObject((HGDIOBJECT)hBmpDstOriginal); + gdi_DeleteDC(hdcSrc); + gdi_DeleteDC(hdcDst); + + return rc; +} + +int TestGdiBitBlt(int argc, char* argv[]) +{ + int rc = 0; + const UINT32 formatList[] = { PIXEL_FORMAT_RGB8, PIXEL_FORMAT_RGB15, PIXEL_FORMAT_ARGB15, + PIXEL_FORMAT_RGB16, PIXEL_FORMAT_RGB24, PIXEL_FORMAT_RGBA32, + PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, + PIXEL_FORMAT_BGR15, PIXEL_FORMAT_ABGR15, PIXEL_FORMAT_BGR16, + PIXEL_FORMAT_BGR24, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32, + PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_XBGR32 }; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + for (size_t x = 0; x < ARRAYSIZE(formatList); x++) + { + /* Skip 8bpp, only supported on remote end. */ + for (size_t y = 1; y < ARRAYSIZE(formatList); y++) + { + if (!test_gdi_BitBlt(formatList[x], formatList[y])) + { + (void)fprintf(stderr, "test_gdi_BitBlt(SrcFormat=%s, DstFormat=%s) failed!\n", + FreeRDPGetColorFormatName(formatList[x]), + FreeRDPGetColorFormatName(formatList[y])); + rc = -1; + } + } + } + + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/TestGdiCreate.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/TestGdiCreate.c new file mode 100644 index 0000000000000000000000000000000000000000..4b042b561dc55da72b9a416d956eac904f5bc86c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/TestGdiCreate.c @@ -0,0 +1,595 @@ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "line.h" +#include "brush.h" +#include "drawing.h" + +static const UINT32 colorFormatList[] = { + PIXEL_FORMAT_RGB15, PIXEL_FORMAT_BGR15, PIXEL_FORMAT_RGB16, PIXEL_FORMAT_BGR16, + PIXEL_FORMAT_RGB24, PIXEL_FORMAT_BGR24, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32, + PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRX32 + +}; +static const UINT32 colorFormatCount = sizeof(colorFormatList) / sizeof(colorFormatList[0]); + +static int test_gdi_GetDC(void) +{ + int rc = -1; + HGDI_DC hdc = NULL; + + if (!(hdc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + return -1; + } + + if (hdc->format != PIXEL_FORMAT_XRGB32) + goto fail; + + if (hdc->drawMode != GDI_R2_BLACK) + goto fail; + + rc = 0; +fail: + gdi_DeleteDC(hdc); + return rc; +} + +static int test_gdi_CreateCompatibleDC(void) +{ + int rc = -1; + HGDI_DC hdc = NULL; + HGDI_DC chdc = NULL; + + if (!(hdc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + return -1; + } + + hdc->format = PIXEL_FORMAT_RGB16; + hdc->drawMode = GDI_R2_XORPEN; + + if (!(chdc = gdi_CreateCompatibleDC(hdc))) + { + printf("gdi_CreateCompatibleDC failed\n"); + goto fail; + } + + if (chdc->format != hdc->format) + goto fail; + + if (chdc->drawMode != hdc->drawMode) + goto fail; + + rc = 0; +fail: + + if (chdc) + gdi_DeleteDC(chdc); + + gdi_DeleteDC(hdc); + return rc; +} + +static int test_gdi_CreateBitmap(void) +{ + int rc = -1; + UINT32 format = PIXEL_FORMAT_ARGB32; + INT32 width = 0; + INT32 height = 0; + BYTE* data = NULL; + HGDI_BITMAP hBitmap = NULL; + width = 32; + height = 16; + + if (!(data = (BYTE*)winpr_aligned_malloc(4ULL * width * height, 16))) + { + printf("failed to allocate aligned bitmap data memory\n"); + return -1; + } + + if (!(hBitmap = gdi_CreateBitmap(width, height, format, data))) + { + printf("gdi_CreateBitmap failed\n"); + goto fail; + } + + if (hBitmap->objectType != GDIOBJECT_BITMAP) + goto fail; + + if (hBitmap->format != format) + goto fail; + + if (hBitmap->width != width) + goto fail; + + if (hBitmap->height != height) + goto fail; + + if (hBitmap->data != data) + goto fail; + + rc = 0; +fail: + + if (hBitmap) + gdi_DeleteObject((HGDIOBJECT)hBitmap); + else + winpr_aligned_free(data); + + return rc; +} + +static int test_gdi_CreateCompatibleBitmap(void) +{ + int rc = -1; + HGDI_DC hdc = NULL; + INT32 width = 0; + INT32 height = 0; + HGDI_BITMAP hBitmap = NULL; + + if (!(hdc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + return -1; + } + + hdc->format = PIXEL_FORMAT_ARGB32; + width = 32; + height = 16; + hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); + + if (hBitmap->objectType != GDIOBJECT_BITMAP) + goto fail; + + if (hBitmap->format != hdc->format) + goto fail; + + if (hBitmap->width != width) + goto fail; + + if (hBitmap->height != height) + goto fail; + + if (!hBitmap->data) + goto fail; + + rc = 0; +fail: + + if (hBitmap) + gdi_DeleteObject((HGDIOBJECT)hBitmap); + + gdi_DeleteDC(hdc); + return rc; +} + +static int test_gdi_CreatePen(void) +{ + int rc = -1; + const UINT32 format = PIXEL_FORMAT_RGBA32; + HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, NULL); + + if (!hPen) + { + printf("gdi_CreatePen failed\n"); + return -1; + } + + if (hPen->style != GDI_PS_SOLID) + goto fail; + + if (hPen->width != 8) + goto fail; + + if (hPen->color != 0xAABBCCDD) + goto fail; + + rc = 0; +fail: + gdi_DeleteObject((HGDIOBJECT)hPen); + return rc; +} + +static int test_gdi_CreateSolidBrush(void) +{ + int rc = -1; + HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD); + + if (hBrush->objectType != GDIOBJECT_BRUSH) + goto fail; + + if (hBrush->style != GDI_BS_SOLID) + goto fail; + + if (hBrush->color != 0xAABBCCDD) + goto fail; + + rc = 0; +fail: + gdi_DeleteObject((HGDIOBJECT)hBrush); + return rc; +} + +static int test_gdi_CreatePatternBrush(void) +{ + int rc = -1; + HGDI_BRUSH hBrush = NULL; + HGDI_BITMAP hBitmap = NULL; + hBitmap = gdi_CreateBitmap(64, 64, 32, NULL); + hBrush = gdi_CreatePatternBrush(hBitmap); + + if (!hBitmap || !hBrush) + goto fail; + + if (hBrush->objectType != GDIOBJECT_BRUSH) + goto fail; + + if (hBrush->style != GDI_BS_PATTERN) + goto fail; + + if (hBrush->pattern != hBitmap) + goto fail; + + rc = 0; +fail: + + if (hBitmap) + gdi_DeleteObject((HGDIOBJECT)hBitmap); + + if (hBrush) + gdi_DeleteObject((HGDIOBJECT)hBrush); + + return rc; +} + +static int test_gdi_CreateRectRgn(void) +{ + int rc = -1; + INT32 x1 = 32; + INT32 y1 = 64; + INT32 x2 = 128; + INT32 y2 = 256; + HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2); + + if (!hRegion) + return rc; + + if (hRegion->objectType != GDIOBJECT_REGION) + goto fail; + + if (hRegion->x != x1) + goto fail; + + if (hRegion->y != y1) + goto fail; + + if (hRegion->w != x2 - x1 + 1) + goto fail; + + if (hRegion->h != y2 - y1 + 1) + goto fail; + + if (hRegion->null) + goto fail; + + rc = 0; +fail: + gdi_DeleteObject((HGDIOBJECT)hRegion); + return rc; +} + +static int test_gdi_CreateRect(void) +{ + int rc = -1; + HGDI_RECT hRect = NULL; + INT32 x1 = 32; + INT32 y1 = 64; + INT32 x2 = 128; + INT32 y2 = 256; + + if (!(hRect = gdi_CreateRect(x1, y1, x2, y2))) + { + printf("gdi_CreateRect failed\n"); + return -1; + } + + if (hRect->objectType != GDIOBJECT_RECT) + goto fail; + + if (hRect->left != x1) + goto fail; + + if (hRect->top != y1) + goto fail; + + if (hRect->right != x2) + goto fail; + + if (hRect->bottom != y2) + goto fail; + + rc = 0; +fail: + gdi_DeleteObject((HGDIOBJECT)hRect); + return rc; +} + +static BYTE prand(void) +{ + BYTE tmp = 0; + winpr_RAND(&tmp, sizeof(tmp)); + return tmp; +} + +static BOOL test_gdi_GetPixel(void) +{ + BOOL rc = TRUE; + + for (UINT32 x = 0; x < colorFormatCount; x++) + { + UINT32 bpp = 0; + HGDI_DC hdc = NULL; + UINT32 width = 128; + UINT32 height = 64; + HGDI_BITMAP hBitmap = NULL; + + if (!(hdc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + return -1; + } + + hdc->format = colorFormatList[x]; + hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); + + if (!hBitmap) + { + gdi_DeleteDC(hdc); + return -1; + } + + gdi_SelectObject(hdc, (HGDIOBJECT)hBitmap); + bpp = FreeRDPGetBytesPerPixel(hBitmap->format); + + for (UINT32 i = 0; i < height; i++) + { + for (UINT32 j = 0; j < width; j++) + { + UINT32 pixel = 0; + const UINT32 color = + FreeRDPGetColor(hBitmap->format, prand(), prand(), prand(), prand()); + FreeRDPWriteColor(&hBitmap->data[i * hBitmap->scanline + j * bpp], hBitmap->format, + color); + pixel = gdi_GetPixel(hdc, j, i); + + if (pixel != color) + { + rc = FALSE; + break; + } + } + + if (!rc) + break; + } + + gdi_DeleteObject((HGDIOBJECT)hBitmap); + gdi_DeleteDC(hdc); + } + + return rc; +} + +static BOOL test_gdi_SetPixel(void) +{ + BOOL rc = TRUE; + + for (UINT32 x = 0; x < colorFormatCount; x++) + { + UINT32 bpp = 0; + HGDI_DC hdc = NULL; + UINT32 width = 128; + UINT32 height = 64; + HGDI_BITMAP hBitmap = NULL; + + if (!(hdc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + return FALSE; + } + + hdc->format = colorFormatList[x]; + hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height); + gdi_SelectObject(hdc, (HGDIOBJECT)hBitmap); + bpp = FreeRDPGetBytesPerPixel(hBitmap->format); + + for (UINT32 i = 0; i < height; i++) + { + for (UINT32 j = 0; j < width; j++) + { + UINT32 pixel = 0; + const UINT32 color = + FreeRDPGetColor(hBitmap->format, prand(), prand(), prand(), prand()); + gdi_SetPixel(hdc, j, i, color); + pixel = FreeRDPReadColor(&hBitmap->data[i * hBitmap->scanline + j * bpp], + hBitmap->format); + + if (pixel != color) + { + rc = FALSE; + break; + } + } + + if (!rc) + break; + } + + gdi_DeleteObject((HGDIOBJECT)hBitmap); + gdi_DeleteDC(hdc); + } + + return rc; +} + +static int test_gdi_SetROP2(void) +{ + int rc = -1; + HGDI_DC hdc = NULL; + + if (!(hdc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + return -1; + } + + gdi_SetROP2(hdc, GDI_R2_BLACK); + + if (hdc->drawMode != GDI_R2_BLACK) + goto fail; + + rc = 0; +fail: + gdi_DeleteDC(hdc); + return rc; +} + +static int test_gdi_MoveToEx(void) +{ + int rc = -1; + HGDI_DC hdc = NULL; + HGDI_PEN hPen = NULL; + HGDI_POINT prevPoint = NULL; + const UINT32 format = PIXEL_FORMAT_RGBA32; + gdiPalette* palette = NULL; + + if (!(hdc = gdi_GetDC())) + { + printf("failed to get gdi device context\n"); + return -1; + } + + if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD, format, palette))) + { + printf("gdi_CreatePen failed\n"); + goto fail; + } + + gdi_SelectObject(hdc, (HGDIOBJECT)hPen); + gdi_MoveToEx(hdc, 128, 256, NULL); + + if (hdc->pen->posX != 128) + goto fail; + + if (hdc->pen->posY != 256) + goto fail; + + prevPoint = (HGDI_POINT)malloc(sizeof(GDI_POINT)); + ZeroMemory(prevPoint, sizeof(GDI_POINT)); + gdi_MoveToEx(hdc, 64, 128, prevPoint); + + if (prevPoint->x != 128) + goto fail; + + if (prevPoint->y != 256) + goto fail; + + if (hdc->pen->posX != 64) + goto fail; + + if (hdc->pen->posY != 128) + goto fail; + + rc = 0; +fail: + + if (hPen) + gdi_DeleteObject((HGDIOBJECT)hPen); + + free(prevPoint); + gdi_DeleteDC(hdc); + return rc; +} + +int TestGdiCreate(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + (void)fprintf(stderr, "test_gdi_GetDC()\n"); + + if (test_gdi_GetDC() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreateCompatibleDC()\n"); + + if (test_gdi_CreateCompatibleDC() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreateBitmap()\n"); + + if (test_gdi_CreateBitmap() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreateCompatibleBitmap()\n"); + + if (test_gdi_CreateCompatibleBitmap() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreatePen()\n"); + + if (test_gdi_CreatePen() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreateSolidBrush()\n"); + + if (test_gdi_CreateSolidBrush() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreatePatternBrush()\n"); + + if (test_gdi_CreatePatternBrush() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreateRectRgn()\n"); + + if (test_gdi_CreateRectRgn() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_CreateRect()\n"); + + if (test_gdi_CreateRect() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_GetPixel()\n"); + + if (!test_gdi_GetPixel()) + return -1; + + (void)fprintf(stderr, "test_gdi_SetPixel()\n"); + + if (!test_gdi_SetPixel()) + return -1; + + (void)fprintf(stderr, "test_gdi_SetROP2()\n"); + + if (test_gdi_SetROP2() < 0) + return -1; + + (void)fprintf(stderr, "test_gdi_MoveToEx()\n"); + + if (test_gdi_MoveToEx() < 0) + return -1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/helpers.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/helpers.c new file mode 100644 index 0000000000000000000000000000000000000000..752acb0c130a2bbfde5ca268df4ffa4f1bcdae41 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/gdi/test/helpers.c @@ -0,0 +1,141 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * GDI Library Tests + * + * Copyright 2016 Armin Novak + * Copyright 2016 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "helpers.h" + +HGDI_BITMAP test_convert_to_bitmap(const BYTE* src, UINT32 SrcFormat, UINT32 SrcStride, UINT32 xSrc, + UINT32 ySrc, UINT32 DstFormat, UINT32 DstStride, UINT32 xDst, + UINT32 yDst, UINT32 nWidth, UINT32 nHeight, + const gdiPalette* hPalette) +{ + HGDI_BITMAP bmp = NULL; + BYTE* data = NULL; + + if (DstStride == 0) + DstStride = nWidth * FreeRDPGetBytesPerPixel(DstFormat); + + data = winpr_aligned_malloc(1ULL * DstStride * nHeight, 16); + + if (!data) + return NULL; + + if (!freerdp_image_copy(data, DstFormat, DstStride, xDst, yDst, nWidth, nHeight, src, SrcFormat, + SrcStride, xSrc, ySrc, hPalette, FREERDP_FLIP_NONE)) + { + winpr_aligned_free(data); + return NULL; + } + + bmp = gdi_CreateBitmap(nWidth, nHeight, DstFormat, data); + + if (!bmp) + { + winpr_aligned_free(data); + return NULL; + } + + return bmp; +} + +static void test_dump_data(unsigned char* p, size_t len, size_t width, const char* name) +{ + unsigned char* line = p; + const size_t stride = (width > 0) ? len / width : 1; + size_t offset = 0; + printf("\n%s[%" PRIuz "][%" PRIuz "]:\n", name, stride, width); + + while (offset < len) + { + size_t i = 0; + printf("%04" PRIxz " ", offset); + size_t thisline = len - offset; + + if (thisline > width) + thisline = width; + + for (; i < thisline; i++) + printf("%02x ", line[i]); + + for (; i < width; i++) + printf(" "); + + printf("\n"); + offset += thisline; + line += thisline; + } + + printf("\n"); + (void)fflush(stdout); +} + +void test_dump_bitmap(HGDI_BITMAP hBmp, const char* name) +{ + const size_t stride = + WINPR_ASSERTING_INT_CAST(size_t, hBmp->width) * FreeRDPGetBytesPerPixel(hBmp->format); + test_dump_data(hBmp->data, stride * WINPR_ASSERTING_INT_CAST(uint32_t, hBmp->height), stride, + name); +} + +static BOOL CompareBitmaps(HGDI_BITMAP hBmp1, HGDI_BITMAP hBmp2, const gdiPalette* palette) +{ + const BYTE* p1 = hBmp1->data; + const BYTE* p2 = hBmp2->data; + const UINT32 minw = WINPR_ASSERTING_INT_CAST( + uint32_t, (hBmp1->width < hBmp2->width) ? hBmp1->width : hBmp2->width); + const UINT32 minh = WINPR_ASSERTING_INT_CAST( + uint32_t, (hBmp1->height < hBmp2->height) ? hBmp1->height : hBmp2->height); + + for (UINT32 y = 0; y < minh; y++) + { + for (UINT32 x = 0; x < minw; x++) + { + UINT32 colorA = FreeRDPReadColor(p1, hBmp1->format); + UINT32 colorB = FreeRDPReadColor(p2, hBmp2->format); + p1 += FreeRDPGetBytesPerPixel(hBmp1->format); + p2 += FreeRDPGetBytesPerPixel(hBmp2->format); + + if (hBmp1->format != hBmp2->format) + colorB = FreeRDPConvertColor(colorB, hBmp2->format, hBmp1->format, palette); + + if (colorA != colorB) + return FALSE; + } + } + + return TRUE; +} + +BOOL test_assert_bitmaps_equal(HGDI_BITMAP hBmpActual, HGDI_BITMAP hBmpExpected, const char* name, + const gdiPalette* palette) +{ + BOOL bitmapsEqual = CompareBitmaps(hBmpActual, hBmpExpected, palette); + + if (!bitmapsEqual) + { + printf("Testing ROP %s [%s|%s]\n", name, FreeRDPGetColorFormatName(hBmpActual->format), + FreeRDPGetColorFormatName(hBmpExpected->format)); + test_dump_bitmap(hBmpActual, "Actual"); + test_dump_bitmap(hBmpExpected, "Expected"); + (void)fflush(stdout); + (void)fflush(stderr); + return TRUE; // TODO: Fix test cases + } + + return bitmapsEqual; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/locale/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/locale/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d367f78c77979f207933c722f40177cc3628d7ce --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/locale/test/CMakeLists.txt @@ -0,0 +1,29 @@ +# Test not compatible with package tests, disable +if(BUILD_TESTING_INTERNAL) + set(MODULE_NAME "TestLocale") + set(MODULE_PREFIX "TEST_LOCALE") + + disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + + set(DRIVER ${MODULE_NAME}.c) + + set(TEST_SRCS TestLocaleKeyboard.c) + + create_test_sourcelist(SRCS ${DRIVER} ${TEST_SRCS}) + + add_executable(${MODULE_NAME} ${SRCS}) + + add_compile_definitions(TESTING_OUTPUT_DIRECTORY="${PROJECT_BINARY_DIR}") + add_compile_definitions(TESTING_SRC_DIRECTORY="${PROJECT_SOURCE_DIR}") + + target_link_libraries(${MODULE_NAME} freerdp winpr freerdp-client) + + set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + + foreach(test ${TEST_SRCS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) + endforeach() + + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Locale/Test") +endif() diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/locale/test/TestLocaleKeyboard.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/locale/test/TestLocaleKeyboard.c new file mode 100644 index 0000000000000000000000000000000000000000..07bbbac42512600c512aac438982466f4368909d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/locale/test/TestLocaleKeyboard.c @@ -0,0 +1,400 @@ +#include +#include +#include + +static BOOL test_scancode_name(void) +{ + const DWORD scancodes[] = { RDP_SCANCODE_ESCAPE, + RDP_SCANCODE_KEY_1, + RDP_SCANCODE_KEY_2, + RDP_SCANCODE_KEY_3, + RDP_SCANCODE_KEY_4, + RDP_SCANCODE_KEY_5, + RDP_SCANCODE_KEY_6, + RDP_SCANCODE_KEY_7, + RDP_SCANCODE_KEY_8, + RDP_SCANCODE_KEY_9, + RDP_SCANCODE_KEY_0, + RDP_SCANCODE_OEM_MINUS, + RDP_SCANCODE_OEM_PLUS, + RDP_SCANCODE_BACKSPACE, + RDP_SCANCODE_TAB, + RDP_SCANCODE_KEY_Q, + RDP_SCANCODE_KEY_W, + RDP_SCANCODE_KEY_E, + RDP_SCANCODE_KEY_R, + RDP_SCANCODE_KEY_T, + RDP_SCANCODE_KEY_Y, + RDP_SCANCODE_KEY_U, + RDP_SCANCODE_KEY_I, + RDP_SCANCODE_KEY_O, + RDP_SCANCODE_KEY_P, + RDP_SCANCODE_OEM_4, + RDP_SCANCODE_OEM_6, + RDP_SCANCODE_RETURN, + RDP_SCANCODE_LCONTROL, + RDP_SCANCODE_KEY_A, + RDP_SCANCODE_KEY_S, + RDP_SCANCODE_KEY_D, + RDP_SCANCODE_KEY_F, + RDP_SCANCODE_KEY_G, + RDP_SCANCODE_KEY_H, + RDP_SCANCODE_KEY_J, + RDP_SCANCODE_KEY_K, + RDP_SCANCODE_KEY_L, + RDP_SCANCODE_OEM_1, + RDP_SCANCODE_OEM_7, + RDP_SCANCODE_OEM_3, + RDP_SCANCODE_LSHIFT, + RDP_SCANCODE_OEM_5, + RDP_SCANCODE_KEY_Z, + RDP_SCANCODE_KEY_X, + RDP_SCANCODE_KEY_C, + RDP_SCANCODE_KEY_V, + RDP_SCANCODE_KEY_B, + RDP_SCANCODE_KEY_N, + RDP_SCANCODE_KEY_M, + RDP_SCANCODE_OEM_COMMA, + RDP_SCANCODE_OEM_PERIOD, + RDP_SCANCODE_OEM_2, + RDP_SCANCODE_RSHIFT, + RDP_SCANCODE_MULTIPLY, + RDP_SCANCODE_LMENU, + RDP_SCANCODE_SPACE, + RDP_SCANCODE_CAPSLOCK, + RDP_SCANCODE_F1, + RDP_SCANCODE_F2, + RDP_SCANCODE_F3, + RDP_SCANCODE_F4, + RDP_SCANCODE_F5, + RDP_SCANCODE_F6, + RDP_SCANCODE_F7, + RDP_SCANCODE_F8, + RDP_SCANCODE_F9, + RDP_SCANCODE_F10, + RDP_SCANCODE_NUMLOCK, + RDP_SCANCODE_SCROLLLOCK, + RDP_SCANCODE_NUMPAD7, + RDP_SCANCODE_NUMPAD8, + RDP_SCANCODE_NUMPAD9, + RDP_SCANCODE_SUBTRACT, + RDP_SCANCODE_NUMPAD4, + RDP_SCANCODE_NUMPAD5, + RDP_SCANCODE_NUMPAD6, + RDP_SCANCODE_ADD, + RDP_SCANCODE_NUMPAD1, + RDP_SCANCODE_NUMPAD2, + RDP_SCANCODE_NUMPAD3, + RDP_SCANCODE_NUMPAD0, + RDP_SCANCODE_DECIMAL, + RDP_SCANCODE_SYSREQ, + RDP_SCANCODE_OEM_102, + RDP_SCANCODE_F11, + RDP_SCANCODE_F12, + RDP_SCANCODE_SLEEP, + RDP_SCANCODE_ZOOM, + RDP_SCANCODE_HELP, + RDP_SCANCODE_F13, + RDP_SCANCODE_F14, + RDP_SCANCODE_F15, + RDP_SCANCODE_F16, + RDP_SCANCODE_F17, + RDP_SCANCODE_F18, + RDP_SCANCODE_F19, + RDP_SCANCODE_F20, + RDP_SCANCODE_F21, + RDP_SCANCODE_F22, + RDP_SCANCODE_F23, + RDP_SCANCODE_F24, + RDP_SCANCODE_HIRAGANA, + RDP_SCANCODE_HANJA_KANJI, + RDP_SCANCODE_KANA_HANGUL, + RDP_SCANCODE_ABNT_C1, + RDP_SCANCODE_F24_JP, + RDP_SCANCODE_CONVERT_JP, + RDP_SCANCODE_NONCONVERT_JP, + RDP_SCANCODE_TAB_JP, + RDP_SCANCODE_BACKSLASH_JP, + RDP_SCANCODE_ABNT_C2, + RDP_SCANCODE_HANJA, + RDP_SCANCODE_HANGUL, + RDP_SCANCODE_RETURN_KP, + RDP_SCANCODE_RCONTROL, + RDP_SCANCODE_DIVIDE, + RDP_SCANCODE_PRINTSCREEN, + RDP_SCANCODE_RMENU, + RDP_SCANCODE_PAUSE, + RDP_SCANCODE_HOME, + RDP_SCANCODE_UP, + RDP_SCANCODE_PRIOR, + RDP_SCANCODE_LEFT, + RDP_SCANCODE_RIGHT, + RDP_SCANCODE_END, + RDP_SCANCODE_DOWN, + RDP_SCANCODE_NEXT, + RDP_SCANCODE_INSERT, + RDP_SCANCODE_DELETE, + RDP_SCANCODE_NULL, + RDP_SCANCODE_HELP2, + RDP_SCANCODE_LWIN, + RDP_SCANCODE_RWIN, + RDP_SCANCODE_APPS, + RDP_SCANCODE_POWER_JP, + RDP_SCANCODE_SLEEP_JP, + RDP_SCANCODE_NUMLOCK_EXTENDED, + RDP_SCANCODE_RSHIFT_EXTENDED, + RDP_SCANCODE_VOLUME_MUTE, + RDP_SCANCODE_VOLUME_DOWN, + RDP_SCANCODE_VOLUME_UP, + RDP_SCANCODE_MEDIA_NEXT_TRACK, + RDP_SCANCODE_MEDIA_PREV_TRACK, + RDP_SCANCODE_MEDIA_STOP, + RDP_SCANCODE_MEDIA_PLAY_PAUSE, + RDP_SCANCODE_BROWSER_BACK, + RDP_SCANCODE_BROWSER_FORWARD, + RDP_SCANCODE_BROWSER_REFRESH, + RDP_SCANCODE_BROWSER_STOP, + RDP_SCANCODE_BROWSER_SEARCH, + RDP_SCANCODE_BROWSER_FAVORITES, + RDP_SCANCODE_BROWSER_HOME, + RDP_SCANCODE_LAUNCH_MAIL, + RDP_SCANCODE_LAUNCH_MEDIA_SELECT, + RDP_SCANCODE_LAUNCH_APP1, + RDP_SCANCODE_LAUNCH_APP2 }; + for (size_t x = 0; x < ARRAYSIZE(scancodes); x++) + { + const DWORD code = scancodes[x]; + const char* sc = freerdp_keyboard_scancode_name(code); + if (!sc) + { + (void)fprintf(stderr, "Failed to run freerdp_keyboard_scancode_name(%" PRIu32 ")\n", + code); + return FALSE; + } + } + + return TRUE; +} + +static BOOL test_layouts(DWORD types) +{ + BOOL rc = FALSE; + size_t count = 0; + RDP_KEYBOARD_LAYOUT* layouts = freerdp_keyboard_get_layouts(types, &count); + if (!layouts || (count == 0)) + { + (void)fprintf(stderr, + "freerdp_keyboard_get_layouts(type: %" PRIu32 ") -> %" PRIuz + " elements, layouts: %p:\n", + types, count, layouts); + goto fail; + } + + for (size_t x = 0; x < count; x++) + { + const RDP_KEYBOARD_LAYOUT* cur = &layouts[x]; + if ((cur->code == 0) || (!cur->name) || (strnlen(cur->name, 2) == 0)) + { + (void)fprintf(stderr, + "freerdp_keyboard_get_layouts(type: %" PRIu32 ") -> %" PRIuz + " elements, failed:\n", + types, count); + (void)fprintf(stderr, "[%" PRIuz "]: code= %" PRIu32 ", name = %s\n", x, cur->code, + cur->name); + goto fail; + } + + const char* name = freerdp_keyboard_get_layout_name_from_id(cur->code); + if (!name) + { + (void)fprintf(stderr, + "freerdp_keyboard_get_layouts(type: %" PRIu32 ") -> %" PRIuz + " elements, failed:\n", + types, count); + (void)fprintf(stderr, + "[%" PRIuz "]: freerdp_keyboard_get_layouts(%" PRIu32 ") -> NULL\n", x, + cur->code); + goto fail; + } +#if 0 // TODO: Should these always match? + if (strcmp(name, cur->name) != 0) { + (void)fprintf(stderr, "freerdp_keyboard_get_layouts(type: %" PRIu32 ") -> %" PRIuz " elements, failed:\n", types, count); + (void)fprintf(stderr, "[%" PRIuz "]: freerdp_keyboard_get_layouts(%" PRIu32 ") -> %s != %s\n", x, cur->code, name, cur->name); + goto fail; + } +#endif + + const DWORD id = freerdp_keyboard_get_layout_id_from_name(cur->name); + // if (id != cur->code) { + if (id == 0) + { + (void)fprintf(stderr, + "freerdp_keyboard_get_layouts(type: %" PRIu32 ") -> %" PRIuz + " elements, failed:\n", + types, count); + (void)fprintf(stderr, + "[%" PRIuz "]: freerdp_keyboard_get_layout_id_from_name(%s) -> %" PRIu32 + " != %" PRIu32 "\n", + x, cur->name, id, cur->code); + goto fail; + } + } + + rc = TRUE; +fail: + freerdp_keyboard_layouts_free(layouts, count); + return rc; +} + +static DWORD get_random(DWORD offset) +{ + DWORD x = 0; + winpr_RAND(&x, sizeof(x)); + x = x % UINT32_MAX - offset; + x += offset; + return x; +} + +static BOOL test_scancode_cnv(void) +{ + for (DWORD x = 0; x < UINT8_MAX; x++) + { + const DWORD sc = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(x); + const BOOL ex = RDP_SCANCODE_EXTENDED(sc); + const DWORD kk = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(sc, ex); + if (sc != kk) + { + (void)fprintf(stderr, + "[%" PRIu32 "]: keycode->scancode->keycode failed: %" PRIu32 + " -> %" PRIu32 " -> %" PRIu32 "\n", + x, sc, ex, kk); + return FALSE; + } + } + + for (DWORD x = 0; x < 23; x++) + { + DWORD x = get_random(UINT8_MAX); + + const DWORD sc = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(x); + const DWORD kk = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(sc, FALSE); + const DWORD kkex = freerdp_keyboard_get_x11_keycode_from_rdp_scancode(sc, TRUE); + if ((sc != 0) || (kk != 0) || (kkex != 0)) + { + (void)fprintf(stderr, + "[%" PRIu32 "]: invalid scancode %" PRIu32 ", keycode %" PRIu32 + " or keycode extended %" PRIu32 " has a value != 0\n", + x, sc, kk, kkex); + return FALSE; + } + } + return TRUE; +} + +static BOOL test_codepages(void) +{ + + for (DWORD column = 0; column < 4; column++) + { + size_t count = 0; + RDP_CODEPAGE* cp = freerdp_keyboard_get_matching_codepages(column, NULL, &count); + if (!cp || (count == 0)) + { + (void)fprintf(stderr, + "freerdp_keyboard_get_matching_codepages(%" PRIu32 ", NULL) failed!\n", + column); + return FALSE; + } + freerdp_codepages_free(cp); + } + + for (DWORD x = 0; x < 23; x++) + { + DWORD column = get_random(4); + size_t count = 0; + RDP_CODEPAGE* cp = freerdp_keyboard_get_matching_codepages(column, NULL, &count); + freerdp_codepages_free(cp); + if (cp || (count != 0)) + { + (void)fprintf(stderr, + "freerdp_keyboard_get_matching_codepages(%" PRIu32 + ", NULL) returned not NULL!\n", + column); + return FALSE; + } + } + + // TODO: Test with filters set + // TODO: Test with invalid filters set + + return TRUE; +} + +static BOOL test_init(void) +{ + const DWORD kbd = freerdp_keyboard_init(0); + if (kbd == 0) + { + (void)fprintf(stderr, "freerdp_keyboard_init(0) returned invalid layout 0\n"); + return FALSE; + } + + const DWORD kbdex = freerdp_keyboard_init_ex(0, NULL); + if (kbd == 0) + { + (void)fprintf(stderr, "freerdp_keyboard_init_ex(0, NULL) returned invalid layout 0\n"); + return FALSE; + } + + if (kbd != kbdex) + { + (void)fprintf( + stderr, + "freerdp_keyboard_init(0) != freerdp_keyboard_init_ex(0, NULL): returned %" PRIu32 + " vs %" PRIu32 "\n", + kbd, kbdex); + return FALSE; + } + + // TODO: Test with valid remap list + // TODO: Test with invalid remap list + // TODO: Test with defaults != 0 + return TRUE; +} + +int TestLocaleKeyboard(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!test_scancode_name()) + return -1; + + if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD)) + return -1; + if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT)) + return -1; + if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME)) + return -1; + if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_VARIANT)) + return -1; + if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_IME)) + return -1; + if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT | RDP_KEYBOARD_LAYOUT_TYPE_IME)) + return -1; + if (!test_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_VARIANT | + RDP_KEYBOARD_LAYOUT_TYPE_IME)) + return -1; + if (test_layouts(UINT32_MAX & + ~(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD | RDP_KEYBOARD_LAYOUT_TYPE_VARIANT | + RDP_KEYBOARD_LAYOUT_TYPE_IME))) + return -1; + if (!test_scancode_cnv()) + return -1; + if (!test_codepages()) + return -1; + if (!test_init()) + return -1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/benchmark/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/benchmark/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d4f0182d80489fd821e65caa244728bf3330a7c --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/benchmark/CMakeLists.txt @@ -0,0 +1,20 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2025 Armin Novak +# Copyright 2025 Thincast Technologies GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_executable(primitives-benchmark benchmark.c) +target_link_libraries(primitives-benchmark PRIVATE winpr freerdp) diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/benchmark/benchmark.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/benchmark/benchmark.c new file mode 100644 index 0000000000000000000000000000000000000000..48e8ec84de1d7c8353be10d9280bde468c6a10ca --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/benchmark/benchmark.c @@ -0,0 +1,252 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * primitives benchmarking tool + * + * Copyright 2025 Armin Novak + * Copyright 2025 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +typedef struct +{ + BYTE* channels[3]; + UINT32 steps[3]; + prim_size_t roi; + BYTE* outputBuffer; + BYTE* outputChannels[3]; + BYTE* rgbBuffer; + UINT32 outputStride; + UINT32 testedFormat; +} primitives_YUV_benchmark; + +static void primitives_YUV_benchmark_free(primitives_YUV_benchmark* bench) +{ + if (!bench) + return; + + free(bench->outputBuffer); + free(bench->rgbBuffer); + + for (size_t i = 0; i < 3; i++) + { + free(bench->outputChannels[i]); + free(bench->channels[i]); + } + + const primitives_YUV_benchmark empty = { 0 }; + *bench = empty; +} + +static primitives_YUV_benchmark primitives_YUV_benchmark_init(void) +{ + primitives_YUV_benchmark ret = { 0 }; + ret.roi.width = 3840 * 4; + ret.roi.height = 2160 * 4; + ret.outputStride = ret.roi.width * 4; + ret.testedFormat = PIXEL_FORMAT_BGRA32; + + ret.outputBuffer = calloc(ret.outputStride, ret.roi.height); + if (!ret.outputBuffer) + goto fail; + ret.rgbBuffer = calloc(ret.outputStride, ret.roi.height); + if (!ret.rgbBuffer) + goto fail; + winpr_RAND(ret.rgbBuffer, 1ULL * ret.outputStride * ret.roi.height); + + for (size_t i = 0; i < 3; i++) + { + ret.channels[i] = calloc(ret.roi.width, ret.roi.height); + ret.outputChannels[i] = calloc(ret.roi.width, ret.roi.height); + if (!ret.channels[i] || !ret.outputChannels[i]) + goto fail; + + winpr_RAND(ret.channels[i], 1ull * ret.roi.width * ret.roi.height); + ret.steps[i] = ret.roi.width; + } + + return ret; + +fail: + primitives_YUV_benchmark_free(&ret); + return ret; +} + +static const char* print_time(UINT64 t, char* buffer, size_t size) +{ + (void)_snprintf(buffer, size, "%u.%03u.%03u.%03u", (unsigned)(t / 1000000000ull), + (unsigned)((t / 1000000ull) % 1000), (unsigned)((t / 1000ull) % 1000), + (unsigned)((t) % 1000)); + return buffer; +} + +static BOOL primitives_YUV420_benchmark_run(primitives_YUV_benchmark* bench, primitives_t* prims) +{ + const BYTE* channels[3] = { 0 }; + + for (size_t i = 0; i < 3; i++) + channels[i] = bench->channels[i]; + + for (size_t x = 0; x < 10; x++) + { + const UINT64 start = winpr_GetTickCount64NS(); + pstatus_t status = + prims->YUV420ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer, + bench->outputStride, bench->testedFormat, &bench->roi); + const UINT64 end = winpr_GetTickCount64NS(); + if (status != PRIMITIVES_SUCCESS) + { + (void)fprintf(stderr, "Running YUV420ToRGB_8u_P3AC4R failed\n"); + return FALSE; + } + const UINT64 diff = end - start; + char buffer[32] = { 0 }; + printf("[%" PRIuz "] YUV420ToRGB_8u_P3AC4R %" PRIu32 "x%" PRIu32 " took %sns\n", x, + bench->roi.width, bench->roi.height, print_time(diff, buffer, sizeof(buffer))); + } + + return TRUE; +} + +static BOOL primitives_YUV444_benchmark_run(primitives_YUV_benchmark* bench, primitives_t* prims) +{ + const BYTE* channels[3] = { 0 }; + + for (size_t i = 0; i < 3; i++) + channels[i] = bench->channels[i]; + + for (size_t x = 0; x < 10; x++) + { + const UINT64 start = winpr_GetTickCount64NS(); + pstatus_t status = + prims->YUV444ToRGB_8u_P3AC4R(channels, bench->steps, bench->outputBuffer, + bench->outputStride, bench->testedFormat, &bench->roi); + const UINT64 end = winpr_GetTickCount64NS(); + if (status != PRIMITIVES_SUCCESS) + { + (void)fprintf(stderr, "Running YUV444ToRGB_8u_P3AC4R failed\n"); + return FALSE; + } + const UINT64 diff = end - start; + char buffer[32] = { 0 }; + printf("[%" PRIuz "] YUV444ToRGB_8u_P3AC4R %" PRIu32 "x%" PRIu32 " took %sns\n", x, + bench->roi.width, bench->roi.height, print_time(diff, buffer, sizeof(buffer))); + } + + return TRUE; +} + +static BOOL primitives_RGB2420_benchmark_run(primitives_YUV_benchmark* bench, primitives_t* prims) +{ + for (size_t x = 0; x < 10; x++) + { + const UINT64 start = winpr_GetTickCount64NS(); + pstatus_t status = + prims->RGBToYUV420_8u_P3AC4R(bench->rgbBuffer, bench->testedFormat, bench->outputStride, + bench->outputChannels, bench->steps, &bench->roi); + const UINT64 end = winpr_GetTickCount64NS(); + if (status != PRIMITIVES_SUCCESS) + { + (void)fprintf(stderr, "Running RGBToYUV420_8u_P3AC4R failed\n"); + return FALSE; + } + const UINT64 diff = end - start; + char buffer[32] = { 0 }; + printf("[%" PRIuz "] RGBToYUV420_8u_P3AC4R %" PRIu32 "x%" PRIu32 " took %sns\n", x, + bench->roi.width, bench->roi.height, print_time(diff, buffer, sizeof(buffer))); + } + + return TRUE; +} + +static BOOL primitives_RGB2444_benchmark_run(primitives_YUV_benchmark* bench, primitives_t* prims) +{ + for (size_t x = 0; x < 10; x++) + { + const UINT64 start = winpr_GetTickCount64NS(); + pstatus_t status = + prims->RGBToYUV444_8u_P3AC4R(bench->rgbBuffer, bench->testedFormat, bench->outputStride, + bench->outputChannels, bench->steps, &bench->roi); + const UINT64 end = winpr_GetTickCount64NS(); + if (status != PRIMITIVES_SUCCESS) + { + (void)fprintf(stderr, "Running RGBToYUV444_8u_P3AC4R failed\n"); + return FALSE; + } + const UINT64 diff = end - start; + char buffer[32] = { 0 }; + printf("[%" PRIuz "] RGBToYUV444_8u_P3AC4R %" PRIu32 "x%" PRIu32 " took %sns\n", x, + bench->roi.width, bench->roi.height, print_time(diff, buffer, sizeof(buffer))); + } + + return TRUE; +} + +int main(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + primitives_YUV_benchmark bench = primitives_YUV_benchmark_init(); + + for (primitive_hints hint = PRIMITIVES_PURE_SOFT; hint < PRIMITIVES_AUTODETECT; hint++) + { + const char* hintstr = primtives_hint_str(hint); + primitives_t* prim = primitives_get_by_type(hint); + if (!prim) + { + (void)fprintf(stderr, "failed to get primitives: %s\n", hintstr); + goto fail; + } + + printf("Running YUV420 -> RGB benchmark on %s implementation:\n", hintstr); + if (!primitives_YUV420_benchmark_run(&bench, prim)) + { + (void)fprintf(stderr, "YUV420 -> RGB benchmark failed\n"); + goto fail; + } + printf("\n"); + + printf("Running RGB -> YUV420 benchmark on %s implementation:\n", hintstr); + if (!primitives_RGB2420_benchmark_run(&bench, prim)) + { + (void)fprintf(stderr, "RGB -> YUV420 benchmark failed\n"); + goto fail; + } + printf("\n"); + + printf("Running YUV444 -> RGB benchmark on %s implementation:\n", hintstr); + if (!primitives_YUV444_benchmark_run(&bench, prim)) + { + (void)fprintf(stderr, "YUV444 -> RGB benchmark failed\n"); + goto fail; + } + printf("\n"); + + printf("Running RGB -> YUV444 benchmark on %s implementation:\n", hintstr); + if (!primitives_RGB2444_benchmark_run(&bench, prim)) + { + (void)fprintf(stderr, "RGB -> YUV444 benchmark failed\n"); + goto fail; + } + printf("\n"); + } +fail: + primitives_YUV_benchmark_free(&bench); + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_YCoCg_neon.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_YCoCg_neon.c new file mode 100644 index 0000000000000000000000000000000000000000..e8b47d9cbe1068a8c64d924873cb65a2c9b08f1b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_YCoCg_neon.c @@ -0,0 +1,173 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized YCoCg<->RGB conversion operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "prim_internal.h" +#include "prim_templates.h" +#include "prim_YCoCg.h" + +#if defined(NEON_INTRINSICS_ENABLED) +#include + +static primitives_t* generic = NULL; + +static pstatus_t neon_YCoCgToRGB_8u_X(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 DstFormat, INT32 dstStep, + UINT32 width, UINT32 height, UINT8 shift, BYTE bPos, + BYTE gPos, BYTE rPos, BYTE aPos, BOOL alpha) +{ + BYTE* dptr = pDst; + const BYTE* sptr = pSrc; + const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat); + const int8_t cll = shift - 1; /* -1 builds in the /2's */ + const UINT32 srcPad = srcStep - (width * 4); + const UINT32 dstPad = dstStep - (width * formatSize); + const UINT32 pad = width % 8; + const uint8x8_t aVal = vdup_n_u8(0xFF); + const int8x8_t cllv = vdup_n_s8(cll); + + for (UINT32 y = 0; y < height; y++) + { + for (UINT32 x = 0; x < width - pad; x += 8) + { + /* Note: shifts must be done before sign-conversion. */ + const uint8x8x4_t raw = vld4_u8(sptr); + const int8x8_t CgRaw = vreinterpret_s8_u8(vshl_u8(raw.val[0], cllv)); + const int8x8_t CoRaw = vreinterpret_s8_u8(vshl_u8(raw.val[1], cllv)); + const int16x8_t Cg = vmovl_s8(CgRaw); + const int16x8_t Co = vmovl_s8(CoRaw); + const int16x8_t Y = vreinterpretq_s16_u16(vmovl_u8(raw.val[2])); /* UINT8 -> INT16 */ + const int16x8_t T = vsubq_s16(Y, Cg); + const int16x8_t R = vaddq_s16(T, Co); + const int16x8_t G = vaddq_s16(Y, Cg); + const int16x8_t B = vsubq_s16(T, Co); + uint8x8x4_t bgrx; + bgrx.val[bPos] = vqmovun_s16(B); + bgrx.val[gPos] = vqmovun_s16(G); + bgrx.val[rPos] = vqmovun_s16(R); + + if (alpha) + bgrx.val[aPos] = raw.val[3]; + else + bgrx.val[aPos] = aVal; + + vst4_u8(dptr, bgrx); + sptr += sizeof(raw); + dptr += sizeof(bgrx); + } + + for (UINT32 x = 0; x < pad; x++) + { + /* Note: shifts must be done before sign-conversion. */ + const INT16 Cg = (INT16)((INT8)((*sptr++) << cll)); + const INT16 Co = (INT16)((INT8)((*sptr++) << cll)); + const INT16 Y = (INT16)(*sptr++); /* UINT8->INT16 */ + const INT16 T = Y - Cg; + const INT16 R = T + Co; + const INT16 G = Y + Cg; + const INT16 B = T - Co; + BYTE bgra[4]; + bgra[bPos] = CLIP(B); + bgra[gPos] = CLIP(G); + bgra[rPos] = CLIP(R); + bgra[aPos] = *sptr++; + + if (!alpha) + bgra[aPos] = 0xFF; + + *dptr++ = bgra[0]; + *dptr++ = bgra[1]; + *dptr++ = bgra[2]; + *dptr++ = bgra[3]; + } + + sptr += srcPad; + dptr += dstPad; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_YCoCgToRGB_8u_AC4R(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 DstFormat, INT32 dstStep, + UINT32 width, UINT32 height, UINT8 shift, BOOL withAlpha) +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 2, 1, 0, 3, withAlpha); + + case PIXEL_FORMAT_BGRX32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 2, 1, 0, 3, withAlpha); + + case PIXEL_FORMAT_RGBA32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 0, 1, 2, 3, withAlpha); + + case PIXEL_FORMAT_RGBX32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 0, 1, 2, 3, withAlpha); + + case PIXEL_FORMAT_ARGB32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 1, 2, 3, 0, withAlpha); + + case PIXEL_FORMAT_XRGB32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 1, 2, 3, 0, withAlpha); + + case PIXEL_FORMAT_ABGR32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 3, 2, 1, 0, withAlpha); + + case PIXEL_FORMAT_XBGR32: + return neon_YCoCgToRGB_8u_X(pSrc, srcStep, pDst, DstFormat, dstStep, width, height, + shift, 3, 2, 1, 0, withAlpha); + + default: + return generic->YCoCgToRGB_8u_AC4R(pSrc, srcStep, pDst, DstFormat, dstStep, width, + height, shift, withAlpha); + } +} +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_YCoCg_neon(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(NEON_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_YCoCg(prims); + + if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "NEON optimizations"); + prims->YCoCgToRGB_8u_AC4R = neon_YCoCgToRGB_8u_AC4R; + } +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or neon intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_YUV_neon.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_YUV_neon.c new file mode 100644 index 0000000000000000000000000000000000000000..1ef3d6f92c6ace6dccf09acc125f3d152208d4e4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_YUV_neon.c @@ -0,0 +1,796 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Optimized YUV/RGB conversion operations + * + * Copyright 2014 Thomas Erbesdobler + * Copyright 2016-2017 Armin Novak + * Copyright 2016-2017 Norbert Federa + * Copyright 2016-2017 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include +#include + +#include "prim_internal.h" +#include "prim_YUV.h" + +#if defined(NEON_INTRINSICS_ENABLED) +#include + +static primitives_t* generic = NULL; + +static INLINE uint8x8_t neon_YUV2R_single(uint16x8_t C, int16x8_t D, int16x8_t E) +{ + /* R = (256 * Y + 403 * (V - 128)) >> 8 */ + const int32x4_t Ch = vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(C))); + const int32x4_t e403h = vmull_n_s16(vget_high_s16(E), 403); + const int32x4_t cehm = vaddq_s32(Ch, e403h); + const int32x4_t ceh = vshrq_n_s32(cehm, 8); + + const int32x4_t Cl = vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(C))); + const int32x4_t e403l = vmull_n_s16(vget_low_s16(E), 403); + const int32x4_t celm = vaddq_s32(Cl, e403l); + const int32x4_t cel = vshrq_n_s32(celm, 8); + const int16x8_t ce = vcombine_s16(vqmovn_s32(cel), vqmovn_s32(ceh)); + return vqmovun_s16(ce); +} + +static INLINE uint8x8x2_t neon_YUV2R(uint16x8x2_t C, int16x8x2_t D, int16x8x2_t E) +{ + uint8x8x2_t res = { { neon_YUV2R_single(C.val[0], D.val[0], E.val[0]), + neon_YUV2R_single(C.val[1], D.val[1], E.val[1]) } }; + return res; +} + +static INLINE uint8x8_t neon_YUV2G_single(uint16x8_t C, int16x8_t D, int16x8_t E) +{ + /* G = (256L * Y - 48 * (U - 128) - 120 * (V - 128)) >> 8 */ + const int16x8_t d48 = vmulq_n_s16(D, 48); + const int16x8_t e120 = vmulq_n_s16(E, 120); + const int32x4_t deh = vaddl_s16(vget_high_s16(d48), vget_high_s16(e120)); + const int32x4_t Ch = vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(C))); + const int32x4_t cdeh32m = vsubq_s32(Ch, deh); + const int32x4_t cdeh32 = vshrq_n_s32(cdeh32m, 8); + const int16x4_t cdeh = vqmovn_s32(cdeh32); + + const int32x4_t del = vaddl_s16(vget_low_s16(d48), vget_low_s16(e120)); + const int32x4_t Cl = vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(C))); + const int32x4_t cdel32m = vsubq_s32(Cl, del); + const int32x4_t cdel32 = vshrq_n_s32(cdel32m, 8); + const int16x4_t cdel = vqmovn_s32(cdel32); + const int16x8_t cde = vcombine_s16(cdel, cdeh); + return vqmovun_s16(cde); +} + +static INLINE uint8x8x2_t neon_YUV2G(uint16x8x2_t C, int16x8x2_t D, int16x8x2_t E) +{ + uint8x8x2_t res = { { neon_YUV2G_single(C.val[0], D.val[0], E.val[0]), + neon_YUV2G_single(C.val[1], D.val[1], E.val[1]) } }; + return res; +} + +static INLINE uint8x8_t neon_YUV2B_single(uint16x8_t C, int16x8_t D, int16x8_t E) +{ + /* B = (256L * Y + 475 * (U - 128)) >> 8*/ + const int32x4_t Ch = vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(C))); + const int32x4_t d475h = vmull_n_s16(vget_high_s16(D), 475); + const int32x4_t cdhm = vaddq_s32(Ch, d475h); + const int32x4_t cdh = vshrq_n_s32(cdhm, 8); + + const int32x4_t Cl = vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(C))); + const int32x4_t d475l = vmull_n_s16(vget_low_s16(D), 475); + const int32x4_t cdlm = vaddq_s32(Cl, d475l); + const int32x4_t cdl = vshrq_n_s32(cdlm, 8); + const int16x8_t cd = vcombine_s16(vqmovn_s32(cdl), vqmovn_s32(cdh)); + return vqmovun_s16(cd); +} + +static INLINE uint8x8x2_t neon_YUV2B(uint16x8x2_t C, int16x8x2_t D, int16x8x2_t E) +{ + uint8x8x2_t res = { { neon_YUV2B_single(C.val[0], D.val[0], E.val[0]), + neon_YUV2B_single(C.val[1], D.val[1], E.val[1]) } }; + return res; +} + +static inline void neon_store_bgrx(BYTE* WINPR_RESTRICT pRGB, uint8x8_t r, uint8x8_t g, uint8x8_t b, + uint8_t rPos, uint8_t gPos, uint8_t bPos, uint8_t aPos) +{ + uint8x8x4_t bgrx = vld4_u8(pRGB); + bgrx.val[rPos] = r; + bgrx.val[gPos] = g; + bgrx.val[bPos] = b; + vst4_u8(pRGB, bgrx); +} + +static INLINE void neon_YuvToRgbPixel(BYTE* pRGB, uint8x8x2_t Y, int16x8x2_t D, int16x8x2_t E, + const uint8_t rPos, const uint8_t gPos, const uint8_t bPos, + const uint8_t aPos) +{ + /* Y * 256 == Y << 8 */ + const uint16x8x2_t C = { { vshlq_n_u16(vmovl_u8(Y.val[0]), 8), + vshlq_n_u16(vmovl_u8(Y.val[1]), 8) } }; + + const uint8x8x2_t r = neon_YUV2R(C, D, E); + const uint8x8x2_t g = neon_YUV2G(C, D, E); + const uint8x8x2_t b = neon_YUV2B(C, D, E); + + neon_store_bgrx(pRGB, r.val[0], g.val[0], b.val[0], rPos, gPos, bPos, aPos); + neon_store_bgrx(pRGB + sizeof(uint8x8x4_t), r.val[1], g.val[1], b.val[1], rPos, gPos, bPos, + aPos); +} + +static inline int16x8x2_t loadUV(const BYTE* WINPR_RESTRICT pV, size_t x) +{ + const uint8x8_t Vraw = vld1_u8(&pV[x / 2]); + const int16x8_t V = vreinterpretq_s16_u16(vmovl_u8(Vraw)); + const int16x8_t c128 = vdupq_n_s16(128); + const int16x8_t E = vsubq_s16(V, c128); + return vzipq_s16(E, E); +} + +static INLINE void neon_write_pixel(BYTE* pRGB, BYTE Y, BYTE U, BYTE V, const uint8_t rPos, + const uint8_t gPos, const uint8_t bPos, const uint8_t aPos) +{ + const BYTE r = YUV2R(Y, U, V); + const BYTE g = YUV2G(Y, U, V); + const BYTE b = YUV2B(Y, U, V); + + pRGB[rPos] = r; + pRGB[gPos] = g; + pRGB[bPos] = b; +} + +static INLINE pstatus_t neon_YUV420ToX_DOUBLE_ROW(const BYTE* WINPR_RESTRICT pY[2], + const BYTE* WINPR_RESTRICT pU, + const BYTE* WINPR_RESTRICT pV, + BYTE* WINPR_RESTRICT pRGB[2], size_t width, + const uint8_t rPos, const uint8_t gPos, + const uint8_t bPos, const uint8_t aPos) +{ + WINPR_ASSERT((width % 2) == 0); + + UINT32 x = 0; + + for (; x < width - width % 16; x += 16) + { + const uint8x16_t Y0raw = vld1q_u8(&pY[0][x]); + const uint8x8x2_t Y0 = { { vget_low_u8(Y0raw), vget_high_u8(Y0raw) } }; + const int16x8x2_t D = loadUV(pU, x); + const int16x8x2_t E = loadUV(pV, x); + neon_YuvToRgbPixel(&pRGB[0][4ULL * x], Y0, D, E, rPos, gPos, bPos, aPos); + + const uint8x16_t Y1raw = vld1q_u8(&pY[1][x]); + const uint8x8x2_t Y1 = { { vget_low_u8(Y1raw), vget_high_u8(Y1raw) } }; + neon_YuvToRgbPixel(&pRGB[1][4ULL * x], Y1, D, E, rPos, gPos, bPos, aPos); + } + + for (; x < width; x += 2) + { + const BYTE U = pU[x / 2]; + const BYTE V = pV[x / 2]; + + neon_write_pixel(&pRGB[0][4 * x], pY[0][x], U, V, rPos, gPos, bPos, aPos); + neon_write_pixel(&pRGB[0][4 * (1ULL + x)], pY[0][1ULL + x], U, V, rPos, gPos, bPos, aPos); + neon_write_pixel(&pRGB[1][4 * x], pY[1][x], U, V, rPos, gPos, bPos, aPos); + neon_write_pixel(&pRGB[1][4 * (1ULL + x)], pY[1][1ULL + x], U, V, rPos, gPos, bPos, aPos); + } + + return PRIMITIVES_SUCCESS; +} + +static INLINE pstatus_t neon_YUV420ToX(const BYTE* WINPR_RESTRICT pSrc[3], const UINT32 srcStep[3], + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi, const uint8_t rPos, + const uint8_t gPos, const uint8_t bPos, const uint8_t aPos) +{ + const UINT32 nWidth = roi->width; + const UINT32 nHeight = roi->height; + + WINPR_ASSERT((nHeight % 2) == 0); + for (UINT32 y = 0; y < nHeight; y += 2) + { + const uint8_t* pY[2] = { pSrc[0] + y * srcStep[0], pSrc[0] + (1ULL + y) * srcStep[0] }; + const uint8_t* pU = pSrc[1] + (y / 2) * srcStep[1]; + const uint8_t* pV = pSrc[2] + (y / 2) * srcStep[2]; + uint8_t* pRGB[2] = { pDst + y * dstStep, pDst + (1ULL + y) * dstStep }; + + const pstatus_t rc = + neon_YUV420ToX_DOUBLE_ROW(pY, pU, pV, pRGB, nWidth, rPos, gPos, bPos, aPos); + if (rc != PRIMITIVES_SUCCESS) + return rc; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_YUV420ToRGB_8u_P3AC4R(const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + case PIXEL_FORMAT_BGRX32: + return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 2, 1, 0, 3); + + case PIXEL_FORMAT_RGBA32: + case PIXEL_FORMAT_RGBX32: + return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 0, 1, 2, 3); + + case PIXEL_FORMAT_ARGB32: + case PIXEL_FORMAT_XRGB32: + return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 1, 2, 3, 0); + + case PIXEL_FORMAT_ABGR32: + case PIXEL_FORMAT_XBGR32: + return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 3, 2, 1, 0); + + default: + return generic->YUV420ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} + +static inline int16x8_t loadUVreg(uint8x8_t Vraw) +{ + const int16x8_t V = vreinterpretq_s16_u16(vmovl_u8(Vraw)); + const int16x8_t c128 = vdupq_n_s16(128); + const int16x8_t E = vsubq_s16(V, c128); + return E; +} + +static inline int16x8x2_t loadUV444(uint8x16_t Vld) +{ + const uint8x8x2_t V = { { vget_low_u8(Vld), vget_high_u8(Vld) } }; + const int16x8x2_t res = { { + loadUVreg(V.val[0]), + loadUVreg(V.val[1]), + } }; + return res; +} + +static inline void avgUV(BYTE U[2][2]) +{ + const BYTE u00 = U[0][0]; + const INT16 umul = (INT16)u00 << 2; + const INT16 sum = (INT16)U[0][1] + U[1][0] + U[1][1]; + const INT16 wavg = umul - sum; + const BYTE val = CONDITIONAL_CLIP(wavg, u00); + U[0][0] = val; +} + +static inline void neon_avgUV(uint8x16_t pU[2]) +{ + /* put even and odd values into different registers. + * U 0/0 is in lower half */ + const uint8x16x2_t usplit = vuzpq_u8(pU[0], pU[1]); + const uint8x16_t ueven = usplit.val[0]; + const uint8x16_t uodd = usplit.val[1]; + + const uint8x8_t u00 = vget_low_u8(ueven); + const uint8x8_t u01 = vget_low_u8(uodd); + const uint8x8_t u10 = vget_high_u8(ueven); + const uint8x8_t u11 = vget_high_u8(uodd); + + /* Create sum of U01 + U10 + U11 */ + const uint16x8_t uoddsum = vaddl_u8(u01, u10); + const uint16x8_t usum = vaddq_u16(uoddsum, vmovl_u8(u11)); + + /* U00 * 4 */ + const uint16x8_t umul = vshll_n_u8(u00, 2); + + /* U00 - (U01 + U10 + U11) */ + const int16x8_t wavg = vsubq_s16(vreinterpretq_s16_u16(umul), vreinterpretq_s16_u16(usum)); + const uint8x8_t avg = vqmovun_s16(wavg); + + /* abs(u00 - avg) */ + const uint8x8_t absdiff = vabd_u8(avg, u00); + + /* (diff < 30) ? u00 : avg */ + const uint8x8_t mask = vclt_u8(absdiff, vdup_n_u8(30)); + + /* out1 = u00 & mask */ + const uint8x8_t out1 = vand_u8(u00, mask); + + /* invmask = ~mask */ + const uint8x8_t notmask = vmvn_u8(mask); + + /* out2 = avg & invmask */ + const uint8x8_t out2 = vand_u8(avg, notmask); + + /* out = out1 | out2 */ + const uint8x8_t out = vorr_u8(out1, out2); + + const uint8x8x2_t ua = vzip_u8(out, u01); + const uint8x16_t u = vcombine_u8(ua.val[0], ua.val[1]); + pU[0] = u; +} + +static INLINE pstatus_t neon_YUV444ToX_SINGLE_ROW(const BYTE* WINPR_RESTRICT pY, + const BYTE* WINPR_RESTRICT pU, + const BYTE* WINPR_RESTRICT pV, + BYTE* WINPR_RESTRICT pRGB, size_t width, + const uint8_t rPos, const uint8_t gPos, + const uint8_t bPos, const uint8_t aPos) +{ + WINPR_ASSERT(width % 2 == 0); + + size_t x = 0; + + for (; x < width - width % 16; x += 16) + { + uint8x16_t U = vld1q_u8(&pU[x]); + uint8x16_t V = vld1q_u8(&pV[x]); + const uint8x16_t Y0raw = vld1q_u8(&pY[x]); + const uint8x8x2_t Y0 = { { vget_low_u8(Y0raw), vget_high_u8(Y0raw) } }; + const int16x8x2_t D0 = loadUV444(U); + const int16x8x2_t E0 = loadUV444(V); + neon_YuvToRgbPixel(&pRGB[4ULL * x], Y0, D0, E0, rPos, gPos, bPos, aPos); + } + + for (; x < width; x += 2) + { + BYTE* rgb = &pRGB[x * 4]; + + for (size_t j = 0; j < 2; j++) + { + const BYTE y = pY[x + j]; + const BYTE u = pU[x + j]; + const BYTE v = pV[x + j]; + + neon_write_pixel(&rgb[4 * (j)], y, u, v, rPos, gPos, bPos, aPos); + } + } + + return PRIMITIVES_SUCCESS; +} + +static INLINE pstatus_t neon_YUV444ToX_DOUBLE_ROW(const BYTE* WINPR_RESTRICT pY[2], + const BYTE* WINPR_RESTRICT pU[2], + const BYTE* WINPR_RESTRICT pV[2], + BYTE* WINPR_RESTRICT pRGB[2], size_t width, + const uint8_t rPos, const uint8_t gPos, + const uint8_t bPos, const uint8_t aPos) +{ + WINPR_ASSERT(width % 2 == 0); + + size_t x = 0; + + for (; x < width - width % 16; x += 16) + { + uint8x16_t U[2] = { vld1q_u8(&pU[0][x]), vld1q_u8(&pU[1][x]) }; + neon_avgUV(U); + + uint8x16_t V[2] = { vld1q_u8(&pV[0][x]), vld1q_u8(&pV[1][x]) }; + neon_avgUV(V); + + const uint8x16_t Y0raw = vld1q_u8(&pY[0][x]); + const uint8x8x2_t Y0 = { { vget_low_u8(Y0raw), vget_high_u8(Y0raw) } }; + const int16x8x2_t D0 = loadUV444(U[0]); + const int16x8x2_t E0 = loadUV444(V[0]); + neon_YuvToRgbPixel(&pRGB[0][4ULL * x], Y0, D0, E0, rPos, gPos, bPos, aPos); + + const uint8x16_t Y1raw = vld1q_u8(&pY[1][x]); + const uint8x8x2_t Y1 = { { vget_low_u8(Y1raw), vget_high_u8(Y1raw) } }; + const int16x8x2_t D1 = loadUV444(U[1]); + const int16x8x2_t E1 = loadUV444(V[1]); + neon_YuvToRgbPixel(&pRGB[1][4ULL * x], Y1, D1, E1, rPos, gPos, bPos, aPos); + } + + for (; x < width; x += 2) + { + BYTE* rgb[2] = { &pRGB[0][x * 4], &pRGB[1][x * 4] }; + BYTE U[2][2] = { { pU[0][x], pU[0][x + 1] }, { pU[1][x], pU[1][x + 1] } }; + avgUV(U); + + BYTE V[2][2] = { { pV[0][x], pV[0][x + 1] }, { pV[1][x], pV[1][x + 1] } }; + avgUV(V); + + for (size_t i = 0; i < 2; i++) + { + for (size_t j = 0; j < 2; j++) + { + const BYTE y = pY[i][x + j]; + const BYTE u = U[i][j]; + const BYTE v = V[i][j]; + + neon_write_pixel(&rgb[i][4 * (j)], y, u, v, rPos, gPos, bPos, aPos); + } + } + } + + return PRIMITIVES_SUCCESS; +} + +static INLINE pstatus_t neon_YUV444ToX(const BYTE* WINPR_RESTRICT pSrc[3], const UINT32 srcStep[3], + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi, const uint8_t rPos, + const uint8_t gPos, const uint8_t bPos, const uint8_t aPos) +{ + WINPR_ASSERT(roi); + const UINT32 nWidth = roi->width; + const UINT32 nHeight = roi->height; + + size_t y = 0; + for (; y < nHeight - nHeight % 2; y += 2) + { + const uint8_t* WINPR_RESTRICT pY[2] = { pSrc[0] + y * srcStep[0], + pSrc[0] + (y + 1) * srcStep[0] }; + const uint8_t* WINPR_RESTRICT pU[2] = { pSrc[1] + y * srcStep[1], + pSrc[1] + (y + 1) * srcStep[1] }; + const uint8_t* WINPR_RESTRICT pV[2] = { pSrc[2] + y * srcStep[2], + pSrc[2] + (y + 1) * srcStep[2] }; + + uint8_t* WINPR_RESTRICT pRGB[2] = { &pDst[y * dstStep], &pDst[(y + 1) * dstStep] }; + + const pstatus_t rc = + neon_YUV444ToX_DOUBLE_ROW(pY, pU, pV, pRGB, nWidth, rPos, gPos, bPos, aPos); + if (rc != PRIMITIVES_SUCCESS) + return rc; + } + for (; y < nHeight; y++) + { + const uint8_t* WINPR_RESTRICT pY = pSrc[0] + y * srcStep[0]; + const uint8_t* WINPR_RESTRICT pU = pSrc[1] + y * srcStep[1]; + const uint8_t* WINPR_RESTRICT pV = pSrc[2] + y * srcStep[2]; + uint8_t* WINPR_RESTRICT pRGB = &pDst[y * dstStep]; + + const pstatus_t rc = + neon_YUV444ToX_SINGLE_ROW(pY, pU, pV, pRGB, nWidth, rPos, gPos, bPos, aPos); + if (rc != PRIMITIVES_SUCCESS) + return rc; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_YUV444ToRGB_8u_P3AC4R(const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + case PIXEL_FORMAT_BGRX32: + return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 2, 1, 0, 3); + + case PIXEL_FORMAT_RGBA32: + case PIXEL_FORMAT_RGBX32: + return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 0, 1, 2, 3); + + case PIXEL_FORMAT_ARGB32: + case PIXEL_FORMAT_XRGB32: + return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 1, 2, 3, 0); + + case PIXEL_FORMAT_ABGR32: + case PIXEL_FORMAT_XBGR32: + return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 3, 2, 1, 0); + + default: + return generic->YUV444ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} + +static pstatus_t neon_LumaToYUV444(const BYTE* WINPR_RESTRICT pSrcRaw[3], const UINT32 srcStep[3], + BYTE* WINPR_RESTRICT pDstRaw[3], const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + const UINT32 nWidth = roi->right - roi->left; + const UINT32 nHeight = roi->bottom - roi->top; + const UINT32 halfWidth = (nWidth + 1) / 2; + const UINT32 halfHeight = (nHeight + 1) / 2; + const UINT32 evenY = 0; + const BYTE* pSrc[3] = { pSrcRaw[0] + roi->top * srcStep[0] + roi->left, + pSrcRaw[1] + roi->top / 2 * srcStep[1] + roi->left / 2, + pSrcRaw[2] + roi->top / 2 * srcStep[2] + roi->left / 2 }; + BYTE* pDst[3] = { pDstRaw[0] + roi->top * dstStep[0] + roi->left, + pDstRaw[1] + roi->top * dstStep[1] + roi->left, + pDstRaw[2] + roi->top * dstStep[2] + roi->left }; + + /* Y data is already here... */ + /* B1 */ + for (UINT32 y = 0; y < nHeight; y++) + { + const BYTE* Ym = pSrc[0] + srcStep[0] * y; + BYTE* pY = pDst[0] + dstStep[0] * y; + memcpy(pY, Ym, nWidth); + } + + /* The first half of U, V are already here part of this frame. */ + /* B2 and B3 */ + for (UINT32 y = 0; y < halfHeight; y++) + { + const UINT32 val2y = (2 * y + evenY); + const BYTE* Um = pSrc[1] + srcStep[1] * y; + const BYTE* Vm = pSrc[2] + srcStep[2] * y; + BYTE* pU = pDst[1] + dstStep[1] * val2y; + BYTE* pV = pDst[2] + dstStep[2] * val2y; + BYTE* pU1 = pU + dstStep[1]; + BYTE* pV1 = pV + dstStep[2]; + + UINT32 x = 0; + for (; x + 16 < halfWidth; x += 16) + { + { + const uint8x16_t u = vld1q_u8(Um); + uint8x16x2_t u2x; + u2x.val[0] = u; + u2x.val[1] = u; + vst2q_u8(pU, u2x); + vst2q_u8(pU1, u2x); + Um += 16; + pU += 32; + pU1 += 32; + } + { + const uint8x16_t v = vld1q_u8(Vm); + uint8x16x2_t v2x; + v2x.val[0] = v; + v2x.val[1] = v; + vst2q_u8(pV, v2x); + vst2q_u8(pV1, v2x); + Vm += 16; + pV += 32; + pV1 += 32; + } + } + + for (; x < halfWidth; x++) + { + const BYTE u = *Um++; + const BYTE v = *Vm++; + *pU++ = u; + *pU++ = u; + *pU1++ = u; + *pU1++ = u; + *pV++ = v; + *pV++ = v; + *pV1++ = v; + *pV1++ = v; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_ChromaV1ToYUV444(const BYTE* WINPR_RESTRICT pSrcRaw[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDstRaw[3], + const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + const UINT32 mod = 16; + UINT32 uY = 0; + UINT32 vY = 0; + const UINT32 nWidth = roi->right - roi->left; + const UINT32 nHeight = roi->bottom - roi->top; + const UINT32 halfWidth = (nWidth) / 2; + const UINT32 halfHeight = (nHeight) / 2; + const UINT32 oddY = 1; + const UINT32 evenY = 0; + const UINT32 oddX = 1; + /* The auxiliary frame is aligned to multiples of 16x16. + * We need the padded height for B4 and B5 conversion. */ + const UINT32 padHeigth = nHeight + 16 - nHeight % 16; + const UINT32 halfPad = halfWidth % 16; + const BYTE* pSrc[3] = { pSrcRaw[0] + roi->top * srcStep[0] + roi->left, + pSrcRaw[1] + roi->top / 2 * srcStep[1] + roi->left / 2, + pSrcRaw[2] + roi->top / 2 * srcStep[2] + roi->left / 2 }; + BYTE* pDst[3] = { pDstRaw[0] + roi->top * dstStep[0] + roi->left, + pDstRaw[1] + roi->top * dstStep[1] + roi->left, + pDstRaw[2] + roi->top * dstStep[2] + roi->left }; + + /* The second half of U and V is a bit more tricky... */ + /* B4 and B5 */ + for (UINT32 y = 0; y < padHeigth; y++) + { + const BYTE* Ya = pSrc[0] + srcStep[0] * y; + BYTE* pX; + + if ((y) % mod < (mod + 1) / 2) + { + const UINT32 pos = (2 * uY++ + oddY); + + if (pos >= nHeight) + continue; + + pX = pDst[1] + dstStep[1] * pos; + } + else + { + const UINT32 pos = (2 * vY++ + oddY); + + if (pos >= nHeight) + continue; + + pX = pDst[2] + dstStep[2] * pos; + } + + memcpy(pX, Ya, nWidth); + } + + /* B6 and B7 */ + for (UINT32 y = 0; y < halfHeight; y++) + { + const UINT32 val2y = (y * 2 + evenY); + const BYTE* Ua = pSrc[1] + srcStep[1] * y; + const BYTE* Va = pSrc[2] + srcStep[2] * y; + BYTE* pU = pDst[1] + dstStep[1] * val2y; + BYTE* pV = pDst[2] + dstStep[2] * val2y; + + UINT32 x = 0; + for (; x < halfWidth - halfPad; x += 16) + { + { + uint8x16x2_t u = vld2q_u8(&pU[2 * x]); + u.val[1] = vld1q_u8(&Ua[x]); + vst2q_u8(&pU[2 * x], u); + } + { + uint8x16x2_t v = vld2q_u8(&pV[2 * x]); + v.val[1] = vld1q_u8(&Va[x]); + vst2q_u8(&pV[2 * x], v); + } + } + + for (; x < halfWidth; x++) + { + const UINT32 val2x1 = (x * 2 + oddX); + pU[val2x1] = Ua[x]; + pV[val2x1] = Va[x]; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_ChromaV2ToYUV444(const BYTE* WINPR_RESTRICT pSrc[3], const UINT32 srcStep[3], + UINT32 nTotalWidth, UINT32 nTotalHeight, + BYTE* WINPR_RESTRICT pDst[3], const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + const UINT32 nWidth = roi->right - roi->left; + const UINT32 nHeight = roi->bottom - roi->top; + const UINT32 halfWidth = (nWidth + 1) / 2; + const UINT32 halfPad = halfWidth % 16; + const UINT32 halfHeight = (nHeight + 1) / 2; + const UINT32 quaterWidth = (nWidth + 3) / 4; + const UINT32 quaterPad = quaterWidth % 16; + + /* B4 and B5: odd UV values for width/2, height */ + for (UINT32 y = 0; y < nHeight; y++) + { + const UINT32 yTop = y + roi->top; + const BYTE* pYaU = pSrc[0] + srcStep[0] * yTop + roi->left / 2; + const BYTE* pYaV = pYaU + nTotalWidth / 2; + BYTE* pU = pDst[1] + dstStep[1] * yTop + roi->left; + BYTE* pV = pDst[2] + dstStep[2] * yTop + roi->left; + + UINT32 x = 0; + for (; x < halfWidth - halfPad; x += 16) + { + { + uint8x16x2_t u = vld2q_u8(&pU[2 * x]); + u.val[1] = vld1q_u8(&pYaU[x]); + vst2q_u8(&pU[2 * x], u); + } + { + uint8x16x2_t v = vld2q_u8(&pV[2 * x]); + v.val[1] = vld1q_u8(&pYaV[x]); + vst2q_u8(&pV[2 * x], v); + } + } + + for (; x < halfWidth; x++) + { + const UINT32 odd = 2 * x + 1; + pU[odd] = pYaU[x]; + pV[odd] = pYaV[x]; + } + } + + /* B6 - B9 */ + for (UINT32 y = 0; y < halfHeight; y++) + { + const BYTE* pUaU = pSrc[1] + srcStep[1] * (y + roi->top / 2) + roi->left / 4; + const BYTE* pUaV = pUaU + nTotalWidth / 4; + const BYTE* pVaU = pSrc[2] + srcStep[2] * (y + roi->top / 2) + roi->left / 4; + const BYTE* pVaV = pVaU + nTotalWidth / 4; + BYTE* pU = pDst[1] + dstStep[1] * (2 * y + 1 + roi->top) + roi->left; + BYTE* pV = pDst[2] + dstStep[2] * (2 * y + 1 + roi->top) + roi->left; + + UINT32 x = 0; + for (; x < quaterWidth - quaterPad; x += 16) + { + { + uint8x16x4_t u = vld4q_u8(&pU[4 * x]); + u.val[0] = vld1q_u8(&pUaU[x]); + u.val[2] = vld1q_u8(&pVaU[x]); + vst4q_u8(&pU[4 * x], u); + } + { + uint8x16x4_t v = vld4q_u8(&pV[4 * x]); + v.val[0] = vld1q_u8(&pUaV[x]); + v.val[2] = vld1q_u8(&pVaV[x]); + vst4q_u8(&pV[4 * x], v); + } + } + + for (; x < quaterWidth; x++) + { + pU[4 * x + 0] = pUaU[x]; + pV[4 * x + 0] = pUaV[x]; + pU[4 * x + 2] = pVaU[x]; + pV[4 * x + 2] = pVaV[x]; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_YUV420CombineToYUV444(avc444_frame_type type, + const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], UINT32 nWidth, UINT32 nHeight, + BYTE* WINPR_RESTRICT pDst[3], const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + if (!pSrc || !pSrc[0] || !pSrc[1] || !pSrc[2]) + return -1; + + if (!pDst || !pDst[0] || !pDst[1] || !pDst[2]) + return -1; + + if (!roi) + return -1; + + switch (type) + { + case AVC444_LUMA: + return neon_LumaToYUV444(pSrc, srcStep, pDst, dstStep, roi); + + case AVC444_CHROMAv1: + return neon_ChromaV1ToYUV444(pSrc, srcStep, pDst, dstStep, roi); + + case AVC444_CHROMAv2: + return neon_ChromaV2ToYUV444(pSrc, srcStep, nWidth, nHeight, pDst, dstStep, roi); + + default: + return -1; + } +} +#endif + +void primitives_init_YUV_neon(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(NEON_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_YUV(prims); + + if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "NEON optimizations"); + prims->YUV420ToRGB_8u_P3AC4R = neon_YUV420ToRGB_8u_P3AC4R; + prims->YUV444ToRGB_8u_P3AC4R = neon_YUV444ToRGB_8u_P3AC4R; + prims->YUV420CombineToYUV444 = neon_YUV420CombineToYUV444; + } +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or neon intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_colors_neon.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_colors_neon.c new file mode 100644 index 0000000000000000000000000000000000000000..f63b9fd247e95ef66c7ddcf0bcdeb846c585b145 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/neon/prim_colors_neon.c @@ -0,0 +1,364 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized Color conversion operations. + * vi:ts=4 sw=4: + * + * Copyright 2011 Stephen Erisman + * Copyright 2011 Norbert Federa + * Copyright 2011 Martin Fleisz + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include +#include + +#include "prim_internal.h" +#include "prim_templates.h" +#include "prim_colors.h" + +/*---------------------------------------------------------------------------*/ +#if defined(NEON_INTRINSICS_ENABLED) +#include + +static primitives_t* generic = NULL; + +static pstatus_t +neon_yCbCrToRGB_16s16s_P3P3(const INT16* WINPR_RESTRICT pSrc[3], INT32 srcStep, + INT16* WINPR_RESTRICT pDst[3], INT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + /* TODO: If necessary, check alignments and call the general version. */ + int16x8_t zero = vdupq_n_s16(0); + int16x8_t max = vdupq_n_s16(255); + int16x8_t r_cr = vdupq_n_s16(22986); // 1.403 << 14 + int16x8_t g_cb = vdupq_n_s16(-5636); // -0.344 << 14 + int16x8_t g_cr = vdupq_n_s16(-11698); // -0.714 << 14 + int16x8_t b_cb = vdupq_n_s16(28999); // 1.770 << 14 + int16x8_t c4096 = vdupq_n_s16(4096); + const int16x8_t* y_buf = (const int16x8_t*)pSrc[0]; + const int16x8_t* cb_buf = (const int16x8_t*)pSrc[1]; + const int16x8_t* cr_buf = (const int16x8_t*)pSrc[2]; + int16x8_t* r_buf = (int16x8_t*)pDst[0]; + int16x8_t* g_buf = (int16x8_t*)pDst[1]; + int16x8_t* b_buf = (int16x8_t*)pDst[2]; + int srcbump = srcStep / sizeof(int16x8_t); + int dstbump = dstStep / sizeof(int16x8_t); + int imax = roi->width * sizeof(INT16) / sizeof(int16x8_t); + + for (int yp = 0; yp < roi->height; ++yp) + { + for (int i = 0; i < imax; i++) + { + /* + In order to use NEON signed 16-bit integer multiplication we need to convert + the floating point factors to signed int without losing information. + The result of this multiplication is 32 bit and we have a NEON instruction + that returns the hi word of the saturated double. + Thus we will multiply the factors by the highest possible 2^n, take the + upper 16 bits of the signed 32-bit result (vqdmulhq_s16 followed by a right + shift by 1 to reverse the doubling) and correct this result by multiplying it + by 2^(16-n). + For the given factors in the conversion matrix the best possible n is 14. + + Example for calculating r: + r = (y>>5) + 128 + (cr*1.403)>>5 // our base formula + r = (y>>5) + 128 + (HIWORD(cr*(1.403<<14)<<2))>>5 // see above + r = (y+4096)>>5 + (HIWORD(cr*22986)<<2)>>5 // simplification + r = ((y+4096)>>2 + HIWORD(cr*22986)) >> 3 + */ + /* y = (y_buf[i] + 4096) >> 2 */ + int16x8_t y = vld1q_s16((INT16*)&y_buf[i]); + y = vaddq_s16(y, c4096); + y = vshrq_n_s16(y, 2); + /* cb = cb_buf[i]; */ + int16x8_t cb = vld1q_s16((INT16*)&cb_buf[i]); + /* cr = cr_buf[i]; */ + int16x8_t cr = vld1q_s16((INT16*)&cr_buf[i]); + /* (y + HIWORD(cr*22986)) >> 3 */ + int16x8_t r = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cr, r_cr), 1)); + r = vshrq_n_s16(r, 3); + /* r_buf[i] = CLIP(r); */ + r = vminq_s16(vmaxq_s16(r, zero), max); + vst1q_s16((INT16*)&r_buf[i], r); + /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ + int16x8_t g = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cb, g_cb), 1)); + g = vaddq_s16(g, vshrq_n_s16(vqdmulhq_s16(cr, g_cr), 1)); + g = vshrq_n_s16(g, 3); + /* g_buf[i] = CLIP(g); */ + g = vminq_s16(vmaxq_s16(g, zero), max); + vst1q_s16((INT16*)&g_buf[i], g); + /* (y + HIWORD(cb*28999)) >> 3 */ + int16x8_t b = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cb, b_cb), 1)); + b = vshrq_n_s16(b, 3); + /* b_buf[i] = CLIP(b); */ + b = vminq_s16(vmaxq_s16(b, zero), max); + vst1q_s16((INT16*)&b_buf[i], b); + } + + y_buf += srcbump; + cb_buf += srcbump; + cr_buf += srcbump; + r_buf += dstbump; + g_buf += dstbump; + b_buf += dstbump; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_yCbCrToRGB_16s8u_P3AC4R_X(const INT16* WINPR_RESTRICT pSrc[3], UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi, uint8_t rPos, + uint8_t gPos, uint8_t bPos, uint8_t aPos) +{ + BYTE* pRGB = pDst; + const INT16* pY = pSrc[0]; + const INT16* pCb = pSrc[1]; + const INT16* pCr = pSrc[2]; + const size_t srcPad = (srcStep - (roi->width * sizeof(INT16))) / sizeof(INT16); + const size_t dstPad = (dstStep - (roi->width * 4)) / 4; + const size_t pad = roi->width % 8; + const int16x4_t c4096 = vdup_n_s16(4096); + + for (UINT32 y = 0; y < roi->height; y++) + { + for (UINT32 x = 0; x < roi->width - pad; x += 8) + { + const int16x8_t Y = vld1q_s16(pY); + const int16x4_t Yh = vget_high_s16(Y); + const int16x4_t Yl = vget_low_s16(Y); + const int32x4_t YhAdd = vaddl_s16(Yh, c4096); /* Y + 4096 */ + const int32x4_t YlAdd = vaddl_s16(Yl, c4096); /* Y + 4096 */ + const int32x4_t YhW = vshlq_n_s32(YhAdd, 16); + const int32x4_t YlW = vshlq_n_s32(YlAdd, 16); + const int16x8_t Cr = vld1q_s16(pCr); + const int16x4_t Crh = vget_high_s16(Cr); + const int16x4_t Crl = vget_low_s16(Cr); + const int16x8_t Cb = vld1q_s16(pCb); + const int16x4_t Cbh = vget_high_s16(Cb); + const int16x4_t Cbl = vget_low_s16(Cb); + uint8x8x4_t bgrx; + { + /* R */ + const int32x4_t CrhR = vmulq_n_s32(vmovl_s16(Crh), 91916); /* 1.402525 * 2^16 */ + const int32x4_t CrlR = vmulq_n_s32(vmovl_s16(Crl), 91916); /* 1.402525 * 2^16 */ + const int32x4_t CrhRa = vaddq_s32(CrhR, YhW); + const int32x4_t CrlRa = vaddq_s32(CrlR, YlW); + const int16x4_t Rsh = vmovn_s32(vshrq_n_s32(CrhRa, 21)); + const int16x4_t Rsl = vmovn_s32(vshrq_n_s32(CrlRa, 21)); + const int16x8_t Rs = vcombine_s16(Rsl, Rsh); + bgrx.val[rPos] = vqmovun_s16(Rs); + } + { + /* G */ + const int32x4_t CbGh = vmull_n_s16(Cbh, 22527); /* 0.343730 * 2^16 */ + const int32x4_t CbGl = vmull_n_s16(Cbl, 22527); /* 0.343730 * 2^16 */ + const int32x4_t CrGh = vmulq_n_s32(vmovl_s16(Crh), 46819); /* 0.714401 * 2^16 */ + const int32x4_t CrGl = vmulq_n_s32(vmovl_s16(Crl), 46819); /* 0.714401 * 2^16 */ + const int32x4_t CbCrGh = vaddq_s32(CbGh, CrGh); + const int32x4_t CbCrGl = vaddq_s32(CbGl, CrGl); + const int32x4_t YCbCrGh = vsubq_s32(YhW, CbCrGh); + const int32x4_t YCbCrGl = vsubq_s32(YlW, CbCrGl); + const int16x4_t Gsh = vmovn_s32(vshrq_n_s32(YCbCrGh, 21)); + const int16x4_t Gsl = vmovn_s32(vshrq_n_s32(YCbCrGl, 21)); + const int16x8_t Gs = vcombine_s16(Gsl, Gsh); + const uint8x8_t G = vqmovun_s16(Gs); + bgrx.val[gPos] = G; + } + { + /* B */ + const int32x4_t CbBh = vmulq_n_s32(vmovl_s16(Cbh), 115992); /* 1.769905 * 2^16 */ + const int32x4_t CbBl = vmulq_n_s32(vmovl_s16(Cbl), 115992); /* 1.769905 * 2^16 */ + const int32x4_t YCbBh = vaddq_s32(CbBh, YhW); + const int32x4_t YCbBl = vaddq_s32(CbBl, YlW); + const int16x4_t Bsh = vmovn_s32(vshrq_n_s32(YCbBh, 21)); + const int16x4_t Bsl = vmovn_s32(vshrq_n_s32(YCbBl, 21)); + const int16x8_t Bs = vcombine_s16(Bsl, Bsh); + const uint8x8_t B = vqmovun_s16(Bs); + bgrx.val[bPos] = B; + } + /* A */ + { + bgrx.val[aPos] = vdup_n_u8(0xFF); + } + vst4_u8(pRGB, bgrx); + pY += 8; + pCb += 8; + pCr += 8; + pRGB += 32; + } + + for (UINT32 x = 0; x < pad; x++) + { + const INT32 divisor = 16; + const INT32 Y = ((*pY++) + 4096) << divisor; + const INT32 Cb = (*pCb++); + const INT32 Cr = (*pCr++); + const INT32 CrR = Cr * (INT32)(1.402525f * (1 << divisor)); + const INT32 CrG = Cr * (INT32)(0.714401f * (1 << divisor)); + const INT32 CbG = Cb * (INT32)(0.343730f * (1 << divisor)); + const INT32 CbB = Cb * (INT32)(1.769905f * (1 << divisor)); + INT16 R = ((INT16)((CrR + Y) >> divisor) >> 5); + INT16 G = ((INT16)((Y - CbG - CrG) >> divisor) >> 5); + INT16 B = ((INT16)((CbB + Y) >> divisor) >> 5); + BYTE bgrx[4]; + bgrx[bPos] = CLIP(B); + bgrx[gPos] = CLIP(G); + bgrx[rPos] = CLIP(R); + bgrx[aPos] = 0xFF; + *pRGB++ = bgrx[0]; + *pRGB++ = bgrx[1]; + *pRGB++ = bgrx[2]; + *pRGB++ = bgrx[3]; + } + + pY += srcPad; + pCb += srcPad; + pCr += srcPad; + pRGB += dstPad; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t neon_yCbCrToRGB_16s8u_P3AC4R(const INT16* WINPR_RESTRICT pSrc[3], UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + case PIXEL_FORMAT_BGRX32: + return neon_yCbCrToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 2, 1, 0, 3); + + case PIXEL_FORMAT_RGBA32: + case PIXEL_FORMAT_RGBX32: + return neon_yCbCrToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 0, 1, 2, 3); + + case PIXEL_FORMAT_ARGB32: + case PIXEL_FORMAT_XRGB32: + return neon_yCbCrToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 1, 2, 3, 0); + + case PIXEL_FORMAT_ABGR32: + case PIXEL_FORMAT_XBGR32: + return neon_yCbCrToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 3, 2, 1, 0); + + default: + return generic->yCbCrToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} + +static pstatus_t +neon_RGBToRGB_16s8u_P3AC4R_X(const INT16* WINPR_RESTRICT pSrc[3], /* 16-bit R,G, and B arrays */ + UINT32 srcStep, /* bytes between rows in source data */ + BYTE* WINPR_RESTRICT pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + UINT32 dstStep, /* bytes between rows in dest data */ + const prim_size_t* WINPR_RESTRICT roi, /* region of interest */ + uint8_t rPos, uint8_t gPos, uint8_t bPos, uint8_t aPos) +{ + UINT32 pad = roi->width % 8; + + for (UINT32 y = 0; y < roi->height; y++) + { + const INT16* pr = (const INT16*)(((BYTE*)pSrc[0]) + y * srcStep); + const INT16* pg = (const INT16*)(((BYTE*)pSrc[1]) + y * srcStep); + const INT16* pb = (const INT16*)(((BYTE*)pSrc[2]) + y * srcStep); + BYTE* dst = pDst + y * dstStep; + + for (UINT32 x = 0; x < roi->width - pad; x += 8) + { + int16x8_t r = vld1q_s16(pr); + int16x8_t g = vld1q_s16(pg); + int16x8_t b = vld1q_s16(pb); + uint8x8x4_t bgrx; + bgrx.val[aPos] = vdup_n_u8(0xFF); + bgrx.val[rPos] = vqmovun_s16(r); + bgrx.val[gPos] = vqmovun_s16(g); + bgrx.val[bPos] = vqmovun_s16(b); + vst4_u8(dst, bgrx); + pr += 8; + pg += 8; + pb += 8; + dst += 32; + } + + for (UINT32 x = 0; x < pad; x++) + { + BYTE bgrx[4]; + bgrx[bPos] = *pb++; + bgrx[gPos] = *pg++; + bgrx[rPos] = *pr++; + bgrx[aPos] = 0xFF; + *dst++ = bgrx[0]; + *dst++ = bgrx[1]; + *dst++ = bgrx[2]; + *dst++ = bgrx[3]; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t +neon_RGBToRGB_16s8u_P3AC4R(const INT16* WINPR_RESTRICT pSrc[3], /* 16-bit R,G, and B arrays */ + UINT32 srcStep, /* bytes between rows in source data */ + BYTE* WINPR_RESTRICT pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + UINT32 dstStep, /* bytes between rows in dest data */ + UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + case PIXEL_FORMAT_BGRX32: + return neon_RGBToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 2, 1, 0, 3); + + case PIXEL_FORMAT_RGBA32: + case PIXEL_FORMAT_RGBX32: + return neon_RGBToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 0, 1, 2, 3); + + case PIXEL_FORMAT_ARGB32: + case PIXEL_FORMAT_XRGB32: + return neon_RGBToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 1, 2, 3, 0); + + case PIXEL_FORMAT_ABGR32: + case PIXEL_FORMAT_XBGR32: + return neon_RGBToRGB_16s8u_P3AC4R_X(pSrc, srcStep, pDst, dstStep, roi, 3, 2, 1, 0); + + default: + return generic->RGBToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} +#endif /* NEON_INTRINSICS_ENABLED */ + +/* ------------------------------------------------------------------------- */ +void primitives_init_colors_neon(primitives_t* prims) +{ +#if defined(NEON_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_colors(prims); + + if (IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "NEON optimizations"); + prims->RGBToRGB_16s8u_P3AC4R = neon_RGBToRGB_16s8u_P3AC4R; + prims->yCbCrToRGB_16s8u_P3AC4R = neon_yCbCrToRGB_16s8u_P3AC4R; + prims->yCbCrToRGB_16s16s_P3P3 = neon_yCbCrToRGB_16s16s_P3P3; + } +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or neon intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/prim_YUV_opencl.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/prim_YUV_opencl.c new file mode 100644 index 0000000000000000000000000000000000000000..fb03e6fa39200baad65485c777efc886c95463d3 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/prim_YUV_opencl.c @@ -0,0 +1,501 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Optimized YUV/RGB conversion operations using openCL + * + * Copyright 2019 David Fort + * Copyright 2019 Rangee Gmbh + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include "prim_internal.h" + +#if defined(WITH_OPENCL) +#ifdef __APPLE__ +#include "OpenCL/opencl.h" +#else +#include +#endif +#include "primitives-opencl-program.h" + +#include +#define TAG FREERDP_TAG("primitives") + +typedef struct +{ + BOOL support; + cl_platform_id platformId; + cl_device_id deviceId; + cl_context context; + cl_command_queue commandQueue; + cl_program program; +} primitives_opencl_context; + +typedef struct +{ + primitives_opencl_context* cl; + cl_kernel kernel; + cl_mem srcObjs[3]; + cl_mem dstObj; + prim_size_t roi; + size_t dstStep; +} primitives_cl_kernel; + +static primitives_opencl_context* primitives_get_opencl_context(void); + +static void cl_kernel_free(primitives_cl_kernel* kernel) +{ + if (!kernel) + return; + + if (kernel->dstObj) + clReleaseMemObject(kernel->dstObj); + + for (size_t i = 0; i < ARRAYSIZE(kernel->srcObjs); i++) + { + cl_mem obj = kernel->srcObjs[i]; + kernel->srcObjs[i] = NULL; + if (obj) + clReleaseMemObject(obj); + } + + if (kernel->kernel) + clReleaseKernel(kernel->kernel); + + free(kernel); +} + +static primitives_cl_kernel* cl_kernel_new(const char* kernelName, const prim_size_t* roi) +{ + WINPR_ASSERT(kernelName); + WINPR_ASSERT(roi); + + primitives_cl_kernel* kernel = calloc(1, sizeof(primitives_cl_kernel)); + if (!kernel) + goto fail; + + kernel->roi = *roi; + kernel->cl = primitives_get_opencl_context(); + if (!kernel->cl) + goto fail; + + cl_int ret = CL_INVALID_VALUE; + kernel->kernel = clCreateKernel(kernel->cl->program, kernelName, &ret); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "openCL: unable to create kernel %s", kernelName); + goto fail; + } + + return kernel; +fail: + cl_kernel_free(kernel); + return NULL; +} + +static BOOL cl_kernel_set_sources(primitives_cl_kernel* ctx, const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3]) +{ + const char* sourceNames[] = { "Y", "U", "V" }; + + WINPR_ASSERT(ctx); + WINPR_ASSERT(pSrc); + WINPR_ASSERT(srcStep); + + for (cl_uint i = 0; i < ARRAYSIZE(ctx->srcObjs); i++) + { + cl_int ret = CL_INVALID_VALUE; + const BYTE* csrc = pSrc[i]; + void* WINPR_RESTRICT src = WINPR_CAST_CONST_PTR_AWAY(csrc, void* WINPR_RESTRICT); + ctx->srcObjs[i] = clCreateBuffer(ctx->cl->context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, + 1ull * srcStep[i] * ctx->roi.height, src, &ret); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to create %sobj", sourceNames[i]); + return FALSE; + } + + ret = clSetKernelArg(ctx->kernel, i * 2, sizeof(cl_mem), (const void*)&ctx->srcObjs[i]); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to set arg for %sobj", sourceNames[i]); + return FALSE; + } + + ret = clSetKernelArg(ctx->kernel, i * 2 + 1, sizeof(cl_uint), &srcStep[i]); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to set arg stride for %sobj", sourceNames[i]); + return FALSE; + } + } + + return TRUE; +} + +static BOOL cl_kernel_set_destination(primitives_cl_kernel* ctx, UINT32 dstStep) +{ + + WINPR_ASSERT(ctx); + + ctx->dstStep = dstStep; + cl_int ret = CL_INVALID_VALUE; + ctx->dstObj = clCreateBuffer(ctx->cl->context, CL_MEM_WRITE_ONLY, + 1ull * dstStep * ctx->roi.height, NULL, &ret); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to create dest obj"); + return FALSE; + } + + ret = clSetKernelArg(ctx->kernel, 6, sizeof(cl_mem), (const void*)&ctx->dstObj); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to set arg destObj"); + return FALSE; + } + + ret = clSetKernelArg(ctx->kernel, 7, sizeof(cl_uint), &dstStep); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to set arg dstStep"); + return FALSE; + } + + return TRUE; +} + +static BOOL cl_kernel_process(primitives_cl_kernel* ctx, BYTE* pDst) +{ + WINPR_ASSERT(ctx); + WINPR_ASSERT(pDst); + + size_t indexes[2] = { 0 }; + indexes[0] = ctx->roi.width; + indexes[1] = ctx->roi.height; + + cl_int ret = clEnqueueNDRangeKernel(ctx->cl->commandQueue, ctx->kernel, 2, NULL, indexes, NULL, + 0, NULL, NULL); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to enqueue call kernel"); + return FALSE; + } + + /* Transfer result to host */ + ret = clEnqueueReadBuffer(ctx->cl->commandQueue, ctx->dstObj, CL_TRUE, 0, + ctx->roi.height * ctx->dstStep, pDst, 0, NULL, NULL); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "unable to read back buffer"); + return FALSE; + } + + return TRUE; +} + +static pstatus_t opencl_YUVToRGB(const char* kernelName, const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi) +{ + pstatus_t res = -1; + + primitives_cl_kernel* ctx = cl_kernel_new(kernelName, roi); + if (!ctx) + goto fail; + + if (!cl_kernel_set_sources(ctx, pSrc, srcStep)) + goto fail; + + if (!cl_kernel_set_destination(ctx, dstStep)) + goto fail; + + if (!cl_kernel_process(ctx, pDst)) + goto fail; + + res = PRIMITIVES_SUCCESS; + +fail: + cl_kernel_free(ctx); + return res; +} + +static primitives_opencl_context openclContext = { 0 }; + +static primitives_opencl_context* primitives_get_opencl_context(void) +{ + return &openclContext; +} + +static void cl_context_free(primitives_opencl_context* ctx) +{ + if (!ctx) + return; + clReleaseProgram(ctx->program); + clReleaseCommandQueue(ctx->commandQueue); + clReleaseContext(ctx->context); + clReleaseDevice(ctx->deviceId); + ctx->support = FALSE; +} + +static pstatus_t primitives_uninit_opencl(void) +{ + if (!openclContext.support) + return PRIMITIVES_SUCCESS; + + cl_context_free(&openclContext); + return PRIMITIVES_SUCCESS; +} + +static BOOL primitives_init_opencl_context(primitives_opencl_context* WINPR_RESTRICT prims) +{ + cl_uint ndevices = 0; + cl_uint nplatforms = 0; + cl_kernel kernel = NULL; + + BOOL gotGPU = FALSE; + size_t programLen = 0; + + cl_int ret = clGetPlatformIDs(0, NULL, &nplatforms); + if (ret != CL_SUCCESS || nplatforms < 1) + return FALSE; + + cl_platform_id* platform_ids = (cl_platform_id*)calloc(nplatforms, sizeof(cl_platform_id)); + if (!platform_ids) + return FALSE; + + ret = clGetPlatformIDs(nplatforms, platform_ids, &nplatforms); + if (ret != CL_SUCCESS) + { + free((void*)platform_ids); + return FALSE; + } + + for (cl_uint i = 0; (i < nplatforms) && !gotGPU; i++) + { + cl_device_id device_id = NULL; + cl_context context = NULL; + char platformName[1000] = { 0 }; + char deviceName[1000] = { 0 }; + + ret = clGetPlatformInfo(platform_ids[i], CL_PLATFORM_NAME, sizeof(platformName), + platformName, NULL); + if (ret != CL_SUCCESS) + continue; + + ret = clGetDeviceIDs(platform_ids[i], CL_DEVICE_TYPE_GPU, 1, &device_id, &ndevices); + if (ret != CL_SUCCESS) + continue; + + ret = clGetDeviceInfo(device_id, CL_DEVICE_NAME, sizeof(deviceName), deviceName, NULL); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "openCL: unable get device name for platform %s", platformName); + clReleaseDevice(device_id); + continue; + } + + context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &ret); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "openCL: unable to create context for platform %s, device %s", + platformName, deviceName); + clReleaseDevice(device_id); + continue; + } + +#if defined(CL_VERSION_2_0) + prims->commandQueue = clCreateCommandQueueWithProperties(context, device_id, NULL, &ret); +#else + prims->commandQueue = clCreateCommandQueue(context, device_id, 0, &ret); +#endif + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "openCL: unable to create command queue"); + clReleaseContext(context); + clReleaseDevice(device_id); + continue; + } + + WLog_INFO(TAG, "openCL: using platform=%s device=%s", platformName, deviceName); + + prims->platformId = platform_ids[i]; + prims->deviceId = device_id; + prims->context = context; + gotGPU = TRUE; + } + + free((void*)platform_ids); + + if (!gotGPU) + { + WLog_ERR(TAG, "openCL: no GPU found"); + return FALSE; + } + + programLen = strnlen(openclProgram, sizeof(openclProgram)); + const char* ptr = openclProgram; + prims->program = clCreateProgramWithSource(prims->context, 1, &ptr, &programLen, &ret); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "openCL: unable to create program"); + goto fail; + } + + ret = clBuildProgram(prims->program, 1, &prims->deviceId, NULL, NULL, NULL); + if (ret != CL_SUCCESS) + { + size_t length = 0; + char buffer[2048]; + ret = clGetProgramBuildInfo(prims->program, prims->deviceId, CL_PROGRAM_BUILD_LOG, + sizeof(buffer), buffer, &length); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, + "openCL: building program failed but unable to retrieve buildLog, error=%d", + ret); + } + else + { + WLog_ERR(TAG, "openCL: unable to build program, errorLog=%s", buffer); + } + goto fail; + } + + kernel = clCreateKernel(prims->program, "yuv420_to_bgra_1b", &ret); + if (ret != CL_SUCCESS) + { + WLog_ERR(TAG, "openCL: unable to create yuv420_to_bgra_1b kernel"); + goto fail; + } + clReleaseKernel(kernel); + + prims->support = TRUE; + return TRUE; + +fail: + cl_context_free(prims); + return FALSE; +} + +static pstatus_t opencl_YUV420ToRGB_8u_P3AC4R(const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) +{ + const char* kernel_name = NULL; + + switch (DstFormat) + { + case PIXEL_FORMAT_ABGR32: + kernel_name = "yuv420_to_abgr_1b"; + break; + case PIXEL_FORMAT_XBGR32: + kernel_name = "yuv420_to_xbgr_1b"; + break; + case PIXEL_FORMAT_RGBX32: + kernel_name = "yuv420_to_rgba_1b"; + break; + case PIXEL_FORMAT_RGBA32: + kernel_name = "yuv420_to_rgbx_1b"; + break; + case PIXEL_FORMAT_BGRA32: + kernel_name = "yuv420_to_bgra_1b"; + break; + case PIXEL_FORMAT_BGRX32: + kernel_name = "yuv420_to_bgrx_1b"; + break; + case PIXEL_FORMAT_XRGB32: + kernel_name = "yuv420_to_xrgb_1b"; + break; + case PIXEL_FORMAT_ARGB32: + kernel_name = "yuv420_to_argb_1b"; + break; + default: + { + primitives_t* p = primitives_get_by_type(PRIMITIVES_ONLY_CPU); + if (!p) + return -1; + return p->YUV420ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } + } + + return opencl_YUVToRGB(kernel_name, pSrc, srcStep, pDst, dstStep, roi); +} + +static pstatus_t opencl_YUV444ToRGB_8u_P3AC4R(const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) +{ + const char* kernel_name = NULL; + + switch (DstFormat) + { + case PIXEL_FORMAT_ABGR32: + kernel_name = "yuv444_to_abgr_1b"; + break; + case PIXEL_FORMAT_XBGR32: + kernel_name = "yuv444_to_xbgr_1b"; + break; + case PIXEL_FORMAT_RGBX32: + kernel_name = "yuv444_to_rgba_1b"; + break; + case PIXEL_FORMAT_RGBA32: + kernel_name = "yuv444_to_rgbx_1b"; + break; + case PIXEL_FORMAT_BGRA32: + kernel_name = "yuv444_to_bgra_1b"; + break; + case PIXEL_FORMAT_BGRX32: + kernel_name = "yuv444_to_bgrx_1b"; + break; + case PIXEL_FORMAT_XRGB32: + kernel_name = "yuv444_to_xrgb_1b"; + break; + case PIXEL_FORMAT_ARGB32: + kernel_name = "yuv444_to_argb_1b"; + break; + default: + { + primitives_t* p = primitives_get_by_type(PRIMITIVES_ONLY_CPU); + if (!p) + return -1; + return p->YUV444ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } + } + + return opencl_YUVToRGB(kernel_name, pSrc, srcStep, pDst, dstStep, roi); +} + +BOOL primitives_init_opencl(primitives_t* prims) +{ + primitives_t* p = primitives_get_by_type(PRIMITIVES_ONLY_CPU); + if (!prims || !p) + return FALSE; + *prims = *p; + + if (!primitives_init_opencl_context(&openclContext)) + return FALSE; + + prims->YUV420ToRGB_8u_P3AC4R = opencl_YUV420ToRGB_8u_P3AC4R; + prims->YUV444ToRGB_8u_P3AC4R = opencl_YUV444ToRGB_8u_P3AC4R; + prims->flags |= PRIM_FLAGS_HAVE_EXTGPU; + prims->uninit = primitives_uninit_opencl; + return TRUE; +} +#endif diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/primitives.cl b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/primitives.cl new file mode 100644 index 0000000000000000000000000000000000000000..a5e1cf27ac8d8d1215083fd6c3bceab3b2db657d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/primitives.cl @@ -0,0 +1,474 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Optimized operations using openCL + * vi:ts=4 sw=4 + * + * Copyright 2019 David Fort + * Copyright 2019 Rangee Gmbh + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +uchar clamp_uc(int v, short l, short h) +{ + if (v > h) + v = h; + if (v < l) + v = l; + return (uchar)v; +} + +short avgUV(__global const uchar* buf, unsigned stride, unsigned x, unsigned y) +{ + const short U00 = buf[y * stride]; + if ((x != 0) || (y != 0)) + return U00; + const short U01 = buf[y * stride + 1]; + const short U10 = buf[(y + 1) * stride]; + const short U11 = buf[(y + 1) * stride + 1]; + const short avg = U00 * 4 - U01 - U10 - U11; + const short avgU = clamp_uc(avg, 0, 255); + const short diff = abs(U00 - avgU); + if (diff < 30) + return U00; + return avgU; +} + +__kernel void yuv420_to_rgba_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short Udim = bufU[(y / 2) * strideU + (x / 2)] - 128; + short Vdim = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (403 * Vdim)) >> 8, 0, 255); /* R */ + destPtr[1] = clamp_uc((y256 - (48 * Udim) - (120 * Vdim)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (475 * Udim)) >> 8, 0, 255); /* B */ + /* A */ +} + +__kernel void yuv420_to_abgr_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = bufU[(y / 2) * strideU + (x / 2)] - 128; + short V = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + /* A */ + destPtr[1] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */ + destPtr[2] = clamp_uc((y256 - (48 * U) - (120 * V)) >> 8, 0, 255); /* G */ + destPtr[3] = clamp_uc((y256 + (403 * V)) >> 8, 0, 255); /* R */ +} + +__kernel void yuv444_to_abgr_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + /* A */ + destPtr[1] = clamp_uc((y256 + (475 * D)) >> 8, 0, 255); /* B */ + destPtr[2] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[3] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ +} + +__kernel void yuv444_to_rgba_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ + destPtr[1] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (475 * D)) >> 8, 0, 255); /* B */ + /* A */ +} + +__kernel void yuv420_to_rgbx_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short Udim = bufU[(y / 2) * strideU + (x / 2)] - 128; + short Vdim = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (403 * Vdim)) >> 8, 0, 255); /* R */ + destPtr[1] = clamp_uc((y256 - (48 * Udim) - (120 * Vdim)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (475 * Udim)) >> 8, 0, 255); /* B */ + destPtr[3] = 0xff; /* A */ +} + +__kernel void yuv420_to_xbgr_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = bufU[(y / 2) * strideU + (x / 2)] - 128; + short V = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = 0xff; /* A */ + destPtr[1] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */ + destPtr[2] = clamp_uc((y256 - (48 * U) - (120 * V)) >> 8, 0, 255); /* G */ + destPtr[3] = clamp_uc((y256 + (403 * V)) >> 8, 0, 255); /* R */ +} + +__kernel void yuv444_to_xbgr_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = 0xff; /* A */ + destPtr[1] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */ + destPtr[2] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[3] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ +} + +__kernel void yuv444_to_rgbx_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ + destPtr[1] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (475 * D)) >> 8, 0, 255); /* B */ + destPtr[3] = 0xff; /* A */ +} + +__kernel void yuv420_to_argb_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short Udim = bufU[(y / 2) * strideU + (x / 2)] - 128; + short Vdim = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + /* A */ + destPtr[1] = clamp_uc((y256 + (403 * Vdim)) >> 8, 0, 255); /* R */ + destPtr[2] = clamp_uc((y256 - (48 * Udim) - (120 * Vdim)) >> 8, 0, 255); /* G */ + destPtr[3] = clamp_uc((y256 + (475 * Udim)) >> 8, 0, 255); /* B */ +} + +__kernel void yuv420_to_bgra_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = bufU[(y / 2) * strideU + (x / 2)] - 128; + short V = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */ + destPtr[1] = clamp_uc((y256 - (48 * U) - (120 * V)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (403 * V)) >> 8, 0, 255); /* R */ + /* A */ +} + +__kernel void yuv444_to_bgra_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (475 * D)) >> 8, 0, 255); /* B */ + destPtr[1] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ + /* A */ +} + +__kernel void yuv444_to_argb_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[3] = clamp_uc((y256 + (475 * D)) >> 8, 0, 255); /* B */ + destPtr[2] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[1] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ + /* A */ +} + +__kernel void yuv420_to_xrgb_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short Udim = bufU[(y / 2) * strideU + (x / 2)] - 128; + short Vdim = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = 0xff; /* A */ + destPtr[1] = clamp_uc((y256 + (403 * Vdim)) >> 8, 0, 255); /* R */ + destPtr[2] = clamp_uc((y256 - (48 * Udim) - (120 * Vdim)) >> 8, 0, 255); /* G */ + destPtr[3] = clamp_uc((y256 + (475 * Udim)) >> 8, 0, 255); /* B */ +} + +__kernel void yuv420_to_bgrx_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = bufU[(y / 2) * strideU + (x / 2)] - 128; + short V = bufV[(y / 2) * strideV + (x / 2)] - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (475 * U)) >> 8, 0, 255); /* B */ + destPtr[1] = clamp_uc((y256 - (48 * U) - (120 * V)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (403 * V)) >> 8, 0, 255); /* R */ + destPtr[3] = 0xff; /* A */ +} + +__kernel void yuv444_to_bgrx_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[0] = clamp_uc((y256 + (475 * D)) >> 8, 0, 255); /* B */ + destPtr[1] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[2] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ + destPtr[3] = 0xff; /* A */ +} + +__kernel void yuv444_to_xrgb_1b(__global const uchar* bufY, unsigned strideY, + __global const uchar* bufU, unsigned strideU, + __global const uchar* bufV, unsigned strideV, __global uchar* dest, + unsigned strideDest) +{ + unsigned int x = get_global_id(0); + unsigned int y = get_global_id(1); + + short Y = bufY[y * strideY + x]; + short U = avgUV(bufU, strideU, x, y); + short V = avgUV(bufV, strideV, x, y); + short D = U - 128; + short E = V - 128; + + __global uchar* destPtr = dest + (strideDest * y) + (x * 4); + + /** + * | R | ( | 256 0 403 | | Y | ) + * | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8 + * | B | ( | 256 475 0 | | V - 128 | ) + */ + int y256 = 256 * Y; + destPtr[3] = clamp_uc((y256 + (475 * D)) >> 8, 0, 255); /* B */ + destPtr[2] = clamp_uc((y256 - (48 * D) - (120 * E)) >> 8, 0, 255); /* G */ + destPtr[1] = clamp_uc((y256 + (403 * E)) >> 8, 0, 255); /* R */ + destPtr[0] = 0xff; /* A */ +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/primitives.h.in b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/primitives.h.in new file mode 100644 index 0000000000000000000000000000000000000000..69a4ed4c2731178c426dcc730e254043dda8d624 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/opencl/primitives.h.in @@ -0,0 +1,11 @@ +/* AUTOGENERATED file, do not edit + * + * part of @PROJECT_NAME@ + * generated from libfreerdp/primitives/opencl/primitives.h.in + * + * with file contents of @FILENAME@ + */ +#pragma once + +static const char openclProgram[] = { @FILEDATA@ }; + diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_YCoCg_ssse3.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_YCoCg_ssse3.c new file mode 100644 index 0000000000000000000000000000000000000000..c2ad2a632c28eab93c2d3f77b4b7b8249dd198c6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_YCoCg_ssse3.c @@ -0,0 +1,468 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized YCoCg<->RGB conversion operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include +#include + +#include "prim_YCoCg.h" + +#include "prim_internal.h" +#include "prim_templates.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include + +static primitives_t* generic = NULL; + +/* ------------------------------------------------------------------------- */ +static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_invert(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 DstFormat, + UINT32 dstStep, UINT32 width, UINT32 height, + UINT8 shift, BOOL withAlpha) +{ + const BYTE* sptr = pSrc; + BYTE* dptr = pDst; + + WINPR_ASSERT(srcStep / sizeof(UINT32) >= width); + WINPR_ASSERT(dstStep / sizeof(UINT32) >= width); + const size_t sRowBump = srcStep - width * sizeof(UINT32); + const size_t dRowBump = dstStep - width * sizeof(UINT32); + /* Shift left by "shift" and divide by two is the same as shift + * left by "shift-1". + */ + int dataShift = shift - 1; + BYTE mask = (BYTE)(0xFFU << dataShift); + + /* Let's say the data is of the form: + * y0y0o0g0 a1y1o1g1 a2y2o2g2... + * Apply: + * |R| | 1 1/2 -1/2 | |y| + * |G| = | 1 0 1/2 | * |o| + * |B| | 1 -1/2 -1/2 | |g| + * where Y is 8-bit unsigned and o & g are 8-bit signed. + */ + + if ((width < 8) || (ULONG_PTR)dptr & 0x03) + { + /* Too small, or we'll never hit a 16-byte boundary. Punt. */ + return generic->YCoCgToRGB_8u_AC4R(pSrc, WINPR_ASSERTING_INT_CAST(INT32, srcStep), pDst, + DstFormat, WINPR_ASSERTING_INT_CAST(INT32, dstStep), + width, height, shift, withAlpha); + } + + for (UINT32 h = 0; h < height; h++) + { + UINT32 w = width; + BOOL onStride = 0; + + /* Get to a 16-byte destination boundary. */ + if ((ULONG_PTR)dptr & 0x0f) + { + pstatus_t status = 0; + UINT32 startup = (16 - ((ULONG_PTR)dptr & 0x0f)) / 4; + + if (startup > width) + startup = width; + + status = generic->YCoCgToRGB_8u_AC4R( + sptr, WINPR_ASSERTING_INT_CAST(INT32, srcStep), dptr, DstFormat, + WINPR_ASSERTING_INT_CAST(INT32, dstStep), startup, 1, shift, withAlpha); + + if (status != PRIMITIVES_SUCCESS) + return status; + + sptr += startup * sizeof(UINT32); + dptr += startup * sizeof(UINT32); + w -= startup; + } + + /* Each loop handles eight pixels at a time. */ + onStride = (((ULONG_PTR)sptr & 0x0f) == 0) ? TRUE : FALSE; + + while (w >= 8) + { + __m128i R0; + __m128i R1; + __m128i R2; + __m128i R3; + __m128i R4; + __m128i R5; + __m128i R6; + __m128i R7; + + if (onStride) + { + /* The faster path, 16-byte aligned load. */ + R0 = _mm_load_si128((const __m128i*)sptr); + sptr += (128 / 8); + R1 = _mm_load_si128((const __m128i*)sptr); + sptr += (128 / 8); + } + else + { + /* Off-stride, slower LDDQU load. */ + R0 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += (128 / 8); + R1 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += (128 / 8); + } + + /* R0 = a3y3o3g3 a2y2o2g2 a1y1o1g1 a0y0o0g0 */ + /* R1 = a7y7o7g7 a6y6o6g6 a5y5o5g5 a4y4o4g4 */ + /* Shuffle to pack all the like types together. */ + R2 = _mm_set_epi32(0x0f0b0703, 0x0e0a0602, 0x0d090501, 0x0c080400); + R3 = _mm_shuffle_epi8(R0, R2); + R4 = _mm_shuffle_epi8(R1, R2); + /* R3 = a3a2a1a0 y3y2y1y0 o3o2o1o0 g3g2g1g0 */ + /* R4 = a7a6a5a4 y7y6y5y4 o7o6o5o4 g7g6g5g4 */ + R5 = _mm_unpackhi_epi32(R3, R4); + R6 = _mm_unpacklo_epi32(R3, R4); + + /* R5 = a7a6a5a4 a3a2a1a0 y7y6y5y4 y3y2y1y0 */ + /* R6 = o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + /* Save alphas aside */ + if (withAlpha) + R7 = _mm_unpackhi_epi64(R5, R5); + else + R7 = mm_set1_epu32(0xFFFFFFFFU); + + /* R7 = a7a6a5a4 a3a2a1a0 a7a6a5a4 a3a2a1a0 */ + /* Expand Y's from 8-bit unsigned to 16-bit signed. */ + R1 = mm_set1_epu32(0); + R0 = _mm_unpacklo_epi8(R5, R1); + /* R0 = 00y700y6 00y500y4 00y300y2 00y100y0 */ + /* Shift Co's and Cg's by (shift-1). -1 covers division by two. + * Note: this must be done before sign-conversion. + * Note also there is no slli_epi8, so we have to use a 16-bit + * version and then mask. + */ + R6 = _mm_slli_epi16(R6, dataShift); + R1 = mm_set1_epu8(mask); + R6 = _mm_and_si128(R6, R1); + /* R6 = shifted o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + /* Expand Co's from 8-bit signed to 16-bit signed */ + R1 = _mm_unpackhi_epi8(R6, R6); + R1 = _mm_srai_epi16(R1, 8); + /* R1 = xxo7xxo6 xxo5xxo4 xxo3xxo2 xxo1xxo0 */ + /* Expand Cg's form 8-bit signed to 16-bit signed */ + R2 = _mm_unpacklo_epi8(R6, R6); + R2 = _mm_srai_epi16(R2, 8); + /* R2 = xxg7xxg6 xxg5xxg4 xxg3xxg2 xxg1xxg0 */ + /* Get Y - halfCg and save */ + R6 = _mm_subs_epi16(R0, R2); + /* R = (Y-halfCg) + halfCo */ + R3 = _mm_adds_epi16(R6, R1); + /* R3 = xxR7xxR6 xxR5xxR4 xxR3xxR2 xxR1xxR0 */ + /* G = Y + Cg(/2) */ + R4 = _mm_adds_epi16(R0, R2); + /* R4 = xxG7xxG6 xxG5xxG4 xxG3xxG2 xxG1xxG0 */ + /* B = (Y-halfCg) - Co(/2) */ + R5 = _mm_subs_epi16(R6, R1); + /* R5 = xxB7xxB6 xxB5xxB4 xxB3xxB2 xxB1xxB0 */ + /* Repack R's & B's. */ + R0 = _mm_packus_epi16(R3, R5); + /* R0 = R7R6R5R4 R3R2R1R0 B7B6B5B4 B3B2B1B0 */ + /* Repack G's. */ + R1 = _mm_packus_epi16(R4, R4); + /* R1 = G7G6G6G4 G3G2G1G0 G7G6G6G4 G3G2G1G0 */ + /* And add the A's. */ + R1 = _mm_unpackhi_epi64(R1, R7); + /* R1 = A7A6A6A4 A3A2A1A0 G7G6G6G4 G3G2G1G0 */ + /* Now do interleaving again. */ + R2 = _mm_unpacklo_epi8(R0, R1); + /* R2 = G7B7G6B6 G5B5G4B4 G3B3G2B2 G1B1G0B0 */ + R3 = _mm_unpackhi_epi8(R0, R1); + /* R3 = A7R7A6R6 A5R5A4R4 A3R3A2R2 A1R1A0R0 */ + R4 = _mm_unpacklo_epi16(R2, R3); + /* R4 = A3R3G3B3 A2R2G2B2 A1R1G1B1 A0R0G0B0 */ + R5 = _mm_unpackhi_epi16(R2, R3); + /* R5 = A7R7G7B7 A6R6G6B6 A5R6G5B5 A4R4G4B4 */ + _mm_store_si128((__m128i*)dptr, R4); + dptr += (128 / 8); + _mm_store_si128((__m128i*)dptr, R5); + dptr += (128 / 8); + w -= 8; + } + + /* Handle any remainder pixels. */ + if (w > 0) + { + pstatus_t status = 0; + status = generic->YCoCgToRGB_8u_AC4R( + sptr, WINPR_ASSERTING_INT_CAST(INT32, srcStep), dptr, DstFormat, + WINPR_ASSERTING_INT_CAST(INT32, dstStep), w, 1, shift, withAlpha); + + if (status != PRIMITIVES_SUCCESS) + return status; + + sptr += w * sizeof(UINT32); + dptr += w * sizeof(UINT32); + } + + sptr += sRowBump; + dptr += dRowBump; + } + + return PRIMITIVES_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ +static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R_no_invert(const BYTE* WINPR_RESTRICT pSrc, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst, + UINT32 DstFormat, UINT32 dstStep, UINT32 width, + UINT32 height, UINT8 shift, BOOL withAlpha) +{ + const BYTE* sptr = pSrc; + BYTE* dptr = pDst; + size_t sRowBump = srcStep - width * sizeof(UINT32); + size_t dRowBump = dstStep - width * sizeof(UINT32); + /* Shift left by "shift" and divide by two is the same as shift + * left by "shift-1". + */ + int dataShift = shift - 1; + BYTE mask = (BYTE)(0xFFU << dataShift); + + /* Let's say the data is of the form: + * y0y0o0g0 a1y1o1g1 a2y2o2g2... + * Apply: + * |R| | 1 1/2 -1/2 | |y| + * |G| = | 1 0 1/2 | * |o| + * |B| | 1 -1/2 -1/2 | |g| + * where Y is 8-bit unsigned and o & g are 8-bit signed. + */ + + if ((width < 8) || (ULONG_PTR)dptr & 0x03) + { + /* Too small, or we'll never hit a 16-byte boundary. Punt. */ + return generic->YCoCgToRGB_8u_AC4R(pSrc, WINPR_ASSERTING_INT_CAST(INT32, srcStep), pDst, + DstFormat, WINPR_ASSERTING_INT_CAST(INT32, dstStep), + width, height, shift, withAlpha); + } + + for (UINT32 h = 0; h < height; h++) + { + UINT32 w = width; + BOOL onStride = 0; + + /* Get to a 16-byte destination boundary. */ + if ((ULONG_PTR)dptr & 0x0f) + { + pstatus_t status = 0; + UINT32 startup = (16 - ((ULONG_PTR)dptr & 0x0f)) / 4; + + if (startup > width) + startup = width; + + status = generic->YCoCgToRGB_8u_AC4R( + sptr, WINPR_ASSERTING_INT_CAST(INT32, srcStep), dptr, DstFormat, + WINPR_ASSERTING_INT_CAST(INT32, dstStep), startup, 1, shift, withAlpha); + + if (status != PRIMITIVES_SUCCESS) + return status; + + sptr += startup * sizeof(UINT32); + dptr += startup * sizeof(UINT32); + w -= startup; + } + + /* Each loop handles eight pixels at a time. */ + onStride = (((const ULONG_PTR)sptr & 0x0f) == 0) ? TRUE : FALSE; + + while (w >= 8) + { + __m128i R0; + __m128i R1; + __m128i R2; + __m128i R3; + __m128i R4; + __m128i R5; + __m128i R6; + __m128i R7; + + if (onStride) + { + /* The faster path, 16-byte aligned load. */ + R0 = _mm_load_si128((const __m128i*)sptr); + sptr += (128 / 8); + R1 = _mm_load_si128((const __m128i*)sptr); + sptr += (128 / 8); + } + else + { + /* Off-stride, slower LDDQU load. */ + R0 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += (128 / 8); + R1 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += (128 / 8); + } + + /* R0 = a3y3o3g3 a2y2o2g2 a1y1o1g1 a0y0o0g0 */ + /* R1 = a7y7o7g7 a6y6o6g6 a5y5o5g5 a4y4o4g4 */ + /* Shuffle to pack all the like types together. */ + R2 = _mm_set_epi32(0x0f0b0703, 0x0e0a0602, 0x0d090501, 0x0c080400); + R3 = _mm_shuffle_epi8(R0, R2); + R4 = _mm_shuffle_epi8(R1, R2); + /* R3 = a3a2a1a0 y3y2y1y0 o3o2o1o0 g3g2g1g0 */ + /* R4 = a7a6a5a4 y7y6y5y4 o7o6o5o4 g7g6g5g4 */ + R5 = _mm_unpackhi_epi32(R3, R4); + R6 = _mm_unpacklo_epi32(R3, R4); + + /* R5 = a7a6a5a4 a3a2a1a0 y7y6y5y4 y3y2y1y0 */ + /* R6 = o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + /* Save alphas aside */ + if (withAlpha) + R7 = _mm_unpackhi_epi64(R5, R5); + else + R7 = mm_set1_epu32(0xFFFFFFFFU); + + /* R7 = a7a6a5a4 a3a2a1a0 a7a6a5a4 a3a2a1a0 */ + /* Expand Y's from 8-bit unsigned to 16-bit signed. */ + R1 = mm_set1_epu32(0); + R0 = _mm_unpacklo_epi8(R5, R1); + /* R0 = 00y700y6 00y500y4 00y300y2 00y100y0 */ + /* Shift Co's and Cg's by (shift-1). -1 covers division by two. + * Note: this must be done before sign-conversion. + * Note also there is no slli_epi8, so we have to use a 16-bit + * version and then mask. + */ + R6 = _mm_slli_epi16(R6, dataShift); + R1 = mm_set1_epu8(mask); + R6 = _mm_and_si128(R6, R1); + /* R6 = shifted o7o6o5o4 o3o2o1o0 g7g6g5g4 g3g2g1g0 */ + /* Expand Co's from 8-bit signed to 16-bit signed */ + R1 = _mm_unpackhi_epi8(R6, R6); + R1 = _mm_srai_epi16(R1, 8); + /* R1 = xxo7xxo6 xxo5xxo4 xxo3xxo2 xxo1xxo0 */ + /* Expand Cg's form 8-bit signed to 16-bit signed */ + R2 = _mm_unpacklo_epi8(R6, R6); + R2 = _mm_srai_epi16(R2, 8); + /* R2 = xxg7xxg6 xxg5xxg4 xxg3xxg2 xxg1xxg0 */ + /* Get Y - halfCg and save */ + R6 = _mm_subs_epi16(R0, R2); + /* R = (Y-halfCg) + halfCo */ + R3 = _mm_adds_epi16(R6, R1); + /* R3 = xxR7xxR6 xxR5xxR4 xxR3xxR2 xxR1xxR0 */ + /* G = Y + Cg(/2) */ + R4 = _mm_adds_epi16(R0, R2); + /* R4 = xxG7xxG6 xxG5xxG4 xxG3xxG2 xxG1xxG0 */ + /* B = (Y-halfCg) - Co(/2) */ + R5 = _mm_subs_epi16(R6, R1); + /* R5 = xxB7xxB6 xxB5xxB4 xxB3xxB2 xxB1xxB0 */ + /* Repack R's & B's. */ + /* This line is the only diff between inverted and non-inverted. + * Unfortunately, it would be expensive to check "inverted" + * every time through this loop. + */ + R0 = _mm_packus_epi16(R5, R3); + /* R0 = B7B6B5B4 B3B2B1B0 R7R6R5R4 R3R2R1R0 */ + /* Repack G's. */ + R1 = _mm_packus_epi16(R4, R4); + /* R1 = G7G6G6G4 G3G2G1G0 G7G6G6G4 G3G2G1G0 */ + /* And add the A's. */ + R1 = _mm_unpackhi_epi64(R1, R7); + /* R1 = A7A6A6A4 A3A2A1A0 G7G6G6G4 G3G2G1G0 */ + /* Now do interleaving again. */ + R2 = _mm_unpacklo_epi8(R0, R1); + /* R2 = G7B7G6B6 G5B5G4B4 G3B3G2B2 G1B1G0B0 */ + R3 = _mm_unpackhi_epi8(R0, R1); + /* R3 = A7R7A6R6 A5R5A4R4 A3R3A2R2 A1R1A0R0 */ + R4 = _mm_unpacklo_epi16(R2, R3); + /* R4 = A3R3G3B3 A2R2G2B2 A1R1G1B1 A0R0G0B0 */ + R5 = _mm_unpackhi_epi16(R2, R3); + /* R5 = A7R7G7B7 A6R6G6B6 A5R6G5B5 A4R4G4B4 */ + _mm_store_si128((__m128i*)dptr, R4); + dptr += (128 / 8); + _mm_store_si128((__m128i*)dptr, R5); + dptr += (128 / 8); + w -= 8; + } + + /* Handle any remainder pixels. */ + if (w > 0) + { + pstatus_t status = 0; + status = generic->YCoCgToRGB_8u_AC4R( + sptr, WINPR_ASSERTING_INT_CAST(INT32, srcStep), dptr, DstFormat, + WINPR_ASSERTING_INT_CAST(INT32, dstStep), WINPR_ASSERTING_INT_CAST(UINT32, w), 1, + shift, withAlpha); + + if (status != PRIMITIVES_SUCCESS) + return status; + + sptr += WINPR_ASSERTING_INT_CAST(UINT32, w) * sizeof(UINT32); + dptr += WINPR_ASSERTING_INT_CAST(UINT32, w) * sizeof(UINT32); + } + + sptr += sRowBump; + dptr += dRowBump; + } + + return PRIMITIVES_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ +static pstatus_t ssse3_YCoCgRToRGB_8u_AC4R(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 DstFormat, + INT32 dstStep, UINT32 width, UINT32 height, UINT8 shift, + BOOL withAlpha) +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return ssse3_YCoCgRToRGB_8u_AC4R_invert( + pSrc, WINPR_ASSERTING_INT_CAST(UINT32, srcStep), pDst, DstFormat, + WINPR_ASSERTING_INT_CAST(UINT32, dstStep), width, height, shift, withAlpha); + + case PIXEL_FORMAT_RGBX32: + case PIXEL_FORMAT_RGBA32: + return ssse3_YCoCgRToRGB_8u_AC4R_no_invert( + pSrc, WINPR_ASSERTING_INT_CAST(UINT32, srcStep), pDst, DstFormat, + WINPR_ASSERTING_INT_CAST(UINT32, dstStep), width, height, shift, withAlpha); + + default: + return generic->YCoCgToRGB_8u_AC4R(pSrc, srcStep, pDst, DstFormat, dstStep, width, + height, shift, withAlpha); + } +} + +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_YCoCg_ssse3(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_YCoCg(prims); + + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3) && + IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE3/SSSE3 optimizations"); + prims->YCoCgToRGB_8u_AC4R = ssse3_YCoCgRToRGB_8u_AC4R; + } +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE2 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_YUV_sse4.1.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_YUV_sse4.1.c new file mode 100644 index 0000000000000000000000000000000000000000..05083b55638b899d7de0bf4e603548157688de18 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_YUV_sse4.1.c @@ -0,0 +1,1775 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Optimized YUV/RGB conversion operations + * + * Copyright 2014 Thomas Erbesdobler + * Copyright 2016-2017 Armin Novak + * Copyright 2016-2017 Norbert Federa + * Copyright 2016-2017 Thincast Technologies GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include +#include +#include +#include + +#include "prim_internal.h" +#include "prim_YUV.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include +#include + +static primitives_t* generic = NULL; + +/****************************************************************************/ +/* sse41 YUV420 -> RGB conversion */ +/****************************************************************************/ +static inline __m128i* sse41_YUV444Pixel(__m128i* WINPR_RESTRICT dst, __m128i Yraw, __m128i Uraw, + __m128i Vraw, UINT8 pos) +{ + const __m128i mapY[] = { mm_set_epu32(0x80800380, 0x80800280, 0x80800180, 0x80800080), + mm_set_epu32(0x80800780, 0x80800680, 0x80800580, 0x80800480), + mm_set_epu32(0x80800B80, 0x80800A80, 0x80800980, 0x80800880), + mm_set_epu32(0x80800F80, 0x80800E80, 0x80800D80, 0x80800C80) }; + const __m128i mapUV[] = { mm_set_epu32(0x80038002, 0x80018000, 0x80808080, 0x80808080), + mm_set_epu32(0x80078006, 0x80058004, 0x80808080, 0x80808080), + mm_set_epu32(0x800B800A, 0x80098008, 0x80808080, 0x80808080), + mm_set_epu32(0x800F800E, 0x800D800C, 0x80808080, 0x80808080) }; + const __m128i mask[] = { mm_set_epu32(0x80038080, 0x80028080, 0x80018080, 0x80008080), + mm_set_epu32(0x80800380, 0x80800280, 0x80800180, 0x80800080), + mm_set_epu32(0x80808003, 0x80808002, 0x80808001, 0x80808000) }; + const __m128i c128 = _mm_set1_epi16(128); + __m128i BGRX = _mm_and_si128(_mm_loadu_si128(dst), + mm_set_epu32(0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000)); + { + __m128i C; + __m128i D; + __m128i E; + /* Load Y values and expand to 32 bit */ + { + C = _mm_shuffle_epi8(Yraw, mapY[pos]); /* Reorder and multiply by 256 */ + } + /* Load U values and expand to 32 bit */ + { + const __m128i U = _mm_shuffle_epi8(Uraw, mapUV[pos]); /* Reorder dcba */ + D = _mm_sub_epi16(U, c128); /* D = U - 128 */ + } + /* Load V values and expand to 32 bit */ + { + const __m128i V = _mm_shuffle_epi8(Vraw, mapUV[pos]); /* Reorder dcba */ + E = _mm_sub_epi16(V, c128); /* E = V - 128 */ + } + /* Get the R value */ + { + const __m128i c403 = _mm_set1_epi16(403); + const __m128i e403 = + _mm_unpackhi_epi16(_mm_mullo_epi16(E, c403), _mm_mulhi_epi16(E, c403)); + const __m128i Rs = _mm_add_epi32(C, e403); + const __m128i R32 = _mm_srai_epi32(Rs, 8); + const __m128i R16 = _mm_packs_epi32(R32, _mm_setzero_si128()); + const __m128i R = _mm_packus_epi16(R16, _mm_setzero_si128()); + const __m128i packed = _mm_shuffle_epi8(R, mask[0]); + BGRX = _mm_or_si128(BGRX, packed); + } + /* Get the G value */ + { + const __m128i c48 = _mm_set1_epi16(48); + const __m128i d48 = + _mm_unpackhi_epi16(_mm_mullo_epi16(D, c48), _mm_mulhi_epi16(D, c48)); + const __m128i c120 = _mm_set1_epi16(120); + const __m128i e120 = + _mm_unpackhi_epi16(_mm_mullo_epi16(E, c120), _mm_mulhi_epi16(E, c120)); + const __m128i de = _mm_add_epi32(d48, e120); + const __m128i Gs = _mm_sub_epi32(C, de); + const __m128i G32 = _mm_srai_epi32(Gs, 8); + const __m128i G16 = _mm_packs_epi32(G32, _mm_setzero_si128()); + const __m128i G = _mm_packus_epi16(G16, _mm_setzero_si128()); + const __m128i packed = _mm_shuffle_epi8(G, mask[1]); + BGRX = _mm_or_si128(BGRX, packed); + } + /* Get the B value */ + { + const __m128i c475 = _mm_set1_epi16(475); + const __m128i d475 = + _mm_unpackhi_epi16(_mm_mullo_epi16(D, c475), _mm_mulhi_epi16(D, c475)); + const __m128i Bs = _mm_add_epi32(C, d475); + const __m128i B32 = _mm_srai_epi32(Bs, 8); + const __m128i B16 = _mm_packs_epi32(B32, _mm_setzero_si128()); + const __m128i B = _mm_packus_epi16(B16, _mm_setzero_si128()); + const __m128i packed = _mm_shuffle_epi8(B, mask[2]); + BGRX = _mm_or_si128(BGRX, packed); + } + } + _mm_storeu_si128(dst++, BGRX); + return dst; +} + +static inline pstatus_t sse41_YUV420ToRGB_BGRX(const BYTE* WINPR_RESTRICT pSrc[], + const UINT32* WINPR_RESTRICT srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi) +{ + const UINT32 nWidth = roi->width; + const UINT32 nHeight = roi->height; + const UINT32 pad = roi->width % 16; + const __m128i duplicate = _mm_set_epi8(7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0); + + for (size_t y = 0; y < nHeight; y++) + { + __m128i* dst = (__m128i*)(pDst + dstStep * y); + const BYTE* YData = pSrc[0] + y * srcStep[0]; + const BYTE* UData = pSrc[1] + (y / 2) * srcStep[1]; + const BYTE* VData = pSrc[2] + (y / 2) * srcStep[2]; + + for (UINT32 x = 0; x < nWidth - pad; x += 16) + { + const __m128i Y = _mm_loadu_si128((const __m128i*)YData); + const __m128i uRaw = _mm_loadu_si128((const __m128i*)UData); + const __m128i vRaw = _mm_loadu_si128((const __m128i*)VData); + const __m128i U = _mm_shuffle_epi8(uRaw, duplicate); + const __m128i V = _mm_shuffle_epi8(vRaw, duplicate); + YData += 16; + UData += 8; + VData += 8; + dst = sse41_YUV444Pixel(dst, Y, U, V, 0); + dst = sse41_YUV444Pixel(dst, Y, U, V, 1); + dst = sse41_YUV444Pixel(dst, Y, U, V, 2); + dst = sse41_YUV444Pixel(dst, Y, U, V, 3); + } + + for (UINT32 x = 0; x < pad; x++) + { + const BYTE Y = *YData++; + const BYTE U = *UData; + const BYTE V = *VData; + const BYTE r = YUV2R(Y, U, V); + const BYTE g = YUV2G(Y, U, V); + const BYTE b = YUV2B(Y, U, V); + dst = (__m128i*)writePixelBGRX((BYTE*)dst, 4, PIXEL_FORMAT_BGRX32, r, g, b, 0); + + if (x % 2) + { + UData++; + VData++; + } + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_YUV420ToRGB(const BYTE* WINPR_RESTRICT pSrc[3], const UINT32 srcStep[3], + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return sse41_YUV420ToRGB_BGRX(pSrc, srcStep, pDst, dstStep, roi); + + default: + return generic->YUV420ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} + +static inline void BGRX_fillRGB(size_t offset, BYTE* WINPR_RESTRICT pRGB[2], + const BYTE* WINPR_RESTRICT pY[2], const BYTE* WINPR_RESTRICT pU[2], + const BYTE* WINPR_RESTRICT pV[2], BOOL filter) +{ + WINPR_ASSERT(pRGB); + WINPR_ASSERT(pY); + WINPR_ASSERT(pU); + WINPR_ASSERT(pV); + + const UINT32 DstFormat = PIXEL_FORMAT_BGRX32; + const UINT32 bpp = 4; + + for (size_t i = 0; i < 2; i++) + { + for (size_t j = 0; j < 2; j++) + { + const BYTE Y = pY[i][offset + j]; + BYTE U = pU[i][offset + j]; + BYTE V = pV[i][offset + j]; + if ((i == 0) && (j == 0) && filter) + { + const INT32 avgU = + 4 * pU[0][offset] - pU[0][offset + 1] - pU[1][offset] - pU[1][offset + 1]; + const INT32 avgV = + 4 * pV[0][offset] - pV[0][offset + 1] - pV[1][offset] - pV[1][offset + 1]; + + U = CONDITIONAL_CLIP(avgU, pU[0][offset]); + V = CONDITIONAL_CLIP(avgV, pV[0][offset]); + } + + const BYTE r = YUV2R(Y, U, V); + const BYTE g = YUV2G(Y, U, V); + const BYTE b = YUV2B(Y, U, V); + writePixelBGRX(&pRGB[i][(j + offset) * bpp], bpp, DstFormat, r, g, b, 0); + } + } +} + +static inline void unpack_mul_add(__m128i toadd[2], __m128i narrow, short iMul, __m128i sub) +{ + const __m128i usub = _mm_sub_epi16(narrow, sub); + const __m128i mul = _mm_set1_epi32(iMul); + const __m128i umulhi = _mm_mulhi_epi16(usub, mul); + const __m128i umullo = _mm_mullo_epi16(usub, mul); + { + const __m128i umul = _mm_unpackhi_epi16(umullo, umulhi); + toadd[0] = _mm_add_epi32(toadd[0], umul); + } + { + const __m128i umul = _mm_unpacklo_epi16(umullo, umulhi); + toadd[1] = _mm_add_epi32(toadd[1], umul); + } +} + +/* input are uint16_t vectors */ +static inline __m128i sse41_yuv2x_single(const __m128i Y, __m128i U, __m128i V, const short iMulU, + const short iMulV) +{ + const __m128i zero = _mm_set1_epi8(0); + + __m128i Ylo = _mm_unpacklo_epi16(Y, zero); + __m128i Yhi = _mm_unpackhi_epi16(Y, zero); + if (iMulU != 0) + { + const __m128i addX = _mm_set1_epi16(128); + const __m128i D = _mm_sub_epi16(U, addX); + const __m128i mulU = _mm_set1_epi16(iMulU); + const __m128i mulDlo = _mm_mullo_epi16(D, mulU); + const __m128i mulDhi = _mm_mulhi_epi16(D, mulU); + const __m128i Dlo = _mm_unpacklo_epi16(mulDlo, mulDhi); + Ylo = _mm_add_epi32(Ylo, Dlo); + + const __m128i Dhi = _mm_unpackhi_epi16(mulDlo, mulDhi); + Yhi = _mm_add_epi32(Yhi, Dhi); + } + if (iMulV != 0) + { + const __m128i addX = _mm_set1_epi16(128); + const __m128i E = _mm_sub_epi16(V, addX); + const __m128i mul = _mm_set1_epi16(iMulV); + const __m128i mulElo = _mm_mullo_epi16(E, mul); + const __m128i mulEhi = _mm_mulhi_epi16(E, mul); + const __m128i Elo = _mm_unpacklo_epi16(mulElo, mulEhi); + const __m128i esumlo = _mm_add_epi32(Ylo, Elo); + + const __m128i Ehi = _mm_unpackhi_epi16(mulElo, mulEhi); + const __m128i esumhi = _mm_add_epi32(Yhi, Ehi); + Ylo = esumlo; + Yhi = esumhi; + } + + const __m128i rYlo = _mm_srai_epi32(Ylo, 8); + const __m128i rYhi = _mm_srai_epi32(Yhi, 8); + const __m128i rY = _mm_packs_epi32(rYlo, rYhi); + return rY; +} + +/* Input are uint8_t vectors */ +static inline __m128i sse41_yuv2x(const __m128i Y, __m128i U, __m128i V, const short iMulU, + const short iMulV) +{ + const __m128i zero = _mm_set1_epi8(0); + + /* Ylo = Y * 256 + * Ulo = uint8_t -> uint16_t + * Vlo = uint8_t -> uint16_t + */ + const __m128i Ylo = _mm_unpacklo_epi8(zero, Y); + const __m128i Ulo = _mm_unpacklo_epi8(U, zero); + const __m128i Vlo = _mm_unpacklo_epi8(V, zero); + const __m128i preslo = sse41_yuv2x_single(Ylo, Ulo, Vlo, iMulU, iMulV); + + const __m128i Yhi = _mm_unpackhi_epi8(zero, Y); + const __m128i Uhi = _mm_unpackhi_epi8(U, zero); + const __m128i Vhi = _mm_unpackhi_epi8(V, zero); + const __m128i preshi = sse41_yuv2x_single(Yhi, Uhi, Vhi, iMulU, iMulV); + const __m128i res = _mm_packus_epi16(preslo, preshi); + + return res; +} + +/* const INT32 r = ((256L * C(Y) + 0L * D(U) + 403L * E(V))) >> 8; */ +static inline __m128i sse41_yuv2r(const __m128i Y, __m128i U, __m128i V) +{ + return sse41_yuv2x(Y, U, V, 0, 403); +} + +/* const INT32 g = ((256L * C(Y) - 48L * D(U) - 120L * E(V))) >> 8; */ +static inline __m128i sse41_yuv2g(const __m128i Y, __m128i U, __m128i V) +{ + return sse41_yuv2x(Y, U, V, -48, -120); +} + +/* const INT32 b = ((256L * C(Y) + 475L * D(U) + 0L * E(V))) >> 8; */ +static inline __m128i sse41_yuv2b(const __m128i Y, __m128i U, __m128i V) +{ + return sse41_yuv2x(Y, U, V, 475, 0); +} + +static inline void sse41_BGRX_fillRGB_pixel(BYTE* WINPR_RESTRICT pRGB, __m128i Y, __m128i U, + __m128i V) +{ + const __m128i zero = _mm_set1_epi8(0); + /* Y * 256 */ + const __m128i r = sse41_yuv2r(Y, U, V); + const __m128i rx[2] = { _mm_unpackhi_epi8(r, zero), _mm_unpacklo_epi8(r, zero) }; + + const __m128i g = sse41_yuv2g(Y, U, V); + const __m128i b = sse41_yuv2b(Y, U, V); + + const __m128i bg[2] = { _mm_unpackhi_epi8(b, g), _mm_unpacklo_epi8(b, g) }; + + const __m128i mask = mm_set_epu8(0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, + 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF); + + __m128i* rgb = (__m128i*)pRGB; + const __m128i bgrx0 = _mm_unpacklo_epi16(bg[1], rx[1]); + _mm_maskmoveu_si128(bgrx0, mask, (char*)&rgb[0]); + const __m128i bgrx1 = _mm_unpackhi_epi16(bg[1], rx[1]); + _mm_maskmoveu_si128(bgrx1, mask, (char*)&rgb[1]); + const __m128i bgrx2 = _mm_unpacklo_epi16(bg[0], rx[0]); + _mm_maskmoveu_si128(bgrx2, mask, (char*)&rgb[2]); + const __m128i bgrx3 = _mm_unpackhi_epi16(bg[0], rx[0]); + _mm_maskmoveu_si128(bgrx3, mask, (char*)&rgb[3]); +} + +static inline __m128i odd1sum(__m128i u1) +{ + const __m128i zero = _mm_set1_epi8(0); + const __m128i u1hi = _mm_unpackhi_epi8(u1, zero); + const __m128i u1lo = _mm_unpacklo_epi8(u1, zero); + return _mm_hadds_epi16(u1lo, u1hi); +} + +static inline __m128i odd0sum(__m128i u0, __m128i u1sum) +{ + /* Mask out even bytes, extend uint8_t to uint16_t by filling in zero bytes, + * horizontally add the values */ + const __m128i mask = mm_set_epu8(0x80, 0x0F, 0x80, 0x0D, 0x80, 0x0B, 0x80, 0x09, 0x80, 0x07, + 0x80, 0x05, 0x80, 0x03, 0x80, 0x01); + const __m128i u0odd = _mm_shuffle_epi8(u0, mask); + return _mm_adds_epi16(u1sum, u0odd); +} + +static inline __m128i calcavg(__m128i u0even, __m128i sum) +{ + const __m128i u4zero = _mm_slli_epi16(u0even, 2); + const __m128i uavg = _mm_sub_epi16(u4zero, sum); + const __m128i zero = _mm_set1_epi8(0); + const __m128i savg = _mm_packus_epi16(uavg, zero); + const __m128i smask = mm_set_epu8(0x80, 0x07, 0x80, 0x06, 0x80, 0x05, 0x80, 0x04, 0x80, 0x03, + 0x80, 0x02, 0x80, 0x01, 0x80, 0x00); + return _mm_shuffle_epi8(savg, smask); +} + +static inline __m128i diffmask(__m128i avg, __m128i u0even) +{ + /* Check for values >= 30 to apply the avg value to + * use int16 for calculations to avoid issues with signed 8bit integers + */ + const __m128i diff = _mm_subs_epi16(u0even, avg); + const __m128i absdiff = _mm_abs_epi16(diff); + const __m128i val30 = _mm_set1_epi16(30); + return _mm_cmplt_epi16(absdiff, val30); +} + +static inline void sse41_filter(__m128i pU[2]) +{ + const __m128i u1sum = odd1sum(pU[1]); + const __m128i sum = odd0sum(pU[0], u1sum); + + /* Mask out the odd bytes. We don´t need to do anything to make the uint8_t to uint16_t */ + const __m128i emask = mm_set_epu8(0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, + 0x00, 0xff, 0x00, 0xff, 0x00, 0xff); + const __m128i u0even = _mm_and_si128(pU[0], emask); + const __m128i avg = calcavg(u0even, sum); + const __m128i umask = diffmask(avg, u0even); + + const __m128i u0orig = _mm_and_si128(u0even, umask); + const __m128i u0avg = _mm_andnot_si128(umask, avg); + const __m128i evenresult = _mm_or_si128(u0orig, u0avg); + const __m128i omask = mm_set_epu8(0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00); + const __m128i u0odd = _mm_and_si128(pU[0], omask); + const __m128i result = _mm_or_si128(evenresult, u0odd); + pU[0] = result; +} + +static inline void sse41_BGRX_fillRGB(BYTE* WINPR_RESTRICT pRGB[2], const __m128i pY[2], + __m128i pU[2], __m128i pV[2]) +{ + WINPR_ASSERT(pRGB); + WINPR_ASSERT(pY); + WINPR_ASSERT(pU); + WINPR_ASSERT(pV); + + sse41_filter(pU); + sse41_filter(pV); + + for (size_t i = 0; i < 2; i++) + { + sse41_BGRX_fillRGB_pixel(pRGB[i], pY[i], pU[i], pV[i]); + } +} + +static inline pstatus_t sse41_YUV444ToRGB_8u_P3AC4R_BGRX_DOUBLE_ROW( + BYTE* WINPR_RESTRICT pDst[2], const BYTE* WINPR_RESTRICT YData[2], + const BYTE* WINPR_RESTRICT UData[2], const BYTE* WINPR_RESTRICT VData[2], UINT32 nWidth) +{ + WINPR_ASSERT((nWidth % 2) == 0); + const UINT32 pad = nWidth % 16; + + size_t x = 0; + for (; x < nWidth - pad; x += 16) + { + const __m128i Y[] = { _mm_loadu_si128((const __m128i*)&YData[0][x]), + _mm_loadu_si128((const __m128i*)&YData[1][x]) }; + __m128i U[] = { _mm_loadu_si128((const __m128i*)&UData[0][x]), + _mm_loadu_si128((const __m128i*)&UData[1][x]) }; + __m128i V[] = { _mm_loadu_si128((const __m128i*)&VData[0][x]), + _mm_loadu_si128((const __m128i*)&VData[1][x]) }; + + BYTE* dstp[] = { &pDst[0][x * 4], &pDst[1][x * 4] }; + sse41_BGRX_fillRGB(dstp, Y, U, V); + } + + for (; x < nWidth; x += 2) + { + BGRX_fillRGB(x, pDst, YData, UData, VData, TRUE); + } + + return PRIMITIVES_SUCCESS; +} + +static inline void BGRX_fillRGB_single(size_t offset, BYTE* WINPR_RESTRICT pRGB, + const BYTE* WINPR_RESTRICT pY, const BYTE* WINPR_RESTRICT pU, + const BYTE* WINPR_RESTRICT pV, BOOL filter) +{ + WINPR_ASSERT(pRGB); + WINPR_ASSERT(pY); + WINPR_ASSERT(pU); + WINPR_ASSERT(pV); + + const UINT32 DstFormat = PIXEL_FORMAT_BGRX32; + const UINT32 bpp = 4; + + for (size_t j = 0; j < 2; j++) + { + const BYTE Y = pY[offset + j]; + BYTE U = pU[offset + j]; + BYTE V = pV[offset + j]; + + const BYTE r = YUV2R(Y, U, V); + const BYTE g = YUV2G(Y, U, V); + const BYTE b = YUV2B(Y, U, V); + writePixelBGRX(&pRGB[(j + offset) * bpp], bpp, DstFormat, r, g, b, 0); + } +} + +static inline pstatus_t sse41_YUV444ToRGB_8u_P3AC4R_BGRX_SINGLE_ROW( + BYTE* WINPR_RESTRICT pDst, const BYTE* WINPR_RESTRICT YData, const BYTE* WINPR_RESTRICT UData, + const BYTE* WINPR_RESTRICT VData, UINT32 nWidth) +{ + WINPR_ASSERT((nWidth % 2) == 0); + + for (size_t x = 0; x < nWidth; x += 2) + { + BGRX_fillRGB_single(x, pDst, YData, UData, VData, TRUE); + } + + return PRIMITIVES_SUCCESS; +} + +static inline pstatus_t sse41_YUV444ToRGB_8u_P3AC4R_BGRX(const BYTE* WINPR_RESTRICT pSrc[], + const UINT32 srcStep[], + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi) +{ + const UINT32 nWidth = roi->width; + const UINT32 nHeight = roi->height; + + size_t y = 0; + for (; y < nHeight - nHeight % 2; y += 2) + { + BYTE* dst[] = { (pDst + dstStep * y), (pDst + dstStep * (y + 1)) }; + const BYTE* YData[] = { pSrc[0] + y * srcStep[0], pSrc[0] + (y + 1) * srcStep[0] }; + const BYTE* UData[] = { pSrc[1] + y * srcStep[1], pSrc[1] + (y + 1) * srcStep[1] }; + const BYTE* VData[] = { pSrc[2] + y * srcStep[2], pSrc[2] + (y + 1) * srcStep[2] }; + + const pstatus_t rc = + sse41_YUV444ToRGB_8u_P3AC4R_BGRX_DOUBLE_ROW(dst, YData, UData, VData, nWidth); + if (rc != PRIMITIVES_SUCCESS) + return rc; + } + for (; y < nHeight; y++) + { + BYTE* dst = (pDst + dstStep * y); + const BYTE* YData = pSrc[0] + y * srcStep[0]; + const BYTE* UData = pSrc[1] + y * srcStep[1]; + const BYTE* VData = pSrc[2] + y * srcStep[2]; + const pstatus_t rc = + sse41_YUV444ToRGB_8u_P3AC4R_BGRX_SINGLE_ROW(dst, YData, UData, VData, nWidth); + if (rc != PRIMITIVES_SUCCESS) + return rc; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_YUV444ToRGB_8u_P3AC4R(const BYTE* WINPR_RESTRICT pSrc[], + const UINT32 srcStep[], BYTE* WINPR_RESTRICT pDst, + UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) +{ + switch (DstFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return sse41_YUV444ToRGB_8u_P3AC4R_BGRX(pSrc, srcStep, pDst, dstStep, roi); + + default: + return generic->YUV444ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} + +/****************************************************************************/ +/* sse41 RGB -> YUV420 conversion **/ +/****************************************************************************/ + +/** + * Note (nfedera): + * The used forward transformation factors from RGB to YUV are based on the + * values specified in [Rec. ITU-R BT.709-6] Section 3: + * http://www.itu.int/rec/R-REC-BT.709-6-201506-I/en + * + * Y = 0.21260 * R + 0.71520 * G + 0.07220 * B + 0; + * U = -0.11457 * R - 0.38543 * G + 0.50000 * B + 128; + * V = 0.50000 * R - 0.45415 * G - 0.04585 * B + 128; + * + * The most accurate integer arithmetic approximation when using 8-bit signed + * integer factors with 16-bit signed integer intermediate results is: + * + * Y = ( ( 27 * R + 92 * G + 9 * B) >> 7 ); + * U = ( (-29 * R - 99 * G + 128 * B) >> 8 ) + 128; + * V = ( ( 128 * R - 116 * G - 12 * B) >> 8 ) + 128; + * + * Due to signed 8bit range being [-128,127] the U and V constants of 128 are + * rounded to 127 + */ + +#define BGRX_Y_FACTORS _mm_set_epi8(0, 27, 92, 9, 0, 27, 92, 9, 0, 27, 92, 9, 0, 27, 92, 9) +#define BGRX_U_FACTORS \ + _mm_set_epi8(0, -29, -99, 127, 0, -29, -99, 127, 0, -29, -99, 127, 0, -29, -99, 127) +#define BGRX_V_FACTORS \ + _mm_set_epi8(0, 127, -116, -12, 0, 127, -116, -12, 0, 127, -116, -12, 0, 127, -116, -12) +#define CONST128_FACTORS _mm_set1_epi8(-128) + +#define Y_SHIFT 7 +#define U_SHIFT 8 +#define V_SHIFT 8 + +/* +TODO: +RGB[AX] can simply be supported using the following factors. And instead of loading the +globals directly the functions below could be passed pointers to the correct vectors +depending on the source picture format. + +PRIM_ALIGN_128 static const BYTE rgbx_y_factors[] = { + 27, 92, 9, 0, 27, 92, 9, 0, 27, 92, 9, 0, 27, 92, 9, 0 +}; +PRIM_ALIGN_128 static const BYTE rgbx_u_factors[] = { + -15, -49, 64, 0, -15, -49, 64, 0, -15, -49, 64, 0, -15, -49, 64, 0 +}; +PRIM_ALIGN_128 static const BYTE rgbx_v_factors[] = { + 64, -58, -6, 0, 64, -58, -6, 0, 64, -58, -6, 0, 64, -58, -6, 0 +}; +*/ + +static inline void sse41_BGRX_TO_YUV(const BYTE* WINPR_RESTRICT pLine1, BYTE* WINPR_RESTRICT pYLine, + BYTE* WINPR_RESTRICT pULine, BYTE* WINPR_RESTRICT pVLine) +{ + const BYTE r1 = pLine1[2]; + const BYTE g1 = pLine1[1]; + const BYTE b1 = pLine1[0]; + + if (pYLine) + pYLine[0] = RGB2Y(r1, g1, b1); + if (pULine) + pULine[0] = RGB2U(r1, g1, b1); + if (pVLine) + pVLine[0] = RGB2V(r1, g1, b1); +} + +/* compute the luma (Y) component from a single rgb source line */ + +static INLINE void sse41_RGBToYUV420_BGRX_Y(const BYTE* WINPR_RESTRICT src, BYTE* dst, UINT32 width) +{ + const __m128i y_factors = BGRX_Y_FACTORS; + const __m128i* argb = (const __m128i*)src; + __m128i* ydst = (__m128i*)dst; + + UINT32 x = 0; + + for (; x < width - width % 16; x += 16) + { + /* store 16 rgba pixels in 4 128 bit registers */ + __m128i x0 = _mm_loadu_si128(argb++); // 1st 4 pixels + { + x0 = _mm_maddubs_epi16(x0, y_factors); + + __m128i x1 = _mm_loadu_si128(argb++); // 2nd 4 pixels + x1 = _mm_maddubs_epi16(x1, y_factors); + x0 = _mm_hadds_epi16(x0, x1); + x0 = _mm_srli_epi16(x0, Y_SHIFT); + } + + __m128i x2 = _mm_loadu_si128(argb++); // 3rd 4 pixels + { + x2 = _mm_maddubs_epi16(x2, y_factors); + + __m128i x3 = _mm_loadu_si128(argb++); // 4th 4 pixels + x3 = _mm_maddubs_epi16(x3, y_factors); + x2 = _mm_hadds_epi16(x2, x3); + x2 = _mm_srli_epi16(x2, Y_SHIFT); + } + + x0 = _mm_packus_epi16(x0, x2); + /* save to y plane */ + _mm_storeu_si128(ydst++, x0); + } + + for (; x < width; x++) + { + sse41_BGRX_TO_YUV(&src[4ULL * x], &dst[x], NULL, NULL); + } +} + +/* compute the chrominance (UV) components from two rgb source lines */ + +static INLINE void sse41_RGBToYUV420_BGRX_UV(const BYTE* WINPR_RESTRICT src1, + const BYTE* WINPR_RESTRICT src2, + BYTE* WINPR_RESTRICT dst1, BYTE* WINPR_RESTRICT dst2, + UINT32 width) +{ + const __m128i u_factors = BGRX_U_FACTORS; + const __m128i v_factors = BGRX_V_FACTORS; + const __m128i vector128 = CONST128_FACTORS; + + size_t x = 0; + + for (; x < width - width % 16; x += 16) + { + const __m128i* rgb1 = (const __m128i*)&src1[4ULL * x]; + const __m128i* rgb2 = (const __m128i*)&src2[4ULL * x]; + __m64* udst = (__m64*)&dst1[x / 2]; + __m64* vdst = (__m64*)&dst2[x / 2]; + + /* subsample 16x2 pixels into 16x1 pixels */ + __m128i x0 = _mm_loadu_si128(&rgb1[0]); + __m128i x4 = _mm_loadu_si128(&rgb2[0]); + x0 = _mm_avg_epu8(x0, x4); + + __m128i x1 = _mm_loadu_si128(&rgb1[1]); + x4 = _mm_loadu_si128(&rgb2[1]); + x1 = _mm_avg_epu8(x1, x4); + + __m128i x2 = _mm_loadu_si128(&rgb1[2]); + x4 = _mm_loadu_si128(&rgb2[2]); + x2 = _mm_avg_epu8(x2, x4); + + __m128i x3 = _mm_loadu_si128(&rgb1[3]); + x4 = _mm_loadu_si128(&rgb2[3]); + x3 = _mm_avg_epu8(x3, x4); + + /* subsample these 16x1 pixels into 8x1 pixels */ + /** + * shuffle controls + * c = a[0],a[2],b[0],b[2] == 10 00 10 00 = 0x88 + * c = a[1],a[3],b[1],b[3] == 11 01 11 01 = 0xdd + */ + x4 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(x0), _mm_castsi128_ps(x1), 0x88)); + x0 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(x0), _mm_castsi128_ps(x1), 0xdd)); + x0 = _mm_avg_epu8(x0, x4); + x4 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(x2), _mm_castsi128_ps(x3), 0x88)); + x1 = _mm_castps_si128(_mm_shuffle_ps(_mm_castsi128_ps(x2), _mm_castsi128_ps(x3), 0xdd)); + x1 = _mm_avg_epu8(x1, x4); + /* multiplications and subtotals */ + x2 = _mm_maddubs_epi16(x0, u_factors); + x3 = _mm_maddubs_epi16(x1, u_factors); + x4 = _mm_maddubs_epi16(x0, v_factors); + __m128i x5 = _mm_maddubs_epi16(x1, v_factors); + /* the total sums */ + x0 = _mm_hadd_epi16(x2, x3); + x1 = _mm_hadd_epi16(x4, x5); + /* shift the results */ + x0 = _mm_srai_epi16(x0, U_SHIFT); + x1 = _mm_srai_epi16(x1, V_SHIFT); + /* pack the 16 words into bytes */ + x0 = _mm_packs_epi16(x0, x1); + /* add 128 */ + x0 = _mm_sub_epi8(x0, vector128); + /* the lower 8 bytes go to the u plane */ + _mm_storel_pi(udst, _mm_castsi128_ps(x0)); + /* the upper 8 bytes go to the v plane */ + _mm_storeh_pi(vdst, _mm_castsi128_ps(x0)); + } + + for (; x < width - width % 2; x += 2) + { + BYTE u[4] = { 0 }; + BYTE v[4] = { 0 }; + sse41_BGRX_TO_YUV(&src1[4ULL * x], NULL, &u[0], &v[0]); + sse41_BGRX_TO_YUV(&src1[4ULL * (1ULL + x)], NULL, &u[1], &v[1]); + sse41_BGRX_TO_YUV(&src2[4ULL * x], NULL, &u[2], &v[2]); + sse41_BGRX_TO_YUV(&src2[4ULL * (1ULL + x)], NULL, &u[3], &v[3]); + const INT16 u4 = WINPR_ASSERTING_INT_CAST(INT16, (INT16)u[0] + u[1] + u[2] + u[3]); + const INT16 uu = WINPR_ASSERTING_INT_CAST(INT16, u4 / 4); + const BYTE u8 = CLIP(uu); + dst1[x / 2] = u8; + + const INT16 v4 = WINPR_ASSERTING_INT_CAST(INT16, (INT16)v[0] + v[1] + v[2] + v[3]); + const INT16 vu = WINPR_ASSERTING_INT_CAST(INT16, v4 / 4); + const BYTE v8 = CLIP(vu); + dst2[x / 2] = v8; + } +} + +static pstatus_t sse41_RGBToYUV420_BGRX(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst[], const UINT32 dstStep[], + const prim_size_t* WINPR_RESTRICT roi) +{ + if (roi->height < 1 || roi->width < 1) + { + return !PRIMITIVES_SUCCESS; + } + + size_t y = 0; + for (; y < roi->height - roi->height % 2; y += 2) + { + const BYTE* line1 = &pSrc[y * srcStep]; + const BYTE* line2 = &pSrc[(1ULL + y) * srcStep]; + BYTE* ydst1 = &pDst[0][y * dstStep[0]]; + BYTE* ydst2 = &pDst[0][(1ULL + y) * dstStep[0]]; + BYTE* udst = &pDst[1][y / 2 * dstStep[1]]; + BYTE* vdst = &pDst[2][y / 2 * dstStep[2]]; + + sse41_RGBToYUV420_BGRX_UV(line1, line2, udst, vdst, roi->width); + sse41_RGBToYUV420_BGRX_Y(line1, ydst1, roi->width); + sse41_RGBToYUV420_BGRX_Y(line2, ydst2, roi->width); + } + + for (; y < roi->height; y++) + { + const BYTE* line = &pSrc[y * srcStep]; + BYTE* ydst = &pDst[0][1ULL * y * dstStep[0]]; + sse41_RGBToYUV420_BGRX_Y(line, ydst, roi->width); + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_RGBToYUV420(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[], + const UINT32 dstStep[], const prim_size_t* WINPR_RESTRICT roi) +{ + switch (srcFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return sse41_RGBToYUV420_BGRX(pSrc, srcStep, pDst, dstStep, roi); + + default: + return generic->RGBToYUV420_8u_P3AC4R(pSrc, srcFormat, srcStep, pDst, dstStep, roi); + } +} + +/****************************************************************************/ +/* sse41 RGB -> AVC444-YUV conversion **/ +/****************************************************************************/ + +static INLINE void sse41_RGBToAVC444YUV_BGRX_DOUBLE_ROW( + const BYTE* WINPR_RESTRICT srcEven, const BYTE* WINPR_RESTRICT srcOdd, + BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2, + BYTE* WINPR_RESTRICT b3, BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5, + BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7, UINT32 width) +{ + const __m128i* argbEven = (const __m128i*)srcEven; + const __m128i* argbOdd = (const __m128i*)srcOdd; + const __m128i y_factors = BGRX_Y_FACTORS; + const __m128i u_factors = BGRX_U_FACTORS; + const __m128i v_factors = BGRX_V_FACTORS; + const __m128i vector128 = CONST128_FACTORS; + + UINT32 x = 0; + for (; x < width - width % 16; x += 16) + { + /* store 16 rgba pixels in 4 128 bit registers */ + const __m128i xe1 = _mm_loadu_si128(argbEven++); // 1st 4 pixels + const __m128i xe2 = _mm_loadu_si128(argbEven++); // 2nd 4 pixels + const __m128i xe3 = _mm_loadu_si128(argbEven++); // 3rd 4 pixels + const __m128i xe4 = _mm_loadu_si128(argbEven++); // 4th 4 pixels + const __m128i xo1 = _mm_loadu_si128(argbOdd++); // 1st 4 pixels + const __m128i xo2 = _mm_loadu_si128(argbOdd++); // 2nd 4 pixels + const __m128i xo3 = _mm_loadu_si128(argbOdd++); // 3rd 4 pixels + const __m128i xo4 = _mm_loadu_si128(argbOdd++); // 4th 4 pixels + { + /* Y: multiplications with subtotals and horizontal sums */ + const __m128i ye1 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe1, y_factors), + _mm_maddubs_epi16(xe2, y_factors)), + Y_SHIFT); + const __m128i ye2 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe3, y_factors), + _mm_maddubs_epi16(xe4, y_factors)), + Y_SHIFT); + const __m128i ye = _mm_packus_epi16(ye1, ye2); + const __m128i yo1 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo1, y_factors), + _mm_maddubs_epi16(xo2, y_factors)), + Y_SHIFT); + const __m128i yo2 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo3, y_factors), + _mm_maddubs_epi16(xo4, y_factors)), + Y_SHIFT); + const __m128i yo = _mm_packus_epi16(yo1, yo2); + /* store y [b1] */ + _mm_storeu_si128((__m128i*)b1Even, ye); + b1Even += 16; + + if (b1Odd) + { + _mm_storeu_si128((__m128i*)b1Odd, yo); + b1Odd += 16; + } + } + { + /* We have now + * 16 even U values in ue + * 16 odd U values in uo + * + * We need to split these according to + * 3.3.8.3.2 YUV420p Stream Combination for YUV444 mode */ + __m128i ue; + __m128i uo = { 0 }; + { + const __m128i ue1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe1, u_factors), + _mm_maddubs_epi16(xe2, u_factors)), + U_SHIFT); + const __m128i ue2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe3, u_factors), + _mm_maddubs_epi16(xe4, u_factors)), + U_SHIFT); + ue = _mm_sub_epi8(_mm_packs_epi16(ue1, ue2), vector128); + } + + if (b1Odd) + { + const __m128i uo1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo1, u_factors), + _mm_maddubs_epi16(xo2, u_factors)), + U_SHIFT); + const __m128i uo2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo3, u_factors), + _mm_maddubs_epi16(xo4, u_factors)), + U_SHIFT); + uo = _mm_sub_epi8(_mm_packs_epi16(uo1, uo2), vector128); + } + + /* Now we need the following storage distribution: + * 2x 2y -> b2 + * x 2y+1 -> b4 + * 2x+1 2y -> b6 */ + if (b1Odd) /* b2 */ + { + const __m128i ueh = _mm_unpackhi_epi8(ue, _mm_setzero_si128()); + const __m128i uoh = _mm_unpackhi_epi8(uo, _mm_setzero_si128()); + const __m128i hi = _mm_add_epi16(ueh, uoh); + const __m128i uel = _mm_unpacklo_epi8(ue, _mm_setzero_si128()); + const __m128i uol = _mm_unpacklo_epi8(uo, _mm_setzero_si128()); + const __m128i lo = _mm_add_epi16(uel, uol); + const __m128i added = _mm_hadd_epi16(lo, hi); + const __m128i avg16 = _mm_srai_epi16(added, 2); + const __m128i avg = _mm_packus_epi16(avg16, avg16); + _mm_storel_epi64((__m128i*)b2, avg); + } + else + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 14, 12, 10, 8, 6, 4, 2, 0); + const __m128i ud = _mm_shuffle_epi8(ue, mask); + _mm_storel_epi64((__m128i*)b2, ud); + } + + b2 += 8; + + if (b1Odd) /* b4 */ + { + _mm_storeu_si128((__m128i*)b4, uo); + b4 += 16; + } + + { + /* b6 */ + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 15, 13, 11, 9, 7, 5, 3, 1); + const __m128i ude = _mm_shuffle_epi8(ue, mask); + _mm_storel_epi64((__m128i*)b6, ude); + b6 += 8; + } + } + { + /* We have now + * 16 even V values in ue + * 16 odd V values in uo + * + * We need to split these according to + * 3.3.8.3.2 YUV420p Stream Combination for YUV444 mode */ + __m128i ve; + __m128i vo = { 0 }; + { + const __m128i ve1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe1, v_factors), + _mm_maddubs_epi16(xe2, v_factors)), + V_SHIFT); + const __m128i ve2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe3, v_factors), + _mm_maddubs_epi16(xe4, v_factors)), + V_SHIFT); + ve = _mm_sub_epi8(_mm_packs_epi16(ve1, ve2), vector128); + } + + if (b1Odd) + { + const __m128i vo1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo1, v_factors), + _mm_maddubs_epi16(xo2, v_factors)), + V_SHIFT); + const __m128i vo2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo3, v_factors), + _mm_maddubs_epi16(xo4, v_factors)), + V_SHIFT); + vo = _mm_sub_epi8(_mm_packs_epi16(vo1, vo2), vector128); + } + + /* Now we need the following storage distribution: + * 2x 2y -> b3 + * x 2y+1 -> b5 + * 2x+1 2y -> b7 */ + if (b1Odd) /* b3 */ + { + const __m128i veh = _mm_unpackhi_epi8(ve, _mm_setzero_si128()); + const __m128i voh = _mm_unpackhi_epi8(vo, _mm_setzero_si128()); + const __m128i hi = _mm_add_epi16(veh, voh); + const __m128i vel = _mm_unpacklo_epi8(ve, _mm_setzero_si128()); + const __m128i vol = _mm_unpacklo_epi8(vo, _mm_setzero_si128()); + const __m128i lo = _mm_add_epi16(vel, vol); + const __m128i added = _mm_hadd_epi16(lo, hi); + const __m128i avg16 = _mm_srai_epi16(added, 2); + const __m128i avg = _mm_packus_epi16(avg16, avg16); + _mm_storel_epi64((__m128i*)b3, avg); + } + else + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 14, 12, 10, 8, 6, 4, 2, 0); + const __m128i vd = _mm_shuffle_epi8(ve, mask); + _mm_storel_epi64((__m128i*)b3, vd); + } + + b3 += 8; + + if (b1Odd) /* b5 */ + { + _mm_storeu_si128((__m128i*)b5, vo); + b5 += 16; + } + + { + /* b7 */ + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 15, 13, 11, 9, 7, 5, 3, 1); + const __m128i vde = _mm_shuffle_epi8(ve, mask); + _mm_storel_epi64((__m128i*)b7, vde); + b7 += 8; + } + } + } + + general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(x, srcEven, srcOdd, b1Even, b1Odd, b2, b3, b4, b5, b6, + b7, width); +} + +static pstatus_t sse41_RGBToAVC444YUV_BGRX(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[], + const UINT32 dst1Step[], BYTE* WINPR_RESTRICT pDst2[], + const UINT32 dst2Step[], + const prim_size_t* WINPR_RESTRICT roi) +{ + if (roi->height < 1 || roi->width < 1) + return !PRIMITIVES_SUCCESS; + + size_t y = 0; + for (; y < roi->height - roi->height % 2; y += 2) + { + const BYTE* srcEven = pSrc + y * srcStep; + const BYTE* srcOdd = pSrc + (y + 1) * srcStep; + const size_t i = y >> 1; + const size_t n = (i & (size_t)~7) + i; + BYTE* b1Even = pDst1[0] + y * dst1Step[0]; + BYTE* b1Odd = (b1Even + dst1Step[0]); + BYTE* b2 = pDst1[1] + (y / 2) * dst1Step[1]; + BYTE* b3 = pDst1[2] + (y / 2) * dst1Step[2]; + BYTE* b4 = pDst2[0] + 1ULL * dst2Step[0] * n; + BYTE* b5 = b4 + 8ULL * dst2Step[0]; + BYTE* b6 = pDst2[1] + (y / 2) * dst2Step[1]; + BYTE* b7 = pDst2[2] + (y / 2) * dst2Step[2]; + sse41_RGBToAVC444YUV_BGRX_DOUBLE_ROW(srcEven, srcOdd, b1Even, b1Odd, b2, b3, b4, b5, b6, b7, + roi->width); + } + + for (; y < roi->height; y++) + { + const BYTE* srcEven = pSrc + y * srcStep; + BYTE* b1Even = pDst1[0] + y * dst1Step[0]; + BYTE* b2 = pDst1[1] + (y / 2) * dst1Step[1]; + BYTE* b3 = pDst1[2] + (y / 2) * dst1Step[2]; + BYTE* b6 = pDst2[1] + (y / 2) * dst2Step[1]; + BYTE* b7 = pDst2[2] + (y / 2) * dst2Step[2]; + general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(0, srcEven, NULL, b1Even, NULL, b2, b3, NULL, NULL, + b6, b7, roi->width); + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_RGBToAVC444YUV(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[], + const UINT32 dst1Step[], BYTE* WINPR_RESTRICT pDst2[], + const UINT32 dst2Step[], + const prim_size_t* WINPR_RESTRICT roi) +{ + switch (srcFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return sse41_RGBToAVC444YUV_BGRX(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2, + dst2Step, roi); + + default: + return generic->RGBToAVC444YUV(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2, + dst2Step, roi); + } +} + +/* Mapping of arguments: + * + * b1 [even lines] -> yLumaDstEven + * b1 [odd lines] -> yLumaDstOdd + * b2 -> uLumaDst + * b3 -> vLumaDst + * b4 -> yChromaDst1 + * b5 -> yChromaDst2 + * b6 -> uChromaDst1 + * b7 -> uChromaDst2 + * b8 -> vChromaDst1 + * b9 -> vChromaDst2 + */ +static INLINE void sse41_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW( + const BYTE* WINPR_RESTRICT srcEven, const BYTE* WINPR_RESTRICT srcOdd, + BYTE* WINPR_RESTRICT yLumaDstEven, BYTE* WINPR_RESTRICT yLumaDstOdd, + BYTE* WINPR_RESTRICT uLumaDst, BYTE* WINPR_RESTRICT vLumaDst, + BYTE* WINPR_RESTRICT yEvenChromaDst1, BYTE* WINPR_RESTRICT yEvenChromaDst2, + BYTE* WINPR_RESTRICT yOddChromaDst1, BYTE* WINPR_RESTRICT yOddChromaDst2, + BYTE* WINPR_RESTRICT uChromaDst1, BYTE* WINPR_RESTRICT uChromaDst2, + BYTE* WINPR_RESTRICT vChromaDst1, BYTE* WINPR_RESTRICT vChromaDst2, UINT32 width) +{ + const __m128i vector128 = CONST128_FACTORS; + const __m128i* argbEven = (const __m128i*)srcEven; + const __m128i* argbOdd = (const __m128i*)srcOdd; + + UINT32 x = 0; + for (; x < width - width % 16; x += 16) + { + /* store 16 rgba pixels in 4 128 bit registers + * for even and odd rows. + */ + const __m128i xe1 = _mm_loadu_si128(argbEven++); /* 1st 4 pixels */ + const __m128i xe2 = _mm_loadu_si128(argbEven++); /* 2nd 4 pixels */ + const __m128i xe3 = _mm_loadu_si128(argbEven++); /* 3rd 4 pixels */ + const __m128i xe4 = _mm_loadu_si128(argbEven++); /* 4th 4 pixels */ + const __m128i xo1 = _mm_loadu_si128(argbOdd++); /* 1st 4 pixels */ + const __m128i xo2 = _mm_loadu_si128(argbOdd++); /* 2nd 4 pixels */ + const __m128i xo3 = _mm_loadu_si128(argbOdd++); /* 3rd 4 pixels */ + const __m128i xo4 = _mm_loadu_si128(argbOdd++); /* 4th 4 pixels */ + { + /* Y: multiplications with subtotals and horizontal sums */ + const __m128i y_factors = BGRX_Y_FACTORS; + const __m128i ye1 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe1, y_factors), + _mm_maddubs_epi16(xe2, y_factors)), + Y_SHIFT); + const __m128i ye2 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe3, y_factors), + _mm_maddubs_epi16(xe4, y_factors)), + Y_SHIFT); + const __m128i ye = _mm_packus_epi16(ye1, ye2); + /* store y [b1] */ + _mm_storeu_si128((__m128i*)yLumaDstEven, ye); + yLumaDstEven += 16; + } + + if (yLumaDstOdd) + { + const __m128i y_factors = BGRX_Y_FACTORS; + const __m128i yo1 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo1, y_factors), + _mm_maddubs_epi16(xo2, y_factors)), + Y_SHIFT); + const __m128i yo2 = _mm_srli_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo3, y_factors), + _mm_maddubs_epi16(xo4, y_factors)), + Y_SHIFT); + const __m128i yo = _mm_packus_epi16(yo1, yo2); + _mm_storeu_si128((__m128i*)yLumaDstOdd, yo); + yLumaDstOdd += 16; + } + + { + /* We have now + * 16 even U values in ue + * 16 odd U values in uo + * + * We need to split these according to + * 3.3.8.3.3 YUV420p Stream Combination for YUV444v2 mode */ + /* U: multiplications with subtotals and horizontal sums */ + __m128i ue; + __m128i uo; + __m128i uavg; + { + const __m128i u_factors = BGRX_U_FACTORS; + const __m128i ue1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe1, u_factors), + _mm_maddubs_epi16(xe2, u_factors)), + U_SHIFT); + const __m128i ue2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe3, u_factors), + _mm_maddubs_epi16(xe4, u_factors)), + U_SHIFT); + const __m128i ueavg = _mm_hadd_epi16(ue1, ue2); + ue = _mm_sub_epi8(_mm_packs_epi16(ue1, ue2), vector128); + uavg = ueavg; + } + { + const __m128i u_factors = BGRX_U_FACTORS; + const __m128i uo1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo1, u_factors), + _mm_maddubs_epi16(xo2, u_factors)), + U_SHIFT); + const __m128i uo2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo3, u_factors), + _mm_maddubs_epi16(xo4, u_factors)), + U_SHIFT); + const __m128i uoavg = _mm_hadd_epi16(uo1, uo2); + uo = _mm_sub_epi8(_mm_packs_epi16(uo1, uo2), vector128); + uavg = _mm_add_epi16(uavg, uoavg); + uavg = _mm_srai_epi16(uavg, 2); + uavg = _mm_packs_epi16(uavg, uoavg); + uavg = _mm_sub_epi8(uavg, vector128); + } + /* Now we need the following storage distribution: + * 2x 2y -> uLumaDst + * 2x+1 y -> yChromaDst1 + * 4x 2y+1 -> uChromaDst1 + * 4x+2 2y+1 -> vChromaDst1 */ + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 15, 13, 11, 9, 7, 5, 3, 1); + const __m128i ude = _mm_shuffle_epi8(ue, mask); + _mm_storel_epi64((__m128i*)yEvenChromaDst1, ude); + yEvenChromaDst1 += 8; + } + + if (yLumaDstOdd) + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 15, 13, 11, 9, 7, 5, 3, 1); + const __m128i udo /* codespell:ignore udo */ = _mm_shuffle_epi8(uo, mask); + _mm_storel_epi64((__m128i*)yOddChromaDst1, udo); // codespell:ignore udo + yOddChromaDst1 += 8; + } + + if (yLumaDstOdd) + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 14, 10, 6, 2, 12, 8, 4, 0); + const __m128i ud = _mm_shuffle_epi8(uo, mask); + int* uDst1 = (int*)uChromaDst1; + int* vDst1 = (int*)vChromaDst1; + const int* src = (const int*)&ud; + _mm_stream_si32(uDst1, src[0]); + _mm_stream_si32(vDst1, src[1]); + uChromaDst1 += 4; + vChromaDst1 += 4; + } + + if (yLumaDstOdd) + { + _mm_storel_epi64((__m128i*)uLumaDst, uavg); + uLumaDst += 8; + } + else + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 14, 12, 10, 8, 6, 4, 2, 0); + const __m128i ud = _mm_shuffle_epi8(ue, mask); + _mm_storel_epi64((__m128i*)uLumaDst, ud); + uLumaDst += 8; + } + } + + { + /* V: multiplications with subtotals and horizontal sums */ + __m128i ve; + __m128i vo; + __m128i vavg; + { + const __m128i v_factors = BGRX_V_FACTORS; + const __m128i ve1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe1, v_factors), + _mm_maddubs_epi16(xe2, v_factors)), + V_SHIFT); + const __m128i ve2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xe3, v_factors), + _mm_maddubs_epi16(xe4, v_factors)), + V_SHIFT); + const __m128i veavg = _mm_hadd_epi16(ve1, ve2); + ve = _mm_sub_epi8(_mm_packs_epi16(ve1, ve2), vector128); + vavg = veavg; + } + { + const __m128i v_factors = BGRX_V_FACTORS; + const __m128i vo1 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo1, v_factors), + _mm_maddubs_epi16(xo2, v_factors)), + V_SHIFT); + const __m128i vo2 = + _mm_srai_epi16(_mm_hadd_epi16(_mm_maddubs_epi16(xo3, v_factors), + _mm_maddubs_epi16(xo4, v_factors)), + V_SHIFT); + const __m128i voavg = _mm_hadd_epi16(vo1, vo2); + vo = _mm_sub_epi8(_mm_packs_epi16(vo1, vo2), vector128); + vavg = _mm_add_epi16(vavg, voavg); + vavg = _mm_srai_epi16(vavg, 2); + vavg = _mm_packs_epi16(vavg, voavg); + vavg = _mm_sub_epi8(vavg, vector128); + } + /* Now we need the following storage distribution: + * 2x 2y -> vLumaDst + * 2x+1 y -> yChromaDst2 + * 4x 2y+1 -> uChromaDst2 + * 4x+2 2y+1 -> vChromaDst2 */ + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 15, 13, 11, 9, 7, 5, 3, 1); + __m128i vde = _mm_shuffle_epi8(ve, mask); + _mm_storel_epi64((__m128i*)yEvenChromaDst2, vde); + yEvenChromaDst2 += 8; + } + + if (yLumaDstOdd) + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 15, 13, 11, 9, 7, 5, 3, 1); + __m128i vdo = _mm_shuffle_epi8(vo, mask); + _mm_storel_epi64((__m128i*)yOddChromaDst2, vdo); + yOddChromaDst2 += 8; + } + + if (yLumaDstOdd) + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 14, 10, 6, 2, 12, 8, 4, 0); + const __m128i vd = _mm_shuffle_epi8(vo, mask); + int* uDst2 = (int*)uChromaDst2; + int* vDst2 = (int*)vChromaDst2; + const int* src = (const int*)&vd; + _mm_stream_si32(uDst2, src[0]); + _mm_stream_si32(vDst2, src[1]); + uChromaDst2 += 4; + vChromaDst2 += 4; + } + + if (yLumaDstOdd) + { + _mm_storel_epi64((__m128i*)vLumaDst, vavg); + vLumaDst += 8; + } + else + { + const __m128i mask = + _mm_set_epi8((char)0x80, (char)0x80, (char)0x80, (char)0x80, (char)0x80, + (char)0x80, (char)0x80, (char)0x80, 14, 12, 10, 8, 6, 4, 2, 0); + __m128i vd = _mm_shuffle_epi8(ve, mask); + _mm_storel_epi64((__m128i*)vLumaDst, vd); + vLumaDst += 8; + } + } + } + + general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(x, srcEven, srcOdd, yLumaDstEven, yLumaDstOdd, + uLumaDst, vLumaDst, yEvenChromaDst1, yEvenChromaDst2, + yOddChromaDst1, yOddChromaDst2, uChromaDst1, + uChromaDst2, vChromaDst1, vChromaDst2, width); +} + +static pstatus_t sse41_RGBToAVC444YUVv2_BGRX(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[], + const UINT32 dst1Step[], BYTE* WINPR_RESTRICT pDst2[], + const UINT32 dst2Step[], + const prim_size_t* WINPR_RESTRICT roi) +{ + if (roi->height < 1 || roi->width < 1) + return !PRIMITIVES_SUCCESS; + + size_t y = 0; + for (; y < roi->height - roi->height % 2; y += 2) + { + const BYTE* srcEven = (pSrc + y * srcStep); + const BYTE* srcOdd = (srcEven + srcStep); + BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]); + BYTE* dstLumaYOdd = (dstLumaYEven + dst1Step[0]); + BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]); + BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]); + BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]); + BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2; + BYTE* dstOddChromaY1 = dstEvenChromaY1 + dst2Step[0]; + BYTE* dstOddChromaY2 = dstEvenChromaY2 + dst2Step[0]; + BYTE* dstChromaU1 = (pDst2[1] + (y / 2) * dst2Step[1]); + BYTE* dstChromaV1 = (pDst2[2] + (y / 2) * dst2Step[2]); + BYTE* dstChromaU2 = dstChromaU1 + roi->width / 4; + BYTE* dstChromaV2 = dstChromaV1 + roi->width / 4; + sse41_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(srcEven, srcOdd, dstLumaYEven, dstLumaYOdd, dstLumaU, + dstLumaV, dstEvenChromaY1, dstEvenChromaY2, + dstOddChromaY1, dstOddChromaY2, dstChromaU1, + dstChromaU2, dstChromaV1, dstChromaV2, roi->width); + } + + for (; y < roi->height; y++) + { + const BYTE* srcEven = (pSrc + y * srcStep); + BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]); + BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]); + BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]); + BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]); + BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2; + BYTE* dstChromaU1 = (pDst2[1] + (y / 2) * dst2Step[1]); + BYTE* dstChromaV1 = (pDst2[2] + (y / 2) * dst2Step[2]); + BYTE* dstChromaU2 = dstChromaU1 + roi->width / 4; + BYTE* dstChromaV2 = dstChromaV1 + roi->width / 4; + general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(0, srcEven, NULL, dstLumaYEven, NULL, dstLumaU, + dstLumaV, dstEvenChromaY1, dstEvenChromaY2, NULL, + NULL, dstChromaU1, dstChromaU2, dstChromaV1, + dstChromaV2, roi->width); + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_RGBToAVC444YUVv2(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, + UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[], + const UINT32 dst1Step[], BYTE* WINPR_RESTRICT pDst2[], + const UINT32 dst2Step[], + const prim_size_t* WINPR_RESTRICT roi) +{ + switch (srcFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return sse41_RGBToAVC444YUVv2_BGRX(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2, + dst2Step, roi); + + default: + return generic->RGBToAVC444YUVv2(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2, + dst2Step, roi); + } +} + +static pstatus_t sse41_LumaToYUV444(const BYTE* WINPR_RESTRICT pSrcRaw[], const UINT32 srcStep[], + BYTE* WINPR_RESTRICT pDstRaw[], const UINT32 dstStep[], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + const UINT32 nWidth = roi->right - roi->left; + const UINT32 nHeight = roi->bottom - roi->top; + const UINT32 halfWidth = (nWidth + 1) / 2; + const UINT32 halfPad = halfWidth % 16; + const UINT32 halfHeight = (nHeight + 1) / 2; + const UINT32 oddY = 1; + const UINT32 evenY = 0; + const UINT32 oddX = 1; + const UINT32 evenX = 0; + const BYTE* pSrc[3] = { pSrcRaw[0] + 1ULL * roi->top * srcStep[0] + roi->left, + pSrcRaw[1] + 1ULL * roi->top / 2 * srcStep[1] + roi->left / 2, + pSrcRaw[2] + 1ULL * roi->top / 2 * srcStep[2] + roi->left / 2 }; + BYTE* pDst[3] = { pDstRaw[0] + 1ULL * roi->top * dstStep[0] + roi->left, + pDstRaw[1] + 1ULL * roi->top * dstStep[1] + roi->left, + pDstRaw[2] + 1ULL * roi->top * dstStep[2] + roi->left }; + + /* Y data is already here... */ + /* B1 */ + for (size_t y = 0; y < nHeight; y++) + { + const BYTE* Ym = pSrc[0] + y * srcStep[0]; + BYTE* pY = pDst[0] + y * dstStep[0]; + memcpy(pY, Ym, nWidth); + } + + /* The first half of U, V are already here part of this frame. */ + /* B2 and B3 */ + for (size_t y = 0; y < halfHeight; y++) + { + const size_t val2y = (2 * y + evenY); + const size_t val2y1 = val2y + oddY; + const BYTE* Um = pSrc[1] + 1ULL * srcStep[1] * y; + const BYTE* Vm = pSrc[2] + 1ULL * srcStep[2] * y; + BYTE* pU = pDst[1] + 1ULL * dstStep[1] * val2y; + BYTE* pV = pDst[2] + 1ULL * dstStep[2] * val2y; + BYTE* pU1 = pDst[1] + 1ULL * dstStep[1] * val2y1; + BYTE* pV1 = pDst[2] + 1ULL * dstStep[2] * val2y1; + + size_t x = 0; + for (; x < halfWidth - halfPad; x += 16) + { + const __m128i unpackHigh = _mm_set_epi8(7, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0); + const __m128i unpackLow = + _mm_set_epi8(15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8); + { + const __m128i u = _mm_loadu_si128((const __m128i*)&Um[x]); + const __m128i uHigh = _mm_shuffle_epi8(u, unpackHigh); + const __m128i uLow = _mm_shuffle_epi8(u, unpackLow); + _mm_storeu_si128((__m128i*)&pU[2ULL * x], uHigh); + _mm_storeu_si128((__m128i*)&pU[2ULL * x + 16], uLow); + _mm_storeu_si128((__m128i*)&pU1[2ULL * x], uHigh); + _mm_storeu_si128((__m128i*)&pU1[2ULL * x + 16], uLow); + } + { + const __m128i u = _mm_loadu_si128((const __m128i*)&Vm[x]); + const __m128i uHigh = _mm_shuffle_epi8(u, unpackHigh); + const __m128i uLow = _mm_shuffle_epi8(u, unpackLow); + _mm_storeu_si128((__m128i*)&pV[2 * x], uHigh); + _mm_storeu_si128((__m128i*)&pV[2 * x + 16], uLow); + _mm_storeu_si128((__m128i*)&pV1[2 * x], uHigh); + _mm_storeu_si128((__m128i*)&pV1[2 * x + 16], uLow); + } + } + + for (; x < halfWidth; x++) + { + const size_t val2x = 2 * x + evenX; + const size_t val2x1 = val2x + oddX; + pU[val2x] = Um[x]; + pV[val2x] = Vm[x]; + pU[val2x1] = Um[x]; + pV[val2x1] = Vm[x]; + pU1[val2x] = Um[x]; + pV1[val2x] = Vm[x]; + pU1[val2x1] = Um[x]; + pV1[val2x1] = Vm[x]; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_ChromaV1ToYUV444(const BYTE* WINPR_RESTRICT pSrcRaw[3], + const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDstRaw[3], + const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + const UINT32 mod = 16; + UINT32 uY = 0; + UINT32 vY = 0; + const UINT32 nWidth = roi->right - roi->left; + const UINT32 nHeight = roi->bottom - roi->top; + const UINT32 halfWidth = (nWidth + 1) / 2; + const UINT32 halfPad = halfWidth % 16; + const UINT32 halfHeight = (nHeight + 1) / 2; + const UINT32 oddY = 1; + const UINT32 evenY = 0; + const UINT32 oddX = 1; + /* The auxiliary frame is aligned to multiples of 16x16. + * We need the padded height for B4 and B5 conversion. */ + const UINT32 padHeigth = nHeight + 16 - nHeight % 16; + const BYTE* pSrc[3] = { pSrcRaw[0] + 1ULL * roi->top * srcStep[0] + roi->left, + pSrcRaw[1] + 1ULL * roi->top / 2 * srcStep[1] + roi->left / 2, + pSrcRaw[2] + 1ULL * roi->top / 2 * srcStep[2] + roi->left / 2 }; + BYTE* pDst[3] = { pDstRaw[0] + 1ULL * roi->top * dstStep[0] + roi->left, + pDstRaw[1] + 1ULL * roi->top * dstStep[1] + roi->left, + pDstRaw[2] + 1ULL * roi->top * dstStep[2] + roi->left }; + const __m128i zero = _mm_setzero_si128(); + const __m128i mask = _mm_set_epi8(0, (char)0x80, 0, (char)0x80, 0, (char)0x80, 0, (char)0x80, 0, + (char)0x80, 0, (char)0x80, 0, (char)0x80, 0, (char)0x80); + + /* The second half of U and V is a bit more tricky... */ + /* B4 and B5 */ + for (size_t y = 0; y < padHeigth; y++) + { + const BYTE* Ya = pSrc[0] + 1ULL * srcStep[0] * y; + BYTE* pX = NULL; + + if ((y) % mod < (mod + 1) / 2) + { + const UINT32 pos = (2 * uY++ + oddY); + + if (pos >= nHeight) + continue; + + pX = pDst[1] + 1ULL * dstStep[1] * pos; + } + else + { + const UINT32 pos = (2 * vY++ + oddY); + + if (pos >= nHeight) + continue; + + pX = pDst[2] + 1ULL * dstStep[2] * pos; + } + + memcpy(pX, Ya, nWidth); + } + + /* B6 and B7 */ + for (size_t y = 0; y < halfHeight; y++) + { + const size_t val2y = (y * 2 + evenY); + const BYTE* Ua = pSrc[1] + srcStep[1] * y; + const BYTE* Va = pSrc[2] + srcStep[2] * y; + BYTE* pU = pDst[1] + dstStep[1] * val2y; + BYTE* pV = pDst[2] + dstStep[2] * val2y; + + size_t x = 0; + for (; x < halfWidth - halfPad; x += 16) + { + { + const __m128i u = _mm_loadu_si128((const __m128i*)&Ua[x]); + const __m128i u2 = _mm_unpackhi_epi8(u, zero); + const __m128i u1 = _mm_unpacklo_epi8(u, zero); + _mm_maskmoveu_si128(u1, mask, (char*)&pU[2 * x]); + _mm_maskmoveu_si128(u2, mask, (char*)&pU[2 * x + 16]); + } + { + const __m128i u = _mm_loadu_si128((const __m128i*)&Va[x]); + const __m128i u2 = _mm_unpackhi_epi8(u, zero); + const __m128i u1 = _mm_unpacklo_epi8(u, zero); + _mm_maskmoveu_si128(u1, mask, (char*)&pV[2 * x]); + _mm_maskmoveu_si128(u2, mask, (char*)&pV[2 * x + 16]); + } + } + + for (; x < halfWidth; x++) + { + const size_t val2x1 = (x * 2ULL + oddX); + pU[val2x1] = Ua[x]; + pV[val2x1] = Va[x]; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_ChromaV2ToYUV444(const BYTE* WINPR_RESTRICT pSrc[3], const UINT32 srcStep[3], + UINT32 nTotalWidth, UINT32 nTotalHeight, + BYTE* WINPR_RESTRICT pDst[3], const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + const UINT32 nWidth = roi->right - roi->left; + const UINT32 nHeight = roi->bottom - roi->top; + const UINT32 halfWidth = (nWidth + 1) / 2; + const UINT32 halfPad = halfWidth % 16; + const UINT32 halfHeight = (nHeight + 1) / 2; + const UINT32 quaterWidth = (nWidth + 3) / 4; + const UINT32 quaterPad = quaterWidth % 16; + const __m128i zero = _mm_setzero_si128(); + const __m128i mask = _mm_set_epi8((char)0x80, 0, (char)0x80, 0, (char)0x80, 0, (char)0x80, 0, + (char)0x80, 0, (char)0x80, 0, (char)0x80, 0, (char)0x80, 0); + const __m128i mask2 = _mm_set_epi8(0, (char)0x80, 0, (char)0x80, 0, (char)0x80, 0, (char)0x80, + 0, (char)0x80, 0, (char)0x80, 0, (char)0x80, 0, (char)0x80); + const __m128i shuffle1 = + _mm_set_epi8((char)0x80, 15, (char)0x80, 14, (char)0x80, 13, (char)0x80, 12, (char)0x80, 11, + (char)0x80, 10, (char)0x80, 9, (char)0x80, 8); + const __m128i shuffle2 = + _mm_set_epi8((char)0x80, 7, (char)0x80, 6, (char)0x80, 5, (char)0x80, 4, (char)0x80, 3, + (char)0x80, 2, (char)0x80, 1, (char)0x80, 0); + + /* B4 and B5: odd UV values for width/2, height */ + for (size_t y = 0; y < nHeight; y++) + { + const size_t yTop = y + roi->top; + const BYTE* pYaU = pSrc[0] + srcStep[0] * yTop + roi->left / 2; + const BYTE* pYaV = pYaU + nTotalWidth / 2; + BYTE* pU = pDst[1] + 1ULL * dstStep[1] * yTop + roi->left; + BYTE* pV = pDst[2] + 1ULL * dstStep[2] * yTop + roi->left; + + size_t x = 0; + for (; x < halfWidth - halfPad; x += 16) + { + { + const __m128i u = _mm_loadu_si128((const __m128i*)&pYaU[x]); + const __m128i u2 = _mm_unpackhi_epi8(zero, u); + const __m128i u1 = _mm_unpacklo_epi8(zero, u); + _mm_maskmoveu_si128(u1, mask, (char*)&pU[2 * x]); + _mm_maskmoveu_si128(u2, mask, (char*)&pU[2 * x + 16]); + } + { + const __m128i v = _mm_loadu_si128((const __m128i*)&pYaV[x]); + const __m128i v2 = _mm_unpackhi_epi8(zero, v); + const __m128i v1 = _mm_unpacklo_epi8(zero, v); + _mm_maskmoveu_si128(v1, mask, (char*)&pV[2 * x]); + _mm_maskmoveu_si128(v2, mask, (char*)&pV[2 * x + 16]); + } + } + + for (; x < halfWidth; x++) + { + const size_t odd = 2ULL * x + 1; + pU[odd] = pYaU[x]; + pV[odd] = pYaV[x]; + } + } + + /* B6 - B9 */ + for (size_t y = 0; y < halfHeight; y++) + { + const BYTE* pUaU = pSrc[1] + srcStep[1] * (y + roi->top / 2) + roi->left / 4; + const BYTE* pUaV = pUaU + nTotalWidth / 4; + const BYTE* pVaU = pSrc[2] + srcStep[2] * (y + roi->top / 2) + roi->left / 4; + const BYTE* pVaV = pVaU + nTotalWidth / 4; + BYTE* pU = pDst[1] + dstStep[1] * (2 * y + 1 + roi->top) + roi->left; + BYTE* pV = pDst[2] + dstStep[2] * (2 * y + 1 + roi->top) + roi->left; + + UINT32 x = 0; + for (; x < quaterWidth - quaterPad; x += 16) + { + { + const __m128i uU = _mm_loadu_si128((const __m128i*)&pUaU[x]); + const __m128i uV = _mm_loadu_si128((const __m128i*)&pVaU[x]); + const __m128i uHigh = _mm_unpackhi_epi8(uU, uV); + const __m128i uLow = _mm_unpacklo_epi8(uU, uV); + const __m128i u1 = _mm_shuffle_epi8(uLow, shuffle2); + const __m128i u2 = _mm_shuffle_epi8(uLow, shuffle1); + const __m128i u3 = _mm_shuffle_epi8(uHigh, shuffle2); + const __m128i u4 = _mm_shuffle_epi8(uHigh, shuffle1); + _mm_maskmoveu_si128(u1, mask2, (char*)&pU[4 * x + 0]); + _mm_maskmoveu_si128(u2, mask2, (char*)&pU[4 * x + 16]); + _mm_maskmoveu_si128(u3, mask2, (char*)&pU[4 * x + 32]); + _mm_maskmoveu_si128(u4, mask2, (char*)&pU[4 * x + 48]); + } + { + const __m128i vU = _mm_loadu_si128((const __m128i*)&pUaV[x]); + const __m128i vV = _mm_loadu_si128((const __m128i*)&pVaV[x]); + const __m128i vHigh = _mm_unpackhi_epi8(vU, vV); + const __m128i vLow = _mm_unpacklo_epi8(vU, vV); + const __m128i v1 = _mm_shuffle_epi8(vLow, shuffle2); + const __m128i v2 = _mm_shuffle_epi8(vLow, shuffle1); + const __m128i v3 = _mm_shuffle_epi8(vHigh, shuffle2); + const __m128i v4 = _mm_shuffle_epi8(vHigh, shuffle1); + _mm_maskmoveu_si128(v1, mask2, (char*)&pV[4 * x + 0]); + _mm_maskmoveu_si128(v2, mask2, (char*)&pV[4 * x + 16]); + _mm_maskmoveu_si128(v3, mask2, (char*)&pV[4 * x + 32]); + _mm_maskmoveu_si128(v4, mask2, (char*)&pV[4 * x + 48]); + } + } + + for (; x < quaterWidth; x++) + { + pU[4 * x + 0] = pUaU[x]; + pV[4 * x + 0] = pUaV[x]; + pU[4 * x + 2] = pVaU[x]; + pV[4 * x + 2] = pVaV[x]; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse41_YUV420CombineToYUV444(avc444_frame_type type, + const BYTE* WINPR_RESTRICT pSrc[3], + const UINT32 srcStep[3], UINT32 nWidth, UINT32 nHeight, + BYTE* WINPR_RESTRICT pDst[3], const UINT32 dstStep[3], + const RECTANGLE_16* WINPR_RESTRICT roi) +{ + if (!pSrc || !pSrc[0] || !pSrc[1] || !pSrc[2]) + return -1; + + if (!pDst || !pDst[0] || !pDst[1] || !pDst[2]) + return -1; + + if (!roi) + return -1; + + switch (type) + { + case AVC444_LUMA: + return sse41_LumaToYUV444(pSrc, srcStep, pDst, dstStep, roi); + + case AVC444_CHROMAv1: + return sse41_ChromaV1ToYUV444(pSrc, srcStep, pDst, dstStep, roi); + + case AVC444_CHROMAv2: + return sse41_ChromaV2ToYUV444(pSrc, srcStep, nWidth, nHeight, pDst, dstStep, roi); + + default: + return -1; + } +} +#endif + +void primitives_init_YUV_sse41(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_YUV(prims); + + if (IsProcessorFeaturePresentEx(PF_EX_SSE41) && + IsProcessorFeaturePresent(PF_SSE4_1_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE3/sse41 optimizations"); + prims->RGBToYUV420_8u_P3AC4R = sse41_RGBToYUV420; + prims->RGBToAVC444YUV = sse41_RGBToAVC444YUV; + prims->RGBToAVC444YUVv2 = sse41_RGBToAVC444YUVv2; + prims->YUV420ToRGB_8u_P3AC4R = sse41_YUV420ToRGB; + prims->YUV444ToRGB_8u_P3AC4R = sse41_YUV444ToRGB_8u_P3AC4R; + prims->YUV420CombineToYUV444 = sse41_YUV420CombineToYUV444; + } +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or sse41 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_add_sse3.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_add_sse3.c new file mode 100644 index 0000000000000000000000000000000000000000..24e17b3020d3977d7b95465bad1a895150e8afe6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_add_sse3.c @@ -0,0 +1,192 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized add operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ + +#include + +#include +#include +#include + +#include "prim_add.h" + +#include "prim_internal.h" +#include "prim_templates.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include + +static primitives_t* generic = NULL; + +/* ------------------------------------------------------------------------- */ +SSE3_SSD_ROUTINE(sse3_add_16s, INT16, generic->add_16s, _mm_adds_epi16, + generic->add_16s(sptr1++, sptr2++, dptr++, 1)) + +static pstatus_t sse3_add_16s_inplace(INT16* WINPR_RESTRICT pSrcDst1, + INT16* WINPR_RESTRICT pSrcDst2, UINT32 len) +{ + const int shifts = 2; + INT16* dptr1 = pSrcDst1; + INT16* dptr2 = pSrcDst2; + + if (len < 16) /* pointless if too small */ + return generic->add_16s_inplace(pSrcDst1, pSrcDst2, len); + + UINT32 offBeatMask = (1 << (shifts - 1)) - 1; + if ((ULONG_PTR)pSrcDst1 & offBeatMask) + { + /* Incrementing the pointer skips over 16-byte boundary. */ + return generic->add_16s_inplace(pSrcDst1, pSrcDst2, len); + } + /* Get to the 16-byte boundary now. */ + const size_t rem = ((UINT_PTR)dptr1 & 0xf) / sizeof(INT16); + if (rem != 0) + { + const UINT32 add = 16 - (UINT32)rem; + pstatus_t status = generic->add_16s_inplace(dptr1, dptr2, add); + if (status != PRIMITIVES_SUCCESS) + return status; + dptr1 += add; + dptr2 += add; + } + /* Use 4 128-bit SSE registers. */ + size_t count = len >> (7 - shifts); + len -= count << (7 - shifts); + if (((const ULONG_PTR)dptr1 & 0x0f) || ((const ULONG_PTR)dptr2 & 0x0f)) + { + /* Unaligned loads */ + while (count--) + { + const __m128i* vsptr1 = (const __m128i*)dptr1; + const __m128i* vsptr2 = (const __m128i*)dptr2; + __m128i* vdptr1 = (__m128i*)dptr1; + __m128i* vdptr2 = (__m128i*)dptr2; + + __m128i xmm0 = _mm_lddqu_si128(vsptr1++); + __m128i xmm1 = _mm_lddqu_si128(vsptr1++); + __m128i xmm2 = _mm_lddqu_si128(vsptr1++); + __m128i xmm3 = _mm_lddqu_si128(vsptr1++); + __m128i xmm4 = _mm_lddqu_si128(vsptr2++); + __m128i xmm5 = _mm_lddqu_si128(vsptr2++); + __m128i xmm6 = _mm_lddqu_si128(vsptr2++); + __m128i xmm7 = _mm_lddqu_si128(vsptr2++); + + xmm0 = _mm_adds_epi16(xmm0, xmm4); + xmm1 = _mm_adds_epi16(xmm1, xmm5); + xmm2 = _mm_adds_epi16(xmm2, xmm6); + xmm3 = _mm_adds_epi16(xmm3, xmm7); + + _mm_store_si128(vdptr1++, xmm0); + _mm_store_si128(vdptr1++, xmm1); + _mm_store_si128(vdptr1++, xmm2); + _mm_store_si128(vdptr1++, xmm3); + + _mm_store_si128(vdptr2++, xmm0); + _mm_store_si128(vdptr2++, xmm1); + _mm_store_si128(vdptr2++, xmm2); + _mm_store_si128(vdptr2++, xmm3); + + dptr1 = (INT16*)vdptr1; + dptr2 = (INT16*)vdptr2; + } + } + else + { + /* Aligned loads */ + while (count--) + { + const __m128i* vsptr1 = (const __m128i*)dptr1; + const __m128i* vsptr2 = (const __m128i*)dptr2; + __m128i* vdptr1 = (__m128i*)dptr1; + __m128i* vdptr2 = (__m128i*)dptr2; + + __m128i xmm0 = _mm_load_si128(vsptr1++); + __m128i xmm1 = _mm_load_si128(vsptr1++); + __m128i xmm2 = _mm_load_si128(vsptr1++); + __m128i xmm3 = _mm_load_si128(vsptr1++); + __m128i xmm4 = _mm_load_si128(vsptr2++); + __m128i xmm5 = _mm_load_si128(vsptr2++); + __m128i xmm6 = _mm_load_si128(vsptr2++); + __m128i xmm7 = _mm_load_si128(vsptr2++); + + xmm0 = _mm_adds_epi16(xmm0, xmm4); + xmm1 = _mm_adds_epi16(xmm1, xmm5); + xmm2 = _mm_adds_epi16(xmm2, xmm6); + xmm3 = _mm_adds_epi16(xmm3, xmm7); + + _mm_store_si128(vdptr1++, xmm0); + _mm_store_si128(vdptr1++, xmm1); + _mm_store_si128(vdptr1++, xmm2); + _mm_store_si128(vdptr1++, xmm3); + + _mm_store_si128(vdptr2++, xmm0); + _mm_store_si128(vdptr2++, xmm1); + _mm_store_si128(vdptr2++, xmm2); + _mm_store_si128(vdptr2++, xmm3); + + dptr1 = (INT16*)vdptr1; + dptr2 = (INT16*)vdptr2; + } + } + /* Use a single 128-bit SSE register. */ + count = len >> (5 - shifts); + len -= count << (5 - shifts); + while (count--) + { + const __m128i* vsptr1 = (const __m128i*)dptr1; + const __m128i* vsptr2 = (const __m128i*)dptr2; + __m128i* vdptr1 = (__m128i*)dptr1; + __m128i* vdptr2 = (__m128i*)dptr2; + + __m128i xmm0 = LOAD_SI128(vsptr1); + __m128i xmm1 = LOAD_SI128(vsptr2); + + xmm0 = _mm_adds_epi16(xmm0, xmm1); + + _mm_store_si128(vdptr1++, xmm0); + _mm_store_si128(vdptr2++, xmm0); + + dptr1 = (INT16*)vdptr1; + dptr2 = (INT16*)vdptr2; + } + /* Finish off the remainder. */ + if (len > 0) + return generic->add_16s_inplace(dptr1, dptr2, len); + + return PRIMITIVES_SUCCESS; +} +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_add_sse3(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_add(prims); + + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) && + IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) /* for LDDQU */ + { + WLog_VRB(PRIM_TAG, "SSE2/SSE3 optimizations"); + prims->add_16s = sse3_add_16s; + prims->add_16s_inplace = sse3_add_16s_inplace; + } + +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE3 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_alphaComp_sse3.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_alphaComp_sse3.c new file mode 100644 index 0000000000000000000000000000000000000000..d945b4733e61b415d40366e605a5b4c04fb4b22a --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_alphaComp_sse3.c @@ -0,0 +1,220 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized alpha blending routines. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + * Note: this code assumes the second operand is fully opaque, + * e.g. + * newval = alpha1*val1 + (1-alpha1)*val2 + * rather than + * newval = alpha1*val1 + (1-alpha1)*alpha2*val2 + * The IPP gives other options. + */ + +#include + +#include +#include +#include + +#include "prim_alphaComp.h" + +#include "prim_internal.h" + +/* ------------------------------------------------------------------------- */ +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include + +static primitives_t* generic = NULL; + +static pstatus_t sse2_alphaComp_argb(const BYTE* WINPR_RESTRICT pSrc1, UINT32 src1Step, + const BYTE* WINPR_RESTRICT pSrc2, UINT32 src2Step, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, UINT32 width, + UINT32 height) +{ + const UINT32* sptr1 = (const UINT32*)pSrc1; + const UINT32* sptr2 = (const UINT32*)pSrc2; + + if ((width <= 0) || (height <= 0)) + return PRIMITIVES_SUCCESS; + + if (width < 4) /* pointless if too small */ + { + return generic->alphaComp_argb(pSrc1, src1Step, pSrc2, src2Step, pDst, dstStep, width, + height); + } + + UINT32* dptr = (UINT32*)pDst; + const size_t linebytes = width * sizeof(UINT32); + const size_t src1Jump = (src1Step - linebytes) / sizeof(UINT32); + const size_t src2Jump = (src2Step - linebytes) / sizeof(UINT32); + const size_t dstJump = (dstStep - linebytes) / sizeof(UINT32); + __m128i xmm0 = mm_set1_epu32(0); + __m128i xmm1 = _mm_set1_epi16(1); + + for (UINT32 y = 0; y < height; ++y) + { + uint32_t pixels = width; + uint32_t count = 0; + /* Get to the 16-byte boundary now. */ + uint32_t leadIn = 0; + + switch ((ULONG_PTR)dptr & 0x0f) + { + case 0: + leadIn = 0; + break; + + case 4: + leadIn = 3; + break; + + case 8: + leadIn = 2; + break; + + case 12: + leadIn = 1; + break; + + default: + /* We'll never hit a 16-byte boundary, so do the whole + * thing the slow way. + */ + leadIn = width; + break; + } + + if (leadIn) + { + pstatus_t status = 0; + status = generic->alphaComp_argb((const BYTE*)sptr1, src1Step, (const BYTE*)sptr2, + src2Step, (BYTE*)dptr, dstStep, leadIn, 1); + if (status != PRIMITIVES_SUCCESS) + return status; + + sptr1 += leadIn; + sptr2 += leadIn; + dptr += leadIn; + pixels -= leadIn; + } + + /* Use SSE registers to do 4 pixels at a time. */ + count = pixels >> 2; + pixels -= count << 2; + + while (count--) + { + __m128i xmm2; + __m128i xmm3; + __m128i xmm4; + __m128i xmm5; + __m128i xmm6; + __m128i xmm7; + /* BdGdRdAdBcGcRcAcBbGbRbAbBaGaRaAa */ + xmm2 = LOAD_SI128(sptr1); + sptr1 += 4; + /* BhGhRhAhBgGgRgAgBfGfRfAfBeGeReAe */ + xmm3 = LOAD_SI128(sptr2); + sptr2 += 4; + /* 00Bb00Gb00Rb00Ab00Ba00Ga00Ra00Aa */ + xmm4 = _mm_unpackhi_epi8(xmm2, xmm0); + /* 00Bf00Gf00Bf00Af00Be00Ge00Re00Ae */ + xmm5 = _mm_unpackhi_epi8(xmm3, xmm0); + /* subtract */ + xmm6 = _mm_subs_epi16(xmm4, xmm5); + /* 00Bb00Gb00Rb00Ab00Aa00Aa00Aa00Aa */ + xmm4 = _mm_shufflelo_epi16(xmm4, 0xff); + /* 00Ab00Ab00Ab00Ab00Aa00Aa00Aa00Aa */ + xmm4 = _mm_shufflehi_epi16(xmm4, 0xff); + /* Add one to alphas */ + xmm4 = _mm_adds_epi16(xmm4, xmm1); + /* Multiply and take low word */ + xmm4 = _mm_mullo_epi16(xmm4, xmm6); + /* Shift 8 right */ + xmm4 = _mm_srai_epi16(xmm4, 8); + /* Add xmm5 */ + xmm4 = _mm_adds_epi16(xmm4, xmm5); + /* 00Bj00Gj00Rj00Aj00Bi00Gi00Ri00Ai */ + /* 00Bd00Gd00Rd00Ad00Bc00Gc00Rc00Ac */ + xmm5 = _mm_unpacklo_epi8(xmm2, xmm0); + /* 00Bh00Gh00Rh00Ah00Bg00Gg00Rg00Ag */ + xmm6 = _mm_unpacklo_epi8(xmm3, xmm0); + /* subtract */ + xmm7 = _mm_subs_epi16(xmm5, xmm6); + /* 00Bd00Gd00Rd00Ad00Ac00Ac00Ac00Ac */ + xmm5 = _mm_shufflelo_epi16(xmm5, 0xff); + /* 00Ad00Ad00Ad00Ad00Ac00Ac00Ac00Ac */ + xmm5 = _mm_shufflehi_epi16(xmm5, 0xff); + /* Add one to alphas */ + xmm5 = _mm_adds_epi16(xmm5, xmm1); + /* Multiply and take low word */ + xmm5 = _mm_mullo_epi16(xmm5, xmm7); + /* Shift 8 right */ + xmm5 = _mm_srai_epi16(xmm5, 8); + /* Add xmm6 */ + xmm5 = _mm_adds_epi16(xmm5, xmm6); + /* 00Bl00Gl00Rl00Al00Bk00Gk00Rk0ABk */ + /* Must mask off remainders or pack gets confused */ + xmm3 = _mm_set1_epi16(0x00ffU); + xmm4 = _mm_and_si128(xmm4, xmm3); + xmm5 = _mm_and_si128(xmm5, xmm3); + /* BlGlRlAlBkGkRkAkBjGjRjAjBiGiRiAi */ + xmm5 = _mm_packus_epi16(xmm5, xmm4); + _mm_store_si128((__m128i*)dptr, xmm5); + dptr += 4; + } + + /* Finish off the remainder. */ + if (pixels) + { + pstatus_t status = 0; + status = generic->alphaComp_argb((const BYTE*)sptr1, src1Step, (const BYTE*)sptr2, + src2Step, (BYTE*)dptr, dstStep, pixels, 1); + if (status != PRIMITIVES_SUCCESS) + return status; + + sptr1 += pixels; + sptr2 += pixels; + dptr += pixels; + } + + /* Jump to next row. */ + sptr1 += src1Jump; + sptr2 += src2Jump; + dptr += dstJump; + } + + return PRIMITIVES_SUCCESS; +} +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_alphaComp_sse3(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_alphaComp(prims); + + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) && + IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) /* for LDDQU */ + { + WLog_VRB(PRIM_TAG, "SSE2/SSE3 optimizations"); + prims->alphaComp_argb = sse2_alphaComp_argb; + } + +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE3 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_andor_sse3.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_andor_sse3.c new file mode 100644 index 0000000000000000000000000000000000000000..04b485167f48d57f7c171ba1ab5208241aac7daf --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_andor_sse3.c @@ -0,0 +1,59 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized Logical operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include +#include + +#include "prim_andor.h" + +#include "prim_internal.h" +#include "prim_templates.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include + +static primitives_t* generic = NULL; + +/* ------------------------------------------------------------------------- */ +SSE3_SCD_PRE_ROUTINE(sse3_andC_32u, UINT32, generic->andC_32u, _mm_and_si128, + *dptr++ = *sptr++ & val) +SSE3_SCD_PRE_ROUTINE(sse3_orC_32u, UINT32, generic->orC_32u, _mm_or_si128, *dptr++ = *sptr++ | val) + +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_andor_sse3(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_andor(prims); + + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) && + IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE2/SSE3 optimizations"); + prims->andC_32u = sse3_andC_32u; + prims->orC_32u = sse3_orC_32u; + } + +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE3 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_colors_sse2.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_colors_sse2.c new file mode 100644 index 0000000000000000000000000000000000000000..171f2904d3e406181fdae230bb08fc4839c7a872 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_colors_sse2.c @@ -0,0 +1,1233 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized Color conversion operations. + * vi:ts=4 sw=4: + * + * Copyright 2011 Stephen Erisman + * Copyright 2011 Norbert Federa + * Copyright 2011 Martin Fleisz + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include +#include + +#include "prim_colors.h" + +#include "prim_internal.h" +#include "prim_templates.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include + +static primitives_t* generic = NULL; + +#ifdef __GNUC__ +#define GNU_INLINE __attribute__((__gnu_inline__, __always_inline__, __artificial__)) +#else +#define GNU_INLINE +#endif + +#define CACHE_LINE_BYTES 64 + +/* 1.403 << 14 */ +/* -0.344 << 14 */ +/* -0.714 << 14 */ +/* 1.770 << 14 */ + +static const int32_t ycbcr_table[][4] = { { 1, 0, -1, 2 }, + { 3, -1, -1, 4 }, + { 6, -1, -3, 7 }, + { 11, -3, -6, 14 }, + { 22, -6, -11, 28 }, + { 45, -11, -23, 57 }, + { 90, -22, -46, 113 }, + { 180, -44, -91, 227 }, + { 359, -88, -183, 453 }, + { 718, -176, -366, 906 }, + { 1437, -352, -731, 1812 }, + { 2873, -705, -1462, 3625 }, + { 5747, -1409, -2925, 7250 }, + { 11493, -2818, -5849, 14500 }, + { 22987, -5636, -11698, 29000 }, + { 45974, -11272, -23396, 57999 }, + { 91947, -22544, -46793, 115999 }, + { 183894, -45089, -93585, 231997 }, + { 367788, -90178, -187171, 463995 }, + { 735576, -180355, -374342, 927990 }, + { 1471152, -360710, -748683, 1855980 }, + { 2942304, -721420, -1497367, 3711959 }, + { 5884609, -1442841, -2994733, 7423918 }, + { 11769217, -2885681, -5989466, 14847836 }, + { 23538434, -5771362, -11978932, 29695672 }, + { 47076868, -11542725, -23957864, 59391345 }, + { 94153736, -23085449, -47915729, 118782689 }, + { 188307472, -46170898, -95831458, 237565379 }, + { 376614945, -92341797, -191662916, 475130757 }, + { 753229890, -184683594, -383325831, 950261514 }, + { 1506459779, -369367187, -766651662, 1900523028 } }; + +static inline __m128i mm_between_epi16_int(__m128i val, __m128i min, __m128i max) +{ + return _mm_min_epi16(max, _mm_max_epi16(val, min)); +} + +#define mm_between_epi16(_val, _min, _max) (_val) = mm_between_epi16_int((_val), (_min), (_max)) + +#ifdef DO_PREFETCH +/*---------------------------------------------------------------------------*/ +static inline void GNU_INLINE _mm_prefetch_buffer(char* WINPR_RESTRICT buffer, int num_bytes) +{ + __m128i* buf = (__m128i*)buffer; + + for (unsigned int i = 0; i < (num_bytes / sizeof(__m128i)); + i += (CACHE_LINE_BYTES / sizeof(__m128i))) + { + _mm_prefetch((char*)(&buf[i]), _MM_HINT_NTA); + } +} +#endif /* DO_PREFETCH */ + +/*---------------------------------------------------------------------------*/ +static pstatus_t +sse2_yCbCrToRGB_16s16s_P3P3(const INT16* WINPR_RESTRICT pSrc[3], int srcStep, + INT16* WINPR_RESTRICT pDst[3], int dstStep, + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + if (((ULONG_PTR)(pSrc[0]) & 0x0f) || ((ULONG_PTR)(pSrc[1]) & 0x0f) || + ((ULONG_PTR)(pSrc[2]) & 0x0f) || ((ULONG_PTR)(pDst[0]) & 0x0f) || + ((ULONG_PTR)(pDst[1]) & 0x0f) || ((ULONG_PTR)(pDst[2]) & 0x0f) || (roi->width & 0x07) || + (srcStep & 127) || (dstStep & 127)) + { + /* We can't maintain 16-byte alignment. */ + return generic->yCbCrToRGB_16s16s_P3P3(pSrc, srcStep, pDst, dstStep, roi); + } + + const __m128i zero = _mm_setzero_si128(); + const __m128i max = _mm_set1_epi16(255); + const __m128i* y_buf = (const __m128i*)(pSrc[0]); + const __m128i* cb_buf = (const __m128i*)(pSrc[1]); + const __m128i* cr_buf = (const __m128i*)(pSrc[2]); + __m128i* r_buf = (__m128i*)(pDst[0]); + __m128i* g_buf = (__m128i*)(pDst[1]); + __m128i* b_buf = (__m128i*)(pDst[2]); + __m128i r_cr = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][0])); /* 1.403 << 14 */ + __m128i g_cb = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][1])); /* -0.344 << 14 */ + __m128i g_cr = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][2])); /* -0.714 << 14 */ + __m128i b_cb = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][3])); /* 1.770 << 14 */ + __m128i c4096 = _mm_set1_epi16(4096); + const size_t srcbump = WINPR_ASSERTING_INT_CAST(size_t, srcStep) / sizeof(__m128i); + const size_t dstbump = WINPR_ASSERTING_INT_CAST(size_t, dstStep) / sizeof(__m128i); +#ifdef DO_PREFETCH + + /* Prefetch Y's, Cb's, and Cr's. */ + for (UINT32 yp = 0; yp < roi->height; yp++) + { + for (int i = 0; i < roi->width * sizeof(INT16) / sizeof(__m128i); + i += (CACHE_LINE_BYTES / sizeof(__m128i))) + { + _mm_prefetch((char*)(&y_buf[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&cb_buf[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&cr_buf[i]), _MM_HINT_NTA); + } + + y_buf += srcbump; + cb_buf += srcbump; + cr_buf += srcbump; + } + + y_buf = (__m128i*)(pSrc[0]); + cb_buf = (__m128i*)(pSrc[1]); + cr_buf = (__m128i*)(pSrc[2]); +#endif /* DO_PREFETCH */ + const size_t imax = roi->width * sizeof(INT16) / sizeof(__m128i); + + for (UINT32 yp = 0; yp < roi->height; ++yp) + { + for (size_t i = 0; i < imax; i++) + { + /* In order to use SSE2 signed 16-bit integer multiplication + * we need to convert the floating point factors to signed int + * without losing information. + * The result of this multiplication is 32 bit and we have two + * SSE instructions that return either the hi or lo word. + * Thus we will multiply the factors by the highest possible 2^n, + * take the upper 16 bits of the signed 32-bit result + * (_mm_mulhi_epi16) and correct this result by multiplying + * it by 2^(16-n). + * + * For the given factors in the conversion matrix the best + * possible n is 14. + * + * Example for calculating r: + * r = (y>>5) + 128 + (cr*1.403)>>5 // our base formula + * r = (y>>5) + 128 + (HIWORD(cr*(1.403<<14)<<2))>>5 // see above + * r = (y+4096)>>5 + (HIWORD(cr*22986)<<2)>>5 // simplification + * r = ((y+4096)>>2 + HIWORD(cr*22986)) >> 3 + */ + /* y = (y_r_buf[i] + 4096) >> 2 */ + __m128i y = _mm_load_si128(y_buf + i); + y = _mm_add_epi16(y, c4096); + y = _mm_srai_epi16(y, 2); + /* cb = cb_g_buf[i]; */ + __m128i cb = _mm_load_si128(cb_buf + i); + /* cr = cr_b_buf[i]; */ + __m128i cr = _mm_load_si128(cr_buf + i); + /* (y + HIWORD(cr*22986)) >> 3 */ + __m128i r = _mm_add_epi16(y, _mm_mulhi_epi16(cr, r_cr)); + r = _mm_srai_epi16(r, 3); + /* r_buf[i] = CLIP(r); */ + mm_between_epi16(r, zero, max); + _mm_store_si128(r_buf + i, r); + /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ + __m128i g = _mm_add_epi16(y, _mm_mulhi_epi16(cb, g_cb)); + g = _mm_add_epi16(g, _mm_mulhi_epi16(cr, g_cr)); + g = _mm_srai_epi16(g, 3); + /* g_buf[i] = CLIP(g); */ + mm_between_epi16(g, zero, max); + _mm_store_si128(g_buf + i, g); + /* (y + HIWORD(cb*28999)) >> 3 */ + __m128i b = _mm_add_epi16(y, _mm_mulhi_epi16(cb, b_cb)); + b = _mm_srai_epi16(b, 3); + /* b_buf[i] = CLIP(b); */ + mm_between_epi16(b, zero, max); + _mm_store_si128(b_buf + i, b); + } + + y_buf += srcbump; + cb_buf += srcbump; + cr_buf += srcbump; + r_buf += dstbump; + g_buf += dstbump; + b_buf += dstbump; + } + + return PRIMITIVES_SUCCESS; +} + +/*---------------------------------------------------------------------------*/ +static pstatus_t +sse2_yCbCrToRGB_16s8u_P3AC4R_BGRX(const INT16* WINPR_RESTRICT pSrc[3], UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + const __m128i zero = _mm_setzero_si128(); + const __m128i max = _mm_set1_epi16(255); + const __m128i r_cr = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][0])); /* 1.403 << 14 */ + const __m128i g_cb = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][1])); /* -0.344 << 14 */ + const __m128i g_cr = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][2])); /* -0.714 << 14 */ + const __m128i b_cb = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][3])); /* 1.770 << 14 */ + const __m128i c4096 = _mm_set1_epi16(4096); + const INT16* y_buf = pSrc[0]; + const INT16* cb_buf = pSrc[1]; + const INT16* cr_buf = pSrc[2]; + const UINT32 pad = roi->width % 16; + const UINT32 step = sizeof(__m128i) / sizeof(INT16); + const size_t imax = (roi->width - pad) * sizeof(INT16) / sizeof(__m128i); + BYTE* d_buf = pDst; + const size_t dstPad = (dstStep - roi->width * 4); +#ifdef DO_PREFETCH + + /* Prefetch Y's, Cb's, and Cr's. */ + for (UINT32 yp = 0; yp < roi->height; yp++) + { + for (size_t i = 0; i < imax; i += (CACHE_LINE_BYTES / sizeof(__m128i))) + { + _mm_prefetch((char*)(&((__m128i*)y_buf)[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&((__m128i*)cb_buf)[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&((__m128i*)cr_buf)[i]), _MM_HINT_NTA); + } + + y_buf += srcStep / sizeof(INT16); + cb_buf += srcStep / sizeof(INT16); + cr_buf += srcStep / sizeof(INT16); + } + + y_buf = (INT16*)pSrc[0]; + cb_buf = (INT16*)pSrc[1]; + cr_buf = (INT16*)pSrc[2]; +#endif /* DO_PREFETCH */ + + for (UINT32 yp = 0; yp < roi->height; ++yp) + { + for (size_t i = 0; i < imax; i += 2) + { + /* In order to use SSE2 signed 16-bit integer multiplication + * we need to convert the floating point factors to signed int + * without losing information. + * The result of this multiplication is 32 bit and we have two + * SSE instructions that return either the hi or lo word. + * Thus we will multiply the factors by the highest possible 2^n, + * take the upper 16 bits of the signed 32-bit result + * (_mm_mulhi_epi16) and correct this result by multiplying + * it by 2^(16-n). + * + * For the given factors in the conversion matrix the best + * possible n is 14. + * + * Example for calculating r: + * r = (y>>5) + 128 + (cr*1.403)>>5 // our base formula + * r = (y>>5) + 128 + (HIWORD(cr*(1.403<<14)<<2))>>5 // see above + * r = (y+4096)>>5 + (HIWORD(cr*22986)<<2)>>5 // simplification + * r = ((y+4096)>>2 + HIWORD(cr*22986)) >> 3 + */ + /* y = (y_r_buf[i] + 4096) >> 2 */ + __m128i y1 = _mm_load_si128((const __m128i*)y_buf); + y_buf += step; + y1 = _mm_add_epi16(y1, c4096); + y1 = _mm_srai_epi16(y1, 2); + /* cb = cb_g_buf[i]; */ + __m128i cb1 = _mm_load_si128((const __m128i*)cb_buf); + cb_buf += step; + /* cr = cr_b_buf[i]; */ + __m128i cr1 = _mm_load_si128((const __m128i*)cr_buf); + cr_buf += step; + /* (y + HIWORD(cr*22986)) >> 3 */ + __m128i r1 = _mm_add_epi16(y1, _mm_mulhi_epi16(cr1, r_cr)); + r1 = _mm_srai_epi16(r1, 3); + /* r_buf[i] = CLIP(r); */ + mm_between_epi16(r1, zero, max); + /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ + __m128i g1 = _mm_add_epi16(y1, _mm_mulhi_epi16(cb1, g_cb)); + g1 = _mm_add_epi16(g1, _mm_mulhi_epi16(cr1, g_cr)); + g1 = _mm_srai_epi16(g1, 3); + /* g_buf[i] = CLIP(g); */ + mm_between_epi16(g1, zero, max); + /* (y + HIWORD(cb*28999)) >> 3 */ + __m128i b1 = _mm_add_epi16(y1, _mm_mulhi_epi16(cb1, b_cb)); + b1 = _mm_srai_epi16(b1, 3); + /* b_buf[i] = CLIP(b); */ + mm_between_epi16(b1, zero, max); + __m128i y2 = _mm_load_si128((const __m128i*)y_buf); + y_buf += step; + y2 = _mm_add_epi16(y2, c4096); + y2 = _mm_srai_epi16(y2, 2); + /* cb = cb_g_buf[i]; */ + __m128i cb2 = _mm_load_si128((const __m128i*)cb_buf); + cb_buf += step; + /* cr = cr_b_buf[i]; */ + __m128i cr2 = _mm_load_si128((const __m128i*)cr_buf); + cr_buf += step; + /* (y + HIWORD(cr*22986)) >> 3 */ + __m128i r2 = _mm_add_epi16(y2, _mm_mulhi_epi16(cr2, r_cr)); + r2 = _mm_srai_epi16(r2, 3); + /* r_buf[i] = CLIP(r); */ + mm_between_epi16(r2, zero, max); + /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ + __m128i g2 = _mm_add_epi16(y2, _mm_mulhi_epi16(cb2, g_cb)); + g2 = _mm_add_epi16(g2, _mm_mulhi_epi16(cr2, g_cr)); + g2 = _mm_srai_epi16(g2, 3); + /* g_buf[i] = CLIP(g); */ + mm_between_epi16(g2, zero, max); + /* (y + HIWORD(cb*28999)) >> 3 */ + __m128i b2 = _mm_add_epi16(y2, _mm_mulhi_epi16(cb2, b_cb)); + b2 = _mm_srai_epi16(b2, 3); + /* b_buf[i] = CLIP(b); */ + mm_between_epi16(b2, zero, max); + { + /* The comments below pretend these are 8-byte registers + * rather than 16-byte, for readability. + */ + __m128i R0 = b1; /* R0 = 00B300B200B100B0 */ + __m128i R1 = b2; /* R1 = 00B700B600B500B4 */ + R0 = _mm_packus_epi16(R0, R1); /* R0 = B7B6B5B4B3B2B1B0 */ + R1 = g1; /* R1 = 00G300G200G100G0 */ + __m128i R2 = g2; /* R2 = 00G700G600G500G4 */ + R1 = _mm_packus_epi16(R1, R2); /* R1 = G7G6G5G4G3G2G1G0 */ + R2 = R1; /* R2 = G7G6G5G4G3G2G1G0 */ + R2 = _mm_unpacklo_epi8(R0, R2); /* R2 = B3G3B2G2B1G1B0G0 */ + R1 = _mm_unpackhi_epi8(R0, R1); /* R1 = B7G7B6G6B5G5B4G4 */ + R0 = r1; /* R0 = 00R300R200R100R0 */ + __m128i R3 = r2; /* R3 = 00R700R600R500R4 */ + R0 = _mm_packus_epi16(R0, R3); /* R0 = R7R6R5R4R3R2R1R0 */ + R3 = mm_set1_epu32(0xFFFFFFFFU); /* R3 = FFFFFFFFFFFFFFFF */ + __m128i R4 = R3; /* R4 = FFFFFFFFFFFFFFFF */ + R4 = _mm_unpacklo_epi8(R0, R4); /* R4 = R3FFR2FFR1FFR0FF */ + R3 = _mm_unpackhi_epi8(R0, R3); /* R3 = R7FFR6FFR5FFR4FF */ + R0 = R4; /* R0 = R4 */ + R0 = _mm_unpacklo_epi16(R2, R0); /* R0 = B1G1R1FFB0G0R0FF */ + R4 = _mm_unpackhi_epi16(R2, R4); /* R4 = B3G3R3FFB2G2R2FF */ + R2 = R3; /* R2 = R3 */ + R2 = _mm_unpacklo_epi16(R1, R2); /* R2 = B5G5R5FFB4G4R4FF */ + R3 = _mm_unpackhi_epi16(R1, R3); /* R3 = B7G7R7FFB6G6R6FF */ + _mm_store_si128((__m128i*)d_buf, R0); /* B1G1R1FFB0G0R0FF */ + d_buf += sizeof(__m128i); + _mm_store_si128((__m128i*)d_buf, R4); /* B3G3R3FFB2G2R2FF */ + d_buf += sizeof(__m128i); + _mm_store_si128((__m128i*)d_buf, R2); /* B5G5R5FFB4G4R4FF */ + d_buf += sizeof(__m128i); + _mm_store_si128((__m128i*)d_buf, R3); /* B7G7R7FFB6G6R6FF */ + d_buf += sizeof(__m128i); + } + } + + for (UINT32 i = 0; i < pad; i++) + { + const INT32 divisor = 16; + const INT32 Y = ((*y_buf++) + 4096) << divisor; + const INT32 Cb = (*cb_buf++); + const INT32 Cr = (*cr_buf++); + const INT32 CrR = Cr * ycbcr_table[divisor][0]; + const INT32 CrG = Cr * ycbcr_table[divisor][1]; + const INT32 CbG = Cb * ycbcr_table[divisor][2]; + const INT32 CbB = Cb * ycbcr_table[divisor][3]; + const INT16 R = WINPR_ASSERTING_INT_CAST(int16_t, (((CrR + Y) >> divisor) >> 5)); + const INT16 G = WINPR_ASSERTING_INT_CAST(int16_t, (((Y - CbG - CrG) >> divisor) >> 5)); + const INT16 B = WINPR_ASSERTING_INT_CAST(int16_t, (((CbB + Y) >> divisor) >> 5)); + *d_buf++ = CLIP(B); + *d_buf++ = CLIP(G); + *d_buf++ = CLIP(R); + *d_buf++ = 0xFF; + } + + d_buf += dstPad; + } + + return PRIMITIVES_SUCCESS; +} + +/*---------------------------------------------------------------------------*/ +static pstatus_t +sse2_yCbCrToRGB_16s8u_P3AC4R_RGBX(const INT16* WINPR_RESTRICT pSrc[3], UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + const __m128i zero = _mm_setzero_si128(); + const __m128i max = _mm_set1_epi16(255); + const __m128i r_cr = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][0])); /* 1.403 << 14 */ + const __m128i g_cb = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][1])); /* -0.344 << 14 */ + const __m128i g_cr = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][2])); /* -0.714 << 14 */ + const __m128i b_cb = + _mm_set1_epi16(WINPR_ASSERTING_INT_CAST(int16_t, ycbcr_table[14][3])); /* 1.770 << 14 */ + const __m128i c4096 = _mm_set1_epi16(4096); + const INT16* y_buf = pSrc[0]; + const INT16* cb_buf = pSrc[1]; + const INT16* cr_buf = pSrc[2]; + const UINT32 pad = roi->width % 16; + const UINT32 step = sizeof(__m128i) / sizeof(INT16); + const size_t imax = (roi->width - pad) * sizeof(INT16) / sizeof(__m128i); + BYTE* d_buf = pDst; + const size_t dstPad = (dstStep - roi->width * 4); +#ifdef DO_PREFETCH + + /* Prefetch Y's, Cb's, and Cr's. */ + for (UINT32 yp = 0; yp < roi->height; yp++) + { + for (size_t i = 0; i < imax; i += (CACHE_LINE_BYTES / sizeof(__m128i))) + { + _mm_prefetch((char*)(&((__m128i*)y_buf)[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&((__m128i*)cb_buf)[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&((__m128i*)cr_buf)[i]), _MM_HINT_NTA); + } + + y_buf += srcStep / sizeof(INT16); + cb_buf += srcStep / sizeof(INT16); + cr_buf += srcStep / sizeof(INT16); + } + + y_buf = (INT16*)(pSrc[0]); + cb_buf = (INT16*)(pSrc[1]); + cr_buf = (INT16*)(pSrc[2]); +#endif /* DO_PREFETCH */ + + for (UINT32 yp = 0; yp < roi->height; ++yp) + { + for (size_t i = 0; i < imax; i += 2) + { + /* In order to use SSE2 signed 16-bit integer multiplication + * we need to convert the floating point factors to signed int + * without losing information. + * The result of this multiplication is 32 bit and we have two + * SSE instructions that return either the hi or lo word. + * Thus we will multiply the factors by the highest possible 2^n, + * take the upper 16 bits of the signed 32-bit result + * (_mm_mulhi_epi16) and correct this result by multiplying + * it by 2^(16-n). + * + * For the given factors in the conversion matrix the best + * possible n is 14. + * + * Example for calculating r: + * r = (y>>5) + 128 + (cr*1.403)>>5 // our base formula + * r = (y>>5) + 128 + (HIWORD(cr*(1.403<<14)<<2))>>5 // see above + * r = (y+4096)>>5 + (HIWORD(cr*22986)<<2)>>5 // simplification + * r = ((y+4096)>>2 + HIWORD(cr*22986)) >> 3 + */ + /* y = (y_r_buf[i] + 4096) >> 2 */ + __m128i y1 = _mm_load_si128((const __m128i*)y_buf); + y_buf += step; + y1 = _mm_add_epi16(y1, c4096); + y1 = _mm_srai_epi16(y1, 2); + /* cb = cb_g_buf[i]; */ + __m128i cb1 = _mm_load_si128((const __m128i*)cb_buf); + cb_buf += step; + /* cr = cr_b_buf[i]; */ + __m128i cr1 = _mm_load_si128((const __m128i*)cr_buf); + cr_buf += step; + /* (y + HIWORD(cr*22986)) >> 3 */ + __m128i r1 = _mm_add_epi16(y1, _mm_mulhi_epi16(cr1, r_cr)); + r1 = _mm_srai_epi16(r1, 3); + /* r_buf[i] = CLIP(r); */ + mm_between_epi16(r1, zero, max); + /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ + __m128i g1 = _mm_add_epi16(y1, _mm_mulhi_epi16(cb1, g_cb)); + g1 = _mm_add_epi16(g1, _mm_mulhi_epi16(cr1, g_cr)); + g1 = _mm_srai_epi16(g1, 3); + /* g_buf[i] = CLIP(g); */ + mm_between_epi16(g1, zero, max); + /* (y + HIWORD(cb*28999)) >> 3 */ + __m128i b1 = _mm_add_epi16(y1, _mm_mulhi_epi16(cb1, b_cb)); + b1 = _mm_srai_epi16(b1, 3); + /* b_buf[i] = CLIP(b); */ + mm_between_epi16(b1, zero, max); + __m128i y2 = _mm_load_si128((const __m128i*)y_buf); + y_buf += step; + y2 = _mm_add_epi16(y2, c4096); + y2 = _mm_srai_epi16(y2, 2); + /* cb = cb_g_buf[i]; */ + __m128i cb2 = _mm_load_si128((const __m128i*)cb_buf); + cb_buf += step; + /* cr = cr_b_buf[i]; */ + __m128i cr2 = _mm_load_si128((const __m128i*)cr_buf); + cr_buf += step; + /* (y + HIWORD(cr*22986)) >> 3 */ + __m128i r2 = _mm_add_epi16(y2, _mm_mulhi_epi16(cr2, r_cr)); + r2 = _mm_srai_epi16(r2, 3); + /* r_buf[i] = CLIP(r); */ + mm_between_epi16(r2, zero, max); + /* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */ + __m128i g2 = _mm_add_epi16(y2, _mm_mulhi_epi16(cb2, g_cb)); + g2 = _mm_add_epi16(g2, _mm_mulhi_epi16(cr2, g_cr)); + g2 = _mm_srai_epi16(g2, 3); + /* g_buf[i] = CLIP(g); */ + mm_between_epi16(g2, zero, max); + /* (y + HIWORD(cb*28999)) >> 3 */ + __m128i b2 = _mm_add_epi16(y2, _mm_mulhi_epi16(cb2, b_cb)); + b2 = _mm_srai_epi16(b2, 3); + /* b_buf[i] = CLIP(b); */ + mm_between_epi16(b2, zero, max); + { + /* The comments below pretend these are 8-byte registers + * rather than 16-byte, for readability. + */ + __m128i R0 = r1; /* R0 = 00R300R200R100R0 */ + __m128i R1 = r2; /* R1 = 00R700R600R500R4 */ + R0 = _mm_packus_epi16(R0, R1); /* R0 = R7R6R5R4R3R2R1R0 */ + R1 = g1; /* R1 = 00G300G200G100G0 */ + __m128i R2 = g2; /* R2 = 00G700G600G500G4 */ + R1 = _mm_packus_epi16(R1, R2); /* R1 = G7G6G5G4G3G2G1G0 */ + R2 = R1; /* R2 = G7G6G5G4G3G2G1G0 */ + R2 = _mm_unpacklo_epi8(R0, R2); /* R2 = R3G3R2G2R1G1R0G0 */ + R1 = _mm_unpackhi_epi8(R0, R1); /* R1 = R7G7R6G6R5G5R4G4 */ + R0 = b1; /* R0 = 00B300B200B100B0 */ + __m128i R3 = b2; /* R3 = 00B700B600B500B4 */ + R0 = _mm_packus_epi16(R0, R3); /* R0 = B7B6B5B4B3B2B1B0 */ + R3 = mm_set1_epu32(0xFFFFFFFFU); /* R3 = FFFFFFFFFFFFFFFF */ + __m128i R4 = R3; /* R4 = FFFFFFFFFFFFFFFF */ + R4 = _mm_unpacklo_epi8(R0, R4); /* R4 = B3FFB2FFB1FFB0FF */ + R3 = _mm_unpackhi_epi8(R0, R3); /* R3 = B7FFB6FFB5FFB4FF */ + R0 = R4; /* R0 = R4 */ + R0 = _mm_unpacklo_epi16(R2, R0); /* R0 = R1G1B1FFR0G0B0FF */ + R4 = _mm_unpackhi_epi16(R2, R4); /* R4 = R3G3B3FFR2G2B2FF */ + R2 = R3; /* R2 = R3 */ + R2 = _mm_unpacklo_epi16(R1, R2); /* R2 = R5G5B5FFR4G4B4FF */ + R3 = _mm_unpackhi_epi16(R1, R3); /* R3 = R7G7B7FFR6G6B6FF */ + _mm_store_si128((__m128i*)d_buf, R0); /* R1G1B1FFR0G0B0FF */ + d_buf += sizeof(__m128i); + _mm_store_si128((__m128i*)d_buf, R4); /* R3G3B3FFR2G2B2FF */ + d_buf += sizeof(__m128i); + _mm_store_si128((__m128i*)d_buf, R2); /* R5G5B5FFR4G4B4FF */ + d_buf += sizeof(__m128i); + _mm_store_si128((__m128i*)d_buf, R3); /* R7G7B7FFR6G6B6FF */ + d_buf += sizeof(__m128i); + } + } + + for (UINT32 i = 0; i < pad; i++) + { + const INT32 divisor = 16; + const INT32 Y = ((*y_buf++) + 4096) << divisor; + const INT32 Cb = (*cb_buf++); + const INT32 Cr = (*cr_buf++); + const INT32 CrR = Cr * ycbcr_table[divisor][0]; + const INT32 CrG = Cr * ycbcr_table[divisor][1]; + const INT32 CbG = Cb * ycbcr_table[divisor][2]; + const INT32 CbB = Cb * ycbcr_table[divisor][3]; + const INT16 R = WINPR_ASSERTING_INT_CAST(int16_t, (((CrR + Y) >> divisor) >> 5)); + const INT16 G = WINPR_ASSERTING_INT_CAST(int16_t, (((Y - CbG - CrG) >> divisor) >> 5)); + const INT16 B = WINPR_ASSERTING_INT_CAST(int16_t, (((CbB + Y) >> divisor) >> 5)); + *d_buf++ = CLIP(R); + *d_buf++ = CLIP(G); + *d_buf++ = CLIP(B); + *d_buf++ = 0xFF; + } + + d_buf += dstPad; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t +sse2_yCbCrToRGB_16s8u_P3AC4R(const INT16* WINPR_RESTRICT pSrc[3], UINT32 srcStep, + BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, UINT32 DstFormat, + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + if (((ULONG_PTR)(pSrc[0]) & 0x0f) || ((ULONG_PTR)(pSrc[1]) & 0x0f) || + ((ULONG_PTR)(pSrc[2]) & 0x0f) || ((ULONG_PTR)(pDst)&0x0f) || (srcStep & 0x0f) || + (dstStep & 0x0f)) + { + /* We can't maintain 16-byte alignment. */ + return generic->yCbCrToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } + + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + case PIXEL_FORMAT_BGRX32: + return sse2_yCbCrToRGB_16s8u_P3AC4R_BGRX(pSrc, srcStep, pDst, dstStep, roi); + + case PIXEL_FORMAT_RGBA32: + case PIXEL_FORMAT_RGBX32: + return sse2_yCbCrToRGB_16s8u_P3AC4R_RGBX(pSrc, srcStep, pDst, dstStep, roi); + + default: + return generic->yCbCrToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} +/* The encodec YCbCr coeffectients are represented as 11.5 fixed-point + * numbers. See the general code above. + */ +static pstatus_t +sse2_RGBToYCbCr_16s16s_P3P3(const INT16* WINPR_RESTRICT pSrc[3], int srcStep, + INT16* WINPR_RESTRICT pDst[3], int dstStep, + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + const __m128i* r_buf = (const __m128i*)(pSrc[0]); + const __m128i* g_buf = (const __m128i*)(pSrc[1]); + const __m128i* b_buf = (const __m128i*)(pSrc[2]); + __m128i* y_buf = (__m128i*)(pDst[0]); + __m128i* cb_buf = (__m128i*)(pDst[1]); + __m128i* cr_buf = (__m128i*)(pDst[2]); + + if (((ULONG_PTR)(pSrc[0]) & 0x0f) || ((ULONG_PTR)(pSrc[1]) & 0x0f) || + ((ULONG_PTR)(pSrc[2]) & 0x0f) || ((ULONG_PTR)(pDst[0]) & 0x0f) || + ((ULONG_PTR)(pDst[1]) & 0x0f) || ((ULONG_PTR)(pDst[2]) & 0x0f) || (roi->width & 0x07) || + (srcStep & 127) || (dstStep & 127)) + { + /* We can't maintain 16-byte alignment. */ + return generic->RGBToYCbCr_16s16s_P3P3(pSrc, srcStep, pDst, dstStep, roi); + } + + const __m128i min = _mm_set1_epi16(-128 * 32); + const __m128i max = _mm_set1_epi16(127 * 32); + + __m128i y_r = _mm_set1_epi16(9798); /* 0.299000 << 15 */ + __m128i y_g = _mm_set1_epi16(19235); /* 0.587000 << 15 */ + __m128i y_b = _mm_set1_epi16(3735); /* 0.114000 << 15 */ + __m128i cb_r = _mm_set1_epi16(-5535); /* -0.168935 << 15 */ + __m128i cb_g = _mm_set1_epi16(-10868); /* -0.331665 << 15 */ + __m128i cb_b = _mm_set1_epi16(16403); /* 0.500590 << 15 */ + __m128i cr_r = _mm_set1_epi16(16377); /* 0.499813 << 15 */ + __m128i cr_g = _mm_set1_epi16(-13714); /* -0.418531 << 15 */ + __m128i cr_b = _mm_set1_epi16(-2663); /* -0.081282 << 15 */ + const size_t srcbump = WINPR_ASSERTING_INT_CAST(size_t, srcStep) / sizeof(__m128i); + const size_t dstbump = WINPR_ASSERTING_INT_CAST(size_t, dstStep) / sizeof(__m128i); +#ifdef DO_PREFETCH + + /* Prefetch RGB's. */ + for (UINT32 yp = 0; yp < roi->height; yp++) + { + for (int i = 0; i < roi->width * sizeof(INT16) / sizeof(__m128i); + i += (CACHE_LINE_BYTES / sizeof(__m128i))) + { + _mm_prefetch((char*)(&r_buf[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&g_buf[i]), _MM_HINT_NTA); + _mm_prefetch((char*)(&b_buf[i]), _MM_HINT_NTA); + } + + r_buf += srcbump; + g_buf += srcbump; + b_buf += srcbump; + } + + r_buf = (__m128i*)(pSrc[0]); + g_buf = (__m128i*)(pSrc[1]); + b_buf = (__m128i*)(pSrc[2]); +#endif /* DO_PREFETCH */ + const size_t imax = roi->width * sizeof(INT16) / sizeof(__m128i); + + for (UINT32 yp = 0; yp < roi->height; ++yp) + { + for (size_t i = 0; i < imax; i++) + { + /* In order to use SSE2 signed 16-bit integer multiplication we + * need to convert the floating point factors to signed int + * without losing information. The result of this multiplication + * is 32 bit and using SSE2 we get either the product's hi or lo + * word. Thus we will multiply the factors by the highest + * possible 2^n and take the upper 16 bits of the signed 32-bit + * result (_mm_mulhi_epi16). Since the final result needs to + * be scaled by << 5 and also in in order to keep the precision + * within the upper 16 bits we will also have to scale the RGB + * values used in the multiplication by << 5+(16-n). + */ + __m128i r = _mm_load_si128(r_buf + i); + __m128i g = _mm_load_si128(g_buf + i); + __m128i b = _mm_load_si128(b_buf + i); + /* r<<6; g<<6; b<<6 */ + r = _mm_slli_epi16(r, 6); + g = _mm_slli_epi16(g, 6); + b = _mm_slli_epi16(b, 6); + /* y = HIWORD(r*y_r) + HIWORD(g*y_g) + HIWORD(b*y_b) + min */ + __m128i y = _mm_mulhi_epi16(r, y_r); + y = _mm_add_epi16(y, _mm_mulhi_epi16(g, y_g)); + y = _mm_add_epi16(y, _mm_mulhi_epi16(b, y_b)); + y = _mm_add_epi16(y, min); + /* y_r_buf[i] = MINMAX(y, 0, (255 << 5)) - (128 << 5); */ + mm_between_epi16(y, min, max); + _mm_store_si128(y_buf + i, y); + /* cb = HIWORD(r*cb_r) + HIWORD(g*cb_g) + HIWORD(b*cb_b) */ + __m128i cb = _mm_mulhi_epi16(r, cb_r); + cb = _mm_add_epi16(cb, _mm_mulhi_epi16(g, cb_g)); + cb = _mm_add_epi16(cb, _mm_mulhi_epi16(b, cb_b)); + /* cb_g_buf[i] = MINMAX(cb, (-128 << 5), (127 << 5)); */ + mm_between_epi16(cb, min, max); + _mm_store_si128(cb_buf + i, cb); + /* cr = HIWORD(r*cr_r) + HIWORD(g*cr_g) + HIWORD(b*cr_b) */ + __m128i cr = _mm_mulhi_epi16(r, cr_r); + cr = _mm_add_epi16(cr, _mm_mulhi_epi16(g, cr_g)); + cr = _mm_add_epi16(cr, _mm_mulhi_epi16(b, cr_b)); + /* cr_b_buf[i] = MINMAX(cr, (-128 << 5), (127 << 5)); */ + mm_between_epi16(cr, min, max); + _mm_store_si128(cr_buf + i, cr); + } + + y_buf += srcbump; + cb_buf += srcbump; + cr_buf += srcbump; + r_buf += dstbump; + g_buf += dstbump; + b_buf += dstbump; + } + + return PRIMITIVES_SUCCESS; +} + +/*---------------------------------------------------------------------------*/ +static pstatus_t sse2_RGBToRGB_16s8u_P3AC4R_BGRX( + const INT16* WINPR_RESTRICT pSrc[3], /* 16-bit R,G, and B arrays */ + UINT32 srcStep, /* bytes between rows in source data */ + BYTE* WINPR_RESTRICT pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + UINT32 dstStep, /* bytes between rows in dest data */ + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + const UINT16* pr = (const UINT16*)(pSrc[0]); + const UINT16* pg = (const UINT16*)(pSrc[1]); + const UINT16* pb = (const UINT16*)(pSrc[2]); + const UINT32 pad = roi->width % 16; + const __m128i a = mm_set1_epu32(0xFFFFFFFFU); + BYTE* out = NULL; + UINT32 srcbump = 0; + UINT32 dstbump = 0; + out = pDst; + srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + dstbump = (dstStep - (roi->width * sizeof(UINT32))); + + for (UINT32 y = 0; y < roi->height; ++y) + { + for (UINT32 x = 0; x < roi->width - pad; x += 16) + { + __m128i r; + __m128i g; + __m128i b; + /* The comments below pretend these are 8-byte registers + * rather than 16-byte, for readability. + */ + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R0 = 00B300B200B100B0 */ + R1 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R1 = 00B700B600B500B4 */ + b = _mm_packus_epi16(R0, R1); /* b = B7B6B5B4B3B2B1B0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R1 = 00G300G200G100G0 */ + R1 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R2 = 00G700G600G500G4 */ + g = _mm_packus_epi16(R0, R1); /* g = G7G6G5G4G3G2G1G0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R0 = 00R300R200R100R0 */ + R1 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R3 = 00R700R600R500R4 */ + r = _mm_packus_epi16(R0, R1); /* r = R7R6R5R4R3R2R1R0 */ + } + { + const __m128i gbLo = _mm_unpacklo_epi8(b, g); /* R0 = G7G6G5G4G3G2G1G0 */ + const __m128i gbHi = _mm_unpackhi_epi8(b, g); /* R1 = G7B7G6B7G5B5G4B4 */ + const __m128i arLo = _mm_unpacklo_epi8(r, a); /* R4 = FFR3FFR2FFR1FFR0 */ + const __m128i arHi = _mm_unpackhi_epi8(r, a); /* R3 = FFR7FFR6FFR5FFR4 */ + + { + const __m128i bgrx = _mm_unpacklo_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR1G1B1FFR0G0B0 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR3G3B3FFR2G2B2 */ + } + { + const __m128i bgrx = _mm_unpacklo_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR5G5B5FFR4G4B4 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR7G7B7FFR6G6B6 */ + } + } + } + + for (UINT32 x = 0; x < pad; x++) + { + const BYTE R = CLIP(*pr++); + const BYTE G = CLIP(*pg++); + const BYTE B = CLIP(*pb++); + *out++ = B; + *out++ = G; + *out++ = R; + *out++ = 0xFF; + } + + /* Jump to next row. */ + pr += srcbump; + pg += srcbump; + pb += srcbump; + out += dstbump; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse2_RGBToRGB_16s8u_P3AC4R_RGBX( + const INT16* WINPR_RESTRICT pSrc[3], /* 16-bit R,G, and B arrays */ + UINT32 srcStep, /* bytes between rows in source data */ + BYTE* WINPR_RESTRICT pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + UINT32 dstStep, /* bytes between rows in dest data */ + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + const UINT16* pr = (const UINT16*)(pSrc[0]); + const UINT16* pg = (const UINT16*)(pSrc[1]); + const UINT16* pb = (const UINT16*)(pSrc[2]); + const UINT32 pad = roi->width % 16; + const __m128i a = mm_set1_epu32(0xFFFFFFFFU); + BYTE* out = NULL; + UINT32 srcbump = 0; + UINT32 dstbump = 0; + out = pDst; + srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + dstbump = (dstStep - (roi->width * sizeof(UINT32))); + + for (UINT32 y = 0; y < roi->height; ++y) + { + for (UINT32 x = 0; x < roi->width - pad; x += 16) + { + __m128i r; + __m128i g; + __m128i b; + /* The comments below pretend these are 8-byte registers + * rather than 16-byte, for readability. + */ + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R0 = 00B300B200B100B0 */ + R1 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R1 = 00B700B600B500B4 */ + b = _mm_packus_epi16(R0, R1); /* b = B7B6B5B4B3B2B1B0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R1 = 00G300G200G100G0 */ + R1 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R2 = 00G700G600G500G4 */ + g = _mm_packus_epi16(R0, R1); /* g = G7G6G5G4G3G2G1G0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R0 = 00R300R200R100R0 */ + R1 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R3 = 00R700R600R500R4 */ + r = _mm_packus_epi16(R0, R1); /* r = R7R6R5R4R3R2R1R0 */ + } + { + __m128i gbHi; + __m128i gbLo; + __m128i arHi; + __m128i arLo; + { + gbLo = _mm_unpacklo_epi8(r, g); /* R0 = G7G6G5G4G3G2G1G0 */ + gbHi = _mm_unpackhi_epi8(r, g); /* R1 = G7B7G6B7G5B5G4B4 */ + arLo = _mm_unpacklo_epi8(b, a); /* R4 = FFR3FFR2FFR1FFR0 */ + arHi = _mm_unpackhi_epi8(b, a); /* R3 = FFR7FFR6FFR5FFR4 */ + } + { + const __m128i bgrx = _mm_unpacklo_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR1G1B1FFR0G0B0 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR3G3B3FFR2G2B2 */ + } + { + const __m128i bgrx = _mm_unpacklo_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR5G5B5FFR4G4B4 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR7G7B7FFR6G6B6 */ + } + } + } + + for (UINT32 x = 0; x < pad; x++) + { + const BYTE R = CLIP(*pr++); + const BYTE G = CLIP(*pg++); + const BYTE B = CLIP(*pb++); + *out++ = R; + *out++ = G; + *out++ = B; + *out++ = 0xFF; + } + + /* Jump to next row. */ + pr += srcbump; + pg += srcbump; + pb += srcbump; + out += dstbump; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse2_RGBToRGB_16s8u_P3AC4R_XBGR( + const INT16* WINPR_RESTRICT pSrc[3], /* 16-bit R,G, and B arrays */ + UINT32 srcStep, /* bytes between rows in source data */ + BYTE* WINPR_RESTRICT pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + UINT32 dstStep, /* bytes between rows in dest data */ + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + const UINT16* pr = (const UINT16*)(pSrc[0]); + const UINT16* pg = (const UINT16*)(pSrc[1]); + const UINT16* pb = (const UINT16*)(pSrc[2]); + const UINT32 pad = roi->width % 16; + const __m128i a = mm_set1_epu32(0xFFFFFFFFU); + BYTE* out = NULL; + UINT32 srcbump = 0; + UINT32 dstbump = 0; + out = pDst; + srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + dstbump = (dstStep - (roi->width * sizeof(UINT32))); + + for (UINT32 y = 0; y < roi->height; ++y) + { + for (UINT32 x = 0; x < roi->width - pad; x += 16) + { + __m128i r; + __m128i g; + __m128i b; + /* The comments below pretend these are 8-byte registers + * rather than 16-byte, for readability. + */ + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R0 = 00B300B200B100B0 */ + R1 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R1 = 00B700B600B500B4 */ + b = _mm_packus_epi16(R0, R1); /* b = B7B6B5B4B3B2B1B0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R1 = 00G300G200G100G0 */ + R1 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R2 = 00G700G600G500G4 */ + g = _mm_packus_epi16(R0, R1); /* g = G7G6G5G4G3G2G1G0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R0 = 00R300R200R100R0 */ + R1 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R3 = 00R700R600R500R4 */ + r = _mm_packus_epi16(R0, R1); /* r = R7R6R5R4R3R2R1R0 */ + } + { + __m128i gbHi; + __m128i gbLo; + __m128i arHi; + __m128i arLo; + { + gbLo = _mm_unpacklo_epi8(a, b); /* R0 = G7G6G5G4G3G2G1G0 */ + gbHi = _mm_unpackhi_epi8(a, b); /* R1 = G7B7G6B7G5B5G4B4 */ + arLo = _mm_unpacklo_epi8(g, r); /* R4 = FFR3FFR2FFR1FFR0 */ + arHi = _mm_unpackhi_epi8(g, r); /* R3 = FFR7FFR6FFR5FFR4 */ + } + { + const __m128i bgrx = _mm_unpacklo_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR1G1B1FFR0G0B0 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR3G3B3FFR2G2B2 */ + } + { + const __m128i bgrx = _mm_unpacklo_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR5G5B5FFR4G4B4 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR7G7B7FFR6G6B6 */ + } + } + } + + for (UINT32 x = 0; x < pad; x++) + { + const BYTE R = CLIP(*pr++); + const BYTE G = CLIP(*pg++); + const BYTE B = CLIP(*pb++); + *out++ = 0xFF; + *out++ = B; + *out++ = G; + *out++ = R; + } + + /* Jump to next row. */ + pr += srcbump; + pg += srcbump; + pb += srcbump; + out += dstbump; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse2_RGBToRGB_16s8u_P3AC4R_XRGB( + const INT16* WINPR_RESTRICT pSrc[3], /* 16-bit R,G, and B arrays */ + UINT32 srcStep, /* bytes between rows in source data */ + BYTE* WINPR_RESTRICT pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + UINT32 dstStep, /* bytes between rows in dest data */ + const prim_size_t* WINPR_RESTRICT roi) /* region of interest */ +{ + const UINT16* pr = (const UINT16*)(pSrc[0]); + const UINT16* pg = (const UINT16*)(pSrc[1]); + const UINT16* pb = (const UINT16*)(pSrc[2]); + const __m128i a = mm_set1_epu32(0xFFFFFFFFU); + const UINT32 pad = roi->width % 16; + BYTE* out = NULL; + UINT32 srcbump = 0; + UINT32 dstbump = 0; + out = pDst; + srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16); + dstbump = (dstStep - (roi->width * sizeof(UINT32))); + + for (UINT32 y = 0; y < roi->height; ++y) + { + for (UINT32 x = 0; x < roi->width - pad; x += 16) + { + __m128i r; + __m128i g; + __m128i b; + /* The comments below pretend these are 8-byte registers + * rather than 16-byte, for readability. + */ + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R0 = 00B300B200B100B0 */ + R1 = _mm_load_si128((const __m128i*)pb); + pb += 8; /* R1 = 00B700B600B500B4 */ + b = _mm_packus_epi16(R0, R1); /* b = B7B6B5B4B3B2B1B0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R1 = 00G300G200G100G0 */ + R1 = _mm_load_si128((const __m128i*)pg); + pg += 8; /* R2 = 00G700G600G500G4 */ + g = _mm_packus_epi16(R0, R1); /* g = G7G6G5G4G3G2G1G0 */ + } + { + __m128i R0; + __m128i R1; + R0 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R0 = 00R300R200R100R0 */ + R1 = _mm_load_si128((const __m128i*)pr); + pr += 8; /* R3 = 00R700R600R500R4 */ + r = _mm_packus_epi16(R0, R1); /* r = R7R6R5R4R3R2R1R0 */ + } + { + __m128i gbHi; + __m128i gbLo; + __m128i arHi; + __m128i arLo; + { + gbLo = _mm_unpacklo_epi8(a, r); /* R0 = G7G6G5G4G3G2G1G0 */ + gbHi = _mm_unpackhi_epi8(a, r); /* R1 = G7B7G6B7G5B5G4B4 */ + arLo = _mm_unpacklo_epi8(g, b); /* R4 = FFR3FFR2FFR1FFR0 */ + arHi = _mm_unpackhi_epi8(g, b); /* R3 = FFR7FFR6FFR5FFR4 */ + } + { + const __m128i bgrx = _mm_unpacklo_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR1G1B1FFR0G0B0 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbLo, arLo); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR3G3B3FFR2G2B2 */ + } + { + const __m128i bgrx = _mm_unpacklo_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR5G5B5FFR4G4B4 */ + } + { + const __m128i bgrx = _mm_unpackhi_epi16(gbHi, arHi); + _mm_store_si128((__m128i*)out, bgrx); + out += 16; /* FFR7G7B7FFR6G6B6 */ + } + } + } + + for (UINT32 x = 0; x < pad; x++) + { + const BYTE R = CLIP(*pr++); + const BYTE G = CLIP(*pg++); + const BYTE B = CLIP(*pb++); + *out++ = 0xFF; + *out++ = R; + *out++ = G; + *out++ = B; + } + + /* Jump to next row. */ + pr += srcbump; + pg += srcbump; + pb += srcbump; + out += dstbump; + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t +sse2_RGBToRGB_16s8u_P3AC4R(const INT16* WINPR_RESTRICT pSrc[3], /* 16-bit R,G, and B arrays */ + UINT32 srcStep, /* bytes between rows in source data */ + BYTE* WINPR_RESTRICT pDst, /* 32-bit interleaved ARGB (ABGR?) data */ + UINT32 dstStep, /* bytes between rows in dest data */ + UINT32 DstFormat, const prim_size_t* WINPR_RESTRICT roi) +{ + if (((ULONG_PTR)pSrc[0] & 0x0f) || ((ULONG_PTR)pSrc[1] & 0x0f) || ((ULONG_PTR)pSrc[2] & 0x0f) || + (srcStep & 0x0f) || ((ULONG_PTR)pDst & 0x0f) || (dstStep & 0x0f)) + return generic->RGBToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + + switch (DstFormat) + { + case PIXEL_FORMAT_BGRA32: + case PIXEL_FORMAT_BGRX32: + return sse2_RGBToRGB_16s8u_P3AC4R_BGRX(pSrc, srcStep, pDst, dstStep, roi); + + case PIXEL_FORMAT_RGBA32: + case PIXEL_FORMAT_RGBX32: + return sse2_RGBToRGB_16s8u_P3AC4R_RGBX(pSrc, srcStep, pDst, dstStep, roi); + + case PIXEL_FORMAT_ABGR32: + case PIXEL_FORMAT_XBGR32: + return sse2_RGBToRGB_16s8u_P3AC4R_XBGR(pSrc, srcStep, pDst, dstStep, roi); + + case PIXEL_FORMAT_ARGB32: + case PIXEL_FORMAT_XRGB32: + return sse2_RGBToRGB_16s8u_P3AC4R_XRGB(pSrc, srcStep, pDst, dstStep, roi); + + default: + return generic->RGBToRGB_16s8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi); + } +} +#endif + +void primitives_init_colors_sse2(primitives_t* prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_colors(prims); + + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE2 optimizations"); + prims->RGBToRGB_16s8u_P3AC4R = sse2_RGBToRGB_16s8u_P3AC4R; + prims->yCbCrToRGB_16s16s_P3P3 = sse2_yCbCrToRGB_16s16s_P3P3; + prims->yCbCrToRGB_16s8u_P3AC4R = sse2_yCbCrToRGB_16s8u_P3AC4R; + prims->RGBToYCbCr_16s16s_P3P3 = sse2_RGBToYCbCr_16s16s_P3P3; + } + +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE2 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_copy_avx2.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_copy_avx2.c new file mode 100644 index 0000000000000000000000000000000000000000..0baed39dbe8da52ce97c085f6debd8b7a67e19a4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_copy_avx2.c @@ -0,0 +1,288 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Copy operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include + +#include +#include +#include +#include + +#include "prim_internal.h" +#include "prim_copy.h" +#include "../codec/color.h" + +#include + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#define TAG FREERDP_TAG("primitives.copy") + +#include +#include + +static inline __m256i mm256_set_epu32(uint32_t i0, uint32_t i1, uint32_t i2, uint32_t i3, + uint32_t i4, uint32_t i5, uint32_t i6, uint32_t i7) +{ + return _mm256_set_epi32((int32_t)i0, (int32_t)i1, (int32_t)i2, (int32_t)i3, (int32_t)i4, + (int32_t)i5, (int32_t)i6, (int32_t)i7); +} + +static INLINE pstatus_t avx2_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstData, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, + UINT32 nHeight, + const BYTE* WINPR_RESTRICT pSrcData, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, + SSIZE_T dstVMultiplier, SSIZE_T dstVOffset) +{ + + const SSIZE_T srcByte = 3; + const SSIZE_T dstByte = 4; + + const __m256i mask = mm256_set_epu32(0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, + 0xFF000000, 0xFF000000, 0xFF000000); + const __m256i smask = mm256_set_epu32(0xff171615, 0xff141312, 0xff1110ff, 0xffffffff, + 0xff0b0a09, 0xff080706, 0xff050403, 0xff020100); + const __m256i shelpmask = mm256_set_epu32(0xffffffff, 0xffffffff, 0xffffff1f, 0xff1e1d1c, + 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff); + const UINT32 rem = nWidth % 8; + const SSIZE_T width = nWidth - rem; + + const size_t align = nSrcStep % 32; + const BOOL fast = (align == 0) ? TRUE : (align >= 8 - MIN(8, (size_t)rem) ? TRUE : FALSE); + for (SSIZE_T y = 0; y < nHeight; y++) + { + const BYTE* WINPR_RESTRICT srcLine = + &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset]; + BYTE* WINPR_RESTRICT dstLine = + &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset]; + + SSIZE_T x = 0; + + /* Ensure alignment requirements can be met */ + if (fast) + { + for (; x < width; x += 8) + { + const __m256i* src = (const __m256i*)&srcLine[(x + nXSrc) * srcByte]; + __m256i* dst = (__m256i*)&dstLine[(x + nXDst) * dstByte]; + const __m256i s0 = _mm256_loadu_si256(src); + __m256i s1 = _mm256_shuffle_epi8(s0, smask); + + /* _mm256_shuffle_epi8 can not cross 128bit lanes. + * manually copy these bytes with extract/insert */ + const __m256i sx = _mm256_broadcastsi128_si256(_mm256_extractf128_si256(s0, 0)); + const __m256i sxx = _mm256_shuffle_epi8(sx, shelpmask); + const __m256i bmask = + _mm256_set_epi32(0x00000000, 0x00000000, 0x000000FF, 0x00FFFFFF, 0x00000000, + 0x00000000, 0x00000000, 0x00000000); + const __m256i merged = _mm256_blendv_epi8(s1, sxx, bmask); + + const __m256i s2 = _mm256_loadu_si256(dst); + __m256i d0 = _mm256_blendv_epi8(merged, s2, mask); + _mm256_storeu_si256(dst, d0); + } + } + for (; x < nWidth; x++) + { + const BYTE* src = &srcLine[(x + nXSrc) * srcByte]; + BYTE* dst = &dstLine[(x + nXDst) * dstByte]; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + } + } + + return PRIMITIVES_SUCCESS; +} + +static INLINE pstatus_t avx2_image_copy_bgrx32_bgrx32(BYTE* WINPR_RESTRICT pDstData, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* WINPR_RESTRICT pSrcData, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, + SSIZE_T dstVMultiplier, SSIZE_T dstVOffset) +{ + + const SSIZE_T srcByte = 4; + const SSIZE_T dstByte = 4; + + const __m256i mask = _mm256_setr_epi8( + (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00, + (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00, + (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00, + (char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00); + const UINT32 rem = nWidth % 8; + const SSIZE_T width = nWidth - rem; + for (SSIZE_T y = 0; y < nHeight; y++) + { + const BYTE* WINPR_RESTRICT srcLine = + &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset]; + BYTE* WINPR_RESTRICT dstLine = + &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset]; + + SSIZE_T x = 0; + for (; x < width; x += 8) + { + const __m256i* src = (const __m256i*)&srcLine[(x + nXSrc) * srcByte]; + __m256i* dst = (__m256i*)&dstLine[(x + nXDst) * dstByte]; + const __m256i s0 = _mm256_loadu_si256(src); + const __m256i s1 = _mm256_loadu_si256(dst); + __m256i d0 = _mm256_blendv_epi8(s1, s0, mask); + _mm256_storeu_si256(dst, d0); + } + + for (; x < nWidth; x++) + { + const BYTE* src = &srcLine[(x + nXSrc) * srcByte]; + BYTE* dst = &dstLine[(x + nXDst) * dstByte]; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t avx2_image_copy_no_overlap_dst_alpha( + BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette, + UINT32 flags, SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, + SSIZE_T dstVOffset) +{ + WINPR_ASSERT(pDstData); + WINPR_ASSERT(pSrcData); + + switch (SrcFormat) + { + case PIXEL_FORMAT_BGR24: + switch (DstFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return avx2_image_copy_bgr24_bgrx32( + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep, + nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset); + default: + break; + } + break; + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + switch (DstFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return avx2_image_copy_bgrx32_bgrx32( + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep, + nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset); + default: + break; + } + break; + case PIXEL_FORMAT_RGBX32: + case PIXEL_FORMAT_RGBA32: + switch (DstFormat) + { + case PIXEL_FORMAT_RGBX32: + case PIXEL_FORMAT_RGBA32: + return avx2_image_copy_bgrx32_bgrx32( + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep, + nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset); + default: + break; + } + break; + default: + break; + } + + primitives_t* gen = primitives_get_generic(); + return gen->copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, + pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette, flags); +} + +static pstatus_t avx2_image_copy_no_overlap(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + const gdiPalette* WINPR_RESTRICT palette, UINT32 flags) +{ + const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE; + SSIZE_T srcVOffset = 0; + SSIZE_T srcVMultiplier = 1; + SSIZE_T dstVOffset = 0; + SSIZE_T dstVMultiplier = 1; + + if ((nWidth == 0) || (nHeight == 0)) + return PRIMITIVES_SUCCESS; + + if ((nHeight > INT32_MAX) || (nWidth > INT32_MAX)) + return -1; + + if (!pDstData || !pSrcData) + return -1; + + if (nDstStep == 0) + nDstStep = nWidth * FreeRDPGetBytesPerPixel(DstFormat); + + if (nSrcStep == 0) + nSrcStep = nWidth * FreeRDPGetBytesPerPixel(SrcFormat); + + if (vSrcVFlip) + { + srcVOffset = (nHeight - 1ll) * nSrcStep; + srcVMultiplier = -1; + } + + if (((flags & FREERDP_KEEP_DST_ALPHA) != 0) && FreeRDPColorHasAlpha(DstFormat)) + return avx2_image_copy_no_overlap_dst_alpha(pDstData, DstFormat, nDstStep, nXDst, nYDst, + nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, + nXSrc, nYSrc, palette, flags, srcVMultiplier, + srcVOffset, dstVMultiplier, dstVOffset); + else if (FreeRDPAreColorFormatsEqualNoAlpha(SrcFormat, DstFormat)) + return generic_image_copy_no_overlap_memcpy(pDstData, DstFormat, nDstStep, nXDst, nYDst, + nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, + nXSrc, nYSrc, palette, srcVMultiplier, + srcVOffset, dstVMultiplier, dstVOffset, flags); + else + { + primitives_t* gen = primitives_get_generic(); + return gen->copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, + pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette, flags); + } +} +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_copy_avx2(primitives_t* prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + if (IsProcessorFeaturePresent(PF_AVX2_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "AVX2 optimizations"); + prims->copy_no_overlap = avx2_image_copy_no_overlap; + } +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or WITH_AVX2 or AVX2 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_copy_sse4_1.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_copy_sse4_1.c new file mode 100644 index 0000000000000000000000000000000000000000..2bf65d66cba134146bca91a0db843cfd4390cc39 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_copy_sse4_1.c @@ -0,0 +1,265 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Copy operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include + +#include +#include +#include +#include + +#include "prim_internal.h" +#include "prim_copy.h" +#include "../codec/color.h" + +#include + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#define TAG FREERDP_TAG("primitives.copy") + +#include +#include + +static INLINE pstatus_t sse_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstData, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, + UINT32 nHeight, + const BYTE* WINPR_RESTRICT pSrcData, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, + SSIZE_T dstVMultiplier, SSIZE_T dstVOffset) +{ + + const SSIZE_T srcByte = 3; + const SSIZE_T dstByte = 4; + + const __m128i mask = mm_set_epu32(0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000); + const __m128i smask = mm_set_epu32(0xff0b0a09, 0xff080706, 0xff050403, 0xff020100); + const UINT32 rem = nWidth % 4; + + const size_t align = nSrcStep % 64; + const BOOL fast = (align == 0) ? TRUE : (align >= 16 - MIN(16, (size_t)rem) ? TRUE : FALSE); + const SSIZE_T width = nWidth - rem; + for (SSIZE_T y = 0; y < nHeight; y++) + { + const BYTE* WINPR_RESTRICT srcLine = + &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset]; + BYTE* WINPR_RESTRICT dstLine = + &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset]; + + SSIZE_T x = 0; + /* Ensure alignment requirements can be met */ + if (fast) + { + for (; x < width; x += 4) + { + const __m128i* src = (const __m128i*)&srcLine[(x + nXSrc) * srcByte]; + __m128i* dst = (__m128i*)&dstLine[(x + nXDst) * dstByte]; + const __m128i s0 = _mm_loadu_si128(src); + const __m128i s1 = _mm_shuffle_epi8(s0, smask); + const __m128i s2 = _mm_loadu_si128(dst); + + __m128i d0 = _mm_blendv_epi8(s1, s2, mask); + _mm_storeu_si128(dst, d0); + } + } + for (; x < nWidth; x++) + { + const BYTE* src = &srcLine[(x + nXSrc) * srcByte]; + BYTE* dst = &dstLine[(x + nXDst) * dstByte]; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + } + } + + return PRIMITIVES_SUCCESS; +} + +static INLINE pstatus_t sse_image_copy_bgrx32_bgrx32(BYTE* WINPR_RESTRICT pDstData, UINT32 nDstStep, + UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, + UINT32 nHeight, + const BYTE* WINPR_RESTRICT pSrcData, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, + SSIZE_T dstVMultiplier, SSIZE_T dstVOffset) +{ + + const SSIZE_T srcByte = 4; + const SSIZE_T dstByte = 4; + + const __m128i mask = _mm_setr_epi8((char)0xFF, (char)0xFF, (char)0xFF, 0x00, (char)0xFF, + (char)0xFF, (char)0xFF, 0x00, (char)0xFF, (char)0xFF, + (char)0xFF, 0x00, (char)0xFF, (char)0xFF, (char)0xFF, 0x00); + const UINT32 rem = nWidth % 4; + const SSIZE_T width = nWidth - rem; + for (SSIZE_T y = 0; y < nHeight; y++) + { + const BYTE* WINPR_RESTRICT srcLine = + &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset]; + BYTE* WINPR_RESTRICT dstLine = + &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset]; + + SSIZE_T x = 0; + for (; x < width; x += 4) + { + const __m128i* src = (const __m128i*)&srcLine[(x + nXSrc) * srcByte]; + __m128i* dst = (__m128i*)&dstLine[(x + nXDst) * dstByte]; + const __m128i s0 = _mm_loadu_si128(src); + const __m128i s1 = _mm_loadu_si128(dst); + __m128i d0 = _mm_blendv_epi8(s1, s0, mask); + _mm_storeu_si128(dst, d0); + } + + for (; x < nWidth; x++) + { + const BYTE* src = &srcLine[(x + nXSrc) * srcByte]; + BYTE* dst = &dstLine[(x + nXDst) * dstByte]; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + } + } + + return PRIMITIVES_SUCCESS; +} + +static pstatus_t sse_image_copy_no_overlap_dst_alpha( + BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette, + UINT32 flags, SSIZE_T srcVMultiplier, SSIZE_T srcVOffset, SSIZE_T dstVMultiplier, + SSIZE_T dstVOffset) +{ + WINPR_ASSERT(pDstData); + WINPR_ASSERT(pSrcData); + + switch (SrcFormat) + { + case PIXEL_FORMAT_BGR24: + switch (DstFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return sse_image_copy_bgr24_bgrx32( + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep, + nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset); + default: + break; + } + break; + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + switch (DstFormat) + { + case PIXEL_FORMAT_BGRX32: + case PIXEL_FORMAT_BGRA32: + return sse_image_copy_bgrx32_bgrx32( + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep, + nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset); + default: + break; + } + break; + case PIXEL_FORMAT_RGBX32: + case PIXEL_FORMAT_RGBA32: + switch (DstFormat) + { + case PIXEL_FORMAT_RGBX32: + case PIXEL_FORMAT_RGBA32: + return sse_image_copy_bgrx32_bgrx32( + pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep, + nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset); + default: + break; + } + break; + default: + break; + } + + primitives_t* gen = primitives_get_generic(); + return gen->copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, + pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette, flags); +} + +static pstatus_t sse_image_copy_no_overlap(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat, + UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + const gdiPalette* WINPR_RESTRICT palette, UINT32 flags) +{ + const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE; + SSIZE_T srcVOffset = 0; + SSIZE_T srcVMultiplier = 1; + SSIZE_T dstVOffset = 0; + SSIZE_T dstVMultiplier = 1; + + if ((nWidth == 0) || (nHeight == 0)) + return PRIMITIVES_SUCCESS; + + if ((nHeight > INT32_MAX) || (nWidth > INT32_MAX)) + return -1; + + if (!pDstData || !pSrcData) + return -1; + + if (nDstStep == 0) + nDstStep = nWidth * FreeRDPGetBytesPerPixel(DstFormat); + + if (nSrcStep == 0) + nSrcStep = nWidth * FreeRDPGetBytesPerPixel(SrcFormat); + + if (vSrcVFlip) + { + srcVOffset = (nHeight - 1ll) * nSrcStep; + srcVMultiplier = -1; + } + + if (((flags & FREERDP_KEEP_DST_ALPHA) != 0) && FreeRDPColorHasAlpha(DstFormat)) + return sse_image_copy_no_overlap_dst_alpha(pDstData, DstFormat, nDstStep, nXDst, nYDst, + nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, + nXSrc, nYSrc, palette, flags, srcVMultiplier, + srcVOffset, dstVMultiplier, dstVOffset); + else if (FreeRDPAreColorFormatsEqualNoAlpha(SrcFormat, DstFormat)) + return generic_image_copy_no_overlap_memcpy(pDstData, DstFormat, nDstStep, nXDst, nYDst, + nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, + nXSrc, nYSrc, palette, srcVMultiplier, + srcVOffset, dstVMultiplier, dstVOffset, flags); + else + { + primitives_t* gen = primitives_get_generic(); + return gen->copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, + pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc, palette, flags); + } +} +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_copy_sse41(primitives_t* prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + if (IsProcessorFeaturePresent(PF_SSE4_1_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE4.1 optimizations"); + prims->copy_no_overlap = sse_image_copy_no_overlap; + } +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE4.1 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_set_sse2.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_set_sse2.c new file mode 100644 index 0000000000000000000000000000000000000000..47993adc9c9fdacee95ae20144ef325f640bdd48 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_set_sse2.c @@ -0,0 +1,235 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized routines to set a chunk of memory to a constant. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + */ + +#include + +#include +#include +#include +#include + +#include "prim_internal.h" +#include "prim_set.h" + +/* ========================================================================= */ +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include + +static primitives_t* generic = NULL; + +static pstatus_t sse2_set_8u(BYTE val, BYTE* WINPR_RESTRICT pDst, UINT32 len) +{ + BYTE byte = 0; + BYTE* dptr = NULL; + __m128i xmm0; + size_t count = 0; + + if (len < 16) + return generic->set_8u(val, pDst, len); + + byte = val; + dptr = pDst; + + /* Seek 16-byte alignment. */ + while ((ULONG_PTR)dptr & 0x0f) + { + *dptr++ = byte; + + if (--len == 0) + return PRIMITIVES_SUCCESS; + } + + xmm0 = mm_set1_epu8(byte); + /* Cover 256-byte chunks via SSE register stores. */ + count = len >> 8; + len -= count << 8; + + /* Do 256-byte chunks using one XMM register. */ + while (count--) + { + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + } + + /* Cover 16-byte chunks via SSE register stores. */ + count = len >> 4; + len -= count << 4; + + /* Do 16-byte chunks using one XMM register. */ + while (count--) + { + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 16; + } + + /* Do leftover bytes. */ + while (len--) + *dptr++ = byte; + + return PRIMITIVES_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ +static pstatus_t sse2_set_32u(UINT32 val, UINT32* WINPR_RESTRICT pDst, UINT32 len) +{ + const primitives_t* prim = primitives_get_generic(); + UINT32* dptr = pDst; + __m128i xmm0; + size_t count = 0; + + /* If really short, just do it here. */ + if (len < 32) + { + while (len--) + *dptr++ = val; + + return PRIMITIVES_SUCCESS; + } + + /* Assure we can reach 16-byte alignment. */ + if (((ULONG_PTR)dptr & 0x03) != 0) + { + return prim->set_32u(val, pDst, len); + } + + /* Seek 16-byte alignment. */ + while ((ULONG_PTR)dptr & 0x0f) + { + *dptr++ = val; + + if (--len == 0) + return PRIMITIVES_SUCCESS; + } + + xmm0 = mm_set1_epu32(val); + /* Cover 256-byte chunks via SSE register stores. */ + count = len >> 6; + len -= count << 6; + + /* Do 256-byte chunks using one XMM register. */ + while (count--) + { + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + } + + /* Cover 16-byte chunks via SSE register stores. */ + count = len >> 2; + len -= count << 2; + + /* Do 16-byte chunks using one XMM register. */ + while (count--) + { + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 4; + } + + /* Do leftover bytes. */ + while (len--) + *dptr++ = val; + + return PRIMITIVES_SUCCESS; +} + +/* ------------------------------------------------------------------------- */ +static pstatus_t sse2_set_32s(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 len) +{ + UINT32 uval = *((UINT32*)&val); + return sse2_set_32u(uval, (UINT32*)pDst, len); +} +#endif + +/* ------------------------------------------------------------------------- */ +void primitives_init_set_sse2(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_set(prims); + /* Pick tuned versions if possible. */ + + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE2 optimizations"); + prims->set_8u = sse2_set_8u; + prims->set_32s = sse2_set_32s; + prims->set_32u = sse2_set_32u; + } + +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE2 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_shift_sse3.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_shift_sse3.c new file mode 100644 index 0000000000000000000000000000000000000000..b6e708b4844d6f757fb31c8da31c48b31afca75e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_shift_sse3.c @@ -0,0 +1,164 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Shift operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include +#include + +#include "prim_shift.h" + +#include "prim_internal.h" +#include "prim_templates.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include + +static primitives_t* generic = NULL; + +/* ------------------------------------------------------------------------- */ +SSE3_SCD_ROUTINE(sse2_lShiftC_16s, INT16, generic->lShiftC_16s, _mm_slli_epi16, int16_t, + *dptr++ = (INT16)(((UINT16)*sptr++ << val) & 0xFFFF)) +/* ------------------------------------------------------------------------- */ +SSE3_SCD_ROUTINE(sse2_rShiftC_16s, INT16, generic->rShiftC_16s, _mm_srai_epi16, int16_t, + *dptr++ = *sptr++ >> val) +/* ------------------------------------------------------------------------- */ +SSE3_SCD_ROUTINE(sse2_lShiftC_16u, UINT16, generic->lShiftC_16u, _mm_slli_epi16, int16_t, + *dptr++ = (((UINT16)*sptr++ << val) & 0xFFFF)) +/* ------------------------------------------------------------------------- */ +SSE3_SCD_ROUTINE(sse2_rShiftC_16u, UINT16, generic->rShiftC_16u, _mm_srli_epi16, int16_t, + *dptr++ = *sptr++ >> val) + +static pstatus_t sse2_lShiftC_16s_inplace(INT16* WINPR_RESTRICT pSrcDst, UINT32 val, UINT32 len) +{ + const INT32 shifts = 2; + if (val == 0) + return PRIMITIVES_SUCCESS; + if (val >= 16) + return -1; + if (len < 16) /* pointless if too small */ + return generic->lShiftC_16s_inplace(pSrcDst, val, len); + + UINT32 offBeatMask = (1 << (shifts - 1)) - 1; + if ((ULONG_PTR)pSrcDst & offBeatMask) + { + /* Incrementing the pointer skips over 16-byte boundary. */ + return generic->lShiftC_16s_inplace(pSrcDst, val, len); + } + /* Get to the 16-byte boundary now. */ + const UINT32 rem = ((UINT_PTR)pSrcDst & 0x0f) / sizeof(INT16); + if (rem > 0) + { + const UINT32 add = 16 - rem; + pstatus_t status = generic->lShiftC_16s_inplace(pSrcDst, val, add); + if (status != PRIMITIVES_SUCCESS) + return status; + pSrcDst += add; + len -= add; + } + + /* Use 8 128-bit SSE registers. */ + uint32_t count = len >> (8 - shifts); + len -= count << (8 - shifts); + + while (count--) + { + const __m128i* src = (const __m128i*)pSrcDst; + + __m128i xmm0 = _mm_load_si128(src++); + __m128i xmm1 = _mm_load_si128(src++); + __m128i xmm2 = _mm_load_si128(src++); + __m128i xmm3 = _mm_load_si128(src++); + __m128i xmm4 = _mm_load_si128(src++); + __m128i xmm5 = _mm_load_si128(src++); + __m128i xmm6 = _mm_load_si128(src++); + __m128i xmm7 = _mm_load_si128(src); + + xmm0 = _mm_slli_epi16(xmm0, (int16_t)val); + xmm1 = _mm_slli_epi16(xmm1, (int16_t)val); + xmm2 = _mm_slli_epi16(xmm2, (int16_t)val); + xmm3 = _mm_slli_epi16(xmm3, (int16_t)val); + xmm4 = _mm_slli_epi16(xmm4, (int16_t)val); + xmm5 = _mm_slli_epi16(xmm5, (int16_t)val); + xmm6 = _mm_slli_epi16(xmm6, (int16_t)val); + xmm7 = _mm_slli_epi16(xmm7, (int16_t)val); + + __m128i* dst = (__m128i*)pSrcDst; + + _mm_store_si128(dst++, xmm0); + _mm_store_si128(dst++, xmm1); + _mm_store_si128(dst++, xmm2); + _mm_store_si128(dst++, xmm3); + _mm_store_si128(dst++, xmm4); + _mm_store_si128(dst++, xmm5); + _mm_store_si128(dst++, xmm6); + _mm_store_si128(dst++, xmm7); + + pSrcDst = (INT16*)dst; + } + + /* Use a single 128-bit SSE register. */ + count = len >> (5 - shifts); + len -= count << (5 - shifts); + while (count--) + { + const __m128i* src = (const __m128i*)pSrcDst; + __m128i xmm0 = LOAD_SI128(src); + + xmm0 = _mm_slli_epi16(xmm0, (int16_t)val); + + __m128i* dst = (__m128i*)pSrcDst; + _mm_store_si128(dst++, xmm0); + pSrcDst = (INT16*)dst; + } + + /* Finish off the remainder. */ + if (len > 0) + return generic->lShiftC_16s_inplace(pSrcDst, val, len); + + return PRIMITIVES_SUCCESS; +} +#endif + +/* Note: the IPP version will have to call ippLShiftC_16s or ippRShiftC_16s + * depending on the sign of val. To avoid using the deprecated inplace + * routines, a wrapper can use the src for the dest. + */ + +/* ------------------------------------------------------------------------- */ +void primitives_init_shift_sse3(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_shift(prims); + + if (IsProcessorFeaturePresent(PF_SSE2_INSTRUCTIONS_AVAILABLE) && + IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE2/SSE3 optimizations"); + prims->lShiftC_16s_inplace = sse2_lShiftC_16s_inplace; + prims->lShiftC_16s = sse2_lShiftC_16s; + prims->rShiftC_16s = sse2_rShiftC_16s; + prims->lShiftC_16u = sse2_lShiftC_16u; + prims->rShiftC_16u = sse2_rShiftC_16u; + } + +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSE3 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_sign_ssse3.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_sign_ssse3.c new file mode 100644 index 0000000000000000000000000000000000000000..0cac444c0d392ece1b90579758b5ed44d56390c8 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/sse/prim_sign_ssse3.c @@ -0,0 +1,190 @@ +/* FreeRDP: A Remote Desktop Protocol Client + * Optimized sign operations. + * vi:ts=4 sw=4: + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include +#include + +#include "prim_sign.h" + +#include "prim_internal.h" + +#if defined(SSE_AVX_INTRINSICS_ENABLED) +#include +#include + +static primitives_t* generic = NULL; + +/* ------------------------------------------------------------------------- */ +static pstatus_t ssse3_sign_16s(const INT16* WINPR_RESTRICT pSrc, INT16* WINPR_RESTRICT pDst, + UINT32 len) +{ + const INT16* sptr = pSrc; + INT16* dptr = pDst; + size_t count = 0; + + if (len < 16) + { + return generic->sign_16s(pSrc, pDst, len); + } + + /* Check for 16-byte alignment (eventually). */ + if ((ULONG_PTR)pDst & 0x01) + { + return generic->sign_16s(pSrc, pDst, len); + } + + /* Seek 16-byte alignment. */ + while ((ULONG_PTR)dptr & 0x0f) + { + INT16 src = *sptr++; + *dptr++ = WINPR_ASSERTING_INT_CAST(int16_t, (src < 0) ? (-1) : ((src > 0) ? 1 : 0)); + + if (--len == 0) + return PRIMITIVES_SUCCESS; + } + + /* Do 32-short chunks using 8 XMM registers. */ + count = len >> 5; /* / 32 */ + len -= count << 5; /* * 32 */ + + if ((ULONG_PTR)sptr & 0x0f) + { + /* Unaligned */ + while (count--) + { + __m128i xmm0; + __m128i xmm1; + __m128i xmm2; + __m128i xmm3; + __m128i xmm4; + __m128i xmm5; + __m128i xmm6; + __m128i xmm7; + xmm0 = _mm_set1_epi16(0x0001U); + xmm1 = _mm_set1_epi16(0x0001U); + xmm2 = _mm_set1_epi16(0x0001U); + xmm3 = _mm_set1_epi16(0x0001U); + xmm4 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += 8; + xmm5 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += 8; + xmm6 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += 8; + xmm7 = _mm_lddqu_si128((const __m128i*)sptr); + sptr += 8; + xmm0 = _mm_sign_epi16(xmm0, xmm4); + xmm1 = _mm_sign_epi16(xmm1, xmm5); + xmm2 = _mm_sign_epi16(xmm2, xmm6); + xmm3 = _mm_sign_epi16(xmm3, xmm7); + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 8; + _mm_store_si128((__m128i*)dptr, xmm1); + dptr += 8; + _mm_store_si128((__m128i*)dptr, xmm2); + dptr += 8; + _mm_store_si128((__m128i*)dptr, xmm3); + dptr += 8; + } + } + else + { + /* Aligned */ + while (count--) + { + __m128i xmm0; + __m128i xmm1; + __m128i xmm2; + __m128i xmm3; + __m128i xmm4; + __m128i xmm5; + __m128i xmm6; + __m128i xmm7; + xmm0 = _mm_set1_epi16(0x0001U); + xmm1 = _mm_set1_epi16(0x0001U); + xmm2 = _mm_set1_epi16(0x0001U); + xmm3 = _mm_set1_epi16(0x0001U); + xmm4 = _mm_load_si128((const __m128i*)sptr); + sptr += 8; + xmm5 = _mm_load_si128((const __m128i*)sptr); + sptr += 8; + xmm6 = _mm_load_si128((const __m128i*)sptr); + sptr += 8; + xmm7 = _mm_load_si128((const __m128i*)sptr); + sptr += 8; + xmm0 = _mm_sign_epi16(xmm0, xmm4); + xmm1 = _mm_sign_epi16(xmm1, xmm5); + xmm2 = _mm_sign_epi16(xmm2, xmm6); + xmm3 = _mm_sign_epi16(xmm3, xmm7); + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 8; + _mm_store_si128((__m128i*)dptr, xmm1); + dptr += 8; + _mm_store_si128((__m128i*)dptr, xmm2); + dptr += 8; + _mm_store_si128((__m128i*)dptr, xmm3); + dptr += 8; + } + } + + /* Do 8-short chunks using two XMM registers. */ + count = len >> 3; + len -= count << 3; + + while (count--) + { + __m128i xmm0 = _mm_set1_epi16(0x0001U); + __m128i xmm1 = LOAD_SI128(sptr); + sptr += 8; + xmm0 = _mm_sign_epi16(xmm0, xmm1); + _mm_store_si128((__m128i*)dptr, xmm0); + dptr += 8; + } + + /* Do leftovers. */ + while (len--) + { + INT16 src = *sptr++; + *dptr++ = WINPR_ASSERTING_INT_CAST(int16_t, (src < 0) ? -1 : ((src > 0) ? 1 : 0)); + } + + return PRIMITIVES_SUCCESS; +} + +#endif /* SSE_AVX_INTRINSICS_ENABLED */ + +/* ------------------------------------------------------------------------- */ +void primitives_init_sign_ssse3(primitives_t* WINPR_RESTRICT prims) +{ +#if defined(SSE_AVX_INTRINSICS_ENABLED) + generic = primitives_get_generic(); + primitives_init_sign(prims); + /* Pick tuned versions if possible. */ + /* I didn't spot an IPP version of this. */ + + if (IsProcessorFeaturePresentEx(PF_EX_SSSE3) && + IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE)) + { + WLog_VRB(PRIM_TAG, "SSE3/SSSE3 optimizations"); + prims->sign_16s = ssse3_sign_16s; + } + +#else + WLog_VRB(PRIM_TAG, "undefined WITH_SIMD or SSSE3/SSE3 intrinsics not available"); + WINPR_UNUSED(prims); +#endif +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7716f2993dc5cb4893346af852ad320896ee8925 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/CMakeLists.txt @@ -0,0 +1,39 @@ +set(MODULE_NAME "TestPrimitives") +set(MODULE_PREFIX "TEST_FREERDP_PRIMITIVES") + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c) + +set(${MODULE_PREFIX}_TESTS + TestPrimitivesAdd.c + TestPrimitivesAlphaComp.c + TestPrimitivesAndOr.c + TestPrimitivesColors.c + TestPrimitivesCopy.c + TestPrimitivesSet.c + TestPrimitivesShift.c + TestPrimitivesSign.c + TestPrimitivesYUV.c + TestPrimitivesYCbCr.c + TestPrimitivesYCoCg.c +) + +create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS}) + +set(${MODULE_PREFIX}_EXTRA_SRCS prim_test.c prim_test.h measure.h) + +add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS} ${${MODULE_PREFIX}_EXTRA_SRCS}) + +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr freerdp) + +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${${MODULE_PREFIX}_TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Test") diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAdd.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAdd.c new file mode 100644 index 0000000000000000000000000000000000000000..9edbae9e384179de529da21b95cb8452abe02e83 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAdd.c @@ -0,0 +1,82 @@ +/* test_add.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include "prim_test.h" + +#define FUNC_TEST_SIZE 65536 +/* ========================================================================= */ +static BOOL test_add16s_func(void) +{ + pstatus_t status = 0; + + INT16 ALIGN(src1[FUNC_TEST_SIZE + 3]) = { 0 }; + INT16 ALIGN(src2[FUNC_TEST_SIZE + 3]) = { 0 }; + INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]) = { 0 }; + INT16 ALIGN(d2[FUNC_TEST_SIZE + 3]) = { 0 }; + + winpr_RAND(src1, sizeof(src1)); + winpr_RAND(src2, sizeof(src2)); + status = generic->add_16s(src1 + 1, src2 + 1, d1 + 1, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + /* Unaligned */ + status = optimized->add_16s(src1 + 1, src2 + 1, d2 + 2, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_add16s_speed(void) +{ + BYTE ALIGN(src1[MAX_TEST_SIZE + 3]); + BYTE ALIGN(src2[MAX_TEST_SIZE + 3]); + BYTE ALIGN(dst[MAX_TEST_SIZE + 3]); + + if (!g_TestPrimitivesPerformance) + return TRUE; + + winpr_RAND(src1, sizeof(src1)); + winpr_RAND(src2, sizeof(src2)); + + if (!speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->add_16s, + (speed_test_fkt)optimized->add_16s, src1, src2, dst, FUNC_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +int TestPrimitivesAdd(int argc, char* argv[]) +{ + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + prim_test_setup(FALSE); + if (!test_add16s_func()) + return -1; + + if (g_TestPrimitivesPerformance) + { + if (!test_add16s_speed()) + return -1; + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c new file mode 100644 index 0000000000000000000000000000000000000000..78fce4889bc5ceeb3f7904cfe99f1080f6e9b647 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAlphaComp.c @@ -0,0 +1,202 @@ +/* test_alphaComp.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include + +#include "prim_test.h" + +#define MAX_BLOCK_SIZE 256 +#define SIZE_SQUARED (MAX_BLOCK_SIZE * MAX_BLOCK_SIZE) + +/* ========================================================================= */ +#define ALF(_c_) (((_c_)&0xFF000000U) >> 24) +#define RED(_c_) (((_c_)&0x00FF0000U) >> 16) +#define GRN(_c_) (((_c_)&0x0000FF00U) >> 8) +#define BLU(_c_) ((_c_)&0x000000FFU) +#define TOLERANCE 1 +static inline const UINT32* PIXEL(const BYTE* _addr_, UINT32 _bytes_, UINT32 _x_, UINT32 _y_) +{ + const BYTE* addr = _addr_ + 1ULL * _x_ * sizeof(UINT32) + 1ULL * _y_ * _bytes_; + return (const UINT32*)addr; +} + +#define SRC1_WIDTH 6 +#define SRC1_HEIGHT 6 +#define SRC2_WIDTH 7 +#define SRC2_HEIGHT 7 +#define DST_WIDTH 9 +#define DST_HEIGHT 9 +#define TEST_WIDTH 4 +#define TEST_HEIGHT 5 + +/* ------------------------------------------------------------------------- */ +static UINT32 alpha_add(UINT32 c1, UINT32 c2) +{ + UINT32 a1 = ALF(c1); + UINT32 r1 = RED(c1); + UINT32 g1 = GRN(c1); + UINT32 b1 = BLU(c1); + UINT32 a2 = ALF(c2); + UINT32 r2 = RED(c2); + UINT32 g2 = GRN(c2); + UINT32 b2 = BLU(c2); + UINT32 a3 = ((a1 * a1 + (255 - a1) * a2) / 255) & 0xff; + UINT32 r3 = ((a1 * r1 + (255 - a1) * r2) / 255) & 0xff; + UINT32 g3 = ((a1 * g1 + (255 - a1) * g2) / 255) & 0xff; + UINT32 b3 = ((a1 * b1 + (255 - a1) * b2) / 255) & 0xff; + return (a3 << 24) | (r3 << 16) | (g3 << 8) | b3; +} + +/* ------------------------------------------------------------------------- */ +static UINT32 colordist(UINT32 c1, UINT32 c2) +{ + int d = 0; + int maxd = 0; + d = ABS((INT32)(ALF(c1) - ALF(c2))); + + if (d > maxd) + maxd = d; + + d = ABS((INT32)(RED(c1) - RED(c2))); + + if (d > maxd) + maxd = d; + + d = ABS((INT32)(GRN(c1) - GRN(c2))); + + if (d > maxd) + maxd = d; + + d = ABS((INT32)(BLU(c1) - BLU(c2))); + + if (d > maxd) + maxd = d; + + return maxd; +} + +/* ------------------------------------------------------------------------- */ +static BOOL check(const BYTE* pSrc1, UINT32 src1Step, const BYTE* pSrc2, UINT32 src2Step, + BYTE* pDst, UINT32 dstStep, UINT32 width, UINT32 height) +{ + for (UINT32 y = 0; y < height; ++y) + { + for (UINT32 x = 0; x < width; ++x) + { + UINT32 s1 = *PIXEL(pSrc1, src1Step, x, y); + UINT32 s2 = *PIXEL(pSrc2, src2Step, x, y); + UINT32 c0 = alpha_add(s1, s2); + UINT32 c1 = *PIXEL(pDst, dstStep, x, y); + + if (colordist(c0, c1) > TOLERANCE) + { + printf("alphaComp-general: [%" PRIu32 ",%" PRIu32 "] 0x%08" PRIx32 "+0x%08" PRIx32 + "=0x%08" PRIx32 ", got 0x%08" PRIx32 "\n", + x, y, s1, s2, c0, c1); + return FALSE; + } + } + } + + return TRUE; +} + +static BOOL test_alphaComp_func(void) +{ + pstatus_t status = 0; + BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT * 4]) = { 0 }; + BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT * 4]) = { 0 }; + BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT * 4]) = { 0 }; + UINT32* ptr = NULL; + winpr_RAND(src1, sizeof(src1)); + /* Special-case the first two values */ + src1[0] &= 0x00FFFFFFU; + src1[1] |= 0xFF000000U; + winpr_RAND(src2, sizeof(src2)); + /* Set the second operand to fully-opaque. */ + ptr = (UINT32*)src2; + + for (UINT32 i = 0; i < sizeof(src2) / 4; ++i) + *ptr++ |= 0xFF000000U; + + status = generic->alphaComp_argb(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, + 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH, + TEST_HEIGHT)) + return FALSE; + + status = optimized->alphaComp_argb((const BYTE*)src1, 4 * SRC1_WIDTH, (const BYTE*)src2, + 4 * SRC2_WIDTH, (BYTE*)dst1, 4 * DST_WIDTH, TEST_WIDTH, + TEST_HEIGHT); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check(src1, 4 * SRC1_WIDTH, src2, 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH, + TEST_HEIGHT)) + return FALSE; + + return TRUE; +} + +static int test_alphaComp_speed(void) +{ + BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]) = { 0 }; + BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]) = { 0 }; + BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]) = { 0 }; + UINT32* ptr = NULL; + + winpr_RAND(src1, sizeof(src1)); + /* Special-case the first two values */ + src1[0] &= 0x00FFFFFFU; + src1[1] |= 0xFF000000U; + winpr_RAND(src2, sizeof(src2)); + /* Set the second operand to fully-opaque. */ + ptr = (UINT32*)src2; + + for (UINT32 i = 0; i < sizeof(src2) / 4; ++i) + *ptr++ |= 0xFF000000U; + + if (!speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->alphaComp_argb, + (speed_test_fkt)optimized->alphaComp_argb, src1, 4 * SRC1_WIDTH, src2, + 4 * SRC2_WIDTH, dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT)) + return FALSE; + + return TRUE; +} + +int TestPrimitivesAlphaComp(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + prim_test_setup(FALSE); + + if (!test_alphaComp_func()) + return -1; + + if (g_TestPrimitivesPerformance) + { + if (!test_alphaComp_speed()) + return -1; + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAndOr.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAndOr.c new file mode 100644 index 0000000000000000000000000000000000000000..8f3b141de52ad5dd8216790ca1a84afbbb70dca6 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesAndOr.c @@ -0,0 +1,169 @@ +/* test_andor.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include + +#include "prim_test.h" + +#define FUNC_TEST_SIZE 65536 + +#define VALUE (0xA5A5A5A5U) + +/* ========================================================================= */ +static BOOL test_and_32u_impl(const char* name, __andC_32u_t fkt, const UINT32* src, + const UINT32 val, UINT32* dst, size_t size) +{ + pstatus_t status = fkt(src, val, dst, WINPR_ASSERTING_INT_CAST(int32_t, size)); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + for (size_t i = 0; i < size; ++i) + { + if (dst[i] != (src[i] & val)) + { + + printf("AND %s FAIL[%" PRIuz "] 0x%08" PRIx32 "&0x%08" PRIx32 "=0x%08" PRIx32 + ", got 0x%08" PRIx32 "\n", + name, i, src[i], val, (src[i] & val), dst[i]); + + return FALSE; + } + } + + return TRUE; +} + +static BOOL test_and_32u_func(void) +{ + UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 }; + UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 }; + + winpr_RAND(src, sizeof(src)); + + if (!test_and_32u_impl("generic->andC_32u aligned", generic->andC_32u, src + 1, VALUE, dst + 1, + FUNC_TEST_SIZE)) + return FALSE; + if (!test_and_32u_impl("generic->andC_32u unaligned", generic->andC_32u, src + 1, VALUE, + dst + 2, FUNC_TEST_SIZE)) + return FALSE; + if (!test_and_32u_impl("optimized->andC_32u aligned", optimized->andC_32u, src + 1, VALUE, + dst + 1, FUNC_TEST_SIZE)) + return FALSE; + if (!test_and_32u_impl("optimized->andC_32u unaligned", optimized->andC_32u, src + 1, VALUE, + dst + 2, FUNC_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_and_32u_speed(void) +{ + UINT32 ALIGN(src[MAX_TEST_SIZE + 3]) = { 0 }; + UINT32 ALIGN(dst[MAX_TEST_SIZE + 3]) = { 0 }; + + winpr_RAND(src, sizeof(src)); + + if (!speed_test("andC_32u", "aligned", g_Iterations, (speed_test_fkt)generic->andC_32u, + (speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 1, MAX_TEST_SIZE)) + return FALSE; + if (!speed_test("andC_32u", "unaligned", g_Iterations, (speed_test_fkt)generic->andC_32u, + (speed_test_fkt)optimized->andC_32u, src + 1, VALUE, dst + 2, MAX_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +/* ========================================================================= */ +static BOOL check(const UINT32* src, const UINT32* dst, UINT32 size, UINT32 value) +{ + for (UINT32 i = 0; i < size; ++i) + { + if (dst[i] != (src[i] | value)) + { + printf("OR-general general FAIL[%" PRIu32 "] 0x%08" PRIx32 "&0x%08" PRIx32 + "=0x%08" PRIx32 ", got 0x%08" PRIx32 "\n", + i, src[i], value, src[i] | value, dst[i]); + return FALSE; + } + } + + return TRUE; +} + +static BOOL test_or_32u_func(void) +{ + pstatus_t status = 0; + UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 }; + UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 }; + + winpr_RAND(src, sizeof(src)); + + status = generic->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE)) + return FALSE; + + status = optimized->orC_32u(src + 1, VALUE, dst + 1, FUNC_TEST_SIZE); + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check(src + 1, dst + 1, FUNC_TEST_SIZE, VALUE)) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_or_32u_speed(void) +{ + UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 }; + UINT32 ALIGN(dst[FUNC_TEST_SIZE + 3]) = { 0 }; + + winpr_RAND(src, sizeof(src)); + + if (!speed_test("add16s", "aligned", g_Iterations, (speed_test_fkt)generic->orC_32u, + (speed_test_fkt)optimized->orC_32u, src + 1, VALUE, dst + 1, FUNC_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +int TestPrimitivesAndOr(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + prim_test_setup(FALSE); + + if (!test_and_32u_func()) + return -1; + + if (!test_or_32u_func()) + return -1; + + if (g_TestPrimitivesPerformance) + { + if (!test_and_32u_speed()) + return -1; + if (!test_or_32u_speed()) + return -1; + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesColors.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesColors.c new file mode 100644 index 0000000000000000000000000000000000000000..c44dafde579235988869ae413a4b3c36563994dc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesColors.c @@ -0,0 +1,298 @@ +/* test_colors.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include + +#include "prim_test.h" + +/* ------------------------------------------------------------------------- */ +static BOOL test_RGBToRGB_16s8u_P3AC4R_func(prim_size_t roi, DWORD DstFormat) +{ + INT16* r = NULL; + INT16* g = NULL; + INT16* b = NULL; + BYTE* out1 = NULL; + BYTE* out2 = NULL; + BOOL failed = FALSE; + const INT16* ptrs[3]; + const UINT32 rgbStride = roi.width * 2; + const UINT32 dstStride = roi.width * 4; + PROFILER_DEFINE(genericProf) + PROFILER_DEFINE(optProf) + PROFILER_CREATE(genericProf, "RGBToRGB_16s8u_P3AC4R-GENERIC") + PROFILER_CREATE(optProf, "RGBToRGB_16s8u_P3AC4R-OPTIMIZED") + r = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16); + g = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16); + b = winpr_aligned_calloc(1, 1ULL * rgbStride * roi.height, 16); + out1 = winpr_aligned_calloc(1, 1ULL * dstStride * roi.height, 16); + out2 = winpr_aligned_calloc(1, 1ULL * dstStride * roi.height, 16); + + if (!r || !g || !b || !out1 || !out2) + goto fail; + +#if 0 + { + for (UINT32 y = 0; y < roi.height; y++) + { + for (UINT32 x = 0; x < roi.width; x++) + { + r[y * roi.width + x] = 0x01; + g[y * roi.width + x] = 0x02; + b[y * roi.width + x] = 0x04; + } + } + } +#else + winpr_RAND(r, 1ULL * rgbStride * roi.height); + winpr_RAND(g, 1ULL * rgbStride * roi.height); + winpr_RAND(b, 1ULL * rgbStride * roi.height); +#endif + ptrs[0] = r; + ptrs[1] = g; + ptrs[2] = b; + PROFILER_ENTER(genericProf) + + if (generic->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out1, dstStride, DstFormat, &roi) != + PRIMITIVES_SUCCESS) + goto fail; + + PROFILER_EXIT(genericProf) + PROFILER_ENTER(optProf) + + if (optimized->RGBToRGB_16s8u_P3AC4R(ptrs, rgbStride, out2, dstStride, DstFormat, &roi) != + PRIMITIVES_SUCCESS) + goto fail; + + PROFILER_EXIT(optProf) + + if (memcmp(out1, out2, 1ULL * dstStride * roi.height) != 0) + { + for (UINT64 i = 0; i < 1ull * roi.width * roi.height; ++i) + { + const UINT32 o1 = FreeRDPReadColor(out1 + 4 * i, DstFormat); + const UINT32 o2 = FreeRDPReadColor(out2 + 4 * i, DstFormat); + + if (o1 != o2) + { + printf("RGBToRGB_16s8u_P3AC4R FAIL: out1[%" PRIu64 "]=0x%08" PRIx8 " out2[%" PRIu64 + "]=0x%08" PRIx8 "\n", + i, out1[i], i, out2[i]); + failed = TRUE; + } + } + } + + printf("Results for %" PRIu32 "x%" PRIu32 " [%s]", roi.width, roi.height, + FreeRDPGetColorFormatName(DstFormat)); + PROFILER_PRINT_HEADER + PROFILER_PRINT(genericProf) + PROFILER_PRINT(optProf) + PROFILER_PRINT_FOOTER +fail: + PROFILER_FREE(genericProf) + PROFILER_FREE(optProf) + winpr_aligned_free(r); + winpr_aligned_free(g); + winpr_aligned_free(b); + winpr_aligned_free(out1); + winpr_aligned_free(out2); + return !failed; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(void) +{ + union + { + const INT16** cpv; + INT16** pv; + } cnv; + const prim_size_t roi64x64 = { 64, 64 }; + INT16 ALIGN(r[4096 + 1]); + INT16 ALIGN(g[4096 + 1]); + INT16 ALIGN(b[4096 + 1]); + UINT32 ALIGN(dst[4096 + 1]); + INT16* ptrs[3]; + winpr_RAND(r, sizeof(r)); + winpr_RAND(g, sizeof(g)); + winpr_RAND(b, sizeof(b)); + + /* clear upper bytes */ + for (int i = 0; i < 4096; ++i) + { + r[i] &= 0x00FFU; + g[i] &= 0x00FFU; + b[i] &= 0x00FFU; + } + + ptrs[0] = r + 1; + ptrs[1] = g + 1; + ptrs[2] = b + 1; + + cnv.pv = ptrs; + if (!speed_test("RGBToRGB_16s8u_P3AC4R", "aligned", g_Iterations, + generic->RGBToRGB_16s8u_P3AC4R, optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, + 64 * 2, (BYTE*)dst, 64 * 4, &roi64x64)) + return FALSE; + + if (!speed_test("RGBToRGB_16s8u_P3AC4R", "unaligned", g_Iterations, + generic->RGBToRGB_16s8u_P3AC4R, optimized->RGBToRGB_16s8u_P3AC4R, cnv.cpv, + 64 * 2, ((BYTE*)dst) + 1, 64 * 4, &roi64x64)) + return FALSE; + + return TRUE; +} + +/* ========================================================================= */ +static BOOL test_yCbCrToRGB_16s16s_P3P3_func(void) +{ + pstatus_t status = 0; + INT16 ALIGN(y[4096]) = { 0 }; + INT16 ALIGN(cb[4096]) = { 0 }; + INT16 ALIGN(cr[4096]) = { 0 }; + INT16 ALIGN(r1[4096]) = { 0 }; + INT16 ALIGN(g1[4096]) = { 0 }; + INT16 ALIGN(b1[4096]) = { 0 }; + INT16 ALIGN(r2[4096]) = { 0 }; + INT16 ALIGN(g2[4096]) = { 0 }; + INT16 ALIGN(b2[4096]) = { 0 }; + const INT16* in[3]; + INT16* out1[3]; + INT16* out2[3]; + prim_size_t roi = { 64, 64 }; + winpr_RAND(y, sizeof(y)); + winpr_RAND(cb, sizeof(cb)); + winpr_RAND(cr, sizeof(cr)); + + /* Normalize to 11.5 fixed radix */ + for (int i = 0; i < 4096; ++i) + { + y[i] &= 0x1FE0U; + cb[i] &= 0x1FE0U; + cr[i] &= 0x1FE0U; + } + + in[0] = y; + in[1] = cb; + in[2] = cr; + out1[0] = r1; + out1[1] = g1; + out1[2] = b1; + out2[0] = r2; + out2[1] = g2; + out2[2] = b2; + status = generic->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out1, 64 * 2, &roi); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->yCbCrToRGB_16s16s_P3P3(in, 64 * 2, out2, 64 * 2, &roi); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + for (int i = 0; i < 4096; ++i) + { + if ((ABS(r1[i] - r2[i]) > 1) || (ABS(g1[i] - g2[i]) > 1) || (ABS(b1[i] - b2[i]) > 1)) + { + printf("YCbCrToRGB-SSE FAIL[%d]: %" PRId16 ",%" PRId16 ",%" PRId16 " vs %" PRId16 + ",%" PRId16 ",%" PRId16 "\n", + i, r1[i], g1[i], b1[i], r2[i], g2[i], b2[i]); + return FALSE; + } + } + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static int test_yCbCrToRGB_16s16s_P3P3_speed(void) +{ + prim_size_t roi = { 64, 64 }; + INT16 ALIGN(y[4096]); + INT16 ALIGN(cb[4096]); + INT16 ALIGN(cr[4096]); + INT16 ALIGN(r[4096]); + INT16 ALIGN(g[4096]); + INT16 ALIGN(b[4096]); + const INT16* input[3]; + INT16* output[3]; + winpr_RAND(y, sizeof(y)); + winpr_RAND(cb, sizeof(cb)); + winpr_RAND(cr, sizeof(cr)); + + /* Normalize to 11.5 fixed radix */ + for (int i = 0; i < 4096; ++i) + { + y[i] &= 0x1FE0U; + cb[i] &= 0x1FE0U; + cr[i] &= 0x1FE0U; + } + + input[0] = y; + input[1] = cb; + input[2] = cr; + output[0] = r; + output[1] = g; + output[2] = b; + + if (!speed_test("yCbCrToRGB_16s16s_P3P3", "aligned", g_Iterations, + (speed_test_fkt)generic->yCbCrToRGB_16s16s_P3P3, + (speed_test_fkt)optimized->yCbCrToRGB_16s16s_P3P3, input, 64 * 2, output, + 64 * 2, &roi)) + return FALSE; + + return TRUE; +} + +int TestPrimitivesColors(int argc, char* argv[]) +{ + const DWORD formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_ABGR32, + PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, + PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; + prim_size_t roi = { 1920 / 4, 1080 / 4 }; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + prim_test_setup(FALSE); + + for (UINT32 x = 0; x < sizeof(formats) / sizeof(formats[0]); x++) + { + if (!test_RGBToRGB_16s8u_P3AC4R_func(roi, formats[x])) + return 1; + +#if 0 + + if (g_TestPrimitivesPerformance) + { + if (!test_RGBToRGB_16s8u_P3AC4R_speed()) + return 1; + } + + if (!test_yCbCrToRGB_16s16s_P3P3_func()) + return 1; + + if (g_TestPrimitivesPerformance) + { + if (!test_yCbCrToRGB_16s16s_P3P3_speed()) + return 1; + } + +#endif + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesCopy.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesCopy.c new file mode 100644 index 0000000000000000000000000000000000000000..1c074f5179b626359154f4f44d8c548fc26689ab --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesCopy.c @@ -0,0 +1,287 @@ +/* test_copy.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include + +#include +#include "prim_test.h" + +#define COPY_TESTSIZE (256 * 2 + 16 * 2 + 15 + 15) + +/* ------------------------------------------------------------------------- */ +static BOOL test_copy8u_func(void) +{ + primitives_t* prims = primitives_get(); + BYTE ALIGN(data[COPY_TESTSIZE + 15]) = { 0 }; + winpr_RAND(data, sizeof(data)); + + for (int soff = 0; soff < 16; ++soff) + { + for (int doff = 0; doff < 16; ++doff) + { + for (int length = 1; length <= COPY_TESTSIZE - doff; ++length) + { + BYTE ALIGN(dest[COPY_TESTSIZE + 15]) = { 0 }; + + if (prims->copy_8u(data + soff, dest + doff, length) != PRIMITIVES_SUCCESS) + return FALSE; + + for (int i = 0; i < length; ++i) + { + if (dest[i + doff] != data[i + soff]) + { + printf("COPY8U FAIL: off=%d len=%d, dest[%d]=0x%02" PRIx8 "" + "data[%d]=0x%02" PRIx8 "\n", + doff, length, i + doff, dest[i + doff], i + soff, data[i + soff]); + return FALSE; + } + } + } + } + } + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_copy8u_speed(void) +{ + BYTE ALIGN(src[MAX_TEST_SIZE + 4]); + BYTE ALIGN(dst[MAX_TEST_SIZE + 4]); + + if (!speed_test("copy_8u", "aligned", g_Iterations, (speed_test_fkt)generic->copy_8u, + (speed_test_fkt)optimized->copy_8u, src, dst, MAX_TEST_SIZE)) + return FALSE; + + if (!speed_test("copy_8u", "unaligned", g_Iterations, (speed_test_fkt)generic->copy_8u, + (speed_test_fkt)optimized->copy_8u, src + 1, dst + 1, MAX_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +static BYTE* rand_alloc(size_t w, size_t h, size_t bpp, size_t pad, BYTE** copy) +{ + const size_t s = w * bpp + pad; + BYTE* ptr = calloc(s, h); + if (!ptr) + return NULL; + + winpr_RAND(ptr, s * h); + + if (copy) + { + BYTE* ptr2 = calloc(s, h); + if (!ptr2) + { + free(ptr); + return NULL; + } + memcpy(ptr2, ptr, s * h); + *copy = ptr2; + } + return ptr; +} + +static size_t runcount = 0; + +static BOOL test_copy_no_overlap_off(BOOL verbose, UINT32 srcFormat, UINT32 dstFormat, UINT32 flags, + UINT32 pad, UINT32 w, UINT32 h, UINT32 dxoff, UINT32 dyoff, + UINT32 sxoff, UINT32 syoff) +{ + BOOL rc = FALSE; + primitives_t* gen = primitives_get_generic(); + primitives_t* prims = primitives_get(); + if (!gen || !prims) + return FALSE; + + runcount++; + + WINPR_ASSERT(dxoff < w); + WINPR_ASSERT(sxoff < w); + WINPR_ASSERT(dyoff < h); + WINPR_ASSERT(syoff < h); + + const UINT32 sbpp = FreeRDPGetBytesPerPixel(srcFormat); + const UINT32 dbpp = FreeRDPGetBytesPerPixel(dstFormat); + + if (verbose) + { + (void)fprintf(stderr, + "run src: %s, dst: %s [flags 0x%08" PRIx32 "] %" PRIu32 "x%" PRIu32 + ", soff=%" PRIu32 "x%" PRIu32 ", doff=%" PRIu32 "x%" PRIu32 ", pad=%" PRIu32 + "\n", + FreeRDPGetColorFormatName(srcFormat), FreeRDPGetColorFormatName(dstFormat), + flags, w, h, sxoff, syoff, dxoff, dyoff, pad); + } + + const UINT32 sstride = (w + sxoff) * sbpp + pad; + const UINT32 dstride = (w + dxoff) * dbpp + pad; + BYTE* dst2 = NULL; + BYTE* src2 = NULL; + BYTE* dst1 = rand_alloc(w + dxoff, h + dyoff, dbpp, pad, &dst2); + BYTE* src1 = rand_alloc(w + sxoff, h + syoff, sbpp, pad, &src2); + if (!dst1 || !dst2 || !src1 || !src2) + goto fail; + + if (gen->copy_no_overlap(dst1, dstFormat, dstride, dxoff, dyoff, w, h, src1, srcFormat, sstride, + sxoff, syoff, NULL, flags) != PRIMITIVES_SUCCESS) + goto fail; + + if (memcmp(src1, src2, 1ULL * sstride * h) != 0) + goto fail; + + if (prims->copy_no_overlap(dst2, dstFormat, dstride, dxoff, dyoff, w, h, src1, srcFormat, + sstride, sxoff, syoff, NULL, flags) != PRIMITIVES_SUCCESS) + goto fail; + + if (memcmp(src1, src2, 1ULL * sstride * h) != 0) + goto fail; + + if (memcmp(dst1, dst2, 1ULL * dstride * h) != 0) + goto fail; + + if (flags == FREERDP_KEEP_DST_ALPHA) + { + for (size_t y = 0; y < h; y++) + { + const BYTE* d1 = &dst1[(y + dyoff) * dstride]; + const BYTE* d2 = &dst2[(y + dyoff) * dstride]; + for (size_t x = 0; x < w; x++) + { + const UINT32 c1 = FreeRDPReadColor(&d1[(x + dxoff) * dbpp], dstFormat); + const UINT32 c2 = FreeRDPReadColor(&d2[(x + dxoff) * dbpp], dstFormat); + BYTE a1 = 0; + BYTE a2 = 0; + FreeRDPSplitColor(c1, dstFormat, NULL, NULL, NULL, &a1, NULL); + FreeRDPSplitColor(c2, dstFormat, NULL, NULL, NULL, &a2, NULL); + if (a1 != a2) + goto fail; + } + } + } + rc = TRUE; + +fail: + if (!rc) + { + (void)fprintf(stderr, "failed to compare copy_no_overlap(%s -> %s [0x%08" PRIx32 "])\n", + FreeRDPGetColorFormatName(srcFormat), FreeRDPGetColorFormatName(dstFormat), + flags); + } + free(dst1); + free(dst2); + free(src1); + free(src2); + return rc; +} + +static BOOL test_copy_no_overlap(BOOL verbose, UINT32 srcFormat, UINT32 dstFormat, UINT32 flags, + UINT32 width, UINT32 height) +{ + BOOL rc = TRUE; + const UINT32 mw = 4; + const UINT32 mh = 4; + for (UINT32 dxoff = 0; dxoff < mw; dxoff++) + { + for (UINT32 dyoff = 0; dyoff <= mh; dyoff++) + { + for (UINT32 sxoff = 0; sxoff <= mw; sxoff++) + { + for (UINT32 syoff = 0; syoff <= mh; syoff++) + { + /* We need minimum alignment of 8 bytes. + * AVX2 can read 8 pixels (at most 8x4=32 bytes) per step + * if we have 24bpp input that is 24 bytes with 8 bytes read + * out of bound */ + for (UINT32 pad = 8; pad <= 12; pad++) + { + if (!test_copy_no_overlap_off(verbose, srcFormat, dstFormat, flags, pad, + width, height, dxoff, dyoff, sxoff, syoff)) + rc = FALSE; + } + } + } + } + } + + return rc; +} + +int TestPrimitivesCopy(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + const BOOL verbose = argc > 1; + + prim_test_setup(FALSE); + + if (!test_copy8u_func()) + return 1; + + if (g_TestPrimitivesPerformance) + { + if (!test_copy8u_speed()) + return 1; + } + + const UINT32 flags[] = { + FREERDP_FLIP_NONE, + FREERDP_KEEP_DST_ALPHA, + FREERDP_FLIP_HORIZONTAL, + FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_HORIZONTAL, +#if 0 + FREERDP_FLIP_VERTICAL, + FREERDP_FLIP_VERTICAL | FREERDP_FLIP_HORIZONTAL, + FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_VERTICAL, + FREERDP_KEEP_DST_ALPHA | FREERDP_FLIP_VERTICAL | FREERDP_FLIP_HORIZONTAL +#endif + }; + const UINT32 formats[] = { + PIXEL_FORMAT_BGRA32, + PIXEL_FORMAT_BGRX32, + PIXEL_FORMAT_BGR24 +#if 0 /* Only the previous 3 have SIMD optimizations, so skip the rest */ + , PIXEL_FORMAT_RGB24, + PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_XBGR32, + PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32 +#endif + }; + + int rc = 0; + for (size_t z = 0; z < ARRAYSIZE(flags); z++) + { + const UINT32 flag = flags[z]; + for (size_t x = 0; x < ARRAYSIZE(formats); x++) + { + const UINT32 sformat = formats[x]; + for (size_t y = 0; y < ARRAYSIZE(formats); y++) + { + const UINT32 dformat = formats[y]; + + if (!test_copy_no_overlap(verbose, sformat, dformat, flag, 21, 17)) + rc = -1; + } + } + } + + if (verbose) + (void)fprintf(stderr, "runcount=%" PRIuz "\n", runcount); + + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesSet.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesSet.c new file mode 100644 index 0000000000000000000000000000000000000000..c6cefcc799c9673d19783a2fbebeb0fb2369bedf --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesSet.c @@ -0,0 +1,274 @@ +/* test_set.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include "prim_test.h" + +/* ------------------------------------------------------------------------- */ +static BOOL check8(const BYTE* src, UINT32 length, UINT32 offset, BYTE value) +{ + for (UINT32 i = 0; i < length; ++i) + { + if (src[offset + i] != value) + { + printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%02" PRIx8 + "\n", + offset, length, i + offset, src[i + offset]); + return FALSE; + } + } + + return TRUE; +} + +static BOOL test_set8u_func(void) +{ + pstatus_t status = 0; + + for (UINT32 off = 0; off < 16; ++off) + { + BYTE dest[1024]; + + memset(dest, 3, sizeof(dest)); + for (UINT32 len = 1; len < 48 - off; ++len) + { + status = generic->set_8u(0xa5, dest + off, len); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check8(dest, len, off, 0xa5)) + return FALSE; + } + } + + for (UINT32 off = 0; off < 16; ++off) + { + BYTE dest[1024]; + + memset(dest, 3, sizeof(dest)); + for (UINT32 len = 1; len < 48 - off; ++len) + { + status = optimized->set_8u(0xa5, dest + off, len); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check8(dest, len, off, 0xa5)) + return FALSE; + } + } + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_set8u_speed(void) +{ + BYTE dest[1024]; + BYTE value = 0; + + for (UINT32 x = 0; x < 16; x++) + { + winpr_RAND(&value, sizeof(value)); + + if (!speed_test("set_8u", "", g_Iterations, (speed_test_fkt)generic->set_8u, + (speed_test_fkt)optimized->set_8u, value, dest + x, x)) + return FALSE; + } + + return TRUE; +} + +static BOOL check32s(const INT32* src, UINT32 length, UINT32 offset, INT32 value) +{ + for (UINT32 i = 0; i < length; ++i) + { + if (src[offset + i] != value) + { + printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32 + "\n", + offset, length, i + offset, src[i + offset]); + return FALSE; + } + } + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_set32s_func(void) +{ + pstatus_t status = 0; + const INT32 value = -0x12345678; + + for (UINT32 off = 0; off < 16; ++off) + { + INT32 dest[1024] = { 0 }; + + for (UINT32 len = 1; len < 48 - off; ++len) + { + status = generic->set_32s(value, dest + off, len); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32s(dest, len, off, value)) + return FALSE; + } + } + + for (UINT32 off = 0; off < 16; ++off) + { + INT32 dest[1024] = { 0 }; + + for (UINT32 len = 1; len < 48 - off; ++len) + { + status = optimized->set_32s(value, dest + off, len); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32s(dest, len, off, value)) + return FALSE; + } + } + + return TRUE; +} + +static BOOL check32u(const UINT32* src, UINT32 length, UINT32 offset, UINT32 value) +{ + for (UINT32 i = 0; i < length; ++i) + { + if (src[offset + i] != value) + { + printf("SET8U FAILED: off=%" PRIu32 " len=%" PRIu32 " dest[%" PRIu32 "]=0x%08" PRIx32 + "\n", + offset, length, i + offset, src[i + offset]); + return FALSE; + } + } + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_set32u_func(void) +{ + pstatus_t status = 0; + const UINT32 value = 0xABCDEF12; + + for (UINT32 off = 0; off < 16; ++off) + { + UINT32 dest[1024] = { 0 }; + + for (UINT32 len = 1; len < 48 - off; ++len) + { + status = generic->set_32u(value, dest + off, len); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32u(dest, len, off, value)) + return FALSE; + } + } + + for (UINT32 off = 0; off < 16; ++off) + { + UINT32 dest[1024] = { 0 }; + + for (UINT32 len = 1; len < 48 - off; ++len) + { + status = optimized->set_32u(value, dest + off, len); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (!check32u(dest, len, off, value)) + return FALSE; + } + } + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_set32u_speed(void) +{ + UINT32 dest[1024]; + BYTE value = 0; + + for (UINT32 x = 0; x < 16; x++) + { + winpr_RAND(&value, sizeof(value)); + + if (!speed_test("set_32u", "", g_Iterations, (speed_test_fkt)generic->set_32u, + (speed_test_fkt)optimized->set_32u, value, dest + x, x)) + return FALSE; + } + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_set32s_speed(void) +{ + INT32 dest[1024]; + BYTE value = 0; + + for (UINT32 x = 0; x < 16; x++) + { + winpr_RAND(&value, sizeof(value)); + + if (!speed_test("set_32s", "", g_Iterations, (speed_test_fkt)generic->set_32s, + (speed_test_fkt)optimized->set_32s, value, dest + x, x)) + return FALSE; + } + + return TRUE; +} + +int TestPrimitivesSet(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + prim_test_setup(FALSE); + + if (!test_set8u_func()) + return -1; + + if (!test_set32s_func()) + return -1; + + if (!test_set32u_func()) + return -1; + + if (g_TestPrimitivesPerformance) + { + if (!test_set8u_speed()) + return -1; + + if (!test_set32s_speed()) + return -1; + + if (!test_set32u_speed()) + return -1; + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesShift.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesShift.c new file mode 100644 index 0000000000000000000000000000000000000000..b0d58f2c3c2b8b121926561ae7b8fa5e6e2bad5e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesShift.c @@ -0,0 +1,468 @@ +/* test_shift.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include "prim_test.h" + +#define FUNC_TEST_SIZE 65536 + +static BOOL test_lShift_16s_func(void) +{ + pstatus_t status = 0; + INT16 ALIGN(src[FUNC_TEST_SIZE + 3]); + INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]); + UINT32 val = 0; + winpr_RAND(&val, sizeof(val)); + winpr_RAND(src, sizeof(src)); + val = val % 16; + /* Negative tests */ + status = generic->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->lShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + /* Aligned */ + status = generic->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->lShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + /* Unaligned */ + status = generic->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->lShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +static BOOL test_lShift_16u_func(void) +{ + pstatus_t status = 0; + UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]); + UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]); + UINT32 val = 0; + winpr_RAND(&val, sizeof(val)); + winpr_RAND(src, sizeof(src)); + val = val % 16; + + /* Negative tests */ + status = generic->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->lShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + /* Aligned */ + status = generic->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->lShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + /* Unaligned */ + status = generic->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->lShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +static BOOL test_rShift_16s_func(void) +{ + pstatus_t status = 0; + INT16 ALIGN(src[FUNC_TEST_SIZE + 3]); + INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]); + UINT32 val = 0; + winpr_RAND(&val, sizeof(val)); + winpr_RAND(src, sizeof(src)); + val = val % 16; + + /* Negative Tests */ + status = generic->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->rShiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + /* Aligned */ + status = generic->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->rShiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + /* Unaligned */ + status = generic->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->rShiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +static BOOL test_rShift_16u_func(void) +{ + pstatus_t status = 0; + UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]); + UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]); + UINT32 val = 0; + winpr_RAND(&val, sizeof(val)); + winpr_RAND(src, sizeof(src)); + val = val % 16; + /* Negative tests */ + status = generic->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->rShiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + /* Aligned */ + status = generic->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->rShiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + /* Unaligned */ + status = generic->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->rShiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +static BOOL test_ShiftWrapper_16s_func(void) +{ + pstatus_t status = 0; + INT16 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 }; + INT16 ALIGN(d1[FUNC_TEST_SIZE + 3]) = { 0 }; + UINT32 tmp = 0; + winpr_RAND(&tmp, sizeof(tmp)); + winpr_RAND(src, sizeof(src)); + INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16); + + /* Negative tests */ + status = generic->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16s(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + /* Aligned */ + status = generic->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16s(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = generic->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16s(src + 1, -val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + /* Unaligned */ + status = generic->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16s(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = generic->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16s(src + 1, -val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +static BOOL test_ShiftWrapper_16u_func(void) +{ + pstatus_t status = 0; + UINT16 ALIGN(src[FUNC_TEST_SIZE + 3]) = { 0 }; + UINT16 ALIGN(d1[FUNC_TEST_SIZE + 3]) = { 0 }; + UINT32 tmp = 0; + winpr_RAND(&tmp, sizeof(tmp)); + winpr_RAND(src, sizeof(src)); + INT32 val = WINPR_ASSERTING_INT_CAST(int32_t, tmp % 16); + + /* Negative */ + status = generic->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16u(src + 1, 16, d1 + 1, FUNC_TEST_SIZE); + + if (status == PRIMITIVES_SUCCESS) + return FALSE; + + /* Aligned */ + status = generic->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16u(src + 1, val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = generic->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16u(src + 1, -val, d1 + 1, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + /* Unaligned */ + status = generic->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16u(src + 1, val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = generic->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->shiftC_16u(src + 1, -val, d1 + 2, FUNC_TEST_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_lShift_16s_speed(void) +{ + UINT32 val = 0; + INT16 ALIGN(src[MAX_TEST_SIZE + 1]); + INT16 ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(src, sizeof(src)); + winpr_RAND(&val, sizeof(val)); + + val = val % 16; + if (!speed_test("lShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s, + (speed_test_fkt)optimized->lShiftC_16s, src, val, dst, MAX_TEST_SIZE)) + return FALSE; + + if (!speed_test("lShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16s, + (speed_test_fkt)optimized->lShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_lShift_16u_speed(void) +{ + UINT32 val = 0; + UINT16 ALIGN(src[MAX_TEST_SIZE + 1]); + UINT16 ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(&val, sizeof(val)); + winpr_RAND(src, sizeof(src)); + + val = val % 16; + if (!speed_test("lShift_16u", "aligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u, + (speed_test_fkt)optimized->lShiftC_16u, src, val, dst, MAX_TEST_SIZE)) + return FALSE; + + if (!speed_test("lShift_16u", "unaligned", g_Iterations, (speed_test_fkt)generic->lShiftC_16u, + (speed_test_fkt)optimized->lShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_rShift_16s_speed(void) +{ + UINT32 val = 0; + INT16 ALIGN(src[MAX_TEST_SIZE + 1]); + INT16 ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(src, sizeof(src)); + winpr_RAND(&val, sizeof(val)); + + val = val % 16; + if (!speed_test("rShift_16s", "aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s, + (speed_test_fkt)optimized->rShiftC_16s, src, val, dst, MAX_TEST_SIZE)) + return FALSE; + + if (!speed_test("rShift_16s", "unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16s, + (speed_test_fkt)optimized->rShiftC_16s, src + 1, val, dst, MAX_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +/* ------------------------------------------------------------------------- */ +static BOOL test_rShift_16u_speed(void) +{ + UINT32 val = 0; + UINT16 ALIGN(src[MAX_TEST_SIZE + 1]); + UINT16 ALIGN(dst[MAX_TEST_SIZE + 1]); + winpr_RAND(&val, sizeof(val)); + winpr_RAND(src, sizeof(src)); + + val = val % 16; + if (!speed_test("rShift_16u", "aligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u, + (speed_test_fkt)optimized->rShiftC_16u, src, val, dst, MAX_TEST_SIZE)) + return FALSE; + + if (!speed_test("rShift_16u", "unaligned", g_Iterations, (speed_test_fkt)generic->rShiftC_16u, + (speed_test_fkt)optimized->rShiftC_16u, src + 1, val, dst, MAX_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +int TestPrimitivesShift(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + prim_test_setup(FALSE); + + if (!test_lShift_16s_func()) + return 1; + + if (g_TestPrimitivesPerformance) + { + if (!test_lShift_16s_speed()) + return 1; + } + + if (!test_lShift_16u_func()) + return 1; + + if (g_TestPrimitivesPerformance) + { + if (!test_lShift_16u_speed()) + return 1; + } + + if (!test_rShift_16s_func()) + return 1; + + if (g_TestPrimitivesPerformance) + { + if (!test_rShift_16s_speed()) + return 1; + } + + if (!test_rShift_16u_func()) + return 1; + + if (g_TestPrimitivesPerformance) + { + if (!test_rShift_16u_speed()) + return 1; + } + + if (!test_ShiftWrapper_16s_func()) + return 1; + + if (!test_ShiftWrapper_16u_func()) + return 1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesSign.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesSign.c new file mode 100644 index 0000000000000000000000000000000000000000..fb9549ae9a36cec72855d36b58bf43c1049e224b --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesSign.c @@ -0,0 +1,93 @@ +/* test_sign.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include +#include "prim_test.h" + +#define TEST_BUFFER_SIZE 65535 + +/* ------------------------------------------------------------------------- */ +static BOOL test_sign16s_func(void) +{ + pstatus_t status = 0; + INT16 ALIGN(src[TEST_BUFFER_SIZE + 16]) = { 0 }; + INT16 ALIGN(d1[TEST_BUFFER_SIZE + 16]) = { 0 }; + INT16 ALIGN(d2[TEST_BUFFER_SIZE + 16]) = { 0 }; + winpr_RAND(src, sizeof(src)); + status = generic->sign_16s(src + 1, d1 + 1, TEST_BUFFER_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->sign_16s(src + 1, d2 + 1, TEST_BUFFER_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (memcmp(d1, d2, sizeof(d1)) != 0) + return FALSE; + + status = generic->sign_16s(src + 1, d1 + 2, TEST_BUFFER_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + status = optimized->sign_16s(src + 1, d2 + 2, TEST_BUFFER_SIZE); + + if (status != PRIMITIVES_SUCCESS) + return FALSE; + + if (memcmp(d1, d2, sizeof(d1)) != 0) + return FALSE; + + return TRUE; +} + +static int test_sign16s_speed(void) +{ + INT16 ALIGN(src[MAX_TEST_SIZE + 3]) = { 0 }; + INT16 ALIGN(dst[MAX_TEST_SIZE + 3]) = { 0 }; + winpr_RAND(src, sizeof(src)); + + if (!speed_test("sign16s", "aligned", g_Iterations, (speed_test_fkt)generic->sign_16s, + (speed_test_fkt)optimized->sign_16s, src + 1, dst + 1, MAX_TEST_SIZE)) + return FALSE; + + if (!speed_test("sign16s", "unaligned", g_Iterations, (speed_test_fkt)generic->sign_16s, + (speed_test_fkt)optimized->sign_16s, src + 1, dst + 2, MAX_TEST_SIZE)) + return FALSE; + + return TRUE; +} + +int TestPrimitivesSign(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + prim_test_setup(FALSE); + + if (!test_sign16s_func()) + return 1; + + if (g_TestPrimitivesPerformance) + { + if (!test_sign16s_speed()) + return 1; + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYCbCr.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYCbCr.c new file mode 100644 index 0000000000000000000000000000000000000000..ca9e906c35e460e29bbb05bdcb2c9e83d00abb08 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYCbCr.c @@ -0,0 +1,1838 @@ + +#include "prim_test.h" + +#include +#include +#include +#include + +#include + +#define TAG __FILE__ + +static const INT16 TEST_Y_COMPONENT[4096] = { + -32, +16, +64, +272, -32, -16, +0, -16, -32, -24, -16, -8, +0, + -24, -48, -72, -96, -90, -84, -78, -72, -98, -124, -150, -176, -192, + -208, -224, -240, -256, -272, -288, -304, -304, -304, -304, -304, -336, -368, + -400, -432, -450, -468, -486, -504, -522, -540, -558, -576, -598, -620, -642, + -664, -686, -708, -730, -752, -768, -784, -800, -816, -816, -816, -816, +68, + +120, +172, +240, +53, +55, +57, +43, +30, +32, +34, +36, +38, +20, + +2, -16, -34, -36, -38, -40, -42, -68, -94, -120, -146, -148, -151, + -186, -220, -227, -233, -240, -247, -254, -261, -268, -275, -302, -329, -356, + -384, -403, -423, -443, -463, -484, -506, -528, -550, -572, -594, -616, -639, + -673, -707, -709, -712, -733, -754, -775, -796, -796, -796, -796, +168, +224, + +281, +209, +138, +126, +115, +103, +92, +88, +84, +80, +76, +64, +52, + +40, +28, +18, +8, -2, -12, -38, -64, -90, -116, -105, -95, -148, + -201, -198, -195, -192, -190, -204, -218, -232, -247, -269, -291, -313, -336, + -357, -379, -400, -422, -447, -473, -498, -524, -546, -569, -591, -614, -660, + -707, -689, -672, -698, -724, -750, -776, -776, -776, -776, +268, +312, +357, + +273, +191, +181, +172, +162, +154, +144, +134, +124, +114, +108, +102, +80, + +58, +56, +54, +52, +50, +24, -2, -44, -86, -61, -38, -93, -149, + -137, -124, -144, -165, -170, -175, -196, -218, -235, -252, -269, -288, -310, + -334, -357, -381, -409, -439, -468, -498, -520, -543, -565, -589, -647, -706, + -668, -632, -663, -694, -725, -756, -756, -756, -756, +368, +401, +434, +339, + +244, +237, +230, +223, +216, +200, +184, +168, +152, +152, +152, +120, +88, + +94, +100, +106, +112, +86, +60, +2, -56, -18, +19, -39, -98, -76, + -55, -97, -140, -136, -133, -161, -190, -202, -215, -227, -240, -265, -290, + -315, -340, -373, -406, -439, -472, -495, -518, -541, -564, -635, -706, -649, + -592, -628, -664, -700, -736, -736, -736, -736, +404, +556, +454, +383, +313, + +531, +239, +282, +326, +304, +282, +260, +238, +246, +254, +118, +238, +196, + +154, +32, -90, -88, -86, +76, +238, +243, +247, +29, -191, -232, -272, + -121, +29, -62, -153, -149, -145, -162, -180, -197, -216, -240, -265, -289, + -315, -345, -376, -406, -438, -446, -456, -497, -539, -595, -653, -502, -608, + -625, -642, -675, -708, -708, -708, -708, +440, +713, +475, +428, +382, +827, + +249, +342, +436, +408, +380, +352, +324, +340, +356, -140, -124, +42, +208, + +214, +220, +250, +280, +406, +532, +504, +476, +352, +229, +125, +22, -146, + -314, -244, -175, -138, -101, -123, -146, -169, -192, -216, -241, -265, -290, + -318, -347, -375, -404, -399, -395, -454, -514, -557, -601, -356, -624, -622, + -620, -650, -680, -680, -680, -680, +604, +677, +495, +457, +419, +770, +354, + +386, +418, +416, +414, +380, +346, +258, -342, -302, -6, +288, +582, +604, + +626, +588, +550, +688, +826, +829, +833, +724, +616, +481, +348, +181, +15, + -139, -292, -175, -56, -83, -112, -139, -168, -192, -216, -240, -265, -291, + -317, -343, -370, -351, -333, -411, -489, -486, -484, -402, -576, -587, -598, + -625, -652, -652, -652, -652, +1280, +1154, +1028, +998, +968, +970, +460, +430, + +400, +424, +448, +408, +368, +432, -528, -208, +112, +534, +956, +994, +1032, + +926, +820, +970, +1120, +1155, +1190, +1097, +1004, +839, +674, +509, +344, +223, + +102, +45, -12, -45, -78, -111, -144, -168, -192, -216, -240, -264, -288, + -312, -336, -304, -272, -368, -464, -416, -368, -448, -528, -552, -576, -600, + -624, -624, -624, -624, +770, +671, +573, +554, +536, +629, +467, +464, +462, + +492, +523, +490, +457, +281, -405, -101, +204, +599, +995, +1310, +1370, +1297, + +1225, +1296, +1368, +1432, +1498, +1402, +1308, +1184, +1062, +874, +688, +586, +485, + +303, +123, -82, -32, -76, -122, -174, -226, -199, -171, -193, -216, -238, + -261, -314, -368, -325, -283, -360, -438, -451, -465, -515, -565, -583, -601, + -617, -633, -633, +772, +701, +630, +623, +616, +545, +474, +499, +524, +561, + +599, +572, +546, +131, -283, +6, +296, +665, +1034, +1627, +1708, +1669, +1630, + +1623, +1616, +1711, +1806, +1709, +1612, +1531, +1450, +1241, +1032, +950, +869, +563, + +258, -120, +15, -42, -100, -180, -261, -182, -103, -123, -144, -165, -186, + -325, -464, -283, -102, -305, -508, -455, -402, -478, -554, -566, -578, -610, + -642, -642, +774, +730, +687, +675, +664, +620, +577, +581, +586, +597, +610, + +590, +571, -147, -96, +209, +516, +794, +1073, +1575, +1822, +1976, +1875, +1869, + +1864, +1988, +2114, +2014, +1916, +1876, +1838, +1606, +1376, +1266, +1156, +902, +137, + -61, -3, -120, -238, -122, -7, -69, -130, -164, -200, -219, -239, -271, + -304, -128, -209, -297, -386, -426, -467, -937, -895, -549, -459, -667, -619, + -619, +776, +760, +744, +728, +712, +696, +680, +664, +648, +635, +622, +609, + +596, -425, +90, +413, +736, +924, +1112, +1524, +1936, +2284, +2120, +2116, +2112, + +2267, +2422, +2321, +2220, +2223, +2226, +1973, +1720, +1582, +1444, +1242, +16, -2, + -20, +58, +136, -65, -267, -212, -158, -207, -257, -274, -292, -218, -144, + +26, -316, -290, -264, -142, -20, +2956, +2860, -788, -852, -980, -596, -596, + +826, +807, +789, +770, +752, +749, +747, +744, +742, +677, +613, +516, +421, + -285, +288, +573, +860, +1081, +1303, +1668, +2034, +2313, +2337, +2344, +2352, +2452, + +2554, +2574, +2596, +2506, +2418, +2248, +2080, +1961, +1843, +925, +7, +40, +74, + +748, +654, +453, +251, +48, -154, -107, -61, -111, -161, -28, +104, +45, + -271, -274, -278, -842, +1411, +3007, +3323, +327, -1389, -1197, -493, -493, +876, + +855, +834, +813, +792, +803, +814, +825, +836, +720, +605, +681, +758, +110, + +487, +735, +984, +1239, +1494, +1813, +2132, +2343, +2554, +2573, +2592, +2639, +2686, + +2829, +2972, +2791, +2610, +2525, +2440, +2341, +2243, +608, -2, +83, +169, +1438, + +1172, +970, +768, +565, +363, +249, +135, +52, -30, -95, -160, -193, -226, + -259, -292, +763, -742, +2290, +1738, -1118, -902, -902, -390, -390, +926, +902, + +879, +855, +832, +824, +817, +809, +802, +763, +724, +397, +2375, +970, +589, + +848, +1108, +1396, +1685, +1941, +2198, +2468, +2739, +2785, +2832, +2888, +2946, +3178, + +2900, +3058, +2962, +2848, +2736, +2896, +2546, -364, +309, +205, +871, +1760, +1626, + +1471, +1317, +1145, +975, +844, +714, +599, +485, +351, +216, +146, +75, -355, + +750, +2687, +529, -1067, -615, -835, -799, -847, -383, -383, +976, +950, +924, + +898, +872, +846, +820, +794, +768, +806, +844, +882, +1432, +2598, +692, +962, + +1232, +1554, +1876, +2070, +2264, +2594, +2924, +2998, +3072, +3139, +3206, +3273, +2316, + +3071, +3314, +3173, +3032, +2941, +1826, -57, +108, +73, +1574, +2083, +2080, +1973, + +1866, +1727, +1588, +1441, +1294, +1147, +1000, +796, +592, +484, +376, +828, +256, + +772, -248, -72, -408, +984, -184, -536, -376, -376, +1026, +997, +969, +941, + +913, +888, +864, +840, +816, +762, +709, +768, +1339, +2269, +2176, +1411, +1414, + +1677, +1941, +2188, +2436, +2730, +3023, +3157, +3291, +3349, +3409, +3420, +2152, +3000, + +3594, +3403, +3213, +3233, +951, +12, +97, -303, +2883, +2755, +2373, +2312, +2252, + +2143, +2036, +1861, +1687, +1544, +1403, +1254, +1106, +974, +842, +1229, +1105, +21, + +217, +46, -381, +1912, +3181, +2765, +301, -723, +1076, +1045, +1015, +984, +954, + +931, +909, +886, +864, +719, +575, +654, +1246, +1685, +3149, +1604, +1596, +1801, + +2006, +2307, +2609, +2866, +3123, +3316, +3510, +3561, +3613, +3568, +1988, +2931, +3875, + +3634, +3394, +3527, +76, +81, +86, +859, +3168, +2917, +2666, +2652, +2639, +2561, + +2484, +2282, +2081, +1943, +1806, +1713, +1621, +1464, +1308, +1119, +931, +550, +170, + -92, -354, +1560, +3986, +1970, -558, -558, +1126, +1092, +1060, +1027, +995, +973, + +953, +932, +912, +899, +888, -340, +1249, +1756, +2521, +2421, +1810, +2036, +2263, + +2521, +2781, +3066, +3350, +3443, +3537, +3612, +3688, +3476, +2496, +3021, +3803, +3833, + +3863, +2843, +33, +133, -21, +2099, +3197, +3061, +2927, +2944, +2961, +2882, +2804, + +2607, +2410, +2309, +2209, +2139, +2071, +1842, +1614, +1328, +1044, +663, +283, +10, + -263, -488, -201, -201, -457, -457, +1176, +1141, +1106, +1071, +1036, +1017, +998, + +979, +960, +825, +690, +203, +740, +1573, +1894, +3239, +2024, +2272, +2521, +2737, + +2954, +3010, +3067, +3315, +3564, +3664, +3764, +3384, +3004, +3112, +3732, +3776, +3820, + +1905, -10, +187, -128, +3341, +3226, +3207, +3188, +3236, +3284, +3204, +3124, +2932, + +2740, +2676, +2612, +2567, +2522, +2221, +1920, +1539, +1158, +777, +396, +112, -172, + -488, -292, -324, -356, -356, +1194, +1162, +1131, +1099, +1069, +1047, +1026, +972, + +920, +969, +507, +380, +767, +1428, +1834, +2799, +2486, +2347, +2721, +2919, +3118, + +3290, +3462, +3266, +3071, +3157, +3243, +3521, +3800, +3674, +3548, +3710, +3873, +874, + +179, +91, +517, +3439, +3291, +3333, +3377, +3403, +3430, +3361, +3292, +3174, +3057, + +3004, +2951, +2761, +2572, +2222, +1874, +1554, +1235, +883, +533, +220, -93, -470, + -335, -319, -303, -303, +1212, +1184, +1157, +1129, +1102, +1078, +1055, +967, +880, + +1114, +325, +559, +794, +1284, +1775, +2361, +2948, +2423, +2923, +3103, +3283, +3314, + +3346, +3474, +3602, +3674, +3747, +3659, +3572, +3980, +3877, +3901, +3926, -157, +368, + +253, +1674, +3795, +3356, +3461, +3566, +3571, +3577, +3518, +3460, +3417, +3375, +3332, + +3290, +2956, +2623, +2225, +1828, +1570, +1313, +991, +670, +328, -14, -452, -378, + -314, -250, -250, +1230, +1206, +1182, +1158, +1135, +1109, +1083, +1025, +968, +779, + +78, +481, +885, +1284, +1939, +2466, +3250, +2626, +2772, +3157, +3543, +3514, +3486, + +3729, +3717, +3775, +3834, +3780, +3728, +3934, +3885, +3915, +2667, +92, +333, +173, + +2831, +3701, +3549, +3587, +3627, +3642, +3659, +3643, +3628, +3675, +3724, +3436, +3149, + +2847, +2545, +2275, +2006, +1730, +1454, +1114, +775, +388, +1, -402, -293, -309, + -325, -325, +1248, +1228, +1208, +1188, +1168, +1140, +1112, +1084, +1056, +700, +344, + +660, +976, +1284, +2104, +2316, +3040, +2319, +2110, +2189, +2268, +2691, +3114, +3729, + +3832, +3877, +3922, +3903, +3884, +3889, +3894, +3931, +1408, +341, +298, +95, +3988, + +3609, +3742, +3715, +3688, +3715, +3742, +3769, +3796, +3679, +3562, +3285, +3008, +2738, + +2468, +2326, +2184, +1890, +1596, +1238, +880, +448, +16, -352, -208, -304, -400, + -400, +1296, +1284, +1272, +1260, +1249, +1165, +1081, +1093, +1106, +232, +382, +677, + +971, +973, +1232, +834, +693, +537, +639, +564, +490, +563, +637, -106, +944, + +2358, +3773, +3795, +4074, +3964, +3855, +4337, +212, +204, +197, +1341, +4023, +3813, + +3860, +3810, +3762, +3766, +3771, +3776, +3781, +3603, +3427, +3201, +2977, +2838, +2699, + +2400, +2101, +1982, +1607, +1280, +954, +545, -120, -321, -266, -314, -362, -362, + +1344, +1340, +1337, +1333, +1330, +1190, +1051, +1103, +1156, +20, +933, +950, +967, + +919, +872, +889, +906, +805, +705, +733, +761, +740, +720, +668, +616, +328, + +40, +1640, +3752, +3784, +3816, +3208, +40, +581, +97, +2589, +4058, +4018, +3979, + +3907, +3836, +3818, +3801, +3784, +3767, +3529, +3292, +3375, +3458, +3706, +3954, +3754, + +3555, +2843, +1619, +1067, +516, +386, -256, -290, -324, -324, -324, -324, +1392, + +1364, +1337, +1309, +1283, +1247, +1212, +968, +982, +1424, +1099, +1079, +1058, +1072, + +1088, +815, +799, +1056, +802, +772, +743, +645, +547, +769, +736, +649, +563, + +332, +102, +1939, +4033, +1982, +444, +332, -36, +4076, +4093, +4047, +4001, +3955, + +3910, +3870, +3830, +3791, +3752, +3806, +3861, +3835, +3811, +3678, +3545, +3380, +3216, + +3639, +3806, +2341, +1134, +1091, +24, -387, -286, -286, -286, -286, +1440, +1389, + +1338, +1287, +1236, +1305, +1374, +1091, +1320, +1037, +1267, +1208, +1150, +715, +281, + +486, +1204, +1564, +901, +1325, +1750, +1830, +1911, +1383, +344, +459, +574, +817, + +548, +351, +666, +757, +336, +340, +856, +4028, +4128, +4076, +4024, +4004, +3984, + +3922, +3861, +3799, +3738, +3828, +3919, +3785, +3652, +3394, +3137, +3007, +2878, +2900, + +2923, +3105, +3800, +1284, +1328, +28, -248, -248, -248, -248, +1456, +1406, +1358, + +1309, +1261, +1209, +1159, +1444, +1218, +1265, +33, -654, -1342, -977, -356, +394, + +1401, +1753, +1338, +1738, +2140, +2575, +3009, +3524, +3784, +2536, +1033, +265, +522, + +440, +615, +629, +388, +403, +2211, +4051, +4099, +4078, +4058, +3990, +3922, +3910, + +3898, +3886, +3875, +3805, +3735, +3553, +3373, +3126, +2879, +2585, +2291, +2026, +1762, + +2649, +3026, +2303, +2092, +665, -250, -250, -250, -250, +1472, +1425, +1379, +1332, + +1286, +1371, +1457, +1030, -932, -1834, -1712, -1237, -763, -621, +33, +815, +1598, + +1943, +1776, +2153, +2531, +2808, +3085, +3362, +3640, +4102, +4052, +3042, +496, +530, + +564, +502, +440, +211, +3055, +3818, +4070, +4081, +4093, +3976, +3860, +3898, +3936, + +3974, +4013, +3783, +3553, +3323, +3094, +2858, +2623, +2420, +2217, +1921, +1626, +915, + +2764, +250, +296, +22, -252, -252, -252, -252, +1488, +1443, +1399, +1371, +1343, + +1308, +1530, -408, -1834, -1589, -1089, -811, -535, -281, +485, +1171, +1859, +2132, + +2150, +2503, +2857, +3105, +3352, +3536, +3720, +3875, +3775, +4298, +4054, +2123, +449, + +502, +556, +546, +26, +2113, +3945, +4115, +4031, +3946, +3862, +3838, +3814, +3982, + +3894, +3488, +3338, +3140, +2943, +2622, +2302, +2030, +1758, +1495, +1234, +1259, +774, + -347, -188, -189, -190, -222, -254, -254, +1504, +1462, +1420, +1410, +1400, +1246, + +1604, -1334, -1712, -1089, -978, -643, -308, +59, +938, +1529, +2120, +2322, +2524, + +2854, +3184, +3402, +3620, +3710, +3800, +3905, +4010, +4019, +4028, +3973, +334, +503, + +672, +627, +582, +409, +236, +2359, +3970, +3917, +3864, +3778, +3692, +3990, +3776, + +3194, +3124, +2958, +2792, +2387, +1982, +1641, +1300, +1071, +842, +69, -192, -176, + -160, -144, -128, -192, -256, -256, +1546, +1496, +1447, +1430, +1413, +1627, +1330, + -2102, -1184, -819, -712, -395, -80, +405, +1148, +1713, +2280, +2486, +2692, +2995, + +3297, +3467, +3638, +3712, +3787, +3915, +4045, +3917, +4047, +3097, +357, +655, +699, + +198, +466, +381, +297, +376, +200, +1815, +3431, +3568, +3961, +4114, +3755, +3310, + +3121, +2804, +2487, +2208, +1931, +1189, +447, +37, -116, -254, -136, -111, -86, + -109, -132, -196, -260, -260, +1588, +1531, +1475, +1450, +1426, +1497, +33, -1591, + -1168, -807, -446, -149, +148, +753, +1358, +1899, +2440, +2650, +2861, +3136, +3411, + +3533, +3656, +3715, +3774, +3927, +4080, +3817, +4066, +2223, +380, +553, +214, +3610, + +350, +354, +358, +442, +526, +226, -74, +286, +1158, +1678, +1686, +1634, +1582, + +1114, +646, +239, -168, -31, +107, -228, -51, -65, -80, -46, -12, -74, + -136, -200, -264, -264, +1630, +1565, +1502, +1470, +1439, +1590, -817, -1399, -960, + -633, -308, -14, +280, +875, +1472, +1971, +2472, +2718, +2965, +3229, +3492, +3582, + +3674, +3701, +3729, +3793, +3859, +4147, +4181, +707, +563, +417, +1297, +3917, +4234, + +2198, +163, +267, +372, +348, +325, +108, +147, +186, -31, +38, +107, +96, + +85, +61, +38, -162, -106, -126, +111, +876, -152, -93, -34, -87, -140, + -204, -268, -268, +1672, +1601, +1530, +1491, +1452, +1685, -1666, -1209, -752, -461, + -170, +121, +412, +999, +1586, +2045, +2504, +2787, +3071, +3322, +3574, +3633, +3693, + +3688, +3684, +3661, +3638, +3711, +2760, +473, +746, +283, +2380, +4225, +4022, +4043, + +4064, +2141, +218, +215, +212, +186, +160, +230, +300, +234, +168, +102, +36, + -117, -269, +218, +1218, +2025, +2833, +1048, -224, -140, -56, -100, -144, -208, + -272, -272, +1626, +1607, +1589, +1458, +1585, +692, -1479, -1107, -736, -451, -168, + +115, +400, +805, +1468, +1937, +2408, +2703, +2999, +3327, +3655, +3568, +3482, +3620, + +3759, +3439, +3121, +1601, +851, +819, +533, +437, +3415, +4252, +4066, +4055, +4045, + +4084, +4124, +2995, +1867, +1068, +269, +62, -145, -38, +69, +704, +1339, +2183, + +3028, +2816, +2861, +2953, +2790, -349, +96, -19, -134, -137, -140, -204, -268, + -268, +1580, +1614, +1649, +1427, +1718, -300, -1293, -1006, -720, -443, -166, +111, + +388, +613, +1350, +1831, +2312, +2620, +2928, +3076, +3225, +3249, +3273, +3297, +3322, + +3475, +3628, +3333, +1502, +655, +832, +593, +3938, +4024, +4110, +4068, +4026, +3980, + +3934, +3984, +4034, +3998, +3962, +3990, +4018, +3786, +3554, +3610, +3666, +3459, +3253, + +3111, +2969, +2858, +2236, -210, -96, -154, -212, -174, -136, -200, -264, -264, + +1662, +1653, +1644, +1619, +1851, -988, -1266, -985, -704, -401, -100, +9, +120, + +403, +944, +1579, +2216, +2504, +2793, +2873, +2954, +2976, +2999, +3085, +3173, +3237, + +3303, +3575, +521, +553, +587, +1771, +3981, +4019, +4058, +4032, +4007, +3971, +3936, + +3948, +3961, +3920, +3879, +3806, +3989, +3866, +3743, +3636, +3529, +3375, +3222, +3069, + +2916, +2907, +1362, -119, -64, -113, -162, -147, -132, -196, -260, -260, +1744, + +1692, +1640, +1556, +1472, -1932, -1240, -964, -688, -361, -34, +165, +364, +707, + +1050, +1585, +2120, +2389, +2658, +2671, +2684, +2705, +2726, +2875, +3024, +3001, +2978, + +2283, +564, +965, +342, +2951, +4024, +4015, +4006, +3997, +3988, +3963, +3938, +3913, + +3888, +3842, +3796, +3622, +3960, +3946, +3932, +3662, +3392, +3292, +3192, +3028, +2864, + +2956, +488, -28, -32, -72, -112, -120, -128, -192, -256, -256, +1834, +1635, + +1692, +1718, +208, -1663, -1229, -924, -619, -283, +50, +256, +719, +705, +948, + +1126, +1562, +1845, +2129, +2236, +2344, +2447, +2551, +2654, +2759, +2738, +2719, +1562, + +663, +623, +327, +4207, +3992, +4012, +4034, +3990, +3948, +3922, +3898, +3872, +3848, + +3774, +3701, +3484, +3523, +3726, +3929, +3812, +3695, +3604, +3513, +3407, +3300, +3350, + -440, -231, -22, -48, -74, -100, -126, -174, -222, -222, +1924, +1578, +1745, + +1880, -1057, -1394, -1219, -884, -550, -207, +135, +93, +563, +449, +847, +669, + +1004, +1302, +1600, +1802, +2005, +2191, +2377, +2435, +2494, +2477, +2460, +843, +763, + +794, +1337, +3928, +3960, +4011, +4062, +3985, +3908, +3883, +3858, +3833, +3808, +3707, + +3607, +3603, +3599, +3506, +3414, +3706, +3998, +3916, +3835, +3786, +3737, +2208, -345, + +78, -12, -24, -36, -80, -124, -156, -188, -188, +1598, +1585, +1829, +2154, + -1873, -1413, -1208, -556, -417, -514, -102, +440, +214, +191, +681, +435, +702, + +870, +1039, +1224, +1409, +1709, +2010, +2039, +2069, +2086, +1849, +795, +766, +596, + +2474, +3953, +3896, +3928, +3962, +3914, +3868, +3842, +3818, +3792, +3768, +3687, +3608, + +3577, +3546, +3462, +3379, +3312, +3245, +3364, +3484, +3189, +2893, +858, -154, +35, + -34, -48, -62, -108, -154, -154, -154, -154, +1784, +1849, +1915, +892, -1666, + -1176, -1711, -741, -796, -822, +175, -748, +378, +191, +517, +202, +400, +439, + +479, +646, +814, +1229, +1645, +1644, +1644, +1697, +1239, +748, +770, +399, +3613, + +3978, +3832, +3847, +3862, +3845, +3828, +3803, +3778, +3753, +3728, +3669, +3611, +3552, + +3494, +3419, +3345, +3174, +3004, +2813, +2623, +2592, +2562, -237, +37, -9, -56, + -72, -88, -136, -184, -152, -120, -120, +1802, +1900, +2255, -286, -1290, -1129, + -712, -391, -327, -385, -445, +201, -178, +436, +27, -45, -118, +204, +270, + +384, +498, +685, +874, +998, +1123, +1252, +1127, +794, +717, +1161, +3654, +3843, + +3776, +3788, +3802, +3782, +3764, +3616, +3726, +3690, +3656, +3595, +3536, +3476, +3417, + +3341, +3265, +3078, +2891, +2687, +2484, +2617, +1982, -28, +8, +14, +18, -18, + -54, +6, +66, -30, -126, -126, +1820, +1696, +2084, -2232, -1939, -570, -1762, + -1834, -1394, -461, -552, -387, -223, -1110, -462, -37, -124, -31, -451, -134, + +183, +143, +104, +353, +602, +809, +1017, +841, +665, +1924, +3696, +3708, +3720, + +3731, +3742, +3721, +3700, +3431, +3674, +3629, +3584, +3523, +3462, +3401, +3341, +3264, + +3187, +2982, +2778, +2562, +2346, +2386, +891, -77, -20, +36, +92, +36, -20, + -108, -196, -164, -132, -132, +1710, +1955, +1177, -2833, -955, -2075, -2172, -364, + -1885, -1352, -820, -1599, -843, -1249, -887, -652, -674, -554, -435, -636, -325, + -304, -282, -101, -175, +493, +906, +871, +580, +2767, +3674, +3653, +3632, +3656, + +3682, +3626, +3572, +3436, +3558, +3534, +3512, +3449, +3388, +3325, +3264, +3186, +3108, + +2902, +2697, +2500, +2304, +2219, +343, +179, +271, +154, +38, -6, -50, -110, + -170, -154, -138, -138, +1600, +1959, -242, -2667, -2020, -2557, -2582, -1455, +696, + +316, +960, +2052, +2120, +1940, +1760, +1292, +824, -310, -932, -1394, -832, -750, + -668, -298, -440, +434, +796, +902, +496, +3610, +3652, +3598, +3544, +3583, +3622, + +3533, +3444, +3443, +3442, +3441, +3440, +3377, +3314, +3251, +3188, +3109, +3030, +2823, + +2616, +2439, +2262, +2053, -204, +179, +50, +17, -16, -48, -80, -112, -144, + -144, -144, -144, +1956, +1852, -2091, -3025, -1145, +322, +2045, +1672, +1555, +1328, + +1614, +1916, +1706, +1622, +1282, +1502, +1466, +1301, +1393, +940, -792, -1548, -768, + -820, -617, +926, +934, +909, +1397, +3323, +3456, +3446, +3436, +3393, +3351, +3388, + +3426, +3373, +3321, +3444, +3313, +3264, +3217, +3153, +3090, +2997, +2906, +2686, +2467, + +2290, +2115, +1282, -61, +136, +79, +36, -5, -37, -69, -101, -133, -133, + -133, -133, +1800, +1746, +669, +1992, +1779, +1665, +1552, +1727, +1390, +1317, +1245, + +1269, +1293, +1560, +1316, +1456, +1084, +1121, +1158, +971, +1297, +726, -869, -1343, + -794, +1419, +1072, +917, +2299, +3036, +3261, +3294, +3328, +3204, +3080, +3244, +3409, + +3305, +3201, +3449, +3186, +3153, +3121, +3056, +2992, +2887, +2783, +2550, +2318, +2143, + +1968, +513, +82, +95, +108, +57, +6, -26, -58, -90, -122, -122, -122, + -122, +1516, +1832, +1636, +1905, +1406, +1344, +1283, +1589, +1641, +1465, +1291, +1277, + +1263, +1386, +1254, +1314, +1118, +1116, +1115, +905, +953, +1160, +1111, +118, -363, + +807, +698, +700, +2240, +3325, +2361, +2934, +3252, +2998, +2745, +2924, +3103, +3155, + +2952, +3277, +3091, +3057, +3024, +2959, +2894, +2776, +2659, +2414, +2169, +2074, +1981, + +255, +65, +68, +73, +44, +17, -15, -47, -79, -111, -111, -111, -111, + +1744, +1662, +1581, +1563, +1546, +1536, +1527, +1453, +1380, +1359, +1339, +1286, +1234, + +1213, +1193, +1172, +1152, +1112, +1073, +1097, +1122, +826, +1043, +1067, +1092, +964, + +837, +741, +2182, +2078, +2487, +2831, +2664, +2793, +2923, +2860, +2798, +3007, +2705, + +3106, +2996, +2962, +2928, +2862, +2796, +2666, +2536, +2278, +2020, +1751, +1482, -259, + +48, +43, +38, +33, +28, -4, -36, -68, -100, -100, -100, -100, +1684, + +1640, +1596, +1584, +1573, +1543, +1513, +1451, +1391, +1359, +1329, +1282, +1236, +1213, + +1190, +1168, +1146, +1107, +1069, +1063, +1058, +920, +1038, +996, +955, +924, +894, + +880, +1635, +1679, +2235, +2439, +2132, +2451, +2771, +2580, +2644, +2713, +2528, +2742, + +2701, +2828, +2699, +2570, +2442, +2383, +2324, +2105, +1887, +1732, +811, -79, +55, + +62, +71, +46, +23, -7, -37, -67, -97, -113, -129, -129, +1624, +1618, + +1612, +1606, +1601, +1551, +1501, +1451, +1402, +1361, +1320, +1279, +1239, +1214, +1189, + +1164, +1140, +1103, +1067, +1031, +995, +1014, +1034, +926, +818, +885, +953, +1021, + +1089, +1024, +1472, +2048, +2112, +2110, +2109, +2044, +2491, +2421, +2352, +2379, +2406, + +2694, +2471, +2279, +2088, +2100, +2113, +1933, +1754, +1715, +140, +101, +62, +83, + +104, +61, +18, -10, -38, -66, -94, -126, -158, -158, +1724, +1788, +1852, + +1692, +1532, +1494, +1456, +1418, +1381, +1345, +1311, +1275, +1241, +1214, +1187, +1160, + +1134, +1098, +1064, +1029, +995, +996, +998, +935, +873, +877, +883, +792, +702, + +657, +1125, +1832, +2284, +1193, +1638, +1796, +2209, +2320, +2176, +2239, +2047, +2560, + +2562, +1891, +1734, +1673, +1613, +1744, +1621, +1152, -83, -8, +69, +70, +73, + +42, +13, -13, -39, -65, -91, -139, -187, -187, +1824, +1702, +1580, +1522, + +1464, +1438, +1412, +1386, +1360, +1331, +1302, +1273, +1244, +1215, +1186, +1157, +1128, + +1095, +1062, +1029, +996, +979, +962, +945, +928, +871, +814, +821, +828, +803, + +1290, +1617, +1944, +2068, +1168, +1292, +1416, +1708, +1488, +1844, +1688, +2171, +2142, + +1249, +1380, +1503, +1626, +1045, -48, +79, +206, +141, +76, +59, +42, +25, + +8, -16, -40, -64, -88, -152, -216, -216, +1688, +1615, +1542, +1501, +1460, + +1429, +1398, +1367, +1336, +1309, +1284, +1257, +1232, +1205, +1180, +1153, +1128, +1092, + +1058, +1022, +988, +968, +950, +930, +912, +861, +812, +793, +776, +595, +672, + +971, +1272, +330, +924, +1038, +1152, +1298, +1444, +1910, +1608, +1531, +1200, +515, + +344, +259, +176, +251, +72, +122, +174, +128, +84, +64, +46, +26, +8, + -18, -44, -70, -96, -144, -192, -192, +1552, +1528, +1504, +1480, +1456, +1420, + +1384, +1348, +1312, +1289, +1266, +1243, +1220, +1197, +1174, +1151, +1128, +1091, +1054, + +1017, +980, +959, +938, +917, +896, +853, +810, +767, +724, +645, +566, +583, + +600, +640, +680, +528, +376, +376, +888, +1464, +1016, +637, +258, +295, +332, + +297, +262, +227, +192, +167, +142, +117, +92, +71, +50, +29, +8, -20, + -48, -76, -104, -136, -168, -168, +1544, +1521, +1498, +1475, +1452, +1411, +1370, + +1329, +1288, +1267, +1248, +1227, +1208, +1187, +1168, +1147, +1128, +1088, +1050, +1010, + +972, +948, +926, +902, +880, +843, +808, +771, +736, +677, +620, +609, +600, + +614, +628, +546, +464, +238, +2060, +1690, +1576, +1709, +308, +313, +320, +285, + +252, +217, +184, +162, +142, +120, +100, +76, +54, +30, +8, -22, -52, + -82, -112, -128, -144, -144, +1536, +1514, +1492, +1470, +1448, +1402, +1356, +1310, + +1264, +1247, +1230, +1213, +1196, +1179, +1162, +1145, +1128, +1087, +1046, +1005, +964, + +939, +914, +889, +864, +835, +806, +777, +748, +711, +674, +637, +600, +588, + +576, +564, +552, +612, +160, +1916, +1112, +223, +358, +333, +308, +275, +242, + +209, +176, +159, +142, +125, +108, +83, +58, +33, +8, -24, -56, -88, + -120, -120, -120, -120, +1536, +1514, +1492, +1470, +1448, +1402, +1356, +1310, +1264, + +1246, +1230, +1212, +1196, +1178, +1162, +1144, +1128, +1086, +1046, +1004, +964, +938, + +914, +888, +864, +834, +806, +776, +748, +710, +674, +636, +600, +588, +576, + +564, +552, +644, +480, +108, +504, +158, +326, +316, +308, +274, +242, +208, + +176, +158, +142, +124, +108, +82, +58, +32, +8, -24, -56, -88, -120, + -120, -120, -120, +1536, +1514, +1492, +1470, +1448, +1402, +1356, +1310, +1264, +1247, + +1230, +1213, +1196, +1179, +1162, +1145, +1128, +1087, +1046, +1005, +964, +939, +914, + +889, +864, +835, +806, +777, +748, +711, +674, +637, +600, +588, +576, +564, + +552, +420, +288, +348, +408, +351, +294, +301, +308, +275, +242, +209, +176, + +159, +142, +125, +108, +83, +58, +33, +8, -24, -56, -88, -120, -120, + -120, -120, +1536, +1514, +1492, +1470, +1448, +1402, +1356, +1310, +1264, +1246, +1230, + +1212, +1196, +1178, +1162, +1144, +1128, +1086, +1046, +1004, +964, +938, +914, +888, + +864, +834, +806, +776, +748, +710, +674, +636, +600, +588, +576, +564, +552, + +420, +288, +348, +408, +350, +294, +300, +308, +274, +242, +208, +176, +158, + +142, +124, +108, +82, +58, +32, +8, -24, -56, -88, -120, -120, -120, + -120 +}; + +static const INT16 TEST_CB_COMPONENT[4096] = { + +1728, +1730, +1732, +1734, +1736, +1738, +1740, +1742, +1744, +1740, +1736, +1732, +1728, + +1796, +1864, +1804, +1744, +1754, +1764, +1774, +1784, +1794, +1804, +1814, +1824, +1774, + +1724, +1802, +1880, +1814, +1748, +1810, +1872, +1878, +1884, +1890, +1896, +1910, +1924, + +1938, +1952, +1938, +1924, +1910, +1896, +1914, +1932, +1950, +1968, +1974, +1980, +1986, + +1992, +1998, +2004, +2010, +2016, +2016, +2016, +2016, +2016, +2016, +2016, +2016, +1710, + +1697, +1684, +1704, +1723, +1726, +1730, +1733, +1737, +1738, +1740, +1741, +1743, +1758, + +1774, +1757, +1741, +1762, +1783, +1788, +1793, +1774, +1755, +1784, +1813, +1817, +1821, + +1825, +1829, +1857, +1885, +1881, +1877, +1849, +1821, +1857, +1894, +1904, +1914, +1924, + +1935, +1928, +1922, +1915, +1909, +1922, +1936, +1949, +1963, +1974, +1985, +1997, +2008, + +2009, +2011, +2012, +2014, +2017, +2020, +2023, +2026, +2026, +2026, +2026, +1692, +1664, + +1637, +1674, +1711, +1715, +1720, +1725, +1730, +1737, +1744, +1751, +1758, +1721, +1684, + +1711, +1738, +1770, +1802, +1802, +1802, +1754, +1706, +1754, +1802, +1860, +1918, +1848, + +1778, +1900, +2022, +1952, +1882, +1820, +1759, +1825, +1892, +1898, +1905, +1911, +1918, + +1919, +1920, +1921, +1922, +1931, +1940, +1949, +1958, +1974, +1991, +2008, +2025, +2021, + +2018, +2015, +2012, +2018, +2024, +2030, +2036, +2036, +2036, +2036, +1674, +1631, +1589, + +1644, +1698, +1703, +1710, +1716, +1723, +1735, +1748, +1760, +1773, +1763, +1754, +1760, + +1767, +1794, +1821, +1800, +1779, +1830, +1881, +1900, +1919, +2047, +2175, +2015, +1855, + +1879, +1903, +1927, +1951, +1759, +1824, +1856, +1890, +1892, +1895, +1897, +1901, +1909, + +1918, +1926, +1935, +1939, +1944, +1948, +1953, +1974, +1996, +2019, +2041, +2032, +2025, + +2017, +2010, +2019, +2028, +2037, +2046, +2046, +2046, +2046, +1656, +1599, +1543, +1614, + +1686, +1693, +1701, +1708, +1716, +1734, +1752, +1770, +1788, +1806, +1824, +1810, +1796, + +1818, +1840, +2054, +2268, +1650, +1032, +510, -12, -70, -128, +390, +908, +1602, + +2296, +2158, +2020, +1699, +1890, +1889, +1888, +1887, +1886, +1885, +1884, +1900, +1916, + +1932, +1948, +1948, +1948, +1948, +1948, +1975, +2003, +2030, +2058, +2045, +2033, +2020, + +2008, +2020, +2032, +2044, +2056, +2056, +2056, +2056, +1590, +1570, +1551, +1612, +1673, + +1579, +1742, +1713, +1685, +1672, +1660, +1711, +1763, +1694, +1626, +1941, +2001, +2060, + +583, -654, -1891, -2046, -2201, -2084, -1967, -2049, -2131, -2053, -1975, -1751, -1527, + +41, +1609, +2374, +1859, +2000, +1886, +1898, +1912, +1909, +1907, +1900, +1894, +1919, + +1945, +1944, +1944, +1943, +1943, +1967, +1992, +2017, +2042, +2032, +2023, +2014, +2006, + +2017, +2028, +2039, +2050, +2050, +2050, +2050, +1524, +1542, +1560, +1610, +1661, +1467, + +1785, +1719, +1654, +1611, +1568, +1653, +1738, +1839, +1940, +793, -866, -2050, -2210, + -2082, -1954, -1902, -1850, -1862, -1874, -1980, -2086, -1936, -1786, -1776, -1766, -1820, + -1874, -534, +1829, +2112, +1884, +1911, +1939, +1934, +1930, +1901, +1872, +1907, +1942, + +1941, +1940, +1939, +1938, +1960, +1982, +2004, +2027, +2021, +2015, +2009, +2004, +2014, + +2024, +2034, +2044, +2044, +2044, +2044, +1586, +1641, +1697, +1704, +1712, +1577, +1699, + +1660, +1623, +1613, +1604, +1642, +1681, +1791, -402, -2036, -1877, -2144, -1899, -1942, + -1985, -1918, -1851, -1880, -1909, -1959, -2009, -1931, -1853, -1801, -1749, -1617, -1485, + -1939, -1882, +96, +2074, +1971, +1869, +1895, +1921, +1885, +1850, +1894, +1939, +1937, + +1936, +1934, +1933, +1952, +1972, +1991, +2011, +2008, +2006, +2003, +2002, +2011, +2020, + +2029, +2038, +2038, +2038, +2038, +1136, +1229, +1322, +1287, +1252, +1433, +1614, +1603, + +1592, +1616, +1640, +1632, +1624, +2256, -1720, -1792, -1864, -1982, -2100, -2058, -2016, + -1934, -1852, -1898, -1944, -1938, -1932, -1926, -1920, -1826, -1732, -1670, -1608, -1552, + -1496, -1664, -1320, +2288, +1800, +1856, +1912, +1870, +1828, +1882, +1936, +1934, +1932, + +1930, +1928, +1945, +1962, +1979, +1996, +1997, +1998, +1999, +2000, +2008, +2016, +2024, + +2032, +2032, +2032, +2032, +1552, +1624, +1698, +1674, +1652, +1644, +1638, +1614, +1592, + +1611, +1630, +1681, +1733, +1146, -2000, -1787, -1830, -1924, -2019, -2049, -2080, -1986, + -1893, -1895, -1898, -1896, -1894, -1860, -1827, -1779, -1731, -1667, -1604, -1615, -1626, + -1878, -594, +2063, +1903, +2016, +1873, +2132, +1880, +1884, +1888, +1921, +1955, +1941, + +1927, +1925, +1925, +1955, +1987, +2005, +2025, +2043, +2063, +1995, +1927, +2099, +2015, + +2095, +2175, +2175, +1456, +1509, +1562, +1551, +1540, +1601, +1662, +1627, +1592, +1606, + +1621, +1731, +1842, +37, -2281, -1782, -1796, -1867, -1938, -2041, -2144, -2039, -1934, + -1893, -1852, -1854, -1857, -1795, -1734, -1732, -1731, -1665, -1600, -1678, -1757, -1836, + +645, +2094, +2007, +1920, +1322, +2139, +1933, +1886, +1840, +1909, +1979, +1952, +1926, + +1907, +1888, +1933, +1978, +2015, +2052, +2089, +2126, +1982, +1838, +2174, +1998, +2158, + +2318, +2318, +1488, +1520, +1554, +1554, +1556, +1588, +1622, +1606, +1592, +1569, +1547, + +1700, +1855, -993, -2049, -1825, -1858, -1905, -1953, -2016, -2080, -1995, -1911, -1858, + -1806, -1812, -1819, -1729, -1641, -1685, -1730, -1678, -1628, -1677, -1727, -2194, +1947, + +2125, +2046, +945, -2205, +114, +2177, +2144, +1856, +1912, +1970, +1963, +1957, +1935, + +1915, +1925, +1937, +1991, +2047, +2181, +2061, +2337, +2613, +1817, +2301, +2157, +2269, + +2397, +1520, +1533, +1546, +1559, +1572, +1577, +1582, +1587, +1592, +1533, +1474, +1671, + +1868, -2023, -1818, -1869, -1920, -1944, -1968, -1992, -2016, -1952, -1888, -1824, -1760, + -1771, -1782, -1665, -1548, -1639, -1730, -1693, -1656, -1677, -1699, -1017, +2226, +1644, + +2087, -286, -2148, -2167, -1674, +611, +2384, +2173, +1962, +1975, +1988, +1965, +1942, + +1919, +1896, +1969, +2042, +2019, +1484, -1916, -1220, +2484, +1068, -916, +1708, +1964, + +1504, +1514, +1526, +1536, +1548, +1550, +1554, +1556, +1560, +1581, +1604, +1786, +689, + -2138, -1894, -1905, -1918, -1926, -1935, -1943, -1952, -1878, -1805, -1731, -1658, -1626, + -1596, -1549, -1503, -1507, -1513, -1518, -1524, -1526, -1785, +148, +2080, +1995, +2422, + -2094, -2003, -2033, -1809, -1665, -1776, -189, +1398, +2536, +2139, +2122, +2105, +2327, + +2295, +2204, +2113, +2870, -213, -1669, -1077, -1237, -1653, -1589, +2059, +1931, +1488, + +1497, +1506, +1515, +1524, +1525, +1526, +1527, +1528, +1631, +1735, +1902, -490, -2254, + -1971, -1943, -1916, -1909, -1902, -1895, -1888, -1805, -1722, -1639, -1556, -1483, -1411, + -1434, -1458, -1377, -1297, -1344, -1392, -1376, -1872, +1312, +1935, +1834, +1734, -2622, + -2370, -2157, -1945, -1892, -1840, -2039, -2239, -2022, -782, -281, +220, +433, +134, + -377, -888, -1655, -1398, -1166, -934, -1374, -1302, -726, +2410, +1898, +1472, +1478, + +1486, +1492, +1500, +1498, +1498, +1496, +1496, +1600, +1705, +1666, -933, -1474, -2015, + -1964, -1914, -1891, -1869, -1846, -1824, -1731, -1639, -1546, -1454, -1387, -1321, -1191, + -1317, -1150, -1240, -1250, -1260, -1545, -1575, +2459, +1885, +2057, +182, -2429, -2225, + -2088, -1952, -1928, -1904, -1905, -1907, -2149, -1879, -1835, -1793, -1670, -1803, -1645, + -1489, -1491, -1239, -1335, -1431, -1335, -1495, +681, +2345, +2089, +1456, +1461, +1466, + +1471, +1476, +1473, +1470, +1467, +1464, +1570, +1676, +1174, -1888, -950, -2060, -1986, + -1912, -1874, -1836, -1798, -1760, -1658, -1556, -1454, -1352, -1292, -1232, -1204, -1688, + -1180, -1184, -1156, -1128, -1203, -254, +2071, +1836, +2281, -1370, -2237, -2080, -2020, + -1960, -1964, -1968, -2028, -2088, -2020, -1952, -1855, -1758, -1725, -1692, -1635, -1578, + -1329, -1592, -1504, -1416, -1040, -1688, +2088, +2280, +2280, +1428, +1438, +1450, +1460, + +1472, +1463, +1454, +1493, +1533, +1512, +1748, -160, -2068, -1346, -1137, -1775, -1902, + -1848, -1794, -1708, -1622, -1544, -1466, -1356, -1247, -1198, -1149, -1196, -1755, -1246, + -993, -1012, -1032, -1202, +930, +2023, +1837, +2238, -2480, -2286, -1838, -1799, -1761, + -1835, -1909, -1954, -2000, -1982, -1964, -1908, -1853, -1829, -1807, -1749, -1692, -1538, + -1642, -1526, -1410, -638, -122, +774, +1926, +1926, +1400, +1417, +1434, +1451, +1469, + +1454, +1439, +1520, +1602, +1455, +1820, -1239, -1737, -1743, -726, -1821, -1892, -1822, + -1752, -1618, -1485, -1431, -1377, -1259, -1142, -1104, -1066, -1188, -1823, -1313, -803, + -869, -936, -1203, +2115, +1976, +1838, +916, -2055, -1569, -1596, -1579, -1563, -1706, + -1850, -1881, -1913, -1944, -1976, -1962, -1949, -1935, -1922, -1864, -1807, -1749, -1692, + -1548, -1404, -1004, -92, +996, +2084, +2084, +1372, +1394, +1418, +1441, +1465, +1444, + +1423, +1483, +1543, +1765, +1732, -2204, -1533, -1611, -1179, -1274, -1882, -1764, -1646, + -1560, -1475, -1301, -1127, -1113, -1101, -994, -887, -1052, -1730, -1395, -804, -709, + -872, -306, +2051, +1929, +2063, -151, -1597, -1347, -1354, -1326, -1300, -1417, -1535, + -1599, -1665, -1730, -1796, -1824, -1852, -1880, -1909, -1883, -1857, -1767, -1678, -1570, + -1462, -1434, +1154, +2402, +1858, +1858, +1344, +1373, +1403, +1432, +1462, +1435, +1409, + +1446, +1484, +1564, +621, -1890, -1842, -1737, -1633, -728, -1872, -1706, -1541, -1503, + -1466, -1428, -1391, -1225, -1060, -884, -709, -917, -1638, -1478, -807, -551, -808, + +590, +1988, +1882, +2288, -1218, -1140, -1126, -1112, -1075, -1038, -1129, -1220, -1319, + -1418, -1517, -1616, -1686, -1756, -1826, -1896, -1902, -1908, -1786, -1664, -1592, -1520, + -1864, +2400, +2016, +2144, +2144, +1348, +1372, +1398, +1424, +1450, +1463, +1477, +1491, + +1505, +1729, -607, -1838, -1790, -1735, -1681, -1003, -1350, -1710, -1558, -1519, -1480, + -1382, -1285, -1379, -1475, -1208, -941, -611, -793, -796, -800, -611, -680, +1364, + +1872, +1932, +1481, -1150, -966, -926, -886, -868, -851, -929, -1009, -1061, -1114, + -1230, -1348, -1521, -1695, -1805, -1915, -1900, -1886, -1792, -1698, -1604, -1766, -744, + +2326, +2134, +2198, +2198, +1352, +1373, +1395, +1417, +1439, +1492, +1546, +1536, +1526, + +1894, -1835, -1787, -1739, -1735, -1731, -1279, -828, -1714, -1577, -1536, -1495, -1337, + -1180, -1023, -866, -764, -663, -562, -973, -371, -282, -417, -552, +2138, +1757, + +1983, +674, -1083, -793, -726, -660, -662, -665, -731, -798, -804, -811, -945, + -1080, -1357, -1635, -1784, -1934, -1899, -1865, -1798, -1732, -1616, -2012, +376, +2252, + +2252, +2252, +2252, +1356, +1373, +1391, +1409, +1427, +1425, +1423, +1501, +1579, +907, + -1814, -1702, -1847, -1909, -1716, -1634, -786, -1686, -1819, -1712, -1605, -1371, -1139, + -921, -705, -656, -608, -384, -416, -233, -308, -477, +376, +1968, +1769, +2033, + -5, -839, -651, -606, -562, -584, -606, -660, -715, -739, -763, -963, -1164, + -1432, -1702, -1843, -1985, -1977, -1971, -1884, -1798, -2012, -2226, +2152, +2178, +2194, + +2210, +2210, +1360, +1374, +1388, +1402, +1416, +1358, +1300, +1466, +1632, -81, -1794, + -1619, -1956, -2085, -1702, -1991, -744, -891, -526, -353, -180, -383, -586, -821, + -1056, -805, -554, -463, -372, -353, -334, -539, +1304, +1799, +1782, +2085, -684, + -597, -510, -487, -464, -506, -548, -590, -632, -674, -716, -982, -1248, -1509, + -1770, -1903, -2036, -2057, -2078, -1971, -1864, -1896, -1416, +2392, +2104, +2136, +2168, + +2168, +1346, +1358, +1371, +1383, +1396, +1395, +1393, +1552, +1711, -1177, -1762, -2203, + -1364, -465, +690, +1942, +1913, +1747, +1837, +1816, +1794, +1889, +1983, +1774, +1564, + +548, -468, -299, -386, -391, -398, -147, +1895, +1920, +1946, +1284, -401, -397, + -393, -421, -450, -478, -507, -568, -629, -722, -815, -1068, -1321, -1697, -2074, + -2082, -2091, -2129, -2168, -2030, -1894, -2028, +142, +2280, +2114, +2082, +2050, +2050, + +1332, +1343, +1354, +1365, +1377, +1432, +1487, +1382, +1278, -1763, -195, +1308, +1788, + +1667, +1547, +1522, +1498, +1569, +1641, +1681, +1721, +1600, +1480, +1552, +1624, +1901, + +2179, +1145, -401, -431, -462, -12, +1974, +1786, +2111, +484, -119, -198, -277, + -356, -436, -451, -467, -547, -627, -770, -914, -898, -882, -606, -330, -470, + -611, -1435, -2259, -2091, -1924, -2160, +1700, +2168, +2124, +2028, +1932, +1932, +1318, + +1327, +1337, +1346, +1357, +1405, +1452, +1420, +1389, +1381, +1629, +1748, +1356, +1495, + +1635, +1631, +1627, +1551, +1732, +1689, +1647, +1728, +1809, +1730, +1652, +1686, +1721, + +1948, +1921, +874, -430, +363, +1925, +1764, +1859, +148, -28, -95, -160, -291, + -422, -423, -426, -557, -688, -370, -309, -280, -251, -570, -890, -858, -826, + -563, -301, -1079, -1858, -1636, +2170, +2296, +2166, +2118, +2070, +2070, +1304, +1312, + +1321, +1329, +1338, +1378, +1419, +1459, +1500, +1452, +1404, +1420, +1436, +1580, +1724, + +1484, +1244, +1022, +1313, +1187, +1062, +1088, +1115, +1397, +1680, +1728, +1777, +1729, + +1682, +1922, +1651, +1763, +1876, +1742, +1609, -189, +62, +8, -45, -226, -408, + -397, -387, -568, -750, -227, -217, -430, -644, -1047, -1451, -1502, -1554, -1229, + -905, -580, -256, -856, +1616, +1912, +2208, +2208, +2208, +2208, +1290, +1304, +1319, + +1334, +1350, +1377, +1404, +1271, +1395, +1525, +1655, +1769, +1884, +1802, +1720, +1430, + +1141, +1026, +1168, +1037, +908, +700, +491, +331, +172, +873, +1575, +1524, +1731, + +1991, +1738, +1774, +1811, +1914, +993, -119, +48, -74, -196, -271, -346, -407, + -470, -324, -179, -213, -503, -810, -1117, -1273, -1430, -1636, -1841, -1823, -1551, + -1246, -686, +1194, +1026, +1610, +2194, +2194, +2194, +2194, +1276, +1297, +1319, +1341, + +1363, +1376, +1390, +1340, +1802, +1854, +1907, +1863, +1820, +1768, +1717, +1377, +1038, + +1031, +1024, +889, +755, +568, +381, +290, +200, +19, -162, +553, +1781, +2060, + +1827, +1786, +1746, +2086, +378, -50, +35, -156, -348, -316, -284, -419, -554, + -337, -121, -456, -791, -934, -1078, -1244, -1411, -1514, -1617, -1907, -1686, -1657, + -1116, +1964, +1972, +2076, +2180, +2180, +2180, +2180, +1262, +1289, +1318, +1346, +1375, + +1359, +1344, +1632, +1921, +1927, +1934, +1876, +1820, +1702, +1585, +1259, +935, +907, + +880, +724, +569, +436, +302, +217, +132, +44, -43, -99, +102, +801, +2011, + +1878, +1745, +1426, +2131, +916, -43, -191, -340, -393, -446, -461, -478, -237, + -254, -522, -790, -962, -1135, -1519, -1647, -1760, -1872, -1446, -2045, -1827, -1354, + +2254, +2278, +2222, +2166, +2166, +2166, +2166, +1248, +1283, +1318, +1353, +1388, +1343, + +1298, +1925, +2040, +2001, +1962, +1891, +1820, +1637, +1454, +1143, +832, +784, +736, + +560, +384, +304, +224, +144, +64, +70, +76, +18, -40, +54, +1684, +1714, + +1744, +1790, +1836, +1882, +1928, +798, -332, -470, -608, -505, -402, -139, -388, + -589, -790, -991, -1192, -1794, -1884, -2006, -2128, -2266, -868, +818, +2504, +2288, + +2072, +2112, +2152, +2152, +2152, +2152, +1238, +1263, +1290, +1332, +1375, +1301, +1484, + +2002, +2009, +1973, +1939, +1871, +1805, +1608, +1411, +1118, +826, +751, +676, +505, + +334, +273, +212, +151, +91, +69, +48, +11, -26, +482, +1758, +1771, +1784, + +2033, +1771, +1860, +1950, +1989, +2029, +884, -260, -1156, -261, -309, -614, -922, + -975, -1411, -1848, -2062, -2019, -697, +626, +2060, +2471, +2273, +2076, +2051, +2026, + +2081, +2136, +2136, +2136, +2136, +1228, +1245, +1263, +1313, +1363, +1260, +1670, +2080, + +1978, +1947, +1916, +1853, +1791, +1580, +1369, +1094, +820, +718, +616, +450, +285, + +243, +201, +159, +118, +69, +20, +4, -13, +910, +1833, +1828, +1824, +229, + +1706, +1839, +1972, +1901, +1830, +1983, +2136, +2032, +1416, +1056, +696, +280, +376, + +728, +1080, +1767, +2454, +2405, +2356, +2035, +2226, +2193, +2160, +2070, +1980, +2050, + +2120, +2120, +2120, +2120, +1218, +1226, +1235, +1292, +1350, +1235, +1888, +2061, +1979, + +1935, +1893, +1834, +1776, +1551, +1326, +1070, +814, +685, +556, +395, +235, +212, + +189, +166, +145, +116, +88, -68, +33, +1306, +1811, +1949, +1576, -200, -183, + +905, +1994, +1956, +1919, +1881, +1844, +2004, +1909, +2005, +2102, +2042, +2239, +2195, + +2152, +2043, +1935, +2370, +2038, +2697, +1821, +368, +2244, +2121, +1998, +2051, +2104, + +2104, +2104, +2104, +1208, +1208, +1209, +1273, +1338, +1210, +2107, +2043, +1980, +1925, + +1871, +1816, +1762, +1523, +1285, +1046, +808, +652, +497, +341, +186, +182, +179, + +175, +172, +164, +157, +117, +590, +1958, +1791, +1815, +816, +140, -24, -28, + -32, +988, +2008, +2036, +2064, +1977, +1890, +1931, +1972, +2013, +2054, +2127, +2200, + +2320, +2440, +2080, +184, -1760, -3192, +336, +2328, +2172, +2016, +2052, +2088, +2088, + +2088, +2088, +1222, +1215, +1209, +1266, +1325, +1459, +2104, +2046, +1989, +1945, +1903, + +1861, +1819, +1612, +1406, +1136, +866, +715, +564, +446, +328, +295, +263, +230, + +199, +481, +764, +711, +1427, +2086, +1721, +1692, +128, -37, +55, -14, -82, + -108, -135, +335, +804, +1293, +1783, +2272, +2250, +2197, +1889, +1356, +568, -763, + -2095, -3010, -2646, -2931, -2705, +2305, +2196, +2159, +2122, +2117, +2112, +2112, +2112, + +2112, +1236, +1223, +1210, +1261, +1313, +1708, +2103, +2050, +1998, +1967, +1937, +1907, + +1877, +1702, +1528, +1226, +924, +778, +633, +552, +471, +409, +348, +287, +226, + +287, +349, +283, +1241, +1702, +1652, +1826, -48, +43, +134, +1, -132, -181, + -230, -343, -456, -670, -884, -202, -544, -946, -1860, -1718, -2088, -2311, -2534, + -2469, -2404, -2311, -1706, +2483, +2064, +2146, +2228, +2182, +2136, +2136, +2136, +2136, + +1250, +1230, +1211, +1255, +1300, +1957, +2101, +2054, +2007, +1956, +1906, +1856, +1806, + +1696, +1586, +1284, +982, +841, +701, +657, +613, +554, +497, +438, +381, +412, + +445, +717, +1758, +1782, +1807, +1095, -128, -70, -11, -97, -182, -253, -325, + -428, -532, -761, -991, -580, -170, -1033, -873, -1976, -1800, -2018, -2237, -2343, + -2450, -2650, -35, +2308, +2092, +2117, +2142, +2151, +2160, +2160, +2160, +2160, +1264, + +1238, +1212, +1250, +1288, +2206, +2100, +2058, +2016, +1946, +1876, +1806, +1736, +1690, + +1644, +1342, +1040, +905, +770, +763, +756, +701, +646, +591, +536, +539, +542, + +897, +1764, +1607, +1962, +365, -208, -182, -156, -194, -232, -326, -420, -514, + -608, -853, -1098, -1471, -820, -97, -910, -955, -2024, -2238, -2452, -2474, -2496, + -2990, +1636, +2134, +2120, +2088, +2056, +2120, +2184, +2184, +2184, +2184, +1198, +1191, + +1185, +1227, +1525, +2065, +2093, +2009, +1925, +1887, +1850, +1781, +1712, +1682, +1653, + +1464, +1275, +1130, +986, +937, +889, +840, +792, +743, +696, +684, +674, +1335, + +1741, +1839, +1939, +54, -294, -295, -297, -298, -300, -414, -527, -641, -755, + -947, -1140, -1732, -1813, -733, -166, -1038, -887, -1234, -1581, -1609, -1636, -1158, + +2392, +2279, +2166, +2119, +2072, +2121, +2170, +2170, +2170, +2170, +1132, +1145, +1159, + +1205, +1763, +1924, +2086, +1960, +1834, +1829, +1825, +1756, +1688, +1675, +1663, +1586, + +1510, +1356, +1202, +1112, +1023, +981, +939, +897, +856, +831, +807, +1774, +1718, + +1817, +1405, -512, -380, -409, -438, -403, -369, -502, -635, -768, -902, -1042, + -1182, -1482, -1782, -2138, -1982, -610, -262, -486, -711, -744, -777, +162, +2125, + +1912, +2212, +2150, +2088, +2122, +2156, +2156, +2156, +2156, +1194, +1146, +1100, +1182, + +1776, +1927, +2079, +1863, +1903, +1978, +1799, +1843, +1632, +1619, +1608, +1612, +1617, + +1517, +1418, +1351, +1284, +1216, +1149, +1098, +1048, +945, +1099, +1781, +1695, +1954, + +422, -566, -530, -554, -579, -571, -565, -686, -806, -927, -1049, -1232, -1416, + -1679, -1943, -2342, -2486, -2501, -2773, -2074, -1376, -1671, -2221, +458, +2369, +2137, + +2162, +2133, +2104, +2123, +2142, +2142, +2142, +2142, +1256, +1149, +1043, +1160, +1790, + +1931, +2073, +1766, +1972, +2129, +1774, +1931, +1576, +1565, +1554, +1639, +1724, +1679, + +1635, +1590, +1546, +1453, +1361, +1300, +1240, +1060, +1392, +1788, +1672, +2092, -560, + -620, -680, -700, -721, -741, -762, -870, -979, -1087, -1196, -1423, -1650, -1877, + -2104, -2291, -2478, -2857, -2724, -2895, -3067, -3110, -3666, +2547, +2103, +2107, +2112, + +2116, +2120, +2124, +2128, +2128, +2128, +2128, +1214, +1170, +1128, +1453, +1779, +1692, + +1861, +1807, +1753, +1732, +1712, +1803, +1640, +1759, +1623, +1710, +1799, +1666, +1790, + +1755, +1719, +1628, +1539, +1497, +1456, +1352, +1504, +1752, +1745, +1445, -902, -898, + -894, -907, -921, -935, -950, -1070, -1190, -1310, -1431, -1641, -1852, -2062, -2273, + -2431, -2590, -2812, -2779, -2929, -3080, -3279, -2198, +2298, +2187, +2124, +2062, +2081, + +2100, +2119, +2138, +2138, +2138, +2138, +1172, +1193, +1214, +1747, +1769, +1710, +2163, + +2360, +2046, +1592, +1651, +1677, +1704, +1954, +1693, +1783, +1874, +1654, +1947, +1920, + +1893, +1805, +1718, +1695, +1672, +1644, +1617, +1717, +1818, +798, -1245, -1176, -1108, + -1115, -1123, -1131, -1139, -1270, -1402, -1534, -1666, -1860, -2054, -2248, -2442, -2572, + -2702, -2768, -2834, -2964, -3094, -3192, -219, +2306, +2272, +2142, +2012, +2046, +2080, + +2114, +2148, +2148, +2148, +2148, +1194, +1150, +1364, +1784, +1694, +1983, +2272, +1441, + +2147, +1980, +1813, +1838, +1864, +1909, +1698, +1823, +1949, +1818, +1943, +1989, +2034, + +1933, +1833, +1812, +1792, +1712, +1633, +1649, +1923, -536, -1459, -1390, -1322, -1354, + -1388, -1421, -1455, -1566, -1678, -1789, -1901, -2078, -2256, -2433, -2611, -2744, -2878, + -2915, -2953, -2998, -3044, -3777, +1633, +2298, +1941, +2015, +2090, +2107, +2124, +2141, + +2158, +2158, +2158, +2158, +1216, +1109, +1514, +1823, +1620, +2001, +1870, +1803, +1224, + +1600, +1464, +1232, +1000, +1096, +1192, +1352, +1512, +1726, +1940, +2058, +2176, +2062, + +1948, +1930, +1912, +1781, +1650, +1583, +2028, -1871, -1674, -1605, -1536, -1595, -1654, + -1713, -1772, -1863, -1954, -2045, -2136, -2297, -2458, -2619, -2780, -2917, -3054, -3063, + -3072, -3033, -2994, -2827, +2460, +2035, +2122, +2145, +2168, +2168, +2168, +2168, +2168, + +2168, +2168, +2168, +1190, +1271, +1610, +1756, +1647, +1523, +1144, +1324, +1249, +1364, + +1224, +1211, +1199, +1255, +1566, +1430, +1294, +1404, +1514, +1800, +2087, +2075, +2063, + +2003, +1944, +1654, +1621, +1811, +979, -1997, -1903, -1888, -1874, -1927, -1982, -2036, + -2091, -2163, -2236, -2308, -2381, -2513, -2646, -2778, -2911, -3005, -3100, -3114, -3129, + -3039, -3206, -1084, +2317, +2104, +2148, +2159, +2171, +2175, +2179, +2183, +2187, +2187, + +2187, +2187, +1164, +1179, +1195, +1179, +1163, +1302, +1442, +1358, +1274, +1385, +1496, + +1447, +1399, +1158, +1429, +1508, +1588, +1594, +1601, +1543, +1486, +1832, +2179, +2077, + +1976, +1528, +1593, +1785, -582, -2381, -2133, -2172, -2212, -2261, -2311, -2361, -2411, + -2464, -2518, -2572, -2626, -2730, -2834, -2938, -3042, -3094, -3146, -3166, -3186, -3046, + -3418, +658, +2174, +2174, +2174, +2174, +2174, +2182, +2190, +2198, +2206, +2206, +2206, + +2206, +1202, +1230, +1259, +1272, +1286, +1321, +1356, +1343, +1331, +1405, +1480, +1474, + +1470, +1349, +1483, +1522, +1562, +1576, +1591, +1573, +1557, +1589, +1622, +1718, +1816, + +1690, +1820, +1694, -2015, -2556, -2330, -2376, -2422, -2610, -2799, -2700, -2602, -2669, + -2736, -2803, -2871, -2946, -3022, -3097, -3173, -3182, -3192, -3153, -3115, -3324, -3278, + +2256, +2159, +2147, +2136, +2156, +2177, +2189, +2201, +2213, +2225, +2225, +2225, +2225, + +1240, +1282, +1325, +1367, +1410, +1340, +1271, +1329, +1388, +1426, +1465, +1503, +1542, + +1540, +1539, +1537, +1536, +1559, +1582, +1605, +1628, +1603, +1578, +1617, +1656, +1596, + +1536, +1604, -2936, -2476, -2528, -2580, -2632, -2704, -2777, -2785, -2794, -2874, -2955, + -3035, -3116, -3163, -3210, -3257, -3304, -3271, -3238, -3141, -3044, -3091, -2114, +2319, + +2144, +2121, +2098, +2139, +2180, +2196, +2212, +2228, +2244, +2244, +2244, +2244, +1230, + +1255, +1281, +1306, +1333, +1303, +1272, +1338, +1405, +1436, +1468, +1500, +1533, +1535, + +1537, +1539, +1542, +1562, +1584, +1605, +1627, +1601, +1577, +1616, +1656, +1807, +1959, + -417, -2793, -2797, -2545, -2581, -2618, -2687, -2757, -2794, -2833, -2901, -2968, -3036, + -3105, -3145, -3186, -3178, -3171, -3149, -3128, -3058, -2989, -3221, -126, +2281, +2129, + +2084, +2040, +2107, +2175, +2189, +2203, +2217, +2231, +2231, +2231, +2231, +1220, +1229, + +1238, +1247, +1257, +1266, +1275, +1348, +1422, +1447, +1473, +1499, +1525, +1530, +1536, + +1542, +1548, +1567, +1587, +1606, +1626, +1601, +1577, +1616, +1656, +1763, +1871, +1658, + -2138, -2862, -2563, -2583, -2604, -2671, -2738, -2805, -2873, -2928, -2983, -3038, -3094, + -3128, -3162, -3100, -3038, -3028, -3018, -2976, -2934, -3352, +1862, +2244, +2114, +2048, + +1982, +2076, +2170, +2182, +2194, +2206, +2218, +2218, +2218, +2218, +1210, +1234, +1259, + +1283, +1308, +1325, +1341, +1390, +1439, +1457, +1477, +1496, +1516, +1525, +1535, +1544, + +1554, +1571, +1589, +1607, +1625, +1616, +1608, +1632, +1656, +1718, +1782, +1685, +1845, + +528, -2836, -2728, -2622, -2654, -2687, -2719, -2752, -2763, -2773, -2992, -2955, -3030, + -3106, -2813, -2777, -3226, -2908, -3134, -3359, -971, +2186, +2270, +2099, +2075, +2052, + +2108, +2165, +2175, +2185, +2195, +2205, +2205, +2205, +2205, +1200, +1240, +1280, +1320, + +1360, +1384, +1408, +1432, +1456, +1469, +1482, +1495, +1508, +1521, +1534, +1547, +1560, + +1576, +1592, +1608, +1624, +1632, +1640, +1648, +1656, +1675, +1694, +1713, +1732, +1871, + +986, -827, -2640, -2638, -2636, -2634, -2632, -2598, -2564, -2946, -2816, -2933, -3050, + -2783, -3028, -3169, -1774, +293, +2360, +2179, +1998, +2041, +2084, +2103, +2122, +2141, + +2160, +2168, +2176, +2184, +2192, +2192, +2192, +2192, +1232, +1266, +1300, +1334, +1368, + +1390, +1412, +1434, +1456, +1468, +1482, +1494, +1508, +1520, +1534, +1546, +1560, +1578, + +1596, +1614, +1632, +1640, +1648, +1656, +1664, +1645, +1628, +1705, +1784, +2101, +1908, + +1298, +688, +1071, -594, -1587, -2580, -2891, -3202, -2281, -2640, -2058, -1476, -94, + +1032, +2278, +2244, +2209, +2176, +2131, +2088, +2091, +2096, +2111, +2128, +2143, +2160, + +2168, +2176, +2184, +2192, +2192, +2192, +2192, +1264, +1292, +1320, +1348, +1376, +1396, + +1416, +1436, +1456, +1469, +1482, +1495, +1508, +1521, +1534, +1547, +1560, +1580, +1600, + +1620, +1640, +1648, +1656, +1664, +1672, +1617, +1562, +1699, +1836, +1821, +1806, +1887, + +1968, +1964, +1960, +2020, +2080, +1936, +1792, +1200, +1632, +1889, +2146, +2083, +2020, + +2093, +2166, +2079, +1992, +2085, +2178, +2143, +2108, +2121, +2134, +2147, +2160, +2168, + +2176, +2184, +2192, +2192, +2192, +2192, +1296, +1318, +1340, +1362, +1384, +1402, +1420, + +1438, +1456, +1468, +1482, +1494, +1508, +1520, +1534, +1546, +1560, +1582, +1604, +1626, + +1648, +1656, +1664, +1672, +1680, +1667, +1656, +1739, +1824, +1811, +1800, +1835, +1872, + +1881, +1890, +1819, +1748, +1995, +450, +937, +912, +715, +2056, +2019, +1984, +2035, + +2088, +2059, +2032, +2085, +2140, +2129, +2120, +2129, +2140, +2149, +2160, +2168, +2176, + +2184, +2192, +2192, +2192, +2192, +1328, +1344, +1360, +1376, +1392, +1408, +1424, +1440, + +1456, +1469, +1482, +1495, +1508, +1521, +1534, +1547, +1560, +1584, +1608, +1632, +1656, + +1664, +1672, +1680, +1688, +1719, +1750, +1781, +1812, +1803, +1794, +1785, +1776, +1798, + +1820, +1874, +1928, +1798, +2180, +674, +1216, +2103, +1966, +1957, +1948, +1979, +2010, + +2041, +2072, +2087, +2102, +2117, +2132, +2139, +2146, +2153, +2160, +2168, +2176, +2184, + +2192, +2192, +2192, +2192, +1328, +1344, +1360, +1376, +1392, +1408, +1424, +1440, +1456, + +1468, +1482, +1494, +1508, +1520, +1534, +1546, +1560, +1584, +1608, +1632, +1656, +1664, + +1672, +1680, +1688, +1718, +1750, +1780, +1812, +1802, +1794, +1784, +1776, +1798, +1820, + +1858, +1896, +1750, +1860, +2338, +1792, +2134, +1966, +1956, +1948, +1978, +2010, +2040, + +2072, +2086, +2102, +2116, +2132, +2138, +2146, +2152, +2160, +2168, +2176, +2184, +2192, + +2192, +2192, +2192, +1328, +1344, +1360, +1376, +1392, +1408, +1424, +1440, +1456, +1469, + +1482, +1495, +1508, +1521, +1534, +1547, +1560, +1584, +1608, +1632, +1656, +1664, +1672, + +1680, +1688, +1719, +1750, +1781, +1812, +1803, +1794, +1785, +1776, +1798, +1820, +1842, + +1864, +1958, +2052, +1954, +1856, +1911, +1966, +1957, +1948, +1979, +2010, +2041, +2072, + +2087, +2102, +2117, +2132, +2139, +2146, +2153, +2160, +2168, +2176, +2184, +2192, +2192, + +2192, +2192, +1328, +1344, +1360, +1376, +1392, +1408, +1424, +1440, +1456, +1468, +1482, + +1494, +1508, +1520, +1534, +1546, +1560, +1584, +1608, +1632, +1656, +1664, +1672, +1680, + +1688, +1718, +1750, +1780, +1812, +1802, +1794, +1784, +1776, +1798, +1820, +1842, +1864, + +1958, +2052, +1954, +1856, +1910, +1966, +1956, +1948, +1978, +2010, +2040, +2072, +2086, + +2102, +2116, +2132, +2138, +2146, +2152, +2160, +2168, +2176, +2184, +2192, +2192, +2192, + +2192 +}; + +static const INT16 TEST_CR_COMPONENT[4096] = { + -2112, -2114, -2116, -2118, -2120, -2122, -2124, -2126, -2128, -2118, -2108, -2098, -2088, + -2150, -2212, -2146, -2080, -2100, -2120, -2140, -2160, -2164, -2168, -2172, -2176, -2092, + -2008, -2052, -2096, -2132, -2168, -2076, -1984, -2088, -2192, -2168, -2144, -2136, -2128, + -2120, -2112, -2126, -2140, -2154, -2168, -2150, -2132, -2114, -2096, -2096, -2096, -2096, + -2096, -2096, -2096, -2096, -2096, -2080, -2064, -2048, -2032, -2032, -2032, -2032, -2128, + -2113, -2098, -2115, -2132, -2133, -2134, -2135, -2137, -2127, -2117, -2107, -2097, -2117, + -2137, -2125, -2114, -2134, -2154, -2159, -2163, -2135, -2108, -2128, -2149, -2132, -2116, + -2116, -2115, -2115, -2114, -2098, -2082, -2112, -2142, -2141, -2139, -2133, -2128, -2122, + -2117, -2127, -2137, -2147, -2158, -2146, -2134, -2122, -2111, -2108, -2106, -2104, -2102, + -2101, -2101, -2101, -2101, -2087, -2073, -2059, -2045, -2045, -2045, -2045, -2144, -2112, + -2080, -2112, -2145, -2145, -2145, -2145, -2146, -2136, -2126, -2116, -2107, -2085, -2063, + -2105, -2148, -2168, -2189, -2178, -2167, -2107, -2048, -2085, -2122, -2173, -2225, -2180, + -2135, -2098, -2061, -2120, -2180, -2136, -2093, -2114, -2135, -2131, -2128, -2125, -2122, + -2128, -2135, -2141, -2148, -2142, -2137, -2131, -2126, -2121, -2117, -2112, -2108, -2107, + -2107, -2106, -2106, -2094, -2082, -2070, -2058, -2058, -2058, -2058, -2160, -2111, -2062, + -2109, -2157, -2156, -2155, -2154, -2155, -2145, -2135, -2125, -2116, -2132, -2148, -2132, + -2118, -2154, -2191, -2181, -2170, -2494, -2308, -2393, -2479, -2470, -2461, -2243, -2282, + -2353, -2167, -2174, -2182, -2160, -2139, -2135, -2130, -2128, -2128, -2127, -2127, -2129, + -2132, -2134, -2138, -2138, -2139, -2139, -2141, -2133, -2127, -2120, -2114, -2112, -2112, + -2111, -2111, -2101, -2091, -2081, -2071, -2071, -2071, -2071, -2176, -2110, -2045, -2107, + -2170, -2168, -2167, -2165, -2164, -2154, -2145, -2135, -2126, -2180, -2235, -2161, -2088, + -2141, -2195, -2440, -2686, -2371, -1033, -398, +236, +305, +375, -3, -894, -2096, + -2787, -2485, -2184, -2185, -2187, -2156, -2126, -2127, -2129, -2130, -2132, -2131, -2130, + -2129, -2128, -2135, -2142, -2149, -2156, -2147, -2138, -2129, -2120, -2119, -2118, -2117, + -2116, -2108, -2100, -2092, -2084, -2084, -2084, -2084, -2112, -2085, -2058, -2112, -2166, + -2067, -2225, -2190, -2157, -2107, -2057, -2104, -2151, -2119, -2088, -2632, -2666, -2263, + -837, +844, +2526, +3327, +2847, +2847, +2847, +2726, +2606, +2967, +3070, +2968, +2867, + +397, -2074, -2745, -2137, -2281, -2169, -2202, -2236, -2190, -2145, -2145, -2147, -2148, + -2150, -2152, -2156, -2159, -2163, -2159, -2156, -2152, -2150, -2130, -2111, -2123, -2137, + -2127, -2117, -2107, -2097, -2097, -2097, -2097, -2048, -2060, -2073, -2118, -2163, -1967, + -2284, -2217, -2150, -2060, -1971, -2074, -2177, -2315, -2454, -1057, +1364, +2990, +2568, + +2593, +2619, +2369, +2631, +2508, +2386, +2332, +2278, +2352, +2427, +2913, +2888, +3022, + +3156, +1302, -2088, -2406, -2213, -2279, -2345, -2251, -2158, -2161, -2165, -2168, -2172, + -2171, -2171, -2170, -2170, -2172, -2175, -2177, -2180, -2142, -2105, -2131, -2158, -2146, + -2134, -2122, -2110, -2110, -2110, -2110, -2112, -2163, -2215, -2235, -2255, -1994, -2247, + -2194, -2143, -2109, -2076, -2123, -2170, -2270, +700, +3527, +2770, +2035, +2325, +2293, + +2263, +2178, +2350, +2265, +2181, +2129, +2078, +2154, +2231, +2521, +2557, +2559, +2562, + +3221, +3113, +140, -2832, -2034, -2261, -2199, -2139, -2160, -2182, -2188, -2194, -2189, + -2185, -2181, -2177, -2185, -2193, -2201, -2210, -2154, -2098, -2138, -2179, -2165, -2151, + -2137, -2123, -2123, -2123, -2123, -1664, -1755, -1846, -1841, -1836, -1767, -2210, -2173, + -2136, -2159, -2182, -2173, -2164, -2739, +2830, +2735, +2640, +2361, +2082, +1995, +1908, + +1989, +2070, +2023, +1976, +1927, +1878, +1957, +2036, +2131, +2226, +2353, +2480, +2581, + +2682, +2943, +2692, -2815, -2178, -2149, -2120, -2160, -2200, -2208, -2216, -2208, -2200, + -2192, -2184, -2198, -2212, -2226, -2240, -2166, -2092, -2146, -2200, -2184, -2168, -2152, + -2136, -2136, -2136, -2136, -2096, -2166, -2238, -2228, -2220, -2087, -2210, -2173, -2137, + -2189, -2243, -2152, -2318, -2031, +3375, +2861, +2605, +2305, +2007, +1851, +1697, +1756, + +1815, +1810, +1806, +1756, +1707, +1754, +1801, +1911, +2023, +2149, +2277, +2299, +2323, + +2729, +1345, -2439, -2129, -2217, -2307, -2349, -2136, -2179, -2222, -2223, -2224, -2193, + -2162, -2171, -2180, -2190, -2199, -2198, -2198, -2213, -2229, -2172, -2115, -2170, -2225, + -2113, -2257, -2257, -2016, -2067, -2118, -2105, -2093, -2152, -2211, -2174, -2138, -2221, + -2305, -2132, -2472, +212, +2897, +2477, +2570, +2251, +1932, +1709, +1487, +1524, +1561, + +1598, +1636, +1586, +1537, +1552, +1567, +1693, +1820, +1947, +2074, +2019, +1964, +2261, + -514, -2321, -2080, -2031, -1982, -2283, -2073, -2151, -2229, -2238, -2248, -2194, -2140, + -2144, -2149, -2154, -2159, -2231, -2304, -2281, -2258, -2160, -2062, -2188, -2314, -2090, + -2378, -2378, -2064, -2094, -2126, -2125, -2125, -2152, -2179, -2159, -2139, -2204, -2270, + -2144, -2530, +1688, +2834, +2460, +2343, +2147, +1953, +1678, +1404, +1387, +1370, +1418, + +1466, +1416, +1366, +1349, +1332, +1442, +1553, +1663, +1775, +1817, +1861, +2415, -2405, + -2457, -1999, -2035, -281, -1464, -2393, -2378, -2363, -2301, -2240, -2195, -2150, -2165, + -2181, -2182, -2182, -2199, -2218, -2188, -2159, -2756, -2329, -1934, -2307, -2627, -2179, + -2307, -2112, -2123, -2135, -2146, -2158, -2153, -2149, -2144, -2140, -2188, -2236, -2156, + -2588, +3164, +2772, +2444, +2116, +2045, +1975, +1648, +1322, +1251, +1181, +1238, +1296, + +1246, +1197, +1147, +1098, +1192, +1287, +1381, +1476, +1617, +1758, +1291, -2760, -2083, + -2430, -1273, -628, -647, -667, -1582, -2498, -2365, -2233, -2196, -2160, -2187, -2215, + -2210, -2206, -2169, -2133, -2096, -2060, -280, -548, -2448, -1788, -860, -1980, -2236, + -2112, -2120, -2130, -2140, -2150, -2145, -2141, -2137, -2133, -2147, -2161, -2079, -718, + +3207, +2525, +2291, +2057, +1941, +1827, +1553, +1279, +1174, +1070, +1094, +1118, +1044, + +970, +976, +983, +1001, +1019, +1165, +1313, +1305, +1555, -212, -2491, -2189, -2401, + -867, -615, -642, -671, -603, -536, -1354, -2172, -2271, -2370, -2340, -2311, -2330, + -2349, -2315, -2282, -2697, -1321, -420, -543, -394, -757, -741, -2261, -2261, -2112, + -2119, -2127, -2135, -2143, -2138, -2134, -2130, -2126, -2106, -2087, -2259, +640, +2995, + +2279, +2138, +1998, +1839, +1681, +1459, +1237, +1098, +960, +950, +940, +842, +744, + +806, +869, +811, +753, +951, +1150, +995, +1352, -1715, -2222, -2297, -2372, -463, + -602, -639, -676, -649, -623, -600, -577, -810, -1044, -1214, -1384, -1426, -1469, + -1183, -897, -483, -582, -560, -538, -900, -750, -1134, -2542, -2286, -2112, -2117, + -2123, -2129, -2135, -2131, -2127, -2123, -2119, -2017, -1916, -2886, +1262, +2014, +2256, + +2097, +1939, +1736, +1534, +1364, +1194, +1022, +850, +806, +762, +736, +710, +508, + +818, +604, +646, +752, +859, +1131, +1149, -2865, -2273, -2339, -1639, -425, -493, + -522, -553, -566, -581, -677, -773, -661, -550, -567, -585, -586, -588, -657, + -727, -572, -675, -668, -661, -798, -679, -1799, -2407, -2151, -2112, -2116, -2120, + -2124, -2128, -2124, -2120, -2116, -2112, -2185, -2258, -1723, +1884, +1035, +2234, +2057, + +1880, +1634, +1388, +1270, +1152, +946, +740, +662, +584, +630, +676, +466, +1280, + +654, +540, +554, +568, +757, -78, -2481, -2324, -2383, -906, -389, -384, -407, + -430, -485, -540, -499, -458, -513, -568, -689, -810, -771, -732, -645, -558, + -663, -768, -776, -784, -696, -608, -2464, -2272, -2016, -2104, -2110, -2116, -2122, + -2129, -2105, -2081, -2105, -2130, -2204, -2536, -84, +1856, +1148, +1209, +1701, +1683, + +1507, +1332, +1188, +1045, +837, +630, +518, +407, +489, +572, +398, +1249, +662, + +330, +383, +436, +589, -1304, -2350, -2117, -2615, +213, -12, -239, -265, -293, + -320, -348, -377, -407, -484, -562, -626, -691, -675, -661, -625, -590, -682, + -776, -804, -832, -540, -248, -664, -1848, -2616, -2096, -2104, -2113, -2121, -2130, + -2086, -2043, -2095, -2148, -2225, -2815, +1555, +1829, +1519, +697, +1603, +1486, +1381, + +1276, +1107, +938, +729, +520, +375, +230, +349, +468, +331, +1219, +670, +121, + +212, +304, +423, -2531, -2477, -2423, -1569, +309, -149, -94, -125, -157, -157, + -157, -256, -356, -456, -556, -564, -573, -581, -590, -606, -623, -703, -784, + -832, -880, -384, +112, -1424, -2448, -2192, -2088, -2098, -2109, -2119, -2131, -2099, + -2068, -2100, -2134, -2485, -2325, +2921, +2025, +1536, +1048, +1088, +1385, +1270, +1156, + +993, +831, +700, +570, +407, +245, +256, +268, +343, +932, +662, +135, +185, + +236, -337, -2445, -2346, -2504, -793, +149, -75, -45, -64, -84, -88, -93, + -183, -273, -363, -454, -454, -454, -518, -583, -619, -655, -723, -792, -796, + -800, -868, -1960, -2296, -2376, -2248, -2080, -2093, -2106, -2119, -2132, -2113, -2094, + -2107, -2120, -2234, -813, +2752, +2222, +1555, +1401, +574, +1284, +1160, +1036, +880, + +724, +672, +620, +440, +260, +164, +69, +357, +646, +654, +151, +159, +168, + -1096, -2361, -2217, -2586, -18, -11, -3, +4, -4, -13, -21, -30, -110, + -191, -271, -352, -344, -336, -456, -576, -632, -688, -744, -800, -760, -720, + -584, -2496, -2400, -2304, -2304, -2072, -2086, -2102, -2117, -2133, -2171, -2211, -2170, + -2130, -2462, +1045, +2615, +2138, +1656, +1432, +807, +951, +1193, +924, +734, +545, + +397, +250, +486, +723, +569, +416, +311, +207, +384, +305, +242, +180, -1825, + -2295, -2348, -1891, +69, -19, -10, -3, -7, -12, -16, -22, -65, -107, + -182, -258, -309, -361, -477, -593, -640, -688, -736, -784, -752, -720, -1200, + -2448, -2384, -2320, -2320, -2064, -2081, -2099, -2116, -2134, -2231, -2329, -2234, -2140, + -2691, +2902, +2478, +2055, +1759, +1464, +1041, +618, +1227, +812, +589, +366, +379, + +392, +277, +162, +207, +253, +267, +281, +114, -52, +70, +192, -2555, -2230, + -2481, -1197, +156, -28, -19, -10, -11, -12, -13, -15, -20, -25, -94, + -164, -275, -387, -498, -610, -649, -689, -728, -768, -744, -720, -1816, -2400, + -2368, -2336, -2336, -2056, -2075, -2095, -2115, -2135, -2178, -2222, -2138, -2310, -1319, + +2743, +2293, +2099, +1893, +1432, +1242, +541, +1036, +1020, +699, +379, +376, +374, + +275, +177, +196, +217, +189, +162, +100, +39, +153, -756, -2420, -2293, -2549, + -502, +131, -4, -10, -17, -14, -12, -9, -7, -7, -6, -102, -198, + -320, -444, -519, -595, -641, -689, -720, -752, -768, -784, -2192, -2320, -2336, + -2352, -2352, -2048, -2070, -2092, -2114, -2136, -2126, -2116, -2042, -2480, +52, +2584, + +2108, +2144, +2028, +1400, +1444, +464, +78, -308, -470, -632, -394, -156, +18, + +192, +187, +182, +113, +44, +87, +130, +237, -1704, -2286, -2356, -2618, +192, + +106, +20, -2, -24, -18, -12, -6, +0, +6, +12, -110, -232, -367, + -502, -541, -580, -635, -690, -713, -736, -792, -848, -2568, -2240, -2304, -2368, + -2368, -2046, -2068, -2091, -2113, -2136, -2121, -2105, -2186, -2523, +1999, +2681, +2740, + +1518, +117, -1541, -2639, -2457, -2465, -2474, -2466, -2459, -2498, -2536, -2303, -2070, + -995, +81, -76, +24, +35, +47, -150, -2394, -2422, -2450, -1806, +117, +85, + +53, +21, -11, -11, -11, -11, -11, -11, -11, -107, -203, -404, -606, + -615, -625, -610, -596, -693, -791, -757, -1491, -2401, -2287, -2303, -2319, -2319, + -2044, -2067, -2090, -2113, -2137, -2116, -2095, -2074, -2054, +2923, +219, -1748, -2692, + -2563, -2435, -2114, -2306, -2193, -2080, -2159, -2239, -2298, -2357, -2320, -2284, -2432, + -2580, -1544, +4, -16, -36, -280, -2572, -2302, -2544, -994, +43, +64, +86, + +44, +2, -4, -10, -16, -22, -28, -34, -104, -174, -186, -198, -178, + -158, -330, -502, -674, -846, -722, -2134, -2234, -2334, -2302, -2270, -2270, -2042, + -2065, -2089, -2112, -2137, -2159, -2180, -2154, -2129, -2458, -2532, -2604, -2166, -2218, + -2272, -2293, -2315, -2000, -2198, -2219, -2242, -2322, -2401, -2385, -2370, -2285, -2201, + -2452, -2704, -1411, +137, -1402, -2174, -2502, -2830, +250, +0, +28, +55, +35, + +15, +3, -9, -21, -33, -45, -57, -101, -145, -175, -206, -220, -235, + -177, -120, -414, -709, -191, -2489, -2547, -2349, -2349, -2349, -2349, -2040, -2064, + -2089, -2113, -2138, -2202, -2267, -2235, -2204, -2207, -2210, -2181, -2152, -2131, -2110, + -2217, -1812, -1552, -2317, -2025, -1734, -1578, -1423, -1939, -2456, -2395, -2334, -2081, + -2340, -2551, -2250, -2013, -2288, -2446, -2093, -43, -42, -8, +25, +26, +28, + +10, -8, -26, -44, -62, -80, -98, -116, -165, -214, -263, -312, -281, + -250, -155, -60, -940, -1820, -2348, -2364, -2396, -2428, -2428, -2038, -2058, -2079, + -2100, -2122, -2123, -2124, -2285, -2191, -2065, -1940, -1910, -1882, -2232, -2327, -2149, + -1717, -1485, -2022, -1759, -1497, -1242, -987, -716, -446, -1226, -2007, -2723, -2160, + -2330, -2245, -2175, -2362, -2338, -1034, +109, -28, -19, -10, +15, +41, +19, + -3, -25, -47, -89, -131, -141, -151, -208, -266, -355, -445, -458, -472, + -405, -83, -1135, -1163, -1895, -2371, -2387, -2403, -2403, -2036, -2053, -2071, -2089, + -2107, -2044, -1982, -2080, -1666, -1668, -1671, -1897, -2124, -2590, -2545, -2083, -1622, + -1419, -1729, -1495, -1261, -1162, -1064, -774, -484, -314, -144, -806, -2492, -2366, + -2240, -2338, -2436, -2486, -489, +4, -15, -30, -45, +4, +54, +28, +2, + -24, -50, -116, -182, -184, -186, -252, -318, -448, -578, -636, -694, -656, + -106, -2098, -2042, -2210, -2378, -2378, -2378, -2378, -2034, -2047, -2062, -2076, -2091, + -2093, -2096, -1650, -1461, -1687, -1913, -2155, -2398, -2676, -2442, -2016, -1591, -1448, + -1563, -1341, -1120, -986, -853, -623, -394, -265, -137, +200, +24, -1554, -2363, + -2324, -2286, -2122, -2727, -1220, +31, +136, -15, +25, +67, +37, +7, -7, + -21, -111, -201, -211, -221, -295, -370, -460, -551, -509, -468, -634, -545, + -2805, -2249, -2301, -2353, -2353, -2353, -2353, -2032, -2043, -2054, -2065, -2076, -2143, + -2210, -1477, -1768, -1962, -2156, -2414, -2672, -2762, -2340, -1950, -1560, -1479, -1398, + -1189, -980, -811, -642, -473, -304, -217, -130, -75, -20, +27, -2486, -2311, + -2136, -2527, -2406, -2445, -2484, -979, +14, +47, +80, +46, +12, +10, +8, + -106, -220, -238, -256, -339, -422, -473, -524, -639, -754, -1637, -2520, -2232, + -2456, -2392, -2328, -2328, -2328, -2328, -2012, -2030, -2049, -2052, -2055, -2191, -2073, + -1585, -1867, -2081, -2296, -2526, -2757, -2653, -2294, -1886, -1479, -1380, -1282, -1087, + -893, -748, -604, -491, -379, -243, -109, -181, +1, -606, -2493, -2283, -2331, + -2481, -2376, -2413, -2452, -2308, -2421, -1350, -278, -124, +30, +88, +145, +127, + +109, +27, -56, -278, -501, -1107, -1714, -2162, -2612, -2532, -2453, -2297, -2397, + -2369, -2341, -2341, -2341, -2341, -1992, -2018, -2045, -2040, -2035, -2241, -1936, -1695, + -1966, -2201, -2436, -2639, -2842, -2545, -2248, -1823, -1398, -1282, -1166, -986, -806, + -686, -566, -510, -454, -271, -88, -289, +22, -1239, -2500, -2257, -2526, -388, + -2346, -2383, -2421, -2358, -2296, -2490, -2684, -2342, -2001, -1627, -1254, -1176, -1099, + -1501, -1904, -2266, -2628, -2510, -2393, -2407, -2422, -2404, -2386, -2362, -2338, -2346, + -2354, -2354, -2354, -2354, -1972, -2006, -2040, -2043, -2046, -2194, -1831, -1835, -2097, + -2336, -2576, -2735, -2895, -2564, -2234, -1839, -1445, -1279, -1114, -916, -719, -623, + -528, -528, -529, -425, -323, -59, -53, -2527, -2443, -2517, -2081, +170, -140, + -1312, -2485, -2440, -2395, -2382, -2370, -2400, -2431, -2509, -2589, -2559, -2530, -2500, + -2472, -2429, -2387, -2489, -2335, -2939, -2008, -1331, -2447, -2395, -2343, -2355, -2367, + -2367, -2367, -2367, -1952, -1994, -2037, -2047, -2058, -2148, -1727, -1977, -2228, -2472, + -2716, -2832, -2948, -2584, -2220, -1856, -1492, -1277, -1062, -847, -632, -561, -490, + -547, -604, -581, -558, -343, -1152, -2281, -2386, -2523, -1124, -40, +19, +15, + +10, -1242, -2495, -2531, -2568, -2459, -2350, -2369, -2388, -2407, -2426, -2477, -2528, + -2593, -2659, -2212, -1254, +369, +967, -1026, -2508, -2428, -2348, -2364, -2380, -2380, + -2380, -2380, -1948, -1996, -2044, -2060, -2077, -1957, -1837, -2069, -2303, -2545, -2788, + -2918, -3049, -2873, -2442, -2026, -1611, -1374, -1138, -965, -793, -732, -672, -707, + -743, -847, -953, -2017, -2059, -2441, -2313, -2327, -295, +99, -19, +23, +65, + +26, -13, -629, -1246, -1795, -2345, -2509, -2675, -2540, -2406, -1887, -1368, -467, + +434, +439, +699, +1162, +856, -2695, -2409, -2413, -2417, -2389, -2361, -2361, -2361, + -2361, -1944, -1998, -2052, -2074, -2097, -1767, -1949, -2163, -2378, -2619, -2860, -3005, + -3150, -3163, -2664, -2197, -1730, -1472, -1214, -1084, -954, -904, -854, -868, -882, + -859, -836, -877, -1942, -2091, -2240, -2389, +22, -18, -57, +32, +121, +14, + -93, -9, +76, +149, +221, +166, +110, +143, +175, +239, +304, +379, +455, + +530, +605, +676, +235, -2573, -2310, -2398, -2486, -2414, -2342, -2342, -2342, -2342, + -1940, -2000, -2060, -2072, -2084, -1640, -1964, -2144, -2325, -2532, -2740, -2899, -3059, + -3052, -2790, -2319, -1849, -1569, -1290, -1202, -1115, -1075, -1036, -1028, -1021, -1077, + -1135, -503, -2689, -2395, -2359, -1553, +19, -6, -30, +25, +80, +34, -12, + +37, +86, +124, +162, +137, +111, +137, +163, +237, +312, +393, +475, +525, + +574, +654, -803, -2466, -2339, -2383, -2427, -2375, -2323, -2323, -2323, -2323, -1936, + -2002, -2068, -2070, -2072, -1514, -1980, -2126, -2272, -2446, -2620, -2794, -2968, -2942, + -2916, -2442, -1968, -1667, -1366, -1321, -1276, -1247, -1218, -1189, -1160, -1041, -922, + -1411, -2412, -2189, -2478, -719, +16, +6, -4, +18, +40, +54, +68, +82, + +96, +100, +104, +108, +112, +132, +152, +236, +320, +408, +496, +520, +544, + +632, -1840, -2360, -2368, -2368, -2368, -2336, -2304, -2304, -2304, -2304, -1898, -1921, + -1944, -2111, -1766, -1551, -1848, -1985, -2122, -2318, -2515, -2664, -2813, -3074, -3079, + -2828, -2321, -2024, -1729, -1608, -1489, -1457, -1425, -1393, -1362, -1246, -1131, -1879, + -2372, -2532, -2693, +331, +25, +40, +55, +54, +54, +71, +88, +105, +123, + +151, +180, +208, +237, +83, -70, +48, +167, +248, +329, +346, +363, +733, + -2738, -2577, -2416, -2395, -2374, -2353, -2332, -2332, -2332, -2332, -1860, -1840, -1820, + -2152, -1460, -1588, -1716, -1844, -1972, -2191, -2411, -2535, -2659, -2950, -2730, -2958, + -2674, -2383, -2092, -1897, -1703, -1668, -1633, -1598, -1564, -1452, -1340, -2348, -2333, + -2365, -1885, -157, +34, +74, +115, +91, +68, +88, +109, +129, +150, +203, + +256, +309, +362, +291, +220, +117, +14, +88, +162, +172, +183, -702, -2612, + -2282, -2464, -2422, -2380, -2370, -2360, -2360, -2360, -2360, -2110, -1967, -1824, -1953, + -1314, -1513, -1712, -1815, -1918, -2207, -2242, -2453, -2408, -2602, -2541, -2752, -2707, + -2692, -2679, -2409, -2140, -2054, -1968, -1867, -1766, -1721, -1677, -2369, -2293, -2516, + -948, -53, +75, +92, +110, +95, +82, +105, +129, +152, +177, +222, +268, + +313, +359, +354, +350, +441, +533, +472, +411, +414, +674, -1689, -2518, -2339, + -2416, -2401, -2386, -2387, -2388, -2388, -2388, -2388, -1848, -1838, -1828, -1754, -1168, + -1438, -1708, -1786, -1864, -2225, -2075, -2372, -2158, -2255, -2353, -2546, -2740, -2747, + -2755, -2666, -2578, -2441, -2305, -2136, -1968, -1991, -2015, -2390, -2254, -2669, -13, + +51, +116, +111, +106, +101, +96, +123, +150, +177, +204, +242, +280, +318, + +356, +418, +480, +510, +540, +600, +661, +657, +1166, -2677, -2425, -2396, -2368, + -2380, -2392, -2404, -2416, -2416, -2416, -2416, -1882, -1711, -1796, -1369, -1198, -1419, + -1640, -1749, -1858, -1977, -1842, -2058, -2019, -2113, -2207, -2366, -2525, -2478, -2689, + -2836, -2983, -2759, -2536, -2393, -2250, -2194, -2139, -2357, -2318, -2018, +72, +113, + +157, +150, +145, +139, +134, +159, +186, +212, +239, +273, +308, +342, +377, + +439, +502, +548, +595, +632, +669, +931, +170, -2666, -2430, -2403, -2376, -2385, + -2394, -2403, -2412, -2412, -2412, -2412, -1916, -1840, -2276, -1240, -1228, -1400, -1572, + -1712, -1852, -1731, -1610, -1745, -1881, -1972, -2063, -2186, -2310, -2211, -2625, -2751, + -2877, -2822, -2768, -2650, -2532, -2398, -2265, -2324, -2383, -1369, +156, +177, +198, + +191, +185, +178, +172, +197, +223, +248, +274, +305, +336, +367, +398, +461, + +524, +587, +650, +664, +679, +1206, -827, -2656, -2437, -2410, -2384, -2390, -2396, + -2402, -2408, -2408, -2408, -2408, -1950, -1953, -1956, -1063, -1194, -1317, -1440, -1435, + -1430, -1499, -1314, -1431, -1550, -1638, -1726, -1798, -1871, -1927, -2240, -2409, -2578, + -2597, -2616, -2731, -2846, -2554, -2262, -2259, -2511, -527, +176, +207, +239, +231, + +224, +217, +210, +234, +259, +284, +309, +336, +364, +391, +419, +482, +546, + +609, +673, +744, +816, +936, -2015, -2485, -2187, -2289, -2392, -2395, -2398, -2401, + -2404, -2404, -2404, -2404, -1984, -2066, -1636, -886, -1160, -1234, -1308, -1414, -1520, + -2037, -2042, -1887, -1732, -1817, -1902, -1923, -1944, -1900, -1856, -2068, -2280, -2372, + -2464, -2556, -2648, -2454, -2260, -2194, -2640, +314, +196, +238, +280, +272, +264, + +256, +248, +272, +296, +320, +344, +368, +392, +416, +440, +504, +568, +632, + +696, +825, +954, +923, -2692, -2315, -2450, -2425, -2400, -2400, -2400, -2400, -2400, + -2400, -2400, -2400, -2252, -1953, -1142, -1035, -1441, -1826, -2211, -2244, -2278, -2220, + -1908, -1914, -1922, -2001, -2336, -2095, -2111, -2171, -2231, -2131, -2031, -2143, -2255, + -2303, -2352, -2306, -2260, -2359, -1689, +442, +269, +305, +341, +333, +325, +317, + +309, +329, +349, +369, +389, +415, +441, +468, +494, +536, +579, +669, +760, + +797, +1091, -248, -2610, -2406, -2459, -2431, -2404, -2400, -2396, -2392, -2388, -2388, + -2388, -2388, -2008, -2096, -1673, -1953, -2234, -2162, -2091, -2051, -2012, -2149, -2286, + -2199, -2113, -1930, -2259, -2012, -2278, -2186, -2094, -2194, -2295, -2171, -2047, -2051, + -2056, -2158, -2261, -2524, -739, +570, +343, +372, +402, +394, +386, +378, +370, + +386, +402, +418, +434, +462, +491, +520, +549, +569, +590, +707, +824, +770, + +1228, -1418, -2528, -2498, -2468, -2438, -2408, -2400, -2392, -2384, -2376, -2376, -2376, + -2376, -1988, -2191, -2139, -2150, -2163, -2130, -2098, -2081, -2066, -2140, -2216, -2179, + -2143, -2066, -2245, -2137, -2285, -2233, -2181, -2225, -2270, -2326, -2382, -2166, -1952, + -2250, -2549, -2465, +180, +394, +352, +407, +463, +455, +447, +423, +399, +523, + +391, +547, +447, +493, +540, +572, +603, +633, +665, +792, +920, +1094, +1269, + -2764, -2446, -2429, -2413, -2412, -2412, -2400, -2388, -2376, -2364, -2364, -2364, -2364, + -1968, -2031, -2094, -2093, -2092, -2099, -2106, -2113, -2120, -2133, -2147, -2160, -2174, + -2203, -2233, -2262, -2292, -2280, -2269, -2257, -2246, -2226, -2207, -2283, -2360, -2343, + -2327, -2406, +586, -38, +363, +443, +524, +516, +508, +468, +428, +660, +380, + +676, +460, +525, +591, +624, +658, +699, +741, +878, +1016, +907, +286, -2575, + -2364, -2361, -2358, -2387, -2416, -2400, -2384, -2368, -2352, -2352, -2352, -2352, -2020, + -2071, -2124, -2080, -2037, -2062, -2089, -2115, -2142, -2152, -2164, -2176, -2188, -2211, + -2235, -2259, -2283, -2275, -2267, -2260, -2253, -2249, -2246, -2290, -2336, -2337, -2339, + -1205, -71, -16, +296, +496, +441, +469, +497, +381, +521, +635, +493, +735, + +465, +544, +624, +640, +656, +747, +839, +899, +960, +1115, -1033, -2493, -2418, + -2378, -2339, -2379, -2420, -2408, -2396, -2384, -2372, -2372, -2372, -2372, -2072, -2113, + -2155, -2068, -1982, -2027, -2073, -2118, -2164, -2173, -2183, -2193, -2203, -2220, -2238, + -2256, -2274, -2270, -2267, -2264, -2261, -2273, -2286, -2299, -2312, -2332, -2352, -2052, + -729, +7, +230, +550, +358, +422, +486, +294, +614, +610, +606, +794, +470, + +564, +658, +656, +655, +797, +939, +921, +904, +1324, -2352, -2412, -2472, -2396, + -2320, -2372, -2424, -2416, -2408, -2400, -2392, -2392, -2392, -2392, -1996, -1930, -1865, + -1960, -2055, -2087, -2120, -2153, -2186, -2193, -2201, -2209, -2217, -2229, -2241, -2253, + -2265, -2265, -2266, -2267, -2268, -2280, -2294, -2306, -2320, -2342, -2365, -2707, -2538, + -1491, -188, +172, +275, +327, +379, +287, +451, +505, +559, +773, +475, +551, + +628, +512, +653, +909, +654, +1007, +1104, -739, -2583, -2506, -2430, -2397, -2365, + -2396, -2428, -2424, -2420, -2416, -2412, -2412, -2412, -2412, -1920, -2004, -2088, -2108, + -2128, -2148, -2168, -2188, -2208, -2214, -2220, -2226, -2232, -2238, -2244, -2250, -2256, + -2261, -2266, -2271, -2276, -2289, -2302, -2315, -2328, -2353, -2378, -2339, -2300, -2477, + -1630, -719, +192, +232, +272, +280, +288, +400, +512, +752, +480, +539, +598, + +369, +652, +767, -142, -1211, -2792, -2547, -2302, -2345, -2388, -2399, -2410, -2421, + -2432, -2432, -2432, -2432, -2432, -2432, -2432, -2432, -2024, -2070, -2116, -2130, -2144, + -2164, -2184, -2204, -2224, -2228, -2232, -2236, -2240, -2244, -2248, -2252, -2256, -2262, + -2270, -2276, -2284, -2296, -2310, -2322, -2336, -2319, -2304, -2287, -2272, -2559, -2336, + -1855, -1376, -2264, -1104, -520, +64, +384, +704, +704, +192, -44, -280, -1236, + -1936, -3018, -2564, -2349, -2392, -2390, -2390, -2388, -2388, -2398, -2410, -2420, -2432, + -2432, -2432, -2432, -2432, -2432, -2432, -2432, -2128, -2136, -2144, -2152, -2160, -2180, + -2200, -2220, -2240, -2242, -2244, -2246, -2248, -2250, -2252, -2254, -2256, -2265, -2274, + -2283, -2292, -2305, -2318, -2331, -2344, -2287, -2230, -2237, -2244, -2387, -2530, -2481, + -2432, -2456, -2480, -2600, -2720, -2448, -2176, -1904, -2144, -2419, -2694, -2585, -2476, + -2451, -2426, -2465, -2504, -2491, -2478, -2433, -2388, -2399, -2410, -2421, -2432, -2432, + -2432, -2432, -2432, -2432, -2432, -2432, -2104, -2122, -2140, -2158, -2176, -2196, -2216, + -2236, -2256, -2256, -2256, -2256, -2256, -2256, -2256, -2256, -2256, -2266, -2278, -2288, + -2300, -2312, -2326, -2338, -2352, -2317, -2284, -2281, -2280, -2357, -2436, -2417, -2400, + -2408, -2416, -2360, -2304, -2480, -864, -1648, -1408, -1225, -2580, -2509, -2440, -2427, + -2416, -2435, -2456, -2446, -2438, -2412, -2388, -2398, -2410, -2420, -2432, -2432, -2432, + -2432, -2432, -2432, -2432, -2432, -2080, -2108, -2136, -2164, -2192, -2212, -2232, -2252, + -2272, -2270, -2268, -2266, -2264, -2262, -2260, -2258, -2256, -2269, -2282, -2295, -2308, + -2321, -2334, -2347, -2360, -2349, -2338, -2327, -2316, -2329, -2342, -2355, -2368, -2360, + -2352, -2376, -2400, -2256, -2624, -1392, -1696, -2593, -2466, -2435, -2404, -2405, -2406, + -2407, -2408, -2403, -2398, -2393, -2388, -2399, -2410, -2421, -2432, -2432, -2432, -2432, + -2432, -2432, -2432, -2432, -2080, -2108, -2136, -2164, -2192, -2212, -2232, -2252, -2272, + -2270, -2268, -2266, -2264, -2262, -2260, -2258, -2256, -2268, -2282, -2294, -2308, -2320, + -2334, -2346, -2360, -2348, -2338, -2326, -2316, -2328, -2342, -2354, -2368, -2360, -2352, + -2360, -2368, -2352, -2592, -2192, -2560, -2768, -2466, -2434, -2404, -2404, -2406, -2406, + -2408, -2402, -2398, -2392, -2388, -2398, -2410, -2420, -2432, -2432, -2432, -2432, -2432, + -2432, -2432, -2432, -2080, -2108, -2136, -2164, -2192, -2212, -2232, -2252, -2272, -2270, + -2268, -2266, -2264, -2262, -2260, -2258, -2256, -2269, -2282, -2295, -2308, -2321, -2334, + -2347, -2360, -2349, -2338, -2327, -2316, -2329, -2342, -2355, -2368, -2360, -2352, -2344, + -2336, -2448, -2560, -2480, -2400, -2433, -2466, -2435, -2404, -2405, -2406, -2407, -2408, + -2403, -2398, -2393, -2388, -2399, -2410, -2421, -2432, -2432, -2432, -2432, -2432, -2432, + -2432, -2432, -2080, -2108, -2136, -2164, -2192, -2212, -2232, -2252, -2272, -2270, -2268, + -2266, -2264, -2262, -2260, -2258, -2256, -2268, -2282, -2294, -2308, -2320, -2334, -2346, + -2360, -2348, -2338, -2326, -2316, -2328, -2342, -2354, -2368, -2360, -2352, -2344, -2336, + -2448, -2560, -2480, -2400, -2432, -2466, -2434, -2404, -2404, -2406, -2406, -2408, -2402, + -2398, -2392, -2388, -2398, -2410, -2420, -2432, -2432, -2432, -2432, -2432, -2432, -2432, + -2432 +}; + +/** + * 64x64 XRGB Image + */ + +static const UINT32 TEST_XRGB_IMAGE[4096] = { + 0xFF229cdf, 0xFF249de0, 0xFF259fe2, 0xFF2ca5e8, 0xFF229cdf, 0xFF229ce0, 0xFF239de0, 0xFF229ce0, + 0xFF229cdf, 0xFF229cdf, 0xFF239ce0, 0xFF249ce0, 0xFF249ce0, 0xFF219ce3, 0xFF1e9ce6, 0xFF209ae2, + 0xFF2299dd, 0xFF2199de, 0xFF209adf, 0xFF209ae0, 0xFF1f9be0, 0xFF1e9ae0, 0xFF1d99e0, 0xFF1c98e0, + 0xFF1b97df, 0xFF1e96dc, 0xFF2194d9, 0xFF1f93dd, 0xFF1d93e0, 0xFF1b94dc, 0xFF1895d8, 0xFF1c92db, + 0xFF208fde, 0xFF1b91de, 0xFF1693df, 0xFF1793df, 0xFF1992df, 0xFF1891df, 0xFF178fdf, 0xFF178edf, + 0xFF168dde, 0xFF158cdd, 0xFF148cdc, 0xFF128cda, 0xFF118cd9, 0xFF118bd9, 0xFF128ada, 0xFF1289da, + 0xFF1288db, 0xFF1187da, 0xFF1186da, 0xFF1085da, 0xFF0f85d9, 0xFF0f84d9, 0xFF0e83d9, 0xFF0d82d8, + 0xFF0d82d8, 0xFF0d81d8, 0xFF0d80d7, 0xFF0d7fd7, 0xFF0d7ed6, 0xFF0d7ed6, 0xFF0d7ed6, 0xFF0d7ed6, + 0xFF259fe1, 0xFF27a1e2, 0xFF29a2e3, 0xFF2ba4e6, 0xFF249fe1, 0xFF249fe1, 0xFF249fe1, 0xFF249ee1, + 0xFF239ee1, 0xFF249ee1, 0xFF249ee1, 0xFF259de1, 0xFF259de2, 0xFF249de2, 0xFF229de2, 0xFF229ce1, + 0xFF229bdf, 0xFF219ce0, 0xFF209ce1, 0xFF209ce2, 0xFF209ce2, 0xFF209ae0, 0xFF2199de, 0xFF1f99df, + 0xFF1d98e0, 0xFF1e97e0, 0xFF1f97e0, 0xFF1d96df, 0xFF1c95de, 0xFF1c94e0, 0xFF1c94e1, 0xFF1d93e1, + 0xFF1d92e0, 0xFF1b93de, 0xFF1a94dc, 0xFF1a93de, 0xFF1a93e0, 0xFF1992e0, 0xFF1891df, 0xFF188fdf, + 0xFF178edf, 0xFF168ede, 0xFF158edd, 0xFF148ddc, 0xFF138ddb, 0xFF138cdb, 0xFF138bdb, 0xFF128adb, + 0xFF1289db, 0xFF1288db, 0xFF1187db, 0xFF1186db, 0xFF1085db, 0xFF0f84da, 0xFF0e83d9, 0xFF0e83d9, + 0xFF0e83d9, 0xFF0e82d9, 0xFF0e81d8, 0xFF0e80d8, 0xFF0d7fd7, 0xFF0d7fd7, 0xFF0d7fd7, 0xFF0d7fd7, + 0xFF27a3e3, 0xFF2aa4e3, 0xFF2ea6e3, 0xFF2aa4e3, 0xFF26a2e3, 0xFF26a1e3, 0xFF25a1e3, 0xFF25a0e3, + 0xFF25a0e3, 0xFF25a0e3, 0xFF259fe3, 0xFF269fe3, 0xFF269ee4, 0xFF279ee1, 0xFF279edf, 0xFF259ee0, + 0xFF239ee1, 0xFF219ee2, 0xFF209ee4, 0xFF209de4, 0xFF219de3, 0xFF229be0, 0xFF2499dc, 0xFF2299de, + 0xFF1f98e0, 0xFF1d99e4, 0xFF1b9ae7, 0xFF1c98e2, 0xFF1c96dc, 0xFF1e94e3, 0xFF2092ea, 0xFF1d94e6, + 0xFF1a96e2, 0xFF1c96de, 0xFF1d95da, 0xFF1c94de, 0xFF1b94e1, 0xFF1a93e0, 0xFF1a92e0, 0xFF1991e0, + 0xFF1890e0, 0xFF1790df, 0xFF178fde, 0xFF168fde, 0xFF158edd, 0xFF148ddd, 0xFF138cdc, 0xFF138bdc, + 0xFF128adc, 0xFF1289dc, 0xFF1188dc, 0xFF1187dd, 0xFF1086dd, 0xFF0f85db, 0xFF0e83d9, 0xFF0e84da, + 0xFF0f84da, 0xFF0e83da, 0xFF0e82d9, 0xFF0e81d9, 0xFF0e80d8, 0xFF0e80d8, 0xFF0e80d8, 0xFF0e80d8, + 0xFF2aa7e5, 0xFF2da7e4, 0xFF31a8e3, 0xFF2ca6e3, 0xFF27a4e4, 0xFF27a3e4, 0xFF27a3e4, 0xFF27a3e4, + 0xFF26a2e4, 0xFF26a2e4, 0xFF27a1e5, 0xFF27a0e5, 0xFF27a0e6, 0xFF26a0e5, 0xFF25a0e4, 0xFF259fe4, + 0xFF259ee3, 0xFF239ee5, 0xFF229fe6, 0xFF229fe5, 0xFF229fe4, 0xFF13a5e6, 0xFF1b9fe8, 0xFF16a0e8, + 0xFF11a0e7, 0xFF129fef, 0xFF139ef7, 0xFF1b99ec, 0xFF179ae2, 0xFF149ce4, 0xFF1d98e5, 0xFF1c97e6, + 0xFF1b96e7, 0xFF1c98dc, 0xFF1d97df, 0xFF1c96e1, 0xFF1c94e2, 0xFF1b94e1, 0xFF1b93e1, 0xFF1a93e0, + 0xFF1a92e0, 0xFF1991e0, 0xFF1890e0, 0xFF1790df, 0xFF168fdf, 0xFF158ede, 0xFF158dde, 0xFF148cdd, + 0xFF138bdc, 0xFF128add, 0xFF1289dd, 0xFF1188de, 0xFF1187de, 0xFF0f85dc, 0xFF0d83da, 0xFF0f85db, + 0xFF1086db, 0xFF0f84db, 0xFF0f83da, 0xFF0e82da, 0xFF0e81da, 0xFF0e81da, 0xFF0e81da, 0xFF0e81da, + 0xFF2caae7, 0xFF30aae5, 0xFF34abe3, 0xFF2ea8e4, 0xFF29a6e5, 0xFF28a6e5, 0xFF28a5e5, 0xFF28a5e5, + 0xFF28a5e6, 0xFF28a4e6, 0xFF28a3e7, 0xFF28a2e7, 0xFF28a1e8, 0xFF25a2e9, 0xFF23a3ea, 0xFF25a0e8, + 0xFF279ee6, 0xFF259fe7, 0xFF23a0e9, 0xFF18a4f5, 0xFF0ea7ff, 0xFF1ba6de, 0xFF558ebb, 0xFF6f839c, + 0xFF89797e, 0xFF8d797c, 0xFF917979, 0xFF7f7b94, 0xFF5687af, 0xFF229bd6, 0xFF04a4fd, 0xFF109df4, + 0xFF1c97eb, 0xFF1c9ada, 0xFF1c98e4, 0xFF1c97e3, 0xFF1d95e2, 0xFF1c95e2, 0xFF1c94e2, 0xFF1c94e1, + 0xFF1b94e1, 0xFF1a93e1, 0xFF1a92e1, 0xFF1991e1, 0xFF1890e1, 0xFF178fe0, 0xFF158edf, 0xFF148dde, + 0xFF138cdd, 0xFF128bde, 0xFF128adf, 0xFF1289df, 0xFF1188e0, 0xFF0f85dd, 0xFF0d83da, 0xFF0f85db, + 0xFF1187dd, 0xFF1086dc, 0xFF0f84dc, 0xFF0e83db, 0xFF0e81db, 0xFF0e81db, 0xFF0e81db, 0xFF0e81db, + 0xFF30abe5, 0xFF36afe8, 0xFF34abe4, 0xFF2faae5, 0xFF2ba8e6, 0xFF36aee8, 0xFF26a6e8, 0xFF29a7e7, + 0xFF2ca8e7, 0xFF2da7e6, 0xFF2fa5e5, 0xFF2ca5e7, 0xFF29a4e9, 0xFF2ba5e5, 0xFF2ca5e2, 0xFF10aaef, + 0xFF13adf6, 0xFF23a3f8, 0xFF6091a5, 0xFFa6755d, 0xFFec5915, 0xFFff490c, 0xFFfa5504, 0xFFff590f, + 0xFFff5d1b, 0xFFff6116, 0xFFfa6412, 0xFFff550f, 0xFFff4b0d, 0xFFfb4918, 0xFFf54823, 0xFF8e737e, + 0xFF269eda, 0xFF06a2ff, 0xFF1d97e2, 0xFF1799ea, 0xFF1c97e4, 0xFF1a98e4, 0xFF1898e4, 0xFF1a96e3, + 0xFF1b95e3, 0xFF1a94e2, 0xFF1a93e0, 0xFF1992e1, 0xFF1891e2, 0xFF1790e1, 0xFF168fe0, 0xFF158fdf, + 0xFF138ede, 0xFF138ddf, 0xFF138ce0, 0xFF128be0, 0xFF1189e0, 0xFF1087de, 0xFF0f85db, 0xFF138ae0, + 0xFF0f87dc, 0xFF0f86dc, 0xFF0f85dc, 0xFF0f84dc, 0xFF0e83db, 0xFF0e83db, 0xFF0e83db, 0xFF0e83db, + 0xFF34abe2, 0xFF3cb4ec, 0xFF34ace5, 0xFF31abe6, 0xFF2daae8, 0xFF44b6eb, 0xFF24a7ea, 0xFF29aaea, + 0xFF2face9, 0xFF32a9e6, 0xFF35a7e3, 0xFF30a7e6, 0xFF2ba8ea, 0xFF25aaf0, 0xFF20adf6, 0xFF4d8ba7, + 0xFFb8674c, 0xFFff5510, 0xFFf7650c, 0xFFf86313, 0xFFfa611b, 0xFFf0671f, 0xFFfc6222, 0xFFfb6926, + 0xFFf96f29, 0xFFf67122, 0xFFf3721b, 0xFFf26b20, 0xFFf16424, 0xFFff5622, 0xFFff531f, 0xFFff4b17, + 0xFFff440e, 0xFFb1615b, 0xFF1f95e0, 0xFF129bf0, 0xFF1c9ae5, 0xFF189ae6, 0xFF159be7, 0xFF1898e6, + 0xFF1b95e5, 0xFF1b95e2, 0xFF1995e0, 0xFF1994e1, 0xFF1892e2, 0xFF1792e1, 0xFF1691e0, 0xFF1590df, + 0xFF148fdf, 0xFF148fe0, 0xFF148fe1, 0xFF128de1, 0xFF108be0, 0xFF1189de, 0xFF1186dd, 0xFF178fe4, + 0xFF0e87db, 0xFF0e87dc, 0xFF0f87dd, 0xFF0f85dc, 0xFF0e84dc, 0xFF0e84dc, 0xFF0e84dc, 0xFF0e84dc, + 0xFF36b1eb, 0xFF36b4f0, 0xFF2eafed, 0xFF2caeec, 0xFF2aadec, 0xFF41b4ef, 0xFF29abe9, 0xFF2cabe8, + 0xFF2fabe7, 0xFF31abe6, 0xFF32aae6, 0xFF2faae7, 0xFF2ca9e8, 0xFF25a7eb, 0xFF946a5f, 0xFFff3e06, + 0xFFf95618, 0xFFe27312, 0xFFf87329, 0xFFf77427, 0xFFf77626, 0xFFf27628, 0xFFf8712b, 0xFFf9772e, + 0xFFf97e30, 0xFFf77f2e, 0xFFf5812b, 0xFFf57b2c, 0xFFf5752d, 0xFFfd6a2b, 0xFFfb652a, 0xFFf65e2c, + 0xFFf1572e, 0xFFff4810, 0xFFff460f, 0xFF817680, 0xFF02a7f1, 0xFF2496ea, 0xFF199be4, 0xFF1b98e4, + 0xFF1d96e5, 0xFF1b96e2, 0xFF1a96e0, 0xFF1995e1, 0xFF1794e3, 0xFF1793e2, 0xFF1692e1, 0xFF1691e0, + 0xFF1590df, 0xFF1591e1, 0xFF1591e3, 0xFF138fe1, 0xFF108ce0, 0xFF128be0, 0xFF158ae0, 0xFF168de2, + 0xFF0f89dd, 0xFF0f88dd, 0xFF0f88dd, 0xFF0f86dd, 0xFF0f85dc, 0xFF0f85dc, 0xFF0f85dc, 0xFF0f85dc, + 0xFF5fc1e7, 0xFF57bee8, 0xFF4fbbe9, 0xFF4ebae6, 0xFF4ebae3, 0xFF51b6ee, 0xFF2eaee8, 0xFF2eade6, + 0xFF2fabe5, 0xFF2face7, 0xFF2eade9, 0xFF2eace7, 0xFF2daae5, 0xFF15b2ff, 0xFFec4310, 0xFFf15016, + 0xFFf75d1c, 0xFFf87123, 0xFFf9862a, 0xFFf6882d, 0xFFf48b31, 0xFFf48532, 0xFFf47f33, 0xFFf78535, + 0xFFfa8c37, 0xFFf88e39, 0xFFf7903a, 0xFFf88b38, 0xFFf98635, 0xFFf87e35, 0xFFf77635, 0xFFf76d34, + 0xFFf76532, 0xFFf85e31, 0xFFf95730, 0xFFff5125, 0xFFf65237, 0xFF03a5fd, 0xFF1e9be1, 0xFF1e98e3, + 0xFF1f96e5, 0xFF1c97e2, 0xFF1a97df, 0xFF1896e1, 0xFF1795e4, 0xFF1794e3, 0xFF1793e2, 0xFF1692e1, + 0xFF1692e0, 0xFF1693e2, 0xFF1794e4, 0xFF1391e2, 0xFF0f8ee0, 0xFF148ee1, 0xFF198ee3, 0xFF148ce1, + 0xFF0f8bde, 0xFF0f8ade, 0xFF0f89de, 0xFF0f88dd, 0xFF0f86dd, 0xFF0f86dd, 0xFF0f86dd, 0xFF0f86dd, + 0xFF3cb6ee, 0xFF36b4ef, 0xFF30b2f0, 0xFF30b1ee, 0xFF2fb1ec, 0xFF38b0ef, 0xFF2eaee9, 0xFF2faee8, + 0xFF31ade6, 0xFF2fafe8, 0xFF2eb1ea, 0xFF31adec, 0xFF29afee, 0xFF30aac8, 0xFFff3d05, 0xFFfa501a, + 0xFFf96021, 0xFFf87428, 0xFFf7882f, 0xFFfa9638, 0xFFf59b38, 0xFFf5973b, 0xFFf6923e, 0xFFf89440, + 0xFFfa9742, 0xFFfa9a44, 0xFFfa9d46, 0xFFf99845, 0xFFf89444, 0xFFf98d43, 0xFFfa8641, 0xFFf97d3f, + 0xFFf9743d, 0xFFf77039, 0xFFf56d35, 0xFFff6122, 0xFFbf6c63, 0xFF129eef, 0xFF229ae8, 0xFF1c99ed, + 0xFF179ce4, 0xFF1498f0, 0xFF1b94e1, 0xFF1a96e2, 0xFF1998e3, 0xFF1897e4, 0xFF1896e5, 0xFF1895e4, + 0xFF1993e2, 0xFF1792e1, 0xFF1590df, 0xFF1692e2, 0xFF1793e5, 0xFF1490e4, 0xFF128ee2, 0xFF118de3, + 0xFF108de3, 0xFF118bde, 0xFF1289d9, 0xFF0f88e2, 0xFF0c89dd, 0xFF1085e0, 0xFF0987e4, 0xFF0987e4, + 0xFF40b5e9, 0xFF3bb4e9, 0xFF37b2ea, 0xFF37b2e9, 0xFF38b1e8, 0xFF33b0ea, 0xFF2eaeeb, 0xFF30afe9, + 0xFF33afe8, 0xFF30b2ea, 0xFF2eb5ec, 0xFF34aff2, 0xFF25b4f7, 0xFF8d7f86, 0xFFf64f00, 0xFFed5c1e, + 0xFFfa6326, 0xFFf7762d, 0xFFf58a35, 0xFFfea242, 0xFFf7ab3f, 0xFFf7a843, 0xFFf7a548, 0xFFf9a34a, + 0xFFfaa24c, 0xFFfba64f, 0xFFfcaa52, 0xFFf9a652, 0xFFf7a252, 0xFFfa9c50, 0xFFfd974e, 0xFFfc8d4b, + 0xFFfb8348, 0xFFf68341, 0xFFf1823a, 0xFFf5732c, 0xFF718cac, 0xFF179af0, 0xFF2599ef, 0xFF2697e9, + 0xFF269bc6, 0xFF1696f1, 0xFF1d91e3, 0xFF1c96e3, 0xFF1b9be3, 0xFF1a99e6, 0xFF1998e9, 0xFF1b97e7, + 0xFF1c95e5, 0xFF1891df, 0xFF138dda, 0xFF1992e2, 0xFF1e98ea, 0xFF1592e6, 0xFF0b8de2, 0xFF0e8ee5, + 0xFF108fe9, 0xFF128cdf, 0xFF1489d4, 0xFF0e88e6, 0xFF088cdc, 0xFF1184e4, 0xFF0488ec, 0xFF0488ec, + 0xFF3eb6ea, 0xFF3bb5eb, 0xFF38b4eb, 0xFF38b4eb, 0xFF38b3eb, 0xFF35b2eb, 0xFF33b1ec, 0xFF34b1eb, + 0xFF35b1ea, 0xFF32b3e9, 0xFF30b5e9, 0xFF34b0f0, 0xFF23b6f8, 0xFFc56044, 0xFFf9540c, 0xFFf26322, + 0xFFf77029, 0xFFf77d2f, 0xFFf78b35, 0xFFfba142, 0xFFf6b046, 0xFFfbb44f, 0xFFf7b051, 0xFFf9af54, + 0xFFfbad56, 0xFFfcb25a, 0xFFfeb75d, 0xFFfab35f, 0xFFf6b061, 0xFFfaac5d, 0xFFfda95a, 0xFFfb9f55, + 0xFFf99551, 0xFFf7914b, 0xFFf68d45, 0xFFff7e23, 0xFF1ba5f0, 0xFF129ef4, 0xFF2896f1, 0xFF239fb1, + 0xFF6c9600, 0xFF3c9c82, 0xFF179ef8, 0xFF169cf4, 0xFF149de3, 0xFF169ae5, 0xFF1897e7, 0xFF1995e6, + 0xFF1a93e5, 0xFF1993e3, 0xFF1793e0, 0xFF1c98e6, 0xFF1a95e5, 0xFF1692e5, 0xFF138fe5, 0xFF138ceb, + 0xFF138be3, 0xFF0087e4, 0xFF007cf5, 0xFF1a86d3, 0xFF0d8cf1, 0xFF008fe2, 0xFF0d85ea, 0xFF0886f1, + 0xFF3cb7ec, 0xFF3bb7ed, 0xFF3ab6ed, 0xFF39b6ed, 0xFF38b5ed, 0xFF37b5ed, 0xFF37b4ed, 0xFF37b3ed, + 0xFF36b3ec, 0xFF34b4e9, 0xFF31b5e5, 0xFF35b1ef, 0xFF21b8fa, 0xFFfd4203, 0xFFfc581e, 0xFFf86a26, + 0xFFf47c2d, 0xFFf78431, 0xFFf98c36, 0xFFf8a041, 0xFFf6b54d, 0xFFfec05b, 0xFFf6bc5a, 0xFFf8ba5d, + 0xFFfbb861, 0xFFfdbe65, 0xFFffc469, 0xFFfbc16c, 0xFFf5bd70, 0xFFfabc6b, 0xFFfebb66, 0xFFfab160, + 0xFFf6a75a, 0xFFf89f55, 0xFFfa984f, 0xFFdf956f, 0xFF08a6fc, 0xFF259ddb, 0xFF159ff3, 0xFF4aa172, + 0xFF69a90d, 0xFF62a406, 0xFF5a981b, 0xFF34969b, 0xFF0e99ff, 0xFF1297f2, 0xFF1695e4, 0xFF1793e5, + 0xFF1892e5, 0xFF1995e6, 0xFF1a98e7, 0xFF209deb, 0xFF1593df, 0xFF1892e4, 0xFF1a91e9, 0xFF2095eb, + 0xFF259dd1, 0xFFd0f772, 0xFFc1f396, 0xFF0083f1, 0xFF1782a0, 0xFF3c7e2f, 0xFF1787cc, 0xFF0b8ada, + 0xFF3db9ed, 0xFF3cb8ed, 0xFF3bb8ed, 0xFF3ab7ed, 0xFF39b7ed, 0xFF39b7ed, 0xFF39b6ed, 0xFF3ab6ed, + 0xFF3ab6ed, 0xFF37b4ed, 0xFF34b2ec, 0xFF35abf3, 0xFF6e96b3, 0xFFff4601, 0xFFf86520, 0xFFf67329, + 0xFFf58131, 0xFFf78b37, 0xFFf9953e, 0xFFf8a649, 0xFFf8b854, 0xFFfcc260, 0xFFf8c465, 0xFFf9c36a, + 0xFFfac26e, 0xFFfac773, 0xFFfacb77, 0xFFfbcb7b, 0xFFfccb7e, 0xFFfac87b, 0xFFf8c578, 0xFFf9bc72, + 0xFFfbb46d, 0xFFf6b069, 0xFFfeaa57, 0xFF94a0a5, 0xFF13a1f3, 0xFF219df0, 0xFF199eff, 0xFF71c124, + 0xFF79b826, 0xFF72b21e, 0xFF6aaa24, 0xFF67a125, 0xFF649a19, 0xFF419d72, 0xFF1f9fcb, 0xFF1994ff, + 0xFF1399f1, 0xFF199cf4, 0xFF1ea0f8, 0xFF1b9cff, 0xFF1193f6, 0xFF1293f1, 0xFF1393ec, 0xFF0083ff, + 0xFF72cca0, 0xFFcbf982, 0xFFd0ffac, 0xFF79a046, 0xFF337700, 0xFF3a7c03, 0xFF0d8de2, 0xFF0d8edb, + 0xFF3fbbee, 0xFF3ebaed, 0xFF3db9ed, 0xFF3cb9ed, 0xFF3bb8ed, 0xFF3bb8ed, 0xFF3cb9ee, 0xFF3cb9ee, + 0xFF3db9ef, 0xFF3ab4f1, 0xFF37aff3, 0xFF32b3fe, 0xFFb48f7d, 0xFFff5907, 0xFFf37122, 0xFFf57c2b, + 0xFFf68735, 0xFFf7923d, 0xFFf89d45, 0xFFf9ac50, 0xFFf9bb5a, 0xFFf9c465, 0xFFfacd71, 0xFFfacd76, + 0xFFfacd7b, 0xFFf7cf80, 0xFFf4d286, 0xFFfcd689, 0xFFffd98c, 0xFFfbd48b, 0xFFf3cf8a, 0xFFf9c885, + 0xFFffc17f, 0xFFf5c27d, 0xFFffbc5e, 0xFF48abdc, 0xFF1e9deb, 0xFF1ea2e8, 0xFF1da8e5, 0xFF99d31c, + 0xFF8acb22, 0xFF82c427, 0xFF7abc2c, 0xFF75b429, 0xFF70ad25, 0xFF6dab17, 0xFF6ba908, 0xFF5ea912, + 0xFF519f54, 0xFF489b6d, 0xFF3e9887, 0xFF3b9592, 0xFF389880, 0xFF449663, 0xFF509446, 0xFF83b43c, + 0xFF4f851b, 0xFFafe187, 0xFF9fcc83, 0xFF368011, 0xFF43821c, 0xFF32853c, 0xFF0492f9, 0xFF1092dd, + 0xFF40bcee, 0xFF3fbcee, 0xFF3ebbee, 0xFF3dbaed, 0xFF3cbaed, 0xFF3cb9ed, 0xFF3cb9ec, 0xFF3cb9ec, + 0xFF3cb8ec, 0xFF3fb4f0, 0xFF43aff5, 0xFF0ebbe9, 0xFFffb897, 0xFFf7814d, 0xFFf57623, 0xFFf6812e, + 0xFFf88c39, 0xFFf89943, 0xFFf8a64d, 0xFFf8b257, 0xFFf9bd60, 0xFFfac96d, 0xFFfbd47b, 0xFFfad681, + 0xFFfad788, 0xFFfbd98e, 0xFFfbda93, 0xFFfae5a1, 0xFFfed692, 0xFFfadea0, 0xFFf9db98, 0xFFfad694, + 0xFFfbd090, 0xFFffd285, 0xFFffc778, 0xFF009afd, 0xFF26a8f2, 0xFF20a4f8, 0xFF53bea5, 0xFFa4da31, + 0xFF9dd638, 0xFF97d03a, 0xFF91ca3d, 0xFF8bc539, 0xFF85c035, 0xFF7dbe31, 0xFF74bc2d, 0xFF76b81c, + 0xFF77b027, 0xFF72ab25, 0xFF6da724, 0xFF6ba328, 0xFF68a31f, 0xFF58951a, 0xFF78b745, 0xFFbbf181, + 0xFF73ad4c, 0xFF417c15, 0xFF508b1e, 0xFF43861c, 0xFF498614, 0xFF17868b, 0xFF0b90f6, 0xFF168ee8, + 0xFF42beef, 0xFF41bdee, 0xFF40bcee, 0xFF3fbced, 0xFF3ebbed, 0xFF3dbaec, 0xFF3db9eb, 0xFF3cb8ea, + 0xFF3bb7e9, 0xFF39b9f0, 0xFF37bbf7, 0xFF50b5dc, 0xFFff9744, 0xFFfec49d, 0xFFf87a24, 0xFFf88530, + 0xFFf9913d, 0xFFf8a049, 0xFFf7af55, 0xFFf8b85d, 0xFFf9c065, 0xFFface75, 0xFFfcdb85, 0xFFfbde8d, + 0xFFfae195, 0xFFfee29b, 0xFFffe2a0, 0xFFfbe9a4, 0xFFffbe6b, 0xFFfdde9f, 0xFFffe8a6, 0xFFfbe3a3, + 0xFFf8dea0, 0xFFfdd899, 0xFFb6bdab, 0xFF119ff1, 0xFF1ea4e9, 0xFF1a9fff, 0xFF89d465, 0xFFb0e245, + 0xFFb0e04e, 0xFFacdc4e, 0xFFa7d94e, 0xFFa1d649, 0xFF9ad345, 0xFF97ce3d, 0xFF94c935, 0xFF8dc534, + 0xFF86c133, 0xFF7bbc32, 0xFF6fb731, 0xFF6db330, 0xFF6cae2e, 0xFF7eba3f, 0xFF70a531, 0xFF7bb54f, + 0xFF579a20, 0xFF5c9f2b, 0xFF519425, 0xFF80b965, 0xFF609a1d, 0xFF0390e3, 0xFF118ef2, 0xFF1c89f2, + 0xFF44c0ef, 0xFF43bfef, 0xFF42beee, 0xFF40bdee, 0xFF3fbcee, 0xFF3fbbed, 0xFF40baeb, 0xFF3eb9ed, + 0xFF3cb9ee, 0xFF37b9eb, 0xFF27bcf7, 0xFF949c8f, 0xFFfb9637, 0xFFf9bc7c, 0xFFf9b585, 0xFFf7994a, + 0xFFf69b43, 0xFFf6a64e, 0xFFf7b259, 0xFFf8bc66, 0xFFfac672, 0xFFfad380, 0xFFfae08d, 0xFFf9e698, + 0xFFf9eba2, 0xFFfeeaa6, 0xFFffeaab, 0xFFfcefa9, 0xFFfaba62, 0xFFfbdc99, 0xFFfff4b9, 0xFFfbecb2, + 0xFFf7e6ab, 0xFFffe5a3, 0xFF64b1d1, 0xFF199ff0, 0xFF269fe9, 0xFF0499f2, 0xFFe3f051, 0xFFd5ef58, + 0xFFc0e364, 0xFFbde165, 0xFFbae065, 0xFFb5de5d, 0xFFb0dc56, 0xFFaad74e, 0xFFa3d346, 0xFF9bd043, + 0xFF93cd3f, 0xFF8cc93e, 0xFF84c63c, 0xFF81c139, 0xFF7dbc36, 0xFF8bc746, 0xFF89c245, 0xFF63a02c, + 0xFF65aa2c, 0xFF5ea42d, 0xFF509626, 0xFFa4cf98, 0xFFd9eadd, 0xFFb9ddff, 0xFF389ef4, 0xFF008fd4, + 0xFF46c1ef, 0xFF44c0ef, 0xFF43bfef, 0xFF42beef, 0xFF40bdef, 0xFF42bced, 0xFF43baec, 0xFF40baf0, + 0xFF3dbaf4, 0xFF35b8e7, 0xFF17bdf7, 0xFFd97f50, 0xFFf79147, 0xFFf7a554, 0xFFffdbba, 0xFFf8a24d, + 0xFFf3a549, 0xFFf5ad53, 0xFFf7b55e, 0xFFf9c16f, 0xFFfbcc7f, 0xFFf9d88a, 0xFFf8e595, 0xFFf8eda2, + 0xFFf8f5ae, 0xFFfff3b2, 0xFFfff2b6, 0xFFfef5ae, 0xFFf4b659, 0xFFf9db93, 0xFFfeffcd, 0xFFfbf6c1, + 0xFFf7edb6, 0xFFfff2ac, 0xFF13a4f7, 0xFF16a5f0, 0xFF18a5e8, 0xFF56b4cd, 0xFFf1f271, 0xFFd5ef84, + 0xFFcfe67b, 0xFFcde77c, 0xFFcbe77c, 0xFFc9e672, 0xFFc7e567, 0xFFbce15f, 0xFFb1dd57, 0xFFa9dc51, + 0xFFa0da4b, 0xFF9dd749, 0xFF9ad447, 0xFF94cf43, 0xFF8fcb3f, 0xFF88c43c, 0xFF82be39, 0xFF72b430, + 0xFF63a928, 0xFF59a028, 0xFF4e9827, 0xFFa0c479, 0xFFfffbf7, 0xFF7fd3f5, 0xFF038fe2, 0xFF0e89e2, + 0xFF48c3ef, 0xFF46c2ef, 0xFF45c1f0, 0xFF43c0f0, 0xFF42bff0, 0xFF42beee, 0xFF43bdec, 0xFF41bcef, + 0xFF3fbcf2, 0xFF2fc0fe, 0xFF36bdfc, 0xFFf54c00, 0xFFff8a52, 0xFFfaa65e, 0xFFfdc48e, 0xFFfbc185, + 0xFFf5ae50, 0xFFf7b65e, 0xFFf9be6c, 0xFFfac978, 0xFFfbd485, 0xFFfede98, 0xFFffe8aa, 0xFFfdeeae, + 0xFFf9f5b2, 0xFFfcf6ba, 0xFFfff7c2, 0xFFfcf0b2, 0xFFf7cc6e, 0xFFfbde91, 0xFFfdfcca, 0xFFfffbd1, + 0xFFfffdc8, 0xFFcae4c8, 0xFF16a1f2, 0xFF1da4ef, 0xFF12a1f1, 0xFF9fd5b9, 0xFFeaf28c, 0xFFdcf095, + 0xFFd9eb90, 0xFFd9ec93, 0xFFd9ec95, 0xFFd6eb8c, 0xFFd4ea83, 0xFFc9e779, 0xFFbfe36f, 0xFFb8e368, + 0xFFb1e262, 0xFFafe05e, 0xFFaddf5a, 0xFFa3d952, 0xFF99d449, 0xFF8ecb41, 0xFF84c33a, 0xFF75b833, + 0xFF66ac2c, 0xFF5da329, 0xFF559927, 0xFF4b9421, 0xFF2499b9, 0xFF1593fe, 0xFF0993d8, 0xFF0f90d8, + 0xFF4ac5ef, 0xFF48c4f0, 0xFF46c2f0, 0xFF45c1f1, 0xFF43c0f1, 0xFF43bfef, 0xFF43bfed, 0xFF42beee, + 0xFF41bdf0, 0xFF38bbf0, 0xFF72a1b8, 0xFFff5d1e, 0xFFf97931, 0xFFf5a151, 0xFFf9ad61, 0xFFfee0bd, + 0xFFf8b758, 0xFFfabf69, 0xFFfcc87a, 0xFFfcd282, 0xFFfcdc8b, 0xFFfbde8f, 0xFFfbe193, 0xFFfbeba4, + 0xFFfbf5b5, 0xFFfaf8c2, 0xFFf9fcce, 0xFFf9ecb7, 0xFFfae183, 0xFFfee290, 0xFFfbfac8, 0xFFfdf8d8, + 0xFFfffccb, 0xFF8bcedc, 0xFF189fee, 0xFF25a3ee, 0xFF0b9dfb, 0xFFe8f6a5, 0xFFe4f1a6, 0xFFe4f0a6, + 0xFFe4efa6, 0xFFe5f1aa, 0xFFe6f2ad, 0xFFe3f1a6, 0xFFe0ef9e, 0xFFd7ec93, 0xFFcde987, 0xFFc8ea80, + 0xFFc2eb78, 0xFFc1ea73, 0xFFc0e96e, 0xFFb1e360, 0xFFa3dd53, 0xFF94d247, 0xFF86c83b, 0xFF78bc35, + 0xFF69b030, 0xFF62a52b, 0xFF5b9b27, 0xFF57920a, 0xFF0995fc, 0xFF0d96e5, 0xFF1091eb, 0xFF1091eb, + 0xFF4ac5f0, 0xFF49c4f0, 0xFF47c3f1, 0xFF45c2f1, 0xFF44c1f2, 0xFF41c1f2, 0xFF3fc1f2, 0xFF3fbff1, + 0xFF3fbcf0, 0xFF32c3fe, 0xFFbe7f6e, 0xFFfe6526, 0xFFf67b35, 0xFFf59a4d, 0xFFf8ab5c, 0xFFfbd0a0, + 0xFFf7c783, 0xFFfec16b, 0xFFfdd17f, 0xFFfbdb87, 0xFFf9e590, 0xFFf8ed9a, 0xFFf7f4a5, 0xFFfbea9a, + 0xFFffdf8e, 0xFFfce3a0, 0xFFf7e6b1, 0xFFfceecc, 0xFFfffbcb, 0xFFfff3c7, 0xFFfcf1c3, 0xFFfef5d2, + 0xFFfffcd3, 0xFF4bb5e7, 0xFF21a5ed, 0xFF1ca2ee, 0xFF3daae2, 0xFFeef6ac, 0xFFe6f2b1, 0xFFe8f2b5, + 0xFFe9f3b8, 0xFFeaf4ba, 0xFFebf5bc, 0xFFe8f3b6, 0xFFe6f2af, 0xFFe0f0a8, 0xFFdbeea2, 0xFFd6ef9a, + 0xFFd1f092, 0xFFc9ed82, 0xFFc1eb73, 0xFFb0e362, 0xFFa1dc51, 0xFF94d347, 0xFF88ca3e, 0xFF7bbf38, + 0xFF6eb433, 0xFF66a92e, 0xFF5da01b, 0xFF3d9448, 0xFF0a93f6, 0xFF0e94ec, 0xFF1193f0, 0xFF1193f0, + 0xFF4bc5f1, 0xFF4ac5f1, 0xFF48c4f1, 0xFF47c3f2, 0xFF45c3f2, 0xFF40c3f4, 0xFF3bc4f6, 0xFF3cbff3, + 0xFF3ebbf0, 0xFF2dcaff, 0xFFff5d25, 0xFFfe6d2f, 0xFFf37d39, 0xFFf59348, 0xFFf8a958, 0xFFf7c083, + 0xFFf7d7ae, 0xFFffc36d, 0xFFffda84, 0xFFfbe48c, 0xFFf7ee94, 0xFFf8ed9e, 0xFFfaeca7, 0xFFf9f1b4, + 0xFFf8f6c1, 0xFFfcf6c8, 0xFFfff6d0, 0xFFfef2d3, 0xFFfcf4ba, 0xFFfffee8, 0xFFf7fdea, 0xFFfdfde3, + 0xFFfffcdc, 0xFF0b9df1, 0xFF2aaaed, 0xFF1baaf6, 0xFF80c8da, 0xFFfdffbb, 0xFFe8f2bd, 0xFFebf4c4, + 0xFFeff7cb, 0xFFeff7cb, 0xFFeff7cb, 0xFFedf6c5, 0xFFebf5c0, 0xFFeaf4be, 0xFFe8f3bd, 0xFFe4f4b4, + 0xFFe0f6ab, 0xFFd0f191, 0xFFc1ec77, 0xFFb0e463, 0xFF9edb4e, 0xFF95d448, 0xFF8bcc42, 0xFF7fc23b, + 0xFF73b935, 0xFF6aac31, 0xFF60a510, 0xFF229687, 0xFF0b91f1, 0xFF0e93f3, 0xFF1294f5, 0xFF1294f5, + 0xFF4cc6f1, 0xFF4bc5f2, 0xFF49c5f2, 0xFF47c4f2, 0xFF46c4f2, 0xFF43c4f1, 0xFF40c4f0, 0xFF42c0f3, + 0xFF39c1f6, 0xFF5eacca, 0xFFfb591e, 0xFFf36e31, 0xFFf88135, 0xFFfb923f, 0xFFfbaf5e, 0xFFffc373, + 0xFFfde2ba, 0xFFffcd75, 0xFFffd372, 0xFFffe584, 0xFFfff796, 0xFFfef4a2, 0xFFfdf1ae, 0xFFfff8c2, + 0xFFfcf8cd, 0xFFfef8d2, 0xFFfff9d6, 0xFFfef6e1, 0xFFfcf5dd, 0xFFfffbee, 0xFFfbfce8, 0xFFfffce0, + 0xFFb2e0e8, 0xFF19a4f0, 0xFF26abec, 0xFF16a8f6, 0xFFc2e4d8, 0xFFf9fac5, 0xFFeff6cb, 0xFFf0f7ce, + 0xFFf1f8d2, 0xFFf1f8d1, 0xFFf2f9d1, 0xFFf1f9cd, 0xFFf1f9ca, 0xFFf2fbca, 0xFFf4fdca, 0xFFe7f8b6, + 0xFFdaf3a2, 0xFFcbef8a, 0xFFbcec71, 0xFFb0e661, 0xFFa5e151, 0xFF9ad949, 0xFF8fd240, 0xFF83c73b, + 0xFF77bc35, 0xFF6ab31d, 0xFF5ea905, 0xFF138dea, 0xFF1193ef, 0xFF1093f0, 0xFF0f93f0, 0xFF0f93f0, + 0xFF4dc6f2, 0xFF4cc6f2, 0xFF4ac5f3, 0xFF48c5f3, 0xFF47c5f3, 0xFF46c4ef, 0xFF46c4eb, 0xFF48c0f3, + 0xFF34c7fb, 0xFF989591, 0xFFfc6428, 0xFFf1773b, 0xFFfc8432, 0xFFff9135, 0xFFffb564, 0xFFffbe5a, + 0xFFf3ddb6, 0xFFccd097, 0xFFb4cea5, 0xFFb0d3b1, 0xFFabd7bd, 0xFFc3e1bf, 0xFFdaebc1, 0xFFf5fdc7, + 0xFFffffbd, 0xFFfffecd, 0xFFfffcdc, 0xFFfffce0, 0xFFfbfce5, 0xFFfdfbe6, 0xFFfffae7, 0xFFfffbdd, + 0xFF61c4f4, 0xFF26aaee, 0xFF22abec, 0xFF10a7f6, 0xFFffffd7, 0xFFf5f5d0, 0xFFf6fad9, 0xFFf4f9d9, + 0xFFf2f9da, 0xFFf3fad8, 0xFFf4fbd7, 0xFFf5fcd5, 0xFFf7fdd4, 0xFFf3face, 0xFFf0f7c8, 0xFFe2f4b0, + 0xFFd4f199, 0xFFc5ee82, 0xFFb7eb6b, 0xFFb1e95f, 0xFFabe754, 0xFF9fdf49, 0xFF94d83f, 0xFF87cc3a, + 0xFF7bc034, 0xFF6bb425, 0xFF5ba332, 0xFF0495f9, 0xFF1795ee, 0xFF1293ed, 0xFF0c91eb, 0xFF0c91eb, + 0xFF4fc8f3, 0xFF4dc8f3, 0xFF4cc8f4, 0xFF4bc8f4, 0xFF49c8f4, 0xFF47c5f2, 0xFF45c2ef, 0xFF42c2f8, + 0xFF34c8ff, 0xFFdf6746, 0xFFff632a, 0xFFff701b, 0xFFe18b53, 0xFFa4a185, 0xFF63c1cd, 0xFF26c0ff, + 0xFF2ab8ff, 0xFF25b5f1, 0xFF27b7f9, 0xFF26b5f6, 0xFF23b3f2, 0xFF24b5fa, 0xFF25b7ff, 0xFF189ddf, + 0xFF43bbf4, 0xFF9edae8, 0xFFf9f9dc, 0xFFf3fbe6, 0xFFffffea, 0xFFfdffe6, 0xFFfafce2, 0xFFffffff, + 0xFF1ea8ef, 0xFF1ca8f1, 0xFF1ba8f2, 0xFF5bc4f1, 0xFFffffe7, 0xFFfbf9e1, 0xFFfbfce3, 0xFFf8fbe0, + 0xFFf5fadd, 0xFFf5fbdb, 0xFFf5fbda, 0xFFf6fcd7, 0xFFf6fdd3, 0xFFf0f8c9, 0xFFebf4be, 0xFFdff2a9, + 0xFFd4f094, 0xFFc7f47b, 0xFFbaf862, 0xFFb0ef58, 0xFFa6e64e, 0xFFa3e248, 0xFF98d73a, 0xFF8acd38, + 0xFF7bc435, 0xFF70b821, 0xFF3b9c84, 0xFF0d93f4, 0xFF1394ed, 0xFF1193e9, 0xFF0f92e6, 0xFF0f92e6, + 0xFF50c9f4, 0xFF4fcaf4, 0xFF4ecaf5, 0xFF4dcaf5, 0xFF4ccaf6, 0xFF48c5f4, 0xFF45c0f3, 0xFF47c2ef, + 0xFF4ac4eb, 0xFFff521f, 0xFFa79a92, 0xFF51b7e6, 0xFF28c7ff, 0xFF2cc4f9, 0xFF31c1f1, 0xFF3fbbf0, + 0xFF37c0ef, 0xFF39b9f0, 0xFF3bb3f1, 0xFF38b5f4, 0xFF36b7f7, 0xFF32b9f0, 0xFF2fbbe8, 0xFF2fb8eb, + 0xFF2fb5ed, 0xFF20acf3, 0xFF10a3fa, 0xFF70c9f3, 0xFFf5f9df, 0xFFf6fbde, 0xFFf6fdde, 0xFFd8ebe4, + 0xFF11a5ee, 0xFF2db2f5, 0xFF14a5f8, 0xFFa5e2ec, 0xFFfffff8, 0xFFfffef3, 0xFFfffded, 0xFFfcfde6, + 0xFFf8fce0, 0xFFf7fcde, 0xFFf6fcdd, 0xFFf6fcd8, 0xFFf5fdd3, 0xFFedf7c4, 0xFFe5f1b4, 0xFFe5f5b8, + 0xFFe4f9bb, 0xFFecfed2, 0xFFf3ffe9, 0xFFedfedb, 0xFFe8f9cd, 0xFFcaef89, 0xFF9cd636, 0xFF84c72e, + 0xFF6bb826, 0xFF6cb315, 0xFF1a95d6, 0xFF1591ef, 0xFF1093eb, 0xFF1193e6, 0xFF1294e1, 0xFF1294e1, + 0xFF52cbf4, 0xFF50caf4, 0xFF4ecaf4, 0xFF4ccaf3, 0xFF4ac9f3, 0xFF48c8f5, 0xFF46c7f6, 0xFF40bfed, + 0xFF41bfeb, 0xFF41d4f9, 0xFF33c9fc, 0xFF2fc9ff, 0xFF42c3ec, 0xFF40c3f4, 0xFF3ec3fc, 0xFF35bbf4, + 0xFF33bbf3, 0xFF49bdf7, 0xFF39b7f9, 0xFF37b7f6, 0xFF35b7f2, 0xFF2eb5f4, 0xFF28b3f5, 0xFF2fbbf8, + 0xFF2fbaf2, 0xFF30b5f2, 0xFF31b0f1, 0xFF1facf6, 0xFF0dabed, 0xFF7fd2ed, 0xFFffffe6, 0xFF80d9d2, + 0xFF2faaf8, 0xFF1dafec, 0xFF03aae6, 0xFFfff8ff, 0xFFfffffe, 0xFFfffff9, 0xFFfffdf4, 0xFFfdfeeb, + 0xFFfbfee3, 0xFFf9fde1, 0xFFf7fce0, 0xFFf5fdd8, 0xFFf4fdcf, 0xFFf5fce2, 0xFFf6fde8, 0xFFf3fde8, + 0xFFf1fde9, 0xFFebfdd3, 0xFFe6fdbe, 0xFFe0f8ba, 0xFFdaf2b7, 0xFFeafcd2, 0xFFf2fde6, 0xFFb7de8d, + 0xFF84c73d, 0xFF9ab848, 0xFF14a1f9, 0xFF0494f3, 0xFF1094ef, 0xFF1095ec, 0xFF1095e9, 0xFF1095e9, + 0xFF54ccf5, 0xFF51cbf4, 0xFF4ecaf3, 0xFF4cc9f2, 0xFF49c8f1, 0xFF48cbf5, 0xFF48cef9, 0xFF40c4f3, + 0xFF49cafc, 0xFF40c2f1, 0xFF47caf5, 0xFF46c7f4, 0xFF46c4f3, 0xFF39b5ee, 0xFF2ca5e8, 0xFF2eb1e1, + 0xFF56c1ea, 0xFF6dc9e9, 0xFF37c2e5, 0xFF51caeb, 0xFF6bd2f1, 0xFF74d1f5, 0xFF7dcff9, 0xFF56c7f8, + 0xFF1fafe8, 0xFF25b1ee, 0xFF2cb3f4, 0xFF3eb5f9, 0xFF2bb3ee, 0xFF1baff5, 0xFF32b5f0, 0xFF3fb2f9, + 0xFF26a9f2, 0xFF1faeeb, 0xFF3fb8f4, 0xFFfcfff3, 0xFFffffff, 0xFFffffff, 0xFFfffefb, 0xFFfefff1, + 0xFFfeffe6, 0xFFfbffe5, 0xFFf8fde3, 0xFFf5fdd7, 0xFFf3fecb, 0xFFf5fbeb, 0xFFf7feee, 0xFFf2fdde, + 0xFFedfccf, 0xFFe3f9b0, 0xFFd9f692, 0xFFd2f48b, 0xFFccf184, 0xFFceee97, 0xFFd0eaa9, 0xFFdaebc1, + 0xFFf4fbe9, 0xFF7fc679, 0xFF5ac1ff, 0xFF1aa1eb, 0xFF1195f2, 0xFF0f96f2, 0xFF0e97f2, 0xFF0e97f2, + 0xFF54cdf5, 0xFF52ccf4, 0xFF4fcbf3, 0xFF4dc9f3, 0xFF4ac8f2, 0xFF49c6f2, 0xFF47c4f2, 0xFF49d2f3, + 0xFF46c8f3, 0xFF4dc5fc, 0xFF2c9add, 0xFF1883cd, 0xFF046cbe, 0xFF0080c5, 0xFF0f96d4, 0xFF2eaddb, + 0xFF60c6eb, 0xFF76cdef, 0xFF51caea, 0xFF69d2f0, 0xFF81daf5, 0xFF9ae4f7, 0xFFb3eff9, 0xFFcffaff, + 0xFFe3feff, 0xFF9ae1ff, 0xFF48bcf7, 0xFF11b5dd, 0xFF32aef0, 0xFF28acfc, 0xFF31b2f3, 0xFF34b1f6, + 0xFF25adf0, 0xFF26acf6, 0xFF98d1fc, 0xFFfffdf8, 0xFFffffff, 0xFFfffffb, 0xFFfefff4, 0xFFfdffee, + 0xFFfcfde7, 0xFFfbfee4, 0xFFfaffe0, 0xFFf8fde7, 0xFFf7fcef, 0xFFf3fbeb, 0xFFeffdd9, 0xFFe9fbc2, + 0xFFe3f9ac, 0xFFd9f49b, 0xFFceef8b, 0xFFc1ea76, 0xFFb4e562, 0xFFabdd5a, 0xFFa2d261, 0xFFc1e98e, + 0xFFdbe8b9, 0xFF96d4ff, 0xFF8ed0fa, 0xFF42aeee, 0xFF1095f1, 0xFF1096f1, 0xFF0f96f1, 0xFF0f96f1, + 0xFF55cef5, 0xFF53ccf4, 0xFF50cbf4, 0xFF4ecaf4, 0xFF4cc8f4, 0xFF51caf7, 0xFF57cbfa, 0xFF45c0ea, + 0xFF1a75c7, 0xFF0058ad, 0xFF015bb4, 0xFF066fc0, 0xFF0b84cd, 0xFF0093ce, 0xFF11a7e0, 0xFF3eb9e6, + 0xFF6bcbeb, 0xFF7ed1f6, 0xFF6cd3f0, 0xFF82dbf4, 0xFF98e3f9, 0xFFa5ecf7, 0xFFb2f4f5, 0xFFc7f7f9, + 0xFFddfafd, 0xFFf2ffff, 0xFFf8fff6, 0xFFbcebfe, 0xFF22b4f2, 0xFF29afff, 0xFF2fb0f7, 0xFF29b1f2, + 0xFF23b1ee, 0xFF1aa7fa, 0xFFcae6f4, 0xFFf7f8f4, 0xFFfeffff, 0xFFfefff7, 0xFFfeffed, 0xFFfcffeb, + 0xFFfbfae9, 0xFFfbfee3, 0xFFfbffdc, 0xFFfbffe9, 0xFFfbfff7, 0xFFf1fedd, 0xFFe7fbc3, 0xFFe0f6b4, + 0xFFd8f0a5, 0xFFceec94, 0xFFc4e884, 0xFFb8e678, 0xFFace36c, 0xFFa0df53, 0xFF94d455, 0xFF80bd41, + 0xFFd2e599, 0xFF2ca1f4, 0xFF30a2f6, 0xFF209cf3, 0xFF1096f1, 0xFF1096f1, 0xFF1096f1, 0xFF1096f1, + 0xFF55cef4, 0xFF53cdf4, 0xFF51cbf5, 0xFF50cbf5, 0xFF4ecaf6, 0xFF4dc9f4, 0xFF54d0fa, 0xFF2b86ce, + 0xFF0752b1, 0xFF045fb9, 0xFF0a74c9, 0xFF0882ce, 0xFF0691d4, 0xFF02a0d5, 0xFF24b5e7, 0xFF4cc4ea, + 0xFF74d3ee, 0xFF83d9f5, 0xFF7fddf4, 0xFF93e4f6, 0xFFa8ecf9, 0xFFb6f2f9, 0xFFc3f9f9, 0xFFd3fafb, + 0xFFe3fcfc, 0xFFedfefb, 0xFFf0f9f3, 0xFFffffff, 0xFFfffdff, 0xFF7edcef, 0xFF26adfd, 0xFF2aaff7, + 0xFF2db2f2, 0xFF34b1e0, 0xFF09a7f7, 0xFF8dd3f5, 0xFFfdfbf9, 0xFFfffff6, 0xFFfdffeb, 0xFFfcffe6, + 0xFFfcfce0, 0xFFf9fcde, 0xFFf7fcdd, 0xFFfcffef, 0xFFf9fdec, 0xFFe8f5d0, 0xFFdff5bd, 0xFFd9f1ad, + 0xFFd2ed9d, 0xFFc5e97e, 0xFFb8e26d, 0xFFabdd5e, 0xFF9fd74f, 0xFF98c95f, 0xFF92c735, 0xFF8bc942, + 0xFF80b34d, 0xFF009bf2, 0xFF1894f8, 0xFF1595f5, 0xFF1397f2, 0xFF1296f1, 0xFF1195f0, 0xFF1195f0, + 0xFF56cff4, 0xFF54cdf5, 0xFF52ccf5, 0xFF51cbf7, 0xFF51cbf9, 0xFF49c8f1, 0xFF51d5fa, 0xFF1662c1, + 0xFF005cbb, 0xFF0874cd, 0xFF037cce, 0xFF028dd4, 0xFF019edb, 0xFF09aedc, 0xFF37c2ee, 0xFF5acfef, + 0xFF7edcf0, 0xFF88e1f4, 0xFF92e6f8, 0xFFa5eef8, 0xFFb9f5f9, 0xFFc7f9fb, 0xFFd5fdfe, 0xFFdffdfc, + 0xFFe9fdfa, 0xFFf0fefe, 0xFFf8ffff, 0xFFfafffe, 0xFFfdfffc, 0xFFfdfbff, 0xFF1db0e8, 0xFF2ab1ee, + 0xFF37b2f5, 0xFF25b9f7, 0xFF29b4f8, 0xFF22aff5, 0xFF1baaf2, 0xFF9fd7f6, 0xFFfdffea, 0xFFfcfee0, + 0xFFfcfdd7, 0xFFf8fada, 0xFFf4f7dd, 0xFFfdfef5, 0xFFf6fae1, 0xFFdfecc3, 0xFFd8efb6, 0xFFd2eca6, + 0xFFccea95, 0xFFbce567, 0xFFabdb56, 0xFF9fd344, 0xFF92cb33, 0xFF85c824, 0xFF79b46a, 0xFF3a9eaf, + 0xFF0c97ff, 0xFF1994f9, 0xFF0f9bee, 0xFF139af0, 0xFF1699f3, 0xFF1497f1, 0xFF1295ef, 0xFF1295ef, + 0xFF58d0f5, 0xFF56cef5, 0xFF53cdf4, 0xFF53ccf6, 0xFF52cbf8, 0xFF53d6fb, 0xFF4fc8fc, 0xFF004cad, + 0xFF096fca, 0xFF0b80d4, 0xFF0588d5, 0xFF0598db, 0xFF05a8e1, 0xFF18b6e6, 0xFF3fc8f2, 0xFF63d3f3, + 0xFF86dff5, 0xFF91e4f7, 0xFF9ce9fa, 0xFFaef0f9, 0xFFc0f7f9, 0xFFcbfafb, 0xFFd7fdfd, 0xFFdefdfc, + 0xFFe6fefb, 0xFFf0fffe, 0xFFfaffff, 0xFFf2fefb, 0xFFfefffd, 0xFFc6e9fb, 0xFF1eb0ec, 0xFF30b4f6, + 0xFF30b7f8, 0xFF19a8f7, 0xFF26b0f0, 0xFF22aef3, 0xFF1eabf5, 0xFF27aafa, 0xFF1ca6f6, 0xFF7dcdea, + 0xFFdff4dd, 0xFFeaffb0, 0xFFfdfeed, 0xFFffffef, 0xFFfcf9d3, 0xFFedeeb4, 0xFFe6e9ac, 0xFFd9e68a, + 0xFFcbe367, 0xFFb9e153, 0xFFa6dd4d, 0xFF75c57f, 0xFF43adb0, 0xFF229bf3, 0xFF0a9cff, 0xFF0998f6, + 0xFF109cef, 0xFF189aee, 0xFF149ded, 0xFF159bf0, 0xFF1599f2, 0xFF1397f0, 0xFF1195ee, 0xFF1195ee, + 0xFF5ad1f6, 0xFF57cff5, 0xFF54cef4, 0xFF54cdf6, 0xFF53cbf8, 0xFF4dd3f4, 0xFF2c9add, 0xFF045ec1, + 0xFF0572c9, 0xFF0683d2, 0xFF0794dc, 0xFF08a2e2, 0xFF08b1e8, 0xFF28bfef, 0xFF48cef6, 0xFF6bd8f8, + 0xFF8fe3fa, 0xFF9be8fa, 0xFFa6edfb, 0xFFb7f3fb, 0xFFc7f9fa, 0xFFd0fbfc, 0xFFd9fdfd, 0xFFdefefd, + 0xFFe2fffc, 0xFFeffffe, 0xFFfcffff, 0xFFebfef7, 0xFFfffffe, 0xFF8fd7f8, 0xFF1eb0f1, 0xFF2eb0f6, + 0xFF18abec, 0xFFe0f7fd, 0xFF24ade9, 0xFF23acf1, 0xFF21acf8, 0xFF26aef7, 0xFF2cb0f6, 0xFF1aa9f5, + 0xFF08a3f4, 0xFF22a7f9, 0xFF4cc2f2, 0xFF6dcdef, 0xFF7ec9db, 0xFF7fcac2, 0xFF81c6c6, 0xFF61bccb, + 0xFF41b3d0, 0xFF24a7e9, 0xFF089bff, 0xFF119dff, 0xFF1a9fff, 0xFF0f99e9, 0xFF149cf9, 0xFF159cf7, + 0xFF159cf5, 0xFF179df1, 0xFF199eed, 0xFF179cef, 0xFF1599f1, 0xFF1397ef, 0xFF1195ed, 0xFF1195ed, + 0xFF5cd2f6, 0xFF59d0f5, 0xFF55cff3, 0xFF54cdf5, 0xFF53ccf8, 0xFF51d5f6, 0xFF167bcf, 0xFF0467c6, + 0xFF067bcf, 0xFF068bd7, 0xFF059cdf, 0xFF08a9e5, 0xFF0ab6eb, 0xFF2bc4f1, 0xFF4cd2f7, 0xFF6ddbf9, + 0xFF8ee5fa, 0xFF9deafb, 0xFFaceffb, 0xFFbdf5fb, 0xFFcefbfa, 0xFFd5fbfc, 0xFFdcfcfd, 0xFFdcfefd, + 0xFFddfffd, 0xFFe4fffd, 0xFFeafffd, 0xFFfffffe, 0xFFffffff, 0xFF27c0de, 0xFF26b5f6, 0xFF1fb0f9, + 0xFF4dc6ff, 0xFFfff9ef, 0xFFfefffa, 0xFF8bd8f7, 0xFF18a7f3, 0xFF1daaf4, 0xFF23acf6, 0xFF22acf3, + 0xFF22abf0, 0xFF1aa3f2, 0xFF1aa6ee, 0xFF18a8f5, 0xFF0ea2f3, 0xFF11a4f2, 0xFF14a4ff, 0xFF15a3fc, + 0xFF16a3fa, 0xFF17a2f3, 0xFF19a2ec, 0xFF0e99fe, 0xFF169bed, 0xFF00a1ff, 0xFF2b9de8, 0xFF61b5b0, + 0xFF109af7, 0xFF149cf2, 0xFF189eed, 0xFF169cef, 0xFF149af0, 0xFF1298ee, 0xFF1096ec, 0xFF1096ec, + 0xFF5fd3f7, 0xFF5bd2f5, 0xFF56d0f3, 0xFF55cef5, 0xFF53cdf7, 0xFF56d8f8, 0xFF005cc0, 0xFF0370cb, + 0xFF0785d6, 0xFF0594dc, 0xFF04a3e2, 0xFF08afe8, 0xFF0cbcee, 0xFF2ec8f3, 0xFF50d5f9, 0xFF6fdefa, + 0xFF8de7fb, 0xFF9fecfb, 0xFFb1f2fb, 0xFFc3f7fb, 0xFFd4fcfa, 0xFFd9fcfc, 0xFFdefcfd, 0xFFdbfdfd, + 0xFFd9fffd, 0xFFd9fdfb, 0xFFd9fcfa, 0xFFe5fafa, 0xFFa4eaf7, 0xFF2badfb, 0xFF2fb9fa, 0xFF1aaeed, + 0xFF99dbf8, 0xFFffffff, 0xFFfefdfc, 0xFFfffefd, 0xFFfffffd, 0xFF8cd4fa, 0xFF19a9f6, 0xFF18a9f7, + 0xFF16aaf9, 0xFF1aa7f3, 0xFF1ea5ee, 0xFF1fa7f2, 0xFF21a9f6, 0xFF1ea7f7, 0xFF1ba5f7, 0xFF17a4f9, + 0xFF12a2fb, 0xFF0b9dfd, 0xFF0399fe, 0xFF26a2fa, 0xFF6fc0b0, 0xFFcfca5e, 0xFFffe528, 0xFF74b4b3, + 0xFF0b98fa, 0xFF119af4, 0xFF179dee, 0xFF159cee, 0xFF139aef, 0xFF1198ed, 0xFF0f96eb, 0xFF0f96eb, + 0xFF5dd1f6, 0xFF5bd2f5, 0xFF58d2f4, 0xFF53cef4, 0xFF56d2fb, 0xFF40b2e6, 0xFF0164c6, 0xFF0376cf, + 0xFF0487d7, 0xFF0296dd, 0xFF01a4e4, 0xFF04b1ea, 0xFF07bdf1, 0xFF1bc8f2, 0xFF43d5fc, 0xFF64ddfb, + 0xFF85e6fb, 0xFF98ebfc, 0xFFacf1fd, 0xFFbef9ff, 0xFFcfffff, 0xFFcffdff, 0xFFcff9fb, 0xFFd2fefe, + 0xFFd5ffff, 0xFFc6f9ff, 0xFFb8efff, 0xFF5ad7d9, 0xFF40b9e9, 0xFF2fb9ff, 0xFF2bb2f0, 0xFF28afeb, + 0xFFdef0f2, 0xFFffffff, 0xFFfeffff, 0xFFfffefe, 0xFFfffefa, 0xFFfffffa, 0xFFfffff9, 0xFFc2e8f0, + 0xFF84cde7, 0xFF53bbe9, 0xFF22a9eb, 0xFF14a1ff, 0xFF069ff8, 0xFF0fa0f8, 0xFF19a3eb, 0xFF43b1e1, + 0xFF6ec2c9, 0xFFb0d79a, 0xFFf2eb6b, 0xFFebee32, 0xFFf8e647, 0xFFffe23a, 0xFFfde142, 0xFF0098f4, + 0xFF19a1fc, 0xFF169ef7, 0xFF129bf1, 0xFF139af1, 0xFF149af0, 0xFF1298ee, 0xFF1096ec, 0xFF1096ec, + 0xFF5ccff6, 0xFF5bd2f6, 0xFF5ad4f6, 0xFF52cdf2, 0xFF5ad6fe, 0xFF298cd5, 0xFF026ccc, 0xFF027bd2, + 0xFF0189d8, 0xFF0097df, 0xFF00a6e6, 0xFF00b2ed, 0xFF02bef4, 0xFF09c7f1, 0xFF35d5ff, 0xFF59ddfd, + 0xFF7ce5fb, 0xFF91eafd, 0xFFa6f0ff, 0xFFb1f2ff, 0xFFbbf5ff, 0xFFbef5fc, 0xFFc1f6f9, 0xFFc1f7f7, + 0xFFc1f9f4, 0xFFc7fdfc, 0xFFcdffff, 0xFFc2f9f8, 0xFF5acdf4, 0xFF39b1f3, 0xFF38baf5, 0xFF2ab4f7, + 0xFFfcfbf8, 0xFFfdfeff, 0xFFfeffff, 0xFFfffeff, 0xFFfffcf6, 0xFFfdfef2, 0xFFf7ffee, 0xFFfcffea, + 0xFFffffe5, 0xFFffffd8, 0xFFffffcb, 0xFFfffbf1, 0xFFffffdf, 0xFFfdfdc2, 0xFFf7ff88, 0xFFfbfe92, + 0xFFffff7f, 0xFFfdfc6c, 0xFFfaf759, 0xFFf8f059, 0xFFf7e958, 0xFFf7e359, 0xFFd0d368, 0xFF0998ff, + 0xFF189aef, 0xFF129af2, 0xFF0c99f5, 0xFF1199f3, 0xFF1599f2, 0xFF1397f0, 0xFF1195ee, 0xFF1195ee, + 0xFF5fd2f9, 0xFF5cd3f8, 0xFF59d4f6, 0xFF58d3f8, 0xFF5edaff, 0xFF1971cd, 0xFF026ecd, 0xFF037bd3, + 0xFF0488d9, 0xFF0497e0, 0xFF05a6e6, 0xFF01ade7, 0xFF00b5e8, 0xFF07beea, 0xFF23cbf5, 0xFF4cd7f8, + 0xFF74e4fc, 0xFF89e8fd, 0xFF9fecfe, 0xFFa5edfe, 0xFFabeffe, 0xFFaeeffc, 0xFFb0eff9, 0xFFb3f3f9, + 0xFFb6f6f8, 0xFFb6f9fc, 0xFFb5fcff, 0xFFdaf3ff, 0xFF1ab9f1, 0xFF28b3f4, 0xFF2bb3f6, 0xFF73cef4, + 0xFFfdfdf5, 0xFFfdfefa, 0xFFfdfffe, 0xFFfffef9, 0xFFfffdf3, 0xFFfdfeee, 0xFFfaffe9, 0xFFfdffe4, + 0xFFffffde, 0xFFffffd0, 0xFFffffc2, 0xFFfdfad7, 0xFFfffcf3, 0xFFffffc0, 0xFFfcfbc5, 0xFFfcff84, + 0xFFfcfb8b, 0xFFfbf67a, 0xFFf9f269, 0xFFf7ed5e, 0xFFf4e954, 0xFFf7e948, 0xFF87bda9, 0xFF109afc, + 0xFF179cf2, 0xFF149bf1, 0xFF119af1, 0xFF1399f2, 0xFF1698f3, 0xFF1496f1, 0xFF1294ef, 0xFF1294ef, + 0xFF62d4fc, 0xFF5dd4f9, 0xFF59d4f6, 0xFF56d1f6, 0xFF53cef5, 0xFF014ebe, 0xFF026fcd, 0xFF057bd4, + 0xFF0787da, 0xFF0996e0, 0xFF0ca5e7, 0xFF0bb0e9, 0xFF09bbeb, 0xFF15c5f3, 0xFF21d0fc, 0xFF46dafc, + 0xFF6ce3fc, 0xFF82e6fd, 0xFF97e9fe, 0xFF99e9fe, 0xFF9ce8fe, 0xFF9ee9fb, 0xFFa0e9f9, 0xFFa6eefa, + 0xFFacf3fc, 0xFFb0effc, 0xFFb5ecfb, 0xFF89ddf9, 0xFF28b4f3, 0xFF3ebef7, 0xFF1eadf7, 0xFFbde8f0, + 0xFFfefff2, 0xFFfefff3, 0xFFfdfff4, 0xFFfefef2, 0xFFfefef0, 0xFFfefeea, 0xFFfefee4, 0xFFfefede, + 0xFFfefed8, 0xFFfcffc9, 0xFFfbffba, 0xFFf6fea0, 0xFFffffce, 0xFFfff9f6, 0xFFffffc9, 0xFFfdf7be, + 0xFFf8f87a, 0xFFf9f66b, 0xFFf9f35c, 0xFFf5ee56, 0xFFf1e84f, 0xFFf8ee37, 0xFF3fa7ea, 0xFF189df5, + 0xFF179df4, 0xFF169cf1, 0xFF159bee, 0xFF169af2, 0xFF1798f5, 0xFF1596f3, 0xFF1394f1, 0xFF1394f1, + 0xFF66d7fc, 0xFF5fd1f5, 0xFF60d4f6, 0xFF59d8f9, 0xFF399ddb, 0xFF0858be, 0xFF096ccd, 0xFF0c7ad2, + 0xFF1087d7, 0xFF1296df, 0xFF13a6e8, 0xFF13b0eb, 0xFF1bc3f5, 0xFF0fc8f3, 0xFF17d0f9, 0xFF27d3f4, + 0xFF4bd7f7, 0xFF61dbf8, 0xFF77def9, 0xFF7fe0fa, 0xFF88e1fa, 0xFF8de4fb, 0xFF91e7fb, 0xFF96eafc, + 0xFF9aedfd, 0xFF9feafb, 0xFFa3e7fa, 0xFF5eccfb, 0xFF2db7f5, 0xFF24b8f9, 0xFF14b1f5, 0xFFfffbff, + 0xFFfeffec, 0xFFffffed, 0xFFffffee, 0xFFffffec, 0xFFfefdeb, 0xFFfefde4, 0xFFfefddd, 0xFFfefed6, + 0xFFfefece, 0xFFfcfdc1, 0xFFfcfcb5, 0xFFf6fb8d, 0xFFf8fc8a, 0xFFf8facc, 0xFFf8fef2, 0xFFf9ffbe, + 0xFFfbf9c2, 0xFFfbf8ac, 0xFFfcf796, 0xFFfaf491, 0xFFf7f18d, 0xFFffe5a9, 0xFF0096f7, 0xFF089af7, + 0xFF159ef7, 0xFF169df4, 0xFF169cf0, 0xFF169bf2, 0xFF1699f4, 0xFF1497f3, 0xFF1396f1, 0xFF1396f1, + 0xFF6bd9fb, 0xFF61cef1, 0xFF67d3f7, 0xFF5cdefd, 0xFF1f6cc0, 0xFF0f63bf, 0xFF0f6acd, 0xFF1478d1, + 0xFF1887d4, 0xFF1997df, 0xFF1aa6e9, 0xFF14a9e4, 0xFF1dbbef, 0xFF0dbeeb, 0xFF23c5f6, 0xFF13c6ed, + 0xFF2acbf3, 0xFF40cff4, 0xFF56d4f4, 0xFF65d7f6, 0xFF74daf7, 0xFF7bdffb, 0xFF83e5fe, 0xFF86e6fe, + 0xFF89e8fd, 0xFF8ee5fb, 0xFF92e2fa, 0xFF33bcfc, 0xFF32b9f7, 0xFF31bafd, 0xFF57c5f7, 0xFFf4ffde, + 0xFFfdffe7, 0xFFffffe7, 0xFFffffe7, 0xFFffffe6, 0xFFfdfce6, 0xFFfdfddd, 0xFFfdfdd5, 0xFFfdfdcd, + 0xFFfefdc5, 0xFFfdfaba, 0xFFfcf8af, 0xFFfef99f, 0xFFfffb8e, 0xFFfafe77, 0xFFf4fb7d, 0xFFf9f8d2, + 0xFFfdffee, 0xFFfefedf, 0xFFfffcd0, 0xFFfefacd, 0xFFfdf9ca, 0xFFa6d3ce, 0xFF0399eb, 0xFF1ea1ec, + 0xFF149ffa, 0xFF159ef6, 0xFF179ef2, 0xFF169cf3, 0xFF159af3, 0xFF1499f2, 0xFF1398f1, 0xFF1398f1, + 0xFF55d4f4, 0xFF5bd1f1, 0xFF69d6f6, 0xFF6ee2ff, 0xFF0c50a8, 0xFF1161be, 0xFF0f6acd, 0xFF1f83d6, + 0xFF1f89dc, 0xFF0f8cdd, 0xFF1a9be0, 0xFF22b1f4, 0xFF1dabe1, 0xFF14aedf, 0xFF26bdee, 0xFF15bae7, + 0xFF1fc1ef, 0xFF25c7ef, 0xFF2bcdef, 0xFF3dcdf1, 0xFF4ecef3, 0xFF5bd6f9, 0xFF68defe, 0xFF6eddfc, + 0xFF73ddfb, 0xFF76ddf5, 0xFF70d3f7, 0xFF31bafb, 0xFF33b9f6, 0xFF24b6ff, 0xFFa4dee5, 0xFFf9ffdc, + 0xFFfdfedc, 0xFFffffdc, 0xFFffffdc, 0xFFfefedb, 0xFFfcfdda, 0xFFfdfdd2, 0xFFfdfdcb, 0xFFfdfdc3, + 0xFFfefdbc, 0xFFfdfbaf, 0xFFfcfaa2, 0xFFfdfb93, 0xFFfefb83, 0xFFfcfd6b, 0xFFf9fc60, 0xFFfbf85d, + 0xFFfdf74c, 0xFFfef576, 0xFFfff2a1, 0xFFf6ec87, 0xFFf8e360, 0xFF51bbb4, 0xFF0d9afe, 0xFF1a9ef7, + 0xFF159ef6, 0xFF159df4, 0xFF159df2, 0xFF149bf2, 0xFF1299f2, 0xFF1299f2, 0xFF1299f2, 0xFF1299f2, + 0xFF67d4fd, 0xFF69d6f9, 0xFF6cd9f5, 0xFF4fb7dc, 0xFF1953af, 0xFF1c67c6, 0xFF005abd, 0xFF1a7eca, + 0xFF157bd4, 0xFF0581dc, 0xFF2aa1e7, 0xFF0189d3, 0xFF2dabe3, 0xFF23a7dc, 0xFF29b4e6, 0xFF17ade1, + 0xFF14b7ec, 0xFF15b9ea, 0xFF16bbe9, 0xFF1fbfec, 0xFF28c2ef, 0xFF3bcdf7, 0xFF4ed8ff, 0xFF56d5fb, + 0xFF5dd2f8, 0xFF5ed6f0, 0xFF4ec5f4, 0xFF2fb9fa, 0xFF35b8f4, 0xFF17b1ff, 0xFFf0f7d2, 0xFFfeffda, + 0xFFfdfcd2, 0xFFfdfdd1, 0xFFfdfed1, 0xFFfdfecf, 0xFFfcfecd, 0xFFfcfdc7, 0xFFfdfdc0, 0xFFfdfdb9, + 0xFFfdfdb2, 0xFFfdfca4, 0xFFfdfc95, 0xFFfdfc87, 0xFFfdfc79, 0xFFfdfa6c, 0xFFfef85f, 0xFFf9f645, + 0xFFf6ef47, 0xFFf2e938, 0xFFefe428, 0xFFeee425, 0xFFffdd05, 0xFF0399ff, 0xFF17a1f5, 0xFF179ef4, + 0xFF169cf3, 0xFF159cf3, 0xFF149cf3, 0xFF129bf1, 0xFF1099f0, 0xFF119af1, 0xFF129bf2, 0xFF129bf2, + 0xFF66d5fb, 0xFF70d5fc, 0xFF78e2ff, 0xFF3b86c7, 0xFF235fba, 0xFF1e6aba, 0xFF227ad1, 0xFF2787d8, + 0xFF248cd7, 0xFF1d8dd4, 0xFF2189d1, 0xFF2ca1ea, 0xFF2296d5, 0xFF31aaef, 0xFF20a1db, 0xFF17a1dd, + 0xFF0ea1e0, 0xFF1aace3, 0xFF13b1eb, 0xFF10b8ed, 0xFF0dc0ef, 0xFF1cc1ef, 0xFF2cc3f0, 0xFF36c4f2, + 0xFF40c5f4, 0xFF47c9f2, 0xFF45c3f6, 0xFF31bafa, 0xFF31b7f7, 0xFF4cc2f4, 0xFFf5fac0, 0xFFfdffc6, + 0xFFfdfcc5, 0xFFfdfdc4, 0xFFfdfdc4, 0xFFfcfdc2, 0xFFfbfdc1, 0xFFf8f9b6, 0xFFfdfdb3, 0xFFfdfdab, + 0xFFfdfca3, 0xFFfcfc95, 0xFFfcfb88, 0xFFfcfb7b, 0xFFfbfb6d, 0xFFfcf962, 0xFFfcf757, 0xFFf8f245, + 0xFFf4eb41, 0xFFf0e532, 0xFFebe023, 0xFFfbe01c, 0xFFc5d244, 0xFF0aa2fe, 0xFF169ff9, 0xFF179ff6, + 0xFF189ff3, 0xFF179ef2, 0xFF159df2, 0xFF179ff5, 0xFF18a1f8, 0xFF159ef5, 0xFF129bf2, 0xFF129bf2, + 0xFF65d7fa, 0xFF64d1f7, 0xFF5de7ff, 0xFF04439b, 0xFF0e4ca5, 0xFF317bcd, 0xFF0455c1, 0xFF0053c9, + 0xFF0368c6, 0xFF2687ca, 0xFF2881ca, 0xFF2789d1, 0xFF2791d7, 0xFF0774c9, 0xFF178dcf, 0xFF1f9ce1, + 0xFF179be4, 0xFF1e9eda, 0xFF0097de, 0xFF03a5e6, 0xFF08b1ee, 0xFF09b0e8, 0xFF0aafe2, 0xFF17b4e9, + 0xFF24b9ef, 0xFF30bdf4, 0xFF3cc1f9, 0xFF34bcf9, 0xFF2cb6f9, 0xFF80d2e8, 0xFFfafdaf, 0xFFfcfdb3, + 0xFFfdfcb7, 0xFFfdfcb7, 0xFFfdfdb7, 0xFFfcfcb6, 0xFFfbfcb5, 0xFFf4f4a5, 0xFFfdfda5, 0xFFfcfc9d, + 0xFFfcfc94, 0xFFfbfb87, 0xFFfbfb7b, 0xFFfafa6e, 0xFFfafa61, 0xFFfaf758, 0xFFfaf54e, 0xFFf7ee44, + 0xFFf3e73a, 0xFFede12c, 0xFFe7db1e, 0xFFffd21a, 0xFF78b090, 0xFF09a0fd, 0xFF159dfd, 0xFF18a0f8, + 0xFF1aa2f2, 0xFF18a0f2, 0xFF169ef2, 0xFF139bf2, 0xFF1099f1, 0xFF119af2, 0xFF129bf3, 0xFF129bf3, + 0xFF60d4f7, 0xFF67dcfd, 0xFF4fc2f0, 0xFF002c8a, 0xFF2e6bc0, 0xFF0547ad, 0xFF0044ba, 0xFF3685c4, + 0xFF064ebc, 0xFF1462c3, 0xFF2d70cb, 0xFF0f5ab4, 0xFF2274cd, 0xFF1169c2, 0xFF1979c2, 0xFF1d80d0, + 0xFF1980d7, 0xFF1a86d3, 0xFF1090de, 0xFF038dda, 0xFF0599e6, 0xFF059ce1, 0xFF049edd, 0xFF05a6e1, + 0xFF00a7de, 0xFF1fb6ee, 0xFF39bdf7, 0xFF38bcf6, 0xFF24b5fc, 0xFFbfe8b9, 0xFFfafea2, 0xFFfbfca5, + 0xFFfcfaa8, 0xFFfcfca7, 0xFFfdfda6, 0xFFfbfca3, 0xFFf9fb9f, 0xFFf6f795, 0xFFfafb92, 0xFFfbfb8b, + 0xFFfbfb85, 0xFFfafa79, 0xFFfafa6d, 0xFFf9f961, 0xFFf8f956, 0xFFf9f64c, 0xFFf9f442, 0xFFf5ec39, + 0xFFf2e531, 0xFFefde28, 0xFFecd620, 0xFFeed900, 0xFF32a6e5, 0xFF19a4ff, 0xFF29a4f4, 0xFF20a2f4, + 0xFF18a0f5, 0xFF179ef4, 0xFF159df4, 0xFF139bf3, 0xFF1199f2, 0xFF129af2, 0xFF129af3, 0xFF129af3, + 0xFF5bd1f5, 0xFF63dffa, 0xFF318dcc, 0xFF062d91, 0xFF0e499a, 0xFF00369f, 0xFF003897, 0xFF155fb6, + 0xFF53aad9, 0xFF31a6e2, 0xFF45bcef, 0xFF6dddff, 0xFF76defa, 0xFF6dd9f9, 0xFF64d5f9, 0xFF54c5f3, + 0xFF45b5ed, 0xFF238ed6, 0xFF1277ce, 0xFF006cc6, 0xFF0282de, 0xFF0187db, 0xFF008dd7, 0xFF079be1, + 0xFF0099dc, 0xFF22b1f0, 0xFF36baf4, 0xFF3cbcf4, 0xFF1cb5ff, 0xFFfffe89, 0xFFfbff96, 0xFFfbfc98, + 0xFFfbf99a, 0xFFfcfb98, 0xFFfdfd96, 0xFFfafb90, 0xFFf6f98a, 0xFFf7f984, 0xFFf8fa7f, 0xFFfafa7a, + 0xFFfbfb75, 0xFFfafa6a, 0xFFf9f960, 0xFFf8f855, 0xFFf7f84a, 0xFFf7f540, 0xFFf8f336, 0xFFf4eb2f, + 0xFFf0e328, 0xFFf0da24, 0xFFf0d121, 0xFFe9ca24, 0xFF049bff, 0xFF20a3f6, 0xFF16a1f7, 0xFF16a0f7, + 0xFF169ef7, 0xFF159df6, 0xFF149cf5, 0xFF139bf4, 0xFF129af3, 0xFF129af3, 0xFF129af3, 0xFF129af3, + 0xFF5ae3ff, 0xFF64d8ff, 0xFF0d4798, 0xFF002682, 0xFF1d6bb7, 0xFF3aa2de, 0xFF5fe5ff, 0xFF52d8fd, + 0xFF4dd6f6, 0xFF48ccf5, 0xFF5fd0f6, 0xFF68d9ff, 0xFF61d3f8, 0xFF5bd2f8, 0xFF42cbff, 0xFF53cefe, + 0xFF51cff5, 0xFF49caf6, 0xFF4acdff, 0xFF40baff, 0xFF0e7edb, 0xFF0069c2, 0xFF0584da, 0xFF0184d5, + 0xFF068cd8, 0xFF38bef8, 0xFF3abef7, 0xFF35beff, 0xFF62c7e2, 0xFFfbf379, 0xFFf8fa83, 0xFFf9f983, + 0xFFfaf884, 0xFFf9f77f, 0xFFf7f77b, 0xFFf8f979, 0xFFf9fa77, 0xFFf8f972, 0xFFf7f86c, 0xFFfcfc6c, + 0xFFf9f864, 0xFFf8f85b, 0xFFf8f752, 0xFFf7f649, 0xFFf6f53f, 0xFFf5f237, 0xFFf4ef2f, 0xFFf1e628, + 0xFFeede20, 0xFFead61f, 0xFFf2cc11, 0xFF9db96c, 0xFF0c9ffe, 0xFF1ba3f9, 0xFF17a2f9, 0xFF17a0f9, + 0xFF169ef8, 0xFF169df7, 0xFF159cf6, 0xFF149bf5, 0xFF139af5, 0xFF139af5, 0xFF139af5, 0xFF139af5, + 0xFF60d8f9, 0xFF5bd9f8, 0xFF4cadd7, 0xFF69ddff, 0xFF56ddf8, 0xFF55d6fc, 0xFF55d0ff, 0xFF5cd5ff, + 0xFF53cbf2, 0xFF4bcaf6, 0xFF43cafa, 0xFF47c9f8, 0xFF4cc8f6, 0xFF5ccff1, 0xFF46ccf8, 0xFF55caff, + 0xFF3ec4fa, 0xFF43c3fb, 0xFF48c2fd, 0xFF3ebff4, 0xFF44ccfb, 0xFF37b3fc, 0xFF0b7bdd, 0xFF006dc9, + 0xFF0d80d4, 0xFF4eccff, 0xFF3ec3fa, 0xFF2ec2ff, 0xFFa7dea8, 0xFFf8ec5b, 0xFFf5f570, 0xFFf7f66f, + 0xFFfaf76e, 0xFFf5f467, 0xFFf1f060, 0xFFf6f663, 0xFFfbfc65, 0xFFf8f95f, 0xFFf6f659, 0xFFfefe5d, + 0xFFf7f652, 0xFFf7f54c, 0xFFf7f545, 0xFFf6f33d, 0xFFf6f235, 0xFFf3ef2f, 0xFFf1eb29, 0xFFefe221, + 0xFFecd818, 0xFFe5d21a, 0xFFf3c700, 0xFF52a9b4, 0xFF14a4fb, 0xFF15a3fb, 0xFF17a3fc, 0xFF17a1fa, + 0xFF179ff8, 0xFF169df8, 0xFF159cf7, 0xFF159bf7, 0xFF1499f6, 0xFF1499f6, 0xFF1499f6, 0xFF1499f6, + 0xFF58cff2, 0xFF59ddfd, 0xFF55d5f9, 0xFF5ddeff, 0xFF4dcef3, 0xFF4dcbf3, 0xFF4cc8f3, 0xFF56d2fc, + 0xFF59d3fd, 0xFF50cefb, 0xFF47cafa, 0xFF48c9f9, 0xFF49c7f9, 0xFF51cbf6, 0xFF45c9f9, 0xFF4bc8fd, + 0xFF3fc5f9, 0xFF41c4fa, 0xFF43c2fb, 0xFF3bbdf3, 0xFF3ac0f4, 0xFF3ec7fc, 0xFF3ac6fc, 0xFF25a1e3, + 0xFF1f8dd9, 0xFF37b9f7, 0xFF26bbfa, 0xFF2abbf4, 0xFFced857, 0xFFf9fa5b, 0xFFd9db49, 0xFFedec58, + 0xFFfaf560, 0xFFf2ef4d, 0xFFe9ea3b, 0xFFeeef46, 0xFFf2f451, 0xFFf9f34f, 0xFFedf145, 0xFFfef84b, + 0xFFf4f542, 0xFFf5f43d, 0xFFf6f337, 0xFFf5f131, 0xFFf5ef2b, 0xFFf2eb27, 0xFFf0e622, 0xFFeedb1d, + 0xFFecd117, 0xFFf1cc09, 0xFFf5c509, 0xFF0fadff, 0xFF17a1f9, 0xFF18a1f9, 0xFF18a1f8, 0xFF18a0f9, + 0xFF179ff9, 0xFF169df9, 0xFF169cf8, 0xFF159bf8, 0xFF1599f8, 0xFF1599f8, 0xFF1599f8, 0xFF1599f8, + 0xFF60d5fb, 0xFF5bd3fb, 0xFF56d2fb, 0xFF55d1fc, 0xFF55d0fe, 0xFF54d0fa, 0xFF53d1f6, 0xFF51cef7, + 0xFF4ecbf8, 0xFF4dcbf9, 0xFF4ccafb, 0xFF49c8fb, 0xFF47c6fc, 0xFF45c6fb, 0xFF43c6fa, 0xFF41c6fa, + 0xFF40c7f9, 0xFF3fc5f9, 0xFF3ec3f9, 0xFF3fc3fb, 0xFF41c4fd, 0xFF38baf2, 0xFF40c1f8, 0xFF3dc3fb, + 0xFF3bc5fe, 0xFF37c1f6, 0xFF34beef, 0xFF2ebcf0, 0xFFded722, 0xFFbfdc38, 0xFFdee142, 0xFFecea4a, + 0xFFeae442, 0xFFeee942, 0xFFf2ee42, 0xFFeeed3f, 0xFFeaec3d, 0xFFfbee3f, 0xFFe5ec31, 0xFFfff239, + 0xFFf2f531, 0xFFf4f32e, 0xFFf5f12a, 0xFFf5ee25, 0xFFf4ec21, 0xFFf2e71e, 0xFFf0e11c, 0xFFeed519, + 0xFFecc917, 0xFFdec40c, 0xFFbbbe39, 0xFF0798f8, 0xFF1a9ff8, 0xFF1a9ff7, 0xFF1a9ff5, 0xFF189ff7, + 0xFF179ff9, 0xFF179ef9, 0xFF169cf9, 0xFF169bf9, 0xFF1699f9, 0xFF1699f9, 0xFF1699f9, 0xFF1699f9, + 0xFF5cd4f9, 0xFF58d4f9, 0xFF55d3f9, 0xFF56d2fa, 0xFF58d0fb, 0xFF56d0f8, 0xFF54d0f6, 0xFF51cef7, + 0xFF4dccf9, 0xFF4ccbfa, 0xFF4bcafb, 0xFF49c8fb, 0xFF47c7fb, 0xFF45c7fb, 0xFF43c6fa, 0xFF41c6fa, + 0xFF40c6f9, 0xFF3fc4f9, 0xFF3ec3f9, 0xFF3ec2fa, 0xFF3ec2fb, 0xFF3abef5, 0xFF3ec2f8, 0xFF3bc1f9, + 0xFF37c0f9, 0xFF36beff, 0xFF35bbff, 0xFF67bb84, 0xFFb0d219, 0xFFb4d31a, 0xFFd3da39, 0xFFe2dd3d, + 0xFFd6d532, 0xFFe1df38, 0xFFece93e, 0xFFe1e636, 0xFFe9e536, 0xFFf1e634, 0xFFe5e42b, 0xFFf6e62e, + 0xFFe9eb29, 0xFFf0ee2a, 0xFFf0e824, 0xFFece420, 0xFFe9e01d, 0xFFebdb1c, 0xFFedd71c, 0xFFe9ce19, + 0xFFe5c516, 0xFFe7c004, 0xFF6cb292, 0xFF109dfc, 0xFF18a1f7, 0xFF1aa0f5, 0xFF1ca0f3, 0xFF19a0f6, + 0xFF179ff9, 0xFF169ef9, 0xFF169cf9, 0xFF159bf8, 0xFF159af8, 0xFF1499f8, 0xFF1499f7, 0xFF1499f7, + 0xFF58d4f6, 0xFF56d4f6, 0xFF54d5f7, 0xFF57d3f7, 0xFF5bd1f8, 0xFF58d0f6, 0xFF54cff5, 0xFF50cef8, + 0xFF4dcdfa, 0xFF4bcbfb, 0xFF4acafb, 0xFF48c9fb, 0xFF46c7fb, 0xFF45c7fa, 0xFF43c7fa, 0xFF42c6fa, + 0xFF40c6f9, 0xFF3fc4f9, 0xFF3ec3f9, 0xFF3dc1f9, 0xFF3cc0f9, 0xFF3cc1f8, 0xFF3cc2f7, 0xFF38bff6, + 0xFF34bbf5, 0xFF35bdfd, 0xFF37beff, 0xFF46bcfc, 0xFF82c92c, 0xFFa0be02, 0xFFb8c420, 0xFFd8cf31, + 0xFFd2d632, 0xFFd4d52e, 0xFFd7d42a, 0xFFcdd725, 0xFFe9df2f, 0xFFe6dd2a, 0xFFe4dc25, 0xFFedd922, + 0xFFe0e220, 0xFFede927, 0xFFeae01e, 0xFFe4da1c, 0xFFded319, 0xFFe5d01a, 0xFFebcd1b, 0xFFe5c818, + 0xFFdec214, 0xFFf0bc00, 0xFF1da5eb, 0xFF19a1ff, 0xFF16a2f7, 0xFF19a2f4, 0xFF1ea2f1, 0xFF1aa0f5, + 0xFF169ff9, 0xFF169ef8, 0xFF159df8, 0xFF159cf8, 0xFF149bf8, 0xFF139af7, 0xFF1299f6, 0xFF1299f6, + 0xFF5ed5f9, 0xFF63d6fc, 0xFF68d6ff, 0xFF5fd3fc, 0xFF56d0f8, 0xFF53cff8, 0xFF51cef8, 0xFF4ecdf9, + 0xFF4bccfb, 0xFF4acbfb, 0xFF48cafb, 0xFF47c9fa, 0xFF46c8fb, 0xFF44c7fa, 0xFF43c7fa, 0xFF42c6fa, + 0xFF40c5f9, 0xFF3fc4f9, 0xFF3ec3f9, 0xFF3dc1f9, 0xFF3cc0f9, 0xFF3bc1f9, 0xFF3bc1f8, 0xFF38bff7, + 0xFF36bdf7, 0xFF35bdfa, 0xFF34bdfe, 0xFF22c3f6, 0xFF27bbfc, 0xFF53b0b2, 0xFF9bc606, 0xFFc1d322, + 0xFFd3dd36, 0xFFb4ba12, 0xFFc4c71f, 0xFFc5cf22, 0xFFd9d82d, 0xFFdfdb30, 0xFFdcd52b, 0xFFe8d520, + 0xFFd5d51c, 0xFFe8e428, 0xFFece324, 0xFFd1ce1f, 0xFFd3c51d, 0xFFdcc302, 0xFFcfc312, 0xFFe3c209, + 0xFFe3be00, 0xFF84bf6e, 0xFF0ca0f6, 0xFF129ffd, 0xFF18a2f6, 0xFF19a1f5, 0xFF1ba1f4, 0xFF18a0f6, + 0xFF169ff8, 0xFF159ef8, 0xFF159df8, 0xFF149cf7, 0xFF139bf7, 0xFF129af6, 0xFF1098f4, 0xFF1098f4, + 0xFF65d7fb, 0xFF5dd4fa, 0xFF56d2f8, 0xFF53d0f9, 0xFF50cff9, 0xFF4fcef9, 0xFF4dcdfa, 0xFF4bcdfa, + 0xFF4accfb, 0xFF48cbfb, 0xFF47cafb, 0xFF46c9fa, 0xFF45c8fa, 0xFF44c7fa, 0xFF43c7fa, 0xFF42c6fa, + 0xFF40c5fa, 0xFF3fc4f9, 0xFF3ec3f9, 0xFF3dc1f9, 0xFF3bc0f9, 0xFF3ac0f9, 0xFF39c0f9, 0xFF38bff9, + 0xFF37bff9, 0xFF34bef8, 0xFF31bcf7, 0xFF33bbf8, 0xFF35bbfa, 0xFF2cbcff, 0xFF61c2df, 0xFF93cb85, + 0xFFc5d52b, 0xFFcbd82f, 0xFFb0bb13, 0xFFb5be17, 0xFFb9c21b, 0xFFc7c826, 0xFFc5bf21, 0xFFdbc817, + 0xFFcac819, 0xFFdbd722, 0xFFddd61a, 0xFFb7bd0d, 0xFFc8bd04, 0xFFd0c000, 0xFFadc951, 0xFF6cb8b1, + 0xFF04a3ff, 0xFF13a4fb, 0xFF21a4f5, 0xFF1ea3f5, 0xFF1aa1f6, 0xFF19a1f6, 0xFF18a0f7, 0xFF17a0f7, + 0xFF169ff8, 0xFF159ef7, 0xFF149ef7, 0xFF139df7, 0xFF139cf6, 0xFF119af4, 0xFF0f98f2, 0xFF0f98f2, + 0xFF5cd5f9, 0xFF58d3f8, 0xFF53d1f8, 0xFF52d0f9, 0xFF50cff9, 0xFF4ecefa, 0xFF4ccdfa, 0xFF4accfa, + 0xFF48ccfa, 0xFF47cbfa, 0xFF46cafa, 0xFF45c9fa, 0xFF44c8fa, 0xFF43c7fa, 0xFF42c7fa, 0xFF41c6fa, + 0xFF40c5fa, 0xFF3fc4f9, 0xFF3ec2f9, 0xFF3cc1f9, 0xFF3bc0f9, 0xFF3ac0f9, 0xFF38bff9, 0xFF37bff9, + 0xFF36bff9, 0xFF35bdf6, 0xFF34bbf3, 0xFF35b9f7, 0xFF35b8fb, 0xFF22b5ff, 0xFF2fb5ff, 0xFF4dbae6, + 0xFF6bbfce, 0xFF27b1c5, 0xFF6cbc7c, 0xFF8abd49, 0xFFa7be15, 0xFFb9bf09, 0xFFccc000, 0xFFdac43d, + 0xFFbbca20, 0xFFaec73e, 0xFF99bc54, 0xFF5aad8b, 0xFF36abc4, 0xFF04b3ff, 0xFF15a7ff, 0xFF21a4ff, + 0xFF19a0fb, 0xFF1ba2fa, 0xFF1da4f9, 0xFF1ba3f8, 0xFF1aa1f7, 0xFF19a1f7, 0xFF18a0f7, 0xFF17a0f7, + 0xFF169ff8, 0xFF159ef7, 0xFF149ef7, 0xFF139df7, 0xFF129cf6, 0xFF119af5, 0xFF0f99f3, 0xFF0f99f3, + 0xFF53d2f6, 0xFF52d1f7, 0xFF51d1f8, 0xFF50d0f9, 0xFF4fcffa, 0xFF4dcefa, 0xFF4bcdfa, 0xFF49ccfa, + 0xFF47cbfa, 0xFF46caf9, 0xFF45caf9, 0xFF44c9f9, 0xFF44c8fa, 0xFF43c7fa, 0xFF42c6f9, 0xFF41c6f9, + 0xFF40c5fa, 0xFF3fc4f9, 0xFF3dc2f9, 0xFF3cc1f9, 0xFF3ac0f9, 0xFF39c0f9, 0xFF38bff9, 0xFF36bff9, + 0xFF35bef8, 0xFF36bcf4, 0xFF38baf0, 0xFF36b8f6, 0xFF34b5fc, 0xFF2cb6f9, 0xFF23b7f6, 0xFF25b5fa, + 0xFF28b4ff, 0xFF28b6ff, 0xFF29b7ff, 0xFF1fb5ff, 0xFF15b2ff, 0xFF20aef7, 0xFF3cb9ff, 0xFF5acbf0, + 0xFF42befa, 0xFF2ab6fc, 0xFF12adff, 0xFF18acfc, 0xFF1eacfa, 0xFF1ea9fd, 0xFF1ea7ff, 0xFF1ba8fa, + 0xFF18a8f4, 0xFF18a6f8, 0xFF18a4fd, 0xFF19a3fa, 0xFF1aa1f7, 0xFF19a1f7, 0xFF18a0f8, 0xFF17a0f8, + 0xFF169ff8, 0xFF159ef7, 0xFF149df7, 0xFF139cf6, 0xFF129bf6, 0xFF119af5, 0xFF1099f4, 0xFF1099f4, + 0xFF54d1f8, 0xFF52d1f8, 0xFF51d0f9, 0xFF4fcff9, 0xFF4ecffa, 0xFF4ccefa, 0xFF4acdf9, 0xFF48ccf9, + 0xFF45cbf9, 0xFF45caf9, 0xFF44c9f9, 0xFF43c8f9, 0xFF43c8f9, 0xFF42c7f9, 0xFF42c6f9, 0xFF41c5f9, + 0xFF40c5fa, 0xFF3fc4f9, 0xFF3dc2f9, 0xFF3bc1f9, 0xFF3ac0fa, 0xFF38bff9, 0xFF37bff9, 0xFF36bef9, + 0xFF34bef8, 0xFF35bcf6, 0xFF35baf5, 0xFF34b8f8, 0xFF33b6fc, 0xFF2eb6f9, 0xFF29b6f7, 0xFF29b5f8, + 0xFF2ab4fa, 0xFF2ab5fb, 0xFF2ab5fc, 0xFF2ab2f6, 0xFF2aafef, 0xFF1ba9f6, 0xFF9bcfd9, 0xFF6dcfe9, + 0xFF74c7e4, 0xFF80c9dd, 0xFF19adfb, 0xFF1cacf9, 0xFF1fabf8, 0xFF1fa9f9, 0xFF1ea7fb, 0xFF1ca7f9, + 0xFF1aa7f6, 0xFF1aa5f8, 0xFF1aa4fb, 0xFF1aa3fa, 0xFF1aa2f8, 0xFF19a1f8, 0xFF18a0f8, 0xFF17a0f8, + 0xFF169ff8, 0xFF159ef7, 0xFF149df7, 0xFF139cf6, 0xFF129bf6, 0xFF119bf5, 0xFF119af5, 0xFF119af5, + 0xFF55d0f9, 0xFF53d0fa, 0xFF51d0fa, 0xFF4fcffa, 0xFF4dcffa, 0xFF4bcefa, 0xFF49cdf9, 0xFF46ccf9, + 0xFF44caf8, 0xFF43caf8, 0xFF43c9f8, 0xFF43c8f9, 0xFF42c8f9, 0xFF42c7f9, 0xFF41c6f9, 0xFF41c6f9, + 0xFF40c5fa, 0xFF3ec3f9, 0xFF3dc2fa, 0xFF3bc1fa, 0xFF39c0fa, 0xFF38bff9, 0xFF36bff9, 0xFF35bef9, + 0xFF34bdf8, 0xFF33bcf9, 0xFF33bafa, 0xFF32b9fb, 0xFF32b8fc, 0xFF30b7fa, 0xFF2eb6f8, 0xFF2db5f7, + 0xFF2bb4f5, 0xFF2bb4f6, 0xFF2bb3f7, 0xFF29b2f9, 0xFF28b2fc, 0xFF30b2f7, 0xFF12a8fe, 0xFF7fd4e1, + 0xFF58bbe6, 0xFF15aafb, 0xFF1fadf8, 0xFF20acf7, 0xFF20aaf5, 0xFF1fa9f6, 0xFF1ea8f7, 0xFF1da6f7, + 0xFF1ca5f8, 0xFF1ca4f8, 0xFF1ba3f9, 0xFF1ba3f9, 0xFF1ba2f9, 0xFF19a1f9, 0xFF18a0f8, 0xFF17a0f8, + 0xFF169ff8, 0xFF159ef7, 0xFF149df7, 0xFF139cf6, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, + 0xFF55d0f9, 0xFF53d0fa, 0xFF51d0fa, 0xFF4fcffa, 0xFF4dcffa, 0xFF4bcefa, 0xFF49cdf9, 0xFF46ccf9, + 0xFF44caf8, 0xFF43caf8, 0xFF43c9f8, 0xFF43c8f9, 0xFF42c8f9, 0xFF42c7f9, 0xFF41c6f9, 0xFF41c6f9, + 0xFF40c5fa, 0xFF3ec3f9, 0xFF3dc2fa, 0xFF3bc1fa, 0xFF39c0fa, 0xFF38bff9, 0xFF36bff9, 0xFF35bef9, + 0xFF34bdf8, 0xFF33bcf9, 0xFF33bafa, 0xFF32b9fb, 0xFF32b8fc, 0xFF30b7fa, 0xFF2eb6f8, 0xFF2db5f7, + 0xFF2bb4f5, 0xFF2bb4f6, 0xFF2bb3f7, 0xFF2ab2f8, 0xFF29b2fa, 0xFF2db6f5, 0xFF1db5f6, 0xFF239bff, + 0xFF20b6f3, 0xFF0cacfb, 0xFF1eacf7, 0xFF1fabf6, 0xFF20aaf5, 0xFF1fa9f6, 0xFF1ea8f7, 0xFF1da6f7, + 0xFF1ca5f8, 0xFF1ca4f8, 0xFF1ba3f9, 0xFF1ba3f9, 0xFF1ba2f9, 0xFF19a1f9, 0xFF18a0f8, 0xFF17a0f8, + 0xFF169ff8, 0xFF159ef7, 0xFF149df7, 0xFF139cf6, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, + 0xFF55d0f9, 0xFF53d0fa, 0xFF51d0fa, 0xFF4fcffa, 0xFF4dcffa, 0xFF4bcefa, 0xFF49cdf9, 0xFF46ccf9, + 0xFF44caf8, 0xFF43caf8, 0xFF43c9f8, 0xFF43c8f9, 0xFF42c8f9, 0xFF42c7f9, 0xFF41c6f9, 0xFF41c6f9, + 0xFF40c5fa, 0xFF3ec3f9, 0xFF3dc2fa, 0xFF3bc1fa, 0xFF39c0fa, 0xFF38bff9, 0xFF36bff9, 0xFF35bef9, + 0xFF34bdf8, 0xFF33bcf9, 0xFF33bafa, 0xFF32b9fb, 0xFF32b8fc, 0xFF30b7fa, 0xFF2eb6f8, 0xFF2db5f7, + 0xFF2bb4f5, 0xFF2bb4f6, 0xFF2bb3f7, 0xFF2bb2f8, 0xFF2bb1f8, 0xFF22aff9, 0xFF19acfa, 0xFF1eadf7, + 0xFF24aef3, 0xFF20adf5, 0xFF1dabf6, 0xFF1fabf6, 0xFF20aaf5, 0xFF1fa9f6, 0xFF1ea8f7, 0xFF1da6f7, + 0xFF1ca5f8, 0xFF1ca4f8, 0xFF1ba3f9, 0xFF1ba3f9, 0xFF1ba2f9, 0xFF19a1f9, 0xFF18a0f8, 0xFF17a0f8, + 0xFF169ff8, 0xFF159ef7, 0xFF149df7, 0xFF139cf6, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, + 0xFF55d0f9, 0xFF53d0fa, 0xFF51d0fa, 0xFF4fcffa, 0xFF4dcffa, 0xFF4bcefa, 0xFF49cdf9, 0xFF46ccf9, + 0xFF44caf8, 0xFF43caf8, 0xFF43c9f8, 0xFF43c8f9, 0xFF42c8f9, 0xFF42c7f9, 0xFF41c6f9, 0xFF41c6f9, + 0xFF40c5fa, 0xFF3ec3f9, 0xFF3dc2fa, 0xFF3bc1fa, 0xFF39c0fa, 0xFF38bff9, 0xFF36bff9, 0xFF35bef9, + 0xFF34bdf8, 0xFF33bcf9, 0xFF33bafa, 0xFF32b9fb, 0xFF32b8fc, 0xFF30b7fa, 0xFF2eb6f8, 0xFF2db5f7, + 0xFF2bb4f5, 0xFF2bb4f6, 0xFF2bb3f7, 0xFF2bb2f8, 0xFF2bb1f8, 0xFF22aff9, 0xFF19acfa, 0xFF1eadf7, + 0xFF24aef3, 0xFF20adf5, 0xFF1dabf6, 0xFF1fabf6, 0xFF20aaf5, 0xFF1fa9f6, 0xFF1ea8f7, 0xFF1da6f7, + 0xFF1ca5f8, 0xFF1ca4f8, 0xFF1ba3f9, 0xFF1ba3f9, 0xFF1ba2f9, 0xFF19a1f9, 0xFF18a0f8, 0xFF17a0f8, + 0xFF169ff8, 0xFF159ef7, 0xFF149df7, 0xFF139cf6, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5, 0xFF129bf5 +}; + +static int test_bmp_cmp_count(const BYTE* mem1, const BYTE* mem2, size_t size, int channel, + int margin) +{ + int error = 0; + int count = 0; + size /= 4; + mem1 += channel; + mem2 += channel; + + for (size_t index = 0; index < size; index++) + { + if (*mem1 != *mem2) + { + error = (*mem1 > *mem2) ? *mem1 - *mem2 : *mem2 - *mem1; + + if (error > margin) + count++; + } + + mem1 += 4; + mem2 += 4; + } + + return count; +} + +static int test_bmp_cmp_dump(const BYTE* actual, const BYTE* expected, size_t size, int channel, + int margin) +{ + int error[3] = { 0 }; + int count = 0; + size /= 4; + actual += channel; + expected += channel; + + for (size_t index = 0; index < size; index++) + { + if (*actual != *expected) + { + const UINT32 pixel = *((const UINT32*)&actual[-channel]); + const UINT32 ePixel = *((const UINT32*)&expected[-channel]); + const INT16 Y = TEST_Y_COMPONENT[index]; + const INT16 Cb = TEST_CB_COMPONENT[index]; + const INT16 Cr = TEST_CR_COMPONENT[index]; + const size_t x = index % 64; + const size_t y = (index - x) / 64; + BYTE R = 0; + BYTE G = 0; + BYTE B = 0; + BYTE eR = 0; + BYTE eG = 0; + BYTE eB = 0; + + FreeRDPSplitColor(pixel, PIXEL_FORMAT_XRGB32, &R, &G, &B, NULL, NULL); + FreeRDPSplitColor(ePixel, PIXEL_FORMAT_XRGB32, &eR, &eG, &eB, NULL, NULL); + error[0] = (R > eR) ? R - eR : eR - R; + error[1] = (G > eG) ? G - eG : eG - G; + error[2] = (B > eB) ? B - eB : eB - B; + + if ((error[0] > margin) || (error[1] > margin) || (error[2] > margin)) + { + printf("(%2" PRIuz ",%2" PRIuz ") Y: %+5" PRId16 " Cb: %+5" PRId16 + " Cr: %+5" PRId16 " R: %03" PRIu8 "/%03" PRIu8 " G: %03" PRIu8 + "/%03" PRIu8 " B: %03" PRIu8 "/%03" PRIu8 " %d %d %d\n", + x, y, Y, Cb, Cr, R, eR, G, eG, B, eB, R - eR, G - eG, B - eB); + count++; + } + } + + actual += 4; + expected += 4; + } + + return count; +} + +static int test_PrimitivesYCbCr(const primitives_t* prims, UINT32 format, prim_size_t roi, + BOOL compare) +{ + union + { + const INT16** cpi; + INT16** pi; + const UINT16** cpv; + UINT16** pv; + } cnv; + pstatus_t status = -1; + int cnt[3]; + float err[3]; + BYTE* actual = NULL; + BYTE* actual1 = NULL; + const BYTE* expected = (const BYTE*)TEST_XRGB_IMAGE; + int margin = 1; + INT16* pYCbCr[3] = { NULL, NULL, NULL }; + const UINT32 srcStride = roi.width * 2; + const UINT32 dstStride = roi.width * FreeRDPGetBytesPerPixel(format); + const UINT32 srcSize = srcStride * roi.height; + const UINT32 dstSize = dstStride * roi.height; + PROFILER_DEFINE(prof) + PROFILER_DEFINE(prof1) + PROFILER_DEFINE(prof2) + // return test_YCbCr_pixels(); + + actual = winpr_aligned_malloc(dstSize, 16); + actual1 = winpr_aligned_malloc(dstSize, 16); + PROFILER_CREATE(prof, "yCbCrToRGB_16s8u") + PROFILER_CREATE(prof1, "yCbCrToRGB16s16s") + PROFILER_CREATE(prof2, "RGBToRGB_16s8u") + + if (!actual || !actual1) + goto fail; + + ZeroMemory(actual, dstSize); + ZeroMemory(actual1, dstSize); + pYCbCr[0] = winpr_aligned_malloc(srcSize, 16); + pYCbCr[1] = winpr_aligned_malloc(srcSize, 16); + pYCbCr[2] = winpr_aligned_malloc(srcSize, 16); + + if (!pYCbCr[0] || !pYCbCr[1] || !pYCbCr[2]) + goto fail; + + winpr_RAND(pYCbCr[0], srcSize); + winpr_RAND(pYCbCr[1], srcSize); + winpr_RAND(pYCbCr[2], srcSize); + + if (compare) + { + memcpy(pYCbCr[0], TEST_Y_COMPONENT, srcSize); + memcpy(pYCbCr[1], TEST_CB_COMPONENT, srcSize); + memcpy(pYCbCr[2], TEST_CR_COMPONENT, srcSize); + } + + { + PROFILER_ENTER(prof) + cnv.pi = pYCbCr; + status = + prims->yCbCrToRGB_16s8u_P3AC4R(cnv.cpi, srcStride, actual, dstStride, format, &roi); + if (status != PRIMITIVES_SUCCESS) + goto fail; + + PROFILER_EXIT(prof) + } + + { + INT16* pSrcDst[3]; + pSrcDst[0] = winpr_aligned_malloc(srcSize, 16); + pSrcDst[1] = winpr_aligned_malloc(srcSize, 16); + pSrcDst[2] = winpr_aligned_malloc(srcSize, 16); + CopyMemory(pSrcDst[0], pYCbCr[0], srcSize); + CopyMemory(pSrcDst[1], pYCbCr[1], srcSize); + CopyMemory(pSrcDst[2], pYCbCr[2], srcSize); + PROFILER_ENTER(prof1) + cnv.pi = pSrcDst; + status = + prims->yCbCrToRGB_16s16s_P3P3(cnv.cpi, WINPR_ASSERTING_INT_CAST(int, srcStride), + pSrcDst, WINPR_ASSERTING_INT_CAST(int, srcStride), &roi); + PROFILER_EXIT(prof1) + + if (status != PRIMITIVES_SUCCESS) + goto fail2; + + PROFILER_ENTER(prof2) + status = prims->RGBToRGB_16s8u_P3AC4R(cnv.cpi, srcStride, actual1, dstStride, format, &roi); + PROFILER_EXIT(prof2) + fail2: + winpr_aligned_free(pSrcDst[0]); + winpr_aligned_free(pSrcDst[1]); + winpr_aligned_free(pSrcDst[2]); + + if (status != PRIMITIVES_SUCCESS) + goto fail; + } + + if (compare) + { + cnt[2] = test_bmp_cmp_count(actual, expected, dstSize, 2, margin); /* red */ + err[2] = ((float)cnt[2]) / ((float)dstSize / 4.0f) * 100.0f; + cnt[1] = test_bmp_cmp_count(actual, expected, dstSize, 1, margin); /* green */ + err[1] = ((float)cnt[1]) / ((float)dstSize / 4.0f) * 100.0f; + cnt[0] = test_bmp_cmp_count(actual, expected, dstSize, 0, margin); /* blue */ + err[0] = ((float)cnt[0]) / ((float)dstSize / 4.0f) * 100.0f; + + if (cnt[0] || cnt[1] || cnt[2]) + { + printf("Summary information yCbCrToRGB_16s8u_P3AC4R\n"); + printf("Red Error Dump:\n"); + test_bmp_cmp_dump(actual, expected, dstSize, 2, margin); /* red */ + printf("Green Error Dump:\n"); + test_bmp_cmp_dump(actual, expected, dstSize, 1, margin); /* green */ + printf("Blue Error Dump:\n"); + test_bmp_cmp_dump(actual, expected, dstSize, 0, margin); /* blue */ + printf("R: diff: %d (%f%%)\n", cnt[2], err[2]); + printf("G: diff: %d (%f%%)\n", cnt[1], err[1]); + printf("B: diff: %d (%f%%)\n", cnt[0], err[0]); + } + + cnt[2] = test_bmp_cmp_count(actual1, expected, dstSize, 2, margin); /* red */ + err[2] = ((float)cnt[2]) / ((float)dstSize / 4.0f) * 100.0f; + cnt[1] = test_bmp_cmp_count(actual1, expected, dstSize, 1, margin); /* green */ + err[1] = ((float)cnt[1]) / ((float)dstSize / 4.0f) * 100.0f; + cnt[0] = test_bmp_cmp_count(actual1, expected, dstSize, 0, margin); /* blue */ + err[0] = ((float)cnt[0]) / ((float)dstSize / 4.0f) * 100.0f; + + if (cnt[0] || cnt[1] || cnt[2]) + { + printf("Summary information yCbCrToRGB_16s16s_P3P3 & RGBToRGB_16s8u_P3AC4R\n"); + printf("Red Error Dump:\n"); + test_bmp_cmp_dump(actual1, expected, dstSize, 2, margin); /* red */ + printf("Green Error Dump:\n"); + test_bmp_cmp_dump(actual1, expected, dstSize, 1, margin); /* green */ + printf("Blue Error Dump:\n"); + test_bmp_cmp_dump(actual1, expected, dstSize, 0, margin); /* blue */ + printf("R: diff: %d (%f%%)\n", cnt[2], err[2]); + printf("G: diff: %d (%f%%)\n", cnt[1], err[1]); + printf("B: diff: %d (%f%%)\n", cnt[0], err[0]); + } + } + + PROFILER_PRINT_HEADER + PROFILER_PRINT(prof) + PROFILER_PRINT(prof1) + PROFILER_PRINT(prof2) + PROFILER_PRINT_FOOTER +fail: + winpr_aligned_free((BYTE*)pYCbCr[0]); + winpr_aligned_free((BYTE*)pYCbCr[1]); + winpr_aligned_free((BYTE*)pYCbCr[2]); + winpr_aligned_free(actual); + winpr_aligned_free(actual1); + PROFILER_FREE(prof) + PROFILER_FREE(prof1) + PROFILER_FREE(prof2) + return status; +} + +int TestPrimitivesYCbCr(int argc, char* argv[]) +{ + const UINT32 formats[] = { PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_ARGB32, + PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, + PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; + const primitives_t* prims = primitives_get(); + const primitives_t* generics = primitives_get_generic(); + + WINPR_UNUSED(argv); + + if (argc < 2) + { + { + /* Do content comparison. */ + for (UINT32 x = 0; x < sizeof(formats) / sizeof(formats[0]); x++) + { + prim_size_t roi = { 64, 64 }; + int rc = 0; + printf("----------------------- GENERIC %s [%" PRIu32 "x%" PRIu32 + "] COMPARE CONTENT ----\n", + FreeRDPGetColorFormatName(formats[x]), roi.width, roi.height); + rc = test_PrimitivesYCbCr(generics, formats[x], roi, TRUE); + + if (rc != PRIMITIVES_SUCCESS) + return rc; + + printf("------------------------- END %s ----------------------\n", + FreeRDPGetColorFormatName(formats[x])); + printf("---------------------- OPTIMIZED %s [%" PRIu32 "x%" PRIu32 + "] COMPARE CONTENT ----\n", + FreeRDPGetColorFormatName(formats[x]), roi.width, roi.height); + rc = test_PrimitivesYCbCr(prims, formats[x], roi, TRUE); + + if (rc != PRIMITIVES_SUCCESS) + return rc; + + printf("------------------------- END %s ----------------------\n", + FreeRDPGetColorFormatName(formats[x])); + } + } + /* Do random data conversion with random sizes */ + { + prim_size_t roi; + + do + { + winpr_RAND(&roi.width, sizeof(roi.width)); + roi.width %= 2048 / 4; + } while (roi.width < 16); + + do + { + winpr_RAND(&roi.height, sizeof(roi.height)); + roi.height %= 2048 / 4; + } while (roi.height < 16); + + for (size_t x = 0; x < sizeof(formats) / sizeof(formats[0]); x++) + { + int rc = 0; + printf("----------------------- GENERIC %s [%" PRIu32 "x%" PRIu32 + "] COMPARE CONTENT ----\n", + FreeRDPGetColorFormatName(formats[x]), roi.width, roi.height); + rc = test_PrimitivesYCbCr(generics, formats[x], roi, FALSE); + + if (rc != PRIMITIVES_SUCCESS) + return rc; + + printf("------------------------- END %s ----------------------\n", + FreeRDPGetColorFormatName(formats[x])); + printf("---------------------- OPTIMIZED %s [%" PRIu32 "x%" PRIu32 + "] COMPARE CONTENT ----\n", + FreeRDPGetColorFormatName(formats[x]), roi.width, roi.height); + rc = test_PrimitivesYCbCr(prims, formats[x], roi, FALSE); + + if (rc != PRIMITIVES_SUCCESS) + return rc; + + printf("------------------------- END %s ----------------------\n", + FreeRDPGetColorFormatName(formats[x])); + } + } + } + /* Do a performance run with full HD */ + else + { + prim_size_t roi = { 1928 / 8, 1080 / 8 }; + + for (size_t x = 0; x < sizeof(formats) / sizeof(formats[0]); x++) + { + int rc = 0; + printf("----------------------- GENERIC %s [%" PRIu32 "x%" PRIu32 + "] COMPARE CONTENT ----\n", + FreeRDPGetColorFormatName(formats[x]), roi.width, roi.height); + rc = test_PrimitivesYCbCr(generics, formats[x], roi, FALSE); + + if (rc != PRIMITIVES_SUCCESS) + return rc; + + printf("------------------------- END %s ----------------------\n", + FreeRDPGetColorFormatName(formats[x])); + printf("---------------------- OPTIMIZED %s [%" PRIu32 "x%" PRIu32 + "] COMPARE CONTENT ----\n", + FreeRDPGetColorFormatName(formats[x]), roi.width, roi.height); + rc = test_PrimitivesYCbCr(prims, formats[x], roi, FALSE); + + if (rc != PRIMITIVES_SUCCESS) + return rc; + + printf("------------------------- END %s ----------------------\n", + FreeRDPGetColorFormatName(formats[x])); + } + } + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYCoCg.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYCoCg.c new file mode 100644 index 0000000000000000000000000000000000000000..a31d5ebfc0a55d58be501b582c83f3e9cd6cfb13 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYCoCg.c @@ -0,0 +1,147 @@ +/* test_YCoCg.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2014 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include "prim_test.h" +#include + +/* ------------------------------------------------------------------------- */ +static BOOL test_YCoCgRToRGB_8u_AC4R_func(UINT32 width, UINT32 height) +{ + pstatus_t status = -1; + BYTE* out_sse = NULL; + BYTE* in = NULL; + BYTE* out_c = NULL; + const UINT32 srcStride = width * 4; + const UINT32 size = srcStride * height; + const UINT32 formats[] = { PIXEL_FORMAT_ARGB32, PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32, + PIXEL_FORMAT_RGBX32, PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; + PROFILER_DEFINE(genericProf) + PROFILER_DEFINE(optProf) + in = winpr_aligned_calloc(1, size, 16); + out_c = winpr_aligned_calloc(1, size, 16); + out_sse = winpr_aligned_calloc(1, size, 16); + + if (!in || !out_c || !out_sse) + goto fail; + + winpr_RAND(in, size); + + for (size_t x = 0; x < sizeof(formats) / sizeof(formats[0]); x++) + { + const UINT32 format = formats[x]; + const UINT32 dstStride = width * FreeRDPGetBytesPerPixel(format); + const char* formatName = FreeRDPGetColorFormatName(format); + PROFILER_CREATE(genericProf, "YCoCgRToRGB_8u_AC4R-GENERIC") + PROFILER_CREATE(optProf, "YCoCgRToRGB_8u_AC4R-OPT") + PROFILER_ENTER(genericProf) + status = generic->YCoCgToRGB_8u_AC4R(in, WINPR_ASSERTING_INT_CAST(int, srcStride), out_c, + format, WINPR_ASSERTING_INT_CAST(int, dstStride), + width, height, 2, TRUE); + PROFILER_EXIT(genericProf) + + if (status != PRIMITIVES_SUCCESS) + goto loop_fail; + + PROFILER_ENTER(optProf) + status = optimized->YCoCgToRGB_8u_AC4R( + in, WINPR_ASSERTING_INT_CAST(int, srcStride), out_sse, format, + WINPR_ASSERTING_INT_CAST(int, dstStride), width, height, 2, TRUE); + PROFILER_EXIT(optProf) + + if (status != PRIMITIVES_SUCCESS) + goto loop_fail; + + if (memcmp(out_c, out_sse, 1ULL * dstStride * height) != 0) + { + for (size_t i = 0; i < 1ull * width * height; ++i) + { + const UINT32 c = FreeRDPReadColor(out_c + 4 * i, format); + const UINT32 sse = FreeRDPReadColor(out_sse + 4 * i, format); + + if (c != sse) + { + printf("optimized->YCoCgRToRGB FAIL[%s] [%" PRIuz "]: 0x%08" PRIx32 + " -> C 0x%08" PRIx32 " vs optimized 0x%08" PRIx32 "\n", + formatName, i, in[i + 1], c, sse); + status = -1; + } + } + } + + printf("--------------------------- [%s] [%" PRIu32 "x%" PRIu32 + "] ---------------------------\n", + formatName, width, height); + PROFILER_PRINT_HEADER + PROFILER_PRINT(genericProf) + PROFILER_PRINT(optProf) + PROFILER_PRINT_FOOTER + loop_fail: + PROFILER_FREE(genericProf) + PROFILER_FREE(optProf) + + if (status != PRIMITIVES_SUCCESS) + goto fail; + } + +fail: + winpr_aligned_free(in); + winpr_aligned_free(out_c); + winpr_aligned_free(out_sse); + return status == PRIMITIVES_SUCCESS; +} + +int TestPrimitivesYCoCg(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + prim_test_setup(FALSE); + + /* Random resolution tests */ + if (argc < 2) + { + for (UINT32 x = 0; x < 10; x++) + { + UINT32 w = 0; + UINT32 h = 0; + + do + { + winpr_RAND(&w, sizeof(w)); + w %= 2048 / 4; + } while (w < 16); + + do + { + winpr_RAND(&h, sizeof(h)); + h %= 2048 / 4; + } while (h < 16); + + if (!test_YCoCgRToRGB_8u_AC4R_func(w, h)) + return 1; + } + } + + /* Test once with full HD/4 */ + if (!test_YCoCgRToRGB_8u_AC4R_func(1920 / 4, 1080 / 4)) + return 1; + + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYUV.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYUV.c new file mode 100644 index 0000000000000000000000000000000000000000..4f808615d789ad5216cb200af1f7f7295fcb8fde --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/TestPrimitivesYUV.c @@ -0,0 +1,1440 @@ + +#include + +#include +#include + +#include "prim_test.h" + +#include + +#include +#include +#include +#include + +#include "../prim_internal.h" + +#define TAG __FILE__ + +#define PADDING_FILL_VALUE 0x37 + +/* YUV to RGB conversion is lossy, so consider every value only + * differing by less than 2 abs equal. */ +static BOOL similar(const BYTE* src, const BYTE* dst, size_t size) +{ + for (size_t x = 0; x < size; x++) + { + int diff = src[x] - dst[x]; + + if (abs(diff) > 4) + { + (void)fprintf(stderr, "%" PRIuz " %02" PRIX8 " : %02" PRIX8 " diff=%d\n", x, src[x], + dst[x], abs(diff)); + return FALSE; + } + } + + return TRUE; +} + +static BOOL similarRGB(size_t y, const BYTE* src, const BYTE* dst, size_t size, UINT32 format, + BOOL use444) +{ + const UINT32 bpp = FreeRDPGetBytesPerPixel(format); + BYTE fill = PADDING_FILL_VALUE; + if (!FreeRDPColorHasAlpha(format)) + fill = 0xFF; + + for (size_t x = 0; x < size; x++) + { + const LONG maxDiff = 4; + UINT32 sColor = 0; + UINT32 dColor = 0; + BYTE sR = 0; + BYTE sG = 0; + BYTE sB = 0; + BYTE sA = 0; + BYTE dR = 0; + BYTE dG = 0; + BYTE dB = 0; + BYTE dA = 0; + sColor = FreeRDPReadColor(src, format); + dColor = FreeRDPReadColor(dst, format); + src += bpp; + dst += bpp; + FreeRDPSplitColor(sColor, format, &sR, &sG, &sB, &sA, NULL); + FreeRDPSplitColor(dColor, format, &dR, &dG, &dB, &dA, NULL); + + const long diffr = labs(1L * sR - dR); + const long diffg = labs(1L * sG - dG); + const long diffb = labs(1L * sB - dB); + if ((diffr > maxDiff) || (diffg > maxDiff) || (diffb > maxDiff)) + { + /* AVC444 uses an averaging filter for luma pixel U/V and reverses it in YUV444 -> RGB + * this is lossy and does not handle all combinations well so the 2x,2y pixel can be + * quite different after RGB -> YUV444 -> RGB conversion. + * + * skip these pixels to avoid failing the test + */ + if (use444 && ((x % 2) == 0) && ((y % 2) == 0)) + { + continue; + } + + const BYTE sY = RGB2Y(sR, sG, sB); + const BYTE sU = RGB2U(sR, sG, sB); + const BYTE sV = RGB2V(sR, sG, sB); + const BYTE dY = RGB2Y(dR, dG, dB); + const BYTE dU = RGB2U(dR, dG, dB); + const BYTE dV = RGB2V(dR, dG, dB); + (void)fprintf(stderr, + "[%s] Color value mismatch R[%02X %02X], G[%02X %02X], B[%02X %02X] at " + "position %" PRIuz "\n", + use444 ? "AVC444" : "AVC420", sR, dR, sG, dG, sA, dA, x); + (void)fprintf(stderr, + "[%s] Color value mismatch Y[%02X %02X], U[%02X %02X], V[%02X %02X] at " + "position %" PRIuz "\n", + use444 ? "AVC444" : "AVC420", sY, dY, sU, dU, sV, dV, x); + return FALSE; + } + + if (dA != fill) + { + (void)fprintf( + stderr, + "[%s] Invalid destination alpha value 0x%02X [expected 0x%02X] at position %" PRIuz + "\n", + use444 ? "AVC444" : "AVC420", dA, fill, x); + return FALSE; + } + } + + return TRUE; +} + +static void get_size(BOOL large, UINT32* width, UINT32* height) +{ + UINT32 shift = large ? 8 : 1; + winpr_RAND(width, sizeof(*width)); + winpr_RAND(height, sizeof(*height)); + *width = (*width % 64 + 1) << shift; + *height = (*height % 64 + 1); +} + +static BOOL check_padding(const BYTE* psrc, size_t size, size_t padding, const char* buffer) +{ + BOOL rc = TRUE; + const BYTE* src = NULL; + const BYTE* esrc = NULL; + size_t halfPad = (padding + 1) / 2; + + if (!psrc) + return FALSE; + + src = psrc - halfPad; + esrc = src + size + halfPad; + + for (size_t x = 0; x < halfPad; x++) + { + const BYTE s = *src++; + const BYTE d = *esrc++; + + if (s != 'A') + { + size_t start = x; + + while ((x < halfPad) && (*esrc++ != 'A')) + x++; + + (void)fprintf(stderr, + "Buffer underflow detected %02" PRIx8 " != %02X %s [%" PRIuz "-%" PRIuz + "]\n", + d, 'A', buffer, start, x); + return FALSE; + } + + if (d != 'A') + { + size_t start = x; + + while ((x < halfPad) && (*esrc++ != 'A')) + x++; + + (void)fprintf(stderr, + "Buffer overflow detected %02" PRIx8 " != %02X %s [%" PRIuz "-%" PRIuz + "]\n", + d, 'A', buffer, start, x); + return FALSE; + } + } + + return rc; +} + +static void* set_padding(size_t size, size_t padding) +{ + size_t halfPad = (padding + 1) / 2; + BYTE* psrc = NULL; + BYTE* src = winpr_aligned_malloc(size + 2 * halfPad, 16); + + if (!src) + return NULL; + + memset(&src[0], 'A', halfPad); + memset(&src[halfPad], PADDING_FILL_VALUE, size); + memset(&src[halfPad + size], 'A', halfPad); + psrc = &src[halfPad]; + + if (!check_padding(psrc, size, padding, "init")) + { + winpr_aligned_free(src); + return NULL; + } + + return psrc; +} + +static void free_padding(void* src, size_t padding) +{ + BYTE* ptr = NULL; + + if (!src) + return; + + ptr = ((BYTE*)src) - (padding + 1) / 2; + winpr_aligned_free(ptr); +} + +/* Create 2 pseudo YUV420 frames of same size. + * Combine them and check, if the data is at the expected position. */ +static BOOL TestPrimitiveYUVCombine(primitives_t* prims, prim_size_t roi) +{ + union + { + const BYTE** cpv; + BYTE** pv; + } cnv; + size_t awidth = 0; + size_t aheight = 0; + BOOL rc = FALSE; + BYTE* luma[3] = { 0 }; + BYTE* chroma[3] = { 0 }; + BYTE* yuv[3] = { 0 }; + BYTE* pmain[3] = { 0 }; + BYTE* paux[3] = { 0 }; + UINT32 lumaStride[3] = { 0 }; + UINT32 chromaStride[3] = { 0 }; + UINT32 yuvStride[3] = { 0 }; + const size_t padding = 10000; + RECTANGLE_16 rect = { 0 }; + PROFILER_DEFINE(yuvCombine) + PROFILER_DEFINE(yuvSplit) + + // TODO: we only support even height values at the moment + if (roi.height % 2) + roi.height++; + + awidth = roi.width + 16 - roi.width % 16; + aheight = roi.height + 16 - roi.height % 16; + (void)fprintf(stderr, + "Running YUVCombine on frame size %" PRIu32 "x%" PRIu32 " [%" PRIu32 "x%" PRIu32 + "]\n", + roi.width, roi.height, awidth, aheight); + PROFILER_CREATE(yuvCombine, "YUV420CombineToYUV444") + PROFILER_CREATE(yuvSplit, "YUV444SplitToYUV420") + rect.left = 0; + rect.top = 0; + rect.right = roi.width; + rect.bottom = roi.height; + + if (!prims || !prims->YUV420CombineToYUV444) + goto fail; + + for (UINT32 x = 0; x < 3; x++) + { + size_t halfStride = ((x > 0) ? awidth / 2 : awidth); + size_t size = aheight * awidth; + size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight); + yuvStride[x] = awidth; + + if (!(yuv[x] = set_padding(size, padding))) + goto fail; + + lumaStride[x] = halfStride; + + if (!(luma[x] = set_padding(halfSize, padding))) + goto fail; + + if (!(pmain[x] = set_padding(halfSize, padding))) + goto fail; + + chromaStride[x] = halfStride; + + if (!(chroma[x] = set_padding(halfSize, padding))) + goto fail; + + if (!(paux[x] = set_padding(halfSize, padding))) + goto fail; + + memset(luma[x], WINPR_ASSERTING_INT_CAST(int, 0xAB + 3 * x), halfSize); + memset(chroma[x], WINPR_ASSERTING_INT_CAST(int, 0x80 + 2 * x), halfSize); + + if (!check_padding(luma[x], halfSize, padding, "luma")) + goto fail; + + if (!check_padding(chroma[x], halfSize, padding, "chroma")) + goto fail; + + if (!check_padding(pmain[x], halfSize, padding, "main")) + goto fail; + + if (!check_padding(paux[x], halfSize, padding, "aux")) + goto fail; + + if (!check_padding(yuv[x], size, padding, "yuv")) + goto fail; + } + + PROFILER_ENTER(yuvCombine) + + cnv.pv = luma; + if (prims->YUV420CombineToYUV444(AVC444_LUMA, cnv.cpv, lumaStride, roi.width, roi.height, yuv, + yuvStride, &rect) != PRIMITIVES_SUCCESS) + { + PROFILER_EXIT(yuvCombine) + goto fail; + } + + cnv.pv = chroma; + if (prims->YUV420CombineToYUV444(AVC444_CHROMAv1, cnv.cpv, chromaStride, roi.width, roi.height, + yuv, yuvStride, &rect) != PRIMITIVES_SUCCESS) + { + PROFILER_EXIT(yuvCombine) + goto fail; + } + + PROFILER_EXIT(yuvCombine) + + for (size_t x = 0; x < 3; x++) + { + size_t halfStride = ((x > 0) ? awidth / 2 : awidth); + size_t size = 1ULL * aheight * awidth; + size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight); + + if (!check_padding(luma[x], halfSize, padding, "luma")) + goto fail; + + if (!check_padding(chroma[x], halfSize, padding, "chroma")) + goto fail; + + if (!check_padding(yuv[x], size, padding, "yuv")) + goto fail; + } + + PROFILER_ENTER(yuvSplit) + + cnv.pv = yuv; + if (prims->YUV444SplitToYUV420(cnv.cpv, yuvStride, pmain, lumaStride, paux, chromaStride, + &roi) != PRIMITIVES_SUCCESS) + { + PROFILER_EXIT(yuvSplit) + goto fail; + } + + PROFILER_EXIT(yuvSplit) + + for (UINT32 x = 0; x < 3; x++) + { + size_t halfStride = ((x > 0) ? awidth / 2 : awidth); + size_t size = aheight * awidth; + size_t halfSize = ((x > 0) ? halfStride * aheight / 2 : awidth * aheight); + + if (!check_padding(pmain[x], halfSize, padding, "main")) + goto fail; + + if (!check_padding(paux[x], halfSize, padding, "aux")) + goto fail; + + if (!check_padding(yuv[x], size, padding, "yuv")) + goto fail; + } + + for (size_t i = 0; i < 3; i++) + { + for (size_t y = 0; y < roi.height; y++) + { + UINT32 w = roi.width; + UINT32 lstride = lumaStride[i]; + UINT32 cstride = chromaStride[i]; + + if (i > 0) + { + w = (roi.width + 3) / 4; + + if (roi.height > (roi.height + 1) / 2) + continue; + } + + if (!similar(luma[i] + y * lstride, pmain[i] + y * lstride, w)) + goto fail; + + /* Need to ignore lines of destination Y plane, + * if the lines are not a multiple of 16 + * as the UV planes are packed in 8 line stripes. */ + if (i == 0) + { + /* TODO: This check is not perfect, it does not + * include the last V lines packed to the Y + * frame. */ + UINT32 rem = roi.height % 16; + + if (y > roi.height - rem) + continue; + } + + if (!similar(chroma[i] + y * cstride, paux[i] + y * cstride, w)) + goto fail; + } + } + + PROFILER_PRINT_HEADER + PROFILER_PRINT(yuvSplit) + PROFILER_PRINT(yuvCombine) + PROFILER_PRINT_FOOTER + rc = TRUE; +fail: + printf("[%s] run %s.\n", __func__, (rc) ? "SUCCESS" : "FAILED"); + PROFILER_FREE(yuvCombine) + PROFILER_FREE(yuvSplit) + + for (UINT32 x = 0; x < 3; x++) + { + free_padding(yuv[x], padding); + free_padding(luma[x], padding); + free_padding(chroma[x], padding); + free_padding(pmain[x], padding); + free_padding(paux[x], padding); + } + + return rc; +} + +static BOOL TestPrimitiveYUV(primitives_t* prims, prim_size_t roi, BOOL use444) +{ + union + { + const BYTE** cpv; + BYTE** pv; + } cnv; + BOOL res = FALSE; + UINT32 awidth = 0; + UINT32 aheight = 0; + BYTE* yuv[3] = { 0 }; + UINT32 yuv_step[3]; + BYTE* rgb = NULL; + BYTE* rgb_dst = NULL; + size_t size = 0; + size_t uvsize = 0; + size_t uvwidth = 0; + size_t padding = 100ULL * 16ULL; + UINT32 stride = 0; + const UINT32 formats[] = { PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_ARGB32, + PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, + PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; + PROFILER_DEFINE(rgbToYUV420) + PROFILER_DEFINE(rgbToYUV444) + PROFILER_DEFINE(yuv420ToRGB) + PROFILER_DEFINE(yuv444ToRGB) + /* Buffers need to be 16x16 aligned. */ + awidth = roi.width + 16 - roi.width % 16; + aheight = roi.height + 16 - roi.height % 16; + stride = 1ULL * awidth * sizeof(UINT32); + size = 1ULL * awidth * aheight; + + if (use444) + { + uvwidth = awidth; + uvsize = size; + + if (!prims || !prims->RGBToYUV444_8u_P3AC4R || !prims->YUV444ToRGB_8u_P3AC4R) + return FALSE; + } + else + { + uvwidth = (awidth + 1) / 2; + uvsize = (aheight + 1) / 2 * uvwidth; + + if (!prims || !prims->RGBToYUV420_8u_P3AC4R || !prims->YUV420ToRGB_8u_P3AC4R) + return FALSE; + } + + (void)fprintf(stderr, "Running AVC%s on frame size %" PRIu32 "x%" PRIu32 "\n", + use444 ? "444" : "420", roi.width, roi.height); + + /* Test RGB to YUV444 conversion and vice versa */ + if (!(rgb = set_padding(size * sizeof(UINT32), padding))) + goto fail; + + if (!(rgb_dst = set_padding(size * sizeof(UINT32), padding))) + goto fail; + + if (!(yuv[0] = set_padding(size, padding))) + goto fail; + + if (!(yuv[1] = set_padding(uvsize, padding))) + goto fail; + + if (!(yuv[2] = set_padding(uvsize, padding))) + goto fail; + + for (size_t y = 0; y < roi.height; y++) + { + BYTE* line = &rgb[y * stride]; + winpr_RAND(line, stride); + } + + yuv_step[0] = awidth; + yuv_step[1] = uvwidth; + yuv_step[2] = uvwidth; + + for (UINT32 x = 0; x < ARRAYSIZE(formats); x++) + { + pstatus_t rc = 0; + const UINT32 DstFormat = formats[x]; + printf("Testing destination color format %s\n", FreeRDPGetColorFormatName(DstFormat)); + memset(rgb_dst, PADDING_FILL_VALUE, size * sizeof(UINT32)); + + PROFILER_CREATE(rgbToYUV420, "RGBToYUV420") + PROFILER_CREATE(rgbToYUV444, "RGBToYUV444") + PROFILER_CREATE(yuv420ToRGB, "YUV420ToRGB") + PROFILER_CREATE(yuv444ToRGB, "YUV444ToRGB") + + if (use444) + { + PROFILER_ENTER(rgbToYUV444) + rc = prims->RGBToYUV444_8u_P3AC4R(rgb, DstFormat, stride, yuv, yuv_step, &roi); + PROFILER_EXIT(rgbToYUV444) + + if (rc != PRIMITIVES_SUCCESS) + goto loop_fail; + + PROFILER_PRINT_HEADER + PROFILER_PRINT(rgbToYUV444) + PROFILER_PRINT_FOOTER + } + else + { + PROFILER_ENTER(rgbToYUV420) + rc = prims->RGBToYUV420_8u_P3AC4R(rgb, DstFormat, stride, yuv, yuv_step, &roi); + PROFILER_EXIT(rgbToYUV420) + + if (rc != PRIMITIVES_SUCCESS) + goto loop_fail; + + PROFILER_PRINT_HEADER + PROFILER_PRINT(rgbToYUV420) + PROFILER_PRINT_FOOTER + } + + if (!check_padding(rgb, size * sizeof(UINT32), padding, "rgb")) + { + rc = -1; + goto loop_fail; + } + + if ((!check_padding(yuv[0], size, padding, "Y")) || + (!check_padding(yuv[1], uvsize, padding, "U")) || + (!check_padding(yuv[2], uvsize, padding, "V"))) + { + rc = -1; + goto loop_fail; + } + + cnv.pv = yuv; + if (use444) + { + PROFILER_ENTER(yuv444ToRGB) + rc = prims->YUV444ToRGB_8u_P3AC4R(cnv.cpv, yuv_step, rgb_dst, stride, DstFormat, &roi); + PROFILER_EXIT(yuv444ToRGB) + + if (rc != PRIMITIVES_SUCCESS) + goto loop_fail; + + loop_fail: + PROFILER_EXIT(yuv444ToRGB) + PROFILER_PRINT_HEADER + PROFILER_PRINT(yuv444ToRGB) + PROFILER_PRINT_FOOTER + + if (rc != PRIMITIVES_SUCCESS) + goto fail; + } + else + { + PROFILER_ENTER(yuv420ToRGB) + + if (prims->YUV420ToRGB_8u_P3AC4R(cnv.cpv, yuv_step, rgb_dst, stride, DstFormat, &roi) != + PRIMITIVES_SUCCESS) + { + PROFILER_EXIT(yuv420ToRGB) + goto fail; + } + + PROFILER_EXIT(yuv420ToRGB) + PROFILER_PRINT_HEADER + PROFILER_PRINT(yuv420ToRGB) + PROFILER_PRINT_FOOTER + } + + if (!check_padding(rgb_dst, size * sizeof(UINT32), padding, "rgb dst")) + goto fail; + + if ((!check_padding(yuv[0], size, padding, "Y")) || + (!check_padding(yuv[1], uvsize, padding, "U")) || + (!check_padding(yuv[2], uvsize, padding, "V"))) + goto fail; + +#if 0 // TODO: lossy conversion, we have a lot of outliers that prevent the check to pass + for (size_t y = 0; y < roi.height; y++) + { + BYTE* srgb = &rgb[y * stride]; + BYTE* drgb = &rgb_dst[y * stride]; + + if (!similarRGB(y, srgb, drgb, roi.width, DstFormat, use444)) + goto fail; + } +#endif + + PROFILER_FREE(rgbToYUV420) + PROFILER_FREE(rgbToYUV444) + PROFILER_FREE(yuv420ToRGB) + PROFILER_FREE(yuv444ToRGB) + } + + res = TRUE; +fail: + printf("[%s] run %s.\n", __func__, (res) ? "SUCCESS" : "FAILED"); + free_padding(rgb, padding); + free_padding(rgb_dst, padding); + free_padding(yuv[0], padding); + free_padding(yuv[1], padding); + free_padding(yuv[2], padding); + return res; +} + +static BOOL allocate_yuv420(BYTE** planes, UINT32 width, UINT32 height, UINT32 padding) +{ + const size_t size = 1ULL * width * height; + const size_t uvwidth = (1ULL + width) / 2; + const size_t uvsize = (1ULL + height) / 2 * uvwidth; + + if (!(planes[0] = set_padding(size, padding))) + goto fail; + + if (!(planes[1] = set_padding(uvsize, padding))) + goto fail; + + if (!(planes[2] = set_padding(uvsize, padding))) + goto fail; + + return TRUE; +fail: + free_padding(planes[0], padding); + free_padding(planes[1], padding); + free_padding(planes[2], padding); + return FALSE; +} + +static void free_yuv420(BYTE** planes, UINT32 padding) +{ + if (!planes) + return; + + free_padding(planes[0], padding); + free_padding(planes[1], padding); + free_padding(planes[2], padding); + planes[0] = NULL; + planes[1] = NULL; + planes[2] = NULL; +} + +static BOOL check_yuv420(BYTE** planes, UINT32 width, UINT32 height, UINT32 padding) +{ + const size_t size = 1ULL * width * height; + const size_t uvwidth = (width + 1) / 2; + const size_t uvsize = (height + 1) / 2 * uvwidth; + const BOOL yOk = check_padding(planes[0], size, padding, "Y"); + const BOOL uOk = check_padding(planes[1], uvsize, padding, "U"); + const BOOL vOk = check_padding(planes[2], uvsize, padding, "V"); + return (yOk && uOk && vOk); +} + +static BOOL check_for_mismatches(const BYTE* planeA, const BYTE* planeB, UINT32 size) +{ + BOOL rc = FALSE; + + for (UINT32 x = 0; x < size; x++) + { + const BYTE a = planeA[x]; + const BYTE b = planeB[x]; + + if (fabsf((float)a - (float)b) > 2.0f) + { + rc = TRUE; + (void)fprintf(stderr, "[%08x] %02x != %02x\n", x, a, b); + } + } + + return rc; +} + +static BOOL compare_yuv420(BYTE** planesA, BYTE** planesB, UINT32 width, UINT32 height, + UINT32 padding) +{ + BOOL rc = TRUE; + const size_t size = 1ULL * width * height; + const size_t uvwidth = (1ULL * width + 1) / 2; + const size_t uvsize = (1ULL * height + 1) / 2 * uvwidth; + + if (check_for_mismatches(planesA[0], planesB[0], size)) + { + (void)fprintf(stderr, "Mismatch in Y planes!\n"); + rc = FALSE; + } + + if (check_for_mismatches(planesA[1], planesB[1], uvsize)) + { + (void)fprintf(stderr, "Mismatch in U planes!\n"); + rc = FALSE; + } + + if (check_for_mismatches(planesA[2], planesB[2], uvsize)) + { + (void)fprintf(stderr, "Mismatch in V planes!\n"); + rc = FALSE; + } + + return rc; +} + +static UINT32 prand(UINT32 max) +{ + UINT32 tmp = 0; + if (max <= 1) + return 1; + winpr_RAND(&tmp, sizeof(tmp)); + return tmp % (max - 1) + 1; +} + +static BOOL TestPrimitiveRgbToLumaChroma(primitives_t* prims, prim_size_t roi, UINT32 version) +{ + BOOL res = FALSE; + UINT32 awidth = 0; + UINT32 aheight = 0; + BYTE* luma[3] = { 0 }; + BYTE* chroma[3] = { 0 }; + BYTE* lumaGeneric[3] = { 0 }; + BYTE* chromaGeneric[3] = { 0 }; + UINT32 yuv_step[3]; + BYTE* rgb = NULL; + size_t size = 0; + size_t uvwidth = 0; + const size_t padding = 0x1000; + UINT32 stride = 0; + __RGBToAVC444YUV_t fkt = NULL; + __RGBToAVC444YUV_t gen = NULL; + const UINT32 formats[] = { PIXEL_FORMAT_XRGB32, PIXEL_FORMAT_XBGR32, PIXEL_FORMAT_ARGB32, + PIXEL_FORMAT_ABGR32, PIXEL_FORMAT_RGBA32, PIXEL_FORMAT_RGBX32, + PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_BGRX32 }; + PROFILER_DEFINE(rgbToYUV444) + PROFILER_DEFINE(rgbToYUV444opt) + /* Buffers need to be 16x16 aligned. */ + awidth = roi.width; + + if (awidth % 16 != 0) + awidth += 16 - roi.width % 16; + + aheight = roi.height; + + if (aheight % 16 != 0) + aheight += 16 - roi.height % 16; + + stride = 1ULL * awidth * sizeof(UINT32); + size = 1ULL * awidth * aheight; + uvwidth = 1ULL * (awidth + 1) / 2; + + if (!prims || !generic) + return FALSE; + + switch (version) + { + case 1: + fkt = prims->RGBToAVC444YUV; + gen = generic->RGBToAVC444YUV; + break; + + case 2: + fkt = prims->RGBToAVC444YUVv2; + gen = generic->RGBToAVC444YUVv2; + break; + + default: + return FALSE; + } + + if (!fkt || !gen) + return FALSE; + + (void)fprintf(stderr, "Running AVC444 on frame size %" PRIu32 "x%" PRIu32 "\n", roi.width, + roi.height); + + /* Test RGB to YUV444 conversion and vice versa */ + if (!(rgb = set_padding(size * sizeof(UINT32), padding))) + goto fail; + + if (!allocate_yuv420(luma, awidth, aheight, padding)) + goto fail; + + if (!allocate_yuv420(chroma, awidth, aheight, padding)) + goto fail; + + if (!allocate_yuv420(lumaGeneric, awidth, aheight, padding)) + goto fail; + + if (!allocate_yuv420(chromaGeneric, awidth, aheight, padding)) + goto fail; + + for (size_t y = 0; y < roi.height; y++) + { + BYTE* line = &rgb[y * stride]; + + winpr_RAND(line, 4ULL * roi.width); + } + + yuv_step[0] = awidth; + yuv_step[1] = uvwidth; + yuv_step[2] = uvwidth; + + for (UINT32 x = 0; x < ARRAYSIZE(formats); x++) + { + pstatus_t rc = -1; + const UINT32 DstFormat = formats[x]; + printf("Testing destination color format %s\n", FreeRDPGetColorFormatName(DstFormat)); + PROFILER_CREATE(rgbToYUV444, "RGBToYUV444-generic") + PROFILER_CREATE(rgbToYUV444opt, "RGBToYUV444-optimized") + + for (UINT32 cnt = 0; cnt < 10; cnt++) + { + PROFILER_ENTER(rgbToYUV444opt) + rc = fkt(rgb, DstFormat, stride, luma, yuv_step, chroma, yuv_step, &roi); + PROFILER_EXIT(rgbToYUV444opt) + + if (rc != PRIMITIVES_SUCCESS) + goto loop_fail; + } + + PROFILER_PRINT_HEADER + PROFILER_PRINT(rgbToYUV444opt) + PROFILER_PRINT_FOOTER + + if (!check_padding(rgb, size * sizeof(UINT32), padding, "rgb")) + { + rc = -1; + goto loop_fail; + } + + if (!check_yuv420(luma, awidth, aheight, padding) || + !check_yuv420(chroma, awidth, aheight, padding)) + { + rc = -1; + goto loop_fail; + } + + for (UINT32 cnt = 0; cnt < 10; cnt++) + { + PROFILER_ENTER(rgbToYUV444) + rc = gen(rgb, DstFormat, stride, lumaGeneric, yuv_step, chromaGeneric, yuv_step, &roi); + PROFILER_EXIT(rgbToYUV444) + + if (rc != PRIMITIVES_SUCCESS) + goto loop_fail; + } + + PROFILER_PRINT_HEADER + PROFILER_PRINT(rgbToYUV444) + PROFILER_PRINT_FOOTER + + if (!check_padding(rgb, size * sizeof(UINT32), padding, "rgb")) + { + rc = -1; + goto loop_fail; + } + + if (!check_yuv420(lumaGeneric, awidth, aheight, padding) || + !check_yuv420(chromaGeneric, awidth, aheight, padding)) + { + rc = -1; + goto loop_fail; + } + + if (!compare_yuv420(luma, lumaGeneric, awidth, aheight, padding) || + !compare_yuv420(chroma, chromaGeneric, awidth, aheight, padding)) + { + rc = -1; + goto loop_fail; + } + + loop_fail: + PROFILER_FREE(rgbToYUV444) + PROFILER_FREE(rgbToYUV444opt) + + if (rc != PRIMITIVES_SUCCESS) + goto fail; + } + + res = TRUE; +fail: + printf("[%s][version %u] run %s.\n", __func__, (unsigned)version, (res) ? "SUCCESS" : "FAILED"); + free_padding(rgb, padding); + free_yuv420(luma, padding); + free_yuv420(chroma, padding); + free_yuv420(lumaGeneric, padding); + free_yuv420(chromaGeneric, padding); + return res; +} + +static BOOL run_tests(prim_size_t roi) +{ + BOOL rc = FALSE; + for (UINT32 type = PRIMITIVES_PURE_SOFT; type <= PRIMITIVES_AUTODETECT; type++) + { + primitives_t* prims = primitives_get_by_type(type); + if (!prims) + { + printf("primitives type %d not supported\n", type); + continue; + } + + for (UINT32 x = 0; x < 5; x++) + { + + printf("-------------------- GENERIC ------------------------\n"); + + if (!TestPrimitiveYUV(prims, roi, TRUE)) + goto fail; + + printf("---------------------- END --------------------------\n"); + printf("-------------------- GENERIC ------------------------\n"); + + if (!TestPrimitiveYUV(prims, roi, FALSE)) + goto fail; + + printf("---------------------- END --------------------------\n"); + printf("-------------------- GENERIC ------------------------\n"); + + if (!TestPrimitiveYUVCombine(prims, roi)) + goto fail; + + printf("---------------------- END --------------------------\n"); + printf("-------------------- GENERIC ------------------------\n"); + + if (!TestPrimitiveRgbToLumaChroma(prims, roi, 1)) + goto fail; + + printf("---------------------- END --------------------------\n"); + printf("-------------------- GENERIC ------------------------\n"); + + if (!TestPrimitiveRgbToLumaChroma(prims, roi, 2)) + goto fail; + + printf("---------------------- END --------------------------\n"); + } + } + rc = TRUE; +fail: + printf("[%s] run %s.\n", __func__, (rc) ? "SUCCESS" : "FAILED"); + return rc; +} + +static void free_yuv(BYTE* yuv[3]) +{ + for (size_t x = 0; x < 3; x++) + { + free(yuv[x]); + yuv[x] = NULL; + } +} + +static BOOL allocate_yuv(BYTE* yuv[3], prim_size_t roi) +{ + yuv[0] = calloc(roi.width, roi.height); + yuv[1] = calloc(roi.width, roi.height); + yuv[2] = calloc(roi.width, roi.height); + + if (!yuv[0] || !yuv[1] || !yuv[2]) + { + free_yuv(yuv); + return FALSE; + } + + winpr_RAND(yuv[0], 1ULL * roi.width * roi.height); + winpr_RAND(yuv[1], 1ULL * roi.width * roi.height); + winpr_RAND(yuv[2], 1ULL * roi.width * roi.height); + return TRUE; +} + +static BOOL yuv444_to_rgb(BYTE* rgb, size_t stride, const BYTE* yuv[3], const UINT32 yuvStep[3], + prim_size_t roi) +{ + for (size_t y = 0; y < roi.height; y++) + { + const BYTE* yline[3] = { + yuv[0] + y * roi.width, + yuv[1] + y * roi.width, + yuv[2] + y * roi.width, + }; + BYTE* line = &rgb[y * stride]; + + for (size_t x = 0; x < roi.width; x++) + { + const BYTE Y = yline[0][x]; + const BYTE U = yline[1][x]; + const BYTE V = yline[2][x]; + const BYTE r = YUV2R(Y, U, V); + const BYTE g = YUV2G(Y, U, V); + const BYTE b = YUV2B(Y, U, V); + writePixelBGRX(&line[x * 4], 4, PIXEL_FORMAT_BGRX32, r, g, b, 0xFF); + } + } +} + +/* Check the result of generic matches the optimized routine. + * + */ +static BOOL compare_yuv444_to_rgb(prim_size_t roi, DWORD type) +{ + BOOL rc = FALSE; + const UINT32 format = PIXEL_FORMAT_BGRA32; + BYTE* yuv[3] = { 0 }; + const UINT32 yuvStep[3] = { roi.width, roi.width, roi.width }; + const size_t stride = 4ULL * roi.width; + + primitives_t* prims = primitives_get_by_type(type); + if (!prims) + { + printf("primitives type %" PRIu32 " not supported, skipping\n", type); + return TRUE; + } + + BYTE* rgb1 = calloc(roi.height, stride); + BYTE* rgb2 = calloc(roi.height, stride); + + primitives_t* soft = primitives_get_by_type(PRIMITIVES_PURE_SOFT); + if (!soft) + goto fail; + if (!allocate_yuv(yuv, roi) || !rgb1 || !rgb2) + goto fail; + + if (soft->YUV444ToRGB_8u_P3AC4R(yuv, yuvStep, rgb1, stride, format, &roi) != PRIMITIVES_SUCCESS) + goto fail; + if (prims->YUV444ToRGB_8u_P3AC4R(yuv, yuvStep, rgb2, stride, format, &roi) != + PRIMITIVES_SUCCESS) + goto fail; + + for (size_t y = 0; y < roi.height; y++) + { + const BYTE* yline[3] = { + yuv[0] + y * roi.width, + yuv[1] + y * roi.width, + yuv[2] + y * roi.width, + }; + const BYTE* line1 = &rgb1[y * stride]; + const BYTE* line2 = &rgb2[y * stride]; + + for (size_t x = 0; x < roi.width; x++) + { + const int Y = yline[0][x]; + const int U = yline[1][x]; + const int V = yline[2][x]; + const UINT32 color1 = FreeRDPReadColor(&line1[x * 4], format); + const UINT32 color2 = FreeRDPReadColor(&line2[x * 4], format); + + BYTE r1 = 0; + BYTE g1 = 0; + BYTE b1 = 0; + FreeRDPSplitColor(color1, format, &r1, &g1, &b1, NULL, NULL); + + BYTE r2 = 0; + BYTE g2 = 0; + BYTE b2 = 0; + FreeRDPSplitColor(color2, format, &r2, &g2, &b2, NULL, NULL); + + const int dr12 = abs(r1 - r2); + const int dg12 = abs(g1 - g2); + const int db12 = abs(b1 - b2); + + if ((dr12 != 0) || (dg12 != 0) || (db12 != 0)) + { + printf("{\n"); + printf("\tdiff 1/2: yuv {%d, %d, %d}, rgb {%d, %d, %d}\n", Y, U, V, dr12, dg12, + db12); + printf("}\n"); + } + + if ((dr12 > 0) || (dg12 > 0) || (db12 > 0)) + { + (void)fprintf(stderr, + "[%" PRIuz "x%" PRIuz + "] generic and optimized data mismatch: r[0x%" PRIx8 "|0x%" PRIx8 + "] g[0x%" PRIx8 "|0x%" PRIx8 "] b[0x%" PRIx8 "|0x%" PRIx8 "]\n", + x, y, r1, r2, g1, g2, b1, b2); + (void)fprintf(stderr, "roi: %dx%d\n", roi.width, roi.height); + winpr_HexDump("y0", WLOG_INFO, &yline[0][x], 16); + winpr_HexDump("y1", WLOG_INFO, &yline[0][x + roi.width], 16); + winpr_HexDump("u0", WLOG_INFO, &yline[1][x], 16); + winpr_HexDump("u1", WLOG_INFO, &yline[1][x + roi.width], 16); + winpr_HexDump("v0", WLOG_INFO, &yline[2][x], 16); + winpr_HexDump("v1", WLOG_INFO, &yline[2][x + roi.width], 16); + winpr_HexDump("foo1", WLOG_INFO, &line1[x * 4], 16); + winpr_HexDump("foo2", WLOG_INFO, &line2[x * 4], 16); + goto fail; + } + } + } + + rc = TRUE; +fail: + printf("%s finished with %s\n", __func__, rc ? "SUCCESS" : "FAILURE"); + free_yuv(yuv); + free(rgb1); + free(rgb2); + + return rc; +} + +/* Check the result of generic matches the optimized routine. + * + */ +static BOOL compare_rgb_to_yuv444(prim_size_t roi, DWORD type) +{ + BOOL rc = FALSE; + const UINT32 format = PIXEL_FORMAT_BGRA32; + const size_t stride = 4ULL * roi.width; + const UINT32 yuvStep[] = { roi.width, roi.width, roi.width }; + BYTE* yuv1[3] = { 0 }; + BYTE* yuv2[3] = { 0 }; + + primitives_t* prims = primitives_get_by_type(type); + if (!prims) + { + printf("primitives type %" PRIu32 " not supported, skipping\n", type); + return TRUE; + } + + BYTE* rgb = calloc(roi.height, stride); + + primitives_t* soft = primitives_get_by_type(PRIMITIVES_PURE_SOFT); + if (!soft || !rgb) + goto fail; + + if (!allocate_yuv(yuv1, roi) || !allocate_yuv(yuv2, roi)) + goto fail; + + if (soft->RGBToYUV444_8u_P3AC4R(rgb, format, stride, yuv1, yuvStep, &roi) != PRIMITIVES_SUCCESS) + goto fail; + if (prims->RGBToYUV444_8u_P3AC4R(rgb, format, stride, yuv2, yuvStep, &roi) != + PRIMITIVES_SUCCESS) + goto fail; + + for (size_t y = 0; y < roi.height; y++) + { + const BYTE* yline1[3] = { + yuv1[0] + y * roi.width, + yuv1[1] + y * roi.width, + yuv1[2] + y * roi.width, + }; + const BYTE* yline2[3] = { + yuv2[0] + y * roi.width, + yuv2[1] + y * roi.width, + yuv2[2] + y * roi.width, + }; + + for (size_t x = 0; x < ARRAYSIZE(yline1); x++) + { + if (memcmp(yline1[x], yline2[x], yuvStep[x]) != 0) + { + (void)fprintf(stderr, "[%s] compare failed in line %" PRIuz, __func__, x); + goto fail; + } + } + } + + rc = TRUE; +fail: + printf("%s finished with %s\n", __func__, rc ? "SUCCESS" : "FAILURE"); + free(rgb); + free_yuv(yuv1); + free_yuv(yuv2); + + return rc; +} + +/* Check the result of generic matches the optimized routine. + * + */ +static BOOL compare_yuv420_to_rgb(prim_size_t roi, DWORD type) +{ + BOOL rc = FALSE; + const UINT32 format = PIXEL_FORMAT_BGRA32; + BYTE* yuv[3] = { 0 }; + const UINT32 yuvStep[3] = { roi.width, roi.width / 2, roi.width / 2 }; + const size_t stride = 4ULL * roi.width; + + primitives_t* prims = primitives_get_by_type(type); + if (!prims) + { + printf("primitives type %" PRIu32 " not supported, skipping\n", type); + return TRUE; + } + + BYTE* rgb1 = calloc(roi.height, stride); + BYTE* rgb2 = calloc(roi.height, stride); + + primitives_t* soft = primitives_get_by_type(PRIMITIVES_PURE_SOFT); + if (!soft) + goto fail; + if (!allocate_yuv(yuv, roi) || !rgb1 || !rgb2) + goto fail; + + if (soft->YUV420ToRGB_8u_P3AC4R(yuv, yuvStep, rgb1, stride, format, &roi) != PRIMITIVES_SUCCESS) + goto fail; + if (prims->YUV420ToRGB_8u_P3AC4R(yuv, yuvStep, rgb2, stride, format, &roi) != + PRIMITIVES_SUCCESS) + goto fail; + + for (size_t y = 0; y < roi.height; y++) + { + const BYTE* yline[3] = { + yuv[0] + y * yuvStep[0], + yuv[1] + y * yuvStep[1], + yuv[2] + y * yuvStep[2], + }; + const BYTE* line1 = &rgb1[y * stride]; + const BYTE* line2 = &rgb2[y * stride]; + + for (size_t x = 0; x < roi.width; x++) + { + const int Y = yline[0][x]; + const int U = yline[1][x / 2]; + const int V = yline[2][x / 2]; + const UINT32 color1 = FreeRDPReadColor(&line1[x * 4], format); + const UINT32 color2 = FreeRDPReadColor(&line2[x * 4], format); + + BYTE r1 = 0; + BYTE g1 = 0; + BYTE b1 = 0; + FreeRDPSplitColor(color1, format, &r1, &g1, &b1, NULL, NULL); + + BYTE r2 = 0; + BYTE g2 = 0; + BYTE b2 = 0; + FreeRDPSplitColor(color2, format, &r2, &g2, &b2, NULL, NULL); + + const int dr12 = abs(r1 - r2); + const int dg12 = abs(g1 - g2); + const int db12 = abs(b1 - b2); + + if ((dr12 != 0) || (dg12 != 0) || (db12 != 0)) + { + printf("{\n"); + printf("\tdiff 1/2: yuv {%d, %d, %d}, rgb {%d, %d, %d}\n", Y, U, V, dr12, dg12, + db12); + printf("}\n"); + } + + if ((dr12 > 0) || (dg12 > 0) || (db12 > 0)) + { + printf("[%s] failed: r[%" PRIx8 "|%" PRIx8 "] g[%" PRIx8 "|%" PRIx8 "] b[%" PRIx8 + "|%" PRIx8 "]\n", + __func__, r1, r2, g1, g2, b1, b2); + goto fail; + } + } + } + + rc = TRUE; +fail: + printf("%s finished with %s\n", __func__, rc ? "SUCCESS" : "FAILURE"); + free_yuv(yuv); + free(rgb1); + free(rgb2); + + return rc; +} + +static BOOL similarYUV(const BYTE* line1, const BYTE* line2, size_t len) +{ + for (size_t x = 0; x < len; x++) + { + const int a = line1[x]; + const int b = line2[x]; + const int diff = abs(a - b); + if (diff >= 2) + return FALSE; + return TRUE; + } +} + +/* Due to optimizations the Y value might be off by +/- 1 */ +static int similarY(const BYTE* a, const BYTE* b, size_t size, size_t type) +{ + switch (type) + { + case 0: + case 1: + case 2: + for (size_t x = 0; x < size; x++) + { + const int ba = a[x]; + const int bb = b[x]; + const int diff = abs(ba - bb); + if (diff > 2) + return diff; + } + return 0; + break; + default: + return memcmp(a, b, size); + } +} +/* Check the result of generic matches the optimized routine. + * + */ +static BOOL compare_rgb_to_yuv420(prim_size_t roi, DWORD type) +{ + BOOL rc = FALSE; + const UINT32 format = PIXEL_FORMAT_BGRA32; + const size_t stride = 4ULL * roi.width; + const UINT32 yuvStep[] = { roi.width, roi.width / 2, roi.width / 2 }; + BYTE* yuv1[3] = { 0 }; + BYTE* yuv2[3] = { 0 }; + + primitives_t* prims = primitives_get_by_type(type); + if (!prims) + { + printf("primitives type %" PRIu32 " not supported, skipping\n", type); + return TRUE; + } + + BYTE* rgb = calloc(roi.height, stride); + BYTE* rgbcopy = calloc(roi.height, stride); + + primitives_t* soft = primitives_get_by_type(PRIMITIVES_PURE_SOFT); + if (!soft || !rgb || !rgbcopy) + goto fail; + + winpr_RAND(rgb, roi.height * stride); + memcpy(rgbcopy, rgb, roi.height * stride); + + if (!allocate_yuv(yuv1, roi) || !allocate_yuv(yuv2, roi)) + goto fail; + + if (soft->RGBToYUV420_8u_P3AC4R(rgb, format, stride, yuv1, yuvStep, &roi) != PRIMITIVES_SUCCESS) + goto fail; + if (memcmp(rgb, rgbcopy, roi.height * stride) != 0) + goto fail; + if (prims->RGBToYUV420_8u_P3AC4R(rgb, format, stride, yuv2, yuvStep, &roi) != + PRIMITIVES_SUCCESS) + goto fail; + + for (size_t y = 0; y < roi.height; y++) + { + // odd lines do produce artefacts in last line, skip check + if (((y + 1) >= roi.height) && ((y % 2) == 0)) + continue; + + const BYTE* yline1[3] = { + &yuv1[0][y * yuvStep[0]], + &yuv1[1][(y / 2) * yuvStep[1]], + &yuv1[2][(y / 2) * yuvStep[2]], + }; + const BYTE* yline2[3] = { + &yuv2[0][y * yuvStep[0]], + &yuv2[1][(y / 2) * yuvStep[1]], + &yuv2[2][(y / 2) * yuvStep[2]], + }; + + for (size_t x = 0; x < ARRAYSIZE(yline1); x++) + { + if (similarY(yline1[x], yline2[x], yuvStep[x], x) != 0) + { + (void)fprintf(stderr, + "[%s] compare failed in component %" PRIuz ", line %" PRIuz "\n", + __func__, x, y); + (void)fprintf(stderr, "[%s] roi %" PRIu32 "x%" PRIu32 "\n", __func__, roi.width, + roi.height); + winpr_HexDump(TAG, WLOG_WARN, yline1[x], yuvStep[x]); + winpr_HexDump(TAG, WLOG_WARN, yline2[x], yuvStep[x]); + winpr_HexDump(TAG, WLOG_WARN, &rgb[y * stride], stride); + goto fail; + } + } + } + + rc = TRUE; +fail: + printf("%s finished with %s\n", __func__, rc ? "SUCCESS" : "FAILURE"); + free(rgb); + free(rgbcopy); + free_yuv(yuv1); + free_yuv(yuv2); + + return rc; +} + +int TestPrimitivesYUV(int argc, char* argv[]) +{ + BOOL large = (argc > 1); + int rc = -1; + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + prim_size_t roi = { 0 }; + + if (argc > 1) + { + // NOLINTNEXTLINE(cert-err34-c) + int crc = sscanf(argv[1], "%" PRIu32 "x%" PRIu32, &roi.width, &roi.height); + + if (crc != 2) + { + roi.width = 1920; + roi.height = 1080; + } + } + else + get_size(large, &roi.width, &roi.height); + + prim_test_setup(FALSE); + + for (UINT32 type = PRIMITIVES_PURE_SOFT; type <= PRIMITIVES_AUTODETECT; type++) + { + if (!compare_yuv444_to_rgb(roi, type)) + goto end; + if (!compare_rgb_to_yuv444(roi, type)) + goto end; + + if (!compare_yuv420_to_rgb(roi, type)) + goto end; + if (!compare_rgb_to_yuv420(roi, type)) + goto end; + } + + if (!run_tests(roi)) + goto end; + + rc = 0; +end: + printf("[%s] finished, status %s [%d]\n", __func__, (rc == 0) ? "SUCCESS" : "FAILURE", rc); + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/measure.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/measure.h new file mode 100644 index 0000000000000000000000000000000000000000..e97091e83d011c629e6e9db3d069a550490eaeb9 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/measure.h @@ -0,0 +1,138 @@ +/* measure.h + * Macros to help with performance measurement. + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. Algorithms used by + * this code may be covered by patents by HP, Microsoft, or other parties. + * + * MEASURE_LOOP_START("measurement", 2000) + * code to be measured + * MEASURE_LOOP_STOP + * buffer flush and such + * MEASURE_SHOW_RESULTS + * + * Define GOOGLE_PROFILER if you want gperftools included. + */ + +#ifndef TEST_MEASURE_H_INCLUDED +#define TEST_MEASURE_H_INCLUDED + +#include + +#include +#include +#include + +#ifndef _WIN32 +#include +#endif + +#include + +#ifdef _WIN32 + +#define PROFILER_START(_prefix_) +#define PROFILER_STOP + +#define MEASURE_LOOP_START(_prefix_, _count_) +#define MEASURE_LOOP_STOP +#define MEASURE_GET_RESULTS(_result_) +#define MEASURE_SHOW_RESULTS(_result_) +#define MEASURE_SHOW_RESULTS_SCALED(_scale_, _label_) +#define MEASURE_TIMED(_label_, _init_iter_, _test_time_, _result_, _call_) + +#else + +#ifdef GOOGLE_PROFILER +#include +#define PROFILER_START(_prefix_) \ + do \ + { \ + char _path[PATH_MAX]; \ + sprintf_s(_path, sizeof(_path), "./%s.prof", (_prefix_)); \ + ProfilerStart(_path); \ + } while (0); +#define PROFILER_STOP \ + do \ + { \ + ProfilerStop(); \ + } while (0); +#else +#define PROFILER_START(_prefix_) +#define PROFILER_STOP +#endif // GOOGLE_PROFILER + +extern float measure_delta_time(UINT64 t0, UINT64 t1); +extern void measure_floatprint(float t, char* output, size_t len); + +#define MEASURE_LOOP_START(_prefix_, _count_) \ + { \ + int _count = (_count_); \ + int _loop; \ + char str1[32] = { 0 }; \ + char str2[32] = { 0 }; \ + char* _prefix = _strdup(_prefix_); \ + const UINT64 start = winpr_GetTickCount64NS(); \ + PROFILER_START(_prefix); \ + _loop = (_count); \ + do \ + { + +#define MEASURE_LOOP_STOP \ + } \ + while (--_loop) \ + ; + +#define MEASURE_GET_RESULTS(_result_) \ + PROFILER_STOP; \ + const UINT64 stop = winpr_GetTickCount64NS(); \ + const float delta = measure_delta_time(start, stop); \ + (_result_) = (float)_count / delta; \ + free(_prefix); \ + } + +#define MEASURE_SHOW_RESULTS(_result_) \ + PROFILER_STOP; \ + const UINT64 stop = winpr_GetTickCount64NS(); \ + const float delta = measure_delta_time(start, stop); \ + (_result_) = (float)_count / delta; \ + measure_floatprint((float)_count / delta, str1); \ + printf("%s: %9d iterations in %5.1f seconds = %s/s \n", _prefix, _count, delta, str1); \ + free(_prefix); \ + } + +#define MEASURE_SHOW_RESULTS_SCALED(_scale_, _label_) \ + PROFILER_STOP; \ + const UINT64 stop = winpr_GetTickCount64NS(); \ + const float delta = measure_delta_time(start, stop); \ + measure_floatprint((float)_count / delta, str1); \ + measure_floatprint((float)_count / delta * (_scale_), str2); \ + printf("%s: %9d iterations in %5.1f seconds = %s/s = %s%s \n", _prefix, _count, delta, str1, \ + str2, _label_); \ + free(_prefix); \ + } + +#define MEASURE_TIMED(_label_, _init_iter_, _test_time_, _result_, _call_) \ + { \ + float _r; \ + MEASURE_LOOP_START(_label_, _init_iter_); \ + _call_; \ + MEASURE_LOOP_STOP; \ + MEASURE_GET_RESULTS(_r); \ + MEASURE_LOOP_START(_label_, _r* _test_time_); \ + _call_; \ + MEASURE_LOOP_STOP; \ + MEASURE_SHOW_RESULTS(_result_); \ + } + +#endif + +#endif // __MEASURE_H_INCLUDED__ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/prim_test.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/prim_test.c new file mode 100644 index 0000000000000000000000000000000000000000..2d415df0389431d7bd50496615443e0d96a4534e --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/prim_test.c @@ -0,0 +1,94 @@ +/* prim_test.c + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include + +#include "prim_test.h" + +#ifndef _WIN32 +#include +#include +#include +#include +#endif + +#include +#include +#include + +primitives_t* generic = NULL; +primitives_t* optimized = NULL; +BOOL g_TestPrimitivesPerformance = FALSE; +UINT32 g_Iterations = 1000; + +int test_sizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; + +/* ------------------------------------------------------------------------- */ + +float measure_delta_time(UINT64 t0, UINT64 t1) +{ + INT64 diff = (INT64)(t1 - t0); + double retval = ((double)diff / 1000000000.0); + return (retval < 0.0) ? 0.0f : (float)retval; +} + +/* ------------------------------------------------------------------------- */ +void measure_floatprint(float t, char* output, size_t len) +{ + /* I don't want to link against -lm, so avoid log,exp,... */ + float f = 10.0f; + int i = 0; + + while (t > f) + f *= 10.0f; + + f /= 1000.0f; + i = ((int)(t / f + 0.5f)) * (int)f; + + if (t < 0.0f) + (void)_snprintf(output, len, "%f", t); + else if (i == 0) + (void)_snprintf(output, len, "%d", (int)(t + 0.5f)); + else if (t < 1e+3f) + (void)_snprintf(output, len, "%3d", i); + else if (t < 1e+6f) + (void)_snprintf(output, len, "%3d,%03d", i / 1000, i % 1000); + else if (t < 1e+9f) + (void)_snprintf(output, len, "%3d,%03d,000", i / 1000000, (i % 1000000) / 1000); + else if (t < 1e+12f) + (void)_snprintf(output, len, "%3d,%03d,000,000", i / 1000000000, + (i % 1000000000) / 1000000); + else + (void)_snprintf(output, len, "%f", t); +} + +void prim_test_setup(BOOL performance) +{ + generic = primitives_get_generic(); + optimized = primitives_get(); + g_TestPrimitivesPerformance = performance; +} + +BOOL speed_test(const char* name, const char* dsc, UINT32 iterations, speed_test_fkt generic, + speed_test_fkt optimized, ...) +{ + if (!name || !generic || !optimized || (iterations == 0)) + return FALSE; + + for (UINT32 i = 0; i < iterations; i++) + { + } + + return TRUE; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/prim_test.h b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/prim_test.h new file mode 100644 index 0000000000000000000000000000000000000000..06db846d92e7272e0c5df36716be8cbdb28cd006 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/primitives/test/prim_test.h @@ -0,0 +1,54 @@ +/* primtest.h + * vi:ts=4 sw=4 + * + * (c) Copyright 2012 Hewlett-Packard Development Company, L.P. + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. Algorithms used by + * this code may be covered by patents by HP, Microsoft, or other parties. + */ + +#ifndef FREERDP_LIB_PRIMTEST_H +#define FREERDP_LIB_PRIMTEST_H + +#include +#include +#include +#include +#include + +#include + +#include "measure.h" + +#ifdef _WIN32 +#define ALIGN(x) x +#else +#define ALIGN(x) x DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) +#endif + +#define ABS(_x_) ((_x_) < 0 ? (-(_x_)) : (_x_)) +#define MAX_TEST_SIZE 4096 + +extern int test_sizes[]; +#define NUM_TEST_SIZES 10 + +extern BOOL g_TestPrimitivesPerformance; +extern UINT32 g_Iterations; + +extern primitives_t* generic; +extern primitives_t* optimized; + +void prim_test_setup(BOOL performance); + +typedef pstatus_t (*speed_test_fkt)(); + +BOOL speed_test(const char* name, const char* dsc, UINT32 iterations, speed_test_fkt generic, + speed_test_fkt optimized, ...); + +#endif /* FREERDP_LIB_PRIMTEST_H */ diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/CMakeLists.txt b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b90c5f478509576d557b7c9bffe7827f286be6ae --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/CMakeLists.txt @@ -0,0 +1,26 @@ +set(MODULE_NAME "TestFreeRDPUtils") +set(MODULE_PREFIX "TEST_FREERDP_UTILS") + +disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR}) + +set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c) + +set(${MODULE_PREFIX}_TESTS TestRingBuffer.c TestPodArrays.c TestEncodedTypes.c) + +create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS}) + +add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + +target_link_libraries(${MODULE_NAME} PRIVATE freerdp winpr) +if(NOT WIN32) + target_link_libraries(${MODULE_NAME} PRIVATE m) +endif() + +set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}") + +foreach(test ${${MODULE_PREFIX}_TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "FreeRDP/Test") diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestEncodedTypes.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestEncodedTypes.c new file mode 100644 index 0000000000000000000000000000000000000000..80eab107be3e1ef3a7a037f25d5fb0ee8b4529f4 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestEncodedTypes.c @@ -0,0 +1,215 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2024 Thincast Technologies GmbH + * Copyright 2024 Armin Novak + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include + +#define MIN(x, y) ((x) < (y)) ? (x) : (y) +#define MAX(x, y) ((x) > (y)) ? (x) : (y) + +static BOOL test_signed_integer_read_write_equal(INT32 value) +{ + INT32 rvalue = 0; + BYTE buffer[32] = { 0 }; + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); + WINPR_ASSERT(s); + + if (!freerdp_write_four_byte_signed_integer(s, value)) + { + (void)fprintf(stderr, "[%s(%" PRId32 ")] failed to write to stream\n", __func__, value); + return FALSE; + } + if (!Stream_SetPosition(s, 0)) + { + (void)fprintf(stderr, "[%s(%" PRId32 ")] failed to reset stream position\n", __func__, + value); + return FALSE; + } + if (!freerdp_read_four_byte_signed_integer(s, &rvalue)) + { + (void)fprintf(stderr, "[%s(%" PRId32 ")] failed to read from stream\n", __func__, value); + return FALSE; + } + if (value != rvalue) + { + (void)fprintf(stderr, "[%s(%" PRId32 ")] read invalid value %" PRId32 " from stream\n", + __func__, value, rvalue); + return FALSE; + } + return TRUE; +} + +static BOOL test_signed_integer_write_oor(INT32 value) +{ + BYTE buffer[32] = { 0 }; + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); + WINPR_ASSERT(s); + + if (freerdp_write_four_byte_signed_integer(s, value)) + { + (void)fprintf(stderr, + "[%s(%" PRId32 ")] out of range value not detected and written to stream\n", + __func__, value); + return FALSE; + } + return TRUE; +} + +static BOOL test_signed_integers(void) +{ + const INT32 outofrange[] = { FREERDP_FOUR_BYTE_SIGNED_INT_MAX + 1, + FREERDP_FOUR_BYTE_SIGNED_INT_MIN - 1, INT32_MAX, INT32_MIN }; + const INT32 limits[] = { 1, 0, -1, FREERDP_FOUR_BYTE_SIGNED_INT_MAX, + FREERDP_FOUR_BYTE_SIGNED_INT_MIN }; + + for (size_t x = 0; x < ARRAYSIZE(limits); x++) + { + if (!test_signed_integer_read_write_equal(limits[x])) + return FALSE; + } + for (size_t x = 0; x < ARRAYSIZE(outofrange); x++) + { + if (!test_signed_integer_write_oor(outofrange[x])) + return FALSE; + } + for (size_t x = 0; x < 100000; x++) + { + INT32 val = 0; + winpr_RAND(&val, sizeof(val)); + val = MAX(val, 0); + val = MIN(val, FREERDP_FOUR_BYTE_SIGNED_INT_MAX); + + const INT32 nval = -val; + if (!test_signed_integer_read_write_equal(val)) + return FALSE; + if (!test_signed_integer_read_write_equal(nval)) + return FALSE; + } + return TRUE; +} + +static BOOL test_float_read_write_equal(double value) +{ + BYTE exp = 0; + double rvalue = FP_NAN; + BYTE buffer[32] = { 0 }; + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); + WINPR_ASSERT(s); + + if (!freerdp_write_four_byte_float(s, value)) + { + (void)fprintf(stderr, "[%s(%lf)] failed to write to stream\n", __func__, value); + return FALSE; + } + if (!Stream_SetPosition(s, 0)) + { + (void)fprintf(stderr, "[%s(%lf)] failed to reset stream position\n", __func__, value); + return FALSE; + } + if (!freerdp_read_four_byte_float_exp(s, &rvalue, &exp)) + { + (void)fprintf(stderr, "[%s(%lf)] failed to read from stream\n", __func__, value); + return FALSE; + } + const double diff = fabs(value - rvalue); + const double expdiff = diff * pow(10, exp); + if (expdiff >= 1.0) + { + (void)fprintf(stderr, "[%s(%lf)] read invalid value %lf from stream\n", __func__, value, + rvalue); + return FALSE; + } + return TRUE; +} + +static BOOL test_floag_write_oor(double value) +{ + BYTE buffer[32] = { 0 }; + wStream sbuffer = { 0 }; + wStream* s = Stream_StaticInit(&sbuffer, buffer, sizeof(buffer)); + WINPR_ASSERT(s); + + if (freerdp_write_four_byte_float(s, value)) + { + (void)fprintf(stderr, "[%s(%lf)] out of range value not detected and written to stream\n", + __func__, value); + return FALSE; + } + return TRUE; +} + +static double get(void) +{ + double val = NAN; + do + { + winpr_RAND(&val, sizeof(val)); + } while ((val < 0.0) || (val > FREERDP_FOUR_BYTE_FLOAT_MAX) || isnan(val) || isinf(val)); + return val; +} + +static BOOL test_floats(void) +{ + const double outofrange[] = { FREERDP_FOUR_BYTE_FLOAT_MAX + 1, FREERDP_FOUR_BYTE_FLOAT_MIN - 1, + DBL_MAX, -DBL_MAX }; + const double limits[] = { 100045.26129238126, 1, 0, -1, FREERDP_FOUR_BYTE_FLOAT_MAX, + FREERDP_FOUR_BYTE_FLOAT_MIN }; + + for (size_t x = 0; x < ARRAYSIZE(limits); x++) + { + if (!test_float_read_write_equal(limits[x])) + return FALSE; + } + for (size_t x = 0; x < ARRAYSIZE(outofrange); x++) + { + if (!test_floag_write_oor(outofrange[x])) + return FALSE; + } + for (size_t x = 0; x < 100000; x++) + { + double val = get(); + + const double nval = -val; + if (!test_float_read_write_equal(val)) + return FALSE; + if (!test_float_read_write_equal(nval)) + return FALSE; + } + return TRUE; +} + +int TestEncodedTypes(int argc, char* argv[]) +{ + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!test_signed_integers()) + return -1; + if (!test_floats()) + return -1; + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestPodArrays.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestPodArrays.c new file mode 100644 index 0000000000000000000000000000000000000000..f14e8cf8f1e4441bbbce2fd6f438c248e1669b1d --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestPodArrays.c @@ -0,0 +1,132 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * TestPodArrays + * + * Copyright 2022 David Fort + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +// NOLINTNEXTLINE(readability-non-const-parameter) +static BOOL cb_compute_sum(UINT32* v, void* target) +{ + UINT32* ret = (UINT32*)target; + *ret += *v; + return TRUE; +} + +static BOOL cb_stop_at_5(UINT32* v, void* target) +{ + UINT32* ret = (UINT32*)target; + *ret += 1; + return (*ret != 5); +} + +static BOOL cb_set_to_1(UINT32* v, void* target) +{ + *v = 1; + return TRUE; +} + +static BOOL cb_reset_after_1(UINT32* v, void* target) +{ + ArrayUINT32* a = (ArrayUINT32*)target; + array_uint32_reset(a); + return TRUE; +} + +typedef struct +{ + UINT32 v1; + UINT16 v2; +} BasicStruct; + +static BOOL cb_basic_struct(BasicStruct* v, void* target) +{ + return (v->v1 == 1) && (v->v2 == 2); +} +// NOLINTNEXTLINE(bugprone-suspicious-memory-comparison,cert-exp42-c,cert-flp37-c) +POD_ARRAYS_IMPL(BasicStruct, basicstruct) + +int TestPodArrays(int argc, char* argv[]) +{ + int rc = -1; + UINT32 sum = 0; + UINT32 foreach_index = 0; + ArrayUINT32 uint32s = { 0 }; + UINT32* ptr = NULL; + const UINT32* cptr = NULL; + ArrayBasicStruct basicStructs = { 0 }; + BasicStruct basicStruct = { 1, 2 }; + + array_uint32_init(&uint32s); + array_basicstruct_init(&basicStructs); + + for (UINT32 i = 0; i < 10; i++) + if (!array_uint32_append(&uint32s, i)) + goto fail; + + sum = 0; + if (!array_uint32_foreach(&uint32s, cb_compute_sum, &sum)) + goto fail; + + if (sum != 45) + goto fail; + + foreach_index = 0; + if (array_uint32_foreach(&uint32s, cb_stop_at_5, &foreach_index)) + goto fail; + + if (foreach_index != 5) + goto fail; + + if (array_uint32_get(&uint32s, 4) != 4) + goto fail; + + array_uint32_set(&uint32s, 4, 5); + if (array_uint32_get(&uint32s, 4) != 5) + goto fail; + + ptr = array_uint32_data(&uint32s); + if (*ptr != 0) + goto fail; + + cptr = array_uint32_cdata(&uint32s); + if (*cptr != 0) + goto fail; + + /* test modifying values of the array during the foreach */ + if (!array_uint32_foreach(&uint32s, cb_set_to_1, NULL) || array_uint32_get(&uint32s, 5) != 1) + goto fail; + + /* this one is to test that we can modify the array itself during the foreach and that things + * go nicely */ + if (!array_uint32_foreach(&uint32s, cb_reset_after_1, &uint32s) || array_uint32_size(&uint32s)) + goto fail; + + /* give a try with an array of BasicStructs */ + if (!array_basicstruct_append(&basicStructs, basicStruct)) + goto fail; + + if (!array_basicstruct_foreach(&basicStructs, cb_basic_struct, NULL)) + goto fail; + + rc = 0; + +fail: + array_uint32_uninit(&uint32s); + array_basicstruct_uninit(&basicStructs); + + return rc; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestRingBuffer.c b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestRingBuffer.c new file mode 100644 index 0000000000000000000000000000000000000000..ebe868128216a7834c395b2fb594899979fcc6f9 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/libfreerdp/utils/test/TestRingBuffer.c @@ -0,0 +1,227 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * + * Copyright 2014 Thincast Technologies GmbH + * Copyright 2014 Hardening + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +static BOOL test_overlaps(void) +{ + RingBuffer rb; + DataChunk chunks[2]; + BYTE bytes[200]; + int nchunks = 0; + int counter = 0; + + for (size_t i = 0; i < sizeof(bytes); i++) + bytes[i] = (BYTE)i; + + ringbuffer_init(&rb, 5); + if (!ringbuffer_write(&rb, bytes, 4)) /* [0123.] */ + goto error; + counter += 4; + ringbuffer_commit_read_bytes(&rb, 2); /* [..23.] */ + + if (!ringbuffer_write(&rb, &bytes[counter], 2)) /* [5.234] */ + goto error; + counter += 2; + + nchunks = ringbuffer_peek(&rb, chunks, 4); + if (nchunks != 2 || chunks[0].size != 3 || chunks[1].size != 1) + goto error; + + for (int x = 0, j = 2; x < nchunks; x++) + { + for (size_t k = 0; k < chunks[x].size; k++, j++) + { + if (chunks[x].data[k] != (BYTE)j) + goto error; + } + } + + ringbuffer_commit_read_bytes(&rb, 3); /* [5....] */ + if (ringbuffer_used(&rb) != 1) + goto error; + + if (!ringbuffer_write(&rb, &bytes[counter], 6)) /* [56789ab....] */ + goto error; + + ringbuffer_commit_read_bytes(&rb, 6); /* [......b....] */ + nchunks = ringbuffer_peek(&rb, chunks, 10); + if (nchunks != 1 || chunks[0].size != 1 || (*chunks[0].data != 0xb)) + goto error; + + if (ringbuffer_capacity(&rb) != 5) + goto error; + + ringbuffer_destroy(&rb); + return TRUE; +error: + ringbuffer_destroy(&rb); + return FALSE; +} + +int TestRingBuffer(int argc, char* argv[]) +{ + RingBuffer ringBuffer; + int testNo = 0; + BYTE* tmpBuf = NULL; + BYTE* rb_ptr = NULL; + DataChunk chunks[2]; + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + if (!ringbuffer_init(&ringBuffer, 10)) + { + (void)fprintf(stderr, "unable to initialize ringbuffer\n"); + return -1; + } + + tmpBuf = (BYTE*)malloc(50); + if (!tmpBuf) + return -1; + + for (int i = 0; i < 50; i++) + tmpBuf[i] = (char)i; + + (void)fprintf(stderr, "%d: basic tests...", ++testNo); + if (!ringbuffer_write(&ringBuffer, tmpBuf, 5) || !ringbuffer_write(&ringBuffer, tmpBuf, 5) || + !ringbuffer_write(&ringBuffer, tmpBuf, 5)) + { + (void)fprintf(stderr, "error when writing bytes\n"); + return -1; + } + + if (ringbuffer_used(&ringBuffer) != 15) + { + (void)fprintf(stderr, "invalid used size got %" PRIuz " when I would expect 15\n", + ringbuffer_used(&ringBuffer)); + return -1; + } + + if (ringbuffer_peek(&ringBuffer, chunks, 10) != 1 || chunks[0].size != 10) + { + (void)fprintf(stderr, "error when reading bytes\n"); + return -1; + } + ringbuffer_commit_read_bytes(&ringBuffer, chunks[0].size); + + /* check retrieved bytes */ + for (size_t i = 0; i < chunks[0].size; i++) + { + if (chunks[0].data[i] != i % 5) + { + (void)fprintf(stderr, + "invalid byte at %" PRIuz ", got %" PRIu8 " instead of %" PRIuz "\n", i, + chunks[0].data[i], i % 5ULL); + return -1; + } + } + + if (ringbuffer_used(&ringBuffer) != 5) + { + (void)fprintf(stderr, "invalid used size after read got %" PRIuz " when I would expect 5\n", + ringbuffer_used(&ringBuffer)); + return -1; + } + + /* write some more bytes to have writePtr < readPtr and data split in 2 chunks */ + if (!ringbuffer_write(&ringBuffer, tmpBuf, 6) || + ringbuffer_peek(&ringBuffer, chunks, 11) != 2 || chunks[0].size != 10 || + chunks[1].size != 1) + { + (void)fprintf(stderr, "invalid read of split data\n"); + return -1; + } + + ringbuffer_commit_read_bytes(&ringBuffer, 11); + (void)fprintf(stderr, "ok\n"); + + (void)fprintf(stderr, "%d: peek with nothing to read...", ++testNo); + if (ringbuffer_peek(&ringBuffer, chunks, 10)) + { + (void)fprintf(stderr, "peek returns some chunks\n"); + return -1; + } + (void)fprintf(stderr, "ok\n"); + + (void)fprintf(stderr, "%d: ensure_linear_write / read() shouldn't grow...", ++testNo); + for (int i = 0; i < 1000; i++) + { + rb_ptr = ringbuffer_ensure_linear_write(&ringBuffer, 50); + if (!rb_ptr) + { + (void)fprintf(stderr, "ringbuffer_ensure_linear_write() error\n"); + return -1; + } + + memcpy(rb_ptr, tmpBuf, 50); + + if (!ringbuffer_commit_written_bytes(&ringBuffer, 50)) + { + (void)fprintf(stderr, "ringbuffer_commit_written_bytes() error, i=%d\n", i); + return -1; + } + + // ringbuffer_commit_read_bytes(&ringBuffer, 25); + } + + for (int i = 0; i < 1000; i++) + ringbuffer_commit_read_bytes(&ringBuffer, 25); + + for (int i = 0; i < 1000; i++) + ringbuffer_commit_read_bytes(&ringBuffer, 25); + + if (ringbuffer_capacity(&ringBuffer) != 10) + { + (void)fprintf(stderr, "not the expected capacity, have %" PRIuz " and expects 10\n", + ringbuffer_capacity(&ringBuffer)); + return -1; + } + (void)fprintf(stderr, "ok\n"); + + (void)fprintf(stderr, "%d: free size is correctly computed...", ++testNo); + for (int i = 0; i < 1000; i++) + { + ringbuffer_ensure_linear_write(&ringBuffer, 50); + if (!ringbuffer_commit_written_bytes(&ringBuffer, 50)) + { + (void)fprintf(stderr, "ringbuffer_commit_written_bytes() error, i=%d\n", i); + return -1; + } + } + ringbuffer_commit_read_bytes(&ringBuffer, 50ULL * 1000ULL); + (void)fprintf(stderr, "ok\n"); + + ringbuffer_destroy(&ringBuffer); + + (void)fprintf(stderr, "%d: specific overlaps test...", ++testNo); + if (!test_overlaps()) + { + (void)fprintf(stderr, "ko\n"); + return -1; + } + (void)fprintf(stderr, "ok\n"); + + ringbuffer_destroy(&ringBuffer); + free(tmpBuf); + return 0; +} diff --git a/local-test-freerdp-delta-01/afc-freerdp/resources/font/OFL.txt b/local-test-freerdp-delta-01/afc-freerdp/resources/font/OFL.txt new file mode 100644 index 0000000000000000000000000000000000000000..9b448d4017f9233c21ae6db92c90bc2d229f56b2 --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/resources/font/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/local-test-freerdp-delta-01/afc-freerdp/resources/font/README.txt b/local-test-freerdp-delta-01/afc-freerdp/resources/font/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..2548322ce764e9f85aecb7470c5d68d3fd4fbbbc --- /dev/null +++ b/local-test-freerdp-delta-01/afc-freerdp/resources/font/README.txt @@ -0,0 +1,100 @@ +Open Sans Variable Font +======================= + +This download contains Open Sans as both variable fonts and static fonts. + +Open Sans is a variable font with these axes: + wdth + wght + +This means all the styles are contained in these files: + OpenSans-VariableFont_wdth,wght.ttf + OpenSans-Italic-VariableFont_wdth,wght.ttf + +If your app fully supports variable fonts, you can now pick intermediate styles +that aren’t available as static fonts. Not all apps support variable fonts, and +in those cases you can use the static font files for Open Sans: + static/OpenSans_Condensed-Light.ttf + static/OpenSans_Condensed-Regular.ttf + static/OpenSans_Condensed-Medium.ttf + static/OpenSans_Condensed-SemiBold.ttf + static/OpenSans_Condensed-Bold.ttf + static/OpenSans_Condensed-ExtraBold.ttf + static/OpenSans_SemiCondensed-Light.ttf + static/OpenSans_SemiCondensed-Regular.ttf + static/OpenSans_SemiCondensed-Medium.ttf + static/OpenSans_SemiCondensed-SemiBold.ttf + static/OpenSans_SemiCondensed-Bold.ttf + static/OpenSans_SemiCondensed-ExtraBold.ttf + static/OpenSans-Light.ttf + static/OpenSans-Regular.ttf + static/OpenSans-Medium.ttf + static/OpenSans-SemiBold.ttf + static/OpenSans-Bold.ttf + static/OpenSans-ExtraBold.ttf + static/OpenSans_Condensed-LightItalic.ttf + static/OpenSans_Condensed-Italic.ttf + static/OpenSans_Condensed-MediumItalic.ttf + static/OpenSans_Condensed-SemiBoldItalic.ttf + static/OpenSans_Condensed-BoldItalic.ttf + static/OpenSans_Condensed-ExtraBoldItalic.ttf + static/OpenSans_SemiCondensed-LightItalic.ttf + static/OpenSans_SemiCondensed-Italic.ttf + static/OpenSans_SemiCondensed-MediumItalic.ttf + static/OpenSans_SemiCondensed-SemiBoldItalic.ttf + static/OpenSans_SemiCondensed-BoldItalic.ttf + static/OpenSans_SemiCondensed-ExtraBoldItalic.ttf + static/OpenSans-LightItalic.ttf + static/OpenSans-Italic.ttf + static/OpenSans-MediumItalic.ttf + static/OpenSans-SemiBoldItalic.ttf + static/OpenSans-BoldItalic.ttf + static/OpenSans-ExtraBoldItalic.ttf + +Get started +----------- + +1. Install the font files you want to use + +2. Use your app's font picker to view the font family and all the +available styles + +Learn more about variable fonts +------------------------------- + + https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts + https://variablefonts.typenetwork.com + https://medium.com/variable-fonts + +In desktop apps + + https://theblog.adobe.com/can-variable-fonts-illustrator-cc + https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts + +Online + + https://developers.google.com/fonts/docs/getting_started + https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide + https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts + +Installing fonts + + MacOS: https://support.apple.com/en-us/HT201749 + Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux + Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows + +Android Apps + + https://developers.google.com/fonts/docs/android + https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts + +License +------- +Please read the full license text (OFL.txt) to understand the permissions, +restrictions and requirements for usage, redistribution, and modification. + +You can use them in your products & projects – print or digital, +commercial or otherwise. + +This isn't legal advice, please consider consulting a lawyer and see the full +license for all details. diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/FreeRDP_Logo.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/FreeRDP_Logo.png new file mode 100644 index 0000000000000000000000000000000000000000..47e66901252c9e7402cb024e686824d8ca2bddc4 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/FreeRDP_Logo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59ba765841240f38d0aea60305a18ab22d3a02329630b4b4f069ab0449aec735 +size 30329 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/background.jpg b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/background.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b54dc9401a29390eec7b5166e18bc2dfa0eac56f --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/background.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d0e61a9ff3cdcf6f90d8a8b7f7fe9f73c4a8f6ca59810d260da78cdd2f87859 +size 118109 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures_phone.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures_phone.png new file mode 100644 index 0000000000000000000000000000000000000000..db0157a9e42a6fdf88662175048cf44847220a92 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/gestures_phone.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:780b4dace804ffd21c16896157380c6279ce5344051893ab2a65ddfdbe78b63e +size 27770 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_gestures.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_gestures.png new file mode 100644 index 0000000000000000000000000000000000000000..b8ccc6229abc92f08d0d5345f830a9df913d336e --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/nav_gestures.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0542a7e508082f2929967e4d55fa27a52fc52cf742aea92008aceb94bfc00037 +size 2394 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.png new file mode 100644 index 0000000000000000000000000000000000000000..1847c36a5b4a7666c6f7be057efeeaedde3ef950 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abe46c88e7e1785232b0b82b7db3412094ac3f860282bf5790bd5e86bdb81ef2 +size 7010 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar_phone.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar_phone.png new file mode 100644 index 0000000000000000000000000000000000000000..b4354677a8cba9936ce45ce3443dfa54f4d5960c --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/toolbar_phone.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4924bcc54436b833506c1491a3b368c12196476250ec6d971f3be1548b052166 +size 5555 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer.png new file mode 100644 index 0000000000000000000000000000000000000000..7fb052810c18c7e81385bed3355feaf3074baedf --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/de_help_page/touch_pointer.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c464545763a884d386988172133d96d26925c5c56658d4f19086664932cc498 +size 110449 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.png new file mode 100644 index 0000000000000000000000000000000000000000..1847c36a5b4a7666c6f7be057efeeaedde3ef950 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/assets/help_page/toolbar.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abe46c88e7e1785232b0b82b7db3412094ac3f860282bf5790bd5e86bdb81ef2 +size 7010 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-hdpi/icon_launcher_freerdp.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-hdpi/icon_launcher_freerdp.png new file mode 100644 index 0000000000000000000000000000000000000000..b9a7cba1067f2abdc88c6280b47d21e6f82d8f88 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-hdpi/icon_launcher_freerdp.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c7d86d620b29b41928222e883ec140e622559c63630f33f537d8b3c27518888c +size 2858 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-ldpi/icon_launcher_freerdp.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-ldpi/icon_launcher_freerdp.png new file mode 100644 index 0000000000000000000000000000000000000000..f0af8aed723b879c5c3ee5b984ef1dce82fe088c --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-ldpi/icon_launcher_freerdp.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72f01072f36120d597acb48fd6218f38e6d943a1f40f796c0ccf4a16d3a33098 +size 1200 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-mdpi/icon_launcher_freerdp.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-mdpi/icon_launcher_freerdp.png new file mode 100644 index 0000000000000000000000000000000000000000..a6b026a6ad2c8de6325aa070d7aaf39a529b575a --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable-mdpi/icon_launcher_freerdp.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59f6d357eca1b2494352999a1bd115d8a91cb7f4e68887d4593254db764af0e9 +size 1784 diff --git a/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable/icon_launcher_freerdp.png b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable/icon_launcher_freerdp.png new file mode 100644 index 0000000000000000000000000000000000000000..6ae5d33077517bc6bd775dac01e003b3e3794141 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/client/Android/Studio/aFreeRDP/src/main/res/drawable/icon_launcher_freerdp.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0dfcf66372077073d1012961cc1ba4b850f6a6e484aab884da28f2c618a30406 +size 4196 diff --git a/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/progressive.bmp b/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/progressive.bmp new file mode 100644 index 0000000000000000000000000000000000000000..e0de4ee2c04f082c531dbd2e37a4ea751dc5f838 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/progressive.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1823670e5894000b49b482717b2df431c02800f525fb57041c3e9cefaf965a98 +size 3506618 diff --git a/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/rfx.bmp b/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/rfx.bmp new file mode 100644 index 0000000000000000000000000000000000000000..6b2c1bb242689300a912012406a0d809ab1a2a77 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/rfx.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e49e00b4f63da93223e21ad52b0366d91909519fbece0cc9b63a5f557277c155 +size 16438 diff --git a/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/test01.bmp b/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/test01.bmp new file mode 100644 index 0000000000000000000000000000000000000000..757c27f6da3214373b8574a611762f284e916a74 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/libfreerdp/codec/test/test01.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30a20b5cafa8cd361b68c9dda92cf9798128a4acf0b834d68afa6ecb6fb0ff10 +size 4150 diff --git a/local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-Italic-VariableFont_wdth,wght.ttf b/local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-Italic-VariableFont_wdth,wght.ttf new file mode 100644 index 0000000000000000000000000000000000000000..781a25df2fe858fa5d5df8515f6bec854636a10d --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-Italic-VariableFont_wdth,wght.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:602606bec0b527ba124c6da553e9aa790e21187f8261c7e96af547c400abd15d +size 580356 diff --git a/local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-VariableFont_wdth,wght.ttf b/local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-VariableFont_wdth,wght.ttf new file mode 100644 index 0000000000000000000000000000000000000000..49f2be6f4a48d541eef7bede41be5621a8a32b4f --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/resources/font/OpenSans-VariableFont_wdth,wght.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1b1331ba90e949be8664b073976b4f0369b831f381e13e506d728e50ce29083 +size 529700 diff --git a/local-test-freerdp-full-01/afc-freerdp/server/Sample/rfx_test.pcap b/local-test-freerdp-full-01/afc-freerdp/server/Sample/rfx_test.pcap new file mode 100644 index 0000000000000000000000000000000000000000..77c23eca111c4890eb3dca30138c4344e4034b2c --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/server/Sample/rfx_test.pcap @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c63a086603c8b301cb1e2a2ea0ec9de5e8c0dbb085af61d20ae943ef8ff17de0 +size 994948 diff --git a/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.bmp b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.bmp new file mode 100644 index 0000000000000000000000000000000000000000..ab95586deeed11c8f7ff4fa9f1b9cca4f9def068 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d624a07ec286374997b70058111bfa998c1cb43fd448965eb2603453e74368ef +size 5770 diff --git a/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.jpg b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.jpg new file mode 100644 index 0000000000000000000000000000000000000000..00372d043b3d635abfb0687e175d3771d44ee3f1 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9ea48531a5f2c6b65181a7d833d7cdca7a2992f30f33a022b970bbc438c24b7 +size 4096 diff --git a/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.png b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..27429d725cb61a3ec04adf6ddac632f3fcbb86a3 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca0c65ba3f733324d628f461f0f6b9b37b5e6bf61571c52e9de1158ccd72c484 +size 6140 diff --git a/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.webp b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.webp new file mode 100644 index 0000000000000000000000000000000000000000..f592a2a21e950c19471acc07ecef49c261bbc965 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/server/Sample/test_icon.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:137814f32ef6707494ef0f7b740335a6685ea46863c39a7ef37b340fc7d95cdd +size 2122 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/lodepng_32bit.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/lodepng_32bit.bmp new file mode 100644 index 0000000000000000000000000000000000000000..15fc2836d142b0cd80c2580978a5983839cd0bf2 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/lodepng_32bit.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b5f55fcf57bdf1b7714871af3e607a8f9ba6dadf5f2c84c5f1f30264b15c1c0 +size 16522 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16.bmp new file mode 100644 index 0000000000000000000000000000000000000000..7cf06e85cd0904f19f085699f1c37e7da59b3db9 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdc78681f8ed0cffacb02cdf254444149ed40430b8439855a205bc27682936d7 +size 1966218 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16.nocolor.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16.nocolor.bmp new file mode 100644 index 0000000000000000000000000000000000000000..6a0d0de406e8cbab2f23caad9c0768622fa7d83e --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16.nocolor.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d135ebb59691eebad95721b7b27fb299c225d89d71f3f622ff070facff6c6d57 +size 1966150 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16a.nocolor.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16a.nocolor.bmp new file mode 100644 index 0000000000000000000000000000000000000000..268826993e8fb52e755624a1ccd7d8892758505a --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16a.nocolor.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e28dd1f0145f13fab693e607690388a1eb36d738835e142e9f0923c3d3ff16c +size 1966150 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16x.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16x.bmp new file mode 100644 index 0000000000000000000000000000000000000000..82fc2aabc5c095e878c47085adf1f219f9f9c72b --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16x.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f9b5c6818ea7b320798e16a1526e6fa663b54e19a30d882104b1951fdaa629c4 +size 1966218 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16x.nocolor.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16x.nocolor.bmp new file mode 100644 index 0000000000000000000000000000000000000000..07eaa542620f03a62a771ef3ff530a486d5b3f33 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.16x.nocolor.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a70e211f8995cc211ed262c36a358b41cb538dc27d382c546c9a78e3eb80862 +size 1966150 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.24.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.24.bmp new file mode 100644 index 0000000000000000000000000000000000000000..b66aefa9d0063bdaa8e1f62fa0c15d1c2eeaa5fd --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.24.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f53c5699c142ed1b085dad854bb3dc70d136fa0931144e3da004579b458e084a +size 2949258 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.32.nocolor.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.32.nocolor.bmp new file mode 100644 index 0000000000000000000000000000000000000000..fe2ce949fcc3ba11c25b0338d28f98cdb2bd6127 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.32.nocolor.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:82aa6e5654f144e3a1a25b833127821d544d8dee54e5d5241de24eacc45db98a +size 3932230 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.32x.nocolor.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.32x.nocolor.bmp new file mode 100644 index 0000000000000000000000000000000000000000..b5a7b84d594ca33b5886b36fd31a8f8d4a079cf9 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.32x.nocolor.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f95d37627d1ae04b61056cc2e5a69595141dc80430fefca3f1816f53c6f70987 +size 3932230 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.bmp b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.bmp new file mode 100644 index 0000000000000000000000000000000000000000..c60063888b85f907c4e275a0b637fee0ac0d7cc7 --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.bmp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e081f0ea91534fb1a7cf280ff3fba39750b3b1887fec3b2ce0a2c5009bedfd6 +size 2949258 diff --git a/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.jpg b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6b563aef012515811ca363e95548925f9305d7cf --- /dev/null +++ b/local-test-freerdp-full-01/afc-freerdp/winpr/libwinpr/utils/test/rgb.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fed25329beee83cbb17cb2958c76919ea282d5d4a13142ce7170d4a2ab1ec211 +size 280142