Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
9.1 KiB

  1. /*
  2. (C) Copyright 1998
  3. All rights reserved.
  4. Portions of this software are:
  5. (C) Copyright 1994 TriplePoint, Inc. -- http://www.TriplePoint.com
  6. License to use this software is granted under the same terms
  7. outlined in the Microsoft Windows Device Driver Development Kit.
  8. (C) Copyright 1992 Microsoft Corp. -- http://www.Microsoft.com
  9. License to use this software is granted under the terms outlined in
  10. the Microsoft Windows Device Driver Development Kit.
  11. @doc INTERNAL TpiParam TpiParam_h
  12. @module TpiParam.h |
  13. This module, along with <f TpiParam\.c>, implements a table driven parser
  14. for the NDIS registry parameters. This file defines the parameter
  15. parsing structures and values used by the routine <f ParamParseRegistry>.
  16. You should #include this file into the driver module defining the
  17. configuration parameter table <t PARAM_TABLE>.
  18. @comm
  19. See <f Keywords\.h> for details of how to add new parameters.
  20. This is a driver independent module which can be re-used, without
  21. change, by any NDIS3 driver.
  22. @head3 Contents |
  23. @index class,mfunc,func,msg,mdata,struct,enum | TpiParam_h
  24. @end
  25. */
  26. #ifndef _TPIPARAM_H
  27. #define _TPIPARAM_H
  28. #if !defined(NDIS_NT) && !defined(UNICODE_NULL)
  29. /*
  30. // These types were culled from the NT ndis.h file
  31. // We should be compiling with the NT DDK's ndis.h to get these,
  32. // but sometimes we need to compile with the 95 DDK ndis.h.
  33. */
  34. #undef PUNICODE_STRING
  35. typedef USHORT WCHAR;
  36. typedef WCHAR *PWSTR;
  37. typedef STRING ANSI_STRING;
  38. typedef PSTRING PANSI_STRING;
  39. /*
  40. // Unicode strings are counted 16-bit character strings. If they are
  41. // NULL terminated, Length does not include trailing NULL.
  42. */
  43. typedef struct _UNICODE_STRING {
  44. USHORT Length;
  45. USHORT MaximumLength;
  46. #ifdef MIDL_PASS
  47. [size_is(MaximumLength / 2), length_is((Length) / 2) ] USHORT * Buffer;
  48. #else // MIDL_PASS
  49. PWSTR Buffer;
  50. #endif // MIDL_PASS
  51. } UNICODE_STRING;
  52. typedef UNICODE_STRING *PUNICODE_STRING;
  53. #define UNICODE_NULL ((WCHAR)0) // winnt
  54. #endif // NDIS_NT
  55. /* @doc INTERNAL TpiParam TpiParam_h PARAM_ENTRY
  56. @func <t PARAM_TABLE> | PARAM_ENTRY |
  57. This macro is used to define an entry in the registry parameter table,
  58. one entry per parameter. See <t PARAM_TABLE> for more details on the
  59. expected input values.
  60. @parm struct | Strct | The structure type associated with <f Field>.
  61. @parm type | Field | The name of the field within the structure <f Strct>.
  62. @parm const char * | Name | The name of the registry parameter key.
  63. @parm BOOL | Required | True if parameter is required.
  64. @parm NDIS_PARAMETER_TYPE | Type | The kind of parameter value.
  65. @parm UCHAR | Flags | How to return a string parameter value (ANSI, UNICODE).
  66. @parm UINT | Default | The default value for an undefined integer parameter.
  67. @parm UINT | Min | The minimum value for an integer parameter.
  68. @parm UINT | Max | The minimum value for an integer parameter.
  69. @comm
  70. Parameters that need to be stored in different data structures, need to
  71. be declared in separate parameter tables, and then parsed separately
  72. using mulitple calls to <f ParamParseRegistry>.
  73. @iex
  74. PARAM_TABLE ParameterTable[] =
  75. {
  76. PARAM_ENTRY(MINIPORT_CONTEXT, DbgFlags, PARAM_DEBUGFLAGS_STRING,
  77. FALSE, NdisParameterHexInteger, 0,
  78. DBG_ERROR_ON|DBG_WARNING_ON, 0, 0xffffffff),
  79. // The last entry must be an empty string!
  80. { { 0 } }
  81. };
  82. @normal
  83. */
  84. #define PARAM_OFFSET(Strct, Field) ((ULONG)(ULONG_PTR)&(((Strct *)0)->Field))
  85. #define PARAM_SIZEOF(Strct, Field) sizeof(((Strct *) 0)->Field)
  86. #define PARAM_ENTRY(Strct, Field, Name, \
  87. Required, Type, Flags, \
  88. Default, Min, Max) \
  89. { NDIS_STRING_CONST(Name), \
  90. Required, \
  91. Type, \
  92. Flags, \
  93. PARAM_SIZEOF(Strct, Field), \
  94. PARAM_OFFSET(Strct, Field), \
  95. (PVOID) (Default), \
  96. Min, \
  97. Max }
  98. /* @doc INTERNAL TpiParam TpiParam_h PARAM_TABLE
  99. @struct PARAM_TABLE |
  100. This structure defines how a parameter is to be parsed from the Windows
  101. registry. The driver declares an array of these parameter records and
  102. passes it to <f ParamParseRegistry> during initialization. The values
  103. for each parameter are then read from the registry and can be used to
  104. configure the driver.
  105. <nl>
  106. <f Note>: Multiple parameter tables can be used to parse parameters that
  107. must be stored in different memory locations.
  108. */
  109. typedef struct PARAM_TABLE
  110. {
  111. NDIS_STRING RegVarName; // @field
  112. // Parameter name string declared as an <t NDIS_STRING>. The registry
  113. // parameter key must match this string.
  114. UCHAR Mandantory; // @field
  115. // Set to FALSE, zero, if parameter value is optional; otherwise set to
  116. // TRUE, non-zero, if the parameter is required to exist in the registry.
  117. // If FALSE, and the parameter does not exist, the <y Default> value will
  118. // be returned. If TRUE, and the parameter does not exist, an error code
  119. // is returned and no further parsing is done.
  120. UCHAR Type; // @field
  121. // This value determines how the parameter will be parsed from the
  122. // registry. The value can be one of the following values defined
  123. // by <t NDIS_PARAMETER_TYPE>.
  124. // <nl>0=NdisParameterInteger - Decimal integer value.
  125. // <nl>1=NdisParameterHexInteger - Hexadecimal integer value.
  126. // <nl>2=NdisParameterString - Single UNICODE string value.
  127. // <nl>3=NdisParameterMultiString - Multiple UNICODE string values.
  128. // These are returned as a list of N strings, separated by NULL
  129. // terminators, the last string is followed by two NULL terminators.
  130. UCHAR Flags; // @field
  131. // This value determines how a string parameter will be translated before
  132. // it is returned to the caller. <f Flags> can be one of the following
  133. // values:
  134. // <nl>0=PARAM_FLAGS_ANSISTRING - Return string value as an ANSI string.
  135. // <nl>0=PARAM_FLAGS_ANSISTRING - Return string value as a UNICODE string.
  136. # define PARAM_FLAGS_ANSISTRING 0
  137. # define PARAM_FLAGS_UNICODESTRING 1
  138. UCHAR Size; // @field
  139. // This value determines how an integer parameter will be translated
  140. // before it is returned to the caller. <f Size> can be one of the
  141. // following values:
  142. // <nl>0=UINT - unsigned integer (16 or 32 bits).
  143. // <nl>1=UCHAR - unsigned char integer (8 bits).
  144. // <nl>2=USHORT - unsigned short integer (16 bits).
  145. // <nl>4=ULONG - unsigned long integer (32 bits).
  146. // <f Note>: The most-significant bits will be truncated in the conversion.
  147. UINT Offset; // @field
  148. // This value indicates the offset, in bytes, from the <f BaseContext>
  149. // pointer passed into <f ParamParseRegistry>. The return value for
  150. // the parameter will be saved at this offset from <f BaseContext>.
  151. // <nl>*(PUINT)((PUCHAR)BaseContext+Offset) = (UINT) Value;
  152. PVOID Default; // @field
  153. // This value is used as the default value for the parameter if it is
  154. // not found in the registry, and it is not mandatory. This only applys
  155. // to integer parameters. String parameters must provide support for
  156. // their own default values.
  157. UINT Min; // @field
  158. // If this value is non-zero, and the parameter is an integer type, the
  159. // registry value will be compared to make sure it is \>= <f Min>.
  160. // If the registry value is less, the returned value will be set to
  161. // <f Min> and no error is returned.
  162. UINT Max; // @field
  163. // If this value is non-zero, and the parameter is an integer type, the
  164. // registry value will be compared to make sure it is \<= <f Max>.
  165. // If the registry value is greater, the returned value will be set to
  166. // <f Max> and no error is returned.
  167. UINT Reserved; // @field
  168. // This field is not currently used, and it must be zero for future
  169. // compatability.
  170. } PARAM_TABLE, *PPARAM_TABLE;
  171. extern USHORT ustrlen(
  172. IN PUSHORT string
  173. );
  174. extern NDIS_STATUS ParamParseRegistry(
  175. IN NDIS_HANDLE AdapterHandle,
  176. IN NDIS_HANDLE RegistryConfigHandle,
  177. IN PUCHAR BaseContext,
  178. IN PPARAM_TABLE Parameters
  179. );
  180. extern VOID ParamUnicodeStringToAnsiString(
  181. OUT PANSI_STRING out,
  182. IN PUNICODE_STRING in
  183. );
  184. extern VOID ParamUnicodeCopyString(
  185. OUT PUNICODE_STRING out,
  186. IN PUNICODE_STRING in
  187. );
  188. #endif // _TPIPARAM_H