Merge 14551:14980 from trunk
[reactos.git] / reactos / drivers / net / tcpip / tcpip / iinfo.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
4 * FILE: tcpip/iinfo.c
5 * PURPOSE: Per-interface information.
6 * PROGRAMMERS: Art Yerkes
7 * REVISIONS:
8 * CSH 01/08-2000 Created
9 */
10
11 #include "precomp.h"
12
13 TDI_STATUS InfoTdiQueryGetInterfaceMIB(TDIEntityID *ID,
14 PIP_INTERFACE Interface,
15 PNDIS_BUFFER Buffer,
16 PUINT BufferSize) {
17 TDI_STATUS Status = TDI_INVALID_REQUEST;
18 PIFENTRY OutData;
19 PLAN_ADAPTER IF = (PLAN_ADAPTER)Interface->Context;
20 PCHAR IFDescr;
21 ULONG Size;
22 UINT DescrLenMax = MAX_IFDESCR_LEN - 1;
23
24 TI_DbgPrint(DEBUG_INFO,
25 ("Getting IFEntry MIB (IF %08x LA %08x) (%04x:%d)\n",
26 Interface, IF, ID->tei_entity, ID->tei_instance));
27
28 OutData =
29 (PIFENTRY)ExAllocatePool( NonPagedPool,
30 sizeof(IFENTRY) + MAX_IFDESCR_LEN );
31
32 if( !OutData ) return TDI_INVALID_REQUEST; /* Out of memory */
33
34 RtlZeroMemory( OutData, sizeof(IFENTRY) + MAX_IFDESCR_LEN );
35
36 OutData->Index = Interface->Index;
37 /* viz: tcpip keeps those indices */
38 OutData->Type = Interface ==
39 Loopback ? MIB_IF_TYPE_LOOPBACK : MIB_IF_TYPE_ETHERNET;
40 OutData->Mtu = Interface->MTU;
41 TI_DbgPrint(DEBUG_INFO,
42 ("Getting interface speed\n"));
43 OutData->PhysAddrLen = Interface->AddressLength;
44 OutData->AdminStatus = MIB_IF_ADMIN_STATUS_UP;
45 /* NDIS_HARDWARE_STATUS -> ROUTER_CONNECTION_STATE */
46 Status = GetInterfaceConnectionStatus( Interface, &OutData->OperStatus );
47
48 /* Not sure what to do here, but not ready seems a safe bet on failure */
49 if( !NT_SUCCESS(Status) )
50 OutData->OperStatus = NdisHardwareStatusNotReady;
51
52 IFDescr = (PCHAR)&OutData[1];
53
54 if( IF ) {
55 GetInterfaceSpeed( Interface, (PUINT)&OutData->Speed );
56 TI_DbgPrint(DEBUG_INFO,
57 ("IF Speed = %d * 100bps\n", OutData->Speed));
58 memcpy(OutData->PhysAddr,Interface->Address,Interface->AddressLength);
59 TI_DbgPrint(DEBUG_INFO, ("Got HWAddr\n"));
60 }
61
62 GetInterfaceName( Interface, IFDescr, MAX_IFDESCR_LEN - 1 );
63 DescrLenMax = strlen( IFDescr ) + 1;
64
65 TI_DbgPrint(DEBUG_INFO, ("Copied in name %s\n", IFDescr));
66 OutData->DescrLen = DescrLenMax;
67 IFDescr += DescrLenMax;
68 Size = IFDescr - (PCHAR)OutData + 1;
69
70 TI_DbgPrint(DEBUG_INFO, ("Finished IFEntry MIB (%04x:%d) size %d\n",
71 ID->tei_entity, ID->tei_instance, Size));
72
73 Status = InfoCopyOut( (PCHAR)OutData, Size, Buffer, BufferSize );
74 ExFreePool( OutData );
75
76 TI_DbgPrint(DEBUG_INFO,("Returning %x\n", Status));
77
78 return Status;
79 }
80
81 TDI_STATUS InfoInterfaceTdiQueryEx( UINT InfoClass,
82 UINT InfoType,
83 UINT InfoId,
84 PVOID Context,
85 TDIEntityID *id,
86 PNDIS_BUFFER Buffer,
87 PUINT BufferSize ) {
88 if( InfoClass == INFO_CLASS_GENERIC &&
89 InfoType == INFO_TYPE_PROVIDER &&
90 InfoId == ENTITY_TYPE_ID ) {
91 ULONG Temp = IF_MIB;
92 return InfoCopyOut( (PCHAR)&Temp, sizeof(Temp), Buffer, BufferSize );
93 } else if( InfoClass == INFO_CLASS_PROTOCOL &&
94 InfoType == INFO_TYPE_PROVIDER &&
95 InfoId == IF_MIB_STATS_ID ) {
96 return InfoTdiQueryGetInterfaceMIB( id, Context, Buffer, BufferSize );
97 } else
98 return TDI_INVALID_REQUEST;
99 }
100
101 TDI_STATUS InfoInterfaceTdiSetEx( UINT InfoClass,
102 UINT InfoType,
103 UINT InfoId,
104 PVOID Context,
105 TDIEntityID *id,
106 PCHAR Buffer,
107 UINT BufferSize ) {
108 TI_DbgPrint(DEBUG_INFO, ("Got Request: Class %x Type %x Id %x, EntityID %x:%x\n",
109 InfoClass, InfoId, id->tei_entity, id->tei_instance));
110 return TDI_INVALID_REQUEST;
111 }