22 #include <freerdp/config.h>
30 #include <winpr/collections.h>
31 #include <winpr/comm.h>
32 #include <winpr/crt.h>
33 #include <winpr/stream.h>
34 #include <winpr/synch.h>
35 #include <winpr/thread.h>
36 #include <winpr/wlog.h>
37 #include <winpr/assert.h>
39 #include <freerdp/freerdp.h>
40 #include <freerdp/channels/rdpdr.h>
41 #include <freerdp/channels/log.h>
42 #include <freerdp/utils/rdpdr_utils.h>
44 #define TAG CHANNELS_TAG("serial.client")
46 #define MAX_IRP_THREADS 5
52 SERIAL_DRIVER_ID ServerSerialDriverId;
57 wMessageQueue* MainIrpQueue;
60 wListDictionary* IrpThreads;
62 rdpContext* rdpcontext;
67 SERIAL_DEVICE* serial;
71 static void close_terminated_irp_thread_handles(SERIAL_DEVICE* serial, BOOL forceClose);
72 static UINT32 GetLastErrorToIoStatus(SERIAL_DEVICE* serial)
76 switch (GetLastError())
78 case ERROR_BAD_DEVICE:
79 return STATUS_INVALID_DEVICE_REQUEST;
81 case ERROR_CALL_NOT_IMPLEMENTED:
82 return STATUS_NOT_IMPLEMENTED;
85 return STATUS_CANCELLED;
87 case ERROR_INSUFFICIENT_BUFFER:
88 return STATUS_BUFFER_TOO_SMALL;
90 case ERROR_INVALID_DEVICE_OBJECT_PARAMETER:
91 return STATUS_INVALID_DEVICE_STATE;
93 case ERROR_INVALID_HANDLE:
94 return STATUS_INVALID_DEVICE_REQUEST;
96 case ERROR_INVALID_PARAMETER:
97 return STATUS_INVALID_PARAMETER;
100 return STATUS_IO_DEVICE_ERROR;
102 case ERROR_IO_PENDING:
103 return STATUS_PENDING;
105 case ERROR_NOT_SUPPORTED:
106 return STATUS_NOT_SUPPORTED;
109 return STATUS_TIMEOUT;
114 WLog_Print(serial->log, WLOG_DEBUG,
"unexpected last-error: 0x%08" PRIX32
"", GetLastError());
115 return STATUS_UNSUCCESSFUL;
118 static UINT serial_process_irp_create(SERIAL_DEVICE* serial, IRP* irp)
120 DWORD DesiredAccess = 0;
121 DWORD SharedAccess = 0;
122 DWORD CreateDisposition = 0;
123 UINT32 PathLength = 0;
125 WINPR_ASSERT(serial);
128 if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32))
129 return ERROR_INVALID_DATA;
131 Stream_Read_UINT32(irp->input, DesiredAccess);
132 Stream_Seek_UINT64(irp->input);
133 Stream_Seek_UINT32(irp->input);
134 Stream_Read_UINT32(irp->input, SharedAccess);
135 Stream_Read_UINT32(irp->input, CreateDisposition);
136 Stream_Seek_UINT32(irp->input);
137 Stream_Read_UINT32(irp->input, PathLength);
139 if (!Stream_SafeSeek(irp->input, PathLength))
140 return ERROR_INVALID_DATA;
142 WINPR_ASSERT(PathLength == 0);
159 WLog_Print(serial->log, WLOG_DEBUG,
160 "DesiredAccess: 0x%" PRIX32
", SharedAccess: 0x%" PRIX32
161 ", CreateDisposition: 0x%" PRIX32
"",
162 DesiredAccess, SharedAccess, CreateDisposition);
164 DesiredAccess = GENERIC_READ | GENERIC_WRITE;
166 CreateDisposition = OPEN_EXISTING;
169 CreateFile(serial->device.name, DesiredAccess, SharedAccess, NULL,
170 CreateDisposition, 0,
173 if (!serial->hComm || (serial->hComm == INVALID_HANDLE_VALUE))
175 WLog_Print(serial->log, WLOG_WARN,
"CreateFile failure: %s last-error: 0x%08" PRIX32
"",
176 serial->device.name, GetLastError());
177 irp->IoStatus = STATUS_UNSUCCESSFUL;
181 _comm_setServerSerialDriver(serial->hComm, serial->ServerSerialDriverId);
182 _comm_set_permissive(serial->hComm, serial->permissive);
191 WINPR_ASSERT(irp->FileId == 0);
192 irp->FileId = irp->devman->id_sequence++;
193 irp->IoStatus = STATUS_SUCCESS;
194 WLog_Print(serial->log, WLOG_DEBUG,
"%s (DeviceId: %" PRIu32
", FileId: %" PRIu32
") created.",
195 serial->device.name, irp->device->id, irp->FileId);
197 Stream_Write_UINT32(irp->output, irp->FileId);
198 Stream_Write_UINT8(irp->output, 0);
199 return CHANNEL_RC_OK;
202 static UINT serial_process_irp_close(SERIAL_DEVICE* serial, IRP* irp)
204 WINPR_ASSERT(serial);
207 if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32))
208 return ERROR_INVALID_DATA;
210 Stream_Seek(irp->input, 32);
212 close_terminated_irp_thread_handles(serial, TRUE);
214 if (!CloseHandle(serial->hComm))
216 WLog_Print(serial->log, WLOG_WARN,
"CloseHandle failure: %s (%" PRIu32
") closed.",
217 serial->device.name, irp->device->id);
218 irp->IoStatus = STATUS_UNSUCCESSFUL;
222 WLog_Print(serial->log, WLOG_DEBUG,
"%s (DeviceId: %" PRIu32
", FileId: %" PRIu32
") closed.",
223 serial->device.name, irp->device->id, irp->FileId);
224 irp->IoStatus = STATUS_SUCCESS;
226 serial->hComm = NULL;
227 Stream_Zero(irp->output, 5);
228 return CHANNEL_RC_OK;
236 static UINT serial_process_irp_read(SERIAL_DEVICE* serial, IRP* irp)
243 WINPR_ASSERT(serial);
246 if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32))
247 return ERROR_INVALID_DATA;
249 Stream_Read_UINT32(irp->input, Length);
250 Stream_Read_UINT64(irp->input, Offset);
253 Stream_Seek(irp->input, 20);
254 buffer = (BYTE*)calloc(Length,
sizeof(BYTE));
258 irp->IoStatus = STATUS_NO_MEMORY;
265 WLog_Print(serial->log, WLOG_DEBUG,
"reading %" PRIu32
" bytes from %s", Length,
266 serial->device.name);
269 if (CommReadFile(serial->hComm, buffer, Length, &nbRead, NULL))
271 irp->IoStatus = STATUS_SUCCESS;
275 WLog_Print(serial->log, WLOG_DEBUG,
276 "read failure to %s, nbRead=%" PRIu32
", last-error: 0x%08" PRIX32
"",
277 serial->device.name, nbRead, GetLastError());
278 irp->IoStatus = GetLastErrorToIoStatus(serial);
281 WLog_Print(serial->log, WLOG_DEBUG,
"%" PRIu32
" bytes read from %s", nbRead,
282 serial->device.name);
284 Stream_Write_UINT32(irp->output, nbRead);
288 if (!Stream_EnsureRemainingCapacity(irp->output, nbRead))
290 WLog_Print(serial->log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
292 return CHANNEL_RC_NO_MEMORY;
295 Stream_Write(irp->output, buffer, nbRead);
299 return CHANNEL_RC_OK;
302 static UINT serial_process_irp_write(SERIAL_DEVICE* serial, IRP* irp)
308 WINPR_ASSERT(serial);
311 if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32))
312 return ERROR_INVALID_DATA;
314 Stream_Read_UINT32(irp->input, Length);
315 Stream_Read_UINT64(irp->input, Offset);
318 if (!Stream_SafeSeek(irp->input, 20))
319 return ERROR_INVALID_DATA;
327 WLog_Print(serial->log, WLOG_DEBUG,
"writing %" PRIu32
" bytes to %s", Length,
328 serial->device.name);
330 const void* ptr = Stream_ConstPointer(irp->input);
331 if (!Stream_SafeSeek(irp->input, Length))
332 return ERROR_INVALID_DATA;
334 if (CommWriteFile(serial->hComm, ptr, Length, &nbWritten, NULL))
336 irp->IoStatus = STATUS_SUCCESS;
340 WLog_Print(serial->log, WLOG_DEBUG,
341 "write failure to %s, nbWritten=%" PRIu32
", last-error: 0x%08" PRIX32
"",
342 serial->device.name, nbWritten, GetLastError());
343 irp->IoStatus = GetLastErrorToIoStatus(serial);
346 WLog_Print(serial->log, WLOG_DEBUG,
"%" PRIu32
" bytes written to %s", nbWritten,
347 serial->device.name);
348 Stream_Write_UINT32(irp->output, nbWritten);
349 Stream_Write_UINT8(irp->output, 0);
350 return CHANNEL_RC_OK;
358 static UINT serial_process_irp_device_control(SERIAL_DEVICE* serial, IRP* irp)
360 UINT32 IoControlCode = 0;
361 UINT32 InputBufferLength = 0;
362 BYTE* InputBuffer = NULL;
363 UINT32 OutputBufferLength = 0;
364 BYTE* OutputBuffer = NULL;
365 DWORD BytesReturned = 0;
367 WINPR_ASSERT(serial);
370 if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, 32))
371 return ERROR_INVALID_DATA;
373 Stream_Read_UINT32(irp->input, OutputBufferLength);
374 Stream_Read_UINT32(irp->input, InputBufferLength);
375 Stream_Read_UINT32(irp->input, IoControlCode);
376 Stream_Seek(irp->input, 20);
378 if (!Stream_CheckAndLogRequiredLengthWLog(serial->log, irp->input, InputBufferLength))
379 return ERROR_INVALID_DATA;
381 OutputBuffer = (BYTE*)calloc(OutputBufferLength,
sizeof(BYTE));
383 if (OutputBuffer == NULL)
385 irp->IoStatus = STATUS_NO_MEMORY;
389 InputBuffer = (BYTE*)calloc(InputBufferLength,
sizeof(BYTE));
391 if (InputBuffer == NULL)
393 irp->IoStatus = STATUS_NO_MEMORY;
397 Stream_Read(irp->input, InputBuffer, InputBufferLength);
398 WLog_Print(serial->log, WLOG_DEBUG,
399 "CommDeviceIoControl: CompletionId=%" PRIu32
", IoControlCode=[0x%" PRIX32
"] %s",
400 irp->CompletionId, IoControlCode, _comm_serial_ioctl_name(IoControlCode));
403 if (CommDeviceIoControl(serial->hComm, IoControlCode, InputBuffer, InputBufferLength,
404 OutputBuffer, OutputBufferLength, &BytesReturned, NULL))
409 irp->IoStatus = STATUS_SUCCESS;
413 WLog_Print(serial->log, WLOG_DEBUG,
414 "CommDeviceIoControl failure: IoControlCode=[0x%" PRIX32
415 "] %s, last-error: 0x%08" PRIX32
"",
416 IoControlCode, _comm_serial_ioctl_name(IoControlCode), GetLastError());
417 irp->IoStatus = GetLastErrorToIoStatus(serial);
424 WINPR_ASSERT(OutputBufferLength == BytesReturned);
425 Stream_Write_UINT32(irp->output, BytesReturned);
427 if (BytesReturned > 0)
429 if (!Stream_EnsureRemainingCapacity(irp->output, BytesReturned))
431 WLog_Print(serial->log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
434 return CHANNEL_RC_NO_MEMORY;
437 Stream_Write(irp->output, OutputBuffer, BytesReturned);
450 return CHANNEL_RC_OK;
458 static UINT serial_process_irp(SERIAL_DEVICE* serial, IRP* irp)
460 UINT error = CHANNEL_RC_OK;
462 WINPR_ASSERT(serial);
465 WLog_Print(serial->log, WLOG_DEBUG,
"IRP MajorFunction: %s, MinorFunction: 0x%08" PRIX32
"\n",
466 rdpdr_irp_string(irp->MajorFunction), irp->MinorFunction);
468 switch (irp->MajorFunction)
471 error = serial_process_irp_create(serial, irp);
475 error = serial_process_irp_close(serial, irp);
479 error = serial_process_irp_read(serial, irp);
483 error = serial_process_irp_write(serial, irp);
486 case IRP_MJ_DEVICE_CONTROL:
487 error = serial_process_irp_device_control(serial, irp);
491 irp->IoStatus = STATUS_NOT_SUPPORTED;
495 DWORD level = WLOG_TRACE;
499 WLog_Print(serial->log, level,
500 "[%s|0x%08" PRIx32
"] completed with %s [0x%08" PRIx32
"] (IoStatus %s [0x%08" PRIx32
502 rdpdr_irp_string(irp->MajorFunction), irp->MajorFunction, WTSErrorToString(error),
503 error, NtStatus2Tag(irp->IoStatus), irp->IoStatus);
508 static DWORD WINAPI irp_thread_func(LPVOID arg)
510 IRP_THREAD_DATA* data = (IRP_THREAD_DATA*)arg;
514 WINPR_ASSERT(data->serial);
515 WINPR_ASSERT(data->irp);
518 if ((error = serial_process_irp(data->serial, data->irp)))
520 WLog_Print(data->serial->log, WLOG_ERROR,
521 "serial_process_irp failed with error %" PRIu32
"", error);
525 EnterCriticalSection(&data->serial->TerminatingIrpThreadsLock);
526 error = data->irp->Complete(data->irp);
527 LeaveCriticalSection(&data->serial->TerminatingIrpThreadsLock);
530 if (error && data->serial->rdpcontext)
531 setChannelError(data->serial->rdpcontext, error,
"irp_thread_func reported an error");
541 static void close_unterminated_irp_thread(wListDictionary* list, wLog* log, ULONG_PTR
id)
544 HANDLE
self = _GetCurrentThread();
545 HANDLE cirpThread = ListDictionary_GetItemValue(list, (
void*)
id);
546 if (
self == cirpThread)
547 WLog_Print(log, WLOG_DEBUG,
"Skipping termination of own IRP thread");
549 ListDictionary_Remove(list, (
void*)
id);
552 static void close_terminated_irp_thread(wListDictionary* list, wLog* log, ULONG_PTR
id)
556 HANDLE cirpThread = ListDictionary_GetItemValue(list, (
void*)
id);
559 const DWORD waitResult = WaitForSingleObject(cirpThread, 0);
561 if (waitResult == WAIT_OBJECT_0)
562 ListDictionary_Remove(list, (
void*)
id);
563 else if (waitResult != WAIT_TIMEOUT)
566 WLog_Print(log, WLOG_WARN,
"WaitForSingleObject, got an unexpected result=0x%" PRIX32
"\n",
571 void close_terminated_irp_thread_handles(SERIAL_DEVICE* serial, BOOL forceClose)
573 WINPR_ASSERT(serial);
575 EnterCriticalSection(&serial->TerminatingIrpThreadsLock);
577 ULONG_PTR* ids = NULL;
578 const size_t nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids);
580 for (
size_t i = 0; i < nbIds; i++)
582 ULONG_PTR
id = ids[i];
584 close_unterminated_irp_thread(serial->IrpThreads, serial->log,
id);
586 close_terminated_irp_thread(serial->IrpThreads, serial->log,
id);
591 LeaveCriticalSection(&serial->TerminatingIrpThreadsLock);
594 static void create_irp_thread(SERIAL_DEVICE* serial, IRP* irp)
596 IRP_THREAD_DATA* data = NULL;
597 HANDLE irpThread = NULL;
598 HANDLE previousIrpThread = NULL;
601 WINPR_ASSERT(serial);
604 close_terminated_irp_thread_handles(serial, FALSE);
616 key = irp->CompletionId + 1ull;
617 previousIrpThread = ListDictionary_GetItemValue(serial->IrpThreads, (
void*)key);
619 if (previousIrpThread)
622 WLog_Print(serial->log, WLOG_DEBUG,
623 "IRP recall: IRP with the CompletionId=%" PRIu32
" not yet completed!",
643 if (ListDictionary_Count(serial->IrpThreads) >= MAX_IRP_THREADS)
645 WLog_Print(serial->log, WLOG_WARN,
646 "Number of IRP threads threshold reached: %" PRIuz
", keep on anyway",
647 ListDictionary_Count(serial->IrpThreads));
657 data = (IRP_THREAD_DATA*)calloc(1,
sizeof(IRP_THREAD_DATA));
661 WLog_Print(serial->log, WLOG_WARN,
"Could not allocate a new IRP_THREAD_DATA.");
665 data->serial = serial;
668 irpThread = CreateThread(NULL, 0, irp_thread_func, (
void*)data, CREATE_SUSPENDED, NULL);
670 if (irpThread == INVALID_HANDLE_VALUE)
672 WLog_Print(serial->log, WLOG_WARN,
"Could not allocate a new IRP thread.");
676 key = irp->CompletionId + 1ull;
678 if (!ListDictionary_Add(serial->IrpThreads, (
void*)key, irpThread))
680 WLog_Print(serial->log, WLOG_ERROR,
"ListDictionary_Add failed!");
684 ResumeThread(irpThread);
689 (void)CloseHandle(irpThread);
690 irp->IoStatus = STATUS_NO_MEMORY;
695 static DWORD WINAPI serial_thread_func(LPVOID arg)
698 wMessage message = { 0 };
699 SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg;
700 UINT error = CHANNEL_RC_OK;
702 WINPR_ASSERT(serial);
706 if (!MessageQueue_Wait(serial->MainIrpQueue))
708 WLog_Print(serial->log, WLOG_ERROR,
"MessageQueue_Wait failed!");
709 error = ERROR_INTERNAL_ERROR;
713 if (!MessageQueue_Peek(serial->MainIrpQueue, &message, TRUE))
715 WLog_Print(serial->log, WLOG_ERROR,
"MessageQueue_Peek failed!");
716 error = ERROR_INTERNAL_ERROR;
720 if (message.id == WMQ_QUIT)
723 irp = (IRP*)message.wParam;
726 create_irp_thread(serial, irp);
729 ListDictionary_Clear(serial->IrpThreads);
730 if (error && serial->rdpcontext)
731 setChannelError(serial->rdpcontext, error,
"serial_thread_func reported an error");
742 static UINT serial_irp_request(DEVICE* device, IRP* irp)
744 SERIAL_DEVICE* serial = (SERIAL_DEVICE*)device;
745 WINPR_ASSERT(irp != NULL);
746 WINPR_ASSERT(serial);
749 return CHANNEL_RC_OK;
756 if (!MessageQueue_Post(serial->MainIrpQueue, NULL, 0, (
void*)irp, NULL))
758 WLog_Print(serial->log, WLOG_ERROR,
"MessageQueue_Post failed!");
759 return ERROR_INTERNAL_ERROR;
762 return CHANNEL_RC_OK;
770 static UINT serial_free(DEVICE* device)
773 SERIAL_DEVICE* serial = (SERIAL_DEVICE*)device;
775 return CHANNEL_RC_OK;
777 WLog_Print(serial->log, WLOG_DEBUG,
"freeing");
778 if (serial->MainIrpQueue)
779 MessageQueue_PostQuit(serial->MainIrpQueue, 0);
781 if (serial->MainThread)
783 if (WaitForSingleObject(serial->MainThread, INFINITE) == WAIT_FAILED)
785 error = GetLastError();
786 WLog_Print(serial->log, WLOG_ERROR,
787 "WaitForSingleObject failed with error %" PRIu32
"!", error);
789 (void)CloseHandle(serial->MainThread);
793 (void)CloseHandle(*serial->hComm);
796 Stream_Free(serial->device.data, TRUE);
797 MessageQueue_Free(serial->MainIrpQueue);
798 ListDictionary_Free(serial->IrpThreads);
799 DeleteCriticalSection(&serial->TerminatingIrpThreadsLock);
801 return CHANNEL_RC_OK;
804 static void serial_message_free(
void* obj)
812 IRP* irp = (IRP*)msg->wParam;
815 WINPR_ASSERT(irp->Discard);
819 static void irp_thread_close(
void* arg)
824 HANDLE thz = _GetCurrentThread();
826 WLog_WARN(TAG,
"closing self, ignoring...");
829 (void)TerminateThread(hdl, 0);
830 (void)WaitForSingleObject(hdl, INFINITE);
831 (void)CloseHandle(hdl);
845 SERIAL_DEVICE* serial = NULL;
846 UINT error = CHANNEL_RC_OK;
848 WINPR_ASSERT(pEntryPoints);
851 WINPR_ASSERT(device);
853 wLog* log = WLog_Get(TAG);
854 const char* name = device->device.Name;
855 const char* path = device->Path;
856 const char* driver = device->Driver;
858 if (!name || (name[0] ==
'*'))
861 WLog_Print(log, WLOG_WARN,
862 "Serial port autodetection not implemented, nothing will be redirected!");
863 return CHANNEL_RC_OK;
866 if ((name && name[0]) && (path && path[0]))
868 WLog_Print(log, WLOG_DEBUG,
"Defining %s as %s", name, path);
870 if (!DefineCommDevice(name , path ))
872 DWORD status = GetLastError();
873 WLog_Print(log, WLOG_ERROR,
"DefineCommDevice failed with %08" PRIx32, status);
874 return ERROR_INTERNAL_ERROR;
877 serial = (SERIAL_DEVICE*)calloc(1,
sizeof(SERIAL_DEVICE));
881 WLog_Print(log, WLOG_ERROR,
"calloc failed!");
882 return CHANNEL_RC_NO_MEMORY;
886 serial->device.type = RDPDR_DTYP_SERIAL;
887 serial->device.name = name;
888 serial->device.IRPRequest = serial_irp_request;
889 serial->device.Free = serial_free;
890 serial->rdpcontext = pEntryPoints->rdpcontext;
892 serial->device.data = Stream_New(NULL, len + 1);
894 if (!serial->device.data)
896 WLog_Print(serial->log, WLOG_ERROR,
"calloc failed!");
897 error = CHANNEL_RC_NO_MEMORY;
901 for (
size_t i = 0; i <= len; i++)
902 Stream_Write_UINT8(serial->device.data, name[i] < 0 ?
'_' : name[i]);
906 if (_stricmp(driver,
"Serial") == 0)
907 serial->ServerSerialDriverId = SerialDriverSerialSys;
908 else if (_stricmp(driver,
"SerCx") == 0)
909 serial->ServerSerialDriverId = SerialDriverSerCxSys;
910 else if (_stricmp(driver,
"SerCx2") == 0)
911 serial->ServerSerialDriverId = SerialDriverSerCx2Sys;
914 WLog_Print(serial->log, WLOG_WARN,
"Unknown server's serial driver: %s.", driver);
915 WLog_Print(serial->log, WLOG_WARN,
916 "Valid options are: 'Serial' (default), 'SerCx' and 'SerCx2'");
923 serial->ServerSerialDriverId = SerialDriverSerialSys;
926 if (device->Permissive != NULL)
928 if (_stricmp(device->Permissive,
"permissive") == 0)
930 serial->permissive = TRUE;
934 WLog_Print(serial->log, WLOG_WARN,
"Unknown flag: %s", device->Permissive);
939 WLog_Print(serial->log, WLOG_DEBUG,
"Server's serial driver: %s (id: %d)", driver,
940 serial->ServerSerialDriverId);
942 serial->MainIrpQueue = MessageQueue_New(NULL);
944 if (!serial->MainIrpQueue)
946 WLog_Print(serial->log, WLOG_ERROR,
"MessageQueue_New failed!");
947 error = CHANNEL_RC_NO_MEMORY;
952 wObject* obj = MessageQueue_Object(serial->MainIrpQueue);
954 obj->fnObjectFree = serial_message_free;
958 serial->IrpThreads = ListDictionary_New(FALSE);
960 if (!serial->IrpThreads)
962 WLog_Print(serial->log, WLOG_ERROR,
"ListDictionary_New failed!");
963 error = CHANNEL_RC_NO_MEMORY;
968 wObject* obj = ListDictionary_ValueObject(serial->IrpThreads);
970 obj->fnObjectFree = irp_thread_close;
973 InitializeCriticalSection(&serial->TerminatingIrpThreadsLock);
975 error = pEntryPoints->RegisterDevice(pEntryPoints->devman, &serial->device);
976 if (error != CHANNEL_RC_OK)
978 WLog_Print(serial->log, WLOG_ERROR,
979 "EntryPoints->RegisterDevice failed with error %" PRIu32
"!", error);
983 serial->MainThread = CreateThread(NULL, 0, serial_thread_func, serial, 0, NULL);
984 if (!serial->MainThread)
986 WLog_Print(serial->log, WLOG_ERROR,
"CreateThread failed!");
987 error = ERROR_INTERNAL_ERROR;
995 serial_free(&serial->device);
This struct contains function pointer to initialize/free objects.