2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TDI interface
5 * PURPOSE: TDI entity enumeration
12 /* A generic thing-getting function which interacts in the right way with
13 * TDI. This may seem oblique, but I'm using it to reduce code and hopefully
14 * make this thing easier to debug.
16 * The things returned can be any of:
24 NTSTATUS
tdiGetSetOfThings( HANDLE tcpFile
,
34 TCP_REQUEST_QUERY_INFORMATION_EX req
= TCP_REQUEST_QUERY_INFORMATION_INIT
;
36 NTSTATUS status
= STATUS_SUCCESS
;
37 DWORD allocationSizeForEntityArray
= entrySize
* MAX_TDI_ENTITIES
,
38 arraySize
= entrySize
* MAX_TDI_ENTITIES
;
40 req
.ID
.toi_class
= toiClass
;
41 req
.ID
.toi_type
= toiType
;
42 req
.ID
.toi_id
= toiId
;
43 req
.ID
.toi_entity
.tei_entity
= teiEntity
;
44 req
.ID
.toi_entity
.tei_instance
= teiInstance
;
46 /* There's a subtle problem here...
47 * If an interface is added at this exact instant, (as if by a PCMCIA
48 * card insertion), the array will still not have enough entries after
49 * have allocated it after the first DeviceIoControl call.
51 * We'll get around this by repeating until the number of interfaces
55 status
= DeviceIoControl( tcpFile
,
56 IOCTL_TCP_QUERY_INFORMATION_EX
,
61 &allocationSizeForEntityArray
,
66 return STATUS_UNSUCCESSFUL
;
69 arraySize
= allocationSizeForEntityArray
;
70 entitySet
= HeapAlloc( GetProcessHeap(), 0, arraySize
);
73 status
= STATUS_INSUFFICIENT_RESOURCES
;
77 status
= DeviceIoControl( tcpFile
,
78 IOCTL_TCP_QUERY_INFORMATION_EX
,
83 &allocationSizeForEntityArray
,
86 /* This is why we have the loop -- we might have added an adapter */
87 if( arraySize
== allocationSizeForEntityArray
)
90 HeapFree( GetProcessHeap(), 0, entitySet
);
94 return STATUS_UNSUCCESSFUL
;
95 } while( TRUE
); /* We break if the array we received was the size we
96 * expected. Therefore, we got here because it wasn't */
98 *numEntries
= (arraySize
- fixedPart
) / entrySize
;
99 *tdiEntitySet
= entitySet
;
101 return STATUS_SUCCESS
;
104 VOID
tdiFreeThingSet( PVOID things
) {
105 HeapFree( GetProcessHeap(), 0, things
);
108 NTSTATUS
tdiGetEntityIDSet( HANDLE tcpFile
,
109 TDIEntityID
**entitySet
,
110 PDWORD numEntities
) {
111 NTSTATUS status
= tdiGetSetOfThings( tcpFile
,