2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
5 * PURPOSE: TDI query and set information routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * CSH 01/08-2000 Created
15 TDI_STATUS
InfoCopyOut( PCHAR DataOut
, UINT SizeOut
,
16 PNDIS_BUFFER ClientBuf
, PUINT ClientBufSize
) {
17 UINT RememberedCBSize
= *ClientBufSize
;
18 *ClientBufSize
= SizeOut
;
20 /* The driver returns success even when it couldn't fit every available
22 if( RememberedCBSize
< SizeOut
)
25 CopyBufferToBufferChain( ClientBuf
, 0, (PCHAR
)DataOut
, SizeOut
);
30 VOID
InsertTDIInterfaceEntity( PIP_INTERFACE Interface
) {
34 TI_DbgPrint(DEBUG_INFO
,
35 ("Inserting interface %08x (%d entities already)\n",
36 Interface
, EntityCount
));
38 TcpipAcquireSpinLock( &EntityListLock
, &OldIrql
);
40 /* Count IP Entities */
41 for( i
= 0; i
< EntityCount
; i
++ )
42 if( EntityList
[i
].tei_entity
== IF_ENTITY
) {
44 TI_DbgPrint(DEBUG_INFO
, ("Entity %d is an IF. Found %d\n",
48 EntityList
[EntityCount
].tei_entity
= IF_ENTITY
;
49 EntityList
[EntityCount
].tei_instance
= Count
;
50 EntityList
[EntityCount
].context
= Interface
;
51 EntityList
[EntityCount
].info_req
= InfoInterfaceTdiQueryEx
;
52 EntityList
[EntityCount
].info_set
= InfoInterfaceTdiSetEx
;
56 TcpipReleaseSpinLock( &EntityListLock
, OldIrql
);
59 VOID
RemoveTDIInterfaceEntity( PIP_INTERFACE Interface
) {
63 TcpipAcquireSpinLock( &EntityListLock
, &OldIrql
);
65 /* Remove entities that have this interface as context
66 * In the future, this might include AT_ENTITY types, too
68 for( i
= 0; i
< EntityCount
; i
++ ) {
69 if( EntityList
[i
].context
== Interface
) {
70 if( i
!= EntityCount
-1 )
71 memcpy( &EntityList
[i
],
72 &EntityList
[--EntityCount
],
73 sizeof(EntityList
[i
]) );
77 TcpipReleaseSpinLock( &EntityListLock
, OldIrql
);
80 TDI_STATUS
InfoTdiQueryListEntities(PNDIS_BUFFER Buffer
,
83 UINT Count
, Size
, BufSize
= *BufferSize
;
86 TI_DbgPrint(DEBUG_INFO
,("About to copy %d TDIEntityIDs to user\n",
89 TcpipAcquireSpinLock(&EntityListLock
, &OldIrql
);
91 Size
= EntityCount
* sizeof(TDIEntityID
);
94 TI_DbgPrint(DEBUG_INFO
,("BufSize: %d, NeededSize: %d\n", BufSize
, Size
));
98 TcpipReleaseSpinLock( &EntityListLock
, OldIrql
);
99 /* The buffer is too small to contain requested data, but we return
100 * success anyway, as we did everything we wanted. */
104 /* Return entity list -- Copy only the TDIEntityID parts. */
105 for( Count
= 0; Count
< EntityCount
; Count
++ ) {
106 CopyBufferToBufferChain(Buffer
,
107 Count
* sizeof(TDIEntityID
),
108 (PCHAR
)&EntityList
[Count
],
109 sizeof(TDIEntityID
));
112 TcpipReleaseSpinLock(&EntityListLock
, OldIrql
);
117 TDI_STATUS
InfoTdiQueryInformationEx(
118 PTDI_REQUEST Request
,
124 * FUNCTION: Returns extended information
126 * Request = Pointer to TDI request structure for the request
128 * Buffer = Pointer to buffer with data to use
129 * BufferSize = Pointer to buffer with size of Buffer. On return
130 * this is filled with number of bytes returned
131 * Context = Pointer to context buffer
133 * Status of operation
138 PVOID context
= NULL
;
139 NTSTATUS Status
= TDI_INVALID_PARAMETER
;
140 BOOL FoundEntity
= FALSE
;
141 InfoRequest_f InfoRequest
= NULL
;
143 TI_DbgPrint(DEBUG_INFO
,
144 ("InfoEx Req: %x %x %x!%04x:%d\n",
148 ID
->toi_entity
.tei_entity
,
149 ID
->toi_entity
.tei_instance
));
151 /* Check wether it is a query for a list of entities */
152 if (ID
->toi_entity
.tei_entity
== GENERIC_ENTITY
)
154 if ((ID
->toi_class
!= INFO_CLASS_GENERIC
) ||
155 (ID
->toi_type
!= INFO_TYPE_PROVIDER
) ||
156 (ID
->toi_id
!= ENTITY_LIST_ID
)) {
157 TI_DbgPrint(DEBUG_INFO
,("Invalid parameter\n"));
158 Status
= TDI_INVALID_PARAMETER
;
160 Status
= InfoTdiQueryListEntities(Buffer
, BufferSize
);
162 TcpipAcquireSpinLock( &EntityListLock
, &OldIrql
);
164 for( i
= 0; i
< EntityCount
; i
++ ) {
165 if( EntityList
[i
].tei_entity
== ID
->toi_entity
.tei_entity
&&
166 EntityList
[i
].tei_instance
== ID
->toi_entity
.tei_instance
) {
167 InfoRequest
= EntityList
[i
].info_req
;
168 context
= EntityList
[i
].context
;
174 TcpipReleaseSpinLock( &EntityListLock
, OldIrql
);
177 TI_DbgPrint(DEBUG_INFO
,
178 ("Calling Entity %d (%04x:%d) InfoEx (%x,%x,%x)\n",
179 i
, ID
->toi_entity
.tei_entity
,
180 ID
->toi_entity
.tei_instance
,
181 ID
->toi_class
, ID
->toi_type
, ID
->toi_id
));
182 Status
= InfoRequest( ID
->toi_class
,
192 TI_DbgPrint(DEBUG_INFO
,("Status: %08x\n", Status
));
197 TDI_STATUS InfoTdiSetInformationEx
198 (PTDI_REQUEST Request
,
203 * FUNCTION: Sets extended information
205 * Request = Pointer to TDI request structure for the request
206 * ID = Pointer to TDI object ID
207 * Buffer = Pointer to buffer with data to use
208 * BufferSize = Size of Buffer
210 * Status of operation
213 switch( ID
->toi_class
) {
214 case INFO_CLASS_PROTOCOL
:
215 switch( ID
->toi_type
) {
216 case INFO_TYPE_PROVIDER
:
217 switch( ID
->toi_id
) {
218 case IP_MIB_ROUTETABLE_ENTRY_ID
:
219 return InfoNetworkLayerTdiSetEx
232 return TDI_INVALID_PARAMETER
;