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)
65 WINPR_ASSERT(irp->output);
66 WINPR_ASSERT(irp->devman);
71 const size_t pos = Stream_GetPosition(irp->output);
72 Stream_SetPosition(irp->output, RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4);
73 Stream_Write_INT32(irp->output, irp->IoStatus);
74 Stream_SetPosition(irp->output, pos);
76 const UINT error = rdpdr_send(rdpdr, irp->output);
83IRP* irp_new(DEVMAN* devman, wStreamPool* pool,
wStream* s, wLog* log, UINT* error)
86 DEVICE* device = NULL;
93 if (!Stream_CheckAndLogRequiredLengthWLog(log, s, 20))
96 *error = ERROR_INVALID_DATA;
100 Stream_Read_UINT32(s, DeviceId);
101 device = devman_get_device_by_id(devman, DeviceId);
106 *error = ERROR_DEV_NOT_EXIST;
111 irp = (IRP*)winpr_aligned_calloc(1,
sizeof(IRP), MEMORY_ALLOCATION_ALIGNMENT);
115 WLog_Print(log, WLOG_ERROR,
"_aligned_malloc failed!");
117 *error = CHANNEL_RC_NO_MEMORY;
121 Stream_Read_UINT32(s, irp->FileId);
122 Stream_Read_UINT32(s, irp->CompletionId);
123 Stream_Read_UINT32(s, irp->MajorFunction);
124 Stream_Read_UINT32(s, irp->MinorFunction);
128 irp->device = device;
129 irp->devman = devman;
131 irp->output = StreamPool_Take(pool, 256);
134 WLog_Print(log, WLOG_ERROR,
"Stream_New failed!");
137 *error = CHANNEL_RC_NO_MEMORY;
141 if (!rdpdr_write_iocompletion_header(irp->output, DeviceId, irp->CompletionId, 0))
145 *error = CHANNEL_RC_NO_MEMORY;
149 irp->Complete = irp_complete;
150 irp->Discard = irp_free;
153 irp->cancelled = FALSE;
156 *error = CHANNEL_RC_OK;