1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include "pch.hpp"
#include "netvadapter.h"
#include "trace.h"
#include "configuration.tmh"
typedef struct _NETVADAPTER_ADVANCED_PROPERTY
{
UNICODE_STRING RegName; // variable name text
UINT32 FieldOffset; // offset to NetvAdapter field
UINT32 FieldSize; // size (in bytes) of the field
UINT32 Default; // default value to use
UINT32 Min; // minimum value allowed
UINT32 Max; // maximum value allowed
} NETVADAPTER_ADVANCED_PROPERTY;
#define NETV_OFFSET(field) ((UINT32)FIELD_OFFSET(NetvAdapter,field))
#define NETV_SIZE(field) RTL_FIELD_SIZE(NetvAdapter,field)
#define CONSTANT_UNICODE_STRING(s) {sizeof( s ) - sizeof( WCHAR ), sizeof( s ), s }
NETVADAPTER_ADVANCED_PROPERTY NetvSupportedProperties[] =
{
// reg value name - Offset in NetvAdapter - Field size - Default Value - Min - Max
// Standard Keywords
{ CONSTANT_UNICODE_STRING(L"MACLastByte"), NETV_OFFSET(MACLastByte), NETV_SIZE(MACLastByte), 0, 0, 254 },
{ CONSTANT_UNICODE_STRING(L"LinkProcIndex"), NETV_OFFSET(LinkProcIndex), NETV_SIZE(LinkProcIndex), 1000, 0, 1023 },
{ CONSTANT_UNICODE_STRING(L"S0Idle"), NETV_OFFSET(S0Idle), NETV_SIZE(S0Idle), 0, 0, 1 },
{ CONSTANT_UNICODE_STRING(L"EnableUsoUro"), NETV_OFFSET(EnableUsoUro), NETV_SIZE(EnableUsoUro), 0, 0, 1 },
};
NTSTATUS
NetvAdapterReadConfiguration(
NetvAdapter *Adapter,
WDFDEVICE Device
)
{
NTSTATUS status = STATUS_SUCCESS;
NETCONFIGURATION configuration;
RETURN_IF_NOT_STATUS_SUCCESS(
NetDeviceOpenConfiguration(Device, WDF_NO_OBJECT_ATTRIBUTES, &configuration));
// read all the registry values
for (auto &property : NetvSupportedProperties)
{
// Driver should NOT fail the initialization only because it can not
// read the registry
auto pointer = (PUCHAR)Adapter + property.FieldOffset;
// Get the configuration value for a specific parameter. Under NT the
// parameters are all read in as DWORDs.
ULONG value = 0;
status = NetConfigurationQueryUlong(
configuration,
NET_CONFIGURATION_QUERY_ULONG_NO_FLAGS,
&property.RegName,
&value);
// Store the value in the adapter structure.
switch (property.FieldSize)
{
case 1:
*((PUCHAR)pointer) = (UCHAR)value;
break;
case 2:
*((PUSHORT)pointer) = (USHORT)value;
break;
case 4:
*((PULONG)pointer) = (ULONG)value;
break;
default:
break;
}
// If the parameter was present, then check its value for validity.
if (NT_SUCCESS(status))
{
// Check that param value is not too small or too large
if (value < property.Min ||
value > property.Max)
{
value = property.Default;
}
}
else
{
value = property.Default;
status = STATUS_SUCCESS;
}
}
NetConfigurationClose(configuration);
RETURN_STATUS_SUCCESS();
}
|