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 UINT error = ERROR_INVALID_DATA;
73 const size_t pos = Stream_GetPosition(irp->output);
74 if (!Stream_SetPosition(irp->output, RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4))
76 Stream_Write_INT32(irp->output, irp->IoStatus);
77 if (!Stream_SetPosition(irp->output, pos))
80 error = rdpdr_send(rdpdr, irp->output);
81 irp->output =
nullptr;
87IRP* irp_new(DEVMAN* devman, wStreamPool* pool,
wStream* s, wLog* log, UINT* error)
90 DEVICE* device =
nullptr;
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_calloc(1,
sizeof(IRP), MEMORY_ALLOCATION_ALIGNMENT);
119 WLog_Print(log, WLOG_ERROR,
"_aligned_malloc failed!");
121 *error = CHANNEL_RC_NO_MEMORY;
125 Stream_Read_UINT32(s, irp->FileId);
126 Stream_Read_UINT32(s, irp->CompletionId);
127 Stream_Read_UINT32(s, irp->MajorFunction);
128 Stream_Read_UINT32(s, irp->MinorFunction);
132 irp->device = device;
133 irp->devman = devman;
135 irp->output = StreamPool_Take(pool, 256);
138 WLog_Print(log, WLOG_ERROR,
"Stream_New failed!");
141 *error = CHANNEL_RC_NO_MEMORY;
145 if (!rdpdr_write_iocompletion_header(irp->output, DeviceId, irp->CompletionId, 0))
149 *error = CHANNEL_RC_NO_MEMORY;
153 irp->Complete = irp_complete;
154 irp->Discard = irp_free;
156 irp->thread =
nullptr;
157 irp->cancelled = FALSE;
160 *error = CHANNEL_RC_OK;