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>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include "urbdrc_types.h"
|
|
|
|
#include "data_transfer.h"
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void usb_process_get_port_status(IUDEVICE* pdev, BYTE* OutputBuffer)
|
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:
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(OutputBuffer, 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:
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(OutputBuffer, 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:
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(OutputBuffer, 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:
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(OutputBuffer, 0x503);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ISOCH_FIFO
|
2012-10-03 01:24:52 +04:00
|
|
|
|
|
|
|
static int func_check_isochronous_fds(IUDEVICE* pdev)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* data_temp;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 size_temp, process_times = 2;
|
2012-10-03 01:24:52 +04:00
|
|
|
ISOCH_CALLBACK_QUEUE* isoch_queue = NULL;
|
|
|
|
ISOCH_CALLBACK_DATA* isoch = NULL;
|
|
|
|
URBDRC_CHANNEL_CALLBACK* callback;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
isoch_queue = (ISOCH_CALLBACK_QUEUE*) pdev->get_isoch_queue(pdev);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
while (process_times)
|
|
|
|
{
|
|
|
|
process_times--;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (isoch_queue == NULL || !pdev)
|
|
|
|
return -1;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
pthread_mutex_lock(&isoch_queue->isoch_loading);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (isoch_queue->head == NULL)
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&isoch_queue->isoch_loading);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
isoch = isoch_queue->head;
|
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (!isoch || !isoch->out_data)
|
|
|
|
{
|
|
|
|
pthread_mutex_unlock(&isoch_queue->isoch_loading);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
callback = (URBDRC_CHANNEL_CALLBACK*) isoch->callback;
|
2012-04-25 22:26:35 +04:00
|
|
|
size_temp = isoch->out_size;
|
|
|
|
data_temp = isoch->out_data;
|
|
|
|
|
|
|
|
ret = isoch_queue->unregister_data(isoch_queue, isoch);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (!ret)
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "isoch_queue_unregister_data: Not found isoch data!!");
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
pthread_mutex_unlock(&isoch_queue->isoch_loading);
|
|
|
|
|
|
|
|
if (pdev && !pdev->isSigToEnd(pdev))
|
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
callback->channel->Write(callback->channel, size_temp, data_temp, NULL);
|
2012-04-25 22:26:35 +04:00
|
|
|
zfree(data_temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
#endif
|
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
static int urbdrc_process_register_request_callback(URBDRC_CHANNEL_CALLBACK* callback,
|
2012-10-09 11:26:39 +04:00
|
|
|
BYTE* data, UINT32 data_sizem, IUDEVMAN* udevman, UINT32 UsbDevice)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
IUDEVICE* pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 NumRequestCompletion = 0;
|
|
|
|
UINT32 RequestCompletion = 0;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_register_request_callback");
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (data_sizem >= 8)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, NumRequestCompletion); /** must be 1 */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** RequestCompletion:
|
|
|
|
* unique Request Completion interface for the client to use */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 4, RequestCompletion);
|
2012-04-25 22:26:35 +04:00
|
|
|
pdev->set_ReqCompletion(pdev, RequestCompletion);
|
|
|
|
}
|
|
|
|
else /** Unregister the device */
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestCompletion);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (1)//(pdev->get_ReqCompletion(pdev) == RequestCompletion)
|
|
|
|
{
|
|
|
|
/** The wrong driver may also receive this message, So we
|
|
|
|
* need some time(default 3s) to check the driver or delete
|
|
|
|
* it */
|
|
|
|
sleep(3);
|
|
|
|
callback->channel->Write(callback->channel, 0, NULL, NULL);
|
|
|
|
pdev->SigToEnd(pdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static int urbdrc_process_cancel_request(BYTE* data, UINT32 data_sizem, IUDEVMAN* udevman, UINT32 UsbDevice)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
IUDEVICE* pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 CancelId;
|
2012-10-03 01:24:52 +04:00
|
|
|
int error = 0;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, CancelId); /** RequestId */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_cancel_request: id 0x%"PRIx32"", CancelId);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error = pdev->cancel_transfer_request(pdev, CancelId);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static int urbdrc_process_retract_device_request(BYTE* data, UINT32 data_sizem, IUDEVMAN* udevman, UINT32 UsbDevice)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 Reason;
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_retract_device_request");
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, Reason); /** Reason */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
switch (Reason)
|
|
|
|
{
|
|
|
|
case UsbRetractReason_BlockedByPolicy:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "UsbRetractReason_BlockedByPolicy: now it is not support");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
break;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_retract_device_request: Unknown Reason %"PRIu32"", Reason);
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem, UINT32 MessageId, IUDEVMAN * udevman, UINT32 UsbDevice)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
IUDEVICE* pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 out_size;
|
|
|
|
UINT32 InterfaceId;
|
|
|
|
UINT32 IoControlCode;
|
|
|
|
UINT32 InputBufferSize;
|
|
|
|
UINT32 OutputBufferSize;
|
|
|
|
UINT32 RequestId;
|
|
|
|
UINT32 usbd_status = USBD_STATUS_SUCCESS;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* OutputBuffer;
|
|
|
|
BYTE* out_data;
|
2012-10-03 01:24:52 +04:00
|
|
|
int i, offset, success = 0;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process__io_control");
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, IoControlCode);
|
|
|
|
data_read_UINT32(data + 4, InputBufferSize);
|
|
|
|
data_read_UINT32(data + 8 + InputBufferSize, OutputBufferSize);
|
|
|
|
data_read_UINT32(data + 12 + InputBufferSize, RequestId);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
|
|
|
/** process */
|
2015-07-06 17:46:21 +03:00
|
|
|
OutputBuffer = (BYTE *)calloc(1, OutputBufferSize);
|
|
|
|
if (!OutputBuffer)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
switch (IoControlCode)
|
|
|
|
{
|
2012-04-25 22:26:35 +04:00
|
|
|
case IOCTL_INTERNAL_USB_SUBMIT_URB: /** 0x00220003 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "ioctl: IOCTL_INTERNAL_USB_SUBMIT_URB");
|
|
|
|
WLog_ERR(TAG, " Function IOCTL_INTERNAL_USB_SUBMIT_URB: 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_RESET_PORT: /** 0x00220007 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "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 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "ioctl: IOCTL_INTERNAL_USB_GET_PORT_STATUS");
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
success = pdev->query_device_port_status(pdev, &usbd_status, &OutputBufferSize, OutputBuffer);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
if (pdev->isExist(pdev) == 0)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(OutputBuffer, 0);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usb_process_get_port_status(pdev, OutputBuffer);
|
|
|
|
OutputBufferSize = 4;
|
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "PORT STATUS(fake!):0x%02"PRIx8"%02"PRIx8"%02"PRIx8"%02"PRIx8"",
|
2014-09-12 18:19:32 +04:00
|
|
|
OutputBuffer[3], OutputBuffer[2], OutputBuffer[1], OutputBuffer[0]);
|
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_CYCLE_PORT: /** 0x0022001F */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "ioctl: IOCTL_INTERNAL_USB_CYCLE_PORT");
|
|
|
|
WLog_ERR(TAG, " 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 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "ioctl: IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION");
|
|
|
|
WLog_ERR(TAG, " 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:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_io_control: unknown IoControlCode 0x%"PRIX32"", IoControlCode);
|
2013-08-29 17:30:22 +04:00
|
|
|
zfree(OutputBuffer);
|
2015-07-06 17:46:21 +03:00
|
|
|
return ERROR_INVALID_OPERATION;
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = 28;
|
|
|
|
out_size = offset + OutputBufferSize;
|
2015-07-06 17:46:21 +03:00
|
|
|
out_data = (BYTE *) calloc(1, out_size);
|
|
|
|
if (!out_data)
|
|
|
|
{
|
|
|
|
zfree(OutputBuffer);
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
|
|
|
data_write_UINT32(out_data + 8, IOCONTROL_COMPLETION); /** function id */
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, USBD_STATUS_SUCCESS); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 20, OutputBufferSize); /** Information */
|
|
|
|
data_write_UINT32(out_data + 24, OutputBufferSize); /** OutputBufferSize */
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
for (i = 0; i < OutputBufferSize; i++)
|
2012-10-03 01:24:52 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_BYTE(out_data + offset, OutputBuffer[i]); /** OutputBuffer */
|
2012-04-25 22:26:35 +04:00
|
|
|
offset += 1;
|
|
|
|
}
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
|
|
|
zfree(OutputBuffer);
|
|
|
|
|
2015-07-06 17:46:21 +03:00
|
|
|
return CHANNEL_RC_OK;
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int urbdrc_process_internal_io_control(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem, UINT32 MessageId, IUDEVMAN* udevman, UINT32 UsbDevice)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
IUDEVICE* pdev;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* out_data;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 out_size, IoControlCode, InterfaceId, InputBufferSize;
|
|
|
|
UINT32 OutputBufferSize, RequestId, frames;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, IoControlCode);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_internal_io_control:0x%"PRIx32"", IoControlCode);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 4, InputBufferSize);
|
|
|
|
data_read_UINT32(data + 8, OutputBufferSize);
|
|
|
|
data_read_UINT32(data + 12, RequestId);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
/** Fixme: Currently this is a FALSE bustime... */
|
2012-04-25 22:26:35 +04:00
|
|
|
urbdrc_get_mstime(frames);
|
|
|
|
|
|
|
|
out_size = 32;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
|
|
|
data_write_UINT32(out_data + 8, IOCONTROL_COMPLETION); /** function id */
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 20, 4); /** Information */
|
|
|
|
data_write_UINT32(out_data + 24, 4); /** OutputBufferSize */
|
|
|
|
data_write_UINT32(out_data + 28, frames); /** OutputBuffer */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int urbdrc_process_query_device_text(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem, UINT32 MessageId, IUDEVMAN* udevman, UINT32 UsbDevice)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
IUDEVICE* pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 out_size;
|
|
|
|
UINT32 InterfaceId;
|
|
|
|
UINT32 TextType;
|
|
|
|
UINT32 LocaleId;
|
|
|
|
UINT32 bufferSize = 1024;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* out_data;
|
|
|
|
BYTE DeviceDescription[bufferSize];
|
2012-10-03 01:24:52 +04:00
|
|
|
int out_offset;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_query_device_text");
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, TextType);
|
|
|
|
data_read_UINT32(data + 4, LocaleId);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
pdev->control_query_device_text(pdev, TextType, LocaleId, &bufferSize, DeviceDescription);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
InterfaceId = ((STREAM_ID_STUB << 30) | UsbDevice);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
out_offset = 16;
|
|
|
|
out_size = out_offset + 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
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE*) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-10-03 01:24:52 +04:00
|
|
|
|
|
|
|
if (bufferSize != 0)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, (bufferSize/2)+1); /** cchDeviceDescription */
|
2012-04-25 22:26:35 +04:00
|
|
|
out_offset = 12;
|
|
|
|
memcpy(out_data + out_offset, DeviceDescription, bufferSize);
|
|
|
|
out_offset += bufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + out_offset, 0x0000);
|
2012-04-25 22:26:35 +04:00
|
|
|
out_offset += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, 0); /** cchDeviceDescription */
|
2012-04-25 22:26:35 +04:00
|
|
|
out_offset = 12;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + out_offset, 0); /** HResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
static void func_select_all_interface_for_msconfig(IUDEVICE* pdev, MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
int inum;
|
|
|
|
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = MsConfig->MsInterfaces;
|
2012-10-09 11:01:37 +04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int urb_select_configuration(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem, UINT32 MessageId, IUDEVMAN* udevman, UINT32 UsbDevice, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
MSUSB_CONFIG_DESCRIPTOR * MsConfig = NULL;
|
2012-10-03 01:24:52 +04:00
|
|
|
IUDEVICE* pdev = NULL;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 out_size, InterfaceId, RequestId, NumInterfaces, usbd_status = 0;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE ConfigurationDescriptorIsValid;
|
|
|
|
BYTE* out_data;
|
2012-10-03 01:24:52 +04:00
|
|
|
int MsOutSize = 0, offset = 0;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "urb_select_configuration: not support transfer out");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_BYTE(data + 4, ConfigurationDescriptorIsValid);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 8, NumInterfaces);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 12;
|
|
|
|
|
|
|
|
/** if ConfigurationDescriptorIsValid is zero, then just do nothing.*/
|
|
|
|
if (ConfigurationDescriptorIsValid)
|
|
|
|
{
|
|
|
|
/* parser data for struct config */
|
|
|
|
MsConfig = msusb_msconfig_read(data + offset, data_sizem - offset, NumInterfaces);
|
|
|
|
/* select config */
|
|
|
|
pdev->select_configuration(pdev, MsConfig->bConfigurationValue);
|
|
|
|
/* select all interface */
|
|
|
|
func_select_all_interface_for_msconfig(pdev, MsConfig);
|
|
|
|
/* complete configuration setup */
|
|
|
|
MsConfig = pdev->complete_msconfig_setup(pdev, MsConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MsConfig)
|
|
|
|
MsOutSize = MsConfig->MsOutSize;
|
|
|
|
|
|
|
|
if (MsOutSize > 0)
|
|
|
|
out_size = 36 + MsOutSize;
|
|
|
|
else
|
|
|
|
out_size = 44;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA); /** function id */
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
2012-04-25 22:26:35 +04:00
|
|
|
if (MsOutSize > 0)
|
|
|
|
{
|
|
|
|
/** CbTsUrbResult */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 16, 8 + MsOutSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TS_URB_RESULT_HEADER Size*/
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 8 + MsOutSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 16, 16);
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 16);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_SELECT_CONFIGURATION);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 28;
|
|
|
|
/** TS_URB_SELECT_CONFIGURATION_RESULT */
|
|
|
|
if (MsOutSize > 0)
|
|
|
|
{
|
|
|
|
msusb_msconfig_write(MsConfig, out_data, &offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + offset, 0); /** ConfigurationHandle */
|
|
|
|
data_write_UINT32(out_data + offset + 4, NumInterfaces); /** NumInterfaces */
|
2012-04-25 22:26:35 +04:00
|
|
|
offset += 8;
|
|
|
|
}
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + offset, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + offset + 4, 0); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
static int urb_select_interface(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data, UINT32 data_sizem,
|
|
|
|
UINT32 MessageId, IUDEVMAN* udevman, UINT32 UsbDevice, 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;
|
|
|
|
IUDEVICE* pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 out_size, InterfaceId, RequestId, ConfigurationHandle;
|
|
|
|
UINT32 OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE InterfaceNumber;
|
|
|
|
BYTE* out_data;
|
2012-10-03 01:24:52 +04:00
|
|
|
int out_offset, interface_size;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "urb_select_interface: not support transfer out");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
|
|
|
data_read_UINT32(data + 4, ConfigurationHandle);
|
2012-10-03 01:24:52 +04:00
|
|
|
out_offset = 8;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
MsInterface = msusb_msinterface_read(data + out_offset, data_sizem - out_offset, &out_offset);
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + out_offset, 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;
|
|
|
|
msusb_msinterface_replace(MsConfig, InterfaceNumber, MsInterface);
|
|
|
|
|
|
|
|
/* complete configuration setup */
|
|
|
|
MsConfig = pdev->complete_msconfig_setup(pdev, MsConfig);
|
|
|
|
MsInterface = MsConfig->MsInterfaces[InterfaceNumber];
|
|
|
|
interface_size = 16 + (MsInterface->NumberOfPipes * 20);
|
|
|
|
|
|
|
|
out_size = 36 + interface_size ;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE*) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA); /** function id */
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 8 + interface_size); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 8 + interface_size); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_SELECT_INTERFACE);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, USBD_STATUS_SUCCESS); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
out_offset = 28;
|
|
|
|
|
|
|
|
/** TS_URB_SELECT_INTERFACE_RESULT */
|
|
|
|
msusb_msinterface_write(MsInterface, out_data + out_offset, &out_offset);
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + out_offset, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + out_offset + 4, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int urb_control_transfer(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem, UINT32 MessageId, IUDEVMAN* udevman, UINT32 UsbDevice, int transferDir, int External)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-10-03 01:24:52 +04:00
|
|
|
IUDEVICE* pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 out_size, RequestId, InterfaceId, EndpointAddress, PipeHandle;
|
|
|
|
UINT32 TransferFlags, OutputBufferSize, usbd_status, Timeout;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE bmRequestType, Request;
|
|
|
|
UINT16 Value, Index, length;
|
|
|
|
BYTE* buffer;
|
|
|
|
BYTE* out_data;
|
2012-10-03 01:24:52 +04:00
|
|
|
int offset, ret;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
|
|
|
data_read_UINT32(data + 4, PipeHandle);
|
|
|
|
data_read_UINT32(data + 8, TransferFlags); /** TransferFlags */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
EndpointAddress = (PipeHandle & 0x000000ff);
|
|
|
|
offset = 12;
|
|
|
|
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:
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + offset, Timeout); /** TransferFlags */
|
2012-04-25 22:26:35 +04:00
|
|
|
offset += 4;
|
|
|
|
break;
|
|
|
|
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 */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_BYTE(data + offset, bmRequestType);
|
|
|
|
data_read_BYTE(data + offset + 1, Request);
|
|
|
|
data_read_UINT16(data + offset + 2, Value);
|
|
|
|
data_read_UINT16(data + offset + 4, Index);
|
|
|
|
data_read_UINT16(data + offset + 6, length);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + offset + 8, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset += 12;
|
|
|
|
|
2012-10-03 01:24:52 +04:00
|
|
|
if (length != OutputBufferSize)
|
|
|
|
{
|
2014-09-15 21:39:08 +04:00
|
|
|
WLog_ERR(TAG, "urb_control_transfer ERROR: buf != length");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
/** Get Buffer Data */
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
|
|
|
|
memcpy(buffer, data + offset, OutputBufferSize);
|
|
|
|
|
|
|
|
/** process URB_FUNCTION_CONTROL_TRANSFER */
|
|
|
|
ret = pdev->control_transfer(
|
|
|
|
pdev, RequestId, EndpointAddress, TransferFlags,
|
|
|
|
bmRequestType,
|
|
|
|
Request,
|
|
|
|
Value,
|
|
|
|
Index,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
Timeout);
|
|
|
|
|
|
|
|
if (ret < 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "control_transfer: error num %d!!", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** send data */
|
|
|
|
offset = 36;
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_IN)
|
|
|
|
out_size = offset + OutputBufferSize;
|
|
|
|
else
|
|
|
|
out_size = offset;
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if(transferDir == USBD_TRANSFER_DIRECTION_IN && OutputBufferSize != 0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION); /** function id */
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 0x00000008); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 0x0008); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_CONTROL_TRANSFER);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
2012-10-03 01:24:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static int urb_bulk_or_interrupt_transfer(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem, UINT32 MessageId, IUDEVMAN* udevman, UINT32 UsbDevice, int transferDir)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
2012-11-13 20:19:17 +04:00
|
|
|
int offset;
|
|
|
|
BYTE* Buffer;
|
|
|
|
IUDEVICE* pdev;
|
|
|
|
BYTE* out_data;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, EndpointAddress, PipeHandle;
|
|
|
|
UINT32 TransferFlags, OutputBufferSize, usbd_status = 0;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-11-13 20:19:17 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-11-13 20:19:17 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY << 30) | pdev->get_ReqCompletion(pdev));
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
|
|
|
data_read_UINT32(data + 4, PipeHandle);
|
|
|
|
data_read_UINT32(data + 8, TransferFlags); /** TransferFlags */
|
|
|
|
data_read_UINT32(data + 12, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 16;
|
|
|
|
EndpointAddress = (PipeHandle & 0x000000ff);
|
|
|
|
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
|
|
|
|
out_size = 36;
|
|
|
|
else
|
|
|
|
out_size = 36 + OutputBufferSize;
|
|
|
|
|
2012-11-13 20:19:17 +04:00
|
|
|
Buffer = NULL;
|
|
|
|
out_data = (BYTE*) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
|
|
|
Buffer = data + offset;
|
|
|
|
break;
|
2012-11-13 20:19:17 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
Buffer = out_data + 36;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-13 20:19:17 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
/** process URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER */
|
|
|
|
pdev->bulk_or_interrupt_transfer(
|
|
|
|
pdev, RequestId, EndpointAddress,
|
|
|
|
TransferFlags,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
Buffer,
|
|
|
|
10000);
|
|
|
|
|
|
|
|
offset = 36;
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_IN)
|
|
|
|
out_size = offset + OutputBufferSize;
|
|
|
|
else
|
|
|
|
out_size = offset;
|
|
|
|
/** send data */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
if(transferDir == USBD_TRANSFER_DIRECTION_IN && OutputBufferSize != 0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION); /** function id */
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 0x00000008); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 0x0008); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (pdev && !pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_isoch_transfer(URBDRC_CHANNEL_CALLBACK * callback, BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
|
|
|
IUDEVICE * pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 RequestId, InterfaceId, EndpointAddress;
|
|
|
|
UINT32 PipeHandle, TransferFlags, StartFrame, NumberOfPackets;
|
|
|
|
UINT32 ErrorCount, OutputBufferSize, usbd_status = 0;
|
|
|
|
UINT32 RequestField, noAck = 0;
|
|
|
|
UINT32 out_size = 0;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * iso_buffer = NULL;
|
|
|
|
BYTE * iso_packets = NULL;
|
|
|
|
BYTE * out_data = NULL;
|
2012-04-25 22:26:35 +04:00
|
|
|
int offset, nullBuffer = 0, iso_status;
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
if (pdev->isSigToEnd(pdev))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestField);
|
2012-04-25 22:26:35 +04:00
|
|
|
RequestId = RequestField & 0x7fffffff;
|
|
|
|
noAck = (RequestField & 0x80000000)>>31;
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 4, PipeHandle);
|
2012-04-25 22:26:35 +04:00
|
|
|
EndpointAddress = (PipeHandle & 0x000000ff);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 8, TransferFlags); /** TransferFlags */
|
|
|
|
data_read_UINT32(data + 12, StartFrame); /** StartFrame */
|
|
|
|
data_read_UINT32(data + 16, NumberOfPackets); /** NumberOfPackets */
|
|
|
|
data_read_UINT32(data + 20, ErrorCount); /** ErrorCount */
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 24 + (NumberOfPackets * 12);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + offset, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
/** send data memory alloc */
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT) {
|
|
|
|
if (!noAck) {
|
|
|
|
out_size = 48 + (NumberOfPackets * 12);
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
iso_packets = out_data + 40;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
out_size = 48 + OutputBufferSize + (NumberOfPackets * 12);
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
iso_packets = out_data + 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (out_size)
|
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
|
|
|
/** Get Buffer Data */
|
|
|
|
//memcpy(iso_buffer, data + offset, OutputBufferSize);
|
|
|
|
iso_buffer = data + offset;
|
|
|
|
break;
|
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
iso_buffer = out_data + 48 + (NumberOfPackets * 12);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "urb_isoch_transfer: EndpointAddress: 0x%"PRIx32", "
|
|
|
|
"TransferFlags: 0x%"PRIx32", "
|
|
|
|
"StartFrame: 0x%"PRIx32", "
|
|
|
|
"NumberOfPackets: 0x%"PRIx32", "
|
|
|
|
"OutputBufferSize: 0x%"PRIx32" "
|
|
|
|
"RequestId: 0x%"PRIx32"",
|
|
|
|
EndpointAddress, TransferFlags, StartFrame,
|
|
|
|
NumberOfPackets, OutputBufferSize, RequestId);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
#if ISOCH_FIFO
|
|
|
|
ISOCH_CALLBACK_QUEUE * isoch_queue = NULL;
|
|
|
|
ISOCH_CALLBACK_DATA * isoch = NULL;
|
|
|
|
if(!noAck)
|
|
|
|
{
|
|
|
|
isoch_queue = (ISOCH_CALLBACK_QUEUE *)pdev->get_isoch_queue(pdev);
|
|
|
|
isoch = isoch_queue->register_data(isoch_queue, callback, pdev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
iso_status = pdev->isoch_transfer(
|
|
|
|
pdev, RequestId, EndpointAddress,
|
|
|
|
TransferFlags,
|
|
|
|
noAck,
|
|
|
|
&ErrorCount,
|
|
|
|
&usbd_status,
|
|
|
|
&StartFrame,
|
|
|
|
NumberOfPackets,
|
|
|
|
iso_packets,
|
|
|
|
&OutputBufferSize,
|
|
|
|
iso_buffer,
|
|
|
|
2000);
|
|
|
|
|
|
|
|
if(noAck)
|
|
|
|
{
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iso_status < 0)
|
|
|
|
nullBuffer = 1;
|
|
|
|
|
|
|
|
|
|
|
|
out_size = 48;
|
|
|
|
if (nullBuffer)
|
|
|
|
OutputBufferSize = 0;
|
|
|
|
else
|
|
|
|
out_size += OutputBufferSize + (NumberOfPackets * 12);
|
|
|
|
/* fill the send data */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
if(OutputBufferSize != 0 && !nullBuffer)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION); /** function id */
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 20 + (NumberOfPackets * 12)); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 20 + (NumberOfPackets * 12)); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_ISOCH_TRANSFER);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, StartFrame); /** StartFrame */
|
2012-04-25 22:26:35 +04:00
|
|
|
if (!nullBuffer)
|
|
|
|
{
|
|
|
|
/** NumberOfPackets */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 32, NumberOfPackets);
|
|
|
|
data_write_UINT32(out_data + 36, ErrorCount); /** ErrorCount */
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 40 + (NumberOfPackets * 12);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 32, 0); /** NumberOfPackets */
|
|
|
|
data_write_UINT32(out_data + 36, NumberOfPackets); /** ErrorCount */
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 40;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + offset, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + offset + 4, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
#if ISOCH_FIFO
|
|
|
|
if(!noAck){
|
|
|
|
pthread_mutex_lock(&isoch_queue->isoch_loading);
|
|
|
|
isoch->out_data = out_data;
|
|
|
|
isoch->out_size = out_size;
|
|
|
|
pthread_mutex_unlock(&isoch_queue->isoch_loading);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
zfree(out_data);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (nullBuffer)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_control_descriptor_request(URBDRC_CHANNEL_CALLBACK* callback,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE func_recipient,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, InterfaceId, RequestId, OutputBufferSize, usbd_status;
|
|
|
|
BYTE bmRequestType, desc_index, desc_type;
|
|
|
|
UINT16 langId;
|
|
|
|
BYTE* buffer;
|
|
|
|
BYTE* out_data;
|
|
|
|
int ret, offset;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_BYTE(data + 4, desc_index);
|
|
|
|
data_read_BYTE(data + 5, desc_type);
|
|
|
|
data_read_UINT16(data + 6, langId);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 8, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
bmRequestType = func_recipient;
|
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
bmRequestType |= 0x80;
|
|
|
|
break;
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
|
|
|
bmRequestType |= 0x00;
|
|
|
|
offset = 12;
|
|
|
|
memcpy(buffer, data + offset, OutputBufferSize);
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "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 */
|
|
|
|
|
|
|
|
ret = pdev->control_transfer(
|
|
|
|
pdev, RequestId, 0, 0, bmRequestType,
|
|
|
|
0x06, /* REQUEST_GET_DESCRIPTOR */
|
|
|
|
(desc_type << 8) | desc_index,
|
|
|
|
langId,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
1000);
|
|
|
|
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "get_descriptor: error num %d", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = 36;
|
|
|
|
out_size = offset + OutputBufferSize;
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION); /** function id */
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 0x00000008); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 0x0008); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_control_get_status_request(URBDRC_CHANNEL_CALLBACK * callback, BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE func_recipient,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, OutputBufferSize, usbd_status;
|
|
|
|
UINT16 Index;
|
|
|
|
BYTE bmRequestType;
|
|
|
|
BYTE* buffer;
|
|
|
|
BYTE* out_data;
|
|
|
|
int offset, ret;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (transferDir == 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urb_control_get_status_request: not support transfer out");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data + 4, Index); /** Index */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 8, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
bmRequestType = func_recipient | 0x80;
|
|
|
|
|
|
|
|
ret = pdev->control_transfer(
|
|
|
|
pdev, RequestId, 0, 0, bmRequestType,
|
|
|
|
0x00, /* REQUEST_GET_STATUS */
|
|
|
|
0,
|
|
|
|
Index,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
1000);
|
|
|
|
|
|
|
|
if (ret < 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "control_transfer: error num %d!!", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
usbd_status = USBD_STATUS_STALL_PID;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
usbd_status = USBD_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** send data */
|
|
|
|
offset = 36;
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_IN)
|
|
|
|
out_size = offset + OutputBufferSize;
|
|
|
|
else
|
|
|
|
out_size = offset;
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if(transferDir == USBD_TRANSFER_DIRECTION_IN && OutputBufferSize != 0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION); /** function id */
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId, include NoAck*/
|
|
|
|
data_write_UINT32(out_data + 16, 0x00000008); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 0x0008); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_VENDOR_DEVICE);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_control_vendor_or_class_request(URBDRC_CHANNEL_CALLBACK * callback,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE func_type,
|
|
|
|
BYTE func_recipient,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, TransferFlags, usbd_status;
|
|
|
|
UINT32 OutputBufferSize;
|
|
|
|
BYTE ReqTypeReservedBits, Request, bmRequestType;
|
|
|
|
UINT16 Value, Index, Padding;
|
|
|
|
BYTE* buffer;
|
|
|
|
BYTE* out_data;
|
|
|
|
int offset, ret;
|
2012-04-25 22:26:35 +04:00
|
|
|
/** control by vendor command */
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
|
|
|
data_read_UINT32(data + 4, TransferFlags); /** TransferFlags */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_BYTE(data + 8, ReqTypeReservedBits); /** ReqTypeReservedBids */
|
|
|
|
data_read_BYTE(data + 9, Request); /** Request */
|
|
|
|
data_read_UINT16(data + 10, Value); /** value */
|
|
|
|
data_read_UINT16(data + 12, Index); /** index */
|
|
|
|
data_read_UINT16(data + 14, Padding); /** Padding */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 16, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 20;
|
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
/** Get Buffer */
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_OUT)
|
|
|
|
memcpy(buffer, data + offset, OutputBufferSize);
|
|
|
|
|
|
|
|
/** vendor or class command */
|
|
|
|
bmRequestType = func_type | func_recipient;
|
|
|
|
|
|
|
|
if (TransferFlags & USBD_TRANSFER_DIRECTION)
|
|
|
|
bmRequestType |= 0x80;
|
|
|
|
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urb_control_vendor_or_class_request: "
|
2016-12-14 00:47:08 +03:00
|
|
|
"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);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
ret = pdev->control_transfer(
|
|
|
|
pdev, RequestId, 0, 0, bmRequestType,
|
|
|
|
Request,
|
|
|
|
Value,
|
|
|
|
Index,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
2000);
|
|
|
|
|
|
|
|
if (ret < 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "control_transfer: error num %d!!", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
usbd_status = USBD_STATUS_STALL_PID;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
usbd_status = USBD_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = 36;
|
|
|
|
if (transferDir == USBD_TRANSFER_DIRECTION_IN)
|
|
|
|
out_size = offset + OutputBufferSize;
|
|
|
|
else
|
|
|
|
out_size = offset;
|
|
|
|
/** send data */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if(transferDir == USBD_TRANSFER_DIRECTION_IN && OutputBufferSize != 0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION); /** function id */
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId, include NoAck*/
|
|
|
|
data_write_UINT32(out_data + 16, 0x00000008); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 0x0008); /** Size */
|
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_VENDOR_DEVICE); /** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_os_feature_descriptor_request(URBDRC_CHANNEL_CALLBACK * callback,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, OutputBufferSize, usbd_status;
|
|
|
|
BYTE Recipient, InterfaceNumber, Ms_PageIndex;
|
|
|
|
UINT16 Ms_featureDescIndex;
|
|
|
|
BYTE* out_data;
|
|
|
|
BYTE* buffer;
|
|
|
|
int offset, ret;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_BYTE(data + 4, Recipient); /** Recipient */
|
2015-03-28 03:08:36 +03:00
|
|
|
Recipient = (Recipient & 0x1f); /* XXX: origin: Recipient && 0x1f !? */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_BYTE(data + 5, InterfaceNumber); /** InterfaceNumber */
|
|
|
|
data_read_BYTE(data + 6, Ms_PageIndex); /** Ms_PageIndex */
|
|
|
|
data_read_UINT16(data + 7, Ms_featureDescIndex); /** Ms_featureDescIndex */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 12, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 16;
|
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Function urb_os_feature_descriptor_request: OUT Unchecked");
|
2012-04-25 22:26:35 +04:00
|
|
|
memcpy(buffer, data + offset, OutputBufferSize);
|
|
|
|
break;
|
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "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 */
|
|
|
|
ret = pdev->os_feature_descriptor_request(
|
|
|
|
pdev, RequestId, Recipient,
|
|
|
|
InterfaceNumber,
|
|
|
|
Ms_PageIndex,
|
|
|
|
Ms_featureDescIndex,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
1000);
|
|
|
|
|
|
|
|
if (ret < 0)
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "os_feature_descriptor_request: error num %d", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
offset = 36;
|
|
|
|
out_size = offset + OutputBufferSize;
|
|
|
|
/** send data */
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
if(OutputBufferSize!=0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION); /** function id */
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 0x00000008); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 0x0008); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
|
|
|
|
zfree(out_data);
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_pipe_request(URBDRC_CHANNEL_CALLBACK * callback, BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir,
|
|
|
|
int action)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, PipeHandle, EndpointAddress;
|
|
|
|
UINT32 OutputBufferSize, usbd_status = 0;
|
|
|
|
BYTE* out_data;
|
|
|
|
int out_offset, ret;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (transferDir == 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urb_pipe_request: not support transfer out");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
|
|
|
data_read_UINT32(data + 4, PipeHandle); /** PipeHandle */
|
|
|
|
data_read_UINT32(data + 8, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
EndpointAddress = (PipeHandle & 0x000000ff);
|
|
|
|
|
|
|
|
|
|
|
|
switch (action){
|
|
|
|
case PIPE_CANCEL:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "urb_pipe_request: PIPE_CANCEL 0x%"PRIx32"", EndpointAddress);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
ret = pdev->control_pipe_request(
|
|
|
|
pdev, RequestId, EndpointAddress,
|
|
|
|
&usbd_status,
|
|
|
|
PIPE_CANCEL);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "PIPE SET HALT: error num %d", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
case PIPE_RESET:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "urb_pipe_request: PIPE_RESET ep 0x%"PRIx32"", EndpointAddress);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
ret = pdev->control_pipe_request(
|
|
|
|
pdev, RequestId, EndpointAddress,
|
|
|
|
&usbd_status,
|
|
|
|
PIPE_RESET);
|
|
|
|
|
|
|
|
if (ret < 0)
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "PIPE RESET: error num %d!!", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urb_pipe_request action: %d is not support!", action);
|
2012-04-25 22:26:35 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** send data */
|
|
|
|
out_offset = 36;
|
|
|
|
out_size = out_offset + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 0x00000008); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 0x0008); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, 0); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
zfree(out_data);
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_get_current_frame_number(URBDRC_CHANNEL_CALLBACK* callback,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, OutputBufferSize;
|
|
|
|
UINT32 dummy_frames;
|
|
|
|
BYTE* out_data;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (transferDir == 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urb_get_current_frame_number: not support transfer out");
|
2012-04-25 22:26:35 +04:00
|
|
|
//exit(1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
|
|
|
data_read_UINT32(data + 4, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Fixme: Need to fill actual frame number!!*/
|
|
|
|
urbdrc_get_mstime(dummy_frames);
|
|
|
|
|
|
|
|
out_size = 40;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 12); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 12); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_GET_CURRENT_FRAME_NUMBER);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, USBD_STATUS_SUCCESS); /** UsbdStatus */
|
|
|
|
data_write_UINT32(out_data + 28, dummy_frames); /** FrameNumber */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 32, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 36, 0); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Unused function for current server */
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_control_get_configuration_request(URBDRC_CHANNEL_CALLBACK* callback,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, OutputBufferSize, usbd_status;
|
|
|
|
BYTE* buffer;
|
|
|
|
BYTE* out_data;
|
|
|
|
int ret, offset;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
if (transferDir == 0)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urb_control_get_configuration_request:"
|
|
|
|
" not support transfer out");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
|
|
|
data_read_UINT32(data + 4, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
ret = pdev->control_transfer(
|
|
|
|
pdev, RequestId, 0, 0, 0x80 | 0x00,
|
|
|
|
0x08, /* REQUEST_GET_CONFIGURATION */
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
1000);
|
|
|
|
|
|
|
|
if (ret < 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "control_transfer: error num %d", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
offset = 36;
|
|
|
|
out_size = offset + OutputBufferSize;
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (OutputBufferSize != 0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION);
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 8); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 8); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_GET_CONFIGURATION);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unused function for current server */
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_control_get_interface_request(URBDRC_CHANNEL_CALLBACK* callback,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, OutputBufferSize, usbd_status;
|
|
|
|
UINT16 interface;
|
|
|
|
BYTE* buffer;
|
|
|
|
BYTE* out_data;
|
|
|
|
int ret, offset;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (transferDir == 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urb_control_get_interface_request: not support transfer out");
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data + 4, interface);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 8, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
ret = pdev->control_transfer(pdev, RequestId, 0, 0, 0x80 | 0x01,
|
|
|
|
0x0A, /* REQUEST_GET_INTERFACE */
|
|
|
|
0,
|
|
|
|
interface,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
1000);
|
|
|
|
|
|
|
|
if (ret < 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "control_transfer: error num %d", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = 36;
|
|
|
|
out_size = offset + OutputBufferSize;
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (OutputBufferSize != 0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION);
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 8); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 8); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_GET_INTERFACE);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urb_control_feature_request(URBDRC_CHANNEL_CALLBACK * callback, BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE func_recipient,
|
|
|
|
BYTE command,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
2012-11-21 04:34:52 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
UINT32 out_size, RequestId, InterfaceId, OutputBufferSize, usbd_status;
|
|
|
|
UINT16 FeatureSelector, Index;
|
|
|
|
BYTE bmRequestType, bmRequest;
|
|
|
|
BYTE* buffer;
|
|
|
|
BYTE* out_data;
|
|
|
|
int ret, offset;
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
2012-11-21 04:34:52 +04:00
|
|
|
|
2012-04-25 22:26:35 +04:00
|
|
|
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, RequestId);
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data + 4, FeatureSelector);
|
|
|
|
data_read_UINT16(data + 6, Index);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 8, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
offset = 12;
|
|
|
|
|
|
|
|
out_size = 36 + OutputBufferSize;
|
2012-10-09 11:01:37 +04:00
|
|
|
out_data = (BYTE *) malloc(out_size);
|
2012-04-25 22:26:35 +04:00
|
|
|
memset(out_data, 0, out_size);
|
|
|
|
|
|
|
|
buffer = out_data + 36;
|
|
|
|
|
|
|
|
bmRequestType = func_recipient;
|
|
|
|
switch (transferDir)
|
|
|
|
{
|
|
|
|
case USBD_TRANSFER_DIRECTION_OUT:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Function urb_control_feature_request: OUT Unchecked");
|
2012-04-25 22:26:35 +04:00
|
|
|
memcpy(buffer, data + offset, OutputBufferSize);
|
|
|
|
bmRequestType |= 0x00;
|
|
|
|
break;
|
|
|
|
case USBD_TRANSFER_DIRECTION_IN:
|
|
|
|
bmRequestType |= 0x80;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case URB_SET_FEATURE:
|
|
|
|
bmRequest = 0x03; /* REQUEST_SET_FEATURE */
|
|
|
|
break;
|
|
|
|
case URB_CLEAR_FEATURE:
|
|
|
|
bmRequest = 0x01; /* REQUEST_CLEAR_FEATURE */
|
|
|
|
break;
|
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "urb_control_feature_request: Error Command 0x%02"PRIx8"", command);
|
2013-08-29 17:30:22 +04:00
|
|
|
zfree(out_data);
|
2012-04-25 22:26:35 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = pdev->control_transfer(
|
|
|
|
pdev, RequestId, 0, 0, bmRequestType, bmRequest,
|
|
|
|
FeatureSelector,
|
|
|
|
Index,
|
|
|
|
&usbd_status,
|
|
|
|
&OutputBufferSize,
|
|
|
|
buffer,
|
|
|
|
1000);
|
|
|
|
|
|
|
|
if (ret < 0){
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "feature control transfer: error num %d", ret);
|
2012-04-25 22:26:35 +04:00
|
|
|
OutputBufferSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = 36;
|
|
|
|
out_size = offset + OutputBufferSize;
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 0, InterfaceId); /** interface */
|
|
|
|
data_write_UINT32(out_data + 4, MessageId); /** message id */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
if (OutputBufferSize != 0)
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION);
|
2012-04-25 22:26:35 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 8, URB_COMPLETION_NO_DATA);
|
|
|
|
data_write_UINT32(out_data + 12, RequestId); /** RequestId */
|
|
|
|
data_write_UINT32(out_data + 16, 8); /** CbTsUrbResult */
|
2012-04-25 22:26:35 +04:00
|
|
|
/** TsUrbResult TS_URB_RESULT_HEADER */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 20, 8); /** Size */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
/** Padding, MUST be ignored upon receipt */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_write_UINT16(out_data + 22, URB_FUNCTION_GET_INTERFACE);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 24, usbd_status); /** UsbdStatus */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_write_UINT32(out_data + 28, 0); /** HResult */
|
|
|
|
data_write_UINT32(out_data + 32, OutputBufferSize); /** OutputBufferSize */
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (!pdev->isSigToEnd(pdev))
|
|
|
|
callback->channel->Write(callback->channel, out_size, out_data, NULL);
|
|
|
|
zfree(out_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
static int urbdrc_process_transfer_request(URBDRC_CHANNEL_CALLBACK * callback, BYTE * data,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 data_sizem,
|
|
|
|
UINT32 MessageId,
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman,
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 UsbDevice,
|
2012-04-25 22:26:35 +04:00
|
|
|
int transferDir)
|
|
|
|
{
|
|
|
|
IUDEVICE * pdev;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 CbTsUrb;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 Size;
|
|
|
|
UINT16 URB_Function;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 OutputBufferSize;
|
2012-04-25 22:26:35 +04:00
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL)
|
|
|
|
return 0;
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 0, CbTsUrb); /** CbTsUrb */
|
2012-10-09 11:01:37 +04:00
|
|
|
data_read_UINT16(data + 4, Size); /** size */
|
|
|
|
data_read_UINT16(data + 6, URB_Function);
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(data + 4 + CbTsUrb, OutputBufferSize);
|
2012-04-25 22:26:35 +04:00
|
|
|
|
|
|
|
switch (URB_Function)
|
|
|
|
{
|
|
|
|
case URB_FUNCTION_SELECT_CONFIGURATION: /** 0x0000 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SELECT_CONFIGURATION");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_select_configuration(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SELECT_INTERFACE: /** 0x0001 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SELECT_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_select_interface(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_ABORT_PIPE: /** 0x0002 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_ABORT_PIPE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_pipe_request(
|
|
|
|
callback, data + 8, data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir,
|
|
|
|
PIPE_CANCEL);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL: /** 0x0003 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1; /** This URB function is obsolete in Windows 2000
|
|
|
|
* and later operating systems
|
|
|
|
* and is not supported by Microsoft. */
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL: /** 0x0004 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1; /** This URB function is obsolete in Windows 2000
|
|
|
|
* and later operating systems
|
|
|
|
* and is not supported by Microsoft. */
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_FRAME_LENGTH: /** 0x0005 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_FRAME_LENGTH");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1; /** This URB function is obsolete in Windows 2000
|
|
|
|
* and later operating systems
|
|
|
|
* and is not supported by Microsoft. */
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_FRAME_LENGTH: /** 0x0006 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_FRAME_LENGTH");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1; /** This URB function is obsolete in Windows 2000
|
|
|
|
* and later operating systems
|
|
|
|
* and is not supported by Microsoft. */
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_CURRENT_FRAME_NUMBER: /** 0x0007 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_CURRENT_FRAME_NUMBER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_get_current_frame_number(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CONTROL_TRANSFER: /** 0x0008 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CONTROL_TRANSFER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_transfer(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir,
|
|
|
|
URB_CONTROL_TRANSFER_NONEXTERNAL);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /** 0x0009 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_bulk_or_interrupt_transfer(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_ISOCH_TRANSFER: /** 0x000A */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_ISOCH_TRANSFER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_isoch_transfer(
|
|
|
|
callback, data + 8, data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE: /** 0x000B */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_descriptor_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x00,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE: /** 0x000C */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_descriptor_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x00,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_FEATURE_TO_DEVICE: /** 0x000D */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_FEATURE_TO_DEVICE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(callback,
|
|
|
|
data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x00,
|
|
|
|
URB_SET_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_FEATURE_TO_INTERFACE: /** 0x000E */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_FEATURE_TO_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x01,
|
|
|
|
URB_SET_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_FEATURE_TO_ENDPOINT: /** 0x000F */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_FEATURE_TO_ENDPOINT");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x02,
|
|
|
|
URB_SET_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE: /** 0x0010 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x00,
|
|
|
|
URB_CLEAR_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE: /** 0x0011 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x01,
|
|
|
|
URB_CLEAR_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT: /** 0x0012 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x02,
|
|
|
|
URB_CLEAR_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_STATUS_FROM_DEVICE: /** 0x0013 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_STATUS_FROM_DEVICE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_get_status_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x00,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_STATUS_FROM_INTERFACE: /** 0x0014 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_STATUS_FROM_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_get_status_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x01,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_STATUS_FROM_ENDPOINT: /** 0x0015 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_STATUS_FROM_ENDPOINT");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_get_status_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x02,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RESERVED_0X0016: /** 0x0016 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RESERVED_0X0016");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_VENDOR_DEVICE: /** 0x0017 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_VENDOR_DEVICE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x02 << 5), /* vendor type */
|
|
|
|
0x00,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_VENDOR_INTERFACE: /** 0x0018 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_VENDOR_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x02 << 5), /* vendor type */
|
|
|
|
0x01,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_VENDOR_ENDPOINT: /** 0x0019 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_VENDOR_ENDPOINT");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x02 << 5), /* vendor type */
|
|
|
|
0x02,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLASS_DEVICE: /** 0x001A */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLASS_DEVICE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x01 << 5), /* class type */
|
|
|
|
0x00,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLASS_INTERFACE: /** 0x001B */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLASS_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x01 << 5), /* class type */
|
|
|
|
0x01,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLASS_ENDPOINT: /** 0x001C */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLASS_ENDPOINT");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x01 << 5), /* class type */
|
|
|
|
0x02,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RESERVE_0X001D: /** 0x001D */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RESERVE_0X001D");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL: /** 0x001E */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_pipe_request(
|
|
|
|
callback, data + 8, data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir,
|
|
|
|
PIPE_RESET);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLASS_OTHER: /** 0x001F */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLASS_OTHER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x01 << 5), /* class type */
|
|
|
|
0x03,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_VENDOR_OTHER: /** 0x0020 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_VENDOR_OTHER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_vendor_or_class_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
(0x02 << 5), /* vendor type */
|
|
|
|
0x03,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_STATUS_FROM_OTHER: /** 0x0021 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_STATUS_FROM_OTHER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_get_status_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x03,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CLEAR_FEATURE_TO_OTHER: /** 0x0022 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CLEAR_FEATURE_TO_OTHER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x03,
|
|
|
|
URB_CLEAR_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_FEATURE_TO_OTHER: /** 0x0023 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_FEATURE_TO_OTHER");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_feature_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x03,
|
|
|
|
URB_SET_FEATURE,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT: /** 0x0024 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_descriptor_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x02,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT: /** 0x0025 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_descriptor_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x02,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_CONFIGURATION: /** 0x0026 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_CONFIGURATION");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_get_configuration_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_INTERFACE: /** 0x0027 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_get_interface_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE: /** 0x0028 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_descriptor_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x01,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE: /** 0x0029 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_descriptor_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
0x01,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR: /** 0x002A */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_os_feature_descriptor_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir);
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RESERVE_0X002B: /** 0x002B */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RESERVE_0X002B");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RESERVE_0X002C: /** 0x002C */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RESERVE_0X002C");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RESERVE_0X002D: /** 0x002D */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RESERVE_0X002D");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RESERVE_0X002E: /** 0x002E */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RESERVE_0X002E");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_RESERVE_0X002F: /** 0x002F */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_RESERVE_0X002F");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
/** USB 2.0 calls start at 0x0030 */
|
|
|
|
case URB_FUNCTION_SYNC_RESET_PIPE: /** 0x0030 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SYNC_RESET_PIPE");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_pipe_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir,
|
|
|
|
PIPE_RESET);
|
|
|
|
error = -9; /** function not support */
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_SYNC_CLEAR_STALL: /** 0x0031 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_SYNC_CLEAR_STALL");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_pipe_request(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir,
|
|
|
|
PIPE_RESET);
|
|
|
|
error = -9;
|
|
|
|
break;
|
|
|
|
case URB_FUNCTION_CONTROL_TRANSFER_EX: /** 0x0032 */
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "URB_Func: URB_FUNCTION_CONTROL_TRANSFER_EX");
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urb_control_transfer(
|
|
|
|
callback, data + 8,
|
|
|
|
data_sizem - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
transferDir,
|
|
|
|
URB_CONTROL_TRANSFER_EXTERNAL);
|
|
|
|
break;
|
|
|
|
default:
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "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
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2012-11-21 04:34:52 +04:00
|
|
|
void* urbdrc_process_udev_data_transfer(void* arg)
|
2012-04-25 22:26:35 +04:00
|
|
|
{
|
|
|
|
TRANSFER_DATA* transfer_data = (TRANSFER_DATA*) arg;
|
|
|
|
URBDRC_CHANNEL_CALLBACK * callback = transfer_data->callback;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE * pBuffer = transfer_data->pBuffer;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 cbSize = transfer_data->cbSize;
|
|
|
|
UINT32 UsbDevice = transfer_data->UsbDevice;
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVMAN * udevman = transfer_data->udevman;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 MessageId;
|
|
|
|
UINT32 FunctionId;
|
2012-04-25 22:26:35 +04:00
|
|
|
IUDEVICE* pdev;
|
|
|
|
int error = 0;
|
|
|
|
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
|
|
|
|
if (pdev == NULL || pdev->isSigToEnd(pdev))
|
|
|
|
{
|
2017-02-01 22:29:37 +03:00
|
|
|
if (transfer_data->pBuffer)
|
|
|
|
zfree(transfer_data->pBuffer);
|
|
|
|
zfree(transfer_data);
|
2012-04-25 22:26:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdev->push_action(pdev);
|
|
|
|
|
|
|
|
/* USB kernel driver detach!! */
|
|
|
|
pdev->detach_kernel_driver(pdev);
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
data_read_UINT32(pBuffer + 0, MessageId);
|
|
|
|
data_read_UINT32(pBuffer + 4, FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
switch (FunctionId)
|
|
|
|
{
|
|
|
|
case CANCEL_REQUEST:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>CANCEL_REQUEST<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_cancel_request(
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
udevman,
|
|
|
|
UsbDevice);
|
|
|
|
break;
|
|
|
|
case REGISTER_REQUEST_CALLBACK:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>REGISTER_REQUEST_CALLBACK<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_register_request_callback(
|
|
|
|
callback,
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
udevman,
|
|
|
|
UsbDevice);
|
|
|
|
break;
|
|
|
|
case IO_CONTROL:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>IO_CONTROL<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_io_control(
|
|
|
|
callback,
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman, UsbDevice);
|
|
|
|
break;
|
|
|
|
case INTERNAL_IO_CONTROL:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>INTERNAL_IO_CONTROL<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_internal_io_control(
|
|
|
|
callback,
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman, UsbDevice);
|
|
|
|
break;
|
|
|
|
case QUERY_DEVICE_TEXT:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>QUERY_DEVICE_TEXT<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_query_device_text(
|
|
|
|
callback,
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice);
|
|
|
|
break;
|
|
|
|
case TRANSFER_IN_REQUEST:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>TRANSFER_IN_REQUEST<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_transfer_request(
|
|
|
|
callback,
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
USBD_TRANSFER_DIRECTION_IN);
|
|
|
|
break;
|
|
|
|
case TRANSFER_OUT_REQUEST:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>TRANSFER_OUT_REQUEST<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_transfer_request(
|
|
|
|
callback,
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
MessageId,
|
|
|
|
udevman,
|
|
|
|
UsbDevice,
|
|
|
|
USBD_TRANSFER_DIRECTION_OUT);
|
|
|
|
break;
|
|
|
|
case RETRACT_DEVICE:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" >>RETRACT_DEVICE<<0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = urbdrc_process_retract_device_request(
|
|
|
|
pBuffer + 8,
|
|
|
|
cbSize - 8,
|
|
|
|
udevman,
|
|
|
|
UsbDevice);
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_DBG(TAG, "urbdrc_process_udev_data_transfer:"
|
2016-12-14 00:47:08 +03:00
|
|
|
" unknown FunctionId 0x%"PRIX32"", FunctionId);
|
2012-04-25 22:26:35 +04:00
|
|
|
error = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transfer_data)
|
|
|
|
{
|
|
|
|
if (transfer_data->pBuffer)
|
|
|
|
zfree(transfer_data->pBuffer);
|
|
|
|
zfree(transfer_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pdev)
|
|
|
|
{
|
|
|
|
#if ISOCH_FIFO
|
|
|
|
/* check isochronous fds */
|
|
|
|
func_check_isochronous_fds(pdev);
|
|
|
|
#endif
|
|
|
|
/* close this channel, if device is not found. */
|
|
|
|
pdev->complete_action(pdev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
udevman->push_urb(udevman);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
udevman->push_urb(udevman);
|
|
|
|
return 0;
|
|
|
|
}
|