HttpBootConfig.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /** @file
  2. Helper functions for configuring or getting the parameters relating to HTTP Boot.
  3. Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "HttpBootDxe.h"
  7. #include <Library/UefiBootManagerLib.h>
  8. CHAR16 mHttpBootConfigStorageName[] = L"HTTP_BOOT_CONFIG_IFR_NVDATA";
  9. /**
  10. Add new boot option for HTTP boot.
  11. @param[in] Private Pointer to the driver private data.
  12. @param[in] UsingIpv6 Set to TRUE if creating boot option for IPv6.
  13. @param[in] Description The description text of the boot option.
  14. @param[in] Uri The URI string of the boot file.
  15. @retval EFI_SUCCESS The boot option is created successfully.
  16. @retval Others Failed to create new boot option.
  17. **/
  18. EFI_STATUS
  19. HttpBootAddBootOption (
  20. IN HTTP_BOOT_PRIVATE_DATA *Private,
  21. IN BOOLEAN UsingIpv6,
  22. IN CHAR16 *Description,
  23. IN CHAR16 *Uri
  24. )
  25. {
  26. EFI_DEV_PATH *Node;
  27. EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath;
  28. EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
  29. UINTN Length;
  30. CHAR8 AsciiUri[URI_STR_MAX_SIZE];
  31. EFI_STATUS Status;
  32. UINTN Index;
  33. EFI_BOOT_MANAGER_LOAD_OPTION NewOption;
  34. NewDevicePath = NULL;
  35. Node = NULL;
  36. TmpDevicePath = NULL;
  37. if (StrLen (Description) == 0) {
  38. return EFI_INVALID_PARAMETER;
  39. }
  40. //
  41. // Convert the scheme to all lower case.
  42. //
  43. for (Index = 0; Index < StrLen (Uri); Index++) {
  44. if (Uri[Index] == L':') {
  45. break;
  46. }
  47. if ((Uri[Index] >= L'A') && (Uri[Index] <= L'Z')) {
  48. Uri[Index] -= (CHAR16)(L'A' - L'a');
  49. }
  50. }
  51. //
  52. // Only accept empty URI, or http and https URI.
  53. //
  54. if ((StrLen (Uri) != 0) && (StrnCmp (Uri, L"http://", 7) != 0) && (StrnCmp (Uri, L"https://", 8) != 0)) {
  55. return EFI_INVALID_PARAMETER;
  56. }
  57. //
  58. // Create a new device path by appending the IP node and URI node to
  59. // the driver's parent device path
  60. //
  61. if (!UsingIpv6) {
  62. Node = AllocateZeroPool (sizeof (IPv4_DEVICE_PATH));
  63. if (Node == NULL) {
  64. Status = EFI_OUT_OF_RESOURCES;
  65. goto ON_EXIT;
  66. }
  67. Node->Ipv4.Header.Type = MESSAGING_DEVICE_PATH;
  68. Node->Ipv4.Header.SubType = MSG_IPv4_DP;
  69. SetDevicePathNodeLength (Node, sizeof (IPv4_DEVICE_PATH));
  70. } else {
  71. Node = AllocateZeroPool (sizeof (IPv6_DEVICE_PATH));
  72. if (Node == NULL) {
  73. Status = EFI_OUT_OF_RESOURCES;
  74. goto ON_EXIT;
  75. }
  76. Node->Ipv6.Header.Type = MESSAGING_DEVICE_PATH;
  77. Node->Ipv6.Header.SubType = MSG_IPv6_DP;
  78. SetDevicePathNodeLength (Node, sizeof (IPv6_DEVICE_PATH));
  79. }
  80. TmpDevicePath = AppendDevicePathNode (Private->ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
  81. FreePool (Node);
  82. if (TmpDevicePath == NULL) {
  83. return EFI_OUT_OF_RESOURCES;
  84. }
  85. //
  86. // Update the URI node with the input boot file URI.
  87. //
  88. UnicodeStrToAsciiStrS (Uri, AsciiUri, sizeof (AsciiUri));
  89. Length = sizeof (EFI_DEVICE_PATH_PROTOCOL) + AsciiStrSize (AsciiUri);
  90. Node = AllocatePool (Length);
  91. if (Node == NULL) {
  92. Status = EFI_OUT_OF_RESOURCES;
  93. FreePool (TmpDevicePath);
  94. goto ON_EXIT;
  95. }
  96. Node->DevPath.Type = MESSAGING_DEVICE_PATH;
  97. Node->DevPath.SubType = MSG_URI_DP;
  98. SetDevicePathNodeLength (Node, Length);
  99. CopyMem ((UINT8 *)Node + sizeof (EFI_DEVICE_PATH_PROTOCOL), AsciiUri, AsciiStrSize (AsciiUri));
  100. NewDevicePath = AppendDevicePathNode (TmpDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)Node);
  101. FreePool (Node);
  102. FreePool (TmpDevicePath);
  103. if (NewDevicePath == NULL) {
  104. Status = EFI_OUT_OF_RESOURCES;
  105. goto ON_EXIT;
  106. }
  107. //
  108. // Add a new load option.
  109. //
  110. Status = EfiBootManagerInitializeLoadOption (
  111. &NewOption,
  112. LoadOptionNumberUnassigned,
  113. LoadOptionTypeBoot,
  114. LOAD_OPTION_ACTIVE,
  115. Description,
  116. NewDevicePath,
  117. NULL,
  118. 0
  119. );
  120. if (EFI_ERROR (Status)) {
  121. goto ON_EXIT;
  122. }
  123. Status = EfiBootManagerAddLoadOptionVariable (&NewOption, (UINTN)-1);
  124. EfiBootManagerFreeLoadOption (&NewOption);
  125. ON_EXIT:
  126. if (NewDevicePath != NULL) {
  127. FreePool (NewDevicePath);
  128. }
  129. return Status;
  130. }
  131. /**
  132. This function allows the caller to request the current
  133. configuration for one or more named elements. The resulting
  134. string is in <ConfigAltResp> format. Also, any and all alternative
  135. configuration strings shall be appended to the end of the
  136. current configuration string. If they are, they must appear
  137. after the current configuration. They must contain the same
  138. routing (GUID, NAME, PATH) as the current configuration string.
  139. They must have an additional description indicating the type of
  140. alternative configuration the string represents,
  141. "ALTCFG=<StringToken>". That <StringToken> (when
  142. converted from Hex UNICODE to binary) is a reference to a
  143. string in the associated string pack.
  144. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  145. @param[in] Request A null-terminated Unicode string in
  146. <ConfigRequest> format. Note that this
  147. includes the routing information as well as
  148. the configurable name / value pairs. It is
  149. invalid for this string to be in
  150. <MultiConfigRequest> format.
  151. @param[out] Progress On return, points to a character in the
  152. Request string. Points to the string's null
  153. terminator if request was successful. Points
  154. to the most recent "&" before the first
  155. failing name / value pair (or the beginning
  156. of the string if the failure is in the first
  157. name / value pair) if the request was not successful.
  158. @param[out] Results A null-terminated Unicode string in
  159. <ConfigAltResp> format which has all values
  160. filled in for the names in the Request string.
  161. String to be allocated by the called function.
  162. @retval EFI_SUCCESS The Results string is filled with the
  163. values corresponding to all requested
  164. names.
  165. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
  166. parts of the results that must be
  167. stored awaiting possible future
  168. protocols.
  169. @retval EFI_INVALID_PARAMETER For example, passing in a NULL
  170. for the Request parameter
  171. would result in this type of
  172. error. In this case, the
  173. Progress parameter would be
  174. set to NULL.
  175. @retval EFI_NOT_FOUND Routing data doesn't match any
  176. known driver. Progress set to the
  177. first character in the routing header.
  178. Note: There is no requirement that the
  179. driver validate the routing data. It
  180. must skip the <ConfigHdr> in order to
  181. process the names.
  182. @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
  183. to most recent "&" before the
  184. error or the beginning of the
  185. string.
  186. @retval EFI_INVALID_PARAMETER Unknown name. Progress points
  187. to the & before the name in
  188. question.
  189. **/
  190. EFI_STATUS
  191. EFIAPI
  192. HttpBootFormExtractConfig (
  193. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  194. IN CONST EFI_STRING Request,
  195. OUT EFI_STRING *Progress,
  196. OUT EFI_STRING *Results
  197. )
  198. {
  199. EFI_STATUS Status;
  200. UINTN BufferSize;
  201. HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;
  202. EFI_STRING ConfigRequestHdr;
  203. EFI_STRING ConfigRequest;
  204. BOOLEAN AllocatedRequest;
  205. UINTN Size;
  206. if ((Progress == NULL) || (Results == NULL)) {
  207. return EFI_INVALID_PARAMETER;
  208. }
  209. *Progress = Request;
  210. if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gHttpBootConfigGuid, mHttpBootConfigStorageName)) {
  211. return EFI_NOT_FOUND;
  212. }
  213. ConfigRequestHdr = NULL;
  214. ConfigRequest = NULL;
  215. AllocatedRequest = FALSE;
  216. Size = 0;
  217. CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);
  218. //
  219. // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
  220. //
  221. BufferSize = sizeof (HTTP_BOOT_CONFIG_IFR_NVDATA);
  222. ZeroMem (&CallbackInfo->HttpBootNvData, BufferSize);
  223. StrCpyS (CallbackInfo->HttpBootNvData.Description, DESCRIPTION_STR_MAX_SIZE / sizeof (CHAR16), HTTP_BOOT_DEFAULT_DESCRIPTION_STR);
  224. ConfigRequest = Request;
  225. if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
  226. //
  227. // Request has no request element, construct full request string.
  228. // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
  229. // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
  230. //
  231. ConfigRequestHdr = HiiConstructConfigHdr (&gHttpBootConfigGuid, mHttpBootConfigStorageName, CallbackInfo->ChildHandle);
  232. Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
  233. ConfigRequest = AllocateZeroPool (Size);
  234. if (ConfigRequest == NULL) {
  235. return EFI_OUT_OF_RESOURCES;
  236. }
  237. AllocatedRequest = TRUE;
  238. UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
  239. FreePool (ConfigRequestHdr);
  240. }
  241. Status = gHiiConfigRouting->BlockToConfig (
  242. gHiiConfigRouting,
  243. ConfigRequest,
  244. (UINT8 *)&CallbackInfo->HttpBootNvData,
  245. BufferSize,
  246. Results,
  247. Progress
  248. );
  249. //
  250. // Free the allocated config request string.
  251. //
  252. if (AllocatedRequest) {
  253. FreePool (ConfigRequest);
  254. ConfigRequest = NULL;
  255. }
  256. //
  257. // Set Progress string to the original request string.
  258. //
  259. if (Request == NULL) {
  260. *Progress = NULL;
  261. } else if (StrStr (Request, L"OFFSET") == NULL) {
  262. *Progress = Request + StrLen (Request);
  263. }
  264. return Status;
  265. }
  266. /**
  267. This function applies changes in a driver's configuration.
  268. Input is a Configuration, which has the routing data for this
  269. driver followed by name / value configuration pairs. The driver
  270. must apply those pairs to its configurable storage. If the
  271. driver's configuration is stored in a linear block of data
  272. and the driver's name / value pairs are in <BlockConfig>
  273. format, it may use the ConfigToBlock helper function (above) to
  274. simplify the job.
  275. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  276. @param[in] Configuration A null-terminated Unicode string in
  277. <ConfigString> format.
  278. @param[out] Progress A pointer to a string filled in with the
  279. offset of the most recent '&' before the
  280. first failing name / value pair (or the
  281. beginning of the string if the failure
  282. is in the first name / value pair) or
  283. the terminating NULL if all was
  284. successful.
  285. @retval EFI_SUCCESS The results have been distributed or are
  286. awaiting distribution.
  287. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
  288. parts of the results that must be
  289. stored awaiting possible future
  290. protocols.
  291. @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
  292. Results parameter would result
  293. in this type of error.
  294. @retval EFI_NOT_FOUND Target for the specified routing data
  295. was not found.
  296. **/
  297. EFI_STATUS
  298. EFIAPI
  299. HttpBootFormRouteConfig (
  300. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  301. IN CONST EFI_STRING Configuration,
  302. OUT EFI_STRING *Progress
  303. )
  304. {
  305. EFI_STATUS Status;
  306. UINTN BufferSize;
  307. HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;
  308. HTTP_BOOT_PRIVATE_DATA *Private;
  309. if (Progress == NULL) {
  310. return EFI_INVALID_PARAMETER;
  311. }
  312. *Progress = Configuration;
  313. if (Configuration == NULL) {
  314. return EFI_INVALID_PARAMETER;
  315. }
  316. //
  317. // Check routing data in <ConfigHdr>.
  318. // Note: there is no name for Name/Value storage, only GUID will be checked
  319. //
  320. if (!HiiIsConfigHdrMatch (Configuration, &gHttpBootConfigGuid, mHttpBootConfigStorageName)) {
  321. return EFI_NOT_FOUND;
  322. }
  323. CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);
  324. Private = HTTP_BOOT_PRIVATE_DATA_FROM_CALLBACK_INFO (CallbackInfo);
  325. BufferSize = sizeof (HTTP_BOOT_CONFIG_IFR_NVDATA);
  326. ZeroMem (&CallbackInfo->HttpBootNvData, BufferSize);
  327. Status = gHiiConfigRouting->ConfigToBlock (
  328. gHiiConfigRouting,
  329. Configuration,
  330. (UINT8 *)&CallbackInfo->HttpBootNvData,
  331. &BufferSize,
  332. Progress
  333. );
  334. if (EFI_ERROR (Status)) {
  335. return Status;
  336. }
  337. //
  338. // Create a new boot option according to the configuration data.
  339. //
  340. HttpBootAddBootOption (
  341. Private,
  342. (CallbackInfo->HttpBootNvData.IpVersion == HTTP_BOOT_IP_VERSION_6) ? TRUE : FALSE,
  343. CallbackInfo->HttpBootNvData.Description,
  344. CallbackInfo->HttpBootNvData.Uri
  345. );
  346. return EFI_SUCCESS;
  347. }
  348. /**
  349. This function is called to provide results data to the driver.
  350. This data consists of a unique key that is used to identify
  351. which data is either being passed back or being asked for.
  352. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  353. @param[in] Action Specifies the type of action taken by the browser.
  354. @param[in] QuestionId A unique value which is sent to the original
  355. exporting driver so that it can identify the type
  356. of data to expect. The format of the data tends to
  357. vary based on the opcode that generated the callback.
  358. @param[in] Type The type of value for the question.
  359. @param[in, out] Value A pointer to the data being sent to the original
  360. exporting driver.
  361. @param[out] ActionRequest On return, points to the action requested by the
  362. callback function.
  363. @retval EFI_SUCCESS The callback successfully handled the action.
  364. @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
  365. variable and its data.
  366. @retval EFI_DEVICE_ERROR The variable could not be saved.
  367. @retval EFI_UNSUPPORTED The specified Action is not supported by the
  368. callback.
  369. **/
  370. EFI_STATUS
  371. EFIAPI
  372. HttpBootFormCallback (
  373. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  374. IN EFI_BROWSER_ACTION Action,
  375. IN EFI_QUESTION_ID QuestionId,
  376. IN UINT8 Type,
  377. IN OUT EFI_IFR_TYPE_VALUE *Value,
  378. OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
  379. )
  380. {
  381. EFI_INPUT_KEY Key;
  382. CHAR16 *Uri;
  383. UINTN UriLen;
  384. CHAR8 *AsciiUri;
  385. HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;
  386. EFI_STATUS Status;
  387. Uri = NULL;
  388. UriLen = 0;
  389. AsciiUri = NULL;
  390. Status = EFI_SUCCESS;
  391. if ((This == NULL) || (Value == NULL)) {
  392. return EFI_INVALID_PARAMETER;
  393. }
  394. CallbackInfo = HTTP_BOOT_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);
  395. if (Action != EFI_BROWSER_ACTION_CHANGING) {
  396. return EFI_UNSUPPORTED;
  397. }
  398. switch (QuestionId) {
  399. case KEY_INITIATOR_URI:
  400. //
  401. // Get user input URI string
  402. //
  403. Uri = HiiGetString (CallbackInfo->RegisteredHandle, Value->string, NULL);
  404. if (Uri == NULL) {
  405. return EFI_INVALID_PARAMETER;
  406. }
  407. //
  408. // The URI should be either an empty string (for corporate environment) ,or http(s) for home environment.
  409. // Pop up a message box for the unsupported URI.
  410. //
  411. if (StrLen (Uri) != 0) {
  412. UriLen = StrLen (Uri) + 1;
  413. AsciiUri = AllocateZeroPool (UriLen);
  414. if (AsciiUri == NULL) {
  415. FreePool (Uri);
  416. return EFI_OUT_OF_RESOURCES;
  417. }
  418. UnicodeStrToAsciiStrS (Uri, AsciiUri, UriLen);
  419. Status = HttpBootCheckUriScheme (AsciiUri);
  420. if (Status == EFI_INVALID_PARAMETER) {
  421. DEBUG ((DEBUG_ERROR, "HttpBootFormCallback: %r.\n", Status));
  422. CreatePopUp (
  423. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  424. &Key,
  425. L"ERROR: Unsupported URI!",
  426. L"Only supports HTTP and HTTPS",
  427. NULL
  428. );
  429. } else if (Status == EFI_ACCESS_DENIED) {
  430. DEBUG ((DEBUG_ERROR, "HttpBootFormCallback: %r.\n", Status));
  431. CreatePopUp (
  432. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  433. &Key,
  434. L"ERROR: Unsupported URI!",
  435. L"HTTP is disabled",
  436. NULL
  437. );
  438. }
  439. }
  440. if (Uri != NULL) {
  441. FreePool (Uri);
  442. }
  443. if (AsciiUri != NULL) {
  444. FreePool (AsciiUri);
  445. }
  446. break;
  447. default:
  448. break;
  449. }
  450. return Status;
  451. }
  452. /**
  453. Initialize the configuration form.
  454. @param[in] Private Pointer to the driver private data.
  455. @retval EFI_SUCCESS The configuration form is initialized.
  456. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
  457. **/
  458. EFI_STATUS
  459. HttpBootConfigFormInit (
  460. IN HTTP_BOOT_PRIVATE_DATA *Private
  461. )
  462. {
  463. EFI_STATUS Status;
  464. HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;
  465. VENDOR_DEVICE_PATH VendorDeviceNode;
  466. CHAR16 *MacString;
  467. CHAR16 *OldMenuString;
  468. CHAR16 MenuString[128];
  469. CallbackInfo = &Private->CallbackInfo;
  470. if (CallbackInfo->Initialized) {
  471. return EFI_SUCCESS;
  472. }
  473. CallbackInfo->Signature = HTTP_BOOT_FORM_CALLBACK_INFO_SIGNATURE;
  474. //
  475. // Construct device path node for EFI HII Config Access protocol,
  476. // which consists of controller physical device path and one hardware
  477. // vendor guid node.
  478. //
  479. ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH));
  480. VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH;
  481. VendorDeviceNode.Header.SubType = HW_VENDOR_DP;
  482. CopyGuid (&VendorDeviceNode.Guid, &gEfiCallerIdGuid);
  483. SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));
  484. CallbackInfo->HiiVendorDevicePath = AppendDevicePathNode (
  485. Private->ParentDevicePath,
  486. (EFI_DEVICE_PATH_PROTOCOL *)&VendorDeviceNode
  487. );
  488. if (CallbackInfo->HiiVendorDevicePath == NULL) {
  489. Status = EFI_OUT_OF_RESOURCES;
  490. goto Error;
  491. }
  492. CallbackInfo->ConfigAccess.ExtractConfig = HttpBootFormExtractConfig;
  493. CallbackInfo->ConfigAccess.RouteConfig = HttpBootFormRouteConfig;
  494. CallbackInfo->ConfigAccess.Callback = HttpBootFormCallback;
  495. //
  496. // Install Device Path Protocol and Config Access protocol to driver handle.
  497. //
  498. Status = gBS->InstallMultipleProtocolInterfaces (
  499. &CallbackInfo->ChildHandle,
  500. &gEfiDevicePathProtocolGuid,
  501. CallbackInfo->HiiVendorDevicePath,
  502. &gEfiHiiConfigAccessProtocolGuid,
  503. &CallbackInfo->ConfigAccess,
  504. NULL
  505. );
  506. if (EFI_ERROR (Status)) {
  507. goto Error;
  508. }
  509. //
  510. // Publish our HII data.
  511. //
  512. CallbackInfo->RegisteredHandle = HiiAddPackages (
  513. &gHttpBootConfigGuid,
  514. CallbackInfo->ChildHandle,
  515. HttpBootDxeStrings,
  516. HttpBootConfigVfrBin,
  517. NULL
  518. );
  519. if (CallbackInfo->RegisteredHandle == NULL) {
  520. Status = EFI_OUT_OF_RESOURCES;
  521. goto Error;
  522. }
  523. //
  524. // Append MAC string in the menu help string
  525. //
  526. Status = NetLibGetMacString (Private->Controller, NULL, &MacString);
  527. if (!EFI_ERROR (Status)) {
  528. OldMenuString = HiiGetString (
  529. CallbackInfo->RegisteredHandle,
  530. STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP),
  531. NULL
  532. );
  533. UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
  534. HiiSetString (
  535. CallbackInfo->RegisteredHandle,
  536. STRING_TOKEN (STR_HTTP_BOOT_CONFIG_FORM_HELP),
  537. MenuString,
  538. NULL
  539. );
  540. FreePool (MacString);
  541. FreePool (OldMenuString);
  542. CallbackInfo->Initialized = TRUE;
  543. return EFI_SUCCESS;
  544. }
  545. Error:
  546. HttpBootConfigFormUnload (Private);
  547. return Status;
  548. }
  549. /**
  550. Unload the configuration form, this includes: delete all the configuration
  551. entries, uninstall the form callback protocol, and free the resources used.
  552. The form will only be unload completely when both IP4 and IP6 stack are stopped.
  553. @param[in] Private Pointer to the driver private data.
  554. @retval EFI_SUCCESS The configuration form is unloaded.
  555. @retval Others Failed to unload the form.
  556. **/
  557. EFI_STATUS
  558. HttpBootConfigFormUnload (
  559. IN HTTP_BOOT_PRIVATE_DATA *Private
  560. )
  561. {
  562. HTTP_BOOT_FORM_CALLBACK_INFO *CallbackInfo;
  563. if ((Private->Ip4Nic != NULL) || (Private->Ip6Nic != NULL)) {
  564. //
  565. // Only unload the configuration form when both IP4 and IP6 stack are stopped.
  566. //
  567. return EFI_SUCCESS;
  568. }
  569. CallbackInfo = &Private->CallbackInfo;
  570. if (CallbackInfo->ChildHandle != NULL) {
  571. //
  572. // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
  573. //
  574. gBS->UninstallMultipleProtocolInterfaces (
  575. CallbackInfo->ChildHandle,
  576. &gEfiDevicePathProtocolGuid,
  577. CallbackInfo->HiiVendorDevicePath,
  578. &gEfiHiiConfigAccessProtocolGuid,
  579. &CallbackInfo->ConfigAccess,
  580. NULL
  581. );
  582. CallbackInfo->ChildHandle = NULL;
  583. }
  584. if (CallbackInfo->HiiVendorDevicePath != NULL) {
  585. FreePool (CallbackInfo->HiiVendorDevicePath);
  586. CallbackInfo->HiiVendorDevicePath = NULL;
  587. }
  588. if (CallbackInfo->RegisteredHandle != NULL) {
  589. //
  590. // Remove HII package list
  591. //
  592. HiiRemovePackages (CallbackInfo->RegisteredHandle);
  593. CallbackInfo->RegisteredHandle = NULL;
  594. }
  595. return EFI_SUCCESS;
  596. }