24 #include <freerdp/config.h>
30 #include <winpr/crt.h>
31 #include <winpr/stream.h>
33 #include <freerdp/types.h>
34 #include <freerdp/addin.h>
35 #include <freerdp/client/channels.h>
36 #include <freerdp/channels/log.h>
38 #include "rdpdr_main.h"
42 #define TAG CHANNELS_TAG("rdpdr.client")
44 static void devman_device_free(
void* obj)
46 DEVICE* device = (DEVICE*)obj;
51 IFCALL(device->Free, device);
56 DEVMAN* devman = NULL;
61 devman = (DEVMAN*)calloc(1,
sizeof(DEVMAN));
65 WLog_Print(rdpdr->log, WLOG_INFO,
"calloc failed!");
69 devman->plugin = (
void*)rdpdr;
70 devman->id_sequence = 1;
71 devman->devices = ListDictionary_New(TRUE);
75 WLog_Print(rdpdr->log, WLOG_INFO,
"ListDictionary_New failed!");
80 ListDictionary_ValueObject(devman->devices)->fnObjectFree = devman_device_free;
84 void devman_free(DEVMAN* devman)
86 ListDictionary_Free(devman->devices);
90 void devman_unregister_device(DEVMAN* devman,
void* key)
92 DEVICE* device = NULL;
97 device = (DEVICE*)ListDictionary_Take(devman->devices, key);
100 devman_device_free(device);
108 static UINT devman_register_device(DEVMAN* devman, DEVICE* device)
112 if (!devman || !device)
113 return ERROR_INVALID_PARAMETER;
115 device->id = devman->id_sequence++;
116 key = (
void*)(
size_t)device->id;
118 if (!ListDictionary_Add(devman->devices, key, device))
120 WLog_INFO(TAG,
"ListDictionary_Add failed!");
121 return ERROR_INTERNAL_ERROR;
124 return CHANNEL_RC_OK;
127 DEVICE* devman_get_device_by_id(DEVMAN* devman, UINT32
id)
129 DEVICE* device = NULL;
130 void* key = (
void*)(
size_t)id;
134 WLog_ERR(TAG,
"device manager=%p", devman);
138 device = (DEVICE*)ListDictionary_GetItemValue(devman->devices, key);
140 WLog_WARN(TAG,
"could not find device ID 0x%08" PRIx32,
id);
144 DEVICE* devman_get_device_by_type(DEVMAN* devman, UINT32 type)
146 DEVICE* device = NULL;
147 ULONG_PTR* keys = NULL;
152 ListDictionary_Lock(devman->devices);
153 const size_t count = ListDictionary_GetKeys(devman->devices, &keys);
155 for (
size_t x = 0; x < count; x++)
157 DEVICE* cur = (DEVICE*)ListDictionary_GetItemValue(devman->devices, (
void*)keys[x]);
162 if (cur->type != type)
170 ListDictionary_Unlock(devman->devices);
174 static const char DRIVE_SERVICE_NAME[] =
"drive";
175 static const char PRINTER_SERVICE_NAME[] =
"printer";
176 static const char SMARTCARD_SERVICE_NAME[] =
"smartcard";
177 static const char SERIAL_SERVICE_NAME[] =
"serial";
178 static const char PARALLEL_SERVICE_NAME[] =
"parallel";
185 UINT devman_load_device_service(DEVMAN* devman,
const RDPDR_DEVICE* device, rdpContext* rdpcontext)
187 const char* ServiceName = NULL;
195 devconv.cdp = device;
196 if (!devman || !device || !rdpcontext)
197 return ERROR_INVALID_PARAMETER;
199 if (device->Type == RDPDR_DTYP_FILESYSTEM)
200 ServiceName = DRIVE_SERVICE_NAME;
201 else if (device->Type == RDPDR_DTYP_PRINT)
202 ServiceName = PRINTER_SERVICE_NAME;
203 else if (device->Type == RDPDR_DTYP_SMARTCARD)
204 ServiceName = SMARTCARD_SERVICE_NAME;
205 else if (device->Type == RDPDR_DTYP_SERIAL)
206 ServiceName = SERIAL_SERVICE_NAME;
207 else if (device->Type == RDPDR_DTYP_PARALLEL)
208 ServiceName = PARALLEL_SERVICE_NAME;
212 WLog_INFO(TAG,
"ServiceName %s did not match!", ServiceName);
213 return ERROR_INVALID_NAME;
217 WLog_INFO(TAG,
"Loading device service %s [%s] (static)", ServiceName, device->Name);
219 WLog_INFO(TAG,
"Loading device service %s (static)", ServiceName);
221 PVIRTUALCHANNELENTRY pvce =
222 freerdp_load_channel_addin_entry(ServiceName, NULL,
"DeviceServiceEntry", 0);
223 PDEVICE_SERVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PDEVICE_SERVICE_ENTRY);
227 WLog_INFO(TAG,
"freerdp_load_channel_addin_entry failed!");
228 return ERROR_INTERNAL_ERROR;
232 ep.RegisterDevice = devman_register_device;
233 ep.device = devconv.dp;
234 ep.rdpcontext = rdpcontext;