Ip6ConfigNv.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092
  1. /** @file
  2. Helper functions for configuring or obtaining the parameters relating to IP6.
  3. Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "Ip6Impl.h"
  7. CHAR16 mIp6ConfigStorageName[] = L"IP6_CONFIG_IFR_NVDATA";
  8. /**
  9. The notify function of create event when performing a manual configuration.
  10. @param[in] Event The pointer of Event.
  11. @param[in] Context The pointer of Context.
  12. **/
  13. VOID
  14. EFIAPI
  15. Ip6ConfigManualAddressNotify (
  16. IN EFI_EVENT Event,
  17. IN VOID *Context
  18. )
  19. {
  20. *((BOOLEAN *)Context) = TRUE;
  21. }
  22. /**
  23. Get the configuration data for the EFI IPv6 network stack running on the
  24. communication. It is a help function to the call EfiIp6ConfigGetData().
  25. @param[in] Ip6Config The pointer to the EFI_IP6_CONFIG_PROTOCOL instance.
  26. @param[in] DataType The type of data to get.
  27. @param[out] DataSize The size of buffer required in bytes.
  28. @param[out] Data The data buffer in which the configuration data is returned. The
  29. type of the data buffer associated with the DataType.
  30. It is the caller's responsibility to free the resource.
  31. @retval EFI_SUCCESS The specified configuration data was obtained successfully.
  32. @retval EFI_INVALID_PARAMETER One or more of the followings are TRUE:
  33. - Ip6Config is NULL or invalid.
  34. - DataSize is NULL.
  35. - Data is NULL.
  36. @retval EFI_OUT_OF_RESOURCES Fail to perform the operation due to lack of resources.
  37. @retval EFI_NOT_READY The specified configuration data is not ready due to an
  38. asynchronous configuration process already in progress.
  39. @retval EFI_NOT_FOUND The specified configuration data was not found.
  40. **/
  41. EFI_STATUS
  42. Ip6ConfigNvGetData (
  43. IN EFI_IP6_CONFIG_PROTOCOL *Ip6Config,
  44. IN EFI_IP6_CONFIG_DATA_TYPE DataType,
  45. OUT UINTN *DataSize,
  46. OUT VOID **Data
  47. )
  48. {
  49. UINTN BufferSize;
  50. VOID *Buffer;
  51. EFI_STATUS Status;
  52. if ((Ip6Config == NULL) || (Data == NULL) || (DataSize == NULL)) {
  53. return EFI_INVALID_PARAMETER;
  54. }
  55. BufferSize = 0;
  56. Status = Ip6Config->GetData (
  57. Ip6Config,
  58. DataType,
  59. &BufferSize,
  60. NULL
  61. );
  62. if (Status != EFI_BUFFER_TOO_SMALL) {
  63. return Status;
  64. }
  65. Buffer = AllocateZeroPool (BufferSize);
  66. if (Buffer == NULL) {
  67. return EFI_OUT_OF_RESOURCES;
  68. }
  69. Status = Ip6Config->GetData (
  70. Ip6Config,
  71. DataType,
  72. &BufferSize,
  73. Buffer
  74. );
  75. if (EFI_ERROR (Status)) {
  76. FreePool (Buffer);
  77. return Status;
  78. }
  79. *DataSize = BufferSize;
  80. *Data = Buffer;
  81. return EFI_SUCCESS;
  82. }
  83. /**
  84. Free all nodes in IP6_ADDRESS_INFO_ENTRY in the list array specified
  85. with ListHead.
  86. @param[in] ListHead The head of the list array in IP6_ADDRESS_INFO_ENTRY.
  87. **/
  88. VOID
  89. Ip6FreeAddressInfoList (
  90. IN LIST_ENTRY *ListHead
  91. )
  92. {
  93. IP6_ADDRESS_INFO_ENTRY *Node;
  94. LIST_ENTRY *Entry;
  95. LIST_ENTRY *NextEntry;
  96. NET_LIST_FOR_EACH_SAFE (Entry, NextEntry, ListHead) {
  97. Node = NET_LIST_USER_STRUCT (Entry, IP6_ADDRESS_INFO_ENTRY, Link);
  98. RemoveEntryList (&Node->Link);
  99. FreePool (Node);
  100. }
  101. }
  102. /**
  103. Convert the IPv6 address into a formatted string.
  104. @param[in] Ip6 The IPv6 address.
  105. @param[out] Str The formatted IP string.
  106. **/
  107. VOID
  108. Ip6ToStr (
  109. IN EFI_IPv6_ADDRESS *Ip6,
  110. OUT CHAR16 *Str
  111. )
  112. {
  113. UINTN Index;
  114. BOOLEAN Short;
  115. UINTN Number;
  116. CHAR16 FormatString[8];
  117. Short = FALSE;
  118. for (Index = 0; Index < 15; Index = Index + 2) {
  119. if (!Short &&
  120. (Index % 2 == 0) &&
  121. (Ip6->Addr[Index] == 0) &&
  122. (Ip6->Addr[Index + 1] == 0)
  123. )
  124. {
  125. //
  126. // Deal with the case of ::.
  127. //
  128. if (Index == 0) {
  129. *Str = L':';
  130. *(Str + 1) = L':';
  131. Str = Str + 2;
  132. } else {
  133. *Str = L':';
  134. Str = Str + 1;
  135. }
  136. while ((Index < 15) && (Ip6->Addr[Index] == 0) && (Ip6->Addr[Index + 1] == 0)) {
  137. Index = Index + 2;
  138. }
  139. Short = TRUE;
  140. if (Index == 16) {
  141. //
  142. // :: is at the end of the address.
  143. //
  144. *Str = L'\0';
  145. break;
  146. }
  147. }
  148. ASSERT (Index < 15);
  149. if (Ip6->Addr[Index] == 0) {
  150. Number = UnicodeSPrint (Str, 2 * IP6_STR_MAX_SIZE, L"%x:", (UINTN)Ip6->Addr[Index + 1]);
  151. } else {
  152. if (Ip6->Addr[Index + 1] < 0x10) {
  153. CopyMem (FormatString, L"%x0%x:", StrSize (L"%x0%x:"));
  154. } else {
  155. CopyMem (FormatString, L"%x%x:", StrSize (L"%x%x:"));
  156. }
  157. Number = UnicodeSPrint (
  158. Str,
  159. 2 * IP6_STR_MAX_SIZE,
  160. (CONST CHAR16 *)FormatString,
  161. (UINTN)Ip6->Addr[Index],
  162. (UINTN)Ip6->Addr[Index + 1]
  163. );
  164. }
  165. Str = Str + Number;
  166. if (Index + 2 == 16) {
  167. *Str = L'\0';
  168. if (*(Str - 1) == L':') {
  169. *(Str - 1) = L'\0';
  170. }
  171. }
  172. }
  173. }
  174. /**
  175. Convert EFI_IP6_CONFIG_INTERFACE_ID to string format.
  176. @param[out] String The buffer to store the converted string.
  177. @param[in] IfId The pointer of EFI_IP6_CONFIG_INTERFACE_ID.
  178. @retval EFI_SUCCESS The string converted successfully.
  179. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  180. **/
  181. EFI_STATUS
  182. Ip6ConvertInterfaceIdToString (
  183. OUT CHAR16 *String,
  184. IN EFI_IP6_CONFIG_INTERFACE_ID *IfId
  185. )
  186. {
  187. UINT8 Index;
  188. UINTN Number;
  189. if ((String == NULL) || (IfId == NULL)) {
  190. return EFI_INVALID_PARAMETER;
  191. }
  192. for (Index = 0; Index < 8; Index++) {
  193. Number = UnicodeSPrint (
  194. String,
  195. 2 * INTERFACE_ID_STR_STORAGE,
  196. L"%x:",
  197. (UINTN)IfId->Id[Index]
  198. );
  199. String = String + Number;
  200. }
  201. *(String - 1) = '\0';
  202. return EFI_SUCCESS;
  203. }
  204. /**
  205. Parse InterfaceId in string format and convert it to EFI_IP6_CONFIG_INTERFACE_ID.
  206. @param[in] String The buffer of the string to be parsed.
  207. @param[out] IfId The pointer of EFI_IP6_CONFIG_INTERFACE_ID.
  208. @retval EFI_SUCCESS The operation finished successfully.
  209. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  210. **/
  211. EFI_STATUS
  212. Ip6ParseInterfaceIdFromString (
  213. IN CONST CHAR16 *String,
  214. OUT EFI_IP6_CONFIG_INTERFACE_ID *IfId
  215. )
  216. {
  217. UINT8 Index;
  218. CHAR16 *IfIdStr;
  219. CHAR16 *TempStr;
  220. UINTN NodeVal;
  221. if ((String == NULL) || (IfId == NULL)) {
  222. return EFI_INVALID_PARAMETER;
  223. }
  224. IfIdStr = (CHAR16 *)String;
  225. ZeroMem (IfId, sizeof (EFI_IP6_CONFIG_INTERFACE_ID));
  226. for (Index = 0; Index < 8; Index++) {
  227. TempStr = IfIdStr;
  228. while ((*IfIdStr != L'\0') && (*IfIdStr != L':')) {
  229. IfIdStr++;
  230. }
  231. //
  232. // The InterfaceId format is X:X:X:X, the number of X should not exceed 8.
  233. // If the number of X is less than 8, zero is appended to the InterfaceId.
  234. //
  235. if ((*IfIdStr == ':') && (Index == 7)) {
  236. return EFI_INVALID_PARAMETER;
  237. }
  238. //
  239. // Convert the string to interface id. AsciiStrHexToUintn stops at the
  240. // first character that is not a valid hex character, ':' or '\0' here.
  241. //
  242. NodeVal = StrHexToUintn (TempStr);
  243. if (NodeVal > 0xFF) {
  244. return EFI_INVALID_PARAMETER;
  245. }
  246. IfId->Id[Index] = (UINT8)NodeVal;
  247. IfIdStr++;
  248. }
  249. return EFI_SUCCESS;
  250. }
  251. /**
  252. Create Hii Extend Label OpCode as the start opcode and end opcode. It is
  253. a help function.
  254. @param[in] StartLabelNumber The number of start label.
  255. @param[out] StartOpCodeHandle Points to the start opcode handle.
  256. @param[out] StartLabel Points to the created start opcode.
  257. @param[out] EndOpCodeHandle Points to the end opcode handle.
  258. @param[out] EndLabel Points to the created end opcode.
  259. @retval EFI_OUT_OF_RESOURCES Does not have sufficient resources to finish this
  260. operation.
  261. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  262. @retval EFI_SUCCESS The operation completed successfully.
  263. **/
  264. EFI_STATUS
  265. Ip6CreateOpCode (
  266. IN UINT16 StartLabelNumber,
  267. OUT VOID **StartOpCodeHandle,
  268. OUT EFI_IFR_GUID_LABEL **StartLabel,
  269. OUT VOID **EndOpCodeHandle,
  270. OUT EFI_IFR_GUID_LABEL **EndLabel
  271. )
  272. {
  273. EFI_STATUS Status;
  274. EFI_IFR_GUID_LABEL *InternalStartLabel;
  275. EFI_IFR_GUID_LABEL *InternalEndLabel;
  276. if ((StartOpCodeHandle == NULL) || (StartLabel == NULL) || (EndOpCodeHandle == NULL) || (EndLabel == NULL)) {
  277. return EFI_INVALID_PARAMETER;
  278. }
  279. *StartOpCodeHandle = NULL;
  280. *EndOpCodeHandle = NULL;
  281. Status = EFI_OUT_OF_RESOURCES;
  282. //
  283. // Initialize the container for dynamic opcodes.
  284. //
  285. *StartOpCodeHandle = HiiAllocateOpCodeHandle ();
  286. if (*StartOpCodeHandle == NULL) {
  287. return Status;
  288. }
  289. *EndOpCodeHandle = HiiAllocateOpCodeHandle ();
  290. if (*EndOpCodeHandle == NULL) {
  291. goto Exit;
  292. }
  293. //
  294. // Create Hii Extend Label OpCode as the start opcode.
  295. //
  296. InternalStartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
  297. *StartOpCodeHandle,
  298. &gEfiIfrTianoGuid,
  299. NULL,
  300. sizeof (EFI_IFR_GUID_LABEL)
  301. );
  302. if (InternalStartLabel == NULL) {
  303. goto Exit;
  304. }
  305. InternalStartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
  306. InternalStartLabel->Number = StartLabelNumber;
  307. //
  308. // Create Hii Extend Label OpCode as the end opcode.
  309. //
  310. InternalEndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
  311. *EndOpCodeHandle,
  312. &gEfiIfrTianoGuid,
  313. NULL,
  314. sizeof (EFI_IFR_GUID_LABEL)
  315. );
  316. if (InternalEndLabel == NULL) {
  317. goto Exit;
  318. }
  319. InternalEndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
  320. InternalEndLabel->Number = LABEL_END;
  321. *StartLabel = InternalStartLabel;
  322. *EndLabel = InternalEndLabel;
  323. return EFI_SUCCESS;
  324. Exit:
  325. if (*StartOpCodeHandle != NULL) {
  326. HiiFreeOpCodeHandle (*StartOpCodeHandle);
  327. }
  328. if (*EndOpCodeHandle != NULL) {
  329. HiiFreeOpCodeHandle (*EndOpCodeHandle);
  330. }
  331. return Status;
  332. }
  333. /**
  334. This function converts the different format of address list to string format and
  335. then generates the corresponding text opcode to illustrate the address info in
  336. IP6 configuration page. Currently, the following formats are supported:
  337. EFI_IP6_ADDRESS_INFO AddressType: Ip6ConfigNvHostAddress;
  338. EFI_IPv6_ADDRESS AddressType: Ip6ConfigNvGatewayAddress and Ip6ConfigNvDnsAddress;
  339. EFI_IP6_ROUTE_TABLE AddressType: Ip6ConfigNvRouteTable.
  340. @param[in, out] String The pointer to the buffer to store the converted
  341. string.
  342. @param[in] HiiHandle A handle that was previously registered in the
  343. HII Database.
  344. @param[in] AddressType The address type.
  345. @param[in] AddressInfo Pointer to the address list.
  346. @param[in] AddressCount The address count of the address list.
  347. @retval EFI_SUCCESS The operation finished successfully.
  348. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  349. @retval EFI_UNSUPPORTED The AddressType is not supported.
  350. **/
  351. EFI_STATUS
  352. Ip6ConvertAddressListToString (
  353. IN OUT CHAR16 *String,
  354. IN EFI_HII_HANDLE HiiHandle,
  355. IN IP6_CONFIG_NV_ADDRESS_TYPE AddressType,
  356. IN VOID *AddressInfo,
  357. IN UINTN AddressCount
  358. )
  359. {
  360. UINTN Index;
  361. UINTN Number;
  362. CHAR16 *TempStr;
  363. EFI_STATUS Status;
  364. VOID *StartOpCodeHandle;
  365. EFI_IFR_GUID_LABEL *StartLabel;
  366. VOID *EndOpCodeHandle;
  367. EFI_IFR_GUID_LABEL *EndLabel;
  368. UINT16 StartLabelNumber;
  369. EFI_STRING_ID TextTwo;
  370. UINT8 *AddressHead;
  371. UINT8 PrefixLength;
  372. EFI_IPv6_ADDRESS *Address;
  373. if ((String == NULL) || (HiiHandle == NULL) || (AddressInfo == NULL)) {
  374. return EFI_INVALID_PARAMETER;
  375. }
  376. if (AddressType == Ip6ConfigNvHostAddress) {
  377. StartLabelNumber = HOST_ADDRESS_LABEL;
  378. } else if (AddressType == Ip6ConfigNvGatewayAddress) {
  379. StartLabelNumber = GATEWAY_ADDRESS_LABEL;
  380. } else if (AddressType == Ip6ConfigNvDnsAddress) {
  381. StartLabelNumber = DNS_ADDRESS_LABEL;
  382. } else if (AddressType == Ip6ConfigNvRouteTable) {
  383. StartLabelNumber = ROUTE_TABLE_LABEL;
  384. } else {
  385. ASSERT (FALSE);
  386. return EFI_UNSUPPORTED;
  387. }
  388. Status = Ip6CreateOpCode (
  389. StartLabelNumber,
  390. &StartOpCodeHandle,
  391. &StartLabel,
  392. &EndOpCodeHandle,
  393. &EndLabel
  394. );
  395. if (EFI_ERROR (Status)) {
  396. return Status;
  397. }
  398. AddressHead = (UINT8 *)AddressInfo;
  399. for (Index = 0; Index < AddressCount; Index++) {
  400. if (AddressType == Ip6ConfigNvHostAddress) {
  401. AddressInfo = AddressHead + sizeof (EFI_IP6_ADDRESS_INFO) * Index;
  402. Address = &((EFI_IP6_ADDRESS_INFO *)AddressInfo)->Address;
  403. } else if (AddressType == Ip6ConfigNvRouteTable) {
  404. AddressInfo = AddressHead + sizeof (EFI_IP6_ROUTE_TABLE) * Index;
  405. Address = &((EFI_IP6_ROUTE_TABLE *)AddressInfo)->Destination;
  406. } else {
  407. AddressInfo = AddressHead + sizeof (EFI_IPv6_ADDRESS) * Index;
  408. Address = AddressInfo;
  409. }
  410. //
  411. // Convert the IP address info to string.
  412. //
  413. Ip6ToStr (Address, String);
  414. TempStr = String + StrLen (String);
  415. if ((AddressType == Ip6ConfigNvHostAddress) || (AddressType == Ip6ConfigNvRouteTable)) {
  416. if (AddressType == Ip6ConfigNvHostAddress) {
  417. PrefixLength = ((EFI_IP6_ADDRESS_INFO *)AddressInfo)->PrefixLength;
  418. } else {
  419. PrefixLength = ((EFI_IP6_ROUTE_TABLE *)AddressInfo)->PrefixLength;
  420. }
  421. //
  422. // Append the prefix length to the string.
  423. //
  424. *TempStr = L'/';
  425. TempStr++;
  426. Number = UnicodeSPrint (TempStr, 6, L"%d", PrefixLength);
  427. TempStr = TempStr + Number;
  428. }
  429. if (AddressType == Ip6ConfigNvRouteTable) {
  430. //
  431. // Append " >> " to the string.
  432. //
  433. Number = UnicodeSPrint (TempStr, 8, L" >> ");
  434. TempStr = TempStr + Number;
  435. //
  436. // Append the gateway address to the string.
  437. //
  438. Ip6ToStr (&((EFI_IP6_ROUTE_TABLE *)AddressInfo)->Gateway, TempStr);
  439. TempStr = TempStr + StrLen (TempStr);
  440. }
  441. //
  442. // Generate a text opcode and update the UI.
  443. //
  444. TextTwo = HiiSetString (HiiHandle, 0, String, NULL);
  445. if (TextTwo == 0) {
  446. Status = EFI_INVALID_PARAMETER;
  447. goto Exit;
  448. }
  449. HiiCreateTextOpCode (StartOpCodeHandle, STR_NULL, STR_NULL, TextTwo);
  450. String = TempStr;
  451. *String = IP6_ADDRESS_DELIMITER;
  452. String++;
  453. }
  454. *(String - 1) = '\0';
  455. Status = HiiUpdateForm (
  456. HiiHandle, // HII handle
  457. &gIp6ConfigNvDataGuid, // Formset GUID
  458. FORMID_MAIN_FORM, // Form ID
  459. StartOpCodeHandle, // Label for where to insert opcodes
  460. EndOpCodeHandle // Replace data
  461. );
  462. Exit:
  463. HiiFreeOpCodeHandle (StartOpCodeHandle);
  464. HiiFreeOpCodeHandle (EndOpCodeHandle);
  465. return Status;
  466. }
  467. /**
  468. Parse address list in string format and convert it to a list array of node in
  469. IP6_ADDRESS_INFO_ENTRY.
  470. @param[in] String The buffer to string to be parsed.
  471. @param[out] ListHead The list head of array.
  472. @param[out] AddressCount The number of list nodes in the array.
  473. @retval EFI_SUCCESS The operation finished successfully.
  474. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  475. @retval EFI_OUT_OF_RESOURCES Failed to perform the operation due to lack of resource.
  476. **/
  477. EFI_STATUS
  478. Ip6ParseAddressListFromString (
  479. IN CONST CHAR16 *String,
  480. OUT LIST_ENTRY *ListHead,
  481. OUT UINT32 *AddressCount
  482. )
  483. {
  484. EFI_STATUS Status;
  485. CHAR16 *LocalString;
  486. CHAR16 *Temp;
  487. CHAR16 *TempStr;
  488. EFI_IP6_ADDRESS_INFO AddressInfo;
  489. IP6_ADDRESS_INFO_ENTRY *Node;
  490. BOOLEAN Last;
  491. UINT32 Count;
  492. if ((String == NULL) || (ListHead == NULL) || (AddressCount == NULL)) {
  493. return EFI_INVALID_PARAMETER;
  494. }
  495. ZeroMem (&AddressInfo, sizeof (EFI_IP6_ADDRESS_INFO));
  496. LocalString = (CHAR16 *)AllocateCopyPool (StrSize (String), String);
  497. if (LocalString == NULL) {
  498. return EFI_OUT_OF_RESOURCES;
  499. }
  500. //
  501. // Clean the original address list.
  502. //
  503. Ip6FreeAddressInfoList (ListHead);
  504. Temp = LocalString;
  505. Last = FALSE;
  506. Count = 0;
  507. while (*LocalString != L'\0') {
  508. TempStr = LocalString;
  509. while ((*LocalString != L'\0') && (*LocalString != IP6_ADDRESS_DELIMITER)) {
  510. LocalString++;
  511. }
  512. if (*LocalString == L'\0') {
  513. Last = TRUE;
  514. }
  515. *LocalString = L'\0';
  516. Status = NetLibStrToIp6andPrefix (TempStr, &AddressInfo.Address, &AddressInfo.PrefixLength);
  517. if (EFI_ERROR (Status)) {
  518. goto Error;
  519. }
  520. if (AddressInfo.PrefixLength == 0xFF) {
  521. AddressInfo.PrefixLength = 0;
  522. }
  523. if (!NetIp6IsValidUnicast (&AddressInfo.Address)) {
  524. Status = EFI_INVALID_PARAMETER;
  525. goto Error;
  526. }
  527. Node = AllocatePool (sizeof (IP6_ADDRESS_INFO_ENTRY));
  528. if (Node == NULL) {
  529. Status = EFI_OUT_OF_RESOURCES;
  530. goto Error;
  531. }
  532. CopyMem (&Node->AddrInfo, &AddressInfo, sizeof (EFI_IP6_ADDRESS_INFO));
  533. InsertTailList (ListHead, &Node->Link);
  534. Count++;
  535. if (Last) {
  536. break;
  537. }
  538. LocalString++;
  539. }
  540. FreePool (Temp);
  541. *AddressCount = Count;
  542. return EFI_SUCCESS;
  543. Error:
  544. Ip6FreeAddressInfoList (ListHead);
  545. FreePool (Temp);
  546. return Status;
  547. }
  548. /**
  549. This function converts the interface info to string and draws it to the IP6 UI.
  550. The interface information includes interface name, interface type, hardware
  551. address and route table information.
  552. @param[in] IfInfo The pointer of EFI_IP6_CONFIG_INTERFACE_INFO.
  553. @param[in] HiiHandle The handle that was previously registered in the
  554. HII Database.
  555. @param[in, out] IfrNvData Points to IP6_CONFIG_IFR_NVDATA.
  556. @retval EFI_SUCCESS The operation finished successfully.
  557. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  558. @retval EFI_OUT_OF_RESOURCES The operation failed due to lack of resources.
  559. **/
  560. EFI_STATUS
  561. Ip6ConvertInterfaceInfoToString (
  562. IN EFI_IP6_CONFIG_INTERFACE_INFO *IfInfo,
  563. IN EFI_HII_HANDLE HiiHandle,
  564. IN OUT IP6_CONFIG_IFR_NVDATA *IfrNvData
  565. )
  566. {
  567. UINT32 Index;
  568. UINTN Number;
  569. CHAR16 *String;
  570. CHAR16 PortString[ADDRESS_STR_MAX_SIZE];
  571. CHAR16 FormatString[8];
  572. EFI_STRING_ID StringId;
  573. if ((IfInfo == NULL) || (HiiHandle == NULL) || (IfrNvData == NULL)) {
  574. return EFI_INVALID_PARAMETER;
  575. }
  576. //
  577. // Print the interface name.
  578. //
  579. StringId = HiiSetString (
  580. HiiHandle,
  581. STRING_TOKEN (STR_IP6_INTERFACE_NAME_CONTENT),
  582. IfInfo->Name,
  583. NULL
  584. );
  585. if (StringId == 0) {
  586. return EFI_OUT_OF_RESOURCES;
  587. }
  588. //
  589. // Print the interface type.
  590. //
  591. if (IfInfo->IfType == Ip6InterfaceTypeEthernet) {
  592. CopyMem (PortString, IP6_ETHERNET, sizeof (IP6_ETHERNET));
  593. } else if (IfInfo->IfType == Ip6InterfaceTypeExperimentalEthernet) {
  594. CopyMem (PortString, IP6_EXPERIMENTAL_ETHERNET, sizeof (IP6_EXPERIMENTAL_ETHERNET));
  595. } else {
  596. //
  597. // Refer to RFC1700, chapter Number Hardware Type.
  598. //
  599. UnicodeSPrint (PortString, 6, L"%d", IfInfo->IfType);
  600. }
  601. StringId = HiiSetString (
  602. HiiHandle,
  603. STRING_TOKEN (STR_IP6_INTERFACE_TYPE_CONTENT),
  604. PortString,
  605. NULL
  606. );
  607. if (StringId == 0) {
  608. return EFI_OUT_OF_RESOURCES;
  609. }
  610. //
  611. // Convert the hardware address.
  612. //
  613. String = PortString;
  614. ASSERT (IfInfo->HwAddressSize <= 32);
  615. for (Index = 0; Index < IfInfo->HwAddressSize; Index++) {
  616. if (IfInfo->HwAddress.Addr[Index] < 0x10) {
  617. CopyMem (FormatString, L"0%x-", sizeof (L"0%x-"));
  618. } else {
  619. CopyMem (FormatString, L"%x-", sizeof (L"%x-"));
  620. }
  621. Number = UnicodeSPrint (
  622. String,
  623. 8,
  624. (CONST CHAR16 *)FormatString,
  625. (UINTN)IfInfo->HwAddress.Addr[Index]
  626. );
  627. String = String + Number;
  628. }
  629. if (Index != 0) {
  630. ASSERT (String > PortString);
  631. String--;
  632. *String = '\0';
  633. }
  634. //
  635. // Print the hardware address.
  636. //
  637. StringId = HiiSetString (
  638. HiiHandle,
  639. STRING_TOKEN (STR_IP6_MAC_ADDRESS_CONTENT),
  640. PortString,
  641. NULL
  642. );
  643. if (StringId == 0) {
  644. return EFI_OUT_OF_RESOURCES;
  645. }
  646. return EFI_SUCCESS;
  647. }
  648. /**
  649. Build the address info list from list array of node in IP6_ADDRESS_INFO_ENTRY.
  650. @param[in] Instance Points to IP6 config instance data.
  651. @param[in] AddressType The address type.
  652. @param[out] AddressInfo The pointer to the buffer to store the address list.
  653. @param[out] AddressSize The address size of the address list.
  654. @retval EFI_SUCCESS The operation finished successfully.
  655. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  656. @retval EFI_UNSUPPORTED The AddressType is not supported.
  657. **/
  658. EFI_STATUS
  659. Ip6BuildNvAddressInfo (
  660. IN IP6_CONFIG_INSTANCE *Instance,
  661. IN IP6_CONFIG_NV_ADDRESS_TYPE AddressType,
  662. OUT VOID **AddressInfo,
  663. OUT UINTN *AddressSize
  664. )
  665. {
  666. IP6_CONFIG_NVDATA *Ip6NvData;
  667. LIST_ENTRY *Entry;
  668. LIST_ENTRY *ListHead;
  669. IP6_ADDRESS_INFO_ENTRY *Node;
  670. VOID *AddressList;
  671. VOID *TmpStr;
  672. UINTN DataSize;
  673. EFI_IPv6_ADDRESS *Ip6Address;
  674. EFI_IP6_CONFIG_MANUAL_ADDRESS *ManualAddress;
  675. if ((Instance == NULL) || (AddressInfo == NULL) || (AddressSize == NULL)) {
  676. return EFI_INVALID_PARAMETER;
  677. }
  678. NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);
  679. Ip6NvData = &Instance->Ip6NvData;
  680. if (AddressType == Ip6ConfigNvHostAddress) {
  681. ListHead = &Ip6NvData->ManualAddress;
  682. DataSize = sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS) * Ip6NvData->ManualAddressCount;
  683. } else if (AddressType == Ip6ConfigNvGatewayAddress) {
  684. ListHead = &Ip6NvData->GatewayAddress;
  685. DataSize = sizeof (EFI_IPv6_ADDRESS) * Ip6NvData->GatewayAddressCount;
  686. } else if (AddressType == Ip6ConfigNvDnsAddress) {
  687. ListHead = &Ip6NvData->DnsAddress;
  688. DataSize = sizeof (EFI_IPv6_ADDRESS) * Ip6NvData->DnsAddressCount;
  689. } else {
  690. return EFI_UNSUPPORTED;
  691. }
  692. AddressList = AllocateZeroPool (DataSize);
  693. if (AddressList == NULL) {
  694. return EFI_OUT_OF_RESOURCES;
  695. }
  696. TmpStr = AddressList;
  697. NET_LIST_FOR_EACH (Entry, ListHead) {
  698. Node = NET_LIST_USER_STRUCT (Entry, IP6_ADDRESS_INFO_ENTRY, Link);
  699. if (AddressType == Ip6ConfigNvHostAddress) {
  700. ManualAddress = (EFI_IP6_CONFIG_MANUAL_ADDRESS *)AddressList;
  701. IP6_COPY_ADDRESS (&ManualAddress->Address, &Node->AddrInfo.Address);
  702. ManualAddress->PrefixLength = Node->AddrInfo.PrefixLength;
  703. AddressList = (UINT8 *)AddressList + sizeof (EFI_IP6_CONFIG_MANUAL_ADDRESS);
  704. } else {
  705. Ip6Address = (EFI_IPv6_ADDRESS *)AddressList;
  706. IP6_COPY_ADDRESS (Ip6Address, &Node->AddrInfo.Address);
  707. AddressList = (UINT8 *)AddressList + sizeof (EFI_IPv6_ADDRESS);
  708. }
  709. }
  710. *AddressInfo = TmpStr;
  711. *AddressSize = DataSize;
  712. return EFI_SUCCESS;
  713. }
  714. /**
  715. Convert the IP6 configuration data into the IFR data.
  716. @param[in, out] IfrNvData The IFR NV data.
  717. @param[in] Instance The IP6 config instance data.
  718. @retval EFI_SUCCESS The operation finished successfully.
  719. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  720. @retval EFI_UNSUPPORTED The policy is not supported in the current implementation.
  721. @retval Others Other errors as indicated.
  722. **/
  723. EFI_STATUS
  724. Ip6ConvertConfigNvDataToIfrNvData (
  725. IN OUT IP6_CONFIG_IFR_NVDATA *IfrNvData,
  726. IN IP6_CONFIG_INSTANCE *Instance
  727. )
  728. {
  729. IP6_CONFIG_NVDATA *Ip6NvData;
  730. EFI_IP6_CONFIG_PROTOCOL *Ip6Config;
  731. UINTN DataSize;
  732. VOID *Data;
  733. EFI_STATUS Status;
  734. EFI_IP6_CONFIG_POLICY Policy;
  735. EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS DadXmits;
  736. EFI_HII_HANDLE HiiHandle;
  737. if ((IfrNvData == NULL) || (Instance == NULL)) {
  738. return EFI_INVALID_PARAMETER;
  739. }
  740. NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);
  741. Ip6Config = &Instance->Ip6Config;
  742. Ip6NvData = &Instance->Ip6NvData;
  743. Data = NULL;
  744. DataSize = 0;
  745. HiiHandle = Instance->CallbackInfo.RegisteredHandle;
  746. //
  747. // Get the current interface info.
  748. //
  749. Status = Ip6ConfigNvGetData (
  750. Ip6Config,
  751. Ip6ConfigDataTypeInterfaceInfo,
  752. &DataSize,
  753. (VOID **)&Data
  754. );
  755. if (EFI_ERROR (Status)) {
  756. goto Exit;
  757. }
  758. //
  759. // Convert the interface info to string and print.
  760. //
  761. Status = Ip6ConvertInterfaceInfoToString (
  762. (EFI_IP6_CONFIG_INTERFACE_INFO *)Data,
  763. HiiHandle,
  764. IfrNvData
  765. );
  766. if (EFI_ERROR (Status)) {
  767. goto Exit;
  768. }
  769. //
  770. // Get the interface id.
  771. //
  772. DataSize = sizeof (EFI_IP6_CONFIG_INTERFACE_ID);
  773. ZeroMem (&Ip6NvData->InterfaceId, DataSize);
  774. Status = Ip6Config->GetData (
  775. Ip6Config,
  776. Ip6ConfigDataTypeAltInterfaceId,
  777. &DataSize,
  778. &Ip6NvData->InterfaceId
  779. );
  780. if (EFI_ERROR (Status)) {
  781. goto Exit;
  782. }
  783. Ip6ConvertInterfaceIdToString (IfrNvData->InterfaceId, &Ip6NvData->InterfaceId);
  784. //
  785. // Get current policy.
  786. //
  787. DataSize = sizeof (EFI_IP6_CONFIG_POLICY);
  788. Status = Ip6Config->GetData (
  789. Ip6Config,
  790. Ip6ConfigDataTypePolicy,
  791. &DataSize,
  792. &Policy
  793. );
  794. if (EFI_ERROR (Status)) {
  795. goto Exit;
  796. }
  797. if (Policy == Ip6ConfigPolicyManual) {
  798. IfrNvData->Policy = IP6_POLICY_MANUAL;
  799. } else if (Policy == Ip6ConfigPolicyAutomatic) {
  800. IfrNvData->Policy = IP6_POLICY_AUTO;
  801. } else {
  802. ASSERT (FALSE);
  803. Status = EFI_UNSUPPORTED;
  804. goto Exit;
  805. }
  806. //
  807. // Get Duplicate Address Detection Transmits count.
  808. //
  809. DataSize = sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS);
  810. Status = Ip6Config->GetData (
  811. Ip6Config,
  812. Ip6ConfigDataTypeDupAddrDetectTransmits,
  813. &DataSize,
  814. &DadXmits
  815. );
  816. if (EFI_ERROR (Status)) {
  817. goto Exit;
  818. }
  819. IfrNvData->DadTransmitCount = DadXmits.DupAddrDetectTransmits;
  820. Exit:
  821. if (Data != NULL) {
  822. FreePool (Data);
  823. }
  824. return Status;
  825. }
  826. /**
  827. Convert IFR data into IP6 configuration data. The policy, alternative interface
  828. ID, and DAD transmit counts, and will be saved.
  829. @param[in] IfrNvData The IFR NV data.
  830. @param[in, out] Instance The IP6 config instance data.
  831. @retval EFI_SUCCESS The operation finished successfully.
  832. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  833. @retval Others Other errors as indicated.
  834. **/
  835. EFI_STATUS
  836. Ip6ConvertIfrNvDataToConfigNvDataGeneral (
  837. IN IP6_CONFIG_IFR_NVDATA *IfrNvData,
  838. IN OUT IP6_CONFIG_INSTANCE *Instance
  839. )
  840. {
  841. IP6_CONFIG_NVDATA *Ip6NvData;
  842. EFI_IP6_CONFIG_PROTOCOL *Ip6Config;
  843. EFI_STATUS Status;
  844. if ((IfrNvData == NULL) || (Instance == NULL)) {
  845. return EFI_INVALID_PARAMETER;
  846. }
  847. NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);
  848. Ip6NvData = &Instance->Ip6NvData;
  849. Ip6Config = &Instance->Ip6Config;
  850. //
  851. // Update those fields which don't have INTERACTIVE attribute.
  852. //
  853. if (IfrNvData->Policy == IP6_POLICY_AUTO) {
  854. Ip6NvData->Policy = Ip6ConfigPolicyAutomatic;
  855. } else if (IfrNvData->Policy == IP6_POLICY_MANUAL) {
  856. Ip6NvData->Policy = Ip6ConfigPolicyManual;
  857. }
  858. Ip6NvData->DadTransmitCount.DupAddrDetectTransmits = IfrNvData->DadTransmitCount;
  859. //
  860. // Set the configured policy.
  861. //
  862. Status = Ip6Config->SetData (
  863. Ip6Config,
  864. Ip6ConfigDataTypePolicy,
  865. sizeof (EFI_IP6_CONFIG_POLICY),
  866. &Ip6NvData->Policy
  867. );
  868. if (EFI_ERROR (Status)) {
  869. return Status;
  870. }
  871. //
  872. // Set the duplicate address detection transmits count.
  873. //
  874. Status = Ip6Config->SetData (
  875. Ip6Config,
  876. Ip6ConfigDataTypeDupAddrDetectTransmits,
  877. sizeof (EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS),
  878. &Ip6NvData->DadTransmitCount
  879. );
  880. if (EFI_ERROR (Status)) {
  881. return Status;
  882. }
  883. //
  884. // Set the alternative interface ID
  885. //
  886. Status = Ip6Config->SetData (
  887. Ip6Config,
  888. Ip6ConfigDataTypeAltInterfaceId,
  889. sizeof (EFI_IP6_CONFIG_INTERFACE_ID),
  890. &Ip6NvData->InterfaceId
  891. );
  892. if (EFI_ERROR (Status)) {
  893. return Status;
  894. }
  895. return EFI_SUCCESS;
  896. }
  897. /**
  898. Convert IFR data into IP6 configuration data. The policy, configured
  899. manual address, gateway address, and DNS server address will be saved.
  900. @param[in] IfrNvData The IFR NV data.
  901. @param[in, out] Instance The IP6 config instance data.
  902. @retval EFI_SUCCESS The operation finished successfully.
  903. @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
  904. @retval Others Other errors as indicated.
  905. **/
  906. EFI_STATUS
  907. Ip6ConvertIfrNvDataToConfigNvDataAdvanced (
  908. IN IP6_CONFIG_IFR_NVDATA *IfrNvData,
  909. IN OUT IP6_CONFIG_INSTANCE *Instance
  910. )
  911. {
  912. IP6_CONFIG_NVDATA *Ip6NvData;
  913. EFI_IP6_CONFIG_PROTOCOL *Ip6Config;
  914. EFI_STATUS Status;
  915. EFI_IP6_CONFIG_MANUAL_ADDRESS *ManualAddress;
  916. EFI_IPv6_ADDRESS *Address;
  917. BOOLEAN IsAddressOk;
  918. EFI_EVENT SetAddressEvent;
  919. EFI_EVENT TimeoutEvent;
  920. UINTN DataSize;
  921. if ((IfrNvData == NULL) || (Instance == NULL)) {
  922. return EFI_INVALID_PARAMETER;
  923. }
  924. if (IfrNvData->Policy == IP6_POLICY_AUTO) {
  925. return EFI_SUCCESS;
  926. }
  927. NET_CHECK_SIGNATURE (Instance, IP6_CONFIG_INSTANCE_SIGNATURE);
  928. Ip6NvData = &Instance->Ip6NvData;
  929. Ip6Config = &Instance->Ip6Config;
  930. //
  931. // Update those fields which don't have INTERACTIVE attribute.
  932. //
  933. Ip6NvData->Policy = Ip6ConfigPolicyManual;
  934. //
  935. // Set the configured policy.
  936. //
  937. Status = Ip6Config->SetData (
  938. Ip6Config,
  939. Ip6ConfigDataTypePolicy,
  940. sizeof (EFI_IP6_CONFIG_POLICY),
  941. &Ip6NvData->Policy
  942. );
  943. if (EFI_ERROR (Status)) {
  944. return Status;
  945. }
  946. //
  947. // Create events & timers for asynchronous settings.
  948. //
  949. SetAddressEvent = NULL;
  950. TimeoutEvent = NULL;
  951. ManualAddress = NULL;
  952. Address = NULL;
  953. Status = gBS->CreateEvent (
  954. EVT_NOTIFY_SIGNAL,
  955. TPL_NOTIFY,
  956. Ip6ConfigManualAddressNotify,
  957. &IsAddressOk,
  958. &SetAddressEvent
  959. );
  960. if (EFI_ERROR (Status)) {
  961. goto Exit;
  962. }
  963. Status = gBS->CreateEvent (
  964. EVT_TIMER,
  965. TPL_CALLBACK,
  966. NULL,
  967. NULL,
  968. &TimeoutEvent
  969. );
  970. if (EFI_ERROR (Status)) {
  971. goto Exit;
  972. }
  973. //
  974. // Set the manual address list. This is an asynchronous process.
  975. //
  976. if (!IsListEmpty (&Ip6NvData->ManualAddress) && (Ip6NvData->ManualAddressCount != 0)) {
  977. Status = Ip6BuildNvAddressInfo (
  978. Instance,
  979. Ip6ConfigNvHostAddress,
  980. (VOID **)&ManualAddress,
  981. &DataSize
  982. );
  983. if (EFI_ERROR (Status)) {
  984. goto Exit;
  985. }
  986. IsAddressOk = FALSE;
  987. Status = Ip6Config->RegisterDataNotify (
  988. Ip6Config,
  989. Ip6ConfigDataTypeManualAddress,
  990. SetAddressEvent
  991. );
  992. if (EFI_ERROR (Status)) {
  993. goto Exit;
  994. }
  995. Status = Ip6Config->SetData (
  996. Ip6Config,
  997. Ip6ConfigDataTypeManualAddress,
  998. DataSize,
  999. (VOID *)ManualAddress
  1000. );
  1001. if (Status == EFI_NOT_READY) {
  1002. gBS->SetTimer (TimeoutEvent, TimerRelative, 50000000);
  1003. while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))) {
  1004. if (IsAddressOk) {
  1005. Status = EFI_SUCCESS;
  1006. }
  1007. break;
  1008. }
  1009. }
  1010. Status = Ip6Config->UnregisterDataNotify (
  1011. Ip6Config,
  1012. Ip6ConfigDataTypeManualAddress,
  1013. SetAddressEvent
  1014. );
  1015. if (EFI_ERROR (Status)) {
  1016. goto Exit;
  1017. }
  1018. }
  1019. //
  1020. // Set gateway address list.
  1021. //
  1022. if (!IsListEmpty (&Ip6NvData->GatewayAddress) && (Ip6NvData->GatewayAddressCount != 0)) {
  1023. Status = Ip6BuildNvAddressInfo (
  1024. Instance,
  1025. Ip6ConfigNvGatewayAddress,
  1026. (VOID **)&Address,
  1027. &DataSize
  1028. );
  1029. if (EFI_ERROR (Status)) {
  1030. goto Exit;
  1031. }
  1032. Status = Ip6Config->SetData (
  1033. Ip6Config,
  1034. Ip6ConfigDataTypeGateway,
  1035. DataSize,
  1036. (VOID *)Address
  1037. );
  1038. if (EFI_ERROR (Status)) {
  1039. goto Exit;
  1040. }
  1041. FreePool (Address);
  1042. Address = NULL;
  1043. }
  1044. //
  1045. // Set DNS server address list.
  1046. //
  1047. if (!IsListEmpty (&Ip6NvData->DnsAddress) && (Ip6NvData->DnsAddressCount != 0)) {
  1048. Status = Ip6BuildNvAddressInfo (
  1049. Instance,
  1050. Ip6ConfigNvDnsAddress,
  1051. (VOID **)&Address,
  1052. &DataSize
  1053. );
  1054. if (EFI_ERROR (Status)) {
  1055. goto Exit;
  1056. }
  1057. Status = Ip6Config->SetData (
  1058. Ip6Config,
  1059. Ip6ConfigDataTypeDnsServer,
  1060. DataSize,
  1061. (VOID *)Address
  1062. );
  1063. if (EFI_ERROR (Status)) {
  1064. goto Exit;
  1065. }
  1066. }
  1067. Status = EFI_SUCCESS;
  1068. Exit:
  1069. if (SetAddressEvent != NULL) {
  1070. gBS->CloseEvent (SetAddressEvent);
  1071. }
  1072. if (TimeoutEvent != NULL) {
  1073. gBS->CloseEvent (TimeoutEvent);
  1074. }
  1075. if (ManualAddress != NULL) {
  1076. FreePool (ManualAddress);
  1077. }
  1078. if (Address != NULL) {
  1079. FreePool (Address);
  1080. }
  1081. return Status;
  1082. }
  1083. /**
  1084. This function allows the caller to request the current
  1085. configuration for one or more named elements. The resulting
  1086. string is in <ConfigAltResp> format. Any and all alternative
  1087. configuration strings shall also be appended to the end of the
  1088. current configuration string. If they are, they must appear
  1089. after the current configuration. They must contain the same
  1090. routing (GUID, NAME, PATH) as the current configuration string.
  1091. They must have an additional description indicating the type of
  1092. alternative configuration the string represents,
  1093. "ALTCFG=<StringToken>". That <StringToken> (when
  1094. converted from Hex UNICODE to binary) is a reference to a
  1095. string in the associated string pack.
  1096. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  1097. @param[in] Request A null-terminated Unicode string in
  1098. <ConfigRequest> format. Note that this
  1099. includes the routing information as well as
  1100. the configurable name / value pairs. It is
  1101. invalid for this string to be in
  1102. <MultiConfigRequest> format.
  1103. @param[out] Progress On return, points to a character in the
  1104. Request string. Points to the string's null
  1105. terminator if request was successful. Points
  1106. to the most recent "&" before the first
  1107. failing name / value pair (or the beginning
  1108. of the string if the failure is in the first
  1109. name / value pair) if the request was not
  1110. successful.
  1111. @param[out] Results A null-terminated Unicode string in
  1112. <ConfigAltResp> format which has all values
  1113. filled in for the names in the Request string.
  1114. String to be allocated by the called function.
  1115. @retval EFI_SUCCESS The Results string is filled with the
  1116. values corresponding to all requested
  1117. names.
  1118. @retval EFI_OUT_OF_RESOURCES Not enough memory to store the
  1119. parts of the results that must be
  1120. stored awaiting possible future
  1121. protocols.
  1122. @retval EFI_INVALID_PARAMETER For example, passing in a NULL
  1123. for the Request parameter
  1124. would result in this type of
  1125. error. In this case, the
  1126. Progress parameter would be
  1127. set to NULL.
  1128. @retval EFI_NOT_FOUND Routing data doesn't match any
  1129. known driver. Progress set to the
  1130. first character in the routing header.
  1131. Note: There is no requirement that the
  1132. driver validate the routing data. It
  1133. must skip the <ConfigHdr> in order to
  1134. process the names.
  1135. @retval EFI_INVALID_PARAMETER Illegal syntax. Progress set
  1136. to most recent & before the
  1137. error or the beginning of the
  1138. string.
  1139. @retval EFI_INVALID_PARAMETER Unknown name. Progress points
  1140. to the & before the name in
  1141. question. Currently not implemented.
  1142. **/
  1143. EFI_STATUS
  1144. EFIAPI
  1145. Ip6FormExtractConfig (
  1146. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  1147. IN CONST EFI_STRING Request,
  1148. OUT EFI_STRING *Progress,
  1149. OUT EFI_STRING *Results
  1150. )
  1151. {
  1152. EFI_STATUS Status;
  1153. IP6_FORM_CALLBACK_INFO *Private;
  1154. IP6_CONFIG_INSTANCE *Ip6ConfigInstance;
  1155. IP6_CONFIG_IFR_NVDATA *IfrNvData;
  1156. EFI_STRING ConfigRequestHdr;
  1157. EFI_STRING ConfigRequest;
  1158. BOOLEAN AllocatedRequest;
  1159. UINTN Size;
  1160. UINTN BufferSize;
  1161. if ((This == NULL) || (Progress == NULL) || (Results == NULL)) {
  1162. return EFI_INVALID_PARAMETER;
  1163. }
  1164. *Progress = Request;
  1165. if ((Request != NULL) &&
  1166. !HiiIsConfigHdrMatch (Request, &gIp6ConfigNvDataGuid, mIp6ConfigStorageName))
  1167. {
  1168. return EFI_NOT_FOUND;
  1169. }
  1170. ConfigRequestHdr = NULL;
  1171. ConfigRequest = NULL;
  1172. AllocatedRequest = FALSE;
  1173. Size = 0;
  1174. Private = IP6_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);
  1175. Ip6ConfigInstance = IP6_CONFIG_INSTANCE_FROM_FORM_CALLBACK (Private);
  1176. BufferSize = sizeof (IP6_CONFIG_IFR_NVDATA);
  1177. IfrNvData = (IP6_CONFIG_IFR_NVDATA *)AllocateZeroPool (BufferSize);
  1178. if (IfrNvData == NULL) {
  1179. return EFI_OUT_OF_RESOURCES;
  1180. }
  1181. Status = Ip6ConvertConfigNvDataToIfrNvData (IfrNvData, Ip6ConfigInstance);
  1182. if (EFI_ERROR (Status)) {
  1183. goto Exit;
  1184. }
  1185. ConfigRequest = Request;
  1186. if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
  1187. //
  1188. // Request has no request element, construct full request string.
  1189. // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
  1190. // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator.
  1191. //
  1192. ConfigRequestHdr = HiiConstructConfigHdr (
  1193. &gIp6ConfigNvDataGuid,
  1194. mIp6ConfigStorageName,
  1195. Private->ChildHandle
  1196. );
  1197. Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);
  1198. ConfigRequest = AllocateZeroPool (Size);
  1199. ASSERT (ConfigRequest != NULL);
  1200. AllocatedRequest = TRUE;
  1201. UnicodeSPrint (
  1202. ConfigRequest,
  1203. Size,
  1204. L"%s&OFFSET=0&WIDTH=%016LX",
  1205. ConfigRequestHdr,
  1206. (UINT64)BufferSize
  1207. );
  1208. FreePool (ConfigRequestHdr);
  1209. }
  1210. //
  1211. // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
  1212. //
  1213. Status = gHiiConfigRouting->BlockToConfig (
  1214. gHiiConfigRouting,
  1215. ConfigRequest,
  1216. (UINT8 *)IfrNvData,
  1217. BufferSize,
  1218. Results,
  1219. Progress
  1220. );
  1221. Exit:
  1222. FreePool (IfrNvData);
  1223. //
  1224. // Free the allocated config request string.
  1225. //
  1226. if (AllocatedRequest) {
  1227. FreePool (ConfigRequest);
  1228. ConfigRequest = NULL;
  1229. }
  1230. //
  1231. // Set Progress string to the original request string.
  1232. //
  1233. if (Request == NULL) {
  1234. *Progress = NULL;
  1235. } else if (StrStr (Request, L"OFFSET") == NULL) {
  1236. *Progress = Request + StrLen (Request);
  1237. }
  1238. return Status;
  1239. }
  1240. /**
  1241. This function applies changes in a driver's configuration.
  1242. Input is a Configuration, which has the routing data for this
  1243. driver followed by name / value configuration pairs. The driver
  1244. must apply those pairs to its configurable storage. If the
  1245. driver's configuration is stored in a linear block of data
  1246. and the driver's name / value pairs are in <BlockConfig>
  1247. format, it may use the ConfigToBlock helper function (above) to
  1248. simplify the job. Currently not implemented.
  1249. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  1250. @param[in] Configuration A null-terminated Unicode string in
  1251. <ConfigString> format.
  1252. @param[out] Progress A pointer to a string filled in with the
  1253. offset of the most recent '&' before the
  1254. first failing name / value pair (or the
  1255. beginning of the string if the failure
  1256. is in the first name / value pair) or
  1257. the terminating NULL if all was
  1258. successful.
  1259. @retval EFI_SUCCESS The results have been distributed or are
  1260. awaiting distribution.
  1261. @retval EFI_OUT_OF_MEMORY Not enough memory to store the
  1262. parts of the results that must be
  1263. stored awaiting possible future
  1264. protocols.
  1265. @retval EFI_INVALID_PARAMETERS Passing in a NULL for the
  1266. Results parameter would result
  1267. in this type of error.
  1268. @retval EFI_NOT_FOUND Target for the specified routing data
  1269. was not found.
  1270. **/
  1271. EFI_STATUS
  1272. EFIAPI
  1273. Ip6FormRouteConfig (
  1274. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  1275. IN CONST EFI_STRING Configuration,
  1276. OUT EFI_STRING *Progress
  1277. )
  1278. {
  1279. if ((This == NULL) || (Configuration == NULL) || (Progress == NULL)) {
  1280. return EFI_INVALID_PARAMETER;
  1281. }
  1282. //
  1283. // Check routing data in <ConfigHdr>.
  1284. // Note: if only one Storage is used, then this checking could be skipped.
  1285. //
  1286. if (!HiiIsConfigHdrMatch (Configuration, &gIp6ConfigNvDataGuid, mIp6ConfigStorageName)) {
  1287. *Progress = Configuration;
  1288. return EFI_NOT_FOUND;
  1289. }
  1290. *Progress = Configuration + StrLen (Configuration);
  1291. return EFI_SUCCESS;
  1292. }
  1293. /**
  1294. Display host addresses, route table, DNS addresses and gateway addresses in
  1295. "IPv6 Current Setting" page.
  1296. @param[in] Instance The IP6 config instance data.
  1297. @retval EFI_SUCCESS The operation finished successfully.
  1298. @retval Others Other errors as indicated.
  1299. **/
  1300. EFI_STATUS
  1301. Ip6GetCurrentSetting (
  1302. IN IP6_CONFIG_INSTANCE *Instance
  1303. )
  1304. {
  1305. EFI_IP6_CONFIG_PROTOCOL *Ip6Config;
  1306. EFI_HII_HANDLE HiiHandle;
  1307. EFI_IP6_CONFIG_INTERFACE_INFO *Data;
  1308. UINTN DataSize;
  1309. EFI_STATUS Status;
  1310. CHAR16 PortString[ADDRESS_STR_MAX_SIZE];
  1311. EFI_IP6_CONFIG_INTERFACE_INFO *IfInfo;
  1312. Ip6Config = &Instance->Ip6Config;
  1313. HiiHandle = Instance->CallbackInfo.RegisteredHandle;
  1314. Data = NULL;
  1315. //
  1316. // Get current interface info.
  1317. //
  1318. Status = Ip6ConfigNvGetData (
  1319. Ip6Config,
  1320. Ip6ConfigDataTypeInterfaceInfo,
  1321. &DataSize,
  1322. (VOID **)&Data
  1323. );
  1324. if (EFI_ERROR (Status)) {
  1325. return Status;
  1326. }
  1327. //
  1328. // Generate dynamic text opcode for host address and draw it.
  1329. //
  1330. IfInfo = (EFI_IP6_CONFIG_INTERFACE_INFO *)Data;
  1331. Status = Ip6ConvertAddressListToString (
  1332. PortString,
  1333. HiiHandle,
  1334. Ip6ConfigNvHostAddress,
  1335. IfInfo->AddressInfo,
  1336. IfInfo->AddressInfoCount
  1337. );
  1338. if (EFI_ERROR (Status)) {
  1339. FreePool (Data);
  1340. return Status;
  1341. }
  1342. //
  1343. // Generate the dynamic text opcode for route table and draw it.
  1344. //
  1345. Status = Ip6ConvertAddressListToString (
  1346. PortString,
  1347. HiiHandle,
  1348. Ip6ConfigNvRouteTable,
  1349. IfInfo->RouteTable,
  1350. IfInfo->RouteCount
  1351. );
  1352. if (EFI_ERROR (Status)) {
  1353. FreePool (Data);
  1354. return Status;
  1355. }
  1356. //
  1357. // Get DNS server list.
  1358. //
  1359. FreePool (Data);
  1360. DataSize = 0;
  1361. Data = NULL;
  1362. Status = Ip6ConfigNvGetData (
  1363. Ip6Config,
  1364. Ip6ConfigDataTypeDnsServer,
  1365. &DataSize,
  1366. (VOID **)&Data
  1367. );
  1368. if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
  1369. if (Data != NULL) {
  1370. FreePool (Data);
  1371. }
  1372. return Status;
  1373. }
  1374. if (DataSize > 0) {
  1375. //
  1376. // Generate the dynamic text opcode for DNS server and draw it.
  1377. //
  1378. Status = Ip6ConvertAddressListToString (
  1379. PortString,
  1380. HiiHandle,
  1381. Ip6ConfigNvDnsAddress,
  1382. Data,
  1383. DataSize / sizeof (EFI_IPv6_ADDRESS)
  1384. );
  1385. if (EFI_ERROR (Status)) {
  1386. FreePool (Data);
  1387. return Status;
  1388. }
  1389. }
  1390. //
  1391. // Get gateway address list.
  1392. //
  1393. if (Data != NULL) {
  1394. FreePool (Data);
  1395. }
  1396. DataSize = 0;
  1397. Data = NULL;
  1398. Status = Ip6ConfigNvGetData (
  1399. Ip6Config,
  1400. Ip6ConfigDataTypeGateway,
  1401. &DataSize,
  1402. (VOID **)&Data
  1403. );
  1404. if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
  1405. if (Data != NULL) {
  1406. FreePool (Data);
  1407. }
  1408. return Status;
  1409. }
  1410. if (DataSize > 0) {
  1411. //
  1412. // Generate the dynamic text opcode for gateway and draw it.
  1413. //
  1414. Status = Ip6ConvertAddressListToString (
  1415. PortString,
  1416. HiiHandle,
  1417. Ip6ConfigNvGatewayAddress,
  1418. Data,
  1419. DataSize / sizeof (EFI_IPv6_ADDRESS)
  1420. );
  1421. if (EFI_ERROR (Status)) {
  1422. FreePool (Data);
  1423. return Status;
  1424. }
  1425. }
  1426. if (Data != NULL) {
  1427. FreePool (Data);
  1428. }
  1429. return EFI_SUCCESS;
  1430. }
  1431. /**
  1432. This function is called to provide results data to the driver.
  1433. This data consists of a unique key that is used to identify
  1434. which data is either being passed back or being asked for.
  1435. @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
  1436. @param[in] Action Specifies the type of action taken by the browser.
  1437. @param[in] QuestionId A unique value which is sent to the original
  1438. exporting driver so that it can identify the type
  1439. of data to expect. The format of the data tends to
  1440. vary based on the opcode that generated the callback.
  1441. @param[in] Type The type of value for the question.
  1442. @param[in] Value A pointer to the data being sent to the original
  1443. exporting driver.
  1444. @param[out] ActionRequest On return, points to the action requested by the
  1445. callback function.
  1446. @retval EFI_SUCCESS The callback successfully handled the action.
  1447. @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
  1448. variable and its data.
  1449. @retval EFI_DEVICE_ERROR The variable could not be saved.
  1450. @retval EFI_UNSUPPORTED The specified Action is not supported by the
  1451. callback. Currently not implemented.
  1452. @retval EFI_INVALID_PARAMETER Passed in the wrong parameter.
  1453. @retval Others Other errors as indicated.
  1454. **/
  1455. EFI_STATUS
  1456. EFIAPI
  1457. Ip6FormCallback (
  1458. IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
  1459. IN EFI_BROWSER_ACTION Action,
  1460. IN EFI_QUESTION_ID QuestionId,
  1461. IN UINT8 Type,
  1462. IN EFI_IFR_TYPE_VALUE *Value,
  1463. OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
  1464. )
  1465. {
  1466. IP6_FORM_CALLBACK_INFO *Private;
  1467. UINTN BufferSize;
  1468. IP6_CONFIG_IFR_NVDATA *IfrNvData;
  1469. EFI_STATUS Status;
  1470. EFI_INPUT_KEY Key;
  1471. IP6_CONFIG_INSTANCE *Instance;
  1472. IP6_CONFIG_NVDATA *Ip6NvData;
  1473. if (This == NULL) {
  1474. return EFI_INVALID_PARAMETER;
  1475. }
  1476. Private = IP6_FORM_CALLBACK_INFO_FROM_CONFIG_ACCESS (This);
  1477. Instance = IP6_CONFIG_INSTANCE_FROM_FORM_CALLBACK (Private);
  1478. Ip6NvData = &Instance->Ip6NvData;
  1479. if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {
  1480. return EFI_SUCCESS;
  1481. }
  1482. if ((Action != EFI_BROWSER_ACTION_CHANGING) && (Action != EFI_BROWSER_ACTION_CHANGED)) {
  1483. return EFI_UNSUPPORTED;
  1484. }
  1485. if ((Value == NULL) || (ActionRequest == NULL)) {
  1486. return EFI_INVALID_PARAMETER;
  1487. }
  1488. //
  1489. // Retrieve uncommitted data from Browser
  1490. //
  1491. BufferSize = sizeof (IP6_CONFIG_IFR_NVDATA);
  1492. IfrNvData = AllocateZeroPool (BufferSize);
  1493. if (IfrNvData == NULL) {
  1494. return EFI_OUT_OF_RESOURCES;
  1495. }
  1496. Status = EFI_SUCCESS;
  1497. HiiGetBrowserData (NULL, NULL, BufferSize, (UINT8 *)IfrNvData);
  1498. if (Action == EFI_BROWSER_ACTION_CHANGING) {
  1499. switch (QuestionId) {
  1500. case KEY_GET_CURRENT_SETTING:
  1501. Status = Ip6GetCurrentSetting (Instance);
  1502. break;
  1503. default:
  1504. break;
  1505. }
  1506. } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
  1507. switch (QuestionId) {
  1508. case KEY_SAVE_CONFIG_CHANGES:
  1509. Status = Ip6ConvertIfrNvDataToConfigNvDataAdvanced (IfrNvData, Instance);
  1510. if (EFI_ERROR (Status)) {
  1511. break;
  1512. }
  1513. Status = Ip6GetCurrentSetting (Instance);
  1514. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT;
  1515. break;
  1516. case KEY_IGNORE_CONFIG_CHANGES:
  1517. Ip6FreeAddressInfoList (&Ip6NvData->ManualAddress);
  1518. Ip6FreeAddressInfoList (&Ip6NvData->GatewayAddress);
  1519. Ip6FreeAddressInfoList (&Ip6NvData->DnsAddress);
  1520. Ip6NvData->ManualAddressCount = 0;
  1521. Ip6NvData->GatewayAddressCount = 0;
  1522. Ip6NvData->DnsAddressCount = 0;
  1523. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
  1524. break;
  1525. case KEY_SAVE_CHANGES:
  1526. Status = Ip6ConvertIfrNvDataToConfigNvDataGeneral (IfrNvData, Instance);
  1527. if (EFI_ERROR (Status)) {
  1528. break;
  1529. }
  1530. *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
  1531. break;
  1532. case KEY_INTERFACE_ID:
  1533. Status = Ip6ParseInterfaceIdFromString (IfrNvData->InterfaceId, &Ip6NvData->InterfaceId);
  1534. if (EFI_ERROR (Status)) {
  1535. CreatePopUp (
  1536. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1537. &Key,
  1538. L"Invalid Interface ID!",
  1539. NULL
  1540. );
  1541. }
  1542. break;
  1543. case KEY_MANUAL_ADDRESS:
  1544. Status = Ip6ParseAddressListFromString (
  1545. IfrNvData->ManualAddress,
  1546. &Ip6NvData->ManualAddress,
  1547. &Ip6NvData->ManualAddressCount
  1548. );
  1549. if (EFI_ERROR (Status)) {
  1550. CreatePopUp (
  1551. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1552. &Key,
  1553. L"Invalid Host Addresses!",
  1554. NULL
  1555. );
  1556. }
  1557. break;
  1558. case KEY_GATEWAY_ADDRESS:
  1559. Status = Ip6ParseAddressListFromString (
  1560. IfrNvData->GatewayAddress,
  1561. &Ip6NvData->GatewayAddress,
  1562. &Ip6NvData->GatewayAddressCount
  1563. );
  1564. if (EFI_ERROR (Status)) {
  1565. CreatePopUp (
  1566. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1567. &Key,
  1568. L"Invalid Gateway Addresses!",
  1569. NULL
  1570. );
  1571. }
  1572. break;
  1573. case KEY_DNS_ADDRESS:
  1574. Status = Ip6ParseAddressListFromString (
  1575. IfrNvData->DnsAddress,
  1576. &Ip6NvData->DnsAddress,
  1577. &Ip6NvData->DnsAddressCount
  1578. );
  1579. if (EFI_ERROR (Status)) {
  1580. CreatePopUp (
  1581. EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
  1582. &Key,
  1583. L"Invalid DNS Addresses!",
  1584. NULL
  1585. );
  1586. }
  1587. break;
  1588. default:
  1589. break;
  1590. }
  1591. }
  1592. if (!EFI_ERROR (Status)) {
  1593. //
  1594. // Pass changed uncommitted data back to Form Browser.
  1595. //
  1596. BufferSize = sizeof (IP6_CONFIG_IFR_NVDATA);
  1597. HiiSetBrowserData (NULL, NULL, BufferSize, (UINT8 *)IfrNvData, NULL);
  1598. }
  1599. FreePool (IfrNvData);
  1600. return Status;
  1601. }
  1602. /**
  1603. Install HII Config Access protocol for network device and allocate resources.
  1604. @param[in, out] Instance The IP6_CONFIG_INSTANCE to create a form.
  1605. @retval EFI_SUCCESS The HII Config Access protocol is installed.
  1606. @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
  1607. @retval Others Other errors as indicated.
  1608. **/
  1609. EFI_STATUS
  1610. Ip6ConfigFormInit (
  1611. IN OUT IP6_CONFIG_INSTANCE *Instance
  1612. )
  1613. {
  1614. EFI_STATUS Status;
  1615. IP6_SERVICE *IpSb;
  1616. IP6_FORM_CALLBACK_INFO *CallbackInfo;
  1617. EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
  1618. VENDOR_DEVICE_PATH VendorDeviceNode;
  1619. EFI_SERVICE_BINDING_PROTOCOL *MnpSb;
  1620. CHAR16 *MacString;
  1621. CHAR16 MenuString[128];
  1622. CHAR16 PortString[128];
  1623. CHAR16 *OldMenuString;
  1624. EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
  1625. IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
  1626. ASSERT (IpSb != NULL);
  1627. Status = gBS->HandleProtocol (
  1628. IpSb->Controller,
  1629. &gEfiDevicePathProtocolGuid,
  1630. (VOID **)&ParentDevicePath
  1631. );
  1632. if (EFI_ERROR (Status)) {
  1633. return Status;
  1634. }
  1635. CallbackInfo = &Instance->CallbackInfo;
  1636. CallbackInfo->Signature = IP6_FORM_CALLBACK_INFO_SIGNATURE;
  1637. //
  1638. // Construct device path node for EFI HII Config Access protocol,
  1639. // which consists of controller physical device path and one hardware
  1640. // vendor guid node.
  1641. //
  1642. ZeroMem (&VendorDeviceNode, sizeof (VENDOR_DEVICE_PATH));
  1643. VendorDeviceNode.Header.Type = HARDWARE_DEVICE_PATH;
  1644. VendorDeviceNode.Header.SubType = HW_VENDOR_DP;
  1645. CopyGuid (&VendorDeviceNode.Guid, &gEfiCallerIdGuid);
  1646. SetDevicePathNodeLength (&VendorDeviceNode.Header, sizeof (VENDOR_DEVICE_PATH));
  1647. CallbackInfo->HiiVendorDevicePath = AppendDevicePathNode (
  1648. ParentDevicePath,
  1649. (EFI_DEVICE_PATH_PROTOCOL *)&VendorDeviceNode
  1650. );
  1651. if (CallbackInfo->HiiVendorDevicePath == NULL) {
  1652. Status = EFI_OUT_OF_RESOURCES;
  1653. goto Error;
  1654. }
  1655. ConfigAccess = &CallbackInfo->HiiConfigAccess;
  1656. ConfigAccess->ExtractConfig = Ip6FormExtractConfig;
  1657. ConfigAccess->RouteConfig = Ip6FormRouteConfig;
  1658. ConfigAccess->Callback = Ip6FormCallback;
  1659. //
  1660. // Install Device Path Protocol and Config Access protocol on new handle
  1661. //
  1662. Status = gBS->InstallMultipleProtocolInterfaces (
  1663. &CallbackInfo->ChildHandle,
  1664. &gEfiDevicePathProtocolGuid,
  1665. CallbackInfo->HiiVendorDevicePath,
  1666. &gEfiHiiConfigAccessProtocolGuid,
  1667. ConfigAccess,
  1668. NULL
  1669. );
  1670. if (!EFI_ERROR (Status)) {
  1671. //
  1672. // Open the Parent Handle for the child
  1673. //
  1674. Status = gBS->OpenProtocol (
  1675. IpSb->Controller,
  1676. &gEfiManagedNetworkServiceBindingProtocolGuid,
  1677. (VOID **)&MnpSb,
  1678. IpSb->Image,
  1679. CallbackInfo->ChildHandle,
  1680. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
  1681. );
  1682. }
  1683. if (EFI_ERROR (Status)) {
  1684. goto Error;
  1685. }
  1686. //
  1687. // Publish our HII data
  1688. //
  1689. CallbackInfo->RegisteredHandle = HiiAddPackages (
  1690. &gIp6ConfigNvDataGuid,
  1691. CallbackInfo->ChildHandle,
  1692. Ip6DxeStrings,
  1693. Ip6ConfigBin,
  1694. NULL
  1695. );
  1696. if (CallbackInfo->RegisteredHandle == NULL) {
  1697. Status = EFI_OUT_OF_RESOURCES;
  1698. goto Error;
  1699. }
  1700. //
  1701. // Append MAC string in the menu help string and tile help string
  1702. //
  1703. Status = NetLibGetMacString (IpSb->Controller, IpSb->Image, &MacString);
  1704. if (!EFI_ERROR (Status)) {
  1705. OldMenuString = HiiGetString (
  1706. CallbackInfo->RegisteredHandle,
  1707. STRING_TOKEN (STR_IP6_CONFIG_FORM_HELP),
  1708. NULL
  1709. )
  1710. ;
  1711. UnicodeSPrint (MenuString, 128, L"%s (MAC:%s)", OldMenuString, MacString);
  1712. HiiSetString (
  1713. CallbackInfo->RegisteredHandle,
  1714. STRING_TOKEN (STR_IP6_CONFIG_FORM_HELP),
  1715. MenuString,
  1716. NULL
  1717. );
  1718. UnicodeSPrint (PortString, 128, L"MAC:%s", MacString);
  1719. HiiSetString (
  1720. CallbackInfo->RegisteredHandle,
  1721. STRING_TOKEN (STR_IP6_DEVICE_FORM_HELP),
  1722. PortString,
  1723. NULL
  1724. );
  1725. FreePool (MacString);
  1726. FreePool (OldMenuString);
  1727. InitializeListHead (&Instance->Ip6NvData.ManualAddress);
  1728. InitializeListHead (&Instance->Ip6NvData.GatewayAddress);
  1729. InitializeListHead (&Instance->Ip6NvData.DnsAddress);
  1730. return EFI_SUCCESS;
  1731. }
  1732. Error:
  1733. Ip6ConfigFormUnload (Instance);
  1734. return Status;
  1735. }
  1736. /**
  1737. Uninstall the HII Config Access protocol for network devices and free up the resources.
  1738. @param[in, out] Instance The IP6_CONFIG_INSTANCE to unload a form.
  1739. **/
  1740. VOID
  1741. Ip6ConfigFormUnload (
  1742. IN OUT IP6_CONFIG_INSTANCE *Instance
  1743. )
  1744. {
  1745. IP6_SERVICE *IpSb;
  1746. IP6_FORM_CALLBACK_INFO *CallbackInfo;
  1747. IP6_CONFIG_NVDATA *Ip6NvData;
  1748. IpSb = IP6_SERVICE_FROM_IP6_CONFIG_INSTANCE (Instance);
  1749. ASSERT (IpSb != NULL);
  1750. CallbackInfo = &Instance->CallbackInfo;
  1751. if (CallbackInfo->ChildHandle != NULL) {
  1752. //
  1753. // Close the child handle
  1754. //
  1755. gBS->CloseProtocol (
  1756. IpSb->Controller,
  1757. &gEfiManagedNetworkServiceBindingProtocolGuid,
  1758. IpSb->Image,
  1759. CallbackInfo->ChildHandle
  1760. );
  1761. //
  1762. // Uninstall EFI_HII_CONFIG_ACCESS_PROTOCOL
  1763. //
  1764. gBS->UninstallMultipleProtocolInterfaces (
  1765. CallbackInfo->ChildHandle,
  1766. &gEfiDevicePathProtocolGuid,
  1767. CallbackInfo->HiiVendorDevicePath,
  1768. &gEfiHiiConfigAccessProtocolGuid,
  1769. &CallbackInfo->HiiConfigAccess,
  1770. NULL
  1771. );
  1772. }
  1773. if (CallbackInfo->HiiVendorDevicePath != NULL) {
  1774. FreePool (CallbackInfo->HiiVendorDevicePath);
  1775. }
  1776. if (CallbackInfo->RegisteredHandle != NULL) {
  1777. //
  1778. // Remove HII package list
  1779. //
  1780. HiiRemovePackages (CallbackInfo->RegisteredHandle);
  1781. }
  1782. Ip6NvData = &Instance->Ip6NvData;
  1783. Ip6FreeAddressInfoList (&Ip6NvData->ManualAddress);
  1784. Ip6FreeAddressInfoList (&Ip6NvData->GatewayAddress);
  1785. Ip6FreeAddressInfoList (&Ip6NvData->DnsAddress);
  1786. Ip6NvData->ManualAddressCount = 0;
  1787. Ip6NvData->GatewayAddressCount = 0;
  1788. Ip6NvData->DnsAddressCount = 0;
  1789. }