Source code of Windows XP (NT5)
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.

254 lines
9.0 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. #if defined(_IA64_)
  85. # define PARAM_OFFSET(Strct, Field) ((LONG)(LONG_PTR)&(((Strct *)0)->Field))
  86. #else
  87. # define PARAM_OFFSET(Strct, Field) ((UINT)((PUCHAR) &((Strct *) 0)->Field))
  88. #endif
  89. #define PARAM_SIZEOF(Strct, Field) sizeof(((Strct *) 0)->Field)
  90. #define PARAM_ENTRY(Strct, Field, Name, \
  91. Required, Type, Flags, \
  92. Default, Min, Max) \
  93. { NDIS_STRING_CONST(Name), \
  94. Required, \
  95. Type, \
  96. Flags, \
  97. PARAM_SIZEOF(Strct, Field), \
  98. PARAM_OFFSET(Strct, Field), \
  99. (PVOID) (Default), \
  100. Min, \
  101. Max }
  102. /* @doc INTERNAL TpiParam TpiParam_h PARAM_TABLE
  103. @struct PARAM_TABLE |
  104. This structure defines how a parameter is to be parsed from the Windows
  105. registry. The driver declares an array of these parameter records and
  106. passes it to <f ParamParseRegistry> during initialization. The values
  107. for each parameter are then read from the registry and can be used to
  108. configure the driver.
  109. <nl>
  110. <f Note>: Multiple parameter tables can be used to parse parameters that
  111. must be stored in different memory locations.
  112. */
  113. typedef struct PARAM_TABLE
  114. {
  115. NDIS_STRING RegVarName; // @field
  116. // Parameter name string declared as an <t NDIS_STRING>. The registry
  117. // parameter key must match this string.
  118. UCHAR Mandantory; // @field
  119. // Set to FALSE, zero, if parameter value is optional; otherwise set to
  120. // TRUE, non-zero, if the parameter is required to exist in the registry.
  121. // If FALSE, and the parameter does not exist, the <y Default> value will
  122. // be returned. If TRUE, and the parameter does not exist, an error code
  123. // is returned and no further parsing is done.
  124. UCHAR Type; // @field
  125. // This value determines how the parameter will be parsed from the
  126. // registry. The value can be one of the following values defined
  127. // by <t NDIS_PARAMETER_TYPE>.
  128. // <nl>0=NdisParameterInteger - Decimal integer value.
  129. // <nl>1=NdisParameterHexInteger - Hexadecimal integer value.
  130. // <nl>2=NdisParameterString - Single UNICODE string value.
  131. // <nl>3=NdisParameterMultiString - Multiple UNICODE string values.
  132. // These are returned as a list of N strings, separated by NULL
  133. // terminators, the last string is followed by two NULL terminators.
  134. UCHAR Flags; // @field
  135. // This value determines how a string parameter will be translated before
  136. // it is returned to the caller. <f Flags> can be one of the following
  137. // values:
  138. // <nl>0=PARAM_FLAGS_ANSISTRING - Return string value as an ANSI string.
  139. // <nl>0=PARAM_FLAGS_ANSISTRING - Return string value as a UNICODE string.
  140. # define PARAM_FLAGS_ANSISTRING 0
  141. # define PARAM_FLAGS_UNICODESTRING 1
  142. UCHAR Size; // @field
  143. // This value determines how an integer parameter will be translated
  144. // before it is returned to the caller. <f Size> can be one of the
  145. // following values:
  146. // <nl>0=UINT - unsigned integer (16 or 32 bits).
  147. // <nl>1=UCHAR - unsigned char integer (8 bits).
  148. // <nl>2=USHORT - unsigned short integer (16 bits).
  149. // <nl>4=ULONG - unsigned long integer (32 bits).
  150. // <f Note>: The most-significant bits will be truncated in the conversion.
  151. UINT Offset; // @field
  152. // This value indicates the offset, in bytes, from the <f BaseContext>
  153. // pointer passed into <f ParamParseRegistry>. The return value for
  154. // the parameter will be saved at this offset from <f BaseContext>.
  155. // <nl>*(PUINT)((PUCHAR)BaseContext+Offset) = (UINT) Value;
  156. PVOID Default; // @field
  157. // This value is used as the default value for the parameter if it is
  158. // not found in the registry, and it is not mandatory. This only applys
  159. // to integer parameters. String parameters must provide support for
  160. // their own default values.
  161. UINT Min; // @field
  162. // If this value is non-zero, and the parameter is an integer type, the
  163. // registry value will be compared to make sure it is \>= <f Min>.
  164. // If the registry value is less, the returned value will be set to
  165. // <f Min> and no error is returned.
  166. UINT Max; // @field
  167. // If this value is non-zero, and the parameter is an integer type, the
  168. // registry value will be compared to make sure it is \<= <f Max>.
  169. // If the registry value is greater, the returned value will be set to
  170. // <f Max> and no error is returned.
  171. UINT Reserved; // @field
  172. // This field is not currently used, and it must be zero for future
  173. // compatability.
  174. } PARAM_TABLE, *PPARAM_TABLE;
  175. extern USHORT ustrlen(
  176. IN PUSHORT string
  177. );
  178. extern NDIS_STATUS ParamParseRegistry(
  179. IN NDIS_HANDLE AdapterHandle,
  180. IN NDIS_HANDLE RegistryConfigHandle,
  181. IN PUCHAR BaseContext,
  182. IN PPARAM_TABLE Parameters
  183. );
  184. extern VOID ParamUnicodeStringToAnsiString(
  185. OUT PANSI_STRING out,
  186. IN PUNICODE_STRING in
  187. );
  188. extern VOID ParamUnicodeCopyString(
  189. OUT PUNICODE_STRING out,
  190. IN PUNICODE_STRING in
  191. );
  192. #endif // _TPIPARAM_H