Skip to content

Commit 560abfd

Browse files
Claire GirkaClearlyClaire
authored andcommitted
[draft] winebus: implement BusQueryContainerID based on container sysfs path
1 parent ccfe78a commit 560abfd

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

dlls/winebus.sys/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MODULE = winebus.sys
22
UNIXLIB = winebus.so
3-
IMPORTS = ntoskrnl hidparse
3+
IMPORTS = ntoskrnl hidparse ole32
44
UNIX_LIBS = $(IOKIT_LIBS) $(UDEV_LIBS) $(PTHREAD_LIBS) $(INOTIFY_LIBS)
55
UNIX_CFLAGS = $(UDEV_CFLAGS) $(SDL2_CFLAGS)
66

dlls/winebus.sys/main.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "wine/debug.h"
3838
#include "wine/list.h"
3939
#include "wine/unixlib.h"
40+
#include "ole2.h"
4041

4142
#include "unixlib.h"
4243

@@ -198,6 +199,36 @@ static WCHAR *get_instance_id(DEVICE_OBJECT *device)
198199
return dst;
199200
}
200201

202+
static WCHAR *get_container_id(DEVICE_OBJECT *device)
203+
{
204+
struct device_extension *ext = (struct device_extension *)device->DeviceExtension;
205+
UINT len = (38+1)*sizeof(WCHAR);
206+
WCHAR *dst;
207+
GUID guid;
208+
const char *p;
209+
210+
if (!ext->desc.container_syspath[0])
211+
return NULL;
212+
213+
memset(&guid, 0, sizeof(GUID));
214+
guid.Data1 = (ext->desc.vid << 16) | ext->desc.pid;
215+
216+
/* Get just the USB bus-devpath part */
217+
p = strrchr(ext->desc.container_syspath, '/');
218+
if (!p || (p - ext->desc.container_syspath) <= 12)
219+
return NULL;
220+
221+
for (int i = 0; p[i]; i++) {
222+
((char *) &guid)[4 + i % 12] ^= p[i];
223+
}
224+
225+
if (!(dst = ExAllocatePool(PagedPool, len)))
226+
return NULL;
227+
228+
StringFromGUID2(&guid, dst, len);
229+
return dst;
230+
}
231+
201232
static WCHAR *get_device_id(DEVICE_OBJECT *device)
202233
{
203234
static const WCHAR input_format[] = L"&MI_%02u";
@@ -522,6 +553,10 @@ static NTSTATUS handle_IRP_MN_QUERY_ID(DEVICE_OBJECT *device, IRP *irp)
522553
TRACE("BusQueryInstanceID\n");
523554
irp->IoStatus.Information = (ULONG_PTR)get_instance_id(device);
524555
break;
556+
case BusQueryContainerID:
557+
TRACE("BusQueryContainerID\n");
558+
irp->IoStatus.Information = (ULONG_PTR)get_container_id(device);
559+
break;
525560
default:
526561
FIXME("Unhandled type %08x\n", type);
527562
return status;

0 commit comments

Comments
 (0)