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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
#include <winpr/sysinfo.h>
|
|
|
|
|
|
|
|
#include <urbdrc_helpers.h>
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
#include "urbdrc_types.h"
|
|
|
|
#include "data_transfer.h"
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static void usb_process_get_port_status(IUDEVICE* pdev, wStream* out)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int bcdUSB = pdev->query_device_descriptor(pdev, BCD_USB);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
|
|
|
switch (bcdUSB)
|
|
|
|
{
|
2012-04-25 22:26:35 +04:00
|
|
|
case USB_v1_0:
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0x303);
|
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
|
|
|
case USB_v1_1:
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0x103);
|
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
|
|
|
case USB_v2_0:
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0x503);
|
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
|
|
|
Stream_Write_UINT32(out, 0x503);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_write_completion(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, BOOL noAck,
|
|
|
|
wStream* out, UINT32 InterfaceId, UINT32 MessageId,
|
|
|
|
UINT32 RequestId, UINT32 usbd_status, UINT32 OutputBufferSize)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (Stream_Capacity(out) < OutputBufferSize + 36)
|
2012-04-25 22:26:35 +04: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
|
|
|
Stream_SetPosition(out, 0);
|
|
|
|
Stream_Write_UINT32(out, InterfaceId); /** interface */
|
|
|
|
Stream_Write_UINT32(out, MessageId); /** message id */
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (OutputBufferSize != 0)
|
|
|
|
Stream_Write_UINT32(out, URB_COMPLETION);
|
|
|
|
else
|
|
|
|
Stream_Write_UINT32(out, URB_COMPLETION_NO_DATA);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!noAck)
|
|
|
|
return stream_write_and_free(callback->plugin, callback->channel, out);
|
|
|
|
else
|
|
|
|
Stream_Free(out, TRUE);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static wStream* urb_create_iocompletion(UINT32 InterfaceField, UINT32 MessageId, UINT32 RequestId,
|
|
|
|
UINT32 OutputBufferSize)
|
|
|
|
{
|
|
|
|
const UINT32 InterfaceId = (STREAM_ID_PROXY << 30) | (InterfaceField & 0x3FFFFFFF);
|
|
|
|
wStream* out = Stream_New(NULL, OutputBufferSize + 28);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_register_request_callback(IUDEVICE* pdev,
|
|
|
|
URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
IUDEVMAN* udevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 NumRequestCompletion = 0;
|
|
|
|
UINT32 RequestCompletion = 0;
|
2019-11-22 12:42:05 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "urbdrc_process_register_request_callback");
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) >= 8)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, NumRequestCompletion); /** must be 1 */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** RequestCompletion:
|
2019-11-06 17:24:51 +03:00
|
|
|
* unique Request Completion interface for the client to use */
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, RequestCompletion);
|
2012-04-25 22:26:35 +04:00
|
|
|
pdev->set_ReqCompletion(pdev, RequestCompletion);
|
|
|
|
}
|
2019-12-17 17:51:24 +03:00
|
|
|
else if (Stream_GetRemainingLength(s) >= 4) /** Unregister the device */
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, RequestCompletion);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (pdev->get_ReqCompletion(pdev) == RequestCompletion)
|
|
|
|
pdev->setChannelClosed(pdev);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
2019-11-22 12:42:05 +03:00
|
|
|
else
|
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_cancel_request(IUDEVICE* pdev, wStream* s, IUDEVMAN* udevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 CancelId;
|
2019-11-22 12:42:05 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)udevman->plugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
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_Read_UINT32(s, CancelId);
|
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "CANCEL_REQUEST: CancelId=%08" PRIx32 "", CancelId);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (pdev->cancel_transfer_request(pdev, CancelId) < 0)
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_retract_device_request(IUDEVICE* pdev, wStream* s, IUDEVMAN* udevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 Reason;
|
2019-11-22 12:42:05 +03:00
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
|
|
|
|
if (!s || !udevman)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
urbdrc = (URBDRC_PLUGIN*)udevman->plugin;
|
|
|
|
|
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, Reason); /** Reason */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
switch (Reason)
|
|
|
|
{
|
|
|
|
case UsbRetractReason_BlockedByPolicy:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG,
|
|
|
|
"UsbRetractReason_BlockedByPolicy: now it is not support");
|
|
|
|
return ERROR_ACCESS_DENIED;
|
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_DEBUG,
|
|
|
|
"urbdrc_process_retract_device_request: Unknown Reason %" PRIu32 "", Reason);
|
|
|
|
return ERROR_ACCESS_DENIED;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_io_control(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 MessageId, IUDEVMAN* udevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 InterfaceId;
|
|
|
|
UINT32 IoControlCode;
|
|
|
|
UINT32 InputBufferSize;
|
|
|
|
UINT32 OutputBufferSize;
|
|
|
|
UINT32 RequestId;
|
|
|
|
UINT32 usbd_status = USBD_STATUS_SUCCESS;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
int success = 0;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, IoControlCode);
|
|
|
|
Stream_Read_UINT32(s, InputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2020-04-29 17:01:52 +03:00
|
|
|
if (!Stream_SafeSeek(s, InputBufferSize))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
if (Stream_GetRemainingLength(s) < 8ULL)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
|
|
|
Stream_Read_UINT32(s, RequestId);
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2020-08-13 14:51:38 +03:00
|
|
|
out = urb_create_iocompletion(InterfaceId, MessageId, RequestId, OutputBufferSize + 4);
|
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-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
switch (IoControlCode)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
case IOCTL_INTERNAL_USB_SUBMIT_URB: /** 0x00220003 */
|
2019-11-22 12:42:05 +03:00
|
|
|
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");
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case IOCTL_INTERNAL_USB_RESET_PORT: /** 0x00220007 */
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "ioctl: IOCTL_INTERNAL_USB_RESET_PORT");
|
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
|
|
|
case IOCTL_INTERNAL_USB_GET_PORT_STATUS: /** 0x00220013 */
|
2019-11-22 12:42:05 +03:00
|
|
|
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));
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
2020-08-13 14:51:38 +03:00
|
|
|
if (!Stream_SafeSeek(out, OutputBufferSize))
|
|
|
|
{
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev->isExist(pdev) == 0)
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0);
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2019-11-22 12:42:05 +03:00
|
|
|
usb_process_get_port_status(pdev, out);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case IOCTL_INTERNAL_USB_CYCLE_PORT: /** 0x0022001F */
|
2019-11-22 12:42:05 +03:00
|
|
|
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");
|
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
|
|
|
case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: /** 0x00220027 */
|
2019-11-22 12:42:05 +03:00
|
|
|
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");
|
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_DEBUG,
|
|
|
|
"urbdrc_process_io_control: unknown IoControlCode 0x%" PRIX32 "",
|
|
|
|
IoControlCode);
|
|
|
|
Stream_Free(out, TRUE);
|
2015-07-06 17:46:21 +03:00
|
|
|
return ERROR_INVALID_OPERATION;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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 urbdrc_process_internal_io_control(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 MessageId, IUDEVMAN* udevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
UINT32 IoControlCode, InterfaceId, InputBufferSize;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 OutputBufferSize, RequestId, frames;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev || !callback || !s || !udevman)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, IoControlCode);
|
|
|
|
Stream_Read_UINT32(s, InputBufferSize);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2020-04-29 17:01:52 +03:00
|
|
|
if (!Stream_SafeSeek(s, InputBufferSize))
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
if (Stream_GetRemainingLength(s) < 8ULL)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
|
|
|
Stream_Read_UINT32(s, RequestId);
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
// TODO: Implement control code.
|
2012-10-09 10:31:28 +04:00
|
|
|
/** Fixme: Currently this is a FALSE bustime... */
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_query_device_text(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 MessageId, IUDEVMAN* udevman)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 out_size;
|
|
|
|
UINT32 TextType;
|
|
|
|
UINT32 LocaleId;
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 InterfaceId;
|
|
|
|
UINT8 bufferSize = 0xFF;
|
|
|
|
UINT32 hr;
|
|
|
|
wStream* out;
|
|
|
|
BYTE DeviceDescription[0x100] = { 0 };
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev || !callback || !s || !udevman)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, TextType);
|
|
|
|
Stream_Read_UINT32(s, LocaleId);
|
|
|
|
if (LocaleId > UINT16_MAX)
|
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
|
|
|
if (bufferSize != 0)
|
2012-04-25 22:26:35 +04:00
|
|
|
out_size += 2;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void func_select_all_interface_for_msconfig(IUDEVICE* pdev,
|
|
|
|
MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-02-07 16:32:38 +03:00
|
|
|
UINT32 inum;
|
2012-10-03 01:24:52 +04:00
|
|
|
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = MsConfig->MsInterfaces;
|
2019-11-06 17:24:51 +03:00
|
|
|
BYTE InterfaceNumber, AlternateSetting;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 NumInterfaces = MsConfig->NumInterfaces;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
for (inum = 0; inum < NumInterfaces; inum++)
|
|
|
|
{
|
|
|
|
InterfaceNumber = MsInterfaces[inum]->InterfaceNumber;
|
|
|
|
AlternateSetting = MsInterfaces[inum]->AlternateSetting;
|
|
|
|
pdev->select_interface(pdev, InterfaceNumber, AlternateSetting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_select_configuration(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman,
|
|
|
|
int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
MSUSB_CONFIG_DESCRIPTOR* MsConfig = NULL;
|
2020-04-29 17:01:52 +03:00
|
|
|
size_t out_size;
|
|
|
|
UINT32 InterfaceId, NumInterfaces, usbd_status = 0;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE ConfigurationDescriptorIsValid;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
int MsOutSize = 0;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
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;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "urb_select_configuration: unsupported transfer out");
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT8(s, ConfigurationDescriptorIsValid);
|
|
|
|
Stream_Seek(s, 3); /* Padding */
|
|
|
|
Stream_Read_UINT32(s, NumInterfaces);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** if ConfigurationDescriptorIsValid is zero, then just do nothing.*/
|
|
|
|
if (ConfigurationDescriptorIsValid)
|
|
|
|
{
|
|
|
|
/* parser data for struct config */
|
2019-11-22 12:42:05 +03:00
|
|
|
MsConfig = msusb_msconfig_read(s, NumInterfaces);
|
|
|
|
|
|
|
|
if (!MsConfig)
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
/* select config */
|
|
|
|
pdev->select_configuration(pdev, MsConfig->bConfigurationValue);
|
|
|
|
/* select all interface */
|
|
|
|
func_select_all_interface_for_msconfig(pdev, MsConfig);
|
|
|
|
/* complete configuration setup */
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev->complete_msconfig_setup(pdev, MsConfig))
|
|
|
|
{
|
|
|
|
msusb_msconfig_free(MsConfig);
|
|
|
|
MsConfig = NULL;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (MsConfig)
|
|
|
|
MsOutSize = MsConfig->MsOutSize;
|
|
|
|
|
|
|
|
if (MsOutSize > 0)
|
2020-08-10 13:04:02 +03:00
|
|
|
{
|
|
|
|
if ((size_t)MsOutSize > SIZE_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
out_size = 36 + MsOutSize;
|
2020-08-10 13:04:02 +03:00
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
|
|
|
out_size = 44;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (MsOutSize > 0)
|
|
|
|
{
|
|
|
|
/** CbTsUrbResult */
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 8 + MsOutSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TS_URB_RESULT_HEADER Size*/
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT16(out, 8 + MsOutSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 16);
|
|
|
|
Stream_Write_UINT16(out, 16);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT16(out, TS_URB_SELECT_CONFIGURATION);
|
|
|
|
Stream_Write_UINT32(out, usbd_status); /** UsbdStatus */
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TS_URB_SELECT_CONFIGURATION_RESULT */
|
|
|
|
if (MsOutSize > 0)
|
2019-11-22 12:42:05 +03:00
|
|
|
msusb_msconfig_write(MsConfig, out);
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0); /** ConfigurationHandle */
|
|
|
|
Stream_Write_UINT32(out, NumInterfaces); /** NumInterfaces */
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_select_interface(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman,
|
|
|
|
int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
MSUSB_CONFIG_DESCRIPTOR* MsConfig;
|
|
|
|
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 out_size, InterfaceId, ConfigurationHandle;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE InterfaceNumber;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
UINT32 interface_size;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
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;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "urb_select_interface: not support transfer out");
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, ConfigurationHandle);
|
|
|
|
MsInterface = msusb_msinterface_read(s);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if ((Stream_GetRemainingLength(s) < 4) || !MsInterface)
|
2021-04-27 11:04:47 +03:00
|
|
|
{
|
|
|
|
msusb_msinterface_free(MsInterface);
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2021-04-27 11:04:47 +03:00
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
pdev->select_interface(pdev, MsInterface->InterfaceNumber, MsInterface->AlternateSetting);
|
|
|
|
/* replace device's MsInterface */
|
|
|
|
MsConfig = pdev->get_MsConfig(pdev);
|
|
|
|
InterfaceNumber = MsInterface->InterfaceNumber;
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!msusb_msinterface_replace(MsConfig, InterfaceNumber, MsInterface))
|
|
|
|
{
|
|
|
|
msusb_msconfig_free(MsConfig);
|
|
|
|
return ERROR_BAD_CONFIGURATION;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
/* complete configuration setup */
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev->complete_msconfig_setup(pdev, MsConfig))
|
|
|
|
{
|
|
|
|
msusb_msconfig_free(MsConfig);
|
|
|
|
return ERROR_BAD_CONFIGURATION;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
MsInterface = MsConfig->MsInterfaces[InterfaceNumber];
|
|
|
|
interface_size = 16 + (MsInterface->NumberOfPipes * 20);
|
2019-11-06 17:24:51 +03:00
|
|
|
out_size = 36 + interface_size;
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TS_URB_RESULT_HEADER */
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT16(out, 8 + interface_size); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT16(out, TS_URB_SELECT_INTERFACE);
|
|
|
|
Stream_Write_UINT32(out, USBD_STATUS_SUCCESS); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TS_URB_SELECT_INTERFACE_RESULT */
|
2019-11-22 12:42:05 +03:00
|
|
|
msusb_msinterface_write(MsInterface, out);
|
|
|
|
Stream_Write_UINT32(out, 0); /** HResult */
|
|
|
|
Stream_Write_UINT32(out, 0); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!noAck)
|
|
|
|
return stream_write_and_free(callback->plugin, callback->channel, out);
|
|
|
|
else
|
|
|
|
Stream_Free(out, TRUE);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_control_transfer(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman,
|
|
|
|
int transferDir, int External)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 out_size, InterfaceId, EndpointAddress, PipeHandle;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 TransferFlags, OutputBufferSize, usbd_status, Timeout;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE bmRequestType, Request;
|
|
|
|
UINT16 Value, Index, length;
|
|
|
|
BYTE* buffer;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
Stream_Read_UINT32(s, PipeHandle);
|
|
|
|
Stream_Read_UINT32(s, TransferFlags); /** TransferFlags */
|
2012-04-25 22:26:35 +04:00
|
|
|
EndpointAddress = (PipeHandle & 0x000000ff);
|
|
|
|
Timeout = 2000;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
switch (External)
|
|
|
|
{
|
|
|
|
case URB_CONTROL_TRANSFER_EXTERNAL:
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
Stream_Read_UINT32(s, Timeout); /** TransferFlags */
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case URB_CONTROL_TRANSFER_NONEXTERNAL:
|
|
|
|
break;
|
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
/** SetupPacket 8 bytes */
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (length != OutputBufferSize)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "urb_control_transfer ERROR: buf != length");
|
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
2012-04-25 22:26:35 +04:00
|
|
|
/** Get Buffer Data */
|
2019-11-22 12:42:05 +03:00
|
|
|
buffer = Stream_Pointer(out);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
|
|
|
|
Stream_Copy(s, out, OutputBufferSize);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
/** process TS_URB_CONTROL_TRANSFER */
|
|
|
|
if (!pdev->control_transfer(pdev, RequestId, EndpointAddress, TransferFlags, bmRequestType,
|
|
|
|
Request, Value, Index, &usbd_status, &OutputBufferSize, buffer,
|
|
|
|
Timeout))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "control_transfer failed");
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static void urb_bulk_transfer_cb(IUDEVICE* pdev, URBDRC_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);
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Free(out, TRUE);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_bulk_or_interrupt_transfer(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 EndpointAddress, PipeHandle;
|
|
|
|
UINT32 TransferFlags, OutputBufferSize;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev || !callback || !s || !udevman)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, PipeHandle);
|
|
|
|
Stream_Read_UINT32(s, TransferFlags); /** TransferFlags */
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
EndpointAddress = (PipeHandle & 0x000000ff);
|
2019-11-22 12:42:05 +03:00
|
|
|
/** process TS_URB_BULK_OR_INTERRUPT_TRANSFER */
|
2021-06-22 15:30:46 +03:00
|
|
|
return 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);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static void urb_isoch_transfer_cb(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, wStream* out,
|
|
|
|
UINT32 InterfaceId, BOOL noAck, UINT32 MessageId,
|
|
|
|
UINT32 RequestId, UINT32 NumberOfPackets, UINT32 status,
|
|
|
|
UINT32 StartFrame, UINT32 ErrorCount, UINT32 OutputBufferSize)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!noAck)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, RequestId); /** RequestId */
|
|
|
|
Stream_Write_UINT32(out, 20 + packetSize); /** CbTsUrbResult */
|
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
|
|
|
Stream_Write_UINT16(out, 20 + packetSize); /** Size */
|
|
|
|
Stream_Write_UINT16(out, 0); /* Padding */
|
|
|
|
Stream_Write_UINT32(out, status); /** UsbdStatus */
|
|
|
|
Stream_Write_UINT32(out, StartFrame); /** StartFrame */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Write_UINT32(out, 0); /** HResult */
|
|
|
|
Stream_Write_UINT32(out, OutputBufferSize); /** OutputBufferSize */
|
|
|
|
Stream_Seek(out, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2020-07-09 13:20:48 +03:00
|
|
|
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
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_isoch_transfer(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman,
|
|
|
|
int transferDir)
|
|
|
|
{
|
|
|
|
UINT32 EndpointAddress;
|
|
|
|
UINT32 PipeHandle, TransferFlags, StartFrame, NumberOfPackets;
|
|
|
|
UINT32 ErrorCount, OutputBufferSize;
|
|
|
|
BYTE* packetDescriptorData;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev || !callback || !udevman)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 20)
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
|
|
|
|
2021-09-21 09:01:51 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < NumberOfPackets * 12ULL + 4ULL)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
|
|
|
|
packetDescriptorData = Stream_Pointer(s);
|
|
|
|
Stream_Seek(s, NumberOfPackets * 12);
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
|
|
|
return 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);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_control_descriptor_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, BYTE func_recipient, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-04-29 17:01:52 +03:00
|
|
|
size_t out_size;
|
|
|
|
UINT32 InterfaceId, OutputBufferSize, usbd_status;
|
2012-11-21 04:34:52 +04:00
|
|
|
BYTE bmRequestType, desc_index, desc_type;
|
|
|
|
UINT16 langId;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
|
|
|
|
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT8(s, desc_index);
|
|
|
|
Stream_Read_UINT8(s, desc_type);
|
|
|
|
Stream_Read_UINT16(s, langId);
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2020-04-29 17:01:52 +03:00
|
|
|
if (OutputBufferSize > UINT32_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
2019-11-22 12:42:05 +03:00
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
|
|
|
|
{
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < OutputBufferSize)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2020-04-29 17:01:52 +03:00
|
|
|
out_size = 36ULL + OutputBufferSize;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
2012-04-25 22:26:35 +04:00
|
|
|
bmRequestType = func_recipient;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
bmRequestType |= 0x80;
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
|
|
|
bmRequestType |= 0x00;
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Copy(s, out, OutputBufferSize);
|
|
|
|
Stream_Rewind(out, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "get error transferDir");
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
usbd_status = USBD_STATUS_STALL_PID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** process get usb device descriptor */
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev->control_transfer(pdev, RequestId, 0, 0, bmRequestType,
|
|
|
|
0x06, /* REQUEST_GET_DESCRIPTOR */
|
|
|
|
(desc_type << 8) | desc_index, langId, &usbd_status,
|
|
|
|
&OutputBufferSize, Stream_Pointer(out), 1000))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "get_descriptor failed");
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_control_get_status_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, BYTE func_recipient, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-04-29 17:01:52 +03:00
|
|
|
size_t out_size;
|
|
|
|
UINT32 InterfaceId, OutputBufferSize, usbd_status;
|
2012-11-21 04:34:52 +04:00
|
|
|
UINT16 Index;
|
|
|
|
BYTE bmRequestType;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (transferDir == 0)
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG,
|
|
|
|
"urb_control_get_status_request: transfer out not supported");
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
Stream_Read_UINT16(s, Index); /** Index */
|
|
|
|
Stream_Seek(s, 2);
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2020-04-29 17:01:52 +03:00
|
|
|
if (OutputBufferSize > UINT32_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
out_size = 36ULL + OutputBufferSize;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
|
|
|
bmRequestType = func_recipient | 0x80;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_control_vendor_or_class_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, BYTE func_type,
|
|
|
|
BYTE func_recipient, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 out_size, InterfaceId, TransferFlags, usbd_status;
|
2012-11-21 04:34:52 +04:00
|
|
|
UINT32 OutputBufferSize;
|
|
|
|
BYTE ReqTypeReservedBits, Request, bmRequestType;
|
|
|
|
UINT16 Value, Index, Padding;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
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;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 16)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
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_Read_UINT16(s, Padding); /** Padding */
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2020-04-29 17:01:52 +03:00
|
|
|
if (OutputBufferSize > UINT32_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
|
|
|
|
{
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < OutputBufferSize)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2020-04-29 17:01:52 +03:00
|
|
|
out_size = 36ULL + OutputBufferSize;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Get Buffer */
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
|
2019-11-22 12:42:05 +03:00
|
|
|
{
|
|
|
|
Stream_Copy(s, out, OutputBufferSize);
|
|
|
|
Stream_Rewind(out, OutputBufferSize);
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** vendor or class command */
|
|
|
|
bmRequestType = func_type | func_recipient;
|
|
|
|
|
|
|
|
if (TransferFlags & USBD_TRANSFER_DIRECTION)
|
|
|
|
bmRequestType |= 0x80;
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev->control_transfer(pdev, RequestId, 0, 0, bmRequestType, Request, Value, Index,
|
|
|
|
&usbd_status, &OutputBufferSize, Stream_Pointer(out), 2000))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR, "control_transfer failed");
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_os_feature_descriptor_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-04-29 17:01:52 +03:00
|
|
|
size_t out_size;
|
|
|
|
UINT32 InterfaceId, OutputBufferSize, usbd_status;
|
2012-11-21 04:34:52 +04:00
|
|
|
BYTE Recipient, InterfaceNumber, Ms_PageIndex;
|
|
|
|
UINT16 Ms_featureDescIndex;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
int ret;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2020-04-29 17:01:52 +03:00
|
|
|
if (OutputBufferSize > UINT32_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < OutputBufferSize)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
break;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2020-04-29 17:01:52 +03:00
|
|
|
out_size = 36ULL + OutputBufferSize;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Copy(s, out, OutputBufferSize);
|
|
|
|
Stream_Rewind(out, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
/** get ms string */
|
2019-11-06 17:24:51 +03:00
|
|
|
ret = pdev->os_feature_descriptor_request(pdev, RequestId, Recipient, InterfaceNumber,
|
|
|
|
Ms_PageIndex, Ms_featureDescIndex, &usbd_status,
|
2019-11-22 12:42:05 +03:00
|
|
|
&OutputBufferSize, Stream_Pointer(out), 1000);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (ret < 0)
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "os_feature_descriptor_request: error num %d", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_pipe_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback, wStream* s,
|
|
|
|
UINT32 RequestField, UINT32 MessageId, IUDEVMAN* udevman,
|
|
|
|
int transferDir, int action)
|
|
|
|
{
|
|
|
|
UINT32 out_size, InterfaceId, PipeHandle, EndpointAddress;
|
|
|
|
UINT32 OutputBufferSize, usbd_status = 0;
|
|
|
|
wStream* out;
|
|
|
|
UINT32 ret = USBD_STATUS_REQUEST_FAILED;
|
|
|
|
int rc;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "urb_pipe_request: not support transfer out");
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, PipeHandle); /** PipeHandle */
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
EndpointAddress = (PipeHandle & 0x000000ff);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
switch (action)
|
|
|
|
{
|
2012-04-25 22:26:35 +04:00
|
|
|
case PIPE_CANCEL:
|
2019-11-22 12:42:05 +03:00
|
|
|
rc = pdev->control_pipe_request(pdev, RequestId, EndpointAddress, &usbd_status,
|
|
|
|
PIPE_CANCEL);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (rc < 0)
|
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "PIPE SET HALT: error %d", ret);
|
|
|
|
else
|
|
|
|
ret = USBD_STATUS_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (rc < 0)
|
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "PIPE RESET: error %d", ret);
|
|
|
|
else
|
|
|
|
ret = USBD_STATUS_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "urb_pipe_request action: %d not supported",
|
|
|
|
action);
|
|
|
|
ret = USBD_STATUS_INVALID_URB_FUNCTION;
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** send data */
|
2019-11-22 12:42:05 +03:00
|
|
|
out_size = 36;
|
|
|
|
out = Stream_New(NULL, out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId, ret,
|
|
|
|
0);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_get_current_frame_number(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 out_size, InterfaceId, OutputBufferSize;
|
2012-11-21 04:34:52 +04:00
|
|
|
UINT32 dummy_frames;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
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;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG,
|
|
|
|
"urb_get_current_frame_number: not support transfer out");
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2019-11-06 17:24:51 +03:00
|
|
|
/** Fixme: Need to fill actual frame number!!*/
|
2019-11-22 12:42:05 +03:00
|
|
|
dummy_frames = GetTickCount();
|
2012-04-25 22:26:35 +04:00
|
|
|
out_size = 40;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!noAck)
|
|
|
|
return stream_write_and_free(callback->plugin, callback->channel, out);
|
|
|
|
else
|
|
|
|
Stream_Free(out, TRUE);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_SUCCESS;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unused function for current server */
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_control_get_configuration_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-04-29 17:01:52 +03:00
|
|
|
size_t out_size;
|
|
|
|
UINT32 InterfaceId, OutputBufferSize, usbd_status;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG,
|
|
|
|
"urb_control_get_configuration_request:"
|
|
|
|
" not support transfer out");
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 4)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2020-04-29 17:01:52 +03:00
|
|
|
if (OutputBufferSize > UINT32_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
out_size = 36ULL + OutputBufferSize;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev->control_transfer(pdev, RequestId, 0, 0, 0x80 | 0x00,
|
|
|
|
0x08, /* REQUEST_GET_CONFIGURATION */
|
|
|
|
0, 0, &usbd_status, &OutputBufferSize, Stream_Pointer(out), 1000))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "control_transfer failed");
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Unused function for current server */
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_control_get_interface_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2020-04-29 17:01:52 +03:00
|
|
|
size_t out_size;
|
|
|
|
UINT32 InterfaceId, OutputBufferSize, usbd_status;
|
2012-11-21 04:34:52 +04:00
|
|
|
UINT16 interface;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
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;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG,
|
|
|
|
"urb_control_get_interface_request: not support transfer out");
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT16(s, interface);
|
|
|
|
Stream_Seek(s, 2);
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2020-04-29 17:01:52 +03:00
|
|
|
if (OutputBufferSize > UINT32_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
out_size = 36ULL + OutputBufferSize;
|
2019-11-22 12:42:05 +03:00
|
|
|
out = Stream_New(NULL, out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev->control_transfer(
|
|
|
|
pdev, RequestId, 0, 0, 0x80 | 0x01, 0x0A, /* REQUEST_GET_INTERFACE */
|
|
|
|
0, interface, &usbd_status, &OutputBufferSize, Stream_Pointer(out), 1000))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "control_transfer failed");
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urb_control_feature_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 RequestField, UINT32 MessageId,
|
|
|
|
IUDEVMAN* udevman, BYTE func_recipient, BYTE command,
|
|
|
|
int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 InterfaceId, OutputBufferSize, usbd_status;
|
2012-11-21 04:34:52 +04:00
|
|
|
UINT16 FeatureSelector, Index;
|
|
|
|
BYTE bmRequestType, bmRequest;
|
2019-11-22 12:42:05 +03:00
|
|
|
wStream* out;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
|
|
|
const BOOL noAck = (RequestField & 0x80000000U) != 0;
|
|
|
|
const UINT32 RequestId = RequestField & 0x7FFFFFFF;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
|
|
|
|
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Read_UINT16(s, FeatureSelector);
|
|
|
|
Stream_Read_UINT16(s, Index);
|
|
|
|
Stream_Read_UINT32(s, OutputBufferSize);
|
2020-04-29 17:01:52 +03:00
|
|
|
if (OutputBufferSize > UINT32_MAX - 36)
|
|
|
|
return ERROR_INVALID_DATA;
|
2019-11-22 12:42:05 +03:00
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < OutputBufferSize)
|
2019-11-22 12:42:05 +03:00
|
|
|
return ERROR_INVALID_DATA;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
break;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2020-04-29 17:01:52 +03:00
|
|
|
out = Stream_New(NULL, 36ULL + OutputBufferSize);
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
Stream_Seek(out, 36);
|
2012-04-25 22:26:35 +04:00
|
|
|
bmRequestType = func_recipient;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR,
|
|
|
|
"Function urb_control_feature_request: OUT Unchecked");
|
|
|
|
Stream_Copy(s, out, OutputBufferSize);
|
|
|
|
Stream_Rewind(out, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
bmRequestType |= 0x00;
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
bmRequestType |= 0x80;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case URB_SET_FEATURE:
|
|
|
|
bmRequest = 0x03; /* REQUEST_SET_FEATURE */
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case URB_CLEAR_FEATURE:
|
|
|
|
bmRequest = 0x01; /* REQUEST_CLEAR_FEATURE */
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_ERROR,
|
|
|
|
"urb_control_feature_request: Error Command 0x%02" PRIx8 "", command);
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!pdev->control_transfer(pdev, RequestId, 0, 0, bmRequestType, bmRequest, FeatureSelector,
|
|
|
|
Index, &usbd_status, &OutputBufferSize, Stream_Pointer(out), 1000))
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "feature control transfer failed");
|
|
|
|
Stream_Free(out, TRUE);
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return urb_write_completion(pdev, callback, noAck, out, InterfaceId, MessageId, RequestId,
|
|
|
|
usbd_status, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
static UINT urbdrc_process_transfer_request(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callback,
|
|
|
|
wStream* s, UINT32 MessageId, IUDEVMAN* udevman,
|
|
|
|
int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 CbTsUrb;
|
|
|
|
UINT16 Size;
|
|
|
|
UINT16 URB_Function;
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 RequestId;
|
|
|
|
UINT error = ERROR_INTERNAL_ERROR;
|
|
|
|
URBDRC_PLUGIN* urbdrc;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
if (!callback || !s || !udevman || !pdev)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
urbdrc = (URBDRC_PLUGIN*)callback->plugin;
|
|
|
|
|
|
|
|
if (!urbdrc)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2019-12-17 17:51:24 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
switch (URB_Function)
|
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
case TS_URB_SELECT_CONFIGURATION: /** 0x0000 */
|
|
|
|
error = urb_select_configuration(pdev, callback, s, RequestId, MessageId, udevman,
|
|
|
|
transferDir);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_SELECT_INTERFACE: /** 0x0001 */
|
2019-11-06 17:24:51 +03:00
|
|
|
error =
|
2019-11-22 12:42:05 +03:00
|
|
|
urb_select_interface(pdev, callback, s, RequestId, MessageId, udevman, transferDir);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_PIPE_REQUEST: /** 0x0002 */
|
|
|
|
error = urb_pipe_request(pdev, callback, s, RequestId, MessageId, udevman, transferDir,
|
|
|
|
PIPE_CANCEL);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
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. */
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
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);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
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 */
|
2019-11-06 17:24:51 +03:00
|
|
|
error =
|
2019-11-22 12:42:05 +03:00
|
|
|
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 */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x00, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_VENDOR_INTERFACE: /** 0x0018 */
|
|
|
|
error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId,
|
|
|
|
udevman, (0x02 << 5), /* vendor type */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x01, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_VENDOR_ENDPOINT: /** 0x0019 */
|
|
|
|
error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId,
|
|
|
|
udevman, (0x02 << 5), /* vendor type */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x02, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_CLASS_DEVICE: /** 0x001A */
|
|
|
|
error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId,
|
|
|
|
udevman, (0x01 << 5), /* class type */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x00, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_CLASS_INTERFACE: /** 0x001B */
|
|
|
|
error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId,
|
|
|
|
udevman, (0x01 << 5), /* class type */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x01, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_CLASS_ENDPOINT: /** 0x001C */
|
|
|
|
error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId,
|
|
|
|
udevman, (0x01 << 5), /* class type */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x02, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_RESERVE_0X001D: /** 0x001D */
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_SYNC_RESET_PIPE_AND_CLEAR_STALL: /** 0x001E */
|
|
|
|
error = urb_pipe_request(pdev, callback, s, RequestId, MessageId, udevman, transferDir,
|
|
|
|
PIPE_RESET);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_CLASS_OTHER: /** 0x001F */
|
|
|
|
error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId,
|
|
|
|
udevman, (0x01 << 5), /* class type */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x03, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_VENDOR_OTHER: /** 0x0020 */
|
|
|
|
error = urb_control_vendor_or_class_request(pdev, callback, s, RequestId, MessageId,
|
|
|
|
udevman, (0x02 << 5), /* vendor type */
|
2019-11-06 17:24:51 +03:00
|
|
|
0x03, transferDir);
|
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_GET_STATUS_FROM_OTHER: /** 0x0021 */
|
|
|
|
error = urb_control_get_status_request(pdev, callback, s, RequestId, MessageId, udevman,
|
|
|
|
0x03, transferDir);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
case TS_URB_CLEAR_FEATURE_TO_OTHER: /** 0x0022 */
|
|
|
|
error = urb_control_feature_request(pdev, callback, s, RequestId, MessageId, udevman,
|
|
|
|
0x03, URB_CLEAR_FEATURE, transferDir);
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
/** USB 2.0 calls start at 0x0030 */
|
2019-11-22 12:42:05 +03:00
|
|
|
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);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_DEBUG, "URB_Func: %" PRIx16 " is not found!",
|
|
|
|
URB_Function);
|
2012-11-21 04:34:52 +04:00
|
|
|
break;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2021-11-03 13:11:36 +03:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_Print(urbdrc->log, WLOG_WARN,
|
|
|
|
"USB transfer request URB Function %08" PRIx32 " failed with %08" PRIx32,
|
|
|
|
URB_Function, error);
|
|
|
|
}
|
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT urbdrc_process_udev_data_transfer(URBDRC_CHANNEL_CALLBACK* callback, URBDRC_PLUGIN* urbdrc,
|
|
|
|
IUDEVMAN* udevman, wStream* data)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT32 InterfaceId;
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 MessageId;
|
|
|
|
UINT32 FunctionId;
|
|
|
|
IUDEVICE* pdev;
|
2019-11-22 12:42:05 +03:00
|
|
|
UINT error = ERROR_INTERNAL_ERROR;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
if (!urbdrc || !data || !callback || !udevman)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
len = Stream_GetRemainingLength(data);
|
|
|
|
|
2019-11-22 13:47:16 +03:00
|
|
|
if (len < 8)
|
2019-11-22 12:42:05 +03:00
|
|
|
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)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2019-11-22 12:42:05 +03:00
|
|
|
error = ERROR_SUCCESS;
|
|
|
|
goto fail;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
/* Device has been removed, ignore this request. */
|
|
|
|
if (pdev->isChannelClosed(pdev))
|
|
|
|
{
|
|
|
|
error = ERROR_SUCCESS;
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/* USB kernel driver detach!! */
|
|
|
|
pdev->detach_kernel_driver(pdev);
|
|
|
|
|
|
|
|
switch (FunctionId)
|
|
|
|
{
|
|
|
|
case CANCEL_REQUEST:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_cancel_request(pdev, data, udevman);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case REGISTER_REQUEST_CALLBACK:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_register_request_callback(pdev, callback, data, udevman);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case IO_CONTROL:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_io_control(pdev, callback, data, MessageId, udevman);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case INTERNAL_IO_CONTROL:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_internal_io_control(pdev, callback, data, MessageId, udevman);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case QUERY_DEVICE_TEXT:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_query_device_text(pdev, callback, data, MessageId, udevman);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case TRANSFER_IN_REQUEST:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_transfer_request(pdev, callback, data, MessageId, udevman,
|
|
|
|
USBD_TRANSFER_DIRECTION_IN);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case TRANSFER_OUT_REQUEST:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_transfer_request(pdev, callback, data, MessageId, udevman,
|
|
|
|
USBD_TRANSFER_DIRECTION_OUT);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case RETRACT_DEVICE:
|
2019-11-22 12:42:05 +03:00
|
|
|
error = urbdrc_process_retract_device_request(pdev, data, udevman);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
2019-11-22 12:42:05 +03:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2019-11-22 12:42:05 +03:00
|
|
|
WLog_Print(urbdrc->log, WLOG_WARN,
|
|
|
|
"urbdrc_process_udev_data_transfer:"
|
|
|
|
" unknown FunctionId 0x%" PRIX32 "",
|
|
|
|
FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
fail:
|
2020-02-26 14:24:25 +03:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "USB request failed with %08" PRIx32, error);
|
|
|
|
}
|
|
|
|
|
2019-11-22 12:42:05 +03:00
|
|
|
return error;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|