2012-04-25 22:26:35 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-04-25 22:26:35 +04:00
|
|
|
* RemoteFX USB Redirection
|
|
|
|
*
|
|
|
|
* Copyright 2012 Atrust corp.
|
|
|
|
* Copyright 2012 Alfred Liu <alfred.liu@atruscorp.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-06-09 15:03:34 +03:00
|
|
|
#include <winpr/assert.h>
|
2012-04-25 22:26:35 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-11-14 18:10:52 +03:00
|
|
|
#include <errno.h>
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
#include <winpr/pool.h>
|
|
|
|
#include <winpr/print.h>
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-11-27 05:15:48 +04:00
|
|
|
#include <winpr/synch.h>
|
2015-07-03 14:26:15 +03:00
|
|
|
#include <winpr/string.h>
|
2012-11-21 04:34:52 +04:00
|
|
|
#include <winpr/cmdline.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2012-10-03 00:54:14 +04:00
|
|
|
#include <freerdp/dvc.h>
|
2012-11-21 04:34:52 +04:00
|
|
|
#include <freerdp/addin.h>
|
2014-08-11 11:12:01 +04:00
|
|
|
#include <freerdp/channels/log.h>
|
2019-11-22 12:42:05 +03:00
|
|
|
#include <freerdp/channels/urbdrc.h>
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
#include "urbdrc_types.h"
|
|
|
|
#include "urbdrc_main.h"
|
|
|
|
#include "data_transfer.h"
|
2020-02-28 15:45:26 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
#include <urbdrc_helpers.h>
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static BOOL Stream_Write_UTF16_String_From_Utf8(wStream* s, const char* utf8, size_t len)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
BOOL ret;
|
|
|
|
WCHAR* utf16;
|
|
|
|
int rc;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (len > INT_MAX)
|
|
|
|
return FALSE;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
rc = ConvertToUnicode(CP_UTF8, 0, utf8, (int)len, &utf16, 0);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (rc < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ret = Stream_Write_UTF16_String(s, utf16, (size_t)rc);
|
|
|
|
free(utf16);
|
|
|
|
return ret;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static IWTSVirtualChannel* get_channel(IUDEVMAN* idevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
IWTSVirtualChannelManager* channel_mgr;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!idevman)
|
|
|
|
return NULL;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)idevman->plugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc || !urbdrc->listener_callback)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
channel_mgr = urbdrc->listener_callback->channel_mgr;
|
|
|
|
|
|
|
|
if (!channel_mgr)
|
|
|
|
return NULL;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return channel_mgr->FindChannelById(channel_mgr, idevman->controlChannelId);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
static int func_container_id_generate(IUDEVICE* pdev, char* strContainerId)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
char *p, *path;
|
2020-07-03 16:47:53 +03:00
|
|
|
UINT8 containerId[17] = { 0 };
|
2015-04-12 14:51:27 +03:00
|
|
|
UINT16 idVendor, idProduct;
|
|
|
|
idVendor = (UINT16)pdev->query_device_descriptor(pdev, ID_VENDOR);
|
|
|
|
idProduct = (UINT16)pdev->query_device_descriptor(pdev, ID_PRODUCT);
|
2012-04-25 22:26:35 +04:00
|
|
|
path = pdev->getPath(pdev);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (strlen(path) > 8)
|
|
|
|
p = (path + strlen(path)) - 8;
|
|
|
|
else
|
|
|
|
p = path;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s((char*)containerId, sizeof(containerId), "%04" PRIX16 "%04" PRIX16 "%s", idVendor,
|
|
|
|
idProduct, p);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* format */
|
2015-07-03 14:26:15 +03:00
|
|
|
sprintf_s(strContainerId, DEVICE_CONTAINER_STR_SIZE,
|
2019-11-06 17:24:51 +03:00
|
|
|
"{%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]);
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static int func_instance_id_generate(IUDEVICE* pdev, char* strInstanceId, size_t len)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-07-03 15:59:03 +03:00
|
|
|
char instanceId[17] = { 0 };
|
2019-11-22 12:42:05 +03:00
|
|
|
sprintf_s(instanceId, sizeof(instanceId), "\\%s", pdev->getPath(pdev));
|
2012-04-25 22:26:35 +04:00
|
|
|
/* format */
|
2019-11-22 12:42:05 +03:00
|
|
|
sprintf_s(strInstanceId, len,
|
2019-11-06 17:24:51 +03:00
|
|
|
"%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]);
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_capability_request(URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 MessageId)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 InterfaceId;
|
|
|
|
UINT32 Version;
|
|
|
|
UINT32 out_size;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
|
|
|
|
if (!callback || !s)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, Version);
|
|
|
|
|
|
|
|
if (Version > RIM_CAPABILITY_VERSION_01)
|
|
|
|
Version = RIM_CAPABILITY_VERSION_01;
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
InterfaceId = ((STREAM_ID_NONE << 30) | CAPABILITIES_NEGOTIATOR);
|
2012-04-25 22:26:35 +04:00
|
|
|
out_size = 16;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
2015-07-06 17:46:21 +03:00
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_channel_create(URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 MessageId)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 InterfaceId;
|
|
|
|
UINT32 out_size;
|
|
|
|
UINT32 MajorVersion;
|
|
|
|
UINT32 MinorVersion;
|
|
|
|
UINT32 Capabilities;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
|
|
|
|
if (!callback || !s || !callback->plugin)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 12))
|
2019-11-22 12:42:05 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | CLIENT_CHANNEL_NOTIFICATION);
|
2012-04-25 22:26:35 +04:00
|
|
|
out_size = 24;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
2015-07-06 17:46:21 +03:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urdbrc_send_virtual_channel_add(IWTSPlugin* plugin, IWTSVirtualChannel* channel,
|
|
|
|
UINT32 MessageId)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK* callback, IUDEVICE* pdev)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 InterfaceId;
|
2019-11-22 12:42:05 +03:00
|
|
|
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;
|
|
|
|
size_t CompatibilityIdLen[3];
|
|
|
|
size_t HardwareIdsLen[2];
|
|
|
|
size_t ContainerIdLen, InstanceIdLen;
|
|
|
|
size_t cchCompatIds;
|
|
|
|
UINT32 bcdUSB;
|
2017-11-14 18:10:52 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | CLIENT_DEVICE_SINK);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* USB kernel driver detach!! */
|
|
|
|
pdev->detach_kernel_driver(pdev);
|
2019-11-22 12:42:05 +03:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
sprintf_s(HardwareIds[1], DEVICE_HARDWARE_ID_SIZE,
|
|
|
|
"USB\\VID_%04" PRIX16 "&PID_%04" PRIX16 "", idVendor, idProduct);
|
2020-04-25 09:34:08 +03:00
|
|
|
sprintf_s(HardwareIds[0], DEVICE_HARDWARE_ID_SIZE,
|
|
|
|
"USB\\VID_%04" PRIX16 "&PID_%04" PRIX16 "&REV_%04" PRIX16 "", idVendor, idProduct,
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!(pdev->isCompositeDevice(pdev)))
|
|
|
|
{
|
|
|
|
sprintf_s(CompatibilityIds[2], DEVICE_COMPATIBILITY_ID_SIZE, "USB\\Class_%02" PRIX8 "",
|
|
|
|
bDeviceClass);
|
2020-04-25 09:34:08 +03:00
|
|
|
sprintf_s(CompatibilityIds[1], DEVICE_COMPATIBILITY_ID_SIZE,
|
|
|
|
"USB\\Class_%02" PRIX8 "&SubClass_%02" PRIX8 "", bDeviceClass,
|
|
|
|
bDeviceSubClass);
|
|
|
|
sprintf_s(CompatibilityIds[0], DEVICE_COMPATIBILITY_ID_SIZE,
|
|
|
|
"USB\\Class_%02" PRIX8 "&SubClass_%02" PRIX8 "&Prot_%02" PRIX8 "",
|
|
|
|
bDeviceClass, bDeviceSubClass, bDeviceProtocol);
|
2019-11-22 12:42:05 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf_s(CompatibilityIds[2], DEVICE_COMPATIBILITY_ID_SIZE, "USB\\DevClass_00");
|
2020-04-25 09:34:08 +03:00
|
|
|
sprintf_s(CompatibilityIds[1], DEVICE_COMPATIBILITY_ID_SIZE,
|
|
|
|
"USB\\DevClass_00&SubClass_00");
|
|
|
|
sprintf_s(CompatibilityIds[0], DEVICE_COMPATIBILITY_ID_SIZE,
|
|
|
|
"USB\\DevClass_00&SubClass_00&Prot_00");
|
2019-11-22 12:42:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func_instance_id_generate(pdev, strInstanceId, DEVICE_INSTANCE_STR_SIZE);
|
2012-04-25 22:26:35 +04:00
|
|
|
func_container_id_generate(pdev, strContainerId);
|
2019-11-22 12:42:05 +03:00
|
|
|
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));
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (pdev->isCompositeDevice(pdev))
|
2019-11-22 12:42:05 +03:00
|
|
|
cchCompatIds += composite_len + 1;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
size = 24;
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
2015-07-06 17:46:21 +03:00
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, strInstanceId, InstanceIdLen);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
|
|
|
Stream_Write_UINT32(out, HardwareIdsLen[0] + HardwareIdsLen[1] + 3); /* cchHwIds */
|
2012-04-25 22:26:35 +04:00
|
|
|
/* HardwareIds 1 */
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, HardwareIds[0], HardwareIdsLen[0]);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, HardwareIds[1], HardwareIdsLen[1]);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
|
|
|
Stream_Write_UINT16(out, 0); /* add "\0" */
|
|
|
|
Stream_Write_UINT32(out, (UINT32)cchCompatIds); /* cchCompatIds */
|
|
|
|
/* CompatibilityIds */
|
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, CompatibilityIds[0], CompatibilityIdLen[0]);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, CompatibilityIds[1], CompatibilityIdLen[1]);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, CompatibilityIds[2], CompatibilityIdLen[2]);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (pdev->isCompositeDevice(pdev))
|
2019-11-22 12:42:05 +03:00
|
|
|
{
|
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, composite_str, composite_len);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT16(out, 0x0000); /* add "\0" */
|
|
|
|
Stream_Write_UINT32(out, (UINT32)ContainerIdLen + 1); /* cchContainerId */
|
2012-04-25 22:26:35 +04:00
|
|
|
/* ContainerId */
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UTF16_String_From_Utf8(out, strContainerId, ContainerIdLen);
|
|
|
|
Stream_Write_UINT16(out, 0);
|
2012-04-25 22:26:35 +04:00
|
|
|
/* USB_DEVICE_CAPABILITIES 28 bytes */
|
2019-11-22 12:42:05 +03:00
|
|
|
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
|
2012-04-25 22:26:35 +04:00
|
|
|
/* Supported_USB_Version, 0x110,0x110 or 0x200(usb2.0) */
|
|
|
|
bcdUSB = pdev->query_device_descriptor(pdev, BCD_USB);
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, bcdUSB);
|
|
|
|
Stream_Write_UINT32(out, 0x00000000); /* HcdCapabilities, MUST always be zero */
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (bcdUSB < 0x200)
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0x00000000); /* DeviceIsHighSpeed */
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0x00000001); /* DeviceIsHighSpeed */
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0x50); /* NoAckIsochWriteJitterBufferSizeInMs, >=10 or <=512 */
|
|
|
|
return stream_write_and_free(callback->plugin, callback->channel, out);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_exchange_capabilities(URBDRC_CHANNEL_CALLBACK* callback, wStream* data)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 MessageId;
|
|
|
|
UINT32 FunctionId;
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 InterfaceId;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2019-11-22 13:47:16 +03:00
|
|
|
if (!data)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, data, 8))
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
Stream_Rewind_UINT32(data);
|
|
|
|
Stream_Read_UINT32(data, InterfaceId);
|
|
|
|
Stream_Read_UINT32(data, MessageId);
|
|
|
|
Stream_Read_UINT32(data, FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
switch (FunctionId)
|
|
|
|
{
|
|
|
|
case RIM_EXCHANGE_CAPABILITY_REQUEST:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_capability_request(callback, data, MessageId);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIMCALL_RELEASE:
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2015-07-06 17:46:21 +03:00
|
|
|
error = ERROR_NOT_FOUND;
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2020-02-28 15:45:26 +03:00
|
|
|
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);
|
2021-07-29 11:07:04 +03:00
|
|
|
UINT cerror =
|
2020-02-28 15:45:26 +03:00
|
|
|
urdbrc_send_virtual_channel_add(udevman->plugin, get_channel(udevman), deviceId);
|
|
|
|
|
2021-07-29 11:07:04 +03:00
|
|
|
if (cerror != ERROR_SUCCESS)
|
2020-02-28 15:45:26 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
udevman->loading_unlock(udevman);
|
|
|
|
|
|
|
|
return error == ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_device_control_channel(URBDRC_CHANNEL_CALLBACK* callback, wStream* s)
|
2017-11-14 18:10:52 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN* udevman = urbdrc->udevman;
|
2019-11-22 12:42:05 +03:00
|
|
|
IWTSVirtualChannel* channel = callback->channel;
|
2012-10-03 01:24:52 +04:00
|
|
|
IUDEVICE* pdev = NULL;
|
2019-11-22 12:42:05 +03:00
|
|
|
BOOL found = FALSE;
|
|
|
|
UINT error = ERROR_INTERNAL_ERROR;
|
|
|
|
UINT32 channelId = callback->channel_mgr->GetChannelId(channel);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
|
|
|
switch (urbdrc->vchannel_status)
|
|
|
|
{
|
2012-04-25 22:26:35 +04:00
|
|
|
case INIT_CHANNEL_IN:
|
2019-11-22 12:42:05 +03:00
|
|
|
/* Control channel was established */
|
|
|
|
error = ERROR_SUCCESS;
|
|
|
|
udevman->initialize(udevman, channelId);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2020-02-28 15:45:26 +03:00
|
|
|
if (!urbdrc_announce_devices(udevman))
|
|
|
|
goto fail;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
urbdrc->vchannel_status = INIT_CHANNEL_OUT;
|
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
|
|
|
case INIT_CHANNEL_OUT:
|
2019-11-22 12:42:05 +03:00
|
|
|
/* A new device channel was created, add the channel
|
|
|
|
* to the device */
|
2012-04-25 22:26:35 +04:00
|
|
|
udevman->loading_lock(udevman);
|
|
|
|
udevman->rewind(udevman);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2017-11-14 18:10:52 +03:00
|
|
|
while (udevman->has_next(udevman))
|
2012-10-03 01:24:52 +04:00
|
|
|
{
|
2012-04-25 22:26:35 +04:00
|
|
|
pdev = udevman->get_next(udevman);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (!pdev->isAlreadySend(pdev))
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
const UINT32 channelID = callback->channel_mgr->GetChannelId(channel);
|
|
|
|
found = TRUE;
|
2012-04-25 22:26:35 +04:00
|
|
|
pdev->setAlreadySend(pdev);
|
2019-11-22 12:42:05 +03:00
|
|
|
pdev->set_channelManager(pdev, callback->channel_mgr);
|
|
|
|
pdev->set_channelID(pdev, channelID);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
udevman->loading_unlock(udevman);
|
2019-11-22 12:42:05 +03:00
|
|
|
error = ERROR_SUCCESS;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (found && pdev->isAlreadySend(pdev))
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urdbrc_send_usb_device_add(callback, pdev);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "vchannel_status unknown value %" PRIu32 "",
|
|
|
|
urbdrc->vchannel_status);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
fail:
|
|
|
|
return error;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_channel_notification(URBDRC_CHANNEL_CALLBACK* callback, wStream* data)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 MessageId;
|
|
|
|
UINT32 FunctionId;
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 InterfaceId;
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2019-11-22 12:42:05 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !data)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, data, 8))
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
switch (FunctionId)
|
|
|
|
{
|
|
|
|
case CHANNEL_CREATED:
|
|
|
|
error = urbdrc_process_channel_create(callback, data, MessageId);
|
|
|
|
break;
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
case RIMCALL_RELEASE:
|
|
|
|
error = urbdrc_device_control_channel(callback, data);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_TRACE, "%s: unknown FunctionId 0x%" PRIX32 "",
|
|
|
|
__FUNCTION__, FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT urbdrc_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream* data)
|
2012-10-03 01:24:52 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
URBDRC_CHANNEL_CALLBACK* callback = (URBDRC_CHANNEL_CALLBACK*)pChannelCallback;
|
2012-10-03 01:24:52 +04:00
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
IUDEVMAN* udevman;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 InterfaceId;
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT error = ERROR_INTERNAL_ERROR;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
|
|
|
if (callback == NULL)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (callback->plugin == NULL)
|
2019-11-22 12:42:05 +03:00
|
|
|
return error;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (urbdrc->udevman == NULL)
|
2019-11-22 12:42:05 +03:00
|
|
|
return error;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
udevman = (IUDEVMAN*)urbdrc->udevman;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, data, 12))
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
urbdrc_dump_message(urbdrc->log, FALSE, FALSE, data);
|
|
|
|
Stream_Read_UINT32(data, InterfaceId);
|
|
|
|
|
|
|
|
/* Need to check InterfaceId and mask values */
|
2012-04-25 22:26:35 +04:00
|
|
|
switch (InterfaceId)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
case CAPABILITIES_NEGOTIATOR | (STREAM_ID_NONE << 30):
|
|
|
|
error = urbdrc_exchange_capabilities(callback, data);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
case SERVER_CHANNEL_NOTIFICATION | (STREAM_ID_PROXY << 30):
|
|
|
|
error = urbdrc_process_channel_notification(callback, data);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_udev_data_transfer(callback, urbdrc, udevman, data);
|
|
|
|
error = ERROR_SUCCESS; /* Ignore errors, the device may have been unplugged. */
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return error;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2017-11-14 18:10:52 +03:00
|
|
|
static UINT urbdrc_on_close(IWTSVirtualChannelCallback* pChannelCallback)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
URBDRC_CHANNEL_CALLBACK* callback = (URBDRC_CHANNEL_CALLBACK*)pChannelCallback;
|
2019-11-22 12:42:05 +03:00
|
|
|
if (callback)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
|
|
|
if (urbdrc)
|
2020-03-03 13:09:27 +03:00
|
|
|
{
|
|
|
|
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;
|
2020-08-10 14:30:41 +03:00
|
|
|
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);
|
|
|
|
}
|
2020-03-03 13:09:27 +03:00
|
|
|
}
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2019-11-22 12:42:05 +03:00
|
|
|
free(callback);
|
2015-07-06 17:46:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT urbdrc_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
|
2019-11-06 17:24:51 +03:00
|
|
|
IWTSVirtualChannel* pChannel, BYTE* pData,
|
|
|
|
BOOL* pbAccept,
|
|
|
|
IWTSVirtualChannelCallback** ppCallback)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
URBDRC_LISTENER_CALLBACK* listener_callback = (URBDRC_LISTENER_CALLBACK*)pListenerCallback;
|
2012-10-03 01:24:52 +04:00
|
|
|
URBDRC_CHANNEL_CALLBACK* callback;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
if (!ppCallback)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
callback = (URBDRC_CHANNEL_CALLBACK*)calloc(1, sizeof(URBDRC_CHANNEL_CALLBACK));
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
if (!callback)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2014-12-09 19:28:13 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
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;
|
2019-11-06 17:24:51 +03:00
|
|
|
*ppCallback = (IWTSVirtualChannelCallback*)callback;
|
2015-07-06 17:46:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT urbdrc_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-04-23 06:13:13 +03:00
|
|
|
UINT status;
|
2019-11-06 17:24:51 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin;
|
2020-05-20 09:59:44 +03:00
|
|
|
IUDEVMAN* udevman;
|
2019-11-22 12:42:05 +03:00
|
|
|
char channelName[sizeof(URBDRC_CHANNEL_NAME)] = { URBDRC_CHANNEL_NAME };
|
|
|
|
|
2020-05-20 09:59:44 +03:00
|
|
|
if (!urbdrc || !urbdrc->udevman)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2020-08-10 16:36:31 +03:00
|
|
|
if (urbdrc->initialized)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "[%s] channel initialized twice, aborting", URBDRC_CHANNEL_NAME);
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2020-05-20 09:59:44 +03:00
|
|
|
udevman = urbdrc->udevman;
|
2019-11-06 17:24:51 +03:00
|
|
|
urbdrc->listener_callback =
|
|
|
|
(URBDRC_LISTENER_CALLBACK*)calloc(1, sizeof(URBDRC_LISTENER_CALLBACK));
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
if (!urbdrc->listener_callback)
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
urbdrc->listener_callback->iface.OnNewChannelConnection = urbdrc_on_new_channel_connection;
|
|
|
|
urbdrc->listener_callback->plugin = pPlugin;
|
|
|
|
urbdrc->listener_callback->channel_mgr = pChannelMgr;
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
/* [MS-RDPEUSB] 2.1 Transport defines the channel name in uppercase letters */
|
|
|
|
CharUpperA(channelName);
|
2020-04-23 06:13:13 +03:00
|
|
|
status = pChannelMgr->CreateListener(pChannelMgr, channelName, 0,
|
2020-05-12 15:26:45 +03:00
|
|
|
&urbdrc->listener_callback->iface, &urbdrc->listener);
|
2020-04-23 06:13:13 +03:00
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
return status;
|
|
|
|
|
2020-08-10 16:36:31 +03:00
|
|
|
status = CHANNEL_RC_OK;
|
2020-04-23 06:13:13 +03:00
|
|
|
if (udevman->listener_created_callback)
|
2020-08-10 16:36:31 +03:00
|
|
|
status = udevman->listener_created_callback(udevman);
|
2020-04-23 06:13:13 +03:00
|
|
|
|
2020-08-10 16:36:31 +03:00
|
|
|
urbdrc->initialized = status == CHANNEL_RC_OK;
|
|
|
|
return status;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT urbdrc_plugin_terminated(IWTSPlugin* pPlugin)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin;
|
2019-11-22 12:42:05 +03:00
|
|
|
IUDEVMAN* udevman;
|
|
|
|
|
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_DATA;
|
2020-05-12 11:54:07 +03:00
|
|
|
if (urbdrc->listener_callback)
|
|
|
|
{
|
|
|
|
IWTSVirtualChannelManager* mgr = urbdrc->listener_callback->channel_mgr;
|
|
|
|
if (mgr)
|
2020-05-12 15:26:45 +03:00
|
|
|
IFCALL(mgr->DestroyListener, mgr, urbdrc->listener);
|
2020-05-12 11:54:07 +03:00
|
|
|
}
|
2019-11-22 12:42:05 +03:00
|
|
|
udevman = urbdrc->udevman;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (udevman)
|
|
|
|
{
|
|
|
|
udevman->free(udevman);
|
|
|
|
udevman = NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
free(urbdrc->subsystem);
|
|
|
|
free(urbdrc->listener_callback);
|
|
|
|
free(urbdrc);
|
2015-07-06 17:46:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static BOOL urbdrc_register_udevman_addin(IWTSPlugin* pPlugin, IUDEVMAN* udevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (urbdrc->udevman)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "existing device, abort.");
|
|
|
|
return FALSE;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_DVC("device registered.");
|
|
|
|
urbdrc->udevman = udevman;
|
2019-11-22 12:42:05 +03:00
|
|
|
return TRUE;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2020-11-18 09:51:45 +03:00
|
|
|
static UINT urbdrc_load_udevman_addin(IWTSPlugin* pPlugin, LPCSTR name, const ADDIN_ARGV* args)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)pPlugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
PFREERDP_URBDRC_DEVICE_ENTRY entry;
|
|
|
|
FREERDP_URBDRC_SERVICE_ENTRY_POINTS entryPoints;
|
2019-11-22 12:42:05 +03:00
|
|
|
entry = (PFREERDP_URBDRC_DEVICE_ENTRY)freerdp_load_channel_addin_entry(URBDRC_CHANNEL_NAME,
|
|
|
|
name, NULL, 0);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
if (!entry)
|
|
|
|
return ERROR_INVALID_OPERATION;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
entryPoints.plugin = pPlugin;
|
2012-11-21 04:34:52 +04:00
|
|
|
entryPoints.pRegisterUDEVMAN = urbdrc_register_udevman_addin;
|
|
|
|
entryPoints.args = args;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (entry(&entryPoints) != 0)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "%s entry returns error.", name);
|
2015-07-06 17:46:21 +03:00
|
|
|
return ERROR_INVALID_OPERATION;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static BOOL urbdrc_set_subsystem(URBDRC_PLUGIN* urbdrc, const char* subsystem)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2015-05-11 10:07:39 +03:00
|
|
|
free(urbdrc->subsystem);
|
2012-11-21 04:34:52 +04:00
|
|
|
urbdrc->subsystem = _strdup(subsystem);
|
2015-07-06 17:46:21 +03:00
|
|
|
return (urbdrc->subsystem != NULL);
|
2012-11-21 04:34:52 +04:00
|
|
|
}
|
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_addin_args(URBDRC_PLUGIN* urbdrc, const ADDIN_ARGV* args)
|
2012-11-21 04:34:52 +04:00
|
|
|
{
|
|
|
|
int status;
|
2019-11-06 17:24:51 +03:00
|
|
|
COMMAND_LINE_ARGUMENT_A urbdrc_args[] = {
|
|
|
|
{ "dbg", COMMAND_LINE_VALUE_FLAG, "", NULL, BoolValueFalse, -1, NULL, "debug" },
|
|
|
|
{ "sys", COMMAND_LINE_VALUE_REQUIRED, "<subsystem>", NULL, NULL, -1, NULL, "subsystem" },
|
2021-04-12 12:06:45 +03:00
|
|
|
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device list>", 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" },
|
2019-11-06 17:24:51 +03:00
|
|
|
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
|
|
|
};
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
const DWORD flags =
|
|
|
|
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
|
2021-09-07 09:31:07 +03:00
|
|
|
const COMMAND_LINE_ARGUMENT_A* arg;
|
2019-11-06 17:24:51 +03:00
|
|
|
status =
|
|
|
|
CommandLineParseArgumentsA(args->argc, args->argv, urbdrc_args, flags, urbdrc, NULL, NULL);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
if (status < 0)
|
|
|
|
return ERROR_INVALID_DATA;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
|
|
|
arg = urbdrc_args;
|
|
|
|
|
|
|
|
do
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
|
|
|
continue;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
CommandLineSwitchStart(arg) CommandLineSwitchCase(arg, "dbg")
|
2012-11-21 04:34:52 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_SetLogLevel(urbdrc->log, WLOG_TRACE);
|
2012-11-21 04:34:52 +04:00
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "sys")
|
|
|
|
{
|
2015-07-06 17:46:21 +03:00
|
|
|
if (!urbdrc_set_subsystem(urbdrc, arg->Value))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-11-21 04:34:52 +04:00
|
|
|
}
|
|
|
|
CommandLineSwitchDefault(arg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CommandLineSwitchEnd(arg)
|
2019-11-06 17:24:51 +03:00
|
|
|
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2020-02-28 15:45:26 +03:00
|
|
|
BOOL add_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum, UINT16 idVendor,
|
|
|
|
UINT16 idProduct)
|
2019-11-22 12:42:05 +03:00
|
|
|
{
|
|
|
|
size_t success = 0;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2020-02-28 15:45:26 +03:00
|
|
|
UINT32 mask, regflags = 0;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
if (!idevman)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
urbdrc = (URBDRC_PLUGIN*)idevman->plugin;
|
|
|
|
|
|
|
|
if (!urbdrc || !urbdrc->listener_callback)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-02-28 15:45:26 +03:00
|
|
|
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;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2020-02-28 15:45:26 +03:00
|
|
|
success = idevman->register_udevice(idevman, busnum, devnum, idVendor, idProduct, regflags);
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2020-02-28 15:45:26 +03:00
|
|
|
if ((success > 0) && (flags & DEVICE_ADD_FLAG_REGISTER))
|
2019-11-22 12:42:05 +03:00
|
|
|
{
|
2020-02-28 15:45:26 +03:00
|
|
|
if (!urbdrc_announce_devices(idevman))
|
|
|
|
return FALSE;
|
2019-11-22 12:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-03-02 10:40:40 +03:00
|
|
|
BOOL del_device(IUDEVMAN* idevman, UINT32 flags, BYTE busnum, BYTE devnum, UINT16 idVendor,
|
|
|
|
UINT16 idProduct)
|
2019-11-22 12:42:05 +03:00
|
|
|
{
|
|
|
|
IUDEVICE* pdev = NULL;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2020-03-02 10:40:40 +03:00
|
|
|
BOOL match = TRUE;
|
2019-11-22 12:42:05 +03:00
|
|
|
IUDEVICE* dev = idevman->get_next(idevman);
|
|
|
|
|
2020-03-02 10:40:40 +03:00
|
|
|
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)
|
2019-11-22 12:42:05 +03:00
|
|
|
{
|
|
|
|
pdev = dev;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdev)
|
|
|
|
pdev->setChannelClosed(pdev);
|
|
|
|
|
|
|
|
idevman->loading_unlock(idevman);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-10-14 10:38:58 +04:00
|
|
|
|
2015-08-27 15:25:09 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
2022-02-16 17:45:55 +03:00
|
|
|
UINT urbdrc_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2015-08-27 15:25:09 +03:00
|
|
|
UINT status = 0;
|
2020-11-18 09:51:45 +03:00
|
|
|
const ADDIN_ARGV* args;
|
2012-04-25 22:26:35 +04:00
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, URBDRC_CHANNEL_NAME);
|
2012-11-21 04:34:52 +04:00
|
|
|
args = pEntryPoints->GetPluginData(pEntryPoints);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (urbdrc == NULL)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)calloc(1, sizeof(URBDRC_PLUGIN));
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return CHANNEL_RC_NO_MEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
urbdrc->iface.Initialize = urbdrc_plugin_initialize;
|
|
|
|
urbdrc->iface.Terminated = urbdrc_plugin_terminated;
|
|
|
|
urbdrc->vchannel_status = INIT_CHANNEL_IN;
|
2021-10-07 16:50:57 +03:00
|
|
|
status = pEntryPoints->RegisterPlugin(pEntryPoints, URBDRC_CHANNEL_NAME, &urbdrc->iface);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2021-11-16 10:40:34 +03:00
|
|
|
/* After we register the plugin free will be taken care of by dynamic channel */
|
2015-07-06 17:46:21 +03:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2021-11-16 10:40:34 +03:00
|
|
|
{
|
|
|
|
free(urbdrc);
|
2019-11-22 12:42:05 +03:00
|
|
|
goto fail;
|
2021-11-16 10:40:34 +03:00
|
|
|
}
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
urbdrc->log = WLog_Get(TAG);
|
|
|
|
|
|
|
|
if (!urbdrc->log)
|
|
|
|
goto fail;
|
2015-07-06 17:46:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
status = urbdrc_process_addin_args(urbdrc, args);
|
2017-11-14 18:10:52 +03:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
if (status != CHANNEL_RC_OK)
|
2019-11-22 12:42:05 +03:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!urbdrc->subsystem && !urbdrc_set_subsystem(urbdrc, "libusb"))
|
|
|
|
goto fail;
|
|
|
|
|
2021-10-07 16:50:57 +03:00
|
|
|
return urbdrc_load_udevman_addin(&urbdrc->iface, urbdrc->subsystem, args);
|
2019-11-22 12:42:05 +03:00
|
|
|
fail:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT stream_write_and_free(IWTSPlugin* plugin, IWTSVirtualChannel* channel, wStream* out)
|
|
|
|
{
|
|
|
|
UINT rc;
|
|
|
|
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*)plugin;
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (!channel || !out || !urbdrc)
|
2015-07-06 17:46:21 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!channel->Write)
|
2015-07-06 17:46:21 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2015-07-06 17:46:21 +03:00
|
|
|
}
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc_dump_message(urbdrc->log, TRUE, TRUE, out);
|
|
|
|
rc = channel->Write(channel, Stream_GetPosition(out), Stream_Buffer(out), NULL);
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return rc;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|