urbdrc: code style cleanup

This commit is contained in:
Marc-André Moreau 2012-10-02 17:24:52 -04:00
parent dda32388ff
commit 299b780d13
4 changed files with 445 additions and 492 deletions

View File

@ -30,47 +30,52 @@
#include "urbdrc_types.h"
#include "data_transfer.h"
static void
usb_process_get_port_status(IUDEVICE * pdev, uint8 * OutputBuffer)
static void usb_process_get_port_status(IUDEVICE* pdev, uint8* OutputBuffer)
{
int bcdUSB = pdev->query_device_descriptor(pdev, BCD_USB);
switch (bcdUSB){
switch (bcdUSB)
{
case USB_v1_0:
data_write_uint32(OutputBuffer, 0x303);
break;
case USB_v1_1:
data_write_uint32(OutputBuffer, 0x103);
break;
case USB_v2_0:
data_write_uint32(OutputBuffer, 0x503);
break;
default:
data_write_uint32(OutputBuffer, 0x503);
break;
}
}
#if ISOCH_FIFO
static int
func_check_isochronous_fds(IUDEVICE * pdev)
static int func_check_isochronous_fds(IUDEVICE* pdev)
{
int ret = 0;
uint8* data_temp;
uint32 size_temp, process_times = 2;
ISOCH_CALLBACK_QUEUE* isoch_queue = NULL;
ISOCH_CALLBACK_DATA* isoch = NULL;
URBDRC_CHANNEL_CALLBACK* callback;
uint32 size_temp, process_times = 2;
uint8 * data_temp;
int ret = 0;
isoch_queue = (ISOCH_CALLBACK_QUEUE*) pdev->get_isoch_queue(pdev);
while (process_times)
{
process_times--;
if (isoch_queue == NULL || !pdev)
return -1;
pthread_mutex_lock(&isoch_queue->isoch_loading);
if (isoch_queue->head == NULL)
{
pthread_mutex_unlock(&isoch_queue->isoch_loading);
@ -80,6 +85,7 @@ func_check_isochronous_fds(IUDEVICE * pdev)
{
isoch = isoch_queue->head;
}
if (!isoch || !isoch->out_data)
{
pthread_mutex_unlock(&isoch_queue->isoch_loading);
@ -92,30 +98,27 @@ func_check_isochronous_fds(IUDEVICE * pdev)
data_temp = isoch->out_data;
ret = isoch_queue->unregister_data(isoch_queue, isoch);
if (!ret)
LLOGLN(0, ("isoch_queue_unregister_data: Not found isoch data!!\n"));
pthread_mutex_unlock(&isoch_queue->isoch_loading);
if (pdev && !pdev->isSigToEnd(pdev))
{
callback->channel->Write(callback->channel, size_temp,
data_temp, NULL);
callback->channel->Write(callback->channel, size_temp, data_temp, NULL);
zfree(data_temp);
}
}
}
}
return 0;
}
#endif
static int
urbdrc_process_register_request_callback(URBDRC_CHANNEL_CALLBACK * callback,
uint8 * data,
uint32 data_sizem,
IUDEVMAN * udevman,
uint32 UsbDevice)
static int urbdrc_process_register_request_callback(URBDRC_CHANNEL_CALLBACK* callback,
uint8* data, uint32 data_sizem, IUDEVMAN* udevman, uint32 UsbDevice)
{
IUDEVICE* pdev;
uint32 NumRequestCompletion = 0;
@ -124,6 +127,7 @@ urbdrc_process_register_request_callback(URBDRC_CHANNEL_CALLBACK * callback,
LLOGLN(urbdrc_debug, ("urbdrc_process_register_request_callback"));
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
@ -138,6 +142,7 @@ urbdrc_process_register_request_callback(URBDRC_CHANNEL_CALLBACK * callback,
else /** Unregister the device */
{
data_read_uint32(data + 0, RequestCompletion);
if (1)//(pdev->get_ReqCompletion(pdev) == RequestCompletion)
{
/** The wrong driver may also receive this message, So we
@ -152,10 +157,7 @@ urbdrc_process_register_request_callback(URBDRC_CHANNEL_CALLBACK * callback,
return 0;
}
static int
urbdrc_process_cancel_request(uint8 * data, uint32 data_sizem,
IUDEVMAN * udevman,
uint32 UsbDevice)
static int urbdrc_process_cancel_request(uint8* data, uint32 data_sizem, IUDEVMAN* udevman, uint32 UsbDevice)
{
IUDEVICE* pdev;
uint32 CancelId;
@ -166,6 +168,7 @@ urbdrc_process_cancel_request(uint8 * data, uint32 data_sizem,
LLOGLN(urbdrc_debug, ("urbdrc_process_cancel_request: id 0x%x", CancelId));
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
@ -174,10 +177,7 @@ urbdrc_process_cancel_request(uint8 * data, uint32 data_sizem,
return error;
}
static int
urbdrc_process_retract_device_request(uint8 * data, uint32 data_sizem,
IUDEVMAN * udevman,
uint32 UsbDevice)
static int urbdrc_process_retract_device_request(uint8* data, uint32 data_sizem, IUDEVMAN* udevman, uint32 UsbDevice)
{
uint32 Reason;
LLOGLN(urbdrc_debug, ("urbdrc_process_retract_device_request"));
@ -190,6 +190,7 @@ urbdrc_process_retract_device_request(uint8 * data, uint32 data_sizem,
LLOGLN(urbdrc_debug, ("UsbRetractReason_BlockedByPolicy: now it is not support"));
return -1;
break;
default:
LLOGLN(urbdrc_debug, ("urbdrc_process_retract_device_request: Unknown Reason %d", Reason));
return -1;
@ -199,12 +200,8 @@ urbdrc_process_retract_device_request(uint8 * data, uint32 data_sizem,
return 0;
}
static int
urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
uint32 data_sizem,
uint32 MessageId,
IUDEVMAN * udevman,
uint32 UsbDevice)
static int urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK* callback, uint8* data,
uint32 data_sizem, uint32 MessageId, IUDEVMAN * udevman, uint32 UsbDevice)
{
IUDEVICE* pdev;
uint32 out_size;
@ -226,30 +223,31 @@ urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
data_read_uint32(data + 12 + InputBufferSize, RequestId);
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
/** process */
OutputBuffer = (uint8 *)malloc(OutputBufferSize);
memset(OutputBuffer, 0, OutputBufferSize);
switch (IoControlCode){
switch (IoControlCode)
{
case IOCTL_INTERNAL_USB_SUBMIT_URB: /** 0x00220003 */
LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_SUBMIT_URB"));
printf(" Function IOCTL_INTERNAL_USB_SUBMIT_URB: Unchecked\n");
break;
case IOCTL_INTERNAL_USB_RESET_PORT: /** 0x00220007 */
LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_RESET_PORT"));
break;
case IOCTL_INTERNAL_USB_GET_PORT_STATUS: /** 0x00220013 */
LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_GET_PORT_STATUS"));
success = pdev->query_device_port_status(pdev, &usbd_status,
&OutputBufferSize,
OutputBuffer);
success = pdev->query_device_port_status(pdev, &usbd_status, &OutputBufferSize, OutputBuffer);
if (success)
{
@ -262,26 +260,29 @@ urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
usb_process_get_port_status(pdev, OutputBuffer);
OutputBufferSize = 4;
}
LLOGLN(urbdrc_debug, ("PORT STATUS(fake!):0x%02x%02x%02x%02x",
OutputBuffer[3], OutputBuffer[2], OutputBuffer[1], OutputBuffer[0]));
}
break;
case IOCTL_INTERNAL_USB_CYCLE_PORT: /** 0x0022001F */
LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_CYCLE_PORT"));
printf(" Function IOCTL_INTERNAL_USB_CYCLE_PORT: Unchecked\n");
break;
case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: /** 0x00220027 */
LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION"));
printf(" Function IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: Unchecked\n");
break;
default:
LLOGLN(urbdrc_debug, ("urbdrc_process_io_control: unknown IoControlCode 0x%X", IoControlCode));
return -1;
break;
}
offset = 28;
out_size = offset + OutputBufferSize;
out_data = (uint8 *) malloc(out_size);
@ -294,10 +295,12 @@ urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
data_write_uint32(out_data + 20, OutputBufferSize); /** Information */
data_write_uint32(out_data + 24, OutputBufferSize); /** OutputBufferSize */
for (i=0;i<OutputBufferSize;i++){
for (i=0;i<OutputBufferSize;i++)
{
data_write_uint8(out_data + offset, OutputBuffer[i]); /** OutputBuffer */
offset += 1;
}
if (!pdev->isSigToEnd(pdev))
callback->channel->Write(callback->channel, out_size, out_data, NULL);
@ -307,17 +310,13 @@ urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
return 0;
}
static int
urbdrc_process_internal_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
uint32 data_sizem,
uint32 MessageId,
IUDEVMAN * udevman,
uint32 UsbDevice)
static int urbdrc_process_internal_io_control(URBDRC_CHANNEL_CALLBACK* callback, uint8* data,
uint32 data_sizem, uint32 MessageId, IUDEVMAN* udevman, uint32 UsbDevice)
{
IUDEVICE* pdev;
uint8* out_data;
uint32 out_size, IoControlCode, InterfaceId, InputBufferSize;
uint32 OutputBufferSize, RequestId, frames;
uint8 * out_data;
data_read_uint32(data + 0, IoControlCode);
@ -328,8 +327,10 @@ urbdrc_process_internal_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * d
data_read_uint32(data + 12, RequestId);
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
InterfaceId = ((STREAM_ID_PROXY<<30) | pdev->get_ReqCompletion(pdev));
/** Fixme: Currently this is a false bustime... */
@ -347,7 +348,6 @@ urbdrc_process_internal_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * d
data_write_uint32(out_data + 24, 4); /** OutputBufferSize */
data_write_uint32(out_data + 28, frames); /** OutputBuffer */
if (!pdev->isSigToEnd(pdev))
callback->channel->Write(callback->channel, out_size, out_data, NULL);
@ -356,13 +356,8 @@ urbdrc_process_internal_io_control(URBDRC_CHANNEL_CALLBACK * callback, uint8 * d
return 0;
}
static int
urbdrc_process_query_device_text(URBDRC_CHANNEL_CALLBACK * callback,
uint8 * data,
uint32 data_sizem,
uint32 MessageId,
IUDEVMAN * udevman,
uint32 UsbDevice)
static int urbdrc_process_query_device_text(URBDRC_CHANNEL_CALLBACK* callback, uint8* data,
uint32 data_sizem, uint32 MessageId, IUDEVMAN* udevman, uint32 UsbDevice)
{
IUDEVICE* pdev;
uint32 out_size;
@ -380,28 +375,28 @@ urbdrc_process_query_device_text(URBDRC_CHANNEL_CALLBACK * callback,
data_read_uint32(data + 4, LocaleId);
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
pdev->control_query_device_text(
pdev,
TextType,
LocaleId,
&bufferSize,
DeviceDescription);
pdev->control_query_device_text(pdev, TextType, LocaleId, &bufferSize, DeviceDescription);
InterfaceId = ((STREAM_ID_STUB << 30) | UsbDevice);
out_offset = 16;
out_size = out_offset + bufferSize;
if (bufferSize != 0)
out_size += 2;
out_data = (uint8*) malloc(out_size);
memset(out_data, 0, out_size);
data_write_uint32(out_data + 0, InterfaceId); /** interface */
data_write_uint32(out_data + 4, MessageId); /** message id */
if (bufferSize != 0) {
if (bufferSize != 0)
{
data_write_uint32(out_data + 8, (bufferSize/2)+1); /** cchDeviceDescription */
out_offset = 12;
memcpy(out_data + out_offset, DeviceDescription, bufferSize);
@ -425,15 +420,12 @@ urbdrc_process_query_device_text(URBDRC_CHANNEL_CALLBACK * callback,
return 0;
}
static void
func_select_all_interface_for_msconfig(IUDEVICE * pdev, MSUSB_CONFIG_DESCRIPTOR * MsConfig)
static void func_select_all_interface_for_msconfig(IUDEVICE* pdev, MSUSB_CONFIG_DESCRIPTOR* MsConfig)
{
int inum;
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces = MsConfig->MsInterfaces;
uint8 InterfaceNumber, AlternateSetting;
uint32 NumInterfaces = MsConfig->NumInterfaces;
int inum;
for (inum = 0; inum < NumInterfaces; inum++)
{
@ -443,15 +435,8 @@ func_select_all_interface_for_msconfig(IUDEVICE * pdev, MSUSB_CONFIG_DESCRIPTOR
}
}
static int
urb_select_configuration(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
uint32 data_sizem,
uint32 MessageId,
IUDEVMAN * udevman,
uint32 UsbDevice,
int transferDir)
static int urb_select_configuration(URBDRC_CHANNEL_CALLBACK* callback, uint8* data,
uint32 data_sizem, uint32 MessageId, IUDEVMAN* udevman, uint32 UsbDevice, int transferDir)
{
MSUSB_CONFIG_DESCRIPTOR * MsConfig = NULL;
IUDEVICE* pdev = NULL;
@ -460,12 +445,14 @@ urb_select_configuration(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
uint8* out_data;
int MsOutSize = 0, offset = 0;
if (transferDir == 0){
if (transferDir == 0)
{
printf("urb_select_configuration: not support transfer out\n");
return -1;
}
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
@ -538,14 +525,8 @@ urb_select_configuration(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
return 0;
}
static int
urb_select_interface(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
uint32 data_sizem,
uint32 MessageId,
IUDEVMAN * udevman,
uint32 UsbDevice,
int transferDir)
static int urb_select_interface(URBDRC_CHANNEL_CALLBACK* callback, uint8* data, uint32 data_sizem,
uint32 MessageId, IUDEVMAN* udevman, uint32 UsbDevice, int transferDir)
{
MSUSB_CONFIG_DESCRIPTOR* MsConfig;
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
@ -556,12 +537,14 @@ urb_select_interface(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
uint8* out_data;
int out_offset, interface_size;
if (transferDir == 0){
if (transferDir == 0)
{
printf("urb_select_interface: not support transfer out\n");
return -1;
}
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
@ -590,6 +573,7 @@ urb_select_interface(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
out_size = 36 + interface_size ;
out_data = (uint8*) malloc(out_size);
memset(out_data, 0, out_size);
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 */
@ -612,19 +596,12 @@ urb_select_interface(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
callback->channel->Write(callback->channel, out_size, out_data, NULL);
zfree(out_data);
return 0;
}
static int
urb_control_transfer(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
uint32 data_sizem,
uint32 MessageId,
IUDEVMAN * udevman,
uint32 UsbDevice,
int transferDir,
int External)
static int urb_control_transfer(URBDRC_CHANNEL_CALLBACK* callback, uint8* data,
uint32 data_sizem, uint32 MessageId, IUDEVMAN* udevman, uint32 UsbDevice, int transferDir, int External)
{
IUDEVICE* pdev;
uint32 out_size, RequestId, InterfaceId, EndpointAddress, PipeHandle;
@ -636,6 +613,7 @@ urb_control_transfer(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
int offset, ret;
pdev = udevman->get_udevice_by_UsbDevice(udevman, UsbDevice);
if (pdev == NULL)
return 0;
@ -647,6 +625,7 @@ urb_control_transfer(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
EndpointAddress = (PipeHandle & 0x000000ff);
offset = 12;
Timeout = 2000;
switch (External)
{
case URB_CONTROL_TRANSFER_EXTERNAL:
@ -656,6 +635,7 @@ urb_control_transfer(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
case URB_CONTROL_TRANSFER_NONEXTERNAL:
break;
}
/** SetupPacket 8 bytes */
data_read_uint8(data + offset, bmRequestType);
data_read_uint8(data + offset + 1, Request);
@ -665,7 +645,8 @@ urb_control_transfer(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
data_read_uint32(data + offset + 8, OutputBufferSize);
offset += 12;
if (length != OutputBufferSize){
if (length != OutputBufferSize)
{
LLOGLN(urbdrc_debug, ("urb_control_transfer ERROR: buf != length"));
return -1;
}
@ -727,18 +708,12 @@ urb_control_transfer(URBDRC_CHANNEL_CALLBACK * callback, uint8 * data,
callback->channel->Write(callback->channel, out_size, out_data, NULL);
zfree(out_data);
return 0;
}
static int
urb_bulk_or_interrupt_transfer(URBDRC_CHANNEL_CALLBACK * callback,
uint8 * data,
uint32 data_sizem,
uint32 MessageId,
IUDEVMAN * udevman,
uint32 UsbDevice,
int transferDir)
static int urb_bulk_or_interrupt_transfer(URBDRC_CHANNEL_CALLBACK* callback, uint8* data,
uint32 data_sizem, uint32 MessageId, IUDEVMAN* udevman, uint32 UsbDevice, int transferDir)
{
IUDEVICE * pdev;
uint32 out_size, RequestId, InterfaceId, EndpointAddress, PipeHandle;

View File

@ -24,15 +24,12 @@
#include <unistd.h>
#include "isoch_queue.h"
static void
isoch_queue_rewind(ISOCH_CALLBACK_QUEUE * queue)
static void isoch_queue_rewind(ISOCH_CALLBACK_QUEUE* queue)
{
queue->curr = queue->head;
}
static int
isoch_queue_has_next(ISOCH_CALLBACK_QUEUE * queue)
static int isoch_queue_has_next(ISOCH_CALLBACK_QUEUE* queue)
{
if (queue->curr == NULL)
return 0;
@ -40,8 +37,7 @@ isoch_queue_has_next(ISOCH_CALLBACK_QUEUE * queue)
return 1;
}
static ISOCH_CALLBACK_DATA*
isoch_queue_get_next(ISOCH_CALLBACK_QUEUE * queue)
static ISOCH_CALLBACK_DATA* isoch_queue_get_next(ISOCH_CALLBACK_QUEUE* queue)
{
ISOCH_CALLBACK_DATA* isoch;
@ -51,12 +47,7 @@ isoch_queue_get_next(ISOCH_CALLBACK_QUEUE * queue)
return isoch;
}
static ISOCH_CALLBACK_DATA*
isoch_queue_register_data(ISOCH_CALLBACK_QUEUE* queue, void * callback,
void * dev)
static ISOCH_CALLBACK_DATA* isoch_queue_register_data(ISOCH_CALLBACK_QUEUE* queue, void* callback, void* dev)
{
ISOCH_CALLBACK_DATA* isoch;
@ -71,6 +62,7 @@ isoch_queue_register_data(ISOCH_CALLBACK_QUEUE* queue, void * callback,
isoch->callback = callback;
pthread_mutex_lock(&queue->isoch_loading);
if (queue->head == NULL)
{
/* linked queue is empty */
@ -85,18 +77,18 @@ isoch_queue_register_data(ISOCH_CALLBACK_QUEUE* queue, void * callback,
queue->tail = isoch;
}
queue->isoch_num += 1;
pthread_mutex_unlock(&queue->isoch_loading);
return isoch;
}
static int
isoch_queue_unregister_data(ISOCH_CALLBACK_QUEUE* queue, ISOCH_CALLBACK_DATA* isoch)
static int isoch_queue_unregister_data(ISOCH_CALLBACK_QUEUE* queue, ISOCH_CALLBACK_DATA* isoch)
{
ISOCH_CALLBACK_DATA* p;
queue->rewind(queue);
while (queue->has_next(queue) != 0)
{
p = queue->get_next(queue);
@ -145,15 +137,15 @@ isoch_queue_unregister_data(ISOCH_CALLBACK_QUEUE* queue, ISOCH_CALLBACK_DATA* is
return 0;
}
void
isoch_queue_free(ISOCH_CALLBACK_QUEUE * queue)
void isoch_queue_free(ISOCH_CALLBACK_QUEUE* queue)
{
ISOCH_CALLBACK_DATA* isoch;
pthread_mutex_lock(&queue->isoch_loading);
/** unregister all isochronous data*/
queue->rewind(queue);
while (queue->has_next(queue))
{
isoch = queue->get_next(queue);
@ -169,9 +161,7 @@ isoch_queue_free(ISOCH_CALLBACK_QUEUE * queue)
zfree(queue);
}
ISOCH_CALLBACK_QUEUE*
isoch_queue_new()
ISOCH_CALLBACK_QUEUE* isoch_queue_new()
{
ISOCH_CALLBACK_QUEUE* queue;

View File

@ -25,14 +25,12 @@
#include <unistd.h>
#include "searchman.h"
static void
searchman_rewind(USB_SEARCHMAN* searchman)
static void searchman_rewind(USB_SEARCHMAN* searchman)
{
searchman->idev = searchman->head;
}
static int
searchman_has_next(USB_SEARCHMAN* searchman)
static int searchman_has_next(USB_SEARCHMAN* searchman)
{
if (searchman->idev == NULL)
return 0;
@ -40,8 +38,7 @@ searchman_has_next(USB_SEARCHMAN* searchman)
return 1;
}
static USB_SEARCHDEV*
searchman_get_next(USB_SEARCHMAN* searchman)
static USB_SEARCHDEV* searchman_get_next(USB_SEARCHMAN* searchman)
{
USB_SEARCHDEV* search;
@ -51,10 +48,7 @@ searchman_get_next(USB_SEARCHMAN* searchman)
return search;
}
static int
searchman_list_add(USB_SEARCHMAN* searchman, uint16 idVendor, uint16 idProduct)
static int searchman_list_add(USB_SEARCHMAN* searchman, uint16 idVendor, uint16 idProduct)
{
USB_SEARCHDEV* search;
@ -83,15 +77,13 @@ searchman_list_add(USB_SEARCHMAN* searchman, uint16 idVendor, uint16 idProduct)
return 1;
}
static int
searchman_list_remove(USB_SEARCHMAN* searchman, uint16 idVendor,
uint16 idProduct)
static int searchman_list_remove(USB_SEARCHMAN* searchman, uint16 idVendor, uint16 idProduct)
{
USB_SEARCHDEV* search;
USB_SEARCHDEV* point;
searchman_rewind(searchman);
while (searchman_has_next(searchman) != 0)
{
point = searchman_get_next(searchman);
@ -139,10 +131,7 @@ searchman_list_remove(USB_SEARCHMAN* searchman, uint16 idVendor,
return 0;
}
static void
searchman_start(USB_SEARCHMAN* self, void * func)
static void searchman_start(USB_SEARCHMAN* self, void* func)
{
pthread_t thread;
@ -153,18 +142,15 @@ searchman_start(USB_SEARCHMAN* self, void * func)
}
/* close thread */
static void
searchman_close(USB_SEARCHMAN* self)
static void searchman_close(USB_SEARCHMAN* self)
{
wait_obj_set(self->term_event);
}
static void
searchman_list_show(USB_SEARCHMAN* self)
static void searchman_list_show(USB_SEARCHMAN* self)
{
USB_SEARCHDEV* usb;
int num = 0;
USB_SEARCHDEV* usb;
printf("=========== Usb Search List ========= \n");
self->rewind(self);
@ -178,9 +164,7 @@ searchman_list_show(USB_SEARCHMAN* self)
printf("================= END =============== \n");
}
void
searchman_free(USB_SEARCHMAN* self)
void searchman_free(USB_SEARCHMAN* self)
{
USB_SEARCHDEV * dev;
@ -196,12 +180,11 @@ searchman_free(USB_SEARCHMAN* self)
free(self);
}
USB_SEARCHMAN*
searchman_new(void * urbdrc, uint32 UsbDevice)
USB_SEARCHMAN* searchman_new(void * urbdrc, uint32 UsbDevice)
{
USB_SEARCHMAN* searchman;
int ret;
USB_SEARCHMAN* searchman;
searchman = (USB_SEARCHMAN*) malloc(sizeof(USB_SEARCHMAN));
searchman->idev = NULL;
@ -212,6 +195,7 @@ searchman_new(void * urbdrc, uint32 UsbDevice)
searchman->UsbDevice = UsbDevice;
ret = pthread_mutex_init(&searchman->mutex, NULL);
if (ret != 0)
{
printf("searchman mutex initialization: searchman->mutex failed");

View File

@ -35,8 +35,7 @@
int urbdrc_debug = 0;
static int
func_hardware_id_format(IUDEVICE * pdev, char (*HardwareIds)[DEVICE_HARDWARE_ID_SIZE])
static int func_hardware_id_format(IUDEVICE* pdev, char (*HardwareIds)[DEVICE_HARDWARE_ID_SIZE])
{
char str[DEVICE_HARDWARE_ID_SIZE];
int idVendor, idProduct, bcdDevice;
@ -55,9 +54,7 @@ func_hardware_id_format(IUDEVICE * pdev, char (*HardwareIds)[DEVICE_HARDWARE_ID_
return 0;
}
static int
func_compat_id_format(IUDEVICE *pdev, char (*CompatibilityIds)[DEVICE_COMPATIBILITY_ID_SIZE])
static int func_compat_id_format(IUDEVICE *pdev, char (*CompatibilityIds)[DEVICE_COMPATIBILITY_ID_SIZE])
{
char str[DEVICE_COMPATIBILITY_ID_SIZE];
int bDeviceClass, bDeviceSubClass, bDeviceProtocol;
@ -66,7 +63,8 @@ func_compat_id_format(IUDEVICE *pdev, char (*CompatibilityIds)[DEVICE_COMPATIBIL
bDeviceSubClass = pdev->query_device_descriptor(pdev, B_DEVICE_SUBCLASS);
bDeviceProtocol = pdev->query_device_descriptor(pdev, B_DEVICE_PROTOCOL);
if(!(pdev->isCompositeDevice(pdev))){
if(!(pdev->isCompositeDevice(pdev)))
{
sprintf(str, "USB\\Class_%02X", bDeviceClass);
strcpy(CompatibilityIds[2], str);
sprintf(str, "%s&SubClass_%02X", str, bDeviceSubClass);
@ -74,7 +72,8 @@ func_compat_id_format(IUDEVICE *pdev, char (*CompatibilityIds)[DEVICE_COMPATIBIL
sprintf(str, "%s&Prot_%02X", str, bDeviceProtocol);
strcpy(CompatibilityIds[0], str);
}
else{
else
{
sprintf(str, "USB\\DevClass_00");
strcpy(CompatibilityIds[2], str);
sprintf(str, "%s&SubClass_00", str);
@ -86,13 +85,11 @@ func_compat_id_format(IUDEVICE *pdev, char (*CompatibilityIds)[DEVICE_COMPATIBIL
return 0;
}
static void
func_close_udevice(USB_SEARCHMAN * searchman, IUDEVICE * pdev)
static void func_close_udevice(USB_SEARCHMAN* searchman, IUDEVICE* pdev)
{
URBDRC_PLUGIN * urbdrc = searchman->urbdrc;
int idVendor = 0;
int idProduct = 0;
URBDRC_PLUGIN* urbdrc = searchman->urbdrc;
pdev->SigToEnd(pdev);
idVendor = pdev->query_device_descriptor(pdev, ID_VENDOR);
@ -103,21 +100,21 @@ func_close_udevice(USB_SEARCHMAN * searchman, IUDEVICE * pdev)
pdev->wait_action_completion(pdev);
#if ISOCH_FIFO
{
/* free isoch queue */
ISOCH_CALLBACK_QUEUE* isoch_queue = pdev->get_isoch_queue(pdev);
if (isoch_queue)
isoch_queue->free(isoch_queue);
}
#endif
urbdrc->udevman->unregister_udevice(urbdrc->udevman,
pdev->get_bus_number(pdev),
pdev->get_dev_number(pdev));
//searchman->show(searchman);
}
static int
fun_device_string_send_set(char * out_data, int out_offset, char * str)
static int fun_device_string_send_set(char* out_data, int out_offset, char* str)
{
int i = 0;
int offset = 0;
@ -128,28 +125,31 @@ fun_device_string_send_set(char * out_data, int out_offset, char * str)
i++;
offset += 2;
}
data_write_uint16(out_data + out_offset + offset, 0x0000); /* add "\0" */
offset += 2;
return offset + out_offset;
}
static int
func_container_id_generate(IUDEVICE * pdev, char * strContainerId)
static int func_container_id_generate(IUDEVICE* pdev, char* strContainerId)
{
char containerId[17];
char *p, *path;
char containerId[17];
int idVendor, idProduct;
idVendor = pdev->query_device_descriptor(pdev, ID_VENDOR);
idProduct = pdev->query_device_descriptor(pdev, ID_PRODUCT);
path = pdev->getPath(pdev);
if (strlen(path) > 8)
p = (path + strlen(path)) - 8;
else
p = path;
sprintf(containerId, "%04X%04X%s", idVendor, idProduct, p);
/* format */
sprintf(strContainerId,
"{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
@ -161,14 +161,13 @@ func_container_id_generate(IUDEVICE * pdev, char * strContainerId)
return 0;
}
static int
func_instance_id_generate(IUDEVICE * pdev, char *strInstanceId)
static int func_instance_id_generate(IUDEVICE* pdev, char* strInstanceId)
{
char instanceId[17];
memset(instanceId, 0, 17);
sprintf(instanceId, "\\%s", pdev->getPath(pdev));
/* format */
sprintf(strInstanceId,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
@ -180,26 +179,27 @@ func_instance_id_generate(IUDEVICE * pdev, char *strInstanceId)
return 0;
}
#if ISOCH_FIFO
static void
func_lock_isoch_mutex(TRANSFER_DATA* transfer_data)
static void func_lock_isoch_mutex(TRANSFER_DATA* transfer_data)
{
IUDEVMAN * udevman = transfer_data->udevman;
int noAck = 0;
IUDEVICE* pdev;
uint32 FunctionId;
uint32 RequestField;
uint16 URB_Function;
int noAck = 0;
IUDEVMAN* udevman = transfer_data->udevman;
if (transfer_data->cbSize >= 8)
{
data_read_uint32(transfer_data->pBuffer + 4, FunctionId);
if ((FunctionId == TRANSFER_IN_REQUEST ||
FunctionId == TRANSFER_OUT_REQUEST) &&
transfer_data->cbSize >= 16)
{
data_read_uint16(transfer_data->pBuffer + 14, URB_Function);
if (URB_Function == URB_FUNCTION_ISOCH_TRANSFER &&
transfer_data->cbSize >= 20)
{
@ -208,20 +208,17 @@ func_lock_isoch_mutex(TRANSFER_DATA* transfer_data)
if (!noAck)
{
pdev = udevman->get_udevice_by_UsbDevice(udevman,
transfer_data->UsbDevice);
pdev = udevman->get_udevice_by_UsbDevice(udevman, transfer_data->UsbDevice);
pdev->lock_fifo_isoch(pdev);
}
}
}
}
}
#endif
static int
urbdrc_process_capability_request(URBDRC_CHANNEL_CALLBACK * callback,
char * data, uint32 data_sizem, uint32 MessageId)
static int urbdrc_process_capability_request(URBDRC_CHANNEL_CALLBACK* callback, char* data, uint32 data_sizem, uint32 MessageId)
{
uint32 InterfaceId;
uint32 Version;
@ -246,10 +243,7 @@ urbdrc_process_capability_request(URBDRC_CHANNEL_CALLBACK * callback,
return 0;
}
static int
urbdrc_process_channel_create(URBDRC_CHANNEL_CALLBACK * callback, char * data,
uint32 data_sizem,
uint32 MessageId)
static int urbdrc_process_channel_create(URBDRC_CHANNEL_CALLBACK* callback, char* data, uint32 data_sizem, uint32 MessageId)
{
uint32 InterfaceId;
uint32 out_size;
@ -280,9 +274,7 @@ urbdrc_process_channel_create(URBDRC_CHANNEL_CALLBACK * callback, char * data,
return 0;
}
static int
urdbrc_send_virtual_channel_add(IWTSVirtualChannel * channel, uint32 MessageId)
static int urdbrc_send_virtual_channel_add(IWTSVirtualChannel* channel, uint32 MessageId)
{
uint32 out_size;
uint32 InterfaceId;
@ -305,15 +297,12 @@ urdbrc_send_virtual_channel_add(IWTSVirtualChannel * channel, uint32 MessageId)
return 0;
}
static int
urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK * callback, IUDEVICE* pdev)
static int urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK* callback, IUDEVICE* pdev)
{
char* out_data;
uint32 InterfaceId;
char HardwareIds[2][DEVICE_HARDWARE_ID_SIZE];
char CompatibilityIds[3][DEVICE_COMPATIBILITY_ID_SIZE];
char * out_data;
char strContainerId[DEVICE_CONTAINER_STR_SIZE];
char strInstanceId[DEVICE_INSTANCE_STR_SIZE];
char* composite_str = "USB\\COMPOSITE";
@ -324,6 +313,7 @@ urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK * callback, IUDEVICE* pdev)
/* USB kernel driver detach!! */
pdev->detach_kernel_driver(pdev);
#if ISOCH_FIFO
/* create/initial isoch queue */
pdev->set_isoch_queue(pdev, (void *)isoch_queue_new());
@ -343,6 +333,7 @@ urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK * callback, IUDEVICE* pdev)
out_offset = 24;
size = 24;
size += (strlen(strInstanceId)+1) * 2 +
(strlen(HardwareIds[0]) + 1) * 2 + 4 +
(strlen(HardwareIds[1]) + 1) * 2 + 2 +
@ -351,6 +342,7 @@ urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK * callback, IUDEVICE* pdev)
out_data = (char*) malloc(size);
memset(out_data, 0, size);
data_write_uint32(out_data + 0, InterfaceId); /* interface */
data_write_uint32(out_data + 4, 0); /* message id */
data_write_uint32(out_data + 8, ADD_DEVICE); /* function id */
@ -393,14 +385,17 @@ urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK * callback, IUDEVICE* pdev)
data_write_uint32(out_data + out_offset, 0x0000001c); /* CbSize */
data_write_uint32(out_data + out_offset + 4, 2); /* UsbBusInterfaceVersion, 0 ,1 or 2 */
data_write_uint32(out_data + out_offset + 8, 0x600); /* USBDI_Version, 0x500 or 0x600 */
/* Supported_USB_Version, 0x110,0x110 or 0x200(usb2.0) */
bcdUSB = pdev->query_device_descriptor(pdev, BCD_USB);
data_write_uint32(out_data + out_offset + 12, bcdUSB);
data_write_uint32(out_data + out_offset + 16, 0x00000000); /* HcdCapabilities, MUST always be zero */
if (bcdUSB < 0x200)
data_write_uint32(out_data + out_offset + 20, 0x00000000); /* DeviceIsHighSpeed */
else
data_write_uint32(out_data + out_offset + 20, 0x00000001); /* DeviceIsHighSpeed */
data_write_uint32(out_data + out_offset + 24, 0x50); /* NoAckIsochWriteJitterBufferSizeInMs, >=10 or <=512 */
out_offset += 28;
@ -410,11 +405,7 @@ urdbrc_send_usb_device_add(URBDRC_CHANNEL_CALLBACK * callback, IUDEVICE* pdev)
return 0;
}
static int
urbdrc_exchange_capabilities(URBDRC_CHANNEL_CALLBACK * callback,
char * pBuffer,
uint32 cbSize)
static int urbdrc_exchange_capabilities(URBDRC_CHANNEL_CALLBACK* callback, char* pBuffer, uint32 cbSize)
{
uint32 MessageId;
uint32 FunctionId;
@ -427,23 +418,19 @@ urbdrc_exchange_capabilities(URBDRC_CHANNEL_CALLBACK * callback,
switch (FunctionId)
{
case RIM_EXCHANGE_CAPABILITY_REQUEST:
error = urbdrc_process_capability_request(callback,
pBuffer + 8,
cbSize - 8,
MessageId);
error = urbdrc_process_capability_request(callback, pBuffer + 8, cbSize - 8, MessageId);
break;
default:
LLOGLN(10, ("urbdrc_exchange_capabilities: unknown FunctionId 0x%X", FunctionId));
error = 1;
break;
}
return error;
}
static void *
urbdrc_search_usb_device(void * arg)
static void* urbdrc_search_usb_device(void* arg)
{
USB_SEARCHMAN* searchman = (USB_SEARCHMAN*) arg;
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*) searchman->urbdrc;
@ -468,7 +455,9 @@ urbdrc_search_usb_device(void * arg)
struct udev_monitor* mon;
udev = udev_new();
if (!udev) {
if (!udev)
{
printf("Can't create udev\n");
return 0;
}
@ -477,6 +466,7 @@ urbdrc_search_usb_device(void * arg)
mon = udev_monitor_new_from_netlink(udev, "udev");
udev_monitor_filter_add_match_subsystem_devtype(mon, "usb", "usb_device");
udev_monitor_enable_receiving(mon);
/* Get the file descriptor (fd) for the monitor.
This fd will get passed to select() */
mon_fd = wait_obj_new_with_fd((void*) (size_t) udev_monitor_get_fd(mon));
@ -494,6 +484,7 @@ urbdrc_search_usb_device(void * arg)
listobj[1] = mon_fd;
numobj = 2;
wait_obj_select(listobj, numobj, -1);
if (wait_obj_is_set(searchman->term_event))
{
sem_post(&searchman->sem_term);
@ -503,17 +494,20 @@ urbdrc_search_usb_device(void * arg)
if (wait_obj_is_set(mon_fd))
{
dev = udev_monitor_receive_device(mon);
if (dev) {
if (dev)
{
const char* action = udev_device_get_action(dev);
if (strcmp(action, "add") == 0)
{
int idVendor, idProduct;
success = 0;
found = 0;
idVendor = strtol(
udev_device_get_sysattr_value(dev, "idVendor"), NULL, 16);
idProduct = strtol(
udev_device_get_sysattr_value(dev, "idProduct"), NULL, 16);
idVendor = strtol(udev_device_get_sysattr_value(dev, "idVendor"), NULL, 16);
idProduct = strtol(udev_device_get_sysattr_value(dev, "idProduct"), NULL, 16);
if (idVendor < 0 || idProduct < 0)
{
udev_device_unref(dev);
@ -525,10 +519,13 @@ urbdrc_search_usb_device(void * arg)
dvc_channel = channel_mgr->FindChannelById(channel_mgr,
urbdrc->first_channel_id);
searchman->rewind(searchman);
while(dvc_channel && searchman->has_next(searchman))
{
sdev = searchman->get_next(searchman);
if (sdev->idVendor == idVendor &&
sdev->idProduct == idProduct)
{
@ -547,16 +544,15 @@ urbdrc_search_usb_device(void * arg)
}
if (found)
success = udevman->register_udevice(udevman,
busnum,
devnum,
searchman->UsbDevice,
0,
0,
UDEVMAN_FLAG_ADD_BY_ADDR);
{
success = udevman->register_udevice(udevman, busnum, devnum,
searchman->UsbDevice, 0, 0, UDEVMAN_FLAG_ADD_BY_ADDR);
}
if (success)
{
searchman->UsbDevice++;
/* when we send the usb device add request,
* we will detach the device driver at same
* time. But, if the time of detach the
@ -564,20 +560,24 @@ urbdrc_search_usb_device(void * arg)
* the system will crash. workaround: we
* wait it for some time to avoid system
* crash. */
listobj[0] = searchman->term_event;
numobj = 1;
timeout = 4000; /* milliseconds */
wait_obj_select(listobj, numobj, timeout);
if (wait_obj_is_set(searchman->term_event))
{
wait_obj_free(mon_fd);
sem_post(&searchman->sem_term);
return 0;
}
error = urdbrc_send_virtual_channel_add(dvc_channel, 0);
if (found == 1)
searchman->remove(searchman, sdev->idVendor,
sdev->idProduct);
searchman->remove(searchman, sdev->idVendor, sdev->idProduct);
}
}
else if (strcmp(action, "remove") == 0)
@ -588,17 +588,18 @@ urbdrc_search_usb_device(void * arg)
usleep(500000);
udevman->loading_lock(udevman);
udevman->rewind(udevman);
while(udevman->has_next(udevman))
{
pdev = udevman->get_next(udevman);
if (pdev->get_bus_number(pdev) == busnum &&
pdev->get_dev_number(pdev) == devnum)
if (pdev->get_bus_number(pdev) == busnum && pdev->get_dev_number(pdev) == devnum)
{
dvc_channel = channel_mgr->FindChannelById(channel_mgr,
pdev->get_channel_id(pdev));
if (dvc_channel == NULL){
LLOGLN(0, ("SEARCH: dvc_channel %d is NULL!!",
pdev->get_channel_id(pdev)));
dvc_channel = channel_mgr->FindChannelById(channel_mgr, pdev->get_channel_id(pdev));
if (dvc_channel == NULL)
{
LLOGLN(0, ("SEARCH: dvc_channel %d is NULL!!", pdev->get_channel_id(pdev)));
func_close_udevice(searchman, pdev);
break;
}
@ -608,16 +609,20 @@ urbdrc_search_usb_device(void * arg)
dvc_channel->Write(dvc_channel, 0, NULL, NULL);
pdev->SigToEnd(pdev);
}
on_close = 1;
break;
}
}
udevman->loading_unlock(udevman);
listobj[0] = searchman->term_event;
numobj = 1;
timeout = 3000; /* milliseconds */
wait_obj_select(listobj, numobj, timeout);
if (wait_obj_is_set(searchman->term_event))
{
wait_obj_free(mon_fd);
@ -625,13 +630,13 @@ urbdrc_search_usb_device(void * arg)
return 0;
}
if(pdev && on_close && dvc_channel && pdev->isSigToEnd(pdev) &&
!(pdev->isChannelClosed(pdev)))
if(pdev && on_close && dvc_channel && pdev->isSigToEnd(pdev) && !(pdev->isChannelClosed(pdev)))
{
on_close = 0;
dvc_channel->Close(dvc_channel);
}
}
udev_device_unref(dev);
}
else {
@ -646,9 +651,7 @@ urbdrc_search_usb_device(void * arg)
return 0;
}
void *
urbdrc_new_device_create(void * arg)
void* urbdrc_new_device_create(void * arg)
{
TRANSFER_DATA* transfer_data = (TRANSFER_DATA*) arg;
URBDRC_CHANNEL_CALLBACK* callback = transfer_data->callback;
@ -656,7 +659,6 @@ urbdrc_new_device_create(void * arg)
URBDRC_PLUGIN* urbdrc = transfer_data->urbdrc;
USB_SEARCHMAN* searchman = urbdrc->searchman;
uint8* pBuffer = transfer_data->pBuffer;
//uint32 cbSize = transfer_data->cbSize;
IUDEVMAN* udevman = transfer_data->udevman;
IUDEVICE* pdev = NULL;
uint32 ChannelId = 0;
@ -671,22 +673,27 @@ urbdrc_new_device_create(void * arg)
data_read_uint32(pBuffer + 4, FunctionId);
int error = 0;
switch (urbdrc->vchannel_status){
switch (urbdrc->vchannel_status)
{
case INIT_CHANNEL_IN:
urbdrc->first_channel_id = ChannelId;
searchman->start(searchman, urbdrc_search_usb_device);
for (i = 0; i < udevman->get_device_num(udevman); i++)
{
error = urdbrc_send_virtual_channel_add(callback->channel, MessageId);
}
urbdrc->vchannel_status = INIT_CHANNEL_OUT;
break;
case INIT_CHANNEL_OUT:
udevman->loading_lock(udevman);
udevman->rewind(udevman);
while(udevman->has_next(udevman)){
while(udevman->has_next(udevman))
{
pdev = udevman->get_next(udevman);
if (!pdev->isAlreadySend(pdev))
{
found = 1;
@ -703,12 +710,15 @@ urbdrc_new_device_create(void * arg)
* the device driver at same time. But, if the time of detach the
* driver and attach driver is too close, the system will crash.
* workaround: we wait it for some time to avoid system crash. */
error = pdev->wait_for_detach(pdev);
if (error >= 0)
urdbrc_send_usb_device_add(callback, pdev);
}
break;
default:
LLOGLN(0, ("urbdrc_new_device_create: vchannel_status unknown value %d",
urbdrc->vchannel_status));
@ -718,16 +728,12 @@ urbdrc_new_device_create(void * arg)
return 0;
}
static int
urbdrc_process_channel_notification(URBDRC_CHANNEL_CALLBACK * callback,
char * pBuffer, uint32 cbSize)
static int urbdrc_process_channel_notification(URBDRC_CHANNEL_CALLBACK* callback, char* pBuffer, uint32 cbSize)
{
URBDRC_PLUGIN * urbdrc = (URBDRC_PLUGIN *) callback->plugin;
int i, error = 0;
uint32 MessageId;
uint32 FunctionId;
int i, error = 0;
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*) callback->plugin;
data_read_uint32(pBuffer + 0, MessageId);
data_read_uint32(pBuffer + 4, FunctionId);
@ -737,6 +743,7 @@ urbdrc_process_channel_notification(URBDRC_CHANNEL_CALLBACK * callback,
case CHANNEL_CREATED:
error = urbdrc_process_channel_create(callback, pBuffer + 8, cbSize - 8, MessageId);
break;
case RIMCALL_RELEASE:
LLOGLN(10, ("urbdrc_process_channel_notification: recv RIMCALL_RELEASE"));
pthread_t thread;
@ -750,6 +757,7 @@ urbdrc_process_channel_notification(URBDRC_CHANNEL_CALLBACK * callback,
transfer_data->urbdrc = urbdrc;
transfer_data->cbSize = cbSize;
transfer_data->pBuffer = (uint8 *)malloc((cbSize));
for (i = 0; i < (cbSize); i++)
{
transfer_data->pBuffer[i] = pBuffer[i];
@ -758,6 +766,7 @@ urbdrc_process_channel_notification(URBDRC_CHANNEL_CALLBACK * callback,
pthread_create(&thread, 0, urbdrc_new_device_create, transfer_data);
pthread_detach(thread);
break;
default:
LLOGLN(10, ("urbdrc_process_channel_notification: unknown FunctionId 0x%X", FunctionId));
error = 1;
@ -766,13 +775,7 @@ urbdrc_process_channel_notification(URBDRC_CHANNEL_CALLBACK * callback,
return error;
}
static int
urbdrc_on_data_received(IWTSVirtualChannelCallback * pChannelCallback,
uint32 cbSize,
uint8 * Buffer)
static int urbdrc_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, uint32 cbSize, uint8* Buffer)
{
URBDRC_CHANNEL_CALLBACK* callback = (URBDRC_CHANNEL_CALLBACK*) pChannelCallback;
URBDRC_PLUGIN* urbdrc;
@ -783,10 +786,17 @@ urbdrc_on_data_received(IWTSVirtualChannelCallback * pChannelCallback,
int error = 0;
char* pBuffer = (char*) Buffer;
if (callback == NULL) return 0;
if (callback->plugin == NULL) return 0;
if (callback == NULL)
return 0;
if (callback->plugin == NULL)
return 0;
urbdrc = (URBDRC_PLUGIN*) callback->plugin;
if (urbdrc->udevman == NULL) return 0;
if (urbdrc->udevman == NULL)
return 0;
udevman = (IUDEVMAN*) urbdrc->udevman;
data_read_uint32(pBuffer + 0, InterfaceTemp);
@ -799,17 +809,21 @@ urbdrc_on_data_received(IWTSVirtualChannelCallback * pChannelCallback,
case CAPABILITIES_NEGOTIATOR:
error = urbdrc_exchange_capabilities(callback, pBuffer + 4, cbSize - 4);
break;
case SERVER_CHANNEL_NOTIFICATION:
error = urbdrc_process_channel_notification(callback, pBuffer + 4, cbSize - 4);
break;
default:
LLOGLN(10, ("urbdrc_on_data_received: InterfaceId 0x%X Start matching devices list", InterfaceId));
pthread_t thread;
TRANSFER_DATA* transfer_data;
transfer_data = (TRANSFER_DATA*) malloc(sizeof(TRANSFER_DATA));
if (transfer_data == NULL)
printf("transfer_data is NULL!!");
transfer_data->callback = callback;
transfer_data->urbdrc = urbdrc;
transfer_data->udevman = udevman;
@ -828,21 +842,19 @@ urbdrc_on_data_received(IWTSVirtualChannelCallback * pChannelCallback,
#endif
error = pthread_create(&thread, 0, urbdrc_process_udev_data_transfer, transfer_data);
if (error < 0)
LLOGLN(0, ("Create Data Transfer Thread got error = %d", error));
else
pthread_detach(thread);
//urbdrc_process_udev_data_transfer(transfer_data);
break;
}
return 0;
}
static int
urbdrc_on_close(IWTSVirtualChannelCallback * pChannelCallback)
static int urbdrc_on_close(IWTSVirtualChannelCallback * pChannelCallback)
{
URBDRC_CHANNEL_CALLBACK* callback = (URBDRC_CHANNEL_CALLBACK*) pChannelCallback;
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*) callback->plugin;
@ -858,16 +870,20 @@ urbdrc_on_close(IWTSVirtualChannelCallback * pChannelCallback)
udevman->loading_lock(udevman);
udevman->rewind(udevman);
while(udevman->has_next(udevman))
{
pdev = udevman->get_next(udevman);
if (pdev->get_channel_id(pdev) == ChannelId)
{
found = 1;
break;
}
}
udevman->loading_unlock(udevman);
if (found && pdev && !(pdev->isChannelClosed(pdev)))
{
pdev->setChannelClosed(pdev);
@ -881,12 +897,8 @@ urbdrc_on_close(IWTSVirtualChannelCallback * pChannelCallback)
return 0;
}
static int
urbdrc_on_new_channel_connection(IWTSListenerCallback * pListenerCallback,
IWTSVirtualChannel * pChannel,
uint8 * pData,
int * pbAccept,
IWTSVirtualChannelCallback ** ppCallback)
static int urbdrc_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
IWTSVirtualChannel * pChannel, uint8* pData, int* pbAccept, IWTSVirtualChannelCallback** ppCallback)
{
URBDRC_LISTENER_CALLBACK* listener_callback = (URBDRC_LISTENER_CALLBACK*) pListenerCallback;
URBDRC_CHANNEL_CALLBACK* callback;
@ -899,11 +911,11 @@ urbdrc_on_new_channel_connection(IWTSListenerCallback * pListenerCallback,
callback->channel_mgr = listener_callback->channel_mgr;
callback->channel = pChannel;
*ppCallback = (IWTSVirtualChannelCallback*) callback;
return 0;
}
static int
urbdrc_plugin_initialize(IWTSPlugin * pPlugin, IWTSVirtualChannelManager * pChannelMgr)
static int urbdrc_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
{
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*) pPlugin;
IUDEVMAN* udevman = NULL;
@ -926,8 +938,7 @@ urbdrc_plugin_initialize(IWTSPlugin * pPlugin, IWTSVirtualChannelManager * pChan
(IWTSListenerCallback *) urbdrc->listener_callback, NULL);
}
static int
urbdrc_plugin_terminated(IWTSPlugin * pPlugin)
static int urbdrc_plugin_terminated(IWTSPlugin* pPlugin)
{
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*) pPlugin;
IUDEVMAN* udevman = urbdrc->udevman;
@ -939,6 +950,7 @@ urbdrc_plugin_terminated(IWTSPlugin * pPlugin)
{
/* close searchman */
searchman->close(searchman);
/* free searchman */
if (searchman->strated)
{
@ -947,6 +959,7 @@ urbdrc_plugin_terminated(IWTSPlugin * pPlugin)
ts.tv_nsec = 0;
sem_timedwait(&searchman->sem_term, &ts);
}
searchman->free(searchman);
searchman = NULL;
}
@ -959,14 +972,14 @@ urbdrc_plugin_terminated(IWTSPlugin * pPlugin)
if (urbdrc->listener_callback)
zfree(urbdrc->listener_callback);
if(urbdrc)
zfree(urbdrc);
return 0;
}
static void
urbdrc_register_udevman_plugin(IWTSPlugin* pPlugin, IUDEVMAN* udevman)
static void urbdrc_register_udevman_plugin(IWTSPlugin* pPlugin, IUDEVMAN* udevman)
{
URBDRC_PLUGIN* urbdrc = (URBDRC_PLUGIN*) pPlugin;
@ -981,10 +994,7 @@ urbdrc_register_udevman_plugin(IWTSPlugin* pPlugin, IUDEVMAN* udevman)
urbdrc->udevman = udevman;
}
static int
urbdrc_load_udevman_plugin(IWTSPlugin* pPlugin, const char* name, RDP_PLUGIN_DATA* data)
static int urbdrc_load_udevman_plugin(IWTSPlugin* pPlugin, const char* name, RDP_PLUGIN_DATA* data)
{
char* fullname;
PFREERDP_URBDRC_DEVICE_ENTRY entry;
@ -1019,11 +1029,7 @@ urbdrc_load_udevman_plugin(IWTSPlugin* pPlugin, const char* name, RDP_PLUGIN_DAT
return true;
}
static int
urbdrc_process_plugin_data(IWTSPlugin* pPlugin, RDP_PLUGIN_DATA* data)
static int urbdrc_process_plugin_data(IWTSPlugin* pPlugin, RDP_PLUGIN_DATA* data)
{
boolean ret;
@ -1036,9 +1042,7 @@ urbdrc_process_plugin_data(IWTSPlugin* pPlugin, RDP_PLUGIN_DATA* data)
return true;
}
int
DVCPluginEntry(IDRDYNVC_ENTRY_POINTS * pEntryPoints)
int DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints)
{
int error = 0;
URBDRC_PLUGIN* urbdrc;
@ -1059,6 +1063,7 @@ DVCPluginEntry(IDRDYNVC_ENTRY_POINTS * pEntryPoints)
urbdrc->vchannel_status = INIT_CHANNEL_IN;
urbdrc_debug = 10;
if (data->data[2] && strstr((char *)data->data[2], "debug"))
urbdrc_debug = 0;
@ -1070,4 +1075,3 @@ DVCPluginEntry(IDRDYNVC_ENTRY_POINTS * pEntryPoints)
return error;
}