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.

246 lines
6.4 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include "advanced.h"
  4. #include "hwres.h"
  5. #include "ncreg.h"
  6. #include "ncsetup.h"
  7. #include "netcomm.h"
  8. #include "netsetup.h"
  9. HRESULT
  10. HrDoOemUpgradeProcessing(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid,
  11. PCWSTR pszAnswerFile, PCWSTR pszAnswerSections)
  12. {
  13. // Open the driver key
  14. //
  15. HKEY hkey;
  16. HRESULT hr = HrSetupDiOpenDevRegKey(hdi, pdeid,
  17. DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_ALL_ACCESS,
  18. &hkey);
  19. if (S_OK == hr)
  20. {
  21. TraceTag(ttidNetComm, "Calling OEM Upgrade Code");
  22. hr = HrOemUpgrade (hkey, pszAnswerFile, pszAnswerSections);
  23. RegCloseKey(hkey);
  24. }
  25. TraceError("HrDoOemUpgradeProcessing", hr);
  26. return hr;
  27. }
  28. VOID
  29. UpdateAdvancedParametersIfNeeded(HDEVINFO hdi, PSP_DEVINFO_DATA pdeid)
  30. {
  31. Assert(IsValidHandle(hdi));
  32. Assert(pdeid);
  33. CAdvancedParams Advanced;
  34. // initialize advanced params class. This will load parameters and check
  35. // if current values exist. For each parameter with no current value,
  36. // a modifed flag is set which will cause the default to be written
  37. // as the current value on FSave.
  38. //
  39. if (SUCCEEDED(Advanced.HrInit(hdi, pdeid)))
  40. {
  41. // Save any modified values.
  42. (void) Advanced.FSave();
  43. }
  44. }
  45. BOOL
  46. ProcessAnswerFile(
  47. PCWSTR pszAnswerFile,
  48. PCWSTR pszAnswerSections,
  49. HDEVINFO hdi,
  50. PSP_DEVINFO_DATA pdeid)
  51. {
  52. Assert(IsValidHandle(hdi));
  53. Assert(pdeid);
  54. CAdvancedParams Advanced;
  55. BOOL fAdvanced = FALSE;
  56. BOOL fResources = FALSE;
  57. BOOL fModified = FALSE;
  58. if (pszAnswerFile && pszAnswerSections)
  59. {
  60. CHwRes Resources;
  61. HRESULT hr = Resources.HrInit(pdeid->DevInst);
  62. // Only continue to use the HwRes class if S_OK is returned.
  63. //
  64. if (S_OK == hr)
  65. {
  66. Resources.UseAnswerFile(pszAnswerFile, pszAnswerSections);
  67. fResources = TRUE;
  68. }
  69. else
  70. {
  71. hr = S_OK;
  72. }
  73. // initialize
  74. if (SUCCEEDED(Advanced.HrInit(hdi, pdeid)))
  75. {
  76. // We need the advanced params class.
  77. fAdvanced = TRUE;
  78. }
  79. // If the device has advanced paramters, have the advanced class
  80. // read the parameters from the answerfile.
  81. if (fAdvanced)
  82. {
  83. Advanced.UseAnswerFile(pszAnswerFile, pszAnswerSections);
  84. }
  85. hr = HrDoOemUpgradeProcessing(hdi, pdeid, pszAnswerFile,
  86. pszAnswerSections);
  87. if (S_OK == hr)
  88. {
  89. fModified = TRUE;
  90. }
  91. if (fResources)
  92. {
  93. // Validate answerfile params for pResources (hardware resources)
  94. // and apply if validated.
  95. hr = Resources.HrValidateAnswerfileSettings(FALSE);
  96. if (S_OK == hr)
  97. {
  98. Resources.FCommitAnswerfileSettings();
  99. fModified = TRUE;
  100. }
  101. #ifdef ENABLETRACE
  102. else
  103. {
  104. TraceTag(ttidNetComm, "Error in answerfile concerning "
  105. "hardware resources. Base section %S",
  106. pszAnswerSections);
  107. }
  108. #endif
  109. }
  110. // Validate the advanced parameters from the answerfile
  111. // This will attempt to correct bad params. Even though an
  112. // error status is returned, it shouldn't stop us and we should
  113. // still apply changes.
  114. //
  115. if (fAdvanced)
  116. {
  117. (void) Advanced.FValidateAllParams(FALSE, NULL);
  118. // Save any advanced params
  119. fModified = Advanced.FSave();
  120. }
  121. TraceError("Netcomm::HrUpdateAdapterParameters",
  122. (S_FALSE == hr) ? S_OK : hr);
  123. }
  124. return fModified;
  125. }
  126. BOOL
  127. FUpdateAdapterParameters(PCWSTR pszAnswerFile,
  128. PCWSTR pszAnswerSection,
  129. HDEVINFO hdi,
  130. PSP_DEVINFO_DATA pdeid)
  131. {
  132. Assert(IsValidHandle(hdi));
  133. Assert(pdeid);
  134. CAdvancedParams Advanced;
  135. BOOL fAdvanced = FALSE;
  136. BOOL fResources = FALSE;
  137. // initialize
  138. if (SUCCEEDED(Advanced.HrInit(hdi, pdeid)))
  139. {
  140. // We need the advanced params class
  141. fAdvanced = TRUE;
  142. }
  143. if (pszAnswerFile && pszAnswerSection)
  144. {
  145. CHwRes Resources;
  146. HRESULT hr = Resources.HrInit(pdeid->DevInst);
  147. // Only continue to use the HwRes class if S_OK is returned,
  148. // otherwise set a flag to ignore the class (Note: ignore the
  149. // class on S_FALSE as well)
  150. if (S_OK == hr)
  151. {
  152. Resources.UseAnswerFile(pszAnswerFile, pszAnswerSection);
  153. fResources = TRUE;
  154. }
  155. else
  156. {
  157. hr = S_OK;
  158. }
  159. // If the device has advanced paramters, have the advanced class
  160. // read the parameters from the answerfile
  161. if (fAdvanced)
  162. {
  163. Advanced.UseAnswerFile(pszAnswerFile, pszAnswerSection);
  164. }
  165. hr = HrDoOemUpgradeProcessing(hdi, pdeid, pszAnswerFile,
  166. pszAnswerSection);
  167. if (fResources)
  168. {
  169. // Validate answerfile params for pResources (hardware resources)
  170. // and apply if validated
  171. hr = Resources.HrValidateAnswerfileSettings(FALSE);
  172. if (S_OK == hr)
  173. {
  174. Resources.FCommitAnswerfileSettings();
  175. }
  176. #ifdef ENABLETRACE
  177. else
  178. {
  179. TraceTag(ttidNetComm, "Error in answerfile concerning "
  180. "hardware resources. Base section %S",
  181. pszAnswerSection);
  182. }
  183. #endif
  184. }
  185. // Validate the advanced parameters from the answerfile
  186. // This will attempt to correct bad params. Even though an
  187. // error status is returned, it shouldn't stop us and we should
  188. // still apply changes
  189. //
  190. if (fAdvanced)
  191. {
  192. (void) Advanced.FValidateAllParams(FALSE, NULL);
  193. }
  194. TraceError("Netcomm::HrUpdateAdapterParameters",
  195. (S_FALSE == hr) ? S_OK : hr);
  196. }
  197. // Save any advanced params
  198. // Note: we have to do this even if there was no answerfile
  199. // Since the parameters might have defaults
  200. if (fAdvanced)
  201. {
  202. Advanced.FSave();
  203. }
  204. // return TRUE if we had advanced parameters or resources updated
  205. return (fAdvanced || fResources);
  206. }