23#include <freerdp/config.h> 
   30#include <winpr/stream.h> 
   32#include <freerdp/utils/rdpdr_utils.h> 
   34#include "rdpdr_main.h" 
   43static UINT irp_free(IRP* irp)
 
   49    Stream_Release(irp->input);
 
   51    Stream_Release(irp->output);
 
   53  winpr_aligned_free(irp);
 
   62static UINT irp_complete(IRP* irp)
 
   69  WINPR_ASSERT(irp->output);
 
   70  WINPR_ASSERT(irp->devman);
 
   75  pos = Stream_GetPosition(irp->output);
 
   76  Stream_SetPosition(irp->output, RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4);
 
   77  Stream_Write_INT32(irp->output, irp->IoStatus); 
 
   78  Stream_SetPosition(irp->output, pos);
 
   80  error = rdpdr_send(
rdpdr, irp->output);
 
   87IRP* irp_new(DEVMAN* devman, wStreamPool* pool, 
wStream* s, wLog* log, UINT* error)
 
   90  DEVICE* device = NULL;
 
   97  if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
 
  100      *error = ERROR_INVALID_DATA;
 
  104  Stream_Read_UINT32(s, DeviceId); 
 
  105  device = devman_get_device_by_id(devman, DeviceId);
 
  110      *error = ERROR_DEV_NOT_EXIST;
 
  115  irp = (IRP*)winpr_aligned_malloc(
sizeof(IRP), MEMORY_ALLOCATION_ALIGNMENT);
 
  119    WLog_Print(log, WLOG_ERROR, 
"_aligned_malloc failed!");
 
  121      *error = CHANNEL_RC_NO_MEMORY;
 
  125  ZeroMemory(irp, 
sizeof(IRP));
 
  127  Stream_Read_UINT32(s, irp->FileId);        
 
  128  Stream_Read_UINT32(s, irp->CompletionId);  
 
  129  Stream_Read_UINT32(s, irp->MajorFunction); 
 
  130  Stream_Read_UINT32(s, irp->MinorFunction); 
 
  134  irp->device = device;
 
  135  irp->devman = devman;
 
  137  irp->output = StreamPool_Take(pool, 256);
 
  140    WLog_Print(log, WLOG_ERROR, 
"Stream_New failed!");
 
  143      *error = CHANNEL_RC_NO_MEMORY;
 
  147  if (!rdpdr_write_iocompletion_header(irp->output, DeviceId, irp->CompletionId, 0))
 
  151      *error = CHANNEL_RC_NO_MEMORY;
 
  155  irp->Complete = irp_complete;
 
  156  irp->Discard = irp_free;
 
  159  irp->cancelled = FALSE;
 
  162    *error = CHANNEL_RC_OK;